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 Inital support for iwn for new wifi stack.



details:   https://anonhg.NetBSD.org/src-all/rev/5b320136cdfe
branches:  trunk
changeset: 933061:5b320136cdfe
user:      Nathanial Sloss <nat%netbsd.org@localhost>
date:      Fri May 01 01:09:09 2020 +1000

description:
Inital support for iwn for new wifi stack.
Doesn't work just yet, but it compiles.

diffstat:

 sys/dev/pci/if_iwn.c |  545 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 360 insertions(+), 185 deletions(-)

diffs (truncated from 1259 to 300 lines):

diff -r 5a6fb8bd6bff -r 5b320136cdfe sys/dev/pci/if_iwn.c
--- a/sys/dev/pci/if_iwn.c      Fri May 01 00:16:58 2020 +1000
+++ b/sys/dev/pci/if_iwn.c      Fri May 01 01:09:09 2020 +1000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_iwn.c,v 1.94 2020/03/20 16:35:41 sevan Exp $        */
+/*     $NetBSD: if_iwn.c,v 1.90.2.3 2020/04/13 08:04:26 martin Exp $   */
 /*     $OpenBSD: if_iwn.c,v 1.135 2014/09/10 07:22:09 dcoppa Exp $     */
 
 /*-
@@ -22,7 +22,7 @@
  * adapters.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_iwn.c,v 1.94 2020/03/20 16:35:41 sevan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_iwn.c,v 1.90.2.3 2020/04/13 08:04:26 martin Exp $");
 
 #define IWN_USE_RBUF   /* Use local storage for RX */
 #undef IWN_HWCRYPTO    /* XXX does not even compile yet */
@@ -32,7 +32,9 @@
 #include <sys/proc.h>
 #include <sys/mbuf.h>
 #include <sys/kernel.h>
+#include <sys/kmem.h>
 #include <sys/socket.h>
+#include <sys/sysctl.h>
 #include <sys/systm.h>
 #include <sys/malloc.h>
 #ifdef notyetMODULE
@@ -66,6 +68,7 @@
 #include <net/if_ether.h>
 #include <netinet/ip.h>
 
+#include <net80211/ieee80211_netbsd.h>
 #include <net80211/ieee80211_var.h>
 #include <net80211/ieee80211_amrr.h>
 #include <net80211/ieee80211_radiotap.h>
@@ -122,7 +125,7 @@
 static void    iwn_attach(device_t , device_t , void *);
 static int     iwn4965_attach(struct iwn_softc *, pci_product_id_t);
 static int     iwn5000_attach(struct iwn_softc *, pci_product_id_t);
-static void    iwn_radiotap_attach(struct iwn_softc *);
+//static void  iwn_radiotap_attach(struct iwn_softc *);
 static int     iwn_detach(device_t , int);
 #if 0
 static void    iwn_power(int, void *);
@@ -153,6 +156,17 @@
 static void    iwn5000_ict_reset(struct iwn_softc *);
 static int     iwn_read_eeprom(struct iwn_softc *);
 static void    iwn4965_read_eeprom(struct iwn_softc *);
+static void    iwn_getradiocaps(struct ieee80211com *, int, int *,
+                   struct ieee80211_channel []);
+static struct ieee80211vap *
+               iwn_vap_create(struct ieee80211com *,
+                   const char [IFNAMSIZ], int, enum ieee80211_opmode, int,
+                   const uint8_t [IEEE80211_ADDR_LEN],
+                   const uint8_t [IEEE80211_ADDR_LEN]);
+static void    iwn_vap_delete(struct ieee80211vap *);
+static void    iwn_parent(struct ieee80211com *);
+static void    iwn_scan_end(struct ieee80211com *);
+static int     iwn_reset(struct ieee80211vap *, u_long);
 
 #ifdef IWN_DEBUG
 static void    iwn4965_print_power_group(struct iwn_softc *, int);
@@ -160,10 +174,9 @@
 static void    iwn5000_read_eeprom(struct iwn_softc *);
 static void    iwn_read_eeprom_channels(struct iwn_softc *, int, uint32_t);
 static void    iwn_read_eeprom_enhinfo(struct iwn_softc *);
-static struct  ieee80211_node *iwn_node_alloc(struct ieee80211_node_table *);
 static void    iwn_newassoc(struct ieee80211_node *, int);
 static int     iwn_media_change(struct ifnet *);
