From patchwork Mon Mar 15 21:51:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 400559 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3784555jai; Mon, 15 Mar 2021 14:53:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1fMcaG/HD9jrXDcu++tT85sdNSmVtG2K84la9pvTCJWQIFIvuM4l0nUWa01pjjyMXHjTO X-Received: by 2002:aa7:d813:: with SMTP id v19mr19771257edq.213.1615845187783; Mon, 15 Mar 2021 14:53:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615845187; cv=none; d=google.com; s=arc-20160816; b=QCEyLlC/6j/vRD9ohsgzJmPIcpxCLC1ateNXL6Foj9fSu9RL11LfPU8aTpf9x4nYOy io1q0G8BMC826lfvkh2GDZNEBcy5t9OwBzumJmXvHOhjW3ULQzq0luR1NvAnAXIQW068 S737S167WrGrNuVGAT8TULbBD6Cw0bSoAt7UAsDCJEayFo7HWmb9FA4fADBWrjrHjY7x /wHgVK2/Rg9U7wA0VkkcF6r5UIoVidZofk+38ul7MqlvCtNRo6+hizMnQs9r6Z/OMpx5 3zZXRbG2jExPsv4rju+44SUPCWhXPipBrGl5LlIcEQWDQCoZ4/ip/5ikDT+xaieoebyP S4jw== 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=v7N6p1x0BsH0iM7+7iNRHjfZcm0BfhMj037soR+6HF4=; b=aQk/j7BNMxdYBaPaMOxqE8bvBOmiiVNBlSxPIqZrpOKDo1PEYU/PCIQ8csncRzb5aV VvHJyfsFde0zdIUFlAEwmXGijRM1uSJ01wvyL2g3H/BAgb4vWAQBP2YB6jh3qc8L3jq7 vZUBThXa2LLUHc3a9SgzDk7wDjrmati3a7lzEHrDMWn/9O2E9YWOzdUhY0fE9yVbxorw 9i+kYlS3hM99LLC+iGL1YgbnSd4tgbHI8J4LhXO+H1o9Ii6n0vk4t++OxyqInqjiJ+ti 2AxZnUTAWCyU7cgYApcevPdc9IN6UgEcoeoQ4wdLMtSYLMgUa5YwCeFSMqq27iA/83Fl 8kJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=poW1YMS4; 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 c13si12173560eje.45.2021.03.15.14.53.07; Mon, 15 Mar 2021 14:53:07 -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=poW1YMS4; 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 S234122AbhCOVwh (ORCPT + 8 others); Mon, 15 Mar 2021 17:52:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233186AbhCOVwC (ORCPT ); Mon, 15 Mar 2021 17:52:02 -0400 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46125C06175F for ; Mon, 15 Mar 2021 14:52:02 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id h18so10843554ils.2 for ; Mon, 15 Mar 2021 14:52:02 -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=v7N6p1x0BsH0iM7+7iNRHjfZcm0BfhMj037soR+6HF4=; b=poW1YMS4YSxaLKEiHkfDczYRpqjgHVgtW4F8oj4a78qxH0zHERoYJ65kHX3saRWU8p SpOhu/1bOxZlp+4PZxOMRBGzZ7LHESr7/QUG7FxrxE618vxSEn7G9lgXlNgJ2NsBgTKk gqjmxWmyL6Plw2ZRbUKZrpEzJ0Er7SCmELP2JN1vG1siq4wGMUPgI+yS7QIhKFyZ/Arm 42kAJUpxzU1EbUY2mtvYAX0e8IVnKLAZTshpovvj34m7gg21m0yx3Ahn0WAHj3nvIuwx us8ySMRvf33t20j7ObYagpY1Bx2qCbFq6a0rqSaVIZtl5y6J/tZjLuRaynAC5KTsy0eb yj8w== 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=v7N6p1x0BsH0iM7+7iNRHjfZcm0BfhMj037soR+6HF4=; b=dW0SiybYPukuOcKDPc6cSGLa8r/ldAwPVFRWycsCOvCnWNPBnlmf2AEZhnx0OS+CAx tqHxzki9FGPVUbf2w40bq+LwjbYOWvXj8MmPu1DwLJdiWO0UNafO93mgpkWzcPfIdtv6 Qvdnr9YbtSB0dHW2J1e0nDka5H+XC96CMuE/8TDLZTiXohkEfHYPT77EFiGqQHz1p83g VmXMctc6qhKja1nKfl3AWBf6B4PcEGJJZjYSsfpsdl3MsPzeQfi6e5IwascOTlA31I+9 /uWoqe3WFutk7RpGabd6IwX78nejqixpKKiQms8EadMhiduamg3aiXCSn0fGo1KVYzzt oI3Q== X-Gm-Message-State: AOAM530HwdW3bZex9AUB+GpHFiPNfmyvshP1a0ekcupp9Pdz/KYGP3cO UXKHBqnyZY/NABNOM3vBHcjsrg== X-Received: by 2002:a92:c690:: with SMTP id o16mr1375597ilg.256.1615845121704; Mon, 15 Mar 2021 14:52:01 -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 y3sm7424625iot.15.2021.03.15.14.52.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 14:52:01 -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, alexander.duyck@gmail.com, elder@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Duyck Subject: [PATCH net-next v6 6/6] net: qualcomm: rmnet: don't use C bit-fields in rmnet checksum header Date: Mon, 15 Mar 2021 16:51:51 -0500 Message-Id: <20210315215151.3029676-7-elder@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210315215151.3029676-1-elder@linaro.org> References: <20210315215151.3029676-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 Reviewed-by: Alexander Duyck --- v5: - Assign checksum start offset a little later (with csum_info) 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 | 38 +++++++------------ include/linux/if_rmnet.h | 21 +++++----- 2 files changed, 23 insertions(+), 36 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 c336c17e01fe4..0ac2ff828320c 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c @@ -197,20 +197,16 @@ 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 val; - ul_header->csum_start_offset = htons(skb_network_header_len(skb)); - 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_start_offset = htons(skb_network_header_len(skb)); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -237,21 +233,16 @@ 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 val; - ul_header->csum_start_offset = htons(skb_network_header_len(skb)); - 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_start_offset = htons(skb_network_header_len(skb)); + ul_header->csum_info = htons(val); skb->ip_summed = CHECKSUM_NONE; @@ -419,10 +410,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_) */