Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753451AbcKRLzn (ORCPT ); Fri, 18 Nov 2016 06:55:43 -0500 Received: from mail-sn1nam01on0086.outbound.protection.outlook.com ([104.47.32.86]:28142 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753242AbcKRLzk (ORCPT ); Fri, 18 Nov 2016 06:55:40 -0500 X-Greylist: delayed 67617 seconds by postgrey-1.27 at vger.kernel.org; Fri, 18 Nov 2016 06:55:40 EST From: Rafal Ozieblo To: Harini Katakam CC: Nicolas Ferre , Andrei Pistirica , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH net-next] cadence: Add hardware PTP support. Thread-Topic: [PATCH net-next] cadence: Add hardware PTP support. Thread-Index: AQHSQYkoeWKNoo8sOUmiZH3lOKPBgKDen0WAgAABjqA= Date: Fri, 18 Nov 2016 11:55:37 +0000 Message-ID: References: <1479466028-29914-1-git-send-email-rafalo@cadence.com> In-Reply-To: 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-microsoft-exchange-diagnostics: 1;BN3PR07MB2516;7:lJMUxELBZCv9BdprS9y50aqIwaTIKdy28Zb2rladySYxV3HBZl9KVC77e1o6Kzd936ow1AqF9r+EKmLFMyPv9dXLdf3AF1KJ7CC6Cih/Ll9BqI5R1QChzRLwRnYeAmuU/n5lrQK56V0+y0uxQWIIjCF4DnqefNdxX+QzRAHOXZtI209jlE2w2RNd+JTRDXjBaQ3xTneXswGwc6xXNqQH/ut66GP6Dct71tKhhyicMuKu/bTG/QeLMQ/3/6UwuQMfd3jGP/2r5rsaFoOCxWdjC2GDWUgVpJHAD0cijaIzQ98lJoQfXZOJqiOdoa5oh8I3XjPgtgte9+m3p7ll5ys+OQO5TjuKov9fSBywUr/esWo=;20:xmCKM9QNzzcRGufZnzchsRMHeJzeg/cW67o3TEtkXA4ewm4AZSI9dLy7AkgRsGgInB+E+cExpSFjsTi01oejNCwCBoABubg2CLvvnAXuqTtBQ9xR51Ul20rz3LftL9Kp1VjLnI6HqYCiYfUAwy69bJgT3w1cLEzqa1Gtgr+rGIK5cXdF4vD+eTHj8SSlO95LI6rcpYSctft80t6TiP8OvzybWuIWjOOaWysxw4/jF91eRUK1o1E27PXVD3seM7no x-ms-office365-filtering-correlation-id: bec15805-ddc0-44be-3645-08d40fa9d013 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BN3PR07MB2516; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(88287073810984)(72806322054110); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040281)(6060326)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041223)(6061324);SRVR:BN3PR07MB2516;BCL:0;PCL:0;RULEID:;SRVR:BN3PR07MB2516; x-forefront-prvs: 01304918F3 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(199003)(36092001)(189002)(101416001)(9686002)(229853002)(8936002)(97736004)(3660700001)(3280700002)(81156014)(189998001)(81166006)(54356999)(76176999)(6506003)(102836003)(2906002)(38730400001)(77096005)(6116002)(3846002)(4326007)(50986999)(92566002)(2900100001)(106116001)(66066001)(106356001)(105586002)(68736007)(99286002)(15974865002)(87936001)(1411001)(122556002)(76576001)(74316002)(8676002)(7736002)(5660300001)(6916009)(7846002)(305945005)(2950100002)(7696004)(33656002)(110136003)(86362001)(18886075002);DIR:OUT;SFP:1101;SCL:1;SRVR:BN3PR07MB2516;H:BN3PR07MB2516.namprd07.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Nov 2016 11:55:37.9611 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR07MB2516 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 base64 to 8bit by mail.home.local id uAIBtuDQ017920 Content-Length: 9727 Lines: 148 >Hi Rafal > >I'm still comparing the full solution but just a couple of things first: > >> @@ -876,6 +964,17 @@ static int gem_rx(struct macb *bp, int budget) >> bp->stats.rx_packets++; >> bp->stats.rx_bytes += skb->len; >> >> +#if IS_ENABLED(CONFIG_PTP_1588_CLOCK) >> + if (bp->ptp_hw_support) { >> + struct timespec64 ts; >> + >> + if (MACB_BFEXT(DMA_RX_TS_VALID, desc->addr)) { >> + macb_hw_timestamp(bp, desc->dma_desc_ts_1, desc->dma_desc_ts_2, &ts); >> + skb_hwtstamps(skb)->hwtstamp = ktime_set(ts.tv_sec, ts.tv_nsec); >> + } >> + } >> +#endif >> + > >I've had to read PTP event registers for upper part of seconds timestamp in addition to the descriptor (since descriptor only has 5 bits of seconds TS). >I don't know which version of the IP you use - it could be different. >Please let me know so that I can check the spec. >Same with tx timestamp of course. I use GEM_GXL 1p9 and 1p10 but I should be comatible with old version as well. >From documentation: Receive Buffer Descriptor Entry Word 0: Bit 2: Address [2] of beginning of buffer. Or In Extended Buffer Descriptor Mode (DMA configuration register[28] = 1), indicates a valid timestamp in the BD entry Transmit Buffer Descriptor Entry Word 1: Bit 23: For Extended Buffer Descriptor Mode this bit Indicates a timestamp has been captured in the BD. Otherwise Reserved. > > >> @@ -1195,6 +1297,87 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id) >> queue_writel(queue, ISR, MACB_BIT(HRESP)); >> } >> >> +#if IS_ENABLED(CONFIG_PTP_1588_CLOCK) >> + if (status & MACB_BIT(PTP_DELAY_REQ_FRAME_RECEIVED)) { >> + if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) >> + queue_writel(queue, ISR, MACB_BIT(PTP_DELAY_REQ_FRAME_RECEIVED)); >> + if (macb_ptp_time_frame_rx_get(bp, &ts) != 0) { >> + ts.tv_sec = 0; >> + ts.tv_nsec = 0; >> + } >> + macb_ptp_event(bp, &ts); >> + } >> + >> + if (status & MACB_BIT(PTP_SYNC_FRAME_RECEIVED)) { >> + if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) >> + queue_writel(queue, ISR, MACB_BIT(PTP_SYNC_FRAME_RECEIVED)); >> + if (macb_ptp_time_frame_rx_get(bp, &ts) != 0) { >> + ts.tv_sec = 0; >> + ts.tv_nsec = 0; >> + } >> + macb_ptp_event(bp, &ts); >> + } >> + >> + if (status & MACB_BIT(PTP_DELAY_REQ_FRAME_TRANSMITTED)) { >> + if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) >> + queue_writel(queue, ISR, MACB_BIT(PTP_DELAY_REQ_FRAME_TRANSMITTED)); >> + if (macb_ptp_time_frame_tx_get(bp, &ts) != 0) { >> + ts.tv_sec = 0; >> + ts.tv_nsec = 0; >> + } >> + macb_ptp_event(bp, &ts); >> + } >> + >> + if (status & MACB_BIT(PTP_SYNC_FRAME_TRANSMITTED)) { >> + if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) >> + queue_writel(queue, ISR, MACB_BIT(PTP_SYNC_FRAME_TRANSMITTED)); >> + if (macb_ptp_time_frame_tx_get(bp, &ts) != 0) { >> + ts.tv_sec = 0; >> + ts.tv_nsec = 0; >> + } >> + macb_ptp_event(bp, &ts); >> + } >> + >> + if (status & MACB_BIT(PTP_PDELAY_REQ_FRAME_RECEIVED)) { >> + if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) >> + queue_writel(queue, ISR, MACB_BIT(PTP_PDELAY_REQ_FRAME_RECEIVED)); >> + if (macb_ptp_time_peer_frame_rx_get(bp, &ts) != 0) { >> + ts.tv_sec = 0; >> + ts.tv_nsec = 0; >> + } >> + macb_ptp_event(bp, &ts); >> + } >> + >> + if (status & MACB_BIT(PTP_PDELAY_RESP_FRAME_RECEIVED)) { >> + if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) >> + queue_writel(queue, ISR, MACB_BIT(PTP_PDELAY_RESP_FRAME_RECEIVED)); >> + if (macb_ptp_time_peer_frame_rx_get(bp, &ts) != 0) { >> + ts.tv_sec = 0; >> + ts.tv_nsec = 0; >> + } >> + macb_ptp_event(bp, &ts); >> + } >> + >> + if (status & MACB_BIT(PTP_PDELAY_REQ_FRAME_TRANSMITTED)) { >> + if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) >> + queue_writel(queue, ISR, MACB_BIT(PTP_PDELAY_REQ_FRAME_TRANSMITTED)); >> + if (macb_ptp_time_peer_frame_tx_get(bp, &ts) != 0) { >> + ts.tv_sec = 0; >> + ts.tv_nsec = 0; >> + } >> + macb_ptp_event(bp, &ts); >> + } >> + >> + if (status & MACB_BIT(PTP_PDELAY_RESP_FRAME_TRANSMITTED)) { >> + if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE) >> + queue_writel(queue, ISR, MACB_BIT(PTP_PDELAY_RESP_FRAME_TRANSMITTED)); >> + if (macb_ptp_time_peer_frame_tx_get(bp, &ts) != 0) { >> + ts.tv_sec = 0; >> + ts.tv_nsec = 0; >> + } >> + macb_ptp_event(bp, &ts); >> + } >> +#endif > >I'm not sure of your application and why this is necessary. >Can you please check Andrei's patches and mine and Richard Cochran's comments? >I use linuxptp to test. > This could be an overhead. I use linuxptp as well and it works. >Regards, >Harini >  Best regards, Rafal Ozieblo   |   Firmware System Engineer, phone nbr.: +48 32 5085469 www.cadence.com