svn commit: r333030 - in head/sys/dev/cxgbe: . tom

Navdeep Parhar np at FreeBSD.org
Thu Apr 26 19:00:36 UTC 2018


Author: np
Date: Thu Apr 26 19:00:35 2018
New Revision: 333030
URL: https://svnweb.freebsd.org/changeset/base/333030

Log:
  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

Modified:
  head/sys/dev/cxgbe/adapter.h
  head/sys/dev/cxgbe/t4_main.c
  head/sys/dev/cxgbe/tom/t4_connect.c
  head/sys/dev/cxgbe/tom/t4_tom.c

Modified: head/sys/dev/cxgbe/adapter.h
==============================================================================
--- head/sys/dev/cxgbe/adapter.h	Thu Apr 26 18:54:00 2018	(r333029)
+++ head/sys/dev/cxgbe/adapter.h	Thu Apr 26 19:00:35 2018	(r333030)
@@ -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 */

Modified: head/sys/dev/cxgbe/t4_main.c
==============================================================================
--- head/sys/dev/cxgbe/t4_main.c	Thu Apr 26 18:54:00 2018	(r333029)
+++ head/sys/dev/cxgbe/t4_main.c	Thu Apr 26 19:00:35 2018	(r333030)
@@ -2460,6 +2460,81 @@ rw_via_memwin(struct adapter *sc, int idx, uint32_t ad
 	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)
 {

Modified: head/sys/dev/cxgbe/tom/t4_connect.c
==============================================================================
--- head/sys/dev/cxgbe/tom/t4_connect.c	Thu Apr 26 18:54:00 2018	(r333029)
+++ head/sys/dev/cxgbe/tom/t4_connect.c	Thu Apr 26 19:00:35 2018	(r333030)
@@ -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.
  */

Modified: head/sys/dev/cxgbe/tom/t4_tom.c
==============================================================================
--- head/sys/dev/cxgbe/tom/t4_tom.c	Thu Apr 26 18:54:00 2018	(r333029)
+++ head/sys/dev/cxgbe/tom/t4_tom.c	Thu Apr 26 19:00:35 2018	(r333030)
@@ -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);
+	atomic_store_rel_int(&t->tids_in_use, 0);
 
-	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;
+	return (0);
+}
 
+static void
+free_tid_tab(struct tid_info *t)
+{
+
+	KASSERT(t->tids_in_use == 0,
+	    ("%s: %d tids still in use.", __func__, t->tids_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->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_stid_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;
-
-	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


More information about the svn-src-head mailing list