Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2210405rdb; Mon, 9 Oct 2023 17:21:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFeYcigawU92TNDkCpNDPxl4NlcIz4RxGrRCljd+JNIZ9MCNJer80OskHbMJfbVxatVSrw X-Received: by 2002:a05:6358:722:b0:14b:9537:b18e with SMTP id e34-20020a056358072200b0014b9537b18emr17177047rwj.7.1696897270478; Mon, 09 Oct 2023 17:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696897270; cv=none; d=google.com; s=arc-20160816; b=mPHpdom0iXuARZYJ5blX+M+tKrQaNrMW7lA1uEMa4t6hVbza+Vof09J0FADFa6snlc Qa9+sqNVYnPE6V5RRrrrpoJ+R+d7E5h/oCr3OJj0EcvZ0uyNUIu+FoxnuhZHC29ZQUID 69Hia/q0a3PxjoOE1uuuV6JDJ0V+y61jGQ6v5Eq34diwVzz9q7UBbf33aWMoQ2l7QxAw +NtBaxesfN3dEKrPuif7IOxGvM2uGsHapSWbo1QCr4lxObmbGo2/8sgFeTaWQtqU//kW GSJbbBcxShEtdQz2Oa+JAyc6jnEXwGlv/CSea5M/F6XLa2lOfyKdgoOqWFD2wbYgs/uE pZSg== 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=rDqndGGh7MZCzNbyA7vFVrmWG4+Liupi5noCib/AUdM=; fh=y1/5TSIVXHZtUBXoXu6dbqD4lnaxmJFoBy9NDKn3tJY=; b=XD+b8ajzkEPVs/n/dVmbS68vY39pNQgO9QuWfxi+qtWxib0BKHlKWEcPJxhhouLdxv Y0If6JXhAkgAGIZx1dXI9mr1URdFxf6TVklTTh5BXO33GfLMnF6n++OO6QJmttvIuuvm EtXLTlEfUuciVJmDmMzDFY4f9oNu1nmxvDaoAM9MkbAe9bzjMXQ9A3xFbHZlvMiX1jI1 nwOUpC+O0Zh2sa7coWCIhlFkT8sxp1UiETrdvAPDJ/dBzYyytR/KYUFO9mSHHA2K0aHz z5qP0L0U8VvaUnVRRwR8rGGssxOPfJMyA3PJOk0jPM83Su4FaFb5BPrfv75p+Eu9Uifh igFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=q1L2Ew8S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id x5-20020a654145000000b00569362d6cebsi5483406pgp.2.2023.10.09.17.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 17:21:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=q1L2Ew8S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 8B06281D6DA9; Mon, 9 Oct 2023 17:21:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379138AbjJJAUu (ORCPT + 99 others); Mon, 9 Oct 2023 20:20:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379131AbjJJAUt (ORCPT ); Mon, 9 Oct 2023 20:20:49 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B20C9A9 for ; Mon, 9 Oct 2023 17:20:46 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-51e24210395so26099a12.0 for ; Mon, 09 Oct 2023 17:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696897245; x=1697502045; 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=rDqndGGh7MZCzNbyA7vFVrmWG4+Liupi5noCib/AUdM=; b=q1L2Ew8S8aTwsyoTDNwzGp7wlHxHuUCJWhRTVNlUVtfKSf5A6U2wBHGK5uqPVyFYpc iIRQ7vrgC5ZyMr/I4vLf037s4/1/7DiBN4AGlgEwP1vMR48pCLpvW+YEXvFUsSs5UFJJ p4DNjfPrDKR/qwH4EPBgNn1i1dmobJtCIr62k81YCNTL8ZLBFe27VbvI3Cq2pU7y4oT1 BCOsb0FR55NAGG3Fo5tw+hPJUFe36uEY34hQA0ud4rHdtIrQEdil3ZKbTd1C8Qtk6x4+ 7u0ZZYe/A3fV8uyD/BMNHHrOpxNjAEJia0TwmoQZazl7SL6qFzyEQMFCoPg73ZSMuJR8 KWkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696897245; x=1697502045; 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=rDqndGGh7MZCzNbyA7vFVrmWG4+Liupi5noCib/AUdM=; b=cNMmN+LhNnXqyo5+fd1jIRnxFrMFALwe9kQmA/GVY1Wl+60lWmM96qi7AMjZ6L80qs WWrLUKI7X/28S0XisA8Dha8n+xaxkz3kza7QJg9Py2Sz1+npfBrEN2wjNI/3tYrL0n5s dgwPNyjERccEePCPIEGiz432Vx/usOS1w3N4zctYCxpLGb6J2P6EInEyW/s+p3J9B21v ilWzkSG+uqDAeIBCUBpaI+MOkkz+bIzSn0Yyo/7TtKmehDS2LGPJTeht2j0dnIXC0UzT Mku7CEfLowDVYNyevSLHHqxTlY9nmxQl3p9CI1OOUtHciUGYDEV8bYmwXUVZJsQPkHd3 qASg== X-Gm-Message-State: AOJu0YyRR9iYiiBB7rJHvNoVL6aFJ8KcnUSTN2ofmxXRtIbxPN5552bZ 7vrzHNJXANHC/r3QEFkPVy3EZeu5pgCqnOzWMX/QPA== X-Received: by 2002:a50:c051:0:b0:538:1d3a:d704 with SMTP id u17-20020a50c051000000b005381d3ad704mr466255edd.1.1696897244899; Mon, 09 Oct 2023 17:20:44 -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: Mon, 9 Oct 2023 17:20:33 -0700 Message-ID: Subject: Re: [PATCH 2/2] usb: gadget: ncm: Add support to update wMaxSegmentSize via configfs To: Krishna Kurapati 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=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Mon, 09 Oct 2023 17:21:07 -0700 (PDT) On Mon, Oct 9, 2023 at 5:17=E2=80=AFPM Maciej =C5=BBenczykowski wrote: > > On Mon, Oct 9, 2023 at 7:20=E2=80=AFAM Krishna Kurapati > wrote: > > > > Currently the NCM driver restricts wMaxSegmentSize that indicates > > the datagram size coming from network layer to 1514. However the > > spec doesn't have any limitation. For P2P connections over NCM, > > increasing MTU helps increasing throughput. > > > > Add support to configure this value before configfs symlink is > > created. Also since the NTB Out/In buffer sizes are fixed at 16384 > > bytes, limit the segment size to an upper cap of 15014. Set the > > default MTU size for the ncm interface during function bind before > > network interface is registered allowing MTU to be set in parity > > with wMaxSegmentSize. > > > > Signed-off-by: Krishna Kurapati > > --- > > drivers/usb/gadget/function/f_ncm.c | 51 +++++++++++++++++++++++++++++ > > drivers/usb/gadget/function/u_ncm.h | 2 ++ > > 2 files changed, 53 insertions(+) > > > > diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/f= unction/f_ncm.c > > index feccf4c8cc4f..eab297b22200 100644 > > --- a/drivers/usb/gadget/function/f_ncm.c > > +++ b/drivers/usb/gadget/function/f_ncm.c > > @@ -103,6 +103,8 @@ static inline struct f_ncm *func_to_ncm(struct usb_= function *f) > > /* Delay for the transmit to wait before sending an unfilled NTB frame= . */ > > #define TX_TIMEOUT_NSECS 300000 > > > > +#define MAX_DATAGRAM_SIZE 15014 > > + > > #define FORMATS_SUPPORTED (USB_CDC_NCM_NTB16_SUPPORTED | \ > > USB_CDC_NCM_NTB32_SUPPORTED) > > > > @@ -1408,6 +1410,7 @@ static int ncm_bind(struct usb_configuration *c, = struct usb_function *f) > > ncm_opts =3D container_of(f->fi, struct f_ncm_opts, func_inst); > > > > if (cdev->use_os_string) { > > + ncm_opts->net->mtu =3D (ncm_opts->max_segment_size - ET= H_HLEN); > > f->os_desc_table =3D kzalloc(sizeof(*f->os_desc_table), > > GFP_KERNEL); > > if (!f->os_desc_table) > > @@ -1469,6 +1472,8 @@ static int ncm_bind(struct usb_configuration *c, = struct usb_function *f) > > > > status =3D -ENODEV; > > > > + ecm_desc.wMaxSegmentSize =3D ncm_opts->max_segment_size; > > I think you need byte swap here. > > > + > > /* allocate instance-specific endpoints */ > > ep =3D usb_ep_autoconfig(cdev->gadget, &fs_ncm_in_desc); > > if (!ep) > > @@ -1569,11 +1574,56 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm); > > /* f_ncm_opts_ifname */ > > USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm); > > > > +static ssize_t ncm_opts_max_segment_size_show(struct config_item *item= , > > + char *page) > > +{ > > + struct f_ncm_opts *opts =3D to_f_ncm_opts(item); > > + u32 segment_size; > > + > > + mutex_lock(&opts->lock); > > + segment_size =3D opts->max_segment_size; > > + mutex_unlock(&opts->lock); > > + > > + return sprintf(page, "%u\n", segment_size); > > +} > > + > > +static ssize_t ncm_opts_max_segment_size_store(struct config_item *ite= m, > > + const char *page, size_t= len) > > +{ > > + struct f_ncm_opts *opts =3D to_f_ncm_opts(item); > > + int ret; > > + u32 segment_size; > > + > > + mutex_lock(&opts->lock); > > + if (opts->refcnt) { > > + ret =3D -EBUSY; > > + goto out; > > + } > > + > > + ret =3D kstrtou32(page, 0, &segment_size); > > + if (ret) > > + goto out; > > + > > + if (segment_size > MAX_DATAGRAM_SIZE) { > > + ret =3D -EINVAL; > > + goto out; > > + } > > + > > + opts->max_segment_size =3D segment_size; > > + ret =3D len; > > +out: > > + mutex_unlock(&opts->lock); > > + return ret; > > +} > > + > > +CONFIGFS_ATTR(ncm_opts_, max_segment_size); > > + > > static struct configfs_attribute *ncm_attrs[] =3D { > > &ncm_opts_attr_dev_addr, > > &ncm_opts_attr_host_addr, > > &ncm_opts_attr_qmult, > > &ncm_opts_attr_ifname, > > + &ncm_opts_attr_max_segment_size, > > NULL, > > }; > > > > @@ -1616,6 +1666,7 @@ static struct usb_function_instance *ncm_alloc_in= st(void) > > kfree(opts); > > return ERR_CAST(net); > > } > > + opts->max_segment_size =3D cpu_to_le16(ETH_FRAME_LEN); > > and not here. ie. max_segment_size should be native endian > > > INIT_LIST_HEAD(&opts->ncm_os_desc.ext_prop); > > > > descs[0] =3D &opts->ncm_os_desc; > > diff --git a/drivers/usb/gadget/function/u_ncm.h b/drivers/usb/gadget/f= unction/u_ncm.h > > index 5408854d8407..d3403cf13f17 100644 > > --- a/drivers/usb/gadget/function/u_ncm.h > > +++ b/drivers/usb/gadget/function/u_ncm.h > > @@ -31,6 +31,8 @@ struct f_ncm_opts { > > */ > > struct mutex lock; > > int refcnt; > > + > > + u32 max_segment_size; > > }; > > > > #endif /* U_NCM_H */ > > -- > > 2.42.0 > > > > That said, I don't really follow what this is doing... Also static struct usb_cdc_ether_desc ecm_desc =3D { ... .wMaxSegmentSize =3D cpu_to_le16(ETH_FRAME_LEN), ^ I think this should be deleted now, right? since it's always overwritten= ? And if it isn't always overwritten, that would be a bug I think, cause what happens if you bring up 2 ncm devices and only change the setting on the 1st?