Skip to content

Commit a8038be

Browse files
committed
Merge branch 'hns3-next'
Peng Li says: ==================== add some features and fix some bugs for HNS3 driver This patchset adds some new feature support and fixes some bugs: [Patch 1/17 - 5/17] add the support to modify/query the tqp number through ethtool -L/l command, and also fix some related bugs for change tqp number. [Patch 6/17 - 9-17] add support vlan tag offload on tx&&rx direction for pf, and fix some related bugs. [patch 10/17 - 11/17] fix bugs for auto negotiation. [patch 12/17] adds support for ethtool command set_pauseparam. [patch 13/17 - 14/17] add support to update flow control settings after autoneg. [patch 15/17 - 17/17] fix some other bugs in net-next. --- Change Log: V4 -> V5: 1. change the name spelling of Peng Li. V3 -> V4: 1. change the name spelling of Mingguang Qu and Jian Shen. V2 -> V3: 1. order local variables requested by David Miller. 2. use "int" for index iteration loops requested by David Miller. V1 -> V2: 1. fix the comments from Sergei Shtylyov. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 214bb1c + 71b8386 commit a8038be

File tree

10 files changed

+855
-44
lines changed

10 files changed

+855
-44
lines changed

drivers/net/ethernet/hisilicon/hns3/hnae3.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ struct hnae3_ae_dev {
278278
* Set vlan filter config of Ports
279279
* set_vf_vlan_filter()
280280
* Set vlan filter config of vf
281+
* enable_hw_strip_rxvtag()
282+
* Enable/disable hardware strip vlan tag of packets received
281283
*/
282284
struct hnae3_ae_ops {
283285
int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
@@ -384,8 +386,16 @@ struct hnae3_ae_ops {
384386
u16 vlan_id, bool is_kill);
385387
int (*set_vf_vlan_filter)(struct hnae3_handle *handle, int vfid,
386388
u16 vlan, u8 qos, __be16 proto);
389+
int (*enable_hw_strip_rxvtag)(struct hnae3_handle *handle, bool enable);
387390
void (*reset_event)(struct hnae3_handle *handle,
388391
enum hnae3_reset_type reset);
392+
void (*get_channels)(struct hnae3_handle *handle,
393+
struct ethtool_channels *ch);
394+
void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
395+
u16 *free_tqps, u16 *max_rss_size);
396+
int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num);
397+
void (*get_flowctrl_adv)(struct hnae3_handle *handle,
398+
u32 *flowctrl_adv);
389399
};
390400

391401
struct hnae3_dcb_ops {

drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 220 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,58 @@ static void hns3_set_txbd_baseinfo(u16 *bdtp_fe_sc_vld_ra_ri, int frag_end)
723723
hnae_set_field(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_SC_M, HNS3_TXD_SC_S, 0);
724724
}
725725

