[dpdk-dev,v2,2/6] ethdev: add new ops of 'is_command_supported' and 'rx_classification_filter_ctl'
diff mbox

Message ID 1406535955-31070-3-git-send-email-helin.zhang@intel.com
State Superseded, archived
Headers show

Commit Message

Helin Zhang July 28, 2014, 8:25 a.m. UTC
Two ops of 'is_command_supported' and
'rx_classification_filter_ctl' are added. New header
file of 'rte_eth_features.h' is added.
* 'is_command_supported': It is for capability discovery,
  that is to check if specific feature/command is
  supported on a port.
* 'rx_classification_filter_ctl': It is for receive
  classification filter configuring. e.g. selecting hash
  function, possibly configuring flow director. It is a
  common API where a lot of commands can be implemented
  for different sub features, to avoid defining quite a
  lot of ops for device specific features.
* 'rte_eth_features.h': It includes all the feature
  commands which can be checked and processed in above
  two ops. Also it may include other commands for future
  implementations.

Signed-off-by: Helin Zhang <helin.zhang@intel.com>
---
 lib/librte_ether/Makefile           |  1 +
 lib/librte_ether/rte_eth_features.h | 73 +++++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.c       | 31 ++++++++++++++++
 lib/librte_ether/rte_ethdev.h       | 55 ++++++++++++++++++++++++++++
 4 files changed, 160 insertions(+)
 create mode 100644 lib/librte_ether/rte_eth_features.h

Patch
diff mbox

diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile
index b310f8b..8089723 100644
--- a/lib/librte_ether/Makefile
+++ b/lib/librte_ether/Makefile
@@ -46,6 +46,7 @@  SRCS-y += rte_ethdev.c
 #
 SYMLINK-y-include += rte_ether.h
 SYMLINK-y-include += rte_ethdev.h
+SYMLINK-y-include += rte_eth_features.h
 
 # this lib depends upon:
 DEPDIRS-y += lib/librte_eal lib/librte_mempool lib/librte_ring lib/librte_mbuf
