1*5113495bSYour Name /*
2*5113495bSYour Name * Copyright (c) 2011, 2014-2019, 2021 The Linux Foundation. All rights reserved.
3*5113495bSYour Name *
4*5113495bSYour Name * Permission to use, copy, modify, and/or distribute this software for
5*5113495bSYour Name * any purpose with or without fee is hereby granted, provided that the
6*5113495bSYour Name * above copyright notice and this permission notice appear in all
7*5113495bSYour Name * copies.
8*5113495bSYour Name *
9*5113495bSYour Name * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10*5113495bSYour Name * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11*5113495bSYour Name * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12*5113495bSYour Name * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13*5113495bSYour Name * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14*5113495bSYour Name * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15*5113495bSYour Name * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16*5113495bSYour Name * PERFORMANCE OF THIS SOFTWARE.
17*5113495bSYour Name */
18*5113495bSYour Name
19*5113495bSYour Name /* standard header files */
20*5113495bSYour Name #include <qdf_nbuf.h> /* qdf_nbuf_map */
21*5113495bSYour Name #include <qdf_mem.h> /* qdf_mem_cmp */
22*5113495bSYour Name
23*5113495bSYour Name /* external header files */
24*5113495bSYour Name #include <ol_cfg.h> /* wlan_op_mode_ap, etc. */
25*5113495bSYour Name #include <ol_htt_rx_api.h> /* htt_rx_msdu_desc_retrieve */
26*5113495bSYour Name #include <cds_ieee80211_common.h> /* ieee80211_frame, etc. */
27*5113495bSYour Name
28*5113495bSYour Name /* internal header files */
29*5113495bSYour Name #include <ol_rx_fwd.h> /* our own defs */
30*5113495bSYour Name #include <ol_rx.h> /* ol_rx_deliver */
31*5113495bSYour Name #include <ol_txrx_internal.h> /* TXRX_ASSERT1 */
32*5113495bSYour Name #include <ol_tx.h>
33*5113495bSYour Name #include <ol_txrx.h>
34*5113495bSYour Name
35*5113495bSYour Name /*
36*5113495bSYour Name * Porting from Ap11PrepareForwardedPacket.
37*5113495bSYour Name * This routine is called when a RX data frame from an associated station is
38*5113495bSYour Name * to be forwarded to another associated station. We will prepare the
39*5113495bSYour Name * received packet so that it is suitable for transmission again.
40*5113495bSYour Name * Check that this Packet is suitable for forwarding. If yes, then
41*5113495bSYour Name * prepare the new 802.11 header.
42*5113495bSYour Name */
ol_ap_fwd_check(struct ol_txrx_vdev_t * vdev,qdf_nbuf_t msdu)43*5113495bSYour Name static inline void ol_ap_fwd_check(struct ol_txrx_vdev_t *vdev, qdf_nbuf_t msdu)
44*5113495bSYour Name {
45*5113495bSYour Name struct ieee80211_frame *mac_header;
46*5113495bSYour Name unsigned char tmp_addr[QDF_MAC_ADDR_SIZE];
47*5113495bSYour Name unsigned char type;
48*5113495bSYour Name unsigned char subtype;
49*5113495bSYour Name unsigned char fromds;
50*5113495bSYour Name unsigned char tods;
51*5113495bSYour Name
52*5113495bSYour Name mac_header = (struct ieee80211_frame *)(qdf_nbuf_data(msdu));
53*5113495bSYour Name TXRX_ASSERT1(mac_header);
54*5113495bSYour Name
55*5113495bSYour Name type = mac_header->i_fc[0] & IEEE80211_FC0_TYPE_MASK;
56*5113495bSYour Name subtype = mac_header->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK;
57*5113495bSYour Name tods = mac_header->i_fc[1] & IEEE80211_FC1_DIR_TODS;
58*5113495bSYour Name fromds = mac_header->i_fc[1] & IEEE80211_FC1_DIR_FROMDS;
59*5113495bSYour Name
60*5113495bSYour Name /*
61*5113495bSYour Name * Make sure no QOS or any other non-data subtype
62*5113495bSYour Name * Should be a ToDs data frame.
63*5113495bSYour Name * Make sure that this frame is unicast and not for us.
64*5113495bSYour Name * These packets should come up through the normal rx path and
65*5113495bSYour Name * not forwarded.
66*5113495bSYour Name */
67*5113495bSYour Name if (type != IEEE80211_FC0_TYPE_DATA ||
68*5113495bSYour Name subtype != 0x0 ||
69*5113495bSYour Name ((tods != 1) || (fromds != 0)) ||
70*5113495bSYour Name qdf_mem_cmp
71*5113495bSYour Name (mac_header->i_addr3, vdev->mac_addr.raw,
72*5113495bSYour Name QDF_MAC_ADDR_SIZE)) {
73*5113495bSYour Name ol_txrx_dbg("Exit | Unnecessary to adjust mac header");
74*5113495bSYour Name } else {
75*5113495bSYour Name /* Flip the ToDs bit to FromDs */
76*5113495bSYour Name mac_header->i_fc[1] &= 0xfe;
77*5113495bSYour Name mac_header->i_fc[1] |= 0x2;
78*5113495bSYour Name
79*5113495bSYour Name /*
80*5113495bSYour Name * Flip the addresses
81*5113495bSYour Name * (ToDs, addr1, RA=BSSID) move to (FrDs, addr2, TA=BSSID)
82*5113495bSYour Name * (ToDs, addr2, SA) move to (FrDs, addr3, SA)
83*5113495bSYour Name * (ToDs, addr3, DA) move to (FrDs, addr1, DA)
84*5113495bSYour Name */
85*5113495bSYour Name
86*5113495bSYour Name memcpy(tmp_addr, mac_header->i_addr2, sizeof(tmp_addr));
87*5113495bSYour Name
88*5113495bSYour Name memcpy(mac_header->i_addr2,
89*5113495bSYour Name mac_header->i_addr1, sizeof(tmp_addr));
90*5113495bSYour Name
91*5113495bSYour Name memcpy(mac_header->i_addr1,
92*5113495bSYour Name mac_header->i_addr3, sizeof(tmp_addr));
93*5113495bSYour Name
94*5113495bSYour Name memcpy(mac_header->i_addr3, tmp_addr, sizeof(tmp_addr));
95*5113495bSYour Name }
96*5113495bSYour Name }
97*5113495bSYour Name
ol_rx_fwd_to_tx(struct ol_txrx_vdev_t * vdev,qdf_nbuf_t msdu)98*5113495bSYour Name static inline void ol_rx_fwd_to_tx(struct ol_txrx_vdev_t *vdev, qdf_nbuf_t msdu)
99*5113495bSYour Name {
100*5113495bSYour Name struct ol_txrx_pdev_t *pdev = vdev->pdev;
101*5113495bSYour Name
102*5113495bSYour Name if (pdev->frame_format == wlan_frm_fmt_native_wifi)
103*5113495bSYour Name ol_ap_fwd_check(vdev, msdu);
104*5113495bSYour Name
105*5113495bSYour Name /*
106*5113495bSYour Name * Map the netbuf, so it's accessible to the DMA that
107*5113495bSYour Name * sends it to the target.
108*5113495bSYour Name */
109*5113495bSYour Name qdf_nbuf_set_next(msdu, NULL); /* add NULL terminator */
110*5113495bSYour Name
111*5113495bSYour Name /* for HL, point to payload before send to tx again.*/
112*5113495bSYour Name if (pdev->cfg.is_high_latency) {
113*5113495bSYour Name void *rx_desc;
114*5113495bSYour Name
115*5113495bSYour Name rx_desc = htt_rx_msdu_desc_retrieve(pdev->htt_pdev,
116*5113495bSYour Name msdu);
117*5113495bSYour Name qdf_nbuf_pull_head(msdu,
118*5113495bSYour Name htt_rx_msdu_rx_desc_size_hl(pdev->htt_pdev,
119*5113495bSYour Name rx_desc));
120*5113495bSYour Name }
121*5113495bSYour Name
122*5113495bSYour Name /* Clear the msdu control block as it will be re-interpreted */
123*5113495bSYour Name qdf_mem_zero(msdu->cb, sizeof(msdu->cb));
124*5113495bSYour Name /* update any cb field expected by OL_TX_SEND */
125*5113495bSYour Name
126*5113495bSYour Name msdu = OL_TX_SEND(vdev, msdu);
127*5113495bSYour Name
128*5113495bSYour Name if (msdu) {
129*5113495bSYour Name /*
130*5113495bSYour Name * The frame was not accepted by the tx.
131*5113495bSYour Name * We could store the frame and try again later,
132*5113495bSYour Name * but the simplest solution is to discard the frames.
133*5113495bSYour Name */
134*5113495bSYour Name qdf_nbuf_tx_free(msdu, QDF_NBUF_PKT_ERROR);
135*5113495bSYour Name }
136*5113495bSYour Name }
137*5113495bSYour Name
138*5113495bSYour Name void
ol_rx_fwd_check(struct ol_txrx_vdev_t * vdev,struct ol_txrx_peer_t * peer,unsigned int tid,qdf_nbuf_t msdu_list)139*5113495bSYour Name ol_rx_fwd_check(struct ol_txrx_vdev_t *vdev,
140*5113495bSYour Name struct ol_txrx_peer_t *peer,
141*5113495bSYour Name unsigned int tid, qdf_nbuf_t msdu_list)
142*5113495bSYour Name {
143*5113495bSYour Name struct ol_txrx_pdev_t *pdev = vdev->pdev;
144*5113495bSYour Name qdf_nbuf_t deliver_list_head = NULL;
145*5113495bSYour Name qdf_nbuf_t deliver_list_tail = NULL;
146*5113495bSYour Name qdf_nbuf_t msdu;
147*5113495bSYour Name
148*5113495bSYour Name msdu = msdu_list;
149*5113495bSYour Name while (msdu) {
150*5113495bSYour Name struct ol_txrx_vdev_t *tx_vdev;
151*5113495bSYour Name void *rx_desc;
152*5113495bSYour Name uint16_t off = 0;
153*5113495bSYour Name /*
154*5113495bSYour Name * Remember the next list elem, because our processing
155*5113495bSYour Name * may cause the MSDU to get linked into a different list.
156*5113495bSYour Name */
157*5113495bSYour Name msdu_list = qdf_nbuf_next(msdu);
158*5113495bSYour Name
159*5113495bSYour Name rx_desc = htt_rx_msdu_desc_retrieve(pdev->htt_pdev, msdu);
160*5113495bSYour Name
161*5113495bSYour Name if (!vdev->disable_intrabss_fwd &&
162*5113495bSYour Name htt_rx_msdu_forward(pdev->htt_pdev, rx_desc)) {
163*5113495bSYour Name /*
164*5113495bSYour Name * Use the same vdev that received the frame to
165*5113495bSYour Name * transmit the frame.
166*5113495bSYour Name * This is exactly what we want for intra-BSS
167*5113495bSYour Name * forwarding, like STA-to-STA forwarding and
168*5113495bSYour Name * multicast echo.
169*5113495bSYour Name * If this is a intra-BSS forwarding case (which is not
170*5113495bSYour Name * currently supported), then the tx vdev is different
171*5113495bSYour Name * from the rx vdev.
172*5113495bSYour Name * On the LL host the vdevs are not actually used
173*5113495bSYour Name * for tx, so it would still work to use the rx vdev
174*5113495bSYour Name * rather than the tx vdev.
175*5113495bSYour Name * For HL, the tx classification searches for the DA
176*5113495bSYour Name * within the given vdev, so we would want to get the DA
177*5113495bSYour Name * peer ID from the target, so we can locate
178*5113495bSYour Name * the tx vdev.
179*5113495bSYour Name */
180*5113495bSYour Name tx_vdev = vdev;
181*5113495bSYour Name /*
182*5113495bSYour Name * Copying TID value of RX packet to forwarded
183*5113495bSYour Name * packet if the tid is other than non qos tid.
184*5113495bSYour Name * But for non qos tid fill invalid tid so that
185*5113495bSYour Name * Fw will take care of filling proper tid.
186*5113495bSYour Name */
187*5113495bSYour Name if (tid != HTT_NON_QOS_TID) {
188*5113495bSYour Name qdf_nbuf_set_tid(msdu, tid);
189*5113495bSYour Name } else {
190*5113495bSYour Name qdf_nbuf_set_tid(msdu,
191*5113495bSYour Name QDF_NBUF_TX_EXT_TID_INVALID);
192*5113495bSYour Name }
193*5113495bSYour Name
194*5113495bSYour Name if (!ol_txrx_fwd_desc_thresh_check(vdev)) {
195*5113495bSYour Name /* Drop the packet*/
196*5113495bSYour Name htt_rx_msdu_desc_free(pdev->htt_pdev, msdu);
197*5113495bSYour Name TXRX_STATS_MSDU_LIST_INCR(
198*5113495bSYour Name pdev, tx.dropped.host_reject, msdu);
199*5113495bSYour Name /* add NULL terminator */
200*5113495bSYour Name qdf_nbuf_set_next(msdu, NULL);
201*5113495bSYour Name qdf_nbuf_tx_free(msdu,
202*5113495bSYour Name QDF_NBUF_PKT_ERROR);
203*5113495bSYour Name msdu = msdu_list;
204*5113495bSYour Name continue;
205*5113495bSYour Name }
206*5113495bSYour Name
207*5113495bSYour Name if (pdev->cfg.is_high_latency)
208*5113495bSYour Name off = htt_rx_msdu_rx_desc_size_hl(
209*5113495bSYour Name pdev->htt_pdev,
210*5113495bSYour Name rx_desc);
211*5113495bSYour Name
212*5113495bSYour Name if (vdev->opmode == wlan_op_mode_ap &&
213*5113495bSYour Name __qdf_nbuf_data_is_ipv4_eapol_pkt(
214*5113495bSYour Name qdf_nbuf_data(msdu) + off) &&
215*5113495bSYour Name qdf_mem_cmp(qdf_nbuf_data(msdu) +
216*5113495bSYour Name QDF_NBUF_DEST_MAC_OFFSET,
217*5113495bSYour Name vdev->mac_addr.raw,
218*5113495bSYour Name QDF_MAC_ADDR_SIZE)) {
219*5113495bSYour Name TXRX_STATS_MSDU_LIST_INCR(
220*5113495bSYour Name pdev, tx.dropped.host_reject, msdu);
221*5113495bSYour Name qdf_nbuf_set_next(msdu, NULL);
222*5113495bSYour Name qdf_nbuf_tx_free(msdu, QDF_NBUF_PKT_ERROR);
223*5113495bSYour Name msdu = msdu_list;
224*5113495bSYour Name continue;
225*5113495bSYour Name }
226*5113495bSYour Name
227*5113495bSYour Name /*
228*5113495bSYour Name * This MSDU needs to be forwarded to the tx path.
229*5113495bSYour Name * Check whether it also needs to be sent to the OS
230*5113495bSYour Name * shim, in which case we need to make a copy
231*5113495bSYour Name * (or clone?).
232*5113495bSYour Name */
233*5113495bSYour Name if (htt_rx_msdu_discard(pdev->htt_pdev, rx_desc)) {
234*5113495bSYour Name htt_rx_msdu_desc_free(pdev->htt_pdev, msdu);
235*5113495bSYour Name ol_rx_fwd_to_tx(tx_vdev, msdu);
236*5113495bSYour Name msdu = NULL; /* already handled this MSDU */
237*5113495bSYour Name tx_vdev->fwd_tx_packets++;
238*5113495bSYour Name vdev->fwd_rx_packets++;
239*5113495bSYour Name TXRX_STATS_ADD(pdev,
240*5113495bSYour Name pub.rx.intra_bss_fwd.packets_fwd, 1);
241*5113495bSYour Name } else {
242*5113495bSYour Name qdf_nbuf_t copy;
243*5113495bSYour Name
244*5113495bSYour Name copy = qdf_nbuf_copy(msdu);
245*5113495bSYour Name if (copy) {
246*5113495bSYour Name ol_rx_fwd_to_tx(tx_vdev, copy);
247*5113495bSYour Name tx_vdev->fwd_tx_packets++;
248*5113495bSYour Name }
249*5113495bSYour Name TXRX_STATS_ADD(pdev,
250*5113495bSYour Name pub.rx.intra_bss_fwd.packets_stack_n_fwd, 1);
251*5113495bSYour Name }
252*5113495bSYour Name } else {
253*5113495bSYour Name TXRX_STATS_ADD(pdev,
254*5113495bSYour Name pub.rx.intra_bss_fwd.packets_stack, 1);
255*5113495bSYour Name }
256*5113495bSYour Name if (msdu) {
257*5113495bSYour Name /* send this frame to the OS */
258*5113495bSYour Name OL_TXRX_LIST_APPEND(deliver_list_head,
259*5113495bSYour Name deliver_list_tail, msdu);
260*5113495bSYour Name }
261*5113495bSYour Name msdu = msdu_list;
262*5113495bSYour Name }
263*5113495bSYour Name if (deliver_list_head) {
264*5113495bSYour Name /* add NULL terminator */
265*5113495bSYour Name qdf_nbuf_set_next(deliver_list_tail, NULL);
266*5113495bSYour Name if (ol_cfg_is_full_reorder_offload(pdev->ctrl_pdev)) {
267*5113495bSYour Name ol_rx_in_order_deliver(vdev, peer, tid,
268*5113495bSYour Name deliver_list_head);
269*5113495bSYour Name } else {
270*5113495bSYour Name ol_rx_deliver(vdev, peer, tid, deliver_list_head);
271*5113495bSYour Name }
272*5113495bSYour Name }
273*5113495bSYour Name }
274*5113495bSYour Name
275*5113495bSYour Name /*
276*5113495bSYour Name * ol_get_intra_bss_fwd_pkts_count() - to get the total tx and rx packets
277*5113495bSYour Name * that has been forwarded from txrx layer without going to upper layers.
278*5113495bSYour Name * @soc_hdl: Datapath soc handle
279*5113495bSYour Name * @vdev_id: vdev id
280*5113495bSYour Name * @fwd_tx_packets: pointer to forwarded tx packets count parameter
281*5113495bSYour Name * @fwd_rx_packets: pointer to forwarded rx packets count parameter
282*5113495bSYour Name *
283*5113495bSYour Name * Return: status -> A_OK - success, A_ERROR - failure
284*5113495bSYour Name */
ol_get_intra_bss_fwd_pkts_count(struct cdp_soc_t * soc_hdl,uint8_t vdev_id,uint64_t * fwd_tx_packets,uint64_t * fwd_rx_packets)285*5113495bSYour Name A_STATUS ol_get_intra_bss_fwd_pkts_count(struct cdp_soc_t *soc_hdl,
286*5113495bSYour Name uint8_t vdev_id,
287*5113495bSYour Name uint64_t *fwd_tx_packets,
288*5113495bSYour Name uint64_t *fwd_rx_packets)
289*5113495bSYour Name {
290*5113495bSYour Name struct ol_txrx_vdev_t *vdev = NULL;
291*5113495bSYour Name
292*5113495bSYour Name vdev = (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(vdev_id);
293*5113495bSYour Name if (!vdev)
294*5113495bSYour Name return A_ERROR;
295*5113495bSYour Name
296*5113495bSYour Name *fwd_tx_packets = vdev->fwd_tx_packets;
297*5113495bSYour Name *fwd_rx_packets = vdev->fwd_rx_packets;
298*5113495bSYour Name return A_OK;
299*5113495bSYour Name }
300*5113495bSYour Name
301