Commit | Line | Data |
---|---|---|
62683ab5 GR |
1 | /******************************************************************************* |
2 | * | |
3 | * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver | |
ef8693eb | 4 | * Copyright(c) 2013 - 2014 Intel Corporation. |
62683ab5 GR |
5 | * |
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 | * | |
b831607d JB |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | * | |
62683ab5 GR |
18 | * 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 | **/ | |
43 | static 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 | ||
ef8693eb MW |
49 | if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED) |
50 | return 0; /* nothing to see here, move along */ | |
51 | ||
62683ab5 GR |
52 | err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL); |
53 | if (err) | |
54 | dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, error %d, aq status %d\n", | |
55 | op, err, hw->aq.asq_last_status); | |
56 | return err; | |
57 | } | |
58 | ||
59 | /** | |
60 | * i40evf_send_api_ver | |
61 | * @adapter: adapter structure | |
62 | * | |
63 | * Send API version admin queue message to the PF. The reply is not checked | |
64 | * in this function. Returns 0 if the message was successfully | |
65 | * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not. | |
66 | **/ | |
67 | int i40evf_send_api_ver(struct i40evf_adapter *adapter) | |
68 | { | |
69 | struct i40e_virtchnl_version_info vvi; | |
70 | ||
71 | vvi.major = I40E_VIRTCHNL_VERSION_MAJOR; | |
72 | vvi.minor = I40E_VIRTCHNL_VERSION_MINOR; | |
73 | ||
74 | return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi, | |
75 | sizeof(vvi)); | |
76 | } | |
77 | ||
78 | /** | |
79 | * i40evf_verify_api_ver | |
80 | * @adapter: adapter structure | |
81 | * | |
82 | * Compare API versions with the PF. Must be called after admin queue is | |
83 | * initialized. Returns 0 if API versions match, -EIO if | |
84 | * they do not, or I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty. | |
85 | **/ | |
86 | int i40evf_verify_api_ver(struct i40evf_adapter *adapter) | |
87 | { | |
88 | struct i40e_virtchnl_version_info *pf_vvi; | |
89 | struct i40e_hw *hw = &adapter->hw; | |
90 | struct i40e_arq_event_info event; | |
91 | i40e_status err; | |
92 | ||
93 | event.msg_size = I40EVF_MAX_AQ_BUF_SIZE; | |
94 | event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL); | |
95 | if (!event.msg_buf) { | |
96 | err = -ENOMEM; | |
97 | goto out; | |
98 | } | |
99 | ||
100 | err = i40evf_clean_arq_element(hw, &event, NULL); | |
101 | if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) | |
102 | goto out_alloc; | |
103 | ||
104 | err = (i40e_status)le32_to_cpu(event.desc.cookie_low); | |
105 | if (err) { | |
106 | err = -EIO; | |
107 | goto out_alloc; | |
108 | } | |
109 | ||
110 | if ((enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high) != | |
111 | I40E_VIRTCHNL_OP_VERSION) { | |
112 | err = -EIO; | |
113 | goto out_alloc; | |
114 | } | |
115 | ||
116 | pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf; | |
117 | if ((pf_vvi->major != I40E_VIRTCHNL_VERSION_MAJOR) || | |
118 | (pf_vvi->minor != I40E_VIRTCHNL_VERSION_MINOR)) | |
119 | err = -EIO; | |
120 | ||
121 | out_alloc: | |
122 | kfree(event.msg_buf); | |
123 | out: | |
124 | return err; | |
125 | } | |
126 | ||
127 | /** | |
128 | * i40evf_send_vf_config_msg | |
129 | * @adapter: adapter structure | |
130 | * | |
131 | * Send VF configuration request admin queue message to the PF. The reply | |
132 | * is not checked in this function. Returns 0 if the message was | |
133 | * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not. | |
134 | **/ | |
135 | int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter) | |
136 | { | |
137 | return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_VF_RESOURCES, | |
138 | NULL, 0); | |
139 | } | |
140 | ||
141 | /** | |
142 | * i40evf_get_vf_config | |
143 | * @hw: pointer to the hardware structure | |
144 | * @len: length of buffer | |
145 | * | |
146 | * Get VF configuration from PF and populate hw structure. Must be called after | |
147 | * admin queue is initialized. Busy waits until response is received from PF, | |
148 | * with maximum timeout. Response from PF is returned in the buffer for further | |
149 | * processing by the caller. | |
150 | **/ | |
151 | int i40evf_get_vf_config(struct i40evf_adapter *adapter) | |
152 | { | |
153 | struct i40e_hw *hw = &adapter->hw; | |
154 | struct i40e_arq_event_info event; | |
155 | u16 len; | |
156 | i40e_status err; | |
157 | ||
158 | len = sizeof(struct i40e_virtchnl_vf_resource) + | |
159 | I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource); | |
160 | event.msg_size = len; | |
161 | event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL); | |
162 | if (!event.msg_buf) { | |
163 | err = -ENOMEM; | |
164 | goto out; | |
165 | } | |
166 | ||
167 | err = i40evf_clean_arq_element(hw, &event, NULL); | |
168 | if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK) | |
169 | goto out_alloc; | |
170 | ||
171 | err = (i40e_status)le32_to_cpu(event.desc.cookie_low); | |
172 | if (err) { | |
173 | dev_err(&adapter->pdev->dev, | |
174 | "%s: Error returned from PF, %d, %d\n", __func__, | |
175 | le32_to_cpu(event.desc.cookie_high), | |
176 | le32_to_cpu(event.desc.cookie_low)); | |
177 | err = -EIO; | |
178 | goto out_alloc; | |
179 | } | |
180 | ||
181 | if ((enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high) != | |
182 | I40E_VIRTCHNL_OP_GET_VF_RESOURCES) { | |
183 | dev_err(&adapter->pdev->dev, | |
184 | "%s: Invalid response from PF, %d, %d\n", __func__, | |
185 | le32_to_cpu(event.desc.cookie_high), | |
186 | le32_to_cpu(event.desc.cookie_low)); | |
187 | err = -EIO; | |
188 | goto out_alloc; | |
189 | } | |
190 | memcpy(adapter->vf_res, event.msg_buf, min(event.msg_size, len)); | |
191 | ||
192 | i40e_vf_parse_hw_config(hw, adapter->vf_res); | |
193 | out_alloc: | |
194 | kfree(event.msg_buf); | |
195 | out: | |
196 | return err; | |
197 | } | |
198 | ||
199 | /** | |
200 | * i40evf_configure_queues | |
201 | * @adapter: adapter structure | |
202 | * | |
203 | * Request that the PF set up our (previously allocated) queues. | |
204 | **/ | |
205 | void i40evf_configure_queues(struct i40evf_adapter *adapter) | |
206 | { | |
207 | struct i40e_virtchnl_vsi_queue_config_info *vqci; | |
208 | struct i40e_virtchnl_queue_pair_info *vqpi; | |
209 | int pairs = adapter->vsi_res->num_queue_pairs; | |
210 | int i, len; | |
211 | ||
212 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
213 | /* bail because we already have a command pending */ | |
214 | dev_err(&adapter->pdev->dev, "%s: command %d pending\n", | |
215 | __func__, adapter->current_op); | |
216 | return; | |
217 | } | |
218 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES; | |
219 | len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) + | |
220 | (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs); | |
221 | vqci = kzalloc(len, GFP_ATOMIC); | |
249c8b8d | 222 | if (!vqci) |
62683ab5 | 223 | return; |
249c8b8d | 224 | |
62683ab5 GR |
225 | vqci->vsi_id = adapter->vsi_res->vsi_id; |
226 | vqci->num_queue_pairs = pairs; | |
227 | vqpi = vqci->qpair; | |
228 | /* Size check is not needed here - HW max is 16 queue pairs, and we | |
229 | * can fit info for 31 of them into the AQ buffer before it overflows. | |
230 | */ | |
231 | for (i = 0; i < pairs; i++) { | |
232 | vqpi->txq.vsi_id = vqci->vsi_id; | |
233 | vqpi->txq.queue_id = i; | |
234 | vqpi->txq.ring_len = adapter->tx_rings[i]->count; | |
235 | vqpi->txq.dma_ring_addr = adapter->tx_rings[i]->dma; | |
236 | ||
237 | vqpi->rxq.vsi_id = vqci->vsi_id; | |
238 | vqpi->rxq.queue_id = i; | |
239 | vqpi->rxq.ring_len = adapter->rx_rings[i]->count; | |
240 | vqpi->rxq.dma_ring_addr = adapter->rx_rings[i]->dma; | |
241 | vqpi->rxq.max_pkt_size = adapter->netdev->mtu | |
242 | + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN; | |
243 | vqpi->rxq.databuffer_size = adapter->rx_rings[i]->rx_buf_len; | |
244 | vqpi++; | |
245 | } | |
246 | ||
247 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES, | |
248 | (u8 *)vqci, len); | |
249 | kfree(vqci); | |
250 | adapter->aq_pending |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES; | |
251 | adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES; | |
252 | } | |
253 | ||
254 | /** | |
255 | * i40evf_enable_queues | |
256 | * @adapter: adapter structure | |
257 | * | |
258 | * Request that the PF enable all of our queues. | |
259 | **/ | |
260 | void i40evf_enable_queues(struct i40evf_adapter *adapter) | |
261 | { | |
262 | struct i40e_virtchnl_queue_select vqs; | |
263 | ||
264 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
265 | /* bail because we already have a command pending */ | |
266 | dev_err(&adapter->pdev->dev, "%s: command %d pending\n", | |
267 | __func__, adapter->current_op); | |
268 | return; | |
269 | } | |
270 | adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES; | |
271 | vqs.vsi_id = adapter->vsi_res->vsi_id; | |
272 | vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1; | |
273 | vqs.rx_queues = vqs.tx_queues; | |
274 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES, | |
275 | (u8 *)&vqs, sizeof(vqs)); | |
276 | adapter->aq_pending |= I40EVF_FLAG_AQ_ENABLE_QUEUES; | |
277 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES; | |
278 | } | |
279 | ||
280 | /** | |
281 | * i40evf_disable_queues | |
282 | * @adapter: adapter structure | |
283 | * | |
284 | * Request that the PF disable all of our queues. | |
285 | **/ | |
286 | void i40evf_disable_queues(struct i40evf_adapter *adapter) | |
287 | { | |
288 | struct i40e_virtchnl_queue_select vqs; | |
289 | ||
290 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
291 | /* bail because we already have a command pending */ | |
292 | dev_err(&adapter->pdev->dev, "%s: command %d pending\n", | |
293 | __func__, adapter->current_op); | |
294 | return; | |
295 | } | |
296 | adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES; | |
297 | vqs.vsi_id = adapter->vsi_res->vsi_id; | |
298 | vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1; | |
299 | vqs.rx_queues = vqs.tx_queues; | |
300 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES, | |
301 | (u8 *)&vqs, sizeof(vqs)); | |
302 | adapter->aq_pending |= I40EVF_FLAG_AQ_DISABLE_QUEUES; | |
303 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES; | |
304 | } | |
305 | ||
306 | /** | |
307 | * i40evf_map_queues | |
308 | * @adapter: adapter structure | |
309 | * | |
310 | * Request that the PF map queues to interrupt vectors. Misc causes, including | |
311 | * admin queue, are always mapped to vector 0. | |
312 | **/ | |
313 | void i40evf_map_queues(struct i40evf_adapter *adapter) | |
314 | { | |
315 | struct i40e_virtchnl_irq_map_info *vimi; | |
316 | int v_idx, q_vectors, len; | |
317 | struct i40e_q_vector *q_vector; | |
318 | ||
319 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
320 | /* bail because we already have a command pending */ | |
321 | dev_err(&adapter->pdev->dev, "%s: command %d pending\n", | |
322 | __func__, adapter->current_op); | |
323 | return; | |
324 | } | |
325 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP; | |
326 | ||
327 | q_vectors = adapter->num_msix_vectors - NONQ_VECS; | |
328 | ||
329 | len = sizeof(struct i40e_virtchnl_irq_map_info) + | |
330 | (adapter->num_msix_vectors * | |
331 | sizeof(struct i40e_virtchnl_vector_map)); | |
332 | vimi = kzalloc(len, GFP_ATOMIC); | |
249c8b8d | 333 | if (!vimi) |
62683ab5 | 334 | return; |
62683ab5 GR |
335 | |
336 | vimi->num_vectors = adapter->num_msix_vectors; | |
337 | /* Queue vectors first */ | |
338 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { | |
339 | q_vector = adapter->q_vector[v_idx]; | |
340 | vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id; | |
341 | vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS; | |
342 | vimi->vecmap[v_idx].txq_map = q_vector->ring_mask; | |
343 | vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask; | |
344 | } | |
345 | /* Misc vector last - this is only for AdminQ messages */ | |
346 | vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id; | |
347 | vimi->vecmap[v_idx].vector_id = 0; | |
348 | vimi->vecmap[v_idx].txq_map = 0; | |
349 | vimi->vecmap[v_idx].rxq_map = 0; | |
350 | ||
351 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP, | |
352 | (u8 *)vimi, len); | |
353 | kfree(vimi); | |
354 | adapter->aq_pending |= I40EVF_FLAG_AQ_MAP_VECTORS; | |
355 | adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS; | |
356 | } | |
357 | ||
358 | /** | |
359 | * i40evf_add_ether_addrs | |
360 | * @adapter: adapter structure | |
361 | * @addrs: the MAC address filters to add (contiguous) | |
362 | * @count: number of filters | |
363 | * | |
364 | * Request that the PF add one or more addresses to our filters. | |
365 | **/ | |
366 | void i40evf_add_ether_addrs(struct i40evf_adapter *adapter) | |
367 | { | |
368 | struct i40e_virtchnl_ether_addr_list *veal; | |
369 | int len, i = 0, count = 0; | |
370 | struct i40evf_mac_filter *f; | |
371 | ||
372 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
373 | /* bail because we already have a command pending */ | |
374 | dev_err(&adapter->pdev->dev, "%s: command %d pending\n", | |
375 | __func__, adapter->current_op); | |
376 | return; | |
377 | } | |
378 | list_for_each_entry(f, &adapter->mac_filter_list, list) { | |
379 | if (f->add) | |
380 | count++; | |
381 | } | |
382 | if (!count) { | |
383 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER; | |
384 | return; | |
385 | } | |
386 | adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS; | |
387 | ||
388 | len = sizeof(struct i40e_virtchnl_ether_addr_list) + | |
389 | (count * sizeof(struct i40e_virtchnl_ether_addr)); | |
390 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { | |
391 | dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request.\n", | |
392 | __func__); | |
393 | count = (I40EVF_MAX_AQ_BUF_SIZE - | |
394 | sizeof(struct i40e_virtchnl_ether_addr_list)) / | |
395 | sizeof(struct i40e_virtchnl_ether_addr); | |
396 | len = I40EVF_MAX_AQ_BUF_SIZE; | |
397 | } | |
398 | ||
399 | veal = kzalloc(len, GFP_ATOMIC); | |
249c8b8d | 400 | if (!veal) |
62683ab5 | 401 | return; |
249c8b8d | 402 | |
62683ab5 GR |
403 | veal->vsi_id = adapter->vsi_res->vsi_id; |
404 | veal->num_elements = count; | |
405 | list_for_each_entry(f, &adapter->mac_filter_list, list) { | |
406 | if (f->add) { | |
407 | memcpy(veal->list[i].addr, f->macaddr, ETH_ALEN); | |
408 | i++; | |
409 | f->add = false; | |
410 | } | |
411 | } | |
412 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS, | |
413 | (u8 *)veal, len); | |
414 | kfree(veal); | |
415 | adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_MAC_FILTER; | |
416 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER; | |
417 | ||
418 | } | |
419 | ||
420 | /** | |
421 | * i40evf_del_ether_addrs | |
422 | * @adapter: adapter structure | |
423 | * @addrs: the MAC address filters to remove (contiguous) | |
424 | * @count: number of filtes | |
425 | * | |
426 | * Request that the PF remove one or more addresses from our filters. | |
427 | **/ | |
428 | void i40evf_del_ether_addrs(struct i40evf_adapter *adapter) | |
429 | { | |
430 | struct i40e_virtchnl_ether_addr_list *veal; | |
431 | struct i40evf_mac_filter *f, *ftmp; | |
432 | int len, i = 0, count = 0; | |
433 | ||
434 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
435 | /* bail because we already have a command pending */ | |
436 | dev_err(&adapter->pdev->dev, "%s: command %d pending\n", | |
437 | __func__, adapter->current_op); | |
438 | return; | |
439 | } | |
440 | list_for_each_entry(f, &adapter->mac_filter_list, list) { | |
441 | if (f->remove) | |
442 | count++; | |
443 | } | |
444 | if (!count) { | |
445 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER; | |
446 | return; | |
447 | } | |
448 | adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS; | |
449 | ||
450 | len = sizeof(struct i40e_virtchnl_ether_addr_list) + | |
451 | (count * sizeof(struct i40e_virtchnl_ether_addr)); | |
452 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { | |
453 | dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request.\n", | |
454 | __func__); | |
455 | count = (I40EVF_MAX_AQ_BUF_SIZE - | |
456 | sizeof(struct i40e_virtchnl_ether_addr_list)) / | |
457 | sizeof(struct i40e_virtchnl_ether_addr); | |
458 | len = I40EVF_MAX_AQ_BUF_SIZE; | |
459 | } | |
460 | veal = kzalloc(len, GFP_ATOMIC); | |
249c8b8d | 461 | if (!veal) |
62683ab5 | 462 | return; |
249c8b8d | 463 | |
62683ab5 GR |
464 | veal->vsi_id = adapter->vsi_res->vsi_id; |
465 | veal->num_elements = count; | |
466 | list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) { | |
467 | if (f->remove) { | |
468 | memcpy(veal->list[i].addr, f->macaddr, ETH_ALEN); | |
469 | i++; | |
470 | list_del(&f->list); | |
471 | kfree(f); | |
472 | } | |
473 | } | |
474 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS, | |
475 | (u8 *)veal, len); | |
476 | kfree(veal); | |
477 | adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_MAC_FILTER; | |
478 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER; | |
479 | } | |
480 | ||
481 | /** | |
482 | * i40evf_add_vlans | |
483 | * @adapter: adapter structure | |
484 | * @vlans: the VLANs to add | |
485 | * @count: number of VLANs | |
486 | * | |
487 | * Request that the PF add one or more VLAN filters to our VSI. | |
488 | **/ | |
489 | void i40evf_add_vlans(struct i40evf_adapter *adapter) | |
490 | { | |
491 | struct i40e_virtchnl_vlan_filter_list *vvfl; | |
492 | int len, i = 0, count = 0; | |
493 | struct i40evf_vlan_filter *f; | |
494 | ||
495 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
496 | /* bail because we already have a command pending */ | |
497 | dev_err(&adapter->pdev->dev, "%s: command %d pending\n", | |
498 | __func__, adapter->current_op); | |
499 | return; | |
500 | } | |
501 | ||
502 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { | |
503 | if (f->add) | |
504 | count++; | |
505 | } | |
506 | if (!count) { | |
507 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER; | |
508 | return; | |
509 | } | |
510 | adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN; | |
511 | ||
512 | len = sizeof(struct i40e_virtchnl_vlan_filter_list) + | |
513 | (count * sizeof(u16)); | |
514 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { | |
515 | dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request.\n", | |
516 | __func__); | |
517 | count = (I40EVF_MAX_AQ_BUF_SIZE - | |
518 | sizeof(struct i40e_virtchnl_vlan_filter_list)) / | |
519 | sizeof(u16); | |
520 | len = I40EVF_MAX_AQ_BUF_SIZE; | |
521 | } | |
522 | vvfl = kzalloc(len, GFP_ATOMIC); | |
249c8b8d | 523 | if (!vvfl) |
62683ab5 | 524 | return; |
249c8b8d | 525 | |
62683ab5 GR |
526 | vvfl->vsi_id = adapter->vsi_res->vsi_id; |
527 | vvfl->num_elements = count; | |
528 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { | |
529 | if (f->add) { | |
530 | vvfl->vlan_id[i] = f->vlan; | |
531 | i++; | |
532 | f->add = false; | |
533 | } | |
534 | } | |
535 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len); | |
536 | kfree(vvfl); | |
537 | adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER; | |
538 | adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER; | |
539 | } | |
540 | ||
541 | /** | |
542 | * i40evf_del_vlans | |
543 | * @adapter: adapter structure | |
544 | * @vlans: the VLANs to remove | |
545 | * @count: number of VLANs | |
546 | * | |
547 | * Request that the PF remove one or more VLAN filters from our VSI. | |
548 | **/ | |
549 | void i40evf_del_vlans(struct i40evf_adapter *adapter) | |
550 | { | |
551 | struct i40e_virtchnl_vlan_filter_list *vvfl; | |
552 | struct i40evf_vlan_filter *f, *ftmp; | |
553 | int len, i = 0, count = 0; | |
554 | ||
555 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
556 | /* bail because we already have a command pending */ | |
557 | dev_err(&adapter->pdev->dev, "%s: command %d pending\n", | |
558 | __func__, adapter->current_op); | |
559 | return; | |
560 | } | |
561 | ||
562 | list_for_each_entry(f, &adapter->vlan_filter_list, list) { | |
563 | if (f->remove) | |
564 | count++; | |
565 | } | |
566 | if (!count) { | |
567 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER; | |
568 | return; | |
569 | } | |
570 | adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN; | |
571 | ||
572 | len = sizeof(struct i40e_virtchnl_vlan_filter_list) + | |
573 | (count * sizeof(u16)); | |
574 | if (len > I40EVF_MAX_AQ_BUF_SIZE) { | |
575 | dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request.\n", | |
576 | __func__); | |
577 | count = (I40EVF_MAX_AQ_BUF_SIZE - | |
578 | sizeof(struct i40e_virtchnl_vlan_filter_list)) / | |
579 | sizeof(u16); | |
580 | len = I40EVF_MAX_AQ_BUF_SIZE; | |
581 | } | |
582 | vvfl = kzalloc(len, GFP_ATOMIC); | |
249c8b8d | 583 | if (!vvfl) |
62683ab5 | 584 | return; |
249c8b8d | 585 | |
62683ab5 GR |
586 | vvfl->vsi_id = adapter->vsi_res->vsi_id; |
587 | vvfl->num_elements = count; | |
588 | list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { | |
589 | if (f->remove) { | |
590 | vvfl->vlan_id[i] = f->vlan; | |
591 | i++; | |
592 | list_del(&f->list); | |
593 | kfree(f); | |
594 | } | |
595 | } | |
596 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len); | |
597 | kfree(vvfl); | |
598 | adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER; | |
599 | adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER; | |
600 | } | |
601 | ||
602 | /** | |
603 | * i40evf_set_promiscuous | |
604 | * @adapter: adapter structure | |
605 | * @flags: bitmask to control unicast/multicast promiscuous. | |
606 | * | |
607 | * Request that the PF enable promiscuous mode for our VSI. | |
608 | **/ | |
609 | void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags) | |
610 | { | |
611 | struct i40e_virtchnl_promisc_info vpi; | |
612 | ||
613 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
614 | /* bail because we already have a command pending */ | |
615 | dev_err(&adapter->pdev->dev, "%s: command %d pending\n", | |
616 | __func__, adapter->current_op); | |
617 | return; | |
618 | } | |
619 | adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE; | |
620 | vpi.vsi_id = adapter->vsi_res->vsi_id; | |
621 | vpi.flags = flags; | |
622 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, | |
623 | (u8 *)&vpi, sizeof(vpi)); | |
624 | } | |
625 | ||
626 | /** | |
627 | * i40evf_request_stats | |
628 | * @adapter: adapter structure | |
629 | * | |
630 | * Request VSI statistics from PF. | |
631 | **/ | |
632 | void i40evf_request_stats(struct i40evf_adapter *adapter) | |
633 | { | |
634 | struct i40e_virtchnl_queue_select vqs; | |
635 | if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) { | |
636 | /* no error message, this isn't crucial */ | |
637 | return; | |
638 | } | |
639 | adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS; | |
640 | vqs.vsi_id = adapter->vsi_res->vsi_id; | |
641 | /* queue maps are ignored for this message - only the vsi is used */ | |
642 | if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS, | |
643 | (u8 *)&vqs, sizeof(vqs))) | |
644 | /* if the request failed, don't lock out others */ | |
645 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; | |
646 | } | |
625777e3 MW |
647 | /** |
648 | * i40evf_request_reset | |
649 | * @adapter: adapter structure | |
650 | * | |
651 | * Request that the PF reset this VF. No response is expected. | |
652 | **/ | |
653 | void i40evf_request_reset(struct i40evf_adapter *adapter) | |
654 | { | |
655 | /* Don't check CURRENT_OP - this is always higher priority */ | |
656 | i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0); | |
657 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; | |
658 | } | |
62683ab5 GR |
659 | |
660 | /** | |
661 | * i40evf_virtchnl_completion | |
662 | * @adapter: adapter structure | |
663 | * @v_opcode: opcode sent by PF | |
664 | * @v_retval: retval sent by PF | |
665 | * @msg: message sent by PF | |
666 | * @msglen: message length | |
667 | * | |
668 | * Asynchronous completion function for admin queue messages. Rather than busy | |
669 | * wait, we fire off our requests and assume that no errors will be returned. | |
670 | * This function handles the reply messages. | |
671 | **/ | |
672 | void i40evf_virtchnl_completion(struct i40evf_adapter *adapter, | |
673 | enum i40e_virtchnl_ops v_opcode, | |
674 | i40e_status v_retval, | |
675 | u8 *msg, u16 msglen) | |
676 | { | |
677 | struct net_device *netdev = adapter->netdev; | |
678 | ||
679 | if (v_opcode == I40E_VIRTCHNL_OP_EVENT) { | |
680 | struct i40e_virtchnl_pf_event *vpe = | |
681 | (struct i40e_virtchnl_pf_event *)msg; | |
682 | switch (vpe->event) { | |
683 | case I40E_VIRTCHNL_EVENT_LINK_CHANGE: | |
684 | adapter->link_up = | |
685 | vpe->event_data.link_event.link_status; | |
686 | if (adapter->link_up && !netif_carrier_ok(netdev)) { | |
687 | dev_info(&adapter->pdev->dev, "NIC Link is Up\n"); | |
688 | netif_carrier_on(netdev); | |
689 | netif_tx_wake_all_queues(netdev); | |
690 | } else if (!adapter->link_up) { | |
691 | dev_info(&adapter->pdev->dev, "NIC Link is Down\n"); | |
692 | netif_carrier_off(netdev); | |
693 | netif_tx_stop_all_queues(netdev); | |
694 | } | |
695 | break; | |
696 | case I40E_VIRTCHNL_EVENT_RESET_IMPENDING: | |
ef8693eb MW |
697 | dev_info(&adapter->pdev->dev, "PF reset warning received\n"); |
698 | if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) { | |
699 | adapter->flags |= I40EVF_FLAG_RESET_PENDING; | |
700 | dev_info(&adapter->pdev->dev, "Scheduling reset task\n"); | |
701 | schedule_work(&adapter->reset_task); | |
702 | } | |
62683ab5 GR |
703 | break; |
704 | default: | |
705 | dev_err(&adapter->pdev->dev, | |
706 | "%s: Unknown event %d from pf\n", | |
707 | __func__, vpe->event); | |
708 | break; | |
709 | ||
710 | } | |
711 | return; | |
712 | } | |
713 | if (v_opcode != adapter->current_op) { | |
714 | dev_err(&adapter->pdev->dev, "%s: Pending op is %d, received %d.\n", | |
715 | __func__, adapter->current_op, v_opcode); | |
716 | /* We're probably completely screwed at this point, but clear | |
717 | * the current op and try to carry on.... | |
718 | */ | |
719 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; | |
720 | return; | |
721 | } | |
722 | if (v_retval) { | |
723 | dev_err(&adapter->pdev->dev, "%s: PF returned error %d to our request %d!\n", | |
724 | __func__, v_retval, v_opcode); | |
725 | } | |
726 | switch (v_opcode) { | |
727 | case I40E_VIRTCHNL_OP_GET_STATS: { | |
728 | struct i40e_eth_stats *stats = | |
729 | (struct i40e_eth_stats *)msg; | |
730 | adapter->net_stats.rx_packets = stats->rx_unicast + | |
731 | stats->rx_multicast + | |
732 | stats->rx_broadcast; | |
733 | adapter->net_stats.tx_packets = stats->tx_unicast + | |
734 | stats->tx_multicast + | |
735 | stats->tx_broadcast; | |
736 | adapter->net_stats.rx_bytes = stats->rx_bytes; | |
737 | adapter->net_stats.tx_bytes = stats->tx_bytes; | |
62683ab5 | 738 | adapter->net_stats.tx_errors = stats->tx_errors; |
03da6f6a | 739 | adapter->net_stats.rx_dropped = stats->rx_discards; |
62683ab5 GR |
740 | adapter->net_stats.tx_dropped = stats->tx_discards; |
741 | adapter->current_stats = *stats; | |
742 | } | |
743 | break; | |
744 | case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS: | |
745 | adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_MAC_FILTER); | |
746 | break; | |
747 | case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS: | |
748 | adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_MAC_FILTER); | |
749 | break; | |
750 | case I40E_VIRTCHNL_OP_ADD_VLAN: | |
751 | adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_VLAN_FILTER); | |
752 | break; | |
753 | case I40E_VIRTCHNL_OP_DEL_VLAN: | |
754 | adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_VLAN_FILTER); | |
755 | break; | |
756 | case I40E_VIRTCHNL_OP_ENABLE_QUEUES: | |
757 | adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ENABLE_QUEUES); | |
758 | /* enable transmits */ | |
759 | i40evf_irq_enable(adapter, true); | |
760 | netif_tx_start_all_queues(adapter->netdev); | |
761 | netif_carrier_on(adapter->netdev); | |
762 | break; | |
763 | case I40E_VIRTCHNL_OP_DISABLE_QUEUES: | |
764 | adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DISABLE_QUEUES); | |
765 | break; | |
766 | case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES: | |
767 | adapter->aq_pending &= ~(I40EVF_FLAG_AQ_CONFIGURE_QUEUES); | |
768 | break; | |
769 | case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP: | |
770 | adapter->aq_pending &= ~(I40EVF_FLAG_AQ_MAP_VECTORS); | |
771 | break; | |
772 | default: | |
773 | dev_warn(&adapter->pdev->dev, "%s: Received unexpected message %d from PF.\n", | |
774 | __func__, v_opcode); | |
775 | break; | |
776 | } /* switch v_opcode */ | |
777 | adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN; | |
778 | } |