Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1320349lqp; Mon, 15 Apr 2024 02:51:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPtzknS6lKczqCUo8V2nDkedlJp56fUTR6Z5cxZ37yIavurWVtTv2LQibatcMYX7v3ICEWCD/I2gE1CD9PNb7pVWCnT2rQpFoTWLhLoA== X-Google-Smtp-Source: AGHT+IES2DIwiVwoB8ZE4m3pOpPIrbiLdrQQwyANNFYbJ4m1hRQKfzKNOuGzRx3eBLQTncbsZFdy X-Received: by 2002:a2e:9c13:0:b0:2d7:1e2b:6284 with SMTP id s19-20020a2e9c13000000b002d71e2b6284mr6596238lji.27.1713174677800; Mon, 15 Apr 2024 02:51:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713174677; cv=pass; d=google.com; s=arc-20160816; b=uLNshGx2GiRhcZLYRJZTjuJlrnC0VoOII/U3f60ykGL+k5Z9fZXdn7nY/92YD5/fij GGE32uCoSwX7YtBkMyYjdgBMO7hZ3SLKolWREwL+v/64U32FAkWi0jVoze7CY9ieDe2H D6tmBR2ns+UH/SvztynMl4t6khTBhi3RcDIib1UZDD2wvKuL8Bp76jvDjasxMKccMocV JnmWYf/iNvzMZbugTnCjb0qxgbvLz+V8wFBVNw2KJ0GUALuOCjnXdXhq1Vyp6ccGPWVI U74U0haXvxBmgC2lgQdDpR5zguuAW7eJKUq9p8USDGmbmDkH22tsXdbnQMfmUN8Bo5qa 8jJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=I0/lrKTOZRAEKlw4IxM0UxHLji3Bd4EZwvEMBRN/Fps=; fh=MPHGc8f5QQSyqOfQ1MeGGhRXuFfFkhi+uso3PghHYNw=; b=lpUk7b+q6dl5GIZTAUL5o6T5hdNMntjtMMyyNIjUXGYDUyZtRs7ZP9w7SMqK2cLfU7 /jJIKgKkI0ev2uExsuRVOaEzOvwDpdFSRtKvpIT4QzYDOcZIr/bznKnf2tSoYmIuItCt cVKjOfSVuwo9N3nD9VQopvwGCc3upBaPxTKU2QA1sw+fSe1acaYGnm5gY7yCtuGhroH8 QBnJUHbAtsVahjTXjIS47Sf0miXpJaxECZ9hCl1/dajRaoP/QoIE7d0impV1M07k2rPB EsfQn9Ci+0JSsm/blhjjGzp2vDYCWX24APMbY8e1NFBfUcwrJfxF+mKNUmzni/BbtKo5 g08g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=HREzJFRF; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-144865-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144865-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id rs28-20020a170907037c00b00a51a67eeec9si4457439ejb.950.2024.04.15.02.51.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 02:51:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144865-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=HREzJFRF; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-144865-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144865-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5BC771F22E1D for ; Mon, 15 Apr 2024 09:51:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ABE2C51010; Mon, 15 Apr 2024 09:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="HREzJFRF" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C10347A7F; Mon, 15 Apr 2024 09:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713174592; cv=none; b=LZXxHBbzjeg1rHAwALvatUC69mJYY2GxxPYP+rdijfhiHcAT+WYqoXQJWZkYI1EIZlwfNz0AbshG80csgXrvTffVZ5FjFrRV1PKre54asIR7heEM8L7eZe8W8nvSdCbt5wU5ykhs2a7gBwrnAziabgL9Cupq4W3+wmpqo4L2mmg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713174592; c=relaxed/simple; bh=HPqIfe8N0h1aRaKL1e6qWNji6hvbGbimqY4dEkNUOi4=; h=From:To:Cc:Subject:Date:Message-Id; b=NFAcTYJOcd/XtkPFUKntyvXzTG0WTcbP4cNwdr2i1oiBRThs1B7VFzwrgbJ/AWPzz3AlG1HqcacY2Pp4cXMbooyac6VOB78Ivv1Nmt/mDOnuGCHV5+5rcOIqa5g6QpZDrzWVGduvkfEiMSqORrTVWQ0L6hj7NcvrgyncMD6M/CA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=HREzJFRF; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: by linux.microsoft.com (Postfix, from userid 1134) id 9AC8420FC60E; Mon, 15 Apr 2024 02:49:50 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9AC8420FC60E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1713174590; bh=I0/lrKTOZRAEKlw4IxM0UxHLji3Bd4EZwvEMBRN/Fps=; h=From:To:Cc:Subject:Date:From; b=HREzJFRFIojtvhKFj4dl+RnRoAPWmBOCXhHvKF0V3TI3hbC/3bErU8JTUi7F/hjMV 9CvIYHwhL4pT6vwbC6627dcePGt8GB6kJGcIeu1tgnw1CSeGg8xMHf+0IpLU3Q69GT WcigWcty1iqnWg4s2SJYN+I9Eh3+bA57QQnEPdow= From: Shradha Gupta To: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org Cc: Shradha Gupta , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Ajay Sharma , Leon Romanovsky , Thomas Gleixner , Sebastian Andrzej Siewior , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Michael Kelley , Shradha Gupta , Yury Norov , Konstantin Taranov , Souradeep Chakrabarti Subject: [PATCH net-next] net: mana: Add new device attributes for mana Date: Mon, 15 Apr 2024 02:49:49 -0700 Message-Id: <1713174589-29243-1-git-send-email-shradhagupta@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Add new device attributes to view multiport, msix, and adapter MTU setting for MANA device. Signed-off-by: Shradha Gupta --- .../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; + err = mana_gd_setup(pdev); if (err) goto unmap_bar; @@ -1544,6 +1607,15 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return err; } +static void mana_cleanup_sysfs_files(struct pci_dev *pdev, + struct gdma_context *gc) +{ + device_remove_file(&pdev->dev, &gc->mana_attributes.mana_msix_attr); + device_remove_file(&pdev->dev, + &gc->mana_attributes.mana_adapter_mtu_attr); + device_remove_file(&pdev->dev, &gc->mana_attributes.mana_mport_attr); +} + static void mana_gd_remove(struct pci_dev *pdev) { struct gdma_context *gc = pci_get_drvdata(pdev); @@ -1552,6 +1624,8 @@ static void mana_gd_remove(struct pci_dev *pdev) mana_gd_cleanup(pdev); + mana_cleanup_sysfs_files(pdev, gc); + pci_iounmap(pdev, gc->bar0_va); vfree(gc); diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h index 27684135bb4d..ea636959164c 100644 --- a/include/net/mana/gdma.h +++ b/include/net/mana/gdma.h @@ -354,6 +354,12 @@ struct gdma_irq_context { char name[MANA_IRQ_NAME_SZ]; }; +struct mana_device_attributes { + struct device_attribute mana_mport_attr; + struct device_attribute mana_adapter_mtu_attr; + struct device_attribute mana_msix_attr; +}; + struct gdma_context { struct device *dev; @@ -395,6 +401,9 @@ struct gdma_context { /* Azure RDMA adapter */ struct gdma_dev mana_ib; + + /* device attributes */ + struct mana_device_attributes mana_attributes; }; #define MAX_NUM_GDMA_DEVICES 4 -- 2.34.1