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 Wrap firmware upload in a function.



details:   https://anonhg.NetBSD.org/src-all/rev/907407a22a46
branches:  trunk
changeset: 1027131:907407a22a46
user:      Nathanial Sloss <nat%netbsd.org@localhost>
date:      Sat Nov 20 01:54:23 2021 +1100

description:
Wrap firmware upload in a function.

diffstat:

 sys/dev/pci/if_iwn.c |  53 +++++++++++++++++++++++++++++++--------------------
 1 files changed, 32 insertions(+), 21 deletions(-)

diffs (78 lines):

diff -r 9db37d73126c -r 907407a22a46 sys/dev/pci/if_iwn.c
--- a/sys/dev/pci/if_iwn.c      Thu Nov 18 08:39:49 2021 +1100
+++ b/sys/dev/pci/if_iwn.c      Sat Nov 20 01:54:23 2021 +1100
@@ -413,6 +413,7 @@
 static int     iwn_hw_init(struct iwn_softc *);
 static void    iwn_hw_stop(struct iwn_softc *);
 static int     iwn_init(struct ifnet *);
+static int     iwn_fw_init(struct iwn_softc *);
 static void    iwn_stop(struct ifnet *, int);
 
 /* XXX MCLGETI alternative */
@@ -6865,6 +6866,36 @@
 }
 
 static int
+iwn_fw_init(struct iwn_softc *sc)
+{
+       int error = 0;
+
+       /* Read firmware images from the filesystem. */
+       if ((error = iwn_read_firmware(sc)) != 0) {
+               aprint_error_dev(sc->sc_dev,
+                   "could not read firmware\n");
+               return error;
+       }
+
+       /* Initialize interrupt mask to default value. */
+       sc->int_mask = IWN_INT_MASK_DEF;
+       sc->sc_flags &= ~IWN_FLAG_USE_ICT;
+
+       /* Initialize hardware and upload firmware. */
+       KASSERT(sc->fw.data != NULL && sc->fw.size > 0);
+       error = iwn_hw_init(sc);
+       firmware_free(sc->fw.data, sc->fw.size);
+       sc->fw.data = NULL;
+       sc->fw.size = 0;
+       if (error != 0) {
+               aprint_error_dev(sc->sc_dev,
+                   "could not initialize hardware\n");
+       }
+
+       return error;
+}
+
+static int
 iwn_init(struct ifnet *ifp)
 {
        struct ieee80211vap *vap = ifp->if_softc;
@@ -6890,28 +6921,8 @@
                goto fail;
        }
 
-       /* Read firmware images from the filesystem. */
-       if ((error = iwn_read_firmware(sc)) != 0) {
-               aprint_error_dev(sc->sc_dev,
-                   "could not read firmware\n");
+       if (iwn_fw_init(sc) != 0)
                goto fail;
-       }
-
-       /* Initialize interrupt mask to default value. */
-       sc->int_mask = IWN_INT_MASK_DEF;
-       sc->sc_flags &= ~IWN_FLAG_USE_ICT;
-
-       /* Initialize hardware and upload firmware. */
-       KASSERT(sc->fw.data != NULL && sc->fw.size > 0);
-       error = iwn_hw_init(sc);
-       firmware_free(sc->fw.data, sc->fw.size);
-       sc->fw.data = NULL;
-       sc->fw.size = 0;
-       if (error != 0) {
-               aprint_error_dev(sc->sc_dev,
-                   "could not initialize hardware\n");
-               goto fail;
-       }
 
        /* Configure adapter now that it is ready. */
        if ((error = iwn_config(vap)) != 0) {



Home | Main Index | Thread Index | Old Index