1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: System Services -- Message manipulation functions
25 Desc: Source Code for message related functions.
29 *********************************************************************21*/
33 /* header include files (.h) */
35 #include "envopt.h" /* environment options */
36 #include "envdep.h" /* environment dependent */
37 #include "envind.h" /* environment independent */
39 #include "gen.h" /* general layer */
40 #include "ssi.h" /* system services */
42 #include "ss_err.h" /* errors */
43 #include "ss_dep.h" /* implementation-specific */
44 #include "ss_queue.h" /* queues */
45 #include "ss_strm.h" /* STREAMS */
46 #include "ss_msg.h" /* messaging */
47 #include "ss_mem.h" /* memory management interface */
48 #include "ss_gen.h" /* general */
52 #ifdef RGL_SPECIFIC_CHANGES
59 /* header/extern include files (.x) */
61 #include "gen.x" /* general layer */
62 #include "ssi.x" /* system services */
64 #include "ss_dep.x" /* implementation-specific */
65 #include "ss_queue.x" /* queues */
66 #include "ss_task.x" /* tasking */
67 #include "ss_timer.x" /* timers */
68 #include "ss_strm.x" /* STREAMS */
69 #include "ss_msg.x" /* messaging */
70 #include "ss_mem.x" /* memory management interface */
71 #include "ss_drvr.x" /* driver tasks */
72 #ifdef SS_LOCKLESS_MEMORY
75 #include "cm_mem_wl.x" /* common memory manager */
77 #include "cm_mem.x" /* common memory manager */
78 #endif /* SS_LOCKLESS_MEMORY */
79 #include "ss_gen.x" /* general */
81 /*ss004.301: Cavium changes */
83 /* cvmx includes files */
84 #include "cvmx-config.h"
89 #include "cvmx-helper-fpa.h"
90 #include "cvmx-malloc.h"
91 #endif /* SS_SEUM_CAVIUM */
93 #ifdef XEON_SPECIFIC_CHANGES
94 uint32_t startMemLeak=0;
95 pthread_mutex_t memLock;
98 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
103 #include "mt_plat_t33.h"
104 #include "mt_plat_t33.x"
106 /* forward declarations */
107 S16 ssGetDBufOfSize ARGS((Region region, Size size, Buffer **dBuf));
108 S16 SIncMsgRef(Buffer *srcBuf,Region dstRegion, Pool dstPool,Buffer **dstBuf);
109 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
110 uint32_t GetNextFreeIdx ARGS((StaticMemAllocInfo * memAllocInfo));
111 void LogForStaticMemLeak ARGS((StaticMemAllocInfo* memAllocInfo, char*
112 file, uint32_t line, uint32_t size, void* ptr, uint32_t idx));
113 void FreeIdx ARGS((uint8_t* ptr, uint32_t idx, StaticMemAllocInfo*
114 memAllocInfo,uint32_t size, char* file, uint32_t line));
117 #ifdef SS_USE_ZBC_MEMORY
118 #ifdef T2K_MEM_LEAK_DBG
119 static S16 SPutZbcDBufNew ARGS((Region region, Buffer *buf,char*,uint32_t));
122 static S16 SPutZbcDBuf ARGS((Region region, Buffer *buf));
123 S16 SAttachPtrToBuf ARGS(( Region region, Pool pool, Data *ptr,
124 MsgLen totalLen, Buffer** mBuf));
128 /* ss012.13: Addition */
129 #ifdef SS_M_PROTO_REGION
130 #ifdef T2K_MEM_LEAK_DBG
131 #define DupMsg(region,buffer) DupMsgNew(region,buffer,file,line)
132 static Buffer *DupMsgNew ARGS((Region region, Buffer *buffer,char*,uint32_t));
135 #ifdef T2K_MEM_LEAK_DBG
136 S16 SAttachPtrToMBuf1 ARGS(( Region region, Pool pool, Data *ptr, MsgLen totalLen,
137 MsgLen ptrLen, Buffer** mBuf, char* file, uint32_t line));
139 S16 SAttachPtrToMBuf ARGS(( Region region, Pool pool, Data *ptr, MsgLen totalLen,
140 MsgLen ptrLen, Buffer** mBuf));
142 #ifdef T2K_MEM_LEAK_DBG
143 S16 SAttachWlsPtrToMBuf1 ARGS(( Region region, Pool pool, Data *ptr,
144 Data *readPtr, MsgLen totalLen,
145 MsgLen ptrLen, Buffer** mBuf, char* file, uint32_t line));
147 S16 SAttachWlsPtrToMBuf ARGS(( Region region, Pool pool, Data *ptr,
148 Data *readPtr, MsgLen totalLen,
149 MsgLen ptrLen, Buffer** mBuf));
152 S16 SDetachDpdkPtrFrmMBuf ARGS((Buffer *mBuf, Data **ptr));
153 S16 SDetachDpdkPtrFrmDBuf ARGS((Buffer *mBuf, Data **ptr));
154 S16 SPutSBufDpdk ARGS(( Data *ptr));
155 #endif /* TENB_DPDK_BUF */
158 #endif /* INTEL_WLS */
160 static Buffer *DupMsg ARGS((Region region, Buffer *buffer));
162 #endif /* SS_M_PROTO_REGION */
165 #define MBSIZE (sizeof(SsMblk))
166 #define MDBSIZE (sizeof(SsDblk) + sizeof(SsMblk))
167 #define MSGSIZE (MDBSIZE + sizeof(SsMsgInfo))
169 /*ss014.301 SSI-4GMX specific changes*/
170 #if (defined(SS_4GMX_LCORE) && defined (RB_HEAD_ROOM))
171 #define INITMBLK(mp, dp, dat) {\
175 mp->b_rptr = (dat + RB_MSG_HEAD_ROOM);\
176 mp->b_wptr = (dat + RB_MSG_HEAD_ROOM);\
180 #define INITMBLK(mp, dp, dat) {\
191 #ifdef SS_DBLK_FREE_RTN
192 #define INITDBLK(dp, dat, size, frtn) {\
193 dp->db_frtnp = frtn;\
195 dp->db_lim = (dat == NULLP ? dat : (dat + size));\
197 dp->shared = FALSE; \
198 dp->db_type = SS_M_DATA;\
201 #define INITDBLK(dp, dat, size, frtn) {\
203 dp->db_lim = (dat == NULLP ? dat : (dat + size));\
205 dp->shared = FALSE; \
206 dp->db_type = SS_M_DATA;\
208 #endif /* SS_DBLK_FREE_RTN */
210 #define INITB(mp, dp, dat, size, frtn) {\
211 INITMBLK(mp, dp, dat)\
212 INITDBLK(dp, dat, size, frtn)\
216 pthread_t tmpRegTidMap[20];
217 #define CM_MEM_GET_REGION(_region) \
222 for(_regCnt = 0; _regCnt < 12; _regCnt++) \
224 if(tmpRegTidMap[_regCnt] == pthread_self()) \
232 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF) || defined(L2_OPTMZ))
237 * Fun: ssGetDBufOfSize
239 * Desc: This function gets a message buffer from specified region and
243 * RFAILED - failed, general (optional)
244 * ROUTRES - failed, out of resources (optional)
246 * Notes: message is created. message is returned via message buffer
247 * pointer. Buffer type is SS_M_DATA.
253 #ifdef T2K_MEM_LEAK_DBG
254 S16 ssGetDBufOfSizeNew
275 #if (ERRCLASS & ERRCLS_INT_PAR)
276 /* check buffer pointer */
279 SSLOGERROR(ERRCLS_INT_PAR, ESS047, ERRZERO, "ssGetDBufOfSize : Null\
283 if (region >= SS_MAX_REGS)
285 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "ssGetDBufOfSize : Invalid\
292 SSLOGERROR(ERRCLS_INT_PAR, ESS049, ERRZERO, "ssGetDBufOfSize : Invalid\
298 /* ss006.301 : optmized this function */
299 mdsize = MDBSIZE + size;
300 #ifdef SS_HISTOGRAM_SUPPORT
301 if (SAlloc(region, &mdsize, 0, (Data **) dBuf, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
303 if (SAlloc(region, &mdsize, 0, (Data **) dBuf) != ROK)
304 #endif /* SS_HISTOGRAM_SUPPORT */
308 data = (Data *) (*dBuf) + MDBSIZE;
309 size = mdsize - MDBSIZE;
311 dptr = (SsDblk*) (((Data *) (*dBuf)) + MBSIZE);
313 INITB((*dBuf), dptr, data, size, NULLP)
314 #ifndef SS_DBUF_REFLOCK_DISABLE
315 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
317 SSLOGERROR(ERRCLS_DEBUG, ESS056, ERRZERO,"Falied to initalize lock");
322 } /* ssGetDBufOfSize */
329 * Desc: This function gets a message
332 * RFAILED - failed, general (optional)
333 * ROUTRES - failed, out of resources (optional)
335 * Notes: message is created. message is set to type SS_M_PROTO.
336 * message is returned via message buffer pointer.
342 /* ss001.301: additions */
343 #ifdef SS_HISTOGRAM_SUPPORT
346 Region region, /* region id */
347 Pool pool, /* pool id */
348 Buffer **mBuf, /* pointer to message buffer */
352 #else /* SS_HISTOGRAM_SUPPORT */
353 #ifdef T2K_MEM_LEAK_DBG
356 Region region, /* region id */
357 Pool pool, /* pool id */
358 Buffer **mBuf, /* pointer to message buffer */
365 Region region, /* region id */
366 Pool pool, /* pool id */
367 Buffer **mBuf /* pointer to message buffer */
370 #endif /* SS_HISTOGRAM_SUPPORT */
376 /* ss001.301: additions */
377 #ifdef SS_HISTOGRAM_SUPPORT
379 #endif /* SS_HISTOGRAM_SUPPORT */
381 /* ss021.103 - Addition of return value */
383 #if (ERRCLASS & ERRCLS_INT_PAR)
389 #ifdef XEON_SPECIFIC_CHANGES
394 #if (ERRCLASS & ERRCLS_INT_PAR)
395 /* check buffer pointer */
398 SSLOGERROR(ERRCLS_INT_PAR, ESS050, ERRZERO, "SGetMsg : Null Buffer");
401 if (region >= SS_MAX_REGS)
403 SSLOGERROR(ERRCLS_INT_PAR, ESS051, ERRZERO, "SGetMsg : Invalid region\
408 if (pool >= SS_MAX_POOLS_PER_REG)
410 SSLOGERROR(ERRCLS_INT_PAR, ESS052, ERRZERO, "SGetMsg : Invalid pool id");
414 /* ss037.103 Removed the semaphore operation for performance enhancement */
417 /* ss021.103 - Addition to check if region is registered */
418 /* acquire one semaphore, to protect against deregistration */
419 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
423 #if (ERRCLASS & ERRCLS_DEBUG)
424 SSLOGERROR(ERRCLS_DEBUG, ESS053, (ErrVal) ret,
425 "Could not lock region table");
432 #if (ERRCLASS & ERRCLS_INT_PAR)
433 /* verify that this region is present */
434 if (osCp.regionTbl[region].used == FALSE)
436 /* ss037.103 Removed the semaphore operation for performance enhancement */
439 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
441 #if (ERRCLASS & ERRCLS_DEBUG)
442 SSLOGERROR(ERRCLS_DEBUG, ESS054, ERRZERO,
443 "Could not release semaphore");
448 SSLOGERROR(ERRCLS_INT_PAR, ESS055, region, "Region not registered");
451 /* ss037.103 Removed the semaphore operation for performance enhancement */
454 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
456 #if (ERRCLASS & ERRCLS_DEBUG)
457 SSLOGERROR(ERRCLS_DEBUG, ESS056, ERRZERO,
458 "Could not release semaphore");
465 /* ss001.301: additions */
466 #ifdef SS_HISTOGRAM_SUPPORT
467 SGetEntInd(&entId, fileName);
468 #endif /* SS_HISTOGRAM_SUPPORT */
470 /* ss012.13: Addition */
471 #ifdef SS_M_PROTO_REGION
472 /* ss001.301: additions */
473 #ifdef SS_HISTOGRAM_SUPPORT
474 if (SAlloc(region, &size, 0, (Data**) mBuf, line, fileName, entId) != ROK)
476 if (SAlloc(region, &size, 0, (Data**) mBuf) != ROK)
477 #endif /* SS_HISTOGRAM_SUPPORT */
479 SSLOGERROR(ERRCLS_DEBUG, ESS058, ERRZERO, "SGetMsg:Failed in SAlloc");
482 #else /* SS_M_PROTO_REGION */
483 /* ss001.301: additions */
484 #ifdef SS_HISTOGRAM_SUPPORT
485 if (SAlloc(SS_DFLT_REGION, &size, 0, (Data**) mBuf, line, fileName, entId) != ROK)
487 if (SAlloc(region, &size, 0, (Data**) mBuf) != ROK)
488 #endif /* SS_HISTOGRAM_SUPPORT */
490 SSLOGERROR(ERRCLS_DEBUG, ESS059, ERRZERO, "SGetMsg:Failed in SAlloc");
493 #endif /* SS_M_PROTO_REGION */
495 dptr = (SsDblk*) (((Data *) (*mBuf)) + MBSIZE);
496 data = (Data*) (((Data *) (*mBuf)) + MDBSIZE);
498 /* INITB initialises and sets up the message blk */
499 INITB((*mBuf), dptr, data, sizeof(SsMsgInfo), NULLP)
501 (*mBuf)->b_datap->db_type = SS_M_PROTO;
502 (*mBuf)->b_wptr = (*mBuf)->b_rptr + sizeof(SsMsgInfo);
504 /* initialise message info of mBuf */
505 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
507 minfo->region = region;
510 minfo->endptr = NULLP;
511 minfo->eventInfo.event = SS_EVNT_DATA;
512 /* ss021.103 - Addition to initialize next and route */
516 if(clusterMode == RADIO_CLUSTER_MODE)
525 #ifdef RGL_SPECIFIC_CHANGES
526 S16 SSetMBufPool(Buffer *mBuf, Pool pool)
531 minfo = (SsMsgInfo*) mBuf->b_rptr;
538 /* #ifdef SS_LOCKLESS_MEMORY */
544 * Desc: This function deallocates a message back.
547 * RFAILED - failed, general (optional)
549 * Notes: all data attached to message is returned to memory.
550 * message is returned to memory. return is ok.
555 /* ss001.301: additions */
556 #ifdef SS_HISTOGRAM_SUPPORT
563 #else /* SS_HISTOGRAM_SUPPORT */
564 #ifdef T2K_MEM_LEAK_DBG
577 #endif /* SS_HISTOGRAM_SUPPORT */
581 #ifdef SS_MEM_WL_DEBUG
585 /* ss001.301: additions */
586 #ifdef SS_HISTOGRAM_SUPPORT
588 #endif /* SS_HISTOGRAM_SUPPORT */
591 //#ifdef RADIO_CLUSTER
592 if(clusterMode == RADIO_CLUSTER_MODE)
598 if (mBuf->refCnt > 0)
604 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
606 pthread_t gMacTId,gRlcTId;
608 if(clusterMode == RADIO_CLUSTER_MODE)
611 #ifdef MAC_FREE_RING_BUF
612 if(pthread_self() == gMacTId)
613 //if(pthread_equal(pthread_self(),gMacTId))
615 if(ROK == mtAddBufToRing(SS_RNG_BUF_MAC_FREE_RING,(Void *)mBuf,0))
621 #ifdef RLC_FREE_RING_BUF
622 else if(pthread_self() == gRlcTId)
624 if(ROK == mtAddBufToRing(SS_RNG_BUF_RLC_FREE_RING,(Void *)mBuf,0))
634 #if (ERRCLASS & ERRCLS_INT_PAR)
637 SSLOGERROR(ERRCLS_INT_PAR, ESS060, ERRZERO, "SPutMsg: Null Buffer");
640 if (mBuf->b_datap->db_type != SS_M_PROTO)
642 SSLOGERROR(ERRCLS_INT_PAR, ESS061, ERRZERO, "SPutMsg: Incorrect buffer\
648 #ifdef SS_MEM_WL_DEBUG
649 CM_MEM_GET_REGION(tmpThrReg)
650 if(tmpThrReg == 0xFF)
653 printf("\n Not able to get region \n");
659 /* get the message info */
660 minfo = (SsMsgInfo *) mBuf->b_rptr;
662 while ((tmp = mBuf->b_cont))
664 /* set b_cont of mBuf to point to the b_cont of tmp */
665 mBuf->b_cont = tmp->b_cont;
666 #ifdef SS_MEM_WL_DEBUG
667 (Void) SPutDBuf(tmpThrReg, minfo->pool, tmp);
669 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
673 /* ss001.301: additions */
674 #ifdef SS_HISTOGRAM_SUPPORT
675 SGetEntInd(&entId, fileName);
676 #endif /* SS_HISTOGRAM_SUPPORT */
678 /* ss012.13: Addition */
679 #ifdef SS_M_PROTO_REGION
680 /* ss021.103 - Addition to check return value of SFree */
681 #ifdef SS_HISTOGRAM_SUPPORT
682 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE, line, fileName, entId) == RFAILED)
684 #ifdef SS_MEM_WL_DEBUG
685 if (SFree(tmpThrReg, (Data *) mBuf, MSGSIZE) == RFAILED)
687 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE) == RFAILED)
689 #endif /* SS_HISTOGRAM_SUPPORT */
691 #else /* SS_M_PROTO_REGION */
692 /* ss021.103 - Addition to check return value of SFree */
693 #ifdef SS_HISTOGRAM_SUPPORT
694 if (SFree(SS_DFLT_REGION, (Data *) mBuf, MSGSIZE, line, fileName, entId) == RFAILED)
696 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE) == RFAILED)
697 #endif /* SS_HISTOGRAM_SUPPORT */
699 #endif /* SS_M_PROTO_REGION */
704 #ifdef SS_LOCKLESS_MEMORY
707 * Fun: SPutStaticBuffer
709 * Desc: Returns a buffer to the specified static pool in the
710 * specified memory region.
713 * RFAILED - failed, general (optional)
720 /* ss001.301: additions */
721 #ifdef T2K_MEM_LEAK_DBG
722 S16 SPutStaticBufferNew
724 Region region, /* region ID */
725 Pool pool, /* pool ID */
726 Data *ptr, /* pointer to buffer */
727 Size size, /* size */
728 uint8_t memType, /* memory type used if shareable or not */
735 Region region, /* region ID */
736 Pool pool, /* pool ID */
737 Data *ptr, /* pointer to buffer */
738 Size size, /* size */
739 uint8_t memType /* memory type used if shareable or not */
745 #if (ERRCLASS & ERRCLS_INT_PAR)
746 /* validate region ID */
747 if (region >= SS_MAX_REGS)
749 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
753 /* validate pool ID */
754 if (pool >= SS_MAX_POOLS_PER_REG)
756 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
759 /* validate data pointer */
762 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
769 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
773 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
775 pthread_t gMacTId,gRlcTId;
777 if(clusterMode == RADIO_CLUSTER_MODE)
779 #ifdef MAC_FREE_RING_BUF
780 if(pthread_self() == gMacTId)
781 //if(pthread_equal(pthread_self(),gMacTId))
783 if(ROK == mtAddBufToRing(SS_RNG_BUF_MAC_FREE_RING,(Void *)ptr,1))
789 #ifdef RLC_FREE_RING_BUF
790 else if(pthread_self() == gRlcTId)
792 if(ROK == mtAddBufToRing(SS_RNG_BUF_RLC_FREE_RING,(Void *)ptr,1))
801 region = SS_GET_THREAD_MEM_REGION();
804 #if (ERRCLASS & ERRCLS_INT_PAR)
805 /* verify that this region is present */
806 if (((memType == SS_NON_SHARABLE_MEMORY) &&
807 (osCp.regionTbl[region].used == FALSE)) ||
808 ((memType == SS_SHARABLE_MEMORY) &&
809 (osCp.dynRegionTbl[region].used == FALSE)))
811 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
816 /* call the memory manager, to allocate this memory */
817 #ifndef SS_DBUF_REFLOCK_DISABLE
818 if(memType == SS_NON_SHARABLE_MEMORY)
820 #ifndef T2K_MEM_LEAK_DBG
821 ret = (osCp.regionTbl[region].free)
822 (osCp.regionTbl[region].regCb, ptr, size);
824 ret = (osCp.regionTbl[region].free)
825 (osCp.regionTbl[region].regCb, ptr, size, file, line);
829 else if(memType == SS_SHARABLE_MEMORY)
833 #ifndef T2K_MEM_LEAK_DBG
834 ret = (osCp.dynRegionTbl[region].free)
835 (osCp.dynRegionTbl[region].regCb, ptr, size);
837 ret = (osCp.dynRegionTbl[region].free)
838 (osCp.dynRegionTbl[region].regCb, ptr, size,file,line);
840 #ifndef SS_DBUF_REFLOCK_DISABLE
849 * Fun: SGetStaticBuffer
851 * Desc: Allocates a buffer from the specified static memory pool
852 * in the specified region. Depending on the type wheather
853 * the buffer is sharable or non-sharable indicated by the
854 * memType prameter allocation region is choosen
858 * RFAILED - failed, general (optional)
865 #ifdef T2K_MEM_LEAK_DBG
866 S16 SGetStaticBufferNew
868 Region region, /* region ID */
869 Pool pool, /* pool ID */
870 Data **ptr, /* pointer to buffer */
871 Size size, /* size requested */
872 uint8_t memType, /* memory type used if shareable or not */
879 Region region, /* region ID */
880 Pool pool, /* pool ID */
881 Data **ptr, /* pointer to buffer */
882 Size size, /* size requested */
883 uint8_t memType /* memory type used if shareable or not */
890 #if (ERRCLASS & ERRCLS_INT_PAR)
891 /* validate region ID */
892 if (region >= SS_MAX_REGS)
894 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
898 /* validate pool ID */
899 if (pool >= SS_MAX_POOLS_PER_REG)
901 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
904 /* validate data pointer */
907 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
914 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
919 #if (ERRCLASS & ERRCLS_INT_PAR)
920 /* verify that this region is present */
921 if (((memType == SS_NON_SHARABLE_MEMORY) &&
922 (osCp.regionTbl[region].used == FALSE)) ||
923 ((memType == SS_SHARABLE_MEMORY) &&
924 (osCp.dynRegionTbl[region].used == FALSE)))
926 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
933 region = SS_GET_THREAD_MEM_REGION();
935 if (region == SS_STATIC_REGION)
939 /* call the memory manager, to allocate this memory */
940 #ifndef SS_DBUF_REFLOCK_DISABLE
941 if(memType == SS_NON_SHARABLE_MEMORY)
943 #ifndef T2K_MEM_LEAK_DBG
944 ret = (osCp.regionTbl[region].alloc)
945 (osCp.regionTbl[region].regCb, &size, flags, ptr);
947 ret = (osCp.regionTbl[region].alloc)
948 (osCp.regionTbl[region].regCb, &size, flags, ptr, file,line);
951 else if(memType == SS_SHARABLE_MEMORY)
954 #ifndef T2K_MEM_LEAK_DBG
955 ret = (osCp.dynRegionTbl[region].alloc)
956 (osCp.dynRegionTbl[region].regCb, &size, flags, ptr);
958 ret = (osCp.dynRegionTbl[region].alloc)
959 (osCp.dynRegionTbl[region].regCb, &size, flags, ptr,file,line);
961 #ifndef SS_DBUF_REFLOCK_DISABLE
967 #endif /* SS_LOCKLESS_MEMORY */
970 #ifndef SS_LOCKLESS_MEMORY
973 Region region, /* region ID */
974 Pool pool, /* pool ID */
975 Data **ptr, /* pointer to buffer */
976 Size size, /* size requested */
977 uint8_t memType /* memory type used if shareable or not */
982 ret = SGetSBuf(region, pool, ptr, size);
990 Region region, /* region ID */
991 Pool pool, /* pool ID */
992 Data *ptr, /* pointer to buffer */
993 Size size, /* size */
994 uint8_t memType /* memory type used if shareable or not */
1000 ret = SPutSBuf(region, pool, ptr, size);
1006 #ifdef T2K_MEM_LEAK_DBG
1009 Region region, /* region ID */
1010 Pool pool, /* pool ID */
1011 Data **ptr, /* pointer to buffer */
1012 Size size, /* size requested */
1019 Region region, /* region ID */
1020 Pool pool, /* pool ID */
1021 Data **ptr, /* pointer to buffer */
1022 Size size /* size requested */
1027 #ifndef SS_LOCKLESS_MEMORY
1031 #ifdef SS_LOCKLESS_MEMORY
1032 region = SS_GET_THREAD_MEM_REGION();
1033 ret = SAlloc(region, &size, 0, ptr);
1036 #ifdef T2K_MEM_LEAK_DBG
1037 ret = (osCp.regionTbl[region].alloc)
1038 (osCp.regionTbl[region].regCb, &size, flags, ptr,file,line);
1040 ret = (osCp.regionTbl[region].alloc)
1041 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1048 #ifdef T2K_MEM_LEAK_DBG
1051 Region region, /* region ID */
1052 Pool pool, /* pool ID */
1053 Data *ptr, /* pointer to buffer */
1054 Size size, /* size */
1061 Region region, /* region ID */
1062 Pool pool, /* pool ID */
1063 Data *ptr, /* pointer to buffer */
1064 Size size /* size */
1070 #ifdef SS_LOCKLESS_MEMORY
1071 region = SS_GET_THREAD_MEM_REGION();
1072 ret = SFree(region, ptr, size);
1075 #ifdef T2K_MEM_LEAK_DBG
1076 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,file,line);
1078 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1085 #endif /* INTEL_WLS */
1092 * Desc: Allocates a buffer from the specified static memory pool
1093 * in the specified region.
1096 * RFAILED - failed, general (optional)
1098 * Notes: The new memory management scheme eliminates the concept
1099 * of pools. This call maps directly to a call to the memory
1105 /* ss001.301: additions */
1106 #ifdef SS_HISTOGRAM_SUPPORT
1109 Region region, /* region ID */
1110 Pool pool, /* pool ID */
1111 Data **ptr, /* pointer to buffer */
1112 Size size, /* size requested */
1116 #else /* SS_HISTOGRAM_SUPPORT */
1117 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1120 Region region, /* region ID */
1121 Pool pool, /* pool ID */
1122 Data **ptr, /* pointer to buffer */
1123 Size size, /* size requested */
1130 Region region, /* region ID */
1131 Pool pool, /* pool ID */
1132 Data **ptr, /* pointer to buffer */
1133 Size size /* size requested */
1136 #endif /* SS_HISTOGRAM_SUPPORT */
1140 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1144 #ifdef SS_HISTOGRAM_SUPPORT
1146 Bool hstReg = FALSE;
1147 #endif /* SS_HISTOGRAM_SUPPORT */
1150 region = SS_GET_THREAD_MEM_REGION();
1153 #endif /* INTEL_WLS */
1155 #if (ERRCLASS & ERRCLS_INT_PAR)
1156 /* validate region ID */
1157 if (region >= SS_MAX_REGS)
1159 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
1163 /* validate pool ID */
1164 if (pool >= SS_MAX_POOLS_PER_REG)
1166 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
1169 /* ss008.13: addition */
1170 /* validate data pointer */
1173 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
1180 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
1184 /* ss037.103 Removed the semaphore operation for performance enhancement */
1186 #ifndef RGL_SPECIFIC_CHANGES
1187 region = SS_GET_THREAD_MEM_REGION();
1190 /* acquire one semaphore, to protect against deregistration */
1191 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1195 #if (ERRCLASS & ERRCLS_DEBUG)
1196 SSLOGERROR(ERRCLS_DEBUG, ESS216, (ErrVal) ret,
1197 "Could not lock region table");
1205 #if (ERRCLASS & ERRCLS_INT_PAR)
1206 /* verify that this region is present */
1207 if (osCp.regionTbl[region].used == FALSE)
1211 /* ss006.13: addition */
1212 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1214 #if (ERRCLASS & ERRCLS_DEBUG)
1215 SSLOGERROR(ERRCLS_DEBUG, ESS217, ERRZERO,
1216 "Could not release semaphore");
1221 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
1230 /* ss024.103 - Addition for memory calculator tool */
1232 if (region == SS_STATIC_REGION)
1236 /* ss001.301: additions */
1237 #ifdef SS_HISTOGRAM_SUPPORT
1239 SGetEntInd(&entId, fileName);
1240 /* Get the Information from the oscp that the tapa task with the entity
1241 id (entid) is registed for histogram or not */
1242 SGetHstGrmInfo(&entId, &hstReg);
1243 /* call the memory manager, to allocate this memory */
1244 #ifdef SSI_DEBUG_LEVEL1
1245 ret = (osCp.regionTbl[region].alloc)
1246 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1247 SS_STATIC_MEM_FLAG, line, fileName, entId, hstReg);
1249 ret = (osCp.regionTbl[region].alloc)
1250 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1251 line, fileName, entId, hstReg);
1252 #endif /* SSI_DEBUG_LEVEL1 */
1256 /* call the memory manager, to allocate this memory */
1257 /* ss036.103 - addition for passing additional parameter memType as static */
1258 #ifdef SSI_DEBUG_LEVEL1
1259 ret = (osCp.regionTbl[region].alloc)
1260 (osCp.regionTbl[region].regCb, &size, flags, ptr, SS_STATIC_MEM_FLAG);
1262 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1263 /* Static mem leak detection changes */
1265 #ifdef T2K_MEM_LEAK_DBG
1266 ret = (osCp.regionTbl[region].alloc)
1267 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr, file, line);
1269 ret = (osCp.regionTbl[region].alloc)
1270 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr);
1272 /*size = tmpSize - 4;*/
1274 /*printf("\nptr = %p *ptr = %p\n",ptr,*ptr);*/
1275 #ifdef XEON_SPECIFIC_CHANGES
1276 pthread_mutex_lock(&(memLock));
1278 uint32_t idx = GetNextFreeIdx(&SMemLeakInfo[region]);
1279 uint8_t* allocatedPtr = *ptr;
1280 void* actualPtr = allocatedPtr + 4;
1282 /* store the index in the memory allocated itself */
1283 /**((uint32_t*)*((uint32_t*)allocatedPtr)) = idx;*/
1284 *((uint32_t*)allocatedPtr) = idx;
1285 /*printf("\nregion = %d idx = %d ptr = %p *ptr = %p actual = %p allocated = %p content = %d\n",region, idx, ptr, *ptr, actualPtr, allocatedPtr, *((uint32_t*)allocatedPtr));*/
1287 LogForStaticMemLeak(&SMemLeakInfo[region],
1293 #ifdef XEON_SPECIFIC_CHANGES
1294 pthread_mutex_unlock(&(memLock));
1298 #ifndef T2K_MEM_LEAK_DBG
1299 ret = (osCp.regionTbl[region].alloc)
1300 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1302 ret = (osCp.regionTbl[region].alloc)
1303 (osCp.regionTbl[region].regCb, &size, flags, ptr, file, line);
1307 #endif /* SSI_DEBUG_LEVEL1 */
1309 #endif /* SS_HISTOGRAM_SUPPORT */
1311 /* release the semaphore we took */
1314 /* ss006.13: addition */
1315 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1317 #if (ERRCLASS & ERRCLS_DEBUG)
1318 SSLOGERROR(ERRCLS_DEBUG, ESS219, ERRZERO,
1319 "Could not release semaphore");
1324 /* ss036.103 - Addition to handle the memory trampling return value
1325 * This in turn might invoke SRegMemErrHdlr
1327 #ifdef SSI_DEBUG_LEVEL1
1328 if (ret == RTRAMPLINGNOK)
1330 SRegMemErrHdlr( region, *ptr, ret);
1332 #endif /* SSI_DEBUG_LEVEL1 */
1342 * Desc: Returns a buffer to the specified static pool in the
1343 * specified memory region.
1346 * RFAILED - failed, general (optional)
1353 /* ss001.301: additions */
1354 #ifdef SS_HISTOGRAM_SUPPORT
1357 Region region, /* region ID */
1358 Pool pool, /* pool ID */
1359 Data *ptr, /* pointer to buffer */
1360 Size size, /* size */
1364 #else /* SS_HISTOGRAM_SUPPORT */
1365 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1368 Region region, /* region ID */
1369 Pool pool, /* pool ID */
1370 Data *ptr, /* pointer to buffer */
1371 Size size, /* size */
1378 Region region, /* region ID */
1379 Pool pool, /* pool ID */
1380 Data *ptr, /* pointer to buffer */
1381 Size size /* size */
1384 #endif /* SS_HISTOGRAM_SUPPORT */
1388 #ifdef SS_HISTOGRAM_SUPPORT
1390 Bool hstReg = FALSE;
1391 #endif /* SS_HISTOGRAM_SUPPORT */
1393 region = SS_GET_THREAD_MEM_REGION();
1394 #if (!defined(SS_LOCKLESS_MEMORY) && defined(INTEL_WLS))
1396 #endif /* INTEL_WLS */
1398 #if (ERRCLASS & ERRCLS_INT_PAR)
1399 /* validate region ID */
1400 if (region >= SS_MAX_REGS)
1402 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
1406 /* validate pool ID */
1407 if (pool >= SS_MAX_POOLS_PER_REG)
1409 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
1412 /* ss008.13: addition */
1413 /* validate data pointer */
1416 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
1423 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
1427 /* ss037.103 Removed the semaphore operation for performance enhancement */
1428 #ifndef RGL_SPECIFIC_CHANGES
1429 region = SS_GET_THREAD_MEM_REGION();
1432 /* acquire one semaphore, to protect against deregistration */
1433 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1437 #if (ERRCLASS & ERRCLS_DEBUG)
1438 SSLOGERROR(ERRCLS_DEBUG, ESS225, (ErrVal) ret,
1439 "Could not lock region table");
1446 #if (ERRCLASS & ERRCLS_INT_PAR)
1447 /* verify that this region is around */
1448 if (osCp.regionTbl[region].used == FALSE)
1452 /* ss006.13: addition */
1453 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1455 #if (ERRCLASS & ERRCLS_DEBUG)
1456 SSLOGERROR(ERRCLS_DEBUG, ESS226, ERRZERO,
1457 "Could not release semaphore");
1462 SSLOGERROR(ERRCLS_INT_PAR, ESS227, region, "Region not registered");
1467 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1468 /* Static mem leak detection changes */
1470 #ifdef XEON_SPECIFIC_CHANGES
1471 pthread_mutex_lock(&(memLock));
1473 uint32_t idx = *((uint32_t*)((uint8_t *)ptr - 4));
1474 FreeIdx(ptr,idx,&SMemLeakInfo[region],size,file,line);
1475 #ifdef XEON_SPECIFIC_CHANGES
1476 pthread_mutex_unlock(&(memLock));
1479 /* Static mem leak detection changes */
1482 /* ss001.301: additions */
1483 #ifdef SS_HISTOGRAM_SUPPORT
1484 SGetEntInd(&entId, fileName);
1485 /* Get the Information from the oscp that the tapa task with the entity
1486 id (entid) is registed for histogram or not */
1487 SGetHstGrmInfo(&entId, &hstReg);
1489 /* call the memory manager to free this memory */
1490 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,
1491 line, fileName, entId, hstReg);
1493 /* call the memory manager to free this memory */
1494 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1495 #ifdef T2K_MEM_LEAK_DBG
1496 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4, file, line);
1498 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4);
1501 #ifndef T2K_MEM_LEAK_DBG
1502 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1504 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size, file, line);
1507 #endif /* SS_HISTOGRAM_SUPPORT */
1508 /* ss037.103 Removed the semaphore operation for performance enhancement */
1511 /* release the semaphore we took */
1513 /* ss006.13: addition */
1514 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1516 #if (ERRCLASS & ERRCLS_DEBUG)
1517 SSLOGERROR(ERRCLS_DEBUG, ESS228, ERRZERO,
1518 "Could not release semaphore");
1523 /* ss036.103 - addition to handle double free and trampling return values
1524 * This might invoke SRegMemErrHdlr
1526 #ifdef SSI_DEBUG_LEVEL1
1527 /* handle the double free error here by calling the OS specific error handling function */
1528 if ((ret == RDBLFREE) || (ret == RTRAMPLINGNOK))
1530 SRegMemErrHdlr( region, ptr, ret);
1532 #endif /* SSI_DEBUG_LEVEL1 */
1542 * Desc: This function deallocates a message back and then
1543 * reinitializes the message.
1546 * RFAILED - failed, general (optional)
1548 * Notes: all data attached to message is returned to memory.
1549 * message is set to empty. message is not returned to
1550 * memory. return is ok.
1556 S16 SInitMsg(Buffer *mBuf)
1562 #if (ERRCLASS & ERRCLS_INT_PAR)
1563 /* check message buffer */
1566 SSLOGERROR(ERRCLS_INT_PAR, ESS062, ERRZERO, "SInitMsg: Null Buffer");
1569 if (mBuf->b_datap->db_type != SS_M_PROTO)
1571 SSLOGERROR(ERRCLS_INT_PAR, ESS063, ERRZERO, "SInitMsg: Incorrect buffer\
1577 /* get the message info */
1580 CM_MEM_GET_REGION(tmpRegId);
1581 if(tmpRegId == 0xFF)
1586 minfo = (SsMsgInfo*) mBuf->b_rptr;
1588 /* free all SS_M_DATA blks */
1589 while ((tmp = mBuf->b_cont))
1591 mBuf->b_cont = tmp->b_cont;
1594 #ifdef T2K_MEM_LEAK_DBG
1595 char * file = __FILE__;
1596 uint32_t line = __LINE__;
1599 (Void) SPutDBuf(tmpRegId, minfo->pool, tmp);
1601 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
1604 /* initialise the length and endptr variables of mBuf */
1607 minfo->endptr = NULLP;
1608 minfo->next = NULLP;
1613 /* ss016.301 - Added a new API - SAddPreMsgMultInOrder. This preserves the
1614 * byte order while adding the data bytes to the beginning of the message.
1618 * Fun: SAddPreMsgMultInOrder
1620 * Desc: This function copies consecutive bytes of data to the
1621 * beginning of a message and keeps the bytes order preserved.
1623 * Ret: ROK - Appended the bytes to the beginning of the message.
1624 * RFAILED - Failed to append the bytes.
1625 * ROUTRES - Out of resources - Possibly insufficient memory.
1627 * Notes: If the message is empty,data is placed in the message. Message
1628 * length is incremented. Return is ROK.
1630 * If the message is not empty,data is read by source pointer
1631 * and appended at the beginning of the message.
1632 * Message length is incremented. Return is ROK.
1637 S16 SAddPreMsgMultInOrder
1644 SsMsgInfo *minfo; /* Message info */
1646 Buffer *curblk=NULLP;
1649 MsgLen numBytes; /* no. of bytes to be copied */
1655 #if (ERRCLASS & ERRCLS_INT_PAR)
1656 /* check message buffer */
1659 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMultInOrder:\
1666 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMultInOrder:\
1673 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMultInOrder:\
1677 if (mBuf->b_datap->db_type != SS_M_PROTO)
1679 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMultInOrder:\
1680 Incorrect buffer type");
1685 /* get the SsMsgInfo of mBuf */
1686 minfo = (SsMsgInfo*) mBuf->b_rptr;
1687 #ifdef RGL_SPECIFIC_CHANGES
1691 /* store cnt in length */
1696 /* point to the end of the source buffer */
1697 revSrc = src + cnt ;
1699 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
1700 (tmp->b_datap->db_base < tmp->b_rptr))
1702 /* store the offset of the read pointer of tmp */
1703 offset = tmp->b_rptr - tmp->b_datap->db_base;
1705 /* determine the number of bytes to copy */
1706 numBytes = MIN(cnt, offset);
1708 /* traverse back from the end of the source buffer*/
1714 /* move the read pointer towards the left */
1715 tmp->b_rptr -= numBytes ;
1716 SMemCpy((Void *)(tmp->b_rptr ), (Void *) revSrc, (size_t) numBytes);
1724 newblk = prevblk = NULLP;
1727 /* allocate a message blk */
1728 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
1730 while ((curblk = prevblk))
1732 prevblk = prevblk->b_cont;
1733 #ifdef T2K_MEM_LEAK_DBG
1734 char * file = __FILE__;
1735 uint32_t line = __LINE__;
1738 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
1743 tmp->b_rptr = tmp->b_datap->db_base + offset;
1748 /* attach curblk in the newblk chain */
1751 curblk->b_cont = prevblk; /* stack them up */
1759 /* set the read and write pointers to the end of the data buffer */
1760 /* subsequent prepends have all the buffer to insert data into */
1761 curblk->b_wptr = curblk->b_datap->db_lim;
1762 rptr = curblk->b_datap->db_lim;
1765 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
1770 /* move the read pointer towards the left */
1773 /* traverse back the source buffer */
1776 SMemCpy((Void *)(rptr), (Void *) revSrc, (size_t) numBytes);
1778 curblk->b_rptr = rptr;
1781 /* attach the newblk chain into mBuf */
1782 newblk->b_cont = tmp;
1783 mBuf->b_cont = curblk;
1785 /* update endptr of mBuf */
1788 minfo->endptr = newblk;
1790 /* update length of message */
1799 * Desc: This function copies one byte of data to the
1800 * beginning of a message.
1803 * RFAILED - failed, general (optional)
1804 * ROUTRES - failed, out of resources (optional)
1806 * Notes: if message is empty: data is placed in the message. message
1807 * length is incremented. return is ok.
1809 * if message is not empty: data is placed in front of all
1810 * other data in message. message length is incremented.
1828 #if (ERRCLASS & ERRCLS_INT_PAR)
1829 /* check message buffer */
1832 SSLOGERROR(ERRCLS_INT_PAR, ESS064, ERRZERO, "SAddPreMsg: Null Buffer");
1835 if (mBuf->b_datap->db_type != SS_M_PROTO)
1837 SSLOGERROR(ERRCLS_INT_PAR, ESS065, ERRZERO, "SAddPreMsg: Incorrect\
1843 minfo = (SsMsgInfo *) mBuf->b_rptr;
1845 /* ss021.103 - Addition to check if exceeding maximum message length */
1847 if (minfo->len == 0x7FFFFFFF)
1849 if (minfo->len == 0x7FFF)
1856 * allocate a message blk using SGetDBuf(), if there are no data blks in the
1857 * message, mBuf, or if the reference count of the first data blk is greater
1858 * than 1, or if there is no space to append databytes in front of the read
1859 * pointer of the first data blk
1861 if (!(tmp = mBuf->b_cont) || (tmp->b_datap->db_ref > 1) ||
1862 (tmp->b_rptr == tmp->b_datap->db_base))
1864 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
1866 SSLOGERROR(ERRCLS_DEBUG, ESS066, ERRZERO, "SAddPreMsg:Failed in\
1870 /* set the read and write pointers to end of data buffer */
1871 /* subsequent prepends have all the buffer to insert data into */
1872 newb->b_wptr = newb->b_datap->db_lim;
1873 newb->b_rptr = newb->b_datap->db_lim;
1875 /* insert newb before tmp */
1876 newb -> b_cont = tmp;
1877 mBuf->b_cont = newb;
1879 /* if endptr of mBuf is NULLP, set it to newb */
1881 minfo->endptr = newb;
1884 /* insert data, increment length */
1885 *--tmp->b_rptr = data;
1895 * Desc: This function copies one byte of data to the
1899 * RFAILED - failed, general (optional)
1900 * ROUTRES - failed, out of resources (optional)
1902 * Notes: if message is empty: data is placed in the message. message
1903 * length is incremented. return is ok.
1905 * if message is not empty: data is placed in back of all
1906 * other data in message. message length is incremented.
1924 #if (ERRCLASS & ERRCLS_INT_PAR)
1925 /* check message buffer */
1928 SSLOGERROR(ERRCLS_INT_PAR, ESS067, ERRZERO, "SAddPstMsg: Null Buffer");
1931 if (mBuf->b_datap->db_type != SS_M_PROTO)
1933 SSLOGERROR(ERRCLS_INT_PAR, ESS068, ERRZERO, "SAddPstMsg: Incorrect\
1939 /* get the message info */
1940 minfo = (SsMsgInfo *) mBuf->b_rptr;
1942 if (!(tmp = minfo->endptr) || (tmp->b_datap->db_ref > 1) ||
1943 (tmp->b_wptr == tmp->b_datap->db_lim))
1945 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
1947 SSLOGERROR(ERRCLS_DEBUG, ESS069, ERRZERO, "SAddPstMsg: Failed in\
1952 /* append newb to the end of the mBuf chain */
1956 mBuf->b_cont = newb;
1958 /* set the endptr of mBuf to newb */
1959 minfo->endptr = newb;
1963 /* insert data, increment length */
1964 *tmp->b_wptr++ = data;
1972 * Fun: SAddPreMsgMult
1974 * Desc: This function copies consecutive bytes of data to the
1975 * beginning of a message.
1978 * RFAILED - failed, general (optional)
1979 * ROUTRES - failed, out of resources (optional)
1981 * Notes: if message is empty: data is placed in the message. message
1982 * length is incremented. return is ok.
1984 * if message is not empty: data is read by source pointer,
1985 * data is placed in front of all other data in message.
1986 * message length is incremented. return is ok.
1988 * the first byte of data pointed to by the source pointer will
1989 * be placed at the front of the message first, the last byte of
1990 * data pointed to by the source pointer will be placed at the
1991 * front of the message last (i.e. it will become the first
1992 * byte of the message).
1998 #ifdef T2K_MEM_LEAK_DBG
2017 SsMsgInfo *minfo; /* Message info */
2019 Buffer *curblk=NULLP;
2022 MsgLen numBytes; /* no. of bytes to be copied */
2027 #if (ERRCLASS & ERRCLS_INT_PAR)
2028 /* check message buffer */
2031 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMult:Null Buffer");
2037 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMult:Null Buffer");
2043 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMult: Invalid\
2047 if (mBuf->b_datap->db_type != SS_M_PROTO)
2049 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMult: Incorrect\
2055 /* get the SsMsgInfo of mBuf */
2056 minfo = (SsMsgInfo*) mBuf->b_rptr;
2058 /* store cnt in length */
2060 /* ss014.13: Addition */
2063 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
2064 (tmp->b_datap->db_base < tmp->b_rptr))
2066 /* store the offset of the read pointer of tmp */
2067 offset = tmp->b_rptr - tmp->b_datap->db_base;
2069 /* determine the number of bytes to copy */
2070 numBytes = MIN(cnt, offset);
2077 *--tmp->b_rptr = *src++;
2084 newblk = prevblk = NULLP;
2087 /* allocate a message blk */
2088 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2090 while ((curblk = prevblk))
2092 prevblk = prevblk->b_cont;
2093 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2098 tmp->b_rptr = tmp->b_datap->db_base + offset;
2103 /* attach curblk in the newblk chain */
2105 curblk->b_cont = prevblk; /* stack them up */
2110 /* set the read and write pointers to the end of the data buffer */
2111 /* subsequent prepends have all the buffer to insert data into */
2112 curblk->b_wptr = curblk->b_datap->db_lim;
2113 rptr = curblk->b_datap->db_lim;
2116 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
2123 curblk->b_rptr = rptr;
2126 /* attach the newblk chain into mBuf */
2127 newblk -> b_cont = tmp;
2128 mBuf -> b_cont = curblk;
2130 /* update endptr of mBuf */
2132 minfo -> endptr = newblk;
2134 /* update length of message */
2142 * Fun: SAddPstMsgMult
2144 * Desc: This function copies consecutive bytes of data to the
2148 * RFAILED - failed, general (optional)
2149 * ROUTRES - failed, out of resources (optional)
2151 * Notes: if message is empty: data is placed in the message. message
2152 * length is incremented. return is ok.
2154 * if message is not empty: data is read by source pointer,
2155 * data is placed in back of all other data in message.
2156 * message length is incremented. return is ok.
2158 * the first byte of data pointed to by the source pointer will
2159 * be placed at the back of the message first, the last byte of
2160 * data pointed to by the source pointer will be placed at the
2161 * back of the message last (i.e. it will become the last
2162 * byte of the message).
2168 #ifdef T2K_MEM_LEAK_DBG
2189 Buffer *curblk=NULLP;
2196 #if (ERRCLASS & ERRCLS_INT_PAR)
2197 /* check message buffer */
2200 SSLOGERROR(ERRCLS_INT_PAR, ESS074, ERRZERO, "SAddPstMsgMult:Null Buffer");
2206 SSLOGERROR(ERRCLS_INT_PAR, ESS075, ERRZERO, "SAddPstMsgMult:Null Buffer");
2212 SSLOGERROR(ERRCLS_INT_PAR, ESS076, ERRZERO, "SAddPstMsgMult:Invalid\
2216 if (mBuf->b_datap->db_type != SS_M_PROTO)
2218 SSLOGERROR(ERRCLS_INT_PAR, ESS077, ERRZERO, "SAddPstMsgMult: Incorrect\
2224 /* get the SsMsgInfo of mBuf */
2225 minfo = (SsMsgInfo*) mBuf->b_rptr;
2227 /* store cnt in len */
2230 /* ss014.13: Addition */
2233 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
2234 (tmp->b_datap->db_lim > tmp->b_wptr))
2236 /* store offset of the write pointer */
2237 /* incase subsequent allocations fail, offset is read reset to original */
2238 offset = tmp->b_datap->db_lim - tmp->b_wptr;
2240 /* determine the number of bytes to copy */
2241 numBytes = MIN(cnt, offset);
2247 /* ss002.13: addition */
2249 /* ss004.13: addition */
2250 SMemCpy((Void *) tmp->b_wptr, (Void *) src, (size_t) numBytes);
2252 tmp->b_wptr += numBytes;
2262 newblk = prevblk = NULLP;
2266 /* allocate a message blk */
2267 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2269 while ((curblk = newblk))
2271 newblk = newblk->b_cont;
2272 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2277 tmp->b_wptr = tmp->b_datap->db_lim - offset;
2283 /* insert curblk in the newblk chain */
2285 prevblk->b_cont = curblk; /* stack them down */
2291 wptr = curblk->b_wptr;
2292 numBytes = MIN(cnt, curblk->b_datap->db_lim - wptr);
2298 /* ss002.13: addition */
2299 /* ss003.13: addition */
2300 SMemCpy( (Void *) wptr, (Void *) src, (size_t) numBytes);
2302 src = src + numBytes;
2304 curblk->b_wptr += numBytes;
2306 /* insert newblk chain into mBuf */
2308 tmp->b_cont = newblk;
2310 mBuf->b_cont = newblk;
2311 minfo->endptr = curblk;
2319 /* #ifdef SS_LOCKLESS_MEMORY */
2327 * Desc: This function copies and then removes one byte of
2328 * data from the beginning of a message.
2331 * ROKDNA - ok, data not available
2332 * RFAILED - failed, general (optional)
2334 * Notes: if message is empty: message is unchanged. return is ok,
2335 * data not available.
2337 * if message is not empty: data is removed from front of
2338 * message, data is returned via pointer to data. message
2339 * length is decremented. return is ok.
2354 #ifdef T2K_MEM_LEAK_DBG
2355 char* file = __FILE__;
2356 uint32_t line = __LINE__;
2359 #if (ERRCLASS & ERRCLS_INT_PAR)
2360 /* check data pointer */
2363 SSLOGERROR(ERRCLS_INT_PAR, ESS078, ERRZERO, "SRemPreMsg : Null Buffer");
2366 /* check message buffer */
2369 SSLOGERROR(ERRCLS_INT_PAR, ESS079, ERRZERO, "SRemPreMsg : Null Buffer");
2372 if (mBuf->b_datap->db_type != SS_M_PROTO)
2374 SSLOGERROR(ERRCLS_INT_PAR, ESS080, ERRZERO, "SRemPreMsg : Incorrect\
2380 if (!(tmp = mBuf->b_cont))
2383 /* get SsMsgInfo of mBuf */
2384 minfo = (SsMsgInfo *) mBuf->b_rptr;
2386 /* read databyte into dataPtr and incrment read ptr */
2387 *dataPtr = *tmp->b_rptr++;
2389 /* if all data is exhausted, release the blk */
2390 if (tmp->b_rptr == tmp->b_wptr)
2392 mBuf->b_cont = tmp->b_cont;
2393 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2395 /* update SsMsgInfo */
2397 minfo->endptr = NULLP;
2406 * Desc: This function copies and then removes one byte of
2407 * data from the end of a message.
2410 * ROKDNA - ok, data not available
2411 * RFAILED - failed, general (optional)
2413 * Notes: if message is empty: message is unchanged. return is ok,
2414 * data not available.
2416 * if message is not empty: data is removed from back of
2417 * message, data is returned via pointer to data. message
2418 * length is decremented. return is ok.
2427 Data *dataPtr, /* pointer to data */
2434 #ifdef T2K_MEM_LEAK_DBG
2435 char* file = __FILE__;
2436 uint32_t line = __LINE__;
2439 #if (ERRCLASS & ERRCLS_INT_PAR)
2440 /* check data pointer */
2441 if (dataPtr == NULLP)
2443 SSLOGERROR(ERRCLS_INT_PAR, ESS081, ERRZERO, "SRemPstMsg : Null Buffer");
2446 /* check message buffer */
2449 SSLOGERROR(ERRCLS_INT_PAR, ESS082, ERRZERO, "SRemPstMsg : Null Buffer");
2452 if (mBuf->b_datap->db_type != SS_M_PROTO)
2454 SSLOGERROR(ERRCLS_INT_PAR, ESS083, ERRZERO, "SRemPstMsg : Incorrect\
2460 /* get the SsMsgInfo */
2461 minfo = (SsMsgInfo*) mBuf->b_rptr;
2463 if (!(last = minfo->endptr))
2466 /* read databyte into dataPtr and decrement write ptr */
2467 *dataPtr = *--last->b_wptr;
2469 /* if all data is exhausted, release the blk */
2470 if (last->b_rptr == last->b_wptr)
2472 for (tmp = mBuf; tmp->b_cont != last;)
2474 tmp->b_cont = NULLP;
2475 (Void) SPutDBuf(minfo->region, minfo->pool, last);
2479 minfo->endptr = tmp;
2481 minfo->endptr = NULLP;
2483 /* update SsMsgInfo */
2492 * Fun: SRemPreMsgMult
2494 * Desc: This function copies and then removes consecutive bytes of
2495 * data from the beginning of a message.
2498 * ROKDNA - ok, data not available
2499 * RFAILED - failed, general (optional)
2501 * Notes: if message is empty: message is unchanged. return is ok,
2502 * data not available.
2504 * if the destination buffer is NULL, data is not copied.
2506 * if message is not empty: data is removed from front of
2507 * message, data is returned by destination pointer. message
2508 * length is decremented. return is ok.
2510 * the first byte of data read from the message will be placed
2511 * in the destination buffer first (i.e. this was the first byte
2512 * of the message), the last byte of data read from the message
2513 * will be placed in the destination buffer last.
2521 Data *dst, /* destination */
2522 MsgLen cnt, /* count */
2526 SsMsgInfo *minfo = NULLP;
2527 Buffer *tmp = NULLP;
2529 #ifdef T2K_MEM_LEAK_DBG
2530 char* file = __FILE__;
2531 uint32_t line = __LINE__;
2535 /* ss023.103 - Modification of SRemPreMsgMult for bug fix */
2537 #if (ERRCLASS & ERRCLS_INT_PAR)
2541 SSLOGERROR(ERRCLS_INT_PAR, ESS084, ERRZERO, "SRemPreMsgMult:Invalid\
2545 /* check message buffer */
2548 SSLOGERROR(ERRCLS_INT_PAR, ESS085, ERRZERO, "SRemPreMsgMult:Null Buffer");
2551 /* ss021.103 - Addition to check for NULL pointer */
2552 /* check data pointer */
2553 /* ss022.103 - Removed check for NULL pointer */
2554 if (mBuf->b_datap->db_type != SS_M_PROTO)
2556 SSLOGERROR(ERRCLS_INT_PAR, ESS086, ERRZERO, "SRemPreMsgMult : Incorrect\
2562 /* get the SsMsgInfo */
2563 minfo = (SsMsgInfo*) mBuf->b_rptr;
2565 /* check if data present */
2566 if (minfo->len < cnt)
2573 /* get the first SS_M_DATA blk */
2576 /* determine the number of bytes to be copy */
2577 numBytes = MIN(cnt, tmp->b_wptr - tmp->b_rptr);
2582 /* move data into dst */
2586 SMemCpy( (Void *) dst, (Void *) tmp->b_rptr, (size_t) numBytes);
2590 tmp->b_rptr += numBytes;
2592 if (tmp->b_rptr == tmp->b_wptr)
2594 mBuf->b_cont = tmp->b_cont;
2595 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2598 /* update SsMsgInfo */
2600 minfo->endptr = NULLP;
2607 * Fun: SRemPstMsgMult
2609 * Desc: This function copies and then removes consecutive bytes of
2610 * data from the end of a message.
2613 * ROKDNA - ok, data not available
2614 * RFAILED - failed, general (optional)
2616 * Notes: if message is empty: message is unchanged. return is ok,
2617 * data not available.
2619 * if the destination buffer is NULL, data is not copied.
2621 * if message is not empty: data is removed from front of
2622 * message, data is returned by destination pointer. message
2623 * length is decremented. return is ok.
2625 * the first byte of data read from the message will be placed
2626 * in the destination buffer first (i.e. this was the last byte
2627 * of the message), the last byte of data read from the message
2628 * will be placed in the destination buffer last.
2636 Data *dst, /* destination */
2637 MsgLen cnt, /* count */
2647 #ifdef T2K_MEM_LEAK_DBG
2648 char* file = __FILE__;
2649 uint32_t line = __LINE__;
2653 #if (ERRCLASS & ERRCLS_INT_PAR)
2657 SSLOGERROR(ERRCLS_INT_PAR, ESS087, ERRZERO, "SRemPstMsgMult:Invalid\
2661 /* check message buffer */
2664 SSLOGERROR(ERRCLS_INT_PAR, ESS088, ERRZERO, "SRemPstMsgMult:Null Buffer");
2667 if (mBuf->b_datap->db_type != SS_M_PROTO)
2669 SSLOGERROR(ERRCLS_INT_PAR, ESS089, ERRZERO, "SRemPstMsgMult : Incorrect\
2673 /* ss021.103 - Addition to check dst data pointer */
2674 /* check data pointer */
2675 /* ss022.103 - Removed check for NULL destination pointer */
2678 /* get the SsMsgInfo */
2679 minfo = (SsMsgInfo*) mBuf->b_rptr;
2681 /* check if data present */
2682 if (minfo->len < cnt)
2692 /* determine blk containing offset, and prev node */
2693 FIND_OFFSET_AND_PREV(prev, tmp, count)
2700 numBytes = MIN(cnt, (tmp->b_wptr - tmp->b_rptr - count));
2702 tmp->b_wptr -= numBytes;
2714 if (tmp->b_rptr == tmp->b_wptr)
2716 prev->b_cont = tmp->b_cont;
2717 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2726 minfo->endptr = NULLP;
2728 minfo->endptr = prev;
2737 * Desc: This function copies one byte of data from a message
2738 * without modifying the message.
2741 * ROKDNA - ok, data not available
2742 * RFAILED - failed, general (optional)
2744 * Notes: index is 0 based and indicates location in message
2746 * if index is less than the length of the message:
2747 * message is unchanged and data is examined at specified
2748 * index and returned via pointer to data. message length
2749 * is unchanged. return is ok.
2751 * if index is greater than or equal to
2752 * the length of the message: message is unchanged and 0
2753 * is returned via pointer to data. return is ok, data
2763 Data *dataPtr, /* pointer to data */
2764 Buffer *mBuf, /* message buffer */
2771 #if (ERRCLASS & ERRCLS_INT_PAR)
2772 /* check data pointer */
2775 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SExamMsg : Null Buffer");
2778 /* check message buffer */
2781 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SExamMsg : Null Buffer");
2787 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SExamMsg : Invalid Index");
2790 if (mBuf->b_datap->db_type != SS_M_PROTO)
2792 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SExamMsg : Incorrect buffer\
2798 /* get the SsMsgInfo */
2799 minfo = (SsMsgInfo*) mBuf->b_rptr;
2801 if (minfo->len <= idx)
2806 /* get the first SS_M_DATA blk */
2809 /* determine offset */
2810 FIND_OFFSET(tmp, idx)
2812 *dataPtr = *(tmp->b_rptr + idx);
2821 * Fun: SGetDataFrmMsg
2823 * Desc: This function copies requested byte of data from a message
2824 * without modifying the message.
2827 * ROKDNA - ok, data not available
2828 * RFAILED - failed, general (optional)
2830 * Notes: index is 0 based and indicates location in message
2832 * if index is less than the length of the message:
2833 * message is unchanged and data is examined at specified
2834 * index and returned via pointer to data. message length
2835 * is unchanged. return is ok.
2837 * if index is greater than or equal to
2838 * the length of the message: message is unchanged and 0
2839 * is returned via pointer to data. return is ok, data
2849 Buffer *mBuf, /* message buffer */
2850 Data *dataPtr, /* pointer to data */
2858 Data *tmpDataPtr = dataPtr;
2860 #if (ERRCLASS & ERRCLS_INT_PAR)
2861 /* check data pointer */
2864 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SGetDataFrmMsg: Null Buffer");
2867 /* check message buffer */
2870 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SGetDataFrmMsg: Null Buffer");
2876 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SGetDataFrmMsg: Invalid Index");
2879 if (mBuf->b_datap->db_type != SS_M_PROTO)
2881 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SGetDataFrmMsg: Incorrect buffer\
2887 /* get the SsMsgInfo */
2888 minfo = (SsMsgInfo*) mBuf->b_rptr;
2890 if (minfo->len <= (idx + dataLen) )
2895 /* get the first SS_M_DATA blk */
2898 /* determine offset */
2905 FIND_OFFSET(tmp, idx)
2906 offSetLen = ((tmp->b_wptr - (tmp->b_rptr + idx)));
2908 for(;(offSetLen < dataLen && tmp != NULLP);)
2910 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)offSetLen);
2911 dataLen = dataLen - offSetLen;
2914 tmpDataPtr = tmpDataPtr + offSetLen;
2915 offSetLen = tmp->b_wptr - tmp->b_rptr;
2921 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)dataLen);
2925 } /* End of SGetDataFrmMsg() */
2931 * Desc: This function determines the length of data within
2935 * RFAILED - failed, general (optional)
2937 * Notes: length of message is determined, message is unchanged
2938 * and length is returned via pointer to length. return is ok.
2947 REG1 Buffer *mBuf, /* message buffer */
2953 #if (ERRCLASS & ERRCLS_INT_PAR)
2954 /* check message buffer */
2957 SSLOGERROR(ERRCLS_INT_PAR, ESS094, ERRZERO, "SFndLenMsg : Null Buffer");
2960 /* check length pointer */
2961 if (lngPtr == NULLP)
2963 SSLOGERROR(ERRCLS_INT_PAR, ESS095, ERRZERO, "SFndLenMsg : Null Buffer");
2966 if (mBuf->b_datap->db_type != SS_M_PROTO)
2968 SSLOGERROR(ERRCLS_INT_PAR, ESS096, ERRZERO, "SFndLenMsg : Incorrect\
2974 /* get the SsMsgInfo */
2975 minfo = (SsMsgInfo*) mBuf->b_rptr;
2978 *lngPtr = minfo->len;
2984 /* #ifdef SS_LOCKLESS_MEMORY */
2990 * Desc: This function will segment one specified message into two
2994 * ROKDNA - ok, data not available
2995 * RFAILED - failed, general (optional)
2996 * ROUTRES - failed, out of resources (optional)
2998 * Notes: message 1 is the original message.
3000 * message 2 is the new message.
3002 * index is 0 based and indicates location in message 1
3003 * from which message 2 will be created.
3005 * if index is equal to 0: message 2 is created and all data
3006 * attached to message 1 is moved to message 2. message 1
3007 * is not returned to memory. return is ok.
3009 * if index is not equal to 0 and less than the length of
3010 * the message minus 1: message 2 is created, all data
3011 * attached to message 1 from index (inclusive) is moved to
3012 * message 2. message 1 contains data from index 0 to index
3013 * minus 1. return is ok.
3015 * if index is not equal to 0 and greater than or equal to
3016 * the length of the message minus 1: message 1 is unchanged.
3017 * message 2 is set to null. return is ok, data not available.
3022 #ifdef T2K_MEM_LEAK_DBG
3025 Buffer *mBuf1, /* message 1 */
3026 MsgLen idx, /* index */
3034 Buffer *mBuf1, /* message 1 */
3035 MsgLen idx, /* index */
3047 #if (ERRCLASS & ERRCLS_INT_PAR)
3048 /* check message buffer 1 */
3051 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SSegMsg : Null Buffer");
3054 /* check message buffer 2 */
3057 SSLOGERROR(ERRCLS_INT_PAR, ESS098, ERRZERO, "SSegMsg : Null Buffer");
3062 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SSegMsg : Invalid index");
3065 if (mBuf1->b_datap->db_type != SS_M_PROTO)
3067 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SSegMsg : Incorrect buffer\
3073 /* get the SsMsgInfo of mBuf1 */
3074 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
3075 #ifdef RGL_SPECIFIC_CHANGES
3079 /* if index > length of mBuf, return */
3080 if (idx >= minfo1->len)
3085 /* allocate message buffer */
3086 if (SGetMsg(minfo1->region, minfo1->pool, mBuf2) != ROK)
3088 SSLOGERROR(ERRCLS_DEBUG, ESS101, ERRZERO, "SSegMsg : SGetMsg failed");
3092 /* get the SsMsgInfo of mBuf2 */
3093 minfo2 = (SsMsgInfo*) (*mBuf2)->b_rptr;
3095 /* adjust the lengths of mBuf1, mBuf2 */
3096 minfo2->len = minfo1->len - idx;
3099 /* set the endptr of mBuf2 to mBuf1 */
3100 minfo2->endptr = minfo1->endptr;
3102 /* if index is zero ... */
3105 (*mBuf2)->b_cont = mBuf1->b_cont;
3107 /* set the endptr and b_cont of mBuf1 to NULLP */
3108 minfo1->endptr = NULLP;
3109 mBuf1->b_cont = NULLP;
3114 /* get the first SS_M_DATA blk */
3115 tmp = mBuf1->b_cont;
3118 FIND_OFFSET_AND_PREV(prev, tmp, idx)
3120 /* segmented at the start of a blk */
3123 (*mBuf2)->b_cont = tmp;
3124 prev->b_cont = NULLP;
3125 minfo1->endptr = prev;
3129 #ifndef SS_MULTICORE_SUPPORT
3130 /* allocate a message blk without a data blk */
3131 /* ssDupB internally increments the reference count */
3132 #ifdef SS_M_PROTO_REGION
3133 if (!(next = DupMsg(minfo1->region, tmp)))
3135 if (!(next = ssDupB(tmp)))
3136 #endif /* SS_M_PROTO_REGION */
3139 minfo1->len += minfo2->len;
3140 (Void) SPutMsg(*mBuf2);
3144 (*mBuf2)->b_cont = next;
3146 tmp->b_cont = NULLP;
3148 tmp->b_wptr = tmp->b_rptr + idx;
3149 next->b_rptr = tmp->b_wptr;
3151 /* If the index was in the last mblk of the message, the
3152 * end pointer of the new message needs to be set to the
3153 * dup'ped mblk. Otherwise, the end pointer of the first
3154 * message will be set to the mblk in which the index
3155 * was found, and the end pointer of the new message can
3156 * remain where it is.
3158 if (minfo1->endptr == tmp)
3160 minfo2->endptr = next;
3164 minfo1->endptr = tmp;
3166 #else /*SS_MULTICORE_SUPPORT*/
3170 #ifdef SS_M_PROTO_REGION
3171 if (!(next = DupMsg(minfo1->region, tmp)))
3173 if (!(next = ssDupB(tmp)))
3174 #endif /* SS_M_PROTO_REGION */
3177 minfo1->len += minfo2->len;
3178 (Void) SPutMsg(*mBuf2);
3181 (*mBuf2)->b_cont = next;
3182 tmp->b_wptr = tmp->b_rptr + idx;
3183 next->b_rptr += idx;
3186 /* copy rest of the blocks */
3190 prev->b_cont = NULLP;
3191 minfo2->endptr = minfo1->endptr;
3192 minfo1->endptr = prev;
3196 next->b_cont = NULLP;
3197 minfo2->endptr = next;
3200 #endif /*SS_MULTICORE_SUPPORT*/
3210 * Desc: This function copies data from a fixed buffer to a
3214 * RFAILED - failed, general (optional)
3224 Data *srcBuf, /* source buffer */
3225 Buffer *dstMbuf, /* destination message buffer */
3226 MsgLen dstIdx, /* destination index */
3227 MsgLen cnt, /* count */
3235 #if (ERRCLASS & ERRCLS_INT_PAR)
3236 /* check source message buffer */
3237 if (srcBuf == NULLP)
3239 SSLOGERROR(ERRCLS_INT_PAR, ESS102, ERRZERO, "SCpyFixMsg : Null Buffer");
3242 /* check destination message buffer */
3243 if (dstMbuf == NULLP)
3245 SSLOGERROR(ERRCLS_INT_PAR, ESS103, ERRZERO, "SCpyFixMsg : Null Buffer");
3248 /* check copied count buffer */
3251 SSLOGERROR(ERRCLS_INT_PAR, ESS104, ERRZERO, "SCpyFixMsg : Null Buffer");
3254 /* check copy count */
3257 SSLOGERROR(ERRCLS_INT_PAR, ESS105, ERRZERO, "SCpyFixMsg : Invalid count");
3260 if (dstMbuf->b_datap->db_type != SS_M_PROTO)
3262 SSLOGERROR(ERRCLS_INT_PAR, ESS106, ERRZERO, "SCpyFixMsg : Incorrect\
3268 minfo = (SsMsgInfo*) dstMbuf->b_rptr;
3270 if (minfo->len < dstIdx)
3272 #if (ERRCLASS & ERRCLS_DEBUG)
3273 SSLOGERROR(ERRCLS_DEBUG, ESS107, ERRZERO, "SCpyFixMsg : Invalid Index");
3278 /* ss021.103 - Addition test if message length will exceed max msg length */
3279 #if (ERRCLASS & ERRCLS_INT_PAR)
3281 if (minfo->len > 0x7FFFFFFF - cnt)
3283 if (minfo->len > 0x7FFF - cnt)
3288 SSLOGERROR(ERRCLS_INT_PAR, ESS108, ERRZERO, "SCpyFixMsg : msgLen + cnt > maxS16");
3293 /* add data at the start of dst buffer */
3296 if ((ret = SAddPreMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3298 #if (ERRCLASS & ERRCLS_DEBUG)
3299 SSLOGERROR(ERRCLS_DEBUG, ESS109, ERRZERO, "SCpyFixMsg : Failed in\
3309 /* add data at the end of the dst buffer */
3310 if (minfo->len == dstIdx)
3312 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3321 /* segment the message into dstMbuf and right */
3322 if ((ret = SSegMsg(dstMbuf, dstIdx, &right)) != ROK)
3327 /* append data at the end of dstMbuf */
3328 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3330 /* ss020.103 - Addition for cleanup */
3331 (Void) SPutMsg(right);
3335 /* cancatenate dstMbuf and right */
3336 if ((ret = SCatMsg(dstMbuf, right, M1M2)) != ROK)
3338 /* ss020.103 - Addition for cleanup */
3339 (Void) SPutMsg(right);
3345 (Void) SPutMsg(right);
3354 * Desc: This function copies data from a message
3355 * into a fixed buffer.
3358 * RFAILED - failed, general (optional)
3368 Buffer *srcMbuf, /* source message buffer */
3369 MsgLen srcIdx, /* source index */
3370 MsgLen cnt, /* count */
3371 Data *dstBuf, /* destination buffer */
3376 Buffer *tmp = NULLP;
3377 SsMsgInfo *minfo = NULLP;
3380 #if (ERRCLASS & ERRCLS_INT_PAR)
3381 /* check source message buffer */
3382 if (srcMbuf == NULLP)
3384 SSLOGERROR(ERRCLS_INT_PAR, ESS110, ERRZERO, "SCpyMsgFix : Null Buffer");
3387 /* check destination message buffer */
3388 if (dstBuf == NULLP)
3390 SSLOGERROR(ERRCLS_INT_PAR, ESS111, ERRZERO, "SCpyMsgFix : Null Buffer");
3395 SSLOGERROR(ERRCLS_INT_PAR, ESS112, ERRZERO, "SCpyMsgFix : Invalid Index");
3401 SSLOGERROR(ERRCLS_INT_PAR, ESS113, ERRZERO, "SCpyMsgFix : Invalid Index");
3406 SSLOGERROR(ERRCLS_INT_PAR, ESS114, ERRZERO, "SCpyMsgFix : Null Buffer");
3409 if (srcMbuf->b_datap->db_type != SS_M_PROTO)
3411 SSLOGERROR(ERRCLS_INT_PAR, ESS115, ERRZERO, "SCpyMsgFix : Incorrect\
3418 minfo = (SsMsgInfo*) srcMbuf->b_rptr;
3420 if ((srcIdx + cnt) > minfo->len)
3426 /* get the first SS_M_DATA blk */
3427 tmp = srcMbuf->b_cont;
3429 /* get to the srcIdx-th offset */
3430 FIND_OFFSET(tmp, srcIdx)
3434 /* set cptr to the read ptr of tmp + offset */
3435 cptr = tmp->b_rptr + srcIdx;
3439 /* determine the number of bytes to be copied */
3440 numBytes = MIN(cnt, (tmp->b_wptr - cptr));
3447 /* ss002.13 addition */
3449 /* ss003.13 addition */
3450 SMemCpy((Void *) dstBuf, (Void *) cptr, (size_t) numBytes);
3456 /* get the next blk */
3457 if ((tmp = tmp->b_cont))
3458 /* set cptr to the read ptr of tmp */
3471 * Desc: This function is used to copy a message into
3472 * a new region and or pool of memory.
3475 * RFAILED - failed, general (optional)
3476 * ROUTRES - failed, out of resources (optional)
3484 #ifdef T2K_MEM_LEAK_DBG
3511 /* ss021.103 - Addition of return value */
3513 #if (ERRCLASS & ERRCLS_INT_PAR)
3518 #if (ERRCLASS & ERRCLS_INT_PAR)
3521 SSLOGERROR(ERRCLS_INT_PAR, ESS116, ERRZERO, "SCpyMsgMsg : Null Buffer");
3524 if (srcBuf->b_datap->db_type != SS_M_PROTO)
3526 SSLOGERROR(ERRCLS_INT_PAR, ESS117, ERRZERO, "SCpyMsgMsg : Incorrect\
3530 /* ss021.103 - Addition to validate region and pool */
3531 if (dstRegion >= SS_MAX_REGS)
3533 SSLOGERROR(ERRCLS_INT_PAR, ESS118, ERRZERO,
3534 "SCpyMsgMsg : Invalid region id");
3538 if (dstPool >= SS_MAX_POOLS_PER_REG)
3540 SSLOGERROR(ERRCLS_INT_PAR, ESS119, ERRZERO,
3541 "SCpyMsgMsg : Invalid pool id");
3544 /* ss037.103 Removed the semaphore operation for performance enhancement */
3547 /* ss021.103 - Addition to check if region is valid */
3548 /* acquire one semaphore, to protect against deregistration */
3549 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
3553 #if (ERRCLASS & ERRCLS_DEBUG)
3554 SSLOGERROR(ERRCLS_DEBUG, ESS120, (ErrVal) ret,
3555 "Could not lock region table");
3562 #if (ERRCLASS & ERRCLS_INT_PAR)
3563 /* verify that this region is present */
3564 if (osCp.regionTbl[dstRegion].used == FALSE)
3567 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3569 #if (ERRCLASS & ERRCLS_DEBUG)
3570 SSLOGERROR(ERRCLS_DEBUG, ESS121, ERRZERO,
3571 "Could not release semaphore");
3576 SSLOGERROR(ERRCLS_INT_PAR, ESS122, dstRegion, "Region not registered");
3580 /* ss037.103 Removed the semaphore operation for performance enhancement */
3583 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3585 #if (ERRCLASS & ERRCLS_DEBUG)
3586 SSLOGERROR(ERRCLS_DEBUG, ESS123, ERRZERO,
3587 "Could not release semaphore");
3594 #ifdef XEON_SPECIFIC_CHANGES
3598 /* allocate a message buffer */
3599 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
3601 #if (ERRCLASS & ERRCLS_DEBUG)
3602 SSLOGERROR(ERRCLS_DEBUG, ESS124, ERRZERO, "SCpyMsgMsg : SGetMsg failed");
3606 /* get the SsMsgInfo from srcBuf */
3607 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
3609 /* get the SsMsgInfo from srcBuf */
3610 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
3612 /* get the first SS_M_DATA blk of srcBuf */
3613 tmp = srcBuf->b_cont;
3615 /* if srcBuf and dstBuf belong to the same region, increment the reference
3624 #ifdef SS_M_PROTO_REGION
3625 if ((curblk = DupMsg(dstRegion,tmp)) == NULLP)
3627 if ((curblk = ssDupB(tmp)) == NULLP)
3628 #endif /* SS_M_PROTO_REGION */
3632 curblk = newblk->b_cont;
3633 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
3637 printf("\nFailed to get the buffer of size %s %d\n", __FILE__, __LINE__);
3639 (Void) SPutMsg(*dstBuf);
3646 prevblk->b_cont = curblk;
3652 curblk->b_cont = NULLP;
3654 minfo2->len = minfo1->len;
3655 minfo2->endptr = curblk;
3656 (*dstBuf)->b_cont = newblk;
3667 * Desc: This function is used to copy a message into
3668 * a new region and or pool of memory.
3671 * RFAILED - failed, general (optional)
3672 * ROUTRES - failed, out of resources (optional)
3679 #ifdef T2K_MEM_LEAK_DBG
3710 #if (ERRCLASS & ERRCLS_INT_PAR)
3713 SSLOGERROR(ERRCLS_INT_PAR, ESS126, ERRZERO, "SAddMsgRef : Null Buffer");
3716 if (srcBuf->b_datap->db_type != SS_M_PROTO)
3718 SSLOGERROR(ERRCLS_INT_PAR, ESS127, ERRZERO, "SAddMsgRef : Incorrect\
3723 #ifdef XEON_SPECIFIC_CHANGES
3728 /* allocate a message buffer */
3729 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
3731 #if (ERRCLASS & ERRCLS_DEBUG)
3732 SSLOGERROR(ERRCLS_DEBUG, ESS128, ERRZERO, "SAddMsgRef : SGetMsg failed");
3736 /* get the SsMsgInfo from srcBuf */
3737 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
3739 /* get the SsMsgInfo from srcBuf */
3740 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
3742 /* get the first SS_M_DATA blk of srcBuf */
3743 tmp = srcBuf->b_cont;
3745 /* if srcBuf and dstBuf belong to the same region, increment the reference
3748 if (dstRegion == minfo1->region)
3756 #ifdef SS_M_PROTO_REGION
3757 if ((curblk = DupMsg(dstRegion, tmp)) == NULLP)
3759 if ((curblk = ssDupB(tmp)) == NULLP)
3760 #endif /* SS_M_PROTO_REGION */
3764 curblk = newblk->b_cont;
3765 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
3768 (Void) SPutMsg(*dstBuf);
3775 prevblk->b_cont = curblk;
3781 curblk->b_cont = NULLP;
3783 minfo2->len = minfo1->len;
3784 minfo2->endptr = curblk;
3785 (*dstBuf)->b_cont = newblk;
3790 /* allocate a data buffer */
3791 if (ssGetDBufOfSize(dstRegion, minfo1->len, &dBuf) != ROK)
3793 /* ss016.13: addition */
3794 (Void) SPutMsg(*dstBuf);
3795 SSLOGERROR(ERRCLS_DEBUG, ESS129, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
3799 dBuf->b_datap->db_type = SS_M_DATA;
3803 numBytes = tmp->b_wptr - tmp->b_rptr;
3806 *dBuf->b_wptr++ = *cptr++;
3809 minfo2->len = minfo1->len;
3810 /* set the endptr and b_cont of dstBuf to point to dBuf */
3811 minfo2->endptr = dBuf;
3812 (*dstBuf)->b_cont = dBuf;
3816 /* ss012.13: Addition */
3817 #ifdef SS_M_PROTO_REGION
3822 * Desc: Duplicates the specified message block, copying it
3823 * into a newly-allocated message block. Increments
3824 * the reference count of the data block that is pointed
3825 * at by the original message block descriptor.
3827 * Ret: non-NULL - ok
3835 #ifdef T2K_MEM_LEAK_DBG
3836 static Buffer *DupMsgNew
3838 Region region, /* region id */
3839 Buffer *mp, /* message block */
3844 static Buffer *DupMsg
3846 Region region, /* region id */
3847 Buffer *mp /* message block */
3851 Buffer *bp; /* mblk for iteration */
3852 S16 r; /* return value */
3853 Size m; /* temporary */
3856 #if (ERRCLASS & ERRCLS_INT_PAR)
3859 SSLOGERROR(ERRCLS_INT_PAR, ESS130, ERRZERO, "Null pointer");
3863 if (region >= SS_MAX_REGS)
3865 SSLOGERROR(ERRCLS_INT_PAR, ESS131, ERRZERO, "DupMsg : Invalid region\
3872 /* allocate a single block for the mblock and the dblock */
3874 m = (sizeof(SsMblk) + sizeof(SsDblk));
3876 numBytes = mp->b_wptr - mp->b_rptr;
3877 m = MDBSIZE + numBytes;
3878 #endif /* SS_MULTICORE_SUPPORT */
3879 /* ss001.301: additions */
3880 #ifdef SS_HISTOGRAM_SUPPORT
3881 r = SAlloc(region, &m, 0, (Data **)&bp, __LINE__, (uint8_t*) __FILE__, ENTNC);
3883 r = SAlloc(region, &m, 0, (Data **)&bp);
3884 #endif /* SS_HISTOGRAM_SUPPORT */
3887 #if (ERRCLASS & ERRCLS_ADD_RES)
3888 SSLOGERROR(ERRCLS_ADD_RES, ESS132, (ErrVal) r, "SAlloc() failed");
3893 /* generic set-up-message function */
3895 #ifndef SS_DBUF_REFLOCK_DISABLE
3896 SS_STRM_INITB(bp, (SsDblk *)(((uint8_t *)bp) + sizeof(SsMblk)), NULLP, 0, NULLP);
3899 data = (Data *) (bp) + MDBSIZE;
3900 SS_STRM_INITB(bp,(SsDblk *)(((uint8_t *)bp) + sizeof(SsMblk)), data, numBytes, NULLP);
3901 #endif /* SS_MULTICORE_SUPPORT */
3904 /* make the new message block identical to the one to be dup'ed.
3905 * notice that an mblk/dblk pair is allocated but only the mblk
3906 * is used,, this is for optimum performance in the average case.
3908 SMemCpy( (Void *)bp, (Void *)mp, (size_t)sizeof(SsMblk));
3910 /* ss006.301 - added the Lock */
3911 #ifndef SS_DBUF_REFLOCK_DISABLE
3912 if((SLock(&(mp->b_datap->dBufLock))) != ROK)
3914 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
3915 "Could not lock the mBuf Ref Lock");
3919 /* increment the reference count of the dblock */
3920 /* increment the reference count of the dblock */
3921 mp->b_datap->db_ref++;
3922 mp->b_datap->shared = TRUE;
3923 #ifndef SS_DBUF_REFLOCK_DISABLE
3924 if((SUnlock(&(mp->b_datap->dBufLock))) != ROK)
3926 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
3927 "Could not lock the mBuf Ref Lock");
3935 #endif /* SS_M_PROTO_REGION */
3941 * Desc: This function allocates a buffer from the dynamic
3942 * memory pool indicated by the caller.
3945 * RFAILED - failed, general (optional)
3946 * ROUTRES - failed, out of resources (optional)
3948 * Notes: The dynamic memory pools are used to create and
3949 * manipulate messages.
3951 * SGetDBuf is never called by a protocol layer.
3953 * SGetDBuf assumes that interrupts are already disabled.
3959 #ifdef T2K_MEM_LEAK_DBG
3962 Region region, /* region id */
3963 Pool pool, /* pool id */
3971 Region region, /* region id */
3972 Pool pool, /* pool id */
3981 #ifdef SS_LOCKLESS_MEMORY
3982 #ifdef SS_USE_ICC_MEMORY
3983 CmMmDynRegCb *regCb;
3985 CmMmGlobRegCb *regCb;
3988 SsRegionEntry *regp;
3989 #endif /* SS_LOCKLESS_MEMORY */
3990 /* ss021.103 - Addition of return value */
3992 #if (ERRCLASS & ERRCLS_INT_PAR)
3997 #if (ERRCLASS & ERRCLS_INT_PAR)
3998 /* check buffer pointer */
4001 SSLOGERROR(ERRCLS_INT_PAR, ESS133, ERRZERO, "SGetDBuf : Null Buffer");
4004 if (region >= SS_MAX_REGS)
4006 SSLOGERROR(ERRCLS_INT_PAR, ESS134, ERRZERO, "SGetDBuf : Invalid region\
4011 if (pool >= SS_MAX_POOLS_PER_REG)
4013 SSLOGERROR(ERRCLS_INT_PAR, ESS135, ERRZERO, "SGetDBuf : Invalid pool id");
4016 /* ss037.103 Removed the semaphore operation for performance enhancement */
4019 /* ss021.103 - Addition to check if region is registered */
4020 /* acquire one semaphore, to protect against deregistration */
4021 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
4025 #if (ERRCLASS & ERRCLS_DEBUG)
4026 SSLOGERROR(ERRCLS_DEBUG, ESS136, (ErrVal) ret,
4027 "Could not lock region table");
4035 #if (ERRCLASS & ERRCLS_INT_PAR)
4036 /* verify that this region is present */
4037 if (osCp.regionTbl[region].used == FALSE)
4039 /* ss037.103 Removed the semaphore operation for performance enhancement */
4042 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4044 #if (ERRCLASS & ERRCLS_DEBUG)
4045 SSLOGERROR(ERRCLS_DEBUG, ESS137, ERRZERO,
4046 "Could not release semaphore");
4051 SSLOGERROR(ERRCLS_INT_PAR, ESS138, region, "Region not registered");
4055 /* ss037.103 Removed the semaphore operation for performance enhancement */
4058 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4060 #if (ERRCLASS & ERRCLS_DEBUG)
4061 SSLOGERROR(ERRCLS_DEBUG, ESS139, ERRZERO,
4062 "Could not release semaphore");
4069 #ifdef SS_LOCKLESS_MEMORY
4070 #ifdef SS_USE_ICC_MEMORY
4071 regCb = (CmMmDynRegCb *)(osCp.dynRegionTbl[region].regCb);
4072 mdsize = regCb->bktSize[pool];
4073 #else /* SS_USE_ICC_MEMORY */
4074 regCb = osCp.globRegCb;
4075 #ifdef SS_MEM_WL_DEBUG
4076 mdsize = regCb->bktTbl[pool].size - 4;
4077 #else /* SS_MEM_WL_DEBUG */
4078 mdsize = regCb->bktTbl[pool].size;
4079 #endif /* SS_MEM_WL_DEBUG */
4080 #endif /* SS_USE_ICC_MEMORY */
4082 regp = &osCp.regionTbl[region];
4083 size = regp->poolTbl[pool].u.dpool.size;
4084 /* ss006.301 : optimized this function */
4085 mdsize = MDBSIZE + size;
4086 #endif /* SS_LOCKLESS_MEMORY */
4088 /* ss006.301 : optimized this function */
4089 /* ss001.301: additions */
4090 #ifdef SS_HISTOGRAM_SUPPORT
4091 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
4093 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr) != ROK)
4094 #endif /* SS_HISTOGRAM_SUPPORT */
4098 data = (Data *) (*bufPtr) + MDBSIZE;
4099 size = mdsize - MDBSIZE;
4101 dptr = (SsDblk*) (((Data *) (*bufPtr)) + MBSIZE);
4103 INITB((*bufPtr), dptr, data, size, NULLP)
4104 #ifndef SS_DBUF_REFLOCK_DISABLE
4105 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
4108 printf("\nFalied to destroy lock\n");
4120 * Desc: This function deallocates a buffer back to the
4121 * dynamic memory pool indicated by the caller.
4124 * RFAILED - failed, general (optional)
4126 * Notes: The dynamic memory pools are used to create and
4127 * manipulate messages.
4129 * SPutDBuf is never called by a protocol layer.
4131 * SPutDBuf assumes that interrupts are already disabled.
4137 #ifdef T2K_MEM_LEAK_DBG
4155 register SsDblk *dptr = NULLP;
4156 /* ss021.103 - Addition to check return value of SFree */
4158 #if (defined(SS_USE_ZBC_MEMORY) && defined (TENB_DPDK_BUF))
4159 Data *dpdkBuf = NULLP;
4163 /* ss021.103 - Addition of ret initialization */
4166 #if (ERRCLASS & ERRCLS_INT_PAR)
4167 if (region >= SS_MAX_REGS)
4169 SSLOGERROR(ERRCLS_INT_PAR, ESS141, ERRZERO, "SPutDBuf:Invalid region");
4173 if (pool >= SS_MAX_POOLS_PER_REG)
4175 SSLOGERROR(ERRCLS_INT_PAR, ESS142, ERRZERO, "SPutDBuf:Invalid pool");
4181 SSLOGERROR(ERRCLS_INT_PAR, ESS143, ERRZERO, "SPutDBuf:Null pointer");
4185 if ( (buf->b_datap->db_type != SS_M_DATA) && (buf->b_datap->db_type != SS_M_PROTO))
4187 SSLOGERROR(ERRCLS_INT_PAR, ESS144, ERRZERO, "SPutDBuf:Incorrect\
4192 /* ss016.13: Addition */
4193 dptr = buf->b_datap;
4195 #ifdef SS_USE_ZBC_MEMORY
4196 if(dptr->db_type == SS_MEM_TYPE_SSI_ZBC)
4198 ret = SPutZbcDBuf(region, buf);
4202 #ifdef TENB_DPDK_BUF
4203 if(dptr->db_type == SS_MEM_TYPE_DPDK_ZBC)
4205 /* Not considering referances for DPDK buffer for now */
4206 SDetachDpdkPtrFrmDBuf(buf, &dpdkBuf);
4207 SPutSBufDpdk(dpdkBuf);
4208 ret = SFree(region, (Data *) buf, MDBSIZE);
4211 #endif /* TENB_DPDK_BUF */
4212 #endif /* SS_USE_ZBC_MEMORY */
4214 /* ss028.103 - Addition of lock for mBuf reference count */
4215 /* ss006.301 : optimized this funciton */
4219 #ifndef SS_DBUF_REFLOCK_DISABLE
4220 SDestroyLock(&dptr->dBufLock);
4222 /* if the data block is not shared, free the buffer, checks not reqd */
4223 #ifdef SS_HISTOGRAM_SUPPORT
4224 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4225 , __LINE__, (uint8_t*) __FILE__, ENTNC);
4227 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4228 #endif /* SS_HISTOGRAM_SUPPORT */
4232 #ifndef SS_DBUF_REFLOCK_DISABLE
4233 if((ret=SLock(&dptr->dBufLock)))
4235 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
4236 "Could not lock the mBuf Ref Lock");
4241 /* if buffer's message blk is obtained during dupb */
4242 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
4245 SsDblk* dupdptr = (SsDblk *)((uint8_t *)buf + MBSIZE);
4247 if(dupdptr->db_ref == 0)
4250 #ifdef SS_HISTOGRAM_SUPPORT
4251 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__, ENTNC);
4253 ret = SFree(region, (Data *) buf, MDBSIZE);
4255 #endif /* SS_HISTOGRAM_SUPPORT */
4257 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
4259 /* if reference count falls to zero */
4262 #ifndef SS_DBUF_REFLOCK_DISABLE
4263 ret = SUnlock(&dptr->dBufLock) ;
4264 if((SDestroyLock(&dptr->dBufLock)) != 0)
4267 printf("\nFalied to destroy lock\n");
4271 /* free buffer to region */
4272 #ifdef SS_HISTOGRAM_SUPPORT
4273 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4274 , __LINE__, (uint8_t*) __FILE__, ENTNC);
4276 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4277 #endif /* SS_HISTOGRAM_SUPPORT */
4280 #ifndef SS_DBUF_REFLOCK_DISABLE
4281 ret = SUnlock(&(dptr->dBufLock));
4284 #else /* SS_MULTICORE_SUPPORT */
4285 /* If MultiCore Support enabled, Dblk never be shared */
4286 #ifdef SS_HISTOGRAM_SUPPORT
4287 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4288 , __LINE__, (uint8_t*) __FILE__, ENTNC);
4290 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4291 #endif /* SS_HISTOGRAM_SUPPORT */
4292 #endif /* SS_MULTICORE_SUPPORT */
4297 /* #ifdef SS_LOCKLESS_MEMORY */
4304 * Desc: This function will concatenate the two specified messages
4308 * RFAILED - failed, general (optional)
4310 * Notes: if order equal M1M2: all data attached to message 2 is
4311 * moved to the end of message 1. message 2 is set to empty.
4312 * message 1 length is increased by length of message 2.
4313 * message 2 length is set to zero. message 2 is not returned
4314 * to memory. return is ok.
4316 * if order equal M2M1: all data attached to message 2 is
4317 * moved to the front of message 1. message 2 is set to empty.
4318 * message 1 length is increased by length of message 2.
4319 * message 2 length is set to zero. message 2 is not returned
4320 * to memory. return is ok.
4329 Buffer *mBuf1, /* message 1 */
4330 Buffer *mBuf2, /* message 2 */
4339 #if (ERRCLASS & ERRCLS_INT_PAR)
4340 /* check message buffer 1 */
4343 SSLOGERROR(ERRCLS_INT_PAR, ESS148, ERRZERO, "SCatMsg : Null Buffer");
4346 /* check message buffer 2 */
4349 SSLOGERROR(ERRCLS_INT_PAR, ESS149, ERRZERO, "SCatMsg : Null Buffer");
4352 /* ss021.103 - Addition to test if same buffer */
4353 /* check message buffer 1 and 2 not same buffer */
4356 SSLOGERROR(ERRCLS_INT_PAR, ESS150, ERRZERO, "SCatMsg : mBuf1 == mBuf2");
4359 if ((order != M1M2) && (order != M2M1))
4361 SSLOGERROR(ERRCLS_INT_PAR, ESS151, ERRZERO, "SCatMsg : Invalid Order");
4364 if ((mBuf1->b_datap->db_type != SS_M_PROTO) ||
4365 (mBuf2->b_datap->db_type != SS_M_PROTO))
4367 SSLOGERROR(ERRCLS_INT_PAR, ESS152, ERRZERO,
4368 "SCatMsg : Incorrect buffer type");
4373 /* no data to append or prepend */
4377 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
4378 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
4380 /* ss021.103 - Addition to test max length of message is not exceeded */
4381 #if (ERRCLASS & ERRCLS_INT_PAR)
4383 if (minfo1->len > 0x7FFFFFFF - minfo2->len)
4385 if (minfo1->len > 0x7FFF - minfo2->len)
4388 SSLOGERROR(ERRCLS_INT_PAR, ESS153, ERRZERO, "SCpyFixMsg : messages too big");
4393 if (minfo1->region != minfo2->region)
4395 /* duplicate mBuf2 from the region/pool of mBuf1, initialise mBuf2 */
4396 /*ss015.13: addition */
4397 if (SCpyMsgMsg(mBuf2, minfo1->region, minfo1->pool, &newb) != ROK)
4400 minfo2 = (SsMsgInfo*) newb->b_rptr;
4405 if ((tmp = mBuf1->b_cont) == NULLP)
4407 mBuf1->b_cont = newb->b_cont;
4408 minfo1->endptr = minfo2->endptr;
4413 /* attach newb after mBuf1 */
4415 minfo1->endptr->b_cont = newb->b_cont;
4416 minfo1->endptr = minfo2->endptr;
4421 /* attach newb before mBuf1 */
4423 minfo2->endptr->b_cont = mBuf1->b_cont;
4424 mBuf1->b_cont = newb->b_cont;
4426 else /* invalid order */
4428 #if (ERRCLASS & ERRCLS_DEBUG)
4429 SSLOGERROR(ERRCLS_DEBUG, ESS154, ERRZERO, "SCatMsg:Invalid order");
4431 if (newb && (newb != mBuf2))
4432 (Void) SPutMsg(newb);
4437 minfo1->len += minfo2->len;
4440 minfo2->endptr = NULLP;
4443 newb->b_cont = NULLP;
4447 (Void) SPutMsg(newb);
4448 (Void) SInitMsg(mBuf2);
4458 * Desc: This function replaces one byte of data in a message.
4461 * ROKDNA - ok, data not available
4462 * RFAILED - failed, general (optional)
4464 * Notes: index is 0 based and indicates location in message
4466 * if index is less than the length of the message:
4467 * data is replaced at specified index. message length
4468 * is unchanged. return is ok.
4470 * if index is greater than or equal to
4471 * the length of the message: message is unchanged.
4472 * return is ok, data not available.
4481 Data data, /* data */
4482 Buffer *mBuf, /* message buffer */
4493 #ifdef T2K_MEM_LEAK_DBG
4494 char* file = __FILE__;
4495 uint32_t line = __LINE__;
4497 #if ( ERRCLASS & ERRCLS_INT_PAR)
4498 /* check message buffer */
4501 SSLOGERROR(ERRCLS_INT_PAR, ESS155, ERRZERO, "SRepMsg : Null Buffer");
4506 SSLOGERROR(ERRCLS_INT_PAR, ESS156, ERRZERO, "SRepMsg : Invalid index");
4509 if (mBuf->b_datap->db_type != SS_M_PROTO)
4511 SSLOGERROR(ERRCLS_INT_PAR, ESS157, ERRZERO, "SRepMsg : Incorrect buffer\
4517 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4519 /* if index > length of the buffer */
4520 if (minfo->len <= idx)
4525 tmp = mBuf->b_cont; /* get the first SS_M_DATA blk */
4526 prev = mBuf; /* parent */
4528 FIND_OFFSET_AND_PREV(prev, tmp, idx)
4530 /* if ref cnt is greater than 1, duplicate tmp */
4531 if (tmp->b_datap->db_ref > 1)
4533 /* allocate a message blk of message size of tmp */
4534 numBytes = tmp->b_wptr - tmp->b_rptr;
4535 if (ssGetDBufOfSize(minfo->region, numBytes, &newb) != ROK)
4537 SSLOGERROR(ERRCLS_DEBUG, ESS158, ERRZERO, "SRepMsg : ssGetDBufOfSize\
4542 *newb->b_wptr++ = *tmp->b_rptr++;
4544 newb->b_cont = tmp->b_cont;
4545 prev->b_cont = newb;
4546 if (minfo->endptr == tmp)
4547 minfo->endptr = newb;
4550 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
4553 *(tmp->b_rptr + idx) = data;
4562 * Desc: Update a message with a new dBuf
4575 Buffer *mBuf, /* message buffer */
4576 Buffer *dBuf, /* data buffer */
4582 #if (ERRCLASS & ERRCLS_INT_PAR)
4585 SSLOGERROR(ERRCLS_INT_PAR, ESS159, ERRZERO, "SUpdMsg : Null Buffer");
4590 SSLOGERROR(ERRCLS_INT_PAR, ESS160, ERRZERO, "SUpdMsg : Null Buffer");
4595 SSLOGERROR(ERRCLS_INT_PAR, ESS161, ERRZERO, "SUpdMsg : Invalid length");
4598 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4599 (dBuf->b_datap->db_type != SS_M_DATA))
4601 SSLOGERROR(ERRCLS_INT_PAR, ESS162, ERRZERO, "SUpdMsg : Incorrect buffer\
4607 /* get the message info of mBuf */
4608 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4610 /* accept zero length data */
4612 /* buffer offset out of bounds */
4613 if ((dBuf->b_rptr + dLen) > dBuf->b_datap->db_lim)
4615 SSLOGERROR(ERRCLS_DEBUG, ESS163, ERRZERO, "SUpdMsg:Offset out of bounds");
4619 /* offset write ptr from read ptr by dLen */
4620 dBuf->b_wptr = dBuf->b_rptr + dLen;
4622 /* attach dBuf at the end of mBuf */
4624 minfo->endptr->b_cont = dBuf;
4626 mBuf->b_cont = dBuf;
4628 /* update SsMsgInfo */
4629 minfo->endptr = dBuf;
4640 * Desc: This function queues a data buffer to the
4641 * back of the specified message buffer .
4644 * RFAILED - failed, general (optional)
4646 * Notes: if queue is empty: buffer is placed in the queue.
4647 * queue length is incremented.
4649 * if queue is not empty: buffer is placed behind all
4650 * other buffers in queue. queue length is incremented.
4659 Buffer *mBuf, /* message buffer */
4665 #if (ERRCLASS & ERRCLS_INT_PAR)
4666 /* check buffer queue */
4669 SSLOGERROR(ERRCLS_INT_PAR, ESS164, ERRZERO, "SAddDBufPst : Null Buffer");
4672 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4673 (dBuf->b_datap->db_type != SS_M_DATA))
4675 SSLOGERROR(ERRCLS_INT_PAR, ESS165, ERRZERO, "SAddDBufPst : Incorrect\
4681 /* no data, return */
4682 if (dBuf->b_wptr == dBuf->b_rptr)
4685 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4687 /* attach dBuf at the end of mBuf */
4689 minfo->endptr->b_cont = dBuf;
4691 mBuf->b_cont = dBuf;
4693 /* update SsMsgInfo */
4694 minfo->endptr = dBuf;
4696 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
4705 * Desc: This function queues a data buffer to the
4706 * front of the specified message buffer.
4709 * RFAILED - failed, general (optional)
4711 * Notes: if buffer queue is empty: buffer is placed in the queue. queue
4712 * length is incremented.
4714 * if buffer queue is not empty: buffer is placed in front of all
4715 * other buffers in queue. queue length is incremented.
4724 Buffer *mBuf, /* message buffer */
4731 #if (ERRCLASS & ERRCLS_INT_PAR)
4732 /* check buffer queue */
4735 SSLOGERROR(ERRCLS_INT_PAR, ESS166, ERRZERO, "SAddDBufPre : Null Buffer");
4738 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4739 (dBuf->b_datap->db_type != SS_M_DATA))
4741 SSLOGERROR(ERRCLS_INT_PAR, ESS167, ERRZERO, "SAddDBufPre : Incorrect\
4747 /* no data, return */
4748 if (dBuf->b_wptr == dBuf->b_rptr)
4751 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4755 /* attach dBuf at the start of mBuf */
4756 mBuf->b_cont = dBuf;
4759 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
4762 minfo->endptr = dBuf;
4771 * Desc: This function dequeues a data buffer from
4772 * the front of the specified message buffer.
4775 * ROKDNA - ok, data not available
4776 * RFAILED - failed, general (optional)
4778 * Notes: if queue is empty: pointer to buffer is set to null and
4779 * return is ok, data not available. queue length is unchanged.
4781 * if queue is not empty: pointer to buffer is set to first
4782 * buffer in queue, first buffer in queue is removed and
4783 * return is ok. queue length is decremented.
4792 Buffer *mBuf, /* message buffer */
4798 #if (ERRCLASS & ERRCLS_INT_PAR)
4799 /* check buffer pointer */
4800 if (dBufPtr == NULLP)
4802 SSLOGERROR(ERRCLS_INT_PAR, ESS168, ERRZERO, "SRemDBufPre : Null Buffer");
4808 SSLOGERROR(ERRCLS_INT_PAR, ESS169, ERRZERO, "SRemDBufPre : Null Buffer");
4811 if (mBuf->b_datap->db_type != SS_M_PROTO)
4813 SSLOGERROR(ERRCLS_INT_PAR, ESS170, ERRZERO, "SRemDBufPre : Incorrect\
4819 /* no data blk, return */
4820 if ((*dBufPtr = mBuf->b_cont) == NULLP)
4824 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4826 mBuf->b_cont = (*dBufPtr)->b_cont;
4827 (*dBufPtr)->b_cont = NULLP;
4829 /* update SsMsgInfo */
4830 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
4831 minfo->endptr = NULLP;
4840 * Desc: This function dequeues a data or message buffer from the
4841 * back of the specified message buffer.
4844 * ROKDNA - ok, data not available
4845 * RFAILED - failed, general (optional)
4847 * Notes: if queue is empty: pointer to buffer is set to null and
4848 * return is ok, data not available. queue length is unchanged.
4850 * if queue is not empty: pointer to buffer is set to last
4851 * buffer in queue, last buffer in queue is removed and
4852 * return is ok. queue length is decremented.
4861 Buffer *mBuf, /* message buffer */
4868 #if (ERRCLASS & ERRCLS_INT_PAR)
4869 /* check buffer pointer */
4872 SSLOGERROR(ERRCLS_INT_PAR, ESS171, ERRZERO, "SRemDBufPst : Null Buffer");
4878 SSLOGERROR(ERRCLS_INT_PAR, ESS172, ERRZERO, "SRemDBufPst : Null Buffer");
4881 if (mBuf->b_datap->db_type != SS_M_PROTO)
4883 SSLOGERROR(ERRCLS_INT_PAR, ESS173, ERRZERO, "SRemDBufPst : Incorrect\
4889 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4891 /* no data blk, return */
4892 if ((*dBufPtr = minfo->endptr) == NULLP)
4896 for (tmp = mBuf; tmp->b_cont != (*dBufPtr); )
4899 tmp->b_cont = NULLP;
4901 /* update SsMsgInfo */
4902 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
4903 minfo->endptr = NULLP;
4905 minfo->endptr = tmp;
4914 * Desc: Initialize next Data Buffer Id
4918 * Notes: Must be called prior to SGetNxtDBuf
4932 #if (ERRCLASS & ERRCLS_INT_PAR)
4935 SSLOGERROR(ERRCLS_INT_PAR, ESS174, ERRZERO, "SInitNxtDBuf : Null Buffer");
4938 if (mBuf->b_datap->db_type != SS_M_PROTO)
4940 SSLOGERROR(ERRCLS_INT_PAR, ESS175, ERRZERO, "SInitNxtDBuf : Incorrect\
4946 minfo = (SsMsgInfo*) mBuf->b_rptr;
4948 /* set the next ptr of mBuf to point to the first SS_M_DATA blk */
4949 minfo->next = mBuf->b_cont;
4958 * Desc: Get next dBuf in message chain
4962 * Notes: Must be called after SInitNxtDBuf
4971 Buffer *mBuf, /* message buffer */
4977 #if (ERRCLASS & ERRCLS_INT_PAR)
4980 SSLOGERROR(ERRCLS_INT_PAR, ESS176, ERRZERO, "SGetNxtDBuf : Null Buffer");
4985 SSLOGERROR(ERRCLS_INT_PAR, ESS177, ERRZERO, "SGetNxtDBuf : Null Buffer");
4988 if (mBuf->b_datap->db_type != SS_M_PROTO)
4990 SSLOGERROR(ERRCLS_INT_PAR, ESS178, ERRZERO, "SGetNxtDBuf : Incorrect\
4996 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4998 /* if next ptr of mBuf is NULLP, return */
4999 if ((*dBuf = minfo->next) == NULLP)
5003 minfo->next = (*dBuf)->b_cont;
5012 * Desc: check if next data buffer exists.
5014 * Ret: ROK/ROKDNA/RFAILED
5016 * Notes: doesn't modify nxtDBuf
5029 #if (ERRCLASS & ERRCLS_INT_PAR)
5032 SSLOGERROR(ERRCLS_INT_PAR, ESS179, ERRZERO, "SChkNxtDBuf : Null Buffer");
5035 if (mBuf->b_datap->db_type != SS_M_PROTO)
5037 SSLOGERROR(ERRCLS_INT_PAR, ESS180, ERRZERO, "SChkNxtDBuf : Incorrect\
5041 #endif /* ERRCLASS */
5043 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5045 /* if next is valid, return ROK */
5056 * Desc: Given a data buffer, return a pointer to the
5057 * data payload, and the length of the payload
5063 * Notes: This assumes an uninitialized dBuf
5072 Buffer *dBuf, /* data buffer */
5073 MsgLen pad, /* pad */
5074 Data **retDatPtr, /* return data pointer */
5079 #if (ERRCLASS & ERRCLS_INT_PAR)
5082 SSLOGERROR(ERRCLS_INT_PAR, ESS181, ERRZERO, "SGetDataRx : Null Buffer");
5085 if (!retDatLen || (pad < 0))
5087 SSLOGERROR(ERRCLS_INT_PAR, ESS182, ERRZERO, "SGetDataRx : Null Buffer");
5092 SSLOGERROR(ERRCLS_INT_PAR, ESS183, ERRZERO, "SGetDataRx : Null Buffer");
5095 if (dBuf->b_datap->db_type != SS_M_DATA)
5097 SSLOGERROR(ERRCLS_INT_PAR, ESS184, ERRZERO, "SGetDataRx : Incorrect\
5101 #endif /* ERRCLASS */
5103 if (dBuf->b_datap->db_ref > 1) /* cannot write to a shared buffer */
5105 #if (ERRCLASS & ERRCLS_DEBUG)
5106 SSLOGERROR(ERRCLS_DEBUG, ESS185, ERRZERO, "SGetDataRx : Reference\
5112 /* return the write ptr loc(with padding) if there is data to write to */
5113 if ((*retDatLen = (dBuf->b_datap->db_lim - dBuf->b_wptr - pad)) > 0)
5114 *retDatPtr = dBuf->b_wptr + pad;
5118 #if (ERRCLASS & ERRCLS_DEBUG)
5119 SSLOGERROR(ERRCLS_DEBUG, ESS186, ERRZERO, "SGetDataRx:No data available");
5131 * Desc: Given a data buffer, return a pointer to the
5132 * data payload, and the length of the payload
5138 * Notes: This assumes an initialized dBuf
5147 Buffer *dBuf, /* data buffer */
5148 Data **retDatPtr, /* return data pointer */
5149 MsgLen *retDatLen /* return data length */
5153 #if (ERRCLASS & ERRCLS_INT_PAR)
5154 /* ss021.103 - Modification to check parameters */
5157 SSLOGERROR(ERRCLS_INT_PAR, ESS187, ERRZERO, "SGetDataTx : Null Buffer");
5162 SSLOGERROR(ERRCLS_INT_PAR, ESS188, ERRZERO, "SGetDataTx : Null Buffer");
5163 *retDatPtr = (Data *)NULLP;
5168 SSLOGERROR(ERRCLS_INT_PAR, ESS189, ERRZERO, "SGetDataTx : Null Buffer");
5171 if (dBuf->b_datap->db_type != SS_M_DATA)
5173 SSLOGERROR(ERRCLS_INT_PAR, ESS190, ERRZERO, "SGetDataTx : Incorrect\
5175 *retDatPtr = (Data *)NULLP;
5178 #endif /* ERRCLASS */
5180 /* if there is data, return read ptr */
5181 if ((*retDatLen = dBuf->b_wptr - dBuf->b_rptr))
5182 *retDatPtr = dBuf->b_rptr;
5186 #if (ERRCLASS & ERRCLS_DEBUG)
5187 SSLOGERROR(ERRCLS_DEBUG, ESS191, ERRZERO, "SGetDataTx : Buffer empty");
5195 #ifndef SS_ENABLE_MACROS
5199 * Fun: SGetBufRegionPool
5201 * Desc: returns the region and pool of the message buffer
5203 * Ret: ROK on success
5211 S16 SGetBufRegionPool
5213 Buffer *mBuf, /* message buffer */
5214 Region *region, /* region */
5215 Pool *pool /* pool */
5218 SsMsgInfo *mInfo; /* message info pointer */
5221 #if (ERRCLASS & ERRCLS_INT_PAR)
5225 SSLOGERROR(ERRCLS_INT_PAR, ESS192, ERRZERO,
5226 "SGetBufRegionPool : Null Buffer");
5229 if ((region == NULLP) && (pool == NULLP))
5231 SSLOGERROR(ERRCLS_INT_PAR, ESS193, ERRZERO,
5232 "SGetBufRegionPool : Null region and pool pointers");
5235 if (mBuf->b_datap->db_type != SS_M_PROTO)
5237 SSLOGERROR(ERRCLS_INT_PAR, ESS194, ERRZERO,
5238 "SUpdMsg : Incorrect buffer type");
5241 #endif /* (ERRCLASS & ERRCLS_INT_PAR */
5243 /* get message info of mBuf */
5244 if ((mInfo = (SsMsgInfo *) mBuf->b_rptr) == NULLP)
5246 #if (ERRCLASS & ERRCLS_DEBUG)
5247 SSLOGERROR(ERRCLS_DEBUG, ESS195, ERRZERO,
5248 "SGetBufRegionPool : mBuf's control data is null");
5253 if (region != NULLP)
5254 *region = mInfo->region;
5256 *pool = mInfo->pool;
5259 } /* end of SGetBufRegionPool */
5261 #endif /* SS_ENABLE_MACROS */
5267 * Desc: This function is used to compress a message into
5268 * the minimum number of data buffers needed.
5271 * RFAILED - failed, general (optional)
5272 * ROUTRES - failed, out of resources (optional)
5293 #ifdef T2K_MEM_LEAK_DBG
5294 char* file = __FILE__;
5295 uint32_t line = __LINE__;
5298 #if (ERRCLASS & ERRCLS_INT_PAR)
5301 SSLOGERROR(ERRCLS_INT_PAR, ESS196, ERRZERO, "SCompressMsg : Null Buffer");
5304 if (mBuf->b_datap->db_type != SS_M_PROTO)
5306 SSLOGERROR(ERRCLS_INT_PAR, ESS197, ERRZERO, "SCompressMsg : Incorrect\
5312 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5314 if ((tmp = mBuf->b_cont) == minfo->endptr)
5319 /* allocate a data buffer of size bytes*/
5320 if ((ret = ssGetDBufOfSize(minfo->region, minfo->len, &dBuf)) != ROK)
5322 SSLOGERROR(ERRCLS_DEBUG, ESS198, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
5326 dBuf->b_datap->db_type = SS_M_DATA;
5330 /* determine number of bytes to be copied */
5331 numBytes = tmp->b_wptr - tmp->b_rptr;
5335 /* ss002.13: addition */
5336 /* ss003.13: addition */
5337 SMemCpy( (Void *)dBuf->b_wptr, (Void *)tmp->b_rptr, (size_t)numBytes);
5339 dBuf->b_wptr += numBytes;
5340 tmp->b_rptr += numBytes;
5344 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
5347 /* update mBuf and SsMsgInfo */
5348 mBuf->b_cont = dBuf;
5349 minfo->endptr = dBuf;
5358 * Desc: This function prints the contents of a message. The
5359 * following information is printed: queue length,
5360 * message length, direction, hexadecimal and ASCII
5361 * (if appropriate) values of all bytes in the message.
5363 * This function should be used for debugging only.
5375 Buffer *mBuf, /* message buffer */
5376 S16 src, /* source id */
5377 S16 dst /* destination id */
5380 QLen qlen =0; /* queue length */
5381 MsgLen mlen =0; /* message length */
5385 /* ss038.103 : 102061 Changed to MsgLen from S16 */
5386 MsgLen i =0; /* counter */
5387 S16 j =0; /* counter */
5388 S16 k =0; /* counter */
5389 uint8_t data =0; /* data */
5390 uint8_t tdata[16] = {0}; /* temporary data */
5391 S8 prntBuf[256] ={0}; /* print buffer */
5392 Buffer *tmp = NULLP; /* buffer ptr */
5394 /* ss012.13: Addition */
5401 sprintf(prntBuf,"\nmsg: empty\n");
5403 SPrint( (S8*)"\n\n");
5407 for (qlen = 0, tmp = mBuf->b_cont; tmp; qlen++)
5409 mlen = ((SsMsgInfo*)(mBuf->b_rptr))->len;
5410 reg = ((SsMsgInfo*)(mBuf->b_rptr))->region;
5411 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
5413 sprintf(prntBuf,"\nmsg: qlen: %04d mlen: %04d %02d-->%02d region: %02d\n",
5414 (uint16_t)qlen,(uint16_t)mlen,src,dst,reg);
5416 #ifdef XEON_SPECIFIC_CHANGES
5417 printf("%s\n", prntBuf);
5419 SPrint((S8*) "dat: ");
5420 #ifdef XEON_SPECIFIC_CHANGES
5427 sprintf(prntBuf," empty\n");
5429 SPrint( (S8*)"\n\n");
5439 for( j = 0; j < 16; j++)
5445 sprintf( prntBuf,"%02x ",(uint16_t) data);
5448 #ifdef XEON_SPECIFIC_CHANGES
5449 printf("%s\n", prntBuf);
5452 if (cptr == tmp->b_wptr)
5458 /* ss024.103 - Modification to fix bug */
5465 sprintf( prntBuf," ");
5468 #ifdef XEON_SPECIFIC_CHANGES
5469 printf("%s\n", prntBuf);
5474 for (k = 0; k < 16; k++)
5476 if( (i >= mlen) && (k>=(mlen%16)) && mlen%16 != 0)
5478 if (AIsAscii(tdata[k]))
5480 /* print character if printable */
5481 sprintf(prntBuf,"%c",tdata[k]);
5484 #ifdef XEON_SPECIFIC_CHANGES
5485 printf("%s\n", prntBuf);
5491 /* print . if non printable */
5494 #ifdef XEON_SPECIFIC_CHANGES
5500 sprintf(prntBuf,"\n ");
5503 #ifdef XEON_SPECIFIC_CHANGES
5504 printf("%s\n", prntBuf);
5510 } /* end of SPrntMsg */
5516 * Fun: SGetPstMsgMult
5518 * Desc: This function allocates consecutive bytes of data at the
5522 * RFAILED - failed, general (optional)
5523 * ROUTRES - failed, out of resources (optional)
5525 * Notes: if message is empty: message length is incremented.
5528 * if message is not empty: space is allocated in back of
5529 * all other data in message. message length is incremented.
5537 MsgLen cnt, /* count */
5538 Buffer *mBuf /* message buffer */
5548 #if ( ERRCLASS & ERRCLS_INT_PAR )
5549 /* check message buffer */
5559 if (mBuf->b_datap->db_type != SS_M_PROTO)
5564 /* get the message info */
5565 minfo = (SsMsgInfo *) (mBuf->b_rptr);
5570 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
5571 ((avail = tmp->b_datap->db_lim - tmp->b_wptr)))
5573 numBytes = MIN(cnt, avail);
5576 minfo->len += numBytes;
5579 /* ss002.13 addition */
5580 /* ss003.13 addition */
5581 SMemSet( (Void *)tmp->b_wptr, (Data)'\0', (size_t)numBytes);
5583 tmp->b_wptr += numBytes;
5587 if (ssGetDBufOfSize(minfo->region, cnt, &newb) != ROK)
5589 /* ss027.103 - Modification to fix bug in SGetPstMsgMult */
5590 if ((avail) && (tmp))
5591 tmp->b_wptr = tmp->b_datap->db_lim - avail;
5592 minfo->len -= avail;
5599 /* ss002.13: addition */
5600 /* ss003.13: addition */
5601 SMemSet( (Void *)newb->b_wptr, (Data)'\0', (size_t)cnt);
5603 newb->b_wptr += cnt;
5609 mBuf->b_cont = newb;
5611 minfo->endptr = newb;
5620 * Desc: Check Message
5622 * Ret: ROK on success
5625 * Notes: Check that the first buffer in a message
5626 * contains at least two bytes. This check is required
5627 * by 68302/68360 processors to insure accurate fisu
5642 #if ( ERRCLASS & ERRCLS_INT_PAR )
5643 /* check message buffer */
5648 if (mBuf->b_datap->db_type != SS_M_PROTO)
5653 /* get the message info */
5654 minfo = (SsMsgInfo *) (mBuf->b_rptr);
5659 /* get the first M_DATA blk*/
5662 if (((tmp->b_rptr + 2) <= tmp->b_wptr) || (SCompressMsg(mBuf) == ROK))
5670 * Fun: SAlignDBufEven
5672 * Desc: align data portion of a data buffer on an even
5677 * Notes: required for SS7 microcode on the 68302
5684 Buffer *dBuf /* data buffer */
5690 #if (ERRCLASS & ERRCLS_INT_PAR)
5693 SSLOGERROR(ERRCLS_INT_PAR, ESS199, ERRZERO, "SAlignDBufEven : Null\
5697 if (dBuf->b_datap->db_type != SS_M_DATA)
5699 SSLOGERROR(ERRCLS_INT_PAR, ESS200, ERRZERO, "SAlignDBufEven : Incorrect\
5706 /* ss008.13: addition */
5707 if (!((PTR)src % (PTR)2))
5710 if (dBuf->b_datap->db_ref > 1)
5713 len = dBuf->b_wptr - dBuf->b_rptr;
5715 if (dBuf->b_datap->db_base < dBuf->b_rptr)
5717 dBuf->b_wptr = --dBuf->b_rptr;
5719 *dBuf->b_wptr++ = *src++;
5722 if (dBuf->b_datap->db_lim > dBuf->b_wptr)
5724 src = dBuf->b_wptr - 1;
5725 dBuf->b_rptr = ++dBuf->b_wptr;
5727 *--dBuf->b_rptr = *src--;
5735 /* ss004.13: addition */
5740 * Desc: Align data portion of a data buffer on the specified
5741 * boundary. No restriction is imposed on the alignment.
5745 * Notes: required by drivers (68360, 860)
5752 Buffer *dBuf, /* data buffer */
5753 uint32_t align /* alignemnt required */
5758 uint32_t upShift; /* no. of bytes to be shifted up */
5759 uint32_t downShift; /* no. of bytes to be shifted down */
5761 #if (ERRCLASS & ERRCLS_INT_PAR)
5764 SSLOGERROR(ERRCLS_INT_PAR, ESS201, ERRZERO, "SAlignDBuf: Null\
5768 if (dBuf->b_datap->db_type != SS_M_DATA)
5770 SSLOGERROR(ERRCLS_INT_PAR, ESS202, ERRZERO, "SAlignDBuf: Incorrect\
5777 /* ss008.13: addition */
5778 upShift = (PTR)src % (PTR)align; /* no. of bytes by which to shift up
5779 * the read and write pointers */
5784 if (dBuf->b_datap->db_ref > 1)
5787 downShift = align - upShift; /* no of bytes by which to shift down
5788 * the read and write pointers */
5789 len = dBuf->b_wptr - dBuf->b_rptr;
5791 if (dBuf->b_datap->db_base <= (dBuf->b_rptr - upShift))
5793 /* there is space to shift up the read and write pointers */
5795 dBuf->b_rptr -= upShift; /* align the read pointer */
5796 dBuf->b_wptr = dBuf->b_rptr;
5797 SMemCpy( (Void *) dBuf->b_wptr, (Void *) src, (size_t) len);
5798 dBuf->b_wptr = dBuf->b_wptr + len;
5802 if (dBuf->b_datap->db_lim > dBuf->b_wptr + downShift)
5804 src = dBuf->b_wptr - 1;
5805 dBuf->b_wptr = dBuf->b_wptr + downShift;
5806 dBuf->b_rptr = dBuf->b_wptr;
5808 *--dBuf->b_rptr = *src--;
5822 * Desc: Allocates a static buffer pool within the specified
5826 * RFAILED - failed, general (optional)
5828 * Notes: The new memory management scheme makes this function
5829 * meaningless. It merely sets the pool ID to zero and
5837 Region region, /* region ID */
5838 Size size, /* size */
5839 Pool *pool /* pointer to pool ID */
5846 #if (ERRCLASS & ERRCLS_INT_PAR)
5847 /* validate region ID */
5848 if (region >= SS_MAX_REGS)
5850 SSLOGERROR(ERRCLS_INT_PAR, ESS203, region, "Invalid region");
5854 /* validate pointer to pool ID */
5857 SSLOGERROR(ERRCLS_INT_PAR, ESS204, region, "Null pointer");
5863 /* set the pool ID to zero and return success */
5875 * Desc: Deallocates a static buffer pool within the specified
5879 * RFAILED - failed, general (optional)
5881 * Notes: The new memory management scheme makes this function
5882 * meaningless. It does nothing.
5889 Region region, /* region ID */
5890 Pool pool /* pool ID */
5893 /* ss021.103 - Addition of return value */
5894 #if (ERRCLASS & ERRCLS_INT_PAR)
5899 #if (ERRCLASS & ERRCLS_INT_PAR)
5900 /* validate region ID */
5901 if (region >= SS_MAX_REGS)
5903 SSLOGERROR(ERRCLS_INT_PAR, ESS205, region, "Invalid region");
5907 /* validate pool ID */
5908 if (pool >= SS_MAX_POOLS_PER_REG)
5910 SSLOGERROR(ERRCLS_INT_PAR, ESS206, region, "Invalid pool");
5914 /* ss021.103 - Addition to check if region is registered */
5915 /* acquire one semaphore, to protect against deregistration */
5916 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
5920 #if (ERRCLASS & ERRCLS_DEBUG)
5921 SSLOGERROR(ERRCLS_DEBUG, ESS207, (ErrVal) ret,
5922 "Could not lock region table");
5929 #if (ERRCLASS & ERRCLS_INT_PAR)
5930 /* verify that this region is present */
5931 if (osCp.regionTbl[region].used == FALSE)
5933 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
5935 #if (ERRCLASS & ERRCLS_DEBUG)
5936 SSLOGERROR(ERRCLS_DEBUG, ESS208, ERRZERO,
5937 "Could not release semaphore");
5942 SSLOGERROR(ERRCLS_INT_PAR, ESS209, region, "Region not registered");
5947 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
5949 #if (ERRCLASS & ERRCLS_DEBUG)
5950 SSLOGERROR(ERRCLS_DEBUG, ESS210, ERRZERO,
5951 "Could not release semaphore");
5965 * Desc: Checks the available system resources (memory).
5968 * RFAILED - failed, general (optional)
5977 Region region, /* region ID */
5978 Pool pool, /* pool ID */
5979 Status *status /* pointer to status */
5987 #if (ERRCLASS & ERRCLS_INT_PAR)
5988 /* validate region ID */
5989 if (region >= SS_MAX_REGS)
5991 SSLOGERROR(ERRCLS_INT_PAR, ESS229, region, "Invalid region");
5995 /* validate pool ID */
5996 if (pool >= SS_MAX_POOLS_PER_REG)
5998 SSLOGERROR(ERRCLS_INT_PAR, ESS230, region, "Invalid pool");
6002 /* validate status pointer */
6003 if (status == NULLP)
6005 SSLOGERROR(ERRCLS_INT_PAR, ESS231, ERRZERO, "Null pointer");
6009 /* ss037.103 Removed the semaphore operation for performance enhancement */
6012 /* acquire one semaphore, to protect against deregistration */
6013 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
6017 #if (ERRCLASS & ERRCLS_DEBUG)
6018 SSLOGERROR(ERRCLS_DEBUG, ESS232, (ErrVal) ret,
6019 "Could not lock region table");
6026 #if (ERRCLASS & ERRCLS_INT_PAR)
6027 /* verify that this region is around */
6028 if (osCp.regionTbl[region].used == FALSE)
6031 /* ss006.13: addition */
6032 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6034 #if (ERRCLASS & ERRCLS_DEBUG)
6035 SSLOGERROR(ERRCLS_DEBUG, ESS233, ERRZERO,
6036 "Could not release semaphore");
6041 SSLOGERROR(ERRCLS_INT_PAR, ESS234, region, "Region not registered");
6045 /* verify that this is a valid pool */
6046 if (osCp.regionTbl[region].poolTbl[pool].type != SS_POOL_DYNAMIC)
6048 SSLOGERROR(ERRCLS_DEBUG, ESS235, ERRZERO, "Invalid pool");
6054 /* call the memory manager to check resources */
6055 mctl.op = SS_MEM_CHK_RES;
6056 mctl.u.chkres.size = osCp.regionTbl[region].poolTbl[pool].u.dpool.size;
6057 mctl.u.chkres.status = status;
6058 ret = (osCp.regionTbl[region].ctl)
6059 (osCp.regionTbl[region].regCb, SS_MEM_CHK_RES, &mctl);
6061 /* release the semaphore we took */
6063 /* ss006.13: addition */
6064 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6066 #if (ERRCLASS & ERRCLS_DEBUG)
6067 SSLOGERROR(ERRCLS_DEBUG, ESS236, ERRZERO,
6068 "Could not release semaphore");
6081 * Desc: This function will swap two message data contents.
6082 * The original mBuf pointers are unchanged.
6096 Buffer *mBuf1, /* message 1 */
6097 Buffer *mBuf2 /* message 2 */
6102 #if (ERRCLASS & ERRCLS_INT_PAR)
6110 #if (ERRCLASS & ERRCLS_INT_PAR)
6111 /* check message buffer 1 */
6114 SSLOGERROR(ERRCLS_INT_PAR, ESS237, ERRZERO, "SSwapMsg : Null Buffer");
6117 /* check message buffer 2 */
6120 SSLOGERROR(ERRCLS_INT_PAR, ESS238, ERRZERO, "SSwapMsg : Null Buffer");
6123 if (mBuf1->b_datap->db_type != SS_M_PROTO)
6125 SSLOGERROR(ERRCLS_INT_PAR, ESS239, ERRZERO, "SSwapMsg: Incorrect buffer\
6129 if (mBuf2->b_datap->db_type != SS_M_PROTO)
6131 SSLOGERROR(ERRCLS_INT_PAR, ESS240, ERRZERO, "SSwapMsg: Incorrect buffer\
6135 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
6136 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
6137 if (minfo1->region != minfo2->region)
6139 SSLOGERROR(ERRCLS_INT_PAR, ESS241, ERRZERO, "SSwapMsg: differnt regions\
6146 tmp = mBuf1->b_next;
6147 mBuf1->b_next = mBuf2->b_next;
6148 mBuf2->b_next = tmp;
6150 tmp = mBuf1->b_prev;
6151 mBuf1->b_prev = mBuf2->b_prev;
6152 mBuf2->b_prev = tmp;
6154 tmp = mBuf1->b_cont;
6155 mBuf1->b_cont = mBuf2->b_cont;
6156 mBuf2->b_cont = tmp;
6159 #ifdef SS_DBLK_FREE_RTN
6160 tmp = (Buffer *) mBuf1->b_datap->db_frtnp;
6161 mBuf1->b_datap->db_frtnp = mBuf2->b_datap->db_frtnp;
6162 mBuf2->b_datap->db_frtnp = (struct ssfree_rtn *) tmp;
6165 tmp2 = mBuf1->b_datap->db_ref;
6166 mBuf1->b_datap->db_ref = mBuf2->b_datap->db_ref;
6167 mBuf2->b_datap->db_ref = tmp2;
6172 SMemCpy((Void *) minfop, (Void *) (mBuf1->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6173 SMemCpy((Void *) (mBuf1->b_datap->db_base), (Void *) (mBuf2->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6174 SMemCpy((Void *) (mBuf2->b_datap->db_base), (Void *) minfop, (size_t)(sizeof(SsMsgInfo)));
6178 /* ss004.301 : Cavium changes */
6179 #ifdef SS_SEUM_CAVIUM
6185 * Desc: This function will converts the pointer to
6189 * RFAILED - failed, general (optional)
6191 * Notes: Function to convert the Pointer (Virtual address) to
6192 * Physical Address. This will take the Buffer type as
6193 * input and will convert all pointer associated with
6194 * that to Physical Address
6207 SsMsgInfo *minfoPtr;
6212 /* check mBuf for NULLP */
6213 if ( (mBuf == NULLP) || (*mBuf == NULLP ) )
6218 /* first block in Buffer is head */
6220 nextPtr = curPtr->b_cont;
6222 /* Get the physical address of the Pointer */
6225 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6230 curPtr->b_next = (Buffer*)cvmx_ptr_to_phys (curPtr->b_next);
6235 curPtr->b_prev = (Buffer*)cvmx_ptr_to_phys (curPtr->b_prev);
6238 /* Convert the pointers of Minfo to Physical addr */
6239 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6241 if (minfoPtr->endptr)
6243 minfoPtr->endptr = (Buffer*)cvmx_ptr_to_phys (minfoPtr->endptr);
6247 minfoPtr->next = (Buffer*)cvmx_ptr_to_phys (minfoPtr->next);
6250 curPtr->b_rptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_rptr);
6252 curPtr->b_wptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_wptr);
6254 /* Convert the pointers of Dblock to Physical addr */
6255 dblkPtr = (SsDblk*)curPtr->b_datap;
6258 #ifdef SS_DBLK_FREE_RTN
6259 frtnPtr = dblkPtr->db_frtnp;
6260 if( frtnPtr != NULLP)
6262 if (frtnPtr->free_func)
6264 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6266 if (frtnPtr->free_arg)
6268 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6271 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6275 dblkPtr->db_base = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_base);
6276 dblkPtr->db_lim = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6278 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6280 /* second block onwards is dblk */
6285 nextPtr = curPtr->b_cont;
6287 /* Get the physical address of the Pointer */
6290 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6293 curPtr->b_rptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_rptr);
6294 curPtr->b_wptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_wptr);
6296 /* Convert the pointers of Dblock to Physical addr */
6297 dblkPtr = (SsDblk*)curPtr->b_datap;
6300 #ifdef SS_DBLK_FREE_RTN
6301 frtnPtr = dblkPtr->db_frtnp;
6302 if( frtnPtr != NULLP)
6304 if (frtnPtr->free_func)
6306 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6308 if (frtnPtr->free_arg)
6310 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6313 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6317 dblkPtr->db_base = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_base);
6318 dblkPtr->db_lim = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6320 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6326 *mBuf = (Buffer*)cvmx_ptr_to_phys (*mBuf);
6336 * Desc: This function will converts the physical address
6339 * Ret: On Success - Pointer to converted buffer
6340 * On Failuer - Returns NULL
6342 * Notes: Function to Convert the Physical address to Pointer
6343 * (Virtual address) This will take work buffer as input
6344 * and will convert all address associated with that to
6358 SsMsgInfo *minfoPtr;
6363 /* check workPtr for NULLP */
6364 if ( (workPtr == NULLP) || (*workPtr == NULLP) )
6369 /* Convert the buffer address to pointer */
6370 mBuf = (Buffer*)cvmx_phys_to_ptr ((uint64_t)(*workPtr));
6374 /* first block is mblk */
6377 curPtr->b_next = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_next);
6382 curPtr->b_prev = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_prev);
6387 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_cont);
6390 curPtr->b_rptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_rptr);
6392 /* Get the pointer for minfo */
6393 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6395 if (minfoPtr->endptr)
6397 minfoPtr->endptr = (Buffer*)cvmx_phys_to_ptr ((uint64_t)minfoPtr->endptr);
6401 minfoPtr->next = (Buffer*)cvmx_phys_to_ptr ((uint64_t)minfoPtr->next);
6404 curPtr->b_wptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_wptr);
6406 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_datap);
6408 /* Get the Dblock pointers */
6409 dblkPtr = (SsDblk*)curPtr->b_datap;
6412 #ifdef SS_DBLK_FREE_RTN
6413 if (dblkPtr->db_frtnp)
6415 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_frtnp);
6416 frtnPtr = dblkPtr->db_frtnp;
6418 if (frtnPtr->free_func)
6420 frtnPtr->free_func = cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_func);
6422 if (frtnPtr->free_arg)
6424 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_arg);
6429 dblkPtr->db_base = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_base);
6430 dblkPtr->db_lim = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_lim);
6432 curPtr = curPtr->b_cont;
6434 /* after the first block is dblk */
6439 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_cont);
6442 curPtr->b_rptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_rptr);
6444 curPtr->b_wptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_wptr);
6446 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_datap);
6448 /* Get the Dblock pointers */
6449 dblkPtr = (SsDblk*)curPtr->b_datap;
6452 #ifdef SS_DBLK_FREE_RTN
6453 if (dblkPtr->db_frtnp)
6455 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_frtnp);
6457 frtnPtr = dblkPtr->db_frtnp;
6459 if (frtnPtr->free_func)
6461 frtnPtr->free_func = cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_func);
6463 if (frtnPtr->free_arg)
6465 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_arg);
6470 dblkPtr->db_base = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_base);
6471 dblkPtr->db_lim = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_lim);
6473 curPtr = curPtr->b_cont;
6476 /* Place the converted buffer */
6487 * Desc: This function will copy the message from FPA region
6490 * Ret: On Success - ROK
6491 * On Failuer - RFAILED
6493 * Notes: Function to copy the message from FPA region to
6494 * other region. This will internally allocates the
6495 * memory for the destination buffer and copies the
6496 * message in the same chain list
6513 Buffer *curPtr = NULLP;
6515 Buffer *tmpblk = NULLP;
6516 Buffer *newblk = NULLP;
6517 Buffer *prevblk = NULLP;
6518 SsMsgInfo *minfoSrc = NULLP;
6519 SsMsgInfo *minfoDst = NULLP;
6520 SsDblk *dblkPtr = NULLP;
6521 SsDblk *dptr = NULLP;
6524 if ( srcBuf == (Buffer*)NULLP )
6529 if ((dstRegion >= SS_MAX_REGS) || (dstPool >= SS_MAX_POOLS_PER_REG))
6531 /* Free the source buffer and return failure */
6536 /* Allocate memory for destination buffer */
6537 if(SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
6539 /* Free the source buffer and return failure */
6544 /* get the minfo of dest and src buffers */
6545 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
6546 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
6548 curPtr = srcBuf->b_cont;
6550 /* Copy all the blocks associated with this Buffer */
6553 /* Allocate the memeory for dblock */
6555 dblkPtr = (SsDblk*)curPtr->b_datap;
6556 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
6557 size = numBytes + MDBSIZE;
6559 ret = SAlloc( dstRegion, &size, 0, (Data**)&tmpblk);
6563 /* Free all allocated buffers before returning */
6566 tmpblk = newblk->b_cont;
6567 (Void) SPutDBuf(dstRegion, dstPool, newblk);
6570 (Void) SPutMsg(*dstBuf);
6571 /* Free the source buffer and return failure */
6576 dat = (Data *)tmpblk + MDBSIZE;
6577 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
6580 /* Initialize the pointer and copy the data */
6581 INITB( tmpblk, dptr, dat, size, NULLP );
6582 #ifndef SS_DBUF_REFLOCK_DISABLE
6583 SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX);
6585 numBytes = curPtr->b_wptr - curPtr->b_rptr;
6586 /* Copy the data part if its present */
6589 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
6590 tmpblk->b_wptr += numBytes;
6599 prevblk->b_cont = tmpblk;
6603 curPtr = curPtr->b_cont;
6608 tmpblk->b_cont = NULLP;
6611 *minfoDst = *minfoSrc;
6612 minfoDst->region = 0;
6614 minfoDst->len = minfoSrc->len;
6615 minfoDst->endptr = tmpblk;
6616 minfoDst->next = NULLP;
6618 (*dstBuf)->b_cont = newblk;
6620 /* Free the source buffer after copying it */
6631 * Desc: This function will copy the message from any region
6634 * Ret: On Success - ROK
6635 * On Failuer - RFAILED
6637 * Notes: Function will copy the mbuf from msg to FPA.
6638 * This function allocates the memory internally
6639 * and copies the message to newly allocated mBuf.
6640 * The size of mBuf should be either of one
6641 * pre-difined sizes otherwise mBuf is dopped.
6653 Buffer *curPtr = NULLP;
6655 Buffer *tmpblk = NULLP;
6656 Buffer *prevblk = NULLP;
6657 Buffer *newblk = NULLP;
6658 SsMsgInfo *minfoSrc = NULLP;
6659 SsMsgInfo *minfoDst = NULLP;
6660 SsDblk *dblkPtr = NULLP;
6661 SsDblk *dptr = NULLP;
6666 if (srcBuf == (Buffer*)NULLP)
6671 *dstBuf = (Buffer*)cvmx_fpa_alloc(SS_CVMX_POOL_0);
6673 if ( *dstBuf == NULLP )
6675 /* Free the source buffer before returning */
6680 dat = (Data *)(*dstBuf) + MDBSIZE;
6681 dptr = (SsDblk*) ((Data *)(*dstBuf) + MBSIZE);
6682 numBytes = SS_CVMX_POOL_0_SIZE - MDBSIZE;
6684 /* Initialize the pointers of new block */
6685 INITB((*dstBuf), dptr, dat, numBytes, NULLP);
6687 (*dstBuf)->b_datap->db_type = SS_M_PROTO;
6688 (*dstBuf)->b_wptr = (*dstBuf)->b_rptr + sizeof(SsMsgInfo);
6690 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
6691 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
6692 curPtr = srcBuf->b_cont;
6696 dblkPtr = (SsDblk*)curPtr->b_datap;
6698 /* Get the size required which is to be allocated */
6699 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
6700 numBytes += MDBSIZE;
6702 /* get the pool depending on the size need to be allocated */
6705 case SS_CVMX_POOL_0_SIZE:
6707 pool = SS_CVMX_POOL_0;
6710 case SS_CVMX_POOL_1_SIZE:
6712 pool = SS_CVMX_POOL_1;
6715 case SS_CVMX_POOL_2_SIZE:
6717 pool = SS_CVMX_POOL_2;
6720 case SS_CVMX_POOL_3_SIZE:
6722 pool = SS_CVMX_POOL_3;
6726 /* size doesn't match, drop the mBuf and returning
6728 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SCpyMsgFpa: Invalid\
6729 buffer size, dropping the message");
6731 (*dstBuf)->b_cont = newblk;
6732 SPutFpaMsg(*dstBuf);
6733 /* Free the source buffer before returning */
6738 /* Allocate for mBuf and copy both the header and contents */
6739 tmpblk = (Buffer*)cvmx_fpa_alloc(pool);
6741 if ( tmpblk == NULLP )
6743 /* Return error if fails to allocate memory */
6745 (*dstBuf)->b_cont = newblk;
6746 SPutFpaMsg(*dstBuf);
6747 /* Free the source buffer before returning */
6752 dat = (Data *)tmpblk + MDBSIZE;
6753 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
6754 numBytes -= MDBSIZE;
6756 /* Initialize the pointers of new block */
6757 INITB( tmpblk, dptr, dat, numBytes, NULLP );
6759 numBytes = curPtr->b_wptr - curPtr->b_rptr;
6760 /* Copy the message contents */
6763 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
6764 tmpblk->b_wptr += numBytes;
6767 /* Add the mew mBuf to the Buffer chain */
6774 prevblk->b_cont = tmpblk;
6778 /* Get the next block */
6779 curPtr = curPtr->b_cont;
6782 /* Initialize the last mBuf */
6785 tmpblk->b_cont = NULLP;
6788 *minfoDst = *minfoSrc;
6789 minfoDst->region = 0;
6791 minfoDst->len = minfoSrc->len;
6792 minfoDst->endptr = tmpblk;
6793 minfoDst->next = NULLP;
6795 (*dstBuf)->b_cont = newblk;
6797 /* Free the source buffer after copying it */
6808 * Desc: This function will free the Buffer associated with
6811 * Ret: On Success - ROK
6812 * On Failuer - RFAILED
6814 * Notes: Function free the all buffer associated with wqBuf
6815 * This will get the pool id by the size of the buffer
6816 * and same will be used to free the buffer.
6832 if( fpaBuf == NULLP )
6837 curBlk = fpaBuf->b_cont;
6841 nextBlk = curBlk->b_cont;
6843 dblkPtr = (SsDblk*)curBlk->b_datap;
6845 size = dblkPtr->db_lim - dblkPtr->db_base + MDBSIZE;
6847 /* Free the dblock according to its size */
6850 case SS_CVMX_POOL_0_SIZE:
6851 cvmx_fpa_free(curBlk, SS_CVMX_POOL_0, 0);
6854 case SS_CVMX_POOL_1_SIZE:
6855 cvmx_fpa_free(curBlk, SS_CVMX_POOL_1, 0);
6858 case SS_CVMX_POOL_2_SIZE:
6859 cvmx_fpa_free(curBlk, SS_CVMX_POOL_2, 0);
6862 case SS_CVMX_POOL_3_SIZE:
6863 cvmx_fpa_free(curBlk, SS_CVMX_POOL_3, 0);
6867 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SPutFpaMsg: Invalid\
6868 buffer size, dropping the message");
6875 cvmx_fpa_free(fpaBuf, SS_CVMX_POOL_0, 0);
6881 #endif /* SS_SEUM_CAVIUM */
6883 /* ss006.301 : new buffer management APIs, start */
6888 * Desc: This function is used to copy a portion of message(srcBuf) into
6889 * another msg(dstBuf)
6892 * RFAILED - failed, general (optional)
6893 * ROUTRES - failed, out of resources (optional) - In this case
6894 * caller shall reclaim the resources allocated for dstBuf.
6920 #if (ERRCLASS & ERRCLS_INT_PAR)
6923 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null src Buffer");
6926 if (srcBuf->b_datap->db_type != SS_M_PROTO)
6928 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
6934 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null dst Buffer");
6937 if (dstBuf->b_datap->db_type != SS_M_PROTO)
6939 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
6943 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
6945 /* if index > length of mBuf, return */
6946 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
6947 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
6949 if (idx >= sMinfo->len)
6951 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
6956 sBuf = srcBuf->b_cont;
6957 FIND_OFFSET(sBuf, idx)
6961 dBuf = (dMinfo->endptr) ? (dMinfo->endptr) : (dstBuf->b_cont);
6965 crnt = dPrev->b_cont;
6969 crnt = crnt->b_cont;
6976 sCnt = sBuf->b_wptr - (sBuf->b_rptr + idx);
6979 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
6983 /* allocate a data buffer */
6984 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
6986 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyPartMsg : SGetDBuf\
6990 dCnt = MIN(cnt, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
6991 dPrev->b_cont = dBuf;
6994 if(sCnt > cnt) /* src Dblk has enough data to copy */
6998 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7000 dBuf->b_wptr += dCnt;
7001 dBuf = dBuf->b_cont;
7007 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), cnt);
7008 dBuf->b_wptr += cnt;
7009 dBuf->b_cont = NULLP;
7015 else /* src dBlk has partial data to be copied */
7019 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7020 dBuf->b_wptr += dCnt;
7021 dBuf = dBuf->b_cont;
7028 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), sCnt);
7029 dBuf->b_wptr += sCnt;
7031 sBuf = sBuf->b_cont;
7037 /* update the msgLen in dstBuf */
7038 dMinfo->len += numCpd;
7039 dMinfo->endptr = dBuf;
7048 * Desc: This function is used to replace a portion of message(mBuf) with the
7052 * RFAILED - failed, general (optional)
7078 #if (ERRCLASS & ERRCLS_INT_PAR)
7081 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null dstBuf");
7084 if (dstBuf->b_datap->db_type != SS_M_PROTO)
7086 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7087 dstBuf buffer type");
7092 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null Src Buffer ");
7095 if (srcBuf->b_datap->db_type != SS_M_PROTO)
7097 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7101 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
7103 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
7104 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
7106 if(((idx + cnt) > dMinfo->len) || (cnt < sMinfo->len))
7108 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7113 dBuf = dstBuf->b_cont;
7114 FIND_OFFSET(dBuf, idx)
7115 sBuf = srcBuf->b_cont;
7117 while(cnt && dBuf && sBuf)
7119 dCnt = (dBuf->b_wptr - (dBuf->b_rptr + idx));
7120 sCnt = sBuf->b_wptr - (sBuf->b_rptr + sIdx);
7121 cpBytes = MIN(cnt, sCnt);
7122 cpBytes = MIN(cpBytes, dCnt);
7123 SMemCpy((void*)(dBuf->b_rptr + idx), (void*)(sBuf->b_rptr + sIdx), cpBytes);
7129 /* move to next DBlk in srcBuf */
7130 sBuf = sBuf->b_cont;
7134 else /* cpBytes equals dCnt */
7136 /* move to the next DBlk in dstBuf */
7137 dBuf = dBuf->b_cont;
7151 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : unable to replace\
7163 * Desc: This function will move a portion of the first msg to second msg
7166 * ROKDNA - ok, data not available
7167 * RFAILED - failed, general (optional)
7168 * ROUTRES - failed, out of resources (optional)
7170 * Notes: message 1 is the message from which the segment will be copied
7172 * message 2 is the updated message.
7174 * index is 0 based and indicates location in message 1
7175 * up to which the data will be copied to message 2
7177 * if index is equal to 0, message 1 will not be changed and no data
7178 shall be copied to message 2.
7179 * message 1 is not returned to memory. return is ok.
7181 * if index is not equal to 0 and less than the length of
7182 * the message minus 1: data upto index, shall be copied to message 2
7183 * and read/write pointers of message 1 will be updated accordingly
7185 * if index is not equal to 0 and greater than or equal to
7186 * the length of the message minus 1: all of the message 1 data.
7187 * shall be copied to message 2. return is ok.
7196 Buffer *srcBuf, /* message 1 */
7197 MsgLen idx, /* index */
7198 Buffer *dstBuf /* message 2 */
7208 #ifdef T2K_MEM_LEAK_DBG
7209 char* file = __FILE__;
7210 uint32_t line = __LINE__;
7214 #if (ERRCLASS & ERRCLS_INT_PAR)
7215 /* check message buffer 1 */
7216 if ((!srcBuf) || (!dstBuf ))
7218 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SMovPartMsg : Null Buffer (src or Dst)");
7223 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SMovPartMsg : Invalid index");
7226 if ((srcBuf->b_datap->db_type != SS_M_PROTO) || (dstBuf->b_datap->db_type != SS_M_PROTO))
7228 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SMovPartMsg : Incorrect buffer\
7234 /* get the SsMsgInfo of srcBuf */
7235 sMinfo = (SsMsgInfo*) srcBuf->b_rptr;
7237 /* get the SsMsgInfo of dstBuf */
7238 dMinfo = (SsMsgInfo*) dstBuf->b_rptr;
7240 /* if index > length of mBuf, return */
7242 if (idx > sMinfo->len)
7247 /* one block might not sufficient - Check for generic implementation */
7248 sBuf = srcBuf->b_cont;
7249 /* dBuf = dMinfo->endptr; */
7250 dPrev = (dBuf = dMinfo->endptr) ? dBuf : dstBuf;
7252 /* adjust the lengths of srcBuf, dstBuf */
7258 sCnt = sBuf->b_wptr - sBuf->b_rptr;
7261 /* allocate a data buffer */
7262 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
7264 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyMsgPartMsg : SGetDBuf\
7268 dCnt = MIN(idx, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
7269 dPrev->b_cont = dBuf;
7274 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
7276 if(sCnt > idx) /* src Dblk has enough data to copy */
7280 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7281 dBuf->b_wptr += dCnt;
7282 dBuf = dBuf->b_cont;
7284 sBuf->b_rptr += dCnt;
7288 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), idx);
7289 dBuf->b_wptr += idx;
7290 dBuf->b_cont = NULLP;
7291 sBuf->b_rptr += idx;
7296 else /* src dBlk has partial data to be copied */
7300 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7301 dBuf->b_wptr += dCnt;
7302 dBuf = dBuf->b_cont;
7304 sBuf->b_rptr += dCnt;
7309 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), sCnt);
7310 dBuf->b_wptr += sCnt;
7312 /* deallocate the sBuf here */
7314 /* printf("\nSMovPartMsg() sBuf is completely copied sBuf->b_cont(%p)\n", sBuf->b_cont); */
7315 (Void)SPutDBuf(sMinfo->region, sMinfo->pool, sBuf);
7316 srcBuf->b_cont = sBuf = tmp;
7320 dMinfo->endptr = dBuf;
7325 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SMovPartMsg : unable to copy\
7337 * Desc: This function copies consecutive bytes of data to the
7338 * beginning of a message.
7341 * RFAILED - failed, general (optional)
7342 * ROUTRES - failed, out of resources (optional)
7344 * Notes: if message is empty: data is placed in the message. message
7345 * length is incremented. return is ok.
7347 * if message is not empty: data is read by source pointer,
7348 * data is placed in front of all other data in message.
7349 * message length is incremented. return is ok.
7351 * the first byte of data pointed to by the source pointer
7352 * will be placed at the front of the message first (i.e. it
7353 * will become the first byte of the message) and the last
7354 * byte will be placed in front of the existing msg contents,
7355 * i.e. order of the source is preserved.
7368 SsMsgInfo *minfo; /* Message info */
7371 MsgLen numBytes; /* no. of bytes to be copied */
7375 #if (ERRCLASS & ERRCLS_INT_PAR)
7376 /* check message buffer */
7379 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SPkMsgMult:Null Buffer");
7385 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SPkMsgMult:Null Buffer");
7391 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SPkMsgMult: Invalid\
7395 if (mBuf->b_datap->db_type != SS_M_PROTO)
7397 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SPkMsgMult: Incorrect\
7403 /* get the SsMsgInfo of mBuf */
7404 minfo = (SsMsgInfo*) mBuf->b_rptr;
7406 /* ss014.13: Addition */
7409 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
7410 (tmp->b_datap->db_base < tmp->b_rptr))
7412 /* store the offset of the read pointer of tmp */
7413 offset = tmp->b_rptr - tmp->b_datap->db_base;
7415 /* determine the number of bytes to copy */
7416 numBytes = MIN(cnt, offset);
7421 /* update the read ptr */
7422 tmp->b_rptr -= numBytes;
7424 memcpy(tmp->b_rptr, (src + cnt), numBytes);
7425 minfo->len += numBytes;
7432 /* allocate a DBlk minimum of size Cnt to pack the data */
7434 if (ssGetDBufOfSize(minfo->region, cnt, &newblk) != ROK)
7438 newblk->b_datap->db_type = SS_M_DATA;
7439 newblk->b_rptr = newblk->b_datap->db_lim - cnt;
7440 newblk->b_wptr = newblk->b_datap->db_lim;
7441 memcpy(newblk->b_rptr, src, cnt);
7442 /* attach the newblk chain into mBuf */
7443 newblk->b_cont = tmp;
7444 mBuf->b_cont = newblk;
7446 minfo->endptr = newblk;
7450 /* ss006.301 : new buffer management APIs, end */
7455 * Desc: This function retunrs the pointer to the read the message from mBuf
7458 * RFAILED - failed, general (optional)
7474 if (mBuf && mBuf->b_cont)
7476 *data = mBuf->b_cont->b_rptr;
7477 *len = ((SsMsgInfo*)(mBuf->b_rptr))->len;
7487 #ifdef SS_USE_ZBC_MEMORY
7490 * Fun: SAttachPtrToBuf
7492 * Desc: This function attaches the Pointer provided into a new
7493 * message buffer after allocating the same. It allocates
7494 * header (M-Block) and an additional dBuf (D-Block) and attaches
7495 * the provided pointer to it.
7498 * RFAILED - failed, general (optional)
7499 * ROUTRES - failed, out of resources (optional)
7507 #ifdef T2K_MEM_LEAK_DBG
7508 S16 SAttachPtrToBufNew
7529 SsMsgInfo *minfo; /* Message info */
7533 /* Void *iccHdlr; */
7536 #if (ERRCLASS & ERRCLS_INT_PAR)
7539 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
7544 #ifdef XEON_SPECIFIC_CHANGES
7547 if(SGetMsg(region, pool, mBuf) != ROK)
7549 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
7555 #ifdef SS_HISTOGRAM_SUPPORT
7556 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
7558 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
7559 #endif /* SS_HISTOGRAM_SUPPORT */
7561 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
7566 (*mBuf)->b_cont = newblk;
7568 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
7570 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
7573 newblk->b_datap->db_base = ptr;
7574 newblk->b_datap->db_lim = ptr + totalLen;
7575 newblk->b_rptr = newblk->b_datap->db_base;
7576 newblk->b_wptr = newblk->b_rptr + totalLen;
7578 #ifndef SS_DBUF_REFLOCK_DISABLE
7579 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
7582 printf("\nFalied to destroy lock\n");
7587 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
7589 /* get the SsMsgInfo of mBuf */
7590 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
7591 minfo->len = totalLen;
7592 minfo->endptr = newblk;
7601 * Desc: This function deallocates a buffer back to the
7602 * dynamic memory pool which is allocated for ZBC
7605 * RFAILED - failed, general (optional)
7613 #ifdef T2K_MEM_LEAK_DBG
7614 static S16 SPutZbcDBufNew
7622 static S16 SPutZbcDBuf
7629 register SsDblk *dptr;
7634 dptr = buf->b_datap;
7635 /* Get the length of the buffer */
7636 bufLen = buf->b_datap->db_lim - buf->b_datap->db_base;
7638 /* If the buffer is not shared, free the buffer */
7641 #ifndef SS_DBUF_REFLOCK_DISABLE
7642 SDestroyLock(&dptr->dBufLock);
7645 /* Free the ZBC buffer first and then free the block allocated for the
7648 #ifdef SS_HISTOGRAM_SUPPORT
7649 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
7650 (uint8_t*) __FILE__, ENTNC);
7652 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
7653 #endif /* SS_HISTOGRAM_SUPPORT */
7655 /* if the data block is not shared, free the buffer, checks not reqd */
7656 #ifdef SS_HISTOGRAM_SUPPORT
7657 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__,
7660 ret = SFree(region, (Data *) buf, MDBSIZE);
7661 #endif /* SS_HISTOGRAM_SUPPORT */
7663 /* If the buffer is shared, reduce the refernce count and free the buffer
7664 * if reference count falls to zero */
7667 #ifndef SS_DBUF_REFLOCK_DISABLE
7668 if((ret=SLock(&dptr->dBufLock)))
7670 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
7671 "Could not lock the mBuf Ref Lock");
7676 /* if buffer's message blk is obtained during dupb */
7677 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
7679 #ifdef SS_HISTOGRAM_SUPPORT
7680 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__, ENTNC);
7682 ret = SFree(region, (Data *) buf, MDBSIZE);
7683 #endif /* SS_HISTOGRAM_SUPPORT */
7684 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
7686 /* if reference count falls to zero */
7689 #ifndef SS_DBUF_REFLOCK_DISABLE
7690 ret = SUnlock(&dptr->dBufLock) ;
7691 if((SDestroyLock(&dptr->dBufLock)) != 0)
7694 printf("\nFalied to destroy lock\n");
7698 #ifdef SS_HISTOGRAM_SUPPORT
7699 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
7700 (uint8_t*) __FILE__, ENTNC);
7702 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
7703 #endif /* SS_HISTOGRAM_SUPPORT */
7705 #ifdef SS_HISTOGRAM_SUPPORT
7706 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__,
7709 ret = SFree(region, (Data *) buf, MDBSIZE);
7710 #endif /* SS_HISTOGRAM_SUPPORT */
7713 #ifndef SS_DBUF_REFLOCK_DISABLE
7714 ret = SUnlock(&(dptr->dBufLock));
7720 #endif /* SS_USE_ZBC_MEMORY */
7726 * Fun: SAttachPtrToMBuf
7728 * Desc: This function attaches the Pointer provided into a new
7729 * message buffer after allocating the same. It allocates
7730 * header (M-Block) and an additional dBuf (D-Block) and attaches
7731 * the provided pointer to it.
7734 * RFAILED - failed, general (optional)
7735 * ROUTRES - failed, out of resources (optional)
7742 #ifdef T2K_MEM_LEAK_DBG
7743 S16 SAttachPtrToMBuf1
7755 S16 SAttachPtrToMBuf
7766 SsMsgInfo *minfo; /* Message info */
7770 /* Void *iccHdlr; */
7773 #if (ERRCLASS & ERRCLS_INT_PAR)
7776 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
7781 if(SGetMsg(region, pool, mBuf) != ROK)
7783 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
7790 #ifdef SS_HISTOGRAM_SUPPORT
7791 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
7793 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
7794 #endif /* SS_HISTOGRAM_SUPPORT */
7796 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
7801 (*mBuf)->b_cont = newblk;
7803 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
7805 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
7808 newblk->b_datap->db_base = ptr;
7809 newblk->b_datap->db_lim = ptr + ptrLen;
7810 newblk->b_rptr = newblk->b_datap->db_base;
7811 newblk->b_wptr = newblk->b_rptr + totalLen;
7813 #ifndef SS_DBUF_REFLOCK_DISABLE
7814 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
7817 printf("\nFalied to destroy lock\n");
7822 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
7824 /* get the SsMsgInfo of mBuf */
7825 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
7826 minfo->len = totalLen;
7827 minfo->endptr = newblk;
7829 //printf("\nMbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
7832 #endif /* INTEL_WLS */
7833 S16 SIncMsgRef(Buffer *srcBuf,Region dstRegion, Pool dstPool,Buffer **dstBuf)
7836 return (SAddMsgRef(srcBuf,dstRegion, dstPool,dstBuf));
7843 Void SResetMBuf(Buffer *mbuf)
7849 minfo = (SsMsgInfo *) mbuf->b_rptr;
7850 //tmp = minfo->endptr;
7857 // printf("\nSResetMBuf The write & read ptr is %p %p %p %p \n", tmp->b_wptr, tmp->b_rptr, tmp->b_datap->db_base, tmp->b_datap->db_lim );
7858 // tmp->b_wptr = tmp->b_rptr = tmp->b_datap->db_base;
7859 tmp->b_wptr = tmp->b_rptr = (tmp->b_datap->db_base + 5);
7860 tmp->b_datap->db_ref = 1;
7861 tmp->b_datap->shared = 0;
7873 * Fun: SAttachWlsPtrToMBuf
7875 * Desc: This function attaches the Pointer provided into a new
7876 * message buffer after allocating the same. It allocates
7877 * header (M-Block) and an additional dBuf (D-Block) and attaches
7878 * the provided pointer to it.
7881 * RFAILED - failed, general (optional)
7882 * ROUTRES - failed, out of resources (optional)
7889 #ifdef T2K_MEM_LEAK_DBG
7890 S16 SAttachWlsPtrToMBuf1
7903 S16 SAttachWlsPtrToMBuf
7915 SsMsgInfo *minfo; /* Message info */
7919 /* Void *iccHdlr; */
7922 #if (ERRCLASS & ERRCLS_INT_PAR)
7925 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
7931 if(SGetMsg(region, pool, mBuf) != ROK)
7933 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
7939 #ifdef SS_HISTOGRAM_SUPPORT
7940 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
7942 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
7943 #endif /* SS_HISTOGRAM_SUPPORT */
7945 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
7950 (*mBuf)->b_cont = newblk;
7952 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
7954 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
7957 newblk->b_datap->db_base = ptr;
7958 newblk->b_datap->db_lim = ptr + ptrLen;
7959 newblk->b_rptr = readPtr;
7960 newblk->b_wptr = newblk->b_rptr + totalLen;
7962 #ifndef SS_DBUF_REFLOCK_DISABLE
7963 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
7966 printf("\nFalied to destroy lock\n");
7971 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
7973 /* get the SsMsgInfo of mBuf */
7974 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
7975 minfo->len = totalLen;
7976 minfo->endptr = newblk;
7978 //printf("\nMbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
7982 #ifdef TENB_DPDK_BUF
7988 Data **ptr, /* pointer to buffer */
7989 Size size /* size requested */
7994 *ptr = ntl_alloc(mtGetNtlHdl(), size);
8001 Data *ptr /* pointer to buffer */
8007 ntl_free(mtGetNtlHdl(), ptr);
8012 S16 SDetachDpdkPtrFrmDBuf
8022 //msgBlk = mBuf->b_cont;
8023 //*ptr = msgBlk->b_rptr;
8024 *ptr = mBuf->b_datap->db_base;
8026 mBuf->b_cont = NULL;
8028 //minfo = (SsMsgInfo*) mBuf->b_rptr;
8036 S16 SDetachDpdkPtrFrmMBuf
8045 register SsDblk *dptr;
8049 msgBlk = mBuf->b_cont;
8056 dptr = msgBlk->b_datap;
8057 if(dptr->db_type != SS_MEM_TYPE_DPDK_ZBC)
8063 *ptr = msgBlk->b_rptr;
8065 mBuf->b_cont = NULL;
8067 minfo = (SsMsgInfo*) mBuf->b_rptr;
8074 S16 SAttachDpdkPtrToMBuf
8091 SAttachWlsPtrToMBuf(region, pool, ptr, readPtr, msgLen, totalLen, mBuf);
8092 dptr = (SsDblk*) (((Data *) ((*mBuf)->b_cont)) + MBSIZE);
8094 dptr->db_type = SS_MEM_TYPE_DPDK_ZBC;
8099 #endif /* TENB_DPDK_BUF */
8101 #endif /* INTEL_WLS */
8103 /**********************************************************************
8105 **********************************************************************/