From patchwork Mon Mar 27 10:57:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= X-Patchwork-Id: 13189042 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F54BC76195 for ; Mon, 27 Mar 2023 10:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232101AbjC0K6y (ORCPT ); Mon, 27 Mar 2023 06:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232091AbjC0K6w (ORCPT ); Mon, 27 Mar 2023 06:58:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 518FF3C29 for ; Mon, 27 Mar 2023 03:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679914687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uTUNxXB8waGM5klCOXVJjaX6sSxl38RK0MX/Rq9S0D4=; b=aiqVxf1gas3UUgxPgUQzkTFz5VlfqrKpao/Y8UrnfckxbhHznRcfg49VO4t05esiScFuQE CLKcfdrOiFe5IKSEJfPD0IYqqdCfaaWl2wYzelYWoJZ1ImVABvws79mKdJH9Oy2li6w7FP ke5ewVxn7uBSPiGNQzEZ7PNsJxdVWIM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-150-2us3aDiZMayV_lTt-QKvXw-1; Mon, 27 Mar 2023 06:58:04 -0400 X-MC-Unique: 2us3aDiZMayV_lTt-QKvXw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BCEA61C05B0D; Mon, 27 Mar 2023 10:58:03 +0000 (UTC) Received: from ihuguet-laptop.redhat.com (unknown [10.39.192.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E24FC15BA0; Mon, 27 Mar 2023 10:58:01 +0000 (UTC) From: =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= To: ecree.xilinx@gmail.com, habetsm.xilinx@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, richardcochran@gmail.com, netdev@vger.kernel.org, =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= , Yalin Li Subject: [PATCH v5 net-next 1/4] sfc: store PTP filters in a list Date: Mon, 27 Mar 2023 12:57:52 +0200 Message-Id: <20230327105755.13949-2-ihuguet@redhat.com> In-Reply-To: <20230327105755.13949-1-ihuguet@redhat.com> References: <20230327105755.13949-1-ihuguet@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Instead of using a fixed sized array for the PTP filters, use a list. This is not actually necessary at this point because the filters for multicast PTP are a fixed number, but this is a preparation for the following patches adding support for unicast PTP. To avoid confusion with the new struct type efx_ptp_rxfilter, change the name of some local variables from rxfilter to spec, given they're of the type efx_filter_spec. Reported-by: Yalin Li Signed-off-by: Íñigo Huguet Reviewed-by: Edward Cree --- drivers/net/ethernet/sfc/ptp.c | 81 ++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c index 9f07e1ba7780..8418a25ed724 100644 --- a/drivers/net/ethernet/sfc/ptp.c +++ b/drivers/net/ethernet/sfc/ptp.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -118,8 +119,6 @@ #define PTP_MIN_LENGTH 63 -#define PTP_RXFILTERS_LEN 5 - #define PTP_ADDR_IPV4 0xe0000181 /* 224.0.1.129 */ #define PTP_ADDR_IPV6 {0xff, 0x0e, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0x01, 0x81} /* ff0e::181 */ @@ -213,6 +212,16 @@ struct efx_ptp_timeset { u32 window; /* Derived: end - start, allowing for wrap */ }; +/** + * struct efx_ptp_rxfilter - Filter for PTP packets + * @list: Node of the list where the filter is added + * @handle: Handle ID for the MCDI filters table + */ +struct efx_ptp_rxfilter { + struct list_head list; + int handle; +}; + /** * struct efx_ptp_data - Precision Time Protocol (PTP) state * @efx: The NIC context @@ -229,8 +238,7 @@ struct efx_ptp_timeset { * @work: Work task * @reset_required: A serious error has occurred and the PTP task needs to be * reset (disable, enable). - * @rxfilters: Receive filters when operating - * @rxfilters_count: Num of installed rxfilters, should be == PTP_RXFILTERS_LEN + * @rxfilters_mcast: Receive filters for multicast PTP packets * @config: Current timestamp configuration * @enabled: PTP operation enabled * @mode: Mode in which PTP operating (PTP version) @@ -299,8 +307,7 @@ struct efx_ptp_data { struct workqueue_struct *workwq; struct work_struct work; bool reset_required; - u32 rxfilters[PTP_RXFILTERS_LEN]; - size_t rxfilters_count; + struct list_head rxfilters_mcast; struct hwtstamp_config config; bool enabled; unsigned int mode; @@ -1292,11 +1299,13 @@ static inline void efx_ptp_process_rx(struct efx_nic *efx, struct sk_buff *skb) static void efx_ptp_remove_multicast_filters(struct efx_nic *efx) { struct efx_ptp_data *ptp = efx->ptp_data; + struct efx_ptp_rxfilter *rxfilter, *tmp; - while (ptp->rxfilters_count) { - ptp->rxfilters_count--; + list_for_each_entry_safe(rxfilter, tmp, &ptp->rxfilters_mcast, list) { efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, - ptp->rxfilters[ptp->rxfilters_count]); + rxfilter->handle); + list_del(&rxfilter->list); + kfree(rxfilter); } } @@ -1311,48 +1320,60 @@ static void efx_ptp_init_filter(struct efx_nic *efx, } static int efx_ptp_insert_filter(struct efx_nic *efx, - struct efx_filter_spec *rxfilter) + struct efx_filter_spec *spec) { struct efx_ptp_data *ptp = efx->ptp_data; + struct efx_ptp_rxfilter *rxfilter; + int rc; + + rxfilter = kzalloc(sizeof(*rxfilter), GFP_KERNEL); + if (!rxfilter) + return -ENOMEM; - int rc = efx_filter_insert_filter(efx, rxfilter, true); + rc = efx_filter_insert_filter(efx, spec, true); if (rc < 0) - return rc; - ptp->rxfilters[ptp->rxfilters_count] = rc; - ptp->rxfilters_count++; + goto fail; + + rxfilter->handle = rc; + list_add(&rxfilter->list, &ptp->rxfilters_mcast); + return 0; + +fail: + kfree(rxfilter); + return rc; } static int efx_ptp_insert_ipv4_filter(struct efx_nic *efx, u16 port) { - struct efx_filter_spec rxfilter; + struct efx_filter_spec spec; - efx_ptp_init_filter(efx, &rxfilter); - efx_filter_set_ipv4_local(&rxfilter, IPPROTO_UDP, htonl(PTP_ADDR_IPV4), + efx_ptp_init_filter(efx, &spec); + efx_filter_set_ipv4_local(&spec, IPPROTO_UDP, htonl(PTP_ADDR_IPV4), htons(port)); - return efx_ptp_insert_filter(efx, &rxfilter); + return efx_ptp_insert_filter(efx, &spec); } static int efx_ptp_insert_ipv6_filter(struct efx_nic *efx, u16 port) { const struct in6_addr addr = {{PTP_ADDR_IPV6}}; - struct efx_filter_spec rxfilter; + struct efx_filter_spec spec; - efx_ptp_init_filter(efx, &rxfilter); - efx_filter_set_ipv6_local(&rxfilter, IPPROTO_UDP, &addr, htons(port)); - return efx_ptp_insert_filter(efx, &rxfilter); + efx_ptp_init_filter(efx, &spec); + efx_filter_set_ipv6_local(&spec, IPPROTO_UDP, &addr, htons(port)); + return efx_ptp_insert_filter(efx, &spec); } static int efx_ptp_insert_eth_filter(struct efx_nic *efx) { const u8 addr[ETH_ALEN] = PTP_ADDR_ETHER; - struct efx_filter_spec rxfilter; + struct efx_filter_spec spec; - efx_ptp_init_filter(efx, &rxfilter); - efx_filter_set_eth_local(&rxfilter, EFX_FILTER_VID_UNSPEC, addr); - rxfilter.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE; - rxfilter.ether_type = htons(ETH_P_1588); - return efx_ptp_insert_filter(efx, &rxfilter); + efx_ptp_init_filter(efx, &spec); + efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, addr); + spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE; + spec.ether_type = htons(ETH_P_1588); + return efx_ptp_insert_filter(efx, &spec); } static int efx_ptp_insert_multicast_filters(struct efx_nic *efx) @@ -1360,7 +1381,7 @@ static int efx_ptp_insert_multicast_filters(struct efx_nic *efx) struct efx_ptp_data *ptp = efx->ptp_data; int rc; - if (!ptp->channel || ptp->rxfilters_count) + if (!ptp->channel || !list_empty(&ptp->rxfilters_mcast)) return 0; /* Must filter on both event and general ports to ensure @@ -1566,6 +1587,8 @@ int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel) for (pos = 0; pos < MAX_RECEIVE_EVENTS; pos++) list_add(&ptp->rx_evts[pos].link, &ptp->evt_free_list); + INIT_LIST_HEAD(&ptp->rxfilters_mcast); + /* Get the NIC PTP attributes and set up time conversions */ rc = efx_ptp_get_attributes(efx); if (rc < 0) From patchwork Mon Mar 27 10:57:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= X-Patchwork-Id: 13189045 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF1DDC7619A for ; Mon, 27 Mar 2023 11:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232110AbjC0LAr (ORCPT ); Mon, 27 Mar 2023 07:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232105AbjC0K64 (ORCPT ); Mon, 27 Mar 2023 06:58:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 491BD110 for ; Mon, 27 Mar 2023 03:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679914687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2+OrNNLEX71khpuEogSlcpfo4IcuJBt+uvmI96vNqXs=; b=CEARRIqV4u1+7a2+UmwRTPNZk0ymMaEN8ZVCRX3SqWOuLVa4m0pLoFHdcBEbwgyRGyVCFG Z+F+JDD1bdpkIg1ThJLavn8vit8fVP8UPALjYcfovW5SCYFkZtcO+0lTQ1Nav22Hou3Ypw wPGPNRkP1PR4PKlHI7l10p+NT8eDex4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-6-sMOa8E_9NB219RY73tprmw-1; Mon, 27 Mar 2023 06:58:06 -0400 X-MC-Unique: sMOa8E_9NB219RY73tprmw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C30D33C025CE; Mon, 27 Mar 2023 10:58:05 +0000 (UTC) Received: from ihuguet-laptop.redhat.com (unknown [10.39.192.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CFDCC15BA0; Mon, 27 Mar 2023 10:58:03 +0000 (UTC) From: =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= To: ecree.xilinx@gmail.com, habetsm.xilinx@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, richardcochran@gmail.com, netdev@vger.kernel.org, =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= , Yalin Li Subject: [PATCH v5 net-next 2/4] sfc: allow insertion of filters for unicast PTP Date: Mon, 27 Mar 2023 12:57:53 +0200 Message-Id: <20230327105755.13949-3-ihuguet@redhat.com> In-Reply-To: <20230327105755.13949-1-ihuguet@redhat.com> References: <20230327105755.13949-1-ihuguet@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a second list for unicast filters and generalize the efx_ptp_insert/remove_filters functions to allow acting in any of the 2 lists. No filters for unicast are inserted yet. That will be done in the next patch. The reason to use 2 different lists instead of a single one is that, in next patches, we will want to check if unicast filters are already added and if they're expired. We don't need that for multicast filters. Reported-by: Yalin Li Signed-off-by: Íñigo Huguet Reviewed-by: Edward Cree --- drivers/net/ethernet/sfc/ptp.c | 59 +++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c index 8418a25ed724..d5631e02e626 100644 --- a/drivers/net/ethernet/sfc/ptp.c +++ b/drivers/net/ethernet/sfc/ptp.c @@ -239,6 +239,7 @@ struct efx_ptp_rxfilter { * @reset_required: A serious error has occurred and the PTP task needs to be * reset (disable, enable). * @rxfilters_mcast: Receive filters for multicast PTP packets + * @rxfilters_ucast: Receive filters for unicast PTP packets * @config: Current timestamp configuration * @enabled: PTP operation enabled * @mode: Mode in which PTP operating (PTP version) @@ -308,6 +309,7 @@ struct efx_ptp_data { struct work_struct work; bool reset_required; struct list_head rxfilters_mcast; + struct list_head rxfilters_ucast; struct hwtstamp_config config; bool enabled; unsigned int mode; @@ -1296,12 +1298,12 @@ static inline void efx_ptp_process_rx(struct efx_nic *efx, struct sk_buff *skb) local_bh_enable(); } -static void efx_ptp_remove_multicast_filters(struct efx_nic *efx) +static void efx_ptp_remove_filters(struct efx_nic *efx, + struct list_head *filter_list) { - struct efx_ptp_data *ptp = efx->ptp_data; struct efx_ptp_rxfilter *rxfilter, *tmp; - list_for_each_entry_safe(rxfilter, tmp, &ptp->rxfilters_mcast, list) { + list_for_each_entry_safe(rxfilter, tmp, filter_list, list) { efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, rxfilter->handle); list_del(&rxfilter->list); @@ -1320,9 +1322,9 @@ static void efx_ptp_init_filter(struct efx_nic *efx, } static int efx_ptp_insert_filter(struct efx_nic *efx, + struct list_head *filter_list, struct efx_filter_spec *spec) { - struct efx_ptp_data *ptp = efx->ptp_data; struct efx_ptp_rxfilter *rxfilter; int rc; @@ -1335,7 +1337,7 @@ static int efx_ptp_insert_filter(struct efx_nic *efx, goto fail; rxfilter->handle = rc; - list_add(&rxfilter->list, &ptp->rxfilters_mcast); + list_add(&rxfilter->list, filter_list); return 0; @@ -1344,28 +1346,31 @@ static int efx_ptp_insert_filter(struct efx_nic *efx, return rc; } -static int efx_ptp_insert_ipv4_filter(struct efx_nic *efx, u16 port) +static int efx_ptp_insert_ipv4_filter(struct efx_nic *efx, + struct list_head *filter_list, + __be32 addr, u16 port) { struct efx_filter_spec spec; efx_ptp_init_filter(efx, &spec); - efx_filter_set_ipv4_local(&spec, IPPROTO_UDP, htonl(PTP_ADDR_IPV4), - htons(port)); - return efx_ptp_insert_filter(efx, &spec); + efx_filter_set_ipv4_local(&spec, IPPROTO_UDP, addr, htons(port)); + return efx_ptp_insert_filter(efx, filter_list, &spec); } -static int efx_ptp_insert_ipv6_filter(struct efx_nic *efx, u16 port) +static int efx_ptp_insert_ipv6_filter(struct efx_nic *efx, + struct list_head *filter_list, + struct in6_addr *addr, u16 port) { - const struct in6_addr addr = {{PTP_ADDR_IPV6}}; struct efx_filter_spec spec; efx_ptp_init_filter(efx, &spec); - efx_filter_set_ipv6_local(&spec, IPPROTO_UDP, &addr, htons(port)); - return efx_ptp_insert_filter(efx, &spec); + efx_filter_set_ipv6_local(&spec, IPPROTO_UDP, addr, htons(port)); + return efx_ptp_insert_filter(efx, filter_list, &spec); } -static int efx_ptp_insert_eth_filter(struct efx_nic *efx) +static int efx_ptp_insert_eth_multicast_filter(struct efx_nic *efx) { + struct efx_ptp_data *ptp = efx->ptp_data; const u8 addr[ETH_ALEN] = PTP_ADDR_ETHER; struct efx_filter_spec spec; @@ -1373,7 +1378,7 @@ static int efx_ptp_insert_eth_filter(struct efx_nic *efx) efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, addr); spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE; spec.ether_type = htons(ETH_P_1588); - return efx_ptp_insert_filter(efx, &spec); + return efx_ptp_insert_filter(efx, &ptp->rxfilters_mcast, &spec); } static int efx_ptp_insert_multicast_filters(struct efx_nic *efx) @@ -1387,11 +1392,13 @@ static int efx_ptp_insert_multicast_filters(struct efx_nic *efx) /* Must filter on both event and general ports to ensure * that there is no packet re-ordering. */ - rc = efx_ptp_insert_ipv4_filter(efx, PTP_EVENT_PORT); + rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_mcast, + htonl(PTP_ADDR_IPV4), PTP_EVENT_PORT); if (rc < 0) goto fail; - rc = efx_ptp_insert_ipv4_filter(efx, PTP_GENERAL_PORT); + rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_mcast, + htonl(PTP_ADDR_IPV4), PTP_GENERAL_PORT); if (rc < 0) goto fail; @@ -1399,15 +1406,19 @@ static int efx_ptp_insert_multicast_filters(struct efx_nic *efx) * PTP over IPv6 and Ethernet */ if (efx_ptp_use_mac_tx_timestamps(efx)) { - rc = efx_ptp_insert_ipv6_filter(efx, PTP_EVENT_PORT); + struct in6_addr ipv6_addr = {{PTP_ADDR_IPV6}}; + + rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_mcast, + &ipv6_addr, PTP_EVENT_PORT); if (rc < 0) goto fail; - rc = efx_ptp_insert_ipv6_filter(efx, PTP_GENERAL_PORT); + rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_mcast, + &ipv6_addr, PTP_GENERAL_PORT); if (rc < 0) goto fail; - rc = efx_ptp_insert_eth_filter(efx); + rc = efx_ptp_insert_eth_multicast_filter(efx); if (rc < 0) goto fail; } @@ -1415,7 +1426,7 @@ static int efx_ptp_insert_multicast_filters(struct efx_nic *efx) return 0; fail: - efx_ptp_remove_multicast_filters(efx); + efx_ptp_remove_filters(efx, &ptp->rxfilters_mcast); return rc; } @@ -1440,7 +1451,7 @@ static int efx_ptp_start(struct efx_nic *efx) return 0; fail: - efx_ptp_remove_multicast_filters(efx); + efx_ptp_remove_filters(efx, &ptp->rxfilters_mcast); return rc; } @@ -1456,7 +1467,8 @@ static int efx_ptp_stop(struct efx_nic *efx) rc = efx_ptp_disable(efx); - efx_ptp_remove_multicast_filters(efx); + efx_ptp_remove_filters(efx, &ptp->rxfilters_mcast); + efx_ptp_remove_filters(efx, &ptp->rxfilters_ucast); /* Make sure RX packets are really delivered */ efx_ptp_deliver_rx_queue(&efx->ptp_data->rxq); @@ -1588,6 +1600,7 @@ int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel) list_add(&ptp->rx_evts[pos].link, &ptp->evt_free_list); INIT_LIST_HEAD(&ptp->rxfilters_mcast); + INIT_LIST_HEAD(&ptp->rxfilters_ucast); /* Get the NIC PTP attributes and set up time conversions */ rc = efx_ptp_get_attributes(efx); From patchwork Mon Mar 27 10:57:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= X-Patchwork-Id: 13189043 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96F47C76195 for ; Mon, 27 Mar 2023 10:59:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231422AbjC0K7B (ORCPT ); Mon, 27 Mar 2023 06:59:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229935AbjC0K67 (ORCPT ); Mon, 27 Mar 2023 06:58:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9828E40FF for ; Mon, 27 Mar 2023 03:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679914689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EHq0zXvMK81OV18CB0uexUVX2noCWuNlagUW3O56hFA=; b=QYe/XjcKLUATKjXQKzc5nuxWhBhwiv+GgTmQxl0CUAKw2S8NIEBvxdTylaVTB//CpMm3l3 sPEtQSUDhnoGFAWC8y01T2VRV9H9BKK7SVfn9E1PRPfcCLutpt/i8Z/kTbHjYl/vK/8dt/ EWNZbUt6RZMzPMeueO1bNTCqZd/5uV0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-320-Nh6wHRO6NwCTA05sJTSH_g-1; Mon, 27 Mar 2023 06:58:08 -0400 X-MC-Unique: Nh6wHRO6NwCTA05sJTSH_g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C38B31C05EB9; Mon, 27 Mar 2023 10:58:07 +0000 (UTC) Received: from ihuguet-laptop.redhat.com (unknown [10.39.192.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11C41C15BA0; Mon, 27 Mar 2023 10:58:05 +0000 (UTC) From: =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= To: ecree.xilinx@gmail.com, habetsm.xilinx@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, richardcochran@gmail.com, netdev@vger.kernel.org, =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= , Yalin Li Subject: [PATCH v5 net-next 3/4] sfc: support unicast PTP Date: Mon, 27 Mar 2023 12:57:54 +0200 Message-Id: <20230327105755.13949-4-ihuguet@redhat.com> In-Reply-To: <20230327105755.13949-1-ihuguet@redhat.com> References: <20230327105755.13949-1-ihuguet@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When sending a PTP event packet, add the correct filters that will make that future incoming unicast PTP event packets will be timestamped. The unicast address for the filter is gotten from the outgoing skb before sending it. Until now they were not timestamped because only filters that match with the PTP multicast addressed were being configured into the NIC for the PTP special channel. Packets received through different channels are not timestamped, getting "received SYNC without timestamp" error in ptp4l. Note that the inserted filters are never removed unless the NIC is stopped or reconfigured, so efx_ptp_stop is called. Removal of old filters will be handled by the next patch. Additionally, cleanup a bit efx_ptp_xmit_skb_mc to use the reverse xmas tree convention and remove an unnecessary assignment to rc variable in void function. Reported-by: Yalin Li Signed-off-by: Íñigo Huguet Reviewed-by: Edward Cree --- drivers/net/ethernet/sfc/ptp.c | 101 ++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 3 deletions(-) -- 2.39.2 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c index d5631e02e626..b495f3d0616b 100644 --- a/drivers/net/ethernet/sfc/ptp.c +++ b/drivers/net/ethernet/sfc/ptp.c @@ -215,10 +215,16 @@ struct efx_ptp_timeset { /** * struct efx_ptp_rxfilter - Filter for PTP packets * @list: Node of the list where the filter is added + * @ether_type: Network protocol of the filter (ETHER_P_IP / ETHER_P_IPV6) + * @loc_port: UDP port of the filter (PTP_EVENT_PORT / PTP_GENERAL_PORT) + * @loc_host: IPv4/v6 address of the filter * @handle: Handle ID for the MCDI filters table */ struct efx_ptp_rxfilter { struct list_head list; + __be16 ether_type; + __be16 loc_port; + __be32 loc_host[4]; int handle; }; @@ -367,6 +373,8 @@ static int efx_phc_settime(struct ptp_clock_info *ptp, const struct timespec64 *e_ts); static int efx_phc_enable(struct ptp_clock_info *ptp, struct ptp_clock_request *request, int on); +static int efx_ptp_insert_unicast_filter(struct efx_nic *efx, + struct sk_buff *skb); bool efx_ptp_use_mac_tx_timestamps(struct efx_nic *efx) { @@ -1112,6 +1120,8 @@ static void efx_ptp_xmit_skb_queue(struct efx_nic *efx, struct sk_buff *skb) tx_queue = efx_channel_get_tx_queue(ptp_data->channel, type); if (tx_queue && tx_queue->timestamping) { + skb_get(skb); + /* This code invokes normal driver TX code which is always * protected from softirqs when called from generic TX code, * which in turn disables preemption. Look at __dev_queue_xmit @@ -1135,6 +1145,13 @@ static void efx_ptp_xmit_skb_queue(struct efx_nic *efx, struct sk_buff *skb) local_bh_disable(); efx_enqueue_skb(tx_queue, skb); local_bh_enable(); + + /* We need to add the filters after enqueuing the packet. + * Otherwise, there's high latency in sending back the + * timestamp, causing ptp4l timeouts + */ + efx_ptp_insert_unicast_filter(efx, skb); + dev_consume_skb_any(skb); } else { WARN_ONCE(1, "PTP channel has no timestamped tx queue\n"); dev_kfree_skb_any(skb); @@ -1144,11 +1161,11 @@ static void efx_ptp_xmit_skb_queue(struct efx_nic *efx, struct sk_buff *skb) /* Transmit a PTP packet, via the MCDI interface, to the wire. */ static void efx_ptp_xmit_skb_mc(struct efx_nic *efx, struct sk_buff *skb) { + MCDI_DECLARE_BUF(txtime, MC_CMD_PTP_OUT_TRANSMIT_LEN); struct efx_ptp_data *ptp_data = efx->ptp_data; struct skb_shared_hwtstamps timestamps; - int rc = -EIO; - MCDI_DECLARE_BUF(txtime, MC_CMD_PTP_OUT_TRANSMIT_LEN); size_t len; + int rc; MCDI_SET_DWORD(ptp_data->txbuf, PTP_IN_OP, MC_CMD_PTP_OP_TRANSMIT); MCDI_SET_DWORD(ptp_data->txbuf, PTP_IN_PERIPH_ID, 0); @@ -1182,7 +1199,10 @@ static void efx_ptp_xmit_skb_mc(struct efx_nic *efx, struct sk_buff *skb) skb_tstamp_tx(skb, ×tamps); - rc = 0; + /* Add the filters after sending back the timestamp to avoid delaying it + * or ptp4l may timeout. + */ + efx_ptp_insert_unicast_filter(efx, skb); fail: dev_kfree_skb_any(skb); @@ -1298,6 +1318,21 @@ static inline void efx_ptp_process_rx(struct efx_nic *efx, struct sk_buff *skb) local_bh_enable(); } +static bool efx_ptp_filter_exists(struct list_head *filter_list, + struct efx_filter_spec *spec) +{ + struct efx_ptp_rxfilter *rxfilter; + + list_for_each_entry(rxfilter, filter_list, list) { + if (rxfilter->ether_type == spec->ether_type && + rxfilter->loc_port == spec->loc_port && + !memcmp(rxfilter->loc_host, spec->loc_host, sizeof(spec->loc_host))) + return true; + } + + return false; +} + static void efx_ptp_remove_filters(struct efx_nic *efx, struct list_head *filter_list) { @@ -1328,6 +1363,9 @@ static int efx_ptp_insert_filter(struct efx_nic *efx, struct efx_ptp_rxfilter *rxfilter; int rc; + if (efx_ptp_filter_exists(filter_list, spec)) + return 0; + rxfilter = kzalloc(sizeof(*rxfilter), GFP_KERNEL); if (!rxfilter) return -ENOMEM; @@ -1337,6 +1375,9 @@ static int efx_ptp_insert_filter(struct efx_nic *efx, goto fail; rxfilter->handle = rc; + rxfilter->ether_type = spec->ether_type; + rxfilter->loc_port = spec->loc_port; + memcpy(rxfilter->loc_host, spec->loc_host, sizeof(spec->loc_host)); list_add(&rxfilter->list, filter_list); return 0; @@ -1430,6 +1471,60 @@ static int efx_ptp_insert_multicast_filters(struct efx_nic *efx) return rc; } +static bool efx_ptp_valid_unicast_event_pkt(struct sk_buff *skb) +{ + if (skb->protocol == htons(ETH_P_IP)) { + return ip_hdr(skb)->daddr != htonl(PTP_ADDR_IPV4) && + ip_hdr(skb)->protocol == IPPROTO_UDP && + udp_hdr(skb)->source == htons(PTP_EVENT_PORT); + } else if (skb->protocol == htons(ETH_P_IPV6)) { + struct in6_addr mcast_addr = {{PTP_ADDR_IPV6}}; + + return !ipv6_addr_equal(&ipv6_hdr(skb)->daddr, &mcast_addr) && + ipv6_hdr(skb)->nexthdr == IPPROTO_UDP && + udp_hdr(skb)->source == htons(PTP_EVENT_PORT); + } + return false; +} + +static int efx_ptp_insert_unicast_filter(struct efx_nic *efx, + struct sk_buff *skb) +{ + struct efx_ptp_data *ptp = efx->ptp_data; + int rc; + + if (!efx_ptp_valid_unicast_event_pkt(skb)) + return -EINVAL; + + if (skb->protocol == htons(ETH_P_IP)) { + __be32 addr = ip_hdr(skb)->saddr; + + rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_ucast, + addr, PTP_EVENT_PORT); + if (rc < 0) + goto out; + + rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_ucast, + addr, PTP_GENERAL_PORT); + } else if (efx_ptp_use_mac_tx_timestamps(efx)) { + /* IPv6 PTP only supported by devices with MAC hw timestamp */ + struct in6_addr *addr = &ipv6_hdr(skb)->saddr; + + rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_ucast, + addr, PTP_EVENT_PORT); + if (rc < 0) + goto out; + + rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_ucast, + addr, PTP_GENERAL_PORT); + } else { + return -EOPNOTSUPP; + } + +out: + return rc; +} + static int efx_ptp_start(struct efx_nic *efx) { struct efx_ptp_data *ptp = efx->ptp_data; From patchwork Mon Mar 27 10:57:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= X-Patchwork-Id: 13189044 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 857C3C761A6 for ; Mon, 27 Mar 2023 10:59:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231959AbjC0K7C (ORCPT ); Mon, 27 Mar 2023 06:59:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232110AbjC0K64 (ORCPT ); Mon, 27 Mar 2023 06:58:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A94E3C2A for ; Mon, 27 Mar 2023 03:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679914693; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NWFv7t02vS0yYyBB7zVZWHgzKmSZWKJ46Htcmvlz8e8=; b=h00AGLklUspkEcTIEB6LxtWgMSI88tw7CuboVv4AkvYNtxIlZviSNTUmsvKes/V/HxOwZh wZUifczd30MKIMW4QlixAHEMkic/7u44sszN7jAu1svK3A40cBZ1nbEsShtvXDb4N/y2fv 7DgdP6fZhQsN0mh2uK9rhy7akO+XdD8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-659-NVFXkJFmNe6gUf9kqJgVQw-1; Mon, 27 Mar 2023 06:58:10 -0400 X-MC-Unique: NVFXkJFmNe6gUf9kqJgVQw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C49CC101A54F; Mon, 27 Mar 2023 10:58:09 +0000 (UTC) Received: from ihuguet-laptop.redhat.com (unknown [10.39.192.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1199BC15BA0; Mon, 27 Mar 2023 10:58:07 +0000 (UTC) From: =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= To: ecree.xilinx@gmail.com, habetsm.xilinx@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, richardcochran@gmail.com, netdev@vger.kernel.org, =?utf-8?b?w43DsWlnbyBIdWd1ZXQ=?= , Yalin Li Subject: [PATCH v5 net-next 4/4] sfc: remove expired unicast PTP filters Date: Mon, 27 Mar 2023 12:57:55 +0200 Message-Id: <20230327105755.13949-5-ihuguet@redhat.com> In-Reply-To: <20230327105755.13949-1-ihuguet@redhat.com> References: <20230327105755.13949-1-ihuguet@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Filters inserted to support unicast PTP mode might become unused after some time, so we need to remove them to avoid accumulating many of them. Refresh the expiration time of a filter each time it's used. Then check periodically if any filter hasn't been used for a long time (30s) and remove it. Reported-by: Yalin Li Signed-off-by: Íñigo Huguet --- drivers/net/ethernet/sfc/ptp.c | 96 +++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c index b495f3d0616b..949299f61bdd 100644 --- a/drivers/net/ethernet/sfc/ptp.c +++ b/drivers/net/ethernet/sfc/ptp.c @@ -75,6 +75,9 @@ /* How long an unmatched event or packet can be held */ #define PKT_EVENT_LIFETIME_MS 10 +/* How long unused unicast filters can be held */ +#define UCAST_FILTER_EXPIRY_JIFFIES msecs_to_jiffies(30000) + /* Offsets into PTP packet for identification. These offsets are from the * start of the IP header, not the MAC header. Note that neither PTP V1 nor * PTP V2 permit the use of IPV4 options. @@ -218,6 +221,7 @@ struct efx_ptp_timeset { * @ether_type: Network protocol of the filter (ETHER_P_IP / ETHER_P_IPV6) * @loc_port: UDP port of the filter (PTP_EVENT_PORT / PTP_GENERAL_PORT) * @loc_host: IPv4/v6 address of the filter + * @expiry: time when the filter expires, in jiffies * @handle: Handle ID for the MCDI filters table */ struct efx_ptp_rxfilter { @@ -225,6 +229,7 @@ struct efx_ptp_rxfilter { __be16 ether_type; __be16 loc_port; __be32 loc_host[4]; + unsigned long expiry; int handle; }; @@ -313,6 +318,7 @@ struct efx_ptp_data { struct efx_ptp_event_rx rx_evts[MAX_RECEIVE_EVENTS]; struct workqueue_struct *workwq; struct work_struct work; + struct delayed_work cleanup_work; bool reset_required; struct list_head rxfilters_mcast; struct list_head rxfilters_ucast; @@ -1318,8 +1324,8 @@ static inline void efx_ptp_process_rx(struct efx_nic *efx, struct sk_buff *skb) local_bh_enable(); } -static bool efx_ptp_filter_exists(struct list_head *filter_list, - struct efx_filter_spec *spec) +static struct efx_ptp_rxfilter * +efx_ptp_find_filter(struct list_head *filter_list, struct efx_filter_spec *spec) { struct efx_ptp_rxfilter *rxfilter; @@ -1327,10 +1333,19 @@ static bool efx_ptp_filter_exists(struct list_head *filter_list, if (rxfilter->ether_type == spec->ether_type && rxfilter->loc_port == spec->loc_port && !memcmp(rxfilter->loc_host, spec->loc_host, sizeof(spec->loc_host))) - return true; + return rxfilter; } - return false; + return NULL; +} + +static void efx_ptp_remove_one_filter(struct efx_nic *efx, + struct efx_ptp_rxfilter *rxfilter) +{ + efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, + rxfilter->handle); + list_del(&rxfilter->list); + kfree(rxfilter); } static void efx_ptp_remove_filters(struct efx_nic *efx, @@ -1338,12 +1353,8 @@ static void efx_ptp_remove_filters(struct efx_nic *efx, { struct efx_ptp_rxfilter *rxfilter, *tmp; - list_for_each_entry_safe(rxfilter, tmp, filter_list, list) { - efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, - rxfilter->handle); - list_del(&rxfilter->list); - kfree(rxfilter); - } + list_for_each_entry_safe(rxfilter, tmp, filter_list, list) + efx_ptp_remove_one_filter(efx, rxfilter); } static void efx_ptp_init_filter(struct efx_nic *efx, @@ -1358,13 +1369,18 @@ static void efx_ptp_init_filter(struct efx_nic *efx, static int efx_ptp_insert_filter(struct efx_nic *efx, struct list_head *filter_list, - struct efx_filter_spec *spec) + struct efx_filter_spec *spec, + unsigned long expiry) { + struct efx_ptp_data *ptp = efx->ptp_data; struct efx_ptp_rxfilter *rxfilter; int rc; - if (efx_ptp_filter_exists(filter_list, spec)) + rxfilter = efx_ptp_find_filter(filter_list, spec); + if (rxfilter) { + rxfilter->expiry = expiry; return 0; + } rxfilter = kzalloc(sizeof(*rxfilter), GFP_KERNEL); if (!rxfilter) @@ -1378,8 +1394,12 @@ static int efx_ptp_insert_filter(struct efx_nic *efx, rxfilter->ether_type = spec->ether_type; rxfilter->loc_port = spec->loc_port; memcpy(rxfilter->loc_host, spec->loc_host, sizeof(spec->loc_host)); + rxfilter->expiry = expiry; list_add(&rxfilter->list, filter_list); + queue_delayed_work(ptp->workwq, &ptp->cleanup_work, + UCAST_FILTER_EXPIRY_JIFFIES); + return 0; fail: @@ -1389,24 +1409,26 @@ static int efx_ptp_insert_filter(struct efx_nic *efx, static int efx_ptp_insert_ipv4_filter(struct efx_nic *efx, struct list_head *filter_list, - __be32 addr, u16 port) + __be32 addr, u16 port, + unsigned long expiry) { struct efx_filter_spec spec; efx_ptp_init_filter(efx, &spec); efx_filter_set_ipv4_local(&spec, IPPROTO_UDP, addr, htons(port)); - return efx_ptp_insert_filter(efx, filter_list, &spec); + return efx_ptp_insert_filter(efx, filter_list, &spec, expiry); } static int efx_ptp_insert_ipv6_filter(struct efx_nic *efx, struct list_head *filter_list, - struct in6_addr *addr, u16 port) + struct in6_addr *addr, u16 port, + unsigned long expiry) { struct efx_filter_spec spec; efx_ptp_init_filter(efx, &spec); efx_filter_set_ipv6_local(&spec, IPPROTO_UDP, addr, htons(port)); - return efx_ptp_insert_filter(efx, filter_list, &spec); + return efx_ptp_insert_filter(efx, filter_list, &spec, expiry); } static int efx_ptp_insert_eth_multicast_filter(struct efx_nic *efx) @@ -1419,7 +1441,7 @@ static int efx_ptp_insert_eth_multicast_filter(struct efx_nic *efx) efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, addr); spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE; spec.ether_type = htons(ETH_P_1588); - return efx_ptp_insert_filter(efx, &ptp->rxfilters_mcast, &spec); + return efx_ptp_insert_filter(efx, &ptp->rxfilters_mcast, &spec, 0); } static int efx_ptp_insert_multicast_filters(struct efx_nic *efx) @@ -1434,12 +1456,14 @@ static int efx_ptp_insert_multicast_filters(struct efx_nic *efx) * that there is no packet re-ordering. */ rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_mcast, - htonl(PTP_ADDR_IPV4), PTP_EVENT_PORT); + htonl(PTP_ADDR_IPV4), PTP_EVENT_PORT, + 0); if (rc < 0) goto fail; rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_mcast, - htonl(PTP_ADDR_IPV4), PTP_GENERAL_PORT); + htonl(PTP_ADDR_IPV4), PTP_GENERAL_PORT, + 0); if (rc < 0) goto fail; @@ -1450,12 +1474,12 @@ static int efx_ptp_insert_multicast_filters(struct efx_nic *efx) struct in6_addr ipv6_addr = {{PTP_ADDR_IPV6}}; rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_mcast, - &ipv6_addr, PTP_EVENT_PORT); + &ipv6_addr, PTP_EVENT_PORT, 0); if (rc < 0) goto fail; rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_mcast, - &ipv6_addr, PTP_GENERAL_PORT); + &ipv6_addr, PTP_GENERAL_PORT, 0); if (rc < 0) goto fail; @@ -1491,32 +1515,35 @@ static int efx_ptp_insert_unicast_filter(struct efx_nic *efx, struct sk_buff *skb) { struct efx_ptp_data *ptp = efx->ptp_data; + unsigned long expiry; int rc; if (!efx_ptp_valid_unicast_event_pkt(skb)) return -EINVAL; + expiry = jiffies + UCAST_FILTER_EXPIRY_JIFFIES; + if (skb->protocol == htons(ETH_P_IP)) { __be32 addr = ip_hdr(skb)->saddr; rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_ucast, - addr, PTP_EVENT_PORT); + addr, PTP_EVENT_PORT, expiry); if (rc < 0) goto out; rc = efx_ptp_insert_ipv4_filter(efx, &ptp->rxfilters_ucast, - addr, PTP_GENERAL_PORT); + addr, PTP_GENERAL_PORT, expiry); } else if (efx_ptp_use_mac_tx_timestamps(efx)) { /* IPv6 PTP only supported by devices with MAC hw timestamp */ struct in6_addr *addr = &ipv6_hdr(skb)->saddr; rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_ucast, - addr, PTP_EVENT_PORT); + addr, PTP_EVENT_PORT, expiry); if (rc < 0) goto out; rc = efx_ptp_insert_ipv6_filter(efx, &ptp->rxfilters_ucast, - addr, PTP_GENERAL_PORT); + addr, PTP_GENERAL_PORT, expiry); } else { return -EOPNOTSUPP; } @@ -1627,6 +1654,23 @@ static void efx_ptp_worker(struct work_struct *work) efx_ptp_process_rx(efx, skb); } +static void efx_ptp_cleanup_worker(struct work_struct *work) +{ + struct efx_ptp_data *ptp = + container_of(work, struct efx_ptp_data, cleanup_work.work); + struct efx_ptp_rxfilter *rxfilter, *tmp; + + list_for_each_entry_safe(rxfilter, tmp, &ptp->rxfilters_ucast, list) { + if (time_is_before_jiffies(rxfilter->expiry)) + efx_ptp_remove_one_filter(ptp->efx, rxfilter); + } + + if (!list_empty(&ptp->rxfilters_ucast)) { + queue_delayed_work(ptp->workwq, &ptp->cleanup_work, + UCAST_FILTER_EXPIRY_JIFFIES + 1); + } +} + static const struct ptp_clock_info efx_phc_clock_info = { .owner = THIS_MODULE, .name = "sfc", @@ -1685,6 +1729,7 @@ int efx_ptp_probe(struct efx_nic *efx, struct efx_channel *channel) } INIT_WORK(&ptp->work, efx_ptp_worker); + INIT_DELAYED_WORK(&ptp->cleanup_work, efx_ptp_cleanup_worker); ptp->config.flags = 0; ptp->config.tx_type = HWTSTAMP_TX_OFF; ptp->config.rx_filter = HWTSTAMP_FILTER_NONE; @@ -1776,6 +1821,7 @@ void efx_ptp_remove(struct efx_nic *efx) (void)efx_ptp_disable(efx); cancel_work_sync(&efx->ptp_data->work); + cancel_delayed_work_sync(&efx->ptp_data->cleanup_work); if (efx->ptp_data->pps_workwq) cancel_work_sync(&efx->ptp_data->pps_work);