History log of /openbsd-current/sys/dev/pci/if_sk.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.197 26-Jun-2024 jsg

return type on a dedicated line when declaring functions
ok mglocker@


# 1.196 24-May-2024 jsg

remove unneeded includes; ok miod@


Revision tags: OPENBSD_7_5_BASE
# 1.195 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.194 11-Mar-2022 mpi

Constify struct cfattach.


# 1.193 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.192 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.191 10-Jul-2020 patrick

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

ok dlg@ tobhe@


# 1.190 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


Revision tags: 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.189 04-Jun-2017 dlg

use htolem32 and lemtoh32 instead of htole32 and letoh32.

saves about half a k on sparc64.


# 1.188 02-Jun-2017 dlg

handle 64bit dva in the tx path as well as the rx path.


# 1.187 01-Jun-2017 dlg

reorder ops in sk_start to avoid possibly rolling back ifq_deq.

instead of checking for space after beggining to deq a packet, check
for space before committing to handling a packet. this means we
can use ifq_dequeue instead of ifq_deq_begin/commit/rollback.

ok mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.186 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@


# 1.185 08-Jan-2017 visa

Use a macro for the Tx timeout value.

OK deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.184 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.183 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.182 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.181 24-Nov-2015 mpi

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


# 1.180 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.179 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.178 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.177 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.176 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.175 30-Apr-2015 mpi

Convert to if_input(), tweak and ok dlg@


# 1.174 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@


Revision tags: OPENBSD_5_7_BASE
# 1.173 22-Dec-2014 tedu

unifdef INET


# 1.172 20-Aug-2014 dlg

brad said i had some whitespace screwups in my previous diff. this cleans
them up and the others i found in this file.

no functional change.


# 1.171 20-Aug-2014 dlg

replace sks jumbo allocator with MCLGETI. the system provides jumbos in
the right shape now, we dont have to do it by hand all over the place
any more.

rework the rxr ring management to use if_rxring while here.

largely based on if_sk.c r1.152 and if_skvar.h r1.4 by kettenis.
tested by me on:

skc0 at pci3 dev 11 function 0 "Schneider & Koch SK-98xx" rev 0x12, GEnesis (0x0): apic 3 int 5
sk0 at skc0 port A: address 00:00:5a:99:8a:ec
xmphy0 at sk0 phy 0: XMAC II Gigabit PHY, rev. 2

and this from ian mcwilliam

skc0 at pci0 dev 9 function 0 "D-Link DGE-530T B1" rev 0x11, Yukon Lite (0x9): apic 2 int 17
sk0 at skc0 port A: address 00:17:9a:ba:b5:39
eephy0 at sk0 phy 0: 88E1011 Gigabit PHY, rev. 5

tested by brad@ too


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

Fewer <netinet/in_systm.h>


# 1.169 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.168 19-Apr-2014 henning

kill checksum offloading in sk.
it was RX only, nothing on the TX side
rather complex, might eat up (or more) offloading benefits in many cases
the hardware miscomputes the cksums sometimes, so we don't trust it
claiming a cksum is bad and re-do the cksum verification in sw then...
(but we trust it to not mark bad ones good? hmmmmmmmmm.)
diff was on tech for 3 months, nobody disagreed, everybody who spoke up
agrees or doesn't care.
pretty exactly a revert of the cksum offloading addition years ago, tested
by several, the only report i quickly find now is from David Higgs <higgsd
at gmail dot com>, thanks!


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

Sync activate code sequnces to if_msk.c as much as possible, in case
one of these is ever found in a suspend/hibernate system.


# 1.166 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.165 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_4_BASE
# 1.164 07-Mar-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok chris@


Revision tags: OPENBSD_5_3_BASE
# 1.163 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@


# 1.162 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


Revision tags: OPENBSD_5_2_BASE
# 1.161 24-Feb-2012 guenther

Correct the spelling of "transferred" and "transferring"

from Tobias Ulmer (tobiasu at tmux.org); ok jmc@, krw@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.160 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.159 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.158 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


Revision tags: OPENBSD_4_8_BASE
# 1.157 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.156 17-Oct-2009 martynas

use sc->sk_bsize in the unmap call too; ok theo


# 1.155 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.154 04-Oct-2009 deraadt

Merge over a bunch of detach logic from msk(4) so that this driver can
detach as well
ok kettenis


# 1.153 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_6_BASE
# 1.152 08-Jul-2009 sthen

revert MCLGETI for sk(4) for now. commit requested by deraadt@


# 1.151 30-Mar-2009 kettenis

Switch sk(4) over to using MCLGETI when allocating mbufs for the RX ring.
Another evil jumbo allocator bites the dust.


Revision tags: OPENBSD_4_5_BASE
# 1.150 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.149 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.148 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.147 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.146 24-May-2008 brad

Also recognize the Schneider & Koch SK-9821/SK-9843 adapters from
Fujitsu.


# 1.145 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.144 02-Mar-2008 brad

Change some spaces to tabs in the transmit functions.

ok kettenis@


# 1.143 17-Jan-2008 brad

Add splnet around mii_tick() in sk_yukon_tick().

ok kettenis@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.142 26-May-2007 reyk

separate the attach information from the status information with a colon.

suggested by deraadt@


# 1.141 22-May-2007 ray

%z in printf(9) is not the same as %z in printf(3). Change to %lu
and cast arg to ulong.

OK miod@.


# 1.140 07-May-2007 deraadt

shrink code by not using __inline without static; ok kettenis


Revision tags: OPENBSD_4_1_BASE
# 1.139 12-Feb-2007 pedro

Fix prototype, from brad@, no binary change


# 1.138 10-Feb-2007 krw

Move HASH_BITS constant to if_skreg.h as SK_HASH_BITS. Remove unused
code and an unnecessary comment, No functional change.

From brad@.


# 1.137 03-Feb-2007 kettenis

Fix typo; clear tx FIFO underrun IRQ as intended instead of rx FIFO overrun
IRQ. From brad@


# 1.136 18-Jan-2007 krw

Don't reinitialize card at every media change.

From Brad, tested by Brad, wilfried@ and Johan M:son Lindman.

ok wilfried@


# 1.135 05-Jan-2007 kettenis

For Yukon-based cards, pass MIIF_DOPAUSE to mii_attach().

From brad@


# 1.134 03-Jan-2007 kettenis

In sk_marv_miibus_writereg, wait for busy flag to clear instead of
continuing when busy flag set.


# 1.133 03-Jan-2007 krw

Don't say 'Marvell' twice for each sk/msk device in dmesg. No functional
change.

from brad@ ok mglocker@


# 1.132 06-Dec-2006 reyk

- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested on amd64/i386/sparc64

ok brad@ mglocker@


# 1.131 16-Nov-2006 brad

remove the small amount of code for Yukon-2 chipsets now that there is msk(4).


# 1.130 08-Nov-2006 kettenis

Make XMAC work on on big-endian systems.

help & ok jason@, ok brad@


# 1.129 16-Oct-2006 tom

Fix some "is is"s. ok otto@.


# 1.128 27-Sep-2006 brad

fix the use of LIST_INSERT_HEAD in [m]sk_alloc_jumbo_mem().


# 1.127 26-Sep-2006 brad

Set sk_jumbo_buf to NULL if malloc() fails in the for loop within
[m]sk_alloc_jumbo_mem().


# 1.126 18-Sep-2006 brad

g/c unused SK_{SET,CLR}BIT macros

From riz@NetBSD


Revision tags: OPENBSD_4_0_BASE
# 1.125 17-Aug-2006 brad

cosmetic tweaks.


# 1.124 17-Aug-2006 brad

remove PCI ids which msk(4) will match against from sk(4).


# 1.123 09-Aug-2006 brad

revert rev 1.119 as this seems to cause problems with some PHY.


# 1.122 04-Aug-2006 brad

and the same goes for sk_init_yukon().


# 1.121 04-Aug-2006 brad

remove now redundant promiscuous mode handling code from sk_init_xmac().


# 1.120 04-Aug-2006 brad

refactor the promiscuous mode handling code and simplify the ioctl handler.


# 1.119 04-Aug-2006 brad

Fix busy check for PHY write operation with Yukon chips.

From yongari@FreeBSD


# 1.118 30-Jul-2006 brad

Add more strict receive path packet validation routine. Previously
the driver could pass corrupted packets to the upper layer under
certain conditions.

From yongari@FreeBSD


# 1.117 23-Jul-2006 brad

improved Yukon init routine with proper workaround for the PHY COMA mode.

From yongari@FreeBSD


# 1.116 22-Jun-2006 brad

Add appropriate swapping for big-endian systems. Allows sk(4) to work
on macppc and sparc64.

ok reyk@


# 1.115 22-Jun-2006 brad

adjust PCI ids.


# 1.114 17-Jun-2006 brad

add sys/timeout.h


# 1.113 17-Jun-2006 brad

remove some whitespace.


# 1.112 15-Jun-2006 brad

Fix watchdog timeout errors seen on a few systems.

The SK-NET GENESIS document says reading the SK_ISSR register should stop
generating further interrupts, but it seems there is the possibility
of losing interrupts between reading the SK_ISSR register and determining
which interrupts have been reported. To cope with this situation we
continuously read the SK_ISSR register until there are no interrupts.

However, it seems that the above workaround does not fix all cases.
Add workaround code that tries to protect against false alarms from
the watchdog handler by trying to reclaim pending Tx descriptors
before resetting the hardware.

This should fix occasional watchdog timeouts seen with this driver.

From FreeBSD


# 1.111 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.110 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.109 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.108 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.107 01-May-2006 brad

Activate Tx descriptor poll timer in order to protect possible loss
of SK_TXBMU_TX_START command. Previously the driver continuously issued
SK_TXBMU_TX_START when it notices pending Tx descriptors not processed
yet in interrupt handler. That approach would add additional PCI
write access overhead under high Tx load situations and it might fail
if the first SK_TXBMU_TX_START was lost and no interrupt is generated
from the first SK_TXBMU_TX_START command.

From FreeBSD


# 1.106 01-May-2006 brad

Added Rx/Tx FIFO flush support for Yukon

From FreeBSD


# 1.105 01-May-2006 brad

A new function sk_yukon_tick(), to handle auto-negotiation properly for
Yukon-based adapters.

From FreeBSD


# 1.104 30-Apr-2006 brad

- Use SK_IS_GENESIS/SK_IS_YUKON where appropriate
- Remove SK_YUKON_FAMILY


# 1.103 30-Apr-2006 brad

- Interrupt handler now checks shared interrupt source and protects
the interrupt handler from NULL pointer dereference which was caused
by odd status word value. The status word can return 0xffffffff if the
cable is unplugged while Rx/Tx/auto-negotiation is in progress.

From FreeBSD


# 1.102 30-Apr-2006 brad

Update if_oerrors if we encounter watchdog error.

From FreeBSD


# 1.101 30-Apr-2006 brad

- Added/corrected register definitions for Yukon.
(Register information from Linux skge driver.)

From FreeBSD


# 1.100 23-Apr-2006 brad

some more ANSI, KNF and other tidying up.


# 1.99 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.98 17-Apr-2006 brad

If there is a timeout while writing to the PHY in
sk_marv_miibus_writereg() then print a message
indicating so, as done in the XMAC case.


# 1.97 17-Apr-2006 brad

Coviery CID 1108: Avoid NULL pointer deref.

Coverity CID 1105: Avoid NULL deref.

From NetBSD


# 1.96 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.95 13-Feb-2006 brad

add some ASIC revisions to the various switch cases and identify
some newer revs.


# 1.94 09-Feb-2006 brad

sync PCI id.


# 1.93 22-Dec-2005 brad

re-work PHY setup, media handling and dual-port detection.

Based on the Marvell FreeBSD driver.


# 1.92 16-Dec-2005 brad

remove unused code to use IO space.


# 1.91 15-Dec-2005 brad

merge printing of the revision and the interrupt string into one printf.


# 1.90 10-Dec-2005 brad

sk_shutdown -> skc_shutdown and register the shutdown function with
shutdownhook_establish().


# 1.89 10-Dec-2005 brad

shrink dmesg entry by one line by merging the chipset revision into
the skc line and fix various error condition printf's in skc_attach(),
sk_attach() and sk_alloc_jumbo_mem() so the messages will be displayed
properly.

ok krw@


# 1.88 26-Nov-2005 brad

fix interrupt moderation timer frequencies for Yukon and Yukon-II based
chips.

From Jeff Rizzo on NetBSD's tech-net list, based on the Marvell
sk98lin Linux driver, and also matches what the Marvell FreeBSD
does.


# 1.87 15-Nov-2005 brad

more accurately reflect the naming scheme of the Marvell Yukon devices with there
pcidevs entries.

Based on information from the Marvell Yukon/Yukon-II FreeBSD driver.


# 1.86 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.85 15-Oct-2005 brad

add 2 new Yukon PCI ids and recognize Yukon-2 EC Ultra ASIC.


# 1.84 15-Oct-2005 brad

update Via and 3Com ids.


# 1.83 20-Sep-2005 brad

memory, media handling and a bunch of register definitions for Yukon-2.

From jason@


# 1.82 20-Sep-2005 brad

merge xmaciireg.h and yukonreg.h into if_skreg.h


# 1.81 20-Sep-2005 brad

shuffle some stuff from skreg to skvar


# 1.80 17-Sep-2005 brad

add media detection and dual port detection for Yukon-2.

from jason@


# 1.79 16-Sep-2005 brad

- remove code to read PCI VPD as we do not use that anymore.
- remove some FreeBSD-ism's: struct resource *'s.
- fail more gracefully in sk_probe() instead of in sk_attach()
for newer unsupported ASIC revisions.

From jason@


Revision tags: OPENBSD_3_8_BASE
# 1.78 29-Aug-2005 brad

- use pci_mapreg_type() to fix some systems that would fail to attach
sk(4) with "can't map mem space".
- add missing newline for failure case of pci_intr_establish().

ok deraadt@


# 1.77 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.76 24-Jul-2005 fgsch

simplify error paths and add some missing ones; brad@ ok.
deallocation for jumbo memory left.


# 1.75 22-Jul-2005 brad

- sync sk_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()
- oops, forgot to remove a line in sk_rxeof()


# 1.74 22-Jul-2005 brad

also take the PCI subsystem id into consideration when trying to probe
for Linksys EG1032 cards, that way we do not try and attach to newer
rev 3 cards that use the RealTek 8169S chipset.


# 1.73 21-Jul-2005 brad

- add bus_dmamap_sync()'s; From NetBSD
- use pci_mapreg_map()
- remove unnecessary splimp() usage in skc_attach()
- make sure to disestablish the interrupt on failure

Tested by a few end-users.


# 1.72 14-Jul-2005 brad

add D-Link PCI id.

From: jsg@


# 1.71 12-Jul-2005 brad

remove unused prototype sk_free_jumbo_mem


# 1.70 12-Jul-2005 brad

free resources for Jumbo buffers in sk_stop().

ok deraadt, krw, beck


# 1.69 02-Jul-2005 brad

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


# 1.68 02-Jul-2005 brad

- mbuf external storage is of (caddr_t), not (caddr_t *).
- check for MTU being too small with ETHERMIN
- don't bother reseting the card since it'll default to allowing Jumbos


# 1.67 17-May-2005 jason

remove spurious bpf_mtap (I think it's leftover debugging code from a year ago)


# 1.66 16-May-2005 brad

add a newline here


# 1.65 11-May-2005 brad

remove comment which is not valid anymore


# 1.64 11-May-2005 brad

- Also match on Yukon LP's for the Lite rev A0 test.
- Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().
- Take PHY out of reset for Yukon Lite rev A3. This resolves the
intermittent "no PHY found!" issue.

From FreeBSD

- Recognize some newer Yukon chipsets

ok krw@, tested by krw@ and a few others, mostly with LOM Lite A3's but
also with some other ASIC revs too.


# 1.63 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.62 18-Mar-2005 brad

fail to attach with a printf instead of a panic for newer yet unsupported
Yukon-2-based cards.

ok deraadt@


# 1.61 12-Mar-2005 brad

add a bunch of PCI ids from the SysKonnect sk98lin driver.


# 1.60 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.59 02-Jan-2005 brad

cleanup and better ram sizing.


# 1.58 01-Jan-2005 brad

better chip/card identification.

From NetBSD

ok krw@


# 1.57 01-Jan-2005 brad

rev 1.92

only clear the IFF_OACTIVE flag when we have a chance of being able to
queue a packet to the hardware... instead of when the hardware queue is
empty..

don't initalize cur_tx now that it doesn't need to be...

rev 1.90

_OACTIVE is now handled better...

From FreeBSD

ok krw@


# 1.56 01-Jan-2005 krw

Don't initialize the card (and start an autonegotiation!) every time
the IP address changes. Makes 'dhclient sk0' invocations way faster
and more consistant. i.e. one DHCPREQUEST elicts the DHCPACK.

ok brad@ 'Wow. Great Idea.' deraadt@.


# 1.55 22-Dec-2004 brad

- add missing braces for SIOCSIFMTU switch case.
- allow reception of Jumbo frames all the time on GEnesis based cards,
same as Yukon based cards.

ok krw@ mcbride@


# 1.54 14-Dec-2004 krw

Fix off-by-one. From FreeBSD r1.87. Also in NetBSD. Field being filled
(sk_vpd_readonly) is not currently used, but the memory being tromped
on might be.

ok millert@.


# 1.53 08-Dec-2004 brad

use ETHER_MAX_LEN


# 1.52 08-Dec-2004 krw

Enable jumbo frames on Yukon varients of sk(4).

ok mcbride@.


# 1.51 16-Nov-2004 brad

Lower interrupt moderation timer to decrease service latency.

From NetBSD

ok deraadt@


# 1.50 16-Nov-2004 brad

back out previous commit and put the right change in which corresponds
to what the previous commit message said...

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).


# 1.49 16-Nov-2004 brad

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).

From NetBSD

ok henning@ mcbride@


# 1.48 11-Nov-2004 brad

- Fix Yukon ram sizing.
- Keep tx queue running by kicking the tx bmu repeatedly.
- Handle if_timer a bit better.

From NetBSD

ok deraadt@


# 1.47 14-Oct-2004 brad

Bail out quietly if the eeprom appears to be missing or empty. Fixes
support for D-Link DGE-530T adapters.

From: FreeBSD via Blake Willis <blake at 2112 dot net>

ok mcbride@


# 1.46 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
# 1.45 20-Aug-2004 deraadt

a belkin ID on a sk card


# 1.44 19-Aug-2004 mcbride

Don't complain about lack of jumbo storage when processing incoming packets
unless we're debugging.


# 1.43 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


# 1.42 04-Aug-2004 mcbride

Make jumbo frames work.
- allocate and manage our own memory for rx packets rather than using
mbuf clusters; code for this lifted from if_bge.c
- pass the correct size to bus_dmamap_create()

ok deraadt@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.41 29-May-2004 naddy

replace hand-rolled CRC calculation in multicast hash setup with calls to
ether_crc32_*(); ok mcbride@


# 1.40 24-May-2004 naddy

Make Yukon-style adapters also set up the multicast filter in sk_init().
This fixes various multicast-related problems. ok henning@


# 1.39 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.38 09-Mar-2004 matthieu

Fix multicast on recent sk chipsets. Adapted from a patch by Keith Mitchell
in <http://lists.freebsd.org/pipermail/freebsd-hardware/2003-December/000851.html>
Ok deraadt@.


# 1.37 17-Dec-2003 jason

not qualifying a product based on vendor AND product ID just bugs me


# 1.36 17-Dec-2003 jason

marvell skv2 (smc9452TX); from freebsd


# 1.35 17-Dec-2003 jason

add support for linksys (eg1032v2, eg1064v2) and dlink (dge530t); from NetBSD


# 1.34 13-Oct-2003 jason

rx checksum offload support (based on earlier code from aaron@, but with
fixes by me). Note: sk v1 chips can sometimes compute an incorrect cksum.
To deal with that, we never set the "bad" flags. Ie. if the card says it's
good, we assume it's good. If the card says it's bad, we fall back to
software. Ugly? You betcha.


Revision tags: OPENBSD_3_4_BASE
# 1.33 12-Aug-2003 nate

add/update my copyright


# 1.32 01-Aug-2003 nate

Support for new Marvell based Gigabit Ethernet adapters
ok deraadt@


Revision tags: UBC_SYNC_A
# 1.31 14-May-2003 nate

Makefile sk(4) use bus_dma
ok jason


# 1.30 08-May-2003 nate

a bit more cleanup


# 1.29 08-May-2003 nate

ansify, clean up formatting, remove useless return statements.
ok jason


Revision tags: OPENBSD_3_3_BASE
# 1.28 12-Mar-2003 nate

sk is capable of transmitting and receiving longer packets for 802.1q vlans
thanks to David Gwynne <loki@niteshade.net>. ok jason@ deraadt@


# 1.27 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.26 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.25 08-Jun-2002 jason

add missing ioctl support for SIOCSIFMTU


# 1.24 04-Jun-2002 deraadt

spelling; raj@cerias.purdue.edu


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

First round of __P removal in sys


# 1.22 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.21 15-Feb-2002 nordin

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


# 1.20 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


Revision tags: UBC_BASE
# 1.19 06-Nov-2001 miod

branches: 1.19.2;
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.18 05-Oct-2001 nate

use positive logic for match


# 1.17 11-Sep-2001 miod

Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.16 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.15 15-Aug-2001 jason

Add some stuff missed in a previous FreeBSD merge... Fixes the problem where
sk busy loops when carrier is lost until it returns; based on patch from
david langhorst <dirt@monkey.org> and tested by John Ladwig <jladwig@mango.lioness.net>


# 1.14 12-Aug-2001 mickey

remove redundant vm includes


# 1.13 25-Jun-2001 fgsch

trivial ether_input_mbuf() conversion.


Revision tags: OPENBSD_2_9_BASE
# 1.12 29-Mar-2001 jason

From FreeBSD:
- Call mii_pollstat() after we bring up the link on a 1000baseTX card
after autoneg so we make sure to set the link state and duplex mode
correctly.
- Make sure to set the 'ignore pause frames' bit on the XMAC.
- Small linewrap fix.
- Add actual URL for XMAC II datasheet in comments.


# 1.11 25-Mar-2001 csapuntz

Missing splx(s). Thanks to Dawson and team for finding this one


# 1.10 20-Feb-2001 mickey

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


Revision tags: OPENBSD_2_8_BASE
# 1.9 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.8 04-Sep-2000 deraadt

printing XaQti on 5 consecutive lines is stupid


# 1.7 29-Aug-2000 jason

From FreeBSD: split out the support for XMAC-II phys and other phys
add xmphy & brgphy to GENERIC


Revision tags: OPENBSD_2_7_BASE
# 1.6 15-Feb-2000 jason

make sure to call ether_{add,del}multi() as appropriate in xxx_ioctl()


Revision tags: SMP_BASE kame_19991208
# 1.5 08-Dec-1999 aaron

branches: 1.5.2;
Remove unused #define cruft.


Revision tags: OPENBSD_2_6_BASE
# 1.4 22-Oct-1999 deraadt

fix some panic bugs; jason


# 1.3 04-Oct-1999 jason

m_new is the new mbuf, not m
fix calculation of buffer slot number


# 1.2 03-Oct-1999 jason

take advantage of m->m_ext.ext_handle for storing the softc
(instead of stashing it in the buffer)


# 1.1 01-Oct-1999 jason

driver for SysKonnect 984x gigabit ethernet adapters; from FreeBSD


# 1.196 24-May-2024 jsg

remove unneeded includes; ok miod@


Revision tags: OPENBSD_7_5_BASE
# 1.195 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.194 11-Mar-2022 mpi

Constify struct cfattach.


# 1.193 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.192 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.191 10-Jul-2020 patrick

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

ok dlg@ tobhe@


# 1.190 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


Revision tags: 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.189 04-Jun-2017 dlg

use htolem32 and lemtoh32 instead of htole32 and letoh32.

saves about half a k on sparc64.


# 1.188 02-Jun-2017 dlg

handle 64bit dva in the tx path as well as the rx path.


# 1.187 01-Jun-2017 dlg

reorder ops in sk_start to avoid possibly rolling back ifq_deq.

instead of checking for space after beggining to deq a packet, check
for space before committing to handling a packet. this means we
can use ifq_dequeue instead of ifq_deq_begin/commit/rollback.

ok mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.186 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@


# 1.185 08-Jan-2017 visa

Use a macro for the Tx timeout value.

OK deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.184 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.183 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.182 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.181 24-Nov-2015 mpi

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


# 1.180 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.179 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.178 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.177 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.176 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.175 30-Apr-2015 mpi

Convert to if_input(), tweak and ok dlg@


# 1.174 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@


Revision tags: OPENBSD_5_7_BASE
# 1.173 22-Dec-2014 tedu

unifdef INET


# 1.172 20-Aug-2014 dlg

brad said i had some whitespace screwups in my previous diff. this cleans
them up and the others i found in this file.

no functional change.


# 1.171 20-Aug-2014 dlg

replace sks jumbo allocator with MCLGETI. the system provides jumbos in
the right shape now, we dont have to do it by hand all over the place
any more.

rework the rxr ring management to use if_rxring while here.

largely based on if_sk.c r1.152 and if_skvar.h r1.4 by kettenis.
tested by me on:

skc0 at pci3 dev 11 function 0 "Schneider & Koch SK-98xx" rev 0x12, GEnesis (0x0): apic 3 int 5
sk0 at skc0 port A: address 00:00:5a:99:8a:ec
xmphy0 at sk0 phy 0: XMAC II Gigabit PHY, rev. 2

and this from ian mcwilliam

skc0 at pci0 dev 9 function 0 "D-Link DGE-530T B1" rev 0x11, Yukon Lite (0x9): apic 2 int 17
sk0 at skc0 port A: address 00:17:9a:ba:b5:39
eephy0 at sk0 phy 0: 88E1011 Gigabit PHY, rev. 5

tested by brad@ too


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

Fewer <netinet/in_systm.h>


# 1.169 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.168 19-Apr-2014 henning

kill checksum offloading in sk.
it was RX only, nothing on the TX side
rather complex, might eat up (or more) offloading benefits in many cases
the hardware miscomputes the cksums sometimes, so we don't trust it
claiming a cksum is bad and re-do the cksum verification in sw then...
(but we trust it to not mark bad ones good? hmmmmmmmmm.)
diff was on tech for 3 months, nobody disagreed, everybody who spoke up
agrees or doesn't care.
pretty exactly a revert of the cksum offloading addition years ago, tested
by several, the only report i quickly find now is from David Higgs <higgsd
at gmail dot com>, thanks!


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

Sync activate code sequnces to if_msk.c as much as possible, in case
one of these is ever found in a suspend/hibernate system.


