LCOV - code coverage report
Current view: top level - drivers/net/nfp/nfpcore - nfp_cpp.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 4 0.0 %
Date: 2024-01-22 16:26:08 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 37 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018 Netronome Systems, Inc.
       3                 :            :  * All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #ifndef __NFP_CPP_H__
       7                 :            : #define __NFP_CPP_H__
       8                 :            : 
       9                 :            : #include <ethdev_pci.h>
      10                 :            : 
      11                 :            : /* NFP CPP handle */
      12                 :            : struct nfp_cpp;
      13                 :            : 
      14                 :            : /* NFP CPP device area handle */
      15                 :            : struct nfp_cpp_area;
      16                 :            : 
      17                 :            : #define NFP_SERIAL_LEN        6
      18                 :            : 
      19                 :            : #define NFP_CPP_NUM_TARGETS             16
      20                 :            : 
      21                 :            : #define PCI_64BIT_BAR_COUNT             3
      22                 :            : 
      23                 :            : /*
      24                 :            :  * NFP CPP operations structure
      25                 :            :  */
      26                 :            : struct nfp_cpp_operations {
      27                 :            :         /* Size of priv area in struct nfp_cpp_area */
      28                 :            :         size_t area_priv_size;
      29                 :            : 
      30                 :            :         /* Instance an NFP CPP */
      31                 :            :         int (*init)(struct nfp_cpp *cpp);
      32                 :            : 
      33                 :            :         /*
      34                 :            :          * Free the bus.
      35                 :            :          * Called only once, during nfp_cpp_unregister()
      36                 :            :          */
      37                 :            :         void (*free)(struct nfp_cpp *cpp);
      38                 :            : 
      39                 :            :         int (*get_interface)(struct rte_pci_device *dev,
      40                 :            :                         uint16_t *interface);
      41                 :            : 
      42                 :            :         int (*get_serial)(struct rte_pci_device *dev,
      43                 :            :                         uint8_t *serial,
      44                 :            :                         size_t length);
      45                 :            : 
      46                 :            :         /*
      47                 :            :          * Initialize a new NFP CPP area
      48                 :            :          * NOTE: This is _not_ serialized
      49                 :            :          */
      50                 :            :         int (*area_init)(struct nfp_cpp_area *area,
      51                 :            :                         uint32_t dest,
      52                 :            :                         uint64_t address,
      53                 :            :                         size_t size);
      54                 :            :         /*
      55                 :            :          * Clean up a NFP CPP area before it is freed
      56                 :            :          * NOTE: This is _not_ serialized
      57                 :            :          */
      58                 :            :         void (*area_cleanup)(struct nfp_cpp_area *area);
      59                 :            : 
      60                 :            :         /*
      61                 :            :          * Acquire resources for a NFP CPP area
      62                 :            :          * Serialized
      63                 :            :          */
      64                 :            :         int (*area_acquire)(struct nfp_cpp_area *area);
      65                 :            : 
      66                 :            :         /*
      67                 :            :          * Release resources for a NFP CPP area
      68                 :            :          * Serialized
      69                 :            :          */
      70                 :            :         void (*area_release)(struct nfp_cpp_area *area);
      71                 :            : 
      72                 :            :         /*
      73                 :            :          * Return a void IO pointer to a NFP CPP area
      74                 :            :          * NOTE: This is _not_ serialized
      75                 :            :          */
      76                 :            :         void *(*area_iomem)(struct nfp_cpp_area *area);
      77                 :            : 
      78                 :            :         /*
      79                 :            :          * Perform a read from a NFP CPP area
      80                 :            :          * Serialized
      81                 :            :          */
      82                 :            :         int (*area_read)(struct nfp_cpp_area *area,
      83                 :            :                         void *kernel_vaddr,
      84                 :            :                         uint32_t offset,
      85                 :            :                         size_t length);
      86                 :            :         /*
      87                 :            :          * Perform a write to a NFP CPP area
      88                 :            :          * Serialized
      89                 :            :          */
      90                 :            :         int (*area_write)(struct nfp_cpp_area *area,
      91                 :            :                         const void *kernel_vaddr,
      92                 :            :                         uint32_t offset,
      93                 :            :                         size_t length);
      94                 :            : };
      95                 :            : 
      96                 :            : /*
      97                 :            :  * Wildcard indicating a CPP read or write action
      98                 :            :  *
      99                 :            :  * The action used will be either read or write depending on whether a read or
     100                 :            :  * write instruction/call is performed on the NFP_CPP_ID.  It is recommended that
     101                 :            :  * the RW action is used even if all actions to be performed on a NFP_CPP_ID are
     102                 :            :  * known to be only reads or writes. Doing so will in many cases save NFP CPP
     103                 :            :  * internal software resources.
     104                 :            :  */
     105                 :            : #define NFP_CPP_ACTION_RW 32
     106                 :            : 
     107                 :            : #define NFP_CPP_TARGET_ID_MASK 0x1f
     108                 :            : 
     109                 :            : /**
     110                 :            :  * Pack target, token, and action into a CPP ID.
     111                 :            :  *
     112                 :            :  * Create a 32-bit CPP identifier representing the access to be made.
     113                 :            :  * These identifiers are used as parameters to other NFP CPP functions.
     114                 :            :  * Some CPP devices may allow wildcard identifiers to be specified.
     115                 :            :  *
     116                 :            :  * @param target
     117                 :            :  *   NFP CPP target id
     118                 :            :  * @param action
     119                 :            :  *   NFP CPP action id
     120                 :            :  * @param token
     121                 :            :  *   NFP CPP token id
     122                 :            :  *
     123                 :            :  * @return
     124                 :            :  *   NFP CPP ID
     125                 :            :  */
     126                 :            : #define NFP_CPP_ID(target, action, token)                               \
     127                 :            :                 ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \
     128                 :            :                 (((action) & 0xff) << 8))
     129                 :            : 
     130                 :            : /**
     131                 :            :  * Pack target, token, action, and island into a CPP ID.
     132                 :            :  *
     133                 :            :  * Create a 32-bit CPP identifier representing the access to be made.
     134                 :            :  * These identifiers are used as parameters to other NFP CPP functions.
     135                 :            :  * Some CPP devices may allow wildcard identifiers to be specified.
     136                 :            :  *
     137                 :            :  * @param target
     138                 :            :  *   NFP CPP target id
     139                 :            :  * @param action
     140                 :            :  *   NFP CPP action id
     141                 :            :  * @param token
     142                 :            :  *   NFP CPP token id
     143                 :            :  * @param island
     144                 :            :  *   NFP CPP island id
     145                 :            :  *
     146                 :            :  * @return
     147                 :            :  *   NFP CPP ID
     148                 :            :  */
     149                 :            : #define NFP_CPP_ISLAND_ID(target, action, token, island)                \
     150                 :            :                 ((((target) & 0x7f) << 24) | (((token) & 0xff) << 16) | \
     151                 :            :                 (((action) & 0xff) << 8) | (((island) & 0xff) << 0))
     152                 :            : 
     153                 :            : /**
     154                 :            :  * Return the NFP CPP target of a NFP CPP ID
     155                 :            :  *
     156                 :            :  * @param id
     157                 :            :  *   NFP CPP ID
     158                 :            :  *
     159                 :            :  * @return
     160                 :            :  *   NFP CPP target
     161                 :            :  */
     162                 :            : static inline uint8_t
     163                 :            : NFP_CPP_ID_TARGET_of(uint32_t id)
     164                 :            : {
     165   [ #  #  #  #  :          0 :         return (id >> 24) & NFP_CPP_TARGET_ID_MASK;
          #  #  #  #  #  
             #  #  #  # ]
     166                 :            : }
     167                 :            : 
     168                 :            : /**
     169                 :            :  * Return the NFP CPP token of a NFP CPP ID
     170                 :            :  *
     171                 :            :  * @param id
     172                 :            :  *   NFP CPP ID
     173                 :            :  *
     174                 :            :  * @return
     175                 :            :  *   NFP CPP token
     176                 :            :  */
     177                 :            : static inline uint8_t
     178                 :            : NFP_CPP_ID_TOKEN_of(uint32_t id)
     179                 :            : {
     180                 :          0 :         return (id >> 16) & 0xff;
     181                 :            : }
     182                 :            : 
     183                 :            : /**
     184                 :            :  * Return the NFP CPP action of a NFP CPP ID
     185                 :            :  *
     186                 :            :  * @param id
     187                 :            :  *   NFP CPP ID
     188                 :            :  *
     189                 :            :  * @return
     190                 :            :  *   NFP CPP action
     191                 :            :  */
     192                 :            : static inline uint8_t
     193                 :            : NFP_CPP_ID_ACTION_of(uint32_t id)
     194                 :            : {
     195                 :          0 :         return (id >> 8) & 0xff;
     196                 :            : }
     197                 :            : 
     198                 :            : /**
     199                 :            :  * Return the NFP CPP island of a NFP CPP ID
     200                 :            :  *
     201                 :            :  * @param id
     202                 :            :  *   NFP CPP ID
     203                 :            :  *
     204                 :            :  * @return
     205                 :            :  *   NFP CPP island
     206                 :            :  */
     207                 :            : static inline uint8_t
     208                 :            : NFP_CPP_ID_ISLAND_of(uint32_t id)
     209                 :            : {
     210   [ #  #  #  #  :          0 :         return id & 0xff;
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     211                 :            : }
     212                 :            : 
     213                 :            : void nfp_cpp_model_set(struct nfp_cpp *cpp, uint32_t model);
     214                 :            : 
     215                 :            : void nfp_cpp_interface_set(struct nfp_cpp *cpp, uint32_t interface);
     216                 :            : 
     217                 :            : void nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial,
     218                 :            :                 size_t serial_len);
     219                 :            : 
     220                 :            : void nfp_cpp_priv_set(struct nfp_cpp *cpp, void *priv);
     221                 :            : 
     222                 :            : void *nfp_cpp_priv(struct nfp_cpp *cpp);
     223                 :            : 
     224                 :            : void *nfp_cpp_area_priv(struct nfp_cpp_area *cpp_area);
     225                 :            : 
     226                 :            : uint32_t nfp_cpp_model_autodetect(struct nfp_cpp *cpp, uint32_t *model);
     227                 :            : 
     228                 :            : /* NFP CPP core interface for CPP clients */
     229                 :            : struct nfp_cpp *nfp_cpp_from_device_name(struct rte_pci_device *dev,
     230                 :            :                 void *priv, bool driver_lock_needed);
     231                 :            : 
     232                 :            : void nfp_cpp_free(struct nfp_cpp *cpp);
     233                 :            : 
     234                 :            : #define NFP_CPP_MODEL_INVALID   0xffffffff
     235                 :            : 
     236                 :            : uint32_t nfp_cpp_model(struct nfp_cpp *cpp);
     237                 :            : 
     238                 :            : /*
     239                 :            :  * NFP Interface types - logical interface for this CPP connection 4 bits are
     240                 :            :  * reserved for interface type.
     241                 :            :  */
     242                 :            : #define NFP_CPP_INTERFACE_TYPE_INVALID          0x0
     243                 :            : #define NFP_CPP_INTERFACE_TYPE_PCI              0x1
     244                 :            : #define NFP_CPP_INTERFACE_TYPE_ARM              0x2
     245                 :            : #define NFP_CPP_INTERFACE_TYPE_RPC              0x3
     246                 :            : #define NFP_CPP_INTERFACE_TYPE_ILA              0x4
     247                 :            : 
     248                 :            : /**
     249                 :            :  * Construct a 16-bit NFP Interface ID
     250                 :            :  *
     251                 :            :  * Interface IDs consists of 4 bits of interface type, 4 bits of unit
     252                 :            :  * identifier, and 8 bits of channel identifier.
     253                 :            :  *
     254                 :            :  * The NFP Interface ID is used in the implementation of NFP CPP API mutexes,
     255                 :            :  * which use the MU Atomic CompareAndWrite operation - hence the limit to 16
     256                 :            :  * bits to be able to use the NFP Interface ID as a lock owner.
     257                 :            :  *
     258                 :            :  * @param type
     259                 :            :  *   NFP Interface Type
     260                 :            :  * @param unit
     261                 :            :  *   Unit identifier for the interface type
     262                 :            :  * @param channel
     263                 :            :  *   Channel identifier for the interface unit
     264                 :            :  *
     265                 :            :  * @return
     266                 :            :  *   Interface ID
     267                 :            :  */
     268                 :            : #define NFP_CPP_INTERFACE(type, unit, channel) \
     269                 :            :         ((((type) & 0xf) << 12) | \
     270                 :            :          (((unit) & 0xf) <<  8) | \
     271                 :            :          (((channel) & 0xff) << 0))
     272                 :            : 
     273                 :            : /**
     274                 :            :  * Get the interface type of a NFP Interface ID
     275                 :            :  *
     276                 :            :  * @param interface
     277                 :            :  *   NFP Interface ID
     278                 :            :  *
     279                 :            :  * @return
     280                 :            :  *   NFP Interface ID's type
     281                 :            :  */
     282                 :            : #define NFP_CPP_INTERFACE_TYPE_of(interface)    (((interface) >> 12) & 0xf)
     283                 :            : 
     284                 :            : /**
     285                 :            :  * Get the interface unit of a NFP Interface ID
     286                 :            :  *
     287                 :            :  * @param interface
     288                 :            :  *   NFP Interface ID
     289                 :            :  *
     290                 :            :  * @return
     291                 :            :  *   NFP Interface ID's unit
     292                 :            :  */
     293                 :            : #define NFP_CPP_INTERFACE_UNIT_of(interface)    (((interface) >>  8) & 0xf)
     294                 :            : 
     295                 :            : /**
     296                 :            :  * Get the interface channel of a NFP Interface ID
     297                 :            :  *
     298                 :            :  * @param interface
     299                 :            :  *   NFP Interface ID
     300                 :            :  *
     301                 :            :  * @return
     302                 :            :  *   NFP Interface ID's channel
     303                 :            :  */
     304                 :            : #define NFP_CPP_INTERFACE_CHANNEL_of(interface) (((interface) >>  0) & 0xff)
     305                 :            : 
     306                 :            : /*
     307                 :            :  * Use this channel ID for multiple virtual channel interfaces
     308                 :            :  * (ie ARM and PCIe) when setting up the interface field.
     309                 :            :  */
     310                 :            : #define NFP_CPP_INTERFACE_CHANNEL_PEROPENER    255
     311                 :            : 
     312                 :            : uint16_t nfp_cpp_interface(struct nfp_cpp *cpp);
     313                 :            : 
     314                 :            : uint32_t nfp_cpp_serial(struct nfp_cpp *cpp, const uint8_t **serial);
     315                 :            : 
     316                 :            : bool nfp_cpp_driver_need_lock(const struct nfp_cpp *cpp);
     317                 :            : 
     318                 :            : struct nfp_cpp_area *nfp_cpp_area_alloc(struct nfp_cpp *cpp, uint32_t cpp_id,
     319                 :            :                 uint64_t address, size_t size);
     320                 :            : 
     321                 :            : struct nfp_cpp_area *nfp_cpp_area_alloc_with_name(struct nfp_cpp *cpp,
     322                 :            :                 uint32_t cpp_id, const char *name, uint64_t address,
     323                 :            :                 uint32_t size);
     324                 :            : 
     325                 :            : void nfp_cpp_area_free(struct nfp_cpp_area *area);
     326                 :            : 
     327                 :            : int nfp_cpp_area_acquire(struct nfp_cpp_area *area);
     328                 :            : 
     329                 :            : void nfp_cpp_area_release(struct nfp_cpp_area *area);
     330                 :            : 
     331                 :            : struct nfp_cpp_area *nfp_cpp_area_alloc_acquire(struct nfp_cpp *cpp,
     332                 :            :                 uint32_t cpp_id, uint64_t address, size_t size);
     333                 :            : 
     334                 :            : void nfp_cpp_area_release_free(struct nfp_cpp_area *area);
     335                 :            : 
     336                 :            : uint8_t *nfp_cpp_map_area(struct nfp_cpp *cpp, uint32_t cpp_id,
     337                 :            :                 uint64_t addr, uint32_t size, struct nfp_cpp_area **area);
     338                 :            : 
     339                 :            : int nfp_cpp_area_read(struct nfp_cpp_area *area, uint32_t offset,
     340                 :            :                 void *address, size_t length);
     341                 :            : 
     342                 :            : int nfp_cpp_area_write(struct nfp_cpp_area *area, uint32_t offset,
     343                 :            :                 const void *address, size_t length);
     344                 :            : 
     345                 :            : void *nfp_cpp_area_iomem(struct nfp_cpp_area *area);
     346                 :            : 
     347                 :            : struct nfp_cpp *nfp_cpp_area_cpp(struct nfp_cpp_area *cpp_area);
     348                 :            : 
     349                 :            : const char *nfp_cpp_area_name(struct nfp_cpp_area *cpp_area);
     350                 :            : 
     351                 :            : int nfp_cpp_read(struct nfp_cpp *cpp, uint32_t cpp_id,
     352                 :            :                 uint64_t address, void *buf, size_t length);
     353                 :            : 
     354                 :            : int nfp_cpp_write(struct nfp_cpp *cpp, uint32_t cpp_id,
     355                 :            :                 uint64_t address, const void *buf, size_t length);
     356                 :            : 
     357                 :            : int nfp_cpp_area_readl(struct nfp_cpp_area *area, uint32_t offset,
     358                 :            :                 uint32_t *value);
     359                 :            : 
     360                 :            : int nfp_cpp_area_writel(struct nfp_cpp_area *area, uint32_t offset,
     361                 :            :                 uint32_t value);
     362                 :            : 
     363                 :            : int nfp_cpp_area_readq(struct nfp_cpp_area *area, uint32_t offset,
     364                 :            :                 uint64_t *value);
     365                 :            : 
     366                 :            : int nfp_cpp_area_writeq(struct nfp_cpp_area *area, uint32_t offset,
     367                 :            :                 uint64_t value);
     368                 :            : 
     369                 :            : int nfp_xpb_writel(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t value);
     370                 :            : 
     371                 :            : int nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_tgt, uint32_t *value);
     372                 :            : 
     373                 :            : int nfp_cpp_readl(struct nfp_cpp *cpp, uint32_t cpp_id,
     374                 :            :                 uint64_t address, uint32_t *value);
     375                 :            : 
     376                 :            : int nfp_cpp_writel(struct nfp_cpp *cpp, uint32_t cpp_id,
     377                 :            :                 uint64_t address, uint32_t value);
     378                 :            : 
     379                 :            : int nfp_cpp_readq(struct nfp_cpp *cpp, uint32_t cpp_id,
     380                 :            :                 uint64_t address, uint64_t *value);
     381                 :            : 
     382                 :            : int nfp_cpp_writeq(struct nfp_cpp *cpp, uint32_t cpp_id,
     383                 :            :                 uint64_t address, uint64_t value);
     384                 :            : 
     385                 :            : uint32_t nfp_cpp_mu_locality_lsb(struct nfp_cpp *cpp);
     386                 :            : 
     387                 :            : #endif /* __NFP_CPP_H__ */

Generated by: LCOV version 1.14