bce(4): Detect context initialization failure
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 2 Jul 2011 11:37:24 +0000 (19:37 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 2 Jul 2011 12:05:27 +0000 (20:05 +0800)
Obtained-from: FreeBSD 210259

sys/dev/netif/bce/if_bce.c

index fb10193..7d262c8 100644 (file)
@@ -424,7 +424,7 @@ static void bce_ifmedia_sts(struct ifnet *, struct ifmediareq *);
 static void    bce_init(void *);
 static void    bce_mgmt_init(struct bce_softc *);
 
-static void    bce_init_ctx(struct bce_softc *);
+static int     bce_init_ctx(struct bce_softc *);
 static void    bce_get_mac_addr(struct bce_softc *);
 static void    bce_set_mac_addr(struct bce_softc *);
 static void    bce_phy_intr(struct bce_softc *);
@@ -3206,7 +3206,7 @@ bce_init_cpus(struct bce_softc *sc)
 /* Returns:                                                                 */
 /*   Nothing.                                                               */
 /****************************************************************************/
-static void
+static int
 bce_init_ctx(struct bce_softc *sc)
 {
        if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709 ||
@@ -3232,6 +3232,11 @@ bce_init_ctx(struct bce_softc *sc)
                                break;
                        DELAY(2);
                }
+               if (i == retry_cnt) {
+                       device_printf(sc->bce_dev,
+                           "Context memory initialization failed!\n");
+                       return ETIMEDOUT;
+               }
 
                for (i = 0; i < sc->ctx_pages; i++) {
                        int j;
@@ -3258,6 +3263,11 @@ bce_init_ctx(struct bce_softc *sc)
                                        break;
                                DELAY(5);
                        }
+                       if (j == retry_cnt) {
+                               device_printf(sc->bce_dev,
+                                   "Failed to initialize context page!\n");
+                               return ETIMEDOUT;
+                       }
                }
        } else {
                uint32_t vcid_addr, offset;
@@ -3282,6 +3292,7 @@ bce_init_ctx(struct bce_softc *sc)
                        REG_WR(sc, BCE_CTX_PAGE_TBL, vcid_addr);
                }
        }
+       return 0;
 }
 
 
@@ -3550,7 +3561,9 @@ bce_chipinit(struct bce_softc *sc)
               BCE_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
 
        /* Initialize context mapping and zero out the quick contexts. */
-       bce_init_ctx(sc);
+       rc = bce_init_ctx(sc);
+       if (rc != 0)
+               return rc;
 
        /* Initialize the on-boards CPUs */
        bce_init_cpus(sc);