1 /* 2 * Private header file for Linux OS Independent Layer 3 * 4 * Copyright (C) 2020, Broadcom. 5 * 6 * Unless you and Broadcom execute a separate written software license 7 * agreement governing use of this software, this software is licensed to you 8 * under the terms of the GNU General Public License version 2 (the "GPL"), 9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 10 * following added to such license: 11 * 12 * As a special exception, the copyright holders of this software give you 13 * permission to link this software with independent modules, and to copy and 14 * distribute the resulting executable under terms of your choice, provided that 15 * you also meet, for each linked independent module, the terms and conditions of 16 * the license of that module. An independent module is a module which is not 17 * derived from this software. The special exception does not apply to any 18 * modifications of the software. 19 * 20 * 21 * <<Broadcom-WL-IPTag/Dual:>> 22 */ 23 24 #ifndef _LINUX_OSL_PRIV_H_ 25 #define _LINUX_OSL_PRIV_H_ 26 27 #include <osl.h> 28 29 #define OS_HANDLE_MAGIC 0x1234abcd /* Magic # to recognize osh */ 30 #define BCM_MEM_FILENAME_LEN 24 /* Mem. filename length */ 31 32 /* dependancy check */ 33 #if !defined(BCMPCIE) && defined(DHD_USE_STATIC_CTRLBUF) 34 #error "DHD_USE_STATIC_CTRLBUF suppored PCIE target only" 35 #endif /* !BCMPCIE && DHD_USE_STATIC_CTRLBUF */ 36 37 #define OSL_MEMLIST_LOCK(lock, flags) (flags) = osl_spin_lock(lock) 38 #define OSL_MEMLIST_UNLOCK(lock, flags) osl_spin_unlock((lock), (flags)) 39 40 #define OSL_STATIC_BUF_LOCK(lock, flags) (flags) = osl_spin_lock(lock) 41 #define OSL_STATIC_BUF_UNLOCK(lock, flags) osl_spin_unlock((lock), (flags)) 42 43 #define OSL_STATIC_PKT_LOCK(lock, flags) (flags) = osl_spin_lock(lock) 44 #define OSL_STATIC_PKT_UNLOCK(lock, flags) osl_spin_unlock((lock), (flags)) 45 46 #define OSL_PKTLIST_LOCK(lock, flags) (flags) = osl_spin_lock(lock) 47 #define OSL_PKTLIST_UNLOCK(lock, flags) osl_spin_unlock((lock), (flags)) 48 49 #define OSL_CTRACE_LOCK(lock, flags) (flags) = osl_spin_lock(lock) 50 #define OSL_CTRACE_UNLOCK(lock, flags) osl_spin_unlock((lock), (flags)) 51 52 #ifdef CONFIG_DHD_USE_STATIC_BUF 53 #ifdef DHD_USE_STATIC_CTRLBUF 54 #define DHD_SKB_1PAGE_BUFSIZE (PAGE_SIZE*1) 55 #define DHD_SKB_2PAGE_BUFSIZE (PAGE_SIZE*2) 56 #define DHD_SKB_4PAGE_BUFSIZE (PAGE_SIZE*4) 57 58 #define PREALLOC_FREE_MAGIC 0xFEDC 59 #define PREALLOC_USED_MAGIC 0xFCDE 60 #else 61 #define DHD_SKB_HDRSIZE 336 62 #define DHD_SKB_1PAGE_BUFSIZE ((PAGE_SIZE*1)-DHD_SKB_HDRSIZE) 63 #define DHD_SKB_2PAGE_BUFSIZE ((PAGE_SIZE*2)-DHD_SKB_HDRSIZE) 64 #define DHD_SKB_4PAGE_BUFSIZE ((PAGE_SIZE*4)-DHD_SKB_HDRSIZE) 65 #endif /* DHD_USE_STATIC_CTRLBUF */ 66 67 #define STATIC_BUF_MAX_NUM 16 68 #define STATIC_BUF_SIZE (PAGE_SIZE*2) 69 #define STATIC_BUF_TOTAL_LEN (STATIC_BUF_MAX_NUM * STATIC_BUF_SIZE) 70 71 typedef struct bcm_static_buf { 72 spinlock_t static_lock; 73 unsigned char *buf_ptr; 74 unsigned char buf_use[STATIC_BUF_MAX_NUM]; 75 } bcm_static_buf_t; 76 77 extern bcm_static_buf_t *bcm_static_buf; 78 79 #ifdef DHD_USE_STATIC_CTRLBUF 80 #define STATIC_PKT_4PAGE_NUM 0 81 #define DHD_SKB_MAX_BUFSIZE DHD_SKB_2PAGE_BUFSIZE 82 #elif defined(ENHANCED_STATIC_BUF) 83 #define STATIC_PKT_4PAGE_NUM 1 84 #define DHD_SKB_MAX_BUFSIZE DHD_SKB_4PAGE_BUFSIZE 85 #else 86 #define STATIC_PKT_4PAGE_NUM 0 87 #define DHD_SKB_MAX_BUFSIZE DHD_SKB_2PAGE_BUFSIZE 88 #endif /* DHD_USE_STATIC_CTRLBUF */ 89 90 #ifdef DHD_USE_STATIC_CTRLBUF 91 #define STATIC_PKT_1PAGE_NUM 0 92 /* Should match DHD_SKB_2PAGE_BUF_NUM */ 93 #define STATIC_PKT_2PAGE_NUM 192 94 #else 95 #define STATIC_PKT_1PAGE_NUM 8 96 #define STATIC_PKT_2PAGE_NUM 8 97 #endif /* DHD_USE_STATIC_CTRLBUF */ 98 99 #define STATIC_PKT_1_2PAGE_NUM \ 100 ((STATIC_PKT_1PAGE_NUM) + (STATIC_PKT_2PAGE_NUM)) 101 #define STATIC_PKT_MAX_NUM \ 102 ((STATIC_PKT_1_2PAGE_NUM) + (STATIC_PKT_4PAGE_NUM)) 103 104 typedef struct bcm_static_pkt { 105 #ifdef DHD_USE_STATIC_CTRLBUF 106 struct sk_buff *skb_8k[STATIC_PKT_2PAGE_NUM]; 107 unsigned char pkt_invalid[STATIC_PKT_2PAGE_NUM]; 108 spinlock_t osl_pkt_lock; 109 uint32 last_allocated_index; 110 #else 111 struct sk_buff *skb_4k[STATIC_PKT_1PAGE_NUM]; 112 struct sk_buff *skb_8k[STATIC_PKT_2PAGE_NUM]; 113 #ifdef ENHANCED_STATIC_BUF 114 struct sk_buff *skb_16k; 115 #endif /* ENHANCED_STATIC_BUF */ 116 struct semaphore osl_pkt_sem; 117 #endif /* DHD_USE_STATIC_CTRLBUF */ 118 unsigned char pkt_use[STATIC_PKT_MAX_NUM]; 119 } bcm_static_pkt_t; 120 121 extern bcm_static_pkt_t *bcm_static_skb; 122 #endif /* CONFIG_DHD_USE_STATIC_BUF */ 123 124 typedef struct bcm_mem_link { 125 struct bcm_mem_link *prev; 126 struct bcm_mem_link *next; 127 uint size; 128 int line; 129 void *osh; 130 char file[BCM_MEM_FILENAME_LEN]; 131 } bcm_mem_link_t; 132 133 struct osl_cmn_info { 134 atomic_t malloced; 135 atomic_t pktalloced; /* Number of allocated packet buffers */ 136 spinlock_t dbgmem_lock; 137 bcm_mem_link_t *dbgmem_list; 138 bcm_mem_link_t *dbgvmem_list; 139 #ifdef BCMDBG_PKT /* pkt logging for debugging */ 140 spinlock_t pktlist_lock; 141 pktlist_info_t pktlist; 142 #endif /* BCMDBG_PKT */ 143 spinlock_t pktalloc_lock; 144 atomic_t refcount; /* Number of references to this shared structure. */ 145 }; 146 typedef struct osl_cmn_info osl_cmn_t; 147 148 #if defined(AXI_TIMEOUTS_NIC) 149 typedef uint32 (*bpt_cb_fn)(void *ctx, void *addr); 150 #endif /* AXI_TIMEOUTS_NIC */ 151 152 struct osl_info { 153 osl_pubinfo_t pub; 154 uint32 flags; /* If specific cases to be handled in the OSL */ 155 uint magic; 156 void *pdev; 157 uint failed; 158 uint bustype; 159 osl_cmn_t *cmn; /* Common OSL related data shred between two OSH's */ 160 161 /* for host drivers, a bus handle is needed when reading from and/or writing to dongle 162 * registeres, however ai/si utilities only passes osh handle to R_REG and W_REG. as 163 * a work around, save the bus handle here 164 */ 165 void *bus_handle; 166 #ifdef BCMDBG_CTRACE 167 spinlock_t ctrace_lock; 168 struct list_head ctrace_list; 169 int ctrace_num; 170 #endif /* BCMDBG_CTRACE */ 171 #if defined(AXI_TIMEOUTS_NIC) 172 bpt_cb_fn bpt_cb; 173 void *sih; 174 #endif /* AXI_TIMEOUTS_NIC */ 175 #ifdef USE_DMA_LOCK 176 spinlock_t dma_lock; 177 bool dma_lock_bh; 178 #endif /* USE_DMA_LOCK */ 179 #ifdef DHD_MAP_LOGGING 180 void *dhd_map_log; 181 void *dhd_unmap_log; 182 #endif /* DHD_MAP_LOGGING */ 183 }; 184 185 #endif /* _LINUX_OSL_PRIV_H_ */ 186