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)
652 printf("\n Not able to get region \n");
657 /* get the message info */
658 minfo = (SsMsgInfo *) mBuf->b_rptr;
660 while ((tmp = mBuf->b_cont))
662 /* set b_cont of mBuf to point to the b_cont of tmp */
663 mBuf->b_cont = tmp->b_cont;
664 #ifdef SS_MEM_WL_DEBUG
665 (Void) SPutDBuf(tmpThrReg, minfo->pool, tmp);
667 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
671 /* ss001.301: additions */
672 #ifdef SS_HISTOGRAM_SUPPORT
673 SGetEntInd(&entId, fileName);
674 #endif /* SS_HISTOGRAM_SUPPORT */
676 /* ss012.13: Addition */
677 #ifdef SS_M_PROTO_REGION
678 /* ss021.103 - Addition to check return value of SFree */
679 #ifdef SS_HISTOGRAM_SUPPORT
680 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE, line, fileName, entId) == RFAILED)
682 #ifdef SS_MEM_WL_DEBUG
683 if (SFree(tmpThrReg, (Data *) mBuf, MSGSIZE) == RFAILED)
685 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE) == RFAILED)
687 #endif /* SS_HISTOGRAM_SUPPORT */
689 #else /* SS_M_PROTO_REGION */
690 /* ss021.103 - Addition to check return value of SFree */
691 #ifdef SS_HISTOGRAM_SUPPORT
692 if (SFree(SS_DFLT_REGION, (Data *) mBuf, MSGSIZE, line, fileName, entId) == RFAILED)
694 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE) == RFAILED)
695 #endif /* SS_HISTOGRAM_SUPPORT */
697 #endif /* SS_M_PROTO_REGION */
702 #ifdef SS_LOCKLESS_MEMORY
705 * Fun: SPutStaticBuffer
707 * Desc: Returns a buffer to the specified static pool in the
708 * specified memory region.
711 * RFAILED - failed, general (optional)
718 /* ss001.301: additions */
719 #ifdef T2K_MEM_LEAK_DBG
720 S16 SPutStaticBufferNew
722 Region region, /* region ID */
723 Pool pool, /* pool ID */
724 Data *ptr, /* pointer to buffer */
725 Size size, /* size */
726 uint8_t memType, /* memory type used if shareable or not */
733 Region region, /* region ID */
734 Pool pool, /* pool ID */
735 Data *ptr, /* pointer to buffer */
736 Size size, /* size */
737 uint8_t memType /* memory type used if shareable or not */
743 #if (ERRCLASS & ERRCLS_INT_PAR)
744 /* validate region ID */
745 if (region >= SS_MAX_REGS)
747 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
751 /* validate pool ID */
752 if (pool >= SS_MAX_POOLS_PER_REG)
754 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
757 /* validate data pointer */
760 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
767 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
771 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
773 pthread_t gMacTId,gRlcTId;
775 if(clusterMode == RADIO_CLUSTER_MODE)
777 #ifdef MAC_FREE_RING_BUF
778 if(pthread_self() == gMacTId)
779 //if(pthread_equal(pthread_self(),gMacTId))
781 if(ROK == mtAddBufToRing(SS_RNG_BUF_MAC_FREE_RING,(Void *)ptr,1))
787 #ifdef RLC_FREE_RING_BUF
788 else if(pthread_self() == gRlcTId)
790 if(ROK == mtAddBufToRing(SS_RNG_BUF_RLC_FREE_RING,(Void *)ptr,1))
799 region = SS_GET_THREAD_MEM_REGION();
802 #if (ERRCLASS & ERRCLS_INT_PAR)
803 /* verify that this region is present */
804 if (((memType == SS_NON_SHARABLE_MEMORY) &&
805 (osCp.regionTbl[region].used == FALSE)) ||
806 ((memType == SS_SHARABLE_MEMORY) &&
807 (osCp.dynRegionTbl[region].used == FALSE)))
809 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
814 /* call the memory manager, to allocate this memory */
815 #ifndef SS_DBUF_REFLOCK_DISABLE
816 if(memType == SS_NON_SHARABLE_MEMORY)
818 #ifndef T2K_MEM_LEAK_DBG
819 ret = (osCp.regionTbl[region].free)
820 (osCp.regionTbl[region].regCb, ptr, size);
822 ret = (osCp.regionTbl[region].free)
823 (osCp.regionTbl[region].regCb, ptr, size, file, line);
827 else if(memType == SS_SHARABLE_MEMORY)
831 #ifndef T2K_MEM_LEAK_DBG
832 ret = (osCp.dynRegionTbl[region].free)
833 (osCp.dynRegionTbl[region].regCb, ptr, size);
835 ret = (osCp.dynRegionTbl[region].free)
836 (osCp.dynRegionTbl[region].regCb, ptr, size,file,line);
838 #ifndef SS_DBUF_REFLOCK_DISABLE
847 * Fun: SGetStaticBuffer
849 * Desc: Allocates a buffer from the specified static memory pool
850 * in the specified region. Depending on the type wheather
851 * the buffer is sharable or non-sharable indicated by the
852 * memType prameter allocation region is choosen
856 * RFAILED - failed, general (optional)
863 #ifdef T2K_MEM_LEAK_DBG
864 S16 SGetStaticBufferNew
866 Region region, /* region ID */
867 Pool pool, /* pool ID */
868 Data **ptr, /* pointer to buffer */
869 Size size, /* size requested */
870 uint8_t memType, /* memory type used if shareable or not */
877 Region region, /* region ID */
878 Pool pool, /* pool ID */
879 Data **ptr, /* pointer to buffer */
880 Size size, /* size requested */
881 uint8_t memType /* memory type used if shareable or not */
888 #if (ERRCLASS & ERRCLS_INT_PAR)
889 /* validate region ID */
890 if (region >= SS_MAX_REGS)
892 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
896 /* validate pool ID */
897 if (pool >= SS_MAX_POOLS_PER_REG)
899 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
902 /* validate data pointer */
905 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
912 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
917 #if (ERRCLASS & ERRCLS_INT_PAR)
918 /* verify that this region is present */
919 if (((memType == SS_NON_SHARABLE_MEMORY) &&
920 (osCp.regionTbl[region].used == FALSE)) ||
921 ((memType == SS_SHARABLE_MEMORY) &&
922 (osCp.dynRegionTbl[region].used == FALSE)))
924 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
931 region = SS_GET_THREAD_MEM_REGION();
933 if (region == SS_STATIC_REGION)
937 /* call the memory manager, to allocate this memory */
938 #ifndef SS_DBUF_REFLOCK_DISABLE
939 if(memType == SS_NON_SHARABLE_MEMORY)
941 #ifndef T2K_MEM_LEAK_DBG
942 ret = (osCp.regionTbl[region].alloc)
943 (osCp.regionTbl[region].regCb, &size, flags, ptr);
945 ret = (osCp.regionTbl[region].alloc)
946 (osCp.regionTbl[region].regCb, &size, flags, ptr, file,line);
949 else if(memType == SS_SHARABLE_MEMORY)
952 #ifndef T2K_MEM_LEAK_DBG
953 ret = (osCp.dynRegionTbl[region].alloc)
954 (osCp.dynRegionTbl[region].regCb, &size, flags, ptr);
956 ret = (osCp.dynRegionTbl[region].alloc)
957 (osCp.dynRegionTbl[region].regCb, &size, flags, ptr,file,line);
959 #ifndef SS_DBUF_REFLOCK_DISABLE
965 #endif /* SS_LOCKLESS_MEMORY */
968 #ifndef SS_LOCKLESS_MEMORY
971 Region region, /* region ID */
972 Pool pool, /* pool ID */
973 Data **ptr, /* pointer to buffer */
974 Size size, /* size requested */
975 uint8_t memType /* memory type used if shareable or not */
980 ret = SGetSBuf(region, pool, ptr, size);
988 Region region, /* region ID */
989 Pool pool, /* pool ID */
990 Data *ptr, /* pointer to buffer */
991 Size size, /* size */
992 uint8_t memType /* memory type used if shareable or not */
998 ret = SPutSBuf(region, pool, ptr, size);
1004 #ifdef T2K_MEM_LEAK_DBG
1007 Region region, /* region ID */
1008 Pool pool, /* pool ID */
1009 Data **ptr, /* pointer to buffer */
1010 Size size, /* size requested */
1017 Region region, /* region ID */
1018 Pool pool, /* pool ID */
1019 Data **ptr, /* pointer to buffer */
1020 Size size /* size requested */
1025 #ifndef SS_LOCKLESS_MEMORY
1029 #ifdef SS_LOCKLESS_MEMORY
1030 region = SS_GET_THREAD_MEM_REGION();
1031 ret = SAlloc(region, &size, 0, ptr);
1034 #ifdef T2K_MEM_LEAK_DBG
1035 ret = (osCp.regionTbl[region].alloc)
1036 (osCp.regionTbl[region].regCb, &size, flags, ptr,file,line);
1038 ret = (osCp.regionTbl[region].alloc)
1039 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1046 #ifdef T2K_MEM_LEAK_DBG
1049 Region region, /* region ID */
1050 Pool pool, /* pool ID */
1051 Data *ptr, /* pointer to buffer */
1052 Size size, /* size */
1059 Region region, /* region ID */
1060 Pool pool, /* pool ID */
1061 Data *ptr, /* pointer to buffer */
1062 Size size /* size */
1068 #ifdef SS_LOCKLESS_MEMORY
1069 region = SS_GET_THREAD_MEM_REGION();
1070 ret = SFree(region, ptr, size);
1073 #ifdef T2K_MEM_LEAK_DBG
1074 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,file,line);
1076 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1083 #endif /* INTEL_WLS */
1090 * Desc: Allocates a buffer from the specified static memory pool
1091 * in the specified region.
1094 * RFAILED - failed, general (optional)
1096 * Notes: The new memory management scheme eliminates the concept
1097 * of pools. This call maps directly to a call to the memory
1103 /* ss001.301: additions */
1104 #ifdef SS_HISTOGRAM_SUPPORT
1107 Region region, /* region ID */
1108 Pool pool, /* pool ID */
1109 Data **ptr, /* pointer to buffer */
1110 Size size, /* size requested */
1114 #else /* SS_HISTOGRAM_SUPPORT */
1115 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1118 Region region, /* region ID */
1119 Pool pool, /* pool ID */
1120 Data **ptr, /* pointer to buffer */
1121 Size size, /* size requested */
1128 Region region, /* region ID */
1129 Pool pool, /* pool ID */
1130 Data **ptr, /* pointer to buffer */
1131 Size size /* size requested */
1134 #endif /* SS_HISTOGRAM_SUPPORT */
1138 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1142 #ifdef SS_HISTOGRAM_SUPPORT
1144 Bool hstReg = FALSE;
1145 #endif /* SS_HISTOGRAM_SUPPORT */
1148 region = SS_GET_THREAD_MEM_REGION();
1151 #endif /* INTEL_WLS */
1153 #if (ERRCLASS & ERRCLS_INT_PAR)
1154 /* validate region ID */
1155 if (region >= SS_MAX_REGS)
1157 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
1161 /* validate pool ID */
1162 if (pool >= SS_MAX_POOLS_PER_REG)
1164 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
1167 /* ss008.13: addition */
1168 /* validate data pointer */
1171 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
1178 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
1182 /* ss037.103 Removed the semaphore operation for performance enhancement */
1184 #ifndef RGL_SPECIFIC_CHANGES
1185 region = SS_GET_THREAD_MEM_REGION();
1188 /* acquire one semaphore, to protect against deregistration */
1189 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1193 #if (ERRCLASS & ERRCLS_DEBUG)
1194 SSLOGERROR(ERRCLS_DEBUG, ESS216, (ErrVal) ret,
1195 "Could not lock region table");
1203 #if (ERRCLASS & ERRCLS_INT_PAR)
1204 /* verify that this region is present */
1205 if (osCp.regionTbl[region].used == FALSE)
1209 /* ss006.13: addition */
1210 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1212 #if (ERRCLASS & ERRCLS_DEBUG)
1213 SSLOGERROR(ERRCLS_DEBUG, ESS217, ERRZERO,
1214 "Could not release semaphore");
1219 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
1228 /* ss024.103 - Addition for memory calculator tool */
1230 if (region == SS_STATIC_REGION)
1234 /* ss001.301: additions */
1235 #ifdef SS_HISTOGRAM_SUPPORT
1237 SGetEntInd(&entId, fileName);
1238 /* Get the Information from the oscp that the tapa task with the entity
1239 id (entid) is registed for histogram or not */
1240 SGetHstGrmInfo(&entId, &hstReg);
1241 /* call the memory manager, to allocate this memory */
1242 #ifdef SSI_DEBUG_LEVEL1
1243 ret = (osCp.regionTbl[region].alloc)
1244 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1245 SS_STATIC_MEM_FLAG, line, fileName, entId, hstReg);
1247 ret = (osCp.regionTbl[region].alloc)
1248 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1249 line, fileName, entId, hstReg);
1250 #endif /* SSI_DEBUG_LEVEL1 */
1254 /* call the memory manager, to allocate this memory */
1255 /* ss036.103 - addition for passing additional parameter memType as static */
1256 #ifdef SSI_DEBUG_LEVEL1
1257 ret = (osCp.regionTbl[region].alloc)
1258 (osCp.regionTbl[region].regCb, &size, flags, ptr, SS_STATIC_MEM_FLAG);
1260 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1261 /* Static mem leak detection changes */
1263 #ifdef T2K_MEM_LEAK_DBG
1264 ret = (osCp.regionTbl[region].alloc)
1265 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr, file, line);
1267 ret = (osCp.regionTbl[region].alloc)
1268 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr);
1270 /*size = tmpSize - 4;*/
1272 /*printf("\nptr = %p *ptr = %p\n",ptr,*ptr);*/
1273 #ifdef XEON_SPECIFIC_CHANGES
1274 pthread_mutex_lock(&(memLock));
1276 uint32_t idx = GetNextFreeIdx(&SMemLeakInfo[region]);
1277 uint8_t* allocatedPtr = *ptr;
1278 void* actualPtr = allocatedPtr + 4;
1280 /* store the index in the memory allocated itself */
1281 /**((uint32_t*)*((uint32_t*)allocatedPtr)) = idx;*/
1282 *((uint32_t*)allocatedPtr) = idx;
1283 /*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));*/
1285 LogForStaticMemLeak(&SMemLeakInfo[region],
1291 #ifdef XEON_SPECIFIC_CHANGES
1292 pthread_mutex_unlock(&(memLock));
1296 #ifndef T2K_MEM_LEAK_DBG
1297 ret = (osCp.regionTbl[region].alloc)
1298 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1300 ret = (osCp.regionTbl[region].alloc)
1301 (osCp.regionTbl[region].regCb, &size, flags, ptr, file, line);
1305 #endif /* SSI_DEBUG_LEVEL1 */
1307 #endif /* SS_HISTOGRAM_SUPPORT */
1309 /* release the semaphore we took */
1312 /* ss006.13: addition */
1313 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1315 #if (ERRCLASS & ERRCLS_DEBUG)
1316 SSLOGERROR(ERRCLS_DEBUG, ESS219, ERRZERO,
1317 "Could not release semaphore");
1322 /* ss036.103 - Addition to handle the memory trampling return value
1323 * This in turn might invoke SRegMemErrHdlr
1325 #ifdef SSI_DEBUG_LEVEL1
1326 if (ret == RTRAMPLINGNOK)
1328 SRegMemErrHdlr( region, *ptr, ret);
1330 #endif /* SSI_DEBUG_LEVEL1 */
1340 * Desc: Returns a buffer to the specified static pool in the
1341 * specified memory region.
1344 * RFAILED - failed, general (optional)
1351 /* ss001.301: additions */
1352 #ifdef SS_HISTOGRAM_SUPPORT
1355 Region region, /* region ID */
1356 Pool pool, /* pool ID */
1357 Data *ptr, /* pointer to buffer */
1358 Size size, /* size */
1362 #else /* SS_HISTOGRAM_SUPPORT */
1363 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1366 Region region, /* region ID */
1367 Pool pool, /* pool ID */
1368 Data *ptr, /* pointer to buffer */
1369 Size size, /* size */
1376 Region region, /* region ID */
1377 Pool pool, /* pool ID */
1378 Data *ptr, /* pointer to buffer */
1379 Size size /* size */
1382 #endif /* SS_HISTOGRAM_SUPPORT */
1386 #ifdef SS_HISTOGRAM_SUPPORT
1388 Bool hstReg = FALSE;
1389 #endif /* SS_HISTOGRAM_SUPPORT */
1391 region = SS_GET_THREAD_MEM_REGION();
1392 #if (!defined(SS_LOCKLESS_MEMORY) && defined(INTEL_WLS))
1394 #endif /* INTEL_WLS */
1396 #if (ERRCLASS & ERRCLS_INT_PAR)
1397 /* validate region ID */
1398 if (region >= SS_MAX_REGS)
1400 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
1404 /* validate pool ID */
1405 if (pool >= SS_MAX_POOLS_PER_REG)
1407 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
1410 /* ss008.13: addition */
1411 /* validate data pointer */
1414 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
1421 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
1425 /* ss037.103 Removed the semaphore operation for performance enhancement */
1426 #ifndef RGL_SPECIFIC_CHANGES
1427 region = SS_GET_THREAD_MEM_REGION();
1430 /* acquire one semaphore, to protect against deregistration */
1431 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1435 #if (ERRCLASS & ERRCLS_DEBUG)
1436 SSLOGERROR(ERRCLS_DEBUG, ESS225, (ErrVal) ret,
1437 "Could not lock region table");
1444 #if (ERRCLASS & ERRCLS_INT_PAR)
1445 /* verify that this region is around */
1446 if (osCp.regionTbl[region].used == FALSE)
1450 /* ss006.13: addition */
1451 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1453 #if (ERRCLASS & ERRCLS_DEBUG)
1454 SSLOGERROR(ERRCLS_DEBUG, ESS226, ERRZERO,
1455 "Could not release semaphore");
1460 SSLOGERROR(ERRCLS_INT_PAR, ESS227, region, "Region not registered");
1465 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1466 /* Static mem leak detection changes */
1468 #ifdef XEON_SPECIFIC_CHANGES
1469 pthread_mutex_lock(&(memLock));
1471 uint32_t idx = *((uint32_t*)((uint8_t *)ptr - 4));
1472 FreeIdx(ptr,idx,&SMemLeakInfo[region],size,file,line);
1473 #ifdef XEON_SPECIFIC_CHANGES
1474 pthread_mutex_unlock(&(memLock));
1477 /* Static mem leak detection changes */
1480 /* ss001.301: additions */
1481 #ifdef SS_HISTOGRAM_SUPPORT
1482 SGetEntInd(&entId, fileName);
1483 /* Get the Information from the oscp that the tapa task with the entity
1484 id (entid) is registed for histogram or not */
1485 SGetHstGrmInfo(&entId, &hstReg);
1487 /* call the memory manager to free this memory */
1488 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,
1489 line, fileName, entId, hstReg);
1491 /* call the memory manager to free this memory */
1492 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1493 #ifdef T2K_MEM_LEAK_DBG
1494 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4, file, line);
1496 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4);
1499 #ifndef T2K_MEM_LEAK_DBG
1500 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1502 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size, file, line);
1505 #endif /* SS_HISTOGRAM_SUPPORT */
1506 /* ss037.103 Removed the semaphore operation for performance enhancement */
1509 /* release the semaphore we took */
1511 /* ss006.13: addition */
1512 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1514 #if (ERRCLASS & ERRCLS_DEBUG)
1515 SSLOGERROR(ERRCLS_DEBUG, ESS228, ERRZERO,
1516 "Could not release semaphore");
1521 /* ss036.103 - addition to handle double free and trampling return values
1522 * This might invoke SRegMemErrHdlr
1524 #ifdef SSI_DEBUG_LEVEL1
1525 /* handle the double free error here by calling the OS specific error handling function */
1526 if ((ret == RDBLFREE) || (ret == RTRAMPLINGNOK))
1528 SRegMemErrHdlr( region, ptr, ret);
1530 #endif /* SSI_DEBUG_LEVEL1 */
1540 * Desc: This function deallocates a message back and then
1541 * reinitializes the message.
1544 * RFAILED - failed, general (optional)
1546 * Notes: all data attached to message is returned to memory.
1547 * message is set to empty. message is not returned to
1548 * memory. return is ok.
1554 S16 SInitMsg(Buffer *mBuf)
1560 #if (ERRCLASS & ERRCLS_INT_PAR)
1561 /* check message buffer */
1564 SSLOGERROR(ERRCLS_INT_PAR, ESS062, ERRZERO, "SInitMsg: Null Buffer");
1567 if (mBuf->b_datap->db_type != SS_M_PROTO)
1569 SSLOGERROR(ERRCLS_INT_PAR, ESS063, ERRZERO, "SInitMsg: Incorrect buffer\
1575 /* get the message info */
1578 CM_MEM_GET_REGION(tmpRegId);
1579 if(tmpRegId == 0xFF)
1584 minfo = (SsMsgInfo*) mBuf->b_rptr;
1586 /* free all SS_M_DATA blks */
1587 while ((tmp = mBuf->b_cont))
1589 mBuf->b_cont = tmp->b_cont;
1592 #ifdef T2K_MEM_LEAK_DBG
1593 char * file = __FILE__;
1594 uint32_t line = __LINE__;
1597 (Void) SPutDBuf(tmpRegId, minfo->pool, tmp);
1599 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
1602 /* initialise the length and endptr variables of mBuf */
1605 minfo->endptr = NULLP;
1606 minfo->next = NULLP;
1611 /* ss016.301 - Added a new API - SAddPreMsgMultInOrder. This preserves the
1612 * byte order while adding the data bytes to the beginning of the message.
1616 * Fun: SAddPreMsgMultInOrder
1618 * Desc: This function copies consecutive bytes of data to the
1619 * beginning of a message and keeps the bytes order preserved.
1621 * Ret: ROK - Appended the bytes to the beginning of the message.
1622 * RFAILED - Failed to append the bytes.
1623 * ROUTRES - Out of resources - Possibly insufficient memory.
1625 * Notes: If the message is empty,data is placed in the message. Message
1626 * length is incremented. Return is ROK.
1628 * If the message is not empty,data is read by source pointer
1629 * and appended at the beginning of the message.
1630 * Message length is incremented. Return is ROK.
1635 S16 SAddPreMsgMultInOrder
1642 SsMsgInfo *minfo; /* Message info */
1644 Buffer *curblk=NULLP;
1647 MsgLen numBytes; /* no. of bytes to be copied */
1653 #if (ERRCLASS & ERRCLS_INT_PAR)
1654 /* check message buffer */
1657 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMultInOrder:\
1664 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMultInOrder:\
1671 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMultInOrder:\
1675 if (mBuf->b_datap->db_type != SS_M_PROTO)
1677 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMultInOrder:\
1678 Incorrect buffer type");
1683 /* get the SsMsgInfo of mBuf */
1684 minfo = (SsMsgInfo*) mBuf->b_rptr;
1685 #ifdef RGL_SPECIFIC_CHANGES
1689 /* store cnt in length */
1694 /* point to the end of the source buffer */
1695 revSrc = src + cnt ;
1697 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
1698 (tmp->b_datap->db_base < tmp->b_rptr))
1700 /* store the offset of the read pointer of tmp */
1701 offset = tmp->b_rptr - tmp->b_datap->db_base;
1703 /* determine the number of bytes to copy */
1704 numBytes = MIN(cnt, offset);
1706 /* traverse back from the end of the source buffer*/
1712 /* move the read pointer towards the left */
1713 tmp->b_rptr -= numBytes ;
1714 SMemCpy((Void *)(tmp->b_rptr ), (Void *) revSrc, (size_t) numBytes);
1722 newblk = prevblk = NULLP;
1725 /* allocate a message blk */
1726 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
1728 while ((curblk = prevblk))
1730 prevblk = prevblk->b_cont;
1731 #ifdef T2K_MEM_LEAK_DBG
1732 char * file = __FILE__;
1733 uint32_t line = __LINE__;
1736 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
1741 tmp->b_rptr = tmp->b_datap->db_base + offset;
1746 /* attach curblk in the newblk chain */
1749 curblk->b_cont = prevblk; /* stack them up */
1757 /* set the read and write pointers to the end of the data buffer */
1758 /* subsequent prepends have all the buffer to insert data into */
1759 curblk->b_wptr = curblk->b_datap->db_lim;
1760 rptr = curblk->b_datap->db_lim;
1763 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
1768 /* move the read pointer towards the left */
1771 /* traverse back the source buffer */
1774 SMemCpy((Void *)(rptr), (Void *) revSrc, (size_t) numBytes);
1776 curblk->b_rptr = rptr;
1779 /* attach the newblk chain into mBuf */
1780 newblk->b_cont = tmp;
1781 mBuf->b_cont = curblk;
1783 /* update endptr of mBuf */
1786 minfo->endptr = newblk;
1788 /* update length of message */
1797 * Desc: This function copies one byte of data to the
1798 * beginning of a message.
1801 * RFAILED - failed, general (optional)
1802 * ROUTRES - failed, out of resources (optional)
1804 * Notes: if message is empty: data is placed in the message. message
1805 * length is incremented. return is ok.
1807 * if message is not empty: data is placed in front of all
1808 * other data in message. message length is incremented.
1826 #if (ERRCLASS & ERRCLS_INT_PAR)
1827 /* check message buffer */
1830 SSLOGERROR(ERRCLS_INT_PAR, ESS064, ERRZERO, "SAddPreMsg: Null Buffer");
1833 if (mBuf->b_datap->db_type != SS_M_PROTO)
1835 SSLOGERROR(ERRCLS_INT_PAR, ESS065, ERRZERO, "SAddPreMsg: Incorrect\
1841 minfo = (SsMsgInfo *) mBuf->b_rptr;
1843 /* ss021.103 - Addition to check if exceeding maximum message length */
1845 if (minfo->len == 0x7FFFFFFF)
1847 if (minfo->len == 0x7FFF)
1854 * allocate a message blk using SGetDBuf(), if there are no data blks in the
1855 * message, mBuf, or if the reference count of the first data blk is greater
1856 * than 1, or if there is no space to append databytes in front of the read
1857 * pointer of the first data blk
1859 if (!(tmp = mBuf->b_cont) || (tmp->b_datap->db_ref > 1) ||
1860 (tmp->b_rptr == tmp->b_datap->db_base))
1862 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
1864 SSLOGERROR(ERRCLS_DEBUG, ESS066, ERRZERO, "SAddPreMsg:Failed in\
1868 /* set the read and write pointers to end of data buffer */
1869 /* subsequent prepends have all the buffer to insert data into */
1870 newb->b_wptr = newb->b_datap->db_lim;
1871 newb->b_rptr = newb->b_datap->db_lim;
1873 /* insert newb before tmp */
1874 newb -> b_cont = tmp;
1875 mBuf->b_cont = newb;
1877 /* if endptr of mBuf is NULLP, set it to newb */
1879 minfo->endptr = newb;
1882 /* insert data, increment length */
1883 *--tmp->b_rptr = data;
1893 * Desc: This function copies one byte of data to the
1897 * RFAILED - failed, general (optional)
1898 * ROUTRES - failed, out of resources (optional)
1900 * Notes: if message is empty: data is placed in the message. message
1901 * length is incremented. return is ok.
1903 * if message is not empty: data is placed in back of all
1904 * other data in message. message length is incremented.
1922 #if (ERRCLASS & ERRCLS_INT_PAR)
1923 /* check message buffer */
1926 SSLOGERROR(ERRCLS_INT_PAR, ESS067, ERRZERO, "SAddPstMsg: Null Buffer");
1929 if (mBuf->b_datap->db_type != SS_M_PROTO)
1931 SSLOGERROR(ERRCLS_INT_PAR, ESS068, ERRZERO, "SAddPstMsg: Incorrect\
1937 /* get the message info */
1938 minfo = (SsMsgInfo *) mBuf->b_rptr;
1940 if (!(tmp = minfo->endptr) || (tmp->b_datap->db_ref > 1) ||
1941 (tmp->b_wptr == tmp->b_datap->db_lim))
1943 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
1945 SSLOGERROR(ERRCLS_DEBUG, ESS069, ERRZERO, "SAddPstMsg: Failed in\
1950 /* append newb to the end of the mBuf chain */
1954 mBuf->b_cont = newb;
1956 /* set the endptr of mBuf to newb */
1957 minfo->endptr = newb;
1961 /* insert data, increment length */
1962 *tmp->b_wptr++ = data;
1970 * Fun: SAddPreMsgMult
1972 * Desc: This function copies consecutive bytes of data to the
1973 * beginning of a message.
1976 * RFAILED - failed, general (optional)
1977 * ROUTRES - failed, out of resources (optional)
1979 * Notes: if message is empty: data is placed in the message. message
1980 * length is incremented. return is ok.
1982 * if message is not empty: data is read by source pointer,
1983 * data is placed in front of all other data in message.
1984 * message length is incremented. return is ok.
1986 * the first byte of data pointed to by the source pointer will
1987 * be placed at the front of the message first, the last byte of
1988 * data pointed to by the source pointer will be placed at the
1989 * front of the message last (i.e. it will become the first
1990 * byte of the message).
1996 #ifdef T2K_MEM_LEAK_DBG
2015 SsMsgInfo *minfo; /* Message info */
2017 Buffer *curblk=NULLP;
2020 MsgLen numBytes; /* no. of bytes to be copied */
2025 #if (ERRCLASS & ERRCLS_INT_PAR)
2026 /* check message buffer */
2029 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMult:Null Buffer");
2035 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMult:Null Buffer");
2041 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMult: Invalid\
2045 if (mBuf->b_datap->db_type != SS_M_PROTO)
2047 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMult: Incorrect\
2053 /* get the SsMsgInfo of mBuf */
2054 minfo = (SsMsgInfo*) mBuf->b_rptr;
2056 /* store cnt in length */
2058 /* ss014.13: Addition */
2061 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
2062 (tmp->b_datap->db_base < tmp->b_rptr))
2064 /* store the offset of the read pointer of tmp */
2065 offset = tmp->b_rptr - tmp->b_datap->db_base;
2067 /* determine the number of bytes to copy */
2068 numBytes = MIN(cnt, offset);
2075 *--tmp->b_rptr = *src++;
2082 newblk = prevblk = NULLP;
2085 /* allocate a message blk */
2086 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2088 while ((curblk = prevblk))
2090 prevblk = prevblk->b_cont;
2091 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2096 tmp->b_rptr = tmp->b_datap->db_base + offset;
2101 /* attach curblk in the newblk chain */
2103 curblk->b_cont = prevblk; /* stack them up */
2108 /* set the read and write pointers to the end of the data buffer */
2109 /* subsequent prepends have all the buffer to insert data into */
2110 curblk->b_wptr = curblk->b_datap->db_lim;
2111 rptr = curblk->b_datap->db_lim;
2114 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
2121 curblk->b_rptr = rptr;
2124 /* attach the newblk chain into mBuf */
2125 newblk -> b_cont = tmp;
2126 mBuf -> b_cont = curblk;
2128 /* update endptr of mBuf */
2130 minfo -> endptr = newblk;
2132 /* update length of message */
2140 * Fun: SAddPstMsgMult
2142 * Desc: This function copies consecutive bytes of data to the
2146 * RFAILED - failed, general (optional)
2147 * ROUTRES - failed, out of resources (optional)
2149 * Notes: if message is empty: data is placed in the message. message
2150 * length is incremented. return is ok.
2152 * if message is not empty: data is read by source pointer,
2153 * data is placed in back of all other data in message.
2154 * message length is incremented. return is ok.
2156 * the first byte of data pointed to by the source pointer will
2157 * be placed at the back of the message first, the last byte of
2158 * data pointed to by the source pointer will be placed at the
2159 * back of the message last (i.e. it will become the last
2160 * byte of the message).
2166 #ifdef T2K_MEM_LEAK_DBG
2187 Buffer *curblk=NULLP;
2194 #if (ERRCLASS & ERRCLS_INT_PAR)
2195 /* check message buffer */
2198 SSLOGERROR(ERRCLS_INT_PAR, ESS074, ERRZERO, "SAddPstMsgMult:Null Buffer");
2204 SSLOGERROR(ERRCLS_INT_PAR, ESS075, ERRZERO, "SAddPstMsgMult:Null Buffer");
2210 SSLOGERROR(ERRCLS_INT_PAR, ESS076, ERRZERO, "SAddPstMsgMult:Invalid\
2214 if (mBuf->b_datap->db_type != SS_M_PROTO)
2216 SSLOGERROR(ERRCLS_INT_PAR, ESS077, ERRZERO, "SAddPstMsgMult: Incorrect\
2222 /* get the SsMsgInfo of mBuf */
2223 minfo = (SsMsgInfo*) mBuf->b_rptr;
2225 /* store cnt in len */
2228 /* ss014.13: Addition */
2231 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
2232 (tmp->b_datap->db_lim > tmp->b_wptr))
2234 /* store offset of the write pointer */
2235 /* incase subsequent allocations fail, offset is read reset to original */
2236 offset = tmp->b_datap->db_lim - tmp->b_wptr;
2238 /* determine the number of bytes to copy */
2239 numBytes = MIN(cnt, offset);
2245 /* ss002.13: addition */
2247 /* ss004.13: addition */
2248 SMemCpy((Void *) tmp->b_wptr, (Void *) src, (size_t) numBytes);
2250 tmp->b_wptr += numBytes;
2260 newblk = prevblk = NULLP;
2264 /* allocate a message blk */
2265 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2267 while ((curblk = newblk))
2269 newblk = newblk->b_cont;
2270 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2275 tmp->b_wptr = tmp->b_datap->db_lim - offset;
2281 /* insert curblk in the newblk chain */
2283 prevblk->b_cont = curblk; /* stack them down */
2289 wptr = curblk->b_wptr;
2290 numBytes = MIN(cnt, curblk->b_datap->db_lim - wptr);
2296 /* ss002.13: addition */
2297 /* ss003.13: addition */
2298 SMemCpy( (Void *) wptr, (Void *) src, (size_t) numBytes);
2300 src = src + numBytes;
2302 curblk->b_wptr += numBytes;
2304 /* insert newblk chain into mBuf */
2306 tmp->b_cont = newblk;
2308 mBuf->b_cont = newblk;
2309 minfo->endptr = curblk;
2317 /* #ifdef SS_LOCKLESS_MEMORY */
2325 * Desc: This function copies and then removes one byte of
2326 * data from the beginning of a message.
2329 * ROKDNA - ok, data not available
2330 * RFAILED - failed, general (optional)
2332 * Notes: if message is empty: message is unchanged. return is ok,
2333 * data not available.
2335 * if message is not empty: data is removed from front of
2336 * message, data is returned via pointer to data. message
2337 * length is decremented. return is ok.
2352 #ifdef T2K_MEM_LEAK_DBG
2353 char* file = __FILE__;
2354 uint32_t line = __LINE__;
2357 #if (ERRCLASS & ERRCLS_INT_PAR)
2358 /* check data pointer */
2361 SSLOGERROR(ERRCLS_INT_PAR, ESS078, ERRZERO, "SRemPreMsg : Null Buffer");
2364 /* check message buffer */
2367 SSLOGERROR(ERRCLS_INT_PAR, ESS079, ERRZERO, "SRemPreMsg : Null Buffer");
2370 if (mBuf->b_datap->db_type != SS_M_PROTO)
2372 SSLOGERROR(ERRCLS_INT_PAR, ESS080, ERRZERO, "SRemPreMsg : Incorrect\
2378 if (!(tmp = mBuf->b_cont))
2381 /* get SsMsgInfo of mBuf */
2382 minfo = (SsMsgInfo *) mBuf->b_rptr;
2384 /* read databyte into dataPtr and incrment read ptr */
2385 *dataPtr = *tmp->b_rptr++;
2387 /* if all data is exhausted, release the blk */
2388 if (tmp->b_rptr == tmp->b_wptr)
2390 mBuf->b_cont = tmp->b_cont;
2391 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2393 /* update SsMsgInfo */
2395 minfo->endptr = NULLP;
2404 * Desc: This function copies and then removes one byte of
2405 * data from the end of a message.
2408 * ROKDNA - ok, data not available
2409 * RFAILED - failed, general (optional)
2411 * Notes: if message is empty: message is unchanged. return is ok,
2412 * data not available.
2414 * if message is not empty: data is removed from back of
2415 * message, data is returned via pointer to data. message
2416 * length is decremented. return is ok.
2425 Data *dataPtr, /* pointer to data */
2432 #ifdef T2K_MEM_LEAK_DBG
2433 char* file = __FILE__;
2434 uint32_t line = __LINE__;
2437 #if (ERRCLASS & ERRCLS_INT_PAR)
2438 /* check data pointer */
2439 if (dataPtr == NULLP)
2441 SSLOGERROR(ERRCLS_INT_PAR, ESS081, ERRZERO, "SRemPstMsg : Null Buffer");
2444 /* check message buffer */
2447 SSLOGERROR(ERRCLS_INT_PAR, ESS082, ERRZERO, "SRemPstMsg : Null Buffer");
2450 if (mBuf->b_datap->db_type != SS_M_PROTO)
2452 SSLOGERROR(ERRCLS_INT_PAR, ESS083, ERRZERO, "SRemPstMsg : Incorrect\
2458 /* get the SsMsgInfo */
2459 minfo = (SsMsgInfo*) mBuf->b_rptr;
2461 if (!(last = minfo->endptr))
2464 /* read databyte into dataPtr and decrement write ptr */
2465 *dataPtr = *--last->b_wptr;
2467 /* if all data is exhausted, release the blk */
2468 if (last->b_rptr == last->b_wptr)
2470 for (tmp = mBuf; tmp->b_cont != last;)
2472 tmp->b_cont = NULLP;
2473 (Void) SPutDBuf(minfo->region, minfo->pool, last);
2477 minfo->endptr = tmp;
2479 minfo->endptr = NULLP;
2481 /* update SsMsgInfo */
2490 * Fun: SRemPreMsgMult
2492 * Desc: This function copies and then removes consecutive bytes of
2493 * data from the beginning of a message.
2496 * ROKDNA - ok, data not available
2497 * RFAILED - failed, general (optional)
2499 * Notes: if message is empty: message is unchanged. return is ok,
2500 * data not available.
2502 * if the destination buffer is NULL, data is not copied.
2504 * if message is not empty: data is removed from front of
2505 * message, data is returned by destination pointer. message
2506 * length is decremented. return is ok.
2508 * the first byte of data read from the message will be placed
2509 * in the destination buffer first (i.e. this was the first byte
2510 * of the message), the last byte of data read from the message
2511 * will be placed in the destination buffer last.
2519 Data *dst, /* destination */
2520 MsgLen cnt, /* count */
2524 SsMsgInfo *minfo = NULLP;
2525 Buffer *tmp = NULLP;
2527 #ifdef T2K_MEM_LEAK_DBG
2528 char* file = __FILE__;
2529 uint32_t line = __LINE__;
2533 /* ss023.103 - Modification of SRemPreMsgMult for bug fix */
2535 #if (ERRCLASS & ERRCLS_INT_PAR)
2539 SSLOGERROR(ERRCLS_INT_PAR, ESS084, ERRZERO, "SRemPreMsgMult:Invalid\
2543 /* check message buffer */
2546 SSLOGERROR(ERRCLS_INT_PAR, ESS085, ERRZERO, "SRemPreMsgMult:Null Buffer");
2549 /* ss021.103 - Addition to check for NULL pointer */
2550 /* check data pointer */
2551 /* ss022.103 - Removed check for NULL pointer */
2552 if (mBuf->b_datap->db_type != SS_M_PROTO)
2554 SSLOGERROR(ERRCLS_INT_PAR, ESS086, ERRZERO, "SRemPreMsgMult : Incorrect\
2560 /* get the SsMsgInfo */
2561 minfo = (SsMsgInfo*) mBuf->b_rptr;
2563 /* check if data present */
2564 if (minfo->len < cnt)
2571 /* get the first SS_M_DATA blk */
2574 /* determine the number of bytes to be copy */
2575 numBytes = MIN(cnt, tmp->b_wptr - tmp->b_rptr);
2580 /* move data into dst */
2584 SMemCpy( (Void *) dst, (Void *) tmp->b_rptr, (size_t) numBytes);
2588 tmp->b_rptr += numBytes;
2590 if (tmp->b_rptr == tmp->b_wptr)
2592 mBuf->b_cont = tmp->b_cont;
2593 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2596 /* update SsMsgInfo */
2598 minfo->endptr = NULLP;
2605 * Fun: SRemPstMsgMult
2607 * Desc: This function copies and then removes consecutive bytes of
2608 * data from the end of a message.
2611 * ROKDNA - ok, data not available
2612 * RFAILED - failed, general (optional)
2614 * Notes: if message is empty: message is unchanged. return is ok,
2615 * data not available.
2617 * if the destination buffer is NULL, data is not copied.
2619 * if message is not empty: data is removed from front of
2620 * message, data is returned by destination pointer. message
2621 * length is decremented. return is ok.
2623 * the first byte of data read from the message will be placed
2624 * in the destination buffer first (i.e. this was the last byte
2625 * of the message), the last byte of data read from the message
2626 * will be placed in the destination buffer last.
2634 Data *dst, /* destination */
2635 MsgLen cnt, /* count */
2645 #ifdef T2K_MEM_LEAK_DBG
2646 char* file = __FILE__;
2647 uint32_t line = __LINE__;
2651 #if (ERRCLASS & ERRCLS_INT_PAR)
2655 SSLOGERROR(ERRCLS_INT_PAR, ESS087, ERRZERO, "SRemPstMsgMult:Invalid\
2659 /* check message buffer */
2662 SSLOGERROR(ERRCLS_INT_PAR, ESS088, ERRZERO, "SRemPstMsgMult:Null Buffer");
2665 if (mBuf->b_datap->db_type != SS_M_PROTO)
2667 SSLOGERROR(ERRCLS_INT_PAR, ESS089, ERRZERO, "SRemPstMsgMult : Incorrect\
2671 /* ss021.103 - Addition to check dst data pointer */
2672 /* check data pointer */
2673 /* ss022.103 - Removed check for NULL destination pointer */
2676 /* get the SsMsgInfo */
2677 minfo = (SsMsgInfo*) mBuf->b_rptr;
2679 /* check if data present */
2680 if (minfo->len < cnt)
2690 /* determine blk containing offset, and prev node */
2691 FIND_OFFSET_AND_PREV(prev, tmp, count)
2698 numBytes = MIN(cnt, (tmp->b_wptr - tmp->b_rptr - count));
2700 tmp->b_wptr -= numBytes;
2712 if (tmp->b_rptr == tmp->b_wptr)
2714 prev->b_cont = tmp->b_cont;
2715 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2724 minfo->endptr = NULLP;
2726 minfo->endptr = prev;
2735 * Desc: This function copies one byte of data from a message
2736 * without modifying the message.
2739 * ROKDNA - ok, data not available
2740 * RFAILED - failed, general (optional)
2742 * Notes: index is 0 based and indicates location in message
2744 * if index is less than the length of the message:
2745 * message is unchanged and data is examined at specified
2746 * index and returned via pointer to data. message length
2747 * is unchanged. return is ok.
2749 * if index is greater than or equal to
2750 * the length of the message: message is unchanged and 0
2751 * is returned via pointer to data. return is ok, data
2761 Data *dataPtr, /* pointer to data */
2762 Buffer *mBuf, /* message buffer */
2769 #if (ERRCLASS & ERRCLS_INT_PAR)
2770 /* check data pointer */
2773 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SExamMsg : Null Buffer");
2776 /* check message buffer */
2779 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SExamMsg : Null Buffer");
2785 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SExamMsg : Invalid Index");
2788 if (mBuf->b_datap->db_type != SS_M_PROTO)
2790 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SExamMsg : Incorrect buffer\
2796 /* get the SsMsgInfo */
2797 minfo = (SsMsgInfo*) mBuf->b_rptr;
2799 if (minfo->len <= idx)
2804 /* get the first SS_M_DATA blk */
2807 /* determine offset */
2808 FIND_OFFSET(tmp, idx)
2810 *dataPtr = *(tmp->b_rptr + idx);
2819 * Fun: SGetDataFrmMsg
2821 * Desc: This function copies requested byte of data from a message
2822 * without modifying the message.
2825 * ROKDNA - ok, data not available
2826 * RFAILED - failed, general (optional)
2828 * Notes: index is 0 based and indicates location in message
2830 * if index is less than the length of the message:
2831 * message is unchanged and data is examined at specified
2832 * index and returned via pointer to data. message length
2833 * is unchanged. return is ok.
2835 * if index is greater than or equal to
2836 * the length of the message: message is unchanged and 0
2837 * is returned via pointer to data. return is ok, data
2847 Buffer *mBuf, /* message buffer */
2848 Data *dataPtr, /* pointer to data */
2856 Data *tmpDataPtr = dataPtr;
2858 #if (ERRCLASS & ERRCLS_INT_PAR)
2859 /* check data pointer */
2862 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SGetDataFrmMsg: Null Buffer");
2865 /* check message buffer */
2868 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SGetDataFrmMsg: Null Buffer");
2874 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SGetDataFrmMsg: Invalid Index");
2877 if (mBuf->b_datap->db_type != SS_M_PROTO)
2879 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SGetDataFrmMsg: Incorrect buffer\
2885 /* get the SsMsgInfo */
2886 minfo = (SsMsgInfo*) mBuf->b_rptr;
2888 if (minfo->len <= (idx + dataLen) )
2893 /* get the first SS_M_DATA blk */
2896 /* determine offset */
2903 FIND_OFFSET(tmp, idx)
2904 offSetLen = ((tmp->b_wptr - (tmp->b_rptr + idx)));
2906 for(;(offSetLen < dataLen && tmp != NULLP);)
2908 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)offSetLen);
2909 dataLen = dataLen - offSetLen;
2912 tmpDataPtr = tmpDataPtr + offSetLen;
2913 offSetLen = tmp->b_wptr - tmp->b_rptr;
2919 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)dataLen);
2923 } /* End of SGetDataFrmMsg() */
2929 * Desc: This function determines the length of data within
2933 * RFAILED - failed, general (optional)
2935 * Notes: length of message is determined, message is unchanged
2936 * and length is returned via pointer to length. return is ok.
2945 REG1 Buffer *mBuf, /* message buffer */
2951 #if (ERRCLASS & ERRCLS_INT_PAR)
2952 /* check message buffer */
2955 SSLOGERROR(ERRCLS_INT_PAR, ESS094, ERRZERO, "SFndLenMsg : Null Buffer");
2958 /* check length pointer */
2959 if (lngPtr == NULLP)
2961 SSLOGERROR(ERRCLS_INT_PAR, ESS095, ERRZERO, "SFndLenMsg : Null Buffer");
2964 if (mBuf->b_datap->db_type != SS_M_PROTO)
2966 SSLOGERROR(ERRCLS_INT_PAR, ESS096, ERRZERO, "SFndLenMsg : Incorrect\
2972 /* get the SsMsgInfo */
2973 minfo = (SsMsgInfo*) mBuf->b_rptr;
2976 *lngPtr = minfo->len;
2982 /* #ifdef SS_LOCKLESS_MEMORY */
2988 * Desc: This function will segment one specified message into two
2992 * ROKDNA - ok, data not available
2993 * RFAILED - failed, general (optional)
2994 * ROUTRES - failed, out of resources (optional)
2996 * Notes: message 1 is the original message.
2998 * message 2 is the new message.
3000 * index is 0 based and indicates location in message 1
3001 * from which message 2 will be created.
3003 * if index is equal to 0: message 2 is created and all data
3004 * attached to message 1 is moved to message 2. message 1
3005 * is not returned to memory. return is ok.
3007 * if index is not equal to 0 and less than the length of
3008 * the message minus 1: message 2 is created, all data
3009 * attached to message 1 from index (inclusive) is moved to
3010 * message 2. message 1 contains data from index 0 to index
3011 * minus 1. return is ok.
3013 * if index is not equal to 0 and greater than or equal to
3014 * the length of the message minus 1: message 1 is unchanged.
3015 * message 2 is set to null. return is ok, data not available.
3020 #ifdef T2K_MEM_LEAK_DBG
3023 Buffer *mBuf1, /* message 1 */
3024 MsgLen idx, /* index */
3032 Buffer *mBuf1, /* message 1 */
3033 MsgLen idx, /* index */
3045 #if (ERRCLASS & ERRCLS_INT_PAR)
3046 /* check message buffer 1 */
3049 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SSegMsg : Null Buffer");
3052 /* check message buffer 2 */
3055 SSLOGERROR(ERRCLS_INT_PAR, ESS098, ERRZERO, "SSegMsg : Null Buffer");
3060 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SSegMsg : Invalid index");
3063 if (mBuf1->b_datap->db_type != SS_M_PROTO)
3065 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SSegMsg : Incorrect buffer\
3071 /* get the SsMsgInfo of mBuf1 */
3072 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
3073 #ifdef RGL_SPECIFIC_CHANGES
3077 /* if index > length of mBuf, return */
3078 if (idx >= minfo1->len)
3083 /* allocate message buffer */
3084 if (SGetMsg(minfo1->region, minfo1->pool, mBuf2) != ROK)
3086 SSLOGERROR(ERRCLS_DEBUG, ESS101, ERRZERO, "SSegMsg : SGetMsg failed");
3090 /* get the SsMsgInfo of mBuf2 */
3091 minfo2 = (SsMsgInfo*) (*mBuf2)->b_rptr;
3093 /* adjust the lengths of mBuf1, mBuf2 */
3094 minfo2->len = minfo1->len - idx;
3097 /* set the endptr of mBuf2 to mBuf1 */
3098 minfo2->endptr = minfo1->endptr;
3100 /* if index is zero ... */
3103 (*mBuf2)->b_cont = mBuf1->b_cont;
3105 /* set the endptr and b_cont of mBuf1 to NULLP */
3106 minfo1->endptr = NULLP;
3107 mBuf1->b_cont = NULLP;
3112 /* get the first SS_M_DATA blk */
3113 tmp = mBuf1->b_cont;
3116 FIND_OFFSET_AND_PREV(prev, tmp, idx)
3118 /* segmented at the start of a blk */
3121 (*mBuf2)->b_cont = tmp;
3122 prev->b_cont = NULLP;
3123 minfo1->endptr = prev;
3127 #ifndef SS_MULTICORE_SUPPORT
3128 /* allocate a message blk without a data blk */
3129 /* ssDupB internally increments the reference count */
3130 #ifdef SS_M_PROTO_REGION
3131 if (!(next = DupMsg(minfo1->region, tmp)))
3133 if (!(next = ssDupB(tmp)))
3134 #endif /* SS_M_PROTO_REGION */
3137 minfo1->len += minfo2->len;
3138 (Void) SPutMsg(*mBuf2);
3142 (*mBuf2)->b_cont = next;
3144 tmp->b_cont = NULLP;
3146 tmp->b_wptr = tmp->b_rptr + idx;
3147 next->b_rptr = tmp->b_wptr;
3149 /* If the index was in the last mblk of the message, the
3150 * end pointer of the new message needs to be set to the
3151 * dup'ped mblk. Otherwise, the end pointer of the first
3152 * message will be set to the mblk in which the index
3153 * was found, and the end pointer of the new message can
3154 * remain where it is.
3156 if (minfo1->endptr == tmp)
3158 minfo2->endptr = next;
3162 minfo1->endptr = tmp;
3164 #else /*SS_MULTICORE_SUPPORT*/
3168 #ifdef SS_M_PROTO_REGION
3169 if (!(next = DupMsg(minfo1->region, tmp)))
3171 if (!(next = ssDupB(tmp)))
3172 #endif /* SS_M_PROTO_REGION */
3175 minfo1->len += minfo2->len;
3176 (Void) SPutMsg(*mBuf2);
3179 (*mBuf2)->b_cont = next;
3180 tmp->b_wptr = tmp->b_rptr + idx;
3181 next->b_rptr += idx;
3184 /* copy rest of the blocks */
3188 prev->b_cont = NULLP;
3189 minfo2->endptr = minfo1->endptr;
3190 minfo1->endptr = prev;
3194 next->b_cont = NULLP;
3195 minfo2->endptr = next;
3198 #endif /*SS_MULTICORE_SUPPORT*/
3208 * Desc: This function copies data from a fixed buffer to a
3212 * RFAILED - failed, general (optional)
3222 Data *srcBuf, /* source buffer */
3223 Buffer *dstMbuf, /* destination message buffer */
3224 MsgLen dstIdx, /* destination index */
3225 MsgLen cnt, /* count */
3233 #if (ERRCLASS & ERRCLS_INT_PAR)
3234 /* check source message buffer */
3235 if (srcBuf == NULLP)
3237 SSLOGERROR(ERRCLS_INT_PAR, ESS102, ERRZERO, "SCpyFixMsg : Null Buffer");
3240 /* check destination message buffer */
3241 if (dstMbuf == NULLP)
3243 SSLOGERROR(ERRCLS_INT_PAR, ESS103, ERRZERO, "SCpyFixMsg : Null Buffer");
3246 /* check copied count buffer */
3249 SSLOGERROR(ERRCLS_INT_PAR, ESS104, ERRZERO, "SCpyFixMsg : Null Buffer");
3252 /* check copy count */
3255 SSLOGERROR(ERRCLS_INT_PAR, ESS105, ERRZERO, "SCpyFixMsg : Invalid count");
3258 if (dstMbuf->b_datap->db_type != SS_M_PROTO)
3260 SSLOGERROR(ERRCLS_INT_PAR, ESS106, ERRZERO, "SCpyFixMsg : Incorrect\
3266 minfo = (SsMsgInfo*) dstMbuf->b_rptr;
3268 if (minfo->len < dstIdx)
3270 #if (ERRCLASS & ERRCLS_DEBUG)
3271 SSLOGERROR(ERRCLS_DEBUG, ESS107, ERRZERO, "SCpyFixMsg : Invalid Index");
3276 /* ss021.103 - Addition test if message length will exceed max msg length */
3277 #if (ERRCLASS & ERRCLS_INT_PAR)
3279 if (minfo->len > 0x7FFFFFFF - cnt)
3281 if (minfo->len > 0x7FFF - cnt)
3286 SSLOGERROR(ERRCLS_INT_PAR, ESS108, ERRZERO, "SCpyFixMsg : msgLen + cnt > maxS16");
3291 /* add data at the start of dst buffer */
3294 if ((ret = SAddPreMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3296 #if (ERRCLASS & ERRCLS_DEBUG)
3297 SSLOGERROR(ERRCLS_DEBUG, ESS109, ERRZERO, "SCpyFixMsg : Failed in\
3307 /* add data at the end of the dst buffer */
3308 if (minfo->len == dstIdx)
3310 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3319 /* segment the message into dstMbuf and right */
3320 if ((ret = SSegMsg(dstMbuf, dstIdx, &right)) != ROK)
3325 /* append data at the end of dstMbuf */
3326 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3328 /* ss020.103 - Addition for cleanup */
3329 (Void) SPutMsg(right);
3333 /* cancatenate dstMbuf and right */
3334 if ((ret = SCatMsg(dstMbuf, right, M1M2)) != ROK)
3336 /* ss020.103 - Addition for cleanup */
3337 (Void) SPutMsg(right);
3343 (Void) SPutMsg(right);
3352 * Desc: This function copies data from a message
3353 * into a fixed buffer.
3356 * RFAILED - failed, general (optional)
3366 Buffer *srcMbuf, /* source message buffer */
3367 MsgLen srcIdx, /* source index */
3368 MsgLen cnt, /* count */
3369 Data *dstBuf, /* destination buffer */
3374 Buffer *tmp = NULLP;
3375 SsMsgInfo *minfo = NULLP;
3378 #if (ERRCLASS & ERRCLS_INT_PAR)
3379 /* check source message buffer */
3380 if (srcMbuf == NULLP)
3382 SSLOGERROR(ERRCLS_INT_PAR, ESS110, ERRZERO, "SCpyMsgFix : Null Buffer");
3385 /* check destination message buffer */
3386 if (dstBuf == NULLP)
3388 SSLOGERROR(ERRCLS_INT_PAR, ESS111, ERRZERO, "SCpyMsgFix : Null Buffer");
3393 SSLOGERROR(ERRCLS_INT_PAR, ESS112, ERRZERO, "SCpyMsgFix : Invalid Index");
3399 SSLOGERROR(ERRCLS_INT_PAR, ESS113, ERRZERO, "SCpyMsgFix : Invalid Index");
3404 SSLOGERROR(ERRCLS_INT_PAR, ESS114, ERRZERO, "SCpyMsgFix : Null Buffer");
3407 if (srcMbuf->b_datap->db_type != SS_M_PROTO)
3409 SSLOGERROR(ERRCLS_INT_PAR, ESS115, ERRZERO, "SCpyMsgFix : Incorrect\
3416 minfo = (SsMsgInfo*) srcMbuf->b_rptr;
3418 if ((srcIdx + cnt) > minfo->len)
3424 /* get the first SS_M_DATA blk */
3425 tmp = srcMbuf->b_cont;
3427 /* get to the srcIdx-th offset */
3428 FIND_OFFSET(tmp, srcIdx)
3432 /* set cptr to the read ptr of tmp + offset */
3433 cptr = tmp->b_rptr + srcIdx;
3437 /* determine the number of bytes to be copied */
3438 numBytes = MIN(cnt, (tmp->b_wptr - cptr));
3445 /* ss002.13 addition */
3447 /* ss003.13 addition */
3448 SMemCpy((Void *) dstBuf, (Void *) cptr, (size_t) numBytes);
3454 /* get the next blk */
3455 if ((tmp = tmp->b_cont))
3456 /* set cptr to the read ptr of tmp */
3469 * Desc: This function is used to copy a message into
3470 * a new region and or pool of memory.
3473 * RFAILED - failed, general (optional)
3474 * ROUTRES - failed, out of resources (optional)
3482 #ifdef T2K_MEM_LEAK_DBG
3509 /* ss021.103 - Addition of return value */
3511 #if (ERRCLASS & ERRCLS_INT_PAR)
3516 #if (ERRCLASS & ERRCLS_INT_PAR)
3519 SSLOGERROR(ERRCLS_INT_PAR, ESS116, ERRZERO, "SCpyMsgMsg : Null Buffer");
3522 if (srcBuf->b_datap->db_type != SS_M_PROTO)
3524 SSLOGERROR(ERRCLS_INT_PAR, ESS117, ERRZERO, "SCpyMsgMsg : Incorrect\
3528 /* ss021.103 - Addition to validate region and pool */
3529 if (dstRegion >= SS_MAX_REGS)
3531 SSLOGERROR(ERRCLS_INT_PAR, ESS118, ERRZERO,
3532 "SCpyMsgMsg : Invalid region id");
3536 if (dstPool >= SS_MAX_POOLS_PER_REG)
3538 SSLOGERROR(ERRCLS_INT_PAR, ESS119, ERRZERO,
3539 "SCpyMsgMsg : Invalid pool id");
3542 /* ss037.103 Removed the semaphore operation for performance enhancement */
3545 /* ss021.103 - Addition to check if region is valid */
3546 /* acquire one semaphore, to protect against deregistration */
3547 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
3551 #if (ERRCLASS & ERRCLS_DEBUG)
3552 SSLOGERROR(ERRCLS_DEBUG, ESS120, (ErrVal) ret,
3553 "Could not lock region table");
3560 #if (ERRCLASS & ERRCLS_INT_PAR)
3561 /* verify that this region is present */
3562 if (osCp.regionTbl[dstRegion].used == FALSE)
3565 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3567 #if (ERRCLASS & ERRCLS_DEBUG)
3568 SSLOGERROR(ERRCLS_DEBUG, ESS121, ERRZERO,
3569 "Could not release semaphore");
3574 SSLOGERROR(ERRCLS_INT_PAR, ESS122, dstRegion, "Region not registered");
3578 /* ss037.103 Removed the semaphore operation for performance enhancement */
3581 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3583 #if (ERRCLASS & ERRCLS_DEBUG)
3584 SSLOGERROR(ERRCLS_DEBUG, ESS123, ERRZERO,
3585 "Could not release semaphore");
3592 #ifdef XEON_SPECIFIC_CHANGES
3596 /* allocate a message buffer */
3597 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
3599 #if (ERRCLASS & ERRCLS_DEBUG)
3600 SSLOGERROR(ERRCLS_DEBUG, ESS124, ERRZERO, "SCpyMsgMsg : SGetMsg failed");
3604 /* get the SsMsgInfo from srcBuf */
3605 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
3607 /* get the SsMsgInfo from srcBuf */
3608 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
3610 /* get the first SS_M_DATA blk of srcBuf */
3611 tmp = srcBuf->b_cont;
3613 /* if srcBuf and dstBuf belong to the same region, increment the reference
3622 #ifdef SS_M_PROTO_REGION
3623 if ((curblk = DupMsg(dstRegion,tmp)) == NULLP)
3625 if ((curblk = ssDupB(tmp)) == NULLP)
3626 #endif /* SS_M_PROTO_REGION */
3630 curblk = newblk->b_cont;
3631 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
3634 printf("\nFailed to get the buffer of size %s %d\n", __FILE__, __LINE__);
3635 (Void) SPutMsg(*dstBuf);
3642 prevblk->b_cont = curblk;
3648 curblk->b_cont = NULLP;
3650 minfo2->len = minfo1->len;
3651 minfo2->endptr = curblk;
3652 (*dstBuf)->b_cont = newblk;
3663 * Desc: This function is used to copy a message into
3664 * a new region and or pool of memory.
3667 * RFAILED - failed, general (optional)
3668 * ROUTRES - failed, out of resources (optional)
3675 #ifdef T2K_MEM_LEAK_DBG
3706 #if (ERRCLASS & ERRCLS_INT_PAR)
3709 SSLOGERROR(ERRCLS_INT_PAR, ESS126, ERRZERO, "SAddMsgRef : Null Buffer");
3712 if (srcBuf->b_datap->db_type != SS_M_PROTO)
3714 SSLOGERROR(ERRCLS_INT_PAR, ESS127, ERRZERO, "SAddMsgRef : Incorrect\
3719 #ifdef XEON_SPECIFIC_CHANGES
3724 /* allocate a message buffer */
3725 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
3727 #if (ERRCLASS & ERRCLS_DEBUG)
3728 SSLOGERROR(ERRCLS_DEBUG, ESS128, ERRZERO, "SAddMsgRef : SGetMsg failed");
3732 /* get the SsMsgInfo from srcBuf */
3733 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
3735 /* get the SsMsgInfo from srcBuf */
3736 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
3738 /* get the first SS_M_DATA blk of srcBuf */
3739 tmp = srcBuf->b_cont;
3741 /* if srcBuf and dstBuf belong to the same region, increment the reference
3744 if (dstRegion == minfo1->region)
3752 #ifdef SS_M_PROTO_REGION
3753 if ((curblk = DupMsg(dstRegion, tmp)) == NULLP)
3755 if ((curblk = ssDupB(tmp)) == NULLP)
3756 #endif /* SS_M_PROTO_REGION */
3760 curblk = newblk->b_cont;
3761 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
3764 (Void) SPutMsg(*dstBuf);
3771 prevblk->b_cont = curblk;
3777 curblk->b_cont = NULLP;
3779 minfo2->len = minfo1->len;
3780 minfo2->endptr = curblk;
3781 (*dstBuf)->b_cont = newblk;
3786 /* allocate a data buffer */
3787 if (ssGetDBufOfSize(dstRegion, minfo1->len, &dBuf) != ROK)
3789 /* ss016.13: addition */
3790 (Void) SPutMsg(*dstBuf);
3791 SSLOGERROR(ERRCLS_DEBUG, ESS129, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
3795 dBuf->b_datap->db_type = SS_M_DATA;
3799 numBytes = tmp->b_wptr - tmp->b_rptr;
3802 *dBuf->b_wptr++ = *cptr++;
3805 minfo2->len = minfo1->len;
3806 /* set the endptr and b_cont of dstBuf to point to dBuf */
3807 minfo2->endptr = dBuf;
3808 (*dstBuf)->b_cont = dBuf;
3812 /* ss012.13: Addition */
3813 #ifdef SS_M_PROTO_REGION
3818 * Desc: Duplicates the specified message block, copying it
3819 * into a newly-allocated message block. Increments
3820 * the reference count of the data block that is pointed
3821 * at by the original message block descriptor.
3823 * Ret: non-NULL - ok
3831 #ifdef T2K_MEM_LEAK_DBG
3832 static Buffer *DupMsgNew
3834 Region region, /* region id */
3835 Buffer *mp, /* message block */
3840 static Buffer *DupMsg
3842 Region region, /* region id */
3843 Buffer *mp /* message block */
3847 Buffer *bp; /* mblk for iteration */
3848 S16 r; /* return value */
3849 Size m; /* temporary */
3852 #if (ERRCLASS & ERRCLS_INT_PAR)
3855 SSLOGERROR(ERRCLS_INT_PAR, ESS130, ERRZERO, "Null pointer");
3859 if (region >= SS_MAX_REGS)
3861 SSLOGERROR(ERRCLS_INT_PAR, ESS131, ERRZERO, "DupMsg : Invalid region\
3868 /* allocate a single block for the mblock and the dblock */
3870 m = (sizeof(SsMblk) + sizeof(SsDblk));
3872 numBytes = mp->b_wptr - mp->b_rptr;
3873 m = MDBSIZE + numBytes;
3874 #endif /* SS_MULTICORE_SUPPORT */
3875 /* ss001.301: additions */
3876 #ifdef SS_HISTOGRAM_SUPPORT
3877 r = SAlloc(region, &m, 0, (Data **)&bp, __LINE__, (uint8_t*) __FILE__, ENTNC);
3879 r = SAlloc(region, &m, 0, (Data **)&bp);
3880 #endif /* SS_HISTOGRAM_SUPPORT */
3883 #if (ERRCLASS & ERRCLS_ADD_RES)
3884 SSLOGERROR(ERRCLS_ADD_RES, ESS132, (ErrVal) r, "SAlloc() failed");
3889 /* generic set-up-message function */
3891 #ifndef SS_DBUF_REFLOCK_DISABLE
3892 SS_STRM_INITB(bp, (SsDblk *)(((uint8_t *)bp) + sizeof(SsMblk)), NULLP, 0, NULLP);
3895 data = (Data *) (bp) + MDBSIZE;
3896 SS_STRM_INITB(bp,(SsDblk *)(((uint8_t *)bp) + sizeof(SsMblk)), data, numBytes, NULLP);
3897 #endif /* SS_MULTICORE_SUPPORT */
3900 /* make the new message block identical to the one to be dup'ed.
3901 * notice that an mblk/dblk pair is allocated but only the mblk
3902 * is used,, this is for optimum performance in the average case.
3904 SMemCpy( (Void *)bp, (Void *)mp, (size_t)sizeof(SsMblk));
3906 /* ss006.301 - added the Lock */
3907 #ifndef SS_DBUF_REFLOCK_DISABLE
3908 if((SLock(&(mp->b_datap->dBufLock))) != ROK)
3910 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
3911 "Could not lock the mBuf Ref Lock");
3915 /* increment the reference count of the dblock */
3916 /* increment the reference count of the dblock */
3917 mp->b_datap->db_ref++;
3918 mp->b_datap->shared = TRUE;
3919 #ifndef SS_DBUF_REFLOCK_DISABLE
3920 if((SUnlock(&(mp->b_datap->dBufLock))) != ROK)
3922 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
3923 "Could not lock the mBuf Ref Lock");
3931 #endif /* SS_M_PROTO_REGION */
3937 * Desc: This function allocates a buffer from the dynamic
3938 * memory pool indicated by the caller.
3941 * RFAILED - failed, general (optional)
3942 * ROUTRES - failed, out of resources (optional)
3944 * Notes: The dynamic memory pools are used to create and
3945 * manipulate messages.
3947 * SGetDBuf is never called by a protocol layer.
3949 * SGetDBuf assumes that interrupts are already disabled.
3955 #ifdef T2K_MEM_LEAK_DBG
3958 Region region, /* region id */
3959 Pool pool, /* pool id */
3967 Region region, /* region id */
3968 Pool pool, /* pool id */
3977 #ifdef SS_LOCKLESS_MEMORY
3978 #ifdef SS_USE_ICC_MEMORY
3979 CmMmDynRegCb *regCb;
3981 CmMmGlobRegCb *regCb;
3984 SsRegionEntry *regp;
3985 #endif /* SS_LOCKLESS_MEMORY */
3986 /* ss021.103 - Addition of return value */
3988 #if (ERRCLASS & ERRCLS_INT_PAR)
3993 #if (ERRCLASS & ERRCLS_INT_PAR)
3994 /* check buffer pointer */
3997 SSLOGERROR(ERRCLS_INT_PAR, ESS133, ERRZERO, "SGetDBuf : Null Buffer");
4000 if (region >= SS_MAX_REGS)
4002 SSLOGERROR(ERRCLS_INT_PAR, ESS134, ERRZERO, "SGetDBuf : Invalid region\
4007 if (pool >= SS_MAX_POOLS_PER_REG)
4009 SSLOGERROR(ERRCLS_INT_PAR, ESS135, ERRZERO, "SGetDBuf : Invalid pool id");
4012 /* ss037.103 Removed the semaphore operation for performance enhancement */
4015 /* ss021.103 - Addition to check if region is registered */
4016 /* acquire one semaphore, to protect against deregistration */
4017 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
4021 #if (ERRCLASS & ERRCLS_DEBUG)
4022 SSLOGERROR(ERRCLS_DEBUG, ESS136, (ErrVal) ret,
4023 "Could not lock region table");
4031 #if (ERRCLASS & ERRCLS_INT_PAR)
4032 /* verify that this region is present */
4033 if (osCp.regionTbl[region].used == FALSE)
4035 /* ss037.103 Removed the semaphore operation for performance enhancement */
4038 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4040 #if (ERRCLASS & ERRCLS_DEBUG)
4041 SSLOGERROR(ERRCLS_DEBUG, ESS137, ERRZERO,
4042 "Could not release semaphore");
4047 SSLOGERROR(ERRCLS_INT_PAR, ESS138, region, "Region not registered");
4051 /* ss037.103 Removed the semaphore operation for performance enhancement */
4054 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4056 #if (ERRCLASS & ERRCLS_DEBUG)
4057 SSLOGERROR(ERRCLS_DEBUG, ESS139, ERRZERO,
4058 "Could not release semaphore");
4065 #ifdef SS_LOCKLESS_MEMORY
4066 #ifdef SS_USE_ICC_MEMORY
4067 regCb = (CmMmDynRegCb *)(osCp.dynRegionTbl[region].regCb);
4068 mdsize = regCb->bktSize[pool];
4069 #else /* SS_USE_ICC_MEMORY */
4070 regCb = osCp.globRegCb;
4071 #ifdef SS_MEM_WL_DEBUG
4072 mdsize = regCb->bktTbl[pool].size - 4;
4073 #else /* SS_MEM_WL_DEBUG */
4074 mdsize = regCb->bktTbl[pool].size;
4075 #endif /* SS_MEM_WL_DEBUG */
4076 #endif /* SS_USE_ICC_MEMORY */
4078 regp = &osCp.regionTbl[region];
4079 size = regp->poolTbl[pool].u.dpool.size;
4080 /* ss006.301 : optimized this function */
4081 mdsize = MDBSIZE + size;
4082 #endif /* SS_LOCKLESS_MEMORY */
4084 /* ss006.301 : optimized this function */
4085 /* ss001.301: additions */
4086 #ifdef SS_HISTOGRAM_SUPPORT
4087 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
4089 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr) != ROK)
4090 #endif /* SS_HISTOGRAM_SUPPORT */
4094 data = (Data *) (*bufPtr) + MDBSIZE;
4095 size = mdsize - MDBSIZE;
4097 dptr = (SsDblk*) (((Data *) (*bufPtr)) + MBSIZE);
4099 INITB((*bufPtr), dptr, data, size, NULLP)
4100 #ifndef SS_DBUF_REFLOCK_DISABLE
4101 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
4103 printf("\nFalied to destroy lock\n");
4114 * Desc: This function deallocates a buffer back to the
4115 * dynamic memory pool indicated by the caller.
4118 * RFAILED - failed, general (optional)
4120 * Notes: The dynamic memory pools are used to create and
4121 * manipulate messages.
4123 * SPutDBuf is never called by a protocol layer.
4125 * SPutDBuf assumes that interrupts are already disabled.
4131 #ifdef T2K_MEM_LEAK_DBG
4149 register SsDblk *dptr = NULLP;
4150 /* ss021.103 - Addition to check return value of SFree */
4152 #if (defined(SS_USE_ZBC_MEMORY) && defined (TENB_DPDK_BUF))
4153 Data *dpdkBuf = NULLP;
4157 /* ss021.103 - Addition of ret initialization */
4160 #if (ERRCLASS & ERRCLS_INT_PAR)
4161 if (region >= SS_MAX_REGS)
4163 SSLOGERROR(ERRCLS_INT_PAR, ESS141, ERRZERO, "SPutDBuf:Invalid region");
4167 if (pool >= SS_MAX_POOLS_PER_REG)
4169 SSLOGERROR(ERRCLS_INT_PAR, ESS142, ERRZERO, "SPutDBuf:Invalid pool");
4175 SSLOGERROR(ERRCLS_INT_PAR, ESS143, ERRZERO, "SPutDBuf:Null pointer");
4179 if ( (buf->b_datap->db_type != SS_M_DATA) && (buf->b_datap->db_type != SS_M_PROTO))
4181 SSLOGERROR(ERRCLS_INT_PAR, ESS144, ERRZERO, "SPutDBuf:Incorrect\
4186 /* ss016.13: Addition */
4187 dptr = buf->b_datap;
4189 #ifdef SS_USE_ZBC_MEMORY
4190 if(dptr->db_type == SS_MEM_TYPE_SSI_ZBC)
4192 ret = SPutZbcDBuf(region, buf);
4196 #ifdef TENB_DPDK_BUF
4197 if(dptr->db_type == SS_MEM_TYPE_DPDK_ZBC)
4199 /* Not considering referances for DPDK buffer for now */
4200 SDetachDpdkPtrFrmDBuf(buf, &dpdkBuf);
4201 SPutSBufDpdk(dpdkBuf);
4202 ret = SFree(region, (Data *) buf, MDBSIZE);
4205 #endif /* TENB_DPDK_BUF */
4206 #endif /* SS_USE_ZBC_MEMORY */
4208 /* ss028.103 - Addition of lock for mBuf reference count */
4209 /* ss006.301 : optimized this funciton */
4213 #ifndef SS_DBUF_REFLOCK_DISABLE
4214 SDestroyLock(&dptr->dBufLock);
4216 /* if the data block is not shared, free the buffer, checks not reqd */
4217 #ifdef SS_HISTOGRAM_SUPPORT
4218 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4219 , __LINE__, (uint8_t*) __FILE__, ENTNC);
4221 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4222 #endif /* SS_HISTOGRAM_SUPPORT */
4226 #ifndef SS_DBUF_REFLOCK_DISABLE
4227 if((ret=SLock(&dptr->dBufLock)))
4229 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
4230 "Could not lock the mBuf Ref Lock");
4235 /* if buffer's message blk is obtained during dupb */
4236 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
4239 SsDblk* dupdptr = (SsDblk *)((uint8_t *)buf + MBSIZE);
4241 if(dupdptr->db_ref == 0)
4244 #ifdef SS_HISTOGRAM_SUPPORT
4245 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__, ENTNC);
4247 ret = SFree(region, (Data *) buf, MDBSIZE);
4249 #endif /* SS_HISTOGRAM_SUPPORT */
4251 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
4253 /* if reference count falls to zero */
4256 #ifndef SS_DBUF_REFLOCK_DISABLE
4257 ret = SUnlock(&dptr->dBufLock) ;
4258 if((SDestroyLock(&dptr->dBufLock)) != 0)
4260 printf("\nFalied to destroy lock\n");
4263 /* free buffer to region */
4264 #ifdef SS_HISTOGRAM_SUPPORT
4265 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4266 , __LINE__, (uint8_t*) __FILE__, ENTNC);
4268 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4269 #endif /* SS_HISTOGRAM_SUPPORT */
4272 #ifndef SS_DBUF_REFLOCK_DISABLE
4273 ret = SUnlock(&(dptr->dBufLock));
4276 #else /* SS_MULTICORE_SUPPORT */
4277 /* If MultiCore Support enabled, Dblk never be shared */
4278 #ifdef SS_HISTOGRAM_SUPPORT
4279 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4280 , __LINE__, (uint8_t*) __FILE__, ENTNC);
4282 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4283 #endif /* SS_HISTOGRAM_SUPPORT */
4284 #endif /* SS_MULTICORE_SUPPORT */
4289 /* #ifdef SS_LOCKLESS_MEMORY */
4296 * Desc: This function will concatenate the two specified messages
4300 * RFAILED - failed, general (optional)
4302 * Notes: if order equal M1M2: all data attached to message 2 is
4303 * moved to the end of message 1. message 2 is set to empty.
4304 * message 1 length is increased by length of message 2.
4305 * message 2 length is set to zero. message 2 is not returned
4306 * to memory. return is ok.
4308 * if order equal M2M1: all data attached to message 2 is
4309 * moved to the front of message 1. message 2 is set to empty.
4310 * message 1 length is increased by length of message 2.
4311 * message 2 length is set to zero. message 2 is not returned
4312 * to memory. return is ok.
4321 Buffer *mBuf1, /* message 1 */
4322 Buffer *mBuf2, /* message 2 */
4331 #if (ERRCLASS & ERRCLS_INT_PAR)
4332 /* check message buffer 1 */
4335 SSLOGERROR(ERRCLS_INT_PAR, ESS148, ERRZERO, "SCatMsg : Null Buffer");
4338 /* check message buffer 2 */
4341 SSLOGERROR(ERRCLS_INT_PAR, ESS149, ERRZERO, "SCatMsg : Null Buffer");
4344 /* ss021.103 - Addition to test if same buffer */
4345 /* check message buffer 1 and 2 not same buffer */
4348 SSLOGERROR(ERRCLS_INT_PAR, ESS150, ERRZERO, "SCatMsg : mBuf1 == mBuf2");
4351 if ((order != M1M2) && (order != M2M1))
4353 SSLOGERROR(ERRCLS_INT_PAR, ESS151, ERRZERO, "SCatMsg : Invalid Order");
4356 if ((mBuf1->b_datap->db_type != SS_M_PROTO) ||
4357 (mBuf2->b_datap->db_type != SS_M_PROTO))
4359 SSLOGERROR(ERRCLS_INT_PAR, ESS152, ERRZERO,
4360 "SCatMsg : Incorrect buffer type");
4365 /* no data to append or prepend */
4369 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
4370 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
4372 /* ss021.103 - Addition to test max length of message is not exceeded */
4373 #if (ERRCLASS & ERRCLS_INT_PAR)
4375 if (minfo1->len > 0x7FFFFFFF - minfo2->len)
4377 if (minfo1->len > 0x7FFF - minfo2->len)
4380 SSLOGERROR(ERRCLS_INT_PAR, ESS153, ERRZERO, "SCpyFixMsg : messages too big");
4385 if (minfo1->region != minfo2->region)
4387 /* duplicate mBuf2 from the region/pool of mBuf1, initialise mBuf2 */
4388 /*ss015.13: addition */
4389 if (SCpyMsgMsg(mBuf2, minfo1->region, minfo1->pool, &newb) != ROK)
4392 minfo2 = (SsMsgInfo*) newb->b_rptr;
4397 if ((tmp = mBuf1->b_cont) == NULLP)
4399 mBuf1->b_cont = newb->b_cont;
4400 minfo1->endptr = minfo2->endptr;
4405 /* attach newb after mBuf1 */
4407 minfo1->endptr->b_cont = newb->b_cont;
4408 minfo1->endptr = minfo2->endptr;
4413 /* attach newb before mBuf1 */
4415 minfo2->endptr->b_cont = mBuf1->b_cont;
4416 mBuf1->b_cont = newb->b_cont;
4418 else /* invalid order */
4420 #if (ERRCLASS & ERRCLS_DEBUG)
4421 SSLOGERROR(ERRCLS_DEBUG, ESS154, ERRZERO, "SCatMsg:Invalid order");
4423 if (newb && (newb != mBuf2))
4424 (Void) SPutMsg(newb);
4429 minfo1->len += minfo2->len;
4432 minfo2->endptr = NULLP;
4435 newb->b_cont = NULLP;
4439 (Void) SPutMsg(newb);
4440 (Void) SInitMsg(mBuf2);
4450 * Desc: This function replaces one byte of data in a message.
4453 * ROKDNA - ok, data not available
4454 * RFAILED - failed, general (optional)
4456 * Notes: index is 0 based and indicates location in message
4458 * if index is less than the length of the message:
4459 * data is replaced at specified index. message length
4460 * is unchanged. return is ok.
4462 * if index is greater than or equal to
4463 * the length of the message: message is unchanged.
4464 * return is ok, data not available.
4473 Data data, /* data */
4474 Buffer *mBuf, /* message buffer */
4485 #ifdef T2K_MEM_LEAK_DBG
4486 char* file = __FILE__;
4487 uint32_t line = __LINE__;
4489 #if ( ERRCLASS & ERRCLS_INT_PAR)
4490 /* check message buffer */
4493 SSLOGERROR(ERRCLS_INT_PAR, ESS155, ERRZERO, "SRepMsg : Null Buffer");
4498 SSLOGERROR(ERRCLS_INT_PAR, ESS156, ERRZERO, "SRepMsg : Invalid index");
4501 if (mBuf->b_datap->db_type != SS_M_PROTO)
4503 SSLOGERROR(ERRCLS_INT_PAR, ESS157, ERRZERO, "SRepMsg : Incorrect buffer\
4509 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4511 /* if index > length of the buffer */
4512 if (minfo->len <= idx)
4517 tmp = mBuf->b_cont; /* get the first SS_M_DATA blk */
4518 prev = mBuf; /* parent */
4520 FIND_OFFSET_AND_PREV(prev, tmp, idx)
4522 /* if ref cnt is greater than 1, duplicate tmp */
4523 if (tmp->b_datap->db_ref > 1)
4525 /* allocate a message blk of message size of tmp */
4526 numBytes = tmp->b_wptr - tmp->b_rptr;
4527 if (ssGetDBufOfSize(minfo->region, numBytes, &newb) != ROK)
4529 SSLOGERROR(ERRCLS_DEBUG, ESS158, ERRZERO, "SRepMsg : ssGetDBufOfSize\
4534 *newb->b_wptr++ = *tmp->b_rptr++;
4536 newb->b_cont = tmp->b_cont;
4537 prev->b_cont = newb;
4538 if (minfo->endptr == tmp)
4539 minfo->endptr = newb;
4542 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
4545 *(tmp->b_rptr + idx) = data;
4554 * Desc: Update a message with a new dBuf
4567 Buffer *mBuf, /* message buffer */
4568 Buffer *dBuf, /* data buffer */
4574 #if (ERRCLASS & ERRCLS_INT_PAR)
4577 SSLOGERROR(ERRCLS_INT_PAR, ESS159, ERRZERO, "SUpdMsg : Null Buffer");
4582 SSLOGERROR(ERRCLS_INT_PAR, ESS160, ERRZERO, "SUpdMsg : Null Buffer");
4587 SSLOGERROR(ERRCLS_INT_PAR, ESS161, ERRZERO, "SUpdMsg : Invalid length");
4590 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4591 (dBuf->b_datap->db_type != SS_M_DATA))
4593 SSLOGERROR(ERRCLS_INT_PAR, ESS162, ERRZERO, "SUpdMsg : Incorrect buffer\
4599 /* get the message info of mBuf */
4600 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4602 /* accept zero length data */
4604 /* buffer offset out of bounds */
4605 if ((dBuf->b_rptr + dLen) > dBuf->b_datap->db_lim)
4607 SSLOGERROR(ERRCLS_DEBUG, ESS163, ERRZERO, "SUpdMsg:Offset out of bounds");
4611 /* offset write ptr from read ptr by dLen */
4612 dBuf->b_wptr = dBuf->b_rptr + dLen;
4614 /* attach dBuf at the end of mBuf */
4616 minfo->endptr->b_cont = dBuf;
4618 mBuf->b_cont = dBuf;
4620 /* update SsMsgInfo */
4621 minfo->endptr = dBuf;
4632 * Desc: This function queues a data buffer to the
4633 * back of the specified message buffer .
4636 * RFAILED - failed, general (optional)
4638 * Notes: if queue is empty: buffer is placed in the queue.
4639 * queue length is incremented.
4641 * if queue is not empty: buffer is placed behind all
4642 * other buffers in queue. queue length is incremented.
4651 Buffer *mBuf, /* message buffer */
4657 #if (ERRCLASS & ERRCLS_INT_PAR)
4658 /* check buffer queue */
4661 SSLOGERROR(ERRCLS_INT_PAR, ESS164, ERRZERO, "SAddDBufPst : Null Buffer");
4664 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4665 (dBuf->b_datap->db_type != SS_M_DATA))
4667 SSLOGERROR(ERRCLS_INT_PAR, ESS165, ERRZERO, "SAddDBufPst : Incorrect\
4673 /* no data, return */
4674 if (dBuf->b_wptr == dBuf->b_rptr)
4677 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4679 /* attach dBuf at the end of mBuf */
4681 minfo->endptr->b_cont = dBuf;
4683 mBuf->b_cont = dBuf;
4685 /* update SsMsgInfo */
4686 minfo->endptr = dBuf;
4688 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
4697 * Desc: This function queues a data buffer to the
4698 * front of the specified message buffer.
4701 * RFAILED - failed, general (optional)
4703 * Notes: if buffer queue is empty: buffer is placed in the queue. queue
4704 * length is incremented.
4706 * if buffer queue is not empty: buffer is placed in front of all
4707 * other buffers in queue. queue length is incremented.
4716 Buffer *mBuf, /* message buffer */
4723 #if (ERRCLASS & ERRCLS_INT_PAR)
4724 /* check buffer queue */
4727 SSLOGERROR(ERRCLS_INT_PAR, ESS166, ERRZERO, "SAddDBufPre : Null Buffer");
4730 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4731 (dBuf->b_datap->db_type != SS_M_DATA))
4733 SSLOGERROR(ERRCLS_INT_PAR, ESS167, ERRZERO, "SAddDBufPre : Incorrect\
4739 /* no data, return */
4740 if (dBuf->b_wptr == dBuf->b_rptr)
4743 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4747 /* attach dBuf at the start of mBuf */
4748 mBuf->b_cont = dBuf;
4751 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
4754 minfo->endptr = dBuf;
4763 * Desc: This function dequeues a data buffer from
4764 * the front of the specified message buffer.
4767 * ROKDNA - ok, data not available
4768 * RFAILED - failed, general (optional)
4770 * Notes: if queue is empty: pointer to buffer is set to null and
4771 * return is ok, data not available. queue length is unchanged.
4773 * if queue is not empty: pointer to buffer is set to first
4774 * buffer in queue, first buffer in queue is removed and
4775 * return is ok. queue length is decremented.
4784 Buffer *mBuf, /* message buffer */
4790 #if (ERRCLASS & ERRCLS_INT_PAR)
4791 /* check buffer pointer */
4792 if (dBufPtr == NULLP)
4794 SSLOGERROR(ERRCLS_INT_PAR, ESS168, ERRZERO, "SRemDBufPre : Null Buffer");
4800 SSLOGERROR(ERRCLS_INT_PAR, ESS169, ERRZERO, "SRemDBufPre : Null Buffer");
4803 if (mBuf->b_datap->db_type != SS_M_PROTO)
4805 SSLOGERROR(ERRCLS_INT_PAR, ESS170, ERRZERO, "SRemDBufPre : Incorrect\
4811 /* no data blk, return */
4812 if ((*dBufPtr = mBuf->b_cont) == NULLP)
4816 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4818 mBuf->b_cont = (*dBufPtr)->b_cont;
4819 (*dBufPtr)->b_cont = NULLP;
4821 /* update SsMsgInfo */
4822 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
4823 minfo->endptr = NULLP;
4832 * Desc: This function dequeues a data or message buffer from the
4833 * back of the specified message buffer.
4836 * ROKDNA - ok, data not available
4837 * RFAILED - failed, general (optional)
4839 * Notes: if queue is empty: pointer to buffer is set to null and
4840 * return is ok, data not available. queue length is unchanged.
4842 * if queue is not empty: pointer to buffer is set to last
4843 * buffer in queue, last buffer in queue is removed and
4844 * return is ok. queue length is decremented.
4853 Buffer *mBuf, /* message buffer */
4860 #if (ERRCLASS & ERRCLS_INT_PAR)
4861 /* check buffer pointer */
4864 SSLOGERROR(ERRCLS_INT_PAR, ESS171, ERRZERO, "SRemDBufPst : Null Buffer");
4870 SSLOGERROR(ERRCLS_INT_PAR, ESS172, ERRZERO, "SRemDBufPst : Null Buffer");
4873 if (mBuf->b_datap->db_type != SS_M_PROTO)
4875 SSLOGERROR(ERRCLS_INT_PAR, ESS173, ERRZERO, "SRemDBufPst : Incorrect\
4881 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4883 /* no data blk, return */
4884 if ((*dBufPtr = minfo->endptr) == NULLP)
4888 for (tmp = mBuf; tmp->b_cont != (*dBufPtr); )
4891 tmp->b_cont = NULLP;
4893 /* update SsMsgInfo */
4894 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
4895 minfo->endptr = NULLP;
4897 minfo->endptr = tmp;
4906 * Desc: Initialize next Data Buffer Id
4910 * Notes: Must be called prior to SGetNxtDBuf
4924 #if (ERRCLASS & ERRCLS_INT_PAR)
4927 SSLOGERROR(ERRCLS_INT_PAR, ESS174, ERRZERO, "SInitNxtDBuf : Null Buffer");
4930 if (mBuf->b_datap->db_type != SS_M_PROTO)
4932 SSLOGERROR(ERRCLS_INT_PAR, ESS175, ERRZERO, "SInitNxtDBuf : Incorrect\
4938 minfo = (SsMsgInfo*) mBuf->b_rptr;
4940 /* set the next ptr of mBuf to point to the first SS_M_DATA blk */
4941 minfo->next = mBuf->b_cont;
4950 * Desc: Get next dBuf in message chain
4954 * Notes: Must be called after SInitNxtDBuf
4963 Buffer *mBuf, /* message buffer */
4969 #if (ERRCLASS & ERRCLS_INT_PAR)
4972 SSLOGERROR(ERRCLS_INT_PAR, ESS176, ERRZERO, "SGetNxtDBuf : Null Buffer");
4977 SSLOGERROR(ERRCLS_INT_PAR, ESS177, ERRZERO, "SGetNxtDBuf : Null Buffer");
4980 if (mBuf->b_datap->db_type != SS_M_PROTO)
4982 SSLOGERROR(ERRCLS_INT_PAR, ESS178, ERRZERO, "SGetNxtDBuf : Incorrect\
4988 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4990 /* if next ptr of mBuf is NULLP, return */
4991 if ((*dBuf = minfo->next) == NULLP)
4995 minfo->next = (*dBuf)->b_cont;
5004 * Desc: check if next data buffer exists.
5006 * Ret: ROK/ROKDNA/RFAILED
5008 * Notes: doesn't modify nxtDBuf
5021 #if (ERRCLASS & ERRCLS_INT_PAR)
5024 SSLOGERROR(ERRCLS_INT_PAR, ESS179, ERRZERO, "SChkNxtDBuf : Null Buffer");
5027 if (mBuf->b_datap->db_type != SS_M_PROTO)
5029 SSLOGERROR(ERRCLS_INT_PAR, ESS180, ERRZERO, "SChkNxtDBuf : Incorrect\
5033 #endif /* ERRCLASS */
5035 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5037 /* if next is valid, return ROK */
5048 * Desc: Given a data buffer, return a pointer to the
5049 * data payload, and the length of the payload
5055 * Notes: This assumes an uninitialized dBuf
5064 Buffer *dBuf, /* data buffer */
5065 MsgLen pad, /* pad */
5066 Data **retDatPtr, /* return data pointer */
5071 #if (ERRCLASS & ERRCLS_INT_PAR)
5074 SSLOGERROR(ERRCLS_INT_PAR, ESS181, ERRZERO, "SGetDataRx : Null Buffer");
5077 if (!retDatLen || (pad < 0))
5079 SSLOGERROR(ERRCLS_INT_PAR, ESS182, ERRZERO, "SGetDataRx : Null Buffer");
5084 SSLOGERROR(ERRCLS_INT_PAR, ESS183, ERRZERO, "SGetDataRx : Null Buffer");
5087 if (dBuf->b_datap->db_type != SS_M_DATA)
5089 SSLOGERROR(ERRCLS_INT_PAR, ESS184, ERRZERO, "SGetDataRx : Incorrect\
5093 #endif /* ERRCLASS */
5095 if (dBuf->b_datap->db_ref > 1) /* cannot write to a shared buffer */
5097 #if (ERRCLASS & ERRCLS_DEBUG)
5098 SSLOGERROR(ERRCLS_DEBUG, ESS185, ERRZERO, "SGetDataRx : Reference\
5104 /* return the write ptr loc(with padding) if there is data to write to */
5105 if ((*retDatLen = (dBuf->b_datap->db_lim - dBuf->b_wptr - pad)) > 0)
5106 *retDatPtr = dBuf->b_wptr + pad;
5110 #if (ERRCLASS & ERRCLS_DEBUG)
5111 SSLOGERROR(ERRCLS_DEBUG, ESS186, ERRZERO, "SGetDataRx:No data available");
5123 * Desc: Given a data buffer, return a pointer to the
5124 * data payload, and the length of the payload
5130 * Notes: This assumes an initialized dBuf
5139 Buffer *dBuf, /* data buffer */
5140 Data **retDatPtr, /* return data pointer */
5141 MsgLen *retDatLen /* return data length */
5145 #if (ERRCLASS & ERRCLS_INT_PAR)
5146 /* ss021.103 - Modification to check parameters */
5149 SSLOGERROR(ERRCLS_INT_PAR, ESS187, ERRZERO, "SGetDataTx : Null Buffer");
5154 SSLOGERROR(ERRCLS_INT_PAR, ESS188, ERRZERO, "SGetDataTx : Null Buffer");
5155 *retDatPtr = (Data *)NULLP;
5160 SSLOGERROR(ERRCLS_INT_PAR, ESS189, ERRZERO, "SGetDataTx : Null Buffer");
5163 if (dBuf->b_datap->db_type != SS_M_DATA)
5165 SSLOGERROR(ERRCLS_INT_PAR, ESS190, ERRZERO, "SGetDataTx : Incorrect\
5167 *retDatPtr = (Data *)NULLP;
5170 #endif /* ERRCLASS */
5172 /* if there is data, return read ptr */
5173 if ((*retDatLen = dBuf->b_wptr - dBuf->b_rptr))
5174 *retDatPtr = dBuf->b_rptr;
5178 #if (ERRCLASS & ERRCLS_DEBUG)
5179 SSLOGERROR(ERRCLS_DEBUG, ESS191, ERRZERO, "SGetDataTx : Buffer empty");
5187 #ifndef SS_ENABLE_MACROS
5191 * Fun: SGetBufRegionPool
5193 * Desc: returns the region and pool of the message buffer
5195 * Ret: ROK on success
5203 S16 SGetBufRegionPool
5205 Buffer *mBuf, /* message buffer */
5206 Region *region, /* region */
5207 Pool *pool /* pool */
5210 SsMsgInfo *mInfo; /* message info pointer */
5213 #if (ERRCLASS & ERRCLS_INT_PAR)
5217 SSLOGERROR(ERRCLS_INT_PAR, ESS192, ERRZERO,
5218 "SGetBufRegionPool : Null Buffer");
5221 if ((region == NULLP) && (pool == NULLP))
5223 SSLOGERROR(ERRCLS_INT_PAR, ESS193, ERRZERO,
5224 "SGetBufRegionPool : Null region and pool pointers");
5227 if (mBuf->b_datap->db_type != SS_M_PROTO)
5229 SSLOGERROR(ERRCLS_INT_PAR, ESS194, ERRZERO,
5230 "SUpdMsg : Incorrect buffer type");
5233 #endif /* (ERRCLASS & ERRCLS_INT_PAR */
5235 /* get message info of mBuf */
5236 if ((mInfo = (SsMsgInfo *) mBuf->b_rptr) == NULLP)
5238 #if (ERRCLASS & ERRCLS_DEBUG)
5239 SSLOGERROR(ERRCLS_DEBUG, ESS195, ERRZERO,
5240 "SGetBufRegionPool : mBuf's control data is null");
5245 if (region != NULLP)
5246 *region = mInfo->region;
5248 *pool = mInfo->pool;
5251 } /* end of SGetBufRegionPool */
5253 #endif /* SS_ENABLE_MACROS */
5259 * Desc: This function is used to compress a message into
5260 * the minimum number of data buffers needed.
5263 * RFAILED - failed, general (optional)
5264 * ROUTRES - failed, out of resources (optional)
5285 #ifdef T2K_MEM_LEAK_DBG
5286 char* file = __FILE__;
5287 uint32_t line = __LINE__;
5290 #if (ERRCLASS & ERRCLS_INT_PAR)
5293 SSLOGERROR(ERRCLS_INT_PAR, ESS196, ERRZERO, "SCompressMsg : Null Buffer");
5296 if (mBuf->b_datap->db_type != SS_M_PROTO)
5298 SSLOGERROR(ERRCLS_INT_PAR, ESS197, ERRZERO, "SCompressMsg : Incorrect\
5304 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5306 if ((tmp = mBuf->b_cont) == minfo->endptr)
5311 /* allocate a data buffer of size bytes*/
5312 if ((ret = ssGetDBufOfSize(minfo->region, minfo->len, &dBuf)) != ROK)
5314 SSLOGERROR(ERRCLS_DEBUG, ESS198, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
5318 dBuf->b_datap->db_type = SS_M_DATA;
5322 /* determine number of bytes to be copied */
5323 numBytes = tmp->b_wptr - tmp->b_rptr;
5327 /* ss002.13: addition */
5328 /* ss003.13: addition */
5329 SMemCpy( (Void *)dBuf->b_wptr, (Void *)tmp->b_rptr, (size_t)numBytes);
5331 dBuf->b_wptr += numBytes;
5332 tmp->b_rptr += numBytes;
5336 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
5339 /* update mBuf and SsMsgInfo */
5340 mBuf->b_cont = dBuf;
5341 minfo->endptr = dBuf;
5350 * Desc: This function prints the contents of a message. The
5351 * following information is printed: queue length,
5352 * message length, direction, hexadecimal and ASCII
5353 * (if appropriate) values of all bytes in the message.
5355 * This function should be used for debugging only.
5367 Buffer *mBuf, /* message buffer */
5368 S16 src, /* source id */
5369 S16 dst /* destination id */
5372 QLen qlen =0; /* queue length */
5373 MsgLen mlen =0; /* message length */
5377 /* ss038.103 : 102061 Changed to MsgLen from S16 */
5378 MsgLen i =0; /* counter */
5379 S16 j =0; /* counter */
5380 S16 k =0; /* counter */
5381 uint8_t data =0; /* data */
5382 uint8_t tdata[16] = {0}; /* temporary data */
5383 S8 prntBuf[256] ={0}; /* print buffer */
5384 Buffer *tmp = NULLP; /* buffer ptr */
5386 /* ss012.13: Addition */
5393 sprintf(prntBuf,"\nmsg: empty\n");
5395 SPrint( (S8*)"\n\n");
5399 for (qlen = 0, tmp = mBuf->b_cont; tmp; qlen++)
5401 mlen = ((SsMsgInfo*)(mBuf->b_rptr))->len;
5402 reg = ((SsMsgInfo*)(mBuf->b_rptr))->region;
5403 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
5404 sprintf(prntBuf,"\nmsg: qlen: %04d mlen: %04d %02d-->%02d region: %02d\n",
5405 (uint16_t)qlen,(uint16_t)mlen,src,dst,reg);
5407 #ifdef XEON_SPECIFIC_CHANGES
5408 printf("%s\n", prntBuf);
5410 SPrint((S8*) "dat: ");
5411 #ifdef XEON_SPECIFIC_CHANGES
5417 sprintf(prntBuf," empty\n");
5419 SPrint( (S8*)"\n\n");
5429 for( j = 0; j < 16; j++)
5435 sprintf( prntBuf,"%02x ",(uint16_t) data);
5437 #ifdef XEON_SPECIFIC_CHANGES
5438 printf("%s\n", prntBuf);
5440 if (cptr == tmp->b_wptr)
5446 /* ss024.103 - Modification to fix bug */
5453 sprintf( prntBuf," ");
5455 #ifdef XEON_SPECIFIC_CHANGES
5456 printf("%s\n", prntBuf);
5460 for (k = 0; k < 16; k++)
5462 if( (i >= mlen) && (k>=(mlen%16)) && mlen%16 != 0)
5464 if (AIsAscii(tdata[k]))
5466 /* print character if printable */
5467 sprintf(prntBuf,"%c",tdata[k]);
5469 #ifdef XEON_SPECIFIC_CHANGES
5470 printf("%s\n", prntBuf);
5475 /* print . if non printable */
5477 #ifdef XEON_SPECIFIC_CHANGES
5482 sprintf(prntBuf,"\n ");
5484 #ifdef XEON_SPECIFIC_CHANGES
5485 printf("%s\n", prntBuf);
5490 } /* end of SPrntMsg */
5496 * Fun: SGetPstMsgMult
5498 * Desc: This function allocates consecutive bytes of data at the
5502 * RFAILED - failed, general (optional)
5503 * ROUTRES - failed, out of resources (optional)
5505 * Notes: if message is empty: message length is incremented.
5508 * if message is not empty: space is allocated in back of
5509 * all other data in message. message length is incremented.
5517 MsgLen cnt, /* count */
5518 Buffer *mBuf /* message buffer */
5528 #if ( ERRCLASS & ERRCLS_INT_PAR )
5529 /* check message buffer */
5539 if (mBuf->b_datap->db_type != SS_M_PROTO)
5544 /* get the message info */
5545 minfo = (SsMsgInfo *) (mBuf->b_rptr);
5550 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
5551 ((avail = tmp->b_datap->db_lim - tmp->b_wptr)))
5553 numBytes = MIN(cnt, avail);
5556 minfo->len += numBytes;
5559 /* ss002.13 addition */
5560 /* ss003.13 addition */
5561 SMemSet( (Void *)tmp->b_wptr, (Data)'\0', (size_t)numBytes);
5563 tmp->b_wptr += numBytes;
5567 if (ssGetDBufOfSize(minfo->region, cnt, &newb) != ROK)
5569 /* ss027.103 - Modification to fix bug in SGetPstMsgMult */
5570 if ((avail) && (tmp))
5571 tmp->b_wptr = tmp->b_datap->db_lim - avail;
5572 minfo->len -= avail;
5579 /* ss002.13: addition */
5580 /* ss003.13: addition */
5581 SMemSet( (Void *)newb->b_wptr, (Data)'\0', (size_t)cnt);
5583 newb->b_wptr += cnt;
5589 mBuf->b_cont = newb;
5591 minfo->endptr = newb;
5600 * Desc: Check Message
5602 * Ret: ROK on success
5605 * Notes: Check that the first buffer in a message
5606 * contains at least two bytes. This check is required
5607 * by 68302/68360 processors to insure accurate fisu
5622 #if ( ERRCLASS & ERRCLS_INT_PAR )
5623 /* check message buffer */
5628 if (mBuf->b_datap->db_type != SS_M_PROTO)
5633 /* get the message info */
5634 minfo = (SsMsgInfo *) (mBuf->b_rptr);
5639 /* get the first M_DATA blk*/
5642 if (((tmp->b_rptr + 2) <= tmp->b_wptr) || (SCompressMsg(mBuf) == ROK))
5650 * Fun: SAlignDBufEven
5652 * Desc: align data portion of a data buffer on an even
5657 * Notes: required for SS7 microcode on the 68302
5664 Buffer *dBuf /* data buffer */
5670 #if (ERRCLASS & ERRCLS_INT_PAR)
5673 SSLOGERROR(ERRCLS_INT_PAR, ESS199, ERRZERO, "SAlignDBufEven : Null\
5677 if (dBuf->b_datap->db_type != SS_M_DATA)
5679 SSLOGERROR(ERRCLS_INT_PAR, ESS200, ERRZERO, "SAlignDBufEven : Incorrect\
5686 /* ss008.13: addition */
5687 if (!((PTR)src % (PTR)2))
5690 if (dBuf->b_datap->db_ref > 1)
5693 len = dBuf->b_wptr - dBuf->b_rptr;
5695 if (dBuf->b_datap->db_base < dBuf->b_rptr)
5697 dBuf->b_wptr = --dBuf->b_rptr;
5699 *dBuf->b_wptr++ = *src++;
5702 if (dBuf->b_datap->db_lim > dBuf->b_wptr)
5704 src = dBuf->b_wptr - 1;
5705 dBuf->b_rptr = ++dBuf->b_wptr;
5707 *--dBuf->b_rptr = *src--;
5715 /* ss004.13: addition */
5720 * Desc: Align data portion of a data buffer on the specified
5721 * boundary. No restriction is imposed on the alignment.
5725 * Notes: required by drivers (68360, 860)
5732 Buffer *dBuf, /* data buffer */
5733 uint32_t align /* alignemnt required */
5738 uint32_t upShift; /* no. of bytes to be shifted up */
5739 uint32_t downShift; /* no. of bytes to be shifted down */
5741 #if (ERRCLASS & ERRCLS_INT_PAR)
5744 SSLOGERROR(ERRCLS_INT_PAR, ESS201, ERRZERO, "SAlignDBuf: Null\
5748 if (dBuf->b_datap->db_type != SS_M_DATA)
5750 SSLOGERROR(ERRCLS_INT_PAR, ESS202, ERRZERO, "SAlignDBuf: Incorrect\
5757 /* ss008.13: addition */
5758 upShift = (PTR)src % (PTR)align; /* no. of bytes by which to shift up
5759 * the read and write pointers */
5764 if (dBuf->b_datap->db_ref > 1)
5767 downShift = align - upShift; /* no of bytes by which to shift down
5768 * the read and write pointers */
5769 len = dBuf->b_wptr - dBuf->b_rptr;
5771 if (dBuf->b_datap->db_base <= (dBuf->b_rptr - upShift))
5773 /* there is space to shift up the read and write pointers */
5775 dBuf->b_rptr -= upShift; /* align the read pointer */
5776 dBuf->b_wptr = dBuf->b_rptr;
5777 SMemCpy( (Void *) dBuf->b_wptr, (Void *) src, (size_t) len);
5778 dBuf->b_wptr = dBuf->b_wptr + len;
5782 if (dBuf->b_datap->db_lim > dBuf->b_wptr + downShift)
5784 src = dBuf->b_wptr - 1;
5785 dBuf->b_wptr = dBuf->b_wptr + downShift;
5786 dBuf->b_rptr = dBuf->b_wptr;
5788 *--dBuf->b_rptr = *src--;
5802 * Desc: Allocates a static buffer pool within the specified
5806 * RFAILED - failed, general (optional)
5808 * Notes: The new memory management scheme makes this function
5809 * meaningless. It merely sets the pool ID to zero and
5817 Region region, /* region ID */
5818 Size size, /* size */
5819 Pool *pool /* pointer to pool ID */
5826 #if (ERRCLASS & ERRCLS_INT_PAR)
5827 /* validate region ID */
5828 if (region >= SS_MAX_REGS)
5830 SSLOGERROR(ERRCLS_INT_PAR, ESS203, region, "Invalid region");
5834 /* validate pointer to pool ID */
5837 SSLOGERROR(ERRCLS_INT_PAR, ESS204, region, "Null pointer");
5843 /* set the pool ID to zero and return success */
5855 * Desc: Deallocates a static buffer pool within the specified
5859 * RFAILED - failed, general (optional)
5861 * Notes: The new memory management scheme makes this function
5862 * meaningless. It does nothing.
5869 Region region, /* region ID */
5870 Pool pool /* pool ID */
5873 /* ss021.103 - Addition of return value */
5874 #if (ERRCLASS & ERRCLS_INT_PAR)
5879 #if (ERRCLASS & ERRCLS_INT_PAR)
5880 /* validate region ID */
5881 if (region >= SS_MAX_REGS)
5883 SSLOGERROR(ERRCLS_INT_PAR, ESS205, region, "Invalid region");
5887 /* validate pool ID */
5888 if (pool >= SS_MAX_POOLS_PER_REG)
5890 SSLOGERROR(ERRCLS_INT_PAR, ESS206, region, "Invalid pool");
5894 /* ss021.103 - Addition to check if region is registered */
5895 /* acquire one semaphore, to protect against deregistration */
5896 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
5900 #if (ERRCLASS & ERRCLS_DEBUG)
5901 SSLOGERROR(ERRCLS_DEBUG, ESS207, (ErrVal) ret,
5902 "Could not lock region table");
5909 #if (ERRCLASS & ERRCLS_INT_PAR)
5910 /* verify that this region is present */
5911 if (osCp.regionTbl[region].used == FALSE)
5913 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
5915 #if (ERRCLASS & ERRCLS_DEBUG)
5916 SSLOGERROR(ERRCLS_DEBUG, ESS208, ERRZERO,
5917 "Could not release semaphore");
5922 SSLOGERROR(ERRCLS_INT_PAR, ESS209, region, "Region not registered");
5927 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
5929 #if (ERRCLASS & ERRCLS_DEBUG)
5930 SSLOGERROR(ERRCLS_DEBUG, ESS210, ERRZERO,
5931 "Could not release semaphore");
5945 * Desc: Checks the available system resources (memory).
5948 * RFAILED - failed, general (optional)
5957 Region region, /* region ID */
5958 Pool pool, /* pool ID */
5959 Status *status /* pointer to status */
5967 #if (ERRCLASS & ERRCLS_INT_PAR)
5968 /* validate region ID */
5969 if (region >= SS_MAX_REGS)
5971 SSLOGERROR(ERRCLS_INT_PAR, ESS229, region, "Invalid region");
5975 /* validate pool ID */
5976 if (pool >= SS_MAX_POOLS_PER_REG)
5978 SSLOGERROR(ERRCLS_INT_PAR, ESS230, region, "Invalid pool");
5982 /* validate status pointer */
5983 if (status == NULLP)
5985 SSLOGERROR(ERRCLS_INT_PAR, ESS231, ERRZERO, "Null pointer");
5989 /* ss037.103 Removed the semaphore operation for performance enhancement */
5992 /* acquire one semaphore, to protect against deregistration */
5993 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
5997 #if (ERRCLASS & ERRCLS_DEBUG)
5998 SSLOGERROR(ERRCLS_DEBUG, ESS232, (ErrVal) ret,
5999 "Could not lock region table");
6006 #if (ERRCLASS & ERRCLS_INT_PAR)
6007 /* verify that this region is around */
6008 if (osCp.regionTbl[region].used == FALSE)
6011 /* ss006.13: addition */
6012 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6014 #if (ERRCLASS & ERRCLS_DEBUG)
6015 SSLOGERROR(ERRCLS_DEBUG, ESS233, ERRZERO,
6016 "Could not release semaphore");
6021 SSLOGERROR(ERRCLS_INT_PAR, ESS234, region, "Region not registered");
6025 /* verify that this is a valid pool */
6026 if (osCp.regionTbl[region].poolTbl[pool].type != SS_POOL_DYNAMIC)
6028 SSLOGERROR(ERRCLS_DEBUG, ESS235, ERRZERO, "Invalid pool");
6034 /* call the memory manager to check resources */
6035 mctl.op = SS_MEM_CHK_RES;
6036 mctl.u.chkres.size = osCp.regionTbl[region].poolTbl[pool].u.dpool.size;
6037 mctl.u.chkres.status = status;
6038 ret = (osCp.regionTbl[region].ctl)
6039 (osCp.regionTbl[region].regCb, SS_MEM_CHK_RES, &mctl);
6041 /* release the semaphore we took */
6043 /* ss006.13: addition */
6044 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6046 #if (ERRCLASS & ERRCLS_DEBUG)
6047 SSLOGERROR(ERRCLS_DEBUG, ESS236, ERRZERO,
6048 "Could not release semaphore");
6061 * Desc: This function will swap two message data contents.
6062 * The original mBuf pointers are unchanged.
6076 Buffer *mBuf1, /* message 1 */
6077 Buffer *mBuf2 /* message 2 */
6082 #if (ERRCLASS & ERRCLS_INT_PAR)
6090 #if (ERRCLASS & ERRCLS_INT_PAR)
6091 /* check message buffer 1 */
6094 SSLOGERROR(ERRCLS_INT_PAR, ESS237, ERRZERO, "SSwapMsg : Null Buffer");
6097 /* check message buffer 2 */
6100 SSLOGERROR(ERRCLS_INT_PAR, ESS238, ERRZERO, "SSwapMsg : Null Buffer");
6103 if (mBuf1->b_datap->db_type != SS_M_PROTO)
6105 SSLOGERROR(ERRCLS_INT_PAR, ESS239, ERRZERO, "SSwapMsg: Incorrect buffer\
6109 if (mBuf2->b_datap->db_type != SS_M_PROTO)
6111 SSLOGERROR(ERRCLS_INT_PAR, ESS240, ERRZERO, "SSwapMsg: Incorrect buffer\
6115 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
6116 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
6117 if (minfo1->region != minfo2->region)
6119 SSLOGERROR(ERRCLS_INT_PAR, ESS241, ERRZERO, "SSwapMsg: differnt regions\
6126 tmp = mBuf1->b_next;
6127 mBuf1->b_next = mBuf2->b_next;
6128 mBuf2->b_next = tmp;
6130 tmp = mBuf1->b_prev;
6131 mBuf1->b_prev = mBuf2->b_prev;
6132 mBuf2->b_prev = tmp;
6134 tmp = mBuf1->b_cont;
6135 mBuf1->b_cont = mBuf2->b_cont;
6136 mBuf2->b_cont = tmp;
6139 #ifdef SS_DBLK_FREE_RTN
6140 tmp = (Buffer *) mBuf1->b_datap->db_frtnp;
6141 mBuf1->b_datap->db_frtnp = mBuf2->b_datap->db_frtnp;
6142 mBuf2->b_datap->db_frtnp = (struct ssfree_rtn *) tmp;
6145 tmp2 = mBuf1->b_datap->db_ref;
6146 mBuf1->b_datap->db_ref = mBuf2->b_datap->db_ref;
6147 mBuf2->b_datap->db_ref = tmp2;
6152 SMemCpy((Void *) minfop, (Void *) (mBuf1->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6153 SMemCpy((Void *) (mBuf1->b_datap->db_base), (Void *) (mBuf2->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6154 SMemCpy((Void *) (mBuf2->b_datap->db_base), (Void *) minfop, (size_t)(sizeof(SsMsgInfo)));
6158 /* ss004.301 : Cavium changes */
6159 #ifdef SS_SEUM_CAVIUM
6165 * Desc: This function will converts the pointer to
6169 * RFAILED - failed, general (optional)
6171 * Notes: Function to convert the Pointer (Virtual address) to
6172 * Physical Address. This will take the Buffer type as
6173 * input and will convert all pointer associated with
6174 * that to Physical Address
6187 SsMsgInfo *minfoPtr;
6192 /* check mBuf for NULLP */
6193 if ( (mBuf == NULLP) || (*mBuf == NULLP ) )
6198 /* first block in Buffer is head */
6200 nextPtr = curPtr->b_cont;
6202 /* Get the physical address of the Pointer */
6205 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6210 curPtr->b_next = (Buffer*)cvmx_ptr_to_phys (curPtr->b_next);
6215 curPtr->b_prev = (Buffer*)cvmx_ptr_to_phys (curPtr->b_prev);
6218 /* Convert the pointers of Minfo to Physical addr */
6219 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6221 if (minfoPtr->endptr)
6223 minfoPtr->endptr = (Buffer*)cvmx_ptr_to_phys (minfoPtr->endptr);
6227 minfoPtr->next = (Buffer*)cvmx_ptr_to_phys (minfoPtr->next);
6230 curPtr->b_rptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_rptr);
6232 curPtr->b_wptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_wptr);
6234 /* Convert the pointers of Dblock to Physical addr */
6235 dblkPtr = (SsDblk*)curPtr->b_datap;
6238 #ifdef SS_DBLK_FREE_RTN
6239 frtnPtr = dblkPtr->db_frtnp;
6240 if( frtnPtr != NULLP)
6242 if (frtnPtr->free_func)
6244 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6246 if (frtnPtr->free_arg)
6248 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6251 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6255 dblkPtr->db_base = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_base);
6256 dblkPtr->db_lim = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6258 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6260 /* second block onwards is dblk */
6265 nextPtr = curPtr->b_cont;
6267 /* Get the physical address of the Pointer */
6270 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6273 curPtr->b_rptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_rptr);
6274 curPtr->b_wptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_wptr);
6276 /* Convert the pointers of Dblock to Physical addr */
6277 dblkPtr = (SsDblk*)curPtr->b_datap;
6280 #ifdef SS_DBLK_FREE_RTN
6281 frtnPtr = dblkPtr->db_frtnp;
6282 if( frtnPtr != NULLP)
6284 if (frtnPtr->free_func)
6286 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6288 if (frtnPtr->free_arg)
6290 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6293 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6297 dblkPtr->db_base = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_base);
6298 dblkPtr->db_lim = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6300 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6306 *mBuf = (Buffer*)cvmx_ptr_to_phys (*mBuf);
6316 * Desc: This function will converts the physical address
6319 * Ret: On Success - Pointer to converted buffer
6320 * On Failuer - Returns NULL
6322 * Notes: Function to Convert the Physical address to Pointer
6323 * (Virtual address) This will take work buffer as input
6324 * and will convert all address associated with that to
6338 SsMsgInfo *minfoPtr;
6343 /* check workPtr for NULLP */
6344 if ( (workPtr == NULLP) || (*workPtr == NULLP) )
6349 /* Convert the buffer address to pointer */
6350 mBuf = (Buffer*)cvmx_phys_to_ptr ((uint64_t)(*workPtr));
6354 /* first block is mblk */
6357 curPtr->b_next = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_next);
6362 curPtr->b_prev = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_prev);
6367 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_cont);
6370 curPtr->b_rptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_rptr);
6372 /* Get the pointer for minfo */
6373 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6375 if (minfoPtr->endptr)
6377 minfoPtr->endptr = (Buffer*)cvmx_phys_to_ptr ((uint64_t)minfoPtr->endptr);
6381 minfoPtr->next = (Buffer*)cvmx_phys_to_ptr ((uint64_t)minfoPtr->next);
6384 curPtr->b_wptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_wptr);
6386 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_datap);
6388 /* Get the Dblock pointers */
6389 dblkPtr = (SsDblk*)curPtr->b_datap;
6392 #ifdef SS_DBLK_FREE_RTN
6393 if (dblkPtr->db_frtnp)
6395 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_frtnp);
6396 frtnPtr = dblkPtr->db_frtnp;
6398 if (frtnPtr->free_func)
6400 frtnPtr->free_func = cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_func);
6402 if (frtnPtr->free_arg)
6404 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_arg);
6409 dblkPtr->db_base = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_base);
6410 dblkPtr->db_lim = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_lim);
6412 curPtr = curPtr->b_cont;
6414 /* after the first block is dblk */
6419 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_cont);
6422 curPtr->b_rptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_rptr);
6424 curPtr->b_wptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_wptr);
6426 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_datap);
6428 /* Get the Dblock pointers */
6429 dblkPtr = (SsDblk*)curPtr->b_datap;
6432 #ifdef SS_DBLK_FREE_RTN
6433 if (dblkPtr->db_frtnp)
6435 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_frtnp);
6437 frtnPtr = dblkPtr->db_frtnp;
6439 if (frtnPtr->free_func)
6441 frtnPtr->free_func = cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_func);
6443 if (frtnPtr->free_arg)
6445 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_arg);
6450 dblkPtr->db_base = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_base);
6451 dblkPtr->db_lim = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_lim);
6453 curPtr = curPtr->b_cont;
6456 /* Place the converted buffer */
6467 * Desc: This function will copy the message from FPA region
6470 * Ret: On Success - ROK
6471 * On Failuer - RFAILED
6473 * Notes: Function to copy the message from FPA region to
6474 * other region. This will internally allocates the
6475 * memory for the destination buffer and copies the
6476 * message in the same chain list
6493 Buffer *curPtr = NULLP;
6495 Buffer *tmpblk = NULLP;
6496 Buffer *newblk = NULLP;
6497 Buffer *prevblk = NULLP;
6498 SsMsgInfo *minfoSrc = NULLP;
6499 SsMsgInfo *minfoDst = NULLP;
6500 SsDblk *dblkPtr = NULLP;
6501 SsDblk *dptr = NULLP;
6504 if ( srcBuf == (Buffer*)NULLP )
6509 if ((dstRegion >= SS_MAX_REGS) || (dstPool >= SS_MAX_POOLS_PER_REG))
6511 /* Free the source buffer and return failure */
6516 /* Allocate memory for destination buffer */
6517 if(SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
6519 /* Free the source buffer and return failure */
6524 /* get the minfo of dest and src buffers */
6525 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
6526 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
6528 curPtr = srcBuf->b_cont;
6530 /* Copy all the blocks associated with this Buffer */
6533 /* Allocate the memeory for dblock */
6535 dblkPtr = (SsDblk*)curPtr->b_datap;
6536 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
6537 size = numBytes + MDBSIZE;
6539 ret = SAlloc( dstRegion, &size, 0, (Data**)&tmpblk);
6543 /* Free all allocated buffers before returning */
6546 tmpblk = newblk->b_cont;
6547 (Void) SPutDBuf(dstRegion, dstPool, newblk);
6550 (Void) SPutMsg(*dstBuf);
6551 /* Free the source buffer and return failure */
6556 dat = (Data *)tmpblk + MDBSIZE;
6557 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
6560 /* Initialize the pointer and copy the data */
6561 INITB( tmpblk, dptr, dat, size, NULLP );
6562 #ifndef SS_DBUF_REFLOCK_DISABLE
6563 SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX);
6565 numBytes = curPtr->b_wptr - curPtr->b_rptr;
6566 /* Copy the data part if its present */
6569 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
6570 tmpblk->b_wptr += numBytes;
6579 prevblk->b_cont = tmpblk;
6583 curPtr = curPtr->b_cont;
6588 tmpblk->b_cont = NULLP;
6591 *minfoDst = *minfoSrc;
6592 minfoDst->region = 0;
6594 minfoDst->len = minfoSrc->len;
6595 minfoDst->endptr = tmpblk;
6596 minfoDst->next = NULLP;
6598 (*dstBuf)->b_cont = newblk;
6600 /* Free the source buffer after copying it */
6611 * Desc: This function will copy the message from any region
6614 * Ret: On Success - ROK
6615 * On Failuer - RFAILED
6617 * Notes: Function will copy the mbuf from msg to FPA.
6618 * This function allocates the memory internally
6619 * and copies the message to newly allocated mBuf.
6620 * The size of mBuf should be either of one
6621 * pre-difined sizes otherwise mBuf is dopped.
6633 Buffer *curPtr = NULLP;
6635 Buffer *tmpblk = NULLP;
6636 Buffer *prevblk = NULLP;
6637 Buffer *newblk = NULLP;
6638 SsMsgInfo *minfoSrc = NULLP;
6639 SsMsgInfo *minfoDst = NULLP;
6640 SsDblk *dblkPtr = NULLP;
6641 SsDblk *dptr = NULLP;
6646 if (srcBuf == (Buffer*)NULLP)
6651 *dstBuf = (Buffer*)cvmx_fpa_alloc(SS_CVMX_POOL_0);
6653 if ( *dstBuf == NULLP )
6655 /* Free the source buffer before returning */
6660 dat = (Data *)(*dstBuf) + MDBSIZE;
6661 dptr = (SsDblk*) ((Data *)(*dstBuf) + MBSIZE);
6662 numBytes = SS_CVMX_POOL_0_SIZE - MDBSIZE;
6664 /* Initialize the pointers of new block */
6665 INITB((*dstBuf), dptr, dat, numBytes, NULLP);
6667 (*dstBuf)->b_datap->db_type = SS_M_PROTO;
6668 (*dstBuf)->b_wptr = (*dstBuf)->b_rptr + sizeof(SsMsgInfo);
6670 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
6671 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
6672 curPtr = srcBuf->b_cont;
6676 dblkPtr = (SsDblk*)curPtr->b_datap;
6678 /* Get the size required which is to be allocated */
6679 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
6680 numBytes += MDBSIZE;
6682 /* get the pool depending on the size need to be allocated */
6685 case SS_CVMX_POOL_0_SIZE:
6687 pool = SS_CVMX_POOL_0;
6690 case SS_CVMX_POOL_1_SIZE:
6692 pool = SS_CVMX_POOL_1;
6695 case SS_CVMX_POOL_2_SIZE:
6697 pool = SS_CVMX_POOL_2;
6700 case SS_CVMX_POOL_3_SIZE:
6702 pool = SS_CVMX_POOL_3;
6706 /* size doesn't match, drop the mBuf and returning
6708 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SCpyMsgFpa: Invalid\
6709 buffer size, dropping the message");
6711 (*dstBuf)->b_cont = newblk;
6712 SPutFpaMsg(*dstBuf);
6713 /* Free the source buffer before returning */
6718 /* Allocate for mBuf and copy both the header and contents */
6719 tmpblk = (Buffer*)cvmx_fpa_alloc(pool);
6721 if ( tmpblk == NULLP )
6723 /* Return error if fails to allocate memory */
6725 (*dstBuf)->b_cont = newblk;
6726 SPutFpaMsg(*dstBuf);
6727 /* Free the source buffer before returning */
6732 dat = (Data *)tmpblk + MDBSIZE;
6733 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
6734 numBytes -= MDBSIZE;
6736 /* Initialize the pointers of new block */
6737 INITB( tmpblk, dptr, dat, numBytes, NULLP );
6739 numBytes = curPtr->b_wptr - curPtr->b_rptr;
6740 /* Copy the message contents */
6743 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
6744 tmpblk->b_wptr += numBytes;
6747 /* Add the mew mBuf to the Buffer chain */
6754 prevblk->b_cont = tmpblk;
6758 /* Get the next block */
6759 curPtr = curPtr->b_cont;
6762 /* Initialize the last mBuf */
6765 tmpblk->b_cont = NULLP;
6768 *minfoDst = *minfoSrc;
6769 minfoDst->region = 0;
6771 minfoDst->len = minfoSrc->len;
6772 minfoDst->endptr = tmpblk;
6773 minfoDst->next = NULLP;
6775 (*dstBuf)->b_cont = newblk;
6777 /* Free the source buffer after copying it */
6788 * Desc: This function will free the Buffer associated with
6791 * Ret: On Success - ROK
6792 * On Failuer - RFAILED
6794 * Notes: Function free the all buffer associated with wqBuf
6795 * This will get the pool id by the size of the buffer
6796 * and same will be used to free the buffer.
6812 if( fpaBuf == NULLP )
6817 curBlk = fpaBuf->b_cont;
6821 nextBlk = curBlk->b_cont;
6823 dblkPtr = (SsDblk*)curBlk->b_datap;
6825 size = dblkPtr->db_lim - dblkPtr->db_base + MDBSIZE;
6827 /* Free the dblock according to its size */
6830 case SS_CVMX_POOL_0_SIZE:
6831 cvmx_fpa_free(curBlk, SS_CVMX_POOL_0, 0);
6834 case SS_CVMX_POOL_1_SIZE:
6835 cvmx_fpa_free(curBlk, SS_CVMX_POOL_1, 0);
6838 case SS_CVMX_POOL_2_SIZE:
6839 cvmx_fpa_free(curBlk, SS_CVMX_POOL_2, 0);
6842 case SS_CVMX_POOL_3_SIZE:
6843 cvmx_fpa_free(curBlk, SS_CVMX_POOL_3, 0);
6847 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SPutFpaMsg: Invalid\
6848 buffer size, dropping the message");
6855 cvmx_fpa_free(fpaBuf, SS_CVMX_POOL_0, 0);
6861 #endif /* SS_SEUM_CAVIUM */
6863 /* ss006.301 : new buffer management APIs, start */
6868 * Desc: This function is used to copy a portion of message(srcBuf) into
6869 * another msg(dstBuf)
6872 * RFAILED - failed, general (optional)
6873 * ROUTRES - failed, out of resources (optional) - In this case
6874 * caller shall reclaim the resources allocated for dstBuf.
6900 #if (ERRCLASS & ERRCLS_INT_PAR)
6903 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null src Buffer");
6906 if (srcBuf->b_datap->db_type != SS_M_PROTO)
6908 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
6914 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null dst Buffer");
6917 if (dstBuf->b_datap->db_type != SS_M_PROTO)
6919 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
6923 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
6925 /* if index > length of mBuf, return */
6926 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
6927 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
6929 if (idx >= sMinfo->len)
6931 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
6936 sBuf = srcBuf->b_cont;
6937 FIND_OFFSET(sBuf, idx)
6941 dBuf = (dMinfo->endptr) ? (dMinfo->endptr) : (dstBuf->b_cont);
6945 crnt = dPrev->b_cont;
6949 crnt = crnt->b_cont;
6956 sCnt = sBuf->b_wptr - (sBuf->b_rptr + idx);
6959 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
6963 /* allocate a data buffer */
6964 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
6966 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyPartMsg : SGetDBuf\
6970 dCnt = MIN(cnt, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
6971 dPrev->b_cont = dBuf;
6974 if(sCnt > cnt) /* src Dblk has enough data to copy */
6978 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
6980 dBuf->b_wptr += dCnt;
6981 dBuf = dBuf->b_cont;
6987 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), cnt);
6988 dBuf->b_wptr += cnt;
6989 dBuf->b_cont = NULLP;
6995 else /* src dBlk has partial data to be copied */
6999 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7000 dBuf->b_wptr += dCnt;
7001 dBuf = dBuf->b_cont;
7008 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), sCnt);
7009 dBuf->b_wptr += sCnt;
7011 sBuf = sBuf->b_cont;
7017 /* update the msgLen in dstBuf */
7018 dMinfo->len += numCpd;
7019 dMinfo->endptr = dBuf;
7028 * Desc: This function is used to replace a portion of message(mBuf) with the
7032 * RFAILED - failed, general (optional)
7058 #if (ERRCLASS & ERRCLS_INT_PAR)
7061 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null dstBuf");
7064 if (dstBuf->b_datap->db_type != SS_M_PROTO)
7066 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7067 dstBuf buffer type");
7072 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null Src Buffer ");
7075 if (srcBuf->b_datap->db_type != SS_M_PROTO)
7077 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7081 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
7083 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
7084 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
7086 if(((idx + cnt) > dMinfo->len) || (cnt < sMinfo->len))
7088 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7093 dBuf = dstBuf->b_cont;
7094 FIND_OFFSET(dBuf, idx)
7095 sBuf = srcBuf->b_cont;
7097 while(cnt && dBuf && sBuf)
7099 dCnt = (dBuf->b_wptr - (dBuf->b_rptr + idx));
7100 sCnt = sBuf->b_wptr - (sBuf->b_rptr + sIdx);
7101 cpBytes = MIN(cnt, sCnt);
7102 cpBytes = MIN(cpBytes, dCnt);
7103 SMemCpy((void*)(dBuf->b_rptr + idx), (void*)(sBuf->b_rptr + sIdx), cpBytes);
7109 /* move to next DBlk in srcBuf */
7110 sBuf = sBuf->b_cont;
7114 else /* cpBytes equals dCnt */
7116 /* move to the next DBlk in dstBuf */
7117 dBuf = dBuf->b_cont;
7131 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : unable to replace\
7143 * Desc: This function will move a portion of the first msg to second msg
7146 * ROKDNA - ok, data not available
7147 * RFAILED - failed, general (optional)
7148 * ROUTRES - failed, out of resources (optional)
7150 * Notes: message 1 is the message from which the segment will be copied
7152 * message 2 is the updated message.
7154 * index is 0 based and indicates location in message 1
7155 * up to which the data will be copied to message 2
7157 * if index is equal to 0, message 1 will not be changed and no data
7158 shall be copied to message 2.
7159 * message 1 is not returned to memory. return is ok.
7161 * if index is not equal to 0 and less than the length of
7162 * the message minus 1: data upto index, shall be copied to message 2
7163 * and read/write pointers of message 1 will be updated accordingly
7165 * if index is not equal to 0 and greater than or equal to
7166 * the length of the message minus 1: all of the message 1 data.
7167 * shall be copied to message 2. return is ok.
7176 Buffer *srcBuf, /* message 1 */
7177 MsgLen idx, /* index */
7178 Buffer *dstBuf /* message 2 */
7188 #ifdef T2K_MEM_LEAK_DBG
7189 char* file = __FILE__;
7190 uint32_t line = __LINE__;
7194 #if (ERRCLASS & ERRCLS_INT_PAR)
7195 /* check message buffer 1 */
7196 if ((!srcBuf) || (!dstBuf ))
7198 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SMovPartMsg : Null Buffer (src or Dst)");
7203 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SMovPartMsg : Invalid index");
7206 if ((srcBuf->b_datap->db_type != SS_M_PROTO) || (dstBuf->b_datap->db_type != SS_M_PROTO))
7208 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SMovPartMsg : Incorrect buffer\
7214 /* get the SsMsgInfo of srcBuf */
7215 sMinfo = (SsMsgInfo*) srcBuf->b_rptr;
7217 /* get the SsMsgInfo of dstBuf */
7218 dMinfo = (SsMsgInfo*) dstBuf->b_rptr;
7220 /* if index > length of mBuf, return */
7222 if (idx > sMinfo->len)
7227 /* one block might not sufficient - Check for generic implementation */
7228 sBuf = srcBuf->b_cont;
7229 /* dBuf = dMinfo->endptr; */
7230 dPrev = (dBuf = dMinfo->endptr) ? dBuf : dstBuf;
7232 /* adjust the lengths of srcBuf, dstBuf */
7238 sCnt = sBuf->b_wptr - sBuf->b_rptr;
7241 /* allocate a data buffer */
7242 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
7244 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyMsgPartMsg : SGetDBuf\
7248 dCnt = MIN(idx, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
7249 dPrev->b_cont = dBuf;
7254 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
7256 if(sCnt > idx) /* src Dblk has enough data to copy */
7260 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7261 dBuf->b_wptr += dCnt;
7262 dBuf = dBuf->b_cont;
7264 sBuf->b_rptr += dCnt;
7268 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), idx);
7269 dBuf->b_wptr += idx;
7270 dBuf->b_cont = NULLP;
7271 sBuf->b_rptr += idx;
7276 else /* src dBlk has partial data to be copied */
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;
7289 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), sCnt);
7290 dBuf->b_wptr += sCnt;
7292 /* deallocate the sBuf here */
7294 /* printf("\nSMovPartMsg() sBuf is completely copied sBuf->b_cont(%p)\n", sBuf->b_cont); */
7295 (Void)SPutDBuf(sMinfo->region, sMinfo->pool, sBuf);
7296 srcBuf->b_cont = sBuf = tmp;
7300 dMinfo->endptr = dBuf;
7305 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SMovPartMsg : unable to copy\
7317 * Desc: This function copies consecutive bytes of data to the
7318 * beginning of a message.
7321 * RFAILED - failed, general (optional)
7322 * ROUTRES - failed, out of resources (optional)
7324 * Notes: if message is empty: data is placed in the message. message
7325 * length is incremented. return is ok.
7327 * if message is not empty: data is read by source pointer,
7328 * data is placed in front of all other data in message.
7329 * message length is incremented. return is ok.
7331 * the first byte of data pointed to by the source pointer
7332 * will be placed at the front of the message first (i.e. it
7333 * will become the first byte of the message) and the last
7334 * byte will be placed in front of the existing msg contents,
7335 * i.e. order of the source is preserved.
7348 SsMsgInfo *minfo; /* Message info */
7351 MsgLen numBytes; /* no. of bytes to be copied */
7355 #if (ERRCLASS & ERRCLS_INT_PAR)
7356 /* check message buffer */
7359 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SPkMsgMult:Null Buffer");
7365 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SPkMsgMult:Null Buffer");
7371 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SPkMsgMult: Invalid\
7375 if (mBuf->b_datap->db_type != SS_M_PROTO)
7377 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SPkMsgMult: Incorrect\
7383 /* get the SsMsgInfo of mBuf */
7384 minfo = (SsMsgInfo*) mBuf->b_rptr;
7386 /* ss014.13: Addition */
7389 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
7390 (tmp->b_datap->db_base < tmp->b_rptr))
7392 /* store the offset of the read pointer of tmp */
7393 offset = tmp->b_rptr - tmp->b_datap->db_base;
7395 /* determine the number of bytes to copy */
7396 numBytes = MIN(cnt, offset);
7401 /* update the read ptr */
7402 tmp->b_rptr -= numBytes;
7404 memcpy(tmp->b_rptr, (src + cnt), numBytes);
7405 minfo->len += numBytes;
7412 /* allocate a DBlk minimum of size Cnt to pack the data */
7414 if (ssGetDBufOfSize(minfo->region, cnt, &newblk) != ROK)
7418 newblk->b_datap->db_type = SS_M_DATA;
7419 newblk->b_rptr = newblk->b_datap->db_lim - cnt;
7420 newblk->b_wptr = newblk->b_datap->db_lim;
7421 memcpy(newblk->b_rptr, src, cnt);
7422 /* attach the newblk chain into mBuf */
7423 newblk->b_cont = tmp;
7424 mBuf->b_cont = newblk;
7426 minfo->endptr = newblk;
7430 /* ss006.301 : new buffer management APIs, end */
7435 * Desc: This function retunrs the pointer to the read the message from mBuf
7438 * RFAILED - failed, general (optional)
7454 if (mBuf && mBuf->b_cont)
7456 *data = mBuf->b_cont->b_rptr;
7457 *len = ((SsMsgInfo*)(mBuf->b_rptr))->len;
7467 #ifdef SS_USE_ZBC_MEMORY
7470 * Fun: SAttachPtrToBuf
7472 * Desc: This function attaches the Pointer provided into a new
7473 * message buffer after allocating the same. It allocates
7474 * header (M-Block) and an additional dBuf (D-Block) and attaches
7475 * the provided pointer to it.
7478 * RFAILED - failed, general (optional)
7479 * ROUTRES - failed, out of resources (optional)
7487 #ifdef T2K_MEM_LEAK_DBG
7488 S16 SAttachPtrToBufNew
7509 SsMsgInfo *minfo; /* Message info */
7513 /* Void *iccHdlr; */
7516 #if (ERRCLASS & ERRCLS_INT_PAR)
7519 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
7524 #ifdef XEON_SPECIFIC_CHANGES
7527 if(SGetMsg(region, pool, mBuf) != ROK)
7529 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
7535 #ifdef SS_HISTOGRAM_SUPPORT
7536 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
7538 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
7539 #endif /* SS_HISTOGRAM_SUPPORT */
7541 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
7546 (*mBuf)->b_cont = newblk;
7548 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
7550 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
7553 newblk->b_datap->db_base = ptr;
7554 newblk->b_datap->db_lim = ptr + totalLen;
7555 newblk->b_rptr = newblk->b_datap->db_base;
7556 newblk->b_wptr = newblk->b_rptr + totalLen;
7558 #ifndef SS_DBUF_REFLOCK_DISABLE
7559 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
7561 printf("\nFalied to destroy lock\n");
7565 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
7567 /* get the SsMsgInfo of mBuf */
7568 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
7569 minfo->len = totalLen;
7570 minfo->endptr = newblk;
7579 * Desc: This function deallocates a buffer back to the
7580 * dynamic memory pool which is allocated for ZBC
7583 * RFAILED - failed, general (optional)
7591 #ifdef T2K_MEM_LEAK_DBG
7592 static S16 SPutZbcDBufNew
7600 static S16 SPutZbcDBuf
7607 register SsDblk *dptr;
7612 dptr = buf->b_datap;
7613 /* Get the length of the buffer */
7614 bufLen = buf->b_datap->db_lim - buf->b_datap->db_base;
7616 /* If the buffer is not shared, free the buffer */
7619 #ifndef SS_DBUF_REFLOCK_DISABLE
7620 SDestroyLock(&dptr->dBufLock);
7623 /* Free the ZBC buffer first and then free the block allocated for the
7626 #ifdef SS_HISTOGRAM_SUPPORT
7627 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
7628 (uint8_t*) __FILE__, ENTNC);
7630 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
7631 #endif /* SS_HISTOGRAM_SUPPORT */
7633 /* if the data block is not shared, free the buffer, checks not reqd */
7634 #ifdef SS_HISTOGRAM_SUPPORT
7635 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__,
7638 ret = SFree(region, (Data *) buf, MDBSIZE);
7639 #endif /* SS_HISTOGRAM_SUPPORT */
7641 /* If the buffer is shared, reduce the refernce count and free the buffer
7642 * if reference count falls to zero */
7645 #ifndef SS_DBUF_REFLOCK_DISABLE
7646 if((ret=SLock(&dptr->dBufLock)))
7648 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
7649 "Could not lock the mBuf Ref Lock");
7654 /* if buffer's message blk is obtained during dupb */
7655 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
7657 #ifdef SS_HISTOGRAM_SUPPORT
7658 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__, ENTNC);
7660 ret = SFree(region, (Data *) buf, MDBSIZE);
7661 #endif /* SS_HISTOGRAM_SUPPORT */
7662 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
7664 /* if reference count falls to zero */
7667 #ifndef SS_DBUF_REFLOCK_DISABLE
7668 ret = SUnlock(&dptr->dBufLock) ;
7669 if((SDestroyLock(&dptr->dBufLock)) != 0)
7671 printf("\nFalied to destroy lock\n");
7674 #ifdef SS_HISTOGRAM_SUPPORT
7675 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
7676 (uint8_t*) __FILE__, ENTNC);
7678 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
7679 #endif /* SS_HISTOGRAM_SUPPORT */
7681 #ifdef SS_HISTOGRAM_SUPPORT
7682 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__,
7685 ret = SFree(region, (Data *) buf, MDBSIZE);
7686 #endif /* SS_HISTOGRAM_SUPPORT */
7689 #ifndef SS_DBUF_REFLOCK_DISABLE
7690 ret = SUnlock(&(dptr->dBufLock));
7696 #endif /* SS_USE_ZBC_MEMORY */
7702 * Fun: SAttachPtrToMBuf
7704 * Desc: This function attaches the Pointer provided into a new
7705 * message buffer after allocating the same. It allocates
7706 * header (M-Block) and an additional dBuf (D-Block) and attaches
7707 * the provided pointer to it.
7710 * RFAILED - failed, general (optional)
7711 * ROUTRES - failed, out of resources (optional)
7718 #ifdef T2K_MEM_LEAK_DBG
7719 S16 SAttachPtrToMBuf1
7731 S16 SAttachPtrToMBuf
7742 SsMsgInfo *minfo; /* Message info */
7746 /* Void *iccHdlr; */
7749 #if (ERRCLASS & ERRCLS_INT_PAR)
7752 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
7757 if(SGetMsg(region, pool, mBuf) != ROK)
7759 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
7766 #ifdef SS_HISTOGRAM_SUPPORT
7767 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
7769 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
7770 #endif /* SS_HISTOGRAM_SUPPORT */
7772 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
7777 (*mBuf)->b_cont = newblk;
7779 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
7781 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
7784 newblk->b_datap->db_base = ptr;
7785 newblk->b_datap->db_lim = ptr + ptrLen;
7786 newblk->b_rptr = newblk->b_datap->db_base;
7787 newblk->b_wptr = newblk->b_rptr + totalLen;
7789 #ifndef SS_DBUF_REFLOCK_DISABLE
7790 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
7792 printf("\nFalied to destroy lock\n");
7796 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
7798 /* get the SsMsgInfo of mBuf */
7799 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
7800 minfo->len = totalLen;
7801 minfo->endptr = newblk;
7803 //printf("\nMbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
7806 #endif /* INTEL_WLS */
7807 S16 SIncMsgRef(Buffer *srcBuf,Region dstRegion, Pool dstPool,Buffer **dstBuf)
7810 return (SAddMsgRef(srcBuf,dstRegion, dstPool,dstBuf));
7817 Void SResetMBuf(Buffer *mbuf)
7823 minfo = (SsMsgInfo *) mbuf->b_rptr;
7824 //tmp = minfo->endptr;
7831 // 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 );
7832 // tmp->b_wptr = tmp->b_rptr = tmp->b_datap->db_base;
7833 tmp->b_wptr = tmp->b_rptr = (tmp->b_datap->db_base + 5);
7834 tmp->b_datap->db_ref = 1;
7835 tmp->b_datap->shared = 0;
7847 * Fun: SAttachWlsPtrToMBuf
7849 * Desc: This function attaches the Pointer provided into a new
7850 * message buffer after allocating the same. It allocates
7851 * header (M-Block) and an additional dBuf (D-Block) and attaches
7852 * the provided pointer to it.
7855 * RFAILED - failed, general (optional)
7856 * ROUTRES - failed, out of resources (optional)
7863 #ifdef T2K_MEM_LEAK_DBG
7864 S16 SAttachWlsPtrToMBuf1
7877 S16 SAttachWlsPtrToMBuf
7889 SsMsgInfo *minfo; /* Message info */
7893 /* Void *iccHdlr; */
7896 #if (ERRCLASS & ERRCLS_INT_PAR)
7899 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
7905 if(SGetMsg(region, pool, mBuf) != ROK)
7907 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
7913 #ifdef SS_HISTOGRAM_SUPPORT
7914 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
7916 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
7917 #endif /* SS_HISTOGRAM_SUPPORT */
7919 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
7924 (*mBuf)->b_cont = newblk;
7926 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
7928 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
7931 newblk->b_datap->db_base = ptr;
7932 newblk->b_datap->db_lim = ptr + ptrLen;
7933 newblk->b_rptr = readPtr;
7934 newblk->b_wptr = newblk->b_rptr + totalLen;
7936 #ifndef SS_DBUF_REFLOCK_DISABLE
7937 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
7939 printf("\nFalied to destroy lock\n");
7943 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
7945 /* get the SsMsgInfo of mBuf */
7946 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
7947 minfo->len = totalLen;
7948 minfo->endptr = newblk;
7950 //printf("\nMbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
7954 #ifdef TENB_DPDK_BUF
7960 Data **ptr, /* pointer to buffer */
7961 Size size /* size requested */
7966 *ptr = ntl_alloc(mtGetNtlHdl(), size);
7973 Data *ptr /* pointer to buffer */
7979 ntl_free(mtGetNtlHdl(), ptr);
7984 S16 SDetachDpdkPtrFrmDBuf
7994 //msgBlk = mBuf->b_cont;
7995 //*ptr = msgBlk->b_rptr;
7996 *ptr = mBuf->b_datap->db_base;
7998 mBuf->b_cont = NULL;
8000 //minfo = (SsMsgInfo*) mBuf->b_rptr;
8008 S16 SDetachDpdkPtrFrmMBuf
8017 register SsDblk *dptr;
8021 msgBlk = mBuf->b_cont;
8028 dptr = msgBlk->b_datap;
8029 if(dptr->db_type != SS_MEM_TYPE_DPDK_ZBC)
8035 *ptr = msgBlk->b_rptr;
8037 mBuf->b_cont = NULL;
8039 minfo = (SsMsgInfo*) mBuf->b_rptr;
8046 S16 SAttachDpdkPtrToMBuf
8063 SAttachWlsPtrToMBuf(region, pool, ptr, readPtr, msgLen, totalLen, mBuf);
8064 dptr = (SsDblk*) (((Data *) ((*mBuf)->b_cont)) + MBSIZE);
8066 dptr->db_type = SS_MEM_TYPE_DPDK_ZBC;
8071 #endif /* TENB_DPDK_BUF */
8073 #endif /* INTEL_WLS */
8075 /**********************************************************************
8077 **********************************************************************/