Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3791970rdb; Sun, 10 Dec 2023 22:54:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFa+ETczstusijQC1exqN7FTYZlsIfyVaKAHk6VxtlwwkHNDSSNPepKjDz9TBWE7kFFUGRK X-Received: by 2002:a25:ad41:0:b0:db7:dad0:76c0 with SMTP id l1-20020a25ad41000000b00db7dad076c0mr1758665ybe.92.1702277687506; Sun, 10 Dec 2023 22:54:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702277687; cv=none; d=google.com; s=arc-20160816; b=jyxeiMrwI/sh9cBqtYDUdhx4nlx+MYf3oI2LihoO844z4EIIqjC094r97br9QbZE7Z fMxEvvx6ymtrpVvSXeTDybtJrlVCKdPrqFvbL+NqKKv+5aVF70qeLXeHKXH1otYWKaSn uScqgO4p1LMvbX/DZ8XdReb1RF8Wr9lacH73mtVKJFfRKWhcKw7DvVzvthTRQ+PSXiRG XkzW8F+kEud28WloLdkkr5lYp+00ipclJxI2G6bfIWmnbxQagIF+lObU4jis2BqUq0x1 WiBC+2HRnI1SINHXMjjCVqE4JGsVesHSMTXgmjI215sZFz6vZOFaCUVNnEeYUCyCrLRe w0Sg== 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=hc51N0Guq3dh4qtHiKdd3a9aKkvfTdIQRPa5z8w6MfI=; fh=Qjn9V3WRZ8voNKTR0T2aDdpU9SDpV6npG0M5VoIf0Yo=; b=D4PdGN8t3J5kr5dTxHsWR/7NIAE86RSbu6na7EtQlBkkNYfRbeJUtAA00owfneyNVX H8/n52pHaDitCncNZwiLZncT73ThuJXtddUcutN7juFMtXlgXpJUCrtlaLtgI+t2g4kh GzyMqB8dKTbtcD1eIude3/pNL/SkwdWnAXPuKIbFJbq2F1DgOK+7+IxtZxHcNFQZ8f6L 9Onx6IM1BGSONbj2/T3z7PLP6/oim4GgJ3RaC0MDsWx5G7tWQdm8eHlEkaQECoIz92q0 dMrw0w9+8DSk2EE8k5znzn126TVslEA3osnNSafAzIW0go301J8Pyo7jV4B4T0xznHu7 sdIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CiiRskOq; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id b5-20020a63eb45000000b0059f0cebd04csi5638520pgk.722.2023.12.10.22.54.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 22:54:47 -0800 (PST) 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=@gmail.com header.s=20230601 header.b=CiiRskOq; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DD7A98056995; Sun, 10 Dec 2023 22:54:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233576AbjLKGy1 (ORCPT + 99 others); Mon, 11 Dec 2023 01:54:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbjLKGy0 (ORCPT ); Mon, 11 Dec 2023 01:54:26 -0500 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86B01D6 for ; Sun, 10 Dec 2023 22:54:32 -0800 (PST) Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6d9f8578932so1906523a34.2 for ; Sun, 10 Dec 2023 22:54:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702277672; x=1702882472; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hc51N0Guq3dh4qtHiKdd3a9aKkvfTdIQRPa5z8w6MfI=; b=CiiRskOq2h50q6Z4lQ+oTJ1l1W41B6gCmTeBIwiFv8EkLYp3WyMVt8YkKK8lnugupz t/Hkp6yH+bR3wkHcSip2VeG1hi197gqpA0LcMtisP989CZD9GyB45ZYQLddkuiFehjRb pojfQHEFLp56NLxo4gqqObavgujga2qWewLi2PWjy0o1b5KMmjjMdAQ3dPo86tnls9cv wlCMot7dK1e8eeugTjGMvPmnsIfoEbcVQwjTKaNiT0TGKR29qfnf3uH5DGLo0zWkPvbp bPd0bigqbXjhiUS6CJF/fIeeQ8/vIxXFzVnunVvFGklr0SrvdZ9VNfItjiwe8kZzMJD4 L8rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702277672; x=1702882472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hc51N0Guq3dh4qtHiKdd3a9aKkvfTdIQRPa5z8w6MfI=; b=lrY/AFLTVdhC6gQ65vx86zsIP/pkoIcEIIzmHrZP4e5Z2oJ349A0UNV+EjepUxHxha lQOo/YAASqbwpiHTX36KcwcPJiMyvY3b8XgDu+puQErxxyCDxf/Viymo2GCwdkSmUAXF 2/UfHRLFamMycepJFrJey93qgZZa9OT9vw7pGvFqUQHVQ1CZAII336HO1Q11XKxfhTL9 JX4wnhzs2Yzcds0sseiY3yvKE8v0cyiFvlNrMVn0WQcLN5CLhVFXu7I2KZB1TTEJOCL7 FUZ09s1/8bgRXBzydiEvkKjsqjmH6zJk9PTWXwDM8eVkWKX+UYab4lRiFTV1dWY+4ADq iYBg== X-Gm-Message-State: AOJu0YxwwgpewbgdYHNifAyctCAeOMeT8dA7ZUJFpqnr3iCq5dib5CoK eha4AtV9924HisfaWzEGWkA= X-Received: by 2002:a05:6830:914:b0:6d8:80a7:7e79 with SMTP id v20-20020a056830091400b006d880a77e79mr4893189ott.30.1702277671739; Sun, 10 Dec 2023 22:54:31 -0800 (PST) Received: from toolbox.. ([103.46.201.248]) by smtp.gmail.com with ESMTPSA id r1-20020a62e401000000b006ce91d27c72sm5751054pfh.175.2023.12.10.22.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 22:54:31 -0800 (PST) From: Ayush Singh To: greybus-dev@lists.linaro.org Cc: Ayush Singh , johan@kernel.org, elder@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, jkridner@beagleboard.org, nm@ti.com, yujie.liu@intel.com Subject: [PATCH V2 1/1] greybus: gb-beagleplay: Remove use of pad bytes Date: Mon, 11 Dec 2023 12:24:18 +0530 Message-ID: <20231211065420.213664-2-ayushdevel1325@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231211065420.213664-1-ayushdevel1325@gmail.com> References: <20231211065420.213664-1-ayushdevel1325@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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]); Sun, 10 Dec 2023 22:54:45 -0800 (PST) Make gb-beagleplay greybus spec compliant by moving cport information to transport layer instead of using `header->pad` bytes. Greybus HDLC frame now has the following payload: 1. le16 cport 2. gb_operation_msg_hdr msg_header 3. u8 *msg_payload Fixes: ec558bbfea67 ("greybus: Add BeaglePlay Linux Driver") Signed-off-by: Ayush Singh --- drivers/greybus/gb-beagleplay.c | 55 ++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/drivers/greybus/gb-beagleplay.c b/drivers/greybus/gb-beagleplay.c index 1e70ff7e3da4..82dc8a25e6b9 100644 --- a/drivers/greybus/gb-beagleplay.c +++ b/drivers/greybus/gb-beagleplay.c @@ -85,17 +85,31 @@ struct hdlc_payload { void *buf; }; +/** + * struct hdlc_greybus_frame - Structure to represent greybus HDLC frame payload + * + * @cport: cport id + * @hdr: greybus operation header + * @payload: greybus message payload + * + * The HDLC payload sent over UART for greybus address has cport preappended to greybus message + */ +struct hdlc_greybus_frame { + __le16 cport; + struct gb_operation_msg_hdr hdr; + u8 payload[]; +} __packed; + static void hdlc_rx_greybus_frame(struct gb_beagleplay *bg, u8 *buf, u16 len) { - u16 cport_id; - struct gb_operation_msg_hdr *hdr = (struct gb_operation_msg_hdr *)buf; - - memcpy(&cport_id, hdr->pad, sizeof(cport_id)); + struct hdlc_greybus_frame *gb_frame = (struct hdlc_greybus_frame *)buf; + u16 cport_id = le16_to_cpu(gb_frame->cport); + u16 gb_msg_len = le16_to_cpu(gb_frame->hdr.size); dev_dbg(&bg->sd->dev, "Greybus Operation %u type %X cport %u status %u received", - hdr->operation_id, hdr->type, le16_to_cpu(cport_id), hdr->result); + gb_frame->hdr.operation_id, gb_frame->hdr.type, cport_id, gb_frame->hdr.result); - greybus_data_rcvd(bg->gb_hd, le16_to_cpu(cport_id), buf, len); + greybus_data_rcvd(bg->gb_hd, cport_id, (u8 *)&gb_frame->hdr, gb_msg_len); } static void hdlc_rx_dbg_frame(const struct gb_beagleplay *bg, const char *buf, u16 len) @@ -336,10 +350,23 @@ static struct serdev_device_ops gb_beagleplay_ops = { .write_wakeup = gb_tty_wakeup, }; +/** + * gb_message_send() - Send greybus message using HDLC over UART + * + * @hd: pointer to greybus host device + * @cport: AP cport where message originates + * @msg: greybus message to send + * @mask: gfp mask + * + * Greybus HDLC frame has the following format: + * 1. le16 cport + * 2. gb_operation_msg_hdr msg_header + * 3. u8 *msg_payload + */ static int gb_message_send(struct gb_host_device *hd, u16 cport, struct gb_message *msg, gfp_t mask) { struct gb_beagleplay *bg = dev_get_drvdata(&hd->dev); - struct hdlc_payload payloads[2]; + struct hdlc_payload payloads[3]; __le16 cport_id = le16_to_cpu(cport); dev_dbg(&hd->dev, "Sending greybus message with Operation %u, Type: %X on Cport %u", @@ -348,14 +375,14 @@ static int gb_message_send(struct gb_host_device *hd, u16 cport, struct gb_messa if (le16_to_cpu(msg->header->size) > RX_HDLC_PAYLOAD) return dev_err_probe(&hd->dev, -E2BIG, "Greybus message too big"); - memcpy(msg->header->pad, &cport_id, sizeof(cport_id)); - - payloads[0].buf = msg->header; - payloads[0].len = sizeof(*msg->header); - payloads[1].buf = msg->payload; - payloads[1].len = msg->payload_size; + payloads[0].buf = &cport_id; + payloads[0].len = sizeof(cport_id); + payloads[1].buf = msg->header; + payloads[1].len = sizeof(*msg->header); + payloads[2].buf = msg->payload; + payloads[2].len = msg->payload_size; - hdlc_tx_frames(bg, ADDRESS_GREYBUS, 0x03, payloads, 2); + hdlc_tx_frames(bg, ADDRESS_GREYBUS, 0x03, payloads, 3); greybus_message_sent(bg->gb_hd, msg, 0); return 0; -- 2.43.0