1 // SPDX-License-Identifier: GPL-2.0-only
2 /****************************************************************************
3 * Driver for Solarflare network controllers and boards
4 * Copyright 2015 Solarflare Communications Inc.
6 #include <linux/etherdevice.h>
8 #include <linux/module.h>
9 #include "net_driver.h"
10 #include "ef10_sriov.h"
13 #include "mcdi_pcol.h"
15 static int efx_ef10_evb_port_assign(struct efx_nic
*efx
, unsigned int port_id
,
18 MCDI_DECLARE_BUF(inbuf
, MC_CMD_EVB_PORT_ASSIGN_IN_LEN
);
19 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
21 MCDI_SET_DWORD(inbuf
, EVB_PORT_ASSIGN_IN_PORT_ID
, port_id
);
22 MCDI_POPULATE_DWORD_2(inbuf
, EVB_PORT_ASSIGN_IN_FUNCTION
,
23 EVB_PORT_ASSIGN_IN_PF
, nic_data
->pf_index
,
24 EVB_PORT_ASSIGN_IN_VF
, vf_fn
);
26 return efx_mcdi_rpc(efx
, MC_CMD_EVB_PORT_ASSIGN
, inbuf
, sizeof(inbuf
),
30 static int efx_ef10_vswitch_alloc(struct efx_nic
*efx
, unsigned int port_id
,
31 unsigned int vswitch_type
)
33 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VSWITCH_ALLOC_IN_LEN
);
36 MCDI_SET_DWORD(inbuf
, VSWITCH_ALLOC_IN_UPSTREAM_PORT_ID
, port_id
);
37 MCDI_SET_DWORD(inbuf
, VSWITCH_ALLOC_IN_TYPE
, vswitch_type
);
38 MCDI_SET_DWORD(inbuf
, VSWITCH_ALLOC_IN_NUM_VLAN_TAGS
, 2);
39 MCDI_POPULATE_DWORD_1(inbuf
, VSWITCH_ALLOC_IN_FLAGS
,
40 VSWITCH_ALLOC_IN_FLAG_AUTO_PORT
, 0);
42 /* Quietly try to allocate 2 VLAN tags */
43 rc
= efx_mcdi_rpc_quiet(efx
, MC_CMD_VSWITCH_ALLOC
, inbuf
, sizeof(inbuf
),
46 /* If 2 VLAN tags is too many, revert to trying with 1 VLAN tags */
48 MCDI_SET_DWORD(inbuf
, VSWITCH_ALLOC_IN_NUM_VLAN_TAGS
, 1);
49 rc
= efx_mcdi_rpc(efx
, MC_CMD_VSWITCH_ALLOC
, inbuf
,
50 sizeof(inbuf
), NULL
, 0, NULL
);
52 efx_mcdi_display_error(efx
, MC_CMD_VSWITCH_ALLOC
,
53 MC_CMD_VSWITCH_ALLOC_IN_LEN
,
59 static int efx_ef10_vswitch_free(struct efx_nic
*efx
, unsigned int port_id
)
61 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VSWITCH_FREE_IN_LEN
);
63 MCDI_SET_DWORD(inbuf
, VSWITCH_FREE_IN_UPSTREAM_PORT_ID
, port_id
);
65 return efx_mcdi_rpc(efx
, MC_CMD_VSWITCH_FREE
, inbuf
, sizeof(inbuf
),
69 static int efx_ef10_vport_alloc(struct efx_nic
*efx
,
70 unsigned int port_id_in
,
71 unsigned int vport_type
,
73 unsigned int *port_id_out
)
75 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VPORT_ALLOC_IN_LEN
);
76 MCDI_DECLARE_BUF(outbuf
, MC_CMD_VPORT_ALLOC_OUT_LEN
);
80 EFX_WARN_ON_PARANOID(!port_id_out
);
82 MCDI_SET_DWORD(inbuf
, VPORT_ALLOC_IN_UPSTREAM_PORT_ID
, port_id_in
);
83 MCDI_SET_DWORD(inbuf
, VPORT_ALLOC_IN_TYPE
, vport_type
);
84 MCDI_SET_DWORD(inbuf
, VPORT_ALLOC_IN_NUM_VLAN_TAGS
,
85 (vlan
!= EFX_EF10_NO_VLAN
));
86 MCDI_POPULATE_DWORD_1(inbuf
, VPORT_ALLOC_IN_FLAGS
,
87 VPORT_ALLOC_IN_FLAG_AUTO_PORT
, 0);
88 if (vlan
!= EFX_EF10_NO_VLAN
)
89 MCDI_POPULATE_DWORD_1(inbuf
, VPORT_ALLOC_IN_VLAN_TAGS
,
90 VPORT_ALLOC_IN_VLAN_TAG_0
, vlan
);
92 rc
= efx_mcdi_rpc(efx
, MC_CMD_VPORT_ALLOC
, inbuf
, sizeof(inbuf
),
93 outbuf
, sizeof(outbuf
), &outlen
);
96 if (outlen
< MC_CMD_VPORT_ALLOC_OUT_LEN
)
99 *port_id_out
= MCDI_DWORD(outbuf
, VPORT_ALLOC_OUT_VPORT_ID
);
103 static int efx_ef10_vport_free(struct efx_nic
*efx
, unsigned int port_id
)
105 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VPORT_FREE_IN_LEN
);
107 MCDI_SET_DWORD(inbuf
, VPORT_FREE_IN_VPORT_ID
, port_id
);
109 return efx_mcdi_rpc(efx
, MC_CMD_VPORT_FREE
, inbuf
, sizeof(inbuf
),
113 static void efx_ef10_sriov_free_vf_vports(struct efx_nic
*efx
)
115 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
121 for (i
= 0; i
< efx
->vf_count
; i
++) {
122 struct ef10_vf
*vf
= nic_data
->vf
+ i
;
124 /* If VF is assigned, do not free the vport */
126 vf
->pci_dev
->dev_flags
& PCI_DEV_FLAGS_ASSIGNED
)
129 if (vf
->vport_assigned
) {
130 efx_ef10_evb_port_assign(efx
, EVB_PORT_ID_NULL
, i
);
131 vf
->vport_assigned
= 0;
134 if (!is_zero_ether_addr(vf
->mac
)) {
135 efx_ef10_vport_del_mac(efx
, vf
->vport_id
, vf
->mac
);
136 eth_zero_addr(vf
->mac
);
140 efx_ef10_vport_free(efx
, vf
->vport_id
);
148 static void efx_ef10_sriov_free_vf_vswitching(struct efx_nic
*efx
)
150 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
152 efx_ef10_sriov_free_vf_vports(efx
);
157 static int efx_ef10_sriov_assign_vf_vport(struct efx_nic
*efx
,
160 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
161 struct ef10_vf
*vf
= nic_data
->vf
+ vf_i
;
164 if (WARN_ON_ONCE(!nic_data
->vf
))
167 rc
= efx_ef10_vport_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
168 MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL
,
169 vf
->vlan
, &vf
->vport_id
);
173 rc
= efx_ef10_vport_add_mac(efx
, vf
->vport_id
, vf
->mac
);
175 eth_zero_addr(vf
->mac
);
179 rc
= efx_ef10_evb_port_assign(efx
, vf
->vport_id
, vf_i
);
183 vf
->vport_assigned
= 1;
187 static int efx_ef10_sriov_alloc_vf_vswitching(struct efx_nic
*efx
)
189 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
193 nic_data
->vf
= kcalloc(efx
->vf_count
, sizeof(struct ef10_vf
),
198 for (i
= 0; i
< efx
->vf_count
; i
++) {
199 eth_random_addr(nic_data
->vf
[i
].mac
);
200 nic_data
->vf
[i
].efx
= NULL
;
201 nic_data
->vf
[i
].vlan
= EFX_EF10_NO_VLAN
;
203 rc
= efx_ef10_sriov_assign_vf_vport(efx
, i
);
210 efx_ef10_sriov_free_vf_vports(efx
);
216 static int efx_ef10_sriov_restore_vf_vswitching(struct efx_nic
*efx
)
221 for (i
= 0; i
< efx
->vf_count
; i
++) {
222 rc
= efx_ef10_sriov_assign_vf_vport(efx
, i
);
229 efx_ef10_sriov_free_vf_vswitching(efx
);
233 static int efx_ef10_vadaptor_alloc_set_features(struct efx_nic
*efx
)
238 rc
= efx_ef10_vadaptor_alloc(efx
, efx
->vport_id
);
240 goto fail_vadaptor_alloc
;
242 rc
= efx_ef10_vadaptor_query(efx
, efx
->vport_id
,
243 &port_flags
, NULL
, NULL
);
245 goto fail_vadaptor_query
;
248 (1 << MC_CMD_VPORT_ALLOC_IN_FLAG_VLAN_RESTRICT_LBN
))
249 efx
->fixed_features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
251 efx
->fixed_features
&= ~NETIF_F_HW_VLAN_CTAG_FILTER
;
256 efx_ef10_vadaptor_free(efx
, EVB_PORT_ID_ASSIGNED
);
261 /* On top of the default firmware vswitch setup, create a VEB vswitch and
262 * expansion vport for use by this function.
264 int efx_ef10_vswitching_probe_pf(struct efx_nic
*efx
)
266 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
267 struct net_device
*net_dev
= efx
->net_dev
;
270 if (pci_sriov_get_totalvfs(efx
->pci_dev
) <= 0) {
271 /* vswitch not needed as we have no VFs */
272 efx_ef10_vadaptor_alloc_set_features(efx
);
276 rc
= efx_ef10_vswitch_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
277 MC_CMD_VSWITCH_ALLOC_IN_VSWITCH_TYPE_VEB
);
281 rc
= efx_ef10_vport_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
282 MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL
,
283 EFX_EF10_NO_VLAN
, &efx
->vport_id
);
287 rc
= efx_ef10_vport_add_mac(efx
, efx
->vport_id
, net_dev
->dev_addr
);
290 ether_addr_copy(nic_data
->vport_mac
, net_dev
->dev_addr
);
292 rc
= efx_ef10_vadaptor_alloc_set_features(efx
);
298 efx_ef10_vport_del_mac(efx
, efx
->vport_id
, nic_data
->vport_mac
);
299 eth_zero_addr(nic_data
->vport_mac
);
301 efx_ef10_vport_free(efx
, efx
->vport_id
);
302 efx
->vport_id
= EVB_PORT_ID_ASSIGNED
;
304 efx_ef10_vswitch_free(efx
, EVB_PORT_ID_ASSIGNED
);
309 int efx_ef10_vswitching_probe_vf(struct efx_nic
*efx
)
311 return efx_ef10_vadaptor_alloc_set_features(efx
);
314 int efx_ef10_vswitching_restore_pf(struct efx_nic
*efx
)
316 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
319 if (!nic_data
->must_probe_vswitching
)
322 rc
= efx_ef10_vswitching_probe_pf(efx
);
326 rc
= efx_ef10_sriov_restore_vf_vswitching(efx
);
330 nic_data
->must_probe_vswitching
= false;
335 int efx_ef10_vswitching_restore_vf(struct efx_nic
*efx
)
337 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
340 if (!nic_data
->must_probe_vswitching
)
343 rc
= efx_ef10_vadaptor_free(efx
, EVB_PORT_ID_ASSIGNED
);
347 nic_data
->must_probe_vswitching
= false;
351 void efx_ef10_vswitching_remove_pf(struct efx_nic
*efx
)
353 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
355 efx_ef10_sriov_free_vf_vswitching(efx
);
357 efx_ef10_vadaptor_free(efx
, efx
->vport_id
);
359 if (efx
->vport_id
== EVB_PORT_ID_ASSIGNED
)
360 return; /* No vswitch was ever created */
362 if (!is_zero_ether_addr(nic_data
->vport_mac
)) {
363 efx_ef10_vport_del_mac(efx
, efx
->vport_id
,
364 efx
->net_dev
->dev_addr
);
365 eth_zero_addr(nic_data
->vport_mac
);
367 efx_ef10_vport_free(efx
, efx
->vport_id
);
368 efx
->vport_id
= EVB_PORT_ID_ASSIGNED
;
370 /* Only free the vswitch if no VFs are assigned */
371 if (!pci_vfs_assigned(efx
->pci_dev
))
372 efx_ef10_vswitch_free(efx
, efx
->vport_id
);
375 void efx_ef10_vswitching_remove_vf(struct efx_nic
*efx
)
377 efx_ef10_vadaptor_free(efx
, EVB_PORT_ID_ASSIGNED
);
380 static int efx_ef10_pci_sriov_enable(struct efx_nic
*efx
, int num_vfs
)
383 struct pci_dev
*dev
= efx
->pci_dev
;
385 efx
->vf_count
= num_vfs
;
387 rc
= efx_ef10_sriov_alloc_vf_vswitching(efx
);
391 rc
= pci_enable_sriov(dev
, num_vfs
);
397 efx_ef10_sriov_free_vf_vswitching(efx
);
400 netif_err(efx
, probe
, efx
->net_dev
,
401 "Failed to enable SRIOV VFs\n");
405 static int efx_ef10_pci_sriov_disable(struct efx_nic
*efx
, bool force
)
407 struct pci_dev
*dev
= efx
->pci_dev
;
408 unsigned int vfs_assigned
= 0;
410 vfs_assigned
= pci_vfs_assigned(dev
);
412 if (vfs_assigned
&& !force
) {
413 netif_info(efx
, drv
, efx
->net_dev
, "VFs are assigned to guests; "
414 "please detach them before disabling SR-IOV\n");
419 pci_disable_sriov(dev
);
421 efx_ef10_sriov_free_vf_vswitching(efx
);
426 int efx_ef10_sriov_configure(struct efx_nic
*efx
, int num_vfs
)
429 return efx_ef10_pci_sriov_disable(efx
, false);
431 return efx_ef10_pci_sriov_enable(efx
, num_vfs
);
434 int efx_ef10_sriov_init(struct efx_nic
*efx
)
439 void efx_ef10_sriov_fini(struct efx_nic
*efx
)
441 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
446 /* Remove any un-assigned orphaned VFs */
447 if (pci_num_vf(efx
->pci_dev
) && !pci_vfs_assigned(efx
->pci_dev
))
448 pci_disable_sriov(efx
->pci_dev
);
452 /* Remove any VFs in the host */
453 for (i
= 0; i
< efx
->vf_count
; ++i
) {
454 struct efx_nic
*vf_efx
= nic_data
->vf
[i
].efx
;
457 vf_efx
->pci_dev
->driver
->remove(vf_efx
->pci_dev
);
460 rc
= efx_ef10_pci_sriov_disable(efx
, true);
462 netif_dbg(efx
, drv
, efx
->net_dev
,
463 "Disabling SRIOV was not successful rc=%d\n", rc
);
465 netif_dbg(efx
, drv
, efx
->net_dev
, "SRIOV disabled\n");
468 static int efx_ef10_vport_del_vf_mac(struct efx_nic
*efx
, unsigned int port_id
,
471 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN
);
472 MCDI_DECLARE_BUF_ERR(outbuf
);
476 MCDI_SET_DWORD(inbuf
, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID
, port_id
);
477 ether_addr_copy(MCDI_PTR(inbuf
, VPORT_DEL_MAC_ADDRESS_IN_MACADDR
), mac
);
479 rc
= efx_mcdi_rpc(efx
, MC_CMD_VPORT_DEL_MAC_ADDRESS
, inbuf
,
480 sizeof(inbuf
), outbuf
, sizeof(outbuf
), &outlen
);
485 int efx_ef10_sriov_set_vf_mac(struct efx_nic
*efx
, int vf_i
, u8
*mac
)
487 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
494 if (vf_i
>= efx
->vf_count
)
496 vf
= nic_data
->vf
+ vf_i
;
499 efx_device_detach_sync(vf
->efx
);
500 efx_net_stop(vf
->efx
->net_dev
);
502 down_write(&vf
->efx
->filter_sem
);
503 vf
->efx
->type
->filter_table_remove(vf
->efx
);
505 rc
= efx_ef10_vadaptor_free(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
507 up_write(&vf
->efx
->filter_sem
);
512 rc
= efx_ef10_evb_port_assign(efx
, EVB_PORT_ID_NULL
, vf_i
);
516 if (!is_zero_ether_addr(vf
->mac
)) {
517 rc
= efx_ef10_vport_del_vf_mac(efx
, vf
->vport_id
, vf
->mac
);
522 if (!is_zero_ether_addr(mac
)) {
523 rc
= efx_ef10_vport_add_mac(efx
, vf
->vport_id
, mac
);
528 ether_addr_copy(vf
->efx
->net_dev
->dev_addr
, mac
);
531 ether_addr_copy(vf
->mac
, mac
);
533 rc
= efx_ef10_evb_port_assign(efx
, vf
->vport_id
, vf_i
);
538 /* VF cannot use the vport_id that the PF created */
539 rc
= efx_ef10_vadaptor_alloc(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
541 up_write(&vf
->efx
->filter_sem
);
544 vf
->efx
->type
->filter_table_probe(vf
->efx
);
545 up_write(&vf
->efx
->filter_sem
);
546 efx_net_open(vf
->efx
->net_dev
);
547 efx_device_attach_if_not_resetting(vf
->efx
);
553 eth_zero_addr(vf
->mac
);
557 int efx_ef10_sriov_set_vf_vlan(struct efx_nic
*efx
, int vf_i
, u16 vlan
,
560 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
565 if (vf_i
>= efx
->vf_count
)
570 vf
= nic_data
->vf
+ vf_i
;
572 new_vlan
= (vlan
== 0) ? EFX_EF10_NO_VLAN
: vlan
;
573 if (new_vlan
== vf
->vlan
)
577 efx_device_detach_sync(vf
->efx
);
578 efx_net_stop(vf
->efx
->net_dev
);
580 mutex_lock(&vf
->efx
->mac_lock
);
581 down_write(&vf
->efx
->filter_sem
);
582 vf
->efx
->type
->filter_table_remove(vf
->efx
);
584 rc
= efx_ef10_vadaptor_free(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
586 goto restore_filters
;
589 if (vf
->vport_assigned
) {
590 rc
= efx_ef10_evb_port_assign(efx
, EVB_PORT_ID_NULL
, vf_i
);
592 netif_warn(efx
, drv
, efx
->net_dev
,
593 "Failed to change vlan on VF %d.\n", vf_i
);
594 netif_warn(efx
, drv
, efx
->net_dev
,
595 "This is likely because the VF is bound to a driver in a VM.\n");
596 netif_warn(efx
, drv
, efx
->net_dev
,
597 "Please unload the driver in the VM.\n");
598 goto restore_vadaptor
;
600 vf
->vport_assigned
= 0;
603 if (!is_zero_ether_addr(vf
->mac
)) {
604 rc
= efx_ef10_vport_del_mac(efx
, vf
->vport_id
, vf
->mac
);
606 goto restore_evb_port
;
610 rc
= efx_ef10_vport_free(efx
, vf
->vport_id
);
616 /* Do the actual vlan change */
619 /* Restore everything in reverse order */
620 rc
= efx_ef10_vport_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
621 MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL
,
622 vf
->vlan
, &vf
->vport_id
);
624 goto reset_nic_up_write
;
627 if (!is_zero_ether_addr(vf
->mac
)) {
628 rc2
= efx_ef10_vport_add_mac(efx
, vf
->vport_id
, vf
->mac
);
630 eth_zero_addr(vf
->mac
);
631 goto reset_nic_up_write
;
636 rc2
= efx_ef10_evb_port_assign(efx
, vf
->vport_id
, vf_i
);
638 goto reset_nic_up_write
;
640 vf
->vport_assigned
= 1;
644 rc2
= efx_ef10_vadaptor_alloc(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
646 goto reset_nic_up_write
;
651 rc2
= vf
->efx
->type
->filter_table_probe(vf
->efx
);
653 goto reset_nic_up_write
;
655 up_write(&vf
->efx
->filter_sem
);
656 mutex_unlock(&vf
->efx
->mac_lock
);
658 rc2
= efx_net_open(vf
->efx
->net_dev
);
662 efx_device_attach_if_not_resetting(vf
->efx
);
668 up_write(&vf
->efx
->filter_sem
);
669 mutex_unlock(&vf
->efx
->mac_lock
);
673 netif_err(efx
, drv
, efx
->net_dev
,
674 "Failed to restore VF - scheduling reset.\n");
675 efx_schedule_reset(vf
->efx
, RESET_TYPE_DATAPATH
);
677 netif_err(efx
, drv
, efx
->net_dev
,
678 "Failed to restore the VF and cannot reset the VF "
679 "- VF is not functional.\n");
680 netif_err(efx
, drv
, efx
->net_dev
,
681 "Please reload the driver attached to the VF.\n");
684 return rc
? rc
: rc2
;
687 static int efx_ef10_sriov_set_privilege_mask(struct efx_nic
*efx
, int vf_i
,
690 MCDI_DECLARE_BUF(pm_outbuf
, MC_CMD_PRIVILEGE_MASK_OUT_LEN
);
691 MCDI_DECLARE_BUF(pm_inbuf
, MC_CMD_PRIVILEGE_MASK_IN_LEN
);
692 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
693 u32 old_mask
, new_mask
;
697 EFX_WARN_ON_PARANOID((value
& ~mask
) != 0);
699 /* Get privilege mask */
700 MCDI_POPULATE_DWORD_2(pm_inbuf
, PRIVILEGE_MASK_IN_FUNCTION
,
701 PRIVILEGE_MASK_IN_FUNCTION_PF
, nic_data
->pf_index
,
702 PRIVILEGE_MASK_IN_FUNCTION_VF
, vf_i
);
704 rc
= efx_mcdi_rpc(efx
, MC_CMD_PRIVILEGE_MASK
,
705 pm_inbuf
, sizeof(pm_inbuf
),
706 pm_outbuf
, sizeof(pm_outbuf
), &outlen
);
710 if (outlen
!= MC_CMD_PRIVILEGE_MASK_OUT_LEN
)
713 old_mask
= MCDI_DWORD(pm_outbuf
, PRIVILEGE_MASK_OUT_OLD_MASK
);
715 new_mask
= old_mask
& ~mask
;
718 if (new_mask
== old_mask
)
721 new_mask
|= MC_CMD_PRIVILEGE_MASK_IN_DO_CHANGE
;
723 /* Set privilege mask */
724 MCDI_SET_DWORD(pm_inbuf
, PRIVILEGE_MASK_IN_NEW_MASK
, new_mask
);
726 rc
= efx_mcdi_rpc(efx
, MC_CMD_PRIVILEGE_MASK
,
727 pm_inbuf
, sizeof(pm_inbuf
),
728 pm_outbuf
, sizeof(pm_outbuf
), &outlen
);
732 if (outlen
!= MC_CMD_PRIVILEGE_MASK_OUT_LEN
)
738 int efx_ef10_sriov_set_vf_spoofchk(struct efx_nic
*efx
, int vf_i
, bool spoofchk
)
740 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
742 /* Can't enable spoofchk if firmware doesn't support it. */
743 if (!(nic_data
->datapath_caps
&
744 BIT(MC_CMD_GET_CAPABILITIES_OUT_TX_MAC_SECURITY_FILTERING_LBN
)) &&
748 return efx_ef10_sriov_set_privilege_mask(efx
, vf_i
,
749 MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING_TX
,
750 spoofchk
? 0 : MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING_TX
);
753 int efx_ef10_sriov_set_vf_link_state(struct efx_nic
*efx
, int vf_i
,
756 MCDI_DECLARE_BUF(inbuf
, MC_CMD_LINK_STATE_MODE_IN_LEN
);
757 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
759 BUILD_BUG_ON(IFLA_VF_LINK_STATE_AUTO
!=
760 MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_AUTO
);
761 BUILD_BUG_ON(IFLA_VF_LINK_STATE_ENABLE
!=
762 MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_UP
);
763 BUILD_BUG_ON(IFLA_VF_LINK_STATE_DISABLE
!=
764 MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_DOWN
);
765 MCDI_POPULATE_DWORD_2(inbuf
, LINK_STATE_MODE_IN_FUNCTION
,
766 LINK_STATE_MODE_IN_FUNCTION_PF
,
768 LINK_STATE_MODE_IN_FUNCTION_VF
, vf_i
);
769 MCDI_SET_DWORD(inbuf
, LINK_STATE_MODE_IN_NEW_MODE
, link_state
);
770 return efx_mcdi_rpc(efx
, MC_CMD_LINK_STATE_MODE
, inbuf
, sizeof(inbuf
),
771 NULL
, 0, NULL
); /* don't care what old mode was */
774 int efx_ef10_sriov_get_vf_config(struct efx_nic
*efx
, int vf_i
,
775 struct ifla_vf_info
*ivf
)
777 MCDI_DECLARE_BUF(inbuf
, MC_CMD_LINK_STATE_MODE_IN_LEN
);
778 MCDI_DECLARE_BUF(outbuf
, MC_CMD_LINK_STATE_MODE_OUT_LEN
);
780 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
785 if (vf_i
>= efx
->vf_count
)
791 vf
= nic_data
->vf
+ vf_i
;
794 ivf
->min_tx_rate
= 0;
795 ivf
->max_tx_rate
= 0;
796 ether_addr_copy(ivf
->mac
, vf
->mac
);
797 ivf
->vlan
= (vf
->vlan
== EFX_EF10_NO_VLAN
) ? 0 : vf
->vlan
;
800 MCDI_POPULATE_DWORD_2(inbuf
, LINK_STATE_MODE_IN_FUNCTION
,
801 LINK_STATE_MODE_IN_FUNCTION_PF
,
803 LINK_STATE_MODE_IN_FUNCTION_VF
, vf_i
);
804 MCDI_SET_DWORD(inbuf
, LINK_STATE_MODE_IN_NEW_MODE
,
805 MC_CMD_LINK_STATE_MODE_IN_DO_NOT_CHANGE
);
806 rc
= efx_mcdi_rpc(efx
, MC_CMD_LINK_STATE_MODE
, inbuf
, sizeof(inbuf
),
807 outbuf
, sizeof(outbuf
), &outlen
);
810 if (outlen
< MC_CMD_LINK_STATE_MODE_OUT_LEN
)
812 ivf
->linkstate
= MCDI_DWORD(outbuf
, LINK_STATE_MODE_OUT_OLD_MODE
);