svn commit: r346849 - in stable/11/sys/dev/cxgbe: . tom

Navdeep Parhar np at FreeBSD.org
Sun Apr 28 18:36:56 UTC 2019


Author: np
Date: Sun Apr 28 18:36:54 2019
New Revision: 346849
URL: https://svnweb.freebsd.org/changeset/base/346849

Log:
  MFC r333030:
  
  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:
  stable/11/sys/dev/cxgbe/adapter.h
  stable/11/sys/dev/cxgbe/t4_main.c
  stable/11/sys/dev/cxgbe/tom/t4_connect.c
  stable/11/sys/dev/cxgbe/tom/t4_tom.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/cxgbe/adapter.h
==============================================================================
--- stable/11/sys/dev/cxgbe/adapter.h	Sun Apr 28 18:30:19 2019	(r346848)
+++ stable/11/sys/dev/cxgbe/adapter.h	Sun Apr 28 18:36:54 2019	(r346849)
@@ -1119,6 +1119,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: stable/11/sys/dev/cxgbe/t4_main.c
==============================================================================
--- stable/11/sys/dev/cxgbe/t4_main.c	Sun Apr 28 18:30:19 2019	(r346848)
+++ stable/11/sys/dev/cxgbe/t4_main.c	Sun Apr 28 18:36:54 2019	(r346849)
@@ -2755,6 +2755,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: stable/11/sys/dev/cxgbe/tom/t4_connect.c
==============================================================================
--- stable/11/sys/dev/cxgbe/tom/t4_connect.c	Sun Apr 28 18:30:19 2019	(r346848)
+++ stable/11/sys/dev/cxgbe/tom/t4_connect.c	Sun Apr 28 18:36:54 2019	(r346849)
@@ -63,51 +63,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: stable/11/sys/dev/cxgbe/tom/t4_tom.c
==============================================================================
--- stable/11/sys/dev/cxgbe/tom/t4_tom.c	Sun Apr 28 18:30:19 2019	(r346848)
+++ stable/11/sys/dev/cxgbe/tom/t4_tom.c	Sun Apr 28 18:36:54 2019	(r346849)
@@ -751,55 +751,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-all mailing list