| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2011, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bdma_pci_priv.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/3 $ |
|---|
| 12 | * $brcm_Date: 3/21/11 6:39p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/portinginterface/dma/7400/bdma_pci_priv.h $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/3 3/21/11 6:39p vanessah |
|---|
| 21 | * SW7420-1431: support oflarge DMA descriptor list subset |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/2 7/11/08 3:46p syang |
|---|
| 24 | * PR 43729: rm code for old crypto hw arch |
|---|
| 25 | * |
|---|
| 26 | * Hydra_Software_Devel/1 7/11/08 1:16p syang |
|---|
| 27 | * PR 43729: break from the old 7038 |
|---|
| 28 | * |
|---|
| 29 | * Hydra_Software_Devel/13 12/7/07 4:09p syang |
|---|
| 30 | * PR 34606: rewrite more than half of code to support hw sharing for |
|---|
| 31 | * kernel and user-mode sides |
|---|
| 32 | * |
|---|
| 33 | * Hydra_Software_Devel/12 10/15/07 3:42p syang |
|---|
| 34 | * PR 35947: add "_isr" to call back func name |
|---|
| 35 | * |
|---|
| 36 | * Hydra_Software_Devel/11 3/16/07 12:50p syang |
|---|
| 37 | * PR 28173: add dynamic link support (not turn on yet) |
|---|
| 38 | * |
|---|
| 39 | * Hydra_Software_Devel/9 2/5/07 4:43p syang |
|---|
| 40 | * PR 23354: allow mem addr in mem_1; cleanup cip specific code section |
|---|
| 41 | * macro usage |
|---|
| 42 | * |
|---|
| 43 | * Hydra_Software_Devel/8 10/3/06 4:01p syang |
|---|
| 44 | * PR 24634: replace critical section with private mutex for |
|---|
| 45 | * mem/pci_dma_handle create/destroy. |
|---|
| 46 | * |
|---|
| 47 | * Hydra_Software_Devel/7 2/4/04 3:01p syang |
|---|
| 48 | * PR 9608: 1). added init for hMemDma / hPciDma of Channel, hDma of |
|---|
| 49 | * MemDma / PciDma and hChannel of Queue; 2). split CallBackFunc type def |
|---|
| 50 | * to mem and pci versions; 3). fixed typo in TranHandle def; 4).leave |
|---|
| 51 | * critical section before calling BINT func; 5). fixed a bug with |
|---|
| 52 | * nextDesc in Desc info setting; 6). use wake to start dma as in sleep |
|---|
| 53 | * mode; 7). corrected typo in the asserts of Queue_CreateTran. |
|---|
| 54 | * |
|---|
| 55 | * Hydra_Software_Devel/6 10/24/03 2:53p syang |
|---|
| 56 | * changed to use PciBusAddr and MemBusAddr from SrcBusAddr and |
|---|
| 57 | * DstBusAddr. I think the new addr model is more natural to the way how |
|---|
| 58 | * user gets the addr |
|---|
| 59 | * |
|---|
| 60 | * Hydra_Software_Devel/5 10/23/03 6:18p syang |
|---|
| 61 | * to make linux comipler silent |
|---|
| 62 | * |
|---|
| 63 | * Hydra_Software_Devel/4 10/23/03 4:20p syang |
|---|
| 64 | * adjusted sub-module implementaion overview |
|---|
| 65 | * |
|---|
| 66 | * Hydra_Software_Devel/3 10/23/03 3:16p syang |
|---|
| 67 | * added real pci dma implementation |
|---|
| 68 | * |
|---|
| 69 | * Hydra_Software_Devel/2 10/10/03 4:05p syang |
|---|
| 70 | * updated BDMA_Pci_Context |
|---|
| 71 | * |
|---|
| 72 | * Hydra_Software_Devel/1 9/25/03 6:45p syang |
|---|
| 73 | * init version, from scratch |
|---|
| 74 | * |
|---|
| 75 | ***************************************************************************/ |
|---|
| 76 | #ifndef BDMA_PCI_PRIV_H__ |
|---|
| 77 | #define BDMA_PCI_PRIV_H__ |
|---|
| 78 | |
|---|
| 79 | #include "bdma_priv.h" |
|---|
| 80 | #include "bdma_queue.h" |
|---|
| 81 | |
|---|
| 82 | #ifdef __cplusplus |
|---|
| 83 | extern "C" { |
|---|
| 84 | #endif |
|---|
| 85 | |
|---|
| 86 | /*************************************************************************** |
|---|
| 87 | * {private} |
|---|
| 88 | |
|---|
| 89 | * Implementation Overview: |
|---|
| 90 | * |
|---|
| 91 | * The implementation uses a private queue module, to manage the active |
|---|
| 92 | * transfers. The queue module is shared by both memory DMA and PCI DMA. |
|---|
| 93 | * It manages the queue entry assigning, freeing, and the transfer status. |
|---|
| 94 | * Refer to queue module overview for more info. |
|---|
| 95 | * |
|---|
| 96 | * PCI DMA sub-module code should never refer to the member of queue |
|---|
| 97 | * module directly, however it needs to know the def of struct |
|---|
| 98 | * BDMA_P_QueueEntry. |
|---|
| 99 | * |
|---|
| 100 | * By abstracting out the queue module, the readabilty, maintainabilty, and |
|---|
| 101 | * extendabilty (such as to IO DMA) are much improved. Code size is also |
|---|
| 102 | * improved. |
|---|
| 103 | ****************************************************************************/ |
|---|
| 104 | |
|---|
| 105 | #define BDMA_P_PCI_GET_CONTEXT(handle, context) \ |
|---|
| 106 | BDMA_P_GENERIC_GET_CONTEXT((handle), (context), BDMA_P_Pci_Context) |
|---|
| 107 | |
|---|
| 108 | #define BDMA_P_PCI_SET_BLACK_MAGIC(handle) \ |
|---|
| 109 | BDMA_P_GENERIC_SET_BLACK_MAGIC((handle), BDMA_P_Pci_Context) |
|---|
| 110 | |
|---|
| 111 | #define BDMA_P_PCI_DESTROY_CONTEXT(struct_ptr) \ |
|---|
| 112 | BDMA_P_GENERIC_DESTROY_CONTEXT(struct_ptr, BDMA_P_Pci_Context) |
|---|
| 113 | |
|---|
| 114 | #define BDMA_P_PCI_NUM_WORDS_PER_DESC 4 |
|---|
| 115 | |
|---|
| 116 | #define BDMA_P_PCI_MAX_BLOCK_SIZE (0x1000000 -1) /* 16 MBytes */ |
|---|
| 117 | #define BDMA_P_PCI_ADDR_MASK (0xffffffff) |
|---|
| 118 | #define BDMA_P_PCI_LITTLE_ENDIAN 1 |
|---|
| 119 | |
|---|
| 120 | #define BDMA_P_PCI_END_IF_ERR(result, done_lable) \ |
|---|
| 121 | if ( BERR_SUCCESS != (result)) \ |
|---|
| 122 | {\ |
|---|
| 123 | goto done_lable; \ |
|---|
| 124 | }\ |
|---|
| 125 | |
|---|
| 126 | /*************************************************************************** |
|---|
| 127 | * Pci Tran Handle |
|---|
| 128 | */ |
|---|
| 129 | typedef struct BDMA_P_Pci_TranContext |
|---|
| 130 | { |
|---|
| 131 | BDMA_P_QueueEntry QueueEntry; |
|---|
| 132 | |
|---|
| 133 | } BDMA_P_Pci_TranContext; |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | /*************************************************************************** |
|---|
| 137 | * Pci Dma Context |
|---|
| 138 | */ |
|---|
| 139 | typedef struct BDMA_P_Pci_Context |
|---|
| 140 | { |
|---|
| 141 | uint32_t ulBlackMagic; /* Black magic for handle validation */ |
|---|
| 142 | |
|---|
| 143 | /* created from this handle */ |
|---|
| 144 | BDMA_Handle hDma; |
|---|
| 145 | |
|---|
| 146 | /* engine id */ |
|---|
| 147 | BDMA_PciDmaEngine eEngine; |
|---|
| 148 | |
|---|
| 149 | /* configures */ |
|---|
| 150 | BDMA_SwapMode eSwapMode; /* swap mode */ |
|---|
| 151 | BDMA_MaxBurstSize eMaxBurstSize; /* max burst size mode */ |
|---|
| 152 | |
|---|
| 153 | /* tran entry queue */ |
|---|
| 154 | BDMA_P_QueueHandle hQueue; |
|---|
| 155 | |
|---|
| 156 | /* interrupt call back handle */ |
|---|
| 157 | BINT_CallbackHandle hCallBack; |
|---|
| 158 | |
|---|
| 159 | } BDMA_P_Pci_Context; |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | /*************************************************************************** |
|---|
| 163 | * |
|---|
| 164 | * Utility functions used by BDMA |
|---|
| 165 | * |
|---|
| 166 | ***************************************************************************/ |
|---|
| 167 | /*-------------------------------------------------------------------------- |
|---|
| 168 | * To be called by BDMA API func before taking real action, to get dma mutex |
|---|
| 169 | * WITH block, ideally for user mode |
|---|
| 170 | */ |
|---|
| 171 | BERR_Code BDMA_P_Pci_AcquireMutex( |
|---|
| 172 | BDMA_Pci_Handle hPciDma, |
|---|
| 173 | BKNI_MutexHandle *phMutex ); |
|---|
| 174 | |
|---|
| 175 | /*************************************************************************** |
|---|
| 176 | * |
|---|
| 177 | */ |
|---|
| 178 | BERR_Code BDMA_P_Pci_Init( |
|---|
| 179 | BDMA_P_Pci_Context * pPciDma, |
|---|
| 180 | const BDMA_Pci_Settings *pSettings, |
|---|
| 181 | uint32_t ulL2IntrBintId ); |
|---|
| 182 | |
|---|
| 183 | /*************************************************************************** |
|---|
| 184 | * |
|---|
| 185 | */ |
|---|
| 186 | BERR_Code BDMA_P_Pci_UnInit( |
|---|
| 187 | BDMA_P_Pci_Context * pPciDma ); |
|---|
| 188 | |
|---|
| 189 | /*************************************************************************** |
|---|
| 190 | * |
|---|
| 191 | * API support functions |
|---|
| 192 | * |
|---|
| 193 | ***************************************************************************/ |
|---|
| 194 | |
|---|
| 195 | /*************************************************************************** |
|---|
| 196 | * |
|---|
| 197 | */ |
|---|
| 198 | BERR_Code BDMA_P_Pci_Create( |
|---|
| 199 | BDMA_Handle hDma, |
|---|
| 200 | BDMA_PciDmaEngine eEngine, |
|---|
| 201 | const BDMA_Pci_Settings *pSettings, |
|---|
| 202 | BDMA_Pci_Handle * phPciDma ); |
|---|
| 203 | |
|---|
| 204 | /*************************************************************************** |
|---|
| 205 | * |
|---|
| 206 | */ |
|---|
| 207 | BERR_Code BDMA_P_Pci_Destroy( |
|---|
| 208 | BDMA_Pci_Handle hPciDma ); |
|---|
| 209 | |
|---|
| 210 | /*************************************************************************** |
|---|
| 211 | * |
|---|
| 212 | */ |
|---|
| 213 | BERR_Code BDMA_P_Pci_SetSwapMode_isr( |
|---|
| 214 | BDMA_Pci_Handle hPciDma, |
|---|
| 215 | BDMA_SwapMode eSwapMode ); |
|---|
| 216 | |
|---|
| 217 | /*************************************************************************** |
|---|
| 218 | * |
|---|
| 219 | */ |
|---|
| 220 | BERR_Code BDMA_P_Pci_SetMaxBurstSize_isr( |
|---|
| 221 | BDMA_Pci_Handle hPciDma, |
|---|
| 222 | BDMA_MaxBurstSize eMaxBurstSize ); |
|---|
| 223 | |
|---|
| 224 | /*************************************************************************** |
|---|
| 225 | * |
|---|
| 226 | */ |
|---|
| 227 | BERR_Code BDMA_P_Pci_Tran_Create_isr( |
|---|
| 228 | BDMA_Pci_Handle hPciDma, |
|---|
| 229 | uint32_t ulNumBlocks, |
|---|
| 230 | bool bCachedDesc, |
|---|
| 231 | BDMA_Pci_Tran_Handle * phTran ); |
|---|
| 232 | |
|---|
| 233 | /*************************************************************************** |
|---|
| 234 | * To be called to set the block info for a Tran block. Input para are |
|---|
| 235 | * validated. |
|---|
| 236 | */ |
|---|
| 237 | BERR_Code BDMA_P_Pci_Tran_SetBlockInfo_isr( |
|---|
| 238 | BDMA_Pci_Tran_Handle hTran, |
|---|
| 239 | uint32_t ulBlockId, |
|---|
| 240 | uint32_t ulMemBusAddr, |
|---|
| 241 | uint32_t ulPciBusAddr, |
|---|
| 242 | uint32_t ulBlockSize, |
|---|
| 243 | BDMA_TranDir eTranDirection ); |
|---|
| 244 | |
|---|
| 245 | /*************************************************************************** |
|---|
| 246 | * To be called by both BDMA_P_Pci_Tran_Start and |
|---|
| 247 | * BDMA_P_Pci_Tran_StartAndCallBack, BDMA_P_Pci_Tran_Start should pass NULL |
|---|
| 248 | * for pCallBackFunc_isr and pUserCallBackParam |
|---|
| 249 | */ |
|---|
| 250 | BERR_Code BDMA_P_Pci_Tran_Start_isr( |
|---|
| 251 | BDMA_Pci_Tran_Handle hTran, |
|---|
| 252 | uint32_t ulNumActBlocks, |
|---|
| 253 | BDMA_Pci_CallbackFunc pCallBackFunc_isr, |
|---|
| 254 | void * pUserCallBackParam ); |
|---|
| 255 | |
|---|
| 256 | /*************************************************************************** |
|---|
| 257 | * To be called by both BDMA_Pci_Tran_StartDmaSubset and |
|---|
| 258 | * BDMA_Pci_Tran_StartDmaSubsetAndCallBack. |
|---|
| 259 | */ |
|---|
| 260 | |
|---|
| 261 | BERR_Code BDMA_P_Pci_Tran_StartSubset_isr( |
|---|
| 262 | BDMA_Mem_Tran_Handle hTran, |
|---|
| 263 | uint32_t ulFirstBlock, |
|---|
| 264 | uint32_t ulNumActBlocks, |
|---|
| 265 | BDMA_Mem_CallbackFunc pCallBackFunc_isr, |
|---|
| 266 | void * pUserCallBackParam ); |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | /*************************************************************************** |
|---|
| 270 | * To be called by BDMA_Pci_Tran_GetStatus. |
|---|
| 271 | */ |
|---|
| 272 | BERR_Code BDMA_P_Pci_Tran_GetStatus_isr( |
|---|
| 273 | BDMA_Pci_Tran_Handle hTran, |
|---|
| 274 | BDMA_TranStatus * peTranStatus ); |
|---|
| 275 | |
|---|
| 276 | /*************************************************************************** |
|---|
| 277 | * To be called by BDMA_Pci_Tran_Destroy. It free the queue entries occupied |
|---|
| 278 | * this Tran |
|---|
| 279 | */ |
|---|
| 280 | BERR_Code BDMA_P_Pci_Tran_Destroy_isr( |
|---|
| 281 | BDMA_Pci_Tran_Handle hTran ); |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | /*************************************************************************** |
|---|
| 285 | * To be called by BDMA_Pci_Tran_Reset. It resets the Tran into its |
|---|
| 286 | * initially created state |
|---|
| 287 | */ |
|---|
| 288 | BERR_Code BDMA_P_Pci_Tran_Reset_isr( |
|---|
| 289 | BDMA_Pci_Tran_Handle hTran ); |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | #ifdef __cplusplus |
|---|
| 293 | } |
|---|
| 294 | #endif |
|---|
| 295 | |
|---|
| 296 | #endif /* #ifndef BDMA_PCI_PRIV_H__ */ |
|---|
| 297 | |
|---|
| 298 | /* end of file */ |
|---|