-static int     iwn_newstate(struct ieee80211com *, enum ieee80211_state, int);
+static int     iwn_newstate(struct ieee80211vap *, enum ieee80211_state, int);
 static void    iwn_iter_func(void *, struct ieee80211_node *);
 static void    iwn_calib_timeout(void *);
 static void    iwn_rx_phy(struct iwn_softc *, struct iwn_rx_desc *,
@@ -239,12 +252,12 @@
 static int     iwn_config_bt_coex_adv1(struct iwn_softc *);
 static int     iwn_config_bt_coex_adv2(struct iwn_softc *);
 
-static int     iwn_config(struct iwn_softc *);
-static uint16_t        iwn_get_active_dwell_time(struct iwn_softc *, uint16_t,
+static int     iwn_config(struct ieee80211vap *);
+static uint16_t        iwn_get_active_dwell_time(struct ieee80211vap *, uint16_t,
                    uint8_t);
-static uint16_t        iwn_limit_dwell(struct iwn_softc *, uint16_t);
-static uint16_t        iwn_get_passive_dwell_time(struct iwn_softc *, uint16_t);
-static int     iwn_scan(struct iwn_softc *, uint16_t);
+static uint16_t        iwn_limit_dwell(struct ieee80211vap *, uint16_t);
+static uint16_t        iwn_get_passive_dwell_time(struct ieee80211vap *, uint16_t);
+static void    iwn_scan(struct ieee80211com *);
 static int     iwn_auth(struct iwn_softc *);
 static int     iwn_run(struct iwn_softc *);
 #ifdef IWN_HWCRYPTO
@@ -324,6 +337,8 @@
 #define DPRINTFN(n, x)
 #endif
 
+static const uint8_t iwn_chan_2ghz[] =
+        { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
 CFATTACH_DECL_NEW(iwn, sizeof(struct iwn_softc), iwn_match, iwn_attach,
        iwn_detach, NULL);
 
@@ -344,11 +359,29 @@
 }
 
 static void
+iwn_getradiocaps(struct ieee80211com *ic,
+    int maxchans, int *nchans, struct ieee80211_channel chans[])
+{
+        uint8_t bands[IEEE80211_MODE_BYTES];
+
+        /*
+         * NNN Should be able to do something based on chip if
+         * a chip has more bands .... eg. N ... but for the future.
+         */
+
+        memset(bands, 0, sizeof(bands));
+        setbit(bands, IEEE80211_MODE_11B);
+        setbit(bands, IEEE80211_MODE_11G);
+        setbit(bands, IEEE80211_MODE_11NG);
+        ieee80211_add_channel_list_2ghz(chans, maxchans, nchans,
+            iwn_chan_2ghz, nitems(iwn_chan_2ghz), bands, IEEE80211_CHAN_HT20);
+}
+
+static void
 iwn_attach(device_t parent __unused, device_t self, void *aux)
 {
        struct iwn_softc *sc = device_private(self);
        struct ieee80211com *ic = &sc->sc_ic;
-       struct ifnet *ifp = &sc->sc_ec.ec_if;
        struct pci_attach_args *pa = aux;
        const char *intrstr;
        pcireg_t memtype, reg;
@@ -516,12 +549,11 @@
            ((sc->rxchainmask >> 0) & 1);
        aprint_normal_dev(self, "MIMO %dT%dR, %.4s, address %s\n",
            sc->ntxchains, sc->nrxchains, sc->eeprom_domain,
-           ether_sprintf(ic->ic_myaddr));
-
-       ic->ic_ifp = ifp;
+           ether_sprintf(ic->ic_macaddr));
+
+       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;
 
        /*
         * Set device capabilities.
@@ -544,24 +576,26 @@
 #if IWN_RBUF_SIZE == 8192
                    IEEE80211_HTCAP_AMSDU7935 |
 #endif
-                   IEEE80211_HTCAP_CBW20_40 |
-                   IEEE80211_HTCAP_SGI20 |
-                   IEEE80211_HTCAP_SGI40;
+                   IEEE80211_HTCAP_SHORTGI20 |         /* short GI in 20MHz */
+                   IEEE80211_HTCAP_CHWIDTH40 |         /* 40 MHz channel width */
+                   IEEE80211_HTCAP_SHORTGI40;          /* short GI in 40MHz */
+#ifdef notyet
                if (sc->hw_type != IWN_HW_REV_TYPE_4965)
                        ic->ic_htcaps |= IEEE80211_HTCAP_GF;
                if (sc->hw_type == IWN_HW_REV_TYPE_6050)
                        ic->ic_htcaps |= IEEE80211_HTCAP_SMPS_DYN;
                else
                        ic->ic_htcaps |= IEEE80211_HTCAP_SMPS_DIS;
+#endif
+               ic->ic_txstream = sc->ntxchains;
+               ic->ic_rxstream = sc->nrxchains;
+
        }
 #endif /* !IEEE80211_NO_HT */
 
+       ic->ic_getradiocaps = iwn_getradiocaps;
+
        /* Set supported legacy rates. */
-       ic->ic_sup_rates[IEEE80211_MODE_11B] = ieee80211_std_rateset_11b;
-       ic->ic_sup_rates[IEEE80211_MODE_11G] = ieee80211_std_rateset_11g;
-       if (sc->sc_flags & IWN_FLAG_HAS_5GHZ) {
-               ic->ic_sup_rates[IEEE80211_MODE_11A] = ieee80211_std_rateset_11a;
-       }
 #ifndef IEEE80211_NO_HT
        if (sc->sc_flags & IWN_FLAG_HAS_11N) {
                /* Set supported HT rates. */
@@ -573,31 +607,23 @@
        }
 #endif
 
+#if 0
        /* IBSS channel undefined for now. */
-       ic->ic_ibss_chan = &ic->ic_channels[0];
-
-       ifp->if_softc = sc;
-       ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
-       ifp->if_init = iwn_init;
-       ifp->if_ioctl = iwn_ioctl;
-       ifp->if_start = iwn_start;
-       ifp->if_stop = iwn_stop;
-       ifp->if_watchdog = iwn_watchdog;
-       IFQ_SET_READY(&ifp->if_snd);
-       memcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
-
-       error = if_initialize(ifp);
-       if (error != 0) {
-               aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n",
-                   error);
-               goto fail5;
-       }
+       ic->ic_curchan = &ic->ic_channels[0];
+#endif
+
+
+       iwn_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans, 
+           ic->ic_channels);
+
+       //ifp->if_percpuq = if_percpuq_create(ifp);
        ieee80211_ifattach(ic);
