18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2004-2011 Atheros Communications Inc.
38c2ecf20Sopenharmony_ci * Copyright (c) 2011 Qualcomm Atheros, Inc.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
68c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
78c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
108c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
118c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
128c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
138c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
148c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
158c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef HIF_H
198c2ecf20Sopenharmony_ci#define HIF_H
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include "common.h"
228c2ecf20Sopenharmony_ci#include "core.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#include <linux/scatterlist.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define BUS_REQUEST_MAX_NUM                64
278c2ecf20Sopenharmony_ci#define HIF_MBOX_BLOCK_SIZE                128
288c2ecf20Sopenharmony_ci#define HIF_MBOX0_BLOCK_SIZE               1
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define HIF_DMA_BUFFER_SIZE (32 * 1024)
318c2ecf20Sopenharmony_ci#define CMD53_FIXED_ADDRESS 1
328c2ecf20Sopenharmony_ci#define CMD53_INCR_ADDRESS  2
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define MAX_SCATTER_REQUESTS             4
358c2ecf20Sopenharmony_ci#define MAX_SCATTER_ENTRIES_PER_REQ      16
368c2ecf20Sopenharmony_ci#define MAX_SCATTER_REQ_TRANSFER_SIZE    (32 * 1024)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* Mailbox address in SDIO address space */
398c2ecf20Sopenharmony_ci#define HIF_MBOX_BASE_ADDR                 0x800
408c2ecf20Sopenharmony_ci#define HIF_MBOX_WIDTH                     0x800
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define HIF_MBOX_END_ADDR  (HTC_MAILBOX_NUM_MAX * HIF_MBOX_WIDTH - 1)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* version 1 of the chip has only a 12K extended mbox range */
458c2ecf20Sopenharmony_ci#define HIF_MBOX0_EXT_BASE_ADDR  0x4000
468c2ecf20Sopenharmony_ci#define HIF_MBOX0_EXT_WIDTH      (12*1024)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* GMBOX addresses */
498c2ecf20Sopenharmony_ci#define HIF_GMBOX_BASE_ADDR                0x7000
508c2ecf20Sopenharmony_ci#define HIF_GMBOX_WIDTH                    0x4000
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/* interrupt mode register */
538c2ecf20Sopenharmony_ci#define CCCR_SDIO_IRQ_MODE_REG         0xF0
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* mode to enable special 4-bit interrupt assertion without clock */
568c2ecf20Sopenharmony_ci#define SDIO_IRQ_MODE_ASYNC_4BIT_IRQ   (1 << 0)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* HTC runs over mailbox 0 */
598c2ecf20Sopenharmony_ci#define HTC_MAILBOX	0
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define ATH6KL_TARGET_DEBUG_INTR_MASK     0x01
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* FIXME: are these duplicates with MAX_SCATTER_ values in hif.h? */
648c2ecf20Sopenharmony_ci#define ATH6KL_SCATTER_ENTRIES_PER_REQ            16
658c2ecf20Sopenharmony_ci#define ATH6KL_MAX_TRANSFER_SIZE_PER_SCATTER      (16 * 1024)
668c2ecf20Sopenharmony_ci#define ATH6KL_SCATTER_REQS                       4
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define ATH6KL_HIF_COMMUNICATION_TIMEOUT	1000
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistruct bus_request {
718c2ecf20Sopenharmony_ci	struct list_head list;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	/* request data */
748c2ecf20Sopenharmony_ci	u32 address;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	u8 *buffer;
778c2ecf20Sopenharmony_ci	u32 length;
788c2ecf20Sopenharmony_ci	u32 request;
798c2ecf20Sopenharmony_ci	struct htc_packet *packet;
808c2ecf20Sopenharmony_ci	int status;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	/* this is a scatter request */
838c2ecf20Sopenharmony_ci	struct hif_scatter_req *scat_req;
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci/* direction of transfer (read/write) */
878c2ecf20Sopenharmony_ci#define HIF_READ                    0x00000001
888c2ecf20Sopenharmony_ci#define HIF_WRITE                   0x00000002
898c2ecf20Sopenharmony_ci#define HIF_DIR_MASK                (HIF_READ | HIF_WRITE)
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/*
928c2ecf20Sopenharmony_ci *     emode - This indicates the whether the command is to be executed in a
938c2ecf20Sopenharmony_ci *             blocking or non-blocking fashion (HIF_SYNCHRONOUS/
948c2ecf20Sopenharmony_ci *             HIF_ASYNCHRONOUS). The read/write data paths in HTC have been
958c2ecf20Sopenharmony_ci *             implemented using the asynchronous mode allowing the the bus
968c2ecf20Sopenharmony_ci *             driver to indicate the completion of operation through the
978c2ecf20Sopenharmony_ci *             registered callback routine. The requirement primarily comes
988c2ecf20Sopenharmony_ci *             from the contexts these operations get called from (a driver's
998c2ecf20Sopenharmony_ci *             transmit context or the ISR context in case of receive).
1008c2ecf20Sopenharmony_ci *             Support for both of these modes is essential.
1018c2ecf20Sopenharmony_ci */
1028c2ecf20Sopenharmony_ci#define HIF_SYNCHRONOUS             0x00000010
1038c2ecf20Sopenharmony_ci#define HIF_ASYNCHRONOUS            0x00000020
1048c2ecf20Sopenharmony_ci#define HIF_EMODE_MASK              (HIF_SYNCHRONOUS | HIF_ASYNCHRONOUS)
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/*
1078c2ecf20Sopenharmony_ci *     dmode - An interface may support different kinds of commands based on
1088c2ecf20Sopenharmony_ci *             the tradeoff between the amount of data it can carry and the
1098c2ecf20Sopenharmony_ci *             setup time. Byte and Block modes are supported (HIF_BYTE_BASIS/
1108c2ecf20Sopenharmony_ci *             HIF_BLOCK_BASIS). In case of latter, the data is rounded off
1118c2ecf20Sopenharmony_ci *             to the nearest block size by padding. The size of the block is
1128c2ecf20Sopenharmony_ci *             configurable at compile time using the HIF_BLOCK_SIZE and is
1138c2ecf20Sopenharmony_ci *             negotiated with the target during initialization after the
1148c2ecf20Sopenharmony_ci *             ATH6KL interrupts are enabled.
1158c2ecf20Sopenharmony_ci */
1168c2ecf20Sopenharmony_ci#define HIF_BYTE_BASIS              0x00000040
1178c2ecf20Sopenharmony_ci#define HIF_BLOCK_BASIS             0x00000080
1188c2ecf20Sopenharmony_ci#define HIF_DMODE_MASK              (HIF_BYTE_BASIS | HIF_BLOCK_BASIS)
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/*
1218c2ecf20Sopenharmony_ci *     amode - This indicates if the address has to be incremented on ATH6KL
1228c2ecf20Sopenharmony_ci *             after every read/write operation (HIF?FIXED_ADDRESS/
1238c2ecf20Sopenharmony_ci *             HIF_INCREMENTAL_ADDRESS).
1248c2ecf20Sopenharmony_ci */
1258c2ecf20Sopenharmony_ci#define HIF_FIXED_ADDRESS           0x00000100
1268c2ecf20Sopenharmony_ci#define HIF_INCREMENTAL_ADDRESS     0x00000200
1278c2ecf20Sopenharmony_ci#define HIF_AMODE_MASK		  (HIF_FIXED_ADDRESS | HIF_INCREMENTAL_ADDRESS)
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define HIF_WR_ASYNC_BYTE_INC					\
1308c2ecf20Sopenharmony_ci	(HIF_WRITE | HIF_ASYNCHRONOUS |				\
1318c2ecf20Sopenharmony_ci	 HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS)
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#define HIF_WR_ASYNC_BLOCK_INC					\
1348c2ecf20Sopenharmony_ci	(HIF_WRITE | HIF_ASYNCHRONOUS |				\
1358c2ecf20Sopenharmony_ci	 HIF_BLOCK_BASIS | HIF_INCREMENTAL_ADDRESS)
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci#define HIF_WR_SYNC_BYTE_FIX					\
1388c2ecf20Sopenharmony_ci	(HIF_WRITE | HIF_SYNCHRONOUS |				\
1398c2ecf20Sopenharmony_ci	 HIF_BYTE_BASIS | HIF_FIXED_ADDRESS)
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define HIF_WR_SYNC_BYTE_INC					\
1428c2ecf20Sopenharmony_ci	(HIF_WRITE | HIF_SYNCHRONOUS |				\
1438c2ecf20Sopenharmony_ci	 HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS)
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci#define HIF_WR_SYNC_BLOCK_INC					\
1468c2ecf20Sopenharmony_ci	(HIF_WRITE | HIF_SYNCHRONOUS |				\
1478c2ecf20Sopenharmony_ci	 HIF_BLOCK_BASIS | HIF_INCREMENTAL_ADDRESS)
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#define HIF_RD_SYNC_BYTE_INC						\
1508c2ecf20Sopenharmony_ci	(HIF_READ | HIF_SYNCHRONOUS |					\
1518c2ecf20Sopenharmony_ci	 HIF_BYTE_BASIS | HIF_INCREMENTAL_ADDRESS)
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#define HIF_RD_SYNC_BYTE_FIX						\
1548c2ecf20Sopenharmony_ci	(HIF_READ | HIF_SYNCHRONOUS |					\
1558c2ecf20Sopenharmony_ci	 HIF_BYTE_BASIS | HIF_FIXED_ADDRESS)
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#define HIF_RD_ASYNC_BLOCK_FIX						\
1588c2ecf20Sopenharmony_ci	(HIF_READ | HIF_ASYNCHRONOUS |					\
1598c2ecf20Sopenharmony_ci	 HIF_BLOCK_BASIS | HIF_FIXED_ADDRESS)
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#define HIF_RD_SYNC_BLOCK_FIX						\
1628c2ecf20Sopenharmony_ci	(HIF_READ | HIF_SYNCHRONOUS |					\
1638c2ecf20Sopenharmony_ci	 HIF_BLOCK_BASIS | HIF_FIXED_ADDRESS)
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistruct hif_scatter_item {
1668c2ecf20Sopenharmony_ci	u8 *buf;
1678c2ecf20Sopenharmony_ci	int len;
1688c2ecf20Sopenharmony_ci	struct htc_packet *packet;
1698c2ecf20Sopenharmony_ci};
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_cistruct hif_scatter_req {
1728c2ecf20Sopenharmony_ci	struct list_head list;
1738c2ecf20Sopenharmony_ci	/* address for the read/write operation */
1748c2ecf20Sopenharmony_ci	u32 addr;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	/* request flags */
1778c2ecf20Sopenharmony_ci	u32 req;
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	/* total length of entire transfer */
1808c2ecf20Sopenharmony_ci	u32 len;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	bool virt_scat;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	void (*complete) (struct htc_target *, struct hif_scatter_req *);
1858c2ecf20Sopenharmony_ci	int status;
1868c2ecf20Sopenharmony_ci	int scat_entries;
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	struct bus_request *busrequest;
1898c2ecf20Sopenharmony_ci	struct scatterlist *sgentries;
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	/* bounce buffer for upper layers to copy to/from */
1928c2ecf20Sopenharmony_ci	u8 *virt_dma_buf;
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	u32 scat_q_depth;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	struct hif_scatter_item scat_list[];
1978c2ecf20Sopenharmony_ci};
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistruct ath6kl_irq_proc_registers {
2008c2ecf20Sopenharmony_ci	u8 host_int_status;
2018c2ecf20Sopenharmony_ci	u8 cpu_int_status;
2028c2ecf20Sopenharmony_ci	u8 error_int_status;
2038c2ecf20Sopenharmony_ci	u8 counter_int_status;
2048c2ecf20Sopenharmony_ci	u8 mbox_frame;
2058c2ecf20Sopenharmony_ci	u8 rx_lkahd_valid;
2068c2ecf20Sopenharmony_ci	u8 host_int_status2;
2078c2ecf20Sopenharmony_ci	u8 gmbox_rx_avail;
2088c2ecf20Sopenharmony_ci	__le32 rx_lkahd[2];
2098c2ecf20Sopenharmony_ci	__le32 rx_gmbox_lkahd_alias[2];
2108c2ecf20Sopenharmony_ci} __packed;
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_cistruct ath6kl_irq_enable_reg {
2138c2ecf20Sopenharmony_ci	u8 int_status_en;
2148c2ecf20Sopenharmony_ci	u8 cpu_int_status_en;
2158c2ecf20Sopenharmony_ci	u8 err_int_status_en;
2168c2ecf20Sopenharmony_ci	u8 cntr_int_status_en;
2178c2ecf20Sopenharmony_ci} __packed;
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistruct ath6kl_device {
2208c2ecf20Sopenharmony_ci	/* protects irq_proc_reg and irq_en_reg below */
2218c2ecf20Sopenharmony_ci	spinlock_t lock;
2228c2ecf20Sopenharmony_ci	struct ath6kl_irq_proc_registers irq_proc_reg;
2238c2ecf20Sopenharmony_ci	struct ath6kl_irq_enable_reg irq_en_reg;
2248c2ecf20Sopenharmony_ci	struct htc_target *htc_cnxt;
2258c2ecf20Sopenharmony_ci	struct ath6kl *ar;
2268c2ecf20Sopenharmony_ci};
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistruct ath6kl_hif_ops {
2298c2ecf20Sopenharmony_ci	int (*read_write_sync)(struct ath6kl *ar, u32 addr, u8 *buf,
2308c2ecf20Sopenharmony_ci			       u32 len, u32 request);
2318c2ecf20Sopenharmony_ci	int (*write_async)(struct ath6kl *ar, u32 address, u8 *buffer,
2328c2ecf20Sopenharmony_ci			   u32 length, u32 request, struct htc_packet *packet);
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	void (*irq_enable)(struct ath6kl *ar);
2358c2ecf20Sopenharmony_ci	void (*irq_disable)(struct ath6kl *ar);
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	struct hif_scatter_req *(*scatter_req_get)(struct ath6kl *ar);
2388c2ecf20Sopenharmony_ci	void (*scatter_req_add)(struct ath6kl *ar,
2398c2ecf20Sopenharmony_ci				struct hif_scatter_req *s_req);
2408c2ecf20Sopenharmony_ci	int (*enable_scatter)(struct ath6kl *ar);
2418c2ecf20Sopenharmony_ci	int (*scat_req_rw) (struct ath6kl *ar,
2428c2ecf20Sopenharmony_ci			    struct hif_scatter_req *scat_req);
2438c2ecf20Sopenharmony_ci	void (*cleanup_scatter)(struct ath6kl *ar);
2448c2ecf20Sopenharmony_ci	int (*suspend)(struct ath6kl *ar, struct cfg80211_wowlan *wow);
2458c2ecf20Sopenharmony_ci	int (*resume)(struct ath6kl *ar);
2468c2ecf20Sopenharmony_ci	int (*diag_read32)(struct ath6kl *ar, u32 address, u32 *value);
2478c2ecf20Sopenharmony_ci	int (*diag_write32)(struct ath6kl *ar, u32 address, __le32 value);
2488c2ecf20Sopenharmony_ci	int (*bmi_read)(struct ath6kl *ar, u8 *buf, u32 len);
2498c2ecf20Sopenharmony_ci	int (*bmi_write)(struct ath6kl *ar, u8 *buf, u32 len);
2508c2ecf20Sopenharmony_ci	int (*power_on)(struct ath6kl *ar);
2518c2ecf20Sopenharmony_ci	int (*power_off)(struct ath6kl *ar);
2528c2ecf20Sopenharmony_ci	void (*stop)(struct ath6kl *ar);
2538c2ecf20Sopenharmony_ci	int (*pipe_send)(struct ath6kl *ar, u8 pipe, struct sk_buff *hdr_buf,
2548c2ecf20Sopenharmony_ci			 struct sk_buff *buf);
2558c2ecf20Sopenharmony_ci	void (*pipe_get_default)(struct ath6kl *ar, u8 *pipe_ul, u8 *pipe_dl);
2568c2ecf20Sopenharmony_ci	int (*pipe_map_service)(struct ath6kl *ar, u16 service_id, u8 *pipe_ul,
2578c2ecf20Sopenharmony_ci				u8 *pipe_dl);
2588c2ecf20Sopenharmony_ci	u16 (*pipe_get_free_queue_number)(struct ath6kl *ar, u8 pipe);
2598c2ecf20Sopenharmony_ci};
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ciint ath6kl_hif_setup(struct ath6kl_device *dev);
2628c2ecf20Sopenharmony_ciint ath6kl_hif_unmask_intrs(struct ath6kl_device *dev);
2638c2ecf20Sopenharmony_ciint ath6kl_hif_mask_intrs(struct ath6kl_device *dev);
2648c2ecf20Sopenharmony_ciint ath6kl_hif_poll_mboxmsg_rx(struct ath6kl_device *dev,
2658c2ecf20Sopenharmony_ci			       u32 *lk_ahd, int timeout);
2668c2ecf20Sopenharmony_ciint ath6kl_hif_rx_control(struct ath6kl_device *dev, bool enable_rx);
2678c2ecf20Sopenharmony_ciint ath6kl_hif_disable_intrs(struct ath6kl_device *dev);
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ciint ath6kl_hif_rw_comp_handler(void *context, int status);
2708c2ecf20Sopenharmony_ciint ath6kl_hif_intr_bh_handler(struct ath6kl *ar);
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci/* Scatter Function and Definitions */
2738c2ecf20Sopenharmony_ciint ath6kl_hif_submit_scat_req(struct ath6kl_device *dev,
2748c2ecf20Sopenharmony_ci			       struct hif_scatter_req *scat_req, bool read);
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci#endif
277