ixgbe: use tc_cls_can_offload_and_chain0()
[platform/kernel/linux-starfive.git] / drivers / net / ethernet / intel / ixgbe / ixgbe_main.c
index 4f28621..bbb622f 100644 (file)
@@ -1171,7 +1171,7 @@ static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
        struct ixgbe_adapter *adapter = q_vector->adapter;
        struct ixgbe_tx_buffer *tx_buffer;
        union ixgbe_adv_tx_desc *tx_desc;
-       unsigned int total_bytes = 0, total_packets = 0;
+       unsigned int total_bytes = 0, total_packets = 0, total_ipsec = 0;
        unsigned int budget = q_vector->tx.work_limit;
        unsigned int i = tx_ring->next_to_clean;
 
@@ -1202,6 +1202,8 @@ static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
                /* update the statistics for this packet */
                total_bytes += tx_buffer->bytecount;
                total_packets += tx_buffer->gso_segs;
+               if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_IPSEC)
+                       total_ipsec++;
 
                /* free the skb */
                if (ring_is_xdp(tx_ring))
@@ -1264,6 +1266,7 @@ static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
        u64_stats_update_end(&tx_ring->syncp);
        q_vector->tx.total_bytes += total_bytes;
        q_vector->tx.total_packets += total_packets;
+       adapter->tx_ipsec += total_ipsec;
 
        if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
                /* schedule immediate reset if we believe we hung */
@@ -1752,6 +1755,9 @@ static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
                __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
        }
 
+       if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_SECP))
+               ixgbe_ipsec_rx(rx_ring, rx_desc, skb);
+
        skb->protocol = eth_type_trans(skb, dev);
 
        /* record Rx queue, or update MACVLAN statistics */
@@ -5425,6 +5431,7 @@ static void ixgbe_configure(struct ixgbe_adapter *adapter)
 
        ixgbe_set_rx_mode(adapter->netdev);
        ixgbe_restore_vlan(adapter);
+       ixgbe_ipsec_restore(adapter);
 
        switch (hw->mac.type) {
        case ixgbe_mac_82599EB:
@@ -7795,10 +7802,12 @@ static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
 }
 
 static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
-                         struct ixgbe_tx_buffer *first)
+                         struct ixgbe_tx_buffer *first,
+                         struct ixgbe_ipsec_tx_data *itd)
 {
        struct sk_buff *skb = first->skb;
        u32 vlan_macip_lens = 0;
+       u32 fceof_saidx = 0;
        u32 type_tucmd = 0;
 
        if (skb->ip_summed != CHECKSUM_PARTIAL) {
@@ -7839,7 +7848,12 @@ no_csum:
        vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
        vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
 
-       ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
+       if (first->tx_flags & IXGBE_TX_FLAGS_IPSEC) {
+               fceof_saidx |= itd->sa_idx;
+               type_tucmd |= itd->flags | itd->trailer_len;
+       }
+
+       ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd, 0);
 }
 
 #define IXGBE_SET_FLAG(_input, _flag, _result) \
@@ -7882,11 +7896,16 @@ static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
                                        IXGBE_TX_FLAGS_CSUM,
                                        IXGBE_ADVTXD_POPTS_TXSM);
 
-       /* enble IPv4 checksum for TSO */
+       /* enable IPv4 checksum for TSO */
        olinfo_status |= IXGBE_SET_FLAG(tx_flags,
                                        IXGBE_TX_FLAGS_IPV4,
                                        IXGBE_ADVTXD_POPTS_IXSM);
 
+       /* enable IPsec */
+       olinfo_status |= IXGBE_SET_FLAG(tx_flags,
+                                       IXGBE_TX_FLAGS_IPSEC,
+                                       IXGBE_ADVTXD_POPTS_IPSEC);
+
        /*
         * Check Context must be set if Tx switch is enabled, which it
         * always is for case where virtual functions are running
@@ -8350,6 +8369,7 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
        u32 tx_flags = 0;
        unsigned short f;
        u16 count = TXD_USE_COUNT(skb_headlen(skb));
+       struct ixgbe_ipsec_tx_data ipsec_tx = { 0 };
        __be16 protocol = skb->protocol;
        u8 hdr_len = 0;
 
@@ -8454,11 +8474,16 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
        }
 
 #endif /* IXGBE_FCOE */
+
+#ifdef CONFIG_XFRM_OFFLOAD
+       if (skb->sp && !ixgbe_ipsec_tx(tx_ring, first, &ipsec_tx))
+               goto out_drop;
+#endif
        tso = ixgbe_tso(tx_ring, first, &hdr_len);
        if (tso < 0)
                goto out_drop;
        else if (!tso)
-               ixgbe_tx_csum(tx_ring, first);
+               ixgbe_tx_csum(tx_ring, first, &ipsec_tx);
 
        /* add the ATR filter if ATR is on */
        if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
@@ -9278,9 +9303,6 @@ free_jump:
 static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter,
                                  struct tc_cls_u32_offload *cls_u32)
 {
-       if (cls_u32->common.chain_index)
-               return -EOPNOTSUPP;
-
        switch (cls_u32->command) {
        case TC_CLSU32_NEW_KNODE:
        case TC_CLSU32_REPLACE_KNODE:
@@ -9302,7 +9324,7 @@ static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
 {
        struct ixgbe_adapter *adapter = cb_priv;
 
-       if (!tc_can_offload(adapter->netdev))
+       if (!tc_cls_can_offload_and_chain0(adapter->netdev, type_data))
                return -EOPNOTSUPP;
 
        switch (type) {
@@ -9870,6 +9892,12 @@ ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
        if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
                features &= ~NETIF_F_TSO;
 
+#ifdef CONFIG_XFRM_OFFLOAD
+       /* IPsec offload doesn't get along well with others *yet* */
+       if (skb->sp)
+               features &= ~(NETIF_F_TSO | NETIF_F_HW_CSUM);
+#endif
+
        return features;
 }
 
@@ -10459,6 +10487,7 @@ skip_sriov:
                                         NETIF_F_FCOE_MTU;
        }
 #endif /* IXGBE_FCOE */
+       ixgbe_init_ipsec_offload(adapter);
 
        if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
                netdev->hw_features |= NETIF_F_LRO;
@@ -10694,6 +10723,7 @@ static void ixgbe_remove(struct pci_dev *pdev)
        if (netdev->reg_state == NETREG_REGISTERED)
                unregister_netdev(netdev);
 
+       ixgbe_stop_ipsec_offload(adapter);
        ixgbe_clear_interrupt_scheme(adapter);
 
        ixgbe_release_hw_control(adapter);