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

packet.c (1704B)


      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:        packet.c
      8  * Purpose:
      9  * Requires:    
     10  */
     11 
     12 #include "cmicsim.h"
     13 #include <sal/core/alloc.h>
     14 
     15 #if !defined(min)
     16 #define min(a,b)  ((a) < (b) ? (a) : (b))
     17 #endif
     18 
     19 
     20 int
     21 pcid_add_pkt(pcid_info_t *pcid_info, uint8 *pkt_data, int pkt_len, uint32 *dcbd)
     22 {
     23     packet_t *newpkt, *pp;
     24     int      i; 
     25     int      word_count=8; /* FB/ER 3 + 5 words of HG + PBE */
     26     
     27     if (pcid_info->pkt_count < CPU_MAX_PACKET_QUEUE) {
     28         newpkt = sal_alloc(sizeof(packet_t), "pcid_add_pkt");
     29         if (newpkt == NULL) {
     30             return 1;
     31         }
     32         newpkt->length = min(pkt_len, PKT_SIZE_MAX);
     33         newpkt->consum = 0;
     34         newpkt->next = 0;
     35 
     36 #ifdef BCM_TRX_SUPPORT
     37         if (SOC_IS_TRX(pcid_info->unit)) {
     38             word_count = 13; /* 4 + 7 words of HG + PBE */
     39         }
     40 #endif /* BCM_TRX_SUPPORT */
     41 
     42         for (i = 0; i < word_count; i++) {
     43             newpkt->dcbd[i] = dcbd[i];
     44         }
     45         memset(newpkt->data, 0, PKT_SIZE_MAX);
     46         memcpy(newpkt->data, pkt_data, min(pkt_len, PKT_SIZE_MAX));
     47 
     48         sal_mutex_take(pcid_info->pkt_mutex, sal_mutex_FOREVER);
     49         ++(pcid_info->pkt_count);
     50         /* Queue current packet on end of list */
     51         if (!pcid_info->pkt_list) {
     52             pcid_info->pkt_list = newpkt;
     53         } else {
     54             for (pp = pcid_info->pkt_list; pp->next; pp = pp->next)
     55                 ;
     56             pp->next = newpkt;
     57         }
     58         sal_mutex_give(pcid_info->pkt_mutex);
     59 
     60         return 0;
     61     }
     62 
     63     return 1;
     64 }
     65