linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vadim Lomovtsev <Vadim.Lomovtsev@caviumnetworks.com>
To: sgoutham@cavium.com, sunil.kovvuri@gmail.com, rric@kernel.org,
	linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, davem@davemloft.net
Cc: dnelson@redhat.com, ynorov@caviumnetworks.com,
	Vadim Lomovtsev <Vadim.Lomovtsev@cavium.com>
Subject: [PATCH v2 7/7] net: thunderx: add ndo_set_rx_mode callback implementation for VF
Date: Fri, 30 Mar 2018 04:59:53 -0700	[thread overview]
Message-ID: <20180330115953.17154-8-Vadim.Lomovtsev@caviumnetworks.com> (raw)
In-Reply-To: <20180330115953.17154-1-Vadim.Lomovtsev@caviumnetworks.com>

From: Vadim Lomovtsev <Vadim.Lomovtsev@cavium.com>

The ndo_set_rx_mode() is called from atomic context which causes
messages response timeouts while VF to PF communication via MSIx.
To get rid of that we're copy passed mc list, parse flags and queue
handling of kernel request to ordered workqueue.

Signed-off-by: Vadim Lomovtsev <Vadim.Lomovtsev@cavium.com>
---
 drivers/net/ethernet/cavium/thunder/nicvf_main.c | 110 ++++++++++++++++++++++-
 1 file changed, 109 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
index 7d9c5ffbd041..c8a8faaf17e9 100644
--- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c
+++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
@@ -21,6 +21,7 @@
 #include <linux/bpf_trace.h>
 #include <linux/filter.h>
 #include <linux/net_tstamp.h>
+#include <linux/workqueue.h>
 
 #include "nic_reg.h"
 #include "nic.h"
@@ -67,6 +68,9 @@ module_param(cpi_alg, int, S_IRUGO);
 MODULE_PARM_DESC(cpi_alg,
 		 "PFC algorithm (0=none, 1=VLAN, 2=VLAN16, 3=IP Diffserv)");
 
+/* workqueue for handling kernel ndo_set_rx_mode() calls */
+static struct workqueue_struct *nicvf_rx_mode_wq;
+
 static inline u8 nicvf_netdev_qidx(struct nicvf *nic, u8 qidx)
 {
 	if (nic->sqs_mode)
@@ -1919,6 +1923,100 @@ static int nicvf_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
 	}
 }
 
