From patchwork Wed Jul 27 11:39:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 12930381 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 8FECDC04A68 for ; Wed, 27 Jul 2022 11:40:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232360AbiG0Lj6 (ORCPT ); Wed, 27 Jul 2022 07:39:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232483AbiG0Lju (ORCPT ); Wed, 27 Jul 2022 07:39:50 -0400 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150047.outbound.protection.outlook.com [40.107.15.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DCB14A817; Wed, 27 Jul 2022 04:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TpYM7oXPOHTY0kVAVRwDF/2fub/hO5Db/MFaSeZHxPms/JJVAQnueOJXGjJoSGxuUstc8UQlbsp1tPn05INfeIvPlOaZYVzJ6Agorq8M+04Ff8ML7qGkK178De1XGMZl/DmtuARHTpvG8C8nmX0tjSfMq8q0ZJxz70tDT4TH7avyRHBtMZwStKb1OAEyDrCO/McEcWEz3Sgxxn6xoxJ9jF/LsHHgNk2bnA44COemn8WYQRIKQKGwZcHDFP6gqmq2yZa31WrdAuep9eGGTqKO190Q6j/YiYNfIFQth8ibKXS4OoGP0b47Mxq8WMMLwgaRTagcYmMh3Lpfb7kr26f7GA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jJp0V+0kY8rdq0JAprqzgWILm1S7hYossD2/Gky3V/U=; b=kg65X1x4QYtFfmtM+DjvB99Ax4XZa0VspNx7W0/ztBH71wzfvWJN1ocKtzA3A47nJaZ7Y7JHtaGwCPgDhpWE8YurOz8zHml4ngTczPQjvy7iubaAXFmnaGHxdXxFP1DRv1v/IGwRIoK8eSSsT3E4X8GTWEzQhFio4TImDNEsWMbCWXG0hF1L++PWFgOxsOHU5QsdXGdkOwdl3jO1Yl+/43SMLEtS/fca8h2H8/M2D+RSDKp3SuzKFlnffzcFjWFsqQAZ38BjtFqFk4lTNhs73J+6Qcig8KbdRvLWMaTmXMqtrXhiB9GsECsbUqHz4vBYX6Q7WNLRaKAtqCLUzLV0Yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jJp0V+0kY8rdq0JAprqzgWILm1S7hYossD2/Gky3V/U=; b=hW9WSM9Aku7lO3u8xKdWMDvUMm6/IA15ZkjR4kb4UnRxBKGhqL4PvUjYfNjTA6NDXHsIbDUS7Y7xRd42Zw1qK7yQcjgKMnzQ6w7zisuBUVaG6TvOoqJ0QaFy0MHKn7ccP2oNn6Wkdej8VT4ZWkHXyZn1evPtUo9p1AVY4K6XxB+DkJTHgDfVJ4bc/LRlNlna7VvlUldN+qpYfztRLUZ5MAYo1Y0sSxKqycm3Gac3MJ0QvN7+FQ49yj3LXY8O7m4RjnCTKwbTzVpWZaZXTvwGo70h3SfB6MoU8YqNpxVg1Bvs8SzqYKcsQ/Pa4I5dTg0GLrGEDJefCW2N7nNC+zmjUw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR0401MB2526.eurprd04.prod.outlook.com (2603:10a6:800:58::16) by AM5PR0401MB2641.eurprd04.prod.outlook.com (2603:10a6:203:3b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.25; Wed, 27 Jul 2022 11:39:46 +0000 Received: from VI1PR0401MB2526.eurprd04.prod.outlook.com ([fe80::21d5:a855:6e65:cf5d]) by VI1PR0401MB2526.eurprd04.prod.outlook.com ([fe80::21d5:a855:6e65:cf5d%12]) with mapi id 15.20.5458.025; Wed, 27 Jul 2022 11:39:45 +0000 Message-ID: <2397d98d-e373-1740-eb5f-8fe795a0352a@suse.com> Date: Wed, 27 Jul 2022 13:39:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 To: Hayes Wang Content-Language: en-US Cc: USB list , "netdev@vger.kernel.org" From: Oliver Neukum Subject: handling MAC set by user space in reset_resume() of r8152 X-ClientProxiedBy: AM5PR0602CA0023.eurprd06.prod.outlook.com (2603:10a6:203:a3::33) To VI1PR0401MB2526.eurprd04.prod.outlook.com (2603:10a6:800:58::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 878a704a-b862-436a-cf54-08da6fc4b440 X-MS-TrafficTypeDiagnostic: AM5PR0401MB2641:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VTvRw8vMGtpj49zK8vDqYvyVFhyPbY+YnfnEr2eVDI42wot9QHkwdfjOu1olzJ9Wn/T5mR3scrbQw74g653M9oqStjEXqtXMM45MMjH6ah4o1/TksISP38JHsjWhjTMEEELAUIeipHJulqxAByW9h7AcOUhU72v8Oe2aFXxZVK62yqD8hYB0AjAWi25apmcbjjrqg6ceZfrT1B+E9FsPinv6og5H5Rf+R2NPErUyNPskoCV6tJ2RZ8zdOyOGBusPv8QNhinTOyMoLLY0t/lkZbH+f7ABm5bjz7sgGT3Mm2dJcpamac1wqWXb7JbAxW0uKfZYKJd+e7wNkF0m5Nl6CQ5tzdKcHR3dgkbK/hHrsgP1cTVcQcX+LI0/i/IYTWNRhzrh9XMYujN1l48gTUkEZtmH4C6h/JtGt4vOV9XQxPhXeFYc4VbuOWU8HwlhF7rKA0gFUYsqIbRvXTjXZcx8jk4QNLVcI19SmQeLGEFxgb+k1hLwm69f8esBlWw8FYER59XdO+T/0I5yflqzrlvqiExd/UivBc6hkJzVDEjR5IMNu3nknKp3SfoNcC6rXj8S1dtfu9llYMxHx/s4fMXMjO8wWE2TwG8m4FKkNsX+1OkAMKIuS+eS9yU7qJvs1dH3wCzAihJq2NrvlAjVJe9ev/0FJruCdb1l4LxC4Van059W0+CN+m8jBRBWZz24bLxICSSVuwGHkKRK1igMpRBn6+kHmvdr18m1AAn2TvJzoy49RgLqCNl0K1Y+RCRH3IL0zwSBtN8VRlQUailhvC+p+2vMKnOQmsWuD7G1wcbD5rUz1miKePMpwaFm37LcOPgGirYjmSjRh33mPX3r/24L8w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0401MB2526.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(39860400002)(346002)(376002)(396003)(366004)(136003)(36756003)(4326008)(8676002)(66946007)(66556008)(66476007)(235185007)(186003)(6486002)(54906003)(6916009)(6506007)(33964004)(2616005)(316002)(31686004)(83380400001)(564344004)(38100700002)(478600001)(86362001)(6512007)(8936002)(2906002)(41300700001)(31696002)(5660300002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-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B/m/b457SdMxlR3GBQ+Su2V8oVg/ZMMBH1ppRD4f1nqHp0xDvkTn1N0uI0/2kJ?= =?utf-8?q?EL7HVDgChoJEY0Se9LruukMHFMiv8SxKT9iz5GX7UDHtLjH7GEESu3TfDzvYSvKfg?= =?utf-8?q?c+dQHTBJTz85EkyiA+n59biHjuGejsBsDAj+YAkkcy0QfK39XB0kSDSWkFHw+rF37?= =?utf-8?q?48jJix1yBhbCupnePeCbeGRVcjS+o+wN3tRVhDNYZUsk/B0taKteNzBX0BZsS5let?= =?utf-8?q?PMl6BJRMt+tFltySX9hi9GxtiGAweA/vvnuMJjtV14pZ66RQl8dS2f8/ZQD4ufRuR?= =?utf-8?q?InmKHR9douLcEtUa0a8qNOSoK0GqWVjdsC4/q5S5RUbvDxG0TYftnoZsfguUcvHc0?= =?utf-8?q?hDcRwQ0UtUkOL8/cuEvKTSy2ovq0YXQySC3U4RQvFVWVitDZDA8GN8ZTChkzsTnOZ?= =?utf-8?q?BfA0kwbSSiTvpwouxSrIUCvjF9WCe3tBmUaY1qrt0qN66lh4mLSoB2uzDSWVxDGMD?= =?utf-8?q?3tjAPCWDWUWtfp+1tSc5gvsDm2QtH0h8LoZS//0aNzI0gsft5Mu3OiBk5YMlvspp1?= =?utf-8?q?ZR+iHM3ow+LOZauLAXzlxYJbaDF/8aObC58VsSewVxwE9R9pJ3t+gzyrxRmRrkTB4?= =?utf-8?q?SPmymRCTj/tvscAOwYfVUAr+zZr+4HgIWtZDeRsPZ9swiCUc9bara6/j0lnOwQRF9?= =?utf-8?q?dxm4jIDtT/qv1hOwUgUqOk4T4Iy2PburpY0msAKJSoHJyQvbBT+hh28MD3dNshLN7?= =?utf-8?q?JA7OUmTvOOr?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 878a704a-b862-436a-cf54-08da6fc4b440 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0401MB2526.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2022 11:39:45.7734 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vK0yDHpEVvq7rqZX+YbXK4ryiAmMud5oN7hsrJhPPBFqBBVBwOYWtg9aqtKMHWinzFqGErq7shPqX+K++Nht2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0401MB2641 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Hi, looking at the driver it looks to me like the address provided to ndo_set_mac_address() is thrown away after use. That looks problematic to me, because reset_resume() should redo the operation. What do you think? Regards Oliver From 19fc972a5cc98197bc81a7c56dd5d68e3fdfc36b Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Wed, 27 Jul 2022 13:29:42 +0200 Subject: [PATCH] r8152: restore external MAC in reset_resume If user space has set the MAC of the interface, reset_resume() must restore that setting rather than redetermine the MAC like if te interface is probed regularly. Signed-off-by: Oliver Neukum --- drivers/net/usb/r8152.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 0f6efaabaa32..5cf74b984655 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -923,6 +923,7 @@ struct r8152 { atomic_t rx_count; bool eee_en; + bool external_mac; int intr_interval; u32 saved_wolopts; u32 msg_enable; @@ -933,6 +934,8 @@ struct r8152 { u32 rx_copybreak; u32 rx_pending; u32 fc_pause_on, fc_pause_off; + /* for reset_resume */ + struct sockaddr saved_addr; unsigned int pipe_in, pipe_out, pipe_intr, pipe_ctrl_in, pipe_ctrl_out; @@ -1574,6 +1577,7 @@ static int __rtl8152_set_mac_address(struct net_device *netdev, void *p, mutex_lock(&tp->control); eth_hw_addr_set(netdev, addr->sa_data); + memcpy(&tp->saved_addr, addr, sizeof(tp->saved_addr)); ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); pla_ocp_write(tp, PLA_IDR, BYTE_EN_SIX_BYTES, 8, addr->sa_data); @@ -1589,7 +1593,13 @@ static int __rtl8152_set_mac_address(struct net_device *netdev, void *p, static int rtl8152_set_mac_address(struct net_device *netdev, void *p) { - return __rtl8152_set_mac_address(netdev, p, false); + int rv; + struct r8152 *tp = netdev_priv(netdev); + + rv = __rtl8152_set_mac_address(netdev, p, false); + if (!rv) + tp->external_mac = true; + return rv; } /* Devices containing proper chips can support a persistent @@ -1676,10 +1686,14 @@ static int vendor_mac_passthru_addr_read(struct r8152 *tp, struct sockaddr *sa) static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa) { struct net_device *dev = tp->netdev; - int ret; + int ret = 0; sa->sa_family = dev->type; + if (tp->external_mac) { + ether_addr_copy(sa->sa_data, dev->dev_addr); + return ret; + } ret = eth_platform_get_mac_address(&tp->udev->dev, sa->sa_data); if (ret < 0) { if (tp->version == RTL_VER_01) { @@ -1713,17 +1727,18 @@ static int determine_ethernet_addr(struct r8152 *tp, struct sockaddr *sa) static int set_ethernet_addr(struct r8152 *tp, bool in_resume) { struct net_device *dev = tp->netdev; - struct sockaddr sa; - int ret; + int ret = 0; - ret = determine_ethernet_addr(tp, &sa); - if (ret < 0) - return ret; + if (!tp->external_mac) { + ret = determine_ethernet_addr(tp, &tp->saved_addr); + if (ret < 0) + return ret; + } if (tp->version == RTL_VER_01) - eth_hw_addr_set(dev, sa.sa_data); + eth_hw_addr_set(dev, tp->saved_addr.sa_data); else - ret = __rtl8152_set_mac_address(dev, &sa, in_resume); + ret = __rtl8152_set_mac_address(dev, &tp->saved_addr, in_resume); return ret; } @@ -6225,6 +6240,7 @@ static void rtl8152_down(struct r8152 *tp) r8152_aldps_en(tp, false); r8152b_enter_oob(tp); r8152_aldps_en(tp, true); + tp->external_mac = false; } static void rtl8153_up(struct r8152 *tp) -- 2.35.3