-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guangbin Huang says: ==================== net: hns3: add support devlink This series adds devlink support for the HNS3 ethernet driver. change log: V2 -> V3: 1. remove two patches of setting rx/tx buffer size by devlink param. V1 -> V2: 1. add more detailed descriptions of parameters in document hns3.rst. RFC -> V1: 1. use DEVLINK_INFO_VERSION_GENERIC_FW instead of "fw-version". 2. add devlink documentation for hns3 driver. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Showing
13 changed files
with
390 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.. SPDX-License-Identifier: GPL-2.0 | ||
==================== | ||
hns3 devlink support | ||
==================== | ||
|
||
This document describes the devlink features implemented by the ``hns3`` | ||
device driver. | ||
|
||
The ``hns3`` driver supports reloading via ``DEVLINK_CMD_RELOAD``. | ||
|
||
Info versions | ||
============= | ||
|
||
The ``hns3`` driver reports the following versions | ||
|
||
.. list-table:: devlink info versions implemented | ||
:widths: 10 10 80 | ||
|
||
* - Name | ||
- Type | ||
- Description | ||
* - ``fw`` | ||
- running | ||
- Used to represent the firmware version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ parameters, info versions, and other features it supports. | |
:maxdepth: 1 | ||
|
||
bnxt | ||
hns3 | ||
ionic | ||
ice | ||
mlx4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
/* Copyright (c) 2021 Hisilicon Limited. */ | ||
|
||
#include <net/devlink.h> | ||
|
||
#include "hclge_devlink.h" | ||
|
||
static int hclge_devlink_info_get(struct devlink *devlink, | ||
struct devlink_info_req *req, | ||
struct netlink_ext_ack *extack) | ||
{ | ||
#define HCLGE_DEVLINK_FW_STRING_LEN 32 | ||
struct hclge_devlink_priv *priv = devlink_priv(devlink); | ||
char version_str[HCLGE_DEVLINK_FW_STRING_LEN]; | ||
struct hclge_dev *hdev = priv->hdev; | ||
int ret; | ||
|
||
ret = devlink_info_driver_name_put(req, KBUILD_MODNAME); | ||
if (ret) | ||
return ret; | ||
|
||
snprintf(version_str, sizeof(version_str), "%lu.%lu.%lu.%lu", | ||
hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE3_MASK, | ||
HNAE3_FW_VERSION_BYTE3_SHIFT), | ||
hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE2_MASK, | ||
HNAE3_FW_VERSION_BYTE2_SHIFT), | ||
hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE1_MASK, | ||
HNAE3_FW_VERSION_BYTE1_SHIFT), | ||
hnae3_get_field(hdev->fw_version, HNAE3_FW_VERSION_BYTE0_MASK, | ||
HNAE3_FW_VERSION_BYTE0_SHIFT)); | ||
|
||
return devlink_info_version_running_put(req, | ||
DEVLINK_INFO_VERSION_GENERIC_FW, | ||
version_str); | ||
} | ||
|
||
static int hclge_devlink_reload_down(struct devlink *devlink, bool netns_change, | ||
enum devlink_reload_action action, | ||
enum devlink_reload_limit limit, | ||
struct netlink_ext_ack *extack) | ||
{ | ||
struct hclge_devlink_priv *priv = devlink_priv(devlink); | ||
struct hclge_dev *hdev = priv->hdev; | ||
struct hnae3_handle *h = &hdev->vport->nic; | ||
struct pci_dev *pdev = hdev->pdev; | ||
int ret; | ||
|
||
if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state)) { | ||
dev_err(&pdev->dev, "reset is handling\n"); | ||
return -EBUSY; | ||
} | ||
|
||
switch (action) { | ||
case DEVLINK_RELOAD_ACTION_DRIVER_REINIT: | ||
rtnl_lock(); | ||
ret = hdev->nic_client->ops->reset_notify(h, HNAE3_DOWN_CLIENT); | ||
if (ret) { | ||
rtnl_unlock(); | ||
return ret; | ||
} | ||
|
||
ret = hdev->nic_client->ops->reset_notify(h, | ||
HNAE3_UNINIT_CLIENT); | ||
rtnl_unlock(); | ||
return ret; | ||
default: | ||
return -EOPNOTSUPP; | ||
} | ||
} | ||
|
||
static int hclge_devlink_reload_up(struct devlink *devlink, | ||
enum devlink_reload_action action, | ||
enum devlink_reload_limit limit, | ||
u32 *actions_performed, | ||
struct netlink_ext_ack *extack) | ||
{ | ||
struct hclge_devlink_priv *priv = devlink_priv(devlink); | ||
struct hclge_dev *hdev = priv->hdev; | ||
struct hnae3_handle *h = &hdev->vport->nic; | ||
int ret; | ||
|
||
*actions_performed = BIT(action); | ||
switch (action) { | ||
case DEVLINK_RELOAD_ACTION_DRIVER_REINIT: | ||
rtnl_lock(); | ||
ret = hdev->nic_client->ops->reset_notify(h, HNAE3_INIT_CLIENT); | ||
if (ret) { | ||
rtnl_unlock(); | ||
return ret; | ||
} | ||
|
||
ret = hdev->nic_client->ops->reset_notify(h, HNAE3_UP_CLIENT); | ||
rtnl_unlock(); | ||
return ret; | ||
default: | ||
return -EOPNOTSUPP; | ||
} | ||
} | ||
|
||
static const struct devlink_ops hclge_devlink_ops = { | ||
.info_get = hclge_devlink_info_get, | ||
.reload_actions = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT), | ||
.reload_down = hclge_devlink_reload_down, | ||
.reload_up = hclge_devlink_reload_up, | ||
}; | ||
|
||
int hclge_devlink_init(struct hclge_dev *hdev) | ||
{ | ||
struct pci_dev *pdev = hdev->pdev; | ||
struct hclge_devlink_priv *priv; | ||
struct devlink *devlink; | ||
int ret; | ||
|
||
devlink = devlink_alloc(&hclge_devlink_ops, | ||
sizeof(struct hclge_devlink_priv)); | ||
if (!devlink) | ||
return -ENOMEM; | ||
|
||
priv = devlink_priv(devlink); | ||
priv->hdev = hdev; | ||
|
||
ret = devlink_register(devlink, &pdev->dev); | ||
if (ret) { | ||
dev_err(&pdev->dev, "failed to register devlink, ret = %d\n", | ||
ret); | ||
goto out_reg_fail; | ||
} | ||
|
||
hdev->devlink = devlink; | ||
|
||
devlink_reload_enable(devlink); | ||
|
||
return 0; | ||
|
||
out_reg_fail: | ||
devlink_free(devlink); | ||
return ret; | ||
} | ||
|
||
void hclge_devlink_uninit(struct hclge_dev *hdev) | ||
{ | ||
struct devlink *devlink = hdev->devlink; | ||
|
||
if (!devlink) | ||
return; | ||
|
||
devlink_reload_disable(devlink); | ||
|
||
devlink_unregister(devlink); | ||
|
||
devlink_free(devlink); | ||
|
||
hdev->devlink = NULL; | ||
} |
15 changes: 15 additions & 0 deletions
15
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* SPDX-License-Identifier: GPL-2.0+ */ | ||
/* Copyright (c) 2021 Hisilicon Limited. */ | ||
|
||
#ifndef __HCLGE_DEVLINK_H | ||
#define __HCLGE_DEVLINK_H | ||
|
||
#include "hclge_main.h" | ||
|
||
struct hclge_devlink_priv { | ||
struct hclge_dev *hdev; | ||
}; | ||
|
||
int hclge_devlink_init(struct hclge_dev *hdev); | ||
void hclge_devlink_uninit(struct hclge_dev *hdev); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.