Skip to content

Commit

Permalink
Merge branch 'net-hns3-updates-for-next'
Browse files Browse the repository at this point in the history
Guangbin Huang says:

====================
net: hns3: updates for -next

This series includes some updates for the HNS3 ethernet driver.
====================

Link: https://lore.kernel.org/r/20220916023803.23756-1-huangguangbin2@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Sep 21, 2022
2 parents 6fb4825 + 236b8f5 commit 6287e55
Show file tree
Hide file tree
Showing 11 changed files with 454 additions and 219 deletions.
11 changes: 11 additions & 0 deletions drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ struct hclgevf_mbx_arq_ring {
__le16 msg_q[HCLGE_MBX_MAX_ARQ_MSG_NUM][HCLGE_MBX_MAX_ARQ_MSG_SIZE];
};

struct hclge_dev;

#define HCLGE_MBX_OPCODE_MAX 256
struct hclge_mbx_ops_param {
struct hclge_vport *vport;
struct hclge_mbx_vf_to_pf_cmd *req;
struct hclge_respond_to_vf_msg *resp_msg;
};

typedef int (*hclge_mbx_ops_fn)(struct hclge_mbx_ops_param *param);

#define hclge_mbx_ring_ptr_move_crq(crq) \
(crq->next_to_use = (crq->next_to_use + 1) % crq->desc_num)
#define hclge_mbx_tail_ptr_move_arq(arq) \
Expand Down
6 changes: 6 additions & 0 deletions drivers/net/ethernet/hisilicon/hns3/hnae3.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ struct hns3_mac_stats {

/* hnae3 loop mode */
enum hnae3_loop {
HNAE3_LOOP_EXTERNAL,
HNAE3_LOOP_APP,
HNAE3_LOOP_SERIAL_SERDES,
HNAE3_LOOP_PARALLEL_SERDES,
Expand Down Expand Up @@ -797,6 +798,8 @@ struct hnae3_tc_info {
bool mqprio_active;
};

#define HNAE3_MAX_DSCP 64
#define HNAE3_PRIO_ID_INVALID 0xff
struct hnae3_knic_private_info {
struct net_device *netdev; /* Set by KNIC client when init instance */
u16 rss_size; /* Allocated RSS queues */
Expand All @@ -808,6 +811,8 @@ struct hnae3_knic_private_info {

struct hnae3_tc_info tc_info;
u8 tc_map_mode;
u8 dscp_app_cnt;
u8 dscp_prio[HNAE3_MAX_DSCP];

u16 num_tqps; /* total number of TQPs in this handle */
struct hnae3_queue **tqp; /* array base of all TQPs in this instance */
Expand Down Expand Up @@ -839,6 +844,7 @@ struct hnae3_roce_private_info {
#define HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK BIT(2)
#define HNAE3_SUPPORT_VF BIT(3)
#define HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK BIT(4)
#define HNAE3_SUPPORT_EXTERNAL_LOOPBACK BIT(5)

#define HNAE3_USER_UPE BIT(0) /* unicast promisc enabled by user */
#define HNAE3_USER_MPE BIT(1) /* mulitcast promisc enabled by user */
Expand Down
64 changes: 56 additions & 8 deletions drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -2987,22 +2987,19 @@ static u16 hns3_nic_select_queue(struct net_device *netdev,
struct net_device *sb_dev)
{
struct hnae3_handle *h = hns3_get_handle(netdev);
u8 dscp, priority;
int ret;
u8 dscp;

if (h->kinfo.tc_map_mode != HNAE3_TC_MAP_MODE_DSCP ||
!h->ae_algo->ops->get_dscp_prio)
goto out;

dscp = hns3_get_skb_dscp(skb);
if (unlikely(dscp == HNS3_INVALID_DSCP))
goto out;

ret = h->ae_algo->ops->get_dscp_prio(h, dscp, NULL, &priority);
if (ret)
if (unlikely(dscp >= HNAE3_MAX_DSCP))
goto out;

skb->priority = priority;
skb->priority = h->kinfo.dscp_prio[dscp];
if (skb->priority == HNAE3_PRIO_ID_INVALID)
skb->priority = 0;

out:
return netdev_pick_tx(netdev, skb, sb_dev);
Expand Down Expand Up @@ -5827,6 +5824,57 @@ int hns3_set_channels(struct net_device *netdev,
return 0;
}

void hns3_external_lb_prepare(struct net_device *ndev, bool if_running)
{
struct hns3_nic_priv *priv = netdev_priv(ndev);
struct hnae3_handle *h = priv->ae_handle;
int i;

if (!if_running)
return;

netif_carrier_off(ndev);
netif_tx_disable(ndev);

for (i = 0; i < priv->vector_num; i++)
hns3_vector_disable(&priv->tqp_vector[i]);

for (i = 0; i < h->kinfo.num_tqps; i++)
hns3_tqp_disable(h->kinfo.tqp[i]);

/* delay ring buffer clearing to hns3_reset_notify_uninit_enet
* during reset process, because driver may not be able
* to disable the ring through firmware when downing the netdev.
*/
if (!hns3_nic_resetting(ndev))
hns3_nic_reset_all_ring(priv->ae_handle);

hns3_reset_tx_queue(priv->ae_handle);
}

void hns3_external_lb_restore(struct net_device *ndev, bool if_running)
{
struct hns3_nic_priv *priv = netdev_priv(ndev);
struct hnae3_handle *h = priv->ae_handle;
int i;

if (!if_running)
return;

hns3_nic_reset_all_ring(priv->ae_handle);

for (i = 0; i < priv->vector_num; i++)
hns3_vector_enable(&priv->tqp_vector[i]);

for (i = 0; i < h->kinfo.num_tqps; i++)
hns3_tqp_enable(h->kinfo.tqp[i]);

netif_tx_wake_all_queues(ndev);

if (h->ae_algo->ops->get_status(h))
netif_carrier_on(ndev);
}

static const struct hns3_hw_error_info hns3_hw_err[] = {
{ .type = HNAE3_PPU_POISON_ERROR,
.msg = "PPU poison" },
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,4 +744,7 @@ u16 hns3_get_max_available_channels(struct hnae3_handle *h);
void hns3_cq_period_mode_init(struct hns3_nic_priv *priv,
enum dim_cq_period_mode tx_mode,
enum dim_cq_period_mode rx_mode);

void hns3_external_lb_prepare(struct net_device *ndev, bool if_running);
void hns3_external_lb_restore(struct net_device *ndev, bool if_running);
#endif
61 changes: 44 additions & 17 deletions drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ static const struct hns3_stats hns3_rxq_stats[] = {

#define HNS3_TQP_STATS_COUNT (HNS3_TXQ_STATS_COUNT + HNS3_RXQ_STATS_COUNT)

#define HNS3_SELF_TEST_TYPE_NUM 4
#define HNS3_NIC_LB_TEST_PKT_NUM 1
#define HNS3_NIC_LB_TEST_RING_ID 0
#define HNS3_NIC_LB_TEST_PACKET_SIZE 128
Expand All @@ -95,6 +94,7 @@ static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop, bool en)
case HNAE3_LOOP_PARALLEL_SERDES:
case HNAE3_LOOP_APP:
case HNAE3_LOOP_PHY:
case HNAE3_LOOP_EXTERNAL:
ret = h->ae_algo->ops->set_loopback(h, loop, en);
break;
default:
Expand Down Expand Up @@ -304,6 +304,10 @@ static int hns3_lp_run_test(struct net_device *ndev, enum hnae3_loop mode)

static void hns3_set_selftest_param(struct hnae3_handle *h, int (*st_param)[2])
{
st_param[HNAE3_LOOP_EXTERNAL][0] = HNAE3_LOOP_EXTERNAL;
st_param[HNAE3_LOOP_EXTERNAL][1] =
h->flags & HNAE3_SUPPORT_EXTERNAL_LOOPBACK;

st_param[HNAE3_LOOP_APP][0] = HNAE3_LOOP_APP;
st_param[HNAE3_LOOP_APP][1] =
h->flags & HNAE3_SUPPORT_APP_LOOPBACK;
Expand All @@ -322,17 +326,11 @@ static void hns3_set_selftest_param(struct hnae3_handle *h, int (*st_param)[2])
h->flags & HNAE3_SUPPORT_PHY_LOOPBACK;
}

static void hns3_selftest_prepare(struct net_device *ndev,
bool if_running, int (*st_param)[2])
static void hns3_selftest_prepare(struct net_device *ndev, bool if_running)
{
struct hns3_nic_priv *priv = netdev_priv(ndev);
struct hnae3_handle *h = priv->ae_handle;

if (netif_msg_ifdown(h))
netdev_info(ndev, "self test start\n");

hns3_set_selftest_param(h, st_param);

if (if_running)
ndev->netdev_ops->ndo_stop(ndev);

Expand Down Expand Up @@ -371,18 +369,15 @@ static void hns3_selftest_restore(struct net_device *ndev, bool if_running)

if (if_running)
ndev->netdev_ops->ndo_open(ndev);

if (netif_msg_ifdown(h))
netdev_info(ndev, "self test end\n");
}

static void hns3_do_selftest(struct net_device *ndev, int (*st_param)[2],
struct ethtool_test *eth_test, u64 *data)
{
int test_index = 0;
int test_index = HNAE3_LOOP_APP;
u32 i;

for (i = 0; i < HNS3_SELF_TEST_TYPE_NUM; i++) {
for (i = HNAE3_LOOP_APP; i < HNAE3_LOOP_NONE; i++) {
enum hnae3_loop loop_type = (enum hnae3_loop)st_param[i][0];

if (!st_param[i][1])
Expand All @@ -401,6 +396,20 @@ static void hns3_do_selftest(struct net_device *ndev, int (*st_param)[2],
}
}

static void hns3_do_external_lb(struct net_device *ndev,
struct ethtool_test *eth_test, u64 *data)
{
data[HNAE3_LOOP_EXTERNAL] = hns3_lp_up(ndev, HNAE3_LOOP_EXTERNAL);
if (!data[HNAE3_LOOP_EXTERNAL])
data[HNAE3_LOOP_EXTERNAL] = hns3_lp_run_test(ndev, HNAE3_LOOP_EXTERNAL);
hns3_lp_down(ndev, HNAE3_LOOP_EXTERNAL);

if (data[HNAE3_LOOP_EXTERNAL])
eth_test->flags |= ETH_TEST_FL_FAILED;

eth_test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
}

/**
* hns3_self_test - self test
* @ndev: net device
Expand All @@ -410,21 +419,39 @@ static void hns3_do_selftest(struct net_device *ndev, int (*st_param)[2],
static void hns3_self_test(struct net_device *ndev,
struct ethtool_test *eth_test, u64 *data)
{
int st_param[HNS3_SELF_TEST_TYPE_NUM][2];
struct hns3_nic_priv *priv = netdev_priv(ndev);
struct hnae3_handle *h = priv->ae_handle;
int st_param[HNAE3_LOOP_NONE][2];
bool if_running = netif_running(ndev);

if (hns3_nic_resetting(ndev)) {
netdev_err(ndev, "dev resetting!");
return;
}

/* Only do offline selftest, or pass by default */
if (eth_test->flags != ETH_TEST_FL_OFFLINE)
if (!(eth_test->flags & ETH_TEST_FL_OFFLINE))
return;

hns3_selftest_prepare(ndev, if_running, st_param);
if (netif_msg_ifdown(h))
netdev_info(ndev, "self test start\n");

hns3_set_selftest_param(h, st_param);

/* external loopback test requires that the link is up and the duplex is
* full, do external test first to reduce the whole test time
*/
if (eth_test->flags & ETH_TEST_FL_EXTERNAL_LB) {
hns3_external_lb_prepare(ndev, if_running);
hns3_do_external_lb(ndev, eth_test, data);
hns3_external_lb_restore(ndev, if_running);
}

hns3_selftest_prepare(ndev, if_running);
hns3_do_selftest(ndev, st_param, eth_test, data);
hns3_selftest_restore(ndev, if_running);

if (netif_msg_ifdown(h))
netdev_info(ndev, "self test end\n");
}

static void hns3_update_limit_promisc_mode(struct net_device *netdev,
Expand Down
28 changes: 14 additions & 14 deletions drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ static int hclge_ieee_setapp(struct hnae3_handle *h, struct dcb_app *app)
int ret;

if (app->selector != IEEE_8021QAZ_APP_SEL_DSCP ||
app->protocol >= HCLGE_MAX_DSCP ||
app->protocol >= HNAE3_MAX_DSCP ||
app->priority >= HNAE3_MAX_USER_PRIO)
return -EINVAL;

dev_info(&hdev->pdev->dev, "setapp dscp=%u priority=%u\n",
app->protocol, app->priority);

if (app->priority == hdev->tm_info.dscp_prio[app->protocol])
if (app->priority == h->kinfo.dscp_prio[app->protocol])
return 0;

ret = dcb_ieee_setapp(netdev, app);
Expand All @@ -384,21 +384,21 @@ static int hclge_ieee_setapp(struct hnae3_handle *h, struct dcb_app *app)

old_app.selector = IEEE_8021QAZ_APP_SEL_DSCP;
old_app.protocol = app->protocol;
old_app.priority = hdev->tm_info.dscp_prio[app->protocol];
old_app.priority = h->kinfo.dscp_prio[app->protocol];

hdev->tm_info.dscp_prio[app->protocol] = app->priority;
h->kinfo.dscp_prio[app->protocol] = app->priority;
ret = hclge_dscp_to_tc_map(hdev);
if (ret) {
dev_err(&hdev->pdev->dev,
"failed to set dscp to tc map, ret = %d\n", ret);
hdev->tm_info.dscp_prio[app->protocol] = old_app.priority;
h->kinfo.dscp_prio[app->protocol] = old_app.priority;
(void)dcb_ieee_delapp(netdev, app);
return ret;
}

vport->nic.kinfo.tc_map_mode = HNAE3_TC_MAP_MODE_DSCP;
if (old_app.priority == HCLGE_PRIO_ID_INVALID)
hdev->tm_info.dscp_app_cnt++;
if (old_app.priority == HNAE3_PRIO_ID_INVALID)
h->kinfo.dscp_app_cnt++;
else
ret = dcb_ieee_delapp(netdev, &old_app);

Expand All @@ -413,9 +413,9 @@ static int hclge_ieee_delapp(struct hnae3_handle *h, struct dcb_app *app)
int ret;

if (app->selector != IEEE_8021QAZ_APP_SEL_DSCP ||
app->protocol >= HCLGE_MAX_DSCP ||
app->protocol >= HNAE3_MAX_DSCP ||
app->priority >= HNAE3_MAX_USER_PRIO ||
app->priority != hdev->tm_info.dscp_prio[app->protocol])
app->priority != h->kinfo.dscp_prio[app->protocol])
return -EINVAL;

dev_info(&hdev->pdev->dev, "delapp dscp=%u priority=%u\n",
Expand All @@ -425,20 +425,20 @@ static int hclge_ieee_delapp(struct hnae3_handle *h, struct dcb_app *app)
if (ret)
return ret;

hdev->tm_info.dscp_prio[app->protocol] = HCLGE_PRIO_ID_INVALID;
h->kinfo.dscp_prio[app->protocol] = HNAE3_PRIO_ID_INVALID;
ret = hclge_dscp_to_tc_map(hdev);
if (ret) {
dev_err(&hdev->pdev->dev,
"failed to del dscp to tc map, ret = %d\n", ret);
hdev->tm_info.dscp_prio[app->protocol] = app->priority;
h->kinfo.dscp_prio[app->protocol] = app->priority;
(void)dcb_ieee_setapp(netdev, app);
return ret;
}

if (hdev->tm_info.dscp_app_cnt)
hdev->tm_info.dscp_app_cnt--;
if (h->kinfo.dscp_app_cnt)
h->kinfo.dscp_app_cnt--;

if (!hdev->tm_info.dscp_app_cnt) {
if (!h->kinfo.dscp_app_cnt) {
vport->nic.kinfo.tc_map_mode = HNAE3_TC_MAP_MODE_PRIO;
ret = hclge_up_to_tc_map(hdev);
}
Expand Down
Loading

0 comments on commit 6287e55

Please sign in to comment.