Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933061AbcLIJUP (ORCPT ); Fri, 9 Dec 2016 04:20:15 -0500 Received: from mail-sn1nam02on0089.outbound.protection.outlook.com ([104.47.36.89]:46336 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753558AbcLIJUL (ORCPT ); Fri, 9 Dec 2016 04:20:11 -0500 From: Rafal Ozieblo To: "Andrei.Pistirica@microchip.com" , "richardcochran@gmail.com" CC: "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "davem@davemloft.net" , "nicolas.ferre@atmel.com" , "harinikatakamlinux@gmail.com" , "harini.katakam@xilinx.com" , "punnaia@xilinx.com" , "michals@xilinx.com" , "anirudh@xilinx.com" , "boris.brezillon@free-electrons.com" , "alexandre.belloni@free-electrons.com" , "tbultel@pixelsurmer.com" Subject: RE: [RFC PATCH net-next v3 1/2] macb: Add 1588 support in Cadence GEM. Thread-Topic: [RFC PATCH net-next v3 1/2] macb: Add 1588 support in Cadence GEM. Thread-Index: AQHSUJ45+CsZ2mZCq06wFmLvRnJqIKD84euAgAAXyACAASd2AIABNEmg Date: Fri, 9 Dec 2016 09:20:08 +0000 Message-ID: References: <1481134912-2243-1-git-send-email-andrei.pistirica@microchip.com> <20161207193908.GA13062@netboy> <20161207210416.GA27622@netboy> <07C910AB6AC6C345A093D5A08F5AF568CB74AF28@CHN-SV-EXMX03.mchp-main.com> In-Reply-To: <07C910AB6AC6C345A093D5A08F5AF568CB74AF28@CHN-SV-EXMX03.mchp-main.com> Accept-Language: pl-PL, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=rafalo@cadence.com; x-originating-ip: [213.131.238.28] x-ms-office365-filtering-correlation-id: a5acd653-db74-4f1c-dcb2-08d42014922d x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BN3PR07MB2514; x-microsoft-exchange-diagnostics: 1;BN3PR07MB2514;7:g2WDjzsPujUEeRSvWo1a9ZqgBm8rnv5y4u2/zeoyuPCF4SG+ywjgeKv11H2eVZNy01EpQjZCdI2umZxFzlSnTV8wW/8gCxF84rs1Tj7qyATLzLiiOufaqgAbKNf3aLC1tDIjcfB+pkTS7vdDeXu+/aFKY6eT0yx7XRyMCElzhdpbOTnDWk7f1B+gpBkTT4EFnSZUwTHYJjCNf/g/ybi/TTn9SVyVWRNSQ0Ar1IFKurAt6bf1XbRRb7d3L7Vje/ZNYiACtm8cscDqwEbByx1UgzsChsqFiDbqOgz8Jq3nIp69M29kZFV4h97CM3F7CG9cdWN7GF1VtIW9EzlhOUQ6dg9vrNk7dUXV7EFNahMkHuV00SxFKH63Sl6bj9Rj5uUlMtuYFn5M+0twJ1HlfoOXmsMafoymC7S2nTmXKyrLK12DRRGx7AcIrtBdxrR18PMAt3HfVS8u3Q8zOzwRrp9V9A==;20:t2pR94OIMge+SVKVbWQIBo1gfLPS0K3sOzMVNM3i1TKZjj4xaYlxlsxjLk8U8vTONf/09FO1GV45eXG1ckk8CT6rcm6oAV2DDqYwstDZXGiPN5hJHPIfy8DYMpEvD7gm3vOg/NDmC3obi8bmZUORg3LZLaXIp7lrPG5B5xcrlvBIVk+50c+Ofo+Ktw3eycHMU8ghir2vLro1z/1Rr6JCAK3p8xsmmPVYfWXCTgGEJMnttx5QT2tDZUglE0FEz2YI x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(88287073810984)(258649278758335)(192813158149592)(58145275503218)(72806322054110); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123562025)(20161123558021)(20161123564025)(20161123560025)(20161123555025)(6072148);SRVR:BN3PR07MB2514;BCL:0;PCL:0;RULEID:;SRVR:BN3PR07MB2514; x-forefront-prvs: 015114592F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(39850400002)(39410400002)(39840400002)(39860400002)(39450400003)(189002)(36092001)(13464003)(24454002)(377454003)(199003)(101416001)(50986999)(54356999)(106116001)(76176999)(7696004)(105586002)(5660300001)(99286002)(2950100002)(122556002)(68736007)(7416002)(106356001)(4326007)(3846002)(102836003)(6116002)(15974865002)(76576001)(2906002)(189998001)(93886004)(77096006)(38730400001)(81166006)(8676002)(81156014)(8936002)(305945005)(33656002)(3280700002)(7736002)(3660700001)(9686002)(97736004)(2900100001)(66066001)(8666005)(92566002)(2501003)(74316002)(39060400001)(229853002)(6506006)(5001770100001)(6436002)(86362001)(7059030)(217873001)(18886075002);DIR:OUT;SFP:1101;SCL:1;SRVR:BN3PR07MB2514;H:BN3PR07MB2516.namprd07.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Dec 2016 09:20:08.6603 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR07MB2514 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uB99KM0n006025 Content-Length: 4826 Lines: 102 -----Original Message----- > From: Andrei.Pistirica@microchip.com [mailto:Andrei.Pistirica@microchip.com] > Sent: 8 grudnia 2016 15:42 > To: richardcochran@gmail.com > Cc: netdev@vger.kernel.org; linux-kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org; davem@davemloft.net; nicolas.ferre@atmel.com; harinikatakamlinux@gmail.com; harini.katakam@xilinx.com; punnaia@xilinx.com; michals@xilinx.com; anirudh@xilinx.com; boris.brezillon@free-electrons.com; alexandre.belloni@free-electrons.com; tbultel@pixelsurmer.com; Rafal Ozieblo > Subject: RE: [RFC PATCH net-next v3 1/2] macb: Add 1588 support in Cadence GEM. > > > > > -----Original Message----- > > From: Richard Cochran [mailto:richardcochran@gmail.com] > > Sent: Wednesday, December 07, 2016 11:04 PM > > To: Andrei Pistirica - M16132 > > Cc: netdev@vger.kernel.org; linux-kernel@vger.kernel.org; linux-arm- > > kernel@lists.infradead.org; davem@davemloft.net; > > nicolas.ferre@atmel.com; harinikatakamlinux@gmail.com; > > harini.katakam@xilinx.com; punnaia@xilinx.com; michals@xilinx.com; > > anirudh@xilinx.com; boris.brezillon@free-electrons.com; > > alexandre.belloni@free-electrons.com; tbultel@pixelsurmer.com; > > rafalo@cadence.com > > Subject: Re: [RFC PATCH net-next v3 1/2] macb: Add 1588 support in > > Cadence GEM. > > > > On Wed, Dec 07, 2016 at 08:39:09PM +0100, Richard Cochran wrote: > > > > +static s32 gem_ptp_max_adj(unsigned int f_nom) { > > > > + u64 adj; > > > > + > > > > + /* The 48 bits of seconds for the GEM overflows every: > > > > + * 2^48/(365.25 * 24 * 60 *60) =~ 8 925 512 years (~= 9 mil years), > > > > + * thus the maximum adjust frequency must not overflow CNS > > register: > > > > + * > > > > + * addend = 10^9/nominal_freq > > > > + * adj_max = +/- addend*ppb_max/10^9 > > > > + * max_ppb = (2^8-1)*nominal_freq-10^9 > > > > + */ > > > > + adj = f_nom; > > > > + adj *= 0xffff; > > > > + adj -= 1000000000ULL; > > > > > > What is this computation, and how does it relate to the comment? > > I considered the following simple equation: increment value at nominal frequency (which is 10^9/nominal frequency nsecs) + the maximum drift value (nsecs) <= maximum increment value at nominal frequency (which is 8bit:0xffff). > If maximum drift is written as function of nominal frequency and maximum ppb, then the equation above yields that the maximum ppb is: (2^8 - 1) *nominal_frequency - 10^9. The equation is also simplified by the fact that the drift is written as ppm + 16bit_fractions and the increment value is written as nsec + 16bit_fractions. > > Rafal said that this value is hardcoded: 0x64E6, while Harini said: 250000000. To clarify a little bit. In my reference code this value (0x64E6) was taken from our legacy code. It was used for testing only. I know it should be change to something more accurate. This is the reason why I asked how did you count it (250000000). According to our calculations this value depends on actual set period (incr_ns and incr_sub_ns) and min and max value we can set. The calculation were a little bit intricate, so we decided to leave it as it was. > > I need to dig into this... > > > > > I am not sure what you meant, but it sounds like you are on the wrong track. > > Let me explain... > > Thanks. > > > > > The max_adj has nothing at all to do with the width of the time register. > > Rather, it should reflect the maximum possible change in the tuning word. > > > > For example, with a nominal 8 ns period, the tuning word is 0x80000. > > Looking at running the clock more slowly, the slowest possible word is > > 0x00001, meaning a difference of 0x7FFFF. This implies an adjustment > > of > > 0x7FFFF/0x80000 or 999998092 ppb. Running more quickly, we can > > already have 0x100000, twice as fast, or just under 2 billion ppb. > > > > You should consider the extreme cases to determine the most limited > > (smallest) max_adj value: > > > > Case 1 - high frequency > > ~~~~~~~~~~~~~~~~~~~~~~~ > > > > With a nominal 1 ns period, we have the nominal tuning word 0x10000. > > The smallest is 0x1 for a difference of 0xFFFF. This corresponds to > > an adjustment of 0xFFFF/0x10000 = .9999847412109375 or 999984741 ppb. > > > > Case 2 - low frequency > > ~~~~~~~~~~~~~~~~~~~~~~ > > > > With a nominal 255 ns period, the nominal word is 0xFF0000, the > > largest 0xFFFFFF, and the difference is 0xFFFF. This corresponds to > > and adjustment of 0xFFFF/0xFF0000 = .0039215087890625 or 3921508 ppb. > > > > Since 3921508 ppb is a huge adjustment, you can simply use that as a > > safe maximum, ignoring the actual input clock. > > > > Thanks, > > Richard > > > > > > Regards, > Andrei > Best regards, Rafal Ozieblo | Firmware System Engineer, phone nbr.: +48 32 5085469 www.cadence.com