2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2012-2021 Chelsio Communications, Inc.
6 * Written by: Navdeep Parhar <np@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
32 #include "opt_inet6.h"
34 #include <sys/types.h>
36 #include <sys/eventhandler.h>
37 #include <sys/malloc.h>
38 #include <sys/rmlock.h>
40 #include <sys/socket.h>
41 #include <sys/taskqueue.h>
43 #include <net/if_var.h>
44 #include <netinet/in.h>
45 #include <netinet6/in6_var.h>
46 #include <netinet6/scope6_var.h>
48 #include "common/common.h"
52 * Code to deal with the Compressed Local IPv6 (CLIP) table in the ASIC.
54 * The driver maintains a global CLIP database (clip_db) of IPv6 addresses and a
55 * per-adapter CLIP table (sc->clip_table) with entries that point to an IPv6 in
56 * the clip_db. All access is protected by a single global lock (clip_db_lock).
57 * The correct lock order is clip lock before synchronized op.
59 * By default (hw.cxgbe.clip_db_auto=1) all local IPv6 addresses are added to
60 * the db. Addresses are also added on-demand when the driver allocates an
61 * entry for a filter, TOE tid, etc. krn_ref counts the number of times an
62 * address appears in the system. adp_ref counts the number of adapters that
63 * have that address in their CLIP table. If both are 0 then the entry is
64 * evicted from the db. Consumers of the CLIP table entry (filters, TOE tids)
65 * are tracked in ce->refcount. Driver ioctls let external consumers add/remove
66 * addresses from the CLIP table.
70 struct clip_db_entry {
71 LIST_ENTRY(clip_db_entry) link; /* clip_db hash linkage */
73 u_int krn_ref; /* # of times this IP6 appears in list of all IP6 */
74 u_int adp_ref; /* # of adapters with this IP6 in their CLIP */
75 u_int tmp_ref; /* Used only during refresh */
79 LIST_ENTRY(clip_entry) link; /* clip_table hash linkage */
80 TAILQ_ENTRY(clip_entry) plink; /* clip_pending linkage */
81 struct clip_db_entry *cde;
82 int16_t clip_idx; /* index in the hw table */
83 bool pending; /* in clip_pending list */
87 static eventhandler_tag ifaddr_evhandler;
88 static struct mtx clip_db_lock;
89 static LIST_HEAD(, clip_db_entry) *clip_db;
90 static u_long clip_db_mask;
91 static int clip_db_gen;
92 static struct task clip_db_task;
94 static int add_lip(struct adapter *, struct in6_addr *, int16_t *);
95 static int del_lip(struct adapter *, struct in6_addr *);
96 static void t4_clip_db_task(void *, int);
97 static void t4_clip_task(void *, int);
98 static void update_clip_db(void);
99 static int update_sw_clip_table(struct adapter *);
100 static int update_hw_clip_table(struct adapter *);
101 static void update_clip_table(struct adapter *, void *);
102 static int sysctl_clip_db(SYSCTL_HANDLER_ARGS);
103 static int sysctl_clip_db_auto(SYSCTL_HANDLER_ARGS);
104 static struct clip_db_entry *lookup_clip_db_entry(struct in6_addr *, bool);
105 static struct clip_entry *lookup_clip_entry(struct adapter *, struct in6_addr *,
108 SYSCTL_PROC(_hw_cxgbe, OID_AUTO, clip_db, CTLTYPE_STRING | CTLFLAG_RD |
109 CTLFLAG_SKIP | CTLFLAG_MPSAFE, NULL, 0, sysctl_clip_db, "A",
112 int t4_clip_db_auto = 1;
113 SYSCTL_PROC(_hw_cxgbe, OID_AUTO, clip_db_auto, CTLTYPE_INT | CTLFLAG_RWTUN |
114 CTLFLAG_MPSAFE, NULL, 0, sysctl_clip_db_auto, "I",
115 "Add local IPs to CLIP db automatically (0 = no, 1 = yes)");
117 static inline uint32_t
118 clip_hashfn(struct in6_addr *addr)
120 return (fnv_32_buf(addr, sizeof(*addr), FNV1_32_INIT) & clip_db_mask);
123 static inline struct clip_db_entry *
124 alloc_clip_db_entry(struct in6_addr *in6)
126 struct clip_db_entry *cde;
128 cde = malloc(sizeof(*cde), M_CXGBE, M_NOWAIT | M_ZERO);
129 if (__predict_true(cde != NULL))
130 memcpy(&cde->lip, in6, sizeof(cde->lip));
135 static inline struct clip_entry *
136 alloc_clip_entry(struct clip_db_entry *cde)
138 struct clip_entry *ce;
140 mtx_assert(&clip_db_lock, MA_OWNED);
142 ce = malloc(sizeof(*ce), M_CXGBE, M_NOWAIT | M_ZERO);
143 if (__predict_true(ce != NULL)) {
153 * Look up the IP6 address in the CLIP db. If add is set then an entry for the
154 * IP6 will be added to the db.
156 static struct clip_db_entry *
157 lookup_clip_db_entry(struct in6_addr *in6, bool add)
159 struct clip_db_entry *cde;
160 const int bucket = clip_hashfn(in6);
162 mtx_assert(&clip_db_lock, MA_OWNED);
164 LIST_FOREACH(cde, &clip_db[bucket], link) {
165 if (IN6_ARE_ADDR_EQUAL(&cde->lip, in6))
169 /* Not found. Create a new entry if requested. */
171 cde = alloc_clip_db_entry(in6);
173 LIST_INSERT_HEAD(&clip_db[bucket], cde, link);
180 * Look up the IP6 address in the CLIP db. If add is set then an entry for the
181 * IP6 will be added to the db.
183 static struct clip_entry *
184 lookup_clip_entry(struct adapter *sc, struct in6_addr *in6, bool add)
186 struct clip_db_entry *cde;
187 struct clip_entry *ce;
188 const int bucket = clip_hashfn(in6);
190 mtx_assert(&clip_db_lock, MA_OWNED);
192 cde = lookup_clip_db_entry(in6, add);
196 LIST_FOREACH(ce, &sc->clip_table[bucket], link) {
201 /* Not found. Create a new entry if requested. */
203 ce = alloc_clip_entry(cde);
205 LIST_INSERT_HEAD(&sc->clip_table[bucket], ce, link);
206 TAILQ_INSERT_TAIL(&sc->clip_pending, ce, plink);
215 add_lip(struct adapter *sc, struct in6_addr *lip, int16_t *idx)
217 struct fw_clip_cmd c;
220 ASSERT_SYNCHRONIZED_OP(sc);
222 memset(&c, 0, sizeof(c));
223 c.op_to_write = htonl(V_FW_CMD_OP(FW_CLIP_CMD) | F_FW_CMD_REQUEST |
225 c.alloc_to_len16 = htonl(F_FW_CLIP_CMD_ALLOC | FW_LEN16(c));
226 c.ip_hi = *(uint64_t *)&lip->s6_addr[0];
227 c.ip_lo = *(uint64_t *)&lip->s6_addr[8];
229 rc = -t4_wr_mbox_ns(sc, sc->mbox, &c, sizeof(c), &c);
230 if (rc == 0 && idx != NULL)
231 *idx = G_FW_CLIP_CMD_INDEX(ntohl(c.alloc_to_len16));
236 del_lip(struct adapter *sc, struct in6_addr *lip)
238 struct fw_clip_cmd c;
240 ASSERT_SYNCHRONIZED_OP(sc);
242 memset(&c, 0, sizeof(c));
243 c.op_to_write = htonl(V_FW_CMD_OP(FW_CLIP_CMD) | F_FW_CMD_REQUEST |
245 c.alloc_to_len16 = htonl(F_FW_CLIP_CMD_FREE | FW_LEN16(c));
246 c.ip_hi = *(uint64_t *)&lip->s6_addr[0];
247 c.ip_lo = *(uint64_t *)&lip->s6_addr[8];
249 return (-t4_wr_mbox_ns(sc, sc->mbox, &c, sizeof(c), &c));
254 t4_get_clip_entry(struct adapter *sc, struct in6_addr *in6, bool add)
257 struct clip_entry *ce;
258 bool schedule = false;
260 mtx_lock(&clip_db_lock);
261 ce = lookup_clip_entry(sc, in6, add);
263 MPASS(ce->cde->adp_ref > 0);
264 if (++ce->refcount == 1 && ce->pending && ce->clip_idx != -1) {
266 * Valid entry that was waiting to be deleted. It is in
267 * use now so take it off the pending list.
269 TAILQ_REMOVE(&sc->clip_pending, ce, plink);
272 if (ce->clip_idx == -1 && update_hw_clip_table(sc) != 0)
275 mtx_unlock(&clip_db_lock);
277 taskqueue_enqueue_timeout(taskqueue_thread, &sc->clip_task, 0);
286 t4_hold_clip_entry(struct adapter *sc, struct clip_entry *ce)
290 MPASS(ce->cde->adp_ref > 0);
292 mtx_lock(&clip_db_lock);
293 MPASS(ce->refcount > 0); /* Caller should already have a reference */
295 mtx_unlock(&clip_db_lock);
301 release_clip_entry_locked(struct adapter *sc, struct clip_entry *ce)
303 struct clip_db_entry *cde;
305 mtx_assert(&clip_db_lock, MA_OWNED);
306 MPASS(ce->refcount > 0);
308 MPASS(cde->adp_ref > 0);
309 if (--ce->refcount == 0 && cde->krn_ref == 0) {
310 if (ce->clip_idx == -1) {
311 /* Was never written to the hardware. */
313 TAILQ_REMOVE(&sc->clip_pending, ce, plink);
314 LIST_REMOVE(ce, link);
316 if (--cde->adp_ref == 0) {
317 LIST_REMOVE(cde, link);
322 * Valid entry is now unused, add to the pending list
323 * for deletion. Its refcount was 1 on entry so it
324 * can't already be pending.
327 TAILQ_INSERT_HEAD(&sc->clip_pending, ce, plink);
335 t4_release_clip_entry(struct adapter *sc, struct clip_entry *ce)
340 mtx_lock(&clip_db_lock);
341 release_clip_entry_locked(sc, ce);
343 * This isn't a manual release via the ioctl. No need to update the
344 * hw right now even if the release resulted in the entry being queued
347 mtx_unlock(&clip_db_lock);
352 t4_release_clip_addr(struct adapter *sc, struct in6_addr *in6)
356 struct clip_entry *ce;
357 bool schedule = false;
359 mtx_lock(&clip_db_lock);
360 ce = lookup_clip_entry(sc, in6, false);
363 else if (ce->refcount == 0)
366 release_clip_entry_locked(sc, ce);
367 if (update_hw_clip_table(sc) != 0)
371 mtx_unlock(&clip_db_lock);
373 taskqueue_enqueue_timeout(taskqueue_thread, &sc->clip_task, 0);
380 t4_init_clip_table(struct adapter *sc)
382 TAILQ_INIT(&sc->clip_pending);
383 TIMEOUT_TASK_INIT(taskqueue_thread, &sc->clip_task, 0, t4_clip_task, sc);
385 sc->clip_table = hashinit(CLIP_HASH_SIZE, M_CXGBE, &sc->clip_mask);
387 /* Both the hashes must use the same bucket for the same key. */
388 if (sc->clip_table != NULL)
389 MPASS(sc->clip_mask == clip_db_mask);
391 * Don't bother forcing an update of the clip table when the
392 * adapter is initialized. Before an interface can be used it
393 * must be assigned an address which will trigger the event
394 * handler to update the table.
399 * Returns true if any additions or deletions were made to the CLIP DB.
404 VNET_ITERATOR_DECL(vnet_iter);
405 struct rm_priotracker in6_ifa_tracker;
406 struct in6_addr *in6, tin6;
407 struct in6_ifaddr *ia;
408 struct clip_db_entry *cde, *cde_tmp;
412 IN6_IFADDR_RLOCK(&in6_ifa_tracker);
413 mtx_lock(&clip_db_lock);
414 VNET_FOREACH(vnet_iter) {
415 CURVNET_SET_QUIET(vnet_iter);
416 CK_STAILQ_FOREACH(ia, &V_in6_ifaddrhead, ia_link) {
417 if (if_getflags(ia->ia_ifp) & IFF_LOOPBACK)
419 in6 = &ia->ia_addr.sin6_addr;
420 KASSERT(!IN6_IS_ADDR_MULTICAST(in6),
421 ("%s: mcast address in in6_ifaddr list", __func__));
422 if (IN6_IS_ADDR_LOOPBACK(in6))
425 if (IN6_IS_SCOPE_EMBED(in6)) {
430 cde = lookup_clip_db_entry(in6, true);
439 for (i = 0; i <= clip_db_mask; i++) {
440 LIST_FOREACH_SAFE(cde, &clip_db[i], link, cde_tmp) {
441 if (cde->krn_ref == 0 && cde->tmp_ref > 0) {
442 addel++; /* IP6 addr added. */
443 } else if (cde->krn_ref > 0 && cde->tmp_ref == 0) {
444 if (cde->adp_ref == 0) {
445 LIST_REMOVE(cde, link);
449 addel++; /* IP6 addr deleted. */
451 cde->krn_ref = cde->tmp_ref;
457 mtx_unlock(&clip_db_lock);
458 IN6_IFADDR_RUNLOCK(&in6_ifa_tracker);
464 * Update the CLIP db and then update the CLIP tables on all the adapters.
467 t4_clip_db_task(void *arg, int count)
470 t4_iterate(update_clip_table, NULL);
474 * Refresh the sw CLIP table for this adapter from the global CLIP db. Entries
475 * that need to be added or deleted from the hardware CLIP table are placed on a
476 * pending list but the hardware is not touched. The pending list is something
477 * reasonable even if this fails so it's ok to apply that to the hardware.
480 update_sw_clip_table(struct adapter *sc)
482 struct clip_db_entry *cde;
483 struct clip_entry *ce, *ce_temp;
487 mtx_assert(&clip_db_lock, MA_OWNED);
490 * We are about to rebuild the pending list from scratch. Deletions are
491 * placed before additions because that's how we want to submit them to
494 TAILQ_INIT(&sc->clip_pending);
497 * Walk the sw CLIP table first. We want to reset every entry's pending
498 * status as we're rebuilding the pending list.
500 for (i = 0; i <= clip_db_mask; i++) {
501 LIST_FOREACH_SAFE(ce, &sc->clip_table[i], link, ce_temp) {
503 MPASS(cde->adp_ref > 0);
504 if (ce->refcount != 0 || cde->krn_ref != 0) {
506 * Entry should stay in the CLIP.
509 if (ce->clip_idx != -1) {
512 /* Was never added, carry forward. */
514 TAILQ_INSERT_TAIL(&sc->clip_pending, ce,
521 * Entry should be removed from the CLIP.
524 if (ce->clip_idx != -1) {
526 TAILQ_INSERT_HEAD(&sc->clip_pending, ce, plink);
528 /* Was never added, free right now. */
530 LIST_REMOVE(ce, link);
532 if (--cde->adp_ref == 0) {
533 LIST_REMOVE(cde, link);
540 for (i = 0; i <= clip_db_mask; i++) {
541 LIST_FOREACH(cde, &clip_db[i], link) {
542 if (cde->krn_ref == 0)
546 LIST_FOREACH(ce, &sc->clip_table[i], link) {
547 if (ce->cde == cde) {
554 ce = alloc_clip_entry(cde);
557 LIST_INSERT_HEAD(&sc->clip_table[i], ce, link);
558 TAILQ_INSERT_TAIL(&sc->clip_pending, ce, plink);
563 sc->clip_gen = clip_db_gen;
568 update_hw_clip_table(struct adapter *sc)
570 struct clip_db_entry *cde;
571 struct clip_entry *ce;
573 char ip[INET6_ADDRSTRLEN];
575 mtx_assert(&clip_db_lock, MA_OWNED);
576 rc = begin_synchronized_op(sc, NULL, HOLD_LOCK, "t4clip");
579 if (hw_off_limits(sc))
580 goto done; /* with rc = 0, we don't want to reschedule. */
581 while (!TAILQ_EMPTY(&sc->clip_pending)) {
582 ce = TAILQ_FIRST(&sc->clip_pending);
585 MPASS(cde->adp_ref > 0);
587 if (ce->clip_idx == -1) {
589 * Entry was queued for addition to the HW CLIP.
592 if (ce->refcount == 0 && cde->krn_ref == 0) {
593 /* No need to add to HW CLIP. */
594 TAILQ_REMOVE(&sc->clip_pending, ce, plink);
595 LIST_REMOVE(ce, link);
597 if (--cde->adp_ref == 0) {
598 LIST_REMOVE(cde, link);
602 /* Add to the HW CLIP. */
603 rc = add_lip(sc, &cde->lip, &ce->clip_idx);
604 if (rc == FW_ENOMEM) {
605 /* CLIP full, no point in retrying. */
610 inet_ntop(AF_INET6, &cde->lip, &ip[0],
612 CH_ERR(sc, "add_lip(%s) failed: %d\n",
616 MPASS(ce->clip_idx != -1);
617 TAILQ_REMOVE(&sc->clip_pending, ce, plink);
622 * Entry was queued for deletion from the HW CLIP.
625 if (ce->refcount == 0 && cde->krn_ref == 0) {
627 * Delete from the HW CLIP. Delete should never
628 * fail so we always log an error. But if the
629 * failure is that the entry wasn't found in the
630 * CLIP then we carry on as if it was deleted.
632 rc = del_lip(sc, &cde->lip);
634 CH_ERR(sc, "del_lip(%s) failed: %d\n",
641 TAILQ_REMOVE(&sc->clip_pending, ce, plink);
642 LIST_REMOVE(ce, link);
644 if (--cde->adp_ref == 0) {
645 LIST_REMOVE(cde, link);
649 /* No need to delete from HW CLIP. */
650 TAILQ_REMOVE(&sc->clip_pending, ce, plink);
656 end_synchronized_op(sc, LOCK_HELD);
661 update_clip_table(struct adapter *sc, void *arg __unused)
665 if (sc->clip_table == NULL)
669 mtx_lock(&clip_db_lock);
670 if (sc->clip_gen != clip_db_gen && update_sw_clip_table(sc) != 0)
672 if (!TAILQ_EMPTY(&sc->clip_pending) && update_hw_clip_table(sc) != 0)
674 mtx_unlock(&clip_db_lock);
676 taskqueue_enqueue_timeout(taskqueue_thread, &sc->clip_task,
681 * Update the CLIP table of the specified adapter.
684 t4_clip_task(void *sc, int count)
686 update_clip_table(sc, NULL);
690 t4_destroy_clip_table(struct adapter *sc)
692 struct clip_entry *ce, *ce_temp;
695 mtx_lock(&clip_db_lock);
696 if (sc->clip_table == NULL)
697 goto done; /* CLIP was never initialized. */
698 for (i = 0; i <= sc->clip_mask; i++) {
699 LIST_FOREACH_SAFE(ce, &sc->clip_table[i], link, ce_temp) {
700 MPASS(ce->refcount == 0);
701 MPASS(ce->cde->adp_ref > 0);
703 del_lip(sc, &ce->lip);
705 LIST_REMOVE(ce, link);
706 if (--ce->cde->adp_ref == 0 && ce->cde->krn_ref == 0) {
707 LIST_REMOVE(ce->cde, link);
708 free(ce->cde, M_CXGBE);
713 hashdestroy(sc->clip_table, M_CXGBE, sc->clip_mask);
714 sc->clip_table = NULL;
716 mtx_unlock(&clip_db_lock);
720 t4_ifaddr_event(void *arg __unused, if_t ifp, struct ifaddr *ifa,
723 struct in6_addr *in6;
725 if (t4_clip_db_auto == 0)
726 return; /* Automatic updates not allowed. */
727 if (ifa->ifa_addr->sa_family != AF_INET6)
729 if (if_getflags(ifp) & IFF_LOOPBACK)
731 in6 = &((struct in6_ifaddr *)ifa)->ia_addr.sin6_addr;
732 if (IN6_IS_ADDR_LOOPBACK(in6) || IN6_IS_ADDR_MULTICAST(in6))
735 taskqueue_enqueue(taskqueue_thread, &clip_db_task);
739 sysctl_clip(SYSCTL_HANDLER_ARGS)
741 struct adapter *sc = arg1;
742 struct clip_entry *ce;
744 int i, rc, header = 0;
745 char ip[INET6_ADDRSTRLEN];
747 rc = sysctl_wire_old_buffer(req, 0);
751 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
755 mtx_lock(&clip_db_lock);
756 for (i = 0; i <= sc->clip_mask; i++) {
757 LIST_FOREACH(ce, &sc->clip_table[i], link) {
759 sbuf_printf(sb, "%-4s %-4s %s", "Indx", "Refs",
763 inet_ntop(AF_INET6, &ce->cde->lip, &ip[0], sizeof(ip));
764 if (ce->clip_idx == -1) {
765 sbuf_printf(sb, "\n%-4s %-4d %s", "-",
768 sbuf_printf(sb, "\n%-4d %-4d %s", ce->clip_idx,
773 mtx_unlock(&clip_db_lock);
775 rc = sbuf_finish(sb);
782 sysctl_clip_db(SYSCTL_HANDLER_ARGS)
784 struct clip_db_entry *cde;
786 int i, rc, header = 0;
787 char ip[INET6_ADDRSTRLEN];
789 rc = sysctl_wire_old_buffer(req, 0);
793 sb = sbuf_new_for_sysctl(NULL, NULL, 4096, req);
797 mtx_lock(&clip_db_lock);
798 for (i = 0; i <= clip_db_mask; i++) {
799 LIST_FOREACH(cde, &clip_db[i], link) {
800 MPASS(cde->tmp_ref == 0);
802 sbuf_printf(sb, "%-4s %-4s %s", "Kref", "Aref",
806 inet_ntop(AF_INET6, &cde->lip, &ip[0], sizeof(ip));
807 sbuf_printf(sb, "\n%-4d %-4d %s", cde->krn_ref,
811 mtx_unlock(&clip_db_lock);
813 rc = sbuf_finish(sb);
820 sysctl_clip_db_auto(SYSCTL_HANDLER_ARGS)
824 val = t4_clip_db_auto;
825 rc = sysctl_handle_int(oidp, &val, 0, req);
826 if (rc != 0 || req->newptr == NULL)
829 if (val == 0 || val == 1)
830 t4_clip_db_auto = val;
833 * Writing a value other than 0 or 1 forces a one-time update of
834 * the clip_db directly in the sysctl and not in some taskqueue.
836 t4_clip_db_task(NULL, 0);
843 t4_clip_modload(void)
845 mtx_init(&clip_db_lock, "clip_db", NULL, MTX_DEF);
846 clip_db = hashinit(CLIP_HASH_SIZE, M_CXGBE, &clip_db_mask);
847 TASK_INIT(&clip_db_task, 0, t4_clip_db_task, NULL);
848 ifaddr_evhandler = EVENTHANDLER_REGISTER(ifaddr_event_ext,
849 t4_ifaddr_event, NULL, EVENTHANDLER_PRI_ANY);
853 t4_clip_modunload(void)
855 struct clip_db_entry *cde;
858 EVENTHANDLER_DEREGISTER(ifaddr_event_ext, ifaddr_evhandler);
859 taskqueue_drain(taskqueue_thread, &clip_db_task);
860 mtx_lock(&clip_db_lock);
861 for (i = 0; i <= clip_db_mask; i++) {
862 while ((cde = LIST_FIRST(&clip_db[i])) != NULL) {
863 MPASS(cde->tmp_ref == 0);
864 MPASS(cde->adp_ref == 0);
865 LIST_REMOVE(cde, link);
869 mtx_unlock(&clip_db_lock);
870 hashdestroy(clip_db, M_CXGBE, clip_db_mask);
871 mtx_destroy(&clip_db_lock);