Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3223628rwb; Tue, 8 Nov 2022 01:57:13 -0800 (PST) X-Google-Smtp-Source: AMsMyM6pzDehpIedmKVOIj8sbbVBGl7bDIk9h3atwv/XhQWwLV8f08TNoq7fxMMiYdZUvQq+/bGt X-Received: by 2002:a50:eb83:0:b0:462:a2ac:8623 with SMTP id y3-20020a50eb83000000b00462a2ac8623mr54699765edr.360.1667901433556; Tue, 08 Nov 2022 01:57:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667901433; cv=none; d=google.com; s=arc-20160816; b=Ku9EMpZ+wOXoiQJK+qihRG7kLfUAbwewXgv7aYSnaYvPWnTafykiRWoJytVqwvZaxh QGWfo0NiC3t08eTVyftwOz1Z6cOCprn51GBCA4JCXlHNq2tVAVlHXCkHvt2Bg0Ua2iS1 iAZHJfMCV7HSVV5qZtkaFs25Uo7YA0wbw4oTVIwM1KeQVPDaI4aVixSuFHGAjt/0lDu/ WYqqQP7edbq1p3F115FROeAsrRf8S/xNeeM06RlAwXSN1b4pxcUFWUecZIQqw7luMmM3 nGY9gy/nZVowTmVIsfL1fkonEuF6CTiIzXVLKuWjBQjkcNLDt0BoHCI+IVvaD1yzA556 ON6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZioQH0ZdPvbg8JsVgr0Jja7ENNA+LAa9Yzjp7in7/t0=; b=F4FStGA2EshExzaY+ZMcCFEiKvbkhmy0XVeVZMP70g3iWZdyKhM0D9ZV4k2GAecwe9 jl6dyeBS3kcKo6Aaoa6rUPiK8c9Vmbd5eOvOeiz2OpgEvxgnAy0DRGImeb0dcc+3i7pj 1YlHP5FtzxA1Lh6DMNUlYqCms3+ailUQf5vrfD3jFagaiKYN1lRGVav60m3Hv9ybXKDT 5LeNGcWiC0IRjTc71XQQpmuTTbYY7uHR1i0K7o6spbtSfsMXCdxa00OlRg49qvPWhjW5 1bVXzxW1egMPzrkD2KdZ/vSFG7EsaF8Rc1G26kZ61B6RSmO+E7ws7jLhaNLPFs493uig /0pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=j1Pjb6kN; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga32-20020a1709070c2000b007ade20fc415si13014564ejc.811.2022.11.08.01.56.48; Tue, 08 Nov 2022 01:57:13 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=j1Pjb6kN; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233751AbiKHJVa (ORCPT + 89 others); Tue, 8 Nov 2022 04:21:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233606AbiKHJVV (ORCPT ); Tue, 8 Nov 2022 04:21:21 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7128120F7F; Tue, 8 Nov 2022 01:21:20 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id f27so36969398eje.1; Tue, 08 Nov 2022 01:21:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ZioQH0ZdPvbg8JsVgr0Jja7ENNA+LAa9Yzjp7in7/t0=; b=j1Pjb6kNYsWmK1z/0ZfR+rj2fv/BzIU7Cc/s9RwB+0OjIz3F4CIPFB+smNiDSa8Lf9 5H6fOc2DgbtHWJdf1afjIs23ZBDkzsK+aaFuoLmqIwI8+Y0v6gotRO+p6rSB0FAt4e4L Qwf6HkDNBnTbPcmnq4D/wIm25H660M6LEUEhkYo4lMB7UN0gMe25PiRKbNLGzgyhRzER uvdM1qIdIym7MpTXh6CbD2hvSflwuFy1O3OjZmG5viYiPr2esoZNA/O8Q0uCvj3eVdji 2nfwonLxxk0d1vN/wJ3niLrE3kf/hJsL7XmUX6Q5+Zl9LLeJ1uaBdLW9UtXLF8dsWLKO W8iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZioQH0ZdPvbg8JsVgr0Jja7ENNA+LAa9Yzjp7in7/t0=; b=QoARKOnVK7kYReIN2DtFZGp1x64Kh4HHTegNWZfEdrDRc1Bn6ZZ3pPaSI3eX5eeeJR 335jlAgyU7TeqZ+6p1XK53PbOkTzkd/K6bTvA1Pi3B56SZwv+j1vNj6dWYOLQe+MXzKw S52MaolpA2ka37V2ex17xaUxSKEGJTE2L7a4+LK9iXDKpZ+5arw6IVbaWR9DOjHAYyDp 6eYPeckJD4nEupjHlTSmjiCayVW1SqrBD+1qFYD6Bejzog7ZHz4ifyNAD8PRipnkufx0 O6cjil7c+/uDm8MhIbRRh6BcZLr/6uxbxOzhA/5r4KRvZoIL+tDK6HQzyprOz/EDDA9W lA3Q== X-Gm-Message-State: ACrzQf3dd5rf4+EbQwya8sxLxWC9mIo2kHETCs03TBzlLZw/t0fgAzY/ HR0XgZ5ChWxwN2V0XUJs0Bs= X-Received: by 2002:a17:906:5e51:b0:7ae:32ca:78c9 with SMTP id b17-20020a1709065e5100b007ae32ca78c9mr20885499eju.166.1667899278966; Tue, 08 Nov 2022 01:21:18 -0800 (PST) Received: from skbuf ([188.27.184.197]) by smtp.gmail.com with ESMTPSA id h3-20020a1709066d8300b0074136cac2e7sm4398494ejt.81.2022.11.08.01.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 01:21:18 -0800 (PST) Date: Tue, 8 Nov 2022 11:21:16 +0200 From: Vladimir Oltean To: Oleksij Rempel Cc: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Vivien Didelot , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Arun.Ramadoss@microchip.com Subject: Re: [PATCH net-next v3 3/3] net: dsa: microchip: ksz8: add MTU configuration support Message-ID: <20221108092116.fpwvlxz3bbvkha66@skbuf> References: <20221108054336.4165931-1-o.rempel@pengutronix.de> <20221108054336.4165931-4-o.rempel@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221108054336.4165931-4-o.rempel@pengutronix.de> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 On Tue, Nov 08, 2022 at 06:43:36AM +0100, Oleksij Rempel wrote: > +static int ksz8863_change_mtu(struct ksz_device *dev, int port, int max_frame) Don't pass "int port" if you're not going to use it. > +{ > + u8 ctrl2 = 0; > + > + if (max_frame <= KSZ8_LEGAL_PACKET_SIZE) > + ctrl2 |= KSZ8863_LEGAL_PACKET_ENABLE; > + else if (max_frame > KSZ8863_NORMAL_PACKET_SIZE) > + ctrl2 |= KSZ8863_HUGE_PACKET_ENABLE; > + > + return ksz_rmw8(dev, REG_SW_CTRL_2, KSZ8863_LEGAL_PACKET_ENABLE > + | KSZ8863_HUGE_PACKET_ENABLE, ctrl2); Coding conventions are to not start a new line with an operator, but to put it at the end of the previous line: return ksz_rmw8(dev, REG_SW_CTRL_2, KSZ8863_LEGAL_PACKET_ENABLE | KSZ8863_HUGE_PACKET_ENABLE, ctrl2); > +} > + > +static int ksz8795_change_mtu(struct ksz_device *dev, int port, int max_frame) Same. > +{ > + u8 ctrl1 = 0, ctrl2 = 0; > + int ret; > + > + if (max_frame > KSZ8_LEGAL_PACKET_SIZE) > + ctrl2 |= SW_LEGAL_PACKET_DISABLE; > + else if (max_frame > KSZ8863_NORMAL_PACKET_SIZE) > + ctrl1 |= SW_HUGE_PACKET; > + > + ret = ksz_rmw8(dev, REG_SW_CTRL_1, SW_HUGE_PACKET, ctrl1); > + if (ret) > + return ret; > + > + return ksz_rmw8(dev, REG_SW_CTRL_2, SW_LEGAL_PACKET_DISABLE, ctrl2); > +} > + > +int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu) > +{ > + u16 frame_size, max_frame = 0; > + int i; > + > + frame_size = mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; > + > + /* Cache the per-port MTU setting */ > + dev->ports[port].max_frame = frame_size; > + > + for (i = 0; i < dev->info->port_cnt; i++) > + max_frame = max(max_frame, dev->ports[i].max_frame); You can do what other switches do, and instead of caching into an array, "return 0" for everything except the CPU port. The CPU port will always be programmed with the largest MTU. > + > + switch (dev->chip_id) { > + case KSZ8795_CHIP_ID: > + case KSZ8794_CHIP_ID: > + case KSZ8765_CHIP_ID: > + return ksz8795_change_mtu(dev, port, max_frame); > + case KSZ8830_CHIP_ID: > + return ksz8863_change_mtu(dev, port, max_frame); > + } > + > + return -EOPNOTSUPP; > +} > +