18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * NXP Wireless LAN device driver: SDIO specific definitions
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright 2011-2020 NXP
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This software file (the "File") is distributed by NXP
78c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License Version 2, June 1991
88c2ecf20Sopenharmony_ci * (the "License").  You may use, redistribute and/or modify this File in
98c2ecf20Sopenharmony_ci * accordance with the terms and conditions of the License, a copy of which
108c2ecf20Sopenharmony_ci * is available by writing to the Free Software Foundation, Inc.,
118c2ecf20Sopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
128c2ecf20Sopenharmony_ci * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
158c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
168c2ecf20Sopenharmony_ci * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
178c2ecf20Sopenharmony_ci * this warranty disclaimer.
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#ifndef	_MWIFIEX_SDIO_H
218c2ecf20Sopenharmony_ci#define	_MWIFIEX_SDIO_H
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#include <linux/completion.h>
258c2ecf20Sopenharmony_ci#include <linux/mmc/sdio.h>
268c2ecf20Sopenharmony_ci#include <linux/mmc/sdio_ids.h>
278c2ecf20Sopenharmony_ci#include <linux/mmc/sdio_func.h>
288c2ecf20Sopenharmony_ci#include <linux/mmc/card.h>
298c2ecf20Sopenharmony_ci#include <linux/mmc/host.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#include "main.h"
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define SD8786_DEFAULT_FW_NAME "mrvl/sd8786_uapsta.bin"
348c2ecf20Sopenharmony_ci#define SD8787_DEFAULT_FW_NAME "mrvl/sd8787_uapsta.bin"
358c2ecf20Sopenharmony_ci#define SD8797_DEFAULT_FW_NAME "mrvl/sd8797_uapsta.bin"
368c2ecf20Sopenharmony_ci#define SD8897_DEFAULT_FW_NAME "mrvl/sd8897_uapsta.bin"
378c2ecf20Sopenharmony_ci#define SD8887_DEFAULT_FW_NAME "mrvl/sd8887_uapsta.bin"
388c2ecf20Sopenharmony_ci#define SD8801_DEFAULT_FW_NAME "mrvl/sd8801_uapsta.bin"
398c2ecf20Sopenharmony_ci#define SD8977_DEFAULT_FW_NAME "mrvl/sdsd8977_combo_v2.bin"
408c2ecf20Sopenharmony_ci#define SD8987_DEFAULT_FW_NAME "mrvl/sd8987_uapsta.bin"
418c2ecf20Sopenharmony_ci#define SD8997_DEFAULT_FW_NAME "mrvl/sdsd8997_combo_v4.bin"
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define BLOCK_MODE	1
448c2ecf20Sopenharmony_ci#define BYTE_MODE	0
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define REG_PORT			0
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define MWIFIEX_SDIO_IO_PORT_MASK		0xfffff
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define MWIFIEX_SDIO_BYTE_MODE_MASK	0x80000000
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define MWIFIEX_MAX_FUNC2_REG_NUM	13
538c2ecf20Sopenharmony_ci#define MWIFIEX_SDIO_SCRATCH_SIZE	10
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define SDIO_MPA_ADDR_BASE		0x1000
568c2ecf20Sopenharmony_ci#define CTRL_PORT			0
578c2ecf20Sopenharmony_ci#define CTRL_PORT_MASK			0x0001
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define CMD_PORT_UPLD_INT_MASK		(0x1U<<6)
608c2ecf20Sopenharmony_ci#define CMD_PORT_DNLD_INT_MASK		(0x1U<<7)
618c2ecf20Sopenharmony_ci#define HOST_TERM_CMD53			(0x1U << 2)
628c2ecf20Sopenharmony_ci#define REG_PORT			0
638c2ecf20Sopenharmony_ci#define MEM_PORT			0x10000
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#define CMD53_NEW_MODE			(0x1U << 0)
668c2ecf20Sopenharmony_ci#define CMD_PORT_RD_LEN_EN		(0x1U << 2)
678c2ecf20Sopenharmony_ci#define CMD_PORT_AUTO_EN		(0x1U << 0)
688c2ecf20Sopenharmony_ci#define CMD_PORT_SLCT			0x8000
698c2ecf20Sopenharmony_ci#define UP_LD_CMD_PORT_HOST_INT_STATUS	(0x40U)
708c2ecf20Sopenharmony_ci#define DN_LD_CMD_PORT_HOST_INT_STATUS	(0x80U)
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#define MWIFIEX_MP_AGGR_BUF_SIZE_16K	(16384)
738c2ecf20Sopenharmony_ci#define MWIFIEX_MP_AGGR_BUF_SIZE_32K	(32768)
748c2ecf20Sopenharmony_ci/* we leave one block of 256 bytes for DMA alignment*/
758c2ecf20Sopenharmony_ci#define MWIFIEX_MP_AGGR_BUF_SIZE_MAX    (65280)
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/* Misc. Config Register : Auto Re-enable interrupts */
788c2ecf20Sopenharmony_ci#define AUTO_RE_ENABLE_INT              BIT(4)
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* Host Control Registers : Configuration */
818c2ecf20Sopenharmony_ci#define CONFIGURATION_REG		0x00
828c2ecf20Sopenharmony_ci/* Host Control Registers : Host power up */
838c2ecf20Sopenharmony_ci#define HOST_POWER_UP			(0x1U << 1)
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* Host Control Registers : Upload host interrupt mask */
868c2ecf20Sopenharmony_ci#define UP_LD_HOST_INT_MASK		(0x1U)
878c2ecf20Sopenharmony_ci/* Host Control Registers : Download host interrupt mask */
888c2ecf20Sopenharmony_ci#define DN_LD_HOST_INT_MASK		(0x2U)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* Host Control Registers : Upload host interrupt status */
918c2ecf20Sopenharmony_ci#define UP_LD_HOST_INT_STATUS		(0x1U)
928c2ecf20Sopenharmony_ci/* Host Control Registers : Download host interrupt status */
938c2ecf20Sopenharmony_ci#define DN_LD_HOST_INT_STATUS		(0x2U)
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/* Host Control Registers : Host interrupt status */
968c2ecf20Sopenharmony_ci#define CARD_INT_STATUS_REG		0x28
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/* Card Control Registers : Card I/O ready */
998c2ecf20Sopenharmony_ci#define CARD_IO_READY                   (0x1U << 3)
1008c2ecf20Sopenharmony_ci/* Card Control Registers : Download card ready */
1018c2ecf20Sopenharmony_ci#define DN_LD_CARD_RDY                  (0x1U << 0)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* Max retry number of CMD53 write */
1048c2ecf20Sopenharmony_ci#define MAX_WRITE_IOMEM_RETRY		2
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* SDIO Tx aggregation in progress ? */
1078c2ecf20Sopenharmony_ci#define MP_TX_AGGR_IN_PROGRESS(a) (a->mpa_tx.pkt_cnt > 0)
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/* SDIO Tx aggregation buffer room for next packet ? */
1108c2ecf20Sopenharmony_ci#define MP_TX_AGGR_BUF_HAS_ROOM(a, len) ((a->mpa_tx.buf_len+len)	\
1118c2ecf20Sopenharmony_ci						<= a->mpa_tx.buf_size)
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/* Copy current packet (SDIO Tx aggregation buffer) to SDIO buffer */
1148c2ecf20Sopenharmony_ci#define MP_TX_AGGR_BUF_PUT(a, payload, pkt_len, port) do {		\
1158c2ecf20Sopenharmony_ci	memmove(&a->mpa_tx.buf[a->mpa_tx.buf_len],			\
1168c2ecf20Sopenharmony_ci			payload, pkt_len);				\
1178c2ecf20Sopenharmony_ci	a->mpa_tx.buf_len += pkt_len;					\
1188c2ecf20Sopenharmony_ci	if (!a->mpa_tx.pkt_cnt)						\
1198c2ecf20Sopenharmony_ci		a->mpa_tx.start_port = port;				\
1208c2ecf20Sopenharmony_ci	if (a->mpa_tx.start_port <= port)				\
1218c2ecf20Sopenharmony_ci		a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt));		\
1228c2ecf20Sopenharmony_ci	else								\
1238c2ecf20Sopenharmony_ci		a->mpa_tx.ports |= (1<<(a->mpa_tx.pkt_cnt+1+		\
1248c2ecf20Sopenharmony_ci						(a->max_ports -	\
1258c2ecf20Sopenharmony_ci						a->mp_end_port)));	\
1268c2ecf20Sopenharmony_ci	a->mpa_tx.pkt_cnt++;						\
1278c2ecf20Sopenharmony_ci} while (0)
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/* SDIO Tx aggregation limit ? */
1308c2ecf20Sopenharmony_ci#define MP_TX_AGGR_PKT_LIMIT_REACHED(a)					\
1318c2ecf20Sopenharmony_ci			(a->mpa_tx.pkt_cnt == a->mpa_tx.pkt_aggr_limit)
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/* Reset SDIO Tx aggregation buffer parameters */
1348c2ecf20Sopenharmony_ci#define MP_TX_AGGR_BUF_RESET(a) do {					\
1358c2ecf20Sopenharmony_ci	a->mpa_tx.pkt_cnt = 0;						\
1368c2ecf20Sopenharmony_ci	a->mpa_tx.buf_len = 0;						\
1378c2ecf20Sopenharmony_ci	a->mpa_tx.ports = 0;						\
1388c2ecf20Sopenharmony_ci	a->mpa_tx.start_port = 0;					\
1398c2ecf20Sopenharmony_ci} while (0)
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/* SDIO Rx aggregation limit ? */
1428c2ecf20Sopenharmony_ci#define MP_RX_AGGR_PKT_LIMIT_REACHED(a)					\
1438c2ecf20Sopenharmony_ci			(a->mpa_rx.pkt_cnt == a->mpa_rx.pkt_aggr_limit)
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* SDIO Rx aggregation in progress ? */
1468c2ecf20Sopenharmony_ci#define MP_RX_AGGR_IN_PROGRESS(a) (a->mpa_rx.pkt_cnt > 0)
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci/* SDIO Rx aggregation buffer room for next packet ? */
1498c2ecf20Sopenharmony_ci#define MP_RX_AGGR_BUF_HAS_ROOM(a, rx_len)				\
1508c2ecf20Sopenharmony_ci			((a->mpa_rx.buf_len+rx_len) <= a->mpa_rx.buf_size)
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/* Reset SDIO Rx aggregation buffer parameters */
1538c2ecf20Sopenharmony_ci#define MP_RX_AGGR_BUF_RESET(a) do {					\
1548c2ecf20Sopenharmony_ci	a->mpa_rx.pkt_cnt = 0;						\
1558c2ecf20Sopenharmony_ci	a->mpa_rx.buf_len = 0;						\
1568c2ecf20Sopenharmony_ci	a->mpa_rx.ports = 0;						\
1578c2ecf20Sopenharmony_ci	a->mpa_rx.start_port = 0;					\
1588c2ecf20Sopenharmony_ci} while (0)
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/* data structure for SDIO MPA TX */
1618c2ecf20Sopenharmony_cistruct mwifiex_sdio_mpa_tx {
1628c2ecf20Sopenharmony_ci	/* multiport tx aggregation buffer pointer */
1638c2ecf20Sopenharmony_ci	u8 *buf;
1648c2ecf20Sopenharmony_ci	u32 buf_len;
1658c2ecf20Sopenharmony_ci	u32 pkt_cnt;
1668c2ecf20Sopenharmony_ci	u32 ports;
1678c2ecf20Sopenharmony_ci	u16 start_port;
1688c2ecf20Sopenharmony_ci	u8 enabled;
1698c2ecf20Sopenharmony_ci	u32 buf_size;
1708c2ecf20Sopenharmony_ci	u32 pkt_aggr_limit;
1718c2ecf20Sopenharmony_ci};
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_cistruct mwifiex_sdio_mpa_rx {
1748c2ecf20Sopenharmony_ci	u8 *buf;
1758c2ecf20Sopenharmony_ci	u32 buf_len;
1768c2ecf20Sopenharmony_ci	u32 pkt_cnt;
1778c2ecf20Sopenharmony_ci	u32 ports;
1788c2ecf20Sopenharmony_ci	u16 start_port;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	struct sk_buff **skb_arr;
1818c2ecf20Sopenharmony_ci	u32 *len_arr;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	u8 enabled;
1848c2ecf20Sopenharmony_ci	u32 buf_size;
1858c2ecf20Sopenharmony_ci	u32 pkt_aggr_limit;
1868c2ecf20Sopenharmony_ci};
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ciint mwifiex_bus_register(void);
1898c2ecf20Sopenharmony_civoid mwifiex_bus_unregister(void);
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_cistruct mwifiex_sdio_card_reg {
1928c2ecf20Sopenharmony_ci	u8 start_rd_port;
1938c2ecf20Sopenharmony_ci	u8 start_wr_port;
1948c2ecf20Sopenharmony_ci	u8 base_0_reg;
1958c2ecf20Sopenharmony_ci	u8 base_1_reg;
1968c2ecf20Sopenharmony_ci	u8 poll_reg;
1978c2ecf20Sopenharmony_ci	u8 host_int_enable;
1988c2ecf20Sopenharmony_ci	u8 host_int_rsr_reg;
1998c2ecf20Sopenharmony_ci	u8 host_int_status_reg;
2008c2ecf20Sopenharmony_ci	u8 host_int_mask_reg;
2018c2ecf20Sopenharmony_ci	u8 status_reg_0;
2028c2ecf20Sopenharmony_ci	u8 status_reg_1;
2038c2ecf20Sopenharmony_ci	u8 sdio_int_mask;
2048c2ecf20Sopenharmony_ci	u32 data_port_mask;
2058c2ecf20Sopenharmony_ci	u8 io_port_0_reg;
2068c2ecf20Sopenharmony_ci	u8 io_port_1_reg;
2078c2ecf20Sopenharmony_ci	u8 io_port_2_reg;
2088c2ecf20Sopenharmony_ci	u8 max_mp_regs;
2098c2ecf20Sopenharmony_ci	u8 rd_bitmap_l;
2108c2ecf20Sopenharmony_ci	u8 rd_bitmap_u;
2118c2ecf20Sopenharmony_ci	u8 rd_bitmap_1l;
2128c2ecf20Sopenharmony_ci	u8 rd_bitmap_1u;
2138c2ecf20Sopenharmony_ci	u8 wr_bitmap_l;
2148c2ecf20Sopenharmony_ci	u8 wr_bitmap_u;
2158c2ecf20Sopenharmony_ci	u8 wr_bitmap_1l;
2168c2ecf20Sopenharmony_ci	u8 wr_bitmap_1u;
2178c2ecf20Sopenharmony_ci	u8 rd_len_p0_l;
2188c2ecf20Sopenharmony_ci	u8 rd_len_p0_u;
2198c2ecf20Sopenharmony_ci	u8 card_misc_cfg_reg;
2208c2ecf20Sopenharmony_ci	u8 card_cfg_2_1_reg;
2218c2ecf20Sopenharmony_ci	u8 cmd_rd_len_0;
2228c2ecf20Sopenharmony_ci	u8 cmd_rd_len_1;
2238c2ecf20Sopenharmony_ci	u8 cmd_rd_len_2;
2248c2ecf20Sopenharmony_ci	u8 cmd_rd_len_3;
2258c2ecf20Sopenharmony_ci	u8 cmd_cfg_0;
2268c2ecf20Sopenharmony_ci	u8 cmd_cfg_1;
2278c2ecf20Sopenharmony_ci	u8 cmd_cfg_2;
2288c2ecf20Sopenharmony_ci	u8 cmd_cfg_3;
2298c2ecf20Sopenharmony_ci	u8 fw_dump_host_ready;
2308c2ecf20Sopenharmony_ci	u8 fw_dump_ctrl;
2318c2ecf20Sopenharmony_ci	u8 fw_dump_start;
2328c2ecf20Sopenharmony_ci	u8 fw_dump_end;
2338c2ecf20Sopenharmony_ci	u8 func1_dump_reg_start;
2348c2ecf20Sopenharmony_ci	u8 func1_dump_reg_end;
2358c2ecf20Sopenharmony_ci	u8 func1_scratch_reg;
2368c2ecf20Sopenharmony_ci	u8 func1_spec_reg_num;
2378c2ecf20Sopenharmony_ci	u8 func1_spec_reg_table[MWIFIEX_MAX_FUNC2_REG_NUM];
2388c2ecf20Sopenharmony_ci};
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_cistruct sdio_mmc_card {
2418c2ecf20Sopenharmony_ci	struct sdio_func *func;
2428c2ecf20Sopenharmony_ci	struct mwifiex_adapter *adapter;
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	struct completion fw_done;
2458c2ecf20Sopenharmony_ci	const char *firmware;
2468c2ecf20Sopenharmony_ci	const struct mwifiex_sdio_card_reg *reg;
2478c2ecf20Sopenharmony_ci	u8 max_ports;
2488c2ecf20Sopenharmony_ci	u8 mp_agg_pkt_limit;
2498c2ecf20Sopenharmony_ci	u16 tx_buf_size;
2508c2ecf20Sopenharmony_ci	u32 mp_tx_agg_buf_size;
2518c2ecf20Sopenharmony_ci	u32 mp_rx_agg_buf_size;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	u32 mp_rd_bitmap;
2548c2ecf20Sopenharmony_ci	u32 mp_wr_bitmap;
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	u16 mp_end_port;
2578c2ecf20Sopenharmony_ci	u32 mp_data_port_mask;
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	u8 curr_rd_port;
2608c2ecf20Sopenharmony_ci	u8 curr_wr_port;
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci	u8 *mp_regs;
2638c2ecf20Sopenharmony_ci	bool supports_sdio_new_mode;
2648c2ecf20Sopenharmony_ci	bool has_control_mask;
2658c2ecf20Sopenharmony_ci	bool can_dump_fw;
2668c2ecf20Sopenharmony_ci	bool fw_dump_enh;
2678c2ecf20Sopenharmony_ci	bool can_auto_tdls;
2688c2ecf20Sopenharmony_ci	bool can_ext_scan;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	struct mwifiex_sdio_mpa_tx mpa_tx;
2718c2ecf20Sopenharmony_ci	struct mwifiex_sdio_mpa_rx mpa_rx;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	struct work_struct work;
2748c2ecf20Sopenharmony_ci	unsigned long work_flags;
2758c2ecf20Sopenharmony_ci};
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_cistruct mwifiex_sdio_device {
2788c2ecf20Sopenharmony_ci	const char *firmware;
2798c2ecf20Sopenharmony_ci	const struct mwifiex_sdio_card_reg *reg;
2808c2ecf20Sopenharmony_ci	u8 max_ports;
2818c2ecf20Sopenharmony_ci	u8 mp_agg_pkt_limit;
2828c2ecf20Sopenharmony_ci	u16 tx_buf_size;
2838c2ecf20Sopenharmony_ci	u32 mp_tx_agg_buf_size;
2848c2ecf20Sopenharmony_ci	u32 mp_rx_agg_buf_size;
2858c2ecf20Sopenharmony_ci	bool supports_sdio_new_mode;
2868c2ecf20Sopenharmony_ci	bool has_control_mask;
2878c2ecf20Sopenharmony_ci	bool can_dump_fw;
2888c2ecf20Sopenharmony_ci	bool fw_dump_enh;
2898c2ecf20Sopenharmony_ci	bool can_auto_tdls;
2908c2ecf20Sopenharmony_ci	bool can_ext_scan;
2918c2ecf20Sopenharmony_ci};
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci/*
2948c2ecf20Sopenharmony_ci * .cmdrsp_complete handler
2958c2ecf20Sopenharmony_ci */
2968c2ecf20Sopenharmony_cistatic inline int mwifiex_sdio_cmdrsp_complete(struct mwifiex_adapter *adapter,
2978c2ecf20Sopenharmony_ci					       struct sk_buff *skb)
2988c2ecf20Sopenharmony_ci{
2998c2ecf20Sopenharmony_ci	dev_kfree_skb_any(skb);
3008c2ecf20Sopenharmony_ci	return 0;
3018c2ecf20Sopenharmony_ci}
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci/*
3048c2ecf20Sopenharmony_ci * .event_complete handler
3058c2ecf20Sopenharmony_ci */
3068c2ecf20Sopenharmony_cistatic inline int mwifiex_sdio_event_complete(struct mwifiex_adapter *adapter,
3078c2ecf20Sopenharmony_ci					      struct sk_buff *skb)
3088c2ecf20Sopenharmony_ci{
3098c2ecf20Sopenharmony_ci	dev_kfree_skb_any(skb);
3108c2ecf20Sopenharmony_ci	return 0;
3118c2ecf20Sopenharmony_ci}
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_cistatic inline bool
3148c2ecf20Sopenharmony_cimp_rx_aggr_port_limit_reached(struct sdio_mmc_card *card)
3158c2ecf20Sopenharmony_ci{
3168c2ecf20Sopenharmony_ci	u8 tmp;
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci	if (card->curr_rd_port < card->mpa_rx.start_port) {
3198c2ecf20Sopenharmony_ci		if (card->supports_sdio_new_mode)
3208c2ecf20Sopenharmony_ci			tmp = card->mp_end_port >> 1;
3218c2ecf20Sopenharmony_ci		else
3228c2ecf20Sopenharmony_ci			tmp = card->mp_agg_pkt_limit;
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci		if (((card->max_ports - card->mpa_rx.start_port) +
3258c2ecf20Sopenharmony_ci		    card->curr_rd_port) >= tmp)
3268c2ecf20Sopenharmony_ci			return true;
3278c2ecf20Sopenharmony_ci	}
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	if (!card->supports_sdio_new_mode)
3308c2ecf20Sopenharmony_ci		return false;
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	if ((card->curr_rd_port - card->mpa_rx.start_port) >=
3338c2ecf20Sopenharmony_ci	    (card->mp_end_port >> 1))
3348c2ecf20Sopenharmony_ci		return true;
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	return false;
3378c2ecf20Sopenharmony_ci}
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_cistatic inline bool
3408c2ecf20Sopenharmony_cimp_tx_aggr_port_limit_reached(struct sdio_mmc_card *card)
3418c2ecf20Sopenharmony_ci{
3428c2ecf20Sopenharmony_ci	u16 tmp;
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	if (card->curr_wr_port < card->mpa_tx.start_port) {
3458c2ecf20Sopenharmony_ci		if (card->supports_sdio_new_mode)
3468c2ecf20Sopenharmony_ci			tmp = card->mp_end_port >> 1;
3478c2ecf20Sopenharmony_ci		else
3488c2ecf20Sopenharmony_ci			tmp = card->mp_agg_pkt_limit;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci		if (((card->max_ports - card->mpa_tx.start_port) +
3518c2ecf20Sopenharmony_ci		    card->curr_wr_port) >= tmp)
3528c2ecf20Sopenharmony_ci			return true;
3538c2ecf20Sopenharmony_ci	}
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	if (!card->supports_sdio_new_mode)
3568c2ecf20Sopenharmony_ci		return false;
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	if ((card->curr_wr_port - card->mpa_tx.start_port) >=
3598c2ecf20Sopenharmony_ci	    (card->mp_end_port >> 1))
3608c2ecf20Sopenharmony_ci		return true;
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci	return false;
3638c2ecf20Sopenharmony_ci}
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci/* Prepare to copy current packet from card to SDIO Rx aggregation buffer */
3668c2ecf20Sopenharmony_cistatic inline void mp_rx_aggr_setup(struct sdio_mmc_card *card,
3678c2ecf20Sopenharmony_ci				    u16 rx_len, u8 port)
3688c2ecf20Sopenharmony_ci{
3698c2ecf20Sopenharmony_ci	card->mpa_rx.buf_len += rx_len;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	if (!card->mpa_rx.pkt_cnt)
3728c2ecf20Sopenharmony_ci		card->mpa_rx.start_port = port;
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci	if (card->supports_sdio_new_mode) {
3758c2ecf20Sopenharmony_ci		card->mpa_rx.ports |= (1 << port);
3768c2ecf20Sopenharmony_ci	} else {
3778c2ecf20Sopenharmony_ci		if (card->mpa_rx.start_port <= port)
3788c2ecf20Sopenharmony_ci			card->mpa_rx.ports |= 1 << (card->mpa_rx.pkt_cnt);
3798c2ecf20Sopenharmony_ci		else
3808c2ecf20Sopenharmony_ci			card->mpa_rx.ports |= 1 << (card->mpa_rx.pkt_cnt + 1);
3818c2ecf20Sopenharmony_ci	}
3828c2ecf20Sopenharmony_ci	card->mpa_rx.skb_arr[card->mpa_rx.pkt_cnt] = NULL;
3838c2ecf20Sopenharmony_ci	card->mpa_rx.len_arr[card->mpa_rx.pkt_cnt] = rx_len;
3848c2ecf20Sopenharmony_ci	card->mpa_rx.pkt_cnt++;
3858c2ecf20Sopenharmony_ci}
3868c2ecf20Sopenharmony_ci#endif /* _MWIFIEX_SDIO_H */
387