mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Lin <yu-hao.lin@nxp.com>
To: linux-wireless@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kvalo@kernel.org,
	johannes@sipsolutions.net, briannorris@chromium.org,
	francesco@dolcini.it, tsung-hsien.hsieh@nxp.com,
	David Lin <yu-hao.lin@nxp.com>
Subject: [PATCH v2 27/43] wifi: nxpwifi: add sdio.h
Date: Fri,  9 Aug 2024 17:45:17 +0800	[thread overview]
Message-ID: <20240809094533.1660-28-yu-hao.lin@nxp.com> (raw)
In-Reply-To: <20240809094533.1660-1-yu-hao.lin@nxp.com>

---
 drivers/net/wireless/nxp/nxpwifi/sdio.h | 340 ++++++++++++++++++++++++
 1 file changed, 340 insertions(+)
 create mode 100644 drivers/net/wireless/nxp/nxpwifi/sdio.h

diff --git a/drivers/net/wireless/nxp/nxpwifi/sdio.h b/drivers/net/wireless/nxp/nxpwifi/sdio.h
new file mode 100644
index 000000000000..de5c884a5b14
--- /dev/null
+++ b/drivers/net/wireless/nxp/nxpwifi/sdio.h
@@ -0,0 +1,340 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * NXP Wireless LAN device driver: SDIO specific definitions
+ *
+ * Copyright 2011-2024 NXP
+ */
+
+#ifndef	_NXPWIFI_SDIO_H
+#define	_NXPWIFI_SDIO_H
+
+#include "main.h"
+
+#define IW61X_SDIO_FW_NAME     "nxp/sd_w61x_v1.bin.se"
+
+#define BLOCK_MODE	1
+#define BYTE_MODE	0
+
+#define NXPWIFI_SDIO_IO_PORT_MASK	0xfffff
+
+#define NXPWIFI_SDIO_BYTE_MODE_MASK	0x80000000
+
+#define NXPWIFI_MAX_FUNC2_REG_NUM	13
+#define NXPWIFI_SDIO_SCRATCH_SIZE	10
+
+#define SDIO_MPA_ADDR_BASE		0x1000
+
+#define CMD_PORT_UPLD_INT_MASK		(0x1U << 6)
+#define CMD_PORT_DNLD_INT_MASK		(0x1U << 7)
+#define HOST_TERM_CMD53			(0x1U << 2)
+#define REG_PORT			0
+#define MEM_PORT			0x10000
+
+#define CMD53_NEW_MODE			(0x1U << 0)
+#define CMD_PORT_RD_LEN_EN		(0x1U << 2)
+#define CMD_PORT_AUTO_EN		(0x1U << 0)
+#define CMD_PORT_SLCT			0x8000
+#define UP_LD_CMD_PORT_HOST_INT_STATUS	(0x40U)
+#define DN_LD_CMD_PORT_HOST_INT_STATUS	(0x80U)
+
+#define NXPWIFI_MP_AGGR_BSIZE_32K	(32768)
+/* we leave one block of 256 bytes for DMA alignment*/
+#define NXPWIFI_MP_AGGR_BSIZE_MAX	(65280)
+
+/* Misc. Config Register : Auto Re-enable interrupts */
+#define AUTO_RE_ENABLE_INT		BIT(4)
+
+/* Host Control Registers : Configuration */
+#define CONFIGURATION_REG		0x00
+/* Host Control Registers : Host power up */
+#define HOST_POWER_UP			(0x1U << 1)
+
+/* Host Control Registers : Upload host interrupt mask */
+#define UP_LD_HOST_INT_MASK		(0x1U)
+/* Host Control Registers : Download host interrupt mask */
+#define DN_LD_HOST_INT_MASK		(0x2U)
+
+/* Host Control Registers : Upload host interrupt status */
+#define UP_LD_HOST_INT_STATUS		(0x1U)
+/* Host Control Registers : Download host interrupt status */
+#define DN_LD_HOST_INT_STATUS		(0x2U)
+
+/* Host Control Registers : Host interrupt status */
+#define CARD_INT_STATUS_REG		0x28
+
+/* Card Control Registers : Card I/O ready */
+#define CARD_IO_READY                   (0x1U << 3)
+/* Card Control Registers : Download card ready */
+#define DN_LD_CARD_RDY                  (0x1U << 0)
+
+/* Max retry number of CMD53 write */
+#define MAX_WRITE_IOMEM_RETRY		2
+
+/* SDIO Tx aggregation in progress ? */
+#define MP_TX_AGGR_IN_PROGRESS(a) ((a)->mpa_tx.pkt_cnt > 0)
+
+/* SDIO Tx aggregation buffer room for next packet ? */
+#define MP_TX_AGGR_BUF_HAS_ROOM(a, len) ({ \
+	typeof(a) (_a) = a; \
+	(((_a)->mpa_tx.buf_len + (len))	<= (_a)->mpa_tx.buf_size); \
+	})
+
+/* Copy current packet (SDIO Tx aggregation buffer) to SDIO buffer */
+#define MP_TX_AGGR_BUF_PUT(a, payload, pkt_len, port) do {		\
+	typeof(a) (_a) = (a);						\
+	typeof(pkt_len) (_pkt_len) = pkt_len;				\
+	typeof(port) (_port) = port;					\
+	memmove(&(_a)->mpa_tx.buf[(_a)->mpa_tx.buf_len],		\
+		payload, (_pkt_len));					\
+	(_a)->mpa_tx.buf_len += (_pkt_len);				\
+	if (!(_a)->mpa_tx.pkt_cnt)					\
+		(_a)->mpa_tx.start_port = (_port);			\
+	if ((_a)->mpa_tx.start_port <= (_port))				\
+		(_a)->mpa_tx.ports |= (1 << ((_a)->mpa_tx.pkt_cnt));	\
+	else								\
+		(_a)->mpa_tx.ports |= (1 << ((_a)->mpa_tx.pkt_cnt + 1 +	\
+					     ((_a)->max_ports -		\
+					      (_a)->mp_end_port)));	\
+	(_a)->mpa_tx.pkt_cnt++;						\
+} while (0)
+
+/* SDIO Tx aggregation limit ? */
+#define MP_TX_AGGR_PKT_LIMIT_REACHED(a) ({				\
+	typeof(a) (_a) = a;						\
+	((_a)->mpa_tx.pkt_cnt == (_a)->mpa_tx.pkt_aggr_limit);		\
+	})
+
+/* Reset SDIO Tx aggregation buffer parameters */
+#define MP_TX_AGGR_BUF_RESET(a) do {					\
+	typeof(a) (_a) = (a);						\
+	(_a)->mpa_tx.pkt_cnt = 0;					\
+	(_a)->mpa_tx.buf_len = 0;					\
+	(_a)->mpa_tx.ports = 0;						\
+	(_a)->mpa_tx.start_port = 0;					\
+} while (0)
+
+/* SDIO Rx aggregation limit ? */
+#define MP_RX_AGGR_PKT_LIMIT_REACHED(a)	({				\
+	typeof(a) (_a) = a;						\
+	((_a)->mpa_rx.pkt_cnt == (_a)->mpa_rx.pkt_aggr_limit);		\
+	})
+
+/* SDIO Rx aggregation in progress ? */
+#define MP_RX_AGGR_IN_PROGRESS(a) ((a)->mpa_rx.pkt_cnt > 0)
+
+/* SDIO Rx aggregation buffer room for next packet ? */
+#define MP_RX_AGGR_BUF_HAS_ROOM(a, rx_len) ({				\
+	typeof(a) (_a) = a;						\
+	((((_a)->mpa_rx.buf_len + (rx_len))) <= (_a)->mpa_rx.buf_size);	\
+	})
+
+/* Reset SDIO Rx aggregation buffer parameters */
+#define MP_RX_AGGR_BUF_RESET(a) do {					\
+	typeof(a) (_a) = (a);						\
+	(_a)->mpa_rx.pkt_cnt = 0;					\
+	(_a)->mpa_rx.buf_len = 0;					\
+	(_a)->mpa_rx.ports = 0;						\
+	(_a)->mpa_rx.start_port = 0;					\
+} while (0)
+
+/* data structure for SDIO MPA TX */
+struct nxpwifi_sdio_mpa_tx {
+	/* multiport tx aggregation buffer pointer */
+	u8 *buf;
+	u32 buf_len;
+	u32 pkt_cnt;
+	u32 ports;
+	u16 start_port;
+	u8 enabled;
+	u32 buf_size;
+	u32 pkt_aggr_limit;
+};
+
+struct nxpwifi_sdio_mpa_rx {
+	u8 *buf;
+	u32 buf_len;
+	u32 pkt_cnt;
+	u32 ports;
+	u16 start_port;
+	u32 *len_arr;
+	u8 enabled;
+	u32 buf_size;
+	u32 pkt_aggr_limit;
+};
+
+int nxpwifi_bus_register(void);
+void nxpwifi_bus_unregister(void);
+
+struct nxpwifi_sdio_card_reg {
+	u8 start_rd_port;
+	u8 start_wr_port;
+	u8 base_0_reg;
+	u8 base_1_reg;
+	u8 poll_reg;
+	u8 host_int_enable;
+	u8 host_int_rsr_reg;
+	u8 host_int_status_reg;
+	u8 host_int_mask_reg;
+	u8 host_strap_reg;
+	u8 host_strap_mask;
+	u8 host_strap_value;
+	u8 status_reg_0;
+	u8 status_reg_1;
+	u8 sdio_int_mask;
+	u32 data_port_mask;
+	u8 io_port_0_reg;
+	u8 io_port_1_reg;
+	u8 io_port_2_reg;
+	u8 max_mp_regs;
+	u8 rd_bitmap_l;
+	u8 rd_bitmap_u;
+	u8 rd_bitmap_1l;
+	u8 rd_bitmap_1u;
+	u8 wr_bitmap_l;
+	u8 wr_bitmap_u;
+	u8 wr_bitmap_1l;
+	u8 wr_bitmap_1u;
+	u8 rd_len_p0_l;
+	u8 rd_len_p0_u;
+	u8 card_misc_cfg_reg;
+	u8 card_cfg_2_1_reg;
+	u8 cmd_rd_len_0;
+	u8 cmd_rd_len_1;
+	u8 cmd_rd_len_2;
+	u8 cmd_rd_len_3;
+	u8 cmd_cfg_0;
+	u8 cmd_cfg_1;
+	u8 cmd_cfg_2;
+	u8 cmd_cfg_3;
+	u8 fw_dump_host_ready;
+	u8 fw_dump_ctrl;
+	u8 fw_dump_start;
+	u8 fw_dump_end;
+	u8 func1_dump_reg_start;
+	u8 func1_dump_reg_end;
+	u8 func1_scratch_reg;
+	u8 func1_spec_reg_num;
+	u8 func1_spec_reg_table[NXPWIFI_MAX_FUNC2_REG_NUM];
+};
+
+struct sdio_mmc_card {
+	struct sdio_func *func;
+	struct nxpwifi_adapter *adapter;
+
+	struct completion fw_done;
+	const char *firmware;
+	const char *firmware_sdiouart;
+	const struct nxpwifi_sdio_card_reg *reg;
+	u8 max_ports;
+	u8 mp_agg_pkt_limit;
+	u16 tx_buf_size;
+	u32 mp_tx_agg_buf_size;
+	u32 mp_rx_agg_buf_size;
+
+	u32 mp_rd_bitmap;
+	u32 mp_wr_bitmap;
+
+	u16 mp_end_port;
+	u32 mp_data_port_mask;
+
+	u8 curr_rd_port;
+	u8 curr_wr_port;
+
+	u8 *mp_regs;
+	bool can_dump_fw;
+	bool fw_dump_enh;
+	bool can_ext_scan;
+
+	struct nxpwifi_sdio_mpa_tx mpa_tx;
+	struct nxpwifi_sdio_mpa_rx mpa_rx;
+
+	struct work_struct work;
+	unsigned long work_flags;
+};
+
+struct nxpwifi_sdio_device {
+	const char *firmware;
+	const char *firmware_sdiouart;
+	const struct nxpwifi_sdio_card_reg *reg;
+	u8 max_ports;
+	u8 mp_agg_pkt_limit;
+	u16 tx_buf_size;
+	u32 mp_tx_agg_buf_size;
+	u32 mp_rx_agg_buf_size;
+	bool can_dump_fw;
+	bool fw_dump_enh;
+	bool can_ext_scan;
+};
+
+/* .cmdrsp_complete handler
+ */
+static inline int nxpwifi_sdio_cmdrsp_complete(struct nxpwifi_adapter *adapter,
+					       struct sk_buff *skb)
+{
+	dev_kfree_skb_any(skb);
+	return 0;
+}
+
+/* .event_complete handler
+ */
+static inline int nxpwifi_sdio_event_complete(struct nxpwifi_adapter *adapter,
+					      struct sk_buff *skb)
+{
+	dev_kfree_skb_any(skb);
+	return 0;
+}
+
+static inline bool
+mp_rx_aggr_port_limit_reached(struct sdio_mmc_card *card)
+{
+	u8 tmp;
+
+	if (card->curr_rd_port < card->mpa_rx.start_port) {
+		tmp = card->mp_end_port >> 1;
+
+		if (((card->max_ports - card->mpa_rx.start_port) +
+		    card->curr_rd_port) >= tmp)
+			return true;
+	}
+
+	if ((card->curr_rd_port - card->mpa_rx.start_port) >=
+	    (card->mp_end_port >> 1))
+		return true;
+
+	return false;
+}
+
+static inline bool
+mp_tx_aggr_port_limit_reached(struct sdio_mmc_card *card)
+{
+	u16 tmp;
+
+	if (card->curr_wr_port < card->mpa_tx.start_port) {
+		tmp = card->mp_end_port >> 1;
+
+		if (((card->max_ports - card->mpa_tx.start_port) +
+		    card->curr_wr_port) >= tmp)
+			return true;
+	}
+
+	if ((card->curr_wr_port - card->mpa_tx.start_port) >=
+	    (card->mp_end_port >> 1))
+		return true;
+
+	return false;
+}
+
+/* Prepare to copy current packet from card to SDIO Rx aggregation buffer */
+static inline void mp_rx_aggr_setup(struct sdio_mmc_card *card,
+				    u16 rx_len, u8 port)
+{
+	card->mpa_rx.buf_len += rx_len;
+
+	if (!card->mpa_rx.pkt_cnt)
+		card->mpa_rx.start_port = port;
+
+	card->mpa_rx.ports |= (1 << port);
+	card->mpa_rx.len_arr[card->mpa_rx.pkt_cnt] = rx_len;
+	card->mpa_rx.pkt_cnt++;
+}
+#endif /* _NXPWIFI_SDIO_H */
-- 
2.34.1


  parent reply	other threads:[~2024-08-09  9:47 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-09  9:44 [PATCH v2 00/43] wifi: nxpwifi: create nxpwifi to support iw61x David Lin
2024-08-09  9:44 ` [PATCH v2 01/43] wifi: nxpwifi: add 11ac.c David Lin
2024-08-09  9:44 ` [PATCH v2 02/43] wifi: nxpwifi: add 11ac.h David Lin
2024-08-09  9:44 ` [PATCH v2 03/43] wifi: nxpwifi: add 11h.c David Lin
2024-08-09  9:44 ` [PATCH v2 04/43] wifi: nxpwifi: add 11n_aggr.c David Lin
2024-08-09  9:44 ` [PATCH v2 05/43] wifi: nxpwifi: add 11n_aggr.h David Lin
2024-08-09  9:44 ` [PATCH v2 06/43] wifi: nxpwifi: add 11n.c David Lin
2024-08-09  9:44 ` [PATCH v2 07/43] wifi: nxpwifi: add 11n.h David Lin
2024-08-09  9:44 ` [PATCH v2 08/43] wifi: nxpwifi: add 11n_rxreorder.c David Lin
2024-08-09  9:44 ` [PATCH v2 09/43] wifi: nxpwifi: add 11n_rxreorder.h David Lin
2024-08-09  9:45 ` [PATCH v2 10/43] wifi: nxpwifi: add cfg80211.c David Lin
2024-08-09  9:45 ` [PATCH v2 11/43] wifi: nxpwifi: add cfg80211.h David Lin
2024-08-09  9:45 ` [PATCH v2 12/43] wifi: nxpwifi: add cfg.h David Lin
2024-08-09  9:45 ` [PATCH v2 13/43] wifi: nxpwifi: add cfp.c David Lin
2024-08-09  9:45 ` [PATCH v2 14/43] wifi: nxpwifi: add cmdevt.c David Lin
2024-08-09  9:45 ` [PATCH v2 15/43] wifi: nxpwifi: add cmdevt.h David Lin
2024-08-09  9:45 ` [PATCH v2 16/43] wifi: nxpwifi: add debugfs.c David Lin
2024-08-09  9:45 ` [PATCH v2 17/43] wifi: nxpwifi: add decl.h David Lin
2024-08-09  9:45 ` [PATCH v2 18/43] wifi: nxpwifi: add ethtool.c David Lin
2024-08-09  9:45 ` [PATCH v2 19/43] wifi: nxpwifi: add fw.h David Lin
2024-08-09  9:45 ` [PATCH v2 20/43] wifi: nxpwifi: add ie.c David Lin
2024-08-09  9:45 ` [PATCH v2 21/43] wifi: nxpwifi: add init.c David Lin
2024-08-09  9:45 ` [PATCH v2 22/43] wifi: nxpwifi: add join.c David Lin
2024-08-09  9:45 ` [PATCH v2 23/43] wifi: nxpwifi: add main.c David Lin
2024-08-09  9:45 ` [PATCH v2 24/43] wifi: nxpwifi: add main.h David Lin
2024-08-09  9:45 ` [PATCH v2 25/43] wifi: nxpwifi: add scan.c David Lin
2024-08-09  9:45 ` [PATCH v2 26/43] wifi: nxpwifi: add sdio.c David Lin
2024-08-09  9:45 ` David Lin [this message]
2024-08-09  9:45 ` [PATCH v2 28/43] wifi: nxpwifi: add sta_cfg.c David Lin
2024-08-09  9:45 ` [PATCH v2 29/43] wifi: nxpwifi: add sta_cmd.c David Lin
2024-08-09  9:45 ` [PATCH v2 30/43] wifi: nxpwifi: add sta_event.c David Lin
2024-08-09  9:45 ` [PATCH v2 31/43] wifi: nxpwifi: add sta_rx.c David Lin
2024-08-09  9:45 ` [PATCH v2 32/43] wifi: nxpwifi: add sta_tx.c David Lin
2024-08-09  9:45 ` [PATCH v2 33/43] wifi: nxpwifi: add txrx.c David Lin
2024-08-09  9:45 ` [PATCH v2 34/43] wifi: nxpwifi: add uap_cmd.c David Lin
2024-08-09  9:45 ` [PATCH v2 35/43] wifi: nxpwifi: add uap_event.c David Lin
2024-08-09  9:45 ` [PATCH v2 36/43] wifi: nxpwifi: add uap_txrx.c David Lin
2024-08-09  9:45 ` [PATCH v2 37/43] wifi: nxpwifi: add util.c David Lin
2024-08-09  9:45 ` [PATCH v2 38/43] wifi: nxpwifi: add util.h David Lin
2024-08-09  9:45 ` [PATCH v2 39/43] wifi: nxpwifi: add wmm.c David Lin
2024-08-09  9:45 ` [PATCH v2 40/43] wifi: nxpwifi: add wmm.h David Lin
2024-08-14 18:48   ` Greg KH
2024-08-15  1:52     ` [EXT] " David Lin
2024-08-15  5:08       ` Greg KH
2024-08-15  6:20         ` David Lin
2024-08-15  6:23           ` David Lin
2024-08-15  6:57           ` Greg KH
2024-08-15  9:51           ` Kalle Valo
2024-08-16  1:39             ` David Lin
2024-08-15  9:43         ` Kalle Valo
2024-08-15  9:58           ` Greg KH
2024-08-15 11:44             ` Kalle Valo
2024-08-09  9:45 ` [PATCH v2 41/43] wifi: nxpwifi: add nxp sdio vendor id and iw61x device id David Lin
2024-08-09  9:45 ` [PATCH v2 42/43] wifi: nxpwifi: add Makefile and Kconfig files for nxpwifi compilation David Lin
2024-08-09  9:45 ` [PATCH v2 43/43] wifi: nxpwifi: add nxpwifi related information to MAINTAINERS David Lin
2024-08-14  3:47 ` [PATCH v2 00/43] wifi: nxpwifi: create nxpwifi to support iw61x David Lin
2024-08-15  9:35   ` Kalle Valo
2024-08-16  5:32     ` [EXT] " David Lin
2024-08-22 12:56 ` Sascha Hauer
2024-08-24 13:48   ` Francesco Dolcini
2024-08-26  2:30     ` [EXT] " David Lin
2024-08-26  7:43     ` Sascha Hauer
2024-08-25 20:37   ` Calvin Owens
2024-08-26  2:33     ` [EXT] " David Lin
2024-08-26  2:49       ` Calvin Owens
2024-08-26  2:56         ` David Lin
2024-08-26  5:30           ` Calvin Owens
2024-08-26  5:49             ` David Lin
2024-10-17  7:48   ` Kalle Valo
2024-12-11  3:52     ` [EXT] " David Lin
2025-01-10  5:31       ` Jeff Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240809094533.1660-28-yu-hao.lin@nxp.com \
    --to=yu-hao.lin@nxp.com \
    --cc=briannorris@chromium.org \
    --cc=francesco@dolcini.it \
    --cc=johannes@sipsolutions.net \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=tsung-hsien.hsieh@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®