# 1.166 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.165 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_4_BASE
# 1.164 07-Mar-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok chris@


Revision tags: OPENBSD_5_3_BASE
# 1.163 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@


# 1.162 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


Revision tags: OPENBSD_5_2_BASE
# 1.161 24-Feb-2012 guenther

Correct the spelling of "transferred" and "transferring"

from Tobias Ulmer (tobiasu at tmux.org); ok jmc@, krw@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.160 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.159 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.158 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


Revision tags: OPENBSD_4_8_BASE
# 1.157 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.156 17-Oct-2009 martynas

use sc->sk_bsize in the unmap call too; ok theo


# 1.155 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.154 04-Oct-2009 deraadt

Merge over a bunch of detach logic from msk(4) so that this driver can
detach as well
ok kettenis


# 1.153 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_6_BASE
# 1.152 08-Jul-2009 sthen

revert MCLGETI for sk(4) for now. commit requested by deraadt@


# 1.151 30-Mar-2009 kettenis

Switch sk(4) over to using MCLGETI when allocating mbufs for the RX ring.
Another evil jumbo allocator bites the dust.


Revision tags: OPENBSD_4_5_BASE
# 1.150 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.149 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.148 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.147 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.146 24-May-2008 brad

Also recognize the Schneider & Koch SK-9821/SK-9843 adapters from
Fujitsu.


# 1.145 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.144 02-Mar-2008 brad

Change some spaces to tabs in the transmit functions.

ok kettenis@


# 1.143 17-Jan-2008 brad

Add splnet around mii_tick() in sk_yukon_tick().

ok kettenis@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.142 26-May-2007 reyk

separate the attach information from the status information with a colon.

suggested by deraadt@


# 1.141 22-May-2007 ray

%z in printf(9) is not the same as %z in printf(3). Change to %lu
and cast arg to ulong.

OK miod@.


# 1.140 07-May-2007 deraadt

shrink code by not using __inline without static; ok kettenis


Revision tags: OPENBSD_4_1_BASE
# 1.139 12-Feb-2007 pedro

Fix prototype, from brad@, no binary change


# 1.138 10-Feb-2007 krw

Move HASH_BITS constant to if_skreg.h as SK_HASH_BITS. Remove unused
code and an unnecessary comment, No functional change.

From brad@.


# 1.137 03-Feb-2007 kettenis

Fix typo; clear tx FIFO underrun IRQ as intended instead of rx FIFO overrun
IRQ. From brad@


# 1.136 18-Jan-2007 krw

Don't reinitialize card at every media change.

From Brad, tested by Brad, wilfried@ and Johan M:son Lindman.

ok wilfried@


# 1.135 05-Jan-2007 kettenis

For Yukon-based cards, pass MIIF_DOPAUSE to mii_attach().

From brad@


# 1.134 03-Jan-2007 kettenis

In sk_marv_miibus_writereg, wait for busy flag to clear instead of
continuing when busy flag set.


# 1.133 03-Jan-2007 krw

Don't say 'Marvell' twice for each sk/msk device in dmesg. No functional
change.

from brad@ ok mglocker@


# 1.132 06-Dec-2006 reyk

- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested on amd64/i386/sparc64

ok brad@ mglocker@


# 1.131 16-Nov-2006 brad

remove the small amount of code for Yukon-2 chipsets now that there is msk(4).


# 1.130 08-Nov-2006 kettenis

Make XMAC work on on big-endian systems.

help & ok jason@, ok brad@


# 1.129 16-Oct-2006 tom

Fix some "is is"s. ok otto@.


# 1.128 27-Sep-2006 brad

fix the use of LIST_INSERT_HEAD in [m]sk_alloc_jumbo_mem().


# 1.127 26-Sep-2006 brad

Set sk_jumbo_buf to NULL if malloc() fails in the for loop within
[m]sk_alloc_jumbo_mem().


# 1.126 18-Sep-2006 brad

g/c unused SK_{SET,CLR}BIT macros

From riz@NetBSD


Revision tags: OPENBSD_4_0_BASE
# 1.125 17-Aug-2006 brad

cosmetic tweaks.


# 1.124 17-Aug-2006 brad

remove PCI ids which msk(4) will match against from sk(4).


# 1.123 09-Aug-2006 brad

revert rev 1.119 as this seems to cause problems with some PHY.


# 1.122 04-Aug-2006 brad

and the same goes for sk_init_yukon().


# 1.121 04-Aug-2006 brad

remove now redundant promiscuous mode handling code from sk_init_xmac().


# 1.120 04-Aug-2006 brad

refactor the promiscuous mode handling code and simplify the ioctl handler.


# 1.119 04-Aug-2006 brad

Fix busy check for PHY write operation with Yukon chips.

From yongari@FreeBSD


# 1.118 30-Jul-2006 brad

Add more strict receive path packet validation routine. Previously
the driver could pass corrupted packets to the upper layer under
certain conditions.

From yongari@FreeBSD


# 1.117 23-Jul-2006 brad

improved Yukon init routine with proper workaround for the PHY COMA mode.

From yongari@FreeBSD


# 1.116 22-Jun-2006 brad

Add appropriate swapping for big-endian systems. Allows sk(4) to work
on macppc and sparc64.

ok reyk@


# 1.115 22-Jun-2006 brad

adjust PCI ids.


# 1.114 17-Jun-2006 brad

add sys/timeout.h


# 1.113 17-Jun-2006 brad

remove some whitespace.


# 1.112 15-Jun-2006 brad

Fix watchdog timeout errors seen on a few systems.

The SK-NET GENESIS document says reading the SK_ISSR register should stop
generating further interrupts, but it seems there is the possibility
of losing interrupts between reading the SK_ISSR register and determining
which interrupts have been reported. To cope with this situation we
continuously read the SK_ISSR register until there are no interrupts.

However, it seems that the above workaround does not fix all cases.
Add workaround code that tries to protect against false alarms from
the watchdog handler by trying to reclaim pending Tx descriptors
before resetting the hardware.

This should fix occasional watchdog timeouts seen with this driver.

From FreeBSD


# 1.111 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.110 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.109 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.108 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.107 01-May-2006 brad

Activate Tx descriptor poll timer in order to protect possible loss
of SK_TXBMU_TX_START command. Previously the driver continuously issued
SK_TXBMU_TX_START when it notices pending Tx descriptors not processed
yet in interrupt handler. That approach would add additional PCI
write access overhead under high Tx load situations and it might fail
if the first SK_TXBMU_TX_START was lost and no interrupt is generated
from the first SK_TXBMU_TX_START command.

From FreeBSD


# 1.106 01-May-2006 brad

Added Rx/Tx FIFO flush support for Yukon

From FreeBSD


# 1.105 01-May-2006 brad

A new function sk_yukon_tick(), to handle auto-negotiation properly for
Yukon-based adapters.

From FreeBSD


# 1.104 30-Apr-2006 brad

- Use SK_IS_GENESIS/SK_IS_YUKON where appropriate
- Remove SK_YUKON_FAMILY


# 1.103 30-Apr-2006 brad

- Interrupt handler now checks shared interrupt source and protects
the interrupt handler from NULL pointer dereference which was caused
by odd status word value. The status word can return 0xffffffff if the
cable is unplugged while Rx/Tx/auto-negotiation is in progress.

From FreeBSD


# 1.102 30-Apr-2006 brad

Update if_oerrors if we encounter watchdog error.

From FreeBSD


# 1.101 30-Apr-2006 brad

- Added/corrected register definitions for Yukon.
(Register information from Linux skge driver.)

From FreeBSD


# 1.100 23-Apr-2006 brad

some more ANSI, KNF and other tidying up.


# 1.99 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.98 17-Apr-2006 brad

If there is a timeout while writing to the PHY in
sk_marv_miibus_writereg() then print a message
indicating so, as done in the XMAC case.


# 1.97 17-Apr-2006 brad

Coviery CID 1108: Avoid NULL pointer deref.

Coverity CID 1105: Avoid NULL deref.

From NetBSD


# 1.96 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.95 13-Feb-2006 brad

add some ASIC revisions to the various switch cases and identify
some newer revs.


# 1.94 09-Feb-2006 brad

sync PCI id.


# 1.93 22-Dec-2005 brad

re-work PHY setup, media handling and dual-port detection.

Based on the Marvell FreeBSD driver.


# 1.92 16-Dec-2005 brad

remove unused code to use IO space.


# 1.91 15-Dec-2005 brad

merge printing of the revision and the interrupt string into one printf.


# 1.90 10-Dec-2005 brad

sk_shutdown -> skc_shutdown and register the shutdown function with
shutdownhook_establish().


# 1.89 10-Dec-2005 brad

shrink dmesg entry by one line by merging the chipset revision into
the skc line and fix various error condition printf's in skc_attach(),
sk_attach() and sk_alloc_jumbo_mem() so the messages will be displayed
properly.

ok krw@


# 1.88 26-Nov-2005 brad

fix interrupt moderation timer frequencies for Yukon and Yukon-II based
chips.

From Jeff Rizzo on NetBSD's tech-net list, based on the Marvell
sk98lin Linux driver, and also matches what the Marvell FreeBSD
does.


# 1.87 15-Nov-2005 brad

more accurately reflect the naming scheme of the Marvell Yukon devices with there
pcidevs entries.

Based on information from the Marvell Yukon/Yukon-II FreeBSD driver.


# 1.86 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.85 15-Oct-2005 brad

add 2 new Yukon PCI ids and recognize Yukon-2 EC Ultra ASIC.


# 1.84 15-Oct-2005 brad

update Via and 3Com ids.


# 1.83 20-Sep-2005 brad

memory, media handling and a bunch of register definitions for Yukon-2.

From jason@


# 1.82 20-Sep-2005 brad

merge xmaciireg.h and yukonreg.h into if_skreg.h


# 1.81 20-Sep-2005 brad

shuffle some stuff from skreg to skvar


# 1.80 17-Sep-2005 brad

add media detection and dual port detection for Yukon-2.

from jason@


# 1.79 16-Sep-2005 brad

- remove code to read PCI VPD as we do not use that anymore.
- remove some FreeBSD-ism's: struct resource *'s.
- fail more gracefully in sk_probe() instead of in sk_attach()
for newer unsupported ASIC revisions.

From jason@


Revision tags: OPENBSD_3_8_BASE
# 1.78 29-Aug-2005 brad

- use pci_mapreg_type() to fix some systems that would fail to attach
sk(4) with "can't map mem space".
- add missing newline for failure case of pci_intr_establish().

ok deraadt@


# 1.77 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.76 24-Jul-2005 fgsch

simplify error paths and add some missing ones; brad@ ok.
deallocation for jumbo memory left.


# 1.75 22-Jul-2005 brad

- sync sk_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()
- oops, forgot to remove a line in sk_rxeof()


# 1.74 22-Jul-2005 brad

also take the PCI subsystem id into consideration when trying to probe
for Linksys EG1032 cards, that way we do not try and attach to newer
rev 3 cards that use the RealTek 8169S chipset.


# 1.73 21-Jul-2005 brad

- add bus_dmamap_sync()'s; From NetBSD
- use pci_mapreg_map()
- remove unnecessary splimp() usage in skc_attach()
- make sure to disestablish the interrupt on failure

Tested by a few end-users.


# 1.72 14-Jul-2005 brad

add D-Link PCI id.

From: jsg@


# 1.71 12-Jul-2005 brad

remove unused prototype sk_free_jumbo_mem


# 1.70 12-Jul-2005 brad

free resources for Jumbo buffers in sk_stop().

ok deraadt, krw, beck


# 1.69 02-Jul-2005 brad

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


# 1.68 02-Jul-2005 brad

- mbuf external storage is of (caddr_t), not (caddr_t *).
- check for MTU being too small with ETHERMIN
- don't bother reseting the card since it'll default to allowing Jumbos


# 1.67 17-May-2005 jason

remove spurious bpf_mtap (I think it's leftover debugging code from a year ago)


# 1.66 16-May-2005 brad

add a newline here


# 1.65 11-May-2005 brad

remove comment which is not valid anymore


# 1.64 11-May-2005 brad

- Also match on Yukon LP's for the Lite rev A0 test.
- Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().
- Take PHY out of reset for Yukon Lite rev A3. This resolves the
intermittent "no PHY found!" issue.

From FreeBSD

- Recognize some newer Yukon chipsets

ok krw@, tested by krw@ and a few others, mostly with LOM Lite A3's but
also with some other ASIC revs too.


# 1.63 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.62 18-Mar-2005 brad

fail to attach with a printf instead of a panic for newer yet unsupported
Yukon-2-based cards.

ok deraadt@


# 1.61 12-Mar-2005 brad

add a bunch of PCI ids from the SysKonnect sk98lin driver.


# 1.60 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.59 02-Jan-2005 brad

cleanup and better ram sizing.


# 1.58 01-Jan-2005 brad

better chip/card identification.

From NetBSD

ok krw@


# 1.57 01-Jan-2005 brad

rev 1.92

only clear the IFF_OACTIVE flag when we have a chance of being able to
queue a packet to the hardware... instead of when the hardware queue is
empty..

don't initalize cur_tx now that it doesn't need to be...

rev 1.90

_OACTIVE is now handled better...

From FreeBSD

ok krw@


# 1.56 01-Jan-2005 krw

Don't initialize the card (and start an autonegotiation!) every time
the IP address changes. Makes 'dhclient sk0' invocations way faster
and more consistant. i.e. one DHCPREQUEST elicts the DHCPACK.

ok brad@ 'Wow. Great Idea.' deraadt@.


# 1.55 22-Dec-2004 brad

- add missing braces for SIOCSIFMTU switch case.
- allow reception of Jumbo frames all the time on GEnesis based cards,
same as Yukon based cards.

ok krw@ mcbride@


# 1.54 14-Dec-2004 krw

Fix off-by-one. From FreeBSD r1.87. Also in NetBSD. Field being filled
(sk_vpd_readonly) is not currently used, but the memory being tromped
on might be.

ok millert@.


# 1.53 08-Dec-2004 brad

use ETHER_MAX_LEN


# 1.52 08-Dec-2004 krw

Enable jumbo frames on Yukon varients of sk(4).

ok mcbride@.


# 1.51 16-Nov-2004 brad

Lower interrupt moderation timer to decrease service latency.

From NetBSD

ok deraadt@


# 1.50 16-Nov-2004 brad

back out previous commit and put the right change in which corresponds
to what the previous commit message said...

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).


# 1.49 16-Nov-2004 brad

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).

From NetBSD

ok henning@ mcbride@


# 1.48 11-Nov-2004 brad

- Fix Yukon ram sizing.
- Keep tx queue running by kicking the tx bmu repeatedly.
- Handle if_timer a bit better.

From NetBSD

ok deraadt@


# 1.47 14-Oct-2004 brad

Bail out quietly if the eeprom appears to be missing or empty. Fixes
support for D-Link DGE-530T adapters.

From: FreeBSD via Blake Willis <blake at 2112 dot net>

ok mcbride@


# 1.46 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
# 1.45 20-Aug-2004 deraadt

a belkin ID on a sk card


# 1.44 19-Aug-2004 mcbride

Don't complain about lack of jumbo storage when processing incoming packets
unless we're debugging.


# 1.43 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


# 1.42 04-Aug-2004 mcbride

Make jumbo frames work.
- allocate and manage our own memory for rx packets rather than using
mbuf clusters; code for this lifted from if_bge.c
- pass the correct size to bus_dmamap_create()

ok deraadt@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.41 29-May-2004 naddy

replace hand-rolled CRC calculation in multicast hash setup with calls to
ether_crc32_*(); ok mcbride@


# 1.40 24-May-2004 naddy

Make Yukon-style adapters also set up the multicast filter in sk_init().
This fixes various multicast-related problems. ok henning@


# 1.39 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.38 09-Mar-2004 matthieu

Fix multicast on recent sk chipsets. Adapted from a patch by Keith Mitchell
in <http://lists.freebsd.org/pipermail/freebsd-hardware/2003-December/000851.html>
Ok deraadt@.


# 1.37 17-Dec-2003 jason

not qualifying a product based on vendor AND product ID just bugs me


# 1.36 17-Dec-2003 jason

marvell skv2 (smc9452TX); from freebsd


# 1.35 17-Dec-2003 jason

add support for linksys (eg1032v2, eg1064v2) and dlink (dge530t); from NetBSD


# 1.34 13-Oct-2003 jason

rx checksum offload support (based on earlier code from aaron@, but with
fixes by me). Note: sk v1 chips can sometimes compute an incorrect cksum.
To deal with that, we never set the "bad" flags. Ie. if the card says it's
good, we assume it's good. If the card says it's bad, we fall back to
software. Ugly? You betcha.


Revision tags: OPENBSD_3_4_BASE
# 1.33 12-Aug-2003 nate

add/update my copyright


# 1.32 01-Aug-2003 nate

Support for new Marvell based Gigabit Ethernet adapters
ok deraadt@


Revision tags: UBC_SYNC_A
# 1.31 14-May-2003 nate

Makefile sk(4) use bus_dma
ok jason


# 1.30 08-May-2003 nate

a bit more cleanup


# 1.29 08-May-2003 nate

ansify, clean up formatting, remove useless return statements.
ok jason


Revision tags: OPENBSD_3_3_BASE
# 1.28 12-Mar-2003 nate

sk is capable of transmitting and receiving longer packets for 802.1q vlans
thanks to David Gwynne <loki@niteshade.net>. ok jason@ deraadt@


# 1.27 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.26 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.25 08-Jun-2002 jason

add missing ioctl support for SIOCSIFMTU


# 1.24 04-Jun-2002 deraadt

spelling; raj@cerias.purdue.edu


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

First round of __P removal in sys


# 1.22 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.21 15-Feb-2002 nordin

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


# 1.20 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


Revision tags: UBC_BASE
# 1.19 06-Nov-2001 miod

branches: 1.19.2;
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.18 05-Oct-2001 nate

use positive logic for match


# 1.17 11-Sep-2001 miod

Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.16 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.15 15-Aug-2001 jason

Add some stuff missed in a previous FreeBSD merge... Fixes the problem where
sk busy loops when carrier is lost until it returns; based on patch from
david langhorst <dirt@monkey.org> and tested by John Ladwig <jladwig@mango.lioness.net>


# 1.14 12-Aug-2001 mickey

remove redundant vm includes


# 1.13 25-Jun-2001 fgsch

trivial ether_input_mbuf() conversion.


Revision tags: OPENBSD_2_9_BASE
# 1.12 29-Mar-2001 jason

From FreeBSD:
- Call mii_pollstat() after we bring up the link on a 1000baseTX card
after autoneg so we make sure to set the link state and duplex mode
correctly.
- Make sure to set the 'ignore pause frames' bit on the XMAC.
- Small linewrap fix.
- Add actual URL for XMAC II datasheet in comments.


# 1.11 25-Mar-2001 csapuntz

Missing splx(s). Thanks to Dawson and team for finding this one


# 1.10 20-Feb-2001 mickey

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


Revision tags: OPENBSD_2_8_BASE
# 1.9 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.8 04-Sep-2000 deraadt

printing XaQti on 5 consecutive lines is stupid


# 1.7 29-Aug-2000 jason

From FreeBSD: split out the support for XMAC-II phys and other phys
add xmphy & brgphy to GENERIC


Revision tags: OPENBSD_2_7_BASE
# 1.6 15-Feb-2000 jason

make sure to call ether_{add,del}multi() as appropriate in xxx_ioctl()


Revision tags: SMP_BASE kame_19991208
# 1.5 08-Dec-1999 aaron

branches: 1.5.2;
Remove unused #define cruft.


Revision tags: OPENBSD_2_6_BASE
# 1.4 22-Oct-1999 deraadt

fix some panic bugs; jason


# 1.3 04-Oct-1999 jason

m_new is the new mbuf, not m
fix calculation of buffer slot number


# 1.2 03-Oct-1999 jason

take advantage of m->m_ext.ext_handle for storing the softc
(instead of stashing it in the buffer)


# 1.1 01-Oct-1999 jason

driver for SysKonnect 984x gigabit ethernet adapters; from FreeBSD


# 1.195 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.194 11-Mar-2022 mpi

Constify struct cfattach.


# 1.193 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.192 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.191 10-Jul-2020 patrick

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

ok dlg@ tobhe@


# 1.190 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


Revision tags: 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.189 04-Jun-2017 dlg

use htolem32 and lemtoh32 instead of htole32 and letoh32.

saves about half a k on sparc64.


# 1.188 02-Jun-2017 dlg

handle 64bit dva in the tx path as well as the rx path.


# 1.187 01-Jun-2017 dlg

reorder ops in sk_start to avoid possibly rolling back ifq_deq.

instead of checking for space after beggining to deq a packet, check
for space before committing to handling a packet. this means we
can use ifq_dequeue instead of ifq_deq_begin/commit/rollback.

ok mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.186 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@


# 1.185 08-Jan-2017 visa

Use a macro for the Tx timeout value.

OK deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.184 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.183 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.182 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.181 24-Nov-2015 mpi

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


# 1.180 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.179 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.178 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.177 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.176 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.175 30-Apr-2015 mpi

Convert to if_input(), tweak and ok dlg@


# 1.174 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@


Revision tags: OPENBSD_5_7_BASE
# 1.173 22-Dec-2014 tedu

unifdef INET


# 1.172 20-Aug-2014 dlg

brad said i had some whitespace screwups in my previous diff. this cleans
them up and the others i found in this file.

no functional change.


# 1.171 20-Aug-2014 dlg

replace sks jumbo allocator with MCLGETI. the system provides jumbos in
the right shape now, we dont have to do it by hand all over the place
any more.

rework the rxr ring management to use if_rxring while here.

largely based on if_sk.c r1.152 and if_skvar.h r1.4 by kettenis.
tested by me on:

skc0 at pci3 dev 11 function 0 "Schneider & Koch SK-98xx" rev 0x12, GEnesis (0x0): apic 3 int 5
sk0 at skc0 port A: address 00:00:5a:99:8a:ec
xmphy0 at sk0 phy 0: XMAC II Gigabit PHY, rev. 2

and this from ian mcwilliam

skc0 at pci0 dev 9 function 0 "D-Link DGE-530T B1" rev 0x11, Yukon Lite (0x9): apic 2 int 17
sk0 at skc0 port A: address 00:17:9a:ba:b5:39
eephy0 at sk0 phy 0: 88E1011 Gigabit PHY, rev. 5

tested by brad@ too


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

Fewer <netinet/in_systm.h>


# 1.169 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.168 19-Apr-2014 henning

kill checksum offloading in sk.
it was RX only, nothing on the TX side
rather complex, might eat up (or more) offloading benefits in many cases
the hardware miscomputes the cksums sometimes, so we don't trust it
claiming a cksum is bad and re-do the cksum verification in sw then...
(but we trust it to not mark bad ones good? hmmmmmmmmm.)
diff was on tech for 3 months, nobody disagreed, everybody who spoke up
agrees or doesn't care.
pretty exactly a revert of the cksum offloading addition years ago, tested
by several, the only report i quickly find now is from David Higgs <higgsd
at gmail dot com>, thanks!


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

Sync activate code sequnces to if_msk.c as much as possible, in case
one of these is ever found in a suspend/hibernate system.


# 1.166 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.165 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_4_BASE
# 1.164 07-Mar-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok chris@


Revision tags: OPENBSD_5_3_BASE
# 1.163 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@


# 1.162 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


Revision tags: OPENBSD_5_2_BASE
# 1.161 24-Feb-2012 guenther

Correct the spelling of "transferred" and "transferring"

from Tobias Ulmer (tobiasu at tmux.org); ok jmc@, krw@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.160 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.159 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.158 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


Revision tags: OPENBSD_4_8_BASE
# 1.157 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.156 17-Oct-2009 martynas

use sc->sk_bsize in the unmap call too; ok theo


# 1.155 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.154 04-Oct-2009 deraadt

Merge over a bunch of detach logic from msk(4) so that this driver can
detach as well
ok kettenis


# 1.153 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_6_BASE
# 1.152 08-Jul-2009 sthen

revert MCLGETI for sk(4) for now. commit requested by deraadt@


# 1.151 30-Mar-2009 kettenis

Switch sk(4) over to using MCLGETI when allocating mbufs for the RX ring.
Another evil jumbo allocator bites the dust.


Revision tags: OPENBSD_4_5_BASE
# 1.150 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.149 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.148 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.147 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.146 24-May-2008 brad

Also recognize the Schneider & Koch SK-9821/SK-9843 adapters from
Fujitsu.


# 1.145 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.144 02-Mar-2008 brad

Change some spaces to tabs in the transmit functions.

ok kettenis@


# 1.143 17-Jan-2008 brad

Add splnet around mii_tick() in sk_yukon_tick().

ok kettenis@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.142 26-May-2007 reyk

separate the attach information from the status information with a colon.

suggested by deraadt@


# 1.141 22-May-2007 ray

%z in printf(9) is not the same as %z in printf(3). Change to %lu
and cast arg to ulong.

OK miod@.


# 1.140 07-May-2007 deraadt

shrink code by not using __inline without static; ok kettenis


Revision tags: OPENBSD_4_1_BASE
# 1.139 12-Feb-2007 pedro

Fix prototype, from brad@, no binary change


# 1.138 10-Feb-2007 krw

Move HASH_BITS constant to if_skreg.h as SK_HASH_BITS. Remove unused
code and an unnecessary comment, No functional change.

From brad@.


# 1.137 03-Feb-2007 kettenis

Fix typo; clear tx FIFO underrun IRQ as intended instead of rx FIFO overrun
IRQ. From brad@


# 1.136 18-Jan-2007 krw

Don't reinitialize card at every media change.

From Brad, tested by Brad, wilfried@ and Johan M:son Lindman.

ok wilfried@


# 1.135 05-Jan-2007 kettenis

For Yukon-based cards, pass MIIF_DOPAUSE to mii_attach().

From brad@


# 1.134 03-Jan-2007 kettenis

In sk_marv_miibus_writereg, wait for busy flag to clear instead of
continuing when busy flag set.


# 1.133 03-Jan-2007 krw

Don't say 'Marvell' twice for each sk/msk device in dmesg. No functional
change.

from brad@ ok mglocker@


# 1.132 06-Dec-2006 reyk

- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested on amd64/i386/sparc64

ok brad@ mglocker@


# 1.131 16-Nov-2006 brad

remove the small amount of code for Yukon-2 chipsets now that there is msk(4).


# 1.130 08-Nov-2006 kettenis

Make XMAC work on on big-endian systems.

help & ok jason@, ok brad@


# 1.129 16-Oct-2006 tom

Fix some "is is"s. ok otto@.


# 1.128 27-Sep-2006 brad

fix the use of LIST_INSERT_HEAD in [m]sk_alloc_jumbo_mem().


# 1.127 26-Sep-2006 brad

