From patchwork Mon Mar 29 15:18:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 410860 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3701677jai; Mon, 29 Mar 2021 08:10:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz93TTu6DIRQwAq+zw+sj2s8wSQrAE3fsoXlw+1L5aNiZQcNxpp8bEyfNo51ORCHoqAV+R/ X-Received: by 2002:a17:906:6d8e:: with SMTP id h14mr28871417ejt.410.1617030642134; Mon, 29 Mar 2021 08:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617030642; cv=none; d=google.com; s=arc-20160816; b=0n0avyDb4I7o3NR/P+ztiWvNKJrlzHJHq8wKRmSvc/h1cIFyFD72aAMZVbdHIHvvOm tgd+kUjD7zzKNIgX3vmUApKhTqB/ewPjCVmSWjVWmOFyqFw+tOkqGmyw59Pigj5qFAcm eG6G4Pj+PUjgIErTfkVqhn9e6pnEgKCnZ1Evu6t5LxU4e//ab5de5xBsK2hnzTKy8ijL NTEhwaNHivvxLwSMQvylUkvAy5SFPQbHdANuDPU1avIgTBTTcJ7iZ33kww3x5AKVUVKT bge5x4t47Efi3oARSoliJlP8UnyXphBqb6rT7G37p6tjYoBuVdIgMZ5xleAWiefY1I1t Jcgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=tOvOPLVCfwLiB7xIEPiMjsyZHcZMpEfWNqr4+JSwO0c=; b=AMIDYp0hSAqobr/SrGyqtCHxgJQX6tCBSw+uj3Lttp9m9yXx3McdmWEj7rHAeT87W4 Tyd8qAl9MX+VvOXGQYAPP6991HzKpp72MGHlUK/rqkeHDhjKYp/vIOMEScgW1Gplukwq 8C7uUNfr9lrg7XMV8MDdkQBmpXDb2qK4YLjmY8QwGV6Te28PV0+Abqwt4i6BSe3ZMiJy 7tQOUpuE07Fttk1dWdVPxzlwP3s81Rp6Kg1nVDG6FC4bdDLC0ViGCr8CFUkxMYnF3cHe CnsjfuOZ1XwLrf4JgE67VyovOsOBftSwUF+Da7Gtt+eDMdIN3ROUqpJ5QkFyYrL6MPTA 0z6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="JrlhhBc/"; 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 t4si12886616ejd.376.2021.03.29.08.10.41; Mon, 29 Mar 2021 08:10:42 -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="JrlhhBc/"; 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 S230397AbhC2PKL (ORCPT + 8 others); Mon, 29 Mar 2021 11:10:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbhC2PJp (ORCPT ); Mon, 29 Mar 2021 11:09:45 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3E7DC061574 for ; Mon, 29 Mar 2021 08:09:44 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id c8so13202027wrq.11 for ; Mon, 29 Mar 2021 08:09:44 -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; bh=tOvOPLVCfwLiB7xIEPiMjsyZHcZMpEfWNqr4+JSwO0c=; b=JrlhhBc/BkL6VZkGdEI6LjvjPNV1Oov0v49OcxHgaR5w5XbMJMq5+UAjo1wnH6yW7L Pobsz3YqjxFrgNHq+f2TUOr5V63GYiNtUB25SPDnL3qz0VaIMrlSAVwf/T1/wkwtynCP 5Yx8sg/uo3KLwHGCIaGAKDBmY1I1nuuzDk3abb86yCGZCf4YreoIKKryo1P+IDUj9Qc0 kub12402cCn/s1FqnOBJ/cnGiL6yZCd0D82fjh1OjRD+XzFZVVguM+9k50vb6HI2duMg c7xSTjxu8+/Il6v4/sfh4rWwearD2m7up0ecN/pqy8KiASF9Vs+2Z2C88xxMmiJgyEm2 lGjw== 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; bh=tOvOPLVCfwLiB7xIEPiMjsyZHcZMpEfWNqr4+JSwO0c=; b=jcCEsQRMhAqIPaoeWJzd8mAWWEtK1Xi9HcqOxKlzsM5GRwf96FQjVQbRWVpJ4opgm/ 5gQ+81z38q4gRqWnIkzXjm/bqD3EcHpfIdLM+hLdY9ik/B0VBRGXtHHnFx+RPkGBKG8J hzJy1mP6nfL+82LoZ4cDQttq0dfYbdEBPQVbe2sgt1+QhPaweKiOfOdunEcam7ffpKFC 09qwYePO/JYzkUrd1ZYhZUP3nc1ICHMbIbYI2TpEvYbXxqYNfZV3gCBg3e96UH0j55Q6 SLSDTcZwuZ2qLBXUWCJJRd8To1N6mm01nkYp61x/+BbDWs55ud8ihiWlnRMuprNVLho8 doPg== X-Gm-Message-State: AOAM533CUatSbISlXspQEnx2PGXd982BL1wZR2uwkBud/yVkm8zJySvy R6j/z/XwrPzfCsC4u+eNzRlr5w== X-Received: by 2002:adf:f005:: with SMTP id j5mr28363939wro.423.1617030583633; Mon, 29 Mar 2021 08:09:43 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:82c:5f0:e89:f257:8111:afb6]) by smtp.gmail.com with ESMTPSA id x11sm24963636wmi.3.2021.03.29.08.09.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Mar 2021 08:09:42 -0700 (PDT) From: Loic Poulain To: kuba@kernel.org, davem@davemloft.net Cc: netdev@vger.kernel.org, Loic Poulain Subject: [PATCH net-next v2 1/2] net: mhi: Add support for non-linear MBIM skb processing Date: Mon, 29 Mar 2021 17:18:24 +0200 Message-Id: <1617031105-3147-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, if skb is non-linear, due to MHI skb chaining, it is linearized in MBIM RX handler prior MBIM decoding, causing extra allocation and copy that can be as large as the maximum MBIM frame size (32K). This change introduces MBIM decoding for non-linear skb, allowing to process 'large' non-linear MBIM packets without skb linearization. The IP packets are simply extracted from the MBIM frame using the skb_copy_bits helper. Signed-off-by: Loic Poulain --- v2: added to the series for reducing chained skb processing overhead drivers/net/mhi/proto_mbim.c | 50 +++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 26 deletions(-) -- 2.7.4 diff --git a/drivers/net/mhi/proto_mbim.c b/drivers/net/mhi/proto_mbim.c index 75b5484..10ffb97 100644 --- a/drivers/net/mhi/proto_mbim.c +++ b/drivers/net/mhi/proto_mbim.c @@ -91,20 +91,11 @@ static int mbim_rx_verify_nth16(struct sk_buff *skb) return le16_to_cpu(nth16->wNdpIndex); } -static int mbim_rx_verify_ndp16(struct sk_buff *skb, int ndpoffset) +static int mbim_rx_verify_ndp16(struct sk_buff *skb, struct usb_cdc_ncm_ndp16 *ndp16) { struct mhi_net_dev *dev = netdev_priv(skb->dev); - struct usb_cdc_ncm_ndp16 *ndp16; int ret; - if (ndpoffset + sizeof(struct usb_cdc_ncm_ndp16) > skb->len) { - netif_dbg(dev, rx_err, dev->ndev, "invalid NDP offset <%u>\n", - ndpoffset); - return -EINVAL; - } - - ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb->data + ndpoffset); - if (le16_to_cpu(ndp16->wLength) < USB_CDC_NCM_NDP16_LENGTH_MIN) { netif_dbg(dev, rx_err, dev->ndev, "invalid DPT16 length <%u>\n", le16_to_cpu(ndp16->wLength)); @@ -130,9 +121,6 @@ static void mbim_rx(struct mhi_net_dev *mhi_netdev, struct sk_buff *skb) struct net_device *ndev = mhi_netdev->ndev; int ndpoffset; - if (skb_linearize(skb)) - goto error; - /* Check NTB header and retrieve first NDP offset */ ndpoffset = mbim_rx_verify_nth16(skb); if (ndpoffset < 0) { @@ -142,12 +130,18 @@ static void mbim_rx(struct mhi_net_dev *mhi_netdev, struct sk_buff *skb) /* Process each NDP */ while (1) { - struct usb_cdc_ncm_ndp16 *ndp16; - struct usb_cdc_ncm_dpe16 *dpe16; - int nframes, n; + struct usb_cdc_ncm_ndp16 ndp16; + struct usb_cdc_ncm_dpe16 dpe16; + int nframes, n, dpeoffset; + + if (skb_copy_bits(skb, ndpoffset, &ndp16, sizeof(ndp16))) { + net_err_ratelimited("%s: Incorrect NDP offset (%u)\n", ndpoffset); + __mbim_length_errors_inc(mhi_netdev); + goto error; + } /* Check NDP header and retrieve number of datagrams */ - nframes = mbim_rx_verify_ndp16(skb, ndpoffset); + nframes = mbim_rx_verify_ndp16(skb, &ndp16); if (nframes < 0) { net_err_ratelimited("%s: Incorrect NDP16\n", ndev->name); __mbim_length_errors_inc(mhi_netdev); @@ -155,8 +149,7 @@ static void mbim_rx(struct mhi_net_dev *mhi_netdev, struct sk_buff *skb) } /* Only IP data type supported, no DSS in MHI context */ - ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb->data + ndpoffset); - if ((ndp16->dwSignature & cpu_to_le32(MBIM_NDP16_SIGN_MASK)) + if ((ndp16.dwSignature & cpu_to_le32(MBIM_NDP16_SIGN_MASK)) != cpu_to_le32(USB_CDC_MBIM_NDP16_IPS_SIGN)) { net_err_ratelimited("%s: Unsupported NDP type\n", ndev->name); __mbim_errors_inc(mhi_netdev); @@ -164,19 +157,24 @@ static void mbim_rx(struct mhi_net_dev *mhi_netdev, struct sk_buff *skb) } /* Only primary IP session 0 (0x00) supported for now */ - if (ndp16->dwSignature & ~cpu_to_le32(MBIM_NDP16_SIGN_MASK)) { + if (ndp16.dwSignature & ~cpu_to_le32(MBIM_NDP16_SIGN_MASK)) { net_err_ratelimited("%s: bad packet session\n", ndev->name); __mbim_errors_inc(mhi_netdev); goto next_ndp; } /* de-aggregate and deliver IP packets */ - dpe16 = ndp16->dpe16; - for (n = 0; n < nframes; n++, dpe16++) { - u16 dgram_offset = le16_to_cpu(dpe16->wDatagramIndex); - u16 dgram_len = le16_to_cpu(dpe16->wDatagramLength); + dpeoffset = ndpoffset + sizeof(struct usb_cdc_ncm_ndp16); + for (n = 0; n < nframes; n++, dpeoffset += sizeof(dpe16)) { + u16 dgram_offset, dgram_len; struct sk_buff *skbn; + if (skb_copy_bits(skb, dpeoffset, &dpe16, sizeof(dpe16))) + break; + + dgram_offset = le16_to_cpu(dpe16.wDatagramIndex); + dgram_len = le16_to_cpu(dpe16.wDatagramLength); + if (!dgram_offset || !dgram_len) break; /* null terminator */ @@ -185,7 +183,7 @@ static void mbim_rx(struct mhi_net_dev *mhi_netdev, struct sk_buff *skb) continue; skb_put(skbn, dgram_len); - memcpy(skbn->data, skb->data + dgram_offset, dgram_len); + skb_copy_bits(skb, dgram_offset, skbn->data, dgram_len); switch (skbn->data[0] & 0xf0) { case 0x40: @@ -206,7 +204,7 @@ static void mbim_rx(struct mhi_net_dev *mhi_netdev, struct sk_buff *skb) } next_ndp: /* Other NDP to process? */ - ndpoffset = (int)le16_to_cpu(ndp16->wNextNdpIndex); + ndpoffset = (int)le16_to_cpu(ndp16.wNextNdpIndex); if (!ndpoffset) break; } From patchwork Mon Mar 29 15:18:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 410861 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp3701685jai; Mon, 29 Mar 2021 08:10:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdcZQiXyuFRFHeAmUd2dm3LNsTK/R5u5lUvPGpYaS7KTcqkiSNVIL0sTklJJ8T4EL9/u4y X-Received: by 2002:a17:906:2e45:: with SMTP id r5mr28085641eji.380.1617030642532; Mon, 29 Mar 2021 08:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617030642; cv=none; d=google.com; s=arc-20160816; b=hxNvEk6IrDzruf78qJsM7eZgUt0gorRmHbcWIfgrXhoVTIl1TIq5Fdl3159vEpzGD1 s9Z/THZzkZO9BUteO4b60hG4hIJK7r/8MZztFscpmhDPERoXHE6dj4Kt4xQtqpoArbf/ yOQtFe19DTQ4RskYz9aLoIn5/PJl/EUlfcO00OetmfYCnaCcduLs8Kh5+p7A1UmVoDd0 Z0UvX6iGKxqWKDIo5jCfimEbsVb1KsdAMT6XCZQqKNVSYrs2fr3s+J8dt4TSU6wyQr/3 5T87PAuvn+NjQdJ+9xt+MBPeUdIC8s5t/pjANkm2BFsVbwXvHjd5KTQMwE6X8Sxt/dOX hLTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=+X/hKTZh40f/grnF7BdEW6HAu8wuo4fpxyd9sGXZx8Q=; b=0rlLucxQT6RKilvG6dioeUg0n2tgOlqQibC86PdmPNnQAd5D3UanFmp3wTTY7oLMMq R+oCHYsQcRYJyGoVbp4C0dR5pmUNSGJtFveSsFhGgDw3y8XJ2oujJDmgyIDVK9RFnuSs tn/o9F8S9hhGW17jhTa9gfdIWyKV2tDvX7ecy0R6DHG7CrAv/TG+V1rYXLslscOCCtIF 4BQP5VBxZ34sBC6CFAVY5B7Rg3bbJd1gPxUdTv8J/suCDUa5ajmL631UlGDFBmGq5lNb KNcLUwc2ZEyyow0cELk4tw4vt64ownyJNitmkBS8MULSMp0va9/V9BBIya+9braJWrpp cafQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QZ++iBuH; 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 t4si12886616ejd.376.2021.03.29.08.10.42; Mon, 29 Mar 2021 08:10:42 -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=QZ++iBuH; 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 S230402AbhC2PKN (ORCPT + 8 others); Mon, 29 Mar 2021 11:10:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230248AbhC2PJx (ORCPT ); Mon, 29 Mar 2021 11:09:53 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAED5C061574 for ; Mon, 29 Mar 2021 08:09:52 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id d8-20020a1c1d080000b029010f15546281so8706793wmd.4 for ; Mon, 29 Mar 2021 08:09:52 -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; bh=+X/hKTZh40f/grnF7BdEW6HAu8wuo4fpxyd9sGXZx8Q=; b=QZ++iBuHwzRhONRzeQg8IMTGg8a14AW0TeGqUrA7MszWwzDoJ57k6eb7R4fuWfQFSi bbAdveCnnrh2RG76mVRgSCHHu2phUoqqLoxsuk3XZb2WGFA9f+40k15OajiNugSBg0YO NT/n+PaN3EXInGC12S1nYX2SSJuG2UzT830BV8msUV8LcI/zQOeIgM4B5WpAKYpgoVwn H8x4FFxzpcCyL9OUh/nbRqHU9GtHPdNz8KHGtGO/tLwMc6R9OLYOd4iKMOE6u3A6fAUL sSy5KttzX+zunsw2V0/917Md66Ej0rjnb90YmCBY14+2ykSc0ooc9Cb6z1F+GWS426xd 1bZA== 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; bh=+X/hKTZh40f/grnF7BdEW6HAu8wuo4fpxyd9sGXZx8Q=; b=ihPGcTf7hJJlacfCOkFbjyc393fuvbKMk+CJkBKXpRTyqjd1nDqTbIbfKFmPEmksRL kjWsiTbQO6WRpfX7y4t64xF+znEJ9O35mDuVlaCPaoA7MIN0S8gdV0ZUmSVKd9FQb2M4 Qe/oCUTssoZNFjflLwNVFkCcy3wwhcRiAXYsPt2KKi6FwUeO350YyIZZn8+SeiTf5XgI H+TJs63shFCDKemOchS0yW7iTP9m6a45NqqRBCiZNh2QWbKjkI3eS0dQinAwqAAQyAdN OL/pN7LY8uOtAxUeYYkE26nfAsuhJ24Yb9NrEeH4Tw1VjOMBj9dHeepD3+stvdXVeimF Khsw== X-Gm-Message-State: AOAM532L6Ro9CfqSKmnkhvsdSmVb6FC9LhmL9LIgQg/pokql16XpBKx6 5pK1Gz8So9MM3LViphDKE08Uqg== X-Received: by 2002:a7b:cdf7:: with SMTP id p23mr25412470wmj.26.1617030591610; Mon, 29 Mar 2021 08:09:51 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:82c:5f0:e89:f257:8111:afb6]) by smtp.gmail.com with ESMTPSA id x11sm24963636wmi.3.2021.03.29.08.09.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Mar 2021 08:09:51 -0700 (PDT) From: Loic Poulain To: kuba@kernel.org, davem@davemloft.net Cc: netdev@vger.kernel.org, Loic Poulain Subject: [PATCH net-next v2 2/2] net: mhi: Allow decoupled MTU/MRU Date: Mon, 29 Mar 2021 17:18:25 +0200 Message-Id: <1617031105-3147-2-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1617031105-3147-1-git-send-email-loic.poulain@linaro.org> References: <1617031105-3147-1-git-send-email-loic.poulain@linaro.org> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org MBIM protocol makes the mhi network interface asymmetric, ingress data received from MHI is MBIM protocol, possibly containing multiple aggregated IP packets, while egress data received from network stack is IP protocol. This changes allows a 'protocol' to specify its own MRU, that when specified is used to allocate MHI RX buffers (skb). For MBIM, Set the default MTU to 1500, which is the usual network MTU for WWAN IP packets, and MRU to 3.5K (for allocation efficiency), allowing skb to fit in an usual 4K page (including padding, skb_shared_info, ...). Signed-off-by: Loic Poulain --- v2: squashed 1/2 and 1/2 (decoupled mtu/mru + mbim mru) Reduced MRU from 32k to 3.5K drivers/net/mhi/mhi.h | 1 + drivers/net/mhi/net.c | 4 +++- drivers/net/mhi/proto_mbim.c | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/net/mhi/mhi.h b/drivers/net/mhi/mhi.h index 12e7407..1d0c499 100644 --- a/drivers/net/mhi/mhi.h +++ b/drivers/net/mhi/mhi.h @@ -29,6 +29,7 @@ struct mhi_net_dev { struct mhi_net_stats stats; u32 rx_queue_sz; int msg_enable; + unsigned int mru; }; struct mhi_net_proto { diff --git a/drivers/net/mhi/net.c b/drivers/net/mhi/net.c index b1769fb..4bef7fe 100644 --- a/drivers/net/mhi/net.c +++ b/drivers/net/mhi/net.c @@ -270,10 +270,12 @@ static void mhi_net_rx_refill_work(struct work_struct *work) rx_refill.work); struct net_device *ndev = mhi_netdev->ndev; struct mhi_device *mdev = mhi_netdev->mdev; - int size = READ_ONCE(ndev->mtu); struct sk_buff *skb; + unsigned int size; int err; + size = mhi_netdev->mru ? mhi_netdev->mru : READ_ONCE(ndev->mtu); + while (!mhi_queue_is_full(mdev, DMA_FROM_DEVICE)) { skb = netdev_alloc_skb(ndev, size); if (unlikely(!skb)) diff --git a/drivers/net/mhi/proto_mbim.c b/drivers/net/mhi/proto_mbim.c index 10ffb97..a1df2f6 100644 --- a/drivers/net/mhi/proto_mbim.c +++ b/drivers/net/mhi/proto_mbim.c @@ -26,6 +26,15 @@ #define MBIM_NDP16_SIGN_MASK 0x00ffffff +/* Usual WWAN MTU */ +#define MHI_MBIM_DEFAULT_MTU 1500 + +/* 3500 allows to optimize skb allocation, the skbs will basically fit in + * one 4K page. Large MBIM packets will simply be split over several MHI + * transfers and chained by the MHI net layer (zerocopy). + */ +#define MHI_MBIM_DEFAULT_MRU 3500 + struct mbim_context { u16 rx_seq; u16 tx_seq; @@ -280,6 +289,8 @@ static int mbim_init(struct mhi_net_dev *mhi_netdev) return -ENOMEM; ndev->needed_headroom = sizeof(struct mbim_tx_hdr); + ndev->mtu = MHI_MBIM_DEFAULT_MTU; + mhi_netdev->mru = MHI_MBIM_DEFAULT_MRU; return 0; }