Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1158370imu; Tue, 20 Nov 2018 12:41:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/U3FyHMlHMPk3FqepfVF9EQzLpq+ljNhHvrQtQK9/ihFetW+0dsSs/vUBENs+EnggqlMeSX X-Received: by 2002:a17:902:280b:: with SMTP id e11mr3760928plb.269.1542746506486; Tue, 20 Nov 2018 12:41:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542746506; cv=none; d=google.com; s=arc-20160816; b=ZM53c86UNkf0g+aJobBXGLzQY/fDLzaTtkutoDxKVhp5iZpaRU4yuFfcaIuvVTrLqr QIB90eN+nUe1TroR86cjzw87DNnfncfz7bb0ss4+H7Bmk1Mxk0ZxffR3VNTILR0pV4m+ QzRRpXz3CHP3xPRBlVldGdQ5o+QjsnC3Zp3YFcn51G47hcPFlRsPAcGfADo0RCWpHSmX B9F6rMktxMLvmPn9u1hAHXLwvfBTS7+tEWD0K8um85qyIfYQh13gZxrb8DC/HJEpHaUV tlDi07o+rL8bGqD+5FRLqVrT57mJajZYS4/u9jWwDvPCjb9DZbIqNaF745rUIf8PtKNc SWqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject :smtp-origin-cluster:cc:to:smtp-origin-hostname:from :smtp-origin-hostprefix:dkim-signature; bh=C0bVDWa5ikxrQ1eeZ7hJ9sEsRIWOebCqNDKh+PWFPeI=; b=pyBZIs0zc8MPeLnGPFmpn9oMnrDYxqvk/jGVv+pD/7CCRfALuUkCHAi1RJaAMmbQUI s+XccpVY6pG0Oti/etoG9zIidT/Ma1EuF8ZHQDBVFTMz9rGA02HUbBmMYOiZQ39BsGQF ZSgQRMF9fqdnwHQ1hdbqHSQcSRuCAd2aCT3olNPeB+uvVrPs+qmjolO3jNs1bHoMxsDt MtrQkW9oEq0/Gh0/RWNhplLaan2+T3CkvHz/j5Vui1OzsE/TJQ2x2BRBVhr9aF/QAl7R 0kQYhsyPryFdu5SJ5jlCqBkBka0D+Cfc4J6aO+2z6b1nR/0baaizv/iDjOPXNcziAwGt QExQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=FlPI08XB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 20si2673662pgt.469.2018.11.20.12.41.31; Tue, 20 Nov 2018 12:41:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=FlPI08XB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726818AbeKUHHO (ORCPT + 99 others); Wed, 21 Nov 2018 02:07:14 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:58900 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbeKUHHO (ORCPT ); Wed, 21 Nov 2018 02:07:14 -0500 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wAKKZlp5016801 for ; Tue, 20 Nov 2018 12:36:14 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=C0bVDWa5ikxrQ1eeZ7hJ9sEsRIWOebCqNDKh+PWFPeI=; b=FlPI08XBy2kHY3ZpZ/LYftB4WrlHjCl7msYwMEoFA9LdvUtBC9iqqDLMS/l1j7rg1XR1 fyJmJaG15Xtt0VbCPVEejNYc26aHrz3rhqYiXtYByM3aeEHdXTdZZGGi82aN378q70fv VUWA1aLkZBoAtxAlQCSpwc4x6Y4gcpBKIpM= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2nvpd80u9g-12 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 20 Nov 2018 12:36:14 -0800 Received: from mx-out.facebook.com (2620:10d:c0a1:3::13) by mail.thefacebook.com (2620:10d:c021:18::172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1531.3; Tue, 20 Nov 2018 12:35:50 -0800 Received: by devvm4117.prn2.facebook.com (Postfix, from userid 167582) id B16F23FC46CB; Tue, 20 Nov 2018 12:35:46 -0800 (PST) Smtp-Origin-Hostprefix: devvm From: Vijay Khemka Smtp-Origin-Hostname: devvm4117.prn2.facebook.com To: Samuel Mendoza-Jonas , "David S. Miller" , , CC: , "openbmc @ lists . ozlabs . org" , , , Smtp-Origin-Cluster: prn2c23 Subject: [PATCH net-next] net/ncsi: Add NCSI Mellanox OEM command Date: Tue, 20 Nov 2018 12:35:16 -0800 Message-ID: <20181120203516.3460764-1-vijaykhemka@fb.com> X-Mailer: git-send-email 2.17.1 X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-20_09:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds OEM Mellanox commands and response handling. It also defines OEM Get MAC Address handler to get and configure the device. ncsi_oem_gma_handler_mlx: This handler send NCSI mellanox command for getting mac address. ncsi_rsp_handler_oem_mlx: This handles response received for all mellanox OEM commands. ncsi_rsp_handler_oem_mlx_gma: This handles get mac address response and set it to device. Signed-off-by: Vijay Khemka --- net/ncsi/internal.h | 5 +++++ net/ncsi/ncsi-manage.c | 25 ++++++++++++++++++++++++- net/ncsi/ncsi-pkt.h | 9 +++++++++ net/ncsi/ncsi-rsp.c | 41 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h index 1dae77c54009..7f3eb1360b9b 100644 --- a/net/ncsi/internal.h +++ b/net/ncsi/internal.h @@ -73,10 +73,15 @@ enum { #define NCSI_OEM_MFR_BCM_ID 0x113d /* Broadcom specific OEM Command */ #define NCSI_OEM_BCM_CMD_GMA 0x01 /* CMD ID for Get MAC */ +/* Mellanox specific OEM Command */ +#define NCSI_OEM_MLX_CMD_GMA 0x00 /* CMD ID for Get MAC */ +#define NCSI_OEM_MLX_CMD_GMA_PARAM 0x1b /* Parameter for GMA */ /* OEM Command payload lengths*/ #define NCSI_OEM_BCM_CMD_GMA_LEN 12 +#define NCSI_OEM_MLX_CMD_GMA_LEN 8 /* Mac address offset in OEM response */ #define BCM_MAC_ADDR_OFFSET 28 +#define MLX_MAC_ADDR_OFFSET 8 struct ncsi_channel_version { diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c index bfc43b28c7a6..eacb653ff987 100644 --- a/net/ncsi/ncsi-manage.c +++ b/net/ncsi/ncsi-manage.c @@ -675,12 +675,35 @@ static int ncsi_oem_gma_handler_bcm(struct ncsi_cmd_arg *nca) return ret; } +static int ncsi_oem_gma_handler_mlx(struct ncsi_cmd_arg *nca) +{ + unsigned char data[NCSI_OEM_MLX_CMD_GMA_LEN]; + int ret = 0; + + nca->payload = NCSI_OEM_MLX_CMD_GMA_LEN; + + memset(data, 0, NCSI_OEM_MLX_CMD_GMA_LEN); + *(unsigned int *)data = ntohl(NCSI_OEM_MFR_MLX_ID); + data[5] = NCSI_OEM_MLX_CMD_GMA; + data[6] = NCSI_OEM_MLX_CMD_GMA_PARAM; + + nca->data = data; + + ret = ncsi_xmit_cmd(nca); + if (ret) + netdev_err(nca->ndp->ndev.dev, + "NCSI: Failed to transmit cmd 0x%x during configure\n", + nca->type); + return ret; +} + /* OEM Command handlers initialization */ static struct ncsi_oem_gma_handler { unsigned int mfr_id; int (*handler)(struct ncsi_cmd_arg *nca); } ncsi_oem_gma_handlers[] = { - { NCSI_OEM_MFR_BCM_ID, ncsi_oem_gma_handler_bcm } + { NCSI_OEM_MFR_BCM_ID, ncsi_oem_gma_handler_bcm }, + { NCSI_OEM_MFR_MLX_ID, ncsi_oem_gma_handler_mlx } }; static int ncsi_gma_handler(struct ncsi_cmd_arg *nca, unsigned int mf_id) diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h index 4d3f06be38bd..2a6d83a596c9 100644 --- a/net/ncsi/ncsi-pkt.h +++ b/net/ncsi/ncsi-pkt.h @@ -165,6 +165,15 @@ struct ncsi_rsp_oem_pkt { unsigned char data[]; /* Payload data */ }; +/* Mellanox Response Data */ +struct ncsi_rsp_oem_mlx_pkt { + unsigned char cmd_rev; /* Command Revision */ + unsigned char cmd; /* Command ID */ + unsigned char param; /* Parameter */ + unsigned char optional; /* Optional data */ + unsigned char data[]; /* Data */ +}; + /* Broadcom Response Data */ struct ncsi_rsp_oem_bcm_pkt { unsigned char ver; /* Payload Version */ diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c index 77e07ba3f493..ba9a4ba97c64 100644 --- a/net/ncsi/ncsi-rsp.c +++ b/net/ncsi/ncsi-rsp.c @@ -611,6 +611,45 @@ 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) +{ + 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[MLX_MAC_ADDR_OFFSET], ETH_ALEN); + 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 Mellanox card */ +static int ncsi_rsp_handler_oem_mlx(struct ncsi_request *nr) +{ + struct ncsi_rsp_oem_mlx_pkt *mlx; + struct ncsi_rsp_oem_pkt *rsp; + + /* Get the response header */ + rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp); + mlx = (struct ncsi_rsp_oem_mlx_pkt *)(rsp->data); + + 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 0; +} + /* Response handler for Broadcom command Get Mac Address */ static int ncsi_rsp_handler_oem_bcm_gma(struct ncsi_request *nr) { @@ -655,7 +694,7 @@ static struct ncsi_rsp_oem_handler { unsigned int mfr_id; int (*handler)(struct ncsi_request *nr); } ncsi_rsp_oem_handlers[] = { - { NCSI_OEM_MFR_MLX_ID, NULL }, + { NCSI_OEM_MFR_MLX_ID, ncsi_rsp_handler_oem_mlx }, { NCSI_OEM_MFR_BCM_ID, ncsi_rsp_handler_oem_bcm } }; -- 2.17.1