Skip to content

Commit 209f2f9

Browse files
bcreeley13anguy11
authored andcommitted
iavf: Add support for VIRTCHNL_VF_OFFLOAD_VLAN_V2 negotiation
In order to support the new VIRTCHNL_VF_OFFLOAD_VLAN_V2 capability the VF driver needs to rework it's initialization state machine and reset flow. This has to be done because successful negotiation of VIRTCHNL_VF_OFFLOAD_VLAN_V2 requires the VF driver to perform a second capability request via VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS before configuring the adapter and its netdev. Add the VIRTCHNL_VF_OFFLOAD_VLAN_V2 bit when sending the VIRTHCNL_OP_GET_VF_RESOURECES message. The underlying PF will either support VIRTCHNL_VF_OFFLOAD_VLAN or VIRTCHNL_VF_OFFLOAD_VLAN_V2 or neither. Both of these offloads should never be supported together. Based on this, add 2 new states to the initialization state machine: __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS __IAVF_INIT_CONFIG_ADAPTER The __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS state is used to request/store the new VLAN capabilities if and only if VIRTCHNL_VLAN_OFFLOAD_VLAN_V2 was successfully negotiated in the __IAVF_INIT_GET_RESOURCES state. The __IAVF_INIT_CONFIG_ADAPTER state is used to configure the adapter/netdev after the resource requests have finished. The VF will move into this state regardless of whether it successfully negotiated VIRTCHNL_VF_OFFLOAD_VLAN or VIRTCHNL_VF_OFFLOAD_VLAN_V2. Also, add a the new flag IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS and set it during VF reset. If VIRTCHNL_VF_OFFLOAD_VLAN_V2 was successfully negotiated then the VF will request its VLAN capabilities via VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS during the reset. This is needed because the PF may change/modify the VF's configuration during VF reset (i.e. modifying the VF's port VLAN configuration). This also, required the VF to call netdev_update_features() since its VLAN features may change during VF reset. Make sure to call this under rtnl_lock(). Signed-off-by: Brett Creeley <[email protected]> Tested-by: Konrad Jankowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent bd0b536 commit 209f2f9

File tree

3 files changed

+240
-52
lines changed

3 files changed

+240
-52
lines changed

drivers/net/ethernet/intel/iavf/iavf.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ enum iavf_state_t {
181181
__IAVF_REMOVE, /* driver is being unloaded */
182182
__IAVF_INIT_VERSION_CHECK, /* aq msg sent, awaiting reply */
183183
__IAVF_INIT_GET_RESOURCES, /* aq msg sent, awaiting reply */
184+
__IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS,
185+
__IAVF_INIT_CONFIG_ADAPTER,
184186
__IAVF_INIT_SW, /* got resources, setting up structs */
185187
__IAVF_INIT_FAILED, /* init failed, restarting procedure */
186188
__IAVF_RESETTING, /* in reset */
@@ -310,6 +312,7 @@ struct iavf_adapter {
310312
#define IAVF_FLAG_AQ_ADD_ADV_RSS_CFG BIT(27)
311313
#define IAVF_FLAG_AQ_DEL_ADV_RSS_CFG BIT(28)
312314
#define IAVF_FLAG_AQ_REQUEST_STATS BIT(29)
315+
#define IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS BIT(30)
313316

314317
/* OS defined structs */
315318
struct net_device *netdev;
@@ -349,6 +352,8 @@ struct iavf_adapter {
349352
VIRTCHNL_VF_OFFLOAD_RSS_PF)))
350353
#define VLAN_ALLOWED(_a) ((_a)->vf_res->vf_cap_flags & \
351354
VIRTCHNL_VF_OFFLOAD_VLAN)
355+
#define VLAN_V2_ALLOWED(_a) ((_a)->vf_res->vf_cap_flags & \
356+
VIRTCHNL_VF_OFFLOAD_VLAN_V2)
352357
#define ADV_LINK_SUPPORT(_a) ((_a)->vf_res->vf_cap_flags & \
353358
VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
354359
#define FDIR_FLTR_SUPPORT(_a) ((_a)->vf_res->vf_cap_flags & \
@@ -360,6 +365,7 @@ struct iavf_adapter {
360365
struct virtchnl_version_info pf_version;
361366
#define PF_IS_V11(_a) (((_a)->pf_version.major == 1) && \
362367
((_a)->pf_version.minor == 1))
368+
struct virtchnl_vlan_caps vlan_v2_caps;
363369
u16 msg_enable;
364370
struct iavf_eth_stats current_stats;
365371
struct iavf_vsi vsi;
@@ -448,6 +454,7 @@ static inline void iavf_change_state(struct iavf_adapter *adapter,
448454
int iavf_up(struct iavf_adapter *adapter);
449455
void iavf_down(struct iavf_adapter *adapter);
450456
int iavf_process_config(struct iavf_adapter *adapter);
457+
int iavf_parse_vf_resource_msg(struct iavf_adapter *adapter);
451458
void iavf_schedule_reset(struct iavf_adapter *adapter);
452459
void iavf_schedule_request_stats(struct iavf_adapter *adapter);
453460
void iavf_reset(struct iavf_adapter *adapter);
@@ -466,6 +473,8 @@ int iavf_send_api_ver(struct iavf_adapter *adapter);
466473
int iavf_verify_api_ver(struct iavf_adapter *adapter);
467474
int iavf_send_vf_config_msg(struct iavf_adapter *adapter);
468475
int iavf_get_vf_config(struct iavf_adapter *adapter);
476+
int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter);
477+
int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter);
469478
void iavf_irq_enable(struct iavf_adapter *adapter, bool flush);
470479
void iavf_configure_queues(struct iavf_adapter *adapter);
471480
void iavf_deconfigure_queues(struct iavf_adapter *adapter);

