History log of /netbsd-current/sys/dev/pci/if_iwm.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.89 09-Feb-2024 mlelstv

Fix DMA sync sizes.
Don't panic for inconsistent queue counter, just print an error to console.


Revision tags: thorpej-ifq-base thorpej-altq-separation-base
# 1.88 21-Sep-2023 msaitoh

s/ for for / for / in comment.


Revision tags: netbsd-10-0-RC4 netbsd-10-0-RC3 netbsd-10-0-RC2 netbsd-10-0-RC1 netbsd-10-base bouyer-sunxi-drm-base thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.87 24-Jun-2021 riastradh

iwm(4): Disentangle attach.

Don't attach a half-baked interface and then detach it and then
reattach it after mountroot when we can read firmware; just defer
attaching the interface altogether until mountroot.

Likely fixes some panics I've seen every now and then at boot with
iwm(4).


# 1.86 16-Jun-2021 riastradh

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

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

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

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

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

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

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

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

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


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.85 22-May-2020 thorpej

branches: 1.85.6;
This driver sleeps during iwm_media_change(), and thus requires an
adaptive mutex for the media lock.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.84 30-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base2 ad-namecache-base1 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.83 26-Jun-2018 msaitoh

branches: 1.83.2; 1.83.10;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625
# 1.82 08-Jun-2018 knakahara

iwm(4) workaround as ifp->if_hwdl can be set only once. Advised nonaka@n.o and ozaki-r@n.o, thanks.

To avoid for iwm(4) to set if_hwdl before loading firmware, use local address
as dummy. See sys/net/if.c::if_set_sadl().


# 1.81 08-Jun-2018 knakahara

Fix "ifconfig iwm0" failures reported by ryoon@n.o. Advised nonaka@n.o and ozaki-r@n.o, thanks.


# 1.80 06-Jun-2018 maya

Remove duplicate ;


# 1.79 05-Jun-2018 knakahara

Fix panic on boot with iwm(4). Advised by nonaka@n.o, thanks.

XXX pullup-8


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.78 21-Jan-2018 christos

branches: 1.78.2;
CID-1427736: Appease coverity using KASSERT


# 1.77 10-Jan-2018 mlelstv

Match Intel Dual Band Wireless AC 3168. The code already supports it.


Revision tags: tls-maxphys-base-20171202
# 1.76 23-Oct-2017 msaitoh

branches: 1.76.2;
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.


Revision tags: nick-nhusb-base-20170825
# 1.75 23-Jul-2017 para

branches: 1.75.2;
kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.88 21-Sep-2023 msaitoh

s/ for for / for / in comment.


Revision tags: netbsd-10-base bouyer-sunxi-drm-base thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base thorpej-i2c-spi-conf-base
# 1.87 24-Jun-2021 riastradh

iwm(4): Disentangle attach.

Don't attach a half-baked interface and then detach it and then
reattach it after mountroot when we can read firmware; just defer
attaching the interface altogether until mountroot.

Likely fixes some panics I've seen every now and then at boot with
iwm(4).


# 1.86 16-Jun-2021 riastradh

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

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

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

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

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

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

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

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

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


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.85 22-May-2020 thorpej

branches: 1.85.6;
This driver sleeps during iwm_media_change(), and thus requires an
adaptive mutex for the media lock.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.84 30-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: netbsd-9-3-RELEASE netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base2 ad-namecache-base1 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.83 26-Jun-2018 msaitoh

branches: 1.83.2; 1.83.10;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625
# 1.82 08-Jun-2018 knakahara

iwm(4) workaround as ifp->if_hwdl can be set only once. Advised nonaka@n.o and ozaki-r@n.o, thanks.

To avoid for iwm(4) to set if_hwdl before loading firmware, use local address
as dummy. See sys/net/if.c::if_set_sadl().


# 1.81 08-Jun-2018 knakahara

Fix "ifconfig iwm0" failures reported by ryoon@n.o. Advised nonaka@n.o and ozaki-r@n.o, thanks.


# 1.80 06-Jun-2018 maya

