Commit 87dba256 authored by Mateusz Palczewski's avatar Mateusz Palczewski Committed by Tony Nguyen

iavf: refactor processing of VLAN V2 capability message

In order to handle the capability exchange necessary for
VIRTCHNL_VF_OFFLOAD_VLAN_V2, the driver must send
a VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS message. This must occur prior to
__IAVF_CONFIG_ADAPTER, and the driver must wait for the response from
the PF.

To handle this, the __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS state was
introduced. This state is intended to process the response from the VLAN
V2 caps message. This works ok, but is difficult to extend to adding
more extended capability exchange.

Existing (and future) AVF features are relying more and more on these
sort of extended ops for processing additional capabilities. Just like
VLAN V2, this exchange must happen prior to __IAVF_CONFIG_ADPATER.

Since we only send one outstanding AQ message at a time during init, it
is not clear where to place this state. Adding more capability specific
states becomes a mess. Instead of having the "previous" state send
a message and then transition into a capability-specific state,
introduce __IAVF_EXTENDED_CAPS state. This state will use a list of
extended_caps that determines what messages to send and receive. As long
as there are extended_caps bits still set, the driver will remain in
this state performing one send or one receive per state machine loop.

Refactor the VLAN V2 negotiation to use this new state, and remove the
capability-specific state. This makes it significantly easier to add
a new similar capability exchange going forward.

