From: Krzysztof Kozlowski <krzk@kernel.org>
To: Jeff Chen <jeff.chen_1@nxp.com>, linux-wireless@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, briannorris@chromium.org,
johannes@sipsolutions.net, francesco@dolcini.it,
tsung-hsien.hsieh@nxp.com, s.hauer@pengutronix.de
Subject: Re: [PATCH v8 19/22] wifi: nxpwifi: add initial SDIO bus driver support
Date: Fri, 5 Dec 2025 08:51:12 +0100 [thread overview]
Message-ID: <3fc73b5d-1de7-41bb-b9ca-2878f311c6fc@kernel.org> (raw)
In-Reply-To: <20251205065545.3325032-20-jeff.chen_1@nxp.com>
On 05/12/2025 07:55, Jeff Chen wrote:
> +static const struct of_device_id nxpwifi_sdio_of_match_table[] __maybe_unused = {
> + { .compatible = "nxp,iw61x" },
> + { }
> +};
> +
> +/*
> + * This function parse device tree node using mmc subnode devicetree API.
> + * The device node is saved in card->plt_of_node.
> + * if the device tree node exist and include interrupts attributes, this
> + * function will also request platform specific wakeup interrupt.
> + */
> +static int nxpwifi_sdio_probe_of(struct device *dev)
> +{
> + if (!of_match_node(nxpwifi_sdio_of_match_table, dev->of_node)) {
> + dev_err(dev, "required compatible string missing\n");
What? How did you probe otherwise?
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +/*
> + * SDIO probe.
> + *
> + * This function probes an nxpwifi device and registers it. It allocates
> + * the card structure, enables SDIO function number and initiates the
> + * device registration and initialization procedure by adding a logical
> + * interface.
> + */
> +static int
> +nxpwifi_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id)
> +{
> + int ret;
> + struct sdio_mmc_card *card = NULL;
> +
> + pr_debug("info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n",
> + func->vendor, func->device, func->class, func->num);
NAK. Don't post such code. Look how drivers are supposed to use debug
functions.
And entrance to probe IS NEVER, NEVER debugged.
> +
> + card = devm_kzalloc(&func->dev, sizeof(*card), GFP_KERNEL);
> + if (!card)
> + return -ENOMEM;
> +
> + init_completion(&card->fw_done);
> +
> + card->func = func;
> +
> + func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
> +
> + if (id->driver_data) {
> + struct nxpwifi_sdio_device *data = (void *)id->driver_data;
> +
> + card->firmware = data->firmware;
> + card->firmware_sdiouart = data->firmware_sdiouart;
> + card->reg = data->reg;
> + card->max_ports = data->max_ports;
> + card->mp_agg_pkt_limit = data->mp_agg_pkt_limit;
> + card->tx_buf_size = data->tx_buf_size;
> + card->mp_tx_agg_buf_size = data->mp_tx_agg_buf_size;
> + card->mp_rx_agg_buf_size = data->mp_rx_agg_buf_size;
> + card->can_dump_fw = data->can_dump_fw;
> + card->fw_dump_enh = data->fw_dump_enh;
> + card->can_ext_scan = data->can_ext_scan;
> + INIT_WORK(&card->work, nxpwifi_sdio_work);
> + }
> +
> + sdio_claim_host(func);
> + ret = sdio_enable_func(func);
> + sdio_release_host(func);
> +
> + if (ret) {
> + dev_err(&func->dev, "failed to enable function\n");
> + return ret;
> + }
> +
> + /* device tree node parsing and platform specific configuration*/
> + if (func->dev.of_node) {
> + ret = nxpwifi_sdio_probe_of(&func->dev);
> + if (ret)
> + goto err_disable;
> + }
> +
> + ret = nxpwifi_add_card(card, &card->fw_done, &sdio_ops,
> + NXPWIFI_SDIO, &func->dev);
> + if (ret) {
> + dev_err(&func->dev, "add card failed\n");
> + goto err_disable;
> + }
> +
> + return 0;
> +
> +err_disable:
> + sdio_claim_host(func);
> + sdio_disable_func(func);
> + sdio_release_host(func);
> +
> + return ret;
> +}
> +
> +/*
> + * SDIO resume.
> + *
> + * Kernel needs to suspend all functions separately. Therefore all
> + * registered functions must have drivers with suspend and resume
> + * methods. Failing that the kernel simply removes the whole card.
> + *
> + * If already not resumed, this function turns on the traffic and
> + * sends a host sleep cancel request to the firmware.
> + */
> +static int nxpwifi_sdio_resume(struct device *dev)
> +{
> + struct sdio_func *func = dev_to_sdio_func(dev);
> + struct sdio_mmc_card *card;
> + struct nxpwifi_adapter *adapter;
> +
> + card = sdio_get_drvdata(func);
> + if (!card || !card->adapter) {
> + nxpwifi_dbg(adapter, ERROR, "resume: invalid card or adapter\n");
> + return 0;
> + }
> +
> + adapter = card->adapter;
> +
> + if (!test_bit(NXPWIFI_IS_SUSPENDED, &adapter->work_flags)) {
> + nxpwifi_dbg(adapter, WARN,
> + "device already resumed\n");
> + return 0;
> + }
> +
> + clear_bit(NXPWIFI_IS_SUSPENDED, &adapter->work_flags);
> +
> + /* Disable Host Sleep */
> + nxpwifi_cancel_hs(nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_STA),
> + NXPWIFI_SYNC_CMD);
> +
> + nxpwifi_disable_wake(adapter);
> +
> + return 0;
> +}
> +
> +/* Write data into SDIO card register. Caller claims SDIO device. */
> +static int
> +nxpwifi_write_reg_locked(struct sdio_func *func, u32 reg, u8 data)
> +{
> + int ret;
> +
> + sdio_writeb(func, data, reg, &ret);
> + return ret;
> +}
> +
> +/* This function writes data into SDIO card register.
> + */
> +static int
> +nxpwifi_write_reg(struct nxpwifi_adapter *adapter, u32 reg, u8 data)
> +{
> + struct sdio_mmc_card *card = adapter->card;
> + int ret;
> +
> + sdio_claim_host(card->func);
> + ret = nxpwifi_write_reg_locked(card->func, reg, data);
> + sdio_release_host(card->func);
> +
> + return ret;
> +}
> +
> +/* This function reads data from SDIO card register.
> + */
> +static int
> +nxpwifi_read_reg(struct nxpwifi_adapter *adapter, u32 reg, u8 *data)
> +{
> + struct sdio_mmc_card *card = adapter->card;
> + int ret;
> + u8 val;
> +
> + sdio_claim_host(card->func);
> + val = sdio_readb(card->func, reg, &ret);
> + sdio_release_host(card->func);
> +
> + *data = val;
> +
> + return ret;
> +}
> +
> +/*
> + * This function writes multiple data into SDIO card memory.
> + *
> + * This does not work in suspended mode.
> + */
> +static int
> +nxpwifi_write_data_sync(struct nxpwifi_adapter *adapter,
> + u8 *buffer, u32 pkt_len, u32 port)
> +{
> + struct sdio_mmc_card *card = adapter->card;
> + int ret;
> + u8 blk_mode =
> + (port & NXPWIFI_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
> + u32 blk_size = (blk_mode == BLOCK_MODE) ? NXPWIFI_SDIO_BLOCK_SIZE : 1;
> + u32 blk_cnt =
> + (blk_mode ==
> + BLOCK_MODE) ? (pkt_len /
> + NXPWIFI_SDIO_BLOCK_SIZE) : pkt_len;
> + u32 ioport = (port & NXPWIFI_SDIO_IO_PORT_MASK);
> +
> + if (test_bit(NXPWIFI_IS_SUSPENDED, &adapter->work_flags)) {
> + nxpwifi_dbg(adapter, ERROR,
> + "%s: not allowed while suspended\n", __func__);
> + return -EPERM;
> + }
> +
> + sdio_claim_host(card->func);
> +
> + ret = sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size);
> +
> + sdio_release_host(card->func);
> +
> + return ret;
> +}
> +
> +/* This function reads multiple data from SDIO card memory.
> + */
> +static int nxpwifi_read_data_sync(struct nxpwifi_adapter *adapter, u8 *buffer,
> + u32 len, u32 port, u8 claim)
> +{
> + struct sdio_mmc_card *card = adapter->card;
> + int ret;
> + u8 blk_mode = (port & NXPWIFI_SDIO_BYTE_MODE_MASK) ? BYTE_MODE
> + : BLOCK_MODE;
> + u32 blk_size = (blk_mode == BLOCK_MODE) ? NXPWIFI_SDIO_BLOCK_SIZE : 1;
> + u32 blk_cnt = (blk_mode == BLOCK_MODE) ? (len / NXPWIFI_SDIO_BLOCK_SIZE)
> + : len;
> + u32 ioport = (port & NXPWIFI_SDIO_IO_PORT_MASK);
> +
> + if (claim)
> + sdio_claim_host(card->func);
> +
> + ret = sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size);
> +
> + if (claim)
> + sdio_release_host(card->func);
> +
> + return ret;
> +}
> +
> +/* This function reads the firmware status.
> + */
> +static int
> +nxpwifi_sdio_read_fw_status(struct nxpwifi_adapter *adapter, u16 *dat)
> +{
> + struct sdio_mmc_card *card = adapter->card;
> + const struct nxpwifi_sdio_card_reg *reg = card->reg;
> + u8 fws0, fws1;
> + int ret;
> +
> + ret = nxpwifi_read_reg(adapter, reg->status_reg_0, &fws0);
> + if (ret)
> + return ret;
> +
> + ret = nxpwifi_read_reg(adapter, reg->status_reg_1, &fws1);
> + if (ret)
> + return ret;
> +
> + *dat = (u16)((fws1 << 8) | fws0);
> + return ret;
> +}
> +
> +/* This function checks the firmware status in card.
> + */
> +static int nxpwifi_check_fw_status(struct nxpwifi_adapter *adapter,
> + u32 poll_num)
> +{
> + int ret = 0;
> + u16 firmware_stat = 0;
> + u32 tries;
> +
> + for (tries = 0; tries < poll_num; tries++) {
> + ret = nxpwifi_sdio_read_fw_status(adapter, &firmware_stat);
> + if (ret)
> + continue;
> + if (firmware_stat == FIRMWARE_READY_SDIO) {
> + ret = 0;
> + break;
> + }
> +
> + msleep(100);
> + ret = -EPERM;
> + }
> +
> + if (firmware_stat == FIRMWARE_READY_SDIO)
> + /*
> + * firmware might pretend to be ready, when it's not.
> + * Wait a little bit more as a workaround.
> + */
> + msleep(100);
> +
> + return ret;
> +}
> +
> +/* This function checks if WLAN is the winner.
> + */
> +static int nxpwifi_check_winner_status(struct nxpwifi_adapter *adapter)
> +{
> + int ret;
> + u8 winner = 0;
> + struct sdio_mmc_card *card = adapter->card;
> +
> + ret = nxpwifi_read_reg(adapter, card->reg->status_reg_0, &winner);
> + if (ret)
> + return ret;
> +
> + if (winner)
> + adapter->winner = 0;
> + else
> + adapter->winner = 1;
> +
> + return ret;
> +}
> +
> +/*
> + * SDIO remove.
> + *
> + * This function removes the interface and frees up the card structure.
> + */
> +static void
> +nxpwifi_sdio_remove(struct sdio_func *func)
> +{
> + struct sdio_mmc_card *card;
> + struct nxpwifi_adapter *adapter;
> + struct nxpwifi_private *priv;
> + int ret = 0;
> + u16 firmware_stat;
> +
> + card = sdio_get_drvdata(func);
> + if (!card)
> + return;
> +
> + wait_for_completion(&card->fw_done);
> +
> + adapter = card->adapter;
> + if (!adapter || !adapter->priv_num)
> + return;
> +
> + nxpwifi_dbg(adapter, INFO, "info: SDIO func num=%d\n", func->num);
This does not look like useful printk message. Drivers should be silent
on success:
https://elixir.bootlin.com/linux/v6.15-rc7/source/Documentation/process/coding-style.rst#L913
https://elixir.bootlin.com/linux/v6.15-rc7/source/Documentation/process/debugging/driver_development_debugging_guide.rst#L79
Debug messages for entry/exit are really useless.
> +
> +
> +static struct sdio_driver nxpwifi_sdio = {
> + .name = "nxpwifi_sdio",
> + .id_table = nxpwifi_ids,
> + .probe = nxpwifi_sdio_probe,
> + .remove = nxpwifi_sdio_remove,
> + .drv = {
> + .owner = THIS_MODULE,
Why are you upstreaming 12-13 years old code?
No, drop all this old stuff and create your code from the scratch, based
on latest reviewed driver. Otherwise you just duplicated all issues we
fixed past 12 years!
> + .coredump = nxpwifi_sdio_coredump,
> + .pm = &nxpwifi_sdio_pm_ops,
> + }
> +};
> +
> +/*
> + * This function wakes up the card.
Really usesless way of commenting code. Can you look at existing source
code to learn how comments are supposed to be written?
Best regards,
Krzysztof
next prev parent reply other threads:[~2025-12-05 7:51 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-05 6:55 [PATCH v8 00/22] wifi: nxpwifi: create nxpwifi to support Jeff Chen
2025-12-05 6:55 ` [PATCH v8 01/22] wifi: nxpwifi: Add 802.11n support for client and AP modes Jeff Chen
2025-12-05 6:55 ` [PATCH v8 02/22] wifi: nxpwifi: add initial support for 802.11ac Jeff Chen
2025-12-05 6:55 ` [PATCH v8 03/22] wifi: nxpwifi: add initial support for 802.11ax Jeff Chen
2025-12-05 6:55 ` [PATCH v8 04/22] wifi: nxpwifi: add support for 802.11h (DFS and TPC) Jeff Chen
2025-12-05 6:55 ` [PATCH v8 05/22] wifi: nxpwifi: add support for WMM Jeff Chen
2025-12-05 6:55 ` [PATCH v8 06/22] wifi: nxpwifi: add scan support Jeff Chen
2025-12-05 6:55 ` [PATCH v8 07/22] wifi: nxpwifi: add join and association support Jeff Chen
2025-12-05 6:55 ` [PATCH v8 08/22] wifi: nxpwifi: add channel/frequency/power (cfp) support Jeff Chen
2025-12-05 6:55 ` [PATCH v8 09/22] wifi: nxpwifi: add configuration support Jeff Chen
2025-12-05 6:55 ` [PATCH v8 10/22] wifi: nxpwifi: implement cfg80211 ops for STA and AP modes Jeff Chen
2025-12-05 6:55 ` [PATCH v8 11/22] wifi: nxpwifi: add firmware command and TLV definitions Jeff Chen
2025-12-05 6:55 ` [PATCH v8 12/22] wifi: nxpwifi: introduce command and event handling infrastructure Jeff Chen
2025-12-05 7:11 ` Sascha Hauer
2025-12-05 8:40 ` Jeff Chen
2025-12-05 6:55 ` [PATCH v8 13/22] wifi: nxpwifi: add data path support for STA and AP modes Jeff Chen
2025-12-05 6:55 ` [PATCH v8 14/22] wifi: nxpwifi: add debugfs support for diagnostics and testing Jeff Chen
2025-12-05 6:55 ` [PATCH v8 15/22] wifi: nxpwifi: add ethtool support for Wake-on-LAN Jeff Chen
2025-12-05 6:55 ` [PATCH v8 16/22] wifi: nxpwifi: add utility and IE handling support Jeff Chen
2025-12-05 6:55 ` [PATCH v8 17/22] wifi: nxpwifi: add driver initialization and shutdown support Jeff Chen
2025-12-05 6:55 ` [PATCH v8 18/22] wifi: nxpwifi: add core driver implementation Jeff Chen
2025-12-05 6:55 ` [PATCH v8 19/22] wifi: nxpwifi: add initial SDIO bus driver support Jeff Chen
2025-12-05 7:51 ` Krzysztof Kozlowski [this message]
2025-12-05 6:55 ` [PATCH v8 20/22] wifi: nxpwifi: add NXP vendor and IW61x device IDs to sdio_ids.h Jeff Chen
2025-12-05 7:46 ` Krzysztof Kozlowski
2025-12-05 6:55 ` [PATCH v8 21/22] wifi: nxpwifi: add Kconfig and Makefile for kernel integration Jeff Chen
2025-12-05 6:55 ` [PATCH v8 22/22] wifi: nxpwifi: add MAINTAINERS entry for nxpwifi driver Jeff Chen
2025-12-16 14:52 ` [v8,00/22] wifi: nxpwifi: create nxpwifi to support Romit Chatterjee
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=3fc73b5d-1de7-41bb-b9ca-2878f311c6fc@kernel.org \
--to=krzk@kernel.org \
--cc=briannorris@chromium.org \
--cc=francesco@dolcini.it \
--cc=jeff.chen_1@nxp.com \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=s.hauer@pengutronix.de \
--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