Skip to content

Commit

Permalink
Merge branch 'hns3-next'
Browse files Browse the repository at this point in the history
Huazhong Tan says:

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

There are some misc updates for the HNS3 ethernet driver.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Sep 29, 2020
2 parents c2f8ced + dbaae5b commit fe38d95
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 37 deletions.
3 changes: 3 additions & 0 deletions drivers/net/ethernet/hisilicon/hns3/hnae3.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ enum HNAE3_DEV_CAP_BITS {
#define hnae3_dev_stash_supported(hdev) \
test_bit(HNAE3_DEV_SUPPORT_STASH_B, (hdev)->ae_dev->caps)

#define hnae3_ae_dev_tqp_txrx_indep_supported(ae_dev) \
test_bit(HNAE3_DEV_SUPPORT_TQP_TXRX_INDEP_B, (ae_dev)->caps)

#define ring_ptr_move_fw(ring, p) \
((ring)->p = ((ring)->p + 1) % (ring)->desc_num)
#define ring_ptr_move_bw(ring, p) \
Expand Down
50 changes: 48 additions & 2 deletions drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static struct dentry *hns3_dbgfs_root;
static int hns3_dbg_queue_info(struct hnae3_handle *h,
const char *cmd_buf)
{
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
struct hns3_nic_priv *priv = h->priv;
struct hns3_enet_ring *ring;
u32 base_add_l, base_add_h;
Expand Down Expand Up @@ -118,8 +119,25 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h,

value = readl_relaxed(ring->tqp->io_base +
HNS3_RING_TX_RING_PKTNUM_RECORD_REG);
dev_info(&h->pdev->dev, "TX(%u) RING PKTNUM: %u\n\n", i,
value);
dev_info(&h->pdev->dev, "TX(%u) RING PKTNUM: %u\n", i, value);

value = readl_relaxed(ring->tqp->io_base + HNS3_RING_EN_REG);
dev_info(&h->pdev->dev, "TX/RX(%u) RING EN: %s\n", i,
value ? "enable" : "disable");

if (hnae3_ae_dev_tqp_txrx_indep_supported(ae_dev)) {
value = readl_relaxed(ring->tqp->io_base +
HNS3_RING_TX_EN_REG);
dev_info(&h->pdev->dev, "TX(%u) RING EN: %s\n", i,
value ? "enable" : "disable");

value = readl_relaxed(ring->tqp->io_base +
HNS3_RING_RX_EN_REG);
dev_info(&h->pdev->dev, "RX(%u) RING EN: %s\n", i,
value ? "enable" : "disable");
}

dev_info(&h->pdev->dev, "\n");
}

return 0;
Expand Down Expand Up @@ -245,6 +263,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "queue map\n");
dev_info(&h->pdev->dev, "bd info <q_num> <bd index>\n");
dev_info(&h->pdev->dev, "dev capability\n");
dev_info(&h->pdev->dev, "dev spec\n");

if (!hns3_is_phys_func(h->pdev))
return;
Expand Down Expand Up @@ -307,6 +326,31 @@ static void hns3_dbg_dev_caps(struct hnae3_handle *h)
test_bit(HNAE3_DEV_SUPPORT_INT_QL_B, caps) ? "yes" : "no");
}

static void hns3_dbg_dev_specs(struct hnae3_handle *h)
{
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
struct hnae3_dev_specs *dev_specs = &ae_dev->dev_specs;
struct hnae3_knic_private_info *kinfo = &h->kinfo;
struct hns3_nic_priv *priv = h->priv;

dev_info(priv->dev, "MAC entry num: %u\n", dev_specs->mac_entry_num);
dev_info(priv->dev, "MNG entry num: %u\n", dev_specs->mng_entry_num);
dev_info(priv->dev, "MAX non tso bd num: %u\n",
dev_specs->max_non_tso_bd_num);
dev_info(priv->dev, "RSS ind tbl size: %u\n",
dev_specs->rss_ind_tbl_size);
dev_info(priv->dev, "RSS key size: %u\n", dev_specs->rss_key_size);
dev_info(priv->dev, "RSS size: %u\n", kinfo->rss_size);
dev_info(priv->dev, "Allocated RSS size: %u\n", kinfo->req_rss_size);
dev_info(priv->dev, "Task queue pairs numbers: %u\n", kinfo->num_tqps);

dev_info(priv->dev, "RX buffer length: %u\n", kinfo->rx_buf_len);
dev_info(priv->dev, "Desc num per TX queue: %u\n", kinfo->num_tx_desc);
dev_info(priv->dev, "Desc num per RX queue: %u\n", kinfo->num_rx_desc);
dev_info(priv->dev, "Total number of enabled TCs: %u\n", kinfo->num_tc);
dev_info(priv->dev, "MAX INT QL: %u\n", dev_specs->int_ql_max);
}

