From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0051.outbound.protection.outlook.com [104.47.34.51]) by dpdk.org (Postfix) with ESMTP id C47211B2BA for ; Fri, 16 Feb 2018 22:37:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=YfQ/diysNoFNaf7BEbxS4erY8l8zgz3rligM6+qtUEU=; b=d8MaZK5/AB9IAS1twHoIZMz/23+fDoazJcmjPzdZXxTDgLZSx70IMMeJTwD3U8j3T9HHVnaEM1SOREFBx4QdfomP6+VgnppqClzRX+vhghoAssJt2/QgUAPMaQ9YGkmLiDe5klProGWT7RcpgegXDDphy6OHz9xkklwODY14YJc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; Received: from localhost.localdomain (111.93.218.67) by DM5PR07MB3467.namprd07.prod.outlook.com (2603:10b6:4:67::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.506.18; Fri, 16 Feb 2018 21:37:41 +0000 From: Pavan Nikhilesh To: jerin.jacob@caviumnetworks.com, santosh.shukla@caviumnetworks.com, erik.g.carrillo@intel.com Cc: dev@dpdk.org, Pavan Nikhilesh Date: Sat, 17 Feb 2018 03:06:54 +0530 Message-Id: <20180216213700.3415-5-pbhagavatula@caviumnetworks.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180216213700.3415-1-pbhagavatula@caviumnetworks.com> References: <20180216213700.3415-1-pbhagavatula@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: SG2PR01CA0090.apcprd01.prod.exchangelabs.com (2603:1096:3:15::16) To DM5PR07MB3467.namprd07.prod.outlook.com (2603:10b6:4:67::22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b68100c2-b229-4b48-b6bc-08d57585834f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:DM5PR07MB3467; X-Microsoft-Exchange-Diagnostics: 1; DM5PR07MB3467; 3:jDw++yfDrIBMAnskk5DPrd9gqYrgrgTYufTlKP176hJiXfhGPHfgIiMRI6G99qegwhIuYqq4GKS3+ZawQrTDNaTijHEM3ehVDcVH9ozt5cRZD05R/efyPvcoW1Pot/Xq46yVfgwvow7Sbu97QsYDXs0I0tUQBwL7LJ2zgIbwpX673nBw+dpnI/WVt/TlRb0jlZdUN64R2ZzTEka7B6egO0zK4bd0bfTlkTpFEGcUUSRCp1xhh2J6yggvR87yeDZq; 25:rfcPqFkzFAV8k0/hXt6BcRbGTAdkUIXg/jnj0SGwfX6OKJU370UGJu0HVmFTLILY54j8gXlTPCShaR5Sfq+ygSXl9OTtw5py1FYJZBR5Ewu7GKy6vsnQRonUKIU16kBkNaK9+ze8xCoa2UQZGmobHHAHxvtGHoVegpf5FCR5fgIa/cclpCTsJHdunvn51Kc1Osd9BYZ7/j7M3QmRY1cQLfNRI/+kki2T99AggxTlzu4H24KoSBl3G6ub+xvvOs7e/KIYdKsbjSxzEk6jFNsG6Mz/gZg+OT4kGxMzj+CpjKZhy4bgxfx9o8ZjzqR2wQJvNePe1abFjqII7b4Xn2rfaA==; 31:9uSJ4SPegiR9S7CqvP01ZvBaBDMk3LFPDY47RdSmwGJ/NXzSfVfY/8fIDp3OI8Tv1IEYU2hG2LFfnlKy2ST37v4wAGTOtC6VrBtsjhuj3IAii9rzzNy/tEgYiGMZs0g2fpRUWq7yTFi98AR75Kj1ybVbd+E+kNb2TxjJ7Su341qrGSI2n998+mml3dy3heGjxoI2DBaH7Te8DAtJAWsmArv70/TVGN2UFjZHDZaKHrg= X-MS-TrafficTypeDiagnostic: DM5PR07MB3467: X-Microsoft-Exchange-Diagnostics: 1; DM5PR07MB3467; 20:OdmhtXWtvdXPwR3GmyUlnFaZ2I2/x6C/G/j4TK6loZ9b2v2Mz8U38Re3K5OMvOsHhajpO/jQVVtstN0m+vGv82hPNlpmhWElEUQluAkZM5T0babPSKTrHCGw4QYCiSNqTOfxpH/jSgIafAG0uTaWPaWN0MK5xhEm41XwJ8SkSr7hB+F3+eEBo/kzpQ73aTjxaWHZqRRxmSrGcLhCu5RZHmT2XTHx7JOkDOOc/4woSn9TXJ5i8uJOMKuQBVSfpaMA53CLyk5L7Cks+wIXgoW0QiMCUe6OUTHSl/4STanpSlTskG2K0DQ+E8pjK6rsB4GkK2eBmL0q3dkl50Gh7wvq1NfkdSgZbNJgPOFXPjwYRfJ132rrR7g2uDZ4jskwf0wdViQTGnOrmB2PNpRaOOO3cV0D9Jgtf3DDYmq8diSTo9DOlFYFJ799SStrGZvGgX6AOb9xUEWO7o5JcK1lPwlNV0x0g8o+V3NaUwQzlkn/SldYxyHKgxLzd/KOCnnHiLT5v5+AoZw3Xn5XF5wbGZBWzdwRz9ITU0R1GvvN0QTvdmKgVLR3qnGvb5tg7P/0RcD0YHVWz26DI7L/r267roiBCd21ETOoQWdG0J3RuiYTQFc=; 4:uyqrIPQtCH4oAgwyqPYRvg+Cwt/Llc2Xl+ssapz1feaDdxeuGSKldiJyAXAvTqnBEwBPbdkDk9JTmlUUeC15g03rOP1Z7A3nlowA6WOlL1DHMXDB/+sSyA2zLhMH07hIkvS7Id+6wV1rcdGAlOk2o+KzmJxle+XGXPhCwTPiEmvKCQgXXLjpfRvt3XmWUzpDpuawUrX691OyZYaOb9sD0EJdGklWCwX9yAYTgRZ8gzKmDAZQ2ybfnpM/Ozv/xmG//ODZ72TXPuorAoNTHa3RRg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(10201501046)(3231101)(944501161)(93006095)(3002001)(6041288)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(6072148)(201708071742011); SRVR:DM5PR07MB3467; BCL:0; PCL:0; RULEID:; SRVR:DM5PR07MB3467; X-Forefront-PRVS: 0585417D7B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(346002)(366004)(396003)(39860400002)(39380400002)(376002)(189003)(199004)(6486002)(25786009)(2950100002)(386003)(6506007)(53936002)(42882006)(5009440100003)(4326008)(107886003)(6666003)(59450400001)(6512007)(16586007)(106356001)(316002)(105586002)(36756003)(478600001)(2906002)(47776003)(6116002)(76176011)(3846002)(1076002)(97736004)(66066001)(8676002)(51416003)(50466002)(48376002)(81156014)(5660300001)(68736007)(8936002)(52116002)(16526019)(26005)(305945005)(1857600001)(72206003)(81166006)(50226002)(7736002)(42262002)(473944003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR07MB3467; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR07MB3467; 23:LH88wo2uYvVNoUB5LYO7dNv8hRHGzrlMUHiOt863k?= =?us-ascii?Q?ugwx659v1F9V3k2cib0Kjk5njY+o9jofUi8VUEmaKUyxUrOYIjzcQ8uhfNJH?= =?us-ascii?Q?4fUYac1Qo1bt3YIPSlZTk5C/MNlP1wuOUBUA4fiHeyGR2fbrcZYSVWKmXJFM?= =?us-ascii?Q?pPM1q0UpoHntCh96gHWuG0+oeG4gNCjmGrmWyyM2GWr4Z0CvZnwzetzEgKp/?= =?us-ascii?Q?1Jm+AI6prhX28gERKKmIffMVVrTIqh8eQWgZxTxexvW1/rgSZSkUONEBjT/1?= =?us-ascii?Q?9CAOZ+Q/pPFXErzXhLu2mVukrA3FZRKepYAWq1gD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pamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2018 21:37:41.8182 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b68100c2-b229-4b48-b6bc-08d57585834f X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR07MB3467 Subject: [dpdk-dev] [PATCH 04/10] event/octeontx: add support to start and stop timer device 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, 16 Feb 2018 21:37:46 -0000 When application requests to start the timer adapter through `rte_event_timer_adapter_start`, Octeontx TIMvf ring does the following: - Uses mbox to communicate TIMpf driver about, * SCLK frequency used to convert ns<->cycles. * program the ring control parameters and start the ring. * get the exact cycle at which the TIMvf ring has started which can be used to estimate the bucket position. On `rte_event_timer_adapter_stop` i.e stop, Octeontx TIMvf ring does the following: - Use mbox to communicate TIMpf driver about, * reset the ring control parameters and stop the ring. Signed-off-by: Pavan Nikhilesh --- drivers/event/octeontx/timvf_evdev.c | 140 +++++++++++++++++++++++++++++++++++ drivers/event/octeontx/timvf_evdev.h | 5 ++ 2 files changed, 145 insertions(+) diff --git a/drivers/event/octeontx/timvf_evdev.c b/drivers/event/octeontx/timvf_evdev.c index a56ca7e71..dccdf1ddb 100644 --- a/drivers/event/octeontx/timvf_evdev.c +++ b/drivers/event/octeontx/timvf_evdev.c @@ -16,6 +16,32 @@ otx_timvf_init_log(void) rte_log_set_level(otx_logtype_timvf, RTE_LOG_NOTICE); } +struct __rte_packed timvf_mbox_dev_info { + uint64_t ring_active[4]; + uint64_t clk_freq; +}; + +/* Response messages */ +enum { + MBOX_RET_SUCCESS, + MBOX_RET_INVALID, + MBOX_RET_INTERNAL_ERR, +}; + +static int +timvf_mbox_dev_info_get(struct timvf_mbox_dev_info *info) +{ + struct octeontx_mbox_hdr hdr = {0}; + uint16_t len = sizeof(struct timvf_mbox_dev_info); + + hdr.coproc = TIM_COPROC; + hdr.msg = TIM_GET_DEV_INFO; + hdr.vfid = 0; /* TIM DEV is always 0. TIM RING ID changes. */ + + memset(info, 0, len); + return octeontx_ssovf_mbox_send(&hdr, NULL, 0, info, len); +} + static void timvf_ring_info_get(const struct rte_event_timer_adapter *adptr, struct rte_event_timer_adapter_info *adptr_info) @@ -27,6 +53,118 @@ timvf_ring_info_get(const struct rte_event_timer_adapter *adptr, sizeof(struct rte_event_timer_adapter_conf)); } +static int +timvf_ring_conf_set(struct timvf_ctrl_reg *rctl, uint8_t ring_id) +{ + struct octeontx_mbox_hdr hdr = {0}; + uint16_t len = sizeof(struct timvf_ctrl_reg); + int ret; + + hdr.coproc = TIM_COPROC; + hdr.msg = TIM_SET_RING_INFO; + hdr.vfid = ring_id; + + ret = octeontx_ssovf_mbox_send(&hdr, rctl, len, NULL, 0); + if (ret < 0 || hdr.res_code != MBOX_RET_SUCCESS) + return -EACCES; + return 0; +} + +static int +timvf_get_start_cyc(uint64_t *now, uint8_t ring_id) +{ + struct octeontx_mbox_hdr hdr = {0}; + + hdr.coproc = TIM_COPROC; + hdr.msg = TIM_RING_START_CYC_GET; + hdr.vfid = ring_id; + *now = 0; + return octeontx_ssovf_mbox_send(&hdr, NULL, 0, now, sizeof(uint64_t)); +} + +static int +timvf_ring_start(const struct rte_event_timer_adapter *adptr) +{ + int ret; + uint64_t interval = 0; + struct timvf_ctrl_reg rctrl = {0}; + struct timvf_mbox_dev_info dinfo; + struct timvf_ring *timr = adptr->data->adapter_priv; + + ret = timvf_mbox_dev_info_get(&dinfo); + if (ret < 0 || ret != sizeof(struct timvf_mbox_dev_info)) + return -EINVAL; + + /* Calculate the interval cycles according to clock source. */ + switch (timr->clk_src) { + case TIM_CLK_SRC_SCLK: + interval = NSEC2CLK(timr->tck_nsec, dinfo.clk_freq); + break; + case TIM_CLK_SRC_GPIO: + /* GPIO doesn't work on tck_nsec. */ + interval = 0; + break; + case TIM_CLK_SRC_GTI: + interval = NSEC2CLK(timr->tck_nsec, dinfo.clk_freq); + break; + case TIM_CLK_SRC_PTP: + interval = NSEC2CLK(timr->tck_nsec, dinfo.clk_freq); + break; + } + + /*CTRL0 register.*/ + rctrl.rctrl0 = interval; + + /*CTRL1 register.*/ + rctrl.rctrl1 = (uint64_t)(timr->clk_src) << 51 | + 1ull << 48 | + 1ull << 47 | + 1ull << 44 | + (timr->meta.nb_bkts - 1); + + rctrl.rctrl2 = (uint64_t)(TIM_CHUNK_SIZE / 16) << 40; + + timvf_write64((uint64_t)timr->meta.bkt, + (uint8_t *)timr->vbar0 + TIM_VRING_BASE); + if (timvf_ring_conf_set(&rctrl, timr->tim_ring_id)) { + ret = -EACCES; + goto error; + } + + if (timvf_get_start_cyc(&timr->meta.ring_start_cyc, + timr->tim_ring_id) < 0) { + ret = -EACCES; + goto error; + } + timr->meta.tck_int = NSEC2CLK(timr->tck_nsec, rte_get_timer_hz()); + timr->meta.fast_div = rte_reciprocal_value_u64(timr->meta.tck_int); + timvf_log_info("nb_bkts %d min_ns %"PRIu64" min_cyc %"PRIu64"" + " maxtmo %"PRIu64"\n", + timr->meta.nb_bkts, timr->tck_nsec, interval, + timr->max_tout); + + return 0; +error: + rte_free(timr->meta.bkt); + rte_mempool_free(timr->meta.chunk_pool); + return ret; +} + +static int +timvf_ring_stop(const struct rte_event_timer_adapter *adptr) +{ + struct timvf_ring *timr = adptr->data->adapter_priv; + struct timvf_ctrl_reg rctrl = {0}; + rctrl.rctrl0 = timvf_read64((uint8_t *)timr->vbar0 + TIM_VRING_CTL0); + rctrl.rctrl1 = timvf_read64((uint8_t *)timr->vbar0 + TIM_VRING_CTL1); + rctrl.rctrl1 &= ~(1ull << 47); /* Disable */ + rctrl.rctrl2 = timvf_read64((uint8_t *)timr->vbar0 + TIM_VRING_CTL2); + + if (timvf_ring_conf_set(&rctrl, timr->tim_ring_id)) + return -EACCES; + return 0; +} + static int timvf_ring_create(struct rte_event_timer_adapter *adptr) { @@ -145,6 +283,8 @@ timvf_ring_free(struct rte_event_timer_adapter *adptr) static struct rte_event_timer_adapter_ops timvf_ops = { .init = timvf_ring_create, .uninit = timvf_ring_free, + .start = timvf_ring_start, + .stop = timvf_ring_stop, .get_info = timvf_ring_info_get, }; diff --git a/drivers/event/octeontx/timvf_evdev.h b/drivers/event/octeontx/timvf_evdev.h index fcc938b82..a6a64587f 100644 --- a/drivers/event/octeontx/timvf_evdev.h +++ b/drivers/event/octeontx/timvf_evdev.h @@ -74,6 +74,11 @@ #define TIM_VRING_AURA (0x108) #define TIM_VRING_REL (0x110) + +#define NSEC_PER_SEC 1E9 +#define NSEC2CLK(__ns, __freq) (((__ns) * (__freq)) / NSEC_PER_SEC) +#define CLK2NSEC(__clk, __freq) (((__clk) * NSEC_PER_SEC) / (__freq)) + #define timvf_read64 rte_read64_relaxed #define timvf_write64 rte_write64_relaxed -- 2.16.1