xref: /wlan-dirver/qca-wifi-host-cmn/hif/src/sdio/hif_sdio.c (revision dd4dc88b837a295134aa9869114a2efee0f4894b)
1 /*
2  * Copyright (c) 2013-2019 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 #include <qdf_types.h>
20 #include <qdf_status.h>
21 #include <qdf_timer.h>
22 #include <qdf_time.h>
23 #include <qdf_lock.h>
24 #include <qdf_mem.h>
25 #include <qdf_util.h>
26 #include <qdf_defer.h>
27 #include <qdf_atomic.h>
28 #include <qdf_nbuf.h>
29 #include <athdefs.h>
30 #include "qdf_net_types.h"
31 #include "a_types.h"
32 #include "athdefs.h"
33 #include "a_osapi.h"
34 #include <hif.h>
35 #include <htc_services.h>
36 #include <a_debug.h>
37 #include "hif_sdio_dev.h"
38 #include "if_sdio.h"
39 #include "regtable_sdio.h"
40 
41 #define ATH_MODULE_NAME hif_sdio
42 
43 /**
44  * hif_start() - start hif bus interface.
45  * @hif_ctx: HIF context
46  *
47  * Enables hif device interrupts
48  *
49  * Return: int
50  */
51 uint32_t hif_start(struct hif_opaque_softc *hif_ctx)
52 {
53 	struct hif_sdio_softc *scn = HIF_GET_SDIO_SOFTC(hif_ctx);
54 	struct hif_sdio_dev *hif_device = scn->hif_handle;
55 	struct hif_sdio_device *htc_sdio_device = hif_dev_from_hif(hif_device);
56 
57 	HIF_ENTER();
58 	hif_dev_enable_interrupts(htc_sdio_device);
59 	HIF_EXIT();
60 	return QDF_STATUS_SUCCESS;
61 }
62 
63 /**
64  * hif_flush_surprise_remove() - remove hif bus interface.
65  * @hif_ctx: HIF context
66  *
67  *
68  * Return: none
69  */
70 void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx)
71 {
72 
73 }
74 
75 /**
76  * hif_sdio_stop() - stop hif bus interface.
77  * @hif_ctx: HIF context
78  *
79  * Disable hif device interrupts and destroy hif context
80  *
81  * Return: none
82  */
83 void hif_sdio_stop(struct hif_softc *hif_ctx)
84 {
85 	struct hif_sdio_softc *scn = HIF_GET_SDIO_SOFTC(hif_ctx);
86 	struct hif_sdio_dev *hif_device = scn->hif_handle;
87 	struct hif_sdio_device *htc_sdio_device = hif_dev_from_hif(hif_device);
88 
89 	HIF_ENTER();
90 	if (htc_sdio_device) {
91 		hif_dev_disable_interrupts(htc_sdio_device);
92 		hif_dev_destroy(htc_sdio_device);
93 	}
94 	HIF_EXIT();
95 }
96 
97 /**
98  * hif_send_head() - send data on hif bus interface.
99  * @hif_ctx: HIF context
100  *
101  * send tx data on a given pipe id
102  *
103  * Return: int
104  */
105 QDF_STATUS hif_send_head(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
106 		uint32_t transfer_id, uint32_t nbytes, qdf_nbuf_t buf,
107 		uint32_t data_attr)
108 {
109 	struct hif_sdio_softc *scn = HIF_GET_SDIO_SOFTC(hif_ctx);
110 	struct hif_sdio_dev *hif_device = scn->hif_handle;
111 	struct hif_sdio_device *htc_sdio_device = hif_dev_from_hif(hif_device);
112 
113 	return hif_dev_send_buffer(htc_sdio_device,
114 				transfer_id, pipe,
115 				nbytes, buf);
116 }
117 
118 /**
119  * hif_map_service_to_pipe() - maps ul/dl pipe to service id.
120  * @hif_ctx: HIF hdl
121  * @ServiceId: sevice index
122  * @ULPipe: uplink pipe id
123  * @DLPipe: down-linklink pipe id
124  * @ul_is_polled: if ul is polling based
125  * @ul_is_polled: if dl is polling based
126  *
127  * Return: int
128  */
129 int hif_map_service_to_pipe(struct hif_opaque_softc *hif_hdl,
130 			    uint16_t service_id, uint8_t *ul_pipe,
131 			    uint8_t *dl_pipe, int *ul_is_polled,
132 			    int *dl_is_polled)
133 {
134 	struct hif_sdio_softc *scn = HIF_GET_SDIO_SOFTC(hif_hdl);
135 	struct hif_sdio_dev *hif_device = scn->hif_handle;
136 
137 	return hif_dev_map_service_to_pipe(hif_device,
138 					   service_id, ul_pipe, dl_pipe);
139 }
140 
141 /**
142  * hif_map_service_to_pipe() - maps ul/dl pipe to service id.
143  * @scn: HIF context
144  * @ServiceId: sevice index
145  * @ULPipe: uplink pipe id
146  * @DLPipe: down-linklink pipe id
147  * @ul_is_polled: if ul is polling based
148  * @ul_is_polled: if dl is polling based
149  *
150  * Return: int
151  */
152 void hif_get_default_pipe(struct hif_opaque_softc *scn, uint8_t *ul_pipe,
153 			  uint8_t *dl_pipe)
154 {
155 	hif_map_service_to_pipe(scn, HTC_CTRL_RSVD_SVC,
156 				ul_pipe, dl_pipe, NULL, NULL);
157 }
158 
159 /**
160  * hif_post_init() - create hif device after probe.
161  * @hif_ctx: HIF context
162  * @target: HIF target
163  * @callbacks: htc callbacks
164  *
165  *
166  * Return: int
167  */
168 void hif_post_init(struct hif_opaque_softc *hif_ctx, void *target,
169 		   struct hif_msg_callbacks *callbacks)
170 {
171 	struct hif_sdio_softc *scn = HIF_GET_SDIO_SOFTC(hif_ctx);
172 	struct hif_sdio_dev *hif_device = scn->hif_handle;
173 	struct hif_sdio_device *htc_sdio_device = hif_dev_from_hif(hif_device);
174 
175 	HIF_ENTER();
176 
177 	if (!htc_sdio_device)
178 		htc_sdio_device = hif_dev_create(hif_device, callbacks, target);
179 
180 	if (htc_sdio_device)
181 		hif_dev_setup(htc_sdio_device);
182 
183 	HIF_EXIT();
184 }
185 
186 /**
187  * hif_get_free_queue_number() - create hif device after probe.
188  * @hif_ctx: HIF context
189  * @pipe: pipe id
190  *
191  * SDIO uses credit based flow control at the HTC layer
192  * so transmit resource checks are bypassed
193  * Return: int
194  */
195 uint16_t hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx,
196 				   uint8_t pipe)
197 {
198 	uint16_t rv;
199 
200 	rv = 1;
201 	return rv;
202 }
203 
204 /**
205  * hif_send_complete_check() - check tx complete on a given pipe.
206  * @hif_ctx: HIF context
207  * @pipe: HIF target
208  * @force: check if need to pool for completion
209  * Decide whether to actually poll for completions, or just
210  * wait for a later chance.
211  *
212  * Return: int
213  */
214 void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
215 				int force)
216 {
217 
218 }
219 
220