Skip to content

Commit 877253d

Browse files
Mengyuan Loukuba-moo
authored andcommitted
net: ngbe: add sriov function support
Add sriov_configure for driver ops. Add mailbox handler wx_msg_task for ngbe in the interrupt handler. Add the notification flow when the vfs exist. Signed-off-by: Mengyuan Lou <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 359e41f commit 877253d

File tree

6 files changed

+127
-9
lines changed

6 files changed

+127
-9
lines changed

drivers/net/ethernet/wangxun/libwx/wx_sriov.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,3 +834,34 @@ void wx_msg_task(struct wx *wx)
834834
}
835835
}
836836
EXPORT_SYMBOL(wx_msg_task);
837+
838+
void wx_disable_vf_rx_tx(struct wx *wx)
839+
{
840+
wr32(wx, WX_TDM_VFTE_CLR(0), U32_MAX);
841+
wr32(wx, WX_RDM_VFRE_CLR(0), U32_MAX);
842+
if (wx->mac.type != wx_mac_em) {
843+
wr32(wx, WX_TDM_VFTE_CLR(1), U32_MAX);
844+
wr32(wx, WX_RDM_VFRE_CLR(1), U32_MAX);
845+
}
846+
}
847+
EXPORT_SYMBOL(wx_disable_vf_rx_tx);
848+
849+
void wx_ping_all_vfs_with_link_status(struct wx *wx, bool link_up)
850+
{
851+
u32 msgbuf[2] = {0, 0};
852+
u16 i;
853+
854+
if (!wx->num_vfs)
855+
return;
856+
msgbuf[0] = WX_PF_NOFITY_VF_LINK_STATUS | WX_PF_CONTROL_MSG;
857+
if (link_up)
858+
msgbuf[1] = FIELD_PREP(GENMASK(31, 1), wx->speed) | link_up;
859+
if (wx->notify_down)
860+
msgbuf[1] |= WX_PF_NOFITY_VF_NET_NOT_RUNNING;
861+
for (i = 0; i < wx->num_vfs; i++) {
862+
if (wx->vfinfo[i].clear_to_send)
863+
msgbuf[0] |= WX_VT_MSGTYPE_CTS;
864+
wx_write_mbx_pf(wx, msgbuf, 2, i);
865+
}
866+
}
867+
EXPORT_SYMBOL(wx_ping_all_vfs_with_link_status);

drivers/net/ethernet/wangxun/libwx/wx_sriov.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
void wx_disable_sriov(struct wx *wx);
1212
int wx_pci_sriov_configure(struct pci_dev *pdev, int num_vfs);
1313
void wx_msg_task(struct wx *wx);
14+
void wx_disable_vf_rx_tx(struct wx *wx);
15+
void wx_ping_all_vfs_with_link_status(struct wx *wx, bool link_up);
1416

1517
#endif /* _WX_SRIOV_H_ */

drivers/net/ethernet/wangxun/libwx/wx_type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
/************************* Port Registers ************************************/
9393
/* port cfg Registers */
9494
#define WX_CFG_PORT_CTL 0x14400
95+
#define WX_CFG_PORT_CTL_PFRSTD BIT(14)
9596
#define WX_CFG_PORT_CTL_DRV_LOAD BIT(3)
9697
#define WX_CFG_PORT_CTL_QINQ BIT(2)
9798
#define WX_CFG_PORT_CTL_D_VLAN BIT(0) /* double vlan*/
@@ -1231,6 +1232,7 @@ struct wx {
12311232
u8 swfw_index;
12321233

12331234
/* PHY stuff */
1235+
bool notify_down;
12341236
unsigned int link;
12351237
int speed;
12361238
int duplex;

drivers/net/ethernet/wangxun/ngbe/ngbe_main.c

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "../libwx/wx_hw.h"
1616
#include "../libwx/wx_lib.h"
1717
#include "../libwx/wx_ptp.h"
18+
#include "../libwx/wx_mbx.h"
19+
#include "../libwx/wx_sriov.h"
1820
#include "ngbe_type.h"
1921
#include "ngbe_mdio.h"
2022
#include "ngbe_hw.h"
@@ -129,6 +131,10 @@ static int ngbe_sw_init(struct wx *wx)
129131
wx->tx_work_limit = NGBE_DEFAULT_TX_WORK;
130132
wx->rx_work_limit = NGBE_DEFAULT_RX_WORK;
131133

134+
wx->mbx.size = WX_VXMAILBOX_SIZE;
135+
wx->setup_tc = ngbe_setup_tc;
136+
set_bit(0, &wx->fwd_bitmask);
137+
132138
return 0;
133139
}
134140

@@ -200,12 +206,10 @@ static irqreturn_t ngbe_intr(int __always_unused irq, void *data)
200206
return IRQ_HANDLED;
201207
}
202208

