Commit 119c1a33 authored by David S. Miller's avatar David S. Miller

Merge branch 'hns3-cleanups'

Guangbin Huang says:

====================
net: hns3: some cleanups for -next

To improve code readability and simplicity, this series add some cleanup
patches for the HNS3 ethernet driver.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0109841f 184da9dc
...@@ -1083,7 +1083,7 @@ static void hns3_dump_page_pool_info(struct hns3_enet_ring *ring, ...@@ -1083,7 +1083,7 @@ static void hns3_dump_page_pool_info(struct hns3_enet_ring *ring,
sprintf(result[j++], "%u", index); sprintf(result[j++], "%u", index);
sprintf(result[j++], "%u", sprintf(result[j++], "%u",
READ_ONCE(ring->page_pool->pages_state_hold_cnt)); READ_ONCE(ring->page_pool->pages_state_hold_cnt));
sprintf(result[j++], "%u", sprintf(result[j++], "%d",
atomic_read(&ring->page_pool->pages_state_release_cnt)); atomic_read(&ring->page_pool->pages_state_release_cnt));
sprintf(result[j++], "%u", ring->page_pool->p.pool_size); sprintf(result[j++], "%u", ring->page_pool->p.pool_size);
sprintf(result[j++], "%u", ring->page_pool->p.order); sprintf(result[j++], "%u", ring->page_pool->p.order);
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#ifndef __HNS3_DEBUGFS_H #ifndef __HNS3_DEBUGFS_H
#define __HNS3_DEBUGFS_H #define __HNS3_DEBUGFS_H
#include "hnae3.h"
#define HNS3_DBG_READ_LEN 65536 #define HNS3_DBG_READ_LEN 65536
#define HNS3_DBG_READ_LEN_128KB 0x20000 #define HNS3_DBG_READ_LEN_128KB 0x20000
#define HNS3_DBG_READ_LEN_1MB 0x100000 #define HNS3_DBG_READ_LEN_1MB 0x100000
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include "hnae3.h" #include "hnae3.h"
struct iphdr;
struct ipv6hdr;
enum hns3_nic_state { enum hns3_nic_state {
HNS3_NIC_STATE_TESTING, HNS3_NIC_STATE_TESTING,
HNS3_NIC_STATE_RESETTING, HNS3_NIC_STATE_RESETTING,
......
...@@ -77,6 +77,10 @@ static const struct hclge_dbg_reg_type_info hclge_dbg_reg_info[] = { ...@@ -77,6 +77,10 @@ static const struct hclge_dbg_reg_type_info hclge_dbg_reg_info[] = {
.cmd = HCLGE_OPC_DFX_TQP_REG } }, .cmd = HCLGE_OPC_DFX_TQP_REG } },
}; };
/* make sure: len(name) + interval >= maxlen(item data) + 2,
* for example, name = "pkt_num"(len: 7), the prototype of item data is u32,
* and print as "%u"(maxlen: 10), so the interval should be at least 5.
*/
static void hclge_dbg_fill_content(char *content, u16 len, static void hclge_dbg_fill_content(char *content, u16 len,
const struct hclge_dbg_item *items, const struct hclge_dbg_item *items,
const char **result, u16 size) const char **result, u16 size)
...@@ -99,7 +103,7 @@ static void hclge_dbg_fill_content(char *content, u16 len, ...@@ -99,7 +103,7 @@ static void hclge_dbg_fill_content(char *content, u16 len,
static char *hclge_dbg_get_func_id_str(char *buf, u8 id) static char *hclge_dbg_get_func_id_str(char *buf, u8 id)
{ {
if (id) if (id)
sprintf(buf, "vf%u", id - 1); sprintf(buf, "vf%u", id - 1U);
else else
sprintf(buf, "pf"); sprintf(buf, "pf");
...@@ -778,7 +782,6 @@ static int hclge_dbg_dump_tm_pg(struct hclge_dev *hdev, char *buf, int len) ...@@ -778,7 +782,6 @@ static int hclge_dbg_dump_tm_pg(struct hclge_dev *hdev, char *buf, int len)
data_str = kcalloc(ARRAY_SIZE(tm_pg_items), data_str = kcalloc(ARRAY_SIZE(tm_pg_items),
HCLGE_DBG_DATA_STR_LEN, GFP_KERNEL); HCLGE_DBG_DATA_STR_LEN, GFP_KERNEL);
if (!data_str) if (!data_str)
return -ENOMEM; return -ENOMEM;
...@@ -1764,7 +1767,7 @@ hclge_dbg_get_imp_stats_info(struct hclge_dev *hdev, char *buf, int len) ...@@ -1764,7 +1767,7 @@ hclge_dbg_get_imp_stats_info(struct hclge_dev *hdev, char *buf, int len)
#define HCLGE_MAX_NCL_CONFIG_LENGTH 16384 #define HCLGE_MAX_NCL_CONFIG_LENGTH 16384
static void hclge_ncl_config_data_print(struct hclge_desc *desc, int *index, static void hclge_ncl_config_data_print(struct hclge_desc *desc, int *index,
char *buf, int *len, int *pos) char *buf, int len, int *pos)
{ {
#define HCLGE_CMD_DATA_NUM 6 #define HCLGE_CMD_DATA_NUM 6
...@@ -1776,7 +1779,7 @@ static void hclge_ncl_config_data_print(struct hclge_desc *desc, int *index, ...@@ -1776,7 +1779,7 @@ static void hclge_ncl_config_data_print(struct hclge_desc *desc, int *index,
if (i == 0 && j == 0) if (i == 0 && j == 0)
continue; continue;
*pos += scnprintf(buf + *pos, *len - *pos, *pos += scnprintf(buf + *pos, len - *pos,
"0x%04x | 0x%08x\n", offset, "0x%04x | 0x%08x\n", offset,
le32_to_cpu(desc[i].data[j])); le32_to_cpu(desc[i].data[j]));
...@@ -1814,7 +1817,7 @@ hclge_dbg_dump_ncl_config(struct hclge_dev *hdev, char *buf, int len) ...@@ -1814,7 +1817,7 @@ hclge_dbg_dump_ncl_config(struct hclge_dev *hdev, char *buf, int len)
if (ret) if (ret)
return ret; return ret;
hclge_ncl_config_data_print(desc, &index, buf, &len, &pos); hclge_ncl_config_data_print(desc, &index, buf, len, &pos);
} }
return 0; return 0;
......
...@@ -120,7 +120,7 @@ int hclge_devlink_init(struct hclge_dev *hdev) ...@@ -120,7 +120,7 @@ int hclge_devlink_init(struct hclge_dev *hdev)
hdev->devlink = devlink; hdev->devlink = devlink;
devlink_set_features(devlink, DEVLINK_F_RELOAD); devlink_set_features(devlink, DEVLINK_F_RELOAD);
devlink_register(devlink); (void)devlink_register(devlink);
return 0; return 0;
} }
......
...@@ -1890,7 +1890,7 @@ static int hclge_map_tqp(struct hclge_dev *hdev) ...@@ -1890,7 +1890,7 @@ static int hclge_map_tqp(struct hclge_dev *hdev)
u16 i, num_vport; u16 i, num_vport;
num_vport = hdev->num_req_vfs + 1; num_vport = hdev->num_req_vfs + 1;
for (i = 0; i < num_vport; i++) { for (i = 0; i < num_vport; i++) {
int ret; int ret;
ret = hclge_map_tqp_to_vport(hdev, vport); ret = hclge_map_tqp_to_vport(hdev, vport);
...@@ -6806,7 +6806,7 @@ static int hclge_fd_parse_ring_cookie(struct hclge_dev *hdev, u64 ring_cookie, ...@@ -6806,7 +6806,7 @@ static int hclge_fd_parse_ring_cookie(struct hclge_dev *hdev, u64 ring_cookie,
if (vf > hdev->num_req_vfs) { if (vf > hdev->num_req_vfs) {
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"Error: vf id (%u) should be less than %u\n", "Error: vf id (%u) should be less than %u\n",
vf - 1, hdev->num_req_vfs); vf - 1U, hdev->num_req_vfs);
return -EINVAL; return -EINVAL;
} }
...@@ -6816,7 +6816,7 @@ static int hclge_fd_parse_ring_cookie(struct hclge_dev *hdev, u64 ring_cookie, ...@@ -6816,7 +6816,7 @@ static int hclge_fd_parse_ring_cookie(struct hclge_dev *hdev, u64 ring_cookie,
if (ring >= tqps) { if (ring >= tqps) {
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"Error: queue id (%u) > max tqp num (%u)\n", "Error: queue id (%u) > max tqp num (%u)\n",
ring, tqps - 1); ring, tqps - 1U);
return -EINVAL; return -EINVAL;
} }
...@@ -8000,16 +8000,13 @@ static int hclge_set_app_loopback(struct hclge_dev *hdev, bool en) ...@@ -8000,16 +8000,13 @@ static int hclge_set_app_loopback(struct hclge_dev *hdev, bool en)
return ret; return ret;
} }
static int hclge_cfg_common_loopback(struct hclge_dev *hdev, bool en, static int hclge_cfg_common_loopback_cmd_send(struct hclge_dev *hdev, bool en,
enum hnae3_loop loop_mode) enum hnae3_loop loop_mode)
{ {
#define HCLGE_COMMON_LB_RETRY_MS 10
#define HCLGE_COMMON_LB_RETRY_NUM 100
struct hclge_common_lb_cmd *req; struct hclge_common_lb_cmd *req;
struct hclge_desc desc; struct hclge_desc desc;
int ret, i = 0;
u8 loop_mode_b; u8 loop_mode_b;
int ret;
req = (struct hclge_common_lb_cmd *)desc.data; req = (struct hclge_common_lb_cmd *)desc.data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_COMMON_LOOPBACK, false); hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_COMMON_LOOPBACK, false);
...@@ -8026,23 +8023,34 @@ static int hclge_cfg_common_loopback(struct hclge_dev *hdev, bool en, ...@@ -8026,23 +8023,34 @@ static int hclge_cfg_common_loopback(struct hclge_dev *hdev, bool en,
break; break;
default: default:
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"unsupported common loopback mode %d\n", loop_mode); "unsupported loopback mode %d\n", loop_mode);
return -ENOTSUPP; return -ENOTSUPP;
} }
if (en) { req->mask = loop_mode_b;
if (en)
req->enable = loop_mode_b; req->enable = loop_mode_b;
req->mask = loop_mode_b;
} else {
req->mask = loop_mode_b;
}
ret = hclge_cmd_send(&hdev->hw, &desc, 1); ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) { if (ret)
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"common loopback set fail, ret = %d\n", ret); "failed to send loopback cmd, loop_mode = %d, ret = %d\n",
return ret; loop_mode, ret);
}
return ret;
}
static int hclge_cfg_common_loopback_wait(struct hclge_dev *hdev)
{
#define HCLGE_COMMON_LB_RETRY_MS 10
#define HCLGE_COMMON_LB_RETRY_NUM 100
struct hclge_common_lb_cmd *req;
struct hclge_desc desc;
u32 i = 0;
int ret;
req = (struct hclge_common_lb_cmd *)desc.data;
do { do {
msleep(HCLGE_COMMON_LB_RETRY_MS); msleep(HCLGE_COMMON_LB_RETRY_MS);
...@@ -8051,20 +8059,34 @@ static int hclge_cfg_common_loopback(struct hclge_dev *hdev, bool en, ...@@ -8051,20 +8059,34 @@ static int hclge_cfg_common_loopback(struct hclge_dev *hdev, bool en,
ret = hclge_cmd_send(&hdev->hw, &desc, 1); ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) { if (ret) {
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev,
"common loopback get, ret = %d\n", ret); "failed to get loopback done status, ret = %d\n",
ret);
return ret; return ret;
} }
} while (++i < HCLGE_COMMON_LB_RETRY_NUM && } while (++i < HCLGE_COMMON_LB_RETRY_NUM &&
!(req->result & HCLGE_CMD_COMMON_LB_DONE_B)); !(req->result & HCLGE_CMD_COMMON_LB_DONE_B));
if (!(req->result & HCLGE_CMD_COMMON_LB_DONE_B)) { if (!(req->result & HCLGE_CMD_COMMON_LB_DONE_B)) {
dev_err(&hdev->pdev->dev, "common loopback set timeout\n"); dev_err(&hdev->pdev->dev, "wait loopback timeout\n");
return -EBUSY; return -EBUSY;
} else if (!(req->result & HCLGE_CMD_COMMON_LB_SUCCESS_B)) { } else if (!(req->result & HCLGE_CMD_COMMON_LB_SUCCESS_B)) {
dev_err(&hdev->pdev->dev, "common loopback set failed in fw\n"); dev_err(&hdev->pdev->dev, "faile to do loopback test\n");
return -EIO; return -EIO;
} }
return ret;
return 0;
}
static int hclge_cfg_common_loopback(struct hclge_dev *hdev, bool en,
enum hnae3_loop loop_mode)
{
int ret;
ret = hclge_cfg_common_loopback_cmd_send(hdev, en, loop_mode);
if (ret)
return ret;
return hclge_cfg_common_loopback_wait(hdev);
} }
static int hclge_set_common_loopback(struct hclge_dev *hdev, bool en, static int hclge_set_common_loopback(struct hclge_dev *hdev, bool en,
...@@ -9724,8 +9746,8 @@ static int hclge_set_vlan_filter_ctrl(struct hclge_dev *hdev, u8 vlan_type, ...@@ -9724,8 +9746,8 @@ static int hclge_set_vlan_filter_ctrl(struct hclge_dev *hdev, u8 vlan_type,
ret = hclge_cmd_send(&hdev->hw, &desc, 1); ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) { if (ret) {
dev_err(&hdev->pdev->dev, dev_err(&hdev->pdev->dev, "failed to get vport%u vlan filter config, ret = %d.\n",
"failed to get vlan filter config, ret = %d.\n", ret); vf_id, ret);
return ret; return ret;
} }
...@@ -9736,8 +9758,8 @@ static int hclge_set_vlan_filter_ctrl(struct hclge_dev *hdev, u8 vlan_type, ...@@ -9736,8 +9758,8 @@ static int hclge_set_vlan_filter_ctrl(struct hclge_dev *hdev, u8 vlan_type,
ret = hclge_cmd_send(&hdev->hw, &desc, 1); ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) if (ret)
dev_err(&hdev->pdev->dev, "failed to set vlan filter, ret = %d.\n", dev_err(&hdev->pdev->dev, "failed to set vport%u vlan filter, ret = %d.\n",
ret); vf_id, ret);
return ret; return ret;
} }
...@@ -9983,6 +10005,32 @@ static int hclge_set_port_vlan_filter(struct hclge_dev *hdev, __be16 proto, ...@@ -9983,6 +10005,32 @@ static int hclge_set_port_vlan_filter(struct hclge_dev *hdev, __be16 proto,
return ret; return ret;
} }
static bool hclge_need_update_port_vlan(struct hclge_dev *hdev, u16 vport_id,
u16 vlan_id, bool is_kill)
{
/* vlan 0 may be added twice when 8021q module is enabled */
if (!is_kill && !vlan_id &&
test_bit(vport_id, hdev->vlan_table[vlan_id]))
return false;
if (!is_kill && test_and_set_bit(vport_id, hdev->vlan_table[vlan_id])) {
dev_warn(&hdev->pdev->dev,
"Add port vlan failed, vport %u is already in vlan %u\n",
vport_id, vlan_id);
return false;
}
if (is_kill &&
!test_and_clear_bit(vport_id, hdev->vlan_table[vlan_id])) {
dev_warn(&hdev->pdev->dev,
"Delete port vlan failed, vport %u is not in vlan %u\n",
vport_id, vlan_id);
return false;
}
return true;
}
static int hclge_set_vlan_filter_hw(struct hclge_dev *hdev, __be16 proto, static int hclge_set_vlan_filter_hw(struct hclge_dev *hdev, __be16 proto,
u16 vport_id, u16 vlan_id, u16 vport_id, u16 vlan_id,
bool is_kill) bool is_kill)
...@@ -10004,26 +10052,9 @@ static int hclge_set_vlan_filter_hw(struct hclge_dev *hdev, __be16 proto, ...@@ -10004,26 +10052,9 @@ static int hclge_set_vlan_filter_hw(struct hclge_dev *hdev, __be16 proto,
return ret; return ret;
} }
/* vlan 0 may be added twice when 8021q module is enabled */ if (!hclge_need_update_port_vlan(hdev, vport_id, vlan_id, is_kill))
if (!is_kill && !vlan_id &&
test_bit(vport_id, hdev->vlan_table[vlan_id]))
return 0; return 0;
if (!is_kill && test_and_set_bit(vport_id, hdev->vlan_table[vlan_id])) {
dev_err(&hdev->pdev->dev,
"Add port vlan failed, vport %u is already in vlan %u\n",
vport_id, vlan_id);
return -EINVAL;
}
if (is_kill &&
!test_and_clear_bit(vport_id, hdev->vlan_table[vlan_id])) {
dev_err(&hdev->pdev->dev,
"Delete port vlan failed, vport %u is not in vlan %u\n",
vport_id, vlan_id);
return -EINVAL;
}
for_each_set_bit(vport_idx, hdev->vlan_table[vlan_id], HCLGE_VPORT_NUM) for_each_set_bit(vport_idx, hdev->vlan_table[vlan_id], HCLGE_VPORT_NUM)
vport_num++; vport_num++;
......
...@@ -181,7 +181,7 @@ static int hclge_get_ring_chain_from_mbx( ...@@ -181,7 +181,7 @@ static int hclge_get_ring_chain_from_mbx(
if (req->msg.param[i].tqp_index >= vport->nic.kinfo.rss_size) { if (req->msg.param[i].tqp_index >= vport->nic.kinfo.rss_size) {
dev_err(&hdev->pdev->dev, "tqp index(%u) is out of range(0-%u)\n", dev_err(&hdev->pdev->dev, "tqp index(%u) is out of range(0-%u)\n",
req->msg.param[i].tqp_index, req->msg.param[i].tqp_index,
vport->nic.kinfo.rss_size - 1); vport->nic.kinfo.rss_size - 1U);
return -EINVAL; return -EINVAL;
} }
} }
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#ifndef __HCLGE_MDIO_H #ifndef __HCLGE_MDIO_H
#define __HCLGE_MDIO_H #define __HCLGE_MDIO_H
#include "hnae3.h"
struct hclge_dev;
int hclge_mac_mdio_config(struct hclge_dev *hdev); int hclge_mac_mdio_config(struct hclge_dev *hdev);
int hclge_mac_connect_phy(struct hnae3_handle *handle); int hclge_mac_connect_phy(struct hnae3_handle *handle);
void hclge_mac_disconnect_phy(struct hnae3_handle *handle); void hclge_mac_disconnect_phy(struct hnae3_handle *handle);
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#include <linux/net_tstamp.h> #include <linux/net_tstamp.h>
#include <linux/types.h> #include <linux/types.h>
struct hclge_dev;
struct ifreq;
#define HCLGE_PTP_REG_OFFSET 0x29000 #define HCLGE_PTP_REG_OFFSET 0x29000
#define HCLGE_PTP_TX_TS_SEQID_REG 0x0 #define HCLGE_PTP_TX_TS_SEQID_REG 0x0
......
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
#include <linux/types.h> #include <linux/types.h>
#include "hnae3.h"
struct hclge_dev;
struct hclge_vport;
enum hclge_opcode_type;
/* MAC Pause */ /* MAC Pause */
#define HCLGE_TX_MAC_PAUSE_EN_MSK BIT(0) #define HCLGE_TX_MAC_PAUSE_EN_MSK BIT(0)
#define HCLGE_RX_MAC_PAUSE_EN_MSK BIT(1) #define HCLGE_RX_MAC_PAUSE_EN_MSK BIT(1)
......
...@@ -122,7 +122,7 @@ int hclgevf_devlink_init(struct hclgevf_dev *hdev) ...@@ -122,7 +122,7 @@ int hclgevf_devlink_init(struct hclgevf_dev *hdev)
hdev->devlink = devlink; hdev->devlink = devlink;
devlink_set_features(devlink, DEVLINK_F_RELOAD); devlink_set_features(devlink, DEVLINK_F_RELOAD);
devlink_register(devlink); (void)devlink_register(devlink);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment