Netdev List
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: m.chetan.kumar@intel.com
Cc: Netdev <netdev@vger.kernel.org>,
	kuba@kernel.org, davem@davemloft.net, johannes@sipsolutions.net,
	ryazanov.s.a@gmail.com, loic.poulain@linaro.org,
	krishna.c.sudi@intel.com, m.chetan.kumar@linux.intel.com,
	linuxwwan@intel.com, Haijun Liu <haijun.liu@mediatek.com>,
	Madhusmita Sahu <madhusmita.sahu@intel.com>,
	Ricardo Martinez <ricardo.martinez@linux.intel.com>,
	Devegowda Chandrashekar <chandrashekar.devegowda@intel.com>
Subject: Re: [PATCH net-next 3/5] net: wwan: t7xx: PCIe reset rescan
Date: Thu, 18 Aug 2022 17:58:24 +0300 (EEST)	[thread overview]
Message-ID: <56bd12a1-234e-9e92-8be4-72fff69e53bd@linux.intel.com> (raw)
In-Reply-To: <20220816042353.2416956-1-m.chetan.kumar@intel.com>

On Tue, 16 Aug 2022, m.chetan.kumar@intel.com wrote:

> From: Haijun Liu <haijun.liu@mediatek.com>
> 
> PCI rescan module implements "rescan work queue". In firmware flashing
> or coredump collection procedure WWAN device is programmed to boot in
> fastboot mode and a work item is scheduled for removal & detection.
> The WWAN device is reset using APCI call as part driver removal flow.
> Work queue rescans pci bus at fixed interval for device detection,
> later when device is detect work queue exits.
> 
> Signed-off-by: Haijun Liu <haijun.liu@mediatek.com>
> Co-developed-by: Madhusmita Sahu <madhusmita.sahu@intel.com>
> Signed-off-by: Madhusmita Sahu <madhusmita.sahu@intel.com>
> Signed-off-by: Ricardo Martinez <ricardo.martinez@linux.intel.com>
> Signed-off-by: M Chetan Kumar <m.chetan.kumar@linux.intel.com>
> Signed-off-by: Devegowda Chandrashekar <chandrashekar.devegowda@intel.com>
> ---

> +       bool                    hp_enable;

Never written to.

> diff --git a/drivers/net/wwan/t7xx/t7xx_pci_rescan.c b/drivers/net/wwan/t7xx/t7xx_pci_rescan.c
> new file mode 100644
> index 000000000000..045777d8a843
> --- /dev/null
> +++ b/drivers/net/wwan/t7xx/t7xx_pci_rescan.c
> @@ -0,0 +1,117 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2021, MediaTek Inc.
> + * Copyright (c) 2021-2022, Intel Corporation.
> + */
> +
> +#define pr_fmt(fmt) KBUILD_MODNAME ":t7xx:%s: " fmt, __func__
> +#define dev_fmt(fmt) "t7xx: " fmt
> +
> +#include <linux/delay.h>
> +#include <linux/pci.h>
> +#include <linux/spinlock.h>
> +#include <linux/workqueue.h>
> +
> +#include "t7xx_pci.h"
> +#include "t7xx_pci_rescan.h"
> +
> +static struct remove_rescan_context g_mtk_rescan_context;

Any particular reason for this name?

