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, err %s, aq_err %s\n",
55 op
, i40evf_stat_str(hw
, err
),
56 i40evf_aq_str(hw
, hw
->aq
.asq_last_status
));
62 * @adapter: adapter structure
64 * Send API version admin queue message to the PF. The reply is not checked
65 * in this function. Returns 0 if the message was successfully
66 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
68 int i40evf_send_api_ver(struct i40evf_adapter
*adapter
)
70 struct i40e_virtchnl_version_info vvi
;
72 vvi
.major
= I40E_VIRTCHNL_VERSION_MAJOR
;
73 vvi
.minor
= I40E_VIRTCHNL_VERSION_MINOR
;
75 return i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_VERSION
, (u8
*)&vvi
,
80 * i40evf_verify_api_ver
81 * @adapter: adapter structure
83 * Compare API versions with the PF. Must be called after admin queue is
84 * initialized. Returns 0 if API versions match, -EIO if they do not,
85 * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
86 * from the firmware are propagated.
88 int i40evf_verify_api_ver(struct i40evf_adapter
*adapter
)
90 struct i40e_virtchnl_version_info
*pf_vvi
;
91 struct i40e_hw
*hw
= &adapter
->hw
;
92 struct i40e_arq_event_info event
;
93 enum i40e_virtchnl_ops op
;
96 event
.buf_len
= I40EVF_MAX_AQ_BUF_SIZE
;
97 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
104 err
= i40evf_clean_arq_element(hw
, &event
, NULL
);
105 /* When the AQ is empty, i40evf_clean_arq_element will return
106 * nonzero and this loop will terminate.
111 (enum i40e_virtchnl_ops
)le32_to_cpu(event
.desc
.cookie_high
);
112 if (op
== I40E_VIRTCHNL_OP_VERSION
)
117 err
= (i40e_status
)le32_to_cpu(event
.desc
.cookie_low
);
121 if (op
!= I40E_VIRTCHNL_OP_VERSION
) {
122 dev_info(&adapter
->pdev
->dev
, "Invalid reply type %d from PF\n",
128 pf_vvi
= (struct i40e_virtchnl_version_info
*)event
.msg_buf
;
129 adapter
->pf_version
= *pf_vvi
;
131 if ((pf_vvi
->major
> I40E_VIRTCHNL_VERSION_MAJOR
) ||
132 ((pf_vvi
->major
== I40E_VIRTCHNL_VERSION_MAJOR
) &&
133 (pf_vvi
->minor
> I40E_VIRTCHNL_VERSION_MINOR
)))
137 kfree(event
.msg_buf
);
143 * i40evf_send_vf_config_msg
144 * @adapter: adapter structure
146 * Send VF configuration request admin queue message to the PF. The reply
147 * is not checked in this function. Returns 0 if the message was
148 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
150 int i40evf_send_vf_config_msg(struct i40evf_adapter
*adapter
)
154 adapter
->current_op
= I40E_VIRTCHNL_OP_GET_VF_RESOURCES
;
155 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_GET_CONFIG
;
156 caps
= I40E_VIRTCHNL_VF_OFFLOAD_L2
|
157 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ
|
158 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG
|
159 I40E_VIRTCHNL_VF_OFFLOAD_VLAN
|
160 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
|
161 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
;
163 adapter
->current_op
= I40E_VIRTCHNL_OP_GET_VF_RESOURCES
;
164 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_GET_CONFIG
;
165 if (PF_IS_V11(adapter
))
166 return i40evf_send_pf_msg(adapter
,
167 I40E_VIRTCHNL_OP_GET_VF_RESOURCES
,
168 (u8
*)&caps
, sizeof(caps
));
170 return i40evf_send_pf_msg(adapter
,
171 I40E_VIRTCHNL_OP_GET_VF_RESOURCES
,
176 * i40evf_get_vf_config
177 * @hw: pointer to the hardware structure
178 * @len: length of buffer
180 * Get VF configuration from PF and populate hw structure. Must be called after
181 * admin queue is initialized. Busy waits until response is received from PF,
182 * with maximum timeout. Response from PF is returned in the buffer for further
183 * processing by the caller.
185 int i40evf_get_vf_config(struct i40evf_adapter
*adapter
)
187 struct i40e_hw
*hw
= &adapter
->hw
;
188 struct i40e_arq_event_info event
;
189 enum i40e_virtchnl_ops op
;
193 len
= sizeof(struct i40e_virtchnl_vf_resource
) +
194 I40E_MAX_VF_VSI
* sizeof(struct i40e_virtchnl_vsi_resource
);
196 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
197 if (!event
.msg_buf
) {
203 /* When the AQ is empty, i40evf_clean_arq_element will return
204 * nonzero and this loop will terminate.
206 err
= i40evf_clean_arq_element(hw
, &event
, NULL
);
210 (enum i40e_virtchnl_ops
)le32_to_cpu(event
.desc
.cookie_high
);
211 if (op
== I40E_VIRTCHNL_OP_GET_VF_RESOURCES
)
215 err
= (i40e_status
)le32_to_cpu(event
.desc
.cookie_low
);
216 memcpy(adapter
->vf_res
, event
.msg_buf
, min(event
.msg_len
, len
));
218 i40e_vf_parse_hw_config(hw
, adapter
->vf_res
);
220 kfree(event
.msg_buf
);
226 * i40evf_configure_queues
227 * @adapter: adapter structure
229 * Request that the PF set up our (previously allocated) queues.
231 void i40evf_configure_queues(struct i40evf_adapter
*adapter
)
233 struct i40e_virtchnl_vsi_queue_config_info
*vqci
;
234 struct i40e_virtchnl_queue_pair_info
*vqpi
;
235 int pairs
= adapter
->num_active_queues
;
238 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
239 /* bail because we already have a command pending */
240 dev_err(&adapter
->pdev
->dev
, "Cannot configure queues, command %d pending\n",
241 adapter
->current_op
);
244 adapter
->current_op
= I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
;
245 len
= sizeof(struct i40e_virtchnl_vsi_queue_config_info
) +
246 (sizeof(struct i40e_virtchnl_queue_pair_info
) * pairs
);
247 vqci
= kzalloc(len
, GFP_KERNEL
);
251 vqci
->vsi_id
= adapter
->vsi_res
->vsi_id
;
252 vqci
->num_queue_pairs
= pairs
;
254 /* Size check is not needed here - HW max is 16 queue pairs, and we
255 * can fit info for 31 of them into the AQ buffer before it overflows.
257 for (i
= 0; i
< pairs
; i
++) {
258 vqpi
->txq
.vsi_id
= vqci
->vsi_id
;
259 vqpi
->txq
.queue_id
= i
;
260 vqpi
->txq
.ring_len
= adapter
->tx_rings
[i
].count
;
261 vqpi
->txq
.dma_ring_addr
= adapter
->tx_rings
[i
].dma
;
262 vqpi
->txq
.headwb_enabled
= 1;
263 vqpi
->txq
.dma_headwb_addr
= vqpi
->txq
.dma_ring_addr
+
264 (vqpi
->txq
.ring_len
* sizeof(struct i40e_tx_desc
));
266 vqpi
->rxq
.vsi_id
= vqci
->vsi_id
;
267 vqpi
->rxq
.queue_id
= i
;
268 vqpi
->rxq
.ring_len
= adapter
->rx_rings
[i
].count
;
269 vqpi
->rxq
.dma_ring_addr
= adapter
->rx_rings
[i
].dma
;
270 vqpi
->rxq
.max_pkt_size
= adapter
->netdev
->mtu
271 + ETH_HLEN
+ VLAN_HLEN
+ ETH_FCS_LEN
;
272 vqpi
->rxq
.databuffer_size
= adapter
->rx_rings
[i
].rx_buf_len
;
276 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES
;
277 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES
,
283 * i40evf_enable_queues
284 * @adapter: adapter structure
286 * Request that the PF enable all of our queues.
288 void i40evf_enable_queues(struct i40evf_adapter
*adapter
)
290 struct i40e_virtchnl_queue_select vqs
;
292 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
293 /* bail because we already have a command pending */
294 dev_err(&adapter
->pdev
->dev
, "Cannot enable queues, command %d pending\n",
295 adapter
->current_op
);
298 adapter
->current_op
= I40E_VIRTCHNL_OP_ENABLE_QUEUES
;
299 vqs
.vsi_id
= adapter
->vsi_res
->vsi_id
;
300 vqs
.tx_queues
= BIT(adapter
->num_active_queues
) - 1;
301 vqs
.rx_queues
= vqs
.tx_queues
;
302 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_ENABLE_QUEUES
;
303 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_ENABLE_QUEUES
,
304 (u8
*)&vqs
, sizeof(vqs
));
308 * i40evf_disable_queues
309 * @adapter: adapter structure
311 * Request that the PF disable all of our queues.
313 void i40evf_disable_queues(struct i40evf_adapter
*adapter
)
315 struct i40e_virtchnl_queue_select vqs
;
317 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
318 /* bail because we already have a command pending */
319 dev_err(&adapter
->pdev
->dev
, "Cannot disable queues, command %d pending\n",
320 adapter
->current_op
);
323 adapter
->current_op
= I40E_VIRTCHNL_OP_DISABLE_QUEUES
;
324 vqs
.vsi_id
= adapter
->vsi_res
->vsi_id
;
325 vqs
.tx_queues
= BIT(adapter
->num_active_queues
) - 1;
326 vqs
.rx_queues
= vqs
.tx_queues
;
327 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_DISABLE_QUEUES
;
328 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_DISABLE_QUEUES
,
329 (u8
*)&vqs
, sizeof(vqs
));
334 * @adapter: adapter structure
336 * Request that the PF map queues to interrupt vectors. Misc causes, including
337 * admin queue, are always mapped to vector 0.
339 void i40evf_map_queues(struct i40evf_adapter
*adapter
)
341 struct i40e_virtchnl_irq_map_info
*vimi
;
342 int v_idx
, q_vectors
, len
;
343 struct i40e_q_vector
*q_vector
;
345 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
346 /* bail because we already have a command pending */
347 dev_err(&adapter
->pdev
->dev
, "Cannot map queues to vectors, command %d pending\n",
348 adapter
->current_op
);
351 adapter
->current_op
= I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
;
353 q_vectors
= adapter
->num_msix_vectors
- NONQ_VECS
;
355 len
= sizeof(struct i40e_virtchnl_irq_map_info
) +
356 (adapter
->num_msix_vectors
*
357 sizeof(struct i40e_virtchnl_vector_map
));
358 vimi
= kzalloc(len
, GFP_KERNEL
);
362 vimi
->num_vectors
= adapter
->num_msix_vectors
;
363 /* Queue vectors first */
364 for (v_idx
= 0; v_idx
< q_vectors
; v_idx
++) {
365 q_vector
= adapter
->q_vectors
+ v_idx
;
366 vimi
->vecmap
[v_idx
].vsi_id
= adapter
->vsi_res
->vsi_id
;
367 vimi
->vecmap
[v_idx
].vector_id
= v_idx
+ NONQ_VECS
;
368 vimi
->vecmap
[v_idx
].txq_map
= q_vector
->ring_mask
;
369 vimi
->vecmap
[v_idx
].rxq_map
= q_vector
->ring_mask
;
371 /* Misc vector last - this is only for AdminQ messages */
372 vimi
->vecmap
[v_idx
].vsi_id
= adapter
->vsi_res
->vsi_id
;
373 vimi
->vecmap
[v_idx
].vector_id
= 0;
374 vimi
->vecmap
[v_idx
].txq_map
= 0;
375 vimi
->vecmap
[v_idx
].rxq_map
= 0;
377 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_MAP_VECTORS
;
378 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
,
384 * i40evf_add_ether_addrs
385 * @adapter: adapter structure
386 * @addrs: the MAC address filters to add (contiguous)
387 * @count: number of filters
389 * Request that the PF add one or more addresses to our filters.
391 void i40evf_add_ether_addrs(struct i40evf_adapter
*adapter
)
393 struct i40e_virtchnl_ether_addr_list
*veal
;
394 int len
, i
= 0, count
= 0;
395 struct i40evf_mac_filter
*f
;
398 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
399 /* bail because we already have a command pending */
400 dev_err(&adapter
->pdev
->dev
, "Cannot add filters, command %d pending\n",
401 adapter
->current_op
);
404 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
409 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
412 adapter
->current_op
= I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
;
414 len
= sizeof(struct i40e_virtchnl_ether_addr_list
) +
415 (count
* sizeof(struct i40e_virtchnl_ether_addr
));
416 if (len
> I40EVF_MAX_AQ_BUF_SIZE
) {
417 dev_warn(&adapter
->pdev
->dev
, "Too many add MAC changes in one request\n");
418 count
= (I40EVF_MAX_AQ_BUF_SIZE
-
419 sizeof(struct i40e_virtchnl_ether_addr_list
)) /
420 sizeof(struct i40e_virtchnl_ether_addr
);
421 len
= sizeof(struct i40e_virtchnl_ether_addr_list
) +
422 (count
* sizeof(struct i40e_virtchnl_ether_addr
));
426 veal
= kzalloc(len
, GFP_KERNEL
);
430 veal
->vsi_id
= adapter
->vsi_res
->vsi_id
;
431 veal
->num_elements
= count
;
432 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
434 ether_addr_copy(veal
->list
[i
].addr
, f
->macaddr
);
442 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER
;
443 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
,
449 * i40evf_del_ether_addrs
450 * @adapter: adapter structure
451 * @addrs: the MAC address filters to remove (contiguous)
452 * @count: number of filtes
454 * Request that the PF remove one or more addresses from our filters.
456 void i40evf_del_ether_addrs(struct i40evf_adapter
*adapter
)
458 struct i40e_virtchnl_ether_addr_list
*veal
;
459 struct i40evf_mac_filter
*f
, *ftmp
;
460 int len
, i
= 0, count
= 0;
463 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
464 /* bail because we already have a command pending */
465 dev_err(&adapter
->pdev
->dev
, "Cannot remove filters, command %d pending\n",
466 adapter
->current_op
);
469 list_for_each_entry(f
, &adapter
->mac_filter_list
, list
) {
474 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
477 adapter
->current_op
= I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
;
479 len
= sizeof(struct i40e_virtchnl_ether_addr_list
) +
480 (count
* sizeof(struct i40e_virtchnl_ether_addr
));
481 if (len
> I40EVF_MAX_AQ_BUF_SIZE
) {
482 dev_warn(&adapter
->pdev
->dev
, "Too many delete MAC changes in one request\n");
483 count
= (I40EVF_MAX_AQ_BUF_SIZE
-
484 sizeof(struct i40e_virtchnl_ether_addr_list
)) /
485 sizeof(struct i40e_virtchnl_ether_addr
);
486 len
= sizeof(struct i40e_virtchnl_ether_addr_list
) +
487 (count
* sizeof(struct i40e_virtchnl_ether_addr
));
490 veal
= kzalloc(len
, GFP_KERNEL
);
494 veal
->vsi_id
= adapter
->vsi_res
->vsi_id
;
495 veal
->num_elements
= count
;
496 list_for_each_entry_safe(f
, ftmp
, &adapter
->mac_filter_list
, list
) {
498 ether_addr_copy(veal
->list
[i
].addr
, f
->macaddr
);
507 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER
;
508 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
,
515 * @adapter: adapter structure
516 * @vlans: the VLANs to add
517 * @count: number of VLANs
519 * Request that the PF add one or more VLAN filters to our VSI.
521 void i40evf_add_vlans(struct i40evf_adapter
*adapter
)
523 struct i40e_virtchnl_vlan_filter_list
*vvfl
;
524 int len
, i
= 0, count
= 0;
525 struct i40evf_vlan_filter
*f
;
528 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
529 /* bail because we already have a command pending */
530 dev_err(&adapter
->pdev
->dev
, "Cannot add VLANs, command %d pending\n",
531 adapter
->current_op
);
535 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
540 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
543 adapter
->current_op
= I40E_VIRTCHNL_OP_ADD_VLAN
;
545 len
= sizeof(struct i40e_virtchnl_vlan_filter_list
) +
546 (count
* sizeof(u16
));
547 if (len
> I40EVF_MAX_AQ_BUF_SIZE
) {
548 dev_warn(&adapter
->pdev
->dev
, "Too many add VLAN changes in one request\n");
549 count
= (I40EVF_MAX_AQ_BUF_SIZE
-
550 sizeof(struct i40e_virtchnl_vlan_filter_list
)) /
552 len
= sizeof(struct i40e_virtchnl_vlan_filter_list
) +
553 (count
* sizeof(u16
));
556 vvfl
= kzalloc(len
, GFP_KERNEL
);
560 vvfl
->vsi_id
= adapter
->vsi_res
->vsi_id
;
561 vvfl
->num_elements
= count
;
562 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
564 vvfl
->vlan_id
[i
] = f
->vlan
;
572 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER
;
573 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_ADD_VLAN
, (u8
*)vvfl
, len
);
579 * @adapter: adapter structure
580 * @vlans: the VLANs to remove
581 * @count: number of VLANs
583 * Request that the PF remove one or more VLAN filters from our VSI.
585 void i40evf_del_vlans(struct i40evf_adapter
*adapter
)
587 struct i40e_virtchnl_vlan_filter_list
*vvfl
;
588 struct i40evf_vlan_filter
*f
, *ftmp
;
589 int len
, i
= 0, count
= 0;
592 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
593 /* bail because we already have a command pending */
594 dev_err(&adapter
->pdev
->dev
, "Cannot remove VLANs, command %d pending\n",
595 adapter
->current_op
);
599 list_for_each_entry(f
, &adapter
->vlan_filter_list
, list
) {
604 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
607 adapter
->current_op
= I40E_VIRTCHNL_OP_DEL_VLAN
;
609 len
= sizeof(struct i40e_virtchnl_vlan_filter_list
) +
610 (count
* sizeof(u16
));
611 if (len
> I40EVF_MAX_AQ_BUF_SIZE
) {
612 dev_warn(&adapter
->pdev
->dev
, "Too many delete VLAN changes in one request\n");
613 count
= (I40EVF_MAX_AQ_BUF_SIZE
-
614 sizeof(struct i40e_virtchnl_vlan_filter_list
)) /
616 len
= sizeof(struct i40e_virtchnl_vlan_filter_list
) +
617 (count
* sizeof(u16
));
620 vvfl
= kzalloc(len
, GFP_KERNEL
);
624 vvfl
->vsi_id
= adapter
->vsi_res
->vsi_id
;
625 vvfl
->num_elements
= count
;
626 list_for_each_entry_safe(f
, ftmp
, &adapter
->vlan_filter_list
, list
) {
628 vvfl
->vlan_id
[i
] = f
->vlan
;
637 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER
;
638 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_DEL_VLAN
, (u8
*)vvfl
, len
);
643 * i40evf_set_promiscuous
644 * @adapter: adapter structure
645 * @flags: bitmask to control unicast/multicast promiscuous.
647 * Request that the PF enable promiscuous mode for our VSI.
649 void i40evf_set_promiscuous(struct i40evf_adapter
*adapter
, int flags
)
651 struct i40e_virtchnl_promisc_info vpi
;
654 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
655 /* bail because we already have a command pending */
656 dev_err(&adapter
->pdev
->dev
, "Cannot set promiscuous mode, command %d pending\n",
657 adapter
->current_op
);
661 promisc_all
= I40E_FLAG_VF_UNICAST_PROMISC
|
662 I40E_FLAG_VF_MULTICAST_PROMISC
;
663 if ((flags
& promisc_all
) == promisc_all
) {
664 adapter
->flags
|= I40EVF_FLAG_PROMISC_ON
;
665 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_REQUEST_PROMISC
;
666 dev_info(&adapter
->pdev
->dev
, "Entering promiscuous mode\n");
669 if (flags
& I40E_FLAG_VF_MULTICAST_PROMISC
) {
670 adapter
->flags
|= I40EVF_FLAG_ALLMULTI_ON
;
671 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI
;
672 dev_info(&adapter
->pdev
->dev
, "Entering multicast promiscuous mode\n");
676 adapter
->flags
&= ~I40EVF_FLAG_PROMISC_ON
;
677 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_RELEASE_PROMISC
;
678 dev_info(&adapter
->pdev
->dev
, "Leaving promiscuous mode\n");
681 adapter
->current_op
= I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
;
682 vpi
.vsi_id
= adapter
->vsi_res
->vsi_id
;
684 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE
,
685 (u8
*)&vpi
, sizeof(vpi
));
689 * i40evf_request_stats
690 * @adapter: adapter structure
692 * Request VSI statistics from PF.
694 void i40evf_request_stats(struct i40evf_adapter
*adapter
)
696 struct i40e_virtchnl_queue_select vqs
;
698 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
699 /* no error message, this isn't crucial */
702 adapter
->current_op
= I40E_VIRTCHNL_OP_GET_STATS
;
703 vqs
.vsi_id
= adapter
->vsi_res
->vsi_id
;
704 /* queue maps are ignored for this message - only the vsi is used */
705 if (i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_GET_STATS
,
706 (u8
*)&vqs
, sizeof(vqs
)))
707 /* if the request failed, don't lock out others */
708 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
713 * @adapter: adapter structure
715 * Request hash enable capabilities from PF
717 void i40evf_get_hena(struct i40evf_adapter
*adapter
)
719 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
720 /* bail because we already have a command pending */
721 dev_err(&adapter
->pdev
->dev
, "Cannot get RSS hash capabilities, command %d pending\n",
722 adapter
->current_op
);
725 adapter
->current_op
= I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS
;
726 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_GET_HENA
;
727 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS
,
733 * @adapter: adapter structure
735 * Request the PF to set our RSS hash capabilities
737 void i40evf_set_hena(struct i40evf_adapter
*adapter
)
739 struct i40e_virtchnl_rss_hena vrh
;
741 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
742 /* bail because we already have a command pending */
743 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS hash enable, command %d pending\n",
744 adapter
->current_op
);
747 vrh
.hena
= adapter
->hena
;
748 adapter
->current_op
= I40E_VIRTCHNL_OP_SET_RSS_HENA
;
749 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_SET_HENA
;
750 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_SET_RSS_HENA
,
751 (u8
*)&vrh
, sizeof(vrh
));
756 * @adapter: adapter structure
758 * Request the PF to set our RSS hash key
760 void i40evf_set_rss_key(struct i40evf_adapter
*adapter
)
762 struct i40e_virtchnl_rss_key
*vrk
;
765 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
766 /* bail because we already have a command pending */
767 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS key, command %d pending\n",
768 adapter
->current_op
);
771 len
= sizeof(struct i40e_virtchnl_rss_key
) +
772 (adapter
->rss_key_size
* sizeof(u8
)) - 1;
773 vrk
= kzalloc(len
, GFP_KERNEL
);
776 vrk
->vsi_id
= adapter
->vsi
.id
;
777 vrk
->key_len
= adapter
->rss_key_size
;
778 memcpy(vrk
->key
, adapter
->rss_key
, adapter
->rss_key_size
);
780 adapter
->current_op
= I40E_VIRTCHNL_OP_CONFIG_RSS_KEY
;
781 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_SET_RSS_KEY
;
782 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY
,
789 * @adapter: adapter structure
791 * Request the PF to set our RSS lookup table
793 void i40evf_set_rss_lut(struct i40evf_adapter
*adapter
)
795 struct i40e_virtchnl_rss_lut
*vrl
;
798 if (adapter
->current_op
!= I40E_VIRTCHNL_OP_UNKNOWN
) {
799 /* bail because we already have a command pending */
800 dev_err(&adapter
->pdev
->dev
, "Cannot set RSS LUT, command %d pending\n",
801 adapter
->current_op
);
804 len
= sizeof(struct i40e_virtchnl_rss_lut
) +
805 (adapter
->rss_lut_size
* sizeof(u8
)) - 1;
806 vrl
= kzalloc(len
, GFP_KERNEL
);
809 vrl
->vsi_id
= adapter
->vsi
.id
;
810 vrl
->lut_entries
= adapter
->rss_lut_size
;
811 memcpy(vrl
->lut
, adapter
->rss_lut
, adapter
->rss_lut_size
);
812 adapter
->current_op
= I40E_VIRTCHNL_OP_CONFIG_RSS_LUT
;
813 adapter
->aq_required
&= ~I40EVF_FLAG_AQ_SET_RSS_LUT
;
814 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT
,
820 * i40evf_print_link_message - print link up or down
821 * @adapter: adapter structure
823 * Log a message telling the world of our wonderous link status
825 static void i40evf_print_link_message(struct i40evf_adapter
*adapter
)
827 struct net_device
*netdev
= adapter
->netdev
;
828 char *speed
= "Unknown ";
830 if (!adapter
->link_up
) {
831 netdev_info(netdev
, "NIC Link is Down\n");
835 switch (adapter
->link_speed
) {
836 case I40E_LINK_SPEED_40GB
:
839 case I40E_LINK_SPEED_25GB
:
842 case I40E_LINK_SPEED_20GB
:
845 case I40E_LINK_SPEED_10GB
:
848 case I40E_LINK_SPEED_1GB
:
851 case I40E_LINK_SPEED_100MB
:
858 netdev_info(netdev
, "NIC Link is Up %sbps Full Duplex\n", speed
);
862 * i40evf_request_reset
863 * @adapter: adapter structure
865 * Request that the PF reset this VF. No response is expected.
867 void i40evf_request_reset(struct i40evf_adapter
*adapter
)
869 /* Don't check CURRENT_OP - this is always higher priority */
870 i40evf_send_pf_msg(adapter
, I40E_VIRTCHNL_OP_RESET_VF
, NULL
, 0);
871 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;
875 * i40evf_virtchnl_completion
876 * @adapter: adapter structure
877 * @v_opcode: opcode sent by PF
878 * @v_retval: retval sent by PF
879 * @msg: message sent by PF
880 * @msglen: message length
882 * Asynchronous completion function for admin queue messages. Rather than busy
883 * wait, we fire off our requests and assume that no errors will be returned.
884 * This function handles the reply messages.
886 void i40evf_virtchnl_completion(struct i40evf_adapter
*adapter
,
887 enum i40e_virtchnl_ops v_opcode
,
888 i40e_status v_retval
,
891 struct net_device
*netdev
= adapter
->netdev
;
893 if (v_opcode
== I40E_VIRTCHNL_OP_EVENT
) {
894 struct i40e_virtchnl_pf_event
*vpe
=
895 (struct i40e_virtchnl_pf_event
*)msg
;
896 switch (vpe
->event
) {
897 case I40E_VIRTCHNL_EVENT_LINK_CHANGE
:
898 adapter
->link_speed
=
899 vpe
->event_data
.link_event
.link_speed
;
900 if (adapter
->link_up
!=
901 vpe
->event_data
.link_event
.link_status
) {
903 vpe
->event_data
.link_event
.link_status
;
904 if (adapter
->link_up
) {
905 netif_tx_start_all_queues(netdev
);
906 netif_carrier_on(netdev
);
908 netif_tx_stop_all_queues(netdev
);
909 netif_carrier_off(netdev
);
911 i40evf_print_link_message(adapter
);
914 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING
:
915 dev_info(&adapter
->pdev
->dev
, "PF reset warning received\n");
916 if (!(adapter
->flags
& I40EVF_FLAG_RESET_PENDING
)) {
917 adapter
->flags
|= I40EVF_FLAG_RESET_PENDING
;
918 dev_info(&adapter
->pdev
->dev
, "Scheduling reset task\n");
919 schedule_work(&adapter
->reset_task
);
923 dev_err(&adapter
->pdev
->dev
, "Unknown event %d from PF\n",
931 case I40E_VIRTCHNL_OP_ADD_VLAN
:
932 dev_err(&adapter
->pdev
->dev
, "Failed to add VLAN filter, error %s\n",
933 i40evf_stat_str(&adapter
->hw
, v_retval
));
935 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS
:
936 dev_err(&adapter
->pdev
->dev
, "Failed to add MAC filter, error %s\n",
937 i40evf_stat_str(&adapter
->hw
, v_retval
));
939 case I40E_VIRTCHNL_OP_DEL_VLAN
:
940 dev_err(&adapter
->pdev
->dev
, "Failed to delete VLAN filter, error %s\n",
941 i40evf_stat_str(&adapter
->hw
, v_retval
));
943 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS
:
944 dev_err(&adapter
->pdev
->dev
, "Failed to delete MAC filter, error %s\n",
945 i40evf_stat_str(&adapter
->hw
, v_retval
));
948 dev_err(&adapter
->pdev
->dev
, "PF returned error %d (%s) to our request %d\n",
950 i40evf_stat_str(&adapter
->hw
, v_retval
),
955 case I40E_VIRTCHNL_OP_GET_STATS
: {
956 struct i40e_eth_stats
*stats
=
957 (struct i40e_eth_stats
*)msg
;
958 adapter
->net_stats
.rx_packets
= stats
->rx_unicast
+
959 stats
->rx_multicast
+
961 adapter
->net_stats
.tx_packets
= stats
->tx_unicast
+
962 stats
->tx_multicast
+
964 adapter
->net_stats
.rx_bytes
= stats
->rx_bytes
;
965 adapter
->net_stats
.tx_bytes
= stats
->tx_bytes
;
966 adapter
->net_stats
.tx_errors
= stats
->tx_errors
;
967 adapter
->net_stats
.rx_dropped
= stats
->rx_discards
;
968 adapter
->net_stats
.tx_dropped
= stats
->tx_discards
;
969 adapter
->current_stats
= *stats
;
972 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES
: {
973 u16 len
= sizeof(struct i40e_virtchnl_vf_resource
) +
975 sizeof(struct i40e_virtchnl_vsi_resource
);
976 memcpy(adapter
->vf_res
, msg
, min(msglen
, len
));
977 i40e_vf_parse_hw_config(&adapter
->hw
, adapter
->vf_res
);
978 /* restore current mac address */
979 ether_addr_copy(adapter
->hw
.mac
.addr
, netdev
->dev_addr
);
980 i40evf_process_config(adapter
);
983 case I40E_VIRTCHNL_OP_ENABLE_QUEUES
:
984 /* enable transmits */
985 i40evf_irq_enable(adapter
, true);
987 case I40E_VIRTCHNL_OP_DISABLE_QUEUES
:
988 i40evf_free_all_tx_resources(adapter
);
989 i40evf_free_all_rx_resources(adapter
);
990 if (adapter
->state
== __I40EVF_DOWN_PENDING
)
991 adapter
->state
= __I40EVF_DOWN
;
993 case I40E_VIRTCHNL_OP_VERSION
:
994 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP
:
995 /* Don't display an error if we get these out of sequence.
996 * If the firmware needed to get kicked, we'll get these and
999 if (v_opcode
!= adapter
->current_op
)
1002 case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
:
1003 adapter
->client_pending
&=
1004 ~(BIT(I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP
));
1006 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS
: {
1007 struct i40e_virtchnl_rss_hena
*vrh
=
1008 (struct i40e_virtchnl_rss_hena
*)msg
;
1009 if (msglen
== sizeof(*vrh
))
1010 adapter
->hena
= vrh
->hena
;
1012 dev_warn(&adapter
->pdev
->dev
,
1013 "Invalid message %d from PF\n", v_opcode
);
1017 if (v_opcode
!= adapter
->current_op
)
1018 dev_warn(&adapter
->pdev
->dev
, "Expected response %d from PF, received %d\n",
1019 adapter
->current_op
, v_opcode
);
1021 } /* switch v_opcode */
1022 adapter
->current_op
= I40E_VIRTCHNL_OP_UNKNOWN
;