Set sk_jumbo_buf to NULL if malloc() fails in the for loop within
[m]sk_alloc_jumbo_mem().


# 1.126 18-Sep-2006 brad

g/c unused SK_{SET,CLR}BIT macros

From riz@NetBSD


Revision tags: OPENBSD_4_0_BASE
# 1.125 17-Aug-2006 brad

cosmetic tweaks.


# 1.124 17-Aug-2006 brad

remove PCI ids which msk(4) will match against from sk(4).


# 1.123 09-Aug-2006 brad

revert rev 1.119 as this seems to cause problems with some PHY.


# 1.122 04-Aug-2006 brad

and the same goes for sk_init_yukon().


# 1.121 04-Aug-2006 brad

remove now redundant promiscuous mode handling code from sk_init_xmac().


# 1.120 04-Aug-2006 brad

refactor the promiscuous mode handling code and simplify the ioctl handler.


# 1.119 04-Aug-2006 brad

Fix busy check for PHY write operation with Yukon chips.

From yongari@FreeBSD


# 1.118 30-Jul-2006 brad

Add more strict receive path packet validation routine. Previously
the driver could pass corrupted packets to the upper layer under
certain conditions.

From yongari@FreeBSD


# 1.117 23-Jul-2006 brad

improved Yukon init routine with proper workaround for the PHY COMA mode.

From yongari@FreeBSD


# 1.116 22-Jun-2006 brad

Add appropriate swapping for big-endian systems. Allows sk(4) to work
on macppc and sparc64.

ok reyk@


# 1.115 22-Jun-2006 brad

adjust PCI ids.


# 1.114 17-Jun-2006 brad

add sys/timeout.h


# 1.113 17-Jun-2006 brad

remove some whitespace.


# 1.112 15-Jun-2006 brad

Fix watchdog timeout errors seen on a few systems.

The SK-NET GENESIS document says reading the SK_ISSR register should stop
generating further interrupts, but it seems there is the possibility
of losing interrupts between reading the SK_ISSR register and determining
which interrupts have been reported. To cope with this situation we
continuously read the SK_ISSR register until there are no interrupts.

However, it seems that the above workaround does not fix all cases.
Add workaround code that tries to protect against false alarms from
the watchdog handler by trying to reclaim pending Tx descriptors
before resetting the hardware.

This should fix occasional watchdog timeouts seen with this driver.

From FreeBSD


# 1.111 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.110 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.109 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.108 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.107 01-May-2006 brad

Activate Tx descriptor poll timer in order to protect possible loss
of SK_TXBMU_TX_START command. Previously the driver continuously issued
SK_TXBMU_TX_START when it notices pending Tx descriptors not processed
yet in interrupt handler. That approach would add additional PCI
write access overhead under high Tx load situations and it might fail
if the first SK_TXBMU_TX_START was lost and no interrupt is generated
from the first SK_TXBMU_TX_START command.

From FreeBSD


# 1.106 01-May-2006 brad

Added Rx/Tx FIFO flush support for Yukon

From FreeBSD


# 1.105 01-May-2006 brad

A new function sk_yukon_tick(), to handle auto-negotiation properly for
Yukon-based adapters.

From FreeBSD


# 1.104 30-Apr-2006 brad

- Use SK_IS_GENESIS/SK_IS_YUKON where appropriate
- Remove SK_YUKON_FAMILY


# 1.103 30-Apr-2006 brad

- Interrupt handler now checks shared interrupt source and protects
the interrupt handler from NULL pointer dereference which was caused
by odd status word value. The status word can return 0xffffffff if the
cable is unplugged while Rx/Tx/auto-negotiation is in progress.

From FreeBSD


# 1.102 30-Apr-2006 brad

Update if_oerrors if we encounter watchdog error.

From FreeBSD


# 1.101 30-Apr-2006 brad

- Added/corrected register definitions for Yukon.
(Register information from Linux skge driver.)

From FreeBSD


# 1.100 23-Apr-2006 brad

some more ANSI, KNF and other tidying up.


# 1.99 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.98 17-Apr-2006 brad

If there is a timeout while writing to the PHY in
sk_marv_miibus_writereg() then print a message
indicating so, as done in the XMAC case.


# 1.97 17-Apr-2006 brad

Coviery CID 1108: Avoid NULL pointer deref.

Coverity CID 1105: Avoid NULL deref.

From NetBSD


# 1.96 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.95 13-Feb-2006 brad

add some ASIC revisions to the various switch cases and identify
some newer revs.


# 1.94 09-Feb-2006 brad

sync PCI id.


# 1.93 22-Dec-2005 brad

re-work PHY setup, media handling and dual-port detection.

Based on the Marvell FreeBSD driver.


# 1.92 16-Dec-2005 brad

remove unused code to use IO space.


# 1.91 15-Dec-2005 brad

merge printing of the revision and the interrupt string into one printf.


# 1.90 10-Dec-2005 brad

sk_shutdown -> skc_shutdown and register the shutdown function with
shutdownhook_establish().


# 1.89 10-Dec-2005 brad

shrink dmesg entry by one line by merging the chipset revision into
the skc line and fix various error condition printf's in skc_attach(),
sk_attach() and sk_alloc_jumbo_mem() so the messages will be displayed
properly.

ok krw@


# 1.88 26-Nov-2005 brad

fix interrupt moderation timer frequencies for Yukon and Yukon-II based
chips.

From Jeff Rizzo on NetBSD's tech-net list, based on the Marvell
sk98lin Linux driver, and also matches what the Marvell FreeBSD
does.


# 1.87 15-Nov-2005 brad

more accurately reflect the naming scheme of the Marvell Yukon devices with there
pcidevs entries.

Based on information from the Marvell Yukon/Yukon-II FreeBSD driver.


# 1.86 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.85 15-Oct-2005 brad

add 2 new Yukon PCI ids and recognize Yukon-2 EC Ultra ASIC.


# 1.84 15-Oct-2005 brad

update Via and 3Com ids.


# 1.83 20-Sep-2005 brad

memory, media handling and a bunch of register definitions for Yukon-2.

From jason@


# 1.82 20-Sep-2005 brad

merge xmaciireg.h and yukonreg.h into if_skreg.h


# 1.81 20-Sep-2005 brad

shuffle some stuff from skreg to skvar


# 1.80 17-Sep-2005 brad

add media detection and dual port detection for Yukon-2.

from jason@


# 1.79 16-Sep-2005 brad

- remove code to read PCI VPD as we do not use that anymore.
- remove some FreeBSD-ism's: struct resource *'s.
- fail more gracefully in sk_probe() instead of in sk_attach()
for newer unsupported ASIC revisions.

From jason@


Revision tags: OPENBSD_3_8_BASE
# 1.78 29-Aug-2005 brad

- use pci_mapreg_type() to fix some systems that would fail to attach
sk(4) with "can't map mem space".
- add missing newline for failure case of pci_intr_establish().

ok deraadt@


# 1.77 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.76 24-Jul-2005 fgsch

simplify error paths and add some missing ones; brad@ ok.
deallocation for jumbo memory left.


# 1.75 22-Jul-2005 brad

- sync sk_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()
- oops, forgot to remove a line in sk_rxeof()


# 1.74 22-Jul-2005 brad

also take the PCI subsystem id into consideration when trying to probe
for Linksys EG1032 cards, that way we do not try and attach to newer
rev 3 cards that use the RealTek 8169S chipset.


# 1.73 21-Jul-2005 brad

- add bus_dmamap_sync()'s; From NetBSD
- use pci_mapreg_map()
- remove unnecessary splimp() usage in skc_attach()
- make sure to disestablish the interrupt on failure

Tested by a few end-users.


# 1.72 14-Jul-2005 brad

add D-Link PCI id.

From: jsg@


# 1.71 12-Jul-2005 brad

remove unused prototype sk_free_jumbo_mem


# 1.70 12-Jul-2005 brad

free resources for Jumbo buffers in sk_stop().

ok deraadt, krw, beck


# 1.69 02-Jul-2005 brad

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


# 1.68 02-Jul-2005 brad

- mbuf external storage is of (caddr_t), not (caddr_t *).
- check for MTU being too small with ETHERMIN
- don't bother reseting the card since it'll default to allowing Jumbos


# 1.67 17-May-2005 jason

remove spurious bpf_mtap (I think it's leftover debugging code from a year ago)


# 1.66 16-May-2005 brad

add a newline here


# 1.65 11-May-2005 brad

remove comment which is not valid anymore


# 1.64 11-May-2005 brad

- Also match on Yukon LP's for the Lite rev A0 test.
- Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().
- Take PHY out of reset for Yukon Lite rev A3. This resolves the
intermittent "no PHY found!" issue.

From FreeBSD

- Recognize some newer Yukon chipsets

ok krw@, tested by krw@ and a few others, mostly with LOM Lite A3's but
also with some other ASIC revs too.


# 1.63 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.62 18-Mar-2005 brad

fail to attach with a printf instead of a panic for newer yet unsupported
Yukon-2-based cards.

ok deraadt@


# 1.61 12-Mar-2005 brad

add a bunch of PCI ids from the SysKonnect sk98lin driver.


# 1.60 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.59 02-Jan-2005 brad

cleanup and better ram sizing.


# 1.58 01-Jan-2005 brad

better chip/card identification.

From NetBSD

ok krw@


# 1.57 01-Jan-2005 brad

rev 1.92

only clear the IFF_OACTIVE flag when we have a chance of being able to
queue a packet to the hardware... instead of when the hardware queue is
empty..

don't initalize cur_tx now that it doesn't need to be...

rev 1.90

_OACTIVE is now handled better...

From FreeBSD

ok krw@


# 1.56 01-Jan-2005 krw

Don't initialize the card (and start an autonegotiation!) every time
the IP address changes. Makes 'dhclient sk0' invocations way faster
and more consistant. i.e. one DHCPREQUEST elicts the DHCPACK.

ok brad@ 'Wow. Great Idea.' deraadt@.


# 1.55 22-Dec-2004 brad

- add missing braces for SIOCSIFMTU switch case.
- allow reception of Jumbo frames all the time on GEnesis based cards,
same as Yukon based cards.

ok krw@ mcbride@


# 1.54 14-Dec-2004 krw

Fix off-by-one. From FreeBSD r1.87. Also in NetBSD. Field being filled
(sk_vpd_readonly) is not currently used, but the memory being tromped
on might be.

ok millert@.


# 1.53 08-Dec-2004 brad

use ETHER_MAX_LEN


# 1.52 08-Dec-2004 krw

Enable jumbo frames on Yukon varients of sk(4).

ok mcbride@.


# 1.51 16-Nov-2004 brad

Lower interrupt moderation timer to decrease service latency.

From NetBSD

ok deraadt@


# 1.50 16-Nov-2004 brad

back out previous commit and put the right change in which corresponds
to what the previous commit message said...

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).


# 1.49 16-Nov-2004 brad

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).

From NetBSD

ok henning@ mcbride@


# 1.48 11-Nov-2004 brad

- Fix Yukon ram sizing.
- Keep tx queue running by kicking the tx bmu repeatedly.
- Handle if_timer a bit better.

From NetBSD

ok deraadt@


# 1.47 14-Oct-2004 brad

Bail out quietly if the eeprom appears to be missing or empty. Fixes
support for D-Link DGE-530T adapters.

From: FreeBSD via Blake Willis <blake at 2112 dot net>

ok mcbride@


# 1.46 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
# 1.45 20-Aug-2004 deraadt

a belkin ID on a sk card


# 1.44 19-Aug-2004 mcbride

Don't complain about lack of jumbo storage when processing incoming packets
unless we're debugging.


# 1.43 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


# 1.42 04-Aug-2004 mcbride

Make jumbo frames work.
- allocate and manage our own memory for rx packets rather than using
mbuf clusters; code for this lifted from if_bge.c
- pass the correct size to bus_dmamap_create()

ok deraadt@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.41 29-May-2004 naddy

replace hand-rolled CRC calculation in multicast hash setup with calls to
ether_crc32_*(); ok mcbride@


# 1.40 24-May-2004 naddy

Make Yukon-style adapters also set up the multicast filter in sk_init().
This fixes various multicast-related problems. ok henning@


# 1.39 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.38 09-Mar-2004 matthieu

Fix multicast on recent sk chipsets. Adapted from a patch by Keith Mitchell
in <http://lists.freebsd.org/pipermail/freebsd-hardware/2003-December/000851.html>
Ok deraadt@.


# 1.37 17-Dec-2003 jason

not qualifying a product based on vendor AND product ID just bugs me


# 1.36 17-Dec-2003 jason

marvell skv2 (smc9452TX); from freebsd


# 1.35 17-Dec-2003 jason

add support for linksys (eg1032v2, eg1064v2) and dlink (dge530t); from NetBSD


# 1.34 13-Oct-2003 jason

rx checksum offload support (based on earlier code from aaron@, but with
fixes by me). Note: sk v1 chips can sometimes compute an incorrect cksum.
To deal with that, we never set the "bad" flags. Ie. if the card says it's
good, we assume it's good. If the card says it's bad, we fall back to
software. Ugly? You betcha.


Revision tags: OPENBSD_3_4_BASE
# 1.33 12-Aug-2003 nate

add/update my copyright


# 1.32 01-Aug-2003 nate

Support for new Marvell based Gigabit Ethernet adapters
ok deraadt@


Revision tags: UBC_SYNC_A
# 1.31 14-May-2003 nate

Makefile sk(4) use bus_dma
ok jason


# 1.30 08-May-2003 nate

a bit more cleanup


# 1.29 08-May-2003 nate

ansify, clean up formatting, remove useless return statements.
ok jason


Revision tags: OPENBSD_3_3_BASE
# 1.28 12-Mar-2003 nate

sk is capable of transmitting and receiving longer packets for 802.1q vlans
thanks to David Gwynne <loki@niteshade.net>. ok jason@ deraadt@


# 1.27 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.26 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.25 08-Jun-2002 jason

add missing ioctl support for SIOCSIFMTU


# 1.24 04-Jun-2002 deraadt

spelling; raj@cerias.purdue.edu


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

First round of __P removal in sys


# 1.22 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.21 15-Feb-2002 nordin

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


# 1.20 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


Revision tags: UBC_BASE
# 1.19 06-Nov-2001 miod

branches: 1.19.2;
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.18 05-Oct-2001 nate

use positive logic for match


# 1.17 11-Sep-2001 miod

Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.16 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.15 15-Aug-2001 jason

Add some stuff missed in a previous FreeBSD merge... Fixes the problem where
sk busy loops when carrier is lost until it returns; based on patch from
david langhorst <dirt@monkey.org> and tested by John Ladwig <jladwig@mango.lioness.net>


# 1.14 12-Aug-2001 mickey

remove redundant vm includes


# 1.13 25-Jun-2001 fgsch

trivial ether_input_mbuf() conversion.


Revision tags: OPENBSD_2_9_BASE
# 1.12 29-Mar-2001 jason

From FreeBSD:
- Call mii_pollstat() after we bring up the link on a 1000baseTX card
after autoneg so we make sure to set the link state and duplex mode
correctly.
- Make sure to set the 'ignore pause frames' bit on the XMAC.
- Small linewrap fix.
- Add actual URL for XMAC II datasheet in comments.


# 1.11 25-Mar-2001 csapuntz

Missing splx(s). Thanks to Dawson and team for finding this one


# 1.10 20-Feb-2001 mickey

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


Revision tags: OPENBSD_2_8_BASE
# 1.9 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.8 04-Sep-2000 deraadt

printing XaQti on 5 consecutive lines is stupid


# 1.7 29-Aug-2000 jason

From FreeBSD: split out the support for XMAC-II phys and other phys
add xmphy & brgphy to GENERIC


Revision tags: OPENBSD_2_7_BASE
# 1.6 15-Feb-2000 jason

make sure to call ether_{add,del}multi() as appropriate in xxx_ioctl()


Revision tags: SMP_BASE kame_19991208
# 1.5 08-Dec-1999 aaron

branches: 1.5.2;
Remove unused #define cruft.


Revision tags: OPENBSD_2_6_BASE
# 1.4 22-Oct-1999 deraadt

fix some panic bugs; jason


# 1.3 04-Oct-1999 jason

m_new is the new mbuf, not m
fix calculation of buffer slot number


# 1.2 03-Oct-1999 jason

take advantage of m->m_ext.ext_handle for storing the softc
(instead of stashing it in the buffer)


# 1.1 01-Oct-1999 jason

driver for SysKonnect 984x gigabit ethernet adapters; from FreeBSD


# 1.194 11-Mar-2022 mpi

Constify struct cfattach.


# 1.193 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.192 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.191 10-Jul-2020 patrick

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

ok dlg@ tobhe@


# 1.190 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


Revision tags: 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.189 04-Jun-2017 dlg

use htolem32 and lemtoh32 instead of htole32 and letoh32.

saves about half a k on sparc64.


# 1.188 02-Jun-2017 dlg

handle 64bit dva in the tx path as well as the rx path.


# 1.187 01-Jun-2017 dlg

reorder ops in sk_start to avoid possibly rolling back ifq_deq.

instead of checking for space after beggining to deq a packet, check
for space before committing to handling a packet. this means we
can use ifq_dequeue instead of ifq_deq_begin/commit/rollback.

ok mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.186 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@


# 1.185 08-Jan-2017 visa

Use a macro for the Tx timeout value.

OK deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.184 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.183 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.182 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.181 24-Nov-2015 mpi

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


# 1.180 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.179 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.178 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.177 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.176 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.175 30-Apr-2015 mpi

Convert to if_input(), tweak and ok dlg@


# 1.174 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@


Revision tags: OPENBSD_5_7_BASE
# 1.173 22-Dec-2014 tedu

unifdef INET


# 1.172 20-Aug-2014 dlg

brad said i had some whitespace screwups in my previous diff. this cleans
them up and the others i found in this file.

no functional change.


# 1.171 20-Aug-2014 dlg

replace sks jumbo allocator with MCLGETI. the system provides jumbos in
the right shape now, we dont have to do it by hand all over the place
any more.

rework the rxr ring management to use if_rxring while here.

largely based on if_sk.c r1.152 and if_skvar.h r1.4 by kettenis.
tested by me on:

skc0 at pci3 dev 11 function 0 "Schneider & Koch SK-98xx" rev 0x12, GEnesis (0x0): apic 3 int 5
sk0 at skc0 port A: address 00:00:5a:99:8a:ec
xmphy0 at sk0 phy 0: XMAC II Gigabit PHY, rev. 2

and this from ian mcwilliam

skc0 at pci0 dev 9 function 0 "D-Link DGE-530T B1" rev 0x11, Yukon Lite (0x9): apic 2 int 17
sk0 at skc0 port A: address 00:17:9a:ba:b5:39
eephy0 at sk0 phy 0: 88E1011 Gigabit PHY, rev. 5

tested by brad@ too


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

Fewer <netinet/in_systm.h>


# 1.169 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.168 19-Apr-2014 henning

kill checksum offloading in sk.
it was RX only, nothing on the TX side
rather complex, might eat up (or more) offloading benefits in many cases
the hardware miscomputes the cksums sometimes, so we don't trust it
claiming a cksum is bad and re-do the cksum verification in sw then...
(but we trust it to not mark bad ones good? hmmmmmmmmm.)
diff was on tech for 3 months, nobody disagreed, everybody who spoke up
agrees or doesn't care.
pretty exactly a revert of the cksum offloading addition years ago, tested
by several, the only report i quickly find now is from David Higgs <higgsd
at gmail dot com>, thanks!


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

Sync activate code sequnces to if_msk.c as much as possible, in case
one of these is ever found in a suspend/hibernate system.


# 1.166 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.165 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_4_BASE
# 1.164 07-Mar-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok chris@


Revision tags: OPENBSD_5_3_BASE
# 1.163 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@


# 1.162 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


Revision tags: OPENBSD_5_2_BASE
# 1.161 24-Feb-2012 guenther

Correct the spelling of "transferred" and "transferring"

from Tobias Ulmer (tobiasu at tmux.org); ok jmc@, krw@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.160 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.159 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.158 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


Revision tags: OPENBSD_4_8_BASE
# 1.157 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.156 17-Oct-2009 martynas

use sc->sk_bsize in the unmap call too; ok theo


# 1.155 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.154 04-Oct-2009 deraadt

Merge over a bunch of detach logic from msk(4) so that this driver can
detach as well
ok kettenis


# 1.153 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_6_BASE
# 1.152 08-Jul-2009 sthen

revert MCLGETI for sk(4) for now. commit requested by deraadt@


# 1.151 30-Mar-2009 kettenis

Switch sk(4) over to using MCLGETI when allocating mbufs for the RX ring.
Another evil jumbo allocator bites the dust.


Revision tags: OPENBSD_4_5_BASE
# 1.150 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.149 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.148 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.147 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.146 24-May-2008 brad

Also recognize the Schneider & Koch SK-9821/SK-9843 adapters from
Fujitsu.


# 1.145 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.144 02-Mar-2008 brad

Change some spaces to tabs in the transmit functions.

ok kettenis@


# 1.143 17-Jan-2008 brad

Add splnet around mii_tick() in sk_yukon_tick().

ok kettenis@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.142 26-May-2007 reyk

separate the attach information from the status information with a colon.

suggested by deraadt@


# 1.141 22-May-2007 ray

%z in printf(9) is not the same as %z in printf(3). Change to %lu
and cast arg to ulong.

OK miod@.


# 1.140 07-May-2007 deraadt

shrink code by not using __inline without static; ok kettenis


Revision tags: OPENBSD_4_1_BASE
# 1.139 12-Feb-2007 pedro

Fix prototype, from brad@, no binary change


# 1.138 10-Feb-2007 krw

Move HASH_BITS constant to if_skreg.h as SK_HASH_BITS. Remove unused
code and an unnecessary comment, No functional change.

From brad@.


# 1.137 03-Feb-2007 kettenis

Fix typo; clear tx FIFO underrun IRQ as intended instead of rx FIFO overrun
IRQ. From brad@


# 1.136 18-Jan-2007 krw

Don't reinitialize card at every media change.

From Brad, tested by Brad, wilfried@ and Johan M:son Lindman.

ok wilfried@


# 1.135 05-Jan-2007 kettenis

For Yukon-based cards, pass MIIF_DOPAUSE to mii_attach().

From brad@


# 1.134 03-Jan-2007 kettenis

In sk_marv_miibus_writereg, wait for busy flag to clear instead of
continuing when busy flag set.


# 1.133 03-Jan-2007 krw

Don't say 'Marvell' twice for each sk/msk device in dmesg. No functional
change.

from brad@ ok mglocker@


# 1.132 06-Dec-2006 reyk

- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested on amd64/i386/sparc64

ok brad@ mglocker@


# 1.131 16-Nov-2006 brad

remove the small amount of code for Yukon-2 chipsets now that there is msk(4).


# 1.130 08-Nov-2006 kettenis

Make XMAC work on on big-endian systems.

help & ok jason@, ok brad@


# 1.129 16-Oct-2006 tom

Fix some "is is"s. ok otto@.


# 1.128 27-Sep-2006 brad

fix the use of LIST_INSERT_HEAD in [m]sk_alloc_jumbo_mem().


# 1.127 26-Sep-2006 brad

Set sk_jumbo_buf to NULL if malloc() fails in the for loop within
[m]sk_alloc_jumbo_mem().


# 1.126 18-Sep-2006 brad

g/c unused SK_{SET,CLR}BIT macros

From riz@NetBSD


Revision tags: OPENBSD_4_0_BASE
# 1.125 17-Aug-2006 brad

cosmetic tweaks.


# 1.124 17-Aug-2006 brad

remove PCI ids which msk(4) will match against from sk(4).


# 1.123 09-Aug-2006 brad

revert rev 1.119 as this seems to cause problems with some PHY.


# 1.122 04-Aug-2006 brad

and the same goes for sk_init_yukon().


# 1.121 04-Aug-2006 brad

remove now redundant promiscuous mode handling code from sk_init_xmac().


# 1.120 04-Aug-2006 brad

refactor the promiscuous mode handling code and simplify the ioctl handler.


# 1.119 04-Aug-2006 brad

Fix busy check for PHY write operation with Yukon chips.

From yongari@FreeBSD


# 1.118 30-Jul-2006 brad

Add more strict receive path packet validation routine. Previously
the driver could pass corrupted packets to the upper layer under
certain conditions.

From yongari@FreeBSD


# 1.117 23-Jul-2006 brad

improved Yukon init routine with proper workaround for the PHY COMA mode.

From yongari@FreeBSD


# 1.116 22-Jun-2006 brad

Add appropriate swapping for big-endian systems. Allows sk(4) to work
on macppc and sparc64.

ok reyk@


# 1.115 22-Jun-2006 brad

adjust PCI ids.


# 1.114 17-Jun-2006 brad

add sys/timeout.h


# 1.113 17-Jun-2006 brad

remove some whitespace.


# 1.112 15-Jun-2006 brad

Fix watchdog timeout errors seen on a few systems.

The SK-NET GENESIS document says reading the SK_ISSR register should stop
generating further interrupts, but it seems there is the possibility
of losing interrupts between reading the SK_ISSR register and determining
which interrupts have been reported. To cope with this situation we
continuously read the SK_ISSR register until there are no interrupts.

However, it seems that the above workaround does not fix all cases.
Add workaround code that tries to protect against false alarms from
the watchdog handler by trying to reclaim pending Tx descriptors
before resetting the hardware.

This should fix occasional watchdog timeouts seen with this driver.

From FreeBSD


# 1.111 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.110 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.109 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.108 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.107 01-May-2006 brad

Activate Tx descriptor poll timer in order to protect possible loss
of SK_TXBMU_TX_START command. Previously the driver continuously issued
SK_TXBMU_TX_START when it notices pending Tx descriptors not processed
yet in interrupt handler. That approach would add additional PCI
write access overhead under high Tx load situations and it might fail
if the first SK_TXBMU_TX_START was lost and no interrupt is generated
from the first SK_TXBMU_TX_START command.

From FreeBSD


# 1.106 01-May-2006 brad

Added Rx/Tx FIFO flush support for Yukon

From FreeBSD


# 1.105 01-May-2006 brad

A new function sk_yukon_tick(), to handle auto-negotiation properly for
Yukon-based adapters.

From FreeBSD


# 1.104 30-Apr-2006 brad

- Use SK_IS_GENESIS/SK_IS_YUKON where appropriate
- Remove SK_YUKON_FAMILY


# 1.103 30-Apr-2006 brad

- Interrupt handler now checks shared interrupt source and protects
the interrupt handler from NULL pointer dereference which was caused
by odd status word value. The status word can return 0xffffffff if the
cable is unplugged while Rx/Tx/auto-negotiation is in progress.

From FreeBSD


# 1.102 30-Apr-2006 brad

