drm/rockchip: Don't change hdmi reference clock rate
[drm/drm-misc.git] / drivers / net / wireless / quantenna / qtnfmac / util.c
blobcda6f5f3f38afae5d435e11699a38498e229177a
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
4 #include "util.h"
5 #include "qtn_hw_ids.h"
7 void qtnf_sta_list_init(struct qtnf_sta_list *list)
9 if (unlikely(!list))
10 return;
12 INIT_LIST_HEAD(&list->head);
13 atomic_set(&list->size, 0);
16 struct qtnf_sta_node *qtnf_sta_list_lookup(struct qtnf_sta_list *list,
17 const u8 *mac)
19 struct qtnf_sta_node *node;
21 if (unlikely(!mac))
22 return NULL;
24 list_for_each_entry(node, &list->head, list) {
25 if (ether_addr_equal(node->mac_addr, mac))
26 return node;
29 return NULL;
32 struct qtnf_sta_node *qtnf_sta_list_lookup_index(struct qtnf_sta_list *list,
33 size_t index)
35 struct qtnf_sta_node *node;
37 if (qtnf_sta_list_size(list) <= index)
38 return NULL;
40 list_for_each_entry(node, &list->head, list) {
41 if (index-- == 0)
42 return node;
45 return NULL;
48 struct qtnf_sta_node *qtnf_sta_list_add(struct qtnf_vif *vif,
49 const u8 *mac)
51 struct qtnf_sta_list *list = &vif->sta_list;
52 struct qtnf_sta_node *node;
54 if (unlikely(!mac))
55 return NULL;
57 node = qtnf_sta_list_lookup(list, mac);
59 if (node)
60 goto done;
62 node = kzalloc(sizeof(*node), GFP_KERNEL);
63 if (unlikely(!node))
64 goto done;
66 ether_addr_copy(node->mac_addr, mac);
67 list_add_tail(&node->list, &list->head);
68 atomic_inc(&list->size);
69 ++vif->generation;
71 done:
72 return node;
75 bool qtnf_sta_list_del(struct qtnf_vif *vif, const u8 *mac)
77 struct qtnf_sta_list *list = &vif->sta_list;
78 struct qtnf_sta_node *node;
79 bool ret = false;
81 node = qtnf_sta_list_lookup(list, mac);
83 if (node) {
84 list_del(&node->list);
85 atomic_dec(&list->size);
86 kfree(node);
87 ++vif->generation;
88 ret = true;
91 return ret;
94 void qtnf_sta_list_free(struct qtnf_sta_list *list)
96 struct qtnf_sta_node *node, *tmp;
98 atomic_set(&list->size, 0);
100 list_for_each_entry_safe(node, tmp, &list->head, list) {
101 list_del(&node->list);
102 kfree(node);
105 INIT_LIST_HEAD(&list->head);
108 const char *qtnf_chipid_to_string(unsigned long chip_id)
110 switch (chip_id) {
111 case QTN_CHIP_ID_TOPAZ:
112 return "Topaz";
113 case QTN_CHIP_ID_PEARL:
114 return "Pearl revA";
115 case QTN_CHIP_ID_PEARL_B:
116 return "Pearl revB";
117 case QTN_CHIP_ID_PEARL_C:
118 return "Pearl revC";
119 default:
120 return "unknown";
123 EXPORT_SYMBOL_GPL(qtnf_chipid_to_string);