1 /*
2 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 /**
18 * DOC: osif_dp_lro.c
19 * This file contains DP component's LRO osif API implementation
20 */
21 #include "os_if_dp_lro.h"
22 #include <wlan_objmgr_vdev_obj.h>
23 #include <linux/inet_lro.h>
24 #include <linux/list.h>
25 #include <linux/random.h>
26 #include <net/tcp.h>
27
28 #define LRO_VALID_FIELDS \
29 (LRO_DESC | LRO_ELIGIBILITY_CHECKED | LRO_TCP_ACK_NUM | \
30 LRO_TCP_DATA_CSUM | LRO_TCP_SEQ_NUM | LRO_TCP_WIN)
31
32 #if defined(QCA_WIFI_QCA6290) || defined(QCA_WIFI_QCA6390) || \
33 defined(QCA_WIFI_QCA6490) || defined(QCA_WIFI_QCA6750) || \
34 defined(QCA_WIFI_KIWI) || defined(QCA_WIFI_WCN6450)
35 #ifdef WLAN_FEATURE_LRO_CTX_IN_CB
osif_dp_get_lro_ctx(struct sk_buff * skb)36 static qdf_lro_ctx_t osif_dp_get_lro_ctx(struct sk_buff *skb)
37 {
38 return (qdf_lro_ctx_t)QDF_NBUF_CB_RX_LRO_CTX(skb);
39 }
40 #else
osif_dp_get_lro_ctx(struct sk_buff * skb)41 static qdf_lro_ctx_t osif_dp_get_lro_ctx(struct sk_buff *skb)
42 {
43 struct hif_opaque_softc *hif_hdl =
44 (struct hif_opaque_softc *)cds_get_context(QDF_MODULE_ID_HIF);
45 if (!hif_hdl)
46 return NULL;
47
48 return hif_get_lro_info(QDF_NBUF_CB_RX_CTX_ID(skb), hif_hdl);
49 }
50 #endif
51
52 /**
53 * osif_dp_lro_rx() - LRO receive function
54 * @dev: netdev
55 * @nbuf: network buffer
56 *
57 * Delivers LRO eligible frames to the LRO manager
58 *
59 * Return: QDF_STATUS_SUCCESS - frame delivered to LRO manager
60 * QDF_STATUS_E_FAILURE - frame not delivered
61 */
osif_dp_lro_rx(qdf_netdev_t dev,qdf_nbuf_t nbuf)62 QDF_STATUS osif_dp_lro_rx(qdf_netdev_t dev, qdf_nbuf_t nbuf)
63 {
64 qdf_lro_ctx_t ctx;
65 QDF_STATUS status = QDF_STATUS_E_FAILURE;
66 struct qdf_lro_info info;
67 struct net_lro_desc *lro_desc = NULL;
68 struct sk_buff * skb = (struct sk_buff *)nbuf;
69
70 if ((dev->features & NETIF_F_LRO) != NETIF_F_LRO)
71 return QDF_STATUS_E_NOSUPPORT;
72
73 ctx = osif_dp_get_lro_ctx(skb);
74 if (!ctx) {
75 osif_err("LRO mgr is NULL");
76 return status;
77 }
78
79 info.iph = skb->data;
80 info.tcph = skb->data + QDF_NBUF_CB_RX_TCP_OFFSET(skb);
81 ctx->lro_mgr->dev = dev;
82 if (qdf_lro_get_info(ctx, skb, &info, (void **)&lro_desc)) {
83 struct net_lro_info dp_lro_info;
84
85 dp_lro_info.valid_fields = LRO_VALID_FIELDS;
86
87 dp_lro_info.lro_desc = lro_desc;
88 dp_lro_info.lro_eligible = 1;
89 dp_lro_info.tcp_ack_num = QDF_NBUF_CB_RX_TCP_ACK_NUM(skb);
90 dp_lro_info.tcp_data_csum =
91 csum_unfold(htons(QDF_NBUF_CB_RX_TCP_CHKSUM(skb)));
92 dp_lro_info.tcp_seq_num = QDF_NBUF_CB_RX_TCP_SEQ_NUM(skb);
93 dp_lro_info.tcp_win = QDF_NBUF_CB_RX_TCP_WIN(skb);
94
95 lro_receive_skb_ext(ctx->lro_mgr, skb, NULL,
96 &dp_lro_info);
97
98 if (!dp_lro_info.lro_desc->active)
99 qdf_lro_desc_free(ctx, lro_desc);
100
101 status = QDF_STATUS_SUCCESS;
102 } else {
103 qdf_lro_flush_pkt(ctx, &info);
104 }
105 return status;
106 }
107
108 /**
109 * osif_dp_lro_display_stats() - display LRO statistics
110 * @vdev: vdev objmgr context
111 *
112 * Return: none
113 */
osif_dp_lro_display_stats(struct wlan_vdev_objmgr * vdev)114 void osif_dp_lro_display_stats(struct wlan_vdev_objmgr *vdev)
115 {
116 osif_debug("LRO stats is broken, will fix it");
117 }
118
119 QDF_STATUS
osif_dp_lro_set_reset(struct wlan_vdev_objmgr * vdev,uint8_t enable_flag)120 osif_dp_lro_set_reset(struct wlan_vdev_objmgr *vdev, uint8_t enable_flag)
121 {
122 struct vdev_osif_priv *osif_priv;
123 struct net_device *dev;
124 QDF_STATUS status;
125
126 osif_priv = wlan_vdev_get_ospriv(vdev);
127 dev = osif_priv->wdev->netdev;
128
129 status = ucfg_dp_lro_set_reset(vdev, enable_flag);
130 if (QDF_IS_STATUS_ERROR(status))
131 return 0;
132
133 if (enable_flag)
134 dev->features |= NETIF_F_LRO;
135 else
136 dev->features &= ~NETIF_F_LRO;
137
138 return 0;
139 }
140