diff --git a/lib/librte_ether/rte_eth_features.h b/lib/librte_ether/rte_eth_features.h
new file mode 100644
index 0000000..983d7c6
--- /dev/null
+++ b/lib/librte_ether/rte_eth_features.h
@@ -0,0 +1,73 @@ 
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETH_FEATURES_H_
+#define _RTE_ETH_FEATURES_H_
+
+/**
+ * @file
+ *
+ * Ethernet device specific features
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Commands defined for NIC specific features */
+enum rte_eth_command {
+	RTE_CMD_UNKNOWN = 0,
+	/**< Unknown command */
+	RTE_CMD_GET_SYM_HASH_ENABLE_PER_PCTYPE,
+	/**< Get symmetric hash enable per pctype */
+	RTE_CMD_SET_SYM_HASH_ENABLE_PER_PCTYPE,
+	/**< Set symmetric hash enable per pctype */
+	RTE_CMD_GET_SYM_HASH_ENABLE_PER_PORT,
+	/**< Get symmetric hash enable per port */
+	RTE_CMD_SET_SYM_HASH_ENABLE_PER_PORT,
+	/**< Set symmetric hash enable per port */
+	RTE_CMD_GET_FILTER_SWAP,
+	/**< Get filter swap configurations */
+	RTE_CMD_SET_FILTER_SWAP,
+	/**< Set filter swap configurations */
+	RTE_CMD_GET_HASH_FUNCTION,
+	/**< Get hash function */
+	RTE_CMD_SET_HASH_FUNCTION,
+	/**< Set hash function */
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_ETH_FEATURES_H_ */
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index fd1010a..dfeb804 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3002,3 +3002,34 @@  rte_eth_dev_get_flex_filter(uint8_t port_id, uint16_t index,
 	return (*dev->dev_ops->get_flex_filter)(dev, index, filter,
 						rx_queue);
 }
+
+int
+rte_eth_dev_is_command_supported(uint8_t port_id, enum rte_eth_command cmd)
+{
+	struct rte_eth_dev *dev;
+
+	if (port_id >= nb_ports) {
+		PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
+		return -ENODEV;
+	}
+	dev = &rte_eth_devices[port_id];
+	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->is_command_supported, -ENOTSUP);
+	return (*dev->dev_ops->is_command_supported)(dev, cmd);
+}
+
+int
+rte_eth_dev_rx_classification_filter_ctl(uint8_t port_id,
+					 enum rte_eth_command cmd,
+					 void *args)
+{
+	struct rte_eth_dev *dev;
+
+	if (port_id >= nb_ports) {
+		PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
+		return -ENODEV;
+	}
+	dev = &rte_eth_devices[port_id];
+	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_classification_filter_ctl,
+								-ENOTSUP);
+	return (*dev->dev_ops->rx_classification_filter_ctl)(dev, cmd, args);
+}
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index dd36605..5c5d84e 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -177,6 +177,7 @@  extern "C" {
 #include <rte_pci.h>
 #include <rte_mbuf.h>
 #include "rte_ether.h"
+#include "rte_eth_features.h"
 
 /**
  * A structure used to retrieve statistics for an Ethernet port.
@@ -1240,6 +1241,15 @@  typedef int (*eth_mirror_rule_reset_t)(struct rte_eth_dev *dev,
 				  uint8_t rule_id);
 /**< @internal Remove a traffic mirroring rule on an Ethernet device */
 
+typedef int (*eth_is_command_supported_t)(struct rte_eth_dev *dev,
+					  enum rte_eth_command cmd);
+/**< @internal check if the command is supported by the Ethernet device */
+
+typedef int (*eth_rx_classification_filter_ctl_t)(struct rte_eth_dev *dev,
+						  enum rte_eth_command cmd,
+						  void *arg);
+/**< @internal receive classification filter control operations */
+
 #ifdef RTE_NIC_BYPASS
 
 enum {
@@ -1467,6 +1477,10 @@  struct eth_dev_ops {
 	eth_add_flex_filter_t          add_flex_filter;      /**< add flex filter. */
 	eth_remove_flex_filter_t       remove_flex_filter;   /**< remove flex filter. */
 	eth_get_flex_filter_t          get_flex_filter;      /**< get flex filter. */
+	eth_is_command_supported_t     is_command_supported;
+	/**< check if a command is supported. */
+	eth_rx_classification_filter_ctl_t rx_classification_filter_ctl;
+	/**< common control function of hw hash */
 };
 
 /**
@@ -3557,6 +3571,47 @@  int rte_eth_dev_remove_flex_filter(uint8_t port_id, uint16_t index);
 int rte_eth_dev_get_flex_filter(uint8_t port_id, uint16_t index,
 			struct rte_flex_filter *filter, uint16_t *rx_queue);
 
+/**
+ * Check if the command is supported by an Ethernet device. All the commands
+ * are defined in 'rte_eth_features.h'.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param cmd
+ *   The command.
+ *
+ * @return
+ *   - (> 0) The command is supported.
+ *   - (0) The command is not supported.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if <port_id> is invalid.
+ */
+int rte_eth_dev_is_command_supported(uint8_t port_id,
+				     enum rte_eth_command cmd);
+
+/**
+ * Configure the receive classification filter, including hash function
+ * selection. The commands are NIC specific in its exported public header
+ * file. Different types of NIC may have different commands.
+ * All the supported commands are defined in 'rte_eth_features.h'.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device.
+ * @param cmd
+ *   The command.
+ * @param args
+ *   A pointer to arguments defined specifically for the command.
+ *
+ * @return
+ *   - (0) if successful.
+ *   - (-ENOTSUP) if hardware doesn't support.
+ *   - (-ENODEV) if <port_id> is invalid.
+ *   - others depends on the specific command implementation.
+ */
+int rte_eth_dev_rx_classification_filter_ctl(uint8_t port_id,
+					     enum rte_eth_command cmd,
+					     void *args);
+
 #ifdef __cplusplus
 }
 #endif