drivers/net/ethernet/intel/iavf/iavf_main.c

Lines changed: 154 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,8 @@ static int iavf_process_aq_command(struct iavf_adapter *adapter)
15841584
{
15851585
if (adapter->aq_required & IAVF_FLAG_AQ_GET_CONFIG)
15861586
return iavf_send_vf_config_msg(adapter);
1587+
if (adapter->aq_required & IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS)
1588+
return iavf_send_vf_offload_vlan_v2_msg(adapter);
15871589
if (adapter->aq_required & IAVF_FLAG_AQ_DISABLE_QUEUES) {
15881590
iavf_disable_queues(adapter);
15891591
return 0;
@@ -1826,6 +1828,59 @@ static void iavf_init_version_check(struct iavf_adapter *adapter)
18261828
iavf_change_state(adapter, __IAVF_INIT_FAILED);
18271829
}
18281830

1831+
/**
1832+
* iavf_parse_vf_resource_msg - parse response from VIRTCHNL_OP_GET_VF_RESOURCES
1833+
* @adapter: board private structure
1834+
*/
1835+
int iavf_parse_vf_resource_msg(struct iavf_adapter *adapter)
1836+
{
1837+
int i, num_req_queues = adapter->num_req_queues;
1838+
struct iavf_vsi *vsi = &adapter->vsi;
1839+
1840+
for (i = 0; i < adapter->vf_res->num_vsis; i++) {
1841+
if (adapter->vf_res->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
1842+
adapter->vsi_res = &adapter->vf_res->vsi_res[i];
1843+
}
1844+
if (!adapter->vsi_res) {
1845+
dev_err(&adapter->pdev->dev, "No LAN VSI found\n");
1846+
return -ENODEV;
1847+
}
1848+
1849+
if (num_req_queues &&
1850+
num_req_queues > adapter->vsi_res->num_queue_pairs) {
1851+
/* Problem. The PF gave us fewer queues than what we had
1852+
* negotiated in our request. Need a reset to see if we can't
1853+
* get back to a working state.
1854+
*/
1855+
dev_err(&adapter->pdev->dev,
1856+
"Requested %d queues, but PF only gave us %d.\n",
1857+
num_req_queues,
1858+
adapter->vsi_res->num_queue_pairs);
1859+
adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1860+
adapter->num_req_queues = adapter->vsi_res->num_queue_pairs;
1861+
iavf_schedule_reset(adapter);
1862+
1863+
return -EAGAIN;
1864+
}
1865+
adapter->num_req_queues = 0;
1866+
adapter->vsi.id = adapter->vsi_res->vsi_id;
1867+
1868+
adapter->vsi.back = adapter;
1869+
adapter->vsi.base_vector = 1;
1870+
adapter->vsi.work_limit = IAVF_DEFAULT_IRQ_WORK;
1871+
vsi->netdev = adapter->netdev;
1872+
vsi->qs_handle = adapter->vsi_res->qset_handle;
1873+
if (adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
1874+
adapter->rss_key_size = adapter->vf_res->rss_key_size;
1875+
adapter->rss_lut_size = adapter->vf_res->rss_lut_size;
1876+
} else {
1877+
adapter->rss_key_size = IAVF_HKEY_ARRAY_SIZE;
1878+
adapter->rss_lut_size = IAVF_HLUT_ARRAY_SIZE;
1879+
}
1880+
1881+
return 0;
1882+
}
1883+
18291884
/**
18301885
* iavf_init_get_resources - third step of driver startup
18311886
* @adapter: board private structure
@@ -1837,7 +1892,6 @@ static void iavf_init_version_check(struct iavf_adapter *adapter)
18371892
**/
18381893
static void iavf_init_get_resources(struct iavf_adapter *adapter)
18391894
{
1840-
struct net_device *netdev = adapter->netdev;
18411895
struct pci_dev *pdev = adapter->pdev;
18421896
struct iavf_hw *hw = &adapter->hw;
18431897
int err;
@@ -1855,7 +1909,7 @@ static void iavf_init_get_resources(struct iavf_adapter *adapter)
18551909
err = iavf_get_vf_config(adapter);
18561910
if (err == IAVF_ERR_ADMIN_QUEUE_NO_WORK) {
18571911
err = iavf_send_vf_config_msg(adapter);
1858-
goto err;
1912+
goto err_alloc;
18591913
} else if (err == IAVF_ERR_PARAM) {
18601914
/* We only get ERR_PARAM if the device is in a very bad
18611915
* state or if we've been disabled for previous bad
@@ -1870,9 +1924,83 @@ static void iavf_init_get_resources(struct iavf_adapter *adapter)
18701924
goto err_alloc;
18711925
}
18721926

1873-
err = iavf_process_config(adapter);
1927+
err = iavf_parse_vf_resource_msg(adapter);
18741928
if (err)
18751929
goto err_alloc;
1930+
1931+
err = iavf_send_vf_offload_vlan_v2_msg(adapter);
1932+
if (err == -EOPNOTSUPP) {
1933+
/* underlying PF doesn't support VIRTCHNL_VF_OFFLOAD_VLAN_V2, so
1934+
* go directly to finishing initialization
1935+
*/
1936+
iavf_change_state(adapter, __IAVF_INIT_CONFIG_ADAPTER);
1937+
return;
1938+
} else if (err) {
1939+
dev_err(&pdev->dev, "Unable to send offload vlan v2 request (%d)\n",
1940+
err);
1941+
goto err_alloc;
1942+
}
1943+
1944+
/* underlying PF supports VIRTCHNL_VF_OFFLOAD_VLAN_V2, so update the
1945+
* state accordingly
1946+
*/
1947+
iavf_change_state(adapter, __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS);
1948+
return;
1949+
1950+
err_alloc:
1951+
kfree(adapter->vf_res);
1952+
adapter->vf_res = NULL;
1953+
err:
1954+
iavf_change_state(adapter, __IAVF_INIT_FAILED);
1955+
}
1956+
1957+
/**
1958+
* iavf_init_get_offload_vlan_v2_caps - part of driver startup
1959+
* @adapter: board private structure
1960+
*
1961+
* Function processes __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS driver state if the
1962+
* VF negotiates VIRTCHNL_VF_OFFLOAD_VLAN_V2. If VIRTCHNL_VF_OFFLOAD_VLAN_V2 is
1963+
* not negotiated, then this state will never be entered.
1964+
**/
1965+
static void iavf_init_get_offload_vlan_v2_caps(struct iavf_adapter *adapter)
1966+
{
1967+
int ret;
1968+
1969+
WARN_ON(adapter->state != __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS);
1970+
1971+
memset(&adapter->vlan_v2_caps, 0, sizeof(adapter->vlan_v2_caps));
1972+
1973+
ret = iavf_get_vf_vlan_v2_caps(adapter);
1974+
if (ret) {
1975+
if (ret == IAVF_ERR_ADMIN_QUEUE_NO_WORK)
1976+
iavf_send_vf_offload_vlan_v2_msg(adapter);
1977+
goto err;
1978+
}
1979+
1980+
iavf_change_state(adapter, __IAVF_INIT_CONFIG_ADAPTER);
1981+
return;
1982+
err:
1983+
iavf_change_state(adapter, __IAVF_INIT_FAILED);
1984+
}
1985+
1986+
/**
1987+
* iavf_init_config_adapter - last part of driver startup
1988+
* @adapter: board private structure
1989+
*
1990+
* After all the supported capabilities are negotiated, then the
1991+
* __IAVF_INIT_CONFIG_ADAPTER state will finish driver initialization.
1992+
*/
1993+
static void iavf_init_config_adapter(struct iavf_adapter *adapter)
1994+
{
1995+
struct net_device *netdev = adapter->netdev;
1996+
struct pci_dev *pdev = adapter->pdev;
1997+
int err;
1998+
1999+
WARN_ON(adapter->state != __IAVF_INIT_CONFIG_ADAPTER);
2000+
2001+
if (iavf_process_config(adapter))
2002+
goto err;
2003+
18762004
adapter->current_op = VIRTCHNL_OP_UNKNOWN;
18772005

18782006
adapter->flags |= IAVF_FLAG_RX_CSUM_ENABLED;
@@ -1962,9 +2090,6 @@ static void iavf_init_get_resources(struct iavf_adapter *adapter)
19622090
iavf_free_misc_irq(adapter);
19632091
err_sw_init:
19642092
iavf_reset_interrupt_capability(adapter);
1965-
err_alloc:
1966-
kfree(adapter->vf_res);
1967-
adapter->vf_res = NULL;
19682093
err:
19692094
iavf_change_state(adapter, __IAVF_INIT_FAILED);
19702095
}
@@ -2013,6 +2138,18 @@ static void iavf_watchdog_task(struct work_struct *work)
20132138
queue_delayed_work(iavf_wq, &adapter->watchdog_task,
20142139
msecs_to_jiffies(1));
20152140
return;
2141+
case __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS:
2142+
iavf_init_get_offload_vlan_v2_caps(adapter);
2143+
mutex_unlock(&adapter->crit_lock);
2144+
queue_delayed_work(iavf_wq, &adapter->watchdog_task,
2145+
msecs_to_jiffies(1));
2146+
return;
2147+
case __IAVF_INIT_CONFIG_ADAPTER:
2148+
iavf_init_config_adapter(adapter);
2149+
mutex_unlock(&adapter->crit_lock);
2150+
queue_delayed_work(iavf_wq, &adapter->watchdog_task,
2151+
msecs_to_jiffies(1));
2152+
return;
20162153
case __IAVF_INIT_FAILED:
20172154
if (++adapter->aq_wait_count > IAVF_AQ_MAX_ERR) {
20182155
dev_err(&adapter->pdev->dev,
@@ -2066,10 +2203,13 @@ static void iavf_watchdog_task(struct work_struct *work)
20662203
iavf_send_api_ver(adapter);
20672204
}
20682205
} else {
2206+
int ret = iavf_process_aq_command(adapter);
2207+
20692208
/* An error will be returned if no commands were
20702209
* processed; use this opportunity to update stats
2210+
* if the error isn't -ENOTSUPP
20712211
*/
2072-
if (iavf_process_aq_command(adapter) &&
2212+
if (ret && ret != -EOPNOTSUPP &&
20732213
adapter->state == __IAVF_RUNNING)
20742214
iavf_request_stats(adapter);
20752215
}
@@ -2308,6 +2448,13 @@ static void iavf_reset_task(struct work_struct *work)
23082448
}
23092449

23102450
adapter->aq_required |= IAVF_FLAG_AQ_GET_CONFIG;
2451+
/* always set since VIRTCHNL_OP_GET_VF_RESOURCES has not been
2452+
* sent/received yet, so VLAN_V2_ALLOWED() cannot is not reliable here,
2453+
* however the VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS won't be sent until
2454+
* VIRTCHNL_OP_GET_VF_RESOURCES and VIRTCHNL_VF_OFFLOAD_VLAN_V2 have
2455+
* been successfully sent and negotiated
2456+
*/
2457+
adapter->aq_required |= IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS;
23112458
adapter->aq_required |= IAVF_FLAG_AQ_MAP_VECTORS;
23122459

23132460
spin_lock_bh(&adapter->mac_vlan_list_lock);
@@ -3603,39 +3750,10 @@ static int iavf_check_reset_complete(struct iavf_hw *hw)
36033750
int iavf_process_config(struct iavf_adapter *adapter)
36043751
{
36053752
struct virtchnl_vf_resource *vfres = adapter->vf_res;
3606-
int i, num_req_queues = adapter->num_req_queues;
36073753
struct net_device *netdev = adapter->netdev;
3608-
struct iavf_vsi *vsi = &adapter->vsi;
36093754
netdev_features_t hw_enc_features;
36103755
netdev_features_t hw_features;
36113756

3612-
/* got VF config message back from PF, now we can parse it */
3613-
for (i = 0; i < vfres->num_vsis; i++) {
3614-
if (vfres->vsi_res[i].vsi_type == VIRTCHNL_VSI_SRIOV)
3615-
adapter->vsi_res = &vfres->vsi_res[i];
3616-
}
3617-
if (!adapter->vsi_res) {
3618-
dev_err(&adapter->pdev->dev, "No LAN VSI found\n");
3619-
return -ENODEV;
3620-
}
3621-
3622-
if (num_req_queues &&
3623-
num_req_queues > adapter->vsi_res->num_queue_pairs) {
3624-
/* Problem. The PF gave us fewer queues than what we had
3625-
* negotiated in our request. Need a reset to see if we can't
3626-
* get back to a working state.
3627-
*/
3628-
dev_err(&adapter->pdev->dev,
3629-
"Requested %d queues, but PF only gave us %d.\n",
3630-
num_req_queues,
3631-
adapter->vsi_res->num_queue_pairs);
3632-
adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
3633-
adapter->num_req_queues = adapter->vsi_res->num_queue_pairs;
3634-
iavf_schedule_reset(adapter);
3635-
return -ENODEV;
3636-
}
3637-
adapter->num_req_queues = 0;
3638-
36393757
hw_enc_features = NETIF_F_SG |
36403758
NETIF_F_IP_CSUM |
36413759
NETIF_F_IPV6_CSUM |
@@ -3716,21 +3834,6 @@ int iavf_process_config(struct iavf_adapter *adapter)
37163834
netdev->features &= ~NETIF_F_GSO;
37173835
}
37183836

3719-
adapter->vsi.id = adapter->vsi_res->vsi_id;
3720-
3721-
adapter->vsi.back = adapter;
3722-
adapter->vsi.base_vector = 1;
3723-
adapter->vsi.work_limit = IAVF_DEFAULT_IRQ_WORK;
3724-
vsi->netdev = adapter->netdev;
3725-
vsi->qs_handle = adapter->vsi_res->qset_handle;
3726-
if (vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
3727-
adapter->rss_key_size = vfres->rss_key_size;
3728-
adapter->rss_lut_size = vfres->rss_lut_size;
3729-
} else {
3730-
adapter->rss_key_size = IAVF_HKEY_ARRAY_SIZE;
3731-
adapter->rss_lut_size = IAVF_HLUT_ARRAY_SIZE;
3732-
}
3733-
37343837
return 0;
37353838
}
37363839

0 commit comments

Comments
 (0)