blob: d4eb1a5e7d42c4562a659202685d0e8331d384c9 [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 |
159 I40E_VIRTCHNL_VF_OFFLOAD_VLAN;
160 adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
161 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
162 if (PF_IS_V11(adapter))
163 return i40evf_send_pf_msg(adapter,
164 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
165 (u8 *)&caps, sizeof(caps));
166 else
167 return i40evf_send_pf_msg(adapter,
168 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
169 NULL, 0);
Greg Rose62683ab2013-12-21 06:13:01 +0000170}
171
172/**
173 * i40evf_get_vf_config
174 * @hw: pointer to the hardware structure
175 * @len: length of buffer
176 *
177 * Get VF configuration from PF and populate hw structure. Must be called after
178 * admin queue is initialized. Busy waits until response is received from PF,
179 * with maximum timeout. Response from PF is returned in the buffer for further
180 * processing by the caller.
181 **/
182int i40evf_get_vf_config(struct i40evf_adapter *adapter)
183{
184 struct i40e_hw *hw = &adapter->hw;
185 struct i40e_arq_event_info event;
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000186 enum i40e_virtchnl_ops op;
Greg Rose62683ab2013-12-21 06:13:01 +0000187 i40e_status err;
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000188 u16 len;
Greg Rose62683ab2013-12-21 06:13:01 +0000189
190 len = sizeof(struct i40e_virtchnl_vf_resource) +
191 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
Mitch Williams1001dc32014-11-11 20:02:19 +0000192 event.buf_len = len;
193 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Greg Rose62683ab2013-12-21 06:13:01 +0000194 if (!event.msg_buf) {
195 err = -ENOMEM;
196 goto out;
197 }
198
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000199 while (1) {
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000200 /* When the AQ is empty, i40evf_clean_arq_element will return
201 * nonzero and this loop will terminate.
202 */
203 err = i40evf_clean_arq_element(hw, &event, NULL);
204 if (err)
205 goto out_alloc;
206 op =
207 (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
208 if (op == I40E_VIRTCHNL_OP_GET_VF_RESOURCES)
209 break;
210 }
Greg Rose62683ab2013-12-21 06:13:01 +0000211
212 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
Mitch Williams1001dc32014-11-11 20:02:19 +0000213 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
Greg Rose62683ab2013-12-21 06:13:01 +0000214
215 i40e_vf_parse_hw_config(hw, adapter->vf_res);
216out_alloc:
217 kfree(event.msg_buf);
218out:
219 return err;
220}
221
222/**
223 * i40evf_configure_queues
224 * @adapter: adapter structure
225 *
226 * Request that the PF set up our (previously allocated) queues.
227 **/
228void i40evf_configure_queues(struct i40evf_adapter *adapter)
229{
230 struct i40e_virtchnl_vsi_queue_config_info *vqci;
231 struct i40e_virtchnl_queue_pair_info *vqpi;
Mitch Williamscc052922014-10-25 03:24:34 +0000232 int pairs = adapter->num_active_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000233 int i, len;
234
235 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
236 /* bail because we already have a command pending */
237 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
238 __func__, adapter->current_op);
239 return;
240 }
241 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
242 len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
243 (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
244 vqci = kzalloc(len, GFP_ATOMIC);
Mitch Williams249c8b82014-05-10 04:49:04 +0000245 if (!vqci)
Greg Rose62683ab2013-12-21 06:13:01 +0000246 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000247
Greg Rose62683ab2013-12-21 06:13:01 +0000248 vqci->vsi_id = adapter->vsi_res->vsi_id;
249 vqci->num_queue_pairs = pairs;
250 vqpi = vqci->qpair;
251 /* Size check is not needed here - HW max is 16 queue pairs, and we
252 * can fit info for 31 of them into the AQ buffer before it overflows.
253 */
254 for (i = 0; i < pairs; i++) {
255 vqpi->txq.vsi_id = vqci->vsi_id;
256 vqpi->txq.queue_id = i;
257 vqpi->txq.ring_len = adapter->tx_rings[i]->count;
258 vqpi->txq.dma_ring_addr = adapter->tx_rings[i]->dma;
Ashish Shah5d298962014-05-22 06:31:25 +0000259 vqpi->txq.headwb_enabled = 1;
260 vqpi->txq.dma_headwb_addr = vqpi->txq.dma_ring_addr +
261 (vqpi->txq.ring_len * sizeof(struct i40e_tx_desc));
Greg Rose62683ab2013-12-21 06:13:01 +0000262
263 vqpi->rxq.vsi_id = vqci->vsi_id;
264 vqpi->rxq.queue_id = i;
265 vqpi->rxq.ring_len = adapter->rx_rings[i]->count;
266 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i]->dma;
267 vqpi->rxq.max_pkt_size = adapter->netdev->mtu
268 + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
269 vqpi->rxq.databuffer_size = adapter->rx_rings[i]->rx_buf_len;
270 vqpi++;
271 }
272
Mitch Williamsfc86a972014-06-04 20:41:38 +0000273 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
Greg Rose62683ab2013-12-21 06:13:01 +0000274 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
275 (u8 *)vqci, len);
276 kfree(vqci);
Greg Rose62683ab2013-12-21 06:13:01 +0000277}
278
279/**
280 * i40evf_enable_queues
281 * @adapter: adapter structure
282 *
283 * Request that the PF enable all of our queues.
284 **/
285void i40evf_enable_queues(struct i40evf_adapter *adapter)
286{
287 struct i40e_virtchnl_queue_select vqs;
288
289 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
290 /* bail because we already have a command pending */
291 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
292 __func__, adapter->current_op);
293 return;
294 }
295 adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
296 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400297 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000298 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000299 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000300 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
301 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000302}
303
304/**
305 * i40evf_disable_queues
306 * @adapter: adapter structure
307 *
308 * Request that the PF disable all of our queues.
309 **/
310void i40evf_disable_queues(struct i40evf_adapter *adapter)
311{
312 struct i40e_virtchnl_queue_select vqs;
313
314 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
315 /* bail because we already have a command pending */
316 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
317 __func__, adapter->current_op);
318 return;
319 }
320 adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
321 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400322 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000323 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000324 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000325 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
326 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000327}
328
329/**
330 * i40evf_map_queues
331 * @adapter: adapter structure
332 *
333 * Request that the PF map queues to interrupt vectors. Misc causes, including
334 * admin queue, are always mapped to vector 0.
335 **/
336void i40evf_map_queues(struct i40evf_adapter *adapter)
337{
338 struct i40e_virtchnl_irq_map_info *vimi;
339 int v_idx, q_vectors, len;
340 struct i40e_q_vector *q_vector;
341
342 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
343 /* bail because we already have a command pending */
344 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
345 __func__, adapter->current_op);
346 return;
347 }
348 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
349
350 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
351
352 len = sizeof(struct i40e_virtchnl_irq_map_info) +
353 (adapter->num_msix_vectors *
354 sizeof(struct i40e_virtchnl_vector_map));
355 vimi = kzalloc(len, GFP_ATOMIC);
Mitch Williams249c8b82014-05-10 04:49:04 +0000356 if (!vimi)
Greg Rose62683ab2013-12-21 06:13:01 +0000357 return;
Greg Rose62683ab2013-12-21 06:13:01 +0000358
359 vimi->num_vectors = adapter->num_msix_vectors;
360 /* Queue vectors first */
361 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
362 q_vector = adapter->q_vector[v_idx];
363 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
364 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
365 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
366 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
367 }
368 /* Misc vector last - this is only for AdminQ messages */
369 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
370 vimi->vecmap[v_idx].vector_id = 0;
371 vimi->vecmap[v_idx].txq_map = 0;
372 vimi->vecmap[v_idx].rxq_map = 0;
373
Mitch Williamsfc86a972014-06-04 20:41:38 +0000374 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
Greg Rose62683ab2013-12-21 06:13:01 +0000375 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
376 (u8 *)vimi, len);
377 kfree(vimi);
Greg Rose62683ab2013-12-21 06:13:01 +0000378}
379
380/**
381 * i40evf_add_ether_addrs
382 * @adapter: adapter structure
383 * @addrs: the MAC address filters to add (contiguous)
384 * @count: number of filters
385 *
386 * Request that the PF add one or more addresses to our filters.
387 **/
388void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
389{
390 struct i40e_virtchnl_ether_addr_list *veal;
391 int len, i = 0, count = 0;
392 struct i40evf_mac_filter *f;
393
394 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
395 /* bail because we already have a command pending */
396 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
397 __func__, adapter->current_op);
398 return;
399 }
400 list_for_each_entry(f, &adapter->mac_filter_list, list) {
401 if (f->add)
402 count++;
403 }
404 if (!count) {
405 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
406 return;
407 }
408 adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
409
410 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
411 (count * sizeof(struct i40e_virtchnl_ether_addr));
412 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Mitch Williams80e72892014-05-10 04:49:06 +0000413 dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
Mitch Williams75a64432014-11-11 20:02:42 +0000414 __func__);
Greg Rose62683ab2013-12-21 06:13:01 +0000415 count = (I40EVF_MAX_AQ_BUF_SIZE -
416 sizeof(struct i40e_virtchnl_ether_addr_list)) /
417 sizeof(struct i40e_virtchnl_ether_addr);
418 len = I40EVF_MAX_AQ_BUF_SIZE;
419 }
420
421 veal = kzalloc(len, GFP_ATOMIC);
Mitch Williams249c8b82014-05-10 04:49:04 +0000422 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000423 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000424
Greg Rose62683ab2013-12-21 06:13:01 +0000425 veal->vsi_id = adapter->vsi_res->vsi_id;
426 veal->num_elements = count;
427 list_for_each_entry(f, &adapter->mac_filter_list, list) {
428 if (f->add) {
Greg Rose9a173902014-05-22 06:32:02 +0000429 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000430 i++;
431 f->add = false;
432 }
433 }
Mitch Williamsfc86a972014-06-04 20:41:38 +0000434 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Greg Rose62683ab2013-12-21 06:13:01 +0000435 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
436 (u8 *)veal, len);
437 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000438}
439
440/**
441 * i40evf_del_ether_addrs
442 * @adapter: adapter structure
443 * @addrs: the MAC address filters to remove (contiguous)
444 * @count: number of filtes
445 *
446 * Request that the PF remove one or more addresses from our filters.
447 **/
448void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
449{
450 struct i40e_virtchnl_ether_addr_list *veal;
451 struct i40evf_mac_filter *f, *ftmp;
452 int len, i = 0, count = 0;
453
454 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
455 /* bail because we already have a command pending */
456 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
457 __func__, adapter->current_op);
458 return;
459 }
460 list_for_each_entry(f, &adapter->mac_filter_list, list) {
461 if (f->remove)
462 count++;
463 }
464 if (!count) {
465 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
466 return;
467 }
468 adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
469
470 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
471 (count * sizeof(struct i40e_virtchnl_ether_addr));
472 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Mitch Williams80e72892014-05-10 04:49:06 +0000473 dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request\n",
Mitch Williams75a64432014-11-11 20:02:42 +0000474 __func__);
Greg Rose62683ab2013-12-21 06:13:01 +0000475 count = (I40EVF_MAX_AQ_BUF_SIZE -
476 sizeof(struct i40e_virtchnl_ether_addr_list)) /
477 sizeof(struct i40e_virtchnl_ether_addr);
478 len = I40EVF_MAX_AQ_BUF_SIZE;
479 }
480 veal = kzalloc(len, GFP_ATOMIC);
Mitch Williams249c8b82014-05-10 04:49:04 +0000481 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000482 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000483
Greg Rose62683ab2013-12-21 06:13:01 +0000484 veal->vsi_id = adapter->vsi_res->vsi_id;
485 veal->num_elements = count;
486 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
487 if (f->remove) {
Greg Rose9a173902014-05-22 06:32:02 +0000488 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000489 i++;
490 list_del(&f->list);
491 kfree(f);
492 }
493 }
Mitch Williamsfc86a972014-06-04 20:41:38 +0000494 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Greg Rose62683ab2013-12-21 06:13:01 +0000495 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
496 (u8 *)veal, len);
497 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000498}
499
500/**
501 * i40evf_add_vlans
502 * @adapter: adapter structure
503 * @vlans: the VLANs to add
504 * @count: number of VLANs
505 *
506 * Request that the PF add one or more VLAN filters to our VSI.
507 **/
508void i40evf_add_vlans(struct i40evf_adapter *adapter)
509{
510 struct i40e_virtchnl_vlan_filter_list *vvfl;
511 int len, i = 0, count = 0;
512 struct i40evf_vlan_filter *f;
513
514 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
515 /* bail because we already have a command pending */
516 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
517 __func__, adapter->current_op);
518 return;
519 }
520
521 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
522 if (f->add)
523 count++;
524 }
525 if (!count) {
526 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
527 return;
528 }
529 adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
530
531 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
532 (count * sizeof(u16));
533 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Mitch Williams80e72892014-05-10 04:49:06 +0000534 dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
Mitch Williams75a64432014-11-11 20:02:42 +0000535 __func__);
Greg Rose62683ab2013-12-21 06:13:01 +0000536 count = (I40EVF_MAX_AQ_BUF_SIZE -
537 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
538 sizeof(u16);
539 len = I40EVF_MAX_AQ_BUF_SIZE;
540 }
541 vvfl = kzalloc(len, GFP_ATOMIC);
Mitch Williams249c8b82014-05-10 04:49:04 +0000542 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000543 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000544
Greg Rose62683ab2013-12-21 06:13:01 +0000545 vvfl->vsi_id = adapter->vsi_res->vsi_id;
546 vvfl->num_elements = count;
547 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
548 if (f->add) {
549 vvfl->vlan_id[i] = f->vlan;
550 i++;
551 f->add = false;
552 }
553 }
Greg Rose62683ab2013-12-21 06:13:01 +0000554 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000555 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
556 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000557}
558
559/**
560 * i40evf_del_vlans
561 * @adapter: adapter structure
562 * @vlans: the VLANs to remove
563 * @count: number of VLANs
564 *
565 * Request that the PF remove one or more VLAN filters from our VSI.
566 **/
567void i40evf_del_vlans(struct i40evf_adapter *adapter)
568{
569 struct i40e_virtchnl_vlan_filter_list *vvfl;
570 struct i40evf_vlan_filter *f, *ftmp;
571 int len, i = 0, count = 0;
572
573 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
574 /* bail because we already have a command pending */
575 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
576 __func__, adapter->current_op);
577 return;
578 }
579
580 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
581 if (f->remove)
582 count++;
583 }
584 if (!count) {
585 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
586 return;
587 }
588 adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
589
590 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
591 (count * sizeof(u16));
592 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Mitch Williams80e72892014-05-10 04:49:06 +0000593 dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request\n",
Mitch Williams75a64432014-11-11 20:02:42 +0000594 __func__);
Greg Rose62683ab2013-12-21 06:13:01 +0000595 count = (I40EVF_MAX_AQ_BUF_SIZE -
596 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
597 sizeof(u16);
598 len = I40EVF_MAX_AQ_BUF_SIZE;
599 }
600 vvfl = kzalloc(len, GFP_ATOMIC);
Mitch Williams249c8b82014-05-10 04:49:04 +0000601 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000602 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000603
Greg Rose62683ab2013-12-21 06:13:01 +0000604 vvfl->vsi_id = adapter->vsi_res->vsi_id;
605 vvfl->num_elements = count;
606 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
607 if (f->remove) {
608 vvfl->vlan_id[i] = f->vlan;
609 i++;
610 list_del(&f->list);
611 kfree(f);
612 }
613 }
Greg Rose62683ab2013-12-21 06:13:01 +0000614 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000615 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
616 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000617}
618
619/**
620 * i40evf_set_promiscuous
621 * @adapter: adapter structure
622 * @flags: bitmask to control unicast/multicast promiscuous.
623 *
624 * Request that the PF enable promiscuous mode for our VSI.
625 **/
626void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
627{
628 struct i40e_virtchnl_promisc_info vpi;
629
630 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
631 /* bail because we already have a command pending */
632 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
633 __func__, adapter->current_op);
634 return;
635 }
636 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
637 vpi.vsi_id = adapter->vsi_res->vsi_id;
638 vpi.flags = flags;
639 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
640 (u8 *)&vpi, sizeof(vpi));
641}
642
643/**
644 * i40evf_request_stats
645 * @adapter: adapter structure
646 *
647 * Request VSI statistics from PF.
648 **/
649void i40evf_request_stats(struct i40evf_adapter *adapter)
650{
651 struct i40e_virtchnl_queue_select vqs;
Mitch Williams75a64432014-11-11 20:02:42 +0000652
Greg Rose62683ab2013-12-21 06:13:01 +0000653 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
654 /* no error message, this isn't crucial */
655 return;
656 }
657 adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
658 vqs.vsi_id = adapter->vsi_res->vsi_id;
659 /* queue maps are ignored for this message - only the vsi is used */
660 if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
661 (u8 *)&vqs, sizeof(vqs)))
662 /* if the request failed, don't lock out others */
663 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
664}
Mitch Williams625777e2014-02-20 19:29:05 -0800665/**
666 * i40evf_request_reset
667 * @adapter: adapter structure
668 *
669 * Request that the PF reset this VF. No response is expected.
670 **/
671void i40evf_request_reset(struct i40evf_adapter *adapter)
672{
673 /* Don't check CURRENT_OP - this is always higher priority */
674 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
675 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
676}
Greg Rose62683ab2013-12-21 06:13:01 +0000677
678/**
679 * i40evf_virtchnl_completion
680 * @adapter: adapter structure
681 * @v_opcode: opcode sent by PF
682 * @v_retval: retval sent by PF
683 * @msg: message sent by PF
684 * @msglen: message length
685 *
686 * Asynchronous completion function for admin queue messages. Rather than busy
687 * wait, we fire off our requests and assume that no errors will be returned.
688 * This function handles the reply messages.
689 **/
690void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
691 enum i40e_virtchnl_ops v_opcode,
692 i40e_status v_retval,
693 u8 *msg, u16 msglen)
694{
695 struct net_device *netdev = adapter->netdev;
696
697 if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
698 struct i40e_virtchnl_pf_event *vpe =
699 (struct i40e_virtchnl_pf_event *)msg;
700 switch (vpe->event) {
701 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
702 adapter->link_up =
703 vpe->event_data.link_event.link_status;
704 if (adapter->link_up && !netif_carrier_ok(netdev)) {
705 dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
706 netif_carrier_on(netdev);
707 netif_tx_wake_all_queues(netdev);
708 } else if (!adapter->link_up) {
709 dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
710 netif_carrier_off(netdev);
711 netif_tx_stop_all_queues(netdev);
712 }
713 break;
714 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
Mitch Williamsef8693e2014-02-13 03:48:53 -0800715 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
716 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
717 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
718 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
719 schedule_work(&adapter->reset_task);
720 }
Greg Rose62683ab2013-12-21 06:13:01 +0000721 break;
722 default:
723 dev_err(&adapter->pdev->dev,
724 "%s: Unknown event %d from pf\n",
725 __func__, vpe->event);
726 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000727 }
728 return;
729 }
Greg Rose62683ab2013-12-21 06:13:01 +0000730 if (v_retval) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400731 dev_err(&adapter->pdev->dev, "%s: PF returned error %d (%s) to our request %d\n",
732 __func__, v_retval,
733 i40evf_stat_str(&adapter->hw, v_retval), v_opcode);
Greg Rose62683ab2013-12-21 06:13:01 +0000734 }
735 switch (v_opcode) {
736 case I40E_VIRTCHNL_OP_GET_STATS: {
737 struct i40e_eth_stats *stats =
738 (struct i40e_eth_stats *)msg;
739 adapter->net_stats.rx_packets = stats->rx_unicast +
740 stats->rx_multicast +
741 stats->rx_broadcast;
742 adapter->net_stats.tx_packets = stats->tx_unicast +
743 stats->tx_multicast +
744 stats->tx_broadcast;
745 adapter->net_stats.rx_bytes = stats->rx_bytes;
746 adapter->net_stats.tx_bytes = stats->tx_bytes;
Greg Rose62683ab2013-12-21 06:13:01 +0000747 adapter->net_stats.tx_errors = stats->tx_errors;
Shannon Nelson03da6f62014-04-23 04:50:19 +0000748 adapter->net_stats.rx_dropped = stats->rx_discards;
Greg Rose62683ab2013-12-21 06:13:01 +0000749 adapter->net_stats.tx_dropped = stats->tx_discards;
750 adapter->current_stats = *stats;
751 }
752 break;
Mitch Williamse6d038d2015-06-04 16:23:58 -0400753 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: {
754 u16 len = sizeof(struct i40e_virtchnl_vf_resource) +
755 I40E_MAX_VF_VSI *
756 sizeof(struct i40e_virtchnl_vsi_resource);
757 memcpy(adapter->vf_res, msg, min(msglen, len));
758 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
759 i40evf_process_config(adapter);
760 }
761 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000762 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
Greg Rose62683ab2013-12-21 06:13:01 +0000763 /* enable transmits */
764 i40evf_irq_enable(adapter, true);
765 netif_tx_start_all_queues(adapter->netdev);
766 netif_carrier_on(adapter->netdev);
767 break;
768 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
Mitch Williamse284fc82015-03-27 00:12:09 -0700769 i40evf_free_all_tx_resources(adapter);
770 i40evf_free_all_rx_resources(adapter);
Greg Rose62683ab2013-12-21 06:13:01 +0000771 break;
Mitch Williamsed636962015-04-07 19:45:32 -0400772 case I40E_VIRTCHNL_OP_VERSION:
Greg Rose62683ab2013-12-21 06:13:01 +0000773 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
Mitch Williamsed636962015-04-07 19:45:32 -0400774 /* Don't display an error if we get these out of sequence.
775 * If the firmware needed to get kicked, we'll get these and
776 * it's no problem.
777 */
778 if (v_opcode != adapter->current_op)
779 return;
Greg Rose62683ab2013-12-21 06:13:01 +0000780 break;
781 default:
Mitch Williamsed636962015-04-07 19:45:32 -0400782 if (v_opcode != adapter->current_op)
783 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
784 adapter->current_op, v_opcode);
Greg Rose62683ab2013-12-21 06:13:01 +0000785 break;
786 } /* switch v_opcode */
787 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
788}