diff options
Diffstat (limited to 'drivers/net/ixgbe/ixgbe_common.c')
-rw-r--r-- | drivers/net/ixgbe/ixgbe_common.c | 539 |
1 files changed, 516 insertions, 23 deletions
diff --git a/drivers/net/ixgbe/ixgbe_common.c b/drivers/net/ixgbe/ixgbe_common.c index eb49020903c1..1159d9138f05 100644 --- a/drivers/net/ixgbe/ixgbe_common.c +++ b/drivers/net/ixgbe/ixgbe_common.c | |||
@@ -34,7 +34,6 @@ | |||
34 | #include "ixgbe_common.h" | 34 | #include "ixgbe_common.h" |
35 | #include "ixgbe_phy.h" | 35 | #include "ixgbe_phy.h" |
36 | 36 | ||
37 | static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw); | ||
38 | static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw); | 37 | static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw); |
39 | static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw); | 38 | static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw); |
40 | static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw); | 39 | static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw); |
@@ -595,14 +594,14 @@ out: | |||
595 | } | 594 | } |
596 | 595 | ||
597 | /** | 596 | /** |
598 | * ixgbe_read_eeprom_generic - Read EEPROM word using EERD | 597 | * ixgbe_read_eerd_generic - Read EEPROM word using EERD |
599 | * @hw: pointer to hardware structure | 598 | * @hw: pointer to hardware structure |
600 | * @offset: offset of word in the EEPROM to read | 599 | * @offset: offset of word in the EEPROM to read |
601 | * @data: word read from the EEPROM | 600 | * @data: word read from the EEPROM |
602 | * | 601 | * |
603 | * Reads a 16 bit word from the EEPROM using the EERD register. | 602 | * Reads a 16 bit word from the EEPROM using the EERD register. |
604 | **/ | 603 | **/ |
605 | s32 ixgbe_read_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 *data) | 604 | s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data) |
606 | { | 605 | { |
607 | u32 eerd; | 606 | u32 eerd; |
608 | s32 status; | 607 | s32 status; |
@@ -614,15 +613,15 @@ s32 ixgbe_read_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 *data) | |||
614 | goto out; | 613 | goto out; |
615 | } | 614 | } |
616 | 615 | ||
617 | eerd = (offset << IXGBE_EEPROM_READ_ADDR_SHIFT) + | 616 | eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) + |
618 | IXGBE_EEPROM_READ_REG_START; | 617 | IXGBE_EEPROM_RW_REG_START; |
619 | 618 | ||
620 | IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd); | 619 | IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd); |
621 | status = ixgbe_poll_eeprom_eerd_done(hw); | 620 | status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ); |
622 | 621 | ||
623 | if (status == 0) | 622 | if (status == 0) |
624 | *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >> | 623 | *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >> |
625 | IXGBE_EEPROM_READ_REG_DATA); | 624 | IXGBE_EEPROM_RW_REG_DATA); |
626 | else | 625 | else |
627 | hw_dbg(hw, "Eeprom read timed out\n"); | 626 | hw_dbg(hw, "Eeprom read timed out\n"); |
628 | 627 | ||
@@ -631,20 +630,26 @@ out: | |||
631 | } | 630 | } |
632 | 631 | ||
633 | /** | 632 | /** |
634 | * ixgbe_poll_eeprom_eerd_done - Poll EERD status | 633 | * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status |
635 | * @hw: pointer to hardware structure | 634 | * @hw: pointer to hardware structure |
635 | * @ee_reg: EEPROM flag for polling | ||
636 | * | 636 | * |
637 | * Polls the status bit (bit 1) of the EERD to determine when the read is done. | 637 | * Polls the status bit (bit 1) of the EERD or EEWR to determine when the |
638 | * read or write is done respectively. | ||
638 | **/ | 639 | **/ |
639 | static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw) | 640 | s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg) |
640 | { | 641 | { |
641 | u32 i; | 642 | u32 i; |
642 | u32 reg; | 643 | u32 reg; |
643 | s32 status = IXGBE_ERR_EEPROM; | 644 | s32 status = IXGBE_ERR_EEPROM; |
644 | 645 | ||
645 | for (i = 0; i < IXGBE_EERD_ATTEMPTS; i++) { | 646 | for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) { |
646 | reg = IXGBE_READ_REG(hw, IXGBE_EERD); | 647 | if (ee_reg == IXGBE_NVM_POLL_READ) |
647 | if (reg & IXGBE_EEPROM_READ_REG_DONE) { | 648 | reg = IXGBE_READ_REG(hw, IXGBE_EERD); |
649 | else | ||
650 | reg = IXGBE_READ_REG(hw, IXGBE_EEWR); | ||
651 | |||
652 | if (reg & IXGBE_EEPROM_RW_REG_DONE) { | ||
648 | status = 0; | 653 | status = 0; |
649 | break; | 654 | break; |
650 | } | 655 | } |
@@ -1392,14 +1397,17 @@ s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, | |||
1392 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); | 1397 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
1393 | fctrl |= IXGBE_FCTRL_UPE; | 1398 | fctrl |= IXGBE_FCTRL_UPE; |
1394 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); | 1399 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
1400 | hw->addr_ctrl.uc_set_promisc = true; | ||
1395 | } | 1401 | } |
1396 | } else { | 1402 | } else { |
1397 | /* only disable if set by overflow, not by user */ | 1403 | /* only disable if set by overflow, not by user */ |
1398 | if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) { | 1404 | if ((old_promisc_setting && hw->addr_ctrl.uc_set_promisc) && |
1405 | !(hw->addr_ctrl.user_set_promisc)) { | ||
1399 | hw_dbg(hw, " Leaving address overflow promisc mode\n"); | 1406 | hw_dbg(hw, " Leaving address overflow promisc mode\n"); |
1400 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); | 1407 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
1401 | fctrl &= ~IXGBE_FCTRL_UPE; | 1408 | fctrl &= ~IXGBE_FCTRL_UPE; |
1402 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); | 1409 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
1410 | hw->addr_ctrl.uc_set_promisc = false; | ||
1403 | } | 1411 | } |
1404 | } | 1412 | } |
1405 | 1413 | ||
@@ -1484,26 +1492,24 @@ static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr) | |||
1484 | /** | 1492 | /** |
1485 | * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses | 1493 | * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses |
1486 | * @hw: pointer to hardware structure | 1494 | * @hw: pointer to hardware structure |
1487 | * @mc_addr_list: the list of new multicast addresses | 1495 | * @netdev: pointer to net device structure |
1488 | * @mc_addr_count: number of addresses | ||
1489 | * @next: iterator function to walk the multicast address list | ||
1490 | * | 1496 | * |
1491 | * The given list replaces any existing list. Clears the MC addrs from receive | 1497 | * The given list replaces any existing list. Clears the MC addrs from receive |
1492 | * address registers and the multicast table. Uses unused receive address | 1498 | * address registers and the multicast table. Uses unused receive address |
1493 | * registers for the first multicast addresses, and hashes the rest into the | 1499 | * registers for the first multicast addresses, and hashes the rest into the |
1494 | * multicast table. | 1500 | * multicast table. |
1495 | **/ | 1501 | **/ |
1496 | s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list, | 1502 | s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, |
1497 | u32 mc_addr_count, ixgbe_mc_addr_itr next) | 1503 | struct net_device *netdev) |
1498 | { | 1504 | { |
1505 | struct netdev_hw_addr *ha; | ||
1499 | u32 i; | 1506 | u32 i; |
1500 | u32 vmdq; | ||
1501 | 1507 | ||
1502 | /* | 1508 | /* |
1503 | * Set the new number of MC addresses that we are being requested to | 1509 | * Set the new number of MC addresses that we are being requested to |
1504 | * use. | 1510 | * use. |
1505 | */ | 1511 | */ |
1506 | hw->addr_ctrl.num_mc_addrs = mc_addr_count; | 1512 | hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev); |
1507 | hw->addr_ctrl.mta_in_use = 0; | 1513 | hw->addr_ctrl.mta_in_use = 0; |
1508 | 1514 | ||
1509 | /* Clear the MTA */ | 1515 | /* Clear the MTA */ |
@@ -1512,9 +1518,9 @@ s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list, | |||
1512 | IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0); | 1518 | IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0); |
1513 | 1519 | ||
1514 | /* Add the new addresses */ | 1520 | /* Add the new addresses */ |
1515 | for (i = 0; i < mc_addr_count; i++) { | 1521 | netdev_for_each_mc_addr(ha, netdev) { |
1516 | hw_dbg(hw, " Adding the multicast addresses:\n"); | 1522 | hw_dbg(hw, " Adding the multicast addresses:\n"); |
1517 | ixgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq)); | 1523 | ixgbe_set_mta(hw, ha->addr); |
1518 | } | 1524 | } |
1519 | 1525 | ||
1520 | /* Enable mta */ | 1526 | /* Enable mta */ |
@@ -2254,3 +2260,490 @@ s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index) | |||
2254 | 2260 | ||
2255 | return 0; | 2261 | return 0; |
2256 | } | 2262 | } |
2263 | |||
2264 | /** | ||
2265 | * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM | ||
2266 | * @hw: pointer to hardware structure | ||
2267 | * @san_mac_offset: SAN MAC address offset | ||
2268 | * | ||
2269 | * This function will read the EEPROM location for the SAN MAC address | ||
2270 | * pointer, and returns the value at that location. This is used in both | ||
2271 | * get and set mac_addr routines. | ||
2272 | **/ | ||
2273 | static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw, | ||
2274 | u16 *san_mac_offset) | ||
2275 | { | ||
2276 | /* | ||
2277 | * First read the EEPROM pointer to see if the MAC addresses are | ||
2278 | * available. | ||
2279 | */ | ||
2280 | hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset); | ||
2281 | |||
2282 | return 0; | ||
2283 | } | ||
2284 | |||
2285 | /** | ||
2286 | * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM | ||
2287 | * @hw: pointer to hardware structure | ||
2288 | * @san_mac_addr: SAN MAC address | ||
2289 | * | ||
2290 | * Reads the SAN MAC address from the EEPROM, if it's available. This is | ||
2291 | * per-port, so set_lan_id() must be called before reading the addresses. | ||
2292 | * set_lan_id() is called by identify_sfp(), but this cannot be relied | ||
2293 | * upon for non-SFP connections, so we must call it here. | ||
2294 | **/ | ||
2295 | s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr) | ||
2296 | { | ||
2297 | u16 san_mac_data, san_mac_offset; | ||
2298 | u8 i; | ||
2299 | |||
2300 | /* | ||
2301 | * First read the EEPROM pointer to see if the MAC addresses are | ||
2302 | * available. If they're not, no point in calling set_lan_id() here. | ||
2303 | */ | ||
2304 | ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset); | ||
2305 | |||
2306 | if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) { | ||
2307 | /* | ||
2308 | * No addresses available in this EEPROM. It's not an | ||
2309 | * error though, so just wipe the local address and return. | ||
2310 | */ | ||
2311 | for (i = 0; i < 6; i++) | ||
2312 | san_mac_addr[i] = 0xFF; | ||
2313 | |||
2314 | goto san_mac_addr_out; | ||
2315 | } | ||
2316 | |||
2317 | /* make sure we know which port we need to program */ | ||
2318 | hw->mac.ops.set_lan_id(hw); | ||
2319 | /* apply the port offset to the address offset */ | ||
2320 | (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) : | ||
2321 | (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET); | ||
2322 | for (i = 0; i < 3; i++) { | ||
2323 | hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data); | ||
2324 | san_mac_addr[i * 2] = (u8)(san_mac_data); | ||
2325 | san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8); | ||
2326 | san_mac_offset++; | ||
2327 | } | ||
2328 | |||
2329 | san_mac_addr_out: | ||
2330 | return 0; | ||
2331 | } | ||
2332 | |||
2333 | /** | ||
2334 | * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count | ||
2335 | * @hw: pointer to hardware structure | ||
2336 | * | ||
2337 | * Read PCIe configuration space, and get the MSI-X vector count from | ||
2338 | * the capabilities table. | ||
2339 | **/ | ||
2340 | u32 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw) | ||
2341 | { | ||
2342 | struct ixgbe_adapter *adapter = hw->back; | ||
2343 | u16 msix_count; | ||
2344 | pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS, | ||
2345 | &msix_count); | ||
2346 | msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK; | ||
2347 | |||
2348 | /* MSI-X count is zero-based in HW, so increment to give proper value */ | ||
2349 | msix_count++; | ||
2350 | |||
2351 | return msix_count; | ||
2352 | } | ||
2353 | |||
2354 | /** | ||
2355 | * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address | ||
2356 | * @hw: pointer to hardware struct | ||
2357 | * @rar: receive address register index to disassociate | ||
2358 | * @vmdq: VMDq pool index to remove from the rar | ||
2359 | **/ | ||
2360 | s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq) | ||
2361 | { | ||
2362 | u32 mpsar_lo, mpsar_hi; | ||
2363 | u32 rar_entries = hw->mac.num_rar_entries; | ||
2364 | |||
2365 | if (rar < rar_entries) { | ||
2366 | mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar)); | ||
2367 | mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar)); | ||
2368 | |||
2369 | if (!mpsar_lo && !mpsar_hi) | ||
2370 | goto done; | ||
2371 | |||
2372 | if (vmdq == IXGBE_CLEAR_VMDQ_ALL) { | ||
2373 | if (mpsar_lo) { | ||
2374 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0); | ||
2375 | mpsar_lo = 0; | ||
2376 | } | ||
2377 | if (mpsar_hi) { | ||
2378 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0); | ||
2379 | mpsar_hi = 0; | ||
2380 | } | ||
2381 | } else if (vmdq < 32) { | ||
2382 | mpsar_lo &= ~(1 << vmdq); | ||
2383 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo); | ||
2384 | } else { | ||
2385 | mpsar_hi &= ~(1 << (vmdq - 32)); | ||
2386 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi); | ||
2387 | } | ||
2388 | |||
2389 | /* was that the last pool using this rar? */ | ||
2390 | if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0) | ||
2391 | hw->mac.ops.clear_rar(hw, rar); | ||
2392 | } else { | ||
2393 | hw_dbg(hw, "RAR index %d is out of range.\n", rar); | ||
2394 | } | ||
2395 | |||
2396 | done: | ||
2397 | return 0; | ||
2398 | } | ||
2399 | |||
2400 | /** | ||
2401 | * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address | ||
2402 | * @hw: pointer to hardware struct | ||
2403 | * @rar: receive address register index to associate with a VMDq index | ||
2404 | * @vmdq: VMDq pool index | ||
2405 | **/ | ||
2406 | s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq) | ||
2407 | { | ||
2408 | u32 mpsar; | ||
2409 | u32 rar_entries = hw->mac.num_rar_entries; | ||
2410 | |||
2411 | if (rar < rar_entries) { | ||
2412 | if (vmdq < 32) { | ||
2413 | mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar)); | ||
2414 | mpsar |= 1 << vmdq; | ||
2415 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar); | ||
2416 | } else { | ||
2417 | mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar)); | ||
2418 | mpsar |= 1 << (vmdq - 32); | ||
2419 | IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar); | ||
2420 | } | ||
2421 | } else { | ||
2422 | hw_dbg(hw, "RAR index %d is out of range.\n", rar); | ||
2423 | } | ||
2424 | return 0; | ||
2425 | } | ||
2426 | |||
2427 | /** | ||
2428 | * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array | ||
2429 | * @hw: pointer to hardware structure | ||
2430 | **/ | ||
2431 | s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw) | ||
2432 | { | ||
2433 | int i; | ||
2434 | |||
2435 | |||
2436 | for (i = 0; i < 128; i++) | ||
2437 | IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0); | ||
2438 | |||
2439 | return 0; | ||
2440 | } | ||
2441 | |||
2442 | /** | ||
2443 | * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot | ||
2444 | * @hw: pointer to hardware structure | ||
2445 | * @vlan: VLAN id to write to VLAN filter | ||
2446 | * | ||
2447 | * return the VLVF index where this VLAN id should be placed | ||
2448 | * | ||
2449 | **/ | ||
2450 | s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan) | ||
2451 | { | ||
2452 | u32 bits = 0; | ||
2453 | u32 first_empty_slot = 0; | ||
2454 | s32 regindex; | ||
2455 | |||
2456 | /* short cut the special case */ | ||
2457 | if (vlan == 0) | ||
2458 | return 0; | ||
2459 | |||
2460 | /* | ||
2461 | * Search for the vlan id in the VLVF entries. Save off the first empty | ||
2462 | * slot found along the way | ||
2463 | */ | ||
2464 | for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) { | ||
2465 | bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex)); | ||
2466 | if (!bits && !(first_empty_slot)) | ||
2467 | first_empty_slot = regindex; | ||
2468 | else if ((bits & 0x0FFF) == vlan) | ||
2469 | break; | ||
2470 | } | ||
2471 | |||
2472 | /* | ||
2473 | * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan | ||
2474 | * in the VLVF. Else use the first empty VLVF register for this | ||
2475 | * vlan id. | ||
2476 | */ | ||
2477 | if (regindex >= IXGBE_VLVF_ENTRIES) { | ||
2478 | if (first_empty_slot) | ||
2479 | regindex = first_empty_slot; | ||
2480 | else { | ||
2481 | hw_dbg(hw, "No space in VLVF.\n"); | ||
2482 | regindex = IXGBE_ERR_NO_SPACE; | ||
2483 | } | ||
2484 | } | ||
2485 | |||
2486 | return regindex; | ||
2487 | } | ||
2488 | |||
2489 | /** | ||
2490 | * ixgbe_set_vfta_generic - Set VLAN filter table | ||
2491 | * @hw: pointer to hardware structure | ||
2492 | * @vlan: VLAN id to write to VLAN filter | ||
2493 | * @vind: VMDq output index that maps queue to VLAN id in VFVFB | ||
2494 | * @vlan_on: boolean flag to turn on/off VLAN in VFVF | ||
2495 | * | ||
2496 | * Turn on/off specified VLAN in the VLAN filter table. | ||
2497 | **/ | ||
2498 | s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind, | ||
2499 | bool vlan_on) | ||
2500 | { | ||
2501 | s32 regindex; | ||
2502 | u32 bitindex; | ||
2503 | u32 vfta; | ||
2504 | u32 bits; | ||
2505 | u32 vt; | ||
2506 | u32 targetbit; | ||
2507 | bool vfta_changed = false; | ||
2508 | |||
2509 | if (vlan > 4095) | ||
2510 | return IXGBE_ERR_PARAM; | ||
2511 | |||
2512 | /* | ||
2513 | * this is a 2 part operation - first the VFTA, then the | ||
2514 | * VLVF and VLVFB if VT Mode is set | ||
2515 | * We don't write the VFTA until we know the VLVF part succeeded. | ||
2516 | */ | ||
2517 | |||
2518 | /* Part 1 | ||
2519 | * The VFTA is a bitstring made up of 128 32-bit registers | ||
2520 | * that enable the particular VLAN id, much like the MTA: | ||
2521 | * bits[11-5]: which register | ||
2522 | * bits[4-0]: which bit in the register | ||
2523 | */ | ||
2524 | regindex = (vlan >> 5) & 0x7F; | ||
2525 | bitindex = vlan & 0x1F; | ||
2526 | targetbit = (1 << bitindex); | ||
2527 | vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex)); | ||
2528 | |||
2529 | if (vlan_on) { | ||
2530 | if (!(vfta & targetbit)) { | ||
2531 | vfta |= targetbit; | ||
2532 | vfta_changed = true; | ||
2533 | } | ||
2534 | } else { | ||
2535 | if ((vfta & targetbit)) { | ||
2536 | vfta &= ~targetbit; | ||
2537 | vfta_changed = true; | ||
2538 | } | ||
2539 | } | ||
2540 | |||
2541 | /* Part 2 | ||
2542 | * If VT Mode is set | ||
2543 | * Either vlan_on | ||
2544 | * make sure the vlan is in VLVF | ||
2545 | * set the vind bit in the matching VLVFB | ||
2546 | * Or !vlan_on | ||
2547 | * clear the pool bit and possibly the vind | ||
2548 | */ | ||
2549 | vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL); | ||
2550 | if (vt & IXGBE_VT_CTL_VT_ENABLE) { | ||
2551 | s32 vlvf_index; | ||
2552 | |||
2553 | vlvf_index = ixgbe_find_vlvf_slot(hw, vlan); | ||
2554 | if (vlvf_index < 0) | ||
2555 | return vlvf_index; | ||
2556 | |||
2557 | if (vlan_on) { | ||
2558 | /* set the pool bit */ | ||
2559 | if (vind < 32) { | ||
2560 | bits = IXGBE_READ_REG(hw, | ||
2561 | IXGBE_VLVFB(vlvf_index*2)); | ||
2562 | bits |= (1 << vind); | ||
2563 | IXGBE_WRITE_REG(hw, | ||
2564 | IXGBE_VLVFB(vlvf_index*2), | ||
2565 | bits); | ||
2566 | } else { | ||
2567 | bits = IXGBE_READ_REG(hw, | ||
2568 | IXGBE_VLVFB((vlvf_index*2)+1)); | ||
2569 | bits |= (1 << (vind-32)); | ||
2570 | IXGBE_WRITE_REG(hw, | ||
2571 | IXGBE_VLVFB((vlvf_index*2)+1), | ||
2572 | bits); | ||
2573 | } | ||
2574 | } else { | ||
2575 | /* clear the pool bit */ | ||
2576 | if (vind < 32) { | ||
2577 | bits = IXGBE_READ_REG(hw, | ||
2578 | IXGBE_VLVFB(vlvf_index*2)); | ||
2579 | bits &= ~(1 << vind); | ||
2580 | IXGBE_WRITE_REG(hw, | ||
2581 | IXGBE_VLVFB(vlvf_index*2), | ||
2582 | bits); | ||
2583 | bits |= IXGBE_READ_REG(hw, | ||
2584 | IXGBE_VLVFB((vlvf_index*2)+1)); | ||
2585 | } else { | ||
2586 | bits = IXGBE_READ_REG(hw, | ||
2587 | IXGBE_VLVFB((vlvf_index*2)+1)); | ||
2588 | bits &= ~(1 << (vind-32)); | ||
2589 | IXGBE_WRITE_REG(hw, | ||
2590 | IXGBE_VLVFB((vlvf_index*2)+1), | ||
2591 | bits); | ||
2592 | bits |= IXGBE_READ_REG(hw, | ||
2593 | IXGBE_VLVFB(vlvf_index*2)); | ||
2594 | } | ||
2595 | } | ||
2596 | |||
2597 | /* | ||
2598 | * If there are still bits set in the VLVFB registers | ||
2599 | * for the VLAN ID indicated we need to see if the | ||
2600 | * caller is requesting that we clear the VFTA entry bit. | ||
2601 | * If the caller has requested that we clear the VFTA | ||
2602 | * entry bit but there are still pools/VFs using this VLAN | ||
2603 | * ID entry then ignore the request. We're not worried | ||
2604 | * about the case where we're turning the VFTA VLAN ID | ||
2605 | * entry bit on, only when requested to turn it off as | ||
2606 | * there may be multiple pools and/or VFs using the | ||
2607 | * VLAN ID entry. In that case we cannot clear the | ||
2608 | * VFTA bit until all pools/VFs using that VLAN ID have also | ||
2609 | * been cleared. This will be indicated by "bits" being | ||
2610 | * zero. | ||
2611 | */ | ||
2612 | if (bits) { | ||
2613 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), | ||
2614 | (IXGBE_VLVF_VIEN | vlan)); | ||
2615 | if (!vlan_on) { | ||
2616 | /* someone wants to clear the vfta entry | ||
2617 | * but some pools/VFs are still using it. | ||
2618 | * Ignore it. */ | ||
2619 | vfta_changed = false; | ||
2620 | } | ||
2621 | } | ||
2622 | else | ||
2623 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0); | ||
2624 | } | ||
2625 | |||
2626 | if (vfta_changed) | ||
2627 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta); | ||
2628 | |||
2629 | return 0; | ||
2630 | } | ||
2631 | |||
2632 | /** | ||
2633 | * ixgbe_clear_vfta_generic - Clear VLAN filter table | ||
2634 | * @hw: pointer to hardware structure | ||
2635 | * | ||
2636 | * Clears the VLAN filer table, and the VMDq index associated with the filter | ||
2637 | **/ | ||
2638 | s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw) | ||
2639 | { | ||
2640 | u32 offset; | ||
2641 | |||
2642 | for (offset = 0; offset < hw->mac.vft_size; offset++) | ||
2643 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0); | ||
2644 | |||
2645 | for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) { | ||
2646 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0); | ||
2647 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0); | ||
2648 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0); | ||
2649 | } | ||
2650 | |||
2651 | return 0; | ||
2652 | } | ||
2653 | |||
2654 | /** | ||
2655 | * ixgbe_check_mac_link_generic - Determine link and speed status | ||
2656 | * @hw: pointer to hardware structure | ||
2657 | * @speed: pointer to link speed | ||
2658 | * @link_up: true when link is up | ||
2659 | * @link_up_wait_to_complete: bool used to wait for link up or not | ||
2660 | * | ||
2661 | * Reads the links register to determine if link is up and the current speed | ||
2662 | **/ | ||
2663 | s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed, | ||
2664 | bool *link_up, bool link_up_wait_to_complete) | ||
2665 | { | ||
2666 | u32 links_reg; | ||
2667 | u32 i; | ||
2668 | |||
2669 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
2670 | if (link_up_wait_to_complete) { | ||
2671 | for (i = 0; i < IXGBE_LINK_UP_TIME; i++) { | ||
2672 | if (links_reg & IXGBE_LINKS_UP) { | ||
2673 | *link_up = true; | ||
2674 | break; | ||
2675 | } else { | ||
2676 | *link_up = false; | ||
2677 | } | ||
2678 | msleep(100); | ||
2679 | links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS); | ||
2680 | } | ||
2681 | } else { | ||
2682 | if (links_reg & IXGBE_LINKS_UP) | ||
2683 | *link_up = true; | ||
2684 | else | ||
2685 | *link_up = false; | ||
2686 | } | ||
2687 | |||
2688 | if ((links_reg & IXGBE_LINKS_SPEED_82599) == | ||
2689 | IXGBE_LINKS_SPEED_10G_82599) | ||
2690 | *speed = IXGBE_LINK_SPEED_10GB_FULL; | ||
2691 | else if ((links_reg & IXGBE_LINKS_SPEED_82599) == | ||
2692 | IXGBE_LINKS_SPEED_1G_82599) | ||
2693 | *speed = IXGBE_LINK_SPEED_1GB_FULL; | ||
2694 | else | ||
2695 | *speed = IXGBE_LINK_SPEED_100_FULL; | ||
2696 | |||
2697 | /* if link is down, zero out the current_mode */ | ||
2698 | if (*link_up == false) { | ||
2699 | hw->fc.current_mode = ixgbe_fc_none; | ||
2700 | hw->fc.fc_was_autonegged = false; | ||
2701 | } | ||
2702 | |||
2703 | return 0; | ||
2704 | } | ||
2705 | |||
2706 | /** | ||
2707 | * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from | ||
2708 | * the EEPROM | ||
2709 | * @hw: pointer to hardware structure | ||
2710 | * @wwnn_prefix: the alternative WWNN prefix | ||
2711 | * @wwpn_prefix: the alternative WWPN prefix | ||
2712 | * | ||
2713 | * This function will read the EEPROM from the alternative SAN MAC address | ||
2714 | * block to check the support for the alternative WWNN/WWPN prefix support. | ||
2715 | **/ | ||
2716 | s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix, | ||
2717 | u16 *wwpn_prefix) | ||
2718 | { | ||
2719 | u16 offset, caps; | ||
2720 | u16 alt_san_mac_blk_offset; | ||
2721 | |||
2722 | /* clear output first */ | ||
2723 | *wwnn_prefix = 0xFFFF; | ||
2724 | *wwpn_prefix = 0xFFFF; | ||
2725 | |||
2726 | /* check if alternative SAN MAC is supported */ | ||
2727 | hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR, | ||
2728 | &alt_san_mac_blk_offset); | ||
2729 | |||
2730 | if ((alt_san_mac_blk_offset == 0) || | ||
2731 | (alt_san_mac_blk_offset == 0xFFFF)) | ||
2732 | goto wwn_prefix_out; | ||
2733 | |||
2734 | /* check capability in alternative san mac address block */ | ||
2735 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET; | ||
2736 | hw->eeprom.ops.read(hw, offset, &caps); | ||
2737 | if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN)) | ||
2738 | goto wwn_prefix_out; | ||
2739 | |||
2740 | /* get the corresponding prefix for WWNN/WWPN */ | ||
2741 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET; | ||
2742 | hw->eeprom.ops.read(hw, offset, wwnn_prefix); | ||
2743 | |||
2744 | offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET; | ||
2745 | hw->eeprom.ops.read(hw, offset, wwpn_prefix); | ||
2746 | |||
2747 | wwn_prefix_out: | ||
2748 | return 0; | ||
2749 | } | ||