From patchwork Mon Oct 9 14:20:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 150129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1906133vqo; Mon, 9 Oct 2023 07:22:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFqnl7m8tA5qUuaP9JfgFQuNFyzpxv7m1BPdW7ycI1pMwMS8ByQgVH8lRoBrEEZIrqX4SJH X-Received: by 2002:a05:6a20:1004:b0:14c:628b:4b98 with SMTP id gs4-20020a056a20100400b0014c628b4b98mr12060271pzc.4.1696861349157; Mon, 09 Oct 2023 07:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696861349; cv=none; d=google.com; s=arc-20160816; b=xKutbvhtRm9OFAnWrFNXgWc049ryAmtNzDeK4QNRj0YIxXHVvfOU+6KWDEfjb5sqcO PNoAWf6aPoOF92JP2vjme6nyVfT4rrpYlD+5biCuKyS+6gFT0C2zsEHGrlBKhT8wnXK8 +3pShNuWmBV8jpmsD4V1wt7VB5cnadlKq94/TKBXQ5hyhx+m6GY2K0+47gG13+Abwnu9 lRSiVJOC5l2Cj8li7AdbmgIfKG2ARxjyfrU/aFgvh62PJrmwuKBD5Jz5fK4RE2Nj57Lq jJkoKzZQZ6WqRywsYAb8BCK3jjB1LISfRg9T2kpRlkOaeTgOQDkYbsRireOAIqMJSkoh WKPg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=7qdfQioX1zXubJuPh0HpCefHEHuSrBYDOMSQ4QrcvWM=; fh=KAe0ppu4BSZM6v7Ru5xHNSeDPts1++GtjDbOXikzDnM=; b=KYLpl8jJeggEVTaeBp5DYWwjo4mJk4hoDQfObu3C1HBo3wk+ZYldZ3iVYzmdm4GdJ/ +T6douaHC+Ag1InhMyz+sJJ/QuNxSKiSNZOb4yYAnY3rYAUBFkX5XWXnxtQTlcb9fvya 9r54VEhUVYIAr1ylflsEV8d74RybLNBfWj9Aw5XqIUkgP1hlFMBj5KH34Ts2T4etsECu Xfd82r8c+LpDR9J+KJOuArTIk3m+ehV9Al8AiZl1+x+pnycD6fXjscsKV8J34ldcoJst 2XR3p0D/chmmc9WcPy3kh+jY1Rw53+OEEUcqaTwrQK/hVXT/hdyjLpWINTv+t+e+WhlZ bI8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=aerRDdPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id u14-20020a170902e80e00b001c56ede4c97si7895473plg.239.2023.10.09.07.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 07:22:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=aerRDdPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 0434180934A4; Mon, 9 Oct 2023 07:22:27 -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 S1377753AbjJIOV0 (ORCPT + 18 others); Mon, 9 Oct 2023 10:21:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377705AbjJIOVJ (ORCPT ); Mon, 9 Oct 2023 10:21:09 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 942E2D4D; Mon, 9 Oct 2023 07:20:40 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 399DvUFo009578; Mon, 9 Oct 2023 14:20:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=7qdfQioX1zXubJuPh0HpCefHEHuSrBYDOMSQ4QrcvWM=; b=aerRDdPVoitYbuaf7LeSir/QWWhVEh0vffpdXcP9vyqKzFp6EqGVV2Nkr+1s51p8WxP6 /8xj/SE1BR6usNYMhLuzs+/7DwW8O8JeaDfdV8XI9oXVyiinjc70C0h8Ervlf1yO+8Nb 3tH5fCqayL89020+0vvYSl2/kCxnfy7sIlfkX28qCYp7IHRCJe8+jky3fR+O0BOvPN4R zvzVk6m5+O1uZNpNb8PrMRfe122ETlgMeDULd6OjhLwu+KO15HTimWamtKUZJppeW703 zNFkUD2dsSULhjn3M6lz8rMyQBe5HuJRqpWXBpSDrZh9lHJ69Oz4CTX/5wMPEHLK2FiP vg== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tkhx2jjdq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Oct 2023 14:20:36 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 399EKLsx008053 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 9 Oct 2023 14:20:21 GMT Received: from hu-kriskura-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Mon, 9 Oct 2023 07:20:16 -0700 From: Krishna Kurapati To: Greg Kroah-Hartman , =?utf-8?q?Maciej_=C5=BB?= =?utf-8?q?enczykowski?= , onathan Corbet , Linyu Yuan CC: , , , , , , Krishna Kurapati Subject: [PATCH 1/2] Documentation: usb: Update NCM configfs parameters Date: Mon, 9 Oct 2023 19:50:04 +0530 Message-ID: <20231009142005.21338-1-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: Xx960gByasl8Il6ueXmcyg3i4O4ybp_X X-Proofpoint-ORIG-GUID: Xx960gByasl8Il6ueXmcyg3i4O4ybp_X X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-09_12,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 bulkscore=0 adultscore=0 priorityscore=1501 spamscore=0 mlxlogscore=688 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310090118 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Mon, 09 Oct 2023 07:22:27 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779288086209903654 X-GMAIL-MSGID: 1779288086209903654 Updateed NCM configfs parameters by adding max_segment_size property and describing its effect on MTU configuration of NCM interface. Signed-off-by: Krishna Kurapati --- Documentation/usb/gadget-testing.rst | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Documentation/usb/gadget-testing.rst b/Documentation/usb/gadget-testing.rst index 29072c166d23..6e5d96668e8e 100644 --- a/Documentation/usb/gadget-testing.rst +++ b/Documentation/usb/gadget-testing.rst @@ -448,15 +448,17 @@ Function-specific configfs interface The function name to use when creating the function directory is "ncm". The NCM function provides these attributes in its function directory: - =============== ================================================== - ifname network device interface name associated with this - function instance - qmult queue length multiplier for high and super speed - host_addr MAC address of host's end of this - Ethernet over USB link - dev_addr MAC address of device's end of this - Ethernet over USB link - =============== ================================================== + ================= ==================================================== + ifname network device interface name associated with this + function instance + qmult queue length multiplier for high and super speed + host_addr MAC address of host's end of this + Ethernet over USB link + dev_addr MAC address of device's end of this + Ethernet over USB link + max_segment_size Segment size required for P2P connections. This + will inturn set MTU to (max_segment_size - 14 bytes) + ================= ==================================================== and after creating the functions/ncm. they contain default values: qmult is 5, dev_addr and host_addr are randomly selected. From patchwork Mon Oct 9 14:20:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Kurapati X-Patchwork-Id: 150130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1907154vqo; Mon, 9 Oct 2023 07:24:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEmwGGuqqN7VPT6e+fwKlWFP5odNV+IWmWv1GXjn/lvZg/osRsZlhnhD0xcUgGXGbVgNup X-Received: by 2002:a17:90a:4947:b0:263:3386:9da8 with SMTP id c65-20020a17090a494700b0026333869da8mr10863230pjh.49.1696861441709; Mon, 09 Oct 2023 07:24:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696861441; cv=none; d=google.com; s=arc-20160816; b=MLJgOTA4buEI+6vVD5c1ahXppFzwUfkbBM/hqjWTQIdR7cvpCPM30rFt7i/UYmn5Iy t3fERpbxP47JwmxJvCluGsDDT0MXd+3kcCBGtsetsqTS+osQCBBCbBnWnAAdSGx8TL5m fRA8G0swWvU2bauhLhfiFJhF7oAylgYn+dp9C3C9Gc5eikNrgh9Gw3B6Da4Nz1qxfoRY OBDx/FtUDlkbYKn+8igcz1v9EFBgMw9kVTS6uF0YKA+qOarWrzZFhs0i/8Vvh5x7v416 VNrWMjHFd54bqAhTEspHWoXD1kpxiawHn9XrIHPFmu7jn1OG7aGdZiONYQN38D6T2mDj Pgmg== 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=h3xSLnLHj6PnTHglmvRguWsZDsEuuAAN7I/QDS4mg38=; fh=KAe0ppu4BSZM6v7Ru5xHNSeDPts1++GtjDbOXikzDnM=; b=PfdMj3crVxK3rxnMQaKU5T4LK7sNi3pEwsichQKtLq4OMdSrNS5xHMjJviDJ/KytPC X5V0v8zGxx44yKc0/K2mbwu6uLE/ksdrqV5cE3MwsqL5eFgqI6e58USBqa1hi+ClJOOt Oq/vuhOzrl1FEtGQwUaHVCpmwY0cxMZFj75wzYfP1QB0WDHsO6nBkWRxAK4z9gdyx9T/ oychodD0JGElMmV5KS3xGbtkFszwDY0gsBV0S4BOnv8zczDzzMG2Q07/lyMd3WcMwVI6 /b5DRejngOBsdhPqm02ZQxR97hw9R5jqWG6RgLqXPbEzAxBaBa4eOgsUk3YoctydIpec JD+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=oaQt0vMF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id v21-20020a17090a899500b002772b8993ebsi9635502pjn.159.2023.10.09.07.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 07:24:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=oaQt0vMF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id D7828807FD7B; Mon, 9 Oct 2023 07:23:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377713AbjJIOVV (ORCPT + 18 others); Mon, 9 Oct 2023 10:21:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377666AbjJIOVE (ORCPT ); Mon, 9 Oct 2023 10:21:04 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AFD1196; Mon, 9 Oct 2023 07:20:35 -0700 (PDT) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 399Ce6ju023112; Mon, 9 Oct 2023 14:20:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=h3xSLnLHj6PnTHglmvRguWsZDsEuuAAN7I/QDS4mg38=; b=oaQt0vMFfNrTdcJgxYmzO2yeHqA6OlWM1fTDVGYvvgEP1xV/0qqzrf1F9VESHhXhEp2m isYbCAgTzq/Mt48gUk4VV95fwF8dhONWnTz4/tC8jSEe7fVplztDWax5cwsNWkU2vg4A ZXlGdsiGycGOiie/guFmKun4OuCzOomAYzbzY356ZY0IRXALrqVazGeayoLcD0tGx9kI DwnSGlmBVxvz95JjAk9JHCB0z5IFGjIyLLjspNMAy9n7w6YL1nu29NGFUSMaNWZ+EnzH LHKOypg6YQY3m2ILQC3xqgR0oOtcpAo79PY+l+djmALtSf2KBjrlz8yRTED072SqdDzN gA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tkh4dammp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Oct 2023 14:20:26 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 399EKPAC012200 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 9 Oct 2023 14:20:25 GMT Received: from hu-kriskura-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.36; Mon, 9 Oct 2023 07:20:20 -0700 From: Krishna Kurapati To: Greg Kroah-Hartman , =?utf-8?q?Maciej_=C5=BB?= =?utf-8?q?enczykowski?= , onathan Corbet , Linyu Yuan CC: , , , , , , Krishna Kurapati Subject: [PATCH 2/2] usb: gadget: ncm: Add support to update wMaxSegmentSize via configfs Date: Mon, 9 Oct 2023 19:50:05 +0530 Message-ID: <20231009142005.21338-2-quic_kriskura@quicinc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231009142005.21338-1-quic_kriskura@quicinc.com> References: <20231009142005.21338-1-quic_kriskura@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: Gj92zfE8xHz75HBo_vEiTv8jvkMcSNsr X-Proofpoint-ORIG-GUID: Gj92zfE8xHz75HBo_vEiTv8jvkMcSNsr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-09_12,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 phishscore=0 spamscore=0 clxscore=1011 adultscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310090118 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Mon, 09 Oct 2023 07:23:57 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779288183410141594 X-GMAIL-MSGID: 1779288183410141594 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 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 = container_of(f->fi, struct f_ncm_opts, func_inst); if (cdev->use_os_string) { + ncm_opts->net->mtu = (ncm_opts->max_segment_size - ETH_HLEN); f->os_desc_table = 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 = -ENODEV; + ecm_desc.wMaxSegmentSize = ncm_opts->max_segment_size; + /* allocate instance-specific endpoints */ ep = 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 = to_f_ncm_opts(item); + u32 segment_size; + + mutex_lock(&opts->lock); + segment_size = 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 *item, + const char *page, size_t len) +{ + struct f_ncm_opts *opts = to_f_ncm_opts(item); + int ret; + u32 segment_size; + + mutex_lock(&opts->lock); + if (opts->refcnt) { + ret = -EBUSY; + goto out; + } + + ret = kstrtou32(page, 0, &segment_size); + if (ret) + goto out; + + if (segment_size > MAX_DATAGRAM_SIZE) { + ret = -EINVAL; + goto out; + } + + opts->max_segment_size = segment_size; + ret = len; +out: + mutex_unlock(&opts->lock); + return ret; +} + +CONFIGFS_ATTR(ncm_opts_, max_segment_size); + static struct configfs_attribute *ncm_attrs[] = { &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 = cpu_to_le16(ETH_FRAME_LEN); INIT_LIST_HEAD(&opts->ncm_os_desc.ext_prop); descs[0] = &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 */