blob: 2bb81c39d85fa199dfe599cc6897574171b9d386 [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 |
164 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
Anjali Singhai Jainb9eacec2015-11-19 11:34:22 -0800165
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700166 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
Mitch Williamse6d038d2015-06-04 16:23:58 -0400167 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
168 if (PF_IS_V11(adapter))
169 return i40evf_send_pf_msg(adapter,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700170 VIRTCHNL_OP_GET_VF_RESOURCES,
Mitch Williamse6d038d2015-06-04 16:23:58 -0400171 (u8 *)&caps, sizeof(caps));
172 else
173 return i40evf_send_pf_msg(adapter,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700174 VIRTCHNL_OP_GET_VF_RESOURCES,
Mitch Williamse6d038d2015-06-04 16:23:58 -0400175 NULL, 0);
Greg Rose62683ab2013-12-21 06:13:01 +0000176}
177
178/**
179 * i40evf_get_vf_config
180 * @hw: pointer to the hardware structure
181 * @len: length of buffer
182 *
183 * Get VF configuration from PF and populate hw structure. Must be called after
184 * admin queue is initialized. Busy waits until response is received from PF,
185 * with maximum timeout. Response from PF is returned in the buffer for further
186 * processing by the caller.
187 **/
188int i40evf_get_vf_config(struct i40evf_adapter *adapter)
189{
190 struct i40e_hw *hw = &adapter->hw;
191 struct i40e_arq_event_info event;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700192 enum virtchnl_ops op;
Greg Rose62683ab2013-12-21 06:13:01 +0000193 i40e_status err;
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000194 u16 len;
Greg Rose62683ab2013-12-21 06:13:01 +0000195
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700196 len = sizeof(struct virtchnl_vf_resource) +
197 I40E_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
Mitch Williams1001dc32014-11-11 20:02:19 +0000198 event.buf_len = len;
199 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
Greg Rose62683ab2013-12-21 06:13:01 +0000200 if (!event.msg_buf) {
201 err = -ENOMEM;
202 goto out;
203 }
204
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000205 while (1) {
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000206 /* When the AQ is empty, i40evf_clean_arq_element will return
207 * nonzero and this loop will terminate.
208 */
209 err = i40evf_clean_arq_element(hw, &event, NULL);
210 if (err)
211 goto out_alloc;
212 op =
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700213 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
214 if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
Mitch Williamsf8d4db32014-10-25 03:24:33 +0000215 break;
216 }
Greg Rose62683ab2013-12-21 06:13:01 +0000217
218 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
Mitch Williams1001dc32014-11-11 20:02:19 +0000219 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
Greg Rose62683ab2013-12-21 06:13:01 +0000220
221 i40e_vf_parse_hw_config(hw, adapter->vf_res);
222out_alloc:
223 kfree(event.msg_buf);
224out:
225 return err;
226}
227
228/**
229 * i40evf_configure_queues
230 * @adapter: adapter structure
231 *
232 * Request that the PF set up our (previously allocated) queues.
233 **/
234void i40evf_configure_queues(struct i40evf_adapter *adapter)
235{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700236 struct virtchnl_vsi_queue_config_info *vqci;
237 struct virtchnl_queue_pair_info *vqpi;
Mitch Williamscc052922014-10-25 03:24:34 +0000238 int pairs = adapter->num_active_queues;
Alexander Duyckdab86af2017-03-14 10:15:27 -0700239 int i, len, max_frame = I40E_MAX_RXBUFFER;
Greg Rose62683ab2013-12-21 06:13:01 +0000240
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700241 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000242 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400243 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
244 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000245 return;
246 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700247 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
248 len = sizeof(struct virtchnl_vsi_queue_config_info) +
249 (sizeof(struct virtchnl_queue_pair_info) * pairs);
Mitch Williamsa85088d2015-11-06 15:26:04 -0800250 vqci = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000251 if (!vqci)
Greg Rose62683ab2013-12-21 06:13:01 +0000252 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000253
Alexander Duyckdab86af2017-03-14 10:15:27 -0700254 /* Limit maximum frame size when jumbo frames is not enabled */
255 if (!(adapter->flags & I40EVF_FLAG_LEGACY_RX) &&
256 (adapter->netdev->mtu <= ETH_DATA_LEN))
257 max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
258
Greg Rose62683ab2013-12-21 06:13:01 +0000259 vqci->vsi_id = adapter->vsi_res->vsi_id;
260 vqci->num_queue_pairs = pairs;
261 vqpi = vqci->qpair;
262 /* Size check is not needed here - HW max is 16 queue pairs, and we
263 * can fit info for 31 of them into the AQ buffer before it overflows.
264 */
265 for (i = 0; i < pairs; i++) {
266 vqpi->txq.vsi_id = vqci->vsi_id;
267 vqpi->txq.queue_id = i;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400268 vqpi->txq.ring_len = adapter->tx_rings[i].count;
269 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
Greg Rose62683ab2013-12-21 06:13:01 +0000270 vqpi->rxq.vsi_id = vqci->vsi_id;
271 vqpi->rxq.queue_id = i;
Mitch Williams0dd438d2015-10-26 19:44:40 -0400272 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
273 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
Alexander Duyckdab86af2017-03-14 10:15:27 -0700274 vqpi->rxq.max_pkt_size = max_frame;
275 vqpi->rxq.databuffer_size =
276 ALIGN(adapter->rx_rings[i].rx_buf_len,
277 BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
Greg Rose62683ab2013-12-21 06:13:01 +0000278 vqpi++;
279 }
280
Mitch Williamsfc86a972014-06-04 20:41:38 +0000281 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700282 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
Greg Rose62683ab2013-12-21 06:13:01 +0000283 (u8 *)vqci, len);
284 kfree(vqci);
Greg Rose62683ab2013-12-21 06:13:01 +0000285}
286
287/**
288 * i40evf_enable_queues
289 * @adapter: adapter structure
290 *
291 * Request that the PF enable all of our queues.
292 **/
293void i40evf_enable_queues(struct i40evf_adapter *adapter)
294{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700295 struct virtchnl_queue_select vqs;
Greg Rose62683ab2013-12-21 06:13:01 +0000296
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700297 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000298 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400299 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
300 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000301 return;
302 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700303 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
Greg Rose62683ab2013-12-21 06:13:01 +0000304 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400305 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000306 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000307 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700308 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
Mitch Williamsfc86a972014-06-04 20:41:38 +0000309 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000310}
311
312/**
313 * i40evf_disable_queues
314 * @adapter: adapter structure
315 *
316 * Request that the PF disable all of our queues.
317 **/
318void i40evf_disable_queues(struct i40evf_adapter *adapter)
319{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700320 struct virtchnl_queue_select vqs;
Greg Rose62683ab2013-12-21 06:13:01 +0000321
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700322 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000323 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400324 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
325 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000326 return;
327 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700328 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
Greg Rose62683ab2013-12-21 06:13:01 +0000329 vqs.vsi_id = adapter->vsi_res->vsi_id;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -0400330 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
Greg Rose62683ab2013-12-21 06:13:01 +0000331 vqs.rx_queues = vqs.tx_queues;
Greg Rose62683ab2013-12-21 06:13:01 +0000332 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700333 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
Mitch Williamsfc86a972014-06-04 20:41:38 +0000334 (u8 *)&vqs, sizeof(vqs));
Greg Rose62683ab2013-12-21 06:13:01 +0000335}
336
337/**
338 * i40evf_map_queues
339 * @adapter: adapter structure
340 *
341 * Request that the PF map queues to interrupt vectors. Misc causes, including
342 * admin queue, are always mapped to vector 0.
343 **/
344void i40evf_map_queues(struct i40evf_adapter *adapter)
345{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700346 struct virtchnl_irq_map_info *vimi;
Greg Rose62683ab2013-12-21 06:13:01 +0000347 int v_idx, q_vectors, len;
348 struct i40e_q_vector *q_vector;
349
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700350 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000351 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400352 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
353 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000354 return;
355 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700356 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
Greg Rose62683ab2013-12-21 06:13:01 +0000357
358 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
359
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700360 len = sizeof(struct virtchnl_irq_map_info) +
Greg Rose62683ab2013-12-21 06:13:01 +0000361 (adapter->num_msix_vectors *
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700362 sizeof(struct virtchnl_vector_map));
Mitch Williamsa85088d2015-11-06 15:26:04 -0800363 vimi = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000364 if (!vimi)
Greg Rose62683ab2013-12-21 06:13:01 +0000365 return;
Greg Rose62683ab2013-12-21 06:13:01 +0000366
367 vimi->num_vectors = adapter->num_msix_vectors;
368 /* Queue vectors first */
369 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Mitch Williams7d96ba12015-10-26 19:44:39 -0400370 q_vector = adapter->q_vectors + v_idx;
Greg Rose62683ab2013-12-21 06:13:01 +0000371 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
372 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
373 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
374 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
375 }
376 /* Misc vector last - this is only for AdminQ messages */
377 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
378 vimi->vecmap[v_idx].vector_id = 0;
379 vimi->vecmap[v_idx].txq_map = 0;
380 vimi->vecmap[v_idx].rxq_map = 0;
381
Mitch Williamsfc86a972014-06-04 20:41:38 +0000382 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700383 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
Greg Rose62683ab2013-12-21 06:13:01 +0000384 (u8 *)vimi, len);
385 kfree(vimi);
Greg Rose62683ab2013-12-21 06:13:01 +0000386}
387
388/**
Alan Brady5b36e8d2017-08-22 06:57:50 -0400389 * i40evf_request_queues
390 * @adapter: adapter structure
391 * @num: number of requested queues
392 *
393 * We get a default number of queues from the PF. This enables us to request a
394 * different number. Returns 0 on success, negative on failure
395 **/
396int i40evf_request_queues(struct i40evf_adapter *adapter, int num)
397{
398 struct virtchnl_vf_res_request vfres;
399
400 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
401 /* bail because we already have a command pending */
402 dev_err(&adapter->pdev->dev, "Cannot request queues, command %d pending\n",
403 adapter->current_op);
404 return -EBUSY;
405 }
406
407 vfres.num_queue_pairs = num;
408
409 adapter->current_op = VIRTCHNL_OP_REQUEST_QUEUES;
410 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_REQUEST_QUEUES,
411 (u8 *)&vfres, sizeof(vfres));
412}
413
414/**
Greg Rose62683ab2013-12-21 06:13:01 +0000415 * i40evf_add_ether_addrs
416 * @adapter: adapter structure
417 * @addrs: the MAC address filters to add (contiguous)
418 * @count: number of filters
419 *
420 * Request that the PF add one or more addresses to our filters.
421 **/
422void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
423{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700424 struct virtchnl_ether_addr_list *veal;
Greg Rose62683ab2013-12-21 06:13:01 +0000425 int len, i = 0, count = 0;
426 struct i40evf_mac_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400427 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000428
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700429 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000430 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400431 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
432 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000433 return;
434 }
435 list_for_each_entry(f, &adapter->mac_filter_list, list) {
436 if (f->add)
437 count++;
438 }
439 if (!count) {
440 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
441 return;
442 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700443 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
Greg Rose62683ab2013-12-21 06:13:01 +0000444
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700445 len = sizeof(struct virtchnl_ether_addr_list) +
446 (count * sizeof(struct virtchnl_ether_addr));
Greg Rose62683ab2013-12-21 06:13:01 +0000447 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400448 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000449 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700450 sizeof(struct virtchnl_ether_addr_list)) /
451 sizeof(struct virtchnl_ether_addr);
452 len = sizeof(struct virtchnl_ether_addr_list) +
453 (count * sizeof(struct virtchnl_ether_addr));
Mitch Williams1418c342015-10-21 19:47:12 -0400454 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000455 }
456
Mitch Williamsa85088d2015-11-06 15:26:04 -0800457 veal = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000458 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000459 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000460
Greg Rose62683ab2013-12-21 06:13:01 +0000461 veal->vsi_id = adapter->vsi_res->vsi_id;
462 veal->num_elements = count;
463 list_for_each_entry(f, &adapter->mac_filter_list, list) {
464 if (f->add) {
Greg Rose9a173902014-05-22 06:32:02 +0000465 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000466 i++;
467 f->add = false;
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700468 if (i == count)
469 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000470 }
471 }
Mitch Williams1418c342015-10-21 19:47:12 -0400472 if (!more)
473 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700474 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR,
Greg Rose62683ab2013-12-21 06:13:01 +0000475 (u8 *)veal, len);
476 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000477}
478
479/**
480 * i40evf_del_ether_addrs
481 * @adapter: adapter structure
482 * @addrs: the MAC address filters to remove (contiguous)
483 * @count: number of filtes
484 *
485 * Request that the PF remove one or more addresses from our filters.
486 **/
487void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
488{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700489 struct virtchnl_ether_addr_list *veal;
Greg Rose62683ab2013-12-21 06:13:01 +0000490 struct i40evf_mac_filter *f, *ftmp;
491 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400492 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000493
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700494 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000495 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400496 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
497 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000498 return;
499 }
500 list_for_each_entry(f, &adapter->mac_filter_list, list) {
501 if (f->remove)
502 count++;
503 }
504 if (!count) {
505 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
506 return;
507 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700508 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
Greg Rose62683ab2013-12-21 06:13:01 +0000509
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700510 len = sizeof(struct virtchnl_ether_addr_list) +
511 (count * sizeof(struct virtchnl_ether_addr));
Greg Rose62683ab2013-12-21 06:13:01 +0000512 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400513 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000514 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700515 sizeof(struct virtchnl_ether_addr_list)) /
516 sizeof(struct virtchnl_ether_addr);
517 len = sizeof(struct virtchnl_ether_addr_list) +
518 (count * sizeof(struct virtchnl_ether_addr));
Mitch Williams1418c342015-10-21 19:47:12 -0400519 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000520 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800521 veal = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000522 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000523 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000524
Greg Rose62683ab2013-12-21 06:13:01 +0000525 veal->vsi_id = adapter->vsi_res->vsi_id;
526 veal->num_elements = count;
527 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
528 if (f->remove) {
Greg Rose9a173902014-05-22 06:32:02 +0000529 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000530 i++;
531 list_del(&f->list);
532 kfree(f);
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700533 if (i == count)
534 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000535 }
536 }
Mitch Williams1418c342015-10-21 19:47:12 -0400537 if (!more)
538 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700539 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR,
Greg Rose62683ab2013-12-21 06:13:01 +0000540 (u8 *)veal, len);
541 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000542}
543
544/**
545 * i40evf_add_vlans
546 * @adapter: adapter structure
547 * @vlans: the VLANs to add
548 * @count: number of VLANs
549 *
550 * Request that the PF add one or more VLAN filters to our VSI.
551 **/
552void i40evf_add_vlans(struct i40evf_adapter *adapter)
553{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700554 struct virtchnl_vlan_filter_list *vvfl;
Greg Rose62683ab2013-12-21 06:13:01 +0000555 int len, i = 0, count = 0;
556 struct i40evf_vlan_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400557 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000558
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700559 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000560 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400561 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
562 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000563 return;
564 }
565
566 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
567 if (f->add)
568 count++;
569 }
570 if (!count) {
571 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
572 return;
573 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700574 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
Greg Rose62683ab2013-12-21 06:13:01 +0000575
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700576 len = sizeof(struct virtchnl_vlan_filter_list) +
Greg Rose62683ab2013-12-21 06:13:01 +0000577 (count * sizeof(u16));
578 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400579 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000580 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700581 sizeof(struct virtchnl_vlan_filter_list)) /
Greg Rose62683ab2013-12-21 06:13:01 +0000582 sizeof(u16);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700583 len = sizeof(struct virtchnl_vlan_filter_list) +
Mitch Williams1418c342015-10-21 19:47:12 -0400584 (count * sizeof(u16));
585 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000586 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800587 vvfl = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000588 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000589 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000590
Greg Rose62683ab2013-12-21 06:13:01 +0000591 vvfl->vsi_id = adapter->vsi_res->vsi_id;
592 vvfl->num_elements = count;
593 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
594 if (f->add) {
595 vvfl->vlan_id[i] = f->vlan;
596 i++;
597 f->add = false;
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700598 if (i == count)
599 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000600 }
601 }
Mitch Williams1418c342015-10-21 19:47:12 -0400602 if (!more)
603 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700604 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
Mitch Williamsfc86a972014-06-04 20:41:38 +0000605 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000606}
607
608/**
609 * i40evf_del_vlans
610 * @adapter: adapter structure
611 * @vlans: the VLANs to remove
612 * @count: number of VLANs
613 *
614 * Request that the PF remove one or more VLAN filters from our VSI.
615 **/
616void i40evf_del_vlans(struct i40evf_adapter *adapter)
617{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700618 struct virtchnl_vlan_filter_list *vvfl;
Greg Rose62683ab2013-12-21 06:13:01 +0000619 struct i40evf_vlan_filter *f, *ftmp;
620 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400621 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000622
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700623 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000624 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400625 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
626 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000627 return;
628 }
629
630 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
631 if (f->remove)
632 count++;
633 }
634 if (!count) {
635 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
636 return;
637 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700638 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
Greg Rose62683ab2013-12-21 06:13:01 +0000639
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700640 len = sizeof(struct virtchnl_vlan_filter_list) +
Greg Rose62683ab2013-12-21 06:13:01 +0000641 (count * sizeof(u16));
642 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400643 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000644 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700645 sizeof(struct virtchnl_vlan_filter_list)) /
Greg Rose62683ab2013-12-21 06:13:01 +0000646 sizeof(u16);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700647 len = sizeof(struct virtchnl_vlan_filter_list) +
Mitch Williams1418c342015-10-21 19:47:12 -0400648 (count * sizeof(u16));
649 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000650 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800651 vvfl = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000652 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000653 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000654
Greg Rose62683ab2013-12-21 06:13:01 +0000655 vvfl->vsi_id = adapter->vsi_res->vsi_id;
656 vvfl->num_elements = count;
657 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
658 if (f->remove) {
659 vvfl->vlan_id[i] = f->vlan;
660 i++;
661 list_del(&f->list);
662 kfree(f);
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700663 if (i == count)
664 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000665 }
666 }
Mitch Williams1418c342015-10-21 19:47:12 -0400667 if (!more)
668 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700669 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
Mitch Williamsfc86a972014-06-04 20:41:38 +0000670 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000671}
672
673/**
674 * i40evf_set_promiscuous
675 * @adapter: adapter structure
676 * @flags: bitmask to control unicast/multicast promiscuous.
677 *
678 * Request that the PF enable promiscuous mode for our VSI.
679 **/
680void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
681{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700682 struct virtchnl_promisc_info vpi;
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700683 int promisc_all;
Greg Rose62683ab2013-12-21 06:13:01 +0000684
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700685 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000686 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400687 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
688 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000689 return;
690 }
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700691
Jesse Brandeburgff3f4cc2017-05-11 11:23:16 -0700692 promisc_all = FLAG_VF_UNICAST_PROMISC |
693 FLAG_VF_MULTICAST_PROMISC;
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700694 if ((flags & promisc_all) == promisc_all) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700695 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
696 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
697 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700698 }
699
Jesse Brandeburgff3f4cc2017-05-11 11:23:16 -0700700 if (flags & FLAG_VF_MULTICAST_PROMISC) {
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700701 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
702 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
703 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
704 }
705
706 if (!flags) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700707 adapter->flags &= ~I40EVF_FLAG_PROMISC_ON;
708 adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC;
709 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
710 }
711
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700712 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
Greg Rose62683ab2013-12-21 06:13:01 +0000713 vpi.vsi_id = adapter->vsi_res->vsi_id;
714 vpi.flags = flags;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700715 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
Greg Rose62683ab2013-12-21 06:13:01 +0000716 (u8 *)&vpi, sizeof(vpi));
717}
718
719/**
720 * i40evf_request_stats
721 * @adapter: adapter structure
722 *
723 * Request VSI statistics from PF.
724 **/
725void i40evf_request_stats(struct i40evf_adapter *adapter)
726{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700727 struct virtchnl_queue_select vqs;
Mitch Williams75a64432014-11-11 20:02:42 +0000728
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700729 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000730 /* no error message, this isn't crucial */
731 return;
732 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700733 adapter->current_op = VIRTCHNL_OP_GET_STATS;
Greg Rose62683ab2013-12-21 06:13:01 +0000734 vqs.vsi_id = adapter->vsi_res->vsi_id;
735 /* queue maps are ignored for this message - only the vsi is used */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700736 if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS,
Greg Rose62683ab2013-12-21 06:13:01 +0000737 (u8 *)&vqs, sizeof(vqs)))
738 /* if the request failed, don't lock out others */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700739 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Greg Rose62683ab2013-12-21 06:13:01 +0000740}
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700741
742/**
743 * i40evf_get_hena
744 * @adapter: adapter structure
745 *
746 * Request hash enable capabilities from PF
747 **/
748void i40evf_get_hena(struct i40evf_adapter *adapter)
749{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700750 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700751 /* bail because we already have a command pending */
752 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
753 adapter->current_op);
754 return;
755 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700756 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700757 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700758 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700759 NULL, 0);
760}
761
762/**
763 * i40evf_set_hena
764 * @adapter: adapter structure
765 *
766 * Request the PF to set our RSS hash capabilities
767 **/
768void i40evf_set_hena(struct i40evf_adapter *adapter)
769{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700770 struct virtchnl_rss_hena vrh;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700771
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700772 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700773 /* bail because we already have a command pending */
774 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
775 adapter->current_op);
776 return;
777 }
778 vrh.hena = adapter->hena;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700779 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700780 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700781 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700782 (u8 *)&vrh, sizeof(vrh));
783}
784
785/**
786 * i40evf_set_rss_key
787 * @adapter: adapter structure
788 *
789 * Request the PF to set our RSS hash key
790 **/
791void i40evf_set_rss_key(struct i40evf_adapter *adapter)
792{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700793 struct virtchnl_rss_key *vrk;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700794 int len;
795
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700796 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700797 /* bail because we already have a command pending */
798 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
799 adapter->current_op);
800 return;
801 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700802 len = sizeof(struct virtchnl_rss_key) +
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700803 (adapter->rss_key_size * sizeof(u8)) - 1;
804 vrk = kzalloc(len, GFP_KERNEL);
805 if (!vrk)
806 return;
807 vrk->vsi_id = adapter->vsi.id;
808 vrk->key_len = adapter->rss_key_size;
809 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
810
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700811 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700812 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700813 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700814 (u8 *)vrk, len);
815 kfree(vrk);
816}
817
818/**
819 * i40evf_set_rss_lut
820 * @adapter: adapter structure
821 *
822 * Request the PF to set our RSS lookup table
823 **/
824void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
825{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700826 struct virtchnl_rss_lut *vrl;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700827 int len;
828
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700829 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700830 /* bail because we already have a command pending */
831 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
832 adapter->current_op);
833 return;
834 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700835 len = sizeof(struct virtchnl_rss_lut) +
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700836 (adapter->rss_lut_size * sizeof(u8)) - 1;
837 vrl = kzalloc(len, GFP_KERNEL);
838 if (!vrl)
839 return;
840 vrl->vsi_id = adapter->vsi.id;
841 vrl->lut_entries = adapter->rss_lut_size;
842 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700843 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700844 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700845 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700846 (u8 *)vrl, len);
847 kfree(vrl);
848}
849
Mitch Williams625777e2014-02-20 19:29:05 -0800850/**
Mariusz Stachura87743702017-07-17 22:09:45 -0700851 * i40evf_enable_vlan_stripping
852 * @adapter: adapter structure
853 *
854 * Request VLAN header stripping to be enabled
855 **/
856void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter)
857{
858 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
859 /* bail because we already have a command pending */
860 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
861 adapter->current_op);
862 return;
863 }
864 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
865 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
866 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
867 NULL, 0);
868}
869
870/**
871 * i40evf_disable_vlan_stripping
872 * @adapter: adapter structure
873 *
874 * Request VLAN header stripping to be disabled
875 **/
876void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter)
877{
878 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
879 /* bail because we already have a command pending */
880 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
881 adapter->current_op);
882 return;
883 }
884 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
885 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
886 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
887 NULL, 0);
888}
889
890/**
Mitch Williamsfe458e52016-08-04 11:37:02 -0700891 * i40evf_print_link_message - print link up or down
892 * @adapter: adapter structure
893 *
894 * Log a message telling the world of our wonderous link status
895 */
896static void i40evf_print_link_message(struct i40evf_adapter *adapter)
897{
898 struct net_device *netdev = adapter->netdev;
899 char *speed = "Unknown ";
900
901 if (!adapter->link_up) {
902 netdev_info(netdev, "NIC Link is Down\n");
903 return;
904 }
905
906 switch (adapter->link_speed) {
907 case I40E_LINK_SPEED_40GB:
908 speed = "40 G";
909 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800910 case I40E_LINK_SPEED_25GB:
911 speed = "25 G";
912 break;
Mitch Williamsfe458e52016-08-04 11:37:02 -0700913 case I40E_LINK_SPEED_20GB:
914 speed = "20 G";
915 break;
916 case I40E_LINK_SPEED_10GB:
917 speed = "10 G";
918 break;
919 case I40E_LINK_SPEED_1GB:
920 speed = "1000 M";
921 break;
922 case I40E_LINK_SPEED_100MB:
923 speed = "100 M";
924 break;
925 default:
926 break;
927 }
928
929 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
930}
931
932/**
Mitch Williams625777e2014-02-20 19:29:05 -0800933 * i40evf_request_reset
934 * @adapter: adapter structure
935 *
936 * Request that the PF reset this VF. No response is expected.
937 **/
938void i40evf_request_reset(struct i40evf_adapter *adapter)
939{
940 /* Don't check CURRENT_OP - this is always higher priority */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700941 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
942 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Mitch Williams625777e2014-02-20 19:29:05 -0800943}
Greg Rose62683ab2013-12-21 06:13:01 +0000944
945/**
946 * i40evf_virtchnl_completion
947 * @adapter: adapter structure
948 * @v_opcode: opcode sent by PF
949 * @v_retval: retval sent by PF
950 * @msg: message sent by PF
951 * @msglen: message length
952 *
953 * Asynchronous completion function for admin queue messages. Rather than busy
954 * wait, we fire off our requests and assume that no errors will be returned.
955 * This function handles the reply messages.
956 **/
957void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700958 enum virtchnl_ops v_opcode,
Greg Rose62683ab2013-12-21 06:13:01 +0000959 i40e_status v_retval,
960 u8 *msg, u16 msglen)
961{
962 struct net_device *netdev = adapter->netdev;
963
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700964 if (v_opcode == VIRTCHNL_OP_EVENT) {
965 struct virtchnl_pf_event *vpe =
966 (struct virtchnl_pf_event *)msg;
Greg Rose62683ab2013-12-21 06:13:01 +0000967 switch (vpe->event) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700968 case VIRTCHNL_EVENT_LINK_CHANGE:
Mitch Williamsfe458e52016-08-04 11:37:02 -0700969 adapter->link_speed =
970 vpe->event_data.link_event.link_speed;
971 if (adapter->link_up !=
972 vpe->event_data.link_event.link_status) {
973 adapter->link_up =
974 vpe->event_data.link_event.link_status;
Sridhar Samudrala3f341ac2016-09-01 22:27:27 +0200975 if (adapter->link_up) {
976 netif_tx_start_all_queues(netdev);
977 netif_carrier_on(netdev);
978 } else {
979 netif_tx_stop_all_queues(netdev);
980 netif_carrier_off(netdev);
981 }
Mitch Williamsfe458e52016-08-04 11:37:02 -0700982 i40evf_print_link_message(adapter);
Greg Rose62683ab2013-12-21 06:13:01 +0000983 }
984 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700985 case VIRTCHNL_EVENT_RESET_IMPENDING:
Mitch Williamsef8693e2014-02-13 03:48:53 -0800986 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
987 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
988 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
989 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
990 schedule_work(&adapter->reset_task);
991 }
Greg Rose62683ab2013-12-21 06:13:01 +0000992 break;
993 default:
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400994 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
995 vpe->event);
Greg Rose62683ab2013-12-21 06:13:01 +0000996 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000997 }
998 return;
999 }
Greg Rose62683ab2013-12-21 06:13:01 +00001000 if (v_retval) {
Mitch Williams8d8f2292015-10-21 19:47:11 -04001001 switch (v_opcode) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001002 case VIRTCHNL_OP_ADD_VLAN:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001003 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1004 i40evf_stat_str(&adapter->hw, v_retval));
1005 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001006 case VIRTCHNL_OP_ADD_ETH_ADDR:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001007 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1008 i40evf_stat_str(&adapter->hw, v_retval));
1009 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001010 case VIRTCHNL_OP_DEL_VLAN:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001011 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1012 i40evf_stat_str(&adapter->hw, v_retval));
1013 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001014 case VIRTCHNL_OP_DEL_ETH_ADDR:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001015 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1016 i40evf_stat_str(&adapter->hw, v_retval));
1017 break;
1018 default:
1019 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
1020 v_retval,
1021 i40evf_stat_str(&adapter->hw, v_retval),
1022 v_opcode);
1023 }
Greg Rose62683ab2013-12-21 06:13:01 +00001024 }
1025 switch (v_opcode) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001026 case VIRTCHNL_OP_GET_STATS: {
Greg Rose62683ab2013-12-21 06:13:01 +00001027 struct i40e_eth_stats *stats =
1028 (struct i40e_eth_stats *)msg;
Tobias Klauser4a0a3ab2017-04-06 08:46:28 +02001029 netdev->stats.rx_packets = stats->rx_unicast +
1030 stats->rx_multicast +
1031 stats->rx_broadcast;
1032 netdev->stats.tx_packets = stats->tx_unicast +
1033 stats->tx_multicast +
1034 stats->tx_broadcast;
1035 netdev->stats.rx_bytes = stats->rx_bytes;
1036 netdev->stats.tx_bytes = stats->tx_bytes;
1037 netdev->stats.tx_errors = stats->tx_errors;
1038 netdev->stats.rx_dropped = stats->rx_discards;
1039 netdev->stats.tx_dropped = stats->tx_discards;
Greg Rose62683ab2013-12-21 06:13:01 +00001040 adapter->current_stats = *stats;
1041 }
1042 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001043 case VIRTCHNL_OP_GET_VF_RESOURCES: {
1044 u16 len = sizeof(struct virtchnl_vf_resource) +
Mitch Williamse6d038d2015-06-04 16:23:58 -04001045 I40E_MAX_VF_VSI *
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001046 sizeof(struct virtchnl_vsi_resource);
Mitch Williamse6d038d2015-06-04 16:23:58 -04001047 memcpy(adapter->vf_res, msg, min(msglen, len));
1048 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
Mitch Williams8552d852015-08-31 19:54:51 -04001049 /* restore current mac address */
1050 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
Mitch Williamse6d038d2015-06-04 16:23:58 -04001051 i40evf_process_config(adapter);
1052 }
1053 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001054 case VIRTCHNL_OP_ENABLE_QUEUES:
Greg Rose62683ab2013-12-21 06:13:01 +00001055 /* enable transmits */
1056 i40evf_irq_enable(adapter, true);
Greg Rose62683ab2013-12-21 06:13:01 +00001057 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001058 case VIRTCHNL_OP_DISABLE_QUEUES:
Mitch Williamse284fc82015-03-27 00:12:09 -07001059 i40evf_free_all_tx_resources(adapter);
1060 i40evf_free_all_rx_resources(adapter);
Sudheer Mogilappagarife2647a2017-06-23 04:24:44 -04001061 if (adapter->state == __I40EVF_DOWN_PENDING) {
Mitch Williams209dc4d2015-12-09 15:50:27 -08001062 adapter->state = __I40EVF_DOWN;
Sudheer Mogilappagarife2647a2017-06-23 04:24:44 -04001063 wake_up(&adapter->down_waitqueue);
1064 }
Greg Rose62683ab2013-12-21 06:13:01 +00001065 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001066 case VIRTCHNL_OP_VERSION:
1067 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
Mitch Williamsed636962015-04-07 19:45:32 -04001068 /* Don't display an error if we get these out of sequence.
1069 * If the firmware needed to get kicked, we'll get these and
1070 * it's no problem.
1071 */
1072 if (v_opcode != adapter->current_op)
1073 return;
Greg Rose62683ab2013-12-21 06:13:01 +00001074 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001075 case VIRTCHNL_OP_IWARP:
Mitch Williamsed0e8942017-01-24 10:23:59 -08001076 /* Gobble zero-length replies from the PF. They indicate that
1077 * a previous message was received OK, and the client doesn't
1078 * care about that.
1079 */
1080 if (msglen && CLIENT_ENABLED(adapter))
1081 i40evf_notify_client_message(&adapter->vsi,
1082 msg, msglen);
1083 break;
1084
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001085 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
Mitch Williamse5f77f42017-02-09 23:35:18 -08001086 adapter->client_pending &=
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001087 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
Mitch Williamse5f77f42017-02-09 23:35:18 -08001088 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001089 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
Jesse Brandeburgf0adc6e2017-05-11 11:23:15 -07001090 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001091 if (msglen == sizeof(*vrh))
1092 adapter->hena = vrh->hena;
1093 else
1094 dev_warn(&adapter->pdev->dev,
1095 "Invalid message %d from PF\n", v_opcode);
1096 }
1097 break;
Alan Brady5b36e8d2017-08-22 06:57:50 -04001098 case VIRTCHNL_OP_REQUEST_QUEUES: {
1099 struct virtchnl_vf_res_request *vfres =
1100 (struct virtchnl_vf_res_request *)msg;
1101 if (vfres->num_queue_pairs == adapter->num_req_queues) {
1102 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
1103 i40evf_schedule_reset(adapter);
1104 } else {
1105 dev_info(&adapter->pdev->dev,
1106 "Requested %d queues, PF can support %d\n",
1107 adapter->num_req_queues,
1108 vfres->num_queue_pairs);
1109 adapter->num_req_queues = 0;
1110 }
1111 }
1112 break;
Greg Rose62683ab2013-12-21 06:13:01 +00001113 default:
Mitch Williamsed0e8942017-01-24 10:23:59 -08001114 if (adapter->current_op && (v_opcode != adapter->current_op))
Mitch Williamsed636962015-04-07 19:45:32 -04001115 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1116 adapter->current_op, v_opcode);
Greg Rose62683ab2013-12-21 06:13:01 +00001117 break;
1118 } /* switch v_opcode */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001119 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Greg Rose62683ab2013-12-21 06:13:01 +00001120}