blob: deb2cb8dac6b2051ed99a05b11076fc561e141c0 [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"
Mitch Williamsed0e8942017-01-24 10:23:59 -080029#include "i40evf_client.h"
Greg Rose62683ab2013-12-21 06:13:01 +000030
31/* busy wait delay in msec */
32#define I40EVF_BUSY_WAIT_DELAY 10
33#define I40EVF_BUSY_WAIT_COUNT 50
34
35/**
36 * i40evf_send_pf_msg
37 * @adapter: adapter structure
38 * @op: virtual channel opcode
39 * @msg: pointer to message buffer
40 * @len: message length
41 *
42 * Send message to PF and print status if failure.
43 **/
44static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
45 enum i40e_virtchnl_ops op, u8 *msg, u16 len)
46{
47 struct i40e_hw *hw = &adapter->hw;
48 i40e_status err;
49
Mitch Williamsef8693e2014-02-13 03:48:53 -080050 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
51 return 0; /* nothing to see here, move along */
52
Greg Rose62683ab2013-12-21 06:13:01 +000053 err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
54 if (err)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040055 dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
56 op, i40evf_stat_str(hw, err),
57 i40evf_aq_str(hw, hw->aq.asq_last_status));
Greg Rose62683ab2013-12-21 06:13:01 +000058 return err;
59}
60
61/**
62 * i40evf_send_api_ver
63 * @adapter: adapter structure
64 *
65 * Send API version admin queue message to the PF. The reply is not checked
66 * in this function. Returns 0 if the message was successfully
67 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
68 **/
69int i40evf_send_api_ver(struct i40evf_adapter *adapter)
70{
71 struct i40e_virtchnl_version_info vvi;
72
73 vvi.major = I40E_VIRTCHNL_VERSION_MAJOR;
74 vvi.minor = I40E_VIRTCHNL_VERSION_MINOR;
75
76 return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi,
77 sizeof(vvi));
78}
79
80/**
81 * i40evf_verify_api_ver
82 * @adapter: adapter structure
83 *
84 * Compare API versions with the PF. Must be called after admin queue is
Mitch Williams6a8e93d2014-06-05 00:09:17 +000085 * initialized. Returns 0 if API versions match, -EIO if they do not,
86 * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
87 * from the firmware are propagated.
Greg Rose62683ab2013-12-21 06:13:01 +000088 **/
89int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
90{
91 struct i40e_virtchnl_version_info *pf_vvi;
92 struct i40e_hw *hw = &adapter->hw;
93 struct i40e_arq_event_info event;
Mitch Williamsf8d4db32014-10-25 03:24:33 +000094 enum i40e_virtchnl_ops op;
Greg Rose62683ab2013-12-21 06:13:01 +000095 i40e_status err;
96
Mitch Williams1001dc32014-11-11 20:02:19 +000097 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
98 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Greg Rose62683ab2013-12-21 06:13:01 +000099 if (!event.msg_buf) {
100 err = -ENOMEM;
101 goto out;
102 }
103
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000104 while (1) {
105 err = i40evf_clean_arq_element(hw, &event, NULL);
106 /* When the AQ is empty, i40evf_clean_arq_element will return
107 * nonzero and this loop will terminate.
108 */
109 if (err)
110 goto out_alloc;
111 op =
112 (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
113 if (op == I40E_VIRTCHNL_OP_VERSION)
114 break;
115 }
116
Greg Rose62683ab2013-12-21 06:13:01 +0000117
118 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
Mitch Williams6a8e93d2014-06-05 00:09:17 +0000119 if (err)
Greg Rose62683ab2013-12-21 06:13:01 +0000120 goto out_alloc;
Greg Rose62683ab2013-12-21 06:13:01 +0000121
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000122 if (op != I40E_VIRTCHNL_OP_VERSION) {
Mitch Williams6a8e93d2014-06-05 00:09:17 +0000123 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000124 op);
Greg Rose62683ab2013-12-21 06:13:01 +0000125 err = -EIO;
126 goto out_alloc;
127 }
128
129 pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf;
Mitch Williamsee1693e2015-06-04 16:23:59 -0400130 adapter->pf_version = *pf_vvi;
131
132 if ((pf_vvi->major > I40E_VIRTCHNL_VERSION_MAJOR) ||
133 ((pf_vvi->major == I40E_VIRTCHNL_VERSION_MAJOR) &&
134 (pf_vvi->minor > I40E_VIRTCHNL_VERSION_MINOR)))
Greg Rose62683ab2013-12-21 06:13:01 +0000135 err = -EIO;
136
137out_alloc:
138 kfree(event.msg_buf);
139out:
140 return err;
141}
142
143/**
144 * i40evf_send_vf_config_msg
145 * @adapter: adapter structure
146 *
147 * Send VF configuration request admin queue message to the PF. The reply
148 * is not checked in this function. Returns 0 if the message was
149 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
150 **/
151int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
152{
Mitch Williamse6d038d2015-06-04 16:23:58 -0400153 u32 caps;
154
155 adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
156 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
157 caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
158 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ |
159 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
Anjali Singhai Jain1f012272015-09-03 17:18:53 -0400160 I40E_VIRTCHNL_VF_OFFLOAD_VLAN |
Anjali Singhai Jainb9eacec2015-11-19 11:34:22 -0800161 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
Preethi Banalabacd75c2017-03-27 14:43:18 -0700162 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
163 I40E_VIRTCHNL_VF_OFFLOAD_ENCAP |
164 I40E_VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
Anjali Singhai Jainb9eacec2015-11-19 11:34:22 -0800165
Mitch Williamse6d038d2015-06-04 16:23:58 -0400166 adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
167 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
168 if (PF_IS_V11(adapter))
169 return i40evf_send_pf_msg(adapter,
170 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
171 (u8 *)&caps, sizeof(caps));
172 else
173 return i40evf_send_pf_msg(adapter,
174 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
175 NULL, 0);
Greg Rose62683ab2013-12-21 06:13:01 +0000176}
177
178/**
179 * i40evf_get_vf_config
180 * @hw: pointer to the hardware structure
181 * @len: length of buffer
182 *
183 * Get VF configuration from PF and populate hw structure. Must be called after
184 * admin queue is initialized. Busy waits until response is received from PF,
185 * with maximum timeout. Response from PF is returned in the buffer for further
186 * processing by the caller.
187 **/
188int i40evf_get_vf_config(struct i40evf_adapter *adapter)
189{
190 struct i40e_hw *hw = &adapter->hw;
191 struct i40e_arq_event_info event;
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000192 enum i40e_virtchnl_ops op;
Greg Rose62683ab2013-12-21 06:13:01 +0000193 i40e_status err;
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000194 u16 len;
Greg Rose62683ab2013-12-21 06:13:01 +0000195
196 len = sizeof(struct i40e_virtchnl_vf_resource) +
197 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
Mitch Williams1001dc32014-11-11 20:02:19 +0000198 event.buf_len = len;
199 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Greg Rose62683ab2013-12-21 06:13:01 +0000200 if (!event.msg_buf) {
201 err = -ENOMEM;
202 goto out;
203 }
204
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000205 while (1) {
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000206 /* When the AQ is empty, i40evf_clean_arq_element will return
207 * nonzero and this loop will terminate.
208 */
209 err = i40evf_clean_arq_element(hw, &event, NULL);
210 if (err)
211 goto out_alloc;
212 op =
213 (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
214 if (op == I40E_VIRTCHNL_OP_GET_VF_RESOURCES)
215 break;
216 }
Greg Rose62683ab2013-12-21 06:13:01 +0000217
218 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
Mitch Williams1001dc32014-11-11 20:02:19 +0000219 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
Greg Rose62683ab2013-12-21 06:13:01 +0000220
221 i40e_vf_parse_hw_config(hw, adapter->vf_res);
222out_alloc:
223 kfree(event.msg_buf);
224out:
225 return err;
226}
227
228/**
229 * i40evf_configure_queues
230 * @adapter: adapter structure
231 *
232 * Request that the PF set up our (previously allocated) queues.
233 **/
234void i40evf_configure_queues(struct i40evf_adapter *adapter)
235{
236 struct i40e_virtchnl_vsi_queue_config_info *vqci;
237 struct i40e_virtchnl_queue_pair_info *vqpi;
Mitch Williamscc052922014-10-25 03:24:34 +0000238 int pairs = adapter->num_active_queues;
Alexander Duyckdab86af2017-03-14 10:15:27 -0700239 int i, len, max_frame = I40E_MAX_RXBUFFER;
Greg Rose62683ab2013-12-21 06:13:01 +0000240
241 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
242 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400243 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
244 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000245 return;
246 }
247 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
248 len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
249 (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
Mitch Williamsa85088d2015-11-06 15:26:04 -0800250 vqci = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000251 if (!vqci)
Greg Rose62683ab2013-12-21 06:13:01 +0000252 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000253
Alexander Duyckdab86af2017-03-14 10:15:27 -0700254 /* Limit maximum frame size when jumbo frames is not enabled */
255 if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
256 (adapter->netdev->mtu <= ETH_DATA_LEN))
257 max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
258
Greg Rose62683ab2013-12-21 06:13:01 +0000259 vqci->vsi_id = adapter->vsi_res->vsi_id;
260 vqci->num_queue_pairs = pairs;
261 vqpi = vqci->qpair;
262 /* Size check is not needed here - HW max is 16 queue pairs, and we
263 * can fit info for 31 of them into the AQ buffer before it overflows.
264 */
265 for (i = 0; i < pairs; i++) {
266 vqpi->txq.vsi_id = vqci->vsi_id;
267 vqpi->txq.queue_id = i;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400268 vqpi->txq.ring_len = adapter->tx_rings[i].count;
269 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
Greg Rose62683ab2013-12-21 06:13:01 +0000270 vqpi->rxq.vsi_id = vqci->vsi_id;
271 vqpi->rxq.queue_id = i;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400272 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
273 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
Alexander Duyckdab86af2017-03-14 10:15:27 -0700274 vqpi->rxq.max_pkt_size = max_frame;
275 vqpi->rxq.databuffer_size =
276 ALIGN(adapter->rx_rings[i].rx_buf_len,
277 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Greg Rose62683ab2013-12-21 06:13:01 +0000278 vqpi++;
279 }
280
Mitch Williamsfc86a972014-06-04 20:41:38 +0000281 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
Greg Rose62683ab2013-12-21 06:13:01 +0000282 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
283 (u8 *)vqci, len);
284 kfree(vqci);
Greg Rose62683ab2013-12-21 06:13:01 +0000285}
286
287/**
288 * i40evf_enable_queues
289 * @adapter: adapter structure
290 *
291 * Request that the PF enable all of our queues.
292 **/
293void i40evf_enable_queues(struct i40evf_adapter *adapter)
294{
295 struct i40e_virtchnl_queue_select vqs;
296
297 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
298 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400299 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
300 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000301 return;
302 }
303 adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
304 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400305 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000306 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000307 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000308 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
309 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000310}
311
312/**
313 * i40evf_disable_queues
314 * @adapter: adapter structure
315 *
316 * Request that the PF disable all of our queues.
317 **/
318void i40evf_disable_queues(struct i40evf_adapter *adapter)
319{
320 struct i40e_virtchnl_queue_select vqs;
321
322 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
323 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400324 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
325 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000326 return;
327 }
328 adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
329 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400330 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000331 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000332 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000333 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
334 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000335}
336
337/**
338 * i40evf_map_queues
339 * @adapter: adapter structure
340 *
341 * Request that the PF map queues to interrupt vectors. Misc causes, including
342 * admin queue, are always mapped to vector 0.
343 **/
344void i40evf_map_queues(struct i40evf_adapter *adapter)
345{
346 struct i40e_virtchnl_irq_map_info *vimi;
347 int v_idx, q_vectors, len;
348 struct i40e_q_vector *q_vector;
349
350 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
351 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400352 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
353 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000354 return;
355 }
356 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
357
358 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
359
360 len = sizeof(struct i40e_virtchnl_irq_map_info) +
361 (adapter->num_msix_vectors *
362 sizeof(struct i40e_virtchnl_vector_map));
Mitch Williamsa85088d2015-11-06 15:26:04 -0800363 vimi = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000364 if (!vimi)
Greg Rose62683ab2013-12-21 06:13:01 +0000365 return;
Greg Rose62683ab2013-12-21 06:13:01 +0000366
367 vimi->num_vectors = adapter->num_msix_vectors;
368 /* Queue vectors first */
369 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -0400370 q_vector = adapter->q_vectors + v_idx;
Greg Rose62683ab2013-12-21 06:13:01 +0000371 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
372 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
373 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
374 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
375 }
376 /* Misc vector last - this is only for AdminQ messages */
377 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
378 vimi->vecmap[v_idx].vector_id = 0;
379 vimi->vecmap[v_idx].txq_map = 0;
380 vimi->vecmap[v_idx].rxq_map = 0;
381
Mitch Williamsfc86a972014-06-04 20:41:38 +0000382 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
Greg Rose62683ab2013-12-21 06:13:01 +0000383 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
384 (u8 *)vimi, len);
385 kfree(vimi);
Greg Rose62683ab2013-12-21 06:13:01 +0000386}
387
388/**
389 * i40evf_add_ether_addrs
390 * @adapter: adapter structure
391 * @addrs: the MAC address filters to add (contiguous)
392 * @count: number of filters
393 *
394 * Request that the PF add one or more addresses to our filters.
395 **/
396void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
397{
398 struct i40e_virtchnl_ether_addr_list *veal;
399 int len, i = 0, count = 0;
400 struct i40evf_mac_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400401 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000402
403 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
404 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400405 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
406 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000407 return;
408 }
409 list_for_each_entry(f, &adapter->mac_filter_list, list) {
410 if (f->add)
411 count++;
412 }
413 if (!count) {
414 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
415 return;
416 }
417 adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
418
419 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
420 (count * sizeof(struct i40e_virtchnl_ether_addr));
421 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400422 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000423 count = (I40EVF_MAX_AQ_BUF_SIZE -
424 sizeof(struct i40e_virtchnl_ether_addr_list)) /
425 sizeof(struct i40e_virtchnl_ether_addr);
Mitch Williams1418c342015-10-21 19:47:12 -0400426 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
427 (count * sizeof(struct i40e_virtchnl_ether_addr));
428 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000429 }
430
Mitch Williamsa85088d2015-11-06 15:26:04 -0800431 veal = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000432 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000433 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000434
Greg Rose62683ab2013-12-21 06:13:01 +0000435 veal->vsi_id = adapter->vsi_res->vsi_id;
436 veal->num_elements = count;
437 list_for_each_entry(f, &adapter->mac_filter_list, list) {
438 if (f->add) {
Greg Rose9a173902014-05-22 06:32:02 +0000439 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000440 i++;
441 f->add = false;
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700442 if (i == count)
443 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000444 }
445 }
Mitch Williams1418c342015-10-21 19:47:12 -0400446 if (!more)
447 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Greg Rose62683ab2013-12-21 06:13:01 +0000448 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
449 (u8 *)veal, len);
450 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000451}
452
453/**
454 * i40evf_del_ether_addrs
455 * @adapter: adapter structure
456 * @addrs: the MAC address filters to remove (contiguous)
457 * @count: number of filtes
458 *
459 * Request that the PF remove one or more addresses from our filters.
460 **/
461void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
462{
463 struct i40e_virtchnl_ether_addr_list *veal;
464 struct i40evf_mac_filter *f, *ftmp;
465 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400466 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000467
468 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
469 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400470 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
471 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000472 return;
473 }
474 list_for_each_entry(f, &adapter->mac_filter_list, list) {
475 if (f->remove)
476 count++;
477 }
478 if (!count) {
479 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
480 return;
481 }
482 adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
483
484 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
485 (count * sizeof(struct i40e_virtchnl_ether_addr));
486 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400487 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000488 count = (I40EVF_MAX_AQ_BUF_SIZE -
489 sizeof(struct i40e_virtchnl_ether_addr_list)) /
490 sizeof(struct i40e_virtchnl_ether_addr);
Mitch Williams1418c342015-10-21 19:47:12 -0400491 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
492 (count * sizeof(struct i40e_virtchnl_ether_addr));
493 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000494 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800495 veal = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000496 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000497 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000498
Greg Rose62683ab2013-12-21 06:13:01 +0000499 veal->vsi_id = adapter->vsi_res->vsi_id;
500 veal->num_elements = count;
501 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
502 if (f->remove) {
Greg Rose9a173902014-05-22 06:32:02 +0000503 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000504 i++;
505 list_del(&f->list);
506 kfree(f);
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700507 if (i == count)
508 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000509 }
510 }
Mitch Williams1418c342015-10-21 19:47:12 -0400511 if (!more)
512 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Greg Rose62683ab2013-12-21 06:13:01 +0000513 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
514 (u8 *)veal, len);
515 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000516}
517
518/**
519 * i40evf_add_vlans
520 * @adapter: adapter structure
521 * @vlans: the VLANs to add
522 * @count: number of VLANs
523 *
524 * Request that the PF add one or more VLAN filters to our VSI.
525 **/
526void i40evf_add_vlans(struct i40evf_adapter *adapter)
527{
528 struct i40e_virtchnl_vlan_filter_list *vvfl;
529 int len, i = 0, count = 0;
530 struct i40evf_vlan_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400531 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000532
533 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
534 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400535 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
536 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000537 return;
538 }
539
540 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
541 if (f->add)
542 count++;
543 }
544 if (!count) {
545 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
546 return;
547 }
548 adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
549
550 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
551 (count * sizeof(u16));
552 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400553 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000554 count = (I40EVF_MAX_AQ_BUF_SIZE -
555 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
556 sizeof(u16);
Mitch Williams1418c342015-10-21 19:47:12 -0400557 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
558 (count * sizeof(u16));
559 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000560 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800561 vvfl = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000562 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000563 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000564
Greg Rose62683ab2013-12-21 06:13:01 +0000565 vvfl->vsi_id = adapter->vsi_res->vsi_id;
566 vvfl->num_elements = count;
567 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
568 if (f->add) {
569 vvfl->vlan_id[i] = f->vlan;
570 i++;
571 f->add = false;
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700572 if (i == count)
573 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000574 }
575 }
Mitch Williams1418c342015-10-21 19:47:12 -0400576 if (!more)
577 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000578 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
579 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000580}
581
582/**
583 * i40evf_del_vlans
584 * @adapter: adapter structure
585 * @vlans: the VLANs to remove
586 * @count: number of VLANs
587 *
588 * Request that the PF remove one or more VLAN filters from our VSI.
589 **/
590void i40evf_del_vlans(struct i40evf_adapter *adapter)
591{
592 struct i40e_virtchnl_vlan_filter_list *vvfl;
593 struct i40evf_vlan_filter *f, *ftmp;
594 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400595 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000596
597 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
598 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400599 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
600 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000601 return;
602 }
603
604 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
605 if (f->remove)
606 count++;
607 }
608 if (!count) {
609 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
610 return;
611 }
612 adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
613
614 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
615 (count * sizeof(u16));
616 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400617 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000618 count = (I40EVF_MAX_AQ_BUF_SIZE -
619 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
620 sizeof(u16);
Mitch Williams1418c342015-10-21 19:47:12 -0400621 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
622 (count * sizeof(u16));
623 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000624 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800625 vvfl = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000626 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000627 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000628
Greg Rose62683ab2013-12-21 06:13:01 +0000629 vvfl->vsi_id = adapter->vsi_res->vsi_id;
630 vvfl->num_elements = count;
631 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
632 if (f->remove) {
633 vvfl->vlan_id[i] = f->vlan;
634 i++;
635 list_del(&f->list);
636 kfree(f);
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700637 if (i == count)
638 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000639 }
640 }
Mitch Williams1418c342015-10-21 19:47:12 -0400641 if (!more)
642 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Mitch Williamsfc86a972014-06-04 20:41:38 +0000643 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
644 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000645}
646
647/**
648 * i40evf_set_promiscuous
649 * @adapter: adapter structure
650 * @flags: bitmask to control unicast/multicast promiscuous.
651 *
652 * Request that the PF enable promiscuous mode for our VSI.
653 **/
654void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
655{
656 struct i40e_virtchnl_promisc_info vpi;
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700657 int promisc_all;
Greg Rose62683ab2013-12-21 06:13:01 +0000658
659 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
660 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400661 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
662 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000663 return;
664 }
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700665
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700666 promisc_all = I40E_FLAG_VF_UNICAST_PROMISC |
667 I40E_FLAG_VF_MULTICAST_PROMISC;
668 if ((flags & promisc_all) == promisc_all) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700669 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
670 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
671 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700672 }
673
674 if (flags & I40E_FLAG_VF_MULTICAST_PROMISC) {
675 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
676 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
677 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
678 }
679
680 if (!flags) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700681 adapter->flags &= ~I40EVF_FLAG_PROMISC_ON;
682 adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC;
683 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
684 }
685
Greg Rose62683ab2013-12-21 06:13:01 +0000686 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
687 vpi.vsi_id = adapter->vsi_res->vsi_id;
688 vpi.flags = flags;
689 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
690 (u8 *)&vpi, sizeof(vpi));
691}
692
693/**
694 * i40evf_request_stats
695 * @adapter: adapter structure
696 *
697 * Request VSI statistics from PF.
698 **/
699void i40evf_request_stats(struct i40evf_adapter *adapter)
700{
701 struct i40e_virtchnl_queue_select vqs;
Mitch Williams75a64432014-11-11 20:02:42 +0000702
Greg Rose62683ab2013-12-21 06:13:01 +0000703 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
704 /* no error message, this isn't crucial */
705 return;
706 }
707 adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
708 vqs.vsi_id = adapter->vsi_res->vsi_id;
709 /* queue maps are ignored for this message - only the vsi is used */
710 if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
711 (u8 *)&vqs, sizeof(vqs)))
712 /* if the request failed, don't lock out others */
713 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
714}
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700715
716/**
717 * i40evf_get_hena
718 * @adapter: adapter structure
719 *
720 * Request hash enable capabilities from PF
721 **/
722void i40evf_get_hena(struct i40evf_adapter *adapter)
723{
724 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
725 /* bail because we already have a command pending */
726 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
727 adapter->current_op);
728 return;
729 }
730 adapter->current_op = I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS;
731 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
732 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS,
733 NULL, 0);
734}
735
736/**
737 * i40evf_set_hena
738 * @adapter: adapter structure
739 *
740 * Request the PF to set our RSS hash capabilities
741 **/
742void i40evf_set_hena(struct i40evf_adapter *adapter)
743{
744 struct i40e_virtchnl_rss_hena vrh;
745
746 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
747 /* bail because we already have a command pending */
748 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
749 adapter->current_op);
750 return;
751 }
752 vrh.hena = adapter->hena;
753 adapter->current_op = I40E_VIRTCHNL_OP_SET_RSS_HENA;
754 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
755 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_SET_RSS_HENA,
756 (u8 *)&vrh, sizeof(vrh));
757}
758
759/**
760 * i40evf_set_rss_key
761 * @adapter: adapter structure
762 *
763 * Request the PF to set our RSS hash key
764 **/
765void i40evf_set_rss_key(struct i40evf_adapter *adapter)
766{
767 struct i40e_virtchnl_rss_key *vrk;
768 int len;
769
770 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
771 /* bail because we already have a command pending */
772 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
773 adapter->current_op);
774 return;
775 }
776 len = sizeof(struct i40e_virtchnl_rss_key) +
777 (adapter->rss_key_size * sizeof(u8)) - 1;
778 vrk = kzalloc(len, GFP_KERNEL);
779 if (!vrk)
780 return;
781 vrk->vsi_id = adapter->vsi.id;
782 vrk->key_len = adapter->rss_key_size;
783 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
784
785 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_KEY;
786 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
787 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY,
788 (u8 *)vrk, len);
789 kfree(vrk);
790}
791
792/**
793 * i40evf_set_rss_lut
794 * @adapter: adapter structure
795 *
796 * Request the PF to set our RSS lookup table
797 **/
798void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
799{
800 struct i40e_virtchnl_rss_lut *vrl;
801 int len;
802
803 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
804 /* bail because we already have a command pending */
805 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
806 adapter->current_op);
807 return;
808 }
809 len = sizeof(struct i40e_virtchnl_rss_lut) +
810 (adapter->rss_lut_size * sizeof(u8)) - 1;
811 vrl = kzalloc(len, GFP_KERNEL);
812 if (!vrl)
813 return;
814 vrl->vsi_id = adapter->vsi.id;
815 vrl->lut_entries = adapter->rss_lut_size;
816 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
817 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_LUT;
818 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
819 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT,
820 (u8 *)vrl, len);
821 kfree(vrl);
822}
823
Mitch Williams625777e2014-02-20 19:29:05 -0800824/**
Mitch Williamsfe458e52016-08-04 11:37:02 -0700825 * i40evf_print_link_message - print link up or down
826 * @adapter: adapter structure
827 *
828 * Log a message telling the world of our wonderous link status
829 */
830static void i40evf_print_link_message(struct i40evf_adapter *adapter)
831{
832 struct net_device *netdev = adapter->netdev;
833 char *speed = "Unknown ";
834
835 if (!adapter->link_up) {
836 netdev_info(netdev, "NIC Link is Down\n");
837 return;
838 }
839
840 switch (adapter->link_speed) {
841 case I40E_LINK_SPEED_40GB:
842 speed = "40 G";
843 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800844 case I40E_LINK_SPEED_25GB:
845 speed = "25 G";
846 break;
Mitch Williamsfe458e52016-08-04 11:37:02 -0700847 case I40E_LINK_SPEED_20GB:
848 speed = "20 G";
849 break;
850 case I40E_LINK_SPEED_10GB:
851 speed = "10 G";
852 break;
853 case I40E_LINK_SPEED_1GB:
854 speed = "1000 M";
855 break;
856 case I40E_LINK_SPEED_100MB:
857 speed = "100 M";
858 break;
859 default:
860 break;
861 }
862
863 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
864}
865
866/**
Mitch Williams625777e2014-02-20 19:29:05 -0800867 * i40evf_request_reset
868 * @adapter: adapter structure
869 *
870 * Request that the PF reset this VF. No response is expected.
871 **/
872void i40evf_request_reset(struct i40evf_adapter *adapter)
873{
874 /* Don't check CURRENT_OP - this is always higher priority */
875 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
876 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
877}
Greg Rose62683ab2013-12-21 06:13:01 +0000878
879/**
880 * i40evf_virtchnl_completion
881 * @adapter: adapter structure
882 * @v_opcode: opcode sent by PF
883 * @v_retval: retval sent by PF
884 * @msg: message sent by PF
885 * @msglen: message length
886 *
887 * Asynchronous completion function for admin queue messages. Rather than busy
888 * wait, we fire off our requests and assume that no errors will be returned.
889 * This function handles the reply messages.
890 **/
891void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
892 enum i40e_virtchnl_ops v_opcode,
893 i40e_status v_retval,
894 u8 *msg, u16 msglen)
895{
896 struct net_device *netdev = adapter->netdev;
897
898 if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
899 struct i40e_virtchnl_pf_event *vpe =
900 (struct i40e_virtchnl_pf_event *)msg;
901 switch (vpe->event) {
902 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
Mitch Williamsfe458e52016-08-04 11:37:02 -0700903 adapter->link_speed =
904 vpe->event_data.link_event.link_speed;
905 if (adapter->link_up !=
906 vpe->event_data.link_event.link_status) {
907 adapter->link_up =
908 vpe->event_data.link_event.link_status;
Sridhar Samudrala3f341ac2016-09-01 22:27:27 +0200909 if (adapter->link_up) {
910 netif_tx_start_all_queues(netdev);
911 netif_carrier_on(netdev);
912 } else {
913 netif_tx_stop_all_queues(netdev);
914 netif_carrier_off(netdev);
915 }
Mitch Williamsfe458e52016-08-04 11:37:02 -0700916 i40evf_print_link_message(adapter);
Greg Rose62683ab2013-12-21 06:13:01 +0000917 }
918 break;
919 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
Mitch Williamsef8693e2014-02-13 03:48:53 -0800920 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
921 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
922 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
923 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
924 schedule_work(&adapter->reset_task);
925 }
Greg Rose62683ab2013-12-21 06:13:01 +0000926 break;
927 default:
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400928 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
929 vpe->event);
Greg Rose62683ab2013-12-21 06:13:01 +0000930 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000931 }
932 return;
933 }
Greg Rose62683ab2013-12-21 06:13:01 +0000934 if (v_retval) {
Mitch Williams8d8f2292015-10-21 19:47:11 -0400935 switch (v_opcode) {
936 case I40E_VIRTCHNL_OP_ADD_VLAN:
937 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
938 i40evf_stat_str(&adapter->hw, v_retval));
939 break;
940 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
941 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
942 i40evf_stat_str(&adapter->hw, v_retval));
943 break;
944 case I40E_VIRTCHNL_OP_DEL_VLAN:
945 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
946 i40evf_stat_str(&adapter->hw, v_retval));
947 break;
948 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
949 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
950 i40evf_stat_str(&adapter->hw, v_retval));
951 break;
952 default:
953 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
954 v_retval,
955 i40evf_stat_str(&adapter->hw, v_retval),
956 v_opcode);
957 }
Greg Rose62683ab2013-12-21 06:13:01 +0000958 }
959 switch (v_opcode) {
960 case I40E_VIRTCHNL_OP_GET_STATS: {
961 struct i40e_eth_stats *stats =
962 (struct i40e_eth_stats *)msg;
Tobias Klauser4a0a3ab2017-04-06 08:46:28 +0200963 netdev->stats.rx_packets = stats->rx_unicast +
964 stats->rx_multicast +
965 stats->rx_broadcast;
966 netdev->stats.tx_packets = stats->tx_unicast +
967 stats->tx_multicast +
968 stats->tx_broadcast;
969 netdev->stats.rx_bytes = stats->rx_bytes;
970 netdev->stats.tx_bytes = stats->tx_bytes;
971 netdev->stats.tx_errors = stats->tx_errors;
972 netdev->stats.rx_dropped = stats->rx_discards;
973 netdev->stats.tx_dropped = stats->tx_discards;
Greg Rose62683ab2013-12-21 06:13:01 +0000974 adapter->current_stats = *stats;
975 }
976 break;
Mitch Williamse6d038d2015-06-04 16:23:58 -0400977 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: {
978 u16 len = sizeof(struct i40e_virtchnl_vf_resource) +
979 I40E_MAX_VF_VSI *
980 sizeof(struct i40e_virtchnl_vsi_resource);
981 memcpy(adapter->vf_res, msg, min(msglen, len));
982 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
Mitch Williams8552d852015-08-31 19:54:51 -0400983 /* restore current mac address */
984 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
Mitch Williamse6d038d2015-06-04 16:23:58 -0400985 i40evf_process_config(adapter);
986 }
987 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000988 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
Greg Rose62683ab2013-12-21 06:13:01 +0000989 /* enable transmits */
990 i40evf_irq_enable(adapter, true);
Greg Rose62683ab2013-12-21 06:13:01 +0000991 break;
992 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
Mitch Williamse284fc82015-03-27 00:12:09 -0700993 i40evf_free_all_tx_resources(adapter);
994 i40evf_free_all_rx_resources(adapter);
Mitch Williams209dc4d2015-12-09 15:50:27 -0800995 if (adapter->state == __I40EVF_DOWN_PENDING)
996 adapter->state = __I40EVF_DOWN;
Greg Rose62683ab2013-12-21 06:13:01 +0000997 break;
Mitch Williamsed636962015-04-07 19:45:32 -0400998 case I40E_VIRTCHNL_OP_VERSION:
Greg Rose62683ab2013-12-21 06:13:01 +0000999 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
Mitch Williamsed636962015-04-07 19:45:32 -04001000 /* Don't display an error if we get these out of sequence.
1001 * If the firmware needed to get kicked, we'll get these and
1002 * it's no problem.
1003 */
1004 if (v_opcode != adapter->current_op)
1005 return;
Greg Rose62683ab2013-12-21 06:13:01 +00001006 break;
Mitch Williamsed0e8942017-01-24 10:23:59 -08001007 case I40E_VIRTCHNL_OP_IWARP:
1008 /* Gobble zero-length replies from the PF. They indicate that
1009 * a previous message was received OK, and the client doesn't
1010 * care about that.
1011 */
1012 if (msglen && CLIENT_ENABLED(adapter))
1013 i40evf_notify_client_message(&adapter->vsi,
1014 msg, msglen);
1015 break;
1016
Mitch Williamse5f77f42017-02-09 23:35:18 -08001017 case I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1018 adapter->client_pending &=
1019 ~(BIT(I40E_VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
1020 break;
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001021 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
1022 struct i40e_virtchnl_rss_hena *vrh =
1023 (struct i40e_virtchnl_rss_hena *)msg;
1024 if (msglen == sizeof(*vrh))
1025 adapter->hena = vrh->hena;
1026 else
1027 dev_warn(&adapter->pdev->dev,
1028 "Invalid message %d from PF\n", v_opcode);
1029 }
1030 break;
Greg Rose62683ab2013-12-21 06:13:01 +00001031 default:
Mitch Williamsed0e8942017-01-24 10:23:59 -08001032 if (adapter->current_op && (v_opcode != adapter->current_op))
Mitch Williamsed636962015-04-07 19:45:32 -04001033 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1034 adapter->current_op, v_opcode);
Greg Rose62683ab2013-12-21 06:13:01 +00001035 break;
1036 } /* switch v_opcode */
1037 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
1038}