linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: michael.nemanov@ti.com, Kalle Valo <kvalo@kernel.org>,
	Johannes Berg <johannes.berg@intel.com>,
	Breno Leitao <leitao@debian.org>,
	Justin Stitt <justinstitt@google.com>,
	Kees Cook <keescook@chromium.org>,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Sabeeh Khan <sabeeh-khan@ti.com>
Subject: Re: [PATCH 08/17] Add main.c
Date: Wed, 22 May 2024 11:46:21 +0200	[thread overview]
Message-ID: <cfe33bf1-9df3-4d02-b4ed-e29a430b106d@kernel.org> (raw)
In-Reply-To: <20240521171841.884576-9-michael.nemanov@ti.com>

On 21/05/2024 19:18, michael.nemanov@ti.com wrote:
> From: Michael Nemanov <Michael.Nemanov@ti.com>
> 
> General code and structures.
> Notably:
> 


...

> +}
> +
> +static int read_version_info(struct cc33xx *cc)
> +{
> +	int ret;
> +
> +	cc33xx_info("Wireless driver version %s", DRV_VERSION);

Drop

> +
> +	ret = cc33xx_acx_init_get_fw_versions(cc);
> +	if (ret < 0) {
> +		cc33xx_error("Get FW version FAILED!");
> +		return ret;
> +	}
> +
> +	cc33xx_info("Wireless firmware version %u.%u.%u.%u",
> +		    cc->all_versions.fw_ver->major_version,
> +		    cc->all_versions.fw_ver->minor_version,
> +		    cc->all_versions.fw_ver->api_version,
> +		    cc->all_versions.fw_ver->build_version);
> +
> +	cc33xx_info("Wireless PHY version %u.%u.%u.%u.%u.%u",
> +		    cc->all_versions.fw_ver->phy_version[5],
> +		    cc->all_versions.fw_ver->phy_version[4],
> +		    cc->all_versions.fw_ver->phy_version[3],
> +		    cc->all_versions.fw_ver->phy_version[2],
> +		    cc->all_versions.fw_ver->phy_version[1],
> +		    cc->all_versions.fw_ver->phy_version[0]);
> +
> +	cc->all_versions.driver_ver = DRV_VERSION;

Drop

> +
> +	return 0;
> +}
> +
> +static void cc33xx_nvs_cb(const struct firmware *fw, void *context)
> +{
> +	struct cc33xx *cc = context;
> +	struct platform_device *pdev = cc->pdev;
> +	struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
> +
> +	int ret;
> +
> +	if (fw) {
> +		cc->nvs_mac_addr = kmemdup(fw->data, fw->size, GFP_KERNEL);
> +		if (!cc->nvs_mac_addr) {
> +			cc33xx_error("Could not allocate nvs data");
> +			goto out;
> +		}
> +		cc->nvs_mac_addr_len = fw->size;
> +	} else if (pdev_data->family->nvs_name) {
> +		cc33xx_debug(DEBUG_BOOT, "Could not get nvs file %s",
> +			     pdev_data->family->nvs_name);
> +		cc->nvs_mac_addr = NULL;
> +		cc->nvs_mac_addr_len = 0;
> +	} else {
> +		cc->nvs_mac_addr = NULL;
> +		cc->nvs_mac_addr_len = 0;
> +	}
> +
> +	ret = cc33xx_setup(cc);
> +	if (ret < 0)
> +		goto out_free_nvs;
> +
> +	BUILD_BUG_ON(CC33XX_NUM_TX_DESCRIPTORS > CC33XX_MAX_TX_DESCRIPTORS);
> +
> +	/* adjust some runtime configuration parameters */
> +	cc33xx_adjust_conf(cc);
> +
> +	cc->if_ops = pdev_data->if_ops;
> +	cc->if_ops->set_irq_handler(cc->dev, irq_wrapper);
> +
> +	cc33xx_power_off(cc);
> +
> +	setup_wake_irq(cc);
> +
> +	ret = cc33xx_init_fw(cc);
> +	if (ret < 0) {
> +		cc33xx_error("FW download failed");
> +		cc33xx_power_off(cc);
> +		goto out_irq;
> +	}
> +
> +	ret = cc33xx_identify_chip(cc);
> +	if (ret < 0)
> +		goto out_irq;
> +
> +	ret = read_version_info(cc);
> +	if (ret < 0)
> +		goto out_irq;
> +
> +	ret = cc33xx_init_ieee80211(cc);
> +	if (ret)
> +		goto out_irq;
> +
> +	ret = cc33xx_register_hw(cc);
> +	if (ret)
> +		goto out_irq;
> +
> +	cc->initialized = true;
> +	cc33xx_notice("loaded");

?!?!?

> +	goto out;
> +
> +out_irq:
> +	if (cc->wakeirq >= 0)
> +		dev_pm_clear_wake_irq(cc->dev);
> +	device_init_wakeup(cc->dev, false);
> +
> +out_free_nvs:
> +	kfree(cc->nvs_mac_addr);
> +
> +out:
> +	release_firmware(fw);
> +	complete_all(&cc->nvs_loading_complete);
> +	cc33xx_debug(DEBUG_CC33xx, "%s complete", __func__);

NAK, drop. This applies everywhere.


> +}
> +
> +static int cc33xx_remove(struct platform_device *pdev)

