t4_l2t.c (244551) | t4_l2t.c (245434) |
---|---|
1/*- 2 * Copyright (c) 2012 Chelsio Communications, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2012 Chelsio Communications, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26#include <sys/cdefs.h> |
27__FBSDID("$FreeBSD: head/sys/dev/cxgbe/t4_l2t.c 244551 2012-12-21 19:28:17Z np $"); | 27__FBSDID("$FreeBSD: head/sys/dev/cxgbe/t4_l2t.c 245434 2013-01-14 20:36:22Z np $"); |
28 29#include "opt_inet.h" 30#include "opt_inet6.h" 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/module.h> 36#include <sys/bus.h> 37#include <sys/lock.h> 38#include <sys/mutex.h> 39#include <sys/rwlock.h> 40#include <sys/socket.h> 41#include <sys/sbuf.h> 42#include <netinet/in.h> 43 44#include "common/common.h" | 28 29#include "opt_inet.h" 30#include "opt_inet6.h" 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/module.h> 36#include <sys/bus.h> 37#include <sys/lock.h> 38#include <sys/mutex.h> 39#include <sys/rwlock.h> 40#include <sys/socket.h> 41#include <sys/sbuf.h> 42#include <netinet/in.h> 43 44#include "common/common.h" |
45#include "common/jhash.h" | |
46#include "common/t4_msg.h" 47#include "t4_l2t.h" 48 49/* 50 * Module locking notes: There is a RW lock protecting the L2 table as a 51 * whole plus a spinlock per L2T entry. Entry lookups and allocations happen 52 * under the protection of the table lock, individual entry changes happen 53 * while holding that entry's spinlock. The table lock nests outside the --- 19 unchanged lines hidden (view full) --- 73 struct l2t_entry *end, *e, **p; 74 75 rw_assert(&d->lock, RA_WLOCKED); 76 77 if (!atomic_load_acq_int(&d->nfree)) 78 return (NULL); 79 80 /* there's definitely a free entry */ | 45#include "common/t4_msg.h" 46#include "t4_l2t.h" 47 48/* 49 * Module locking notes: There is a RW lock protecting the L2 table as a 50 * whole plus a spinlock per L2T entry. Entry lookups and allocations happen 51 * under the protection of the table lock, individual entry changes happen 52 * while holding that entry's spinlock. The table lock nests outside the --- 19 unchanged lines hidden (view full) --- 72 struct l2t_entry *end, *e, **p; 73 74 rw_assert(&d->lock, RA_WLOCKED); 75 76 if (!atomic_load_acq_int(&d->nfree)) 77 return (NULL); 78 79 /* there's definitely a free entry */ |
81 for (e = d->rover, end = &d->l2tab[L2T_SIZE]; e != end; ++e) | 80 for (e = d->rover, end = &d->l2tab[d->l2t_size]; e != end; ++e) |
82 if (atomic_load_acq_int(&e->refcnt) == 0) 83 goto found; 84 85 for (e = d->l2tab; atomic_load_acq_int(&e->refcnt); ++e) 86 continue; 87found: 88 d->rover = e + 1; 89 atomic_subtract_int(&d->nfree, 1); --- 20 unchanged lines hidden (view full) --- 110 * Write an L2T entry. Must be called with the entry locked. 111 * The write may be synchronous or asynchronous. 112 */ 113int 114t4_write_l2e(struct adapter *sc, struct l2t_entry *e, int sync) 115{ 116 struct wrqe *wr; 117 struct cpl_l2t_write_req *req; | 81 if (atomic_load_acq_int(&e->refcnt) == 0) 82 goto found; 83 84 for (e = d->l2tab; atomic_load_acq_int(&e->refcnt); ++e) 85 continue; 86found: 87 d->rover = e + 1; 88 atomic_subtract_int(&d->nfree, 1); --- 20 unchanged lines hidden (view full) --- 109 * Write an L2T entry. Must be called with the entry locked. 110 * The write may be synchronous or asynchronous. 111 */ 112int 113t4_write_l2e(struct adapter *sc, struct l2t_entry *e, int sync) 114{ 115 struct wrqe *wr; 116 struct cpl_l2t_write_req *req; |
117 int idx = e->idx + sc->vres.l2t.start; |
|
118 119 mtx_assert(&e->lock, MA_OWNED); 120 121 wr = alloc_wrqe(sizeof(*req), &sc->sge.mgmtq); 122 if (wr == NULL) 123 return (ENOMEM); 124 req = wrtod(wr); 125 126 INIT_TP_WR(req, 0); | 118 119 mtx_assert(&e->lock, MA_OWNED); 120 121 wr = alloc_wrqe(sizeof(*req), &sc->sge.mgmtq); 122 if (wr == NULL) 123 return (ENOMEM); 124 req = wrtod(wr); 125 126 INIT_TP_WR(req, 0); |
127 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_L2T_WRITE_REQ, e->idx | | 127 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_L2T_WRITE_REQ, idx | |
128 V_SYNC_WR(sync) | V_TID_QID(sc->sge.fwq.abs_id))); 129 req->params = htons(V_L2T_W_PORT(e->lport) | V_L2T_W_NOREPLY(!sync)); | 128 V_SYNC_WR(sync) | V_TID_QID(sc->sge.fwq.abs_id))); 129 req->params = htons(V_L2T_W_PORT(e->lport) | V_L2T_W_NOREPLY(!sync)); |
130 req->l2t_idx = htons(e->idx); | 130 req->l2t_idx = htons(idx); |
131 req->vlan = htons(e->vlan); 132 memcpy(req->dst_mac, e->dmac, sizeof(req->dst_mac)); 133 134 t4_wrq_tx(sc, wr); 135 136 if (sync && e->state != L2T_STATE_SWITCHING) 137 e->state = L2T_STATE_SYNC_WRITE; 138 --- 39 unchanged lines hidden (view full) --- 178 rc = t4_write_l2e(sc, e, 0); 179 mtx_unlock(&e->lock); 180 return (rc); 181} 182 183int 184t4_init_l2t(struct adapter *sc, int flags) 185{ | 131 req->vlan = htons(e->vlan); 132 memcpy(req->dst_mac, e->dmac, sizeof(req->dst_mac)); 133 134 t4_wrq_tx(sc, wr); 135 136 if (sync && e->state != L2T_STATE_SWITCHING) 137 e->state = L2T_STATE_SYNC_WRITE; 138 --- 39 unchanged lines hidden (view full) --- 178 rc = t4_write_l2e(sc, e, 0); 179 mtx_unlock(&e->lock); 180 return (rc); 181} 182 183int 184t4_init_l2t(struct adapter *sc, int flags) 185{ |
186 int i; | 186 int i, l2t_size; |
187 struct l2t_data *d; 188 | 187 struct l2t_data *d; 188 |
189 d = malloc(sizeof(*d), M_CXGBE, M_ZERO | flags); | 189 l2t_size = sc->vres.l2t.size; 190 if (l2t_size < 2) /* At least 1 bucket for IP and 1 for IPv6 */ 191 return (EINVAL); 192 193 d = malloc(sizeof(*d) + l2t_size * sizeof (struct l2t_entry), M_CXGBE, 194 M_ZERO | flags); |
190 if (!d) 191 return (ENOMEM); 192 | 195 if (!d) 196 return (ENOMEM); 197 |
198 d->l2t_size = l2t_size; |
|
193 d->rover = d->l2tab; | 199 d->rover = d->l2tab; |
194 atomic_store_rel_int(&d->nfree, L2T_SIZE); | 200 atomic_store_rel_int(&d->nfree, l2t_size); |
195 rw_init(&d->lock, "L2T"); 196 | 201 rw_init(&d->lock, "L2T"); 202 |
197 for (i = 0; i < L2T_SIZE; i++) { | 203 for (i = 0; i < l2t_size; i++) { |
198 struct l2t_entry *e = &d->l2tab[i]; 199 200 e->idx = i; 201 e->state = L2T_STATE_UNUSED; 202 mtx_init(&e->lock, "L2T_E", NULL, MTX_DEF); 203 STAILQ_INIT(&e->wr_list); 204 atomic_store_rel_int(&e->refcnt, 0); 205 } --- 4 unchanged lines hidden (view full) --- 210 return (0); 211} 212 213int 214t4_free_l2t(struct l2t_data *d) 215{ 216 int i; 217 | 204 struct l2t_entry *e = &d->l2tab[i]; 205 206 e->idx = i; 207 e->state = L2T_STATE_UNUSED; 208 mtx_init(&e->lock, "L2T_E", NULL, MTX_DEF); 209 STAILQ_INIT(&e->wr_list); 210 atomic_store_rel_int(&e->refcnt, 0); 211 } --- 4 unchanged lines hidden (view full) --- 216 return (0); 217} 218 219int 220t4_free_l2t(struct l2t_data *d) 221{ 222 int i; 223 |
218 for (i = 0; i < L2T_SIZE; i++) | 224 for (i = 0; i < d->l2t_size; i++) |
219 mtx_destroy(&d->l2tab[i].lock); 220 rw_destroy(&d->lock); 221 free(d, M_CXGBE); 222 223 return (0); 224} 225 226int 227do_l2t_write_rpl(struct sge_iq *iq, const struct rss_header *rss, 228 struct mbuf *m) 229{ 230 const struct cpl_l2t_write_rpl *rpl = (const void *)(rss + 1); 231 unsigned int tid = GET_TID(rpl); | 225 mtx_destroy(&d->l2tab[i].lock); 226 rw_destroy(&d->lock); 227 free(d, M_CXGBE); 228 229 return (0); 230} 231 232int 233do_l2t_write_rpl(struct sge_iq *iq, const struct rss_header *rss, 234 struct mbuf *m) 235{ 236 const struct cpl_l2t_write_rpl *rpl = (const void *)(rss + 1); 237 unsigned int tid = GET_TID(rpl); |
232 unsigned int idx = tid & (L2T_SIZE - 1); | 238 unsigned int idx = tid % L2T_SIZE; |
233 234 if (__predict_false(rpl->status != CPL_ERR_NONE)) { 235 log(LOG_ERR, | 239 240 if (__predict_false(rpl->status != CPL_ERR_NONE)) { 241 log(LOG_ERR, |
236 "Unexpected L2T_WRITE_RPL status %u for entry %u\n", | 242 "Unexpected L2T_WRITE_RPL (%u) for entry at hw_idx %u\n", |
237 rpl->status, idx); 238 return (EINVAL); 239 } 240 241 return (0); 242} 243 244#ifdef SBUF_DRAIN --- 19 unchanged lines hidden (view full) --- 264int 265sysctl_l2t(SYSCTL_HANDLER_ARGS) 266{ 267 struct adapter *sc = arg1; 268 struct l2t_data *l2t = sc->l2t; 269 struct l2t_entry *e; 270 struct sbuf *sb; 271 int rc, i, header = 0; | 243 rpl->status, idx); 244 return (EINVAL); 245 } 246 247 return (0); 248} 249 250#ifdef SBUF_DRAIN --- 19 unchanged lines hidden (view full) --- 270int 271sysctl_l2t(SYSCTL_HANDLER_ARGS) 272{ 273 struct adapter *sc = arg1; 274 struct l2t_data *l2t = sc->l2t; 275 struct l2t_entry *e; 276 struct sbuf *sb; 277 int rc, i, header = 0; |
272 char ip[60]; | 278 char ip[INET6_ADDRSTRLEN]; |
273 274 if (l2t == NULL) 275 return (ENXIO); 276 277 rc = sysctl_wire_old_buffer(req, 0); 278 if (rc != 0) 279 return (rc); 280 281 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 282 if (sb == NULL) 283 return (ENOMEM); 284 285 e = &l2t->l2tab[0]; | 279 280 if (l2t == NULL) 281 return (ENXIO); 282 283 rc = sysctl_wire_old_buffer(req, 0); 284 if (rc != 0) 285 return (rc); 286 287 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req); 288 if (sb == NULL) 289 return (ENOMEM); 290 291 e = &l2t->l2tab[0]; |
286 for (i = 0; i < L2T_SIZE; i++, e++) { | 292 for (i = 0; i < l2t->l2t_size; i++, e++) { |
287 mtx_lock(&e->lock); 288 if (e->state == L2T_STATE_UNUSED) 289 goto skip; 290 291 if (header == 0) { 292 sbuf_printf(sb, " Idx IP address " 293 "Ethernet address VLAN/P LP State Users Port"); 294 header = 1; 295 } 296 if (e->state == L2T_STATE_SWITCHING) 297 ip[0] = 0; | 293 mtx_lock(&e->lock); 294 if (e->state == L2T_STATE_UNUSED) 295 goto skip; 296 297 if (header == 0) { 298 sbuf_printf(sb, " Idx IP address " 299 "Ethernet address VLAN/P LP State Users Port"); 300 header = 1; 301 } 302 if (e->state == L2T_STATE_SWITCHING) 303 ip[0] = 0; |
298 else 299 snprintf(ip, sizeof(ip), "%s", 300 inet_ntoa(*(struct in_addr *)&e->addr)); | 304 else { 305 inet_ntop(e->ipv6 ? AF_INET6 : AF_INET, &e->addr[0], 306 &ip[0], sizeof(ip)); 307 } |
301 | 308 |
302 /* XXX: e->ifp may not be around */ | 309 /* 310 * XXX: e->ifp may not be around. 311 * XXX: IPv6 addresses may not align properly in the output. 312 */ |
303 sbuf_printf(sb, "\n%4u %-15s %02x:%02x:%02x:%02x:%02x:%02x %4d" 304 " %u %2u %c %5u %s", 305 e->idx, ip, e->dmac[0], e->dmac[1], e->dmac[2], 306 e->dmac[3], e->dmac[4], e->dmac[5], 307 e->vlan & 0xfff, vlan_prio(e), e->lport, 308 l2e_state(e), atomic_load_acq_int(&e->refcnt), 309 e->ifp->if_xname); 310skip: 311 mtx_unlock(&e->lock); 312 } 313 314 rc = sbuf_finish(sb); 315 sbuf_delete(sb); 316 317 return (rc); 318} 319#endif | 313 sbuf_printf(sb, "\n%4u %-15s %02x:%02x:%02x:%02x:%02x:%02x %4d" 314 " %u %2u %c %5u %s", 315 e->idx, ip, e->dmac[0], e->dmac[1], e->dmac[2], 316 e->dmac[3], e->dmac[4], e->dmac[5], 317 e->vlan & 0xfff, vlan_prio(e), e->lport, 318 l2e_state(e), atomic_load_acq_int(&e->refcnt), 319 e->ifp->if_xname); 320skip: 321 mtx_unlock(&e->lock); 322 } 323 324 rc = sbuf_finish(sb); 325 sbuf_delete(sb); 326 327 return (rc); 328} 329#endif |