blob: 6134b61e0938525bb421037d3ef7fe37a246203f [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,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -070045 enum virtchnl_ops op, u8 *msg, u16 len)
Greg Rose62683ab2013-12-21 06:13:01 +000046{
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)
Mitch Williams905770f2017-07-14 09:27:01 -040055 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040056 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{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -070071 struct virtchnl_version_info vvi;
Greg Rose62683ab2013-12-21 06:13:01 +000072
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -070073 vvi.major = VIRTCHNL_VERSION_MAJOR;
74 vvi.minor = VIRTCHNL_VERSION_MINOR;
Greg Rose62683ab2013-12-21 06:13:01 +000075
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -070076 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
Greg Rose62683ab2013-12-21 06:13:01 +000077 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{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -070091 struct virtchnl_version_info *pf_vvi;
Greg Rose62683ab2013-12-21 06:13:01 +000092 struct i40e_hw *hw = &adapter->hw;
93 struct i40e_arq_event_info event;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -070094 enum 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 =
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700112 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
113 if (op == VIRTCHNL_OP_VERSION)
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000114 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
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700122 if (op != 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
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700129 pf_vvi = (struct virtchnl_version_info *)event.msg_buf;
Mitch Williamsee1693e2015-06-04 16:23:59 -0400130 adapter->pf_version = *pf_vvi;
131
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700132 if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) ||
133 ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) &&
134 (pf_vvi->minor > 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
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700155 caps = VIRTCHNL_VF_OFFLOAD_L2 |
156 VIRTCHNL_VF_OFFLOAD_RSS_PF |
157 VIRTCHNL_VF_OFFLOAD_RSS_AQ |
158 VIRTCHNL_VF_OFFLOAD_RSS_REG |
159 VIRTCHNL_VF_OFFLOAD_VLAN |
160 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
161 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
162 VIRTCHNL_VF_OFFLOAD_ENCAP |
Alan Brady5b36e8d2017-08-22 06:57:50 -0400163 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
Harshitha Ramamurthyd5b33d02018-01-23 08:50:57 -0800164 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
165 VIRTCHNL_VF_OFFLOAD_ADQ;
Anjali Singhai Jainb9eacec2015-11-19 11:34:22 -0800166
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700167 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
Mitch Williamse6d038d2015-06-04 16:23:58 -0400168 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
169 if (PF_IS_V11(adapter))
170 return i40evf_send_pf_msg(adapter,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700171 VIRTCHNL_OP_GET_VF_RESOURCES,
Mitch Williamse6d038d2015-06-04 16:23:58 -0400172 (u8 *)&caps, sizeof(caps));
173 else
174 return i40evf_send_pf_msg(adapter,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700175 VIRTCHNL_OP_GET_VF_RESOURCES,
Mitch Williamse6d038d2015-06-04 16:23:58 -0400176 NULL, 0);
Greg Rose62683ab2013-12-21 06:13:01 +0000177}
178
179/**
180 * i40evf_get_vf_config
181 * @hw: pointer to the hardware structure
182 * @len: length of buffer
183 *
184 * Get VF configuration from PF and populate hw structure. Must be called after
185 * admin queue is initialized. Busy waits until response is received from PF,
186 * with maximum timeout. Response from PF is returned in the buffer for further
187 * processing by the caller.
188 **/
189int i40evf_get_vf_config(struct i40evf_adapter *adapter)
190{
191 struct i40e_hw *hw = &adapter->hw;
192 struct i40e_arq_event_info event;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700193 enum virtchnl_ops op;
Greg Rose62683ab2013-12-21 06:13:01 +0000194 i40e_status err;
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000195 u16 len;
Greg Rose62683ab2013-12-21 06:13:01 +0000196
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700197 len = sizeof(struct virtchnl_vf_resource) +
198 I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
Mitch Williams1001dc32014-11-11 20:02:19 +0000199 event.buf_len = len;
200 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Greg Rose62683ab2013-12-21 06:13:01 +0000201 if (!event.msg_buf) {
202 err = -ENOMEM;
203 goto out;
204 }
205
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000206 while (1) {
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000207 /* When the AQ is empty, i40evf_clean_arq_element will return
208 * nonzero and this loop will terminate.
209 */
210 err = i40evf_clean_arq_element(hw, &event, NULL);
211 if (err)
212 goto out_alloc;
213 op =
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700214 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
215 if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000216 break;
217 }
Greg Rose62683ab2013-12-21 06:13:01 +0000218
219 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
Mitch Williams1001dc32014-11-11 20:02:19 +0000220 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
Greg Rose62683ab2013-12-21 06:13:01 +0000221
222 i40e_vf_parse_hw_config(hw, adapter->vf_res);
223out_alloc:
224 kfree(event.msg_buf);
225out:
226 return err;
227}
228
229/**
230 * i40evf_configure_queues
231 * @adapter: adapter structure
232 *
233 * Request that the PF set up our (previously allocated) queues.
234 **/
235void i40evf_configure_queues(struct i40evf_adapter *adapter)
236{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700237 struct virtchnl_vsi_queue_config_info *vqci;
238 struct virtchnl_queue_pair_info *vqpi;
Mitch Williamscc052922014-10-25 03:24:34 +0000239 int pairs = adapter->num_active_queues;
Alexander Duyckdab86af2017-03-14 10:15:27 -0700240 int i, len, max_frame = I40E_MAX_RXBUFFER;
Greg Rose62683ab2013-12-21 06:13:01 +0000241
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700242 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000243 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400244 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
245 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000246 return;
247 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700248 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
249 len = sizeof(struct virtchnl_vsi_queue_config_info) +
250 (sizeof(struct virtchnl_queue_pair_info) * pairs);
Mitch Williamsa85088d2015-11-06 15:26:04 -0800251 vqci = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000252 if (!vqci)
Greg Rose62683ab2013-12-21 06:13:01 +0000253 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000254
Alexander Duyckdab86af2017-03-14 10:15:27 -0700255 /* Limit maximum frame size when jumbo frames is not enabled */
256 if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
257 (adapter->netdev->mtu <= ETH_DATA_LEN))
258 max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
259
Greg Rose62683ab2013-12-21 06:13:01 +0000260 vqci->vsi_id = adapter->vsi_res->vsi_id;
261 vqci->num_queue_pairs = pairs;
262 vqpi = vqci->qpair;
263 /* Size check is not needed here - HW max is 16 queue pairs, and we
264 * can fit info for 31 of them into the AQ buffer before it overflows.
265 */
266 for (i = 0; i < pairs; i++) {
267 vqpi->txq.vsi_id = vqci->vsi_id;
268 vqpi->txq.queue_id = i;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400269 vqpi->txq.ring_len = adapter->tx_rings[i].count;
270 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
Greg Rose62683ab2013-12-21 06:13:01 +0000271 vqpi->rxq.vsi_id = vqci->vsi_id;
272 vqpi->rxq.queue_id = i;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400273 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
274 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
Alexander Duyckdab86af2017-03-14 10:15:27 -0700275 vqpi->rxq.max_pkt_size = max_frame;
276 vqpi->rxq.databuffer_size =
277 ALIGN(adapter->rx_rings[i].rx_buf_len,
278 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Greg Rose62683ab2013-12-21 06:13:01 +0000279 vqpi++;
280 }
281
Mitch Williamsfc86a972014-06-04 20:41:38 +0000282 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700283 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
Greg Rose62683ab2013-12-21 06:13:01 +0000284 (u8 *)vqci, len);
285 kfree(vqci);
Greg Rose62683ab2013-12-21 06:13:01 +0000286}
287
288/**
289 * i40evf_enable_queues
290 * @adapter: adapter structure
291 *
292 * Request that the PF enable all of our queues.
293 **/
294void i40evf_enable_queues(struct i40evf_adapter *adapter)
295{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700296 struct virtchnl_queue_select vqs;
Greg Rose62683ab2013-12-21 06:13:01 +0000297
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700298 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000299 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400300 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
301 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000302 return;
303 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700304 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
Greg Rose62683ab2013-12-21 06:13:01 +0000305 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400306 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000307 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000308 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700309 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
Mitch Williamsfc86a972014-06-04 20:41:38 +0000310 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000311}
312
313/**
314 * i40evf_disable_queues
315 * @adapter: adapter structure
316 *
317 * Request that the PF disable all of our queues.
318 **/
319void i40evf_disable_queues(struct i40evf_adapter *adapter)
320{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700321 struct virtchnl_queue_select vqs;
Greg Rose62683ab2013-12-21 06:13:01 +0000322
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700323 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000324 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400325 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
326 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000327 return;
328 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700329 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
Greg Rose62683ab2013-12-21 06:13:01 +0000330 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400331 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000332 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000333 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700334 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
Mitch Williamsfc86a972014-06-04 20:41:38 +0000335 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000336}
337
338/**
339 * i40evf_map_queues
340 * @adapter: adapter structure
341 *
342 * Request that the PF map queues to interrupt vectors. Misc causes, including
343 * admin queue, are always mapped to vector 0.
344 **/
345void i40evf_map_queues(struct i40evf_adapter *adapter)
346{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700347 struct virtchnl_irq_map_info *vimi;
Alexander Duyckd4942d52017-12-29 08:51:20 -0500348 struct virtchnl_vector_map *vecmap;
Greg Rose62683ab2013-12-21 06:13:01 +0000349 int v_idx, q_vectors, len;
350 struct i40e_q_vector *q_vector;
351
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700352 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000353 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400354 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
355 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000356 return;
357 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700358 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
Greg Rose62683ab2013-12-21 06:13:01 +0000359
360 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
361
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700362 len = sizeof(struct virtchnl_irq_map_info) +
Greg Rose62683ab2013-12-21 06:13:01 +0000363 (adapter->num_msix_vectors *
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700364 sizeof(struct virtchnl_vector_map));
Mitch Williamsa85088d2015-11-06 15:26:04 -0800365 vimi = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000366 if (!vimi)
Greg Rose62683ab2013-12-21 06:13:01 +0000367 return;
Greg Rose62683ab2013-12-21 06:13:01 +0000368
369 vimi->num_vectors = adapter->num_msix_vectors;
370 /* Queue vectors first */
371 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckd4942d52017-12-29 08:51:20 -0500372 q_vector = &adapter->q_vectors[v_idx];
373 vecmap = &vimi->vecmap[v_idx];
374
375 vecmap->vsi_id = adapter->vsi_res->vsi_id;
376 vecmap->vector_id = v_idx + NONQ_VECS;
377 vecmap->txq_map = q_vector->ring_mask;
378 vecmap->rxq_map = q_vector->ring_mask;
379 vecmap->rxitr_idx = I40E_RX_ITR;
380 vecmap->txitr_idx = I40E_TX_ITR;
Greg Rose62683ab2013-12-21 06:13:01 +0000381 }
382 /* Misc vector last - this is only for AdminQ messages */
Alexander Duyckd4942d52017-12-29 08:51:20 -0500383 vecmap = &vimi->vecmap[v_idx];
384 vecmap->vsi_id = adapter->vsi_res->vsi_id;
385 vecmap->vector_id = 0;
386 vecmap->txq_map = 0;
387 vecmap->rxq_map = 0;
Greg Rose62683ab2013-12-21 06:13:01 +0000388
Mitch Williamsfc86a972014-06-04 20:41:38 +0000389 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700390 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
Greg Rose62683ab2013-12-21 06:13:01 +0000391 (u8 *)vimi, len);
392 kfree(vimi);
Greg Rose62683ab2013-12-21 06:13:01 +0000393}
394
395/**
Alan Brady5b36e8d2017-08-22 06:57:50 -0400396 * i40evf_request_queues
397 * @adapter: adapter structure
398 * @num: number of requested queues
399 *
400 * We get a default number of queues from the PF. This enables us to request a
401 * different number. Returns 0 on success, negative on failure
402 **/
403int i40evf_request_queues(struct i40evf_adapter *adapter, int num)
404{
405 struct virtchnl_vf_res_request vfres;
406
407 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
408 /* bail because we already have a command pending */
409 dev_err(&adapter->pdev->dev, "Cannot request queues, command %d pending\n",
410 adapter->current_op);
411 return -EBUSY;
412 }
413
414 vfres.num_queue_pairs = num;
415
416 adapter->current_op = VIRTCHNL_OP_REQUEST_QUEUES;
Alan Brady17a94222017-10-11 14:49:43 -0700417 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
Alan Brady5b36e8d2017-08-22 06:57:50 -0400418 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_REQUEST_QUEUES,
419 (u8 *)&vfres, sizeof(vfres));
420}
421
422/**
Greg Rose62683ab2013-12-21 06:13:01 +0000423 * i40evf_add_ether_addrs
424 * @adapter: adapter structure
425 * @addrs: the MAC address filters to add (contiguous)
426 * @count: number of filters
427 *
428 * Request that the PF add one or more addresses to our filters.
429 **/
430void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
431{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700432 struct virtchnl_ether_addr_list *veal;
Greg Rose62683ab2013-12-21 06:13:01 +0000433 int len, i = 0, count = 0;
434 struct i40evf_mac_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400435 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000436
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700437 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000438 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400439 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
440 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000441 return;
442 }
Jacob Keller504398f2017-10-27 11:06:50 -0400443
444 spin_lock_bh(&adapter->mac_vlan_list_lock);
445
Greg Rose62683ab2013-12-21 06:13:01 +0000446 list_for_each_entry(f, &adapter->mac_filter_list, list) {
447 if (f->add)
448 count++;
449 }
450 if (!count) {
451 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Jacob Keller504398f2017-10-27 11:06:50 -0400452 spin_unlock_bh(&adapter->mac_vlan_list_lock);
Greg Rose62683ab2013-12-21 06:13:01 +0000453 return;
454 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700455 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
Greg Rose62683ab2013-12-21 06:13:01 +0000456
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700457 len = sizeof(struct virtchnl_ether_addr_list) +
458 (count * sizeof(struct virtchnl_ether_addr));
Greg Rose62683ab2013-12-21 06:13:01 +0000459 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400460 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000461 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700462 sizeof(struct virtchnl_ether_addr_list)) /
463 sizeof(struct virtchnl_ether_addr);
464 len = sizeof(struct virtchnl_ether_addr_list) +
465 (count * sizeof(struct virtchnl_ether_addr));
Mitch Williams1418c342015-10-21 19:47:12 -0400466 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000467 }
468
Wei Yongjun03f431b2018-01-12 02:27:13 +0000469 veal = kzalloc(len, GFP_ATOMIC);
Jacob Keller504398f2017-10-27 11:06:50 -0400470 if (!veal) {
471 spin_unlock_bh(&adapter->mac_vlan_list_lock);
Greg Rose62683ab2013-12-21 06:13:01 +0000472 return;
Jacob Keller504398f2017-10-27 11:06:50 -0400473 }
Mitch Williams249c8b82014-05-10 04:49:04 +0000474
Greg Rose62683ab2013-12-21 06:13:01 +0000475 veal->vsi_id = adapter->vsi_res->vsi_id;
476 veal->num_elements = count;
477 list_for_each_entry(f, &adapter->mac_filter_list, list) {
478 if (f->add) {
Greg Rose9a173902014-05-22 06:32:02 +0000479 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000480 i++;
481 f->add = false;
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700482 if (i == count)
483 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000484 }
485 }
Mitch Williams1418c342015-10-21 19:47:12 -0400486 if (!more)
487 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Jacob Keller504398f2017-10-27 11:06:50 -0400488
489 spin_unlock_bh(&adapter->mac_vlan_list_lock);
490
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700491 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR,
Greg Rose62683ab2013-12-21 06:13:01 +0000492 (u8 *)veal, len);
493 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000494}
495
496/**
497 * i40evf_del_ether_addrs
498 * @adapter: adapter structure
499 * @addrs: the MAC address filters to remove (contiguous)
500 * @count: number of filtes
501 *
502 * Request that the PF remove one or more addresses from our filters.
503 **/
504void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
505{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700506 struct virtchnl_ether_addr_list *veal;
Greg Rose62683ab2013-12-21 06:13:01 +0000507 struct i40evf_mac_filter *f, *ftmp;
508 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400509 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000510
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700511 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000512 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400513 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
514 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000515 return;
516 }
Jacob Keller504398f2017-10-27 11:06:50 -0400517
518 spin_lock_bh(&adapter->mac_vlan_list_lock);
519
Greg Rose62683ab2013-12-21 06:13:01 +0000520 list_for_each_entry(f, &adapter->mac_filter_list, list) {
521 if (f->remove)
522 count++;
523 }
524 if (!count) {
525 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Jacob Keller504398f2017-10-27 11:06:50 -0400526 spin_unlock_bh(&adapter->mac_vlan_list_lock);
Greg Rose62683ab2013-12-21 06:13:01 +0000527 return;
528 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700529 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
Greg Rose62683ab2013-12-21 06:13:01 +0000530
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700531 len = sizeof(struct virtchnl_ether_addr_list) +
532 (count * sizeof(struct virtchnl_ether_addr));
Greg Rose62683ab2013-12-21 06:13:01 +0000533 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400534 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000535 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700536 sizeof(struct virtchnl_ether_addr_list)) /
537 sizeof(struct virtchnl_ether_addr);
538 len = sizeof(struct virtchnl_ether_addr_list) +
539 (count * sizeof(struct virtchnl_ether_addr));
Mitch Williams1418c342015-10-21 19:47:12 -0400540 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000541 }
Wei Yongjun03f431b2018-01-12 02:27:13 +0000542 veal = kzalloc(len, GFP_ATOMIC);
Jacob Keller504398f2017-10-27 11:06:50 -0400543 if (!veal) {
544 spin_unlock_bh(&adapter->mac_vlan_list_lock);
Greg Rose62683ab2013-12-21 06:13:01 +0000545 return;
Jacob Keller504398f2017-10-27 11:06:50 -0400546 }
Mitch Williams249c8b82014-05-10 04:49:04 +0000547
Greg Rose62683ab2013-12-21 06:13:01 +0000548 veal->vsi_id = adapter->vsi_res->vsi_id;
549 veal->num_elements = count;
550 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
551 if (f->remove) {
Greg Rose9a173902014-05-22 06:32:02 +0000552 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000553 i++;
554 list_del(&f->list);
555 kfree(f);
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700556 if (i == count)
557 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000558 }
559 }
Mitch Williams1418c342015-10-21 19:47:12 -0400560 if (!more)
561 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Jacob Keller504398f2017-10-27 11:06:50 -0400562
563 spin_unlock_bh(&adapter->mac_vlan_list_lock);
564
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700565 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR,
Greg Rose62683ab2013-12-21 06:13:01 +0000566 (u8 *)veal, len);
567 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000568}
569
570/**
571 * i40evf_add_vlans
572 * @adapter: adapter structure
573 * @vlans: the VLANs to add
574 * @count: number of VLANs
575 *
576 * Request that the PF add one or more VLAN filters to our VSI.
577 **/
578void i40evf_add_vlans(struct i40evf_adapter *adapter)
579{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700580 struct virtchnl_vlan_filter_list *vvfl;
Greg Rose62683ab2013-12-21 06:13:01 +0000581 int len, i = 0, count = 0;
582 struct i40evf_vlan_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400583 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000584
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700585 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000586 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400587 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
588 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000589 return;
590 }
591
Jacob Keller504398f2017-10-27 11:06:50 -0400592 spin_lock_bh(&adapter->mac_vlan_list_lock);
593
Greg Rose62683ab2013-12-21 06:13:01 +0000594 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
595 if (f->add)
596 count++;
597 }
598 if (!count) {
599 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Jacob Keller504398f2017-10-27 11:06:50 -0400600 spin_unlock_bh(&adapter->mac_vlan_list_lock);
Greg Rose62683ab2013-12-21 06:13:01 +0000601 return;
602 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700603 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
Greg Rose62683ab2013-12-21 06:13:01 +0000604
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700605 len = sizeof(struct virtchnl_vlan_filter_list) +
Greg Rose62683ab2013-12-21 06:13:01 +0000606 (count * sizeof(u16));
607 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400608 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000609 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700610 sizeof(struct virtchnl_vlan_filter_list)) /
Greg Rose62683ab2013-12-21 06:13:01 +0000611 sizeof(u16);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700612 len = sizeof(struct virtchnl_vlan_filter_list) +
Mitch Williams1418c342015-10-21 19:47:12 -0400613 (count * sizeof(u16));
614 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000615 }
Wei Yongjun03f431b2018-01-12 02:27:13 +0000616 vvfl = kzalloc(len, GFP_ATOMIC);
Jacob Keller504398f2017-10-27 11:06:50 -0400617 if (!vvfl) {
618 spin_unlock_bh(&adapter->mac_vlan_list_lock);
Greg Rose62683ab2013-12-21 06:13:01 +0000619 return;
Jacob Keller504398f2017-10-27 11:06:50 -0400620 }
Mitch Williams249c8b82014-05-10 04:49:04 +0000621
Greg Rose62683ab2013-12-21 06:13:01 +0000622 vvfl->vsi_id = adapter->vsi_res->vsi_id;
623 vvfl->num_elements = count;
624 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
625 if (f->add) {
626 vvfl->vlan_id[i] = f->vlan;
627 i++;
628 f->add = false;
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700629 if (i == count)
630 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000631 }
632 }
Mitch Williams1418c342015-10-21 19:47:12 -0400633 if (!more)
634 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Jacob Keller504398f2017-10-27 11:06:50 -0400635
636 spin_unlock_bh(&adapter->mac_vlan_list_lock);
637
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700638 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
Mitch Williamsfc86a972014-06-04 20:41:38 +0000639 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000640}
641
642/**
643 * i40evf_del_vlans
644 * @adapter: adapter structure
645 * @vlans: the VLANs to remove
646 * @count: number of VLANs
647 *
648 * Request that the PF remove one or more VLAN filters from our VSI.
649 **/
650void i40evf_del_vlans(struct i40evf_adapter *adapter)
651{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700652 struct virtchnl_vlan_filter_list *vvfl;
Greg Rose62683ab2013-12-21 06:13:01 +0000653 struct i40evf_vlan_filter *f, *ftmp;
654 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400655 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000656
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700657 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000658 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400659 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
660 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000661 return;
662 }
663
Jacob Keller504398f2017-10-27 11:06:50 -0400664 spin_lock_bh(&adapter->mac_vlan_list_lock);
665
Greg Rose62683ab2013-12-21 06:13:01 +0000666 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
667 if (f->remove)
668 count++;
669 }
670 if (!count) {
671 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Jacob Keller504398f2017-10-27 11:06:50 -0400672 spin_unlock_bh(&adapter->mac_vlan_list_lock);
Greg Rose62683ab2013-12-21 06:13:01 +0000673 return;
674 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700675 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
Greg Rose62683ab2013-12-21 06:13:01 +0000676
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700677 len = sizeof(struct virtchnl_vlan_filter_list) +
Greg Rose62683ab2013-12-21 06:13:01 +0000678 (count * sizeof(u16));
679 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400680 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000681 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700682 sizeof(struct virtchnl_vlan_filter_list)) /
Greg Rose62683ab2013-12-21 06:13:01 +0000683 sizeof(u16);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700684 len = sizeof(struct virtchnl_vlan_filter_list) +
Mitch Williams1418c342015-10-21 19:47:12 -0400685 (count * sizeof(u16));
686 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000687 }
Wei Yongjun03f431b2018-01-12 02:27:13 +0000688 vvfl = kzalloc(len, GFP_ATOMIC);
Jacob Keller504398f2017-10-27 11:06:50 -0400689 if (!vvfl) {
690 spin_unlock_bh(&adapter->mac_vlan_list_lock);
Greg Rose62683ab2013-12-21 06:13:01 +0000691 return;
Jacob Keller504398f2017-10-27 11:06:50 -0400692 }
Mitch Williams249c8b82014-05-10 04:49:04 +0000693
Greg Rose62683ab2013-12-21 06:13:01 +0000694 vvfl->vsi_id = adapter->vsi_res->vsi_id;
695 vvfl->num_elements = count;
696 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
697 if (f->remove) {
698 vvfl->vlan_id[i] = f->vlan;
699 i++;
700 list_del(&f->list);
701 kfree(f);
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700702 if (i == count)
703 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000704 }
705 }
Mitch Williams1418c342015-10-21 19:47:12 -0400706 if (!more)
707 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Jacob Keller504398f2017-10-27 11:06:50 -0400708
709 spin_unlock_bh(&adapter->mac_vlan_list_lock);
710
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700711 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
Mitch Williamsfc86a972014-06-04 20:41:38 +0000712 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000713}
714
715/**
716 * i40evf_set_promiscuous
717 * @adapter: adapter structure
718 * @flags: bitmask to control unicast/multicast promiscuous.
719 *
720 * Request that the PF enable promiscuous mode for our VSI.
721 **/
722void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
723{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700724 struct virtchnl_promisc_info vpi;
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700725 int promisc_all;
Greg Rose62683ab2013-12-21 06:13:01 +0000726
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700727 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000728 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400729 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
730 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000731 return;
732 }
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700733
Jesse Brandeburgff3f4cc2017-05-11 11:23:16 -0700734 promisc_all = FLAG_VF_UNICAST_PROMISC |
735 FLAG_VF_MULTICAST_PROMISC;
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700736 if ((flags & promisc_all) == promisc_all) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700737 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
738 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
739 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700740 }
741
Jesse Brandeburgff3f4cc2017-05-11 11:23:16 -0700742 if (flags & FLAG_VF_MULTICAST_PROMISC) {
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700743 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
744 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
745 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
746 }
747
748 if (!flags) {
Alexander Duyckf23735a2017-11-14 07:00:45 -0500749 adapter->flags &= ~(I40EVF_FLAG_PROMISC_ON |
750 I40EVF_FLAG_ALLMULTI_ON);
751 adapter->aq_required &= ~(I40EVF_FLAG_AQ_RELEASE_PROMISC |
752 I40EVF_FLAG_AQ_RELEASE_ALLMULTI);
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700753 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
754 }
755
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700756 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
Greg Rose62683ab2013-12-21 06:13:01 +0000757 vpi.vsi_id = adapter->vsi_res->vsi_id;
758 vpi.flags = flags;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700759 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
Greg Rose62683ab2013-12-21 06:13:01 +0000760 (u8 *)&vpi, sizeof(vpi));
761}
762
763/**
764 * i40evf_request_stats
765 * @adapter: adapter structure
766 *
767 * Request VSI statistics from PF.
768 **/
769void i40evf_request_stats(struct i40evf_adapter *adapter)
770{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700771 struct virtchnl_queue_select vqs;
Mitch Williams75a64432014-11-11 20:02:42 +0000772
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700773 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000774 /* no error message, this isn't crucial */
775 return;
776 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700777 adapter->current_op = VIRTCHNL_OP_GET_STATS;
Greg Rose62683ab2013-12-21 06:13:01 +0000778 vqs.vsi_id = adapter->vsi_res->vsi_id;
779 /* queue maps are ignored for this message - only the vsi is used */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700780 if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS,
Greg Rose62683ab2013-12-21 06:13:01 +0000781 (u8 *)&vqs, sizeof(vqs)))
782 /* if the request failed, don't lock out others */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700783 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Greg Rose62683ab2013-12-21 06:13:01 +0000784}
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700785
786/**
787 * i40evf_get_hena
788 * @adapter: adapter structure
789 *
790 * Request hash enable capabilities from PF
791 **/
792void i40evf_get_hena(struct i40evf_adapter *adapter)
793{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700794 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700795 /* bail because we already have a command pending */
796 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
797 adapter->current_op);
798 return;
799 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700800 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700801 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700802 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700803 NULL, 0);
804}
805
806/**
807 * i40evf_set_hena
808 * @adapter: adapter structure
809 *
810 * Request the PF to set our RSS hash capabilities
811 **/
812void i40evf_set_hena(struct i40evf_adapter *adapter)
813{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700814 struct virtchnl_rss_hena vrh;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700815
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700816 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700817 /* bail because we already have a command pending */
818 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
819 adapter->current_op);
820 return;
821 }
822 vrh.hena = adapter->hena;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700823 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700824 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700825 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700826 (u8 *)&vrh, sizeof(vrh));
827}
828
829/**
830 * i40evf_set_rss_key
831 * @adapter: adapter structure
832 *
833 * Request the PF to set our RSS hash key
834 **/
835void i40evf_set_rss_key(struct i40evf_adapter *adapter)
836{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700837 struct virtchnl_rss_key *vrk;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700838 int len;
839
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700840 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700841 /* bail because we already have a command pending */
842 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
843 adapter->current_op);
844 return;
845 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700846 len = sizeof(struct virtchnl_rss_key) +
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700847 (adapter->rss_key_size * sizeof(u8)) - 1;
848 vrk = kzalloc(len, GFP_KERNEL);
849 if (!vrk)
850 return;
851 vrk->vsi_id = adapter->vsi.id;
852 vrk->key_len = adapter->rss_key_size;
853 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
854
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700855 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700856 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700857 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700858 (u8 *)vrk, len);
859 kfree(vrk);
860}
861
862/**
863 * i40evf_set_rss_lut
864 * @adapter: adapter structure
865 *
866 * Request the PF to set our RSS lookup table
867 **/
868void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
869{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700870 struct virtchnl_rss_lut *vrl;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700871 int len;
872
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700873 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700874 /* bail because we already have a command pending */
875 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
876 adapter->current_op);
877 return;
878 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700879 len = sizeof(struct virtchnl_rss_lut) +
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700880 (adapter->rss_lut_size * sizeof(u8)) - 1;
881 vrl = kzalloc(len, GFP_KERNEL);
882 if (!vrl)
883 return;
884 vrl->vsi_id = adapter->vsi.id;
885 vrl->lut_entries = adapter->rss_lut_size;
886 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700887 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700888 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700889 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700890 (u8 *)vrl, len);
891 kfree(vrl);
892}
893
Mitch Williams625777e2014-02-20 19:29:05 -0800894/**
Mariusz Stachura87743702017-07-17 22:09:45 -0700895 * i40evf_enable_vlan_stripping
896 * @adapter: adapter structure
897 *
898 * Request VLAN header stripping to be enabled
899 **/
900void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter)
901{
902 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
903 /* bail because we already have a command pending */
904 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
905 adapter->current_op);
906 return;
907 }
908 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
909 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
910 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
911 NULL, 0);
912}
913
914/**
915 * i40evf_disable_vlan_stripping
916 * @adapter: adapter structure
917 *
918 * Request VLAN header stripping to be disabled
919 **/
920void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter)
921{
922 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
923 /* bail because we already have a command pending */
924 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
925 adapter->current_op);
926 return;
927 }
928 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
929 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
930 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
931 NULL, 0);
932}
933
934/**
Mitch Williamsfe458e52016-08-04 11:37:02 -0700935 * i40evf_print_link_message - print link up or down
936 * @adapter: adapter structure
937 *
938 * Log a message telling the world of our wonderous link status
939 */
940static void i40evf_print_link_message(struct i40evf_adapter *adapter)
941{
942 struct net_device *netdev = adapter->netdev;
943 char *speed = "Unknown ";
944
945 if (!adapter->link_up) {
946 netdev_info(netdev, "NIC Link is Down\n");
947 return;
948 }
949
950 switch (adapter->link_speed) {
951 case I40E_LINK_SPEED_40GB:
952 speed = "40 G";
953 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800954 case I40E_LINK_SPEED_25GB:
955 speed = "25 G";
956 break;
Mitch Williamsfe458e52016-08-04 11:37:02 -0700957 case I40E_LINK_SPEED_20GB:
958 speed = "20 G";
959 break;
960 case I40E_LINK_SPEED_10GB:
961 speed = "10 G";
962 break;
963 case I40E_LINK_SPEED_1GB:
964 speed = "1000 M";
965 break;
966 case I40E_LINK_SPEED_100MB:
967 speed = "100 M";
968 break;
969 default:
970 break;
971 }
972
973 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
974}
975
976/**
Harshitha Ramamurthyd5b33d02018-01-23 08:50:57 -0800977 * i40evf_enable_channel
978 * @adapter: adapter structure
979 *
980 * Request that the PF enable channels as specified by
981 * the user via tc tool.
982 **/
983void i40evf_enable_channels(struct i40evf_adapter *adapter)
984{
985 struct virtchnl_tc_info *vti = NULL;
986 u16 len;
987 int i;
988
989 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
990 /* bail because we already have a command pending */
991 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
992 adapter->current_op);
993 return;
994 }
995
996 len = (adapter->num_tc * sizeof(struct virtchnl_channel_info)) +
997 sizeof(struct virtchnl_tc_info);
998
999 vti = kzalloc(len, GFP_KERNEL);
1000 if (!vti)
1001 return;
1002 vti->num_tc = adapter->num_tc;
1003 for (i = 0; i < vti->num_tc; i++) {
1004 vti->list[i].count = adapter->ch_config.ch_info[i].count;
1005 vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
Harshitha Ramamurthy591532d2018-01-23 08:51:01 -08001006 vti->list[i].pad = 0;
1007 vti->list[i].max_tx_rate =
1008 adapter->ch_config.ch_info[i].max_tx_rate;
Harshitha Ramamurthyd5b33d02018-01-23 08:50:57 -08001009 }
1010
1011 adapter->ch_config.state = __I40EVF_TC_RUNNING;
1012 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
1013 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1014 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_CHANNELS;
1015 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS,
1016 (u8 *)vti, len);
1017 kfree(vti);
1018}
1019
1020/**
1021 * i40evf_disable_channel
1022 * @adapter: adapter structure
1023 *
1024 * Request that the PF disable channels that are configured
1025 **/
1026void i40evf_disable_channels(struct i40evf_adapter *adapter)
1027{
1028 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1029 /* bail because we already have a command pending */
1030 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1031 adapter->current_op);
1032 return;
1033 }
1034
1035 adapter->ch_config.state = __I40EVF_TC_INVALID;
1036 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
1037 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1038 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_CHANNELS;
1039 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS,
1040 NULL, 0);
1041}
1042
1043/**
Harshitha Ramamurthy0075fa02018-01-23 08:51:05 -08001044 * i40evf_print_cloud_filter
1045 * @adapter: adapter structure
1046 * @f: cloud filter to print
1047 *
1048 * Print the cloud filter
1049 **/
1050static void i40evf_print_cloud_filter(struct i40evf_adapter *adapter,
1051 struct virtchnl_filter f)
1052{
1053 switch (f.flow_type) {
1054 case VIRTCHNL_TCP_V4_FLOW:
1055 dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI4 src_ip %pI4 dst_port %hu src_port %hu\n",
1056 &f.data.tcp_spec.dst_mac, &f.data.tcp_spec.src_mac,
1057 ntohs(f.data.tcp_spec.vlan_id),
1058 &f.data.tcp_spec.dst_ip[0], &f.data.tcp_spec.src_ip[0],
1059 ntohs(f.data.tcp_spec.dst_port),
1060 ntohs(f.data.tcp_spec.src_port));
1061 break;
1062 case VIRTCHNL_TCP_V6_FLOW:
1063 dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI6 src_ip %pI6 dst_port %hu src_port %hu\n",
1064 &f.data.tcp_spec.dst_mac, &f.data.tcp_spec.src_mac,
1065 ntohs(f.data.tcp_spec.vlan_id),
1066 &f.data.tcp_spec.dst_ip, &f.data.tcp_spec.src_ip,
1067 ntohs(f.data.tcp_spec.dst_port),
1068 ntohs(f.data.tcp_spec.src_port));
1069 break;
1070 }
1071}
1072
1073/**
1074 * i40evf_add_cloud_filter
1075 * @adapter: adapter structure
1076 *
1077 * Request that the PF add cloud filters as specified
1078 * by the user via tc tool.
1079 **/
1080void i40evf_add_cloud_filter(struct i40evf_adapter *adapter)
1081{
1082 struct i40evf_cloud_filter *cf;
1083 struct virtchnl_filter *f;
1084 int len = 0, count = 0;
1085
1086 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1087 /* bail because we already have a command pending */
1088 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1089 adapter->current_op);
1090 return;
1091 }
1092 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1093 if (cf->add) {
1094 count++;
1095 break;
1096 }
1097 }
1098 if (!count) {
1099 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_CLOUD_FILTER;
1100 return;
1101 }
1102 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1103
1104 len = sizeof(struct virtchnl_filter);
1105 f = kzalloc(len, GFP_KERNEL);
1106 if (!f)
1107 return;
1108
1109 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1110 if (cf->add) {
1111 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1112 cf->add = false;
1113 cf->state = __I40EVF_CF_ADD_PENDING;
1114 i40evf_send_pf_msg(adapter,
1115 VIRTCHNL_OP_ADD_CLOUD_FILTER,
1116 (u8 *)f, len);
1117 }
1118 }
1119 kfree(f);
1120}
1121
1122/**
1123 * i40evf_del_cloud_filter
1124 * @adapter: adapter structure
1125 *
1126 * Request that the PF delete cloud filters as specified
1127 * by the user via tc tool.
1128 **/
1129void i40evf_del_cloud_filter(struct i40evf_adapter *adapter)
1130{
1131 struct i40evf_cloud_filter *cf, *cftmp;
1132 struct virtchnl_filter *f;
1133 int len = 0, count = 0;
1134
1135 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1136 /* bail because we already have a command pending */
1137 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1138 adapter->current_op);
1139 return;
1140 }
1141 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1142 if (cf->del) {
1143 count++;
1144 break;
1145 }
1146 }
1147 if (!count) {
1148 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_CLOUD_FILTER;
1149 return;
1150 }
1151 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1152
1153 len = sizeof(struct virtchnl_filter);
1154 f = kzalloc(len, GFP_KERNEL);
1155 if (!f)
1156 return;
1157
1158 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1159 if (cf->del) {
1160 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1161 cf->del = false;
1162 cf->state = __I40EVF_CF_DEL_PENDING;
1163 i40evf_send_pf_msg(adapter,
1164 VIRTCHNL_OP_DEL_CLOUD_FILTER,
1165 (u8 *)f, len);
1166 }
1167 }
1168 kfree(f);
1169}
1170
1171/**
Mitch Williams625777e2014-02-20 19:29:05 -08001172 * i40evf_request_reset
1173 * @adapter: adapter structure
1174 *
1175 * Request that the PF reset this VF. No response is expected.
1176 **/
1177void i40evf_request_reset(struct i40evf_adapter *adapter)
1178{
1179 /* Don't check CURRENT_OP - this is always higher priority */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001180 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1181 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Mitch Williams625777e2014-02-20 19:29:05 -08001182}
Greg Rose62683ab2013-12-21 06:13:01 +00001183
1184/**
1185 * i40evf_virtchnl_completion
1186 * @adapter: adapter structure
1187 * @v_opcode: opcode sent by PF
1188 * @v_retval: retval sent by PF
1189 * @msg: message sent by PF
1190 * @msglen: message length
1191 *
1192 * Asynchronous completion function for admin queue messages. Rather than busy
1193 * wait, we fire off our requests and assume that no errors will be returned.
1194 * This function handles the reply messages.
1195 **/
1196void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001197 enum virtchnl_ops v_opcode,
Greg Rose62683ab2013-12-21 06:13:01 +00001198 i40e_status v_retval,
1199 u8 *msg, u16 msglen)
1200{
1201 struct net_device *netdev = adapter->netdev;
1202
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001203 if (v_opcode == VIRTCHNL_OP_EVENT) {
1204 struct virtchnl_pf_event *vpe =
1205 (struct virtchnl_pf_event *)msg;
Alan Bradye0346f92018-01-05 04:55:21 -05001206 bool link_up = vpe->event_data.link_event.link_status;
Greg Rose62683ab2013-12-21 06:13:01 +00001207 switch (vpe->event) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001208 case VIRTCHNL_EVENT_LINK_CHANGE:
Mitch Williamsfe458e52016-08-04 11:37:02 -07001209 adapter->link_speed =
1210 vpe->event_data.link_event.link_speed;
Alan Bradye0346f92018-01-05 04:55:21 -05001211
1212 /* we've already got the right link status, bail */
1213 if (adapter->link_up == link_up)
1214 break;
1215
Avinash Dayanand836ce5e2018-01-23 08:50:55 -08001216 if (link_up) {
1217 /* If we get link up message and start queues
1218 * before our queues are configured it will
1219 * trigger a TX hang. In that case, just ignore
1220 * the link status message,we'll get another one
1221 * after we enable queues and actually prepared
1222 * to send traffic.
1223 */
1224 if (adapter->state != __I40EVF_RUNNING)
1225 break;
1226
1227 /* For ADq enabled VF, we reconfigure VSIs and
1228 * re-allocate queues. Hence wait till all
1229 * queues are enabled.
1230 */
1231 if (adapter->flags &
1232 I40EVF_FLAG_QUEUES_DISABLED)
1233 break;
1234 }
Alan Bradye0346f92018-01-05 04:55:21 -05001235
1236 adapter->link_up = link_up;
1237 if (link_up) {
1238 netif_tx_start_all_queues(netdev);
1239 netif_carrier_on(netdev);
1240 } else {
1241 netif_tx_stop_all_queues(netdev);
1242 netif_carrier_off(netdev);
Greg Rose62683ab2013-12-21 06:13:01 +00001243 }
Alan Bradye0346f92018-01-05 04:55:21 -05001244 i40evf_print_link_message(adapter);
Greg Rose62683ab2013-12-21 06:13:01 +00001245 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001246 case VIRTCHNL_EVENT_RESET_IMPENDING:
Harshitha Ramamurthy693acdd2018-01-22 12:00:39 -05001247 dev_info(&adapter->pdev->dev, "Reset warning received from the PF\n");
Mitch Williamsef8693e2014-02-13 03:48:53 -08001248 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
1249 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
1250 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1251 schedule_work(&adapter->reset_task);
1252 }
Greg Rose62683ab2013-12-21 06:13:01 +00001253 break;
1254 default:
Shannon Nelsonfb43201f2015-08-26 15:14:17 -04001255 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1256 vpe->event);
Greg Rose62683ab2013-12-21 06:13:01 +00001257 break;
Greg Rose62683ab2013-12-21 06:13:01 +00001258 }
1259 return;
1260 }
Greg Rose62683ab2013-12-21 06:13:01 +00001261 if (v_retval) {
Mitch Williams8d8f2292015-10-21 19:47:11 -04001262 switch (v_opcode) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001263 case VIRTCHNL_OP_ADD_VLAN:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001264 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1265 i40evf_stat_str(&adapter->hw, v_retval));
1266 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001267 case VIRTCHNL_OP_ADD_ETH_ADDR:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001268 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1269 i40evf_stat_str(&adapter->hw, v_retval));
1270 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001271 case VIRTCHNL_OP_DEL_VLAN:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001272 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1273 i40evf_stat_str(&adapter->hw, v_retval));
1274 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001275 case VIRTCHNL_OP_DEL_ETH_ADDR:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001276 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1277 i40evf_stat_str(&adapter->hw, v_retval));
1278 break;
Harshitha Ramamurthyd5b33d02018-01-23 08:50:57 -08001279 case VIRTCHNL_OP_ENABLE_CHANNELS:
1280 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1281 i40evf_stat_str(&adapter->hw, v_retval));
1282 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
1283 adapter->ch_config.state = __I40EVF_TC_INVALID;
1284 netdev_reset_tc(netdev);
1285 netif_tx_start_all_queues(netdev);
1286 break;
1287 case VIRTCHNL_OP_DISABLE_CHANNELS:
1288 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1289 i40evf_stat_str(&adapter->hw, v_retval));
1290 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
1291 adapter->ch_config.state = __I40EVF_TC_RUNNING;
1292 netif_tx_start_all_queues(netdev);
1293 break;
Harshitha Ramamurthy0075fa02018-01-23 08:51:05 -08001294 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1295 struct i40evf_cloud_filter *cf, *cftmp;
1296
1297 list_for_each_entry_safe(cf, cftmp,
1298 &adapter->cloud_filter_list,
1299 list) {
1300 if (cf->state == __I40EVF_CF_ADD_PENDING) {
1301 cf->state = __I40EVF_CF_INVALID;
1302 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
1303 i40evf_stat_str(&adapter->hw,
1304 v_retval));
1305 i40evf_print_cloud_filter(adapter,
1306 cf->f);
1307 list_del(&cf->list);
1308 kfree(cf);
1309 adapter->num_cloud_filters--;
1310 }
1311 }
1312 }
1313 break;
1314 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1315 struct i40evf_cloud_filter *cf;
1316
1317 list_for_each_entry(cf, &adapter->cloud_filter_list,
1318 list) {
1319 if (cf->state == __I40EVF_CF_DEL_PENDING) {
1320 cf->state = __I40EVF_CF_ACTIVE;
1321 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
1322 i40evf_stat_str(&adapter->hw,
1323 v_retval));
1324 i40evf_print_cloud_filter(adapter,
1325 cf->f);
1326 }
1327 }
1328 }
1329 break;
Mitch Williams8d8f2292015-10-21 19:47:11 -04001330 default:
1331 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
1332 v_retval,
1333 i40evf_stat_str(&adapter->hw, v_retval),
1334 v_opcode);
1335 }
Greg Rose62683ab2013-12-21 06:13:01 +00001336 }
1337 switch (v_opcode) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001338 case VIRTCHNL_OP_GET_STATS: {
Greg Rose62683ab2013-12-21 06:13:01 +00001339 struct i40e_eth_stats *stats =
1340 (struct i40e_eth_stats *)msg;
Tobias Klauser4a0a3ab2017-04-06 08:46:28 +02001341 netdev->stats.rx_packets = stats->rx_unicast +
1342 stats->rx_multicast +
1343 stats->rx_broadcast;
1344 netdev->stats.tx_packets = stats->tx_unicast +
1345 stats->tx_multicast +
1346 stats->tx_broadcast;
1347 netdev->stats.rx_bytes = stats->rx_bytes;
1348 netdev->stats.tx_bytes = stats->tx_bytes;
1349 netdev->stats.tx_errors = stats->tx_errors;
1350 netdev->stats.rx_dropped = stats->rx_discards;
1351 netdev->stats.tx_dropped = stats->tx_discards;
Greg Rose62683ab2013-12-21 06:13:01 +00001352 adapter->current_stats = *stats;
1353 }
1354 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001355 case VIRTCHNL_OP_GET_VF_RESOURCES: {
1356 u16 len = sizeof(struct virtchnl_vf_resource) +
Mitch Williamse6d038d2015-06-04 16:23:58 -04001357 I40E_MAX_VF_VSI *
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001358 sizeof(struct virtchnl_vsi_resource);
Mitch Williamse6d038d2015-06-04 16:23:58 -04001359 memcpy(adapter->vf_res, msg, min(msglen, len));
1360 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
Mitch Williams8552d852015-08-31 19:54:51 -04001361 /* restore current mac address */
1362 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
Mitch Williamse6d038d2015-06-04 16:23:58 -04001363 i40evf_process_config(adapter);
1364 }
1365 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001366 case VIRTCHNL_OP_ENABLE_QUEUES:
Greg Rose62683ab2013-12-21 06:13:01 +00001367 /* enable transmits */
1368 i40evf_irq_enable(adapter, true);
Avinash Dayanand836ce5e2018-01-23 08:50:55 -08001369 adapter->flags &= ~I40EVF_FLAG_QUEUES_DISABLED;
Greg Rose62683ab2013-12-21 06:13:01 +00001370 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001371 case VIRTCHNL_OP_DISABLE_QUEUES:
Mitch Williamse284fc82015-03-27 00:12:09 -07001372 i40evf_free_all_tx_resources(adapter);
1373 i40evf_free_all_rx_resources(adapter);
Sudheer Mogilappagarife2647a2017-06-23 04:24:44 -04001374 if (adapter->state == __I40EVF_DOWN_PENDING) {
Mitch Williams209dc4d2015-12-09 15:50:27 -08001375 adapter->state = __I40EVF_DOWN;
Sudheer Mogilappagarife2647a2017-06-23 04:24:44 -04001376 wake_up(&adapter->down_waitqueue);
1377 }
Greg Rose62683ab2013-12-21 06:13:01 +00001378 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001379 case VIRTCHNL_OP_VERSION:
1380 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
Mitch Williamsed636962015-04-07 19:45:32 -04001381 /* Don't display an error if we get these out of sequence.
1382 * If the firmware needed to get kicked, we'll get these and
1383 * it's no problem.
1384 */
1385 if (v_opcode != adapter->current_op)
1386 return;
Greg Rose62683ab2013-12-21 06:13:01 +00001387 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001388 case VIRTCHNL_OP_IWARP:
Mitch Williamsed0e8942017-01-24 10:23:59 -08001389 /* Gobble zero-length replies from the PF. They indicate that
1390 * a previous message was received OK, and the client doesn't
1391 * care about that.
1392 */
1393 if (msglen && CLIENT_ENABLED(adapter))
1394 i40evf_notify_client_message(&adapter->vsi,
1395 msg, msglen);
1396 break;
1397
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001398 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
Mitch Williamse5f77f42017-02-09 23:35:18 -08001399 adapter->client_pending &=
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001400 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
Mitch Williamse5f77f42017-02-09 23:35:18 -08001401 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001402 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
Jesse Brandeburgf0adc6e2017-05-11 11:23:15 -07001403 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001404 if (msglen == sizeof(*vrh))
1405 adapter->hena = vrh->hena;
1406 else
1407 dev_warn(&adapter->pdev->dev,
1408 "Invalid message %d from PF\n", v_opcode);
1409 }
1410 break;
Alan Brady5b36e8d2017-08-22 06:57:50 -04001411 case VIRTCHNL_OP_REQUEST_QUEUES: {
1412 struct virtchnl_vf_res_request *vfres =
1413 (struct virtchnl_vf_res_request *)msg;
Alan Brady17a94222017-10-11 14:49:43 -07001414 if (vfres->num_queue_pairs != adapter->num_req_queues) {
Alan Brady5b36e8d2017-08-22 06:57:50 -04001415 dev_info(&adapter->pdev->dev,
1416 "Requested %d queues, PF can support %d\n",
1417 adapter->num_req_queues,
1418 vfres->num_queue_pairs);
1419 adapter->num_req_queues = 0;
Alan Brady17a94222017-10-11 14:49:43 -07001420 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
Alan Brady5b36e8d2017-08-22 06:57:50 -04001421 }
1422 }
1423 break;
Harshitha Ramamurthy0075fa02018-01-23 08:51:05 -08001424 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1425 struct i40evf_cloud_filter *cf;
1426
1427 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1428 if (cf->state == __I40EVF_CF_ADD_PENDING)
1429 cf->state = __I40EVF_CF_ACTIVE;
1430 }
1431 }
1432 break;
1433 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1434 struct i40evf_cloud_filter *cf, *cftmp;
1435
1436 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
1437 list) {
1438 if (cf->state == __I40EVF_CF_DEL_PENDING) {
1439 cf->state = __I40EVF_CF_INVALID;
1440 list_del(&cf->list);
1441 kfree(cf);
1442 adapter->num_cloud_filters--;
1443 }
1444 }
1445 }
1446 break;
Greg Rose62683ab2013-12-21 06:13:01 +00001447 default:
Mitch Williamsed0e8942017-01-24 10:23:59 -08001448 if (adapter->current_op && (v_opcode != adapter->current_op))
Mitch Williamsed636962015-04-07 19:45:32 -04001449 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1450 adapter->current_op, v_opcode);
Greg Rose62683ab2013-12-21 06:13:01 +00001451 break;
1452 } /* switch v_opcode */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001453 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Greg Rose62683ab2013-12-21 06:13:01 +00001454}