blob: 4f057a4106dedd80c8e357c4d865cad14f1c2f72 [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Houston Hoffman47e387b2015-10-20 17:04:42 -07002 * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28#ifndef _HTC_INTERNAL_H_
29#define _HTC_INTERNAL_H_
30
31#ifdef __cplusplus
32extern "C" {
33#endif /* __cplusplus */
34
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080035#include "htc_api.h"
36#include "htc_packet.h"
Yue Mab16cf302016-03-08 18:30:25 -080037#include <hif.h>
38#include <htc.h>
39#include <qdf_atomic.h>
40#include <qdf_event.h>
41#include <qdf_lock.h>
42#include <qdf_nbuf.h>
43#include <qdf_timer.h>
44#include <qdf_types.h>
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080045
46/* HTC operational parameters */
47#define HTC_TARGET_RESPONSE_TIMEOUT 2000 /* in ms */
48#define HTC_TARGET_DEBUG_INTR_MASK 0x01
49#define HTC_TARGET_CREDIT_INTR_MASK 0xF0
50#define HTC_MIN_MSG_PER_BUNDLE 2
51#if defined(HIF_USB)
52#define HTC_MAX_MSG_PER_BUNDLE 9
53#else
54#define HTC_MAX_MSG_PER_BUNDLE 16
55#endif
56/*
57 * HTC_MAX_TX_BUNDLE_SEND_LIMIT -
58 * This value is in units of tx frame fragments.
59 * It needs to be at least as large as the maximum number of tx frames in a
60 * HTC download bundle times the average number of fragments in each such frame
61 * (In certain operating systems, such as Linux, we expect to only have
62 * a single fragment per frame anyway.)
63 */
64#define HTC_MAX_TX_BUNDLE_SEND_LIMIT 255
65
66#define HTC_PACKET_CONTAINER_ALLOCATION 32
67#define NUM_CONTROL_TX_BUFFERS 2
68#define HTC_CONTROL_BUFFER_SIZE (HTC_MAX_CONTROL_MESSAGE_LENGTH + HTC_HDR_LENGTH)
69#define HTC_CONTROL_BUFFER_ALIGN 32
70#define HTC_TARGET_RESPONSE_POLL_MS 10
71#if !defined(A_SIMOS_DEVHOST)
72#define HTC_TARGET_MAX_RESPONSE_POLL 200 /* actual HW */
73#else
74#define HTC_TARGET_MAX_RESPONSE_POLL 600 /* host + target simulation */
75#endif
76
77#define HTC_SERVICE_TX_PACKET_TAG HTC_TX_PACKET_TAG_INTERNAL
78
79#define HTC_CREDIT_HISTORY_MAX 1024
80
Yue Maec9e71c2016-02-26 18:52:20 -080081#define HTC_IS_EPPING_ENABLED(_x) ((_x) == QDF_GLOBAL_EPPING_MODE)
82
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080083typedef enum {
84 HTC_REQUEST_CREDIT,
85 HTC_PROCESS_CREDIT_REPORT,
86 HTC_SUSPEND_ACK,
87 HTC_SUSPEND_NACK,
88} htc_credit_exchange_type;
89
90typedef struct {
91 htc_credit_exchange_type type;
92 uint64_t time;
93 uint32_t tx_credit;
94 uint32_t htc_tx_queue_depth;
95} HTC_CREDIT_HISTORY;
96
97typedef struct _HTC_ENDPOINT {
98 HTC_ENDPOINT_ID Id;
Houston Hoffman4f2f4592015-10-20 18:00:29 -070099
100 /* service ID this endpoint is bound to
101 * non-zero value means this endpoint is in use
102 */
103 HTC_SERVICE_ID service_id;
104
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800105 HTC_EP_CALLBACKS EpCallBacks; /* callbacks associated with this endpoint */
106 HTC_PACKET_QUEUE TxQueue; /* HTC frame buffer TX queue */
107 int MaxTxQueueDepth; /* max depth of the TX queue before we need to
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530108 call driver's full handler */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800109 int MaxMsgLength; /* max length of endpoint message */
110 uint8_t UL_PipeID;
111 uint8_t DL_PipeID;
112 int ul_is_polled; /* Need to call HIF to get tx completion callbacks? */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530113 qdf_timer_t ul_poll_timer;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800114 int ul_poll_timer_active;
115 int ul_outstanding_cnt;
116 int dl_is_polled; /* Need to call HIF to fetch rx? (Not currently supported.) */
117#if 0 /* not currently supported */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530118 qdf_timer_t dl_poll_timer;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800119#endif
120
121 HTC_PACKET_QUEUE TxLookupQueue; /* lookup queue to match netbufs to htc packets */
122 HTC_PACKET_QUEUE RxBufferHoldQueue; /* temporary hold queue for back compatibility */
Yue Mab16cf302016-03-08 18:30:25 -0800123 uint8_t SeqNo; /* TX seq no (helpful) for debugging */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530124 qdf_atomic_t TxProcessCount; /* serialization */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800125 struct _HTC_TARGET *target;
126 int TxCredits; /* TX credits available on this endpoint */
127 int TxCreditSize; /* size in bytes of each credit (set by HTC) */
128 int TxCreditsPerMaxMsg; /* credits required per max message (precalculated) */
129#ifdef HTC_EP_STAT_PROFILING
Houston Hoffman29573d92015-10-20 17:49:44 -0700130 HTC_ENDPOINT_STATS endpoint_stats; /* endpoint statistics */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800131#endif
Yue Mab16cf302016-03-08 18:30:25 -0800132 bool TxCreditFlowEnabled;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800133} HTC_ENDPOINT;
134
135#ifdef HTC_EP_STAT_PROFILING
Houston Hoffman29573d92015-10-20 17:49:44 -0700136#define INC_HTC_EP_STAT(p, stat, count) ((p)->endpoint_stats.stat += (count))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800137#else
Houston Hoffman29573d92015-10-20 17:49:44 -0700138#define INC_HTC_EP_STAT(p, stat, count)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800139#endif
140
141typedef struct {
Yue Mab16cf302016-03-08 18:30:25 -0800142 uint16_t service_id;
143 uint8_t CreditAllocation;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800144} HTC_SERVICE_TX_CREDIT_ALLOCATION;
145
146#define HTC_MAX_SERVICE_ALLOC_ENTRIES 8
147
148/* Error codes for HTC layer packet stats*/
149enum ol_ath_htc_pkt_ecodes {
150 GET_HTC_PKT_Q_FAIL = 0, /* error- get packet at head of HTC_PACKET_Q */
151 HTC_PKT_Q_EMPTY,
152 HTC_SEND_Q_EMPTY
153};
154/* our HTC target state */
155typedef struct _HTC_TARGET {
Komal Seelam5584a7c2016-02-24 19:22:48 +0530156 struct hif_opaque_softc *hif_dev;
Houston Hoffman29573d92015-10-20 17:49:44 -0700157 HTC_ENDPOINT endpoint[ENDPOINT_MAX];
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530158 qdf_spinlock_t HTCLock;
159 qdf_spinlock_t HTCRxLock;
160 qdf_spinlock_t HTCTxLock;
161 qdf_spinlock_t HTCCreditLock;
Yue Mab16cf302016-03-08 18:30:25 -0800162 uint32_t HTCStateFlags;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800163 void *host_handle;
164 HTC_INIT_INFO HTCInitInfo;
165 HTC_PACKET *pHTCPacketStructPool; /* pool of HTC packets */
166 HTC_PACKET_QUEUE ControlBufferTXFreeList;
Yue Mab16cf302016-03-08 18:30:25 -0800167 uint8_t CtrlResponseBuffer[HTC_MAX_CONTROL_MESSAGE_LENGTH];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800168 int CtrlResponseLength;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530169 qdf_event_t ctrl_response_valid;
Yue Mab16cf302016-03-08 18:30:25 -0800170 bool CtrlResponseProcessing;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800171 int TotalTransmitCredits;
172 HTC_SERVICE_TX_CREDIT_ALLOCATION
173 ServiceTxAllocTable[HTC_MAX_SERVICE_ALLOC_ENTRIES];
174 int TargetCreditSize;
175#ifdef RX_SG_SUPPORT
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530176 qdf_nbuf_queue_t RxSgQueue;
Yue Mab16cf302016-03-08 18:30:25 -0800177 bool IsRxSgInprogress;
178 uint32_t CurRxSgTotalLen; /* current total length */
179 uint32_t ExpRxSgTotalLen; /* expected total length */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800180#endif
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530181 qdf_device_t osdev;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800182 struct ol_ath_htc_stats htc_pkt_stats;
183 HTC_PACKET *pBundleFreeList;
Yue Mab16cf302016-03-08 18:30:25 -0800184 uint32_t ce_send_cnt;
185 uint32_t TX_comp_cnt;
186 uint8_t MaxMsgsPerHTCBundle;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530187 qdf_work_t queue_kicker;
Yue Maec9e71c2016-02-26 18:52:20 -0800188 uint32_t con_mode;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800189} HTC_TARGET;
190
191#define HTC_ENABLE_BUNDLE(target) (target->MaxMsgsPerHTCBundle > 1)
192#ifdef RX_SG_SUPPORT
193#define RESET_RX_SG_CONFIG(_target) \
194 _target->ExpRxSgTotalLen = 0; \
195 _target->CurRxSgTotalLen = 0; \
196 _target->IsRxSgInprogress = false;
197#endif
198
199#define HTC_STATE_STOPPING (1 << 0)
200#define HTC_STOPPING(t) ((t)->HTCStateFlags & HTC_STATE_STOPPING)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530201#define LOCK_HTC(t) qdf_spin_lock_bh(&(t)->HTCLock);
202#define UNLOCK_HTC(t) qdf_spin_unlock_bh(&(t)->HTCLock);
203#define LOCK_HTC_RX(t) qdf_spin_lock_bh(&(t)->HTCRxLock);
204#define UNLOCK_HTC_RX(t) qdf_spin_unlock_bh(&(t)->HTCRxLock);
205#define LOCK_HTC_TX(t) qdf_spin_lock_bh(&(t)->HTCTxLock);
206#define UNLOCK_HTC_TX(t) qdf_spin_unlock_bh(&(t)->HTCTxLock);
207#define LOCK_HTC_CREDIT(t) qdf_spin_lock_bh(&(t)->HTCCreditLock);
208#define UNLOCK_HTC_CREDIT(t) qdf_spin_unlock_bh(&(t)->HTCCreditLock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800209
210#define GET_HTC_TARGET_FROM_HANDLE(hnd) ((HTC_TARGET *)(hnd))
211
212#define IS_TX_CREDIT_FLOW_ENABLED(ep) ((ep)->TxCreditFlowEnabled)
213
214#define HTC_POLL_CLEANUP_PERIOD_MS 10 /* milliseconds */
215
216/* Macro to Increment the HTC_PACKET_ERRORS for Tx.*/
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530217#define OL_ATH_HTC_PKT_ERROR_COUNT_INCR(_target, _ecode) \
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800218 do { \
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530219 if (_ecode == GET_HTC_PKT_Q_FAIL) \
220 (_target->htc_pkt_stats.htc_get_pkt_q_fail_count) += 1 \
221 ; \
222 if (_ecode == HTC_PKT_Q_EMPTY) \
223 (_target->htc_pkt_stats.htc_pkt_q_empty_count) += 1 \
224 ; \
225 if (_ecode == HTC_SEND_Q_EMPTY) \
226 (_target->htc_pkt_stats.htc_send_q_empty_count) += 1 \
227 ; \
228 } while (0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800229/* internal HTC functions */
230
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530231QDF_STATUS htc_rx_completion_handler(void *Context, qdf_nbuf_t netbuf,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800232 uint8_t pipeID);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +0530233QDF_STATUS htc_tx_completion_handler(void *Context, qdf_nbuf_t netbuf,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800234 unsigned int transferID, uint32_t toeplitz_hash_result);
235
236HTC_PACKET *allocate_htc_bundle_packet(HTC_TARGET *target);
237void free_htc_bundle_packet(HTC_TARGET *target, HTC_PACKET *pPacket);
238
239HTC_PACKET *allocate_htc_packet_container(HTC_TARGET *target);
240void free_htc_packet_container(HTC_TARGET *target, HTC_PACKET *pPacket);
241void htc_flush_rx_hold_queue(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint);
242void htc_flush_endpoint_tx(HTC_TARGET *target, HTC_ENDPOINT *pEndpoint,
243 HTC_TX_TAG Tag);
244void htc_recv_init(HTC_TARGET *target);
245A_STATUS htc_wait_recv_ctrl_message(HTC_TARGET *target);
246void htc_free_control_tx_packet(HTC_TARGET *target, HTC_PACKET *pPacket);
247HTC_PACKET *htc_alloc_control_tx_packet(HTC_TARGET *target);
Yue Mab16cf302016-03-08 18:30:25 -0800248uint8_t htc_get_credit_allocation(HTC_TARGET *target, uint16_t service_id);
249void htc_tx_resource_avail_handler(void *context, uint8_t pipeID);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800250void htc_control_rx_complete(void *Context, HTC_PACKET *pPacket);
251void htc_process_credit_rpt(HTC_TARGET *target,
252 HTC_CREDIT_REPORT *pRpt,
253 int NumEntries, HTC_ENDPOINT_ID FromEndpoint);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530254void htc_fw_event_handler(void *context, QDF_STATUS status);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800255void htc_send_complete_check_cleanup(void *context);
Yue Maec9e71c2016-02-26 18:52:20 -0800256#ifdef FEATURE_RUNTIME_PM
Houston Hoffman47e387b2015-10-20 17:04:42 -0700257void htc_kick_queues(void *context);
Yue Maec9e71c2016-02-26 18:52:20 -0800258#endif
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800259
260void htc_credit_record(htc_credit_exchange_type type, uint32_t tx_credit,
261 uint32_t htc_tx_queue_depth);
262
263static inline void htc_send_complete_poll_timer_stop(HTC_ENDPOINT *
264 pEndpoint) {
265 LOCK_HTC_TX(pEndpoint->target);
266 if (pEndpoint->ul_poll_timer_active) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530267 /* qdf_timer_stop(&pEndpoint->ul_poll_timer); */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800268 pEndpoint->ul_poll_timer_active = 0;
269 }
270 UNLOCK_HTC_TX(pEndpoint->target);
271}
272
273static inline void htc_send_complete_poll_timer_start(HTC_ENDPOINT *
274 pEndpoint) {
275 LOCK_HTC_TX(pEndpoint->target);
276 if (pEndpoint->ul_outstanding_cnt
277 && !pEndpoint->ul_poll_timer_active) {
278 /*
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530279 qdf_timer_start(
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800280 &pEndpoint->ul_poll_timer, HTC_POLL_CLEANUP_PERIOD_MS);
281 */
282 pEndpoint->ul_poll_timer_active = 1;
283 }
284 UNLOCK_HTC_TX(pEndpoint->target);
285}
286
287static inline void
288htc_send_complete_check(HTC_ENDPOINT *pEndpoint, int force) {
289 /*
290 * Stop the polling-cleanup timer that will result in a later call to
291 * this function. It may get started again below, if there are still
292 * outsending sends.
293 */
294 htc_send_complete_poll_timer_stop(pEndpoint);
295 /*
296 * Check whether HIF has any prior sends that have finished,
297 * have not had the post-processing done.
298 */
299 hif_send_complete_check(pEndpoint->target->hif_dev,
300 pEndpoint->UL_PipeID, force);
301 /*
302 * If there are still outstanding sends after polling, start a timer
303 * to check again a little later.
304 */
305 htc_send_complete_poll_timer_start(pEndpoint);
306}
307
308#ifdef __cplusplus
309}
310#endif
311
312#ifndef DEBUG_BUNDLE
313#define DEBUG_BUNDLE 0
314#endif
315
316#ifdef HIF_SDIO
317#ifndef ENABLE_BUNDLE_TX
318#define ENABLE_BUNDLE_TX 1
319#endif
320
321#ifndef ENABLE_BUNDLE_RX
322#define ENABLE_BUNDLE_RX 1
323#endif
324#endif /* HIF_SDIO */
325#endif /* !_HTC_HOST_INTERNAL_H_ */