2018-07-19 23:47:06 +09:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
// Copyright (c) 2016-2017 Hisilicon Limited.
|
2017-08-03 00:59:50 +09:00
|
|
|
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/kernel.h>
|
2019-04-22 22:52:23 +09:00
|
|
|
#include <linux/marvell_phy.h>
|
2017-08-03 00:59:50 +09:00
|
|
|
|
|
|
|
#include "hclge_cmd.h"
|
|
|
|
#include "hclge_main.h"
|
|
|
|
#include "hclge_mdio.h"
|
|
|
|
|
|
|
|
enum hclge_mdio_c22_op_seq {
|
|
|
|
HCLGE_MDIO_C22_WRITE = 1,
|
|
|
|
HCLGE_MDIO_C22_READ = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
#define HCLGE_MDIO_CTRL_START_B 0
|
|
|
|
#define HCLGE_MDIO_CTRL_ST_S 1
|
|
|
|
#define HCLGE_MDIO_CTRL_ST_M (0x3 << HCLGE_MDIO_CTRL_ST_S)
|
|
|
|
#define HCLGE_MDIO_CTRL_OP_S 3
|
|
|
|
#define HCLGE_MDIO_CTRL_OP_M (0x3 << HCLGE_MDIO_CTRL_OP_S)
|
|
|
|
|
|
|
|
#define HCLGE_MDIO_PHYID_S 0
|
|
|
|
#define HCLGE_MDIO_PHYID_M (0x1f << HCLGE_MDIO_PHYID_S)
|
|
|
|
|
|
|
|
#define HCLGE_MDIO_PHYREG_S 0
|
|
|
|
#define HCLGE_MDIO_PHYREG_M (0x1f << HCLGE_MDIO_PHYREG_S)
|
|
|
|
|
|
|
|
#define HCLGE_MDIO_STA_B 0
|
|
|
|
|
|
|
|
struct hclge_mdio_cfg_cmd {
|
|
|
|
u8 ctrl_bit;
|
|
|
|
u8 phyid;
|
|
|
|
u8 phyad;
|
|
|
|
u8 rsvd;
|
|
|
|
__le16 reserve;
|
|
|
|
__le16 data_wr;
|
|
|
|
__le16 data_rd;
|
|
|
|
__le16 sta;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hclge_mdio_write(struct mii_bus *bus, int phyid, int regnum,
|
|
|
|
u16 data)
|
|
|
|
{
|
|
|
|
struct hclge_mdio_cfg_cmd *mdio_cmd;
|
|
|
|
struct hclge_dev *hdev = bus->priv;
|
|
|
|
struct hclge_desc desc;
|
|
|
|
int ret;
|
|
|
|
|
2018-10-30 22:50:49 +09:00
|
|
|
if (test_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state))
|
2018-03-24 12:32:47 +09:00
|
|
|
return 0;
|
|
|
|
|
2017-08-03 00:59:50 +09:00
|
|
|
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MDIO_CONFIG, false);
|
|
|
|
|
|
|
|
mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
|
|
|
|
|
2018-07-02 16:50:26 +09:00
|
|
|
hnae3_set_field(mdio_cmd->phyid, HCLGE_MDIO_PHYID_M,
|
2019-06-13 18:12:32 +09:00
|
|
|
HCLGE_MDIO_PHYID_S, (u32)phyid);
|
2018-07-02 16:50:26 +09:00
|
|
|
hnae3_set_field(mdio_cmd->phyad, HCLGE_MDIO_PHYREG_M,
|
2019-06-13 18:12:32 +09:00
|
|
|
HCLGE_MDIO_PHYREG_S, (u32)regnum);
|
2017-08-03 00:59:50 +09:00
|
|
|
|
2018-07-02 16:50:26 +09:00
|
|
|
hnae3_set_bit(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_START_B, 1);
|
|
|
|
hnae3_set_field(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_ST_M,
|
|
|
|
HCLGE_MDIO_CTRL_ST_S, 1);
|
|
|
|
hnae3_set_field(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_OP_M,
|
|
|
|
HCLGE_MDIO_CTRL_OP_S, HCLGE_MDIO_C22_WRITE);
|
2017-08-03 00:59:50 +09:00
|
|
|
|
|
|
|
mdio_cmd->data_wr = cpu_to_le16(data);
|
|
|
|
|
|
|
|
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&hdev->pdev->dev,
|
|
|
|
"mdio write fail when sending cmd, status is %d.\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hclge_mdio_read(struct mii_bus *bus, int phyid, int regnum)
|
|
|
|
{
|
|
|
|
struct hclge_mdio_cfg_cmd *mdio_cmd;
|
|
|
|
struct hclge_dev *hdev = bus->priv;
|
|
|
|
struct hclge_desc desc;
|
|
|
|
int ret;
|
|
|
|
|
2018-10-30 22:50:49 +09:00
|
|
|
if (test_bit(HCLGE_STATE_CMD_DISABLE, &hdev->state))
|
2018-03-24 12:32:47 +09:00
|
|
|
return 0;
|
|
|
|
|
2017-08-03 00:59:50 +09:00
|
|
|
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MDIO_CONFIG, true);
|
|
|
|
|
|
|
|
mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
|
|
|
|
|
2018-07-02 16:50:26 +09:00
|
|
|
hnae3_set_field(mdio_cmd->phyid, HCLGE_MDIO_PHYID_M,
|
2019-06-13 18:12:32 +09:00
|
|
|
HCLGE_MDIO_PHYID_S, (u32)phyid);
|
2018-07-02 16:50:26 +09:00
|
|
|
hnae3_set_field(mdio_cmd->phyad, HCLGE_MDIO_PHYREG_M,
|
2019-06-13 18:12:32 +09:00
|
|
|
HCLGE_MDIO_PHYREG_S, (u32)regnum);
|
2017-08-03 00:59:50 +09:00
|
|
|
|
2018-07-02 16:50:26 +09:00
|
|
|
hnae3_set_bit(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_START_B, 1);
|
|
|
|
hnae3_set_field(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_ST_M,
|
|
|
|
HCLGE_MDIO_CTRL_ST_S, 1);
|
|
|
|
hnae3_set_field(mdio_cmd->ctrl_bit, HCLGE_MDIO_CTRL_OP_M,
|
|
|
|
HCLGE_MDIO_CTRL_OP_S, HCLGE_MDIO_C22_READ);
|
2017-08-03 00:59:50 +09:00
|
|
|
|
|
|
|
/* Read out phy data */
|
|
|
|
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&hdev->pdev->dev,
|
|
|
|
"mdio read fail when get data, status is %d.\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-02 16:50:26 +09:00
|
|
|
if (hnae3_get_bit(le16_to_cpu(mdio_cmd->sta), HCLGE_MDIO_STA_B)) {
|
2017-08-03 00:59:50 +09:00
|
|
|
dev_err(&hdev->pdev->dev, "mdio read data error\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return le16_to_cpu(mdio_cmd->data_rd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int hclge_mac_mdio_config(struct hclge_dev *hdev)
|
|
|
|
{
|
2019-04-14 10:47:44 +09:00
|
|
|
#define PHY_INEXISTENT 255
|
|
|
|
|
2017-08-03 00:59:50 +09:00
|
|
|
struct hclge_mac *mac = &hdev->hw.mac;
|
|
|
|
struct phy_device *phydev;
|
|
|
|
struct mii_bus *mdio_bus;
|
|
|
|
int ret;
|
|
|
|
|
2019-04-14 10:47:44 +09:00
|
|
|
if (hdev->hw.mac.phy_addr == PHY_INEXISTENT) {
|
|
|
|
dev_info(&hdev->pdev->dev,
|
|
|
|
"no phy device is connected to mdio bus\n");
|
|
|
|
return 0;
|
|
|
|
} else if (hdev->hw.mac.phy_addr >= PHY_MAX_ADDR) {
|
2018-05-02 03:56:01 +09:00
|
|
|
dev_err(&hdev->pdev->dev, "phy_addr(%d) is too large.\n",
|
|
|
|
hdev->hw.mac.phy_addr);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-08-03 00:59:50 +09:00
|
|
|
|
|
|
|
mdio_bus = devm_mdiobus_alloc(&hdev->pdev->dev);
|
|
|
|
if (!mdio_bus)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
mdio_bus->name = "hisilicon MII bus";
|
|
|
|
mdio_bus->read = hclge_mdio_read;
|
|
|
|
mdio_bus->write = hclge_mdio_write;
|
|
|
|
snprintf(mdio_bus->id, MII_BUS_ID_SIZE, "%s-%s", "mii",
|
|
|
|
dev_name(&hdev->pdev->dev));
|
|
|
|
|
|
|
|
mdio_bus->parent = &hdev->pdev->dev;
|
|
|
|
mdio_bus->priv = hdev;
|
|
|
|
mdio_bus->phy_mask = ~(1 << mac->phy_addr);
|
|
|
|
ret = mdiobus_register(mdio_bus);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(mdio_bus->parent,
|
|
|
|
"Failed to register MDIO bus ret = %#x\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
phydev = mdiobus_get_phy(mdio_bus, mac->phy_addr);
|
2017-08-30 20:06:03 +09:00
|
|
|
if (!phydev) {
|
2017-08-03 00:59:50 +09:00
|
|
|
dev_err(mdio_bus->parent, "Failed to get phy device\n");
|
|
|
|
mdiobus_unregister(mdio_bus);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
mac->phydev = phydev;
|
|
|
|
mac->mdio_bus = mdio_bus;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hclge_mac_adjust_link(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct hnae3_handle *h = *((void **)netdev_priv(netdev));
|
|
|
|
struct hclge_vport *vport = hclge_get_vport(h);
|
|
|
|
struct hclge_dev *hdev = vport->back;
|
|
|
|
int duplex, speed;
|
|
|
|
int ret;
|
|
|
|
|
2018-12-18 20:37:56 +09:00
|
|
|
/* When phy link down, do nothing */
|
|
|
|
if (netdev->phydev->link == 0)
|
|
|
|
return;
|
|
|
|
|
2017-08-03 00:59:50 +09:00
|
|
|
speed = netdev->phydev->speed;
|
|
|
|
duplex = netdev->phydev->duplex;
|
|
|
|
|
|
|
|
ret = hclge_cfg_mac_speed_dup(hdev, speed, duplex);
|
|
|
|
if (ret)
|
|
|
|
netdev_err(netdev, "failed to adjust link.\n");
|
2017-12-22 13:21:52 +09:00
|
|
|
|
|
|
|
ret = hclge_cfg_flowctrl(hdev);
|
|
|
|
if (ret)
|
|
|
|
netdev_err(netdev, "failed to configure flow control.\n");
|
2017-08-03 00:59:50 +09:00
|
|
|
}
|
|
|
|
|
net: hns3: Fix NULL deref when unloading driver
When the driver is unloading, if there is a calling of ndo_open occurs
between phy_disconnect() and unregister_netdev(), it will end up
causing the kernel to eventually hit a NULL deref:
[14942.417828] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000048
[14942.529878] Mem abort info:
[14942.551166] ESR = 0x96000006
[14942.567070] Exception class = DABT (current EL), IL = 32 bits
[14942.623081] SET = 0, FnV = 0
[14942.639112] EA = 0, S1PTW = 0
[14942.643628] Data abort info:
[14942.659227] ISV = 0, ISS = 0x00000006
[14942.674870] CM = 0, WnR = 0
[14942.679449] user pgtable: 4k pages, 48-bit VAs, pgdp = 00000000224ad6ad
[14942.695595] [0000000000000048] pgd=00000021e6673003, pud=00000021dbf01003, pmd=0000000000000000
[14942.723163] Internal error: Oops: 96000006 [#1] PREEMPT SMP
[14942.729358] Modules linked in: hns3(O) hclge(O) pv680_mii(O) hnae3(O) [last unloaded: hclge]
[14942.738907] CPU: 1 PID: 26629 Comm: kworker/u4:13 Tainted: G O 4.18.0-rc1-12928-ga960791-dirty #145
[14942.749491] Hardware name: Huawei Technologies Co., Ltd. D05/D05, BIOS Hi1620 FPGA TB BOOT BIOS B763 08/17/2018
[14942.760392] Workqueue: events_power_efficient phy_state_machine
[14942.766644] pstate: 80c00009 (Nzcv daif +PAN +UAO)
[14942.771918] pc : test_and_set_bit+0x18/0x38
[14942.776589] lr : netif_carrier_off+0x24/0x70
[14942.781033] sp : ffff0000121abd20
[14942.784518] x29: ffff0000121abd20 x28: 0000000000000000
[14942.790208] x27: ffff0000164d3cd8 x26: ffff8021da68b7b8
[14942.795832] x25: 0000000000000000 x24: ffff8021eb407800
[14942.801445] x23: 0000000000000000 x22: 0000000000000000
[14942.807046] x21: 0000000000000001 x20: 0000000000000000
[14942.812672] x19: 0000000000000000 x18: ffff000009781708
[14942.818284] x17: 00000000004970e8 x16: ffff00000816ad48
[14942.823900] x15: 0000000000000000 x14: 0000000000000008
[14942.829528] x13: 0000000000000000 x12: 0000000000000f65
[14942.835149] x11: 0000000000000001 x10: 00000000000009d0
[14942.840753] x9 : ffff0000121abaa0 x8 : 0000000000000000
[14942.846360] x7 : ffff000009781708 x6 : 0000000000000003
[14942.851970] x5 : 0000000000000020 x4 : 0000000000000004
[14942.857575] x3 : 0000000000000002 x2 : 0000000000000001
[14942.863180] x1 : 0000000000000048 x0 : 0000000000000000
[14942.868875] Process kworker/u4:13 (pid: 26629, stack limit = 0x00000000c909dbf3)
[14942.876464] Call trace:
[14942.879200] test_and_set_bit+0x18/0x38
[14942.883376] phy_link_change+0x38/0x78
[14942.887378] phy_state_machine+0x3dc/0x4f8
[14942.891968] process_one_work+0x158/0x470
[14942.896223] worker_thread+0x50/0x470
[14942.900219] kthread+0x104/0x130
[14942.903905] ret_from_fork+0x10/0x1c
[14942.907755] Code: d2800022 8b400c21 f9800031 9ac32044 (c85f7c22)
[14942.914185] ---[ end trace 968c9e12eb740b23 ]---
So this patch fixes it by modifying the timing to do phy_connect_direct()
and phy_disconnect().
Fixes: 256727da7395 ("net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC")
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-01-31 05:55:46 +09:00
|
|
|
int hclge_mac_connect_phy(struct hnae3_handle *handle)
|
2017-08-03 00:59:50 +09:00
|
|
|
{
|
net: hns3: Fix NULL deref when unloading driver
When the driver is unloading, if there is a calling of ndo_open occurs
between phy_disconnect() and unregister_netdev(), it will end up
causing the kernel to eventually hit a NULL deref:
[14942.417828] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000048
[14942.529878] Mem abort info:
[14942.551166] ESR = 0x96000006
[14942.567070] Exception class = DABT (current EL), IL = 32 bits
[14942.623081] SET = 0, FnV = 0
[14942.639112] EA = 0, S1PTW = 0
[14942.643628] Data abort info:
[14942.659227] ISV = 0, ISS = 0x00000006
[14942.674870] CM = 0, WnR = 0
[14942.679449] user pgtable: 4k pages, 48-bit VAs, pgdp = 00000000224ad6ad
[14942.695595] [0000000000000048] pgd=00000021e6673003, pud=00000021dbf01003, pmd=0000000000000000
[14942.723163] Internal error: Oops: 96000006 [#1] PREEMPT SMP
[14942.729358] Modules linked in: hns3(O) hclge(O) pv680_mii(O) hnae3(O) [last unloaded: hclge]
[14942.738907] CPU: 1 PID: 26629 Comm: kworker/u4:13 Tainted: G O 4.18.0-rc1-12928-ga960791-dirty #145
[14942.749491] Hardware name: Huawei Technologies Co., Ltd. D05/D05, BIOS Hi1620 FPGA TB BOOT BIOS B763 08/17/2018
[14942.760392] Workqueue: events_power_efficient phy_state_machine
[14942.766644] pstate: 80c00009 (Nzcv daif +PAN +UAO)
[14942.771918] pc : test_and_set_bit+0x18/0x38
[14942.776589] lr : netif_carrier_off+0x24/0x70
[14942.781033] sp : ffff0000121abd20
[14942.784518] x29: ffff0000121abd20 x28: 0000000000000000
[14942.790208] x27: ffff0000164d3cd8 x26: ffff8021da68b7b8
[14942.795832] x25: 0000000000000000 x24: ffff8021eb407800
[14942.801445] x23: 0000000000000000 x22: 0000000000000000
[14942.807046] x21: 0000000000000001 x20: 0000000000000000
[14942.812672] x19: 0000000000000000 x18: ffff000009781708
[14942.818284] x17: 00000000004970e8 x16: ffff00000816ad48
[14942.823900] x15: 0000000000000000 x14: 0000000000000008
[14942.829528] x13: 0000000000000000 x12: 0000000000000f65
[14942.835149] x11: 0000000000000001 x10: 00000000000009d0
[14942.840753] x9 : ffff0000121abaa0 x8 : 0000000000000000
[14942.846360] x7 : ffff000009781708 x6 : 0000000000000003
[14942.851970] x5 : 0000000000000020 x4 : 0000000000000004
[14942.857575] x3 : 0000000000000002 x2 : 0000000000000001
[14942.863180] x1 : 0000000000000048 x0 : 0000000000000000
[14942.868875] Process kworker/u4:13 (pid: 26629, stack limit = 0x00000000c909dbf3)
[14942.876464] Call trace:
[14942.879200] test_and_set_bit+0x18/0x38
[14942.883376] phy_link_change+0x38/0x78
[14942.887378] phy_state_machine+0x3dc/0x4f8
[14942.891968] process_one_work+0x158/0x470
[14942.896223] worker_thread+0x50/0x470
[14942.900219] kthread+0x104/0x130
[14942.903905] ret_from_fork+0x10/0x1c
[14942.907755] Code: d2800022 8b400c21 f9800031 9ac32044 (c85f7c22)
[14942.914185] ---[ end trace 968c9e12eb740b23 ]---
So this patch fixes it by modifying the timing to do phy_connect_direct()
and phy_disconnect().
Fixes: 256727da7395 ("net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC")
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-01-31 05:55:46 +09:00
|
|
|
struct hclge_vport *vport = hclge_get_vport(handle);
|
|
|
|
struct hclge_dev *hdev = vport->back;
|
2017-08-03 00:59:50 +09:00
|
|
|
struct net_device *netdev = hdev->vport[0].nic.netdev;
|
|
|
|
struct phy_device *phydev = hdev->hw.mac.phydev;
|
2018-11-11 07:43:33 +09:00
|
|
|
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
|
2017-08-03 00:59:50 +09:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!phydev)
|
|
|
|
return 0;
|
|
|
|
|
2018-11-11 07:43:33 +09:00
|
|
|
linkmode_clear_bit(ETHTOOL_LINK_MODE_FIBRE_BIT, phydev->supported);
|
2018-08-15 01:13:15 +09:00
|
|
|
|
2019-04-22 22:52:23 +09:00
|
|
|
phydev->dev_flags |= MARVELL_PHY_LED0_LINK_LED1_ACTIVE;
|
|
|
|
|
2017-08-03 00:59:50 +09:00
|
|
|
ret = phy_connect_direct(netdev, phydev,
|
|
|
|
hclge_mac_adjust_link,
|
|
|
|
PHY_INTERFACE_MODE_SGMII);
|
|
|
|
if (ret) {
|
|
|
|
netdev_err(netdev, "phy_connect_direct err.\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-20 11:32:43 +09:00
|
|
|
linkmode_copy(mask, hdev->hw.mac.supported);
|
2018-11-11 07:43:33 +09:00
|
|
|
linkmode_and(phydev->supported, phydev->supported, mask);
|
2019-02-20 11:32:43 +09:00
|
|
|
linkmode_copy(phydev->advertising, phydev->supported);
|
2017-11-03 13:18:30 +09:00
|
|
|
|
net: hns3: add Asym Pause support to fix autoneg problem
Local device and link partner config auto-negotiation on both,
local device config pause frame use as: rx on/tx off,
link partner config pause frame use as: rx off/tx on.
We except the result is:
Local device:
Autonegotiate: on
RX: on
TX: off
RX negotiated: on
TX negotiated: off
Link partner:
Autonegotiate: on
RX: off
TX: on
RX negotiated: off
TX negotiated: on
But actually, the result of Local device and link partner is both:
Autonegotiate: on
RX: off
TX: off
RX negotiated: off
TX negotiated: off
The root cause is that the supported flag is has only Pause,
reference to the function genphy_config_advert():
static int genphy_config_advert(struct phy_device *phydev)
{
...
linkmode_and(phydev->advertising, phydev->advertising,
phydev->supported);
...
}
The pause frame use of link partner is rx off/tx on, so its
advertising only set the bit Asym_Pause, and the supported is
only set the bit Pause, so the result of linkmode_and(), is
rx off/tx off.
This patch adds Asym_Pause to the supported flag to fix it.
Signed-off-by: Yonglong Liu <liuyonglong@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-28 20:50:12 +09:00
|
|
|
/* supported flag is Pause and Asym Pause, but default advertising
|
|
|
|
* should be rx on, tx on, so need clear Asym Pause in advertising
|
|
|
|
* flag
|
|
|
|
*/
|
|
|
|
linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
|
|
|
|
phydev->advertising);
|
|
|
|
|
2019-08-16 17:09:42 +09:00
|
|
|
phy_attached_info(phydev);
|
|
|
|
|
2017-08-03 00:59:50 +09:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
net: hns3: Fix NULL deref when unloading driver
When the driver is unloading, if there is a calling of ndo_open occurs
between phy_disconnect() and unregister_netdev(), it will end up
causing the kernel to eventually hit a NULL deref:
[14942.417828] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000048
[14942.529878] Mem abort info:
[14942.551166] ESR = 0x96000006
[14942.567070] Exception class = DABT (current EL), IL = 32 bits
[14942.623081] SET = 0, FnV = 0
[14942.639112] EA = 0, S1PTW = 0
[14942.643628] Data abort info:
[14942.659227] ISV = 0, ISS = 0x00000006
[14942.674870] CM = 0, WnR = 0
[14942.679449] user pgtable: 4k pages, 48-bit VAs, pgdp = 00000000224ad6ad
[14942.695595] [0000000000000048] pgd=00000021e6673003, pud=00000021dbf01003, pmd=0000000000000000
[14942.723163] Internal error: Oops: 96000006 [#1] PREEMPT SMP
[14942.729358] Modules linked in: hns3(O) hclge(O) pv680_mii(O) hnae3(O) [last unloaded: hclge]
[14942.738907] CPU: 1 PID: 26629 Comm: kworker/u4:13 Tainted: G O 4.18.0-rc1-12928-ga960791-dirty #145
[14942.749491] Hardware name: Huawei Technologies Co., Ltd. D05/D05, BIOS Hi1620 FPGA TB BOOT BIOS B763 08/17/2018
[14942.760392] Workqueue: events_power_efficient phy_state_machine
[14942.766644] pstate: 80c00009 (Nzcv daif +PAN +UAO)
[14942.771918] pc : test_and_set_bit+0x18/0x38
[14942.776589] lr : netif_carrier_off+0x24/0x70
[14942.781033] sp : ffff0000121abd20
[14942.784518] x29: ffff0000121abd20 x28: 0000000000000000
[14942.790208] x27: ffff0000164d3cd8 x26: ffff8021da68b7b8
[14942.795832] x25: 0000000000000000 x24: ffff8021eb407800
[14942.801445] x23: 0000000000000000 x22: 0000000000000000
[14942.807046] x21: 0000000000000001 x20: 0000000000000000
[14942.812672] x19: 0000000000000000 x18: ffff000009781708
[14942.818284] x17: 00000000004970e8 x16: ffff00000816ad48
[14942.823900] x15: 0000000000000000 x14: 0000000000000008
[14942.829528] x13: 0000000000000000 x12: 0000000000000f65
[14942.835149] x11: 0000000000000001 x10: 00000000000009d0
[14942.840753] x9 : ffff0000121abaa0 x8 : 0000000000000000
[14942.846360] x7 : ffff000009781708 x6 : 0000000000000003
[14942.851970] x5 : 0000000000000020 x4 : 0000000000000004
[14942.857575] x3 : 0000000000000002 x2 : 0000000000000001
[14942.863180] x1 : 0000000000000048 x0 : 0000000000000000
[14942.868875] Process kworker/u4:13 (pid: 26629, stack limit = 0x00000000c909dbf3)
[14942.876464] Call trace:
[14942.879200] test_and_set_bit+0x18/0x38
[14942.883376] phy_link_change+0x38/0x78
[14942.887378] phy_state_machine+0x3dc/0x4f8
[14942.891968] process_one_work+0x158/0x470
[14942.896223] worker_thread+0x50/0x470
[14942.900219] kthread+0x104/0x130
[14942.903905] ret_from_fork+0x10/0x1c
[14942.907755] Code: d2800022 8b400c21 f9800031 9ac32044 (c85f7c22)
[14942.914185] ---[ end trace 968c9e12eb740b23 ]---
So this patch fixes it by modifying the timing to do phy_connect_direct()
and phy_disconnect().
Fixes: 256727da7395 ("net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC")
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-01-31 05:55:46 +09:00
|
|
|
void hclge_mac_disconnect_phy(struct hnae3_handle *handle)
|
2018-08-15 01:13:14 +09:00
|
|
|
{
|
net: hns3: Fix NULL deref when unloading driver
When the driver is unloading, if there is a calling of ndo_open occurs
between phy_disconnect() and unregister_netdev(), it will end up
causing the kernel to eventually hit a NULL deref:
[14942.417828] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000048
[14942.529878] Mem abort info:
[14942.551166] ESR = 0x96000006
[14942.567070] Exception class = DABT (current EL), IL = 32 bits
[14942.623081] SET = 0, FnV = 0
[14942.639112] EA = 0, S1PTW = 0
[14942.643628] Data abort info:
[14942.659227] ISV = 0, ISS = 0x00000006
[14942.674870] CM = 0, WnR = 0
[14942.679449] user pgtable: 4k pages, 48-bit VAs, pgdp = 00000000224ad6ad
[14942.695595] [0000000000000048] pgd=00000021e6673003, pud=00000021dbf01003, pmd=0000000000000000
[14942.723163] Internal error: Oops: 96000006 [#1] PREEMPT SMP
[14942.729358] Modules linked in: hns3(O) hclge(O) pv680_mii(O) hnae3(O) [last unloaded: hclge]
[14942.738907] CPU: 1 PID: 26629 Comm: kworker/u4:13 Tainted: G O 4.18.0-rc1-12928-ga960791-dirty #145
[14942.749491] Hardware name: Huawei Technologies Co., Ltd. D05/D05, BIOS Hi1620 FPGA TB BOOT BIOS B763 08/17/2018
[14942.760392] Workqueue: events_power_efficient phy_state_machine
[14942.766644] pstate: 80c00009 (Nzcv daif +PAN +UAO)
[14942.771918] pc : test_and_set_bit+0x18/0x38
[14942.776589] lr : netif_carrier_off+0x24/0x70
[14942.781033] sp : ffff0000121abd20
[14942.784518] x29: ffff0000121abd20 x28: 0000000000000000
[14942.790208] x27: ffff0000164d3cd8 x26: ffff8021da68b7b8
[14942.795832] x25: 0000000000000000 x24: ffff8021eb407800
[14942.801445] x23: 0000000000000000 x22: 0000000000000000
[14942.807046] x21: 0000000000000001 x20: 0000000000000000
[14942.812672] x19: 0000000000000000 x18: ffff000009781708
[14942.818284] x17: 00000000004970e8 x16: ffff00000816ad48
[14942.823900] x15: 0000000000000000 x14: 0000000000000008
[14942.829528] x13: 0000000000000000 x12: 0000000000000f65
[14942.835149] x11: 0000000000000001 x10: 00000000000009d0
[14942.840753] x9 : ffff0000121abaa0 x8 : 0000000000000000
[14942.846360] x7 : ffff000009781708 x6 : 0000000000000003
[14942.851970] x5 : 0000000000000020 x4 : 0000000000000004
[14942.857575] x3 : 0000000000000002 x2 : 0000000000000001
[14942.863180] x1 : 0000000000000048 x0 : 0000000000000000
[14942.868875] Process kworker/u4:13 (pid: 26629, stack limit = 0x00000000c909dbf3)
[14942.876464] Call trace:
[14942.879200] test_and_set_bit+0x18/0x38
[14942.883376] phy_link_change+0x38/0x78
[14942.887378] phy_state_machine+0x3dc/0x4f8
[14942.891968] process_one_work+0x158/0x470
[14942.896223] worker_thread+0x50/0x470
[14942.900219] kthread+0x104/0x130
[14942.903905] ret_from_fork+0x10/0x1c
[14942.907755] Code: d2800022 8b400c21 f9800031 9ac32044 (c85f7c22)
[14942.914185] ---[ end trace 968c9e12eb740b23 ]---
So this patch fixes it by modifying the timing to do phy_connect_direct()
and phy_disconnect().
Fixes: 256727da7395 ("net: hns3: Add MDIO support to HNS3 Ethernet driver for hip08 SoC")
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-01-31 05:55:46 +09:00
|
|
|
struct hclge_vport *vport = hclge_get_vport(handle);
|
|
|
|
struct hclge_dev *hdev = vport->back;
|
2018-08-15 01:13:14 +09:00
|
|
|
struct phy_device *phydev = hdev->hw.mac.phydev;
|
|
|
|
|
|
|
|
if (!phydev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
phy_disconnect(phydev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hclge_mac_start_phy(struct hclge_dev *hdev)
|
|
|
|
{
|
|
|
|
struct phy_device *phydev = hdev->hw.mac.phydev;
|
|
|
|
|
|
|
|
if (!phydev)
|
|
|
|
return;
|
|
|
|
|
2021-04-30 18:06:22 +09:00
|
|
|
phy_loopback(phydev, false);
|
|
|
|
|
2018-08-15 01:13:14 +09:00
|
|
|
phy_start(phydev);
|
|
|
|
}
|
|
|
|
|
2017-08-03 00:59:50 +09:00
|
|
|
void hclge_mac_stop_phy(struct hclge_dev *hdev)
|
|
|
|
{
|
|
|
|
struct net_device *netdev = hdev->vport[0].nic.netdev;
|
|
|
|
struct phy_device *phydev = netdev->phydev;
|
|
|
|
|
|
|
|
if (!phydev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
phy_stop(phydev);
|
|
|
|
}
|