726+
static int hns3_fill_desc_vtags(struct sk_buff *skb,
727+
struct hns3_enet_ring *tx_ring,
728+
u32 *inner_vlan_flag,
729+
u32 *out_vlan_flag,
730+
u16 *inner_vtag,
731+
u16 *out_vtag)
732+
{
733+
#define HNS3_TX_VLAN_PRIO_SHIFT 13
734+
735+
if (skb->protocol == htons(ETH_P_8021Q) &&
736+
!(tx_ring->tqp->handle->kinfo.netdev->features &
737+
NETIF_F_HW_VLAN_CTAG_TX)) {
738+
/* When HW VLAN acceleration is turned off, and the stack
739+
* sets the protocol to 802.1q, the driver just need to
740+
* set the protocol to the encapsulated ethertype.
741+
*/
742+
skb->protocol = vlan_get_protocol(skb);
743+
return 0;
744+
}
745+
746+
if (skb_vlan_tag_present(skb)) {
747+
u16 vlan_tag;
748+
749+
vlan_tag = skb_vlan_tag_get(skb);
750+
vlan_tag |= (skb->priority & 0x7) << HNS3_TX_VLAN_PRIO_SHIFT;
751+
752+
/* Based on hw strategy, use out_vtag in two layer tag case,
753+
* and use inner_vtag in one tag case.
754+
*/
755+
if (skb->protocol == htons(ETH_P_8021Q)) {
756+
hnae_set_bit(*out_vlan_flag, HNS3_TXD_OVLAN_B, 1);
757+
*out_vtag = vlan_tag;
758+
} else {
759+
hnae_set_bit(*inner_vlan_flag, HNS3_TXD_VLAN_B, 1);
760+
*inner_vtag = vlan_tag;
761+
}
762+
} else if (skb->protocol == htons(ETH_P_8021Q)) {
763+
struct vlan_ethhdr *vhdr;
764+
int rc;
765+
766+
rc = skb_cow_head(skb, 0);
767+
if (rc < 0)
768+
return rc;
769+
vhdr = (struct vlan_ethhdr *)skb->data;
770+
vhdr->h_vlan_TCI |= cpu_to_be16((skb->priority & 0x7)
771+
<< HNS3_TX_VLAN_PRIO_SHIFT);
772+
}
773+
774+
skb->protocol = vlan_get_protocol(skb);
775+
return 0;
776+
}
777+
726778
static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
727779
int size, dma_addr_t dma, int frag_end,
728780
enum hns_desc_type type)
@@ -733,6 +785,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
733785
u16 bdtp_fe_sc_vld_ra_ri = 0;
734786
u32 type_cs_vlan_tso = 0;
735787
struct sk_buff *skb;
788+
u16 inner_vtag = 0;
789+
u16 out_vtag = 0;
736790
u32 paylen = 0;
737791
u16 mss = 0;
738792
__be16 protocol;
@@ -756,15 +810,16 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
756810
skb = (struct sk_buff *)priv;
757811
paylen = skb->len;
758812

813+
ret = hns3_fill_desc_vtags(skb, ring, &type_cs_vlan_tso,
814+
&ol_type_vlan_len_msec,
815+
&inner_vtag, &out_vtag);
816+
if (unlikely(ret))
817+
return ret;
818+
759819
if (skb->ip_summed == CHECKSUM_PARTIAL) {
760820
skb_reset_mac_len(skb);
761821
protocol = skb->protocol;
762822

763-
/* vlan packet*/
764-
if (protocol == htons(ETH_P_8021Q)) {
765-
protocol = vlan_get_protocol(skb);
766-
skb->protocol = protocol;
767-
}
768823
ret = hns3_get_l4_protocol(skb, &ol4_proto, &il4_proto);
769824
if (ret)
770825
return ret;
@@ -790,6 +845,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
790845
cpu_to_le32(type_cs_vlan_tso);
791846
desc->tx.paylen = cpu_to_le32(paylen);
792847
desc->tx.mss = cpu_to_le16(mss);
848+
desc->tx.vlan_tag = cpu_to_le16(inner_vtag);
849+
desc->tx.outer_vlan_tag = cpu_to_le16(out_vtag);
793850
}
794851

795852
/* move ring pointer to next.*/
@@ -1032,6 +1089,9 @@ static int hns3_nic_set_features(struct net_device *netdev,
10321089
netdev_features_t features)
10331090
{
10341091
struct hns3_nic_priv *priv = netdev_priv(netdev);
1092+
struct hnae3_handle *h = priv->ae_handle;
1093+
netdev_features_t changed;
1094+
int ret;
10351095

10361096
if (features & (NETIF_F_TSO | NETIF_F_TSO6)) {
10371097
priv->ops.fill_desc = hns3_fill_desc_tso;
@@ -1041,6 +1101,17 @@ static int hns3_nic_set_features(struct net_device *netdev,
10411101
priv->ops.maybe_stop_tx = hns3_nic_maybe_stop_tx;
10421102
}
10431103

1104+
changed = netdev->features ^ features;
1105+
if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
1106+
if (features & NETIF_F_HW_VLAN_CTAG_RX)
1107+
ret = h->ae_algo->ops->enable_hw_strip_rxvtag(h, true);
1108+
else
1109+
ret = h->ae_algo->ops->enable_hw_strip_rxvtag(h, false);
1110+
1111+
if (ret)
1112+
return ret;
1113+
}
1114+
10441115
netdev->features = features;
10451116
return 0;
10461117
}
@@ -1492,6 +1563,7 @@ static void hns3_set_default_feature(struct net_device *netdev)
14921563