Remove duplicate ;


# 1.79 05-Jun-2018 knakahara

Fix panic on boot with iwm(4). Advised by nonaka@n.o, thanks.

XXX pullup-8


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.78 21-Jan-2018 christos

branches: 1.78.2;
CID-1427736: Appease coverity using KASSERT


# 1.77 10-Jan-2018 mlelstv

Match Intel Dual Band Wireless AC 3168. The code already supports it.


Revision tags: tls-maxphys-base-20171202
# 1.76 23-Oct-2017 msaitoh

branches: 1.76.2;
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.


Revision tags: nick-nhusb-base-20170825
# 1.75 23-Jul-2017 para

branches: 1.75.2;
kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.87 24-Jun-2021 riastradh

iwm(4): Disentangle attach.

Don't attach a half-baked interface and then detach it and then
reattach it after mountroot when we can read firmware; just defer
attaching the interface altogether until mountroot.

Likely fixes some panics I've seen every now and then at boot with
iwm(4).


Revision tags: thorpej-i2c-spi-conf-base
# 1.86 16-Jun-2021 riastradh

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

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

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

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

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

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

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

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

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


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-cfargs-base thorpej-futex-base
# 1.85 22-May-2020 thorpej

branches: 1.85.6;
This driver sleeps during iwm_media_change(), and thus requires an
adaptive mutex for the media lock.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.84 30-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base2 ad-namecache-base1 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.83 26-Jun-2018 msaitoh

branches: 1.83.2; 1.83.10;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625
# 1.82 08-Jun-2018 knakahara

iwm(4) workaround as ifp->if_hwdl can be set only once. Advised nonaka@n.o and ozaki-r@n.o, thanks.

To avoid for iwm(4) to set if_hwdl before loading firmware, use local address
as dummy. See sys/net/if.c::if_set_sadl().


# 1.81 08-Jun-2018 knakahara

Fix "ifconfig iwm0" failures reported by ryoon@n.o. Advised nonaka@n.o and ozaki-r@n.o, thanks.


# 1.80 06-Jun-2018 maya

Remove duplicate ;


# 1.79 05-Jun-2018 knakahara

Fix panic on boot with iwm(4). Advised by nonaka@n.o, thanks.

XXX pullup-8


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.78 21-Jan-2018 christos

branches: 1.78.2;
CID-1427736: Appease coverity using KASSERT


# 1.77 10-Jan-2018 mlelstv

Match Intel Dual Band Wireless AC 3168. The code already supports it.


Revision tags: tls-maxphys-base-20171202
# 1.76 23-Oct-2017 msaitoh

branches: 1.76.2;
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.


Revision tags: nick-nhusb-base-20170825
# 1.75 23-Jul-2017 para

branches: 1.75.2;
kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.86 16-Jun-2021 riastradh

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

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

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

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

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

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

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

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

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


Revision tags: cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 cjep_staticlib_x-base thorpej-i2c-spi-conf-base thorpej-cfargs-base thorpej-futex-base
# 1.85 22-May-2020 thorpej

This driver sleeps during iwm_media_change(), and thus requires an
adaptive mutex for the media lock.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.84 30-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: netbsd-9-2-RELEASE netbsd-9-1-RELEASE netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base2 ad-namecache-base1 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.83 26-Jun-2018 msaitoh

branches: 1.83.2; 1.83.10;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625
# 1.82 08-Jun-2018 knakahara

iwm(4) workaround as ifp->if_hwdl can be set only once. Advised nonaka@n.o and ozaki-r@n.o, thanks.

To avoid for iwm(4) to set if_hwdl before loading firmware, use local address
as dummy. See sys/net/if.c::if_set_sadl().


# 1.81 08-Jun-2018 knakahara

Fix "ifconfig iwm0" failures reported by ryoon@n.o. Advised nonaka@n.o and ozaki-r@n.o, thanks.


# 1.80 06-Jun-2018 maya

Remove duplicate ;


# 1.79 05-Jun-2018 knakahara

