1616#include "octep_config.h"
1717#include "octep_main.h"
1818#include "octep_ctrl_net.h"
19+ #include "octep_pfvf_mbox.h"
1920
2021#define OCTEP_INTR_POLL_TIME_MSECS 100
2122struct workqueue_struct * octep_wq ;
@@ -159,6 +160,21 @@ static void octep_disable_msix(struct octep_device *oct)
159160 dev_info (& oct -> pdev -> dev , "Disabled MSI-X\n" );
160161}
161162
163+ /**
164+ * octep_mbox_intr_handler() - common handler for pfvf mbox interrupts.
165+ *
166+ * @irq: Interrupt number.
167+ * @data: interrupt data.
168+ *
169+ * this is common handler for pfvf mbox interrupts.
170+ */
171+ static irqreturn_t octep_mbox_intr_handler (int irq , void * data )
172+ {
173+ struct octep_device * oct = data ;
174+
175+ return oct -> hw_ops .mbox_intr_handler (oct );
176+ }
177+
162178/**
163179 * octep_oei_intr_handler() - common handler for output endpoint interrupts.
164180 *
@@ -362,8 +378,12 @@ static int octep_request_irqs(struct octep_device *oct)
362378
363379 snprintf (irq_name , OCTEP_MSIX_NAME_SIZE ,
364380 "%s-%s" , netdev -> name , non_ioq_msix_names [i ]);
365- if (!strncmp (non_ioq_msix_names [i ], "epf_oei_rint" ,
366- strlen ("epf_oei_rint" ))) {
381+ if (!strncmp (non_ioq_msix_names [i ], "epf_mbox_rint" , strlen ("epf_mbox_rint" ))) {
382+ ret = request_irq (msix_entry -> vector ,
383+ octep_mbox_intr_handler , 0 ,
384+ irq_name , oct );
385+ } else if (!strncmp (non_ioq_msix_names [i ], "epf_oei_rint" ,
386+ strlen ("epf_oei_rint" ))) {
367387 ret = request_irq (msix_entry -> vector ,
368388 octep_oei_intr_handler , 0 ,
369389 irq_name , oct );
@@ -1322,6 +1342,7 @@ static void octep_device_cleanup(struct octep_device *oct)
13221342 oct -> mbox [i ] = NULL ;
13231343 }
13241344
1345+ octep_delete_pfvf_mbox (oct );
13251346 octep_ctrl_net_uninit (oct );
13261347 cancel_delayed_work_sync (& oct -> hb_task );
13271348
@@ -1419,6 +1440,12 @@ static int octep_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
14191440 goto err_octep_config ;
14201441 }
14211442
1443+ err = octep_setup_pfvf_mbox (octep_dev );
1444+ if (err ) {
1445+ dev_err (& pdev -> dev , "PF-VF mailbox setup failed\n" );
1446+ goto register_dev_err ;
1447+ }
1448+
14221449 err = octep_ctrl_net_get_info (octep_dev , OCTEP_CTRL_NET_INVALID_VFID ,
14231450 & octep_dev -> conf -> fw_info );
14241451 if (err ) {
@@ -1487,6 +1514,21 @@ static int octep_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
14871514 return err ;
14881515}
14891516
1517+ static int octep_sriov_disable (struct octep_device * oct )
1518+ {
1519+ struct pci_dev * pdev = oct -> pdev ;
1520+
1521+ if (pci_vfs_assigned (oct -> pdev )) {
1522+ dev_warn (& pdev -> dev , "Can't disable SRIOV while VFs are assigned\n" );
1523+ return - EPERM ;
1524+ }
1525+
1526+ pci_disable_sriov (pdev );
1527+ CFG_GET_ACTIVE_VFS (oct -> conf ) = 0 ;
1528+
1529+ return 0 ;
1530+ }
1531+
14901532/**
14911533 * octep_remove() - Remove Octeon PCI device from driver control.
14921534 *
@@ -1504,6 +1546,7 @@ static void octep_remove(struct pci_dev *pdev)
15041546 return ;
15051547
15061548 netdev = oct -> netdev ;
1549+ octep_sriov_disable (oct );
15071550 if (netdev -> reg_state == NETREG_REGISTERED )
15081551 unregister_netdev (netdev );
15091552
@@ -1514,11 +1557,47 @@ static void octep_remove(struct pci_dev *pdev)
15141557 pci_disable_device (pdev );
15151558}
15161559
1560+ static int octep_sriov_enable (struct octep_device * oct , int num_vfs )
1561+ {
1562+ struct pci_dev * pdev = oct -> pdev ;
1563+ int err ;
1564+
1565+ CFG_GET_ACTIVE_VFS (oct -> conf ) = num_vfs ;
1566+ err = pci_enable_sriov (pdev , num_vfs );
1567+ if (err ) {
1568+ dev_warn (& pdev -> dev , "Failed to enable SRIOV err=%d\n" , err );
1569+ CFG_GET_ACTIVE_VFS (oct -> conf ) = 0 ;
1570+ return err ;
1571+ }
1572+
1573+ return num_vfs ;
1574+ }
1575+
1576+ static int octep_sriov_configure (struct pci_dev * pdev , int num_vfs )
1577+ {
1578+ struct octep_device * oct = pci_get_drvdata (pdev );
1579+ int max_nvfs ;
1580+
1581+ if (num_vfs == 0 )
1582+ return octep_sriov_disable (oct );
1583+
1584+ max_nvfs = CFG_GET_MAX_VFS (oct -> conf );
1585+
1586+ if (num_vfs > max_nvfs ) {
1587+ dev_err (& pdev -> dev , "Invalid VF count Max supported VFs = %d\n" ,
1588+ max_nvfs );
1589+ return - EINVAL ;
1590+ }
1591+
1592+ return octep_sriov_enable (oct , num_vfs );
1593+ }
1594+
15171595static struct pci_driver octep_driver = {
15181596 .name = OCTEP_DRV_NAME ,
15191597 .id_table = octep_pci_id_tbl ,
15201598 .probe = octep_probe ,
15211599 .remove = octep_remove ,
1600+ .sriov_configure = octep_sriov_configure ,
15221601};
15231602
15241603/**
0 commit comments