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