Fix panic on boot with iwm(4). Advised by nonaka@n.o, thanks.

XXX pullup-8


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.78 21-Jan-2018 christos

branches: 1.78.2;
CID-1427736: Appease coverity using KASSERT


# 1.77 10-Jan-2018 mlelstv

Match Intel Dual Band Wireless AC 3168. The code already supports it.


Revision tags: tls-maxphys-base-20171202
# 1.76 23-Oct-2017 msaitoh

branches: 1.76.2;
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.


Revision tags: nick-nhusb-base-20170825
# 1.75 23-Jul-2017 para

branches: 1.75.2;
kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.85 22-May-2020 thorpej

This driver sleeps during iwm_media_change(), and thus requires an
adaptive mutex for the media lock.


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1 phil-wifi-20200411 bouyer-xenpvh-base is-mlppp-base phil-wifi-20200406 ad-namecache-base3
# 1.84 30-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: netbsd-9-0-RELEASE netbsd-9-0-RC2 ad-namecache-base2 ad-namecache-base1 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.83 26-Jun-2018 msaitoh

branches: 1.83.2; 1.83.10;
Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625
# 1.82 08-Jun-2018 knakahara

iwm(4) workaround as ifp->if_hwdl can be set only once. Advised nonaka@n.o and ozaki-r@n.o, thanks.

To avoid for iwm(4) to set if_hwdl before loading firmware, use local address
as dummy. See sys/net/if.c::if_set_sadl().


# 1.81 08-Jun-2018 knakahara

Fix "ifconfig iwm0" failures reported by ryoon@n.o. Advised nonaka@n.o and ozaki-r@n.o, thanks.


# 1.80 06-Jun-2018 maya

Remove duplicate ;


# 1.79 05-Jun-2018 knakahara

Fix panic on boot with iwm(4). Advised by nonaka@n.o, thanks.

XXX pullup-8


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.78 21-Jan-2018 christos

branches: 1.78.2;
CID-1427736: Appease coverity using KASSERT


# 1.77 10-Jan-2018 mlelstv

Match Intel Dual Band Wireless AC 3168. The code already supports it.


Revision tags: tls-maxphys-base-20171202
# 1.76 23-Oct-2017 msaitoh

branches: 1.76.2;
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.


Revision tags: nick-nhusb-base-20170825
# 1.75 23-Jul-2017 para

branches: 1.75.2;
kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.84 30-Jan-2020 thorpej

Adopt <net/if_stats.h>.


Revision tags: ad-namecache-base2 ad-namecache-base1 ad-namecache-base netbsd-9-0-RC1 phil-wifi-20191119 netbsd-9-base phil-wifi-20190609 isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.83 26-Jun-2018 msaitoh

Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625
# 1.82 08-Jun-2018 knakahara

iwm(4) workaround as ifp->if_hwdl can be set only once. Advised nonaka@n.o and ozaki-r@n.o, thanks.

To avoid for iwm(4) to set if_hwdl before loading firmware, use local address
as dummy. See sys/net/if.c::if_set_sadl().


# 1.81 08-Jun-2018 knakahara

Fix "ifconfig iwm0" failures reported by ryoon@n.o. Advised nonaka@n.o and ozaki-r@n.o, thanks.


# 1.80 06-Jun-2018 maya

Remove duplicate ;


# 1.79 05-Jun-2018 knakahara

Fix panic on boot with iwm(4). Advised by nonaka@n.o, thanks.

XXX pullup-8


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.78 21-Jan-2018 christos

branches: 1.78.2;
CID-1427736: Appease coverity using KASSERT


# 1.77 10-Jan-2018 mlelstv

Match Intel Dual Band Wireless AC 3168. The code already supports it.


Revision tags: tls-maxphys-base-20171202
# 1.76 23-Oct-2017 msaitoh

branches: 1.76.2;
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.


Revision tags: nick-nhusb-base-20170825
# 1.75 23-Jul-2017 para

branches: 1.75.2;
kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


