1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
3
4 #include "iavf.h"
5 #include "iavf_prototype.h"
6 #include "iavf_client.h"
7
8 /**
9 * iavf_send_pf_msg
10 * @adapter: adapter structure
11 * @op: virtual channel opcode
12 * @msg: pointer to message buffer
13 * @len: message length
14 *
15 * Send message to PF and print status if failure.
16 **/
iavf_send_pf_msg(struct iavf_adapter * adapter,enum virtchnl_ops op,u8 * msg,u16 len)17 static int iavf_send_pf_msg(struct iavf_adapter *adapter,
18 enum virtchnl_ops op, u8 *msg, u16 len)
19 {
20 struct iavf_hw *hw = &adapter->hw;
21 enum iavf_status status;
22
23 if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
24 return 0; /* nothing to see here, move along */
25
26 status = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
27 if (status)
28 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, status %s, aq_err %s\n",
29 op, iavf_stat_str(hw, status),
30 iavf_aq_str(hw, hw->aq.asq_last_status));
31 return iavf_status_to_errno(status);
32 }
33
34 /**
35 * iavf_send_api_ver
36 * @adapter: adapter structure
37 *
38 * Send API version admin queue message to the PF. The reply is not checked
39 * in this function. Returns 0 if the message was successfully
40 * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
41 **/
iavf_send_api_ver(struct iavf_adapter * adapter)42 int iavf_send_api_ver(struct iavf_adapter *adapter)
43 {
44 struct virtchnl_version_info vvi;
45
46 vvi.major = VIRTCHNL_VERSION_MAJOR;
47 vvi.minor = VIRTCHNL_VERSION_MINOR;
48
49 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
50 sizeof(vvi));
51 }
52
53 /**
54 * iavf_poll_virtchnl_msg
55 * @hw: HW configuration structure
56 * @event: event to populate on success
57 * @op_to_poll: requested virtchnl op to poll for
58 *
59 * Initialize poll for virtchnl msg matching the requested_op. Returns 0
60 * if a message of the correct opcode is in the queue or an error code
61 * if no message matching the op code is waiting and other failures.
62 */
63 static int
iavf_poll_virtchnl_msg(struct iavf_hw * hw,struct iavf_arq_event_info * event,enum virtchnl_ops op_to_poll)64 iavf_poll_virtchnl_msg(struct iavf_hw *hw, struct iavf_arq_event_info *event,
65 enum virtchnl_ops op_to_poll)
66 {
67 enum virtchnl_ops received_op;
68 enum iavf_status status;
69 u32 v_retval;
70
71 while (1) {
72 /* When the AQ is empty, iavf_clean_arq_element will return
73 * nonzero and this loop will terminate.
74 */
75 status = iavf_clean_arq_element(hw, event, NULL);
76 if (status != IAVF_SUCCESS)
77 return iavf_status_to_errno(status);
78 received_op =
79 (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high);
80 if (op_to_poll == received_op)
81 break;
82 }
83
84 v_retval = le32_to_cpu(event->desc.cookie_low);
85 return virtchnl_status_to_errno((enum virtchnl_status_code)v_retval);
86 }
87
88 /**
89 * iavf_verify_api_ver
90 * @adapter: adapter structure
91 *
92 * Compare API versions with the PF. Must be called after admin queue is
93 * initialized. Returns 0 if API versions match, -EIO if they do not,
94 * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
95 * from the firmware are propagated.
96 **/
iavf_verify_api_ver(struct iavf_adapter * adapter)97 int iavf_verify_api_ver(struct iavf_adapter *adapter)
98 {
99 struct iavf_arq_event_info event;
100 int err;
101
102 event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
103 event.msg_buf = kzalloc(IAVF_MAX_AQ_BUF_SIZE, GFP_KERNEL);
104 if (!event.msg_buf)
105 return -ENOMEM;
106
107 err = iavf_poll_virtchnl_msg(&adapter->hw, &event, VIRTCHNL_OP_VERSION);
108 if (!err) {
109 struct virtchnl_version_info *pf_vvi =
110 (struct virtchnl_version_info *)event.msg_buf;
111 adapter->pf_version = *pf_vvi;
112
113 if (pf_vvi->major > VIRTCHNL_VERSION_MAJOR ||
114 (pf_vvi->major == VIRTCHNL_VERSION_MAJOR &&
115 pf_vvi->minor > VIRTCHNL_VERSION_MINOR))
116 err = -EIO;
117 }
118
119 kfree(event.msg_buf);
120
121 return err;
122 }
123
124 /**
125 * iavf_send_vf_config_msg
126 * @adapter: adapter structure
127 *
128 * Send VF configuration request admin queue message to the PF. The reply
129 * is not checked in this function. Returns 0 if the message was
130 * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
131 **/
iavf_send_vf_config_msg(struct iavf_adapter * adapter)132 int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
133 {
134 u32 caps;
135
136 caps = VIRTCHNL_VF_OFFLOAD_L2 |
137 VIRTCHNL_VF_OFFLOAD_RSS_PF |
138 VIRTCHNL_VF_OFFLOAD_RSS_AQ |
139 VIRTCHNL_VF_OFFLOAD_RSS_REG |
140 VIRTCHNL_VF_OFFLOAD_VLAN |
141 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
142 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
143 VIRTCHNL_VF_OFFLOAD_ENCAP |
144 VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
145 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
146 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
147 VIRTCHNL_VF_OFFLOAD_ADQ |
148 VIRTCHNL_VF_OFFLOAD_USO |
149 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
150 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
151 VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
152
153 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
154 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG;
155 if (PF_IS_V11(adapter))
156 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
157 (u8 *)&caps, sizeof(caps));
158 else
159 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
160 NULL, 0);
161 }
162
iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter * adapter)163 int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter)
164 {
165 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS;
166
167 if (!VLAN_V2_ALLOWED(adapter))
168 return -EOPNOTSUPP;
169
170 adapter->current_op = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
171
172 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
173 NULL, 0);
174 }
175
176 /**
177 * iavf_validate_num_queues
178 * @adapter: adapter structure
179 *
180 * Validate that the number of queues the PF has sent in
181 * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
182 **/
iavf_validate_num_queues(struct iavf_adapter * adapter)183 static void iavf_validate_num_queues(struct iavf_adapter *adapter)
184 {
185 if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) {
186 struct virtchnl_vsi_resource *vsi_res;
187 int i;
188
189 dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n",
190 adapter->vf_res->num_queue_pairs,
191 IAVF_MAX_REQ_QUEUES);
192 dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n",
193 IAVF_MAX_REQ_QUEUES);
194 adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
195 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
196 vsi_res = &adapter->vf_res->vsi_res[i];
197 vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
198 }
199 }
200 }
201
202 /**
203 * iavf_get_vf_config
204 * @adapter: private adapter structure
205 *
206 * Get VF configuration from PF and populate hw structure. Must be called after
207 * admin queue is initialized. Busy waits until response is received from PF,
208 * with maximum timeout. Response from PF is returned in the buffer for further
209 * processing by the caller.
210 **/
iavf_get_vf_config(struct iavf_adapter * adapter)211 int iavf_get_vf_config(struct iavf_adapter *adapter)
212 {
213 struct iavf_hw *hw = &adapter->hw;
214 struct iavf_arq_event_info event;
215 u16 len;
216 int err;
217
218 len = IAVF_VIRTCHNL_VF_RESOURCE_SIZE;
219 event.buf_len = len;
220 event.msg_buf = kzalloc(len, GFP_KERNEL);
221 if (!event.msg_buf)
222 return -ENOMEM;
223
224 err = iavf_poll_virtchnl_msg(hw, &event, VIRTCHNL_OP_GET_VF_RESOURCES);
225 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
226
227 /* some PFs send more queues than we should have so validate that
228 * we aren't getting too many queues
229 */
230 if (!err)
231 iavf_validate_num_queues(adapter);
232 iavf_vf_parse_hw_config(hw, adapter->vf_res);
233
234 kfree(event.msg_buf);
235
236 return err;
237 }
238
iavf_get_vf_vlan_v2_caps(struct iavf_adapter * adapter)239 int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter)
240 {
241 struct iavf_arq_event_info event;
242 int err;
243 u16 len;
244
245 len = sizeof(struct virtchnl_vlan_caps);
246 event.buf_len = len;
247 event.msg_buf = kzalloc(len, GFP_KERNEL);
248 if (!event.msg_buf)
249 return -ENOMEM;
250
251 err = iavf_poll_virtchnl_msg(&adapter->hw, &event,
252 VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS);
253 if (!err)
254 memcpy(&adapter->vlan_v2_caps, event.msg_buf,
255 min(event.msg_len, len));
256
257 kfree(event.msg_buf);
258
259 return err;
260 }
261
262 /**
263 * iavf_configure_queues
264 * @adapter: adapter structure
265 *
266 * Request that the PF set up our (previously allocated) queues.
267 **/
iavf_configure_queues(struct iavf_adapter * adapter)268 void iavf_configure_queues(struct iavf_adapter *adapter)
269 {
270 struct virtchnl_vsi_queue_config_info *vqci;
271 int i, max_frame = adapter->vf_res->max_mtu;
272 int pairs = adapter->num_active_queues;
273 struct virtchnl_queue_pair_info *vqpi;
274 size_t len;
275
276 if (max_frame > IAVF_MAX_RXBUFFER || !max_frame)
277 max_frame = IAVF_MAX_RXBUFFER;
278
279 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
280 /* bail because we already have a command pending */
281 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
282 adapter->current_op);
283 return;
284 }
285 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
286 len = virtchnl_struct_size(vqci, qpair, pairs);
287 vqci = kzalloc(len, GFP_KERNEL);
288 if (!vqci)
289 return;
290
291 /* Limit maximum frame size when jumbo frames is not enabled */
292 if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) &&
293 (adapter->netdev->mtu <= ETH_DATA_LEN))
294 max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN;
295
296 vqci->vsi_id = adapter->vsi_res->vsi_id;
297 vqci->num_queue_pairs = pairs;
298 vqpi = vqci->qpair;
299 /* Size check is not needed here - HW max is 16 queue pairs, and we
300 * can fit info for 31 of them into the AQ buffer before it overflows.
301 */
302 for (i = 0; i < pairs; i++) {
303 vqpi->txq.vsi_id = vqci->vsi_id;
304 vqpi->txq.queue_id = i;
305 vqpi->txq.ring_len = adapter->tx_rings[i].count;
306 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
307 vqpi->rxq.vsi_id = vqci->vsi_id;
308 vqpi->rxq.queue_id = i;
309 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
310 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
311 vqpi->rxq.max_pkt_size = max_frame;
312 vqpi->rxq.databuffer_size =
313 ALIGN(adapter->rx_rings[i].rx_buf_len,
314 BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT));
315 vqpi++;
316 }
317
318 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
319 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
320 (u8 *)vqci, len);
321 kfree(vqci);
322 }
323
324 /**
325 * iavf_enable_queues
326 * @adapter: adapter structure
327 *
328 * Request that the PF enable all of our queues.
329 **/
iavf_enable_queues(struct iavf_adapter * adapter)330 void iavf_enable_queues(struct iavf_adapter *adapter)
331 {
332 struct virtchnl_queue_select vqs;
333
334 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
335 /* bail because we already have a command pending */
336 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
337 adapter->current_op);
338 return;
339 }
340 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
341 vqs.vsi_id = adapter->vsi_res->vsi_id;
342 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
343 vqs.rx_queues = vqs.tx_queues;
344 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
345 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
346 (u8 *)&vqs, sizeof(vqs));
347 }
348
349 /**
350 * iavf_disable_queues
351 * @adapter: adapter structure
352 *
353 * Request that the PF disable all of our queues.
354 **/
iavf_disable_queues(struct iavf_adapter * adapter)355 void iavf_disable_queues(struct iavf_adapter *adapter)
356 {
357 struct virtchnl_queue_select vqs;
358
359 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
360 /* bail because we already have a command pending */
361 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
362 adapter->current_op);
363 return;
364 }
365 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
366 vqs.vsi_id = adapter->vsi_res->vsi_id;
367 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
368 vqs.rx_queues = vqs.tx_queues;
369 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
370 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
371 (u8 *)&vqs, sizeof(vqs));
372 }
373
374 /**
375 * iavf_map_queues
376 * @adapter: adapter structure
377 *
378 * Request that the PF map queues to interrupt vectors. Misc causes, including
379 * admin queue, are always mapped to vector 0.
380 **/
iavf_map_queues(struct iavf_adapter * adapter)381 void iavf_map_queues(struct iavf_adapter *adapter)
382 {
383 struct virtchnl_irq_map_info *vimi;
384 struct virtchnl_vector_map *vecmap;
385 struct iavf_q_vector *q_vector;
386 int v_idx, q_vectors;
387 size_t len;
388
389 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
390 /* bail because we already have a command pending */
391 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
392 adapter->current_op);
393 return;
394 }
395 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
396
397 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
398
399 len = virtchnl_struct_size(vimi, vecmap, adapter->num_msix_vectors);
400 vimi = kzalloc(len, GFP_KERNEL);
401 if (!vimi)
402 return;
403
404 vimi->num_vectors = adapter->num_msix_vectors;
405 /* Queue vectors first */
406 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
407 q_vector = &adapter->q_vectors[v_idx];
408 vecmap = &vimi->vecmap[v_idx];
409
410 vecmap->vsi_id = adapter->vsi_res->vsi_id;
411 vecmap->vector_id = v_idx + NONQ_VECS;
412 vecmap->txq_map = q_vector->ring_mask;
413 vecmap->rxq_map = q_vector->ring_mask;
414 vecmap->rxitr_idx = IAVF_RX_ITR;
415 vecmap->txitr_idx = IAVF_TX_ITR;
416 }
417 /* Misc vector last - this is only for AdminQ messages */
418 vecmap = &vimi->vecmap[v_idx];
419 vecmap->vsi_id = adapter->vsi_res->vsi_id;
420 vecmap->vector_id = 0;
421 vecmap->txq_map = 0;
422 vecmap->rxq_map = 0;
423
424 adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
425 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
426 (u8 *)vimi, len);
427 kfree(vimi);
428 }
429
430 /**
431 * iavf_set_mac_addr_type - Set the correct request type from the filter type
432 * @virtchnl_ether_addr: pointer to requested list element
433 * @filter: pointer to requested filter
434 **/
435 static void
iavf_set_mac_addr_type(struct virtchnl_ether_addr * virtchnl_ether_addr,const struct iavf_mac_filter * filter)436 iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
437 const struct iavf_mac_filter *filter)
438 {
439 virtchnl_ether_addr->type = filter->is_primary ?
440 VIRTCHNL_ETHER_ADDR_PRIMARY :
441 VIRTCHNL_ETHER_ADDR_EXTRA;
442 }
443
444 /**
445 * iavf_add_ether_addrs
446 * @adapter: adapter structure
447 *
448 * Request that the PF add one or more addresses to our filters.
449 **/
iavf_add_ether_addrs(struct iavf_adapter * adapter)450 void iavf_add_ether_addrs(struct iavf_adapter *adapter)
451 {
452 struct virtchnl_ether_addr_list *veal;
453 struct iavf_mac_filter *f;
454 int i = 0, count = 0;
455 bool more = false;
456 size_t len;
457
458 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
459 /* bail because we already have a command pending */
460 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
461 adapter->current_op);
462 return;
463 }
464
465 spin_lock_bh(&adapter->mac_vlan_list_lock);
466
467 list_for_each_entry(f, &adapter->mac_filter_list, list) {
468 if (f->add)
469 count++;
470 }
471 if (!count) {
472 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
473 spin_unlock_bh(&adapter->mac_vlan_list_lock);
474 return;
475 }
476 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
477
478 len = virtchnl_struct_size(veal, list, count);
479 if (len > IAVF_MAX_AQ_BUF_SIZE) {
480 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
481 while (len > IAVF_MAX_AQ_BUF_SIZE)
482 len = virtchnl_struct_size(veal, list, --count);
483 more = true;
484 }
485
486 veal = kzalloc(len, GFP_ATOMIC);
487 if (!veal) {
488 spin_unlock_bh(&adapter->mac_vlan_list_lock);
489 return;
490 }
491
492 veal->vsi_id = adapter->vsi_res->vsi_id;
493 veal->num_elements = count;
494 list_for_each_entry(f, &adapter->mac_filter_list, list) {
495 if (f->add) {
496 ether_addr_copy(veal->list[i].addr, f->macaddr);
497 iavf_set_mac_addr_type(&veal->list[i], f);
498 i++;
499 f->add = false;
500 if (i == count)
501 break;
502 }
503 }
504 if (!more)
505 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
506
507 spin_unlock_bh(&adapter->mac_vlan_list_lock);
508
509 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
510 kfree(veal);
511 }
512
513 /**
514 * iavf_del_ether_addrs
515 * @adapter: adapter structure
516 *
517 * Request that the PF remove one or more addresses from our filters.
518 **/
iavf_del_ether_addrs(struct iavf_adapter * adapter)519 void iavf_del_ether_addrs(struct iavf_adapter *adapter)
520 {
521 struct virtchnl_ether_addr_list *veal;
522 struct iavf_mac_filter *f, *ftmp;
523 int i = 0, count = 0;
524 bool more = false;
525 size_t len;
526
527 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
528 /* bail because we already have a command pending */
529 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
530 adapter->current_op);
531 return;
532 }
533
534 spin_lock_bh(&adapter->mac_vlan_list_lock);
535
536 list_for_each_entry(f, &adapter->mac_filter_list, list) {
537 if (f->remove)
538 count++;
539 }
540 if (!count) {
541 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
542 spin_unlock_bh(&adapter->mac_vlan_list_lock);
543 return;
544 }
545 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
546
547 len = virtchnl_struct_size(veal, list, count);
548 if (len > IAVF_MAX_AQ_BUF_SIZE) {
549 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
550 while (len > IAVF_MAX_AQ_BUF_SIZE)
551 len = virtchnl_struct_size(veal, list, --count);
552 more = true;
553 }
554 veal = kzalloc(len, GFP_ATOMIC);
555 if (!veal) {
556 spin_unlock_bh(&adapter->mac_vlan_list_lock);
557 return;
558 }
559
560 veal->vsi_id = adapter->vsi_res->vsi_id;
561 veal->num_elements = count;
562 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
563 if (f->remove) {
564 ether_addr_copy(veal->list[i].addr, f->macaddr);
565 iavf_set_mac_addr_type(&veal->list[i], f);
566 i++;
567 list_del(&f->list);
568 kfree(f);
569 if (i == count)
570 break;
571 }
572 }
573 if (!more)
574 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
575
576 spin_unlock_bh(&adapter->mac_vlan_list_lock);
577
578 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
579 kfree(veal);
580 }
581
582 /**
583 * iavf_mac_add_ok
584 * @adapter: adapter structure
585 *
586 * Submit list of filters based on PF response.
587 **/
iavf_mac_add_ok(struct iavf_adapter * adapter)588 static void iavf_mac_add_ok(struct iavf_adapter *adapter)
589 {
590 struct iavf_mac_filter *f, *ftmp;
591
592 spin_lock_bh(&adapter->mac_vlan_list_lock);
593 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
594 f->is_new_mac = false;
595 if (!f->add && !f->add_handled)
596 f->add_handled = true;
597 }
598 spin_unlock_bh(&adapter->mac_vlan_list_lock);
599 }
600
601 /**
602 * iavf_mac_add_reject
603 * @adapter: adapter structure
604 *
605 * Remove filters from list based on PF response.
606 **/
iavf_mac_add_reject(struct iavf_adapter * adapter)607 static void iavf_mac_add_reject(struct iavf_adapter *adapter)
608 {
609 struct net_device *netdev = adapter->netdev;
610 struct iavf_mac_filter *f, *ftmp;
611
612 spin_lock_bh(&adapter->mac_vlan_list_lock);
613 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
614 if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
615 f->remove = false;
616
617 if (!f->add && !f->add_handled)
618 f->add_handled = true;
619
620 if (f->is_new_mac) {
621 list_del(&f->list);
622 kfree(f);
623 }
624 }
625 spin_unlock_bh(&adapter->mac_vlan_list_lock);
626 }
627
628 /**
629 * iavf_vlan_add_reject
630 * @adapter: adapter structure
631 *
632 * Remove VLAN filters from list based on PF response.
633 **/
iavf_vlan_add_reject(struct iavf_adapter * adapter)634 static void iavf_vlan_add_reject(struct iavf_adapter *adapter)
635 {
636 struct iavf_vlan_filter *f, *ftmp;
637
638 spin_lock_bh(&adapter->mac_vlan_list_lock);
639 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
640 if (f->state == IAVF_VLAN_IS_NEW) {
641 list_del(&f->list);
642 kfree(f);
643 adapter->num_vlan_filters--;
644 }
645 }
646 spin_unlock_bh(&adapter->mac_vlan_list_lock);
647 }
648
649 /**
650 * iavf_add_vlans
651 * @adapter: adapter structure
652 *
653 * Request that the PF add one or more VLAN filters to our VSI.
654 **/
iavf_add_vlans(struct iavf_adapter * adapter)655 void iavf_add_vlans(struct iavf_adapter *adapter)
656 {
657 int len, i = 0, count = 0;
658 struct iavf_vlan_filter *f;
659 bool more = false;
660
661 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
662 /* bail because we already have a command pending */
663 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
664 adapter->current_op);
665 return;
666 }
667
668 spin_lock_bh(&adapter->mac_vlan_list_lock);
669
670 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
671 if (f->state == IAVF_VLAN_ADD)
672 count++;
673 }
674 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
675 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
676 spin_unlock_bh(&adapter->mac_vlan_list_lock);
677 return;
678 }
679
680 if (VLAN_ALLOWED(adapter)) {
681 struct virtchnl_vlan_filter_list *vvfl;
682
683 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
684
685 len = virtchnl_struct_size(vvfl, vlan_id, count);
686 if (len > IAVF_MAX_AQ_BUF_SIZE) {
687 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
688 while (len > IAVF_MAX_AQ_BUF_SIZE)
689 len = virtchnl_struct_size(vvfl, vlan_id,
690 --count);
691 more = true;
692 }
693 vvfl = kzalloc(len, GFP_ATOMIC);
694 if (!vvfl) {
695 spin_unlock_bh(&adapter->mac_vlan_list_lock);
696 return;
697 }
698
699 vvfl->vsi_id = adapter->vsi_res->vsi_id;
700 vvfl->num_elements = count;
701 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
702 if (f->state == IAVF_VLAN_ADD) {
703 vvfl->vlan_id[i] = f->vlan.vid;
704 i++;
705 f->state = IAVF_VLAN_IS_NEW;
706 if (i == count)
707 break;
708 }
709 }
710 if (!more)
711 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
712
713 spin_unlock_bh(&adapter->mac_vlan_list_lock);
714
715 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
716 kfree(vvfl);
717 } else {
718 u16 max_vlans = adapter->vlan_v2_caps.filtering.max_filters;
719 u16 current_vlans = iavf_get_num_vlans_added(adapter);
720 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
721
722 adapter->current_op = VIRTCHNL_OP_ADD_VLAN_V2;
723
724 if ((count + current_vlans) > max_vlans &&
725 current_vlans < max_vlans) {
726 count = max_vlans - iavf_get_num_vlans_added(adapter);
727 more = true;
728 }
729
730 len = virtchnl_struct_size(vvfl_v2, filters, count);
731 if (len > IAVF_MAX_AQ_BUF_SIZE) {
732 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
733 while (len > IAVF_MAX_AQ_BUF_SIZE)
734 len = virtchnl_struct_size(vvfl_v2, filters,
735 --count);
736 more = true;
737 }
738
739 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
740 if (!vvfl_v2) {
741 spin_unlock_bh(&adapter->mac_vlan_list_lock);
742 return;
743 }
744
745 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
746 vvfl_v2->num_elements = count;
747 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
748 if (f->state == IAVF_VLAN_ADD) {
749 struct virtchnl_vlan_supported_caps *filtering_support =
750 &adapter->vlan_v2_caps.filtering.filtering_support;
751 struct virtchnl_vlan *vlan;
752
753 if (i == count)
754 break;
755
756 /* give priority over outer if it's enabled */
757 if (filtering_support->outer)
758 vlan = &vvfl_v2->filters[i].outer;
759 else
760 vlan = &vvfl_v2->filters[i].inner;
761
762 vlan->tci = f->vlan.vid;
763 vlan->tpid = f->vlan.tpid;
764
765 i++;
766 f->state = IAVF_VLAN_IS_NEW;
767 }
768 }
769
770 if (!more)
771 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
772
773 spin_unlock_bh(&adapter->mac_vlan_list_lock);
774
775 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN_V2,
776 (u8 *)vvfl_v2, len);
777 kfree(vvfl_v2);
778 }
779 }
780
781 /**
782 * iavf_del_vlans
783 * @adapter: adapter structure
784 *
785 * Request that the PF remove one or more VLAN filters from our VSI.
786 **/
iavf_del_vlans(struct iavf_adapter * adapter)787 void iavf_del_vlans(struct iavf_adapter *adapter)
788 {
789 struct iavf_vlan_filter *f, *ftmp;
790 int len, i = 0, count = 0;
791 bool more = false;
792
793 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
794 /* bail because we already have a command pending */
795 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
796 adapter->current_op);
797 return;
798 }
799
800 spin_lock_bh(&adapter->mac_vlan_list_lock);
801
802 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
803 /* since VLAN capabilities are not allowed, we dont want to send
804 * a VLAN delete request because it will most likely fail and
805 * create unnecessary errors/noise, so just free the VLAN
806 * filters marked for removal to enable bailing out before
807 * sending a virtchnl message
808 */
809 if (f->state == IAVF_VLAN_REMOVE &&
810 !VLAN_FILTERING_ALLOWED(adapter)) {
811 list_del(&f->list);
812 kfree(f);
813 adapter->num_vlan_filters--;
814 } else if (f->state == IAVF_VLAN_DISABLE &&
815 !VLAN_FILTERING_ALLOWED(adapter)) {
816 f->state = IAVF_VLAN_INACTIVE;
817 } else if (f->state == IAVF_VLAN_REMOVE ||
818 f->state == IAVF_VLAN_DISABLE) {
819 count++;
820 }
821 }
822 if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
823 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
824 spin_unlock_bh(&adapter->mac_vlan_list_lock);
825 return;
826 }
827
828 if (VLAN_ALLOWED(adapter)) {
829 struct virtchnl_vlan_filter_list *vvfl;
830
831 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
832
833 len = virtchnl_struct_size(vvfl, vlan_id, count);
834 if (len > IAVF_MAX_AQ_BUF_SIZE) {
835 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
836 while (len > IAVF_MAX_AQ_BUF_SIZE)
837 len = virtchnl_struct_size(vvfl, vlan_id,
838 --count);
839 more = true;
840 }
841 vvfl = kzalloc(len, GFP_ATOMIC);
842 if (!vvfl) {
843 spin_unlock_bh(&adapter->mac_vlan_list_lock);
844 return;
845 }
846
847 vvfl->vsi_id = adapter->vsi_res->vsi_id;
848 vvfl->num_elements = count;
849 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
850 if (f->state == IAVF_VLAN_DISABLE) {
851 vvfl->vlan_id[i] = f->vlan.vid;
852 f->state = IAVF_VLAN_INACTIVE;
853 i++;
854 if (i == count)
855 break;
856 } else if (f->state == IAVF_VLAN_REMOVE) {
857 vvfl->vlan_id[i] = f->vlan.vid;
858 list_del(&f->list);
859 kfree(f);
860 adapter->num_vlan_filters--;
861 i++;
862 if (i == count)
863 break;
864 }
865 }
866
867 if (!more)
868 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
869
870 spin_unlock_bh(&adapter->mac_vlan_list_lock);
871
872 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
873 kfree(vvfl);
874 } else {
875 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
876
877 adapter->current_op = VIRTCHNL_OP_DEL_VLAN_V2;
878
879 len = virtchnl_struct_size(vvfl_v2, filters, count);
880 if (len > IAVF_MAX_AQ_BUF_SIZE) {
881 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
882 while (len > IAVF_MAX_AQ_BUF_SIZE)
883 len = virtchnl_struct_size(vvfl_v2, filters,
884 --count);
885 more = true;
886 }
887
888 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
889 if (!vvfl_v2) {
890 spin_unlock_bh(&adapter->mac_vlan_list_lock);
891 return;
892 }
893
894 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
895 vvfl_v2->num_elements = count;
896 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
897 if (f->state == IAVF_VLAN_DISABLE ||
898 f->state == IAVF_VLAN_REMOVE) {
899 struct virtchnl_vlan_supported_caps *filtering_support =
900 &adapter->vlan_v2_caps.filtering.filtering_support;
901 struct virtchnl_vlan *vlan;
902
903 /* give priority over outer if it's enabled */
904 if (filtering_support->outer)
905 vlan = &vvfl_v2->filters[i].outer;
906 else
907 vlan = &vvfl_v2->filters[i].inner;
908
909 vlan->tci = f->vlan.vid;
910 vlan->tpid = f->vlan.tpid;
911
912 if (f->state == IAVF_VLAN_DISABLE) {
913 f->state = IAVF_VLAN_INACTIVE;
914 } else {
915 list_del(&f->list);
916 kfree(f);
917 adapter->num_vlan_filters--;
918 }
919 i++;
920 if (i == count)
921 break;
922 }
923 }
924
925 if (!more)
926 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
927
928 spin_unlock_bh(&adapter->mac_vlan_list_lock);
929
930 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN_V2,
931 (u8 *)vvfl_v2, len);
932 kfree(vvfl_v2);
933 }
934 }
935
936 /**
937 * iavf_set_promiscuous
938 * @adapter: adapter structure
939 *
940 * Request that the PF enable promiscuous mode for our VSI.
941 **/
iavf_set_promiscuous(struct iavf_adapter * adapter)942 void iavf_set_promiscuous(struct iavf_adapter *adapter)
943 {
944 struct net_device *netdev = adapter->netdev;
945 struct virtchnl_promisc_info vpi;
946 unsigned int flags;
947
948 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
949 /* bail because we already have a command pending */
950 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
951 adapter->current_op);
952 return;
953 }
954
955 /* prevent changes to promiscuous flags */
956 spin_lock_bh(&adapter->current_netdev_promisc_flags_lock);
957
958 /* sanity check to prevent duplicate AQ calls */
959 if (!iavf_promiscuous_mode_changed(adapter)) {
960 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_PROMISC_MODE;
961 dev_dbg(&adapter->pdev->dev, "No change in promiscuous mode\n");
962 /* allow changes to promiscuous flags */
963 spin_unlock_bh(&adapter->current_netdev_promisc_flags_lock);
964 return;
965 }
966
967 /* there are 2 bits, but only 3 states */
968 if (!(netdev->flags & IFF_PROMISC) &&
969 netdev->flags & IFF_ALLMULTI) {
970 /* State 1 - only multicast promiscuous mode enabled
971 * - !IFF_PROMISC && IFF_ALLMULTI
972 */
973 flags = FLAG_VF_MULTICAST_PROMISC;
974 adapter->current_netdev_promisc_flags |= IFF_ALLMULTI;
975 adapter->current_netdev_promisc_flags &= ~IFF_PROMISC;
976 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
977 } else if (!(netdev->flags & IFF_PROMISC) &&
978 !(netdev->flags & IFF_ALLMULTI)) {
979 /* State 2 - unicast/multicast promiscuous mode disabled
980 * - !IFF_PROMISC && !IFF_ALLMULTI
981 */
982 flags = 0;
983 adapter->current_netdev_promisc_flags &=
984 ~(IFF_PROMISC | IFF_ALLMULTI);
985 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
986 } else {
987 /* State 3 - unicast/multicast promiscuous mode enabled
988 * - IFF_PROMISC && IFF_ALLMULTI
989 * - IFF_PROMISC && !IFF_ALLMULTI
990 */
991 flags = FLAG_VF_UNICAST_PROMISC | FLAG_VF_MULTICAST_PROMISC;
992 adapter->current_netdev_promisc_flags |= IFF_PROMISC;
993 if (netdev->flags & IFF_ALLMULTI)
994 adapter->current_netdev_promisc_flags |= IFF_ALLMULTI;
995 else
996 adapter->current_netdev_promisc_flags &= ~IFF_ALLMULTI;
997
998 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
999 }
1000
1001 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_PROMISC_MODE;
1002
1003 /* allow changes to promiscuous flags */
1004 spin_unlock_bh(&adapter->current_netdev_promisc_flags_lock);
1005
1006 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
1007 vpi.vsi_id = adapter->vsi_res->vsi_id;
1008 vpi.flags = flags;
1009 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
1010 (u8 *)&vpi, sizeof(vpi));
1011 }
1012
1013 /**
1014 * iavf_request_stats
1015 * @adapter: adapter structure
1016 *
1017 * Request VSI statistics from PF.
1018 **/
iavf_request_stats(struct iavf_adapter * adapter)1019 void iavf_request_stats(struct iavf_adapter *adapter)
1020 {
1021 struct virtchnl_queue_select vqs;
1022
1023 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1024 /* no error message, this isn't crucial */
1025 return;
1026 }
1027
1028 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS;
1029 adapter->current_op = VIRTCHNL_OP_GET_STATS;
1030 vqs.vsi_id = adapter->vsi_res->vsi_id;
1031 /* queue maps are ignored for this message - only the vsi is used */
1032 if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
1033 sizeof(vqs)))
1034 /* if the request failed, don't lock out others */
1035 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1036 }
1037
1038 /**
1039 * iavf_get_hena
1040 * @adapter: adapter structure
1041 *
1042 * Request hash enable capabilities from PF
1043 **/
iavf_get_hena(struct iavf_adapter * adapter)1044 void iavf_get_hena(struct iavf_adapter *adapter)
1045 {
1046 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1047 /* bail because we already have a command pending */
1048 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
1049 adapter->current_op);
1050 return;
1051 }
1052 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1053 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
1054 iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
1055 }
1056
1057 /**
1058 * iavf_set_hena
1059 * @adapter: adapter structure
1060 *
1061 * Request the PF to set our RSS hash capabilities
1062 **/
iavf_set_hena(struct iavf_adapter * adapter)1063 void iavf_set_hena(struct iavf_adapter *adapter)
1064 {
1065 struct virtchnl_rss_hena vrh;
1066
1067 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1068 /* bail because we already have a command pending */
1069 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
1070 adapter->current_op);
1071 return;
1072 }
1073 vrh.hena = adapter->hena;
1074 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
1075 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
1076 iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
1077 sizeof(vrh));
1078 }
1079
1080 /**
1081 * iavf_set_rss_key
1082 * @adapter: adapter structure
1083 *
1084 * Request the PF to set our RSS hash key
1085 **/
iavf_set_rss_key(struct iavf_adapter * adapter)1086 void iavf_set_rss_key(struct iavf_adapter *adapter)
1087 {
1088 struct virtchnl_rss_key *vrk;
1089 int len;
1090
1091 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1092 /* bail because we already have a command pending */
1093 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
1094 adapter->current_op);
1095 return;
1096 }
1097 len = virtchnl_struct_size(vrk, key, adapter->rss_key_size);
1098 vrk = kzalloc(len, GFP_KERNEL);
1099 if (!vrk)
1100 return;
1101 vrk->vsi_id = adapter->vsi.id;
1102 vrk->key_len = adapter->rss_key_size;
1103 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
1104
1105 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
1106 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
1107 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
1108 kfree(vrk);
1109 }
1110
1111 /**
1112 * iavf_set_rss_lut
1113 * @adapter: adapter structure
1114 *
1115 * Request the PF to set our RSS lookup table
1116 **/
iavf_set_rss_lut(struct iavf_adapter * adapter)1117 void iavf_set_rss_lut(struct iavf_adapter *adapter)
1118 {
1119 struct virtchnl_rss_lut *vrl;
1120 int len;
1121
1122 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1123 /* bail because we already have a command pending */
1124 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
1125 adapter->current_op);
1126 return;
1127 }
1128 len = virtchnl_struct_size(vrl, lut, adapter->rss_lut_size);
1129 vrl = kzalloc(len, GFP_KERNEL);
1130 if (!vrl)
1131 return;
1132 vrl->vsi_id = adapter->vsi.id;
1133 vrl->lut_entries = adapter->rss_lut_size;
1134 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
1135 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
1136 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
1137 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
1138 kfree(vrl);
1139 }
1140
1141 /**
1142 * iavf_enable_vlan_stripping
1143 * @adapter: adapter structure
1144 *
1145 * Request VLAN header stripping to be enabled
1146 **/
iavf_enable_vlan_stripping(struct iavf_adapter * adapter)1147 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
1148 {
1149 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1150 /* bail because we already have a command pending */
1151 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
1152 adapter->current_op);
1153 return;
1154 }
1155 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
1156 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
1157 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
1158 }
1159
1160 /**
1161 * iavf_disable_vlan_stripping
1162 * @adapter: adapter structure
1163 *
1164 * Request VLAN header stripping to be disabled
1165 **/
iavf_disable_vlan_stripping(struct iavf_adapter * adapter)1166 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
1167 {
1168 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1169 /* bail because we already have a command pending */
1170 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
1171 adapter->current_op);
1172 return;
1173 }
1174 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
1175 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
1176 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
1177 }
1178
1179 /**
1180 * iavf_tpid_to_vc_ethertype - transform from VLAN TPID to virtchnl ethertype
1181 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1182 */
iavf_tpid_to_vc_ethertype(u16 tpid)1183 static u32 iavf_tpid_to_vc_ethertype(u16 tpid)
1184 {
1185 switch (tpid) {
1186 case ETH_P_8021Q:
1187 return VIRTCHNL_VLAN_ETHERTYPE_8100;
1188 case ETH_P_8021AD:
1189 return VIRTCHNL_VLAN_ETHERTYPE_88A8;
1190 }
1191
1192 return 0;
1193 }
1194
1195 /**
1196 * iavf_set_vc_offload_ethertype - set virtchnl ethertype for offload message
1197 * @adapter: adapter structure
1198 * @msg: message structure used for updating offloads over virtchnl to update
1199 * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1200 * @offload_op: opcode used to determine which support structure to check
1201 */
1202 static int
iavf_set_vc_offload_ethertype(struct iavf_adapter * adapter,struct virtchnl_vlan_setting * msg,u16 tpid,enum virtchnl_ops offload_op)1203 iavf_set_vc_offload_ethertype(struct iavf_adapter *adapter,
1204 struct virtchnl_vlan_setting *msg, u16 tpid,
1205 enum virtchnl_ops offload_op)
1206 {
1207 struct virtchnl_vlan_supported_caps *offload_support;
1208 u16 vc_ethertype = iavf_tpid_to_vc_ethertype(tpid);
1209
1210 /* reference the correct offload support structure */
1211 switch (offload_op) {
1212 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1213 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1214 offload_support =
1215 &adapter->vlan_v2_caps.offloads.stripping_support;
1216 break;
1217 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1218 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1219 offload_support =
1220 &adapter->vlan_v2_caps.offloads.insertion_support;
1221 break;
1222 default:
1223 dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
1224 offload_op);
1225 return -EINVAL;
1226 }
1227
1228 /* make sure ethertype is supported */
1229 if (offload_support->outer & vc_ethertype &&
1230 offload_support->outer & VIRTCHNL_VLAN_TOGGLE) {
1231 msg->outer_ethertype_setting = vc_ethertype;
1232 } else if (offload_support->inner & vc_ethertype &&
1233 offload_support->inner & VIRTCHNL_VLAN_TOGGLE) {
1234 msg->inner_ethertype_setting = vc_ethertype;
1235 } else {
1236 dev_dbg(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
1237 offload_op, tpid);
1238 return -EINVAL;
1239 }
1240
1241 return 0;
1242 }
1243
1244 /**
1245 * iavf_clear_offload_v2_aq_required - clear AQ required bit for offload request
1246 * @adapter: adapter structure
1247 * @tpid: VLAN TPID
1248 * @offload_op: opcode used to determine which AQ required bit to clear
1249 */
1250 static void
iavf_clear_offload_v2_aq_required(struct iavf_adapter * adapter,u16 tpid,enum virtchnl_ops offload_op)1251 iavf_clear_offload_v2_aq_required(struct iavf_adapter *adapter, u16 tpid,
1252 enum virtchnl_ops offload_op)
1253 {
1254 switch (offload_op) {
1255 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1256 if (tpid == ETH_P_8021Q)
1257 adapter->aq_required &=
1258 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING;
1259 else if (tpid == ETH_P_8021AD)
1260 adapter->aq_required &=
1261 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING;
1262 break;
1263 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1264 if (tpid == ETH_P_8021Q)
1265 adapter->aq_required &=
1266 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING;
1267 else if (tpid == ETH_P_8021AD)
1268 adapter->aq_required &=
1269 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING;
1270 break;
1271 case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1272 if (tpid == ETH_P_8021Q)
1273 adapter->aq_required &=
1274 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION;
1275 else if (tpid == ETH_P_8021AD)
1276 adapter->aq_required &=
1277 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION;
1278 break;
1279 case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1280 if (tpid == ETH_P_8021Q)
1281 adapter->aq_required &=
1282 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION;
1283 else if (tpid == ETH_P_8021AD)
1284 adapter->aq_required &=
1285 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION;
1286 break;
1287 default:
1288 dev_err(&adapter->pdev->dev, "Unsupported opcode %d specified for clearing aq_required bits for VIRTCHNL_VF_OFFLOAD_VLAN_V2 offload request\n",
1289 offload_op);
1290 }
1291 }
1292
1293 /**
1294 * iavf_send_vlan_offload_v2 - send offload enable/disable over virtchnl
1295 * @adapter: adapter structure
1296 * @tpid: VLAN TPID used for the command (i.e. 0x8100 or 0x88a8)
1297 * @offload_op: offload_op used to make the request over virtchnl
1298 */
1299 static void
iavf_send_vlan_offload_v2(struct iavf_adapter * adapter,u16 tpid,enum virtchnl_ops offload_op)1300 iavf_send_vlan_offload_v2(struct iavf_adapter *adapter, u16 tpid,
1301 enum virtchnl_ops offload_op)
1302 {
1303 struct virtchnl_vlan_setting *msg;
1304 int len = sizeof(*msg);
1305
1306 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1307 /* bail because we already have a command pending */
1308 dev_err(&adapter->pdev->dev, "Cannot send %d, command %d pending\n",
1309 offload_op, adapter->current_op);
1310 return;
1311 }
1312
1313 adapter->current_op = offload_op;
1314
1315 msg = kzalloc(len, GFP_KERNEL);
1316 if (!msg)
1317 return;
1318
1319 msg->vport_id = adapter->vsi_res->vsi_id;
1320
1321 /* always clear to prevent unsupported and endless requests */
1322 iavf_clear_offload_v2_aq_required(adapter, tpid, offload_op);
1323
1324 /* only send valid offload requests */
1325 if (!iavf_set_vc_offload_ethertype(adapter, msg, tpid, offload_op))
1326 iavf_send_pf_msg(adapter, offload_op, (u8 *)msg, len);
1327 else
1328 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1329
1330 kfree(msg);
1331 }
1332
1333 /**
1334 * iavf_enable_vlan_stripping_v2 - enable VLAN stripping
1335 * @adapter: adapter structure
1336 * @tpid: VLAN TPID used to enable VLAN stripping
1337 */
iavf_enable_vlan_stripping_v2(struct iavf_adapter * adapter,u16 tpid)1338 void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1339 {
1340 iavf_send_vlan_offload_v2(adapter, tpid,
1341 VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2);
1342 }
1343
1344 /**
1345 * iavf_disable_vlan_stripping_v2 - disable VLAN stripping
1346 * @adapter: adapter structure
1347 * @tpid: VLAN TPID used to disable VLAN stripping
1348 */
iavf_disable_vlan_stripping_v2(struct iavf_adapter * adapter,u16 tpid)1349 void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1350 {
1351 iavf_send_vlan_offload_v2(adapter, tpid,
1352 VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2);
1353 }
1354
1355 /**
1356 * iavf_enable_vlan_insertion_v2 - enable VLAN insertion
1357 * @adapter: adapter structure
1358 * @tpid: VLAN TPID used to enable VLAN insertion
1359 */
iavf_enable_vlan_insertion_v2(struct iavf_adapter * adapter,u16 tpid)1360 void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1361 {
1362 iavf_send_vlan_offload_v2(adapter, tpid,
1363 VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2);
1364 }
1365
1366 /**
1367 * iavf_disable_vlan_insertion_v2 - disable VLAN insertion
1368 * @adapter: adapter structure
1369 * @tpid: VLAN TPID used to disable VLAN insertion
1370 */
iavf_disable_vlan_insertion_v2(struct iavf_adapter * adapter,u16 tpid)1371 void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1372 {
1373 iavf_send_vlan_offload_v2(adapter, tpid,
1374 VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2);
1375 }
1376
1377 #define IAVF_MAX_SPEED_STRLEN 13
1378
1379 /**
1380 * iavf_print_link_message - print link up or down
1381 * @adapter: adapter structure
1382 *
1383 * Log a message telling the world of our wonderous link status
1384 */
iavf_print_link_message(struct iavf_adapter * adapter)1385 static void iavf_print_link_message(struct iavf_adapter *adapter)
1386 {
1387 struct net_device *netdev = adapter->netdev;
1388 int link_speed_mbps;
1389 char *speed;
1390
1391 if (!adapter->link_up) {
1392 netdev_info(netdev, "NIC Link is Down\n");
1393 return;
1394 }
1395
1396 speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
1397 if (!speed)
1398 return;
1399
1400 if (ADV_LINK_SUPPORT(adapter)) {
1401 link_speed_mbps = adapter->link_speed_mbps;
1402 goto print_link_msg;
1403 }
1404
1405 switch (adapter->link_speed) {
1406 case VIRTCHNL_LINK_SPEED_40GB:
1407 link_speed_mbps = SPEED_40000;
1408 break;
1409 case VIRTCHNL_LINK_SPEED_25GB:
1410 link_speed_mbps = SPEED_25000;
1411 break;
1412 case VIRTCHNL_LINK_SPEED_20GB:
1413 link_speed_mbps = SPEED_20000;
1414 break;
1415 case VIRTCHNL_LINK_SPEED_10GB:
1416 link_speed_mbps = SPEED_10000;
1417 break;
1418 case VIRTCHNL_LINK_SPEED_5GB:
1419 link_speed_mbps = SPEED_5000;
1420 break;
1421 case VIRTCHNL_LINK_SPEED_2_5GB:
1422 link_speed_mbps = SPEED_2500;
1423 break;
1424 case VIRTCHNL_LINK_SPEED_1GB:
1425 link_speed_mbps = SPEED_1000;
1426 break;
1427 case VIRTCHNL_LINK_SPEED_100MB:
1428 link_speed_mbps = SPEED_100;
1429 break;
1430 default:
1431 link_speed_mbps = SPEED_UNKNOWN;
1432 break;
1433 }
1434
1435 print_link_msg:
1436 if (link_speed_mbps > SPEED_1000) {
1437 if (link_speed_mbps == SPEED_2500)
1438 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps");
1439 else
1440 /* convert to Gbps inline */
1441 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1442 link_speed_mbps / 1000, "Gbps");
1443 } else if (link_speed_mbps == SPEED_UNKNOWN) {
1444 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps");
1445 } else {
1446 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1447 link_speed_mbps, "Mbps");
1448 }
1449
1450 netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1451 kfree(speed);
1452 }
1453
1454 /**
1455 * iavf_get_vpe_link_status
1456 * @adapter: adapter structure
1457 * @vpe: virtchnl_pf_event structure
1458 *
1459 * Helper function for determining the link status
1460 **/
1461 static bool
iavf_get_vpe_link_status(struct iavf_adapter * adapter,struct virtchnl_pf_event * vpe)1462 iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1463 struct virtchnl_pf_event *vpe)
1464 {
1465 if (ADV_LINK_SUPPORT(adapter))
1466 return vpe->event_data.link_event_adv.link_status;
1467 else
1468 return vpe->event_data.link_event.link_status;
1469 }
1470
1471 /**
1472 * iavf_set_adapter_link_speed_from_vpe
1473 * @adapter: adapter structure for which we are setting the link speed
1474 * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1475 *
1476 * Helper function for setting iavf_adapter link speed
1477 **/
1478 static void
iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter * adapter,struct virtchnl_pf_event * vpe)1479 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1480 struct virtchnl_pf_event *vpe)
1481 {
1482 if (ADV_LINK_SUPPORT(adapter))
1483 adapter->link_speed_mbps =
1484 vpe->event_data.link_event_adv.link_speed;
1485 else
1486 adapter->link_speed = vpe->event_data.link_event.link_speed;
1487 }
1488
1489 /**
1490 * iavf_enable_channels
1491 * @adapter: adapter structure
1492 *
1493 * Request that the PF enable channels as specified by
1494 * the user via tc tool.
1495 **/
iavf_enable_channels(struct iavf_adapter * adapter)1496 void iavf_enable_channels(struct iavf_adapter *adapter)
1497 {
1498 struct virtchnl_tc_info *vti = NULL;
1499 size_t len;
1500 int i;
1501
1502 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1503 /* bail because we already have a command pending */
1504 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1505 adapter->current_op);
1506 return;
1507 }
1508
1509 len = virtchnl_struct_size(vti, list, adapter->num_tc);
1510 vti = kzalloc(len, GFP_KERNEL);
1511 if (!vti)
1512 return;
1513 vti->num_tc = adapter->num_tc;
1514 for (i = 0; i < vti->num_tc; i++) {
1515 vti->list[i].count = adapter->ch_config.ch_info[i].count;
1516 vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1517 vti->list[i].pad = 0;
1518 vti->list[i].max_tx_rate =
1519 adapter->ch_config.ch_info[i].max_tx_rate;
1520 }
1521
1522 adapter->ch_config.state = __IAVF_TC_RUNNING;
1523 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1524 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1525 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1526 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1527 kfree(vti);
1528 }
1529
1530 /**
1531 * iavf_disable_channels
1532 * @adapter: adapter structure
1533 *
1534 * Request that the PF disable channels that are configured
1535 **/
iavf_disable_channels(struct iavf_adapter * adapter)1536 void iavf_disable_channels(struct iavf_adapter *adapter)
1537 {
1538 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1539 /* bail because we already have a command pending */
1540 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1541 adapter->current_op);
1542 return;
1543 }
1544
1545 adapter->ch_config.state = __IAVF_TC_INVALID;
1546 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1547 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1548 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1549 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1550 }
1551
1552 /**
1553 * iavf_print_cloud_filter
1554 * @adapter: adapter structure
1555 * @f: cloud filter to print
1556 *
1557 * Print the cloud filter
1558 **/
iavf_print_cloud_filter(struct iavf_adapter * adapter,struct virtchnl_filter * f)1559 static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1560 struct virtchnl_filter *f)
1561 {
1562 switch (f->flow_type) {
1563 case VIRTCHNL_TCP_V4_FLOW:
1564 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",
1565 &f->data.tcp_spec.dst_mac,
1566 &f->data.tcp_spec.src_mac,
1567 ntohs(f->data.tcp_spec.vlan_id),
1568 &f->data.tcp_spec.dst_ip[0],
1569 &f->data.tcp_spec.src_ip[0],
1570 ntohs(f->data.tcp_spec.dst_port),
1571 ntohs(f->data.tcp_spec.src_port));
1572 break;
1573 case VIRTCHNL_TCP_V6_FLOW:
1574 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",
1575 &f->data.tcp_spec.dst_mac,
1576 &f->data.tcp_spec.src_mac,
1577 ntohs(f->data.tcp_spec.vlan_id),
1578 &f->data.tcp_spec.dst_ip,
1579 &f->data.tcp_spec.src_ip,
1580 ntohs(f->data.tcp_spec.dst_port),
1581 ntohs(f->data.tcp_spec.src_port));
1582 break;
1583 }
1584 }
1585
1586 /**
1587 * iavf_add_cloud_filter
1588 * @adapter: adapter structure
1589 *
1590 * Request that the PF add cloud filters as specified
1591 * by the user via tc tool.
1592 **/
iavf_add_cloud_filter(struct iavf_adapter * adapter)1593 void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1594 {
1595 struct iavf_cloud_filter *cf;
1596 struct virtchnl_filter *f;
1597 int len = 0, count = 0;
1598
1599 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1600 /* bail because we already have a command pending */
1601 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1602 adapter->current_op);
1603 return;
1604 }
1605 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1606 if (cf->add) {
1607 count++;
1608 break;
1609 }
1610 }
1611 if (!count) {
1612 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1613 return;
1614 }
1615 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1616
1617 len = sizeof(struct virtchnl_filter);
1618 f = kzalloc(len, GFP_KERNEL);
1619 if (!f)
1620 return;
1621
1622 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1623 if (cf->add) {
1624 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1625 cf->add = false;
1626 cf->state = __IAVF_CF_ADD_PENDING;
1627 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1628 (u8 *)f, len);
1629 }
1630 }
1631 kfree(f);
1632 }
1633
1634 /**
1635 * iavf_del_cloud_filter
1636 * @adapter: adapter structure
1637 *
1638 * Request that the PF delete cloud filters as specified
1639 * by the user via tc tool.
1640 **/
iavf_del_cloud_filter(struct iavf_adapter * adapter)1641 void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1642 {
1643 struct iavf_cloud_filter *cf, *cftmp;
1644 struct virtchnl_filter *f;
1645 int len = 0, count = 0;
1646
1647 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1648 /* bail because we already have a command pending */
1649 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1650 adapter->current_op);
1651 return;
1652 }
1653 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1654 if (cf->del) {
1655 count++;
1656 break;
1657 }
1658 }
1659 if (!count) {
1660 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1661 return;
1662 }
1663 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1664
1665 len = sizeof(struct virtchnl_filter);
1666 f = kzalloc(len, GFP_KERNEL);
1667 if (!f)
1668 return;
1669
1670 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1671 if (cf->del) {
1672 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1673 cf->del = false;
1674 cf->state = __IAVF_CF_DEL_PENDING;
1675 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1676 (u8 *)f, len);
1677 }
1678 }
1679 kfree(f);
1680 }
1681
1682 /**
1683 * iavf_add_fdir_filter
1684 * @adapter: the VF adapter structure
1685 *
1686 * Request that the PF add Flow Director filters as specified
1687 * by the user via ethtool.
1688 **/
iavf_add_fdir_filter(struct iavf_adapter * adapter)1689 void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1690 {
1691 struct iavf_fdir_fltr *fdir;
1692 struct virtchnl_fdir_add *f;
1693 bool process_fltr = false;
1694 int len;
1695
1696 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1697 /* bail because we already have a command pending */
1698 dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1699 adapter->current_op);
1700 return;
1701 }
1702
1703 len = sizeof(struct virtchnl_fdir_add);
1704 f = kzalloc(len, GFP_KERNEL);
1705 if (!f)
1706 return;
1707
1708 spin_lock_bh(&adapter->fdir_fltr_lock);
1709 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1710 if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1711 process_fltr = true;
1712 fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1713 memcpy(f, &fdir->vc_add_msg, len);
1714 break;
1715 }
1716 }
1717 spin_unlock_bh(&adapter->fdir_fltr_lock);
1718
1719 if (!process_fltr) {
1720 /* prevent iavf_add_fdir_filter() from being called when there
1721 * are no filters to add
1722 */
1723 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1724 kfree(f);
1725 return;
1726 }
1727 adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1728 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1729 kfree(f);
1730 }
1731
1732 /**
1733 * iavf_del_fdir_filter
1734 * @adapter: the VF adapter structure
1735 *
1736 * Request that the PF delete Flow Director filters as specified
1737 * by the user via ethtool.
1738 **/
iavf_del_fdir_filter(struct iavf_adapter * adapter)1739 void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1740 {
1741 struct virtchnl_fdir_del f = {};
1742 struct iavf_fdir_fltr *fdir;
1743 bool process_fltr = false;
1744 int len;
1745
1746 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1747 /* bail because we already have a command pending */
1748 dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1749 adapter->current_op);
1750 return;
1751 }
1752
1753 len = sizeof(struct virtchnl_fdir_del);
1754
1755 spin_lock_bh(&adapter->fdir_fltr_lock);
1756 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1757 if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) {
1758 process_fltr = true;
1759 f.vsi_id = fdir->vc_add_msg.vsi_id;
1760 f.flow_id = fdir->flow_id;
1761 fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1762 break;
1763 } else if (fdir->state == IAVF_FDIR_FLTR_DIS_REQUEST) {
1764 process_fltr = true;
1765 f.vsi_id = fdir->vc_add_msg.vsi_id;
1766 f.flow_id = fdir->flow_id;
1767 fdir->state = IAVF_FDIR_FLTR_DIS_PENDING;
1768 break;
1769 }
1770 }
1771 spin_unlock_bh(&adapter->fdir_fltr_lock);
1772
1773 if (!process_fltr) {
1774 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1775 return;
1776 }
1777
1778 adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1779 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1780 }
1781
1782 /**
1783 * iavf_add_adv_rss_cfg
1784 * @adapter: the VF adapter structure
1785 *
1786 * Request that the PF add RSS configuration as specified
1787 * by the user via ethtool.
1788 **/
iavf_add_adv_rss_cfg(struct iavf_adapter * adapter)1789 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1790 {
1791 struct virtchnl_rss_cfg *rss_cfg;
1792 struct iavf_adv_rss *rss;
1793 bool process_rss = false;
1794 int len;
1795
1796 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1797 /* bail because we already have a command pending */
1798 dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1799 adapter->current_op);
1800 return;
1801 }
1802
1803 len = sizeof(struct virtchnl_rss_cfg);
1804 rss_cfg = kzalloc(len, GFP_KERNEL);
1805 if (!rss_cfg)
1806 return;
1807
1808 spin_lock_bh(&adapter->adv_rss_lock);
1809 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1810 if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) {
1811 process_rss = true;
1812 rss->state = IAVF_ADV_RSS_ADD_PENDING;
1813 memcpy(rss_cfg, &rss->cfg_msg, len);
1814 iavf_print_adv_rss_cfg(adapter, rss,
1815 "Input set change for",
1816 "is pending");
1817 break;
1818 }
1819 }
1820 spin_unlock_bh(&adapter->adv_rss_lock);
1821
1822 if (process_rss) {
1823 adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1824 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1825 (u8 *)rss_cfg, len);
1826 } else {
1827 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1828 }
1829
1830 kfree(rss_cfg);
1831 }
1832
1833 /**
1834 * iavf_del_adv_rss_cfg
1835 * @adapter: the VF adapter structure
1836 *
1837 * Request that the PF delete RSS configuration as specified
1838 * by the user via ethtool.
1839 **/
iavf_del_adv_rss_cfg(struct iavf_adapter * adapter)1840 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1841 {
1842 struct virtchnl_rss_cfg *rss_cfg;
1843 struct iavf_adv_rss *rss;
1844 bool process_rss = false;
1845 int len;
1846
1847 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1848 /* bail because we already have a command pending */
1849 dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1850 adapter->current_op);
1851 return;
1852 }
1853
1854 len = sizeof(struct virtchnl_rss_cfg);
1855 rss_cfg = kzalloc(len, GFP_KERNEL);
1856 if (!rss_cfg)
1857 return;
1858
1859 spin_lock_bh(&adapter->adv_rss_lock);
1860 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1861 if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
1862 process_rss = true;
1863 rss->state = IAVF_ADV_RSS_DEL_PENDING;
1864 memcpy(rss_cfg, &rss->cfg_msg, len);
1865 break;
1866 }
1867 }
1868 spin_unlock_bh(&adapter->adv_rss_lock);
1869
1870 if (process_rss) {
1871 adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
1872 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
1873 (u8 *)rss_cfg, len);
1874 } else {
1875 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
1876 }
1877
1878 kfree(rss_cfg);
1879 }
1880
1881 /**
1882 * iavf_request_reset
1883 * @adapter: adapter structure
1884 *
1885 * Request that the PF reset this VF. No response is expected.
1886 **/
iavf_request_reset(struct iavf_adapter * adapter)1887 int iavf_request_reset(struct iavf_adapter *adapter)
1888 {
1889 int err;
1890 /* Don't check CURRENT_OP - this is always higher priority */
1891 err = iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1892 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1893 return err;
1894 }
1895
1896 /**
1897 * iavf_netdev_features_vlan_strip_set - update vlan strip status
1898 * @netdev: ptr to netdev being adjusted
1899 * @enable: enable or disable vlan strip
1900 *
1901 * Helper function to change vlan strip status in netdev->features.
1902 */
iavf_netdev_features_vlan_strip_set(struct net_device * netdev,const bool enable)1903 static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev,
1904 const bool enable)
1905 {
1906 if (enable)
1907 netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1908 else
1909 netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
1910 }
1911
1912 /**
1913 * iavf_activate_fdir_filters - Reactivate all FDIR filters after a reset
1914 * @adapter: private adapter structure
1915 *
1916 * Called after a reset to re-add all FDIR filters and delete some of them
1917 * if they were pending to be deleted.
1918 */
iavf_activate_fdir_filters(struct iavf_adapter * adapter)1919 static void iavf_activate_fdir_filters(struct iavf_adapter *adapter)
1920 {
1921 struct iavf_fdir_fltr *f, *ftmp;
1922 bool add_filters = false;
1923
1924 spin_lock_bh(&adapter->fdir_fltr_lock);
1925 list_for_each_entry_safe(f, ftmp, &adapter->fdir_list_head, list) {
1926 if (f->state == IAVF_FDIR_FLTR_ADD_REQUEST ||
1927 f->state == IAVF_FDIR_FLTR_ADD_PENDING ||
1928 f->state == IAVF_FDIR_FLTR_ACTIVE) {
1929 /* All filters and requests have been removed in PF,
1930 * restore them
1931 */
1932 f->state = IAVF_FDIR_FLTR_ADD_REQUEST;
1933 add_filters = true;
1934 } else if (f->state == IAVF_FDIR_FLTR_DIS_REQUEST ||
1935 f->state == IAVF_FDIR_FLTR_DIS_PENDING) {
1936 /* Link down state, leave filters as inactive */
1937 f->state = IAVF_FDIR_FLTR_INACTIVE;
1938 } else if (f->state == IAVF_FDIR_FLTR_DEL_REQUEST ||
1939 f->state == IAVF_FDIR_FLTR_DEL_PENDING) {
1940 /* Delete filters that were pending to be deleted, the
1941 * list on PF is already cleared after a reset
1942 */
1943 list_del(&f->list);
1944 kfree(f);
1945 adapter->fdir_active_fltr--;
1946 }
1947 }
1948 spin_unlock_bh(&adapter->fdir_fltr_lock);
1949
1950 if (add_filters)
1951 adapter->aq_required |= IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1952 }
1953
1954 /**
1955 * iavf_virtchnl_completion
1956 * @adapter: adapter structure
1957 * @v_opcode: opcode sent by PF
1958 * @v_retval: retval sent by PF
1959 * @msg: message sent by PF
1960 * @msglen: message length
1961 *
1962 * Asynchronous completion function for admin queue messages. Rather than busy
1963 * wait, we fire off our requests and assume that no errors will be returned.
1964 * This function handles the reply messages.
1965 **/
iavf_virtchnl_completion(struct iavf_adapter * adapter,enum virtchnl_ops v_opcode,enum iavf_status v_retval,u8 * msg,u16 msglen)1966 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1967 enum virtchnl_ops v_opcode,
1968 enum iavf_status v_retval, u8 *msg, u16 msglen)
1969 {
1970 struct net_device *netdev = adapter->netdev;
1971
1972 if (v_opcode == VIRTCHNL_OP_EVENT) {
1973 struct virtchnl_pf_event *vpe =
1974 (struct virtchnl_pf_event *)msg;
1975 bool link_up = iavf_get_vpe_link_status(adapter, vpe);
1976
1977 switch (vpe->event) {
1978 case VIRTCHNL_EVENT_LINK_CHANGE:
1979 iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
1980
1981 /* we've already got the right link status, bail */
1982 if (adapter->link_up == link_up)
1983 break;
1984
1985 if (link_up) {
1986 /* If we get link up message and start queues
1987 * before our queues are configured it will
1988 * trigger a TX hang. In that case, just ignore
1989 * the link status message,we'll get another one
1990 * after we enable queues and actually prepared
1991 * to send traffic.
1992 */
1993 if (adapter->state != __IAVF_RUNNING)
1994 break;
1995
1996 /* For ADq enabled VF, we reconfigure VSIs and
1997 * re-allocate queues. Hence wait till all
1998 * queues are enabled.
1999 */
2000 if (adapter->flags &
2001 IAVF_FLAG_QUEUES_DISABLED)
2002 break;
2003 }
2004
2005 adapter->link_up = link_up;
2006 if (link_up) {
2007 netif_tx_start_all_queues(netdev);
2008 netif_carrier_on(netdev);
2009 } else {
2010 netif_tx_stop_all_queues(netdev);
2011 netif_carrier_off(netdev);
2012 }
2013 iavf_print_link_message(adapter);
2014 break;
2015 case VIRTCHNL_EVENT_RESET_IMPENDING:
2016 dev_info(&adapter->pdev->dev, "Reset indication received from the PF\n");
2017 if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
2018 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
2019 iavf_schedule_reset(adapter, IAVF_FLAG_RESET_PENDING);
2020 }
2021 break;
2022 default:
2023 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
2024 vpe->event);
2025 break;
2026 }
2027 return;
2028 }
2029 if (v_retval) {
2030 switch (v_opcode) {
2031 case VIRTCHNL_OP_ADD_VLAN:
2032 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2033 iavf_stat_str(&adapter->hw, v_retval));
2034 break;
2035 case VIRTCHNL_OP_ADD_ETH_ADDR:
2036 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
2037 iavf_stat_str(&adapter->hw, v_retval));
2038 iavf_mac_add_reject(adapter);
2039 /* restore administratively set MAC address */
2040 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2041 wake_up(&adapter->vc_waitqueue);
2042 break;
2043 case VIRTCHNL_OP_DEL_VLAN:
2044 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
2045 iavf_stat_str(&adapter->hw, v_retval));
2046 break;
2047 case VIRTCHNL_OP_DEL_ETH_ADDR:
2048 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
2049 iavf_stat_str(&adapter->hw, v_retval));
2050 break;
2051 case VIRTCHNL_OP_ENABLE_CHANNELS:
2052 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
2053 iavf_stat_str(&adapter->hw, v_retval));
2054 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2055 adapter->ch_config.state = __IAVF_TC_INVALID;
2056 netdev_reset_tc(netdev);
2057 netif_tx_start_all_queues(netdev);
2058 break;
2059 case VIRTCHNL_OP_DISABLE_CHANNELS:
2060 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
2061 iavf_stat_str(&adapter->hw, v_retval));
2062 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2063 adapter->ch_config.state = __IAVF_TC_RUNNING;
2064 netif_tx_start_all_queues(netdev);
2065 break;
2066 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2067 struct iavf_cloud_filter *cf, *cftmp;
2068
2069 list_for_each_entry_safe(cf, cftmp,
2070 &adapter->cloud_filter_list,
2071 list) {
2072 if (cf->state == __IAVF_CF_ADD_PENDING) {
2073 cf->state = __IAVF_CF_INVALID;
2074 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
2075 iavf_stat_str(&adapter->hw,
2076 v_retval));
2077 iavf_print_cloud_filter(adapter,
2078 &cf->f);
2079 list_del(&cf->list);
2080 kfree(cf);
2081 adapter->num_cloud_filters--;
2082 }
2083 }
2084 }
2085 break;
2086 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2087 struct iavf_cloud_filter *cf;
2088
2089 list_for_each_entry(cf, &adapter->cloud_filter_list,
2090 list) {
2091 if (cf->state == __IAVF_CF_DEL_PENDING) {
2092 cf->state = __IAVF_CF_ACTIVE;
2093 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
2094 iavf_stat_str(&adapter->hw,
2095 v_retval));
2096 iavf_print_cloud_filter(adapter,
2097 &cf->f);
2098 }
2099 }
2100 }
2101 break;
2102 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2103 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2104
2105 spin_lock_bh(&adapter->fdir_fltr_lock);
2106 list_for_each_entry_safe(fdir, fdir_tmp,
2107 &adapter->fdir_list_head,
2108 list) {
2109 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2110 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
2111 iavf_stat_str(&adapter->hw,
2112 v_retval));
2113 iavf_print_fdir_fltr(adapter, fdir);
2114 if (msglen)
2115 dev_err(&adapter->pdev->dev,
2116 "%s\n", msg);
2117 list_del(&fdir->list);
2118 kfree(fdir);
2119 adapter->fdir_active_fltr--;
2120 }
2121 }
2122 spin_unlock_bh(&adapter->fdir_fltr_lock);
2123 }
2124 break;
2125 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2126 struct iavf_fdir_fltr *fdir;
2127
2128 spin_lock_bh(&adapter->fdir_fltr_lock);
2129 list_for_each_entry(fdir, &adapter->fdir_list_head,
2130 list) {
2131 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING ||
2132 fdir->state == IAVF_FDIR_FLTR_DIS_PENDING) {
2133 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2134 dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
2135 iavf_stat_str(&adapter->hw,
2136 v_retval));
2137 iavf_print_fdir_fltr(adapter, fdir);
2138 }
2139 }
2140 spin_unlock_bh(&adapter->fdir_fltr_lock);
2141 }
2142 break;
2143 case VIRTCHNL_OP_ADD_RSS_CFG: {
2144 struct iavf_adv_rss *rss, *rss_tmp;
2145
2146 spin_lock_bh(&adapter->adv_rss_lock);
2147 list_for_each_entry_safe(rss, rss_tmp,
2148 &adapter->adv_rss_list_head,
2149 list) {
2150 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2151 iavf_print_adv_rss_cfg(adapter, rss,
2152 "Failed to change the input set for",
2153 NULL);
2154 list_del(&rss->list);
2155 kfree(rss);
2156 }
2157 }
2158 spin_unlock_bh(&adapter->adv_rss_lock);
2159 }
2160 break;
2161 case VIRTCHNL_OP_DEL_RSS_CFG: {
2162 struct iavf_adv_rss *rss;
2163
2164 spin_lock_bh(&adapter->adv_rss_lock);
2165 list_for_each_entry(rss, &adapter->adv_rss_list_head,
2166 list) {
2167 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2168 rss->state = IAVF_ADV_RSS_ACTIVE;
2169 dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
2170 iavf_stat_str(&adapter->hw,
2171 v_retval));
2172 }
2173 }
2174 spin_unlock_bh(&adapter->adv_rss_lock);
2175 }
2176 break;
2177 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2178 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2179 /* Vlan stripping could not be enabled by ethtool.
2180 * Disable it in netdev->features.
2181 */
2182 iavf_netdev_features_vlan_strip_set(netdev, false);
2183 break;
2184 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2185 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2186 /* Vlan stripping could not be disabled by ethtool.
2187 * Enable it in netdev->features.
2188 */
2189 iavf_netdev_features_vlan_strip_set(netdev, true);
2190 break;
2191 case VIRTCHNL_OP_ADD_VLAN_V2:
2192 iavf_vlan_add_reject(adapter);
2193 dev_warn(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2194 iavf_stat_str(&adapter->hw, v_retval));
2195 break;
2196 default:
2197 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
2198 v_retval, iavf_stat_str(&adapter->hw, v_retval),
2199 v_opcode);
2200 }
2201 }
2202 switch (v_opcode) {
2203 case VIRTCHNL_OP_ADD_ETH_ADDR:
2204 if (!v_retval)
2205 iavf_mac_add_ok(adapter);
2206 if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
2207 if (!ether_addr_equal(netdev->dev_addr,
2208 adapter->hw.mac.addr)) {
2209 netif_addr_lock_bh(netdev);
2210 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2211 netif_addr_unlock_bh(netdev);
2212 }
2213 wake_up(&adapter->vc_waitqueue);
2214 break;
2215 case VIRTCHNL_OP_GET_STATS: {
2216 struct iavf_eth_stats *stats =
2217 (struct iavf_eth_stats *)msg;
2218 netdev->stats.rx_packets = stats->rx_unicast +
2219 stats->rx_multicast +
2220 stats->rx_broadcast;
2221 netdev->stats.tx_packets = stats->tx_unicast +
2222 stats->tx_multicast +
2223 stats->tx_broadcast;
2224 netdev->stats.rx_bytes = stats->rx_bytes;
2225 netdev->stats.tx_bytes = stats->tx_bytes;
2226 netdev->stats.tx_errors = stats->tx_errors;
2227 netdev->stats.rx_dropped = stats->rx_discards;
2228 netdev->stats.tx_dropped = stats->tx_discards;
2229 adapter->current_stats = *stats;
2230 }
2231 break;
2232 case VIRTCHNL_OP_GET_VF_RESOURCES: {
2233 u16 len = IAVF_VIRTCHNL_VF_RESOURCE_SIZE;
2234
2235 memcpy(adapter->vf_res, msg, min(msglen, len));
2236 iavf_validate_num_queues(adapter);
2237 iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
2238 if (is_zero_ether_addr(adapter->hw.mac.addr)) {
2239 /* restore current mac address */
2240 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2241 } else {
2242 netif_addr_lock_bh(netdev);
2243 /* refresh current mac address if changed */
2244 ether_addr_copy(netdev->perm_addr,
2245 adapter->hw.mac.addr);
2246 netif_addr_unlock_bh(netdev);
2247 }
2248 spin_lock_bh(&adapter->mac_vlan_list_lock);
2249 iavf_add_filter(adapter, adapter->hw.mac.addr);
2250
2251 if (VLAN_ALLOWED(adapter)) {
2252 if (!list_empty(&adapter->vlan_filter_list)) {
2253 struct iavf_vlan_filter *vlf;
2254
2255 /* re-add all VLAN filters over virtchnl */
2256 list_for_each_entry(vlf,
2257 &adapter->vlan_filter_list,
2258 list)
2259 vlf->state = IAVF_VLAN_ADD;
2260
2261 adapter->aq_required |=
2262 IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2263 }
2264 }
2265
2266 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2267
2268 iavf_activate_fdir_filters(adapter);
2269
2270 iavf_parse_vf_resource_msg(adapter);
2271
2272 /* negotiated VIRTCHNL_VF_OFFLOAD_VLAN_V2, so wait for the
2273 * response to VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS to finish
2274 * configuration
2275 */
2276 if (VLAN_V2_ALLOWED(adapter))
2277 break;
2278 /* fallthrough and finish config if VIRTCHNL_VF_OFFLOAD_VLAN_V2
2279 * wasn't successfully negotiated with the PF
2280 */
2281 }
2282 fallthrough;
2283 case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: {
2284 struct iavf_mac_filter *f;
2285 bool was_mac_changed;
2286 u64 aq_required = 0;
2287
2288 if (v_opcode == VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS)
2289 memcpy(&adapter->vlan_v2_caps, msg,
2290 min_t(u16, msglen,
2291 sizeof(adapter->vlan_v2_caps)));
2292
2293 iavf_process_config(adapter);
2294 adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES;
2295 iavf_schedule_finish_config(adapter);
2296
2297 iavf_set_queue_vlan_tag_loc(adapter);
2298
2299 was_mac_changed = !ether_addr_equal(netdev->dev_addr,
2300 adapter->hw.mac.addr);
2301
2302 spin_lock_bh(&adapter->mac_vlan_list_lock);
2303
2304 /* re-add all MAC filters */
2305 list_for_each_entry(f, &adapter->mac_filter_list, list) {
2306 if (was_mac_changed &&
2307 ether_addr_equal(netdev->dev_addr, f->macaddr))
2308 ether_addr_copy(f->macaddr,
2309 adapter->hw.mac.addr);
2310
2311 f->is_new_mac = true;
2312 f->add = true;
2313 f->add_handled = false;
2314 f->remove = false;
2315 }
2316
2317 /* re-add all VLAN filters */
2318 if (VLAN_FILTERING_ALLOWED(adapter)) {
2319 struct iavf_vlan_filter *vlf;
2320
2321 if (!list_empty(&adapter->vlan_filter_list)) {
2322 list_for_each_entry(vlf,
2323 &adapter->vlan_filter_list,
2324 list)
2325 vlf->state = IAVF_VLAN_ADD;
2326
2327 aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2328 }
2329 }
2330
2331 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2332
2333 netif_addr_lock_bh(netdev);
2334 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2335 netif_addr_unlock_bh(netdev);
2336
2337 adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER |
2338 aq_required;
2339 }
2340 break;
2341 case VIRTCHNL_OP_ENABLE_QUEUES:
2342 /* enable transmits */
2343 iavf_irq_enable(adapter, true);
2344 wake_up(&adapter->reset_waitqueue);
2345 adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
2346 break;
2347 case VIRTCHNL_OP_DISABLE_QUEUES:
2348 iavf_free_all_tx_resources(adapter);
2349 iavf_free_all_rx_resources(adapter);
2350 if (adapter->state == __IAVF_DOWN_PENDING) {
2351 iavf_change_state(adapter, __IAVF_DOWN);
2352 wake_up(&adapter->down_waitqueue);
2353 }
2354 break;
2355 case VIRTCHNL_OP_VERSION:
2356 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
2357 /* Don't display an error if we get these out of sequence.
2358 * If the firmware needed to get kicked, we'll get these and
2359 * it's no problem.
2360 */
2361 if (v_opcode != adapter->current_op)
2362 return;
2363 break;
2364 case VIRTCHNL_OP_RDMA:
2365 /* Gobble zero-length replies from the PF. They indicate that
2366 * a previous message was received OK, and the client doesn't
2367 * care about that.
2368 */
2369 if (msglen && CLIENT_ENABLED(adapter))
2370 iavf_notify_client_message(&adapter->vsi, msg, msglen);
2371 break;
2372
2373 case VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP:
2374 adapter->client_pending &=
2375 ~(BIT(VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP));
2376 break;
2377 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
2378 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2379
2380 if (msglen == sizeof(*vrh))
2381 adapter->hena = vrh->hena;
2382 else
2383 dev_warn(&adapter->pdev->dev,
2384 "Invalid message %d from PF\n", v_opcode);
2385 }
2386 break;
2387 case VIRTCHNL_OP_REQUEST_QUEUES: {
2388 struct virtchnl_vf_res_request *vfres =
2389 (struct virtchnl_vf_res_request *)msg;
2390
2391 if (vfres->num_queue_pairs != adapter->num_req_queues) {
2392 dev_info(&adapter->pdev->dev,
2393 "Requested %d queues, PF can support %d\n",
2394 adapter->num_req_queues,
2395 vfres->num_queue_pairs);
2396 adapter->num_req_queues = 0;
2397 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2398 }
2399 }
2400 break;
2401 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2402 struct iavf_cloud_filter *cf;
2403
2404 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
2405 if (cf->state == __IAVF_CF_ADD_PENDING)
2406 cf->state = __IAVF_CF_ACTIVE;
2407 }
2408 }
2409 break;
2410 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2411 struct iavf_cloud_filter *cf, *cftmp;
2412
2413 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
2414 list) {
2415 if (cf->state == __IAVF_CF_DEL_PENDING) {
2416 cf->state = __IAVF_CF_INVALID;
2417 list_del(&cf->list);
2418 kfree(cf);
2419 adapter->num_cloud_filters--;
2420 }
2421 }
2422 }
2423 break;
2424 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2425 struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
2426 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2427
2428 spin_lock_bh(&adapter->fdir_fltr_lock);
2429 list_for_each_entry_safe(fdir, fdir_tmp,
2430 &adapter->fdir_list_head,
2431 list) {
2432 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2433 if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2434 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
2435 fdir->loc);
2436 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2437 fdir->flow_id = add_fltr->flow_id;
2438 } else {
2439 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
2440 add_fltr->status);
2441 iavf_print_fdir_fltr(adapter, fdir);
2442 list_del(&fdir->list);
2443 kfree(fdir);
2444 adapter->fdir_active_fltr--;
2445 }
2446 }
2447 }
2448 spin_unlock_bh(&adapter->fdir_fltr_lock);
2449 }
2450 break;
2451 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2452 struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
2453 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2454
2455 spin_lock_bh(&adapter->fdir_fltr_lock);
2456 list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
2457 list) {
2458 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2459 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS ||
2460 del_fltr->status ==
2461 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
2462 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
2463 fdir->loc);
2464 list_del(&fdir->list);
2465 kfree(fdir);
2466 adapter->fdir_active_fltr--;
2467 } else {
2468 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2469 dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
2470 del_fltr->status);
2471 iavf_print_fdir_fltr(adapter, fdir);
2472 }
2473 } else if (fdir->state == IAVF_FDIR_FLTR_DIS_PENDING) {
2474 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS ||
2475 del_fltr->status ==
2476 VIRTCHNL_FDIR_FAILURE_RULE_NONEXIST) {
2477 fdir->state = IAVF_FDIR_FLTR_INACTIVE;
2478 } else {
2479 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2480 dev_info(&adapter->pdev->dev, "Failed to disable Flow Director filter with status: %d\n",
2481 del_fltr->status);
2482 iavf_print_fdir_fltr(adapter, fdir);
2483 }
2484 }
2485 }
2486 spin_unlock_bh(&adapter->fdir_fltr_lock);
2487 }
2488 break;
2489 case VIRTCHNL_OP_ADD_RSS_CFG: {
2490 struct iavf_adv_rss *rss;
2491
2492 spin_lock_bh(&adapter->adv_rss_lock);
2493 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
2494 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2495 iavf_print_adv_rss_cfg(adapter, rss,
2496 "Input set change for",
2497 "successful");
2498 rss->state = IAVF_ADV_RSS_ACTIVE;
2499 }
2500 }
2501 spin_unlock_bh(&adapter->adv_rss_lock);
2502 }
2503 break;
2504 case VIRTCHNL_OP_DEL_RSS_CFG: {
2505 struct iavf_adv_rss *rss, *rss_tmp;
2506
2507 spin_lock_bh(&adapter->adv_rss_lock);
2508 list_for_each_entry_safe(rss, rss_tmp,
2509 &adapter->adv_rss_list_head, list) {
2510 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2511 list_del(&rss->list);
2512 kfree(rss);
2513 }
2514 }
2515 spin_unlock_bh(&adapter->adv_rss_lock);
2516 }
2517 break;
2518 case VIRTCHNL_OP_ADD_VLAN_V2: {
2519 struct iavf_vlan_filter *f;
2520
2521 spin_lock_bh(&adapter->mac_vlan_list_lock);
2522 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
2523 if (f->state == IAVF_VLAN_IS_NEW)
2524 f->state = IAVF_VLAN_ACTIVE;
2525 }
2526 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2527 }
2528 break;
2529 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2530 /* PF enabled vlan strip on this VF.
2531 * Update netdev->features if needed to be in sync with ethtool.
2532 */
2533 if (!v_retval)
2534 iavf_netdev_features_vlan_strip_set(netdev, true);
2535 break;
2536 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2537 /* PF disabled vlan strip on this VF.
2538 * Update netdev->features if needed to be in sync with ethtool.
2539 */
2540 if (!v_retval)
2541 iavf_netdev_features_vlan_strip_set(netdev, false);
2542 break;
2543 default:
2544 if (adapter->current_op && (v_opcode != adapter->current_op))
2545 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
2546 adapter->current_op, v_opcode);
2547 break;
2548 } /* switch v_opcode */
2549 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
2550 }
2551