1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Copyright (c) 2004-2011 Atheros Communications Inc. 3*4882a593Smuzhiyun * Copyright (c) 2011 Qualcomm Atheros, Inc. 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Permission to use, copy, modify, and/or distribute this software for any 6*4882a593Smuzhiyun * purpose with or without fee is hereby granted, provided that the above 7*4882a593Smuzhiyun * copyright notice and this permission notice appear in all copies. 8*4882a593Smuzhiyun * 9*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10*4882a593Smuzhiyun * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11*4882a593Smuzhiyun * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12*4882a593Smuzhiyun * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13*4882a593Smuzhiyun * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14*4882a593Smuzhiyun * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15*4882a593Smuzhiyun * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16*4882a593Smuzhiyun */ 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun #ifndef HIF_H 19*4882a593Smuzhiyun #define HIF_H 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun #include "common.h" 22*4882a593Smuzhiyun #include "core.h" 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun #include <linux/scatterlist.h> 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun #define BUS_REQUEST_MAX_NUM 64 27*4882a593Smuzhiyun #define HIF_MBOX_BLOCK_SIZE 128 28*4882a593Smuzhiyun #define HIF_MBOX0_BLOCK_SIZE 1 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun #define HIF_DMA_BUFFER_SIZE (32 * 1024) 31*4882a593Smuzhiyun #define CMD53_FIXED_ADDRESS 1 32*4882a593Smuzhiyun #define CMD53_INCR_ADDRESS 2 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun #define MAX_SCATTER_REQUESTS 4 35*4882a593Smuzhiyun #define MAX_SCATTER_ENTRIES_PER_REQ 16 36*4882a593Smuzhiyun #define MAX_SCATTER_REQ_TRANSFER_SIZE (32 * 1024) 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun /* Mailbox address in SDIO address space */ 39*4882a593Smuzhiyun #define HIF_MBOX_BASE_ADDR 0x800 40*4882a593Smuzhiyun #define HIF_MBOX_WIDTH 0x800 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun #define HIF_MBOX_END_ADDR (HTC_MAILBOX_NUM_MAX * HIF_MBOX_WIDTH - 1) 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun /* version 1 of the chip has only a 12K extended mbox range */ 45*4882a593Smuzhiyun #define HIF_MBOX0_EXT_BASE_ADDR 0x4000 46*4882a593Smuzhiyun #define HIF_MBOX0_EXT_WIDTH (12*1024) 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun /* GMBOX addresses */ 49*4882a593Smuzhiyun #define HIF_GMBOX_BASE_ADDR 0x7000 50*4882a593Smuzhiyun #define HIF_GMBOX_WIDTH 0x4000 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun /* interrupt mode register */ 53*4882a593Smuzhiyun #define CCCR_SDIO_IRQ_MODE_REG 0xF0 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun /* mode to enable special 4-bit interrupt assertion without clock */ 56*4882a593Smuzhiyun #define SDIO_IRQ_MODE_ASYNC_4BIT_IRQ (1 << 0) 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun /* HTC runs over mailbox 0 */ 59*4882a593Smuzhiyun #define HTC_MAILBOX 0 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun #define ATH6KL_TARGET_DEBUG_INTR_MASK 0x01 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun /* FIXME: are these duplicates with MAX_SCATTER_ values in hif.h? */ 64*4882a593Smuzhiyun #define ATH6KL_SCATTER_ENTRIES_PER_REQ 16 65*4882a593Smuzhiyun #define ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER (16 * 1024) 66*4882a593Smuzhiyun #define ATH6KL_SCATTER_REQS 4 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun #define ATH6KL_HIF_COMMUNICATION_TIMEOUT 1000 69*4882a593Smuzhiyun 70*4882a593Smuzhiyun struct bus_request { 71*4882a593Smuzhiyun struct list_head list; 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun /* request data */ 74*4882a593Smuzhiyun u32 address; 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun u8 *buffer; 77*4882a593Smuzhiyun u32 length; 78*4882a593Smuzhiyun u32 request; 79*4882a593Smuzhiyun struct htc_packet *packet; 80*4882a593Smuzhiyun int status; 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun /* this is a scatter request */ 83*4882a593Smuzhiyun struct hif_scatter_req *scat_req; 84*4882a593Smuzhiyun }; 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun /* direction of transfer (read/write) */ 87*4882a593Smuzhiyun #define HIF_READ 0x00000001 88*4882a593Smuzhiyun #define HIF_WRITE 0x00000002 89*4882a593Smuzhiyun #define HIF_DIR_MASK (HIF_READ | HIF_WRITE) 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun /* 92*4882a593Smuzhiyun * emode - This indicates the whether the command is to be executed in a 93*4882a593Smuzhiyun * blocking or non-blocking fashion (HIF_SYNCHRONOUS/ 94*4882a593Smuzhiyun * HIF_ASYNCHRONOUS). The read/write data paths in HTC have been 95*4882a593Smuzhiyun * implemented using the asynchronous mode allowing the the bus 96*4882a593Smuzhiyun * driver to indicate the completion of operation through the 97*4882a593Smuzhiyun * registered callback routine. The requirement primarily comes 98*4882a593Smuzhiyun * from the contexts these operations get called from (a driver's 99*4882a593Smuzhiyun * transmit context or the ISR context in case of receive). 100*4882a593Smuzhiyun * Support for both of these modes is essential. 101*4882a593Smuzhiyun */ 102*4882a593Smuzhiyun #define HIF_SYNCHRONOUS 0x00000010 103*4882a593Smuzhiyun #define HIF_ASYNCHRONOUS 0x00000020 104*4882a593Smuzhiyun #define HIF_EMODE_MASK (HIF_SYNCHRONOUS | HIF_ASYNCHRONOUS) 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun /* 107*4882a593Smuzhiyun * dmode - An interface may support different kinds of commands based on 108*4882a593Smuzhiyun * the tradeoff between the amount of data it can carry and the 109*4882a593Smuzhiyun * setup time. Byte and Block modes are supported (HIF_BYTE_BASIS/ 110*4882a593Smuzhiyun * HIF_BLOCK_BASIS). In case of latter, the data is rounded off 111*4882a593Smuzhiyun * to the nearest block size by padding. The size of the block is 112*4882a593Smuzhiyun * configurable at compile time using the HIF_BLOCK_SIZE and is 113*4882a593Smuzhiyun * negotiated with the target during initialization after the 114*4882a593Smuzhiyun * ATH6KL interrupts are enabled. 115*4882a593Smuzhiyun */ 116*4882a593Smuzhiyun #define HIF_BYTE_BASIS 0x00000040 117*4882a593Smuzhiyun #define HIF_BLOCK_BASIS 0x00000080 118*4882a593Smuzhiyun #define HIF_DMODE_MASK (HIF_BYTE_BASIS | HIF_BLOCK_BASIS) 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun /* 121*4882a593Smuzhiyun * amode - This indicates if the address has to be incremented on ATH6KL 122*4882a593Smuzhiyun * after every read/write operation (HIF?FIXED_ADDRESS/ 123*4882a593Smuzhiyun * HIF_INCREMENTAL_ADDRESS). 124*4882a593Smuzhiyun */ 125*4882a593Smuzhiyun #define HIF_FIXED_ADDRESS 0x00000100 126*4882a593Smuzhiyun #define HIF_INCREMENTAL_ADDRESS 0x00000200 127*4882a593Smuzhiyun #define HIF_AMODE_MASK (HIF_FIXED_ADDRESS | HIF_INCREMENTAL_ADDRESS) 128*4882a593Smuzhiyun 129*4882a593Smuzhiyun #define HIF_WR_ASYNC_BYTE_INC \ 130*4882a593Smuzhiyun (HIF_WRITE | HIF_ASYNCHRONOUS | \ 131*4882a593Smuzhiyun HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS) 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun #define HIF_WR_ASYNC_BLOCK_INC \ 134*4882a593Smuzhiyun (HIF_WRITE | HIF_ASYNCHRONOUS | \ 135*4882a593Smuzhiyun HIF_BLOCK_BASIS | HIF_INCREMENTAL_ADDRESS) 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun #define HIF_WR_SYNC_BYTE_FIX \ 138*4882a593Smuzhiyun (HIF_WRITE | HIF_SYNCHRONOUS | \ 139*4882a593Smuzhiyun HIF_BYTE_BASIS | HIF_FIXED_ADDRESS) 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun #define HIF_WR_SYNC_BYTE_INC \ 142*4882a593Smuzhiyun (HIF_WRITE | HIF_SYNCHRONOUS | \ 143*4882a593Smuzhiyun HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS) 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun #define HIF_WR_SYNC_BLOCK_INC \ 146*4882a593Smuzhiyun (HIF_WRITE | HIF_SYNCHRONOUS | \ 147*4882a593Smuzhiyun HIF_BLOCK_BASIS | HIF_INCREMENTAL_ADDRESS) 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun #define HIF_RD_SYNC_BYTE_INC \ 150*4882a593Smuzhiyun (HIF_READ | HIF_SYNCHRONOUS | \ 151*4882a593Smuzhiyun HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS) 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun #define HIF_RD_SYNC_BYTE_FIX \ 154*4882a593Smuzhiyun (HIF_READ | HIF_SYNCHRONOUS | \ 155*4882a593Smuzhiyun HIF_BYTE_BASIS | HIF_FIXED_ADDRESS) 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun #define HIF_RD_ASYNC_BLOCK_FIX \ 158*4882a593Smuzhiyun (HIF_READ | HIF_ASYNCHRONOUS | \ 159*4882a593Smuzhiyun HIF_BLOCK_BASIS | HIF_FIXED_ADDRESS) 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun #define HIF_RD_SYNC_BLOCK_FIX \ 162*4882a593Smuzhiyun (HIF_READ | HIF_SYNCHRONOUS | \ 163*4882a593Smuzhiyun HIF_BLOCK_BASIS | HIF_FIXED_ADDRESS) 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun struct hif_scatter_item { 166*4882a593Smuzhiyun u8 *buf; 167*4882a593Smuzhiyun int len; 168*4882a593Smuzhiyun struct htc_packet *packet; 169*4882a593Smuzhiyun }; 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun struct hif_scatter_req { 172*4882a593Smuzhiyun struct list_head list; 173*4882a593Smuzhiyun /* address for the read/write operation */ 174*4882a593Smuzhiyun u32 addr; 175*4882a593Smuzhiyun 176*4882a593Smuzhiyun /* request flags */ 177*4882a593Smuzhiyun u32 req; 178*4882a593Smuzhiyun 179*4882a593Smuzhiyun /* total length of entire transfer */ 180*4882a593Smuzhiyun u32 len; 181*4882a593Smuzhiyun 182*4882a593Smuzhiyun bool virt_scat; 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun void (*complete) (struct htc_target *, struct hif_scatter_req *); 185*4882a593Smuzhiyun int status; 186*4882a593Smuzhiyun int scat_entries; 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun struct bus_request *busrequest; 189*4882a593Smuzhiyun struct scatterlist *sgentries; 190*4882a593Smuzhiyun 191*4882a593Smuzhiyun /* bounce buffer for upper layers to copy to/from */ 192*4882a593Smuzhiyun u8 *virt_dma_buf; 193*4882a593Smuzhiyun 194*4882a593Smuzhiyun u32 scat_q_depth; 195*4882a593Smuzhiyun 196*4882a593Smuzhiyun struct hif_scatter_item scat_list[]; 197*4882a593Smuzhiyun }; 198*4882a593Smuzhiyun 199*4882a593Smuzhiyun struct ath6kl_irq_proc_registers { 200*4882a593Smuzhiyun u8 host_int_status; 201*4882a593Smuzhiyun u8 cpu_int_status; 202*4882a593Smuzhiyun u8 error_int_status; 203*4882a593Smuzhiyun u8 counter_int_status; 204*4882a593Smuzhiyun u8 mbox_frame; 205*4882a593Smuzhiyun u8 rx_lkahd_valid; 206*4882a593Smuzhiyun u8 host_int_status2; 207*4882a593Smuzhiyun u8 gmbox_rx_avail; 208*4882a593Smuzhiyun __le32 rx_lkahd[2]; 209*4882a593Smuzhiyun __le32 rx_gmbox_lkahd_alias[2]; 210*4882a593Smuzhiyun } __packed; 211*4882a593Smuzhiyun 212*4882a593Smuzhiyun struct ath6kl_irq_enable_reg { 213*4882a593Smuzhiyun u8 int_status_en; 214*4882a593Smuzhiyun u8 cpu_int_status_en; 215*4882a593Smuzhiyun u8 err_int_status_en; 216*4882a593Smuzhiyun u8 cntr_int_status_en; 217*4882a593Smuzhiyun } __packed; 218*4882a593Smuzhiyun 219*4882a593Smuzhiyun struct ath6kl_device { 220*4882a593Smuzhiyun /* protects irq_proc_reg and irq_en_reg below */ 221*4882a593Smuzhiyun spinlock_t lock; 222*4882a593Smuzhiyun struct ath6kl_irq_proc_registers irq_proc_reg; 223*4882a593Smuzhiyun struct ath6kl_irq_enable_reg irq_en_reg; 224*4882a593Smuzhiyun struct htc_target *htc_cnxt; 225*4882a593Smuzhiyun struct ath6kl *ar; 226*4882a593Smuzhiyun }; 227*4882a593Smuzhiyun 228*4882a593Smuzhiyun struct ath6kl_hif_ops { 229*4882a593Smuzhiyun int (*read_write_sync)(struct ath6kl *ar, u32 addr, u8 *buf, 230*4882a593Smuzhiyun u32 len, u32 request); 231*4882a593Smuzhiyun int (*write_async)(struct ath6kl *ar, u32 address, u8 *buffer, 232*4882a593Smuzhiyun u32 length, u32 request, struct htc_packet *packet); 233*4882a593Smuzhiyun 234*4882a593Smuzhiyun void (*irq_enable)(struct ath6kl *ar); 235*4882a593Smuzhiyun void (*irq_disable)(struct ath6kl *ar); 236*4882a593Smuzhiyun 237*4882a593Smuzhiyun struct hif_scatter_req *(*scatter_req_get)(struct ath6kl *ar); 238*4882a593Smuzhiyun void (*scatter_req_add)(struct ath6kl *ar, 239*4882a593Smuzhiyun struct hif_scatter_req *s_req); 240*4882a593Smuzhiyun int (*enable_scatter)(struct ath6kl *ar); 241*4882a593Smuzhiyun int (*scat_req_rw) (struct ath6kl *ar, 242*4882a593Smuzhiyun struct hif_scatter_req *scat_req); 243*4882a593Smuzhiyun void (*cleanup_scatter)(struct ath6kl *ar); 244*4882a593Smuzhiyun int (*suspend)(struct ath6kl *ar, struct cfg80211_wowlan *wow); 245*4882a593Smuzhiyun int (*resume)(struct ath6kl *ar); 246*4882a593Smuzhiyun int (*diag_read32)(struct ath6kl *ar, u32 address, u32 *value); 247*4882a593Smuzhiyun int (*diag_write32)(struct ath6kl *ar, u32 address, __le32 value); 248*4882a593Smuzhiyun int (*bmi_read)(struct ath6kl *ar, u8 *buf, u32 len); 249*4882a593Smuzhiyun int (*bmi_write)(struct ath6kl *ar, u8 *buf, u32 len); 250*4882a593Smuzhiyun int (*power_on)(struct ath6kl *ar); 251*4882a593Smuzhiyun int (*power_off)(struct ath6kl *ar); 252*4882a593Smuzhiyun void (*stop)(struct ath6kl *ar); 253*4882a593Smuzhiyun int (*pipe_send)(struct ath6kl *ar, u8 pipe, struct sk_buff *hdr_buf, 254*4882a593Smuzhiyun struct sk_buff *buf); 255*4882a593Smuzhiyun void (*pipe_get_default)(struct ath6kl *ar, u8 *pipe_ul, u8 *pipe_dl); 256*4882a593Smuzhiyun int (*pipe_map_service)(struct ath6kl *ar, u16 service_id, u8 *pipe_ul, 257*4882a593Smuzhiyun u8 *pipe_dl); 258*4882a593Smuzhiyun u16 (*pipe_get_free_queue_number)(struct ath6kl *ar, u8 pipe); 259*4882a593Smuzhiyun }; 260*4882a593Smuzhiyun 261*4882a593Smuzhiyun int ath6kl_hif_setup(struct ath6kl_device *dev); 262*4882a593Smuzhiyun int ath6kl_hif_unmask_intrs(struct ath6kl_device *dev); 263*4882a593Smuzhiyun int ath6kl_hif_mask_intrs(struct ath6kl_device *dev); 264*4882a593Smuzhiyun int ath6kl_hif_poll_mboxmsg_rx(struct ath6kl_device *dev, 265*4882a593Smuzhiyun u32 *lk_ahd, int timeout); 266*4882a593Smuzhiyun int ath6kl_hif_rx_control(struct ath6kl_device *dev, bool enable_rx); 267*4882a593Smuzhiyun int ath6kl_hif_disable_intrs(struct ath6kl_device *dev); 268*4882a593Smuzhiyun 269*4882a593Smuzhiyun int ath6kl_hif_rw_comp_handler(void *context, int status); 270*4882a593Smuzhiyun int ath6kl_hif_intr_bh_handler(struct ath6kl *ar); 271*4882a593Smuzhiyun 272*4882a593Smuzhiyun /* Scatter Function and Definitions */ 273*4882a593Smuzhiyun int ath6kl_hif_submit_scat_req(struct ath6kl_device *dev, 274*4882a593Smuzhiyun struct hif_scatter_req *scat_req, bool read); 275*4882a593Smuzhiyun 276*4882a593Smuzhiyun #endif 277