Update if_oerrors if we encounter watchdog error.

From FreeBSD


# 1.101 30-Apr-2006 brad

- Added/corrected register definitions for Yukon.
(Register information from Linux skge driver.)

From FreeBSD


# 1.100 23-Apr-2006 brad

some more ANSI, KNF and other tidying up.


# 1.99 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.98 17-Apr-2006 brad

If there is a timeout while writing to the PHY in
sk_marv_miibus_writereg() then print a message
indicating so, as done in the XMAC case.


# 1.97 17-Apr-2006 brad

Coviery CID 1108: Avoid NULL pointer deref.

Coverity CID 1105: Avoid NULL deref.

From NetBSD


# 1.96 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.95 13-Feb-2006 brad

add some ASIC revisions to the various switch cases and identify
some newer revs.


# 1.94 09-Feb-2006 brad

sync PCI id.


# 1.93 22-Dec-2005 brad

re-work PHY setup, media handling and dual-port detection.

Based on the Marvell FreeBSD driver.


# 1.92 16-Dec-2005 brad

remove unused code to use IO space.


# 1.91 15-Dec-2005 brad

merge printing of the revision and the interrupt string into one printf.


# 1.90 10-Dec-2005 brad

sk_shutdown -> skc_shutdown and register the shutdown function with
shutdownhook_establish().


# 1.89 10-Dec-2005 brad

shrink dmesg entry by one line by merging the chipset revision into
the skc line and fix various error condition printf's in skc_attach(),
sk_attach() and sk_alloc_jumbo_mem() so the messages will be displayed
properly.

ok krw@


# 1.88 26-Nov-2005 brad

fix interrupt moderation timer frequencies for Yukon and Yukon-II based
chips.

From Jeff Rizzo on NetBSD's tech-net list, based on the Marvell
sk98lin Linux driver, and also matches what the Marvell FreeBSD
does.


# 1.87 15-Nov-2005 brad

more accurately reflect the naming scheme of the Marvell Yukon devices with there
pcidevs entries.

Based on information from the Marvell Yukon/Yukon-II FreeBSD driver.


# 1.86 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.85 15-Oct-2005 brad

add 2 new Yukon PCI ids and recognize Yukon-2 EC Ultra ASIC.


# 1.84 15-Oct-2005 brad

update Via and 3Com ids.


# 1.83 20-Sep-2005 brad

memory, media handling and a bunch of register definitions for Yukon-2.

From jason@


# 1.82 20-Sep-2005 brad

merge xmaciireg.h and yukonreg.h into if_skreg.h


# 1.81 20-Sep-2005 brad

shuffle some stuff from skreg to skvar


# 1.80 17-Sep-2005 brad

add media detection and dual port detection for Yukon-2.

from jason@


# 1.79 16-Sep-2005 brad

- remove code to read PCI VPD as we do not use that anymore.
- remove some FreeBSD-ism's: struct resource *'s.
- fail more gracefully in sk_probe() instead of in sk_attach()
for newer unsupported ASIC revisions.

From jason@


Revision tags: OPENBSD_3_8_BASE
# 1.78 29-Aug-2005 brad

- use pci_mapreg_type() to fix some systems that would fail to attach
sk(4) with "can't map mem space".
- add missing newline for failure case of pci_intr_establish().

ok deraadt@


# 1.77 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.76 24-Jul-2005 fgsch

simplify error paths and add some missing ones; brad@ ok.
deallocation for jumbo memory left.


# 1.75 22-Jul-2005 brad

- sync sk_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()
- oops, forgot to remove a line in sk_rxeof()


# 1.74 22-Jul-2005 brad

also take the PCI subsystem id into consideration when trying to probe
for Linksys EG1032 cards, that way we do not try and attach to newer
rev 3 cards that use the RealTek 8169S chipset.


# 1.73 21-Jul-2005 brad

- add bus_dmamap_sync()'s; From NetBSD
- use pci_mapreg_map()
- remove unnecessary splimp() usage in skc_attach()
- make sure to disestablish the interrupt on failure

Tested by a few end-users.


# 1.72 14-Jul-2005 brad

add D-Link PCI id.

From: jsg@


# 1.71 12-Jul-2005 brad

remove unused prototype sk_free_jumbo_mem


# 1.70 12-Jul-2005 brad

free resources for Jumbo buffers in sk_stop().

ok deraadt, krw, beck


# 1.69 02-Jul-2005 brad

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


# 1.68 02-Jul-2005 brad

- mbuf external storage is of (caddr_t), not (caddr_t *).
- check for MTU being too small with ETHERMIN
- don't bother reseting the card since it'll default to allowing Jumbos


# 1.67 17-May-2005 jason

remove spurious bpf_mtap (I think it's leftover debugging code from a year ago)


# 1.66 16-May-2005 brad

add a newline here


# 1.65 11-May-2005 brad

remove comment which is not valid anymore


# 1.64 11-May-2005 brad

- Also match on Yukon LP's for the Lite rev A0 test.
- Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().
- Take PHY out of reset for Yukon Lite rev A3. This resolves the
intermittent "no PHY found!" issue.

From FreeBSD

- Recognize some newer Yukon chipsets

ok krw@, tested by krw@ and a few others, mostly with LOM Lite A3's but
also with some other ASIC revs too.


# 1.63 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.62 18-Mar-2005 brad

fail to attach with a printf instead of a panic for newer yet unsupported
Yukon-2-based cards.

ok deraadt@


# 1.61 12-Mar-2005 brad

add a bunch of PCI ids from the SysKonnect sk98lin driver.


# 1.60 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.59 02-Jan-2005 brad

cleanup and better ram sizing.


# 1.58 01-Jan-2005 brad

better chip/card identification.

From NetBSD

ok krw@


# 1.57 01-Jan-2005 brad

rev 1.92

only clear the IFF_OACTIVE flag when we have a chance of being able to
queue a packet to the hardware... instead of when the hardware queue is
empty..

don't initalize cur_tx now that it doesn't need to be...

rev 1.90

_OACTIVE is now handled better...

From FreeBSD

ok krw@


# 1.56 01-Jan-2005 krw

Don't initialize the card (and start an autonegotiation!) every time
the IP address changes. Makes 'dhclient sk0' invocations way faster
and more consistant. i.e. one DHCPREQUEST elicts the DHCPACK.

ok brad@ 'Wow. Great Idea.' deraadt@.


# 1.55 22-Dec-2004 brad

- add missing braces for SIOCSIFMTU switch case.
- allow reception of Jumbo frames all the time on GEnesis based cards,
same as Yukon based cards.

ok krw@ mcbride@


# 1.54 14-Dec-2004 krw

Fix off-by-one. From FreeBSD r1.87. Also in NetBSD. Field being filled
(sk_vpd_readonly) is not currently used, but the memory being tromped
on might be.

ok millert@.


# 1.53 08-Dec-2004 brad

use ETHER_MAX_LEN


# 1.52 08-Dec-2004 krw

Enable jumbo frames on Yukon varients of sk(4).

ok mcbride@.


# 1.51 16-Nov-2004 brad

Lower interrupt moderation timer to decrease service latency.

From NetBSD

ok deraadt@


# 1.50 16-Nov-2004 brad

back out previous commit and put the right change in which corresponds
to what the previous commit message said...

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).


# 1.49 16-Nov-2004 brad

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).

From NetBSD

ok henning@ mcbride@


# 1.48 11-Nov-2004 brad

- Fix Yukon ram sizing.
- Keep tx queue running by kicking the tx bmu repeatedly.
- Handle if_timer a bit better.

From NetBSD

ok deraadt@


# 1.47 14-Oct-2004 brad

Bail out quietly if the eeprom appears to be missing or empty. Fixes
support for D-Link DGE-530T adapters.

From: FreeBSD via Blake Willis <blake at 2112 dot net>

ok mcbride@


# 1.46 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
# 1.45 20-Aug-2004 deraadt

a belkin ID on a sk card


# 1.44 19-Aug-2004 mcbride

Don't complain about lack of jumbo storage when processing incoming packets
unless we're debugging.


# 1.43 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


# 1.42 04-Aug-2004 mcbride

Make jumbo frames work.
- allocate and manage our own memory for rx packets rather than using
mbuf clusters; code for this lifted from if_bge.c
- pass the correct size to bus_dmamap_create()

ok deraadt@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.41 29-May-2004 naddy

replace hand-rolled CRC calculation in multicast hash setup with calls to
ether_crc32_*(); ok mcbride@


# 1.40 24-May-2004 naddy

Make Yukon-style adapters also set up the multicast filter in sk_init().
This fixes various multicast-related problems. ok henning@


# 1.39 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.38 09-Mar-2004 matthieu

Fix multicast on recent sk chipsets. Adapted from a patch by Keith Mitchell
in <http://lists.freebsd.org/pipermail/freebsd-hardware/2003-December/000851.html>
Ok deraadt@.


# 1.37 17-Dec-2003 jason

not qualifying a product based on vendor AND product ID just bugs me


# 1.36 17-Dec-2003 jason

marvell skv2 (smc9452TX); from freebsd


# 1.35 17-Dec-2003 jason

add support for linksys (eg1032v2, eg1064v2) and dlink (dge530t); from NetBSD


# 1.34 13-Oct-2003 jason

rx checksum offload support (based on earlier code from aaron@, but with
fixes by me). Note: sk v1 chips can sometimes compute an incorrect cksum.
To deal with that, we never set the "bad" flags. Ie. if the card says it's
good, we assume it's good. If the card says it's bad, we fall back to
software. Ugly? You betcha.


Revision tags: OPENBSD_3_4_BASE
# 1.33 12-Aug-2003 nate

add/update my copyright


# 1.32 01-Aug-2003 nate

Support for new Marvell based Gigabit Ethernet adapters
ok deraadt@


Revision tags: UBC_SYNC_A
# 1.31 14-May-2003 nate

Makefile sk(4) use bus_dma
ok jason


# 1.30 08-May-2003 nate

a bit more cleanup


# 1.29 08-May-2003 nate

ansify, clean up formatting, remove useless return statements.
ok jason


Revision tags: OPENBSD_3_3_BASE
# 1.28 12-Mar-2003 nate

sk is capable of transmitting and receiving longer packets for 802.1q vlans
thanks to David Gwynne <loki@niteshade.net>. ok jason@ deraadt@


# 1.27 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.26 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.25 08-Jun-2002 jason

add missing ioctl support for SIOCSIFMTU


# 1.24 04-Jun-2002 deraadt

spelling; raj@cerias.purdue.edu


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

First round of __P removal in sys


# 1.22 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.21 15-Feb-2002 nordin

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


# 1.20 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


Revision tags: UBC_BASE
# 1.19 06-Nov-2001 miod

branches: 1.19.2;
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.18 05-Oct-2001 nate

use positive logic for match


# 1.17 11-Sep-2001 miod

Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.16 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.15 15-Aug-2001 jason

Add some stuff missed in a previous FreeBSD merge... Fixes the problem where
sk busy loops when carrier is lost until it returns; based on patch from
david langhorst <dirt@monkey.org> and tested by John Ladwig <jladwig@mango.lioness.net>


# 1.14 12-Aug-2001 mickey

remove redundant vm includes


# 1.13 25-Jun-2001 fgsch

trivial ether_input_mbuf() conversion.


Revision tags: OPENBSD_2_9_BASE
# 1.12 29-Mar-2001 jason

From FreeBSD:
- Call mii_pollstat() after we bring up the link on a 1000baseTX card
after autoneg so we make sure to set the link state and duplex mode
correctly.
- Make sure to set the 'ignore pause frames' bit on the XMAC.
- Small linewrap fix.
- Add actual URL for XMAC II datasheet in comments.


# 1.11 25-Mar-2001 csapuntz

Missing splx(s). Thanks to Dawson and team for finding this one


# 1.10 20-Feb-2001 mickey

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


Revision tags: OPENBSD_2_8_BASE
# 1.9 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.8 04-Sep-2000 deraadt

printing XaQti on 5 consecutive lines is stupid


# 1.7 29-Aug-2000 jason

From FreeBSD: split out the support for XMAC-II phys and other phys
add xmphy & brgphy to GENERIC


Revision tags: OPENBSD_2_7_BASE
# 1.6 15-Feb-2000 jason

make sure to call ether_{add,del}multi() as appropriate in xxx_ioctl()


Revision tags: SMP_BASE kame_19991208
# 1.5 08-Dec-1999 aaron

branches: 1.5.2;
Remove unused #define cruft.


Revision tags: OPENBSD_2_6_BASE
# 1.4 22-Oct-1999 deraadt

fix some panic bugs; jason


# 1.3 04-Oct-1999 jason

m_new is the new mbuf, not m
fix calculation of buffer slot number


# 1.2 03-Oct-1999 jason

take advantage of m->m_ext.ext_handle for storing the softc
(instead of stashing it in the buffer)


# 1.1 01-Oct-1999 jason

driver for SysKonnect 984x gigabit ethernet adapters; from FreeBSD


# 1.193 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.192 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.191 10-Jul-2020 patrick

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

ok dlg@ tobhe@


# 1.190 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


Revision tags: 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.189 04-Jun-2017 dlg

use htolem32 and lemtoh32 instead of htole32 and letoh32.

saves about half a k on sparc64.


# 1.188 02-Jun-2017 dlg

handle 64bit dva in the tx path as well as the rx path.


# 1.187 01-Jun-2017 dlg

reorder ops in sk_start to avoid possibly rolling back ifq_deq.

instead of checking for space after beggining to deq a packet, check
for space before committing to handling a packet. this means we
can use ifq_dequeue instead of ifq_deq_begin/commit/rollback.

ok mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.186 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@


# 1.185 08-Jan-2017 visa

Use a macro for the Tx timeout value.

OK deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.184 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.183 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.182 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.181 24-Nov-2015 mpi

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


# 1.180 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.179 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.178 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.177 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.176 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.175 30-Apr-2015 mpi

Convert to if_input(), tweak and ok dlg@


# 1.174 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@


Revision tags: OPENBSD_5_7_BASE
# 1.173 22-Dec-2014 tedu

unifdef INET


# 1.172 20-Aug-2014 dlg

brad said i had some whitespace screwups in my previous diff. this cleans
them up and the others i found in this file.

no functional change.


# 1.171 20-Aug-2014 dlg

replace sks jumbo allocator with MCLGETI. the system provides jumbos in
the right shape now, we dont have to do it by hand all over the place
any more.

rework the rxr ring management to use if_rxring while here.

largely based on if_sk.c r1.152 and if_skvar.h r1.4 by kettenis.
tested by me on:

skc0 at pci3 dev 11 function 0 "Schneider & Koch SK-98xx" rev 0x12, GEnesis (0x0): apic 3 int 5
sk0 at skc0 port A: address 00:00:5a:99:8a:ec
xmphy0 at sk0 phy 0: XMAC II Gigabit PHY, rev. 2

and this from ian mcwilliam

skc0 at pci0 dev 9 function 0 "D-Link DGE-530T B1" rev 0x11, Yukon Lite (0x9): apic 2 int 17
sk0 at skc0 port A: address 00:17:9a:ba:b5:39
eephy0 at sk0 phy 0: 88E1011 Gigabit PHY, rev. 5

tested by brad@ too


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

Fewer <netinet/in_systm.h>


# 1.169 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.168 19-Apr-2014 henning

kill checksum offloading in sk.
it was RX only, nothing on the TX side
rather complex, might eat up (or more) offloading benefits in many cases
the hardware miscomputes the cksums sometimes, so we don't trust it
claiming a cksum is bad and re-do the cksum verification in sw then...
(but we trust it to not mark bad ones good? hmmmmmmmmm.)
diff was on tech for 3 months, nobody disagreed, everybody who spoke up
agrees or doesn't care.
pretty exactly a revert of the cksum offloading addition years ago, tested
by several, the only report i quickly find now is from David Higgs <higgsd
at gmail dot com>, thanks!


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

Sync activate code sequnces to if_msk.c as much as possible, in case
one of these is ever found in a suspend/hibernate system.


# 1.166 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.165 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_4_BASE
# 1.164 07-Mar-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok chris@


Revision tags: OPENBSD_5_3_BASE
# 1.163 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@


# 1.162 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


Revision tags: OPENBSD_5_2_BASE
# 1.161 24-Feb-2012 guenther

Correct the spelling of "transferred" and "transferring"

from Tobias Ulmer (tobiasu at tmux.org); ok jmc@, krw@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.160 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.159 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.158 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


Revision tags: OPENBSD_4_8_BASE
# 1.157 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.156 17-Oct-2009 martynas

use sc->sk_bsize in the unmap call too; ok theo


# 1.155 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.154 04-Oct-2009 deraadt

Merge over a bunch of detach logic from msk(4) so that this driver can
detach as well
ok kettenis


# 1.153 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_6_BASE
# 1.152 08-Jul-2009 sthen

revert MCLGETI for sk(4) for now. commit requested by deraadt@


# 1.151 30-Mar-2009 kettenis

Switch sk(4) over to using MCLGETI when allocating mbufs for the RX ring.
Another evil jumbo allocator bites the dust.


Revision tags: OPENBSD_4_5_BASE
# 1.150 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.149 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.148 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.147 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.146 24-May-2008 brad

Also recognize the Schneider & Koch SK-9821/SK-9843 adapters from
Fujitsu.


# 1.145 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.144 02-Mar-2008 brad

Change some spaces to tabs in the transmit functions.

ok kettenis@


# 1.143 17-Jan-2008 brad

Add splnet around mii_tick() in sk_yukon_tick().

ok kettenis@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.142 26-May-2007 reyk

separate the attach information from the status information with a colon.

suggested by deraadt@


# 1.141 22-May-2007 ray

%z in printf(9) is not the same as %z in printf(3). Change to %lu
and cast arg to ulong.

OK miod@.


# 1.140 07-May-2007 deraadt

shrink code by not using __inline without static; ok kettenis


Revision tags: OPENBSD_4_1_BASE
# 1.139 12-Feb-2007 pedro

Fix prototype, from brad@, no binary change


# 1.138 10-Feb-2007 krw

Move HASH_BITS constant to if_skreg.h as SK_HASH_BITS. Remove unused
code and an unnecessary comment, No functional change.

From brad@.


# 1.137 03-Feb-2007 kettenis

Fix typo; clear tx FIFO underrun IRQ as intended instead of rx FIFO overrun
IRQ. From brad@


# 1.136 18-Jan-2007 krw

Don't reinitialize card at every media change.

From Brad, tested by Brad, wilfried@ and Johan M:son Lindman.

ok wilfried@


# 1.135 05-Jan-2007 kettenis

For Yukon-based cards, pass MIIF_DOPAUSE to mii_attach().

From brad@


# 1.134 03-Jan-2007 kettenis

In sk_marv_miibus_writereg, wait for busy flag to clear instead of
continuing when busy flag set.


# 1.133 03-Jan-2007 krw

Don't say 'Marvell' twice for each sk/msk device in dmesg. No functional
change.

from brad@ ok mglocker@


# 1.132 06-Dec-2006 reyk

- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested on amd64/i386/sparc64

ok brad@ mglocker@


# 1.131 16-Nov-2006 brad

remove the small amount of code for Yukon-2 chipsets now that there is msk(4).


# 1.130 08-Nov-2006 kettenis

Make XMAC work on on big-endian systems.

help & ok jason@, ok brad@


# 1.129 16-Oct-2006 tom

Fix some "is is"s. ok otto@.


# 1.128 27-Sep-2006 brad

fix the use of LIST_INSERT_HEAD in [m]sk_alloc_jumbo_mem().


# 1.127 26-Sep-2006 brad

Set sk_jumbo_buf to NULL if malloc() fails in the for loop within
[m]sk_alloc_jumbo_mem().


# 1.126 18-Sep-2006 brad

g/c unused SK_{SET,CLR}BIT macros

From riz@NetBSD


Revision tags: OPENBSD_4_0_BASE
# 1.125 17-Aug-2006 brad

cosmetic tweaks.


# 1.124 17-Aug-2006 brad

remove PCI ids which msk(4) will match against from sk(4).


# 1.123 09-Aug-2006 brad

revert rev 1.119 as this seems to cause problems with some PHY.


# 1.122 04-Aug-2006 brad

and the same goes for sk_init_yukon().


# 1.121 04-Aug-2006 brad

remove now redundant promiscuous mode handling code from sk_init_xmac().


# 1.120 04-Aug-2006 brad

refactor the promiscuous mode handling code and simplify the ioctl handler.


# 1.119 04-Aug-2006 brad

Fix busy check for PHY write operation with Yukon chips.

From yongari@FreeBSD


# 1.118 30-Jul-2006 brad

Add more strict receive path packet validation routine. Previously
the driver could pass corrupted packets to the upper layer under
certain conditions.

From yongari@FreeBSD


# 1.117 23-Jul-2006 brad

improved Yukon init routine with proper workaround for the PHY COMA mode.

From yongari@FreeBSD


# 1.116 22-Jun-2006 brad

Add appropriate swapping for big-endian systems. Allows sk(4) to work
on macppc and sparc64.

ok reyk@


# 1.115 22-Jun-2006 brad

adjust PCI ids.


# 1.114 17-Jun-2006 brad

add sys/timeout.h


# 1.113 17-Jun-2006 brad

remove some whitespace.


# 1.112 15-Jun-2006 brad

Fix watchdog timeout errors seen on a few systems.

The SK-NET GENESIS document says reading the SK_ISSR register should stop
generating further interrupts, but it seems there is the possibility
of losing interrupts between reading the SK_ISSR register and determining
which interrupts have been reported. To cope with this situation we
continuously read the SK_ISSR register until there are no interrupts.

However, it seems that the above workaround does not fix all cases.
Add workaround code that tries to protect against false alarms from
the watchdog handler by trying to reclaim pending Tx descriptors
before resetting the hardware.

This should fix occasional watchdog timeouts seen with this driver.

From FreeBSD


# 1.111 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.110 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.109 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.108 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.107 01-May-2006 brad

Activate Tx descriptor poll timer in order to protect possible loss
of SK_TXBMU_TX_START command. Previously the driver continuously issued
SK_TXBMU_TX_START when it notices pending Tx descriptors not processed
yet in interrupt handler. That approach would add additional PCI
write access overhead under high Tx load situations and it might fail
if the first SK_TXBMU_TX_START was lost and no interrupt is generated
from the first SK_TXBMU_TX_START command.

From FreeBSD


# 1.106 01-May-2006 brad

Added Rx/Tx FIFO flush support for Yukon

From FreeBSD


# 1.105 01-May-2006 brad

A new function sk_yukon_tick(), to handle auto-negotiation properly for
Yukon-based adapters.

From FreeBSD


# 1.104 30-Apr-2006 brad

- Use SK_IS_GENESIS/SK_IS_YUKON where appropriate
- Remove SK_YUKON_FAMILY


# 1.103 30-Apr-2006 brad

- Interrupt handler now checks shared interrupt source and protects
the interrupt handler from NULL pointer dereference which was caused
by odd status word value. The status word can return 0xffffffff if the
cable is unplugged while Rx/Tx/auto-negotiation is in progress.

From FreeBSD


# 1.102 30-Apr-2006 brad

Update if_oerrors if we encounter watchdog error.

From FreeBSD


# 1.101 30-Apr-2006 brad

- Added/corrected register definitions for Yukon.
(Register information from Linux skge driver.)

From FreeBSD


# 1.100 23-Apr-2006 brad

some more ANSI, KNF and other tidying up.


# 1.99 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.98 17-Apr-2006 brad

If there is a timeout while writing to the PHY in
sk_marv_miibus_writereg() then print a message
indicating so, as done in the XMAC case.


# 1.97 17-Apr-2006 brad

Coviery CID 1108: Avoid NULL pointer deref.

Coverity CID 1105: Avoid NULL deref.

From NetBSD


# 1.96 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.95 13-Feb-2006 brad

add some ASIC revisions to the various switch cases and identify
some newer revs.


# 1.94 09-Feb-2006 brad

sync PCI id.


# 1.93 22-Dec-2005 brad

re-work PHY setup, media handling and dual-port detection.

Based on the Marvell FreeBSD driver.


# 1.92 16-Dec-2005 brad

remove unused code to use IO space.


# 1.91 15-Dec-2005 brad

merge printing of the revision and the interrupt string into one printf.


# 1.90 10-Dec-2005 brad

sk_shutdown -> skc_shutdown and register the shutdown function with
shutdownhook_establish().


# 1.89 10-Dec-2005 brad

shrink dmesg entry by one line by merging the chipset revision into
the skc line and fix various error condition printf's in skc_attach(),
sk_attach() and sk_alloc_jumbo_mem() so the messages will be displayed
properly.

ok krw@


# 1.88 26-Nov-2005 brad

fix interrupt moderation timer frequencies for Yukon and Yukon-II based
chips.

From Jeff Rizzo on NetBSD's tech-net list, based on the Marvell
sk98lin Linux driver, and also matches what the Marvell FreeBSD
does.


# 1.87 15-Nov-2005 brad

more accurately reflect the naming scheme of the Marvell Yukon devices with there
pcidevs entries.

Based on information from the Marvell Yukon/Yukon-II FreeBSD driver.


# 1.86 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.85 15-Oct-2005 brad

add 2 new Yukon PCI ids and recognize Yukon-2 EC Ultra ASIC.


# 1.84 15-Oct-2005 brad

update Via and 3Com ids.


# 1.83 20-Sep-2005 brad

memory, media handling and a bunch of register definitions for Yukon-2.

From jason@


# 1.82 20-Sep-2005 brad

merge xmaciireg.h and yukonreg.h into if_skreg.h


# 1.81 20-Sep-2005 brad

shuffle some stuff from skreg to skvar


# 1.80 17-Sep-2005 brad

add media detection and dual port detection for Yukon-2.

from jason@


# 1.79 16-Sep-2005 brad

- remove code to read PCI VPD as we do not use that anymore.
- remove some FreeBSD-ism's: struct resource *'s.
- fail more gracefully in sk_probe() instead of in sk_attach()
for newer unsupported ASIC revisions.

From jason@


Revision tags: OPENBSD_3_8_BASE
# 1.78 29-Aug-2005 brad

- use pci_mapreg_type() to fix some systems that would fail to attach
sk(4) with "can't map mem space".
- add missing newline for failure case of pci_intr_establish().

ok deraadt@


# 1.77 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.76 24-Jul-2005 fgsch

simplify error paths and add some missing ones; brad@ ok.
deallocation for jumbo memory left.


# 1.75 22-Jul-2005 brad

- sync sk_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()
- oops, forgot to remove a line in sk_rxeof()


# 1.74 22-Jul-2005 brad

also take the PCI subsystem id into consideration when trying to probe
for Linksys EG1032 cards, that way we do not try and attach to newer
rev 3 cards that use the RealTek 8169S chipset.


# 1.73 21-Jul-2005 brad

