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
271 S16 ssGetDBufOfSize(region, size, dBuf)
282 #if (ERRCLASS & ERRCLS_INT_PAR)
283 /* check buffer pointer */
286 SSLOGERROR(ERRCLS_INT_PAR, ESS047, ERRZERO, "ssGetDBufOfSize : Null\
290 if (region >= SS_MAX_REGS)
292 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "ssGetDBufOfSize : Invalid\
299 SSLOGERROR(ERRCLS_INT_PAR, ESS049, ERRZERO, "ssGetDBufOfSize : Invalid\
305 /* ss006.301 : optmized this function */
306 mdsize = MDBSIZE + size;
307 #ifdef SS_HISTOGRAM_SUPPORT
308 if (SAlloc(region, &mdsize, 0, (Data **) dBuf, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
310 if (SAlloc(region, &mdsize, 0, (Data **) dBuf) != ROK)
311 #endif /* SS_HISTOGRAM_SUPPORT */
315 data = (Data *) (*dBuf) + MDBSIZE;
316 size = mdsize - MDBSIZE;
318 dptr = (SsDblk*) (((Data *) (*dBuf)) + MBSIZE);
320 INITB((*dBuf), dptr, data, size, NULLP)
321 #ifndef SS_DBUF_REFLOCK_DISABLE
322 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
324 SSLOGERROR(ERRCLS_DEBUG, ESS056, ERRZERO,"Falied to initalize lock");
329 } /* ssGetDBufOfSize */
336 * Desc: This function gets a message
339 * RFAILED - failed, general (optional)
340 * ROUTRES - failed, out of resources (optional)
342 * Notes: message is created. message is set to type SS_M_PROTO.
343 * message is returned via message buffer pointer.
349 /* ss001.301: additions */
350 #ifdef SS_HISTOGRAM_SUPPORT
354 Region region, /* region id */
355 Pool pool, /* pool id */
356 Buffer **mBuf, /* pointer to message buffer */
361 S16 SGetMsgNew(region, pool, mBuf, line, fileName)
362 Region region; /* region id */
363 Pool pool; /* pool id */
364 Buffer **mBuf; /* pointer to message buffer */
368 #else /* SS_HISTOGRAM_SUPPORT */
369 #ifdef T2K_MEM_LEAK_DBG
372 Region region, /* region id */
373 Pool pool, /* pool id */
374 Buffer **mBuf, /* pointer to message buffer */
382 Region region, /* region id */
383 Pool pool, /* pool id */
384 Buffer **mBuf /* pointer to message buffer */
387 S16 SGetMsg(region, pool, mBuf)
388 Region region; /* region id */
389 Pool pool; /* pool id */
390 Buffer **mBuf; /* pointer to message buffer */
393 #endif /* SS_HISTOGRAM_SUPPORT */
399 /* ss001.301: additions */
400 #ifdef SS_HISTOGRAM_SUPPORT
402 #endif /* SS_HISTOGRAM_SUPPORT */
404 /* ss021.103 - Addition of return value */
406 #if (ERRCLASS & ERRCLS_INT_PAR)
412 #ifdef XEON_SPECIFIC_CHANGES
417 #if (ERRCLASS & ERRCLS_INT_PAR)
418 /* check buffer pointer */
421 SSLOGERROR(ERRCLS_INT_PAR, ESS050, ERRZERO, "SGetMsg : Null Buffer");
424 if (region >= SS_MAX_REGS)
426 SSLOGERROR(ERRCLS_INT_PAR, ESS051, ERRZERO, "SGetMsg : Invalid region\
431 if (pool >= SS_MAX_POOLS_PER_REG)
433 SSLOGERROR(ERRCLS_INT_PAR, ESS052, ERRZERO, "SGetMsg : Invalid pool id");
437 /* ss037.103 Removed the semaphore operation for performance enhancement */
440 /* ss021.103 - Addition to check if region is registered */
441 /* acquire one semaphore, to protect against deregistration */
442 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
446 #if (ERRCLASS & ERRCLS_DEBUG)
447 SSLOGERROR(ERRCLS_DEBUG, ESS053, (ErrVal) ret,
448 "Could not lock region table");
455 #if (ERRCLASS & ERRCLS_INT_PAR)
456 /* verify that this region is present */
457 if (osCp.regionTbl[region].used == FALSE)
459 /* ss037.103 Removed the semaphore operation for performance enhancement */
462 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
464 #if (ERRCLASS & ERRCLS_DEBUG)
465 SSLOGERROR(ERRCLS_DEBUG, ESS054, ERRZERO,
466 "Could not release semaphore");
471 SSLOGERROR(ERRCLS_INT_PAR, ESS055, region, "Region not registered");
474 /* ss037.103 Removed the semaphore operation for performance enhancement */
477 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
479 #if (ERRCLASS & ERRCLS_DEBUG)
480 SSLOGERROR(ERRCLS_DEBUG, ESS056, ERRZERO,
481 "Could not release semaphore");
488 /* ss001.301: additions */
489 #ifdef SS_HISTOGRAM_SUPPORT
490 SGetEntInd(&entId, fileName);
491 #endif /* SS_HISTOGRAM_SUPPORT */
493 /* ss012.13: Addition */
494 #ifdef SS_M_PROTO_REGION
495 /* ss001.301: additions */
496 #ifdef SS_HISTOGRAM_SUPPORT
497 if (SAlloc(region, &size, 0, (Data**) mBuf, line, fileName, entId) != ROK)
499 if (SAlloc(region, &size, 0, (Data**) mBuf) != ROK)
500 #endif /* SS_HISTOGRAM_SUPPORT */
502 SSLOGERROR(ERRCLS_DEBUG, ESS058, ERRZERO, "SGetMsg:Failed in SAlloc");
505 #else /* SS_M_PROTO_REGION */
506 /* ss001.301: additions */
507 #ifdef SS_HISTOGRAM_SUPPORT
508 if (SAlloc(SS_DFLT_REGION, &size, 0, (Data**) mBuf, line, fileName, entId) != ROK)
510 if (SAlloc(region, &size, 0, (Data**) mBuf) != ROK)
511 #endif /* SS_HISTOGRAM_SUPPORT */
513 SSLOGERROR(ERRCLS_DEBUG, ESS059, ERRZERO, "SGetMsg:Failed in SAlloc");
516 #endif /* SS_M_PROTO_REGION */
518 dptr = (SsDblk*) (((Data *) (*mBuf)) + MBSIZE);
519 data = (Data*) (((Data *) (*mBuf)) + MDBSIZE);
521 /* INITB initialises and sets up the message blk */
522 INITB((*mBuf), dptr, data, sizeof(SsMsgInfo), NULLP)
524 (*mBuf)->b_datap->db_type = SS_M_PROTO;
525 (*mBuf)->b_wptr = (*mBuf)->b_rptr + sizeof(SsMsgInfo);
527 /* initialise message info of mBuf */
528 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
530 minfo->region = region;
533 minfo->endptr = NULLP;
534 minfo->eventInfo.event = SS_EVNT_DATA;
535 /* ss021.103 - Addition to initialize next and route */
539 if(clusterMode == RADIO_CLUSTER_MODE)
548 #ifdef RGL_SPECIFIC_CHANGES
549 S16 SSetMBufPool(Buffer *mBuf, Pool pool)
554 minfo = (SsMsgInfo*) mBuf->b_rptr;
561 /* #ifdef SS_LOCKLESS_MEMORY */
567 * Desc: This function deallocates a message back.
570 * RFAILED - failed, general (optional)
572 * Notes: all data attached to message is returned to memory.
573 * message is returned to memory. return is ok.
578 /* ss001.301: additions */
579 #ifdef SS_HISTOGRAM_SUPPORT
588 S16 SPutMsgNew(mBuf, line, fileName)
593 #else /* SS_HISTOGRAM_SUPPORT */
594 #ifdef T2K_MEM_LEAK_DBG
612 #endif /* SS_HISTOGRAM_SUPPORT */
616 #ifdef SS_MEM_WL_DEBUG
620 /* ss001.301: additions */
621 #ifdef SS_HISTOGRAM_SUPPORT
623 #endif /* SS_HISTOGRAM_SUPPORT */
626 //#ifdef RADIO_CLUSTER
627 if(clusterMode == RADIO_CLUSTER_MODE)
633 if (mBuf->refCnt > 0)
639 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
641 pthread_t gMacTId,gRlcTId;
643 if(clusterMode == RADIO_CLUSTER_MODE)
646 #ifdef MAC_FREE_RING_BUF
647 if(pthread_self() == gMacTId)
648 //if(pthread_equal(pthread_self(),gMacTId))
650 if(ROK == mtAddBufToRing(SS_RNG_BUF_MAC_FREE_RING,(Void *)mBuf,0))
656 #ifdef RLC_FREE_RING_BUF
657 else if(pthread_self() == gRlcTId)
659 if(ROK == mtAddBufToRing(SS_RNG_BUF_RLC_FREE_RING,(Void *)mBuf,0))
669 #if (ERRCLASS & ERRCLS_INT_PAR)
672 SSLOGERROR(ERRCLS_INT_PAR, ESS060, ERRZERO, "SPutMsg: Null Buffer");
675 if (mBuf->b_datap->db_type != SS_M_PROTO)
677 SSLOGERROR(ERRCLS_INT_PAR, ESS061, ERRZERO, "SPutMsg: Incorrect buffer\
683 #ifdef SS_MEM_WL_DEBUG
684 CM_MEM_GET_REGION(tmpThrReg)
685 if(tmpThrReg == 0xFF)
687 printf("\n Not able to get region \n");
692 /* get the message info */
693 minfo = (SsMsgInfo *) mBuf->b_rptr;
695 while ((tmp = mBuf->b_cont))
697 /* set b_cont of mBuf to point to the b_cont of tmp */
698 mBuf->b_cont = tmp->b_cont;
699 #ifdef SS_MEM_WL_DEBUG
700 (Void) SPutDBuf(tmpThrReg, minfo->pool, tmp);
702 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
706 /* ss001.301: additions */
707 #ifdef SS_HISTOGRAM_SUPPORT
708 SGetEntInd(&entId, fileName);
709 #endif /* SS_HISTOGRAM_SUPPORT */
711 /* ss012.13: Addition */
712 #ifdef SS_M_PROTO_REGION
713 /* ss021.103 - Addition to check return value of SFree */
714 #ifdef SS_HISTOGRAM_SUPPORT
715 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE, line, fileName, entId) == RFAILED)
717 #ifdef SS_MEM_WL_DEBUG
718 if (SFree(tmpThrReg, (Data *) mBuf, MSGSIZE) == RFAILED)
720 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE) == RFAILED)
722 #endif /* SS_HISTOGRAM_SUPPORT */
724 #else /* SS_M_PROTO_REGION */
725 /* ss021.103 - Addition to check return value of SFree */
726 #ifdef SS_HISTOGRAM_SUPPORT
727 if (SFree(SS_DFLT_REGION, (Data *) mBuf, MSGSIZE, line, fileName, entId) == RFAILED)
729 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE) == RFAILED)
730 #endif /* SS_HISTOGRAM_SUPPORT */
732 #endif /* SS_M_PROTO_REGION */
737 #ifdef SS_LOCKLESS_MEMORY
740 * Fun: SPutStaticBuffer
742 * Desc: Returns a buffer to the specified static pool in the
743 * specified memory region.
746 * RFAILED - failed, general (optional)
753 /* ss001.301: additions */
754 #ifdef T2K_MEM_LEAK_DBG
755 S16 SPutStaticBufferNew
757 Region region, /* region ID */
758 Pool pool, /* pool ID */
759 Data *ptr, /* pointer to buffer */
760 Size size, /* size */
761 uint8_t memType, /* memory type used if shareable or not */
769 Region region, /* region ID */
770 Pool pool, /* pool ID */
771 Data *ptr, /* pointer to buffer */
772 Size size, /* size */
773 uint8_t memType /* memory type used if shareable or not */
776 S16 SPutStaticBuffer(region, pool, ptr, size)
777 Region region; /* region ID */
778 Pool pool; /* pool ID */
779 Data *ptr; /* pointer to buffer */
780 Size size; /* size */
781 uint8_t memType; /* memory type used if shareable or not */
787 #if (ERRCLASS & ERRCLS_INT_PAR)
788 /* validate region ID */
789 if (region >= SS_MAX_REGS)
791 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
795 /* validate pool ID */
796 if (pool >= SS_MAX_POOLS_PER_REG)
798 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
801 /* validate data pointer */
804 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
811 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
815 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
817 pthread_t gMacTId,gRlcTId;
819 if(clusterMode == RADIO_CLUSTER_MODE)
821 #ifdef MAC_FREE_RING_BUF
822 if(pthread_self() == gMacTId)
823 //if(pthread_equal(pthread_self(),gMacTId))
825 if(ROK == mtAddBufToRing(SS_RNG_BUF_MAC_FREE_RING,(Void *)ptr,1))
831 #ifdef RLC_FREE_RING_BUF
832 else if(pthread_self() == gRlcTId)
834 if(ROK == mtAddBufToRing(SS_RNG_BUF_RLC_FREE_RING,(Void *)ptr,1))
843 region = SS_GET_THREAD_MEM_REGION();
846 #if (ERRCLASS & ERRCLS_INT_PAR)
847 /* verify that this region is present */
848 if (((memType == SS_NON_SHARABLE_MEMORY) &&
849 (osCp.regionTbl[region].used == FALSE)) ||
850 ((memType == SS_SHARABLE_MEMORY) &&
851 (osCp.dynRegionTbl[region].used == FALSE)))
853 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
858 /* call the memory manager, to allocate this memory */
859 #ifndef SS_DBUF_REFLOCK_DISABLE
860 if(memType == SS_NON_SHARABLE_MEMORY)
862 #ifndef T2K_MEM_LEAK_DBG
863 ret = (osCp.regionTbl[region].free)
864 (osCp.regionTbl[region].regCb, ptr, size);
866 ret = (osCp.regionTbl[region].free)
867 (osCp.regionTbl[region].regCb, ptr, size, file, line);
871 else if(memType == SS_SHARABLE_MEMORY)
875 #ifndef T2K_MEM_LEAK_DBG
876 ret = (osCp.dynRegionTbl[region].free)
877 (osCp.dynRegionTbl[region].regCb, ptr, size);
879 ret = (osCp.dynRegionTbl[region].free)
880 (osCp.dynRegionTbl[region].regCb, ptr, size,file,line);
882 #ifndef SS_DBUF_REFLOCK_DISABLE
891 * Fun: SGetStaticBuffer
893 * Desc: Allocates a buffer from the specified static memory pool
894 * in the specified region. Depending on the type wheather
895 * the buffer is sharable or non-sharable indicated by the
896 * memType prameter allocation region is choosen
900 * RFAILED - failed, general (optional)
907 #ifdef T2K_MEM_LEAK_DBG
908 S16 SGetStaticBufferNew
910 Region region, /* region ID */
911 Pool pool, /* pool ID */
912 Data **ptr, /* pointer to buffer */
913 Size size, /* size requested */
914 uint8_t memType, /* memory type used if shareable or not */
922 Region region, /* region ID */
923 Pool pool, /* pool ID */
924 Data **ptr, /* pointer to buffer */
925 Size size, /* size requested */
926 uint8_t memType /* memory type used if shareable or not */
929 S16 SGetStaticBuffer(region, pool, ptr, size)
930 Region region; /* region ID */
931 Pool pool; /* pool ID */
932 Data **ptr; /* pointer to buffer */
933 Size size; /* size requested */
934 uint8_t memType; /* memory type used if shareable or not */
941 #if (ERRCLASS & ERRCLS_INT_PAR)
942 /* validate region ID */
943 if (region >= SS_MAX_REGS)
945 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
949 /* validate pool ID */
950 if (pool >= SS_MAX_POOLS_PER_REG)
952 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
955 /* validate data pointer */
958 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
965 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
970 #if (ERRCLASS & ERRCLS_INT_PAR)
971 /* verify that this region is present */
972 if (((memType == SS_NON_SHARABLE_MEMORY) &&
973 (osCp.regionTbl[region].used == FALSE)) ||
974 ((memType == SS_SHARABLE_MEMORY) &&
975 (osCp.dynRegionTbl[region].used == FALSE)))
977 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
984 region = SS_GET_THREAD_MEM_REGION();
986 if (region == SS_STATIC_REGION)
990 /* call the memory manager, to allocate this memory */
991 #ifndef SS_DBUF_REFLOCK_DISABLE
992 if(memType == SS_NON_SHARABLE_MEMORY)
994 #ifndef T2K_MEM_LEAK_DBG
995 ret = (osCp.regionTbl[region].alloc)
996 (osCp.regionTbl[region].regCb, &size, flags, ptr);
998 ret = (osCp.regionTbl[region].alloc)
999 (osCp.regionTbl[region].regCb, &size, flags, ptr, file,line);
1002 else if(memType == SS_SHARABLE_MEMORY)
1005 #ifndef T2K_MEM_LEAK_DBG
1006 ret = (osCp.dynRegionTbl[region].alloc)
1007 (osCp.dynRegionTbl[region].regCb, &size, flags, ptr);
1009 ret = (osCp.dynRegionTbl[region].alloc)
1010 (osCp.dynRegionTbl[region].regCb, &size, flags, ptr,file,line);
1012 #ifndef SS_DBUF_REFLOCK_DISABLE
1018 #endif /* SS_LOCKLESS_MEMORY */
1021 #ifndef SS_LOCKLESS_MEMORY
1023 S16 SGetStaticBuffer
1025 Region region, /* region ID */
1026 Pool pool, /* pool ID */
1027 Data **ptr, /* pointer to buffer */
1028 Size size, /* size requested */
1029 uint8_t memType /* memory type used if shareable or not */
1032 S16 SGetStaticBuffer(region, pool, ptr, size)
1033 Region region; /* region ID */
1034 Pool pool; /* pool ID */
1035 Data **ptr; /* pointer to buffer */
1036 Size size; /* size requested */
1037 uint8_t memType; /* memory type used if shareable or not */
1042 ret = SGetSBuf(region, pool, ptr, size);
1049 S16 SPutStaticBuffer
1051 Region region, /* region ID */
1052 Pool pool, /* pool ID */
1053 Data *ptr, /* pointer to buffer */
1054 Size size, /* size */
1055 uint8_t memType /* memory type used if shareable or not */
1058 S16 SPutStaticBuffer(region, pool, ptr, size)
1059 Region region; /* region ID */
1060 Pool pool; /* pool ID */
1061 Data *ptr; /* pointer to buffer */
1062 Size size; /* size */
1063 uint8_t memType; /* memory type used if shareable or not */
1069 ret = SPutSBuf(region, pool, ptr, size);
1075 #ifdef T2K_MEM_LEAK_DBG
1078 Region region, /* region ID */
1079 Pool pool, /* pool ID */
1080 Data **ptr, /* pointer to buffer */
1081 Size size, /* size requested */
1088 Region region, /* region ID */
1089 Pool pool, /* pool ID */
1090 Data **ptr, /* pointer to buffer */
1091 Size size /* size requested */
1096 #ifndef SS_LOCKLESS_MEMORY
1100 #ifdef SS_LOCKLESS_MEMORY
1101 region = SS_GET_THREAD_MEM_REGION();
1102 ret = SAlloc(region, &size, 0, ptr);
1105 #ifdef T2K_MEM_LEAK_DBG
1106 ret = (osCp.regionTbl[region].alloc)
1107 (osCp.regionTbl[region].regCb, &size, flags, ptr,file,line);
1109 ret = (osCp.regionTbl[region].alloc)
1110 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1117 #ifdef T2K_MEM_LEAK_DBG
1120 Region region, /* region ID */
1121 Pool pool, /* pool ID */
1122 Data *ptr, /* pointer to buffer */
1123 Size size, /* size */
1130 Region region, /* region ID */
1131 Pool pool, /* pool ID */
1132 Data *ptr, /* pointer to buffer */
1133 Size size /* size */
1139 #ifdef SS_LOCKLESS_MEMORY
1140 region = SS_GET_THREAD_MEM_REGION();
1141 ret = SFree(region, ptr, size);
1144 #ifdef T2K_MEM_LEAK_DBG
1145 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,file,line);
1147 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1154 #endif /* INTEL_WLS */
1161 * Desc: Allocates a buffer from the specified static memory pool
1162 * in the specified region.
1165 * RFAILED - failed, general (optional)
1167 * Notes: The new memory management scheme eliminates the concept
1168 * of pools. This call maps directly to a call to the memory
1174 /* ss001.301: additions */
1175 #ifdef SS_HISTOGRAM_SUPPORT
1179 Region region, /* region ID */
1180 Pool pool, /* pool ID */
1181 Data **ptr, /* pointer to buffer */
1182 Size size, /* size requested */
1187 S16 SGetSBufNew(region, pool, ptr, size, line, fileName)
1188 Region region; /* region ID */
1189 Pool pool; /* pool ID */
1190 Data **ptr; /* pointer to buffer */
1191 Size size; /* size requested */
1195 #else /* SS_HISTOGRAM_SUPPORT */
1196 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1200 Region region, /* region ID */
1201 Pool pool, /* pool ID */
1202 Data **ptr, /* pointer to buffer */
1203 Size size, /* size requested */
1208 S16 SGetSBuf1(region, pool, ptr, size, file, line)
1209 Region region; /* region ID */
1210 Pool pool; /* pool ID */
1211 Data **ptr; /* pointer to buffer */
1212 Size size; /* size requested */
1220 Region region, /* region ID */
1221 Pool pool, /* pool ID */
1222 Data **ptr, /* pointer to buffer */
1223 Size size /* size requested */
1226 S16 SGetSBuf(region, pool, ptr, size)
1227 Region region; /* region ID */
1228 Pool pool; /* pool ID */
1229 Data **ptr; /* pointer to buffer */
1230 Size size; /* size requested */
1233 #endif /* SS_HISTOGRAM_SUPPORT */
1237 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1241 #ifdef SS_HISTOGRAM_SUPPORT
1243 Bool hstReg = FALSE;
1244 #endif /* SS_HISTOGRAM_SUPPORT */
1247 region = SS_GET_THREAD_MEM_REGION();
1250 #endif /* INTEL_WLS */
1252 #if (ERRCLASS & ERRCLS_INT_PAR)
1253 /* validate region ID */
1254 if (region >= SS_MAX_REGS)
1256 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
1260 /* validate pool ID */
1261 if (pool >= SS_MAX_POOLS_PER_REG)
1263 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
1266 /* ss008.13: addition */
1267 /* validate data pointer */
1270 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
1277 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
1281 /* ss037.103 Removed the semaphore operation for performance enhancement */
1283 #ifndef RGL_SPECIFIC_CHANGES
1284 region = SS_GET_THREAD_MEM_REGION();
1287 /* acquire one semaphore, to protect against deregistration */
1288 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1292 #if (ERRCLASS & ERRCLS_DEBUG)
1293 SSLOGERROR(ERRCLS_DEBUG, ESS216, (ErrVal) ret,
1294 "Could not lock region table");
1302 #if (ERRCLASS & ERRCLS_INT_PAR)
1303 /* verify that this region is present */
1304 if (osCp.regionTbl[region].used == FALSE)
1308 /* ss006.13: addition */
1309 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1311 #if (ERRCLASS & ERRCLS_DEBUG)
1312 SSLOGERROR(ERRCLS_DEBUG, ESS217, ERRZERO,
1313 "Could not release semaphore");
1318 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
1327 /* ss024.103 - Addition for memory calculator tool */
1329 if (region == SS_STATIC_REGION)
1333 /* ss001.301: additions */
1334 #ifdef SS_HISTOGRAM_SUPPORT
1336 SGetEntInd(&entId, fileName);
1337 /* Get the Information from the oscp that the tapa task with the entity
1338 id (entid) is registed for histogram or not */
1339 SGetHstGrmInfo(&entId, &hstReg);
1340 /* call the memory manager, to allocate this memory */
1341 #ifdef SSI_DEBUG_LEVEL1
1342 ret = (osCp.regionTbl[region].alloc)
1343 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1344 SS_STATIC_MEM_FLAG, line, fileName, entId, hstReg);
1346 ret = (osCp.regionTbl[region].alloc)
1347 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1348 line, fileName, entId, hstReg);
1349 #endif /* SSI_DEBUG_LEVEL1 */
1353 /* call the memory manager, to allocate this memory */
1354 /* ss036.103 - addition for passing additional parameter memType as static */
1355 #ifdef SSI_DEBUG_LEVEL1
1356 ret = (osCp.regionTbl[region].alloc)
1357 (osCp.regionTbl[region].regCb, &size, flags, ptr, SS_STATIC_MEM_FLAG);
1359 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1360 /* Static mem leak detection changes */
1362 #ifdef T2K_MEM_LEAK_DBG
1363 ret = (osCp.regionTbl[region].alloc)
1364 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr, file, line);
1366 ret = (osCp.regionTbl[region].alloc)
1367 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr);
1369 /*size = tmpSize - 4;*/
1371 /*printf("ptr = %p *ptr = %p\n",ptr,*ptr);*/
1372 #ifdef XEON_SPECIFIC_CHANGES
1373 pthread_mutex_lock(&(memLock));
1375 uint32_t idx = GetNextFreeIdx(&SMemLeakInfo[region]);
1376 uint8_t* allocatedPtr = *ptr;
1377 void* actualPtr = allocatedPtr + 4;
1379 /* store the index in the memory allocated itself */
1380 /**((uint32_t*)*((uint32_t*)allocatedPtr)) = idx;*/
1381 *((uint32_t*)allocatedPtr) = idx;
1382 /*printf("region = %d idx = %d ptr = %p *ptr = %p actual = %p allocated = %p content = %d\n",region, idx, ptr, *ptr, actualPtr, allocatedPtr, *((uint32_t*)allocatedPtr));*/
1384 LogForStaticMemLeak(&SMemLeakInfo[region],
1390 #ifdef XEON_SPECIFIC_CHANGES
1391 pthread_mutex_unlock(&(memLock));
1395 #ifndef T2K_MEM_LEAK_DBG
1396 ret = (osCp.regionTbl[region].alloc)
1397 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1399 ret = (osCp.regionTbl[region].alloc)
1400 (osCp.regionTbl[region].regCb, &size, flags, ptr, file, line);
1404 #endif /* SSI_DEBUG_LEVEL1 */
1406 #endif /* SS_HISTOGRAM_SUPPORT */
1408 /* release the semaphore we took */
1411 /* ss006.13: addition */
1412 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1414 #if (ERRCLASS & ERRCLS_DEBUG)
1415 SSLOGERROR(ERRCLS_DEBUG, ESS219, ERRZERO,
1416 "Could not release semaphore");
1421 /* ss036.103 - Addition to handle the memory trampling return value
1422 * This in turn might invoke SRegMemErrHdlr
1424 #ifdef SSI_DEBUG_LEVEL1
1425 if (ret == RTRAMPLINGNOK)
1427 SRegMemErrHdlr( region, *ptr, ret);
1429 #endif /* SSI_DEBUG_LEVEL1 */
1439 * Desc: Returns a buffer to the specified static pool in the
1440 * specified memory region.
1443 * RFAILED - failed, general (optional)
1450 /* ss001.301: additions */
1451 #ifdef SS_HISTOGRAM_SUPPORT
1455 Region region, /* region ID */
1456 Pool pool, /* pool ID */
1457 Data *ptr, /* pointer to buffer */
1458 Size size, /* size */
1463 S16 SPutSBufNew(region, pool, ptr, size, line, fileName)
1464 Region region; /* region ID */
1465 Pool pool; /* pool ID */
1466 Data *ptr; /* pointer to buffer */
1467 Size size; /* size */
1471 #else /* SS_HISTOGRAM_SUPPORT */
1472 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1476 Region region, /* region ID */
1477 Pool pool, /* pool ID */
1478 Data *ptr, /* pointer to buffer */
1479 Size size, /* size */
1484 S16 SPutSBuf1(region, pool, ptr, size, file, line)
1485 Region region; /* region ID */
1486 Pool pool; /* pool ID */
1487 Data *ptr; /* pointer to buffer */
1488 Size size; /* size */
1496 Region region, /* region ID */
1497 Pool pool, /* pool ID */
1498 Data *ptr, /* pointer to buffer */
1499 Size size /* size */
1502 S16 SPutSBuf(region, pool, ptr, size)
1503 Region region; /* region ID */
1504 Pool pool; /* pool ID */
1505 Data *ptr; /* pointer to buffer */
1506 Size size; /* size */
1509 #endif /* SS_HISTOGRAM_SUPPORT */
1513 #ifdef SS_HISTOGRAM_SUPPORT
1515 Bool hstReg = FALSE;
1516 #endif /* SS_HISTOGRAM_SUPPORT */
1518 region = SS_GET_THREAD_MEM_REGION();
1519 #if (!defined(SS_LOCKLESS_MEMORY) && defined(INTEL_WLS))
1521 #endif /* INTEL_WLS */
1523 #if (ERRCLASS & ERRCLS_INT_PAR)
1524 /* validate region ID */
1525 if (region >= SS_MAX_REGS)
1527 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
1531 /* validate pool ID */
1532 if (pool >= SS_MAX_POOLS_PER_REG)
1534 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
1537 /* ss008.13: addition */
1538 /* validate data pointer */
1541 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
1548 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
1552 /* ss037.103 Removed the semaphore operation for performance enhancement */
1553 #ifndef RGL_SPECIFIC_CHANGES
1554 region = SS_GET_THREAD_MEM_REGION();
1557 /* acquire one semaphore, to protect against deregistration */
1558 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1562 #if (ERRCLASS & ERRCLS_DEBUG)
1563 SSLOGERROR(ERRCLS_DEBUG, ESS225, (ErrVal) ret,
1564 "Could not lock region table");
1571 #if (ERRCLASS & ERRCLS_INT_PAR)
1572 /* verify that this region is around */
1573 if (osCp.regionTbl[region].used == FALSE)
1577 /* ss006.13: addition */
1578 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1580 #if (ERRCLASS & ERRCLS_DEBUG)
1581 SSLOGERROR(ERRCLS_DEBUG, ESS226, ERRZERO,
1582 "Could not release semaphore");
1587 SSLOGERROR(ERRCLS_INT_PAR, ESS227, region, "Region not registered");
1592 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1593 /* Static mem leak detection changes */
1595 #ifdef XEON_SPECIFIC_CHANGES
1596 pthread_mutex_lock(&(memLock));
1598 uint32_t idx = *((uint32_t*)((uint8_t *)ptr - 4));
1599 FreeIdx(ptr,idx,&SMemLeakInfo[region],size,file,line);
1600 #ifdef XEON_SPECIFIC_CHANGES
1601 pthread_mutex_unlock(&(memLock));
1604 /* Static mem leak detection changes */
1607 /* ss001.301: additions */
1608 #ifdef SS_HISTOGRAM_SUPPORT
1609 SGetEntInd(&entId, fileName);
1610 /* Get the Information from the oscp that the tapa task with the entity
1611 id (entid) is registed for histogram or not */
1612 SGetHstGrmInfo(&entId, &hstReg);
1614 /* call the memory manager to free this memory */
1615 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,
1616 line, fileName, entId, hstReg);
1618 /* call the memory manager to free this memory */
1619 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1620 #ifdef T2K_MEM_LEAK_DBG
1621 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4, file, line);
1623 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4);
1626 #ifndef T2K_MEM_LEAK_DBG
1627 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1629 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size, file, line);
1632 #endif /* SS_HISTOGRAM_SUPPORT */
1633 /* ss037.103 Removed the semaphore operation for performance enhancement */
1636 /* release the semaphore we took */
1638 /* ss006.13: addition */
1639 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1641 #if (ERRCLASS & ERRCLS_DEBUG)
1642 SSLOGERROR(ERRCLS_DEBUG, ESS228, ERRZERO,
1643 "Could not release semaphore");
1648 /* ss036.103 - addition to handle double free and trampling return values
1649 * This might invoke SRegMemErrHdlr
1651 #ifdef SSI_DEBUG_LEVEL1
1652 /* handle the double free error here by calling the OS specific error handling function */
1653 if ((ret == RDBLFREE) || (ret == RTRAMPLINGNOK))
1655 SRegMemErrHdlr( region, ptr, ret);
1657 #endif /* SSI_DEBUG_LEVEL1 */
1667 * Desc: This function deallocates a message back and then
1668 * reinitializes the message.
1671 * RFAILED - failed, general (optional)
1673 * Notes: all data attached to message is returned to memory.
1674 * message is set to empty. message is not returned to
1675 * memory. return is ok.
1695 #if (ERRCLASS & ERRCLS_INT_PAR)
1696 /* check message buffer */
1699 SSLOGERROR(ERRCLS_INT_PAR, ESS062, ERRZERO, "SInitMsg: Null Buffer");
1702 if (mBuf->b_datap->db_type != SS_M_PROTO)
1704 SSLOGERROR(ERRCLS_INT_PAR, ESS063, ERRZERO, "SInitMsg: Incorrect buffer\
1710 /* get the message info */
1713 CM_MEM_GET_REGION(tmpRegId);
1714 if(tmpRegId == 0xFF)
1719 minfo = (SsMsgInfo*) mBuf->b_rptr;
1721 /* free all SS_M_DATA blks */
1722 while ((tmp = mBuf->b_cont))
1724 mBuf->b_cont = tmp->b_cont;
1727 #ifdef T2K_MEM_LEAK_DBG
1728 char * file = __FILE__;
1729 uint32_t line = __LINE__;
1732 (Void) SPutDBuf(tmpRegId, minfo->pool, tmp);
1734 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
1737 /* initialise the length and endptr variables of mBuf */
1740 minfo->endptr = NULLP;
1741 minfo->next = NULLP;
1746 /* ss016.301 - Added a new API - SAddPreMsgMultInOrder. This preserves the
1747 * byte order while adding the data bytes to the beginning of the message.
1751 * Fun: SAddPreMsgMultInOrder
1753 * Desc: This function copies consecutive bytes of data to the
1754 * beginning of a message and keeps the bytes order preserved.
1756 * Ret: ROK - Appended the bytes to the beginning of the message.
1757 * RFAILED - Failed to append the bytes.
1758 * ROUTRES - Out of resources - Possibly insufficient memory.
1760 * Notes: If the message is empty,data is placed in the message. Message
1761 * length is incremented. Return is ROK.
1763 * If the message is not empty,data is read by source pointer
1764 * and appended at the beginning of the message.
1765 * Message length is incremented. Return is ROK.
1771 S16 SAddPreMsgMultInOrder
1778 S16 SAddPreMsgMultInOrder(src, cnt, mBuf)
1784 SsMsgInfo *minfo; /* Message info */
1786 Buffer *curblk=NULLP;
1789 MsgLen numBytes; /* no. of bytes to be copied */
1795 #if (ERRCLASS & ERRCLS_INT_PAR)
1796 /* check message buffer */
1799 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMultInOrder:\
1806 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMultInOrder:\
1813 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMultInOrder:\
1817 if (mBuf->b_datap->db_type != SS_M_PROTO)
1819 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMultInOrder:\
1820 Incorrect buffer type");
1825 /* get the SsMsgInfo of mBuf */
1826 minfo = (SsMsgInfo*) mBuf->b_rptr;
1827 #ifdef RGL_SPECIFIC_CHANGES
1831 /* store cnt in length */
1836 /* point to the end of the source buffer */
1837 revSrc = src + cnt ;
1839 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
1840 (tmp->b_datap->db_base < tmp->b_rptr))
1842 /* store the offset of the read pointer of tmp */
1843 offset = tmp->b_rptr - tmp->b_datap->db_base;
1845 /* determine the number of bytes to copy */
1846 numBytes = MIN(cnt, offset);
1848 /* traverse back from the end of the source buffer*/
1854 /* move the read pointer towards the left */
1855 tmp->b_rptr -= numBytes ;
1856 SMemCpy((Void *)(tmp->b_rptr ), (Void *) revSrc, (size_t) numBytes);
1864 newblk = prevblk = NULLP;
1867 /* allocate a message blk */
1868 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
1870 while ((curblk = prevblk))
1872 prevblk = prevblk->b_cont;
1873 #ifdef T2K_MEM_LEAK_DBG
1874 char * file = __FILE__;
1875 uint32_t line = __LINE__;
1878 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
1883 tmp->b_rptr = tmp->b_datap->db_base + offset;
1888 /* attach curblk in the newblk chain */
1891 curblk->b_cont = prevblk; /* stack them up */
1899 /* set the read and write pointers to the end of the data buffer */
1900 /* subsequent prepends have all the buffer to insert data into */
1901 curblk->b_wptr = curblk->b_datap->db_lim;
1902 rptr = curblk->b_datap->db_lim;
1905 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
1910 /* move the read pointer towards the left */
1913 /* traverse back the source buffer */
1916 SMemCpy((Void *)(rptr), (Void *) revSrc, (size_t) numBytes);
1918 curblk->b_rptr = rptr;
1921 /* attach the newblk chain into mBuf */
1922 newblk->b_cont = tmp;
1923 mBuf->b_cont = curblk;
1925 /* update endptr of mBuf */
1928 minfo->endptr = newblk;
1930 /* update length of message */
1939 * Desc: This function copies one byte of data to the
1940 * beginning of a message.
1943 * RFAILED - failed, general (optional)
1944 * ROUTRES - failed, out of resources (optional)
1946 * Notes: if message is empty: data is placed in the message. message
1947 * length is incremented. return is ok.
1949 * if message is not empty: data is placed in front of all
1950 * other data in message. message length is incremented.
1965 S16 SAddPreMsg (data, mBuf)
1974 #if (ERRCLASS & ERRCLS_INT_PAR)
1975 /* check message buffer */
1978 SSLOGERROR(ERRCLS_INT_PAR, ESS064, ERRZERO, "SAddPreMsg: Null Buffer");
1981 if (mBuf->b_datap->db_type != SS_M_PROTO)
1983 SSLOGERROR(ERRCLS_INT_PAR, ESS065, ERRZERO, "SAddPreMsg: Incorrect\
1989 minfo = (SsMsgInfo *) mBuf->b_rptr;
1991 /* ss021.103 - Addition to check if exceeding maximum message length */
1993 if (minfo->len == 0x7FFFFFFF)
1995 if (minfo->len == 0x7FFF)
2002 * allocate a message blk using SGetDBuf(), if there are no data blks in the
2003 * message, mBuf, or if the reference count of the first data blk is greater
2004 * than 1, or if there is no space to append databytes in front of the read
2005 * pointer of the first data blk
2007 if (!(tmp = mBuf->b_cont) || (tmp->b_datap->db_ref > 1) ||
2008 (tmp->b_rptr == tmp->b_datap->db_base))
2010 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
2012 SSLOGERROR(ERRCLS_DEBUG, ESS066, ERRZERO, "SAddPreMsg:Failed in\
2016 /* set the read and write pointers to end of data buffer */
2017 /* subsequent prepends have all the buffer to insert data into */
2018 newb->b_wptr = newb->b_datap->db_lim;
2019 newb->b_rptr = newb->b_datap->db_lim;
2021 /* insert newb before tmp */
2022 newb -> b_cont = tmp;
2023 mBuf->b_cont = newb;
2025 /* if endptr of mBuf is NULLP, set it to newb */
2027 minfo->endptr = newb;
2030 /* insert data, increment length */
2031 *--tmp->b_rptr = data;
2041 * Desc: This function copies one byte of data to the
2045 * RFAILED - failed, general (optional)
2046 * ROUTRES - failed, out of resources (optional)
2048 * Notes: if message is empty: data is placed in the message. message
2049 * length is incremented. return is ok.
2051 * if message is not empty: data is placed in back of all
2052 * other data in message. message length is incremented.
2067 S16 SAddPstMsg (data, mBuf)
2076 #if (ERRCLASS & ERRCLS_INT_PAR)
2077 /* check message buffer */
2080 SSLOGERROR(ERRCLS_INT_PAR, ESS067, ERRZERO, "SAddPstMsg: Null Buffer");
2083 if (mBuf->b_datap->db_type != SS_M_PROTO)
2085 SSLOGERROR(ERRCLS_INT_PAR, ESS068, ERRZERO, "SAddPstMsg: Incorrect\
2091 /* get the message info */
2092 minfo = (SsMsgInfo *) mBuf->b_rptr;
2094 if (!(tmp = minfo->endptr) || (tmp->b_datap->db_ref > 1) ||
2095 (tmp->b_wptr == tmp->b_datap->db_lim))
2097 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
2099 SSLOGERROR(ERRCLS_DEBUG, ESS069, ERRZERO, "SAddPstMsg: Failed in\
2104 /* append newb to the end of the mBuf chain */
2108 mBuf->b_cont = newb;
2110 /* set the endptr of mBuf to newb */
2111 minfo->endptr = newb;
2115 /* insert data, increment length */
2116 *tmp->b_wptr++ = data;
2124 * Fun: SAddPreMsgMult
2126 * Desc: This function copies consecutive bytes of data to the
2127 * beginning of a message.
2130 * RFAILED - failed, general (optional)
2131 * ROUTRES - failed, out of resources (optional)
2133 * Notes: if message is empty: data is placed in the message. message
2134 * length is incremented. return is ok.
2136 * if message is not empty: data is read by source pointer,
2137 * data is placed in front of all other data in message.
2138 * message length is incremented. return is ok.
2140 * the first byte of data pointed to by the source pointer will
2141 * be placed at the front of the message first, the last byte of
2142 * data pointed to by the source pointer will be placed at the
2143 * front of the message last (i.e. it will become the first
2144 * byte of the message).
2150 #ifdef T2K_MEM_LEAK_DBG
2169 S16 SAddPreMsgMult(src, cnt, mBuf)
2176 SsMsgInfo *minfo; /* Message info */
2178 Buffer *curblk=NULLP;
2181 MsgLen numBytes; /* no. of bytes to be copied */
2186 #if (ERRCLASS & ERRCLS_INT_PAR)
2187 /* check message buffer */
2190 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMult:Null Buffer");
2196 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMult:Null Buffer");
2202 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMult: Invalid\
2206 if (mBuf->b_datap->db_type != SS_M_PROTO)
2208 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMult: Incorrect\
2214 /* get the SsMsgInfo of mBuf */
2215 minfo = (SsMsgInfo*) mBuf->b_rptr;
2217 /* store cnt in length */
2219 /* ss014.13: Addition */
2222 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
2223 (tmp->b_datap->db_base < tmp->b_rptr))
2225 /* store the offset of the read pointer of tmp */
2226 offset = tmp->b_rptr - tmp->b_datap->db_base;
2228 /* determine the number of bytes to copy */
2229 numBytes = MIN(cnt, offset);
2236 *--tmp->b_rptr = *src++;
2243 newblk = prevblk = NULLP;
2246 /* allocate a message blk */
2247 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2249 while ((curblk = prevblk))
2251 prevblk = prevblk->b_cont;
2252 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2257 tmp->b_rptr = tmp->b_datap->db_base + offset;
2262 /* attach curblk in the newblk chain */
2264 curblk->b_cont = prevblk; /* stack them up */
2269 /* set the read and write pointers to the end of the data buffer */
2270 /* subsequent prepends have all the buffer to insert data into */
2271 curblk->b_wptr = curblk->b_datap->db_lim;
2272 rptr = curblk->b_datap->db_lim;
2275 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
2282 curblk->b_rptr = rptr;
2285 /* attach the newblk chain into mBuf */
2286 newblk -> b_cont = tmp;
2287 mBuf -> b_cont = curblk;
2289 /* update endptr of mBuf */
2291 minfo -> endptr = newblk;
2293 /* update length of message */
2301 * Fun: SAddPstMsgMult
2303 * Desc: This function copies consecutive bytes of data to the
2307 * RFAILED - failed, general (optional)
2308 * ROUTRES - failed, out of resources (optional)
2310 * Notes: if message is empty: data is placed in the message. message
2311 * length is incremented. return is ok.
2313 * if message is not empty: data is read by source pointer,
2314 * data is placed in back of all other data in message.
2315 * message length is incremented. return is ok.
2317 * the first byte of data pointed to by the source pointer will
2318 * be placed at the back of the message first, the last byte of
2319 * data pointed to by the source pointer will be placed at the
2320 * back of the message last (i.e. it will become the last
2321 * byte of the message).
2327 #ifdef T2K_MEM_LEAK_DBG
2345 S16 SAddPstMsgMult(src, cnt, mBuf)
2355 Buffer *curblk=NULLP;
2362 #if (ERRCLASS & ERRCLS_INT_PAR)
2363 /* check message buffer */
2366 SSLOGERROR(ERRCLS_INT_PAR, ESS074, ERRZERO, "SAddPstMsgMult:Null Buffer");
2372 SSLOGERROR(ERRCLS_INT_PAR, ESS075, ERRZERO, "SAddPstMsgMult:Null Buffer");
2378 SSLOGERROR(ERRCLS_INT_PAR, ESS076, ERRZERO, "SAddPstMsgMult:Invalid\
2382 if (mBuf->b_datap->db_type != SS_M_PROTO)
2384 SSLOGERROR(ERRCLS_INT_PAR, ESS077, ERRZERO, "SAddPstMsgMult: Incorrect\
2390 /* get the SsMsgInfo of mBuf */
2391 minfo = (SsMsgInfo*) mBuf->b_rptr;
2393 /* store cnt in len */
2396 /* ss014.13: Addition */
2399 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
2400 (tmp->b_datap->db_lim > tmp->b_wptr))
2402 /* store offset of the write pointer */
2403 /* incase subsequent allocations fail, offset is read reset to original */
2404 offset = tmp->b_datap->db_lim - tmp->b_wptr;
2406 /* determine the number of bytes to copy */
2407 numBytes = MIN(cnt, offset);
2413 /* ss002.13: addition */
2415 /* ss004.13: addition */
2416 SMemCpy((Void *) tmp->b_wptr, (Void *) src, (size_t) numBytes);
2418 tmp->b_wptr += numBytes;
2428 newblk = prevblk = NULLP;
2432 /* allocate a message blk */
2433 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2435 while ((curblk = newblk))
2437 newblk = newblk->b_cont;
2438 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2443 tmp->b_wptr = tmp->b_datap->db_lim - offset;
2449 /* insert curblk in the newblk chain */
2451 prevblk->b_cont = curblk; /* stack them down */
2457 wptr = curblk->b_wptr;
2458 numBytes = MIN(cnt, curblk->b_datap->db_lim - wptr);
2464 /* ss002.13: addition */
2465 /* ss003.13: addition */
2466 SMemCpy( (Void *) wptr, (Void *) src, (size_t) numBytes);
2468 src = src + numBytes;
2470 curblk->b_wptr += numBytes;
2472 /* insert newblk chain into mBuf */
2474 tmp->b_cont = newblk;
2476 mBuf->b_cont = newblk;
2477 minfo->endptr = curblk;
2485 /* #ifdef SS_LOCKLESS_MEMORY */
2493 * Desc: This function copies and then removes one byte of
2494 * data from the beginning of a message.
2497 * ROKDNA - ok, data not available
2498 * RFAILED - failed, general (optional)
2500 * Notes: if message is empty: message is unchanged. return is ok,
2501 * data not available.
2503 * if message is not empty: data is removed from front of
2504 * message, data is returned via pointer to data. message
2505 * length is decremented. return is ok.
2519 S16 SRemPreMsg(dataPtr, mBuf)
2526 #ifdef T2K_MEM_LEAK_DBG
2527 char* file = __FILE__;
2528 uint32_t line = __LINE__;
2531 #if (ERRCLASS & ERRCLS_INT_PAR)
2532 /* check data pointer */
2535 SSLOGERROR(ERRCLS_INT_PAR, ESS078, ERRZERO, "SRemPreMsg : Null Buffer");
2538 /* check message buffer */
2541 SSLOGERROR(ERRCLS_INT_PAR, ESS079, ERRZERO, "SRemPreMsg : Null Buffer");
2544 if (mBuf->b_datap->db_type != SS_M_PROTO)
2546 SSLOGERROR(ERRCLS_INT_PAR, ESS080, ERRZERO, "SRemPreMsg : Incorrect\
2552 if (!(tmp = mBuf->b_cont))
2555 /* get SsMsgInfo of mBuf */
2556 minfo = (SsMsgInfo *) mBuf->b_rptr;
2558 /* read databyte into dataPtr and incrment read ptr */
2559 *dataPtr = *tmp->b_rptr++;
2561 /* if all data is exhausted, release the blk */
2562 if (tmp->b_rptr == tmp->b_wptr)
2564 mBuf->b_cont = tmp->b_cont;
2565 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2567 /* update SsMsgInfo */
2569 minfo->endptr = NULLP;
2578 * Desc: This function copies and then removes one byte of
2579 * data from the end of a message.
2582 * ROKDNA - ok, data not available
2583 * RFAILED - failed, general (optional)
2585 * Notes: if message is empty: message is unchanged. return is ok,
2586 * data not available.
2588 * if message is not empty: data is removed from back of
2589 * message, data is returned via pointer to data. message
2590 * length is decremented. return is ok.
2600 Data *dataPtr, /* pointer to data */
2604 S16 SRemPstMsg(dataPtr, mBuf)
2605 Data *dataPtr; /* pointer to data */
2606 Buffer *mBuf; /* message buffer */
2612 #ifdef T2K_MEM_LEAK_DBG
2613 char* file = __FILE__;
2614 uint32_t line = __LINE__;
2617 #if (ERRCLASS & ERRCLS_INT_PAR)
2618 /* check data pointer */
2619 if (dataPtr == NULLP)
2621 SSLOGERROR(ERRCLS_INT_PAR, ESS081, ERRZERO, "SRemPstMsg : Null Buffer");
2624 /* check message buffer */
2627 SSLOGERROR(ERRCLS_INT_PAR, ESS082, ERRZERO, "SRemPstMsg : Null Buffer");
2630 if (mBuf->b_datap->db_type != SS_M_PROTO)
2632 SSLOGERROR(ERRCLS_INT_PAR, ESS083, ERRZERO, "SRemPstMsg : Incorrect\
2638 /* get the SsMsgInfo */
2639 minfo = (SsMsgInfo*) mBuf->b_rptr;
2641 if (!(last = minfo->endptr))
2644 /* read databyte into dataPtr and decrement write ptr */
2645 *dataPtr = *--last->b_wptr;
2647 /* if all data is exhausted, release the blk */
2648 if (last->b_rptr == last->b_wptr)
2650 for (tmp = mBuf; tmp->b_cont != last;)
2652 tmp->b_cont = NULLP;
2653 (Void) SPutDBuf(minfo->region, minfo->pool, last);
2657 minfo->endptr = tmp;
2659 minfo->endptr = NULLP;
2661 /* update SsMsgInfo */
2670 * Fun: SRemPreMsgMult
2672 * Desc: This function copies and then removes consecutive bytes of
2673 * data from the beginning of a message.
2676 * ROKDNA - ok, data not available
2677 * RFAILED - failed, general (optional)
2679 * Notes: if message is empty: message is unchanged. return is ok,
2680 * data not available.
2682 * if the destination buffer is NULL, data is not copied.
2684 * if message is not empty: data is removed from front of
2685 * message, data is returned by destination pointer. message
2686 * length is decremented. return is ok.
2688 * the first byte of data read from the message will be placed
2689 * in the destination buffer first (i.e. this was the first byte
2690 * of the message), the last byte of data read from the message
2691 * will be placed in the destination buffer last.
2700 Data *dst, /* destination */
2701 MsgLen cnt, /* count */
2705 S16 SRemPreMsgMult(dst, cnt, mBuf)
2706 Data *dst; /* destination */
2707 MsgLen cnt; /* count */
2708 Buffer *mBuf; /* message buffer */
2714 #ifdef T2K_MEM_LEAK_DBG
2715 char* file = __FILE__;
2716 uint32_t line = __LINE__;
2720 /* ss023.103 - Modification of SRemPreMsgMult for bug fix */
2722 #if (ERRCLASS & ERRCLS_INT_PAR)
2726 SSLOGERROR(ERRCLS_INT_PAR, ESS084, ERRZERO, "SRemPreMsgMult:Invalid\
2730 /* check message buffer */
2733 SSLOGERROR(ERRCLS_INT_PAR, ESS085, ERRZERO, "SRemPreMsgMult:Null Buffer");
2736 /* ss021.103 - Addition to check for NULL pointer */
2737 /* check data pointer */
2738 /* ss022.103 - Removed check for NULL pointer */
2739 if (mBuf->b_datap->db_type != SS_M_PROTO)
2741 SSLOGERROR(ERRCLS_INT_PAR, ESS086, ERRZERO, "SRemPreMsgMult : Incorrect\
2747 /* get the SsMsgInfo */
2748 minfo = (SsMsgInfo*) mBuf->b_rptr;
2750 /* check if data present */
2751 if (minfo->len < cnt)
2758 /* get the first SS_M_DATA blk */
2761 /* determine the number of bytes to be copy */
2762 numBytes = MIN(cnt, tmp->b_wptr - tmp->b_rptr);
2767 /* move data into dst */
2771 SMemCpy( (Void *) dst, (Void *) tmp->b_rptr, (size_t) numBytes);
2775 tmp->b_rptr += numBytes;
2777 if (tmp->b_rptr == tmp->b_wptr)
2779 mBuf->b_cont = tmp->b_cont;
2780 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2783 /* update SsMsgInfo */
2785 minfo->endptr = NULLP;
2792 * Fun: SRemPstMsgMult
2794 * Desc: This function copies and then removes consecutive bytes of
2795 * data from the end of a message.
2798 * ROKDNA - ok, data not available
2799 * RFAILED - failed, general (optional)
2801 * Notes: if message is empty: message is unchanged. return is ok,
2802 * data not available.
2804 * if the destination buffer is NULL, data is not copied.
2806 * if message is not empty: data is removed from front of
2807 * message, data is returned by destination pointer. message
2808 * length is decremented. return is ok.
2810 * the first byte of data read from the message will be placed
2811 * in the destination buffer first (i.e. this was the last byte
2812 * of the message), the last byte of data read from the message
2813 * will be placed in the destination buffer last.
2822 Data *dst, /* destination */
2823 MsgLen cnt, /* count */
2827 S16 SRemPstMsgMult(dst, cnt, mBuf)
2828 Data *dst; /* destination */
2829 MsgLen cnt; /* count */
2830 Buffer *mBuf; /* message buffer */
2839 #ifdef T2K_MEM_LEAK_DBG
2840 char* file = __FILE__;
2841 uint32_t line = __LINE__;
2845 #if (ERRCLASS & ERRCLS_INT_PAR)
2849 SSLOGERROR(ERRCLS_INT_PAR, ESS087, ERRZERO, "SRemPstMsgMult:Invalid\
2853 /* check message buffer */
2856 SSLOGERROR(ERRCLS_INT_PAR, ESS088, ERRZERO, "SRemPstMsgMult:Null Buffer");
2859 if (mBuf->b_datap->db_type != SS_M_PROTO)
2861 SSLOGERROR(ERRCLS_INT_PAR, ESS089, ERRZERO, "SRemPstMsgMult : Incorrect\
2865 /* ss021.103 - Addition to check dst data pointer */
2866 /* check data pointer */
2867 /* ss022.103 - Removed check for NULL destination pointer */
2870 /* get the SsMsgInfo */
2871 minfo = (SsMsgInfo*) mBuf->b_rptr;
2873 /* check if data present */
2874 if (minfo->len < cnt)
2884 /* determine blk containing offset, and prev node */
2885 FIND_OFFSET_AND_PREV(prev, tmp, count)
2892 numBytes = MIN(cnt, (tmp->b_wptr - tmp->b_rptr - count));
2894 tmp->b_wptr -= numBytes;
2906 if (tmp->b_rptr == tmp->b_wptr)
2908 prev->b_cont = tmp->b_cont;
2909 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2918 minfo->endptr = NULLP;
2920 minfo->endptr = prev;
2929 * Desc: This function copies one byte of data from a message
2930 * without modifying the message.
2933 * ROKDNA - ok, data not available
2934 * RFAILED - failed, general (optional)
2936 * Notes: index is 0 based and indicates location in message
2938 * if index is less than the length of the message:
2939 * message is unchanged and data is examined at specified
2940 * index and returned via pointer to data. message length
2941 * is unchanged. return is ok.
2943 * if index is greater than or equal to
2944 * the length of the message: message is unchanged and 0
2945 * is returned via pointer to data. return is ok, data
2956 Data *dataPtr, /* pointer to data */
2957 Buffer *mBuf, /* message buffer */
2961 S16 SExamMsg(dataPtr, mBuf, idx)
2962 Data *dataPtr; /* pointer to data */
2963 Buffer *mBuf; /* message buffer */
2964 MsgLen idx; /* index */
2970 #if (ERRCLASS & ERRCLS_INT_PAR)
2971 /* check data pointer */
2974 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SExamMsg : Null Buffer");
2977 /* check message buffer */
2980 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SExamMsg : Null Buffer");
2986 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SExamMsg : Invalid Index");
2989 if (mBuf->b_datap->db_type != SS_M_PROTO)
2991 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SExamMsg : Incorrect buffer\
2997 /* get the SsMsgInfo */
2998 minfo = (SsMsgInfo*) mBuf->b_rptr;
3000 if (minfo->len <= idx)
3005 /* get the first SS_M_DATA blk */
3008 /* determine offset */
3009 FIND_OFFSET(tmp, idx)
3011 *dataPtr = *(tmp->b_rptr + idx);
3020 * Fun: SGetDataFrmMsg
3022 * Desc: This function copies requested byte of data from a message
3023 * without modifying the message.
3026 * ROKDNA - ok, data not available
3027 * RFAILED - failed, general (optional)
3029 * Notes: index is 0 based and indicates location in message
3031 * if index is less than the length of the message:
3032 * message is unchanged and data is examined at specified
3033 * index and returned via pointer to data. message length
3034 * is unchanged. return is ok.
3036 * if index is greater than or equal to
3037 * the length of the message: message is unchanged and 0
3038 * is returned via pointer to data. return is ok, data
3049 Buffer *mBuf, /* message buffer */
3050 Data *dataPtr, /* pointer to data */
3055 S16 SGetDataFrmMsg(mBuf, dataPtr, idx, dataLen)
3056 Buffer *mBuf; /* message buffer */
3057 Data *dataPtr; /* pointer to data */
3058 MsgLen idx; /* index */
3065 Data *tmpDataPtr = dataPtr;
3067 #if (ERRCLASS & ERRCLS_INT_PAR)
3068 /* check data pointer */
3071 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SGetDataFrmMsg: Null Buffer");
3074 /* check message buffer */
3077 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SGetDataFrmMsg: Null Buffer");
3083 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SGetDataFrmMsg: Invalid Index");
3086 if (mBuf->b_datap->db_type != SS_M_PROTO)
3088 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SGetDataFrmMsg: Incorrect buffer\
3094 /* get the SsMsgInfo */
3095 minfo = (SsMsgInfo*) mBuf->b_rptr;
3097 if (minfo->len <= (idx + dataLen) )
3102 /* get the first SS_M_DATA blk */
3105 /* determine offset */
3112 FIND_OFFSET(tmp, idx)
3113 offSetLen = ((tmp->b_wptr - (tmp->b_rptr + idx)));
3115 for(;(offSetLen < dataLen && tmp != NULLP);)
3117 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)offSetLen);
3118 dataLen = dataLen - offSetLen;
3121 tmpDataPtr = tmpDataPtr + offSetLen;
3122 offSetLen = tmp->b_wptr - tmp->b_rptr;
3128 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)dataLen);
3132 } /* End of SGetDataFrmMsg() */
3138 * Desc: This function determines the length of data within
3142 * RFAILED - failed, general (optional)
3144 * Notes: length of message is determined, message is unchanged
3145 * and length is returned via pointer to length. return is ok.
3155 REG1 Buffer *mBuf, /* message buffer */
3159 S16 SFndLenMsg(mBuf, lngPtr)
3160 REG1 Buffer *mBuf; /* message buffer */
3161 MsgLen *lngPtr; /* pointer to length */
3166 #if (ERRCLASS & ERRCLS_INT_PAR)
3167 /* check message buffer */
3170 SSLOGERROR(ERRCLS_INT_PAR, ESS094, ERRZERO, "SFndLenMsg : Null Buffer");
3173 /* check length pointer */
3174 if (lngPtr == NULLP)
3176 SSLOGERROR(ERRCLS_INT_PAR, ESS095, ERRZERO, "SFndLenMsg : Null Buffer");
3179 if (mBuf->b_datap->db_type != SS_M_PROTO)
3181 SSLOGERROR(ERRCLS_INT_PAR, ESS096, ERRZERO, "SFndLenMsg : Incorrect\
3187 /* get the SsMsgInfo */
3188 minfo = (SsMsgInfo*) mBuf->b_rptr;
3191 *lngPtr = minfo->len;
3197 /* #ifdef SS_LOCKLESS_MEMORY */
3203 * Desc: This function will segment one specified message into two
3207 * ROKDNA - ok, data not available
3208 * RFAILED - failed, general (optional)
3209 * ROUTRES - failed, out of resources (optional)
3211 * Notes: message 1 is the original message.
3213 * message 2 is the new message.
3215 * index is 0 based and indicates location in message 1
3216 * from which message 2 will be created.
3218 * if index is equal to 0: message 2 is created and all data
3219 * attached to message 1 is moved to message 2. message 1
3220 * is not returned to memory. return is ok.
3222 * if index is not equal to 0 and less than the length of
3223 * the message minus 1: message 2 is created, all data
3224 * attached to message 1 from index (inclusive) is moved to
3225 * message 2. message 1 contains data from index 0 to index
3226 * minus 1. return is ok.
3228 * if index is not equal to 0 and greater than or equal to
3229 * the length of the message minus 1: message 1 is unchanged.
3230 * message 2 is set to null. return is ok, data not available.
3235 #ifdef T2K_MEM_LEAK_DBG
3238 Buffer *mBuf1, /* message 1 */
3239 MsgLen idx, /* index */
3248 Buffer *mBuf1, /* message 1 */
3249 MsgLen idx, /* index */
3253 S16 SSegMsg(mBuf1, idx, mBuf2)
3254 Buffer *mBuf1; /* message 1 */
3255 MsgLen idx; /* index */
3256 Buffer **mBuf2; /* message 2 */
3267 #if (ERRCLASS & ERRCLS_INT_PAR)
3268 /* check message buffer 1 */
3271 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SSegMsg : Null Buffer");
3274 /* check message buffer 2 */
3277 SSLOGERROR(ERRCLS_INT_PAR, ESS098, ERRZERO, "SSegMsg : Null Buffer");
3282 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SSegMsg : Invalid index");
3285 if (mBuf1->b_datap->db_type != SS_M_PROTO)
3287 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SSegMsg : Incorrect buffer\
3293 /* get the SsMsgInfo of mBuf1 */
3294 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
3295 #ifdef RGL_SPECIFIC_CHANGES
3299 /* if index > length of mBuf, return */
3300 if (idx >= minfo1->len)
3305 /* allocate message buffer */
3306 if (SGetMsg(minfo1->region, minfo1->pool, mBuf2) != ROK)
3308 SSLOGERROR(ERRCLS_DEBUG, ESS101, ERRZERO, "SSegMsg : SGetMsg failed");
3312 /* get the SsMsgInfo of mBuf2 */
3313 minfo2 = (SsMsgInfo*) (*mBuf2)->b_rptr;
3315 /* adjust the lengths of mBuf1, mBuf2 */
3316 minfo2->len = minfo1->len - idx;
3319 /* set the endptr of mBuf2 to mBuf1 */
3320 minfo2->endptr = minfo1->endptr;
3322 /* if index is zero ... */
3325 (*mBuf2)->b_cont = mBuf1->b_cont;
3327 /* set the endptr and b_cont of mBuf1 to NULLP */
3328 minfo1->endptr = NULLP;
3329 mBuf1->b_cont = NULLP;
3334 /* get the first SS_M_DATA blk */
3335 tmp = mBuf1->b_cont;
3338 FIND_OFFSET_AND_PREV(prev, tmp, idx)
3340 /* segmented at the start of a blk */
3343 (*mBuf2)->b_cont = tmp;
3344 prev->b_cont = NULLP;
3345 minfo1->endptr = prev;
3349 #ifndef SS_MULTICORE_SUPPORT
3350 /* allocate a message blk without a data blk */
3351 /* ssDupB internally increments the reference count */
3352 #ifdef SS_M_PROTO_REGION
3353 if (!(next = DupMsg(minfo1->region, tmp)))
3355 if (!(next = ssDupB(tmp)))
3356 #endif /* SS_M_PROTO_REGION */
3359 minfo1->len += minfo2->len;
3360 (Void) SPutMsg(*mBuf2);
3364 (*mBuf2)->b_cont = next;
3366 tmp->b_cont = NULLP;
3368 tmp->b_wptr = tmp->b_rptr + idx;
3369 next->b_rptr = tmp->b_wptr;
3371 /* If the index was in the last mblk of the message, the
3372 * end pointer of the new message needs to be set to the
3373 * dup'ped mblk. Otherwise, the end pointer of the first
3374 * message will be set to the mblk in which the index
3375 * was found, and the end pointer of the new message can
3376 * remain where it is.
3378 if (minfo1->endptr == tmp)
3380 minfo2->endptr = next;
3384 minfo1->endptr = tmp;
3386 #else /*SS_MULTICORE_SUPPORT*/
3390 #ifdef SS_M_PROTO_REGION
3391 if (!(next = DupMsg(minfo1->region, tmp)))
3393 if (!(next = ssDupB(tmp)))
3394 #endif /* SS_M_PROTO_REGION */
3397 minfo1->len += minfo2->len;
3398 (Void) SPutMsg(*mBuf2);
3401 (*mBuf2)->b_cont = next;
3402 tmp->b_wptr = tmp->b_rptr + idx;
3403 next->b_rptr += idx;
3406 /* copy rest of the blocks */
3410 prev->b_cont = NULLP;
3411 minfo2->endptr = minfo1->endptr;
3412 minfo1->endptr = prev;
3416 next->b_cont = NULLP;
3417 minfo2->endptr = next;
3420 #endif /*SS_MULTICORE_SUPPORT*/
3430 * Desc: This function copies data from a fixed buffer to a
3434 * RFAILED - failed, general (optional)
3445 Data *srcBuf, /* source buffer */
3446 Buffer *dstMbuf, /* destination message buffer */
3447 MsgLen dstIdx, /* destination index */
3448 MsgLen cnt, /* count */
3452 S16 SCpyFixMsg(srcBuf, dstMbuf, dstIdx, cnt, cCnt)
3453 Data *srcBuf; /* source buffer */
3454 Buffer *dstMbuf; /* destination message buffer */
3455 MsgLen dstIdx; /* destination index */
3456 MsgLen cnt; /* count */
3457 MsgLen *cCnt; /* copied count */
3464 #if (ERRCLASS & ERRCLS_INT_PAR)
3465 /* check source message buffer */
3466 if (srcBuf == NULLP)
3468 SSLOGERROR(ERRCLS_INT_PAR, ESS102, ERRZERO, "SCpyFixMsg : Null Buffer");
3471 /* check destination message buffer */
3472 if (dstMbuf == NULLP)
3474 SSLOGERROR(ERRCLS_INT_PAR, ESS103, ERRZERO, "SCpyFixMsg : Null Buffer");
3477 /* check copied count buffer */
3480 SSLOGERROR(ERRCLS_INT_PAR, ESS104, ERRZERO, "SCpyFixMsg : Null Buffer");
3483 /* check copy count */
3486 SSLOGERROR(ERRCLS_INT_PAR, ESS105, ERRZERO, "SCpyFixMsg : Invalid count");
3489 if (dstMbuf->b_datap->db_type != SS_M_PROTO)
3491 SSLOGERROR(ERRCLS_INT_PAR, ESS106, ERRZERO, "SCpyFixMsg : Incorrect\
3497 minfo = (SsMsgInfo*) dstMbuf->b_rptr;
3499 if (minfo->len < dstIdx)
3501 #if (ERRCLASS & ERRCLS_DEBUG)
3502 SSLOGERROR(ERRCLS_DEBUG, ESS107, ERRZERO, "SCpyFixMsg : Invalid Index");
3507 /* ss021.103 - Addition test if message length will exceed max msg length */
3508 #if (ERRCLASS & ERRCLS_INT_PAR)
3510 if (minfo->len > 0x7FFFFFFF - cnt)
3512 if (minfo->len > 0x7FFF - cnt)
3517 SSLOGERROR(ERRCLS_INT_PAR, ESS108, ERRZERO, "SCpyFixMsg : msgLen + cnt > maxS16");
3522 /* add data at the start of dst buffer */
3525 if ((ret = SAddPreMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3527 #if (ERRCLASS & ERRCLS_DEBUG)
3528 SSLOGERROR(ERRCLS_DEBUG, ESS109, ERRZERO, "SCpyFixMsg : Failed in\
3538 /* add data at the end of the dst buffer */
3539 if (minfo->len == dstIdx)
3541 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3550 /* segment the message into dstMbuf and right */
3551 if ((ret = SSegMsg(dstMbuf, dstIdx, &right)) != ROK)
3556 /* append data at the end of dstMbuf */
3557 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3559 /* ss020.103 - Addition for cleanup */
3560 (Void) SPutMsg(right);
3564 /* cancatenate dstMbuf and right */
3565 if ((ret = SCatMsg(dstMbuf, right, M1M2)) != ROK)
3567 /* ss020.103 - Addition for cleanup */
3568 (Void) SPutMsg(right);
3574 (Void) SPutMsg(right);
3583 * Desc: This function copies data from a message
3584 * into a fixed buffer.
3587 * RFAILED - failed, general (optional)
3598 Buffer *srcMbuf, /* source message buffer */
3599 MsgLen srcIdx, /* source index */
3600 MsgLen cnt, /* count */
3601 Data *dstBuf, /* destination buffer */
3605 S16 SCpyMsgFix(srcMbuf, srcIdx, cnt, dstBuf, cCnt)
3606 Buffer *srcMbuf; /* source message buffer */
3607 MsgLen srcIdx; /* source index */
3608 MsgLen cnt; /* count */
3609 Data *dstBuf; /* destination buffer */
3610 MsgLen *cCnt; /* copied count */
3618 #if (ERRCLASS & ERRCLS_INT_PAR)
3619 /* check source message buffer */
3620 if (srcMbuf == NULLP)
3622 SSLOGERROR(ERRCLS_INT_PAR, ESS110, ERRZERO, "SCpyMsgFix : Null Buffer");
3625 /* check destination message buffer */
3626 if (dstBuf == NULLP)
3628 SSLOGERROR(ERRCLS_INT_PAR, ESS111, ERRZERO, "SCpyMsgFix : Null Buffer");
3633 SSLOGERROR(ERRCLS_INT_PAR, ESS112, ERRZERO, "SCpyMsgFix : Invalid Index");
3639 SSLOGERROR(ERRCLS_INT_PAR, ESS113, ERRZERO, "SCpyMsgFix : Invalid Index");
3644 SSLOGERROR(ERRCLS_INT_PAR, ESS114, ERRZERO, "SCpyMsgFix : Null Buffer");
3647 if (srcMbuf->b_datap->db_type != SS_M_PROTO)
3649 SSLOGERROR(ERRCLS_INT_PAR, ESS115, ERRZERO, "SCpyMsgFix : Incorrect\
3656 minfo = (SsMsgInfo*) srcMbuf->b_rptr;
3658 if ((srcIdx + cnt) > minfo->len)
3664 /* get the first SS_M_DATA blk */
3665 tmp = srcMbuf->b_cont;
3667 /* get to the srcIdx-th offset */
3668 FIND_OFFSET(tmp, srcIdx)
3672 /* set cptr to the read ptr of tmp + offset */
3673 cptr = tmp->b_rptr + srcIdx;
3677 /* determine the number of bytes to be copied */
3678 numBytes = MIN(cnt, (tmp->b_wptr - cptr));
3685 /* ss002.13 addition */
3687 /* ss003.13 addition */
3688 SMemCpy((Void *) dstBuf, (Void *) cptr, (size_t) numBytes);
3694 /* get the next blk */
3695 if ((tmp = tmp->b_cont))
3696 /* set cptr to the read ptr of tmp */
3709 * Desc: This function is used to copy a message into
3710 * a new region and or pool of memory.
3713 * RFAILED - failed, general (optional)
3714 * ROUTRES - failed, out of resources (optional)
3722 #ifdef T2K_MEM_LEAK_DBG
3742 S16 SCpyMsgMsg(srcBuf, dstRegion, dstPool, dstBuf)
3757 /* ss021.103 - Addition of return value */
3759 #if (ERRCLASS & ERRCLS_INT_PAR)
3764 #if (ERRCLASS & ERRCLS_INT_PAR)
3767 SSLOGERROR(ERRCLS_INT_PAR, ESS116, ERRZERO, "SCpyMsgMsg : Null Buffer");
3770 if (srcBuf->b_datap->db_type != SS_M_PROTO)
3772 SSLOGERROR(ERRCLS_INT_PAR, ESS117, ERRZERO, "SCpyMsgMsg : Incorrect\
3776 /* ss021.103 - Addition to validate region and pool */
3777 if (dstRegion >= SS_MAX_REGS)
3779 SSLOGERROR(ERRCLS_INT_PAR, ESS118, ERRZERO,
3780 "SCpyMsgMsg : Invalid region id");
3784 if (dstPool >= SS_MAX_POOLS_PER_REG)
3786 SSLOGERROR(ERRCLS_INT_PAR, ESS119, ERRZERO,
3787 "SCpyMsgMsg : Invalid pool id");
3790 /* ss037.103 Removed the semaphore operation for performance enhancement */
3793 /* ss021.103 - Addition to check if region is valid */
3794 /* acquire one semaphore, to protect against deregistration */
3795 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
3799 #if (ERRCLASS & ERRCLS_DEBUG)
3800 SSLOGERROR(ERRCLS_DEBUG, ESS120, (ErrVal) ret,
3801 "Could not lock region table");
3808 #if (ERRCLASS & ERRCLS_INT_PAR)
3809 /* verify that this region is present */
3810 if (osCp.regionTbl[dstRegion].used == FALSE)
3813 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3815 #if (ERRCLASS & ERRCLS_DEBUG)
3816 SSLOGERROR(ERRCLS_DEBUG, ESS121, ERRZERO,
3817 "Could not release semaphore");
3822 SSLOGERROR(ERRCLS_INT_PAR, ESS122, dstRegion, "Region not registered");
3826 /* ss037.103 Removed the semaphore operation for performance enhancement */
3829 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3831 #if (ERRCLASS & ERRCLS_DEBUG)
3832 SSLOGERROR(ERRCLS_DEBUG, ESS123, ERRZERO,
3833 "Could not release semaphore");
3840 #ifdef XEON_SPECIFIC_CHANGES
3844 /* allocate a message buffer */
3845 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
3847 #if (ERRCLASS & ERRCLS_DEBUG)
3848 SSLOGERROR(ERRCLS_DEBUG, ESS124, ERRZERO, "SCpyMsgMsg : SGetMsg failed");
3852 /* get the SsMsgInfo from srcBuf */
3853 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
3855 /* get the SsMsgInfo from srcBuf */
3856 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
3858 /* get the first SS_M_DATA blk of srcBuf */
3859 tmp = srcBuf->b_cont;
3861 /* if srcBuf and dstBuf belong to the same region, increment the reference
3870 #ifdef SS_M_PROTO_REGION
3871 if ((curblk = DupMsg(dstRegion,tmp)) == NULLP)
3873 if ((curblk = ssDupB(tmp)) == NULLP)
3874 #endif /* SS_M_PROTO_REGION */
3878 curblk = newblk->b_cont;
3879 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
3882 printf("Failed to get the buffer of size %s %d\n", __FILE__, __LINE__);
3883 (Void) SPutMsg(*dstBuf);
3890 prevblk->b_cont = curblk;
3896 curblk->b_cont = NULLP;
3898 minfo2->len = minfo1->len;
3899 minfo2->endptr = curblk;
3900 (*dstBuf)->b_cont = newblk;
3911 * Desc: This function is used to copy a message into
3912 * a new region and or pool of memory.
3915 * RFAILED - failed, general (optional)
3916 * ROUTRES - failed, out of resources (optional)
3923 #ifdef T2K_MEM_LEAK_DBG
3943 S16 SAddMsgRef(srcBuf, dstRegion, dstPool, dstBuf)
3962 #if (ERRCLASS & ERRCLS_INT_PAR)
3965 SSLOGERROR(ERRCLS_INT_PAR, ESS126, ERRZERO, "SAddMsgRef : Null Buffer");
3968 if (srcBuf->b_datap->db_type != SS_M_PROTO)
3970 SSLOGERROR(ERRCLS_INT_PAR, ESS127, ERRZERO, "SAddMsgRef : Incorrect\
3975 #ifdef XEON_SPECIFIC_CHANGES
3980 /* allocate a message buffer */
3981 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
3983 #if (ERRCLASS & ERRCLS_DEBUG)
3984 SSLOGERROR(ERRCLS_DEBUG, ESS128, ERRZERO, "SAddMsgRef : SGetMsg failed");
3988 /* get the SsMsgInfo from srcBuf */
3989 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
3991 /* get the SsMsgInfo from srcBuf */
3992 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
3994 /* get the first SS_M_DATA blk of srcBuf */
3995 tmp = srcBuf->b_cont;
3997 /* if srcBuf and dstBuf belong to the same region, increment the reference
4000 if (dstRegion == minfo1->region)
4008 #ifdef SS_M_PROTO_REGION
4009 if ((curblk = DupMsg(dstRegion, tmp)) == NULLP)
4011 if ((curblk = ssDupB(tmp)) == NULLP)
4012 #endif /* SS_M_PROTO_REGION */
4016 curblk = newblk->b_cont;
4017 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
4020 (Void) SPutMsg(*dstBuf);
4027 prevblk->b_cont = curblk;
4033 curblk->b_cont = NULLP;
4035 minfo2->len = minfo1->len;
4036 minfo2->endptr = curblk;
4037 (*dstBuf)->b_cont = newblk;
4042 /* allocate a data buffer */
4043 if (ssGetDBufOfSize(dstRegion, minfo1->len, &dBuf) != ROK)
4045 /* ss016.13: addition */
4046 (Void) SPutMsg(*dstBuf);
4047 SSLOGERROR(ERRCLS_DEBUG, ESS129, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
4051 dBuf->b_datap->db_type = SS_M_DATA;
4055 numBytes = tmp->b_wptr - tmp->b_rptr;
4058 *dBuf->b_wptr++ = *cptr++;
4061 minfo2->len = minfo1->len;
4062 /* set the endptr and b_cont of dstBuf to point to dBuf */
4063 minfo2->endptr = dBuf;
4064 (*dstBuf)->b_cont = dBuf;
4068 /* ss012.13: Addition */
4069 #ifdef SS_M_PROTO_REGION
4074 * Desc: Duplicates the specified message block, copying it
4075 * into a newly-allocated message block. Increments
4076 * the reference count of the data block that is pointed
4077 * at by the original message block descriptor.
4079 * Ret: non-NULL - ok
4087 #ifdef T2K_MEM_LEAK_DBG
4088 static Buffer *DupMsgNew
4090 Region region, /* region id */
4091 Buffer *mp, /* message block */
4097 static Buffer *DupMsg
4099 Region region, /* region id */
4100 Buffer *mp /* message block */
4103 static Buffer *DupMsg(region, mp)
4104 Region region; /* region id */
4105 Buffer *mp; /* message block */
4109 Buffer *bp; /* mblk for iteration */
4110 S16 r; /* return value */
4111 Size m; /* temporary */
4114 #if (ERRCLASS & ERRCLS_INT_PAR)
4117 SSLOGERROR(ERRCLS_INT_PAR, ESS130, ERRZERO, "Null pointer");
4121 if (region >= SS_MAX_REGS)
4123 SSLOGERROR(ERRCLS_INT_PAR, ESS131, ERRZERO, "DupMsg : Invalid region\
4130 /* allocate a single block for the mblock and the dblock */
4132 m = (sizeof(SsMblk) + sizeof(SsDblk));
4134 numBytes = mp->b_wptr - mp->b_rptr;
4135 m = MDBSIZE + numBytes;
4136 #endif /* SS_MULTICORE_SUPPORT */
4137 /* ss001.301: additions */
4138 #ifdef SS_HISTOGRAM_SUPPORT
4139 r = SAlloc(region, &m, 0, (Data **)&bp, __LINE__, (uint8_t*) __FILE__, ENTNC);
4141 r = SAlloc(region, &m, 0, (Data **)&bp);
4142 #endif /* SS_HISTOGRAM_SUPPORT */
4145 #if (ERRCLASS & ERRCLS_ADD_RES)
4146 SSLOGERROR(ERRCLS_ADD_RES, ESS132, (ErrVal) r, "SAlloc() failed");
4151 /* generic set-up-message function */
4153 #ifndef SS_DBUF_REFLOCK_DISABLE
4154 SS_STRM_INITB(bp, (SsDblk *)(((uint8_t *)bp) + sizeof(SsMblk)), NULLP, 0, NULLP);
4157 data = (Data *) (bp) + MDBSIZE;
4158 SS_STRM_INITB(bp,(SsDblk *)(((uint8_t *)bp) + sizeof(SsMblk)), data, numBytes, NULLP);
4159 #endif /* SS_MULTICORE_SUPPORT */
4162 /* make the new message block identical to the one to be dup'ed.
4163 * notice that an mblk/dblk pair is allocated but only the mblk
4164 * is used,, this is for optimum performance in the average case.
4166 SMemCpy( (Void *)bp, (Void *)mp, (size_t)sizeof(SsMblk));
4168 /* ss006.301 - added the Lock */
4169 #ifndef SS_DBUF_REFLOCK_DISABLE
4170 if((SLock(&(mp->b_datap->dBufLock))) != ROK)
4172 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
4173 "Could not lock the mBuf Ref Lock");
4177 /* increment the reference count of the dblock */
4178 /* increment the reference count of the dblock */
4179 mp->b_datap->db_ref++;
4180 mp->b_datap->shared = TRUE;
4181 #ifndef SS_DBUF_REFLOCK_DISABLE
4182 if((SUnlock(&(mp->b_datap->dBufLock))) != ROK)
4184 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
4185 "Could not lock the mBuf Ref Lock");
4193 #endif /* SS_M_PROTO_REGION */
4199 * Desc: This function allocates a buffer from the dynamic
4200 * memory pool indicated by the caller.
4203 * RFAILED - failed, general (optional)
4204 * ROUTRES - failed, out of resources (optional)
4206 * Notes: The dynamic memory pools are used to create and
4207 * manipulate messages.
4209 * SGetDBuf is never called by a protocol layer.
4211 * SGetDBuf assumes that interrupts are already disabled.
4217 #ifdef T2K_MEM_LEAK_DBG
4220 Region region, /* region id */
4221 Pool pool, /* pool id */
4230 Region region, /* region id */
4231 Pool pool, /* pool id */
4235 S16 SGetDBuf(region, pool, bufPtr)
4236 Region region; /* region id */
4237 Pool pool; /* pool id */
4238 Buffer **bufPtr; /* pointer to buffer */
4246 #ifdef SS_LOCKLESS_MEMORY
4247 #ifdef SS_USE_ICC_MEMORY
4248 CmMmDynRegCb *regCb;
4250 CmMmGlobRegCb *regCb;
4253 SsRegionEntry *regp;
4254 #endif /* SS_LOCKLESS_MEMORY */
4255 /* ss021.103 - Addition of return value */
4257 #if (ERRCLASS & ERRCLS_INT_PAR)
4262 #if (ERRCLASS & ERRCLS_INT_PAR)
4263 /* check buffer pointer */
4266 SSLOGERROR(ERRCLS_INT_PAR, ESS133, ERRZERO, "SGetDBuf : Null Buffer");
4269 if (region >= SS_MAX_REGS)
4271 SSLOGERROR(ERRCLS_INT_PAR, ESS134, ERRZERO, "SGetDBuf : Invalid region\
4276 if (pool >= SS_MAX_POOLS_PER_REG)
4278 SSLOGERROR(ERRCLS_INT_PAR, ESS135, ERRZERO, "SGetDBuf : Invalid pool id");
4281 /* ss037.103 Removed the semaphore operation for performance enhancement */
4284 /* ss021.103 - Addition to check if region is registered */
4285 /* acquire one semaphore, to protect against deregistration */
4286 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
4290 #if (ERRCLASS & ERRCLS_DEBUG)
4291 SSLOGERROR(ERRCLS_DEBUG, ESS136, (ErrVal) ret,
4292 "Could not lock region table");
4300 #if (ERRCLASS & ERRCLS_INT_PAR)
4301 /* verify that this region is present */
4302 if (osCp.regionTbl[region].used == FALSE)
4304 /* ss037.103 Removed the semaphore operation for performance enhancement */
4307 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4309 #if (ERRCLASS & ERRCLS_DEBUG)
4310 SSLOGERROR(ERRCLS_DEBUG, ESS137, ERRZERO,
4311 "Could not release semaphore");
4316 SSLOGERROR(ERRCLS_INT_PAR, ESS138, region, "Region not registered");
4320 /* ss037.103 Removed the semaphore operation for performance enhancement */
4323 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4325 #if (ERRCLASS & ERRCLS_DEBUG)
4326 SSLOGERROR(ERRCLS_DEBUG, ESS139, ERRZERO,
4327 "Could not release semaphore");
4334 #ifdef SS_LOCKLESS_MEMORY
4335 #ifdef SS_USE_ICC_MEMORY
4336 regCb = (CmMmDynRegCb *)(osCp.dynRegionTbl[region].regCb);
4337 mdsize = regCb->bktSize[pool];
4338 #else /* SS_USE_ICC_MEMORY */
4339 regCb = osCp.globRegCb;
4340 #ifdef SS_MEM_WL_DEBUG
4341 mdsize = regCb->bktTbl[pool].size - 4;
4342 #else /* SS_MEM_WL_DEBUG */
4343 mdsize = regCb->bktTbl[pool].size;
4344 #endif /* SS_MEM_WL_DEBUG */
4345 #endif /* SS_USE_ICC_MEMORY */
4347 regp = &osCp.regionTbl[region];
4348 size = regp->poolTbl[pool].u.dpool.size;
4349 /* ss006.301 : optimized this function */
4350 mdsize = MDBSIZE + size;
4351 #endif /* SS_LOCKLESS_MEMORY */
4353 /* ss006.301 : optimized this function */
4354 /* ss001.301: additions */
4355 #ifdef SS_HISTOGRAM_SUPPORT
4356 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
4358 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr) != ROK)
4359 #endif /* SS_HISTOGRAM_SUPPORT */
4363 data = (Data *) (*bufPtr) + MDBSIZE;
4364 size = mdsize - MDBSIZE;
4366 dptr = (SsDblk*) (((Data *) (*bufPtr)) + MBSIZE);
4368 INITB((*bufPtr), dptr, data, size, NULLP)
4369 #ifndef SS_DBUF_REFLOCK_DISABLE
4370 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
4372 printf("Falied to destroy lock\n");
4383 * Desc: This function deallocates a buffer back to the
4384 * dynamic memory pool indicated by the caller.
4387 * RFAILED - failed, general (optional)
4389 * Notes: The dynamic memory pools are used to create and
4390 * manipulate messages.
4392 * SPutDBuf is never called by a protocol layer.
4394 * SPutDBuf assumes that interrupts are already disabled.
4400 #ifdef T2K_MEM_LEAK_DBG
4418 S16 SPutDBuf(region, pool, buf)
4425 register SsDblk *dptr;
4426 /* ss021.103 - Addition to check return value of SFree */
4428 #if (defined(SS_USE_ZBC_MEMORY) && defined (TENB_DPDK_BUF))
4433 /* ss021.103 - Addition of ret initialization */
4436 #if (ERRCLASS & ERRCLS_INT_PAR)
4437 if (region >= SS_MAX_REGS)
4439 SSLOGERROR(ERRCLS_INT_PAR, ESS141, ERRZERO, "SPutDBuf:Invalid region");
4443 if (pool >= SS_MAX_POOLS_PER_REG)
4445 SSLOGERROR(ERRCLS_INT_PAR, ESS142, ERRZERO, "SPutDBuf:Invalid pool");
4451 SSLOGERROR(ERRCLS_INT_PAR, ESS143, ERRZERO, "SPutDBuf:Null pointer");
4455 if ( (buf->b_datap->db_type != SS_M_DATA) && (buf->b_datap->db_type != SS_M_PROTO))
4457 SSLOGERROR(ERRCLS_INT_PAR, ESS144, ERRZERO, "SPutDBuf:Incorrect\
4462 /* ss016.13: Addition */
4463 dptr = buf->b_datap;
4465 #ifdef SS_USE_ZBC_MEMORY
4466 if(dptr->db_type == SS_MEM_TYPE_SSI_ZBC)
4468 ret = SPutZbcDBuf(region, buf);
4472 #ifdef TENB_DPDK_BUF
4473 if(dptr->db_type == SS_MEM_TYPE_DPDK_ZBC)
4475 /* Not considering referances for DPDK buffer for now */
4476 SDetachDpdkPtrFrmDBuf(buf, &dpdkBuf);
4477 SPutSBufDpdk(dpdkBuf);
4478 ret = SFree(region, (Data *) buf, MDBSIZE);
4481 #endif /* TENB_DPDK_BUF */
4482 #endif /* SS_USE_ZBC_MEMORY */
4484 /* ss028.103 - Addition of lock for mBuf reference count */
4485 /* ss006.301 : optimized this funciton */
4489 #ifndef SS_DBUF_REFLOCK_DISABLE
4490 SDestroyLock(&dptr->dBufLock);
4492 /* if the data block is not shared, free the buffer, checks not reqd */
4493 #ifdef SS_HISTOGRAM_SUPPORT
4494 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4495 , __LINE__, (uint8_t*) __FILE__, ENTNC);
4497 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4498 #endif /* SS_HISTOGRAM_SUPPORT */
4502 #ifndef SS_DBUF_REFLOCK_DISABLE
4503 if((ret=SLock(&dptr->dBufLock)))
4505 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
4506 "Could not lock the mBuf Ref Lock");
4511 /* if buffer's message blk is obtained during dupb */
4512 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
4515 SsDblk* dupdptr = (SsDblk *)((uint8_t *)buf + MBSIZE);
4517 if(dupdptr->db_ref == 0)
4520 #ifdef SS_HISTOGRAM_SUPPORT
4521 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__, ENTNC);
4523 ret = SFree(region, (Data *) buf, MDBSIZE);
4525 #endif /* SS_HISTOGRAM_SUPPORT */
4527 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
4529 /* if reference count falls to zero */
4532 #ifndef SS_DBUF_REFLOCK_DISABLE
4533 ret = SUnlock(&dptr->dBufLock) ;
4534 if((SDestroyLock(&dptr->dBufLock)) != 0)
4536 printf("Falied to destroy lock\n");
4539 /* free buffer to region */
4540 #ifdef SS_HISTOGRAM_SUPPORT
4541 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4542 , __LINE__, (uint8_t*) __FILE__, ENTNC);
4544 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4545 #endif /* SS_HISTOGRAM_SUPPORT */
4548 #ifndef SS_DBUF_REFLOCK_DISABLE
4549 ret = SUnlock(&(dptr->dBufLock));
4552 #else /* SS_MULTICORE_SUPPORT */
4553 /* If MultiCore Support enabled, Dblk never be shared */
4554 #ifdef SS_HISTOGRAM_SUPPORT
4555 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4556 , __LINE__, (uint8_t*) __FILE__, ENTNC);
4558 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4559 #endif /* SS_HISTOGRAM_SUPPORT */
4560 #endif /* SS_MULTICORE_SUPPORT */
4565 /* #ifdef SS_LOCKLESS_MEMORY */
4572 * Desc: This function will concatenate the two specified messages
4576 * RFAILED - failed, general (optional)
4578 * Notes: if order equal M1M2: all data attached to message 2 is
4579 * moved to the end of message 1. message 2 is set to empty.
4580 * message 1 length is increased by length of message 2.
4581 * message 2 length is set to zero. message 2 is not returned
4582 * to memory. return is ok.
4584 * if order equal M2M1: all data attached to message 2 is
4585 * moved to the front of message 1. message 2 is set to empty.
4586 * message 1 length is increased by length of message 2.
4587 * message 2 length is set to zero. message 2 is not returned
4588 * to memory. return is ok.
4598 Buffer *mBuf1, /* message 1 */
4599 Buffer *mBuf2, /* message 2 */
4603 S16 SCatMsg(mBuf1, mBuf2, order)
4604 Buffer *mBuf1; /* message 1 */
4605 Buffer *mBuf2; /* message 2 */
4606 Order order; /* order */
4614 #if (ERRCLASS & ERRCLS_INT_PAR)
4615 /* check message buffer 1 */
4618 SSLOGERROR(ERRCLS_INT_PAR, ESS148, ERRZERO, "SCatMsg : Null Buffer");
4621 /* check message buffer 2 */
4624 SSLOGERROR(ERRCLS_INT_PAR, ESS149, ERRZERO, "SCatMsg : Null Buffer");
4627 /* ss021.103 - Addition to test if same buffer */
4628 /* check message buffer 1 and 2 not same buffer */
4631 SSLOGERROR(ERRCLS_INT_PAR, ESS150, ERRZERO, "SCatMsg : mBuf1 == mBuf2");
4634 if ((order != M1M2) && (order != M2M1))
4636 SSLOGERROR(ERRCLS_INT_PAR, ESS151, ERRZERO, "SCatMsg : Invalid Order");
4639 if ((mBuf1->b_datap->db_type != SS_M_PROTO) ||
4640 (mBuf2->b_datap->db_type != SS_M_PROTO))
4642 SSLOGERROR(ERRCLS_INT_PAR, ESS152, ERRZERO,
4643 "SCatMsg : Incorrect buffer type");
4648 /* no data to append or prepend */
4652 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
4653 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
4655 /* ss021.103 - Addition to test max length of message is not exceeded */
4656 #if (ERRCLASS & ERRCLS_INT_PAR)
4658 if (minfo1->len > 0x7FFFFFFF - minfo2->len)
4660 if (minfo1->len > 0x7FFF - minfo2->len)
4663 SSLOGERROR(ERRCLS_INT_PAR, ESS153, ERRZERO, "SCpyFixMsg : messages too big");
4668 if (minfo1->region != minfo2->region)
4670 /* duplicate mBuf2 from the region/pool of mBuf1, initialise mBuf2 */
4671 /*ss015.13: addition */
4672 if (SCpyMsgMsg(mBuf2, minfo1->region, minfo1->pool, &newb) != ROK)
4675 minfo2 = (SsMsgInfo*) newb->b_rptr;
4680 if ((tmp = mBuf1->b_cont) == NULLP)
4682 mBuf1->b_cont = newb->b_cont;
4683 minfo1->endptr = minfo2->endptr;
4688 /* attach newb after mBuf1 */
4690 minfo1->endptr->b_cont = newb->b_cont;
4691 minfo1->endptr = minfo2->endptr;
4696 /* attach newb before mBuf1 */
4698 minfo2->endptr->b_cont = mBuf1->b_cont;
4699 mBuf1->b_cont = newb->b_cont;
4701 else /* invalid order */
4703 #if (ERRCLASS & ERRCLS_DEBUG)
4704 SSLOGERROR(ERRCLS_DEBUG, ESS154, ERRZERO, "SCatMsg:Invalid order");
4706 if (newb && (newb != mBuf2))
4707 (Void) SPutMsg(newb);
4712 minfo1->len += minfo2->len;
4715 minfo2->endptr = NULLP;
4718 newb->b_cont = NULLP;
4722 (Void) SPutMsg(newb);
4723 (Void) SInitMsg(mBuf2);
4733 * Desc: This function replaces one byte of data in a message.
4736 * ROKDNA - ok, data not available
4737 * RFAILED - failed, general (optional)
4739 * Notes: index is 0 based and indicates location in message
4741 * if index is less than the length of the message:
4742 * data is replaced at specified index. message length
4743 * is unchanged. return is ok.
4745 * if index is greater than or equal to
4746 * the length of the message: message is unchanged.
4747 * return is ok, data not available.
4757 Data data, /* data */
4758 Buffer *mBuf, /* message buffer */
4762 S16 SRepMsg(data, mBuf, idx)
4763 Data data; /* data */
4764 Buffer *mBuf; /* message buffer */
4765 MsgLen idx; /* index */
4775 #ifdef T2K_MEM_LEAK_DBG
4776 char* file = __FILE__;
4777 uint32_t line = __LINE__;
4779 #if ( ERRCLASS & ERRCLS_INT_PAR)
4780 /* check message buffer */
4783 SSLOGERROR(ERRCLS_INT_PAR, ESS155, ERRZERO, "SRepMsg : Null Buffer");
4788 SSLOGERROR(ERRCLS_INT_PAR, ESS156, ERRZERO, "SRepMsg : Invalid index");
4791 if (mBuf->b_datap->db_type != SS_M_PROTO)
4793 SSLOGERROR(ERRCLS_INT_PAR, ESS157, ERRZERO, "SRepMsg : Incorrect buffer\
4799 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4801 /* if index > length of the buffer */
4802 if (minfo->len <= idx)
4807 tmp = mBuf->b_cont; /* get the first SS_M_DATA blk */
4808 prev = mBuf; /* parent */
4810 FIND_OFFSET_AND_PREV(prev, tmp, idx)
4812 /* if ref cnt is greater than 1, duplicate tmp */
4813 if (tmp->b_datap->db_ref > 1)
4815 /* allocate a message blk of message size of tmp */
4816 numBytes = tmp->b_wptr - tmp->b_rptr;
4817 if (ssGetDBufOfSize(minfo->region, numBytes, &newb) != ROK)
4819 SSLOGERROR(ERRCLS_DEBUG, ESS158, ERRZERO, "SRepMsg : ssGetDBufOfSize\
4824 *newb->b_wptr++ = *tmp->b_rptr++;
4826 newb->b_cont = tmp->b_cont;
4827 prev->b_cont = newb;
4828 if (minfo->endptr == tmp)
4829 minfo->endptr = newb;
4832 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
4835 *(tmp->b_rptr + idx) = data;
4844 * Desc: Update a message with a new dBuf
4858 Buffer *mBuf, /* message buffer */
4859 Buffer *dBuf, /* data buffer */
4863 S16 SUpdMsg(mBuf, dBuf, dLen)
4864 Buffer *mBuf; /* message buffer */
4865 Buffer *dBuf; /* data buffer */
4866 MsgLen dLen; /* data length */
4871 #if (ERRCLASS & ERRCLS_INT_PAR)
4874 SSLOGERROR(ERRCLS_INT_PAR, ESS159, ERRZERO, "SUpdMsg : Null Buffer");
4879 SSLOGERROR(ERRCLS_INT_PAR, ESS160, ERRZERO, "SUpdMsg : Null Buffer");
4884 SSLOGERROR(ERRCLS_INT_PAR, ESS161, ERRZERO, "SUpdMsg : Invalid length");
4887 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4888 (dBuf->b_datap->db_type != SS_M_DATA))
4890 SSLOGERROR(ERRCLS_INT_PAR, ESS162, ERRZERO, "SUpdMsg : Incorrect buffer\
4896 /* get the message info of mBuf */
4897 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4899 /* accept zero length data */
4901 /* buffer offset out of bounds */
4902 if ((dBuf->b_rptr + dLen) > dBuf->b_datap->db_lim)
4904 SSLOGERROR(ERRCLS_DEBUG, ESS163, ERRZERO, "SUpdMsg:Offset out of bounds");
4908 /* offset write ptr from read ptr by dLen */
4909 dBuf->b_wptr = dBuf->b_rptr + dLen;
4911 /* attach dBuf at the end of mBuf */
4913 minfo->endptr->b_cont = dBuf;
4915 mBuf->b_cont = dBuf;
4917 /* update SsMsgInfo */
4918 minfo->endptr = dBuf;
4929 * Desc: This function queues a data buffer to the
4930 * back of the specified message buffer .
4933 * RFAILED - failed, general (optional)
4935 * Notes: if queue is empty: buffer is placed in the queue.
4936 * queue length is incremented.
4938 * if queue is not empty: buffer is placed behind all
4939 * other buffers in queue. queue length is incremented.
4949 Buffer *mBuf, /* message buffer */
4953 S16 SAddDBufPst(mBuf, dBuf)
4954 Buffer *mBuf; /* message buffer */
4955 Buffer *dBuf; /* data buffer */
4960 #if (ERRCLASS & ERRCLS_INT_PAR)
4961 /* check buffer queue */
4964 SSLOGERROR(ERRCLS_INT_PAR, ESS164, ERRZERO, "SAddDBufPst : Null Buffer");
4967 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4968 (dBuf->b_datap->db_type != SS_M_DATA))
4970 SSLOGERROR(ERRCLS_INT_PAR, ESS165, ERRZERO, "SAddDBufPst : Incorrect\
4976 /* no data, return */
4977 if (dBuf->b_wptr == dBuf->b_rptr)
4980 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4982 /* attach dBuf at the end of mBuf */
4984 minfo->endptr->b_cont = dBuf;
4986 mBuf->b_cont = dBuf;
4988 /* update SsMsgInfo */
4989 minfo->endptr = dBuf;
4991 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
5000 * Desc: This function queues a data buffer to the
5001 * front of the specified message buffer.
5004 * RFAILED - failed, general (optional)
5006 * Notes: if buffer queue is empty: buffer is placed in the queue. queue
5007 * length is incremented.
5009 * if buffer queue is not empty: buffer is placed in front of all
5010 * other buffers in queue. queue length is incremented.
5020 Buffer *mBuf, /* message buffer */
5024 S16 SAddDBufPre(mBuf, dBuf)
5025 Buffer *mBuf; /* message buffer */
5026 Buffer *dBuf; /* data buffer */
5032 #if (ERRCLASS & ERRCLS_INT_PAR)
5033 /* check buffer queue */
5036 SSLOGERROR(ERRCLS_INT_PAR, ESS166, ERRZERO, "SAddDBufPre : Null Buffer");
5039 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
5040 (dBuf->b_datap->db_type != SS_M_DATA))
5042 SSLOGERROR(ERRCLS_INT_PAR, ESS167, ERRZERO, "SAddDBufPre : Incorrect\
5048 /* no data, return */
5049 if (dBuf->b_wptr == dBuf->b_rptr)
5052 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5056 /* attach dBuf at the start of mBuf */
5057 mBuf->b_cont = dBuf;
5060 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
5063 minfo->endptr = dBuf;
5072 * Desc: This function dequeues a data buffer from
5073 * the front of the specified message buffer.
5076 * ROKDNA - ok, data not available
5077 * RFAILED - failed, general (optional)
5079 * Notes: if queue is empty: pointer to buffer is set to null and
5080 * return is ok, data not available. queue length is unchanged.
5082 * if queue is not empty: pointer to buffer is set to first
5083 * buffer in queue, first buffer in queue is removed and
5084 * return is ok. queue length is decremented.
5094 Buffer *mBuf, /* message buffer */
5098 S16 SRemDBufPre(mBuf, dBufPtr)
5099 Buffer *mBuf; /* message buffer */
5100 Buffer **dBufPtr; /* pointer to data buffer */
5105 #if (ERRCLASS & ERRCLS_INT_PAR)
5106 /* check buffer pointer */
5107 if (dBufPtr == NULLP)
5109 SSLOGERROR(ERRCLS_INT_PAR, ESS168, ERRZERO, "SRemDBufPre : Null Buffer");
5115 SSLOGERROR(ERRCLS_INT_PAR, ESS169, ERRZERO, "SRemDBufPre : Null Buffer");
5118 if (mBuf->b_datap->db_type != SS_M_PROTO)
5120 SSLOGERROR(ERRCLS_INT_PAR, ESS170, ERRZERO, "SRemDBufPre : Incorrect\
5126 /* no data blk, return */
5127 if ((*dBufPtr = mBuf->b_cont) == NULLP)
5131 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5133 mBuf->b_cont = (*dBufPtr)->b_cont;
5134 (*dBufPtr)->b_cont = NULLP;
5136 /* update SsMsgInfo */
5137 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
5138 minfo->endptr = NULLP;
5147 * Desc: This function dequeues a data or message buffer from the
5148 * back of the specified message buffer.
5151 * ROKDNA - ok, data not available
5152 * RFAILED - failed, general (optional)
5154 * Notes: if queue is empty: pointer to buffer is set to null and
5155 * return is ok, data not available. queue length is unchanged.
5157 * if queue is not empty: pointer to buffer is set to last
5158 * buffer in queue, last buffer in queue is removed and
5159 * return is ok. queue length is decremented.
5169 Buffer *mBuf, /* message buffer */
5173 S16 SRemDBufPst(mBuf, dBufPtr)
5174 Buffer *mBuf; /* message buffer */
5175 Buffer **dBufPtr; /* pointer to data buffer */
5181 #if (ERRCLASS & ERRCLS_INT_PAR)
5182 /* check buffer pointer */
5185 SSLOGERROR(ERRCLS_INT_PAR, ESS171, ERRZERO, "SRemDBufPst : Null Buffer");
5191 SSLOGERROR(ERRCLS_INT_PAR, ESS172, ERRZERO, "SRemDBufPst : Null Buffer");
5194 if (mBuf->b_datap->db_type != SS_M_PROTO)
5196 SSLOGERROR(ERRCLS_INT_PAR, ESS173, ERRZERO, "SRemDBufPst : Incorrect\
5202 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5204 /* no data blk, return */
5205 if ((*dBufPtr = minfo->endptr) == NULLP)
5209 for (tmp = mBuf; tmp->b_cont != (*dBufPtr); )
5212 tmp->b_cont = NULLP;
5214 /* update SsMsgInfo */
5215 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
5216 minfo->endptr = NULLP;
5218 minfo->endptr = tmp;
5227 * Desc: Initialize next Data Buffer Id
5231 * Notes: Must be called prior to SGetNxtDBuf
5244 S16 SInitNxtDBuf(mBuf)
5245 Buffer *mBuf; /* message buffer */
5250 #if (ERRCLASS & ERRCLS_INT_PAR)
5253 SSLOGERROR(ERRCLS_INT_PAR, ESS174, ERRZERO, "SInitNxtDBuf : Null Buffer");
5256 if (mBuf->b_datap->db_type != SS_M_PROTO)
5258 SSLOGERROR(ERRCLS_INT_PAR, ESS175, ERRZERO, "SInitNxtDBuf : Incorrect\
5264 minfo = (SsMsgInfo*) mBuf->b_rptr;
5266 /* set the next ptr of mBuf to point to the first SS_M_DATA blk */
5267 minfo->next = mBuf->b_cont;
5276 * Desc: Get next dBuf in message chain
5280 * Notes: Must be called after SInitNxtDBuf
5290 Buffer *mBuf, /* message buffer */
5294 S16 SGetNxtDBuf(mBuf, dBuf)
5295 Buffer *mBuf; /* message buffer */
5296 Buffer **dBuf; /* data buffer return */
5301 #if (ERRCLASS & ERRCLS_INT_PAR)
5304 SSLOGERROR(ERRCLS_INT_PAR, ESS176, ERRZERO, "SGetNxtDBuf : Null Buffer");
5309 SSLOGERROR(ERRCLS_INT_PAR, ESS177, ERRZERO, "SGetNxtDBuf : Null Buffer");
5312 if (mBuf->b_datap->db_type != SS_M_PROTO)
5314 SSLOGERROR(ERRCLS_INT_PAR, ESS178, ERRZERO, "SGetNxtDBuf : Incorrect\
5320 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5322 /* if next ptr of mBuf is NULLP, return */
5323 if ((*dBuf = minfo->next) == NULLP)
5327 minfo->next = (*dBuf)->b_cont;
5336 * Desc: check if next data buffer exists.
5338 * Ret: ROK/ROKDNA/RFAILED
5340 * Notes: doesn't modify nxtDBuf
5352 S16 SChkNxtDBuf(mBuf)
5353 Buffer *mBuf; /* message buffer */
5358 #if (ERRCLASS & ERRCLS_INT_PAR)
5361 SSLOGERROR(ERRCLS_INT_PAR, ESS179, ERRZERO, "SChkNxtDBuf : Null Buffer");
5364 if (mBuf->b_datap->db_type != SS_M_PROTO)
5366 SSLOGERROR(ERRCLS_INT_PAR, ESS180, ERRZERO, "SChkNxtDBuf : Incorrect\
5370 #endif /* ERRCLASS */
5372 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5374 /* if next is valid, return ROK */
5385 * Desc: Given a data buffer, return a pointer to the
5386 * data payload, and the length of the payload
5392 * Notes: This assumes an uninitialized dBuf
5402 Buffer *dBuf, /* data buffer */
5403 MsgLen pad, /* pad */
5404 Data **retDatPtr, /* return data pointer */
5408 S16 SGetDataRx(dBuf, pad, retDatPtr, retDatLen)
5409 Buffer *dBuf; /* data buffer */
5410 MsgLen pad; /* pad */
5411 Data **retDatPtr; /* return data pointer */
5412 MsgLen *retDatLen; /* return data length */
5416 #if (ERRCLASS & ERRCLS_INT_PAR)
5419 SSLOGERROR(ERRCLS_INT_PAR, ESS181, ERRZERO, "SGetDataRx : Null Buffer");
5422 if (!retDatLen || (pad < 0))
5424 SSLOGERROR(ERRCLS_INT_PAR, ESS182, ERRZERO, "SGetDataRx : Null Buffer");
5429 SSLOGERROR(ERRCLS_INT_PAR, ESS183, ERRZERO, "SGetDataRx : Null Buffer");
5432 if (dBuf->b_datap->db_type != SS_M_DATA)
5434 SSLOGERROR(ERRCLS_INT_PAR, ESS184, ERRZERO, "SGetDataRx : Incorrect\
5438 #endif /* ERRCLASS */
5440 if (dBuf->b_datap->db_ref > 1) /* cannot write to a shared buffer */
5442 #if (ERRCLASS & ERRCLS_DEBUG)
5443 SSLOGERROR(ERRCLS_DEBUG, ESS185, ERRZERO, "SGetDataRx : Reference\
5449 /* return the write ptr loc(with padding) if there is data to write to */
5450 if ((*retDatLen = (dBuf->b_datap->db_lim - dBuf->b_wptr - pad)) > 0)
5451 *retDatPtr = dBuf->b_wptr + pad;
5455 #if (ERRCLASS & ERRCLS_DEBUG)
5456 SSLOGERROR(ERRCLS_DEBUG, ESS186, ERRZERO, "SGetDataRx:No data available");
5468 * Desc: Given a data buffer, return a pointer to the
5469 * data payload, and the length of the payload
5475 * Notes: This assumes an initialized dBuf
5485 Buffer *dBuf, /* data buffer */
5486 Data **retDatPtr, /* return data pointer */
5487 MsgLen *retDatLen /* return data length */
5490 S16 SGetDataTx(dBuf, retDatPtr, retDatLen)
5491 Buffer *dBuf; /* data buffer */
5492 Data **retDatPtr; /* return data pointer */
5493 MsgLen *retDatLen; /* return data length */
5497 #if (ERRCLASS & ERRCLS_INT_PAR)
5498 /* ss021.103 - Modification to check parameters */
5501 SSLOGERROR(ERRCLS_INT_PAR, ESS187, ERRZERO, "SGetDataTx : Null Buffer");
5506 SSLOGERROR(ERRCLS_INT_PAR, ESS188, ERRZERO, "SGetDataTx : Null Buffer");
5507 *retDatPtr = (Data *)NULLP;
5512 SSLOGERROR(ERRCLS_INT_PAR, ESS189, ERRZERO, "SGetDataTx : Null Buffer");
5515 if (dBuf->b_datap->db_type != SS_M_DATA)
5517 SSLOGERROR(ERRCLS_INT_PAR, ESS190, ERRZERO, "SGetDataTx : Incorrect\
5519 *retDatPtr = (Data *)NULLP;
5522 #endif /* ERRCLASS */
5524 /* if there is data, return read ptr */
5525 if ((*retDatLen = dBuf->b_wptr - dBuf->b_rptr))
5526 *retDatPtr = dBuf->b_rptr;
5530 #if (ERRCLASS & ERRCLS_DEBUG)
5531 SSLOGERROR(ERRCLS_DEBUG, ESS191, ERRZERO, "SGetDataTx : Buffer empty");
5539 #ifndef SS_ENABLE_MACROS
5543 * Fun: SGetBufRegionPool
5545 * Desc: returns the region and pool of the message buffer
5547 * Ret: ROK on success
5556 S16 SGetBufRegionPool
5558 Buffer *mBuf, /* message buffer */
5559 Region *region, /* region */
5560 Pool *pool /* pool */
5563 S16 SGetBufRegionPool(mBuf, region, pool)
5564 Buffer *mBuf; /* message buffer */
5565 Region *region; /* region */
5566 Pool *pool; /* pool */
5569 SsMsgInfo *mInfo; /* message info pointer */
5572 #if (ERRCLASS & ERRCLS_INT_PAR)
5576 SSLOGERROR(ERRCLS_INT_PAR, ESS192, ERRZERO,
5577 "SGetBufRegionPool : Null Buffer");
5580 if ((region == NULLP) && (pool == NULLP))
5582 SSLOGERROR(ERRCLS_INT_PAR, ESS193, ERRZERO,
5583 "SGetBufRegionPool : Null region and pool pointers");
5586 if (mBuf->b_datap->db_type != SS_M_PROTO)
5588 SSLOGERROR(ERRCLS_INT_PAR, ESS194, ERRZERO,
5589 "SUpdMsg : Incorrect buffer type");
5592 #endif /* (ERRCLASS & ERRCLS_INT_PAR */
5594 /* get message info of mBuf */
5595 if ((mInfo = (SsMsgInfo *) mBuf->b_rptr) == NULLP)
5597 #if (ERRCLASS & ERRCLS_DEBUG)
5598 SSLOGERROR(ERRCLS_DEBUG, ESS195, ERRZERO,
5599 "SGetBufRegionPool : mBuf's control data is null");
5604 if (region != NULLP)
5605 *region = mInfo->region;
5607 *pool = mInfo->pool;
5610 } /* end of SGetBufRegionPool */
5612 #endif /* SS_ENABLE_MACROS */
5618 * Desc: This function is used to compress a message into
5619 * the minimum number of data buffers needed.
5622 * RFAILED - failed, general (optional)
5623 * ROUTRES - failed, out of resources (optional)
5638 S16 SCompressMsg(mBuf)
5639 Buffer *mBuf; /* message buffer */
5649 #ifdef T2K_MEM_LEAK_DBG
5650 char* file = __FILE__;
5651 uint32_t line = __LINE__;
5654 #if (ERRCLASS & ERRCLS_INT_PAR)
5657 SSLOGERROR(ERRCLS_INT_PAR, ESS196, ERRZERO, "SCompressMsg : Null Buffer");
5660 if (mBuf->b_datap->db_type != SS_M_PROTO)
5662 SSLOGERROR(ERRCLS_INT_PAR, ESS197, ERRZERO, "SCompressMsg : Incorrect\
5668 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5670 if ((tmp = mBuf->b_cont) == minfo->endptr)
5675 /* allocate a data buffer of size bytes*/
5676 if ((ret = ssGetDBufOfSize(minfo->region, minfo->len, &dBuf)) != ROK)
5678 SSLOGERROR(ERRCLS_DEBUG, ESS198, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
5682 dBuf->b_datap->db_type = SS_M_DATA;
5686 /* determine number of bytes to be copied */
5687 numBytes = tmp->b_wptr - tmp->b_rptr;
5691 /* ss002.13: addition */
5692 /* ss003.13: addition */
5693 SMemCpy( (Void *)dBuf->b_wptr, (Void *)tmp->b_rptr, (size_t)numBytes);
5695 dBuf->b_wptr += numBytes;
5696 tmp->b_rptr += numBytes;
5700 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
5703 /* update mBuf and SsMsgInfo */
5704 mBuf->b_cont = dBuf;
5705 minfo->endptr = dBuf;
5714 * Desc: This function prints the contents of a message. The
5715 * following information is printed: queue length,
5716 * message length, direction, hexadecimal and ASCII
5717 * (if appropriate) values of all bytes in the message.
5719 * This function should be used for debugging only.
5732 Buffer *mBuf, /* message buffer */
5733 S16 src, /* source id */
5734 S16 dst /* destination id */
5737 S16 SPrntMsg(mBuf, src, dst)
5738 Buffer *mBuf; /* message buffer */
5739 S16 src; /* source id */
5740 S16 dst; /* destination id */
5743 QLen qlen; /* queue length */
5744 MsgLen mlen; /* message length */
5748 /* ss038.103 : 102061 Changed to MsgLen from S16 */
5749 MsgLen i; /* counter */
5750 S16 j; /* counter */
5751 S16 k; /* counter */
5752 uint8_t data; /* data */
5753 uint8_t tdata[16] = {0}; /* temporary data */
5754 S8 prntBuf[256]; /* print buffer */
5755 Buffer *tmp; /* buffer ptr */
5757 /* ss012.13: Addition */
5764 sprintf(prntBuf,"\nmsg: empty\n");
5766 SPrint( (S8*)"\n\n");
5770 for (qlen = 0, tmp = mBuf->b_cont; tmp; qlen++)
5772 mlen = ((SsMsgInfo*)(mBuf->b_rptr))->len;
5773 reg = ((SsMsgInfo*)(mBuf->b_rptr))->region;
5774 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
5775 sprintf(prntBuf,"\nmsg: qlen: %04d mlen: %04d %02d-->%02d region: %02d\n",
5776 (uint16_t)qlen,(uint16_t)mlen,src,dst,reg);
5778 #ifdef XEON_SPECIFIC_CHANGES
5779 printf("%s\n", prntBuf);
5781 SPrint((S8*) "dat: ");
5782 #ifdef XEON_SPECIFIC_CHANGES
5788 sprintf(prntBuf," empty\n");
5790 SPrint( (S8*)"\n\n");
5800 for( j = 0; j < 16; j++)
5806 sprintf( prntBuf,"%02x ",(uint16_t) data);
5808 #ifdef XEON_SPECIFIC_CHANGES
5809 printf("%s\n", prntBuf);
5811 if (cptr == tmp->b_wptr)
5817 /* ss024.103 - Modification to fix bug */
5824 sprintf( prntBuf," ");
5826 #ifdef XEON_SPECIFIC_CHANGES
5827 printf("%s\n", prntBuf);
5831 for (k = 0; k < 16; k++)
5833 if( (i >= mlen) && (k>=(mlen%16)) && mlen%16 != 0)
5835 if (AIsAscii(tdata[k]))
5837 /* print character if printable */
5838 sprintf(prntBuf,"%c",tdata[k]);
5840 #ifdef XEON_SPECIFIC_CHANGES
5841 printf("%s\n", prntBuf);
5846 /* print . if non printable */
5848 #ifdef XEON_SPECIFIC_CHANGES
5853 sprintf(prntBuf,"\n ");
5855 #ifdef XEON_SPECIFIC_CHANGES
5856 printf("%s\n", prntBuf);
5861 } /* end of SPrntMsg */
5867 * Fun: SGetPstMsgMult
5869 * Desc: This function allocates consecutive bytes of data at the
5873 * RFAILED - failed, general (optional)
5874 * ROUTRES - failed, out of resources (optional)
5876 * Notes: if message is empty: message length is incremented.
5879 * if message is not empty: space is allocated in back of
5880 * all other data in message. message length is incremented.
5889 MsgLen cnt, /* count */
5890 Buffer *mBuf /* message buffer */
5893 S16 SGetPstMsgMult(cnt, mBuf)
5894 MsgLen cnt; /* count */
5895 Buffer *mBuf; /* message buffer */
5905 #if ( ERRCLASS & ERRCLS_INT_PAR )
5906 /* check message buffer */
5916 if (mBuf->b_datap->db_type != SS_M_PROTO)
5921 /* get the message info */
5922 minfo = (SsMsgInfo *) (mBuf->b_rptr);
5927 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
5928 ((avail = tmp->b_datap->db_lim - tmp->b_wptr)))
5930 numBytes = MIN(cnt, avail);
5933 minfo->len += numBytes;
5936 /* ss002.13 addition */
5937 /* ss003.13 addition */
5938 SMemSet( (Void *)tmp->b_wptr, (Data)'\0', (size_t)numBytes);
5940 tmp->b_wptr += numBytes;
5944 if (ssGetDBufOfSize(minfo->region, cnt, &newb) != ROK)
5946 /* ss027.103 - Modification to fix bug in SGetPstMsgMult */
5947 if ((avail) && (tmp))
5948 tmp->b_wptr = tmp->b_datap->db_lim - avail;
5949 minfo->len -= avail;
5956 /* ss002.13: addition */
5957 /* ss003.13: addition */
5958 SMemSet( (Void *)newb->b_wptr, (Data)'\0', (size_t)cnt);
5960 newb->b_wptr += cnt;
5966 mBuf->b_cont = newb;
5968 minfo->endptr = newb;
5977 * Desc: Check Message
5979 * Ret: ROK on success
5982 * Notes: Check that the first buffer in a message
5983 * contains at least two bytes. This check is required
5984 * by 68302/68360 processors to insure accurate fisu
6004 #if ( ERRCLASS & ERRCLS_INT_PAR )
6005 /* check message buffer */
6010 if (mBuf->b_datap->db_type != SS_M_PROTO)
6015 /* get the message info */
6016 minfo = (SsMsgInfo *) (mBuf->b_rptr);
6021 /* get the first M_DATA blk*/
6024 if (((tmp->b_rptr + 2) <= tmp->b_wptr) || (SCompressMsg(mBuf) == ROK))
6032 * Fun: SAlignDBufEven
6034 * Desc: align data portion of a data buffer on an even
6039 * Notes: required for SS7 microcode on the 68302
6047 Buffer *dBuf /* data buffer */
6050 S16 SAlignDBufEven(dBuf)
6051 Buffer *dBuf; /* data buffer */
6057 #if (ERRCLASS & ERRCLS_INT_PAR)
6060 SSLOGERROR(ERRCLS_INT_PAR, ESS199, ERRZERO, "SAlignDBufEven : Null\
6064 if (dBuf->b_datap->db_type != SS_M_DATA)
6066 SSLOGERROR(ERRCLS_INT_PAR, ESS200, ERRZERO, "SAlignDBufEven : Incorrect\
6073 /* ss008.13: addition */
6074 if (!((PTR)src % (PTR)2))
6077 if (dBuf->b_datap->db_ref > 1)
6080 len = dBuf->b_wptr - dBuf->b_rptr;
6082 if (dBuf->b_datap->db_base < dBuf->b_rptr)
6084 dBuf->b_wptr = --dBuf->b_rptr;
6086 *dBuf->b_wptr++ = *src++;
6089 if (dBuf->b_datap->db_lim > dBuf->b_wptr)
6091 src = dBuf->b_wptr - 1;
6092 dBuf->b_rptr = ++dBuf->b_wptr;
6094 *--dBuf->b_rptr = *src--;
6102 /* ss004.13: addition */
6107 * Desc: Align data portion of a data buffer on the specified
6108 * boundary. No restriction is imposed on the alignment.
6112 * Notes: required by drivers (68360, 860)
6120 Buffer *dBuf, /* data buffer */
6121 uint32_t align /* alignemnt required */
6124 S16 SAlignDBuf(dBuf, align)
6125 Buffer *dBuf; /* data buffer */
6126 uint32_t align; /* alignemnt required */
6131 uint32_t upShift; /* no. of bytes to be shifted up */
6132 uint32_t downShift; /* no. of bytes to be shifted down */
6134 #if (ERRCLASS & ERRCLS_INT_PAR)
6137 SSLOGERROR(ERRCLS_INT_PAR, ESS201, ERRZERO, "SAlignDBuf: Null\
6141 if (dBuf->b_datap->db_type != SS_M_DATA)
6143 SSLOGERROR(ERRCLS_INT_PAR, ESS202, ERRZERO, "SAlignDBuf: Incorrect\
6150 /* ss008.13: addition */
6151 upShift = (PTR)src % (PTR)align; /* no. of bytes by which to shift up
6152 * the read and write pointers */
6157 if (dBuf->b_datap->db_ref > 1)
6160 downShift = align - upShift; /* no of bytes by which to shift down
6161 * the read and write pointers */
6162 len = dBuf->b_wptr - dBuf->b_rptr;
6164 if (dBuf->b_datap->db_base <= (dBuf->b_rptr - upShift))
6166 /* there is space to shift up the read and write pointers */
6168 dBuf->b_rptr -= upShift; /* align the read pointer */
6169 dBuf->b_wptr = dBuf->b_rptr;
6170 SMemCpy( (Void *) dBuf->b_wptr, (Void *) src, (size_t) len);
6171 dBuf->b_wptr = dBuf->b_wptr + len;
6175 if (dBuf->b_datap->db_lim > dBuf->b_wptr + downShift)
6177 src = dBuf->b_wptr - 1;
6178 dBuf->b_wptr = dBuf->b_wptr + downShift;
6179 dBuf->b_rptr = dBuf->b_wptr;
6181 *--dBuf->b_rptr = *src--;
6195 * Desc: Allocates a static buffer pool within the specified
6199 * RFAILED - failed, general (optional)
6201 * Notes: The new memory management scheme makes this function
6202 * meaningless. It merely sets the pool ID to zero and
6211 Region region, /* region ID */
6212 Size size, /* size */
6213 Pool *pool /* pointer to pool ID */
6216 S16 SGetSMem(region, size, pool)
6217 Region region; /* region ID */
6218 Size size; /* size */
6219 Pool *pool; /* pointer to pool ID */
6226 #if (ERRCLASS & ERRCLS_INT_PAR)
6227 /* validate region ID */
6228 if (region >= SS_MAX_REGS)
6230 SSLOGERROR(ERRCLS_INT_PAR, ESS203, region, "Invalid region");
6234 /* validate pointer to pool ID */
6237 SSLOGERROR(ERRCLS_INT_PAR, ESS204, region, "Null pointer");
6243 /* set the pool ID to zero and return success */
6255 * Desc: Deallocates a static buffer pool within the specified
6259 * RFAILED - failed, general (optional)
6261 * Notes: The new memory management scheme makes this function
6262 * meaningless. It does nothing.
6270 Region region, /* region ID */
6271 Pool pool /* pool ID */
6274 S16 SPutSMem(region, pool)
6275 Region region; /* region ID */
6276 Pool pool; /* pool ID */
6279 /* ss021.103 - Addition of return value */
6280 #if (ERRCLASS & ERRCLS_INT_PAR)
6285 #if (ERRCLASS & ERRCLS_INT_PAR)
6286 /* validate region ID */
6287 if (region >= SS_MAX_REGS)
6289 SSLOGERROR(ERRCLS_INT_PAR, ESS205, region, "Invalid region");
6293 /* validate pool ID */
6294 if (pool >= SS_MAX_POOLS_PER_REG)
6296 SSLOGERROR(ERRCLS_INT_PAR, ESS206, region, "Invalid pool");
6300 /* ss021.103 - Addition to check if region is registered */
6301 /* acquire one semaphore, to protect against deregistration */
6302 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
6306 #if (ERRCLASS & ERRCLS_DEBUG)
6307 SSLOGERROR(ERRCLS_DEBUG, ESS207, (ErrVal) ret,
6308 "Could not lock region table");
6315 #if (ERRCLASS & ERRCLS_INT_PAR)
6316 /* verify that this region is present */
6317 if (osCp.regionTbl[region].used == FALSE)
6319 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6321 #if (ERRCLASS & ERRCLS_DEBUG)
6322 SSLOGERROR(ERRCLS_DEBUG, ESS208, ERRZERO,
6323 "Could not release semaphore");
6328 SSLOGERROR(ERRCLS_INT_PAR, ESS209, region, "Region not registered");
6333 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6335 #if (ERRCLASS & ERRCLS_DEBUG)
6336 SSLOGERROR(ERRCLS_DEBUG, ESS210, ERRZERO,
6337 "Could not release semaphore");
6351 * Desc: Checks the available system resources (memory).
6354 * RFAILED - failed, general (optional)
6364 Region region, /* region ID */
6365 Pool pool, /* pool ID */
6366 Status *status /* pointer to status */
6369 S16 SChkRes(region, pool, status)
6370 Region region; /* region ID */
6371 Pool pool; /* pool ID */
6372 Status *status; /* pointer to status */
6380 #if (ERRCLASS & ERRCLS_INT_PAR)
6381 /* validate region ID */
6382 if (region >= SS_MAX_REGS)
6384 SSLOGERROR(ERRCLS_INT_PAR, ESS229, region, "Invalid region");
6388 /* validate pool ID */
6389 if (pool >= SS_MAX_POOLS_PER_REG)
6391 SSLOGERROR(ERRCLS_INT_PAR, ESS230, region, "Invalid pool");
6395 /* validate status pointer */
6396 if (status == NULLP)
6398 SSLOGERROR(ERRCLS_INT_PAR, ESS231, ERRZERO, "Null pointer");
6402 /* ss037.103 Removed the semaphore operation for performance enhancement */
6405 /* acquire one semaphore, to protect against deregistration */
6406 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
6410 #if (ERRCLASS & ERRCLS_DEBUG)
6411 SSLOGERROR(ERRCLS_DEBUG, ESS232, (ErrVal) ret,
6412 "Could not lock region table");
6419 #if (ERRCLASS & ERRCLS_INT_PAR)
6420 /* verify that this region is around */
6421 if (osCp.regionTbl[region].used == FALSE)
6424 /* ss006.13: addition */
6425 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6427 #if (ERRCLASS & ERRCLS_DEBUG)
6428 SSLOGERROR(ERRCLS_DEBUG, ESS233, ERRZERO,
6429 "Could not release semaphore");
6434 SSLOGERROR(ERRCLS_INT_PAR, ESS234, region, "Region not registered");
6438 /* verify that this is a valid pool */
6439 if (osCp.regionTbl[region].poolTbl[pool].type != SS_POOL_DYNAMIC)
6441 SSLOGERROR(ERRCLS_DEBUG, ESS235, ERRZERO, "Invalid pool");
6447 /* call the memory manager to check resources */
6448 mctl.op = SS_MEM_CHK_RES;
6449 mctl.u.chkres.size = osCp.regionTbl[region].poolTbl[pool].u.dpool.size;
6450 mctl.u.chkres.status = status;
6451 ret = (osCp.regionTbl[region].ctl)
6452 (osCp.regionTbl[region].regCb, SS_MEM_CHK_RES, &mctl);
6454 /* release the semaphore we took */
6456 /* ss006.13: addition */
6457 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6459 #if (ERRCLASS & ERRCLS_DEBUG)
6460 SSLOGERROR(ERRCLS_DEBUG, ESS236, ERRZERO,
6461 "Could not release semaphore");
6474 * Desc: This function will swap two message data contents.
6475 * The original mBuf pointers are unchanged.
6490 Buffer *mBuf1, /* message 1 */
6491 Buffer *mBuf2 /* message 2 */
6494 S16 SSwapMsg(mBuf1, mBuf2)
6495 Buffer *mBuf1; /* message 1 */
6496 Buffer *mBuf2; /* message 2 */
6501 #if (ERRCLASS & ERRCLS_INT_PAR)
6509 #if (ERRCLASS & ERRCLS_INT_PAR)
6510 /* check message buffer 1 */
6513 SSLOGERROR(ERRCLS_INT_PAR, ESS237, ERRZERO, "SSwapMsg : Null Buffer");
6516 /* check message buffer 2 */
6519 SSLOGERROR(ERRCLS_INT_PAR, ESS238, ERRZERO, "SSwapMsg : Null Buffer");
6522 if (mBuf1->b_datap->db_type != SS_M_PROTO)
6524 SSLOGERROR(ERRCLS_INT_PAR, ESS239, ERRZERO, "SSwapMsg: Incorrect buffer\
6528 if (mBuf2->b_datap->db_type != SS_M_PROTO)
6530 SSLOGERROR(ERRCLS_INT_PAR, ESS240, ERRZERO, "SSwapMsg: Incorrect buffer\
6534 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
6535 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
6536 if (minfo1->region != minfo2->region)
6538 SSLOGERROR(ERRCLS_INT_PAR, ESS241, ERRZERO, "SSwapMsg: differnt regions\
6545 tmp = mBuf1->b_next;
6546 mBuf1->b_next = mBuf2->b_next;
6547 mBuf2->b_next = tmp;
6549 tmp = mBuf1->b_prev;
6550 mBuf1->b_prev = mBuf2->b_prev;
6551 mBuf2->b_prev = tmp;
6553 tmp = mBuf1->b_cont;
6554 mBuf1->b_cont = mBuf2->b_cont;
6555 mBuf2->b_cont = tmp;
6558 #ifdef SS_DBLK_FREE_RTN
6559 tmp = (Buffer *) mBuf1->b_datap->db_frtnp;
6560 mBuf1->b_datap->db_frtnp = mBuf2->b_datap->db_frtnp;
6561 mBuf2->b_datap->db_frtnp = (struct ssfree_rtn *) tmp;
6564 tmp2 = mBuf1->b_datap->db_ref;
6565 mBuf1->b_datap->db_ref = mBuf2->b_datap->db_ref;
6566 mBuf2->b_datap->db_ref = tmp2;
6571 SMemCpy((Void *) minfop, (Void *) (mBuf1->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6572 SMemCpy((Void *) (mBuf1->b_datap->db_base), (Void *) (mBuf2->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6573 SMemCpy((Void *) (mBuf2->b_datap->db_base), (Void *) minfop, (size_t)(sizeof(SsMsgInfo)));
6577 /* ss004.301 : Cavium changes */
6578 #ifdef SS_SEUM_CAVIUM
6584 * Desc: This function will converts the pointer to
6588 * RFAILED - failed, general (optional)
6590 * Notes: Function to convert the Pointer (Virtual address) to
6591 * Physical Address. This will take the Buffer type as
6592 * input and will convert all pointer associated with
6593 * that to Physical Address
6604 S16 SConvPtrPhy (mBuf)
6611 SsMsgInfo *minfoPtr;
6616 /* check mBuf for NULLP */
6617 if ( (mBuf == NULLP) || (*mBuf == NULLP ) )
6622 /* first block in Buffer is head */
6624 nextPtr = curPtr->b_cont;
6626 /* Get the physical address of the Pointer */
6629 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6634 curPtr->b_next = (Buffer*)cvmx_ptr_to_phys (curPtr->b_next);
6639 curPtr->b_prev = (Buffer*)cvmx_ptr_to_phys (curPtr->b_prev);
6642 /* Convert the pointers of Minfo to Physical addr */
6643 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6645 if (minfoPtr->endptr)
6647 minfoPtr->endptr = (Buffer*)cvmx_ptr_to_phys (minfoPtr->endptr);
6651 minfoPtr->next = (Buffer*)cvmx_ptr_to_phys (minfoPtr->next);
6654 curPtr->b_rptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_rptr);
6656 curPtr->b_wptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_wptr);
6658 /* Convert the pointers of Dblock to Physical addr */
6659 dblkPtr = (SsDblk*)curPtr->b_datap;
6662 #ifdef SS_DBLK_FREE_RTN
6663 frtnPtr = dblkPtr->db_frtnp;
6664 if( frtnPtr != NULLP)
6666 if (frtnPtr->free_func)
6668 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6670 if (frtnPtr->free_arg)
6672 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6675 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6679 dblkPtr->db_base = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_base);
6680 dblkPtr->db_lim = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6682 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6684 /* second block onwards is dblk */
6689 nextPtr = curPtr->b_cont;
6691 /* Get the physical address of the Pointer */
6694 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6697 curPtr->b_rptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_rptr);
6698 curPtr->b_wptr = (uint8_t*)cvmx_ptr_to_phys (curPtr->b_wptr);
6700 /* Convert the pointers of Dblock to Physical addr */
6701 dblkPtr = (SsDblk*)curPtr->b_datap;
6704 #ifdef SS_DBLK_FREE_RTN
6705 frtnPtr = dblkPtr->db_frtnp;
6706 if( frtnPtr != NULLP)
6708 if (frtnPtr->free_func)
6710 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6712 if (frtnPtr->free_arg)
6714 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6717 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6721 dblkPtr->db_base = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_base);
6722 dblkPtr->db_lim = (uint8_t*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6724 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6730 *mBuf = (Buffer*)cvmx_ptr_to_phys (*mBuf);
6740 * Desc: This function will converts the physical address
6743 * Ret: On Success - Pointer to converted buffer
6744 * On Failuer - Returns NULL
6746 * Notes: Function to Convert the Physical address to Pointer
6747 * (Virtual address) This will take work buffer as input
6748 * and will convert all address associated with that to
6760 S16 SConvPhyPtr (workPtr)
6767 SsMsgInfo *minfoPtr;
6772 /* check workPtr for NULLP */
6773 if ( (workPtr == NULLP) || (*workPtr == NULLP) )
6778 /* Convert the buffer address to pointer */
6779 mBuf = (Buffer*)cvmx_phys_to_ptr ((uint64_t)(*workPtr));
6783 /* first block is mblk */
6786 curPtr->b_next = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_next);
6791 curPtr->b_prev = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_prev);
6796 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_cont);
6799 curPtr->b_rptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_rptr);
6801 /* Get the pointer for minfo */
6802 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6804 if (minfoPtr->endptr)
6806 minfoPtr->endptr = (Buffer*)cvmx_phys_to_ptr ((uint64_t)minfoPtr->endptr);
6810 minfoPtr->next = (Buffer*)cvmx_phys_to_ptr ((uint64_t)minfoPtr->next);
6813 curPtr->b_wptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_wptr);
6815 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_datap);
6817 /* Get the Dblock pointers */
6818 dblkPtr = (SsDblk*)curPtr->b_datap;
6821 #ifdef SS_DBLK_FREE_RTN
6822 if (dblkPtr->db_frtnp)
6824 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_frtnp);
6825 frtnPtr = dblkPtr->db_frtnp;
6827 if (frtnPtr->free_func)
6829 frtnPtr->free_func = cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_func);
6831 if (frtnPtr->free_arg)
6833 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_arg);
6838 dblkPtr->db_base = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_base);
6839 dblkPtr->db_lim = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_lim);
6841 curPtr = curPtr->b_cont;
6843 /* after the first block is dblk */
6848 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_cont);
6851 curPtr->b_rptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_rptr);
6853 curPtr->b_wptr = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_wptr);
6855 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((uint64_t)curPtr->b_datap);
6857 /* Get the Dblock pointers */
6858 dblkPtr = (SsDblk*)curPtr->b_datap;
6861 #ifdef SS_DBLK_FREE_RTN
6862 if (dblkPtr->db_frtnp)
6864 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_frtnp);
6866 frtnPtr = dblkPtr->db_frtnp;
6868 if (frtnPtr->free_func)
6870 frtnPtr->free_func = cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_func);
6872 if (frtnPtr->free_arg)
6874 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((uint64_t)frtnPtr->free_arg);
6879 dblkPtr->db_base = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_base);
6880 dblkPtr->db_lim = (uint8_t*)cvmx_phys_to_ptr ((uint64_t)dblkPtr->db_lim);
6882 curPtr = curPtr->b_cont;
6885 /* Place the converted buffer */
6896 * Desc: This function will copy the message from FPA region
6899 * Ret: On Success - ROK
6900 * On Failuer - RFAILED
6902 * Notes: Function to copy the message from FPA region to
6903 * other region. This will internally allocates the
6904 * memory for the destination buffer and copies the
6905 * message in the same chain list
6919 S16 SCpyFpaMsg (srcBuf, dstRegion, dstPool, dstBuf)
6930 Buffer *curPtr = NULLP;
6932 Buffer *tmpblk = NULLP;
6933 Buffer *newblk = NULLP;
6934 Buffer *prevblk = NULLP;
6935 SsMsgInfo *minfoSrc = NULLP;
6936 SsMsgInfo *minfoDst = NULLP;
6937 SsDblk *dblkPtr = NULLP;
6938 SsDblk *dptr = NULLP;
6941 if ( srcBuf == (Buffer*)NULLP )
6946 if ((dstRegion >= SS_MAX_REGS) || (dstPool >= SS_MAX_POOLS_PER_REG))
6948 /* Free the source buffer and return failure */
6953 /* Allocate memory for destination buffer */
6954 if(SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
6956 /* Free the source buffer and return failure */
6961 /* get the minfo of dest and src buffers */
6962 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
6963 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
6965 curPtr = srcBuf->b_cont;
6967 /* Copy all the blocks associated with this Buffer */
6970 /* Allocate the memeory for dblock */
6972 dblkPtr = (SsDblk*)curPtr->b_datap;
6973 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
6974 size = numBytes + MDBSIZE;
6976 ret = SAlloc( dstRegion, &size, 0, (Data**)&tmpblk);
6980 /* Free all allocated buffers before returning */
6983 tmpblk = newblk->b_cont;
6984 (Void) SPutDBuf(dstRegion, dstPool, newblk);
6987 (Void) SPutMsg(*dstBuf);
6988 /* Free the source buffer and return failure */
6993 dat = (Data *)tmpblk + MDBSIZE;
6994 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
6997 /* Initialize the pointer and copy the data */
6998 INITB( tmpblk, dptr, dat, size, NULLP );
6999 #ifndef SS_DBUF_REFLOCK_DISABLE
7000 SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX);
7002 numBytes = curPtr->b_wptr - curPtr->b_rptr;
7003 /* Copy the data part if its present */
7006 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
7007 tmpblk->b_wptr += numBytes;
7016 prevblk->b_cont = tmpblk;
7020 curPtr = curPtr->b_cont;
7025 tmpblk->b_cont = NULLP;
7028 *minfoDst = *minfoSrc;
7029 minfoDst->region = 0;
7031 minfoDst->len = minfoSrc->len;
7032 minfoDst->endptr = tmpblk;
7033 minfoDst->next = NULLP;
7035 (*dstBuf)->b_cont = newblk;
7037 /* Free the source buffer after copying it */
7048 * Desc: This function will copy the message from any region
7051 * Ret: On Success - ROK
7052 * On Failuer - RFAILED
7054 * Notes: Function will copy the mbuf from msg to FPA.
7055 * This function allocates the memory internally
7056 * and copies the message to newly allocated mBuf.
7057 * The size of mBuf should be either of one
7058 * pre-difined sizes otherwise mBuf is dopped.
7070 S16 SCpyMsgFpa (srcBuf, dstBuf)
7076 Buffer *curPtr = NULLP;
7078 Buffer *tmpblk = NULLP;
7079 Buffer *prevblk = NULLP;
7080 Buffer *newblk = NULLP;
7081 SsMsgInfo *minfoSrc = NULLP;
7082 SsMsgInfo *minfoDst = NULLP;
7083 SsDblk *dblkPtr = NULLP;
7084 SsDblk *dptr = NULLP;
7089 if (srcBuf == (Buffer*)NULLP)
7094 *dstBuf = (Buffer*)cvmx_fpa_alloc(SS_CVMX_POOL_0);
7096 if ( *dstBuf == NULLP )
7098 /* Free the source buffer before returning */
7103 dat = (Data *)(*dstBuf) + MDBSIZE;
7104 dptr = (SsDblk*) ((Data *)(*dstBuf) + MBSIZE);
7105 numBytes = SS_CVMX_POOL_0_SIZE - MDBSIZE;
7107 /* Initialize the pointers of new block */
7108 INITB((*dstBuf), dptr, dat, numBytes, NULLP);
7110 (*dstBuf)->b_datap->db_type = SS_M_PROTO;
7111 (*dstBuf)->b_wptr = (*dstBuf)->b_rptr + sizeof(SsMsgInfo);
7113 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
7114 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
7115 curPtr = srcBuf->b_cont;
7119 dblkPtr = (SsDblk*)curPtr->b_datap;
7121 /* Get the size required which is to be allocated */
7122 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
7123 numBytes += MDBSIZE;
7125 /* get the pool depending on the size need to be allocated */
7128 case SS_CVMX_POOL_0_SIZE:
7130 pool = SS_CVMX_POOL_0;
7133 case SS_CVMX_POOL_1_SIZE:
7135 pool = SS_CVMX_POOL_1;
7138 case SS_CVMX_POOL_2_SIZE:
7140 pool = SS_CVMX_POOL_2;
7143 case SS_CVMX_POOL_3_SIZE:
7145 pool = SS_CVMX_POOL_3;
7149 /* size doesn't match, drop the mBuf and returning
7151 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SCpyMsgFpa: Invalid\
7152 buffer size, dropping the message");
7154 (*dstBuf)->b_cont = newblk;
7155 SPutFpaMsg(*dstBuf);
7156 /* Free the source buffer before returning */
7161 /* Allocate for mBuf and copy both the header and contents */
7162 tmpblk = (Buffer*)cvmx_fpa_alloc(pool);
7164 if ( tmpblk == NULLP )
7166 /* Return error if fails to allocate memory */
7168 (*dstBuf)->b_cont = newblk;
7169 SPutFpaMsg(*dstBuf);
7170 /* Free the source buffer before returning */
7175 dat = (Data *)tmpblk + MDBSIZE;
7176 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
7177 numBytes -= MDBSIZE;
7179 /* Initialize the pointers of new block */
7180 INITB( tmpblk, dptr, dat, numBytes, NULLP );
7182 numBytes = curPtr->b_wptr - curPtr->b_rptr;
7183 /* Copy the message contents */
7186 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
7187 tmpblk->b_wptr += numBytes;
7190 /* Add the mew mBuf to the Buffer chain */
7197 prevblk->b_cont = tmpblk;
7201 /* Get the next block */
7202 curPtr = curPtr->b_cont;
7205 /* Initialize the last mBuf */
7208 tmpblk->b_cont = NULLP;
7211 *minfoDst = *minfoSrc;
7212 minfoDst->region = 0;
7214 minfoDst->len = minfoSrc->len;
7215 minfoDst->endptr = tmpblk;
7216 minfoDst->next = NULLP;
7218 (*dstBuf)->b_cont = newblk;
7220 /* Free the source buffer after copying it */
7231 * Desc: This function will free the Buffer associated with
7234 * Ret: On Success - ROK
7235 * On Failuer - RFAILED
7237 * Notes: Function free the all buffer associated with wqBuf
7238 * This will get the pool id by the size of the buffer
7239 * and same will be used to free the buffer.
7250 S16 SPutFpaMsg(fpaBuf)
7260 if( fpaBuf == NULLP )
7265 curBlk = fpaBuf->b_cont;
7269 nextBlk = curBlk->b_cont;
7271 dblkPtr = (SsDblk*)curBlk->b_datap;
7273 size = dblkPtr->db_lim - dblkPtr->db_base + MDBSIZE;
7275 /* Free the dblock according to its size */
7278 case SS_CVMX_POOL_0_SIZE:
7279 cvmx_fpa_free(curBlk, SS_CVMX_POOL_0, 0);
7282 case SS_CVMX_POOL_1_SIZE:
7283 cvmx_fpa_free(curBlk, SS_CVMX_POOL_1, 0);
7286 case SS_CVMX_POOL_2_SIZE:
7287 cvmx_fpa_free(curBlk, SS_CVMX_POOL_2, 0);
7290 case SS_CVMX_POOL_3_SIZE:
7291 cvmx_fpa_free(curBlk, SS_CVMX_POOL_3, 0);
7295 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SPutFpaMsg: Invalid\
7296 buffer size, dropping the message");
7303 cvmx_fpa_free(fpaBuf, SS_CVMX_POOL_0, 0);
7309 #endif /* SS_SEUM_CAVIUM */
7311 /* ss006.301 : new buffer management APIs, start */
7316 * Desc: This function is used to copy a portion of message(srcBuf) into
7317 * another msg(dstBuf)
7320 * RFAILED - failed, general (optional)
7321 * ROUTRES - failed, out of resources (optional) - In this case
7322 * caller shall reclaim the resources allocated for dstBuf.
7339 S16 SCpyPartMsg(srcBuf, idx, cnt, dstBuf)
7356 #if (ERRCLASS & ERRCLS_INT_PAR)
7359 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null src Buffer");
7362 if (srcBuf->b_datap->db_type != SS_M_PROTO)
7364 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7370 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null dst Buffer");
7373 if (dstBuf->b_datap->db_type != SS_M_PROTO)
7375 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7379 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
7381 /* if index > length of mBuf, return */
7382 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
7383 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
7385 if (idx >= sMinfo->len)
7387 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7392 sBuf = srcBuf->b_cont;
7393 FIND_OFFSET(sBuf, idx)
7397 dBuf = (dMinfo->endptr) ? (dMinfo->endptr) : (dstBuf->b_cont);
7401 crnt = dPrev->b_cont;
7405 crnt = crnt->b_cont;
7412 sCnt = sBuf->b_wptr - (sBuf->b_rptr + idx);
7415 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
7419 /* allocate a data buffer */
7420 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
7422 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyPartMsg : SGetDBuf\
7426 dCnt = MIN(cnt, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
7427 dPrev->b_cont = dBuf;
7430 if(sCnt > cnt) /* src Dblk has enough data to copy */
7434 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7436 dBuf->b_wptr += dCnt;
7437 dBuf = dBuf->b_cont;
7443 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), cnt);
7444 dBuf->b_wptr += cnt;
7445 dBuf->b_cont = NULLP;
7451 else /* src dBlk has partial data to be copied */
7455 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7456 dBuf->b_wptr += dCnt;
7457 dBuf = dBuf->b_cont;
7464 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), sCnt);
7465 dBuf->b_wptr += sCnt;
7467 sBuf = sBuf->b_cont;
7473 /* update the msgLen in dstBuf */
7474 dMinfo->len += numCpd;
7475 dMinfo->endptr = dBuf;
7484 * Desc: This function is used to replace a portion of message(mBuf) with the
7488 * RFAILED - failed, general (optional)
7505 S16 SRepPartMsg(srcBuf, idx, cnt, dstBuf)
7522 #if (ERRCLASS & ERRCLS_INT_PAR)
7525 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null dstBuf");
7528 if (dstBuf->b_datap->db_type != SS_M_PROTO)
7530 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7531 dstBuf buffer type");
7536 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null Src Buffer ");
7539 if (srcBuf->b_datap->db_type != SS_M_PROTO)
7541 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7545 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
7547 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
7548 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
7550 if(((idx + cnt) > dMinfo->len) || (cnt < sMinfo->len))
7552 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7557 dBuf = dstBuf->b_cont;
7558 FIND_OFFSET(dBuf, idx)
7559 sBuf = srcBuf->b_cont;
7561 while(cnt && dBuf && sBuf)
7563 dCnt = (dBuf->b_wptr - (dBuf->b_rptr + idx));
7564 sCnt = sBuf->b_wptr - (sBuf->b_rptr + sIdx);
7565 cpBytes = MIN(cnt, sCnt);
7566 cpBytes = MIN(cpBytes, dCnt);
7567 SMemCpy((void*)(dBuf->b_rptr + idx), (void*)(sBuf->b_rptr + sIdx), cpBytes);
7573 /* move to next DBlk in srcBuf */
7574 sBuf = sBuf->b_cont;
7578 else /* cpBytes equals dCnt */
7580 /* move to the next DBlk in dstBuf */
7581 dBuf = dBuf->b_cont;
7595 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : unable to replace\
7607 * Desc: This function will move a portion of the first msg to second msg
7610 * ROKDNA - ok, data not available
7611 * RFAILED - failed, general (optional)
7612 * ROUTRES - failed, out of resources (optional)
7614 * Notes: message 1 is the message from which the segment will be copied
7616 * message 2 is the updated message.
7618 * index is 0 based and indicates location in message 1
7619 * up to which the data will be copied to message 2
7621 * if index is equal to 0, message 1 will not be changed and no data
7622 shall be copied to message 2.
7623 * message 1 is not returned to memory. return is ok.
7625 * if index is not equal to 0 and less than the length of
7626 * the message minus 1: data upto index, shall be copied to message 2
7627 * and read/write pointers of message 1 will be updated accordingly
7629 * if index is not equal to 0 and greater than or equal to
7630 * the length of the message minus 1: all of the message 1 data.
7631 * shall be copied to message 2. return is ok.
7641 Buffer *srcBuf, /* message 1 */
7642 MsgLen idx, /* index */
7643 Buffer *dstBuf /* message 2 */
7646 S16 SMovPartMsg(srcBuf, idx, dstBuf)
7647 Buffer *srcBuf; /* message 1 */
7648 MsgLen idx; /* index */
7649 Buffer *dstBuf; /* message 2 */
7659 #ifdef T2K_MEM_LEAK_DBG
7660 char* file = __FILE__;
7661 uint32_t line = __LINE__;
7665 #if (ERRCLASS & ERRCLS_INT_PAR)
7666 /* check message buffer 1 */
7667 if ((!srcBuf) || (!dstBuf ))
7669 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SMovPartMsg : Null Buffer (src or Dst)");
7674 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SMovPartMsg : Invalid index");
7677 if ((srcBuf->b_datap->db_type != SS_M_PROTO) || (dstBuf->b_datap->db_type != SS_M_PROTO))
7679 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SMovPartMsg : Incorrect buffer\
7685 /* get the SsMsgInfo of srcBuf */
7686 sMinfo = (SsMsgInfo*) srcBuf->b_rptr;
7688 /* get the SsMsgInfo of dstBuf */
7689 dMinfo = (SsMsgInfo*) dstBuf->b_rptr;
7691 /* if index > length of mBuf, return */
7693 if (idx > sMinfo->len)
7698 /* one block might not sufficient - Check for generic implementation */
7699 sBuf = srcBuf->b_cont;
7700 /* dBuf = dMinfo->endptr; */
7701 dPrev = (dBuf = dMinfo->endptr) ? dBuf : dstBuf;
7703 /* adjust the lengths of srcBuf, dstBuf */
7709 sCnt = sBuf->b_wptr - sBuf->b_rptr;
7712 /* allocate a data buffer */
7713 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
7715 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyMsgPartMsg : SGetDBuf\
7719 dCnt = MIN(idx, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
7720 dPrev->b_cont = dBuf;
7725 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
7727 if(sCnt > idx) /* src Dblk has enough data to copy */
7731 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7732 dBuf->b_wptr += dCnt;
7733 dBuf = dBuf->b_cont;
7735 sBuf->b_rptr += dCnt;
7739 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), idx);
7740 dBuf->b_wptr += idx;
7741 dBuf->b_cont = NULLP;
7742 sBuf->b_rptr += idx;
7747 else /* src dBlk has partial data to be copied */
7751 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7752 dBuf->b_wptr += dCnt;
7753 dBuf = dBuf->b_cont;
7755 sBuf->b_rptr += dCnt;
7760 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), sCnt);
7761 dBuf->b_wptr += sCnt;
7763 /* deallocate the sBuf here */
7765 /* printf("SMovPartMsg() sBuf is completely copied sBuf->b_cont(%p)\n", sBuf->b_cont); */
7766 (Void)SPutDBuf(sMinfo->region, sMinfo->pool, sBuf);
7767 srcBuf->b_cont = sBuf = tmp;
7771 dMinfo->endptr = dBuf;
7776 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SMovPartMsg : unable to copy\
7788 * Desc: This function copies consecutive bytes of data to the
7789 * beginning of a message.
7792 * RFAILED - failed, general (optional)
7793 * ROUTRES - failed, out of resources (optional)
7795 * Notes: if message is empty: data is placed in the message. message
7796 * length is incremented. return is ok.
7798 * if message is not empty: data is read by source pointer,
7799 * data is placed in front of all other data in message.
7800 * message length is incremented. return is ok.
7802 * the first byte of data pointed to by the source pointer
7803 * will be placed at the front of the message first (i.e. it
7804 * will become the first byte of the message) and the last
7805 * byte will be placed in front of the existing msg contents,
7806 * i.e. order of the source is preserved.
7820 S16 SPkMsgMult(src, cnt, mBuf)
7826 SsMsgInfo *minfo; /* Message info */
7829 MsgLen numBytes; /* no. of bytes to be copied */
7833 #if (ERRCLASS & ERRCLS_INT_PAR)
7834 /* check message buffer */
7837 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SPkMsgMult:Null Buffer");
7843 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SPkMsgMult:Null Buffer");
7849 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SPkMsgMult: Invalid\
7853 if (mBuf->b_datap->db_type != SS_M_PROTO)
7855 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SPkMsgMult: Incorrect\
7861 /* get the SsMsgInfo of mBuf */
7862 minfo = (SsMsgInfo*) mBuf->b_rptr;
7864 /* ss014.13: Addition */
7867 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
7868 (tmp->b_datap->db_base < tmp->b_rptr))
7870 /* store the offset of the read pointer of tmp */
7871 offset = tmp->b_rptr - tmp->b_datap->db_base;
7873 /* determine the number of bytes to copy */
7874 numBytes = MIN(cnt, offset);
7879 /* update the read ptr */
7880 tmp->b_rptr -= numBytes;
7882 memcpy(tmp->b_rptr, (src + cnt), numBytes);
7883 minfo->len += numBytes;
7890 /* allocate a DBlk minimum of size Cnt to pack the data */
7892 if (ssGetDBufOfSize(minfo->region, cnt, &newblk) != ROK)
7896 newblk->b_datap->db_type = SS_M_DATA;
7897 newblk->b_rptr = newblk->b_datap->db_lim - cnt;
7898 newblk->b_wptr = newblk->b_datap->db_lim;
7899 memcpy(newblk->b_rptr, src, cnt);
7900 /* attach the newblk chain into mBuf */
7901 newblk->b_cont = tmp;
7902 mBuf->b_cont = newblk;
7904 minfo->endptr = newblk;
7908 /* ss006.301 : new buffer management APIs, end */
7913 * Desc: This function retunrs the pointer to the read the message from mBuf
7916 * RFAILED - failed, general (optional)
7931 S16 SGetReadPtr (mBuf, data, len)
7939 if (mBuf && mBuf->b_cont)
7941 *data = mBuf->b_cont->b_rptr;
7942 *len = ((SsMsgInfo*)(mBuf->b_rptr))->len;
7952 #ifdef SS_USE_ZBC_MEMORY
7955 * Fun: SAttachPtrToBuf
7957 * Desc: This function attaches the Pointer provided into a new
7958 * message buffer after allocating the same. It allocates
7959 * header (M-Block) and an additional dBuf (D-Block) and attaches
7960 * the provided pointer to it.
7963 * RFAILED - failed, general (optional)
7964 * ROUTRES - failed, out of resources (optional)
7972 #ifdef T2K_MEM_LEAK_DBG
7973 S16 SAttachPtrToBufNew
7994 S16 SAttachPtrToBuf(region, pool, ptr, totalLen, mBuf)
8003 SsMsgInfo *minfo; /* Message info */
8007 /* Void *iccHdlr; */
8010 #if (ERRCLASS & ERRCLS_INT_PAR)
8013 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8018 #ifdef XEON_SPECIFIC_CHANGES
8021 if(SGetMsg(region, pool, mBuf) != ROK)
8023 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8029 #ifdef SS_HISTOGRAM_SUPPORT
8030 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
8032 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8033 #endif /* SS_HISTOGRAM_SUPPORT */
8035 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8040 (*mBuf)->b_cont = newblk;
8042 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8044 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8047 newblk->b_datap->db_base = ptr;
8048 newblk->b_datap->db_lim = ptr + totalLen;
8049 newblk->b_rptr = newblk->b_datap->db_base;
8050 newblk->b_wptr = newblk->b_rptr + totalLen;
8052 #ifndef SS_DBUF_REFLOCK_DISABLE
8053 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8055 printf("Falied to destroy lock\n");
8059 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8061 /* get the SsMsgInfo of mBuf */
8062 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8063 minfo->len = totalLen;
8064 minfo->endptr = newblk;
8073 * Desc: This function deallocates a buffer back to the
8074 * dynamic memory pool which is allocated for ZBC
8077 * RFAILED - failed, general (optional)
8085 #ifdef T2K_MEM_LEAK_DBG
8086 static S16 SPutZbcDBufNew
8095 static S16 SPutZbcDBuf
8101 static S16 SPutZbcDBuf(region, buf)
8107 register SsDblk *dptr;
8112 dptr = buf->b_datap;
8113 /* Get the length of the buffer */
8114 bufLen = buf->b_datap->db_lim - buf->b_datap->db_base;
8116 /* If the buffer is not shared, free the buffer */
8119 #ifndef SS_DBUF_REFLOCK_DISABLE
8120 SDestroyLock(&dptr->dBufLock);
8123 /* Free the ZBC buffer first and then free the block allocated for the
8126 #ifdef SS_HISTOGRAM_SUPPORT
8127 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
8128 (uint8_t*) __FILE__, ENTNC);
8130 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
8131 #endif /* SS_HISTOGRAM_SUPPORT */
8133 /* if the data block is not shared, free the buffer, checks not reqd */
8134 #ifdef SS_HISTOGRAM_SUPPORT
8135 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__,
8138 ret = SFree(region, (Data *) buf, MDBSIZE);
8139 #endif /* SS_HISTOGRAM_SUPPORT */
8141 /* If the buffer is shared, reduce the refernce count and free the buffer
8142 * if reference count falls to zero */
8145 #ifndef SS_DBUF_REFLOCK_DISABLE
8146 if((ret=SLock(&dptr->dBufLock)))
8148 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
8149 "Could not lock the mBuf Ref Lock");
8154 /* if buffer's message blk is obtained during dupb */
8155 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
8157 #ifdef SS_HISTOGRAM_SUPPORT
8158 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__, ENTNC);
8160 ret = SFree(region, (Data *) buf, MDBSIZE);
8161 #endif /* SS_HISTOGRAM_SUPPORT */
8162 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
8164 /* if reference count falls to zero */
8167 #ifndef SS_DBUF_REFLOCK_DISABLE
8168 ret = SUnlock(&dptr->dBufLock) ;
8169 if((SDestroyLock(&dptr->dBufLock)) != 0)
8171 printf("Falied to destroy lock\n");
8174 #ifdef SS_HISTOGRAM_SUPPORT
8175 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
8176 (uint8_t*) __FILE__, ENTNC);
8178 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
8179 #endif /* SS_HISTOGRAM_SUPPORT */
8181 #ifdef SS_HISTOGRAM_SUPPORT
8182 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (uint8_t*) __FILE__,
8185 ret = SFree(region, (Data *) buf, MDBSIZE);
8186 #endif /* SS_HISTOGRAM_SUPPORT */
8189 #ifndef SS_DBUF_REFLOCK_DISABLE
8190 ret = SUnlock(&(dptr->dBufLock));
8196 #endif /* SS_USE_ZBC_MEMORY */
8202 * Fun: SAttachPtrToMBuf
8204 * Desc: This function attaches the Pointer provided into a new
8205 * message buffer after allocating the same. It allocates
8206 * header (M-Block) and an additional dBuf (D-Block) and attaches
8207 * the provided pointer to it.
8210 * RFAILED - failed, general (optional)
8211 * ROUTRES - failed, out of resources (optional)
8218 #ifdef T2K_MEM_LEAK_DBG
8219 S16 SAttachPtrToMBuf1
8232 S16 SAttachPtrToMBuf
8242 S16 SAttachPtrToMBuf(region, pool, ptr, totalLen, ptrLen, mBuf)
8252 SsMsgInfo *minfo; /* Message info */
8256 /* Void *iccHdlr; */
8259 #if (ERRCLASS & ERRCLS_INT_PAR)
8262 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8267 if(SGetMsg(region, pool, mBuf) != ROK)
8269 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8276 #ifdef SS_HISTOGRAM_SUPPORT
8277 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
8279 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8280 #endif /* SS_HISTOGRAM_SUPPORT */
8282 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8287 (*mBuf)->b_cont = newblk;
8289 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8291 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8294 newblk->b_datap->db_base = ptr;
8295 newblk->b_datap->db_lim = ptr + ptrLen;
8296 newblk->b_rptr = newblk->b_datap->db_base;
8297 newblk->b_wptr = newblk->b_rptr + totalLen;
8299 #ifndef SS_DBUF_REFLOCK_DISABLE
8300 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8302 printf("Falied to destroy lock\n");
8306 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8308 /* get the SsMsgInfo of mBuf */
8309 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8310 minfo->len = totalLen;
8311 minfo->endptr = newblk;
8313 //printf("Mbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
8316 #endif /* INTEL_WLS */
8317 S16 SIncMsgRef(Buffer *srcBuf,Region dstRegion, Pool dstPool,Buffer **dstBuf)
8320 return (SAddMsgRef(srcBuf,dstRegion, dstPool,dstBuf));
8327 Void SResetMBuf(Buffer *mbuf)
8333 minfo = (SsMsgInfo *) mbuf->b_rptr;
8334 //tmp = minfo->endptr;
8341 // printf("SResetMBuf 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 );
8342 // tmp->b_wptr = tmp->b_rptr = tmp->b_datap->db_base;
8343 tmp->b_wptr = tmp->b_rptr = (tmp->b_datap->db_base + 5);
8344 tmp->b_datap->db_ref = 1;
8345 tmp->b_datap->shared = 0;
8357 * Fun: SAttachWlsPtrToMBuf
8359 * Desc: This function attaches the Pointer provided into a new
8360 * message buffer after allocating the same. It allocates
8361 * header (M-Block) and an additional dBuf (D-Block) and attaches
8362 * the provided pointer to it.
8365 * RFAILED - failed, general (optional)
8366 * ROUTRES - failed, out of resources (optional)
8373 #ifdef T2K_MEM_LEAK_DBG
8374 S16 SAttachWlsPtrToMBuf1
8388 S16 SAttachWlsPtrToMBuf
8399 S16 SAttachWlsPtrToMBuf(region, pool, ptr, readPtr, totalLen, ptrLen, mBuf)
8410 SsMsgInfo *minfo; /* Message info */
8414 /* Void *iccHdlr; */
8417 #if (ERRCLASS & ERRCLS_INT_PAR)
8420 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8426 if(SGetMsg(region, pool, mBuf) != ROK)
8428 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8434 #ifdef SS_HISTOGRAM_SUPPORT
8435 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (uint8_t*) __FILE__, ENTNC) != ROK)
8437 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8438 #endif /* SS_HISTOGRAM_SUPPORT */
8440 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8445 (*mBuf)->b_cont = newblk;
8447 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8449 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8452 newblk->b_datap->db_base = ptr;
8453 newblk->b_datap->db_lim = ptr + ptrLen;
8454 newblk->b_rptr = readPtr;
8455 newblk->b_wptr = newblk->b_rptr + totalLen;
8457 #ifndef SS_DBUF_REFLOCK_DISABLE
8458 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8460 printf("Falied to destroy lock\n");
8464 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8466 /* get the SsMsgInfo of mBuf */
8467 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8468 minfo->len = totalLen;
8469 minfo->endptr = newblk;
8471 //printf("Mbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
8475 #ifdef TENB_DPDK_BUF
8481 Data **ptr, /* pointer to buffer */
8482 Size size /* size requested */
8487 *ptr = ntl_alloc(mtGetNtlHdl(), size);
8494 Data *ptr /* pointer to buffer */
8500 ntl_free(mtGetNtlHdl(), ptr);
8505 S16 SDetachDpdkPtrFrmDBuf
8515 //msgBlk = mBuf->b_cont;
8516 //*ptr = msgBlk->b_rptr;
8517 *ptr = mBuf->b_datap->db_base;
8519 mBuf->b_cont = NULL;
8521 //minfo = (SsMsgInfo*) mBuf->b_rptr;
8529 S16 SDetachDpdkPtrFrmMBuf
8538 register SsDblk *dptr;
8542 msgBlk = mBuf->b_cont;
8549 dptr = msgBlk->b_datap;
8550 if(dptr->db_type != SS_MEM_TYPE_DPDK_ZBC)
8556 *ptr = msgBlk->b_rptr;
8558 mBuf->b_cont = NULL;
8560 minfo = (SsMsgInfo*) mBuf->b_rptr;
8568 S16 SAttachDpdkPtrToMBuf
8579 S16 SAttachDpdkPtrToMBuf(region, pool, ptr, readPtr, msgLen, totalLen, mBuf)
8595 SAttachWlsPtrToMBuf(region, pool, ptr, readPtr, msgLen, totalLen, mBuf);
8596 dptr = (SsDblk*) (((Data *) ((*mBuf)->b_cont)) + MBSIZE);
8598 dptr->db_type = SS_MEM_TYPE_DPDK_ZBC;
8603 #endif /* TENB_DPDK_BUF */
8605 #endif /* INTEL_WLS */
8607 /**********************************************************************
8609 **********************************************************************/