⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htc_internal.h

📁 Linux下SDIO设备的驱动程序
💻 H
字号:
/* * Copyright (c) 2004-2005 Atheros Communications Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. The name of the author may not be used to endorse or promote products *    derived from this software withough specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * HTC internal specific declarations and prototypes */#ifndef _HTC_INTERNAL_H_#define _HTC_INTERNAL_H_#ifdef __cplusplusextern "C" {#endif /* __cplusplus *//* Header files */#include "../include/athdefs.h"#include "../include/athtypes.h"#include "../include/hw/mbox_host_reg.h"#include "../include/hw/rtc_reg.h"#include "../include/htc.h"#include "../include/AR6000_bmi.h"#include "../include/osapi.h"#include "../include/hif.h"/* HTC operational parameters */#define HTC_GLOBAL_EVENT_NUM_MAX           2 /* Target available/unavailable */#define HTC_ENDPOINT_EVENT_NUM_MAX         5 /* Endpoint specific */#define HTC_REG_REQUEST_LIST_SIZE          16#define HTC_MESSAGE_SIZE_MAX               1536 - HTC_HEADER_LEN /* Default maximum message size for each mailbox */#define HTC_TX_CREDITS_NUM_MAX             64#define HTC_TARGET_RESPONSE_TIMEOUT        2000 /* in ms *//* Useful macros */#define GET_ENDPOINT_ID(endPoint) (endPoint - endPoint->target->endPoint)/* ------- Debug related stuff ------- */enum {    ATH_DEBUG_SEND = 0x0001,    ATH_DEBUG_RECV = 0x0002,    ATH_DEBUG_SYNC = 0x0004,    ATH_DEBUG_DUMP = 0x0008,    ATH_DEBUG_INF  = 0x0010,    ATH_DEBUG_TRC  = 0x0020,    ATH_DEBUG_WARN = 0x0040,    ATH_DEBUG_ERR  = 0x0080,    ATH_DEBUG_ANY  = 0xFFFF,};#ifdef DEBUG#define AR_DEBUG_PRINTBUF(buffer, length) do {   \    if (debughtc & ATH_DEBUG_DUMP) {             \        dumpBytes(buffer, length);               \    }                                            \} while(0)#define PRINTX_ARG(arg...) arg#define AR_DEBUG_PRINTF(flags, args) do {        \    if (debughtc & (flags)) {                    \        A_PRINTF(KERN_ALERT PRINTX_ARG args);      \    }                                            \} while (0)#define AR_DEBUG_ASSERT(test) do {               \    if (!(test)) {                               \        AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Debug Assert Caught, File %s, Line: %d, Test:%s \n",__FILE__, __LINE__,#test));         \    }                                            \} while(0)#else#define AR_DEBUG_PRINTF(flags, args)#define AR_DEBUG_PRINTBUF(buffer, length)#define AR_DEBUG_ASSERT(test)#endif/* ------- Event Related Data Structures ------- */typedef struct htc_event_map HTC_EVENT_MAP;typedef struct event_table_element EVENT_TABLE_ELEMENT;typedef struct htc_endpoint_event_table HTC_ENDPOINT_EVENT_TABLE;typedef struct htc_global_event_table HTC_GLOBAL_EVENT_TABLE;#define FRAME_EVENT(_eventInfo, _buffer, _bufferLength,   \                    _actualLength, _status, _cookie) do { \    _eventInfo.buffer  = _buffer;                         \    _eventInfo.bufferLength = _bufferLength;              \    _eventInfo.actualLength = _actualLength;              \    _eventInfo.status = _status;                          \    _eventInfo.cookie = _cookie;                          \} while (0)struct event_table_element {    HTC_EVENT_ID         id;    HTC_EVENT_HANDLER    handler;    void                *param;};struct htc_endpoint_event_table {    EVENT_TABLE_ELEMENT element[HTC_ENDPOINT_EVENT_NUM_MAX];};struct htc_global_event_table {    EVENT_TABLE_ELEMENT element[HTC_GLOBAL_EVENT_NUM_MAX];};/* ------ Mailbox Related Data Structures ------ */typedef struct htc_queue_element HTC_QUEUE_ELEMENT, HTC_REG_REQUEST_ELEMENT, HTC_DATA_REQUEST_ELEMENT;typedef struct htc_mbox_buffer HTC_MBOX_BUFFER;typedef struct htc_reg_buffer HTC_REG_BUFFER;typedef struct htc_data_request_queue HTC_DATA_REQUEST_QUEUE;typedef struct htc_reg_request_list HTC_REG_REQUEST_LIST;typedef struct htc_endpoint HTC_ENDPOINT;typedef enum {    INT_STATUS_REG,    ERROR_INT_STATUS_REG,    CPU_INT_STATUS_REG,    RX_LOOKAHEAD_VALID_REG,    RX_LOOKAHEAD0_REG,    RX_LOOKAHEAD1_REG,    RX_LOOKAHEAD2_REG,    RX_LOOKAHEAD3_REG,    TX_CREDIT_COUNTER_REG,    TX_CREDIT_COUNTER_RESET_REG,    TX_CREDIT_COUNTER_DECREMENT_REG,    SCRATCH_REG,    INT_STATUS_ENABLE_REG,    CPU_INT_STATUS_ENABLE_REG,    ERROR_STATUS_ENABLE_REG,    COUNTER_INT_STATUS_READ_REG,    COUNTER_INT_STATUS_ENABLE_REG,    COUNTER_INT_STATUS_DISABLE_REG,    INT_WLAN_REG,    WINDOW_DATA_REG,    WINDOW_WRITE_ADDR_REG,    WINDOW_READ_ADDR_REG} TARGET_REGISTERS;#define SET_TX_CREDITS_AVAILABLE(endPoint, credits) \                                    endPoint->txCreditsAvailable[0] = (credits)#define SET_TX_CREDITS_CONSUMED(endPoint, credits) \                                    endPoint->txCreditsConsumed = (credits)#define GET_TX_CREDITS_AVAILABLE(endPoint) \                                    endPoint->txCreditsAvailable[0]#define GET_TX_CREDITS_CONSUMED(endPoint) \                                    endPoint->txCreditsConsumed#define IS_ELEMENT_FREE(element)	element->buffer.free#define GET_MBOX_BUFFER(element)	&((element)->buffer.u.mboxBuffer)#define GET_REG_BUFFER(element)		&((element)->buffer.u.regBuffer)#define GET_QUEUE_TAIL(queue)		&queue->element[(queue->head + queue->size) % HTC_DATA_REQUEST_RING_BUFFER_SIZE]#define GET_QUEUE_HEAD(queue)		&queue->element[queue->head]#define IS_DATA_QUEUE_EMPTY(queue)      (!queue->size)#define IS_DATA_QUEUE_FULL(queue)       (!(HTC_DATA_REQUEST_RING_BUFFER_SIZE - queue->size))#define RECYCLE_DATA_REQUEST_ELEMENT(element) do { \    FILL_MBOX_BUFFER(element, NULL, 0, 0, NULL); \    (element)->buffer.free = TRUE; \} while (0)#define FILL_MBOX_BUFFER(element, _buffer, _bufferLength, _actualLength, _cookie) do { \    (GET_MBOX_BUFFER(element))->buffer = _buffer; \    (GET_MBOX_BUFFER(element))->bufferLength = _bufferLength; \    (GET_MBOX_BUFFER(element))->actualLength = _actualLength; \    (GET_MBOX_BUFFER(element))->cookie = _cookie; \} while (0)#define FILL_REG_BUFFER(element, _buffer, _length, _base, _offset) do { \    (GET_REG_BUFFER(element))->buffer = _buffer; \    (GET_REG_BUFFER(element))->length = _length; \    (GET_REG_BUFFER(element))->base = _base; \    (GET_REG_BUFFER(element))->offset = _offset; \} while (0)struct htc_queue_element {    A_STATUS	(*completionCB)(HTC_QUEUE_ELEMENT *element, A_STATUS status);    struct htc_buffer {        /* In use or available */        A_BOOL	free;        union {            struct htc_mbox_buffer {                /*                 * Given by the caller and is associated with the buffer being                 * queued up.                 */                void			*cookie;                /*                 * Pointer to the start of the buffer. In the transmit                 * direction this points to the start of the payload. In the                 * receive direction, however, the buffer when queued up                 * points to the start of the HTC header but when returned                 * to the caller points to the start of the payload                 */                A_UCHAR			*buffer;                /* Holds the length of the buffer */                A_UINT32		bufferLength;                /* Holds the length of the payload */                A_UINT32		actualLength;                HTC_ENDPOINT    *endPoint;            } mboxBuffer;            struct htc_reg_buffer {                HTC_TARGET		*target;                A_UCHAR			*buffer;                A_UINT32		length;                TARGET_REGISTERS	base;                A_UINT32		offset;            } regBuffer;        } u;    } buffer;};/* This is a FIFO queue of the pending data read/write requests. When a requesthas to be issued, the element at the head of the queue is dequeued andprocessed. New requests are added at the tail of the queue. The queue can onlysupport a fixed number of requests and stops adding new requests once the totalnumber of requests that are pending to be processed and the ones that are stillunder process reach the queue capacity */struct htc_data_request_queue {    A_UINT32                  head;    A_UINT32                  size;    HTC_DATA_REQUEST_ELEMENT  element[HTC_DATA_REQUEST_RING_BUFFER_SIZE];};/* This is a list of 'free' register read/write requests. When a request has tobe issued an element is taken from this list and after the completion of therequest is added back to the list */struct htc_reg_request_list {    HTC_REG_REQUEST_ELEMENT  element[HTC_REG_REQUEST_LIST_SIZE];};struct htc_endpoint {    /* Enabled or Disabled */    A_BOOL                   enabled;    /*     * Used to hold the length of the frame received from the target in     * case there are no buffers that have been queued up to receive the     * data.     */    A_UINT32                 rxLengthPending;    /* Number of frames for which the target has space for at any time */    A_UINT8                  txCreditsAvailable[1 + HTC_TX_CREDITS_NUM_MAX];    /*     * Number of frames that have been sent since the transmit credits     * were last updated.     */    A_UINT8                  txCreditsConsumed;    A_BOOL                   txCreditsIntrEnable;    /* Pending Send Queue */    HTC_DATA_REQUEST_QUEUE   sendQueue;    /* Pending Receive Queue */    HTC_DATA_REQUEST_QUEUE   recvQueue;    /* Inverse reference to the target */    HTC_TARGET              *target;    /* Block size configured for the endpoint */    A_UINT32                 blockSize;    /* Event Table */    HTC_ENDPOINT_EVENT_TABLE eventTable;    /* Stating address of the endpoint */    A_UINT32                 address;};/* ------- Target Related Data structures ------- */typedef struct htc_register_table HTC_REGISTER_TABLE;/* * The following Register table only contain those registers that are used * in HTC. It does not reflect the actual register layout in the hardware */struct htc_register_table {    A_UINT8                      host_int_status;    A_UINT8                      cpu_int_status;    A_UINT8                      error_int_status;    A_UINT8                      counter_int_status;    A_UINT8                      mbox_frame;    A_UINT8                      rx_lookahead_valid;    A_UINT8                      hole[2];    A_UINT32                     rx_lookahead[HTC_MAILBOX_NUM_MAX];    A_UINT8                      int_status_enable;    A_UINT8                      cpu_int_status_enable;    A_UINT8                      error_status_enable;    A_UINT8                      counter_int_status_enable;    A_UINT8                      int_wlan;};struct htc_target {    A_BOOL                       ready;    void                        *device; /* Handle to the device instance                                            reported by the bus driver */    HTC_ENDPOINT                 endPoint[HTC_MAILBOX_NUM_MAX];    HTC_REGISTER_TABLE           table;    HTC_REG_REQUEST_LIST         regList;};/* ------- Function Prototypes for Receive -------- */voidhtcReceiveFrame(HTC_ENDPOINT *endPoint);A_UINT32htcGetFrameLength(HTC_ENDPOINT *endPoint);/* ------- Function Prototypes for Transmit -------- */voidhtcSendFrame(HTC_ENDPOINT *endPoint);voidhtcSendBlkSize(HTC_ENDPOINT *endPoint);/* ------- Function Prototypes for Events and Callbacks  ------- */A_STATUShtcRWCompletionHandler(void *element,                       A_STATUS status);A_STATUShtcTxCompletionCB(HTC_DATA_REQUEST_ELEMENT *element,                  A_STATUS status);A_STATUShtcBlkSzNegCompletionCB(HTC_DATA_REQUEST_ELEMENT *element,                        A_STATUS status);A_STATUShtcRxCompletionCB(HTC_DATA_REQUEST_ELEMENT *element,                  A_STATUS status);A_STATUShtcRegCompletionCB(HTC_REG_REQUEST_ELEMENT *element,                   A_STATUS status);A_STATUShtcTargetInsertedHandler(HIF_DEVICE *device);A_STATUShtcTargetRemovedHandler(HIF_DEVICE *device);A_STATUShtcDSRHandler(HIF_DEVICE *device);#ifdef CFA_STATUShtcInterruptDisabler(HIF_DEVICE *device,A_BOOL *callDsr);A_STATUShtcInterruptEnabler(HIF_DEVICE *device);#endif /* CF */voidhtcServiceCPUInterrupt(HTC_TARGET *target);voidhtcServiceErrorInterrupt(HTC_TARGET *target);voidhtcServiceCounterInterrupt(HTC_TARGET *target);voidhtcServiceMailboxInterrupt(HTC_TARGET *target);voidhtcEnableCreditCounterInterrupt(HTC_TARGET *target,                                HTC_ENDPOINT_ID endPointId);voidhtcDisableCreditCounterInterrupt(HTC_TARGET *target,                                 HTC_ENDPOINT_ID endPointId);/* ------- Function Prototypes for Utility routines ------- */A_STATUSaddToMboxQueue(HTC_DATA_REQUEST_QUEUE *queue,               A_UCHAR        *buffer,               A_UINT32        bufferLength,               A_UINT32        actualLength,               void           *cookie);HTC_DATA_REQUEST_ELEMENT *removeFromMboxQueue(HTC_DATA_REQUEST_QUEUE *queue);voidflushMboxQueue(HTC_ENDPOINT *endPoint,               HTC_DATA_REQUEST_QUEUE *queue,               HTC_EVENT_ID eventId);HTC_REG_REQUEST_ELEMENT *allocateRegRequestElement(HTC_TARGET *target);voidfreeRegRequestElement(HTC_REG_REQUEST_ELEMENT *element);A_STATUSaddToEventTable(HTC_TARGET       *target,                HTC_ENDPOINT_ID   endPointId,                HTC_EVENT_ID      eventId,                HTC_EVENT_HANDLER handler,                void             *param);A_STATUSremoveFromEventTable(HTC_TARGET *target,                     HTC_ENDPOINT_ID endPointId,                     HTC_EVENT_ID  eventId);voiddispatchEvent(HTC_TARGET     *target,              HTC_ENDPOINT_ID endPointId,              HTC_EVENT_ID    eventId,              HTC_EVENT_INFO *eventInfo);HTC_TARGET *getTargetInstance(void *device);voidaddTargetInstance(HTC_TARGET *target);voiddelTargetInstance(HTC_TARGET *target);A_UINT32getRegAddr(TARGET_REGISTERS base,           HTC_ENDPOINT_ID endPointId);A_UINT8htcGetBitNumSet(A_UINT32 data);voiddumpBytes(A_UCHAR *buffer, A_UINT16 length);voiddumpRegisters(HTC_TARGET *target);#ifdef __cplusplus}#endif#endif /* _HTC_INTERNAL_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -