From owner-svn-src-all@freebsd.org Sun Apr 28 18:36:56 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 23DE31586353; Sun, 28 Apr 2019 18:36:56 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8E6F670549; Sun, 28 Apr 2019 18:36:55 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 58B59E949; Sun, 28 Apr 2019 18:36:55 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3SIatmP086788; Sun, 28 Apr 2019 18:36:55 GMT (envelope-from np@FreeBSD.org) Received: (from np@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3SIaswn086784; Sun, 28 Apr 2019 18:36:54 GMT (envelope-from np@FreeBSD.org) Message-Id: <201904281836.x3SIaswn086784@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: np set sender to np@FreeBSD.org using -f From: Navdeep Parhar Date: Sun, 28 Apr 2019 18:36:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r346849 - in stable/11/sys/dev/cxgbe: . tom X-SVN-Group: stable-11 X-SVN-Commit-Author: np X-SVN-Commit-Paths: in stable/11/sys/dev/cxgbe: . tom X-SVN-Commit-Revision: 346849 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8E6F670549 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.997,0]; NEURAL_HAM_SHORT(-0.98)[-0.979,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Apr 2019 18:36:56 -0000 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