Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp274189rdg; Thu, 12 Oct 2023 05:32:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmVDCOCYpzMZfp6cwc8+xPX8uJ9LR87y0buLUjm1B9wQModmDRGcbQkSzyh3KZfKNQq65n X-Received: by 2002:a17:902:e550:b0:1b9:e937:9763 with SMTP id n16-20020a170902e55000b001b9e9379763mr25245321plf.12.1697113978980; Thu, 12 Oct 2023 05:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697113978; cv=none; d=google.com; s=arc-20160816; b=hPEaHEgWXSJlFnxZbj36r2XaCKtW6yF5tVacdO99d1gIBHQvnoHAJf70rdD6PWFy6Q +6EgZHSMHbn4qILkc+S4BRxRxO1s/t1G1mauOjFyDW/rKSaw6JIGjs28zQT/d/ATlkgb KA7648GGwvqKQ+xDA2ZKVWWNVsM8B6j5VdXzMWKL/ZdJWkLCkJRBMNTTwus0c2CjUeRU OIVPNNeH5G9bGwL+cin4u+SMtj5PQWQNRC/DSsqU9YMC3bh+pM0MWZWGR2dYPUtAbM/J jldKQxmz8/e2jVfX4wODnnNICCy551Yw1mjxNIp6PmZ9dx8k8O7Ih8w0orYB5Y9rr+jd ldfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=1tkwRjlYkcEjaX7ZtkQRjZiJVYqkPB3IbpRi2aMlfPI=; fh=sUzFhheJP6ORqa8FeWDqX2SGjTp2rOCbrGgrBhqE6Jk=; b=kZrapdUZz7NNgvFFU9HfOC5ZaWonIkLpOyMOrXcgl34xVTnNueuQvE/ANkbQ0qDtHI +ade2WB6DI5U0wQDDZeflWVyPnpDIFB8P0MhUjURCM1m2fecT5EKKHxgLtzqXzp+yPP/ y0CAOZk4nPOjzXiCcPqlfCXW9qx0Zq0TmaDSp3P6WyEocIpQVJgOst8vYuzkNgTe7i1t zhlR/z3zP8vNeYK9WZY8dI7+WuhF3cZ+kfo4AP0xYtsw499w+ogKNwP0CaNhSvzUE3Nr wQnWexr1tr0XzSDT/lMBOvmr426nrDUFkG2C82A9Dq+HI0LQFTFEO6Xg0yPx+Oba2OE0 Vsdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mCD2FoVp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id b6-20020a170902b60600b001c4749ee72csi2041316pls.503.2023.10.12.05.32.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 05:32:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mCD2FoVp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 42D51809AF96; Thu, 12 Oct 2023 05:32:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343983AbjJLMcq (ORCPT + 99 others); Thu, 12 Oct 2023 08:32:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235703AbjJLMcp (ORCPT ); Thu, 12 Oct 2023 08:32:45 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A028AB8 for ; Thu, 12 Oct 2023 05:32:43 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-51e24210395so13248a12.0 for ; Thu, 12 Oct 2023 05:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697113962; x=1697718762; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1tkwRjlYkcEjaX7ZtkQRjZiJVYqkPB3IbpRi2aMlfPI=; b=mCD2FoVpTdj261rfKgwlzoC761ftFnnoaye89kmQpJ5EQ+u2L5YzeZerqFdoKmudZK IWHuCDxhCbUDOT3wkkQ9DyQOqg0NWYI8XGp7Ydm/gqfX78RZ97TdOZmvy0XO0igNKURN Dl+/PtvD8/gJIC5l4OltgVlN+obblW2wMxpORTWqgNK5I6gVxD5cPNoy7bwS1sVo9Vzl PKSTEQMTRzp52xFgBMHmvwK+eUanLpssWupXQJqhIShDgvVk3jqC0zC8BFEwIZr1fLCB NZFlpB1Gei2IaFX/G/Hv7DCMsJYLu2PXe7hi/cDvSWDJ7Wk5HD3zXr7FDfIDQiy5Jkro Ep3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697113962; x=1697718762; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1tkwRjlYkcEjaX7ZtkQRjZiJVYqkPB3IbpRi2aMlfPI=; b=LH9NNT8NnLk20V7jIJEQSCH45D6LAcjJ6TEXT+ZaOJf4LPfcu28VsbpaNc2SB2jpbb S/wOQAofB6orXqf84t+PzPyt8erQVOCtgBbtpLyAhJWcXphsVc6BZYwOqkxdAqATFpu6 gxei3CIeJQoWprPWpOcT9EctIesV2i1Mdcws6dkh9D3vxWL5wGe1NrQ4nXsv/nh3A1XF 10muYNxMKc7U7ZfH7yAThnFCkYr6c3QET8jagHzMhkU22dOxO4YevX4jB0klI4fO+ffm Dbt4BraHVrmzTHKqgiFbaD94QUNQJ+iTwN3MchrhQQZufP4bAVNeAhS5yGGJq1OCGhNU 6laQ== X-Gm-Message-State: AOJu0Yy7Zudg40iCYj/2cybitPaQFxjoyEre2dUdIcVe4+x0ckL2d3Mm +o52HkZHxsaJ3RBwjsdu0fixIsux3lCi/sfV/rw7oIsjxm4WTpAnlVg= X-Received: by 2002:a50:c355:0:b0:52e:f99a:b5f8 with SMTP id q21-20020a50c355000000b0052ef99ab5f8mr244799edb.7.1697113961951; Thu, 12 Oct 2023 05:32:41 -0700 (PDT) MIME-Version: 1.0 References: <20231009142005.21338-1-quic_kriskura@quicinc.com> <20231009142005.21338-2-quic_kriskura@quicinc.com> In-Reply-To: From: =?UTF-8?Q?Maciej_=C5=BBenczykowski?= Date: Thu, 12 Oct 2023 05:32:22 -0700 Message-ID: Subject: Re: [PATCH 2/2] usb: gadget: ncm: Add support to update wMaxSegmentSize via configfs To: Krishna Kurapati PSSNV Cc: Greg Kroah-Hartman , onathan Corbet , Linyu Yuan , linux-usb@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, quic_ppratap@quicinc.com, quic_wcheng@quicinc.com, quic_jackp@quicinc.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 12 Oct 2023 05:32:56 -0700 (PDT) On Thu, Oct 12, 2023 at 1:48=E2=80=AFAM Krishna Kurapati PSSNV wrote: > > > > On 10/10/2023 10:08 AM, Krishna Kurapati PSSNV wrote: > > > > >> > >> ^ is this a problem now if we have >1 gadget? > >> how does it work then? > > > > > > You are right. This would effect unwrap call and the wMaxSegmentSize is > > used directly. Thanks for the catch. I didn't test with 2 NCM interface= s > > and hence I wasn't able to find this bug. Perhaps changing this to > > opts->max_segment_size would fix the implementation as unwrap would > > anyways be called after bind. > > Hi Maciej, > > How about the below diff: > > --------- > > +/* > + * Allow max segment size to be in parity with max_mtu possible > + * for the interface. > + */ > +#define MAX_DATAGRAM_SIZE GETHER_MAX_ETH_FRAME_LEN > + > #define FORMATS_SUPPORTED (USB_CDC_NCM_NTB16_SUPPORTED | \ > USB_CDC_NCM_NTB32_SUPPORTED) > > @@ -194,7 +200,6 @@ static struct usb_cdc_ether_desc ecm_desc =3D { > /* this descriptor actually adds value, surprise! */ > /* .iMACAddress =3D DYNAMIC */ > .bmEthernetStatistics =3D cpu_to_le32(0), /* no statistics */ > - .wMaxSegmentSize =3D cpu_to_le16(ETH_FRAME_LEN), > .wNumberMCFilters =3D cpu_to_le16(0), > .bNumberPowerFilters =3D 0, > }; > @@ -1180,10 +1185,15 @@ static int ncm_unwrap_ntb(struct gether *port, > struct sk_buff *skb2; > int ret =3D -EINVAL; > unsigned ntb_max =3D > le32_to_cpu(ntb_parameters.dwNtbOutMaxSize); > - unsigned frame_max =3D le16_to_cpu(ecm_desc.wMaxSegmentSiz= e); > + unsigned int frame_max; > const struct ndp_parser_opts *opts =3D ncm->parser_opts; > unsigned crc_len =3D ncm->is_crc ? sizeof(uint32_t) : 0; > int dgram_counter; > + struct f_ncm_opts *ncm_opts; > + const struct usb_function_instance *fi =3D port->func.fi; > + > + ncm_opts =3D container_of(fi, struct f_ncm_opts, func_inst); > + frame_max =3D ncm_opts->max_segment_size; > > /* dwSignature */ > if (get_unaligned_le32(tmp) !=3D opts->nth_sign) { > @@ -1440,6 +1450,7 @@ static int ncm_bind(struct usb_configuration *c, > struct usb_function *f) > */ > if (!ncm_opts->bound) { > mutex_lock(&ncm_opts->lock); > + ncm_opts->net->mtu =3D (ncm_opts->max_segment_size - > ETH_HLEN); > gether_set_gadget(ncm_opts->net, cdev->gadget); > status =3D gether_register_netdev(ncm_opts->net); > mutex_unlock(&ncm_opts->lock); > @@ -1484,6 +1495,8 @@ static int ncm_bind(struct usb_configuration *c, > struct usb_function *f) > > status =3D -ENODEV; > > + ecm_desc.wMaxSegmentSize =3D (__le16)ncm_opts->max_segment_size; this looks wrong. pretty sure this should be some form of cpu_to_le16 > + > > ------ > > I can limit the max segment size to (Max MTU + ETH_HELN) and this would > be logical to do. Also we can set the frame_max from ncm_opts itself > while initializing it to 1514 (default value) during alloc_inst callback > and nothing would break while still being backward compatible. > > Let me know your thoughts on this. > > Regards, > Krishna, Could you paste the full patch? This is hard to review without looking at much more context then email is providing (or, even better, send me a link to a CL in gerrit somewhere - for example aosp ACK mainline tree)