Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src-draft/trunk]: src/sys/dev/pci First attempt converting iwi(4) to the new...
details: https://anonhg.NetBSD.org/src-all/rev/d5e38066d166
branches: trunk
changeset: 364302:d5e38066d166
user: Nathanial Sloss <nat%netbsd.org@localhost>
date: Sun Dec 19 08:23:10 2021 +1100
description:
First attempt converting iwi(4) to the new stack.
I does not compile yet.
diffstat:
sys/dev/pci/if_iwi.c | 366 +++++++++++++++++++++++++++++++-------------------
1 files changed, 226 insertions(+), 140 deletions(-)
diffs (truncated from 791 to 300 lines):
diff -r f20d2deb6bec -r d5e38066d166 sys/dev/pci/if_iwi.c
--- a/sys/dev/pci/if_iwi.c Tue Dec 07 18:27:23 2021 +0100
+++ b/sys/dev/pci/if_iwi.c Sun Dec 19 08:23:10 2021 +1100
@@ -109,9 +109,16 @@
static int iwi_media_change(struct ifnet *);
static void iwi_media_status(struct ifnet *, struct ifmediareq *);
static int iwi_wme_update(struct ieee80211com *);
+static void iwi_scan_start(struct ieee80211com *);
+static void iwi_set_chan(struct ieee80211com *);
+static void iwi_parent(struct ieee80211com *);
+static void iwi_newassoc(struct ieee80211_node *, int);
+static int iwi_transmit(struct ieee80211com *, struct mbuf *);
+static int iwi_raw_xmit(struct ieee80211_node *, struct mbuf *,
+ const struct ieee80211_bpf_params *);
static uint16_t iwi_read_prom_word(struct iwi_softc *, uint8_t);
-static int iwi_newstate(struct ieee80211com *, enum ieee80211_state, int);
-static void iwi_fix_channel(struct ieee80211com *, struct mbuf *);
+static int iwi_newstate(struct ieee80211vap *, enum ieee80211_state, int);
+//static void iwi_fix_channel(struct ieee80211com *, struct mbuf *);
static void iwi_frame_intr(struct iwi_softc *, struct iwi_rx_data *, int,
struct iwi_frame *);
static void iwi_notification_intr(struct iwi_softc *, struct iwi_notif *);
@@ -132,7 +139,7 @@
static int iwi_get_table0(struct iwi_softc *, uint32_t *);
-static int iwi_ioctl(struct ifnet *, u_long, void *);
+//static int iwi_ioctl(struct ifnet *, u_long, void *);
static void iwi_stop_master(struct iwi_softc *);
static int iwi_reset(struct iwi_softc *);
static int iwi_load_ucode(struct iwi_softc *, void *, int);
@@ -140,15 +147,29 @@
static int iwi_cache_firmware(struct iwi_softc *);
static void iwi_free_firmware(struct iwi_softc *);
static int iwi_config(struct iwi_softc *);
-static int iwi_set_chan(struct iwi_softc *, struct ieee80211_channel *);
-static int iwi_scan(struct iwi_softc *);
static int iwi_auth_and_assoc(struct iwi_softc *);
-static int iwi_init(struct ifnet *);
-static void iwi_stop(struct ifnet *, int);
+static int iwi_init(struct iwi_softc *);
+static void iwi_stop(struct iwi_softc *, int);
static int iwi_getrfkill(struct iwi_softc *);
static void iwi_led_set(struct iwi_softc *, uint32_t, int);
static void iwi_sysctlattach(struct iwi_softc *);
+static struct ieee80211vap *
+iwi_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ],
+ int unit, enum ieee80211_opmode opmode, int flags,
+ const uint8_t bssid[IEEE80211_ADDR_LEN],
+ const uint8_t macaddr[IEEE80211_ADDR_LEN]);
+static void
+iwi_vap_delete(struct ieee80211vap *vap);
+static void
+iwi_get_radiocaps(struct ieee80211com *ic,
+ int maxchans, int *nchans, struct ieee80211_channel chans[]);
+
+struct iwi_vap {
+ struct ieee80211vap vap;
+ int (*newstate)(struct ieee80211vap *, enum ieee80211_state, int);
+};
+
static inline uint8_t
MEM_READ_1(struct iwi_softc *sc, uint32_t addr)
{
@@ -287,16 +308,20 @@
return;
}
- ic->ic_ifp = ifp;
- ic->ic_wme.wme_update = iwi_wme_update;
+ ic->ic_name = device_xname(self);
+ ic->ic_txstream = 1;
+ ic->ic_rxstream = 1;
+ ic->ic_flags = IFF_BROADCAST | IFF_SIMPLEX;
+ ic->ic_softc = sc;
ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
ic->ic_opmode = IEEE80211_M_STA; /* default to BSS mode */
- ic->ic_state = IEEE80211_S_INIT;
+ //ic->ic_state = IEEE80211_S_INIT;
sc->sc_fwname = "ipw2200-bss.fw";
/* set device capabilities */
ic->ic_caps =
+ IEEE80211_C_STA | /* Station (AP) mode supported */
IEEE80211_C_IBSS | /* IBSS mode supported */
IEEE80211_C_MONITOR | /* monitor mode supported */
IEEE80211_C_TXPMGT | /* tx power management */
@@ -305,19 +330,35 @@
IEEE80211_C_WPA | /* 802.11i */
IEEE80211_C_WME; /* 802.11e */
+ iwi_get_radiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans,
+ ic->ic_channels);
+ ieee80211_ifattach(ic);
+
+ ic->ic_vap_create = iwi_vap_create;
+ ic->ic_vap_delete = iwi_vap_delete;
+ ic->ic_set_channel = iwi_set_chan;
+ ic->ic_getradiocaps = iwi_get_radiocaps;
+ ic->ic_parent = iwi_parent;
+ ic->ic_scan_start = iwi_scan_start;
+ ic->ic_transmit = iwi_transmit;
+ ic->ic_raw_xmit = iwi_raw_xmit;
+ //ic->ic_update_mcast = iwi_update_mcast;
+ ic->ic_newassoc = iwi_newassoc;
+ ic->ic_wme.wme_update = iwi_wme_update;
+
/* read MAC address from EEPROM */
val = iwi_read_prom_word(sc, IWI_EEPROM_MAC + 0);
- ic->ic_myaddr[0] = val & 0xff;
- ic->ic_myaddr[1] = val >> 8;
+ ic->ic_macaddr[0] = val & 0xff;
+ ic->ic_macaddr[1] = val >> 8;
val = iwi_read_prom_word(sc, IWI_EEPROM_MAC + 1);
- ic->ic_myaddr[2] = val & 0xff;
- ic->ic_myaddr[3] = val >> 8;
+ ic->ic_macaddr[2] = val & 0xff;
+ ic->ic_macaddr[3] = val >> 8;
val = iwi_read_prom_word(sc, IWI_EEPROM_MAC + 2);
- ic->ic_myaddr[4] = val & 0xff;
- ic->ic_myaddr[5] = val >> 8;
+ ic->ic_macaddr[4] = val & 0xff;
+ ic->ic_macaddr[5] = val >> 8;
aprint_verbose_dev(self, "802.11 address %s\n",
- ether_sprintf(ic->ic_myaddr));
+ ether_sprintf(ic->ic_macaddr));
/* read the NIC type from EEPROM */
val = iwi_read_prom_word(sc, IWI_EEPROM_NIC_TYPE);
@@ -325,42 +366,8 @@
DPRINTF(("%s: NIC type %d\n", device_xname(self), sc->nictype));
- if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PRO_WL_2915ABG_1 ||
- PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PRO_WL_2915ABG_2) {
- /* set supported .11a rates (2915ABG only) */
- ic->ic_sup_rates[IEEE80211_MODE_11A] = ieee80211_std_rateset_11a;
-
- /* set supported .11a channels */
- for (i = 36; i <= 64; i += 4) {
- ic->ic_channels[i].ic_freq =
- ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ);
- ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A;
- }
- for (i = 149; i <= 165; i += 4) {
- ic->ic_channels[i].ic_freq =
- ieee80211_ieee2mhz(i, IEEE80211_CHAN_5GHZ);
- ic->ic_channels[i].ic_flags = IEEE80211_CHAN_A;
- }
- }
-
- /* set supported .11b and .11g rates */
- ic->ic_sup_rates[IEEE80211_MODE_11B] = ieee80211_std_rateset_11b;
- ic->ic_sup_rates[IEEE80211_MODE_11G] = ieee80211_std_rateset_11g;
-
- /* set supported .11b and .11g channels (1 through 14) */
- for (i = 1; i <= 14; i++) {
- ic->ic_channels[i].ic_freq =
- ieee80211_ieee2mhz(i, IEEE80211_CHAN_2GHZ);
- ic->ic_channels[i].ic_flags =
- IEEE80211_CHAN_CCK | IEEE80211_CHAN_OFDM |
- IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
- }
-
ifp->if_softc = sc;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
- ifp->if_init = iwi_init;
- ifp->if_stop = iwi_stop;
- ifp->if_ioctl = iwi_ioctl;
ifp->if_start = iwi_start;
ifp->if_watchdog = iwi_watchdog;
IFQ_SET_READY(&ifp->if_snd);
@@ -376,9 +383,6 @@
ic->ic_node_alloc = iwi_node_alloc;
sc->sc_node_free = ic->ic_node_free;
ic->ic_node_free = iwi_node_free;
- /* override state transition machine */
- sc->sc_newstate = ic->ic_newstate;
- ic->ic_newstate = iwi_newstate;
/* XXX media locking needs revisiting */
mutex_init(&sc->sc_media_mtx, MUTEX_DEFAULT, IPL_SOFTNET);
@@ -437,6 +441,9 @@
sc->sc_txtap.wt_ihdr.it_len = htole16(sc->sc_txtap_len);
sc->sc_txtap.wt_ihdr.it_present = htole32(IWI_TX_RADIOTAP_PRESENT);
+ ic->ic_rh = (struct ieee80211_radiotap_header *)&sc->sc_rxtapu;
+ ic->ic_th = (struct ieee80211_radiotap_header *)&sc->sc_txtapu;
+
iwi_sysctlattach(sc);
if (pmf_device_register(self, NULL, NULL))
@@ -459,7 +466,7 @@
if (ifp->if_softc != NULL) {
pmf_device_deregister(self);
- iwi_stop(ifp, 1);
+ iwi_stop(sc, 1);
iwi_free_firmware(sc);
ieee80211_ifdetach(&sc->sc_ic);
if_detach(ifp);
@@ -487,6 +494,67 @@
return 0;
}
+static struct ieee80211vap *
+iwi_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ],
+ int unit, enum ieee80211_opmode opmode, int flags,
+ const uint8_t bssid[IEEE80211_ADDR_LEN],
+ const uint8_t macaddr[IEEE80211_ADDR_LEN])
+{
+ struct iwi_vap *vap;
+
+ /* Allocate the vap and setup. */
+ vap = kmem_zalloc(sizeof(*vap), KM_SLEEP);
+ if (ieee80211_vap_setup(ic, &vap->vap, name, unit, opmode,
+ flags | IEEE80211_CLONE_NOBEACONS, bssid) != 0) {
+ kmem_free(vap, sizeof(*vap));
+ return NULL;
+ }
+
+ /* Local overrides... */
+ vap->newstate = vap->vap.iv_newstate;
+ vap->vap.iv_newstate = iwi_newstate;
+
+ /* Use common softint-based if_input */
+ vap->vap.iv_ifp->if_percpuq = if_percpuq_create(vap->vap.iv_ifp);
+
+ /* Finish setup */
+ ieee80211_vap_attach(&vap->vap, ieee80211_media_change,
+ ieee80211_media_status, macaddr);
+
+ ic->ic_opmode = opmode;
+
+ return &vap->vap;
+}
+
+static void
+iwi_vap_delete(struct ieee80211vap *arg)
+{
+ struct ifnet *ifp = arg->iv_ifp;
+ struct iwi_vap *vap = (struct iwi_vap *)arg;
+
+ bpf_detach(ifp);
+ ieee80211_vap_detach(arg);
+ kmem_free(vap, sizeof(*vap));
+}
+
+static void
+iwi_get_radiocaps(struct ieee80211com *ic,
+ int maxchans, int *nchans, struct ieee80211_channel chans[])
+{
+ uint8_t bands[IEEE80211_MODE_BYTES];
+
+ memset(bands, 0, sizeof(bands));
+ setbit(bands, IEEE80211_MODE_11B);
+ setbit(bands, IEEE80211_MODE_11G);
+/* XXX 11A should be set for these boards only
+ if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PRO_WL_2915ABG_1 ||
+ PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PRO_WL_2915ABG_2) {
+*/
+
+
+ ieee80211_add_channels_default_2ghz(chans, maxchans, nchans, bands, 0);
+}
+
static int
iwi_alloc_cmd_ring(struct iwi_softc *sc, struct iwi_cmd_ring *ring,
int count)
@@ -829,7 +897,7 @@
iwi_node_free(struct ieee80211_node *ni)
{
struct ieee80211com *ic = ni->ni_ic;
- struct iwi_softc *sc = ic->ic_ifp->if_softc;
+ struct iwi_softc *sc = ic->ic_softc;
struct iwi_node *in = (struct iwi_node *)ni;
if (in->in_station != -1)
@@ -847,9 +915,6 @@
if (error != ENETRESET)
return error;
- if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) == (IFF_UP | IFF_RUNNING))
- iwi_init(ifp);
-
return 0;
}
@@ -883,13 +948,14 @@
static void
iwi_media_status(struct ifnet *ifp, struct ifmediareq *imr)
{
- struct iwi_softc *sc = ifp->if_softc;
- struct ieee80211com *ic = &sc->sc_ic;
+ struct ieee80211vap *vap = ifp->if_softc;
+ struct ieee80211com *ic = vap->iv_ic;
+ struct iwi_softc *sc = ic->ic_softc;
Home |
Main Index |
Thread Index |
Old Index