1 /*
2 * Copyright (c) 2018,2020 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2021-2023 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 * This file provides OS dependent network interface related APIs
23 */
24 #include "qdf_net_if.h"
25 #include "qdf_types.h"
26 #include "qdf_module.h"
27 #include "qdf_util.h"
28 #include <linux/netdevice.h>
29
30 QDF_STATUS
qdf_net_if_create_dummy_if(struct qdf_net_if * nif)31 qdf_net_if_create_dummy_if(struct qdf_net_if *nif)
32 {
33 int ret;
34
35 if (!nif)
36 return QDF_STATUS_E_INVAL;
37
38 ret = init_dummy_netdev((struct net_device *)nif);
39
40 return qdf_status_from_os_return(ret);
41 }
42
43 qdf_export_symbol(qdf_net_if_create_dummy_if);
44
45 /**
46 * qdf_net_if_get_devname() - Retrieve netdevice name
47 * @nif: Abstraction of netdevice
48 *
49 * Return: netdevice name
50 */
qdf_net_if_get_devname(struct qdf_net_if * nif)51 char *qdf_net_if_get_devname(struct qdf_net_if *nif)
52 {
53 if (!nif)
54 return NULL;
55
56 return (((struct net_device *)nif)->name);
57 }
58
59 qdf_export_symbol(qdf_net_if_get_devname);
60
61 /**
62 * qdf_net_if_get_dev_by_name() - Find a network device by its name
63 * @nif_name: network device name
64 *
65 * This function retrieves the network device by its name
66 *
67 * Return: qdf network device
68 */
qdf_net_if_get_dev_by_name(char * nif_name)69 struct qdf_net_if *qdf_net_if_get_dev_by_name(char *nif_name)
70 {
71 return __qdf_net_if_get_dev_by_name(nif_name);
72 }
73
74 qdf_export_symbol(qdf_net_if_get_dev_by_name);
75
76 /**
77 * qdf_net_if_release_dev() - Release reference to network device
78 * @nif: network device
79 *
80 * This function releases reference to the network device
81 *
82 * Return: QDF_STATUS_SUCCESS on success
83 */
84 QDF_STATUS
qdf_net_if_release_dev(struct qdf_net_if * nif)85 qdf_net_if_release_dev(struct qdf_net_if *nif)
86 {
87 return __qdf_net_if_release_dev(nif);
88 }
89
90 qdf_export_symbol(qdf_net_if_release_dev);
91
92 QDF_STATUS
qdf_net_if_hold_dev(struct qdf_net_if * nif)93 qdf_net_if_hold_dev(struct qdf_net_if *nif)
94 {
95 return __qdf_net_if_hold_dev(nif);
96 }
97
98 qdf_export_symbol(qdf_net_if_hold_dev);
99
100 /**
101 * qdf_net_update_net_device_dev_addr() - update net_device dev_addr
102 * @ndev: net_device
103 * @src_addr: source mac address
104 * @len: length
105 *
106 * kernel version 5.17 onwards made net_device->dev_addr as const unsigned char*
107 * so to update dev_addr, this function calls kernel api dev_addr_mod.
108 *
109 * Return: void
110 */
111 void
qdf_net_update_net_device_dev_addr(struct net_device * ndev,const void * src_addr,size_t len)112 qdf_net_update_net_device_dev_addr(struct net_device *ndev,
113 const void *src_addr,
114 size_t len)
115 {
116 __qdf_net_update_net_device_dev_addr(ndev, src_addr, len);
117 }
118
119 qdf_export_symbol(qdf_net_update_net_device_dev_addr);
120
qdf_napi_enable(struct napi_struct * napi)121 void qdf_napi_enable(struct napi_struct *napi)
122 {
123 __qdf_napi_enable(napi);
124 }
125
126 qdf_export_symbol(qdf_napi_enable);
127
qdf_napi_disable(struct napi_struct * napi)128 void qdf_napi_disable(struct napi_struct *napi)
129 {
130 __qdf_napi_disable(napi);
131 }
132
133 qdf_export_symbol(qdf_napi_disable);
134
qdf_netif_napi_add(struct net_device * netdev,struct napi_struct * napi,int (* poll)(struct napi_struct *,int),int weight)135 void qdf_netif_napi_add(struct net_device *netdev, struct napi_struct *napi,
136 int (*poll)(struct napi_struct *, int), int weight)
137 {
138 __qdf_netif_napi_add(netdev, napi, poll, weight);
139 }
140
141 qdf_export_symbol(qdf_netif_napi_add);
142
qdf_netif_napi_del(struct napi_struct * napi)143 void qdf_netif_napi_del(struct napi_struct *napi)
144 {
145 __qdf_netif_napi_del(napi);
146 }
147
148 qdf_export_symbol(qdf_netif_napi_del);
149