net/ice/base: add routine for tunnel port query
[dpdk.git] / drivers / net / ice / base / ice_flex_pipe.c
index 3beb4d9..8161cca 100644 (file)
@@ -1873,6 +1873,28 @@ ice_find_free_tunnel_entry(struct ice_hw *hw, enum ice_tunnel_type type,
        return false;
 }
 
+/**
+ * ice_get_tunnel_port - retrieve an open tunnel port
+ * @hw: pointer to the HW structure
+ * @type: tunnel type (TNL_ALL will return any open port)
+ * @port: returns open port
+ */
+bool
+ice_get_open_tunnel_port(struct ice_hw *hw, enum ice_tunnel_type type,
+                        u16 *port)
+{
+       u16 i;
+
+       for (i = 0; i < hw->tnl.count && i < ICE_TUNNEL_MAX_ENTRIES; i++)
+               if (hw->tnl.tbl[i].valid && hw->tnl.tbl[i].in_use &&
+                   (type == TNL_ALL || hw->tnl.tbl[i].type == type)) {
+                       *port = hw->tnl.tbl[i].port;
+                       return true;
+               }
+
+       return false;
+}
+
 /**
  * ice_create_tunnel
  * @hw: pointer to the HW structure