blob: ba7fbc0608a6bb6d36dcc88a778ef9e77aa9b7a7 [file] [log] [blame]
Greg Rose62683ab2013-12-21 06:13:01 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
Mitch Williamsef8693e2014-02-13 03:48:53 -08004 * Copyright(c) 2013 - 2014 Intel Corporation.
Greg Rose62683ab2013-12-21 06:13:01 +00005 *
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.
9 *
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
13 * more details.
14 *
Jesse Brandeburgb8316072014-04-05 07:46:11 +000015 * 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/>.
17 *
Greg Rose62683ab2013-12-21 06:13:01 +000018 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
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
24 *
25 ******************************************************************************/
26
27#include "i40evf.h"
28#include "i40e_prototype.h"
29
30/* busy wait delay in msec */
31#define I40EVF_BUSY_WAIT_DELAY 10
32#define I40EVF_BUSY_WAIT_COUNT 50
33
34/**
35 * i40evf_send_pf_msg
36 * @adapter: adapter structure
37 * @op: virtual channel opcode
38 * @msg: pointer to message buffer
39 * @len: message length
40 *
41 * Send message to PF and print status if failure.
42 **/
43static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
44 enum i40e_virtchnl_ops op, u8 *msg, u16 len)
45{
46 struct i40e_hw *hw = &adapter->hw;
47 i40e_status err;
48
Mitch Williamsef8693e2014-02-13 03:48:53 -080049 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
50 return 0; /* nothing to see here, move along */
51
Greg Rose62683ab2013-12-21 06:13:01 +000052 err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
53 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040054 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));
Greg Rose62683ab2013-12-21 06:13:01 +000057 return err;
58}
59
60/**
61 * i40evf_send_api_ver
62 * @adapter: adapter structure
63 *
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.
67 **/
68int i40evf_send_api_ver(struct i40evf_adapter *adapter)
69{
70 struct i40e_virtchnl_version_info vvi;
71
72 vvi.major = I40E_VIRTCHNL_VERSION_MAJOR;
73 vvi.minor = I40E_VIRTCHNL_VERSION_MINOR;
74
75 return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi,
76 sizeof(vvi));
77}
78
79/**
80 * i40evf_verify_api_ver
81 * @adapter: adapter structure
82 *
83 * Compare API versions with the PF. Must be called after admin queue is
Mitch Williams6a8e93d2014-06-05 00:09:17 +000084 * 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.
Greg Rose62683ab2013-12-21 06:13:01 +000087 **/
88int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
89{
90 struct i40e_virtchnl_version_info *pf_vvi;
91 struct i40e_hw *hw = &adapter->hw;
92 struct i40e_arq_event_info event;
Mitch Williamsf8d4db32014-10-25 03:24:33 +000093 enum i40e_virtchnl_ops op;
Greg Rose62683ab2013-12-21 06:13:01 +000094 i40e_status err;
95
Mitch Williams1001dc32014-11-11 20:02:19 +000096 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
97 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Greg Rose62683ab2013-12-21 06:13:01 +000098 if (!event.msg_buf) {
99 err = -ENOMEM;
100 goto out;
101 }
102
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000103 while (1) {
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.
107 */
108 if (err)
109 goto out_alloc;
110 op =
111 (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
112 if (op == I40E_VIRTCHNL_OP_VERSION)
113 break;
114 }
115
Greg Rose62683ab2013-12-21 06:13:01 +0000116
117 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
Mitch Williams6a8e93d2014-06-05 00:09:17 +0000118 if (err)
Greg Rose62683ab2013-12-21 06:13:01 +0000119 goto out_alloc;
Greg Rose62683ab2013-12-21 06:13:01 +0000120
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000121 if (op != I40E_VIRTCHNL_OP_VERSION) {
Mitch Williams6a8e93d2014-06-05 00:09:17 +0000122 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000123 op);
Greg Rose62683ab2013-12-21 06:13:01 +0000124 err = -EIO;
125 goto out_alloc;
126 }
127
128 pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf;
Mitch Williamsee1693e2015-06-04 16:23:59 -0400129 adapter->pf_version = *pf_vvi;
130
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)))
Greg Rose62683ab2013-12-21 06:13:01 +0000134 err = -EIO;
135
136out_alloc:
137 kfree(event.msg_buf);
138out:
139 return err;
140}
141
142/**
143 * i40evf_send_vf_config_msg
144 * @adapter: adapter structure
145 *
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.
149 **/
150int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
151{
Mitch Williamse6d038d2015-06-04 16:23:58 -0400152 u32 caps;
153
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 |
Anjali Singhai Jain1f012272015-09-03 17:18:53 -0400159 I40E_VIRTCHNL_VF_OFFLOAD_VLAN |
Anjali Singhai Jainb9eacec2015-11-19 11:34:22 -0800160 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
161 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
162
Mitch Williamse6d038d2015-06-04 16:23:58 -0400163 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));
169 else
170 return i40evf_send_pf_msg(adapter,
171 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
172 NULL, 0);
Greg Rose62683ab2013-12-21 06:13:01 +0000173}
174
175/**
176 * i40evf_get_vf_config
177 * @hw: pointer to the hardware structure
178 * @len: length of buffer
179 *
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.
184 **/
185int i40evf_get_vf_config(struct i40evf_adapter *adapter)
186{
187 struct i40e_hw *hw = &adapter->hw;
188 struct i40e_arq_event_info event;
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000189 enum i40e_virtchnl_ops op;
Greg Rose62683ab2013-12-21 06:13:01 +0000190 i40e_status err;
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000191 u16 len;
Greg Rose62683ab2013-12-21 06:13:01 +0000192
193 len = sizeof(struct i40e_virtchnl_vf_resource) +
194 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
Mitch Williams1001dc32014-11-11 20:02:19 +0000195 event.buf_len = len;
196 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Greg Rose62683ab2013-12-21 06:13:01 +0000197 if (!event.msg_buf) {
198 err = -ENOMEM;
199 goto out;
200 }
201
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000202 while (1) {
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000203 /* When the AQ is empty, i40evf_clean_arq_element will return
204 * nonzero and this loop will terminate.
205 */
206 err = i40evf_clean_arq_element(hw, &event, NULL);
207 if (err)
208 goto out_alloc;
209 op =
210 (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
211 if (op == I40E_VIRTCHNL_OP_GET_VF_RESOURCES)
212 break;
213 }
Greg Rose62683ab2013-12-21 06:13:01 +0000214
215 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
Mitch Williams1001dc32014-11-11 20:02:19 +0000216 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
Greg Rose62683ab2013-12-21 06:13:01 +0000217
218 i40e_vf_parse_hw_config(hw, adapter->vf_res);
219out_alloc:
220 kfree(event.msg_buf);
221out:
222 return err;
223}
224
225/**
226 * i40evf_configure_queues
227 * @adapter: adapter structure
228 *
229 * Request that the PF set up our (previously allocated) queues.
230 **/
231void i40evf_configure_queues(struct i40evf_adapter *adapter)
232{
233 struct i40e_virtchnl_vsi_queue_config_info *vqci;
234 struct i40e_virtchnl_queue_pair_info *vqpi;
Mitch Williamscc052922014-10-25 03:24:34 +0000235 int pairs = adapter->num_active_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000236 int i, len;
237
238 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
239 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400240 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
241 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000242 return;
243 }
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);
Mitch Williamsa85088d2015-11-06 15:26:04 -0800247 vqci = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000248 if (!vqci)
Greg Rose62683ab2013-12-21 06:13:01 +0000249 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000250
Greg Rose62683ab2013-12-21 06:13:01 +0000251 vqci->vsi_id = adapter->vsi_res->vsi_id;
252 vqci->num_queue_pairs = pairs;
253 vqpi = vqci->qpair;
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.
256 */
257 for (i = 0; i < pairs; i++) {
258 vqpi->txq.vsi_id = vqci->vsi_id;
259 vqpi->txq.queue_id = i;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400260 vqpi->txq.ring_len = adapter->tx_rings[i].count;
261 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
Ashish Shah5d298962014-05-22 06:31:25 +0000262 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));
Greg Rose62683ab2013-12-21 06:13:01 +0000265
266 vqpi->rxq.vsi_id = vqci->vsi_id;
267 vqpi->rxq.queue_id = i;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400268 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
269 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
Greg Rose62683ab2013-12-21 06:13:01 +0000270 vqpi->rxq.max_pkt_size = adapter->netdev->mtu
271 + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400272 vqpi->rxq.databuffer_size = adapter->rx_rings[i].rx_buf_len;
Mitch Williams00e5ec42016-01-15 14:33:10 -0800273 if (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED) {
274 vqpi->rxq.splithdr_enabled = true;
275 vqpi->rxq.hdr_size = I40E_RX_HDR_SIZE;
276 }
Greg Rose62683ab2013-12-21 06:13:01 +0000277 vqpi++;
278 }
279
Mitch Williamsfc86a972014-06-04 20:41:38 +0000280 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
Greg Rose62683ab2013-12-21 06:13:01 +0000281 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
282 (u8 *)vqci, len);
283 kfree(vqci);
Greg Rose62683ab2013-12-21 06:13:01 +0000284}
285
286/**
287 * i40evf_enable_queues
288 * @adapter: adapter structure
289 *
290 * Request that the PF enable all of our queues.
291 **/
292void i40evf_enable_queues(struct i40evf_adapter *adapter)
293{
294 struct i40e_virtchnl_queue_select vqs;
295
296 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
297 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400298 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
299 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000300 return;
301 }
302 adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
303 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400304 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000305 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000306 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000307 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
308 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000309}
310
311/**
312 * i40evf_disable_queues
313 * @adapter: adapter structure
314 *
315 * Request that the PF disable all of our queues.
316 **/
317void i40evf_disable_queues(struct i40evf_adapter *adapter)
318{
319 struct i40e_virtchnl_queue_select vqs;
320
321 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
322 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400323 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
324 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000325 return;
326 }
327 adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
328 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400329 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000330 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000331 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000332 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
333 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000334}
335
336/**
337 * i40evf_map_queues
338 * @adapter: adapter structure
339 *
340 * Request that the PF map queues to interrupt vectors. Misc causes, including
341 * admin queue, are always mapped to vector 0.
342 **/
343void i40evf_map_queues(struct i40evf_adapter *adapter)
344{
345 struct i40e_virtchnl_irq_map_info *vimi;
346 int v_idx, q_vectors, len;
347 struct i40e_q_vector *q_vector;
348
349 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
350 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400351 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
352 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000353 return;
354 }
355 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
356
357 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
358
359 len = sizeof(struct i40e_virtchnl_irq_map_info) +
360 (adapter->num_msix_vectors *
361 sizeof(struct i40e_virtchnl_vector_map));
Mitch Williamsa85088d2015-11-06 15:26:04 -0800362 vimi = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000363 if (!vimi)
Greg Rose62683ab2013-12-21 06:13:01 +0000364 return;
Greg Rose62683ab2013-12-21 06:13:01 +0000365
366 vimi->num_vectors = adapter->num_msix_vectors;
367 /* Queue vectors first */
368 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -0400369 q_vector = adapter->q_vectors + v_idx;
Greg Rose62683ab2013-12-21 06:13:01 +0000370 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
371 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
372 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
373 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
374 }
375 /* Misc vector last - this is only for AdminQ messages */
376 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
377 vimi->vecmap[v_idx].vector_id = 0;
378 vimi->vecmap[v_idx].txq_map = 0;
379 vimi->vecmap[v_idx].rxq_map = 0;
380
Mitch Williamsfc86a972014-06-04 20:41:38 +0000381 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
Greg Rose62683ab2013-12-21 06:13:01 +0000382 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
383 (u8 *)vimi, len);
384 kfree(vimi);
Greg Rose62683ab2013-12-21 06:13:01 +0000385}
386
387/**
388 * i40evf_add_ether_addrs
389 * @adapter: adapter structure
390 * @addrs: the MAC address filters to add (contiguous)
391 * @count: number of filters
392 *
393 * Request that the PF add one or more addresses to our filters.
394 **/
395void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
396{
397 struct i40e_virtchnl_ether_addr_list *veal;
398 int len, i = 0, count = 0;
399 struct i40evf_mac_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400400 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000401
402 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
403 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400404 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
405 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000406 return;
407 }
408 list_for_each_entry(f, &adapter->mac_filter_list, list) {
409 if (f->add)
410 count++;
411 }
412 if (!count) {
413 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
414 return;
415 }
416 adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
417
418 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
419 (count * sizeof(struct i40e_virtchnl_ether_addr));
420 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400421 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000422 count = (I40EVF_MAX_AQ_BUF_SIZE -
423 sizeof(struct i40e_virtchnl_ether_addr_list)) /
424 sizeof(struct i40e_virtchnl_ether_addr);
Mitch Williams1418c342015-10-21 19:47:12 -0400425 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
426 (count * sizeof(struct i40e_virtchnl_ether_addr));
427 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000428 }
429
Mitch Williamsa85088d2015-11-06 15:26:04 -0800430 veal = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000431 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000432 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000433
Greg Rose62683ab2013-12-21 06:13:01 +0000434 veal->vsi_id = adapter->vsi_res->vsi_id;
435 veal->num_elements = count;
436 list_for_each_entry(f, &adapter->mac_filter_list, list) {
437 if (f->add) {
Greg Rose9a173902014-05-22 06:32:02 +0000438 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000439 i++;
440 f->add = false;
441 }
442 }
Mitch Williams1418c342015-10-21 19:47:12 -0400443 if (!more)
444 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Greg Rose62683ab2013-12-21 06:13:01 +0000445 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
446 (u8 *)veal, len);
447 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000448}
449
450/**
451 * i40evf_del_ether_addrs
452 * @adapter: adapter structure
453 * @addrs: the MAC address filters to remove (contiguous)
454 * @count: number of filtes
455 *
456 * Request that the PF remove one or more addresses from our filters.
457 **/
458void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
459{
460 struct i40e_virtchnl_ether_addr_list *veal;
461 struct i40evf_mac_filter *f, *ftmp;
462 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400463 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000464
465 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
466 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400467 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
468 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000469 return;
470 }
471 list_for_each_entry(f, &adapter->mac_filter_list, list) {
472 if (f->remove)
473 count++;
474 }
475 if (!count) {
476 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
477 return;
478 }
479 adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
480
481 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
482 (count * sizeof(struct i40e_virtchnl_ether_addr));
483 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400484 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000485 count = (I40EVF_MAX_AQ_BUF_SIZE -
486 sizeof(struct i40e_virtchnl_ether_addr_list)) /
487 sizeof(struct i40e_virtchnl_ether_addr);
Mitch Williams1418c342015-10-21 19:47:12 -0400488 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
489 (count * sizeof(struct i40e_virtchnl_ether_addr));
490 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000491 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800492 veal = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000493 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000494 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000495
Greg Rose62683ab2013-12-21 06:13:01 +0000496 veal->vsi_id = adapter->vsi_res->vsi_id;
497 veal->num_elements = count;
498 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
499 if (f->remove) {
Greg Rose9a173902014-05-22 06:32:02 +0000500 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000501 i++;
502 list_del(&f->list);
503 kfree(f);
504 }
505 }
Mitch Williams1418c342015-10-21 19:47:12 -0400506 if (!more)
507 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Greg Rose62683ab2013-12-21 06:13:01 +0000508 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
509 (u8 *)veal, len);
510 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000511}
512
513/**
514 * i40evf_add_vlans
515 * @adapter: adapter structure
516 * @vlans: the VLANs to add
517 * @count: number of VLANs
518 *
519 * Request that the PF add one or more VLAN filters to our VSI.
520 **/
521void i40evf_add_vlans(struct i40evf_adapter *adapter)
522{
523 struct i40e_virtchnl_vlan_filter_list *vvfl;
524 int len, i = 0, count = 0;
525 struct i40evf_vlan_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400526 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000527
528 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
529 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400530 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
531 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000532 return;
533 }
534
535 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
536 if (f->add)
537 count++;
538 }
539 if (!count) {
540 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
541 return;
542 }
543 adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
544
545 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
546 (count * sizeof(u16));
547 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400548 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000549 count = (I40EVF_MAX_AQ_BUF_SIZE -
550 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
551 sizeof(u16);
Mitch Williams1418c342015-10-21 19:47:12 -0400552 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
553 (count * sizeof(u16));
554 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000555 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800556 vvfl = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000557 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000558 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000559
Greg Rose62683ab2013-12-21 06:13:01 +0000560 vvfl->vsi_id = adapter->vsi_res->vsi_id;
561 vvfl->num_elements = count;
562 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
563 if (f->add) {
564 vvfl->vlan_id[i] = f->vlan;
565 i++;
566 f->add = false;
567 }
568 }
Mitch Williams1418c342015-10-21 19:47:12 -0400569 if (!more)
570 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000571 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
572 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000573}
574
575/**
576 * i40evf_del_vlans
577 * @adapter: adapter structure
578 * @vlans: the VLANs to remove
579 * @count: number of VLANs
580 *
581 * Request that the PF remove one or more VLAN filters from our VSI.
582 **/
583void i40evf_del_vlans(struct i40evf_adapter *adapter)
584{
585 struct i40e_virtchnl_vlan_filter_list *vvfl;
586 struct i40evf_vlan_filter *f, *ftmp;
587 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400588 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000589
590 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
591 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400592 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
593 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000594 return;
595 }
596
597 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
598 if (f->remove)
599 count++;
600 }
601 if (!count) {
602 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
603 return;
604 }
605 adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
606
607 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
608 (count * sizeof(u16));
609 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400610 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000611 count = (I40EVF_MAX_AQ_BUF_SIZE -
612 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
613 sizeof(u16);
Mitch Williams1418c342015-10-21 19:47:12 -0400614 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
615 (count * sizeof(u16));
616 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000617 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800618 vvfl = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000619 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000620 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000621
Greg Rose62683ab2013-12-21 06:13:01 +0000622 vvfl->vsi_id = adapter->vsi_res->vsi_id;
623 vvfl->num_elements = count;
624 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
625 if (f->remove) {
626 vvfl->vlan_id[i] = f->vlan;
627 i++;
628 list_del(&f->list);
629 kfree(f);
630 }
631 }
Mitch Williams1418c342015-10-21 19:47:12 -0400632 if (!more)
633 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000634 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
635 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000636}
637
638/**
639 * i40evf_set_promiscuous
640 * @adapter: adapter structure
641 * @flags: bitmask to control unicast/multicast promiscuous.
642 *
643 * Request that the PF enable promiscuous mode for our VSI.
644 **/
645void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
646{
647 struct i40e_virtchnl_promisc_info vpi;
648
649 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
650 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400651 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
652 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000653 return;
654 }
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700655
656 if (flags) {
657 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
658 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
659 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
660 } else {
661 adapter->flags &= ~I40EVF_FLAG_PROMISC_ON;
662 adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC;
663 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
664 }
665
Greg Rose62683ab2013-12-21 06:13:01 +0000666 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
667 vpi.vsi_id = adapter->vsi_res->vsi_id;
668 vpi.flags = flags;
669 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
670 (u8 *)&vpi, sizeof(vpi));
671}
672
673/**
674 * i40evf_request_stats
675 * @adapter: adapter structure
676 *
677 * Request VSI statistics from PF.
678 **/
679void i40evf_request_stats(struct i40evf_adapter *adapter)
680{
681 struct i40e_virtchnl_queue_select vqs;
Mitch Williams75a64432014-11-11 20:02:42 +0000682
Greg Rose62683ab2013-12-21 06:13:01 +0000683 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
684 /* no error message, this isn't crucial */
685 return;
686 }
687 adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
688 vqs.vsi_id = adapter->vsi_res->vsi_id;
689 /* queue maps are ignored for this message - only the vsi is used */
690 if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
691 (u8 *)&vqs, sizeof(vqs)))
692 /* if the request failed, don't lock out others */
693 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
694}
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700695
696/**
697 * i40evf_get_hena
698 * @adapter: adapter structure
699 *
700 * Request hash enable capabilities from PF
701 **/
702void i40evf_get_hena(struct i40evf_adapter *adapter)
703{
704 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
705 /* bail because we already have a command pending */
706 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
707 adapter->current_op);
708 return;
709 }
710 adapter->current_op = I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS;
711 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
712 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS,
713 NULL, 0);
714}
715
716/**
717 * i40evf_set_hena
718 * @adapter: adapter structure
719 *
720 * Request the PF to set our RSS hash capabilities
721 **/
722void i40evf_set_hena(struct i40evf_adapter *adapter)
723{
724 struct i40e_virtchnl_rss_hena vrh;
725
726 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
727 /* bail because we already have a command pending */
728 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
729 adapter->current_op);
730 return;
731 }
732 vrh.hena = adapter->hena;
733 adapter->current_op = I40E_VIRTCHNL_OP_SET_RSS_HENA;
734 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
735 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_SET_RSS_HENA,
736 (u8 *)&vrh, sizeof(vrh));
737}
738
739/**
740 * i40evf_set_rss_key
741 * @adapter: adapter structure
742 *
743 * Request the PF to set our RSS hash key
744 **/
745void i40evf_set_rss_key(struct i40evf_adapter *adapter)
746{
747 struct i40e_virtchnl_rss_key *vrk;
748 int len;
749
750 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
751 /* bail because we already have a command pending */
752 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
753 adapter->current_op);
754 return;
755 }
756 len = sizeof(struct i40e_virtchnl_rss_key) +
757 (adapter->rss_key_size * sizeof(u8)) - 1;
758 vrk = kzalloc(len, GFP_KERNEL);
759 if (!vrk)
760 return;
761 vrk->vsi_id = adapter->vsi.id;
762 vrk->key_len = adapter->rss_key_size;
763 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
764
765 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_KEY;
766 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
767 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY,
768 (u8 *)vrk, len);
769 kfree(vrk);
770}
771
772/**
773 * i40evf_set_rss_lut
774 * @adapter: adapter structure
775 *
776 * Request the PF to set our RSS lookup table
777 **/
778void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
779{
780 struct i40e_virtchnl_rss_lut *vrl;
781 int len;
782
783 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
784 /* bail because we already have a command pending */
785 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
786 adapter->current_op);
787 return;
788 }
789 len = sizeof(struct i40e_virtchnl_rss_lut) +
790 (adapter->rss_lut_size * sizeof(u8)) - 1;
791 vrl = kzalloc(len, GFP_KERNEL);
792 if (!vrl)
793 return;
794 vrl->vsi_id = adapter->vsi.id;
795 vrl->lut_entries = adapter->rss_lut_size;
796 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
797 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_LUT;
798 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
799 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT,
800 (u8 *)vrl, len);
801 kfree(vrl);
802}
803
Mitch Williams625777e2014-02-20 19:29:05 -0800804/**
805 * i40evf_request_reset
806 * @adapter: adapter structure
807 *
808 * Request that the PF reset this VF. No response is expected.
809 **/
810void i40evf_request_reset(struct i40evf_adapter *adapter)
811{
812 /* Don't check CURRENT_OP - this is always higher priority */
813 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
814 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
815}
Greg Rose62683ab2013-12-21 06:13:01 +0000816
817/**
818 * i40evf_virtchnl_completion
819 * @adapter: adapter structure
820 * @v_opcode: opcode sent by PF
821 * @v_retval: retval sent by PF
822 * @msg: message sent by PF
823 * @msglen: message length
824 *
825 * Asynchronous completion function for admin queue messages. Rather than busy
826 * wait, we fire off our requests and assume that no errors will be returned.
827 * This function handles the reply messages.
828 **/
829void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
830 enum i40e_virtchnl_ops v_opcode,
831 i40e_status v_retval,
832 u8 *msg, u16 msglen)
833{
834 struct net_device *netdev = adapter->netdev;
835
836 if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
837 struct i40e_virtchnl_pf_event *vpe =
838 (struct i40e_virtchnl_pf_event *)msg;
839 switch (vpe->event) {
840 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
841 adapter->link_up =
842 vpe->event_data.link_event.link_status;
843 if (adapter->link_up && !netif_carrier_ok(netdev)) {
844 dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
845 netif_carrier_on(netdev);
846 netif_tx_wake_all_queues(netdev);
847 } else if (!adapter->link_up) {
848 dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
849 netif_carrier_off(netdev);
850 netif_tx_stop_all_queues(netdev);
851 }
852 break;
853 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
Mitch Williamsef8693e2014-02-13 03:48:53 -0800854 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
855 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
856 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
857 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
858 schedule_work(&adapter->reset_task);
859 }
Greg Rose62683ab2013-12-21 06:13:01 +0000860 break;
861 default:
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400862 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
863 vpe->event);
Greg Rose62683ab2013-12-21 06:13:01 +0000864 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000865 }
866 return;
867 }
Greg Rose62683ab2013-12-21 06:13:01 +0000868 if (v_retval) {
Mitch Williams8d8f2292015-10-21 19:47:11 -0400869 switch (v_opcode) {
870 case I40E_VIRTCHNL_OP_ADD_VLAN:
871 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
872 i40evf_stat_str(&adapter->hw, v_retval));
873 break;
874 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
875 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
876 i40evf_stat_str(&adapter->hw, v_retval));
877 break;
878 case I40E_VIRTCHNL_OP_DEL_VLAN:
879 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
880 i40evf_stat_str(&adapter->hw, v_retval));
881 break;
882 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
883 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
884 i40evf_stat_str(&adapter->hw, v_retval));
885 break;
886 default:
887 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
888 v_retval,
889 i40evf_stat_str(&adapter->hw, v_retval),
890 v_opcode);
891 }
Greg Rose62683ab2013-12-21 06:13:01 +0000892 }
893 switch (v_opcode) {
894 case I40E_VIRTCHNL_OP_GET_STATS: {
895 struct i40e_eth_stats *stats =
896 (struct i40e_eth_stats *)msg;
897 adapter->net_stats.rx_packets = stats->rx_unicast +
898 stats->rx_multicast +
899 stats->rx_broadcast;
900 adapter->net_stats.tx_packets = stats->tx_unicast +
901 stats->tx_multicast +
902 stats->tx_broadcast;
903 adapter->net_stats.rx_bytes = stats->rx_bytes;
904 adapter->net_stats.tx_bytes = stats->tx_bytes;
Greg Rose62683ab2013-12-21 06:13:01 +0000905 adapter->net_stats.tx_errors = stats->tx_errors;
Shannon Nelson03da6f62014-04-23 04:50:19 +0000906 adapter->net_stats.rx_dropped = stats->rx_discards;
Greg Rose62683ab2013-12-21 06:13:01 +0000907 adapter->net_stats.tx_dropped = stats->tx_discards;
908 adapter->current_stats = *stats;
909 }
910 break;
Mitch Williamse6d038d2015-06-04 16:23:58 -0400911 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: {
912 u16 len = sizeof(struct i40e_virtchnl_vf_resource) +
913 I40E_MAX_VF_VSI *
914 sizeof(struct i40e_virtchnl_vsi_resource);
915 memcpy(adapter->vf_res, msg, min(msglen, len));
916 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
Mitch Williams8552d852015-08-31 19:54:51 -0400917 /* restore current mac address */
918 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
Mitch Williamse6d038d2015-06-04 16:23:58 -0400919 i40evf_process_config(adapter);
920 }
921 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000922 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
Greg Rose62683ab2013-12-21 06:13:01 +0000923 /* enable transmits */
924 i40evf_irq_enable(adapter, true);
925 netif_tx_start_all_queues(adapter->netdev);
926 netif_carrier_on(adapter->netdev);
927 break;
928 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
Mitch Williamse284fc82015-03-27 00:12:09 -0700929 i40evf_free_all_tx_resources(adapter);
930 i40evf_free_all_rx_resources(adapter);
Mitch Williams209dc4d2015-12-09 15:50:27 -0800931 if (adapter->state == __I40EVF_DOWN_PENDING)
932 adapter->state = __I40EVF_DOWN;
Greg Rose62683ab2013-12-21 06:13:01 +0000933 break;
Mitch Williamsed636962015-04-07 19:45:32 -0400934 case I40E_VIRTCHNL_OP_VERSION:
Greg Rose62683ab2013-12-21 06:13:01 +0000935 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
Mitch Williamsed636962015-04-07 19:45:32 -0400936 /* Don't display an error if we get these out of sequence.
937 * If the firmware needed to get kicked, we'll get these and
938 * it's no problem.
939 */
940 if (v_opcode != adapter->current_op)
941 return;
Greg Rose62683ab2013-12-21 06:13:01 +0000942 break;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700943 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
944 struct i40e_virtchnl_rss_hena *vrh =
945 (struct i40e_virtchnl_rss_hena *)msg;
946 if (msglen == sizeof(*vrh))
947 adapter->hena = vrh->hena;
948 else
949 dev_warn(&adapter->pdev->dev,
950 "Invalid message %d from PF\n", v_opcode);
951 }
952 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000953 default:
Mitch Williamsed636962015-04-07 19:45:32 -0400954 if (v_opcode != adapter->current_op)
955 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
956 adapter->current_op, v_opcode);
Greg Rose62683ab2013-12-21 06:13:01 +0000957 break;
958 } /* switch v_opcode */
959 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
960}