Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2215955rdb; Mon, 9 Oct 2023 17:37:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvk/VtA8q4h1D1KdsUZ6f1lG+RTFZviA1+q2IqmkkDS2rbnACDu+gQnbXH7aHqgLA8KDE8 X-Received: by 2002:a05:6358:8810:b0:143:a0bf:9a49 with SMTP id hv16-20020a056358881000b00143a0bf9a49mr17940573rwb.3.1696898276477; Mon, 09 Oct 2023 17:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696898276; cv=none; d=google.com; s=arc-20160816; b=TOyZ2UmKcNRSBn2Hw96+jCJjz5/wY4gve5fZOzFi31AT1p/0x62Pe7Ht2F6SYQjz+a 9K95yNK3R4gNSZg3D25p4GGuxDjyiWLv51MyQUT4zfRZYYYGm5+8UEF6j0J0pG+PDMXJ 4R5pqgtJOS5k4BGfRVSptY4sKudsi05bOU6koNqz7EH7OcKOiPkJVs73hvZPOgcKVDRY /eMmFd9D2ffcXA5cmWjFo3OGHYo8iqDU/DHu6yofTzSK+Om0Y/JVuxnKwGKVTTF5lJ/+ 3B1rmWCEdUmRKiBDG2ZvPMhcGycYtnaKK46UbBIgqwkFPLljMe5/9Eg6OJJzjoGwUiwE MOfg== 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=Drda+y33XdGAEUOBvxGHem+aMQjGpAHViuUNurHBjyw=; fh=y1/5TSIVXHZtUBXoXu6dbqD4lnaxmJFoBy9NDKn3tJY=; b=HQvd7IYCsrtHr4J5tEO8xXl6FnmAOlQK+mA/RW0/S2L5wS72cIPn+ZJWfk7meTRe1/ u1D7vABox0DzEidqpBplYzgvIhqnHKgVI5pFyTLRydXY1fvx8E6V4HMFrxjYLQ7I/SRm KHtoWjGbi8Pa+fBNU8myZmFPD8IcVWmiljvX/ztDI/wHycF4A8n0wH+/kUUDWSh3FgcC K5S7oh+ctiMtMD9Ne/3nOrB1hHh9n+zQuSJcuCfRRvh41f7u2qK+NrM95h4anv5JGS1/ QdEtUduicMbXjpnl/PYuj7C0uWMzuePScK4CjMe+S+lQZW40iCUxGs/jCj1kdYD6d1QJ dKBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZZuUvMwX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id h7-20020a636c07000000b00589878c0a65si8929464pgc.735.2023.10.09.17.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 17:37:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZZuUvMwX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 7C7E180FF038; Mon, 9 Oct 2023 17:37:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379194AbjJJAh0 (ORCPT + 99 others); Mon, 9 Oct 2023 20:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379141AbjJJAhZ (ORCPT ); Mon, 9 Oct 2023 20:37:25 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C7CCA4 for ; Mon, 9 Oct 2023 17:37:23 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-537f07dfe8eso22439a12.1 for ; Mon, 09 Oct 2023 17:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696898242; x=1697503042; 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=Drda+y33XdGAEUOBvxGHem+aMQjGpAHViuUNurHBjyw=; b=ZZuUvMwXRR7r0CtDY8tlTiBb+R4ATG5C4ak0Ha5akrPo1CyNgHpiXYsrM7Bl5Bn+dZ +o3d/kyPLfOXa+Pah5J06CnKGep5UOT+osEpyM8HvPaAW2kR1K5qp9hBpAn2rpGP/PyT yqVh9+Og4bxmmx00+QCqrUkuyUvqtzhuIrtusRyIRX8sPhijKIDVHUCl/MRoQEqh2YSI gOi8mUKZyZCZvJtGbeN7W9w3AjkU5VS8SoVmc1kdIZ7EtNdNsKP0YCfztjkRxItSVrnv KYOxqsVnzjdvUMyob6HyeMRS+kGmiriGZhAmTaWw0G6WpVv+XqFMuNCbuCT4qsSbfuox hSdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696898242; x=1697503042; 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=Drda+y33XdGAEUOBvxGHem+aMQjGpAHViuUNurHBjyw=; b=mQuSEbQKf2uc8cqk8LHevaaNpQeHMPgyh3mbuYMfgtj93nRTf6q+milQk41rGUdOje Peve1JyEI3N4Yszkt/SE9k7e+vXoVhhBXIT7wa8OmVqTmtNgNCW1NJKL8diwPnhH3YVv jc7a4Of57Bgoa7OB+WF1LAjEHOoLkMrGe10hY2ayrLD5roV8yOJEPOLbyyEQoKjSdsFT fqoe2fIyKkOSD0+/prsB5gclufvk5cQ2OsEgBeG//XyYZZ3KKDLt9/syeNCVUG172bJr OcFGECUX9PXDTRDKpfGlrhC4QX5g2ybMQwN4vTV23SHDcOxtPL1fBh8RGuB2fTwX04iA sTOA== X-Gm-Message-State: AOJu0YzhzqBsN3ARZ3V5oVZbb/7zSP0fdLt7mRbnon4CTsi8F0vHEVfQ gmWmaA9H3gin1LUEDHz/wvzf2PNe+Q5k3Af3VcldHQ== X-Received: by 2002:a50:d0d7:0:b0:538:1d3b:172f with SMTP id g23-20020a50d0d7000000b005381d3b172fmr471689edf.3.1696898241782; Mon, 09 Oct 2023 17:37:21 -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:37:04 -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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 17:37:50 -0700 (PDT) On Mon, Oct 9, 2023 at 5:20=E2=80=AFPM Maciej =C5=BBenczykowski wrote: > > 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= /function/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 us= b_function *f) > > > /* Delay for the transmit to wait before sending an unfilled NTB fra= me. */ > > > #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 - = ETH_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 *it= em, > > > + 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 *i= tem, > > > + 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_= inst(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= /function/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 overwritt= en? > 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? One last thing... static int ncm_unwrap_ntb(struct gether *port, ... unsigned frame_max =3D le16_to_cpu(ecm_desc.wMaxSegmentSize); ^ is this a problem now if we have >1 gadget? how does it work then?