1*2ffc1057SHemant Agrawal /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) 2*2ffc1057SHemant Agrawal * Copyright 2008-2012 Freescale Semiconductor Inc. 3*2ffc1057SHemant Agrawal * Copyright 2017-2020 NXP 4*2ffc1057SHemant Agrawal */ 5*2ffc1057SHemant Agrawal 6*2ffc1057SHemant Agrawal #ifndef __NCSW_EXT_H 7*2ffc1057SHemant Agrawal #define __NCSW_EXT_H 8*2ffc1057SHemant Agrawal 9*2ffc1057SHemant Agrawal #include <stdint.h> 10*2ffc1057SHemant Agrawal 11*2ffc1057SHemant Agrawal #define PTR_TO_UINT(_ptr) ((uintptr_t)(_ptr)) 12*2ffc1057SHemant Agrawal #define UINT_TO_PTR(_val) ((void *)(uintptr_t)(_val)) 13*2ffc1057SHemant Agrawal 14*2ffc1057SHemant Agrawal /* phys_address_t should be uintptr_t */ 15*2ffc1057SHemant Agrawal typedef uint64_t phys_address_t; 16*2ffc1057SHemant Agrawal 17*2ffc1057SHemant Agrawal /* 18*2ffc1057SHemant Agrawal * @Description Possible RxStore callback responses. 19*2ffc1057SHemant Agrawal */ 20*2ffc1057SHemant Agrawal typedef enum e_rx_store_response { 21*2ffc1057SHemant Agrawal e_RX_STORE_RESPONSE_PAUSE 22*2ffc1057SHemant Agrawal /**< Pause invoking callback with received data; in polling 23*2ffc1057SHemant Agrawal * mode, start again invoking callback only next time user 24*2ffc1057SHemant Agrawal * invokes the receive routine; in interrupt mode, start again 25*2ffc1057SHemant Agrawal * invoking callback only next time a receive event triggers an 26*2ffc1057SHemant Agrawal * interrupt; in all cases, received data that are pending are 27*2ffc1057SHemant Agrawal * not lost, rather, their processing is temporarily deferred; 28*2ffc1057SHemant Agrawal * in all cases, received data are processed in the order in 29*2ffc1057SHemant Agrawal * which they were received. 30*2ffc1057SHemant Agrawal */ 31*2ffc1057SHemant Agrawal , e_RX_STORE_RESPONSE_CONTINUE 32*2ffc1057SHemant Agrawal /**< Continue invoking callback with received data. */ 33*2ffc1057SHemant Agrawal } e_rx_store_response; 34*2ffc1057SHemant Agrawal 35*2ffc1057SHemant Agrawal 36*2ffc1057SHemant Agrawal /* 37*2ffc1057SHemant Agrawal * @Description General Handle 38*2ffc1057SHemant Agrawal */ 39*2ffc1057SHemant Agrawal typedef void *t_handle; /**< handle, used as object's descriptor */ 40*2ffc1057SHemant Agrawal 41*2ffc1057SHemant Agrawal /* @} */ 42*2ffc1057SHemant Agrawal 43*2ffc1057SHemant Agrawal /* 44*2ffc1057SHemant Agrawal * @Function t_get_buf_function 45*2ffc1057SHemant Agrawal * 46*2ffc1057SHemant Agrawal * @Description User callback function called by driver to get data buffer. 47*2ffc1057SHemant Agrawal * 48*2ffc1057SHemant Agrawal * User provides this function. Driver invokes it. 49*2ffc1057SHemant Agrawal * 50*2ffc1057SHemant Agrawal * @Param[in] h_buffer_pool A handle to buffer pool manager 51*2ffc1057SHemant Agrawal * @Param[out] p_buf_context_handle Returns the user's private context that 52*2ffc1057SHemant Agrawal * should be associated with the buffer 53*2ffc1057SHemant Agrawal * 54*2ffc1057SHemant Agrawal * @Return Pointer to data buffer, NULL if error 55*2ffc1057SHemant Agrawal */ 56*2ffc1057SHemant Agrawal typedef uint8_t * (t_get_buf_function)(t_handle h_buffer_pool, 57*2ffc1057SHemant Agrawal t_handle *p_buf_context_handle); 58*2ffc1057SHemant Agrawal 59*2ffc1057SHemant Agrawal /* 60*2ffc1057SHemant Agrawal * @Function t_put_buf_function 61*2ffc1057SHemant Agrawal * 62*2ffc1057SHemant Agrawal * @Description User callback function called by driver to return data buffer. 63*2ffc1057SHemant Agrawal * User provides this function. Driver invokes it. 64*2ffc1057SHemant Agrawal * 65*2ffc1057SHemant Agrawal * @Param[in] h_buffer_pool A handle to buffer pool manager 66*2ffc1057SHemant Agrawal * @Param[in] p_buffer A pointer to buffer to return 67*2ffc1057SHemant Agrawal * @Param[in] h_buf_context The user's private context associated 68*2ffc1057SHemant Agrawal * with the returned buffer 69*2ffc1057SHemant Agrawal * 70*2ffc1057SHemant Agrawal * @Return E_OK on success; Error code otherwise 71*2ffc1057SHemant Agrawal */ 72*2ffc1057SHemant Agrawal typedef uint32_t (t_put_buf_function)(t_handle h_buffer_pool, 73*2ffc1057SHemant Agrawal uint8_t *p_buffer, 74*2ffc1057SHemant Agrawal t_handle h_buf_context); 75*2ffc1057SHemant Agrawal 76*2ffc1057SHemant Agrawal /* 77*2ffc1057SHemant Agrawal * @Function t_phys_to_virt 78*2ffc1057SHemant Agrawal * 79*2ffc1057SHemant Agrawal * @Description Translates a physical address to the matching virtual address. 80*2ffc1057SHemant Agrawal * 81*2ffc1057SHemant Agrawal * @Param[in] addr The physical address to translate. 82*2ffc1057SHemant Agrawal * 83*2ffc1057SHemant Agrawal * @Return Virtual address. 84*2ffc1057SHemant Agrawal */ 85*2ffc1057SHemant Agrawal typedef void *t_phys_to_virt(phys_address_t addr); 86*2ffc1057SHemant Agrawal 87*2ffc1057SHemant Agrawal /* 88*2ffc1057SHemant Agrawal * @Function t_virt_to_phys 89*2ffc1057SHemant Agrawal * 90*2ffc1057SHemant Agrawal * @Description Translates a virtual address to the matching physical address. 91*2ffc1057SHemant Agrawal * 92*2ffc1057SHemant Agrawal * @Param[in] addr The virtual address to translate. 93*2ffc1057SHemant Agrawal * 94*2ffc1057SHemant Agrawal * @Return Physical address. 95*2ffc1057SHemant Agrawal */ 96*2ffc1057SHemant Agrawal typedef phys_address_t t_virt_to_phys(void *addr); 97*2ffc1057SHemant Agrawal 98*2ffc1057SHemant Agrawal /* 99*2ffc1057SHemant Agrawal * @Description Buffer Pool Information Structure. 100*2ffc1057SHemant Agrawal */ 101*2ffc1057SHemant Agrawal typedef struct t_buffer_pool_info { 102*2ffc1057SHemant Agrawal t_handle h_buffer_pool; 103*2ffc1057SHemant Agrawal /**< A handle to the buffer pool mgr */ 104*2ffc1057SHemant Agrawal t_get_buf_function *f_get_buf; 105*2ffc1057SHemant Agrawal /**< User callback to get a free buffer */ 106*2ffc1057SHemant Agrawal t_put_buf_function *f_put_buf; 107*2ffc1057SHemant Agrawal /**< User callback to return a buffer */ 108*2ffc1057SHemant Agrawal uint16_t buffer_size; 109*2ffc1057SHemant Agrawal /**< Buffer size (in bytes) */ 110*2ffc1057SHemant Agrawal t_phys_to_virt *f_phys_to_virt; 111*2ffc1057SHemant Agrawal /**< User callback to translate pool buffers physical addresses 112*2ffc1057SHemant Agrawal * to virtual addresses 113*2ffc1057SHemant Agrawal */ 114*2ffc1057SHemant Agrawal t_virt_to_phys *f_virt_to_phys; 115*2ffc1057SHemant Agrawal /**< User callback to translate pool buffers virtual addresses 116*2ffc1057SHemant Agrawal * to physical addresses 117*2ffc1057SHemant Agrawal */ 118*2ffc1057SHemant Agrawal } t_buffer_pool_info; 119*2ffc1057SHemant Agrawal 120*2ffc1057SHemant Agrawal /* 121*2ffc1057SHemant Agrawal * @Description User callback function called by driver with receive data. 122*2ffc1057SHemant Agrawal * User provides this function. Driver invokes it. 123*2ffc1057SHemant Agrawal * 124*2ffc1057SHemant Agrawal * @Param[in] h_app Application's handle, as was provided to the 125*2ffc1057SHemant Agrawal * driver by the user 126*2ffc1057SHemant Agrawal * @Param[in] queue_id Receive queue ID 127*2ffc1057SHemant Agrawal * @Param[in] p_data Pointer to the buffer with received data 128*2ffc1057SHemant Agrawal * @Param[in] h_buf_context The user's private context associated with the 129*2ffc1057SHemant Agrawal * given data buffer 130*2ffc1057SHemant Agrawal * @Param[in] length Length of received data 131*2ffc1057SHemant Agrawal * @Param[in] status Receive status and errors 132*2ffc1057SHemant Agrawal * @Param[in] position Position of buffer in frame 133*2ffc1057SHemant Agrawal * @Param[in] flags Driver-dependent information 134*2ffc1057SHemant Agrawal * 135*2ffc1057SHemant Agrawal * @Retval e_RX_STORE_RESPONSE_CONTINUE order the driver to continue Rx 136*2ffc1057SHemant Agrawal * operation for all ready data. 137*2ffc1057SHemant Agrawal * @Retval e_RX_STORE_RESPONSE_PAUSE order the driver to stop Rx ops. 138*2ffc1057SHemant Agrawal */ 139*2ffc1057SHemant Agrawal typedef e_rx_store_response(t_rx_store_function)(t_handle h_app, 140*2ffc1057SHemant Agrawal uint32_t queue_id, 141*2ffc1057SHemant Agrawal uint8_t *p_data, 142*2ffc1057SHemant Agrawal t_handle h_buf_context, 143*2ffc1057SHemant Agrawal uint32_t length, 144*2ffc1057SHemant Agrawal uint16_t status, 145*2ffc1057SHemant Agrawal uint8_t position, 146*2ffc1057SHemant Agrawal uint32_t flags); 147*2ffc1057SHemant Agrawal 148*2ffc1057SHemant Agrawal typedef struct t_device { 149*2ffc1057SHemant Agrawal uintptr_t id; /**< the device id */ 150*2ffc1057SHemant Agrawal int fd; /**< the device file descriptor */ 151*2ffc1057SHemant Agrawal t_handle h_user_priv; 152*2ffc1057SHemant Agrawal uint32_t owners; 153*2ffc1057SHemant Agrawal } t_device; 154*2ffc1057SHemant Agrawal 155*2ffc1057SHemant Agrawal t_handle create_device(t_handle h_user_priv, t_handle h_dev_id); 156*2ffc1057SHemant Agrawal t_handle get_device_id(t_handle h_dev); 157*2ffc1057SHemant Agrawal 158*2ffc1057SHemant Agrawal #endif /* __NCSW_EXT_H */ 159