From nobody Sun Nov 10 20:46:55 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A51C9C678D4 for ; Tue, 7 Mar 2023 08:11:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229983AbjCGIL4 (ORCPT ); Tue, 7 Mar 2023 03:11:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229757AbjCGILw (ORCPT ); Tue, 7 Mar 2023 03:11:52 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE6C410415; Tue, 7 Mar 2023 00:11:27 -0800 (PST) X-UUID: a4aa750cbcbf11eda06fc9ecc4dadd91-20230307 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=vgduVIOHUsmEHqgZONx8uKnlTWsJSWncFzmVVWh4R04=; b=WUgWrsYU4kZG7RMZ9IJwuS8qCq51Fpw4yExmwCzaAnoUHzD0KU2FqxETlzf0TBmvSUW/wSI5c9cVoEp0g93LkPH4LNng1BTx99zrer6JxzubRDP117+hayR+CPl08P0H0Ui5B1huk9T+uAbsU+vH7srDenmQ9LFBZ6hf0dCZx38=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.20,REQID:fa58624e-9b59-4247-b325-5e108002f59e,IP:0,U RL:0,TC:0,Content:-25,EDM:-30,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-55 X-CID-META: VersionHash:25b5999,CLOUDID:5afd9327-564d-42d9-9875-7c868ee415ec,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:2,IP:nil,UR L:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0 X-CID-BVR: 0 X-UUID: a4aa750cbcbf11eda06fc9ecc4dadd91-20230307 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1325799970; Tue, 07 Mar 2023 16:11:20 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.25; Tue, 7 Mar 2023 16:11:19 +0800 Received: from mcddlt001.gcn.mediatek.inc (10.19.240.15) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.25 via Frontend Transport; Tue, 7 Mar 2023 16:11:17 +0800 From: To: M Chetan Kumar , Intel Corporation , Loic Poulain , Sergey Ryazanov , Johannes Berg , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Stephan Gerhold , Chandrashekar Devegowda , Chiranjeevi Rapolu , Liu Haijun , Ricardo Martinez , Greg Kroah-Hartman , Matthias Brugger , Oliver Neukum , haozhe chang , Shang XiaoJing , "open list:INTEL WWAN IOSM DRIVER" , open list , "open list:REMOTE PROCESSOR MESSAGING (RPMSG) WWAN CONTROL..." , "open list:USB SUBSYSTEM" , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" CC: , , Subject: [PATCH RESEND net-next] wwan: core: Support slicing in port TX flow of WWAN subsystem Date: Tue, 7 Mar 2023 16:11:04 +0800 Message-ID: <20230307081113.67746-1-haozhe.chang@mediatek.com> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: haozhe chang wwan_port_fops_write inputs the SKB parameter to the TX callback of the WWAN device driver. However, the WWAN device (e.g., t7xx) may have an MTU less than the size of SKB, causing the TX buffer to be sliced and copied once more in the WWAN device driver. This patch implements the slicing in the WWAN subsystem and gives the WWAN devices driver the option to slice(by frag_len) or not. By doing so, the additional memory copy is reduced. Meanwhile, this patch gives WWAN devices driver the option to reserve headroom in fragments for the device-specific metadata. Signed-off-by: haozhe chang Reviewed-by: Loic Poulain --- Changes in v2 -send fragments to device driver by skb frag_list. Changes in v3 -move frag_len and headroom_len setting to wwan_create_port. Changes in v4 -change unreadable parameters to macro definition. Changes in v5 -optimize comments for WWAN_NO_HEADROOM, WWAN_NO_FRAGMENT. Changes in v6 -add reviewer to patch commit. --- drivers/net/wwan/iosm/iosm_ipc_port.c | 3 +- drivers/net/wwan/mhi_wwan_ctrl.c | 3 +- drivers/net/wwan/rpmsg_wwan_ctrl.c | 3 +- drivers/net/wwan/t7xx/t7xx_port_wwan.c | 34 +++++++-------- drivers/net/wwan/wwan_core.c | 59 ++++++++++++++++++++------ drivers/net/wwan/wwan_hwsim.c | 1 + drivers/usb/class/cdc-wdm.c | 3 +- include/linux/wwan.h | 16 +++++++ 8 files changed, 87 insertions(+), 35 deletions(-) diff --git a/drivers/net/wwan/iosm/iosm_ipc_port.c b/drivers/net/wwan/iosm/= iosm_ipc_port.c index b6d81c627277..7798348f61d0 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_port.c +++ b/drivers/net/wwan/iosm/iosm_ipc_port.c @@ -63,7 +63,8 @@ struct iosm_cdev *ipc_port_init(struct iosm_imem *ipc_ime= m, ipc_port->ipc_imem =3D ipc_imem; =20 ipc_port->iosm_port =3D wwan_create_port(ipc_port->dev, port_type, - &ipc_wwan_ctrl_ops, ipc_port); + &ipc_wwan_ctrl_ops, WWAN_NO_FRAGMENT, + WWAN_NO_HEADROOM, ipc_port); =20 return ipc_port; } diff --git a/drivers/net/wwan/mhi_wwan_ctrl.c b/drivers/net/wwan/mhi_wwan_c= trl.c index f7ca52353f40..c397aa53db5d 100644 --- a/drivers/net/wwan/mhi_wwan_ctrl.c +++ b/drivers/net/wwan/mhi_wwan_ctrl.c @@ -237,7 +237,8 @@ static int mhi_wwan_ctrl_probe(struct mhi_device *mhi_d= ev, =20 /* Register as a wwan port, id->driver_data contains wwan port type */ port =3D wwan_create_port(&cntrl->mhi_dev->dev, id->driver_data, - &wwan_pops, mhiwwan); + &wwan_pops, WWAN_NO_FRAGMENT, WWAN_NO_HEADROOM, + mhiwwan); if (IS_ERR(port)) { kfree(mhiwwan); return PTR_ERR(port); diff --git a/drivers/net/wwan/rpmsg_wwan_ctrl.c b/drivers/net/wwan/rpmsg_ww= an_ctrl.c index 31c24420ab2e..fc6c228b7e1c 100644 --- a/drivers/net/wwan/rpmsg_wwan_ctrl.c +++ b/drivers/net/wwan/rpmsg_wwan_ctrl.c @@ -129,7 +129,8 @@ static int rpmsg_wwan_ctrl_probe(struct rpmsg_device *r= pdev) =20 /* Register as a wwan port, id.driver_data contains wwan port type */ port =3D wwan_create_port(parent, rpdev->id.driver_data, - &rpmsg_wwan_pops, rpwwan); + &rpmsg_wwan_pops, WWAN_NO_FRAGMENT, + WWAN_NO_HEADROOM, rpwwan); if (IS_ERR(port)) return PTR_ERR(port); =20 diff --git a/drivers/net/wwan/t7xx/t7xx_port_wwan.c b/drivers/net/wwan/t7xx= /t7xx_port_wwan.c index 33931bfd78fd..b75bb272f861 100644 --- a/drivers/net/wwan/t7xx/t7xx_port_wwan.c +++ b/drivers/net/wwan/t7xx/t7xx_port_wwan.c @@ -54,13 +54,13 @@ static void t7xx_port_ctrl_stop(struct wwan_port *port) static int t7xx_port_ctrl_tx(struct wwan_port *port, struct sk_buff *skb) { struct t7xx_port *port_private =3D wwan_port_get_drvdata(port); - size_t len, offset, chunk_len =3D 0, txq_mtu =3D CLDMA_MTU; const struct t7xx_port_conf *port_conf; + struct sk_buff *cur =3D skb, *cloned; struct t7xx_fsm_ctl *ctl; enum md_state md_state; + int cnt =3D 0, ret; =20 - len =3D skb->len; - if (!len || !port_private->chan_enable) + if (!port_private->chan_enable) return -EINVAL; =20 port_conf =3D port_private->port_conf; @@ -72,23 +72,21 @@ static int t7xx_port_ctrl_tx(struct wwan_port *port, st= ruct sk_buff *skb) return -ENODEV; } =20 - for (offset =3D 0; offset < len; offset +=3D chunk_len) { - struct sk_buff *skb_ccci; - int ret; - - chunk_len =3D min(len - offset, txq_mtu - sizeof(struct ccci_header)); - skb_ccci =3D t7xx_port_alloc_skb(chunk_len); - if (!skb_ccci) - return -ENOMEM; - - skb_put_data(skb_ccci, skb->data + offset, chunk_len); - ret =3D t7xx_port_send_skb(port_private, skb_ccci, 0, 0); + while (cur) { + cloned =3D skb_clone(cur, GFP_KERNEL); + cloned->len =3D skb_headlen(cur); + ret =3D t7xx_port_send_skb(port_private, cloned, 0, 0); if (ret) { - dev_kfree_skb_any(skb_ccci); + dev_kfree_skb(cloned); dev_err(port_private->dev, "Write error on %s port, %d\n", port_conf->name, ret); - return ret; + return cnt ? cnt + ret : ret; } + cnt +=3D cur->len; + if (cur =3D=3D skb) + cur =3D skb_shinfo(skb)->frag_list; + else + cur =3D cur->next; } =20 dev_kfree_skb(skb); @@ -154,13 +152,15 @@ static int t7xx_port_wwan_disable_chl(struct t7xx_por= t *port) static void t7xx_port_wwan_md_state_notify(struct t7xx_port *port, unsigne= d int state) { const struct t7xx_port_conf *port_conf =3D port->port_conf; + unsigned int header_len =3D sizeof(struct ccci_header); =20 if (state !=3D MD_STATE_READY) return; =20 if (!port->wwan_port) { port->wwan_port =3D wwan_create_port(port->dev, port_conf->port_type, - &wwan_ops, port); + &wwan_ops, CLDMA_MTU - header_len, + header_len, port); if (IS_ERR(port->wwan_port)) dev_err(port->dev, "Unable to create WWWAN port %s", port_conf->name); } diff --git a/drivers/net/wwan/wwan_core.c b/drivers/net/wwan/wwan_core.c index 62e9f7d6c9fe..8d35513bcd4c 100644 --- a/drivers/net/wwan/wwan_core.c +++ b/drivers/net/wwan/wwan_core.c @@ -67,6 +67,8 @@ struct wwan_device { * @rxq: Buffer inbound queue * @waitqueue: The waitqueue for port fops (read/write/poll) * @data_lock: Port specific data access serialization + * @headroom_len: SKB reserved headroom size + * @frag_len: Length to fragment packet * @at_data: AT port specific data */ struct wwan_port { @@ -79,6 +81,8 @@ struct wwan_port { struct sk_buff_head rxq; wait_queue_head_t waitqueue; struct mutex data_lock; /* Port specific data access serialization */ + size_t headroom_len; + size_t frag_len; union { struct { struct ktermios termios; @@ -422,6 +426,8 @@ static int __wwan_port_dev_assign_name(struct wwan_port= *port, const char *fmt) struct wwan_port *wwan_create_port(struct device *parent, enum wwan_port_type type, const struct wwan_port_ops *ops, + size_t frag_len, + unsigned int headroom_len, void *drvdata) { struct wwan_device *wwandev; @@ -455,6 +461,8 @@ struct wwan_port *wwan_create_port(struct device *paren= t, =20 port->type =3D type; port->ops =3D ops; + port->frag_len =3D frag_len ? frag_len : SIZE_MAX; + port->headroom_len =3D headroom_len; mutex_init(&port->ops_lock); skb_queue_head_init(&port->rxq); init_waitqueue_head(&port->waitqueue); @@ -698,30 +706,53 @@ static ssize_t wwan_port_fops_read(struct file *filp,= char __user *buf, static ssize_t wwan_port_fops_write(struct file *filp, const char __user *= buf, size_t count, loff_t *offp) { + struct sk_buff *skb, *head =3D NULL, *tail =3D NULL; struct wwan_port *port =3D filp->private_data; - struct sk_buff *skb; + size_t frag_len, remain =3D count; int ret; =20 ret =3D wwan_wait_tx(port, !!(filp->f_flags & O_NONBLOCK)); if (ret) return ret; =20 - skb =3D alloc_skb(count, GFP_KERNEL); - if (!skb) - return -ENOMEM; + do { + frag_len =3D min(remain, port->frag_len); + skb =3D alloc_skb(frag_len + port->headroom_len, GFP_KERNEL); + if (!skb) { + ret =3D -ENOMEM; + goto freeskb; + } + skb_reserve(skb, port->headroom_len); + + if (!head) { + head =3D skb; + } else if (!tail) { + skb_shinfo(head)->frag_list =3D skb; + tail =3D skb; + } else { + tail->next =3D skb; + tail =3D skb; + } =20 - if (copy_from_user(skb_put(skb, count), buf, count)) { - kfree_skb(skb); - return -EFAULT; - } + if (copy_from_user(skb_put(skb, frag_len), buf + count - remain, frag_le= n)) { + ret =3D -EFAULT; + goto freeskb; + } =20 - ret =3D wwan_port_op_tx(port, skb, !!(filp->f_flags & O_NONBLOCK)); - if (ret) { - kfree_skb(skb); - return ret; - } + if (skb !=3D head) { + head->data_len +=3D skb->len; + head->len +=3D skb->len; + head->truesize +=3D skb->truesize; + } + } while (remain -=3D frag_len); + + ret =3D wwan_port_op_tx(port, head, !!(filp->f_flags & O_NONBLOCK)); + if (!ret) + return count; =20 - return count; +freeskb: + kfree_skb(head); + return ret; } =20 static __poll_t wwan_port_fops_poll(struct file *filp, poll_table *wait) diff --git a/drivers/net/wwan/wwan_hwsim.c b/drivers/net/wwan/wwan_hwsim.c index ff09a8cedf93..7fb54cb51628 100644 --- a/drivers/net/wwan/wwan_hwsim.c +++ b/drivers/net/wwan/wwan_hwsim.c @@ -205,6 +205,7 @@ static struct wwan_hwsim_port *wwan_hwsim_port_new(stru= ct wwan_hwsim_dev *dev) =20 port->wwan =3D wwan_create_port(&dev->dev, WWAN_PORT_AT, &wwan_hwsim_port_ops, + WWAN_NO_FRAGMENT, WWAN_NO_HEADROOM, port); if (IS_ERR(port->wwan)) { err =3D PTR_ERR(port->wwan); diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index 1f0951be15ab..e0f0bc878bbd 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c @@ -929,7 +929,8 @@ static void wdm_wwan_init(struct wdm_device *desc) return; } =20 - port =3D wwan_create_port(&intf->dev, desc->wwanp_type, &wdm_wwan_port_op= s, desc); + port =3D wwan_create_port(&intf->dev, desc->wwanp_type, &wdm_wwan_port_op= s, + WWAN_NO_FRAGMENT, WWAN_NO_HEADROOM, desc); if (IS_ERR(port)) { dev_err(&intf->dev, "%s: Unable to create WWAN port\n", dev_name(intf->usb_dev)); diff --git a/include/linux/wwan.h b/include/linux/wwan.h index 5ce2acf444fb..adaf1f4a8652 100644 --- a/include/linux/wwan.h +++ b/include/linux/wwan.h @@ -62,11 +62,25 @@ struct wwan_port_ops { poll_table *wait); }; =20 +/* + * Used to indicate that the WWAN core should not fragment control package= s. + */ +#define WWAN_NO_FRAGMENT 0 + +/* + * Used to indicate that the WWAN core should not reserve headroom in cont= rol packages. + */ +#define WWAN_NO_HEADROOM 0 + /** * wwan_create_port - Add a new WWAN port * @parent: Device to use as parent and shared by all WWAN ports * @type: WWAN port type * @ops: WWAN port operations + * @frag_len: WWAN port TX fragments length, if WWAN_NO_FRAGMENT is set, + * the WWAN core don't fragment control packages. + * @headroom_len: WWAN port TX fragments reserved headroom length, if WWAN= _NO_HEADROOM + * is set, the WWAN core don't reserve headroom in control = packages. * @drvdata: Pointer to caller driver data * * Allocate and register a new WWAN port. The port will be automatically e= xposed @@ -84,6 +98,8 @@ struct wwan_port_ops { struct wwan_port *wwan_create_port(struct device *parent, enum wwan_port_type type, const struct wwan_port_ops *ops, + size_t frag_len, + unsigned int headroom_len, void *drvdata); =20 /** --=20 2.17.0