Path: blob/main/sys/contrib/dev/athk/ath10k/sdio.h
48378 views
/* SPDX-License-Identifier: ISC */1/*2* Copyright (c) 2004-2011 Atheros Communications Inc.3* Copyright (c) 2011-2012 Qualcomm Atheros, Inc.4* Copyright (c) 2016-2017 Erik Stromdahl <[email protected]>5*/67#ifndef _SDIO_H_8#define _SDIO_H_910#define ATH10K_HIF_MBOX_BLOCK_SIZE 2561112#define ATH10K_SDIO_MAX_BUFFER_SIZE 4096 /*Unsure of this constant*/1314/* Mailbox address in SDIO address space */15#define ATH10K_HIF_MBOX_BASE_ADDR 0x100016#define ATH10K_HIF_MBOX_WIDTH 0x8001718#define ATH10K_HIF_MBOX_TOT_WIDTH \19(ATH10K_HIF_MBOX_NUM_MAX * ATH10K_HIF_MBOX_WIDTH)2021#define ATH10K_HIF_MBOX0_EXT_BASE_ADDR 0x500022#define ATH10K_HIF_MBOX0_EXT_WIDTH (36 * 1024)23#define ATH10K_HIF_MBOX0_EXT_WIDTH_ROME_2_0 (56 * 1024)24#define ATH10K_HIF_MBOX1_EXT_WIDTH (36 * 1024)25#define ATH10K_HIF_MBOX_DUMMY_SPACE_SIZE (2 * 1024)2627#define ATH10K_HTC_MBOX_MAX_PAYLOAD_LENGTH \28(ATH10K_SDIO_MAX_BUFFER_SIZE - sizeof(struct ath10k_htc_hdr))2930#define ATH10K_HIF_MBOX_NUM_MAX 431#define ATH10K_SDIO_BUS_REQUEST_MAX_NUM 10243233#define ATH10K_SDIO_HIF_COMMUNICATION_TIMEOUT_HZ (100 * HZ)3435/* HTC runs over mailbox 0 */36#define ATH10K_HTC_MAILBOX 037#define ATH10K_HTC_MAILBOX_MASK BIT(ATH10K_HTC_MAILBOX)3839/* GMBOX addresses */40#define ATH10K_HIF_GMBOX_BASE_ADDR 0x700041#define ATH10K_HIF_GMBOX_WIDTH 0x40004243/* Modified versions of the sdio.h macros.44* The macros in sdio.h can't be used easily with the FIELD_{PREP|GET}45* macros in bitfield.h, so we define our own macros here.46*/47#define ATH10K_SDIO_DRIVE_DTSX_MASK \48(SDIO_DRIVE_DTSx_MASK << SDIO_DRIVE_DTSx_SHIFT)4950#define ATH10K_SDIO_DRIVE_DTSX_TYPE_B 051#define ATH10K_SDIO_DRIVE_DTSX_TYPE_A 152#define ATH10K_SDIO_DRIVE_DTSX_TYPE_C 253#define ATH10K_SDIO_DRIVE_DTSX_TYPE_D 35455/* SDIO CCCR register definitions */56#define CCCR_SDIO_IRQ_MODE_REG 0xF057#define CCCR_SDIO_IRQ_MODE_REG_SDIO3 0x165859#define CCCR_SDIO_DRIVER_STRENGTH_ENABLE_ADDR 0xF26061#define CCCR_SDIO_DRIVER_STRENGTH_ENABLE_A 0x0262#define CCCR_SDIO_DRIVER_STRENGTH_ENABLE_C 0x0463#define CCCR_SDIO_DRIVER_STRENGTH_ENABLE_D 0x086465#define CCCR_SDIO_ASYNC_INT_DELAY_ADDRESS 0xF066#define CCCR_SDIO_ASYNC_INT_DELAY_MASK 0xC06768/* mode to enable special 4-bit interrupt assertion without clock */69#define SDIO_IRQ_MODE_ASYNC_4BIT_IRQ BIT(0)70#define SDIO_IRQ_MODE_ASYNC_4BIT_IRQ_SDIO3 BIT(1)7172#define ATH10K_SDIO_TARGET_DEBUG_INTR_MASK 0x017374/* The theoretical maximum number of RX messages that can be fetched75* from the mbox interrupt handler in one loop is derived in the following76* way:77*78* Let's assume that each packet in a bundle of the maximum bundle size79* (HTC_HOST_MAX_MSG_PER_RX_BUNDLE) has the HTC header bundle count set80* to the maximum value (HTC_HOST_MAX_MSG_PER_RX_BUNDLE).81*82* in this case the driver must allocate83* (HTC_HOST_MAX_MSG_PER_RX_BUNDLE * 2) skb's.84*/85#define ATH10K_SDIO_MAX_RX_MSGS \86(HTC_HOST_MAX_MSG_PER_RX_BUNDLE * 2)8788#define ATH10K_FIFO_TIMEOUT_AND_CHIP_CONTROL 0x00000868u89#define ATH10K_FIFO_TIMEOUT_AND_CHIP_CONTROL_DISABLE_SLEEP_OFF 0xFFFEFFFF90#define ATH10K_FIFO_TIMEOUT_AND_CHIP_CONTROL_DISABLE_SLEEP_ON 0x100009192enum sdio_mbox_state {93SDIO_MBOX_UNKNOWN_STATE = 0,94SDIO_MBOX_REQUEST_TO_SLEEP_STATE = 1,95SDIO_MBOX_SLEEP_STATE = 2,96SDIO_MBOX_AWAKE_STATE = 3,97};9899#define ATH10K_CIS_READ_WAIT_4_RTC_CYCLE_IN_US 125100#define ATH10K_CIS_RTC_STATE_ADDR 0x1138101#define ATH10K_CIS_RTC_STATE_ON 0x01102#define ATH10K_CIS_XTAL_SETTLE_DURATION_IN_US 1500103#define ATH10K_CIS_READ_RETRY 10104#define ATH10K_MIN_SLEEP_INACTIVITY_TIME_MS 50105106/* TODO: remove this and use skb->cb instead, much cleaner approach */107struct ath10k_sdio_bus_request {108struct list_head list;109110/* sdio address */111u32 address;112113struct sk_buff *skb;114enum ath10k_htc_ep_id eid;115int status;116/* Specifies if the current request is an HTC message.117* If not, the eid is not applicable an the TX completion handler118* associated with the endpoint will not be invoked.119*/120bool htc_msg;121/* Completion that (if set) will be invoked for non HTC requests122* (htc_msg == false) when the request has been processed.123*/124struct completion *comp;125};126127struct ath10k_sdio_rx_data {128struct sk_buff *skb;129size_t alloc_len;130size_t act_len;131enum ath10k_htc_ep_id eid;132bool part_of_bundle;133bool last_in_bundle;134bool trailer_only;135};136137struct ath10k_sdio_irq_proc_regs {138u8 host_int_status;139u8 cpu_int_status;140u8 error_int_status;141u8 counter_int_status;142u8 mbox_frame;143u8 rx_lookahead_valid;144u8 host_int_status2;145u8 gmbox_rx_avail;146__le32 rx_lookahead[2 * ATH10K_HIF_MBOX_NUM_MAX];147__le32 int_status_enable;148};149150struct ath10k_sdio_irq_enable_regs {151u8 int_status_en;152u8 cpu_int_status_en;153u8 err_int_status_en;154u8 cntr_int_status_en;155};156157struct ath10k_sdio_irq_data {158/* protects irq_proc_reg and irq_en_reg below.159* We use a mutex here and not a spinlock since we will have the160* mutex locked while calling the sdio_memcpy_ functions.161* These function require non atomic context, and hence, spinlocks162* can be held while calling these functions.163*/164struct mutex mtx;165struct ath10k_sdio_irq_proc_regs *irq_proc_reg;166struct ath10k_sdio_irq_enable_regs *irq_en_reg;167};168169struct ath10k_mbox_ext_info {170u32 htc_ext_addr;171u32 htc_ext_sz;172};173174struct ath10k_mbox_info {175u32 htc_addr;176struct ath10k_mbox_ext_info ext_info[2];177u32 block_size;178u32 block_mask;179u32 gmbox_addr;180u32 gmbox_sz;181};182183struct ath10k_sdio {184struct sdio_func *func;185186struct ath10k_mbox_info mbox_info;187bool swap_mbox;188u32 mbox_addr[ATH10K_HTC_EP_COUNT];189u32 mbox_size[ATH10K_HTC_EP_COUNT];190191/* available bus requests */192struct ath10k_sdio_bus_request bus_req[ATH10K_SDIO_BUS_REQUEST_MAX_NUM];193/* free list of bus requests */194struct list_head bus_req_freeq;195196struct sk_buff_head rx_head;197198/* protects access to bus_req_freeq */199spinlock_t lock;200201struct ath10k_sdio_rx_data rx_pkts[ATH10K_SDIO_MAX_RX_MSGS];202size_t n_rx_pkts;203204struct ath10k *ar;205struct ath10k_sdio_irq_data irq_data;206207/* temporary buffer for sdio read.208* It is allocated when probe, and used for receive bundled packets,209* the read for bundled packets is not parallel, so it does not need210* protected.211*/212u8 *vsg_buffer;213214/* temporary buffer for BMI requests */215u8 *bmi_buf;216217bool is_disabled;218219struct workqueue_struct *workqueue;220struct work_struct wr_async_work;221struct list_head wr_asyncq;222/* protects access to wr_asyncq */223spinlock_t wr_async_lock;224225struct work_struct async_work_rx;226struct timer_list sleep_timer;227enum sdio_mbox_state mbox_state;228};229230static inline struct ath10k_sdio *ath10k_sdio_priv(struct ath10k *ar)231{232return (struct ath10k_sdio *)ar->drv_priv;233}234235#endif236237238