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
This commit is contained in:
Navdeep Parhar 2018-04-26 19:00:35 +00:00
parent 9a16bd169e
commit 3747c1ffc7
4 changed files with 148 additions and 74 deletions

View File

@ -1164,6 +1164,11 @@ int vi_full_uninit(struct vi_info *);
void vi_sysctls(struct vi_info *); void vi_sysctls(struct vi_info *);
void vi_tick(void *); void vi_tick(void *);
int rw_via_memwin(struct adapter *, int, uint32_t, uint32_t *, int, int); 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 #ifdef DEV_NETMAP
/* t4_netmap.c */ /* t4_netmap.c */

View File

@ -2460,6 +2460,81 @@ rw_via_memwin(struct adapter *sc, int idx, uint32_t addr, uint32_t *val,
return (0); 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 static int
t4_range_cmp(const void *a, const void *b) t4_range_cmp(const void *a, const void *b)
{ {

View File

@ -65,51 +65,6 @@ __FBSDID("$FreeBSD$");
#include "tom/t4_tom_l2t.h" #include "tom/t4_tom_l2t.h"
#include "tom/t4_tom.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. * Active open succeeded.
*/ */

View File

@ -754,55 +754,94 @@ negative_advice(int status)
} }
static int 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) + MPASS(t->ntids > 0);
t->natids * sizeof(*t->atid_tab) + MPASS(t->tid_tab == NULL);
t->nstids * sizeof(*t->stid_tab);
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) if (t->tid_tab == NULL)
return (ENOMEM); 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); atomic_store_rel_int(&t->tids_in_use, 0);
return (0); return (0);
} }
static void static void
free_tid_tabs(struct tid_info *t) free_tid_tab(struct tid_info *t)
{ {
KASSERT(t->tids_in_use == 0, KASSERT(t->tids_in_use == 0,
("%s: %d tids still in use.", __func__, t->tids_in_use)); ("%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); free(t->tid_tab, M_CXGBE);
t->tid_tab = NULL; 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)) if (mtx_initialized(&t->stid_lock))
mtx_destroy(&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 static int