Skip to content

Commit bb6b94a

Browse files
321lipengdavem330
authored andcommitted
net: hns3: Add reset interface implementation in client
This patch implement the interface of reset notification in hns3_enet, it will do resetting business which include shutdown nic device, free and initialize client side resource. Signed-off-by: qumingguang <[email protected]> Signed-off-by: Lipeng <[email protected]> Signed-off-by: Yunsheng Lin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f8fa222 commit bb6b94a

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,11 +3009,164 @@ static int hns3_client_setup_tc(struct hnae3_handle *handle, u8 tc)
30093009
return ret;
30103010
}
30113011

3012+
static void hns3_recover_hw_addr(struct net_device *ndev)
3013+
{
3014+
struct netdev_hw_addr_list *list;
3015+
struct netdev_hw_addr *ha, *tmp;
3016+
3017+
/* go through and sync uc_addr entries to the device */
3018+
list = &ndev->uc;
3019+
list_for_each_entry_safe(ha, tmp, &list->list, list)
3020+
hns3_nic_uc_sync(ndev, ha->addr);
3021+
3022+
/* go through and sync mc_addr entries to the device */
3023+
list = &ndev->mc;
3024+
list_for_each_entry_safe(ha, tmp, &list->list, list)
3025+
hns3_nic_mc_sync(ndev, ha->addr);
3026+
}
3027+
3028+
static void hns3_drop_skb_data(struct hns3_enet_ring *ring, struct sk_buff *skb)
3029+
{
3030+
dev_kfree_skb_any(skb);
3031+
}
3032+
3033+
static void hns3_clear_all_ring(struct hnae3_handle *h)
3034+
{
3035+
struct net_device *ndev = h->kinfo.netdev;
3036+
struct hns3_nic_priv *priv = netdev_priv(ndev);
3037+
u32 i;
3038+
3039+
for (i = 0; i < h->kinfo.num_tqps; i++) {
3040+
struct netdev_queue *dev_queue;
3041+
struct hns3_enet_ring *ring;
3042+
3043+
ring = priv->ring_data[i].ring;
3044+
hns3_clean_tx_ring(ring, ring->desc_num);
3045+
dev_queue = netdev_get_tx_queue(ndev,
3046+
priv->ring_data[i].queue_index);
3047+
netdev_tx_reset_queue(dev_queue);
3048+
3049+
ring = priv->ring_data[i + h->kinfo.num_tqps].ring;
3050+
hns3_clean_rx_ring(ring, ring->desc_num, hns3_drop_skb_data);
3051+
}
3052+
}
3053+
3054+
static int hns3_reset_notify_down_enet(struct hnae3_handle *handle)
3055+
{
3056+
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
3057+
struct net_device *ndev = kinfo->netdev;
3058+
3059+
if (!netif_running(ndev))
3060+
return -EIO;
3061+
3062+
return hns3_nic_net_stop(ndev);
3063+
}
3064+
3065+
static int hns3_reset_notify_up_enet(struct hnae3_handle *handle)
3066+
{
3067+
struct hnae3_knic_private_info *kinfo = &handle->kinfo;
3068+
struct hns3_nic_priv *priv = netdev_priv(kinfo->netdev);
3069+
int ret = 0;
3070+
3071+
if (netif_running(kinfo->netdev)) {
3072+
ret = hns3_nic_net_up(kinfo->netdev);
3073+
if (ret) {
3074+
netdev_err(kinfo->netdev,
3075+
"hns net up fail, ret=%d!\n", ret);
3076+
return ret;
3077+
}
3078+
3079+
priv->last_reset_time = jiffies;
3080+
}
3081+
3082+
return ret;
3083+
}
3084+
3085+
static int hns3_reset_notify_init_enet(struct hnae3_handle *handle)
3086+
{
3087+
struct net_device *netdev = handle->kinfo.netdev;
3088+
struct hns3_nic_priv *priv = netdev_priv(netdev);
3089+
int ret;
3090+
3091+
priv->reset_level = 1;
3092+
hns3_init_mac_addr(netdev);
3093+
hns3_nic_set_rx_mode(netdev);
3094+
hns3_recover_hw_addr(netdev);
3095+
3096+
/* Carrier off reporting is important to ethtool even BEFORE open */
3097+
netif_carrier_off(netdev);
3098+
3099+
ret = hns3_get_ring_config(priv);
3100+
if (ret)
3101+
return ret;
3102+
3103+
ret = hns3_nic_init_vector_data(priv);
3104+
if (ret)
3105+
return ret;
3106+
3107+
ret = hns3_init_all_ring(priv);
3108+
if (ret) {
3109+
hns3_nic_uninit_vector_data(priv);
3110+
priv->ring_data = NULL;
3111+
}
3112+
3113+
return ret;
3114+
}
3115+
3116+
static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle)
3117+
{
3118+
struct net_device *netdev = handle->kinfo.netdev;
3119+
struct hns3_nic_priv *priv = netdev_priv(netdev);
3120+
int ret;
3121+
3122+
hns3_clear_all_ring(handle);
3123+
3124+
ret = hns3_nic_uninit_vector_data(priv);
3125+
if (ret) {
3126+
netdev_err(netdev, "uninit vector error\n");
3127+
return ret;
3128+
}
3129+
3130+
ret = hns3_uninit_all_ring(priv);
3131+
if (ret)
3132+
netdev_err(netdev, "uninit ring error\n");
3133+
3134+
priv->ring_data = NULL;
3135+
3136+
return ret;
3137+
}
3138+
3139+
static int hns3_reset_notify(struct hnae3_handle *handle,
3140+
enum hnae3_reset_notify_type type)
3141+
{
3142+
int ret = 0;
3143+
3144+
switch (type) {
3145+
case HNAE3_UP_CLIENT:
3146+
ret = hns3_reset_notify_up_enet(handle);
3147+
break;
3148+
case HNAE3_DOWN_CLIENT:
3149+
ret = hns3_reset_notify_down_enet(handle);
3150+
break;
3151+
case HNAE3_INIT_CLIENT:
3152+
ret = hns3_reset_notify_init_enet(handle);
3153+
break;
3154+
case HNAE3_UNINIT_CLIENT:
3155+
ret = hns3_reset_notify_uninit_enet(handle);
3156+
break;
3157+
default:
3158+
break;
3159+
}
3160+
3161+
return ret;
3162+
}
3163+
30123164
static const struct hnae3_client_ops client_ops = {
30133165
.init_instance = hns3_client_init,
30143166
.uninit_instance = hns3_client_uninit,
30153167
.link_status_change = hns3_link_status_change,
30163168
.setup_tc = hns3_client_setup_tc,
3169+
.reset_notify = hns3_reset_notify,
30173170
};
30183171

30193172
/* hns3_init_module - Driver registration routine

0 commit comments

Comments
 (0)