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()
182 switch (e->state) { in t3_l2t_send_event()
184 neigh_event_send(e->neigh, NULL); in t3_l2t_send_event()
185 spin_lock_bh(&e->lock); in t3_l2t_send_event()
186 if (e->state == L2T_STATE_STALE) { in t3_l2t_send_event()
187 e->state = L2T_STATE_VALID; in t3_l2t_send_event()
189 spin_unlock_bh(&e->lock); in t3_l2t_send_event()
191 case L2T_STATE_VALID: /* fast-path, send the packet on */ in t3_l2t_send_event()
194 spin_lock_bh(&e->lock); in t3_l2t_send_event()
195 if (e->state != L2T_STATE_RESOLVING) { in t3_l2t_send_event()
197 spin_unlock_bh(&e->lock); in t3_l2t_send_event()
200 spin_unlock_bh(&e->lock); in t3_l2t_send_event()
210 neigh_event_send(e->neigh, NULL); in t3_l2t_send_event()
217 * Allocate a free L2T entry. Must be called with l2t_data.lock held.
223 if (!atomic_read(&d->nfree)) in alloc_l2e()
227 for (e = d->rover, end = &d->l2tab[d->nentries]; e != end; ++e) in alloc_l2e()
228 if (atomic_read(&e->refcnt) == 0) in alloc_l2e()
231 for (e = &d->l2tab[1]; atomic_read(&e->refcnt); ++e) ; in alloc_l2e()
233 d->rover = e + 1; in alloc_l2e()
234 atomic_dec(&d->nfree); in alloc_l2e()
240 if (e->state != L2T_STATE_UNUSED) { in alloc_l2e()
241 int hash = arp_hash(e->addr, e->ifindex, d); in alloc_l2e()
243 for (p = &d->l2tab[hash].first; *p; p = &(*p)->next) in alloc_l2e()
245 *p = e->next; in alloc_l2e()
248 e->state = L2T_STATE_UNUSED; in alloc_l2e()
261 * drops to 0 we need to take the entry's lock to avoid races with a new
266 spin_lock_bh(&e->lock); in t3_l2e_free()
267 if (atomic_read(&e->refcnt) == 0) { /* hasn't been recycled */ in t3_l2e_free()
268 if (e->neigh) { in t3_l2e_free()
269 neigh_release(e->neigh); in t3_l2e_free()
270 e->neigh = NULL; in t3_l2e_free()
273 spin_unlock_bh(&e->lock); in t3_l2e_free()
274 atomic_inc(&d->nfree); in t3_l2e_free()
287 spin_lock(&e->lock); /* avoid race with t3_l2t_free */ in reuse_entry()
289 if (neigh != e->neigh) in reuse_entry()
291 nud_state = neigh->nud_state; in reuse_entry()
292 if (memcmp(e->dmac, neigh->ha, sizeof(e->dmac)) || in reuse_entry()
294 e->state = L2T_STATE_RESOLVING; in reuse_entry()
296 e->state = L2T_STATE_VALID; in reuse_entry()
298 e->state = L2T_STATE_STALE; in reuse_entry()
299 spin_unlock(&e->lock); in reuse_entry()
319 addr = *(u32 *) neigh->primary_key; in t3_l2t_get()
320 ifidx = neigh->dev->ifindex; in t3_l2t_get()
323 dev = neigh->dev; in t3_l2t_get()
325 smt_idx = p->port_id; in t3_l2t_get()
333 write_lock_bh(&d->lock); in t3_l2t_get()
334 for (e = d->l2tab[hash].first; e; e = e->next) in t3_l2t_get()
335 if (e->addr == addr && e->ifindex == ifidx && in t3_l2t_get()
336 e->smt_idx == smt_idx) { in t3_l2t_get()
338 if (atomic_read(&e->refcnt) == 1) in t3_l2t_get()
346 spin_lock(&e->lock); /* avoid race with t3_l2t_free */ in t3_l2t_get()
347 e->next = d->l2tab[hash].first; in t3_l2t_get()
348 d->l2tab[hash].first = e; in t3_l2t_get()
349 e->state = L2T_STATE_RESOLVING; in t3_l2t_get()
350 e->addr = addr; in t3_l2t_get()
351 e->ifindex = ifidx; in t3_l2t_get()
352 e->smt_idx = smt_idx; in t3_l2t_get()
353 atomic_set(&e->refcnt, 1); in t3_l2t_get()
355 if (is_vlan_dev(neigh->dev)) in t3_l2t_get()
356 e->vlan = vlan_dev_vlan_id(neigh->dev); in t3_l2t_get()
358 e->vlan = VLAN_NONE; in t3_l2t_get()
359 spin_unlock(&e->lock); in t3_l2t_get()
362 write_unlock_bh(&d->lock); in t3_l2t_get()
388 if (cb->arp_failure_handler) in handle_failed_resolution()
389 cb->arp_failure_handler(dev, skb); in handle_failed_resolution()
404 u32 addr = *(u32 *) neigh->primary_key; in t3_l2t_update()
405 int ifidx = neigh->dev->ifindex; in t3_l2t_update()
408 read_lock_bh(&d->lock); in t3_l2t_update()
409 for (e = d->l2tab[hash].first; e; e = e->next) in t3_l2t_update()
410 if (e->addr == addr && e->ifindex == ifidx) { in t3_l2t_update()
411 spin_lock(&e->lock); in t3_l2t_update()
414 read_unlock_bh(&d->lock); in t3_l2t_update()
420 read_unlock(&d->lock); in t3_l2t_update()
421 if (atomic_read(&e->refcnt)) { in t3_l2t_update()
422 if (neigh != e->neigh) in t3_l2t_update()
425 if (e->state == L2T_STATE_RESOLVING) { in t3_l2t_update()
426 if (neigh->nud_state & NUD_FAILED) { in t3_l2t_update()
427 skb_queue_splice_init(&e->arpq, &arpq); in t3_l2t_update()
428 } else if (neigh->nud_state & (NUD_CONNECTED|NUD_STALE)) in t3_l2t_update()
431 e->state = neigh->nud_state & NUD_CONNECTED ? in t3_l2t_update()
433 if (!ether_addr_equal(e->dmac, neigh->ha)) in t3_l2t_update()
437 spin_unlock_bh(&e->lock); in t3_l2t_update()
452 d->nentries = l2t_capacity; in t3_init_l2t()
453 d->rover = &d->l2tab[1]; /* entry 0 is not used */ in t3_init_l2t()
454 atomic_set(&d->nfree, l2t_capacity - 1); in t3_init_l2t()
455 rwlock_init(&d->lock); in t3_init_l2t()
458 d->l2tab[i].idx = i; in t3_init_l2t()
459 d->l2tab[i].state = L2T_STATE_UNUSED; in t3_init_l2t()
460 __skb_queue_head_init(&d->l2tab[i].arpq); in t3_init_l2t()
461 spin_lock_init(&d->l2tab[i].lock); in t3_init_l2t()
462 atomic_set(&d->l2tab[i].refcnt, 0); in t3_init_l2t()