LCOV - code coverage report
Current view: top level - drivers/net/ngbe/base - ngbe_hw.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 609 0.0 %
Date: 2024-01-22 16:26:08 Functions: 0 52 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 283 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
       3                 :            :  * Copyright(c) 2010-2017 Intel Corporation
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "ngbe_type.h"
       7                 :            : #include "ngbe_mbx.h"
       8                 :            : #include "ngbe_phy.h"
       9                 :            : #include "ngbe_eeprom.h"
      10                 :            : #include "ngbe_mng.h"
      11                 :            : #include "ngbe_hw.h"
      12                 :            : 
      13                 :            : /**
      14                 :            :  *  ngbe_start_hw - Prepare hardware for Tx/Rx
      15                 :            :  *  @hw: pointer to hardware structure
      16                 :            :  *
      17                 :            :  *  Starts the hardware.
      18                 :            :  **/
      19                 :          0 : s32 ngbe_start_hw(struct ngbe_hw *hw)
      20                 :            : {
      21                 :            :         s32 err;
      22                 :            : 
      23                 :            :         /* Clear the VLAN filter table */
      24                 :          0 :         hw->mac.clear_vfta(hw);
      25                 :            : 
      26                 :            :         /* Clear statistics registers */
      27                 :          0 :         hw->mac.clear_hw_cntrs(hw);
      28                 :            : 
      29                 :            :         /* Setup flow control */
      30                 :          0 :         err = hw->mac.setup_fc(hw);
      31         [ #  # ]:          0 :         if (err != 0 && err != NGBE_NOT_IMPLEMENTED) {
      32                 :          0 :                 DEBUGOUT("Flow control setup failed, returning %d", err);
      33                 :          0 :                 return err;
      34                 :            :         }
      35                 :            : 
      36                 :            :         /* Clear adapter stopped flag */
      37                 :          0 :         hw->adapter_stopped = false;
      38                 :            : 
      39                 :          0 :         return 0;
      40                 :            : }
      41                 :            : 
      42                 :            : /**
      43                 :            :  *  ngbe_init_hw - Generic hardware initialization
      44                 :            :  *  @hw: pointer to hardware structure
      45                 :            :  *
      46                 :            :  *  Initialize the hardware by resetting the hardware, filling the bus info
      47                 :            :  *  structure and media type, clears all on chip counters, initializes receive
      48                 :            :  *  address registers, multicast table, VLAN filter table, calls routine to set
      49                 :            :  *  up link and flow control settings, and leaves transmit and receive units
      50                 :            :  *  disabled and uninitialized
      51                 :            :  **/
      52                 :          0 : s32 ngbe_init_hw(struct ngbe_hw *hw)
      53                 :            : {
      54                 :            :         s32 status;
      55                 :            : 
      56                 :          0 :         ngbe_read_efuse(hw);
      57                 :          0 :         ngbe_save_eeprom_version(hw);
      58                 :            : 
      59                 :            :         /* Reset the hardware */
      60                 :          0 :         status = hw->mac.reset_hw(hw);
      61         [ #  # ]:          0 :         if (status == 0) {
      62                 :            :                 /* Start the HW */
      63                 :          0 :                 status = hw->mac.start_hw(hw);
      64                 :            :         }
      65                 :            : 
      66         [ #  # ]:          0 :         if (status != 0)
      67                 :          0 :                 DEBUGOUT("Failed to initialize HW, STATUS = %d", status);
      68                 :            : 
      69                 :          0 :         return status;
      70                 :            : }
      71                 :            : 
      72                 :            : static void
      73                 :          0 : ngbe_reset_misc_em(struct ngbe_hw *hw)
      74                 :            : {
      75                 :            :         int i;
      76                 :            : 
      77                 :          0 :         wr32(hw, NGBE_ISBADDRL, hw->isb_dma & 0xFFFFFFFF);
      78                 :          0 :         wr32(hw, NGBE_ISBADDRH, hw->isb_dma >> 32);
      79                 :            : 
      80                 :            :         /* receive packets that size > 2048 */
      81                 :            :         wr32m(hw, NGBE_MACRXCFG,
      82                 :            :                 NGBE_MACRXCFG_JUMBO, NGBE_MACRXCFG_JUMBO);
      83                 :            : 
      84                 :            :         wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
      85                 :            :                 NGBE_FRMSZ_MAX(NGBE_FRAME_SIZE_DFT));
      86                 :            : 
      87                 :            :         /* clear counters on read */
      88                 :            :         wr32m(hw, NGBE_MACCNTCTL,
      89                 :            :                 NGBE_MACCNTCTL_RC, NGBE_MACCNTCTL_RC);
      90                 :            : 
      91                 :            :         wr32m(hw, NGBE_RXFCCFG,
      92                 :            :                 NGBE_RXFCCFG_FC, NGBE_RXFCCFG_FC);
      93                 :            :         wr32m(hw, NGBE_TXFCCFG,
      94                 :            :                 NGBE_TXFCCFG_FC, NGBE_TXFCCFG_FC);
      95                 :            : 
      96                 :            :         wr32m(hw, NGBE_MACRXFLT,
      97                 :            :                 NGBE_MACRXFLT_PROMISC, NGBE_MACRXFLT_PROMISC);
      98                 :            : 
      99                 :            :         wr32m(hw, NGBE_RSTSTAT,
     100                 :            :                 NGBE_RSTSTAT_TMRINIT_MASK, NGBE_RSTSTAT_TMRINIT(30));
     101                 :            : 
     102                 :            :         /* errata 4: initialize mng flex tbl and wakeup flex tbl*/
     103                 :            :         wr32(hw, NGBE_MNGFLEXSEL, 0);
     104         [ #  # ]:          0 :         for (i = 0; i < 16; i++) {
     105                 :          0 :                 wr32(hw, NGBE_MNGFLEXDWL(i), 0);
     106                 :          0 :                 wr32(hw, NGBE_MNGFLEXDWH(i), 0);
     107                 :          0 :                 wr32(hw, NGBE_MNGFLEXMSK(i), 0);
     108                 :            :         }
     109                 :            :         wr32(hw, NGBE_LANFLEXSEL, 0);
     110         [ #  # ]:          0 :         for (i = 0; i < 16; i++) {
     111                 :          0 :                 wr32(hw, NGBE_LANFLEXDWL(i), 0);
     112                 :          0 :                 wr32(hw, NGBE_LANFLEXDWH(i), 0);
     113                 :          0 :                 wr32(hw, NGBE_LANFLEXMSK(i), 0);
     114                 :            :         }
     115                 :            : 
     116                 :            :         /* set pause frame dst mac addr */
     117                 :            :         wr32(hw, NGBE_RXPBPFCDMACL, 0xC2000001);
     118                 :            :         wr32(hw, NGBE_RXPBPFCDMACH, 0x0180);
     119                 :            : 
     120                 :            :         wr32(hw, NGBE_MDIOMODE, 0xF);
     121                 :            : 
     122                 :            :         wr32m(hw, NGBE_GPIE, NGBE_GPIE_MSIX, NGBE_GPIE_MSIX);
     123                 :            : 
     124         [ #  # ]:          0 :         if (hw->gpio_ctl) {
     125                 :            :                 /* gpio0 is used to power on/off control*/
     126                 :            :                 wr32(hw, NGBE_GPIODIR, NGBE_GPIODIR_DDR(1));
     127                 :            :                 wr32(hw, NGBE_GPIODATA, NGBE_GPIOBIT_0);
     128                 :            :         }
     129                 :            : 
     130                 :          0 :         hw->mac.init_thermal_sensor_thresh(hw);
     131                 :            : 
     132                 :            :         /* enable mac transmitter */
     133                 :            :         wr32m(hw, NGBE_MACTXCFG, NGBE_MACTXCFG_TE, NGBE_MACTXCFG_TE);
     134                 :            : 
     135                 :            :         /* sellect GMII */
     136                 :            :         wr32m(hw, NGBE_MACTXCFG,
     137                 :            :                 NGBE_MACTXCFG_SPEED_MASK, NGBE_MACTXCFG_SPEED_1G);
     138                 :            : 
     139         [ #  # ]:          0 :         for (i = 0; i < 4; i++)
     140                 :          0 :                 wr32m(hw, NGBE_IVAR(i), 0x80808080, 0);
     141                 :          0 : }
     142                 :            : 
     143                 :            : /**
     144                 :            :  *  ngbe_reset_hw_em - Perform hardware reset
     145                 :            :  *  @hw: pointer to hardware structure
     146                 :            :  *
     147                 :            :  *  Resets the hardware by resetting the transmit and receive units, masks
     148                 :            :  *  and clears all interrupts, perform a PHY reset, and perform a link (MAC)
     149                 :            :  *  reset.
     150                 :            :  **/
     151                 :          0 : s32 ngbe_reset_hw_em(struct ngbe_hw *hw)
     152                 :            : {
     153                 :            :         s32 status;
     154                 :            : 
     155                 :            :         /* Call adapter stop to disable tx/rx and clear interrupts */
     156                 :          0 :         status = hw->mac.stop_hw(hw);
     157         [ #  # ]:          0 :         if (status != 0)
     158                 :            :                 return status;
     159                 :            : 
     160                 :            :         /* Identify PHY and related function pointers */
     161                 :          0 :         status = ngbe_init_phy(hw);
     162         [ #  # ]:          0 :         if (status)
     163                 :            :                 return status;
     164                 :            : 
     165                 :            :         /* Reset PHY */
     166         [ #  # ]:          0 :         if (!hw->phy.reset_disable)
     167                 :          0 :                 hw->phy.reset_hw(hw);
     168                 :            : 
     169                 :          0 :         wr32(hw, NGBE_RST, NGBE_RST_LAN(hw->bus.lan_id));
     170                 :            :         ngbe_flush(hw);
     171                 :            :         msec_delay(50);
     172                 :            : 
     173                 :          0 :         ngbe_reset_misc_em(hw);
     174                 :          0 :         hw->mac.clear_hw_cntrs(hw);
     175                 :            : 
     176                 :            :         msec_delay(50);
     177                 :            : 
     178                 :            :         /* Store the permanent mac address */
     179                 :          0 :         hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
     180                 :            : 
     181                 :            :         /*
     182                 :            :          * Store MAC address from RAR0, clear receive address registers, and
     183                 :            :          * clear the multicast table.
     184                 :            :          */
     185                 :          0 :         hw->mac.num_rar_entries = NGBE_EM_RAR_ENTRIES;
     186                 :          0 :         hw->mac.init_rx_addrs(hw);
     187                 :            : 
     188                 :          0 :         return status;
     189                 :            : }
     190                 :            : 
     191                 :            : /**
     192                 :            :  *  ngbe_clear_hw_cntrs - Generic clear hardware counters
     193                 :            :  *  @hw: pointer to hardware structure
     194                 :            :  *
     195                 :            :  *  Clears all hardware statistics counters by reading them from the hardware
     196                 :            :  *  Statistics counters are clear on read.
     197                 :            :  **/
     198                 :          0 : s32 ngbe_clear_hw_cntrs(struct ngbe_hw *hw)
     199                 :            : {
     200                 :            :         u16 i = 0;
     201                 :            : 
     202                 :            :         /* QP Stats */
     203                 :            :         /* don't write clear queue stats */
     204         [ #  # ]:          0 :         for (i = 0; i < NGBE_MAX_QP; i++) {
     205                 :          0 :                 hw->qp_last[i].rx_qp_packets = 0;
     206                 :          0 :                 hw->qp_last[i].tx_qp_packets = 0;
     207                 :          0 :                 hw->qp_last[i].rx_qp_bytes = 0;
     208                 :          0 :                 hw->qp_last[i].tx_qp_bytes = 0;
     209                 :          0 :                 hw->qp_last[i].rx_qp_mc_packets = 0;
     210                 :          0 :                 hw->qp_last[i].tx_qp_mc_packets = 0;
     211                 :          0 :                 hw->qp_last[i].rx_qp_bc_packets = 0;
     212                 :          0 :                 hw->qp_last[i].tx_qp_bc_packets = 0;
     213                 :            :         }
     214                 :            : 
     215                 :            :         /* PB Stats */
     216                 :            :         rd32(hw, NGBE_PBRXLNKXON);
     217                 :            :         rd32(hw, NGBE_PBRXLNKXOFF);
     218                 :            :         rd32(hw, NGBE_PBTXLNKXON);
     219                 :            :         rd32(hw, NGBE_PBTXLNKXOFF);
     220                 :            : 
     221                 :            :         /* DMA Stats */
     222                 :            :         rd32(hw, NGBE_DMARXPKT);
     223                 :            :         rd32(hw, NGBE_DMATXPKT);
     224                 :            : 
     225                 :            :         rd64(hw, NGBE_DMARXOCTL);
     226                 :            :         rd64(hw, NGBE_DMATXOCTL);
     227                 :            : 
     228                 :            :         /* MAC Stats */
     229                 :            :         rd64(hw, NGBE_MACRXERRCRCL);
     230                 :            :         rd64(hw, NGBE_MACRXMPKTL);
     231                 :            :         rd64(hw, NGBE_MACTXMPKTL);
     232                 :            : 
     233                 :            :         rd64(hw, NGBE_MACRXPKTL);
     234                 :            :         rd64(hw, NGBE_MACTXPKTL);
     235                 :            :         rd64(hw, NGBE_MACRXGBOCTL);
     236                 :            : 
     237                 :            :         rd64(hw, NGBE_MACRXOCTL);
     238                 :            :         rd32(hw, NGBE_MACTXOCTL);
     239                 :            : 
     240                 :            :         rd64(hw, NGBE_MACRX1TO64L);
     241                 :            :         rd64(hw, NGBE_MACRX65TO127L);
     242                 :            :         rd64(hw, NGBE_MACRX128TO255L);
     243                 :            :         rd64(hw, NGBE_MACRX256TO511L);
     244                 :            :         rd64(hw, NGBE_MACRX512TO1023L);
     245                 :            :         rd64(hw, NGBE_MACRX1024TOMAXL);
     246                 :            :         rd64(hw, NGBE_MACTX1TO64L);
     247                 :            :         rd64(hw, NGBE_MACTX65TO127L);
     248                 :            :         rd64(hw, NGBE_MACTX128TO255L);
     249                 :            :         rd64(hw, NGBE_MACTX256TO511L);
     250                 :            :         rd64(hw, NGBE_MACTX512TO1023L);
     251                 :            :         rd64(hw, NGBE_MACTX1024TOMAXL);
     252                 :            : 
     253                 :            :         rd64(hw, NGBE_MACRXERRLENL);
     254                 :            :         rd32(hw, NGBE_MACRXOVERSIZE);
     255                 :            :         rd32(hw, NGBE_MACRXJABBER);
     256                 :            : 
     257                 :            :         /* MACsec Stats */
     258                 :            :         rd32(hw, NGBE_LSECTX_UTPKT);
     259                 :            :         rd32(hw, NGBE_LSECTX_ENCPKT);
     260                 :            :         rd32(hw, NGBE_LSECTX_PROTPKT);
     261                 :            :         rd32(hw, NGBE_LSECTX_ENCOCT);
     262                 :            :         rd32(hw, NGBE_LSECTX_PROTOCT);
     263                 :            :         rd32(hw, NGBE_LSECRX_UTPKT);
     264                 :            :         rd32(hw, NGBE_LSECRX_BTPKT);
     265                 :            :         rd32(hw, NGBE_LSECRX_NOSCIPKT);
     266                 :            :         rd32(hw, NGBE_LSECRX_UNSCIPKT);
     267                 :            :         rd32(hw, NGBE_LSECRX_DECOCT);
     268                 :            :         rd32(hw, NGBE_LSECRX_VLDOCT);
     269                 :            :         rd32(hw, NGBE_LSECRX_UNCHKPKT);
     270                 :            :         rd32(hw, NGBE_LSECRX_DLYPKT);
     271                 :            :         rd32(hw, NGBE_LSECRX_LATEPKT);
     272         [ #  # ]:          0 :         for (i = 0; i < 2; i++) {
     273                 :          0 :                 rd32(hw, NGBE_LSECRX_OKPKT(i));
     274                 :          0 :                 rd32(hw, NGBE_LSECRX_INVPKT(i));
     275                 :          0 :                 rd32(hw, NGBE_LSECRX_BADPKT(i));
     276                 :            :         }
     277         [ #  # ]:          0 :         for (i = 0; i < 4; i++) {
     278                 :          0 :                 rd32(hw, NGBE_LSECRX_INVSAPKT(i));
     279                 :          0 :                 rd32(hw, NGBE_LSECRX_BADSAPKT(i));
     280                 :            :         }
     281                 :            : 
     282                 :          0 :         return 0;
     283                 :            : }
     284                 :            : 
     285                 :            : /**
     286                 :            :  *  ngbe_get_mac_addr - Generic get MAC address
     287                 :            :  *  @hw: pointer to hardware structure
     288                 :            :  *  @mac_addr: Adapter MAC address
     289                 :            :  *
     290                 :            :  *  Reads the adapter's MAC address from first Receive Address Register (RAR0)
     291                 :            :  *  A reset of the adapter must be performed prior to calling this function
     292                 :            :  *  in order for the MAC address to have been loaded from the EEPROM into RAR0
     293                 :            :  **/
     294                 :          0 : s32 ngbe_get_mac_addr(struct ngbe_hw *hw, u8 *mac_addr)
     295                 :            : {
     296                 :            :         u32 rar_high;
     297                 :            :         u32 rar_low;
     298                 :            :         u16 i;
     299                 :            : 
     300                 :            :         wr32(hw, NGBE_ETHADDRIDX, 0);
     301                 :            :         rar_high = rd32(hw, NGBE_ETHADDRH);
     302                 :            :         rar_low = rd32(hw, NGBE_ETHADDRL);
     303                 :            : 
     304         [ #  # ]:          0 :         for (i = 0; i < 2; i++)
     305                 :          0 :                 mac_addr[i] = (u8)(rar_high >> (1 - i) * 8);
     306                 :            : 
     307         [ #  # ]:          0 :         for (i = 0; i < 4; i++)
     308                 :          0 :                 mac_addr[i + 2] = (u8)(rar_low >> (3 - i) * 8);
     309                 :            : 
     310                 :          0 :         return 0;
     311                 :            : }
     312                 :            : 
     313                 :            : /**
     314                 :            :  *  ngbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
     315                 :            :  *  @hw: pointer to the HW structure
     316                 :            :  *
     317                 :            :  *  Determines the LAN function id by reading memory-mapped registers and swaps
     318                 :            :  *  the port value if requested, and set MAC instance for devices.
     319                 :            :  **/
     320                 :          0 : void ngbe_set_lan_id_multi_port(struct ngbe_hw *hw)
     321                 :            : {
     322                 :            :         struct ngbe_bus_info *bus = &hw->bus;
     323                 :            :         u32 reg = 0;
     324                 :            : 
     325                 :            :         reg = rd32(hw, NGBE_PORTSTAT);
     326                 :          0 :         bus->lan_id = NGBE_PORTSTAT_ID(reg);
     327                 :          0 :         bus->func = bus->lan_id;
     328                 :          0 : }
     329                 :            : 
     330                 :            : /**
     331                 :            :  *  ngbe_stop_hw - Generic stop Tx/Rx units
     332                 :            :  *  @hw: pointer to hardware structure
     333                 :            :  *
     334                 :            :  *  Sets the adapter_stopped flag within ngbe_hw struct. Clears interrupts,
     335                 :            :  *  disables transmit and receive units. The adapter_stopped flag is used by
     336                 :            :  *  the shared code and drivers to determine if the adapter is in a stopped
     337                 :            :  *  state and should not touch the hardware.
     338                 :            :  **/
     339                 :          0 : s32 ngbe_stop_hw(struct ngbe_hw *hw)
     340                 :            : {
     341                 :            :         u16 i;
     342                 :            :         s32 status = 0;
     343                 :            : 
     344                 :            :         /*
     345                 :            :          * Set the adapter_stopped flag so other driver functions stop touching
     346                 :            :          * the hardware
     347                 :            :          */
     348                 :          0 :         hw->adapter_stopped = true;
     349                 :            : 
     350                 :            :         /* Disable the receive unit */
     351                 :          0 :         ngbe_disable_rx(hw);
     352                 :            : 
     353                 :            :         /* Clear interrupt mask to stop interrupts from being generated */
     354                 :            :         wr32(hw, NGBE_IENMISC, 0);
     355                 :            :         wr32(hw, NGBE_IMS(0), NGBE_IMS_MASK);
     356                 :            : 
     357                 :            :         /* Clear any pending interrupts, flush previous writes */
     358                 :            :         wr32(hw, NGBE_ICRMISC, NGBE_ICRMISC_MASK);
     359                 :            :         wr32(hw, NGBE_ICR(0), NGBE_ICR_MASK);
     360                 :            : 
     361                 :            :         wr32(hw, NGBE_BMECTL, 0x3);
     362                 :            : 
     363                 :            :         /* Disable the receive unit by stopping each queue */
     364         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_rx_queues; i++)
     365                 :          0 :                 wr32(hw, NGBE_RXCFG(i), 0);
     366                 :            : 
     367                 :            :         /* flush all queues disables */
     368                 :            :         ngbe_flush(hw);
     369                 :            :         msec_delay(2);
     370                 :            : 
     371                 :            :         /*
     372                 :            :          * Prevent the PCI-E bus from hanging by disabling PCI-E master
     373                 :            :          * access and verify no pending requests
     374                 :            :          */
     375                 :          0 :         status = ngbe_set_pcie_master(hw, false);
     376         [ #  # ]:          0 :         if (status)
     377                 :            :                 return status;
     378                 :            : 
     379                 :            :         /* Disable the transmit unit.  Each queue must be disabled. */
     380         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_tx_queues; i++)
     381                 :          0 :                 wr32(hw, NGBE_TXCFG(i), 0);
     382                 :            : 
     383                 :            :         /* flush all queues disables */
     384                 :            :         ngbe_flush(hw);
     385                 :            :         msec_delay(2);
     386                 :            : 
     387                 :          0 :         return 0;
     388                 :            : }
     389                 :            : 
     390                 :            : /**
     391                 :            :  *  ngbe_led_on - Turns on the software controllable LEDs.
     392                 :            :  *  @hw: pointer to hardware structure
     393                 :            :  *  @index: led number to turn on
     394                 :            :  **/
     395                 :          0 : s32 ngbe_led_on(struct ngbe_hw *hw, u32 index)
     396                 :            : {
     397                 :            :         u32 led_reg = rd32(hw, NGBE_LEDCTL);
     398                 :            : 
     399         [ #  # ]:          0 :         if (index > 3)
     400                 :            :                 return NGBE_ERR_PARAM;
     401                 :            : 
     402                 :            :         /* To turn on the LED, set mode to ON. */
     403                 :          0 :         led_reg |= NGBE_LEDCTL_100M;
     404                 :            :         wr32(hw, NGBE_LEDCTL, led_reg);
     405                 :            :         ngbe_flush(hw);
     406                 :            : 
     407                 :          0 :         return 0;
     408                 :            : }
     409                 :            : 
     410                 :            : /**
     411                 :            :  *  ngbe_led_off - Turns off the software controllable LEDs.
     412                 :            :  *  @hw: pointer to hardware structure
     413                 :            :  *  @index: led number to turn off
     414                 :            :  **/
     415                 :          0 : s32 ngbe_led_off(struct ngbe_hw *hw, u32 index)
     416                 :            : {
     417                 :            :         u32 led_reg = rd32(hw, NGBE_LEDCTL);
     418                 :            : 
     419         [ #  # ]:          0 :         if (index > 3)
     420                 :            :                 return NGBE_ERR_PARAM;
     421                 :            : 
     422                 :            :         /* To turn off the LED, set mode to OFF. */
     423                 :          0 :         led_reg &= ~NGBE_LEDCTL_100M;
     424                 :            :         wr32(hw, NGBE_LEDCTL, led_reg);
     425                 :            :         ngbe_flush(hw);
     426                 :            : 
     427                 :          0 :         return 0;
     428                 :            : }
     429                 :            : 
     430                 :            : /**
     431                 :            :  *  ngbe_validate_mac_addr - Validate MAC address
     432                 :            :  *  @mac_addr: pointer to MAC address.
     433                 :            :  *
     434                 :            :  *  Tests a MAC address to ensure it is a valid Individual Address.
     435                 :            :  **/
     436         [ #  # ]:          0 : s32 ngbe_validate_mac_addr(u8 *mac_addr)
     437                 :            : {
     438                 :            :         s32 status = 0;
     439                 :            : 
     440                 :            :         /* Make sure it is not a multicast address */
     441         [ #  # ]:          0 :         if (NGBE_IS_MULTICAST((struct rte_ether_addr *)mac_addr)) {
     442                 :            :                 status = NGBE_ERR_INVALID_MAC_ADDR;
     443                 :            :         /* Not a broadcast address */
     444         [ #  # ]:          0 :         } else if (NGBE_IS_BROADCAST((struct rte_ether_addr *)mac_addr)) {
     445                 :            :                 status = NGBE_ERR_INVALID_MAC_ADDR;
     446                 :            :         /* Reject the zero address */
     447   [ #  #  #  #  :          0 :         } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
                   #  # ]
     448   [ #  #  #  #  :          0 :                    mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
                   #  # ]
     449                 :            :                 status = NGBE_ERR_INVALID_MAC_ADDR;
     450                 :            :         }
     451                 :          0 :         return status;
     452                 :            : }
     453                 :            : 
     454                 :            : /**
     455                 :            :  *  ngbe_set_rar - Set Rx address register
     456                 :            :  *  @hw: pointer to hardware structure
     457                 :            :  *  @index: Receive address register to write
     458                 :            :  *  @addr: Address to put into receive address register
     459                 :            :  *  @vmdq: VMDq "set" or "pool" index
     460                 :            :  *  @enable_addr: set flag that address is active
     461                 :            :  *
     462                 :            :  *  Puts an ethernet address into a receive address register.
     463                 :            :  **/
     464                 :          0 : s32 ngbe_set_rar(struct ngbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
     465                 :            :                           u32 enable_addr)
     466                 :            : {
     467                 :            :         u32 rar_low, rar_high;
     468                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
     469                 :            : 
     470                 :            :         /* Make sure we are using a valid rar index range */
     471         [ #  # ]:          0 :         if (index >= rar_entries) {
     472                 :          0 :                 DEBUGOUT("RAR index %d is out of range.", index);
     473                 :          0 :                 return NGBE_ERR_INVALID_ARGUMENT;
     474                 :            :         }
     475                 :            : 
     476                 :            :         /* setup VMDq pool selection before this RAR gets enabled */
     477                 :          0 :         hw->mac.set_vmdq(hw, index, vmdq);
     478                 :            : 
     479                 :            :         /*
     480                 :            :          * HW expects these in little endian so we reverse the byte
     481                 :            :          * order from network order (big endian) to little endian
     482                 :            :          */
     483                 :          0 :         rar_low = NGBE_ETHADDRL_AD0(addr[5]) |
     484                 :          0 :                   NGBE_ETHADDRL_AD1(addr[4]) |
     485                 :          0 :                   NGBE_ETHADDRL_AD2(addr[3]) |
     486                 :          0 :                   NGBE_ETHADDRL_AD3(addr[2]);
     487                 :            :         /*
     488                 :            :          * Some parts put the VMDq setting in the extra RAH bits,
     489                 :            :          * so save everything except the lower 16 bits that hold part
     490                 :            :          * of the address and the address valid bit.
     491                 :            :          */
     492                 :            :         rar_high = rd32(hw, NGBE_ETHADDRH);
     493                 :          0 :         rar_high &= ~NGBE_ETHADDRH_AD_MASK;
     494                 :          0 :         rar_high |= (NGBE_ETHADDRH_AD4(addr[1]) |
     495                 :          0 :                      NGBE_ETHADDRH_AD5(addr[0]));
     496                 :            : 
     497                 :          0 :         rar_high &= ~NGBE_ETHADDRH_VLD;
     498         [ #  # ]:          0 :         if (enable_addr != 0)
     499                 :          0 :                 rar_high |= NGBE_ETHADDRH_VLD;
     500                 :            : 
     501                 :            :         wr32(hw, NGBE_ETHADDRIDX, index);
     502                 :            :         wr32(hw, NGBE_ETHADDRL, rar_low);
     503                 :            :         wr32(hw, NGBE_ETHADDRH, rar_high);
     504                 :            : 
     505                 :          0 :         return 0;
     506                 :            : }
     507                 :            : 
     508                 :            : /**
     509                 :            :  *  ngbe_clear_rar - Remove Rx address register
     510                 :            :  *  @hw: pointer to hardware structure
     511                 :            :  *  @index: Receive address register to write
     512                 :            :  *
     513                 :            :  *  Clears an ethernet address from a receive address register.
     514                 :            :  **/
     515                 :          0 : s32 ngbe_clear_rar(struct ngbe_hw *hw, u32 index)
     516                 :            : {
     517                 :            :         u32 rar_high;
     518                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
     519                 :            : 
     520                 :            :         /* Make sure we are using a valid rar index range */
     521         [ #  # ]:          0 :         if (index >= rar_entries) {
     522                 :          0 :                 DEBUGOUT("RAR index %d is out of range.", index);
     523                 :          0 :                 return NGBE_ERR_INVALID_ARGUMENT;
     524                 :            :         }
     525                 :            : 
     526                 :            :         /*
     527                 :            :          * Some parts put the VMDq setting in the extra RAH bits,
     528                 :            :          * so save everything except the lower 16 bits that hold part
     529                 :            :          * of the address and the address valid bit.
     530                 :            :          */
     531                 :            :         wr32(hw, NGBE_ETHADDRIDX, index);
     532                 :            :         rar_high = rd32(hw, NGBE_ETHADDRH);
     533                 :          0 :         rar_high &= ~(NGBE_ETHADDRH_AD_MASK | NGBE_ETHADDRH_VLD);
     534                 :            : 
     535                 :            :         wr32(hw, NGBE_ETHADDRL, 0);
     536                 :            :         wr32(hw, NGBE_ETHADDRH, rar_high);
     537                 :            : 
     538                 :            :         /* clear VMDq pool/queue selection for this RAR */
     539                 :          0 :         hw->mac.clear_vmdq(hw, index, BIT_MASK32);
     540                 :            : 
     541                 :          0 :         return 0;
     542                 :            : }
     543                 :            : 
     544                 :            : /**
     545                 :            :  *  ngbe_init_rx_addrs - Initializes receive address filters.
     546                 :            :  *  @hw: pointer to hardware structure
     547                 :            :  *
     548                 :            :  *  Places the MAC address in receive address register 0 and clears the rest
     549                 :            :  *  of the receive address registers. Clears the multicast table. Assumes
     550                 :            :  *  the receiver is in reset when the routine is called.
     551                 :            :  **/
     552                 :          0 : s32 ngbe_init_rx_addrs(struct ngbe_hw *hw)
     553                 :            : {
     554                 :            :         u32 i;
     555                 :            :         u32 psrctl;
     556                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
     557                 :            : 
     558                 :            :         /*
     559                 :            :          * If the current mac address is valid, assume it is a software override
     560                 :            :          * to the permanent address.
     561                 :            :          * Otherwise, use the permanent address from the eeprom.
     562                 :            :          */
     563         [ #  # ]:          0 :         if (ngbe_validate_mac_addr(hw->mac.addr) ==
     564                 :            :             NGBE_ERR_INVALID_MAC_ADDR) {
     565                 :            :                 /* Get the MAC address from the RAR0 for later reference */
     566                 :          0 :                 hw->mac.get_mac_addr(hw, hw->mac.addr);
     567                 :            : 
     568                 :          0 :                 DEBUGOUT(" Keeping Current RAR0 Addr = "
     569                 :            :                           RTE_ETHER_ADDR_PRT_FMT,
     570                 :            :                           hw->mac.addr[0], hw->mac.addr[1],
     571                 :            :                           hw->mac.addr[2], hw->mac.addr[3],
     572                 :            :                           hw->mac.addr[4], hw->mac.addr[5]);
     573                 :            :         } else {
     574                 :            :                 /* Setup the receive address. */
     575                 :          0 :                 DEBUGOUT("Overriding MAC Address in RAR[0]");
     576                 :          0 :                 DEBUGOUT(" New MAC Addr = "
     577                 :            :                           RTE_ETHER_ADDR_PRT_FMT,
     578                 :            :                           hw->mac.addr[0], hw->mac.addr[1],
     579                 :            :                           hw->mac.addr[2], hw->mac.addr[3],
     580                 :            :                           hw->mac.addr[4], hw->mac.addr[5]);
     581                 :            : 
     582                 :          0 :                 hw->mac.set_rar(hw, 0, hw->mac.addr, 0, true);
     583                 :            :         }
     584                 :            : 
     585                 :            :         /* clear VMDq pool/queue selection for RAR 0 */
     586                 :          0 :         hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
     587                 :            : 
     588                 :            :         /* Zero out the other receive addresses. */
     589                 :          0 :         DEBUGOUT("Clearing RAR[1-%d]", rar_entries - 1);
     590         [ #  # ]:          0 :         for (i = 1; i < rar_entries; i++) {
     591                 :            :                 wr32(hw, NGBE_ETHADDRIDX, i);
     592                 :            :                 wr32(hw, NGBE_ETHADDRL, 0);
     593                 :            :                 wr32(hw, NGBE_ETHADDRH, 0);
     594                 :            :         }
     595                 :            : 
     596                 :            :         /* Clear the MTA */
     597                 :          0 :         hw->addr_ctrl.mta_in_use = 0;
     598                 :            :         psrctl = rd32(hw, NGBE_PSRCTL);
     599                 :          0 :         psrctl &= ~(NGBE_PSRCTL_ADHF12_MASK | NGBE_PSRCTL_MCHFENA);
     600                 :          0 :         psrctl |= NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
     601                 :            :         wr32(hw, NGBE_PSRCTL, psrctl);
     602                 :            : 
     603                 :          0 :         DEBUGOUT(" Clearing MTA");
     604         [ #  # ]:          0 :         for (i = 0; i < hw->mac.mcft_size; i++)
     605                 :          0 :                 wr32(hw, NGBE_MCADDRTBL(i), 0);
     606                 :            : 
     607                 :          0 :         ngbe_init_uta_tables(hw);
     608                 :            : 
     609                 :          0 :         return 0;
     610                 :            : }
     611                 :            : 
     612                 :            : /**
     613                 :            :  *  ngbe_mta_vector - Determines bit-vector in multicast table to set
     614                 :            :  *  @hw: pointer to hardware structure
     615                 :            :  *  @mc_addr: the multicast address
     616                 :            :  *
     617                 :            :  *  Extracts the 12 bits, from a multicast address, to determine which
     618                 :            :  *  bit-vector to set in the multicast table. The hardware uses 12 bits, from
     619                 :            :  *  incoming rx multicast addresses, to determine the bit-vector to check in
     620                 :            :  *  the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
     621                 :            :  *  by the MO field of the PSRCTRL. The MO field is set during initialization
     622                 :            :  *  to mc_filter_type.
     623                 :            :  **/
     624                 :          0 : static s32 ngbe_mta_vector(struct ngbe_hw *hw, u8 *mc_addr)
     625                 :            : {
     626                 :            :         u32 vector = 0;
     627                 :            : 
     628   [ #  #  #  #  :          0 :         switch (hw->mac.mc_filter_type) {
                      # ]
     629                 :          0 :         case 0:   /* use bits [47:36] of the address */
     630                 :          0 :                 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
     631                 :          0 :                 break;
     632                 :          0 :         case 1:   /* use bits [46:35] of the address */
     633                 :          0 :                 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
     634                 :          0 :                 break;
     635                 :          0 :         case 2:   /* use bits [45:34] of the address */
     636                 :          0 :                 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
     637                 :          0 :                 break;
     638                 :          0 :         case 3:   /* use bits [43:32] of the address */
     639                 :          0 :                 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
     640                 :          0 :                 break;
     641                 :          0 :         default:  /* Invalid mc_filter_type */
     642                 :          0 :                 DEBUGOUT("MC filter type param set incorrectly");
     643                 :          0 :                 ASSERT(0);
     644                 :            :                 break;
     645                 :            :         }
     646                 :            : 
     647                 :            :         /* vector can only be 12-bits or boundary will be exceeded */
     648                 :          0 :         vector &= 0xFFF;
     649                 :          0 :         return vector;
     650                 :            : }
     651                 :            : 
     652                 :            : /**
     653                 :            :  *  ngbe_set_mta - Set bit-vector in multicast table
     654                 :            :  *  @hw: pointer to hardware structure
     655                 :            :  *  @mc_addr: Multicast address
     656                 :            :  *
     657                 :            :  *  Sets the bit-vector in the multicast table.
     658                 :            :  **/
     659                 :          0 : void ngbe_set_mta(struct ngbe_hw *hw, u8 *mc_addr)
     660                 :            : {
     661                 :            :         u32 vector;
     662                 :            :         u32 vector_bit;
     663                 :            :         u32 vector_reg;
     664                 :            : 
     665                 :          0 :         hw->addr_ctrl.mta_in_use++;
     666                 :            : 
     667                 :          0 :         vector = ngbe_mta_vector(hw, mc_addr);
     668                 :          0 :         DEBUGOUT(" bit-vector = 0x%03X", vector);
     669                 :            : 
     670                 :            :         /*
     671                 :            :          * The MTA is a register array of 128 32-bit registers. It is treated
     672                 :            :          * like an array of 4096 bits.  We want to set bit
     673                 :            :          * BitArray[vector_value]. So we figure out what register the bit is
     674                 :            :          * in, read it, OR in the new bit, then write back the new value.  The
     675                 :            :          * register is determined by the upper 7 bits of the vector value and
     676                 :            :          * the bit within that register are determined by the lower 5 bits of
     677                 :            :          * the value.
     678                 :            :          */
     679                 :          0 :         vector_reg = (vector >> 5) & 0x7F;
     680                 :          0 :         vector_bit = vector & 0x1F;
     681                 :          0 :         hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
     682                 :          0 : }
     683                 :            : 
     684                 :            : /**
     685                 :            :  *  ngbe_update_mc_addr_list - Updates MAC list of multicast addresses
     686                 :            :  *  @hw: pointer to hardware structure
     687                 :            :  *  @mc_addr_list: the list of new multicast addresses
     688                 :            :  *  @mc_addr_count: number of addresses
     689                 :            :  *  @next: iterator function to walk the multicast address list
     690                 :            :  *  @clear: flag, when set clears the table beforehand
     691                 :            :  *
     692                 :            :  *  When the clear flag is set, the given list replaces any existing list.
     693                 :            :  *  Hashes the given addresses into the multicast table.
     694                 :            :  **/
     695                 :          0 : s32 ngbe_update_mc_addr_list(struct ngbe_hw *hw, u8 *mc_addr_list,
     696                 :            :                                       u32 mc_addr_count, ngbe_mc_addr_itr next,
     697                 :            :                                       bool clear)
     698                 :            : {
     699                 :            :         u32 i;
     700                 :            :         u32 vmdq;
     701                 :            : 
     702                 :            :         /*
     703                 :            :          * Set the new number of MC addresses that we are being requested to
     704                 :            :          * use.
     705                 :            :          */
     706                 :          0 :         hw->addr_ctrl.num_mc_addrs = mc_addr_count;
     707                 :          0 :         hw->addr_ctrl.mta_in_use = 0;
     708                 :            : 
     709                 :            :         /* Clear mta_shadow */
     710         [ #  # ]:          0 :         if (clear) {
     711                 :          0 :                 DEBUGOUT(" Clearing MTA");
     712                 :          0 :                 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
     713                 :            :         }
     714                 :            : 
     715                 :            :         /* Update mta_shadow */
     716         [ #  # ]:          0 :         for (i = 0; i < mc_addr_count; i++) {
     717                 :          0 :                 DEBUGOUT(" Adding the multicast addresses:");
     718                 :          0 :                 ngbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
     719                 :            :         }
     720                 :            : 
     721                 :            :         /* Enable mta */
     722         [ #  # ]:          0 :         for (i = 0; i < hw->mac.mcft_size; i++)
     723                 :          0 :                 wr32a(hw, NGBE_MCADDRTBL(0), i,
     724                 :            :                                       hw->mac.mta_shadow[i]);
     725                 :            : 
     726         [ #  # ]:          0 :         if (hw->addr_ctrl.mta_in_use > 0) {
     727                 :            :                 u32 psrctl = rd32(hw, NGBE_PSRCTL);
     728                 :          0 :                 psrctl &= ~(NGBE_PSRCTL_ADHF12_MASK | NGBE_PSRCTL_MCHFENA);
     729                 :          0 :                 psrctl |= NGBE_PSRCTL_MCHFENA |
     730                 :          0 :                          NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
     731                 :            :                 wr32(hw, NGBE_PSRCTL, psrctl);
     732                 :            :         }
     733                 :            : 
     734                 :          0 :         DEBUGOUT("ngbe update mc addr list complete");
     735                 :          0 :         return 0;
     736                 :            : }
     737                 :            : 
     738                 :            : /**
     739                 :            :  *  ngbe_setup_fc_em - Set up flow control
     740                 :            :  *  @hw: pointer to hardware structure
     741                 :            :  *
     742                 :            :  *  Called at init time to set up flow control.
     743                 :            :  **/
     744                 :          0 : s32 ngbe_setup_fc_em(struct ngbe_hw *hw)
     745                 :            : {
     746                 :            :         s32 err = 0;
     747                 :            :         u16 reg_cu = 0;
     748                 :            : 
     749                 :            :         /* Validate the requested mode */
     750   [ #  #  #  # ]:          0 :         if (hw->fc.strict_ieee && hw->fc.requested_mode == ngbe_fc_rx_pause) {
     751                 :          0 :                 DEBUGOUT("ngbe_fc_rx_pause not valid in strict IEEE mode");
     752                 :            :                 err = NGBE_ERR_INVALID_LINK_SETTINGS;
     753                 :          0 :                 goto out;
     754                 :            :         }
     755                 :            : 
     756                 :            :         /*
     757                 :            :          * 1gig parts do not have a word in the EEPROM to determine the
     758                 :            :          * default flow control setting, so we explicitly set it to full.
     759                 :            :          */
     760         [ #  # ]:          0 :         if (hw->fc.requested_mode == ngbe_fc_default)
     761                 :          0 :                 hw->fc.requested_mode = ngbe_fc_full;
     762                 :            : 
     763                 :            :         /*
     764                 :            :          * The possible values of fc.requested_mode are:
     765                 :            :          * 0: Flow control is completely disabled
     766                 :            :          * 1: Rx flow control is enabled (we can receive pause frames,
     767                 :            :          *    but not send pause frames).
     768                 :            :          * 2: Tx flow control is enabled (we can send pause frames but
     769                 :            :          *    we do not support receiving pause frames).
     770                 :            :          * 3: Both Rx and Tx flow control (symmetric) are enabled.
     771                 :            :          * other: Invalid.
     772                 :            :          */
     773   [ #  #  #  # ]:          0 :         switch (hw->fc.requested_mode) {
     774                 :            :         case ngbe_fc_none:
     775                 :            :                 /* Flow control completely disabled by software override. */
     776                 :            :                 break;
     777                 :          0 :         case ngbe_fc_tx_pause:
     778                 :            :                 /*
     779                 :            :                  * Tx Flow control is enabled, and Rx Flow control is
     780                 :            :                  * disabled by software override.
     781                 :            :                  */
     782         [ #  # ]:          0 :                 if (hw->phy.type == ngbe_phy_mvl_sfi ||
     783                 :            :                         hw->phy.type == ngbe_phy_yt8521s_sfi)
     784                 :            :                         reg_cu |= MVL_FANA_ASM_PAUSE;
     785                 :            :                 else
     786                 :            :                         reg_cu |= 0x800; /*need to merge rtl and mvl on page 0*/
     787                 :            :                 break;
     788                 :          0 :         case ngbe_fc_rx_pause:
     789                 :            :                 /*
     790                 :            :                  * Rx Flow control is enabled and Tx Flow control is
     791                 :            :                  * disabled by software override. Since there really
     792                 :            :                  * isn't a way to advertise that we are capable of RX
     793                 :            :                  * Pause ONLY, we will advertise that we support both
     794                 :            :                  * symmetric and asymmetric Rx PAUSE, as such we fall
     795                 :            :                  * through to the fc_full statement.  Later, we will
     796                 :            :                  * disable the adapter's ability to send PAUSE frames.
     797                 :            :                  */
     798                 :            :         case ngbe_fc_full:
     799                 :            :                 /* Flow control (both Rx and Tx) is enabled by SW override. */
     800         [ #  # ]:          0 :                 if (hw->phy.type == ngbe_phy_mvl_sfi ||
     801                 :            :                         hw->phy.type == ngbe_phy_yt8521s_sfi)
     802                 :            :                         reg_cu |= MVL_FANA_SYM_PAUSE;
     803                 :            :                 else
     804                 :            :                         reg_cu |= 0xC00; /*need to merge rtl and mvl on page 0*/
     805                 :            :                 break;
     806                 :          0 :         default:
     807                 :          0 :                 DEBUGOUT("Flow control param set incorrectly");
     808                 :            :                 err = NGBE_ERR_CONFIG;
     809                 :          0 :                 goto out;
     810                 :            :         }
     811                 :            : 
     812                 :          0 :         err = hw->phy.set_pause_adv(hw, reg_cu);
     813                 :            : 
     814                 :          0 : out:
     815                 :          0 :         return err;
     816                 :            : }
     817                 :            : 
     818                 :            : /**
     819                 :            :  *  ngbe_fc_enable - Enable flow control
     820                 :            :  *  @hw: pointer to hardware structure
     821                 :            :  *
     822                 :            :  *  Enable flow control according to the current settings.
     823                 :            :  **/
     824                 :          0 : s32 ngbe_fc_enable(struct ngbe_hw *hw)
     825                 :            : {
     826                 :            :         s32 err = 0;
     827                 :            :         u32 mflcn_reg, fccfg_reg;
     828                 :            :         u32 pause_time;
     829                 :            :         u32 fcrtl, fcrth;
     830                 :            : 
     831                 :            :         /* Validate the water mark configuration */
     832         [ #  # ]:          0 :         if (!hw->fc.pause_time) {
     833                 :            :                 err = NGBE_ERR_INVALID_LINK_SETTINGS;
     834                 :          0 :                 goto out;
     835                 :            :         }
     836                 :            : 
     837                 :            :         /* Low water mark of zero causes XOFF floods */
     838   [ #  #  #  # ]:          0 :         if ((hw->fc.current_mode & ngbe_fc_tx_pause) && hw->fc.high_water) {
     839   [ #  #  #  # ]:          0 :                 if (!hw->fc.low_water ||
     840                 :            :                         hw->fc.low_water >= hw->fc.high_water) {
     841                 :          0 :                         DEBUGOUT("Invalid water mark configuration");
     842                 :            :                         err = NGBE_ERR_INVALID_LINK_SETTINGS;
     843                 :          0 :                         goto out;
     844                 :            :                 }
     845                 :            :         }
     846                 :            : 
     847                 :            :         /* Negotiate the fc mode to use */
     848                 :          0 :         hw->mac.fc_autoneg(hw);
     849                 :            : 
     850                 :            :         /* Disable any previous flow control settings */
     851                 :            :         mflcn_reg = rd32(hw, NGBE_RXFCCFG);
     852                 :          0 :         mflcn_reg &= ~NGBE_RXFCCFG_FC;
     853                 :            : 
     854                 :            :         fccfg_reg = rd32(hw, NGBE_TXFCCFG);
     855                 :          0 :         fccfg_reg &= ~NGBE_TXFCCFG_FC;
     856                 :            :         /*
     857                 :            :          * The possible values of fc.current_mode are:
     858                 :            :          * 0: Flow control is completely disabled
     859                 :            :          * 1: Rx flow control is enabled (we can receive pause frames,
     860                 :            :          *    but not send pause frames).
     861                 :            :          * 2: Tx flow control is enabled (we can send pause frames but
     862                 :            :          *    we do not support receiving pause frames).
     863                 :            :          * 3: Both Rx and Tx flow control (symmetric) are enabled.
     864                 :            :          * other: Invalid.
     865                 :            :          */
     866   [ #  #  #  #  :          0 :         switch (hw->fc.current_mode) {
                      # ]
     867                 :            :         case ngbe_fc_none:
     868                 :            :                 /*
     869                 :            :                  * Flow control is disabled by software override or autoneg.
     870                 :            :                  * The code below will actually disable it in the HW.
     871                 :            :                  */
     872                 :            :                 break;
     873                 :          0 :         case ngbe_fc_rx_pause:
     874                 :            :                 /*
     875                 :            :                  * Rx Flow control is enabled and Tx Flow control is
     876                 :            :                  * disabled by software override. Since there really
     877                 :            :                  * isn't a way to advertise that we are capable of RX
     878                 :            :                  * Pause ONLY, we will advertise that we support both
     879                 :            :                  * symmetric and asymmetric Rx PAUSE.  Later, we will
     880                 :            :                  * disable the adapter's ability to send PAUSE frames.
     881                 :            :                  */
     882                 :          0 :                 mflcn_reg |= NGBE_RXFCCFG_FC;
     883                 :          0 :                 break;
     884                 :          0 :         case ngbe_fc_tx_pause:
     885                 :            :                 /*
     886                 :            :                  * Tx Flow control is enabled, and Rx Flow control is
     887                 :            :                  * disabled by software override.
     888                 :            :                  */
     889                 :          0 :                 fccfg_reg |= NGBE_TXFCCFG_FC;
     890                 :          0 :                 break;
     891                 :          0 :         case ngbe_fc_full:
     892                 :            :                 /* Flow control (both Rx and Tx) is enabled by SW override. */
     893                 :          0 :                 mflcn_reg |= NGBE_RXFCCFG_FC;
     894                 :          0 :                 fccfg_reg |= NGBE_TXFCCFG_FC;
     895                 :          0 :                 break;
     896                 :          0 :         default:
     897                 :          0 :                 DEBUGOUT("Flow control param set incorrectly");
     898                 :            :                 err = NGBE_ERR_CONFIG;
     899                 :          0 :                 goto out;
     900                 :            :         }
     901                 :            : 
     902                 :            :         /* Set 802.3x based flow control settings. */
     903                 :            :         wr32(hw, NGBE_RXFCCFG, mflcn_reg);
     904                 :            :         wr32(hw, NGBE_TXFCCFG, fccfg_reg);
     905                 :            : 
     906                 :            :         /* Set up and enable Rx high/low water mark thresholds, enable XON. */
     907         [ #  # ]:          0 :         if ((hw->fc.current_mode & ngbe_fc_tx_pause) &&
     908         [ #  # ]:          0 :                 hw->fc.high_water) {
     909                 :          0 :                 fcrtl = NGBE_FCWTRLO_TH(hw->fc.low_water) |
     910                 :            :                         NGBE_FCWTRLO_XON;
     911                 :          0 :                 fcrth = NGBE_FCWTRHI_TH(hw->fc.high_water) |
     912                 :            :                         NGBE_FCWTRHI_XOFF;
     913                 :            :         } else {
     914                 :            :                 /*
     915                 :            :                  * In order to prevent Tx hangs when the internal Tx
     916                 :            :                  * switch is enabled we must set the high water mark
     917                 :            :                  * to the Rx packet buffer size - 24KB.  This allows
     918                 :            :                  * the Tx switch to function even under heavy Rx
     919                 :            :                  * workloads.
     920                 :            :                  */
     921                 :            :                 fcrtl = 0;
     922                 :          0 :                 fcrth = rd32(hw, NGBE_PBRXSIZE) - 24576;
     923                 :            :         }
     924                 :            :         wr32(hw, NGBE_FCWTRLO, fcrtl);
     925                 :            :         wr32(hw, NGBE_FCWTRHI, fcrth);
     926                 :            : 
     927                 :            :         /* Configure pause time */
     928                 :          0 :         pause_time = NGBE_RXFCFSH_TIME(hw->fc.pause_time);
     929                 :          0 :         wr32(hw, NGBE_FCXOFFTM, pause_time * 0x00010000);
     930                 :            : 
     931                 :            :         /* Configure flow control refresh threshold value */
     932                 :          0 :         wr32(hw, NGBE_RXFCRFSH, hw->fc.pause_time / 2);
     933                 :            : 
     934                 :          0 : out:
     935                 :          0 :         return err;
     936                 :            : }
     937                 :            : 
     938                 :            : /**
     939                 :            :  *  ngbe_negotiate_fc - Negotiate flow control
     940                 :            :  *  @hw: pointer to hardware structure
     941                 :            :  *  @adv_reg: flow control advertised settings
     942                 :            :  *  @lp_reg: link partner's flow control settings
     943                 :            :  *  @adv_sym: symmetric pause bit in advertisement
     944                 :            :  *  @adv_asm: asymmetric pause bit in advertisement
     945                 :            :  *  @lp_sym: symmetric pause bit in link partner advertisement
     946                 :            :  *  @lp_asm: asymmetric pause bit in link partner advertisement
     947                 :            :  *
     948                 :            :  *  Find the intersection between advertised settings and link partner's
     949                 :            :  *  advertised settings
     950                 :            :  **/
     951                 :          0 : s32 ngbe_negotiate_fc(struct ngbe_hw *hw, u32 adv_reg, u32 lp_reg,
     952                 :            :                        u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
     953                 :            : {
     954         [ #  # ]:          0 :         if ((!(adv_reg)) ||  (!(lp_reg))) {
     955                 :          0 :                 DEBUGOUT("Local or link partner's advertised flow control settings are NULL. Local: %x, link partner: %x",
     956                 :            :                               adv_reg, lp_reg);
     957                 :          0 :                 return NGBE_ERR_FC_NOT_NEGOTIATED;
     958                 :            :         }
     959                 :            : 
     960   [ #  #  #  # ]:          0 :         if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
     961                 :            :                 /*
     962                 :            :                  * Now we need to check if the user selected Rx ONLY
     963                 :            :                  * of pause frames.  In this case, we had to advertise
     964                 :            :                  * FULL flow control because we could not advertise RX
     965                 :            :                  * ONLY. Hence, we must now check to see if we need to
     966                 :            :                  * turn OFF the TRANSMISSION of PAUSE frames.
     967                 :            :                  */
     968         [ #  # ]:          0 :                 if (hw->fc.requested_mode == ngbe_fc_full) {
     969                 :          0 :                         hw->fc.current_mode = ngbe_fc_full;
     970                 :          0 :                         DEBUGOUT("Flow Control = FULL.");
     971                 :            :                 } else {
     972                 :          0 :                         hw->fc.current_mode = ngbe_fc_rx_pause;
     973                 :          0 :                         DEBUGOUT("Flow Control=RX PAUSE frames only");
     974                 :            :                 }
     975   [ #  #  #  # ]:          0 :         } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
     976   [ #  #  #  # ]:          0 :                    (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
     977                 :          0 :                 hw->fc.current_mode = ngbe_fc_tx_pause;
     978                 :          0 :                 DEBUGOUT("Flow Control = TX PAUSE frames only.");
     979   [ #  #  #  # ]:          0 :         } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
     980   [ #  #  #  # ]:          0 :                    !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
     981                 :          0 :                 hw->fc.current_mode = ngbe_fc_rx_pause;
     982                 :          0 :                 DEBUGOUT("Flow Control = RX PAUSE frames only.");
     983                 :            :         } else {
     984                 :          0 :                 hw->fc.current_mode = ngbe_fc_none;
     985                 :          0 :                 DEBUGOUT("Flow Control = NONE.");
     986                 :            :         }
     987                 :            :         return 0;
     988                 :            : }
     989                 :            : 
     990                 :            : /**
     991                 :            :  *  ngbe_fc_autoneg_em - Enable flow control IEEE clause 37
     992                 :            :  *  @hw: pointer to hardware structure
     993                 :            :  *
     994                 :            :  *  Enable flow control according to IEEE clause 37.
     995                 :            :  **/
     996                 :          0 : STATIC s32 ngbe_fc_autoneg_em(struct ngbe_hw *hw)
     997                 :            : {
     998                 :          0 :         u8 technology_ability_reg = 0;
     999                 :          0 :         u8 lp_technology_ability_reg = 0;
    1000                 :            : 
    1001                 :          0 :         hw->phy.get_adv_pause(hw, &technology_ability_reg);
    1002                 :          0 :         hw->phy.get_lp_adv_pause(hw, &lp_technology_ability_reg);
    1003                 :            : 
    1004                 :          0 :         return ngbe_negotiate_fc(hw, (u32)technology_ability_reg,
    1005                 :            :                                   (u32)lp_technology_ability_reg,
    1006                 :            :                                   NGBE_TAF_SYM_PAUSE, NGBE_TAF_ASM_PAUSE,
    1007                 :            :                                   NGBE_TAF_SYM_PAUSE, NGBE_TAF_ASM_PAUSE);
    1008                 :            : }
    1009                 :            : 
    1010                 :            : /**
    1011                 :            :  *  ngbe_fc_autoneg - Configure flow control
    1012                 :            :  *  @hw: pointer to hardware structure
    1013                 :            :  *
    1014                 :            :  *  Compares our advertised flow control capabilities to those advertised by
    1015                 :            :  *  our link partner, and determines the proper flow control mode to use.
    1016                 :            :  **/
    1017                 :          0 : void ngbe_fc_autoneg(struct ngbe_hw *hw)
    1018                 :            : {
    1019                 :            :         s32 err = NGBE_ERR_FC_NOT_NEGOTIATED;
    1020                 :            :         u32 speed;
    1021                 :            :         bool link_up;
    1022                 :            : 
    1023                 :            :         /*
    1024                 :            :          * AN should have completed when the cable was plugged in.
    1025                 :            :          * Look for reasons to bail out.  Bail out if:
    1026                 :            :          * - FC autoneg is disabled, or if
    1027                 :            :          * - link is not up.
    1028                 :            :          */
    1029         [ #  # ]:          0 :         if (hw->fc.disable_fc_autoneg) {
    1030                 :          0 :                 DEBUGOUT("Flow control autoneg is disabled");
    1031                 :          0 :                 goto out;
    1032                 :            :         }
    1033                 :            : 
    1034                 :          0 :         hw->mac.check_link(hw, &speed, &link_up, false);
    1035         [ #  # ]:          0 :         if (!link_up) {
    1036                 :          0 :                 DEBUGOUT("The link is down");
    1037                 :          0 :                 goto out;
    1038                 :            :         }
    1039                 :            : 
    1040                 :          0 :         err = ngbe_fc_autoneg_em(hw);
    1041                 :            : 
    1042                 :            : out:
    1043         [ #  # ]:          0 :         if (err == 0) {
    1044                 :          0 :                 hw->fc.fc_was_autonegged = true;
    1045                 :            :         } else {
    1046                 :          0 :                 hw->fc.fc_was_autonegged = false;
    1047                 :          0 :                 hw->fc.current_mode = hw->fc.requested_mode;
    1048                 :            :         }
    1049                 :          0 : }
    1050                 :            : 
    1051                 :            : /**
    1052                 :            :  *  ngbe_set_pcie_master - Disable or Enable PCI-express master access
    1053                 :            :  *  @hw: pointer to hardware structure
    1054                 :            :  *
    1055                 :            :  *  Disables PCI-Express master access and verifies there are no pending
    1056                 :            :  *  requests. NGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
    1057                 :            :  *  bit hasn't caused the master requests to be disabled, else 0
    1058                 :            :  *  is returned signifying master requests disabled.
    1059                 :            :  **/
    1060                 :          0 : s32 ngbe_set_pcie_master(struct ngbe_hw *hw, bool enable)
    1061                 :            : {
    1062                 :          0 :         struct rte_pci_device *pci_dev = (struct rte_pci_device *)hw->back;
    1063                 :            :         s32 status = 0;
    1064                 :            :         u32 i;
    1065                 :            : 
    1066         [ #  # ]:          0 :         if (rte_pci_set_bus_master(pci_dev, enable) < 0) {
    1067                 :          0 :                 DEBUGOUT("Cannot configure PCI bus master\n");
    1068                 :          0 :                 return -1;
    1069                 :            :         }
    1070                 :            : 
    1071         [ #  # ]:          0 :         if (enable)
    1072                 :          0 :                 goto out;
    1073                 :            : 
    1074                 :            :         /* Exit if master requests are blocked */
    1075         [ #  # ]:          0 :         if (!(rd32(hw, NGBE_BMEPEND)) ||
    1076                 :            :             NGBE_REMOVED(hw->hw_addr))
    1077                 :          0 :                 goto out;
    1078                 :            : 
    1079                 :            :         /* Poll for master request bit to clear */
    1080         [ #  # ]:          0 :         for (i = 0; i < NGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
    1081                 :          0 :                 usec_delay(100);
    1082         [ #  # ]:          0 :                 if (!(rd32(hw, NGBE_BMEPEND)))
    1083                 :          0 :                         goto out;
    1084                 :            :         }
    1085                 :            : 
    1086                 :          0 :         DEBUGOUT("PCIe transaction pending bit also did not clear.");
    1087                 :            :         status = NGBE_ERR_MASTER_REQUESTS_PENDING;
    1088                 :            : 
    1089                 :            : out:
    1090                 :            :         return status;
    1091                 :            : }
    1092                 :            : 
    1093                 :            : /**
    1094                 :            :  *  ngbe_acquire_swfw_sync - Acquire SWFW semaphore
    1095                 :            :  *  @hw: pointer to hardware structure
    1096                 :            :  *  @mask: Mask to specify which semaphore to acquire
    1097                 :            :  *
    1098                 :            :  *  Acquires the SWFW semaphore through the MNGSEM register for the specified
    1099                 :            :  *  function (CSR, PHY0, PHY1, EEPROM, Flash)
    1100                 :            :  **/
    1101                 :          0 : s32 ngbe_acquire_swfw_sync(struct ngbe_hw *hw, u32 mask)
    1102                 :            : {
    1103                 :            :         u32 mngsem = 0;
    1104                 :            :         u32 fwsm = 0;
    1105                 :          0 :         u32 swmask = NGBE_MNGSEM_SW(mask);
    1106                 :          0 :         u32 fwmask = NGBE_MNGSEM_FW(mask);
    1107                 :            :         u32 timeout = 200;
    1108                 :            :         u32 i;
    1109                 :            : 
    1110         [ #  # ]:          0 :         for (i = 0; i < timeout; i++) {
    1111                 :            :                 /*
    1112                 :            :                  * SW NVM semaphore bit is used for access to all
    1113                 :            :                  * SW_FW_SYNC bits (not just NVM)
    1114                 :            :                  */
    1115         [ #  # ]:          0 :                 if (ngbe_get_eeprom_semaphore(hw))
    1116                 :            :                         return NGBE_ERR_SWFW_SYNC;
    1117                 :            : 
    1118                 :            :                 mngsem = rd32(hw, NGBE_MNGSEM);
    1119         [ #  # ]:          0 :                 if (mngsem & (fwmask | swmask)) {
    1120                 :            :                         /* Resource is currently in use by FW or SW */
    1121                 :          0 :                         ngbe_release_eeprom_semaphore(hw);
    1122                 :            :                         msec_delay(5);
    1123                 :            :                 } else {
    1124                 :          0 :                         mngsem |= swmask;
    1125                 :            :                         wr32(hw, NGBE_MNGSEM, mngsem);
    1126                 :          0 :                         ngbe_release_eeprom_semaphore(hw);
    1127                 :          0 :                         return 0;
    1128                 :            :                 }
    1129                 :            :         }
    1130                 :            : 
    1131                 :            :         fwsm = rd32(hw, NGBE_MNGFWSYNC);
    1132                 :          0 :         DEBUGOUT("SWFW semaphore not granted: MNG_SWFW_SYNC = 0x%x, MNG_FW_SM = 0x%x",
    1133                 :            :                         mngsem, fwsm);
    1134                 :            : 
    1135                 :            :         msec_delay(5);
    1136                 :          0 :         return NGBE_ERR_SWFW_SYNC;
    1137                 :            : }
    1138                 :            : 
    1139                 :            : /**
    1140                 :            :  *  ngbe_release_swfw_sync - Release SWFW semaphore
    1141                 :            :  *  @hw: pointer to hardware structure
    1142                 :            :  *  @mask: Mask to specify which semaphore to release
    1143                 :            :  *
    1144                 :            :  *  Releases the SWFW semaphore through the MNGSEM register for the specified
    1145                 :            :  *  function (CSR, PHY0, PHY1, EEPROM, Flash)
    1146                 :            :  **/
    1147                 :          0 : void ngbe_release_swfw_sync(struct ngbe_hw *hw, u32 mask)
    1148                 :            : {
    1149                 :            :         u32 mngsem;
    1150                 :            :         u32 swmask = mask;
    1151                 :            : 
    1152                 :          0 :         ngbe_get_eeprom_semaphore(hw);
    1153                 :            : 
    1154                 :            :         mngsem = rd32(hw, NGBE_MNGSEM);
    1155                 :          0 :         mngsem &= ~swmask;
    1156                 :            :         wr32(hw, NGBE_MNGSEM, mngsem);
    1157                 :            : 
    1158                 :          0 :         ngbe_release_eeprom_semaphore(hw);
    1159                 :          0 : }
    1160                 :            : 
    1161                 :            : /**
    1162                 :            :  *  ngbe_disable_sec_rx_path - Stops the receive data path
    1163                 :            :  *  @hw: pointer to hardware structure
    1164                 :            :  *
    1165                 :            :  *  Stops the receive data path and waits for the HW to internally empty
    1166                 :            :  *  the Rx security block
    1167                 :            :  **/
    1168                 :          0 : s32 ngbe_disable_sec_rx_path(struct ngbe_hw *hw)
    1169                 :            : {
    1170                 :            : #define NGBE_MAX_SECRX_POLL 4000
    1171                 :            : 
    1172                 :            :         int i;
    1173                 :            :         u32 secrxreg;
    1174                 :            : 
    1175                 :            :         secrxreg = rd32(hw, NGBE_SECRXCTL);
    1176                 :          0 :         secrxreg |= NGBE_SECRXCTL_XDSA;
    1177                 :            :         wr32(hw, NGBE_SECRXCTL, secrxreg);
    1178         [ #  # ]:          0 :         for (i = 0; i < NGBE_MAX_SECRX_POLL; i++) {
    1179                 :            :                 secrxreg = rd32(hw, NGBE_SECRXSTAT);
    1180         [ #  # ]:          0 :                 if (!(secrxreg & NGBE_SECRXSTAT_RDY))
    1181                 :            :                         /* Use interrupt-safe sleep just in case */
    1182                 :          0 :                         usec_delay(10);
    1183                 :            :                 else
    1184                 :            :                         break;
    1185                 :            :         }
    1186                 :            : 
    1187                 :            :         /* For informational purposes only */
    1188         [ #  # ]:          0 :         if (i >= NGBE_MAX_SECRX_POLL)
    1189                 :          0 :                 DEBUGOUT("Rx unit being enabled before security path fully disabled.  Continuing with init.");
    1190                 :            : 
    1191                 :          0 :         return 0;
    1192                 :            : }
    1193                 :            : 
    1194                 :            : /**
    1195                 :            :  *  ngbe_enable_sec_rx_path - Enables the receive data path
    1196                 :            :  *  @hw: pointer to hardware structure
    1197                 :            :  *
    1198                 :            :  *  Enables the receive data path.
    1199                 :            :  **/
    1200                 :          0 : s32 ngbe_enable_sec_rx_path(struct ngbe_hw *hw)
    1201                 :            : {
    1202                 :            :         u32 secrxreg;
    1203                 :            : 
    1204                 :            :         secrxreg = rd32(hw, NGBE_SECRXCTL);
    1205                 :          0 :         secrxreg &= ~NGBE_SECRXCTL_XDSA;
    1206                 :            :         wr32(hw, NGBE_SECRXCTL, secrxreg);
    1207                 :            :         ngbe_flush(hw);
    1208                 :            : 
    1209                 :          0 :         return 0;
    1210                 :            : }
    1211                 :            : 
    1212                 :            : /**
    1213                 :            :  *  ngbe_clear_vmdq - Disassociate a VMDq pool index from a rx address
    1214                 :            :  *  @hw: pointer to hardware struct
    1215                 :            :  *  @rar: receive address register index to disassociate
    1216                 :            :  *  @vmdq: VMDq pool index to remove from the rar
    1217                 :            :  **/
    1218                 :          0 : s32 ngbe_clear_vmdq(struct ngbe_hw *hw, u32 rar, u32 vmdq)
    1219                 :            : {
    1220                 :            :         u32 mpsar;
    1221                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
    1222                 :            : 
    1223                 :            :         /* Make sure we are using a valid rar index range */
    1224         [ #  # ]:          0 :         if (rar >= rar_entries) {
    1225                 :          0 :                 DEBUGOUT("RAR index %d is out of range.", rar);
    1226                 :          0 :                 return NGBE_ERR_INVALID_ARGUMENT;
    1227                 :            :         }
    1228                 :            : 
    1229                 :            :         wr32(hw, NGBE_ETHADDRIDX, rar);
    1230                 :            :         mpsar = rd32(hw, NGBE_ETHADDRASS);
    1231                 :            : 
    1232                 :            :         if (NGBE_REMOVED(hw->hw_addr))
    1233                 :            :                 goto done;
    1234                 :            : 
    1235         [ #  # ]:          0 :         if (!mpsar)
    1236                 :          0 :                 goto done;
    1237                 :            : 
    1238                 :          0 :         mpsar &= ~(1 << vmdq);
    1239                 :            :         wr32(hw, NGBE_ETHADDRASS, mpsar);
    1240                 :            : 
    1241                 :            :         /* was that the last pool using this rar? */
    1242         [ #  # ]:          0 :         if (mpsar == 0 && rar != 0)
    1243                 :          0 :                 hw->mac.clear_rar(hw, rar);
    1244                 :          0 : done:
    1245                 :            :         return 0;
    1246                 :            : }
    1247                 :            : 
    1248                 :            : /**
    1249                 :            :  *  ngbe_set_vmdq - Associate a VMDq pool index with a rx address
    1250                 :            :  *  @hw: pointer to hardware struct
    1251                 :            :  *  @rar: receive address register index to associate with a VMDq index
    1252                 :            :  *  @vmdq: VMDq pool index
    1253                 :            :  **/
    1254                 :          0 : s32 ngbe_set_vmdq(struct ngbe_hw *hw, u32 rar, u32 vmdq)
    1255                 :            : {
    1256                 :            :         u32 mpsar;
    1257                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
    1258                 :            : 
    1259                 :            :         /* Make sure we are using a valid rar index range */
    1260         [ #  # ]:          0 :         if (rar >= rar_entries) {
    1261                 :          0 :                 DEBUGOUT("RAR index %d is out of range.", rar);
    1262                 :          0 :                 return NGBE_ERR_INVALID_ARGUMENT;
    1263                 :            :         }
    1264                 :            : 
    1265                 :            :         wr32(hw, NGBE_ETHADDRIDX, rar);
    1266                 :            : 
    1267                 :            :         mpsar = rd32(hw, NGBE_ETHADDRASS);
    1268                 :          0 :         mpsar |= 1 << vmdq;
    1269                 :            :         wr32(hw, NGBE_ETHADDRASS, mpsar);
    1270                 :            : 
    1271                 :          0 :         return 0;
    1272                 :            : }
    1273                 :            : 
    1274                 :            : /**
    1275                 :            :  *  ngbe_init_uta_tables - Initialize the Unicast Table Array
    1276                 :            :  *  @hw: pointer to hardware structure
    1277                 :            :  **/
    1278                 :          0 : s32 ngbe_init_uta_tables(struct ngbe_hw *hw)
    1279                 :            : {
    1280                 :            :         int i;
    1281                 :            : 
    1282                 :          0 :         DEBUGOUT(" Clearing UTA");
    1283                 :            : 
    1284         [ #  # ]:          0 :         for (i = 0; i < 128; i++)
    1285                 :          0 :                 wr32(hw, NGBE_UCADDRTBL(i), 0);
    1286                 :            : 
    1287                 :          0 :         return 0;
    1288                 :            : }
    1289                 :            : 
    1290                 :            : /**
    1291                 :            :  *  ngbe_find_vlvf_slot - find the vlanid or the first empty slot
    1292                 :            :  *  @hw: pointer to hardware structure
    1293                 :            :  *  @vlan: VLAN id to write to VLAN filter
    1294                 :            :  *  @vlvf_bypass: true to find vlanid only, false returns first empty slot if
    1295                 :            :  *                vlanid not found
    1296                 :            :  *
    1297                 :            :  *
    1298                 :            :  *  return the VLVF index where this VLAN id should be placed
    1299                 :            :  *
    1300                 :            :  **/
    1301                 :          0 : s32 ngbe_find_vlvf_slot(struct ngbe_hw *hw, u32 vlan, bool vlvf_bypass)
    1302                 :            : {
    1303                 :            :         s32 regindex, first_empty_slot;
    1304                 :            :         u32 bits;
    1305                 :            : 
    1306                 :            :         /* short cut the special case */
    1307         [ #  # ]:          0 :         if (vlan == 0)
    1308                 :            :                 return 0;
    1309                 :            : 
    1310                 :            :         /* if vlvf_bypass is set we don't want to use an empty slot, we
    1311                 :            :          * will simply bypass the VLVF if there are no entries present in the
    1312                 :            :          * VLVF that contain our VLAN
    1313                 :            :          */
    1314         [ #  # ]:          0 :         first_empty_slot = vlvf_bypass ? NGBE_ERR_NO_SPACE : 0;
    1315                 :            : 
    1316                 :            :         /* add VLAN enable bit for comparison */
    1317                 :          0 :         vlan |= NGBE_PSRVLAN_EA;
    1318                 :            : 
    1319                 :            :         /* Search for the vlan id in the VLVF entries. Save off the first empty
    1320                 :            :          * slot found along the way.
    1321                 :            :          *
    1322                 :            :          * pre-decrement loop covering (NGBE_NUM_POOL - 1) .. 1
    1323                 :            :          */
    1324         [ #  # ]:          0 :         for (regindex = NGBE_NUM_POOL; --regindex;) {
    1325                 :          0 :                 wr32(hw, NGBE_PSRVLANIDX, regindex);
    1326                 :            :                 bits = rd32(hw, NGBE_PSRVLAN);
    1327         [ #  # ]:          0 :                 if (bits == vlan)
    1328                 :          0 :                         return regindex;
    1329         [ #  # ]:          0 :                 if (!first_empty_slot && !bits)
    1330                 :            :                         first_empty_slot = regindex;
    1331                 :            :         }
    1332                 :            : 
    1333                 :            :         /* If we are here then we didn't find the VLAN.  Return first empty
    1334                 :            :          * slot we found during our search, else error.
    1335                 :            :          */
    1336         [ #  # ]:          0 :         if (!first_empty_slot)
    1337                 :          0 :                 DEBUGOUT("No space in VLVF.");
    1338                 :            : 
    1339         [ #  # ]:          0 :         return first_empty_slot ? first_empty_slot : NGBE_ERR_NO_SPACE;
    1340                 :            : }
    1341                 :            : 
    1342                 :            : /**
    1343                 :            :  *  ngbe_set_vfta - Set VLAN filter table
    1344                 :            :  *  @hw: pointer to hardware structure
    1345                 :            :  *  @vlan: VLAN id to write to VLAN filter
    1346                 :            :  *  @vind: VMDq output index that maps queue to VLAN id in VLVFB
    1347                 :            :  *  @vlan_on: boolean flag to turn on/off VLAN
    1348                 :            :  *  @vlvf_bypass: boolean flag indicating updating default pool is okay
    1349                 :            :  *
    1350                 :            :  *  Turn on/off specified VLAN in the VLAN filter table.
    1351                 :            :  **/
    1352                 :          0 : s32 ngbe_set_vfta(struct ngbe_hw *hw, u32 vlan, u32 vind,
    1353                 :            :                            bool vlan_on, bool vlvf_bypass)
    1354                 :            : {
    1355                 :            :         u32 regidx, vfta_delta, vfta;
    1356                 :            :         s32 err;
    1357                 :            : 
    1358         [ #  # ]:          0 :         if (vlan > 4095 || vind > 63)
    1359                 :            :                 return NGBE_ERR_PARAM;
    1360                 :            : 
    1361                 :            :         /*
    1362                 :            :          * this is a 2 part operation - first the VFTA, then the
    1363                 :            :          * VLVF and VLVFB if VT Mode is set
    1364                 :            :          * We don't write the VFTA until we know the VLVF part succeeded.
    1365                 :            :          */
    1366                 :            : 
    1367                 :            :         /* Part 1
    1368                 :            :          * The VFTA is a bitstring made up of 128 32-bit registers
    1369                 :            :          * that enable the particular VLAN id, much like the MTA:
    1370                 :            :          *    bits[11-5]: which register
    1371                 :            :          *    bits[4-0]:  which bit in the register
    1372                 :            :          */
    1373                 :          0 :         regidx = vlan / 32;
    1374                 :          0 :         vfta_delta = 1 << (vlan % 32);
    1375                 :          0 :         vfta = rd32(hw, NGBE_VLANTBL(regidx));
    1376                 :            : 
    1377                 :            :         /*
    1378                 :            :          * vfta_delta represents the difference between the current value
    1379                 :            :          * of vfta and the value we want in the register.  Since the diff
    1380                 :            :          * is an XOR mask we can just update the vfta using an XOR
    1381                 :            :          */
    1382         [ #  # ]:          0 :         vfta_delta &= vlan_on ? ~vfta : vfta;
    1383                 :          0 :         vfta ^= vfta_delta;
    1384                 :            : 
    1385                 :            :         /* Part 2
    1386                 :            :          * Call ngbe_set_vlvf to set VLVFB and VLVF
    1387                 :            :          */
    1388                 :          0 :         err = ngbe_set_vlvf(hw, vlan, vind, vlan_on, &vfta_delta,
    1389                 :            :                                          vfta, vlvf_bypass);
    1390         [ #  # ]:          0 :         if (err != 0) {
    1391         [ #  # ]:          0 :                 if (vlvf_bypass)
    1392                 :          0 :                         goto vfta_update;
    1393                 :            :                 return err;
    1394                 :            :         }
    1395                 :            : 
    1396                 :          0 : vfta_update:
    1397                 :            :         /* Update VFTA now that we are ready for traffic */
    1398         [ #  # ]:          0 :         if (vfta_delta)
    1399                 :            :                 wr32(hw, NGBE_VLANTBL(regidx), vfta);
    1400                 :            : 
    1401                 :            :         return 0;
    1402                 :            : }
    1403                 :            : 
    1404                 :            : /**
    1405                 :            :  *  ngbe_set_vlvf - Set VLAN Pool Filter
    1406                 :            :  *  @hw: pointer to hardware structure
    1407                 :            :  *  @vlan: VLAN id to write to VLAN filter
    1408                 :            :  *  @vind: VMDq output index that maps queue to VLAN id in PSRVLANPLM
    1409                 :            :  *  @vlan_on: boolean flag to turn on/off VLAN in PSRVLAN
    1410                 :            :  *  @vfta_delta: pointer to the difference between the current value
    1411                 :            :  *               of PSRVLANPLM and the desired value
    1412                 :            :  *  @vfta: the desired value of the VFTA
    1413                 :            :  *  @vlvf_bypass: boolean flag indicating updating default pool is okay
    1414                 :            :  *
    1415                 :            :  *  Turn on/off specified bit in VLVF table.
    1416                 :            :  **/
    1417                 :          0 : s32 ngbe_set_vlvf(struct ngbe_hw *hw, u32 vlan, u32 vind,
    1418                 :            :                            bool vlan_on, u32 *vfta_delta, u32 vfta,
    1419                 :            :                            bool vlvf_bypass)
    1420                 :            : {
    1421                 :            :         u32 bits;
    1422                 :            :         u32 portctl;
    1423                 :            :         s32 vlvf_index;
    1424                 :            : 
    1425         [ #  # ]:          0 :         if (vlan > 4095 || vind > 63)
    1426                 :            :                 return NGBE_ERR_PARAM;
    1427                 :            : 
    1428                 :            :         /* If VT Mode is set
    1429                 :            :          *   Either vlan_on
    1430                 :            :          *     make sure the vlan is in PSRVLAN
    1431                 :            :          *     set the vind bit in the matching PSRVLANPLM
    1432                 :            :          *   Or !vlan_on
    1433                 :            :          *     clear the pool bit and possibly the vind
    1434                 :            :          */
    1435                 :            :         portctl = rd32(hw, NGBE_PORTCTL);
    1436         [ #  # ]:          0 :         if (!(portctl & NGBE_PORTCTL_NUMVT_MASK))
    1437                 :            :                 return 0;
    1438                 :            : 
    1439                 :          0 :         vlvf_index = ngbe_find_vlvf_slot(hw, vlan, vlvf_bypass);
    1440         [ #  # ]:          0 :         if (vlvf_index < 0)
    1441                 :            :                 return vlvf_index;
    1442                 :            : 
    1443                 :          0 :         wr32(hw, NGBE_PSRVLANIDX, vlvf_index);
    1444                 :          0 :         bits = rd32(hw, NGBE_PSRVLANPLM(vind / 32));
    1445                 :            : 
    1446                 :            :         /* set the pool bit */
    1447                 :          0 :         bits |= 1 << (vind % 32);
    1448         [ #  # ]:          0 :         if (vlan_on)
    1449                 :          0 :                 goto vlvf_update;
    1450                 :            : 
    1451                 :            :         /* clear the pool bit */
    1452                 :          0 :         bits ^= 1 << (vind % 32);
    1453                 :            : 
    1454   [ #  #  #  # ]:          0 :         if (!bits &&
    1455                 :            :             !rd32(hw, NGBE_PSRVLANPLM(vind / 32))) {
    1456                 :            :                 /* Clear PSRVLANPLM first, then disable PSRVLAN. Otherwise
    1457                 :            :                  * we run the risk of stray packets leaking into
    1458                 :            :                  * the PF via the default pool
    1459                 :            :                  */
    1460         [ #  # ]:          0 :                 if (*vfta_delta)
    1461                 :          0 :                         wr32(hw, NGBE_PSRVLANPLM(vlan / 32), vfta);
    1462                 :            : 
    1463                 :            :                 /* disable VLVF and clear remaining bit from pool */
    1464                 :            :                 wr32(hw, NGBE_PSRVLAN, 0);
    1465                 :            :                 wr32(hw, NGBE_PSRVLANPLM(vind / 32), 0);
    1466                 :            : 
    1467                 :          0 :                 return 0;
    1468                 :            :         }
    1469                 :            : 
    1470                 :            :         /* If there are still bits set in the PSRVLANPLM registers
    1471                 :            :          * for the VLAN ID indicated we need to see if the
    1472                 :            :          * caller is requesting that we clear the PSRVLANPLM entry bit.
    1473                 :            :          * If the caller has requested that we clear the PSRVLANPLM
    1474                 :            :          * entry bit but there are still pools/VFs using this VLAN
    1475                 :            :          * ID entry then ignore the request.  We're not worried
    1476                 :            :          * about the case where we're turning the PSRVLANPLM VLAN ID
    1477                 :            :          * entry bit on, only when requested to turn it off as
    1478                 :            :          * there may be multiple pools and/or VFs using the
    1479                 :            :          * VLAN ID entry.  In that case we cannot clear the
    1480                 :            :          * PSRVLANPLM bit until all pools/VFs using that VLAN ID have also
    1481                 :            :          * been cleared.  This will be indicated by "bits" being
    1482                 :            :          * zero.
    1483                 :            :          */
    1484                 :          0 :         *vfta_delta = 0;
    1485                 :            : 
    1486                 :          0 : vlvf_update:
    1487                 :            :         /* record pool change and enable VLAN ID if not already enabled */
    1488                 :            :         wr32(hw, NGBE_PSRVLANPLM(vind / 32), bits);
    1489                 :          0 :         wr32(hw, NGBE_PSRVLAN, NGBE_PSRVLAN_EA | vlan);
    1490                 :            : 
    1491                 :          0 :         return 0;
    1492                 :            : }
    1493                 :            : 
    1494                 :            : /**
    1495                 :            :  *  ngbe_clear_vfta - Clear VLAN filter table
    1496                 :            :  *  @hw: pointer to hardware structure
    1497                 :            :  *
    1498                 :            :  *  Clears the VLAN filer table, and the VMDq index associated with the filter
    1499                 :            :  **/
    1500                 :          0 : s32 ngbe_clear_vfta(struct ngbe_hw *hw)
    1501                 :            : {
    1502                 :            :         u32 offset;
    1503                 :            : 
    1504         [ #  # ]:          0 :         for (offset = 0; offset < hw->mac.vft_size; offset++)
    1505                 :          0 :                 wr32(hw, NGBE_VLANTBL(offset), 0);
    1506                 :            : 
    1507         [ #  # ]:          0 :         for (offset = 0; offset < NGBE_NUM_POOL; offset++) {
    1508                 :            :                 wr32(hw, NGBE_PSRVLANIDX, offset);
    1509                 :            :                 wr32(hw, NGBE_PSRVLAN, 0);
    1510                 :            :                 wr32(hw, NGBE_PSRVLANPLM(0), 0);
    1511                 :            :         }
    1512                 :            : 
    1513                 :          0 :         return 0;
    1514                 :            : }
    1515                 :            : 
    1516                 :            : /**
    1517                 :            :  *  ngbe_check_mac_link_em - Determine link and speed status
    1518                 :            :  *  @hw: pointer to hardware structure
    1519                 :            :  *  @speed: pointer to link speed
    1520                 :            :  *  @link_up: true when link is up
    1521                 :            :  *  @link_up_wait_to_complete: bool used to wait for link up or not
    1522                 :            :  *
    1523                 :            :  *  Reads the links register to determine if link is up and the current speed
    1524                 :            :  **/
    1525                 :          0 : s32 ngbe_check_mac_link_em(struct ngbe_hw *hw, u32 *speed,
    1526                 :            :                         bool *link_up, bool link_up_wait_to_complete)
    1527                 :            : {
    1528                 :            :         u32 i;
    1529                 :            :         s32 status = 0;
    1530                 :            : 
    1531         [ #  # ]:          0 :         if (hw->lsc) {
    1532                 :            :                 u32 reg;
    1533                 :            : 
    1534                 :            :                 reg = rd32(hw, NGBE_GPIOINTSTAT);
    1535                 :            :                 wr32(hw, NGBE_GPIOEOI, reg);
    1536                 :            :         }
    1537                 :            : 
    1538         [ #  # ]:          0 :         if (link_up_wait_to_complete) {
    1539         [ #  # ]:          0 :                 for (i = 0; i < hw->mac.max_link_up_time; i++) {
    1540                 :          0 :                         status = hw->phy.check_link(hw, speed, link_up);
    1541         [ #  # ]:          0 :                         if (*link_up)
    1542                 :            :                                 break;
    1543                 :            :                         msec_delay(100);
    1544                 :            :                 }
    1545                 :            :         } else {
    1546                 :          0 :                 status = hw->phy.check_link(hw, speed, link_up);
    1547                 :            :         }
    1548                 :            : 
    1549                 :          0 :         return status;
    1550                 :            : }
    1551                 :            : 
    1552                 :          0 : s32 ngbe_get_link_capabilities_em(struct ngbe_hw *hw,
    1553                 :            :                                       u32 *speed,
    1554                 :            :                                       bool *autoneg)
    1555                 :            : {
    1556                 :            :         s32 status = 0;
    1557                 :          0 :         u16 value = 0;
    1558                 :            : 
    1559                 :          0 :         hw->mac.autoneg = *autoneg;
    1560                 :            : 
    1561         [ #  # ]:          0 :         if (hw->phy.type == ngbe_phy_rtl) {
    1562                 :          0 :                 *speed = NGBE_LINK_SPEED_1GB_FULL |
    1563                 :            :                         NGBE_LINK_SPEED_100M_FULL |
    1564                 :            :                         NGBE_LINK_SPEED_10M_FULL;
    1565                 :            :         }
    1566                 :            : 
    1567         [ #  # ]:          0 :         if (hw->phy.type == ngbe_phy_yt8521s_sfi) {
    1568                 :          0 :                 ngbe_read_phy_reg_ext_yt(hw, YT_CHIP, 0, &value);
    1569         [ #  # ]:          0 :                 if ((value & YT_CHIP_MODE_MASK) == YT_CHIP_MODE_SEL(1))
    1570                 :          0 :                         *speed = NGBE_LINK_SPEED_1GB_FULL;
    1571                 :            :         }
    1572                 :            : 
    1573                 :          0 :         return status;
    1574                 :            : }
    1575                 :            : 
    1576                 :          0 : s32 ngbe_setup_mac_link_em(struct ngbe_hw *hw,
    1577                 :            :                                u32 speed,
    1578                 :            :                                bool autoneg_wait_to_complete)
    1579                 :            : {
    1580                 :            :         s32 status;
    1581                 :            : 
    1582                 :            :         /* Setup the PHY according to input speed */
    1583                 :          0 :         status = hw->phy.setup_link(hw, speed, autoneg_wait_to_complete);
    1584                 :            : 
    1585                 :          0 :         return status;
    1586                 :            : }
    1587                 :            : 
    1588                 :            : /**
    1589                 :            :  *  ngbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
    1590                 :            :  *  @hw: pointer to hardware structure
    1591                 :            :  *  @enable: enable or disable switch for MAC anti-spoofing
    1592                 :            :  *  @vf: Virtual Function pool - VF Pool to set for MAC anti-spoofing
    1593                 :            :  *
    1594                 :            :  **/
    1595                 :          0 : void ngbe_set_mac_anti_spoofing(struct ngbe_hw *hw, bool enable, int vf)
    1596                 :            : {
    1597                 :            :         u32 pfvfspoof;
    1598                 :            : 
    1599                 :            :         pfvfspoof = rd32(hw, NGBE_POOLTXASMAC);
    1600         [ #  # ]:          0 :         if (enable)
    1601                 :          0 :                 pfvfspoof |= (1 << vf);
    1602                 :            :         else
    1603                 :          0 :                 pfvfspoof &= ~(1 << vf);
    1604                 :            :         wr32(hw, NGBE_POOLTXASMAC, pfvfspoof);
    1605                 :          0 : }
    1606                 :            : 
    1607                 :            : /**
    1608                 :            :  * ngbe_set_pba - Initialize Rx packet buffer
    1609                 :            :  * @hw: pointer to hardware structure
    1610                 :            :  * @headroom: reserve n KB of headroom
    1611                 :            :  **/
    1612                 :          0 : void ngbe_set_pba(struct ngbe_hw *hw)
    1613                 :            : {
    1614                 :          0 :         u32 rxpktsize = hw->mac.rx_pb_size;
    1615                 :            :         u32 txpktsize, txpbthresh;
    1616                 :            : 
    1617                 :            :         /* Reserve 256 KB of headroom */
    1618                 :          0 :         rxpktsize -= 256;
    1619                 :            : 
    1620                 :          0 :         rxpktsize <<= 10;
    1621                 :            :         wr32(hw, NGBE_PBRXSIZE, rxpktsize);
    1622                 :            : 
    1623                 :            :         /* Only support an equally distributed Tx packet buffer strategy. */
    1624                 :            :         txpktsize = NGBE_PBTXSIZE_MAX;
    1625                 :            :         txpbthresh = (txpktsize / 1024) - NGBE_TXPKT_SIZE_MAX;
    1626                 :            : 
    1627                 :            :         wr32(hw, NGBE_PBTXSIZE, txpktsize);
    1628                 :            :         wr32(hw, NGBE_PBTXDMATH, txpbthresh);
    1629                 :          0 : }
    1630                 :            : 
    1631                 :            : /**
    1632                 :            :  *  ngbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
    1633                 :            :  *  @hw: pointer to hardware structure
    1634                 :            :  *  @enable: enable or disable switch for VLAN anti-spoofing
    1635                 :            :  *  @vf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
    1636                 :            :  *
    1637                 :            :  **/
    1638                 :          0 : void ngbe_set_vlan_anti_spoofing(struct ngbe_hw *hw, bool enable, int vf)
    1639                 :            : {
    1640                 :            :         u32 pfvfspoof;
    1641                 :            : 
    1642                 :            :         pfvfspoof = rd32(hw, NGBE_POOLTXASVLAN);
    1643         [ #  # ]:          0 :         if (enable)
    1644                 :          0 :                 pfvfspoof |= (1 << vf);
    1645                 :            :         else
    1646                 :          0 :                 pfvfspoof &= ~(1 << vf);
    1647                 :            :         wr32(hw, NGBE_POOLTXASVLAN, pfvfspoof);
    1648                 :          0 : }
    1649                 :            : 
    1650                 :            : /**
    1651                 :            :  *  ngbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds
    1652                 :            :  *  @hw: pointer to hardware structure
    1653                 :            :  *
    1654                 :            :  *  Inits the thermal sensor thresholds according to the NVM map
    1655                 :            :  *  and save off the threshold and location values into mac.thermal_sensor_data
    1656                 :            :  **/
    1657                 :          0 : s32 ngbe_init_thermal_sensor_thresh(struct ngbe_hw *hw)
    1658                 :            : {
    1659         [ #  # ]:          0 :         struct ngbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
    1660                 :            : 
    1661                 :            :         memset(data, 0, sizeof(struct ngbe_thermal_sensor_data));
    1662                 :            : 
    1663         [ #  # ]:          0 :         if (hw->bus.lan_id != 0)
    1664                 :            :                 return NGBE_NOT_IMPLEMENTED;
    1665                 :            : 
    1666                 :            :         wr32(hw, NGBE_TSINTR,
    1667                 :            :                 NGBE_TSINTR_AEN | NGBE_TSINTR_DEN);
    1668                 :            :         wr32(hw, NGBE_TSEN, NGBE_TSEN_ENA);
    1669                 :            : 
    1670                 :            : 
    1671                 :          0 :         data->sensor[0].alarm_thresh = 115;
    1672                 :            :         wr32(hw, NGBE_TSATHRE, 0x344);
    1673                 :          0 :         data->sensor[0].dalarm_thresh = 110;
    1674                 :            :         wr32(hw, NGBE_TSDTHRE, 0x330);
    1675                 :            : 
    1676                 :          0 :         return 0;
    1677                 :            : }
    1678                 :            : 
    1679                 :          0 : s32 ngbe_mac_check_overtemp(struct ngbe_hw *hw)
    1680                 :            : {
    1681                 :            :         s32 status = 0;
    1682                 :            :         u32 ts_state;
    1683                 :            : 
    1684                 :            :         /* Check that the LASI temp alarm status was triggered */
    1685                 :            :         ts_state = rd32(hw, NGBE_TSALM);
    1686                 :            : 
    1687         [ #  # ]:          0 :         if (ts_state & NGBE_TSALM_HI)
    1688                 :            :                 status = NGBE_ERR_UNDERTEMP;
    1689         [ #  # ]:          0 :         else if (ts_state & NGBE_TSALM_LO)
    1690                 :            :                 status = NGBE_ERR_OVERTEMP;
    1691                 :            : 
    1692                 :          0 :         return status;
    1693                 :            : }
    1694                 :            : 
    1695                 :          0 : void ngbe_disable_rx(struct ngbe_hw *hw)
    1696                 :            : {
    1697                 :            :         u32 pfdtxgswc;
    1698                 :            : 
    1699                 :            :         pfdtxgswc = rd32(hw, NGBE_PSRCTL);
    1700         [ #  # ]:          0 :         if (pfdtxgswc & NGBE_PSRCTL_LBENA) {
    1701                 :          0 :                 pfdtxgswc &= ~NGBE_PSRCTL_LBENA;
    1702                 :            :                 wr32(hw, NGBE_PSRCTL, pfdtxgswc);
    1703                 :          0 :                 hw->mac.set_lben = true;
    1704                 :            :         } else {
    1705                 :          0 :                 hw->mac.set_lben = false;
    1706                 :            :         }
    1707                 :            : 
    1708                 :            :         wr32m(hw, NGBE_PBRXCTL, NGBE_PBRXCTL_ENA, 0);
    1709                 :            :         wr32m(hw, NGBE_MACRXCFG, NGBE_MACRXCFG_ENA, 0);
    1710                 :          0 : }
    1711                 :            : 
    1712                 :          0 : void ngbe_enable_rx(struct ngbe_hw *hw)
    1713                 :            : {
    1714                 :            :         u32 pfdtxgswc;
    1715                 :            : 
    1716                 :            :         wr32m(hw, NGBE_MACRXCFG, NGBE_MACRXCFG_ENA, NGBE_MACRXCFG_ENA);
    1717                 :            :         wr32m(hw, NGBE_PBRXCTL, NGBE_PBRXCTL_ENA, NGBE_PBRXCTL_ENA);
    1718                 :            : 
    1719         [ #  # ]:          0 :         if (hw->mac.set_lben) {
    1720                 :            :                 pfdtxgswc = rd32(hw, NGBE_PSRCTL);
    1721                 :          0 :                 pfdtxgswc |= NGBE_PSRCTL_LBENA;
    1722                 :            :                 wr32(hw, NGBE_PSRCTL, pfdtxgswc);
    1723                 :          0 :                 hw->mac.set_lben = false;
    1724                 :            :         }
    1725                 :          0 : }
    1726                 :            : 
    1727                 :            : /**
    1728                 :            :  *  ngbe_set_mac_type - Sets MAC type
    1729                 :            :  *  @hw: pointer to the HW structure
    1730                 :            :  *
    1731                 :            :  *  This function sets the mac type of the adapter based on the
    1732                 :            :  *  vendor ID and device ID stored in the hw structure.
    1733                 :            :  **/
    1734                 :          0 : s32 ngbe_set_mac_type(struct ngbe_hw *hw)
    1735                 :            : {
    1736                 :            :         s32 err = 0;
    1737                 :            : 
    1738         [ #  # ]:          0 :         if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
    1739                 :          0 :                 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
    1740                 :          0 :                 return NGBE_ERR_DEVICE_NOT_SUPPORTED;
    1741                 :            :         }
    1742                 :            : 
    1743   [ #  #  #  #  :          0 :         switch (hw->sub_device_id) {
                   #  # ]
    1744                 :          0 :         case NGBE_SUB_DEV_ID_EM_RTL_SGMII:
    1745                 :            :         case NGBE_SUB_DEV_ID_EM_MVL_RGMII:
    1746                 :          0 :                 hw->phy.media_type = ngbe_media_type_copper;
    1747                 :          0 :                 hw->mac.type = ngbe_mac_em;
    1748                 :          0 :                 hw->mac.link_type = ngbe_link_copper;
    1749                 :          0 :                 break;
    1750                 :          0 :         case NGBE_SUB_DEV_ID_EM_RTL_YT8521S_SFP:
    1751                 :          0 :                 hw->phy.media_type = ngbe_media_type_copper;
    1752                 :          0 :                 hw->mac.type = ngbe_mac_em;
    1753                 :          0 :                 hw->mac.link_type = ngbe_link_fiber;
    1754                 :          0 :                 break;
    1755                 :          0 :         case NGBE_SUB_DEV_ID_EM_MVL_SFP:
    1756                 :            :         case NGBE_SUB_DEV_ID_EM_YT8521S_SFP:
    1757                 :          0 :                 hw->phy.media_type = ngbe_media_type_fiber;
    1758                 :          0 :                 hw->mac.type = ngbe_mac_em;
    1759                 :          0 :                 hw->mac.link_type = ngbe_link_fiber;
    1760                 :          0 :                 break;
    1761                 :          0 :         case NGBE_SUB_DEV_ID_EM_MVL_MIX:
    1762                 :          0 :                 hw->phy.media_type = ngbe_media_type_unknown;
    1763                 :          0 :                 hw->mac.type = ngbe_mac_em;
    1764                 :          0 :                 hw->mac.link_type = ngbe_link_type_unknown;
    1765                 :          0 :                 break;
    1766                 :          0 :         case NGBE_SUB_DEV_ID_EM_VF:
    1767                 :          0 :                 hw->phy.media_type = ngbe_media_type_virtual;
    1768                 :          0 :                 hw->mac.type = ngbe_mac_em_vf;
    1769                 :          0 :                 break;
    1770                 :          0 :         default:
    1771                 :            :                 err = NGBE_ERR_DEVICE_NOT_SUPPORTED;
    1772                 :          0 :                 hw->phy.media_type = ngbe_media_type_unknown;
    1773                 :          0 :                 hw->mac.type = ngbe_mac_unknown;
    1774                 :          0 :                 DEBUGOUT("Unsupported device id: %x", hw->device_id);
    1775                 :          0 :                 break;
    1776                 :            :         }
    1777                 :            : 
    1778                 :          0 :         DEBUGOUT("found mac: %d media: %d, returns: %d",
    1779                 :            :                   hw->mac.type, hw->phy.media_type, err);
    1780                 :          0 :         return err;
    1781                 :            : }
    1782                 :            : 
    1783                 :            : /**
    1784                 :            :  *  ngbe_enable_rx_dma - Enable the Rx DMA unit
    1785                 :            :  *  @hw: pointer to hardware structure
    1786                 :            :  *  @regval: register value to write to RXCTRL
    1787                 :            :  *
    1788                 :            :  *  Enables the Rx DMA unit
    1789                 :            :  **/
    1790                 :          0 : s32 ngbe_enable_rx_dma(struct ngbe_hw *hw, u32 regval)
    1791                 :            : {
    1792                 :            :         /*
    1793                 :            :          * Workaround silicon errata when enabling the Rx datapath.
    1794                 :            :          * If traffic is incoming before we enable the Rx unit, it could hang
    1795                 :            :          * the Rx DMA unit.  Therefore, make sure the security engine is
    1796                 :            :          * completely disabled prior to enabling the Rx unit.
    1797                 :            :          */
    1798                 :          0 :         hw->mac.disable_sec_rx_path(hw);
    1799                 :            : 
    1800         [ #  # ]:          0 :         if (regval & NGBE_PBRXCTL_ENA)
    1801                 :          0 :                 ngbe_enable_rx(hw);
    1802                 :            :         else
    1803                 :          0 :                 ngbe_disable_rx(hw);
    1804                 :            : 
    1805                 :          0 :         hw->mac.enable_sec_rx_path(hw);
    1806                 :            : 
    1807                 :          0 :         return 0;
    1808                 :            : }
    1809                 :            : 
    1810                 :            : /* cmd_addr is used for some special command:
    1811                 :            :  * 1. to be sector address, when implemented erase sector command
    1812                 :            :  * 2. to be flash address when implemented read, write flash address
    1813                 :            :  *
    1814                 :            :  * Return 0 on success, return 1 on failure.
    1815                 :            :  */
    1816                 :          0 : u32 ngbe_fmgr_cmd_op(struct ngbe_hw *hw, u32 cmd, u32 cmd_addr)
    1817                 :            : {
    1818                 :            :         u32 cmd_val, i;
    1819                 :            : 
    1820                 :          0 :         cmd_val = NGBE_SPICMD_CMD(cmd) | NGBE_SPICMD_CLK(3) | cmd_addr;
    1821                 :            :         wr32(hw, NGBE_SPICMD, cmd_val);
    1822                 :            : 
    1823         [ #  # ]:          0 :         for (i = 0; i < NGBE_SPI_TIMEOUT; i++) {
    1824         [ #  # ]:          0 :                 if (rd32(hw, NGBE_SPISTAT) & NGBE_SPISTAT_OPDONE)
    1825                 :            :                         break;
    1826                 :            : 
    1827                 :          0 :                 usec_delay(10);
    1828                 :            :         }
    1829         [ #  # ]:          0 :         if (i == NGBE_SPI_TIMEOUT)
    1830                 :          0 :                 return 1;
    1831                 :            : 
    1832                 :            :         return 0;
    1833                 :            : }
    1834                 :            : 
    1835                 :          0 : u32 ngbe_flash_read_dword(struct ngbe_hw *hw, u32 addr)
    1836                 :            : {
    1837                 :            :         u32 status;
    1838                 :            : 
    1839                 :          0 :         status = ngbe_fmgr_cmd_op(hw, 1, addr);
    1840         [ #  # ]:          0 :         if (status == 0x1) {
    1841                 :          0 :                 DEBUGOUT("Read flash timeout.");
    1842                 :          0 :                 return status;
    1843                 :            :         }
    1844                 :            : 
    1845                 :          0 :         return rd32(hw, NGBE_SPIDAT);
    1846                 :            : }
    1847                 :            : 
    1848                 :          0 : void ngbe_read_efuse(struct ngbe_hw *hw)
    1849                 :            : {
    1850                 :            :         u32 efuse[2];
    1851                 :          0 :         u8 lan_id = hw->bus.lan_id;
    1852                 :            : 
    1853                 :          0 :         efuse[0] = ngbe_flash_read_dword(hw, 0xfe010 + lan_id * 8);
    1854                 :          0 :         efuse[1] = ngbe_flash_read_dword(hw, 0xfe010 + lan_id * 8 + 4);
    1855                 :            : 
    1856                 :          0 :         DEBUGOUT("port %d efuse[0] = %08x, efuse[1] = %08x\n",
    1857                 :            :                 lan_id, efuse[0], efuse[1]);
    1858                 :            : 
    1859                 :          0 :         hw->gphy_efuse[0] = efuse[0];
    1860                 :          0 :         hw->gphy_efuse[1] = efuse[1];
    1861                 :          0 : }
    1862                 :            : 
    1863                 :          0 : void ngbe_map_device_id(struct ngbe_hw *hw)
    1864                 :            : {
    1865                 :          0 :         u16 oem = hw->sub_system_id & NGBE_OEM_MASK;
    1866                 :            : 
    1867                 :          0 :         hw->is_pf = true;
    1868                 :            : 
    1869                 :            :         /* move subsystem_device_id to device_id */
    1870      [ #  #  # ]:          0 :         switch (hw->device_id) {
    1871                 :          0 :         case NGBE_DEV_ID_EM_WX1860AL_W_VF:
    1872                 :            :         case NGBE_DEV_ID_EM_WX1860A2_VF:
    1873                 :            :         case NGBE_DEV_ID_EM_WX1860A2S_VF:
    1874                 :            :         case NGBE_DEV_ID_EM_WX1860A4_VF:
    1875                 :            :         case NGBE_DEV_ID_EM_WX1860A4S_VF:
    1876                 :            :         case NGBE_DEV_ID_EM_WX1860AL2_VF:
    1877                 :            :         case NGBE_DEV_ID_EM_WX1860AL2S_VF:
    1878                 :            :         case NGBE_DEV_ID_EM_WX1860AL4_VF:
    1879                 :            :         case NGBE_DEV_ID_EM_WX1860AL4S_VF:
    1880                 :            :         case NGBE_DEV_ID_EM_WX1860NCSI_VF:
    1881                 :            :         case NGBE_DEV_ID_EM_WX1860A1_VF:
    1882                 :            :         case NGBE_DEV_ID_EM_WX1860A1L_VF:
    1883                 :          0 :                 hw->device_id = NGBE_DEV_ID_EM_VF;
    1884                 :          0 :                 hw->sub_device_id = NGBE_SUB_DEV_ID_EM_VF;
    1885                 :          0 :                 hw->is_pf = false;
    1886                 :          0 :                 break;
    1887                 :          0 :         case NGBE_DEV_ID_EM_WX1860AL_W:
    1888                 :            :         case NGBE_DEV_ID_EM_WX1860A2:
    1889                 :            :         case NGBE_DEV_ID_EM_WX1860A2S:
    1890                 :            :         case NGBE_DEV_ID_EM_WX1860A4:
    1891                 :            :         case NGBE_DEV_ID_EM_WX1860A4S:
    1892                 :            :         case NGBE_DEV_ID_EM_WX1860AL2:
    1893                 :            :         case NGBE_DEV_ID_EM_WX1860AL2S:
    1894                 :            :         case NGBE_DEV_ID_EM_WX1860AL4:
    1895                 :            :         case NGBE_DEV_ID_EM_WX1860AL4S:
    1896                 :            :         case NGBE_DEV_ID_EM_WX1860NCSI:
    1897                 :            :         case NGBE_DEV_ID_EM_WX1860A1:
    1898                 :            :         case NGBE_DEV_ID_EM_WX1860A1L:
    1899                 :          0 :                 hw->device_id = NGBE_DEV_ID_EM;
    1900         [ #  # ]:          0 :                 if (oem == NGBE_M88E1512_SFP || oem == NGBE_LY_M88E1512_SFP)
    1901                 :          0 :                         hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_SFP;
    1902   [ #  #  #  # ]:          0 :                 else if (oem == NGBE_M88E1512_RJ45 ||
    1903                 :            :                         (hw->sub_system_id == NGBE_SUB_DEV_ID_EM_M88E1512_RJ45))
    1904                 :          0 :                         hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_RGMII;
    1905                 :            :                 else if (oem == NGBE_M88E1512_MIX)
    1906                 :          0 :                         hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_MIX;
    1907                 :            :                 else if (oem == NGBE_YT8521S_SFP ||
    1908                 :            :                          oem == NGBE_YT8521S_SFP_GPIO ||
    1909                 :            :                          oem == NGBE_LY_YT8521S_SFP)
    1910                 :          0 :                         hw->sub_device_id = NGBE_SUB_DEV_ID_EM_YT8521S_SFP;
    1911                 :            :                 else if (oem == NGBE_INTERNAL_YT8521S_SFP ||
    1912                 :            :                          oem == NGBE_INTERNAL_YT8521S_SFP_GPIO)
    1913                 :          0 :                         hw->sub_device_id = NGBE_SUB_DEV_ID_EM_RTL_YT8521S_SFP;
    1914                 :            :                 else
    1915                 :          0 :                         hw->sub_device_id = NGBE_SUB_DEV_ID_EM_RTL_SGMII;
    1916                 :            :                 break;
    1917                 :            :         default:
    1918                 :            :                 break;
    1919                 :            :         }
    1920                 :            : 
    1921         [ #  # ]:          0 :         if (oem == NGBE_LY_M88E1512_SFP || oem == NGBE_YT8521S_SFP_GPIO ||
    1922                 :          0 :                         oem == NGBE_INTERNAL_YT8521S_SFP_GPIO ||
    1923         [ #  # ]:          0 :                         oem == NGBE_LY_YT8521S_SFP)
    1924                 :          0 :                 hw->gpio_ctl = true;
    1925                 :          0 : }
    1926                 :            : 
    1927                 :            : /**
    1928                 :            :  *  ngbe_init_ops_pf - Inits func ptrs and MAC type
    1929                 :            :  *  @hw: pointer to hardware structure
    1930                 :            :  *
    1931                 :            :  *  Initialize the function pointers and assign the MAC type.
    1932                 :            :  *  Does not touch the hardware.
    1933                 :            :  **/
    1934                 :          0 : s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
    1935                 :            : {
    1936                 :            :         struct ngbe_bus_info *bus = &hw->bus;
    1937                 :            :         struct ngbe_mac_info *mac = &hw->mac;
    1938                 :            :         struct ngbe_phy_info *phy = &hw->phy;
    1939                 :            :         struct ngbe_rom_info *rom = &hw->rom;
    1940                 :            :         struct ngbe_mbx_info *mbx = &hw->mbx;
    1941                 :            : 
    1942                 :            :         /* BUS */
    1943                 :          0 :         bus->set_lan_id = ngbe_set_lan_id_multi_port;
    1944                 :            : 
    1945                 :            :         /* PHY */
    1946                 :          0 :         phy->identify = ngbe_identify_phy;
    1947                 :          0 :         phy->read_reg = ngbe_read_phy_reg;
    1948                 :          0 :         phy->write_reg = ngbe_write_phy_reg;
    1949                 :          0 :         phy->read_reg_unlocked = ngbe_read_phy_reg_mdi;
    1950                 :          0 :         phy->write_reg_unlocked = ngbe_write_phy_reg_mdi;
    1951                 :          0 :         phy->reset_hw = ngbe_reset_phy;
    1952                 :          0 :         phy->led_oem_chk = ngbe_phy_led_oem_chk;
    1953                 :            : 
    1954                 :            :         /* MAC */
    1955                 :          0 :         mac->init_hw = ngbe_init_hw;
    1956                 :          0 :         mac->reset_hw = ngbe_reset_hw_em;
    1957                 :          0 :         mac->start_hw = ngbe_start_hw;
    1958                 :          0 :         mac->clear_hw_cntrs = ngbe_clear_hw_cntrs;
    1959                 :          0 :         mac->enable_rx_dma = ngbe_enable_rx_dma;
    1960                 :          0 :         mac->get_mac_addr = ngbe_get_mac_addr;
    1961                 :          0 :         mac->stop_hw = ngbe_stop_hw;
    1962                 :          0 :         mac->acquire_swfw_sync = ngbe_acquire_swfw_sync;
    1963                 :          0 :         mac->release_swfw_sync = ngbe_release_swfw_sync;
    1964                 :            : 
    1965                 :          0 :         mac->disable_sec_rx_path = ngbe_disable_sec_rx_path;
    1966                 :          0 :         mac->enable_sec_rx_path = ngbe_enable_sec_rx_path;
    1967                 :            : 
    1968                 :            :         /* LEDs */
    1969                 :          0 :         mac->led_on = ngbe_led_on;
    1970                 :          0 :         mac->led_off = ngbe_led_off;
    1971                 :            : 
    1972                 :            :         /* RAR, VLAN, Multicast */
    1973                 :          0 :         mac->set_rar = ngbe_set_rar;
    1974                 :          0 :         mac->clear_rar = ngbe_clear_rar;
    1975                 :          0 :         mac->init_rx_addrs = ngbe_init_rx_addrs;
    1976                 :          0 :         mac->update_mc_addr_list = ngbe_update_mc_addr_list;
    1977                 :          0 :         mac->set_vmdq = ngbe_set_vmdq;
    1978                 :          0 :         mac->clear_vmdq = ngbe_clear_vmdq;
    1979                 :          0 :         mac->set_vfta = ngbe_set_vfta;
    1980                 :          0 :         mac->set_vlvf = ngbe_set_vlvf;
    1981                 :          0 :         mac->clear_vfta = ngbe_clear_vfta;
    1982                 :          0 :         mac->set_mac_anti_spoofing = ngbe_set_mac_anti_spoofing;
    1983                 :          0 :         mac->set_vlan_anti_spoofing = ngbe_set_vlan_anti_spoofing;
    1984                 :            : 
    1985                 :            :         /* Flow Control */
    1986                 :          0 :         mac->fc_enable = ngbe_fc_enable;
    1987                 :          0 :         mac->fc_autoneg = ngbe_fc_autoneg;
    1988                 :          0 :         mac->setup_fc = ngbe_setup_fc_em;
    1989                 :            : 
    1990                 :            :         /* Link */
    1991                 :          0 :         mac->get_link_capabilities = ngbe_get_link_capabilities_em;
    1992                 :          0 :         mac->check_link = ngbe_check_mac_link_em;
    1993                 :          0 :         mac->setup_link = ngbe_setup_mac_link_em;
    1994                 :            : 
    1995                 :          0 :         mac->setup_pba = ngbe_set_pba;
    1996                 :            : 
    1997                 :            :         /* Manageability interface */
    1998                 :          0 :         mac->init_thermal_sensor_thresh = ngbe_init_thermal_sensor_thresh;
    1999                 :          0 :         mac->check_overtemp = ngbe_mac_check_overtemp;
    2000                 :            : 
    2001                 :          0 :         mbx->init_params = ngbe_init_mbx_params_pf;
    2002                 :          0 :         mbx->read = ngbe_read_mbx_pf;
    2003                 :          0 :         mbx->write = ngbe_write_mbx_pf;
    2004                 :          0 :         mbx->check_for_msg = ngbe_check_for_msg_pf;
    2005                 :          0 :         mbx->check_for_ack = ngbe_check_for_ack_pf;
    2006                 :          0 :         mbx->check_for_rst = ngbe_check_for_rst_pf;
    2007                 :            : 
    2008                 :            :         /* EEPROM */
    2009                 :          0 :         rom->init_params = ngbe_init_eeprom_params;
    2010                 :          0 :         rom->readw_buffer = ngbe_ee_readw_buffer;
    2011                 :          0 :         rom->read32 = ngbe_ee_read32;
    2012                 :          0 :         rom->writew_buffer = ngbe_ee_writew_buffer;
    2013                 :          0 :         rom->validate_checksum = ngbe_validate_eeprom_checksum_em;
    2014                 :            : 
    2015                 :          0 :         mac->mcft_size               = NGBE_EM_MC_TBL_SIZE;
    2016                 :          0 :         mac->vft_size                = NGBE_EM_VFT_TBL_SIZE;
    2017                 :          0 :         mac->num_rar_entries = NGBE_EM_RAR_ENTRIES;
    2018                 :          0 :         mac->rx_pb_size              = NGBE_EM_RX_PB_SIZE;
    2019                 :          0 :         mac->max_rx_queues   = NGBE_EM_MAX_RX_QUEUES;
    2020                 :          0 :         mac->max_tx_queues   = NGBE_EM_MAX_TX_QUEUES;
    2021                 :            : 
    2022                 :          0 :         mac->default_speeds = NGBE_LINK_SPEED_10M_FULL |
    2023                 :            :                                 NGBE_LINK_SPEED_100M_FULL |
    2024                 :            :                                 NGBE_LINK_SPEED_1GB_FULL;
    2025                 :            : 
    2026                 :          0 :         return 0;
    2027                 :            : }
    2028                 :            : 
    2029                 :            : /**
    2030                 :            :  *  ngbe_init_shared_code - Initialize the shared code
    2031                 :            :  *  @hw: pointer to hardware structure
    2032                 :            :  *
    2033                 :            :  *  This will assign function pointers and assign the MAC type and PHY code.
    2034                 :            :  *  Does not touch the hardware. This function must be called prior to any
    2035                 :            :  *  other function in the shared code. The ngbe_hw structure should be
    2036                 :            :  *  memset to 0 prior to calling this function.  The following fields in
    2037                 :            :  *  hw structure should be filled in prior to calling this function:
    2038                 :            :  *  hw_addr, back, device_id, vendor_id, subsystem_device_id
    2039                 :            :  **/
    2040                 :          0 : s32 ngbe_init_shared_code(struct ngbe_hw *hw)
    2041                 :            : {
    2042                 :            :         s32 status = 0;
    2043                 :            : 
    2044                 :            :         /*
    2045                 :            :          * Set the mac type
    2046                 :            :          */
    2047                 :          0 :         ngbe_set_mac_type(hw);
    2048                 :            : 
    2049                 :          0 :         ngbe_init_ops_dummy(hw);
    2050         [ #  # ]:          0 :         switch (hw->mac.type) {
    2051                 :          0 :         case ngbe_mac_em:
    2052                 :          0 :                 ngbe_init_ops_pf(hw);
    2053                 :          0 :                 break;
    2054                 :            :         default:
    2055                 :            :                 status = NGBE_ERR_DEVICE_NOT_SUPPORTED;
    2056                 :            :                 break;
    2057                 :            :         }
    2058                 :          0 :         hw->mac.max_link_up_time = NGBE_LINK_UP_TIME;
    2059                 :            : 
    2060                 :          0 :         hw->bus.set_lan_id(hw);
    2061                 :            : 
    2062                 :          0 :         return status;
    2063                 :            : }
    2064                 :            : 

Generated by: LCOV version 1.14