From 3747c1ffc7ad6a33ac34c5561f2a9a7d9bff442e Mon Sep 17 00:00:00 2001 From: Navdeep Parhar Date: Thu, 26 Apr 2018 19:00:35 +0000 Subject: [PATCH] cxgbe(4): Break up alloc_tid_tabs and move the atid routines to the base NIC driver. The atid services will be used by new features (hashfilters and inline TLS) that do not involve TOE. Sponsored by: Chelsio Communications --- sys/dev/cxgbe/adapter.h | 5 ++ sys/dev/cxgbe/t4_main.c | 75 ++++++++++++++++++++++++++ sys/dev/cxgbe/tom/t4_connect.c | 45 ---------------- sys/dev/cxgbe/tom/t4_tom.c | 97 ++++++++++++++++++++++++---------- 4 files changed, 148 insertions(+), 74 deletions(-) diff --git a/sys/dev/cxgbe/adapter.h b/sys/dev/cxgbe/adapter.h index 34db6e8218ac..5eed5f80b1f8 100644 --- a/sys/dev/cxgbe/adapter.h +++ b/sys/dev/cxgbe/adapter.h @@ -1164,6 +1164,11 @@ int vi_full_uninit(struct vi_info *); void vi_sysctls(struct vi_info *); void vi_tick(void *); int rw_via_memwin(struct adapter *, int, uint32_t, uint32_t *, int, int); +int alloc_atid_tab(struct tid_info *, int); +void free_atid_tab(struct tid_info *); +int alloc_atid(struct adapter *, void *); +void *lookup_atid(struct adapter *, int); +void free_atid(struct adapter *, int); #ifdef DEV_NETMAP /* t4_netmap.c */ diff --git a/sys/dev/cxgbe/t4_main.c b/sys/dev/cxgbe/t4_main.c index 7ab5c4d76e27..27c2c638bbc0 100644 --- a/sys/dev/cxgbe/t4_main.c +++ b/sys/dev/cxgbe/t4_main.c @@ -2460,6 +2460,81 @@ rw_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val, return (0); } +int +alloc_atid_tab(struct tid_info *t, int flags) +{ + int i; + + MPASS(t->natids > 0); + MPASS(t->atid_tab == NULL); + + t->atid_tab = malloc(t->natids * sizeof(*t->atid_tab), M_CXGBE, + M_ZERO | flags); + if (t->atid_tab == NULL) + return (ENOMEM); + mtx_init(&t->atid_lock, "atid lock", NULL, MTX_DEF); + t->afree = t->atid_tab; + t->atids_in_use = 0; + for (i = 1; i < t->natids; i++) + t->atid_tab[i - 1].next = &t->atid_tab[i]; + t->atid_tab[t->natids - 1].next = NULL; + + return (0); +} + +void +free_atid_tab(struct tid_info *t) +{ + + KASSERT(t->atids_in_use == 0, + ("%s: %d atids still in use.", __func__, t->atids_in_use)); + + if (mtx_initialized(&t->atid_lock)) + mtx_destroy(&t->atid_lock); + free(t->atid_tab, M_CXGBE); + t->atid_tab = NULL; +} + +int +alloc_atid(struct adapter *sc, void *ctx) +{ + struct tid_info *t = &sc->tids; + int atid = -1; + + mtx_lock(&t->atid_lock); + if (t->afree) { + union aopen_entry *p = t->afree; + + atid = p - t->atid_tab; + t->afree = p->next; + p->data = ctx; + t->atids_in_use++; + } + mtx_unlock(&t->atid_lock); + return (atid); +} + +void * +lookup_atid(struct adapter *sc, int atid) +{ + struct tid_info *t = &sc->tids; + + return (t->atid_tab[atid].data); +} + +void +free_atid(struct adapter *sc, int atid) +{ + struct tid_info *t = &sc->tids; + union aopen_entry *p = &t->atid_tab[atid]; + + mtx_lock(&t->atid_lock); + p->next = t->afree; + t->afree = p; + t->atids_in_use--; + mtx_unlock(&t->atid_lock); +} + static int t4_range_cmp(const void *a, const void *b) { diff --git a/sys/dev/cxgbe/tom/t4_connect.c b/sys/dev/cxgbe/tom/t4_connect.c index 05f658698fd6..8d80d116ed4e 100644 --- a/sys/dev/cxgbe/tom/t4_connect.c +++ b/sys/dev/cxgbe/tom/t4_connect.c @@ -65,51 +65,6 @@ __FBSDID("$FreeBSD$"); #include "tom/t4_tom_l2t.h" #include "tom/t4_tom.h" -/* atid services */ -static int alloc_atid(struct adapter *, void *); -static void *lookup_atid(struct adapter *, int); -static void free_atid(struct adapter *, int); - -static int -alloc_atid(struct adapter *sc, void *ctx) -{ - struct tid_info *t = &sc->tids; - int atid = -1; - - mtx_lock(&t->atid_lock); - if (t->afree) { - union aopen_entry *p = t->afree; - - atid = p - t->atid_tab; - t->afree = p->next; - p->data = ctx; - t->atids_in_use++; - } - mtx_unlock(&t->atid_lock); - return (atid); -} - -static void * -lookup_atid(struct adapter *sc, int atid) -{ - struct tid_info *t = &sc->tids; - - return (t->atid_tab[atid].data); -} - -static void -free_atid(struct adapter *sc, int atid) -{ - struct tid_info *t = &sc->tids; - union aopen_entry *p = &t->atid_tab[atid]; - - mtx_lock(&t->atid_lock); - p->next = t->afree; - t->afree = p; - t->atids_in_use--; - mtx_unlock(&t->atid_lock); -} - /* * Active open succeeded. */ diff --git a/sys/dev/cxgbe/tom/t4_tom.c b/sys/dev/cxgbe/tom/t4_tom.c index ced854ec7f1b..411c2db5fe1d 100644 --- a/sys/dev/cxgbe/tom/t4_tom.c +++ b/sys/dev/cxgbe/tom/t4_tom.c @@ -754,55 +754,94 @@ negative_advice(int status) } static int -alloc_tid_tabs(struct tid_info *t) +alloc_tid_tab(struct tid_info *t, int flags) { - size_t size; - unsigned int i; - size = t->ntids * sizeof(*t->tid_tab) + - t->natids * sizeof(*t->atid_tab) + - t->nstids * sizeof(*t->stid_tab); + MPASS(t->ntids > 0); + MPASS(t->tid_tab == NULL); - t->tid_tab = malloc(size, M_CXGBE, M_ZERO | M_NOWAIT); + t->tid_tab = malloc(t->ntids * sizeof(*t->tid_tab), M_CXGBE, + M_ZERO | flags); if (t->tid_tab == NULL) return (ENOMEM); - - mtx_init(&t->atid_lock, "atid lock", NULL, MTX_DEF); - t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids]; - t->afree = t->atid_tab; - t->atids_in_use = 0; - for (i = 1; i < t->natids; i++) - t->atid_tab[i - 1].next = &t->atid_tab[i]; - t->atid_tab[t->natids - 1].next = NULL; - - mtx_init(&t->stid_lock, "stid lock", NULL, MTX_DEF); - t->stid_tab = (struct listen_ctx **)&t->atid_tab[t->natids]; - t->stids_in_use = 0; - TAILQ_INIT(&t->stids); - t->nstids_free_head = t->nstids; - atomic_store_rel_int(&t->tids_in_use, 0); return (0); } static void -free_tid_tabs(struct tid_info *t) +free_tid_tab(struct tid_info *t) { + KASSERT(t->tids_in_use == 0, ("%s: %d tids still in use.", __func__, t->tids_in_use)); - KASSERT(t->atids_in_use == 0, - ("%s: %d atids still in use.", __func__, t->atids_in_use)); - KASSERT(t->stids_in_use == 0, - ("%s: %d tids still in use.", __func__, t->stids_in_use)); free(t->tid_tab, M_CXGBE); t->tid_tab = NULL; +} + +static int +alloc_stid_tab(struct tid_info *t, int flags) +{ + + MPASS(t->nstids > 0); + MPASS(t->stid_tab == NULL); + + t->stid_tab = malloc(t->nstids * sizeof(*t->stid_tab), M_CXGBE, + M_ZERO | flags); + if (t->stid_tab == NULL) + return (ENOMEM); + mtx_init(&t->stid_lock, "stid lock", NULL, MTX_DEF); + t->stids_in_use = 0; + TAILQ_INIT(&t->stids); + t->nstids_free_head = t->nstids; + + return (0); +} + +static void +free_stid_tab(struct tid_info *t) +{ + + KASSERT(t->stids_in_use == 0, + ("%s: %d tids still in use.", __func__, t->stids_in_use)); - if (mtx_initialized(&t->atid_lock)) - mtx_destroy(&t->atid_lock); if (mtx_initialized(&t->stid_lock)) mtx_destroy(&t->stid_lock); + free(t->stid_tab, M_CXGBE); + t->stid_tab = NULL; +} + +static void +free_tid_tabs(struct tid_info *t) +{ + + free_tid_tab(t); + free_atid_tab(t); + free_stid_tab(t); +} + +static int +alloc_tid_tabs(struct tid_info *t) +{ + int rc; + + rc = alloc_tid_tab(t, M_NOWAIT); + if (rc != 0) + goto failed; + + rc = alloc_atid_tab(t, M_NOWAIT); + if (rc != 0) + goto failed; + + rc = alloc_stid_tab(t, M_NOWAIT); + if (rc != 0) + goto failed; + + return (0); +failed: + free_tid_tabs(t); + return (rc); } static int