]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: txgbevf: init interrupts and request irqs
authorMengyuan Lou <mengyuanlou@net-swift.com>
Fri, 4 Jul 2025 09:49:17 +0000 (17:49 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 10 Jul 2025 01:39:13 +0000 (18:39 -0700)
Add irq alloc flow functions for vf.
Alloc pcie msix irqs for drivers and request_irq for tx/rx rings
and misc other events.
If the application is successful, config vertors for interrupts.
Enable interrupts mask in wxvf_irq_enable.

Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>
Link: https://patch.msgid.link/20250704094923.652-7-mengyuanlou@net-swift.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/wangxun/libwx/wx_hw.c
drivers/net/ethernet/wangxun/libwx/wx_lib.c
drivers/net/ethernet/wangxun/libwx/wx_type.h
drivers/net/ethernet/wangxun/libwx/wx_vf_common.c
drivers/net/ethernet/wangxun/txgbevf/txgbevf_main.c
drivers/net/ethernet/wangxun/txgbevf/txgbevf_type.h

index 6e830436a19be58ee7140649af38f7ddffb92f43..58e9d6a388023a2c5bc752656753fa5067bb2d9c 100644 (file)
@@ -11,6 +11,7 @@
 #include "wx_type.h"
 #include "wx_lib.h"
 #include "wx_sriov.h"
+#include "wx_vf.h"
 #include "wx_hw.h"
 
 static int wx_phy_read_reg_mdi(struct mii_bus *bus, int phy_addr, int devnum, int regnum)
@@ -124,6 +125,11 @@ void wx_intr_enable(struct wx *wx, u64 qmask)
 {
        u32 mask;
 
+       if (wx->pdev->is_virtfn) {
+               wr32(wx, WX_VXIMC, qmask);
+               return;
+       }
+
        mask = (qmask & U32_MAX);
        if (mask)
                wr32(wx, WX_PX_IMC(0), mask);
index 55e252789db35ef9a6df98f3715eb9bf178d42aa..0e76be1c815436a0de8cfc5375d145db74ec69cc 100644 (file)
@@ -1819,7 +1819,7 @@ static int wx_set_interrupt_capability(struct wx *wx)
 
        /* We will try to get MSI-X interrupts first */
        ret = wx_acquire_msix_vectors(wx);
-       if (ret == 0 || (ret == -ENOMEM))
+       if (ret == 0 || (ret == -ENOMEM) || pdev->is_virtfn)
                return ret;
 
        /* Disable VMDq support */
@@ -2170,7 +2170,12 @@ int wx_init_interrupt_scheme(struct wx *wx)
        int ret;
 
        /* Number of supported queues */
-       wx_set_num_queues(wx);
+       if (wx->pdev->is_virtfn) {
+               if (wx->set_num_queues)
+                       wx->set_num_queues(wx);
+       } else {
+               wx_set_num_queues(wx);
+       }
 
        /* Set interrupt mode */
        ret = wx_set_interrupt_capability(wx);
index 9e5b0d1fcb21590cec289960cb6a42b75813b091..58e9988388a7b8e705b545419b324bfcfe651cdd 100644 (file)
@@ -1324,6 +1324,7 @@ struct wx {
        int (*setup_tc)(struct net_device *netdev, u8 tc);
        void (*do_reset)(struct net_device *netdev);
        int (*ptp_setup_sdp)(struct wx *wx);
+       void (*set_num_queues)(struct wx *wx);
 
        bool pps_enabled;
        u64 pps_width;
index ed5daeec598af7d4eaf53b69227e868562292204..7442b195425f314efb985ef98a9706766db3849f 100644 (file)
@@ -17,6 +17,7 @@ int wxvf_suspend(struct device *dev_d)
        struct wx *wx = pci_get_drvdata(pdev);
 
        netif_device_detach(wx->netdev);
+       wx_clear_interrupt_scheme(wx);
        pci_disable_device(pdev);
 
        return 0;
@@ -35,6 +36,7 @@ int wxvf_resume(struct device *dev_d)
        struct wx *wx = pci_get_drvdata(pdev);
 
        pci_set_master(pdev);
+       wx_init_interrupt_scheme(wx);
        netif_device_attach(wx->netdev);
 
        return 0;
@@ -51,6 +53,7 @@ void wxvf_remove(struct pci_dev *pdev)
        kfree(wx->vfinfo);
        kfree(wx->rss_key);
        kfree(wx->mac_table);
+       wx_clear_interrupt_scheme(wx);
        pci_release_selected_regions(pdev,
                                     pci_select_bars(pdev, IORESOURCE_MEM));
        pci_disable_device(pdev);
@@ -93,9 +96,8 @@ int wx_request_msix_irqs_vf(struct wx *wx)
                }
        }
 
-       err = request_threaded_irq(wx->msix_entry->vector, NULL,
-                                  wx_msix_misc_vf, IRQF_ONESHOT,
-                                  netdev->name, wx);
+       err = request_threaded_irq(wx->msix_entry->vector, wx_msix_misc_vf,
+                                  NULL, IRQF_ONESHOT, netdev->name, wx);
        if (err) {
                wx_err(wx, "request_irq for msix_other failed: %d\n", err);
                goto free_queue_irqs;
@@ -241,9 +243,35 @@ int wx_set_mac_vf(struct net_device *netdev, void *p)
 }
 EXPORT_SYMBOL(wx_set_mac_vf);
 
+static void wxvf_irq_enable(struct wx *wx)
+{
+       wr32(wx, WX_VXIMC, wx->eims_enable_mask);
+}
+
+static void wxvf_up_complete(struct wx *wx)
+{
+       wx_configure_msix_vf(wx);
+
+       /* clear any pending interrupts, may auto mask */
+       wr32(wx, WX_VXICR, U32_MAX);
+       wxvf_irq_enable(wx);
+}
+
 int wxvf_open(struct net_device *netdev)
 {
+       struct wx *wx = netdev_priv(netdev);
+       int err;
+
+       err = wx_request_msix_irqs_vf(wx);
+       if (err)
+               goto err_reset;
+
+       wxvf_up_complete(wx);
+
        return 0;
+err_reset:
+       wx_reset_vf(wx);
+       return err;
 }
 EXPORT_SYMBOL(wxvf_open);
 
@@ -251,8 +279,13 @@ static void wxvf_down(struct wx *wx)
 {
        struct net_device *netdev = wx->netdev;
 
+       netif_tx_stop_all_queues(netdev);
        netif_tx_disable(netdev);
+       wx_napi_disable_all(wx);
        wx_reset_vf(wx);
+
+       wx_clean_all_tx_rings(wx);
+       wx_clean_all_rx_rings(wx);
 }
 
 int wxvf_close(struct net_device *netdev)
@@ -260,6 +293,7 @@ int wxvf_close(struct net_device *netdev)
        struct wx *wx = netdev_priv(netdev);
 
        wxvf_down(wx);
+       wx_free_irq(wx);
 
        return 0;
 }
