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 */
125 if (vf
->pci_dev
&& pci_is_dev_assigned(vf
->pci_dev
))
128 if (vf
->vport_assigned
) {
129 efx_ef10_evb_port_assign(efx
, EVB_PORT_ID_NULL
, i
);
130 vf
->vport_assigned
= 0;
133 if (!is_zero_ether_addr(vf
->mac
)) {
134 efx_ef10_vport_del_mac(efx
, vf
->vport_id
, vf
->mac
);
135 eth_zero_addr(vf
->mac
);
139 efx_ef10_vport_free(efx
, vf
->vport_id
);
147 static void efx_ef10_sriov_free_vf_vswitching(struct efx_nic
*efx
)
149 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
151 efx_ef10_sriov_free_vf_vports(efx
);
156 static int efx_ef10_sriov_assign_vf_vport(struct efx_nic
*efx
,
159 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
160 struct ef10_vf
*vf
= nic_data
->vf
+ vf_i
;
163 if (WARN_ON_ONCE(!nic_data
->vf
))
166 rc
= efx_ef10_vport_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
167 MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL
,
168 vf
->vlan
, &vf
->vport_id
);
172 rc
= efx_ef10_vport_add_mac(efx
, vf
->vport_id
, vf
->mac
);
174 eth_zero_addr(vf
->mac
);
178 rc
= efx_ef10_evb_port_assign(efx
, vf
->vport_id
, vf_i
);
182 vf
->vport_assigned
= 1;
186 static int efx_ef10_sriov_alloc_vf_vswitching(struct efx_nic
*efx
)
188 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
192 nic_data
->vf
= kcalloc(efx
->vf_count
, sizeof(struct ef10_vf
),
197 for (i
= 0; i
< efx
->vf_count
; i
++) {
198 eth_random_addr(nic_data
->vf
[i
].mac
);
199 nic_data
->vf
[i
].efx
= NULL
;
200 nic_data
->vf
[i
].vlan
= EFX_EF10_NO_VLAN
;
202 rc
= efx_ef10_sriov_assign_vf_vport(efx
, i
);
209 efx_ef10_sriov_free_vf_vswitching(efx
);
213 static int efx_ef10_sriov_restore_vf_vswitching(struct efx_nic
*efx
)
218 for (i
= 0; i
< efx
->vf_count
; i
++) {
219 rc
= efx_ef10_sriov_assign_vf_vport(efx
, i
);
226 efx_ef10_sriov_free_vf_vswitching(efx
);
230 static int efx_ef10_vadaptor_alloc_set_features(struct efx_nic
*efx
)
235 rc
= efx_ef10_vadaptor_alloc(efx
, efx
->vport_id
);
237 goto fail_vadaptor_alloc
;
239 rc
= efx_ef10_vadaptor_query(efx
, efx
->vport_id
,
240 &port_flags
, NULL
, NULL
);
242 goto fail_vadaptor_query
;
245 (1 << MC_CMD_VPORT_ALLOC_IN_FLAG_VLAN_RESTRICT_LBN
))
246 efx
->fixed_features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
248 efx
->fixed_features
&= ~NETIF_F_HW_VLAN_CTAG_FILTER
;
253 efx_ef10_vadaptor_free(efx
, EVB_PORT_ID_ASSIGNED
);
258 /* On top of the default firmware vswitch setup, create a VEB vswitch and
259 * expansion vport for use by this function.
261 int efx_ef10_vswitching_probe_pf(struct efx_nic
*efx
)
263 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
264 struct net_device
*net_dev
= efx
->net_dev
;
267 if (pci_sriov_get_totalvfs(efx
->pci_dev
) <= 0) {
268 /* vswitch not needed as we have no VFs */
269 efx_ef10_vadaptor_alloc_set_features(efx
);
273 rc
= efx_ef10_vswitch_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
274 MC_CMD_VSWITCH_ALLOC_IN_VSWITCH_TYPE_VEB
);
278 rc
= efx_ef10_vport_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
279 MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL
,
280 EFX_EF10_NO_VLAN
, &efx
->vport_id
);
284 rc
= efx_ef10_vport_add_mac(efx
, efx
->vport_id
, net_dev
->dev_addr
);
287 ether_addr_copy(nic_data
->vport_mac
, net_dev
->dev_addr
);
289 rc
= efx_ef10_vadaptor_alloc_set_features(efx
);
295 efx_ef10_vport_del_mac(efx
, efx
->vport_id
, nic_data
->vport_mac
);
296 eth_zero_addr(nic_data
->vport_mac
);
298 efx_ef10_vport_free(efx
, efx
->vport_id
);
299 efx
->vport_id
= EVB_PORT_ID_ASSIGNED
;
301 efx_ef10_vswitch_free(efx
, EVB_PORT_ID_ASSIGNED
);
306 int efx_ef10_vswitching_probe_vf(struct efx_nic
*efx
)
308 return efx_ef10_vadaptor_alloc_set_features(efx
);
311 int efx_ef10_vswitching_restore_pf(struct efx_nic
*efx
)
313 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
316 if (!nic_data
->must_probe_vswitching
)
319 rc
= efx_ef10_vswitching_probe_pf(efx
);
323 rc
= efx_ef10_sriov_restore_vf_vswitching(efx
);
327 nic_data
->must_probe_vswitching
= false;
332 int efx_ef10_vswitching_restore_vf(struct efx_nic
*efx
)
334 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
337 if (!nic_data
->must_probe_vswitching
)
340 rc
= efx_ef10_vadaptor_free(efx
, EVB_PORT_ID_ASSIGNED
);
344 nic_data
->must_probe_vswitching
= false;
348 void efx_ef10_vswitching_remove_pf(struct efx_nic
*efx
)
350 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
352 efx_ef10_sriov_free_vf_vswitching(efx
);
354 efx_ef10_vadaptor_free(efx
, efx
->vport_id
);
356 if (efx
->vport_id
== EVB_PORT_ID_ASSIGNED
)
357 return; /* No vswitch was ever created */
359 if (!is_zero_ether_addr(nic_data
->vport_mac
)) {
360 efx_ef10_vport_del_mac(efx
, efx
->vport_id
,
361 efx
->net_dev
->dev_addr
);
362 eth_zero_addr(nic_data
->vport_mac
);
364 efx_ef10_vport_free(efx
, efx
->vport_id
);
365 efx
->vport_id
= EVB_PORT_ID_ASSIGNED
;
367 /* Only free the vswitch if no VFs are assigned */
368 if (!pci_vfs_assigned(efx
->pci_dev
))
369 efx_ef10_vswitch_free(efx
, efx
->vport_id
);
372 void efx_ef10_vswitching_remove_vf(struct efx_nic
*efx
)
374 efx_ef10_vadaptor_free(efx
, EVB_PORT_ID_ASSIGNED
);
377 static int efx_ef10_pci_sriov_enable(struct efx_nic
*efx
, int num_vfs
)
380 struct pci_dev
*dev
= efx
->pci_dev
;
382 efx
->vf_count
= num_vfs
;
384 rc
= efx_ef10_sriov_alloc_vf_vswitching(efx
);
388 rc
= pci_enable_sriov(dev
, num_vfs
);
394 efx_ef10_sriov_free_vf_vswitching(efx
);
397 netif_err(efx
, probe
, efx
->net_dev
,
398 "Failed to enable SRIOV VFs\n");
402 /* Disable SRIOV and remove VFs
403 * If some VFs are attached to a guest (using Xen, only) nothing is
404 * done if force=false, and vports are freed if force=true (for the non
405 * attachedc ones, only) but SRIOV is not disabled and VFs are not
406 * removed in either case.
408 static int efx_ef10_pci_sriov_disable(struct efx_nic
*efx
, bool force
)
410 struct pci_dev
*dev
= efx
->pci_dev
;
411 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
412 unsigned int vfs_assigned
= pci_vfs_assigned(dev
);
415 if (vfs_assigned
&& !force
) {
416 netif_info(efx
, drv
, efx
->net_dev
, "VFs are assigned to guests; "
417 "please detach them before disabling SR-IOV\n");
422 for (i
= 0; i
< efx
->vf_count
; i
++)
423 nic_data
->vf
[i
].pci_dev
= NULL
;
424 pci_disable_sriov(dev
);
429 efx_ef10_sriov_free_vf_vswitching(efx
);
434 int efx_ef10_sriov_configure(struct efx_nic
*efx
, int num_vfs
)
437 return efx_ef10_pci_sriov_disable(efx
, false);
439 return efx_ef10_pci_sriov_enable(efx
, num_vfs
);
442 int efx_ef10_sriov_init(struct efx_nic
*efx
)
447 void efx_ef10_sriov_fini(struct efx_nic
*efx
)
449 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
453 /* Remove any un-assigned orphaned VFs. This can happen if the PF driver
454 * was unloaded while any VF was assigned to a guest (using Xen, only).
456 if (pci_num_vf(efx
->pci_dev
) && !pci_vfs_assigned(efx
->pci_dev
))
457 pci_disable_sriov(efx
->pci_dev
);
461 /* Disable SRIOV and remove any VFs in the host */
462 rc
= efx_ef10_pci_sriov_disable(efx
, true);
464 netif_dbg(efx
, drv
, efx
->net_dev
,
465 "Disabling SRIOV was not successful rc=%d\n", rc
);
467 netif_dbg(efx
, drv
, efx
->net_dev
, "SRIOV disabled\n");
470 static int efx_ef10_vport_del_vf_mac(struct efx_nic
*efx
, unsigned int port_id
,
473 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN
);
474 MCDI_DECLARE_BUF_ERR(outbuf
);
478 MCDI_SET_DWORD(inbuf
, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID
, port_id
);
479 ether_addr_copy(MCDI_PTR(inbuf
, VPORT_DEL_MAC_ADDRESS_IN_MACADDR
), mac
);
481 rc
= efx_mcdi_rpc(efx
, MC_CMD_VPORT_DEL_MAC_ADDRESS
, inbuf
,
482 sizeof(inbuf
), outbuf
, sizeof(outbuf
), &outlen
);
487 int efx_ef10_sriov_set_vf_mac(struct efx_nic
*efx
, int vf_i
, const u8
*mac
)
489 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
496 if (vf_i
>= efx
->vf_count
)
498 vf
= nic_data
->vf
+ vf_i
;
501 efx_device_detach_sync(vf
->efx
);
502 efx_net_stop(vf
->efx
->net_dev
);
504 vf
->efx
->type
->filter_table_remove(vf
->efx
);
506 rc
= efx_ef10_vadaptor_free(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
511 rc
= efx_ef10_evb_port_assign(efx
, EVB_PORT_ID_NULL
, vf_i
);
515 if (!is_zero_ether_addr(vf
->mac
)) {
516 rc
= efx_ef10_vport_del_vf_mac(efx
, vf
->vport_id
, vf
->mac
);
521 if (!is_zero_ether_addr(mac
)) {
522 rc
= efx_ef10_vport_add_mac(efx
, vf
->vport_id
, mac
);
527 eth_hw_addr_set(vf
->efx
->net_dev
, mac
);
530 ether_addr_copy(vf
->mac
, mac
);
532 rc
= efx_ef10_evb_port_assign(efx
, vf
->vport_id
, vf_i
);
537 /* VF cannot use the vport_id that the PF created */
538 rc
= efx_ef10_vadaptor_alloc(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
541 vf
->efx
->type
->filter_table_probe(vf
->efx
);
542 efx_net_open(vf
->efx
->net_dev
);
543 efx_device_attach_if_not_resetting(vf
->efx
);
549 eth_zero_addr(vf
->mac
);
553 int efx_ef10_sriov_set_vf_vlan(struct efx_nic
*efx
, int vf_i
, u16 vlan
,
556 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
561 if (vf_i
>= efx
->vf_count
)
566 vf
= nic_data
->vf
+ vf_i
;
568 new_vlan
= (vlan
== 0) ? EFX_EF10_NO_VLAN
: vlan
;
569 if (new_vlan
== vf
->vlan
)
573 efx_device_detach_sync(vf
->efx
);
574 efx_net_stop(vf
->efx
->net_dev
);
576 mutex_lock(&vf
->efx
->mac_lock
);
577 vf
->efx
->type
->filter_table_remove(vf
->efx
);
579 rc
= efx_ef10_vadaptor_free(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
581 goto restore_filters
;
584 if (vf
->vport_assigned
) {
585 rc
= efx_ef10_evb_port_assign(efx
, EVB_PORT_ID_NULL
, vf_i
);
587 netif_warn(efx
, drv
, efx
->net_dev
,
588 "Failed to change vlan on VF %d.\n", vf_i
);
589 netif_warn(efx
, drv
, efx
->net_dev
,
590 "This is likely because the VF is bound to a driver in a VM.\n");
591 netif_warn(efx
, drv
, efx
->net_dev
,
592 "Please unload the driver in the VM.\n");
593 goto restore_vadaptor
;
595 vf
->vport_assigned
= 0;
598 if (!is_zero_ether_addr(vf
->mac
)) {
599 rc
= efx_ef10_vport_del_mac(efx
, vf
->vport_id
, vf
->mac
);
601 goto restore_evb_port
;
605 rc
= efx_ef10_vport_free(efx
, vf
->vport_id
);
611 /* Do the actual vlan change */
614 /* Restore everything in reverse order */
615 rc
= efx_ef10_vport_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
616 MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL
,
617 vf
->vlan
, &vf
->vport_id
);
619 goto reset_nic_up_write
;
622 if (!is_zero_ether_addr(vf
->mac
)) {
623 rc2
= efx_ef10_vport_add_mac(efx
, vf
->vport_id
, vf
->mac
);
625 eth_zero_addr(vf
->mac
);
626 goto reset_nic_up_write
;
631 rc2
= efx_ef10_evb_port_assign(efx
, vf
->vport_id
, vf_i
);
633 goto reset_nic_up_write
;
635 vf
->vport_assigned
= 1;
639 rc2
= efx_ef10_vadaptor_alloc(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
641 goto reset_nic_up_write
;
646 rc2
= vf
->efx
->type
->filter_table_probe(vf
->efx
);
648 goto reset_nic_up_write
;
650 mutex_unlock(&vf
->efx
->mac_lock
);
652 rc2
= efx_net_open(vf
->efx
->net_dev
);
656 efx_device_attach_if_not_resetting(vf
->efx
);
662 mutex_unlock(&vf
->efx
->mac_lock
);
665 netif_err(efx
, drv
, efx
->net_dev
,
666 "Failed to restore VF - scheduling reset.\n");
667 efx_schedule_reset(vf
->efx
, RESET_TYPE_DATAPATH
);
669 netif_err(efx
, drv
, efx
->net_dev
,
670 "Failed to restore the VF and cannot reset the VF "
671 "- VF is not functional.\n");
672 netif_err(efx
, drv
, efx
->net_dev
,
673 "Please reload the driver attached to the VF.\n");
676 return rc
? rc
: rc2
;
679 static int efx_ef10_sriov_set_privilege_mask(struct efx_nic
*efx
, int vf_i
,
682 MCDI_DECLARE_BUF(pm_outbuf
, MC_CMD_PRIVILEGE_MASK_OUT_LEN
);
683 MCDI_DECLARE_BUF(pm_inbuf
, MC_CMD_PRIVILEGE_MASK_IN_LEN
);
684 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
685 u32 old_mask
, new_mask
;
689 EFX_WARN_ON_PARANOID((value
& ~mask
) != 0);
691 /* Get privilege mask */
692 MCDI_POPULATE_DWORD_2(pm_inbuf
, PRIVILEGE_MASK_IN_FUNCTION
,
693 PRIVILEGE_MASK_IN_FUNCTION_PF
, nic_data
->pf_index
,
694 PRIVILEGE_MASK_IN_FUNCTION_VF
, vf_i
);
696 rc
= efx_mcdi_rpc(efx
, MC_CMD_PRIVILEGE_MASK
,
697 pm_inbuf
, sizeof(pm_inbuf
),
698 pm_outbuf
, sizeof(pm_outbuf
), &outlen
);
702 if (outlen
!= MC_CMD_PRIVILEGE_MASK_OUT_LEN
)
705 old_mask
= MCDI_DWORD(pm_outbuf
, PRIVILEGE_MASK_OUT_OLD_MASK
);
707 new_mask
= old_mask
& ~mask
;
710 if (new_mask
== old_mask
)
713 new_mask
|= MC_CMD_PRIVILEGE_MASK_IN_DO_CHANGE
;
715 /* Set privilege mask */
716 MCDI_SET_DWORD(pm_inbuf
, PRIVILEGE_MASK_IN_NEW_MASK
, new_mask
);
718 rc
= efx_mcdi_rpc(efx
, MC_CMD_PRIVILEGE_MASK
,
719 pm_inbuf
, sizeof(pm_inbuf
),
720 pm_outbuf
, sizeof(pm_outbuf
), &outlen
);
724 if (outlen
!= MC_CMD_PRIVILEGE_MASK_OUT_LEN
)
730 int efx_ef10_sriov_set_vf_spoofchk(struct efx_nic
*efx
, int vf_i
, bool spoofchk
)
732 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
734 /* Can't enable spoofchk if firmware doesn't support it. */
735 if (!(nic_data
->datapath_caps
&
736 BIT(MC_CMD_GET_CAPABILITIES_OUT_TX_MAC_SECURITY_FILTERING_LBN
)) &&
740 return efx_ef10_sriov_set_privilege_mask(efx
, vf_i
,
741 MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING_TX
,
742 spoofchk
? 0 : MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING_TX
);
745 int efx_ef10_sriov_set_vf_link_state(struct efx_nic
*efx
, int vf_i
,
748 MCDI_DECLARE_BUF(inbuf
, MC_CMD_LINK_STATE_MODE_IN_LEN
);
749 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
751 BUILD_BUG_ON(IFLA_VF_LINK_STATE_AUTO
!=
752 MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_AUTO
);
753 BUILD_BUG_ON(IFLA_VF_LINK_STATE_ENABLE
!=
754 MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_UP
);
755 BUILD_BUG_ON(IFLA_VF_LINK_STATE_DISABLE
!=
756 MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_DOWN
);
757 MCDI_POPULATE_DWORD_2(inbuf
, LINK_STATE_MODE_IN_FUNCTION
,
758 LINK_STATE_MODE_IN_FUNCTION_PF
,
760 LINK_STATE_MODE_IN_FUNCTION_VF
, vf_i
);
761 MCDI_SET_DWORD(inbuf
, LINK_STATE_MODE_IN_NEW_MODE
, link_state
);
762 return efx_mcdi_rpc(efx
, MC_CMD_LINK_STATE_MODE
, inbuf
, sizeof(inbuf
),
763 NULL
, 0, NULL
); /* don't care what old mode was */
766 int efx_ef10_sriov_get_vf_config(struct efx_nic
*efx
, int vf_i
,
767 struct ifla_vf_info
*ivf
)
769 MCDI_DECLARE_BUF(inbuf
, MC_CMD_LINK_STATE_MODE_IN_LEN
);
770 MCDI_DECLARE_BUF(outbuf
, MC_CMD_LINK_STATE_MODE_OUT_LEN
);
772 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
777 if (vf_i
>= efx
->vf_count
)
783 vf
= nic_data
->vf
+ vf_i
;
786 ivf
->min_tx_rate
= 0;
787 ivf
->max_tx_rate
= 0;
788 ether_addr_copy(ivf
->mac
, vf
->mac
);
789 ivf
->vlan
= (vf
->vlan
== EFX_EF10_NO_VLAN
) ? 0 : vf
->vlan
;
792 MCDI_POPULATE_DWORD_2(inbuf
, LINK_STATE_MODE_IN_FUNCTION
,
793 LINK_STATE_MODE_IN_FUNCTION_PF
,
795 LINK_STATE_MODE_IN_FUNCTION_VF
, vf_i
);
796 MCDI_SET_DWORD(inbuf
, LINK_STATE_MODE_IN_NEW_MODE
,
797 MC_CMD_LINK_STATE_MODE_IN_DO_NOT_CHANGE
);
798 rc
= efx_mcdi_rpc(efx
, MC_CMD_LINK_STATE_MODE
, inbuf
, sizeof(inbuf
),
799 outbuf
, sizeof(outbuf
), &outlen
);
802 if (outlen
< MC_CMD_LINK_STATE_MODE_OUT_LEN
)
804 ivf
->linkstate
= MCDI_DWORD(outbuf
, LINK_STATE_MODE_OUT_OLD_MODE
);