blob: 46c8b8a3907cc6150d849dcc348488470b3dedaa [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;
Alan Brady17a94222017-10-11 14:49:43 -0700410 adapter->flags |= I40EVF_FLAG_REINIT_ITR_NEEDED;
Alan Brady5b36e8d2017-08-22 06:57:50 -0400411 return i40evf_send_pf_msg(adapter, VIRTCHNL_OP_REQUEST_QUEUES,
412 (u8 *)&vfres, sizeof(vfres));
413}
414
415/**
Greg Rose62683ab2013-12-21 06:13:01 +0000416 * i40evf_add_ether_addrs
417 * @adapter: adapter structure
418 * @addrs: the MAC address filters to add (contiguous)
419 * @count: number of filters
420 *
421 * Request that the PF add one or more addresses to our filters.
422 **/
423void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
424{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700425 struct virtchnl_ether_addr_list *veal;
Greg Rose62683ab2013-12-21 06:13:01 +0000426 int len, i = 0, count = 0;
427 struct i40evf_mac_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400428 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000429
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700430 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000431 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400432 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
433 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000434 return;
435 }
436 list_for_each_entry(f, &adapter->mac_filter_list, list) {
437 if (f->add)
438 count++;
439 }
440 if (!count) {
441 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
442 return;
443 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700444 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
Greg Rose62683ab2013-12-21 06:13:01 +0000445
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700446 len = sizeof(struct virtchnl_ether_addr_list) +
447 (count * sizeof(struct virtchnl_ether_addr));
Greg Rose62683ab2013-12-21 06:13:01 +0000448 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400449 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000450 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700451 sizeof(struct virtchnl_ether_addr_list)) /
452 sizeof(struct virtchnl_ether_addr);
453 len = sizeof(struct virtchnl_ether_addr_list) +
454 (count * sizeof(struct virtchnl_ether_addr));
Mitch Williams1418c342015-10-21 19:47:12 -0400455 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000456 }
457
Mitch Williamsa85088d2015-11-06 15:26:04 -0800458 veal = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000459 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000460 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000461
Greg Rose62683ab2013-12-21 06:13:01 +0000462 veal->vsi_id = adapter->vsi_res->vsi_id;
463 veal->num_elements = count;
464 list_for_each_entry(f, &adapter->mac_filter_list, list) {
465 if (f->add) {
Greg Rose9a173902014-05-22 06:32:02 +0000466 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000467 i++;
468 f->add = false;
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700469 if (i == count)
470 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000471 }
472 }
Mitch Williams1418c342015-10-21 19:47:12 -0400473 if (!more)
474 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700475 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR,
Greg Rose62683ab2013-12-21 06:13:01 +0000476 (u8 *)veal, len);
477 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000478}
479
480/**
481 * i40evf_del_ether_addrs
482 * @adapter: adapter structure
483 * @addrs: the MAC address filters to remove (contiguous)
484 * @count: number of filtes
485 *
486 * Request that the PF remove one or more addresses from our filters.
487 **/
488void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
489{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700490 struct virtchnl_ether_addr_list *veal;
Greg Rose62683ab2013-12-21 06:13:01 +0000491 struct i40evf_mac_filter *f, *ftmp;
492 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400493 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000494
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700495 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000496 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400497 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
498 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000499 return;
500 }
501 list_for_each_entry(f, &adapter->mac_filter_list, list) {
502 if (f->remove)
503 count++;
504 }
505 if (!count) {
506 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
507 return;
508 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700509 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
Greg Rose62683ab2013-12-21 06:13:01 +0000510
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700511 len = sizeof(struct virtchnl_ether_addr_list) +
512 (count * sizeof(struct virtchnl_ether_addr));
Greg Rose62683ab2013-12-21 06:13:01 +0000513 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400514 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000515 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700516 sizeof(struct virtchnl_ether_addr_list)) /
517 sizeof(struct virtchnl_ether_addr);
518 len = sizeof(struct virtchnl_ether_addr_list) +
519 (count * sizeof(struct virtchnl_ether_addr));
Mitch Williams1418c342015-10-21 19:47:12 -0400520 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000521 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800522 veal = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000523 if (!veal)
Greg Rose62683ab2013-12-21 06:13:01 +0000524 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000525
Greg Rose62683ab2013-12-21 06:13:01 +0000526 veal->vsi_id = adapter->vsi_res->vsi_id;
527 veal->num_elements = count;
528 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
529 if (f->remove) {
Greg Rose9a173902014-05-22 06:32:02 +0000530 ether_addr_copy(veal->list[i].addr, f->macaddr);
Greg Rose62683ab2013-12-21 06:13:01 +0000531 i++;
532 list_del(&f->list);
533 kfree(f);
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700534 if (i == count)
535 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000536 }
537 }
Mitch Williams1418c342015-10-21 19:47:12 -0400538 if (!more)
539 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700540 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR,
Greg Rose62683ab2013-12-21 06:13:01 +0000541 (u8 *)veal, len);
542 kfree(veal);
Greg Rose62683ab2013-12-21 06:13:01 +0000543}
544
545/**
546 * i40evf_add_vlans
547 * @adapter: adapter structure
548 * @vlans: the VLANs to add
549 * @count: number of VLANs
550 *
551 * Request that the PF add one or more VLAN filters to our VSI.
552 **/
553void i40evf_add_vlans(struct i40evf_adapter *adapter)
554{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700555 struct virtchnl_vlan_filter_list *vvfl;
Greg Rose62683ab2013-12-21 06:13:01 +0000556 int len, i = 0, count = 0;
557 struct i40evf_vlan_filter *f;
Mitch Williams1418c342015-10-21 19:47:12 -0400558 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000559
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700560 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000561 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400562 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
563 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000564 return;
565 }
566
567 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
568 if (f->add)
569 count++;
570 }
571 if (!count) {
572 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
573 return;
574 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700575 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
Greg Rose62683ab2013-12-21 06:13:01 +0000576
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700577 len = sizeof(struct virtchnl_vlan_filter_list) +
Greg Rose62683ab2013-12-21 06:13:01 +0000578 (count * sizeof(u16));
579 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400580 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000581 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700582 sizeof(struct virtchnl_vlan_filter_list)) /
Greg Rose62683ab2013-12-21 06:13:01 +0000583 sizeof(u16);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700584 len = sizeof(struct virtchnl_vlan_filter_list) +
Mitch Williams1418c342015-10-21 19:47:12 -0400585 (count * sizeof(u16));
586 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000587 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800588 vvfl = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000589 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000590 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000591
Greg Rose62683ab2013-12-21 06:13:01 +0000592 vvfl->vsi_id = adapter->vsi_res->vsi_id;
593 vvfl->num_elements = count;
594 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
595 if (f->add) {
596 vvfl->vlan_id[i] = f->vlan;
597 i++;
598 f->add = false;
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700599 if (i == count)
600 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000601 }
602 }
Mitch Williams1418c342015-10-21 19:47:12 -0400603 if (!more)
604 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700605 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
Mitch Williamsfc86a972014-06-04 20:41:38 +0000606 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000607}
608
609/**
610 * i40evf_del_vlans
611 * @adapter: adapter structure
612 * @vlans: the VLANs to remove
613 * @count: number of VLANs
614 *
615 * Request that the PF remove one or more VLAN filters from our VSI.
616 **/
617void i40evf_del_vlans(struct i40evf_adapter *adapter)
618{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700619 struct virtchnl_vlan_filter_list *vvfl;
Greg Rose62683ab2013-12-21 06:13:01 +0000620 struct i40evf_vlan_filter *f, *ftmp;
621 int len, i = 0, count = 0;
Mitch Williams1418c342015-10-21 19:47:12 -0400622 bool more = false;
Greg Rose62683ab2013-12-21 06:13:01 +0000623
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700624 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000625 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400626 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
627 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000628 return;
629 }
630
631 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
632 if (f->remove)
633 count++;
634 }
635 if (!count) {
636 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
637 return;
638 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700639 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
Greg Rose62683ab2013-12-21 06:13:01 +0000640
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700641 len = sizeof(struct virtchnl_vlan_filter_list) +
Greg Rose62683ab2013-12-21 06:13:01 +0000642 (count * sizeof(u16));
643 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400644 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
Greg Rose62683ab2013-12-21 06:13:01 +0000645 count = (I40EVF_MAX_AQ_BUF_SIZE -
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700646 sizeof(struct virtchnl_vlan_filter_list)) /
Greg Rose62683ab2013-12-21 06:13:01 +0000647 sizeof(u16);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700648 len = sizeof(struct virtchnl_vlan_filter_list) +
Mitch Williams1418c342015-10-21 19:47:12 -0400649 (count * sizeof(u16));
650 more = true;
Greg Rose62683ab2013-12-21 06:13:01 +0000651 }
Mitch Williamsa85088d2015-11-06 15:26:04 -0800652 vvfl = kzalloc(len, GFP_KERNEL);
Mitch Williams249c8b82014-05-10 04:49:04 +0000653 if (!vvfl)
Greg Rose62683ab2013-12-21 06:13:01 +0000654 return;
Mitch Williams249c8b82014-05-10 04:49:04 +0000655
Greg Rose62683ab2013-12-21 06:13:01 +0000656 vvfl->vsi_id = adapter->vsi_res->vsi_id;
657 vvfl->num_elements = count;
658 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
659 if (f->remove) {
660 vvfl->vlan_id[i] = f->vlan;
661 i++;
662 list_del(&f->list);
663 kfree(f);
Mitch Williams0e8d95f892016-05-16 10:26:36 -0700664 if (i == count)
665 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000666 }
667 }
Mitch Williams1418c342015-10-21 19:47:12 -0400668 if (!more)
669 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700670 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
Mitch Williamsfc86a972014-06-04 20:41:38 +0000671 kfree(vvfl);
Greg Rose62683ab2013-12-21 06:13:01 +0000672}
673
674/**
675 * i40evf_set_promiscuous
676 * @adapter: adapter structure
677 * @flags: bitmask to control unicast/multicast promiscuous.
678 *
679 * Request that the PF enable promiscuous mode for our VSI.
680 **/
681void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
682{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700683 struct virtchnl_promisc_info vpi;
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700684 int promisc_all;
Greg Rose62683ab2013-12-21 06:13:01 +0000685
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700686 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000687 /* bail because we already have a command pending */
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400688 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
689 adapter->current_op);
Greg Rose62683ab2013-12-21 06:13:01 +0000690 return;
691 }
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700692
Jesse Brandeburgff3f4cc2017-05-11 11:23:16 -0700693 promisc_all = FLAG_VF_UNICAST_PROMISC |
694 FLAG_VF_MULTICAST_PROMISC;
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700695 if ((flags & promisc_all) == promisc_all) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700696 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
697 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
698 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700699 }
700
Jesse Brandeburgff3f4cc2017-05-11 11:23:16 -0700701 if (flags & FLAG_VF_MULTICAST_PROMISC) {
Anjali Singhai Jainf42a5c72016-05-03 15:13:10 -0700702 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
703 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
704 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
705 }
706
707 if (!flags) {
Anjali Singhai Jain47d34832016-04-12 08:30:52 -0700708 adapter->flags &= ~I40EVF_FLAG_PROMISC_ON;
709 adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC;
710 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
711 }
712
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700713 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
Greg Rose62683ab2013-12-21 06:13:01 +0000714 vpi.vsi_id = adapter->vsi_res->vsi_id;
715 vpi.flags = flags;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700716 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
Greg Rose62683ab2013-12-21 06:13:01 +0000717 (u8 *)&vpi, sizeof(vpi));
718}
719
720/**
721 * i40evf_request_stats
722 * @adapter: adapter structure
723 *
724 * Request VSI statistics from PF.
725 **/
726void i40evf_request_stats(struct i40evf_adapter *adapter)
727{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700728 struct virtchnl_queue_select vqs;
Mitch Williams75a64432014-11-11 20:02:42 +0000729
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700730 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Greg Rose62683ab2013-12-21 06:13:01 +0000731 /* no error message, this isn't crucial */
732 return;
733 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700734 adapter->current_op = VIRTCHNL_OP_GET_STATS;
Greg Rose62683ab2013-12-21 06:13:01 +0000735 vqs.vsi_id = adapter->vsi_res->vsi_id;
736 /* queue maps are ignored for this message - only the vsi is used */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700737 if (i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS,
Greg Rose62683ab2013-12-21 06:13:01 +0000738 (u8 *)&vqs, sizeof(vqs)))
739 /* if the request failed, don't lock out others */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700740 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Greg Rose62683ab2013-12-21 06:13:01 +0000741}
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700742
743/**
744 * i40evf_get_hena
745 * @adapter: adapter structure
746 *
747 * Request hash enable capabilities from PF
748 **/
749void i40evf_get_hena(struct i40evf_adapter *adapter)
750{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700751 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700752 /* bail because we already have a command pending */
753 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
754 adapter->current_op);
755 return;
756 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700757 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700758 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700759 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700760 NULL, 0);
761}
762
763/**
764 * i40evf_set_hena
765 * @adapter: adapter structure
766 *
767 * Request the PF to set our RSS hash capabilities
768 **/
769void i40evf_set_hena(struct i40evf_adapter *adapter)
770{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700771 struct virtchnl_rss_hena vrh;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700772
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700773 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700774 /* bail because we already have a command pending */
775 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
776 adapter->current_op);
777 return;
778 }
779 vrh.hena = adapter->hena;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700780 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700781 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700782 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700783 (u8 *)&vrh, sizeof(vrh));
784}
785
786/**
787 * i40evf_set_rss_key
788 * @adapter: adapter structure
789 *
790 * Request the PF to set our RSS hash key
791 **/
792void i40evf_set_rss_key(struct i40evf_adapter *adapter)
793{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700794 struct virtchnl_rss_key *vrk;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700795 int len;
796
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700797 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700798 /* bail because we already have a command pending */
799 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
800 adapter->current_op);
801 return;
802 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700803 len = sizeof(struct virtchnl_rss_key) +
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700804 (adapter->rss_key_size * sizeof(u8)) - 1;
805 vrk = kzalloc(len, GFP_KERNEL);
806 if (!vrk)
807 return;
808 vrk->vsi_id = adapter->vsi.id;
809 vrk->key_len = adapter->rss_key_size;
810 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
811
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700812 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700813 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700814 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700815 (u8 *)vrk, len);
816 kfree(vrk);
817}
818
819/**
820 * i40evf_set_rss_lut
821 * @adapter: adapter structure
822 *
823 * Request the PF to set our RSS lookup table
824 **/
825void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
826{
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700827 struct virtchnl_rss_lut *vrl;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700828 int len;
829
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700830 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700831 /* bail because we already have a command pending */
832 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
833 adapter->current_op);
834 return;
835 }
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700836 len = sizeof(struct virtchnl_rss_lut) +
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700837 (adapter->rss_lut_size * sizeof(u8)) - 1;
838 vrl = kzalloc(len, GFP_KERNEL);
839 if (!vrl)
840 return;
841 vrl->vsi_id = adapter->vsi.id;
842 vrl->lut_entries = adapter->rss_lut_size;
843 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700844 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700845 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700846 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT,
Mitch Williams43a3d9b2016-04-12 08:30:44 -0700847 (u8 *)vrl, len);
848 kfree(vrl);
849}
850
Mitch Williams625777e2014-02-20 19:29:05 -0800851/**
Mariusz Stachura87743702017-07-17 22:09:45 -0700852 * i40evf_enable_vlan_stripping
853 * @adapter: adapter structure
854 *
855 * Request VLAN header stripping to be enabled
856 **/
857void i40evf_enable_vlan_stripping(struct i40evf_adapter *adapter)
858{
859 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
860 /* bail because we already have a command pending */
861 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
862 adapter->current_op);
863 return;
864 }
865 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
866 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
867 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
868 NULL, 0);
869}
870
871/**
872 * i40evf_disable_vlan_stripping
873 * @adapter: adapter structure
874 *
875 * Request VLAN header stripping to be disabled
876 **/
877void i40evf_disable_vlan_stripping(struct i40evf_adapter *adapter)
878{
879 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
880 /* bail because we already have a command pending */
881 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
882 adapter->current_op);
883 return;
884 }
885 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
886 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
887 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
888 NULL, 0);
889}
890
891/**
Mitch Williamsfe458e52016-08-04 11:37:02 -0700892 * i40evf_print_link_message - print link up or down
893 * @adapter: adapter structure
894 *
895 * Log a message telling the world of our wonderous link status
896 */
897static void i40evf_print_link_message(struct i40evf_adapter *adapter)
898{
899 struct net_device *netdev = adapter->netdev;
900 char *speed = "Unknown ";
901
902 if (!adapter->link_up) {
903 netdev_info(netdev, "NIC Link is Down\n");
904 return;
905 }
906
907 switch (adapter->link_speed) {
908 case I40E_LINK_SPEED_40GB:
909 speed = "40 G";
910 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800911 case I40E_LINK_SPEED_25GB:
912 speed = "25 G";
913 break;
Mitch Williamsfe458e52016-08-04 11:37:02 -0700914 case I40E_LINK_SPEED_20GB:
915 speed = "20 G";
916 break;
917 case I40E_LINK_SPEED_10GB:
918 speed = "10 G";
919 break;
920 case I40E_LINK_SPEED_1GB:
921 speed = "1000 M";
922 break;
923 case I40E_LINK_SPEED_100MB:
924 speed = "100 M";
925 break;
926 default:
927 break;
928 }
929
930 netdev_info(netdev, "NIC Link is Up %sbps Full Duplex\n", speed);
931}
932
933/**
Mitch Williams625777e2014-02-20 19:29:05 -0800934 * i40evf_request_reset
935 * @adapter: adapter structure
936 *
937 * Request that the PF reset this VF. No response is expected.
938 **/
939void i40evf_request_reset(struct i40evf_adapter *adapter)
940{
941 /* Don't check CURRENT_OP - this is always higher priority */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700942 i40evf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
943 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Mitch Williams625777e2014-02-20 19:29:05 -0800944}
Greg Rose62683ab2013-12-21 06:13:01 +0000945
946/**
947 * i40evf_virtchnl_completion
948 * @adapter: adapter structure
949 * @v_opcode: opcode sent by PF
950 * @v_retval: retval sent by PF
951 * @msg: message sent by PF
952 * @msglen: message length
953 *
954 * Asynchronous completion function for admin queue messages. Rather than busy
955 * wait, we fire off our requests and assume that no errors will be returned.
956 * This function handles the reply messages.
957 **/
958void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700959 enum virtchnl_ops v_opcode,
Greg Rose62683ab2013-12-21 06:13:01 +0000960 i40e_status v_retval,
961 u8 *msg, u16 msglen)
962{
963 struct net_device *netdev = adapter->netdev;
964
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700965 if (v_opcode == VIRTCHNL_OP_EVENT) {
966 struct virtchnl_pf_event *vpe =
967 (struct virtchnl_pf_event *)msg;
Greg Rose62683ab2013-12-21 06:13:01 +0000968 switch (vpe->event) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700969 case VIRTCHNL_EVENT_LINK_CHANGE:
Mitch Williamsfe458e52016-08-04 11:37:02 -0700970 adapter->link_speed =
971 vpe->event_data.link_event.link_speed;
972 if (adapter->link_up !=
973 vpe->event_data.link_event.link_status) {
974 adapter->link_up =
975 vpe->event_data.link_event.link_status;
Sridhar Samudrala3f341ac2016-09-01 22:27:27 +0200976 if (adapter->link_up) {
977 netif_tx_start_all_queues(netdev);
978 netif_carrier_on(netdev);
979 } else {
980 netif_tx_stop_all_queues(netdev);
981 netif_carrier_off(netdev);
982 }
Mitch Williamsfe458e52016-08-04 11:37:02 -0700983 i40evf_print_link_message(adapter);
Greg Rose62683ab2013-12-21 06:13:01 +0000984 }
985 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -0700986 case VIRTCHNL_EVENT_RESET_IMPENDING:
Mitch Williamsef8693e2014-02-13 03:48:53 -0800987 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
988 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
989 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
990 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
991 schedule_work(&adapter->reset_task);
992 }
Greg Rose62683ab2013-12-21 06:13:01 +0000993 break;
994 default:
Shannon Nelsonfb43201f2015-08-26 15:14:17 -0400995 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
996 vpe->event);
Greg Rose62683ab2013-12-21 06:13:01 +0000997 break;
Greg Rose62683ab2013-12-21 06:13:01 +0000998 }
999 return;
1000 }
Greg Rose62683ab2013-12-21 06:13:01 +00001001 if (v_retval) {
Mitch Williams8d8f2292015-10-21 19:47:11 -04001002 switch (v_opcode) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001003 case VIRTCHNL_OP_ADD_VLAN:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001004 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1005 i40evf_stat_str(&adapter->hw, v_retval));
1006 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001007 case VIRTCHNL_OP_ADD_ETH_ADDR:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001008 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1009 i40evf_stat_str(&adapter->hw, v_retval));
1010 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001011 case VIRTCHNL_OP_DEL_VLAN:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001012 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1013 i40evf_stat_str(&adapter->hw, v_retval));
1014 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001015 case VIRTCHNL_OP_DEL_ETH_ADDR:
Mitch Williams8d8f2292015-10-21 19:47:11 -04001016 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1017 i40evf_stat_str(&adapter->hw, v_retval));
1018 break;
1019 default:
1020 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
1021 v_retval,
1022 i40evf_stat_str(&adapter->hw, v_retval),
1023 v_opcode);
1024 }
Greg Rose62683ab2013-12-21 06:13:01 +00001025 }
1026 switch (v_opcode) {
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001027 case VIRTCHNL_OP_GET_STATS: {
Greg Rose62683ab2013-12-21 06:13:01 +00001028 struct i40e_eth_stats *stats =
1029 (struct i40e_eth_stats *)msg;
Tobias Klauser4a0a3ab2017-04-06 08:46:28 +02001030 netdev->stats.rx_packets = stats->rx_unicast +
1031 stats->rx_multicast +
1032 stats->rx_broadcast;
1033 netdev->stats.tx_packets = stats->tx_unicast +
1034 stats->tx_multicast +
1035 stats->tx_broadcast;
1036 netdev->stats.rx_bytes = stats->rx_bytes;
1037 netdev->stats.tx_bytes = stats->tx_bytes;
1038 netdev->stats.tx_errors = stats->tx_errors;
1039 netdev->stats.rx_dropped = stats->rx_discards;
1040 netdev->stats.tx_dropped = stats->tx_discards;
Greg Rose62683ab2013-12-21 06:13:01 +00001041 adapter->current_stats = *stats;
1042 }
1043 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001044 case VIRTCHNL_OP_GET_VF_RESOURCES: {
1045 u16 len = sizeof(struct virtchnl_vf_resource) +
Mitch Williamse6d038d2015-06-04 16:23:58 -04001046 I40E_MAX_VF_VSI *
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001047 sizeof(struct virtchnl_vsi_resource);
Mitch Williamse6d038d2015-06-04 16:23:58 -04001048 memcpy(adapter->vf_res, msg, min(msglen, len));
1049 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
Mitch Williams8552d852015-08-31 19:54:51 -04001050 /* restore current mac address */
1051 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
Mitch Williamse6d038d2015-06-04 16:23:58 -04001052 i40evf_process_config(adapter);
1053 }
1054 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001055 case VIRTCHNL_OP_ENABLE_QUEUES:
Greg Rose62683ab2013-12-21 06:13:01 +00001056 /* enable transmits */
1057 i40evf_irq_enable(adapter, true);
Greg Rose62683ab2013-12-21 06:13:01 +00001058 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001059 case VIRTCHNL_OP_DISABLE_QUEUES:
Mitch Williamse284fc82015-03-27 00:12:09 -07001060 i40evf_free_all_tx_resources(adapter);
1061 i40evf_free_all_rx_resources(adapter);
Sudheer Mogilappagarife2647a2017-06-23 04:24:44 -04001062 if (adapter->state == __I40EVF_DOWN_PENDING) {
Mitch Williams209dc4d2015-12-09 15:50:27 -08001063 adapter->state = __I40EVF_DOWN;
Sudheer Mogilappagarife2647a2017-06-23 04:24:44 -04001064 wake_up(&adapter->down_waitqueue);
1065 }
Greg Rose62683ab2013-12-21 06:13:01 +00001066 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001067 case VIRTCHNL_OP_VERSION:
1068 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
Mitch Williamsed636962015-04-07 19:45:32 -04001069 /* Don't display an error if we get these out of sequence.
1070 * If the firmware needed to get kicked, we'll get these and
1071 * it's no problem.
1072 */
1073 if (v_opcode != adapter->current_op)
1074 return;
Greg Rose62683ab2013-12-21 06:13:01 +00001075 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001076 case VIRTCHNL_OP_IWARP:
Mitch Williamsed0e8942017-01-24 10:23:59 -08001077 /* Gobble zero-length replies from the PF. They indicate that
1078 * a previous message was received OK, and the client doesn't
1079 * care about that.
1080 */
1081 if (msglen && CLIENT_ENABLED(adapter))
1082 i40evf_notify_client_message(&adapter->vsi,
1083 msg, msglen);
1084 break;
1085
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001086 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
Mitch Williamse5f77f42017-02-09 23:35:18 -08001087 adapter->client_pending &=
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001088 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
Mitch Williamse5f77f42017-02-09 23:35:18 -08001089 break;
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001090 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
Jesse Brandeburgf0adc6e2017-05-11 11:23:15 -07001091 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
Mitch Williams43a3d9b2016-04-12 08:30:44 -07001092 if (msglen == sizeof(*vrh))
1093 adapter->hena = vrh->hena;
1094 else
1095 dev_warn(&adapter->pdev->dev,
1096 "Invalid message %d from PF\n", v_opcode);
1097 }
1098 break;
Alan Brady5b36e8d2017-08-22 06:57:50 -04001099 case VIRTCHNL_OP_REQUEST_QUEUES: {
1100 struct virtchnl_vf_res_request *vfres =
1101 (struct virtchnl_vf_res_request *)msg;
Alan Brady17a94222017-10-11 14:49:43 -07001102 if (vfres->num_queue_pairs != adapter->num_req_queues) {
Alan Brady5b36e8d2017-08-22 06:57:50 -04001103 dev_info(&adapter->pdev->dev,
1104 "Requested %d queues, PF can support %d\n",
1105 adapter->num_req_queues,
1106 vfres->num_queue_pairs);
1107 adapter->num_req_queues = 0;
Alan Brady17a94222017-10-11 14:49:43 -07001108 adapter->flags &= ~I40EVF_FLAG_REINIT_ITR_NEEDED;
Alan Brady5b36e8d2017-08-22 06:57:50 -04001109 }
1110 }
1111 break;
Greg Rose62683ab2013-12-21 06:13:01 +00001112 default:
Mitch Williamsed0e8942017-01-24 10:23:59 -08001113 if (adapter->current_op && (v_opcode != adapter->current_op))
Mitch Williamsed636962015-04-07 19:45:32 -04001114 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1115 adapter->current_op, v_opcode);
Greg Rose62683ab2013-12-21 06:13:01 +00001116 break;
1117 } /* switch v_opcode */
Jesse Brandeburg310a2ad2017-05-11 11:23:11 -07001118 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
Greg Rose62683ab2013-12-21 06:13:01 +00001119}