1 /****************************************************************************
2 * Driver for Solarflare network controllers and boards
3 * Copyright 2015 Solarflare Communications Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
10 #include <linux/module.h>
11 #include "net_driver.h"
12 #include "ef10_sriov.h"
15 #include "mcdi_pcol.h"
17 static int efx_ef10_evb_port_assign(struct efx_nic
*efx
, unsigned int port_id
,
20 MCDI_DECLARE_BUF(inbuf
, MC_CMD_EVB_PORT_ASSIGN_IN_LEN
);
21 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
23 MCDI_SET_DWORD(inbuf
, EVB_PORT_ASSIGN_IN_PORT_ID
, port_id
);
24 MCDI_POPULATE_DWORD_2(inbuf
, EVB_PORT_ASSIGN_IN_FUNCTION
,
25 EVB_PORT_ASSIGN_IN_PF
, nic_data
->pf_index
,
26 EVB_PORT_ASSIGN_IN_VF
, vf_fn
);
28 return efx_mcdi_rpc(efx
, MC_CMD_EVB_PORT_ASSIGN
, inbuf
, sizeof(inbuf
),
32 static int efx_ef10_vswitch_alloc(struct efx_nic
*efx
, unsigned int port_id
,
33 unsigned int vswitch_type
)
35 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VSWITCH_ALLOC_IN_LEN
);
38 MCDI_SET_DWORD(inbuf
, VSWITCH_ALLOC_IN_UPSTREAM_PORT_ID
, port_id
);
39 MCDI_SET_DWORD(inbuf
, VSWITCH_ALLOC_IN_TYPE
, vswitch_type
);
40 MCDI_SET_DWORD(inbuf
, VSWITCH_ALLOC_IN_NUM_VLAN_TAGS
, 2);
41 MCDI_POPULATE_DWORD_1(inbuf
, VSWITCH_ALLOC_IN_FLAGS
,
42 VSWITCH_ALLOC_IN_FLAG_AUTO_PORT
, 0);
44 /* Quietly try to allocate 2 VLAN tags */
45 rc
= efx_mcdi_rpc_quiet(efx
, MC_CMD_VSWITCH_ALLOC
, inbuf
, sizeof(inbuf
),
48 /* If 2 VLAN tags is too many, revert to trying with 1 VLAN tags */
50 MCDI_SET_DWORD(inbuf
, VSWITCH_ALLOC_IN_NUM_VLAN_TAGS
, 1);
51 rc
= efx_mcdi_rpc(efx
, MC_CMD_VSWITCH_ALLOC
, inbuf
,
52 sizeof(inbuf
), NULL
, 0, NULL
);
54 efx_mcdi_display_error(efx
, MC_CMD_VSWITCH_ALLOC
,
55 MC_CMD_VSWITCH_ALLOC_IN_LEN
,
61 static int efx_ef10_vswitch_free(struct efx_nic
*efx
, unsigned int port_id
)
63 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VSWITCH_FREE_IN_LEN
);
65 MCDI_SET_DWORD(inbuf
, VSWITCH_FREE_IN_UPSTREAM_PORT_ID
, port_id
);
67 return efx_mcdi_rpc(efx
, MC_CMD_VSWITCH_FREE
, inbuf
, sizeof(inbuf
),
71 static int efx_ef10_vport_alloc(struct efx_nic
*efx
,
72 unsigned int port_id_in
,
73 unsigned int vport_type
,
75 unsigned int *port_id_out
)
77 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VPORT_ALLOC_IN_LEN
);
78 MCDI_DECLARE_BUF(outbuf
, MC_CMD_VPORT_ALLOC_OUT_LEN
);
82 EFX_WARN_ON_PARANOID(!port_id_out
);
84 MCDI_SET_DWORD(inbuf
, VPORT_ALLOC_IN_UPSTREAM_PORT_ID
, port_id_in
);
85 MCDI_SET_DWORD(inbuf
, VPORT_ALLOC_IN_TYPE
, vport_type
);
86 MCDI_SET_DWORD(inbuf
, VPORT_ALLOC_IN_NUM_VLAN_TAGS
,
87 (vlan
!= EFX_EF10_NO_VLAN
));
88 MCDI_POPULATE_DWORD_1(inbuf
, VPORT_ALLOC_IN_FLAGS
,
89 VPORT_ALLOC_IN_FLAG_AUTO_PORT
, 0);
90 if (vlan
!= EFX_EF10_NO_VLAN
)
91 MCDI_POPULATE_DWORD_1(inbuf
, VPORT_ALLOC_IN_VLAN_TAGS
,
92 VPORT_ALLOC_IN_VLAN_TAG_0
, vlan
);
94 rc
= efx_mcdi_rpc(efx
, MC_CMD_VPORT_ALLOC
, inbuf
, sizeof(inbuf
),
95 outbuf
, sizeof(outbuf
), &outlen
);
98 if (outlen
< MC_CMD_VPORT_ALLOC_OUT_LEN
)
101 *port_id_out
= MCDI_DWORD(outbuf
, VPORT_ALLOC_OUT_VPORT_ID
);
105 static int efx_ef10_vport_free(struct efx_nic
*efx
, unsigned int port_id
)
107 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VPORT_FREE_IN_LEN
);
109 MCDI_SET_DWORD(inbuf
, VPORT_FREE_IN_VPORT_ID
, port_id
);
111 return efx_mcdi_rpc(efx
, MC_CMD_VPORT_FREE
, inbuf
, sizeof(inbuf
),
115 static void efx_ef10_sriov_free_vf_vports(struct efx_nic
*efx
)
117 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
123 for (i
= 0; i
< efx
->vf_count
; i
++) {
124 struct ef10_vf
*vf
= nic_data
->vf
+ i
;
126 /* If VF is assigned, do not free the vport */
128 vf
->pci_dev
->dev_flags
& PCI_DEV_FLAGS_ASSIGNED
)
131 if (vf
->vport_assigned
) {
132 efx_ef10_evb_port_assign(efx
, EVB_PORT_ID_NULL
, i
);
133 vf
->vport_assigned
= 0;
136 if (!is_zero_ether_addr(vf
->mac
)) {
137 efx_ef10_vport_del_mac(efx
, vf
->vport_id
, vf
->mac
);
138 eth_zero_addr(vf
->mac
);
142 efx_ef10_vport_free(efx
, vf
->vport_id
);
150 static void efx_ef10_sriov_free_vf_vswitching(struct efx_nic
*efx
)
152 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
154 efx_ef10_sriov_free_vf_vports(efx
);
159 static int efx_ef10_sriov_assign_vf_vport(struct efx_nic
*efx
,
162 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
163 struct ef10_vf
*vf
= nic_data
->vf
+ vf_i
;
166 if (WARN_ON_ONCE(!nic_data
->vf
))
169 rc
= efx_ef10_vport_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
170 MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL
,
171 vf
->vlan
, &vf
->vport_id
);
175 rc
= efx_ef10_vport_add_mac(efx
, vf
->vport_id
, vf
->mac
);
177 eth_zero_addr(vf
->mac
);
181 rc
= efx_ef10_evb_port_assign(efx
, vf
->vport_id
, vf_i
);
185 vf
->vport_assigned
= 1;
189 static int efx_ef10_sriov_alloc_vf_vswitching(struct efx_nic
*efx
)
191 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
195 nic_data
->vf
= kcalloc(efx
->vf_count
, sizeof(struct ef10_vf
),
200 for (i
= 0; i
< efx
->vf_count
; i
++) {
201 random_ether_addr(nic_data
->vf
[i
].mac
);
202 nic_data
->vf
[i
].efx
= NULL
;
203 nic_data
->vf
[i
].vlan
= EFX_EF10_NO_VLAN
;
205 rc
= efx_ef10_sriov_assign_vf_vport(efx
, i
);
212 efx_ef10_sriov_free_vf_vports(efx
);
218 static int efx_ef10_sriov_restore_vf_vswitching(struct efx_nic
*efx
)
223 for (i
= 0; i
< efx
->vf_count
; i
++) {
224 rc
= efx_ef10_sriov_assign_vf_vport(efx
, i
);
231 efx_ef10_sriov_free_vf_vswitching(efx
);
235 static int efx_ef10_vadaptor_alloc_set_features(struct efx_nic
*efx
)
237 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
241 rc
= efx_ef10_vadaptor_alloc(efx
, nic_data
->vport_id
);
243 goto fail_vadaptor_alloc
;
245 rc
= efx_ef10_vadaptor_query(efx
, nic_data
->vport_id
,
246 &port_flags
, NULL
, NULL
);
248 goto fail_vadaptor_query
;
251 (1 << MC_CMD_VPORT_ALLOC_IN_FLAG_VLAN_RESTRICT_LBN
))
252 efx
->fixed_features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
254 efx
->fixed_features
&= ~NETIF_F_HW_VLAN_CTAG_FILTER
;
259 efx_ef10_vadaptor_free(efx
, EVB_PORT_ID_ASSIGNED
);
264 /* On top of the default firmware vswitch setup, create a VEB vswitch and
265 * expansion vport for use by this function.
267 int efx_ef10_vswitching_probe_pf(struct efx_nic
*efx
)
269 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
270 struct net_device
*net_dev
= efx
->net_dev
;
273 if (pci_sriov_get_totalvfs(efx
->pci_dev
) <= 0) {
274 /* vswitch not needed as we have no VFs */
275 efx_ef10_vadaptor_alloc_set_features(efx
);
279 rc
= efx_ef10_vswitch_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
280 MC_CMD_VSWITCH_ALLOC_IN_VSWITCH_TYPE_VEB
);
284 rc
= efx_ef10_vport_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
285 MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL
,
286 EFX_EF10_NO_VLAN
, &nic_data
->vport_id
);
290 rc
= efx_ef10_vport_add_mac(efx
, nic_data
->vport_id
, net_dev
->dev_addr
);
293 ether_addr_copy(nic_data
->vport_mac
, net_dev
->dev_addr
);
295 rc
= efx_ef10_vadaptor_alloc_set_features(efx
);
301 efx_ef10_vport_del_mac(efx
, nic_data
->vport_id
, nic_data
->vport_mac
);
302 eth_zero_addr(nic_data
->vport_mac
);
304 efx_ef10_vport_free(efx
, nic_data
->vport_id
);
305 nic_data
->vport_id
= EVB_PORT_ID_ASSIGNED
;
307 efx_ef10_vswitch_free(efx
, EVB_PORT_ID_ASSIGNED
);
312 int efx_ef10_vswitching_probe_vf(struct efx_nic
*efx
)
314 return efx_ef10_vadaptor_alloc_set_features(efx
);
317 int efx_ef10_vswitching_restore_pf(struct efx_nic
*efx
)
319 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
322 if (!nic_data
->must_probe_vswitching
)
325 rc
= efx_ef10_vswitching_probe_pf(efx
);
329 rc
= efx_ef10_sriov_restore_vf_vswitching(efx
);
333 nic_data
->must_probe_vswitching
= false;
338 int efx_ef10_vswitching_restore_vf(struct efx_nic
*efx
)
340 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
343 if (!nic_data
->must_probe_vswitching
)
346 rc
= efx_ef10_vadaptor_free(efx
, EVB_PORT_ID_ASSIGNED
);
350 nic_data
->must_probe_vswitching
= false;
354 void efx_ef10_vswitching_remove_pf(struct efx_nic
*efx
)
356 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
358 efx_ef10_sriov_free_vf_vswitching(efx
);
360 efx_ef10_vadaptor_free(efx
, nic_data
->vport_id
);
362 if (nic_data
->vport_id
== EVB_PORT_ID_ASSIGNED
)
363 return; /* No vswitch was ever created */
365 if (!is_zero_ether_addr(nic_data
->vport_mac
)) {
366 efx_ef10_vport_del_mac(efx
, nic_data
->vport_id
,
367 efx
->net_dev
->dev_addr
);
368 eth_zero_addr(nic_data
->vport_mac
);
370 efx_ef10_vport_free(efx
, nic_data
->vport_id
);
371 nic_data
->vport_id
= EVB_PORT_ID_ASSIGNED
;
373 /* Only free the vswitch if no VFs are assigned */
374 if (!pci_vfs_assigned(efx
->pci_dev
))
375 efx_ef10_vswitch_free(efx
, nic_data
->vport_id
);
378 void efx_ef10_vswitching_remove_vf(struct efx_nic
*efx
)
380 efx_ef10_vadaptor_free(efx
, EVB_PORT_ID_ASSIGNED
);
383 static int efx_ef10_pci_sriov_enable(struct efx_nic
*efx
, int num_vfs
)
386 struct pci_dev
*dev
= efx
->pci_dev
;
388 efx
->vf_count
= num_vfs
;
390 rc
= efx_ef10_sriov_alloc_vf_vswitching(efx
);
394 rc
= pci_enable_sriov(dev
, num_vfs
);
400 efx_ef10_sriov_free_vf_vswitching(efx
);
403 netif_err(efx
, probe
, efx
->net_dev
,
404 "Failed to enable SRIOV VFs\n");
408 static int efx_ef10_pci_sriov_disable(struct efx_nic
*efx
, bool force
)
410 struct pci_dev
*dev
= efx
->pci_dev
;
411 unsigned int vfs_assigned
= 0;
413 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 pci_disable_sriov(dev
);
424 efx_ef10_sriov_free_vf_vswitching(efx
);
429 int efx_ef10_sriov_configure(struct efx_nic
*efx
, int num_vfs
)
432 return efx_ef10_pci_sriov_disable(efx
, false);
434 return efx_ef10_pci_sriov_enable(efx
, num_vfs
);
437 int efx_ef10_sriov_init(struct efx_nic
*efx
)
442 void efx_ef10_sriov_fini(struct efx_nic
*efx
)
444 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
449 /* Remove any un-assigned orphaned VFs */
450 if (pci_num_vf(efx
->pci_dev
) && !pci_vfs_assigned(efx
->pci_dev
))
451 pci_disable_sriov(efx
->pci_dev
);
455 /* Remove any VFs in the host */
456 for (i
= 0; i
< efx
->vf_count
; ++i
) {
457 struct efx_nic
*vf_efx
= nic_data
->vf
[i
].efx
;
460 vf_efx
->pci_dev
->driver
->remove(vf_efx
->pci_dev
);
463 rc
= efx_ef10_pci_sriov_disable(efx
, true);
465 netif_dbg(efx
, drv
, efx
->net_dev
,
466 "Disabling SRIOV was not successful rc=%d\n", rc
);
468 netif_dbg(efx
, drv
, efx
->net_dev
, "SRIOV disabled\n");
471 static int efx_ef10_vport_del_vf_mac(struct efx_nic
*efx
, unsigned int port_id
,
474 MCDI_DECLARE_BUF(inbuf
, MC_CMD_VPORT_DEL_MAC_ADDRESS_IN_LEN
);
475 MCDI_DECLARE_BUF_ERR(outbuf
);
479 MCDI_SET_DWORD(inbuf
, VPORT_DEL_MAC_ADDRESS_IN_VPORT_ID
, port_id
);
480 ether_addr_copy(MCDI_PTR(inbuf
, VPORT_DEL_MAC_ADDRESS_IN_MACADDR
), mac
);
482 rc
= efx_mcdi_rpc(efx
, MC_CMD_VPORT_DEL_MAC_ADDRESS
, inbuf
,
483 sizeof(inbuf
), outbuf
, sizeof(outbuf
), &outlen
);
488 int efx_ef10_sriov_set_vf_mac(struct efx_nic
*efx
, int vf_i
, u8
*mac
)
490 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
497 if (vf_i
>= efx
->vf_count
)
499 vf
= nic_data
->vf
+ vf_i
;
502 efx_device_detach_sync(vf
->efx
);
503 efx_net_stop(vf
->efx
->net_dev
);
505 down_write(&vf
->efx
->filter_sem
);
506 vf
->efx
->type
->filter_table_remove(vf
->efx
);
508 rc
= efx_ef10_vadaptor_free(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
510 up_write(&vf
->efx
->filter_sem
);
515 rc
= efx_ef10_evb_port_assign(efx
, EVB_PORT_ID_NULL
, vf_i
);
519 if (!is_zero_ether_addr(vf
->mac
)) {
520 rc
= efx_ef10_vport_del_vf_mac(efx
, vf
->vport_id
, vf
->mac
);
525 if (!is_zero_ether_addr(mac
)) {
526 rc
= efx_ef10_vport_add_mac(efx
, vf
->vport_id
, mac
);
528 eth_zero_addr(vf
->mac
);
532 ether_addr_copy(vf
->efx
->net_dev
->dev_addr
, mac
);
535 ether_addr_copy(vf
->mac
, mac
);
537 rc
= efx_ef10_evb_port_assign(efx
, vf
->vport_id
, vf_i
);
542 /* VF cannot use the vport_id that the PF created */
543 rc
= efx_ef10_vadaptor_alloc(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
545 up_write(&vf
->efx
->filter_sem
);
548 vf
->efx
->type
->filter_table_probe(vf
->efx
);
549 up_write(&vf
->efx
->filter_sem
);
550 efx_net_open(vf
->efx
->net_dev
);
551 netif_device_attach(vf
->efx
->net_dev
);
557 memset(vf
->mac
, 0, ETH_ALEN
);
561 int efx_ef10_sriov_set_vf_vlan(struct efx_nic
*efx
, int vf_i
, u16 vlan
,
564 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
566 u16 old_vlan
, new_vlan
;
569 if (vf_i
>= efx
->vf_count
)
574 vf
= nic_data
->vf
+ vf_i
;
576 new_vlan
= (vlan
== 0) ? EFX_EF10_NO_VLAN
: vlan
;
577 if (new_vlan
== vf
->vlan
)
581 efx_device_detach_sync(vf
->efx
);
582 efx_net_stop(vf
->efx
->net_dev
);
584 mutex_lock(&vf
->efx
->mac_lock
);
585 down_write(&vf
->efx
->filter_sem
);
586 vf
->efx
->type
->filter_table_remove(vf
->efx
);
588 rc
= efx_ef10_vadaptor_free(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
590 goto restore_filters
;
593 if (vf
->vport_assigned
) {
594 rc
= efx_ef10_evb_port_assign(efx
, EVB_PORT_ID_NULL
, vf_i
);
596 netif_warn(efx
, drv
, efx
->net_dev
,
597 "Failed to change vlan on VF %d.\n", vf_i
);
598 netif_warn(efx
, drv
, efx
->net_dev
,
599 "This is likely because the VF is bound to a driver in a VM.\n");
600 netif_warn(efx
, drv
, efx
->net_dev
,
601 "Please unload the driver in the VM.\n");
602 goto restore_vadaptor
;
604 vf
->vport_assigned
= 0;
607 if (!is_zero_ether_addr(vf
->mac
)) {
608 rc
= efx_ef10_vport_del_mac(efx
, vf
->vport_id
, vf
->mac
);
610 goto restore_evb_port
;
614 rc
= efx_ef10_vport_free(efx
, vf
->vport_id
);
620 /* Do the actual vlan change */
624 /* Restore everything in reverse order */
625 rc
= efx_ef10_vport_alloc(efx
, EVB_PORT_ID_ASSIGNED
,
626 MC_CMD_VPORT_ALLOC_IN_VPORT_TYPE_NORMAL
,
627 vf
->vlan
, &vf
->vport_id
);
629 goto reset_nic_up_write
;
632 if (!is_zero_ether_addr(vf
->mac
)) {
633 rc2
= efx_ef10_vport_add_mac(efx
, vf
->vport_id
, vf
->mac
);
635 eth_zero_addr(vf
->mac
);
636 goto reset_nic_up_write
;
641 rc2
= efx_ef10_evb_port_assign(efx
, vf
->vport_id
, vf_i
);
643 goto reset_nic_up_write
;
645 vf
->vport_assigned
= 1;
649 rc2
= efx_ef10_vadaptor_alloc(vf
->efx
, EVB_PORT_ID_ASSIGNED
);
651 goto reset_nic_up_write
;
656 rc2
= vf
->efx
->type
->filter_table_probe(vf
->efx
);
658 goto reset_nic_up_write
;
660 up_write(&vf
->efx
->filter_sem
);
661 mutex_unlock(&vf
->efx
->mac_lock
);
663 up_write(&vf
->efx
->filter_sem
);
665 rc2
= efx_net_open(vf
->efx
->net_dev
);
669 netif_device_attach(vf
->efx
->net_dev
);
675 up_write(&vf
->efx
->filter_sem
);
676 mutex_unlock(&vf
->efx
->mac_lock
);
680 netif_err(efx
, drv
, efx
->net_dev
,
681 "Failed to restore VF - scheduling reset.\n");
682 efx_schedule_reset(vf
->efx
, RESET_TYPE_DATAPATH
);
684 netif_err(efx
, drv
, efx
->net_dev
,
685 "Failed to restore the VF and cannot reset the VF "
686 "- VF is not functional.\n");
687 netif_err(efx
, drv
, efx
->net_dev
,
688 "Please reload the driver attached to the VF.\n");
691 return rc
? rc
: rc2
;
694 int efx_ef10_sriov_set_vf_spoofchk(struct efx_nic
*efx
, int vf_i
,
697 return spoofchk
? -EOPNOTSUPP
: 0;
700 int efx_ef10_sriov_set_vf_link_state(struct efx_nic
*efx
, int vf_i
,
703 MCDI_DECLARE_BUF(inbuf
, MC_CMD_LINK_STATE_MODE_IN_LEN
);
704 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
706 BUILD_BUG_ON(IFLA_VF_LINK_STATE_AUTO
!=
707 MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_AUTO
);
708 BUILD_BUG_ON(IFLA_VF_LINK_STATE_ENABLE
!=
709 MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_UP
);
710 BUILD_BUG_ON(IFLA_VF_LINK_STATE_DISABLE
!=
711 MC_CMD_LINK_STATE_MODE_IN_LINK_STATE_DOWN
);
712 MCDI_POPULATE_DWORD_2(inbuf
, LINK_STATE_MODE_IN_FUNCTION
,
713 LINK_STATE_MODE_IN_FUNCTION_PF
,
715 LINK_STATE_MODE_IN_FUNCTION_VF
, vf_i
);
716 MCDI_SET_DWORD(inbuf
, LINK_STATE_MODE_IN_NEW_MODE
, link_state
);
717 return efx_mcdi_rpc(efx
, MC_CMD_LINK_STATE_MODE
, inbuf
, sizeof(inbuf
),
718 NULL
, 0, NULL
); /* don't care what old mode was */
721 int efx_ef10_sriov_get_vf_config(struct efx_nic
*efx
, int vf_i
,
722 struct ifla_vf_info
*ivf
)
724 MCDI_DECLARE_BUF(inbuf
, MC_CMD_LINK_STATE_MODE_IN_LEN
);
725 MCDI_DECLARE_BUF(outbuf
, MC_CMD_LINK_STATE_MODE_OUT_LEN
);
727 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
732 if (vf_i
>= efx
->vf_count
)
738 vf
= nic_data
->vf
+ vf_i
;
741 ivf
->min_tx_rate
= 0;
742 ivf
->max_tx_rate
= 0;
743 ether_addr_copy(ivf
->mac
, vf
->mac
);
744 ivf
->vlan
= (vf
->vlan
== EFX_EF10_NO_VLAN
) ? 0 : vf
->vlan
;
747 MCDI_POPULATE_DWORD_2(inbuf
, LINK_STATE_MODE_IN_FUNCTION
,
748 LINK_STATE_MODE_IN_FUNCTION_PF
,
750 LINK_STATE_MODE_IN_FUNCTION_VF
, vf_i
);
751 MCDI_SET_DWORD(inbuf
, LINK_STATE_MODE_IN_NEW_MODE
,
752 MC_CMD_LINK_STATE_MODE_IN_DO_NOT_CHANGE
);
753 rc
= efx_mcdi_rpc(efx
, MC_CMD_LINK_STATE_MODE
, inbuf
, sizeof(inbuf
),
754 outbuf
, sizeof(outbuf
), &outlen
);
757 if (outlen
< MC_CMD_LINK_STATE_MODE_OUT_LEN
)
759 ivf
->linkstate
= MCDI_DWORD(outbuf
, LINK_STATE_MODE_OUT_OLD_MODE
);
764 int efx_ef10_sriov_get_phys_port_id(struct efx_nic
*efx
,
765 struct netdev_phys_item_id
*ppid
)
767 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
769 if (!is_valid_ether_addr(nic_data
->port_id
))
772 ppid
->id_len
= ETH_ALEN
;
773 memcpy(ppid
->id
, nic_data
->port_id
, ppid
->id_len
);