Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/8605/?format=api
https://patches.dpdk.org/api/patches/8605/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1446568728-12220-4-git-send-email-danielx.t.mrzyglod@intel.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1446568728-12220-4-git-send-email-danielx.t.mrzyglod@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1446568728-12220-4-git-send-email-danielx.t.mrzyglod@intel.com", "date": "2015-11-03T16:38:44", "name": "[dpdk-dev,v3,3/7] ixgbe: add additional ieee1588 support functions", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "676e8f96a7b670cc44fbb3b8de0e6a5b4e8c2db9", "submitter": { "id": 23, "url": "https://patches.dpdk.org/api/people/23/?format=api", "name": "Daniel Mrzyglod", "email": "danielx.t.mrzyglod@intel.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1446568728-12220-4-git-send-email-danielx.t.mrzyglod@intel.com/mbox/", "series": [], "comments": "https://patches.dpdk.org/api/patches/8605/comments/", "check": "pending", "checks": "https://patches.dpdk.org/api/patches/8605/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@dpdk.org", "Delivered-To": "patchwork@dpdk.org", "Received": [ "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 19C738E9A;\n\tTue, 3 Nov 2015 17:44:01 +0100 (CET)", "from mga02.intel.com (mga02.intel.com [134.134.136.20])\n\tby dpdk.org (Postfix) with ESMTP id 8EA5D8E95\n\tfor <dev@dpdk.org>; Tue, 3 Nov 2015 17:43:59 +0100 (CET)", "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby orsmga101.jf.intel.com with ESMTP; 03 Nov 2015 08:43:32 -0800", "from unknown ([10.217.248.15])\n\tby orsmga002.jf.intel.com with SMTP; 03 Nov 2015 08:43:23 -0800", "by (sSMTP sendmail emulation); Tue, 03 Nov 2015 17:42:19 +0100" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.20,239,1444719600\"; d=\"scan'208\";a=\"841649442\"", "From": "Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>", "To": "dev@dpdk.org", "Date": "Tue, 3 Nov 2015 17:38:44 +0100", "Message-Id": "<1446568728-12220-4-git-send-email-danielx.t.mrzyglod@intel.com>", "X-Mailer": "git-send-email 2.1.4", "In-Reply-To": "<1446568728-12220-1-git-send-email-danielx.t.mrzyglod@intel.com>", "References": "<1443799208-9408-1-git-send-email-danielx.t.mrzyglod@intel.com>\n\t<1446568728-12220-1-git-send-email-danielx.t.mrzyglod@intel.com>", "Subject": "[dpdk-dev] [PATCH v3 3/7] ixgbe: add additional ieee1588 support\n\tfunctions", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "patches and discussions about DPDK <dev.dpdk.org>", "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://dpdk.org/ml/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "Add additional functions to support the existing IEEE1588\nfunctionality and to enable getting, setting and adjusting\nthe device time.\n\nSigned-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>\nSigned-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>\n---\n drivers/net/ixgbe/ixgbe_ethdev.c | 272 +++++++++++++++++++++++++++++++++++++--\n drivers/net/ixgbe/ixgbe_ethdev.h | 3 +\n 2 files changed, 264 insertions(+), 11 deletions(-)", "diff": "diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c\nindex 52c2fdb..595d75c 100644\n--- a/drivers/net/ixgbe/ixgbe_ethdev.c\n+++ b/drivers/net/ixgbe/ixgbe_ethdev.c\n@@ -126,10 +126,17 @@\n #define IXGBE_HKEY_MAX_INDEX 10\n \n /* Additional timesync values. */\n-#define IXGBE_TIMINCA_16NS_SHIFT 24\n-#define IXGBE_TIMINCA_INCVALUE 16000000\n-#define IXGBE_TIMINCA_INIT ((0x02 << IXGBE_TIMINCA_16NS_SHIFT) \\\n-\t\t\t\t | IXGBE_TIMINCA_INCVALUE)\n+#define NSEC_PER_SEC 1000000000L\n+#define IXGBE_INCVAL_10GB 0x66666666\n+#define IXGBE_INCVAL_1GB 0x40000000\n+#define IXGBE_INCVAL_100 0x50000000\n+#define IXGBE_INCVAL_SHIFT_10GB 28\n+#define IXGBE_INCVAL_SHIFT_1GB 24\n+#define IXGBE_INCVAL_SHIFT_100 21\n+#define IXGBE_INCVAL_SHIFT_82599 7\n+#define IXGBE_INCPER_SHIFT_82599 24\n+\n+#define IXGBE_CYCLECOUNTER_MASK 0xffffffffffffffff\n \n static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev);\n static int eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev);\n@@ -329,6 +336,11 @@ static int ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,\n \t\t\t\t\t uint32_t flags);\n static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,\n \t\t\t\t\t struct timespec *timestamp);\n+static int ixgbe_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta);\n+static int ixgbe_timesync_time_get(struct rte_eth_dev *dev,\n+\t\t\t\t struct timespec *timestamp);\n+static int ixgbe_timesync_time_set(struct rte_eth_dev *dev,\n+\t\t\t\t struct timespec *timestamp);\n \n /*\n * Define VF Stats MACRO for Non \"cleared on read\" register\n@@ -484,6 +496,9 @@ static const struct eth_dev_ops ixgbe_eth_dev_ops = {\n \t.get_eeprom = ixgbe_get_eeprom,\n \t.set_eeprom = ixgbe_set_eeprom,\n \t.get_dcb_info = ixgbe_dev_get_dcb_info,\n+\t.timesync_time_adjust = ixgbe_timesync_time_adjust,\n+\t.timesync_time_get = ixgbe_timesync_time_get,\n+\t.timesync_time_set = ixgbe_timesync_time_set,\n };\n \n /*\n@@ -5650,20 +5665,232 @@ ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,\n \t\t\t\t\t ixgbe_dev_addr_list_itr, TRUE);\n }\n \n+/*\n+ * Register units might not be nanoseconds. This function converts\n+ * these units into nanoseconds and adds to the previous time stored.\n+ */\n+static uint64_t\n+timecounter_cycles_to_ns_time(struct timecounter *tc, uint64_t cycle_tstamp)\n+{\n+\tuint64_t delta;\n+\tuint64_t nsec = tc->nsec, frac = tc->frac;\n+\n+\tdelta = (cycle_tstamp - tc->cycle_last) & tc->cc->mask;\n+\t/*\n+\t * Cycle counts that are correctly converted as they\n+\t * are between -1/2 max cycle count and +1/2 max cycle count.\n+\t */\n+\tif (delta > (tc->cc->mask / 2)) {\n+\t\tdelta = (tc->cycle_last - cycle_tstamp) & tc->cc->mask;\n+\t\tnsec -= cyclecounter_cycles_to_ns_backwards(tc->cc,\n+\t\t\t\t\t\t\t delta, frac);\n+\t} else {\n+\t\tnsec += cyclecounter_cycles_to_ns(tc->cc, delta, tc->mask,\n+\t\t\t\t\t\t &frac);\n+\t}\n+\n+\treturn nsec;\n+}\n+\n+static uint64_t\n+ixgbe_read_timesync_cyclecounter(struct rte_eth_dev *dev)\n+{\n+\tstruct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);\n+\tuint64_t systime_cycles = 0;\n+\n+\tswitch (hw->mac.type) {\n+\tcase ixgbe_mac_X550:\n+\t\t/* SYSTIMEL stores ns and SYSTIMEH stores seconds. */\n+\t\tsystime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);\n+\t\tsystime_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)\n+\t\t\t\t* NSEC_PER_SEC;\n+\t\tbreak;\n+\tdefault:\n+\t\tsystime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);\n+\t\tsystime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)\n+\t\t\t\t<< 32;\n+\t}\n+\n+\treturn systime_cycles;\n+}\n+\n+/*\n+ * Get nanoseconds since the last call of this function.\n+ */\n+static uint64_t\n+timecounter_read_ns_delta(struct rte_eth_dev *dev)\n+{\n+\tstruct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);\n+\tuint64_t cycle_now, cycle_delta;\n+\tuint64_t ns_offset;\n+\tstruct ixgbe_adapter *adapter =\n+\t\t\t\t(struct ixgbe_adapter *)dev->data->dev_private;\n+\n+\t/* Read cycle counter. */\n+\tcycle_now = adapter->tc.cc->read(dev);\n+\n+\t/* Calculate the delta since the last timecounter_read_delta(). */\n+\tcycle_delta = (cycle_now - adapter->tc.cycle_last) &\n+\t\t adapter->tc.cc->mask;\n+\n+\t/* Convert to nanoseconds. */\n+\tif (hw->mac.type == ixgbe_mac_X550)\n+\t\t/* Registers store directly nanoseconds, no need to convert. */\n+\t\tns_offset = cycle_delta;\n+\telse\n+\t\tns_offset = cyclecounter_cycles_to_ns(adapter->tc.cc,\n+\t\t\t\t\t\t cycle_delta,\n+\t\t\t\t\t\t adapter->tc.mask,\n+\t\t\t\t\t\t &adapter->tc.frac);\n+\n+\t/*\n+\t * Store current cycle counter for next\n+\t * timecounter_read_ns_delta() call.\n+\t */\n+\tadapter->tc.cycle_last = cycle_now;\n+\n+\treturn ns_offset;\n+}\n+\n+static uint64_t\n+timecounter_read(struct rte_eth_dev *dev)\n+{\n+\tuint64_t nsec;\n+\tstruct ixgbe_adapter *adapter =\n+\t\t\t(struct ixgbe_adapter *)dev->data->dev_private;\n+\n+\t/* Increment time by nanoseconds since last call. */\n+\tnsec = timecounter_read_ns_delta(dev);\n+\tnsec += adapter->tc.nsec;\n+\tadapter->tc.nsec = nsec;\n+\n+\treturn nsec;\n+}\n+\n+static void\n+timecounter_init(struct rte_eth_dev *dev, uint64_t start_time)\n+{\n+\tstruct ixgbe_adapter *adapter =\n+\t\t\t\t(struct ixgbe_adapter *)dev->data->dev_private;\n+\n+\tadapter->tc.cc = &adapter->cc;\n+\tadapter->tc.cycle_last = adapter->tc.cc->read(dev);\n+\tadapter->tc.nsec = start_time;\n+\tadapter->tc.mask = (1ULL << adapter->tc.cc->shift) - 1;\n+\tadapter->tc.frac = 0;\n+}\n+\n+static void\n+ixgbe_start_cyclecounter(struct rte_eth_dev *dev)\n+{\n+\tstruct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);\n+\tstruct ixgbe_adapter *adapter =\n+\t\t(struct ixgbe_adapter *)dev->data->dev_private;\n+\tstruct rte_eth_link link;\n+\tuint32_t incval = 0;\n+\tuint32_t shift = 0;\n+\n+\t/* Get current link speed. */\n+\tmemset(&link, 0, sizeof(link));\n+\tixgbe_dev_link_update(dev, 1);\n+\trte_ixgbe_dev_atomic_read_link_status(dev, &link);\n+\n+\tswitch (link.link_speed) {\n+\tcase ETH_LINK_SPEED_100:\n+\t\tincval = IXGBE_INCVAL_100;\n+\t\tshift = IXGBE_INCVAL_SHIFT_100;\n+\t\tbreak;\n+\tcase ETH_LINK_SPEED_1000:\n+\t\tincval = IXGBE_INCVAL_1GB;\n+\t\tshift = IXGBE_INCVAL_SHIFT_1GB;\n+\t\tbreak;\n+\tcase ETH_LINK_SPEED_10000:\n+\tdefault:\n+\t\tincval = IXGBE_INCVAL_10GB;\n+\t\tshift = IXGBE_INCVAL_SHIFT_10GB;\n+\t\tbreak;\n+\t}\n+\n+\tswitch (hw->mac.type) {\n+\tcase ixgbe_mac_X550:\n+\t\t/* Independent of link speed. */\n+\t\tincval = 1;\n+\t\t/* Cycles read will be interpreted as ns. */\n+\t\tshift = 0;\n+\t\t/* Fall-through */\n+\tcase ixgbe_mac_X540:\n+\t\tIXGBE_WRITE_REG(hw, IXGBE_TIMINCA, incval);\n+\t\tbreak;\n+\tcase ixgbe_mac_82599EB:\n+\t\tincval >>= IXGBE_INCVAL_SHIFT_82599;\n+\t\tshift -= IXGBE_INCVAL_SHIFT_82599;\n+\t\tIXGBE_WRITE_REG(hw, IXGBE_TIMINCA,\n+\t\t\t\t(1 << IXGBE_INCPER_SHIFT_82599) | incval);\n+\t\tbreak;\n+\tdefault:\n+\t\t/* Not supported. */\n+\t\treturn;\n+\t}\n+\n+\tmemset(&adapter->cc, 0, sizeof(struct cyclecounter));\n+\tadapter->cc.read = ixgbe_read_timesync_cyclecounter;\n+\tadapter->cc.mask = IXGBE_CYCLECOUNTER_MASK;\n+\tadapter->cc.shift = shift;\n+}\n+\n+static int\n+ixgbe_timesync_time_adjust(struct rte_eth_dev *dev, int64_t delta)\n+{\n+\tstruct ixgbe_adapter *adapter =\n+\t\t\t(struct ixgbe_adapter *)dev->data->dev_private;\n+\n+\tadapter->tc.nsec += delta;\n+\n+\treturn 0;\n+}\n+\n+static int\n+ixgbe_timesync_time_set(struct rte_eth_dev *dev, struct timespec *ts)\n+{\n+\tuint64_t ns;\n+\n+\tns = timespec_to_ns(ts);\n+\t/* Reset the timecounter. */\n+\ttimecounter_init(dev, ns);\n+\n+\treturn 0;\n+}\n+\n+static int\n+ixgbe_timesync_time_get(struct rte_eth_dev *dev, struct timespec *ts)\n+{\n+\tuint64_t ns;\n+\n+\tns = timecounter_read(dev);\n+\t*ts = ns_to_timespec(ns);\n+\n+\treturn 0;\n+}\n+\n static int\n ixgbe_timesync_enable(struct rte_eth_dev *dev)\n {\n \tstruct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);\n \tuint32_t tsync_ctl;\n \tuint32_t tsauxc;\n+\tuint64_t ns;\n+\tstruct timespec zerotime = {0, 0};\n \n \t/* Enable system time for platforms where it isn't on by default. */\n \ttsauxc = IXGBE_READ_REG(hw, IXGBE_TSAUXC);\n \ttsauxc &= ~IXGBE_TSAUXC_DISABLE_SYSTIME;\n-\tIXGBE_WRITE_REG(hw, IXGBE_TSAUXC, tsauxc);\n \n-\t/* Start incrementing the register used to timestamp PTP packets. */\n-\tIXGBE_WRITE_REG(hw, IXGBE_TIMINCA, IXGBE_TIMINCA_INIT);\n+\t/* Set 0.0 epoch time to initialize timecounter. */\n+\tns = timespec_to_ns(&zerotime);\n+\tixgbe_start_cyclecounter(dev);\n+\ttimecounter_init(dev, ns);\n+\n+\tIXGBE_WRITE_REG(hw, IXGBE_TSAUXC, tsauxc);\n \n \t/* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */\n \tIXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588),\n@@ -5681,6 +5908,9 @@ ixgbe_timesync_enable(struct rte_eth_dev *dev)\n \ttsync_ctl |= IXGBE_TSYNCTXCTL_ENABLED;\n \tIXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);\n \n+\t/* After writing to registers should be flush. */\n+\tIXGBE_WRITE_FLUSH(hw);\n+\n \treturn 0;\n }\n \n@@ -5715,9 +5945,13 @@ ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,\n \t\t\t\t uint32_t flags __rte_unused)\n {\n \tstruct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);\n+\tstruct ixgbe_adapter *adapter =\n+\t\t(struct ixgbe_adapter *)dev->data->dev_private;\n+\n \tuint32_t tsync_rxctl;\n \tuint32_t rx_stmpl;\n \tuint32_t rx_stmph;\n+\tuint64_t regival = 0;\n \n \ttsync_rxctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);\n \tif ((tsync_rxctl & IXGBE_TSYNCRXCTL_VALID) == 0)\n@@ -5725,9 +5959,15 @@ ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,\n \n \trx_stmpl = IXGBE_READ_REG(hw, IXGBE_RXSTMPL);\n \trx_stmph = IXGBE_READ_REG(hw, IXGBE_RXSTMPH);\n+\ttimecounter_read(dev);\n \n-\ttimestamp->tv_sec = (uint64_t)(((uint64_t)rx_stmph << 32) | rx_stmpl);\n-\ttimestamp->tv_nsec = 0;\n+\tif (hw->mac.type == ixgbe_mac_X550)\n+\t\tregival = (uint64_t)((uint64_t)rx_stmph * NSEC_PER_SEC\n+\t\t\t+ rx_stmpl);\n+\telse\n+\t\tregival = (uint64_t)(((uint64_t)rx_stmph << 32) | rx_stmpl);\n+\tregival = timecounter_cycles_to_ns_time(&adapter->tc, regival);\n+\t*timestamp = ns_to_timespec(regival);\n \n \treturn 0;\n }\n@@ -5737,9 +5977,13 @@ ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,\n \t\t\t\t struct timespec *timestamp)\n {\n \tstruct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);\n+\tstruct ixgbe_adapter *adapter =\n+\t\t(struct ixgbe_adapter *)dev->data->dev_private;\n+\n \tuint32_t tsync_txctl;\n \tuint32_t tx_stmpl;\n \tuint32_t tx_stmph;\n+\tuint64_t regival = 0;\n \n \ttsync_txctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);\n \tif ((tsync_txctl & IXGBE_TSYNCTXCTL_VALID) == 0)\n@@ -5747,9 +5991,15 @@ ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,\n \n \ttx_stmpl = IXGBE_READ_REG(hw, IXGBE_TXSTMPL);\n \ttx_stmph = IXGBE_READ_REG(hw, IXGBE_TXSTMPH);\n+\ttimecounter_read(dev);\n \n-\ttimestamp->tv_sec = (uint64_t)(((uint64_t)tx_stmph << 32) | tx_stmpl);\n-\ttimestamp->tv_nsec = 0;\n+\tif (hw->mac.type == ixgbe_mac_X550)\n+\t\tregival = (uint64_t)((uint64_t)tx_stmph * NSEC_PER_SEC\n+\t\t\t+ tx_stmpl);\n+\telse\n+\t\tregival = (uint64_t)(((uint64_t)tx_stmph << 32) | tx_stmpl);\n+\tregival = timecounter_cycles_to_ns_time(&adapter->tc, regival);\n+\t*timestamp = ns_to_timespec(regival);\n \n \treturn 0;\n }\ndiff --git a/drivers/net/ixgbe/ixgbe_ethdev.h b/drivers/net/ixgbe/ixgbe_ethdev.h\nindex 569d678..701efde 100644\n--- a/drivers/net/ixgbe/ixgbe_ethdev.h\n+++ b/drivers/net/ixgbe/ixgbe_ethdev.h\n@@ -37,6 +37,7 @@\n #include \"base/ixgbe_dcb_82599.h\"\n #include \"base/ixgbe_dcb_82598.h\"\n #include \"ixgbe_bypass.h\"\n+#include <rte_ptp.h>\n \n /* need update link, bit flag */\n #define IXGBE_FLAG_NEED_LINK_UPDATE (uint32_t)(1 << 0)\n@@ -279,6 +280,8 @@ struct ixgbe_adapter {\n \n \tbool rx_bulk_alloc_allowed;\n \tbool rx_vec_allowed;\n+\tstruct cyclecounter cc;\n+\tstruct timecounter tc;\n };\n \n #define IXGBE_DEV_PRIVATE_TO_HW(adapter)\\\n", "prefixes": [ "dpdk-dev", "v3", "3/7" ] }{ "id": 8605, "url": "