static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
size_t count, loff_t *ppos)
{
Expand Down Expand Up @@ -384,6 +428,8 @@ static ssize_t hns3_dbg_cmd_write(struct file *filp, const char __user *buffer,
ret = hns3_dbg_bd_info(handle, cmd_buf);
else if (strncmp(cmd_buf, "dev capability", 14) == 0)
hns3_dbg_dev_caps(handle);
else if (strncmp(cmd_buf, "dev spec", 8) == 0)
hns3_dbg_dev_specs(handle);
else if (handle->ae_algo->ops->dbg_run_cmd)
ret = handle->ae_algo->ops->dbg_run_cmd(handle, cmd_buf);
else
Expand Down
71 changes: 47 additions & 24 deletions drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,19 @@ static int hns3_set_tso(struct sk_buff *skb, u32 *paylen,

/* normal or tunnel packet */
l4_offset = l4.hdr - skb->data;
hdr_len = (l4.tcp->doff << 2) + l4_offset;

/* remove payload length from inner pseudo checksum when tso */
l4_paylen = skb->len - l4_offset;
csum_replace_by_diff(&l4.tcp->check,
(__force __wsum)htonl(l4_paylen));

if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) {
hdr_len = sizeof(*l4.udp) + l4_offset;
csum_replace_by_diff(&l4.udp->check,
(__force __wsum)htonl(l4_paylen));
} else {
hdr_len = (l4.tcp->doff << 2) + l4_offset;
csum_replace_by_diff(&l4.tcp->check,
(__force __wsum)htonl(l4_paylen));
}

/* find the txbd field values */
*paylen = skb->len - hdr_len;
Expand Down Expand Up @@ -1184,21 +1191,23 @@ static unsigned int hns3_skb_bd_num(struct sk_buff *skb, unsigned int *bd_size,
return bd_num;
}

static unsigned int hns3_tx_bd_num(struct sk_buff *skb, unsigned int *bd_size)
static unsigned int hns3_tx_bd_num(struct sk_buff *skb, unsigned int *bd_size,
u8 max_non_tso_bd_num)
{
struct sk_buff *frag_skb;
unsigned int bd_num = 0;

/* If the total len is within the max bd limit */
if (likely(skb->len <= HNS3_MAX_BD_SIZE && !skb_has_frag_list(skb) &&
skb_shinfo(skb)->nr_frags < HNS3_MAX_NON_TSO_BD_NUM))
skb_shinfo(skb)->nr_frags < max_non_tso_bd_num))
return skb_shinfo(skb)->nr_frags + 1U;

/* The below case will always be linearized, return
* HNS3_MAX_BD_NUM_TSO + 1U to make sure it is linearized.
*/
if (unlikely(skb->len > HNS3_MAX_TSO_SIZE ||
(!skb_is_gso(skb) && skb->len > HNS3_MAX_NON_TSO_SIZE)))
(!skb_is_gso(skb) && skb->len >
HNS3_MAX_NON_TSO_SIZE(max_non_tso_bd_num))))
return HNS3_MAX_TSO_BD_NUM + 1U;

bd_num = hns3_skb_bd_num(skb, bd_size, bd_num);
Expand All @@ -1223,31 +1232,34 @@ static unsigned int hns3_gso_hdr_len(struct sk_buff *skb)
return skb_inner_transport_offset(skb) + inner_tcp_hdrlen(skb);
}