14931564
netdev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
14941565
NETIF_F_HW_VLAN_CTAG_FILTER |
1566+
NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
14951567
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
14961568
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
14971569
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
@@ -1506,6 +1578,7 @@ static void hns3_set_default_feature(struct net_device *netdev)
15061578

15071579
netdev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
15081580
NETIF_F_HW_VLAN_CTAG_FILTER |
1581+
NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
15091582
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
15101583
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
15111584
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
@@ -2085,6 +2158,22 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring,
20852158

20862159
prefetchw(skb->data);
20872160

2161+
/* Based on hw strategy, the tag offloaded will be stored at
2162+
* ot_vlan_tag in two layer tag case, and stored at vlan_tag
2163+
* in one layer tag case.
2164+
*/
2165+
if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
2166+
u16 vlan_tag;
2167+
2168+
vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
2169+
if (!(vlan_tag & VLAN_VID_MASK))
2170+
vlan_tag = le16_to_cpu(desc->rx.vlan_tag);
2171+
if (vlan_tag & VLAN_VID_MASK)
2172+
__vlan_hwaccel_put_tag(skb,
2173+
htons(ETH_P_8021Q),
2174+
vlan_tag);
2175+
}
2176+
20882177
bnum = 1;
20892178
if (length <= HNS3_RX_HEAD_SIZE) {
20902179
memcpy(__skb_put(skb, length), va, ALIGN(length, sizeof(long)));
@@ -2651,6 +2740,19 @@ static int hns3_get_ring_config(struct hns3_nic_priv *priv)
26512740
return ret;
26522741
}
26532742

2743+
static void hns3_put_ring_config(struct hns3_nic_priv *priv)
2744+
{
2745+
struct hnae3_handle *h = priv->ae_handle;
2746+
int i;
2747+
2748+
for (i = 0; i < h->kinfo.num_tqps; i++) {
2749+
devm_kfree(priv->dev, priv->ring_data[i].ring);
2750+
devm_kfree(priv->dev,
2751+
priv->ring_data[i + h->kinfo.num_tqps].ring);
2752+
}
2753+
devm_kfree(priv->dev, priv->ring_data);
2754+
}
2755+
26542756
static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring)
26552757
{
26562758
int ret;
@@ -2787,8 +2889,12 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
27872889
h->ae_algo->ops->reset_queue(h, i);
27882890

27892891
hns3_fini_ring(priv->ring_data[i].ring);
2892+
devm_kfree(priv->dev, priv->ring_data[i].ring);
27902893
hns3_fini_ring(priv->ring_data[i + h->kinfo.num_tqps].ring);
2894+
devm_kfree(priv->dev,
2895+
priv->ring_data[i + h->kinfo.num_tqps].ring);
27912896
}
2897+
devm_kfree(priv->dev, priv->ring_data);
27922898

27932899
return 0;
27942900
}
@@ -3162,6 +3268,115 @@ static int hns3_reset_notify(struct hnae3_handle *handle,
31623268
return ret;
31633269
}
31643270

