From patchwork Fri Jan 8 20:29:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 59401 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp756228lbb; Fri, 8 Jan 2016 11:49:32 -0800 (PST) X-Received: by 10.140.102.11 with SMTP id v11mr142551108qge.39.1452282572460; Fri, 08 Jan 2016 11:49:32 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id a7si18977664qkb.126.2016.01.08.11.49.32; Fri, 08 Jan 2016 11:49:32 -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 09DBC61640; Fri, 8 Jan 2016 19:49:32 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=S9teX5nK; 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_H3, RCVD_IN_MSPIKE_WL, 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 E06DA619D8; Fri, 8 Jan 2016 19:37:32 +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 D31356166B; Fri, 8 Jan 2016 19:34:20 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id 7C00C6167C for ; Fri, 8 Jan 2016 19:31:52 +0000 (UTC) Received: by mail-lf0-f49.google.com with SMTP id d17so15376771lfb.1 for ; Fri, 08 Jan 2016 11:31:52 -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=6Lr1ugN7ZxdXq5hCg5aoD8eAelheiKhLmq7MPOzDRgg=; b=S9teX5nKNvH04/O0QigWXOrKtq8RN3ptkQDSFnFWDaGJu0NJYVXCk6GuMiMl9LapWn lc5fctZE+ThQ3hIfIjcjovtKnmPZaov12fhdPt+T+h34aG0nXTr7jxXBiAYgbvzBo4Bb Cv++hRuoN4JuZG/0c9u4l9BkPKjuAdeup+YSM= 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=6Lr1ugN7ZxdXq5hCg5aoD8eAelheiKhLmq7MPOzDRgg=; b=k+JFXJKrw1NJ3zBWbZG9v+yJHRlqreh8pNBMhvytPMWVX9/IigzouR3Vjmf43g3+4d LrWhKd/a1R84bci+gtzHljp4vwheBt/Ffpm+Wki23ozDUzQ8odJn6rczg9swTFSjy7aE cUHzkNqk920jRkpZzMqkjQRVpZrcxuYePV5H3dxRgo6WjOI0IWS/bxT5Ti3bxYXeDsnZ 5BEeDXe7GcnEhXX2a8MHOZ0M9hzeOP/QnJfy7cJO9tszcP+wtnKPmHs5HVpxaNfGHH1R SuosxgXNPrkfiYkmMfJ3Qk0xMIuVVrb85RLcKadAbFj2g1Lyehmxn62LQqOJk2H3jkpk VTIA== X-Gm-Message-State: ALoCoQmNMLcmK6h31Hd3/RavKkBCmF+iAW9Bpauy7AkCq7I+Wwu+rNwyvCd7GtPVgjlR8mrUM2ycQ418V31m/INsL5EqXVIpJg== X-Received: by 10.25.5.205 with SMTP id 196mr37515750lff.143.1452281511445; Fri, 08 Jan 2016 11:31:51 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 11:31:50 -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:58 +0100 Message-Id: <1452285014-60320-16-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 15/31] linux-generic: driver registration implementation 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" The NIC driver table is defined here, as well as the registration function called by each driver at init time. Signed-off-by: Christophe Milard --- platform/linux-generic/include/odp_internal.h | 2 ++ platform/linux-generic/odp_init.c | 5 +++ platform/linux-generic/odp_nic.c | 49 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 49e23d9..3aa395f 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -76,6 +76,8 @@ int odp_schedule_term_global(void); int odp_schedule_init_local(void); int odp_schedule_term_local(void); +int odp_nic_init_local(void); + int odp_timer_init_global(void); int odp_timer_disarm_all(void); diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index d93dab8..a06c99a 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -157,6 +157,11 @@ int odp_init_local(odp_thread_type_t thr_type) return -1; } + if (odp_nic_init_local()) { + ODP_ERR("ODP nic local init failed.\n"); + return -1; + } + return 0; } diff --git a/platform/linux-generic/odp_nic.c b/platform/linux-generic/odp_nic.c index 0cd1c19..8a4cd43 100644 --- a/platform/linux-generic/odp_nic.c +++ b/platform/linux-generic/odp_nic.c @@ -7,6 +7,27 @@ #include #include #include +#include + +#ifdef WITH_DRIVERS +#include +#endif + +odp_spinlock_t drv_registration_mutex; + +/* + * registered drivers: + * Because at registration time, drivers give function pointers (whose + * scope is linux process) the scope of the following table is a process: + * This table will be shared between ODP threads when implemented as linux + * threads, but will be "duplicated" when ODP threads are processes + */ +#define MAX_DRIVERS 10 +struct { + uint16_t nb_drivers; /* number of registered drivers */ + odp_nic_driver_t drivers[MAX_DRIVERS]; /* drivers */ +} registered_drv; + /* operations on NIC segments pools: */ odp_nic_sgmt_pool_t odp_nic_sgmt_pool_create(odp_pool_t pool_hdl) @@ -161,3 +182,31 @@ void odp_nic_sgmt_set_last(odp_nic_sgmt_t segmt) pkt_hdr = odp_packet_hdr((odp_packet_t)segmt); packet_parse_l2(pkt_hdr); } + +/* initialisation and driver registration functions */ + +int odp_nic_init_local(void) +{ +#ifdef WITH_DRIVERS + /* + * when ODP threads are linux threads, + * prevent multiple or overlapping driver registration + */ + odp_spinlock_lock(&drv_registration_mutex); + + if (registered_drv.nb_drivers == 0) + _odp_driver_init(); + odp_spinlock_unlock(&drv_registration_mutex); + + ODP_DBG("%d drivers initialised\n", registered_drv.nb_drivers); +#endif + return 0; +} + +void odp_nic_driver_register(odp_nic_driver_t *drv) +{ + if (registered_drv.nb_drivers < MAX_DRIVERS - 1) + registered_drv.drivers[registered_drv.nb_drivers++] = *drv; + else + ODP_ERR("Maximum number of drivers exceeded... "); +}