From patchwork Mon Mar 15 13:34:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 400435 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3424787jai; Mon, 15 Mar 2021 06:35:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmYpkCWjt94fN6qOOifDQkXBhjLh4BUGkao77cwIDF7w6xGe6zPSh4PFGDUh27/z2ZPOof X-Received: by 2002:a17:906:4d96:: with SMTP id s22mr23627316eju.189.1615815351400; Mon, 15 Mar 2021 06:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615815351; cv=none; d=google.com; s=arc-20160816; b=eKENwuBtFzZ7W+YN+oBXPpfmVYrPxkSYHF4cWLL1xXLVSX5zIW2oPhL0EZ5gO2cFKk 2eX1MCnD8KjD73UCgqpWNVpRjz6pANOg42SvEOQB8+CfeiabICAtW5QfnUxtZ1thTCqC ujWoqBFULvjA+dL/N7+JpFYBpjXMhyE3XBZOaki8fYe0E+dUo/naa+4NhNoQJjY8QEqz Je0tx89EyTFHloCZq7M2xLs+Cmv97JSdWKdGYjtsg9Wt7LBIky0svIdPklWAm2Gikct8 Ljz5YrMe7hRCHaPEm3KRElC+mO4Y8593Vf5yBPiS1Ceq+irBM3zGTDBXewNqI/6DOx7W eKEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9wMFcNuOVXwXfZ6AijxvuqRZ/xlVmx3dzuXhVIw9piE=; b=KqBEL+GiOMydWQdS58vbLIDTf7AXXpnllDl1s09eKUrYF4OKW/uNw2gmmyFMyXoKq5 8dB+HDYXru0SJ1TmHoqjgVCoRn9DXEGs+x0nS0lGuuDNh8GNqEVakso/O/Ket/guvaOx O7uiNkX8FlSAPigqgm+oXvdMgAXRVOETI5ffv5G4UlXDoJsa+KI9DzAwYujr3use4K9v wCsj6XS/fToFeZimG6MoHfJyQ4VMv/mplgAQSks/HkBGJ6X2KKKFSHfiJZrm0/pF8D/s zuYQeWtWdUDQzdzZoXDRefbewPOa7I0Ni1KkxZN5bhZpn4/PzMOXNDzLYt+GWLkZ4zf3 6LUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VFz1SVaL; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si11097004edr.249.2021.03.15.06.35.51; Mon, 15 Mar 2021 06:35:51 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VFz1SVaL; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229806AbhCONfT (ORCPT + 8 others); Mon, 15 Mar 2021 09:35:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbhCONfF (ORCPT ); Mon, 15 Mar 2021 09:35:05 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAE2FC06175F for ; Mon, 15 Mar 2021 06:35:05 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id n14so33368000iog.3 for ; Mon, 15 Mar 2021 06:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9wMFcNuOVXwXfZ6AijxvuqRZ/xlVmx3dzuXhVIw9piE=; b=VFz1SVaLgdPj7f1Blere5/zlo9Q2YANYLg/vbJnJntFNyuwjMP/xLfvubtjZB8V/Sm AWYVcK9wHMxEyQKxhVbWC4Csp2U8QUyrGzeCUfsOSa3jqn+ZKnWfRnvja/9vj7hJzxXK Y+wvB5WEtZHOUlvJzgo3Vg/KFMmcaHNBNWe6HlCm4QWQah72mv0s5o8CWnbBZTW2NYAX CDtHvYz9hf1ZjA3koZAwhW4Hul+LfGZPSGV1QOUnCLkswPKBtjPOvIFKIDNG+TRwje4d lWSEbKgpXo0q2zJ1aICH+Gsdc74CZSLbEp7ioUzhW2UhHkn7XZo13GkAG+fzRzjpeR2D IShw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9wMFcNuOVXwXfZ6AijxvuqRZ/xlVmx3dzuXhVIw9piE=; b=Rd7VRJy5haCiN4YcgEMhMfFNI796QpzoqTYSUnL0FwKdRgmGlk4UmysJCetAUI0+6O 80/lZiUF8U6PcYwev5TZiPfPBvnj3ygUbNpPWp0GEoa7ytSH1l6+cGSk2EmvZSj2e/wb KMrY9557K0hHAfEt7XNXfKtW4DfmA+BzOZ6weYwmbLlSOPcUGURtLtFvECahw4oWyGS4 YXKzi3ptKBMcPOXf9Hk6qCUSsYM+SG1B6gQ4eUPZvfbSE/82pqFNGQJ6E0zGaFqj+FI5 jUlh9FMdkfeaTFkvfhHP34/GgGlsiiSrV5gqA/ey3FagUsGFApRV5OlaEjME3vl/ZVh2 UMYg== X-Gm-Message-State: AOAM530fKYTfePxKI1uFr5PuSPD8/I1oa6a+mpBA/ldw3IQpOLtdPKVw QTsiSySrEXTBsAeT8NeaKdd2YA== X-Received: by 2002:a5d:93c2:: with SMTP id j2mr7444285ioo.166.1615815305317; Mon, 15 Mar 2021 06:35:05 -0700 (PDT) Received: from localhost.localdomain (c-73-185-129-58.hsd1.mn.comcast.net. [73.185.129.58]) by smtp.gmail.com with ESMTPSA id o23sm7127672ioo.24.2021.03.15.06.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 06:35:05 -0700 (PDT) From: Alex Elder To: subashab@codeaurora.org, stranche@codeaurora.org, davem@davemloft.net, kuba@kernel.org Cc: sharathv@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, cpratapa@codeaurora.org, David.Laight@ACULAB.COM, olteanv@gmail.com, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v4 6/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum header Date: Mon, 15 Mar 2021 08:34:55 -0500 Message-Id: <20210315133455.1576188-7-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315133455.1576188-1-elder@linaro.org> References: <20210315133455.1576188-1-elder@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Replace the use of C bit-fields in the rmnet_map_ul_csum_header structure with a single two-byte (big endian) structure member, and use masks to encode or get values within it. The content of these fields can be accessed using simple bitwise AND and OR operations on the (host byte order) value of the new structure member. Previously rmnet_map_ipv4_ul_csum_header() would update C bit-field values in host byte order, then forcibly fix their byte order using a combination of byte swap operations and types. Instead, just compute the value that needs to go into the new structure member and save it with a simple byte-order conversion. Make similar simplifications in rmnet_map_ipv6_ul_csum_header(). Finally, in rmnet_map_checksum_uplink_packet() a set of assignments zeroes every field in the upload checksum header. Replace that with a single memset() operation. Signed-off-by: Alex Elder --- v4: - Don't use u16_get_bits() to access the checksum field offset v3: - Use BIT(x) and don't use u16_get_bits() for single-bit flags v2: - Fixed to use u16_encode_bits() instead of be16_encode_bits(). .../ethernet/qualcomm/rmnet/rmnet_map_data.c | 34 ++++++------------- include/linux/if_rmnet.h | 21 ++++++------ 2 files changed, 21 insertions(+), 34 deletions(-) -- 2.27.0 diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c index 3df23365497c4..bdb6ab6dad83d 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -197,23 +197,19 @@ rmnet_map_ipv4_ul_csum_header(void *iphdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - __be16 *hdr = (__be16 *)ul_header; struct iphdr *ip4h = iphdr; u16 offset; + u16 val; offset = skb_transport_header(skb) - (unsigned char *)iphdr; ul_header->csum_start_offset = htons(offset); - ul_header->csum_insert_offset = skb->csum_offset; - ul_header->csum_enabled = 1; + val = MAP_CSUM_UL_ENABLED_FLAG; if (ip4h->protocol == IPPROTO_UDP) - ul_header->udp_ind = 1; - else - ul_header->udp_ind = 0; + val |= MAP_CSUM_UL_UDP_FLAG; + val |= skb->csum_offset & MAP_CSUM_UL_OFFSET_MASK; - /* Changing remaining fields to network order */ - hdr++; - *hdr = htons((__force u16)*hdr); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -240,24 +236,19 @@ rmnet_map_ipv6_ul_csum_header(void *ip6hdr, struct rmnet_map_ul_csum_header *ul_header, struct sk_buff *skb) { - __be16 *hdr = (__be16 *)ul_header; struct ipv6hdr *ip6h = ip6hdr; u16 offset; + u16 val; offset = skb_transport_header(skb) - (unsigned char *)ip6hdr; ul_header->csum_start_offset = htons(offset); - ul_header->csum_insert_offset = skb->csum_offset; - ul_header->csum_enabled = 1; - + val = MAP_CSUM_UL_ENABLED_FLAG; if (ip6h->nexthdr == IPPROTO_UDP) - ul_header->udp_ind = 1; - else - ul_header->udp_ind = 0; + val |= MAP_CSUM_UL_UDP_FLAG; + val |= skb->csum_offset & MAP_CSUM_UL_OFFSET_MASK; - /* Changing remaining fields to network order */ - hdr++; - *hdr = htons((__force u16)*hdr); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -425,10 +416,7 @@ void rmnet_map_checksum_uplink_packet(struct sk_buff *skb, } sw_csum: - ul_header->csum_start_offset = 0; - ul_header->csum_insert_offset = 0; - ul_header->csum_enabled = 0; - ul_header->udp_ind = 0; + memset(ul_header, 0, sizeof(*ul_header)); priv->stats.csum_sw++; } diff --git a/include/linux/if_rmnet.h b/include/linux/if_rmnet.h index 941997df9e088..4efb537f57f31 100644 --- a/include/linux/if_rmnet.h +++ b/include/linux/if_rmnet.h @@ -33,17 +33,16 @@ struct rmnet_map_dl_csum_trailer { struct rmnet_map_ul_csum_header { __be16 csum_start_offset; -#if defined(__LITTLE_ENDIAN_BITFIELD) - u16 csum_insert_offset:14; - u16 udp_ind:1; - u16 csum_enabled:1; -#elif defined (__BIG_ENDIAN_BITFIELD) - u16 csum_enabled:1; - u16 udp_ind:1; - u16 csum_insert_offset:14; -#else -#error "Please fix " -#endif + __be16 csum_info; /* MAP_CSUM_UL_* */ } __aligned(1); +/* csum_info field: + * OFFSET: where (offset in bytes) to insert computed checksum + * UDP: 1 = UDP checksum (zero checkum means no checksum) + * ENABLED: 1 = checksum computation requested + */ +#define MAP_CSUM_UL_OFFSET_MASK GENMASK(13, 0) +#define MAP_CSUM_UL_UDP_FLAG BIT(14) +#define MAP_CSUM_UL_ENABLED_FLAG BIT(15) + #endif /* !(_LINUX_IF_RMNET_H_) */