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_int.h (9202B)


      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_int.h
      8  * Purpose:     Internal ATP function headers
      9  */
     10 
     11 #ifndef   _ATP_INT_H_
     12 #define   _ATP_INT_H_
     13 
     14 #include <sdk_config.h>
     15 #include <sal/core/time.h>
     16 #include <sal/core/sync.h>
     17 
     18 #include <bcm/types.h>
     19 #include <bcm/pkt.h>
     20 
     21 #include <appl/cputrans/atp.h>
     22 
     23 /*
     24  * This is the max number of objects that can be marked deleted
     25  * before the garbage collection task is forced to block
     26  *
     27  * GARBAGE_WAITING_SLEEP is how long the RX thread sleeps when
     28  * there's garbage waiting to be collected.  Thus, will wait at
     29  * most ATP_GARBAGE_MAX * ATP_GARBAGE_WAITING_SLEEP microseconds
     30  * before it blocks.
     31  */
     32 
     33 #ifndef ATP_GARBAGE_MAX
     34 #define ATP_GARBAGE_MAX 15
     35 #endif
     36 
     37 #ifndef ATP_GARBAGE_WAITING_SLEEP
     38 #define ATP_GARBAGE_WAITING_SLEEP 50000
     39 #endif
     40 
     41 #define ATP_VERSION       0
     42 
     43 #define ATP_HEADER_BYTES \
     44     (3 * sizeof(uint32) + 2 * sizeof(uint16) + 2 * sizeof(uint8))
     45 
     46 #define ATP_HEADER_START(pkt) (&((pkt)[CPUTRANS_ATP_OFS]))
     47 
     48 /* Sequence number offset:  version + client + hdr_flags */
     49 #define ATP_SEQ_NUM_OFS \
     50     (CPUTRANS_ATP_OFS + 2 * sizeof(uint16) + sizeof(uint32))
     51 
     52 /* Packet opcodes */
     53 typedef enum _atp_opcodes_e {
     54     _ATP_OPC_DATA,
     55     _ATP_OPC_ACK
     56 } _atp_opcodes_t;
     57 
     58 /* RX queue info */
     59 
     60 #ifndef ATP_PKT_DATA_QUEUE_LEN
     61 #define ATP_PKT_DATA_QUEUE_LEN 100
     62 #endif
     63 
     64 static volatile struct _atp_pkt_data_s {
     65     int len;
     66     uint8 *pkt_buf;
     67     uint32 flags;
     68     volatile struct _atp_pkt_data_s *next;
     69 } _atp_rx_pkt[ATP_PKT_DATA_QUEUE_LEN];
     70 
     71 typedef volatile struct _atp_pkt_data_s _atp_pkt_data_t;
     72 
     73 /*
     74  * ATP header information:
     75  *      This maintains the information sent/received in the ATP/BET
     76  *      header and additional info related to a packet segment transaction.
     77  *
     78  * Flags:
     79  *      HDR_NO_ACK         Don't ACK the packet.
     80  *      HDR_NEXT_HOP       Next hop transport being used
     81  *      HDR_RETRANSMIT     Retransmit of packet (data only, not ACK)
     82  *      HDR_IMMEDIATE_ACK  Send ACK immediately
     83  */
     84 
     85 typedef struct _atp_hdr_s _atp_hdr_t;
     86 struct _atp_hdr_s {
     87     int            client_id;     /* Client for packet */
     88     uint16         version;       /* Version number */
     89     uint32         hdr_flags;
     90     uint16         seq_num;       /* Sequence number of transaction */
     91     uint16         tot_bytes;     /* Total bytes in payload */
     92     uint16         tot_segs;      /* Total segments in transaction */
     93     uint16         segment;       /* Segment number */
     94 
     95     /*
     96      * For TX, start_byte is first byte of payload in this segment.
     97      * For ACK, start_byte is number of (contiguous) bytes received.
     98      * (which is the next byte that is expected).
     99      */
    100     uint16         start_byte; 
    101     uint8          opcode;        /* ACK, DATA, etc; see above */
    102     uint8          cos;           /* Cos */
    103 };
    104 
    105 #define _ATP_HDR_NO_ACK         0x1  /* No need to ACK this packet */
    106 #define _ATP_HDR_NEXT_HOP       0x2  /* Use next hop transport if available */
    107 #define _ATP_HDR_RETRANSMIT     0x4  /* This is a retrx packet */
    108 #define _ATP_HDR_IMMEDIATE_ACK  0x8  /* Send ACK immediately */
    109 
    110 /* Number of bytes allocated for an ACK packet */
    111 #define _ATP_ACK_BYTES (CPUTRANS_HEADER_BYTES < 68 ? 68 : CPUTRANS_HEADER_BYTES)
    112 
    113 /* Transaction control block structure */
    114 typedef volatile struct _atp_rx_trans_s _atp_rx_trans_t;
    115 struct _atp_rx_trans_s {
    116     _atp_hdr_t       _atp_hdr;        /* From first portion of pkt received */
    117     int            src_cpu;       /* Where is transact from */
    118 
    119     int            rcv_segs;      /* How many segments received */
    120     int            ack_count;     /* Number of times an ACK sent */
    121     int            payload_len;   /* Total length of the packet data */
    122 
    123     uint8         *ack_data;      /* This transaction's ACK packet */
    124     bcm_pkt_t     *pkt;           /* Pkt for data; setup by cputrans */
    125     uint8         *lb_data;       /* For loopback packets */
    126     sal_usecs_t    rcvd_time;     /* When was request received */
    127 
    128     uint32 flags;
    129 #define _ATP_RX_F_HANDLED     0x1   /* Has the local client been called */
    130 #define _ATP_RX_F_DATA_READY  0x2   /* For reassembly */
    131 #define _ATP_RX_F_LOOPBACK    0x10  /* Packet is loopback packet */
    132 #define _ATP_RX_F_ENQUEUED    0x20  /* For deferred deletion */
    133 
    134     volatile struct _atp_client_s   *client;
    135     _atp_rx_trans_t *next;
    136     _atp_rx_trans_t *prev;
    137 };
    138 
    139 #define RX_TRANS_DATA_DONE(_trans) \
    140    (_trans)->flags & (_ATP_RX_F_DATA_READY | _ATP_RX_F_HANDLED)
    141 
    142 #define RX_TRANS_NO_ACK(_trans) \
    143     ((_trans)->_atp_hdr.hdr_flags & _ATP_HDR_NO_ACK)
    144 #define RX_TRANS_ACK(_trans)  (!RX_TRANS_NO_ACK(_trans))
    145 #define RX_TRANS_NEXT_HOP(_trans) \
    146     ((_trans)->_atp_hdr.hdr_flags & _ATP_HDR_NEXT_HOP)
    147 #define RX_TRANS_C2C(_trans) (!RX_TRANS_NEXT_HOP(_trans))
    148 
    149 /* Transaction control block structure */
    150 typedef volatile struct _atp_tx_trans_s _atp_tx_trans_t;
    151 struct _atp_tx_trans_s {
    152     _atp_hdr_t     _atp_hdr;      /* Basic header for the transaction */
    153     int            dest_cpu;      /* Where's it going */
    154     uint8         *pkt_buf;       /* Pointer to original data */
    155     int            len;           /* Length of payload */
    156     uint32         ct_flags;      /* CPUTRANS flags */
    157     int            db_update;     /* What was DB update count last tx? */
    158 
    159     bcm_pkt_t     *pkt_list;      /* Linked list from cputrans alloc */
    160     sal_sem_t      tx_sem;        /* For sync transmit of ATP pkt */
    161     int            tx_count;      /* How many times sent */
    162     int            bytes_acked;   /* How many bytes in payload ACK'd */
    163     sal_usecs_t    last_tx; /* Last time sent */
    164 
    165     atp_tx_cb_f    callback;      /* If asynch, indicates callback */
    166     void          *cookie;        /* Passed to callback. */
    167     int            tx_rv;         /* Result of tx operation when async */
    168 
    169     int            seg_len;       /* Record in case dyncamically changed */
    170     uint32         flags;
    171 #define _ATP_TX_F_DONE        0x1   /* ACK seen */
    172 #define _ATP_TX_F_PENDING     0x2   /* Is TX being done? */
    173 #define _ATP_TX_F_TIMEOUT     0x4   /* TX timed out */
    174 #define _ATP_TX_ERROR_SEEN    0x8
    175 #define _ATP_TX_F_SYNC_LOCK   0x10  /* Transaction used for sync op */
    176 #define _ATP_TX_F_SEM_WAITING 0x20  /* Has TX semaphore been given? */
    177 #define _ATP_TX_F_DONE_MARK   0x40  /* Has done been handled already */
    178 #define _ATP_TX_F_ENQUEUED    0x80
    179 
    180     volatile struct _atp_client_s   *client;  /* Controlling client */
    181     _atp_tx_trans_t *next;          /* Linked lists of transactions */
    182     _atp_tx_trans_t *prev;          /* For dequeuing */
    183 };
    184 
    185 #define TX_TRANS_NO_ACK(_trans) \
    186     ((_trans)->_atp_hdr.hdr_flags & _ATP_HDR_NO_ACK)
    187 #define TX_TRANS_ACK(_trans)  (!TX_TRANS_NO_ACK(_trans))
    188 #define TX_TRANS_NEXT_HOP(_trans) \
    189     ((_trans)->_atp_hdr.hdr_flags & _ATP_HDR_NEXT_HOP)
    190 #define TX_TRANS_C2C(_trans) (!TX_TRANS_NEXT_HOP(_trans))
    191 
    192 /* Number of hash buckets allowed for client ID lists */
    193 #define _ATP_CLIENT_HASH_MAX 31
    194 
    195 #define ACK_PKT_SIZE            CPUTRANS_HEADER_BYTES
    196 
    197 /*
    198  * ATP client CPU structure.
    199  * Holds callback for RX operations, TX and RX queues for ATP and BET.
    200  * Holds sequence numbers per dest CPU.
    201  */
    202 
    203 typedef volatile struct _atp_client_cpu_s {
    204     _atp_rx_trans_t * rx_trans;  /* Current RX transaction */
    205     _atp_rx_trans_t * rx_tail;   /* Tail for RX trans queue */
    206     _atp_tx_trans_t * tx_trans;  /* TX trans linked list */
    207     _atp_tx_trans_t * tx_tail;   /* Tail for TX trans queues */
    208     uint8 cpu_flags;             /* Per CPU flags */
    209 #define ATP_CPU_RX_TRANS_SEEN     0x1  /* Seen an RX here, RX seq valid */
    210 #define ATP_CPU_ACK_PENDING       0x2  /* Is an ACK pending? */
    211 
    212     uint16 tx_seq_num;           /* Per-CPU TX Sequence number */
    213     uint16 rx_seq_num;           /* Per-CPU current ATP RX Sequence number */
    214 
    215     _atp_hdr_t atp_hdr;          /* Hdr from latest RX transact */
    216     bcm_pkt_t * bet_rx_pkts;     /* For BET packet accumulation */
    217     int bet_segs;                /* Segs in pkt: To be implemented. */
    218 
    219     uint8 *rx_ack_data;          /* Ack data when RX trans queue is empty */
    220 } _atp_client_cpu_t;
    221 
    222 /*
    223  * ATP client structure.
    224  * Holds callback for RX operations.
    225  * Holds CPU info per CPU.
    226  */
    227 
    228 typedef volatile struct _atp_client_s _atp_client_t;
    229 struct _atp_client_s {
    230     int client_id;              /* The actual ID */
    231     uint32 flags;               /* Flags; see atp.h */
    232 /* Remark:  atp.h reserves internal flags as:  ATP_F_RESERVED  0xffff0000 */
    233 
    234     /* TX params */
    235     int cos;                    /* COS and internal priority for packets
    236                                    for this client */
    237     int vlan;                   /* VLAN for packets for this client */
    238 
    239     _atp_client_t *next;        /* Linked lists for hash buckets */
    240     _atp_client_t *prev;        /* Linked lists for hash buckets */
    241 
    242     uint16 bet_tx_seq_num;      /* For best effort TX ops. */
    243 
    244     _atp_client_cpu_t cpu[CPUDB_CPU_MAX];     /* Per CPU info */
    245 
    246     atp_client_cb_f callback;   /* Callback for the client */
    247     void *cookie;               /* Passed to callback */
    248 };
    249 
    250 #endif /* _ATP_INT_H_ */