diff mbox

[API-NEXT,RFC,14/31] driver api: registration and probing interface

Message ID 1452285014-60320-15-git-send-email-christophe.milard@linaro.org
State New
Headers show

Commit Message

Christophe Milard Jan. 8, 2016, 8:29 p.m. UTC
Defining the ODP functions used to register a nic driver (which includes
the probing function prototype)

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>
---
 include/odp/api/nic.h                    | 117 +++++++++++++++++++++++++++++++
 platform/linux-generic/include/odp/nic.h |   1 +
 2 files changed, 118 insertions(+)
diff mbox

Patch

diff --git a/include/odp/api/nic.h b/include/odp/api/nic.h
index 3846608..4624e65 100644
--- a/include/odp/api/nic.h
+++ b/include/odp/api/nic.h
@@ -14,6 +14,8 @@ 
 #define ODP_API_NIC_H_
 
 #include <odp/api/dma.h>
+#include <odp/api/pci.h>
+#include <odp/api/shared_memory.h>
 #include <odp/api/pool.h>
 
 #ifdef __cplusplus
@@ -25,6 +27,121 @@  extern "C" {
  *  @{
  */
 
+typedef struct odp_nic_dev_t odp_nic_dev_t; /* forward declaration */
+
+/**
+ * A structure describing an ODP nic device driver.
+ * A pointer to such a structure must be passed to ODP by each
+ * driver at init time. This is done by the usage of the
+ * odp_eth_driver_register() OPD function which should be called at driver
+ * initalization time.
+ */
+typedef struct odp_nic_driver_t {
+	/**< Driver name. */
+	const char *name;
+	/**< Driver probe function. */
+	odp_nic_dev_t *(*probe)(odp_pci_dev_t pci_dev,
+				odp_pktio_t pktio,
+				odp_nic_sgmt_pool_t rx_sgmt_pool,
+				odp_nic_sgmt_pool_t tx_sgmt_pool);
+} odp_nic_driver_t;
+
+/*
+ * ODP function to register a driver
+ *
+ * @param driver a driver redscription structure (odp_eth_driver_t structure)
+ */
+void odp_nic_driver_register(odp_nic_driver_t *driver);
+
+/**
+ * Structure containing the functions exported by an Ethernet driver:
+ * When a pktio is opened on an interface, the driver probe function
+ * is called: If the driver can handle the device (depending on vendor_id
+ * and device_id), then, the driver will allocate a odp_nic_dev_t structure
+ * (calling odp_nic_dev_alloc) and fill it.
+ * The odp_nic_dev_ops_t structure defined below is a part of odp_nic_dev_t
+ * and describes the functions exported by the driver.
+ */
+
+typedef struct odp_nic_dev_ops_t {
+	int (*dev_start)(odp_nic_dev_t *dev);
+	int (*dev_set_link_up)(odp_nic_dev_t *dev);
+	int (*rx_queue_start)(odp_nic_dev_t *eth_dev,
+			      uint16_t queue_id);
+	int (*rx_queue_setup)(odp_nic_dev_t *eth_dev,
+			      odp_pci_dev_t pci_dev,
+			      uint16_t queue_idx,
+			      uint16_t nb_desc,
+			      odp_nic_sgmt_pool_t sgmt_pool);
+	int (*tx_queue_setup)(odp_nic_dev_t *eth_dev,
+			      odp_pci_dev_t pci_dev,
+			      uint16_t queue_idx,
+			      uint16_t nb_desc,
+			      odp_nic_sgmt_pool_t sgmt_pool);
+	void (*mac_get)(odp_nic_dev_t *dev,
+			void *mac_addr);
+	void (*unprobe)(odp_pci_dev_t pci_dev,
+			odp_nic_dev_t *nic_dev);
+} odp_nic_dev_ops_t;
+
+/**
+ * The data part, associated with each ethernet device:
+ * The structure defined below is a part of odp_nic_dev_t
+ * and describes the data related to the driver.
+ */
+typedef struct odp_nic_dev_data_t {
+	uint8_t port_id;   /**< Device port identifier. */
+	void *dev_private; /**< PMD-specific private data */
+	void **rx_queues;  /**< Array of pointers to RX queues. */
+	void **tx_queues;  /**< Array of pointers to TX queues. */
+	uint16_t nb_rx_queues; /**< Number of RX queues. */
+	uint16_t nb_tx_queues; /**< Number of TX queues. */
+
+} odp_nic_dev_data_t;
+
+/**
+ * The generic data structure associated with each NIC ethernet device.
+ * Allocated (by calling odp_nic_dev_alloc)
+ * and filled by the driver when successful probing occurs.
+ */
+typedef struct odp_nic_dev_t {
+	odp_shm_t data_shm;	   /**< private data shm handle */
+	odp_nic_dev_data_t *data;  /**< Pointer to device data */
+	/**< Pointer to driver receive function. */
+	uint16_t (*rx_pkt_burst)(void *rxq,
+				 odp_nic_sgmt_t *rx_sgmts,
+				 uint16_t nb_pkts);
+	/**< Pointer to driver transmit function. */
+	uint16_t (*tx_pkt_burst)(void *txq,
+				 odp_nic_sgmt_t *rx_sgmts,
+				 uint16_t nb_pkts);
+	/**< other functions exported by the driver */
+	const odp_nic_dev_ops_t *dev_ops;
+} odp_nic_dev_t;
+
+/**
+ * allocate a odp_nic_dev structure. Called by the driver probe function,
+ * when successful probing occurs. The driver then fills the contents of
+ * the empty odp_nic_dev_t structure returned by this function.
+ * @param unique_id		a string identifying uniquely the device, e.g.
+ *				a pci address.
+ * @param private_sz		Size of the private area to be allocated.
+ * @param nb_rxqueues		number of queues for receiving packets
+ * @param nb_txqueues		number of queues for transmitting packets
+ * @param pktio			the packetio handle this interface belongs to.
+ * @returns			a ptr to the allocated odp_nic_dev_t struct
+ *				or NULL
+ */
+odp_nic_dev_t *odp_nic_dev_alloc(const char *unique_id,
+				 int private_sz,
+				 int nb_rxqueues, int nb_txqueues,
+				 odp_pktio_t pktio);
+/**
+ * free an odp_nic_dev structure.
+ * @param nic_dev		Nic device to be freed
+ */
+void odp_nic_dev_free(odp_nic_dev_t *nic_dev);
+
 /**
  * @typedef odp_nic_sgmt_pool_t
  * A nic segment pool.
diff --git a/platform/linux-generic/include/odp/nic.h b/platform/linux-generic/include/odp/nic.h
index b991bc3..7688bee 100644
--- a/platform/linux-generic/include/odp/nic.h
+++ b/platform/linux-generic/include/odp/nic.h
@@ -21,6 +21,7 @@  extern "C" {
 #include <odp/dma.h>
 #include <odp/shared_memory.h>
 #include <odp/plat/nic_types.h>
+#include <odp/pci.h>
 
 /** @ingroup odp_nic
  *  @{