1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
// SPDX-License-Identifier: GPL-2.0+
// Copyright (c) 2024 Hisilicon Limited.
#include <linux/etherdevice.h>
#include <linux/netdevice.h>
#include <linux/phy.h>
#include <linux/rtnetlink.h>
#include "hbg_common.h"
#include "hbg_err.h"
#include "hbg_hw.h"
static void hbg_restore_mac_table(struct hbg_priv *priv)
{
struct hbg_mac_filter *filter = &priv->filter;
u64 addr;
u32 i;
for (i = 0; i < filter->table_max_len; i++)
if (!is_zero_ether_addr(filter->mac_table[i].addr)) {
addr = ether_addr_to_u64(filter->mac_table[i].addr);
hbg_hw_set_uc_addr(priv, addr, i);
}
hbg_hw_set_mac_filter_enable(priv, priv->filter.enabled);
}
static void hbg_restore_user_def_settings(struct hbg_priv *priv)
{
struct ethtool_pauseparam *pause_param = &priv->user_def.pause_param;
hbg_restore_mac_table(priv);
hbg_hw_set_mtu(priv, priv->netdev->mtu);
hbg_hw_set_pause_enable(priv, pause_param->tx_pause,
pause_param->rx_pause);
}
int hbg_rebuild(struct hbg_priv *priv)
{
int ret;
ret = hbg_hw_init(priv);
if (ret)
return ret;
hbg_restore_user_def_settings(priv);
return 0;
}
static int hbg_reset_prepare(struct hbg_priv *priv, enum hbg_reset_type type)
{
int ret;
ASSERT_RTNL();
if (netif_running(priv->netdev)) {
dev_warn(&priv->pdev->dev,
"failed to reset because port is up\n");
return -EBUSY;
}
priv->reset_type = type;
set_bit(HBG_NIC_STATE_RESETTING, &priv->state);
clear_bit(HBG_NIC_STATE_RESET_FAIL, &priv->state);
ret = hbg_hw_event_notify(priv, HBG_HW_EVENT_RESET);
if (ret) {
set_bit(HBG_NIC_STATE_RESET_FAIL, &priv->state);
clear_bit(HBG_NIC_STATE_RESETTING, &priv->state);
}
return ret;
}
static int hbg_reset_done(struct hbg_priv *priv, enum hbg_reset_type type)
{
int ret;
if (!test_bit(HBG_NIC_STATE_RESETTING, &priv->state) ||
type != priv->reset_type)
return 0;
ASSERT_RTNL();
clear_bit(HBG_NIC_STATE_RESETTING, &priv->state);
ret = hbg_rebuild(priv);
if (ret) {
set_bit(HBG_NIC_STATE_RESET_FAIL, &priv->state);
dev_err(&priv->pdev->dev, "failed to rebuild after reset\n");
return ret;
}
dev_info(&priv->pdev->dev, "reset done\n");
return ret;
}
/* must be protected by rtnl lock */
int hbg_reset(struct hbg_priv *priv)
{
int ret;
ASSERT_RTNL();
ret = hbg_reset_prepare(priv, HBG_RESET_TYPE_FUNCTION);
if (ret)
return ret;
return hbg_reset_done(priv, HBG_RESET_TYPE_FUNCTION);
}
static void hbg_pci_err_reset_prepare(struct pci_dev *pdev)
{
struct net_device *netdev = pci_get_drvdata(pdev);
struct hbg_priv *priv = netdev_priv(netdev);
rtnl_lock();
hbg_reset_prepare(priv, HBG_RESET_TYPE_FLR);
}
static void hbg_pci_err_reset_done(struct pci_dev *pdev)
{
struct net_device *netdev = pci_get_drvdata(pdev);
struct hbg_priv *priv = netdev_priv(netdev);
hbg_reset_done(priv, HBG_RESET_TYPE_FLR);
rtnl_unlock();
}
static const struct pci_error_handlers hbg_pci_err_handler = {
.reset_prepare = hbg_pci_err_reset_prepare,
.reset_done = hbg_pci_err_reset_done,
};
void hbg_set_pci_err_handler(struct pci_driver *pdrv)
{
pdrv->err_handler = &hbg_pci_err_handler;
}
|