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