- add bus_dmamap_sync()'s; From NetBSD
- use pci_mapreg_map()
- remove unnecessary splimp() usage in skc_attach()
- make sure to disestablish the interrupt on failure

Tested by a few end-users.


# 1.72 14-Jul-2005 brad

add D-Link PCI id.

From: jsg@


# 1.71 12-Jul-2005 brad

remove unused prototype sk_free_jumbo_mem


# 1.70 12-Jul-2005 brad

free resources for Jumbo buffers in sk_stop().

ok deraadt, krw, beck


# 1.69 02-Jul-2005 brad

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


# 1.68 02-Jul-2005 brad

- mbuf external storage is of (caddr_t), not (caddr_t *).
- check for MTU being too small with ETHERMIN
- don't bother reseting the card since it'll default to allowing Jumbos


# 1.67 17-May-2005 jason

remove spurious bpf_mtap (I think it's leftover debugging code from a year ago)


# 1.66 16-May-2005 brad

add a newline here


# 1.65 11-May-2005 brad

remove comment which is not valid anymore


# 1.64 11-May-2005 brad

- Also match on Yukon LP's for the Lite rev A0 test.
- Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().
- Take PHY out of reset for Yukon Lite rev A3. This resolves the
intermittent "no PHY found!" issue.

From FreeBSD

- Recognize some newer Yukon chipsets

ok krw@, tested by krw@ and a few others, mostly with LOM Lite A3's but
also with some other ASIC revs too.


# 1.63 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.62 18-Mar-2005 brad

fail to attach with a printf instead of a panic for newer yet unsupported
Yukon-2-based cards.

ok deraadt@


# 1.61 12-Mar-2005 brad

add a bunch of PCI ids from the SysKonnect sk98lin driver.


# 1.60 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.59 02-Jan-2005 brad

cleanup and better ram sizing.


# 1.58 01-Jan-2005 brad

better chip/card identification.

From NetBSD

ok krw@


# 1.57 01-Jan-2005 brad

rev 1.92

only clear the IFF_OACTIVE flag when we have a chance of being able to
queue a packet to the hardware... instead of when the hardware queue is
empty..

don't initalize cur_tx now that it doesn't need to be...

rev 1.90

_OACTIVE is now handled better...

From FreeBSD

ok krw@


# 1.56 01-Jan-2005 krw

Don't initialize the card (and start an autonegotiation!) every time
the IP address changes. Makes 'dhclient sk0' invocations way faster
and more consistant. i.e. one DHCPREQUEST elicts the DHCPACK.

ok brad@ 'Wow. Great Idea.' deraadt@.


# 1.55 22-Dec-2004 brad

- add missing braces for SIOCSIFMTU switch case.
- allow reception of Jumbo frames all the time on GEnesis based cards,
same as Yukon based cards.

ok krw@ mcbride@


# 1.54 14-Dec-2004 krw

Fix off-by-one. From FreeBSD r1.87. Also in NetBSD. Field being filled
(sk_vpd_readonly) is not currently used, but the memory being tromped
on might be.

ok millert@.


# 1.53 08-Dec-2004 brad

use ETHER_MAX_LEN


# 1.52 08-Dec-2004 krw

Enable jumbo frames on Yukon varients of sk(4).

ok mcbride@.


# 1.51 16-Nov-2004 brad

Lower interrupt moderation timer to decrease service latency.

From NetBSD

ok deraadt@


# 1.50 16-Nov-2004 brad

back out previous commit and put the right change in which corresponds
to what the previous commit message said...

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).


# 1.49 16-Nov-2004 brad

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).

From NetBSD

ok henning@ mcbride@


# 1.48 11-Nov-2004 brad

- Fix Yukon ram sizing.
- Keep tx queue running by kicking the tx bmu repeatedly.
- Handle if_timer a bit better.

From NetBSD

ok deraadt@


# 1.47 14-Oct-2004 brad

Bail out quietly if the eeprom appears to be missing or empty. Fixes
support for D-Link DGE-530T adapters.

From: FreeBSD via Blake Willis <blake at 2112 dot net>

ok mcbride@


# 1.46 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
# 1.45 20-Aug-2004 deraadt

a belkin ID on a sk card


# 1.44 19-Aug-2004 mcbride

Don't complain about lack of jumbo storage when processing incoming packets
unless we're debugging.


# 1.43 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


# 1.42 04-Aug-2004 mcbride

Make jumbo frames work.
- allocate and manage our own memory for rx packets rather than using
mbuf clusters; code for this lifted from if_bge.c
- pass the correct size to bus_dmamap_create()

ok deraadt@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.41 29-May-2004 naddy

replace hand-rolled CRC calculation in multicast hash setup with calls to
ether_crc32_*(); ok mcbride@


# 1.40 24-May-2004 naddy

Make Yukon-style adapters also set up the multicast filter in sk_init().
This fixes various multicast-related problems. ok henning@


# 1.39 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.38 09-Mar-2004 matthieu

Fix multicast on recent sk chipsets. Adapted from a patch by Keith Mitchell
in <http://lists.freebsd.org/pipermail/freebsd-hardware/2003-December/000851.html>
Ok deraadt@.


# 1.37 17-Dec-2003 jason

not qualifying a product based on vendor AND product ID just bugs me


# 1.36 17-Dec-2003 jason

marvell skv2 (smc9452TX); from freebsd


# 1.35 17-Dec-2003 jason

add support for linksys (eg1032v2, eg1064v2) and dlink (dge530t); from NetBSD


# 1.34 13-Oct-2003 jason

rx checksum offload support (based on earlier code from aaron@, but with
fixes by me). Note: sk v1 chips can sometimes compute an incorrect cksum.
To deal with that, we never set the "bad" flags. Ie. if the card says it's
good, we assume it's good. If the card says it's bad, we fall back to
software. Ugly? You betcha.


Revision tags: OPENBSD_3_4_BASE
# 1.33 12-Aug-2003 nate

add/update my copyright


# 1.32 01-Aug-2003 nate

Support for new Marvell based Gigabit Ethernet adapters
ok deraadt@


Revision tags: UBC_SYNC_A
# 1.31 14-May-2003 nate

Makefile sk(4) use bus_dma
ok jason


# 1.30 08-May-2003 nate

a bit more cleanup


# 1.29 08-May-2003 nate

ansify, clean up formatting, remove useless return statements.
ok jason


Revision tags: OPENBSD_3_3_BASE
# 1.28 12-Mar-2003 nate

sk is capable of transmitting and receiving longer packets for 802.1q vlans
thanks to David Gwynne <loki@niteshade.net>. ok jason@ deraadt@


# 1.27 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.26 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.25 08-Jun-2002 jason

add missing ioctl support for SIOCSIFMTU


# 1.24 04-Jun-2002 deraadt

spelling; raj@cerias.purdue.edu


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

First round of __P removal in sys


# 1.22 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.21 15-Feb-2002 nordin

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


# 1.20 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


Revision tags: UBC_BASE
# 1.19 06-Nov-2001 miod

branches: 1.19.2;
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.18 05-Oct-2001 nate

use positive logic for match


# 1.17 11-Sep-2001 miod

Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.16 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.15 15-Aug-2001 jason

Add some stuff missed in a previous FreeBSD merge... Fixes the problem where
sk busy loops when carrier is lost until it returns; based on patch from
david langhorst <dirt@monkey.org> and tested by John Ladwig <jladwig@mango.lioness.net>


# 1.14 12-Aug-2001 mickey

remove redundant vm includes


# 1.13 25-Jun-2001 fgsch

trivial ether_input_mbuf() conversion.


Revision tags: OPENBSD_2_9_BASE
# 1.12 29-Mar-2001 jason

From FreeBSD:
- Call mii_pollstat() after we bring up the link on a 1000baseTX card
after autoneg so we make sure to set the link state and duplex mode
correctly.
- Make sure to set the 'ignore pause frames' bit on the XMAC.
- Small linewrap fix.
- Add actual URL for XMAC II datasheet in comments.


# 1.11 25-Mar-2001 csapuntz

Missing splx(s). Thanks to Dawson and team for finding this one


# 1.10 20-Feb-2001 mickey

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


Revision tags: OPENBSD_2_8_BASE
# 1.9 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.8 04-Sep-2000 deraadt

printing XaQti on 5 consecutive lines is stupid


# 1.7 29-Aug-2000 jason

From FreeBSD: split out the support for XMAC-II phys and other phys
add xmphy & brgphy to GENERIC


Revision tags: OPENBSD_2_7_BASE
# 1.6 15-Feb-2000 jason

make sure to call ether_{add,del}multi() as appropriate in xxx_ioctl()


Revision tags: SMP_BASE kame_19991208
# 1.5 08-Dec-1999 aaron

branches: 1.5.2;
Remove unused #define cruft.


Revision tags: OPENBSD_2_6_BASE
# 1.4 22-Oct-1999 deraadt

fix some panic bugs; jason


# 1.3 04-Oct-1999 jason

m_new is the new mbuf, not m
fix calculation of buffer slot number


# 1.2 03-Oct-1999 jason

take advantage of m->m_ext.ext_handle for storing the softc
(instead of stashing it in the buffer)


# 1.1 01-Oct-1999 jason

driver for SysKonnect 984x gigabit ethernet adapters; from FreeBSD


# 1.192 12-Dec-2020 jan

Rename the macro MCLGETI to MCLGETL and removes the dead parameter ifp.

OK dlg@, bluhm@
No Opinion mpi@
Not against it claudio@


Revision tags: OPENBSD_6_8_BASE
# 1.191 10-Jul-2020 patrick

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

ok dlg@ tobhe@


# 1.190 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


Revision tags: 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.189 04-Jun-2017 dlg

use htolem32 and lemtoh32 instead of htole32 and letoh32.

saves about half a k on sparc64.


# 1.188 02-Jun-2017 dlg

handle 64bit dva in the tx path as well as the rx path.


# 1.187 01-Jun-2017 dlg

reorder ops in sk_start to avoid possibly rolling back ifq_deq.

instead of checking for space after beggining to deq a packet, check
for space before committing to handling a packet. this means we
can use ifq_dequeue instead of ifq_deq_begin/commit/rollback.

ok mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.186 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@


# 1.185 08-Jan-2017 visa

Use a macro for the Tx timeout value.

OK deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.184 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.183 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.182 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.181 24-Nov-2015 mpi

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


# 1.180 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.179 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.178 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.177 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.176 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.175 30-Apr-2015 mpi

Convert to if_input(), tweak and ok dlg@


# 1.174 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@


Revision tags: OPENBSD_5_7_BASE
# 1.173 22-Dec-2014 tedu

unifdef INET


# 1.172 20-Aug-2014 dlg

brad said i had some whitespace screwups in my previous diff. this cleans
them up and the others i found in this file.

no functional change.


# 1.171 20-Aug-2014 dlg

replace sks jumbo allocator with MCLGETI. the system provides jumbos in
the right shape now, we dont have to do it by hand all over the place
any more.

rework the rxr ring management to use if_rxring while here.

largely based on if_sk.c r1.152 and if_skvar.h r1.4 by kettenis.
tested by me on:

skc0 at pci3 dev 11 function 0 "Schneider & Koch SK-98xx" rev 0x12, GEnesis (0x0): apic 3 int 5
sk0 at skc0 port A: address 00:00:5a:99:8a:ec
xmphy0 at sk0 phy 0: XMAC II Gigabit PHY, rev. 2

and this from ian mcwilliam

skc0 at pci0 dev 9 function 0 "D-Link DGE-530T B1" rev 0x11, Yukon Lite (0x9): apic 2 int 17
sk0 at skc0 port A: address 00:17:9a:ba:b5:39
eephy0 at sk0 phy 0: 88E1011 Gigabit PHY, rev. 5

tested by brad@ too


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

Fewer <netinet/in_systm.h>


# 1.169 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.168 19-Apr-2014 henning

kill checksum offloading in sk.
it was RX only, nothing on the TX side
rather complex, might eat up (or more) offloading benefits in many cases
the hardware miscomputes the cksums sometimes, so we don't trust it
claiming a cksum is bad and re-do the cksum verification in sw then...
(but we trust it to not mark bad ones good? hmmmmmmmmm.)
diff was on tech for 3 months, nobody disagreed, everybody who spoke up
agrees or doesn't care.
pretty exactly a revert of the cksum offloading addition years ago, tested
by several, the only report i quickly find now is from David Higgs <higgsd
at gmail dot com>, thanks!


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

Sync activate code sequnces to if_msk.c as much as possible, in case
one of these is ever found in a suspend/hibernate system.


# 1.166 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.165 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_4_BASE
# 1.164 07-Mar-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok chris@


Revision tags: OPENBSD_5_3_BASE
# 1.163 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@


# 1.162 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


Revision tags: OPENBSD_5_2_BASE
# 1.161 24-Feb-2012 guenther

Correct the spelling of "transferred" and "transferring"

from Tobias Ulmer (tobiasu at tmux.org); ok jmc@, krw@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.160 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.159 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.158 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


Revision tags: OPENBSD_4_8_BASE
# 1.157 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.156 17-Oct-2009 martynas

use sc->sk_bsize in the unmap call too; ok theo


# 1.155 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.154 04-Oct-2009 deraadt

Merge over a bunch of detach logic from msk(4) so that this driver can
detach as well
ok kettenis


# 1.153 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_6_BASE
# 1.152 08-Jul-2009 sthen

revert MCLGETI for sk(4) for now. commit requested by deraadt@


# 1.151 30-Mar-2009 kettenis

Switch sk(4) over to using MCLGETI when allocating mbufs for the RX ring.
Another evil jumbo allocator bites the dust.


Revision tags: OPENBSD_4_5_BASE
# 1.150 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.149 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.148 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.147 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.146 24-May-2008 brad

Also recognize the Schneider & Koch SK-9821/SK-9843 adapters from
Fujitsu.


# 1.145 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.144 02-Mar-2008 brad

Change some spaces to tabs in the transmit functions.

ok kettenis@


# 1.143 17-Jan-2008 brad

Add splnet around mii_tick() in sk_yukon_tick().

ok kettenis@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.142 26-May-2007 reyk

separate the attach information from the status information with a colon.

suggested by deraadt@


# 1.141 22-May-2007 ray

%z in printf(9) is not the same as %z in printf(3). Change to %lu
and cast arg to ulong.

OK miod@.


# 1.140 07-May-2007 deraadt

shrink code by not using __inline without static; ok kettenis


Revision tags: OPENBSD_4_1_BASE
# 1.139 12-Feb-2007 pedro

Fix prototype, from brad@, no binary change


# 1.138 10-Feb-2007 krw

Move HASH_BITS constant to if_skreg.h as SK_HASH_BITS. Remove unused
code and an unnecessary comment, No functional change.

From brad@.


# 1.137 03-Feb-2007 kettenis

Fix typo; clear tx FIFO underrun IRQ as intended instead of rx FIFO overrun
IRQ. From brad@


# 1.136 18-Jan-2007 krw

Don't reinitialize card at every media change.

From Brad, tested by Brad, wilfried@ and Johan M:son Lindman.

ok wilfried@


# 1.135 05-Jan-2007 kettenis

For Yukon-based cards, pass MIIF_DOPAUSE to mii_attach().

From brad@


# 1.134 03-Jan-2007 kettenis

In sk_marv_miibus_writereg, wait for busy flag to clear instead of
continuing when busy flag set.


# 1.133 03-Jan-2007 krw

Don't say 'Marvell' twice for each sk/msk device in dmesg. No functional
change.

from brad@ ok mglocker@


# 1.132 06-Dec-2006 reyk

- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested on amd64/i386/sparc64

ok brad@ mglocker@


# 1.131 16-Nov-2006 brad

remove the small amount of code for Yukon-2 chipsets now that there is msk(4).


# 1.130 08-Nov-2006 kettenis

Make XMAC work on on big-endian systems.

help & ok jason@, ok brad@


# 1.129 16-Oct-2006 tom

Fix some "is is"s. ok otto@.


# 1.128 27-Sep-2006 brad

fix the use of LIST_INSERT_HEAD in [m]sk_alloc_jumbo_mem().


# 1.127 26-Sep-2006 brad

Set sk_jumbo_buf to NULL if malloc() fails in the for loop within
[m]sk_alloc_jumbo_mem().


# 1.126 18-Sep-2006 brad

g/c unused SK_{SET,CLR}BIT macros

From riz@NetBSD


Revision tags: OPENBSD_4_0_BASE
# 1.125 17-Aug-2006 brad

cosmetic tweaks.


# 1.124 17-Aug-2006 brad

remove PCI ids which msk(4) will match against from sk(4).


# 1.123 09-Aug-2006 brad

revert rev 1.119 as this seems to cause problems with some PHY.


# 1.122 04-Aug-2006 brad

and the same goes for sk_init_yukon().


# 1.121 04-Aug-2006 brad

remove now redundant promiscuous mode handling code from sk_init_xmac().


# 1.120 04-Aug-2006 brad

refactor the promiscuous mode handling code and simplify the ioctl handler.


# 1.119 04-Aug-2006 brad

Fix busy check for PHY write operation with Yukon chips.

From yongari@FreeBSD


# 1.118 30-Jul-2006 brad

Add more strict receive path packet validation routine. Previously
the driver could pass corrupted packets to the upper layer under
certain conditions.

From yongari@FreeBSD


# 1.117 23-Jul-2006 brad

improved Yukon init routine with proper workaround for the PHY COMA mode.

From yongari@FreeBSD


# 1.116 22-Jun-2006 brad

Add appropriate swapping for big-endian systems. Allows sk(4) to work
on macppc and sparc64.

ok reyk@


# 1.115 22-Jun-2006 brad

adjust PCI ids.


# 1.114 17-Jun-2006 brad

add sys/timeout.h


# 1.113 17-Jun-2006 brad

remove some whitespace.


# 1.112 15-Jun-2006 brad

Fix watchdog timeout errors seen on a few systems.

The SK-NET GENESIS document says reading the SK_ISSR register should stop
generating further interrupts, but it seems there is the possibility
of losing interrupts between reading the SK_ISSR register and determining
which interrupts have been reported. To cope with this situation we
continuously read the SK_ISSR register until there are no interrupts.

However, it seems that the above workaround does not fix all cases.
Add workaround code that tries to protect against false alarms from
the watchdog handler by trying to reclaim pending Tx descriptors
before resetting the hardware.

This should fix occasional watchdog timeouts seen with this driver.

From FreeBSD


# 1.111 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.110 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.109 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.108 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.107 01-May-2006 brad

Activate Tx descriptor poll timer in order to protect possible loss
of SK_TXBMU_TX_START command. Previously the driver continuously issued
SK_TXBMU_TX_START when it notices pending Tx descriptors not processed
yet in interrupt handler. That approach would add additional PCI
write access overhead under high Tx load situations and it might fail
if the first SK_TXBMU_TX_START was lost and no interrupt is generated
from the first SK_TXBMU_TX_START command.

From FreeBSD


# 1.106 01-May-2006 brad

Added Rx/Tx FIFO flush support for Yukon

From FreeBSD


# 1.105 01-May-2006 brad

A new function sk_yukon_tick(), to handle auto-negotiation properly for
Yukon-based adapters.

From FreeBSD


# 1.104 30-Apr-2006 brad

- Use SK_IS_GENESIS/SK_IS_YUKON where appropriate
- Remove SK_YUKON_FAMILY


# 1.103 30-Apr-2006 brad

- Interrupt handler now checks shared interrupt source and protects
the interrupt handler from NULL pointer dereference which was caused
by odd status word value. The status word can return 0xffffffff if the
cable is unplugged while Rx/Tx/auto-negotiation is in progress.

From FreeBSD


# 1.102 30-Apr-2006 brad

Update if_oerrors if we encounter watchdog error.

From FreeBSD


# 1.101 30-Apr-2006 brad

- Added/corrected register definitions for Yukon.
(Register information from Linux skge driver.)

From FreeBSD


# 1.100 23-Apr-2006 brad

some more ANSI, KNF and other tidying up.


# 1.99 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.98 17-Apr-2006 brad

If there is a timeout while writing to the PHY in
sk_marv_miibus_writereg() then print a message
indicating so, as done in the XMAC case.


# 1.97 17-Apr-2006 brad

Coviery CID 1108: Avoid NULL pointer deref.

Coverity CID 1105: Avoid NULL deref.

From NetBSD


# 1.96 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.95 13-Feb-2006 brad

add some ASIC revisions to the various switch cases and identify
some newer revs.


# 1.94 09-Feb-2006 brad

sync PCI id.


# 1.93 22-Dec-2005 brad

re-work PHY setup, media handling and dual-port detection.

Based on the Marvell FreeBSD driver.


# 1.92 16-Dec-2005 brad

remove unused code to use IO space.


# 1.91 15-Dec-2005 brad

merge printing of the revision and the interrupt string into one printf.


# 1.90 10-Dec-2005 brad

sk_shutdown -> skc_shutdown and register the shutdown function with
shutdownhook_establish().


# 1.89 10-Dec-2005 brad

shrink dmesg entry by one line by merging the chipset revision into
the skc line and fix various error condition printf's in skc_attach(),
sk_attach() and sk_alloc_jumbo_mem() so the messages will be displayed
properly.

ok krw@


# 1.88 26-Nov-2005 brad

fix interrupt moderation timer frequencies for Yukon and Yukon-II based
chips.

From Jeff Rizzo on NetBSD's tech-net list, based on the Marvell
sk98lin Linux driver, and also matches what the Marvell FreeBSD
does.


# 1.87 15-Nov-2005 brad

more accurately reflect the naming scheme of the Marvell Yukon devices with there
pcidevs entries.

Based on information from the Marvell Yukon/Yukon-II FreeBSD driver.


# 1.86 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.85 15-Oct-2005 brad

add 2 new Yukon PCI ids and recognize Yukon-2 EC Ultra ASIC.


# 1.84 15-Oct-2005 brad

update Via and 3Com ids.


# 1.83 20-Sep-2005 brad

memory, media handling and a bunch of register definitions for Yukon-2.

From jason@


# 1.82 20-Sep-2005 brad

merge xmaciireg.h and yukonreg.h into if_skreg.h


# 1.81 20-Sep-2005 brad

shuffle some stuff from skreg to skvar


# 1.80 17-Sep-2005 brad

add media detection and dual port detection for Yukon-2.

from jason@


# 1.79 16-Sep-2005 brad

- remove code to read PCI VPD as we do not use that anymore.
- remove some FreeBSD-ism's: struct resource *'s.
- fail more gracefully in sk_probe() instead of in sk_attach()
for newer unsupported ASIC revisions.

From jason@


Revision tags: OPENBSD_3_8_BASE
# 1.78 29-Aug-2005 brad

- use pci_mapreg_type() to fix some systems that would fail to attach
sk(4) with "can't map mem space".
- add missing newline for failure case of pci_intr_establish().

ok deraadt@


# 1.77 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.76 24-Jul-2005 fgsch

simplify error paths and add some missing ones; brad@ ok.
deallocation for jumbo memory left.


# 1.75 22-Jul-2005 brad

- sync sk_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()
- oops, forgot to remove a line in sk_rxeof()


# 1.74 22-Jul-2005 brad

also take the PCI subsystem id into consideration when trying to probe
for Linksys EG1032 cards, that way we do not try and attach to newer
rev 3 cards that use the RealTek 8169S chipset.


# 1.73 21-Jul-2005 brad

- add bus_dmamap_sync()'s; From NetBSD
- use pci_mapreg_map()
- remove unnecessary splimp() usage in skc_attach()
- make sure to disestablish the interrupt on failure

Tested by a few end-users.


# 1.72 14-Jul-2005 brad

add D-Link PCI id.

From: jsg@


# 1.71 12-Jul-2005 brad

remove unused prototype sk_free_jumbo_mem


# 1.70 12-Jul-2005 brad

free resources for Jumbo buffers in sk_stop().

ok deraadt, krw, beck


# 1.69 02-Jul-2005 brad

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


# 1.68 02-Jul-2005 brad

- mbuf external storage is of (caddr_t), not (caddr_t *).
- check for MTU being too small with ETHERMIN
- don't bother reseting the card since it'll default to allowing Jumbos


# 1.67 17-May-2005 jason

remove spurious bpf_mtap (I think it's leftover debugging code from a year ago)


# 1.66 16-May-2005 brad

add a newline here


# 1.65 11-May-2005 brad

remove comment which is not valid anymore


# 1.64 11-May-2005 brad

- Also match on Yukon LP's for the Lite rev A0 test.
- Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().
- Take PHY out of reset for Yukon Lite rev A3. This resolves the
intermittent "no PHY found!" issue.

From FreeBSD

- Recognize some newer Yukon chipsets

ok krw@, tested by krw@ and a few others, mostly with LOM Lite A3's but
also with some other ASIC revs too.


# 1.63 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.62 18-Mar-2005 brad

fail to attach with a printf instead of a panic for newer yet unsupported
Yukon-2-based cards.

ok deraadt@


# 1.61 12-Mar-2005 brad

add a bunch of PCI ids from the SysKonnect sk98lin driver.


# 1.60 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.59 02-Jan-2005 brad

cleanup and better ram sizing.


# 1.58 01-Jan-2005 brad

better chip/card identification.

From NetBSD

ok krw@


# 1.57 01-Jan-2005 brad

rev 1.92

only clear the IFF_OACTIVE flag when we have a chance of being able to
queue a packet to the hardware... instead of when the hardware queue is
empty..

don't initalize cur_tx now that it doesn't need to be...

rev 1.90

_OACTIVE is now handled better...

From FreeBSD

ok krw@


# 1.56 01-Jan-2005 krw

Don't initialize the card (and start an autonegotiation!) every time
the IP address changes. Makes 'dhclient sk0' invocations way faster
and more consistant. i.e. one DHCPREQUEST elicts the DHCPACK.

ok brad@ 'Wow. Great Idea.' deraadt@.


# 1.55 22-Dec-2004 brad

- add missing braces for SIOCSIFMTU switch case.
- allow reception of Jumbo frames all the time on GEnesis based cards,
same as Yukon based cards.

ok krw@ mcbride@


# 1.54 14-Dec-2004 krw

Fix off-by-one. From FreeBSD r1.87. Also in NetBSD. Field being filled
(sk_vpd_readonly) is not currently used, but the memory being tromped
on might be.

ok millert@.


# 1.53 08-Dec-2004 brad

use ETHER_MAX_LEN


# 1.52 08-Dec-2004 krw

Enable jumbo frames on Yukon varients of sk(4).

ok mcbride@.


# 1.51 16-Nov-2004 brad

Lower interrupt moderation timer to decrease service latency.

From NetBSD

ok deraadt@


# 1.50 16-Nov-2004 brad

back out previous commit and put the right change in which corresponds
to what the previous commit message said...

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).


