net/ice/base: support tunnel port for parser
authorQi Zhang <qi.z.zhang@intel.com>
Fri, 17 Sep 2021 14:43:21 +0000 (22:43 +0800)
committerQi Zhang <qi.z.zhang@intel.com>
Tue, 21 Sep 2021 13:17:58 +0000 (15:17 +0200)
UDP tunnel can be added/deleted for vxlan, geneve, ecpri through
below APIs:
ice_parser_vxlan_tunnel_set
ice_parser_geneve_tunnel_set
ice_parser_ecpri_tunnel_set

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
Acked-by: Junfeng Guo <junfeng.guo@intel.com>
drivers/net/ice/base/ice_parser.c
drivers/net/ice/base/ice_parser.h

index 395ad22..a657e82 100644 (file)
@@ -367,3 +367,78 @@ void ice_parser_dvm_set(struct ice_parser *psr, bool on)
        _bst_vm_set(psr, "BOOST_MAC_VLAN_DVM", on);
        _bst_vm_set(psr, "BOOST_MAC_VLAN_SVM", !on);
 }
+
+static enum ice_status
+_tunnel_port_set(struct ice_parser *psr, const char *prefix, u16 udp_port,
+                bool on)
+{
+       u8 *buf = (u8 *)&udp_port;
+       struct ice_bst_tcam_item *item;
+       u16 i = 0;
+
+       while (true) {
+               item = ice_bst_tcam_search(psr->bst_tcam_table,
+                                          psr->bst_lbl_table,
+                                          prefix, &i);
+               if (!item)
+                       break;
+
+               /* found empty slot to add */
+               if (on && item->key[16] == 0xfe && item->key_inv[16] == 0xfe) {
+                       item->key_inv[15] = buf[0];
+                       item->key_inv[16] = buf[1];
+                       item->key[15] = (u8)(0xff - buf[0]);
+                       item->key[16] = (u8)(0xff - buf[1]);
+
+                       return ICE_SUCCESS;
+               /* found a matched slot to delete */
+               } else if (!on && (item->key_inv[15] == buf[0] ||
+                          item->key_inv[16] == buf[1])) {
+                       item->key_inv[15] = 0xff;
+                       item->key_inv[16] = 0xfe;
+                       item->key[15] = 0xff;
+                       item->key[16] = 0xfe;
+
+                       return ICE_SUCCESS;
+               }
+               i++;
+       }
+
+       return ICE_ERR_PARAM;
+}
+
+/**
+ * ice_parser_vxlan_tunnel_set - configure vxlan tunnel for parser
+ * @psr: pointer to a parser instance
+ * @udp_port: vxlan tunnel port in UDP header
+ * @on: true to turn on; false to turn off
+ */
+enum ice_status ice_parser_vxlan_tunnel_set(struct ice_parser *psr,
+                                           u16 udp_port, bool on)
+{
+       return _tunnel_port_set(psr, "TNL_VXLAN", udp_port, on);
+}
+
+/**
+ * ice_parser_geneve_tunnel_set - configure geneve tunnel for parser
+ * @psr: pointer to a parser instance
+ * @udp_port: geneve tunnel port in UDP header
+ * @on: true to turn on; false to turn off
+ */
+enum ice_status ice_parser_geneve_tunnel_set(struct ice_parser *psr,
+                                            u16 udp_port, bool on)
+{
+       return _tunnel_port_set(psr, "TNL_GENEVE", udp_port, on);
+}
+
+/**
+ * ice_parser_ecpri_tunnel_set - configure ecpri tunnel for parser
+ * @psr: pointer to a parser instance
+ * @udp_port: ecpri tunnel port in UDP header
+ * @on: true to turn on; false to turn off
+ */
+enum ice_status ice_parser_ecpri_tunnel_set(struct ice_parser *psr,
+                                           u16 udp_port, bool on)
+{
+       return _tunnel_port_set(psr, "TNL_UDP_ECPRI", udp_port, on);
+}
index e310466..105d908 100644 (file)
@@ -58,6 +58,12 @@ struct ice_parser {
 enum ice_status ice_parser_create(struct ice_hw *hw, struct ice_parser **psr);
 void ice_parser_destroy(struct ice_parser *psr);
 void ice_parser_dvm_set(struct ice_parser *psr, bool on);
+enum ice_status ice_parser_vxlan_tunnel_set(struct ice_parser *psr,
+                                           u16 udp_port, bool on);
+enum ice_status ice_parser_geneve_tunnel_set(struct ice_parser *psr,
+                                            u16 udp_port, bool on);
+enum ice_status ice_parser_ecpri_tunnel_set(struct ice_parser *psr,
+                                           u16 udp_port, bool on);
 
 struct ice_parser_proto_off {
        u8 proto_id; /* hardware protocol ID */