3271+
static u16 hns3_get_max_available_channels(struct net_device *netdev)
3272+
{
3273+
struct hnae3_handle *h = hns3_get_handle(netdev);
3274+
u16 free_tqps, max_rss_size, max_tqps;
3275+
3276+
h->ae_algo->ops->get_tqps_and_rss_info(h, &free_tqps, &max_rss_size);
3277+
max_tqps = h->kinfo.num_tc * max_rss_size;
3278+
3279+
return min_t(u16, max_tqps, (free_tqps + h->kinfo.num_tqps));
3280+
}
3281+
3282+
static int hns3_modify_tqp_num(struct net_device *netdev, u16 new_tqp_num)
3283+
{
3284+
struct hns3_nic_priv *priv = netdev_priv(netdev);
3285+
struct hnae3_handle *h = hns3_get_handle(netdev);
3286+
int ret;
3287+
3288+
ret = h->ae_algo->ops->set_channels(h, new_tqp_num);
3289+
if (ret)
3290+
return ret;
3291+
3292+
ret = hns3_get_ring_config(priv);
3293+
if (ret)
3294+
return ret;
3295+
3296+
ret = hns3_nic_init_vector_data(priv);
3297+
if (ret)
3298+
goto err_uninit_vector;
3299+
3300+
ret = hns3_init_all_ring(priv);
3301+
if (ret)
3302+
goto err_put_ring;
3303+
3304+
return 0;
3305+
3306+
err_put_ring:
3307+
hns3_put_ring_config(priv);
3308+
err_uninit_vector:
3309+
hns3_nic_uninit_vector_data(priv);
3310+
return ret;
3311+
}
3312+
3313+
static int hns3_adjust_tqps_num(u8 num_tc, u32 new_tqp_num)
3314+
{
3315+
return (new_tqp_num / num_tc) * num_tc;
3316+
}
3317+
3318+
int hns3_set_channels(struct net_device *netdev,
3319+
struct ethtool_channels *ch)
3320+
{
3321+
struct hns3_nic_priv *priv = netdev_priv(netdev);
3322+
struct hnae3_handle *h = hns3_get_handle(netdev);
3323+
struct hnae3_knic_private_info *kinfo = &h->kinfo;
3324+
bool if_running = netif_running(netdev);
3325+
u32 new_tqp_num = ch->combined_count;
3326+
u16 org_tqp_num;
3327+
int ret;
3328+
3329+
if (ch->rx_count || ch->tx_count)
3330+
return -EINVAL;
3331+
3332+
if (new_tqp_num > hns3_get_max_available_channels(netdev) ||
3333+
new_tqp_num < kinfo->num_tc) {
3334+
dev_err(&netdev->dev,
3335+
"Change tqps fail, the tqp range is from %d to %d",
3336+
kinfo->num_tc,
3337+
hns3_get_max_available_channels(netdev));
3338+
return -EINVAL;
3339+
}
3340+
3341+
new_tqp_num = hns3_adjust_tqps_num(kinfo->num_tc, new_tqp_num);
3342+
if (kinfo->num_tqps == new_tqp_num)
3343+
return 0;
3344+
3345+
if (if_running)
3346+
dev_close(netdev);
3347+
3348+
hns3_clear_all_ring(h);
3349+
3350+
ret = hns3_nic_uninit_vector_data(priv);
3351+
if (ret) {
3352+
dev_err(&netdev->dev,
3353+
"Unbind vector with tqp fail, nothing is changed");
3354+
goto open_netdev;
3355+
}
3356+
3357+
hns3_uninit_all_ring(priv);
3358+
3359+
org_tqp_num = h->kinfo.num_tqps;
3360+
ret = hns3_modify_tqp_num(netdev, new_tqp_num);
3361+
if (ret) {
3362+
ret = hns3_modify_tqp_num(netdev, org_tqp_num);
3363+
if (ret) {
3364+
/* If revert to old tqp failed, fatal error occurred */
3365+
dev_err(&netdev->dev,
3366+
"Revert to old tqp num fail, ret=%d", ret);
3367+
return ret;
3368+
}
3369+
dev_info(&netdev->dev,
3370+
"Change tqp num fail, Revert to old tqp num");
3371+
}
3372+
3373+
open_netdev:
3374+
if (if_running)
3375+
dev_open(netdev);
3376+
3377+
return ret;
3378+
}
3379+
31653380
static const struct hnae3_client_ops client_ops = {
31663381
.init_instance = hns3_client_init,
31673382
.uninit_instance = hns3_client_uninit,

drivers/net/ethernet/hisilicon/hns3/hns3_enet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ static inline void hns3_write_reg(void __iomem *base, u32 reg, u32 value)
595595
(((struct hns3_nic_priv *)netdev_priv(ndev))->ae_handle)
596596

597597
void hns3_ethtool_set_ops(struct net_device *netdev);
598+
int hns3_set_channels(struct net_device *netdev,
599+
struct ethtool_channels *ch);
598600

599601
bool hns3_clean_tx_ring(struct hns3_enet_ring *ring, int budget);
600602
int hns3_init_all_ring(struct hns3_nic_priv *priv);

0 commit comments

Comments
 (0)