.. | .. |
---|
1 | | -/* SPDX-License-Identifier: GPL-2.0 */ |
---|
2 | 1 | /* |
---|
3 | 2 | * Linux OS Independent Layer |
---|
4 | 3 | * |
---|
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 | + * |
---|
7 | 8 | * Unless you and Broadcom execute a separate written software license |
---|
8 | 9 | * agreement governing use of this software, this software is licensed to you |
---|
9 | 10 | * under the terms of the GNU General Public License version 2 (the "GPL"), |
---|
10 | 11 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the |
---|
11 | 12 | * following added to such license: |
---|
12 | | - * |
---|
| 13 | + * |
---|
13 | 14 | * As a special exception, the copyright holders of this software give you |
---|
14 | 15 | * permission to link this software with independent modules, and to copy and |
---|
15 | 16 | * distribute the resulting executable under terms of your choice, provided that |
---|
.. | .. |
---|
17 | 18 | * the license of that module. An independent module is a module which is not |
---|
18 | 19 | * derived from this software. The special exception does not apply to any |
---|
19 | 20 | * modifications of the software. |
---|
20 | | - * |
---|
| 21 | + * |
---|
21 | 22 | * Notwithstanding the above, under no circumstances may you combine this |
---|
22 | 23 | * software in any way with any other Broadcom software provided under a license |
---|
23 | 24 | * other than the GPL, without Broadcom's express prior written consent. |
---|
.. | .. |
---|
25 | 26 | * |
---|
26 | 27 | * <<Broadcom-WL-IPTag/Open:>> |
---|
27 | 28 | * |
---|
28 | | - * $Id: linux_osl.c 709309 2019-01-17 09:04:00Z $ |
---|
| 29 | + * $Id: linux_osl.c 697654 2017-05-04 11:59:40Z $ |
---|
29 | 30 | */ |
---|
30 | 31 | |
---|
31 | 32 | #define LINUX_PORT |
---|
.. | .. |
---|
35 | 36 | #include <linuxver.h> |
---|
36 | 37 | #include <bcmdefs.h> |
---|
37 | 38 | |
---|
38 | | - |
---|
39 | | -#if !defined(STBLINUX) |
---|
40 | 39 | #if defined(__ARM_ARCH_7A__) && !defined(DHD_USE_COHERENT_MEM_FOR_RING) |
---|
41 | 40 | #include <asm/cacheflush.h> |
---|
42 | 41 | #endif /* __ARM_ARCH_7A__ && !DHD_USE_COHERENT_MEM_FOR_RING */ |
---|
43 | | -#endif /* STBLINUX */ |
---|
44 | 42 | |
---|
45 | 43 | #include <linux/random.h> |
---|
46 | 44 | |
---|
47 | 45 | #include <osl.h> |
---|
48 | 46 | #include <bcmutils.h> |
---|
49 | 47 | #include <linux/delay.h> |
---|
| 48 | +#include <linux/vmalloc.h> |
---|
50 | 49 | #include <pcicfg.h> |
---|
51 | 50 | |
---|
| 51 | +#if defined(BCMASSERT_LOG) && !defined(OEM_ANDROID) |
---|
| 52 | +#include <bcm_assert_log.h> |
---|
| 53 | +#endif // endif |
---|
52 | 54 | |
---|
53 | 55 | #ifdef BCM_SECURE_DMA |
---|
54 | 56 | #include <linux/module.h> |
---|
.. | .. |
---|
60 | 62 | #include <linux/moduleparam.h> |
---|
61 | 63 | #include <asm/io.h> |
---|
62 | 64 | #include <linux/skbuff.h> |
---|
63 | | -#include <linux/vmalloc.h> |
---|
64 | 65 | #include <stbutils.h> |
---|
65 | 66 | #include <linux/highmem.h> |
---|
66 | 67 | #include <linux/dma-mapping.h> |
---|
67 | 68 | #include <asm/memory.h> |
---|
68 | | -#if defined(__ARM_ARCH_7A__) |
---|
69 | | -#include <arch/arm/include/asm/tlbflush.h> |
---|
70 | | -#endif |
---|
71 | 69 | #endif /* BCM_SECURE_DMA */ |
---|
72 | 70 | |
---|
73 | 71 | #include <linux/fs.h> |
---|
.. | .. |
---|
75 | 73 | #if defined(STB) |
---|
76 | 74 | #include <linux/spinlock.h> |
---|
77 | 75 | extern spinlock_t l2x0_reg_lock; |
---|
78 | | -#endif |
---|
| 76 | +#endif // endif |
---|
79 | 77 | |
---|
80 | 78 | #ifdef BCM_OBJECT_TRACE |
---|
81 | 79 | #include <bcmutils.h> |
---|
82 | 80 | #endif /* BCM_OBJECT_TRACE */ |
---|
| 81 | +#include "linux_osl_priv.h" |
---|
83 | 82 | |
---|
84 | 83 | #define PCI_CFG_RETRY 10 |
---|
85 | 84 | |
---|
86 | | -#define OS_HANDLE_MAGIC 0x1234abcd /* Magic # to recognize osh */ |
---|
87 | | -#define BCM_MEM_FILENAME_LEN 24 /* Mem. filename length */ |
---|
88 | 85 | #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 | | -}; |
---|
224 | 86 | |
---|
225 | 87 | #ifdef BCM_SECURE_DMA |
---|
226 | 88 | static void * osl_sec_dma_ioremap(osl_t *osh, struct page *page, size_t size, |
---|
.. | .. |
---|
239 | 101 | static void osl_sec_dma_free_consistent(osl_t *osh, void *va, uint size, dmaaddr_t pa); |
---|
240 | 102 | #endif /* BCM_SECURE_DMA */ |
---|
241 | 103 | |
---|
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 | | - |
---|
265 | 104 | /* PCMCIA attribute space access macros */ |
---|
266 | 105 | |
---|
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 */ |
---|
270 | 111 | |
---|
| 112 | +module_param(g_assert_type, int, 0); |
---|
271 | 113 | #ifdef BCM_SECURE_DMA |
---|
272 | 114 | #define SECDMA_MODULE_PARAMS 0 |
---|
273 | 115 | #define SECDMA_EXT_FILE 1 |
---|
274 | | - |
---|
275 | 116 | unsigned long secdma_addr = 0; |
---|
276 | 117 | unsigned long secdma_addr2 = 0; |
---|
277 | 118 | u32 secdma_size = 0; |
---|
.. | .. |
---|
283 | 124 | static int secdma_found = 0; |
---|
284 | 125 | #endif /* BCM_SECURE_DMA */ |
---|
285 | 126 | |
---|
| 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 | + |
---|
286 | 141 | static int16 linuxbcmerrormap[] = |
---|
287 | | -{ 0, /* 0 */ |
---|
| 142 | +{ 0, /* 0 */ |
---|
288 | 143 | -EINVAL, /* BCME_ERROR */ |
---|
289 | 144 | -EINVAL, /* BCME_BADARG */ |
---|
290 | 145 | -EINVAL, /* BCME_BADOPTION */ |
---|
.. | .. |
---|
338 | 193 | -ERANGE, /* BCME_REPLAY */ |
---|
339 | 194 | -EINVAL, /* BCME_IE_NOTFOUND */ |
---|
340 | 195 | -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 */ |
---|
341 | 211 | |
---|
342 | 212 | /* When an new error code is added to bcmutils.h, add os |
---|
343 | 213 | * specific error translation here as well |
---|
344 | 214 | */ |
---|
345 | 215 | /* check if BCME_LAST changed since the last time this function was updated */ |
---|
346 | | -#if BCME_LAST != -53 |
---|
| 216 | +#if BCME_LAST != -68 |
---|
347 | 217 | #error "You need to add a OS error translation in the linuxbcmerrormap \ |
---|
348 | 218 | for new error code defined in bcmutils.h" |
---|
349 | | -#endif |
---|
| 219 | +#endif // endif |
---|
350 | 220 | }; |
---|
351 | 221 | 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 */ |
---|
352 | 314 | |
---|
353 | 315 | /* translate bcmerrors into linux errors */ |
---|
354 | 316 | int |
---|
.. | .. |
---|
362 | 324 | /* Array bounds covered by ASSERT in osl_attach */ |
---|
363 | 325 | return linuxbcmerrormap[-bcmerror]; |
---|
364 | 326 | } |
---|
365 | | -#ifdef SHARED_OSL_CMN |
---|
366 | | -osl_t * |
---|
367 | | -osl_attach(void *pdev, uint bustype, bool pkttag, void **osl_cmn) |
---|
368 | | -{ |
---|
369 | | -#else |
---|
370 | 327 | osl_t * |
---|
371 | 328 | osl_attach(void *pdev, uint bustype, bool pkttag) |
---|
372 | 329 | { |
---|
373 | 330 | void **osl_cmn = NULL; |
---|
374 | | -#endif /* SHARED_OSL_CMN */ |
---|
375 | 331 | osl_t *osh; |
---|
376 | 332 | gfp_t flags; |
---|
377 | | - |
---|
378 | 333 | #ifdef BCM_SECURE_DMA |
---|
379 | 334 | u32 secdma_memsize; |
---|
380 | | -#endif |
---|
| 335 | +#endif // endif |
---|
381 | 336 | |
---|
382 | 337 | flags = CAN_SLEEP() ? GFP_KERNEL: GFP_ATOMIC; |
---|
383 | 338 | if (!(osh = kmalloc(sizeof(osl_t), flags))) |
---|
.. | .. |
---|
420 | 375 | |
---|
421 | 376 | if ((secdma_addr != 0) && (secdma_size != 0)) { |
---|
422 | 377 | printk("linux_osl.c: Buffer info passed via module params, using it.\n"); |
---|
423 | | - |
---|
424 | 378 | if (secdma_found == 0) { |
---|
425 | 379 | osh->contig_base_alloc = (phys_addr_t)secdma_addr; |
---|
426 | 380 | secdma_memsize = secdma_size; |
---|
.. | .. |
---|
432 | 386 | kfree(osh); |
---|
433 | 387 | return NULL; |
---|
434 | 388 | } |
---|
435 | | - |
---|
436 | 389 | osh->contig_base = (phys_addr_t)osh->contig_base_alloc; |
---|
437 | | - |
---|
438 | 390 | printf("linux_osl.c: secdma_cma_size = 0x%x\n", secdma_memsize); |
---|
439 | 391 | printf("linux_osl.c: secdma_cma_addr = 0x%x \n", |
---|
440 | 392 | (unsigned int)osh->contig_base_alloc); |
---|
.. | .. |
---|
442 | 394 | } |
---|
443 | 395 | else if (stbpriv_init(osh) == 0) { |
---|
444 | 396 | printk("linux_osl.c: stbpriv.txt found. Get buffer info.\n"); |
---|
445 | | - |
---|
446 | 397 | if (secdma_found == 0) { |
---|
447 | 398 | osh->contig_base_alloc = |
---|
448 | 399 | (phys_addr_t)bcm_strtoul(stbparam_get("secdma_cma_addr"), NULL, 0); |
---|
.. | .. |
---|
456 | 407 | kfree(osh); |
---|
457 | 408 | return NULL; |
---|
458 | 409 | } |
---|
459 | | - |
---|
460 | 410 | osh->contig_base = (phys_addr_t)osh->contig_base_alloc; |
---|
461 | | - |
---|
462 | 411 | printf("linux_osl.c: secdma_cma_size = 0x%x\n", secdma_memsize); |
---|
463 | 412 | printf("linux_osl.c: secdma_cma_addr = 0x%x \n", |
---|
464 | 413 | (unsigned int)osh->contig_base_alloc); |
---|
.. | .. |
---|
469 | 418 | kfree(osh); |
---|
470 | 419 | return NULL; |
---|
471 | 420 | } |
---|
472 | | - |
---|
473 | 421 | secdma_found++; |
---|
474 | 422 | osh->contig_base_alloc_coherent_va = osl_sec_dma_ioremap(osh, |
---|
475 | 423 | phys_to_page((u32)osh->contig_base_alloc), |
---|
.. | .. |
---|
529 | 477 | break; |
---|
530 | 478 | } |
---|
531 | 479 | |
---|
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); |
---|
537 | 481 | |
---|
| 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 */ |
---|
538 | 493 | |
---|
539 | 494 | 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; |
---|
592 | 495 | } |
---|
593 | 496 | |
---|
594 | 497 | void osl_set_bus_handle(osl_t *osh, void *bus_handle) |
---|
.. | .. |
---|
600 | 503 | { |
---|
601 | 504 | return osh->bus_handle; |
---|
602 | 505 | } |
---|
| 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 */ |
---|
603 | 516 | |
---|
604 | 517 | void |
---|
605 | 518 | osl_detach(osl_t *osh) |
---|
.. | .. |
---|
613 | 526 | osl_sec_dma_deinit_elem_mem_block(osh, CMA_BUFSIZE_4K, CMA_BUFNUM, osh->sec_list_base_4096); |
---|
614 | 527 | osl_sec_dma_iounmap(osh, osh->contig_base_coherent_va, CMA_DMA_DESC_MEMBLOCK); |
---|
615 | 528 | osl_sec_dma_iounmap(osh, osh->contig_base_va, CMA_DMA_DATA_MEMBLOCK); |
---|
616 | | - |
---|
617 | 529 | secdma_found--; |
---|
618 | 530 | #endif /* BCM_SECURE_DMA */ |
---|
619 | 531 | |
---|
620 | | - |
---|
621 | 532 | 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 */ |
---|
622 | 538 | |
---|
623 | 539 | ASSERT(osh->magic == OS_HANDLE_MAGIC); |
---|
624 | 540 | atomic_sub(1, &osh->cmn->refcount); |
---|
.. | .. |
---|
628 | 544 | kfree(osh); |
---|
629 | 545 | } |
---|
630 | 546 | |
---|
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) |
---|
632 | 550 | { |
---|
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 | +{ |
---|
643 | 576 | return 0; |
---|
644 | 577 | } |
---|
645 | 578 | |
---|
646 | | -static struct sk_buff *osl_alloc_skb(osl_t *osh, unsigned int len) |
---|
| 579 | +inline int BCMFASTPATH |
---|
| 580 | +osl_acp_war_enab(void) |
---|
647 | 581 | { |
---|
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 | | - |
---|
758 | 582 | return 0; |
---|
759 | 583 | } |
---|
760 | 584 | |
---|
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) |
---|
893 | 587 | { |
---|
894 | 588 | |
---|
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 */ |
---|
896 | 596 | } |
---|
897 | 597 | |
---|
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) |
---|
908 | 600 | { |
---|
909 | | -#if defined(BCMDBG_CTRACE) |
---|
910 | | - int i; |
---|
911 | | - struct sk_buff *skb; |
---|
912 | | -#endif |
---|
913 | 601 | |
---|
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 */ |
---|
934 | 607 | } |
---|
935 | 608 | |
---|
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) |
---|
945 | 611 | { |
---|
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 |
---|
971 | 615 | } |
---|
972 | 616 | |
---|
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 |
---|
1382 | 618 | |
---|
1383 | 619 | uint32 |
---|
1384 | 620 | osl_pci_read_config(osl_t *osh, uint offset, uint size) |
---|
.. | .. |
---|
1396 | 632 | if (val != 0xffffffff) |
---|
1397 | 633 | break; |
---|
1398 | 634 | } while (retry--); |
---|
1399 | | - |
---|
1400 | 635 | |
---|
1401 | 636 | return (val); |
---|
1402 | 637 | } |
---|
.. | .. |
---|
1427 | 662 | { |
---|
1428 | 663 | ASSERT(osh && (osh->magic == OS_HANDLE_MAGIC) && osh->pdev); |
---|
1429 | 664 | |
---|
1430 | | -#if defined(__ARM_ARCH_7A__) && LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35) |
---|
| 665 | +#if defined(__ARM_ARCH_7A__) |
---|
1431 | 666 | return pci_domain_nr(((struct pci_dev *)osh->pdev)->bus); |
---|
1432 | 667 | #else |
---|
1433 | 668 | return ((struct pci_dev *)osh->pdev)->bus->number; |
---|
1434 | | -#endif |
---|
| 669 | +#endif // endif |
---|
1435 | 670 | } |
---|
1436 | 671 | |
---|
1437 | 672 | /* return slot # for the pci device pointed by osh->pdev */ |
---|
.. | .. |
---|
1440 | 675 | { |
---|
1441 | 676 | ASSERT(osh && (osh->magic == OS_HANDLE_MAGIC) && osh->pdev); |
---|
1442 | 677 | |
---|
1443 | | -#if defined(__ARM_ARCH_7A__) && LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35) |
---|
| 678 | +#if defined(__ARM_ARCH_7A__) |
---|
1444 | 679 | return PCI_SLOT(((struct pci_dev *)osh->pdev)->devfn) + 1; |
---|
1445 | 680 | #else |
---|
1446 | 681 | return PCI_SLOT(((struct pci_dev *)osh->pdev)->devfn); |
---|
1447 | | -#endif |
---|
| 682 | +#endif // endif |
---|
1448 | 683 | } |
---|
1449 | 684 | |
---|
1450 | 685 | /* return domain # for the pci device pointed by osh->pdev */ |
---|
.. | .. |
---|
1536 | 771 | #endif /* CONFIG_DHD_USE_STATIC_BUF */ |
---|
1537 | 772 | |
---|
1538 | 773 | 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 |
---|
1539 | 777 | if ((addr = kmalloc(size, flags)) == NULL) { |
---|
| 778 | +#endif // endif |
---|
1540 | 779 | if (osh) |
---|
1541 | 780 | osh->failed++; |
---|
1542 | 781 | return (NULL); |
---|
.. | .. |
---|
1595 | 834 | |
---|
1596 | 835 | atomic_sub(size, &osh->cmn->malloced); |
---|
1597 | 836 | } |
---|
| 837 | +#if defined(DHD_USE_KVMALLOC) && (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)) |
---|
| 838 | + kvfree(addr); |
---|
| 839 | +#else |
---|
1598 | 840 | 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); |
---|
1599 | 888 | } |
---|
1600 | 889 | |
---|
1601 | 890 | uint |
---|
.. | .. |
---|
1622 | 911 | return (osh->failed); |
---|
1623 | 912 | } |
---|
1624 | 913 | |
---|
1625 | | - |
---|
1626 | 914 | uint |
---|
1627 | 915 | osl_dma_consistent_align(void) |
---|
1628 | 916 | { |
---|
.. | .. |
---|
1641 | 929 | *alloced = size; |
---|
1642 | 930 | |
---|
1643 | 931 | #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) |
---|
1645 | 934 | va = kmalloc(size, GFP_ATOMIC | __GFP_ZERO); |
---|
1646 | 935 | if (va) |
---|
1647 | 936 | *pap = (ulong)__virt_to_phys((ulong)va); |
---|
.. | .. |
---|
1656 | 945 | flags = CAN_SLEEP() ? GFP_KERNEL: GFP_ATOMIC; |
---|
1657 | 946 | #endif /* DHD_ALLOC_COHERENT_MEM_FROM_ATOMIC_POOL */ |
---|
1658 | 947 | 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 |
---|
1659 | 952 | *pap = (dmaaddr_t)pap_lin; |
---|
| 953 | +#endif /* BCMDMA64OSL */ |
---|
1660 | 954 | } |
---|
1661 | 955 | #endif /* __ARM_ARCH_7A__ && !DHD_USE_COHERENT_MEM_FOR_RING */ |
---|
1662 | 956 | #else |
---|
.. | .. |
---|
1668 | 962 | void |
---|
1669 | 963 | osl_dma_free_consistent(osl_t *osh, void *va, uint size, dmaaddr_t pa) |
---|
1670 | 964 | { |
---|
| 965 | +#ifdef BCMDMA64OSL |
---|
| 966 | + dma_addr_t paddr; |
---|
| 967 | +#endif /* BCMDMA64OSL */ |
---|
1671 | 968 | ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC))); |
---|
1672 | 969 | |
---|
1673 | 970 | #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) |
---|
1675 | 973 | kfree(va); |
---|
1676 | 974 | #else |
---|
| 975 | +#ifdef BCMDMA64OSL |
---|
| 976 | + PHYSADDRTOULONG(pa, paddr); |
---|
| 977 | + pci_free_consistent(osh->pdev, size, va, paddr); |
---|
| 978 | +#else |
---|
1677 | 979 | pci_free_consistent(osh->pdev, size, va, (dma_addr_t)pa); |
---|
| 980 | +#endif /* BCMDMA64OSL */ |
---|
1678 | 981 | #endif /* __ARM_ARCH_7A__ && !DHD_USE_COHERENT_MEM_FOR_RING */ |
---|
1679 | 982 | #else |
---|
1680 | 983 | osl_sec_dma_free_consistent(osh, va, size, pa); |
---|
1681 | 984 | #endif /* BCM_SECURE_DMA */ |
---|
1682 | 985 | } |
---|
1683 | 986 | |
---|
| 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 | + |
---|
1684 | 1000 | dmaaddr_t BCMFASTPATH |
---|
1685 | 1001 | osl_dma_map(osl_t *osh, void *va, uint size, int direction, void *p, hnddma_seg_map_t *dmah) |
---|
1686 | 1002 | { |
---|
1687 | 1003 | int dir; |
---|
| 1004 | + dmaaddr_t ret_addr; |
---|
| 1005 | + dma_addr_t map_addr; |
---|
| 1006 | + int ret; |
---|
| 1007 | + |
---|
| 1008 | + DMA_LOCK(osh); |
---|
1688 | 1009 | |
---|
1689 | 1010 | ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC))); |
---|
1690 | 1011 | dir = (direction == DMA_TX)? PCI_DMA_TODEVICE: PCI_DMA_FROMDEVICE; |
---|
1691 | 1012 | |
---|
| 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 */ |
---|
1692 | 1034 | |
---|
| 1035 | + ret = pci_dma_mapping_error(osh->pdev, map_addr); |
---|
1693 | 1036 | |
---|
| 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 | + } |
---|
1694 | 1045 | |
---|
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; |
---|
1696 | 1053 | } |
---|
1697 | 1054 | |
---|
1698 | 1055 | 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) |
---|
1700 | 1057 | { |
---|
1701 | 1058 | int dir; |
---|
| 1059 | +#ifdef BCMDMA64OSL |
---|
| 1060 | + dma_addr_t paddr; |
---|
| 1061 | +#endif /* BCMDMA64OSL */ |
---|
1702 | 1062 | |
---|
1703 | 1063 | ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC))); |
---|
1704 | 1064 | |
---|
| 1065 | + DMA_LOCK(osh); |
---|
1705 | 1066 | |
---|
1706 | 1067 | 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 */ |
---|
1707 | 1092 | pci_unmap_single(osh->pdev, (uint32)pa, size, dir); |
---|
| 1093 | +#endif /* STB_SOC_WIFI */ |
---|
| 1094 | + |
---|
| 1095 | +#endif /* BCMDMA64OSL */ |
---|
| 1096 | + |
---|
| 1097 | + DMA_UNLOCK(osh); |
---|
1708 | 1098 | } |
---|
1709 | 1099 | |
---|
1710 | 1100 | /* OSL function for CPU relax */ |
---|
.. | .. |
---|
1714 | 1104 | cpu_relax(); |
---|
1715 | 1105 | } |
---|
1716 | 1106 | |
---|
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) |
---|
1722 | 1108 | { |
---|
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(); |
---|
1726 | 1110 | } |
---|
1727 | 1111 | |
---|
1728 | | -inline void BCMFASTPATH |
---|
1729 | | -osl_cache_inv(void *va, uint size) |
---|
| 1112 | +extern void osl_preempt_enable(osl_t *osh) |
---|
1730 | 1113 | { |
---|
1731 | | - |
---|
1732 | | - dma_sync_single_for_cpu(OSH_NULL, virt_to_dma(OSH_NULL, va), size, DMA_RX); |
---|
| 1114 | + preempt_enable(); |
---|
1733 | 1115 | } |
---|
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 |
---|
1752 | 1116 | |
---|
1753 | 1117 | #if defined(BCMASSERT_LOG) |
---|
1754 | 1118 | void |
---|
.. | .. |
---|
1768 | 1132 | #ifdef BCMASSERT_LOG |
---|
1769 | 1133 | snprintf(tempbuf, 64, "\"%s\": file \"%s\", line %d\n", |
---|
1770 | 1134 | exp, basename, line); |
---|
1771 | | - printk("%s", tempbuf); |
---|
| 1135 | +#ifndef OEM_ANDROID |
---|
| 1136 | + bcm_assert_log(tempbuf); |
---|
| 1137 | +#endif /* OEM_ANDROID */ |
---|
1772 | 1138 | #endif /* BCMASSERT_LOG */ |
---|
1773 | 1139 | |
---|
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 | + } |
---|
1775 | 1156 | } |
---|
1776 | | -#endif |
---|
1777 | | - |
---|
| 1157 | +#endif // endif |
---|
1778 | 1158 | void |
---|
1779 | 1159 | osl_delay(uint usec) |
---|
1780 | 1160 | { |
---|
.. | .. |
---|
1790 | 1170 | void |
---|
1791 | 1171 | osl_sleep(uint ms) |
---|
1792 | 1172 | { |
---|
1793 | | -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36) |
---|
1794 | 1173 | if (ms < 20) |
---|
1795 | 1174 | usleep_range(ms*1000, ms*1000 + 1000); |
---|
1796 | 1175 | else |
---|
1797 | | -#endif |
---|
1798 | | - msleep(ms); |
---|
| 1176 | + msleep(ms); |
---|
1799 | 1177 | } |
---|
1800 | 1178 | |
---|
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) |
---|
1818 | 1181 | { |
---|
1819 | | - void * p; |
---|
| 1182 | + struct timespec64 ts; |
---|
| 1183 | + uint64 usec; |
---|
1820 | 1184 | |
---|
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; |
---|
1873 | 1189 | } |
---|
1874 | 1190 | |
---|
1875 | | -#ifdef BCMDBG_CTRACE |
---|
1876 | | -int osl_pkt_is_frmnative(osl_t *osh, struct sk_buff *pkt) |
---|
| 1191 | +uint64 |
---|
| 1192 | +osl_localtime_ns(void) |
---|
1877 | 1193 | { |
---|
1878 | | - unsigned long flags; |
---|
1879 | | - struct sk_buff *skb; |
---|
1880 | | - int ck = FALSE; |
---|
| 1194 | + uint64 ts_nsec = 0; |
---|
1881 | 1195 | |
---|
1882 | | - spin_lock_irqsave(&osh->ctrace_lock, flags); |
---|
| 1196 | + ts_nsec = local_clock(); |
---|
1883 | 1197 | |
---|
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; |
---|
1893 | 1199 | } |
---|
1894 | 1200 | |
---|
1895 | | -void osl_ctrace_dump(osl_t *osh, struct bcmstrbuf *b) |
---|
| 1201 | +void |
---|
| 1202 | +osl_get_localtime(uint64 *sec, uint64 *usec) |
---|
1896 | 1203 | { |
---|
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; |
---|
1901 | 1206 | |
---|
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); |
---|
1931 | 1211 | } |
---|
1932 | | -#endif /* BCMDBG_CTRACE */ |
---|
1933 | 1212 | |
---|
| 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 | +} |
---|
1934 | 1227 | |
---|
1935 | 1228 | /* |
---|
1936 | 1229 | * OSLREGOPS specifies the use of osl_XXX routines to be used for register access |
---|
.. | .. |
---|
1939 | 1232 | /* |
---|
1940 | 1233 | * BINOSL selects the slightly slower function-call-based binary compatible osl. |
---|
1941 | 1234 | */ |
---|
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 | | -} |
---|
1951 | 1235 | |
---|
1952 | 1236 | uint32 |
---|
1953 | 1237 | osl_rand(void) |
---|
.. | .. |
---|
1983 | 1267 | { |
---|
1984 | 1268 | struct file *fp = (struct file *)image; |
---|
1985 | 1269 | int rdlen; |
---|
1986 | | - loff_t pos; |
---|
1987 | 1270 | |
---|
1988 | 1271 | if (!image) |
---|
1989 | 1272 | return 0; |
---|
1990 | 1273 | |
---|
1991 | | - pos = fp->f_pos; |
---|
1992 | 1274 | #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); |
---|
1994 | 1276 | #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 | + |
---|
1997 | 1280 | if (rdlen > 0) |
---|
1998 | 1281 | fp->f_pos += rdlen; |
---|
1999 | 1282 | |
---|
.. | .. |
---|
2026 | 1309 | /* Linux Kernel: File Operations: end */ |
---|
2027 | 1310 | |
---|
2028 | 1311 | #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) |
---|
2030 | 1313 | { |
---|
2031 | 1314 | unsigned long flags = 0; |
---|
2032 | 1315 | int pci_access = 0; |
---|
| 1316 | + int acp_war_enab = ACP_WAR_ENAB(); |
---|
2033 | 1317 | |
---|
2034 | 1318 | if (osh && BUSTYPE(osh->bustype) == PCI_BUS) |
---|
2035 | 1319 | pci_access = 1; |
---|
2036 | 1320 | |
---|
2037 | | - if (pci_access && ACP_WAR_ENAB()) |
---|
| 1321 | + if (pci_access && acp_war_enab) |
---|
2038 | 1322 | spin_lock_irqsave(&l2x0_reg_lock, flags); |
---|
2039 | 1323 | |
---|
2040 | 1324 | switch (size) { |
---|
2041 | 1325 | case sizeof(uint8): |
---|
2042 | | - *(uint8*)v = readb((volatile uint8*)(addr)); |
---|
| 1326 | + *(volatile uint8*)v = readb((volatile uint8*)(addr)); |
---|
2043 | 1327 | break; |
---|
2044 | 1328 | case sizeof(uint16): |
---|
2045 | | - *(uint16*)v = readw((volatile uint16*)(addr)); |
---|
| 1329 | + *(volatile uint16*)v = readw((volatile uint16*)(addr)); |
---|
2046 | 1330 | break; |
---|
2047 | 1331 | case sizeof(uint32): |
---|
2048 | | - *(uint32*)v = readl((volatile uint32*)(addr)); |
---|
| 1332 | + *(volatile uint32*)v = readl((volatile uint32*)(addr)); |
---|
2049 | 1333 | break; |
---|
2050 | 1334 | case sizeof(uint64): |
---|
2051 | | - *(uint64*)v = *((volatile uint64*)(addr)); |
---|
| 1335 | + *(volatile uint64*)v = *((volatile uint64*)(addr)); |
---|
2052 | 1336 | break; |
---|
2053 | 1337 | } |
---|
2054 | 1338 | |
---|
2055 | | - if (pci_access && ACP_WAR_ENAB()) |
---|
| 1339 | + if (pci_access && acp_war_enab) |
---|
2056 | 1340 | spin_unlock_irqrestore(&l2x0_reg_lock, flags); |
---|
2057 | 1341 | } |
---|
2058 | | -#endif |
---|
| 1342 | +#endif // endif |
---|
2059 | 1343 | |
---|
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) |
---|
2063 | 1346 | { |
---|
2064 | | - osh->flags |= mask; |
---|
2065 | | -} |
---|
| 1347 | + bool poll_timeout = FALSE; |
---|
| 1348 | + static int in_si_clear = FALSE; |
---|
2066 | 1349 | |
---|
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 | + } |
---|
2075 | 1378 | } |
---|
| 1379 | +#endif /* BCM_BACKPLANE_TIMEOUT */ |
---|
2076 | 1380 | |
---|
2077 | 1381 | #ifdef BCM_SECURE_DMA |
---|
2078 | 1382 | static void * |
---|
.. | .. |
---|
2097 | 1401 | if (iscache) { |
---|
2098 | 1402 | addr = vmap(map, size >> PAGE_SHIFT, VM_MAP, __pgprot(PAGE_KERNEL)); |
---|
2099 | 1403 | 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)); |
---|
2101 | 1405 | } |
---|
2102 | | - } |
---|
2103 | | - else { |
---|
| 1406 | + } else { |
---|
2104 | 1407 | |
---|
2105 | 1408 | #if defined(__ARM_ARCH_7A__) |
---|
2106 | 1409 | addr = vmap(map, size >> PAGE_SHIFT, VM_MAP, |
---|
2107 | 1410 | pgprot_noncached(__pgprot(PAGE_KERNEL))); |
---|
2108 | | -#endif |
---|
| 1411 | +#endif // endif |
---|
2109 | 1412 | 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)); |
---|
2111 | 1414 | } |
---|
2112 | 1415 | } |
---|
2113 | 1416 | |
---|
.. | .. |
---|
2160 | 1463 | return ret; |
---|
2161 | 1464 | } |
---|
2162 | 1465 | |
---|
2163 | | - |
---|
2164 | 1466 | static void |
---|
2165 | 1467 | osl_sec_dma_deinit_elem_mem_block(osl_t *osh, size_t mbsize, int max, void *sec_list_base) |
---|
2166 | 1468 | { |
---|
.. | .. |
---|
2207 | 1509 | { |
---|
2208 | 1510 | sec_mem_elem_t *sec_mem_elem = ptr_cma_info->sec_alloc_list; |
---|
2209 | 1511 | 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 | | - } |
---|
2215 | 1512 | |
---|
2216 | 1513 | if (sec_mem_elem->dma_handle == dma_handle) { |
---|
2217 | 1514 | |
---|
.. | .. |
---|
2336 | 1633 | dmah->nsegs = 1; |
---|
2337 | 1634 | dmah->origsize = buflen; |
---|
2338 | 1635 | } |
---|
| 1636 | + *(uint32 *)(pa_cma_kmap_va) = 0x0; |
---|
2339 | 1637 | } |
---|
2340 | 1638 | |
---|
| 1639 | + if (direction == DMA_RX) { |
---|
| 1640 | + flush_kernel_vmap_range(pa_cma_kmap_va, sizeof(int)); |
---|
| 1641 | + } |
---|
2341 | 1642 | dma_handle = dma_map_page(OSH_NULL, pa_cma_page, loffset+offset, buflen, |
---|
2342 | 1643 | (direction == DMA_TX ? DMA_TO_DEVICE:DMA_FROM_DEVICE)); |
---|
2343 | | - |
---|
2344 | 1644 | if (dmah) { |
---|
2345 | 1645 | dmah->segs[0].addr = dma_handle; |
---|
2346 | 1646 | dmah->segs[0].length = buflen; |
---|
.. | .. |
---|
2359 | 1659 | dma_addr_t dma_handle = 0x0; |
---|
2360 | 1660 | uint loffset; |
---|
2361 | 1661 | |
---|
2362 | | - pa_cma = (phys_addr_t)(va - osh->contig_delta_va_pa); |
---|
| 1662 | + pa_cma = ((uint8 *)va - (uint8 *)osh->contig_delta_va_pa); |
---|
2363 | 1663 | pa_cma_page = phys_to_page(pa_cma); |
---|
2364 | 1664 | loffset = pa_cma -(pa_cma & ~(PAGE_SIZE-1)); |
---|
2365 | 1665 | |
---|
.. | .. |
---|
2374 | 1674 | void *p, hnddma_seg_map_t *map, void *ptr_cma_info, uint offset) |
---|
2375 | 1675 | { |
---|
2376 | 1676 | sec_mem_elem_t *sec_mem_elem; |
---|
2377 | | - struct page *pa_cma_page; |
---|
2378 | 1677 | void *pa_cma_kmap_va = NULL; |
---|
2379 | 1678 | uint buflen = 0; |
---|
2380 | 1679 | dma_addr_t pa_cma; |
---|
.. | .. |
---|
2390 | 1689 | va = (uint8 *)va - offset; |
---|
2391 | 1690 | pa_cma = sec_mem_elem->pa_cma; |
---|
2392 | 1691 | |
---|
2393 | | - pa_cma_page = sec_mem_elem->pa_cma_page; |
---|
2394 | | - |
---|
2395 | | - |
---|
2396 | 1692 | if (direction == DMA_RX) { |
---|
2397 | 1693 | |
---|
2398 | 1694 | if (p == NULL) { |
---|
.. | .. |
---|
2403 | 1699 | |
---|
2404 | 1700 | pa_cma_kmap_va = sec_mem_elem->vac; |
---|
2405 | 1701 | |
---|
| 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); |
---|
2406 | 1712 | dma_unmap_page(OSH_NULL, pa_cma, size, DMA_FROM_DEVICE); |
---|
2407 | 1713 | memcpy(va, pa_cma_kmap_va, size); |
---|
2408 | 1714 | /* kunmap_atomic(pa_cma_kmap_va); */ |
---|
.. | .. |
---|
2443 | 1749 | osh->sec_cma_coherent[i].avail = TRUE; |
---|
2444 | 1750 | osh->sec_cma_coherent[i].va = temp_va; |
---|
2445 | 1751 | 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; |
---|
2447 | 1753 | temp_pa += SEC_CMA_COHERENT_BLK; |
---|
2448 | 1754 | } |
---|
2449 | 1755 | } |
---|
.. | .. |
---|
2493 | 1799 | printf("%s:Error: va = 0x%p pa = 0x%lx size = %d\n", __FUNCTION__, |
---|
2494 | 1800 | va, (ulong)pa, size); |
---|
2495 | 1801 | } |
---|
2496 | | - |
---|
2497 | 1802 | #endif /* BCM_SECURE_DMA */ |
---|
2498 | 1803 | |
---|
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) |
---|
2502 | 1808 | void |
---|
2503 | | -osl_pkt_orphan_partial(struct sk_buff *skb) |
---|
| 1809 | +timer_cb_compat(struct timer_list *tl) |
---|
2504 | 1810 | { |
---|
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); |
---|
2535 | 1813 | } |
---|
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 */ |
---|