+static void nicvf_set_rx_mode_task(struct work_struct *work_arg)
+{
+	struct nicvf_work *vf_work = container_of(work_arg, struct nicvf_work,
+						  work.work);
+	struct nicvf *nic = container_of(vf_work, struct nicvf, rx_mode_work);
+	union nic_mbx mbx = {};
+	struct xcast_addr *xaddr, *next;
+
+	if (!vf_work)
+		return;
+
+	/* From the inside of VM code flow we have only 128 bits memory
+	 * available to send message to host's PF, so send all mc addrs
+	 * one by one, starting from flush command in case if kernel
+	 * requests to configure specific MAC filtering
+	 */
+
+	/* flush DMAC filters and reset RX mode */
+	mbx.xcast.msg = NIC_MBOX_MSG_RESET_XCAST;
+	nicvf_send_msg_to_pf(nic, &mbx);
+
+	if (vf_work->mode & BGX_XCAST_MCAST_FILTER) {
+		/* once enabling filtering, we need to signal to PF to add
+		 * its' own LMAC to the filter to accept packets for it.
+		 */
+		mbx.xcast.msg = NIC_MBOX_MSG_ADD_MCAST;
+		mbx.xcast.data.mac = 0;
+		nicvf_send_msg_to_pf(nic, &mbx);
+	}
+
+	/* check if we have any specific MACs to be added to PF DMAC filter */
+	if (vf_work->mc) {
+		/* now go through kernel list of MACs and add them one by one */
+		list_for_each_entry_safe(xaddr, next,
+					 &vf_work->mc->list, list) {
+			mbx.xcast.msg = NIC_MBOX_MSG_ADD_MCAST;
+			mbx.xcast.data.mac = xaddr->addr;
+			nicvf_send_msg_to_pf(nic, &mbx);
+
+			/* after receiving ACK from PF release memory */
+			list_del(&xaddr->list);
+			kfree(xaddr);
+			vf_work->mc->count--;
+		}
+		kfree(vf_work->mc);
+	}
+
+	/* and finally set rx mode for PF accordingly */
+	mbx.xcast.msg = NIC_MBOX_MSG_SET_XCAST;
+	mbx.xcast.data.mode = vf_work->mode;
+
+	nicvf_send_msg_to_pf(nic, &mbx);
+}
+
+static void nicvf_set_rx_mode(struct net_device *netdev)
+{
+	struct nicvf *nic = netdev_priv(netdev);
+	struct netdev_hw_addr *ha;
+	struct xcast_addr_list *mc_list = NULL;
+	u8 mode = 0;
+
+	if (netdev->flags & IFF_PROMISC) {
+		mode = BGX_XCAST_BCAST_ACCEPT | BGX_XCAST_MCAST_ACCEPT;
+	} else {
+		if (netdev->flags & IFF_BROADCAST)
+			mode |= BGX_XCAST_BCAST_ACCEPT;
+
+		if (netdev->flags & IFF_ALLMULTI) {
+			mode |= BGX_XCAST_MCAST_ACCEPT;
+		} else if (netdev->flags & IFF_MULTICAST) {
+			mode |= BGX_XCAST_MCAST_FILTER;
+			/* here we need to copy mc addrs */
+			if (netdev_mc_count(netdev)) {
+				struct xcast_addr *xaddr;
+
+				mc_list = kmalloc(sizeof(*mc_list), GFP_ATOMIC);
+				INIT_LIST_HEAD(&mc_list->list);
+				netdev_hw_addr_list_for_each(ha, &netdev->mc) {
+					xaddr = kmalloc(sizeof(*xaddr),
+							GFP_ATOMIC);
+					xaddr->addr =
+						ether_addr_to_u64(ha->addr);
+					list_add_tail(&xaddr->list,
+						      &mc_list->list);
+					mc_list->count++;
+				}
+			}
+		}
+	}
+	nic->rx_mode_work.mc = mc_list;
+	nic->rx_mode_work.mode = mode;
+	queue_delayed_work(nicvf_rx_mode_wq, &nic->rx_mode_work.work, 2 * HZ);
+}
+
 static const struct net_device_ops nicvf_netdev_ops = {
 	.ndo_open		= nicvf_open,
 	.ndo_stop		= nicvf_stop,
@@ -1931,6 +2029,7 @@ static const struct net_device_ops nicvf_netdev_ops = {
 	.ndo_set_features       = nicvf_set_features,
 	.ndo_bpf		= nicvf_xdp,
 	.ndo_do_ioctl           = nicvf_ioctl,
+	.ndo_set_rx_mode        = nicvf_set_rx_mode,
 };
 
 static int nicvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -2071,6 +2170,8 @@ static int nicvf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	INIT_WORK(&nic->reset_task, nicvf_reset_task);
 
+	INIT_DELAYED_WORK(&nic->rx_mode_work.work, nicvf_set_rx_mode_task);
+
 	err = register_netdev(netdev);
 	if (err) {
 		dev_err(dev, "Failed to register netdevice\n");
@@ -2109,6 +2210,8 @@ static void nicvf_remove(struct pci_dev *pdev)
 	nic = netdev_priv(netdev);
 	pnetdev = nic->pnicvf->netdev;
 
+	cancel_delayed_work_sync(&nic->rx_mode_work.work);
+
 	/* Check if this Qset is assigned to different VF.
 	 * If yes, clean primary and all secondary Qsets.
 	 */
@@ -2140,12 +2243,17 @@ static struct pci_driver nicvf_driver = {
 static int __init nicvf_init_module(void)
 {
 	pr_info("%s, ver %s\n", DRV_NAME, DRV_VERSION);
-
+	nicvf_rx_mode_wq = alloc_ordered_workqueue("nicvf_generic",
+						   WQ_MEM_RECLAIM);
 	return pci_register_driver(&nicvf_driver);
 }
 
 static void __exit nicvf_cleanup_module(void)
 {
+	if (nicvf_rx_mode_wq) {
+		destroy_workqueue(nicvf_rx_mode_wq);
+		nicvf_rx_mode_wq = NULL;
+	}
 	pci_unregister_driver(&nicvf_driver);
 }
 
-- 
2.14.3

  parent reply	other threads:[~2018-03-30 12:01 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-27 15:07 [PATCH 0/7] net: thunderx: implement DMAC filtering support Vadim Lomovtsev
2018-03-27 15:07 ` [PATCH 1/7] net: thunderx: move filter register related macro into proper place Vadim Lomovtsev
2018-03-27 15:07 ` [PATCH 2/7] net: thunderx: add MAC address filter tracking for LMAC Vadim Lomovtsev
2018-03-27 15:07 ` [PATCH 3/7] net: thunderx: add multicast filter management support Vadim Lomovtsev
2018-03-28 12:29   ` kbuild test robot
2018-03-27 15:07 ` [PATCH 4/7] net: thunderx: add new messages for handle ndo_set_rx_mode callback Vadim Lomovtsev
2018-03-27 15:07 ` [PATCH 5/7] net: thunderx: add XCAST messages handlers for PF Vadim Lomovtsev
2018-03-27 15:07 ` [PATCH 6/7] net: thunderx: add workqueue control structures for handle ndo_set_rx_mode request Vadim Lomovtsev
2018-03-27 15:07 ` [PATCH 7/7] net: thunderx: add ndo_set_rx_mode callback implementation for VF Vadim Lomovtsev
2018-03-27 17:28 ` [PATCH 0/7] net: thunderx: implement DMAC filtering support David Miller
2018-03-28  8:47   ` Vadim Lomovtsev
2018-03-30 11:59 ` [PATCH v2 " Vadim Lomovtsev
2018-03-30 11:59   ` [PATCH v2 1/7] net: thunderx: move filter register related macro into proper place Vadim Lomovtsev
2018-03-30 11:59   ` [PATCH v2 2/7] net: thunderx: add MAC address filter tracking for LMAC Vadim Lomovtsev
2018-03-30 11:59   ` [PATCH v2 3/7] net: thunderx: add multicast filter management support Vadim Lomovtsev
2018-03-30 11:59   ` [PATCH v2 4/7] net: thunderx: add new messages for handle ndo_set_rx_mode callback Vadim Lomovtsev
2018-03-30 11:59   ` [PATCH v2 5/7] net: thunderx: add XCAST messages handlers for PF Vadim Lomovtsev
2018-03-30 11:59   ` [PATCH v2 6/7] net: thunderx: add workqueue control structures for handle ndo_set_rx_mode request Vadim Lomovtsev
2018-03-30 11:59   ` Vadim Lomovtsev [this message]
2018-04-01  2:07   ` [PATCH v2 0/7] net: thunderx: implement DMAC filtering support David Miller
2018-04-02 10:40     ` Vadim Lomovtsev
2019-02-20 11:02 ` [PATCH v3 0/8] nic: thunderx: fix communication races between VF & PF Vadim Lomovtsev
2019-02-20 11:02   ` [PATCH v3 1/8] net: thunderx: correct typo in macro name Vadim Lomovtsev
2019-02-20 11:02   ` [PATCH v3 2/8] net: thunderx: replace global nicvf_rx_mode_wq work queue for all VFs to private for each of them Vadim Lomovtsev
2019-02-20 11:02   ` [PATCH v3 3/8] net: thunderx: make CFG_DONE message to run through generic send-ack sequence Vadim Lomovtsev
2019-02-20 11:02   ` [PATCH v3 5/8] net: thunderx: rework xcast message structure to make it fit into 64 bit Vadim Lomovtsev
2019-02-20 11:02   ` [PATCH v3 6/8] net: thunderx: add mutex to protect mailbox from concurrent calls for same VF Vadim Lomovtsev
2019-02-20 11:02   ` [PATCH v3 4/8] net: thunderx: add nicvf_send_msg_to_pf result check for set_rx_mode_task Vadim Lomovtsev
2019-02-20 11:02   ` [PATCH v3 7/8] net: thunderx: move link state polling function to VF Vadim Lomovtsev
2019-02-20 11:02   ` [PATCH v3 8/8] net: thunderx: remove link change polling code and info from nicpf Vadim Lomovtsev
2019-02-20 11:19   ` [PATCH v3 0/8] nic: thunderx: fix communication races between VF & PF Vadim Lomovtsev
2019-02-22 19:44   ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180330115953.17154-8-Vadim.Lomovtsev@caviumnetworks.com \
    --to=vadim.lomovtsev@caviumnetworks.com \
    --cc=Vadim.Lomovtsev@cavium.com \
    --cc=davem@davemloft.net \
    --cc=dnelson@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rric@kernel.org \
    --cc=sgoutham@cavium.com \
    --cc=sunil.kovvuri@gmail.com \
    --cc=ynorov@caviumnetworks.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).