Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3470992rwa; Tue, 23 Aug 2022 05:25:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR7qCMu3KpWheWnaHneIf+KtfRXC+Daoi21l7S82kNJ42wOhj2rOOTlrpGhmAuqWsPMqd0nE X-Received: by 2002:a17:90a:c682:b0:1fb:cfe:e3ba with SMTP id n2-20020a17090ac68200b001fb0cfee3bamr3034316pjt.35.1661257533643; Tue, 23 Aug 2022 05:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661257533; cv=none; d=google.com; s=arc-20160816; b=QPx72QCtQ6KPbZK1uL5jYvct9cQAetu5v68LmVVreMYVZOaNwyZJuxLPj6yvhExlLz 0XJNe5utw5CjcUC8qctpWS0UuMOJMG/U0Arm4Hazp/ShFw2ByKybrG2iiCeFPSNcyrc0 ttTtg0sfMjtNO4wAh6n4shGX6GlDSjdXAt6GHvFO9YLsq/En0PCAsXTw3MB1i6yqeF7S LM5vAA/CO93KnjoRd4uOxaKrAjOj3EK8Br6Mff0vzkqJusGK8Xc9iMG17fnVsjPO6RSz gi2UCN1DDSXc4MdoWTfXnVi1VI7KyA+ejr52Dvk6yAO1helBw2n+DJRxtpm7Gz35Un7l z3UQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/xuzfhaktN8+HGtJ4vH2HlGIDk2e0WnoMBz0P1mWLIs=; b=ToBMWnXR2w2t6Yj4zn68a/sBjzDOGqYo+k2T8Z7B9tp5H7A3z0pIvT3lSAXuwzykUj O5Vz7fwUfbVf+2vb9zqCIs8RVz9Ph1PXUhpv1JNLgBrtbEnFxs7axfpAU50+b0xIMokA PuIkkiNN7WDLCzDNzTSmGIciFTDHXzAS/IVCZOsLuDWvG8TD//pTdtATIjKzyllAKoDQ /3ozd/I/U/zzbrVtm1oVNzm5ffwyuRz2M+AdRKtUqJGy4zn+S/YHiaW2LBx21kJP1a67 cRSb+oJcdcNUNem9KFxvooe4DcIIQTAmVJ4QucdZKE0o0yiglwdcBHZvgrhfxTtk/cql xG7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JG0Jtf+r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j17-20020a63fc11000000b00429ee0682b5si13063893pgi.404.2022.08.23.05.25.22; Tue, 23 Aug 2022 05:25:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JG0Jtf+r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356017AbiHWKqQ (ORCPT + 99 others); Tue, 23 Aug 2022 06:46:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355495AbiHWKij (ORCPT ); Tue, 23 Aug 2022 06:38:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 334401EEF5; Tue, 23 Aug 2022 02:07:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BCB9F6159E; Tue, 23 Aug 2022 09:07:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B57E0C433C1; Tue, 23 Aug 2022 09:07:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245669; bh=boTzLUsBAj1F2wZ4ou4VPjMXnGttbkrUw1RUr52Rtk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JG0Jtf+re1XvJnpW2gquyZUiSIg0EBTfTLEmL1a8gwzPjB1b3c+RNzhDXLQLvqyi2 NsReil7pCmrgm1m9L5cT4ctsBRpnVU9a13r78SnS6GXNV4XUEM+xt6SwRPhQiJNbxJ Ph44O/kChSlvgSRZbrRzC0nXPgxVqcP6yKEYOPLY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Starke , Sasha Levin Subject: [PATCH 4.19 152/287] tty: n_gsm: fix non flow control frames during mux flow off Date: Tue, 23 Aug 2022 10:25:21 +0200 Message-Id: <20220823080105.730518417@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Starke [ Upstream commit bec0224816d19abe4fe503586d16d51890540615 ] n_gsm is based on the 3GPP 07.010 and its newer version is the 3GPP 27.010. See https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1516 The changes from 07.010 to 27.010 are non-functional. Therefore, I refer to the newer 27.010 here. Chapter 5.4.6.3.6 states that FCoff stops the transmission on all channels except the control channel. This is already implemented in gsm_data_kick(). However, chapter 5.4.8.1 explains that this shall result in the same behavior as software flow control on the ldisc in advanced option mode. That means only flow control frames shall be sent during flow off. The current implementation does not consider this case. Change gsm_data_kick() to send only flow control frames if constipated to abide the standard. gsm_read_ea_val() and gsm_is_flow_ctrl_msg() are introduced as helper functions for this. It is planned to use gsm_read_ea_val() in later code cleanups for other functions, too. Fixes: c01af4fec2c8 ("n_gsm : Flow control handling in Mux driver") Signed-off-by: Daniel Starke Link: https://lore.kernel.org/r/20220701061652.39604-5-daniel.starke@siemens.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/n_gsm.c | 54 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index 5d2bb4d95186..baadac224c8d 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -410,6 +410,27 @@ static int gsm_read_ea(unsigned int *val, u8 c) return c & EA; } +/** + * gsm_read_ea_val - read a value until EA + * @val: variable holding value + * @data: buffer of data + * @dlen: length of data + * + * Processes an EA value. Updates the passed variable and + * returns the processed data length. + */ +static unsigned int gsm_read_ea_val(unsigned int *val, const u8 *data, int dlen) +{ + unsigned int len = 0; + + for (; dlen > 0; dlen--) { + len++; + if (gsm_read_ea(val, *data++)) + break; + } + return len; +} + /** * gsm_encode_modem - encode modem data bits * @dlci: DLCI to encode from @@ -657,6 +678,37 @@ static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len, return m; } +/** + * gsm_is_flow_ctrl_msg - checks if flow control message + * @msg: message to check + * + * Returns true if the given message is a flow control command of the + * control channel. False is returned in any other case. + */ +static bool gsm_is_flow_ctrl_msg(struct gsm_msg *msg) +{ + unsigned int cmd; + + if (msg->addr > 0) + return false; + + switch (msg->ctrl & ~PF) { + case UI: + case UIH: + cmd = 0; + if (gsm_read_ea_val(&cmd, msg->data + 2, msg->len - 2) < 1) + break; + switch (cmd & ~PF) { + case CMD_FCOFF: + case CMD_FCON: + return true; + } + break; + } + + return false; +} + /** * gsm_data_kick - poke the queue * @gsm: GSM Mux @@ -675,7 +727,7 @@ static void gsm_data_kick(struct gsm_mux *gsm, struct gsm_dlci *dlci) int len; list_for_each_entry_safe(msg, nmsg, &gsm->tx_list, list) { - if (gsm->constipated && msg->addr) + if (gsm->constipated && !gsm_is_flow_ctrl_msg(msg)) continue; if (gsm->encoding != 0) { gsm->txframe[0] = GSM1_SOF; -- 2.35.1