> +void t7xx_pci_dev_rescan(void)
> +{
> +	struct pci_bus *b = NULL;
> +
> +	pci_lock_rescan_remove();
> +	while ((b = pci_find_next_bus(b)))
> +		pci_rescan_bus(b);
> +
> +	pci_unlock_rescan_remove();

I'd remove the empty line to keep the critical sections grouped together. 

> +}
> +
> +void t7xx_rescan_done(void)
> +{
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&g_mtk_rescan_context.dev_lock, flags);
> +	if (g_mtk_rescan_context.rescan_done == 0) {
> +		pr_debug("this is a rescan probe\n");
> +		g_mtk_rescan_context.rescan_done = 1;
> +	} else {
> +		pr_debug("this is a init probe\n");
> +	}
> +	spin_unlock_irqrestore(&g_mtk_rescan_context.dev_lock, flags);
> +}
> +
> +static void t7xx_remove_rescan(struct work_struct *work)
> +{
> +	struct pci_dev *pdev;
> +	int num_retries = RESCAN_RETRIES;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&g_mtk_rescan_context.dev_lock, flags);
> +	g_mtk_rescan_context.rescan_done = 0;
> +	pdev = g_mtk_rescan_context.dev;
> +	spin_unlock_irqrestore(&g_mtk_rescan_context.dev_lock, flags);
> +
> +	if (pdev) {
> +		pci_stop_and_remove_bus_device_locked(pdev);
> +		pr_debug("start remove and rescan flow\n");
> +	}
> +
> +	do {
> +		t7xx_pci_dev_rescan();
> +		spin_lock_irqsave(&g_mtk_rescan_context.dev_lock, flags);
> +		if (g_mtk_rescan_context.rescan_done) {
> +			spin_unlock_irqrestore(&g_mtk_rescan_context.dev_lock, flags);
> +			break;
> +		}
> +
> +		spin_unlock_irqrestore(&g_mtk_rescan_context.dev_lock, flags);

Ditto.

> +		msleep(DELAY_RESCAN_MTIME);
> +	} while (num_retries--);
> +}
> +
> +void t7xx_rescan_queue_work(struct pci_dev *pdev)
> +{
> +	unsigned long flags;
> +
> +	dev_info(&pdev->dev, "start queue_mtk_rescan_work\n");
> +	spin_lock_irqsave(&g_mtk_rescan_context.dev_lock, flags);
> +	if (!g_mtk_rescan_context.rescan_done) {
> +		dev_err(&pdev->dev, "rescan failed because last rescan undone\n");

The meaning of the message is hard to understand.

> +		spin_unlock_irqrestore(&g_mtk_rescan_context.dev_lock, flags);
> +		return;
> +	}
> +
> +	g_mtk_rescan_context.dev = pdev;
> +	spin_unlock_irqrestore(&g_mtk_rescan_context.dev_lock, flags);

Crit section newlines.

> +	queue_work(g_mtk_rescan_context.pcie_rescan_wq, &g_mtk_rescan_context.service_task);
> +}
> +
> +int t7xx_rescan_init(void)
> +{
> +	spin_lock_init(&g_mtk_rescan_context.dev_lock);
> +	g_mtk_rescan_context.rescan_done = 1;
> +	g_mtk_rescan_context.dev = NULL;
> +	g_mtk_rescan_context.pcie_rescan_wq = create_singlethread_workqueue(MTK_RESCAN_WQ);
> +	if (!g_mtk_rescan_context.pcie_rescan_wq) {
> +		pr_err("Failed to create workqueue: %s\n", MTK_RESCAN_WQ);
> +		return -ENOMEM;
> +	}
> +
> +	INIT_WORK(&g_mtk_rescan_context.service_task, t7xx_remove_rescan);
> +
> +	return 0;
> +}
> +
> +void t7xx_rescan_deinit(void)
> +{
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&g_mtk_rescan_context.dev_lock, flags);
> +	g_mtk_rescan_context.rescan_done = 0;
> +	g_mtk_rescan_context.dev = NULL;
> +	spin_unlock_irqrestore(&g_mtk_rescan_context.dev_lock, flags);
> +	cancel_work_sync(&g_mtk_rescan_context.service_task);
> +	destroy_workqueue(g_mtk_rescan_context.pcie_rescan_wq);
> +}

In general, I felt this whole file was very heavy to read compared with 
the other parts of t7xx code. Maybe it will get better if 
g_mtk_rescan_context becomes shorter and re-newlining is done to better 
indicate the critical sections but we'll see.

> diff --git a/drivers/net/wwan/t7xx/t7xx_pci_rescan.h b/drivers/net/wwan/t7xx/t7xx_pci_rescan.h
> new file mode 100644
> index 000000000000..de4ca1363bb0
> --- /dev/null
> +++ b/drivers/net/wwan/t7xx/t7xx_pci_rescan.h
> @@ -0,0 +1,29 @@
> +/* SPDX-License-Identifier: GPL-2.0-only
> + *
> + * Copyright (c) 2021, MediaTek Inc.
> + * Copyright (c) 2021-2022, Intel Corporation.
> + */
> +
> +#ifndef __T7XX_PCI_RESCAN_H__
> +#define __T7XX_PCI_RESCAN_H__
> +
> +#define MTK_RESCAN_WQ "mtk_rescan_wq"
> +
> +#define DELAY_RESCAN_MTIME 1000
> +#define RESCAN_RETRIES 35
> +
> +struct remove_rescan_context {
> +	struct work_struct	 service_task;

Extra whitespace.

> +	struct workqueue_struct *pcie_rescan_wq;
> +	spinlock_t		dev_lock; /* protects device */

Perhaps use a tab before the comment instead to make some room.

> +	struct pci_dev		*dev;
> +	int			rescan_done;
> +};


-- 
 i.


  reply	other threads:[~2022-08-18 14:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16  4:23 [PATCH net-next 3/5] net: wwan: t7xx: PCIe reset rescan m.chetan.kumar
2022-08-18 14:58 ` Ilpo Järvinen [this message]
2022-08-30  2:02 ` Sergey Ryazanov
2022-09-02  4:50   ` Kumar, M Chetan
2022-09-06 22:19     ` Sergey Ryazanov
2022-09-09 12:20       ` Kumar, M Chetan

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=56bd12a1-234e-9e92-8be4-72fff69e53bd@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=chandrashekar.devegowda@intel.com \
    --cc=davem@davemloft.net \
    --cc=haijun.liu@mediatek.com \
    --cc=johannes@sipsolutions.net \
    --cc=krishna.c.sudi@intel.com \
    --cc=kuba@kernel.org \
    --cc=linuxwwan@intel.com \
    --cc=loic.poulain@linaro.org \
    --cc=m.chetan.kumar@intel.com \
    --cc=m.chetan.kumar@linux.intel.com \
    --cc=madhusmita.sahu@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=ricardo.martinez@linux.intel.com \
    --cc=ryazanov.s.a@gmail.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