Home | History | Annotate | Download | only in Pp2Dxe
      1 /********************************************************************************
      2 Copyright (C) 2016 Marvell International Ltd.
      3 
      4 Marvell BSD License Option
      5 
      6 If you received this File from Marvell, you may opt to use, redistribute and/or
      7 modify this File under the following licensing terms.
      8 Redistribution and use in source and binary forms, with or without modification,
      9 are permitted provided that the following conditions are met:
     10 
     11   * Redistributions of source code must retain the above copyright notice,
     12     this list of conditions and the following disclaimer.
     13 
     14   * Redistributions in binary form must reproduce the above copyright
     15     notice, this list of conditions and the following disclaimer in the
     16     documentation and/or other materials provided with the distribution.
     17 
     18   * Neither the name of Marvell nor the names of its contributors may be
     19     used to endorse or promote products derived from this software without
     20     specific prior written permission.
     21 
     22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
     26 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     29 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32 
     33 *******************************************************************************/
     34 
     35 #ifndef __MVPP2_LIB_H__
     36 #define __MVPP2_LIB_H__
     37 
     38 #include "Mvpp2LibHw.h"
     39 #include "Pp2Dxe.h"
     40 
     41 /* number of RXQs used by single Port */
     42 STATIC INT32 RxqNumber = 1;
     43 /* number of TXQs used by single Port */
     44 STATIC INT32 TxqNumber = 1;
     45 
     46 VOID
     47 Mvpp2PrsMacPromiscSet (
     48   IN MVPP2_SHARED *Priv,
     49   IN INT32 PortId,
     50   IN BOOLEAN Add
     51   );
     52 
     53 VOID
     54 Mvpp2PrsMacMultiSet (
     55   IN MVPP2_SHARED *Priv,
     56   IN INT32 PortId,
     57   IN INT32 Index,
     58   IN BOOLEAN Add
     59   );
     60 
     61 INT32
     62 Mvpp2PrsDefaultInit (
     63   IN MVPP2_SHARED *Priv
     64   );
     65 
     66 INT32
     67 Mvpp2PrsMacDaAccept (
     68   IN MVPP2_SHARED *Priv,
     69   IN INT32 PortId,
     70   IN const UINT8 *Da,
     71   IN BOOLEAN Add
     72   );
     73 
     74 VOID
     75 Mvpp2PrsMcastDelAll (
     76   IN MVPP2_SHARED *Priv,
     77   IN INT32 PortId
     78   );
     79 
     80 INT32
     81 Mvpp2PrsTagModeSet (
     82   IN MVPP2_SHARED *Priv,
     83   IN INT32 PortId,
     84   IN INT32 type
     85   );
     86 
     87 INT32
     88 Mvpp2PrsDefFlow (
     89   IN PP2DXE_PORT *Port
     90   );
     91 
     92 VOID
     93 Mvpp2ClsInit (
     94   IN MVPP2_SHARED *Priv
     95   );
     96 
     97 VOID
     98 Mvpp2ClsPortConfig (
     99   IN PP2DXE_PORT *Port
    100   );
    101 
    102 VOID
    103 Mvpp2ClsOversizeRxqSet (
    104   IN PP2DXE_PORT *Port
    105   );
    106 
    107 VOID
    108 Mvpp2BmPoolHwCreate (
    109   IN MVPP2_SHARED *Priv,
    110   IN MVPP2_BMS_POOL *BmPool,
    111   IN INT32 Size
    112   );
    113 
    114 VOID
    115 Mvpp2BmPoolBufsizeSet (
    116   IN MVPP2_SHARED *Priv,
    117   IN MVPP2_BMS_POOL *BmPool,
    118   IN INT32 BufSize
    119   );
    120 
    121 VOID
    122 Mvpp2BmStop (
    123   IN MVPP2_SHARED *Priv,
    124   IN INT32 Pool
    125   );
    126 
    127 VOID
    128 Mvpp2BmIrqClear (
    129   IN MVPP2_SHARED *Priv,
    130   IN INT32 Pool
    131   );
    132 
    133 VOID
    134 Mvpp2RxqLongPoolSet (
    135   IN PP2DXE_PORT *Port,
    136   IN INT32 Lrxq,
    137   IN INT32 LongPool
    138   );
    139 
    140 VOID
    141 Mvpp2RxqShortPoolSet (
    142   IN PP2DXE_PORT *Port,
    143   IN INT32 Lrxq,
    144   IN INT32 ShortPool
    145   );
    146 
    147 VOID
    148 Mvpp2BmPoolMcPut (
    149   IN PP2DXE_PORT *Port,
    150   IN INT32 Pool,
    151   IN UINT32 BufPhysAddr,
    152   IN UINT32 BufVirtAddr,
    153   IN INT32 McId
    154   );
    155 
    156 VOID
    157 Mvpp2PoolRefill (
    158   IN PP2DXE_PORT *Port,
    159   IN UINT32 Bm,
    160   IN UINT32 PhysAddr,
    161   IN UINT32 Cookie
    162   );
    163 
    164 INTN
    165 Mvpp2BmPoolCtrl (
    166   IN MVPP2_SHARED *Priv,
    167   IN INTN Pool,
    168   IN enum Mvpp2Command cmd
    169   );
    170 
    171 VOID
    172 Mvpp2InterruptsMask (
    173   IN VOID *arg
    174   );
    175 
    176 VOID
    177 Mvpp2InterruptsUnmask (
    178   IN VOID *arg
    179   );
    180 
    181 VOID
    182 Mvpp2PortEnable (
    183   IN PP2DXE_PORT *Port
    184   );
    185 
    186 VOID
    187 Mvpp2PortDisable (
    188   IN PP2DXE_PORT *Port
    189   );
    190 
    191 VOID
    192 Mvpp2DefaultsSet (
    193   IN PP2DXE_PORT *Port
    194   );
    195 
    196 VOID
    197 Mvpp2IngressEnable (
    198   IN PP2DXE_PORT *Port
    199   );
    200 
    201 VOID
    202 Mvpp2IngressDisable (
    203   IN PP2DXE_PORT *Port
    204   );
    205 
    206 VOID
    207 Mvpp2EgressEnable (
    208   IN PP2DXE_PORT *Port
    209   );
    210 
    211 VOID
    212 Mvpp2EgressDisable (
    213   IN PP2DXE_PORT *Port
    214   );
    215 
    216 UINT32
    217 Mvpp2BmCookieBuild (
    218   IN MVPP2_RX_DESC *RxDesc,
    219   IN INT32 Cpu
    220   );
    221 
    222 INT32
    223 Mvpp2TxqDrainSet (
    224   IN PP2DXE_PORT *Port,
    225   IN INT32 Txq,
    226   IN BOOLEAN En
    227   );
    228 
    229 INT32
    230 Mvpp2TxqPendDescNumGet (
    231   IN PP2DXE_PORT *Port,
    232   IN MVPP2_TX_QUEUE *Txq
    233   );
    234 
    235 UINT32
    236 Mvpp2AggrTxqPendDescNumGet (
    237   IN MVPP2_SHARED *Priv,
    238   IN INT32 Cpu
    239   );
    240 
    241 MVPP2_TX_DESC *
    242 Mvpp2TxqNextDescGet (
    243   MVPP2_TX_QUEUE *Txq
    244   );
    245 
    246 VOID
    247 Mvpp2AggrTxqPendDescAdd (
    248   IN PP2DXE_PORT *Port,
    249   IN INT32 Pending
    250   );
    251 
    252 INT32
    253 Mvpp2AggrDescNumCheck (
    254   IN MVPP2_SHARED *Priv,
    255   IN MVPP2_TX_QUEUE *AggrTxq,
    256   IN INT32 Num,
    257   IN INT32 Cpu
    258   );
    259 
    260 INT32
    261 Mvpp2TxqAllocReservedDesc (
    262   IN MVPP2_SHARED *Priv,
    263   IN MVPP2_TX_QUEUE *Txq,
    264   IN INT32 Num
    265   );
    266 
    267 VOID
    268 Mvpp2TxqDescPut (
    269   IN MVPP2_TX_QUEUE *Txq
    270   );
    271 
    272 UINT32
    273 Mvpp2TxqDescCsum (
    274   IN INT32 L3Offs,
    275   IN INT32 L3Proto,
    276   IN INT32 IpHdrLen,
    277   IN INT32 L4Proto
    278   );
    279 
    280 VOID
    281 Mvpp2TxqSentCounterClear (
    282   IN OUT VOID *arg
    283   );
    284 
    285 VOID
    286 Mvpp2GmacMaxRxSizeSet (
    287   IN PP2DXE_PORT *Port
    288   );
    289 
    290 VOID
    291 Mvpp2TxpMaxTxSizeSet (
    292   IN PP2DXE_PORT *Port
    293   );
    294 
    295 VOID
    296 Mvpp2RxPktsCoalSet (
    297   IN PP2DXE_PORT *Port,
    298   IN OUT MVPP2_RX_QUEUE *Rxq,
    299   IN UINT32 Pkts
    300   );
    301 
    302 VOID
    303 Mvpp2RxTimeCoalSet (
    304   IN PP2DXE_PORT *Port,
    305   IN OUT MVPP2_RX_QUEUE *Rxq,
    306   IN UINT32 Usec
    307   );
    308 
    309 VOID
    310 Mvpp2AggrTxqHwInit (
    311   IN OUT MVPP2_TX_QUEUE *AggrTxq,
    312   IN INT32 DescNum,
    313   IN INT32 Cpu,
    314   IN MVPP2_SHARED *Priv
    315   );
    316 
    317 VOID
    318 Mvpp2RxqHwInit (
    319   IN PP2DXE_PORT *Port,
    320   IN OUT MVPP2_RX_QUEUE *Rxq
    321   );
    322 
    323 VOID
    324 Mvpp2RxqDropPkts (
    325   IN PP2DXE_PORT *Port,
    326   IN OUT MVPP2_RX_QUEUE *Rxq,
    327   IN INT32 Cpu
    328   );
    329 
    330 VOID
    331 Mvpp2TxqHwInit (
    332   IN PP2DXE_PORT *Port,
    333   IN OUT MVPP2_TX_QUEUE *Txq
    334   );
    335 
    336 VOID
    337 Mvpp2TxqHwDeinit (
    338   IN PP2DXE_PORT *Port,
    339   IN OUT MVPP2_TX_QUEUE *Txq
    340   );
    341 
    342 VOID
    343 Mvpp2PortPowerUp (
    344   IN PP2DXE_PORT *Port
    345   );
    346 
    347 VOID
    348 Mvpp2RxFifoInit (
    349   IN MVPP2_SHARED *Priv
    350   );
    351 
    352 VOID
    353 Mvpp2RxqHwDeinit (
    354   IN PP2DXE_PORT *Port,
    355   IN OUT MVPP2_RX_QUEUE *Rxq
    356   );
    357 
    358 INT32
    359 MvGop110NetcInit (
    360   IN PP2DXE_PORT *Port,
    361   IN UINT32 NetCompConfig,
    362   IN enum MvNetcPhase phase
    363   );
    364 
    365 UINT32
    366 MvpPp2xGop110NetcCfgCreate (
    367   IN PP2DXE_PORT *Port
    368   );
    369 
    370 INT32
    371 MvGop110PortInit (
    372   IN PP2DXE_PORT *Port
    373   );
    374 
    375 INT32
    376 MvGop110GmacReset (
    377   IN PP2DXE_PORT *Port,
    378   IN enum MvReset ResetCmd
    379   );
    380 
    381 INT32
    382 MvGop110GpcsModeCfg (
    383   IN PP2DXE_PORT *Port,
    384   BOOLEAN En
    385   );
    386 
    387 INT32
    388 MvGop110BypassClkCfg (
    389   IN PP2DXE_PORT *Port,
    390   IN BOOLEAN En
    391   );
    392 
    393 INT32
    394 MvGop110GpcsReset (
    395   IN PP2DXE_PORT *Port,
    396   IN enum MvReset ResetCmd
    397   );
    398 
    399 VOID
    400 MvGop110Xlg2GigMacCfg (
    401   IN PP2DXE_PORT *Port
    402   );
    403 
    404 INT32
    405 MvGop110GmacModeCfg (
    406   IN PP2DXE_PORT *Port
    407   );
    408 
    409 VOID
    410 MvGop110GmacRgmiiCfg (
    411   IN PP2DXE_PORT *Port
    412   );
    413 
    414 VOID
    415 MvGop110GmacSgmii25Cfg (
    416   IN PP2DXE_PORT *Port
    417   );
    418 
    419 VOID
    420 MvGop110GmacSgmiiCfg (
    421   IN PP2DXE_PORT *Port
    422   );
    423 
    424 VOID
    425 MvGop110GmacQsgmiiCfg (
    426   IN PP2DXE_PORT *Port
    427   );
    428 
    429 INT32
    430 Mvpp2SmiPhyAddrCfg (
    431   IN PP2DXE_PORT *Port,
    432   IN INT32 PortId,
    433   IN INT32 Addr
    434   );
    435 
    436 BOOLEAN
    437 MvGop110PortIsLinkUp (
    438   IN PP2DXE_PORT *Port
    439   );
    440 
    441 BOOLEAN
    442 MvGop110GmacLinkStatusGet (
    443   IN PP2DXE_PORT *Port
    444   );
    445 
    446 VOID
    447 MvGop110PortDisable (
    448   IN PP2DXE_PORT *Port
    449   );
    450 
    451 VOID
    452 MvGop110PortEnable (
    453   IN PP2DXE_PORT *Port
    454   );
    455 
    456 VOID
    457 MvGop110GmacPortEnable (
    458   IN PP2DXE_PORT *Port
    459   );
    460 
    461 VOID
    462 MvGop110GmacPortDisable (
    463   IN PP2DXE_PORT *Port
    464   );
    465 
    466 VOID
    467 MvGop110GmacPortLinkEventMask (
    468   IN PP2DXE_PORT *Port
    469   );
    470 
    471 INT32
    472 MvGop110PortEventsMask (
    473   IN PP2DXE_PORT *Port
    474   );
    475 
    476 INT32
    477 MvGop110FlCfg (
    478   IN PP2DXE_PORT *Port
    479   );
    480 
    481 INT32
    482 MvGop110SpeedDuplexSet (
    483   IN PP2DXE_PORT *Port,
    484   IN INT32 Speed,
    485   IN enum MvPortDuplex Duplex
    486   );
    487 
    488 INT32
    489 MvGop110GmacSpeedDuplexSet (
    490   IN PP2DXE_PORT *Port,
    491   IN INT32 Speed,
    492   IN enum MvPortDuplex Duplex
    493   );
    494 
    495 VOID
    496 Mvpp2AxiConfig (
    497   IN MVPP2_SHARED *Priv
    498   );
    499 
    500 VOID
    501 Mvpp2TxpClean (
    502   IN PP2DXE_PORT *Port,
    503   IN INT32 Txp,
    504   IN MVPP2_TX_QUEUE *Txq
    505   );
    506 
    507 VOID
    508 Mvpp2CleanupTxqs (
    509   IN PP2DXE_PORT *Port
    510   );
    511 
    512 VOID
    513 Mvpp2CleanupRxqs (
    514   IN PP2DXE_PORT *Port
    515   );
    516 
    517 /* Get number of physical egress Port */
    518 STATIC
    519 inline
    520 INT32
    521 Mvpp2EgressPort (
    522   IN PP2DXE_PORT *Port
    523   )
    524 {
    525   return MVPP2_MAX_TCONT + Port->Id;
    526 }
    527 
    528 /* Get number of physical TXQ */
    529 STATIC
    530 inline
    531 INT32
    532 Mvpp2TxqPhys (
    533   IN INT32 PortId,
    534   IN INT32 Txq
    535   )
    536 {
    537   return (MVPP2_MAX_TCONT + PortId) * MVPP2_MAX_TXQ + Txq;
    538 }
    539 
    540 /* Set Pool number in a BM Cookie */
    541 STATIC
    542 inline
    543 UINT32
    544 Mvpp2BmCookiePoolSet (
    545   IN UINT32 Cookie,
    546   IN INT32 Pool
    547   )
    548 {
    549   UINT32 Bm;
    550 
    551   Bm = Cookie & ~(0xFF << MVPP2_BM_COOKIE_POOL_OFFS);
    552   Bm |= ((Pool & 0xFF) << MVPP2_BM_COOKIE_POOL_OFFS);
    553 
    554   return Bm;
    555 }
    556 
    557 /* Get Pool number from a BM Cookie */
    558 STATIC
    559 inline
    560 INT32
    561 Mvpp2BmCookiePoolGet (
    562   IN UINT32 Cookie
    563   )
    564 {
    565   return (Cookie >> MVPP2_BM_COOKIE_POOL_OFFS) & 0xFF;
    566 }
    567 
    568 /* Release buffer to BM */
    569 STATIC
    570 inline
    571 VOID
    572 Mvpp2BmPoolPut (
    573   IN MVPP2_SHARED *Priv,
    574   IN INT32 Pool,
    575   IN UINT64 BufPhysAddr,
    576   IN UINT64 BufVirtAddr
    577   )
    578 {
    579   UINT32 Val = 0;
    580 
    581   Val = (Upper32Bits(BufVirtAddr) & MVPP22_ADDR_HIGH_MASK) << MVPP22_BM_VIRT_HIGH_RLS_OFFST;
    582   Val |= (Upper32Bits(BufPhysAddr) & MVPP22_ADDR_HIGH_MASK) << MVPP22_BM_PHY_HIGH_RLS_OFFSET;
    583   Mvpp2Write(Priv, MVPP22_BM_PHY_VIRT_HIGH_RLS_REG, Val);
    584   Mvpp2Write(Priv, MVPP2_BM_VIRT_RLS_REG, (UINT32)BufVirtAddr);
    585   Mvpp2Write(Priv, MVPP2_BM_PHY_RLS_REG(Pool), (UINT32)BufPhysAddr);
    586 }
    587 
    588 STATIC
    589 inline
    590 VOID
    591 Mvpp2InterruptsEnable (
    592   IN PP2DXE_PORT *Port,
    593   IN INT32 CpuMask
    594   )
    595 {
    596   Mvpp2Write(Port->Priv, MVPP2_ISR_ENABLE_REG(Port->Id), MVPP2_ISR_ENABLE_INTERRUPT(CpuMask));
    597 }
    598 
    599 STATIC
    600 inline
    601 VOID
    602 Mvpp2InterruptsDisable (
    603   IN PP2DXE_PORT *Port,
    604   IN INT32 CpuMask
    605   )
    606 {
    607   Mvpp2Write(Port->Priv, MVPP2_ISR_ENABLE_REG(Port->Id), MVPP2_ISR_DISABLE_INTERRUPT(CpuMask));
    608 }
    609 
    610 /* Get number of Rx descriptors occupied by received packets */
    611 STATIC
    612 inline
    613 INT32
    614 Mvpp2RxqReceived (
    615   IN PP2DXE_PORT *Port,
    616   IN INT32 RxqId
    617   )
    618 {
    619   UINT32 Val = Mvpp2Read(Port->Priv, MVPP2_RXQ_STATUS_REG(RxqId));
    620 
    621   return Val & MVPP2_RXQ_OCCUPIED_MASK;
    622 }
    623 
    624 /*
    625  * Update Rx Queue status with the number of occupied and available
    626  * Rx descriptor slots.
    627  */
    628 STATIC
    629 inline
    630 VOID
    631 Mvpp2RxqStatusUpdate (
    632   IN PP2DXE_PORT *Port,
    633   IN INT32 RxqId,
    634   IN INT32 UsedCount,
    635   IN INT32 FreeCount
    636   )
    637 {
    638   /*
    639    * Decrement the number of used descriptors and increment count
    640    * increment the number of free descriptors.
    641    */
    642   UINT32 Val = UsedCount | (FreeCount << MVPP2_RXQ_NUM_NEW_OFFSET);
    643 
    644   Mvpp2Write(Port->Priv, MVPP2_RXQ_STATUS_UPDATE_REG(RxqId), Val);
    645 }
    646 
    647 /* Get pointer to next RX descriptor to be processed by SW */
    648 STATIC
    649 inline
    650 MVPP2_RX_DESC *
    651 Mvpp2RxqNextDescGet (
    652   IN MVPP2_RX_QUEUE *Rxq
    653   )
    654 {
    655   INT32 RxDesc = Rxq->NextDescToProc;
    656 
    657   Rxq->NextDescToProc = MVPP2_QUEUE_NEXT_DESC(Rxq, RxDesc);
    658   Mvpp2Prefetch(Rxq->Descs + Rxq->NextDescToProc);
    659   return Rxq->Descs + RxDesc;
    660 }
    661 
    662 /*
    663  * Get number of sent descriptors and decrement counter.
    664  * The number of sent descriptors is returned.
    665  * Per-CPU access
    666  */
    667 STATIC
    668 inline
    669 INT32
    670 Mvpp2TxqSentDescProc (
    671   IN PP2DXE_PORT *Port,
    672   IN MVPP2_TX_QUEUE *Txq
    673   )
    674 {
    675   UINT32 Val;
    676 
    677   /* Reading status reg resets transmitted descriptor counter */
    678 #ifdef MVPP2V1
    679   Val = Mvpp2Read(Port->Priv, MVPP2_TXQ_SENT_REG(Txq->Id));
    680 #else
    681   Val = Mvpp2Read(Port->Priv, MVPP22_TXQ_SENT_REG(Txq->Id));
    682 #endif
    683 
    684   return (Val & MVPP2_TRANSMITTED_COUNT_MASK) >> MVPP2_TRANSMITTED_COUNT_OFFSET;
    685 }
    686 
    687 STATIC
    688 inline
    689 MVPP2_RX_QUEUE *
    690 Mvpp2GetRxQueue (
    691   IN PP2DXE_PORT *Port,
    692   IN UINT32 Cause
    693   )
    694 {
    695   INT32 Queue = Mvpp2Fls(Cause) - 1;
    696 
    697   return &Port->Rxqs[Queue];
    698 }
    699 
    700 STATIC
    701 inline
    702 MVPP2_TX_QUEUE *
    703 Mvpp2GetTxQueue (
    704   IN PP2DXE_PORT *Port,
    705   IN UINT32 Cause
    706   )
    707 {
    708   INT32 Queue = Mvpp2Fls(Cause) - 1;
    709 
    710   return &Port->Txqs[Queue];
    711 }
    712 
    713 STATIC
    714 inline
    715 void
    716 Mvpp2x2TxdescPhysAddrSet (
    717   IN DmaAddrT PhysAddr,
    718   IN MVPP2_TX_DESC *TxDesc
    719   )
    720 {
    721   UINT64 *BufPhysAddrP = &TxDesc->BufPhysAddrHwCmd2;
    722 
    723   *BufPhysAddrP &= ~(MVPP22_ADDR_MASK);
    724   *BufPhysAddrP |= PhysAddr & MVPP22_ADDR_MASK;
    725 }
    726 #endif /* __MVPP2_LIB_H__ */
    727