# 1.49 16-Nov-2004 brad

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).

From NetBSD

ok henning@ mcbride@


# 1.48 11-Nov-2004 brad

- Fix Yukon ram sizing.
- Keep tx queue running by kicking the tx bmu repeatedly.
- Handle if_timer a bit better.

From NetBSD

ok deraadt@


# 1.47 14-Oct-2004 brad

Bail out quietly if the eeprom appears to be missing or empty. Fixes
support for D-Link DGE-530T adapters.

From: FreeBSD via Blake Willis <blake at 2112 dot net>

ok mcbride@


# 1.46 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
# 1.45 20-Aug-2004 deraadt

a belkin ID on a sk card


# 1.44 19-Aug-2004 mcbride

Don't complain about lack of jumbo storage when processing incoming packets
unless we're debugging.


# 1.43 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


# 1.42 04-Aug-2004 mcbride

Make jumbo frames work.
- allocate and manage our own memory for rx packets rather than using
mbuf clusters; code for this lifted from if_bge.c
- pass the correct size to bus_dmamap_create()

ok deraadt@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.41 29-May-2004 naddy

replace hand-rolled CRC calculation in multicast hash setup with calls to
ether_crc32_*(); ok mcbride@


# 1.40 24-May-2004 naddy

Make Yukon-style adapters also set up the multicast filter in sk_init().
This fixes various multicast-related problems. ok henning@


# 1.39 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.38 09-Mar-2004 matthieu

Fix multicast on recent sk chipsets. Adapted from a patch by Keith Mitchell
in <http://lists.freebsd.org/pipermail/freebsd-hardware/2003-December/000851.html>
Ok deraadt@.


# 1.37 17-Dec-2003 jason

not qualifying a product based on vendor AND product ID just bugs me


# 1.36 17-Dec-2003 jason

marvell skv2 (smc9452TX); from freebsd


# 1.35 17-Dec-2003 jason

add support for linksys (eg1032v2, eg1064v2) and dlink (dge530t); from NetBSD


# 1.34 13-Oct-2003 jason

rx checksum offload support (based on earlier code from aaron@, but with
fixes by me). Note: sk v1 chips can sometimes compute an incorrect cksum.
To deal with that, we never set the "bad" flags. Ie. if the card says it's
good, we assume it's good. If the card says it's bad, we fall back to
software. Ugly? You betcha.


Revision tags: OPENBSD_3_4_BASE
# 1.33 12-Aug-2003 nate

add/update my copyright


# 1.32 01-Aug-2003 nate

Support for new Marvell based Gigabit Ethernet adapters
ok deraadt@


Revision tags: UBC_SYNC_A
# 1.31 14-May-2003 nate

Makefile sk(4) use bus_dma
ok jason


# 1.30 08-May-2003 nate

a bit more cleanup


# 1.29 08-May-2003 nate

ansify, clean up formatting, remove useless return statements.
ok jason


Revision tags: OPENBSD_3_3_BASE
# 1.28 12-Mar-2003 nate

sk is capable of transmitting and receiving longer packets for 802.1q vlans
thanks to David Gwynne <loki@niteshade.net>. ok jason@ deraadt@


# 1.27 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.26 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.25 08-Jun-2002 jason

add missing ioctl support for SIOCSIFMTU


# 1.24 04-Jun-2002 deraadt

spelling; raj@cerias.purdue.edu


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

First round of __P removal in sys


# 1.22 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.21 15-Feb-2002 nordin

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


# 1.20 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


Revision tags: UBC_BASE
# 1.19 06-Nov-2001 miod

branches: 1.19.2;
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.18 05-Oct-2001 nate

use positive logic for match


# 1.17 11-Sep-2001 miod

Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.16 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.15 15-Aug-2001 jason

Add some stuff missed in a previous FreeBSD merge... Fixes the problem where
sk busy loops when carrier is lost until it returns; based on patch from
david langhorst <dirt@monkey.org> and tested by John Ladwig <jladwig@mango.lioness.net>


# 1.14 12-Aug-2001 mickey

remove redundant vm includes


# 1.13 25-Jun-2001 fgsch

trivial ether_input_mbuf() conversion.


Revision tags: OPENBSD_2_9_BASE
# 1.12 29-Mar-2001 jason

From FreeBSD:
- Call mii_pollstat() after we bring up the link on a 1000baseTX card
after autoneg so we make sure to set the link state and duplex mode
correctly.
- Make sure to set the 'ignore pause frames' bit on the XMAC.
- Small linewrap fix.
- Add actual URL for XMAC II datasheet in comments.


# 1.11 25-Mar-2001 csapuntz

Missing splx(s). Thanks to Dawson and team for finding this one


# 1.10 20-Feb-2001 mickey

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


Revision tags: OPENBSD_2_8_BASE
# 1.9 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.8 04-Sep-2000 deraadt

printing XaQti on 5 consecutive lines is stupid


# 1.7 29-Aug-2000 jason

From FreeBSD: split out the support for XMAC-II phys and other phys
add xmphy & brgphy to GENERIC


Revision tags: OPENBSD_2_7_BASE
# 1.6 15-Feb-2000 jason

make sure to call ether_{add,del}multi() as appropriate in xxx_ioctl()


Revision tags: SMP_BASE kame_19991208
# 1.5 08-Dec-1999 aaron

branches: 1.5.2;
Remove unused #define cruft.


Revision tags: OPENBSD_2_6_BASE
# 1.4 22-Oct-1999 deraadt

fix some panic bugs; jason


# 1.3 04-Oct-1999 jason

m_new is the new mbuf, not m
fix calculation of buffer slot number


# 1.2 03-Oct-1999 jason

take advantage of m->m_ext.ext_handle for storing the softc
(instead of stashing it in the buffer)


# 1.1 01-Oct-1999 jason

driver for SysKonnect 984x gigabit ethernet adapters; from FreeBSD


# 1.191 10-Jul-2020 patrick

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

ok dlg@ tobhe@


# 1.190 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


Revision tags: 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.189 04-Jun-2017 dlg

use htolem32 and lemtoh32 instead of htole32 and letoh32.

saves about half a k on sparc64.


# 1.188 02-Jun-2017 dlg

handle 64bit dva in the tx path as well as the rx path.


# 1.187 01-Jun-2017 dlg

reorder ops in sk_start to avoid possibly rolling back ifq_deq.

instead of checking for space after beggining to deq a packet, check
for space before committing to handling a packet. this means we
can use ifq_dequeue instead of ifq_deq_begin/commit/rollback.

ok mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.186 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@


# 1.185 08-Jan-2017 visa

Use a macro for the Tx timeout value.

OK deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.184 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.183 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.182 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.181 24-Nov-2015 mpi

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


# 1.180 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.179 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.178 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.177 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.176 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.175 30-Apr-2015 mpi

Convert to if_input(), tweak and ok dlg@


# 1.174 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@


Revision tags: OPENBSD_5_7_BASE
# 1.173 22-Dec-2014 tedu

unifdef INET


# 1.172 20-Aug-2014 dlg

brad said i had some whitespace screwups in my previous diff. this cleans
them up and the others i found in this file.

no functional change.


# 1.171 20-Aug-2014 dlg

replace sks jumbo allocator with MCLGETI. the system provides jumbos in
the right shape now, we dont have to do it by hand all over the place
any more.

rework the rxr ring management to use if_rxring while here.

largely based on if_sk.c r1.152 and if_skvar.h r1.4 by kettenis.
tested by me on:

skc0 at pci3 dev 11 function 0 "Schneider & Koch SK-98xx" rev 0x12, GEnesis (0x0): apic 3 int 5
sk0 at skc0 port A: address 00:00:5a:99:8a:ec
xmphy0 at sk0 phy 0: XMAC II Gigabit PHY, rev. 2

and this from ian mcwilliam

skc0 at pci0 dev 9 function 0 "D-Link DGE-530T B1" rev 0x11, Yukon Lite (0x9): apic 2 int 17
sk0 at skc0 port A: address 00:17:9a:ba:b5:39
eephy0 at sk0 phy 0: 88E1011 Gigabit PHY, rev. 5

tested by brad@ too


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

Fewer <netinet/in_systm.h>


# 1.169 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.168 19-Apr-2014 henning

kill checksum offloading in sk.
it was RX only, nothing on the TX side
rather complex, might eat up (or more) offloading benefits in many cases
the hardware miscomputes the cksums sometimes, so we don't trust it
claiming a cksum is bad and re-do the cksum verification in sw then...
(but we trust it to not mark bad ones good? hmmmmmmmmm.)
diff was on tech for 3 months, nobody disagreed, everybody who spoke up
agrees or doesn't care.
pretty exactly a revert of the cksum offloading addition years ago, tested
by several, the only report i quickly find now is from David Higgs <higgsd
at gmail dot com>, thanks!


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

Sync activate code sequnces to if_msk.c as much as possible, in case
one of these is ever found in a suspend/hibernate system.


# 1.166 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.165 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_4_BASE
# 1.164 07-Mar-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok chris@


Revision tags: OPENBSD_5_3_BASE
# 1.163 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@


# 1.162 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


Revision tags: OPENBSD_5_2_BASE
# 1.161 24-Feb-2012 guenther

Correct the spelling of "transferred" and "transferring"

from Tobias Ulmer (tobiasu at tmux.org); ok jmc@, krw@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.160 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.159 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.158 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


Revision tags: OPENBSD_4_8_BASE
# 1.157 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.156 17-Oct-2009 martynas

use sc->sk_bsize in the unmap call too; ok theo


# 1.155 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.154 04-Oct-2009 deraadt

Merge over a bunch of detach logic from msk(4) so that this driver can
detach as well
ok kettenis


# 1.153 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_6_BASE
# 1.152 08-Jul-2009 sthen

revert MCLGETI for sk(4) for now. commit requested by deraadt@


# 1.151 30-Mar-2009 kettenis

Switch sk(4) over to using MCLGETI when allocating mbufs for the RX ring.
Another evil jumbo allocator bites the dust.


Revision tags: OPENBSD_4_5_BASE
# 1.150 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.149 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.148 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.147 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.146 24-May-2008 brad

Also recognize the Schneider & Koch SK-9821/SK-9843 adapters from
Fujitsu.


# 1.145 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.144 02-Mar-2008 brad

Change some spaces to tabs in the transmit functions.

ok kettenis@


# 1.143 17-Jan-2008 brad

Add splnet around mii_tick() in sk_yukon_tick().

ok kettenis@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.142 26-May-2007 reyk

separate the attach information from the status information with a colon.

suggested by deraadt@


# 1.141 22-May-2007 ray

%z in printf(9) is not the same as %z in printf(3). Change to %lu
and cast arg to ulong.

OK miod@.


# 1.140 07-May-2007 deraadt

shrink code by not using __inline without static; ok kettenis


Revision tags: OPENBSD_4_1_BASE
# 1.139 12-Feb-2007 pedro

Fix prototype, from brad@, no binary change


# 1.138 10-Feb-2007 krw

Move HASH_BITS constant to if_skreg.h as SK_HASH_BITS. Remove unused
code and an unnecessary comment, No functional change.

From brad@.


# 1.137 03-Feb-2007 kettenis

Fix typo; clear tx FIFO underrun IRQ as intended instead of rx FIFO overrun
IRQ. From brad@


# 1.136 18-Jan-2007 krw

Don't reinitialize card at every media change.

From Brad, tested by Brad, wilfried@ and Johan M:son Lindman.

ok wilfried@


# 1.135 05-Jan-2007 kettenis

For Yukon-based cards, pass MIIF_DOPAUSE to mii_attach().

From brad@


# 1.134 03-Jan-2007 kettenis

In sk_marv_miibus_writereg, wait for busy flag to clear instead of
continuing when busy flag set.


# 1.133 03-Jan-2007 krw

Don't say 'Marvell' twice for each sk/msk device in dmesg. No functional
change.

from brad@ ok mglocker@


# 1.132 06-Dec-2006 reyk

- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested on amd64/i386/sparc64

ok brad@ mglocker@


# 1.131 16-Nov-2006 brad

remove the small amount of code for Yukon-2 chipsets now that there is msk(4).


# 1.130 08-Nov-2006 kettenis

Make XMAC work on on big-endian systems.

help & ok jason@, ok brad@


# 1.129 16-Oct-2006 tom

Fix some "is is"s. ok otto@.


# 1.128 27-Sep-2006 brad

fix the use of LIST_INSERT_HEAD in [m]sk_alloc_jumbo_mem().


# 1.127 26-Sep-2006 brad

Set sk_jumbo_buf to NULL if malloc() fails in the for loop within
[m]sk_alloc_jumbo_mem().


# 1.126 18-Sep-2006 brad

g/c unused SK_{SET,CLR}BIT macros

From riz@NetBSD


Revision tags: OPENBSD_4_0_BASE
# 1.125 17-Aug-2006 brad

cosmetic tweaks.


# 1.124 17-Aug-2006 brad

remove PCI ids which msk(4) will match against from sk(4).


# 1.123 09-Aug-2006 brad

revert rev 1.119 as this seems to cause problems with some PHY.


# 1.122 04-Aug-2006 brad

and the same goes for sk_init_yukon().


# 1.121 04-Aug-2006 brad

remove now redundant promiscuous mode handling code from sk_init_xmac().


# 1.120 04-Aug-2006 brad

refactor the promiscuous mode handling code and simplify the ioctl handler.


# 1.119 04-Aug-2006 brad

Fix busy check for PHY write operation with Yukon chips.

From yongari@FreeBSD


# 1.118 30-Jul-2006 brad

Add more strict receive path packet validation routine. Previously
the driver could pass corrupted packets to the upper layer under
certain conditions.

From yongari@FreeBSD


# 1.117 23-Jul-2006 brad

improved Yukon init routine with proper workaround for the PHY COMA mode.

From yongari@FreeBSD


# 1.116 22-Jun-2006 brad

Add appropriate swapping for big-endian systems. Allows sk(4) to work
on macppc and sparc64.

ok reyk@


# 1.115 22-Jun-2006 brad

adjust PCI ids.


# 1.114 17-Jun-2006 brad

add sys/timeout.h


# 1.113 17-Jun-2006 brad

remove some whitespace.


# 1.112 15-Jun-2006 brad

Fix watchdog timeout errors seen on a few systems.

The SK-NET GENESIS document says reading the SK_ISSR register should stop
generating further interrupts, but it seems there is the possibility
of losing interrupts between reading the SK_ISSR register and determining
which interrupts have been reported. To cope with this situation we
continuously read the SK_ISSR register until there are no interrupts.

However, it seems that the above workaround does not fix all cases.
Add workaround code that tries to protect against false alarms from
the watchdog handler by trying to reclaim pending Tx descriptors
before resetting the hardware.

This should fix occasional watchdog timeouts seen with this driver.

From FreeBSD


# 1.111 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.110 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.109 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.108 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.107 01-May-2006 brad

Activate Tx descriptor poll timer in order to protect possible loss
of SK_TXBMU_TX_START command. Previously the driver continuously issued
SK_TXBMU_TX_START when it notices pending Tx descriptors not processed
yet in interrupt handler. That approach would add additional PCI
write access overhead under high Tx load situations and it might fail
if the first SK_TXBMU_TX_START was lost and no interrupt is generated
from the first SK_TXBMU_TX_START command.

From FreeBSD


# 1.106 01-May-2006 brad

Added Rx/Tx FIFO flush support for Yukon

From FreeBSD


# 1.105 01-May-2006 brad

A new function sk_yukon_tick(), to handle auto-negotiation properly for
Yukon-based adapters.

From FreeBSD


# 1.104 30-Apr-2006 brad

- Use SK_IS_GENESIS/SK_IS_YUKON where appropriate
- Remove SK_YUKON_FAMILY


# 1.103 30-Apr-2006 brad

- Interrupt handler now checks shared interrupt source and protects
the interrupt handler from NULL pointer dereference which was caused
by odd status word value. The status word can return 0xffffffff if the
cable is unplugged while Rx/Tx/auto-negotiation is in progress.

From FreeBSD


# 1.102 30-Apr-2006 brad

Update if_oerrors if we encounter watchdog error.

From FreeBSD


# 1.101 30-Apr-2006 brad

- Added/corrected register definitions for Yukon.
(Register information from Linux skge driver.)

From FreeBSD


# 1.100 23-Apr-2006 brad

some more ANSI, KNF and other tidying up.


# 1.99 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.98 17-Apr-2006 brad

If there is a timeout while writing to the PHY in
sk_marv_miibus_writereg() then print a message
indicating so, as done in the XMAC case.


# 1.97 17-Apr-2006 brad

Coviery CID 1108: Avoid NULL pointer deref.

Coverity CID 1105: Avoid NULL deref.

From NetBSD


# 1.96 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.95 13-Feb-2006 brad

add some ASIC revisions to the various switch cases and identify
some newer revs.


# 1.94 09-Feb-2006 brad

sync PCI id.


# 1.93 22-Dec-2005 brad

re-work PHY setup, media handling and dual-port detection.

Based on the Marvell FreeBSD driver.


# 1.92 16-Dec-2005 brad

remove unused code to use IO space.


# 1.91 15-Dec-2005 brad

merge printing of the revision and the interrupt string into one printf.


# 1.90 10-Dec-2005 brad

sk_shutdown -> skc_shutdown and register the shutdown function with
shutdownhook_establish().


# 1.89 10-Dec-2005 brad

shrink dmesg entry by one line by merging the chipset revision into
the skc line and fix various error condition printf's in skc_attach(),
sk_attach() and sk_alloc_jumbo_mem() so the messages will be displayed
properly.

ok krw@


# 1.88 26-Nov-2005 brad

fix interrupt moderation timer frequencies for Yukon and Yukon-II based
chips.

From Jeff Rizzo on NetBSD's tech-net list, based on the Marvell
sk98lin Linux driver, and also matches what the Marvell FreeBSD
does.


# 1.87 15-Nov-2005 brad

more accurately reflect the naming scheme of the Marvell Yukon devices with there
pcidevs entries.

Based on information from the Marvell Yukon/Yukon-II FreeBSD driver.


# 1.86 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.85 15-Oct-2005 brad

add 2 new Yukon PCI ids and recognize Yukon-2 EC Ultra ASIC.


# 1.84 15-Oct-2005 brad

update Via and 3Com ids.


# 1.83 20-Sep-2005 brad

memory, media handling and a bunch of register definitions for Yukon-2.

From jason@


# 1.82 20-Sep-2005 brad

merge xmaciireg.h and yukonreg.h into if_skreg.h


# 1.81 20-Sep-2005 brad

shuffle some stuff from skreg to skvar


# 1.80 17-Sep-2005 brad

add media detection and dual port detection for Yukon-2.

from jason@


# 1.79 16-Sep-2005 brad

- remove code to read PCI VPD as we do not use that anymore.
- remove some FreeBSD-ism's: struct resource *'s.
- fail more gracefully in sk_probe() instead of in sk_attach()
for newer unsupported ASIC revisions.

From jason@


Revision tags: OPENBSD_3_8_BASE
# 1.78 29-Aug-2005 brad

- use pci_mapreg_type() to fix some systems that would fail to attach
sk(4) with "can't map mem space".
- add missing newline for failure case of pci_intr_establish().

ok deraadt@


# 1.77 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.76 24-Jul-2005 fgsch

simplify error paths and add some missing ones; brad@ ok.
deallocation for jumbo memory left.


# 1.75 22-Jul-2005 brad

- sync sk_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()
- oops, forgot to remove a line in sk_rxeof()


# 1.74 22-Jul-2005 brad

also take the PCI subsystem id into consideration when trying to probe
for Linksys EG1032 cards, that way we do not try and attach to newer
rev 3 cards that use the RealTek 8169S chipset.


# 1.73 21-Jul-2005 brad

- add bus_dmamap_sync()'s; From NetBSD
- use pci_mapreg_map()
- remove unnecessary splimp() usage in skc_attach()
- make sure to disestablish the interrupt on failure

Tested by a few end-users.


# 1.72 14-Jul-2005 brad

add D-Link PCI id.

From: jsg@


# 1.71 12-Jul-2005 brad

remove unused prototype sk_free_jumbo_mem


# 1.70 12-Jul-2005 brad

free resources for Jumbo buffers in sk_stop().

ok deraadt, krw, beck


# 1.69 02-Jul-2005 brad

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


# 1.68 02-Jul-2005 brad

- mbuf external storage is of (caddr_t), not (caddr_t *).
- check for MTU being too small with ETHERMIN
- don't bother reseting the card since it'll default to allowing Jumbos


# 1.67 17-May-2005 jason

remove spurious bpf_mtap (I think it's leftover debugging code from a year ago)


# 1.66 16-May-2005 brad

add a newline here


# 1.65 11-May-2005 brad

remove comment which is not valid anymore


# 1.64 11-May-2005 brad

- Also match on Yukon LP's for the Lite rev A0 test.
- Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().
- Take PHY out of reset for Yukon Lite rev A3. This resolves the
intermittent "no PHY found!" issue.

From FreeBSD

- Recognize some newer Yukon chipsets

ok krw@, tested by krw@ and a few others, mostly with LOM Lite A3's but
also with some other ASIC revs too.


# 1.63 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.62 18-Mar-2005 brad

fail to attach with a printf instead of a panic for newer yet unsupported
Yukon-2-based cards.

ok deraadt@


# 1.61 12-Mar-2005 brad

add a bunch of PCI ids from the SysKonnect sk98lin driver.


# 1.60 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.59 02-Jan-2005 brad

cleanup and better ram sizing.


# 1.58 01-Jan-2005 brad

better chip/card identification.

From NetBSD

ok krw@


# 1.57 01-Jan-2005 brad

rev 1.92

only clear the IFF_OACTIVE flag when we have a chance of being able to
queue a packet to the hardware... instead of when the hardware queue is
empty..

don't initalize cur_tx now that it doesn't need to be...

rev 1.90

_OACTIVE is now handled better...

From FreeBSD

ok krw@


# 1.56 01-Jan-2005 krw

Don't initialize the card (and start an autonegotiation!) every time
the IP address changes. Makes 'dhclient sk0' invocations way faster
and more consistant. i.e. one DHCPREQUEST elicts the DHCPACK.

ok brad@ 'Wow. Great Idea.' deraadt@.


# 1.55 22-Dec-2004 brad

- add missing braces for SIOCSIFMTU switch case.
- allow reception of Jumbo frames all the time on GEnesis based cards,
same as Yukon based cards.

ok krw@ mcbride@


# 1.54 14-Dec-2004 krw

Fix off-by-one. From FreeBSD r1.87. Also in NetBSD. Field being filled
(sk_vpd_readonly) is not currently used, but the memory being tromped
on might be.

ok millert@.


# 1.53 08-Dec-2004 brad

use ETHER_MAX_LEN


# 1.52 08-Dec-2004 krw

Enable jumbo frames on Yukon varients of sk(4).

ok mcbride@.


# 1.51 16-Nov-2004 brad

Lower interrupt moderation timer to decrease service latency.

From NetBSD

ok deraadt@


# 1.50 16-Nov-2004 brad

back out previous commit and put the right change in which corresponds
to what the previous commit message said...

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).


# 1.49 16-Nov-2004 brad

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).

From NetBSD

ok henning@ mcbride@


# 1.48 11-Nov-2004 brad

- Fix Yukon ram sizing.
- Keep tx queue running by kicking the tx bmu repeatedly.
- Handle if_timer a bit better.

From NetBSD

ok deraadt@


# 1.47 14-Oct-2004 brad

Bail out quietly if the eeprom appears to be missing or empty. Fixes
support for D-Link DGE-530T adapters.

From: FreeBSD via Blake Willis <blake at 2112 dot net>

ok mcbride@


# 1.46 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
# 1.45 20-Aug-2004 deraadt

a belkin ID on a sk card


# 1.44 19-Aug-2004 mcbride

Don't complain about lack of jumbo storage when processing incoming packets
unless we're debugging.


# 1.43 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


# 1.42 04-Aug-2004 mcbride

Make jumbo frames work.
- allocate and manage our own memory for rx packets rather than using
mbuf clusters; code for this lifted from if_bge.c
- pass the correct size to bus_dmamap_create()

ok deraadt@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.41 29-May-2004 naddy

replace hand-rolled CRC calculation in multicast hash setup with calls to
ether_crc32_*(); ok mcbride@


# 1.40 24-May-2004 naddy

Make Yukon-style adapters also set up the multicast filter in sk_init().
This fixes various multicast-related problems. ok henning@


# 1.39 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.38 09-Mar-2004 matthieu

Fix multicast on recent sk chipsets. Adapted from a patch by Keith Mitchell
in <http://lists.freebsd.org/pipermail/freebsd-hardware/2003-December/000851.html>
Ok deraadt@.


# 1.37 17-Dec-2003 jason

not qualifying a product based on vendor AND product ID just bugs me


# 1.36 17-Dec-2003 jason

marvell skv2 (smc9452TX); from freebsd


# 1.35 17-Dec-2003 jason

add support for linksys (eg1032v2, eg1064v2) and dlink (dge530t); from NetBSD


# 1.34 13-Oct-2003 jason

rx checksum offload support (based on earlier code from aaron@, but with
fixes by me). Note: sk v1 chips can sometimes compute an incorrect cksum.
To deal with that, we never set the "bad" flags. Ie. if the card says it's
good, we assume it's good. If the card says it's bad, we fall back to
software. Ugly? You betcha.


Revision tags: OPENBSD_3_4_BASE
# 1.33 12-Aug-2003 nate

add/update my copyright


# 1.32 01-Aug-2003 nate

Support for new Marvell based Gigabit Ethernet adapters
ok deraadt@


Revision tags: UBC_SYNC_A
# 1.31 14-May-2003 nate

Makefile sk(4) use bus_dma
ok jason


# 1.30 08-May-2003 nate

a bit more cleanup


# 1.29 08-May-2003 nate

ansify, clean up formatting, remove useless return statements.
ok jason


Revision tags: OPENBSD_3_3_BASE
# 1.28 12-Mar-2003 nate

sk is capable of transmitting and receiving longer packets for 802.1q vlans
thanks to David Gwynne <loki@niteshade.net>. ok jason@ deraadt@


# 1.27 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.26 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.25 08-Jun-2002 jason

add missing ioctl support for SIOCSIFMTU


# 1.24 04-Jun-2002 deraadt

spelling; raj@cerias.purdue.edu


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

First round of __P removal in sys


# 1.22 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.21 15-Feb-2002 nordin

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


# 1.20 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


Revision tags: UBC_BASE
# 1.19 06-Nov-2001 miod

branches: 1.19.2;
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.18 05-Oct-2001 nate

use positive logic for match


# 1.17 11-Sep-2001 miod

Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.16 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.15 15-Aug-2001 jason

