1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (c) 2021 Hisilicon Limited. */
4 #include <net/devlink.h>
6 #include "hclgevf_devlink.h"
8 static int hclgevf_devlink_info_get(struct devlink
*devlink
,
9 struct devlink_info_req
*req
,
10 struct netlink_ext_ack
*extack
)
12 #define HCLGEVF_DEVLINK_FW_STRING_LEN 32
13 struct hclgevf_devlink_priv
*priv
= devlink_priv(devlink
);
14 char version_str
[HCLGEVF_DEVLINK_FW_STRING_LEN
];
15 struct hclgevf_dev
*hdev
= priv
->hdev
;
17 snprintf(version_str
, sizeof(version_str
), "%lu.%lu.%lu.%lu",
18 hnae3_get_field(hdev
->fw_version
, HNAE3_FW_VERSION_BYTE3_MASK
,
19 HNAE3_FW_VERSION_BYTE3_SHIFT
),
20 hnae3_get_field(hdev
->fw_version
, HNAE3_FW_VERSION_BYTE2_MASK
,
21 HNAE3_FW_VERSION_BYTE2_SHIFT
),
22 hnae3_get_field(hdev
->fw_version
, HNAE3_FW_VERSION_BYTE1_MASK
,
23 HNAE3_FW_VERSION_BYTE1_SHIFT
),
24 hnae3_get_field(hdev
->fw_version
, HNAE3_FW_VERSION_BYTE0_MASK
,
25 HNAE3_FW_VERSION_BYTE0_SHIFT
));
27 return devlink_info_version_running_put(req
,
28 DEVLINK_INFO_VERSION_GENERIC_FW
,
32 static int hclgevf_devlink_reload_down(struct devlink
*devlink
,
34 enum devlink_reload_action action
,
35 enum devlink_reload_limit limit
,
36 struct netlink_ext_ack
*extack
)
38 struct hclgevf_devlink_priv
*priv
= devlink_priv(devlink
);
39 struct hclgevf_dev
*hdev
= priv
->hdev
;
40 struct hnae3_handle
*h
= &hdev
->nic
;
41 struct pci_dev
*pdev
= hdev
->pdev
;
44 if (test_bit(HCLGEVF_STATE_RST_HANDLING
, &hdev
->state
)) {
45 dev_err(&pdev
->dev
, "reset is handling\n");
50 case DEVLINK_RELOAD_ACTION_DRIVER_REINIT
:
52 ret
= hdev
->nic_client
->ops
->reset_notify(h
, HNAE3_DOWN_CLIENT
);
58 ret
= hdev
->nic_client
->ops
->reset_notify(h
,
67 static int hclgevf_devlink_reload_up(struct devlink
*devlink
,
68 enum devlink_reload_action action
,
69 enum devlink_reload_limit limit
,
70 u32
*actions_performed
,
71 struct netlink_ext_ack
*extack
)
73 struct hclgevf_devlink_priv
*priv
= devlink_priv(devlink
);
74 struct hclgevf_dev
*hdev
= priv
->hdev
;
75 struct hnae3_handle
*h
= &hdev
->nic
;
78 *actions_performed
= BIT(action
);
80 case DEVLINK_RELOAD_ACTION_DRIVER_REINIT
:
82 ret
= hdev
->nic_client
->ops
->reset_notify(h
, HNAE3_INIT_CLIENT
);
88 ret
= hdev
->nic_client
->ops
->reset_notify(h
, HNAE3_UP_CLIENT
);
96 static const struct devlink_ops hclgevf_devlink_ops
= {
97 .info_get
= hclgevf_devlink_info_get
,
98 .reload_actions
= BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT
),
99 .reload_down
= hclgevf_devlink_reload_down
,
100 .reload_up
= hclgevf_devlink_reload_up
,
103 int hclgevf_devlink_init(struct hclgevf_dev
*hdev
)
105 struct pci_dev
*pdev
= hdev
->pdev
;
106 struct hclgevf_devlink_priv
*priv
;
107 struct devlink
*devlink
;
110 devlink_alloc(&hclgevf_devlink_ops
,
111 sizeof(struct hclgevf_devlink_priv
), &pdev
->dev
);
115 priv
= devlink_priv(devlink
);
117 hdev
->devlink
= devlink
;
119 devlink_register(devlink
);
123 void hclgevf_devlink_uninit(struct hclgevf_dev
*hdev
)
125 struct devlink
*devlink
= hdev
->devlink
;
127 devlink_unregister(devlink
);
129 devlink_free(devlink
);