Extended capabilities are processed by having an associated SEND and
RECV extended capability bit. During __IAVF_EXTENDED_CAPS, the
driver checks these bits in order by feature, first the send bit for
a feature, then the recv bit for a feature. Each send flag will call
a function that sends the necessary response, while each receive flag
will wait for the response from the PF. If a given feature can't be
negotiated with the PF, the associated flags will be cleared in
order to skip processing of that feature.
Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Signed-off-by: default avatarMateusz Palczewski <mateusz.palczewski@intel.com>
Tested-by: default avatarKonrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent d73dd127
...@@ -188,7 +188,7 @@ enum iavf_state_t { ...@@ -188,7 +188,7 @@ enum iavf_state_t {
__IAVF_REMOVE, /* driver is being unloaded */ __IAVF_REMOVE, /* driver is being unloaded */
__IAVF_INIT_VERSION_CHECK, /* aq msg sent, awaiting reply */ __IAVF_INIT_VERSION_CHECK, /* aq msg sent, awaiting reply */
__IAVF_INIT_GET_RESOURCES, /* aq msg sent, awaiting reply */ __IAVF_INIT_GET_RESOURCES, /* aq msg sent, awaiting reply */
__IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS, __IAVF_INIT_EXTENDED_CAPS, /* process extended caps which require aq msg exchange */
__IAVF_INIT_CONFIG_ADAPTER, __IAVF_INIT_CONFIG_ADAPTER,
__IAVF_INIT_SW, /* got resources, setting up structs */ __IAVF_INIT_SW, /* got resources, setting up structs */
__IAVF_INIT_FAILED, /* init failed, restarting procedure */ __IAVF_INIT_FAILED, /* init failed, restarting procedure */
...@@ -329,6 +329,21 @@ struct iavf_adapter { ...@@ -329,6 +329,21 @@ struct iavf_adapter {
#define IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION BIT_ULL(37) #define IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION BIT_ULL(37)
#define IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION BIT_ULL(38) #define IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION BIT_ULL(38)
/* flags for processing extended capability messages during
* __IAVF_INIT_EXTENDED_CAPS. Each capability exchange requires
* both a SEND and a RECV step, which must be processed in sequence.
*
* During the __IAVF_INIT_EXTENDED_CAPS state, the driver will
* process one flag at a time during each state loop.
*/
u64 extended_caps;
#define IAVF_EXTENDED_CAP_SEND_VLAN_V2 BIT_ULL(0)
#define IAVF_EXTENDED_CAP_RECV_VLAN_V2 BIT_ULL(1)
#define IAVF_EXTENDED_CAPS \
(IAVF_EXTENDED_CAP_SEND_VLAN_V2 | \
IAVF_EXTENDED_CAP_RECV_VLAN_V2)
/* OS defined structs */ /* OS defined structs */
struct net_device *netdev; struct net_device *netdev;
struct pci_dev *pdev; struct pci_dev *pdev;
......
...@@ -2189,26 +2189,18 @@ static void iavf_init_get_resources(struct iavf_adapter *adapter) ...@@ -2189,26 +2189,18 @@ static void iavf_init_get_resources(struct iavf_adapter *adapter)
} }
err = iavf_parse_vf_resource_msg(adapter); err = iavf_parse_vf_resource_msg(adapter);
if (err) if (err) {
goto err_alloc; dev_err(&pdev->dev, "Failed to parse VF resource message from PF (%d)\n",
err = iavf_send_vf_offload_vlan_v2_msg(adapter);
if (err == -EOPNOTSUPP) {
/* underlying PF doesn't support VIRTCHNL_VF_OFFLOAD_VLAN_V2, so
* go directly to finishing initialization
*/
iavf_change_state(adapter, __IAVF_INIT_CONFIG_ADAPTER);
return;
} else if (err) {
dev_err(&pdev->dev, "Unable to send offload vlan v2 request (%d)\n",
err); err);
goto err_alloc; goto err_alloc;
} }
/* Some features require additional messages to negotiate extended
/* underlying PF supports VIRTCHNL_VF_OFFLOAD_VLAN_V2, so update the * capabilities. These are processed in sequence by the
* state accordingly * __IAVF_INIT_EXTENDED_CAPS driver state.
*/ */
iavf_change_state(adapter, __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS); adapter->extended_caps = IAVF_EXTENDED_CAPS;
iavf_change_state(adapter, __IAVF_INIT_EXTENDED_CAPS);
return; return;
err_alloc: err_alloc:
...@@ -2219,34 +2211,92 @@ static void iavf_init_get_resources(struct iavf_adapter *adapter) ...@@ -2219,34 +2211,92 @@ static void iavf_init_get_resources(struct iavf_adapter *adapter)
} }
/** /**
* iavf_init_get_offload_vlan_v2_caps - part of driver startup * iavf_init_send_offload_vlan_v2_caps - part of initializing VLAN V2 caps
* @adapter: board private structure
*
* Function processes send of the extended VLAN V2 capability message to the
* PF. Must clear IAVF_EXTENDED_CAP_RECV_VLAN_V2 if the message is not sent,
* e.g. due to PF not negotiating VIRTCHNL_VF_OFFLOAD_VLAN_V2.
*/
static void iavf_init_send_offload_vlan_v2_caps(struct iavf_adapter *adapter)
{
int ret;
WARN_ON(!(adapter->extended_caps & IAVF_EXTENDED_CAP_SEND_VLAN_V2));
ret = iavf_send_vf_offload_vlan_v2_msg(adapter);
if (ret && ret == -EOPNOTSUPP) {
/* PF does not support VIRTCHNL_VF_OFFLOAD_V2. In this case,
* we did not send the capability exchange message and do not
* expect a response.
*/
adapter->extended_caps &= ~IAVF_EXTENDED_CAP_RECV_VLAN_V2;
}
/* We sent the message, so move on to the next step */
adapter->extended_caps &= ~IAVF_EXTENDED_CAP_SEND_VLAN_V2;
}
/**
* iavf_init_recv_offload_vlan_v2_caps - part of initializing VLAN V2 caps
* @adapter: board private structure * @adapter: board private structure
* *
* Function processes __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS driver state if the * Function processes receipt of the extended VLAN V2 capability message from
* VF negotiates VIRTCHNL_VF_OFFLOAD_VLAN_V2. If VIRTCHNL_VF_OFFLOAD_VLAN_V2 is * the PF.
* not negotiated, then this state will never be entered.
**/ **/
static void iavf_init_get_offload_vlan_v2_caps(struct iavf_adapter *adapter) static void iavf_init_recv_offload_vlan_v2_caps(struct iavf_adapter *adapter)
{ {
int ret; int ret;
WARN_ON(adapter->state != __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS); WARN_ON(!(adapter->extended_caps & IAVF_EXTENDED_CAP_RECV_VLAN_V2));
memset(&adapter->vlan_v2_caps, 0, sizeof(adapter->vlan_v2_caps)); memset(&adapter->vlan_v2_caps, 0, sizeof(adapter->vlan_v2_caps));
ret = iavf_get_vf_vlan_v2_caps(adapter); ret = iavf_get_vf_vlan_v2_caps(adapter);
if (ret) { if (ret)
if (ret == IAVF_ERR_ADMIN_QUEUE_NO_WORK)
iavf_send_vf_offload_vlan_v2_msg(adapter);
goto err; goto err;
}
iavf_change_state(adapter, __IAVF_INIT_CONFIG_ADAPTER); /* We've processed receipt of the VLAN V2 caps message */
adapter->extended_caps &= ~IAVF_EXTENDED_CAP_RECV_VLAN_V2;
return; return;
err: err:
/* We didn't receive a reply. Make sure we try sending again when
* __IAVF_INIT_FAILED attempts to recover.
*/
adapter->extended_caps |= IAVF_EXTENDED_CAP_SEND_VLAN_V2;
iavf_change_state(adapter, __IAVF_INIT_FAILED); iavf_change_state(adapter, __IAVF_INIT_FAILED);
} }
/**
* iavf_init_process_extended_caps - Part of driver startup
* @adapter: board private structure
*
* Function processes __IAVF_INIT_EXTENDED_CAPS driver state. This state
* handles negotiating capabilities for features which require an additional
* message.
*
* Once all extended capabilities exchanges are finished, the driver will
* transition into __IAVF_INIT_CONFIG_ADAPTER.
*/
static void iavf_init_process_extended_caps(struct iavf_adapter *adapter)
{
WARN_ON(adapter->state != __IAVF_INIT_EXTENDED_CAPS);
/* Process capability exchange for VLAN V2 */
if (adapter->extended_caps & IAVF_EXTENDED_CAP_SEND_VLAN_V2) {
iavf_init_send_offload_vlan_v2_caps(adapter);
return;
} else if (adapter->extended_caps & IAVF_EXTENDED_CAP_RECV_VLAN_V2) {
iavf_init_recv_offload_vlan_v2_caps(adapter);
return;
}
/* When we reach here, no further extended capabilities exchanges are
* necessary, so we finally transition into __IAVF_INIT_CONFIG_ADAPTER
*/
iavf_change_state(adapter, __IAVF_INIT_CONFIG_ADAPTER);
}
/** /**
* iavf_init_config_adapter - last part of driver startup * iavf_init_config_adapter - last part of driver startup
* @adapter: board private structure * @adapter: board private structure
...@@ -2406,8 +2456,8 @@ static void iavf_watchdog_task(struct work_struct *work) ...@@ -2406,8 +2456,8 @@ static void iavf_watchdog_task(struct work_struct *work)
queue_delayed_work(iavf_wq, &adapter->watchdog_task, queue_delayed_work(iavf_wq, &adapter->watchdog_task,
msecs_to_jiffies(1)); msecs_to_jiffies(1));
return; return;
case __IAVF_INIT_GET_OFFLOAD_VLAN_V2_CAPS: case __IAVF_INIT_EXTENDED_CAPS:
iavf_init_get_offload_vlan_v2_caps(adapter); iavf_init_process_extended_caps(adapter);
mutex_unlock(&adapter->crit_lock); mutex_unlock(&adapter->crit_lock);
queue_delayed_work(iavf_wq, &adapter->watchdog_task, queue_delayed_work(iavf_wq, &adapter->watchdog_task,
msecs_to_jiffies(1)); msecs_to_jiffies(1));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment