cf40c8a8a45d27a91437623e8263d51a83959f4c
[dpdk.git] / drivers / net / cxgbe / smt.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Chelsio Communications.
3  * All rights reserved.
4  */
5
6 #include "base/common.h"
7 #include "smt.h"
8
9 /**
10  * Initialize Source MAC Table
11  */
12 struct smt_data *t4_init_smt(u32 smt_start_idx, u32 smt_size)
13 {
14         struct smt_data *s;
15         u32 i;
16
17         s = t4_alloc_mem(sizeof(*s) + smt_size * sizeof(struct smt_entry));
18         if (!s)
19                 return NULL;
20
21         s->smt_start = smt_start_idx;
22         s->smt_size = smt_size;
23         t4_os_rwlock_init(&s->lock);
24
25         for (i = 0; i < s->smt_size; ++i) {
26                 s->smtab[i].idx = i;
27                 s->smtab[i].hw_idx = smt_start_idx + i;
28                 s->smtab[i].state = SMT_STATE_UNUSED;
29                 memset(&s->smtab[i].src_mac, 0, RTE_ETHER_ADDR_LEN);
30                 t4_os_lock_init(&s->smtab[i].lock);
31                 rte_atomic32_set(&s->smtab[i].refcnt, 0);
32         }
33         return s;
34 }
35
36 /**
37  * Cleanup Source MAC Table
38  */
39 void t4_cleanup_smt(struct adapter *adap)
40 {
41         if (adap->smt)
42                 t4_os_free(adap->smt);
43 }