203-
static irqreturn_t ngbe_msix_other(int __always_unused irq, void *data)
209+
static irqreturn_t __ngbe_msix_misc(struct wx *wx, u32 eicr)
204210
{
205-
struct wx *wx = data;
206-
u32 eicr;
207-
208-
eicr = wx_misc_isb(wx, WX_ISB_MISC);
211+
if (eicr & NGBE_PX_MISC_IC_VF_MBOX)
212+
wx_msg_task(wx);
209213

210214
if (unlikely(eicr & NGBE_PX_MISC_IC_TIMESYNC))
211215
wx_ptp_check_pps_event(wx);
@@ -217,6 +221,35 @@ static irqreturn_t ngbe_msix_other(int __always_unused irq, void *data)
217221
return IRQ_HANDLED;
218222
}
219223

224+
static irqreturn_t ngbe_msix_misc(int __always_unused irq, void *data)
225+
{
226+
struct wx *wx = data;
227+
u32 eicr;
228+
229+
eicr = wx_misc_isb(wx, WX_ISB_MISC);
230+
231+
return __ngbe_msix_misc(wx, eicr);
232+
}
233+
234+
static irqreturn_t ngbe_misc_and_queue(int __always_unused irq, void *data)
235+
{
236+
struct wx_q_vector *q_vector;
237+
struct wx *wx = data;
238+
u32 eicr;
239+
240+
eicr = wx_misc_isb(wx, WX_ISB_MISC);
241+
if (!eicr) {
242+
/* queue */
243+
q_vector = wx->q_vector[0];
244+
napi_schedule_irqoff(&q_vector->napi);
245+
if (netif_running(wx->netdev))
246+
ngbe_irq_enable(wx, true);
247+
return IRQ_HANDLED;
248+
}
249+
250+
return __ngbe_msix_misc(wx, eicr);
251+
}
252+
220253
/**
221254
* ngbe_request_msix_irqs - Initialize MSI-X interrupts
222255
* @wx: board private structure
@@ -249,8 +282,16 @@ static int ngbe_request_msix_irqs(struct wx *wx)
249282
}
250283
}
251284

252-
err = request_irq(wx->msix_entry->vector,
253-
ngbe_msix_other, 0, netdev->name, wx);
285+
/* Due to hardware design, when num_vfs < 7, pf can use 0 for misc and 1
286+
* for queue. But when num_vfs == 7, vector[1] is assigned to vf6.
287+
* Misc and queue should reuse interrupt vector[0].
288+
*/
289+
if (wx->num_vfs == 7)
290+
err = request_irq(wx->msix_entry->vector,
291+
ngbe_misc_and_queue, 0, netdev->name, wx);
292+
else
293+
err = request_irq(wx->msix_entry->vector,
294+
ngbe_msix_misc, 0, netdev->name, wx);
254295

255296
if (err) {
256297
wx_err(wx, "request_irq for msix_other failed: %d\n", err);
@@ -302,6 +343,22 @@ static void ngbe_disable_device(struct wx *wx)
302343
struct net_device *netdev = wx->netdev;
303344
u32 i;
304345

346+
if (wx->num_vfs) {
347+
/* Clear EITR Select mapping */
348+
wr32(wx, WX_PX_ITRSEL, 0);
349+
350+
/* Mark all the VFs as inactive */
351+
for (i = 0; i < wx->num_vfs; i++)
352+
wx->vfinfo[i].clear_to_send = 0;
353+
wx->notify_down = true;
354+
/* ping all the active vfs to let them know we are going down */
355+
wx_ping_all_vfs_with_link_status(wx, false);
356+
wx->notify_down = false;
357+
358+
/* Disable all VFTE/VFRE TX/RX */
359+
wx_disable_vf_rx_tx(wx);
360+
}
361+
305362
/* disable all enabled rx queues */
306363
for (i = 0; i < wx->num_rx_queues; i++)
307364
/* this call also flushes the previous write */
@@ -324,12 +381,19 @@ static void ngbe_disable_device(struct wx *wx)
324381
wx_update_stats(wx);
325382
}
326383

384+
static void ngbe_reset(struct wx *wx)
385+
{
386+
wx_flush_sw_mac_table(wx);
387+
wx_mac_set_default_filter(wx, wx->mac.addr);
388+
if (test_bit(WX_STATE_PTP_RUNNING, wx->state))
389+
wx_ptp_reset(wx);
390+
}
391+
327392
void ngbe_down(struct wx *wx)
328393
{
329394
phylink_stop(wx->phylink);
330395
ngbe_disable_device(wx);
331-
if (test_bit(WX_STATE_PTP_RUNNING, wx->state))
332-
wx_ptp_reset(wx);
396+
ngbe_reset(wx);
333397
wx_clean_all_tx_rings(wx);
334398
wx_clean_all_rx_rings(wx);
335399
}
@@ -352,6 +416,11 @@ void ngbe_up(struct wx *wx)
352416
ngbe_sfp_modules_txrx_powerctl(wx, true);
353417

