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 /** 129 * __qdf_napi_enable() - Enable the napi schedule 130 * @napi: NAPI context 131 * 132 * This function resume NAPI from being scheduled on this context 133 * 134 * Return: NONE 135 */ 136 static inline void 137 __qdf_napi_enable(struct napi_struct *napi) 138 { 139 napi_enable(napi); 140 } 141 142 /** 143 * __qdf_napi_disable() - Disable the napi schedule 144 * @napi: NAPI context 145 * 146 * This function suspends NAPI from being scheduled on this context 147 * 148 * Return: NONE 149 */ 150 static inline void 151 __qdf_napi_disable(struct napi_struct *napi) 152 { 153 napi_disable(napi); 154 } 155 156 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0)) 157 /** 158 * __qdf_netif_napi_add - initialize a NAPI context 159 * @netdev: network device 160 * @napi: NAPI context 161 * @poll: polling function 162 * @weight: default weight 163 * 164 * Upstream commit b48b89f9c189 ("net: drop the weight argument from 165 * netif_napi_add") was introduced in Linux 6.1. As described by the 166 * subject, this removes the weight argument from netif_napi_add(). 167 * 168 * This was preceded by commit 58caed3dacb4 ("netdev: reshuffle 169 * netif_napi_add() APIs to allow dropping weight") in Linux 5.19 170 * which added new APIs to call when a non-default weight wishes to be 171 * sent. 172 * 173 * Return: NONE 174 */ 175 static inline void 176 __qdf_netif_napi_add(struct net_device *netdev, struct napi_struct *napi, 177 int (*poll)(struct napi_struct *, int), int weight) 178 { 179 netif_napi_add_weight(netdev, napi, poll, weight); 180 } 181 #else 182 static inline void 183 __qdf_netif_napi_add(struct net_device *netdev, struct napi_struct *napi, 184 int (*poll)(struct napi_struct *, int), int weight) 185 { 186 netif_napi_add(netdev, napi, poll, weight); 187 } 188 #endif 189 190 /** 191 * __qdf_netif_napi_del: remove a NAPI context 192 * @napi: NAPI context 193 * 194 * Return: NONE 195 */ 196 static inline void 197 __qdf_netif_napi_del(struct napi_struct *napi) 198 { 199 netif_napi_del(napi); 200 } 201 202 #endif /*__I_QDF_NET_IF_H */ 203