Subject: Re: [net-next v3 2/3] net: wwan: t7xx: Add sysfs attribute for device state machine

From: Jakub Kicinski <[email-masked]>
Date: Mon, 8 Jan 2024 07:19:33 -0800

On Thu, 28 Dec 2023 17:44:10 +0800 Jinjian Song wrote:
> From: Jinjian Song <[email-masked]>
> 
> Add support for userspace to get the device mode,
> e.g., reset/ready/fastboot mode.

We need some info under Documentation/ describing the file / attr
and how it's supposed to be used.

> diff --git a/drivers/net/wwan/t7xx/t7xx_modem_ops.c b/drivers/net/wwan/t7xx/t7xx_modem_ops.c
> index 24e7d491468e..ae4578905a8d 100644
> --- a/drivers/net/wwan/t7xx/t7xx_modem_ops.c
> +++ b/drivers/net/wwan/t7xx/t7xx_modem_ops.c
> @@ -192,6 +192,7 @@ static irqreturn_t t7xx_rgu_isr_thread(int irq, void *data)
>  {
>  	struct t7xx_pci_dev *t7xx_dev = data;
>  
> +	atomic_set(&t7xx_dev->mode, T7XX_RESET);

Why is ->mode atomic? There seem to be no RMW operations on it.
You can use READ_ONCE() / WRITE_ONCE() on a normal integer.

>  	msleep(RGU_RESET_DELAY_MS);
>  	t7xx_reset_device_via_pmic(t7xx_dev);
>  	return IRQ_HANDLED;
> diff --git a/drivers/net/wwan/t7xx/t7xx_pci.c b/drivers/net/wwan/t7xx/t7xx_pci.c
> index 91256e005b84..d5f6a8638aba 100644
> --- a/drivers/net/wwan/t7xx/t7xx_pci.c
> +++ b/drivers/net/wwan/t7xx/t7xx_pci.c
> @@ -52,6 +52,68 @@
>  #define PM_RESOURCE_POLL_TIMEOUT_US	10000
>  #define PM_RESOURCE_POLL_STEP_US	100
>  
> +static ssize_t t7xx_mode_store(struct device *dev,
> +			       struct device_attribute *attr,
> +			       const char *buf, size_t count)
> +{
> +	struct pci_dev *pdev;
> +	struct t7xx_pci_dev *t7xx_dev;
> +
> +	pdev = to_pci_dev(dev);
> +	t7xx_dev = pci_get_drvdata(pdev);
> +	if (!t7xx_dev)
> +		return -ENODEV;
> +
> +	atomic_set(&t7xx_dev->mode, T7XX_FASTBOOT_DL_SWITCHING);

This function doesn't use @buf at all. So whenever user does write()
to the file we set to SWITCHING? Shouldn't we narrow down the set
of accepted values to be able to add more functionality later?

> +	return count;
> +};

unnecessary semi-colon