-       /* Use common softint-based if_input */
-       ifp->if_percpuq = if_percpuq_create(ifp);
-       if_register(ifp);
-
-       ic->ic_node_alloc = iwn_node_alloc;
+
+       ic->ic_vap_create = iwn_vap_create;
+       ic->ic_vap_delete = iwn_vap_delete;
+       ic->ic_parent = iwn_parent;
+       ic->ic_scan_start = iwn_scan;
+       ic->ic_scan_end = iwn_scan_end;
        ic->ic_newassoc = iwn_newassoc;
 #ifdef IWN_HWCRYPTO
        ic->ic_crypto.cs_key_set = iwn_set_key;
@@ -611,38 +637,44 @@
        ic->ic_ampdu_tx_stop = iwn_ampdu_tx_stop;
 #endif
 
-       /* Override 802.11 state transition machine. */
-       sc->sc_newstate = ic->ic_newstate;
-       ic->ic_newstate = iwn_newstate;
-
        /* XXX media locking needs revisiting */
        mutex_init(&sc->sc_media_mtx, MUTEX_DEFAULT, IPL_SOFTNET);
+#if 0
        ieee80211_media_init_with_lock(ic,
            iwn_media_change, ieee80211_media_status, &sc->sc_media_mtx);
+#endif
 
        sc->amrr.amrr_min_success_threshold =  1;
        sc->amrr.amrr_max_success_threshold = 15;
 
-       iwn_radiotap_attach(sc);
-
-       /*
-        * XXX for NetBSD, OpenBSD timeout_set replaced by
-        * callout_init and callout_setfunc, above.
-        */
+//     iwn_radiotap_attach(sc);
+
+       /* Use common softint-based if_input */
+       /* XXX NetBSD add call to ieee80211_announce for dmesg. */
+
+       sc->sc_flags |= IWN_FLAG_ATTACHED;
+       struct ieee80211vap *vap =
+            iwn_vap_create(ic, device_xname(sc->sc_dev),
+                device_unit(sc->sc_dev), IEEE80211_M_STA,
+                IEEE80211_CLONE_MACADDR, ic->ic_macaddr, ic->ic_macaddr);
+
+        if (vap == NULL) {
+                /* Didn't work ... now what! */
+                printf ("NNN vap_create didn't work ...\n");
+       }
 
        if (pmf_device_register(self, NULL, iwn_resume))
-               pmf_class_network_register(self, ifp);
+               pmf_class_network_register(self, vap->iv_ifp);
        else
                aprint_error_dev(self, "couldn't establish power handler\n");
 
-       /* XXX NetBSD add call to ieee80211_announce for dmesg. */
+
        ieee80211_announce(ic);
 
-       sc->sc_flags |= IWN_FLAG_ATTACHED;
        return;
 
        /* Free allocated memory if something failed during attachment. */
-fail5: iwn_free_rx_ring(sc, &sc->rxq);
+//fail5:       iwn_free_rx_ring(sc, &sc->rxq);
 fail4: while (--i >= 0)
                iwn_free_tx_ring(sc, &sc->txq[i]);
 #ifdef IWN_USE_RBUF
@@ -662,7 +694,112 @@
 unmap: bus_space_unmap(sc->sc_st, sc->sc_sh, sc->sc_sz);
 }
 
-int
+static void
+iwn_vap_delete(struct ieee80211vap *vap)
+{
+       struct ifnet *ifp = vap->iv_ifp;
+       struct iwn_softc *sc __unused =vap->iv_ic->ic_softc;



Home | Main Index | Thread Index | Old Index