提交 fb6d05c2 编写于 作者: J Junxin Chen 提交者: Yang Yingliang

net: hns3: add protect for parameters and remove unused functions

driver inclusion
category: feature
bugzilla: NA
CVE: NA

----------------------------------

Add protect for hns3_cae and remove some functions, and change version
to 1.9.36.0.
Signed-off-by: NJunxin Chen <chenjunxin1@huawei.com>
Reviewed-by: NZhong Zhaohui <zhongzhaohui@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 c5e03556
...@@ -28,11 +28,10 @@ ccflags-y += -I$(PWD) \ ...@@ -28,11 +28,10 @@ ccflags-y += -I$(PWD) \
obj-$(CONFIG_HNS3) += hnae3.o obj-$(CONFIG_HNS3) += hnae3.o
#### compile hns3.ko #### compile hns3.ko
HNS3_OBJS = hns3_enet.o \ HNS3_OBJS = hns3_enet.o \
hns3_ethtool.o \ hns3_ethtool.o \
hns3_debugfs.o hns3_debugfs.o
HNS3_OBJS_IT = hns-customer/hns3_enet_it.o \ HNS3_OBJS_IT = hns-customer/hns3_enet_it.o
hns-customer/hns3_ext.o
obj-$(CONFIG_HNS3_ENET) += hns3.o obj-$(CONFIG_HNS3_ENET) += hns3.o
hns3-objs = $(HNS3_OBJS) $(HNS3_OBJS_IT) hns3-objs = $(HNS3_OBJS) $(HNS3_OBJS_IT)
...@@ -49,11 +48,8 @@ HCLGE_OBJ = hns3pf/hclge_main.o \ ...@@ -49,11 +48,8 @@ HCLGE_OBJ = hns3pf/hclge_main.o \
HCLGE_OBJ_IT_MAIN = hns-customer/hns3pf/hclge_main_it.o HCLGE_OBJ_IT_MAIN = hns-customer/hns3pf/hclge_main_it.o
HCLGE_OBJ_IT_EXPORT = hns-customer/hns3pf/hclge_ext.o
obj-$(CONFIG_HNS3_HCLGE) += hclge.o obj-$(CONFIG_HNS3_HCLGE) += hclge.o
hclge-objs := $(HCLGE_OBJ) $(HCLGE_OBJ_IT_MAIN) $(HCLGE_OBJ_IT_EXPORT) hclge-objs := $(HCLGE_OBJ) $(HCLGE_OBJ_IT_MAIN)
hclge-$(CONFIG_HNS3_DCB) += hns3pf/hclge_dcb.o hclge-$(CONFIG_HNS3_DCB) += hns3pf/hclge_dcb.o
#### compile hclgevf.ko #### compile hclgevf.ko
obj-$(CONFIG_HNS3_HCLGEVF) += hclgevf.o obj-$(CONFIG_HNS3_HCLGEVF) += hclgevf.o
...@@ -63,25 +59,20 @@ hclgevf-objs := hns3vf/hclgevf_main.o hns3vf/hclgevf_cmd.o hns3vf/hclgevf_mbx.o ...@@ -63,25 +59,20 @@ hclgevf-objs := hns3vf/hclgevf_main.o hns3vf/hclgevf_cmd.o hns3vf/hclgevf_mbx.o
#add rally code #add rally code
HNS3_CAE_OBJS_PRIM = hns3_cae/hns3_cae_init.o \ HNS3_CAE_OBJS_PRIM = hns3_cae/hns3_cae_init.o \
hns3_cae/hns3_cae_lib.o \ hns3_cae/hns3_cae_lib.o \
hns3_cae/hns3_cae_common.o \
hns3_cae/hns3_cae_dcb.o \ hns3_cae/hns3_cae_dcb.o \
hns3_cae/hns3_cae_lamp.o \ hns3_cae/hns3_cae_dcqcn.o \
hns3_cae/hns3_cae_dcqcn.o \ hns3_cae/hns3_cae_version.o \
hns3_cae/hns3_cae_mactbl.o \ hns3_cae/hns3_cae_reset.o \
hns3_cae/hns3_cae_version.o \ hns3_cae/hns3_cae_pfc_storm.o \
hns3_cae/hns3_cae_reset.o \ hns3_cae/hns3_cae_cmd.o
hns3_cae/hns3_cae_pfc_storm.o \
hns3_cae/hns3_cae_cmd.o
#add test code #add test code
HNS3_CAE_OBJS_EXT = hns3_cae/hns3_cae_dfx.o \ HNS3_CAE_OBJS_EXT = hns3_cae/hns3_cae_dfx.o \
hns3_cae/hns3_cae_ext.o \
hns3_cae/hns3_cae_fd.o \ hns3_cae/hns3_cae_fd.o \
hns3_cae/hns3_cae_hilink_param.o \ hns3_cae/hns3_cae_hilink_param.o \
hns3_cae/hns3_cae_checksum.o \ hns3_cae/hns3_cae_checksum.o \
hns3_cae/hns3_cae_irq.o \ hns3_cae/hns3_cae_irq.o \
hns3_cae/hns3_cae_gro.o \ hns3_cae/hns3_cae_gro.o \
hns3_cae/hns3_cae_mac.o \ hns3_cae/hns3_cae_mac.o \
hns3_cae/hns3_cae_pkt.o \
hns3_cae/hns3_cae_port.o \ hns3_cae/hns3_cae_port.o \
hns3_cae/hns3_cae_promisc.o \ hns3_cae/hns3_cae_promisc.o \
hns3_cae/hns3_cae_qinfo.o \ hns3_cae/hns3_cae_qinfo.o \
...@@ -92,6 +83,6 @@ HNS3_CAE_OBJS_EXT = hns3_cae/hns3_cae_dfx.o \ ...@@ -92,6 +83,6 @@ HNS3_CAE_OBJS_EXT = hns3_cae/hns3_cae_dfx.o \
hns3_cae/hns3_cae_tm.o \ hns3_cae/hns3_cae_tm.o \
hns3_cae/hns3_cae_vlan.o \ hns3_cae/hns3_cae_vlan.o \
hns3_cae/hns3_cae_xsfp.o \ hns3_cae/hns3_cae_xsfp.o \
hns3_cae/hns3_cae_led.o hns3_cae/hns3_cae_led.o
obj-$(CONFIG_HNS3_CAE) += hns3_cae.o obj-$(CONFIG_HNS3_CAE) += hns3_cae.o
hns3_cae-objs := $(HNS3_CAE_OBJS_PRIM) $(HNS3_CAE_OBJS_EXT) hns3_cae-objs := $(HNS3_CAE_OBJS_PRIM) $(HNS3_CAE_OBJS_EXT)
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/types.h> #include <linux/types.h>
#define HNAE3_MOD_VERSION "1.9.35.1" #define HNAE3_MOD_VERSION "1.9.36.0"
#define HNAE3_MIN_VECTOR_NUM 2 /* one for msi-x, another for IO */ #define HNAE3_MIN_VECTOR_NUM 2 /* one for msi-x, another for IO */
......
// SPDX-License-Identifier: GPL-2.0+
// Copyright (c) 2016-2017 Hisilicon Limited.
#ifdef CONFIG_HNS3_TEST
#include <linux/dma-mapping.h>
#include <linux/etherdevice.h>
#include <linux/interrupt.h>
#include <linux/if_vlan.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/skbuff.h>
#include <linux/sctp.h>
#include <linux/vermagic.h>
#include <net/gre.h>
#include <net/pkt_cls.h>
#include <net/vxlan.h>
#include "hns3_ext.h"
extern const char hns3_driver_name[];
int nic_netdev_match_check(struct net_device *netdev)
{
struct ethtool_drvinfo drv_info;
if (!netdev)
return -EINVAL;
if (netdev->ethtool_ops && netdev->ethtool_ops->get_drvinfo)
netdev->ethtool_ops->get_drvinfo(netdev, &drv_info);
if (!strncmp(drv_info.driver, hns3_driver_name,
strlen(hns3_driver_name)))
return 0;
return -EINVAL;
}
EXPORT_SYMBOL(nic_netdev_match_check);
void nic_chip_recover_handler(struct net_device *netdev,
enum hnae3_event_type_custom event_t)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(netdev))
return;
dev_info(&netdev->dev, "reset type is %d!!\n", event_t);
if (event_t == HNAE3_PPU_POISON_CUSTOM)
event_t = HNAE3_FUNC_RESET_CUSTOM;
if (event_t != HNAE3_FUNC_RESET_CUSTOM &&
event_t != HNAE3_GLOBAL_RESET_CUSTOM &&
event_t != HNAE3_IMP_RESET_CUSTOM) {
dev_err(&netdev->dev, "reset type err!!\n");
return;
}
h = hns3_get_handle(netdev);
if (h->ae_algo->ops->priv_ops)
h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_RESET, &event_t, 0);
}
EXPORT_SYMBOL(nic_chip_recover_handler);
int nic_clean_stats64(struct net_device *ndev, struct rtnl_link_stats64 *stats)
{
struct hns3_nic_priv *priv;
struct hnae3_handle *h;
struct hnae3_knic_private_info *kinfo;
struct hns3_enet_ring *ring;
int i;
if (nic_netdev_match_check(ndev))
return -ENODEV;
priv = netdev_priv(ndev);
h = hns3_get_handle(ndev);
kinfo = &h->kinfo;
if (h->ae_algo->ops->priv_ops)
h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_CLEAN_STATS64, stats,
0);
for (i = 0; i < kinfo->num_tqps; i++) {
ring = &priv->ring[i];
memset(&ring->stats, 0, sizeof(struct ring_stats));
ring = &priv->ring[i + kinfo->num_tqps];
memset(&ring->stats, 0, sizeof(struct ring_stats));
}
memset(&ndev->stats, 0, sizeof(struct net_device_stats));
return 0;
}
EXPORT_SYMBOL(nic_clean_stats64);
int nic_get_chipid(struct net_device *ndev, u32 *chip_id)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!chip_id)
return -EINVAL;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_GET_CHIPID,
chip_id, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_get_chipid);
int nic_get_mac_id(struct net_device *ndev, u32 *mac_id)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!mac_id)
return -EINVAL;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_GET_MAC_ID,
mac_id, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_get_mac_id);
int nic_get_sfpinfo(struct net_device *ndev, u8 *buff, u16 size, u16 *outlen)
{
struct hns3_sfp_info_para para;
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!buff || !outlen)
return -EINVAL;
para.buff = buff;
para.outlen = outlen;
para.offset = 0;
para.size = size;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops) {
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_GET_SFPINFO,
&para, 0);
} else {
return -EOPNOTSUPP;
}
}
EXPORT_SYMBOL(nic_get_sfpinfo);
int nic_get_sfp_present(struct net_device *ndev, int *present)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!present)
return -EINVAL;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_GET_PRESENT,
present, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_get_sfp_present);
int nic_set_sfp_state(struct net_device *ndev, bool en)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_SET_SFP_STATE,
&en, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_set_sfp_state);
int nic_get_chip_num(struct net_device *ndev, u32 *chip_num)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!chip_num)
return -EINVAL;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_GET_CHIP_NUM,
chip_num, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_get_chip_num);
int nic_get_port_num_per_chip(struct net_device *ndev, u32 *port_num)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!port_num)
return -EINVAL;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_GET_PORT_NUM,
port_num, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_get_port_num_per_chip);
int nic_set_led(struct net_device *ndev, int type, int status)
{
struct hns3_led_state_para para;
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
para.status = status;
para.type = type;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_SET_LED, &para,
0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_set_led);
int nic_get_led_signal(struct net_device *ndev, struct hns3_lamp_signal *signal)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!signal)
return -EINVAL;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_GET_LED_SIGNAL,
signal, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_get_led_signal);
int nic_disable_net_lane(struct net_device *ndev)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_DISABLE_LANE,
NULL, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_disable_net_lane);
int nic_get_net_lane_status(struct net_device *ndev, u32 *status)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!status)
return -EINVAL;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h,
HNS3_EXT_OPC_GET_LANE_STATUS,
status, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_get_net_lane_status);
int nic_set_mac_state(struct net_device *ndev, int enable)
{
struct hnae3_handle *h;
bool en;
if (nic_netdev_match_check(ndev))
return -ENODEV;
h = hns3_get_handle(ndev);
en = !!enable;
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_SET_MAC_STATE,
&en, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_set_mac_state);
int nic_set_cpu_affinity(struct net_device *netdev, cpumask_t *affinity_mask)
{
struct hns3_enet_tqp_vector *tqp_vector;
struct hns3_nic_priv *priv;
int ret;
u16 i;
if (!netdev || !affinity_mask) {
pr_err("Invalid input param when set ethernet cpu affinity\n");
return -EINVAL;
}
if (nic_netdev_match_check(netdev))
return -ENODEV;
priv = netdev_priv(netdev);
if (test_bit(HNS3_NIC_STATE_DOWN, &priv->state)) {
dev_err(&netdev->dev,
"ethernet is down, not support cpu affinity set\n");
return -EOPNOTSUPP;
}
for (i = 0; i < priv->vector_num; i++) {
tqp_vector = &priv->tqp_vector[i];
if (tqp_vector->irq_init_flag != HNS3_VECTOR_INITED)
continue;
tqp_vector->affinity_mask = *affinity_mask;
ret = irq_set_affinity_hint(tqp_vector->vector_irq, NULL);
if (ret) {
dev_err(&netdev->dev,
"reset affinity hint fail, ret = %d\n", ret);
return ret;
}
ret = irq_set_affinity_hint(tqp_vector->vector_irq,
&tqp_vector->affinity_mask);
if (ret) {
dev_err(&netdev->dev,
"set affinity hint fail, ret = %d\n", ret);
return ret;
}
}
dev_info(&netdev->dev, "set nic cpu affinity %*pb succeed\n",
cpumask_pr_args(affinity_mask));
return 0;
}
EXPORT_SYMBOL(nic_set_cpu_affinity);
int nic_disable_clock(struct net_device *ndev)
{
struct hnae3_handle *h;
u32 en;
if (nic_netdev_match_check(ndev))
return -ENODEV;
en = 0;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_CONFIG_CLOCK,
&en, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_disable_clock);
int nic_set_pfc_storm_para(struct net_device *ndev, int dir, int enable,
int period_ms, int times, int recovery_period_ms)
{
struct hns3_pfc_storm_para para;
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
para.dir = dir;
para.enable = enable;
para.period_ms = period_ms;
para.times = times;
para.recovery_period_ms = recovery_period_ms;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h,
HNS3_EXT_OPC_SET_PFC_STORM_PARA,
&para, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_set_pfc_storm_para);
int nic_get_pfc_storm_para(struct net_device *ndev, int dir, int *enable,
int *period_ms, int *times, int *recovery_period_ms)
{
struct hns3_pfc_storm_para para;
struct hnae3_handle *h;
int ret;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!enable || !period_ms || !times || !recovery_period_ms) {
pr_err("get pfc storm para failed because invalid input param.\n");
return -EINVAL;
}
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops) {
para.dir = dir;
ret = h->ae_algo->ops->priv_ops(h,
HNS3_EXT_OPC_GET_PFC_STORM_PARA,
&para, 0);
if (!ret) {
*enable = para.enable;
*period_ms = para.period_ms;
*times = para.times;
*recovery_period_ms = para.recovery_period_ms;
return 0;
} else {
return ret;
}
} else {
return -EOPNOTSUPP;
}
}
EXPORT_SYMBOL(nic_get_pfc_storm_para);
int nic_get_phy_reg(struct net_device *ndev, u32 page_select_addr,
u16 page, u32 reg_addr, u16 *data)
{
struct hns3_phy_para para;
struct hnae3_handle *h;
int ret;
if (nic_netdev_match_check(ndev))
return -ENODEV;
para.page_select_addr = page_select_addr;
para.page = page;
para.reg_addr = reg_addr;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops) {
ret = h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_GET_PHY_REG,
&para, 0);
if (!ret) {
*data = para.data;
return 0;
} else {
return ret;
}
} else {
return -EOPNOTSUPP;
}
}
EXPORT_SYMBOL(nic_get_phy_reg);
int nic_set_phy_reg(struct net_device *ndev, u32 page_select_addr,
u16 page, u32 reg_addr, u16 data)
{
struct hns3_phy_para para;
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
para.page_select_addr = page_select_addr;
para.page = page;
para.reg_addr = reg_addr;
para.data = data;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_SET_PHY_REG,
&para, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_set_phy_reg);
int nic_get_hilink_ref_los(struct net_device *ndev, u32 *status)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!status)
return -EINVAL;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h,
HNS3_EXT_OPC_GET_HILINK_REF_LOS,
status, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_get_hilink_ref_los);
int nic_get_8211_phy_reg(struct net_device *ndev, u32 page_select_addr,
u16 page, u32 reg_addr, u16 *data)
{
struct hns3_phy_para phy_para;
struct hnae3_handle *h;
int ret;
if (nic_netdev_match_check(ndev))
return -ENODEV;
phy_para.page_select_addr = page_select_addr;
phy_para.page = page;
phy_para.reg_addr = reg_addr;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops) {
ret = h->ae_algo->ops->priv_ops(h,
HNS3_EXT_OPC_GET_8211_PHY_REG,
&phy_para, 0);
if (!ret) {
*data = phy_para.data;
return 0;
} else {
return ret;
}
} else {
return -EOPNOTSUPP;
}
}
EXPORT_SYMBOL(nic_get_8211_phy_reg);
int nic_set_8211_phy_reg(struct net_device *ndev, u32 page_select_addr,
u16 page, u32 reg_addr, u16 data)
{
struct hns3_phy_para phy_para;
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
phy_para.page_select_addr = page_select_addr;
phy_para.page = page;
phy_para.reg_addr = reg_addr;
phy_para.data = data;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h,
HNS3_EXT_OPC_SET_8211_PHY_REG,
&phy_para, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_set_8211_phy_reg);
int nic_get_port_wire_type(struct net_device *ndev, u32 *wire_type)
{
struct hnae3_handle *h;
if (nic_netdev_match_check(ndev))
return -ENODEV;
if (!wire_type)
return -EINVAL;
h = hns3_get_handle(ndev);
if (h->ae_algo->ops->priv_ops)
return h->ae_algo->ops->priv_ops(h,
HNS3_EXT_OPC_GET_PORT_TYPE,
wire_type, 0);
else
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(nic_get_port_wire_type);
#endif
/* SPDX-License-Identifier: GPL-2.0+ */
/* Copyright (c) 2016-2017 Hisilicon Limited. */
#ifndef __HNS3_EXT_H
#define __HNS3_EXT_H
#include <linux/types.h>
#include "hns3_enet.h"
#include "hnae3.h"
#include "hclge_main_it.h"
enum hns3_ext_op_code {
HNS3_EXT_OPC_CLEAN_STATS64 = 0,
HNS3_EXT_OPC_GET_CHIPID,
HNS3_EXT_OPC_GET_SFPINFO,
HNS3_EXT_OPC_SET_SFP_STATE,
HNS3_EXT_OPC_GET_CHIP_NUM,
HNS3_EXT_OPC_GET_PORT_NUM,
HNS3_EXT_OPC_SET_LED,
HNS3_EXT_OPC_GET_PRESENT,
HNS3_EXT_OPC_DISABLE_LANE,
HNS3_EXT_OPC_GET_LANE_STATUS,
HNS3_EXT_OPC_GET_LED_SIGNAL,
HNS3_EXT_OPC_SET_MAC_STATE,
HNS3_EXT_OPC_CONFIG_CLOCK,
HNS3_EXT_OPC_GET_PFC_STORM_PARA,
HNS3_EXT_OPC_SET_PFC_STORM_PARA,
HNS3_EXT_OPC_GET_PHY_REG,
HNS3_EXT_OPC_SET_PHY_REG,
HNS3_EXT_OPC_GET_MAC_ID,
HNS3_EXT_OPC_OPT_MAC_TABLE,
HNS3_EXT_OPC_RESET,
HNS3_EXT_OPC_GET_HILINK_REF_LOS,
HNS3_EXT_OPC_GET_8211_PHY_REG,
HNS3_EXT_OPC_SET_8211_PHY_REG,
HNS3_EXT_OPC_GET_PORT_TYPE,
};
struct hns3_sfp_info_para {
u8 *buff;
u16 offset;
u16 size;
u16 *outlen;
};
struct hns3_led_state_para {
u32 type;
u32 status;
};
struct hns3_pfc_storm_para {
u32 dir;
u32 enable;
u32 period_ms;
u32 times;
u32 recovery_period_ms;
};
struct hns3_phy_para {
u32 page_select_addr;
u32 reg_addr;
u16 page;
u16 data;
};
struct hns3_lamp_signal {
u8 error;
u8 locate;
u8 activity;
};
int nic_get_chipid(struct net_device *ndev, u32 *chip_id);
int nic_netdev_match_check(struct net_device *netdev);
int nic_get_sfpinfo(struct net_device *ndev, u8 *buff, u16 size, u16 *outlen);
int nic_get_sfp_present(struct net_device *ndev, int *present);
int nic_set_sfp_state(struct net_device *ndev, bool en);
int nic_clean_stats64(struct net_device *netdev,
struct rtnl_link_stats64 *stats);
int nic_get_chip_num(struct net_device *ndev, u32 *chip_num);
int nic_get_port_num_per_chip(struct net_device *ndev, u32 *port_num);
int nic_set_led(struct net_device *ndev, int type, int status);
int nic_disable_net_lane(struct net_device *ndev);
int nic_get_net_lane_status(struct net_device *ndev, u32 *status);
int nic_set_cpu_affinity(struct net_device *netdev, cpumask_t *affinity_mask);
int nic_set_mac_state(struct net_device *ndev, int enable);
int nic_disable_clock(struct net_device *ndev);
int nic_set_pfc_storm_para(struct net_device *ndev, int dir, int enable,
int period_ms, int times, int recovery_period_ms);
int nic_get_pfc_storm_para(struct net_device *ndev, int dir, int *enable,
int *period_ms, int *times, int *recovery_period_ms);
int nic_get_phy_reg(struct net_device *ndev, u32 page_select_addr,
u16 page, u32 reg_addr, u16 *data);
int nic_set_phy_reg(struct net_device *ndev, u32 page_select_addr,
u16 page, u32 reg_addr, u16 data);
int nic_get_mac_id(struct net_device *ndev, u32 *mac_id);
int nic_get_hilink_ref_los(struct net_device *ndev, u32 *status);
int nic_get_8211_phy_reg(struct net_device *ndev, u32 page_select_addr,
u16 page, u32 reg_addr, u16 *data);
int nic_set_8211_phy_reg(struct net_device *ndev, u32 page_select_addr,
u16 page, u32 reg_addr, u16 data);
int nic_get_port_wire_type(struct net_device *ndev, u32 *wire_type);
#endif
// SPDX-License-Identifier: GPL-2.0+
// Copyright (c) 2016-2017 Hisilicon Limited.
#ifdef CONFIG_IT_VALIDATION
#include <linux/dma-mapping.h>
#include <linux/etherdevice.h>
#include <linux/interrupt.h>
#include <linux/if_vlan.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/skbuff.h>
#include <linux/sctp.h>
#include <linux/vermagic.h>
#include <net/gre.h>
#include <net/pkt_cls.h>
#include <net/vxlan.h>
#include "hclge_main.h"
#include "hnae3.h"
#include "hclge_cmd.h"
#include "hclge_ext.h"
#define BD0_DATA_LEN 20
#define BD1_DATA_LEN 24
void hclge_reset_task_schedule_it(struct hclge_dev *hdev)
{
if (!test_bit(HCLGE_STATE_REMOVING, &hdev->state) &&
!test_and_set_bit(HCLGE_STATE_RST_SERVICE_SCHED, &hdev->state))
mod_delayed_work_on(cpumask_first(&hdev->affinity_mask),
system_wq, &hdev->service_task, 0);
}
#ifdef CONFIG_HNS3_TEST
static int hclge_clean_stats64(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hnae3_knic_private_info *kinfo = NULL;
struct hclge_vport *vport = NULL;
struct hclge_dev *hdev = NULL;
struct hclge_tqp *tqp = NULL;
int i;
kinfo = &handle->kinfo;
vport = hclge_get_vport(handle);
hdev = vport->back;
for (i = 0; i < kinfo->num_tqps; i++) {
tqp = container_of(kinfo->tqp[i], struct hclge_tqp, q);
memset(&tqp->tqp_stats, 0, sizeof(struct hlcge_tqp_stats));
}
memset(&hdev->mac_stats, 0, sizeof(struct hclge_mac_stats));
return 0;
}
static int hclge_get_chipid(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_chip_id_cmd *resp = NULL;
struct hclge_desc desc;
u32 *chip_id;
int ret;
chip_id = (u32 *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CHIP_ID_GET, true);
resp = (struct hclge_chip_id_cmd *)(desc.data);
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "get chip id failed %d\n", ret);
return ret;
}
*chip_id = resp->chip_id;
return 0;
}
static int hclge_get_mac_id(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
u32 *mac_id;
int ret;
mac_id = (u32 *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CHIP_ID_GET, true);
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "get mac id failed, ret = %d\n", ret);
return ret;
}
*mac_id = desc.data[1];
return 0;
}
static int _hclge_get_sfpinfo(struct hnae3_handle *handle, u8 *buff,
u16 offset, u16 size, u16 *outlen)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_desc desc[HCLGE_SFP_INFO_LEN];
struct hclge_dev *hdev = vport->back;
struct hclge_sfp_info *resp = NULL;
u8 *temp_data = NULL;
u32 temp_len;
u32 data_len;
int ret;
u32 i;
u32 j;
memset(desc, 0x0, sizeof(desc));
for (i = 0; i < HCLGE_SFP_INFO_LEN; i++) {
hclge_cmd_setup_basic_desc(&desc[i],
HCLGE_OPC_SFP_GET_INFO, true);
if (i == 0)
desc[0].data[0] = offset | (size << 16);
if (i < HCLGE_SFP_INFO_LEN - 1)
desc[i].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
else
desc[i].flag &= ~(cpu_to_le16(HCLGE_CMD_FLAG_NEXT));
}
ret = hclge_cmd_send(&hdev->hw, desc, HCLGE_SFP_INFO_LEN);
if (ret) {
dev_err(&hdev->pdev->dev,
"get spf information cmd failed %d\n", ret);
return ret;
}
for (i = 0; i < HCLGE_SFP_INFO_LEN; i++) {
resp = (struct hclge_sfp_info *)desc[i].data;
if (i == 0) {
*outlen = (resp[i].sfpinfo[0] >> 16) & 0xFFFF;
temp_len = *outlen;
data_len =
(temp_len > BD0_DATA_LEN) ? BD0_DATA_LEN : temp_len;
temp_data = (u8 *)&resp->sfpinfo[1];
} else {
data_len =
(temp_len > BD1_DATA_LEN) ? BD1_DATA_LEN : temp_len;
temp_data = (u8 *)&resp->sfpinfo[0];
}
for (j = 0; j < data_len; j++)
*buff++ = *temp_data++;
temp_len -= data_len;
if (temp_len == 0)
break;
}
return 0;
}
static int hclge_get_sfpinfo(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_sfp_info_para *para;
u16 tmp_size;
u8 *tmp_buff;
u16 tmp_outlen;
int ret;
para = (struct hclge_sfp_info_para *)data;
tmp_buff = para->buff;
while (para->size) {
WARN_ON_ONCE(!tmp_buff);
if (para->size > HCLGE_SFP_INFO_SIZE)
tmp_size = HCLGE_SFP_INFO_SIZE;
else
tmp_size = para->size;
ret = _hclge_get_sfpinfo(handle, tmp_buff, para->offset,
tmp_size, &tmp_outlen);
if (ret)
return ret;
para->offset += tmp_size;
para->size -= tmp_size;
tmp_buff += tmp_size;
*para->outlen += tmp_outlen;
if (tmp_size != tmp_outlen)
break;
}
return 0;
}
static int hclge_set_sfp_state(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_sfp_enable_cmd *req = NULL;
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
int ret;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SFP_SET_STATUS, false);
req = (struct hclge_sfp_enable_cmd *)desc.data;
req->set_sfp_enable_flag = *(bool *)data;
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret)
dev_err(&hdev->pdev->dev,
"set spf on/off cmd failed %d\n", ret);
return ret;
}
static int hclge_get_chip_num(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
u32 *chip_num = (u32 *)data;
struct hclge_desc desc;
int ret;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_GET_CHIP_NUM, true);
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "get chip number failed %d\n", ret);
return ret;
}
*chip_num = desc.data[0];
return 0;
}
static int hclge_get_port_num(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
u32 *port_num;
int ret;
port_num = (u32 *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_GET_PORT_NUM, true);
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "get port number failed %d\n", ret);
return ret;
}
*port_num = desc.data[0];
return 0;
}
static int hclge_set_led(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_led_state *para;
struct hclge_desc desc;
int ret;
para = (struct hclge_led_state *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SET_LED, false);
desc.data[0] = para->type;
desc.data[1] = para->status;
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "get set led failed %d\n", ret);
return ret;
}
return 0;
}
static int hclge_get_led_signal(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_lamp_signal *signal;
struct hclge_desc desc;
int ret;
signal = (struct hclge_lamp_signal *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SET_LED, true);
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev,
"hclge get led signal failed %d\n", ret);
return ret;
}
signal->error = desc.data[2] & 0xFF;
signal->locate = (desc.data[2] >> 8) & 0xFF;
signal->activity = (desc.data[2] >> 16) & 0xFF;
return 0;
}
static int hclge_get_sfp_present(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_sfp_present_cmd *resp = NULL;
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
u32 *present;
int ret = 0;
present = (u32 *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SFP_GET_PRESENT, true);
resp = (struct hclge_sfp_present_cmd *)desc.data;
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "get spf present failed %d\n", ret);
return ret;
}
*present = resp->sfp_present;
return 0;
}
static int hclge_disable_net_lane(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
int ret = 0;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_DISABLE_NET_LANE, false);
desc.data[0] = 0;
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "disable net lane failed %d\n", ret);
return ret;
}
return 0;
}
static int hclge_get_net_lane_status(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
u32 *status;
int ret = 0;
status = (u32 *)data;
desc.data[0] = 0;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_DISABLE_NET_LANE, true);
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "get lane status failed %d\n", ret);
return ret;
}
*status = desc.data[0];
return 0;
}
static void hclge_set_phy_state(struct hnae3_handle *handle, bool enable)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct phy_device *phydev = hdev->hw.mac.phydev;
if (!phydev)
return;
if (enable)
phy_start(phydev);
else
phy_stop(phydev);
}
static int hclge_set_mac_state(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_config_mac_mode_cmd *req = NULL;
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
u32 loop_en = 0;
bool enable;
int ret;
enable = *(bool *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CONFIG_MAC_MODE, false);
hnae3_set_bit(loop_en, HCLGE_MAC_TX_EN_B, enable);
hnae3_set_bit(loop_en, HCLGE_MAC_RX_EN_B, enable);
hnae3_set_bit(loop_en, HCLGE_MAC_PAD_TX_B, enable);
hnae3_set_bit(loop_en, HCLGE_MAC_PAD_RX_B, enable);
hnae3_set_bit(loop_en, HCLGE_MAC_1588_TX_B, 0);
hnae3_set_bit(loop_en, HCLGE_MAC_1588_RX_B, 0);
hnae3_set_bit(loop_en, HCLGE_MAC_APP_LP_B, 0);
hnae3_set_bit(loop_en, HCLGE_MAC_LINE_LP_B, 0);
hnae3_set_bit(loop_en, HCLGE_MAC_FCS_TX_B, enable);
hnae3_set_bit(loop_en, HCLGE_MAC_RX_FCS_B, enable);
hnae3_set_bit(loop_en, HCLGE_MAC_RX_FCS_STRIP_B, enable);
hnae3_set_bit(loop_en, HCLGE_MAC_TX_OVERSIZE_TRUNCATE_B, enable);
hnae3_set_bit(loop_en, HCLGE_MAC_RX_OVERSIZE_TRUNCATE_B, enable);
hnae3_set_bit(loop_en, HCLGE_MAC_TX_UNDER_MIN_ERR_B, enable);
req = (struct hclge_config_mac_mode_cmd *)desc.data;
req->txrx_pad_fcs_loop_en = cpu_to_le32(loop_en);
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret)
dev_err(&hdev->pdev->dev,
"set mac state %x fail, ret = %d.\n", enable, ret);
hclge_set_phy_state(handle, enable);
return ret;
}
static int hclge_config_nic_clock(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
u32 nic_clock_en = *(u32 *)data;
struct hclge_desc desc;
int ret = 0;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CONFIG_NIC_CLOCK, false);
desc.data[0] = nic_clock_en;
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret)
dev_err(&hdev->pdev->dev,
"config_nic_clock %x fail, ret = %d.\n",
nic_clock_en, ret);
return ret;
}
static int hclge_set_pfc_storm_para(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_pfc_storm_para *para;
struct hclge_desc desc;
int ret = 0;
para = (struct hclge_pfc_storm_para *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CFG_PAUSE_STORM_PARA,
false);
desc.data[0] = para->dir;
desc.data[1] = para->enable;
desc.data[2] = para->period_ms;
desc.data[3] = para->times;
desc.data[4] = para->recovery_period_ms;
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "set pfc storm para failed %d\n",
ret);
return ret;
}
return 0;
}
static int hclge_get_pfc_storm_para(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_pfc_storm_para *para;
struct hclge_desc desc;
int ret = 0;
para = (struct hclge_pfc_storm_para *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CFG_PAUSE_STORM_PARA, true);
desc.data[0] = para->dir;
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "get pfc storm para failed %d\n",
ret);
return ret;
}
para->enable = desc.data[1];
para->period_ms = desc.data[2];
para->times = desc.data[3];
para->recovery_period_ms = desc.data[4];
return 0;
}
enum hclge_phy_op_code {
PHY_OP_READ,
PHY_OP_WRITE,
PHY_OP_MAX,
};
static int hclge_phy_need_page_select(struct hclge_dev *hdev,
enum hclge_phy_op_code opt_type,
struct hclge_phy_para *para,
u16 *cur_page)
{
struct hclge_mac *mac = &hdev->hw.mac;
struct mii_bus *mdio_bus = mac->mdio_bus;
u32 phyid = mac->phy_addr;
int ret;
/* no need to change page when page param is 0 */
if (opt_type != PHY_OP_READ || para->page != 0) {
ret = mdio_bus->read(mdio_bus, phyid, para->page_select_addr);
if (ret < 0) {
dev_err(&hdev->pdev->dev,
"record current phy %d reg page failed.\n",
phyid);
return ret;
}
*cur_page = ret;
if (para->page != *cur_page)
return 1;
else
return 0;
}
return 0;
}
static int hclge_check_phy_opt_param(struct hclge_dev *hdev,
struct mii_bus *mdio_bus,
struct phy_device *phydev,
enum hclge_phy_op_code opt_type)
{
if (!phydev) {
dev_err(&hdev->pdev->dev, "this net dev has no phy.");
return -EINVAL;
}
if (!mdio_bus) {
dev_err(&hdev->pdev->dev, "this net dev has no mdio bus.");
return -EINVAL;
}
if (opt_type >= PHY_OP_MAX) {
dev_err(&hdev->pdev->dev, "unsupported phy operate type %d.",
opt_type);
return -EINVAL;
}
return 0;
}
static int hclge_mdio_bus_opt(struct hclge_phy_para *para,
struct hclge_dev *hdev,
struct mii_bus *mdio_bus, u32 phyid,
enum hclge_phy_op_code opt_type)
{
int op_ret;
if (opt_type == PHY_OP_READ) {
op_ret = mdio_bus->read(mdio_bus, phyid, para->reg_addr);
if (op_ret < 0) {
dev_err(&hdev->pdev->dev,
"read phy %u page %d reg %d failed.\n",
phyid, para->page, para->reg_addr);
} else {
para->data = (u16)op_ret;
op_ret = 0;
}
} else {
op_ret = mdio_bus->write(mdio_bus, phyid, para->reg_addr,
para->data);
if (op_ret < 0) {
dev_err(&hdev->pdev->dev,
"write phy %u page %d reg %d failed.\n",
phyid, para->page, para->reg_addr);
}
}
return op_ret;
}
static int hclge_phy_reg_opt(struct hnae3_handle *handle, void *data,
enum hclge_phy_op_code opt_type)
{
struct hclge_phy_para *para = (struct hclge_phy_para *)data;
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_mac *mac = &hdev->hw.mac;
struct mii_bus *mdio_bus = mac->mdio_bus;
u32 phyid = mac->phy_addr;
int need_page_select;
u16 cur_page;
int op_ret;
int ret;
ret = hclge_check_phy_opt_param(hdev, mdio_bus, mac->phydev, opt_type);
if (ret < 0)
return ret;
/* operate flow:
* 1 record current page address
* 2 jump to operated page
* 3 operate register(read or write)
* 4 come back to the page recorded in the first step.
*/
mutex_lock(&mdio_bus->mdio_lock);
/* check if page select is needed and record current page address */
ret = hclge_phy_need_page_select(hdev, opt_type, para, &cur_page);
if (ret < 0) {
mutex_unlock(&mdio_bus->mdio_lock);
return ret;
}
need_page_select = ret;
/* jump to operated page */
if (need_page_select) {
ret = mdio_bus->write(mdio_bus, phyid, para->page_select_addr,
para->page);
if (ret < 0) {
mutex_unlock(&mdio_bus->mdio_lock);
dev_err(&hdev->pdev->dev,
"change phy %d page %d to page %d failed.\n",
phyid, cur_page, para->page);
return ret;
}
}
/* operate register(read or write) */
op_ret = hclge_mdio_bus_opt(para, hdev, mdio_bus, phyid, opt_type);
/* come back to the page recorded in the first step. */
if (need_page_select) {
ret = mdio_bus->write(mdio_bus, phyid, para->page_select_addr,
cur_page);
if (ret < 0) {
mutex_unlock(&mdio_bus->mdio_lock);
dev_err(&hdev->pdev->dev,
"restore phy %d reg page %u failed.\n",
phyid, cur_page);
return ret;
}
}
mutex_unlock(&mdio_bus->mdio_lock);
return op_ret;
}
static int hclge_get_phy_reg(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
return hclge_phy_reg_opt(handle, data, PHY_OP_READ);
}
static int hclge_set_phy_reg(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
return hclge_phy_reg_opt(handle, data, PHY_OP_WRITE);
}
static int hclge_8211_phy_indirect_opt(struct hclge_phy_para *para,
struct hclge_dev *hdev,
struct mii_bus *mdio_bus,
u32 phyid,
enum hclge_phy_op_code opt_type)
{
u32 indirect_reg_data;
int op_ret;
/* select indirect page 0xa43 */
op_ret = mdio_bus->write(mdio_bus, phyid, para->page_select_addr,
HCLGE_8211_PHY_INDIRECT_PAGE);
if (op_ret < 0) {
dev_err(&hdev->pdev->dev,
"change phy %d indirect page 0xa43 failed.\n", phyid);
return op_ret;
}
/* ndirect access address = page_no*16 + 2*(reg_no%16) */
indirect_reg_data = (para->page << 4) + ((para->reg_addr % 16) << 1);
op_ret = mdio_bus->write(mdio_bus, phyid,
HCLGE_8211_PHY_INDIRECT_REG,
indirect_reg_data);
if (op_ret < 0) {
dev_err(&hdev->pdev->dev,
"write phy %d indirect reg failed.\n", phyid);
return op_ret;
}
if (opt_type == PHY_OP_READ) {
op_ret = mdio_bus->read(mdio_bus, phyid,
HCLGE_8211_PHY_INDIRECT_DATA);
if (op_ret < 0) {
dev_err(&hdev->pdev->dev,
"read phy %d indirect data failed.\n", phyid);
} else {
para->data = (u16)op_ret;
op_ret = 0;
}
} else {
op_ret = mdio_bus->write(mdio_bus, phyid,
HCLGE_8211_PHY_INDIRECT_DATA,
para->data);
if (op_ret < 0) {
dev_err(&hdev->pdev->dev,
"write phy %d indirect data failed.\n", phyid);
}
}
return op_ret;
}
static int hclge_8211_phy_reg_opt(struct hnae3_handle *handle, void *data,
enum hclge_phy_op_code opt_type)
{
struct hclge_phy_para *para = (struct hclge_phy_para *)data;
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_mac *mac = &hdev->hw.mac;
struct mii_bus *mdio_bus = mac->mdio_bus;
u32 phyid = mac->phy_addr;
u16 save_page;
int ret;
ret = hclge_check_phy_opt_param(hdev, mdio_bus, mac->phydev, opt_type);
if (ret < 0)
return ret;
mutex_lock(&mdio_bus->mdio_lock);
ret = mdio_bus->read(mdio_bus, phyid, para->page_select_addr);
if (ret < 0) {
dev_err(&hdev->pdev->dev,
"record phy %d reg page failed.\n",
phyid);
mutex_unlock(&mdio_bus->mdio_lock);
return ret;
}
save_page = ret;
ret = hclge_8211_phy_indirect_opt(para, hdev, mdio_bus, phyid,
opt_type);
if (ret)
dev_err(&hdev->pdev->dev,
"8211 phy %d indirect access failed.\n", phyid);
ret = mdio_bus->write(mdio_bus, phyid, para->page_select_addr,
save_page);
if (ret < 0)
dev_err(&hdev->pdev->dev,
"restore phy %d reg page %u failed.\n",
phyid, save_page);
mutex_unlock(&mdio_bus->mdio_lock);
return ret;
}
static int hclge_8211_phy_need_indirect_access(u16 page)
{
if (page >= HCLGE_8211_PHY_INDIRECT_RANGE1_S &&
page <= HCLGE_8211_PHY_INDIRECT_RANGE1_E)
return true;
else if (page >= HCLGE_8211_PHY_INDIRECT_RANGE2_S &&
page <= HCLGE_8211_PHY_INDIRECT_RANGE2_E)
return true;
else
return false;
}
static int hclge_opt_lookup_mac_tbl(struct hclge_vport *vport,
unsigned char *addr)
{
u32 low_val = addr[4] | (addr[5] << 8);
struct hclge_mac_vlan_tbl_entry_cmd req = {0};
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
u8 resp_code;
u32 high_val;
u16 retval;
int ret;
high_val = addr[2] << 16 | (addr[3] << 24) | (addr[0]) | (addr[1] << 8);
hnae3_set_bit(req.flags, HCLGE_MAC_VLAN_BIT0_EN_B, 1);
req.mac_addr_hi32 = cpu_to_le32(high_val);
req.mac_addr_lo16 = cpu_to_le16(low_val & 0xffff);
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_VLAN_ADD, true);
memcpy(desc.data, &req, sizeof(struct hclge_mac_vlan_tbl_entry_cmd));
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev,
"lookup mac addr failed for cmd_send, ret = %d.\n",
ret);
return ret;
}
resp_code = (le32_to_cpu(desc.data[0]) >> 8) & 0xff;
retval = le16_to_cpu(desc.retval);
if (retval) {
dev_err(&hdev->pdev->dev,
"cmdq execute failed for %s, retval = %d.\n",
__func__, retval);
return -EIO;
}
if (!resp_code) {
return 0;
} else if (resp_code == 1) {
dev_dbg(&hdev->pdev->dev, "lookup mac addr failed for miss.\n");
return -ENOENT;
}
dev_err(&hdev->pdev->dev,
"lookup mac addr failed for undefined, code = %d.\n",
resp_code);
return -EIO;
}
static int hclge_opt_mac_table(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_mac_table_para *info = (struct hclge_mac_table_para *)data;
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = NULL;
int ret;
if (!info || !vport)
return -EIO;
hdev = vport->back;
switch (info->op_cmd) {
case HCLGE_OPT_TABLE_LOOKUP:
ret = hclge_opt_lookup_mac_tbl(vport, info->mac_addr);
if (ret == -ENOENT) {
return ret;
} else if (ret) {
dev_err(&hdev->pdev->dev,
"ext lookup uc mac address(%pM) fail, ret = %d.\n",
info->mac_addr, ret);
return -EIO;
}
break;
case HCLGE_OPT_TABLE_ADD:
ret = hclge_add_uc_addr_common(vport, info->mac_addr);
if (ret == -ENOSPC) {
return ret;
} else if (ret) {
dev_err(&hdev->pdev->dev,
"ext add uc mac address(%pM) fail, ret = %d.\n",
info->mac_addr, ret);
return -EIO;
}
break;
case HCLGE_OPT_TABLE_DEL:
ret = hclge_rm_uc_addr_common(vport, info->mac_addr);
if (ret == -ENOENT) {
return ret;
} else if (ret) {
dev_warn(&hdev->pdev->dev,
"ext remove uc mac address(%pM) fail, ret = %d.\n",
info->mac_addr, ret);
return -EIO;
}
break;
default:
dev_err(&hdev->pdev->dev, "ext opcode error.\n");
return -EIO;
}
return ret;
}
static int hclge_set_reset_task(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
u32 *reset_level = (u32 *)data;
dev_warn(&hdev->pdev->dev, "reset level is %d\n", *reset_level);
/* request reset & schedule reset task */
set_bit(*reset_level, &hdev->reset_request);
hclge_reset_task_schedule_it(hdev);
return 0;
}
static int hclge_get_hilink_ref_los(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
u32 *hilink_ref_los_status;
int ret;
hilink_ref_los_status = (u32 *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_CFG_GET_HILINK_REF_LOS,
true);
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev,
"get hilink ref los failed, ret = %d\n", ret);
return ret;
}
*hilink_ref_los_status = desc.data[0];
return 0;
}
static int hclge_get_8211_phy_reg(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_phy_para *para = (struct hclge_phy_para *)data;
if (hclge_8211_phy_need_indirect_access(para->page))
return hclge_8211_phy_reg_opt(handle, data, PHY_OP_READ);
else
return hclge_phy_reg_opt(handle, data, PHY_OP_READ);
}
static int hclge_set_8211_phy_reg(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_phy_para *para = (struct hclge_phy_para *)data;
if (hclge_8211_phy_need_indirect_access(para->page))
return hclge_8211_phy_reg_opt(handle, data, PHY_OP_WRITE);
else
return hclge_phy_reg_opt(handle, data, PHY_OP_WRITE);
}
static int hclge_get_port_wire_type(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_sfp_info_cmd *resp = NULL;
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
u32 *wire_type;
int ret;
wire_type = (u32 *)data;
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SFP_GET_PORT_INFO, true);
resp = (struct hclge_sfp_info_cmd *)desc.data;
resp->query_type = PORT_QUERY_TYPE_SFP;
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev,
"get port info failed, ret = %d\n", ret);
return ret;
}
*wire_type = resp->module_type;
return 0;
}
static struct hclge_ext_func hclge_ext_func_arr[] = {
{HCLGE_EXT_OPC_CLEAN_STATS64, hclge_clean_stats64},
{HCLGE_EXT_OPC_GET_CHIPID, hclge_get_chipid},
{HCLGE_EXT_OPC_GET_SFPINFO, hclge_get_sfpinfo},
{HCLGE_EXT_OPC_SET_SFP_STATE, hclge_set_sfp_state},
{HCLGE_EXT_OPC_GET_CHIP_NUM, hclge_get_chip_num},
{HCLGE_EXT_OPC_GET_PORT_NUM, hclge_get_port_num},
{HCLGE_EXT_OPC_SET_LED, hclge_set_led},
{HCLGE_EXT_OPC_GET_PRESENT, hclge_get_sfp_present},
{HCLGE_EXT_OPC_DISABLE_LANE, hclge_disable_net_lane},
{HCLGE_EXT_OPC_GET_LANE_STATUS, hclge_get_net_lane_status},
{HCLGE_EXT_OPC_GET_LED_SIGNAL, hclge_get_led_signal},
{HCLGE_EXT_OPC_SET_MAC_STATE, hclge_set_mac_state},
{HCLGE_EXT_OPC_CONFIG_CLOCK, hclge_config_nic_clock},
{HCLGE_EXT_OPC_GET_PFC_STORM_PARA, hclge_get_pfc_storm_para},
{HCLGE_EXT_OPC_SET_PFC_STORM_PARA, hclge_set_pfc_storm_para},
{HCLGE_EXT_OPC_GET_PHY_REG, hclge_get_phy_reg},
{HCLGE_EXT_OPC_SET_PHY_REG, hclge_set_phy_reg},
{HCLGE_EXT_OPC_GET_MAC_ID, hclge_get_mac_id},
{HCLGE_EXT_OPC_OPT_MAC_TABLE, hclge_opt_mac_table},
{HCLGE_EXT_OPC_RESET, hclge_set_reset_task},
{HCLGE_EXT_OPC_GET_HILINK_REF_LOS, hclge_get_hilink_ref_los},
{HCLGE_EXT_OPC_GET_8211_PHY_REG, hclge_get_8211_phy_reg},
{HCLGE_EXT_OPC_SET_8211_PHY_REG, hclge_set_8211_phy_reg},
{HCLGE_EXT_OPC_GET_PORT_TYPE, hclge_get_port_wire_type},
};
int hclge_ext_ops_handle(struct hnae3_handle *handle, int opcode,
void *data, int length)
{
struct hclge_vport *vport = hclge_get_vport(handle);
int cmd_num = ARRAY_SIZE(hclge_ext_func_arr);
struct hclge_dev *hdev = vport->back;
if (opcode >= cmd_num) {
dev_err(&hdev->pdev->dev, "not support opcode %d.\n", opcode);
return -EOPNOTSUPP;
}
if (opcode != hclge_ext_func_arr[opcode].opcode) {
dev_err(&hdev->pdev->dev, "opcode %d is not equals %d.\n",
opcode, hclge_ext_func_arr[opcode].opcode);
return -EINVAL;
}
return hclge_ext_func_arr[opcode].priv_ops(handle, opcode, data,
length);
}
#endif
#endif
/* SPDX-License-Identifier: GPL-2.0+ */
/* Copyright (c) 2016-2017 Hisilicon Limited. */
#ifndef __HCLGE_EXT_H
#define __HCLGE_EXT_H
#include <linux/types.h>
#include "hnae3.h"
#ifdef CONFIG_IT_VALIDATION
#define HCLGE_SFP_INFO_LEN 6
#define HCLGE_SFP_INFO_SIZE 140
#define HCLGE_8211_PHY_INDIRECT_PAGE 0xa43
#define HCLGE_8211_PHY_INDIRECT_REG 0x1b
#define HCLGE_8211_PHY_INDIRECT_DATA 0x1c
#define HCLGE_8211_PHY_INDIRECT_RANGE1_S 0xDC0
#define HCLGE_8211_PHY_INDIRECT_RANGE1_E 0xDCF
#define HCLGE_8211_PHY_INDIRECT_RANGE2_S 0xDE0
#define HCLGE_8211_PHY_INDIRECT_RANGE2_E 0xDF0
#define HCLGE_OPC_CONFIG_NIC_CLOCK 0x0060
#define PORT_QUERY_TYPE_SFP 1
struct hclge_chip_id_cmd {
u32 chip_id;
u32 rsv[5];
};
struct hclge_sfp_info_para {
u8 *buff;
u16 offset;
u16 size;
u16 *outlen;
};
struct hclge_sfp_info {
u32 sfpinfo[6];
};
struct hclge_led_state {
u32 type;
u32 status;
};
struct hclge_pfc_storm_para {
u32 dir;
u32 enable;
u32 period_ms;
u32 times;
u32 recovery_period_ms;
};
struct hclge_phy_para {
u32 page_select_addr;
u32 reg_addr;
u16 page;
u16 data;
};
struct hclge_sfp_enable_cmd {
u32 set_sfp_enable_flag;
u32 rsv[5];
};
struct hclge_sfp_present_cmd {
u32 sfp_present;
u32 rsv[5];
};
struct hclge_lamp_signal {
u8 error;
u8 locate;
u8 activity;
};
struct hclge_mac_table_para {
u8 op_cmd;
u8 mac_addr[ETH_ALEN];
};
enum hclge_ext_op_code {
HCLGE_EXT_OPC_CLEAN_STATS64 = 0,
HCLGE_EXT_OPC_GET_CHIPID,
HCLGE_EXT_OPC_GET_SFPINFO,
HCLGE_EXT_OPC_SET_SFP_STATE,
HCLGE_EXT_OPC_GET_CHIP_NUM,
HCLGE_EXT_OPC_GET_PORT_NUM,
HCLGE_EXT_OPC_SET_LED,
HCLGE_EXT_OPC_GET_PRESENT,
HCLGE_EXT_OPC_DISABLE_LANE,
HCLGE_EXT_OPC_GET_LANE_STATUS,
HCLGE_EXT_OPC_GET_LED_SIGNAL,
HCLGE_EXT_OPC_SET_MAC_STATE,
HCLGE_EXT_OPC_CONFIG_CLOCK,
HCLGE_EXT_OPC_GET_PFC_STORM_PARA,
HCLGE_EXT_OPC_SET_PFC_STORM_PARA,
HCLGE_EXT_OPC_GET_PHY_REG,
HCLGE_EXT_OPC_SET_PHY_REG,
HCLGE_EXT_OPC_GET_MAC_ID,
HCLGE_EXT_OPC_OPT_MAC_TABLE,
HCLGE_EXT_OPC_RESET,
HCLGE_EXT_OPC_GET_HILINK_REF_LOS,
HCLGE_EXT_OPC_GET_8211_PHY_REG,
HCLGE_EXT_OPC_SET_8211_PHY_REG,
HCLGE_EXT_OPC_GET_PORT_TYPE,
};
enum hclge_opt_table_code {
HCLGE_OPT_TABLE_LOOKUP,
HCLGE_OPT_TABLE_ADD,
HCLGE_OPT_TABLE_DEL,
};
struct hclge_ext_func {
int opcode;
int (*priv_ops)(struct hnae3_handle *handle, int opcode,
void *data, int length);
};
enum hclge_ext_opcode_type {
/* misc command */
HCLGE_OPC_CHIP_ID_GET = 0x7003,
HCLGE_OPC_IMP_COMMIT_ID_GET = 0x7004,
HCLGE_OPC_GET_CHIP_NUM = 0x7005,
HCLGE_OPC_GET_PORT_NUM = 0x7006,
HCLGE_OPC_SET_LED = 0x7007,
HCLGE_OPC_DISABLE_NET_LANE = 0x7008,
HCLGE_OPC_CFG_PAUSE_STORM_PARA = 0x7019,
HCLGE_OPC_CFG_GET_HILINK_REF_LOS = 0x701B,
/*SFP command */
HCLGE_OPC_SFP_GET_INFO = 0x7100,
HCLGE_OPC_SFP_GET_PRESENT = 0x7101,
HCLGE_OPC_SFP_SET_STATUS = 0x7102,
HCLGE_OPC_SFP_GET_PORT_INFO = 0x7104,
};
int hclge_ext_ops_handle(struct hnae3_handle *handle, int opcode,
void *data, int length);
void hclge_reset_task_schedule_it(struct hclge_dev *hdev);
#endif
#endif
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "hclge_cmd.h" #include "hclge_cmd.h"
#include "hclge_main.h" #include "hclge_main.h"
#include "hnae3.h" #include "hnae3.h"
#include "hclge_ext.h"
#include "hclge_main_it.h" #include "hclge_main_it.h"
#ifdef CONFIG_IT_VALIDATION #ifdef CONFIG_IT_VALIDATION
...@@ -46,17 +45,16 @@ int nic_unregister_event(void) ...@@ -46,17 +45,16 @@ int nic_unregister_event(void)
} }
EXPORT_SYMBOL(nic_unregister_event); EXPORT_SYMBOL(nic_unregister_event);
void nic_call_event(struct net_device *netdev, static void nic_call_event(struct net_device *netdev,
enum hnae3_event_type_custom event_t) enum hnae3_event_type_custom event_t)
{ {
if (nic_event_call) { if (nic_event_call) {
nic_event_call(netdev, event_t); nic_event_call(netdev, event_t);
netdev_info(netdev, "report event %d\n", event_t); netdev_info(netdev, "report event %d\n", event_t);
} }
} }
EXPORT_SYMBOL(nic_call_event);
void hclge_handle_imp_error_it(struct hnae3_handle *handle) static void hclge_handle_imp_error_it(struct hnae3_handle *handle)
{ {
struct hclge_vport *vport = hclge_get_vport(handle); struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back; struct hclge_dev *hdev = vport->back;
...@@ -85,6 +83,14 @@ void hclge_handle_imp_error_it(struct hnae3_handle *handle) ...@@ -85,6 +83,14 @@ void hclge_handle_imp_error_it(struct hnae3_handle *handle)
} }
static void hclge_reset_task_schedule_it(struct hclge_dev *hdev)
{
if (!test_bit(HCLGE_STATE_REMOVING, &hdev->state) &&
!test_and_set_bit(HCLGE_STATE_RST_SERVICE_SCHED, &hdev->state))
mod_delayed_work_on(cpumask_first(&hdev->affinity_mask),
system_wq, &hdev->service_task, 0);
}
void hclge_reset_event_it(struct pci_dev *pdev, struct hnae3_handle *handle) void hclge_reset_event_it(struct pci_dev *pdev, struct hnae3_handle *handle)
{ {
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev); struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
...@@ -168,10 +174,6 @@ bool hclge_reset_done_it(struct hnae3_handle *handle, bool done) ...@@ -168,10 +174,6 @@ bool hclge_reset_done_it(struct hnae3_handle *handle, bool done)
int hclge_init_it(void) int hclge_init_it(void)
{ {
#ifdef CONFIG_HNS3_TEST
hclge_ops.priv_ops = hclge_ext_ops_handle;
#endif
hclge_ops.reset_event = hclge_reset_event_it; hclge_ops.reset_event = hclge_reset_event_it;
hclge_ops.reset_done = hclge_reset_done_it; hclge_ops.reset_done = hclge_reset_done_it;
hclge_ops.handle_imp_error = hclge_handle_imp_error_it; hclge_ops.handle_imp_error = hclge_handle_imp_error_it;
......
...@@ -48,7 +48,5 @@ int nic_register_event(nic_event_fn_t event_call); ...@@ -48,7 +48,5 @@ int nic_register_event(nic_event_fn_t event_call);
*/ */
int nic_unregister_event(void); int nic_unregister_event(void);
void nic_call_event(struct net_device *netdev,
enum hnae3_event_type_custom event_t);
int hclge_init(void); int hclge_init(void);
#endif #endif
// SPDX-License-Identifier: GPL-2.0+
// Copyright (c) 2016-2017 Hisilicon Limited.
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/phy_fixed.h>
#include <linux/platform_device.h>
#include "hclge_cmd.h"
#include "hclge_main.h"
#include "hnae3.h"
#include "hns3_enet.h"
#include "hns3_cae_cmd.h"
#include "hns3_cae_common.h"
static int hns3_cae_write_reg_cfg(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size,
void *buf_out, u32 out_size)
{
struct reg_param *in_buf = (struct reg_param *)buf_in;
struct hclge_vport *vport = NULL;
struct hclge_dev *hdev = NULL;
struct hclge_desc desc;
int ret;
vport = hns3_cae_get_vport(net_priv->ae_handle);
hdev = vport->back;
if (in_buf->bits_width == 64) {
hns3_cae_cmd_setup_basic_desc(&desc, CMDQ_64_COM_CMD_OPCODE,
false);
desc.data[0] = in_buf->addr;
desc.data[1] = in_buf->data[0];
} else {
hns3_cae_cmd_setup_basic_desc(&desc, CMDQ_32_COM_CMD_OPCODE,
false);
desc.data[0] = in_buf->addr;
desc.data[2] = in_buf->data[0];
}
ret = hns3_cae_cmd_send(hdev, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "%s fail, ret is %d.\n", __func__,
ret);
return ret;
}
return 0;
}
static int hns3_cae_read_reg_cfg(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size,
void *buf_out, u32 out_size)
{
struct hclge_vport *vport = hns3_cae_get_vport(net_priv->ae_handle);
struct reg_ret_param *out_buf = (struct reg_ret_param *)buf_out;
struct reg_param *in_buf = (struct reg_param *)buf_in;
struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
bool check = !buf_out || out_size < sizeof(struct reg_param);
int ret;
if (check) {
pr_err("input param buf_out error in %s function\n", __func__);
return -EFAULT;
}
if (in_buf->bits_width == 64)
hns3_cae_cmd_setup_basic_desc(&desc,
CMDQ_64_COM_CMD_OPCODE, true);
else
hns3_cae_cmd_setup_basic_desc(&desc,
CMDQ_32_COM_CMD_OPCODE, true);
desc.data[0] = in_buf->addr;
ret = hns3_cae_cmd_send(hdev, &desc, 1);
if (ret) {
dev_err(&hdev->pdev->dev, "%s fail, ret is %d.\n", __func__,
ret);
return ret;
}
out_buf->value[0] = desc.data[0];
if (in_buf->bits_width == 64)
out_buf->value[1] = desc.data[1];
return 0;
}
int hns3_cae_reg_cfg(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size, void *buf_out,
u32 out_size)
{
bool check = !buf_in || in_size < sizeof(struct reg_param);
struct reg_param *mode_param = (struct reg_param *)buf_in;
int ret;
if (check) {
pr_err("input param buf_in error in %s function\n", __func__);
return -EFAULT;
}
if (mode_param->is_read == 1)
ret = hns3_cae_read_reg_cfg(net_priv, buf_in, in_size,
buf_out, out_size);
else
ret = hns3_cae_write_reg_cfg(net_priv, buf_in, in_size,
buf_out, out_size);
return ret;
}
/* SPDX-License-Identifier: GPL-2.0+ */
/* Copyright (c) 2016-2019 Hisilicon Limited. */
#ifndef __HNS3_CAE_COMMON_H
#define __HNS3_CAE_COMMON_H
#define REG_RDATA_NUM 2
#define CMDQ_32_COM_CMD_OPCODE 0xfffd
#define CMDQ_64_COM_CMD_OPCODE 0xffff
struct reg_param {
u32 addr;
u32 data[REG_RDATA_NUM];
u8 bits_width;
u8 is_read;
};
struct reg_ret_param {
u32 value[REG_RDATA_NUM];
};
int hns3_cae_reg_cfg(const struct hns3_nic_priv *net_priv, void *buf_in,
u32 in_size, void *buf_out, u32 out_size);
#endif
...@@ -220,13 +220,7 @@ int hns3_cae_dcb_pfc_cfg(const struct hns3_nic_priv *net_priv, ...@@ -220,13 +220,7 @@ int hns3_cae_dcb_pfc_cfg(const struct hns3_nic_priv *net_priv,
dcb_all_info[curr_dev_idx].pfc_cfg_info.prien = dcb_all_info[curr_dev_idx].pfc_cfg_info.prien =
in_info->prien; in_info->prien;
if (ndev->dcbnl_ops->ieee_setpfc) { if (ndev->dcbnl_ops->ieee_setpfc) {
#ifdef CONFIG_EXT_TEST
rtnl_lock();
#endif
ret = ndev->dcbnl_ops->ieee_setpfc(ndev, &pfc); ret = ndev->dcbnl_ops->ieee_setpfc(ndev, &pfc);
#ifdef CONFIG_EXT_TEST
rtnl_unlock();
#endif
if (ret) if (ret)
return ret; return ret;
} }
...@@ -397,13 +391,7 @@ int hns3_cae_dcb_ets_cfg(const struct hns3_nic_priv *net_priv, ...@@ -397,13 +391,7 @@ int hns3_cae_dcb_ets_cfg(const struct hns3_nic_priv *net_priv,
curr_dev_idx); curr_dev_idx);
if (ndev->dcbnl_ops->ieee_setets) { if (ndev->dcbnl_ops->ieee_setets) {
#ifdef CONFIG_EXT_TEST
rtnl_lock();
#endif
ret = ndev->dcbnl_ops->ieee_setets(ndev, &ets); ret = ndev->dcbnl_ops->ieee_setets(ndev, &ets);
#ifdef CONFIG_EXT_TEST
rtnl_unlock();
#endif
if (ret) if (ret)
return ret; return ret;
} }
......
// SPDX-License-Identifier: GPL-2.0+
// Copyright (c) 2016-2017 Hisilicon Limited.
#if (defined CONFIG_EXT_TEST) && (defined CONFIG_IT_VALIDATION)
#include "hns3_cae_ext.h"
#include "hns3_ext.h"
static int hns3_disable_netclk(const struct hns3_nic_priv *net_priv)
{
struct net_device *netdev = net_priv->netdev;
return nic_disable_clock(netdev);
}
static int hns3_get_cpu_affinity(const struct hns3_nic_priv *priv)
{
struct hns3_enet_tqp_vector *tqp_vector = NULL;
struct hnae3_handle *h = NULL;
int i;
if (!priv) {
pr_err("invalid input param when get cpu affinity\n");
return -EINVAL;
}
h = priv->ae_handle;
if (nic_netdev_match_check(priv->netdev))
return -ENODEV;
pr_info("%s : %d irq total.\n", h->pdev->driver->name,
priv->vector_num);
for (i = 0; i < priv->vector_num; i++) {
tqp_vector = &priv->tqp_vector[i];
if (tqp_vector->irq_init_flag != HNS3_VECTOR_INITED)
continue;
pr_err("irq %d ==> cpu affinity: %*pb\n",
tqp_vector->vector_irq,
cpumask_pr_args(&tqp_vector->affinity_mask));
}
return 0;
}
static int hns3_affi(const struct hns3_nic_priv *net_priv, void *in)
{
struct hns3_cpumask_param *cpumask_param = NULL;
cpumask_var_t cpumask_new;
int ret;
cpumask_param = (struct hns3_cpumask_param *)in;
if (cpumask_param->affi_exec_flag != HNS3_AFFI_GET_BIT) {
if (!alloc_cpumask_var(&cpumask_new, GFP_KERNEL))
return -ENOMEM;
ret = cpumask_parse(cpumask_param->mask, cpumask_new);
if (ret) {
pr_err("parse cpu affinity from user fail, ret = %d\n",
ret);
return ret;
}
ret = nic_set_cpu_affinity(net_priv->netdev, cpumask_new);
if (ret) {
pr_err("set cpu affinity fail, ret = %d\n", ret);
return ret;
}
} else {
ret = hns3_get_cpu_affinity(net_priv);
if (ret) {
pr_err("get cpu affinity fail, ret = %d\n", ret);
return ret;
}
}
return ret;
}
static int hns3_get_chipid(const struct hns3_nic_priv *net_priv, void *out)
{
u32 chip_id;
int ret;
ret = nic_get_chipid(net_priv->netdev, &chip_id);
if (!ret)
*(u32 *)out = chip_id;
return ret;
}
static int hns3_match_check(const struct hns3_nic_priv *net_priv)
{
struct net_device *netdev = net_priv->netdev;
return nic_netdev_match_check(netdev);
}
static int hns3_set_led(const struct hns3_nic_priv *net_priv, void *in)
{
struct hns3_led_state_para *para = (struct hns3_led_state_para *)in;
struct net_device *netdev = net_priv->netdev;
return nic_set_led(netdev, para->type, para->status);
}
static int hns3_get_sfp_info(const struct hns3_nic_priv *net_priv, void *in,
void *out)
{
struct hns3_priv_sfp_info_para *para_in =
(struct hns3_priv_sfp_info_para *)in;
struct hns3_priv_sfp_info_para *para_out =
(struct hns3_priv_sfp_info_para *)out;
struct net_device *netdev = net_priv->netdev;
int ret;
ret = nic_get_sfpinfo(netdev, para_out->buff, para_in->size,
&para_out->outlen);
return ret;
}
static int hns3_get_sfp_present(const struct hns3_nic_priv *net_priv,
void *out)
{
struct net_device *netdev = net_priv->netdev;
u32 present;
int ret;
ret = nic_get_sfp_present(netdev, &present);
if (!ret)
*(u32 *)out = present;
return ret;
}
static int hns3_set_sfp_state(const struct hns3_nic_priv *net_priv, void *in)
{
struct net_device *netdev = net_priv->netdev;
bool en = *(bool *)in;
return nic_set_sfp_state(netdev, en);
}
static int hns3_clean_stats64(const struct hns3_nic_priv *net_priv)
{
struct net_device *netdev = net_priv->netdev;
return nic_clean_stats64(netdev, NULL);
}
static int hns3_get_chip_num(const struct hns3_nic_priv *net_priv, void *out)
{
u32 chip_num;
int ret;
ret = nic_get_chip_num(net_priv->netdev, &chip_num);
if (!ret)
*(u32 *)out = chip_num;
return ret;
}
static int hns3_get_port_num(const struct hns3_nic_priv *net_priv, void *out)
{
u32 port_num;
int ret;
ret = nic_get_port_num_per_chip(net_priv->netdev, &port_num);
if (!ret)
*(u32 *)out = port_num;
return ret;
}
static int hns3_disable_net_lane(const struct hns3_nic_priv *net_priv)
{
struct net_device *netdev = net_priv->netdev;
return nic_disable_net_lane(netdev);
}
static int hns3_get_lane_status(const struct hns3_nic_priv *net_priv,
void *out)
{
u32 lane_status;
int ret;
ret = nic_get_net_lane_status(net_priv->netdev, &lane_status);
if (!ret)
*(u32 *)out = lane_status;
return ret;
}
static int hns3_set_mac_state(const struct hns3_nic_priv *net_priv, void *in)
{
struct net_device *netdev = net_priv->netdev;
int enable = *(int *)in;
return nic_set_mac_state(netdev, enable);
}
static int hns3_set_pfc_storm_para(const struct hns3_nic_priv *net_priv,
void *in)
{
struct hns3_pfc_storm_para *para = (struct hns3_pfc_storm_para *)in;
struct net_device *netdev = net_priv->netdev;
return nic_set_pfc_storm_para(netdev, para->dir, para->enable,
para->period_ms, para->times,
para->recovery_period_ms);
}
static int hns3_get_pfc_storm_para(const struct hns3_nic_priv *net_priv,
void *in, void *out)
{
struct hns3_pfc_storm_para *para_in = (struct hns3_pfc_storm_para *)in;
struct net_device *netdev = net_priv->netdev;
struct hns3_pfc_storm_para *para_out =
(struct hns3_pfc_storm_para *)out;
u32 recovery_period_ms;
u32 period_ms;
u32 enable;
u32 times;
u32 dir;
int ret;
dir = para_in->dir;
ret = nic_get_pfc_storm_para(netdev, dir, &enable, &period_ms,
&times, &recovery_period_ms);
if (!ret) {
para_out->dir = dir;
para_out->enable = enable;
para_out->period_ms = period_ms;
para_out->times = times;
para_out->recovery_period_ms = recovery_period_ms;
}
return ret;
}
static int hns3_get_phy_reg(const struct hns3_nic_priv *net_priv,
void *in, void *out,
enum phy_type phy_type)
{
struct hns3_phy_para *para_out = (struct hns3_phy_para *)out;
struct hns3_phy_para *para_in = (struct hns3_phy_para *)in;
u32 page_select_addr = para_in->page_select_addr;
struct net_device *netdev = net_priv->netdev;
u32 reg_addr = para_in->reg_addr;
u16 page = para_in->page;
u16 data;
int ret;
if (phy_type == PHY_TYPE_8211)
ret = nic_get_8211_phy_reg(netdev, page_select_addr, page,
reg_addr, &data);
else
ret = nic_get_phy_reg(netdev, page_select_addr, page, reg_addr,
&data);
if (!ret) {
para_out->page = page;
para_out->reg_addr = reg_addr;
para_out->data = data;
}
return ret;
}
static int hns3_set_phy_reg(const struct hns3_nic_priv *net_priv, void *in,
enum phy_type phy_type)
{
struct hns3_phy_para *para = (struct hns3_phy_para *)in;
struct net_device *netdev = net_priv->netdev;
if (phy_type == PHY_TYPE_8211)
return nic_set_8211_phy_reg(netdev, para->page_select_addr,
para->page, para->reg_addr,
para->data);
else
return nic_set_phy_reg(netdev, para->page_select_addr,
para->page, para->reg_addr,
para->data);
}
static int hns3_get_macid(const struct hns3_nic_priv *net_priv, void *out)
{
u32 mac_id;
int ret;
ret = nic_get_mac_id(net_priv->netdev, &mac_id);
if (!ret)
*(u32 *)out = mac_id;
return ret;
}
static int hns3_get_hilink_ref_los(const struct hns3_nic_priv *net_priv,
void *out)
{
u32 status;
int ret;
ret = nic_get_hilink_ref_los(net_priv->netdev, &status);
if (!ret)
*(u32 *)out = status;
return ret;
}
static int hns3_get_port_type(const struct hns3_nic_priv *net_priv, void *out)
{
u32 wire_type;
int ret;
ret = nic_get_port_wire_type(net_priv->netdev, &wire_type);
if (!ret)
*(u32 *)out = wire_type;
return ret;
}
int hns3_ext_interface_test(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size,
void *buf_out, u32 out_size)
{
struct cmd_ext_driver_param *ext_param_out =
(struct cmd_ext_driver_param *)buf_out;
struct cmd_ext_driver_param *ext_param_in =
(struct cmd_ext_driver_param *)buf_in;
bool check = !buf_in || in_size < sizeof(struct cmd_ext_driver_param) ||
!buf_out || out_size < sizeof(struct cmd_ext_driver_param);
void *out = NULL;
void *in = NULL;
int ret;
if (check) {
pr_err("input parameter error in %s function\n", __func__);
return -EFAULT;
}
in = ext_param_in->buf;
out = ext_param_out->buf;
switch (ext_param_in->op_code) {
case EXT_AFFI_MASK:
ret = hns3_affi(net_priv, in);
break;
case EXT_DISABLE_NET_CLK:
ret = hns3_disable_netclk(net_priv);
break;
case EXT_GET_CHIP_ID:
ret = hns3_get_chipid(net_priv, out);
break;
case EXT_NET_MATCH_CHECK:
ret = hns3_match_check(net_priv);
break;
case EXT_SET_LED:
ret = hns3_set_led(net_priv, in);
break;
case EXT_GET_SFP_INFO:
ret = hns3_get_sfp_info(net_priv, in, out);
break;
case EXT_GET_SFP_PRESENT:
ret = hns3_get_sfp_present(net_priv, out);
break;
case EXT_SET_SFP_STATE:
ret = hns3_set_sfp_state(net_priv, in);
break;
case EXT_CLEAN_STATS64:
ret = hns3_clean_stats64(net_priv);
break;
case EXT_GET_CHIP_NUM:
ret = hns3_get_chip_num(net_priv, out);
break;
case EXT_GET_PORT_NUM:
ret = hns3_get_port_num(net_priv, out);
break;
case EXT_DISABLE_NET_LANE:
ret = hns3_disable_net_lane(net_priv);
break;
case EXT_GET_LANE_STATUS:
ret = hns3_get_lane_status(net_priv, out);
break;
case EXT_SET_MAC_STATE:
ret = hns3_set_mac_state(net_priv, in);
break;
case EXT_SET_PFC_STORM_PARA:
ret = hns3_set_pfc_storm_para(net_priv, in);
break;
case EXT_GET_PFC_STORM_PARA:
ret = hns3_get_pfc_storm_para(net_priv, in, out);
break;
case EXT_GET_PHY_REG:
ret = hns3_get_phy_reg(net_priv, in, out, PHY_TYPE_1512);
break;
case EXT_SET_PHY_REG:
ret = hns3_set_phy_reg(net_priv, in, PHY_TYPE_1512);
break;
case EXT_GET_MAC_ID:
ret = hns3_get_macid(net_priv, out);
break;
case EXT_GET_HILINK_REF_LOS:
ret = hns3_get_hilink_ref_los(net_priv, out);
break;
case EXT_GET_8211_PHY_REG:
ret = hns3_get_phy_reg(net_priv, in, out, PHY_TYPE_8211);
break;
case EXT_SET_8211_PHY_REG:
ret = hns3_set_phy_reg(net_priv, in, PHY_TYPE_8211);
break;
case EXT_GET_PORT_TYPE:
ret = hns3_get_port_type(net_priv, out);
break;
default:
ret = -EFAULT;
}
return ret;
}
#endif
/* SPDX-License-Identifier: GPL-2.0+ */
/* Copyright (c) 2016-2019 Hisilicon Limited. */
#ifndef __HNS3_CAE_EXT_H
#define __HNS3_CAE_EXT_H
#include "hnae3.h"
#include "hns3_enet.h"
#define HNS3_AFFI_SET_BIT BIT(0)
#define HNS3_AFFI_GET_BIT BIT(1)
#define HNS3_AFFI_MAX_LEN 34
enum ext_op_code {
EXT_AFFI_MASK = 0,
EXT_DISABLE_NET_CLK,
EXT_GET_CHIP_ID,
EXT_NET_MATCH_CHECK,
EXT_SET_LED,
EXT_GET_SFP_INFO,
EXT_GET_SFP_PRESENT,
EXT_SET_SFP_STATE,
EXT_CLEAN_STATS64,
EXT_GET_CHIP_NUM,
EXT_GET_PORT_NUM,
EXT_DISABLE_NET_LANE,
EXT_GET_LANE_STATUS,
EXT_SET_MAC_STATE,
EXT_SET_PFC_STORM_PARA,
EXT_GET_PFC_STORM_PARA,
EXT_GET_PHY_REG,
EXT_SET_PHY_REG,
EXT_GET_MAC_ID,
EXT_GET_HILINK_REF_LOS,
EXT_GET_8211_PHY_REG,
EXT_SET_8211_PHY_REG,
EXT_GET_PORT_TYPE,
};
enum phy_type {
PHY_TYPE_8211 = 0,
PHY_TYPE_1512,
};
struct hns3_cpumask_param {
u32 affi_exec_flag;
char mask[HNS3_AFFI_MAX_LEN];
};
struct hns3_priv_sfp_info_para {
u8 buff[768];
u16 offset;
u16 size;
u16 outlen;
};
struct cmd_ext_driver_param {
u32 op_code;
u32 judge_class;
u8 buf[1024];
};
int hns3_ext_interface_test(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size,
void *buf_out, u32 out_size);
#endif
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "hns3_cae_cmd.h" #include "hns3_cae_cmd.h"
#include "hns3_cae_tm.h" #include "hns3_cae_tm.h"
#include "hns3_cae_dcb.h" #include "hns3_cae_dcb.h"
#include "hns3_cae_pkt.h"
#include "hns3_cae_mac.h" #include "hns3_cae_mac.h"
#include "hns3_cae_dfx.h" #include "hns3_cae_dfx.h"
#include "hns3_cae_vlan.h" #include "hns3_cae_vlan.h"
...@@ -29,12 +28,9 @@ ...@@ -29,12 +28,9 @@
#include "hns3_cae_promisc.h" #include "hns3_cae_promisc.h"
#include "hns3_cae_fd.h" #include "hns3_cae_fd.h"
#include "hns3_cae_rss.h" #include "hns3_cae_rss.h"
#include "hns3_cae_common.h"
#include "hns3_cae_qres.h" #include "hns3_cae_qres.h"
#include "hns3_cae_stat.h" #include "hns3_cae_stat.h"
#include "hns3_cae_irq.h" #include "hns3_cae_irq.h"
#include "hns3_cae_lamp.h"
#include "hns3_cae_ext.h"
#include "hns3_cae_pfc_storm.h" #include "hns3_cae_pfc_storm.h"
#include "hns3_cae_xsfp.h" #include "hns3_cae_xsfp.h"
#include "hns3_cae_port.h" #include "hns3_cae_port.h"
...@@ -44,7 +40,6 @@ ...@@ -44,7 +40,6 @@
#include "hns3_cae_dcqcn.h" #include "hns3_cae_dcqcn.h"
#include "hns3_cae_reset.h" #include "hns3_cae_reset.h"
#include "hns3_cae_gro.h" #include "hns3_cae_gro.h"
#include "hns3_cae_mactbl.h"
#include "hns3_cae_led.h" #include "hns3_cae_led.h"
#define MAX_MSG_OUT_SIZE (1024U * 2048U) #define MAX_MSG_OUT_SIZE (1024U * 2048U)
...@@ -153,7 +148,7 @@ static int hns3_cae_netdev_match_check(struct net_device *netdev) ...@@ -153,7 +148,7 @@ static int hns3_cae_netdev_match_check(struct net_device *netdev)
netdev->ethtool_ops->get_drvinfo(netdev, &drv_info); netdev->ethtool_ops->get_drvinfo(netdev, &drv_info);
if (!strncmp(drv_info.driver, hns3_driver_name, if (!strncmp(drv_info.driver, hns3_driver_name,
strlen(hns3_driver_name))) strlen(hns3_driver_name) + 1))
return 0; return 0;
netdev_err(netdev, "match hns3 driver name(%s) failed\n", netdev_err(netdev, "match hns3 driver name(%s) failed\n",
...@@ -243,7 +238,6 @@ struct drv_module_handle driv_module_cmd_handle[] = { ...@@ -243,7 +238,6 @@ struct drv_module_handle driv_module_cmd_handle[] = {
{DFX_INFO_CMD, hns3_cae_get_dfx_info}, {DFX_INFO_CMD, hns3_cae_get_dfx_info},
{DFX_READ_CMD, hns3_cae_read_dfx_info}, {DFX_READ_CMD, hns3_cae_read_dfx_info},
{EVENT_INJECTION_CMD, hns3_cae_event_injection}, {EVENT_INJECTION_CMD, hns3_cae_event_injection},
{SEND_PKT, hns3_cae_send_pkt},
{RX_PRIV_BUFF_WL_CFG, hns3_cae_rx_priv_buff_wl_cfg}, {RX_PRIV_BUFF_WL_CFG, hns3_cae_rx_priv_buff_wl_cfg},
{RX_COMMON_THRD_CFG, hns3_cae_common_thrd_cfg}, {RX_COMMON_THRD_CFG, hns3_cae_common_thrd_cfg},
{RX_COMMON_WL_CFG, hns3_cae_common_wl_cfg}, {RX_COMMON_WL_CFG, hns3_cae_common_wl_cfg},
...@@ -257,26 +251,16 @@ struct drv_module_handle driv_module_cmd_handle[] = { ...@@ -257,26 +251,16 @@ struct drv_module_handle driv_module_cmd_handle[] = {
{GET_BD_BUFF_SIZE, hns3_gro_dump_bd_buff_size}, {GET_BD_BUFF_SIZE, hns3_gro_dump_bd_buff_size},
{PROMISC_MODE_CFG, hns3_promisc_mode_cfg}, {PROMISC_MODE_CFG, hns3_promisc_mode_cfg},
{QINFO_CFG, hns3_cae_qinfo_cfg}, {QINFO_CFG, hns3_cae_qinfo_cfg},
#ifdef CONFIG_IT_VALIDATION
{MACTABLE_CFG, hns3_cae_opt_mactbl},
#endif
{CLEAN_STATS, hns3_cae_clean_stats}, {CLEAN_STATS, hns3_cae_clean_stats},
{FD_CFG, hns3_cae_fd_cfg}, {FD_CFG, hns3_cae_fd_cfg},
{RSS_GENERIC_CFG, hns3_cae_rss_cfg}, {RSS_GENERIC_CFG, hns3_cae_rss_cfg},
{REG_CFG, hns3_cae_reg_cfg},
{COM_REG_CFG, hns3_cae_common_cmd_send}, {COM_REG_CFG, hns3_cae_common_cmd_send},
{GRO_CFG, hns3_gro_age_handle}, {GRO_CFG, hns3_gro_age_handle},
{M7_CMD_MODE_CFG, hns3_m7_cmd_handle},
{QRES_CFG, hns3_cae_qres_cfg}, {QRES_CFG, hns3_cae_qres_cfg},
{STAT_CFG, hns3_stat_mode_cfg}, {STAT_CFG, hns3_stat_mode_cfg},
{IRQ_CFG, hns3_irq_lli_cfg}, {IRQ_CFG, hns3_irq_lli_cfg},
{VLAN_UPMAPPING, hns3_cae_upmapping_cfg}, {VLAN_UPMAPPING, hns3_cae_upmapping_cfg},
#ifdef CONFIG_EXT_TEST
{LAMP_CFG, hns3_lamp_cfg},
{EXTERN_INTERFACE_CFG, hns3_ext_interface_test},
#else
{EXTERN_INTERFACE_CFG, hns3_cae_pfc_storm_cfg}, {EXTERN_INTERFACE_CFG, hns3_cae_pfc_storm_cfg},
#endif
{XSFP_CFG, hns3_xsfp_cfg}, {XSFP_CFG, hns3_xsfp_cfg},
{SHOW_PORT_INFO, hns3_get_port_info}, {SHOW_PORT_INFO, hns3_get_port_info},
{SHOW_HILINK_PARAM, hns3_get_hilink_param}, {SHOW_HILINK_PARAM, hns3_get_hilink_param},
...@@ -342,7 +326,6 @@ static long hns3_cae_k_unlocked_ioctl(struct file *pfile, unsigned int cmd, ...@@ -342,7 +326,6 @@ static long hns3_cae_k_unlocked_ioctl(struct file *pfile, unsigned int cmd,
pr_err("alloc out buffer failed\n"); pr_err("alloc out buffer failed\n");
goto out_free_buf_in; goto out_free_buf_in;
} }
#ifndef CONFIG_EXT_TEST
/** /**
* After decoupling with driver, the scenario of hns driver unregister * After decoupling with driver, the scenario of hns driver unregister
* must be considered. In this scenario, driver unregister may happened * must be considered. In this scenario, driver unregister may happened
...@@ -352,7 +335,6 @@ static long hns3_cae_k_unlocked_ioctl(struct file *pfile, unsigned int cmd, ...@@ -352,7 +335,6 @@ static long hns3_cae_k_unlocked_ioctl(struct file *pfile, unsigned int cmd,
* code yet, so we don't need lock. * code yet, so we don't need lock.
*/ */
rtnl_lock(); rtnl_lock();
#endif
ret = hns3_cae_k_get_netdev_by_ifname(nt_msg.device_name, &nic_dev); ret = hns3_cae_k_get_netdev_by_ifname(nt_msg.device_name, &nic_dev);
if (ret) { if (ret) {
pr_err("can not get the netdevice correctly\n"); pr_err("can not get the netdevice correctly\n");
...@@ -380,18 +362,14 @@ static long hns3_cae_k_unlocked_ioctl(struct file *pfile, unsigned int cmd, ...@@ -380,18 +362,14 @@ static long hns3_cae_k_unlocked_ioctl(struct file *pfile, unsigned int cmd,
ret = -EINVAL; ret = -EINVAL;
goto out_invalid; goto out_invalid;
} }
#ifndef CONFIG_EXT_TEST
rtnl_unlock(); rtnl_unlock();
#endif
ret = copy_buf_out_to_user(&nt_msg, out_size, buf_out); ret = copy_buf_out_to_user(&nt_msg, out_size, buf_out);
if (ret) if (ret)
pr_err("copy buf to user failed\n"); pr_err("copy buf to user failed\n");
goto out_free_buf_out; goto out_free_buf_out;
out_invalid: out_invalid:
#ifndef CONFIG_EXT_TEST
rtnl_unlock(); rtnl_unlock();
#endif
out_free_buf_out: out_free_buf_out:
free_buff_out(buf_out); free_buff_out(buf_out);
out_free_buf_in: out_free_buf_in:
......
// SPDX-License-Identifier: GPL-2.0+
// Copyright (c) 2016-2017 Hisilicon Limited.
#ifdef CONFIG_EXT_TEST
#include "hclge_cmd.h"
#include "hnae3.h"
#include "hclge_main.h"
#include "hns3_enet.h"
#include "hns3_cae_lamp.h"
int hns3_lamp_cfg(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size, void *buf_out, u32 out_size)
{
struct net_device *netdev = net_priv->netdev;
struct hns3_lamp_signal *signal = NULL;
struct hns3_lamp_param *param = NULL;
int ret = -1;
if (!buf_in || in_size < sizeof(struct hns3_lamp_param))
return -ENODEV;
param = (struct hns3_lamp_param *)buf_in;
signal = (struct hns3_lamp_signal *)buf_out;
if (param->op_type == LAMP_OP_GET_SGPIO) {
if (!buf_out || out_size < sizeof(struct hns3_lamp_signal))
return -ENODEV;
ret = nic_get_led_signal(netdev, signal);
} else if (param->op_type == LAMP_OP_SET_TYPE) {
ret = nic_set_led(netdev, param->type, param->status);
}
return ret;
}
#endif
/* SPDX-License-Identifier: GPL-2.0+ */
/* Copyright (c) 2016-2019 Hisilicon Limited. */
#ifndef __HNS3_CAE_LAMP_H__
#define __HNS3_CAE_LAMP_H__
#include "hclge_cmd.h"
#include "hnae3.h"
#include "hclge_main.h"
#include "hns3_enet.h"
enum hns3_lamp_spgio_e {
LAMP_OP_GET_SGPIO = 0,
LAMP_OP_SET_TYPE,
LAMP_OP_UNKNOWN
};
struct hns3_lamp_param {
u32 op_type;
u32 type;
u32 status;
};
struct hns3_lamp_signal {
u8 error;
u8 locate;
u8 activity;
};
int hns3_lamp_cfg(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size,
void *buf_out, u32 out_size);
int nic_get_led_signal(struct net_device *ndev,
struct hns3_lamp_signal *signal);
int nic_set_led(struct net_device *ndev, int type, int status);
#endif
...@@ -63,53 +63,3 @@ int hns3_cae_common_cmd_send(const struct hns3_nic_priv *net_priv, ...@@ -63,53 +63,3 @@ int hns3_cae_common_cmd_send(const struct hns3_nic_priv *net_priv,
return 0; return 0;
} }
int hns3_m7_cmd_handle(const struct hns3_nic_priv *nic_dev, void *buf_in,
u32 in_size, void *buf_out, u32 out_size)
{
struct hclge_vport *vport = hns3_cae_get_vport(nic_dev->ae_handle);
struct m7_cmd_para *cmd_para = (struct m7_cmd_para *)buf_in;
struct hclge_dev *hdev = vport->back;
struct hclge_desc *desc = NULL;
u32 bd_size;
bool check = !buf_in || in_size < sizeof(struct m7_cmd_para);
int ret;
if (check) {
pr_err("input param buf_in error in %s function\n", __func__);
return -EFAULT;
}
bd_size = sizeof(struct hclge_desc) * cmd_para->bd_count;
desc = kzalloc(bd_size, GFP_KERNEL);
if (ZERO_OR_NULL_PTR(desc)) {
pr_err("desc kzalloc failed in m7_cmd_handle function\n");
return -ENOMEM;
}
if (copy_from_user((void *)desc, cmd_para->bd_data, bd_size)) {
pr_err("copy from user failed in m7_cmd_handle function\n");
kfree(desc);
return -EFAULT;
}
ret = hns3_cae_cmd_send(hdev, desc, cmd_para->bd_count);
if (ret) {
dev_err(&hdev->pdev->dev,
"generic cmd send fail, ret is %d.\n", ret);
kfree(desc);
return ret;
}
if (desc->flag & HCLGE_CMD_FLAG_WR) {
if (!buf_out || out_size < bd_size) {
pr_err("input param buf_out error in %s function\n",
__func__);
kfree(desc);
return -EFAULT;
}
memcpy(buf_out, desc, bd_size);
}
kfree(desc);
return 0;
}
...@@ -138,6 +138,4 @@ int hns3_cae_common_cmd_send(const struct hns3_nic_priv *net_priv, ...@@ -138,6 +138,4 @@ int hns3_cae_common_cmd_send(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size, void *buf_out, void *buf_in, u32 in_size, void *buf_out,
u32 out_size); u32 out_size);
int hns3_m7_cmd_handle(const struct hns3_nic_priv *nic_dev, void *buf_in,
u32 in_size, void *buf_out, u32 out_size);
#endif #endif
// SPDX-License-Identifier: GPL-2.0+
// Copyright (c) 2016-2017 Hisilicon Limited.
#ifdef CONFIG_IT_VALIDATION
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/phy_fixed.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include "hclge_cmd.h"
#include "hnae3.h"
#include "hclge_main.h"
#include "hns3_enet.h"
#include "hns3_ext.h"
#include "hns3_cae_mactbl.h"
int hns3_cae_opt_mactbl(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size,
void *buf_out, u32 out_size)
{
#ifndef CONFIG_HNS3_TEST
return -EOPNOTSUPP;
#else
struct hns3_mac_tbl_para *out = (struct hns3_mac_tbl_para *)buf_out;
struct hns3_mac_tbl_para *in = (struct hns3_mac_tbl_para *)buf_in;
struct net_device *netdev = net_priv->netdev;
struct hnae3_handle *h = NULL;
bool check = !buf_in || in_size < sizeof(struct hns3_mac_tbl_para) ||
!buf_out || out_size < sizeof(struct hns3_mac_tbl_para);
int ret;
if (check) {
pr_err("input parameter error in %s function\n", __func__);
return -EFAULT;
}
h = hns3_get_handle(netdev);
if (!h->ae_algo->ops->priv_ops)
return -EOPNOTSUPP;
out->op_cmd = in->op_cmd;
memcpy(out->mac_addr, in->mac_addr, sizeof(in->mac_addr));
ret = h->ae_algo->ops->priv_ops(h, HNS3_EXT_OPC_OPT_MAC_TABLE, in, 0);
if (!ret) {
out->result = HNS3_MACTBL_RESULT_SUCCESS;
return 0;
} else if (ret == -ENOENT) {
out->result = HNS3_MACTBL_RESULT_NOEXIST;
return 0;
}
out->result = HNS3_MACTBL_RESULT_FAIL;
return ret;
#endif
}
#endif
/* SPDX-License-Identifier: GPL-2.0+ */
/* Copyright (c) 2016-2019 Hisilicon Limited. */
#ifndef __HNS3_CAE_MACTBL_H__
#define __HNS3_CAE_MACTBL_H__
enum hns3_mac_table_code {
HNS3_MACTBL_OPT_TABLE_LOOKUP,
HNS3_MACTBL_OPT_TABLE_ADD,
HNS3_MACTBL_OPT_TABLE_DEL,
};
enum hns3_mac_result_code {
HNS3_MACTBL_RESULT_SUCCESS,
HNS3_MACTBL_RESULT_FAIL,
HNS3_MACTBL_RESULT_NOEXIST,
HNS3_MACTBL_RESULT_NOSPACE
};
struct hns3_mac_tbl_para {
u8 op_cmd;
u8 mac_addr[6];
u8 result;
};
int hns3_cae_opt_mactbl(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size,
void *buf_out, u32 out_size);
#endif
// SPDX-License-Identifier: GPL-2.0+
// Copyright (c) 2016-2017 Hisilicon Limited.
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/inetdevice.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_net.h>
#include <linux/if_ether.h>
#include <linux/if_vlan.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/kthread.h>
#include "hns3_enet.h"
#include "hns3_cae_pkt.h"
#define DEFAULT_PAGE_SIZE 4096
#define DEFAULT_TCP_MSS 1460
#define DEFAULT_MIN_PKT_LEN 60
#define NEXTHDR_HOP 0
u8 pkt_head_table[HNS3_CAE_PKT_TYPE_MAX][128] = {
/* ARP */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0xee, 0x08, 0x06, 0x00, 0x01,
0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0xee, 0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* TCP */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0xee, 0x08, 0x00, 0x45, 0x00,
0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0xfd,
0xe4, 0x33, 0xc0, 0xa8, 0x0a, 0x0a, 0xc0, 0xa8,
0x0a, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* TCP_DSCP */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0xee, 0x08, 0x00, 0x45, 0x00,
0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x40, 0xfd,
0xe4, 0x33, 0xc0, 0xa8, 0x0a, 0x0a, 0xc0, 0xa8,
0x0a, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* PAUSE */
{
0x01, 0x80, 0xc2, 0x00, 0x00, 0x01, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x06, 0x88, 0x08, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* PAUSE_ERR */
{
0x01, 0x80, 0xc2, 0x00, 0x00, 0x01, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x06, 0x88, 0x08, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* PFC */
{
0x01, 0x80, 0xc2, 0x00, 0x00, 0x01, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x06, 0x88, 0x08, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* PFC_ERR */
{
0x01, 0x80, 0xc2, 0x00, 0x00, 0x01, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x06, 0x88, 0x08, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* IPV4 */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x02, 0x08, 0x00, 0x45, 0x00,
0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x40, 0xfd,
0x75, 0x8b, 0xc0, 0xa8, 0x0a, 0x0a, 0xc0, 0xa8,
0x0a, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* IPV4_LOOSE_OPTION */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x03, 0x08, 0x00,
0x46, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00,
0x40, 0x06, 0x00, 0x00, 0xc0, 0xa8, 0x0a, 0x0b,
0xc0, 0xa8, 0x0a, 0x0a,
0x83, 0x00, 0x04, 0x00,
0x00, 0x64, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
0x19, 0x09, 0x00, 0x00
},
/* IPV4_TRACEROUTE_OPTION */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x03, 0x08, 0x00,
0x48, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00,
0x40, 0x06, 0x00, 0x00, 0xc0, 0xa8, 0x0a, 0x0b,
0xc0, 0xa8, 0x0a, 0x0a,
0x52, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x00, 0x00, 0x01,
0x00, 0x64, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
0x19, 0x09, 0x00, 0x00
},
/* IPV6 */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x02, 0x86, 0xdd, 0x60, 0x00,
0x00, 0x00, 0x05, 0xdc, 0x3b, 0xff, 0xfe, 0xc0,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x00,
0x00, 0x00, 0xc0, 0xa8, 0x0a, 0x0b, 0xfe, 0xc0,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x00,
0x00, 0x00, 0xc0, 0x55, 0x01, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
},
/* ipv6_extension_routing */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x03, 0x86, 0xdd,
0x60, 0x00, 0x00, 0x00, 0x05, 0xdc, 0x2b, 0xff,
0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x02, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x0a, 0x0b,
0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x02, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x0a, 0x0a,
0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x16, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x21,
0x16, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x22,
0x00, 0x64, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
0x15, 0x99, 0x00, 0x00
},
/* IPV4+SCTP */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x02, 0x08, 0x00,
0x45, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00,
0x40, 0x84, 0x00, 0x00, 0x80, 0x05, 0x7a, 0xb5,
0x80, 0x05, 0x7a, 0xab,
0x00, 0x64, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04,
},
/* IPV6+SCTP */
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xaa,
0xbb, 0xcc, 0xdd, 0x02, 0x86, 0xdd,
0x60, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x84, 0xff,
0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x02, 0x00, 0x00, 0x00, 0x80, 0x05, 0x7a, 0xb5,
0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
0x02, 0x00, 0x00, 0x00, 0x80, 0x05, 0x7a, 0xab,
0x00, 0x64, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04,
},
};
#define MAX_KTHREAD_NUM 16
struct kthread_info {
int tid;
struct task_struct *task;
int stop;
const struct hns3_nic_priv *net_priv;
struct hns3_cae_pkt_cfg_info *in_info;
struct hns3_cae_pkt_result_info *out_info;
};
struct kthread_info *kthread_table[MAX_KTHREAD_NUM] = {0};
/* This mutexes are created for packets send */
struct mutex pkt_mutex[MAX_KTHREAD_NUM];
int is_send_thread(int tid)
{
return (tid % 2 == 0);
}
int __get_tid(int queue_id, int is_send)
{
if (is_send)
return (queue_id * 2) % MAX_KTHREAD_NUM;
else
return (queue_id * 2 + 1) % MAX_KTHREAD_NUM;
}
void fill_skb_head(struct sk_buff *skb, int mss)
{
struct ipv6hdr *ip6_hdr = NULL;
int protocol;
skb->network_header = ETH_HLEN;
if (skb->protocol == htons(ETH_P_8021Q)) {
skb->network_header += VLAN_HLEN;
protocol = vlan_get_protocol(skb);
} else {
protocol = skb->protocol;
}
if (protocol == htons(ETH_P_IP))
skb->transport_header = skb->network_header +
ip_hdr(skb)->ihl * 4;
if (protocol == htons(ETH_P_IPV6)) {
ip6_hdr = (struct ipv6hdr *)skb_network_header(skb);
skb->transport_header = skb->network_header +
sizeof(struct ipv6hdr);
if (ip6_hdr->nexthdr == NEXTHDR_HOP)
skb->transport_header += (skb_transport_header(skb)[1] +
1) << 3;
skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
}
skb_shinfo(skb)->gso_size = mss;
}
static struct sk_buff *__hns_assemble_skb(struct net_device *ndev,
const void *data, int length,
int queue_id, int mss)
{
const struct ethhdr *ethhead = (const struct ethhdr *)data;
const char *head_data = (const char *)data;
struct sk_buff *skb = NULL;
struct page *p = NULL;
void *buff = NULL;
int proc_length;
int bnum = 0;
if (mss <= 0) {
pr_err("mss(=%d) of packet is invalid\n", mss);
return NULL;
}
/* allocate test skb */
skb = alloc_skb(256, GFP_KERNEL);
if (!skb)
return NULL;
skb->protocol = ethhead->h_proto;
skb->queue_mapping = queue_id;
skb->dev = ndev;
skb_reset_mac_header(skb);
if (length <= 256) {
skb_put(skb, length);
memcpy(&skb->data[0], head_data, length);
} else {
skb_put(skb, 256);
memcpy(&skb->data[0], head_data, 256);
proc_length = length - 256;
while (proc_length > DEFAULT_PAGE_SIZE) {
p = dev_alloc_pages(get_order(DEFAULT_PAGE_SIZE));
if (!p) {
dev_kfree_skb_any(skb);
return NULL;
}
buff = page_address(p);
memcpy(buff, head_data + length - proc_length,
DEFAULT_PAGE_SIZE);
skb_add_rx_frag(skb, bnum, p, 0, DEFAULT_PAGE_SIZE,
DEFAULT_PAGE_SIZE);
proc_length -= DEFAULT_PAGE_SIZE;
bnum++;
}
p = dev_alloc_pages(get_order(DEFAULT_PAGE_SIZE));
if (!p) {
dev_kfree_skb_any(skb);
return NULL;
}
buff = page_address(p);
memcpy(buff, head_data + length - proc_length, proc_length);
skb_add_rx_frag(skb, bnum, p, 0, proc_length,
DEFAULT_PAGE_SIZE);
}
fill_skb_head(skb, mss);
return skb;
}
void hns3_cae_pkt_type_deal(u8 *payload, struct hns3_cae_pkt_cfg_info *in_info,
struct in_ifaddr *ifa_list,
u8 *pkt_payload, u32 head_len)
{
u8 payload_data;
int i;
/* DST_MAC */
memcpy(payload, in_info->dst_mac, ETH_ALEN);
payload[16] = in_info->pkt_len / 256;
payload[17] = in_info->pkt_len % 256;
/* checksum */
memcpy(payload + 24, &in_info->pkt_checksum, 2);
/* SRC_IP */
if (ifa_list)
memcpy(payload + 26, &ifa_list->ifa_address, 4);
/* DST_IP */
memcpy(payload + 30, in_info->dst_ip, 4);
/* payload */
payload_data = in_info->pkt_payload_flag == 1 ? 0xFF : 0;
for (i = 0; i < in_info->pkt_len; i++)
pkt_payload[i] = payload_data;
memcpy(payload + head_len, pkt_payload, in_info->pkt_len - head_len);
}
void __fill_the_pkt_head(struct net_device *netdev, u8 *payload,
struct hns3_cae_pkt_cfg_info *in_info)
{
struct in_ifaddr *ifa_list = NULL;
u8 *pkt_payload = NULL;
u32 vlan_tag;
size_t count;
int i;
pkt_payload = kzalloc((in_info->pkt_len) * sizeof(u8), GFP_KERNEL);
if (ZERO_OR_NULL_PTR(pkt_payload))
return;
count = in_info->pkt_len > 128 ? 128 : in_info->pkt_len;
memcpy(payload, pkt_head_table[in_info->type], count);
memcpy(payload + 6, netdev->dev_addr, ETH_ALEN);
ifa_list = (struct in_ifaddr *)netdev->ip_ptr->ifa_list;
switch (in_info->type) {
case HNS3_CAE_PKT_TYPE_ARP:
memcpy(payload + 22, netdev->dev_addr, ETH_ALEN);
if (ifa_list)
memcpy(payload + 28, &ifa_list->ifa_address, 4);
memcpy(payload + 32, in_info->dst_mac, ETH_ALEN);
memcpy(payload + 38, in_info->dst_ip, 4);
break;
case HNS3_CAE_PKT_TYPE_TCP:
memcpy(payload, in_info->dst_mac, ETH_ALEN);
payload[16] = in_info->pkt_len / 256;
payload[17] = in_info->pkt_len % 256;
if (ifa_list)
memcpy(payload + 26, &ifa_list->ifa_address, 4);
memcpy(payload + 30, in_info->dst_ip, 4);
break;
case HNS3_CAE_PKT_TYPE_TCP_DSCP:
memcpy(payload, in_info->dst_mac, ETH_ALEN);
payload[15] = (in_info->dscp << 2);
payload[16] = in_info->pkt_len / 256;
payload[17] = in_info->pkt_len % 256;
if (ifa_list)
memcpy(payload + 26, &ifa_list->ifa_address, 4);
memcpy(payload + 30, in_info->dst_ip, 4);
break;
case HNS3_CAE_PKT_TYPE_PAUSE:
memcpy(payload + 16, &in_info->pause_time, 2);
break;
case HNS3_CAE_PKT_TYPE_PAUSE_ERR:
memcpy(payload, in_info->dst_mac, ETH_ALEN);
memcpy(payload + 12, &in_info->eth_type, 2);
memcpy(payload + 14, &in_info->pause_code, 2);
memcpy(payload + 16, &in_info->pause_time, 2);
break;
case HNS3_CAE_PKT_TYPE_PFC:
payload[17] = in_info->priority;
for (i = 0; i < 8; i++) {
if ((in_info->priority >> i) & 0x01)
memcpy(payload + 18 + i * 2,
&in_info->pause_time, 2);
}
break;
case HNS3_CAE_PKT_TYPE_PFC_ERR:
memcpy(payload, in_info->dst_mac, ETH_ALEN);
memcpy(payload + 12, &in_info->eth_type, 2);
memcpy(payload + 14, &in_info->pause_code, 2);
payload[17] = in_info->priority;
for (i = 0; i < 8; i++) {
if ((in_info->priority >> i) & 0x01)
memcpy(payload + 18 + i * 2,
&in_info->pause_time, 2);
}
break;
case HNS3_CAE_PKT_TYPE_IPV4:
hns3_cae_pkt_type_deal(payload, in_info, ifa_list, pkt_payload,
34);
break;
case HNS3_CAE_PKT_TYPE_IPV4_LOOSESRCROUTE_OPTION:
hns3_cae_pkt_type_deal(payload, in_info, ifa_list, pkt_payload,
58);
break;
case HNS3_CAE_PKT_TYPE_IPV4_TRACEROUTE_OPTION:
if (in_info->pkt_len < IPV4_TRACEROUTE_PKT_LEN) {
dev_err(&netdev->dev,
"pkt_len(=%d) of ipv4 trace route pkt must big than %d.\n",
in_info->pkt_len, IPV4_TRACEROUTE_PKT_LEN);
kfree(pkt_payload);
return;
}
hns3_cae_pkt_type_deal(payload, in_info, ifa_list, pkt_payload,
IPV4_TRACEROUTE_PKT_LEN);
break;
case HNS3_CAE_PKT_TYPE_IPV6:
memcpy(payload, in_info->dst_mac, ETH_ALEN);
memcpy(payload + 22, in_info->pkt_inet6_addr, 16);
hns3_cae_pkt_type_deal(payload, in_info, ifa_list, pkt_payload,
54);
break;
case HNS3_CAE_PKT_TYPE_IPV6_EXTENSION_ROUTING:
if (in_info->pkt_len < IPV6_EXTENSION_PKT_LEN) {
dev_err(&netdev->dev,
"pkt_len(=%d) of ipv6 extension pkt must big than %d.\n",
in_info->pkt_len, IPV6_EXTENSION_PKT_LEN);
kfree(pkt_payload);
return;
}
memcpy(payload, in_info->dst_mac, ETH_ALEN);
memcpy(payload + 22, in_info->pkt_inet6_addr, 16);
hns3_cae_pkt_type_deal(payload, in_info, ifa_list, pkt_payload,
IPV6_EXTENSION_PKT_LEN);
break;
case HNS3_CAE_PKT_TYPE_SCTP4:
memcpy(payload, in_info->dst_mac, ETH_ALEN);
/* SRC_IP */
if (ifa_list)
memcpy(payload + 26, &ifa_list->ifa_address, 4);
memcpy(payload + 30, in_info->dst_ip, 4);
/* checksum */
memcpy(payload + 42, &in_info->pkt_checksum_sctp, 4);
break;
case HNS3_CAE_PKT_TYPE_SCTP6:
memcpy(payload, in_info->dst_mac, ETH_ALEN);
memcpy(payload + 22, in_info->pkt_inet6_addr, 16);
/* checksum */
memcpy(payload + 62, &in_info->pkt_checksum_sctp, 4);
break;
default:
break;
}
if (in_info->vlan_tag) {
memmove(payload + 16, payload + 12, 48);
vlan_tag = htonl(in_info->vlan_tag);
memcpy(payload + 12, &vlan_tag, sizeof(vlan_tag));
}
kfree(pkt_payload);
}
#define MAX_PKTS_NUM_ONCE 50
static int __hns3_cae_change_send_queue(int cur_queue,
struct hns3_cae_pkt_cfg_info *in_info,
u8 *payload)
{
int queue_id = cur_queue;
queue_id++;
if (queue_id >= in_info->queue_id + in_info->multi_queue)
queue_id = in_info->queue_id;
/* use last ip for different queue */
if (in_info->multi_queue > 1)
payload[33] = queue_id % 255;
return queue_id;
}
int __hns3_cae_send_pkt(const struct hns3_nic_priv *net_priv,
struct hns3_cae_pkt_cfg_info *in_info,
struct hns3_cae_pkt_result_info *out_info)
{
struct hnae3_handle *handle = NULL;
struct sk_buff *skb = NULL;
u8 *payload = NULL;
int pkt_len;
int ret = 0;
int i;
int change_flag;
int total_len;
int tid;
int queue_id = in_info->queue_id;
struct net_device *netdev = net_priv->netdev;
handle = net_priv->ae_handle;
if (queue_id >= handle->kinfo.num_tqps ||
queue_id + in_info->multi_queue - 1 >= handle->kinfo.num_tqps ||
queue_id < 0) {
pr_err("%s,%d:queue(%d) or multi_queue(%d) is invalid\n",
__func__, __LINE__,
in_info->queue_id, in_info->multi_queue);
return -EINVAL;
}
pkt_len = in_info->pkt_len;
if (pkt_len < MIN_PKT_LEN) {
dev_err(&netdev->dev, "pkt_len(=%d) is invalid\n", pkt_len);
return -EINVAL;
}
payload = kzalloc(pkt_len, GFP_KERNEL);
if (ZERO_OR_NULL_PTR(payload))
return -ENOMEM;
__fill_the_pkt_head(netdev, payload, in_info);
tid = __get_tid(queue_id, 1);
total_len = 0;
change_flag = MAX_PKTS_NUM_ONCE;
for (i = 0; i < in_info->num; i++) {
skb_again:
if (in_info->multi_queue > 1) {
change_flag--;
if (change_flag <= 0) {
change_flag = MAX_PKTS_NUM_ONCE;
queue_id =
__hns3_cae_change_send_queue(queue_id,
in_info,
payload);
}
}
skb = __hns_assemble_skb(netdev, payload, pkt_len,
queue_id, in_info->mss);
if (!skb) {
ret = -1;
goto out;
}
send_again:
if (in_info->new_thread && kthread_table[tid]) {
if (kthread_table[tid]->stop) {
dev_kfree_skb_any(skb);
break;
}
}
ret = netdev->netdev_ops->ndo_start_xmit(skb, netdev);
if (ret == NETDEV_TX_BUSY) {
if (in_info->multi_queue > 1) {
dev_kfree_skb_any(skb);
change_flag = 0;
goto skb_again;
}
if (in_info->wait_all_finish) {
schedule();
goto send_again;
}
dev_kfree_skb_any(skb);
break;
}
total_len += pkt_len;
}
out_info->num = i;
out_info->total_len = total_len;
out:
kfree(payload);
return ret;
}
void hns3_cae_pkt_init(void)
{
int i;
for (i = 0; i < MAX_KTHREAD_NUM; i++)
mutex_init(&pkt_mutex[i]);
}
void hns3_cae_pkt_destroy(void)
{
int i;
for (i = 0; i < MAX_KTHREAD_NUM; i++)
mutex_destroy(&pkt_mutex[i]);
}
int __hns3_cae_new_task(void *arg)
{
struct kthread_info *info = (struct kthread_info *)arg;
int tid = info->tid;
if (is_send_thread(tid)) {
__hns3_cae_send_pkt(info->net_priv,
info->in_info, info->out_info);
pr_err("send pkt %d, the total len = %d\n",
info->out_info->num, info->out_info->total_len);
}
mutex_lock(&pkt_mutex[tid]);
kfree(info->in_info);
kfree(info->out_info);
kfree(info);
kthread_table[tid] = NULL;
mutex_unlock(&pkt_mutex[tid]);
return 0;
}
int hns3_cae_create_new_thread(int tid,
const struct hns3_nic_priv *net_priv,
struct hns3_cae_pkt_cfg_info *in_info,
struct hns3_cae_pkt_result_info *out_info)
{
char name[] = "hns3_cae_pkt00";
int ret;
if (kthread_table[tid]) {
pr_err("%s,%d:the thread[%d] is busy!\n", __func__, __LINE__,
tid);
return -EINVAL;
}
kthread_table[tid] = kzalloc(sizeof(*kthread_table[0]), GFP_KERNEL);
if (ZERO_OR_NULL_PTR(kthread_table[tid])) {
pr_err("%s,%d:thread[%d] mem alloc failed\n", __func__,
__LINE__, tid);
return -ENOMEM;
}
kthread_table[tid]->tid = tid;
kthread_table[tid]->net_priv = net_priv;
kthread_table[tid]->in_info = kzalloc(sizeof(*in_info), GFP_KERNEL);
if (ZERO_OR_NULL_PTR(kthread_table[tid]->in_info)) {
pr_err("%s,%d:thread[%d] in info alloc failed\n", __func__,
__LINE__, tid);
ret = -ENOMEM;
goto err_in_info_alloc;
}
kthread_table[tid]->out_info = kzalloc(sizeof(*out_info), GFP_KERNEL);
if (ZERO_OR_NULL_PTR(kthread_table[tid]->out_info)) {
pr_err("%s,%d:thread[%d] out info alloc failed\n", __func__,
__LINE__, tid);
ret = -ENOMEM;
goto err_out_info_alloc;
}
memcpy(kthread_table[tid]->in_info, in_info, sizeof(*in_info));
name[strlen(name) - 2] = tid / 10 + '0';
name[strlen(name) - 1] = tid % 10 + '0';
kthread_table[tid]->task =
kthread_run(__hns3_cae_new_task, kthread_table[tid], "%s", name);
if (IS_ERR(kthread_table[tid]->task)) {
pr_err("%s,%d:thread[%d] alloc failed\n", __func__, __LINE__,
tid);
ret = -EAGAIN;
goto err_kthread_alloc;
}
return 0;
err_kthread_alloc:
kfree(kthread_table[tid]->out_info);
err_out_info_alloc:
kfree(kthread_table[tid]->in_info);
err_in_info_alloc:
kfree(kthread_table[tid]);
kthread_table[tid] = NULL;
return ret;
}
void hns3_cae_stop_new_thread(int tid)
{
mutex_lock(&pkt_mutex[tid]);
if (kthread_table[tid])
kthread_table[tid]->stop = 1;
mutex_unlock(&pkt_mutex[tid]);
}
int hns3_cae_send_pkt(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size, void *buf_out,
u32 out_size)
{
struct hns3_cae_pkt_result_info *out_info =
(struct hns3_cae_pkt_result_info *)buf_out;
struct hns3_cae_pkt_cfg_info *in_info =
(struct hns3_cae_pkt_cfg_info *)buf_in;
struct hnae3_handle *handle = NULL;
int queue_id;
int tid;
if (!in_info || in_size < sizeof(struct hns3_cae_pkt_cfg_info) ||
!out_info || out_size < sizeof(struct hns3_cae_pkt_result_info)) {
pr_err("input parameter error in %s function\n", __func__);
return -EFAULT;
}
handle = net_priv->ae_handle;
queue_id = in_info->queue_id;
if (queue_id >= handle->kinfo.num_tqps || queue_id < 0) {
pr_err("%s,%d:queue(%d) is invalid\n", __func__, __LINE__,
in_info->queue_id);
return -EINVAL;
}
memset(out_info, 0, sizeof(*out_info));
tid = __get_tid(in_info->queue_id, 1);
if (in_info->stop_thread) {
hns3_cae_stop_new_thread(tid);
return 0;
}
if (in_info->new_thread)
return hns3_cae_create_new_thread(tid, net_priv, in_info,
out_info);
return __hns3_cae_send_pkt(net_priv, in_info, out_info);
}
/* SPDX-License-Identifier: GPL-2.0+ */
/* Copyright (c) 2016-2019 Hisilicon Limited. */
#ifndef __HNS3_CAE_PKT_H__
#define __HNS3_CAE_PKT_H__
#include <linux/types.h>
#define IP_ADDR_LEN 4
#define IP6_ADDR_LEN 10
#define MIN_PKT_LEN 64
#define IPV4_TRACEROUTE_PKT_LEN 66
#define IPV6_EXTENSION_PKT_LEN 114
enum PKT_TYPE {
HNS3_CAE_PKT_TYPE_ARP = 0,
HNS3_CAE_PKT_TYPE_TCP,
HNS3_CAE_PKT_TYPE_TCP_DSCP,
HNS3_CAE_PKT_TYPE_PAUSE,
HNS3_CAE_PKT_TYPE_PAUSE_ERR,
HNS3_CAE_PKT_TYPE_PFC,
HNS3_CAE_PKT_TYPE_PFC_ERR,
HNS3_CAE_PKT_TYPE_IPV4,
HNS3_CAE_PKT_TYPE_IPV4_LOOSESRCROUTE_OPTION,
HNS3_CAE_PKT_TYPE_IPV4_TRACEROUTE_OPTION,
HNS3_CAE_PKT_TYPE_IPV6,
HNS3_CAE_PKT_TYPE_IPV6_EXTENSION_ROUTING,
HNS3_CAE_PKT_TYPE_SCTP4,
HNS3_CAE_PKT_TYPE_SCTP6,
HNS3_CAE_PKT_TYPE_MAX,
};
struct hns3_cae_pkt_cfg_info {
int queue_id;
int type;
int pkt_len;
int num;
int mss;
int new_thread;
int stop_thread;
int wait_all_finish;
u32 vlan_tag;
u16 pause_time;
u16 eth_type;
u16 pause_code;
u8 priority;
u8 dscp;
u8 dst_mac[ETH_ALEN];
u8 dst_ip[IP_ADDR_LEN];
int multi_queue;
int pkt_payload_flag;
u16 pkt_checksum;
u32 pkt_checksum_sctp;
u16 pkt_inet6_addr[IP6_ADDR_LEN];
};
struct hns3_cae_pkt_result_info {
int total_len;
int num;
};
int hns3_cae_send_pkt(const struct hns3_nic_priv *net_priv, void *buf_in,
u32 in_size, void *buf_out, u32 out_size);
void hns3_cae_pkt_init(void);
void hns3_cae_pkt_destroy(void);
#endif
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#define BD_NUM_6 6 #define BD_NUM_6 6
#define BD_NUM_7 7 #define BD_NUM_7 7
void fill_port_info(struct hclge_port_info *get_port_info_out, static void fill_port_info(struct hclge_port_info *get_port_info_out,
struct hclge_desc *port_desc, u32 bd_num) struct hclge_desc *port_desc, u32 bd_num)
{ {
u8 *dest_data = NULL; u8 *dest_data = NULL;
u8 *tmp_buff = NULL; u8 *tmp_buff = NULL;
......
...@@ -45,6 +45,7 @@ int hns3_set_promisc_mode_cfg(const struct hns3_nic_priv *nic_dev, ...@@ -45,6 +45,7 @@ int hns3_set_promisc_mode_cfg(const struct hns3_nic_priv *nic_dev,
void *buf_in, u32 in_size, void *buf_in, u32 in_size,
void *buf_out, u32 out_size) void *buf_out, u32 out_size)
{ {
#define PROMISC_EN_MAX_VAL 0x1
bool check = !buf_in || in_size < sizeof(struct promisc_mode_param); bool check = !buf_in || in_size < sizeof(struct promisc_mode_param);
struct promisc_mode_param *mode_param = NULL; struct promisc_mode_param *mode_param = NULL;
struct hclge_promisc_cfg_cmd *req = NULL; struct hclge_promisc_cfg_cmd *req = NULL;
...@@ -76,16 +77,22 @@ int hns3_set_promisc_mode_cfg(const struct hns3_nic_priv *nic_dev, ...@@ -76,16 +77,22 @@ int hns3_set_promisc_mode_cfg(const struct hns3_nic_priv *nic_dev,
switch (mode_param->type) { switch (mode_param->type) {
case HNS3_UNICAST: case HNS3_UNICAST:
req->flag &= ~BIT(HNS3_CAE_UC_PROMISC_EN_B); req->flag &= ~BIT(HNS3_CAE_UC_PROMISC_EN_B);
if (mode_param->uc > PROMISC_EN_MAX_VAL)
return -EINVAL;
req->flag |= (mode_param->uc << HNS3_CAE_UC_PROMISC_EN_B) | req->flag |= (mode_param->uc << HNS3_CAE_UC_PROMISC_EN_B) |
HCLGE_PROMISC_TX_EN_B | HCLGE_PROMISC_RX_EN_B; HCLGE_PROMISC_TX_EN_B | HCLGE_PROMISC_RX_EN_B;
break; break;
case HNS3_MULTICAST: case HNS3_MULTICAST:
req->flag &= ~BIT(HNS3_CAE_MC_PROMISC_EN_B); req->flag &= ~BIT(HNS3_CAE_MC_PROMISC_EN_B);
if (mode_param->mc > PROMISC_EN_MAX_VAL)
return -EINVAL;
req->flag |= (mode_param->mc << HNS3_CAE_MC_PROMISC_EN_B) | req->flag |= (mode_param->mc << HNS3_CAE_MC_PROMISC_EN_B) |
HCLGE_PROMISC_TX_EN_B | HCLGE_PROMISC_RX_EN_B; HCLGE_PROMISC_TX_EN_B | HCLGE_PROMISC_RX_EN_B;
break; break;
case HNS3_BROADCAST: case HNS3_BROADCAST:
req->flag &= ~BIT(HNS3_CAE_BC_PROMISC_EN_B); req->flag &= ~BIT(HNS3_CAE_BC_PROMISC_EN_B);
if (mode_param->bc > PROMISC_EN_MAX_VAL)
return -EINVAL;
req->flag |= (mode_param->bc << HNS3_CAE_BC_PROMISC_EN_B) | req->flag |= (mode_param->bc << HNS3_CAE_BC_PROMISC_EN_B) |
HCLGE_PROMISC_TX_EN_B | HCLGE_PROMISC_RX_EN_B; HCLGE_PROMISC_TX_EN_B | HCLGE_PROMISC_RX_EN_B;
break; break;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "hns3_cae_qinfo.h" #include "hns3_cae_qinfo.h"
int hns3_get_q_rx_fbd(const struct hns3_nic_priv *net_priv, int ring_id) static int hns3_get_q_rx_fbd(const struct hns3_nic_priv *net_priv, int ring_id)
{ {
struct hns3_enet_ring *ring = NULL; struct hns3_enet_ring *ring = NULL;
int num; int num;
...@@ -16,7 +16,7 @@ int hns3_get_q_rx_fbd(const struct hns3_nic_priv *net_priv, int ring_id) ...@@ -16,7 +16,7 @@ int hns3_get_q_rx_fbd(const struct hns3_nic_priv *net_priv, int ring_id)
return num; return num;
} }
int hns3_get_q_rx_ebd(const struct hns3_nic_priv *net_priv, int ring_id) static int hns3_get_q_rx_ebd(const struct hns3_nic_priv *net_priv, int ring_id)
{ {
struct hns3_enet_ring *ring = NULL; struct hns3_enet_ring *ring = NULL;
int num; int num;
...@@ -29,7 +29,7 @@ int hns3_get_q_rx_ebd(const struct hns3_nic_priv *net_priv, int ring_id) ...@@ -29,7 +29,7 @@ int hns3_get_q_rx_ebd(const struct hns3_nic_priv *net_priv, int ring_id)
return num; return num;
} }
int hns3_get_q_tx_fbd(const struct hns3_nic_priv *net_priv, int ring_id) static int hns3_get_q_tx_fbd(const struct hns3_nic_priv *net_priv, int ring_id)
{ {
struct hns3_enet_ring *ring = NULL; struct hns3_enet_ring *ring = NULL;
int num; int num;
...@@ -40,7 +40,7 @@ int hns3_get_q_tx_fbd(const struct hns3_nic_priv *net_priv, int ring_id) ...@@ -40,7 +40,7 @@ int hns3_get_q_tx_fbd(const struct hns3_nic_priv *net_priv, int ring_id)
return num; return num;
} }
int hns3_get_q_tx_ebd(const struct hns3_nic_priv *net_priv, int ring_id) static int hns3_get_q_tx_ebd(const struct hns3_nic_priv *net_priv, int ring_id)
{ {
struct hns3_enet_ring *ring = NULL; struct hns3_enet_ring *ring = NULL;
int num; int num;
...@@ -51,7 +51,7 @@ int hns3_get_q_tx_ebd(const struct hns3_nic_priv *net_priv, int ring_id) ...@@ -51,7 +51,7 @@ int hns3_get_q_tx_ebd(const struct hns3_nic_priv *net_priv, int ring_id)
return num; return num;
} }
int hns3_get_q_rx_tail(const struct hns3_nic_priv *net_priv, int ring_id) static int hns3_get_q_rx_tail(const struct hns3_nic_priv *net_priv, int ring_id)
{ {
struct hns3_enet_ring *ring = NULL; struct hns3_enet_ring *ring = NULL;
int num; int num;
...@@ -64,7 +64,7 @@ int hns3_get_q_rx_tail(const struct hns3_nic_priv *net_priv, int ring_id) ...@@ -64,7 +64,7 @@ int hns3_get_q_rx_tail(const struct hns3_nic_priv *net_priv, int ring_id)
return num; return num;
} }
int hns3_get_q_rx_head(const struct hns3_nic_priv *net_priv, int ring_id) static int hns3_get_q_rx_head(const struct hns3_nic_priv *net_priv, int ring_id)
{ {
struct hns3_enet_ring *ring = NULL; struct hns3_enet_ring *ring = NULL;
int num; int num;
...@@ -77,7 +77,7 @@ int hns3_get_q_rx_head(const struct hns3_nic_priv *net_priv, int ring_id) ...@@ -77,7 +77,7 @@ int hns3_get_q_rx_head(const struct hns3_nic_priv *net_priv, int ring_id)
return num; return num;
} }
int hns3_get_q_tx_tail(const struct hns3_nic_priv *net_priv, int ring_id) static int hns3_get_q_tx_tail(const struct hns3_nic_priv *net_priv, int ring_id)
{ {
struct hns3_enet_ring *ring = NULL; struct hns3_enet_ring *ring = NULL;
int num; int num;
...@@ -88,7 +88,7 @@ int hns3_get_q_tx_tail(const struct hns3_nic_priv *net_priv, int ring_id) ...@@ -88,7 +88,7 @@ int hns3_get_q_tx_tail(const struct hns3_nic_priv *net_priv, int ring_id)
return num; return num;
} }
int hns3_get_q_tx_head(const struct hns3_nic_priv *net_priv, int ring_id) static int hns3_get_q_tx_head(const struct hns3_nic_priv *net_priv, int ring_id)
{ {
struct hns3_enet_ring *ring = NULL; struct hns3_enet_ring *ring = NULL;
int num; int num;
...@@ -146,5 +146,6 @@ int hns3_cae_qinfo_cfg(const struct hns3_nic_priv *net_priv, ...@@ -146,5 +146,6 @@ int hns3_cae_qinfo_cfg(const struct hns3_nic_priv *net_priv,
out_info->tx_tail = tx_tail; out_info->tx_tail = tx_tail;
out_info->tx_ebd = tx_ebd; out_info->tx_ebd = tx_ebd;
out_info->tx_fbd = tx_fbd; out_info->tx_fbd = tx_fbd;
return 0; return 0;
} }
...@@ -25,14 +25,6 @@ struct qinfo_param { ...@@ -25,14 +25,6 @@ struct qinfo_param {
int rx_fbd; int rx_fbd;
}; };
int hns3_get_q_rx_fbd(const struct hns3_nic_priv *net_priv, int ring_id);
int hns3_get_q_rx_ebd(const struct hns3_nic_priv *net_priv, int ring_id);
int hns3_get_q_tx_fbd(const struct hns3_nic_priv *net_priv, int ring_id);
int hns3_get_q_tx_ebd(const struct hns3_nic_priv *net_priv, int ring_id);
int hns3_get_q_rx_tail(const struct hns3_nic_priv *net_priv, int ring_id);
int hns3_get_q_rx_head(const struct hns3_nic_priv *net_priv, int ring_id);
int hns3_get_q_tx_tail(const struct hns3_nic_priv *net_priv, int ring_id);
int hns3_get_q_tx_head(const struct hns3_nic_priv *net_priv, int ring_id);
int hns3_cae_qinfo_cfg(const struct hns3_nic_priv *net_priv, int hns3_cae_qinfo_cfg(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size, void *buf_in, u32 in_size,
void *buf_out, u32 out_size); void *buf_out, u32 out_size);
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
#include "hns3_cae_qres.h" #include "hns3_cae_qres.h"
int hns3_get_qres_rx_value(const struct hns3_nic_priv *net_priv, int ring_id, static int hns3_get_qres_rx_value(const struct hns3_nic_priv *net_priv,
enum param_type type) int ring_id, enum param_type type)
{ {
struct hns3_enet_ring *ring = NULL; struct hns3_enet_ring *ring = NULL;
int tqps_num; int tqps_num;
...@@ -51,8 +51,8 @@ int hns3_get_qres_rx_value(const struct hns3_nic_priv *net_priv, int ring_id, ...@@ -51,8 +51,8 @@ int hns3_get_qres_rx_value(const struct hns3_nic_priv *net_priv, int ring_id,
return num; return num;
} }
int hns3_get_qres_tx_value(const struct hns3_nic_priv *net_priv, int ring_id, static int hns3_get_qres_tx_value(const struct hns3_nic_priv *net_priv,
enum param_type type) int ring_id, enum param_type type)
{ {
struct hns3_enet_ring *ring = NULL; struct hns3_enet_ring *ring = NULL;
int num; int num;
...@@ -97,8 +97,8 @@ int hns3_get_qres_tx_value(const struct hns3_nic_priv *net_priv, int ring_id, ...@@ -97,8 +97,8 @@ int hns3_get_qres_tx_value(const struct hns3_nic_priv *net_priv, int ring_id,
return num; return num;
} }
void fill_queue_info(const struct hns3_nic_priv *net_priv, static void fill_queue_info(const struct hns3_nic_priv *net_priv,
struct qres_param *out_info, int ring_id) struct qres_param *out_info, int ring_id)
{ {
/* rx info */ /* rx info */
out_info->qid = ring_id; out_info->qid = ring_id;
......
...@@ -64,8 +64,7 @@ int hns3_cae_nic_timeout_cfg(const struct hns3_nic_priv *net_priv, ...@@ -64,8 +64,7 @@ int hns3_cae_nic_timeout_cfg(const struct hns3_nic_priv *net_priv,
void *buf_in, u32 in_size, void *buf_in, u32 in_size,
void *buf_out, u32 out_size) void *buf_out, u32 out_size)
{ {
struct tx_timeout_param *out_info = struct tx_timeout_param *out_info = (struct tx_timeout_param *)buf_out;
(struct tx_timeout_param *)buf_out;
struct tx_timeout_param *in_info = (struct tx_timeout_param *)buf_in; struct tx_timeout_param *in_info = (struct tx_timeout_param *)buf_in;
bool check = !buf_in || in_size < sizeof(struct tx_timeout_param); bool check = !buf_in || in_size < sizeof(struct tx_timeout_param);
struct net_device *netdev = net_priv->netdev; struct net_device *netdev = net_priv->netdev;
......
...@@ -20,8 +20,9 @@ static int hns3_cae_tm_schd_mode_set(struct hclge_dev *hdev, ...@@ -20,8 +20,9 @@ static int hns3_cae_tm_schd_mode_set(struct hclge_dev *hdev,
{ {
struct hclge_desc desc; struct hclge_desc desc;
if (mode > HCLGE_SCH_MODE_DWRR)
return -EINVAL;
hns3_cae_cmd_setup_basic_desc(&desc, opcode, false); hns3_cae_cmd_setup_basic_desc(&desc, opcode, false);
if (mode == HCLGE_SCH_MODE_DWRR) if (mode == HCLGE_SCH_MODE_DWRR)
desc.data[1] = 1; desc.data[1] = 1;
else else
...@@ -48,7 +49,7 @@ static int hns3_cae_tm_schd_mode_get(struct hclge_dev *hdev, ...@@ -48,7 +49,7 @@ static int hns3_cae_tm_schd_mode_get(struct hclge_dev *hdev,
return ret; return ret;
} }
int hns3_cae_tm_q_to_qs_set(struct hclge_dev *hdev, u16 q_id, u16 qs_id) static int hns3_cae_tm_q_to_qs_set(struct hclge_dev *hdev, u16 q_id, u16 qs_id)
{ {
struct hclge_nq_to_qs_link_cmd *map = NULL; struct hclge_nq_to_qs_link_cmd *map = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -61,7 +62,7 @@ int hns3_cae_tm_q_to_qs_set(struct hclge_dev *hdev, u16 q_id, u16 qs_id) ...@@ -61,7 +62,7 @@ int hns3_cae_tm_q_to_qs_set(struct hclge_dev *hdev, u16 q_id, u16 qs_id)
return hns3_cae_cmd_send(hdev, &desc, 1); return hns3_cae_cmd_send(hdev, &desc, 1);
} }
int hns3_cae_tm_q_to_qs_get(struct hclge_dev *hdev, u16 q_id, u16 *qs_id) static int hns3_cae_tm_q_to_qs_get(struct hclge_dev *hdev, u16 q_id, u16 *qs_id)
{ {
struct hclge_nq_to_qs_link_cmd *map = NULL; struct hclge_nq_to_qs_link_cmd *map = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -78,7 +79,7 @@ int hns3_cae_tm_q_to_qs_get(struct hclge_dev *hdev, u16 q_id, u16 *qs_id) ...@@ -78,7 +79,7 @@ int hns3_cae_tm_q_to_qs_get(struct hclge_dev *hdev, u16 q_id, u16 *qs_id)
return ret; return ret;
} }
int hns3_cae_tm_qs_to_pri_set(struct hclge_dev *hdev, u16 qs_id, u8 pri) static int hns3_cae_tm_qs_to_pri_set(struct hclge_dev *hdev, u16 qs_id, u8 pri)
{ {
struct hclge_qs_to_pri_link_cmd *map = NULL; struct hclge_qs_to_pri_link_cmd *map = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -93,7 +94,7 @@ int hns3_cae_tm_qs_to_pri_set(struct hclge_dev *hdev, u16 qs_id, u8 pri) ...@@ -93,7 +94,7 @@ int hns3_cae_tm_qs_to_pri_set(struct hclge_dev *hdev, u16 qs_id, u8 pri)
return hns3_cae_cmd_send(hdev, &desc, 1); return hns3_cae_cmd_send(hdev, &desc, 1);
} }
int hns3_cae_tm_qs_to_pri_get(struct hclge_dev *hdev, u16 qs_id, u8 *pri) static int hns3_cae_tm_qs_to_pri_get(struct hclge_dev *hdev, u16 qs_id, u8 *pri)
{ {
struct hclge_qs_to_pri_link_cmd *map = NULL; struct hclge_qs_to_pri_link_cmd *map = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -109,7 +110,7 @@ int hns3_cae_tm_qs_to_pri_get(struct hclge_dev *hdev, u16 qs_id, u8 *pri) ...@@ -109,7 +110,7 @@ int hns3_cae_tm_qs_to_pri_get(struct hclge_dev *hdev, u16 qs_id, u8 *pri)
return ret; return ret;
} }
int hns3_cae_tm_qs_weight_set(struct hclge_dev *hdev, u16 qs_id, u8 dwrr) static int hns3_cae_tm_qs_weight_set(struct hclge_dev *hdev, u16 qs_id, u8 dwrr)
{ {
struct hclge_qs_weight_cmd *weight = NULL; struct hclge_qs_weight_cmd *weight = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -122,7 +123,8 @@ int hns3_cae_tm_qs_weight_set(struct hclge_dev *hdev, u16 qs_id, u8 dwrr) ...@@ -122,7 +123,8 @@ int hns3_cae_tm_qs_weight_set(struct hclge_dev *hdev, u16 qs_id, u8 dwrr)
return hns3_cae_cmd_send(hdev, &desc, 1); return hns3_cae_cmd_send(hdev, &desc, 1);
} }
int hns3_cae_tm_qs_weight_get(struct hclge_dev *hdev, u16 qs_id, u8 *dwrr) static int hns3_cae_tm_qs_weight_get(struct hclge_dev *hdev,
u16 qs_id, u8 *dwrr)
{ {
struct hclge_qs_weight_cmd *weight = NULL; struct hclge_qs_weight_cmd *weight = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -138,7 +140,8 @@ int hns3_cae_tm_qs_weight_get(struct hclge_dev *hdev, u16 qs_id, u8 *dwrr) ...@@ -138,7 +140,8 @@ int hns3_cae_tm_qs_weight_get(struct hclge_dev *hdev, u16 qs_id, u8 *dwrr)
return ret; return ret;
} }
int hns3_cae_tm_pri_weight_set(struct hclge_dev *hdev, u8 pri_id, u8 dwrr) static int hns3_cae_tm_pri_weight_set(struct hclge_dev *hdev,
u8 pri_id, u8 dwrr)
{ {
struct hclge_priority_weight_cmd *weight = NULL; struct hclge_priority_weight_cmd *weight = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -151,7 +154,8 @@ int hns3_cae_tm_pri_weight_set(struct hclge_dev *hdev, u8 pri_id, u8 dwrr) ...@@ -151,7 +154,8 @@ int hns3_cae_tm_pri_weight_set(struct hclge_dev *hdev, u8 pri_id, u8 dwrr)
return hns3_cae_cmd_send(hdev, &desc, 1); return hns3_cae_cmd_send(hdev, &desc, 1);
} }
int hns3_cae_tm_pri_weight_get(struct hclge_dev *hdev, u8 pri_id, u8 *dwrr) static int hns3_cae_tm_pri_weight_get(struct hclge_dev *hdev,
u8 pri_id, u8 *dwrr)
{ {
struct hclge_priority_weight_cmd *weight = NULL; struct hclge_priority_weight_cmd *weight = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -167,7 +171,8 @@ int hns3_cae_tm_pri_weight_get(struct hclge_dev *hdev, u8 pri_id, u8 *dwrr) ...@@ -167,7 +171,8 @@ int hns3_cae_tm_pri_weight_get(struct hclge_dev *hdev, u8 pri_id, u8 *dwrr)
return ret; return ret;
} }
int hns3_cae_tm_pri_pg_bitmap_set(struct hclge_dev *hdev, u8 pg_id, u8 bitmap) static int hns3_cae_tm_pri_pg_bitmap_set(struct hclge_dev *hdev,
u8 pg_id, u8 bitmap)
{ {
struct hclge_pg_to_pri_link_cmd *map = NULL; struct hclge_pg_to_pri_link_cmd *map = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -181,8 +186,8 @@ int hns3_cae_tm_pri_pg_bitmap_set(struct hclge_dev *hdev, u8 pg_id, u8 bitmap) ...@@ -181,8 +186,8 @@ int hns3_cae_tm_pri_pg_bitmap_set(struct hclge_dev *hdev, u8 pg_id, u8 bitmap)
return hns3_cae_cmd_send(hdev, &desc, 1); return hns3_cae_cmd_send(hdev, &desc, 1);
} }
int hns3_cae_tm_pri_pg_bitmap_get(struct hclge_dev *hdev, u8 pg_id, static int hns3_cae_tm_pri_pg_bitmap_get(struct hclge_dev *hdev, u8 pg_id,
u8 *bitmap) u8 *bitmap)
{ {
struct hclge_pg_to_pri_link_cmd *map = NULL; struct hclge_pg_to_pri_link_cmd *map = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -200,8 +205,8 @@ int hns3_cae_tm_pri_pg_bitmap_get(struct hclge_dev *hdev, u8 pg_id, ...@@ -200,8 +205,8 @@ int hns3_cae_tm_pri_pg_bitmap_get(struct hclge_dev *hdev, u8 pg_id,
return 0; return 0;
} }
int hns3_cae_tm_qs_bp_bitmap_set(struct hclge_dev *hdev, u8 tc, u8 gp_id, static int hns3_cae_tm_qs_bp_bitmap_set(struct hclge_dev *hdev, u8 tc, u8 gp_id,
u32 map) u32 map)
{ {
struct hclge_bp_to_qs_map_cmd *bp_to_qs_map_cmd = NULL; struct hclge_bp_to_qs_map_cmd *bp_to_qs_map_cmd = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -217,8 +222,8 @@ int hns3_cae_tm_qs_bp_bitmap_set(struct hclge_dev *hdev, u8 tc, u8 gp_id, ...@@ -217,8 +222,8 @@ int hns3_cae_tm_qs_bp_bitmap_set(struct hclge_dev *hdev, u8 tc, u8 gp_id,
return hns3_cae_cmd_send(hdev, &desc, 1); return hns3_cae_cmd_send(hdev, &desc, 1);
} }
int hns3_cae_tm_qs_bp_bitmap_get(struct hclge_dev *hdev, u8 tc, u8 gp_id, static int hns3_cae_tm_qs_bp_bitmap_get(struct hclge_dev *hdev, u8 tc, u8 gp_id,
u32 *map) u32 *map)
{ {
struct hclge_bp_to_qs_map_cmd *bp_to_qs_map_cmd = NULL; struct hclge_bp_to_qs_map_cmd *bp_to_qs_map_cmd = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -237,9 +242,9 @@ int hns3_cae_tm_qs_bp_bitmap_get(struct hclge_dev *hdev, u8 tc, u8 gp_id, ...@@ -237,9 +242,9 @@ int hns3_cae_tm_qs_bp_bitmap_get(struct hclge_dev *hdev, u8 tc, u8 gp_id,
return 0; return 0;
} }
int hns3_cae_tm_pri_shapping_set(struct hclge_dev *hdev, static int hns3_cae_tm_pri_shapping_set(struct hclge_dev *hdev,
enum hclge_shap_bucket bucket, u8 pri_id, enum hclge_shap_bucket bucket,
u32 shaper) u8 pri_id, u32 shaper)
{ {
struct hclge_pri_shapping_cmd *shap_cfg_cmd = NULL; struct hclge_pri_shapping_cmd *shap_cfg_cmd = NULL;
enum hclge_opcode_type opcode; enum hclge_opcode_type opcode;
...@@ -255,9 +260,9 @@ int hns3_cae_tm_pri_shapping_set(struct hclge_dev *hdev, ...@@ -255,9 +260,9 @@ int hns3_cae_tm_pri_shapping_set(struct hclge_dev *hdev,
return hns3_cae_cmd_send(hdev, &desc, 1); return hns3_cae_cmd_send(hdev, &desc, 1);
} }
int hns3_cae_tm_pri_shapping_get(struct hclge_dev *hdev, static int hns3_cae_tm_pri_shapping_get(struct hclge_dev *hdev,
enum hclge_shap_bucket bucket, u8 pri_id, enum hclge_shap_bucket bucket,
u32 *shaper) u8 pri_id, u32 *shaper)
{ {
struct hclge_pri_shapping_cmd *shap_cfg_cmd = NULL; struct hclge_pri_shapping_cmd *shap_cfg_cmd = NULL;
enum hclge_opcode_type opcode; enum hclge_opcode_type opcode;
...@@ -275,7 +280,7 @@ int hns3_cae_tm_pri_shapping_get(struct hclge_dev *hdev, ...@@ -275,7 +280,7 @@ int hns3_cae_tm_pri_shapping_get(struct hclge_dev *hdev,
return ret; return ret;
} }
int hns3_cae_tm_pg_weight_set(struct hclge_dev *hdev, u8 pg_id, u8 dwrr) static int hns3_cae_tm_pg_weight_set(struct hclge_dev *hdev, u8 pg_id, u8 dwrr)
{ {
struct hclge_pg_weight_cmd *weight = NULL; struct hclge_pg_weight_cmd *weight = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -288,7 +293,7 @@ int hns3_cae_tm_pg_weight_set(struct hclge_dev *hdev, u8 pg_id, u8 dwrr) ...@@ -288,7 +293,7 @@ int hns3_cae_tm_pg_weight_set(struct hclge_dev *hdev, u8 pg_id, u8 dwrr)
return hns3_cae_cmd_send(hdev, &desc, 1); return hns3_cae_cmd_send(hdev, &desc, 1);
} }
int hns3_cae_tm_pg_weight_get(struct hclge_dev *hdev, u8 pg_id, u8 *dwrr) static int hns3_cae_tm_pg_weight_get(struct hclge_dev *hdev, u8 pg_id, u8 *dwrr)
{ {
struct hclge_pg_weight_cmd *weight = NULL; struct hclge_pg_weight_cmd *weight = NULL;
struct hclge_desc desc; struct hclge_desc desc;
...@@ -304,9 +309,9 @@ int hns3_cae_tm_pg_weight_get(struct hclge_dev *hdev, u8 pg_id, u8 *dwrr) ...@@ -304,9 +309,9 @@ int hns3_cae_tm_pg_weight_get(struct hclge_dev *hdev, u8 pg_id, u8 *dwrr)
return ret; return ret;
} }
int hns3_cae_tm_pg_shapping_set(struct hclge_dev *hdev, static int hns3_cae_tm_pg_shapping_set(struct hclge_dev *hdev,
enum hclge_shap_bucket bucket, u8 pg_id, enum hclge_shap_bucket bucket,
u32 shaper) u8 pg_id, u32 shaper)
{ {
struct hclge_pg_shapping_cmd *shap_cfg_cmd = NULL; struct hclge_pg_shapping_cmd *shap_cfg_cmd = NULL;
enum hclge_opcode_type opcode; enum hclge_opcode_type opcode;
...@@ -322,9 +327,9 @@ int hns3_cae_tm_pg_shapping_set(struct hclge_dev *hdev, ...@@ -322,9 +327,9 @@ int hns3_cae_tm_pg_shapping_set(struct hclge_dev *hdev,
return hns3_cae_cmd_send(hdev, &desc, 1); return hns3_cae_cmd_send(hdev, &desc, 1);
} }
int hns3_cae_tm_pg_shapping_get(struct hclge_dev *hdev, static int hns3_cae_tm_pg_shapping_get(struct hclge_dev *hdev,
enum hclge_shap_bucket bucket, u8 pg_id, enum hclge_shap_bucket bucket,
u32 *shaper) u8 pg_id, u32 *shaper)
{ {
struct hclge_pg_shapping_cmd *shap_cfg_cmd = NULL; struct hclge_pg_shapping_cmd *shap_cfg_cmd = NULL;
enum hclge_opcode_type opcode; enum hclge_opcode_type opcode;
...@@ -343,7 +348,7 @@ int hns3_cae_tm_pg_shapping_get(struct hclge_dev *hdev, ...@@ -343,7 +348,7 @@ int hns3_cae_tm_pg_shapping_get(struct hclge_dev *hdev,
return ret; return ret;
} }
int hns3_cae_tm_port_shapping_set(struct hclge_dev *hdev, u32 shaper) static int hns3_cae_tm_port_shapping_set(struct hclge_dev *hdev, u32 shaper)
{ {
struct hclge_port_shapping_cmd *shap_cfg_cmd = NULL; struct hclge_port_shapping_cmd *shap_cfg_cmd = NULL;
enum hclge_opcode_type opcode; enum hclge_opcode_type opcode;
...@@ -357,7 +362,7 @@ int hns3_cae_tm_port_shapping_set(struct hclge_dev *hdev, u32 shaper) ...@@ -357,7 +362,7 @@ int hns3_cae_tm_port_shapping_set(struct hclge_dev *hdev, u32 shaper)
return hns3_cae_cmd_send(hdev, &desc, 1); return hns3_cae_cmd_send(hdev, &desc, 1);
} }
int hns3_cae_tm_port_shapping_get(struct hclge_dev *hdev, u32 *shaper) static int hns3_cae_tm_port_shapping_get(struct hclge_dev *hdev, u32 *shaper)
{ {
struct hclge_port_shapping_cmd *shap_cfg_cmd = NULL; struct hclge_port_shapping_cmd *shap_cfg_cmd = NULL;
enum hclge_opcode_type opcode; enum hclge_opcode_type opcode;
...@@ -474,8 +479,9 @@ int hns3_cae_queue_cfg(const struct hns3_nic_priv *net_priv, ...@@ -474,8 +479,9 @@ int hns3_cae_queue_cfg(const struct hns3_nic_priv *net_priv,
return -EFAULT; return -EFAULT;
} }
if (in_info->queue_id >= MAX_QUEUE_ID)
return -EINVAL;
is_read = in_info->is_read; is_read = in_info->is_read;
if (is_read) { if (is_read) {
check = !buf_out || check = !buf_out ||
out_size < sizeof(struct hns3_cae_queue_cfg_info); out_size < sizeof(struct hns3_cae_queue_cfg_info);
...@@ -492,6 +498,8 @@ int hns3_cae_queue_cfg(const struct hns3_nic_priv *net_priv, ...@@ -492,6 +498,8 @@ int hns3_cae_queue_cfg(const struct hns3_nic_priv *net_priv,
return -1; return -1;
} }
} else { } else {
if (in_info->qs >= MAX_QSET_ID)
return -EINVAL;
if (hns3_cae_tm_q_to_qs_set(hdev, in_info->queue_id, if (hns3_cae_tm_q_to_qs_set(hdev, in_info->queue_id,
in_info->qs)) { in_info->qs)) {
pr_err("%s,%d:set queue(%d) to qs(%d) failed!\n", pr_err("%s,%d:set queue(%d) to qs(%d) failed!\n",
...@@ -571,6 +579,8 @@ int hns3_cae_qs_cfg(const struct hns3_nic_priv *net_priv, ...@@ -571,6 +579,8 @@ int hns3_cae_qs_cfg(const struct hns3_nic_priv *net_priv,
is_read = in_info->is_read; is_read = in_info->is_read;
qs_id = in_info->qs_id; qs_id = in_info->qs_id;
if (qs_id >= MAX_QSET_ID)
return -EINVAL;
gp_id = qs_id / 32; gp_id = qs_id / 32;
offset = qs_id % 32; offset = qs_id % 32;
...@@ -618,7 +628,6 @@ int hns3_cae_qs_cfg(const struct hns3_nic_priv *net_priv, ...@@ -618,7 +628,6 @@ int hns3_cae_qs_cfg(const struct hns3_nic_priv *net_priv,
__func__, __LINE__, qs_id, ret); __func__, __LINE__, qs_id, ret);
return -1; return -1;
} }
} else { } else {
if ((in_info->flag & HNS3_TM_QSET_MAPPING_FLAG) && if ((in_info->flag & HNS3_TM_QSET_MAPPING_FLAG) &&
hns3_cae_tm_qs_to_pri_set(hdev, qs_id, in_info->pri)) { hns3_cae_tm_qs_to_pri_set(hdev, qs_id, in_info->pri)) {
...@@ -661,6 +670,10 @@ static int hns3_cae_pri_pg_set_map(struct hclge_dev *hdev, ...@@ -661,6 +670,10 @@ static int hns3_cae_pri_pg_set_map(struct hclge_dev *hdev,
u8 bitmap = map; u8 bitmap = map;
u16 pri_id = in_info->pri_id; u16 pri_id = in_info->pri_id;
if (pri_id >= MAX_TC_NUM)
return -EINVAL;
if (in_info->pg >= MAX_PG_NUM)
return -EINVAL;
/* clear old map */ /* clear old map */
if (in_info->pg != cur_pg) { if (in_info->pg != cur_pg) {
bitmap &= ~BIT(pri_id); bitmap &= ~BIT(pri_id);
...@@ -712,8 +725,9 @@ int hns3_cae_pri_cfg(const struct hns3_nic_priv *net_priv, ...@@ -712,8 +725,9 @@ int hns3_cae_pri_cfg(const struct hns3_nic_priv *net_priv,
} }
is_read = in_info->is_read; is_read = in_info->is_read;
pri_id = in_info->pri_id; pri_id = in_info->pri_id;
if (pri_id >= MAX_TC_NUM)
return -EINVAL;
for (cur_pg = 0; cur_pg < MAX_PG_NUM; cur_pg++) { for (cur_pg = 0; cur_pg < MAX_PG_NUM; cur_pg++) {
bitmap = 0; bitmap = 0;
...@@ -838,6 +852,8 @@ int hns3_cae_pg_cfg(const struct hns3_nic_priv *net_priv, void *buf_in, ...@@ -838,6 +852,8 @@ int hns3_cae_pg_cfg(const struct hns3_nic_priv *net_priv, void *buf_in,
is_read = in_info->is_read; is_read = in_info->is_read;
pg_id = in_info->pg_id; pg_id = in_info->pg_id;
if (pg_id >= MAX_PG_NUM)
return -EINVAL;
if (is_read) { if (is_read) {
check = !buf_out || check = !buf_out ||
...@@ -969,6 +985,7 @@ int hns3_cae_ets_cfg(const struct hns3_nic_priv *net_priv, ...@@ -969,6 +985,7 @@ int hns3_cae_ets_cfg(const struct hns3_nic_priv *net_priv,
u32 out_size) u32 out_size)
{ {
#define HNS3_TM_ETS_PORT_SHAPING 0x10820850 #define HNS3_TM_ETS_PORT_SHAPING 0x10820850
#define HNS3_TM_MAC_ID_MASK 0x7
struct hns3_cae_ets_cfg_info *out_info = struct hns3_cae_ets_cfg_info *out_info =
(struct hns3_cae_ets_cfg_info *)buf_out; (struct hns3_cae_ets_cfg_info *)buf_out;
struct hns3_cae_ets_cfg_info *in_info = struct hns3_cae_ets_cfg_info *in_info =
...@@ -993,7 +1010,16 @@ int hns3_cae_ets_cfg(const struct hns3_nic_priv *net_priv, ...@@ -993,7 +1010,16 @@ int hns3_cae_ets_cfg(const struct hns3_nic_priv *net_priv,
is_read = in_info->is_read; is_read = in_info->is_read;
tc_id = in_info->tc_id; tc_id = in_info->tc_id;
mac_id = in_info->mac_id; if (tc_id >= MAX_TC_NUM) {
pr_err("tc id(%d) is invalid in %s function\n", tc_id, __func__);
return -EFAULT;
}
mac_id = in_info->mac_id & HNS3_TM_MAC_ID_MASK;
if (mac_id & 0x1) {
pr_err("mac id(%d) is invalid in %s function\n", mac_id, __func__);
return -EFAULT;
}
addr = (u64)HNS3_TM_ETS_PORT_SHAPING + ((u64)mac_id << 20); addr = (u64)HNS3_TM_ETS_PORT_SHAPING + ((u64)mac_id << 20);
out_info->tc_id = tc_id; out_info->tc_id = tc_id;
out_info->mac_id = mac_id; out_info->mac_id = mac_id;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#define MAX_QUEUE_NUM 16 #define MAX_QUEUE_NUM 16
#define MAX_PG_NUM 4 #define MAX_PG_NUM 4
#define MAX_TC_NUM 8 #define MAX_TC_NUM 8
#define MAX_QUEUE_ID 1024
#define MAX_QSET_ID 1024
#define HNS3_CAE_QS_ID_MSK (BIT(10) - 1) #define HNS3_CAE_QS_ID_MSK (BIT(10) - 1)
#define HCLGE_OPC_TM_PORT_SCH_MODE_CFG 0x0811 #define HCLGE_OPC_TM_PORT_SCH_MODE_CFG 0x0811
......
...@@ -52,7 +52,6 @@ int hns3_cae_get_fw_ver(const struct hns3_nic_priv *nic_dev, void *buf_in, ...@@ -52,7 +52,6 @@ int hns3_cae_get_fw_ver(const struct hns3_nic_priv *nic_dev, void *buf_in,
struct hclge_vport *vport = struct hclge_vport *vport =
container_of(handle, struct hclge_vport, nic); container_of(handle, struct hclge_vport, nic);
struct hclge_dev *hdev = vport->back; struct hclge_dev *hdev = vport->back;
u32 fw_ver; u32 fw_ver;
if (check) { if (check) {
...@@ -65,10 +64,9 @@ int hns3_cae_get_fw_ver(const struct hns3_nic_priv *nic_dev, void *buf_in, ...@@ -65,10 +64,9 @@ int hns3_cae_get_fw_ver(const struct hns3_nic_priv *nic_dev, void *buf_in,
return -EFAULT; return -EFAULT;
fw_ver = hdev->fw_version; fw_ver = hdev->fw_version;
out_buf->imp_ver = fw_ver;
if (!fw_ver) if (!fw_ver)
return -EFAULT; return -EFAULT;
out_buf->imp_ver = fw_ver;
return 0; return 0;
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#ifndef __HNS3_CAE_VERSION_H__ #ifndef __HNS3_CAE_VERSION_H__
#define __HNS3_CAE_VERSION_H__ #define __HNS3_CAE_VERSION_H__
#define HNS3_CAE_MOD_VERSION "1.9.35.1" #define HNS3_CAE_MOD_VERSION "1.9.36.0"
#define CMT_ID_LEN 8 #define CMT_ID_LEN 8
#define RESV_LEN 3 #define RESV_LEN 3
......
...@@ -124,7 +124,7 @@ static int hns3_get_sfpinfo(struct hnae3_handle *handle, u8 *buff, u16 offset, ...@@ -124,7 +124,7 @@ static int hns3_get_sfpinfo(struct hnae3_handle *handle, u8 *buff, u16 offset,
return 0; return 0;
} }
int hns3_set_sfp_state(struct hnae3_handle *handle, bool en) static int hns3_set_sfp_state(struct hnae3_handle *handle, bool en)
{ {
struct hclge_vport *vport = hns3_cae_get_vport(handle); struct hclge_vport *vport = hns3_cae_get_vport(handle);
struct hclge_sfp_enable_cmd *req = NULL; struct hclge_sfp_enable_cmd *req = NULL;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "hnae3.h" #include "hnae3.h"
#define HNS3_MOD_VERSION "1.9.35.1" #define HNS3_MOD_VERSION "1.9.36.0"
extern char hns3_driver_version[]; extern char hns3_driver_version[];
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "hclge_cmd.h" #include "hclge_cmd.h"
#include "hnae3.h" #include "hnae3.h"
#define HCLGE_MOD_VERSION "1.9.35.1" #define HCLGE_MOD_VERSION "1.9.36.0"
#define HCLGE_DRIVER_NAME "hclge" #define HCLGE_DRIVER_NAME "hclge"
#define HCLGE_MAX_PF_NUM 8 #define HCLGE_MAX_PF_NUM 8
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "hclgevf_cmd.h" #include "hclgevf_cmd.h"
#include "hnae3.h" #include "hnae3.h"
#define HCLGEVF_MOD_VERSION "1.9.35.1" #define HCLGEVF_MOD_VERSION "1.9.36.0"
#define HCLGEVF_DRIVER_NAME "hclgevf" #define HCLGEVF_DRIVER_NAME "hclgevf"
#define HCLGEVF_MAX_VLAN_ID 4095 #define HCLGEVF_MAX_VLAN_ID 4095
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册