Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright(c) 2013 - 2018 Intel Corporation. */
0003 
0004 #include "iavf.h"
0005 #include "iavf_prototype.h"
0006 #include "iavf_client.h"
0007 
0008 /**
0009  * iavf_send_pf_msg
0010  * @adapter: adapter structure
0011  * @op: virtual channel opcode
0012  * @msg: pointer to message buffer
0013  * @len: message length
0014  *
0015  * Send message to PF and print status if failure.
0016  **/
0017 static int iavf_send_pf_msg(struct iavf_adapter *adapter,
0018                 enum virtchnl_ops op, u8 *msg, u16 len)
0019 {
0020     struct iavf_hw *hw = &adapter->hw;
0021     enum iavf_status status;
0022 
0023     if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
0024         return 0; /* nothing to see here, move along */
0025 
0026     status = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
0027     if (status)
0028         dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, status %s, aq_err %s\n",
0029             op, iavf_stat_str(hw, status),
0030             iavf_aq_str(hw, hw->aq.asq_last_status));
0031     return iavf_status_to_errno(status);
0032 }
0033 
0034 /**
0035  * iavf_send_api_ver
0036  * @adapter: adapter structure
0037  *
0038  * Send API version admin queue message to the PF. The reply is not checked
0039  * in this function. Returns 0 if the message was successfully
0040  * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
0041  **/
0042 int iavf_send_api_ver(struct iavf_adapter *adapter)
0043 {
0044     struct virtchnl_version_info vvi;
0045 
0046     vvi.major = VIRTCHNL_VERSION_MAJOR;
0047     vvi.minor = VIRTCHNL_VERSION_MINOR;
0048 
0049     return iavf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
0050                 sizeof(vvi));
0051 }
0052 
0053 /**
0054  * iavf_poll_virtchnl_msg
0055  * @hw: HW configuration structure
0056  * @event: event to populate on success
0057  * @op_to_poll: requested virtchnl op to poll for
0058  *
0059  * Initialize poll for virtchnl msg matching the requested_op. Returns 0
0060  * if a message of the correct opcode is in the queue or an error code
0061  * if no message matching the op code is waiting and other failures.
0062  */
0063 static int
0064 iavf_poll_virtchnl_msg(struct iavf_hw *hw, struct iavf_arq_event_info *event,
0065                enum virtchnl_ops op_to_poll)
0066 {
0067     enum virtchnl_ops received_op;
0068     enum iavf_status status;
0069     u32 v_retval;
0070 
0071     while (1) {
0072         /* When the AQ is empty, iavf_clean_arq_element will return
0073          * nonzero and this loop will terminate.
0074          */
0075         status = iavf_clean_arq_element(hw, event, NULL);
0076         if (status != IAVF_SUCCESS)
0077             return iavf_status_to_errno(status);
0078         received_op =
0079             (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high);
0080         if (op_to_poll == received_op)
0081             break;
0082     }
0083 
0084     v_retval = le32_to_cpu(event->desc.cookie_low);
0085     return virtchnl_status_to_errno((enum virtchnl_status_code)v_retval);
0086 }
0087 
0088 /**
0089  * iavf_verify_api_ver
0090  * @adapter: adapter structure
0091  *
0092  * Compare API versions with the PF. Must be called after admin queue is
0093  * initialized. Returns 0 if API versions match, -EIO if they do not,
0094  * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
0095  * from the firmware are propagated.
0096  **/
0097 int iavf_verify_api_ver(struct iavf_adapter *adapter)
0098 {
0099     struct iavf_arq_event_info event;
0100     int err;
0101 
0102     event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
0103     event.msg_buf = kzalloc(IAVF_MAX_AQ_BUF_SIZE, GFP_KERNEL);
0104     if (!event.msg_buf)
0105         return -ENOMEM;
0106 
0107     err = iavf_poll_virtchnl_msg(&adapter->hw, &event, VIRTCHNL_OP_VERSION);
0108     if (!err) {
0109         struct virtchnl_version_info *pf_vvi =
0110             (struct virtchnl_version_info *)event.msg_buf;
0111         adapter->pf_version = *pf_vvi;
0112 
0113         if (pf_vvi->major > VIRTCHNL_VERSION_MAJOR ||
0114             (pf_vvi->major == VIRTCHNL_VERSION_MAJOR &&
0115              pf_vvi->minor > VIRTCHNL_VERSION_MINOR))
0116             err = -EIO;
0117     }
0118 
0119     kfree(event.msg_buf);
0120 
0121     return err;
0122 }
0123 
0124 /**
0125  * iavf_send_vf_config_msg
0126  * @adapter: adapter structure
0127  *
0128  * Send VF configuration request admin queue message to the PF. The reply
0129  * is not checked in this function. Returns 0 if the message was
0130  * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
0131  **/
0132 int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
0133 {
0134     u32 caps;
0135 
0136     caps = VIRTCHNL_VF_OFFLOAD_L2 |
0137            VIRTCHNL_VF_OFFLOAD_RSS_PF |
0138            VIRTCHNL_VF_OFFLOAD_RSS_AQ |
0139            VIRTCHNL_VF_OFFLOAD_RSS_REG |
0140            VIRTCHNL_VF_OFFLOAD_VLAN |
0141            VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
0142            VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
0143            VIRTCHNL_VF_OFFLOAD_ENCAP |
0144            VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
0145            VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
0146            VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
0147            VIRTCHNL_VF_OFFLOAD_ADQ |
0148            VIRTCHNL_VF_OFFLOAD_USO |
0149            VIRTCHNL_VF_OFFLOAD_FDIR_PF |
0150            VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
0151            VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
0152 
0153     adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
0154     adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG;
0155     if (PF_IS_V11(adapter))
0156         return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
0157                     (u8 *)&caps, sizeof(caps));
0158     else
0159         return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
0160                     NULL, 0);
0161 }
0162 
0163 int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter)
0164 {
0165     adapter->aq_required &= ~IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS;
0166 
0167     if (!VLAN_V2_ALLOWED(adapter))
0168         return -EOPNOTSUPP;
0169 
0170     adapter->current_op = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
0171 
0172     return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
0173                 NULL, 0);
0174 }
0175 
0176 /**
0177  * iavf_validate_num_queues
0178  * @adapter: adapter structure
0179  *
0180  * Validate that the number of queues the PF has sent in
0181  * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
0182  **/
0183 static void iavf_validate_num_queues(struct iavf_adapter *adapter)
0184 {
0185     if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) {
0186         struct virtchnl_vsi_resource *vsi_res;
0187         int i;
0188 
0189         dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n",
0190              adapter->vf_res->num_queue_pairs,
0191              IAVF_MAX_REQ_QUEUES);
0192         dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n",
0193              IAVF_MAX_REQ_QUEUES);
0194         adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
0195         for (i = 0; i < adapter->vf_res->num_vsis; i++) {
0196             vsi_res = &adapter->vf_res->vsi_res[i];
0197             vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
0198         }
0199     }
0200 }
0201 
0202 /**
0203  * iavf_get_vf_config
0204  * @adapter: private adapter structure
0205  *
0206  * Get VF configuration from PF and populate hw structure. Must be called after
0207  * admin queue is initialized. Busy waits until response is received from PF,
0208  * with maximum timeout. Response from PF is returned in the buffer for further
0209  * processing by the caller.
0210  **/
0211 int iavf_get_vf_config(struct iavf_adapter *adapter)
0212 {
0213     struct iavf_hw *hw = &adapter->hw;
0214     struct iavf_arq_event_info event;
0215     u16 len;
0216     int err;
0217 
0218     len = sizeof(struct virtchnl_vf_resource) +
0219         IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
0220     event.buf_len = len;
0221     event.msg_buf = kzalloc(len, GFP_KERNEL);
0222     if (!event.msg_buf)
0223         return -ENOMEM;
0224 
0225     err = iavf_poll_virtchnl_msg(hw, &event, VIRTCHNL_OP_GET_VF_RESOURCES);
0226     memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
0227 
0228     /* some PFs send more queues than we should have so validate that
0229      * we aren't getting too many queues
0230      */
0231     if (!err)
0232         iavf_validate_num_queues(adapter);
0233     iavf_vf_parse_hw_config(hw, adapter->vf_res);
0234 
0235     kfree(event.msg_buf);
0236 
0237     return err;
0238 }
0239 
0240 int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter)
0241 {
0242     struct iavf_arq_event_info event;
0243     int err;
0244     u16 len;
0245 
0246     len = sizeof(struct virtchnl_vlan_caps);
0247     event.buf_len = len;
0248     event.msg_buf = kzalloc(len, GFP_KERNEL);
0249     if (!event.msg_buf)
0250         return -ENOMEM;
0251 
0252     err = iavf_poll_virtchnl_msg(&adapter->hw, &event,
0253                      VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS);
0254     if (!err)
0255         memcpy(&adapter->vlan_v2_caps, event.msg_buf,
0256                min(event.msg_len, len));
0257 
0258     kfree(event.msg_buf);
0259 
0260     return err;
0261 }
0262 
0263 /**
0264  * iavf_configure_queues
0265  * @adapter: adapter structure
0266  *
0267  * Request that the PF set up our (previously allocated) queues.
0268  **/
0269 void iavf_configure_queues(struct iavf_adapter *adapter)
0270 {
0271     struct virtchnl_vsi_queue_config_info *vqci;
0272     int i, max_frame = adapter->vf_res->max_mtu;
0273     int pairs = adapter->num_active_queues;
0274     struct virtchnl_queue_pair_info *vqpi;
0275     size_t len;
0276 
0277     if (max_frame > IAVF_MAX_RXBUFFER || !max_frame)
0278         max_frame = IAVF_MAX_RXBUFFER;
0279 
0280     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
0281         /* bail because we already have a command pending */
0282         dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
0283             adapter->current_op);
0284         return;
0285     }
0286     adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
0287     len = struct_size(vqci, qpair, pairs);
0288     vqci = kzalloc(len, GFP_KERNEL);
0289     if (!vqci)
0290         return;
0291 
0292     /* Limit maximum frame size when jumbo frames is not enabled */
0293     if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) &&
0294         (adapter->netdev->mtu <= ETH_DATA_LEN))
0295         max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN;
0296 
0297     vqci->vsi_id = adapter->vsi_res->vsi_id;
0298     vqci->num_queue_pairs = pairs;
0299     vqpi = vqci->qpair;
0300     /* Size check is not needed here - HW max is 16 queue pairs, and we
0301      * can fit info for 31 of them into the AQ buffer before it overflows.
0302      */
0303     for (i = 0; i < pairs; i++) {
0304         vqpi->txq.vsi_id = vqci->vsi_id;
0305         vqpi->txq.queue_id = i;
0306         vqpi->txq.ring_len = adapter->tx_rings[i].count;
0307         vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
0308         vqpi->rxq.vsi_id = vqci->vsi_id;
0309         vqpi->rxq.queue_id = i;
0310         vqpi->rxq.ring_len = adapter->rx_rings[i].count;
0311         vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
0312         vqpi->rxq.max_pkt_size = max_frame;
0313         vqpi->rxq.databuffer_size =
0314             ALIGN(adapter->rx_rings[i].rx_buf_len,
0315                   BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT));
0316         vqpi++;
0317     }
0318 
0319     adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
0320     iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
0321              (u8 *)vqci, len);
0322     kfree(vqci);
0323 }
0324 
0325 /**
0326  * iavf_enable_queues
0327  * @adapter: adapter structure
0328  *
0329  * Request that the PF enable all of our queues.
0330  **/
0331 void iavf_enable_queues(struct iavf_adapter *adapter)
0332 {
0333     struct virtchnl_queue_select vqs;
0334 
0335     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
0336         /* bail because we already have a command pending */
0337         dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
0338             adapter->current_op);
0339         return;
0340     }
0341     adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
0342     vqs.vsi_id = adapter->vsi_res->vsi_id;
0343     vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
0344     vqs.rx_queues = vqs.tx_queues;
0345     adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
0346     iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
0347              (u8 *)&vqs, sizeof(vqs));
0348 }
0349 
0350 /**
0351  * iavf_disable_queues
0352  * @adapter: adapter structure
0353  *
0354  * Request that the PF disable all of our queues.
0355  **/
0356 void iavf_disable_queues(struct iavf_adapter *adapter)
0357 {
0358     struct virtchnl_queue_select vqs;
0359 
0360     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
0361         /* bail because we already have a command pending */
0362         dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
0363             adapter->current_op);
0364         return;
0365     }
0366     adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
0367     vqs.vsi_id = adapter->vsi_res->vsi_id;
0368     vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
0369     vqs.rx_queues = vqs.tx_queues;
0370     adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
0371     iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
0372              (u8 *)&vqs, sizeof(vqs));
0373 }
0374 
0375 /**
0376  * iavf_map_queues
0377  * @adapter: adapter structure
0378  *
0379  * Request that the PF map queues to interrupt vectors. Misc causes, including
0380  * admin queue, are always mapped to vector 0.
0381  **/
0382 void iavf_map_queues(struct iavf_adapter *adapter)
0383 {
0384     struct virtchnl_irq_map_info *vimi;
0385     struct virtchnl_vector_map *vecmap;
0386     struct iavf_q_vector *q_vector;
0387     int v_idx, q_vectors;
0388     size_t len;
0389 
0390     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
0391         /* bail because we already have a command pending */
0392         dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
0393             adapter->current_op);
0394         return;
0395     }
0396     adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
0397 
0398     q_vectors = adapter->num_msix_vectors - NONQ_VECS;
0399 
0400     len = struct_size(vimi, vecmap, adapter->num_msix_vectors);
0401     vimi = kzalloc(len, GFP_KERNEL);
0402     if (!vimi)
0403         return;
0404 
0405     vimi->num_vectors = adapter->num_msix_vectors;
0406     /* Queue vectors first */
0407     for (v_idx = 0; v_idx < q_vectors; v_idx++) {
0408         q_vector = &adapter->q_vectors[v_idx];
0409         vecmap = &vimi->vecmap[v_idx];
0410 
0411         vecmap->vsi_id = adapter->vsi_res->vsi_id;
0412         vecmap->vector_id = v_idx + NONQ_VECS;
0413         vecmap->txq_map = q_vector->ring_mask;
0414         vecmap->rxq_map = q_vector->ring_mask;
0415         vecmap->rxitr_idx = IAVF_RX_ITR;
0416         vecmap->txitr_idx = IAVF_TX_ITR;
0417     }
0418     /* Misc vector last - this is only for AdminQ messages */
0419     vecmap = &vimi->vecmap[v_idx];
0420     vecmap->vsi_id = adapter->vsi_res->vsi_id;
0421     vecmap->vector_id = 0;
0422     vecmap->txq_map = 0;
0423     vecmap->rxq_map = 0;
0424 
0425     adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
0426     iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
0427              (u8 *)vimi, len);
0428     kfree(vimi);
0429 }
0430 
0431 /**
0432  * iavf_set_mac_addr_type - Set the correct request type from the filter type
0433  * @virtchnl_ether_addr: pointer to requested list element
0434  * @filter: pointer to requested filter
0435  **/
0436 static void
0437 iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
0438                const struct iavf_mac_filter *filter)
0439 {
0440     virtchnl_ether_addr->type = filter->is_primary ?
0441         VIRTCHNL_ETHER_ADDR_PRIMARY :
0442         VIRTCHNL_ETHER_ADDR_EXTRA;
0443 }
0444 
0445 /**
0446  * iavf_add_ether_addrs
0447  * @adapter: adapter structure
0448  *
0449  * Request that the PF add one or more addresses to our filters.
0450  **/
0451 void iavf_add_ether_addrs(struct iavf_adapter *adapter)
0452 {
0453     struct virtchnl_ether_addr_list *veal;
0454     struct iavf_mac_filter *f;
0455     int i = 0, count = 0;
0456     bool more = false;
0457     size_t len;
0458 
0459     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
0460         /* bail because we already have a command pending */
0461         dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
0462             adapter->current_op);
0463         return;
0464     }
0465 
0466     spin_lock_bh(&adapter->mac_vlan_list_lock);
0467 
0468     list_for_each_entry(f, &adapter->mac_filter_list, list) {
0469         if (f->add)
0470             count++;
0471     }
0472     if (!count) {
0473         adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
0474         spin_unlock_bh(&adapter->mac_vlan_list_lock);
0475         return;
0476     }
0477     adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
0478 
0479     len = struct_size(veal, list, count);
0480     if (len > IAVF_MAX_AQ_BUF_SIZE) {
0481         dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
0482         count = (IAVF_MAX_AQ_BUF_SIZE -
0483              sizeof(struct virtchnl_ether_addr_list)) /
0484             sizeof(struct virtchnl_ether_addr);
0485         len = struct_size(veal, list, count);
0486         more = true;
0487     }
0488 
0489     veal = kzalloc(len, GFP_ATOMIC);
0490     if (!veal) {
0491         spin_unlock_bh(&adapter->mac_vlan_list_lock);
0492         return;
0493     }
0494 
0495     veal->vsi_id = adapter->vsi_res->vsi_id;
0496     veal->num_elements = count;
0497     list_for_each_entry(f, &adapter->mac_filter_list, list) {
0498         if (f->add) {
0499             ether_addr_copy(veal->list[i].addr, f->macaddr);
0500             iavf_set_mac_addr_type(&veal->list[i], f);
0501             i++;
0502             f->add = false;
0503             if (i == count)
0504                 break;
0505         }
0506     }
0507     if (!more)
0508         adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
0509 
0510     spin_unlock_bh(&adapter->mac_vlan_list_lock);
0511 
0512     iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
0513     kfree(veal);
0514 }
0515 
0516 /**
0517  * iavf_del_ether_addrs
0518  * @adapter: adapter structure
0519  *
0520  * Request that the PF remove one or more addresses from our filters.
0521  **/
0522 void iavf_del_ether_addrs(struct iavf_adapter *adapter)
0523 {
0524     struct virtchnl_ether_addr_list *veal;
0525     struct iavf_mac_filter *f, *ftmp;
0526     int i = 0, count = 0;
0527     bool more = false;
0528     size_t len;
0529 
0530     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
0531         /* bail because we already have a command pending */
0532         dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
0533             adapter->current_op);
0534         return;
0535     }
0536 
0537     spin_lock_bh(&adapter->mac_vlan_list_lock);
0538 
0539     list_for_each_entry(f, &adapter->mac_filter_list, list) {
0540         if (f->remove)
0541             count++;
0542     }
0543     if (!count) {
0544         adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
0545         spin_unlock_bh(&adapter->mac_vlan_list_lock);
0546         return;
0547     }
0548     adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
0549 
0550     len = struct_size(veal, list, count);
0551     if (len > IAVF_MAX_AQ_BUF_SIZE) {
0552         dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
0553         count = (IAVF_MAX_AQ_BUF_SIZE -
0554              sizeof(struct virtchnl_ether_addr_list)) /
0555             sizeof(struct virtchnl_ether_addr);
0556         len = struct_size(veal, list, count);
0557         more = true;
0558     }
0559     veal = kzalloc(len, GFP_ATOMIC);
0560     if (!veal) {
0561         spin_unlock_bh(&adapter->mac_vlan_list_lock);
0562         return;
0563     }
0564 
0565     veal->vsi_id = adapter->vsi_res->vsi_id;
0566     veal->num_elements = count;
0567     list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
0568         if (f->remove) {
0569             ether_addr_copy(veal->list[i].addr, f->macaddr);
0570             iavf_set_mac_addr_type(&veal->list[i], f);
0571             i++;
0572             list_del(&f->list);
0573             kfree(f);
0574             if (i == count)
0575                 break;
0576         }
0577     }
0578     if (!more)
0579         adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
0580 
0581     spin_unlock_bh(&adapter->mac_vlan_list_lock);
0582 
0583     iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
0584     kfree(veal);
0585 }
0586 
0587 /**
0588  * iavf_mac_add_ok
0589  * @adapter: adapter structure
0590  *
0591  * Submit list of filters based on PF response.
0592  **/
0593 static void iavf_mac_add_ok(struct iavf_adapter *adapter)
0594 {
0595     struct iavf_mac_filter *f, *ftmp;
0596 
0597     spin_lock_bh(&adapter->mac_vlan_list_lock);
0598     list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
0599         f->is_new_mac = false;
0600         if (!f->add && !f->add_handled)
0601             f->add_handled = true;
0602     }
0603     spin_unlock_bh(&adapter->mac_vlan_list_lock);
0604 }
0605 
0606 /**
0607  * iavf_mac_add_reject
0608  * @adapter: adapter structure
0609  *
0610  * Remove filters from list based on PF response.
0611  **/
0612 static void iavf_mac_add_reject(struct iavf_adapter *adapter)
0613 {
0614     struct net_device *netdev = adapter->netdev;
0615     struct iavf_mac_filter *f, *ftmp;
0616 
0617     spin_lock_bh(&adapter->mac_vlan_list_lock);
0618     list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
0619         if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
0620             f->remove = false;
0621 
0622         if (!f->add && !f->add_handled)
0623             f->add_handled = true;
0624 
0625         if (f->is_new_mac) {
0626             list_del(&f->list);
0627             kfree(f);
0628         }
0629     }
0630     spin_unlock_bh(&adapter->mac_vlan_list_lock);
0631 }
0632 
0633 /**
0634  * iavf_vlan_add_reject
0635  * @adapter: adapter structure
0636  *
0637  * Remove VLAN filters from list based on PF response.
0638  **/
0639 static void iavf_vlan_add_reject(struct iavf_adapter *adapter)
0640 {
0641     struct iavf_vlan_filter *f, *ftmp;
0642 
0643     spin_lock_bh(&adapter->mac_vlan_list_lock);
0644     list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
0645         if (f->is_new_vlan) {
0646             if (f->vlan.tpid == ETH_P_8021Q)
0647                 clear_bit(f->vlan.vid,
0648                       adapter->vsi.active_cvlans);
0649             else
0650                 clear_bit(f->vlan.vid,
0651                       adapter->vsi.active_svlans);
0652 
0653             list_del(&f->list);
0654             kfree(f);
0655         }
0656     }
0657     spin_unlock_bh(&adapter->mac_vlan_list_lock);
0658 }
0659 
0660 /**
0661  * iavf_add_vlans
0662  * @adapter: adapter structure
0663  *
0664  * Request that the PF add one or more VLAN filters to our VSI.
0665  **/
0666 void iavf_add_vlans(struct iavf_adapter *adapter)
0667 {
0668     int len, i = 0, count = 0;
0669     struct iavf_vlan_filter *f;
0670     bool more = false;
0671 
0672     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
0673         /* bail because we already have a command pending */
0674         dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
0675             adapter->current_op);
0676         return;
0677     }
0678 
0679     spin_lock_bh(&adapter->mac_vlan_list_lock);
0680 
0681     list_for_each_entry(f, &adapter->vlan_filter_list, list) {
0682         if (f->add)
0683             count++;
0684     }
0685     if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
0686         adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
0687         spin_unlock_bh(&adapter->mac_vlan_list_lock);
0688         return;
0689     }
0690 
0691     if (VLAN_ALLOWED(adapter)) {
0692         struct virtchnl_vlan_filter_list *vvfl;
0693 
0694         adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
0695 
0696         len = sizeof(*vvfl) + (count * sizeof(u16));
0697         if (len > IAVF_MAX_AQ_BUF_SIZE) {
0698             dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
0699             count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
0700                 sizeof(u16);
0701             len = sizeof(*vvfl) + (count * sizeof(u16));
0702             more = true;
0703         }
0704         vvfl = kzalloc(len, GFP_ATOMIC);
0705         if (!vvfl) {
0706             spin_unlock_bh(&adapter->mac_vlan_list_lock);
0707             return;
0708         }
0709 
0710         vvfl->vsi_id = adapter->vsi_res->vsi_id;
0711         vvfl->num_elements = count;
0712         list_for_each_entry(f, &adapter->vlan_filter_list, list) {
0713             if (f->add) {
0714                 vvfl->vlan_id[i] = f->vlan.vid;
0715                 i++;
0716                 f->add = false;
0717                 f->is_new_vlan = true;
0718                 if (i == count)
0719                     break;
0720             }
0721         }
0722         if (!more)
0723             adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
0724 
0725         spin_unlock_bh(&adapter->mac_vlan_list_lock);
0726 
0727         iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
0728         kfree(vvfl);
0729     } else {
0730         u16 max_vlans = adapter->vlan_v2_caps.filtering.max_filters;
0731         u16 current_vlans = iavf_get_num_vlans_added(adapter);
0732         struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
0733 
0734         adapter->current_op = VIRTCHNL_OP_ADD_VLAN_V2;
0735 
0736         if ((count + current_vlans) > max_vlans &&
0737             current_vlans < max_vlans) {
0738             count = max_vlans - iavf_get_num_vlans_added(adapter);
0739             more = true;
0740         }
0741 
0742         len = sizeof(*vvfl_v2) + ((count - 1) *
0743                       sizeof(struct virtchnl_vlan_filter));
0744         if (len > IAVF_MAX_AQ_BUF_SIZE) {
0745             dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
0746             count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl_v2)) /
0747                 sizeof(struct virtchnl_vlan_filter);
0748             len = sizeof(*vvfl_v2) +
0749                 ((count - 1) *
0750                  sizeof(struct virtchnl_vlan_filter));
0751             more = true;
0752         }
0753 
0754         vvfl_v2 = kzalloc(len, GFP_ATOMIC);
0755         if (!vvfl_v2) {
0756             spin_unlock_bh(&adapter->mac_vlan_list_lock);
0757             return;
0758         }
0759 
0760         vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
0761         vvfl_v2->num_elements = count;
0762         list_for_each_entry(f, &adapter->vlan_filter_list, list) {
0763             if (f->add) {
0764                 struct virtchnl_vlan_supported_caps *filtering_support =
0765                     &adapter->vlan_v2_caps.filtering.filtering_support;
0766                 struct virtchnl_vlan *vlan;
0767 
0768                 if (i == count)
0769                     break;
0770 
0771                 /* give priority over outer if it's enabled */
0772                 if (filtering_support->outer)
0773                     vlan = &vvfl_v2->filters[i].outer;
0774                 else
0775                     vlan = &vvfl_v2->filters[i].inner;
0776 
0777                 vlan->tci = f->vlan.vid;
0778                 vlan->tpid = f->vlan.tpid;
0779 
0780                 i++;
0781                 f->add = false;
0782                 f->is_new_vlan = true;
0783             }
0784         }
0785 
0786         if (!more)
0787             adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
0788 
0789         spin_unlock_bh(&adapter->mac_vlan_list_lock);
0790 
0791         iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN_V2,
0792                  (u8 *)vvfl_v2, len);
0793         kfree(vvfl_v2);
0794     }
0795 }
0796 
0797 /**
0798  * iavf_del_vlans
0799  * @adapter: adapter structure
0800  *
0801  * Request that the PF remove one or more VLAN filters from our VSI.
0802  **/
0803 void iavf_del_vlans(struct iavf_adapter *adapter)
0804 {
0805     struct iavf_vlan_filter *f, *ftmp;
0806     int len, i = 0, count = 0;
0807     bool more = false;
0808 
0809     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
0810         /* bail because we already have a command pending */
0811         dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
0812             adapter->current_op);
0813         return;
0814     }
0815 
0816     spin_lock_bh(&adapter->mac_vlan_list_lock);
0817 
0818     list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
0819         /* since VLAN capabilities are not allowed, we dont want to send
0820          * a VLAN delete request because it will most likely fail and
0821          * create unnecessary errors/noise, so just free the VLAN
0822          * filters marked for removal to enable bailing out before
0823          * sending a virtchnl message
0824          */
0825         if (f->remove && !VLAN_FILTERING_ALLOWED(adapter)) {
0826             list_del(&f->list);
0827             kfree(f);
0828         } else if (f->remove) {
0829             count++;
0830         }
0831     }
0832     if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
0833         adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
0834         spin_unlock_bh(&adapter->mac_vlan_list_lock);
0835         return;
0836     }
0837 
0838     if (VLAN_ALLOWED(adapter)) {
0839         struct virtchnl_vlan_filter_list *vvfl;
0840 
0841         adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
0842 
0843         len = sizeof(*vvfl) + (count * sizeof(u16));
0844         if (len > IAVF_MAX_AQ_BUF_SIZE) {
0845             dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
0846             count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
0847                 sizeof(u16);
0848             len = sizeof(*vvfl) + (count * sizeof(u16));
0849             more = true;
0850         }
0851         vvfl = kzalloc(len, GFP_ATOMIC);
0852         if (!vvfl) {
0853             spin_unlock_bh(&adapter->mac_vlan_list_lock);
0854             return;
0855         }
0856 
0857         vvfl->vsi_id = adapter->vsi_res->vsi_id;
0858         vvfl->num_elements = count;
0859         list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
0860             if (f->remove) {
0861                 vvfl->vlan_id[i] = f->vlan.vid;
0862                 i++;
0863                 list_del(&f->list);
0864                 kfree(f);
0865                 if (i == count)
0866                     break;
0867             }
0868         }
0869 
0870         if (!more)
0871             adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
0872 
0873         spin_unlock_bh(&adapter->mac_vlan_list_lock);
0874 
0875         iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
0876         kfree(vvfl);
0877     } else {
0878         struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
0879 
0880         adapter->current_op = VIRTCHNL_OP_DEL_VLAN_V2;
0881 
0882         len = sizeof(*vvfl_v2) +
0883             ((count - 1) * sizeof(struct virtchnl_vlan_filter));
0884         if (len > IAVF_MAX_AQ_BUF_SIZE) {
0885             dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
0886             count = (IAVF_MAX_AQ_BUF_SIZE -
0887                  sizeof(*vvfl_v2)) /
0888                 sizeof(struct virtchnl_vlan_filter);
0889             len = sizeof(*vvfl_v2) +
0890                 ((count - 1) *
0891                  sizeof(struct virtchnl_vlan_filter));
0892             more = true;
0893         }
0894 
0895         vvfl_v2 = kzalloc(len, GFP_ATOMIC);
0896         if (!vvfl_v2) {
0897             spin_unlock_bh(&adapter->mac_vlan_list_lock);
0898             return;
0899         }
0900 
0901         vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
0902         vvfl_v2->num_elements = count;
0903         list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
0904             if (f->remove) {
0905                 struct virtchnl_vlan_supported_caps *filtering_support =
0906                     &adapter->vlan_v2_caps.filtering.filtering_support;
0907                 struct virtchnl_vlan *vlan;
0908 
0909                 /* give priority over outer if it's enabled */
0910                 if (filtering_support->outer)
0911                     vlan = &vvfl_v2->filters[i].outer;
0912                 else
0913                     vlan = &vvfl_v2->filters[i].inner;
0914 
0915                 vlan->tci = f->vlan.vid;
0916                 vlan->tpid = f->vlan.tpid;
0917 
0918                 list_del(&f->list);
0919                 kfree(f);
0920                 i++;
0921                 if (i == count)
0922                     break;
0923             }
0924         }
0925 
0926         if (!more)
0927             adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
0928 
0929         spin_unlock_bh(&adapter->mac_vlan_list_lock);
0930 
0931         iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN_V2,
0932                  (u8 *)vvfl_v2, len);
0933         kfree(vvfl_v2);
0934     }
0935 }
0936 
0937 /**
0938  * iavf_set_promiscuous
0939  * @adapter: adapter structure
0940  * @flags: bitmask to control unicast/multicast promiscuous.
0941  *
0942  * Request that the PF enable promiscuous mode for our VSI.
0943  **/
0944 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags)
0945 {
0946     struct virtchnl_promisc_info vpi;
0947     int promisc_all;
0948 
0949     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
0950         /* bail because we already have a command pending */
0951         dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
0952             adapter->current_op);
0953         return;
0954     }
0955 
0956     promisc_all = FLAG_VF_UNICAST_PROMISC |
0957               FLAG_VF_MULTICAST_PROMISC;
0958     if ((flags & promisc_all) == promisc_all) {
0959         adapter->flags |= IAVF_FLAG_PROMISC_ON;
0960         adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC;
0961         dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
0962     }
0963 
0964     if (flags & FLAG_VF_MULTICAST_PROMISC) {
0965         adapter->flags |= IAVF_FLAG_ALLMULTI_ON;
0966         adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI;
0967         dev_info(&adapter->pdev->dev, "%s is entering multicast promiscuous mode\n",
0968              adapter->netdev->name);
0969     }
0970 
0971     if (!flags) {
0972         if (adapter->flags & IAVF_FLAG_PROMISC_ON) {
0973             adapter->flags &= ~IAVF_FLAG_PROMISC_ON;
0974             adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_PROMISC;
0975             dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
0976         }
0977 
0978         if (adapter->flags & IAVF_FLAG_ALLMULTI_ON) {
0979             adapter->flags &= ~IAVF_FLAG_ALLMULTI_ON;
0980             adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_ALLMULTI;
0981             dev_info(&adapter->pdev->dev, "%s is leaving multicast promiscuous mode\n",
0982                  adapter->netdev->name);
0983         }
0984     }
0985 
0986     adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
0987     vpi.vsi_id = adapter->vsi_res->vsi_id;
0988     vpi.flags = flags;
0989     iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
0990              (u8 *)&vpi, sizeof(vpi));
0991 }
0992 
0993 /**
0994  * iavf_request_stats
0995  * @adapter: adapter structure
0996  *
0997  * Request VSI statistics from PF.
0998  **/
0999 void iavf_request_stats(struct iavf_adapter *adapter)
1000 {
1001     struct virtchnl_queue_select vqs;
1002 
1003     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1004         /* no error message, this isn't crucial */
1005         return;
1006     }
1007 
1008     adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS;
1009     adapter->current_op = VIRTCHNL_OP_GET_STATS;
1010     vqs.vsi_id = adapter->vsi_res->vsi_id;
1011     /* queue maps are ignored for this message - only the vsi is used */
1012     if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
1013                  sizeof(vqs)))
1014         /* if the request failed, don't lock out others */
1015         adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1016 }
1017 
1018 /**
1019  * iavf_get_hena
1020  * @adapter: adapter structure
1021  *
1022  * Request hash enable capabilities from PF
1023  **/
1024 void iavf_get_hena(struct iavf_adapter *adapter)
1025 {
1026     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1027         /* bail because we already have a command pending */
1028         dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
1029             adapter->current_op);
1030         return;
1031     }
1032     adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1033     adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
1034     iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
1035 }
1036 
1037 /**
1038  * iavf_set_hena
1039  * @adapter: adapter structure
1040  *
1041  * Request the PF to set our RSS hash capabilities
1042  **/
1043 void iavf_set_hena(struct iavf_adapter *adapter)
1044 {
1045     struct virtchnl_rss_hena vrh;
1046 
1047     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1048         /* bail because we already have a command pending */
1049         dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
1050             adapter->current_op);
1051         return;
1052     }
1053     vrh.hena = adapter->hena;
1054     adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
1055     adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
1056     iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
1057              sizeof(vrh));
1058 }
1059 
1060 /**
1061  * iavf_set_rss_key
1062  * @adapter: adapter structure
1063  *
1064  * Request the PF to set our RSS hash key
1065  **/
1066 void iavf_set_rss_key(struct iavf_adapter *adapter)
1067 {
1068     struct virtchnl_rss_key *vrk;
1069     int len;
1070 
1071     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1072         /* bail because we already have a command pending */
1073         dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
1074             adapter->current_op);
1075         return;
1076     }
1077     len = sizeof(struct virtchnl_rss_key) +
1078           (adapter->rss_key_size * sizeof(u8)) - 1;
1079     vrk = kzalloc(len, GFP_KERNEL);
1080     if (!vrk)
1081         return;
1082     vrk->vsi_id = adapter->vsi.id;
1083     vrk->key_len = adapter->rss_key_size;
1084     memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
1085 
1086     adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
1087     adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
1088     iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
1089     kfree(vrk);
1090 }
1091 
1092 /**
1093  * iavf_set_rss_lut
1094  * @adapter: adapter structure
1095  *
1096  * Request the PF to set our RSS lookup table
1097  **/
1098 void iavf_set_rss_lut(struct iavf_adapter *adapter)
1099 {
1100     struct virtchnl_rss_lut *vrl;
1101     int len;
1102 
1103     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1104         /* bail because we already have a command pending */
1105         dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
1106             adapter->current_op);
1107         return;
1108     }
1109     len = sizeof(struct virtchnl_rss_lut) +
1110           (adapter->rss_lut_size * sizeof(u8)) - 1;
1111     vrl = kzalloc(len, GFP_KERNEL);
1112     if (!vrl)
1113         return;
1114     vrl->vsi_id = adapter->vsi.id;
1115     vrl->lut_entries = adapter->rss_lut_size;
1116     memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
1117     adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
1118     adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
1119     iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
1120     kfree(vrl);
1121 }
1122 
1123 /**
1124  * iavf_enable_vlan_stripping
1125  * @adapter: adapter structure
1126  *
1127  * Request VLAN header stripping to be enabled
1128  **/
1129 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
1130 {
1131     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1132         /* bail because we already have a command pending */
1133         dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
1134             adapter->current_op);
1135         return;
1136     }
1137     adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
1138     adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
1139     iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
1140 }
1141 
1142 /**
1143  * iavf_disable_vlan_stripping
1144  * @adapter: adapter structure
1145  *
1146  * Request VLAN header stripping to be disabled
1147  **/
1148 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
1149 {
1150     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1151         /* bail because we already have a command pending */
1152         dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
1153             adapter->current_op);
1154         return;
1155     }
1156     adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
1157     adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
1158     iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
1159 }
1160 
1161 /**
1162  * iavf_tpid_to_vc_ethertype - transform from VLAN TPID to virtchnl ethertype
1163  * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1164  */
1165 static u32 iavf_tpid_to_vc_ethertype(u16 tpid)
1166 {
1167     switch (tpid) {
1168     case ETH_P_8021Q:
1169         return VIRTCHNL_VLAN_ETHERTYPE_8100;
1170     case ETH_P_8021AD:
1171         return VIRTCHNL_VLAN_ETHERTYPE_88A8;
1172     }
1173 
1174     return 0;
1175 }
1176 
1177 /**
1178  * iavf_set_vc_offload_ethertype - set virtchnl ethertype for offload message
1179  * @adapter: adapter structure
1180  * @msg: message structure used for updating offloads over virtchnl to update
1181  * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1182  * @offload_op: opcode used to determine which support structure to check
1183  */
1184 static int
1185 iavf_set_vc_offload_ethertype(struct iavf_adapter *adapter,
1186                   struct virtchnl_vlan_setting *msg, u16 tpid,
1187                   enum virtchnl_ops offload_op)
1188 {
1189     struct virtchnl_vlan_supported_caps *offload_support;
1190     u16 vc_ethertype = iavf_tpid_to_vc_ethertype(tpid);
1191 
1192     /* reference the correct offload support structure */
1193     switch (offload_op) {
1194     case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1195     case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1196         offload_support =
1197             &adapter->vlan_v2_caps.offloads.stripping_support;
1198         break;
1199     case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1200     case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1201         offload_support =
1202             &adapter->vlan_v2_caps.offloads.insertion_support;
1203         break;
1204     default:
1205         dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
1206             offload_op);
1207         return -EINVAL;
1208     }
1209 
1210     /* make sure ethertype is supported */
1211     if (offload_support->outer & vc_ethertype &&
1212         offload_support->outer & VIRTCHNL_VLAN_TOGGLE) {
1213         msg->outer_ethertype_setting = vc_ethertype;
1214     } else if (offload_support->inner & vc_ethertype &&
1215            offload_support->inner & VIRTCHNL_VLAN_TOGGLE) {
1216         msg->inner_ethertype_setting = vc_ethertype;
1217     } else {
1218         dev_dbg(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
1219             offload_op, tpid);
1220         return -EINVAL;
1221     }
1222 
1223     return 0;
1224 }
1225 
1226 /**
1227  * iavf_clear_offload_v2_aq_required - clear AQ required bit for offload request
1228  * @adapter: adapter structure
1229  * @tpid: VLAN TPID
1230  * @offload_op: opcode used to determine which AQ required bit to clear
1231  */
1232 static void
1233 iavf_clear_offload_v2_aq_required(struct iavf_adapter *adapter, u16 tpid,
1234                   enum virtchnl_ops offload_op)
1235 {
1236     switch (offload_op) {
1237     case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1238         if (tpid == ETH_P_8021Q)
1239             adapter->aq_required &=
1240                 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING;
1241         else if (tpid == ETH_P_8021AD)
1242             adapter->aq_required &=
1243                 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING;
1244         break;
1245     case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1246         if (tpid == ETH_P_8021Q)
1247             adapter->aq_required &=
1248                 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING;
1249         else if (tpid == ETH_P_8021AD)
1250             adapter->aq_required &=
1251                 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING;
1252         break;
1253     case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1254         if (tpid == ETH_P_8021Q)
1255             adapter->aq_required &=
1256                 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION;
1257         else if (tpid == ETH_P_8021AD)
1258             adapter->aq_required &=
1259                 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION;
1260         break;
1261     case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1262         if (tpid == ETH_P_8021Q)
1263             adapter->aq_required &=
1264                 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION;
1265         else if (tpid == ETH_P_8021AD)
1266             adapter->aq_required &=
1267                 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION;
1268         break;
1269     default:
1270         dev_err(&adapter->pdev->dev, "Unsupported opcode %d specified for clearing aq_required bits for VIRTCHNL_VF_OFFLOAD_VLAN_V2 offload request\n",
1271             offload_op);
1272     }
1273 }
1274 
1275 /**
1276  * iavf_send_vlan_offload_v2 - send offload enable/disable over virtchnl
1277  * @adapter: adapter structure
1278  * @tpid: VLAN TPID used for the command (i.e. 0x8100 or 0x88a8)
1279  * @offload_op: offload_op used to make the request over virtchnl
1280  */
1281 static void
1282 iavf_send_vlan_offload_v2(struct iavf_adapter *adapter, u16 tpid,
1283               enum virtchnl_ops offload_op)
1284 {
1285     struct virtchnl_vlan_setting *msg;
1286     int len = sizeof(*msg);
1287 
1288     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1289         /* bail because we already have a command pending */
1290         dev_err(&adapter->pdev->dev, "Cannot send %d, command %d pending\n",
1291             offload_op, adapter->current_op);
1292         return;
1293     }
1294 
1295     adapter->current_op = offload_op;
1296 
1297     msg = kzalloc(len, GFP_KERNEL);
1298     if (!msg)
1299         return;
1300 
1301     msg->vport_id = adapter->vsi_res->vsi_id;
1302 
1303     /* always clear to prevent unsupported and endless requests */
1304     iavf_clear_offload_v2_aq_required(adapter, tpid, offload_op);
1305 
1306     /* only send valid offload requests */
1307     if (!iavf_set_vc_offload_ethertype(adapter, msg, tpid, offload_op))
1308         iavf_send_pf_msg(adapter, offload_op, (u8 *)msg, len);
1309     else
1310         adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1311 
1312     kfree(msg);
1313 }
1314 
1315 /**
1316  * iavf_enable_vlan_stripping_v2 - enable VLAN stripping
1317  * @adapter: adapter structure
1318  * @tpid: VLAN TPID used to enable VLAN stripping
1319  */
1320 void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1321 {
1322     iavf_send_vlan_offload_v2(adapter, tpid,
1323                   VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2);
1324 }
1325 
1326 /**
1327  * iavf_disable_vlan_stripping_v2 - disable VLAN stripping
1328  * @adapter: adapter structure
1329  * @tpid: VLAN TPID used to disable VLAN stripping
1330  */
1331 void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1332 {
1333     iavf_send_vlan_offload_v2(adapter, tpid,
1334                   VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2);
1335 }
1336 
1337 /**
1338  * iavf_enable_vlan_insertion_v2 - enable VLAN insertion
1339  * @adapter: adapter structure
1340  * @tpid: VLAN TPID used to enable VLAN insertion
1341  */
1342 void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1343 {
1344     iavf_send_vlan_offload_v2(adapter, tpid,
1345                   VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2);
1346 }
1347 
1348 /**
1349  * iavf_disable_vlan_insertion_v2 - disable VLAN insertion
1350  * @adapter: adapter structure
1351  * @tpid: VLAN TPID used to disable VLAN insertion
1352  */
1353 void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1354 {
1355     iavf_send_vlan_offload_v2(adapter, tpid,
1356                   VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2);
1357 }
1358 
1359 #define IAVF_MAX_SPEED_STRLEN   13
1360 
1361 /**
1362  * iavf_print_link_message - print link up or down
1363  * @adapter: adapter structure
1364  *
1365  * Log a message telling the world of our wonderous link status
1366  */
1367 static void iavf_print_link_message(struct iavf_adapter *adapter)
1368 {
1369     struct net_device *netdev = adapter->netdev;
1370     int link_speed_mbps;
1371     char *speed;
1372 
1373     if (!adapter->link_up) {
1374         netdev_info(netdev, "NIC Link is Down\n");
1375         return;
1376     }
1377 
1378     speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
1379     if (!speed)
1380         return;
1381 
1382     if (ADV_LINK_SUPPORT(adapter)) {
1383         link_speed_mbps = adapter->link_speed_mbps;
1384         goto print_link_msg;
1385     }
1386 
1387     switch (adapter->link_speed) {
1388     case VIRTCHNL_LINK_SPEED_40GB:
1389         link_speed_mbps = SPEED_40000;
1390         break;
1391     case VIRTCHNL_LINK_SPEED_25GB:
1392         link_speed_mbps = SPEED_25000;
1393         break;
1394     case VIRTCHNL_LINK_SPEED_20GB:
1395         link_speed_mbps = SPEED_20000;
1396         break;
1397     case VIRTCHNL_LINK_SPEED_10GB:
1398         link_speed_mbps = SPEED_10000;
1399         break;
1400     case VIRTCHNL_LINK_SPEED_5GB:
1401         link_speed_mbps = SPEED_5000;
1402         break;
1403     case VIRTCHNL_LINK_SPEED_2_5GB:
1404         link_speed_mbps = SPEED_2500;
1405         break;
1406     case VIRTCHNL_LINK_SPEED_1GB:
1407         link_speed_mbps = SPEED_1000;
1408         break;
1409     case VIRTCHNL_LINK_SPEED_100MB:
1410         link_speed_mbps = SPEED_100;
1411         break;
1412     default:
1413         link_speed_mbps = SPEED_UNKNOWN;
1414         break;
1415     }
1416 
1417 print_link_msg:
1418     if (link_speed_mbps > SPEED_1000) {
1419         if (link_speed_mbps == SPEED_2500)
1420             snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps");
1421         else
1422             /* convert to Gbps inline */
1423             snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1424                  link_speed_mbps / 1000, "Gbps");
1425     } else if (link_speed_mbps == SPEED_UNKNOWN) {
1426         snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps");
1427     } else {
1428         snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1429              link_speed_mbps, "Mbps");
1430     }
1431 
1432     netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1433     kfree(speed);
1434 }
1435 
1436 /**
1437  * iavf_get_vpe_link_status
1438  * @adapter: adapter structure
1439  * @vpe: virtchnl_pf_event structure
1440  *
1441  * Helper function for determining the link status
1442  **/
1443 static bool
1444 iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1445              struct virtchnl_pf_event *vpe)
1446 {
1447     if (ADV_LINK_SUPPORT(adapter))
1448         return vpe->event_data.link_event_adv.link_status;
1449     else
1450         return vpe->event_data.link_event.link_status;
1451 }
1452 
1453 /**
1454  * iavf_set_adapter_link_speed_from_vpe
1455  * @adapter: adapter structure for which we are setting the link speed
1456  * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1457  *
1458  * Helper function for setting iavf_adapter link speed
1459  **/
1460 static void
1461 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1462                      struct virtchnl_pf_event *vpe)
1463 {
1464     if (ADV_LINK_SUPPORT(adapter))
1465         adapter->link_speed_mbps =
1466             vpe->event_data.link_event_adv.link_speed;
1467     else
1468         adapter->link_speed = vpe->event_data.link_event.link_speed;
1469 }
1470 
1471 /**
1472  * iavf_enable_channels
1473  * @adapter: adapter structure
1474  *
1475  * Request that the PF enable channels as specified by
1476  * the user via tc tool.
1477  **/
1478 void iavf_enable_channels(struct iavf_adapter *adapter)
1479 {
1480     struct virtchnl_tc_info *vti = NULL;
1481     size_t len;
1482     int i;
1483 
1484     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1485         /* bail because we already have a command pending */
1486         dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1487             adapter->current_op);
1488         return;
1489     }
1490 
1491     len = struct_size(vti, list, adapter->num_tc - 1);
1492     vti = kzalloc(len, GFP_KERNEL);
1493     if (!vti)
1494         return;
1495     vti->num_tc = adapter->num_tc;
1496     for (i = 0; i < vti->num_tc; i++) {
1497         vti->list[i].count = adapter->ch_config.ch_info[i].count;
1498         vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1499         vti->list[i].pad = 0;
1500         vti->list[i].max_tx_rate =
1501                 adapter->ch_config.ch_info[i].max_tx_rate;
1502     }
1503 
1504     adapter->ch_config.state = __IAVF_TC_RUNNING;
1505     adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1506     adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1507     adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1508     iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1509     kfree(vti);
1510 }
1511 
1512 /**
1513  * iavf_disable_channels
1514  * @adapter: adapter structure
1515  *
1516  * Request that the PF disable channels that are configured
1517  **/
1518 void iavf_disable_channels(struct iavf_adapter *adapter)
1519 {
1520     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1521         /* bail because we already have a command pending */
1522         dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1523             adapter->current_op);
1524         return;
1525     }
1526 
1527     adapter->ch_config.state = __IAVF_TC_INVALID;
1528     adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1529     adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1530     adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1531     iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1532 }
1533 
1534 /**
1535  * iavf_print_cloud_filter
1536  * @adapter: adapter structure
1537  * @f: cloud filter to print
1538  *
1539  * Print the cloud filter
1540  **/
1541 static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1542                     struct virtchnl_filter *f)
1543 {
1544     switch (f->flow_type) {
1545     case VIRTCHNL_TCP_V4_FLOW:
1546         dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI4 src_ip %pI4 dst_port %hu src_port %hu\n",
1547              &f->data.tcp_spec.dst_mac,
1548              &f->data.tcp_spec.src_mac,
1549              ntohs(f->data.tcp_spec.vlan_id),
1550              &f->data.tcp_spec.dst_ip[0],
1551              &f->data.tcp_spec.src_ip[0],
1552              ntohs(f->data.tcp_spec.dst_port),
1553              ntohs(f->data.tcp_spec.src_port));
1554         break;
1555     case VIRTCHNL_TCP_V6_FLOW:
1556         dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI6 src_ip %pI6 dst_port %hu src_port %hu\n",
1557              &f->data.tcp_spec.dst_mac,
1558              &f->data.tcp_spec.src_mac,
1559              ntohs(f->data.tcp_spec.vlan_id),
1560              &f->data.tcp_spec.dst_ip,
1561              &f->data.tcp_spec.src_ip,
1562              ntohs(f->data.tcp_spec.dst_port),
1563              ntohs(f->data.tcp_spec.src_port));
1564         break;
1565     }
1566 }
1567 
1568 /**
1569  * iavf_add_cloud_filter
1570  * @adapter: adapter structure
1571  *
1572  * Request that the PF add cloud filters as specified
1573  * by the user via tc tool.
1574  **/
1575 void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1576 {
1577     struct iavf_cloud_filter *cf;
1578     struct virtchnl_filter *f;
1579     int len = 0, count = 0;
1580 
1581     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1582         /* bail because we already have a command pending */
1583         dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1584             adapter->current_op);
1585         return;
1586     }
1587     list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1588         if (cf->add) {
1589             count++;
1590             break;
1591         }
1592     }
1593     if (!count) {
1594         adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1595         return;
1596     }
1597     adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1598 
1599     len = sizeof(struct virtchnl_filter);
1600     f = kzalloc(len, GFP_KERNEL);
1601     if (!f)
1602         return;
1603 
1604     list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1605         if (cf->add) {
1606             memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1607             cf->add = false;
1608             cf->state = __IAVF_CF_ADD_PENDING;
1609             iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1610                      (u8 *)f, len);
1611         }
1612     }
1613     kfree(f);
1614 }
1615 
1616 /**
1617  * iavf_del_cloud_filter
1618  * @adapter: adapter structure
1619  *
1620  * Request that the PF delete cloud filters as specified
1621  * by the user via tc tool.
1622  **/
1623 void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1624 {
1625     struct iavf_cloud_filter *cf, *cftmp;
1626     struct virtchnl_filter *f;
1627     int len = 0, count = 0;
1628 
1629     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1630         /* bail because we already have a command pending */
1631         dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1632             adapter->current_op);
1633         return;
1634     }
1635     list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1636         if (cf->del) {
1637             count++;
1638             break;
1639         }
1640     }
1641     if (!count) {
1642         adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1643         return;
1644     }
1645     adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1646 
1647     len = sizeof(struct virtchnl_filter);
1648     f = kzalloc(len, GFP_KERNEL);
1649     if (!f)
1650         return;
1651 
1652     list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1653         if (cf->del) {
1654             memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1655             cf->del = false;
1656             cf->state = __IAVF_CF_DEL_PENDING;
1657             iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1658                      (u8 *)f, len);
1659         }
1660     }
1661     kfree(f);
1662 }
1663 
1664 /**
1665  * iavf_add_fdir_filter
1666  * @adapter: the VF adapter structure
1667  *
1668  * Request that the PF add Flow Director filters as specified
1669  * by the user via ethtool.
1670  **/
1671 void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1672 {
1673     struct iavf_fdir_fltr *fdir;
1674     struct virtchnl_fdir_add *f;
1675     bool process_fltr = false;
1676     int len;
1677 
1678     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1679         /* bail because we already have a command pending */
1680         dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1681             adapter->current_op);
1682         return;
1683     }
1684 
1685     len = sizeof(struct virtchnl_fdir_add);
1686     f = kzalloc(len, GFP_KERNEL);
1687     if (!f)
1688         return;
1689 
1690     spin_lock_bh(&adapter->fdir_fltr_lock);
1691     list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1692         if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1693             process_fltr = true;
1694             fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1695             memcpy(f, &fdir->vc_add_msg, len);
1696             break;
1697         }
1698     }
1699     spin_unlock_bh(&adapter->fdir_fltr_lock);
1700 
1701     if (!process_fltr) {
1702         /* prevent iavf_add_fdir_filter() from being called when there
1703          * are no filters to add
1704          */
1705         adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1706         kfree(f);
1707         return;
1708     }
1709     adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1710     iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1711     kfree(f);
1712 }
1713 
1714 /**
1715  * iavf_del_fdir_filter
1716  * @adapter: the VF adapter structure
1717  *
1718  * Request that the PF delete Flow Director filters as specified
1719  * by the user via ethtool.
1720  **/
1721 void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1722 {
1723     struct iavf_fdir_fltr *fdir;
1724     struct virtchnl_fdir_del f;
1725     bool process_fltr = false;
1726     int len;
1727 
1728     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1729         /* bail because we already have a command pending */
1730         dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1731             adapter->current_op);
1732         return;
1733     }
1734 
1735     len = sizeof(struct virtchnl_fdir_del);
1736 
1737     spin_lock_bh(&adapter->fdir_fltr_lock);
1738     list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1739         if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) {
1740             process_fltr = true;
1741             memset(&f, 0, len);
1742             f.vsi_id = fdir->vc_add_msg.vsi_id;
1743             f.flow_id = fdir->flow_id;
1744             fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1745             break;
1746         }
1747     }
1748     spin_unlock_bh(&adapter->fdir_fltr_lock);
1749 
1750     if (!process_fltr) {
1751         adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1752         return;
1753     }
1754 
1755     adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1756     iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1757 }
1758 
1759 /**
1760  * iavf_add_adv_rss_cfg
1761  * @adapter: the VF adapter structure
1762  *
1763  * Request that the PF add RSS configuration as specified
1764  * by the user via ethtool.
1765  **/
1766 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1767 {
1768     struct virtchnl_rss_cfg *rss_cfg;
1769     struct iavf_adv_rss *rss;
1770     bool process_rss = false;
1771     int len;
1772 
1773     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1774         /* bail because we already have a command pending */
1775         dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1776             adapter->current_op);
1777         return;
1778     }
1779 
1780     len = sizeof(struct virtchnl_rss_cfg);
1781     rss_cfg = kzalloc(len, GFP_KERNEL);
1782     if (!rss_cfg)
1783         return;
1784 
1785     spin_lock_bh(&adapter->adv_rss_lock);
1786     list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1787         if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) {
1788             process_rss = true;
1789             rss->state = IAVF_ADV_RSS_ADD_PENDING;
1790             memcpy(rss_cfg, &rss->cfg_msg, len);
1791             iavf_print_adv_rss_cfg(adapter, rss,
1792                            "Input set change for",
1793                            "is pending");
1794             break;
1795         }
1796     }
1797     spin_unlock_bh(&adapter->adv_rss_lock);
1798 
1799     if (process_rss) {
1800         adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1801         iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1802                  (u8 *)rss_cfg, len);
1803     } else {
1804         adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1805     }
1806 
1807     kfree(rss_cfg);
1808 }
1809 
1810 /**
1811  * iavf_del_adv_rss_cfg
1812  * @adapter: the VF adapter structure
1813  *
1814  * Request that the PF delete RSS configuration as specified
1815  * by the user via ethtool.
1816  **/
1817 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1818 {
1819     struct virtchnl_rss_cfg *rss_cfg;
1820     struct iavf_adv_rss *rss;
1821     bool process_rss = false;
1822     int len;
1823 
1824     if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1825         /* bail because we already have a command pending */
1826         dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1827             adapter->current_op);
1828         return;
1829     }
1830 
1831     len = sizeof(struct virtchnl_rss_cfg);
1832     rss_cfg = kzalloc(len, GFP_KERNEL);
1833     if (!rss_cfg)
1834         return;
1835 
1836     spin_lock_bh(&adapter->adv_rss_lock);
1837     list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1838         if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
1839             process_rss = true;
1840             rss->state = IAVF_ADV_RSS_DEL_PENDING;
1841             memcpy(rss_cfg, &rss->cfg_msg, len);
1842             break;
1843         }
1844     }
1845     spin_unlock_bh(&adapter->adv_rss_lock);
1846 
1847     if (process_rss) {
1848         adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
1849         iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
1850                  (u8 *)rss_cfg, len);
1851     } else {
1852         adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
1853     }
1854 
1855     kfree(rss_cfg);
1856 }
1857 
1858 /**
1859  * iavf_request_reset
1860  * @adapter: adapter structure
1861  *
1862  * Request that the PF reset this VF. No response is expected.
1863  **/
1864 int iavf_request_reset(struct iavf_adapter *adapter)
1865 {
1866     int err;
1867     /* Don't check CURRENT_OP - this is always higher priority */
1868     err = iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1869     adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1870     return err;
1871 }
1872 
1873 /**
1874  * iavf_netdev_features_vlan_strip_set - update vlan strip status
1875  * @netdev: ptr to netdev being adjusted
1876  * @enable: enable or disable vlan strip
1877  *
1878  * Helper function to change vlan strip status in netdev->features.
1879  */
1880 static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev,
1881                         const bool enable)
1882 {
1883     if (enable)
1884         netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1885     else
1886         netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
1887 }
1888 
1889 /**
1890  * iavf_virtchnl_completion
1891  * @adapter: adapter structure
1892  * @v_opcode: opcode sent by PF
1893  * @v_retval: retval sent by PF
1894  * @msg: message sent by PF
1895  * @msglen: message length
1896  *
1897  * Asynchronous completion function for admin queue messages. Rather than busy
1898  * wait, we fire off our requests and assume that no errors will be returned.
1899  * This function handles the reply messages.
1900  **/
1901 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1902                   enum virtchnl_ops v_opcode,
1903                   enum iavf_status v_retval, u8 *msg, u16 msglen)
1904 {
1905     struct net_device *netdev = adapter->netdev;
1906 
1907     if (v_opcode == VIRTCHNL_OP_EVENT) {
1908         struct virtchnl_pf_event *vpe =
1909             (struct virtchnl_pf_event *)msg;
1910         bool link_up = iavf_get_vpe_link_status(adapter, vpe);
1911 
1912         switch (vpe->event) {
1913         case VIRTCHNL_EVENT_LINK_CHANGE:
1914             iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
1915 
1916             /* we've already got the right link status, bail */
1917             if (adapter->link_up == link_up)
1918                 break;
1919 
1920             if (link_up) {
1921                 /* If we get link up message and start queues
1922                  * before our queues are configured it will
1923                  * trigger a TX hang. In that case, just ignore
1924                  * the link status message,we'll get another one
1925                  * after we enable queues and actually prepared
1926                  * to send traffic.
1927                  */
1928                 if (adapter->state != __IAVF_RUNNING)
1929                     break;
1930 
1931                 /* For ADq enabled VF, we reconfigure VSIs and
1932                  * re-allocate queues. Hence wait till all
1933                  * queues are enabled.
1934                  */
1935                 if (adapter->flags &
1936                     IAVF_FLAG_QUEUES_DISABLED)
1937                     break;
1938             }
1939 
1940             adapter->link_up = link_up;
1941             if (link_up) {
1942                 netif_tx_start_all_queues(netdev);
1943                 netif_carrier_on(netdev);
1944             } else {
1945                 netif_tx_stop_all_queues(netdev);
1946                 netif_carrier_off(netdev);
1947             }
1948             iavf_print_link_message(adapter);
1949             break;
1950         case VIRTCHNL_EVENT_RESET_IMPENDING:
1951             dev_info(&adapter->pdev->dev, "Reset indication received from the PF\n");
1952             if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
1953                 adapter->flags |= IAVF_FLAG_RESET_PENDING;
1954                 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1955                 queue_work(iavf_wq, &adapter->reset_task);
1956             }
1957             break;
1958         default:
1959             dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1960                 vpe->event);
1961             break;
1962         }
1963         return;
1964     }
1965     if (v_retval) {
1966         switch (v_opcode) {
1967         case VIRTCHNL_OP_ADD_VLAN:
1968             dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1969                 iavf_stat_str(&adapter->hw, v_retval));
1970             break;
1971         case VIRTCHNL_OP_ADD_ETH_ADDR:
1972             dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1973                 iavf_stat_str(&adapter->hw, v_retval));
1974             iavf_mac_add_reject(adapter);
1975             /* restore administratively set MAC address */
1976             ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1977             wake_up(&adapter->vc_waitqueue);
1978             break;
1979         case VIRTCHNL_OP_DEL_VLAN:
1980             dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1981                 iavf_stat_str(&adapter->hw, v_retval));
1982             break;
1983         case VIRTCHNL_OP_DEL_ETH_ADDR:
1984             dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1985                 iavf_stat_str(&adapter->hw, v_retval));
1986             break;
1987         case VIRTCHNL_OP_ENABLE_CHANNELS:
1988             dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1989                 iavf_stat_str(&adapter->hw, v_retval));
1990             adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1991             adapter->ch_config.state = __IAVF_TC_INVALID;
1992             netdev_reset_tc(netdev);
1993             netif_tx_start_all_queues(netdev);
1994             break;
1995         case VIRTCHNL_OP_DISABLE_CHANNELS:
1996             dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1997                 iavf_stat_str(&adapter->hw, v_retval));
1998             adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1999             adapter->ch_config.state = __IAVF_TC_RUNNING;
2000             netif_tx_start_all_queues(netdev);
2001             break;
2002         case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2003             struct iavf_cloud_filter *cf, *cftmp;
2004 
2005             list_for_each_entry_safe(cf, cftmp,
2006                          &adapter->cloud_filter_list,
2007                          list) {
2008                 if (cf->state == __IAVF_CF_ADD_PENDING) {
2009                     cf->state = __IAVF_CF_INVALID;
2010                     dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
2011                          iavf_stat_str(&adapter->hw,
2012                                    v_retval));
2013                     iavf_print_cloud_filter(adapter,
2014                                 &cf->f);
2015                     list_del(&cf->list);
2016                     kfree(cf);
2017                     adapter->num_cloud_filters--;
2018                 }
2019             }
2020             }
2021             break;
2022         case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2023             struct iavf_cloud_filter *cf;
2024 
2025             list_for_each_entry(cf, &adapter->cloud_filter_list,
2026                         list) {
2027                 if (cf->state == __IAVF_CF_DEL_PENDING) {
2028                     cf->state = __IAVF_CF_ACTIVE;
2029                     dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
2030                          iavf_stat_str(&adapter->hw,
2031                                    v_retval));
2032                     iavf_print_cloud_filter(adapter,
2033                                 &cf->f);
2034                 }
2035             }
2036             }
2037             break;
2038         case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2039             struct iavf_fdir_fltr *fdir, *fdir_tmp;
2040 
2041             spin_lock_bh(&adapter->fdir_fltr_lock);
2042             list_for_each_entry_safe(fdir, fdir_tmp,
2043                          &adapter->fdir_list_head,
2044                          list) {
2045                 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2046                     dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
2047                          iavf_stat_str(&adapter->hw,
2048                                    v_retval));
2049                     iavf_print_fdir_fltr(adapter, fdir);
2050                     if (msglen)
2051                         dev_err(&adapter->pdev->dev,
2052                             "%s\n", msg);
2053                     list_del(&fdir->list);
2054                     kfree(fdir);
2055                     adapter->fdir_active_fltr--;
2056                 }
2057             }
2058             spin_unlock_bh(&adapter->fdir_fltr_lock);
2059             }
2060             break;
2061         case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2062             struct iavf_fdir_fltr *fdir;
2063 
2064             spin_lock_bh(&adapter->fdir_fltr_lock);
2065             list_for_each_entry(fdir, &adapter->fdir_list_head,
2066                         list) {
2067                 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2068                     fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2069                     dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
2070                          iavf_stat_str(&adapter->hw,
2071                                    v_retval));
2072                     iavf_print_fdir_fltr(adapter, fdir);
2073                 }
2074             }
2075             spin_unlock_bh(&adapter->fdir_fltr_lock);
2076             }
2077             break;
2078         case VIRTCHNL_OP_ADD_RSS_CFG: {
2079             struct iavf_adv_rss *rss, *rss_tmp;
2080 
2081             spin_lock_bh(&adapter->adv_rss_lock);
2082             list_for_each_entry_safe(rss, rss_tmp,
2083                          &adapter->adv_rss_list_head,
2084                          list) {
2085                 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2086                     iavf_print_adv_rss_cfg(adapter, rss,
2087                                    "Failed to change the input set for",
2088                                    NULL);
2089                     list_del(&rss->list);
2090                     kfree(rss);
2091                 }
2092             }
2093             spin_unlock_bh(&adapter->adv_rss_lock);
2094             }
2095             break;
2096         case VIRTCHNL_OP_DEL_RSS_CFG: {
2097             struct iavf_adv_rss *rss;
2098 
2099             spin_lock_bh(&adapter->adv_rss_lock);
2100             list_for_each_entry(rss, &adapter->adv_rss_list_head,
2101                         list) {
2102                 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2103                     rss->state = IAVF_ADV_RSS_ACTIVE;
2104                     dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
2105                         iavf_stat_str(&adapter->hw,
2106                                   v_retval));
2107                 }
2108             }
2109             spin_unlock_bh(&adapter->adv_rss_lock);
2110             }
2111             break;
2112         case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2113             dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2114             /* Vlan stripping could not be enabled by ethtool.
2115              * Disable it in netdev->features.
2116              */
2117             iavf_netdev_features_vlan_strip_set(netdev, false);
2118             break;
2119         case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2120             dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2121             /* Vlan stripping could not be disabled by ethtool.
2122              * Enable it in netdev->features.
2123              */
2124             iavf_netdev_features_vlan_strip_set(netdev, true);
2125             break;
2126         case VIRTCHNL_OP_ADD_VLAN_V2:
2127             iavf_vlan_add_reject(adapter);
2128             dev_warn(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2129                  iavf_stat_str(&adapter->hw, v_retval));
2130             break;
2131         default:
2132             dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
2133                 v_retval, iavf_stat_str(&adapter->hw, v_retval),
2134                 v_opcode);
2135         }
2136     }
2137     switch (v_opcode) {
2138     case VIRTCHNL_OP_ADD_ETH_ADDR:
2139         if (!v_retval)
2140             iavf_mac_add_ok(adapter);
2141         if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
2142             if (!ether_addr_equal(netdev->dev_addr,
2143                           adapter->hw.mac.addr)) {
2144                 netif_addr_lock_bh(netdev);
2145                 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2146                 netif_addr_unlock_bh(netdev);
2147             }
2148         wake_up(&adapter->vc_waitqueue);
2149         break;
2150     case VIRTCHNL_OP_GET_STATS: {
2151         struct iavf_eth_stats *stats =
2152             (struct iavf_eth_stats *)msg;
2153         netdev->stats.rx_packets = stats->rx_unicast +
2154                        stats->rx_multicast +
2155                        stats->rx_broadcast;
2156         netdev->stats.tx_packets = stats->tx_unicast +
2157                        stats->tx_multicast +
2158                        stats->tx_broadcast;
2159         netdev->stats.rx_bytes = stats->rx_bytes;
2160         netdev->stats.tx_bytes = stats->tx_bytes;
2161         netdev->stats.tx_errors = stats->tx_errors;
2162         netdev->stats.rx_dropped = stats->rx_discards;
2163         netdev->stats.tx_dropped = stats->tx_discards;
2164         adapter->current_stats = *stats;
2165         }
2166         break;
2167     case VIRTCHNL_OP_GET_VF_RESOURCES: {
2168         u16 len = sizeof(struct virtchnl_vf_resource) +
2169               IAVF_MAX_VF_VSI *
2170               sizeof(struct virtchnl_vsi_resource);
2171         memcpy(adapter->vf_res, msg, min(msglen, len));
2172         iavf_validate_num_queues(adapter);
2173         iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
2174         if (is_zero_ether_addr(adapter->hw.mac.addr)) {
2175             /* restore current mac address */
2176             ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2177         } else {
2178             netif_addr_lock_bh(netdev);
2179             /* refresh current mac address if changed */
2180             ether_addr_copy(netdev->perm_addr,
2181                     adapter->hw.mac.addr);
2182             netif_addr_unlock_bh(netdev);
2183         }
2184         spin_lock_bh(&adapter->mac_vlan_list_lock);
2185         iavf_add_filter(adapter, adapter->hw.mac.addr);
2186 
2187         if (VLAN_ALLOWED(adapter)) {
2188             if (!list_empty(&adapter->vlan_filter_list)) {
2189                 struct iavf_vlan_filter *vlf;
2190 
2191                 /* re-add all VLAN filters over virtchnl */
2192                 list_for_each_entry(vlf,
2193                             &adapter->vlan_filter_list,
2194                             list)
2195                     vlf->add = true;
2196 
2197                 adapter->aq_required |=
2198                     IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2199             }
2200         }
2201 
2202         spin_unlock_bh(&adapter->mac_vlan_list_lock);
2203 
2204         iavf_parse_vf_resource_msg(adapter);
2205 
2206         /* negotiated VIRTCHNL_VF_OFFLOAD_VLAN_V2, so wait for the
2207          * response to VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS to finish
2208          * configuration
2209          */
2210         if (VLAN_V2_ALLOWED(adapter))
2211             break;
2212         /* fallthrough and finish config if VIRTCHNL_VF_OFFLOAD_VLAN_V2
2213          * wasn't successfully negotiated with the PF
2214          */
2215         }
2216         fallthrough;
2217     case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: {
2218         struct iavf_mac_filter *f;
2219         bool was_mac_changed;
2220         u64 aq_required = 0;
2221 
2222         if (v_opcode == VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS)
2223             memcpy(&adapter->vlan_v2_caps, msg,
2224                    min_t(u16, msglen,
2225                      sizeof(adapter->vlan_v2_caps)));
2226 
2227         iavf_process_config(adapter);
2228         adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES;
2229         was_mac_changed = !ether_addr_equal(netdev->dev_addr,
2230                             adapter->hw.mac.addr);
2231 
2232         spin_lock_bh(&adapter->mac_vlan_list_lock);
2233 
2234         /* re-add all MAC filters */
2235         list_for_each_entry(f, &adapter->mac_filter_list, list) {
2236             if (was_mac_changed &&
2237                 ether_addr_equal(netdev->dev_addr, f->macaddr))
2238                 ether_addr_copy(f->macaddr,
2239                         adapter->hw.mac.addr);
2240 
2241             f->is_new_mac = true;
2242             f->add = true;
2243             f->add_handled = false;
2244             f->remove = false;
2245         }
2246 
2247         /* re-add all VLAN filters */
2248         if (VLAN_FILTERING_ALLOWED(adapter)) {
2249             struct iavf_vlan_filter *vlf;
2250 
2251             if (!list_empty(&adapter->vlan_filter_list)) {
2252                 list_for_each_entry(vlf,
2253                             &adapter->vlan_filter_list,
2254                             list)
2255                     vlf->add = true;
2256 
2257                 aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2258             }
2259         }
2260 
2261         spin_unlock_bh(&adapter->mac_vlan_list_lock);
2262 
2263         netif_addr_lock_bh(netdev);
2264         eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2265         netif_addr_unlock_bh(netdev);
2266 
2267         adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER |
2268             aq_required;
2269         }
2270         break;
2271     case VIRTCHNL_OP_ENABLE_QUEUES:
2272         /* enable transmits */
2273         iavf_irq_enable(adapter, true);
2274         adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
2275         break;
2276     case VIRTCHNL_OP_DISABLE_QUEUES:
2277         iavf_free_all_tx_resources(adapter);
2278         iavf_free_all_rx_resources(adapter);
2279         if (adapter->state == __IAVF_DOWN_PENDING) {
2280             iavf_change_state(adapter, __IAVF_DOWN);
2281             wake_up(&adapter->down_waitqueue);
2282         }
2283         break;
2284     case VIRTCHNL_OP_VERSION:
2285     case VIRTCHNL_OP_CONFIG_IRQ_MAP:
2286         /* Don't display an error if we get these out of sequence.
2287          * If the firmware needed to get kicked, we'll get these and
2288          * it's no problem.
2289          */
2290         if (v_opcode != adapter->current_op)
2291             return;
2292         break;
2293     case VIRTCHNL_OP_IWARP:
2294         /* Gobble zero-length replies from the PF. They indicate that
2295          * a previous message was received OK, and the client doesn't
2296          * care about that.
2297          */
2298         if (msglen && CLIENT_ENABLED(adapter))
2299             iavf_notify_client_message(&adapter->vsi, msg, msglen);
2300         break;
2301 
2302     case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2303         adapter->client_pending &=
2304                 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
2305         break;
2306     case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
2307         struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2308 
2309         if (msglen == sizeof(*vrh))
2310             adapter->hena = vrh->hena;
2311         else
2312             dev_warn(&adapter->pdev->dev,
2313                  "Invalid message %d from PF\n", v_opcode);
2314         }
2315         break;
2316     case VIRTCHNL_OP_REQUEST_QUEUES: {
2317         struct virtchnl_vf_res_request *vfres =
2318             (struct virtchnl_vf_res_request *)msg;
2319 
2320         if (vfres->num_queue_pairs != adapter->num_req_queues) {
2321             dev_info(&adapter->pdev->dev,
2322                  "Requested %d queues, PF can support %d\n",
2323                  adapter->num_req_queues,
2324                  vfres->num_queue_pairs);
2325             adapter->num_req_queues = 0;
2326             adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2327         }
2328         }
2329         break;
2330     case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2331         struct iavf_cloud_filter *cf;
2332 
2333         list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
2334             if (cf->state == __IAVF_CF_ADD_PENDING)
2335                 cf->state = __IAVF_CF_ACTIVE;
2336         }
2337         }
2338         break;
2339     case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2340         struct iavf_cloud_filter *cf, *cftmp;
2341 
2342         list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
2343                      list) {
2344             if (cf->state == __IAVF_CF_DEL_PENDING) {
2345                 cf->state = __IAVF_CF_INVALID;
2346                 list_del(&cf->list);
2347                 kfree(cf);
2348                 adapter->num_cloud_filters--;
2349             }
2350         }
2351         }
2352         break;
2353     case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2354         struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
2355         struct iavf_fdir_fltr *fdir, *fdir_tmp;
2356 
2357         spin_lock_bh(&adapter->fdir_fltr_lock);
2358         list_for_each_entry_safe(fdir, fdir_tmp,
2359                      &adapter->fdir_list_head,
2360                      list) {
2361             if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2362                 if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2363                     dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
2364                          fdir->loc);
2365                     fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2366                     fdir->flow_id = add_fltr->flow_id;
2367                 } else {
2368                     dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
2369                          add_fltr->status);
2370                     iavf_print_fdir_fltr(adapter, fdir);
2371                     list_del(&fdir->list);
2372                     kfree(fdir);
2373                     adapter->fdir_active_fltr--;
2374                 }
2375             }
2376         }
2377         spin_unlock_bh(&adapter->fdir_fltr_lock);
2378         }
2379         break;
2380     case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2381         struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
2382         struct iavf_fdir_fltr *fdir, *fdir_tmp;
2383 
2384         spin_lock_bh(&adapter->fdir_fltr_lock);
2385         list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
2386                      list) {
2387             if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2388                 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2389                     dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
2390                          fdir->loc);
2391                     list_del(&fdir->list);
2392                     kfree(fdir);
2393                     adapter->fdir_active_fltr--;
2394                 } else {
2395                     fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2396                     dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
2397                          del_fltr->status);
2398                     iavf_print_fdir_fltr(adapter, fdir);
2399                 }
2400             }
2401         }
2402         spin_unlock_bh(&adapter->fdir_fltr_lock);
2403         }
2404         break;
2405     case VIRTCHNL_OP_ADD_RSS_CFG: {
2406         struct iavf_adv_rss *rss;
2407 
2408         spin_lock_bh(&adapter->adv_rss_lock);
2409         list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
2410             if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2411                 iavf_print_adv_rss_cfg(adapter, rss,
2412                                "Input set change for",
2413                                "successful");
2414                 rss->state = IAVF_ADV_RSS_ACTIVE;
2415             }
2416         }
2417         spin_unlock_bh(&adapter->adv_rss_lock);
2418         }
2419         break;
2420     case VIRTCHNL_OP_DEL_RSS_CFG: {
2421         struct iavf_adv_rss *rss, *rss_tmp;
2422 
2423         spin_lock_bh(&adapter->adv_rss_lock);
2424         list_for_each_entry_safe(rss, rss_tmp,
2425                      &adapter->adv_rss_list_head, list) {
2426             if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2427                 list_del(&rss->list);
2428                 kfree(rss);
2429             }
2430         }
2431         spin_unlock_bh(&adapter->adv_rss_lock);
2432         }
2433         break;
2434     case VIRTCHNL_OP_ADD_VLAN_V2: {
2435         struct iavf_vlan_filter *f;
2436 
2437         spin_lock_bh(&adapter->mac_vlan_list_lock);
2438         list_for_each_entry(f, &adapter->vlan_filter_list, list) {
2439             if (f->is_new_vlan) {
2440                 f->is_new_vlan = false;
2441                 if (f->vlan.tpid == ETH_P_8021Q)
2442                     set_bit(f->vlan.vid,
2443                         adapter->vsi.active_cvlans);
2444                 else
2445                     set_bit(f->vlan.vid,
2446                         adapter->vsi.active_svlans);
2447             }
2448         }
2449         spin_unlock_bh(&adapter->mac_vlan_list_lock);
2450         }
2451         break;
2452     case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2453         /* PF enabled vlan strip on this VF.
2454          * Update netdev->features if needed to be in sync with ethtool.
2455          */
2456         if (!v_retval)
2457             iavf_netdev_features_vlan_strip_set(netdev, true);
2458         break;
2459     case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2460         /* PF disabled vlan strip on this VF.
2461          * Update netdev->features if needed to be in sync with ethtool.
2462          */
2463         if (!v_retval)
2464             iavf_netdev_features_vlan_strip_set(netdev, false);
2465         break;
2466     default:
2467         if (adapter->current_op && (v_opcode != adapter->current_op))
2468             dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
2469                  adapter->current_op, v_opcode);
2470         break;
2471     } /* switch v_opcode */
2472     adapter->current_op = VIRTCHNL_OP_UNKNOWN;
2473 }