1 /*
2  * Copyright (c) 2016-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 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 #include "hal_hw_headers.h"
20 #include "hal_internal.h"
21 #include "cdp_txrx_mon_struct.h"
22 #include "qdf_trace.h"
23 #include "hal_rx.h"
24 #include "hal_tx.h"
25 #include "dp_types.h"
26 #include "hal_api_mon.h"
27 
28 /**
29  * hal_tx_desc_set_dscp_tid_table_id_8074() - Sets DSCP to TID conversion
30  *                                            table ID
31  * @desc: Handle to Tx Descriptor
32  * @id: DSCP to tid conversion table to be used for this frame
33  *
34  * Return: void
35  */
36 
hal_tx_desc_set_dscp_tid_table_id_8074(void * desc,uint8_t id)37 static void hal_tx_desc_set_dscp_tid_table_id_8074(void *desc, uint8_t id)
38 {
39 	HAL_SET_FLD(desc, TCL_DATA_CMD_3,
40 		    DSCP_TO_TID_PRIORITY_TABLE_ID) |=
41 	HAL_TX_SM(TCL_DATA_CMD_3,
42 		  DSCP_TO_TID_PRIORITY_TABLE_ID, id);
43 }
44 
45 /**
46  * hal_tx_set_dscp_tid_map_8074() - Configure default DSCP to TID map table
47  * @soc: HAL SoC context
48  * @map: DSCP-TID mapping table
49  * @id: mapping table ID - 0,1
50  *
51  * DSCP are mapped to 8 TID values using TID values programmed
52  * in two set of mapping registers DSCP_TID1_MAP_<0 to 6> (id = 0)
53  * and DSCP_TID2_MAP_<0 to 6> (id = 1)
54  * Each mapping register has TID mapping for 10 DSCP values
55  *
56  * Return: none
57  */
hal_tx_set_dscp_tid_map_8074(struct hal_soc * soc,uint8_t * map,uint8_t id)58 static void hal_tx_set_dscp_tid_map_8074(struct hal_soc *soc, uint8_t *map,
59 					 uint8_t id)
60 {
61 	int i;
62 	uint32_t addr;
63 	uint32_t value;
64 
65 	if (id == HAL_TX_DSCP_TID_MAP_TABLE_DEFAULT) {
66 		addr = HWIO_TCL_R0_DSCP_TID1_MAP_0_ADDR(
67 				SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET);
68 	} else {
69 		addr = HWIO_TCL_R0_DSCP_TID2_MAP_0_ADDR(
70 				SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET);
71 	}
72 
73 	for (i = 0; i < 64; i += 10) {
74 		value =
75 		  (map[i] |
76 		  (map[i + 1] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_1_SHFT) |
77 		  (map[i + 2] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_2_SHFT) |
78 		  (map[i + 3] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_3_SHFT) |
79 		  (map[i + 4] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_4_SHFT) |
80 		  (map[i + 5] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_5_SHFT) |
81 		  (map[i + 6] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_6_SHFT) |
82 		  (map[i + 7] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_7_SHFT) |
83 		  (map[i + 8] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_8_SHFT) |
84 		  (map[i + 9] << HWIO_TCL_R0_DSCP_TID1_MAP_0_DSCP_9_SHFT));
85 
86 		HAL_REG_WRITE(soc, addr,
87 			      (value & HWIO_TCL_R0_DSCP_TID1_MAP_1_RMSK));
88 
89 		addr += 4;
90 	}
91 }
92 
93 /**
94  * hal_tx_update_dscp_tid_8074() - Update the dscp tid map table as
95  *                                 updated by user
96  * @soc: HAL SoC context
97  * @tid: TID
98  * @id: MAP ID
99  * @dscp: DSCP
100  *
101  * Return: void
102  */
103 static
hal_tx_update_dscp_tid_8074(struct hal_soc * soc,uint8_t tid,uint8_t id,uint8_t dscp)104 void hal_tx_update_dscp_tid_8074(struct hal_soc *soc, uint8_t tid,
105 				 uint8_t id, uint8_t dscp)
106 {
107 	int index;
108 	uint32_t addr;
109 	uint32_t value;
110 	uint32_t regval;
111 
112 	if (id == HAL_TX_DSCP_TID_MAP_TABLE_DEFAULT)
113 		addr = HWIO_TCL_R0_DSCP_TID1_MAP_0_ADDR(
114 				SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET);
115 	else
116 		addr = HWIO_TCL_R0_DSCP_TID2_MAP_0_ADDR(
117 				SEQ_WCSS_UMAC_MAC_TCL_REG_OFFSET);
118 
119 	index = dscp % HAL_TX_NUM_DSCP_PER_REGISTER;
120 	addr += 4 * (dscp / HAL_TX_NUM_DSCP_PER_REGISTER);
121 	value = tid << (HAL_TX_BITS_PER_TID * index);
122 
123 	/* Read back previous DSCP TID config and update
124 	 * with new config.
125 	 */
126 	regval = HAL_REG_READ(soc, addr);
127 	regval &= ~(HAL_TX_TID_BITS_MASK << (HAL_TX_BITS_PER_TID * index));
128 	regval |= value;
129 
130 	HAL_REG_WRITE(soc, addr,
131 		      (regval & HWIO_TCL_R0_DSCP_TID1_MAP_1_RMSK));
132 }
133 
134 /**
135  * hal_tx_desc_set_lmac_id_8074() - Set the lmac_id value
136  * @desc: Handle to Tx Descriptor
137  * @lmac_id: mac Id to ast matching
138  *		     b00 – mac 0
139  *		     b01 – mac 1
140  *		     b10 – mac 2
141  *		     b11 – all macs (legacy HK way)
142  *
143  * Return: void
144  */
hal_tx_desc_set_lmac_id_8074(void * desc,uint8_t lmac_id)145 static void hal_tx_desc_set_lmac_id_8074(void *desc, uint8_t lmac_id)
146 {
147 }
148 
149 /**
150  * hal_tx_init_cmd_credit_ring_8074v1() - Initialize command/credit SRNG
151  * @hal_soc_hdl: Handle to HAL SoC structure
152  * @hal_ring_hdl: Handle to HAL SRNG structure
153  *
154  * Return: none
155  */
hal_tx_init_cmd_credit_ring_8074v1(hal_soc_handle_t hal_soc_hdl,hal_ring_handle_t hal_ring_hdl)156 static inline void hal_tx_init_cmd_credit_ring_8074v1(hal_soc_handle_t hal_soc_hdl,
157 						      hal_ring_handle_t hal_ring_hdl)
158 {
159 	uint8_t *desc_addr;
160 	struct hal_srng_params srng_params;
161 	uint32_t desc_size;
162 	uint32_t num_desc;
163 
164 	hal_get_srng_params(hal_soc_hdl, hal_ring_hdl, &srng_params);
165 
166 	desc_addr = (uint8_t *)srng_params.ring_base_vaddr;
167 	desc_size = sizeof(struct tcl_data_cmd);
168 	num_desc = srng_params.num_entries;
169 
170 	while (num_desc) {
171 		/* using CMD/CREDIT Ring to send DATA CMD tag */
172 		HAL_TX_DESC_SET_TLV_HDR(desc_addr, WIFITCL_DATA_CMD_E,
173 					desc_size);
174 		desc_addr += (desc_size + sizeof(struct tlv_32_hdr));
175 		num_desc--;
176 	}
177 }
178