[dpdk-dev,RFC,2/2] prgdev: introduce generic prgdev API

Message ID 1484882498-18653-3-git-send-email-jing.d.chen@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel compilation success Compilation OK

Commit Message

Chen, Jing D Jan. 20, 2017, 3:21 a.m. UTC
  A new file to define prgdev API prototype and corresponding data
structures.

Signed-off-by: Chen Jing D(Mark) <jing.d.chen@intel.com>
---
 lib/librte_prgdev/rte_prgdev.h |  242 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 242 insertions(+), 0 deletions(-)
 create mode 100644 lib/librte_prgdev/rte_prgdev.h
  

Comments

Stephen Hemminger Feb. 8, 2017, 10:49 p.m. UTC | #1
On Fri, 20 Jan 2017 11:21:38 +0800
"Chen Jing D(Mark)" <jing.d.chen@intel.com> wrote:

> +struct rte_prg_dev_info {
> +	struct rte_pci_device *pci_dev; /**< Device PCI information. */

NAK

No new API should refer to PCI devices. We are trying to make all references
to devices generic. Crypto suceeded, ether is in process, but no new ones please.
  
Wiles, Keith Feb. 8, 2017, 11:06 p.m. UTC | #2
> On Feb 8, 2017, at 4:49 PM, Stephen Hemminger <stephen@networkplumber.org> wrote:
> 
> On Fri, 20 Jan 2017 11:21:38 +0800
> "Chen Jing D(Mark)" <jing.d.chen@intel.com> wrote:
> 
>> +struct rte_prg_dev_info {
>> +	struct rte_pci_device *pci_dev; /**< Device PCI information. */
> 
> NAK
> 
> No new API should refer to PCI devices. We are trying to make all references
> to devices generic. Crypto suceeded, ether is in process, but no new ones please.

The design is not PCI centric and should not be PCI centric, it is just what they started with months ago. So please look past the PCI bits as they have not integrated into the latest code base yet.

Regards,
Keith
  
Chen, Jing D Feb. 9, 2017, 2:23 a.m. UTC | #3
Hi, Keith, Stephen,

> -----Original Message-----
> From: Wiles, Keith
> Sent: Thursday, February 9, 2017 7:07 AM
> To: Stephen Hemminger <stephen@networkplumber.org>
> Cc: Chen, Jing D <jing.d.chen@intel.com>; dev@dpdk.org; Rogers, Gerald
> <gerald.rogers@intel.com>
> Subject: Re: [dpdk-dev] [RFC 2/2] prgdev: introduce generic prgdev API
> 
> 
> > On Feb 8, 2017, at 4:49 PM, Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> >
> > On Fri, 20 Jan 2017 11:21:38 +0800
> > "Chen Jing D(Mark)" <jing.d.chen@intel.com> wrote:
> >
> >> +struct rte_prg_dev_info {
> >> +	struct rte_pci_device *pci_dev; /**< Device PCI information. */
> >
> > NAK
> >
> > No new API should refer to PCI devices. We are trying to make all
> > references to devices generic. Crypto suceeded, ether is in process, but no
> new ones please.
> 
> The design is not PCI centric and should not be PCI centric, it is just what they
> started with months ago. So please look past the PCI bits as they have not
> integrated into the latest code base yet.
> 

I got you. Will remove the reference in formal patch.
  

Patch

diff --git a/lib/librte_prgdev/rte_prgdev.h b/lib/librte_prgdev/rte_prgdev.h
new file mode 100644
index 0000000..849aba4
--- /dev/null
+++ b/lib/librte_prgdev/rte_prgdev.h
@@ -0,0 +1,242 @@ 
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016-2017 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_PRGDEV_H_
+#define _RTE_PRGDEV_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * reflect the device status
+ */
+enum rte_prg_devstat {
+	RTE_PRGDEV_STAT_UNKNOWN = 0,  /** Device in a unkown state */
+	RTE_PRGDEV_STAT_READY,   /** Device is ready to be programming. */
+	RTE_PRGDEV_STAT_ERASING, /** Device is ready being programmed. */
+	/** Device is performing functionalities and can't be programmed. */
+	RTE_PRGDEV_STAT_RUNNING,
+};
+
+/* Reflect the function block attributes */
+/* Block is readable */
+#define RTE_PGR_FUNC_ATTR_RD	0x00000001
+/* Block is writable */
+#define RTE_PGR_FUNC_ATTR_WR	0x00000002
+/* Block is readable and writable */
+#define RTE_PGR_FUNC_ATTR_RDWR	(RTE_PGR_FUNC_ATTR_RD & RTE_PGR_FUNC_ATTR_WR)
+
+struct rte_prg_blk_info {
+	unsigned int size;     /* the block size in bytes */
+	unsigned int version;  /* It's optional */
+	unsigned int flags;    /* Flags to indicate block isreadable/writable */
+};
+
+#define MAX_SIGNATURE_LEN	256
+#define MAX_BLK_NUM		256
+
+struct rte_prg_dev_info {
+	struct rte_pci_device *pci_dev; /**< Device PCI information. */
+	const char *driver_name; /**< Device Driver name. */
+	unsigned int devid; /**< Index to bound host interface, or 0 if none. */
+	/* Programable device HW version number. it's possible that app 
+	 *  have dependency to HW version.
+	 */
+	uint16_t hw_ver_major;  /* major version number */
+	uint16_t hw_ver_minor;  /* minor version number */
+
+	/* A array to store hardware, firmware, running image info.Each device
+  	 * can define and interpret the info. For example, a device can define 
+  	 * byte[3:0] as signature for on-die personality, byte[5:4] is the major
+  	 * version, byte[7:6] is minor version. if 0xFFEA1000 is a signature for
+  	 * virtio personality, major version is 0x0001, minor version is 0x0004.
+  	 * then signature can be defined :
+	 * sig_num = 8;
+	 * signature[7:0]= {00, 0x10, 0xEA, 0xFF, 0x00, 0x01, 0x00, 0x04};
+	 */
+	unsigned int sig_num;  /** < the valid signature length in bytes> */
+	char signature[MAX_SIGNATURE_LEN];
+	enum rte_prg_devstat status;
+
+	/* number of blocks within device */
+	unsigned int blk_num;
+	/* block info */
+	struct rte_prg_blk_info blk_info[MAX_BLK_NUM];
+};
+
+struct rte_prg_dev {
+        struct rte_prg_dev_info  prg_dev_info;
+} __rte_cache_aligned;
+
+/*
+*     prg_dev_init routine
+*
+*     returns : 0 success, non zero failure.
+*/
+
+typedef int (*prg_dev_init_t)(struct rte_prg_dev *prg_dev);
+
+/*
+*     prg_dev_uninit routine
+*
+*     returns : 0 success, non zero failure.
+*/
+
+
+typedef int (*prg_dev_uninit_t)(struct rte_prg_dev *prg_dev);
+
+/**
+ *  @internal
+ *  The structure associated with a programmable driver.
+ *
+ *  Each prg driver acts as a PCI driver and is represented by a generic
+ *  eth_driver* structure that holds:
+ *
+ *  - An *rte_pci_driver* structure (which must be the first field).
+ *
+ * -  The *prg_dev_init_t* function invoked for each matching PCI device.
+ *
+ * - The *prg_dev_remove* function invoked for each matching PCI device.
+ *
+ *  - The size of the private data to allocate for each matching device.
+ */
+
+struct prg_driver {
+	struct rte_pci_driver pci_drv;    /**< The PRG is also a PCI driver. */
+	prg_dev_init_t prg_dev_probe;      /**< Device probe function. */
+	prg_dev_uninit_t prg_dev_remove;  /**< Device remove function. */
+	unsigned int dev_private_size;    /**< Size of device private data. */
+};
+
+
+/*
+*  Query what personality is in the device.
+*
+*  @param device_id
+*   The port identifier of the programmable device.
+*  @param info
+*   A pointer to a structure of type *rte_prg_dev_info* to be filled with
+*   the information of the programmable device.
+*/
+
+int rte_prgdev_get_info(uint8_t device_id,
+			struct rte_prg_dev_info *info);
+
+/* 
+*  Open device for programming, acquiring on-die image, etc. 
+*  Need to call this function first 
+*  prior to calling other functionalities.
+*  In case the device is performing some tasks, it's device's decision on 
+*  what result is returned.
+*/
+
+int rte_prgdev_open(uint8_t device_id);
+
+
+/*
+* Download image from host to programmable device.
+*
+* @param device_id
+*   The port identifier of the programmable device.
+* @param buffer_ptr
+*   A pointer to a buffer that stored the image ready downloading to device
+* @param buf_len
+*   the total image length in bytes.
+*/
+
+int rte_prgdev_img_download(uint8_t device_id,
+			uint8_t *buffer_ptr, uint32_t buf_len);
+
+/*
+* Upload image from programmable device to host.
+*
+* @param device_id
+*   The port identifier of the programmable device.
+* @param buffer_ptr
+*   A pointer to a buffer that store uploaded image
+* @param buf_len
+*   the total buffer length in bytes.
+* @param act_len
+*   pointer to the actual image length in bytes.
+*/
+
+int rte_prgdev_img_upload(uint8_t device_id, uint8_t *buffer_ptr,
+		uint32_t buf_len,uint32_t *act_len);
+
+/*
+ * reflect the device status
+ */
+
+enum rte_prg_fwstat {
+	RTE_PRGDEV_FWSTAT_OK = 0,  /** Image are running well */
+	RTE_PRGDEV_FWSTAT_ERR = -1,   /** Image has error. */
+	RTE_PRGDEV_FWSTAT_ERR_VALID = -2, /** Image is not valid. */
+	RTE_PRGDEV_FWSTAT_ERR_CKSUM = -3, /** Image checksum is not correct. */
+	RTE_PRGDEV_FWSTAT_ERR_LEN = -4, /** Image length is not correct. */
+};
+
+/*
+*  Check if the downloaded image running on die works in expected way, optional 
+*   function.
+* @param device_id
+*   The port identifier of the programmable device.
+*/
+int rte_prgdev_check_stat(uint8_t device_id, enum rte_prg_fwstat *stat);
+
+/*
+* Called to free up resources or whatever to do to hardware
+* after an erase or load of the program.
+* @param device_id
+*   The port identifier of the programmable device.
+*/
+int rte_prgdev_close(uint8_t device_id);
+
+/*
+* Called to bind a programmable device to drivers after close function is called.
+* @param device_id
+*   The port identifier of the programmable device.
+*/
+int rte_prgdev_bind(uint8_t device_id);
+/*
+* Called to unbind all functions except prgdev from drivers.
+* @param device_id
+*   The port identifier of the programmable device.
+*/
+rte_prgdev_unbind(uint8_t device_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_PRGDEV_H_ */