@@ -723,6 +723,58 @@ static void hns3_set_txbd_baseinfo(u16 *bdtp_fe_sc_vld_ra_ri, int frag_end)
723
723
hnae_set_field (* bdtp_fe_sc_vld_ra_ri , HNS3_TXD_SC_M , HNS3_TXD_SC_S , 0 );
724
724
}
725
725
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
+
726
778
static int hns3_fill_desc (struct hns3_enet_ring * ring , void * priv ,
727
779
int size , dma_addr_t dma , int frag_end ,
728
780
enum hns_desc_type type )
@@ -733,6 +785,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
733
785
u16 bdtp_fe_sc_vld_ra_ri = 0 ;
734
786
u32 type_cs_vlan_tso = 0 ;
735
787
struct sk_buff * skb ;
788
+ u16 inner_vtag = 0 ;
789
+ u16 out_vtag = 0 ;
736
790
u32 paylen = 0 ;
737
791
u16 mss = 0 ;
738
792
__be16 protocol ;
@@ -756,15 +810,16 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
756
810
skb = (struct sk_buff * )priv ;
757
811
paylen = skb -> len ;
758
812
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
+
759
819
if (skb -> ip_summed == CHECKSUM_PARTIAL ) {
760
820
skb_reset_mac_len (skb );
761
821
protocol = skb -> protocol ;
762
822
763
- /* vlan packet*/
764
- if (protocol == htons (ETH_P_8021Q )) {
765
- protocol = vlan_get_protocol (skb );
766
- skb -> protocol = protocol ;
767
- }
768
823
ret = hns3_get_l4_protocol (skb , & ol4_proto , & il4_proto );
769
824
if (ret )
770
825
return ret ;
@@ -790,6 +845,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
790
845
cpu_to_le32 (type_cs_vlan_tso );
791
846
desc -> tx .paylen = cpu_to_le32 (paylen );
792
847
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 );
793
850
}
794
851
795
852
/* move ring pointer to next.*/
@@ -1032,6 +1089,9 @@ static int hns3_nic_set_features(struct net_device *netdev,
1032
1089
netdev_features_t features )
1033
1090
{
1034
1091
struct hns3_nic_priv * priv = netdev_priv (netdev );
1092
+ struct hnae3_handle * h = priv -> ae_handle ;
1093
+ netdev_features_t changed ;
1094
+ int ret ;
1035
1095
1036
1096
if (features & (NETIF_F_TSO | NETIF_F_TSO6 )) {
1037
1097
priv -> ops .fill_desc = hns3_fill_desc_tso ;
@@ -1041,6 +1101,17 @@ static int hns3_nic_set_features(struct net_device *netdev,
1041
1101
priv -> ops .maybe_stop_tx = hns3_nic_maybe_stop_tx ;
1042
1102
}
1043
1103
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
+
1044
1115
netdev -> features = features ;
1045
1116
return 0 ;
1046
1117
}
@@ -1492,6 +1563,7 @@ static void hns3_set_default_feature(struct net_device *netdev)
1492
1563
1493
1564
netdev -> features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1494
1565
NETIF_F_HW_VLAN_CTAG_FILTER |
1566
+ NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
1495
1567
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
1496
1568
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
1497
1569
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
@@ -1506,6 +1578,7 @@ static void hns3_set_default_feature(struct net_device *netdev)
1506
1578
1507
1579
netdev -> hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
1508
1580
NETIF_F_HW_VLAN_CTAG_FILTER |
1581
+ NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
1509
1582
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
1510
1583
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
1511
1584
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,
2085
2158
2086
2159
prefetchw (skb -> data );
2087
2160
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
+
2088
2177
bnum = 1 ;
2089
2178
if (length <= HNS3_RX_HEAD_SIZE ) {
2090
2179
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)
2651
2740
return ret ;
2652
2741
}
2653
2742
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
+
2654
2756
static int hns3_alloc_ring_memory (struct hns3_enet_ring * ring )
2655
2757
{
2656
2758
int ret ;
@@ -2787,8 +2889,12 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
2787
2889
h -> ae_algo -> ops -> reset_queue (h , i );
2788
2890
2789
2891
hns3_fini_ring (priv -> ring_data [i ].ring );
2892
+ devm_kfree (priv -> dev , priv -> ring_data [i ].ring );
2790
2893
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 );
2791
2896
}
2897
+ devm_kfree (priv -> dev , priv -> ring_data );
2792
2898
2793
2899
return 0 ;
2794
2900
}
@@ -3162,6 +3268,115 @@ static int hns3_reset_notify(struct hnae3_handle *handle,
3162
3268
return ret ;
3163
3269
}
3164
3270
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
+
3165
3380
static const struct hnae3_client_ops client_ops = {
3166
3381
.init_instance = hns3_client_init ,
3167
3382
.uninit_instance = hns3_client_uninit ,
0 commit comments