0001
0002
0003
0004 #include "util.h"
0005 #include "qtn_hw_ids.h"
0006
0007 void qtnf_sta_list_init(struct qtnf_sta_list *list)
0008 {
0009 if (unlikely(!list))
0010 return;
0011
0012 INIT_LIST_HEAD(&list->head);
0013 atomic_set(&list->size, 0);
0014 }
0015
0016 struct qtnf_sta_node *qtnf_sta_list_lookup(struct qtnf_sta_list *list,
0017 const u8 *mac)
0018 {
0019 struct qtnf_sta_node *node;
0020
0021 if (unlikely(!mac))
0022 return NULL;
0023
0024 list_for_each_entry(node, &list->head, list) {
0025 if (ether_addr_equal(node->mac_addr, mac))
0026 return node;
0027 }
0028
0029 return NULL;
0030 }
0031
0032 struct qtnf_sta_node *qtnf_sta_list_lookup_index(struct qtnf_sta_list *list,
0033 size_t index)
0034 {
0035 struct qtnf_sta_node *node;
0036
0037 if (qtnf_sta_list_size(list) <= index)
0038 return NULL;
0039
0040 list_for_each_entry(node, &list->head, list) {
0041 if (index-- == 0)
0042 return node;
0043 }
0044
0045 return NULL;
0046 }
0047
0048 struct qtnf_sta_node *qtnf_sta_list_add(struct qtnf_vif *vif,
0049 const u8 *mac)
0050 {
0051 struct qtnf_sta_list *list = &vif->sta_list;
0052 struct qtnf_sta_node *node;
0053
0054 if (unlikely(!mac))
0055 return NULL;
0056
0057 node = qtnf_sta_list_lookup(list, mac);
0058
0059 if (node)
0060 goto done;
0061
0062 node = kzalloc(sizeof(*node), GFP_KERNEL);
0063 if (unlikely(!node))
0064 goto done;
0065
0066 ether_addr_copy(node->mac_addr, mac);
0067 list_add_tail(&node->list, &list->head);
0068 atomic_inc(&list->size);
0069 ++vif->generation;
0070
0071 done:
0072 return node;
0073 }
0074
0075 bool qtnf_sta_list_del(struct qtnf_vif *vif, const u8 *mac)
0076 {
0077 struct qtnf_sta_list *list = &vif->sta_list;
0078 struct qtnf_sta_node *node;
0079 bool ret = false;
0080
0081 node = qtnf_sta_list_lookup(list, mac);
0082
0083 if (node) {
0084 list_del(&node->list);
0085 atomic_dec(&list->size);
0086 kfree(node);
0087 ++vif->generation;
0088 ret = true;
0089 }
0090
0091 return ret;
0092 }
0093
0094 void qtnf_sta_list_free(struct qtnf_sta_list *list)
0095 {
0096 struct qtnf_sta_node *node, *tmp;
0097
0098 atomic_set(&list->size, 0);
0099
0100 list_for_each_entry_safe(node, tmp, &list->head, list) {
0101 list_del(&node->list);
0102 kfree(node);
0103 }
0104
0105 INIT_LIST_HEAD(&list->head);
0106 }
0107
0108 const char *qtnf_chipid_to_string(unsigned long chip_id)
0109 {
0110 switch (chip_id) {
0111 case QTN_CHIP_ID_TOPAZ:
0112 return "Topaz";
0113 case QTN_CHIP_ID_PEARL:
0114 return "Pearl revA";
0115 case QTN_CHIP_ID_PEARL_B:
0116 return "Pearl revB";
0117 case QTN_CHIP_ID_PEARL_C:
0118 return "Pearl revC";
0119 default:
0120 return "unknown";
0121 }
0122 }
0123 EXPORT_SYMBOL_GPL(qtnf_chipid_to_string);