Revision tags: isaki-audio2-base pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226 pgoyette-compat-1126 pgoyette-compat-1020 pgoyette-compat-0930 pgoyette-compat-0906 jdolecek-ncqfixes-base pgoyette-compat-0728 phil-wifi-base
# 1.83 26-Jun-2018 msaitoh

Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.


Revision tags: pgoyette-compat-0625
# 1.82 08-Jun-2018 knakahara

iwm(4) workaround as ifp->if_hwdl can be set only once. Advised nonaka@n.o and ozaki-r@n.o, thanks.

To avoid for iwm(4) to set if_hwdl before loading firmware, use local address
as dummy. See sys/net/if.c::if_set_sadl().


# 1.81 08-Jun-2018 knakahara

Fix "ifconfig iwm0" failures reported by ryoon@n.o. Advised nonaka@n.o and ozaki-r@n.o, thanks.


# 1.80 06-Jun-2018 maya

Remove duplicate ;


# 1.79 05-Jun-2018 knakahara

Fix panic on boot with iwm(4). Advised by nonaka@n.o, thanks.

XXX pullup-8


Revision tags: pgoyette-compat-0521 pgoyette-compat-0502 pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 pgoyette-compat-base
# 1.78 21-Jan-2018 christos

branches: 1.78.2;
CID-1427736: Appease coverity using KASSERT


# 1.77 10-Jan-2018 mlelstv

Match Intel Dual Band Wireless AC 3168. The code already supports it.


Revision tags: tls-maxphys-base-20171202
# 1.76 23-Oct-2017 msaitoh

branches: 1.76.2;
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.


Revision tags: nick-nhusb-base-20170825
# 1.75 23-Jul-2017 para

branches: 1.75.2;
kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.78 21-Jan-2018 christos

CID-1427736: Appease coverity using KASSERT


# 1.77 10-Jan-2018 mlelstv

Match Intel Dual Band Wireless AC 3168. The code already supports it.


Revision tags: tls-maxphys-base-20171202
# 1.76 23-Oct-2017 msaitoh

branches: 1.76.2;
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.


Revision tags: nick-nhusb-base-20170825
# 1.75 23-Jul-2017 para

branches: 1.75.2;
kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.77 10-Jan-2018 mlelstv

Match Intel Dual Band Wireless AC 3168. The code already supports it.


Revision tags: tls-maxphys-base-20171202
# 1.76 23-Oct-2017 msaitoh

branches: 1.76.2;
- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.


Revision tags: nick-nhusb-base-20170825
# 1.75 23-Jul-2017 para

branches: 1.75.2;
kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.76 23-Oct-2017 msaitoh

- If if_initialize() failed in the attach function, free resources and return.
- Fix error path in the attach function correctly.


Revision tags: nick-nhusb-base-20170825
# 1.75 23-Jul-2017 para

branches: 1.75.2;
kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.75 23-Jul-2017 para

kmem_intr_free kmem_intr_[z]alloced memory

the underlying pools are the same but api-wise those should match


Revision tags: perseant-stdc-iso10646-base
# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

branches: 1.73.2;
remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.74 09-Jun-2017 nonaka

fix typo.

reported by ryo@.


Revision tags: netbsd-8-base
# 1.73 01-Jun-2017 chs

remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.73 01-Jun-2017 chs

remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.72 19-May-2017 nonaka

iwm(4): match Wireless 8265 device.


Revision tags: prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320
# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

branches: 1.61.2;
iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.71 14-Mar-2017 nonaka

iwm(4): update firmware to maintained core release.

firmware from https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=4b9559fb0565f582a21a4070a81a3b6a7d77610b


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


Revision tags: nick-nhusb-base-20170204
# 1.70 02-Feb-2017 nonaka

wlan interfaces make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html

tested device:
* ath at pci: AR5212, AR5424
* athn at pci: AR9287
* ipw at pci: 2100BG
* iwi at pci: 2915ABG
* iwm at pci: 3165, 7260, 8260
* iwn at pci: 4945, 6235
* ral at pci: RT2560
* rtwn at pci: RTL8192CE


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.69 21-Jan-2017 nonaka