354418
phylink_start(wx->phylink);
419+
/* Set PF Reset Done bit so PF/VF Mail Ops can work */
420+
wr32m(wx, WX_CFG_PORT_CTL,
421+
WX_CFG_PORT_CTL_PFRSTD, WX_CFG_PORT_CTL_PFRSTD);
422+
if (wx->num_vfs)
423+
wx_ping_all_vfs_with_link_status(wx, false);
355424
}
356425

357426
/**
@@ -596,6 +665,10 @@ static int ngbe_probe(struct pci_dev *pdev,
596665
goto err_pci_release_regions;
597666
}
598667

668+
/* The emerald supports up to 8 VFs per pf, but physical
669+
* function also need one pool for basic networking.
670+
*/
671+
pci_sriov_set_totalvfs(pdev, NGBE_MAX_VFS_DRV_LIMIT);
599672
wx->driver_name = ngbe_driver_name;
600673
ngbe_set_ethtool_ops(netdev);
601674
netdev->netdev_ops = &ngbe_netdev_ops;
@@ -743,6 +816,7 @@ static void ngbe_remove(struct pci_dev *pdev)
743816
struct net_device *netdev;
744817

745818
netdev = wx->netdev;
819+
wx_disable_sriov(wx);
746820
unregister_netdev(netdev);
747821
phylink_destroy(wx->phylink);
748822
pci_release_selected_regions(pdev,
@@ -802,6 +876,7 @@ static struct pci_driver ngbe_driver = {
802876
.suspend = ngbe_suspend,
803877
.resume = ngbe_resume,
804878
.shutdown = ngbe_shutdown,
879+
.sriov_configure = wx_pci_sriov_configure,
805880
};
806881

807882
module_pci_driver(ngbe_driver);

drivers/net/ethernet/wangxun/ngbe/ngbe_mdio.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../libwx/wx_type.h"
1010
#include "../libwx/wx_ptp.h"
1111
#include "../libwx/wx_hw.h"
12+
#include "../libwx/wx_sriov.h"
1213
#include "ngbe_type.h"
1314
#include "ngbe_mdio.h"
1415

@@ -70,6 +71,8 @@ static void ngbe_mac_link_down(struct phylink_config *config,
7071
wx->speed = SPEED_UNKNOWN;
7172
if (test_bit(WX_STATE_PTP_RUNNING, wx->state))
7273
wx_ptp_reset_cyclecounter(wx);
74+
/* ping all the active vfs to let them know we are going down */
75+
wx_ping_all_vfs_with_link_status(wx, false);
7376
}
7477

7578
static void ngbe_mac_link_up(struct phylink_config *config,
@@ -114,6 +117,8 @@ static void ngbe_mac_link_up(struct phylink_config *config,
114117
wx->last_rx_ptp_check = jiffies;
115118
if (test_bit(WX_STATE_PTP_RUNNING, wx->state))
116119
wx_ptp_reset_cyclecounter(wx);
120+
/* ping all the active vfs to let them know we are going up */
121+
wx_ping_all_vfs_with_link_status(wx, true);
117122
}
118123

119124
static const struct phylink_mac_ops ngbe_mac_ops = {

drivers/net/ethernet/wangxun/ngbe/ngbe_type.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@
7373
#define NGBE_PX_MISC_IEN_TIMESYNC BIT(11)
7474
#define NGBE_PX_MISC_IEN_ETH_LK BIT(18)
7575
#define NGBE_PX_MISC_IEN_INT_ERR BIT(20)
76+
#define NGBE_PX_MISC_IC_VF_MBOX BIT(23)
7677
#define NGBE_PX_MISC_IEN_GPIO BIT(26)
7778
#define NGBE_PX_MISC_IEN_MASK ( \
7879
NGBE_PX_MISC_IEN_DEV_RST | \
7980
NGBE_PX_MISC_IEN_TIMESYNC | \
8081
NGBE_PX_MISC_IEN_ETH_LK | \
8182
NGBE_PX_MISC_IEN_INT_ERR | \
83+
NGBE_PX_MISC_IC_VF_MBOX | \
8284
NGBE_PX_MISC_IEN_GPIO)
8385

8486
/* Extended Interrupt Cause Read */
@@ -134,6 +136,7 @@
134136
#define NGBE_MAX_RXD 8192
135137
#define NGBE_MIN_RXD 128
136138

139+
#define NGBE_MAX_VFS_DRV_LIMIT 7
137140
extern char ngbe_driver_name[];
138141

139142
void ngbe_down(struct wx *wx);

0 commit comments

Comments
 (0)