/* HW need every continuous 8 buffer data to be larger than MSS,
* we simplify it by ensuring skb_headlen + the first continuous
* 7 frags to to be larger than gso header len + mss, and the remaining
* continuous 7 frags to be larger than MSS except the last 7 frags.
/* HW need every continuous max_non_tso_bd_num buffer data to be larger
* than MSS, we simplify it by ensuring skb_headlen + the first continuous
* max_non_tso_bd_num - 1 frags to be larger than gso header len + mss,
* and the remaining continuous max_non_tso_bd_num - 1 frags to be larger
* than MSS except the last max_non_tso_bd_num - 1 frags.
*/
static bool hns3_skb_need_linearized(struct sk_buff *skb, unsigned int *bd_size,
unsigned int bd_num)
unsigned int bd_num, u8 max_non_tso_bd_num)
{
unsigned int tot_len = 0;
int i;

for (i = 0; i < HNS3_MAX_NON_TSO_BD_NUM - 1U; i++)
for (i = 0; i < max_non_tso_bd_num - 1U; i++)
tot_len += bd_size[i];

/* ensure the first 8 frags is greater than mss + header */
if (tot_len + bd_size[HNS3_MAX_NON_TSO_BD_NUM - 1U] <
/* ensure the first max_non_tso_bd_num frags is greater than
* mss + header
*/
if (tot_len + bd_size[max_non_tso_bd_num - 1U] <
skb_shinfo(skb)->gso_size + hns3_gso_hdr_len(skb))
return true;

/* ensure every continuous 7 buffer is greater than mss
* except the last one.
/* ensure every continuous max_non_tso_bd_num - 1 buffer is greater
* than mss except the last one.
*/
for (i = 0; i < bd_num - HNS3_MAX_NON_TSO_BD_NUM; i++) {
for (i = 0; i < bd_num - max_non_tso_bd_num; i++) {
tot_len -= bd_size[i];
tot_len += bd_size[i + HNS3_MAX_NON_TSO_BD_NUM - 1U];
tot_len += bd_size[i + max_non_tso_bd_num - 1U];

if (tot_len < skb_shinfo(skb)->gso_size)
return true;
Expand All @@ -1269,14 +1281,16 @@ static int hns3_nic_maybe_stop_tx(struct hns3_enet_ring *ring,
struct sk_buff *skb)
{
struct hns3_nic_priv *priv = netdev_priv(netdev);
u8 max_non_tso_bd_num = priv->max_non_tso_bd_num;
unsigned int bd_size[HNS3_MAX_TSO_BD_NUM + 1U];
unsigned int bd_num;

bd_num = hns3_tx_bd_num(skb, bd_size);
if (unlikely(bd_num > HNS3_MAX_NON_TSO_BD_NUM)) {
bd_num = hns3_tx_bd_num(skb, bd_size, max_non_tso_bd_num);
if (unlikely(bd_num > max_non_tso_bd_num)) {
if (bd_num <= HNS3_MAX_TSO_BD_NUM && skb_is_gso(skb) &&
!hns3_skb_need_linearized(skb, bd_size, bd_num)) {
trace_hns3_over_8bd(skb);
!hns3_skb_need_linearized(skb, bd_size, bd_num,
max_non_tso_bd_num)) {
trace_hns3_over_max_bd(skb);
goto out;
}

Expand All @@ -1286,8 +1300,8 @@ static int hns3_nic_maybe_stop_tx(struct hns3_enet_ring *ring,
bd_num = hns3_tx_bd_count(skb->len);
if ((skb_is_gso(skb) && bd_num > HNS3_MAX_TSO_BD_NUM) ||
(!skb_is_gso(skb) &&
bd_num > HNS3_MAX_NON_TSO_BD_NUM)) {
trace_hns3_over_8bd(skb);
bd_num > max_non_tso_bd_num)) {
trace_hns3_over_max_bd(skb);
return -ENOMEM;
}

Expand Down Expand Up @@ -2304,6 +2318,13 @@ static void hns3_set_default_feature(struct net_device *netdev)
netdev->features |= NETIF_F_NTUPLE;
}
}

if (test_bit(HNAE3_DEV_SUPPORT_UDP_GSO_B, ae_dev->caps)) {
netdev->hw_features |= NETIF_F_GSO_UDP_L4;
netdev->features |= NETIF_F_GSO_UDP_L4;
netdev->vlan_features |= NETIF_F_GSO_UDP_L4;
netdev->hw_enc_features |= NETIF_F_GSO_UDP_L4;
}
}

static int hns3_alloc_buffer(struct hns3_enet_ring *ring,
Expand Down Expand Up @@ -3991,6 +4012,7 @@ static void hns3_info_show(struct hns3_nic_priv *priv)
static int hns3_client_init(struct hnae3_handle *handle)
{
struct pci_dev *pdev = handle->pdev;
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
u16 alloc_tqps, max_rss_size;
struct hns3_nic_priv *priv;
struct net_device *netdev;
Expand All @@ -4007,6 +4029,7 @@ static int hns3_client_init(struct hnae3_handle *handle)
priv->netdev = netdev;
priv->ae_handle = handle;
priv->tx_timeout_count = 0;
priv->max_non_tso_bd_num = ae_dev->dev_specs.max_non_tso_bd_num;
set_bit(HNS3_NIC_STATE_DOWN, &priv->state);

handle->msg_enable = netif_msg_init(debug, DEFAULT_MSG_LEVEL);
Expand Down
8 changes: 5 additions & 3 deletions drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ enum hns3_nic_state {
#define HNS3_RING_TX_RING_EBD_OFFSET_REG 0x00070
#define HNS3_RING_TX_RING_BD_ERR_REG 0x00074
#define HNS3_RING_EN_REG 0x00090
#define HNS3_RING_RX_EN_REG 0x00098
#define HNS3_RING_TX_EN_REG 0x000D4

#define HNS3_RX_HEAD_SIZE 256

Expand Down Expand Up @@ -167,13 +169,12 @@ enum hns3_nic_state {
#define HNS3_VECTOR_INITED 1

#define HNS3_MAX_BD_SIZE 65535
#define HNS3_MAX_NON_TSO_BD_NUM 8U
#define HNS3_MAX_TSO_BD_NUM 63U
#define HNS3_MAX_TSO_SIZE \
(HNS3_MAX_BD_SIZE * HNS3_MAX_TSO_BD_NUM)

#define HNS3_MAX_NON_TSO_SIZE \
(HNS3_MAX_BD_SIZE * HNS3_MAX_NON_TSO_BD_NUM)
#define HNS3_MAX_NON_TSO_SIZE(max_non_tso_bd_num) \
(HNS3_MAX_BD_SIZE * (max_non_tso_bd_num))

#define HNS3_VECTOR_GL0_OFFSET 0x100
#define HNS3_VECTOR_GL1_OFFSET 0x200
Expand Down Expand Up @@ -475,6 +476,7 @@ struct hns3_nic_priv {
struct hns3_enet_ring *ring;
struct hns3_enet_tqp_vector *tqp_vector;
u16 vector_num;
u8 max_non_tso_bd_num;

u64 tx_timeout_count;

Expand Down
9 changes: 2 additions & 7 deletions drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ static void hns3_self_test(struct net_device *ndev,
struct hnae3_handle *h = priv->ae_handle;
int st_param[HNS3_SELF_TEST_TYPE_NUM][2];
bool if_running = netif_running(ndev);
#if IS_ENABLED(CONFIG_VLAN_8021Q)
bool dis_vlan_filter;
#endif
int test_index = 0;
u32 i;

Expand Down Expand Up @@ -350,9 +347,7 @@ static void hns3_self_test(struct net_device *ndev,

#if IS_ENABLED(CONFIG_VLAN_8021Q)
/* Disable the vlan filter for selftest does not support it */
dis_vlan_filter = (ndev->features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
h->ae_algo->ops->enable_vlan_filter;
if (dis_vlan_filter)
if (h->ae_algo->ops->enable_vlan_filter)
h->ae_algo->ops->enable_vlan_filter(h, false);
#endif

Expand Down Expand Up @@ -389,7 +384,7 @@ static void hns3_self_test(struct net_device *ndev,
h->ae_algo->ops->halt_autoneg(h, false);

#if IS_ENABLED(CONFIG_VLAN_8021Q)
if (dis_vlan_filter)
if (h->ae_algo->ops->enable_vlan_filter)
h->ae_algo->ops->enable_vlan_filter(h, true);
#endif

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/hisilicon/hns3/hns3_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ DECLARE_EVENT_CLASS(hns3_skb_template,
)
);

DEFINE_EVENT(hns3_skb_template, hns3_over_8bd,
DEFINE_EVENT(hns3_skb_template, hns3_over_max_bd,
TP_PROTO(struct sk_buff *skb),
TP_ARGS(skb));

Expand Down
Loading

0 comments on commit fe38d95

Please sign in to comment.