PR/51797: initialize hardware completely when receiving a deauth frame from AP.

avoid "iwm0: fatal firmware error".


# 1.68 21-Jan-2017 nonaka

more block network interrupt.


# 1.67 21-Jan-2017 nonaka

increase command response timeout value.


# 1.66 21-Jan-2017 nonaka

include <sys/intr.h> for softint(9).


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.65 19-Jan-2017 nonaka

newstate should be blocked network interrupt, because it called iwm_start.


# 1.64 17-Jan-2017 nonaka

show NVM channel flags when AB_DEBUG is set.


# 1.63 17-Jan-2017 nonaka

more acknowledge interrupts from iwn(4).


# 1.62 17-Jan-2017 nonaka

only bus_dmamap_sync(9) once for ICT region.


Revision tags: bouyer-socketcan-base
# 1.61 13-Jan-2017 nonaka

iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.61 13-Jan-2017 nonaka

iwm(4): 3165 works fine with iwlwifi-7265D-17.ucode firmware.

firmware from http://git.kernel.org/cgit/linux/kernel/git/iwlwifi/linux-firmware.git/tree/?id=be8a6fcba2e48e00674d1f35e6def56e2268039c


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.60 10-Jan-2017 nonaka

check LAR support in NVM for 8260/4165.


# 1.59 10-Jan-2017 nonaka

Add apmg_wake_up_wa support from DragonFly BSD.


# 1.58 10-Jan-2017 nonaka

iwm(4): 8260 works now. 4165 may works too.


# 1.57 10-Jan-2017 nonaka

set NULL after free.


# 1.56 09-Jan-2017 nonaka

Apply OpenBSD if_iwm.c rev.1.148.

> While setting up the basic rate bitmask for iwm's firmware, if the AP does
> not specify basic rates for either the CCK or OFDM set, add just the most
> basic rate to that set (1 Mbit/s in case of CCK, 6 Mbit/s in case of OFDM).
> This behaviour matches what code comments seem to imply.

> The previous code would add all possible basic rates in such cases.
> So if all basic rates were CCK only, the code would add all possible OFDM basic
> rates on top. Then the firmware would send some frames at too high rates, e.g.
> RTS frames would be sent at 24Mbit/s which is a bit risky on noisy channels.


# 1.55 09-Jan-2017 khorben

Do not use the "flags" field uninitialized

A backport if iwm(4) (to netbsd-7) does not build without this change.

LGTM nonaka@


# 1.54 09-Jan-2017 nonaka

Added enum iwm_tx_pm_timeouts from FreeBSD.


# 1.53 09-Jan-2017 nonaka

cosmetic.


# 1.52 09-Jan-2017 nonaka

use correct header size.


# 1.51 08-Jan-2017 nonaka

fix indent


# 1.50 08-Jan-2017 nonaka

iwm(4): make interrupt routine running on softint context.

see http://mail-index.netbsd.org/tech-kern/2016/12/06/msg021281.html


# 1.49 08-Jan-2017 nonaka

use pci_intr_establish_xname(9).


# 1.48 08-Jan-2017 nonaka

twiddle bpf related.


# 1.47 08-Jan-2017 nonaka

cosmetic


Revision tags: pgoyette-localcount-20170107
# 1.46 04-Jan-2017 nonaka

Export some 802.11 IE manipulate functions.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.


# 1.45 18-Dec-2016 nonaka

iwm(4): Sync with OpenBSD.

7265 works fine.
7260 and 3160 maybe work.
7265D, 3165 and 8260 not work yet.

if_iwm.c: r1.147.
if_iwmreg.h: r1.19 without r1.16.
if_iwmvar.h: r1.24.

firmware is taken from https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi
- iwlwifi-7260-ucode-16.242414.0.tgz
- iwlwifi-3160-ucode-16.242414.0.tgz
- iwlwifi-7265-ucode-16.242414.0.tgz
- iwlwifi-8000-ucode-16.242414.0.tgz


# 1.44 08-Dec-2016 ozaki-r

Apply deferred if_start framework

