Lines Matching +full:lock +full:- +full:state
2 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
14 * - Redistributions of source code must retain the above
18 * - Redistributions in binary form must reproduce the above
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
65 return e->vlan >> 13; in vlan_prio()
71 return jhash_2words(key, ifindex, 0) & (d->nentries - 1); in arp_hash()
77 if (e->neigh) in neigh_replace()
78 neigh_release(e->neigh); in neigh_replace()
79 e->neigh = n; in neigh_replace()
96 return -ENOMEM; in setup_l2e_send_pending()
100 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); in setup_l2e_send_pending()
101 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_L2T_WRITE_REQ, e->idx)); in setup_l2e_send_pending()
102 req->params = htonl(V_L2T_W_IDX(e->idx) | V_L2T_W_IFF(e->smt_idx) | in setup_l2e_send_pending()
103 V_L2T_W_VLAN(e->vlan & VLAN_VID_MASK) | in setup_l2e_send_pending()
105 memcpy(e->dmac, e->neigh->ha, sizeof(e->dmac)); in setup_l2e_send_pending()
106 memcpy(req->dst_mac, e->dmac, sizeof(req->dst_mac)); in setup_l2e_send_pending()
107 skb->priority = CPL_PRIORITY_CONTROL; in setup_l2e_send_pending()
110 skb_queue_walk_safe(&e->arpq, skb, tmp) { in setup_l2e_send_pending()
111 __skb_unlink(skb, &e->arpq); in setup_l2e_send_pending()
114 e->state = L2T_STATE_VALID; in setup_l2e_send_pending()
121 * Must be called with the entry's lock held.
125 __skb_queue_tail(&e->arpq, skb); in arpq_enqueue()
132 switch (e->state) { in t3_l2t_send_slow()
134 neigh_event_send(e->neigh, NULL); in t3_l2t_send_slow()
135 spin_lock_bh(&e->lock); in t3_l2t_send_slow()
136 if (e->state == L2T_STATE_STALE) in t3_l2t_send_slow()
137 e->state = L2T_STATE_VALID; in t3_l2t_send_slow()
138 spin_unlock_bh(&e->lock); in t3_l2t_send_slow()
140 case L2T_STATE_VALID: /* fast-path, send the packet on */ in t3_l2t_send_slow()
143 spin_lock_bh(&e->lock); in t3_l2t_send_slow()
144 if (e->state != L2T_STATE_RESOLVING) { in t3_l2t_send_slow()
146 spin_unlock_bh(&e->lock); in t3_l2t_send_slow()
150 spin_unlock_bh(&e->lock); in t3_l2t_send_slow()
160 if (!neigh_event_send(e->neigh, NULL)) { in t3_l2t_send_slow()
166 spin_lock_bh(&e->lock); in t3_l2t_send_slow()
167 if (!skb_queue_empty(&e->arpq)) in t3_l2t_send_slow()
171 spin_unlock_bh(&e->lock); in t3_l2t_send_slow()
180 * Allocate a free L2T entry. Must be called with l2t_data.lock held.
186 if (!atomic_read(&d->nfree)) in alloc_l2e()
190 for (e = d->rover, end = &d->l2tab[d->nentries]; e != end; ++e) in alloc_l2e()
191 if (atomic_read(&e->refcnt) == 0) in alloc_l2e()
194 for (e = &d->l2tab[1]; atomic_read(&e->refcnt); ++e) ; in alloc_l2e()
196 d->rover = e + 1; in alloc_l2e()
197 atomic_dec(&d->nfree); in alloc_l2e()
203 if (e->state != L2T_STATE_UNUSED) { in alloc_l2e()
204 int hash = arp_hash(e->addr, e->ifindex, d); in alloc_l2e()
206 for (p = &d->l2tab[hash].first; *p; p = &(*p)->next) in alloc_l2e()
208 *p = e->next; in alloc_l2e()
211 e->state = L2T_STATE_UNUSED; in alloc_l2e()
224 * drops to 0 we need to take the entry's lock to avoid races with a new
229 spin_lock_bh(&e->lock); in t3_l2e_free()
230 if (atomic_read(&e->refcnt) == 0) { /* hasn't been recycled */ in t3_l2e_free()
231 if (e->neigh) { in t3_l2e_free()
232 neigh_release(e->neigh); in t3_l2e_free()
233 e->neigh = NULL; in t3_l2e_free()
236 spin_unlock_bh(&e->lock); in t3_l2e_free()
237 atomic_inc(&d->nfree); in t3_l2e_free()
250 spin_lock(&e->lock); /* avoid race with t3_l2t_free */ in reuse_entry()
252 if (neigh != e->neigh) in reuse_entry()
254 nud_state = neigh->nud_state; in reuse_entry()
255 if (memcmp(e->dmac, neigh->ha, sizeof(e->dmac)) || in reuse_entry()
257 e->state = L2T_STATE_RESOLVING; in reuse_entry()
259 e->state = L2T_STATE_VALID; in reuse_entry()
261 e->state = L2T_STATE_STALE; in reuse_entry()
262 spin_unlock(&e->lock); in reuse_entry()
282 addr = *(u32 *) neigh->primary_key; in t3_l2t_get()
283 ifidx = neigh->dev->ifindex; in t3_l2t_get()
286 dev = neigh->dev; in t3_l2t_get()
288 smt_idx = p->port_id; in t3_l2t_get()
296 write_lock_bh(&d->lock); in t3_l2t_get()
297 for (e = d->l2tab[hash].first; e; e = e->next) in t3_l2t_get()
298 if (e->addr == addr && e->ifindex == ifidx && in t3_l2t_get()
299 e->smt_idx == smt_idx) { in t3_l2t_get()
301 if (atomic_read(&e->refcnt) == 1) in t3_l2t_get()
309 spin_lock(&e->lock); /* avoid race with t3_l2t_free */ in t3_l2t_get()
310 e->next = d->l2tab[hash].first; in t3_l2t_get()
311 d->l2tab[hash].first = e; in t3_l2t_get()
312 e->state = L2T_STATE_RESOLVING; in t3_l2t_get()
313 e->addr = addr; in t3_l2t_get()
314 e->ifindex = ifidx; in t3_l2t_get()
315 e->smt_idx = smt_idx; in t3_l2t_get()
316 atomic_set(&e->refcnt, 1); in t3_l2t_get()
318 if (is_vlan_dev(neigh->dev)) in t3_l2t_get()
319 e->vlan = vlan_dev_vlan_id(neigh->dev); in t3_l2t_get()
321 e->vlan = VLAN_NONE; in t3_l2t_get()
322 spin_unlock(&e->lock); in t3_l2t_get()
325 write_unlock_bh(&d->lock); in t3_l2t_get()
351 if (cb->arp_failure_handler) in handle_failed_resolution()
352 cb->arp_failure_handler(dev, skb); in handle_failed_resolution()
367 u32 addr = *(u32 *) neigh->primary_key; in t3_l2t_update()
368 int ifidx = neigh->dev->ifindex; in t3_l2t_update()
371 read_lock_bh(&d->lock); in t3_l2t_update()
372 for (e = d->l2tab[hash].first; e; e = e->next) in t3_l2t_update()
373 if (e->addr == addr && e->ifindex == ifidx) { in t3_l2t_update()
374 spin_lock(&e->lock); in t3_l2t_update()
377 read_unlock_bh(&d->lock); in t3_l2t_update()
383 read_unlock(&d->lock); in t3_l2t_update()
384 if (atomic_read(&e->refcnt)) { in t3_l2t_update()
385 if (neigh != e->neigh) in t3_l2t_update()
388 if (e->state == L2T_STATE_RESOLVING) { in t3_l2t_update()
389 if (neigh->nud_state & NUD_FAILED) { in t3_l2t_update()
390 skb_queue_splice_init(&e->arpq, &arpq); in t3_l2t_update()
391 } else if (neigh->nud_state & (NUD_CONNECTED|NUD_STALE)) in t3_l2t_update()
394 e->state = neigh->nud_state & NUD_CONNECTED ? in t3_l2t_update()
396 if (!ether_addr_equal(e->dmac, neigh->ha)) in t3_l2t_update()
400 spin_unlock_bh(&e->lock); in t3_l2t_update()
415 d->nentries = l2t_capacity; in t3_init_l2t()
416 d->rover = &d->l2tab[1]; /* entry 0 is not used */ in t3_init_l2t()
417 atomic_set(&d->nfree, l2t_capacity - 1); in t3_init_l2t()
418 rwlock_init(&d->lock); in t3_init_l2t()
421 d->l2tab[i].idx = i; in t3_init_l2t()
422 d->l2tab[i].state = L2T_STATE_UNUSED; in t3_init_l2t()
423 __skb_queue_head_init(&d->l2tab[i].arpq); in t3_init_l2t()
424 spin_lock_init(&d->l2tab[i].lock); in t3_init_l2t()
425 atomic_set(&d->l2tab[i].refcnt, 0); in t3_init_l2t()