Add some stuff missed in a previous FreeBSD merge... Fixes the problem where
sk busy loops when carrier is lost until it returns; based on patch from
david langhorst <dirt@monkey.org> and tested by John Ladwig <jladwig@mango.lioness.net>


# 1.14 12-Aug-2001 mickey

remove redundant vm includes


# 1.13 25-Jun-2001 fgsch

trivial ether_input_mbuf() conversion.


Revision tags: OPENBSD_2_9_BASE
# 1.12 29-Mar-2001 jason

From FreeBSD:
- Call mii_pollstat() after we bring up the link on a 1000baseTX card
after autoneg so we make sure to set the link state and duplex mode
correctly.
- Make sure to set the 'ignore pause frames' bit on the XMAC.
- Small linewrap fix.
- Add actual URL for XMAC II datasheet in comments.


# 1.11 25-Mar-2001 csapuntz

Missing splx(s). Thanks to Dawson and team for finding this one


# 1.10 20-Feb-2001 mickey

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


Revision tags: OPENBSD_2_8_BASE
# 1.9 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.8 04-Sep-2000 deraadt

printing XaQti on 5 consecutive lines is stupid


# 1.7 29-Aug-2000 jason

From FreeBSD: split out the support for XMAC-II phys and other phys
add xmphy & brgphy to GENERIC


Revision tags: OPENBSD_2_7_BASE
# 1.6 15-Feb-2000 jason

make sure to call ether_{add,del}multi() as appropriate in xxx_ioctl()


Revision tags: SMP_BASE kame_19991208
# 1.5 08-Dec-1999 aaron

branches: 1.5.2;
Remove unused #define cruft.


Revision tags: OPENBSD_2_6_BASE
# 1.4 22-Oct-1999 deraadt

fix some panic bugs; jason


# 1.3 04-Oct-1999 jason

m_new is the new mbuf, not m
fix calculation of buffer slot number


# 1.2 03-Oct-1999 jason

take advantage of m->m_ext.ext_handle for storing the softc
(instead of stashing it in the buffer)


# 1.1 01-Oct-1999 jason

driver for SysKonnect 984x gigabit ethernet adapters; from FreeBSD


# 1.190 22-Jun-2020 dlg

use ifiq_input and use it's return value to apply backpressure to rxrs.

this is a step toward deprecating softclock based livelock detection.


Revision tags: 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.189 04-Jun-2017 dlg

use htolem32 and lemtoh32 instead of htole32 and letoh32.

saves about half a k on sparc64.


# 1.188 02-Jun-2017 dlg

handle 64bit dva in the tx path as well as the rx path.


# 1.187 01-Jun-2017 dlg

reorder ops in sk_start to avoid possibly rolling back ifq_deq.

instead of checking for space after beggining to deq a packet, check
for space before committing to handling a packet. this means we
can use ifq_dequeue instead of ifq_deq_begin/commit/rollback.

ok mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.186 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@


# 1.185 08-Jan-2017 visa

Use a macro for the Tx timeout value.

OK deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.184 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.183 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.182 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.181 24-Nov-2015 mpi

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


# 1.180 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.179 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.178 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.177 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.176 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.175 30-Apr-2015 mpi

Convert to if_input(), tweak and ok dlg@


# 1.174 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@


Revision tags: OPENBSD_5_7_BASE
# 1.173 22-Dec-2014 tedu

unifdef INET


# 1.172 20-Aug-2014 dlg

brad said i had some whitespace screwups in my previous diff. this cleans
them up and the others i found in this file.

no functional change.


# 1.171 20-Aug-2014 dlg

replace sks jumbo allocator with MCLGETI. the system provides jumbos in
the right shape now, we dont have to do it by hand all over the place
any more.

rework the rxr ring management to use if_rxring while here.

largely based on if_sk.c r1.152 and if_skvar.h r1.4 by kettenis.
tested by me on:

skc0 at pci3 dev 11 function 0 "Schneider & Koch SK-98xx" rev 0x12, GEnesis (0x0): apic 3 int 5
sk0 at skc0 port A: address 00:00:5a:99:8a:ec
xmphy0 at sk0 phy 0: XMAC II Gigabit PHY, rev. 2

and this from ian mcwilliam

skc0 at pci0 dev 9 function 0 "D-Link DGE-530T B1" rev 0x11, Yukon Lite (0x9): apic 2 int 17
sk0 at skc0 port A: address 00:17:9a:ba:b5:39
eephy0 at sk0 phy 0: 88E1011 Gigabit PHY, rev. 5

tested by brad@ too


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

Fewer <netinet/in_systm.h>


# 1.169 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.168 19-Apr-2014 henning

kill checksum offloading in sk.
it was RX only, nothing on the TX side
rather complex, might eat up (or more) offloading benefits in many cases
the hardware miscomputes the cksums sometimes, so we don't trust it
claiming a cksum is bad and re-do the cksum verification in sw then...
(but we trust it to not mark bad ones good? hmmmmmmmmm.)
diff was on tech for 3 months, nobody disagreed, everybody who spoke up
agrees or doesn't care.
pretty exactly a revert of the cksum offloading addition years ago, tested
by several, the only report i quickly find now is from David Higgs <higgsd
at gmail dot com>, thanks!


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

Sync activate code sequnces to if_msk.c as much as possible, in case
one of these is ever found in a suspend/hibernate system.


# 1.166 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.165 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_4_BASE
# 1.164 07-Mar-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok chris@


Revision tags: OPENBSD_5_3_BASE
# 1.163 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@


# 1.162 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


Revision tags: OPENBSD_5_2_BASE
# 1.161 24-Feb-2012 guenther

Correct the spelling of "transferred" and "transferring"

from Tobias Ulmer (tobiasu at tmux.org); ok jmc@, krw@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.160 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.159 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.158 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


Revision tags: OPENBSD_4_8_BASE
# 1.157 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.156 17-Oct-2009 martynas

use sc->sk_bsize in the unmap call too; ok theo


# 1.155 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.154 04-Oct-2009 deraadt

Merge over a bunch of detach logic from msk(4) so that this driver can
detach as well
ok kettenis


# 1.153 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_6_BASE
# 1.152 08-Jul-2009 sthen

revert MCLGETI for sk(4) for now. commit requested by deraadt@


# 1.151 30-Mar-2009 kettenis

Switch sk(4) over to using MCLGETI when allocating mbufs for the RX ring.
Another evil jumbo allocator bites the dust.


Revision tags: OPENBSD_4_5_BASE
# 1.150 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.149 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.148 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.147 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.146 24-May-2008 brad

Also recognize the Schneider & Koch SK-9821/SK-9843 adapters from
Fujitsu.


# 1.145 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.144 02-Mar-2008 brad

Change some spaces to tabs in the transmit functions.

ok kettenis@


# 1.143 17-Jan-2008 brad

Add splnet around mii_tick() in sk_yukon_tick().

ok kettenis@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.142 26-May-2007 reyk

separate the attach information from the status information with a colon.

suggested by deraadt@


# 1.141 22-May-2007 ray

%z in printf(9) is not the same as %z in printf(3). Change to %lu
and cast arg to ulong.

OK miod@.


# 1.140 07-May-2007 deraadt

shrink code by not using __inline without static; ok kettenis


Revision tags: OPENBSD_4_1_BASE
# 1.139 12-Feb-2007 pedro

Fix prototype, from brad@, no binary change


# 1.138 10-Feb-2007 krw

Move HASH_BITS constant to if_skreg.h as SK_HASH_BITS. Remove unused
code and an unnecessary comment, No functional change.

From brad@.


# 1.137 03-Feb-2007 kettenis

Fix typo; clear tx FIFO underrun IRQ as intended instead of rx FIFO overrun
IRQ. From brad@


# 1.136 18-Jan-2007 krw

Don't reinitialize card at every media change.

From Brad, tested by Brad, wilfried@ and Johan M:son Lindman.

ok wilfried@


# 1.135 05-Jan-2007 kettenis

For Yukon-based cards, pass MIIF_DOPAUSE to mii_attach().

From brad@


# 1.134 03-Jan-2007 kettenis

In sk_marv_miibus_writereg, wait for busy flag to clear instead of
continuing when busy flag set.


# 1.133 03-Jan-2007 krw

Don't say 'Marvell' twice for each sk/msk device in dmesg. No functional
change.

from brad@ ok mglocker@


# 1.132 06-Dec-2006 reyk

- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested on amd64/i386/sparc64

ok brad@ mglocker@


# 1.131 16-Nov-2006 brad

remove the small amount of code for Yukon-2 chipsets now that there is msk(4).


# 1.130 08-Nov-2006 kettenis

Make XMAC work on on big-endian systems.

help & ok jason@, ok brad@


# 1.129 16-Oct-2006 tom

Fix some "is is"s. ok otto@.


# 1.128 27-Sep-2006 brad

fix the use of LIST_INSERT_HEAD in [m]sk_alloc_jumbo_mem().


# 1.127 26-Sep-2006 brad

Set sk_jumbo_buf to NULL if malloc() fails in the for loop within
[m]sk_alloc_jumbo_mem().


# 1.126 18-Sep-2006 brad

g/c unused SK_{SET,CLR}BIT macros

From riz@NetBSD


Revision tags: OPENBSD_4_0_BASE
# 1.125 17-Aug-2006 brad

cosmetic tweaks.


# 1.124 17-Aug-2006 brad

remove PCI ids which msk(4) will match against from sk(4).


# 1.123 09-Aug-2006 brad

revert rev 1.119 as this seems to cause problems with some PHY.


# 1.122 04-Aug-2006 brad

and the same goes for sk_init_yukon().


# 1.121 04-Aug-2006 brad

remove now redundant promiscuous mode handling code from sk_init_xmac().


# 1.120 04-Aug-2006 brad

refactor the promiscuous mode handling code and simplify the ioctl handler.


# 1.119 04-Aug-2006 brad

Fix busy check for PHY write operation with Yukon chips.

From yongari@FreeBSD


# 1.118 30-Jul-2006 brad

Add more strict receive path packet validation routine. Previously
the driver could pass corrupted packets to the upper layer under
certain conditions.

From yongari@FreeBSD


# 1.117 23-Jul-2006 brad

improved Yukon init routine with proper workaround for the PHY COMA mode.

From yongari@FreeBSD


# 1.116 22-Jun-2006 brad

Add appropriate swapping for big-endian systems. Allows sk(4) to work
on macppc and sparc64.

ok reyk@


# 1.115 22-Jun-2006 brad

adjust PCI ids.


# 1.114 17-Jun-2006 brad

add sys/timeout.h


# 1.113 17-Jun-2006 brad

remove some whitespace.


# 1.112 15-Jun-2006 brad

Fix watchdog timeout errors seen on a few systems.

The SK-NET GENESIS document says reading the SK_ISSR register should stop
generating further interrupts, but it seems there is the possibility
of losing interrupts between reading the SK_ISSR register and determining
which interrupts have been reported. To cope with this situation we
continuously read the SK_ISSR register until there are no interrupts.

However, it seems that the above workaround does not fix all cases.
Add workaround code that tries to protect against false alarms from
the watchdog handler by trying to reclaim pending Tx descriptors
before resetting the hardware.

This should fix occasional watchdog timeouts seen with this driver.

From FreeBSD


# 1.111 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.110 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.109 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.108 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.107 01-May-2006 brad

Activate Tx descriptor poll timer in order to protect possible loss
of SK_TXBMU_TX_START command. Previously the driver continuously issued
SK_TXBMU_TX_START when it notices pending Tx descriptors not processed
yet in interrupt handler. That approach would add additional PCI
write access overhead under high Tx load situations and it might fail
if the first SK_TXBMU_TX_START was lost and no interrupt is generated
from the first SK_TXBMU_TX_START command.

From FreeBSD


# 1.106 01-May-2006 brad

Added Rx/Tx FIFO flush support for Yukon

From FreeBSD


# 1.105 01-May-2006 brad

A new function sk_yukon_tick(), to handle auto-negotiation properly for
Yukon-based adapters.

From FreeBSD


# 1.104 30-Apr-2006 brad

- Use SK_IS_GENESIS/SK_IS_YUKON where appropriate
- Remove SK_YUKON_FAMILY


# 1.103 30-Apr-2006 brad

- Interrupt handler now checks shared interrupt source and protects
the interrupt handler from NULL pointer dereference which was caused
by odd status word value. The status word can return 0xffffffff if the
cable is unplugged while Rx/Tx/auto-negotiation is in progress.

From FreeBSD


# 1.102 30-Apr-2006 brad

Update if_oerrors if we encounter watchdog error.

From FreeBSD


# 1.101 30-Apr-2006 brad

- Added/corrected register definitions for Yukon.
(Register information from Linux skge driver.)

From FreeBSD


# 1.100 23-Apr-2006 brad

some more ANSI, KNF and other tidying up.


# 1.99 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.98 17-Apr-2006 brad

If there is a timeout while writing to the PHY in
sk_marv_miibus_writereg() then print a message
indicating so, as done in the XMAC case.


# 1.97 17-Apr-2006 brad

Coviery CID 1108: Avoid NULL pointer deref.

Coverity CID 1105: Avoid NULL deref.

From NetBSD


# 1.96 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.95 13-Feb-2006 brad

add some ASIC revisions to the various switch cases and identify
some newer revs.


# 1.94 09-Feb-2006 brad

sync PCI id.


# 1.93 22-Dec-2005 brad

re-work PHY setup, media handling and dual-port detection.

Based on the Marvell FreeBSD driver.


# 1.92 16-Dec-2005 brad

remove unused code to use IO space.


# 1.91 15-Dec-2005 brad

merge printing of the revision and the interrupt string into one printf.


# 1.90 10-Dec-2005 brad

sk_shutdown -> skc_shutdown and register the shutdown function with
shutdownhook_establish().


# 1.89 10-Dec-2005 brad

shrink dmesg entry by one line by merging the chipset revision into
the skc line and fix various error condition printf's in skc_attach(),
sk_attach() and sk_alloc_jumbo_mem() so the messages will be displayed
properly.

ok krw@


# 1.88 26-Nov-2005 brad

fix interrupt moderation timer frequencies for Yukon and Yukon-II based
chips.

From Jeff Rizzo on NetBSD's tech-net list, based on the Marvell
sk98lin Linux driver, and also matches what the Marvell FreeBSD
does.


# 1.87 15-Nov-2005 brad

more accurately reflect the naming scheme of the Marvell Yukon devices with there
pcidevs entries.

Based on information from the Marvell Yukon/Yukon-II FreeBSD driver.


# 1.86 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.85 15-Oct-2005 brad

add 2 new Yukon PCI ids and recognize Yukon-2 EC Ultra ASIC.


# 1.84 15-Oct-2005 brad

update Via and 3Com ids.


# 1.83 20-Sep-2005 brad

memory, media handling and a bunch of register definitions for Yukon-2.

From jason@


# 1.82 20-Sep-2005 brad

merge xmaciireg.h and yukonreg.h into if_skreg.h


# 1.81 20-Sep-2005 brad

shuffle some stuff from skreg to skvar


# 1.80 17-Sep-2005 brad

add media detection and dual port detection for Yukon-2.

from jason@


# 1.79 16-Sep-2005 brad

- remove code to read PCI VPD as we do not use that anymore.
- remove some FreeBSD-ism's: struct resource *'s.
- fail more gracefully in sk_probe() instead of in sk_attach()
for newer unsupported ASIC revisions.

From jason@


Revision tags: OPENBSD_3_8_BASE
# 1.78 29-Aug-2005 brad

- use pci_mapreg_type() to fix some systems that would fail to attach
sk(4) with "can't map mem space".
- add missing newline for failure case of pci_intr_establish().

ok deraadt@


# 1.77 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.76 24-Jul-2005 fgsch

simplify error paths and add some missing ones; brad@ ok.
deallocation for jumbo memory left.


# 1.75 22-Jul-2005 brad

- sync sk_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()
- oops, forgot to remove a line in sk_rxeof()


# 1.74 22-Jul-2005 brad

also take the PCI subsystem id into consideration when trying to probe
for Linksys EG1032 cards, that way we do not try and attach to newer
rev 3 cards that use the RealTek 8169S chipset.


# 1.73 21-Jul-2005 brad

- add bus_dmamap_sync()'s; From NetBSD
- use pci_mapreg_map()
- remove unnecessary splimp() usage in skc_attach()
- make sure to disestablish the interrupt on failure

Tested by a few end-users.


# 1.72 14-Jul-2005 brad

add D-Link PCI id.

From: jsg@


# 1.71 12-Jul-2005 brad

remove unused prototype sk_free_jumbo_mem


# 1.70 12-Jul-2005 brad

free resources for Jumbo buffers in sk_stop().

ok deraadt, krw, beck


# 1.69 02-Jul-2005 brad

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


# 1.68 02-Jul-2005 brad

- mbuf external storage is of (caddr_t), not (caddr_t *).
- check for MTU being too small with ETHERMIN
- don't bother reseting the card since it'll default to allowing Jumbos


# 1.67 17-May-2005 jason

remove spurious bpf_mtap (I think it's leftover debugging code from a year ago)


# 1.66 16-May-2005 brad

add a newline here


# 1.65 11-May-2005 brad

remove comment which is not valid anymore


# 1.64 11-May-2005 brad

- Also match on Yukon LP's for the Lite rev A0 test.
- Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().
- Take PHY out of reset for Yukon Lite rev A3. This resolves the
intermittent "no PHY found!" issue.

From FreeBSD

- Recognize some newer Yukon chipsets

ok krw@, tested by krw@ and a few others, mostly with LOM Lite A3's but
also with some other ASIC revs too.


# 1.63 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.62 18-Mar-2005 brad

fail to attach with a printf instead of a panic for newer yet unsupported
Yukon-2-based cards.

ok deraadt@


# 1.61 12-Mar-2005 brad

add a bunch of PCI ids from the SysKonnect sk98lin driver.


# 1.60 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.59 02-Jan-2005 brad

cleanup and better ram sizing.


# 1.58 01-Jan-2005 brad

better chip/card identification.

From NetBSD

ok krw@


# 1.57 01-Jan-2005 brad

rev 1.92

only clear the IFF_OACTIVE flag when we have a chance of being able to
queue a packet to the hardware... instead of when the hardware queue is
empty..

don't initalize cur_tx now that it doesn't need to be...

rev 1.90

_OACTIVE is now handled better...

From FreeBSD

ok krw@


# 1.56 01-Jan-2005 krw

Don't initialize the card (and start an autonegotiation!) every time
the IP address changes. Makes 'dhclient sk0' invocations way faster
and more consistant. i.e. one DHCPREQUEST elicts the DHCPACK.

ok brad@ 'Wow. Great Idea.' deraadt@.


# 1.55 22-Dec-2004 brad

- add missing braces for SIOCSIFMTU switch case.
- allow reception of Jumbo frames all the time on GEnesis based cards,
same as Yukon based cards.

ok krw@ mcbride@


# 1.54 14-Dec-2004 krw

Fix off-by-one. From FreeBSD r1.87. Also in NetBSD. Field being filled
(sk_vpd_readonly) is not currently used, but the memory being tromped
on might be.

ok millert@.


# 1.53 08-Dec-2004 brad

use ETHER_MAX_LEN


# 1.52 08-Dec-2004 krw

Enable jumbo frames on Yukon varients of sk(4).

ok mcbride@.


# 1.51 16-Nov-2004 brad

Lower interrupt moderation timer to decrease service latency.

From NetBSD

ok deraadt@


# 1.50 16-Nov-2004 brad

back out previous commit and put the right change in which corresponds
to what the previous commit message said...

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).


# 1.49 16-Nov-2004 brad

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).

From NetBSD

ok henning@ mcbride@


# 1.48 11-Nov-2004 brad

- Fix Yukon ram sizing.
- Keep tx queue running by kicking the tx bmu repeatedly.
- Handle if_timer a bit better.

From NetBSD

ok deraadt@


# 1.47 14-Oct-2004 brad

Bail out quietly if the eeprom appears to be missing or empty. Fixes
support for D-Link DGE-530T adapters.

From: FreeBSD via Blake Willis <blake at 2112 dot net>

ok mcbride@


# 1.46 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
# 1.45 20-Aug-2004 deraadt

a belkin ID on a sk card


# 1.44 19-Aug-2004 mcbride

Don't complain about lack of jumbo storage when processing incoming packets
unless we're debugging.


# 1.43 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


# 1.42 04-Aug-2004 mcbride

Make jumbo frames work.
- allocate and manage our own memory for rx packets rather than using
mbuf clusters; code for this lifted from if_bge.c
- pass the correct size to bus_dmamap_create()

ok deraadt@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.41 29-May-2004 naddy

replace hand-rolled CRC calculation in multicast hash setup with calls to
ether_crc32_*(); ok mcbride@


# 1.40 24-May-2004 naddy

Make Yukon-style adapters also set up the multicast filter in sk_init().
This fixes various multicast-related problems. ok henning@


# 1.39 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.38 09-Mar-2004 matthieu

Fix multicast on recent sk chipsets. Adapted from a patch by Keith Mitchell
in <http://lists.freebsd.org/pipermail/freebsd-hardware/2003-December/000851.html>
Ok deraadt@.


# 1.37 17-Dec-2003 jason

not qualifying a product based on vendor AND product ID just bugs me


# 1.36 17-Dec-2003 jason

marvell skv2 (smc9452TX); from freebsd


# 1.35 17-Dec-2003 jason

add support for linksys (eg1032v2, eg1064v2) and dlink (dge530t); from NetBSD


# 1.34 13-Oct-2003 jason

rx checksum offload support (based on earlier code from aaron@, but with
fixes by me). Note: sk v1 chips can sometimes compute an incorrect cksum.
To deal with that, we never set the "bad" flags. Ie. if the card says it's
good, we assume it's good. If the card says it's bad, we fall back to
software. Ugly? You betcha.


Revision tags: OPENBSD_3_4_BASE
# 1.33 12-Aug-2003 nate

add/update my copyright


# 1.32 01-Aug-2003 nate

Support for new Marvell based Gigabit Ethernet adapters
ok deraadt@


Revision tags: UBC_SYNC_A
# 1.31 14-May-2003 nate

Makefile sk(4) use bus_dma
ok jason


# 1.30 08-May-2003 nate

a bit more cleanup


# 1.29 08-May-2003 nate

ansify, clean up formatting, remove useless return statements.
ok jason


Revision tags: OPENBSD_3_3_BASE
# 1.28 12-Mar-2003 nate

sk is capable of transmitting and receiving longer packets for 802.1q vlans
thanks to David Gwynne <loki@niteshade.net>. ok jason@ deraadt@


# 1.27 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.26 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.25 08-Jun-2002 jason

add missing ioctl support for SIOCSIFMTU


# 1.24 04-Jun-2002 deraadt

spelling; raj@cerias.purdue.edu


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

First round of __P removal in sys


# 1.22 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.21 15-Feb-2002 nordin

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


# 1.20 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


Revision tags: UBC_BASE
# 1.19 06-Nov-2001 miod

branches: 1.19.2;
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.18 05-Oct-2001 nate

use positive logic for match


# 1.17 11-Sep-2001 miod

Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.16 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.15 15-Aug-2001 jason

Add some stuff missed in a previous FreeBSD merge... Fixes the problem where
sk busy loops when carrier is lost until it returns; based on patch from
david langhorst <dirt@monkey.org> and tested by John Ladwig <jladwig@mango.lioness.net>


# 1.14 12-Aug-2001 mickey

remove redundant vm includes


# 1.13 25-Jun-2001 fgsch

trivial ether_input_mbuf() conversion.


Revision tags: OPENBSD_2_9_BASE
# 1.12 29-Mar-2001 jason

From FreeBSD:
- Call mii_pollstat() after we bring up the link on a 1000baseTX card
after autoneg so we make sure to set the link state and duplex mode
correctly.
- Make sure to set the 'ignore pause frames' bit on the XMAC.
- Small linewrap fix.
- Add actual URL for XMAC II datasheet in comments.


# 1.11 25-Mar-2001 csapuntz

Missing splx(s). Thanks to Dawson and team for finding this one


# 1.10 20-Feb-2001 mickey

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


Revision tags: OPENBSD_2_8_BASE
# 1.9 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.8 04-Sep-2000 deraadt

printing XaQti on 5 consecutive lines is stupid


# 1.7 29-Aug-2000 jason

From FreeBSD: split out the support for XMAC-II phys and other phys
add xmphy & brgphy to GENERIC


Revision tags: OPENBSD_2_7_BASE
# 1.6 15-Feb-2000 jason

make sure to call ether_{add,del}multi() as appropriate in xxx_ioctl()


Revision tags: SMP_BASE kame_19991208
# 1.5 08-Dec-1999 aaron

branches: 1.5.2;
Remove unused #define cruft.


Revision tags: OPENBSD_2_6_BASE
# 1.4 22-Oct-1999 deraadt

fix some panic bugs; jason


# 1.3 04-Oct-1999 jason

m_new is the new mbuf, not m
fix calculation of buffer slot number


# 1.2 03-Oct-1999 jason

take advantage of m->m_ext.ext_handle for storing the softc
(instead of stashing it in the buffer)


# 1.1 01-Oct-1999 jason

driver for SysKonnect 984x gigabit ethernet adapters; from FreeBSD


Revision tags: OPENBSD_6_2_BASE
# 1.189 04-Jun-2017 dlg

use htolem32 and lemtoh32 instead of htole32 and letoh32.

saves about half a k on sparc64.


# 1.188 02-Jun-2017 dlg

handle 64bit dva in the tx path as well as the rx path.


# 1.187 01-Jun-2017 dlg

reorder ops in sk_start to avoid possibly rolling back ifq_deq.

instead of checking for space after beggining to deq a packet, check
for space before committing to handling a packet. this means we
can use ifq_dequeue instead of ifq_deq_begin/commit/rollback.

ok mikeb@


Revision tags: OPENBSD_6_1_BASE
# 1.186 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@


# 1.185 08-Jan-2017 visa

Use a macro for the Tx timeout value.

OK deraadt@ kettenis@


Revision tags: OPENBSD_6_0_BASE
# 1.184 13-Apr-2016 mpi

G/C IFQ_SET_READY().


Revision tags: OPENBSD_5_9_BASE
# 1.183 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.182 24-Nov-2015 mpi

You only need <net/if_dl.h> if you're using LLADDR() or a sockaddr_dl.


# 1.181 24-Nov-2015 mpi

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


# 1.180 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.179 14-Nov-2015 mpi

Do not include <net/if_vlan_var.h> when it's not necessary.

Because of the VLAN hacks in mpw(4) this file still contains the definition
of "struct ifvlan" which depends on <sys/refcnt.h> which in turns pull
<sys/atomic.h>...


# 1.178 25-Oct-2015 mpi

arp_ifinit() is no longer needed.


Revision tags: OPENBSD_5_8_BASE
# 1.177 19-Jul-2015 yuo