if_schedule_deferred_start checks if the if_snd queue contains packets,
so drivers don't need to check it by themselves.


Revision tags: nick-nhusb-base-20161204 pgoyette-localcount-20161104 nick-nhusb-base-20161004
# 1.43 23-Sep-2016 maya

Fix inverted logic in iwm(4).

The PROT_REQUIRE flag in should be set for data frames above a certain
length, but we were setting it for !data frames above a certain length,
which makes no sense at all.

- taken from all other BSDs (OpenBSD, FreeBSD, DragonflyBSD...)


Revision tags: localcount-20160914 pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907
# 1.42 10-Jun-2016 ozaki-r

branches: 1.42.2;
Introduce m_set_rcvif and m_reset_rcvif

The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.


Revision tags: nick-nhusb-base-20160529
# 1.41 26-May-2016 ozaki-r

Use M_GETCTX

No functional change.


Revision tags: nick-nhusb-base-20160422 nick-nhusb-base-20160319
# 1.40 09-Feb-2016 ozaki-r

Introduce softint-based if_input

This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!


Revision tags: nick-nhusb-base-20151226
# 1.39 06-Nov-2015 nonaka

Always use pci_intr_alloc(9)/pci_intr_release(9).


# 1.38 14-Oct-2015 ozaki-r

Remove leading whitespaces and kind


Revision tags: nick-nhusb-base-20150921
# 1.37 24-Jul-2015 nonaka

Use pci_intr_alloc().


# 1.36 22-Jul-2015 nonaka

iwm(4) can read the firmware image from disk when interface up.
This change is useful for full-disk encryption environment.


Revision tags: nick-nhusb-base-20150606
# 1.35 22-May-2015 nonaka

Limit the number of dma segments used for transmitting packets to
IWM_NUM_OF_TBS - 2. We have IWM_NUM_OF_TBS slots, but use two of those
for sending commands to the firmware.

From OpenBSD rev. 1.41.


# 1.34 16-May-2015 nonaka

should be able to use 5GHz wireless network.


# 1.33 15-May-2015 knakahara

if_iwm use unified establish API.


# 1.32 29-Apr-2015 nonaka

Added control debugging output via sysctl.


# 1.31 28-Apr-2015 nonaka

Use MSI instead of legacy INTx, if available.

should fix PR/49663.


# 1.30 15-Apr-2015 nonaka

Register iwm(4) with pmf(9).

Patch from Pierre Pronchery.


Revision tags: nick-nhusb-base-20150406
# 1.29 26-Mar-2015 nonaka

branches: 1.29.2;
Not all iwm hardware supports the 5GHz band. Make setting 11a rates
and scanning conditional on the 5GHz support bit in the nvm.

From OpenBSD rev. 1.39. Arranged by me.


# 1.28 07-Mar-2015 nonaka

Fix radiotap and fixed rates. Radiotap was reporting the wrong rate for
data frames and fixed rates weren't really fixed and were converted into
the wrong hardware rate.

From OpenBSD rev.1.36.


# 1.27 07-Mar-2015 khorben

Avoid kmem_free(NULL) in iwm_read_firmware()

This code path can be hit if the firmware failed to load, for instance
if the file is not present on the filesystem. In this case
firmware_open() fails, and fw->fw_rawdata never gets allocated in the
first place.


# 1.26 04-Mar-2015 nonaka

stop the calibration timeout when stopping the interface.

From OpenBSD rev.1.35.


# 1.25 04-Mar-2015 nonaka

Set/clear the IWM_MAC_FILTER_IN_BEACON flag under conditions that match what
Linux does.

From OpenBSD rev.1.34.


# 1.24 03-Mar-2015 nonaka

Fix 11a support.

From OpenBSD rev.1.33.


# 1.23 03-Mar-2015 nonaka

Make setting the MAC context bit for 11g protection when transmitting
OFDM frames conditional on the node via IEEE80211_F_USEPROT.

From OpenBSD rev.1.31.


# 1.22 03-Mar-2015 nonaka

