From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 193382C06 for ; Fri, 20 Jan 2017 11:24:49 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP; 20 Jan 2017 02:24:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,258,1477983600"; d="scan'208";a="924722465" Received: from unknown (HELO localhost.localdomain.sh.intel.com) ([10.239.128.150]) by orsmga003.jf.intel.com with ESMTP; 20 Jan 2017 02:24:48 -0800 From: "Chen Jing D(Mark)" To: dev@dpdk.org Cc: keith.wiles@intel.com, gerald.rogers@intel.com, "Chen Jing D(Mark)" Date: Fri, 20 Jan 2017 11:21:38 +0800 Message-Id: <1484882498-18653-3-git-send-email-jing.d.chen@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1484882498-18653-1-git-send-email-jing.d.chen@intel.com> References: <1484882498-18653-1-git-send-email-jing.d.chen@intel.com> Subject: [dpdk-dev] [RFC 2/2] prgdev: introduce generic prgdev API X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jan 2017 10:24:50 -0000 A new file to define prgdev API prototype and corresponding data structures. Signed-off-by: Chen Jing D(Mark) --- lib/librte_prgdev/rte_prgdev.h | 242 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 242 insertions(+), 0 deletions(-) create mode 100644 lib/librte_prgdev/rte_prgdev.h 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_ */ -- 1.7.7.6