Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5660924rwr; Tue, 9 May 2023 04:52:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7vTy94OXGktCUSw65ImyiASzwhboqVUICi/5OmJXX/uMAzKm+vUen//qgSR/FH1+0OWCJb X-Received: by 2002:a05:6a20:72a7:b0:ff:d067:34f with SMTP id o39-20020a056a2072a700b000ffd067034fmr12416639pzk.33.1683633171841; Tue, 09 May 2023 04:52:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683633171; cv=none; d=google.com; s=arc-20160816; b=h4paEj5NNS/aAoniq+P06+NWR9ZEvE/RxWnhf7WMhwUQ6U6vrHfgSWR/HL5shwQZxd 1o2DcRkmevPNfgMKiGTzgpOEhCcSXJ/32jB8m8xfAtK7vRklahfTwI1ZXDQ6ufRm80qP ii9k6dW3dxXwZKy4/ZdK27PGhuBzV9sl//YEtmpcu/NQmfDvAC7wWMxGDW+9ETkU1uml 1jNHC2cePFTX6Tv2KfJjP3h975a+YwuFuAT3xWkWh++IH+3ietpG73KhtbyeP5IQmtxq XkqcnF6qO2IEd2NXMRc5Tm7d0NbEzIszsN3SGledgoA/1w9e/l+WkJXlkTg1s7R6VlN/ ZHHg== 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=JEf8nW/e5rX1lrg2FM6+u2SZlAqTzqdeg72ZyL+zfRU=; b=z+xEnuc1b1RMFPF+Qh6h19d+2znvNhzb8232KrU41X42k0FoKOLHSUnjsx5PGie2Kg 5MBiBfeuX4Uz9SH9uKfMS1oz6z3HVVvmzgC+2CnzF3Nao9oNOSof/ZZnxFVunJ+rv1vp L5dhNJyzGDGB0A6LPQ/0Fy/QVVUgXIFXfQgqWoVMSiNtX4PIoQ1gzDNPj/lGd0SIbs2n 1Z3cdgepbzrJ7rhjibI+ZRe/7ylWrajF1cSebloJug7iZ0QYTIyZWehK62OPTr4XDDyD ddj6tiy2MdmeJN+u1+/REVi8VieNxGf9yG4zWvlf3jwikXMmLE6OuJx3XV4WLPUA2wms EtIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DBoK7x1n; 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 o22-20020aa79796000000b006455a24291dsi2126610pfp.368.2023.05.09.04.52.39; Tue, 09 May 2023 04:52:51 -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=@gmail.com header.s=20221208 header.b=DBoK7x1n; 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 S235282AbjEILfY (ORCPT + 99 others); Tue, 9 May 2023 07:35:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234221AbjEILfW (ORCPT ); Tue, 9 May 2023 07:35:22 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DDC42D62; Tue, 9 May 2023 04:35:20 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-4f139de8cefso33274559e87.0; Tue, 09 May 2023 04:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683632118; x=1686224118; 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=JEf8nW/e5rX1lrg2FM6+u2SZlAqTzqdeg72ZyL+zfRU=; b=DBoK7x1nOErHLKNeDarD+nJ7xAfoTVKzzzuvV1+0EbaXnT+NGaI9yz1CqpLTLvlkxm oSWE5X4e8uxiEGBIr+IzKysYKjXZQ312NPrRhjhNmUngxnuVTVxXKll5VG/qmg/Sgrhy inlNsCjDZJH28ohfRxgnqdan/4ecqPNd37GN3bd2IhmfrPRKcdyzLpkX8iM5DkcWIzMl T2AAxrNOH7fqdgxZrSiZWOx+1beHKeCywGAZ67WmNmOx/due+1rOadlAn+HbVCGaytkU f09hDEuCgfz2tHeHpd4+DWuYe/wrtwzNrR2CSsbgZk2vx1G9AUvbR0EDm+MWfaoZEeV3 6WXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683632118; x=1686224118; 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=JEf8nW/e5rX1lrg2FM6+u2SZlAqTzqdeg72ZyL+zfRU=; b=SYIpi8UD5dZKcP0gqvWz31Gq1InQq2T+wbZb65iS9JuYMLmvWAqHNJQ5HWagL+ZUVc YTtcekY0qogJmdB9IVSR6fngdzwh17gnF27Y2IvOjFHziC8t0y6EBU/fHTZ4tfmL33xd 7lVPRI4okQJQVRY6snMEV91/fvAV0DUm8q/5yC3rIpGef2wrrYF0rGNS5dJ2MNpezt2V pMZa+b0iRuQ49QsgbO3TjYQspqEsDyxjHiY1xU7/rQP0QB7zaXVzjRulPvSevNWiZ4sc 7nlYNxuBx/neVqGT+xl4bTuyOhBcEow0p0EW3RHjz67pmv9njIgXzmyuxpJdsrC/onlq m+Mg== X-Gm-Message-State: AC+VfDy7xes0b/sgopJ7ysdyoQHAjXgo5qtNUBXv5AfnqHpA1YtoODsQ kXkot0bxDfr5QsTTW8/ieUA= X-Received: by 2002:ac2:5d6b:0:b0:4ee:fdd8:a536 with SMTP id h11-20020ac25d6b000000b004eefdd8a536mr684045lft.8.1683632118467; Tue, 09 May 2023 04:35:18 -0700 (PDT) Received: from localhost.localdomain (93-80-66-133.broadband.corbina.ru. [93.80.66.133]) by smtp.googlemail.com with ESMTPSA id k16-20020ac24570000000b004f25ccac240sm108940lfm.74.2023.05.09.04.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 04:35:17 -0700 (PDT) From: Ivan Mikhaylov To: Samuel Mendoza-Jonas , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, Ivan Mikhaylov Subject: [PATCH v2 1/5] net/ncsi: make one oem_gma function for all mfr id Date: Tue, 9 May 2023 14:35:00 +0000 Message-Id: <20230509143504.30382-2-fr0st61te@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230509143504.30382-1-fr0st61te@gmail.com> References: <20230509143504.30382-1-fr0st61te@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,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 Make the one Get Mac Address function for all manufacturers and change this call in handlers accordingly. Signed-off-by: Ivan Mikhaylov --- net/ncsi/ncsi-rsp.c | 88 ++++++++++----------------------------------- 1 file changed, 19 insertions(+), 69 deletions(-) diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c index 6447a09932f5..91c42253a711 100644 --- a/net/ncsi/ncsi-rsp.c +++ b/net/ncsi/ncsi-rsp.c @@ -611,14 +611,15 @@ static int ncsi_rsp_handler_snfc(struct ncsi_request *nr) return 0; } -/* Response handler for Mellanox command Get Mac Address */ -static int ncsi_rsp_handler_oem_mlx_gma(struct ncsi_request *nr) +/* Response handler for Get Mac Address command */ +static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id) { struct ncsi_dev_priv *ndp = nr->ndp; struct net_device *ndev = ndp->ndev.dev; const struct net_device_ops *ops = ndev->netdev_ops; struct ncsi_rsp_oem_pkt *rsp; struct sockaddr saddr; + u32 mac_addr_off = 0; int ret = 0; /* Get the response header */ @@ -626,7 +627,19 @@ static int ncsi_rsp_handler_oem_mlx_gma(struct ncsi_request *nr) saddr.sa_family = ndev->type; ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; - memcpy(saddr.sa_data, &rsp->data[MLX_MAC_ADDR_OFFSET], ETH_ALEN); + if (mfr_id == NCSI_OEM_MFR_BCM_ID) + mac_addr_off = BCM_MAC_ADDR_OFFSET; + else if (mfr_id == NCSI_OEM_MFR_MLX_ID) + mac_addr_off = MLX_MAC_ADDR_OFFSET; + else if (mfr_id == NCSI_OEM_MFR_INTEL_ID) + mac_addr_off = INTEL_MAC_ADDR_OFFSET; + + memcpy(saddr.sa_data, &rsp->data[mac_addr_off], ETH_ALEN); + if (mfr_id == NCSI_OEM_MFR_BCM_ID || mfr_id == NCSI_OEM_MFR_INTEL_ID) + eth_addr_inc((u8 *)saddr.sa_data); + if (!is_valid_ether_addr((const u8 *)saddr.sa_data)) + return -ENXIO; + /* Set the flag for GMA command which should only be called once */ ndp->gma_flag = 1; @@ -649,41 +662,10 @@ static int ncsi_rsp_handler_oem_mlx(struct ncsi_request *nr) if (mlx->cmd == NCSI_OEM_MLX_CMD_GMA && mlx->param == NCSI_OEM_MLX_CMD_GMA_PARAM) - return ncsi_rsp_handler_oem_mlx_gma(nr); + return ncsi_rsp_handler_oem_gma(nr, NCSI_OEM_MFR_MLX_ID); return 0; } -/* Response handler for Broadcom command Get Mac Address */ -static int ncsi_rsp_handler_oem_bcm_gma(struct ncsi_request *nr) -{ - struct ncsi_dev_priv *ndp = nr->ndp; - struct net_device *ndev = ndp->ndev.dev; - const struct net_device_ops *ops = ndev->netdev_ops; - struct ncsi_rsp_oem_pkt *rsp; - struct sockaddr saddr; - int ret = 0; - - /* Get the response header */ - rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp); - - saddr.sa_family = ndev->type; - ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; - memcpy(saddr.sa_data, &rsp->data[BCM_MAC_ADDR_OFFSET], ETH_ALEN); - /* Increase mac address by 1 for BMC's address */ - eth_addr_inc((u8 *)saddr.sa_data); - if (!is_valid_ether_addr((const u8 *)saddr.sa_data)) - return -ENXIO; - - /* Set the flag for GMA command which should only be called once */ - ndp->gma_flag = 1; - - ret = ops->ndo_set_mac_address(ndev, &saddr); - if (ret < 0) - netdev_warn(ndev, "NCSI: 'Writing mac address to device failed\n"); - - return ret; -} - /* Response handler for Broadcom card */ static int ncsi_rsp_handler_oem_bcm(struct ncsi_request *nr) { @@ -695,42 +677,10 @@ static int ncsi_rsp_handler_oem_bcm(struct ncsi_request *nr) bcm = (struct ncsi_rsp_oem_bcm_pkt *)(rsp->data); if (bcm->type == NCSI_OEM_BCM_CMD_GMA) - return ncsi_rsp_handler_oem_bcm_gma(nr); + return ncsi_rsp_handler_oem_gma(nr, NCSI_OEM_MFR_BCM_ID); return 0; } -/* Response handler for Intel command Get Mac Address */ -static int ncsi_rsp_handler_oem_intel_gma(struct ncsi_request *nr) -{ - struct ncsi_dev_priv *ndp = nr->ndp; - struct net_device *ndev = ndp->ndev.dev; - const struct net_device_ops *ops = ndev->netdev_ops; - struct ncsi_rsp_oem_pkt *rsp; - struct sockaddr saddr; - int ret = 0; - - /* Get the response header */ - rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp); - - saddr.sa_family = ndev->type; - ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; - memcpy(saddr.sa_data, &rsp->data[INTEL_MAC_ADDR_OFFSET], ETH_ALEN); - /* Increase mac address by 1 for BMC's address */ - eth_addr_inc((u8 *)saddr.sa_data); - if (!is_valid_ether_addr((const u8 *)saddr.sa_data)) - return -ENXIO; - - /* Set the flag for GMA command which should only be called once */ - ndp->gma_flag = 1; - - ret = ops->ndo_set_mac_address(ndev, &saddr); - if (ret < 0) - netdev_warn(ndev, - "NCSI: 'Writing mac address to device failed\n"); - - return ret; -} - /* Response handler for Intel card */ static int ncsi_rsp_handler_oem_intel(struct ncsi_request *nr) { @@ -742,7 +692,7 @@ static int ncsi_rsp_handler_oem_intel(struct ncsi_request *nr) intel = (struct ncsi_rsp_oem_intel_pkt *)(rsp->data); if (intel->cmd == NCSI_OEM_INTEL_CMD_GMA) - return ncsi_rsp_handler_oem_intel_gma(nr); + return ncsi_rsp_handler_oem_gma(nr, NCSI_OEM_MFR_INTEL_ID); return 0; } -- 2.40.1