From patchwork Fri Jan 8 20:29:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 59400 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp755818lbb; Fri, 8 Jan 2016 11:48:30 -0800 (PST) X-Received: by 10.140.94.50 with SMTP id f47mr11628004qge.0.1452282510736; Fri, 08 Jan 2016 11:48:30 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k88si84059333qgf.120.2016.01.08.11.48.30; Fri, 08 Jan 2016 11:48:30 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 31DCA61783; Fri, 8 Jan 2016 19:48:30 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=PyKqbhHf; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,T_DKIM_INVALID,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 4A46B6195C; Fri, 8 Jan 2016 19:37:29 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 341806166E; Fri, 8 Jan 2016 19:34:20 +0000 (UTC) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com [209.85.217.176]) by lists.linaro.org (Postfix) with ESMTPS id 319CB61A30 for ; Fri, 8 Jan 2016 19:31:51 +0000 (UTC) Received: by mail-lb0-f176.google.com with SMTP id oh2so230054086lbb.3 for ; Fri, 08 Jan 2016 11:31:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5Kma1sgNZyPjGc3eOW/lGfnM9Am9yThN3eYR9JFIJYo=; b=PyKqbhHfoG/fFY+Xuu8+P/6ar6hT860ZHPbyDce6j7fJHo6F7TgxwWunZs1AVtUPRu e1AS1Z+KCWINEtmSNiXo0AsvMEdKLWeJkbxqL7GUeaFgyjzYIPzAE5MUeMiY6Cp/cLDT 9Xxpbc7qTMpMFTYn5hDHJF5MPmxTEduxKUaHs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5Kma1sgNZyPjGc3eOW/lGfnM9Am9yThN3eYR9JFIJYo=; b=RTP2OzgntVkzYDrUnvuM79ln+NYhpkrC8FxowDCaxvygdZ3haR/DUjNzX/vMPRifPd ZAxskSDqg2GSqYCernfCadhi47zKYGOeCBxM4GhCWmv/D3TvkLg/i/o3+hmpXhdCGjEF lUK58w8B3ZO5aYV/NKeuZLeQ7jC+CZPHjTbf8LlrVEyM9vOP8rgEfcXB2oaqUKqDhFOW ot92G3ZnsV9C51Crpv8fFXvo9qZHFtOIxDyJCWv8EHEW+0QuQWGSYlzK7Zpklvp9gW1R 9o6X6PcoICu6wOGr4LasHpRAz3diJVxk7d28tH6jVlVRqiv1rMK0zrvzgtLxauDHrMuZ IGMg== X-Gm-Message-State: ALoCoQnxKnjfAa1nQtIDIyGitHdMOxR67WaPeFPd4bgRPzFGtefJctdOrJm0dZrB2qqniPK/1LcK0bl/2e+7J57sdanOHcoptA== X-Received: by 10.112.200.229 with SMTP id jv5mr42095724lbc.23.1452281510146; Fri, 08 Jan 2016 11:31:50 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id l204sm2085534lfg.49.2016.01.08.11.31.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 11:31:49 -0800 (PST) From: Christophe Milard To: anders.roxell@linaro.org, mike.holmes@linaro.org, stuart.haslam@linaro.org, maxim.uvarov@linaro.org, bill.fischofer@linaro.org, petri.savolainen@linaro.org, edavis@broadcom.com Date: Fri, 8 Jan 2016 21:29:57 +0100 Message-Id: <1452285014-60320-15-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> References: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [API-NEXT RFC 14/31] driver api: registration and probing interface X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Defining the ODP functions used to register a nic driver (which includes the probing function prototype) Signed-off-by: Christophe Milard --- include/odp/api/nic.h | 117 +++++++++++++++++++++++++++++++ platform/linux-generic/include/odp/nic.h | 1 + 2 files changed, 118 insertions(+) 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 +#include +#include #include #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 #include #include +#include /** @ingroup odp_nic * @{