blob: d2bb250a71afb466bff00815eee2a809133b78b9 [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)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -040055 dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
56 op, i40evf_stat_str(hw, err),
57 i40evf_aq_str(hw, hw->aq.asq_last_status));
Greg Rose62683ab2013-12-21 06:13:01 +000058 return err;
59}
60
61/**
62 * i40evf_send_api_ver
63 * @adapter: adapter structure
64 *
65 * Send API version admin queue message to the PF. The reply is not checked
66 * in this function. Returns 0 if the message was successfully
67 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
68 **/
69int i40evf_send_api_ver(struct i40evf_adapter *adapter)
70{
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 |
163 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
Anjali Singhai Jainb9eacec2015-11-19 11:34:22 -0800164
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700165 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
Mitch Williamse6d038d2015-06-04 16:23:58 -0400166 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
167 if (PF_IS_V11(adapter))
168 return i40evf_send_pf_msg(adapter,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700169 VIRTCHNL_OP_GET_VF_RESOURCES,
Mitch Williamse6d038d2015-06-04 16:23:58 -0400170 (u8 *)&caps, sizeof(caps));
171 else
172 return i40evf_send_pf_msg(adapter,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700173 VIRTCHNL_OP_GET_VF_RESOURCES,
Mitch Williamse6d038d2015-06-04 16:23:58 -0400174 NULL, 0);
Greg Rose62683ab2013-12-21 06:13:01 +0000175}
176
177/**
178 * i40evf_get_vf_config
179 * @hw: pointer to the hardware structure
180 * @len: length of buffer
181 *
182 * Get VF configuration from PF and populate hw structure. Must be called after
183 * admin queue is initialized. Busy waits until response is received from PF,
184 * with maximum timeout. Response from PF is returned in the buffer for further
185 * processing by the caller.
186 **/
187int i40evf_get_vf_config(struct i40evf_adapter *adapter)
188{
189 struct i40e_hw *hw = &adapter->hw;
190 struct i40e_arq_event_info event;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700191 enum virtchnl_ops op;
Greg Rose62683ab2013-12-21 06:13:01 +0000192 i40e_status err;
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000193 u16 len;
Greg Rose62683ab2013-12-21 06:13:01 +0000194
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700195 len = sizeof(struct virtchnl_vf_resource) +
196 I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
Mitch Williams1001dc32014-11-11 20:02:19 +0000197 event.buf_len = len;
198 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Greg Rose62683ab2013-12-21 06:13:01 +0000199 if (!event.msg_buf) {
200 err = -ENOMEM;
201 goto out;
202 }
203
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000204 while (1) {
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000205 /* When the AQ is empty, i40evf_clean_arq_element will return
206 * nonzero and this loop will terminate.
207 */
208 err = i40evf_clean_arq_element(hw, &event, NULL);
209 if (err)
210 goto out_alloc;
211 op =
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700212 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
213 if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000214 break;
215 }
Greg Rose62683ab2013-12-21 06:13:01 +0000216
217 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
Mitch Williams1001dc32014-11-11 20:02:19 +0000218 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
Greg Rose62683ab2013-12-21 06:13:01 +0000219
220 i40e_vf_parse_hw_config(hw, adapter->vf_res);
221out_alloc:
222 kfree(event.msg_buf);
223out:
224 return err;
225}
226
227/**
228 * i40evf_configure_queues
229 * @adapter: adapter structure
230 *
231 * Request that the PF set up our (previously allocated) queues.
232 **/
233void i40evf_configure_queues(struct i40evf_adapter *adapter)
234{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700235 struct virtchnl_vsi_queue_config_info *vqci;
236 struct virtchnl_queue_pair_info *vqpi;
Mitch Williamscc052922014-10-25 03:24:34 +0000237 int pairs = adapter->num_active_queues;
Alexander Duyckdab86af2017-03-14 10:15:27 -0700238 int i, len, max_frame = I40E_MAX_RXBUFFER;
Greg Rose62683ab2013-12-21 06:13:01 +0000239
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700240 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000241 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400242 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
243 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000244 return;
245 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700246 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
247 len = sizeof(struct virtchnl_vsi_queue_config_info) +
248 (sizeof(struct virtchnl_queue_pair_info) * pairs);
Mitch Williamsa85088d2015-11-06 15:26:04 -0800249 vqci = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000250 if (!vqci)
Greg Rose62683ab2013-12-21 06:13:01 +0000251 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000252
Alexander Duyckdab86af2017-03-14 10:15:27 -0700253 /* Limit maximum frame size when jumbo frames is not enabled */
254 if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
255 (adapter->netdev->mtu <= ETH_DATA_LEN))
256 max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
257
Greg Rose62683ab2013-12-21 06:13:01 +0000258 vqci->vsi_id = adapter->vsi_res->vsi_id;
259 vqci->num_queue_pairs = pairs;
260 vqpi = vqci->qpair;
261 /* Size check is not needed here - HW max is 16 queue pairs, and we
262 * can fit info for 31 of them into the AQ buffer before it overflows.
263 */
264 for (i = 0; i < pairs; i++) {
265 vqpi->txq.vsi_id = vqci->vsi_id;
266 vqpi->txq.queue_id = i;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400267 vqpi->txq.ring_len = adapter->tx_rings[i].count;
268 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
Greg Rose62683ab2013-12-21 06:13:01 +0000269 vqpi->rxq.vsi_id = vqci->vsi_id;
270 vqpi->rxq.queue_id = i;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400271 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
272 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
Alexander Duyckdab86af2017-03-14 10:15:27 -0700273 vqpi->rxq.max_pkt_size = max_frame;
274 vqpi->rxq.databuffer_size =
275 ALIGN(adapter->rx_rings[i].rx_buf_len,
276 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Greg Rose62683ab2013-12-21 06:13:01 +0000277 vqpi++;
278 }
279
Mitch Williamsfc86a972014-06-04 20:41:38 +0000280 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700281 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
Greg Rose62683ab2013-12-21 06:13:01 +0000282 (u8 *)vqci, len);
283 kfree(vqci);
Greg Rose62683ab2013-12-21 06:13:01 +0000284}
285
286/**
287 * i40evf_enable_queues
288 * @adapter: adapter structure
289 *
290 * Request that the PF enable all of our queues.
291 **/
292void i40evf_enable_queues(struct i40evf_adapter *adapter)
293{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700294 struct virtchnl_queue_select vqs;
Greg Rose62683ab2013-12-21 06:13:01 +0000295
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700296 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000297 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400298 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
299 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000300 return;
301 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700302 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
Greg Rose62683ab2013-12-21 06:13:01 +0000303 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400304 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000305 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000306 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700307 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
Mitch Williamsfc86a972014-06-04 20:41:38 +0000308 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000309}
310
311/**
312 * i40evf_disable_queues
313 * @adapter: adapter structure
314 *
315 * Request that the PF disable all of our queues.
316 **/
317void i40evf_disable_queues(struct i40evf_adapter *adapter)
318{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700319 struct virtchnl_queue_select vqs;
Greg Rose62683ab2013-12-21 06:13:01 +0000320
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700321 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000322 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400323 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
324 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000325 return;
326 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700327 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
Greg Rose62683ab2013-12-21 06:13:01 +0000328 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400329 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000330 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000331 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700332 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
Mitch Williamsfc86a972014-06-04 20:41:38 +0000333 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000334}
335
336/**
337 * i40evf_map_queues
338 * @adapter: adapter structure
339 *
340 * Request that the PF map queues to interrupt vectors. Misc causes, including
341 * admin queue, are always mapped to vector 0.
342 **/
343void i40evf_map_queues(struct i40evf_adapter *adapter)
344{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700345 struct virtchnl_irq_map_info *vimi;
Greg Rose62683ab2013-12-21 06:13:01 +0000346 int v_idx, q_vectors, len;
347 struct i40e_q_vector *q_vector;
348
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700349 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000350 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400351 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
352 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000353 return;
354 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700355 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
Greg Rose62683ab2013-12-21 06:13:01 +0000356
357 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
358
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700359 len = sizeof(struct virtchnl_irq_map_info) +
Greg Rose62683ab2013-12-21 06:13:01 +0000360 (adapter->num_msix_vectors *
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700361 sizeof(struct virtchnl_vector_map));
Mitch Williamsa85088d2015-11-06 15:26:04 -0800362 vimi = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000363 if (!vimi)
Greg Rose62683ab2013-12-21 06:13:01 +0000364 return;
Greg Rose62683ab2013-12-21 06:13:01 +0000365
366 vimi->num_vectors = adapter->num_msix_vectors;
367 /* Queue vectors first */
368 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -0400369 q_vector = adapter->q_vectors + v_idx;
Greg Rose62683ab2013-12-21 06:13:01 +0000370 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
371 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
372 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
373 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
374 }
375 /* Misc vector last - this is only for AdminQ messages */
376 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
377 vimi->vecmap[v_idx].vector_id = 0;
378 vimi->vecmap[v_idx].txq_map = 0;
379 vimi->vecmap[v_idx].rxq_map = 0;
380
Mitch Williamsfc86a972014-06-04 20:41:38 +0000381 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700382 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
Greg Rose62683ab2013-12-21 06:13:01 +0000383 (u8 *)vimi, len);
384 kfree(vimi);
Greg Rose62683ab2013-12-21 06:13:01 +0000385}
386
387/**
388 * i40evf_add_ether_addrs
389 * @adapter: adapter structure
390 * @addrs: the MAC address filters to add (contiguous)
391 * @count: number of filters
392 *
393 * Request that the PF add one or more addresses to our filters.
394 **/
395void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
396{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700397 struct virtchnl_ether_addr_list *veal;
Greg Rose62683ab2013-12-21 06:13:01 +0000398 int len, i = 0, count = 0;
399 struct i40evf_mac_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400400 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000401
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700402 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000403 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400404 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
405 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000406 return;
407 }
408 list_for_each_entry(f, &adapter->mac_filter_list, list) {
409 if (f->add)
410 count++;
411 }
412 if (!count) {
413 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
414 return;
415 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700416 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
Greg Rose62683ab2013-12-21 06:13:01 +0000417
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700418 len = sizeof(struct virtchnl_ether_addr_list) +
419 (count * sizeof(struct virtchnl_ether_addr));
Greg Rose62683ab2013-12-21 06:13:01 +0000420 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400421 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000422 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700423 sizeof(struct virtchnl_ether_addr_list)) /
424 sizeof(struct virtchnl_ether_addr);
425 len = sizeof(struct virtchnl_ether_addr_list) +
426 (count * sizeof(struct virtchnl_ether_addr));
Mitch Williams1418c342015-10-21 19:47:12 -0400427 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000428 }
429
Mitch Williamsa85088d2015-11-06 15:26:04 -0800430 veal = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000431 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000432 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000433
Greg Rose62683ab2013-12-21 06:13:01 +0000434 veal->vsi_id = adapter->vsi_res->vsi_id;
435 veal->num_elements = count;
436 list_for_each_entry(f, &adapter->mac_filter_list, list) {
437 if (f->add) {
Greg Rose9a173902014-05-22 06:32:02 +0000438 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000439 i++;
440 f->add = false;
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700441 if (i == count)
442 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000443 }
444 }
Mitch Williams1418c342015-10-21 19:47:12 -0400445 if (!more)
446 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700447 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR,
Greg Rose62683ab2013-12-21 06:13:01 +0000448 (u8 *)veal, len);
449 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000450}
451
452/**
453 * i40evf_del_ether_addrs
454 * @adapter: adapter structure
455 * @addrs: the MAC address filters to remove (contiguous)
456 * @count: number of filtes
457 *
458 * Request that the PF remove one or more addresses from our filters.
459 **/
460void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
461{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700462 struct virtchnl_ether_addr_list *veal;
Greg Rose62683ab2013-12-21 06:13:01 +0000463 struct i40evf_mac_filter *f, *ftmp;
464 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400465 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000466
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700467 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000468 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400469 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
470 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000471 return;
472 }
473 list_for_each_entry(f, &adapter->mac_filter_list, list) {
474 if (f->remove)
475 count++;
476 }
477 if (!count) {
478 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
479 return;
480 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700481 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
Greg Rose62683ab2013-12-21 06:13:01 +0000482
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700483 len = sizeof(struct virtchnl_ether_addr_list) +
484 (count * sizeof(struct virtchnl_ether_addr));
Greg Rose62683ab2013-12-21 06:13:01 +0000485 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400486 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000487 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700488 sizeof(struct virtchnl_ether_addr_list)) /
489 sizeof(struct virtchnl_ether_addr);
490 len = sizeof(struct virtchnl_ether_addr_list) +
491 (count * sizeof(struct virtchnl_ether_addr));
Mitch Williams1418c342015-10-21 19:47:12 -0400492 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000493 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800494 veal = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000495 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000496 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000497
Greg Rose62683ab2013-12-21 06:13:01 +0000498 veal->vsi_id = adapter->vsi_res->vsi_id;
499 veal->num_elements = count;
500 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
501 if (f->remove) {
Greg Rose9a173902014-05-22 06:32:02 +0000502 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000503 i++;
504 list_del(&f->list);
505 kfree(f);
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700506 if (i == count)
507 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000508 }
509 }
Mitch Williams1418c342015-10-21 19:47:12 -0400510 if (!more)
511 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700512 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR,
Greg Rose62683ab2013-12-21 06:13:01 +0000513 (u8 *)veal, len);
514 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000515}
516
517/**
518 * i40evf_add_vlans
519 * @adapter: adapter structure
520 * @vlans: the VLANs to add
521 * @count: number of VLANs
522 *
523 * Request that the PF add one or more VLAN filters to our VSI.
524 **/
525void i40evf_add_vlans(struct i40evf_adapter *adapter)
526{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700527 struct virtchnl_vlan_filter_list *vvfl;
Greg Rose62683ab2013-12-21 06:13:01 +0000528 int len, i = 0, count = 0;
529 struct i40evf_vlan_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400530 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000531
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700532 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000533 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400534 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
535 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000536 return;
537 }
538
539 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
540 if (f->add)
541 count++;
542 }
543 if (!count) {
544 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
545 return;
546 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700547 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
Greg Rose62683ab2013-12-21 06:13:01 +0000548
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700549 len = sizeof(struct virtchnl_vlan_filter_list) +
Greg Rose62683ab2013-12-21 06:13:01 +0000550 (count * sizeof(u16));
551 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400552 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000553 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700554 sizeof(struct virtchnl_vlan_filter_list)) /
Greg Rose62683ab2013-12-21 06:13:01 +0000555 sizeof(u16);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700556 len = sizeof(struct virtchnl_vlan_filter_list) +
Mitch Williams1418c342015-10-21 19:47:12 -0400557 (count * sizeof(u16));
558 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000559 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800560 vvfl = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000561 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000562 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000563
Greg Rose62683ab2013-12-21 06:13:01 +0000564 vvfl->vsi_id = adapter->vsi_res->vsi_id;
565 vvfl->num_elements = count;
566 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
567 if (f->add) {
568 vvfl->vlan_id[i] = f->vlan;
569 i++;
570 f->add = false;
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700571 if (i == count)
572 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000573 }
574 }
Mitch Williams1418c342015-10-21 19:47:12 -0400575 if (!more)
576 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700577 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
Mitch Williamsfc86a972014-06-04 20:41:38 +0000578 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000579}
580
581/**
582 * i40evf_del_vlans
583 * @adapter: adapter structure
584 * @vlans: the VLANs to remove
585 * @count: number of VLANs
586 *
587 * Request that the PF remove one or more VLAN filters from our VSI.
588 **/
589void i40evf_del_vlans(struct i40evf_adapter *adapter)
590{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700591 struct virtchnl_vlan_filter_list *vvfl;
Greg Rose62683ab2013-12-21 06:13:01 +0000592 struct i40evf_vlan_filter *f, *ftmp;
593 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400594 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000595
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700596 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000597 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400598 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
599 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000600 return;
601 }
602
603 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
604 if (f->remove)
605 count++;
606 }
607 if (!count) {
608 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
609 return;
610 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700611 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
Greg Rose62683ab2013-12-21 06:13:01 +0000612
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700613 len = sizeof(struct virtchnl_vlan_filter_list) +
Greg Rose62683ab2013-12-21 06:13:01 +0000614 (count * sizeof(u16));
615 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400616 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000617 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700618 sizeof(struct virtchnl_vlan_filter_list)) /
Greg Rose62683ab2013-12-21 06:13:01 +0000619 sizeof(u16);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700620 len = sizeof(struct virtchnl_vlan_filter_list) +
Mitch Williams1418c342015-10-21 19:47:12 -0400621 (count * sizeof(u16));
622 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000623 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800624 vvfl = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000625 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000626 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000627
Greg Rose62683ab2013-12-21 06:13:01 +0000628 vvfl->vsi_id = adapter->vsi_res->vsi_id;
629 vvfl->num_elements = count;
630 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
631 if (f->remove) {
632 vvfl->vlan_id[i] = f->vlan;
633 i++;
634 list_del(&f->list);
635 kfree(f);
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700636 if (i == count)
637 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000638 }
639 }
Mitch Williams1418c342015-10-21 19:47:12 -0400640 if (!more)
641 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700642 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
Mitch Williamsfc86a972014-06-04 20:41:38 +0000643 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000644}
645
646/**
647 * i40evf_set_promiscuous
648 * @adapter: adapter structure
649 * @flags: bitmask to control unicast/multicast promiscuous.
650 *
651 * Request that the PF enable promiscuous mode for our VSI.
652 **/
653void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
654{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700655 struct virtchnl_promisc_info vpi;
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700656 int promisc_all;
Greg Rose62683ab2013-12-21 06:13:01 +0000657
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700658 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000659 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400660 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
661 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000662 return;
663 }
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700664
Jesse Brandeburgff3f4cc2017-05-11 11:23:16 -0700665 promisc_all = FLAG_VF_UNICAST_PROMISC |
666 FLAG_VF_MULTICAST_PROMISC;
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700667 if ((flags & promisc_all) == promisc_all) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700668 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
669 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
670 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700671 }
672
Jesse Brandeburgff3f4cc2017-05-11 11:23:16 -0700673 if (flags & FLAG_VF_MULTICAST_PROMISC) {
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700674 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
675 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
676 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
677 }
678
679 if (!flags) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700680 adapter->flags &= ~I40EVF_FLAG_PROMISC_ON;
681 adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC;
682 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
683 }
684
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700685 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
Greg Rose62683ab2013-12-21 06:13:01 +0000686 vpi.vsi_id = adapter->vsi_res->vsi_id;
687 vpi.flags = flags;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700688 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
Greg Rose62683ab2013-12-21 06:13:01 +0000689 (u8 *)&vpi, sizeof(vpi));
690}
691
692/**
693 * i40evf_request_stats
694 * @adapter: adapter structure
695 *
696 * Request VSI statistics from PF.
697 **/
698void i40evf_request_stats(struct i40evf_adapter *adapter)
699{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700700 struct virtchnl_queue_select vqs;
Mitch Williams75a64432014-11-11 20:02:42 +0000701
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700702 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000703 /* no error message, this isn't crucial */
704 return;
705 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700706 adapter->current_op = VIRTCHNL_OP_GET_STATS;
Greg Rose62683ab2013-12-21 06:13:01 +0000707 vqs.vsi_id = adapter->vsi_res->vsi_id;
708 /* queue maps are ignored for this message - only the vsi is used */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700709 if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS,
Greg Rose62683ab2013-12-21 06:13:01 +0000710 (u8 *)&vqs, sizeof(vqs)))
711 /* if the request failed, don't lock out others */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700712 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Greg Rose62683ab2013-12-21 06:13:01 +0000713}
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700714
715/**
716 * i40evf_get_hena
717 * @adapter: adapter structure
718 *
719 * Request hash enable capabilities from PF
720 **/
721void i40evf_get_hena(struct i40evf_adapter *adapter)
722{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700723 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700724 /* bail because we already have a command pending */
725 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
726 adapter->current_op);
727 return;
728 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700729 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700730 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700731 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700732 NULL, 0);
733}
734
735/**
736 * i40evf_set_hena
737 * @adapter: adapter structure
738 *
739 * Request the PF to set our RSS hash capabilities
740 **/
741void i40evf_set_hena(struct i40evf_adapter *adapter)
742{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700743 struct virtchnl_rss_hena vrh;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700744
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700745 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700746 /* bail because we already have a command pending */
747 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
748 adapter->current_op);
749 return;
750 }
751 vrh.hena = adapter->hena;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700752 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700753 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700754 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700755 (u8 *)&vrh, sizeof(vrh));
756}
757
758/**
759 * i40evf_set_rss_key
760 * @adapter: adapter structure
761 *
762 * Request the PF to set our RSS hash key
763 **/
764void i40evf_set_rss_key(struct i40evf_adapter *adapter)
765{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700766 struct virtchnl_rss_key *vrk;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700767 int len;
768
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700769 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700770 /* bail because we already have a command pending */
771 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
772 adapter->current_op);
773 return;
774 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700775 len = sizeof(struct virtchnl_rss_key) +
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700776 (adapter->rss_key_size * sizeof(u8)) - 1;
777 vrk = kzalloc(len, GFP_KERNEL);
778 if (!vrk)
779 return;
780 vrk->vsi_id = adapter->vsi.id;
781 vrk->key_len = adapter->rss_key_size;
782 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
783
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700784 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700785 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700786 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700787 (u8 *)vrk, len);
788 kfree(vrk);
789}
790
791/**
792 * i40evf_set_rss_lut
793 * @adapter: adapter structure
794 *
795 * Request the PF to set our RSS lookup table
796 **/
797void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
798{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700799 struct virtchnl_rss_lut *vrl;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700800 int len;
801
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700802 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700803 /* bail because we already have a command pending */
804 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
805 adapter->current_op);
806 return;
807 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700808 len = sizeof(struct virtchnl_rss_lut) +
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700809 (adapter->rss_lut_size * sizeof(u8)) - 1;
810 vrl = kzalloc(len, GFP_KERNEL);
811 if (!vrl)
812 return;
813 vrl->vsi_id = adapter->vsi.id;
814 vrl->lut_entries = adapter->rss_lut_size;
815 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700816 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700817 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700818 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700819 (u8 *)vrl, len);
820 kfree(vrl);
821}
822
Mitch Williams625777e2014-02-20 19:29:05 -0800823/**
Mitch Williamsfe458e52016-08-04 11:37:02 -0700824 * i40evf_print_link_message - print link up or down
825 * @adapter: adapter structure
826 *
827 * Log a message telling the world of our wonderous link status
828 */
829static void i40evf_print_link_message(struct i40evf_adapter *adapter)
830{
831 struct net_device *netdev = adapter->netdev;
832 char *speed = "Unknown ";
833
834 if (!adapter->link_up) {
835 netdev_info(netdev, "NIC Link is Down\n");
836 return;
837 }
838
839 switch (adapter->link_speed) {
840 case I40E_LINK_SPEED_40GB:
841 speed = "40 G";
842 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800843 case I40E_LINK_SPEED_25GB:
844 speed = "25 G";
845 break;
Mitch Williamsfe458e52016-08-04 11:37:02 -0700846 case I40E_LINK_SPEED_20GB:
847 speed = "20 G";
848 break;
849 case I40E_LINK_SPEED_10GB:
850 speed = "10 G";
851 break;
852 case I40E_LINK_SPEED_1GB:
853 speed = "1000 M";
854 break;
855 case I40E_LINK_SPEED_100MB:
856 speed = "100 M";
857 break;
858 default:
859 break;
860 }
861
862 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
863}
864
865/**
Mitch Williams625777e2014-02-20 19:29:05 -0800866 * i40evf_request_reset
867 * @adapter: adapter structure
868 *
869 * Request that the PF reset this VF. No response is expected.
870 **/
871void i40evf_request_reset(struct i40evf_adapter *adapter)
872{
873 /* Don't check CURRENT_OP - this is always higher priority */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700874 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
875 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Mitch Williams625777e2014-02-20 19:29:05 -0800876}
Greg Rose62683ab2013-12-21 06:13:01 +0000877
878/**
879 * i40evf_virtchnl_completion
880 * @adapter: adapter structure
881 * @v_opcode: opcode sent by PF
882 * @v_retval: retval sent by PF
883 * @msg: message sent by PF
884 * @msglen: message length
885 *
886 * Asynchronous completion function for admin queue messages. Rather than busy
887 * wait, we fire off our requests and assume that no errors will be returned.
888 * This function handles the reply messages.
889 **/
890void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700891 enum virtchnl_ops v_opcode,
Greg Rose62683ab2013-12-21 06:13:01 +0000892 i40e_status v_retval,
893 u8 *msg, u16 msglen)
894{
895 struct net_device *netdev = adapter->netdev;
896
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700897 if (v_opcode == VIRTCHNL_OP_EVENT) {
898 struct virtchnl_pf_event *vpe =
899 (struct virtchnl_pf_event *)msg;
Greg Rose62683ab2013-12-21 06:13:01 +0000900 switch (vpe->event) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700901 case VIRTCHNL_EVENT_LINK_CHANGE:
Mitch Williamsfe458e52016-08-04 11:37:02 -0700902 adapter->link_speed =
903 vpe->event_data.link_event.link_speed;
904 if (adapter->link_up !=
905 vpe->event_data.link_event.link_status) {
906 adapter->link_up =
907 vpe->event_data.link_event.link_status;
Sridhar Samudrala3f341ac2016-09-01 22:27:27 +0200908 if (adapter->link_up) {
909 netif_tx_start_all_queues(netdev);
910 netif_carrier_on(netdev);
911 } else {
912 netif_tx_stop_all_queues(netdev);
913 netif_carrier_off(netdev);
914 }
Mitch Williamsfe458e52016-08-04 11:37:02 -0700915 i40evf_print_link_message(adapter);
Greg Rose62683ab2013-12-21 06:13:01 +0000916 }
917 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700918 case VIRTCHNL_EVENT_RESET_IMPENDING:
Mitch Williamsef8693e2014-02-13 03:48:53 -0800919 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
920 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
921 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
922 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
923 schedule_work(&adapter->reset_task);
924 }
Greg Rose62683ab2013-12-21 06:13:01 +0000925 break;
926 default:
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400927 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
928 vpe->event);
Greg Rose62683ab2013-12-21 06:13:01 +0000929 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000930 }
931 return;
932 }
Greg Rose62683ab2013-12-21 06:13:01 +0000933 if (v_retval) {
Mitch Williams8d8f2292015-10-21 19:47:11 -0400934 switch (v_opcode) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700935 case VIRTCHNL_OP_ADD_VLAN:
Mitch Williams8d8f2292015-10-21 19:47:11 -0400936 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
937 i40evf_stat_str(&adapter->hw, v_retval));
938 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700939 case VIRTCHNL_OP_ADD_ETH_ADDR:
Mitch Williams8d8f2292015-10-21 19:47:11 -0400940 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
941 i40evf_stat_str(&adapter->hw, v_retval));
942 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700943 case VIRTCHNL_OP_DEL_VLAN:
Mitch Williams8d8f2292015-10-21 19:47:11 -0400944 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
945 i40evf_stat_str(&adapter->hw, v_retval));
946 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700947 case VIRTCHNL_OP_DEL_ETH_ADDR:
Mitch Williams8d8f2292015-10-21 19:47:11 -0400948 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
949 i40evf_stat_str(&adapter->hw, v_retval));
950 break;
951 default:
952 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
953 v_retval,
954 i40evf_stat_str(&adapter->hw, v_retval),
955 v_opcode);
956 }
Greg Rose62683ab2013-12-21 06:13:01 +0000957 }
958 switch (v_opcode) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700959 case VIRTCHNL_OP_GET_STATS: {
Greg Rose62683ab2013-12-21 06:13:01 +0000960 struct i40e_eth_stats *stats =
961 (struct i40e_eth_stats *)msg;
Tobias Klauser4a0a3ab2017-04-06 08:46:28 +0200962 netdev->stats.rx_packets = stats->rx_unicast +
963 stats->rx_multicast +
964 stats->rx_broadcast;
965 netdev->stats.tx_packets = stats->tx_unicast +
966 stats->tx_multicast +
967 stats->tx_broadcast;
968 netdev->stats.rx_bytes = stats->rx_bytes;
969 netdev->stats.tx_bytes = stats->tx_bytes;
970 netdev->stats.tx_errors = stats->tx_errors;
971 netdev->stats.rx_dropped = stats->rx_discards;
972 netdev->stats.tx_dropped = stats->tx_discards;
Greg Rose62683ab2013-12-21 06:13:01 +0000973 adapter->current_stats = *stats;
974 }
975 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700976 case VIRTCHNL_OP_GET_VF_RESOURCES: {
977 u16 len = sizeof(struct virtchnl_vf_resource) +
Mitch Williamse6d038d2015-06-04 16:23:58 -0400978 I40E_MAX_VF_VSI *
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700979 sizeof(struct virtchnl_vsi_resource);
Mitch Williamse6d038d2015-06-04 16:23:58 -0400980 memcpy(adapter->vf_res, msg, min(msglen, len));
981 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
Mitch Williams8552d852015-08-31 19:54:51 -0400982 /* restore current mac address */
983 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
Mitch Williamse6d038d2015-06-04 16:23:58 -0400984 i40evf_process_config(adapter);
985 }
986 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700987 case VIRTCHNL_OP_ENABLE_QUEUES:
Greg Rose62683ab2013-12-21 06:13:01 +0000988 /* enable transmits */
989 i40evf_irq_enable(adapter, true);
Greg Rose62683ab2013-12-21 06:13:01 +0000990 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700991 case VIRTCHNL_OP_DISABLE_QUEUES:
Mitch Williamse284fc82015-03-27 00:12:09 -0700992 i40evf_free_all_tx_resources(adapter);
993 i40evf_free_all_rx_resources(adapter);
Mitch Williams209dc4d2015-12-09 15:50:27 -0800994 if (adapter->state == __I40EVF_DOWN_PENDING)
995 adapter->state = __I40EVF_DOWN;
Greg Rose62683ab2013-12-21 06:13:01 +0000996 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700997 case VIRTCHNL_OP_VERSION:
998 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
Mitch Williamsed636962015-04-07 19:45:32 -0400999 /* Don't display an error if we get these out of sequence.
1000 * If the firmware needed to get kicked, we'll get these and
1001 * it's no problem.
1002 */
1003 if (v_opcode != adapter->current_op)
1004 return;
Greg Rose62683ab2013-12-21 06:13:01 +00001005 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001006 case VIRTCHNL_OP_IWARP:
Mitch Williamsed0e8942017-01-24 10:23:59 -08001007 /* Gobble zero-length replies from the PF. They indicate that
1008 * a previous message was received OK, and the client doesn't
1009 * care about that.
1010 */
1011 if (msglen && CLIENT_ENABLED(adapter))
1012 i40evf_notify_client_message(&adapter->vsi,
1013 msg, msglen);
1014 break;
1015
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001016 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
Mitch Williamse5f77f42017-02-09 23:35:18 -08001017 adapter->client_pending &=
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001018 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
Mitch Williamse5f77f42017-02-09 23:35:18 -08001019 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001020 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
Jesse Brandeburgf0adc6e2017-05-11 11:23:15 -07001021 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001022 if (msglen == sizeof(*vrh))
1023 adapter->hena = vrh->hena;
1024 else
1025 dev_warn(&adapter->pdev->dev,
1026 "Invalid message %d from PF\n", v_opcode);
1027 }
1028 break;
Greg Rose62683ab2013-12-21 06:13:01 +00001029 default:
Mitch Williamsed0e8942017-01-24 10:23:59 -08001030 if (adapter->current_op && (v_opcode != adapter->current_op))
Mitch Williamsed636962015-04-07 19:45:32 -04001031 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1032 adapter->current_op, v_opcode);
Greg Rose62683ab2013-12-21 06:13:01 +00001033 break;
1034 } /* switch v_opcode */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001035 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Greg Rose62683ab2013-12-21 06:13:01 +00001036}