xref: /wlan-dirver/qca-wifi-host-cmn/qdf/linux/src/i_qdf_net_if.h (revision 901120c066e139c7f8a2c8e4820561fdd83c67ef)
1 /*
2  * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: qdf_net_if
22  * QCA driver framework (QDF) network interface management APIs
23  */
24 
25 #if !defined(__I_QDF_NET_IF_H)
26 #define __I_QDF_NET_IF_H
27 
28 /* Include Files */
29 #include <qdf_types.h>
30 #include <qdf_util.h>
31 #include <linux/netdevice.h>
32 
33 struct qdf_net_if;
34 
35 /**
36  * __qdf_net_if_create_dummy_if() - create dummy interface
37  * @nif: interface handle
38  *
39  * This function will create a dummy network interface
40  *
41  * Return: QDF_STATUS_SUCCESS on success
42  */
43 static inline QDF_STATUS
44 __qdf_net_if_create_dummy_if(struct qdf_net_if *nif)
45 {
46 	int ret;
47 
48 	ret = init_dummy_netdev((struct net_device *)nif);
49 
50 	return qdf_status_from_os_return(ret);
51 }
52 
53 /**
54  * qdf_net_if_get_dev_by_name() - Find a network device by its name
55  * @nif_name: network device name
56  *
57  * This function retrieves the network device by its name
58  *
59  * Return: qdf network device
60  */
61 static inline struct qdf_net_if *
62 __qdf_net_if_get_dev_by_name(char *nif_name)
63 {
64 	if (!nif_name)
65 		return NULL;
66 
67 	return ((struct qdf_net_if *)dev_get_by_name(&init_net, nif_name));
68 }
69 
70 /**
71  * qdf_net_if_release_dev() - Release reference to network device
72  * @nif: network device
73  *
74  * This function releases reference to the network device
75  *
76  * Return: QDF_STATUS_SUCCESS on success
77  */
78 static inline QDF_STATUS
79 __qdf_net_if_release_dev(struct qdf_net_if  *nif)
80 {
81 	if (!nif)
82 		return QDF_STATUS_E_INVAL;
83 
84 	dev_put((struct net_device *)nif);
85 
86 	return QDF_STATUS_SUCCESS;
87 }
88 
89 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0))
90 /**
91  * qdf_net_update_net_device_dev_addr() - update net_device dev_addr
92  * @ndev: net_device
93  * @src_addr: source mac address
94  * @len: length
95  *
96  * kernel version 5.17 onwards made net_device->dev_addr as const unsigned char*
97  * so to update dev_addr, this function calls kernel api dev_addr_mod.
98  *
99  * Return: void
100  */
101 static inline void
102 __qdf_net_update_net_device_dev_addr(struct net_device *ndev,
103 				     const void *src_addr,
104 				     size_t len)
105 {
106 	dev_addr_mod(ndev, 0, src_addr, len);
107 }
108 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0)) */
109 /**
110  * qdf_net_update_net_device_dev_addr() - update net_device dev_addr
111  * @ndev: net_device
112  * @src_addr: source mac address
113  * @len: length
114  *
115  * This function updates dev_addr in net_device using mem copy.
116  *
117  * Return: void
118  */
119 static inline void
120 __qdf_net_update_net_device_dev_addr(struct net_device *ndev,
121 				     const void *src_addr,
122 				     size_t len)
123 {
124 	memcpy(ndev->dev_addr, src_addr, len);
125 }
126 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0)) */
127 
128 #endif /*__I_QDF_NET_IF_H */
129