Author: davidcs
Date: Mon Mar 14 23:33:38 2016
New Revision: 296877
URL: https://svnweb.freebsd.org/changeset/base/296877
Log:
MFC r296579
Fix code so that buf_ring allocation for Tx Queues and their mutexes
is done during during bxe_attach() and freed during bxe_detach()
Modified:
stable/9/sys/dev/bxe/bxe.c
Directory Properties:
stable/9/ (props changed)
stable/9/sys/ (props changed)
stable/9/sys/dev/ (props changed)
Modified: stable/9/sys/dev/bxe/bxe.c
==
--- stable/9/sys/dev/bxe/bxe.c Mon Mar 14 23:21:06 2016(r296876)
+++ stable/9/sys/dev/bxe/bxe.c Mon Mar 14 23:33:38 2016(r296877)
@@ -680,6 +680,8 @@ static void bxe_handle_fp_tq(void *conte
static int bxe_add_cdev(struct bxe_softc *sc);
static void bxe_del_cdev(struct bxe_softc *sc);
static int bxe_grc_dump(struct bxe_softc *sc);
+static int bxe_alloc_buf_rings(struct bxe_softc *sc);
+static void bxe_free_buf_rings(struct bxe_softc *sc);
/* calculate crc32 on a buffer (NOTE: crc32_length MUST be aligned to 8) */
uint32_t
@@ -4204,9 +4206,20 @@ bxe_nic_unload(struct bxe_softc *sc,
{
uint8_t global = FALSE;
uint32_t val;
+int i;
BXE_CORE_LOCK_ASSERT(sc);
+sc->ifnet->if_drv_flags &= ~IFF_DRV_RUNNING;
+
+for (i = 0; i < sc->num_queues; i++) {
+struct bxe_fastpath *fp;
+
+fp = >fp[i];
+BXE_FP_TX_LOCK(fp);
+BXE_FP_TX_UNLOCK(fp);
+}
+
BLOGD(sc, DBG_LOAD, "Starting NIC unload...\n");
/* mark driver as unloaded in shmem2 */
@@ -6254,8 +6267,6 @@ bxe_free_fp_buffers(struct bxe_softc *sc
m_freem(m);
BXE_FP_TX_UNLOCK(fp);
}
-buf_ring_free(fp->tx_br, M_DEVBUF);
-fp->tx_br = NULL;
}
#endif
@@ -6285,14 +6296,6 @@ bxe_free_fp_buffers(struct bxe_softc *sc
}
/* XXX verify all mbufs were reclaimed */
-
-if (mtx_initialized(>tx_mtx)) {
-mtx_destroy(>tx_mtx);
-}
-
-if (mtx_initialized(>rx_mtx)) {
-mtx_destroy(>rx_mtx);
-}
}
}
@@ -6514,15 +6517,6 @@ bxe_alloc_fp_buffers(struct bxe_softc *s
for (i = 0; i < sc->num_queues; i++) {
fp = >fp[i];
-#if __FreeBSD_version >= 80
-fp->tx_br = buf_ring_alloc(BXE_BR_SIZE, M_DEVBUF,
- M_DONTWAIT, >tx_mtx);
-if (fp->tx_br == NULL) {
-BLOGE(sc, "buf_ring alloc fail for fp[%02d]\n", i);
-goto bxe_alloc_fp_buffers_error;
-}
-#endif
-
ring_prod = cqe_ring_prod = 0;
fp->rx_bd_cons = 0;
fp->rx_cq_cons = 0;
@@ -9630,14 +9624,6 @@ bxe_init_eth_fp(struct bxe_softc *sc,
fp->sc= sc;
fp->index = idx;
-snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name),
- "bxe%d_fp%d_tx_lock", sc->unit, idx);
-mtx_init(>tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF);
-
-snprintf(fp->rx_mtx_name, sizeof(fp->rx_mtx_name),
- "bxe%d_fp%d_rx_lock", sc->unit, idx);
-mtx_init(>rx_mtx, fp->rx_mtx_name, NULL, MTX_DEF);
-
fp->igu_sb_id = (sc->igu_base_sb + idx + CNIC_SUPPORT(sc));
fp->fw_sb_id = (sc->base_fw_ndsb + idx + CNIC_SUPPORT(sc));
@@ -15829,6 +15815,89 @@ bxe_add_sysctls(struct bxe_softc *sc)
}
}
+static int
+bxe_alloc_buf_rings(struct bxe_softc *sc)
+{
+#if __FreeBSD_version >= 80
+
+int i;
+struct bxe_fastpath *fp;
+
+for (i = 0; i < sc->num_queues; i++) {
+
+fp = >fp[i];
+
+fp->tx_br = buf_ring_alloc(BXE_BR_SIZE, M_DEVBUF,
+ M_NOWAIT, >tx_mtx);
+if (fp->tx_br == NULL)
+return (-1);
+}
+#endif
+return (0);
+}
+
+static void
+bxe_free_buf_rings(struct bxe_softc *sc)
+{
+#if __FreeBSD_version >= 80
+
+int i;
+struct bxe_fastpath *fp;
+
+for (i = 0; i < sc->num_queues; i++) {
+
+fp = >fp[i];
+
+if (fp->tx_br) {
+buf_ring_free(fp->tx_br, M_DEVBUF);
+fp->tx_br = NULL;
+}
+}
+
+#endif
+}
+
+static void
+bxe_init_fp_mutexs(struct bxe_softc *sc)
+{
+int i;
+struct bxe_fastpath *fp;
+
+for (i = 0; i < sc->num_queues; i++) {
+
+fp = >fp[i];
+
+snprintf(fp->tx_mtx_name, sizeof(fp->tx_mtx_name),
+"bxe%d_fp%d_tx_lock", sc->unit, i);
+mtx_init(>tx_mtx, fp->tx_mtx_name, NULL, MTX_DEF);
+
+snprintf(fp->rx_mtx_name, sizeof(fp->rx_mtx_name),
+"bxe%d_fp%d_rx_lock", sc->unit, i);
+mtx_init(>rx_mtx, fp->rx_mtx_name, NULL, MTX_DEF);
+}
+}
+
+static void
+bxe_destroy_fp_mutexs(struct bxe_softc *sc)
+{
+int i;
+struct bxe_fastpath *fp;
+
+for (i = 0; i < sc->num_queues; i++) {
+
+fp = >fp[i];
+
+if (mtx_initialized(>tx_mtx)) {
+mtx_destroy(>tx_mtx);
+}
+
+if (mtx_initialized(>rx_mtx)) {
+mtx_destroy(>rx_mtx);
+}
+