openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

atp.h (7877B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        atp_bet.h
      8  * Purpose:     
      9  */
     10 
     11 #ifndef   _CPUTRANS_ATP_H_
     12 #define   _CPUTRANS_ATP_H_
     13 
     14 #include <sdk_config.h>
     15 #include <shared/idents.h>
     16 
     17 #include <bcm/types.h>
     18 #include <bcm/pkt.h>
     19 #include <bcm/rx.h>
     20 #include <bcm/error.h>
     21 
     22 #include <appl/cputrans/cputrans.h>
     23 
     24 /*
     25  * Function prototype for ATP callbacks.  Callback may steal the packet.
     26  *
     27  * If the application steals the packet, it must free the data using
     28  * atp_free on the allocation pointer (alloc_ptr).
     29  *
     30  * NOTE:  For BET callbacks and loopback packets, the pkt pointer
     31  * may be NULL, and only the payload pointer is set.
     32  */
     33 
     34 typedef bcm_rx_t (*atp_client_cb_f)(cpudb_key_t src_key,
     35                                     int client_id,
     36                                     bcm_pkt_t *pkt,  /* Pass to free */
     37                                     uint8 *payload,  /* Pass to free */
     38                                     int payload_len,
     39                                     void *cookie);
     40 
     41 typedef void (*atp_tx_cb_f)(uint8 *pkt, void *cookie, int rv);
     42 
     43 /*
     44  * ATP Timeout callback.  If an ATP transaction times out and
     45  * a timeout callback is registered, it is called just before
     46  * the timeout failure is returned to the calling application.
     47  */
     48 typedef void (*atp_timeout_cb_f)(cpudb_key_t dest_key);
     49 
     50 #ifdef INCLUDE_USER_KERNEL_TRANSPORTS
     51 #ifndef ATP_RETRY_TIMEOUT_DEFAULT
     52 #define ATP_RETRY_TIMEOUT_DEFAULT 1000000
     53 #endif
     54 #ifndef ATP_RETRY_TIMEOUT_MIN
     55 #define ATP_RETRY_TIMEOUT_MIN     500000
     56 #endif
     57 #else
     58 #ifndef ATP_RETRY_TIMEOUT_DEFAULT
     59 #define ATP_RETRY_TIMEOUT_DEFAULT 300000
     60 #endif
     61 #ifndef ATP_RETRY_TIMEOUT_MIN
     62 #define ATP_RETRY_TIMEOUT_MIN     100000
     63 #endif
     64 #endif
     65 
     66 #ifndef ATP_RETRY_COUNT_DEFAULT
     67 #define ATP_RETRY_COUNT_DEFAULT   10
     68 #endif
     69 
     70 /* Convenience */
     71 #ifndef ATP_TIMEOUT_DEFAULT
     72 #define ATP_TIMEOUT_DEFAULT       \
     73     (ATP_RETRY_COUNT_DEFAULT * ATP_RETRY_TIMEOUT_DEFAULT)
     74 #endif
     75 #ifndef ATP_RX_TRANSACT_DEFAULT
     76 #define ATP_RX_TRANSACT_DEFAULT   32
     77 #endif
     78 #ifndef ATP_TX_TRANSACT_DEFAULT
     79 #define ATP_TX_TRANSACT_DEFAULT   32
     80 #endif
     81 
     82 #ifndef ATP_COS_DEFAULT
     83 #define ATP_COS_DEFAULT       0
     84 #endif
     85 #ifndef ATP_VLAN_DEFAULT
     86 #define ATP_VLAN_DEFAULT      1
     87 #endif
     88 
     89 #define ATP_PKT_TYPE         SHARED_PKT_TYPE_ATP
     90 
     91 #ifndef ATP_RX_PRIORITY
     92 #define ATP_RX_PRIORITY           100   /* Priority used registering w/ RX */
     93 #endif
     94 #ifndef ATP_THREAD_PRIORITY_DEFAULT
     95 #define ATP_THREAD_PRIORITY_DEFAULT   100
     96 #endif
     97 #ifndef ATP_SEG_LEN_DEFAULT
     98 #define ATP_SEG_LEN_DEFAULT   (1518 - CPUTRANS_HEADER_BYTES)
     99 #endif
    100 
    101 #ifndef ATP_MTU
    102 #define ATP_MTU               (64 * 1024)
    103 #endif
    104 
    105 #ifndef ATP_CPU_COUNT_DEFAULT
    106 #define ATP_CPU_COUNT_DEFAULT  CPUDB_CPU_MAX
    107 #endif
    108 
    109 #define ATP_UNITS_ALL 0xffffffff
    110 
    111 /*
    112  * This global variable would determine if the allocated memory for the ATP ACK
    113  * pkt data would be from DMA pool or Heap. By default the value of this is 0
    114  * which means the allocation happens from DMA capable pool. Applications would
    115  * need to set it to a nonzero value if they would like SDK to use system Heap.
    116  */
    117 extern int atp_ack_pkt_data_from_heap;
    118 
    119 /*
    120  * Applications may override atp_tx on a per-CPU basis.
    121  * This provides the type description for such a function pointer.
    122  * Requires using atp_rx_inject to inject packets at the receive end.
    123  */
    124 
    125 typedef int (*atp_tx_f)(cpudb_key_t dest_key,
    126                         int client_id,
    127                         uint8 *pkt_buf,
    128                         int len,
    129                         uint32 ct_flags,
    130                         atp_tx_cb_f callback,
    131                         void *cookie);
    132 
    133 extern int atp_tx_override_set(cpudb_key_t dest_cpu, atp_tx_f override_tx);
    134 extern int atp_tx_override_get(cpudb_key_t dest_cpu, atp_tx_f *override_tx);
    135 
    136 extern int atp_cpu_no_ack_set(cpudb_key_t dest_cpu, int no_ack);
    137 extern int atp_cpu_no_ack_get(cpudb_key_t dest_cpu, int *no_ack);
    138 
    139 extern bcm_rx_t atp_rx_inject(cpudb_key_t src_key, int client_id,
    140                               uint8 *pkt_buf, int len);
    141 
    142 
    143 /****************************************************************
    144  *
    145  * ATP/BET client flags
    146  *   NO_ACK   Register client for best effort (no ACK).  Default is ACK.
    147  *   NEXT_HOP Register client to use next hop.  Default is C2C.
    148  *   REASSEM_BUF     When multi-segment packets are received,
    149  *            the ATP/BET layer can recopy into a new, single buffer
    150  *            and pass that back to the caller.  The cost here is
    151  *            memory allocation and copy.  Alternatively, the
    152  *            ATP/BET can pass back a packet structure with the
    153  *            segments in the pkt_blk structures.  The default is to
    154  *            pass back the segments in the packet.  If the client
    155  *            registers with this flag set, then the packet will be
    156  *            reassembled into a single buffer.
    157  *
    158  * ATP/BET overall flags
    159  *   LEARN_SLF
    160  *            If a valid packet is received, and the source is
    161  *            unknown, should it be added to the local keys?
    162  */
    163 
    164 /* Client flags */
    165 #define ATP_F_NO_ACK                     0x1
    166 #define ATP_F_NEXT_HOP                   0x2
    167 #define ATP_F_REASSEM_BUF                0x4
    168 
    169 /* Start flags */
    170 #define ATP_F_LEARN_SLF                  0x8
    171 
    172 /* Reserved flags for internal use */
    173 #define ATP_F_RESERVED                   0xffff0000
    174 
    175 extern int atp_config_get(int *tx_thrd_pri, int *rx_thrd_pri,
    176                               bcm_trans_ptr_t **trans_ptr);
    177 extern int atp_config_set(int tx_thrd_pri, int rx_thrd_pri,
    178                               bcm_trans_ptr_t *trans_ptr);
    179 
    180 extern int atp_start(uint32 flags,
    181                          uint32 unit_bmp,
    182                          uint32 rco_flags);
    183 
    184 
    185 extern void *atp_rx_data_alloc(int bytes);
    186 
    187 /*
    188  * Must be called on the payload pointer of stolen packets
    189  */
    190 extern void atp_rx_free(void *payload_ptr, void *pkt_ptr);
    191 
    192 extern void *atp_tx_data_alloc(int bytes);
    193 extern void atp_tx_data_free(void *ptr);
    194 
    195 extern int atp_stop(void);
    196 extern int atp_running(void);
    197 
    198 extern int atp_client_add(int client_id);
    199 extern int atp_register(int client_id,
    200                             uint32 flags,
    201                             atp_client_cb_f callback,
    202                             void *cookie,
    203                             int cos,
    204                             int vlan);
    205 
    206 extern void atp_unregister(int client_id);
    207 
    208 /*
    209  * Flags for ATP/BET transmit functions:  See CPUTRANS_ flags.
    210  */
    211 
    212 extern int atp_tx(cpudb_key_t dest_key,
    213                       int client_id,
    214                       uint8 *pkt_data,
    215                       int len,
    216                       uint32 ct_flags,
    217                       atp_tx_cb_f callback,
    218                       void *cookie);
    219 
    220 extern int atp_timeout_set(int retry_usecs, int num_retries);
    221 extern int atp_timeout_get(int *retry_usecs, int *num_retries);
    222 extern int atp_timeout_register(atp_timeout_cb_f callback);
    223 
    224 extern int atp_segment_len_set(int seg_len);
    225 extern int atp_segment_len_get(void);
    226 
    227 extern int atp_pool_size_set(int tx_max, int rx_max);
    228 extern int atp_pool_size_get(int *tx_max, int *rx_max);
    229 
    230 extern int atp_cpu_count_set(int count);
    231 extern int atp_cpu_count_get(void);
    232 
    233 extern int atp_key_add(cpudb_key_t key, int is_local);
    234 extern int atp_cpudb_keys_add(cpudb_ref_t db_ref);
    235 extern int atp_key_remove(cpudb_key_t key);
    236 extern int atp_key_purge(cpudb_key_t key);
    237 
    238 extern void atp_attach_callback(int unit, int attach, cpudb_entry_t *cpuent,
    239                                 int cpuunit);
    240 
    241 extern int atp_cos_vlan_set(int cos, int vlan);
    242 extern int atp_cos_vlan_get(int *cos, int *vlan);
    243 
    244 extern int atp_db_update(cpudb_ref_t db_ref);
    245 extern void atp_db_update_notify(void);
    246 #if defined(BROADCOM_DEBUG)
    247 extern void atp_dump(int verbose);
    248 #endif /* BROADCOM_DEBUG */
    249 #endif /* _CPUTRANS_ATP_H_ */
    250