RE: [PATCH net-next] net: mana: Add new device attributes for mana

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> -----Original Message-----
> From: Shradha Gupta <shradhagupta@xxxxxxxxxxxxxxxxxxx>
> Sent: Monday, April 15, 2024 5:50 AM
> To: linux-kernel@xxxxxxxxxxxxxxx; linux-hyperv@xxxxxxxxxxxxxxx; linux-
> rdma@xxxxxxxxxxxxxxx; netdev@xxxxxxxxxxxxxxx
> Cc: Shradha Gupta <shradhagupta@xxxxxxxxxxxxxxxxxxx>; Eric Dumazet
> <edumazet@xxxxxxxxxx>; Jakub Kicinski <kuba@xxxxxxxxxx>; Paolo Abeni
> <pabeni@xxxxxxxxxx>; Ajay Sharma <sharmaajay@xxxxxxxxxxxxx>; Leon
> Romanovsky <leon@xxxxxxxxxx>; Thomas Gleixner <tglx@xxxxxxxxxxxxx>;
> Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>; KY Srinivasan
> <kys@xxxxxxxxxxxxx>; Haiyang Zhang <haiyangz@xxxxxxxxxxxxx>; Wei Liu
> <wei.liu@xxxxxxxxxx>; Dexuan Cui <decui@xxxxxxxxxxxxx>; Long Li
> <longli@xxxxxxxxxxxxx>; Michael Kelley <mikelley@xxxxxxxxxxxxx>; Shradha
> Gupta <shradhagupta@xxxxxxxxxxxxx>; Yury Norov <yury.norov@xxxxxxxxx>;
> Konstantin Taranov <kotaranov@xxxxxxxxxxxxx>; Souradeep Chakrabarti
> <schakrabarti@xxxxxxxxxxxxxxxxxxx>
> Subject: [PATCH net-next] net: mana: Add new device attributes for mana
> 
> Add new device attributes to view multiport, msix, and adapter MTU
> setting for MANA device.
> 
> Signed-off-by: Shradha Gupta <shradhagupta@xxxxxxxxxxxxxxxxxxx>
> ---
>  .../net/ethernet/microsoft/mana/gdma_main.c   | 74 +++++++++++++++++++
>  include/net/mana/gdma.h                       |  9 +++
>  2 files changed, 83 insertions(+)
> 
> diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c
> b/drivers/net/ethernet/microsoft/mana/gdma_main.c
> index 1332db9a08eb..6674a02cff06 100644
> --- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
> +++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
> @@ -1471,6 +1471,65 @@ static bool mana_is_pf(unsigned short dev_id)
>  	return dev_id == MANA_PF_DEVICE_ID;
>  }
> 
> +static ssize_t mana_attr_show(struct device *dev,
> +			      struct device_attribute *attr, char *buf)
> +{
> +	struct pci_dev *pdev = to_pci_dev(dev);
> +	struct gdma_context *gc = pci_get_drvdata(pdev);
> +	struct mana_context *ac = gc->mana.driver_data;
> +
> +	if (strcmp(attr->attr.name, "mport") == 0)
> +		return snprintf(buf, PAGE_SIZE, "%d\n", ac->num_ports);
> +	else if (strcmp(attr->attr.name, "adapter_mtu") == 0)
> +		return snprintf(buf, PAGE_SIZE, "%d\n", gc->adapter_mtu);
> +	else if (strcmp(attr->attr.name, "msix") == 0)
> +		return snprintf(buf, PAGE_SIZE, "%d\n", gc->max_num_msix);
> +	else
> +		return -EINVAL;
> +}
> +
> +static int mana_gd_setup_sysfs(struct pci_dev *pdev)
> +{
> +	struct gdma_context *gc = pci_get_drvdata(pdev);
> +	int retval = 0;
> +
> +	gc->mana_attributes.mana_mport_attr.attr.name = "mport";
> +	gc->mana_attributes.mana_mport_attr.attr.mode = 0444;
> +	gc->mana_attributes.mana_mport_attr.show = mana_attr_show;
> +	sysfs_attr_init(&gc->mana_attributes.mana_mport_attr);
> +	retval = device_create_file(&pdev->dev,
> +				    &gc->mana_attributes.mana_mport_attr);
> +	if (retval < 0)
> +		return retval;
> +
> +	gc->mana_attributes.mana_adapter_mtu_attr.attr.name =
> "adapter_mtu";
> +	gc->mana_attributes.mana_adapter_mtu_attr.attr.mode = 0444;
> +	gc->mana_attributes.mana_adapter_mtu_attr.show = mana_attr_show;
> +	sysfs_attr_init(&gc->mana_attributes.mana_adapter_mtu_attr);
> +	retval = device_create_file(&pdev->dev,
> +				    &gc->mana_attributes.mana_adapter_mtu_attr);
> +	if (retval < 0)
> +		goto mtu_attr_error;
> +
> +	gc->mana_attributes.mana_msix_attr.attr.name = "msix";
> +	gc->mana_attributes.mana_msix_attr.attr.mode = 0444;
> +	gc->mana_attributes.mana_msix_attr.show = mana_attr_show;
> +	sysfs_attr_init(&gc->mana_attributes.mana_msix_attr);
> +	retval = device_create_file(&pdev->dev,
> +				    &gc->mana_attributes.mana_msix_attr);
> +	if (retval < 0)
> +		goto msix_attr_error;
> +
> +	return retval;
> +msix_attr_error:
> +	device_remove_file(&pdev->dev,
> +			   &gc->mana_attributes.mana_adapter_mtu_attr);
> +mtu_attr_error:
> +	device_remove_file(&pdev->dev,
> +			   &gc->mana_attributes.mana_mport_attr);
> +	return retval;
> +}
> +
>  static int mana_gd_probe(struct pci_dev *pdev, const struct
> pci_device_id *ent)
>  {
>  	struct gdma_context *gc;
> @@ -1519,6 +1578,10 @@ static int mana_gd_probe(struct pci_dev *pdev,
> const struct pci_device_id *ent)
>  	gc->bar0_va = bar0_va;
>  	gc->dev = &pdev->dev;
> 
> +	err = mana_gd_setup_sysfs(pdev);
> +	if (err < 0)
> +		goto free_gc;
> +

Regarding examples, vmbus_drv.c has a number of sysfs variables:

static ssize_t in_read_bytes_avail_show(struct device *dev,
                                        struct device_attribute *dev_attr,
                                        char *buf)
{
        struct hv_device *hv_dev = device_to_hv_device(dev);
        struct hv_ring_buffer_debug_info inbound;
        int ret;

        if (!hv_dev->channel)
                return -ENODEV;

        ret = hv_ringbuffer_get_debuginfo(&hv_dev->channel->inbound, &inbound);
        if (ret < 0)
                return ret;

        return sprintf(buf, "%d\n", inbound.bytes_avail_toread);
}
static DEVICE_ATTR_RO(in_read_bytes_avail);

Thanks,
- Haiyang





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux