From patchwork Wed May 5 18:59:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liming Sun X-Patchwork-Id: 1474519 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=tpHgLDFm; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fb5cW6PXJz9sTD; Thu, 6 May 2021 04:59:55 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1leMkS-00023d-TQ; Wed, 05 May 2021 18:59:52 +0000 Received: from mail-mw2nam12on2042.outbound.protection.outlook.com ([40.107.244.42] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1leMkQ-000233-1v for kernel-team@lists.ubuntu.com; Wed, 05 May 2021 18:59:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jlG/GO6vN9kJEN+ZmShSX/ENUn4/acu5QshA/HxFe1X1PW4fZP790J8hgMmeXZ/5vG1rIgjM2pz+Kt49x/WEc0l7hWf9iVpUHiIvtitws/tarvxkFIj7Fo2X+4OiqA0vQYmC02jJYQ+5i3LMkLhu7Ksp8Wwele9V+7U70PAeRQDwu68mtMNGQJl8L5ayL1bRffYLH1QHmm4B31K1ULf+cBGcRBsK9g85XojZ7q0SVMKC7Lwzi4C/QLNHTBxv2AlrRPqIYusQxXF+SBhlw3+XdxuT5LKvXx+3aSoAT5O6TBhYNSSAUCgEwuZ4mpMd9sfCX3vP3x98+S8mK4pqiKL0EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cjS0U5wdNlSyNhltSZvN9xH4r77w6tilSHbmMitO+VE=; b=LzKxZ5scJ3AwFu5DKvlpYXRlIe05hQw624BoiJf9+6AdywwTLP0O/wTbG0osk45pRkN/lzpHZ13zjJSM10jyKzk+t1/ABqlyXL2FH6c7VcA2s18ZEe7b7QZReuaGTWSOlXWhytwHvfzJXYczqUqVu+S1IskVA7lFj+ECMoneBouBhPxMJvCtl9adZjzVCllI1a8DWSTK+l67IJP3ehIxon8xEtODqD1Kr0VqjTFddSnl8IoQVA3CcOBVkVYSMsIMqTqXUIUF2s06CXeG6IbWMvBuUFM3UJa+h4TIS2PuU3q1kfNi2KgwAYzZKCxWs5GlQd4rfbPhzwWYGguDH3/7gg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cjS0U5wdNlSyNhltSZvN9xH4r77w6tilSHbmMitO+VE=; b=tpHgLDFmuclIG3U+E8eMajXbu8l2pu8E5Ctla/TRPHCHakjCV7/sOCs3b4BKk6epPEp3OCCNm64adHTgh0l81r6yL/PSj/tCrcCGevTe4HHA/zF/BaL3xhWZU14aZNsyW2BKEqA4ygd9gySPIHi5vUX3bqH+o4uw4d/ZvqLR0w8hdyref/qUE/2mVnJ6YmKA4M6YYqKzh0ROJ0MkXaxZ2/TtsD3ICHV1Ulj7y62mnHe/QhmNDB9NI4BEzmXBvYwC7j3KaSK81ZL4lLzEL5RVO2mtt2zw/ZLw9K73sItzNB2Vx79odWDus4smt6qRi9SyECpG3OV+ZxD0V+yxKWIqGg== Received: from MW4PR04CA0280.namprd04.prod.outlook.com (2603:10b6:303:89::15) by BYAPR12MB4744.namprd12.prod.outlook.com (2603:10b6:a03:9e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Wed, 5 May 2021 18:59:46 +0000 Received: from CO1NAM11FT036.eop-nam11.prod.protection.outlook.com (2603:10b6:303:89:cafe::67) by MW4PR04CA0280.outlook.office365.com (2603:10b6:303:89::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Wed, 5 May 2021 18:59:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; lists.ubuntu.com; dkim=none (message not signed) header.d=none;lists.ubuntu.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT036.mail.protection.outlook.com (10.13.174.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4108.25 via Frontend Transport; Wed, 5 May 2021 18:59:46 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 5 May 2021 18:59:45 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 5 May 2021 18:59:45 +0000 From: Liming Sun To: Subject: [SRU][F:linux-bluefield][PATCH v1 1/1] UBUNTU: SAUCE: platform/mellanox: Add ctrl message and MAC configuration Date: Wed, 5 May 2021 14:59:33 -0400 Message-ID: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06702188-f0da-4d14-4ef1-08d90ff7f388 X-MS-TrafficTypeDiagnostic: BYAPR12MB4744: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:483; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 52b67VXxCYlQLZXmpowSQdF7GE8gW7WKBEfuzf3mFKp0c20Z6moHlubxLIfCOLFZLCcmh0rG4WryfSu8D+RgZubrpXURi3RqJKs/EZuuVjkXKiJ9KBTDro1fZX3iVZRphf5dy2F7U0j5qGh7ZQcjMSgRqoR1sDRz6E4+RdVavhJk+7kEdUtuOUZmbn10DOwrmXqQrguQm6TiOjt5m95UoR9leAiFh4B7NFzLsPNlKrjtU0u/IUCxB5cWWmZFwPqULYVEZxHNceVydyEr9QJiNDK3ujYbl47VQGUM1IdS+Y7Swbb3arS0y3RwWbxyjiJLI/8x1AecMr7miF+IizjocD523n5MMRqU9iNibCdhboiPvOs/u8Y+c3jCWY2BN2UbBo3vf4p4dcgAnE1zg9dbXAxxBBPOyrt4VKwpbotXQQdqXP/DRaXPi3IbtNAL48y1WO9uEoMFV8Il8jdh7gKTVqDT0vF2F7dqYfxZyLRe+RQvKVlvws5EZV2iH7dxZiPOzlAkub5XZcxIACT6k9g+0ai4hPKe6wTb4sC0i0YXx8hnIzB5uULy3XDDXXOPVpfNRoPndnqfA65yAPmLJ+ASiLzAtT7D5S0M8NogbzRqC79mOtWKG7xDctO9o4H+2ulgeOYVMcJLH4G4uCAoG9ecwMB6l+Bv2ja2uNlrDSNoJdFgDivMFHZ7k+4OCD3PZ2U7WbjZwJ8AQoilpmsN/FPvzM5aDub3enHS/tN0gE4Cee8= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(396003)(346002)(136003)(376002)(46966006)(36840700001)(36860700001)(15650500001)(478600001)(5660300002)(2906002)(966005)(6916009)(86362001)(82310400003)(4326008)(6666004)(83380400001)(2616005)(316002)(36906005)(186003)(26005)(426003)(336012)(36756003)(8676002)(82740400003)(7636003)(70206006)(107886003)(8936002)(7696005)(356005)(47076005)(54906003)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 18:59:46.5112 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 06702188-f0da-4d14-4ef1-08d90ff7f388 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT036.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB4744 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Sun , Liming Sun Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Liming Sun BugLink: https://bugs.launchpad.net/bugs/1927253 This commit adds control message support and MAC configuration based on the control message. Signed-off-by: Liming Sun --- drivers/platform/mellanox/mlxbf-tmfifo-regs.h | 4 +- drivers/platform/mellanox/mlxbf-tmfifo.c | 180 ++++++++++++++++++++++---- 2 files changed, 156 insertions(+), 28 deletions(-) diff --git a/drivers/platform/mellanox/mlxbf-tmfifo-regs.h b/drivers/platform/mellanox/mlxbf-tmfifo-regs.h index e4f0d2e..e680230 100644 --- a/drivers/platform/mellanox/mlxbf-tmfifo-regs.h +++ b/drivers/platform/mellanox/mlxbf-tmfifo-regs.h @@ -1,6 +1,6 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */ /* - * Copyright (c) 2019, Mellanox Technologies. All rights reserved. + * Copyright (c) 2020 NVIDIA Corporation. All rights reserved. */ #ifndef __MLXBF_TMFIFO_REGS_H__ diff --git a/drivers/platform/mellanox/mlxbf-tmfifo.c b/drivers/platform/mellanox/mlxbf-tmfifo.c index 5739a966..b69ab33 100644 --- a/drivers/platform/mellanox/mlxbf-tmfifo.c +++ b/drivers/platform/mellanox/mlxbf-tmfifo.c @@ -1,8 +1,8 @@ -// SPDX-License-Identifier: GPL-2.0+ +// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only /* - * Mellanox BlueField SoC TmFifo driver + * NVIDIA BlueField SoC TmFifo driver * - * Copyright (C) 2019 Mellanox Technologies + * Copyright (c) 2020 NVIDIA Corporation. All rights reserved. */ #include @@ -150,7 +150,9 @@ struct mlxbf_tmfifo_irq_info { * @timer: background timer * @vring: Tx/Rx ring * @spin_lock: Tx/Rx spin lock + * @ctrl_mac: MAC address received in control message * @is_ready: ready flag + * @send_ctrl: flag to send control message when ready */ struct mlxbf_tmfifo { struct mlxbf_tmfifo_vdev *vdev[MLXBF_TMFIFO_VDEV_MAX]; @@ -165,7 +167,16 @@ struct mlxbf_tmfifo { struct timer_list timer; struct mlxbf_tmfifo_vring *vring[2]; spinlock_t spin_lock[2]; /* spin lock */ - bool is_ready; + u8 ctrl_mac[ETH_ALEN]; + u32 is_ready : 1; + u32 send_ctrl : 1; +}; + +/* Internal message types defined in reverse order starting from 0xFF. */ +enum { + MLXBF_TMFIFO_MSG_CTRL_REQ = 0xFD, + MLXBF_TMFIFO_MSG_MAC_1 = 0xFE, + MLXBF_TMFIFO_MSG_MAC_2 = 0xFF }; /** @@ -175,11 +186,17 @@ struct mlxbf_tmfifo { * will be read by the other side as data stream in the same byte order. * The length needs to be encoded into network order so both sides * could understand it. + * @mac: first or second half of the MAC address depending on the type. + * @checksum: checksum of the message header (only control message for now). */ struct mlxbf_tmfifo_msg_hdr { u8 type; __be16 len; - u8 unused[5]; + union { + u8 mac[3]; + u8 unused[4]; + } __packed; + u8 checksum; } __packed __aligned(sizeof(u64)); /* @@ -491,6 +508,127 @@ static int mlxbf_tmfifo_get_tx_avail(struct mlxbf_tmfifo *fifo, int vdev_id) return fifo->tx_fifo_size - tx_reserve - count; } +/* Read the configured network MAC address from efi variable. */ +static void mlxbf_tmfifo_get_cfg_mac(u8 *mac) +{ + efi_guid_t guid = EFI_GLOBAL_VARIABLE_GUID; + unsigned long size = ETH_ALEN; + u8 buf[ETH_ALEN]; + efi_status_t rc; + + rc = efi.get_variable(mlxbf_tmfifo_efi_name, &guid, NULL, &size, buf); + if (rc == EFI_SUCCESS && size == ETH_ALEN) + ether_addr_copy(mac, buf); + else + ether_addr_copy(mac, mlxbf_tmfifo_net_default_mac); +} + +/* Set the configured network MAC address into efi variable. */ +static efi_status_t mlxbf_tmfifo_set_cfg_mac(u8 *mac) +{ + efi_guid_t guid = EFI_GLOBAL_VARIABLE_GUID; + efi_status_t status = EFI_SUCCESS; + u8 old_mac[ETH_ALEN] = {0}; + + mlxbf_tmfifo_get_cfg_mac(old_mac); + + if (memcmp(old_mac, mac, ETH_ALEN)) { + status = efi.set_variable(mlxbf_tmfifo_efi_name, &guid, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + ETH_ALEN, mac); + } + + return status; +} + +/* Just adds up all the bytes of the header. */ +static u8 mlxbf_tmfifo_ctrl_checksum(struct mlxbf_tmfifo_msg_hdr *hdr) +{ + u8 checksum = 0; + int i; + + for (i = 0; i < sizeof(*hdr); i++) + checksum += ((u8 *)hdr)[i]; + + return checksum; +} + +static void mlxbf_tmfifo_ctrl_update_checksum(struct mlxbf_tmfifo_msg_hdr *hdr) +{ + u8 checksum; + + hdr->checksum = 0; + checksum = mlxbf_tmfifo_ctrl_checksum(hdr); + hdr->checksum = ~checksum + 1; +} + +static bool mlxbf_tmfifo_ctrl_verify_checksum(struct mlxbf_tmfifo_msg_hdr *hdr) +{ + u8 checksum = mlxbf_tmfifo_ctrl_checksum(hdr); + + return checksum ? false : true; +} + +static void mlxbf_tmfifo_ctrl_rx(struct mlxbf_tmfifo *fifo, + struct mlxbf_tmfifo_msg_hdr *hdr) +{ + if (!mlxbf_tmfifo_ctrl_verify_checksum(hdr)) + return; + + switch (hdr->type) { + case MLXBF_TMFIFO_MSG_CTRL_REQ: + /* + * Set a flag to send the MAC address later. It can't be sent + * here since another packet might be still in the middle of + * transmission. + */ + fifo->send_ctrl = 1; + test_and_set_bit(MLXBF_TM_TX_LWM_IRQ, &fifo->pend_events); + schedule_work(&fifo->work); + break; + case MLXBF_TMFIFO_MSG_MAC_1: + /* Get the first half of the MAC address. */ + memcpy(fifo->ctrl_mac, hdr->mac, sizeof(hdr->mac)); + break; + case MLXBF_TMFIFO_MSG_MAC_2: + /* Get the second half of the MAC address and update. */ + memcpy(fifo->ctrl_mac + sizeof(hdr->mac), hdr->mac, + sizeof(hdr->mac)); + mlxbf_tmfifo_set_cfg_mac(fifo->ctrl_mac); + break; + default: + break; + } +} + +static void mlxbf_tmfifo_ctrl_tx(struct mlxbf_tmfifo *fifo, int *num_avail) +{ + struct mlxbf_tmfifo_msg_hdr hdr; + u8 mac[ETH_ALEN] = { 0 }; + + /* Send the MAC address with two control messages. */ + if (fifo->send_ctrl && *num_avail >= 2) { + mlxbf_tmfifo_get_cfg_mac(mac); + + hdr.type = MLXBF_TMFIFO_MSG_MAC_1; + hdr.len = 0; + memcpy(hdr.mac, mac, sizeof(hdr.mac)); + mlxbf_tmfifo_ctrl_update_checksum(&hdr); + writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); + (*num_avail)--; + + hdr.type = MLXBF_TMFIFO_MSG_MAC_2; + memcpy(hdr.mac, mac + sizeof(hdr.mac), sizeof(hdr.mac)); + mlxbf_tmfifo_ctrl_update_checksum(&hdr); + writeq(*(u64 *)&hdr, fifo->tx_base + MLXBF_TMFIFO_TX_DATA); + (*num_avail)--; + + fifo->send_ctrl = 0; + } +} + /* Console Tx (move data from the output buffer into the TmFifo). */ static void mlxbf_tmfifo_console_tx(struct mlxbf_tmfifo *fifo, int avail) { @@ -616,9 +754,11 @@ static void mlxbf_tmfifo_rxtx_header(struct mlxbf_tmfifo_vring *vring, /* Drain one word from the FIFO. */ *(u64 *)&hdr = readq(fifo->rx_base + MLXBF_TMFIFO_RX_DATA); - /* Skip the length 0 packets (keepalive). */ - if (hdr.len == 0) + /* Handle the length 0 packets (control msg). */ + if (hdr.len == 0) { + mlxbf_tmfifo_ctrl_rx(fifo, &hdr); return; + } /* Check packet type. */ if (hdr.type == VIRTIO_ID_NET) { @@ -777,6 +917,9 @@ static void mlxbf_tmfifo_rxtx(struct mlxbf_tmfifo_vring *vring, bool is_rx) /* Console output always comes from the Tx buffer. */ if (!is_rx && devid == VIRTIO_ID_CONSOLE) { + /* Check if there is any control data to send. */ + mlxbf_tmfifo_ctrl_tx(fifo, &avail); + mlxbf_tmfifo_console_tx(fifo, avail); break; } @@ -1122,21 +1265,6 @@ static int mlxbf_tmfifo_delete_vdev(struct mlxbf_tmfifo *fifo, int vdev_id) return 0; } -/* Read the configured network MAC address from efi variable. */ -static void mlxbf_tmfifo_get_cfg_mac(u8 *mac) -{ - efi_guid_t guid = EFI_GLOBAL_VARIABLE_GUID; - unsigned long size = ETH_ALEN; - u8 buf[ETH_ALEN]; - efi_status_t rc; - - rc = efi.get_variable(mlxbf_tmfifo_efi_name, &guid, NULL, &size, buf); - if (rc == EFI_SUCCESS && size == ETH_ALEN) - ether_addr_copy(mac, buf); - else - ether_addr_copy(mac, mlxbf_tmfifo_net_default_mac); -} - /* Set TmFifo thresolds which is used to trigger interrupts. */ static void mlxbf_tmfifo_set_threshold(struct mlxbf_tmfifo *fifo) { @@ -1169,7 +1297,7 @@ static void mlxbf_tmfifo_cleanup(struct mlxbf_tmfifo *fifo) { int i; - fifo->is_ready = false; + fifo->is_ready = 0; del_timer_sync(&fifo->timer); mlxbf_tmfifo_disable_irqs(fifo); cancel_work_sync(&fifo->work); @@ -1242,7 +1370,7 @@ static int mlxbf_tmfifo_probe(struct platform_device *pdev) mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL); - fifo->is_ready = true; + fifo->is_ready = 1; return 0; fail: @@ -1277,6 +1405,6 @@ static int mlxbf_tmfifo_remove(struct platform_device *pdev) module_platform_driver(mlxbf_tmfifo_driver); -MODULE_DESCRIPTION("Mellanox BlueField SoC TmFifo Driver"); -MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("BlueField SoC TmFifo Driver"); +MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("Mellanox Technologies");