net/hns3: fix typos on comments
[dpdk.git] / drivers / net / txgbe / base / txgbe_vf.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020
3  */
4
5 #include "txgbe_mbx.h"
6 #include "txgbe_vf.h"
7
8 /**
9  *  txgbe_init_ops_vf - Initialize the pointers for vf
10  *  @hw: pointer to hardware structure
11  *
12  *  This will assign function pointers, adapter-specific functions can
13  *  override the assignment of generic function pointers by assigning
14  *  their own adapter-specific function pointers.
15  *  Does not touch the hardware.
16  **/
17 s32 txgbe_init_ops_vf(struct txgbe_hw *hw)
18 {
19         struct txgbe_mac_info *mac = &hw->mac;
20         struct txgbe_mbx_info *mbx = &hw->mbx;
21
22         /* MAC */
23         mac->reset_hw = txgbe_reset_hw_vf;
24         mac->start_hw = txgbe_start_hw_vf;
25         /* Cannot clear stats on VF */
26         mac->get_mac_addr = txgbe_get_mac_addr_vf;
27         mac->stop_hw = txgbe_stop_hw_vf;
28         mac->negotiate_api_version = txgbevf_negotiate_api_version;
29         mac->update_mc_addr_list = txgbe_update_mc_addr_list_vf;
30
31         /* Link */
32         mac->check_link = txgbe_check_mac_link_vf;
33
34         /* RAR, Multicast, VLAN */
35         mac->set_rar = txgbe_set_rar_vf;
36         mac->set_uc_addr = txgbevf_set_uc_addr_vf;
37         mac->update_xcast_mode = txgbevf_update_xcast_mode;
38         mac->set_vfta = txgbe_set_vfta_vf;
39         mac->set_rlpml = txgbevf_rlpml_set_vf;
40
41         mac->max_tx_queues = 1;
42         mac->max_rx_queues = 1;
43
44         mbx->init_params = txgbe_init_mbx_params_vf;
45         mbx->read = txgbe_read_mbx_vf;
46         mbx->write = txgbe_write_mbx_vf;
47         mbx->read_posted = txgbe_read_posted_mbx;
48         mbx->write_posted = txgbe_write_posted_mbx;
49         mbx->check_for_msg = txgbe_check_for_msg_vf;
50         mbx->check_for_ack = txgbe_check_for_ack_vf;
51         mbx->check_for_rst = txgbe_check_for_rst_vf;
52
53         return 0;
54 }
55
56 /* txgbe_virt_clr_reg - Set register to default (power on) state.
57  * @hw: pointer to hardware structure
58  */
59 static void txgbe_virt_clr_reg(struct txgbe_hw *hw)
60 {
61         int i;
62         u32 vfsrrctl;
63
64         /* default values (BUF_SIZE = 2048, HDR_SIZE = 256) */
65         vfsrrctl = TXGBE_RXCFG_HDRLEN(TXGBE_RX_HDR_SIZE);
66         vfsrrctl |= TXGBE_RXCFG_PKTLEN(TXGBE_RX_BUF_SIZE);
67
68         for (i = 0; i < 8; i++) {
69                 wr32m(hw, TXGBE_RXCFG(i),
70                         (TXGBE_RXCFG_HDRLEN_MASK | TXGBE_RXCFG_PKTLEN_MASK),
71                         vfsrrctl);
72         }
73
74         txgbe_flush(hw);
75 }
76
77 /**
78  *  txgbe_start_hw_vf - Prepare hardware for Tx/Rx
79  *  @hw: pointer to hardware structure
80  *
81  *  Starts the hardware by filling the bus info structure and media type, clears
82  *  all on chip counters, initializes receive address registers, multicast
83  *  table, VLAN filter table, calls routine to set up link and flow control
84  *  settings, and leaves transmit and receive units disabled and uninitialized
85  **/
86 s32 txgbe_start_hw_vf(struct txgbe_hw *hw)
87 {
88         /* Clear adapter stopped flag */
89         hw->adapter_stopped = false;
90
91         return 0;
92 }
93
94 /**
95  *  txgbe_reset_hw_vf - Performs hardware reset
96  *  @hw: pointer to hardware structure
97  *
98  *  Resets the hardware by resetting the transmit and receive units, masks and
99  *  clears all interrupts.
100  **/
101 s32 txgbe_reset_hw_vf(struct txgbe_hw *hw)
102 {
103         struct txgbe_mbx_info *mbx = &hw->mbx;
104         u32 timeout = TXGBE_VF_INIT_TIMEOUT;
105         s32 ret_val = TXGBE_ERR_INVALID_MAC_ADDR;
106         u32 msgbuf[TXGBE_VF_PERMADDR_MSG_LEN];
107         u8 *addr = (u8 *)(&msgbuf[1]);
108
109         DEBUGFUNC("txgbevf_reset_hw_vf");
110
111         /* Call adapter stop to disable tx/rx and clear interrupts */
112         hw->mac.stop_hw(hw);
113
114         /* reset the api version */
115         hw->api_version = txgbe_mbox_api_10;
116
117         /* backup msix vectors */
118         mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
119         msgbuf[0] = TXGBE_VF_BACKUP;
120         mbx->write_posted(hw, msgbuf, 1, 0);
121         msec_delay(10);
122
123         DEBUGOUT("Issuing a function level reset to MAC\n");
124         wr32(hw, TXGBE_VFRST, TXGBE_VFRST_SET);
125         txgbe_flush(hw);
126         msec_delay(50);
127
128         hw->offset_loaded = 1;
129
130         /* we cannot reset while the RSTI / RSTD bits are asserted */
131         while (!mbx->check_for_rst(hw, 0) && timeout) {
132                 timeout--;
133                 /* if it doesn't work, try in 1 ms */
134                 usec_delay(5);
135         }
136
137         if (!timeout)
138                 return TXGBE_ERR_RESET_FAILED;
139
140         /* Reset VF registers to initial values */
141         txgbe_virt_clr_reg(hw);
142
143         /* mailbox timeout can now become active */
144         mbx->timeout = TXGBE_VF_MBX_INIT_TIMEOUT;
145
146         msgbuf[0] = TXGBE_VF_RESET;
147         mbx->write_posted(hw, msgbuf, 1, 0);
148
149         msec_delay(10);
150
151         /*
152          * set our "perm_addr" based on info provided by PF
153          * also set up the mc_filter_type which is piggy backed
154          * on the mac address in word 3
155          */
156         ret_val = mbx->read_posted(hw, msgbuf,
157                         TXGBE_VF_PERMADDR_MSG_LEN, 0);
158         if (ret_val)
159                 return ret_val;
160
161         if (msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK) &&
162             msgbuf[0] != (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_NACK))
163                 return TXGBE_ERR_INVALID_MAC_ADDR;
164
165         if (msgbuf[0] == (TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK))
166                 memcpy(hw->mac.perm_addr, addr, ETH_ADDR_LEN);
167
168         hw->mac.mc_filter_type = msgbuf[TXGBE_VF_MC_TYPE_WORD];
169
170         return ret_val;
171 }
172
173 /**
174  *  txgbe_stop_hw_vf - Generic stop Tx/Rx units
175  *  @hw: pointer to hardware structure
176  *
177  *  Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
178  *  disables transmit and receive units. The adapter_stopped flag is used by
179  *  the shared code and drivers to determine if the adapter is in a stopped
180  *  state and should not touch the hardware.
181  **/
182 s32 txgbe_stop_hw_vf(struct txgbe_hw *hw)
183 {
184         u16 i;
185
186         /*
187          * Set the adapter_stopped flag so other driver functions stop touching
188          * the hardware
189          */
190         hw->adapter_stopped = true;
191
192         /* Clear interrupt mask to stop from interrupts being generated */
193         wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
194
195         /* Clear any pending interrupts, flush previous writes */
196         wr32(hw, TXGBE_VFICR, TXGBE_VFICR_MASK);
197
198         /* Disable the transmit unit.  Each queue must be disabled. */
199         for (i = 0; i < hw->mac.max_tx_queues; i++)
200                 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
201
202         /* Disable the receive unit by stopping each queue */
203         for (i = 0; i < hw->mac.max_rx_queues; i++)
204                 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, 0);
205
206         /* Clear packet split and pool config */
207         wr32(hw, TXGBE_VFPLCFG, 0);
208         hw->rx_loaded = 1;
209
210         /* flush all queues disables */
211         txgbe_flush(hw);
212         msec_delay(2);
213
214         return 0;
215 }
216
217 /**
218  *  txgbe_mta_vector - Determines bit-vector in multicast table to set
219  *  @hw: pointer to hardware structure
220  *  @mc_addr: the multicast address
221  **/
222 STATIC s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr)
223 {
224         u32 vector = 0;
225
226         switch (hw->mac.mc_filter_type) {
227         case 0:   /* use bits [47:36] of the address */
228                 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
229                 break;
230         case 1:   /* use bits [46:35] of the address */
231                 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
232                 break;
233         case 2:   /* use bits [45:34] of the address */
234                 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
235                 break;
236         case 3:   /* use bits [43:32] of the address */
237                 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
238                 break;
239         default:  /* Invalid mc_filter_type */
240                 DEBUGOUT("MC filter type param set incorrectly\n");
241                 ASSERT(0);
242                 break;
243         }
244
245         /* vector can only be 12-bits or boundary will be exceeded */
246         vector &= 0xFFF;
247         return vector;
248 }
249
250 STATIC s32 txgbevf_write_msg_read_ack(struct txgbe_hw *hw, u32 *msg,
251                                       u32 *retmsg, u16 size)
252 {
253         struct txgbe_mbx_info *mbx = &hw->mbx;
254         s32 retval = mbx->write_posted(hw, msg, size, 0);
255
256         if (retval)
257                 return retval;
258
259         return mbx->read_posted(hw, retmsg, size, 0);
260 }
261
262 /**
263  *  txgbe_set_rar_vf - set device MAC address
264  *  @hw: pointer to hardware structure
265  *  @index: Receive address register to write
266  *  @addr: Address to put into receive address register
267  *  @vmdq: VMDq "set" or "pool" index
268  *  @enable_addr: set flag that address is active
269  **/
270 s32 txgbe_set_rar_vf(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
271                      u32 enable_addr)
272 {
273         u32 msgbuf[3];
274         u8 *msg_addr = (u8 *)(&msgbuf[1]);
275         s32 ret_val;
276         UNREFERENCED_PARAMETER(vmdq, enable_addr, index);
277
278         memset(msgbuf, 0, 12);
279         msgbuf[0] = TXGBE_VF_SET_MAC_ADDR;
280         memcpy(msg_addr, addr, 6);
281         ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
282
283         msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
284
285         /* if nacked the address was rejected, use "perm_addr" */
286         if (!ret_val &&
287             (msgbuf[0] == (TXGBE_VF_SET_MAC_ADDR | TXGBE_VT_MSGTYPE_NACK))) {
288                 txgbe_get_mac_addr_vf(hw, hw->mac.addr);
289                 return TXGBE_ERR_MBX;
290         }
291
292         return ret_val;
293 }
294
295 /**
296  *  txgbe_update_mc_addr_list_vf - Update Multicast addresses
297  *  @hw: pointer to the HW structure
298  *  @mc_addr_list: array of multicast addresses to program
299  *  @mc_addr_count: number of multicast addresses to program
300  *  @next: caller supplied function to return next address in list
301  *  @clear: unused
302  *
303  *  Updates the Multicast Table Array.
304  **/
305 s32 txgbe_update_mc_addr_list_vf(struct txgbe_hw *hw, u8 *mc_addr_list,
306                                  u32 mc_addr_count, txgbe_mc_addr_itr next,
307                                  bool clear)
308 {
309         struct txgbe_mbx_info *mbx = &hw->mbx;
310         u32 msgbuf[TXGBE_P2VMBX_SIZE];
311         u16 *vector_list = (u16 *)&msgbuf[1];
312         u32 vector;
313         u32 cnt, i;
314         u32 vmdq;
315
316         UNREFERENCED_PARAMETER(clear);
317
318         DEBUGFUNC("txgbe_update_mc_addr_list_vf");
319
320         /* Each entry in the list uses 1 16 bit word.  We have 30
321          * 16 bit words available in our HW msg buffer (minus 1 for the
322          * msg type).  That's 30 hash values if we pack 'em right.  If
323          * there are more than 30 MC addresses to add then punt the
324          * extras for now and then add code to handle more than 30 later.
325          * It would be unusual for a server to request that many multi-cast
326          * addresses except for in large enterprise network environments.
327          */
328
329         DEBUGOUT("MC Addr Count = %d\n", mc_addr_count);
330
331         cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
332         msgbuf[0] = TXGBE_VF_SET_MULTICAST;
333         msgbuf[0] |= cnt << TXGBE_VT_MSGINFO_SHIFT;
334
335         for (i = 0; i < cnt; i++) {
336                 vector = txgbe_mta_vector(hw, next(hw, &mc_addr_list, &vmdq));
337                 DEBUGOUT("Hash value = 0x%03X\n", vector);
338                 vector_list[i] = (u16)vector;
339         }
340
341         return mbx->write_posted(hw, msgbuf, TXGBE_P2VMBX_SIZE, 0);
342 }
343
344 /**
345  *  txgbevf_update_xcast_mode - Update Multicast mode
346  *  @hw: pointer to the HW structure
347  *  @xcast_mode: new multicast mode
348  *
349  *  Updates the Multicast Mode of VF.
350  **/
351 s32 txgbevf_update_xcast_mode(struct txgbe_hw *hw, int xcast_mode)
352 {
353         u32 msgbuf[2];
354         s32 err;
355
356         switch (hw->api_version) {
357         case txgbe_mbox_api_12:
358                 /* New modes were introduced in 1.3 version */
359                 if (xcast_mode > TXGBEVF_XCAST_MODE_ALLMULTI)
360                         return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
361                 /* Fall through */
362         case txgbe_mbox_api_13:
363                 break;
364         default:
365                 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
366         }
367
368         msgbuf[0] = TXGBE_VF_UPDATE_XCAST_MODE;
369         msgbuf[1] = xcast_mode;
370
371         err = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
372         if (err)
373                 return err;
374
375         msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
376         if (msgbuf[0] == (TXGBE_VF_UPDATE_XCAST_MODE | TXGBE_VT_MSGTYPE_NACK))
377                 return TXGBE_ERR_FEATURE_NOT_SUPPORTED;
378         return 0;
379 }
380
381 /**
382  *  txgbe_set_vfta_vf - Set/Unset vlan filter table address
383  *  @hw: pointer to the HW structure
384  *  @vlan: 12 bit VLAN ID
385  *  @vind: unused by VF drivers
386  *  @vlan_on: if true then set bit, else clear bit
387  *  @vlvf_bypass: boolean flag indicating updating default pool is okay
388  *
389  *  Turn on/off specified VLAN in the VLAN filter table.
390  **/
391 s32 txgbe_set_vfta_vf(struct txgbe_hw *hw, u32 vlan, u32 vind,
392                       bool vlan_on, bool vlvf_bypass)
393 {
394         u32 msgbuf[2];
395         s32 ret_val;
396         UNREFERENCED_PARAMETER(vind, vlvf_bypass);
397
398         msgbuf[0] = TXGBE_VF_SET_VLAN;
399         msgbuf[1] = vlan;
400         /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
401         msgbuf[0] |= vlan_on << TXGBE_VT_MSGINFO_SHIFT;
402
403         ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
404         if (!ret_val && (msgbuf[0] & TXGBE_VT_MSGTYPE_ACK))
405                 return 0;
406
407         return ret_val | (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK);
408 }
409
410 /**
411  * txgbe_get_mac_addr_vf - Read device MAC address
412  * @hw: pointer to the HW structure
413  * @mac_addr: the MAC address
414  **/
415 s32 txgbe_get_mac_addr_vf(struct txgbe_hw *hw, u8 *mac_addr)
416 {
417         int i;
418
419         for (i = 0; i < ETH_ADDR_LEN; i++)
420                 mac_addr[i] = hw->mac.perm_addr[i];
421
422         return 0;
423 }
424
425 s32 txgbevf_set_uc_addr_vf(struct txgbe_hw *hw, u32 index, u8 *addr)
426 {
427         u32 msgbuf[3], msgbuf_chk;
428         u8 *msg_addr = (u8 *)(&msgbuf[1]);
429         s32 ret_val;
430
431         memset(msgbuf, 0, sizeof(msgbuf));
432         /*
433          * If index is one then this is the start of a new list and needs
434          * indication to the PF so it can do it's own list management.
435          * If it is zero then that tells the PF to just clear all of
436          * this VF's macvlans and there is no new list.
437          */
438         msgbuf[0] |= index << TXGBE_VT_MSGINFO_SHIFT;
439         msgbuf[0] |= TXGBE_VF_SET_MACVLAN;
440         msgbuf_chk = msgbuf[0];
441         if (addr)
442                 memcpy(msg_addr, addr, 6);
443
444         ret_val = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 3);
445         if (!ret_val) {
446                 msgbuf[0] &= ~TXGBE_VT_MSGTYPE_CTS;
447
448                 if (msgbuf[0] == (msgbuf_chk | TXGBE_VT_MSGTYPE_NACK))
449                         return TXGBE_ERR_OUT_OF_MEM;
450         }
451
452         return ret_val;
453 }
454
455 /**
456  *  txgbe_check_mac_link_vf - Get link/speed status
457  *  @hw: pointer to hardware structure
458  *  @speed: pointer to link speed
459  *  @link_up: true is link is up, false otherwise
460  *  @autoneg_wait_to_complete: true when waiting for completion is needed
461  *
462  *  Reads the links register to determine if link is up and the current speed
463  **/
464 s32 txgbe_check_mac_link_vf(struct txgbe_hw *hw, u32 *speed,
465                             bool *link_up, bool wait_to_complete)
466 {
467         /**
468          * for a quick link status checking, wait_to_compelet == 0,
469          * skip PF link status checking
470          */
471         bool no_pflink_check = wait_to_complete == 0;
472         struct txgbe_mbx_info *mbx = &hw->mbx;
473         struct txgbe_mac_info *mac = &hw->mac;
474         s32 ret_val = 0;
475         u32 links_reg;
476         u32 in_msg = 0;
477
478         /* If we were hit with a reset drop the link */
479         if (!mbx->check_for_rst(hw, 0) || !mbx->timeout)
480                 mac->get_link_status = true;
481
482         if (!mac->get_link_status)
483                 goto out;
484
485         /* if link status is down no point in checking to see if pf is up */
486         links_reg = rd32(hw, TXGBE_VFSTATUS);
487         if (!(links_reg & TXGBE_VFSTATUS_UP))
488                 goto out;
489
490         /* for SFP+ modules and DA cables it can take up to 500usecs
491          * before the link status is correct
492          */
493         if (mac->type == txgbe_mac_raptor_vf && wait_to_complete) {
494                 if (po32m(hw, TXGBE_VFSTATUS, TXGBE_VFSTATUS_UP,
495                         0, NULL, 5, 100))
496                         goto out;
497         }
498
499         switch (links_reg & TXGBE_VFSTATUS_BW_MASK) {
500         case TXGBE_VFSTATUS_BW_10G:
501                 *speed = TXGBE_LINK_SPEED_10GB_FULL;
502                 break;
503         case TXGBE_VFSTATUS_BW_1G:
504                 *speed = TXGBE_LINK_SPEED_1GB_FULL;
505                 break;
506         case TXGBE_VFSTATUS_BW_100M:
507                 *speed = TXGBE_LINK_SPEED_100M_FULL;
508                 break;
509         default:
510                 *speed = TXGBE_LINK_SPEED_UNKNOWN;
511         }
512
513         if (no_pflink_check) {
514                 if (*speed == TXGBE_LINK_SPEED_UNKNOWN)
515                         mac->get_link_status = true;
516                 else
517                         mac->get_link_status = false;
518
519                 goto out;
520         }
521
522         /* if the read failed it could just be a mailbox collision, best wait
523          * until we are called again and don't report an error
524          */
525         if (mbx->read(hw, &in_msg, 1, 0))
526                 goto out;
527
528         if (!(in_msg & TXGBE_VT_MSGTYPE_CTS)) {
529                 /* msg is not CTS and is NACK we must have lost CTS status */
530                 if (in_msg & TXGBE_VT_MSGTYPE_NACK)
531                         ret_val = -1;
532                 goto out;
533         }
534
535         /* the pf is talking, if we timed out in the past we reinit */
536         if (!mbx->timeout) {
537                 ret_val = -1;
538                 goto out;
539         }
540
541         /* if we passed all the tests above then the link is up and we no
542          * longer need to check for link
543          */
544         mac->get_link_status = false;
545
546 out:
547         *link_up = !mac->get_link_status;
548         return ret_val;
549 }
550
551 /**
552  *  txgbevf_rlpml_set_vf - Set the maximum receive packet length
553  *  @hw: pointer to the HW structure
554  *  @max_size: value to assign to max frame size
555  **/
556 s32 txgbevf_rlpml_set_vf(struct txgbe_hw *hw, u16 max_size)
557 {
558         u32 msgbuf[2];
559         s32 retval;
560
561         msgbuf[0] = TXGBE_VF_SET_LPE;
562         msgbuf[1] = max_size;
563
564         retval = txgbevf_write_msg_read_ack(hw, msgbuf, msgbuf, 2);
565         if (retval)
566                 return retval;
567         if ((msgbuf[0] & TXGBE_VF_SET_LPE) &&
568             (msgbuf[0] & TXGBE_VT_MSGTYPE_NACK))
569                 return TXGBE_ERR_MBX;
570
571         return 0;
572 }
573
574 /**
575  *  txgbevf_negotiate_api_version - Negotiate supported API version
576  *  @hw: pointer to the HW structure
577  *  @api: integer containing requested API version
578  **/
579 int txgbevf_negotiate_api_version(struct txgbe_hw *hw, int api)
580 {
581         int err;
582         u32 msg[3];
583
584         /* Negotiate the mailbox API version */
585         msg[0] = TXGBE_VF_API_NEGOTIATE;
586         msg[1] = api;
587         msg[2] = 0;
588
589         err = txgbevf_write_msg_read_ack(hw, msg, msg, 3);
590         if (!err) {
591                 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
592
593                 /* Store value and return 0 on success */
594                 if (msg[0] == (TXGBE_VF_API_NEGOTIATE | TXGBE_VT_MSGTYPE_ACK)) {
595                         hw->api_version = api;
596                         return 0;
597                 }
598
599                 err = TXGBE_ERR_INVALID_ARGUMENT;
600         }
601
602         return err;
603 }
604
605 int txgbevf_get_queues(struct txgbe_hw *hw, unsigned int *num_tcs,
606                        unsigned int *default_tc)
607 {
608         int err, i;
609         u32 msg[5];
610
611         /* do nothing if API doesn't support txgbevf_get_queues */
612         switch (hw->api_version) {
613         case txgbe_mbox_api_11:
614         case txgbe_mbox_api_12:
615         case txgbe_mbox_api_13:
616                 break;
617         default:
618                 return 0;
619         }
620
621         /* Fetch queue configuration from the PF */
622         msg[0] = TXGBE_VF_GET_QUEUES;
623         for (i = 1; i < 5; i++)
624                 msg[i] = 0;
625
626         err = txgbevf_write_msg_read_ack(hw, msg, msg, 5);
627         if (!err) {
628                 msg[0] &= ~TXGBE_VT_MSGTYPE_CTS;
629
630                 /*
631                  * if we didn't get an ACK there must have been
632                  * some sort of mailbox error so we should treat it
633                  * as such
634                  */
635                 if (msg[0] != (TXGBE_VF_GET_QUEUES | TXGBE_VT_MSGTYPE_ACK))
636                         return TXGBE_ERR_MBX;
637
638                 /* record and validate values from message */
639                 hw->mac.max_tx_queues = msg[TXGBE_VF_TX_QUEUES];
640                 if (hw->mac.max_tx_queues == 0 ||
641                     hw->mac.max_tx_queues > TXGBE_VF_MAX_TX_QUEUES)
642                         hw->mac.max_tx_queues = TXGBE_VF_MAX_TX_QUEUES;
643
644                 hw->mac.max_rx_queues = msg[TXGBE_VF_RX_QUEUES];
645                 if (hw->mac.max_rx_queues == 0 ||
646                     hw->mac.max_rx_queues > TXGBE_VF_MAX_RX_QUEUES)
647                         hw->mac.max_rx_queues = TXGBE_VF_MAX_RX_QUEUES;
648
649                 *num_tcs = msg[TXGBE_VF_TRANS_VLAN];
650                 /* in case of unknown state assume we cannot tag frames */
651                 if (*num_tcs > hw->mac.max_rx_queues)
652                         *num_tcs = 1;
653
654                 *default_tc = msg[TXGBE_VF_DEF_QUEUE];
655                 /* default to queue 0 on out-of-bounds queue number */
656                 if (*default_tc >= hw->mac.max_tx_queues)
657                         *default_tc = 0;
658         }
659
660         return err;
661 }