xref: /wlan-driver/qcacld-3.0/components/pmo/dispatcher/src/wlan_pmo_tgt_arp.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2017-2018, 2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: Implements public API for pmo to interact with target/WMI
21  */
22 
23 #include "wlan_pmo_tgt_api.h"
24 #include "wlan_pmo_arp_public_struct.h"
25 #include "wlan_pmo_ns_public_struct.h"
26 #include "wlan_pmo_obj_mgmt_public_struct.h"
27 #include "wlan_pmo_main.h"
28 
pmo_tgt_enable_arp_offload_req(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id)29 QDF_STATUS pmo_tgt_enable_arp_offload_req(struct wlan_objmgr_vdev *vdev,
30 		uint8_t vdev_id)
31 {
32 	struct pmo_arp_offload_params *arp_offload_req = NULL;
33 	struct pmo_ns_offload_params *ns_offload_req = NULL;
34 	struct pmo_vdev_priv_obj *vdev_ctx;
35 	struct wlan_objmgr_psoc *psoc;
36 	QDF_STATUS status;
37 	struct wlan_pmo_tx_ops pmo_tx_ops;
38 
39 	vdev_ctx = pmo_vdev_get_priv(vdev);
40 
41 	psoc = pmo_vdev_get_psoc(vdev);
42 
43 	arp_offload_req = qdf_mem_malloc(sizeof(*arp_offload_req));
44 	if (!arp_offload_req) {
45 		status = QDF_STATUS_E_NOMEM;
46 		goto out;
47 	}
48 
49 	ns_offload_req = qdf_mem_malloc(sizeof(*ns_offload_req));
50 	if (!ns_offload_req) {
51 		status = QDF_STATUS_E_NOMEM;
52 		goto out;
53 	}
54 
55 	qdf_spin_lock_bh(&vdev_ctx->pmo_vdev_lock);
56 	qdf_mem_copy(arp_offload_req, &vdev_ctx->vdev_arp_req,
57 		sizeof(*arp_offload_req));
58 	qdf_mem_copy(ns_offload_req, &vdev_ctx->vdev_ns_req,
59 		sizeof(*ns_offload_req));
60 	qdf_spin_unlock_bh(&vdev_ctx->pmo_vdev_lock);
61 
62 	pmo_debug("vdev_id: %d: ARP offload %d NS offload %d ns_count %u",
63 		  vdev_id, arp_offload_req->enable, ns_offload_req->enable,
64 		  ns_offload_req->num_ns_offload_count);
65 
66 	pmo_tx_ops = GET_PMO_TX_OPS_FROM_PSOC(psoc);
67 	if (!pmo_tx_ops.send_arp_offload_req) {
68 		pmo_err("send_arp_offload_req is null");
69 		status = QDF_STATUS_E_NULL_VALUE;
70 		goto out;
71 	}
72 	status = pmo_tx_ops.send_arp_offload_req(
73 			vdev, arp_offload_req, ns_offload_req);
74 	if (status != QDF_STATUS_SUCCESS) {
75 		pmo_err("Failed to send ARP offload");
76 		goto out;
77 	}
78 
79 	qdf_spin_lock_bh(&vdev_ctx->pmo_vdev_lock);
80 	if (vdev_ctx->vdev_arp_req.enable)
81 		vdev_ctx->vdev_arp_req.is_offload_applied = true;
82 	if (vdev_ctx->vdev_ns_req.enable)
83 		vdev_ctx->vdev_ns_req.is_offload_applied = true;
84 	qdf_spin_unlock_bh(&vdev_ctx->pmo_vdev_lock);
85 
86 out:
87 	if (arp_offload_req)
88 		qdf_mem_free(arp_offload_req);
89 	if (ns_offload_req)
90 		qdf_mem_free(ns_offload_req);
91 
92 	return status;
93 }
94 
pmo_tgt_disable_arp_offload_req(struct wlan_objmgr_vdev * vdev,uint8_t vdev_id)95 QDF_STATUS pmo_tgt_disable_arp_offload_req(struct wlan_objmgr_vdev *vdev,
96 		uint8_t vdev_id)
97 {
98 	struct pmo_arp_offload_params *arp_offload_req = NULL;
99 	struct pmo_ns_offload_params *ns_offload_req = NULL;
100 	struct pmo_vdev_priv_obj *vdev_ctx;
101 	struct wlan_objmgr_psoc *psoc;
102 	QDF_STATUS status;
103 	struct wlan_pmo_tx_ops pmo_tx_ops;
104 
105 	pmo_enter();
106 
107 	vdev_ctx = pmo_vdev_get_priv(vdev);
108 
109 	psoc = pmo_vdev_get_psoc(vdev);
110 
111 	arp_offload_req = qdf_mem_malloc(sizeof(*arp_offload_req));
112 	if (!arp_offload_req) {
113 		status = QDF_STATUS_E_NOMEM;
114 		goto out;
115 	}
116 
117 	ns_offload_req = qdf_mem_malloc(sizeof(*ns_offload_req));
118 	if (!ns_offload_req) {
119 		status = QDF_STATUS_E_NOMEM;
120 		goto out;
121 	}
122 
123 	qdf_spin_lock_bh(&vdev_ctx->pmo_vdev_lock);
124 	qdf_mem_copy(arp_offload_req, &vdev_ctx->vdev_arp_req,
125 		sizeof(*arp_offload_req));
126 	qdf_mem_copy(ns_offload_req, &vdev_ctx->vdev_ns_req,
127 		sizeof(*ns_offload_req));
128 	qdf_spin_unlock_bh(&vdev_ctx->pmo_vdev_lock);
129 
130 	pmo_debug("ARP Offload vdev_id: %d enable: %d",
131 		vdev_id,
132 		arp_offload_req->enable);
133 	pmo_debug("NS Offload vdev_id: %d enable: %d ns_count: %u",
134 		vdev_id,
135 		ns_offload_req->enable,
136 		ns_offload_req->num_ns_offload_count);
137 
138 	pmo_tx_ops = GET_PMO_TX_OPS_FROM_PSOC(psoc);
139 	if (!pmo_tx_ops.send_arp_offload_req) {
140 		pmo_err("send_arp_offload_req is null");
141 		status = QDF_STATUS_E_NULL_VALUE;
142 		goto out;
143 	}
144 	status = pmo_tx_ops.send_arp_offload_req(
145 			vdev, arp_offload_req, ns_offload_req);
146 	if (status != QDF_STATUS_SUCCESS)
147 		pmo_err("Failed to send ARP offload");
148 
149 	qdf_spin_lock_bh(&vdev_ctx->pmo_vdev_lock);
150 	vdev_ctx->vdev_arp_req.is_offload_applied = false;
151 	vdev_ctx->vdev_ns_req.is_offload_applied = false;
152 	qdf_spin_unlock_bh(&vdev_ctx->pmo_vdev_lock);
153 
154 out:
155 	if (arp_offload_req)
156 		qdf_mem_free(arp_offload_req);
157 	if (ns_offload_req)
158 		qdf_mem_free(ns_offload_req);
159 	pmo_exit();
160 
161 	return status;
162 }
163 
164