ixgbe_vf.c revision 1.13 1 /* $NetBSD: ixgbe_vf.c,v 1.13 2017/08/30 08:49:18 msaitoh Exp $ */
2
3 /******************************************************************************
4
5 Copyright (c) 2001-2017, Intel Corporation
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13
14 2. Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17
18 3. Neither the name of the Intel Corporation nor the names of its
19 contributors may be used to endorse or promote products derived from
20 this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33
34 ******************************************************************************/
35 /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_vf.c 320688 2017-07-05 17:27:03Z erj $*/
36
37
38 #include "ixgbe_api.h"
39 #include "ixgbe_type.h"
40 #include "ixgbe_vf.h"
41
42 #ifndef IXGBE_VFWRITE_REG
43 #define IXGBE_VFWRITE_REG IXGBE_WRITE_REG
44 #endif
45 #ifndef IXGBE_VFREAD_REG
46 #define IXGBE_VFREAD_REG IXGBE_READ_REG
47 #endif
48
49 /**
50 * ixgbe_init_ops_vf - Initialize the pointers for vf
51 * @hw: pointer to hardware structure
52 *
53 * This will assign function pointers, adapter-specific functions can
54 * override the assignment of generic function pointers by assigning
55 * their own adapter-specific function pointers.
56 * Does not touch the hardware.
57 **/
58 s32 ixgbe_init_ops_vf(struct ixgbe_hw *hw)
59 {
60 /* MAC */
61 hw->mac.ops.init_hw = ixgbe_init_hw_vf;
62 hw->mac.ops.reset_hw = ixgbe_reset_hw_vf;
63 hw->mac.ops.start_hw = ixgbe_start_hw_vf;
64 /* Cannot clear stats on VF */
65 hw->mac.ops.clear_hw_cntrs = NULL;
66 hw->mac.ops.get_media_type = NULL;
67 hw->mac.ops.get_mac_addr = ixgbe_get_mac_addr_vf;
68 hw->mac.ops.stop_adapter = ixgbe_stop_adapter_vf;
69 hw->mac.ops.get_bus_info = NULL;
70 hw->mac.ops.negotiate_api_version = ixgbevf_negotiate_api_version;
71
72 /* Link */
73 hw->mac.ops.setup_link = ixgbe_setup_mac_link_vf;
74 hw->mac.ops.check_link = ixgbe_check_mac_link_vf;
75 hw->mac.ops.get_link_capabilities = NULL;
76
77 /* RAR, Multicast, VLAN */
78 hw->mac.ops.set_rar = ixgbe_set_rar_vf;
79 hw->mac.ops.set_uc_addr = ixgbevf_set_uc_addr_vf;
80 hw->mac.ops.init_rx_addrs = NULL;
81 hw->mac.ops.update_mc_addr_list = ixgbe_update_mc_addr_list_vf;
82 hw->mac.ops.update_xcast_mode = ixgbevf_update_xcast_mode;
83 hw->mac.ops.enable_mc = NULL;
84 hw->mac.ops.disable_mc = NULL;
85 hw->mac.ops.clear_vfta = NULL;
86 hw->mac.ops.set_vfta = ixgbe_set_vfta_vf;
87 hw->mac.ops.set_rlpml = ixgbevf_rlpml_set_vf;
88
89 hw->mac.max_tx_queues = 1;
90 hw->mac.max_rx_queues = 1;
91
92 hw->mbx.ops.init_params = ixgbe_init_mbx_params_vf;
93
94 return IXGBE_SUCCESS;
95 }
96
97 /* ixgbe_virt_clr_reg - Set register to default (power on) state.
98 * @hw: pointer to hardware structure
99 */
100 static void ixgbe_virt_clr_reg(struct ixgbe_hw *hw)
101 {
102 int i;
103 u32 vfsrrctl;
104 u32 vfdca_rxctrl;
105 u32 vfdca_txctrl;
106
107 /* VRSRRCTL default values (BSIZEPACKET = 2048, BSIZEHEADER = 256) */
108 vfsrrctl = 0x100 << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
109 vfsrrctl |= 0x800 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
110
111 /* DCA_RXCTRL default value */
112 vfdca_rxctrl = IXGBE_DCA_RXCTRL_DESC_RRO_EN |
113 IXGBE_DCA_RXCTRL_DATA_WRO_EN |
114 IXGBE_DCA_RXCTRL_HEAD_WRO_EN;
115
116 /* DCA_TXCTRL default value */
117 vfdca_txctrl = IXGBE_DCA_TXCTRL_DESC_RRO_EN |
118 IXGBE_DCA_TXCTRL_DESC_WRO_EN |
119 IXGBE_DCA_TXCTRL_DATA_RRO_EN;
120
121 IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, 0);
122
123 for (i = 0; i < 7; i++) {
124 IXGBE_WRITE_REG(hw, IXGBE_VFRDH(i), 0);
125 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(i), 0);
126 IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), 0);
127 IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(i), vfsrrctl);
128 IXGBE_WRITE_REG(hw, IXGBE_VFTDH(i), 0);
129 IXGBE_WRITE_REG(hw, IXGBE_VFTDT(i), 0);
130 IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(i), 0);
131 IXGBE_WRITE_REG(hw, IXGBE_VFTDWBAH(i), 0);
132 IXGBE_WRITE_REG(hw, IXGBE_VFTDWBAL(i), 0);
133 IXGBE_WRITE_REG(hw, IXGBE_VFDCA_RXCTRL(i), vfdca_rxctrl);
134 IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(i), vfdca_txctrl);
135 }
136
137 IXGBE_WRITE_FLUSH(hw);
138 }
139
140 /**
141 * ixgbe_start_hw_vf - Prepare hardware for Tx/Rx
142 * @hw: pointer to hardware structure
143 *
144 * Starts the hardware by filling the bus info structure and media type, clears
145 * all on chip counters, initializes receive address registers, multicast
146 * table, VLAN filter table, calls routine to set up link and flow control
147 * settings, and leaves transmit and receive units disabled and uninitialized
148 **/
149 s32 ixgbe_start_hw_vf(struct ixgbe_hw *hw)
150 {
151 /* Clear adapter stopped flag */
152 hw->adapter_stopped = FALSE;
153
154 return IXGBE_SUCCESS;
155 }
156
157 /**
158 * ixgbe_init_hw_vf - virtual function hardware initialization
159 * @hw: pointer to hardware structure
160 *
161 * Initialize the hardware by resetting the hardware and then starting
162 * the hardware
163 **/
164 s32 ixgbe_init_hw_vf(struct ixgbe_hw *hw)
165 {
166 s32 status = hw->mac.ops.start_hw(hw);
167
168 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
169
170 return status;
171 }
172
173 /**
174 * ixgbe_reset_hw_vf - Performs hardware reset
175 * @hw: pointer to hardware structure
176 *
177 * Resets the hardware by reseting the transmit and receive units, masks and
178 * clears all interrupts.
179 **/
180 s32 ixgbe_reset_hw_vf(struct ixgbe_hw *hw)
181 {
182 struct ixgbe_mbx_info *mbx = &hw->mbx;
183 u32 timeout = IXGBE_VF_INIT_TIMEOUT;
184 s32 ret_val = IXGBE_ERR_INVALID_MAC_ADDR;
185 u32 msgbuf[IXGBE_VF_PERMADDR_MSG_LEN];
186 u8 *addr = (u8 *)(&msgbuf[1]);
187
188 DEBUGFUNC("ixgbevf_reset_hw_vf");
189
190 /* Call adapter stop to disable tx/rx and clear interrupts */
191 hw->mac.ops.stop_adapter(hw);
192
193 /* reset the api version */
194 hw->api_version = ixgbe_mbox_api_10;
195
196 DEBUGOUT("Issuing a function level reset to MAC\n");
197
198 IXGBE_VFWRITE_REG(hw, IXGBE_VFCTRL, IXGBE_CTRL_RST);
199 IXGBE_WRITE_FLUSH(hw);
200
201 msec_delay(50);
202
203 /* we cannot reset while the RSTI / RSTD bits are asserted */
204 while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
205 timeout--;
206 usec_delay(5);
207 }
208
209 if (!timeout)
210 return IXGBE_ERR_RESET_FAILED;
211
212 /* Reset VF registers to initial values */
213 ixgbe_virt_clr_reg(hw);
214
215 /* mailbox timeout can now become active */
216 mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
217
218 msgbuf[0] = IXGBE_VF_RESET;
219 mbx->ops.write_posted(hw, msgbuf, 1, 0);
220
221 msec_delay(10);
222
223 /*
224 * set our "perm_addr" based on info provided by PF
225 * also set up the mc_filter_type which is piggy backed
226 * on the mac address in word 3
227 */
228 ret_val = mbx->ops.read_posted(hw, msgbuf,
229 IXGBE_VF_PERMADDR_MSG_LEN, 0);
230 if (ret_val)
231 return ret_val;
232
233 if (msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK) &&
234 msgbuf[0] != (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_NACK))
235 return IXGBE_ERR_INVALID_MAC_ADDR;
236
237 if (msgbuf[0] == (IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK))
238 memcpy(hw->mac.perm_addr, addr, IXGBE_ETH_LENGTH_OF_ADDRESS);
239
240 hw->mac.mc_filter_type = msgbuf[IXGBE_VF_MC_TYPE_WORD];
241
242 return ret_val;
243 }
244
245 /**
246 * ixgbe_stop_adapter_vf - Generic stop Tx/Rx units
247 * @hw: pointer to hardware structure
248 *
249 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
250 * disables transmit and receive units. The adapter_stopped flag is used by
251 * the shared code and drivers to determine if the adapter is in a stopped
252 * state and should not touch the hardware.
253 **/
254 s32 ixgbe_stop_adapter_vf(struct ixgbe_hw *hw)
255 {
256 u32 reg_val;
257 u16 i;
258
259 /*
260 * Set the adapter_stopped flag so other driver functions stop touching
261 * the hardware
262 */
263 hw->adapter_stopped = TRUE;
264
265 /* Clear interrupt mask to stop from interrupts being generated */
266 IXGBE_VFWRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
267
268 /* Clear any pending interrupts, flush previous writes */
269 IXGBE_VFREAD_REG(hw, IXGBE_VTEICR);
270
271 /* Disable the transmit unit. Each queue must be disabled. */
272 for (i = 0; i < hw->mac.max_tx_queues; i++)
273 IXGBE_VFWRITE_REG(hw, IXGBE_VFTXDCTL(i), IXGBE_TXDCTL_SWFLSH);
274
275 /* Disable the receive unit by stopping each queue */
276 for (i = 0; i < hw->mac.max_rx_queues; i++) {
277 reg_val = IXGBE_VFREAD_REG(hw, IXGBE_VFRXDCTL(i));
278 reg_val &= ~IXGBE_RXDCTL_ENABLE;
279 IXGBE_VFWRITE_REG(hw, IXGBE_VFRXDCTL(i), reg_val);
280 }
281 /* Clear packet split and pool config */
282 IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, 0);
283
284 /* flush all queues disables */
285 IXGBE_WRITE_FLUSH(hw);
286 msec_delay(2);
287
288 return IXGBE_SUCCESS;
289 }
290
291 /**
292 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
293 * @hw: pointer to hardware structure
294 * @mc_addr: the multicast address
295 *
296 * Extracts the 12 bits, from a multicast address, to determine which
297 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
298 * incoming rx multicast addresses, to determine the bit-vector to check in
299 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
300 * by the MO field of the MCSTCTRL. The MO field is set during initialization
301 * to mc_filter_type.
302 **/
303 static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
304 {
305 u32 vector = 0;
306
307 switch (hw->mac.mc_filter_type) {
308 case 0: /* use bits [47:36] of the address */
309 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
310 break;
311 case 1: /* use bits [46:35] of the address */
312 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
313 break;
314 case 2: /* use bits [45:34] of the address */
315 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
316 break;
317 case 3: /* use bits [43:32] of the address */
318 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
319 break;
320 default: /* Invalid mc_filter_type */
321 DEBUGOUT("MC filter type param set incorrectly\n");
322 ASSERT(0);
323 break;
324 }
325
326 /* vector can only be 12-bits or boundary will be exceeded */
327 vector &= 0xFFF;
328 return vector;
329 }
330
331 static s32 ixgbevf_write_msg_read_ack(struct ixgbe_hw *hw, u32 *msg,
332 u32 *retmsg, u16 size)
333 {
334 struct ixgbe_mbx_info *mbx = &hw->mbx;
335 s32 retval = mbx->ops.write_posted(hw, msg, size, 0);
336
337 if (retval)
338 return retval;
339
340 return mbx->ops.read_posted(hw, retmsg, size, 0);
341 }
342
343 /**
344 * ixgbe_set_rar_vf - set device MAC address
345 * @hw: pointer to hardware structure
346 * @index: Receive address register to write
347 * @addr: Address to put into receive address register
348 * @vmdq: VMDq "set" or "pool" index
349 * @enable_addr: set flag that address is active
350 **/
351 s32 ixgbe_set_rar_vf(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
352 u32 enable_addr)
353 {
354 u32 msgbuf[3];
355 u8 *msg_addr = (u8 *)(&msgbuf[1]);
356 s32 ret_val;
357 UNREFERENCED_3PARAMETER(vmdq, enable_addr, index);
358
359 memset(msgbuf, 0, 12);
360 msgbuf[0] = IXGBE_VF_SET_MAC_ADDR;
361 memcpy(msg_addr, addr, 6);
362 ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
363
364 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
365
366 /* if nacked the address was rejected, use "perm_addr" */
367 if (!ret_val &&
368 (msgbuf[0] == (IXGBE_VF_SET_MAC_ADDR | IXGBE_VT_MSGTYPE_NACK))) {
369 ixgbe_get_mac_addr_vf(hw, hw->mac.addr);
370 return IXGBE_ERR_MBX;
371 }
372
373 return ret_val;
374 }
375
376 /**
377 * ixgbe_update_mc_addr_list_vf - Update Multicast addresses
378 * @hw: pointer to the HW structure
379 * @mc_addr_list: array of multicast addresses to program
380 * @mc_addr_count: number of multicast addresses to program
381 * @next: caller supplied function to return next address in list
382 *
383 * Updates the Multicast Table Array.
384 **/
385 s32 ixgbe_update_mc_addr_list_vf(struct ixgbe_hw *hw, u8 *mc_addr_list,
386 u32 mc_addr_count, ixgbe_mc_addr_itr next,
387 bool clear)
388 {
389 struct ixgbe_mbx_info *mbx = &hw->mbx;
390 u32 msgbuf[IXGBE_VFMAILBOX_SIZE];
391 u16 *vector_list = (u16 *)&msgbuf[1];
392 u32 vector;
393 u32 cnt, i;
394 u32 vmdq;
395
396 UNREFERENCED_1PARAMETER(clear);
397
398 DEBUGFUNC("ixgbe_update_mc_addr_list_vf");
399
400 /* Each entry in the list uses 1 16 bit word. We have 30
401 * 16 bit words available in our HW msg buffer (minus 1 for the
402 * msg type). That's 30 hash values if we pack 'em right. If
403 * there are more than 30 MC addresses to add then punt the
404 * extras for now and then add code to handle more than 30 later.
405 * It would be unusual for a server to request that many multi-cast
406 * addresses except for in large enterprise network environments.
407 */
408
409 DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
410
411 cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
412 msgbuf[0] = IXGBE_VF_SET_MULTICAST;
413 msgbuf[0] |= cnt << IXGBE_VT_MSGINFO_SHIFT;
414
415 for (i = 0; i < cnt; i++) {
416 vector = ixgbe_mta_vector(hw, next(hw, &mc_addr_list, &vmdq));
417 DEBUGOUT1("Hash value = 0x%03X\n", vector);
418 vector_list[i] = (u16)vector;
419 }
420
421 return mbx->ops.write_posted(hw, msgbuf, IXGBE_VFMAILBOX_SIZE, 0);
422 }
423
424 /**
425 * ixgbevf_update_xcast_mode - Update Multicast mode
426 * @hw: pointer to the HW structure
427 * @xcast_mode: new multicast mode
428 *
429 * Updates the Multicast Mode of VF.
430 **/
431 s32 ixgbevf_update_xcast_mode(struct ixgbe_hw *hw, int xcast_mode)
432 {
433 u32 msgbuf[2];
434 s32 err;
435
436 switch (hw->api_version) {
437 case ixgbe_mbox_api_12:
438 /* New modes were introduced in 1.3 version */
439 if (xcast_mode > IXGBEVF_XCAST_MODE_ALLMULTI)
440 return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
441 /* Fall through */
442 case ixgbe_mbox_api_13:
443 break;
444 default:
445 return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
446 }
447
448 msgbuf[0] = IXGBE_VF_UPDATE_XCAST_MODE;
449 msgbuf[1] = xcast_mode;
450
451 err = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
452 if (err)
453 return err;
454
455 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
456 if (msgbuf[0] == (IXGBE_VF_UPDATE_XCAST_MODE | IXGBE_VT_MSGTYPE_NACK))
457 return IXGBE_ERR_FEATURE_NOT_SUPPORTED;
458 return IXGBE_SUCCESS;
459 }
460
461 /**
462 * ixgbe_set_vfta_vf - Set/Unset vlan filter table address
463 * @hw: pointer to the HW structure
464 * @vlan: 12 bit VLAN ID
465 * @vind: unused by VF drivers
466 * @vlan_on: if TRUE then set bit, else clear bit
467 * @vlvf_bypass: boolean flag indicating updating default pool is okay
468 *
469 * Turn on/off specified VLAN in the VLAN filter table.
470 **/
471 s32 ixgbe_set_vfta_vf(struct ixgbe_hw *hw, u32 vlan, u32 vind,
472 bool vlan_on, bool vlvf_bypass)
473 {
474 u32 msgbuf[2];
475 s32 ret_val;
476 UNREFERENCED_2PARAMETER(vind, vlvf_bypass);
477
478 msgbuf[0] = IXGBE_VF_SET_VLAN;
479 msgbuf[1] = vlan;
480 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
481 msgbuf[0] |= (u32)vlan_on << IXGBE_VT_MSGINFO_SHIFT;
482
483 ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
484 if (!ret_val && (msgbuf[0] & IXGBE_VT_MSGTYPE_ACK))
485 return IXGBE_SUCCESS;
486
487 return ret_val | (msgbuf[0] & IXGBE_VT_MSGTYPE_NACK);
488 }
489
490 /**
491 * ixgbe_get_num_of_tx_queues_vf - Get number of TX queues
492 * @hw: pointer to hardware structure
493 *
494 * Returns the number of transmit queues for the given adapter.
495 **/
496 u32 ixgbe_get_num_of_tx_queues_vf(struct ixgbe_hw *hw)
497 {
498 UNREFERENCED_1PARAMETER(hw);
499 return IXGBE_VF_MAX_TX_QUEUES;
500 }
501
502 /**
503 * ixgbe_get_num_of_rx_queues_vf - Get number of RX queues
504 * @hw: pointer to hardware structure
505 *
506 * Returns the number of receive queues for the given adapter.
507 **/
508 u32 ixgbe_get_num_of_rx_queues_vf(struct ixgbe_hw *hw)
509 {
510 UNREFERENCED_1PARAMETER(hw);
511 return IXGBE_VF_MAX_RX_QUEUES;
512 }
513
514 /**
515 * ixgbe_get_mac_addr_vf - Read device MAC address
516 * @hw: pointer to the HW structure
517 **/
518 s32 ixgbe_get_mac_addr_vf(struct ixgbe_hw *hw, u8 *mac_addr)
519 {
520 int i;
521
522 for (i = 0; i < IXGBE_ETH_LENGTH_OF_ADDRESS; i++)
523 mac_addr[i] = hw->mac.perm_addr[i];
524
525 return IXGBE_SUCCESS;
526 }
527
528 s32 ixgbevf_set_uc_addr_vf(struct ixgbe_hw *hw, u32 index, u8 *addr)
529 {
530 u32 msgbuf[3], msgbuf_chk;
531 u8 *msg_addr = (u8 *)(&msgbuf[1]);
532 s32 ret_val;
533
534 memset(msgbuf, 0, sizeof(msgbuf));
535 /*
536 * If index is one then this is the start of a new list and needs
537 * indication to the PF so it can do it's own list management.
538 * If it is zero then that tells the PF to just clear all of
539 * this VF's macvlans and there is no new list.
540 */
541 msgbuf[0] |= index << IXGBE_VT_MSGINFO_SHIFT;
542 msgbuf[0] |= IXGBE_VF_SET_MACVLAN;
543 msgbuf_chk = msgbuf[0];
544 if (addr)
545 memcpy(msg_addr, addr, 6);
546
547 ret_val = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
548 if (!ret_val) {
549 msgbuf[0] &= ~IXGBE_VT_MSGTYPE_CTS;
550
551 if (msgbuf[0] == (msgbuf_chk | IXGBE_VT_MSGTYPE_NACK))
552 return IXGBE_ERR_OUT_OF_MEM;
553 }
554
555 return ret_val;
556 }
557
558 /**
559 * ixgbe_setup_mac_link_vf - Setup MAC link settings
560 * @hw: pointer to hardware structure
561 * @speed: new link speed
562 * @autoneg: TRUE if autonegotiation enabled
563 * @autoneg_wait_to_complete: TRUE when waiting for completion is needed
564 *
565 * Set the link speed in the AUTOC register and restarts link.
566 **/
567 s32 ixgbe_setup_mac_link_vf(struct ixgbe_hw *hw, ixgbe_link_speed speed,
568 bool autoneg_wait_to_complete)
569 {
570 UNREFERENCED_3PARAMETER(hw, speed, autoneg_wait_to_complete);
571 return IXGBE_SUCCESS;
572 }
573
574 /**
575 * ixgbe_check_mac_link_vf - Get link/speed status
576 * @hw: pointer to hardware structure
577 * @speed: pointer to link speed
578 * @link_up: TRUE is link is up, FALSE otherwise
579 * @autoneg_wait_to_complete: TRUE when waiting for completion is needed
580 *
581 * Reads the links register to determine if link is up and the current speed
582 **/
583 s32 ixgbe_check_mac_link_vf(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
584 bool *link_up, bool autoneg_wait_to_complete)
585 {
586 struct ixgbe_mbx_info *mbx = &hw->mbx;
587 struct ixgbe_mac_info *mac = &hw->mac;
588 s32 ret_val = IXGBE_SUCCESS;
589 u32 links_reg;
590 u32 in_msg = 0;
591 UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
592
593 /* If we were hit with a reset drop the link */
594 if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
595 mac->get_link_status = TRUE;
596
597 if (!mac->get_link_status)
598 goto out;
599
600 /* if link status is down no point in checking to see if pf is up */
601 links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
602 if (!(links_reg & IXGBE_LINKS_UP))
603 goto out;
604
605 /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
606 * before the link status is correct
607 */
608 if (mac->type == ixgbe_mac_82599_vf) {
609 int i;
610
611 for (i = 0; i < 5; i++) {
612 usec_delay(100);
613 links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
614
615 if (!(links_reg & IXGBE_LINKS_UP))
616 goto out;
617 }
618 }
619
620 switch (links_reg & IXGBE_LINKS_SPEED_82599) {
621 case IXGBE_LINKS_SPEED_10G_82599:
622 *speed = IXGBE_LINK_SPEED_10GB_FULL;
623 if (hw->mac.type >= ixgbe_mac_X550) {
624 if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
625 *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
626 }
627 break;
628 case IXGBE_LINKS_SPEED_1G_82599:
629 *speed = IXGBE_LINK_SPEED_1GB_FULL;
630 break;
631 case IXGBE_LINKS_SPEED_100_82599:
632 *speed = IXGBE_LINK_SPEED_100_FULL;
633 if (hw->mac.type == ixgbe_mac_X550) {
634 if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
635 *speed = IXGBE_LINK_SPEED_5GB_FULL;
636 }
637 break;
638 case IXGBE_LINKS_SPEED_10_X550EM_A:
639 *speed = IXGBE_LINK_SPEED_UNKNOWN;
640 /* Since Reserved in older MAC's */
641 if (hw->mac.type >= ixgbe_mac_X550)
642 *speed = IXGBE_LINK_SPEED_10_FULL;
643 break;
644 default:
645 *speed = IXGBE_LINK_SPEED_UNKNOWN;
646 }
647
648 /* if the read failed it could just be a mailbox collision, best wait
649 * until we are called again and don't report an error
650 */
651 if (mbx->ops.read(hw, &in_msg, 1, 0))
652 goto out;
653
654 if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
655 /* msg is not CTS and is NACK we must have lost CTS status */
656 if (in_msg & IXGBE_VT_MSGTYPE_NACK)
657 ret_val = -1;
658 goto out;
659 }
660
661 /* the pf is talking, if we timed out in the past we reinit */
662 if (!mbx->timeout) {
663 ret_val = -1;
664 goto out;
665 }
666
667 /* if we passed all the tests above then the link is up and we no
668 * longer need to check for link
669 */
670 mac->get_link_status = FALSE;
671
672 out:
673 *link_up = !mac->get_link_status;
674 return ret_val;
675 }
676
677 /**
678 * ixgbevf_rlpml_set_vf - Set the maximum receive packet length
679 * @hw: pointer to the HW structure
680 * @max_size: value to assign to max frame size
681 **/
682 s32 ixgbevf_rlpml_set_vf(struct ixgbe_hw *hw, u16 max_size)
683 {
684 u32 msgbuf[2];
685 s32 retval;
686
687 msgbuf[0] = IXGBE_VF_SET_LPE;
688 msgbuf[1] = max_size;
689
690 retval = ixgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
691 if (retval)
692 return retval;
693 if ((msgbuf[0] & IXGBE_VF_SET_LPE) &&
694 (msgbuf[0] & IXGBE_VT_MSGTYPE_NACK))
695 return IXGBE_ERR_MBX;
696
697 return 0;
698 }
699
700 /**
701 * ixgbevf_negotiate_api_version - Negotiate supported API version
702 * @hw: pointer to the HW structure
703 * @api: integer containing requested API version
704 **/
705 int ixgbevf_negotiate_api_version(struct ixgbe_hw *hw, int api)
706 {
707 int err;
708 u32 msg[3];
709
710 /* Negotiate the mailbox API version */
711 msg[0] = IXGBE_VF_API_NEGOTIATE;
712 msg[1] = api;
713 msg[2] = 0;
714
715 err = ixgbevf_write_msg_read_ack(hw, msg, msg, 3);
716 if (!err) {
717 msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
718
719 /* Store value and return 0 on success */
720 if (msg[0] == (IXGBE_VF_API_NEGOTIATE | IXGBE_VT_MSGTYPE_ACK)) {
721 hw->api_version = api;
722 return 0;
723 }
724
725 err = IXGBE_ERR_INVALID_ARGUMENT;
726 }
727
728 return err;
729 }
730
731 int ixgbevf_get_queues(struct ixgbe_hw *hw, unsigned int *num_tcs,
732 unsigned int *default_tc)
733 {
734 int err;
735 u32 msg[5];
736
737 /* do nothing if API doesn't support ixgbevf_get_queues */
738 switch (hw->api_version) {
739 case ixgbe_mbox_api_11:
740 case ixgbe_mbox_api_12:
741 case ixgbe_mbox_api_13:
742 break;
743 default:
744 return 0;
745 }
746
747 /* Fetch queue configuration from the PF */
748 msg[0] = IXGBE_VF_GET_QUEUES;
749 msg[1] = msg[2] = msg[3] = msg[4] = 0;
750
751 err = ixgbevf_write_msg_read_ack(hw, msg, msg, 5);
752 if (!err) {
753 msg[0] &= ~IXGBE_VT_MSGTYPE_CTS;
754
755 /*
756 * if we we didn't get an ACK there must have been
757 * some sort of mailbox error so we should treat it
758 * as such
759 */
760 if (msg[0] != (IXGBE_VF_GET_QUEUES | IXGBE_VT_MSGTYPE_ACK))
761 return IXGBE_ERR_MBX;
762
763 /* record and validate values from message */
764 hw->mac.max_tx_queues = msg[IXGBE_VF_TX_QUEUES];
765 if (hw->mac.max_tx_queues == 0 ||
766 hw->mac.max_tx_queues > IXGBE_VF_MAX_TX_QUEUES)
767 hw->mac.max_tx_queues = IXGBE_VF_MAX_TX_QUEUES;
768
769 hw->mac.max_rx_queues = msg[IXGBE_VF_RX_QUEUES];
770 if (hw->mac.max_rx_queues == 0 ||
771 hw->mac.max_rx_queues > IXGBE_VF_MAX_RX_QUEUES)
772 hw->mac.max_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
773
774 *num_tcs = msg[IXGBE_VF_TRANS_VLAN];
775 /* in case of unknown state assume we cannot tag frames */
776 if (*num_tcs > hw->mac.max_rx_queues)
777 *num_tcs = 1;
778
779 *default_tc = msg[IXGBE_VF_DEF_QUEUE];
780 /* default to queue 0 on out-of-bounds queue number */
781 if (*default_tc >= hw->mac.max_tx_queues)
782 *default_tc = 0;
783 }
784
785 return err;
786 }
787