Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0+
  2/* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
 
 
 
 
 
 
 
 
 
 
 
 
 
  3
  4#include "util.h"
  5#include "qtn_hw_ids.h"
  6
  7void qtnf_sta_list_init(struct qtnf_sta_list *list)
  8{
  9	if (unlikely(!list))
 10		return;
 11
 12	INIT_LIST_HEAD(&list->head);
 13	atomic_set(&list->size, 0);
 14}
 15
 16struct qtnf_sta_node *qtnf_sta_list_lookup(struct qtnf_sta_list *list,
 17					   const u8 *mac)
 18{
 19	struct qtnf_sta_node *node;
 20
 21	if (unlikely(!mac))
 22		return NULL;
 23
 24	list_for_each_entry(node, &list->head, list) {
 25		if (ether_addr_equal(node->mac_addr, mac))
 26			return node;
 27	}
 28
 29	return NULL;
 30}
 31
 32struct qtnf_sta_node *qtnf_sta_list_lookup_index(struct qtnf_sta_list *list,
 33						 size_t index)
 34{
 35	struct qtnf_sta_node *node;
 36
 37	if (qtnf_sta_list_size(list) <= index)
 38		return NULL;
 39
 40	list_for_each_entry(node, &list->head, list) {
 41		if (index-- == 0)
 42			return node;
 43	}
 44
 45	return NULL;
 46}
 47
 48struct qtnf_sta_node *qtnf_sta_list_add(struct qtnf_vif *vif,
 49					const u8 *mac)
 50{
 51	struct qtnf_sta_list *list = &vif->sta_list;
 52	struct qtnf_sta_node *node;
 53
 54	if (unlikely(!mac))
 55		return NULL;
 56
 57	node = qtnf_sta_list_lookup(list, mac);
 58
 59	if (node)
 60		goto done;
 61
 62	node = kzalloc(sizeof(*node), GFP_KERNEL);
 63	if (unlikely(!node))
 64		goto done;
 65
 66	ether_addr_copy(node->mac_addr, mac);
 67	list_add_tail(&node->list, &list->head);
 68	atomic_inc(&list->size);
 69	++vif->generation;
 70
 71done:
 72	return node;
 73}
 74
 75bool qtnf_sta_list_del(struct qtnf_vif *vif, const u8 *mac)
 76{
 77	struct qtnf_sta_list *list = &vif->sta_list;
 78	struct qtnf_sta_node *node;
 79	bool ret = false;
 80
 81	node = qtnf_sta_list_lookup(list, mac);
 82
 83	if (node) {
 84		list_del(&node->list);
 85		atomic_dec(&list->size);
 86		kfree(node);
 87		++vif->generation;
 88		ret = true;
 89	}
 90
 91	return ret;
 92}
 93
 94void qtnf_sta_list_free(struct qtnf_sta_list *list)
 95{
 96	struct qtnf_sta_node *node, *tmp;
 97
 98	atomic_set(&list->size, 0);
 99
100	list_for_each_entry_safe(node, tmp, &list->head, list) {
101		list_del(&node->list);
102		kfree(node);
103	}
104
105	INIT_LIST_HEAD(&list->head);
106}
107
108const char *qtnf_chipid_to_string(unsigned long chip_id)
109{
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";
121	}
122}
123EXPORT_SYMBOL_GPL(qtnf_chipid_to_string);
v4.17
  1/*
  2 * Copyright (c) 2015-2016 Quantenna Communications, Inc.
  3 * All rights reserved.
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License
  7 * as published by the Free Software Foundation; either version 2
  8 * of the License, or (at your option) any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 */
 16
 17#include "util.h"
 
 18
 19void qtnf_sta_list_init(struct qtnf_sta_list *list)
 20{
 21	if (unlikely(!list))
 22		return;
 23
 24	INIT_LIST_HEAD(&list->head);
 25	atomic_set(&list->size, 0);
 26}
 27
 28struct qtnf_sta_node *qtnf_sta_list_lookup(struct qtnf_sta_list *list,
 29					   const u8 *mac)
 30{
 31	struct qtnf_sta_node *node;
 32
 33	if (unlikely(!mac))
 34		return NULL;
 35
 36	list_for_each_entry(node, &list->head, list) {
 37		if (ether_addr_equal(node->mac_addr, mac))
 38			return node;
 39	}
 40
 41	return NULL;
 42}
 43
 44struct qtnf_sta_node *qtnf_sta_list_lookup_index(struct qtnf_sta_list *list,
 45						 size_t index)
 46{
 47	struct qtnf_sta_node *node;
 48
 49	if (qtnf_sta_list_size(list) <= index)
 50		return NULL;
 51
 52	list_for_each_entry(node, &list->head, list) {
 53		if (index-- == 0)
 54			return node;
 55	}
 56
 57	return NULL;
 58}
 59
 60struct qtnf_sta_node *qtnf_sta_list_add(struct qtnf_vif *vif,
 61					const u8 *mac)
 62{
 63	struct qtnf_sta_list *list = &vif->sta_list;
 64	struct qtnf_sta_node *node;
 65
 66	if (unlikely(!mac))
 67		return NULL;
 68
 69	node = qtnf_sta_list_lookup(list, mac);
 70
 71	if (node)
 72		goto done;
 73
 74	node = kzalloc(sizeof(*node), GFP_KERNEL);
 75	if (unlikely(!node))
 76		goto done;
 77
 78	ether_addr_copy(node->mac_addr, mac);
 79	list_add_tail(&node->list, &list->head);
 80	atomic_inc(&list->size);
 81	++vif->generation;
 82
 83done:
 84	return node;
 85}
 86
 87bool qtnf_sta_list_del(struct qtnf_vif *vif, const u8 *mac)
 88{
 89	struct qtnf_sta_list *list = &vif->sta_list;
 90	struct qtnf_sta_node *node;
 91	bool ret = false;
 92
 93	node = qtnf_sta_list_lookup(list, mac);
 94
 95	if (node) {
 96		list_del(&node->list);
 97		atomic_dec(&list->size);
 98		kfree(node);
 99		++vif->generation;
100		ret = true;
101	}
102
103	return ret;
104}
105
106void qtnf_sta_list_free(struct qtnf_sta_list *list)
107{
108	struct qtnf_sta_node *node, *tmp;
109
110	atomic_set(&list->size, 0);
111
112	list_for_each_entry_safe(node, tmp, &list->head, list) {
113		list_del(&node->list);
114		kfree(node);
115	}
116
117	INIT_LIST_HEAD(&list->head);
118}