Why remove callback is before probe? Please follow standard driver
convention. This goes immediately after probe.

> +{
> +	struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
> +	struct cc33xx *cc = platform_get_drvdata(pdev);
> +
> +	set_bit(CC33XX_FLAG_DRIVER_REMOVED, &cc->flags);

?!?!

Your code is seriously buggy if you depend on setting bit in remove
callback.

> +
> +	cc->dev->driver->pm = NULL;
> +
> +	if (pdev_data->family && pdev_data->family->nvs_name)
> +		wait_for_completion(&cc->nvs_loading_complete);
> +
> +	if (!cc->initialized)
> +		goto out;
> +
> +	if (cc->wakeirq >= 0) {
> +		dev_pm_clear_wake_irq(cc->dev);
> +		cc->wakeirq = -ENODEV;
> +	}
> +
> +	device_init_wakeup(cc->dev, false);
> +	cc33xx_unregister_hw(cc);
> +	cc33xx_turn_off(cc);
> +
> +out:
> +	cc33xx_free_hw(cc);
> +	return 0;
> +}
> +


> +
> +static int cc33xx_probe(struct platform_device *pdev)
> +{
> +	struct cc33xx *cc;
> +	struct ieee80211_hw *hw;
> +	struct cc33xx_platdev_data *pdev_data = dev_get_platdata(&pdev->dev);
> +	const char *nvs_name;
> +	int ret;
> +
> +	cc33xx_debug(DEBUG_CC33xx, "Wireless Driver Version %s", DRV_VERSION);

Drop

> +
> +	if (!pdev_data) {
> +		cc33xx_error("can't access platform data");

Do not use your own print code. Use standard dev_() calls. This applies
*everywhere*.

> +		return -EINVAL;
> +	}
> +
> +	hw = cc33xx_alloc_hw(CC33XX_AGGR_BUFFER_SIZE);
> +	if (IS_ERR(hw)) {
> +		cc33xx_error("can't allocate hw");

Heh? Since when do we print memory allocation failures? Since when
memory allocation returns ERR ptr?


> +		ret = PTR_ERR(hw);
> +		goto out;
> +	}
> +	cc = hw->priv;
> +	cc->dev = &pdev->dev;
> +	cc->pdev = pdev;
> +	platform_set_drvdata(pdev, cc);
> +
> +	if (pdev_data->family && pdev_data->family->nvs_name) {
> +		nvs_name = pdev_data->family->nvs_name;
> +		ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT,
> +					      nvs_name, &pdev->dev, GFP_KERNEL,
> +					      cc, cc33xx_nvs_cb);
> +		if (ret < 0) {
> +			cc33xx_error("request_firmware_nowait failed for %s: %d",
> +				     nvs_name, ret);
> +			complete_all(&cc->nvs_loading_complete);
> +		}
> +	} else {
> +		cc33xx_nvs_cb(NULL, cc);
> +		cc33xx_error("Invalid platform data entry");
> +		ret = -EINVAL;
> +	}
> +
> +	cc33xx_debug(DEBUG_CC33xx, "WLAN CC33xx platform device probe done");

Drop, tracing/sysfs gices you this. Do not print simple
success/entry/exit messages.

> +	return ret;
> +
> +out:
> +	return ret;
> +}
> +
> +static const struct platform_device_id cc33xx_id_table[] = {
> +	{ "cc33xx", 0 },
> +	{  } /* Terminating Entry */

Drop comment. Obvious.

> +};
> +MODULE_DEVICE_TABLE(platform, cc33xx_id_table);
> +
> +static struct platform_driver cc33xx_driver = {
> +	.probe		= cc33xx_probe,
> +	.remove		= cc33xx_remove,
> +	.id_table	= cc33xx_id_table,
> +	.driver = {
> +		.name	= "cc33xx_driver",
> +	}
> +};
> +
> +u32 cc33xx_debug_level = DEBUG_NO_DATAPATH;

Why this is global? Why u32? Why global variable is defined at the end
of the file?!?!

> +
> +module_platform_driver(cc33xx_driver);
> +
> +module_param_named(debug_level, cc33xx_debug_level, uint, 0600);
> +MODULE_PARM_DESC(debug_level, "cc33xx debugging level");
> +
> +MODULE_PARM_DESC(secure_boot_enable, "Enables secure boot and FW downlaod");

Eh? why secure boot is module param?