use standardized register definition in mii.h rather than each
specific driver definition.

no logical change.

ok deraadt@


# 1.176 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.175 30-Apr-2015 mpi

Convert to if_input(), tweak and ok dlg@


# 1.174 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@


Revision tags: OPENBSD_5_7_BASE
# 1.173 22-Dec-2014 tedu

unifdef INET


# 1.172 20-Aug-2014 dlg

brad said i had some whitespace screwups in my previous diff. this cleans
them up and the others i found in this file.

no functional change.


# 1.171 20-Aug-2014 dlg

replace sks jumbo allocator with MCLGETI. the system provides jumbos in
the right shape now, we dont have to do it by hand all over the place
any more.

rework the rxr ring management to use if_rxring while here.

largely based on if_sk.c r1.152 and if_skvar.h r1.4 by kettenis.
tested by me on:

skc0 at pci3 dev 11 function 0 "Schneider & Koch SK-98xx" rev 0x12, GEnesis (0x0): apic 3 int 5
sk0 at skc0 port A: address 00:00:5a:99:8a:ec
xmphy0 at sk0 phy 0: XMAC II Gigabit PHY, rev. 2

and this from ian mcwilliam

skc0 at pci0 dev 9 function 0 "D-Link DGE-530T B1" rev 0x11, Yukon Lite (0x9): apic 2 int 17
sk0 at skc0 port A: address 00:17:9a:ba:b5:39
eephy0 at sk0 phy 0: 88E1011 Gigabit PHY, rev. 5

tested by brad@ too


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

Fewer <netinet/in_systm.h>


# 1.169 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.168 19-Apr-2014 henning

kill checksum offloading in sk.
it was RX only, nothing on the TX side
rather complex, might eat up (or more) offloading benefits in many cases
the hardware miscomputes the cksums sometimes, so we don't trust it
claiming a cksum is bad and re-do the cksum verification in sw then...
(but we trust it to not mark bad ones good? hmmmmmmmmm.)
diff was on tech for 3 months, nobody disagreed, everybody who spoke up
agrees or doesn't care.
pretty exactly a revert of the cksum offloading addition years ago, tested
by several, the only report i quickly find now is from David Higgs <higgsd
at gmail dot com>, thanks!


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

Sync activate code sequnces to if_msk.c as much as possible, in case
one of these is ever found in a suspend/hibernate system.


# 1.166 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.165 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_4_BASE
# 1.164 07-Mar-2013 brad

Rewrite the receive filter handling code and cleanup the ioctl bits.

ok chris@


Revision tags: OPENBSD_5_3_BASE
# 1.163 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@


# 1.162 18-Oct-2012 deraadt

Convert a number of old private copies of code which predates
pci_set_powerstate() to using it instead. Many of these chunks of code had
bugs in them, especially missing delay() calls. Some of them were doing
things our PCI subsystem is now responsible for handling. If you have
any of the affected devices, please keep an eye out for regressions.
ok kettenis


Revision tags: OPENBSD_5_2_BASE
# 1.161 24-Feb-2012 guenther

Correct the spelling of "transferred" and "transferring"

from Tobias Ulmer (tobiasu at tmux.org); ok jmc@, krw@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.160 22-Jun-2011 tedu

kill a few more casts that aren't helpful. ok krw miod


# 1.159 03-Apr-2011 jasper

use nitems(); no binary change for drivers that are compiled on amd64.

ok claudio@


Revision tags: OPENBSD_4_9_BASE
# 1.158 20-Sep-2010 deraadt

Stop doing shutdown hooks in network drivers where possible. We already
take all interfaces down, via their xxstop routines. Claudio and I have
verified that none of the shutdown hooks do much extra beyond what xxstop
was already doing; it is largely a pile of junk.
ok claudio, some early comments by sthen; also read by matthew, jsg


Revision tags: OPENBSD_4_8_BASE
# 1.157 19-May-2010 oga

BUS_DMA_ZERO instead of alloc, map, bzero.

ok krw@


Revision tags: OPENBSD_4_7_BASE
# 1.156 17-Oct-2009 martynas

use sc->sk_bsize in the unmap call too; ok theo


# 1.155 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.154 04-Oct-2009 deraadt

Merge over a bunch of detach logic from msk(4) so that this driver can
detach as well
ok kettenis


# 1.153 13-Aug-2009 jasper

- consistify cfdriver for the ethernet drivers (0 -> NULL)

ok dlg@


Revision tags: OPENBSD_4_6_BASE
# 1.152 08-Jul-2009 sthen

revert MCLGETI for sk(4) for now. commit requested by deraadt@


# 1.151 30-Mar-2009 kettenis

Switch sk(4) over to using MCLGETI when allocating mbufs for the RX ring.
Another evil jumbo allocator bites the dust.


Revision tags: OPENBSD_4_5_BASE
# 1.150 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.149 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.148 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.147 10-Sep-2008 blambert

Convert timeout_add() calls using multiples of hz to timeout_add_sec()

Really just the low-hanging fruit of (hopefully) forthcoming timeout
conversions.

ok art@, krw@


Revision tags: OPENBSD_4_4_BASE
# 1.146 24-May-2008 brad

Also recognize the Schneider & Koch SK-9821/SK-9843 adapters from
Fujitsu.


# 1.145 23-May-2008 brad

Simplify the combination use of pci_mapreg_type()/pci_mapreg_map() as
suggested by dlg@ awhile ago.

ok dlg@


Revision tags: OPENBSD_4_3_BASE
# 1.144 02-Mar-2008 brad

Change some spaces to tabs in the transmit functions.

ok kettenis@


# 1.143 17-Jan-2008 brad

Add splnet around mii_tick() in sk_yukon_tick().

ok kettenis@ dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.142 26-May-2007 reyk

separate the attach information from the status information with a colon.

suggested by deraadt@


# 1.141 22-May-2007 ray

%z in printf(9) is not the same as %z in printf(3). Change to %lu
and cast arg to ulong.

OK miod@.


# 1.140 07-May-2007 deraadt

shrink code by not using __inline without static; ok kettenis


Revision tags: OPENBSD_4_1_BASE
# 1.139 12-Feb-2007 pedro

Fix prototype, from brad@, no binary change


# 1.138 10-Feb-2007 krw

Move HASH_BITS constant to if_skreg.h as SK_HASH_BITS. Remove unused
code and an unnecessary comment, No functional change.

From brad@.


# 1.137 03-Feb-2007 kettenis

Fix typo; clear tx FIFO underrun IRQ as intended instead of rx FIFO overrun
IRQ. From brad@


# 1.136 18-Jan-2007 krw

Don't reinitialize card at every media change.

From Brad, tested by Brad, wilfried@ and Johan M:son Lindman.

ok wilfried@


# 1.135 05-Jan-2007 kettenis

For Yukon-based cards, pass MIIF_DOPAUSE to mii_attach().

From brad@


# 1.134 03-Jan-2007 kettenis

In sk_marv_miibus_writereg, wait for busy flag to clear instead of
continuing when busy flag set.


# 1.133 03-Jan-2007 krw

Don't say 'Marvell' twice for each sk/msk device in dmesg. No functional
change.

from brad@ ok mglocker@


# 1.132 06-Dec-2006 reyk

- Move TX ring full sanity check further up and check the number of DMA
segments from the DMA map, instead of counting the DMA segments in the
for loop and breaking out later.
- Unload the DMA map if encountering an error condition.

Tested on amd64/i386/sparc64

ok brad@ mglocker@


# 1.131 16-Nov-2006 brad

remove the small amount of code for Yukon-2 chipsets now that there is msk(4).


# 1.130 08-Nov-2006 kettenis

Make XMAC work on on big-endian systems.

help & ok jason@, ok brad@


# 1.129 16-Oct-2006 tom

Fix some "is is"s. ok otto@.


# 1.128 27-Sep-2006 brad

fix the use of LIST_INSERT_HEAD in [m]sk_alloc_jumbo_mem().


# 1.127 26-Sep-2006 brad

Set sk_jumbo_buf to NULL if malloc() fails in the for loop within
[m]sk_alloc_jumbo_mem().


# 1.126 18-Sep-2006 brad

g/c unused SK_{SET,CLR}BIT macros

From riz@NetBSD


Revision tags: OPENBSD_4_0_BASE
# 1.125 17-Aug-2006 brad

cosmetic tweaks.


# 1.124 17-Aug-2006 brad

remove PCI ids which msk(4) will match against from sk(4).


# 1.123 09-Aug-2006 brad

revert rev 1.119 as this seems to cause problems with some PHY.


# 1.122 04-Aug-2006 brad

and the same goes for sk_init_yukon().


# 1.121 04-Aug-2006 brad

remove now redundant promiscuous mode handling code from sk_init_xmac().


# 1.120 04-Aug-2006 brad

refactor the promiscuous mode handling code and simplify the ioctl handler.


# 1.119 04-Aug-2006 brad

Fix busy check for PHY write operation with Yukon chips.

From yongari@FreeBSD


# 1.118 30-Jul-2006 brad

Add more strict receive path packet validation routine. Previously
the driver could pass corrupted packets to the upper layer under
certain conditions.

From yongari@FreeBSD


# 1.117 23-Jul-2006 brad

improved Yukon init routine with proper workaround for the PHY COMA mode.

From yongari@FreeBSD


# 1.116 22-Jun-2006 brad

Add appropriate swapping for big-endian systems. Allows sk(4) to work
on macppc and sparc64.

ok reyk@


# 1.115 22-Jun-2006 brad

adjust PCI ids.


# 1.114 17-Jun-2006 brad

add sys/timeout.h


# 1.113 17-Jun-2006 brad

remove some whitespace.


# 1.112 15-Jun-2006 brad

Fix watchdog timeout errors seen on a few systems.

The SK-NET GENESIS document says reading the SK_ISSR register should stop
generating further interrupts, but it seems there is the possibility
of losing interrupts between reading the SK_ISSR register and determining
which interrupts have been reported. To cope with this situation we
continuously read the SK_ISSR register until there are no interrupts.

However, it seems that the above workaround does not fix all cases.
Add workaround code that tries to protect against false alarms from
the watchdog handler by trying to reclaim pending Tx descriptors
before resetting the hardware.

This should fix occasional watchdog timeouts seen with this driver.

From FreeBSD


# 1.111 28-May-2006 brad

- remove ETHER_MAX_LEN_JUMBO and ETHERMTU_JUMBO.
- use if_hardmtu for MTU ioctl handlers.

ok reyk@


# 1.110 28-May-2006 jason

unknown ioctl is ENOTTY not EINVAL


# 1.109 27-May-2006 brad

remove IFCAP_JUMBO_MTU interface capabilities flag and set if_hardmtu in a few
more drivers.

ok reyk@


# 1.108 20-May-2006 brad

set if_jumbo_mtu and the IFCAP_JUMBO_MTU capabilities flag where
appropriate.

ok reyk@


# 1.107 01-May-2006 brad

Activate Tx descriptor poll timer in order to protect possible loss
of SK_TXBMU_TX_START command. Previously the driver continuously issued
SK_TXBMU_TX_START when it notices pending Tx descriptors not processed
yet in interrupt handler. That approach would add additional PCI
write access overhead under high Tx load situations and it might fail
if the first SK_TXBMU_TX_START was lost and no interrupt is generated
from the first SK_TXBMU_TX_START command.

From FreeBSD


# 1.106 01-May-2006 brad

Added Rx/Tx FIFO flush support for Yukon

From FreeBSD


# 1.105 01-May-2006 brad

A new function sk_yukon_tick(), to handle auto-negotiation properly for
Yukon-based adapters.

From FreeBSD


# 1.104 30-Apr-2006 brad

- Use SK_IS_GENESIS/SK_IS_YUKON where appropriate
- Remove SK_YUKON_FAMILY


# 1.103 30-Apr-2006 brad

- Interrupt handler now checks shared interrupt source and protects
the interrupt handler from NULL pointer dereference which was caused
by odd status word value. The status word can return 0xffffffff if the
cable is unplugged while Rx/Tx/auto-negotiation is in progress.

From FreeBSD


# 1.102 30-Apr-2006 brad

Update if_oerrors if we encounter watchdog error.

From FreeBSD


# 1.101 30-Apr-2006 brad

- Added/corrected register definitions for Yukon.
(Register information from Linux skge driver.)

From FreeBSD


# 1.100 23-Apr-2006 brad

some more ANSI, KNF and other tidying up.


# 1.99 20-Apr-2006 miod

Fix various printf() issues: too many arguments, not enough arguments, argument
order reversed, wrong modifiers. ok deraadt@ marco@ mickey@


# 1.98 17-Apr-2006 brad

If there is a timeout while writing to the PHY in
sk_marv_miibus_writereg() then print a message
indicating so, as done in the XMAC case.


# 1.97 17-Apr-2006 brad

Coviery CID 1108: Avoid NULL pointer deref.

Coverity CID 1105: Avoid NULL deref.

From NetBSD


# 1.96 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.95 13-Feb-2006 brad

add some ASIC revisions to the various switch cases and identify
some newer revs.


# 1.94 09-Feb-2006 brad

sync PCI id.


# 1.93 22-Dec-2005 brad

re-work PHY setup, media handling and dual-port detection.

Based on the Marvell FreeBSD driver.


# 1.92 16-Dec-2005 brad

remove unused code to use IO space.


# 1.91 15-Dec-2005 brad

merge printing of the revision and the interrupt string into one printf.


# 1.90 10-Dec-2005 brad

sk_shutdown -> skc_shutdown and register the shutdown function with
shutdownhook_establish().


# 1.89 10-Dec-2005 brad

shrink dmesg entry by one line by merging the chipset revision into
the skc line and fix various error condition printf's in skc_attach(),
sk_attach() and sk_alloc_jumbo_mem() so the messages will be displayed
properly.

ok krw@


# 1.88 26-Nov-2005 brad

fix interrupt moderation timer frequencies for Yukon and Yukon-II based
chips.

From Jeff Rizzo on NetBSD's tech-net list, based on the Marvell
sk98lin Linux driver, and also matches what the Marvell FreeBSD
does.


# 1.87 15-Nov-2005 brad

more accurately reflect the naming scheme of the Marvell Yukon devices with there
pcidevs entries.

Based on information from the Marvell Yukon/Yukon-II FreeBSD driver.


# 1.86 07-Nov-2005 brad

- splimp -> splnet
- remove spl's from attach
- removing redundant checks before pci_mapreg_map()
- fix dmesg printing
- de-allocate resources on failure to attach
- remove unused VLAN input code from vge(4)


# 1.85 15-Oct-2005 brad

add 2 new Yukon PCI ids and recognize Yukon-2 EC Ultra ASIC.


# 1.84 15-Oct-2005 brad

update Via and 3Com ids.


# 1.83 20-Sep-2005 brad

memory, media handling and a bunch of register definitions for Yukon-2.

From jason@


# 1.82 20-Sep-2005 brad

merge xmaciireg.h and yukonreg.h into if_skreg.h


# 1.81 20-Sep-2005 brad

shuffle some stuff from skreg to skvar


# 1.80 17-Sep-2005 brad

add media detection and dual port detection for Yukon-2.

from jason@


# 1.79 16-Sep-2005 brad

- remove code to read PCI VPD as we do not use that anymore.
- remove some FreeBSD-ism's: struct resource *'s.
- fail more gracefully in sk_probe() instead of in sk_attach()
for newer unsupported ASIC revisions.

From jason@


Revision tags: OPENBSD_3_8_BASE
# 1.78 29-Aug-2005 brad

- use pci_mapreg_type() to fix some systems that would fail to attach
sk(4) with "can't map mem space".
- add missing newline for failure case of pci_intr_establish().

ok deraadt@


# 1.77 25-Jul-2005 brad

don't bother with printf in *_jalloc()


# 1.76 24-Jul-2005 fgsch

simplify error paths and add some missing ones; brad@ ok.
deallocation for jumbo memory left.


# 1.75 22-Jul-2005 brad

- sync sk_alloc_jumbo_mem() to look like bge's bge_alloc_jumbo_mem()
- oops, forgot to remove a line in sk_rxeof()


# 1.74 22-Jul-2005 brad

also take the PCI subsystem id into consideration when trying to probe
for Linksys EG1032 cards, that way we do not try and attach to newer
rev 3 cards that use the RealTek 8169S chipset.


# 1.73 21-Jul-2005 brad

- add bus_dmamap_sync()'s; From NetBSD
- use pci_mapreg_map()
- remove unnecessary splimp() usage in skc_attach()
- make sure to disestablish the interrupt on failure

Tested by a few end-users.


# 1.72 14-Jul-2005 brad

add D-Link PCI id.

From: jsg@


# 1.71 12-Jul-2005 brad

remove unused prototype sk_free_jumbo_mem


# 1.70 12-Jul-2005 brad

free resources for Jumbo buffers in sk_stop().

ok deraadt, krw, beck


# 1.69 02-Jul-2005 brad

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


# 1.68 02-Jul-2005 brad

- mbuf external storage is of (caddr_t), not (caddr_t *).
- check for MTU being too small with ETHERMIN
- don't bother reseting the card since it'll default to allowing Jumbos


# 1.67 17-May-2005 jason

remove spurious bpf_mtap (I think it's leftover debugging code from a year ago)


# 1.66 16-May-2005 brad

add a newline here


# 1.65 11-May-2005 brad

remove comment which is not valid anymore


# 1.64 11-May-2005 brad

- Also match on Yukon LP's for the Lite rev A0 test.
- Do not call mii_pollstat() from within device tick routines; the status
information is updated by mii_tick().
- Take PHY out of reset for Yukon Lite rev A3. This resolves the
intermittent "no PHY found!" issue.

From FreeBSD

- Recognize some newer Yukon chipsets

ok krw@, tested by krw@ and a few others, mostly with LOM Lite A3's but
also with some other ASIC revs too.


# 1.63 25-Apr-2005 brad

csum -> csum_flags

ok krw@ canacar@


Revision tags: OPENBSD_3_7_BASE
# 1.62 18-Mar-2005 brad

fail to attach with a printf instead of a panic for newer yet unsupported
Yukon-2-based cards.

ok deraadt@


# 1.61 12-Mar-2005 brad

add a bunch of PCI ids from the SysKonnect sk98lin driver.


# 1.60 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.59 02-Jan-2005 brad

cleanup and better ram sizing.


# 1.58 01-Jan-2005 brad

better chip/card identification.

From NetBSD

ok krw@


# 1.57 01-Jan-2005 brad

rev 1.92

only clear the IFF_OACTIVE flag when we have a chance of being able to
queue a packet to the hardware... instead of when the hardware queue is
empty..

don't initalize cur_tx now that it doesn't need to be...

rev 1.90

_OACTIVE is now handled better...

From FreeBSD

ok krw@


# 1.56 01-Jan-2005 krw

Don't initialize the card (and start an autonegotiation!) every time
the IP address changes. Makes 'dhclient sk0' invocations way faster
and more consistant. i.e. one DHCPREQUEST elicts the DHCPACK.

ok brad@ 'Wow. Great Idea.' deraadt@.


# 1.55 22-Dec-2004 brad

- add missing braces for SIOCSIFMTU switch case.
- allow reception of Jumbo frames all the time on GEnesis based cards,
same as Yukon based cards.

ok krw@ mcbride@


# 1.54 14-Dec-2004 krw

Fix off-by-one. From FreeBSD r1.87. Also in NetBSD. Field being filled
(sk_vpd_readonly) is not currently used, but the memory being tromped
on might be.

ok millert@.


# 1.53 08-Dec-2004 brad

use ETHER_MAX_LEN


# 1.52 08-Dec-2004 krw

Enable jumbo frames on Yukon varients of sk(4).

ok mcbride@.


# 1.51 16-Nov-2004 brad

Lower interrupt moderation timer to decrease service latency.

From NetBSD

ok deraadt@


# 1.50 16-Nov-2004 brad

back out previous commit and put the right change in which corresponds
to what the previous commit message said...

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).


# 1.49 16-Nov-2004 brad

Fix tx queue (slist can be corrupted when tx interrupts hit within tx_encap).

From NetBSD

ok henning@ mcbride@


# 1.48 11-Nov-2004 brad

- Fix Yukon ram sizing.
- Keep tx queue running by kicking the tx bmu repeatedly.
- Handle if_timer a bit better.

From NetBSD

ok deraadt@


# 1.47 14-Oct-2004 brad

Bail out quietly if the eeprom appears to be missing or empty. Fixes
support for D-Link DGE-530T adapters.

From: FreeBSD via Blake Willis <blake at 2112 dot net>

ok mcbride@


# 1.46 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
# 1.45 20-Aug-2004 deraadt

a belkin ID on a sk card


# 1.44 19-Aug-2004 mcbride

Don't complain about lack of jumbo storage when processing incoming packets
unless we're debugging.


# 1.43 05-Aug-2004 brad

remove some separate per driver constants and use
ETHER_MAX_LEN_JUMBO/ETHERMTU_JUMBO where appropriate.

ok mcbride@ henning@ mickey@


# 1.42 04-Aug-2004 mcbride

Make jumbo frames work.
- allocate and manage our own memory for rx packets rather than using
mbuf clusters; code for this lifted from if_bge.c
- pass the correct size to bus_dmamap_create()

ok deraadt@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.41 29-May-2004 naddy

replace hand-rolled CRC calculation in multicast hash setup with calls to
ether_crc32_*(); ok mcbride@


# 1.40 24-May-2004 naddy

Make Yukon-style adapters also set up the multicast filter in sk_init().
This fixes various multicast-related problems. ok henning@


# 1.39 09-Apr-2004 henning

do not whine if we cannot get mbufs. the countless printfd makes the machine
crawl under mbuf starvation, making the situationmuch worse, and don't make
sense in the first place.
ok tdeval@ millert@ beck@ deraadt@


Revision tags: OPENBSD_3_5_BASE
# 1.38 09-Mar-2004 matthieu

Fix multicast on recent sk chipsets. Adapted from a patch by Keith Mitchell
in <http://lists.freebsd.org/pipermail/freebsd-hardware/2003-December/000851.html>
Ok deraadt@.


# 1.37 17-Dec-2003 jason

not qualifying a product based on vendor AND product ID just bugs me


# 1.36 17-Dec-2003 jason

marvell skv2 (smc9452TX); from freebsd


# 1.35 17-Dec-2003 jason

add support for linksys (eg1032v2, eg1064v2) and dlink (dge530t); from NetBSD


# 1.34 13-Oct-2003 jason

rx checksum offload support (based on earlier code from aaron@, but with
fixes by me). Note: sk v1 chips can sometimes compute an incorrect cksum.
To deal with that, we never set the "bad" flags. Ie. if the card says it's
good, we assume it's good. If the card says it's bad, we fall back to
software. Ugly? You betcha.


Revision tags: OPENBSD_3_4_BASE
# 1.33 12-Aug-2003 nate

add/update my copyright


# 1.32 01-Aug-2003 nate

Support for new Marvell based Gigabit Ethernet adapters
ok deraadt@


Revision tags: UBC_SYNC_A
# 1.31 14-May-2003 nate

Makefile sk(4) use bus_dma
ok jason


# 1.30 08-May-2003 nate

a bit more cleanup


# 1.29 08-May-2003 nate

ansify, clean up formatting, remove useless return statements.
ok jason


Revision tags: OPENBSD_3_3_BASE
# 1.28 12-Mar-2003 nate

sk is capable of transmitting and receiving longer packets for 802.1q vlans
thanks to David Gwynne <loki@niteshade.net>. ok jason@ deraadt@


# 1.27 15-Jan-2003 art

Get rid of the remaining vm_offset_t in pci drivers.


# 1.26 26-Nov-2002 nate

1000baseTX -> 1000baseT
- More technically correct
- Matches FreeBSD and NetBSD
- Preserved #define for 1000baseTX for backwards compatibility
ok jason@


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.25 08-Jun-2002 jason

add missing ioctl support for SIOCSIFMTU


# 1.24 04-Jun-2002 deraadt

spelling; raj@cerias.purdue.edu


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

First round of __P removal in sys


# 1.22 12-Mar-2002 kjc

sync with KAME
ALTQify more drivers.
ok millert@


# 1.21 15-Feb-2002 nordin

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


# 1.20 11-Jan-2002 nordin

Check result from malloc(9) when using M_NOWAIT. fgsch@ ok


Revision tags: UBC_BASE
# 1.19 06-Nov-2001 miod

branches: 1.19.2;
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.18 05-Oct-2001 nate

use positive logic for match


# 1.17 11-Sep-2001 miod

Don't include <vm/vm_kern.h> if you don't need foo_map.


# 1.16 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.15 15-Aug-2001 jason

Add some stuff missed in a previous FreeBSD merge... Fixes the problem where
sk busy loops when carrier is lost until it returns; based on patch from
david langhorst <dirt@monkey.org> and tested by John Ladwig <jladwig@mango.lioness.net>


# 1.14 12-Aug-2001 mickey

remove redundant vm includes


# 1.13 25-Jun-2001 fgsch

trivial ether_input_mbuf() conversion.


Revision tags: OPENBSD_2_9_BASE
# 1.12 29-Mar-2001 jason

From FreeBSD:
- Call mii_pollstat() after we bring up the link on a 1000baseTX card
after autoneg so we make sure to set the link state and duplex mode
correctly.
- Make sure to set the 'ignore pause frames' bit on the XMAC.
- Small linewrap fix.
- Add actual URL for XMAC II datasheet in comments.


# 1.11 25-Mar-2001 csapuntz

Missing splx(s). Thanks to Dawson and team for finding this one


# 1.10 20-Feb-2001 mickey

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


Revision tags: OPENBSD_2_8_BASE
# 1.9 16-Oct-2000 aaron

Use mii_attach() directly instead of mii_phy_probe().


# 1.8 04-Sep-2000 deraadt

printing XaQti on 5 consecutive lines is stupid


# 1.7 29-Aug-2000 jason

From FreeBSD: split out the support for XMAC-II phys and other phys
add xmphy & brgphy to GENERIC


Revision tags: OPENBSD_2_7_BASE
# 1.6 15-Feb-2000 jason

make sure to call ether_{add,del}multi() as appropriate in xxx_ioctl()


Revision tags: SMP_BASE kame_19991208
# 1.5 08-Dec-1999 aaron

branches: 1.5.2;
Remove unused #define cruft.


Revision tags: OPENBSD_2_6_BASE
# 1.4 22-Oct-1999 deraadt

fix some panic bugs; jason


# 1.3 04-Oct-1999 jason

m_new is the new mbuf, not m
fix calculation of buffer slot number


# 1.2 03-Oct-1999 jason

take advantage of m->m_ext.ext_handle for storing the softc
(instead of stashing it in the buffer)


# 1.1 01-Oct-1999 jason

driver for SysKonnect 984x gigabit ethernet adapters; from FreeBSD