Don't set CTS to self. Linux stopped setting this back in
dc271ee0d04d12d6bfabacbec803289a7072fbd9 as it is known
to cause problems.

From OpenBSD rev.1.30.


# 1.21 03-Mar-2015 nonaka

sc_fixed_ridx is initialised to 0 but tested as it it were initialised
to -1. The result of this is tx frames were always sent out at fixed
rate 0 instead of ni_txrate.

Match the iwn behaviour and test ic_fixed_rate for -1 instead.

From OpenBSD rev.1.29.


# 1.20 03-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.28.


# 1.19 03-Mar-2015 nonaka

init error to 0 in iwm_send_cmd().
From OpenBSD rev.1.27.


# 1.18 03-Mar-2015 nonaka

match iwn and init txrate at lowest available bit-rate.
From OpenBSD rev.1.26.


# 1.17 03-Mar-2015 nonaka

workaround for interrupt coalescing bug not needed on 7265.
From OpenBSD if_iwm.c rev.1.25, if_iwmvar.h rev.1.7.


# 1.16 02-Mar-2015 nonaka

Correctly set lowest_present_ofdm in iwm_mvm_ack_rates().
From OpenBSD rev.1.23.


# 1.15 25-Feb-2015 nonaka

Display code number of unhandled packet.


# 1.14 24-Feb-2015 christos

Work around Coverity CIDs 127102{0,1}: Confused by the comparison
nrates > __arraycount(lq->rs_table), coverity erroneously binds nrates
to the range [0..16), whereas it is really bound to [0..15) by
ni->ni_rates.rs_nrates (IEEE80211_RATE_MAXSIZE). We add an explicit comparison
to unconfuse it that will always succeed.


# 1.13 24-Feb-2015 nonaka

Revert previous change.


# 1.12 23-Feb-2015 nonaka

CID 1271021: Overrunning array "in->in_ridx" of 15 bytes at byte offset 15 using index "i" (which evaluates to 15).

http://mail-index.netbsd.org/coverity-updates/2015/02/21/msg000115.html


# 1.11 20-Feb-2015 nonaka

Make the iwm(4) hardware receive filter pass multicast traffic from OpenBSD.
Fixes inet6 autoconf, for example.


# 1.10 20-Feb-2015 nonaka

Don't return success when hw is not ready.


# 1.9 17-Feb-2015 nonaka

fix compile failure with IWM_DEBUG on i386.


# 1.8 16-Feb-2015 nonaka

whitespace


# 1.7 16-Feb-2015 nonaka

Fix compile failure with clang.
Pointed out by Herbert J. Skuhra.


# 1.6 14-Feb-2015 nonaka

print error message when fail to load firmware.


# 1.5 13-Feb-2015 nonaka

iwm(4) works now, but 2.4GHz only.

> iwm0 at pci2 dev 0 function 0: Intel Dual Band Wireless AC 3160 (rev. 0x83)
> iwm0: interrupting at ioapic0 pin 18
> iwm0: hw rev: 0x160, fw ver 25.228 (API ver 9), address XX:XX:XX:XX:XX:XX
> iwm0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
> iwm0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps


# 1.4 13-Feb-2015 nonaka

Make some functions and variables static.


# 1.3 13-Feb-2015 nonaka

Convert printf() to aprint_*().


# 1.2 13-Feb-2015 nonaka

Sync with OpenBSD if_iwm.c rev.1.18.


# 1.1 07-Feb-2015 pooka

Add a driver for Intel Centrino 7260 and similar wireless cards.
Supported devices should more or less match ones supported
by the Linux iwlwifi mvm driver. Sponsored by genua mbh for OpenBSD.

This is probably the world's first Canadian cross device driver: it was
created for OpenBSD by writing and porting a NetBSD driver which was
developed in a rump kernel in Linux userspace.

Note: I don't have access to the hardware anymore, so this version is
not tested and not enabled by default. While I tried to be careful in
adding the NetBSD bits back, it's probable that there's a snafu or two.
Feel free to send private email in case you have the hardware and there
are issues.