index 9918d5b2ee574c45f0b876f863a4aa46c9857faa..a61e4a0781cff3e94cd9499a809cfe0defeaeda9 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "../libwx/wx_type.h"
 #include "../libwx/wx_hw.h"
+#include "../libwx/wx_lib.h"
 #include "../libwx/wx_mbx.h"
 #include "../libwx/wx_vf.h"
 #include "../libwx/wx_vf_common.h"
@@ -43,6 +44,39 @@ static const struct net_device_ops txgbevf_netdev_ops = {
        .ndo_set_mac_address    = wx_set_mac_vf,
 };
 
+static void txgbevf_set_num_queues(struct wx *wx)
+{
+       u32 def_q = 0, num_tcs = 0;
+       u16 rss, queue;
+       int ret = 0;
+
+       /* Start with base case */
+       wx->num_rx_queues = 1;
+       wx->num_tx_queues = 1;
+
+       spin_lock_bh(&wx->mbx.mbx_lock);
+       /* fetch queue configuration from the PF */
+       ret = wx_get_queues_vf(wx, &num_tcs, &def_q);
+       spin_unlock_bh(&wx->mbx.mbx_lock);
+
+       if (ret)
+               return;
+
+       /* we need as many queues as traffic classes */
+       if (num_tcs > 1) {
+               wx->num_rx_queues = num_tcs;
+       } else {
+               rss = min_t(u16, num_online_cpus(), TXGBEVF_MAX_RSS_NUM);
+               queue = min_t(u16, wx->mac.max_rx_queues, wx->mac.max_tx_queues);
+               rss = min_t(u16, queue, rss);
+
+               if (wx->vfinfo->vf_api >= wx_mbox_api_13) {
+                       wx->num_rx_queues = rss;
+                       wx->num_tx_queues = rss;
+               }
+       }
+}
+
 static void txgbevf_init_type_code(struct wx *wx)
 {
        switch (wx->device_id) {
@@ -80,6 +114,8 @@ static int txgbevf_sw_init(struct wx *wx)
        if (err)
                goto err_init_mbx_params;
 
+       /* max q_vectors */
+       wx->mac.max_msix_vectors = TXGBEVF_MAX_MSIX_VECTORS;
        /* Initialize the device type */
        txgbevf_init_type_code(wx);
        /* lock to protect mailbox accesses */
@@ -116,6 +152,8 @@ static int txgbevf_sw_init(struct wx *wx)
        wx->tx_work_limit = TXGBEVF_DEFAULT_TX_WORK;
        wx->rx_work_limit = TXGBEVF_DEFAULT_RX_WORK;
 
+       wx->set_num_queues = txgbevf_set_num_queues;
+
        return 0;
 err_reset_hw:
        kfree(wx->vfinfo);
@@ -211,6 +249,10 @@ static int txgbevf_probe(struct pci_dev *pdev,
        eth_hw_addr_set(netdev, wx->mac.perm_addr);
        ether_addr_copy(netdev->perm_addr, wx->mac.addr);
 
+       err = wx_init_interrupt_scheme(wx);
+       if (err)
+               goto err_free_sw_init;
+
        err = register_netdev(netdev);
        if (err)
                goto err_register;
@@ -220,6 +262,8 @@ static int txgbevf_probe(struct pci_dev *pdev,
        return 0;
 
 err_register:
+       wx_clear_interrupt_scheme(wx);
+err_free_sw_init:
        kfree(wx->vfinfo);
        kfree(wx->rss_key);
        kfree(wx->mac_table);
index 8f4f08ce06c0b1821e790d9ebbc58b35386392f2..1364d2b58bb0363681bbf95977c14c35115d5c4e 100644 (file)
@@ -14,6 +14,8 @@
 #define TXGBEVF_DEV_ID_AML503F                 0x503f
 #define TXGBEVF_DEV_ID_AML513F                 0x513f
 
+#define TXGBEVF_MAX_MSIX_VECTORS               2
+#define TXGBEVF_MAX_RSS_NUM                    4
 #define TXGBEVF_MAX_RX_QUEUES                  4
 #define TXGBEVF_MAX_TX_QUEUES                  4
 #define TXGBEVF_DEFAULT_TXD                    128