hc
2025-02-14 bbb9540dc49f70f6b703d1c8d1b85fa5f602d86e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// SPDX-License-Identifier: GPL-2.0+
/* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
 
#include "util.h"
#include "qtn_hw_ids.h"
 
void qtnf_sta_list_init(struct qtnf_sta_list *list)
{
   if (unlikely(!list))
       return;
 
   INIT_LIST_HEAD(&list->head);
   atomic_set(&list->size, 0);
}
 
struct qtnf_sta_node *qtnf_sta_list_lookup(struct qtnf_sta_list *list,
                      const u8 *mac)
{
   struct qtnf_sta_node *node;
 
   if (unlikely(!mac))
       return NULL;
 
   list_for_each_entry(node, &list->head, list) {
       if (ether_addr_equal(node->mac_addr, mac))
           return node;
   }
 
   return NULL;
}
 
struct qtnf_sta_node *qtnf_sta_list_lookup_index(struct qtnf_sta_list *list,
                        size_t index)
{
   struct qtnf_sta_node *node;
 
   if (qtnf_sta_list_size(list) <= index)
       return NULL;
 
   list_for_each_entry(node, &list->head, list) {
       if (index-- == 0)
           return node;
   }
 
   return NULL;
}
 
struct qtnf_sta_node *qtnf_sta_list_add(struct qtnf_vif *vif,
                   const u8 *mac)
{
   struct qtnf_sta_list *list = &vif->sta_list;
   struct qtnf_sta_node *node;
 
   if (unlikely(!mac))
       return NULL;
 
   node = qtnf_sta_list_lookup(list, mac);
 
   if (node)
       goto done;
 
   node = kzalloc(sizeof(*node), GFP_KERNEL);
   if (unlikely(!node))
       goto done;
 
   ether_addr_copy(node->mac_addr, mac);
   list_add_tail(&node->list, &list->head);
   atomic_inc(&list->size);
   ++vif->generation;
 
done:
   return node;
}
 
bool qtnf_sta_list_del(struct qtnf_vif *vif, const u8 *mac)
{
   struct qtnf_sta_list *list = &vif->sta_list;
   struct qtnf_sta_node *node;
   bool ret = false;
 
   node = qtnf_sta_list_lookup(list, mac);
 
   if (node) {
       list_del(&node->list);
       atomic_dec(&list->size);
       kfree(node);
       ++vif->generation;
       ret = true;
   }
 
   return ret;
}
 
void qtnf_sta_list_free(struct qtnf_sta_list *list)
{
   struct qtnf_sta_node *node, *tmp;
 
   atomic_set(&list->size, 0);
 
   list_for_each_entry_safe(node, tmp, &list->head, list) {
       list_del(&node->list);
       kfree(node);
   }
 
   INIT_LIST_HEAD(&list->head);
}
 
const char *qtnf_chipid_to_string(unsigned long chip_id)
{
   switch (chip_id) {
   case QTN_CHIP_ID_TOPAZ:
       return "Topaz";
   case QTN_CHIP_ID_PEARL:
       return "Pearl revA";
   case QTN_CHIP_ID_PEARL_B:
       return "Pearl revB";
   case QTN_CHIP_ID_PEARL_C:
       return "Pearl revC";
   default:
       return "unknown";
   }
}
EXPORT_SYMBOL_GPL(qtnf_chipid_to_string);