1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
4 * Copyright(c) 2013 - 2014 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 ******************************************************************************/
28 #include "i40e_prototype.h"
30 /* busy wait delay in msec */
31 #define I40EVF_BUSY_WAIT_DELAY 10
32 #define I40EVF_BUSY_WAIT_COUNT 50
36 * @adapter: adapter structure
37 * @op: virtual channel opcode
38 * @msg: pointer to message buffer
39 * @len: message length
41 * Send message to PF and print status if failure.
43 static int i40evf_send_pf_msg(struct i40evf_adapter
*adapter
,
44 enum i40e_virtchnl_ops op
, u8
*msg
, u16 len
)
46 struct i40e_hw
*hw
= &adapter
->hw
;
49 if (adapter
->flags
& I40EVF_FLAG_PF_COMMS_FAILED
)
50 return 0; /* nothing to see here, move along */
52 err
= i40e_aq_send_msg_to_pf(hw
, op
, 0, msg
, len
, NULL
);
54 dev_err(&adapter
->pdev
->dev
, "Unable to send opcode %d to PF, error %d, aq status %d\n",
55 op
, err
, hw
->aq
.asq_last_status
);
61 * @adapter: adapter structure
63 * Send API version admin queue message to the PF. The reply is not checked
64 * in this function. Returns 0 if the message was successfully
65 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
67 int i40evf_send_api_ver(struct i40evf_adapter
*adapter
)
69 struct i40e_virtchnl_version_info vvi
;
71 vvi
.major
= I40E_VIRTCHNL_VERSION_MAJOR
;
72 vvi
.minor
= I40E_VIRTCHNL_VERSION_MINOR
;
74 return i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_VERSION
, (u8
*)&vvi
,
79 * i40evf_verify_api_ver
80 * @adapter: adapter structure
82 * Compare API versions with the PF. Must be called after admin queue is
83 * initialized. Returns 0 if API versions match, -EIO if they do not,
84 * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
85 * from the firmware are propagated.
87 int i40evf_verify_api_ver(struct i40evf_adapter
*adapter
)
89 struct i40e_virtchnl_version_info
*pf_vvi
;
90 struct i40e_hw
*hw
= &adapter
->hw
;
91 struct i40e_arq_event_info event
;
92 enum i40e_virtchnl_ops op
;
95 event
.msg_size
= I40EVF_MAX_AQ_BUF_SIZE
;
96 event
.msg_buf
= kzalloc(event
.msg_size
, GFP_KERNEL
);
103 err
= i40evf_clean_arq_element(hw
, &event
, NULL
);
104 /* When the AQ is empty, i40evf_clean_arq_element will return
105 * nonzero and this loop will terminate.
110 (enum i40e_virtchnl_ops
)le32_to_cpu(event
.desc
.cookie_high
);
111 if (op
== I40E_VIRTCHNL_OP_VERSION
)
116 err
= (i40e_status
)le32_to_cpu(event
.desc
.cookie_low
);
120 if (op
!= I40E_VIRTCHNL_OP_VERSION
) {
121 dev_info(&adapter
->pdev
->dev
, "Invalid reply type %d from PF\n",
127 pf_vvi
= (struct i40e_virtchnl_version_info
*)event
.msg_buf
;
128 if ((pf_vvi
->major
!= I40E_VIRTCHNL_VERSION_MAJOR
) ||
129 (pf_vvi
->minor
!= I40E_VIRTCHNL_VERSION_MINOR
))
133 kfree(event
.msg_buf
);
139 * i40evf_send_vf_config_msg
140 * @adapter: adapter structure
142 * Send VF configuration request admin queue message to the PF. The reply
143 * is not checked in this function. Returns 0 if the message was
144 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
146 int i40evf_send_vf_config_msg(struct i40evf_adapter
*adapter
)
148 return i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_GET_VF_RESOURCES
,
153 * i40evf_get_vf_config
154 * @hw: pointer to the hardware structure
155 * @len: length of buffer
157 * Get VF configuration from PF and populate hw structure. Must be called after
158 * admin queue is initialized. Busy waits until response is received from PF,
159 * with maximum timeout. Response from PF is returned in the buffer for further
160 * processing by the caller.
162 int i40evf_get_vf_config(struct i40evf_adapter
*adapter
)
164 struct i40e_hw
*hw
= &adapter
->hw
;
165 struct i40e_arq_event_info event
;
166 enum i40e_virtchnl_ops op
;
170 len
= sizeof(struct i40e_virtchnl_vf_resource
) +
171 I40E_MAX_VF_VSI
* sizeof(struct i40e_virtchnl_vsi_resource
);
172 event
.msg_size
= len
;
173 event
.msg_buf
= kzalloc(event
.msg_size
, GFP_KERNEL
);
174 if (!event
.msg_buf
) {
180 event
.msg_size
= len
;
181 /* When the AQ is empty, i40evf_clean_arq_element will return
182 * nonzero and this loop will terminate.
184 err
= i40evf_clean_arq_element(hw
, &event
, NULL
);
188 (enum i40e_virtchnl_ops
)le32_to_cpu(event
.desc
.cookie_high
);
189 if (op
== I40E_VIRTCHNL_OP_GET_VF_RESOURCES
)
193 err
= (i40e_status
)le32_to_cpu(event
.desc
.cookie_low
);
194 memcpy(adapter
->vf_res
, event
.msg_buf
, min(event
.msg_size
, len
));
196 i40e_vf_parse_hw_config(hw
, adapter
->vf_res
);
198 kfree(event
.msg_buf
);
204 * i40evf_configure_queues
205 * @adapter: adapter structure
207 * Request that the PF set up our (previously allocated) queues.
209 void i40evf_configure_queues(struct i40evf_adapter
*adapter
)
211 struct i40e_virtchnl_vsi_queue_config_info
*vqci
;
212 struct i40e_virtchnl_queue_pair_info
*vqpi
;
213 int pairs
= adapter
->vsi_res
->num_queue_pairs
;
216 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
217 /* bail because we already have a command pending */
218 dev_err(&adapter
->pdev
->dev
, "%s: command %d pending\n",
219 __func__
, adapter
->current_op
);
222 adapter
->current_op
= I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
;
223 len
= sizeof(struct i40e_virtchnl_vsi_queue_config_info
) +
224 (sizeof(struct i40e_virtchnl_queue_pair_info
) * pairs
);
225 vqci
= kzalloc(len
, GFP_ATOMIC
);
229 vqci
->vsi_id
= adapter
->vsi_res
->vsi_id
;
230 vqci
->num_queue_pairs
= pairs
;
232 /* Size check is not needed here - HW max is 16 queue pairs, and we
233 * can fit info for 31 of them into the AQ buffer before it overflows.
235 for (i
= 0; i
< pairs
; i
++) {
236 vqpi
->txq
.vsi_id
= vqci
->vsi_id
;
237 vqpi
->txq
.queue_id
= i
;
238 vqpi
->txq
.ring_len
= adapter
->tx_rings
[i
]->count
;
239 vqpi
->txq
.dma_ring_addr
= adapter
->tx_rings
[i
]->dma
;
240 vqpi
->txq
.headwb_enabled
= 1;
241 vqpi
->txq
.dma_headwb_addr
= vqpi
->txq
.dma_ring_addr
+
242 (vqpi
->txq
.ring_len
* sizeof(struct i40e_tx_desc
));
244 vqpi
->rxq
.vsi_id
= vqci
->vsi_id
;
245 vqpi
->rxq
.queue_id
= i
;
246 vqpi
->rxq
.ring_len
= adapter
->rx_rings
[i
]->count
;
247 vqpi
->rxq
.dma_ring_addr
= adapter
->rx_rings
[i
]->dma
;
248 vqpi
->rxq
.max_pkt_size
= adapter
->netdev
->mtu
249 + ETH_HLEN
+ VLAN_HLEN
+ ETH_FCS_LEN
;
250 vqpi
->rxq
.databuffer_size
= adapter
->rx_rings
[i
]->rx_buf_len
;
254 adapter
->aq_pending
|= I40EVF_FLAG_AQ_CONFIGURE_QUEUES
;
255 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES
;
256 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
,
262 * i40evf_enable_queues
263 * @adapter: adapter structure
265 * Request that the PF enable all of our queues.
267 void i40evf_enable_queues(struct i40evf_adapter
*adapter
)
269 struct i40e_virtchnl_queue_select vqs
;
271 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
272 /* bail because we already have a command pending */
273 dev_err(&adapter
->pdev
->dev
, "%s: command %d pending\n",
274 __func__
, adapter
->current_op
);
277 adapter
->current_op
= I40E_VIRTCHNL_OP_ENABLE_QUEUES
;
278 vqs
.vsi_id
= adapter
->vsi_res
->vsi_id
;
279 vqs
.tx_queues
= (1 << adapter
->vsi_res
->num_queue_pairs
) - 1;
280 vqs
.rx_queues
= vqs
.tx_queues
;
281 adapter
->aq_pending
|= I40EVF_FLAG_AQ_ENABLE_QUEUES
;
282 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_ENABLE_QUEUES
;
283 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_ENABLE_QUEUES
,
284 (u8
*)&vqs
, sizeof(vqs
));
288 * i40evf_disable_queues
289 * @adapter: adapter structure
291 * Request that the PF disable all of our queues.
293 void i40evf_disable_queues(struct i40evf_adapter
*adapter
)
295 struct i40e_virtchnl_queue_select vqs
;
297 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
298 /* bail because we already have a command pending */
299 dev_err(&adapter
->pdev
->dev
, "%s: command %d pending\n",
300 __func__
, adapter
->current_op
);
303 adapter
->current_op
= I40E_VIRTCHNL_OP_DISABLE_QUEUES
;
304 vqs
.vsi_id
= adapter
->vsi_res
->vsi_id
;
305 vqs
.tx_queues
= (1 << adapter
->vsi_res
->num_queue_pairs
) - 1;
306 vqs
.rx_queues
= vqs
.tx_queues
;
307 adapter
->aq_pending
|= I40EVF_FLAG_AQ_DISABLE_QUEUES
;
308 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_DISABLE_QUEUES
;
309 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_DISABLE_QUEUES
,
310 (u8
*)&vqs
, sizeof(vqs
));
315 * @adapter: adapter structure
317 * Request that the PF map queues to interrupt vectors. Misc causes, including
318 * admin queue, are always mapped to vector 0.
320 void i40evf_map_queues(struct i40evf_adapter
*adapter
)
322 struct i40e_virtchnl_irq_map_info
*vimi
;
323 int v_idx
, q_vectors
, len
;
324 struct i40e_q_vector
*q_vector
;
326 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
327 /* bail because we already have a command pending */
328 dev_err(&adapter
->pdev
->dev
, "%s: command %d pending\n",
329 __func__
, adapter
->current_op
);
332 adapter
->current_op
= I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
;
334 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
336 len
= sizeof(struct i40e_virtchnl_irq_map_info
) +
337 (adapter
->num_msix_vectors
*
338 sizeof(struct i40e_virtchnl_vector_map
));
339 vimi
= kzalloc(len
, GFP_ATOMIC
);
343 vimi
->num_vectors
= adapter
->num_msix_vectors
;
344 /* Queue vectors first */
345 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
346 q_vector
= adapter
->q_vector
[v_idx
];
347 vimi
->vecmap
[v_idx
].vsi_id
= adapter
->vsi_res
->vsi_id
;
348 vimi
->vecmap
[v_idx
].vector_id
= v_idx
+ NONQ_VECS
;
349 vimi
->vecmap
[v_idx
].txq_map
= q_vector
->ring_mask
;
350 vimi
->vecmap
[v_idx
].rxq_map
= q_vector
->ring_mask
;
352 /* Misc vector last - this is only for AdminQ messages */
353 vimi
->vecmap
[v_idx
].vsi_id
= adapter
->vsi_res
->vsi_id
;
354 vimi
->vecmap
[v_idx
].vector_id
= 0;
355 vimi
->vecmap
[v_idx
].txq_map
= 0;
356 vimi
->vecmap
[v_idx
].rxq_map
= 0;
358 adapter
->aq_pending
|= I40EVF_FLAG_AQ_MAP_VECTORS
;
359 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_MAP_VECTORS
;
360 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
,
366 * i40evf_add_ether_addrs
367 * @adapter: adapter structure
368 * @addrs: the MAC address filters to add (contiguous)
369 * @count: number of filters
371 * Request that the PF add one or more addresses to our filters.
373 void i40evf_add_ether_addrs(struct i40evf_adapter
*adapter
)
375 struct i40e_virtchnl_ether_addr_list
*veal
;
376 int len
, i
= 0, count
= 0;
377 struct i40evf_mac_filter
*f
;
379 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
380 /* bail because we already have a command pending */
381 dev_err(&adapter
->pdev
->dev
, "%s: command %d pending\n",
382 __func__
, adapter
->current_op
);
385 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
390 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
393 adapter
->current_op
= I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
;
395 len
= sizeof(struct i40e_virtchnl_ether_addr_list
) +
396 (count
* sizeof(struct i40e_virtchnl_ether_addr
));
397 if (len
> I40EVF_MAX_AQ_BUF_SIZE
) {
398 dev_warn(&adapter
->pdev
->dev
, "%s: Too many MAC address changes in one request\n",
400 count
= (I40EVF_MAX_AQ_BUF_SIZE
-
401 sizeof(struct i40e_virtchnl_ether_addr_list
)) /
402 sizeof(struct i40e_virtchnl_ether_addr
);
403 len
= I40EVF_MAX_AQ_BUF_SIZE
;
406 veal
= kzalloc(len
, GFP_ATOMIC
);
410 veal
->vsi_id
= adapter
->vsi_res
->vsi_id
;
411 veal
->num_elements
= count
;
412 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
414 ether_addr_copy(veal
->list
[i
].addr
, f
->macaddr
);
419 adapter
->aq_pending
|= I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
420 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
421 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
,
427 * i40evf_del_ether_addrs
428 * @adapter: adapter structure
429 * @addrs: the MAC address filters to remove (contiguous)
430 * @count: number of filtes
432 * Request that the PF remove one or more addresses from our filters.
434 void i40evf_del_ether_addrs(struct i40evf_adapter
*adapter
)
436 struct i40e_virtchnl_ether_addr_list
*veal
;
437 struct i40evf_mac_filter
*f
, *ftmp
;
438 int len
, i
= 0, count
= 0;
440 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
441 /* bail because we already have a command pending */
442 dev_err(&adapter
->pdev
->dev
, "%s: command %d pending\n",
443 __func__
, adapter
->current_op
);
446 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
451 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
454 adapter
->current_op
= I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
;
456 len
= sizeof(struct i40e_virtchnl_ether_addr_list
) +
457 (count
* sizeof(struct i40e_virtchnl_ether_addr
));
458 if (len
> I40EVF_MAX_AQ_BUF_SIZE
) {
459 dev_warn(&adapter
->pdev
->dev
, "%s: Too many MAC address changes in one request\n",
461 count
= (I40EVF_MAX_AQ_BUF_SIZE
-
462 sizeof(struct i40e_virtchnl_ether_addr_list
)) /
463 sizeof(struct i40e_virtchnl_ether_addr
);
464 len
= I40EVF_MAX_AQ_BUF_SIZE
;
466 veal
= kzalloc(len
, GFP_ATOMIC
);
470 veal
->vsi_id
= adapter
->vsi_res
->vsi_id
;
471 veal
->num_elements
= count
;
472 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
474 ether_addr_copy(veal
->list
[i
].addr
, f
->macaddr
);
480 adapter
->aq_pending
|= I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
481 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
482 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
,
489 * @adapter: adapter structure
490 * @vlans: the VLANs to add
491 * @count: number of VLANs
493 * Request that the PF add one or more VLAN filters to our VSI.
495 void i40evf_add_vlans(struct i40evf_adapter
*adapter
)
497 struct i40e_virtchnl_vlan_filter_list
*vvfl
;
498 int len
, i
= 0, count
= 0;
499 struct i40evf_vlan_filter
*f
;
501 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
502 /* bail because we already have a command pending */
503 dev_err(&adapter
->pdev
->dev
, "%s: command %d pending\n",
504 __func__
, adapter
->current_op
);
508 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
513 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
516 adapter
->current_op
= I40E_VIRTCHNL_OP_ADD_VLAN
;
518 len
= sizeof(struct i40e_virtchnl_vlan_filter_list
) +
519 (count
* sizeof(u16
));
520 if (len
> I40EVF_MAX_AQ_BUF_SIZE
) {
521 dev_warn(&adapter
->pdev
->dev
, "%s: Too many VLAN changes in one request\n",
523 count
= (I40EVF_MAX_AQ_BUF_SIZE
-
524 sizeof(struct i40e_virtchnl_vlan_filter_list
)) /
526 len
= I40EVF_MAX_AQ_BUF_SIZE
;
528 vvfl
= kzalloc(len
, GFP_ATOMIC
);
532 vvfl
->vsi_id
= adapter
->vsi_res
->vsi_id
;
533 vvfl
->num_elements
= count
;
534 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
536 vvfl
->vlan_id
[i
] = f
->vlan
;
541 adapter
->aq_pending
|= I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
542 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
543 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_ADD_VLAN
, (u8
*)vvfl
, len
);
549 * @adapter: adapter structure
550 * @vlans: the VLANs to remove
551 * @count: number of VLANs
553 * Request that the PF remove one or more VLAN filters from our VSI.
555 void i40evf_del_vlans(struct i40evf_adapter
*adapter
)
557 struct i40e_virtchnl_vlan_filter_list
*vvfl
;
558 struct i40evf_vlan_filter
*f
, *ftmp
;
559 int len
, i
= 0, count
= 0;
561 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
562 /* bail because we already have a command pending */
563 dev_err(&adapter
->pdev
->dev
, "%s: command %d pending\n",
564 __func__
, adapter
->current_op
);
568 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
573 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
576 adapter
->current_op
= I40E_VIRTCHNL_OP_DEL_VLAN
;
578 len
= sizeof(struct i40e_virtchnl_vlan_filter_list
) +
579 (count
* sizeof(u16
));
580 if (len
> I40EVF_MAX_AQ_BUF_SIZE
) {
581 dev_warn(&adapter
->pdev
->dev
, "%s: Too many VLAN changes in one request\n",
583 count
= (I40EVF_MAX_AQ_BUF_SIZE
-
584 sizeof(struct i40e_virtchnl_vlan_filter_list
)) /
586 len
= I40EVF_MAX_AQ_BUF_SIZE
;
588 vvfl
= kzalloc(len
, GFP_ATOMIC
);
592 vvfl
->vsi_id
= adapter
->vsi_res
->vsi_id
;
593 vvfl
->num_elements
= count
;
594 list_for_each_entry_safe(f
, ftmp
, &adapter
->vlan_filter_list
, list
) {
596 vvfl
->vlan_id
[i
] = f
->vlan
;
602 adapter
->aq_pending
|= I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
603 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
604 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_DEL_VLAN
, (u8
*)vvfl
, len
);
609 * i40evf_set_promiscuous
610 * @adapter: adapter structure
611 * @flags: bitmask to control unicast/multicast promiscuous.
613 * Request that the PF enable promiscuous mode for our VSI.
615 void i40evf_set_promiscuous(struct i40evf_adapter
*adapter
, int flags
)
617 struct i40e_virtchnl_promisc_info vpi
;
619 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
620 /* bail because we already have a command pending */
621 dev_err(&adapter
->pdev
->dev
, "%s: command %d pending\n",
622 __func__
, adapter
->current_op
);
625 adapter
->current_op
= I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
;
626 vpi
.vsi_id
= adapter
->vsi_res
->vsi_id
;
628 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
,
629 (u8
*)&vpi
, sizeof(vpi
));
633 * i40evf_request_stats
634 * @adapter: adapter structure
636 * Request VSI statistics from PF.
638 void i40evf_request_stats(struct i40evf_adapter
*adapter
)
640 struct i40e_virtchnl_queue_select vqs
;
641 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
642 /* no error message, this isn't crucial */
645 adapter
->current_op
= I40E_VIRTCHNL_OP_GET_STATS
;
646 vqs
.vsi_id
= adapter
->vsi_res
->vsi_id
;
647 /* queue maps are ignored for this message - only the vsi is used */
648 if (i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_GET_STATS
,
649 (u8
*)&vqs
, sizeof(vqs
)))
650 /* if the request failed, don't lock out others */
651 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
654 * i40evf_request_reset
655 * @adapter: adapter structure
657 * Request that the PF reset this VF. No response is expected.
659 void i40evf_request_reset(struct i40evf_adapter
*adapter
)
661 /* Don't check CURRENT_OP - this is always higher priority */
662 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_RESET_VF
, NULL
, 0);
663 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
667 * i40evf_virtchnl_completion
668 * @adapter: adapter structure
669 * @v_opcode: opcode sent by PF
670 * @v_retval: retval sent by PF
671 * @msg: message sent by PF
672 * @msglen: message length
674 * Asynchronous completion function for admin queue messages. Rather than busy
675 * wait, we fire off our requests and assume that no errors will be returned.
676 * This function handles the reply messages.
678 void i40evf_virtchnl_completion(struct i40evf_adapter
*adapter
,
679 enum i40e_virtchnl_ops v_opcode
,
680 i40e_status v_retval
,
683 struct net_device
*netdev
= adapter
->netdev
;
685 if (v_opcode
== I40E_VIRTCHNL_OP_EVENT
) {
686 struct i40e_virtchnl_pf_event
*vpe
=
687 (struct i40e_virtchnl_pf_event
*)msg
;
688 switch (vpe
->event
) {
689 case I40E_VIRTCHNL_EVENT_LINK_CHANGE
:
691 vpe
->event_data
.link_event
.link_status
;
692 if (adapter
->link_up
&& !netif_carrier_ok(netdev
)) {
693 dev_info(&adapter
->pdev
->dev
, "NIC Link is Up\n");
694 netif_carrier_on(netdev
);
695 netif_tx_wake_all_queues(netdev
);
696 } else if (!adapter
->link_up
) {
697 dev_info(&adapter
->pdev
->dev
, "NIC Link is Down\n");
698 netif_carrier_off(netdev
);
699 netif_tx_stop_all_queues(netdev
);
702 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING
:
703 dev_info(&adapter
->pdev
->dev
, "PF reset warning received\n");
704 if (!(adapter
->flags
& I40EVF_FLAG_RESET_PENDING
)) {
705 adapter
->flags
|= I40EVF_FLAG_RESET_PENDING
;
706 dev_info(&adapter
->pdev
->dev
, "Scheduling reset task\n");
707 schedule_work(&adapter
->reset_task
);
711 dev_err(&adapter
->pdev
->dev
,
712 "%s: Unknown event %d from pf\n",
713 __func__
, vpe
->event
);
719 if (v_opcode
!= adapter
->current_op
) {
720 dev_err(&adapter
->pdev
->dev
, "%s: Pending op is %d, received %d\n",
721 __func__
, adapter
->current_op
, v_opcode
);
722 /* We're probably completely screwed at this point, but clear
723 * the current op and try to carry on....
725 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
729 dev_err(&adapter
->pdev
->dev
, "%s: PF returned error %d to our request %d\n",
730 __func__
, v_retval
, v_opcode
);
733 case I40E_VIRTCHNL_OP_GET_STATS
: {
734 struct i40e_eth_stats
*stats
=
735 (struct i40e_eth_stats
*)msg
;
736 adapter
->net_stats
.rx_packets
= stats
->rx_unicast
+
737 stats
->rx_multicast
+
739 adapter
->net_stats
.tx_packets
= stats
->tx_unicast
+
740 stats
->tx_multicast
+
742 adapter
->net_stats
.rx_bytes
= stats
->rx_bytes
;
743 adapter
->net_stats
.tx_bytes
= stats
->tx_bytes
;
744 adapter
->net_stats
.tx_errors
= stats
->tx_errors
;
745 adapter
->net_stats
.rx_dropped
= stats
->rx_discards
;
746 adapter
->net_stats
.tx_dropped
= stats
->tx_discards
;
747 adapter
->current_stats
= *stats
;
750 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
:
751 adapter
->aq_pending
&= ~(I40EVF_FLAG_AQ_ADD_MAC_FILTER
);
753 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
:
754 adapter
->aq_pending
&= ~(I40EVF_FLAG_AQ_DEL_MAC_FILTER
);
756 case I40E_VIRTCHNL_OP_ADD_VLAN
:
757 adapter
->aq_pending
&= ~(I40EVF_FLAG_AQ_ADD_VLAN_FILTER
);
759 case I40E_VIRTCHNL_OP_DEL_VLAN
:
760 adapter
->aq_pending
&= ~(I40EVF_FLAG_AQ_DEL_VLAN_FILTER
);
762 case I40E_VIRTCHNL_OP_ENABLE_QUEUES
:
763 adapter
->aq_pending
&= ~(I40EVF_FLAG_AQ_ENABLE_QUEUES
);
764 /* enable transmits */
765 i40evf_irq_enable(adapter
, true);
766 netif_tx_start_all_queues(adapter
->netdev
);
767 netif_carrier_on(adapter
->netdev
);
769 case I40E_VIRTCHNL_OP_DISABLE_QUEUES
:
770 adapter
->aq_pending
&= ~(I40EVF_FLAG_AQ_DISABLE_QUEUES
);
772 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
:
773 adapter
->aq_pending
&= ~(I40EVF_FLAG_AQ_CONFIGURE_QUEUES
);
775 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
:
776 adapter
->aq_pending
&= ~(I40EVF_FLAG_AQ_MAP_VECTORS
);
779 dev_warn(&adapter
->pdev
->dev
, "%s: Received unexpected message %d from PF\n",
782 } /* switch v_opcode */
783 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;