hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/linux_osl.c
....@@ -1,15 +1,16 @@
1
-/* SPDX-License-Identifier: GPL-2.0 */
21 /*
32 * Linux OS Independent Layer
43 *
5
- * Copyright (C) 1999-2019, Broadcom Corporation
6
- *
4
+ * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
5
+ *
6
+ * Copyright (C) 1999-2017, Broadcom Corporation
7
+ *
78 * Unless you and Broadcom execute a separate written software license
89 * agreement governing use of this software, this software is licensed to you
910 * under the terms of the GNU General Public License version 2 (the "GPL"),
1011 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
1112 * following added to such license:
12
- *
13
+ *
1314 * As a special exception, the copyright holders of this software give you
1415 * permission to link this software with independent modules, and to copy and
1516 * distribute the resulting executable under terms of your choice, provided that
....@@ -17,7 +18,7 @@
1718 * the license of that module. An independent module is a module which is not
1819 * derived from this software. The special exception does not apply to any
1920 * modifications of the software.
20
- *
21
+ *
2122 * Notwithstanding the above, under no circumstances may you combine this
2223 * software in any way with any other Broadcom software provided under a license
2324 * other than the GPL, without Broadcom's express prior written consent.
....@@ -25,7 +26,7 @@
2526 *
2627 * <<Broadcom-WL-IPTag/Open:>>
2728 *
28
- * $Id: linux_osl.c 709309 2019-01-17 09:04:00Z $
29
+ * $Id: linux_osl.c 697654 2017-05-04 11:59:40Z $
2930 */
3031
3132 #define LINUX_PORT
....@@ -35,20 +36,21 @@
3536 #include <linuxver.h>
3637 #include <bcmdefs.h>
3738
38
-
39
-#if !defined(STBLINUX)
4039 #if defined(__ARM_ARCH_7A__) && !defined(DHD_USE_COHERENT_MEM_FOR_RING)
4140 #include <asm/cacheflush.h>
4241 #endif /* __ARM_ARCH_7A__ && !DHD_USE_COHERENT_MEM_FOR_RING */
43
-#endif /* STBLINUX */
4442
4543 #include <linux/random.h>
4644
4745 #include <osl.h>
4846 #include <bcmutils.h>
4947 #include <linux/delay.h>
48
+#include <linux/vmalloc.h>
5049 #include <pcicfg.h>
5150
51
+#if defined(BCMASSERT_LOG) && !defined(OEM_ANDROID)
52
+#include <bcm_assert_log.h>
53
+#endif // endif
5254
5355 #ifdef BCM_SECURE_DMA
5456 #include <linux/module.h>
....@@ -60,14 +62,10 @@
6062 #include <linux/moduleparam.h>
6163 #include <asm/io.h>
6264 #include <linux/skbuff.h>
63
-#include <linux/vmalloc.h>
6465 #include <stbutils.h>
6566 #include <linux/highmem.h>
6667 #include <linux/dma-mapping.h>
6768 #include <asm/memory.h>
68
-#if defined(__ARM_ARCH_7A__)
69
-#include <arch/arm/include/asm/tlbflush.h>
70
-#endif
7169 #endif /* BCM_SECURE_DMA */
7270
7371 #include <linux/fs.h>
....@@ -75,152 +73,16 @@
7573 #if defined(STB)
7674 #include <linux/spinlock.h>
7775 extern spinlock_t l2x0_reg_lock;
78
-#endif
76
+#endif // endif
7977
8078 #ifdef BCM_OBJECT_TRACE
8179 #include <bcmutils.h>
8280 #endif /* BCM_OBJECT_TRACE */
81
+#include "linux_osl_priv.h"
8382
8483 #define PCI_CFG_RETRY 10
8584
86
-#define OS_HANDLE_MAGIC 0x1234abcd /* Magic # to recognize osh */
87
-#define BCM_MEM_FILENAME_LEN 24 /* Mem. filename length */
8885 #define DUMPBUFSZ 1024
89
-
90
-/* dependancy check */
91
-#if !defined(BCMPCIE) && defined(DHD_USE_STATIC_CTRLBUF)
92
-#error "DHD_USE_STATIC_CTRLBUF suppored PCIE target only"
93
-#endif /* !BCMPCIE && DHD_USE_STATIC_CTRLBUF */
94
-
95
-#ifdef CONFIG_DHD_USE_STATIC_BUF
96
-#ifdef DHD_USE_STATIC_CTRLBUF
97
-#define DHD_SKB_1PAGE_BUFSIZE (PAGE_SIZE*1)
98
-#define DHD_SKB_2PAGE_BUFSIZE (PAGE_SIZE*2)
99
-#define DHD_SKB_4PAGE_BUFSIZE (PAGE_SIZE*4)
100
-
101
-#define PREALLOC_FREE_MAGIC 0xFEDC
102
-#define PREALLOC_USED_MAGIC 0xFCDE
103
-#else
104
-#define DHD_SKB_HDRSIZE 336
105
-#define DHD_SKB_1PAGE_BUFSIZE ((PAGE_SIZE*1)-DHD_SKB_HDRSIZE)
106
-#define DHD_SKB_2PAGE_BUFSIZE ((PAGE_SIZE*2)-DHD_SKB_HDRSIZE)
107
-#define DHD_SKB_4PAGE_BUFSIZE ((PAGE_SIZE*4)-DHD_SKB_HDRSIZE)
108
-#endif /* DHD_USE_STATIC_CTRLBUF */
109
-
110
-#define STATIC_BUF_MAX_NUM 16
111
-#define STATIC_BUF_SIZE (PAGE_SIZE*2)
112
-#define STATIC_BUF_TOTAL_LEN (STATIC_BUF_MAX_NUM * STATIC_BUF_SIZE)
113
-
114
-typedef struct bcm_static_buf {
115
- spinlock_t static_lock;
116
- unsigned char *buf_ptr;
117
- unsigned char buf_use[STATIC_BUF_MAX_NUM];
118
-} bcm_static_buf_t;
119
-
120
-static bcm_static_buf_t *bcm_static_buf = 0;
121
-
122
-#ifdef DHD_USE_STATIC_CTRLBUF
123
-#define STATIC_PKT_4PAGE_NUM 0
124
-#define DHD_SKB_MAX_BUFSIZE DHD_SKB_2PAGE_BUFSIZE
125
-#elif defined(ENHANCED_STATIC_BUF)
126
-#define STATIC_PKT_4PAGE_NUM 1
127
-#define DHD_SKB_MAX_BUFSIZE DHD_SKB_4PAGE_BUFSIZE
128
-#else
129
-#define STATIC_PKT_4PAGE_NUM 0
130
-#define DHD_SKB_MAX_BUFSIZE DHD_SKB_2PAGE_BUFSIZE
131
-#endif /* DHD_USE_STATIC_CTRLBUF */
132
-
133
-#ifdef DHD_USE_STATIC_CTRLBUF
134
-#define STATIC_PKT_1PAGE_NUM 0
135
-#define STATIC_PKT_2PAGE_NUM 64
136
-#else
137
-#define STATIC_PKT_1PAGE_NUM 8
138
-#define STATIC_PKT_2PAGE_NUM 8
139
-#endif /* DHD_USE_STATIC_CTRLBUF */
140
-
141
-#define STATIC_PKT_1_2PAGE_NUM \
142
- ((STATIC_PKT_1PAGE_NUM) + (STATIC_PKT_2PAGE_NUM))
143
-#define STATIC_PKT_MAX_NUM \
144
- ((STATIC_PKT_1_2PAGE_NUM) + (STATIC_PKT_4PAGE_NUM))
145
-
146
-typedef struct bcm_static_pkt {
147
-#ifdef DHD_USE_STATIC_CTRLBUF
148
- struct sk_buff *skb_8k[STATIC_PKT_2PAGE_NUM];
149
- unsigned char pkt_invalid[STATIC_PKT_2PAGE_NUM];
150
- spinlock_t osl_pkt_lock;
151
- uint32 last_allocated_index;
152
-#else
153
- struct sk_buff *skb_4k[STATIC_PKT_1PAGE_NUM];
154
- struct sk_buff *skb_8k[STATIC_PKT_2PAGE_NUM];
155
-#ifdef ENHANCED_STATIC_BUF
156
- struct sk_buff *skb_16k;
157
-#endif /* ENHANCED_STATIC_BUF */
158
- struct semaphore osl_pkt_sem;
159
-#endif /* DHD_USE_STATIC_CTRLBUF */
160
- unsigned char pkt_use[STATIC_PKT_MAX_NUM];
161
-} bcm_static_pkt_t;
162
-
163
-static bcm_static_pkt_t *bcm_static_skb = 0;
164
-
165
-void* wifi_platform_prealloc(void *adapter, int section, unsigned long size);
166
-#endif /* CONFIG_DHD_USE_STATIC_BUF */
167
-
168
-typedef struct bcm_mem_link {
169
- struct bcm_mem_link *prev;
170
- struct bcm_mem_link *next;
171
- uint size;
172
- int line;
173
- void *osh;
174
- char file[BCM_MEM_FILENAME_LEN];
175
-} bcm_mem_link_t;
176
-
177
-struct osl_cmn_info {
178
- atomic_t malloced;
179
- atomic_t pktalloced; /* Number of allocated packet buffers */
180
- spinlock_t dbgmem_lock;
181
- bcm_mem_link_t *dbgmem_list;
182
- spinlock_t pktalloc_lock;
183
- atomic_t refcount; /* Number of references to this shared structure. */
184
-};
185
-typedef struct osl_cmn_info osl_cmn_t;
186
-
187
-struct osl_info {
188
- osl_pubinfo_t pub;
189
- uint32 flags; /* If specific cases to be handled in the OSL */
190
-#ifdef CTFPOOL
191
- ctfpool_t *ctfpool;
192
-#endif /* CTFPOOL */
193
- uint magic;
194
- void *pdev;
195
- uint failed;
196
- uint bustype;
197
- osl_cmn_t *cmn; /* Common OSL related data shred between two OSH's */
198
-
199
- void *bus_handle;
200
-#ifdef BCMDBG_CTRACE
201
- spinlock_t ctrace_lock;
202
- struct list_head ctrace_list;
203
- int ctrace_num;
204
-#endif /* BCMDBG_CTRACE */
205
-#ifdef BCM_SECURE_DMA
206
- struct sec_mem_elem *sec_list_4096;
207
- struct sec_mem_elem *sec_list_base_4096;
208
- phys_addr_t contig_base;
209
- void *contig_base_va;
210
- phys_addr_t contig_base_alloc;
211
- void *contig_base_alloc_va;
212
- phys_addr_t contig_base_alloc_coherent;
213
- void *contig_base_alloc_coherent_va;
214
- void *contig_base_coherent_va;
215
- phys_addr_t contig_delta_va_pa;
216
- struct {
217
- phys_addr_t pa;
218
- void *va;
219
- bool avail;
220
- } sec_cma_coherent[SEC_CMA_COHERENT_MAX];
221
- int stb_ext_params;
222
-#endif /* BCM_SECURE_DMA */
223
-};
22486
22587 #ifdef BCM_SECURE_DMA
22688 static void * osl_sec_dma_ioremap(osl_t *osh, struct page *page, size_t size,
....@@ -239,39 +101,18 @@
239101 static void osl_sec_dma_free_consistent(osl_t *osh, void *va, uint size, dmaaddr_t pa);
240102 #endif /* BCM_SECURE_DMA */
241103
242
-#ifdef BCM_OBJECT_TRACE
243
-/* don't clear the first 4 byte that is the pkt sn */
244
-#define OSL_PKTTAG_CLEAR(p) \
245
-do { \
246
- struct sk_buff *s = (struct sk_buff *)(p); \
247
- ASSERT(OSL_PKTTAG_SZ == 32); \
248
- *(uint32 *)(&s->cb[4]) = 0; \
249
- *(uint32 *)(&s->cb[8]) = 0; *(uint32 *)(&s->cb[12]) = 0; \
250
- *(uint32 *)(&s->cb[16]) = 0; *(uint32 *)(&s->cb[20]) = 0; \
251
- *(uint32 *)(&s->cb[24]) = 0; *(uint32 *)(&s->cb[28]) = 0; \
252
-} while (0)
253
-#else
254
-#define OSL_PKTTAG_CLEAR(p) \
255
-do { \
256
- struct sk_buff *s = (struct sk_buff *)(p); \
257
- ASSERT(OSL_PKTTAG_SZ == 32); \
258
- *(uint32 *)(&s->cb[0]) = 0; *(uint32 *)(&s->cb[4]) = 0; \
259
- *(uint32 *)(&s->cb[8]) = 0; *(uint32 *)(&s->cb[12]) = 0; \
260
- *(uint32 *)(&s->cb[16]) = 0; *(uint32 *)(&s->cb[20]) = 0; \
261
- *(uint32 *)(&s->cb[24]) = 0; *(uint32 *)(&s->cb[28]) = 0; \
262
-} while (0)
263
-#endif /* BCM_OBJECT_TRACE */
264
-
265104 /* PCMCIA attribute space access macros */
266105
267
-/* Global ASSERT type flag */
268
-uint32 g_assert_type = 0;
269
-module_param(g_assert_type, int, 0);
106
+#ifdef CUSTOMER_HW4_DEBUG
107
+uint32 g_assert_type = 1; /* By Default not cause Kernel Panic */
108
+#else
109
+uint32 g_assert_type = 0; /* By Default Kernel Panic */
110
+#endif /* CUSTOMER_HW4_DEBUG */
270111
112
+module_param(g_assert_type, int, 0);
271113 #ifdef BCM_SECURE_DMA
272114 #define SECDMA_MODULE_PARAMS 0
273115 #define SECDMA_EXT_FILE 1
274
-
275116 unsigned long secdma_addr = 0;
276117 unsigned long secdma_addr2 = 0;
277118 u32 secdma_size = 0;
....@@ -283,8 +124,22 @@
283124 static int secdma_found = 0;
284125 #endif /* BCM_SECURE_DMA */
285126
127
+#ifdef USE_DMA_LOCK
128
+static void osl_dma_lock(osl_t *osh);
129
+static void osl_dma_unlock(osl_t *osh);
130
+static void osl_dma_lock_init(osl_t *osh);
131
+
132
+#define DMA_LOCK(osh) osl_dma_lock(osh)
133
+#define DMA_UNLOCK(osh) osl_dma_unlock(osh)
134
+#define DMA_LOCK_INIT(osh) osl_dma_lock_init(osh);
135
+#else
136
+#define DMA_LOCK(osh) do { /* noop */ } while(0)
137
+#define DMA_UNLOCK(osh) do { /* noop */ } while(0)
138
+#define DMA_LOCK_INIT(osh) do { /* noop */ } while(0)
139
+#endif /* USE_DMA_LOCK */
140
+
286141 static int16 linuxbcmerrormap[] =
287
-{ 0, /* 0 */
142
+{ 0, /* 0 */
288143 -EINVAL, /* BCME_ERROR */
289144 -EINVAL, /* BCME_BADARG */
290145 -EINVAL, /* BCME_BADOPTION */
....@@ -338,17 +193,124 @@
338193 -ERANGE, /* BCME_REPLAY */
339194 -EINVAL, /* BCME_IE_NOTFOUND */
340195 -EINVAL, /* BCME_DATA_NOTFOUND */
196
+ -EINVAL, /* BCME_NOT_GC */
197
+ -EINVAL, /* BCME_PRS_REQ_FAILED */
198
+ -EINVAL, /* BCME_NO_P2P_SE */
199
+ -EINVAL, /* BCME_NOA_PND */
200
+ -EINVAL, /* BCME_FRAG_Q_FAILED */
201
+ -EINVAL, /* BCME_GET_AF_FAILED */
202
+ -EINVAL, /* BCME_MSCH_NOTREADY */
203
+ -EINVAL, /* BCME_IOV_LAST_CMD */
204
+ -EINVAL, /* BCME_MINIPMU_CAL_FAIL */
205
+ -EINVAL, /* BCME_RCAL_FAIL */
206
+ -EINVAL, /* BCME_LPF_RCCAL_FAIL */
207
+ -EINVAL, /* BCME_DACBUF_RCCAL_FAIL */
208
+ -EINVAL, /* BCME_VCOCAL_FAIL */
209
+ -EINVAL, /* BCME_BANDLOCKED */
210
+ -EINVAL, /* BCME_DNGL_DEVRESET */
341211
342212 /* When an new error code is added to bcmutils.h, add os
343213 * specific error translation here as well
344214 */
345215 /* check if BCME_LAST changed since the last time this function was updated */
346
-#if BCME_LAST != -53
216
+#if BCME_LAST != -68
347217 #error "You need to add a OS error translation in the linuxbcmerrormap \
348218 for new error code defined in bcmutils.h"
349
-#endif
219
+#endif // endif
350220 };
351221 uint lmtest = FALSE;
222
+
223
+#ifdef DHD_MAP_LOGGING
224
+#define DHD_MAP_LOG_SIZE 2048
225
+
226
+typedef struct dhd_map_item {
227
+ dmaaddr_t pa; /* DMA address (physical) */
228
+ uint64 ts_nsec; /* timestamp: nsec */
229
+ uint32 size; /* mapping size */
230
+ uint8 rsvd[4]; /* reserved for future use */
231
+} dhd_map_item_t;
232
+
233
+typedef struct dhd_map_record {
234
+ uint32 items; /* number of total items */
235
+ uint32 idx; /* current index of metadata */
236
+ dhd_map_item_t map[0]; /* metadata storage */
237
+} dhd_map_log_t;
238
+
239
+void
240
+osl_dma_map_dump(osl_t *osh)
241
+{
242
+ dhd_map_log_t *map_log, *unmap_log;
243
+ uint64 ts_sec, ts_usec;
244
+
245
+ map_log = (dhd_map_log_t *)(osh->dhd_map_log);
246
+ unmap_log = (dhd_map_log_t *)(osh->dhd_unmap_log);
247
+ osl_get_localtime(&ts_sec, &ts_usec);
248
+
249
+ if (map_log && unmap_log) {
250
+ printk("%s: map_idx=%d unmap_idx=%d "
251
+ "current time=[%5lu.%06lu]\n", __FUNCTION__,
252
+ map_log->idx, unmap_log->idx, (unsigned long)ts_sec,
253
+ (unsigned long)ts_usec);
254
+ printk("%s: dhd_map_log(pa)=0x%llx size=%d,"
255
+ " dma_unmap_log(pa)=0x%llx size=%d\n", __FUNCTION__,
256
+ (uint64)__virt_to_phys((ulong)(map_log->map)),
257
+ (uint32)(sizeof(dhd_map_item_t) * map_log->items),
258
+ (uint64)__virt_to_phys((ulong)(unmap_log->map)),
259
+ (uint32)(sizeof(dhd_map_item_t) * unmap_log->items));
260
+ }
261
+}
262
+
263
+static void *
264
+osl_dma_map_log_init(uint32 item_len)
265
+{
266
+ dhd_map_log_t *map_log;
267
+ gfp_t flags;
268
+ uint32 alloc_size = (uint32)(sizeof(dhd_map_log_t) +
269
+ (item_len * sizeof(dhd_map_item_t)));
270
+
271
+ flags = CAN_SLEEP() ? GFP_KERNEL : GFP_ATOMIC;
272
+ map_log = (dhd_map_log_t *)kmalloc(alloc_size, flags);
273
+ if (map_log) {
274
+ memset(map_log, 0, alloc_size);
275
+ map_log->items = item_len;
276
+ map_log->idx = 0;
277
+ }
278
+
279
+ return (void *)map_log;
280
+}
281
+
282
+static void
283
+osl_dma_map_log_deinit(osl_t *osh)
284
+{
285
+ if (osh->dhd_map_log) {
286
+ kfree(osh->dhd_map_log);
287
+ osh->dhd_map_log = NULL;
288
+ }
289
+
290
+ if (osh->dhd_unmap_log) {
291
+ kfree(osh->dhd_unmap_log);
292
+ osh->dhd_unmap_log = NULL;
293
+ }
294
+}
295
+
296
+static void
297
+osl_dma_map_logging(osl_t *osh, void *handle, dmaaddr_t pa, uint32 len)
298
+{
299
+ dhd_map_log_t *log = (dhd_map_log_t *)handle;
300
+ uint32 idx;
301
+
302
+ if (log == NULL) {
303
+ printk("%s: log is NULL\n", __FUNCTION__);
304
+ return;
305
+ }
306
+
307
+ idx = log->idx;
308
+ log->map[idx].ts_nsec = osl_localtime_ns();
309
+ log->map[idx].pa = pa;
310
+ log->map[idx].size = len;
311
+ log->idx = (idx + 1) % log->items;
312
+}
313
+#endif /* DHD_MAP_LOGGING */
352314
353315 /* translate bcmerrors into linux errors */
354316 int
....@@ -362,22 +324,15 @@
362324 /* Array bounds covered by ASSERT in osl_attach */
363325 return linuxbcmerrormap[-bcmerror];
364326 }
365
-#ifdef SHARED_OSL_CMN
366
-osl_t *
367
-osl_attach(void *pdev, uint bustype, bool pkttag, void **osl_cmn)
368
-{
369
-#else
370327 osl_t *
371328 osl_attach(void *pdev, uint bustype, bool pkttag)
372329 {
373330 void **osl_cmn = NULL;
374
-#endif /* SHARED_OSL_CMN */
375331 osl_t *osh;
376332 gfp_t flags;
377
-
378333 #ifdef BCM_SECURE_DMA
379334 u32 secdma_memsize;
380
-#endif
335
+#endif // endif
381336
382337 flags = CAN_SLEEP() ? GFP_KERNEL: GFP_ATOMIC;
383338 if (!(osh = kmalloc(sizeof(osl_t), flags)))
....@@ -420,7 +375,6 @@
420375
421376 if ((secdma_addr != 0) && (secdma_size != 0)) {
422377 printk("linux_osl.c: Buffer info passed via module params, using it.\n");
423
-
424378 if (secdma_found == 0) {
425379 osh->contig_base_alloc = (phys_addr_t)secdma_addr;
426380 secdma_memsize = secdma_size;
....@@ -432,9 +386,7 @@
432386 kfree(osh);
433387 return NULL;
434388 }
435
-
436389 osh->contig_base = (phys_addr_t)osh->contig_base_alloc;
437
-
438390 printf("linux_osl.c: secdma_cma_size = 0x%x\n", secdma_memsize);
439391 printf("linux_osl.c: secdma_cma_addr = 0x%x \n",
440392 (unsigned int)osh->contig_base_alloc);
....@@ -442,7 +394,6 @@
442394 }
443395 else if (stbpriv_init(osh) == 0) {
444396 printk("linux_osl.c: stbpriv.txt found. Get buffer info.\n");
445
-
446397 if (secdma_found == 0) {
447398 osh->contig_base_alloc =
448399 (phys_addr_t)bcm_strtoul(stbparam_get("secdma_cma_addr"), NULL, 0);
....@@ -456,9 +407,7 @@
456407 kfree(osh);
457408 return NULL;
458409 }
459
-
460410 osh->contig_base = (phys_addr_t)osh->contig_base_alloc;
461
-
462411 printf("linux_osl.c: secdma_cma_size = 0x%x\n", secdma_memsize);
463412 printf("linux_osl.c: secdma_cma_addr = 0x%x \n",
464413 (unsigned int)osh->contig_base_alloc);
....@@ -469,7 +418,6 @@
469418 kfree(osh);
470419 return NULL;
471420 }
472
-
473421 secdma_found++;
474422 osh->contig_base_alloc_coherent_va = osl_sec_dma_ioremap(osh,
475423 phys_to_page((u32)osh->contig_base_alloc),
....@@ -529,66 +477,21 @@
529477 break;
530478 }
531479
532
-#ifdef BCMDBG_CTRACE
533
- spin_lock_init(&osh->ctrace_lock);
534
- INIT_LIST_HEAD(&osh->ctrace_list);
535
- osh->ctrace_num = 0;
536
-#endif /* BCMDBG_CTRACE */
480
+ DMA_LOCK_INIT(osh);
537481
482
+#ifdef DHD_MAP_LOGGING
483
+ osh->dhd_map_log = osl_dma_map_log_init(DHD_MAP_LOG_SIZE);
484
+ if (osh->dhd_map_log == NULL) {
485
+ printk("%s: Failed to alloc dhd_map_log\n", __FUNCTION__);
486
+ }
487
+
488
+ osh->dhd_unmap_log = osl_dma_map_log_init(DHD_MAP_LOG_SIZE);
489
+ if (osh->dhd_unmap_log == NULL) {
490
+ printk("%s: Failed to alloc dhd_unmap_log\n", __FUNCTION__);
491
+ }
492
+#endif /* DHD_MAP_LOGGING */
538493
539494 return osh;
540
-}
541
-
542
-int osl_static_mem_init(osl_t *osh, void *adapter)
543
-{
544
-#ifdef CONFIG_DHD_USE_STATIC_BUF
545
- if (!bcm_static_buf && adapter) {
546
- if (!(bcm_static_buf = (bcm_static_buf_t *)wifi_platform_prealloc(adapter,
547
- 3, STATIC_BUF_SIZE + STATIC_BUF_TOTAL_LEN))) {
548
- printk("can not alloc static buf!\n");
549
- bcm_static_skb = NULL;
550
- ASSERT(osh->magic == OS_HANDLE_MAGIC);
551
- return -ENOMEM;
552
- } else {
553
- printk("alloc static buf at %p!\n", bcm_static_buf);
554
- }
555
-
556
- spin_lock_init(&bcm_static_buf->static_lock);
557
-
558
- bcm_static_buf->buf_ptr = (unsigned char *)bcm_static_buf + STATIC_BUF_SIZE;
559
- }
560
-
561
-#if defined(BCMSDIO) || defined(DHD_USE_STATIC_CTRLBUF)
562
- if (!bcm_static_skb && adapter) {
563
- int i;
564
- void *skb_buff_ptr = 0;
565
- bcm_static_skb = (bcm_static_pkt_t *)((char *)bcm_static_buf + 2048);
566
- skb_buff_ptr = wifi_platform_prealloc(adapter, 4, 0);
567
- if (!skb_buff_ptr) {
568
- printk("cannot alloc static buf!\n");
569
- bcm_static_buf = NULL;
570
- bcm_static_skb = NULL;
571
- ASSERT(osh->magic == OS_HANDLE_MAGIC);
572
- return -ENOMEM;
573
- }
574
-
575
- bcopy(skb_buff_ptr, bcm_static_skb, sizeof(struct sk_buff *) *
576
- (STATIC_PKT_MAX_NUM));
577
- for (i = 0; i < STATIC_PKT_MAX_NUM; i++) {
578
- bcm_static_skb->pkt_use[i] = 0;
579
- }
580
-
581
-#ifdef DHD_USE_STATIC_CTRLBUF
582
- spin_lock_init(&bcm_static_skb->osl_pkt_lock);
583
- bcm_static_skb->last_allocated_index = 0;
584
-#else
585
- sema_init(&bcm_static_skb->osl_pkt_sem, 1);
586
-#endif /* DHD_USE_STATIC_CTRLBUF */
587
- }
588
-#endif /* BCMSDIO || DHD_USE_STATIC_CTRLBUF */
589
-#endif /* CONFIG_DHD_USE_STATIC_BUF */
590
-
591
- return 0;
592495 }
593496
594497 void osl_set_bus_handle(osl_t *osh, void *bus_handle)
....@@ -600,6 +503,16 @@
600503 {
601504 return osh->bus_handle;
602505 }
506
+
507
+#if defined(BCM_BACKPLANE_TIMEOUT)
508
+void osl_set_bpt_cb(osl_t *osh, void *bpt_cb, void *bpt_ctx)
509
+{
510
+ if (osh) {
511
+ osh->bpt_cb = (bpt_cb_fn)bpt_cb;
512
+ osh->sih = bpt_ctx;
513
+ }
514
+}
515
+#endif /* BCM_BACKPLANE_TIMEOUT */
603516
604517 void
605518 osl_detach(osl_t *osh)
....@@ -613,12 +526,15 @@
613526 osl_sec_dma_deinit_elem_mem_block(osh, CMA_BUFSIZE_4K, CMA_BUFNUM, osh->sec_list_base_4096);
614527 osl_sec_dma_iounmap(osh, osh->contig_base_coherent_va, CMA_DMA_DESC_MEMBLOCK);
615528 osl_sec_dma_iounmap(osh, osh->contig_base_va, CMA_DMA_DATA_MEMBLOCK);
616
-
617529 secdma_found--;
618530 #endif /* BCM_SECURE_DMA */
619531
620
-
621532 bcm_object_trace_deinit();
533
+
534
+#ifdef DHD_MAP_LOGGING
535
+ osl_dma_map_log_deinit(osh->dhd_map_log);
536
+ osl_dma_map_log_deinit(osh->dhd_unmap_log);
537
+#endif /* DHD_MAP_LOGGING */
622538
623539 ASSERT(osh->magic == OS_HANDLE_MAGIC);
624540 atomic_sub(1, &osh->cmn->refcount);
....@@ -628,757 +544,77 @@
628544 kfree(osh);
629545 }
630546
631
-int osl_static_mem_deinit(osl_t *osh, void *adapter)
547
+/* APIs to set/get specific quirks in OSL layer */
548
+void BCMFASTPATH
549
+osl_flag_set(osl_t *osh, uint32 mask)
632550 {
633
-#ifdef CONFIG_DHD_USE_STATIC_BUF
634
- if (bcm_static_buf) {
635
- bcm_static_buf = 0;
636
- }
637
-#ifdef BCMSDIO
638
- if (bcm_static_skb) {
639
- bcm_static_skb = 0;
640
- }
641
-#endif /* BCMSDIO */
642
-#endif /* CONFIG_DHD_USE_STATIC_BUF */
551
+ osh->flags |= mask;
552
+}
553
+
554
+void
555
+osl_flag_clr(osl_t *osh, uint32 mask)
556
+{
557
+ osh->flags &= ~mask;
558
+}
559
+
560
+#if defined(STB)
561
+inline bool BCMFASTPATH
562
+#else
563
+bool
564
+#endif // endif
565
+osl_is_flag_set(osl_t *osh, uint32 mask)
566
+{
567
+ return (osh->flags & mask);
568
+}
569
+
570
+#if (defined(__ARM_ARCH_7A__) && !defined(DHD_USE_COHERENT_MEM_FOR_RING)) || \
571
+ defined(STB_SOC_WIFI)
572
+
573
+inline int BCMFASTPATH
574
+osl_arch_is_coherent(void)
575
+{
643576 return 0;
644577 }
645578
646
-static struct sk_buff *osl_alloc_skb(osl_t *osh, unsigned int len)
579
+inline int BCMFASTPATH
580
+osl_acp_war_enab(void)
647581 {
648
- struct sk_buff *skb;
649
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
650
- gfp_t flags = (in_atomic() || irqs_disabled()) ? GFP_ATOMIC : GFP_KERNEL;
651
-#if defined(CONFIG_SPARSEMEM) && defined(CONFIG_ZONE_DMA)
652
- flags |= GFP_ATOMIC;
653
-#endif
654
- skb = __dev_alloc_skb(len, flags);
655
-#else
656
- skb = dev_alloc_skb(len);
657
-#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25) */
658
- return skb;
659
-}
660
-
661
-#ifdef CTFPOOL
662
-
663
-#ifdef CTFPOOL_SPINLOCK
664
-#define CTFPOOL_LOCK(ctfpool, flags) spin_lock_irqsave(&(ctfpool)->lock, flags)
665
-#define CTFPOOL_UNLOCK(ctfpool, flags) spin_unlock_irqrestore(&(ctfpool)->lock, flags)
666
-#else
667
-#define CTFPOOL_LOCK(ctfpool, flags) spin_lock_bh(&(ctfpool)->lock)
668
-#define CTFPOOL_UNLOCK(ctfpool, flags) spin_unlock_bh(&(ctfpool)->lock)
669
-#endif /* CTFPOOL_SPINLOCK */
670
-/*
671
- * Allocate and add an object to packet pool.
672
- */
673
-void *
674
-osl_ctfpool_add(osl_t *osh)
675
-{
676
- struct sk_buff *skb;
677
-#ifdef CTFPOOL_SPINLOCK
678
- unsigned long flags;
679
-#endif /* CTFPOOL_SPINLOCK */
680
-
681
- if ((osh == NULL) || (osh->ctfpool == NULL))
682
- return NULL;
683
-
684
- CTFPOOL_LOCK(osh->ctfpool, flags);
685
- ASSERT(osh->ctfpool->curr_obj <= osh->ctfpool->max_obj);
686
-
687
- /* No need to allocate more objects */
688
- if (osh->ctfpool->curr_obj == osh->ctfpool->max_obj) {
689
- CTFPOOL_UNLOCK(osh->ctfpool, flags);
690
- return NULL;
691
- }
692
-
693
- /* Allocate a new skb and add it to the ctfpool */
694
- skb = osl_alloc_skb(osh, osh->ctfpool->obj_size);
695
- if (skb == NULL) {
696
- printf("%s: skb alloc of len %d failed\n", __FUNCTION__,
697
- osh->ctfpool->obj_size);
698
- CTFPOOL_UNLOCK(osh->ctfpool, flags);
699
- return NULL;
700
- }
701
-
702
- /* Add to ctfpool */
703
- skb->next = (struct sk_buff *)osh->ctfpool->head;
704
- osh->ctfpool->head = skb;
705
- osh->ctfpool->fast_frees++;
706
- osh->ctfpool->curr_obj++;
707
-
708
- /* Hijack a skb member to store ptr to ctfpool */
709
- CTFPOOLPTR(osh, skb) = (void *)osh->ctfpool;
710
-
711
- /* Use bit flag to indicate skb from fast ctfpool */
712
- PKTFAST(osh, skb) = FASTBUF;
713
-
714
- CTFPOOL_UNLOCK(osh->ctfpool, flags);
715
-
716
- return skb;
717
-}
718
-
719
-/*
720
- * Add new objects to the pool.
721
- */
722
-void
723
-osl_ctfpool_replenish(osl_t *osh, uint thresh)
724
-{
725
- if ((osh == NULL) || (osh->ctfpool == NULL))
726
- return;
727
-
728
- /* Do nothing if no refills are required */
729
- while ((osh->ctfpool->refills > 0) && (thresh--)) {
730
- osl_ctfpool_add(osh);
731
- osh->ctfpool->refills--;
732
- }
733
-}
734
-
735
-/*
736
- * Initialize the packet pool with specified number of objects.
737
- */
738
-int32
739
-osl_ctfpool_init(osl_t *osh, uint numobj, uint size)
740
-{
741
- gfp_t flags;
742
-
743
- flags = CAN_SLEEP() ? GFP_KERNEL: GFP_ATOMIC;
744
- osh->ctfpool = kzalloc(sizeof(ctfpool_t), flags);
745
- ASSERT(osh->ctfpool);
746
-
747
- osh->ctfpool->max_obj = numobj;
748
- osh->ctfpool->obj_size = size;
749
-
750
- spin_lock_init(&osh->ctfpool->lock);
751
-
752
- while (numobj--) {
753
- if (!osl_ctfpool_add(osh))
754
- return -1;
755
- osh->ctfpool->fast_frees--;
756
- }
757
-
758582 return 0;
759583 }
760584
761
-/*
762
- * Cleanup the packet pool objects.
763
- */
764
-void
765
-osl_ctfpool_cleanup(osl_t *osh)
766
-{
767
- struct sk_buff *skb, *nskb;
768
-#ifdef CTFPOOL_SPINLOCK
769
- unsigned long flags;
770
-#endif /* CTFPOOL_SPINLOCK */
771
-
772
- if ((osh == NULL) || (osh->ctfpool == NULL))
773
- return;
774
-
775
- CTFPOOL_LOCK(osh->ctfpool, flags);
776
-
777
- skb = osh->ctfpool->head;
778
-
779
- while (skb != NULL) {
780
- nskb = skb->next;
781
- dev_kfree_skb(skb);
782
- skb = nskb;
783
- osh->ctfpool->curr_obj--;
784
- }
785
-
786
- ASSERT(osh->ctfpool->curr_obj == 0);
787
- osh->ctfpool->head = NULL;
788
- CTFPOOL_UNLOCK(osh->ctfpool, flags);
789
-
790
- kfree(osh->ctfpool);
791
- osh->ctfpool = NULL;
792
-}
793
-
794
-void
795
-osl_ctfpool_stats(osl_t *osh, void *b)
796
-{
797
- struct bcmstrbuf *bb;
798
-
799
- if ((osh == NULL) || (osh->ctfpool == NULL))
800
- return;
801
-
802
-#ifdef CONFIG_DHD_USE_STATIC_BUF
803
- if (bcm_static_buf) {
804
- bcm_static_buf = 0;
805
- }
806
-#ifdef BCMSDIO
807
- if (bcm_static_skb) {
808
- bcm_static_skb = 0;
809
- }
810
-#endif /* BCMSDIO */
811
-#endif /* CONFIG_DHD_USE_STATIC_BUF */
812
-
813
- bb = b;
814
-
815
- ASSERT((osh != NULL) && (bb != NULL));
816
-
817
- bcm_bprintf(bb, "max_obj %d obj_size %d curr_obj %d refills %d\n",
818
- osh->ctfpool->max_obj, osh->ctfpool->obj_size,
819
- osh->ctfpool->curr_obj, osh->ctfpool->refills);
820
- bcm_bprintf(bb, "fast_allocs %d fast_frees %d slow_allocs %d\n",
821
- osh->ctfpool->fast_allocs, osh->ctfpool->fast_frees,
822
- osh->ctfpool->slow_allocs);
823
-}
824
-
825
-static inline struct sk_buff *
826
-osl_pktfastget(osl_t *osh, uint len)
827
-{
828
- struct sk_buff *skb;
829
-#ifdef CTFPOOL_SPINLOCK
830
- unsigned long flags;
831
-#endif /* CTFPOOL_SPINLOCK */
832
-
833
- /* Try to do fast allocate. Return null if ctfpool is not in use
834
- * or if there are no items in the ctfpool.
835
- */
836
- if (osh->ctfpool == NULL)
837
- return NULL;
838
-
839
- CTFPOOL_LOCK(osh->ctfpool, flags);
840
- if (osh->ctfpool->head == NULL) {
841
- ASSERT(osh->ctfpool->curr_obj == 0);
842
- osh->ctfpool->slow_allocs++;
843
- CTFPOOL_UNLOCK(osh->ctfpool, flags);
844
- return NULL;
845
- }
846
-
847
- if (len > osh->ctfpool->obj_size) {
848
- CTFPOOL_UNLOCK(osh->ctfpool, flags);
849
- return NULL;
850
- }
851
-
852
- ASSERT(len <= osh->ctfpool->obj_size);
853
-
854
- /* Get an object from ctfpool */
855
- skb = (struct sk_buff *)osh->ctfpool->head;
856
- osh->ctfpool->head = (void *)skb->next;
857
-
858
- osh->ctfpool->fast_allocs++;
859
- osh->ctfpool->curr_obj--;
860
- ASSERT(CTFPOOLHEAD(osh, skb) == (struct sock *)osh->ctfpool->head);
861
- CTFPOOL_UNLOCK(osh->ctfpool, flags);
862
-
863
- /* Init skb struct */
864
- skb->next = skb->prev = NULL;
865
-#if defined(__ARM_ARCH_7A__)
866
- skb->data = skb->head + NET_SKB_PAD;
867
- skb->tail = skb->head + NET_SKB_PAD;
868
-#else
869
- skb->data = skb->head + 16;
870
- skb->tail = skb->head + 16;
871
-#endif /* __ARM_ARCH_7A__ */
872
- skb->len = 0;
873
- skb->cloned = 0;
874
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14)
875
- skb->list = NULL;
876
-#endif
877
- atomic_set(&skb->users, 1);
878
-
879
- PKTSETCLINK(skb, NULL);
880
- PKTCCLRATTR(skb);
881
- PKTFAST(osh, skb) &= ~(CTFBUF | SKIPCT | CHAINED);
882
-
883
- return skb;
884
-}
885
-#endif /* CTFPOOL */
886
-
887
-#if defined(BCM_GMAC3)
888
-/* Account for a packet delivered to downstream forwarder.
889
- * Decrement a GMAC forwarder interface's pktalloced count.
890
- */
891
-void BCMFASTPATH
892
-osl_pkt_tofwder(osl_t *osh, void *skbs, int skb_cnt)
585
+inline void BCMFASTPATH
586
+osl_cache_flush(void *va, uint size)
893587 {
894588
895
- atomic_sub(skb_cnt, &osh->cmn->pktalloced);
589
+ if (size > 0)
590
+#ifdef STB_SOC_WIFI
591
+ dma_sync_single_for_device(OSH_NULL, virt_to_phys(va), size, DMA_TX);
592
+#else /* STB_SOC_WIFI */
593
+ dma_sync_single_for_device(OSH_NULL, virt_to_dma(OSH_NULL, va), size,
594
+ DMA_TO_DEVICE);
595
+#endif /* STB_SOC_WIFI */
896596 }
897597
898
-/* Account for a downstream forwarder delivered packet to a WL/DHD driver.
899
- * Increment a GMAC forwarder interface's pktalloced count.
900
- */
901
-#ifdef BCMDBG_CTRACE
902
-void BCMFASTPATH
903
-osl_pkt_frmfwder(osl_t *osh, void *skbs, int skb_cnt, int line, char *file)
904
-#else
905
-void BCMFASTPATH
906
-osl_pkt_frmfwder(osl_t *osh, void *skbs, int skb_cnt)
907
-#endif /* BCMDBG_CTRACE */
598
+inline void BCMFASTPATH
599
+osl_cache_inv(void *va, uint size)
908600 {
909
-#if defined(BCMDBG_CTRACE)
910
- int i;
911
- struct sk_buff *skb;
912
-#endif
913601
914
-#if defined(BCMDBG_CTRACE)
915
- if (skb_cnt > 1) {
916
- struct sk_buff **skb_array = (struct sk_buff **)skbs;
917
- for (i = 0; i < skb_cnt; i++) {
918
- skb = skb_array[i];
919
-#if defined(BCMDBG_CTRACE)
920
- ASSERT(!PKTISCHAINED(skb));
921
- ADD_CTRACE(osh, skb, file, line);
922
-#endif /* BCMDBG_CTRACE */
923
- }
924
- } else {
925
- skb = (struct sk_buff *)skbs;
926
-#if defined(BCMDBG_CTRACE)
927
- ASSERT(!PKTISCHAINED(skb));
928
- ADD_CTRACE(osh, skb, file, line);
929
-#endif /* BCMDBG_CTRACE */
930
- }
931
-#endif
932
-
933
- atomic_add(skb_cnt, &osh->cmn->pktalloced);
602
+#ifdef STB_SOC_WIFI
603
+ dma_sync_single_for_cpu(OSH_NULL, virt_to_phys(va), size, DMA_RX);
604
+#else /* STB_SOC_WIFI */
605
+ dma_sync_single_for_cpu(OSH_NULL, virt_to_dma(OSH_NULL, va), size, DMA_FROM_DEVICE);
606
+#endif /* STB_SOC_WIFI */
934607 }
935608
936
-#endif /* BCM_GMAC3 */
937
-
938
-/* Convert a driver packet to native(OS) packet
939
- * In the process, packettag is zeroed out before sending up
940
- * IP code depends on skb->cb to be setup correctly with various options
941
- * In our case, that means it should be 0
942
- */
943
-struct sk_buff * BCMFASTPATH
944
-osl_pkt_tonative(osl_t *osh, void *pkt)
609
+inline void BCMFASTPATH
610
+osl_prefetch(const void *ptr)
945611 {
946
- struct sk_buff *nskb;
947
-#ifdef BCMDBG_CTRACE
948
- struct sk_buff *nskb1, *nskb2;
949
-#endif
950
-
951
- if (osh->pub.pkttag)
952
- OSL_PKTTAG_CLEAR(pkt);
953
-
954
- /* Decrement the packet counter */
955
- for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next) {
956
- atomic_sub(PKTISCHAINED(nskb) ? PKTCCNT(nskb) : 1, &osh->cmn->pktalloced);
957
-
958
-#ifdef BCMDBG_CTRACE
959
- for (nskb1 = nskb; nskb1 != NULL; nskb1 = nskb2) {
960
- if (PKTISCHAINED(nskb1)) {
961
- nskb2 = PKTCLINK(nskb1);
962
- }
963
- else
964
- nskb2 = NULL;
965
-
966
- DEL_CTRACE(osh, nskb1);
967
- }
968
-#endif /* BCMDBG_CTRACE */
969
- }
970
- return (struct sk_buff *)pkt;
612
+#if !defined(STB_SOC_WIFI)
613
+ __asm__ __volatile__("pld\t%0" :: "o"(*(const char *)ptr) : "cc");
614
+#endif // endif
971615 }
972616
973
-/* Convert a native(OS) packet to driver packet.
974
- * In the process, native packet is destroyed, there is no copying
975
- * Also, a packettag is zeroed out
976
- */
977
-#ifdef BCMDBG_CTRACE
978
-void * BCMFASTPATH
979
-osl_pkt_frmnative(osl_t *osh, void *pkt, int line, char *file)
980
-#else
981
-void * BCMFASTPATH
982
-osl_pkt_frmnative(osl_t *osh, void *pkt)
983
-#endif /* BCMDBG_CTRACE */
984
-{
985
- struct sk_buff *nskb;
986
-#ifdef BCMDBG_CTRACE
987
- struct sk_buff *nskb1, *nskb2;
988
-#endif
989
-
990
- if (osh->pub.pkttag)
991
- OSL_PKTTAG_CLEAR(pkt);
992
-
993
- /* Increment the packet counter */
994
- for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next) {
995
- atomic_add(PKTISCHAINED(nskb) ? PKTCCNT(nskb) : 1, &osh->cmn->pktalloced);
996
-
997
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0))
998
- nskb->prev = NULL;
999
-#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0) */
1000
-
1001
-#ifdef BCMDBG_CTRACE
1002
- for (nskb1 = nskb; nskb1 != NULL; nskb1 = nskb2) {
1003
- if (PKTISCHAINED(nskb1)) {
1004
- nskb2 = PKTCLINK(nskb1);
1005
- }
1006
- else
1007
- nskb2 = NULL;
1008
-
1009
- ADD_CTRACE(osh, nskb1, file, line);
1010
- }
1011
-#endif /* BCMDBG_CTRACE */
1012
- }
1013
- return (void *)pkt;
1014
-}
1015
-
1016
-/* Return a new packet. zero out pkttag */
1017
-#ifdef BCMDBG_CTRACE
1018
-void * BCMFASTPATH
1019
-osl_pktget(osl_t *osh, uint len, int line, char *file)
1020
-#else
1021
-#ifdef BCM_OBJECT_TRACE
1022
-void * BCMFASTPATH
1023
-osl_pktget(osl_t *osh, uint len, int line, const char *caller)
1024
-#else
1025
-void * BCMFASTPATH
1026
-osl_pktget(osl_t *osh, uint len)
1027
-#endif /* BCM_OBJECT_TRACE */
1028
-#endif /* BCMDBG_CTRACE */
1029
-{
1030
- struct sk_buff *skb;
1031
- uchar num = 0;
1032
- if (lmtest != FALSE) {
1033
- get_random_bytes(&num, sizeof(uchar));
1034
- if ((num + 1) <= (256 * lmtest / 100))
1035
- return NULL;
1036
- }
1037
-
1038
-#ifdef CTFPOOL
1039
- /* Allocate from local pool */
1040
- skb = osl_pktfastget(osh, len);
1041
- if ((skb != NULL) || ((skb = osl_alloc_skb(osh, len)) != NULL)) {
1042
-#else /* CTFPOOL */
1043
- if ((skb = osl_alloc_skb(osh, len))) {
1044
-#endif /* CTFPOOL */
1045
- skb->tail += len;
1046
- skb->len += len;
1047
- skb->priority = 0;
1048
-
1049
-#ifdef BCMDBG_CTRACE
1050
- ADD_CTRACE(osh, skb, file, line);
1051
-#endif
1052
- atomic_inc(&osh->cmn->pktalloced);
1053
-#ifdef BCM_OBJECT_TRACE
1054
- bcm_object_trace_opr(skb, BCM_OBJDBG_ADD_PKT, caller, line);
1055
-#endif /* BCM_OBJECT_TRACE */
1056
- }
1057
-
1058
- return ((void*) skb);
1059
-}
1060
-
1061
-#ifdef CTFPOOL
1062
-static inline void
1063
-osl_pktfastfree(osl_t *osh, struct sk_buff *skb)
1064
-{
1065
- ctfpool_t *ctfpool;
1066
-#ifdef CTFPOOL_SPINLOCK
1067
- unsigned long flags;
1068
-#endif /* CTFPOOL_SPINLOCK */
1069
-
1070
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
1071
- skb->tstamp.tv.sec = 0;
1072
-#else
1073
- skb->stamp.tv_sec = 0;
1074
-#endif
1075
-
1076
- /* We only need to init the fields that we change */
1077
- skb->dev = NULL;
1078
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
1079
- skb->dst = NULL;
1080
-#endif
1081
- OSL_PKTTAG_CLEAR(skb);
1082
- skb->ip_summed = 0;
1083
-
1084
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
1085
- skb_orphan(skb);
1086
-#else
1087
- skb->destructor = NULL;
1088
-#endif
1089
-
1090
- ctfpool = (ctfpool_t *)CTFPOOLPTR(osh, skb);
1091
- ASSERT(ctfpool != NULL);
1092
-
1093
- /* Add object to the ctfpool */
1094
- CTFPOOL_LOCK(ctfpool, flags);
1095
- skb->next = (struct sk_buff *)ctfpool->head;
1096
- ctfpool->head = (void *)skb;
1097
-
1098
- ctfpool->fast_frees++;
1099
- ctfpool->curr_obj++;
1100
-
1101
- ASSERT(ctfpool->curr_obj <= ctfpool->max_obj);
1102
- CTFPOOL_UNLOCK(ctfpool, flags);
1103
-}
1104
-#endif /* CTFPOOL */
1105
-
1106
-/* Free the driver packet. Free the tag if present */
1107
-#ifdef BCM_OBJECT_TRACE
1108
-void BCMFASTPATH
1109
-osl_pktfree(osl_t *osh, void *p, bool send, int line, const char *caller)
1110
-#else
1111
-void BCMFASTPATH
1112
-osl_pktfree(osl_t *osh, void *p, bool send)
1113
-#endif /* BCM_OBJECT_TRACE */
1114
-{
1115
- struct sk_buff *skb, *nskb;
1116
- if (osh == NULL)
1117
- return;
1118
-
1119
- skb = (struct sk_buff*) p;
1120
-
1121
- if (send && osh->pub.tx_fn)
1122
- osh->pub.tx_fn(osh->pub.tx_ctx, p, 0);
1123
-
1124
- PKTDBG_TRACE(osh, (void *) skb, PKTLIST_PKTFREE);
1125
-
1126
-#if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_CTRLBUF)
1127
- if (skb && (skb->mac_len == PREALLOC_USED_MAGIC)) {
1128
- printk("%s: pkt %p is from static pool\n",
1129
- __FUNCTION__, p);
1130
- dump_stack();
1131
- return;
1132
- }
1133
-
1134
- if (skb && (skb->mac_len == PREALLOC_FREE_MAGIC)) {
1135
- printk("%s: pkt %p is from static pool and not in used\n",
1136
- __FUNCTION__, p);
1137
- dump_stack();
1138
- return;
1139
- }
1140
-#endif /* CONFIG_DHD_USE_STATIC_BUF && DHD_USE_STATIC_CTRLBUF */
1141
-
1142
- /* perversion: we use skb->next to chain multi-skb packets */
1143
- while (skb) {
1144
- nskb = skb->next;
1145
- skb->next = NULL;
1146
-
1147
-#ifdef BCMDBG_CTRACE
1148
- DEL_CTRACE(osh, skb);
1149
-#endif
1150
-
1151
-
1152
-#ifdef BCM_OBJECT_TRACE
1153
- bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE, caller, line);
1154
-#endif /* BCM_OBJECT_TRACE */
1155
-
1156
-#ifdef CTFPOOL
1157
- if (PKTISFAST(osh, skb)) {
1158
- if (atomic_read(&skb->users) == 1)
1159
- smp_rmb();
1160
- else if (!atomic_dec_and_test(&skb->users))
1161
- goto next_skb;
1162
- osl_pktfastfree(osh, skb);
1163
- } else
1164
-#endif
1165
- {
1166
- dev_kfree_skb_any(skb);
1167
- }
1168
-#ifdef CTFPOOL
1169
-next_skb:
1170
-#endif
1171
- atomic_dec(&osh->cmn->pktalloced);
1172
- skb = nskb;
1173
- }
1174
-}
1175
-
1176
-#ifdef CONFIG_DHD_USE_STATIC_BUF
1177
-void*
1178
-osl_pktget_static(osl_t *osh, uint len)
1179
-{
1180
- int i = 0;
1181
- struct sk_buff *skb;
1182
-#ifdef DHD_USE_STATIC_CTRLBUF
1183
- unsigned long flags;
1184
-#endif /* DHD_USE_STATIC_CTRLBUF */
1185
-
1186
- if (!bcm_static_skb)
1187
- return osl_pktget(osh, len);
1188
-
1189
- if (len > DHD_SKB_MAX_BUFSIZE) {
1190
- printk("%s: attempt to allocate huge packet (0x%x)\n", __FUNCTION__, len);
1191
- return osl_pktget(osh, len);
1192
- }
1193
-
1194
-#ifdef DHD_USE_STATIC_CTRLBUF
1195
- spin_lock_irqsave(&bcm_static_skb->osl_pkt_lock, flags);
1196
-
1197
- if (len <= DHD_SKB_2PAGE_BUFSIZE) {
1198
- uint32 index;
1199
- for (i = 0; i < STATIC_PKT_2PAGE_NUM; i++) {
1200
- index = bcm_static_skb->last_allocated_index % STATIC_PKT_2PAGE_NUM;
1201
- bcm_static_skb->last_allocated_index++;
1202
- if (bcm_static_skb->skb_8k[index] &&
1203
- bcm_static_skb->pkt_use[index] == 0) {
1204
- break;
1205
- }
1206
- }
1207
-
1208
- if ((i != STATIC_PKT_2PAGE_NUM) &&
1209
- (index >= 0) && (index < STATIC_PKT_2PAGE_NUM)) {
1210
- bcm_static_skb->pkt_use[index] = 1;
1211
- skb = bcm_static_skb->skb_8k[index];
1212
- skb->data = skb->head;
1213
-#ifdef NET_SKBUFF_DATA_USES_OFFSET
1214
- skb_set_tail_pointer(skb, NET_SKB_PAD);
1215
-#else
1216
- skb->tail = skb->data + NET_SKB_PAD;
1217
-#endif /* NET_SKBUFF_DATA_USES_OFFSET */
1218
- skb->data += NET_SKB_PAD;
1219
- skb->cloned = 0;
1220
- skb->priority = 0;
1221
-#ifdef NET_SKBUFF_DATA_USES_OFFSET
1222
- skb_set_tail_pointer(skb, len);
1223
-#else
1224
- skb->tail = skb->data + len;
1225
-#endif /* NET_SKBUFF_DATA_USES_OFFSET */
1226
- skb->len = len;
1227
- skb->mac_len = PREALLOC_USED_MAGIC;
1228
- spin_unlock_irqrestore(&bcm_static_skb->osl_pkt_lock, flags);
1229
- return skb;
1230
- }
1231
- }
1232
-
1233
- spin_unlock_irqrestore(&bcm_static_skb->osl_pkt_lock, flags);
1234
- printk("%s: all static pkt in use!\n", __FUNCTION__);
1235
- return NULL;
1236
-#else
1237
- down(&bcm_static_skb->osl_pkt_sem);
1238
-
1239
- if (len <= DHD_SKB_1PAGE_BUFSIZE) {
1240
- for (i = 0; i < STATIC_PKT_MAX_NUM; i++) {
1241
- if (bcm_static_skb->skb_4k[i] &&
1242
- bcm_static_skb->pkt_use[i] == 0) {
1243
- break;
1244
- }
1245
- }
1246
-
1247
- if (i != STATIC_PKT_MAX_NUM) {
1248
- bcm_static_skb->pkt_use[i] = 1;
1249
-
1250
- skb = bcm_static_skb->skb_4k[i];
1251
-#ifdef NET_SKBUFF_DATA_USES_OFFSET
1252
- skb_set_tail_pointer(skb, len);
1253
-#else
1254
- skb->tail = skb->data + len;
1255
-#endif /* NET_SKBUFF_DATA_USES_OFFSET */
1256
- skb->len = len;
1257
-
1258
- up(&bcm_static_skb->osl_pkt_sem);
1259
- return skb;
1260
- }
1261
- }
1262
-
1263
- if (len <= DHD_SKB_2PAGE_BUFSIZE) {
1264
- for (i = STATIC_PKT_1PAGE_NUM; i < STATIC_PKT_1_2PAGE_NUM; i++) {
1265
- if (bcm_static_skb->skb_8k[i - STATIC_PKT_1PAGE_NUM] &&
1266
- bcm_static_skb->pkt_use[i] == 0) {
1267
- break;
1268
- }
1269
- }
1270
-
1271
- if ((i >= STATIC_PKT_1PAGE_NUM) && (i < STATIC_PKT_1_2PAGE_NUM)) {
1272
- bcm_static_skb->pkt_use[i] = 1;
1273
- skb = bcm_static_skb->skb_8k[i - STATIC_PKT_1PAGE_NUM];
1274
-#ifdef NET_SKBUFF_DATA_USES_OFFSET
1275
- skb_set_tail_pointer(skb, len);
1276
-#else
1277
- skb->tail = skb->data + len;
1278
-#endif /* NET_SKBUFF_DATA_USES_OFFSET */
1279
- skb->len = len;
1280
-
1281
- up(&bcm_static_skb->osl_pkt_sem);
1282
- return skb;
1283
- }
1284
- }
1285
-
1286
-#if defined(ENHANCED_STATIC_BUF)
1287
- if (bcm_static_skb->skb_16k &&
1288
- bcm_static_skb->pkt_use[STATIC_PKT_MAX_NUM - 1] == 0) {
1289
- bcm_static_skb->pkt_use[STATIC_PKT_MAX_NUM - 1] = 1;
1290
-
1291
- skb = bcm_static_skb->skb_16k;
1292
-#ifdef NET_SKBUFF_DATA_USES_OFFSET
1293
- skb_set_tail_pointer(skb, len);
1294
-#else
1295
- skb->tail = skb->data + len;
1296
-#endif /* NET_SKBUFF_DATA_USES_OFFSET */
1297
- skb->len = len;
1298
-
1299
- up(&bcm_static_skb->osl_pkt_sem);
1300
- return skb;
1301
- }
1302
-#endif /* ENHANCED_STATIC_BUF */
1303
-
1304
- up(&bcm_static_skb->osl_pkt_sem);
1305
- printk("%s: all static pkt in use!\n", __FUNCTION__);
1306
- return osl_pktget(osh, len);
1307
-#endif /* DHD_USE_STATIC_CTRLBUF */
1308
-}
1309
-
1310
-void
1311
-osl_pktfree_static(osl_t *osh, void *p, bool send)
1312
-{
1313
- int i;
1314
-#ifdef DHD_USE_STATIC_CTRLBUF
1315
- struct sk_buff *skb = (struct sk_buff *)p;
1316
- unsigned long flags;
1317
-#endif /* DHD_USE_STATIC_CTRLBUF */
1318
-
1319
- if (!p) {
1320
- return;
1321
- }
1322
-
1323
- if (!bcm_static_skb) {
1324
- osl_pktfree(osh, p, send);
1325
- return;
1326
- }
1327
-
1328
-#ifdef DHD_USE_STATIC_CTRLBUF
1329
- spin_lock_irqsave(&bcm_static_skb->osl_pkt_lock, flags);
1330
-
1331
- for (i = 0; i < STATIC_PKT_2PAGE_NUM; i++) {
1332
- if (p == bcm_static_skb->skb_8k[i]) {
1333
- if (bcm_static_skb->pkt_use[i] == 0) {
1334
- printk("%s: static pkt idx %d(%p) is double free\n",
1335
- __FUNCTION__, i, p);
1336
- } else {
1337
- bcm_static_skb->pkt_use[i] = 0;
1338
- }
1339
-
1340
- if (skb->mac_len != PREALLOC_USED_MAGIC) {
1341
- printk("%s: static pkt idx %d(%p) is not in used\n",
1342
- __FUNCTION__, i, p);
1343
- }
1344
-
1345
- skb->mac_len = PREALLOC_FREE_MAGIC;
1346
- spin_unlock_irqrestore(&bcm_static_skb->osl_pkt_lock, flags);
1347
- return;
1348
- }
1349
- }
1350
-
1351
- spin_unlock_irqrestore(&bcm_static_skb->osl_pkt_lock, flags);
1352
- printk("%s: packet %p does not exist in the pool\n", __FUNCTION__, p);
1353
-#else
1354
- down(&bcm_static_skb->osl_pkt_sem);
1355
- for (i = 0; i < STATIC_PKT_1PAGE_NUM; i++) {
1356
- if (p == bcm_static_skb->skb_4k[i]) {
1357
- bcm_static_skb->pkt_use[i] = 0;
1358
- up(&bcm_static_skb->osl_pkt_sem);
1359
- return;
1360
- }
1361
- }
1362
-
1363
- for (i = STATIC_PKT_1PAGE_NUM; i < STATIC_PKT_1_2PAGE_NUM; i++) {
1364
- if (p == bcm_static_skb->skb_8k[i - STATIC_PKT_1PAGE_NUM]) {
1365
- bcm_static_skb->pkt_use[i] = 0;
1366
- up(&bcm_static_skb->osl_pkt_sem);
1367
- return;
1368
- }
1369
- }
1370
-#ifdef ENHANCED_STATIC_BUF
1371
- if (p == bcm_static_skb->skb_16k) {
1372
- bcm_static_skb->pkt_use[STATIC_PKT_MAX_NUM - 1] = 0;
1373
- up(&bcm_static_skb->osl_pkt_sem);
1374
- return;
1375
- }
1376
-#endif
1377
- up(&bcm_static_skb->osl_pkt_sem);
1378
- osl_pktfree(osh, p, send);
1379
-#endif /* DHD_USE_STATIC_CTRLBUF */
1380
-}
1381
-#endif /* CONFIG_DHD_USE_STATIC_BUF */
617
+#endif // endif
1382618
1383619 uint32
1384620 osl_pci_read_config(osl_t *osh, uint offset, uint size)
....@@ -1396,7 +632,6 @@
1396632 if (val != 0xffffffff)
1397633 break;
1398634 } while (retry--);
1399
-
1400635
1401636 return (val);
1402637 }
....@@ -1427,11 +662,11 @@
1427662 {
1428663 ASSERT(osh && (osh->magic == OS_HANDLE_MAGIC) && osh->pdev);
1429664
1430
-#if defined(__ARM_ARCH_7A__) && LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35)
665
+#if defined(__ARM_ARCH_7A__)
1431666 return pci_domain_nr(((struct pci_dev *)osh->pdev)->bus);
1432667 #else
1433668 return ((struct pci_dev *)osh->pdev)->bus->number;
1434
-#endif
669
+#endif // endif
1435670 }
1436671
1437672 /* return slot # for the pci device pointed by osh->pdev */
....@@ -1440,11 +675,11 @@
1440675 {
1441676 ASSERT(osh && (osh->magic == OS_HANDLE_MAGIC) && osh->pdev);
1442677
1443
-#if defined(__ARM_ARCH_7A__) && LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35)
678
+#if defined(__ARM_ARCH_7A__)
1444679 return PCI_SLOT(((struct pci_dev *)osh->pdev)->devfn) + 1;
1445680 #else
1446681 return PCI_SLOT(((struct pci_dev *)osh->pdev)->devfn);
1447
-#endif
682
+#endif // endif
1448683 }
1449684
1450685 /* return domain # for the pci device pointed by osh->pdev */
....@@ -1536,7 +771,11 @@
1536771 #endif /* CONFIG_DHD_USE_STATIC_BUF */
1537772
1538773 flags = CAN_SLEEP() ? GFP_KERNEL: GFP_ATOMIC;
774
+#if defined(DHD_USE_KVMALLOC) && (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
775
+ if ((addr = kvmalloc(size, flags)) == NULL) {
776
+#else
1539777 if ((addr = kmalloc(size, flags)) == NULL) {
778
+#endif // endif
1540779 if (osh)
1541780 osh->failed++;
1542781 return (NULL);
....@@ -1595,7 +834,57 @@
1595834
1596835 atomic_sub(size, &osh->cmn->malloced);
1597836 }
837
+#if defined(DHD_USE_KVMALLOC) && (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0))
838
+ kvfree(addr);
839
+#else
1598840 kfree(addr);
841
+#endif // endif
842
+}
843
+
844
+void *
845
+osl_vmalloc(osl_t *osh, uint size)
846
+{
847
+ void *addr;
848
+
849
+ /* only ASSERT if osh is defined */
850
+ if (osh)
851
+ ASSERT(osh->magic == OS_HANDLE_MAGIC);
852
+ if ((addr = vmalloc(size)) == NULL) {
853
+ if (osh)
854
+ osh->failed++;
855
+ return (NULL);
856
+ }
857
+ if (osh && osh->cmn)
858
+ atomic_add(size, &osh->cmn->malloced);
859
+
860
+ return (addr);
861
+}
862
+
863
+void *
864
+osl_vmallocz(osl_t *osh, uint size)
865
+{
866
+ void *ptr;
867
+
868
+ ptr = osl_vmalloc(osh, size);
869
+
870
+ if (ptr != NULL) {
871
+ bzero(ptr, size);
872
+ }
873
+
874
+ return ptr;
875
+}
876
+
877
+void
878
+osl_vmfree(osl_t *osh, void *addr, uint size)
879
+{
880
+ if (osh && osh->cmn) {
881
+ ASSERT(osh->magic == OS_HANDLE_MAGIC);
882
+
883
+ ASSERT(size <= osl_malloced(osh));
884
+
885
+ atomic_sub(size, &osh->cmn->malloced);
886
+ }
887
+ vfree(addr);
1599888 }
1600889
1601890 uint
....@@ -1622,7 +911,6 @@
1622911 return (osh->failed);
1623912 }
1624913
1625
-
1626914 uint
1627915 osl_dma_consistent_align(void)
1628916 {
....@@ -1641,7 +929,8 @@
1641929 *alloced = size;
1642930
1643931 #ifndef BCM_SECURE_DMA
1644
-#if defined(__ARM_ARCH_7A__) && !defined(DHD_USE_COHERENT_MEM_FOR_RING)
932
+#if (defined(__ARM_ARCH_7A__) && !defined(DHD_USE_COHERENT_MEM_FOR_RING)) || \
933
+ defined(STB_SOC_WIFI)
1645934 va = kmalloc(size, GFP_ATOMIC | __GFP_ZERO);
1646935 if (va)
1647936 *pap = (ulong)__virt_to_phys((ulong)va);
....@@ -1656,7 +945,12 @@
1656945 flags = CAN_SLEEP() ? GFP_KERNEL: GFP_ATOMIC;
1657946 #endif /* DHD_ALLOC_COHERENT_MEM_FROM_ATOMIC_POOL */
1658947 va = dma_alloc_coherent(&hwdev->dev, size, &pap_lin, flags);
948
+#ifdef BCMDMA64OSL
949
+ PHYSADDRLOSET(*pap, pap_lin & 0xffffffff);
950
+ PHYSADDRHISET(*pap, (pap_lin >> 32) & 0xffffffff);
951
+#else
1659952 *pap = (dmaaddr_t)pap_lin;
953
+#endif /* BCMDMA64OSL */
1660954 }
1661955 #endif /* __ARM_ARCH_7A__ && !DHD_USE_COHERENT_MEM_FOR_RING */
1662956 #else
....@@ -1668,43 +962,139 @@
1668962 void
1669963 osl_dma_free_consistent(osl_t *osh, void *va, uint size, dmaaddr_t pa)
1670964 {
965
+#ifdef BCMDMA64OSL
966
+ dma_addr_t paddr;
967
+#endif /* BCMDMA64OSL */
1671968 ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
1672969
1673970 #ifndef BCM_SECURE_DMA
1674
-#if defined(__ARM_ARCH_7A__) && !defined(DHD_USE_COHERENT_MEM_FOR_RING)
971
+#if (defined(__ARM_ARCH_7A__) && !defined(DHD_USE_COHERENT_MEM_FOR_RING)) || \
972
+ defined(STB_SOC_WIFI)
1675973 kfree(va);
1676974 #else
975
+#ifdef BCMDMA64OSL
976
+ PHYSADDRTOULONG(pa, paddr);
977
+ pci_free_consistent(osh->pdev, size, va, paddr);
978
+#else
1677979 pci_free_consistent(osh->pdev, size, va, (dma_addr_t)pa);
980
+#endif /* BCMDMA64OSL */
1678981 #endif /* __ARM_ARCH_7A__ && !DHD_USE_COHERENT_MEM_FOR_RING */
1679982 #else
1680983 osl_sec_dma_free_consistent(osh, va, size, pa);
1681984 #endif /* BCM_SECURE_DMA */
1682985 }
1683986
987
+void *
988
+osl_virt_to_phys(void *va)
989
+{
990
+ return (void *)(uintptr)virt_to_phys(va);
991
+}
992
+
993
+#include <asm/cacheflush.h>
994
+void BCMFASTPATH
995
+osl_dma_flush(osl_t *osh, void *va, uint size, int direction, void *p, hnddma_seg_map_t *dmah)
996
+{
997
+ return;
998
+}
999
+
16841000 dmaaddr_t BCMFASTPATH
16851001 osl_dma_map(osl_t *osh, void *va, uint size, int direction, void *p, hnddma_seg_map_t *dmah)
16861002 {
16871003 int dir;
1004
+ dmaaddr_t ret_addr;
1005
+ dma_addr_t map_addr;
1006
+ int ret;
1007
+
1008
+ DMA_LOCK(osh);
16881009
16891010 ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
16901011 dir = (direction == DMA_TX)? PCI_DMA_TODEVICE: PCI_DMA_FROMDEVICE;
16911012
1013
+#ifdef STB_SOC_WIFI
1014
+#if (__LINUX_ARM_ARCH__ == 8)
1015
+ /* need to flush or invalidate the cache here */
1016
+ if (dir == DMA_TX) { /* to device */
1017
+ osl_cache_flush(va, size);
1018
+ } else if (dir == DMA_RX) { /* from device */
1019
+ osl_cache_inv(va, size);
1020
+ } else { /* both */
1021
+ osl_cache_flush(va, size);
1022
+ osl_cache_inv(va, size);
1023
+ }
1024
+ DMA_UNLOCK(osh);
1025
+ return virt_to_phys(va);
1026
+#else /* (__LINUX_ARM_ARCH__ == 8) */
1027
+ map_addr = dma_map_single(osh->pdev, va, size, dir);
1028
+ DMA_UNLOCK(osh);
1029
+ return map_addr;
1030
+#endif /* (__LINUX_ARM_ARCH__ == 8) */
1031
+#else /* ! STB_SOC_WIFI */
1032
+ map_addr = pci_map_single(osh->pdev, va, size, dir);
1033
+#endif /* ! STB_SOC_WIFI */
16921034
1035
+ ret = pci_dma_mapping_error(osh->pdev, map_addr);
16931036
1037
+ if (ret) {
1038
+ printk("%s: Failed to map memory\n", __FUNCTION__);
1039
+ PHYSADDRLOSET(ret_addr, 0);
1040
+ PHYSADDRHISET(ret_addr, 0);
1041
+ } else {
1042
+ PHYSADDRLOSET(ret_addr, map_addr & 0xffffffff);
1043
+ PHYSADDRHISET(ret_addr, (map_addr >> 32) & 0xffffffff);
1044
+ }
16941045
1695
- return (pci_map_single(osh->pdev, va, size, dir));
1046
+#ifdef DHD_MAP_LOGGING
1047
+ osl_dma_map_logging(osh, osh->dhd_map_log, ret_addr, size);
1048
+#endif /* DHD_MAP_LOGGING */
1049
+
1050
+ DMA_UNLOCK(osh);
1051
+
1052
+ return ret_addr;
16961053 }
16971054
16981055 void BCMFASTPATH
1699
-osl_dma_unmap(osl_t *osh, uint pa, uint size, int direction)
1056
+osl_dma_unmap(osl_t *osh, dmaaddr_t pa, uint size, int direction)
17001057 {
17011058 int dir;
1059
+#ifdef BCMDMA64OSL
1060
+ dma_addr_t paddr;
1061
+#endif /* BCMDMA64OSL */
17021062
17031063 ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
17041064
1065
+ DMA_LOCK(osh);
17051066
17061067 dir = (direction == DMA_TX)? PCI_DMA_TODEVICE: PCI_DMA_FROMDEVICE;
1068
+
1069
+#ifdef DHD_MAP_LOGGING
1070
+ osl_dma_map_logging(osh, osh->dhd_unmap_log, pa, size);
1071
+#endif /* DHD_MAP_LOGGING */
1072
+
1073
+#ifdef BCMDMA64OSL
1074
+ PHYSADDRTOULONG(pa, paddr);
1075
+ pci_unmap_single(osh->pdev, paddr, size, dir);
1076
+#else /* BCMDMA64OSL */
1077
+
1078
+#ifdef STB_SOC_WIFI
1079
+#if (__LINUX_ARM_ARCH__ == 8)
1080
+ if (dir == DMA_TX) { /* to device */
1081
+ dma_sync_single_for_device(OSH_NULL, pa, size, DMA_TX);
1082
+ } else if (dir == DMA_RX) { /* from device */
1083
+ dma_sync_single_for_cpu(OSH_NULL, pa, size, DMA_RX);
1084
+ } else { /* both */
1085
+ dma_sync_single_for_device(OSH_NULL, pa, size, DMA_TX);
1086
+ dma_sync_single_for_cpu(OSH_NULL, pa, size, DMA_RX);
1087
+ }
1088
+#else /* (__LINUX_ARM_ARCH__ == 8) */
1089
+ dma_unmap_single(osh->pdev, (uintptr)pa, size, dir);
1090
+#endif /* (__LINUX_ARM_ARCH__ == 8) */
1091
+#else /* STB_SOC_WIFI */
17071092 pci_unmap_single(osh->pdev, (uint32)pa, size, dir);
1093
+#endif /* STB_SOC_WIFI */
1094
+
1095
+#endif /* BCMDMA64OSL */
1096
+
1097
+ DMA_UNLOCK(osh);
17081098 }
17091099
17101100 /* OSL function for CPU relax */
....@@ -1714,41 +1104,15 @@
17141104 cpu_relax();
17151105 }
17161106
1717
-
1718
-#if (defined(__ARM_ARCH_7A__) && !defined(DHD_USE_COHERENT_MEM_FOR_RING))
1719
-
1720
-inline void BCMFASTPATH
1721
-osl_cache_flush(void *va, uint size)
1107
+extern void osl_preempt_disable(osl_t *osh)
17221108 {
1723
-
1724
- if (size > 0)
1725
- dma_sync_single_for_device(OSH_NULL, virt_to_dma(OSH_NULL, va), size, DMA_TX);
1109
+ preempt_disable();
17261110 }
17271111
1728
-inline void BCMFASTPATH
1729
-osl_cache_inv(void *va, uint size)
1112
+extern void osl_preempt_enable(osl_t *osh)
17301113 {
1731
-
1732
- dma_sync_single_for_cpu(OSH_NULL, virt_to_dma(OSH_NULL, va), size, DMA_RX);
1114
+ preempt_enable();
17331115 }
1734
-
1735
-inline void osl_prefetch(const void *ptr)
1736
-{
1737
- __asm__ __volatile__("pld\t%0" :: "o"(*(const char *)ptr) : "cc");
1738
-}
1739
-
1740
-int osl_arch_is_coherent(void)
1741
-{
1742
- return 0;
1743
-}
1744
-
1745
-
1746
-inline int osl_acp_war_enab(void)
1747
-{
1748
- return 0;
1749
-}
1750
-
1751
-#endif
17521116
17531117 #if defined(BCMASSERT_LOG)
17541118 void
....@@ -1768,13 +1132,29 @@
17681132 #ifdef BCMASSERT_LOG
17691133 snprintf(tempbuf, 64, "\"%s\": file \"%s\", line %d\n",
17701134 exp, basename, line);
1771
- printk("%s", tempbuf);
1135
+#ifndef OEM_ANDROID
1136
+ bcm_assert_log(tempbuf);
1137
+#endif /* OEM_ANDROID */
17721138 #endif /* BCMASSERT_LOG */
17731139
1774
-
1140
+ switch (g_assert_type) {
1141
+ case 0:
1142
+ panic("%s", tempbuf);
1143
+ break;
1144
+ case 1:
1145
+ /* fall through */
1146
+ case 3:
1147
+ printk("%s", tempbuf);
1148
+ break;
1149
+ case 2:
1150
+ printk("%s", tempbuf);
1151
+ BUG();
1152
+ break;
1153
+ default:
1154
+ break;
1155
+ }
17751156 }
1776
-#endif
1777
-
1157
+#endif // endif
17781158 void
17791159 osl_delay(uint usec)
17801160 {
....@@ -1790,147 +1170,60 @@
17901170 void
17911171 osl_sleep(uint ms)
17921172 {
1793
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
17941173 if (ms < 20)
17951174 usleep_range(ms*1000, ms*1000 + 1000);
17961175 else
1797
-#endif
1798
- msleep(ms);
1176
+ msleep(ms);
17991177 }
18001178
1801
-
1802
-
1803
-/* Clone a packet.
1804
- * The pkttag contents are NOT cloned.
1805
- */
1806
-#ifdef BCMDBG_CTRACE
1807
-void *
1808
-osl_pktdup(osl_t *osh, void *skb, int line, char *file)
1809
-#else
1810
-#ifdef BCM_OBJECT_TRACE
1811
-void *
1812
-osl_pktdup(osl_t *osh, void *skb, int line, const char *caller)
1813
-#else
1814
-void *
1815
-osl_pktdup(osl_t *osh, void *skb)
1816
-#endif /* BCM_OBJECT_TRACE */
1817
-#endif /* BCMDBG_CTRACE */
1179
+uint64
1180
+osl_sysuptime_us(void)
18181181 {
1819
- void * p;
1182
+ struct timespec64 ts;
1183
+ uint64 usec;
18201184
1821
- ASSERT(!PKTISCHAINED(skb));
1822
-
1823
- /* clear the CTFBUF flag if set and map the rest of the buffer
1824
- * before cloning.
1825
- */
1826
- PKTCTFMAP(osh, skb);
1827
-
1828
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
1829
- if ((p = pskb_copy((struct sk_buff *)skb, GFP_ATOMIC)) == NULL)
1830
-#else
1831
- if ((p = skb_clone((struct sk_buff *)skb, GFP_ATOMIC)) == NULL)
1832
-#endif
1833
- return NULL;
1834
-
1835
-#ifdef CTFPOOL
1836
- if (PKTISFAST(osh, skb)) {
1837
- ctfpool_t *ctfpool;
1838
-
1839
- /* if the buffer allocated from ctfpool is cloned then
1840
- * we can't be sure when it will be freed. since there
1841
- * is a chance that we will be losing a buffer
1842
- * from our pool, we increment the refill count for the
1843
- * object to be alloced later.
1844
- */
1845
- ctfpool = (ctfpool_t *)CTFPOOLPTR(osh, skb);
1846
- ASSERT(ctfpool != NULL);
1847
- PKTCLRFAST(osh, p);
1848
- PKTCLRFAST(osh, skb);
1849
- ctfpool->refills++;
1850
- }
1851
-#endif /* CTFPOOL */
1852
-
1853
- /* Clear PKTC context */
1854
- PKTSETCLINK(p, NULL);
1855
- PKTCCLRFLAGS(p);
1856
- PKTCSETCNT(p, 1);
1857
- PKTCSETLEN(p, PKTLEN(osh, skb));
1858
-
1859
- /* skb_clone copies skb->cb.. we don't want that */
1860
- if (osh->pub.pkttag)
1861
- OSL_PKTTAG_CLEAR(p);
1862
-
1863
- /* Increment the packet counter */
1864
- atomic_inc(&osh->cmn->pktalloced);
1865
-#ifdef BCM_OBJECT_TRACE
1866
- bcm_object_trace_opr(p, BCM_OBJDBG_ADD_PKT, caller, line);
1867
-#endif /* BCM_OBJECT_TRACE */
1868
-
1869
-#ifdef BCMDBG_CTRACE
1870
- ADD_CTRACE(osh, (struct sk_buff *)p, file, line);
1871
-#endif
1872
- return (p);
1185
+ ktime_get_real_ts64(&ts);
1186
+ /* tv_usec content is fraction of a second */
1187
+ usec = (uint64)ts.tv_sec * 1000000ul + (ts.tv_nsec / NSEC_PER_USEC);
1188
+ return usec;
18731189 }
18741190
1875
-#ifdef BCMDBG_CTRACE
1876
-int osl_pkt_is_frmnative(osl_t *osh, struct sk_buff *pkt)
1191
+uint64
1192
+osl_localtime_ns(void)
18771193 {
1878
- unsigned long flags;
1879
- struct sk_buff *skb;
1880
- int ck = FALSE;
1194
+ uint64 ts_nsec = 0;
18811195
1882
- spin_lock_irqsave(&osh->ctrace_lock, flags);
1196
+ ts_nsec = local_clock();
18831197
1884
- list_for_each_entry(skb, &osh->ctrace_list, ctrace_list) {
1885
- if (pkt == skb) {
1886
- ck = TRUE;
1887
- break;
1888
- }
1889
- }
1890
-
1891
- spin_unlock_irqrestore(&osh->ctrace_lock, flags);
1892
- return ck;
1198
+ return ts_nsec;
18931199 }
18941200
1895
-void osl_ctrace_dump(osl_t *osh, struct bcmstrbuf *b)
1201
+void
1202
+osl_get_localtime(uint64 *sec, uint64 *usec)
18961203 {
1897
- unsigned long flags;
1898
- struct sk_buff *skb;
1899
- int idx = 0;
1900
- int i, j;
1204
+ uint64 ts_nsec = 0;
1205
+ unsigned long rem_nsec = 0;
19011206
1902
- spin_lock_irqsave(&osh->ctrace_lock, flags);
1903
-
1904
- if (b != NULL)
1905
- bcm_bprintf(b, " Total %d sbk not free\n", osh->ctrace_num);
1906
- else
1907
- printk(" Total %d sbk not free\n", osh->ctrace_num);
1908
-
1909
- list_for_each_entry(skb, &osh->ctrace_list, ctrace_list) {
1910
- if (b != NULL)
1911
- bcm_bprintf(b, "[%d] skb %p:\n", ++idx, skb);
1912
- else
1913
- printk("[%d] skb %p:\n", ++idx, skb);
1914
-
1915
- for (i = 0; i < skb->ctrace_count; i++) {
1916
- j = (skb->ctrace_start + i) % CTRACE_NUM;
1917
- if (b != NULL)
1918
- bcm_bprintf(b, " [%s(%d)]\n", skb->func[j], skb->line[j]);
1919
- else
1920
- printk(" [%s(%d)]\n", skb->func[j], skb->line[j]);
1921
- }
1922
- if (b != NULL)
1923
- bcm_bprintf(b, "\n");
1924
- else
1925
- printk("\n");
1926
- }
1927
-
1928
- spin_unlock_irqrestore(&osh->ctrace_lock, flags);
1929
-
1930
- return;
1207
+ ts_nsec = local_clock();
1208
+ rem_nsec = do_div(ts_nsec, NSEC_PER_SEC);
1209
+ *sec = (uint64)ts_nsec;
1210
+ *usec = (uint64)(rem_nsec / MSEC_PER_SEC);
19311211 }
1932
-#endif /* BCMDBG_CTRACE */
19331212
1213
+uint64
1214
+osl_systztime_us(void)
1215
+{
1216
+ struct timespec64 ts;
1217
+ uint64 tzusec;
1218
+
1219
+ ktime_get_real_ts64(&ts);
1220
+ /* apply timezone */
1221
+ tzusec = (uint64)((ts.tv_sec - (sys_tz.tz_minuteswest * 60)) *
1222
+ USEC_PER_SEC);
1223
+ tzusec += ts.tv_nsec / NSEC_PER_USEC;
1224
+
1225
+ return tzusec;
1226
+}
19341227
19351228 /*
19361229 * OSLREGOPS specifies the use of osl_XXX routines to be used for register access
....@@ -1939,15 +1232,6 @@
19391232 /*
19401233 * BINOSL selects the slightly slower function-call-based binary compatible osl.
19411234 */
1942
-
1943
-uint
1944
-osl_pktalloced(osl_t *osh)
1945
-{
1946
- if (atomic_read(&osh->cmn->refcount) == 1)
1947
- return (atomic_read(&osh->cmn->pktalloced));
1948
- else
1949
- return 0;
1950
-}
19511235
19521236 uint32
19531237 osl_rand(void)
....@@ -1983,17 +1267,16 @@
19831267 {
19841268 struct file *fp = (struct file *)image;
19851269 int rdlen;
1986
- loff_t pos;
19871270
19881271 if (!image)
19891272 return 0;
19901273
1991
- pos = fp->f_pos;
19921274 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0))
1993
- rdlen = kernel_read(fp, (void *) buf, (size_t) len, (loff_t *) &pos);
1275
+ rdlen = kernel_read(fp, buf, len, &fp->f_pos);
19941276 #else
1995
- rdlen = kernel_read(fp, pos, buf, len);
1996
-#endif
1277
+ rdlen = kernel_read(fp, fp->f_pos, buf, len);
1278
+#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)) */
1279
+
19971280 if (rdlen > 0)
19981281 fp->f_pos += rdlen;
19991282
....@@ -2026,53 +1309,74 @@
20261309 /* Linux Kernel: File Operations: end */
20271310
20281311 #if (defined(STB) && defined(__arm__))
2029
-inline void osl_pcie_rreg(osl_t *osh, ulong addr, void *v, uint size)
1312
+inline void osl_pcie_rreg(osl_t *osh, ulong addr, volatile void *v, uint size)
20301313 {
20311314 unsigned long flags = 0;
20321315 int pci_access = 0;
1316
+ int acp_war_enab = ACP_WAR_ENAB();
20331317
20341318 if (osh && BUSTYPE(osh->bustype) == PCI_BUS)
20351319 pci_access = 1;
20361320
2037
- if (pci_access && ACP_WAR_ENAB())
1321
+ if (pci_access && acp_war_enab)
20381322 spin_lock_irqsave(&l2x0_reg_lock, flags);
20391323
20401324 switch (size) {
20411325 case sizeof(uint8):
2042
- *(uint8*)v = readb((volatile uint8*)(addr));
1326
+ *(volatile uint8*)v = readb((volatile uint8*)(addr));
20431327 break;
20441328 case sizeof(uint16):
2045
- *(uint16*)v = readw((volatile uint16*)(addr));
1329
+ *(volatile uint16*)v = readw((volatile uint16*)(addr));
20461330 break;
20471331 case sizeof(uint32):
2048
- *(uint32*)v = readl((volatile uint32*)(addr));
1332
+ *(volatile uint32*)v = readl((volatile uint32*)(addr));
20491333 break;
20501334 case sizeof(uint64):
2051
- *(uint64*)v = *((volatile uint64*)(addr));
1335
+ *(volatile uint64*)v = *((volatile uint64*)(addr));
20521336 break;
20531337 }
20541338
2055
- if (pci_access && ACP_WAR_ENAB())
1339
+ if (pci_access && acp_war_enab)
20561340 spin_unlock_irqrestore(&l2x0_reg_lock, flags);
20571341 }
2058
-#endif
1342
+#endif // endif
20591343
2060
-/* APIs to set/get specific quirks in OSL layer */
2061
-void
2062
-osl_flag_set(osl_t *osh, uint32 mask)
1344
+#if defined(BCM_BACKPLANE_TIMEOUT)
1345
+inline void osl_bpt_rreg(osl_t *osh, ulong addr, volatile void *v, uint size)
20631346 {
2064
- osh->flags |= mask;
2065
-}
1347
+ bool poll_timeout = FALSE;
1348
+ static int in_si_clear = FALSE;
20661349
2067
-#if defined(STB)
2068
-inline bool BCMFASTPATH
2069
-#else
2070
-bool
2071
-#endif
2072
-osl_is_flag_set(osl_t *osh, uint32 mask)
2073
-{
2074
- return (osh->flags & mask);
1350
+ switch (size) {
1351
+ case sizeof(uint8):
1352
+ *(volatile uint8*)v = readb((volatile uint8*)(addr));
1353
+ if (*(volatile uint8*)v == 0xff)
1354
+ poll_timeout = TRUE;
1355
+ break;
1356
+ case sizeof(uint16):
1357
+ *(volatile uint16*)v = readw((volatile uint16*)(addr));
1358
+ if (*(volatile uint16*)v == 0xffff)
1359
+ poll_timeout = TRUE;
1360
+ break;
1361
+ case sizeof(uint32):
1362
+ *(volatile uint32*)v = readl((volatile uint32*)(addr));
1363
+ if (*(volatile uint32*)v == 0xffffffff)
1364
+ poll_timeout = TRUE;
1365
+ break;
1366
+ case sizeof(uint64):
1367
+ *(volatile uint64*)v = *((volatile uint64*)(addr));
1368
+ if (*(volatile uint64*)v == 0xffffffffffffffff)
1369
+ poll_timeout = TRUE;
1370
+ break;
1371
+ }
1372
+
1373
+ if (osh && osh->sih && (in_si_clear == FALSE) && poll_timeout && osh->bpt_cb) {
1374
+ in_si_clear = TRUE;
1375
+ osh->bpt_cb((void *)osh->sih, (void *)addr);
1376
+ in_si_clear = FALSE;
1377
+ }
20751378 }
1379
+#endif /* BCM_BACKPLANE_TIMEOUT */
20761380
20771381 #ifdef BCM_SECURE_DMA
20781382 static void *
....@@ -2097,17 +1401,16 @@
20971401 if (iscache) {
20981402 addr = vmap(map, size >> PAGE_SHIFT, VM_MAP, __pgprot(PAGE_KERNEL));
20991403 if (isdecr) {
2100
- osh->contig_delta_va_pa = (phys_addr_t)(addr - page_to_phys(page));
1404
+ osh->contig_delta_va_pa = ((uint8 *)addr - page_to_phys(page));
21011405 }
2102
- }
2103
- else {
1406
+ } else {
21041407
21051408 #if defined(__ARM_ARCH_7A__)
21061409 addr = vmap(map, size >> PAGE_SHIFT, VM_MAP,
21071410 pgprot_noncached(__pgprot(PAGE_KERNEL)));
2108
-#endif
1411
+#endif // endif
21091412 if (isdecr) {
2110
- osh->contig_delta_va_pa = (phys_addr_t)(addr - page_to_phys(page));
1413
+ osh->contig_delta_va_pa = ((uint8 *)addr - page_to_phys(page));
21111414 }
21121415 }
21131416
....@@ -2160,7 +1463,6 @@
21601463 return ret;
21611464 }
21621465
2163
-
21641466 static void
21651467 osl_sec_dma_deinit_elem_mem_block(osl_t *osh, size_t mbsize, int max, void *sec_list_base)
21661468 {
....@@ -2207,11 +1509,6 @@
22071509 {
22081510 sec_mem_elem_t *sec_mem_elem = ptr_cma_info->sec_alloc_list;
22091511 sec_mem_elem_t *sec_prv_elem = ptr_cma_info->sec_alloc_list;
2210
-
2211
- if (!sec_mem_elem) {
2212
- printk("osl_sec_dma_find_rem_elem ptr_cma_info->sec_alloc_list is NULL \n");
2213
- return NULL;
2214
- }
22151512
22161513 if (sec_mem_elem->dma_handle == dma_handle) {
22171514
....@@ -2336,11 +1633,14 @@
23361633 dmah->nsegs = 1;
23371634 dmah->origsize = buflen;
23381635 }
1636
+ *(uint32 *)(pa_cma_kmap_va) = 0x0;
23391637 }
23401638
1639
+ if (direction == DMA_RX) {
1640
+ flush_kernel_vmap_range(pa_cma_kmap_va, sizeof(int));
1641
+ }
23411642 dma_handle = dma_map_page(OSH_NULL, pa_cma_page, loffset+offset, buflen,
23421643 (direction == DMA_TX ? DMA_TO_DEVICE:DMA_FROM_DEVICE));
2343
-
23441644 if (dmah) {
23451645 dmah->segs[0].addr = dma_handle;
23461646 dmah->segs[0].length = buflen;
....@@ -2359,7 +1659,7 @@
23591659 dma_addr_t dma_handle = 0x0;
23601660 uint loffset;
23611661
2362
- pa_cma = (phys_addr_t)(va - osh->contig_delta_va_pa);
1662
+ pa_cma = ((uint8 *)va - (uint8 *)osh->contig_delta_va_pa);
23631663 pa_cma_page = phys_to_page(pa_cma);
23641664 loffset = pa_cma -(pa_cma & ~(PAGE_SIZE-1));
23651665
....@@ -2374,7 +1674,6 @@
23741674 void *p, hnddma_seg_map_t *map, void *ptr_cma_info, uint offset)
23751675 {
23761676 sec_mem_elem_t *sec_mem_elem;
2377
- struct page *pa_cma_page;
23781677 void *pa_cma_kmap_va = NULL;
23791678 uint buflen = 0;
23801679 dma_addr_t pa_cma;
....@@ -2390,9 +1689,6 @@
23901689 va = (uint8 *)va - offset;
23911690 pa_cma = sec_mem_elem->pa_cma;
23921691
2393
- pa_cma_page = sec_mem_elem->pa_cma_page;
2394
-
2395
-
23961692 if (direction == DMA_RX) {
23971693
23981694 if (p == NULL) {
....@@ -2403,6 +1699,16 @@
24031699
24041700 pa_cma_kmap_va = sec_mem_elem->vac;
24051701
1702
+ do {
1703
+ invalidate_kernel_vmap_range(pa_cma_kmap_va, sizeof(int));
1704
+
1705
+ buflen = *(uint *)(pa_cma_kmap_va);
1706
+ if (buflen)
1707
+ break;
1708
+
1709
+ OSL_DELAY(1);
1710
+ read_count++;
1711
+ } while (read_count < 200);
24061712 dma_unmap_page(OSH_NULL, pa_cma, size, DMA_FROM_DEVICE);
24071713 memcpy(va, pa_cma_kmap_va, size);
24081714 /* kunmap_atomic(pa_cma_kmap_va); */
....@@ -2443,7 +1749,7 @@
24431749 osh->sec_cma_coherent[i].avail = TRUE;
24441750 osh->sec_cma_coherent[i].va = temp_va;
24451751 osh->sec_cma_coherent[i].pa = temp_pa;
2446
- temp_va += SEC_CMA_COHERENT_BLK;
1752
+ temp_va = ((uint8 *)temp_va)+SEC_CMA_COHERENT_BLK;
24471753 temp_pa += SEC_CMA_COHERENT_BLK;
24481754 }
24491755 }
....@@ -2493,44 +1799,173 @@
24931799 printf("%s:Error: va = 0x%p pa = 0x%lx size = %d\n", __FUNCTION__,
24941800 va, (ulong)pa, size);
24951801 }
2496
-
24971802 #endif /* BCM_SECURE_DMA */
24981803
2499
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0) && defined(TSQ_MULTIPLIER)
2500
-#include <linux/kallsyms.h>
2501
-#include <net/sock.h>
1804
+/* timer apis */
1805
+/* Note: All timer api's are thread unsafe and should be protected with locks by caller */
1806
+
1807
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
25021808 void
2503
-osl_pkt_orphan_partial(struct sk_buff *skb)
1809
+timer_cb_compat(struct timer_list *tl)
25041810 {
2505
- uint32 fraction;
2506
- static void *p_tcp_wfree = NULL;
2507
-
2508
- if (!skb->destructor || skb->destructor == sock_wfree)
2509
- return;
2510
-
2511
- if (unlikely(!p_tcp_wfree)) {
2512
- char sym[KSYM_SYMBOL_LEN];
2513
- sprint_symbol(sym, (unsigned long)skb->destructor);
2514
- sym[9] = 0;
2515
- if (!strcmp(sym, "tcp_wfree"))
2516
- p_tcp_wfree = skb->destructor;
2517
- else
2518
- return;
2519
- }
2520
-
2521
- if (unlikely(skb->destructor != p_tcp_wfree || !skb->sk))
2522
- return;
2523
-
2524
- /* abstract a certain portion of skb truesize from the socket
2525
- * sk_wmem_alloc to allow more skb can be allocated for this
2526
- * socket for better cusion meeting WiFi device requirement
2527
- */
2528
- fraction = skb->truesize * (TSQ_MULTIPLIER - 1) / TSQ_MULTIPLIER;
2529
- skb->truesize -= fraction;
2530
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0))
2531
- WARN_ON(refcount_sub_and_test(fraction, &skb->sk->sk_wmem_alloc));
2532
-#else
2533
- atomic_sub(fraction, &skb->sk->sk_wmem_alloc);
2534
-#endif
1811
+ timer_list_compat_t *t = container_of(tl, timer_list_compat_t, timer);
1812
+ t->callback((ulong)t->arg);
25351813 }
2536
-#endif /* LINUX_VERSION >= 3.6.0 && TSQ_MULTIPLIER */
1814
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0) */
1815
+
1816
+osl_timer_t *
1817
+osl_timer_init(osl_t *osh, const char *name, void (*fn)(void *arg), void *arg)
1818
+{
1819
+ osl_timer_t *t;
1820
+ BCM_REFERENCE(fn);
1821
+ if ((t = MALLOCZ(NULL, sizeof(osl_timer_t))) == NULL) {
1822
+ printk(KERN_ERR "osl_timer_init: out of memory, malloced %d bytes\n",
1823
+ (int)sizeof(osl_timer_t));
1824
+ return (NULL);
1825
+ }
1826
+ bzero(t, sizeof(osl_timer_t));
1827
+ if ((t->timer = MALLOCZ(NULL, sizeof(struct timer_list))) == NULL) {
1828
+ printf("osl_timer_init: malloc failed\n");
1829
+ MFREE(NULL, t, sizeof(osl_timer_t));
1830
+ return (NULL);
1831
+ }
1832
+ t->set = TRUE;
1833
+
1834
+ init_timer_compat(t->timer, (linux_timer_fn)fn, arg);
1835
+
1836
+ return (t);
1837
+}
1838
+
1839
+void
1840
+osl_timer_add(osl_t *osh, osl_timer_t *t, uint32 ms, bool periodic)
1841
+{
1842
+ if (t == NULL) {
1843
+ printf("%s: Timer handle is NULL\n", __FUNCTION__);
1844
+ return;
1845
+ }
1846
+ ASSERT(!t->set);
1847
+
1848
+ t->set = TRUE;
1849
+ if (periodic) {
1850
+ printf("Periodic timers are not supported by Linux timer apis\n");
1851
+ }
1852
+ timer_expires(t->timer) = jiffies + ms*HZ/1000;
1853
+
1854
+ add_timer(t->timer);
1855
+
1856
+ return;
1857
+}
1858
+
1859
+void
1860
+osl_timer_update(osl_t *osh, osl_timer_t *t, uint32 ms, bool periodic)
1861
+{
1862
+ if (t == NULL) {
1863
+ printf("%s: Timer handle is NULL\n", __FUNCTION__);
1864
+ return;
1865
+ }
1866
+ if (periodic) {
1867
+ printf("Periodic timers are not supported by Linux timer apis\n");
1868
+ }
1869
+ t->set = TRUE;
1870
+ timer_expires(t->timer) = jiffies + ms*HZ/1000;
1871
+
1872
+ mod_timer(t->timer, timer_expires(t->timer));
1873
+
1874
+ return;
1875
+}
1876
+
1877
+/*
1878
+ * Return TRUE if timer successfully deleted, FALSE if still pending
1879
+ */
1880
+bool
1881
+osl_timer_del(osl_t *osh, osl_timer_t *t)
1882
+{
1883
+ if (t == NULL) {
1884
+ printf("%s: Timer handle is NULL\n", __FUNCTION__);
1885
+ return (FALSE);
1886
+ }
1887
+ if (t->set) {
1888
+ t->set = FALSE;
1889
+ if (t->timer) {
1890
+ del_timer(t->timer);
1891
+ MFREE(NULL, t->timer, sizeof(struct timer_list));
1892
+ }
1893
+ MFREE(NULL, t, sizeof(osl_timer_t));
1894
+ }
1895
+ return (TRUE);
1896
+}
1897
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0))
1898
+int
1899
+kernel_read_compat(struct file *file, loff_t offset, char *addr, unsigned long count)
1900
+{
1901
+ return (int)kernel_read(file, addr, (size_t)count, &offset);
1902
+}
1903
+#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)) */
1904
+
1905
+void *
1906
+osl_spin_lock_init(osl_t *osh)
1907
+{
1908
+ /* Adding 4 bytes since the sizeof(spinlock_t) could be 0 */
1909
+ /* if CONFIG_SMP and CONFIG_DEBUG_SPINLOCK are not defined */
1910
+ /* and this results in kernel asserts in internal builds */
1911
+ spinlock_t * lock = MALLOC(osh, sizeof(spinlock_t) + 4);
1912
+ if (lock)
1913
+ spin_lock_init(lock);
1914
+ return ((void *)lock);
1915
+}
1916
+
1917
+void
1918
+osl_spin_lock_deinit(osl_t *osh, void *lock)
1919
+{
1920
+ if (lock)
1921
+ MFREE(osh, lock, sizeof(spinlock_t) + 4);
1922
+}
1923
+
1924
+unsigned long
1925
+osl_spin_lock(void *lock)
1926
+{
1927
+ unsigned long flags = 0;
1928
+
1929
+ if (lock)
1930
+ spin_lock_irqsave((spinlock_t *)lock, flags);
1931
+
1932
+ return flags;
1933
+}
1934
+
1935
+void
1936
+osl_spin_unlock(void *lock, unsigned long flags)
1937
+{
1938
+ if (lock)
1939
+ spin_unlock_irqrestore((spinlock_t *)lock, flags);
1940
+}
1941
+
1942
+#ifdef USE_DMA_LOCK
1943
+static void
1944
+osl_dma_lock(osl_t *osh)
1945
+{
1946
+ if (likely(in_irq() || irqs_disabled())) {
1947
+ spin_lock(&osh->dma_lock);
1948
+ } else {
1949
+ spin_lock_bh(&osh->dma_lock);
1950
+ osh->dma_lock_bh = TRUE;
1951
+ }
1952
+}
1953
+
1954
+static void
1955
+osl_dma_unlock(osl_t *osh)
1956
+{
1957
+ if (unlikely(osh->dma_lock_bh)) {
1958
+ osh->dma_lock_bh = FALSE;
1959
+ spin_unlock_bh(&osh->dma_lock);
1960
+ } else {
1961
+ spin_unlock(&osh->dma_lock);
1962
+ }
1963
+}
1964
+
1965
+static void
1966
+osl_dma_lock_init(osl_t *osh)
1967
+{
1968
+ spin_lock_init(&osh->dma_lock);
1969
+ osh->dma_lock_bh = FALSE;
1970
+}
1971
+#endif /* USE_DMA_LOCK */