Lines Matching +full:lock +full:- +full:state
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
38 #include <sys/lock.h>
50 * Module locking notes: There is a RW lock protecting the L2 table as a
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
54 * entry locks. Allocations of new entries take the table lock as writers so
56 * take the table lock as readers so multiple entries can be updated in
59 * can change state or increment its ref count during allocation as both of
68 * Allocate a free L2T entry. Must be called with l2t_data.lock held.
75 rw_assert(&d->lock, RA_WLOCKED);
76 if (__predict_false(d->l2t_stopped))
78 if (!atomic_load_acq_int(&d->nfree))
82 for (e = d->rover, end = &d->l2tab[d->l2t_size]; e != end; ++e)
83 if (atomic_load_acq_int(&e->refcnt) == 0)
86 for (e = d->l2tab; atomic_load_acq_int(&e->refcnt); ++e)
89 d->rover = e + 1;
90 atomic_subtract_int(&d->nfree, 1);
96 if (e->state < L2T_STATE_SWITCHING) {
97 for (p = &d->l2tab[e->hash].first; *p; p = &(*p)->next) {
99 *p = e->next;
100 e->next = NULL;
106 e->state = L2T_STATE_UNUSED;
116 for (e = &d->l2tab[0], end = &d->l2tab[d->l2t_size]; e != end; ++e) {
117 if (atomic_load_acq_int(&e->refcnt) == 0) {
120 } else if (e->state == L2T_STATE_SWITCHING &&
121 memcmp(e->dmac, dmac, ETHER_ADDR_LEN) == 0 &&
122 e->vlan == vlan && e->hw_port == port)
134 if (e->state < L2T_STATE_SWITCHING) {
135 for (p = &d->l2tab[e->hash].first; *p; p = &(*p)->next) {
137 *p = e->next;
138 e->next = NULL;
143 e->state = L2T_STATE_UNUSED;
155 idx = e->idx + sc->vres.l2t.start;
158 V_SYNC_WR(sync) | V_TID_QID(e->iqid)));
159 req->params = htons(V_L2T_W_PORT(e->hw_port) | V_L2T_W_NOREPLY(!reply));
160 req->l2t_idx = htons(idx);
161 req->vlan = htons(e->vlan);
162 memcpy(req->dst_mac, e->dmac, sizeof(req->dst_mac));
177 mtx_assert(&e->lock, MA_OWNED);
178 MPASS(e->wrq != NULL);
180 wrq = e->wrq;
181 sc = wrq->adapter;
191 if (sync && e->state != L2T_STATE_SWITCHING)
192 e->state = L2T_STATE_SYNC_WRITE;
220 d = sc->l2t;
223 rw_rlock(&d->lock);
226 for (i = 0; i < d->l2t_size; i++) {
227 e = &d->l2tab[i];
228 if (e->state != L2T_STATE_TLS)
230 if (e->vlan == vlan && e->hw_port == port &&
231 e->wrq == (struct sge_wrq *)txq &&
232 memcmp(e->dmac, eth_addr, ETHER_ADDR_LEN) == 0) {
233 if (atomic_fetchadd_int(&e->refcnt, 1) == 0) {
238 atomic_subtract_int(&d->nfree, 1);
240 KASSERT(e->refcnt > 0,
242 rw_runlock(&d->lock);
251 if (!rw_try_upgrade(&d->lock)) {
252 rw_runlock(&d->lock);
253 rw_wlock(&d->lock);
259 rw_wunlock(&d->lock);
264 e->state = L2T_STATE_TLS;
265 e->vlan = vlan;
266 e->hw_port = port;
267 e->iqid = sc->sge.fwq.abs_id;
268 e->wrq = (struct sge_wrq *)txq;
269 memcpy(e->dmac, eth_addr, ETHER_ADDR_LEN);
270 atomic_store_rel_int(&e->refcnt, 1);
271 rw_wunlock(&d->lock);
290 struct l2t_data *d = sc->l2t;
294 rw_wlock(&d->lock);
295 if (__predict_false(d->l2t_stopped))
300 if (atomic_load_acq_int(&e->refcnt) == 0) {
301 mtx_lock(&e->lock); /* avoid race with t4_l2t_free */
302 e->wrq = &sc->sge.ctrlq[0];
303 e->iqid = sc->sge.fwq.abs_id;
304 e->state = L2T_STATE_SWITCHING;
305 e->vlan = vlan;
306 e->hw_port = port;
307 memcpy(e->dmac, eth_addr, ETHER_ADDR_LEN);
308 atomic_store_rel_int(&e->refcnt, 1);
309 atomic_subtract_int(&d->nfree, 1);
311 mtx_unlock(&e->lock);
315 MPASS(e->vlan == vlan);
316 MPASS(e->hw_port == port);
317 atomic_add_int(&e->refcnt, 1);
320 rw_wunlock(&d->lock);
330 l2t_size = sc->vres.l2t.size;
339 d->l2t_size = l2t_size;
340 d->l2t_stopped = false;
341 d->rover = d->l2tab;
342 atomic_store_rel_int(&d->nfree, l2t_size);
343 rw_init(&d->lock, "L2T");
346 struct l2t_entry *e = &d->l2tab[i];
348 e->idx = i;
349 e->state = L2T_STATE_UNUSED;
350 mtx_init(&e->lock, "L2T_E", NULL, MTX_DEF);
351 STAILQ_INIT(&e->wr_list);
352 atomic_store_rel_int(&e->refcnt, 0);
355 sc->l2t = d;
363 struct l2t_data *d = sc->l2t;
366 for (i = 0; i < d->l2t_size; i++)
367 mtx_destroy(&d->l2tab[i].lock);
368 rw_destroy(&d->lock);
377 struct l2t_data *d = sc->l2t;
381 rw_wlock(&d->lock);
382 d->l2t_stopped = true;
383 rw_wunlock(&d->lock);
391 struct l2t_data *d = sc->l2t;
395 rw_wlock(&d->lock);
396 d->l2t_stopped = false;
397 rw_wunlock(&d->lock);
406 struct adapter *sc = iq->adapter;
411 MPASS(iq->abs_id == G_TID_QID(GET_TID(rpl)));
413 if (__predict_false(hwidx < sc->vres.l2t.start) ||
414 __predict_false(hwidx >= sc->vres.l2t.start + sc->vres.l2t.size) ||
415 __predict_false(rpl->status != CPL_ERR_NONE)) {
417 __func__, hwidx, rpl->status, sync, sc->vres.l2t.start,
418 sc->vres.l2t.size);
428 return e->vlan >> 13;
434 switch (e->state) {
435 case L2T_STATE_VALID: return 'V'; /* valid, fast-path entry */
438 case L2T_STATE_RESOLVING: return STAILQ_EMPTY(&e->wr_list) ? 'R' : 'A';
449 struct l2t_data *l2t = sc->l2t;
466 e = &l2t->l2tab[0];
467 for (i = 0; i < l2t->l2t_size; i++, e++) {
468 mtx_lock(&e->lock);
469 if (e->state == L2T_STATE_UNUSED)
474 "Ethernet address VLAN/P LP State Users Port");
477 if (e->state >= L2T_STATE_SWITCHING)
480 inet_ntop(e->ipv6 ? AF_INET6 : AF_INET, &e->addr[0],
487 sbuf_printf(sb, "\n%4u %-15s %02x:%02x:%02x:%02x:%02x:%02x %4d"
489 e->idx, ip, e->dmac[0], e->dmac[1], e->dmac[2],
490 e->dmac[3], e->dmac[4], e->dmac[5],
491 e->vlan & 0xfff, vlan_prio(e), e->hw_port,
492 l2e_state(e), atomic_load_acq_int(&e->refcnt),
493 e->ifp ? if_name(e->ifp) : "-");
495 mtx_unlock(&e->lock);