> +
> +module_param_named(fwlog, fwlog_param, charp, 0);
> +MODULE_PARM_DESC(fwlog, "FW logger options: continuous, dbgpins or disable");
> +
> +module_param(no_recovery, int, 0600);
> +MODULE_PARM_DESC(no_recovery, "Prevent HW recovery. FW will remain stuck.");
> +
> +module_param_named(ht_mode, ht_mode_param, charp, 0400);
> +MODULE_PARM_DESC(ht_mode, "Force HT mode: wide or siso20");

Does not look like suitable for module params.

> +
> +MODULE_LICENSE("GPL v2");
> +MODULE_DESCRIPTION("Texas Instruments CC33xx WLAN driver");
> +MODULE_AUTHOR("Michael Nemanov <michael.nemanov@ti.com>");
> +MODULE_AUTHOR("Sabeeh Khan <sabeeh-khan@ti.com>");
> +
> +MODULE_VERSION(DRV_VERSION);

Drop.

Perform internal review first. This is really not ready.


Best regards,
Krzysztof


  parent reply	other threads:[~2024-05-22  9:46 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21 17:18 [PATCH 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family michael.nemanov
2024-05-21 17:18 ` [PATCH 01/17] Add cc33xx.h, cc33xx_i.h michael.nemanov
2024-05-22  9:38   ` Krzysztof Kozlowski
2024-05-22 15:44     ` Nemanov, Michael
2024-08-06 16:56     ` Nemanov, Michael
2024-05-21 17:18 ` [PATCH 02/17] Add debug.h michael.nemanov
2024-05-21 17:18 ` [PATCH 03/17] Add sdio.c, io.c, io.h michael.nemanov
2024-05-21 17:18 ` [PATCH 04/17] Add cmd.c, cmd.h michael.nemanov
2024-05-21 17:18 ` [PATCH 05/17] Add acx.c, acx.h michael.nemanov
2024-05-21 17:18 ` [PATCH 06/17] Add event.c, event.h michael.nemanov
2024-05-21 17:18 ` [PATCH 07/17] Add boot.c, boot.h michael.nemanov
2024-05-22  8:54   ` Breno Leitao
2024-05-22 11:12     ` Krzysztof Kozlowski
2024-05-22 15:15       ` [EXTERNAL] " Nemanov, Michael
2024-05-21 17:18 ` [PATCH 08/17] Add main.c michael.nemanov
2024-05-22  8:52   ` Breno Leitao
2024-05-22  9:46   ` Krzysztof Kozlowski [this message]
2024-05-30 11:54     ` Nemanov, Michael
2024-05-30 14:37       ` Kalle Valo
2024-05-31  7:35       ` Krzysztof Kozlowski
2024-05-31 13:50         ` Nemanov, Michael
2024-06-05  9:55           ` Nemanov, Michael
2024-06-05 10:04             ` Krzysztof Kozlowski
2024-06-05 11:13               ` Kalle Valo
2024-05-21 17:18 ` [PATCH 09/17] Add rx.c, rx.h michael.nemanov
2024-05-22  8:55   ` Breno Leitao
2024-05-26  6:03     ` Nemanov, Michael
2024-05-21 17:18 ` [PATCH 10/17] Add tx.c, tx.h michael.nemanov
2024-05-21 17:18 ` [PATCH 11/17] Add init.c, init.h michael.nemanov
2024-05-21 17:18 ` [PATCH 12/17] Add scan.c, scan.h michael.nemanov
2024-05-21 17:18 ` [PATCH 13/17] Add conf.h michael.nemanov
2024-05-22  9:48   ` Krzysztof Kozlowski
2024-05-23  7:08     ` Kalle Valo
2024-05-23  7:13       ` Krzysztof Kozlowski
2024-05-23  7:18         ` Kalle Valo
2024-05-24  7:48           ` Nemanov, Michael
2024-05-21 17:18 ` [PATCH 14/17] Add ps.c, ps.h michael.nemanov
2024-05-21 17:18 ` [PATCH 15/17] Add testmode.c, testmode.h michael.nemanov
2024-05-21 17:18 ` [PATCH 16/17] Add Kconfig, Makefile and integrate into wireless/ti folder michael.nemanov
2024-05-21 17:18 ` [PATCH 17/17] Add ti,cc33xx.yaml michael.nemanov
2024-05-22  9:35   ` Krzysztof Kozlowski
2024-05-26  6:35     ` Nemanov, Michael
2024-05-23  7:15 ` [PATCH 00/17] wifi: cc33xx: Add driver for new TI CC33xx wireless device family Kalle Valo
2024-05-24  7:48   ` Nemanov, Michael

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=cfe33bf1-9df3-4d02-b4ed-e29a430b106d@kernel.org \
    --to=krzk@kernel.org \
    --cc=johannes.berg@intel.com \
    --cc=justinstitt@google.com \
    --cc=keescook@chromium.org \
    --cc=kvalo@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=michael.nemanov@ti.com \
    --cc=sabeeh-khan@ti.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;
as well as URLs for NNTP newsgroup(s).