Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp259716pxb; Tue, 12 Apr 2022 23:37:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4hG8f1+9TgH6ShEbdjl1Qly3gkn5mtB0D1+OWa+rZZyzpcaAbUzlM18YyN8MPrWrX1O0b X-Received: by 2002:a17:907:7f87:b0:6e8:354c:d440 with SMTP id qk7-20020a1709077f8700b006e8354cd440mr26722908ejc.761.1649831854170; Tue, 12 Apr 2022 23:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649831854; cv=none; d=google.com; s=arc-20160816; b=C336Tabw6G9NDyE5BlVX8VYBo0E+FUdF+vfwngntWJnGr2ICtT2t70tjdBJJXtfO0D tmjSEUsuHFhVS+dalnBRsYWu0BkfNQrpczEijZIF9pm3FaogIvuOULun4o4OmZx5U7LQ 7PtRvHGUO6omtwXfdhj9RidkiTkZLdVQ7SIBQmlpGdp5EO0A3RjfjQWglLQ0FbHm3vgD fA9mW7cURzxiT/kJlqFMyR6QZOPZqZQ784BLDv9owyMLYyeAPDv4vZIYNRzff8Ph3lHe hefdEA21vLECr7GeHb8ApaLcotBGLo7nZ4Ef92zxuelSLJX33z3jL1QINvaAjp1gxlkv oSmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+h6JKrFBeXYt5Pz5XX2g7jcfbhQvOPvbUScAQ8vwG2o=; b=XrY3PlieA2kIyqBqGzgnDlVIIMQijevjGPoj+u+f80vscPoFssqFVLGMkjP2Yo6+Rv ohLrUnZ2T/lO07F+QKSuW8Xx8n7ATkLPEOyQNkzOtnUPg2o3kSxxs5T3DU9Y2Zm6vwt6 NYq/77Y5WwGQSAy5WE5g8btSWwBYcEUcY68UzbF3u+KRrPvVv34Ggu+tgvN+7Dxo3oGe /T56sJsz2J24H/jvQa6x+faILvsSnGj+FodZRAOvss9zvjpZ2LqShTJHH3eeNF6q6Esp +9+jZv/hUBujPri1tGOPyKdI/OfhGHk9JZFanNV/jav2Le6cMSG7V4uSBtSOk9694VeX rBZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0220 header.b=OzZb27DR; 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=REJECT dis=NONE) header.from=marvell.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v18-20020a1709063bd200b006e7f853029esi10274305ejf.444.2022.04.12.23.37.08; Tue, 12 Apr 2022 23:37:34 -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=@marvell.com header.s=pfpt0220 header.b=OzZb27DR; 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=REJECT dis=NONE) header.from=marvell.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232105AbiDMDiN (ORCPT + 99 others); Tue, 12 Apr 2022 23:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232029AbiDMDhp (ORCPT ); Tue, 12 Apr 2022 23:37:45 -0400 Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D00926563; Tue, 12 Apr 2022 20:35:25 -0700 (PDT) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 23CNGcaY018361; Tue, 12 Apr 2022 20:35:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=+h6JKrFBeXYt5Pz5XX2g7jcfbhQvOPvbUScAQ8vwG2o=; b=OzZb27DRRYgrDWoeCRQqFblGOygrbegC3ylvkCtOuND/fMb/dzKm4AFogBiYuDuPf1oS NigL370/SZMESs/nfzBEtWDZaSN/tri3BAtgw6TIyorW92EAs9Zvqs7WukqknKZG7BO/ gALkS9l/CbheA1d6QAHhepMFXPy8domKNwUuRQ7spCxWLWyos8S2rJPJ/lIoAScwWS4B I2WCRnxqHM6f9038RUlX7wR9VGLM4VnI8HQw9Ds0HW6cpqm3+3sOcI5LXWRdlK9rTDsZ oFYfmcOs1TW7eGXzGUWMIxyK0eZ4AllCA7ZRvGop2GSxdI4xVZ0j+ITYDGOZ1jj5IIzL yg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3fdjxyrtjm-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 12 Apr 2022 20:35:12 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 12 Apr 2022 20:35:08 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Tue, 12 Apr 2022 20:35:08 -0700 Received: from sburla-PowerEdge-T630.caveonetworks.com (unknown [10.106.27.217]) by maili.marvell.com (Postfix) with ESMTP id 6F8F23F7048; Tue, 12 Apr 2022 20:35:08 -0700 (PDT) From: Veerasenareddy Burru To: , , , , , , CC: Abhijit Ayarekar , Satananda Burla Subject: [net-next PATCH v5 5/7] octeon_ep: add support for ndo ops Date: Tue, 12 Apr 2022 20:35:01 -0700 Message-ID: <20220413033503.3962-6-vburru@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220413033503.3962-1-vburru@marvell.com> References: <20220413033503.3962-1-vburru@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: 9XERuMEDdrjOZY-9HVBK2Z4z8kvu0QW6 X-Proofpoint-ORIG-GUID: 9XERuMEDdrjOZY-9HVBK2Z4z8kvu0QW6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-12_06,2022-04-12_02,2022-02-23_01 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Add support for ndo ops to set MAC address, change MTU, get stats. Add control path support to set MAC address, change MTU, get stats, set speed, get and set link mode. Signed-off-by: Veerasenareddy Burru Signed-off-by: Abhijit Ayarekar Signed-off-by: Satananda Burla --- V4 -> V5: no change. V3 -> V4: - fix build errors observed with "make W=1 C=1", missed to fix in v3 patchset. - declare variables used to access BAR space with "__iomem" attribute and use memcpy_fromio() instead of memcpy() from copying from __iomem regions. V2 -> V3: no change. V1 -> V2: - Address review comments: - declare variables in reversed Christmas tree, in all functions. - Replace {0} with {} to zero initialize a structure. - use success oriented approach when returning on error; Replace err = foo(..); if (!err) { /* Scucess */ .... } return err; with err = foo(..); if (err) return err; /* Success */ .... - fix build errors observed with clang and "make W=1 C=1". .../marvell/octeon_ep/octep_ctrl_mbox.h | 2 +- .../marvell/octeon_ep/octep_ctrl_net.c | 60 ++++++++++++++ .../ethernet/marvell/octeon_ep/octep_main.c | 78 +++++++++++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_mbox.h b/drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_mbox.h index 30f497f0bc26..2dc5753cfec6 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_mbox.h +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_mbox.h @@ -120,7 +120,7 @@ struct octep_ctrl_mbox { /* size of bar memory */ u32 barmem_sz; /* pointer to BAR memory */ - void __iomem *barmem; + u8 __iomem *barmem; /* user context for callback, can be null */ void *user_ctx; /* callback handler for processing request, called from octep_ctrl_mbox_recv */ diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c b/drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c index c3aca7b2775b..7c00c896ab98 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_ctrl_net.c @@ -87,6 +87,66 @@ int octep_get_mac_addr(struct octep_device *oct, u8 *addr) return err; } +int octep_set_mac_addr(struct octep_device *oct, u8 *addr) +{ + struct octep_ctrl_net_h2f_req req = {}; + struct octep_ctrl_mbox_msg msg = {}; + + req.hdr.cmd = OCTEP_CTRL_NET_H2F_CMD_MAC; + req.mac.cmd = OCTEP_CTRL_NET_CMD_SET; + memcpy(&req.mac.addr, addr, ETH_ALEN); + + msg.hdr.flags = OCTEP_CTRL_MBOX_MSG_HDR_FLAG_REQ; + msg.hdr.sizew = OCTEP_CTRL_NET_H2F_MAC_REQ_SZW; + msg.msg = &req; + + return octep_ctrl_mbox_send(&oct->ctrl_mbox, &msg); +} + +int octep_set_mtu(struct octep_device *oct, int mtu) +{ + struct octep_ctrl_net_h2f_req req = {}; + struct octep_ctrl_mbox_msg msg = {}; + + req.hdr.cmd = OCTEP_CTRL_NET_H2F_CMD_MTU; + req.mtu.cmd = OCTEP_CTRL_NET_CMD_SET; + req.mtu.val = mtu; + + msg.hdr.flags = OCTEP_CTRL_MBOX_MSG_HDR_FLAG_REQ; + msg.hdr.sizew = OCTEP_CTRL_NET_H2F_MTU_REQ_SZW; + msg.msg = &req; + + return octep_ctrl_mbox_send(&oct->ctrl_mbox, &msg); +} + +int octep_get_if_stats(struct octep_device *oct) +{ + void __iomem *iface_rx_stats; + void __iomem *iface_tx_stats; + struct octep_ctrl_net_h2f_req req = {}; + struct octep_ctrl_mbox_msg msg = {}; + int err; + + req.hdr.cmd = OCTEP_CTRL_NET_H2F_CMD_GET_IF_STATS; + req.mac.cmd = OCTEP_CTRL_NET_CMD_GET; + req.get_stats.offset = oct->ctrl_mbox_ifstats_offset; + + msg.hdr.flags = OCTEP_CTRL_MBOX_MSG_HDR_FLAG_REQ; + msg.hdr.sizew = OCTEP_CTRL_NET_H2F_GET_STATS_REQ_SZW; + msg.msg = &req; + err = octep_ctrl_mbox_send(&oct->ctrl_mbox, &msg); + if (err) + return err; + + iface_rx_stats = oct->ctrl_mbox.barmem + oct->ctrl_mbox_ifstats_offset; + iface_tx_stats = oct->ctrl_mbox.barmem + oct->ctrl_mbox_ifstats_offset + + sizeof(struct octep_iface_rx_stats); + memcpy_fromio(&oct->iface_rx_stats, iface_rx_stats, sizeof(struct octep_iface_rx_stats)); + memcpy_fromio(&oct->iface_tx_stats, iface_tx_stats, sizeof(struct octep_iface_tx_stats)); + + return err; +} + int octep_get_link_info(struct octep_device *oct) { struct octep_ctrl_net_h2f_req req = {}; diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c index 8b3dc50d08fd..dac1e9464794 100644 --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c @@ -152,6 +152,43 @@ static netdev_tx_t octep_start_xmit(struct sk_buff *skb, return NETDEV_TX_OK; } +/** + * octep_get_stats64() - Get Octeon network device statistics. + * + * @netdev: kernel network device. + * @stats: pointer to stats structure to be filled in. + */ +static void octep_get_stats64(struct net_device *netdev, + struct rtnl_link_stats64 *stats) +{ + u64 tx_packets, tx_bytes, rx_packets, rx_bytes; + struct octep_device *oct = netdev_priv(netdev); + int q; + + octep_get_if_stats(oct); + tx_packets = 0; + tx_bytes = 0; + rx_packets = 0; + rx_bytes = 0; + for (q = 0; q < oct->num_oqs; q++) { + struct octep_iq *iq = oct->iq[q]; + struct octep_oq *oq = oct->oq[q]; + + tx_packets += iq->stats.instr_completed; + tx_bytes += iq->stats.bytes_sent; + rx_packets += oq->stats.packets; + rx_bytes += oq->stats.bytes; + } + stats->tx_packets = tx_packets; + stats->tx_bytes = tx_bytes; + stats->rx_packets = rx_packets; + stats->rx_bytes = rx_bytes; + stats->multicast = oct->iface_rx_stats.mcast_pkts; + stats->rx_errors = oct->iface_rx_stats.err_pkts; + stats->collisions = oct->iface_tx_stats.xscol; + stats->tx_fifo_errors = oct->iface_tx_stats.undflw; +} + /** * octep_tx_timeout_task - work queue task to Handle Tx queue timeout. * @@ -190,11 +227,52 @@ static void octep_tx_timeout(struct net_device *netdev, unsigned int txqueue) queue_work(octep_wq, &oct->tx_timeout_task); } +static int octep_set_mac(struct net_device *netdev, void *p) +{ + struct octep_device *oct = netdev_priv(netdev); + struct sockaddr *addr = (struct sockaddr *)p; + int err; + + if (!is_valid_ether_addr(addr->sa_data)) + return -EADDRNOTAVAIL; + + err = octep_set_mac_addr(oct, addr->sa_data); + if (err) + return err; + + memcpy(oct->mac_addr, addr->sa_data, ETH_ALEN); + eth_hw_addr_set(netdev, addr->sa_data); + + return 0; +} + +static int octep_change_mtu(struct net_device *netdev, int new_mtu) +{ + struct octep_device *oct = netdev_priv(netdev); + struct octep_iface_link_info *link_info; + int err = 0; + + link_info = &oct->link_info; + if (link_info->mtu == new_mtu) + return 0; + + err = octep_set_mtu(oct, new_mtu); + if (!err) { + oct->link_info.mtu = new_mtu; + netdev->mtu = new_mtu; + } + + return err; +} + static const struct net_device_ops octep_netdev_ops = { .ndo_open = octep_open, .ndo_stop = octep_stop, .ndo_start_xmit = octep_start_xmit, + .ndo_get_stats64 = octep_get_stats64, .ndo_tx_timeout = octep_tx_timeout, + .ndo_set_mac_address = octep_set_mac, + .ndo_change_mtu = octep_change_mtu, }; /** -- 2.17.1