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
95 extern 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 PUBLIC S16 ssGetDBufOfSize ARGS((Region region, Size size, Buffer **dBuf));
108 PUBLIC S16 SIncMsgRef(Buffer *srcBuf,Region dstRegion, Pool dstPool,Buffer **dstBuf);
109 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
110 EXTERN PUBLIC U32 GetNextFreeIdx ARGS((StaticMemAllocInfo * memAllocInfo));
111 EXTERN PUBLIC void LogForStaticMemLeak ARGS((StaticMemAllocInfo* memAllocInfo, char*
112 file, U32 line, U32 size, void* ptr, U32 idx));
113 EXTERN PUBLIC void FreeIdx ARGS((U8* ptr, U32 idx, StaticMemAllocInfo*
114 memAllocInfo,U32 size, char* file, U32 line));
117 #ifdef SS_USE_ZBC_MEMORY
118 #ifdef T2K_MEM_LEAK_DBG
119 PRIVATE S16 SPutZbcDBufNew ARGS((Region region, Buffer *buf,char*,U32));
122 PRIVATE S16 SPutZbcDBuf ARGS((Region region, Buffer *buf));
123 PUBLIC 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 PRIVATE Buffer *DupMsgNew ARGS((Region region, Buffer *buffer,char*,U32));
135 #ifdef T2K_MEM_LEAK_DBG
136 PUBLIC S16 SAttachPtrToMBuf1 ARGS(( Region region, Pool pool, Data *ptr, MsgLen totalLen,
137 MsgLen ptrLen, Buffer** mBuf, char* file, U32 line));
139 PUBLIC S16 SAttachPtrToMBuf ARGS(( Region region, Pool pool, Data *ptr, MsgLen totalLen,
140 MsgLen ptrLen, Buffer** mBuf));
142 #ifdef T2K_MEM_LEAK_DBG
143 PUBLIC S16 SAttachWlsPtrToMBuf1 ARGS(( Region region, Pool pool, Data *ptr,
144 Data *readPtr, MsgLen totalLen,
145 MsgLen ptrLen, Buffer** mBuf, char* file, U32 line));
147 PUBLIC S16 SAttachWlsPtrToMBuf ARGS(( Region region, Pool pool, Data *ptr,
148 Data *readPtr, MsgLen totalLen,
149 MsgLen ptrLen, Buffer** mBuf));
152 PUBLIC S16 SDetachDpdkPtrFrmMBuf ARGS((Buffer *mBuf, Data **ptr));
153 PUBLIC S16 SDetachDpdkPtrFrmDBuf ARGS((Buffer *mBuf, Data **ptr));
154 PUBLIC S16 SPutSBufDpdk ARGS(( Data *ptr));
155 #endif /* TENB_DPDK_BUF */
158 #endif /* INTEL_WLS */
160 PRIVATE 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 EXTERN 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))
233 extern S32 clusterMode;
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 PUBLIC S16 ssGetDBufOfSizeNew
264 PUBLIC S16 ssGetDBufOfSize
271 PUBLIC S16 ssGetDBufOfSize(region, size, dBuf)
282 TRC1(ssGetDBufOfSize)
284 #if (ERRCLASS & ERRCLS_INT_PAR)
285 /* check buffer pointer */
288 SSLOGERROR(ERRCLS_INT_PAR, ESS047, ERRZERO, "ssGetDBufOfSize : Null\
292 if (region >= SS_MAX_REGS)
294 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "ssGetDBufOfSize : Invalid\
301 SSLOGERROR(ERRCLS_INT_PAR, ESS049, ERRZERO, "ssGetDBufOfSize : Invalid\
307 /* ss006.301 : optmized this function */
308 mdsize = MDBSIZE + size;
309 #ifdef SS_HISTOGRAM_SUPPORT
310 if (SAlloc(region, &mdsize, 0, (Data **) dBuf, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
312 if (SAlloc(region, &mdsize, 0, (Data **) dBuf) != ROK)
313 #endif /* SS_HISTOGRAM_SUPPORT */
317 data = (Data *) (*dBuf) + MDBSIZE;
318 size = mdsize - MDBSIZE;
320 dptr = (SsDblk*) (((Data *) (*dBuf)) + MBSIZE);
322 INITB((*dBuf), dptr, data, size, NULLP)
323 #ifndef SS_DBUF_REFLOCK_DISABLE
324 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
326 SSLOGERROR(ERRCLS_DEBUG, ESS056, ERRZERO,"Falied to initalize lock");
331 } /* ssGetDBufOfSize */
338 * Desc: This function gets a message
341 * RFAILED - failed, general (optional)
342 * ROUTRES - failed, out of resources (optional)
344 * Notes: message is created. message is set to type SS_M_PROTO.
345 * message is returned via message buffer pointer.
351 /* ss001.301: additions */
352 #ifdef SS_HISTOGRAM_SUPPORT
354 PUBLIC S16 SGetMsgNew
356 Region region, /* region id */
357 Pool pool, /* pool id */
358 Buffer **mBuf, /* pointer to message buffer */
363 PUBLIC S16 SGetMsgNew(region, pool, mBuf, line, fileName)
364 Region region; /* region id */
365 Pool pool; /* pool id */
366 Buffer **mBuf; /* pointer to message buffer */
370 #else /* SS_HISTOGRAM_SUPPORT */
371 #ifdef T2K_MEM_LEAK_DBG
372 PUBLIC S16 SGetMsgNew
374 Region region, /* region id */
375 Pool pool, /* pool id */
376 Buffer **mBuf, /* pointer to message buffer */
384 Region region, /* region id */
385 Pool pool, /* pool id */
386 Buffer **mBuf /* pointer to message buffer */
389 PUBLIC S16 SGetMsg(region, pool, mBuf)
390 Region region; /* region id */
391 Pool pool; /* pool id */
392 Buffer **mBuf; /* pointer to message buffer */
395 #endif /* SS_HISTOGRAM_SUPPORT */
401 /* ss001.301: additions */
402 #ifdef SS_HISTOGRAM_SUPPORT
404 #endif /* SS_HISTOGRAM_SUPPORT */
406 /* ss021.103 - Addition of return value */
408 #if (ERRCLASS & ERRCLS_INT_PAR)
416 #ifdef XEON_SPECIFIC_CHANGES
421 #if (ERRCLASS & ERRCLS_INT_PAR)
422 /* check buffer pointer */
425 SSLOGERROR(ERRCLS_INT_PAR, ESS050, ERRZERO, "SGetMsg : Null Buffer");
428 if (region >= SS_MAX_REGS)
430 SSLOGERROR(ERRCLS_INT_PAR, ESS051, ERRZERO, "SGetMsg : Invalid region\
435 if (pool >= SS_MAX_POOLS_PER_REG)
437 SSLOGERROR(ERRCLS_INT_PAR, ESS052, ERRZERO, "SGetMsg : Invalid pool id");
441 /* ss037.103 Removed the semaphore operation for performance enhancement */
444 /* ss021.103 - Addition to check if region is registered */
445 /* acquire one semaphore, to protect against deregistration */
446 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
450 #if (ERRCLASS & ERRCLS_DEBUG)
451 SSLOGERROR(ERRCLS_DEBUG, ESS053, (ErrVal) ret,
452 "Could not lock region table");
459 #if (ERRCLASS & ERRCLS_INT_PAR)
460 /* verify that this region is present */
461 if (osCp.regionTbl[region].used == FALSE)
463 /* ss037.103 Removed the semaphore operation for performance enhancement */
466 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
468 #if (ERRCLASS & ERRCLS_DEBUG)
469 SSLOGERROR(ERRCLS_DEBUG, ESS054, ERRZERO,
470 "Could not release semaphore");
475 SSLOGERROR(ERRCLS_INT_PAR, ESS055, region, "Region not registered");
478 /* ss037.103 Removed the semaphore operation for performance enhancement */
481 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
483 #if (ERRCLASS & ERRCLS_DEBUG)
484 SSLOGERROR(ERRCLS_DEBUG, ESS056, ERRZERO,
485 "Could not release semaphore");
492 /* ss001.301: additions */
493 #ifdef SS_HISTOGRAM_SUPPORT
494 SGetEntInd(&entId, fileName);
495 #endif /* SS_HISTOGRAM_SUPPORT */
497 /* ss012.13: Addition */
498 #ifdef SS_M_PROTO_REGION
499 /* ss001.301: additions */
500 #ifdef SS_HISTOGRAM_SUPPORT
501 if (SAlloc(region, &size, 0, (Data**) mBuf, line, fileName, entId) != ROK)
503 if (SAlloc(region, &size, 0, (Data**) mBuf) != ROK)
504 #endif /* SS_HISTOGRAM_SUPPORT */
506 SSLOGERROR(ERRCLS_DEBUG, ESS058, ERRZERO, "SGetMsg:Failed in SAlloc");
509 #else /* SS_M_PROTO_REGION */
510 /* ss001.301: additions */
511 #ifdef SS_HISTOGRAM_SUPPORT
512 if (SAlloc(SS_DFLT_REGION, &size, 0, (Data**) mBuf, line, fileName, entId) != ROK)
514 if (SAlloc(region, &size, 0, (Data**) mBuf) != ROK)
515 #endif /* SS_HISTOGRAM_SUPPORT */
517 SSLOGERROR(ERRCLS_DEBUG, ESS059, ERRZERO, "SGetMsg:Failed in SAlloc");
520 #endif /* SS_M_PROTO_REGION */
522 dptr = (SsDblk*) (((Data *) (*mBuf)) + MBSIZE);
523 data = (Data*) (((Data *) (*mBuf)) + MDBSIZE);
525 /* INITB initialises and sets up the message blk */
526 INITB((*mBuf), dptr, data, sizeof(SsMsgInfo), NULLP)
528 (*mBuf)->b_datap->db_type = SS_M_PROTO;
529 (*mBuf)->b_wptr = (*mBuf)->b_rptr + sizeof(SsMsgInfo);
531 /* initialise message info of mBuf */
532 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
534 minfo->region = region;
537 minfo->endptr = NULLP;
538 minfo->eventInfo.event = SS_EVNT_DATA;
539 /* ss021.103 - Addition to initialize next and route */
543 if(clusterMode == RADIO_CLUSTER_MODE)
552 #ifdef RGL_SPECIFIC_CHANGES
553 S16 SSetMBufPool(Buffer *mBuf, Pool pool)
558 minfo = (SsMsgInfo*) mBuf->b_rptr;
565 /* #ifdef SS_LOCKLESS_MEMORY */
571 * Desc: This function deallocates a message back.
574 * RFAILED - failed, general (optional)
576 * Notes: all data attached to message is returned to memory.
577 * message is returned to memory. return is ok.
582 /* ss001.301: additions */
583 #ifdef SS_HISTOGRAM_SUPPORT
585 PUBLIC S16 SPutMsgNew
592 PUBLIC S16 SPutMsgNew(mBuf, line, fileName)
597 #else /* SS_HISTOGRAM_SUPPORT */
598 #ifdef T2K_MEM_LEAK_DBG
599 PUBLIC S16 SPutMsgNew
612 PUBLIC S16 SPutMsg(mBuf)
616 #endif /* SS_HISTOGRAM_SUPPORT */
620 #ifdef SS_MEM_WL_DEBUG
624 /* ss001.301: additions */
625 #ifdef SS_HISTOGRAM_SUPPORT
627 #endif /* SS_HISTOGRAM_SUPPORT */
632 //#ifdef RADIO_CLUSTER
633 if(clusterMode == RADIO_CLUSTER_MODE)
639 if (mBuf->refCnt > 0)
645 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
647 extern pthread_t gMacTId,gRlcTId;
648 extern S32 clusterMode;
649 if(clusterMode == RADIO_CLUSTER_MODE)
652 #ifdef MAC_FREE_RING_BUF
653 if(pthread_self() == gMacTId)
654 //if(pthread_equal(pthread_self(),gMacTId))
658 if(ROK == mtAddBufToRing(SS_RNG_BUF_MAC_FREE_RING,(Void *)mBuf,0))
665 #ifdef RLC_FREE_RING_BUF
666 else if(pthread_self() == gRlcTId)
670 if(ROK == mtAddBufToRing(SS_RNG_BUF_RLC_FREE_RING,(Void *)mBuf,0))
681 #if (ERRCLASS & ERRCLS_INT_PAR)
684 SSLOGERROR(ERRCLS_INT_PAR, ESS060, ERRZERO, "SPutMsg: Null Buffer");
687 if (mBuf->b_datap->db_type != SS_M_PROTO)
689 SSLOGERROR(ERRCLS_INT_PAR, ESS061, ERRZERO, "SPutMsg: Incorrect buffer\
695 #ifdef SS_MEM_WL_DEBUG
696 CM_MEM_GET_REGION(tmpThrReg)
697 if(tmpThrReg == 0xFF)
699 printf("\n Not able to get region \n");
704 /* get the message info */
705 minfo = (SsMsgInfo *) mBuf->b_rptr;
707 while ((tmp = mBuf->b_cont))
709 /* set b_cont of mBuf to point to the b_cont of tmp */
710 mBuf->b_cont = tmp->b_cont;
711 #ifdef SS_MEM_WL_DEBUG
712 (Void) SPutDBuf(tmpThrReg, minfo->pool, tmp);
714 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
718 /* ss001.301: additions */
719 #ifdef SS_HISTOGRAM_SUPPORT
720 SGetEntInd(&entId, fileName);
721 #endif /* SS_HISTOGRAM_SUPPORT */
723 /* ss012.13: Addition */
724 #ifdef SS_M_PROTO_REGION
725 /* ss021.103 - Addition to check return value of SFree */
726 #ifdef SS_HISTOGRAM_SUPPORT
727 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE, line, fileName, entId) == RFAILED)
729 #ifdef SS_MEM_WL_DEBUG
730 if (SFree(tmpThrReg, (Data *) mBuf, MSGSIZE) == RFAILED)
732 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE) == RFAILED)
734 #endif /* SS_HISTOGRAM_SUPPORT */
736 #else /* SS_M_PROTO_REGION */
737 /* ss021.103 - Addition to check return value of SFree */
738 #ifdef SS_HISTOGRAM_SUPPORT
739 if (SFree(SS_DFLT_REGION, (Data *) mBuf, MSGSIZE, line, fileName, entId) == RFAILED)
741 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE) == RFAILED)
742 #endif /* SS_HISTOGRAM_SUPPORT */
744 #endif /* SS_M_PROTO_REGION */
749 #ifdef SS_LOCKLESS_MEMORY
752 * Fun: SPutStaticBuffer
754 * Desc: Returns a buffer to the specified static pool in the
755 * specified memory region.
758 * RFAILED - failed, general (optional)
765 /* ss001.301: additions */
766 #ifdef T2K_MEM_LEAK_DBG
767 PUBLIC S16 SPutStaticBufferNew
769 Region region, /* region ID */
770 Pool pool, /* pool ID */
771 Data *ptr, /* pointer to buffer */
772 Size size, /* size */
773 U8 memType, /* memory type used if shareable or not */
779 PUBLIC S16 SPutStaticBuffer
781 Region region, /* region ID */
782 Pool pool, /* pool ID */
783 Data *ptr, /* pointer to buffer */
784 Size size, /* size */
785 U8 memType /* memory type used if shareable or not */
788 PUBLIC S16 SPutStaticBuffer(region, pool, ptr, size)
789 Region region; /* region ID */
790 Pool pool; /* pool ID */
791 Data *ptr; /* pointer to buffer */
792 Size size; /* size */
793 U8 memType; /* memory type used if shareable or not */
799 TRC1(SPutStaticBuffer);
801 #if (ERRCLASS & ERRCLS_INT_PAR)
802 /* validate region ID */
803 if (region >= SS_MAX_REGS)
805 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
809 /* validate pool ID */
810 if (pool >= SS_MAX_POOLS_PER_REG)
812 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
815 /* validate data pointer */
818 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
825 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
829 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
831 extern pthread_t gMacTId,gRlcTId;
833 if(clusterMode == RADIO_CLUSTER_MODE)
835 #ifdef MAC_FREE_RING_BUF
836 if(pthread_self() == gMacTId)
837 //if(pthread_equal(pthread_self(),gMacTId))
841 if(ROK == mtAddBufToRing(SS_RNG_BUF_MAC_FREE_RING,(Void *)ptr,1))
848 #ifdef RLC_FREE_RING_BUF
849 else if(pthread_self() == gRlcTId)
853 if(ROK == mtAddBufToRing(SS_RNG_BUF_RLC_FREE_RING,(Void *)ptr,1))
863 region = SS_GET_THREAD_MEM_REGION();
866 #if (ERRCLASS & ERRCLS_INT_PAR)
867 /* verify that this region is present */
868 if (((memType == SS_NON_SHARABLE_MEMORY) &&
869 (osCp.regionTbl[region].used == FALSE)) ||
870 ((memType == SS_SHARABLE_MEMORY) &&
871 (osCp.dynRegionTbl[region].used == FALSE)))
873 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
878 /* call the memory manager, to allocate this memory */
879 #ifndef SS_DBUF_REFLOCK_DISABLE
880 if(memType == SS_NON_SHARABLE_MEMORY)
882 #ifndef T2K_MEM_LEAK_DBG
883 ret = (osCp.regionTbl[region].free)
884 (osCp.regionTbl[region].regCb, ptr, size);
886 ret = (osCp.regionTbl[region].free)
887 (osCp.regionTbl[region].regCb, ptr, size, file, line);
891 else if(memType == SS_SHARABLE_MEMORY)
895 #ifndef T2K_MEM_LEAK_DBG
896 ret = (osCp.dynRegionTbl[region].free)
897 (osCp.dynRegionTbl[region].regCb, ptr, size);
899 ret = (osCp.dynRegionTbl[region].free)
900 (osCp.dynRegionTbl[region].regCb, ptr, size,file,line);
902 #ifndef SS_DBUF_REFLOCK_DISABLE
911 * Fun: SGetStaticBuffer
913 * Desc: Allocates a buffer from the specified static memory pool
914 * in the specified region. Depending on the type wheather
915 * the buffer is sharable or non-sharable indicated by the
916 * memType prameter allocation region is choosen
920 * RFAILED - failed, general (optional)
927 #ifdef T2K_MEM_LEAK_DBG
928 PUBLIC S16 SGetStaticBufferNew
930 Region region, /* region ID */
931 Pool pool, /* pool ID */
932 Data **ptr, /* pointer to buffer */
933 Size size, /* size requested */
934 U8 memType, /* memory type used if shareable or not */
940 PUBLIC S16 SGetStaticBuffer
942 Region region, /* region ID */
943 Pool pool, /* pool ID */
944 Data **ptr, /* pointer to buffer */
945 Size size, /* size requested */
946 U8 memType /* memory type used if shareable or not */
949 PUBLIC S16 SGetStaticBuffer(region, pool, ptr, size)
950 Region region; /* region ID */
951 Pool pool; /* pool ID */
952 Data **ptr; /* pointer to buffer */
953 Size size; /* size requested */
954 U8 memType; /* memory type used if shareable or not */
961 TRC1(SGetStaticBuffer);
963 #if (ERRCLASS & ERRCLS_INT_PAR)
964 /* validate region ID */
965 if (region >= SS_MAX_REGS)
967 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
971 /* validate pool ID */
972 if (pool >= SS_MAX_POOLS_PER_REG)
974 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
977 /* validate data pointer */
980 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
987 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
992 #if (ERRCLASS & ERRCLS_INT_PAR)
993 /* verify that this region is present */
994 if (((memType == SS_NON_SHARABLE_MEMORY) &&
995 (osCp.regionTbl[region].used == FALSE)) ||
996 ((memType == SS_SHARABLE_MEMORY) &&
997 (osCp.dynRegionTbl[region].used == FALSE)))
999 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
1006 region = SS_GET_THREAD_MEM_REGION();
1008 if (region == SS_STATIC_REGION)
1012 /* call the memory manager, to allocate this memory */
1013 #ifndef SS_DBUF_REFLOCK_DISABLE
1014 if(memType == SS_NON_SHARABLE_MEMORY)
1016 #ifndef T2K_MEM_LEAK_DBG
1017 ret = (osCp.regionTbl[region].alloc)
1018 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1020 ret = (osCp.regionTbl[region].alloc)
1021 (osCp.regionTbl[region].regCb, &size, flags, ptr, file,line);
1024 else if(memType == SS_SHARABLE_MEMORY)
1027 #ifndef T2K_MEM_LEAK_DBG
1028 ret = (osCp.dynRegionTbl[region].alloc)
1029 (osCp.dynRegionTbl[region].regCb, &size, flags, ptr);
1031 ret = (osCp.dynRegionTbl[region].alloc)
1032 (osCp.dynRegionTbl[region].regCb, &size, flags, ptr,file,line);
1034 #ifndef SS_DBUF_REFLOCK_DISABLE
1040 #endif /* SS_LOCKLESS_MEMORY */
1043 #ifndef SS_LOCKLESS_MEMORY
1045 PUBLIC S16 SGetStaticBuffer
1047 Region region, /* region ID */
1048 Pool pool, /* pool ID */
1049 Data **ptr, /* pointer to buffer */
1050 Size size, /* size requested */
1051 U8 memType /* memory type used if shareable or not */
1054 PUBLIC S16 SGetStaticBuffer(region, pool, ptr, size)
1055 Region region; /* region ID */
1056 Pool pool; /* pool ID */
1057 Data **ptr; /* pointer to buffer */
1058 Size size; /* size requested */
1059 U8 memType; /* memory type used if shareable or not */
1064 ret = SGetSBuf(region, pool, ptr, size);
1071 PUBLIC S16 SPutStaticBuffer
1073 Region region, /* region ID */
1074 Pool pool, /* pool ID */
1075 Data *ptr, /* pointer to buffer */
1076 Size size, /* size */
1077 U8 memType /* memory type used if shareable or not */
1080 PUBLIC S16 SPutStaticBuffer(region, pool, ptr, size)
1081 Region region; /* region ID */
1082 Pool pool; /* pool ID */
1083 Data *ptr; /* pointer to buffer */
1084 Size size; /* size */
1085 U8 memType; /* memory type used if shareable or not */
1091 ret = SPutSBuf(region, pool, ptr, size);
1097 #ifdef T2K_MEM_LEAK_DBG
1098 PUBLIC S16 SGetSBufWls1
1100 Region region, /* region ID */
1101 Pool pool, /* pool ID */
1102 Data **ptr, /* pointer to buffer */
1103 Size size, /* size requested */
1108 PUBLIC S16 SGetSBufWls
1110 Region region, /* region ID */
1111 Pool pool, /* pool ID */
1112 Data **ptr, /* pointer to buffer */
1113 Size size /* size requested */
1120 #ifdef SS_LOCKLESS_MEMORY
1121 region = SS_GET_THREAD_MEM_REGION();
1122 ret = SAlloc(region, &size, 0, ptr);
1125 #ifdef T2K_MEM_LEAK_DBG
1126 ret = (osCp.regionTbl[region].alloc)
1127 (osCp.regionTbl[region].regCb, &size, flags, ptr,file,line);
1129 ret = (osCp.regionTbl[region].alloc)
1130 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1137 #ifdef T2K_MEM_LEAK_DBG
1138 PUBLIC S16 SPutSBufWls1
1140 Region region, /* region ID */
1141 Pool pool, /* pool ID */
1142 Data *ptr, /* pointer to buffer */
1143 Size size, /* size */
1148 PUBLIC S16 SPutSBufWls
1150 Region region, /* region ID */
1151 Pool pool, /* pool ID */
1152 Data *ptr, /* pointer to buffer */
1153 Size size /* size */
1159 #ifdef SS_LOCKLESS_MEMORY
1160 region = SS_GET_THREAD_MEM_REGION();
1161 ret = SFree(region, ptr, size);
1164 #ifdef T2K_MEM_LEAK_DBG
1165 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,file,line);
1167 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1174 #endif /* INTEL_WLS */
1181 * Desc: Allocates a buffer from the specified static memory pool
1182 * in the specified region.
1185 * RFAILED - failed, general (optional)
1187 * Notes: The new memory management scheme eliminates the concept
1188 * of pools. This call maps directly to a call to the memory
1194 /* ss001.301: additions */
1195 #ifdef SS_HISTOGRAM_SUPPORT
1197 PUBLIC S16 SGetSBufNew
1199 Region region, /* region ID */
1200 Pool pool, /* pool ID */
1201 Data **ptr, /* pointer to buffer */
1202 Size size, /* size requested */
1207 PUBLIC S16 SGetSBufNew(region, pool, ptr, size, line, fileName)
1208 Region region; /* region ID */
1209 Pool pool; /* pool ID */
1210 Data **ptr; /* pointer to buffer */
1211 Size size; /* size requested */
1215 #else /* SS_HISTOGRAM_SUPPORT */
1216 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1218 PUBLIC S16 SGetSBuf1
1220 Region region, /* region ID */
1221 Pool pool, /* pool ID */
1222 Data **ptr, /* pointer to buffer */
1223 Size size, /* size requested */
1228 PUBLIC S16 SGetSBuf1(region, pool, ptr, size, file, line)
1229 Region region; /* region ID */
1230 Pool pool; /* pool ID */
1231 Data **ptr; /* pointer to buffer */
1232 Size size; /* size requested */
1240 Region region, /* region ID */
1241 Pool pool, /* pool ID */
1242 Data **ptr, /* pointer to buffer */
1243 Size size /* size requested */
1246 PUBLIC S16 SGetSBuf(region, pool, ptr, size)
1247 Region region; /* region ID */
1248 Pool pool; /* pool ID */
1249 Data **ptr; /* pointer to buffer */
1250 Size size; /* size requested */
1253 #endif /* SS_HISTOGRAM_SUPPORT */
1257 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1261 #ifdef SS_HISTOGRAM_SUPPORT
1263 Bool hstReg = FALSE;
1264 #endif /* SS_HISTOGRAM_SUPPORT */
1268 region = SS_GET_THREAD_MEM_REGION();
1271 #endif /* INTEL_WLS */
1273 #if (ERRCLASS & ERRCLS_INT_PAR)
1274 /* validate region ID */
1275 if (region >= SS_MAX_REGS)
1277 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
1281 /* validate pool ID */
1282 if (pool >= SS_MAX_POOLS_PER_REG)
1284 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
1287 /* ss008.13: addition */
1288 /* validate data pointer */
1291 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
1298 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
1302 /* ss037.103 Removed the semaphore operation for performance enhancement */
1304 #ifndef RGL_SPECIFIC_CHANGES
1305 region = SS_GET_THREAD_MEM_REGION();
1308 /* acquire one semaphore, to protect against deregistration */
1309 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1313 #if (ERRCLASS & ERRCLS_DEBUG)
1314 SSLOGERROR(ERRCLS_DEBUG, ESS216, (ErrVal) ret,
1315 "Could not lock region table");
1323 #if (ERRCLASS & ERRCLS_INT_PAR)
1324 /* verify that this region is present */
1325 if (osCp.regionTbl[region].used == FALSE)
1329 /* ss006.13: addition */
1330 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1332 #if (ERRCLASS & ERRCLS_DEBUG)
1333 SSLOGERROR(ERRCLS_DEBUG, ESS217, ERRZERO,
1334 "Could not release semaphore");
1339 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
1348 /* ss024.103 - Addition for memory calculator tool */
1350 if (region == SS_STATIC_REGION)
1354 /* ss001.301: additions */
1355 #ifdef SS_HISTOGRAM_SUPPORT
1357 SGetEntInd(&entId, fileName);
1358 /* Get the Information from the oscp that the tapa task with the entity
1359 id (entid) is registed for histogram or not */
1360 SGetHstGrmInfo(&entId, &hstReg);
1361 /* call the memory manager, to allocate this memory */
1362 #ifdef SSI_DEBUG_LEVEL1
1363 ret = (osCp.regionTbl[region].alloc)
1364 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1365 SS_STATIC_MEM_FLAG, line, fileName, entId, hstReg);
1367 ret = (osCp.regionTbl[region].alloc)
1368 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1369 line, fileName, entId, hstReg);
1370 #endif /* SSI_DEBUG_LEVEL1 */
1374 /* call the memory manager, to allocate this memory */
1375 /* ss036.103 - addition for passing additional parameter memType as static */
1376 #ifdef SSI_DEBUG_LEVEL1
1377 ret = (osCp.regionTbl[region].alloc)
1378 (osCp.regionTbl[region].regCb, &size, flags, ptr, SS_STATIC_MEM_FLAG);
1380 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1381 /* Static mem leak detection changes */
1383 #ifdef T2K_MEM_LEAK_DBG
1384 ret = (osCp.regionTbl[region].alloc)
1385 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr, file, line);
1387 ret = (osCp.regionTbl[region].alloc)
1388 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr);
1390 /*size = tmpSize - 4;*/
1392 /*printf("ptr = %p *ptr = %p\n",ptr,*ptr);*/
1393 #ifdef XEON_SPECIFIC_CHANGES
1394 pthread_mutex_lock(&(memLock));
1396 U32 idx = GetNextFreeIdx(&SMemLeakInfo[region]);
1397 U8* allocatedPtr = *ptr;
1398 void* actualPtr = allocatedPtr + 4;
1400 /* store the index in the memory allocated itself */
1401 /**((U32*)*((U32*)allocatedPtr)) = idx;*/
1402 *((U32*)allocatedPtr) = idx;
1403 /*printf("region = %d idx = %d ptr = %p *ptr = %p actual = %p allocated = %p content = %d\n",region, idx, ptr, *ptr, actualPtr, allocatedPtr, *((U32*)allocatedPtr));*/
1405 LogForStaticMemLeak(&SMemLeakInfo[region],
1411 #ifdef XEON_SPECIFIC_CHANGES
1412 pthread_mutex_unlock(&(memLock));
1416 #ifndef T2K_MEM_LEAK_DBG
1417 ret = (osCp.regionTbl[region].alloc)
1418 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1420 ret = (osCp.regionTbl[region].alloc)
1421 (osCp.regionTbl[region].regCb, &size, flags, ptr, file, line);
1425 #endif /* SSI_DEBUG_LEVEL1 */
1427 #endif /* SS_HISTOGRAM_SUPPORT */
1429 /* release the semaphore we took */
1432 /* ss006.13: addition */
1433 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1435 #if (ERRCLASS & ERRCLS_DEBUG)
1436 SSLOGERROR(ERRCLS_DEBUG, ESS219, ERRZERO,
1437 "Could not release semaphore");
1442 /* ss036.103 - Addition to handle the memory trampling return value
1443 * This in turn might invoke SRegMemErrHdlr
1445 #ifdef SSI_DEBUG_LEVEL1
1446 if (ret == RTRAMPLINGNOK)
1448 SRegMemErrHdlr( region, *ptr, ret);
1450 #endif /* SSI_DEBUG_LEVEL1 */
1460 * Desc: Returns a buffer to the specified static pool in the
1461 * specified memory region.
1464 * RFAILED - failed, general (optional)
1471 /* ss001.301: additions */
1472 #ifdef SS_HISTOGRAM_SUPPORT
1474 PUBLIC S16 SPutSBufNew
1476 Region region, /* region ID */
1477 Pool pool, /* pool ID */
1478 Data *ptr, /* pointer to buffer */
1479 Size size, /* size */
1484 PUBLIC S16 SPutSBufNew(region, pool, ptr, size, line, fileName)
1485 Region region; /* region ID */
1486 Pool pool; /* pool ID */
1487 Data *ptr; /* pointer to buffer */
1488 Size size; /* size */
1492 #else /* SS_HISTOGRAM_SUPPORT */
1493 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1495 PUBLIC S16 SPutSBuf1
1497 Region region, /* region ID */
1498 Pool pool, /* pool ID */
1499 Data *ptr, /* pointer to buffer */
1500 Size size, /* size */
1505 PUBLIC S16 SPutSBuf1(region, pool, ptr, size, file, line)
1506 Region region; /* region ID */
1507 Pool pool; /* pool ID */
1508 Data *ptr; /* pointer to buffer */
1509 Size size; /* size */
1517 Region region, /* region ID */
1518 Pool pool, /* pool ID */
1519 Data *ptr, /* pointer to buffer */
1520 Size size /* size */
1523 PUBLIC S16 SPutSBuf(region, pool, ptr, size)
1524 Region region; /* region ID */
1525 Pool pool; /* pool ID */
1526 Data *ptr; /* pointer to buffer */
1527 Size size; /* size */
1530 #endif /* SS_HISTOGRAM_SUPPORT */
1534 #ifdef SS_HISTOGRAM_SUPPORT
1536 Bool hstReg = FALSE;
1537 #endif /* SS_HISTOGRAM_SUPPORT */
1542 region = SS_GET_THREAD_MEM_REGION();
1543 #if (!defined(SS_LOCKLESS_MEMORY) && defined(INTEL_WLS))
1545 #endif /* INTEL_WLS */
1547 #if (ERRCLASS & ERRCLS_INT_PAR)
1548 /* validate region ID */
1549 if (region >= SS_MAX_REGS)
1551 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
1555 /* validate pool ID */
1556 if (pool >= SS_MAX_POOLS_PER_REG)
1558 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
1561 /* ss008.13: addition */
1562 /* validate data pointer */
1565 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
1572 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
1576 /* ss037.103 Removed the semaphore operation for performance enhancement */
1577 #ifndef RGL_SPECIFIC_CHANGES
1578 region = SS_GET_THREAD_MEM_REGION();
1581 /* acquire one semaphore, to protect against deregistration */
1582 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1586 #if (ERRCLASS & ERRCLS_DEBUG)
1587 SSLOGERROR(ERRCLS_DEBUG, ESS225, (ErrVal) ret,
1588 "Could not lock region table");
1595 #if (ERRCLASS & ERRCLS_INT_PAR)
1596 /* verify that this region is around */
1597 if (osCp.regionTbl[region].used == FALSE)
1601 /* ss006.13: addition */
1602 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1604 #if (ERRCLASS & ERRCLS_DEBUG)
1605 SSLOGERROR(ERRCLS_DEBUG, ESS226, ERRZERO,
1606 "Could not release semaphore");
1611 SSLOGERROR(ERRCLS_INT_PAR, ESS227, region, "Region not registered");
1616 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1617 /* Static mem leak detection changes */
1619 #ifdef XEON_SPECIFIC_CHANGES
1620 pthread_mutex_lock(&(memLock));
1622 U32 idx = *((U32*)((U8 *)ptr - 4));
1623 FreeIdx(ptr,idx,&SMemLeakInfo[region],size,file,line);
1624 #ifdef XEON_SPECIFIC_CHANGES
1625 pthread_mutex_unlock(&(memLock));
1628 /* Static mem leak detection changes */
1631 /* ss001.301: additions */
1632 #ifdef SS_HISTOGRAM_SUPPORT
1633 SGetEntInd(&entId, fileName);
1634 /* Get the Information from the oscp that the tapa task with the entity
1635 id (entid) is registed for histogram or not */
1636 SGetHstGrmInfo(&entId, &hstReg);
1638 /* call the memory manager to free this memory */
1639 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,
1640 line, fileName, entId, hstReg);
1642 /* call the memory manager to free this memory */
1643 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1644 #ifdef T2K_MEM_LEAK_DBG
1645 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4, file, line);
1647 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4);
1650 #ifndef T2K_MEM_LEAK_DBG
1651 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1653 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size, file, line);
1656 #endif /* SS_HISTOGRAM_SUPPORT */
1657 /* ss037.103 Removed the semaphore operation for performance enhancement */
1660 /* release the semaphore we took */
1662 /* ss006.13: addition */
1663 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1665 #if (ERRCLASS & ERRCLS_DEBUG)
1666 SSLOGERROR(ERRCLS_DEBUG, ESS228, ERRZERO,
1667 "Could not release semaphore");
1672 /* ss036.103 - addition to handle double free and trampling return values
1673 * This might invoke SRegMemErrHdlr
1675 #ifdef SSI_DEBUG_LEVEL1
1676 /* handle the double free error here by calling the OS specific error handling function */
1677 if ((ret == RDBLFREE) || (ret == RTRAMPLINGNOK))
1679 SRegMemErrHdlr( region, ptr, ret);
1681 #endif /* SSI_DEBUG_LEVEL1 */
1691 * Desc: This function deallocates a message back and then
1692 * reinitializes the message.
1695 * RFAILED - failed, general (optional)
1697 * Notes: all data attached to message is returned to memory.
1698 * message is set to empty. message is not returned to
1699 * memory. return is ok.
1711 PUBLIC S16 SInitMsg(mBuf)
1721 #if (ERRCLASS & ERRCLS_INT_PAR)
1722 /* check message buffer */
1725 SSLOGERROR(ERRCLS_INT_PAR, ESS062, ERRZERO, "SInitMsg: Null Buffer");
1728 if (mBuf->b_datap->db_type != SS_M_PROTO)
1730 SSLOGERROR(ERRCLS_INT_PAR, ESS063, ERRZERO, "SInitMsg: Incorrect buffer\
1736 /* get the message info */
1739 CM_MEM_GET_REGION(tmpRegId);
1740 if(tmpRegId == 0xFF)
1745 minfo = (SsMsgInfo*) mBuf->b_rptr;
1747 /* free all SS_M_DATA blks */
1748 while ((tmp = mBuf->b_cont))
1750 mBuf->b_cont = tmp->b_cont;
1753 #ifdef T2K_MEM_LEAK_DBG
1754 char * file = __FILE__;
1755 U32 line = __LINE__;
1758 (Void) SPutDBuf(tmpRegId, minfo->pool, tmp);
1760 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
1763 /* initialise the length and endptr variables of mBuf */
1766 minfo->endptr = NULLP;
1767 minfo->next = NULLP;
1772 /* ss016.301 - Added a new API - SAddPreMsgMultInOrder. This preserves the
1773 * byte order while adding the data bytes to the beginning of the message.
1777 * Fun: SAddPreMsgMultInOrder
1779 * Desc: This function copies consecutive bytes of data to the
1780 * beginning of a message and keeps the bytes order preserved.
1782 * Ret: ROK - Appended the bytes to the beginning of the message.
1783 * RFAILED - Failed to append the bytes.
1784 * ROUTRES - Out of resources - Possibly insufficient memory.
1786 * Notes: If the message is empty,data is placed in the message. Message
1787 * length is incremented. Return is ROK.
1789 * If the message is not empty,data is read by source pointer
1790 * and appended at the beginning of the message.
1791 * Message length is incremented. Return is ROK.
1797 PUBLIC S16 SAddPreMsgMultInOrder
1804 PUBLIC S16 SAddPreMsgMultInOrder(src, cnt, mBuf)
1810 SsMsgInfo *minfo; /* Message info */
1812 Buffer *curblk=NULLP;
1815 MsgLen numBytes; /* no. of bytes to be copied */
1820 TRC1(SAddPreMsgMultInOrder)
1822 #if (ERRCLASS & ERRCLS_INT_PAR)
1823 /* check message buffer */
1826 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMultInOrder:\
1833 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMultInOrder:\
1840 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMultInOrder:\
1844 if (mBuf->b_datap->db_type != SS_M_PROTO)
1846 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMultInOrder:\
1847 Incorrect buffer type");
1852 /* get the SsMsgInfo of mBuf */
1853 minfo = (SsMsgInfo*) mBuf->b_rptr;
1854 #ifdef RGL_SPECIFIC_CHANGES
1858 /* store cnt in length */
1863 /* point to the end of the source buffer */
1864 revSrc = src + cnt ;
1866 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
1867 (tmp->b_datap->db_base < tmp->b_rptr))
1869 /* store the offset of the read pointer of tmp */
1870 offset = tmp->b_rptr - tmp->b_datap->db_base;
1872 /* determine the number of bytes to copy */
1873 numBytes = MIN(cnt, offset);
1875 /* traverse back from the end of the source buffer*/
1881 /* move the read pointer towards the left */
1882 tmp->b_rptr -= numBytes ;
1883 SMemCpy((Void *)(tmp->b_rptr ), (Void *) revSrc, (size_t) numBytes);
1891 newblk = prevblk = NULLP;
1894 /* allocate a message blk */
1895 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
1897 while ((curblk = prevblk))
1899 prevblk = prevblk->b_cont;
1900 #ifdef T2K_MEM_LEAK_DBG
1901 char * file = __FILE__;
1902 U32 line = __LINE__;
1905 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
1910 tmp->b_rptr = tmp->b_datap->db_base + offset;
1915 /* attach curblk in the newblk chain */
1918 curblk->b_cont = prevblk; /* stack them up */
1926 /* set the read and write pointers to the end of the data buffer */
1927 /* subsequent prepends have all the buffer to insert data into */
1928 curblk->b_wptr = curblk->b_datap->db_lim;
1929 rptr = curblk->b_datap->db_lim;
1932 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
1937 /* move the read pointer towards the left */
1940 /* traverse back the source buffer */
1943 SMemCpy((Void *)(rptr), (Void *) revSrc, (size_t) numBytes);
1945 curblk->b_rptr = rptr;
1948 /* attach the newblk chain into mBuf */
1949 newblk->b_cont = tmp;
1950 mBuf->b_cont = curblk;
1952 /* update endptr of mBuf */
1955 minfo->endptr = newblk;
1957 /* update length of message */
1966 * Desc: This function copies one byte of data to the
1967 * beginning of a message.
1970 * RFAILED - failed, general (optional)
1971 * ROUTRES - failed, out of resources (optional)
1973 * Notes: if message is empty: data is placed in the message. message
1974 * length is incremented. return is ok.
1976 * if message is not empty: data is placed in front of all
1977 * other data in message. message length is incremented.
1986 PUBLIC S16 SAddPreMsg
1992 PUBLIC S16 SAddPreMsg (data, mBuf)
2003 #if (ERRCLASS & ERRCLS_INT_PAR)
2004 /* check message buffer */
2007 SSLOGERROR(ERRCLS_INT_PAR, ESS064, ERRZERO, "SAddPreMsg: Null Buffer");
2010 if (mBuf->b_datap->db_type != SS_M_PROTO)
2012 SSLOGERROR(ERRCLS_INT_PAR, ESS065, ERRZERO, "SAddPreMsg: Incorrect\
2018 minfo = (SsMsgInfo *) mBuf->b_rptr;
2020 /* ss021.103 - Addition to check if exceeding maximum message length */
2022 if (minfo->len == 0x7FFFFFFF)
2024 if (minfo->len == 0x7FFF)
2031 * allocate a message blk using SGetDBuf(), if there are no data blks in the
2032 * message, mBuf, or if the reference count of the first data blk is greater
2033 * than 1, or if there is no space to append databytes in front of the read
2034 * pointer of the first data blk
2036 if (!(tmp = mBuf->b_cont) || (tmp->b_datap->db_ref > 1) ||
2037 (tmp->b_rptr == tmp->b_datap->db_base))
2039 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
2041 SSLOGERROR(ERRCLS_DEBUG, ESS066, ERRZERO, "SAddPreMsg:Failed in\
2045 /* set the read and write pointers to end of data buffer */
2046 /* subsequent prepends have all the buffer to insert data into */
2047 newb->b_wptr = newb->b_datap->db_lim;
2048 newb->b_rptr = newb->b_datap->db_lim;
2050 /* insert newb before tmp */
2051 newb -> b_cont = tmp;
2052 mBuf->b_cont = newb;
2054 /* if endptr of mBuf is NULLP, set it to newb */
2056 minfo->endptr = newb;
2059 /* insert data, increment length */
2060 *--tmp->b_rptr = data;
2070 * Desc: This function copies one byte of data to the
2074 * RFAILED - failed, general (optional)
2075 * ROUTRES - failed, out of resources (optional)
2077 * Notes: if message is empty: data is placed in the message. message
2078 * length is incremented. return is ok.
2080 * if message is not empty: data is placed in back of all
2081 * other data in message. message length is incremented.
2090 PUBLIC S16 SAddPstMsg
2096 PUBLIC S16 SAddPstMsg (data, mBuf)
2107 #if (ERRCLASS & ERRCLS_INT_PAR)
2108 /* check message buffer */
2111 SSLOGERROR(ERRCLS_INT_PAR, ESS067, ERRZERO, "SAddPstMsg: Null Buffer");
2114 if (mBuf->b_datap->db_type != SS_M_PROTO)
2116 SSLOGERROR(ERRCLS_INT_PAR, ESS068, ERRZERO, "SAddPstMsg: Incorrect\
2122 /* get the message info */
2123 minfo = (SsMsgInfo *) mBuf->b_rptr;
2125 if (!(tmp = minfo->endptr) || (tmp->b_datap->db_ref > 1) ||
2126 (tmp->b_wptr == tmp->b_datap->db_lim))
2128 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
2130 SSLOGERROR(ERRCLS_DEBUG, ESS069, ERRZERO, "SAddPstMsg: Failed in\
2135 /* append newb to the end of the mBuf chain */
2139 mBuf->b_cont = newb;
2141 /* set the endptr of mBuf to newb */
2142 minfo->endptr = newb;
2146 /* insert data, increment length */
2147 *tmp->b_wptr++ = data;
2155 * Fun: SAddPreMsgMult
2157 * Desc: This function copies consecutive bytes of data to the
2158 * beginning of a message.
2161 * RFAILED - failed, general (optional)
2162 * ROUTRES - failed, out of resources (optional)
2164 * Notes: if message is empty: data is placed in the message. message
2165 * length is incremented. return is ok.
2167 * if message is not empty: data is read by source pointer,
2168 * data is placed in front of all other data in message.
2169 * message length is incremented. return is ok.
2171 * the first byte of data pointed to by the source pointer will
2172 * be placed at the front of the message first, the last byte of
2173 * data pointed to by the source pointer will be placed at the
2174 * front of the message last (i.e. it will become the first
2175 * byte of the message).
2181 #ifdef T2K_MEM_LEAK_DBG
2182 PUBLIC S16 SAddPreMsgMult1
2193 PUBLIC S16 SAddPreMsgMult
2200 PUBLIC S16 SAddPreMsgMult(src, cnt, mBuf)
2207 SsMsgInfo *minfo; /* Message info */
2209 Buffer *curblk=NULLP;
2212 MsgLen numBytes; /* no. of bytes to be copied */
2217 TRC1(SAddPreMsgMult)
2219 #if (ERRCLASS & ERRCLS_INT_PAR)
2220 /* check message buffer */
2223 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMult:Null Buffer");
2229 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMult:Null Buffer");
2235 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMult: Invalid\
2239 if (mBuf->b_datap->db_type != SS_M_PROTO)
2241 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMult: Incorrect\
2247 /* get the SsMsgInfo of mBuf */
2248 minfo = (SsMsgInfo*) mBuf->b_rptr;
2250 /* store cnt in length */
2252 /* ss014.13: Addition */
2255 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
2256 (tmp->b_datap->db_base < tmp->b_rptr))
2258 /* store the offset of the read pointer of tmp */
2259 offset = tmp->b_rptr - tmp->b_datap->db_base;
2261 /* determine the number of bytes to copy */
2262 numBytes = MIN(cnt, offset);
2269 *--tmp->b_rptr = *src++;
2276 newblk = prevblk = NULLP;
2279 /* allocate a message blk */
2280 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2282 while ((curblk = prevblk))
2284 prevblk = prevblk->b_cont;
2285 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2290 tmp->b_rptr = tmp->b_datap->db_base + offset;
2295 /* attach curblk in the newblk chain */
2297 curblk->b_cont = prevblk; /* stack them up */
2302 /* set the read and write pointers to the end of the data buffer */
2303 /* subsequent prepends have all the buffer to insert data into */
2304 curblk->b_wptr = curblk->b_datap->db_lim;
2305 rptr = curblk->b_datap->db_lim;
2308 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
2315 curblk->b_rptr = rptr;
2318 /* attach the newblk chain into mBuf */
2319 newblk -> b_cont = tmp;
2320 mBuf -> b_cont = curblk;
2322 /* update endptr of mBuf */
2324 minfo -> endptr = newblk;
2326 /* update length of message */
2334 * Fun: SAddPstMsgMult
2336 * Desc: This function copies consecutive bytes of data to the
2340 * RFAILED - failed, general (optional)
2341 * ROUTRES - failed, out of resources (optional)
2343 * Notes: if message is empty: data is placed in the message. message
2344 * length is incremented. return is ok.
2346 * if message is not empty: data is read by source pointer,
2347 * data is placed in back of all other data in message.
2348 * message length is incremented. return is ok.
2350 * the first byte of data pointed to by the source pointer will
2351 * be placed at the back of the message first, the last byte of
2352 * data pointed to by the source pointer will be placed at the
2353 * back of the message last (i.e. it will become the last
2354 * byte of the message).
2360 #ifdef T2K_MEM_LEAK_DBG
2361 PUBLIC S16 SAddPstMsgMult1
2371 PUBLIC S16 SAddPstMsgMult
2378 PUBLIC S16 SAddPstMsgMult(src, cnt, mBuf)
2388 Buffer *curblk=NULLP;
2395 TRC1(SAddPstMsgMult)
2397 #if (ERRCLASS & ERRCLS_INT_PAR)
2398 /* check message buffer */
2401 SSLOGERROR(ERRCLS_INT_PAR, ESS074, ERRZERO, "SAddPstMsgMult:Null Buffer");
2407 SSLOGERROR(ERRCLS_INT_PAR, ESS075, ERRZERO, "SAddPstMsgMult:Null Buffer");
2413 SSLOGERROR(ERRCLS_INT_PAR, ESS076, ERRZERO, "SAddPstMsgMult:Invalid\
2417 if (mBuf->b_datap->db_type != SS_M_PROTO)
2419 SSLOGERROR(ERRCLS_INT_PAR, ESS077, ERRZERO, "SAddPstMsgMult: Incorrect\
2425 /* get the SsMsgInfo of mBuf */
2426 minfo = (SsMsgInfo*) mBuf->b_rptr;
2428 /* store cnt in len */
2431 /* ss014.13: Addition */
2434 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
2435 (tmp->b_datap->db_lim > tmp->b_wptr))
2437 /* store offset of the write pointer */
2438 /* incase subsequent allocations fail, offset is read reset to original */
2439 offset = tmp->b_datap->db_lim - tmp->b_wptr;
2441 /* determine the number of bytes to copy */
2442 numBytes = MIN(cnt, offset);
2448 /* ss002.13: addition */
2450 /* ss004.13: addition */
2451 SMemCpy((Void *) tmp->b_wptr, (Void *) src, (size_t) numBytes);
2453 tmp->b_wptr += numBytes;
2463 newblk = prevblk = NULLP;
2467 /* allocate a message blk */
2468 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2470 while ((curblk = newblk))
2472 newblk = newblk->b_cont;
2473 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2478 tmp->b_wptr = tmp->b_datap->db_lim - offset;
2484 /* insert curblk in the newblk chain */
2486 prevblk->b_cont = curblk; /* stack them down */
2492 wptr = curblk->b_wptr;
2493 numBytes = MIN(cnt, curblk->b_datap->db_lim - wptr);
2499 /* ss002.13: addition */
2500 /* ss003.13: addition */
2501 SMemCpy( (Void *) wptr, (Void *) src, (size_t) numBytes);
2503 src = src + numBytes;
2505 curblk->b_wptr += numBytes;
2507 /* insert newblk chain into mBuf */
2509 tmp->b_cont = newblk;
2511 mBuf->b_cont = newblk;
2512 minfo->endptr = curblk;
2520 /* #ifdef SS_LOCKLESS_MEMORY */
2528 * Desc: This function copies and then removes one byte of
2529 * data from the beginning of a message.
2532 * ROKDNA - ok, data not available
2533 * RFAILED - failed, general (optional)
2535 * Notes: if message is empty: message is unchanged. return is ok,
2536 * data not available.
2538 * if message is not empty: data is removed from front of
2539 * message, data is returned via pointer to data. message
2540 * length is decremented. return is ok.
2548 PUBLIC S16 SRemPreMsg
2554 PUBLIC S16 SRemPreMsg(dataPtr, mBuf)
2561 #ifdef T2K_MEM_LEAK_DBG
2562 char* file = __FILE__;
2563 U32 line = __LINE__;
2568 #if (ERRCLASS & ERRCLS_INT_PAR)
2569 /* check data pointer */
2572 SSLOGERROR(ERRCLS_INT_PAR, ESS078, ERRZERO, "SRemPreMsg : Null Buffer");
2575 /* check message buffer */
2578 SSLOGERROR(ERRCLS_INT_PAR, ESS079, ERRZERO, "SRemPreMsg : Null Buffer");
2581 if (mBuf->b_datap->db_type != SS_M_PROTO)
2583 SSLOGERROR(ERRCLS_INT_PAR, ESS080, ERRZERO, "SRemPreMsg : Incorrect\
2589 if (!(tmp = mBuf->b_cont))
2592 /* get SsMsgInfo of mBuf */
2593 minfo = (SsMsgInfo *) mBuf->b_rptr;
2595 /* read databyte into dataPtr and incrment read ptr */
2596 *dataPtr = *tmp->b_rptr++;
2598 /* if all data is exhausted, release the blk */
2599 if (tmp->b_rptr == tmp->b_wptr)
2601 mBuf->b_cont = tmp->b_cont;
2602 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2604 /* update SsMsgInfo */
2606 minfo->endptr = NULLP;
2615 * Desc: This function copies and then removes one byte of
2616 * data from the end of a message.
2619 * ROKDNA - ok, data not available
2620 * RFAILED - failed, general (optional)
2622 * Notes: if message is empty: message is unchanged. return is ok,
2623 * data not available.
2625 * if message is not empty: data is removed from back of
2626 * message, data is returned via pointer to data. message
2627 * length is decremented. return is ok.
2635 PUBLIC S16 SRemPstMsg
2637 Data *dataPtr, /* pointer to data */
2641 PUBLIC S16 SRemPstMsg(dataPtr, mBuf)
2642 Data *dataPtr; /* pointer to data */
2643 Buffer *mBuf; /* message buffer */
2649 #ifdef T2K_MEM_LEAK_DBG
2650 char* file = __FILE__;
2651 U32 line = __LINE__;
2656 #if (ERRCLASS & ERRCLS_INT_PAR)
2657 /* check data pointer */
2658 if (dataPtr == NULLP)
2660 SSLOGERROR(ERRCLS_INT_PAR, ESS081, ERRZERO, "SRemPstMsg : Null Buffer");
2663 /* check message buffer */
2666 SSLOGERROR(ERRCLS_INT_PAR, ESS082, ERRZERO, "SRemPstMsg : Null Buffer");
2669 if (mBuf->b_datap->db_type != SS_M_PROTO)
2671 SSLOGERROR(ERRCLS_INT_PAR, ESS083, ERRZERO, "SRemPstMsg : Incorrect\
2677 /* get the SsMsgInfo */
2678 minfo = (SsMsgInfo*) mBuf->b_rptr;
2680 if (!(last = minfo->endptr))
2683 /* read databyte into dataPtr and decrement write ptr */
2684 *dataPtr = *--last->b_wptr;
2686 /* if all data is exhausted, release the blk */
2687 if (last->b_rptr == last->b_wptr)
2689 for (tmp = mBuf; tmp->b_cont != last;)
2691 tmp->b_cont = NULLP;
2692 (Void) SPutDBuf(minfo->region, minfo->pool, last);
2696 minfo->endptr = tmp;
2698 minfo->endptr = NULLP;
2700 /* update SsMsgInfo */
2709 * Fun: SRemPreMsgMult
2711 * Desc: This function copies and then removes consecutive bytes of
2712 * data from the beginning of a message.
2715 * ROKDNA - ok, data not available
2716 * RFAILED - failed, general (optional)
2718 * Notes: if message is empty: message is unchanged. return is ok,
2719 * data not available.
2721 * if the destination buffer is NULL, data is not copied.
2723 * if message is not empty: data is removed from front of
2724 * message, data is returned by destination pointer. message
2725 * length is decremented. return is ok.
2727 * the first byte of data read from the message will be placed
2728 * in the destination buffer first (i.e. this was the first byte
2729 * of the message), the last byte of data read from the message
2730 * will be placed in the destination buffer last.
2737 PUBLIC S16 SRemPreMsgMult
2739 Data *dst, /* destination */
2740 MsgLen cnt, /* count */
2744 PUBLIC S16 SRemPreMsgMult(dst, cnt, mBuf)
2745 Data *dst; /* destination */
2746 MsgLen cnt; /* count */
2747 Buffer *mBuf; /* message buffer */
2753 #ifdef T2K_MEM_LEAK_DBG
2754 char* file = __FILE__;
2755 U32 line = __LINE__;
2758 TRC1(SRemPreMsgMult)
2760 /* ss023.103 - Modification of SRemPreMsgMult for bug fix */
2762 #if (ERRCLASS & ERRCLS_INT_PAR)
2766 SSLOGERROR(ERRCLS_INT_PAR, ESS084, ERRZERO, "SRemPreMsgMult:Invalid\
2770 /* check message buffer */
2773 SSLOGERROR(ERRCLS_INT_PAR, ESS085, ERRZERO, "SRemPreMsgMult:Null Buffer");
2776 /* ss021.103 - Addition to check for NULL pointer */
2777 /* check data pointer */
2778 /* ss022.103 - Removed check for NULL pointer */
2779 if (mBuf->b_datap->db_type != SS_M_PROTO)
2781 SSLOGERROR(ERRCLS_INT_PAR, ESS086, ERRZERO, "SRemPreMsgMult : Incorrect\
2787 /* get the SsMsgInfo */
2788 minfo = (SsMsgInfo*) mBuf->b_rptr;
2790 /* check if data present */
2791 if (minfo->len < cnt)
2798 /* get the first SS_M_DATA blk */
2801 /* determine the number of bytes to be copy */
2802 numBytes = MIN(cnt, tmp->b_wptr - tmp->b_rptr);
2807 /* move data into dst */
2811 SMemCpy( (Void *) dst, (Void *) tmp->b_rptr, (size_t) numBytes);
2815 tmp->b_rptr += numBytes;
2817 if (tmp->b_rptr == tmp->b_wptr)
2819 mBuf->b_cont = tmp->b_cont;
2820 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2823 /* update SsMsgInfo */
2825 minfo->endptr = NULLP;
2832 * Fun: SRemPstMsgMult
2834 * Desc: This function copies and then removes consecutive bytes of
2835 * data from the end of a message.
2838 * ROKDNA - ok, data not available
2839 * RFAILED - failed, general (optional)
2841 * Notes: if message is empty: message is unchanged. return is ok,
2842 * data not available.
2844 * if the destination buffer is NULL, data is not copied.
2846 * if message is not empty: data is removed from front of
2847 * message, data is returned by destination pointer. message
2848 * length is decremented. return is ok.
2850 * the first byte of data read from the message will be placed
2851 * in the destination buffer first (i.e. this was the last byte
2852 * of the message), the last byte of data read from the message
2853 * will be placed in the destination buffer last.
2860 PUBLIC S16 SRemPstMsgMult
2862 Data *dst, /* destination */
2863 MsgLen cnt, /* count */
2867 PUBLIC S16 SRemPstMsgMult(dst, cnt, mBuf)
2868 Data *dst; /* destination */
2869 MsgLen cnt; /* count */
2870 Buffer *mBuf; /* message buffer */
2879 #ifdef T2K_MEM_LEAK_DBG
2880 char* file = __FILE__;
2881 U32 line = __LINE__;
2884 TRC1(SRemPstMsgMult)
2886 #if (ERRCLASS & ERRCLS_INT_PAR)
2890 SSLOGERROR(ERRCLS_INT_PAR, ESS087, ERRZERO, "SRemPstMsgMult:Invalid\
2894 /* check message buffer */
2897 SSLOGERROR(ERRCLS_INT_PAR, ESS088, ERRZERO, "SRemPstMsgMult:Null Buffer");
2900 if (mBuf->b_datap->db_type != SS_M_PROTO)
2902 SSLOGERROR(ERRCLS_INT_PAR, ESS089, ERRZERO, "SRemPstMsgMult : Incorrect\
2906 /* ss021.103 - Addition to check dst data pointer */
2907 /* check data pointer */
2908 /* ss022.103 - Removed check for NULL destination pointer */
2911 /* get the SsMsgInfo */
2912 minfo = (SsMsgInfo*) mBuf->b_rptr;
2914 /* check if data present */
2915 if (minfo->len < cnt)
2925 /* determine blk containing offset, and prev node */
2926 FIND_OFFSET_AND_PREV(prev, tmp, count)
2933 numBytes = MIN(cnt, (tmp->b_wptr - tmp->b_rptr - count));
2935 tmp->b_wptr -= numBytes;
2947 if (tmp->b_rptr == tmp->b_wptr)
2949 prev->b_cont = tmp->b_cont;
2950 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2959 minfo->endptr = NULLP;
2961 minfo->endptr = prev;
2970 * Desc: This function copies one byte of data from a message
2971 * without modifying the message.
2974 * ROKDNA - ok, data not available
2975 * RFAILED - failed, general (optional)
2977 * Notes: index is 0 based and indicates location in message
2979 * if index is less than the length of the message:
2980 * message is unchanged and data is examined at specified
2981 * index and returned via pointer to data. message length
2982 * is unchanged. return is ok.
2984 * if index is greater than or equal to
2985 * the length of the message: message is unchanged and 0
2986 * is returned via pointer to data. return is ok, data
2997 Data *dataPtr, /* pointer to data */
2998 Buffer *mBuf, /* message buffer */
3002 PUBLIC S16 SExamMsg(dataPtr, mBuf, idx)
3003 Data *dataPtr; /* pointer to data */
3004 Buffer *mBuf; /* message buffer */
3005 MsgLen idx; /* index */
3013 #if (ERRCLASS & ERRCLS_INT_PAR)
3014 /* check data pointer */
3017 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SExamMsg : Null Buffer");
3020 /* check message buffer */
3023 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SExamMsg : Null Buffer");
3029 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SExamMsg : Invalid Index");
3032 if (mBuf->b_datap->db_type != SS_M_PROTO)
3034 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SExamMsg : Incorrect buffer\
3040 /* get the SsMsgInfo */
3041 minfo = (SsMsgInfo*) mBuf->b_rptr;
3043 if (minfo->len <= idx)
3048 /* get the first SS_M_DATA blk */
3051 /* determine offset */
3052 FIND_OFFSET(tmp, idx)
3054 *dataPtr = *(tmp->b_rptr + idx);
3063 * Fun: SGetDataFrmMsg
3065 * Desc: This function copies requested byte of data from a message
3066 * without modifying the message.
3069 * ROKDNA - ok, data not available
3070 * RFAILED - failed, general (optional)
3072 * Notes: index is 0 based and indicates location in message
3074 * if index is less than the length of the message:
3075 * message is unchanged and data is examined at specified
3076 * index and returned via pointer to data. message length
3077 * is unchanged. return is ok.
3079 * if index is greater than or equal to
3080 * the length of the message: message is unchanged and 0
3081 * is returned via pointer to data. return is ok, data
3090 PUBLIC S16 SGetDataFrmMsg
3092 Buffer *mBuf, /* message buffer */
3093 Data *dataPtr, /* pointer to data */
3098 PUBLIC S16 SGetDataFrmMsg(mBuf, dataPtr, idx, dataLen)
3099 Buffer *mBuf; /* message buffer */
3100 Data *dataPtr; /* pointer to data */
3101 MsgLen idx; /* index */
3108 Data *tmpDataPtr = dataPtr;
3110 TRC1(SGetDataFrmMsg)
3112 #if (ERRCLASS & ERRCLS_INT_PAR)
3113 /* check data pointer */
3116 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SGetDataFrmMsg: Null Buffer");
3119 /* check message buffer */
3122 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SGetDataFrmMsg: Null Buffer");
3128 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SGetDataFrmMsg: Invalid Index");
3131 if (mBuf->b_datap->db_type != SS_M_PROTO)
3133 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SGetDataFrmMsg: Incorrect buffer\
3139 /* get the SsMsgInfo */
3140 minfo = (SsMsgInfo*) mBuf->b_rptr;
3142 if (minfo->len <= (idx + dataLen) )
3147 /* get the first SS_M_DATA blk */
3150 /* determine offset */
3157 FIND_OFFSET(tmp, idx)
3158 offSetLen = ((tmp->b_wptr - (tmp->b_rptr + idx)));
3160 for(;(offSetLen < dataLen && tmp != NULLP);)
3162 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)offSetLen);
3163 dataLen = dataLen - offSetLen;
3166 tmpDataPtr = tmpDataPtr + offSetLen;
3167 offSetLen = tmp->b_wptr - tmp->b_rptr;
3173 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)dataLen);
3177 } /* End of SGetDataFrmMsg() */
3183 * Desc: This function determines the length of data within
3187 * RFAILED - failed, general (optional)
3189 * Notes: length of message is determined, message is unchanged
3190 * and length is returned via pointer to length. return is ok.
3198 PUBLIC S16 SFndLenMsg
3200 REG1 Buffer *mBuf, /* message buffer */
3204 PUBLIC S16 SFndLenMsg(mBuf, lngPtr)
3205 REG1 Buffer *mBuf; /* message buffer */
3206 MsgLen *lngPtr; /* pointer to length */
3213 #if (ERRCLASS & ERRCLS_INT_PAR)
3214 /* check message buffer */
3217 SSLOGERROR(ERRCLS_INT_PAR, ESS094, ERRZERO, "SFndLenMsg : Null Buffer");
3220 /* check length pointer */
3221 if (lngPtr == NULLP)
3223 SSLOGERROR(ERRCLS_INT_PAR, ESS095, ERRZERO, "SFndLenMsg : Null Buffer");
3226 if (mBuf->b_datap->db_type != SS_M_PROTO)
3228 SSLOGERROR(ERRCLS_INT_PAR, ESS096, ERRZERO, "SFndLenMsg : Incorrect\
3234 /* get the SsMsgInfo */
3235 minfo = (SsMsgInfo*) mBuf->b_rptr;
3238 *lngPtr = minfo->len;
3244 /* #ifdef SS_LOCKLESS_MEMORY */
3250 * Desc: This function will segment one specified message into two
3254 * ROKDNA - ok, data not available
3255 * RFAILED - failed, general (optional)
3256 * ROUTRES - failed, out of resources (optional)
3258 * Notes: message 1 is the original message.
3260 * message 2 is the new message.
3262 * index is 0 based and indicates location in message 1
3263 * from which message 2 will be created.
3265 * if index is equal to 0: message 2 is created and all data
3266 * attached to message 1 is moved to message 2. message 1
3267 * is not returned to memory. return is ok.
3269 * if index is not equal to 0 and less than the length of
3270 * the message minus 1: message 2 is created, all data
3271 * attached to message 1 from index (inclusive) is moved to
3272 * message 2. message 1 contains data from index 0 to index
3273 * minus 1. return is ok.
3275 * if index is not equal to 0 and greater than or equal to
3276 * the length of the message minus 1: message 1 is unchanged.
3277 * message 2 is set to null. return is ok, data not available.
3282 #ifdef T2K_MEM_LEAK_DBG
3283 PUBLIC S16 SSegMsgNew
3285 Buffer *mBuf1, /* message 1 */
3286 MsgLen idx, /* index */
3295 Buffer *mBuf1, /* message 1 */
3296 MsgLen idx, /* index */
3300 PUBLIC S16 SSegMsg(mBuf1, idx, mBuf2)
3301 Buffer *mBuf1; /* message 1 */
3302 MsgLen idx; /* index */
3303 Buffer **mBuf2; /* message 2 */
3315 #if (ERRCLASS & ERRCLS_INT_PAR)
3316 /* check message buffer 1 */
3319 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SSegMsg : Null Buffer");
3322 /* check message buffer 2 */
3325 SSLOGERROR(ERRCLS_INT_PAR, ESS098, ERRZERO, "SSegMsg : Null Buffer");
3330 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SSegMsg : Invalid index");
3333 if (mBuf1->b_datap->db_type != SS_M_PROTO)
3335 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SSegMsg : Incorrect buffer\
3341 /* get the SsMsgInfo of mBuf1 */
3342 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
3343 #ifdef RGL_SPECIFIC_CHANGES
3347 /* if index > length of mBuf, return */
3348 if (idx >= minfo1->len)
3353 /* allocate message buffer */
3354 if (SGetMsg(minfo1->region, minfo1->pool, mBuf2) != ROK)
3356 SSLOGERROR(ERRCLS_DEBUG, ESS101, ERRZERO, "SSegMsg : SGetMsg failed");
3360 /* get the SsMsgInfo of mBuf2 */
3361 minfo2 = (SsMsgInfo*) (*mBuf2)->b_rptr;
3363 /* adjust the lengths of mBuf1, mBuf2 */
3364 minfo2->len = minfo1->len - idx;
3367 /* set the endptr of mBuf2 to mBuf1 */
3368 minfo2->endptr = minfo1->endptr;
3370 /* if index is zero ... */
3373 (*mBuf2)->b_cont = mBuf1->b_cont;
3375 /* set the endptr and b_cont of mBuf1 to NULLP */
3376 minfo1->endptr = NULLP;
3377 mBuf1->b_cont = NULLP;
3382 /* get the first SS_M_DATA blk */
3383 tmp = mBuf1->b_cont;
3386 FIND_OFFSET_AND_PREV(prev, tmp, idx)
3388 /* segmented at the start of a blk */
3391 (*mBuf2)->b_cont = tmp;
3392 prev->b_cont = NULLP;
3393 minfo1->endptr = prev;
3397 #ifndef SS_MULTICORE_SUPPORT
3398 /* allocate a message blk without a data blk */
3399 /* ssDupB internally increments the reference count */
3400 #ifdef SS_M_PROTO_REGION
3401 if (!(next = DupMsg(minfo1->region, tmp)))
3403 if (!(next = ssDupB(tmp)))
3404 #endif /* SS_M_PROTO_REGION */
3407 minfo1->len += minfo2->len;
3408 (Void) SPutMsg(*mBuf2);
3412 (*mBuf2)->b_cont = next;
3414 tmp->b_cont = NULLP;
3416 tmp->b_wptr = tmp->b_rptr + idx;
3417 next->b_rptr = tmp->b_wptr;
3419 /* If the index was in the last mblk of the message, the
3420 * end pointer of the new message needs to be set to the
3421 * dup'ped mblk. Otherwise, the end pointer of the first
3422 * message will be set to the mblk in which the index
3423 * was found, and the end pointer of the new message can
3424 * remain where it is.
3426 if (minfo1->endptr == tmp)
3428 minfo2->endptr = next;
3432 minfo1->endptr = tmp;
3434 #else /*SS_MULTICORE_SUPPORT*/
3438 #ifdef SS_M_PROTO_REGION
3439 if (!(next = DupMsg(minfo1->region, tmp)))
3441 if (!(next = ssDupB(tmp)))
3442 #endif /* SS_M_PROTO_REGION */
3445 minfo1->len += minfo2->len;
3446 (Void) SPutMsg(*mBuf2);
3449 (*mBuf2)->b_cont = next;
3450 tmp->b_wptr = tmp->b_rptr + idx;
3451 next->b_rptr += idx;
3454 /* copy rest of the blocks */
3458 prev->b_cont = NULLP;
3459 minfo2->endptr = minfo1->endptr;
3460 minfo1->endptr = prev;
3464 next->b_cont = NULLP;
3465 minfo2->endptr = next;
3468 #endif /*SS_MULTICORE_SUPPORT*/
3478 * Desc: This function copies data from a fixed buffer to a
3482 * RFAILED - failed, general (optional)
3491 PUBLIC S16 SCpyFixMsg
3493 Data *srcBuf, /* source buffer */
3494 Buffer *dstMbuf, /* destination message buffer */
3495 MsgLen dstIdx, /* destination index */
3496 MsgLen cnt, /* count */
3500 PUBLIC S16 SCpyFixMsg(srcBuf, dstMbuf, dstIdx, cnt, cCnt)
3501 Data *srcBuf; /* source buffer */
3502 Buffer *dstMbuf; /* destination message buffer */
3503 MsgLen dstIdx; /* destination index */
3504 MsgLen cnt; /* count */
3505 MsgLen *cCnt; /* copied count */
3514 #if (ERRCLASS & ERRCLS_INT_PAR)
3515 /* check source message buffer */
3516 if (srcBuf == NULLP)
3518 SSLOGERROR(ERRCLS_INT_PAR, ESS102, ERRZERO, "SCpyFixMsg : Null Buffer");
3521 /* check destination message buffer */
3522 if (dstMbuf == NULLP)
3524 SSLOGERROR(ERRCLS_INT_PAR, ESS103, ERRZERO, "SCpyFixMsg : Null Buffer");
3527 /* check copied count buffer */
3530 SSLOGERROR(ERRCLS_INT_PAR, ESS104, ERRZERO, "SCpyFixMsg : Null Buffer");
3533 /* check copy count */
3536 SSLOGERROR(ERRCLS_INT_PAR, ESS105, ERRZERO, "SCpyFixMsg : Invalid count");
3539 if (dstMbuf->b_datap->db_type != SS_M_PROTO)
3541 SSLOGERROR(ERRCLS_INT_PAR, ESS106, ERRZERO, "SCpyFixMsg : Incorrect\
3547 minfo = (SsMsgInfo*) dstMbuf->b_rptr;
3549 if (minfo->len < dstIdx)
3551 #if (ERRCLASS & ERRCLS_DEBUG)
3552 SSLOGERROR(ERRCLS_DEBUG, ESS107, ERRZERO, "SCpyFixMsg : Invalid Index");
3557 /* ss021.103 - Addition test if message length will exceed max msg length */
3558 #if (ERRCLASS & ERRCLS_INT_PAR)
3560 if (minfo->len > 0x7FFFFFFF - cnt)
3562 if (minfo->len > 0x7FFF - cnt)
3567 SSLOGERROR(ERRCLS_INT_PAR, ESS108, ERRZERO, "SCpyFixMsg : msgLen + cnt > maxS16");
3572 /* add data at the start of dst buffer */
3575 if ((ret = SAddPreMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3577 #if (ERRCLASS & ERRCLS_DEBUG)
3578 SSLOGERROR(ERRCLS_DEBUG, ESS109, ERRZERO, "SCpyFixMsg : Failed in\
3588 /* add data at the end of the dst buffer */
3589 if (minfo->len == dstIdx)
3591 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3600 /* segment the message into dstMbuf and right */
3601 if ((ret = SSegMsg(dstMbuf, dstIdx, &right)) != ROK)
3606 /* append data at the end of dstMbuf */
3607 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3609 /* ss020.103 - Addition for cleanup */
3610 (Void) SPutMsg(right);
3614 /* cancatenate dstMbuf and right */
3615 if ((ret = SCatMsg(dstMbuf, right, M1M2)) != ROK)
3617 /* ss020.103 - Addition for cleanup */
3618 (Void) SPutMsg(right);
3624 (Void) SPutMsg(right);
3633 * Desc: This function copies data from a message
3634 * into a fixed buffer.
3637 * RFAILED - failed, general (optional)
3646 PUBLIC S16 SCpyMsgFix
3648 Buffer *srcMbuf, /* source message buffer */
3649 MsgLen srcIdx, /* source index */
3650 MsgLen cnt, /* count */
3651 Data *dstBuf, /* destination buffer */
3655 PUBLIC S16 SCpyMsgFix(srcMbuf, srcIdx, cnt, dstBuf, cCnt)
3656 Buffer *srcMbuf; /* source message buffer */
3657 MsgLen srcIdx; /* source index */
3658 MsgLen cnt; /* count */
3659 Data *dstBuf; /* destination buffer */
3660 MsgLen *cCnt; /* copied count */
3670 #if (ERRCLASS & ERRCLS_INT_PAR)
3671 /* check source message buffer */
3672 if (srcMbuf == NULLP)
3674 SSLOGERROR(ERRCLS_INT_PAR, ESS110, ERRZERO, "SCpyMsgFix : Null Buffer");
3677 /* check destination message buffer */
3678 if (dstBuf == NULLP)
3680 SSLOGERROR(ERRCLS_INT_PAR, ESS111, ERRZERO, "SCpyMsgFix : Null Buffer");
3685 SSLOGERROR(ERRCLS_INT_PAR, ESS112, ERRZERO, "SCpyMsgFix : Invalid Index");
3691 SSLOGERROR(ERRCLS_INT_PAR, ESS113, ERRZERO, "SCpyMsgFix : Invalid Index");
3696 SSLOGERROR(ERRCLS_INT_PAR, ESS114, ERRZERO, "SCpyMsgFix : Null Buffer");
3699 if (srcMbuf->b_datap->db_type != SS_M_PROTO)
3701 SSLOGERROR(ERRCLS_INT_PAR, ESS115, ERRZERO, "SCpyMsgFix : Incorrect\
3708 minfo = (SsMsgInfo*) srcMbuf->b_rptr;
3710 if ((srcIdx + cnt) > minfo->len)
3716 /* get the first SS_M_DATA blk */
3717 tmp = srcMbuf->b_cont;
3719 /* get to the srcIdx-th offset */
3720 FIND_OFFSET(tmp, srcIdx)
3724 /* set cptr to the read ptr of tmp + offset */
3725 cptr = tmp->b_rptr + srcIdx;
3729 /* determine the number of bytes to be copied */
3730 numBytes = MIN(cnt, (tmp->b_wptr - cptr));
3737 /* ss002.13 addition */
3739 /* ss003.13 addition */
3740 SMemCpy((Void *) dstBuf, (Void *) cptr, (size_t) numBytes);
3746 /* get the next blk */
3747 if ((tmp = tmp->b_cont))
3748 /* set cptr to the read ptr of tmp */
3761 * Desc: This function is used to copy a message into
3762 * a new region and or pool of memory.
3765 * RFAILED - failed, general (optional)
3766 * ROUTRES - failed, out of resources (optional)
3774 #ifdef T2K_MEM_LEAK_DBG
3775 PUBLIC S16 SCpyMsgMsgNew
3786 PUBLIC S16 SCpyMsgMsg
3794 PUBLIC S16 SCpyMsgMsg(srcBuf, dstRegion, dstPool, dstBuf)
3809 /* ss021.103 - Addition of return value */
3811 #if (ERRCLASS & ERRCLS_INT_PAR)
3818 #if (ERRCLASS & ERRCLS_INT_PAR)
3821 SSLOGERROR(ERRCLS_INT_PAR, ESS116, ERRZERO, "SCpyMsgMsg : Null Buffer");
3824 if (srcBuf->b_datap->db_type != SS_M_PROTO)
3826 SSLOGERROR(ERRCLS_INT_PAR, ESS117, ERRZERO, "SCpyMsgMsg : Incorrect\
3830 /* ss021.103 - Addition to validate region and pool */
3831 if (dstRegion >= SS_MAX_REGS)
3833 SSLOGERROR(ERRCLS_INT_PAR, ESS118, ERRZERO,
3834 "SCpyMsgMsg : Invalid region id");
3838 if (dstPool >= SS_MAX_POOLS_PER_REG)
3840 SSLOGERROR(ERRCLS_INT_PAR, ESS119, ERRZERO,
3841 "SCpyMsgMsg : Invalid pool id");
3844 /* ss037.103 Removed the semaphore operation for performance enhancement */
3847 /* ss021.103 - Addition to check if region is valid */
3848 /* acquire one semaphore, to protect against deregistration */
3849 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
3853 #if (ERRCLASS & ERRCLS_DEBUG)
3854 SSLOGERROR(ERRCLS_DEBUG, ESS120, (ErrVal) ret,
3855 "Could not lock region table");
3862 #if (ERRCLASS & ERRCLS_INT_PAR)
3863 /* verify that this region is present */
3864 if (osCp.regionTbl[dstRegion].used == FALSE)
3867 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3869 #if (ERRCLASS & ERRCLS_DEBUG)
3870 SSLOGERROR(ERRCLS_DEBUG, ESS121, ERRZERO,
3871 "Could not release semaphore");
3876 SSLOGERROR(ERRCLS_INT_PAR, ESS122, dstRegion, "Region not registered");
3880 /* ss037.103 Removed the semaphore operation for performance enhancement */
3883 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3885 #if (ERRCLASS & ERRCLS_DEBUG)
3886 SSLOGERROR(ERRCLS_DEBUG, ESS123, ERRZERO,
3887 "Could not release semaphore");
3894 #ifdef XEON_SPECIFIC_CHANGES
3898 /* allocate a message buffer */
3899 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
3901 #if (ERRCLASS & ERRCLS_DEBUG)
3902 SSLOGERROR(ERRCLS_DEBUG, ESS124, ERRZERO, "SCpyMsgMsg : SGetMsg failed");
3906 /* get the SsMsgInfo from srcBuf */
3907 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
3909 /* get the SsMsgInfo from srcBuf */
3910 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
3912 /* get the first SS_M_DATA blk of srcBuf */
3913 tmp = srcBuf->b_cont;
3915 /* if srcBuf and dstBuf belong to the same region, increment the reference
3924 #ifdef SS_M_PROTO_REGION
3925 if ((curblk = DupMsg(dstRegion,tmp)) == NULLP)
3927 if ((curblk = ssDupB(tmp)) == NULLP)
3928 #endif /* SS_M_PROTO_REGION */
3932 curblk = newblk->b_cont;
3933 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
3936 printf("Failed to get the buffer of size %s %d\n", __FILE__, __LINE__);
3937 (Void) SPutMsg(*dstBuf);
3944 prevblk->b_cont = curblk;
3950 curblk->b_cont = NULLP;
3952 minfo2->len = minfo1->len;
3953 minfo2->endptr = curblk;
3954 (*dstBuf)->b_cont = newblk;
3965 * Desc: This function is used to copy a message into
3966 * a new region and or pool of memory.
3969 * RFAILED - failed, general (optional)
3970 * ROUTRES - failed, out of resources (optional)
3977 #ifdef T2K_MEM_LEAK_DBG
3978 PUBLIC S16 SAddMsgRefNew
3989 PUBLIC S16 SAddMsgRef
3997 PUBLIC S16 SAddMsgRef(srcBuf, dstRegion, dstPool, dstBuf)
4017 #if (ERRCLASS & ERRCLS_INT_PAR)
4020 SSLOGERROR(ERRCLS_INT_PAR, ESS126, ERRZERO, "SAddMsgRef : Null Buffer");
4023 if (srcBuf->b_datap->db_type != SS_M_PROTO)
4025 SSLOGERROR(ERRCLS_INT_PAR, ESS127, ERRZERO, "SAddMsgRef : Incorrect\
4030 #ifdef XEON_SPECIFIC_CHANGES
4035 /* allocate a message buffer */
4036 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
4038 #if (ERRCLASS & ERRCLS_DEBUG)
4039 SSLOGERROR(ERRCLS_DEBUG, ESS128, ERRZERO, "SAddMsgRef : SGetMsg failed");
4043 /* get the SsMsgInfo from srcBuf */
4044 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
4046 /* get the SsMsgInfo from srcBuf */
4047 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
4049 /* get the first SS_M_DATA blk of srcBuf */
4050 tmp = srcBuf->b_cont;
4052 /* if srcBuf and dstBuf belong to the same region, increment the reference
4055 if (dstRegion == minfo1->region)
4063 #ifdef SS_M_PROTO_REGION
4064 if ((curblk = DupMsg(dstRegion, tmp)) == NULLP)
4066 if ((curblk = ssDupB(tmp)) == NULLP)
4067 #endif /* SS_M_PROTO_REGION */
4071 curblk = newblk->b_cont;
4072 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
4075 (Void) SPutMsg(*dstBuf);
4082 prevblk->b_cont = curblk;
4088 curblk->b_cont = NULLP;
4090 minfo2->len = minfo1->len;
4091 minfo2->endptr = curblk;
4092 (*dstBuf)->b_cont = newblk;
4097 /* allocate a data buffer */
4098 if (ssGetDBufOfSize(dstRegion, minfo1->len, &dBuf) != ROK)
4100 /* ss016.13: addition */
4101 (Void) SPutMsg(*dstBuf);
4102 SSLOGERROR(ERRCLS_DEBUG, ESS129, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
4106 dBuf->b_datap->db_type = SS_M_DATA;
4110 numBytes = tmp->b_wptr - tmp->b_rptr;
4113 *dBuf->b_wptr++ = *cptr++;
4116 minfo2->len = minfo1->len;
4117 /* set the endptr and b_cont of dstBuf to point to dBuf */
4118 minfo2->endptr = dBuf;
4119 (*dstBuf)->b_cont = dBuf;
4123 /* ss012.13: Addition */
4124 #ifdef SS_M_PROTO_REGION
4129 * Desc: Duplicates the specified message block, copying it
4130 * into a newly-allocated message block. Increments
4131 * the reference count of the data block that is pointed
4132 * at by the original message block descriptor.
4134 * Ret: non-NULL - ok
4142 #ifdef T2K_MEM_LEAK_DBG
4143 PRIVATE Buffer *DupMsgNew
4145 Region region, /* region id */
4146 Buffer *mp, /* message block */
4152 PRIVATE Buffer *DupMsg
4154 Region region, /* region id */
4155 Buffer *mp /* message block */
4158 PRIVATE Buffer *DupMsg(region, mp)
4159 Region region; /* region id */
4160 Buffer *mp; /* message block */
4164 Buffer *bp; /* mblk for iteration */
4165 S16 r; /* return value */
4166 Size m; /* temporary */
4171 #if (ERRCLASS & ERRCLS_INT_PAR)
4174 SSLOGERROR(ERRCLS_INT_PAR, ESS130, ERRZERO, "Null pointer");
4178 if (region >= SS_MAX_REGS)
4180 SSLOGERROR(ERRCLS_INT_PAR, ESS131, ERRZERO, "DupMsg : Invalid region\
4187 /* allocate a single block for the mblock and the dblock */
4189 m = (sizeof(SsMblk) + sizeof(SsDblk));
4191 numBytes = mp->b_wptr - mp->b_rptr;
4192 m = MDBSIZE + numBytes;
4193 #endif /* SS_MULTICORE_SUPPORT */
4194 /* ss001.301: additions */
4195 #ifdef SS_HISTOGRAM_SUPPORT
4196 r = SAlloc(region, &m, 0, (Data **)&bp, __LINE__, (U8*) __FILE__, ENTNC);
4198 r = SAlloc(region, &m, 0, (Data **)&bp);
4199 #endif /* SS_HISTOGRAM_SUPPORT */
4202 #if (ERRCLASS & ERRCLS_ADD_RES)
4203 SSLOGERROR(ERRCLS_ADD_RES, ESS132, (ErrVal) r, "SAlloc() failed");
4208 /* generic set-up-message function */
4210 #ifndef SS_DBUF_REFLOCK_DISABLE
4211 SS_STRM_INITB(bp, (SsDblk *)(((U8 *)bp) + sizeof(SsMblk)), NULLP, 0, NULLP);
4214 data = (Data *) (bp) + MDBSIZE;
4215 SS_STRM_INITB(bp,(SsDblk *)(((U8 *)bp) + sizeof(SsMblk)), data, numBytes, NULLP);
4216 #endif /* SS_MULTICORE_SUPPORT */
4219 /* make the new message block identical to the one to be dup'ed.
4220 * notice that an mblk/dblk pair is allocated but only the mblk
4221 * is used,, this is for optimum performance in the average case.
4223 SMemCpy( (Void *)bp, (Void *)mp, (size_t)sizeof(SsMblk));
4225 /* ss006.301 - added the Lock */
4226 #ifndef SS_DBUF_REFLOCK_DISABLE
4227 if((SLock(&(mp->b_datap->dBufLock))) != ROK)
4229 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
4230 "Could not lock the mBuf Ref Lock");
4234 /* increment the reference count of the dblock */
4235 /* increment the reference count of the dblock */
4236 mp->b_datap->db_ref++;
4237 mp->b_datap->shared = TRUE;
4238 #ifndef SS_DBUF_REFLOCK_DISABLE
4239 if((SUnlock(&(mp->b_datap->dBufLock))) != ROK)
4241 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
4242 "Could not lock the mBuf Ref Lock");
4250 #endif /* SS_M_PROTO_REGION */
4256 * Desc: This function allocates a buffer from the dynamic
4257 * memory pool indicated by the caller.
4260 * RFAILED - failed, general (optional)
4261 * ROUTRES - failed, out of resources (optional)
4263 * Notes: The dynamic memory pools are used to create and
4264 * manipulate messages.
4266 * SGetDBuf is never called by a protocol layer.
4268 * SGetDBuf assumes that interrupts are already disabled.
4274 #ifdef T2K_MEM_LEAK_DBG
4275 PUBLIC S16 SGetDBufNew
4277 Region region, /* region id */
4278 Pool pool, /* pool id */
4287 Region region, /* region id */
4288 Pool pool, /* pool id */
4292 PUBLIC S16 SGetDBuf(region, pool, bufPtr)
4293 Region region; /* region id */
4294 Pool pool; /* pool id */
4295 Buffer **bufPtr; /* pointer to buffer */
4303 #ifdef SS_LOCKLESS_MEMORY
4304 #ifdef SS_USE_ICC_MEMORY
4305 CmMmDynRegCb *regCb;
4307 CmMmGlobRegCb *regCb;
4310 SsRegionEntry *regp;
4311 #endif /* SS_LOCKLESS_MEMORY */
4312 /* ss021.103 - Addition of return value */
4314 #if (ERRCLASS & ERRCLS_INT_PAR)
4321 #if (ERRCLASS & ERRCLS_INT_PAR)
4322 /* check buffer pointer */
4325 SSLOGERROR(ERRCLS_INT_PAR, ESS133, ERRZERO, "SGetDBuf : Null Buffer");
4328 if (region >= SS_MAX_REGS)
4330 SSLOGERROR(ERRCLS_INT_PAR, ESS134, ERRZERO, "SGetDBuf : Invalid region\
4335 if (pool >= SS_MAX_POOLS_PER_REG)
4337 SSLOGERROR(ERRCLS_INT_PAR, ESS135, ERRZERO, "SGetDBuf : Invalid pool id");
4340 /* ss037.103 Removed the semaphore operation for performance enhancement */
4343 /* ss021.103 - Addition to check if region is registered */
4344 /* acquire one semaphore, to protect against deregistration */
4345 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
4349 #if (ERRCLASS & ERRCLS_DEBUG)
4350 SSLOGERROR(ERRCLS_DEBUG, ESS136, (ErrVal) ret,
4351 "Could not lock region table");
4359 #if (ERRCLASS & ERRCLS_INT_PAR)
4360 /* verify that this region is present */
4361 if (osCp.regionTbl[region].used == FALSE)
4363 /* ss037.103 Removed the semaphore operation for performance enhancement */
4366 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4368 #if (ERRCLASS & ERRCLS_DEBUG)
4369 SSLOGERROR(ERRCLS_DEBUG, ESS137, ERRZERO,
4370 "Could not release semaphore");
4375 SSLOGERROR(ERRCLS_INT_PAR, ESS138, region, "Region not registered");
4379 /* ss037.103 Removed the semaphore operation for performance enhancement */
4382 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4384 #if (ERRCLASS & ERRCLS_DEBUG)
4385 SSLOGERROR(ERRCLS_DEBUG, ESS139, ERRZERO,
4386 "Could not release semaphore");
4393 #ifdef SS_LOCKLESS_MEMORY
4394 #ifdef SS_USE_ICC_MEMORY
4395 regCb = (CmMmDynRegCb *)(osCp.dynRegionTbl[region].regCb);
4396 mdsize = regCb->bktSize[pool];
4397 #else /* SS_USE_ICC_MEMORY */
4398 regCb = osCp.globRegCb;
4399 #ifdef SS_MEM_WL_DEBUG
4400 mdsize = regCb->bktTbl[pool].size - 4;
4401 #else /* SS_MEM_WL_DEBUG */
4402 mdsize = regCb->bktTbl[pool].size;
4403 #endif /* SS_MEM_WL_DEBUG */
4404 #endif /* SS_USE_ICC_MEMORY */
4406 regp = &osCp.regionTbl[region];
4407 size = regp->poolTbl[pool].u.dpool.size;
4408 /* ss006.301 : optimized this function */
4409 mdsize = MDBSIZE + size;
4410 #endif /* SS_LOCKLESS_MEMORY */
4412 /* ss006.301 : optimized this function */
4413 /* ss001.301: additions */
4414 #ifdef SS_HISTOGRAM_SUPPORT
4415 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
4417 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr) != ROK)
4418 #endif /* SS_HISTOGRAM_SUPPORT */
4422 data = (Data *) (*bufPtr) + MDBSIZE;
4423 size = mdsize - MDBSIZE;
4425 dptr = (SsDblk*) (((Data *) (*bufPtr)) + MBSIZE);
4427 INITB((*bufPtr), dptr, data, size, NULLP)
4428 #ifndef SS_DBUF_REFLOCK_DISABLE
4429 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
4431 printf("Falied to destroy lock\n");
4442 * Desc: This function deallocates a buffer back to the
4443 * dynamic memory pool indicated by the caller.
4446 * RFAILED - failed, general (optional)
4448 * Notes: The dynamic memory pools are used to create and
4449 * manipulate messages.
4451 * SPutDBuf is never called by a protocol layer.
4453 * SPutDBuf assumes that interrupts are already disabled.
4459 #ifdef T2K_MEM_LEAK_DBG
4460 PUBLIC S16 SPutDBufNew
4477 PUBLIC S16 SPutDBuf(region, pool, buf)
4484 register SsDblk *dptr;
4485 /* ss021.103 - Addition to check return value of SFree */
4487 #if (defined(SS_USE_ZBC_MEMORY) && defined (TENB_DPDK_BUF))
4493 /* ss021.103 - Addition of ret initialization */
4496 #if (ERRCLASS & ERRCLS_INT_PAR)
4497 if (region >= SS_MAX_REGS)
4499 SSLOGERROR(ERRCLS_INT_PAR, ESS141, ERRZERO, "SPutDBuf:Invalid region");
4503 if (pool >= SS_MAX_POOLS_PER_REG)
4505 SSLOGERROR(ERRCLS_INT_PAR, ESS142, ERRZERO, "SPutDBuf:Invalid pool");
4511 SSLOGERROR(ERRCLS_INT_PAR, ESS143, ERRZERO, "SPutDBuf:Null pointer");
4515 if ( (buf->b_datap->db_type != SS_M_DATA) && (buf->b_datap->db_type != SS_M_PROTO))
4517 SSLOGERROR(ERRCLS_INT_PAR, ESS144, ERRZERO, "SPutDBuf:Incorrect\
4522 /* ss016.13: Addition */
4523 dptr = buf->b_datap;
4525 #ifdef SS_USE_ZBC_MEMORY
4526 if(dptr->db_type == SS_MEM_TYPE_SSI_ZBC)
4528 ret = SPutZbcDBuf(region, buf);
4532 #ifdef TENB_DPDK_BUF
4533 if(dptr->db_type == SS_MEM_TYPE_DPDK_ZBC)
4535 /* Not considering referances for DPDK buffer for now */
4536 SDetachDpdkPtrFrmDBuf(buf, &dpdkBuf);
4537 SPutSBufDpdk(dpdkBuf);
4538 ret = SFree(region, (Data *) buf, MDBSIZE);
4541 #endif /* TENB_DPDK_BUF */
4542 #endif /* SS_USE_ZBC_MEMORY */
4544 /* ss028.103 - Addition of lock for mBuf reference count */
4545 /* ss006.301 : optimized this funciton */
4549 #ifndef SS_DBUF_REFLOCK_DISABLE
4550 SDestroyLock(&dptr->dBufLock);
4552 /* if the data block is not shared, free the buffer, checks not reqd */
4553 #ifdef SS_HISTOGRAM_SUPPORT
4554 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4555 , __LINE__, (U8*) __FILE__, ENTNC);
4557 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4558 #endif /* SS_HISTOGRAM_SUPPORT */
4562 #ifndef SS_DBUF_REFLOCK_DISABLE
4563 if((ret=SLock(&dptr->dBufLock)))
4565 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
4566 "Could not lock the mBuf Ref Lock");
4571 /* if buffer's message blk is obtained during dupb */
4572 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
4575 SsDblk* dupdptr = (SsDblk *)((U8 *)buf + MBSIZE);
4577 if(dupdptr->db_ref == 0)
4580 #ifdef SS_HISTOGRAM_SUPPORT
4581 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__, ENTNC);
4583 ret = SFree(region, (Data *) buf, MDBSIZE);
4585 #endif /* SS_HISTOGRAM_SUPPORT */
4587 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
4589 /* if reference count falls to zero */
4592 #ifndef SS_DBUF_REFLOCK_DISABLE
4593 ret = SUnlock(&dptr->dBufLock) ;
4594 if((SDestroyLock(&dptr->dBufLock)) != 0)
4596 printf("Falied to destroy lock\n");
4599 /* free buffer to region */
4600 #ifdef SS_HISTOGRAM_SUPPORT
4601 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4602 , __LINE__, (U8*) __FILE__, ENTNC);
4604 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4605 #endif /* SS_HISTOGRAM_SUPPORT */
4608 #ifndef SS_DBUF_REFLOCK_DISABLE
4609 ret = SUnlock(&(dptr->dBufLock));
4612 #else /* SS_MULTICORE_SUPPORT */
4613 /* If MultiCore Support enabled, Dblk never be shared */
4614 #ifdef SS_HISTOGRAM_SUPPORT
4615 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4616 , __LINE__, (U8*) __FILE__, ENTNC);
4618 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4619 #endif /* SS_HISTOGRAM_SUPPORT */
4620 #endif /* SS_MULTICORE_SUPPORT */
4625 /* #ifdef SS_LOCKLESS_MEMORY */
4632 * Desc: This function will concatenate the two specified messages
4636 * RFAILED - failed, general (optional)
4638 * Notes: if order equal M1M2: all data attached to message 2 is
4639 * moved to the end of message 1. message 2 is set to empty.
4640 * message 1 length is increased by length of message 2.
4641 * message 2 length is set to zero. message 2 is not returned
4642 * to memory. return is ok.
4644 * if order equal M2M1: all data attached to message 2 is
4645 * moved to the front of message 1. message 2 is set to empty.
4646 * message 1 length is increased by length of message 2.
4647 * message 2 length is set to zero. message 2 is not returned
4648 * to memory. return is ok.
4658 Buffer *mBuf1, /* message 1 */
4659 Buffer *mBuf2, /* message 2 */
4663 PUBLIC S16 SCatMsg(mBuf1, mBuf2, order)
4664 Buffer *mBuf1; /* message 1 */
4665 Buffer *mBuf2; /* message 2 */
4666 Order order; /* order */
4676 #if (ERRCLASS & ERRCLS_INT_PAR)
4677 /* check message buffer 1 */
4680 SSLOGERROR(ERRCLS_INT_PAR, ESS148, ERRZERO, "SCatMsg : Null Buffer");
4683 /* check message buffer 2 */
4686 SSLOGERROR(ERRCLS_INT_PAR, ESS149, ERRZERO, "SCatMsg : Null Buffer");
4689 /* ss021.103 - Addition to test if same buffer */
4690 /* check message buffer 1 and 2 not same buffer */
4693 SSLOGERROR(ERRCLS_INT_PAR, ESS150, ERRZERO, "SCatMsg : mBuf1 == mBuf2");
4696 if ((order != M1M2) && (order != M2M1))
4698 SSLOGERROR(ERRCLS_INT_PAR, ESS151, ERRZERO, "SCatMsg : Invalid Order");
4701 if ((mBuf1->b_datap->db_type != SS_M_PROTO) ||
4702 (mBuf2->b_datap->db_type != SS_M_PROTO))
4704 SSLOGERROR(ERRCLS_INT_PAR, ESS152, ERRZERO,
4705 "SCatMsg : Incorrect buffer type");
4710 /* no data to append or prepend */
4714 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
4715 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
4717 /* ss021.103 - Addition to test max length of message is not exceeded */
4718 #if (ERRCLASS & ERRCLS_INT_PAR)
4720 if (minfo1->len > 0x7FFFFFFF - minfo2->len)
4722 if (minfo1->len > 0x7FFF - minfo2->len)
4725 SSLOGERROR(ERRCLS_INT_PAR, ESS153, ERRZERO, "SCpyFixMsg : messages too big");
4730 if (minfo1->region != minfo2->region)
4732 /* duplicate mBuf2 from the region/pool of mBuf1, initialise mBuf2 */
4733 /*ss015.13: addition */
4734 if (SCpyMsgMsg(mBuf2, minfo1->region, minfo1->pool, &newb) != ROK)
4737 minfo2 = (SsMsgInfo*) newb->b_rptr;
4742 if ((tmp = mBuf1->b_cont) == NULLP)
4744 mBuf1->b_cont = newb->b_cont;
4745 minfo1->endptr = minfo2->endptr;
4750 /* attach newb after mBuf1 */
4752 minfo1->endptr->b_cont = newb->b_cont;
4753 minfo1->endptr = minfo2->endptr;
4758 /* attach newb before mBuf1 */
4760 minfo2->endptr->b_cont = mBuf1->b_cont;
4761 mBuf1->b_cont = newb->b_cont;
4763 else /* invalid order */
4765 #if (ERRCLASS & ERRCLS_DEBUG)
4766 SSLOGERROR(ERRCLS_DEBUG, ESS154, ERRZERO, "SCatMsg:Invalid order");
4768 if (newb && (newb != mBuf2))
4769 (Void) SPutMsg(newb);
4774 minfo1->len += minfo2->len;
4777 minfo2->endptr = NULLP;
4780 newb->b_cont = NULLP;
4784 (Void) SPutMsg(newb);
4785 (Void) SInitMsg(mBuf2);
4795 * Desc: This function replaces one byte of data in a message.
4798 * ROKDNA - ok, data not available
4799 * RFAILED - failed, general (optional)
4801 * Notes: index is 0 based and indicates location in message
4803 * if index is less than the length of the message:
4804 * data is replaced at specified index. message length
4805 * is unchanged. return is ok.
4807 * if index is greater than or equal to
4808 * the length of the message: message is unchanged.
4809 * return is ok, data not available.
4819 Data data, /* data */
4820 Buffer *mBuf, /* message buffer */
4824 PUBLIC S16 SRepMsg(data, mBuf, idx)
4825 Data data; /* data */
4826 Buffer *mBuf; /* message buffer */
4827 MsgLen idx; /* index */
4838 #ifdef T2K_MEM_LEAK_DBG
4839 char* file = __FILE__;
4840 U32 line = __LINE__;
4842 #if ( ERRCLASS & ERRCLS_INT_PAR)
4843 /* check message buffer */
4846 SSLOGERROR(ERRCLS_INT_PAR, ESS155, ERRZERO, "SRepMsg : Null Buffer");
4851 SSLOGERROR(ERRCLS_INT_PAR, ESS156, ERRZERO, "SRepMsg : Invalid index");
4854 if (mBuf->b_datap->db_type != SS_M_PROTO)
4856 SSLOGERROR(ERRCLS_INT_PAR, ESS157, ERRZERO, "SRepMsg : Incorrect buffer\
4862 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4864 /* if index > length of the buffer */
4865 if (minfo->len <= idx)
4870 tmp = mBuf->b_cont; /* get the first SS_M_DATA blk */
4871 prev = mBuf; /* parent */
4873 FIND_OFFSET_AND_PREV(prev, tmp, idx)
4875 /* if ref cnt is greater than 1, duplicate tmp */
4876 if (tmp->b_datap->db_ref > 1)
4878 /* allocate a message blk of message size of tmp */
4879 numBytes = tmp->b_wptr - tmp->b_rptr;
4880 if (ssGetDBufOfSize(minfo->region, numBytes, &newb) != ROK)
4882 SSLOGERROR(ERRCLS_DEBUG, ESS158, ERRZERO, "SRepMsg : ssGetDBufOfSize\
4887 *newb->b_wptr++ = *tmp->b_rptr++;
4889 newb->b_cont = tmp->b_cont;
4890 prev->b_cont = newb;
4891 if (minfo->endptr == tmp)
4892 minfo->endptr = newb;
4895 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
4898 *(tmp->b_rptr + idx) = data;
4907 * Desc: Update a message with a new dBuf
4921 Buffer *mBuf, /* message buffer */
4922 Buffer *dBuf, /* data buffer */
4926 PUBLIC S16 SUpdMsg(mBuf, dBuf, dLen)
4927 Buffer *mBuf; /* message buffer */
4928 Buffer *dBuf; /* data buffer */
4929 MsgLen dLen; /* data length */
4936 #if (ERRCLASS & ERRCLS_INT_PAR)
4939 SSLOGERROR(ERRCLS_INT_PAR, ESS159, ERRZERO, "SUpdMsg : Null Buffer");
4944 SSLOGERROR(ERRCLS_INT_PAR, ESS160, ERRZERO, "SUpdMsg : Null Buffer");
4949 SSLOGERROR(ERRCLS_INT_PAR, ESS161, ERRZERO, "SUpdMsg : Invalid length");
4952 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4953 (dBuf->b_datap->db_type != SS_M_DATA))
4955 SSLOGERROR(ERRCLS_INT_PAR, ESS162, ERRZERO, "SUpdMsg : Incorrect buffer\
4961 /* get the message info of mBuf */
4962 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4964 /* accept zero length data */
4966 /* buffer offset out of bounds */
4967 if ((dBuf->b_rptr + dLen) > dBuf->b_datap->db_lim)
4969 SSLOGERROR(ERRCLS_DEBUG, ESS163, ERRZERO, "SUpdMsg:Offset out of bounds");
4973 /* offset write ptr from read ptr by dLen */
4974 dBuf->b_wptr = dBuf->b_rptr + dLen;
4976 /* attach dBuf at the end of mBuf */
4978 minfo->endptr->b_cont = dBuf;
4980 mBuf->b_cont = dBuf;
4982 /* update SsMsgInfo */
4983 minfo->endptr = dBuf;
4994 * Desc: This function queues a data buffer to the
4995 * back of the specified message buffer .
4998 * RFAILED - failed, general (optional)
5000 * Notes: if queue is empty: buffer is placed in the queue.
5001 * queue length is incremented.
5003 * if queue is not empty: buffer is placed behind all
5004 * other buffers in queue. queue length is incremented.
5012 PUBLIC S16 SAddDBufPst
5014 Buffer *mBuf, /* message buffer */
5018 PUBLIC S16 SAddDBufPst(mBuf, dBuf)
5019 Buffer *mBuf; /* message buffer */
5020 Buffer *dBuf; /* data buffer */
5027 #if (ERRCLASS & ERRCLS_INT_PAR)
5028 /* check buffer queue */
5031 SSLOGERROR(ERRCLS_INT_PAR, ESS164, ERRZERO, "SAddDBufPst : Null Buffer");
5034 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
5035 (dBuf->b_datap->db_type != SS_M_DATA))
5037 SSLOGERROR(ERRCLS_INT_PAR, ESS165, ERRZERO, "SAddDBufPst : Incorrect\
5043 /* no data, return */
5044 if (dBuf->b_wptr == dBuf->b_rptr)
5047 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5049 /* attach dBuf at the end of mBuf */
5051 minfo->endptr->b_cont = dBuf;
5053 mBuf->b_cont = dBuf;
5055 /* update SsMsgInfo */
5056 minfo->endptr = dBuf;
5058 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
5067 * Desc: This function queues a data buffer to the
5068 * front of the specified message buffer.
5071 * RFAILED - failed, general (optional)
5073 * Notes: if buffer queue is empty: buffer is placed in the queue. queue
5074 * length is incremented.
5076 * if buffer queue is not empty: buffer is placed in front of all
5077 * other buffers in queue. queue length is incremented.
5085 PUBLIC S16 SAddDBufPre
5087 Buffer *mBuf, /* message buffer */
5091 PUBLIC S16 SAddDBufPre(mBuf, dBuf)
5092 Buffer *mBuf; /* message buffer */
5093 Buffer *dBuf; /* data buffer */
5101 #if (ERRCLASS & ERRCLS_INT_PAR)
5102 /* check buffer queue */
5105 SSLOGERROR(ERRCLS_INT_PAR, ESS166, ERRZERO, "SAddDBufPre : Null Buffer");
5108 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
5109 (dBuf->b_datap->db_type != SS_M_DATA))
5111 SSLOGERROR(ERRCLS_INT_PAR, ESS167, ERRZERO, "SAddDBufPre : Incorrect\
5117 /* no data, return */
5118 if (dBuf->b_wptr == dBuf->b_rptr)
5121 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5125 /* attach dBuf at the start of mBuf */
5126 mBuf->b_cont = dBuf;
5129 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
5132 minfo->endptr = dBuf;
5141 * Desc: This function dequeues a data buffer from
5142 * the front of the specified message buffer.
5145 * ROKDNA - ok, data not available
5146 * RFAILED - failed, general (optional)
5148 * Notes: if queue is empty: pointer to buffer is set to null and
5149 * return is ok, data not available. queue length is unchanged.
5151 * if queue is not empty: pointer to buffer is set to first
5152 * buffer in queue, first buffer in queue is removed and
5153 * return is ok. queue length is decremented.
5161 PUBLIC S16 SRemDBufPre
5163 Buffer *mBuf, /* message buffer */
5167 PUBLIC S16 SRemDBufPre(mBuf, dBufPtr)
5168 Buffer *mBuf; /* message buffer */
5169 Buffer **dBufPtr; /* pointer to data buffer */
5176 #if (ERRCLASS & ERRCLS_INT_PAR)
5177 /* check buffer pointer */
5178 if (dBufPtr == NULLP)
5180 SSLOGERROR(ERRCLS_INT_PAR, ESS168, ERRZERO, "SRemDBufPre : Null Buffer");
5186 SSLOGERROR(ERRCLS_INT_PAR, ESS169, ERRZERO, "SRemDBufPre : Null Buffer");
5189 if (mBuf->b_datap->db_type != SS_M_PROTO)
5191 SSLOGERROR(ERRCLS_INT_PAR, ESS170, ERRZERO, "SRemDBufPre : Incorrect\
5197 /* no data blk, return */
5198 if ((*dBufPtr = mBuf->b_cont) == NULLP)
5202 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5204 mBuf->b_cont = (*dBufPtr)->b_cont;
5205 (*dBufPtr)->b_cont = NULLP;
5207 /* update SsMsgInfo */
5208 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
5209 minfo->endptr = NULLP;
5218 * Desc: This function dequeues a data or message buffer from the
5219 * back of the specified message buffer.
5222 * ROKDNA - ok, data not available
5223 * RFAILED - failed, general (optional)
5225 * Notes: if queue is empty: pointer to buffer is set to null and
5226 * return is ok, data not available. queue length is unchanged.
5228 * if queue is not empty: pointer to buffer is set to last
5229 * buffer in queue, last buffer in queue is removed and
5230 * return is ok. queue length is decremented.
5238 PUBLIC S16 SRemDBufPst
5240 Buffer *mBuf, /* message buffer */
5244 PUBLIC S16 SRemDBufPst(mBuf, dBufPtr)
5245 Buffer *mBuf; /* message buffer */
5246 Buffer **dBufPtr; /* pointer to data buffer */
5254 #if (ERRCLASS & ERRCLS_INT_PAR)
5255 /* check buffer pointer */
5258 SSLOGERROR(ERRCLS_INT_PAR, ESS171, ERRZERO, "SRemDBufPst : Null Buffer");
5264 SSLOGERROR(ERRCLS_INT_PAR, ESS172, ERRZERO, "SRemDBufPst : Null Buffer");
5267 if (mBuf->b_datap->db_type != SS_M_PROTO)
5269 SSLOGERROR(ERRCLS_INT_PAR, ESS173, ERRZERO, "SRemDBufPst : Incorrect\
5275 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5277 /* no data blk, return */
5278 if ((*dBufPtr = minfo->endptr) == NULLP)
5282 for (tmp = mBuf; tmp->b_cont != (*dBufPtr); )
5285 tmp->b_cont = NULLP;
5287 /* update SsMsgInfo */
5288 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
5289 minfo->endptr = NULLP;
5291 minfo->endptr = tmp;
5300 * Desc: Initialize next Data Buffer Id
5304 * Notes: Must be called prior to SGetNxtDBuf
5312 PUBLIC S16 SInitNxtDBuf
5317 PUBLIC S16 SInitNxtDBuf(mBuf)
5318 Buffer *mBuf; /* message buffer */
5325 #if (ERRCLASS & ERRCLS_INT_PAR)
5328 SSLOGERROR(ERRCLS_INT_PAR, ESS174, ERRZERO, "SInitNxtDBuf : Null Buffer");
5331 if (mBuf->b_datap->db_type != SS_M_PROTO)
5333 SSLOGERROR(ERRCLS_INT_PAR, ESS175, ERRZERO, "SInitNxtDBuf : Incorrect\
5339 minfo = (SsMsgInfo*) mBuf->b_rptr;
5341 /* set the next ptr of mBuf to point to the first SS_M_DATA blk */
5342 minfo->next = mBuf->b_cont;
5351 * Desc: Get next dBuf in message chain
5355 * Notes: Must be called after SInitNxtDBuf
5363 PUBLIC S16 SGetNxtDBuf
5365 Buffer *mBuf, /* message buffer */
5369 PUBLIC S16 SGetNxtDBuf(mBuf, dBuf)
5370 Buffer *mBuf; /* message buffer */
5371 Buffer **dBuf; /* data buffer return */
5378 #if (ERRCLASS & ERRCLS_INT_PAR)
5381 SSLOGERROR(ERRCLS_INT_PAR, ESS176, ERRZERO, "SGetNxtDBuf : Null Buffer");
5386 SSLOGERROR(ERRCLS_INT_PAR, ESS177, ERRZERO, "SGetNxtDBuf : Null Buffer");
5389 if (mBuf->b_datap->db_type != SS_M_PROTO)
5391 SSLOGERROR(ERRCLS_INT_PAR, ESS178, ERRZERO, "SGetNxtDBuf : Incorrect\
5397 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5399 /* if next ptr of mBuf is NULLP, return */
5400 if ((*dBuf = minfo->next) == NULLP)
5404 minfo->next = (*dBuf)->b_cont;
5413 * Desc: check if next data buffer exists.
5415 * Ret: ROK/ROKDNA/RFAILED
5417 * Notes: doesn't modify nxtDBuf
5424 PUBLIC S16 SChkNxtDBuf
5429 PUBLIC S16 SChkNxtDBuf(mBuf)
5430 Buffer *mBuf; /* message buffer */
5437 #if (ERRCLASS & ERRCLS_INT_PAR)
5440 SSLOGERROR(ERRCLS_INT_PAR, ESS179, ERRZERO, "SChkNxtDBuf : Null Buffer");
5443 if (mBuf->b_datap->db_type != SS_M_PROTO)
5445 SSLOGERROR(ERRCLS_INT_PAR, ESS180, ERRZERO, "SChkNxtDBuf : Incorrect\
5449 #endif /* ERRCLASS */
5451 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5453 /* if next is valid, return ROK */
5464 * Desc: Given a data buffer, return a pointer to the
5465 * data payload, and the length of the payload
5471 * Notes: This assumes an uninitialized dBuf
5479 PUBLIC S16 SGetDataRx
5481 Buffer *dBuf, /* data buffer */
5482 MsgLen pad, /* pad */
5483 Data **retDatPtr, /* return data pointer */
5487 PUBLIC S16 SGetDataRx(dBuf, pad, retDatPtr, retDatLen)
5488 Buffer *dBuf; /* data buffer */
5489 MsgLen pad; /* pad */
5490 Data **retDatPtr; /* return data pointer */
5491 MsgLen *retDatLen; /* return data length */
5496 #if (ERRCLASS & ERRCLS_INT_PAR)
5499 SSLOGERROR(ERRCLS_INT_PAR, ESS181, ERRZERO, "SGetDataRx : Null Buffer");
5502 if (!retDatLen || (pad < 0))
5504 SSLOGERROR(ERRCLS_INT_PAR, ESS182, ERRZERO, "SGetDataRx : Null Buffer");
5509 SSLOGERROR(ERRCLS_INT_PAR, ESS183, ERRZERO, "SGetDataRx : Null Buffer");
5512 if (dBuf->b_datap->db_type != SS_M_DATA)
5514 SSLOGERROR(ERRCLS_INT_PAR, ESS184, ERRZERO, "SGetDataRx : Incorrect\
5518 #endif /* ERRCLASS */
5520 if (dBuf->b_datap->db_ref > 1) /* cannot write to a shared buffer */
5522 #if (ERRCLASS & ERRCLS_DEBUG)
5523 SSLOGERROR(ERRCLS_DEBUG, ESS185, ERRZERO, "SGetDataRx : Reference\
5529 /* return the write ptr loc(with padding) if there is data to write to */
5530 if ((*retDatLen = (dBuf->b_datap->db_lim - dBuf->b_wptr - pad)) > 0)
5531 *retDatPtr = dBuf->b_wptr + pad;
5535 #if (ERRCLASS & ERRCLS_DEBUG)
5536 SSLOGERROR(ERRCLS_DEBUG, ESS186, ERRZERO, "SGetDataRx:No data available");
5548 * Desc: Given a data buffer, return a pointer to the
5549 * data payload, and the length of the payload
5555 * Notes: This assumes an initialized dBuf
5563 PUBLIC S16 SGetDataTx
5565 Buffer *dBuf, /* data buffer */
5566 Data **retDatPtr, /* return data pointer */
5567 MsgLen *retDatLen /* return data length */
5570 PUBLIC S16 SGetDataTx(dBuf, retDatPtr, retDatLen)
5571 Buffer *dBuf; /* data buffer */
5572 Data **retDatPtr; /* return data pointer */
5573 MsgLen *retDatLen; /* return data length */
5578 #if (ERRCLASS & ERRCLS_INT_PAR)
5579 /* ss021.103 - Modification to check parameters */
5582 SSLOGERROR(ERRCLS_INT_PAR, ESS187, ERRZERO, "SGetDataTx : Null Buffer");
5587 SSLOGERROR(ERRCLS_INT_PAR, ESS188, ERRZERO, "SGetDataTx : Null Buffer");
5588 *retDatPtr = (Data *)NULLP;
5593 SSLOGERROR(ERRCLS_INT_PAR, ESS189, ERRZERO, "SGetDataTx : Null Buffer");
5596 if (dBuf->b_datap->db_type != SS_M_DATA)
5598 SSLOGERROR(ERRCLS_INT_PAR, ESS190, ERRZERO, "SGetDataTx : Incorrect\
5600 *retDatPtr = (Data *)NULLP;
5603 #endif /* ERRCLASS */
5605 /* if there is data, return read ptr */
5606 if ((*retDatLen = dBuf->b_wptr - dBuf->b_rptr))
5607 *retDatPtr = dBuf->b_rptr;
5611 #if (ERRCLASS & ERRCLS_DEBUG)
5612 SSLOGERROR(ERRCLS_DEBUG, ESS191, ERRZERO, "SGetDataTx : Buffer empty");
5620 #ifndef SS_ENABLE_MACROS
5624 * Fun: SGetBufRegionPool
5626 * Desc: returns the region and pool of the message buffer
5628 * Ret: ROK on success
5637 PUBLIC S16 SGetBufRegionPool
5639 Buffer *mBuf, /* message buffer */
5640 Region *region, /* region */
5641 Pool *pool /* pool */
5644 PUBLIC S16 SGetBufRegionPool(mBuf, region, pool)
5645 Buffer *mBuf; /* message buffer */
5646 Region *region; /* region */
5647 Pool *pool; /* pool */
5650 SsMsgInfo *mInfo; /* message info pointer */
5652 TRC1(SGetBufRegionPool)
5654 #if (ERRCLASS & ERRCLS_INT_PAR)
5658 SSLOGERROR(ERRCLS_INT_PAR, ESS192, ERRZERO,
5659 "SGetBufRegionPool : Null Buffer");
5662 if ((region == NULLP) && (pool == NULLP))
5664 SSLOGERROR(ERRCLS_INT_PAR, ESS193, ERRZERO,
5665 "SGetBufRegionPool : Null region and pool pointers");
5668 if (mBuf->b_datap->db_type != SS_M_PROTO)
5670 SSLOGERROR(ERRCLS_INT_PAR, ESS194, ERRZERO,
5671 "SUpdMsg : Incorrect buffer type");
5674 #endif /* (ERRCLASS & ERRCLS_INT_PAR */
5676 /* get message info of mBuf */
5677 if ((mInfo = (SsMsgInfo *) mBuf->b_rptr) == NULLP)
5679 #if (ERRCLASS & ERRCLS_DEBUG)
5680 SSLOGERROR(ERRCLS_DEBUG, ESS195, ERRZERO,
5681 "SGetBufRegionPool : mBuf's control data is null");
5686 if (region != NULLP)
5687 *region = mInfo->region;
5689 *pool = mInfo->pool;
5692 } /* end of SGetBufRegionPool */
5694 #endif /* SS_ENABLE_MACROS */
5700 * Desc: This function is used to compress a message into
5701 * the minimum number of data buffers needed.
5704 * RFAILED - failed, general (optional)
5705 * ROUTRES - failed, out of resources (optional)
5715 PUBLIC S16 SCompressMsg
5720 PUBLIC S16 SCompressMsg(mBuf)
5721 Buffer *mBuf; /* message buffer */
5731 #ifdef T2K_MEM_LEAK_DBG
5732 char* file = __FILE__;
5733 U32 line = __LINE__;
5737 #if (ERRCLASS & ERRCLS_INT_PAR)
5740 SSLOGERROR(ERRCLS_INT_PAR, ESS196, ERRZERO, "SCompressMsg : Null Buffer");
5743 if (mBuf->b_datap->db_type != SS_M_PROTO)
5745 SSLOGERROR(ERRCLS_INT_PAR, ESS197, ERRZERO, "SCompressMsg : Incorrect\
5751 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5753 if ((tmp = mBuf->b_cont) == minfo->endptr)
5758 /* allocate a data buffer of size bytes*/
5759 if ((ret = ssGetDBufOfSize(minfo->region, minfo->len, &dBuf)) != ROK)
5761 SSLOGERROR(ERRCLS_DEBUG, ESS198, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
5765 dBuf->b_datap->db_type = SS_M_DATA;
5769 /* determine number of bytes to be copied */
5770 numBytes = tmp->b_wptr - tmp->b_rptr;
5774 /* ss002.13: addition */
5775 /* ss003.13: addition */
5776 SMemCpy( (Void *)dBuf->b_wptr, (Void *)tmp->b_rptr, (size_t)numBytes);
5778 dBuf->b_wptr += numBytes;
5779 tmp->b_rptr += numBytes;
5783 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
5786 /* update mBuf and SsMsgInfo */
5787 mBuf->b_cont = dBuf;
5788 minfo->endptr = dBuf;
5797 * Desc: This function prints the contents of a message. The
5798 * following information is printed: queue length,
5799 * message length, direction, hexadecimal and ASCII
5800 * (if appropriate) values of all bytes in the message.
5802 * This function should be used for debugging only.
5815 Buffer *mBuf, /* message buffer */
5816 S16 src, /* source id */
5817 S16 dst /* destination id */
5820 PUBLIC S16 SPrntMsg(mBuf, src, dst)
5821 Buffer *mBuf; /* message buffer */
5822 S16 src; /* source id */
5823 S16 dst; /* destination id */
5826 QLen qlen; /* queue length */
5827 MsgLen mlen; /* message length */
5831 /* ss038.103 : 102061 Changed to MsgLen from S16 */
5832 MsgLen i; /* counter */
5833 S16 j; /* counter */
5834 S16 k; /* counter */
5836 U8 tdata[16] = {0}; /* temporary data */
5837 S8 prntBuf[256]; /* print buffer */
5838 Buffer *tmp; /* buffer ptr */
5840 /* ss012.13: Addition */
5848 sprintf(prntBuf,"\nmsg: empty\n");
5850 SPrint( (S8*)"\n\n");
5854 for (qlen = 0, tmp = mBuf->b_cont; tmp; qlen++)
5856 mlen = ((SsMsgInfo*)(mBuf->b_rptr))->len;
5857 reg = ((SsMsgInfo*)(mBuf->b_rptr))->region;
5858 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
5859 sprintf(prntBuf,"\nmsg: qlen: %04d mlen: %04d %02d-->%02d region: %02d\n",
5860 (U16)qlen,(U16)mlen,src,dst,reg);
5862 #ifdef XEON_SPECIFIC_CHANGES
5863 printf("%s\n", prntBuf);
5865 SPrint((S8*) "dat: ");
5866 #ifdef XEON_SPECIFIC_CHANGES
5872 sprintf(prntBuf," empty\n");
5874 SPrint( (S8*)"\n\n");
5884 for( j = 0; j < 16; j++)
5890 sprintf( prntBuf,"%02x ",(U16) data);
5892 #ifdef XEON_SPECIFIC_CHANGES
5893 printf("%s\n", prntBuf);
5895 if (cptr == tmp->b_wptr)
5901 /* ss024.103 - Modification to fix bug */
5908 sprintf( prntBuf," ");
5910 #ifdef XEON_SPECIFIC_CHANGES
5911 printf("%s\n", prntBuf);
5915 for (k = 0; k < 16; k++)
5917 if( (i >= mlen) && (k>=(mlen%16)) && mlen%16 != 0)
5919 if (AIsAscii(tdata[k]))
5921 /* print character if printable */
5922 sprintf(prntBuf,"%c",tdata[k]);
5924 #ifdef XEON_SPECIFIC_CHANGES
5925 printf("%s\n", prntBuf);
5930 /* print . if non printable */
5932 #ifdef XEON_SPECIFIC_CHANGES
5937 sprintf(prntBuf,"\n ");
5939 #ifdef XEON_SPECIFIC_CHANGES
5940 printf("%s\n", prntBuf);
5945 } /* end of SPrntMsg */
5951 * Fun: SGetPstMsgMult
5953 * Desc: This function allocates consecutive bytes of data at the
5957 * RFAILED - failed, general (optional)
5958 * ROUTRES - failed, out of resources (optional)
5960 * Notes: if message is empty: message length is incremented.
5963 * if message is not empty: space is allocated in back of
5964 * all other data in message. message length is incremented.
5971 PUBLIC S16 SGetPstMsgMult
5973 MsgLen cnt, /* count */
5974 Buffer *mBuf /* message buffer */
5977 PUBLIC S16 SGetPstMsgMult(cnt, mBuf)
5978 MsgLen cnt; /* count */
5979 Buffer *mBuf; /* message buffer */
5989 char* file = __FILE__;
5990 U32 line = __LINE__;
5992 TRC1(SGetPstMsgMult)
5994 #if ( ERRCLASS & ERRCLS_INT_PAR )
5995 /* check message buffer */
6005 if (mBuf->b_datap->db_type != SS_M_PROTO)
6010 /* get the message info */
6011 minfo = (SsMsgInfo *) (mBuf->b_rptr);
6016 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
6017 ((avail = tmp->b_datap->db_lim - tmp->b_wptr)))
6019 numBytes = MIN(cnt, avail);
6022 minfo->len += numBytes;
6025 /* ss002.13 addition */
6026 /* ss003.13 addition */
6027 SMemSet( (Void *)tmp->b_wptr, (Data)'\0', (size_t)numBytes);
6029 tmp->b_wptr += numBytes;
6033 if (ssGetDBufOfSize(minfo->region, cnt, &newb) != ROK)
6035 /* ss027.103 - Modification to fix bug in SGetPstMsgMult */
6036 if ((avail) && (tmp))
6037 tmp->b_wptr = tmp->b_datap->db_lim - avail;
6038 minfo->len -= avail;
6045 /* ss002.13: addition */
6046 /* ss003.13: addition */
6047 SMemSet( (Void *)newb->b_wptr, (Data)'\0', (size_t)cnt);
6049 newb->b_wptr += cnt;
6055 mBuf->b_cont = newb;
6057 minfo->endptr = newb;
6066 * Desc: Check Message
6068 * Ret: ROK on success
6071 * Notes: Check that the first buffer in a message
6072 * contains at least two bytes. This check is required
6073 * by 68302/68360 processors to insure accurate fisu
6085 PUBLIC S16 SChkMsg(mBuf)
6094 #if ( ERRCLASS & ERRCLS_INT_PAR )
6095 /* check message buffer */
6100 if (mBuf->b_datap->db_type != SS_M_PROTO)
6105 /* get the message info */
6106 minfo = (SsMsgInfo *) (mBuf->b_rptr);
6111 /* get the first M_DATA blk*/
6114 if (((tmp->b_rptr + 2) <= tmp->b_wptr) || (SCompressMsg(mBuf) == ROK))
6122 * Fun: SAlignDBufEven
6124 * Desc: align data portion of a data buffer on an even
6129 * Notes: required for SS7 microcode on the 68302
6135 PUBLIC S16 SAlignDBufEven
6137 Buffer *dBuf /* data buffer */
6140 PUBLIC S16 SAlignDBufEven(dBuf)
6141 Buffer *dBuf; /* data buffer */
6147 TRC1(SAlignDBufEven)
6149 #if (ERRCLASS & ERRCLS_INT_PAR)
6152 SSLOGERROR(ERRCLS_INT_PAR, ESS199, ERRZERO, "SAlignDBufEven : Null\
6156 if (dBuf->b_datap->db_type != SS_M_DATA)
6158 SSLOGERROR(ERRCLS_INT_PAR, ESS200, ERRZERO, "SAlignDBufEven : Incorrect\
6165 /* ss008.13: addition */
6166 if (!((PTR)src % (PTR)2))
6169 if (dBuf->b_datap->db_ref > 1)
6172 len = dBuf->b_wptr - dBuf->b_rptr;
6174 if (dBuf->b_datap->db_base < dBuf->b_rptr)
6176 dBuf->b_wptr = --dBuf->b_rptr;
6178 *dBuf->b_wptr++ = *src++;
6181 if (dBuf->b_datap->db_lim > dBuf->b_wptr)
6183 src = dBuf->b_wptr - 1;
6184 dBuf->b_rptr = ++dBuf->b_wptr;
6186 *--dBuf->b_rptr = *src--;
6194 /* ss004.13: addition */
6199 * Desc: Align data portion of a data buffer on the specified
6200 * boundary. No restriction is imposed on the alignment.
6204 * Notes: required by drivers (68360, 860)
6210 PUBLIC S16 SAlignDBuf
6212 Buffer *dBuf, /* data buffer */
6213 U32 align /* alignemnt required */
6216 PUBLIC S16 SAlignDBuf(dBuf, align)
6217 Buffer *dBuf; /* data buffer */
6218 U32 align; /* alignemnt required */
6223 U32 upShift; /* no. of bytes to be shifted up */
6224 U32 downShift; /* no. of bytes to be shifted down */
6228 #if (ERRCLASS & ERRCLS_INT_PAR)
6231 SSLOGERROR(ERRCLS_INT_PAR, ESS201, ERRZERO, "SAlignDBuf: Null\
6235 if (dBuf->b_datap->db_type != SS_M_DATA)
6237 SSLOGERROR(ERRCLS_INT_PAR, ESS202, ERRZERO, "SAlignDBuf: Incorrect\
6244 /* ss008.13: addition */
6245 upShift = (PTR)src % (PTR)align; /* no. of bytes by which to shift up
6246 * the read and write pointers */
6251 if (dBuf->b_datap->db_ref > 1)
6254 downShift = align - upShift; /* no of bytes by which to shift down
6255 * the read and write pointers */
6256 len = dBuf->b_wptr - dBuf->b_rptr;
6258 if (dBuf->b_datap->db_base <= (dBuf->b_rptr - upShift))
6260 /* there is space to shift up the read and write pointers */
6262 dBuf->b_rptr -= upShift; /* align the read pointer */
6263 dBuf->b_wptr = dBuf->b_rptr;
6264 SMemCpy( (Void *) dBuf->b_wptr, (Void *) src, (size_t) len);
6265 dBuf->b_wptr = dBuf->b_wptr + len;
6269 if (dBuf->b_datap->db_lim > dBuf->b_wptr + downShift)
6271 src = dBuf->b_wptr - 1;
6272 dBuf->b_wptr = dBuf->b_wptr + downShift;
6273 dBuf->b_rptr = dBuf->b_wptr;
6275 *--dBuf->b_rptr = *src--;
6289 * Desc: Allocates a static buffer pool within the specified
6293 * RFAILED - failed, general (optional)
6295 * Notes: The new memory management scheme makes this function
6296 * meaningless. It merely sets the pool ID to zero and
6305 Region region, /* region ID */
6306 Size size, /* size */
6307 Pool *pool /* pointer to pool ID */
6310 PUBLIC S16 SGetSMem(region, size, pool)
6311 Region region; /* region ID */
6312 Size size; /* size */
6313 Pool *pool; /* pointer to pool ID */
6322 #if (ERRCLASS & ERRCLS_INT_PAR)
6323 /* validate region ID */
6324 if (region >= SS_MAX_REGS)
6326 SSLOGERROR(ERRCLS_INT_PAR, ESS203, region, "Invalid region");
6330 /* validate pointer to pool ID */
6333 SSLOGERROR(ERRCLS_INT_PAR, ESS204, region, "Null pointer");
6339 /* set the pool ID to zero and return success */
6351 * Desc: Deallocates a static buffer pool within the specified
6355 * RFAILED - failed, general (optional)
6357 * Notes: The new memory management scheme makes this function
6358 * meaningless. It does nothing.
6366 Region region, /* region ID */
6367 Pool pool /* pool ID */
6370 PUBLIC S16 SPutSMem(region, pool)
6371 Region region; /* region ID */
6372 Pool pool; /* pool ID */
6375 /* ss021.103 - Addition of return value */
6376 #if (ERRCLASS & ERRCLS_INT_PAR)
6383 #if (ERRCLASS & ERRCLS_INT_PAR)
6384 /* validate region ID */
6385 if (region >= SS_MAX_REGS)
6387 SSLOGERROR(ERRCLS_INT_PAR, ESS205, region, "Invalid region");
6391 /* validate pool ID */
6392 if (pool >= SS_MAX_POOLS_PER_REG)
6394 SSLOGERROR(ERRCLS_INT_PAR, ESS206, region, "Invalid pool");
6398 /* ss021.103 - Addition to check if region is registered */
6399 /* acquire one semaphore, to protect against deregistration */
6400 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
6404 #if (ERRCLASS & ERRCLS_DEBUG)
6405 SSLOGERROR(ERRCLS_DEBUG, ESS207, (ErrVal) ret,
6406 "Could not lock region table");
6413 #if (ERRCLASS & ERRCLS_INT_PAR)
6414 /* verify that this region is present */
6415 if (osCp.regionTbl[region].used == FALSE)
6417 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6419 #if (ERRCLASS & ERRCLS_DEBUG)
6420 SSLOGERROR(ERRCLS_DEBUG, ESS208, ERRZERO,
6421 "Could not release semaphore");
6426 SSLOGERROR(ERRCLS_INT_PAR, ESS209, region, "Region not registered");
6431 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6433 #if (ERRCLASS & ERRCLS_DEBUG)
6434 SSLOGERROR(ERRCLS_DEBUG, ESS210, ERRZERO,
6435 "Could not release semaphore");
6449 * Desc: Checks the available system resources (memory).
6452 * RFAILED - failed, general (optional)
6462 Region region, /* region ID */
6463 Pool pool, /* pool ID */
6464 Status *status /* pointer to status */
6467 PUBLIC S16 SChkRes(region, pool, status)
6468 Region region; /* region ID */
6469 Pool pool; /* pool ID */
6470 Status *status; /* pointer to status */
6480 #if (ERRCLASS & ERRCLS_INT_PAR)
6481 /* validate region ID */
6482 if (region >= SS_MAX_REGS)
6484 SSLOGERROR(ERRCLS_INT_PAR, ESS229, region, "Invalid region");
6488 /* validate pool ID */
6489 if (pool >= SS_MAX_POOLS_PER_REG)
6491 SSLOGERROR(ERRCLS_INT_PAR, ESS230, region, "Invalid pool");
6495 /* validate status pointer */
6496 if (status == NULLP)
6498 SSLOGERROR(ERRCLS_INT_PAR, ESS231, ERRZERO, "Null pointer");
6502 /* ss037.103 Removed the semaphore operation for performance enhancement */
6505 /* acquire one semaphore, to protect against deregistration */
6506 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
6510 #if (ERRCLASS & ERRCLS_DEBUG)
6511 SSLOGERROR(ERRCLS_DEBUG, ESS232, (ErrVal) ret,
6512 "Could not lock region table");
6519 #if (ERRCLASS & ERRCLS_INT_PAR)
6520 /* verify that this region is around */
6521 if (osCp.regionTbl[region].used == FALSE)
6524 /* ss006.13: addition */
6525 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6527 #if (ERRCLASS & ERRCLS_DEBUG)
6528 SSLOGERROR(ERRCLS_DEBUG, ESS233, ERRZERO,
6529 "Could not release semaphore");
6534 SSLOGERROR(ERRCLS_INT_PAR, ESS234, region, "Region not registered");
6538 /* verify that this is a valid pool */
6539 if (osCp.regionTbl[region].poolTbl[pool].type != SS_POOL_DYNAMIC)
6541 SSLOGERROR(ERRCLS_DEBUG, ESS235, ERRZERO, "Invalid pool");
6547 /* call the memory manager to check resources */
6548 mctl.op = SS_MEM_CHK_RES;
6549 mctl.u.chkres.size = osCp.regionTbl[region].poolTbl[pool].u.dpool.size;
6550 mctl.u.chkres.status = status;
6551 ret = (osCp.regionTbl[region].ctl)
6552 (osCp.regionTbl[region].regCb, SS_MEM_CHK_RES, &mctl);
6554 /* release the semaphore we took */
6556 /* ss006.13: addition */
6557 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6559 #if (ERRCLASS & ERRCLS_DEBUG)
6560 SSLOGERROR(ERRCLS_DEBUG, ESS236, ERRZERO,
6561 "Could not release semaphore");
6574 * Desc: This function will swap two message data contents.
6575 * The original mBuf pointers are unchanged.
6590 Buffer *mBuf1, /* message 1 */
6591 Buffer *mBuf2 /* message 2 */
6594 PUBLIC S16 SSwapMsg(mBuf1, mBuf2)
6595 Buffer *mBuf1; /* message 1 */
6596 Buffer *mBuf2; /* message 2 */
6601 #if (ERRCLASS & ERRCLS_INT_PAR)
6610 #if (ERRCLASS & ERRCLS_INT_PAR)
6611 /* check message buffer 1 */
6614 SSLOGERROR(ERRCLS_INT_PAR, ESS237, ERRZERO, "SSwapMsg : Null Buffer");
6617 /* check message buffer 2 */
6620 SSLOGERROR(ERRCLS_INT_PAR, ESS238, ERRZERO, "SSwapMsg : Null Buffer");
6623 if (mBuf1->b_datap->db_type != SS_M_PROTO)
6625 SSLOGERROR(ERRCLS_INT_PAR, ESS239, ERRZERO, "SSwapMsg: Incorrect buffer\
6629 if (mBuf2->b_datap->db_type != SS_M_PROTO)
6631 SSLOGERROR(ERRCLS_INT_PAR, ESS240, ERRZERO, "SSwapMsg: Incorrect buffer\
6635 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
6636 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
6637 if (minfo1->region != minfo2->region)
6639 SSLOGERROR(ERRCLS_INT_PAR, ESS241, ERRZERO, "SSwapMsg: differnt regions\
6646 tmp = mBuf1->b_next;
6647 mBuf1->b_next = mBuf2->b_next;
6648 mBuf2->b_next = tmp;
6650 tmp = mBuf1->b_prev;
6651 mBuf1->b_prev = mBuf2->b_prev;
6652 mBuf2->b_prev = tmp;
6654 tmp = mBuf1->b_cont;
6655 mBuf1->b_cont = mBuf2->b_cont;
6656 mBuf2->b_cont = tmp;
6659 #ifdef SS_DBLK_FREE_RTN
6660 tmp = (Buffer *) mBuf1->b_datap->db_frtnp;
6661 mBuf1->b_datap->db_frtnp = mBuf2->b_datap->db_frtnp;
6662 mBuf2->b_datap->db_frtnp = (struct ssfree_rtn *) tmp;
6665 tmp2 = mBuf1->b_datap->db_ref;
6666 mBuf1->b_datap->db_ref = mBuf2->b_datap->db_ref;
6667 mBuf2->b_datap->db_ref = tmp2;
6672 SMemCpy((Void *) minfop, (Void *) (mBuf1->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6673 SMemCpy((Void *) (mBuf1->b_datap->db_base), (Void *) (mBuf2->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6674 SMemCpy((Void *) (mBuf2->b_datap->db_base), (Void *) minfop, (size_t)(sizeof(SsMsgInfo)));
6678 /* ss004.301 : Cavium changes */
6679 #ifdef SS_SEUM_CAVIUM
6685 * Desc: This function will converts the pointer to
6689 * RFAILED - failed, general (optional)
6691 * Notes: Function to convert the Pointer (Virtual address) to
6692 * Physical Address. This will take the Buffer type as
6693 * input and will convert all pointer associated with
6694 * that to Physical Address
6700 PUBLIC S16 SConvPtrPhy
6705 PUBLIC S16 SConvPtrPhy (mBuf)
6712 SsMsgInfo *minfoPtr;
6719 /* check mBuf for NULLP */
6720 if ( (mBuf == NULLP) || (*mBuf == NULLP ) )
6725 /* first block in Buffer is head */
6727 nextPtr = curPtr->b_cont;
6729 /* Get the physical address of the Pointer */
6732 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6737 curPtr->b_next = (Buffer*)cvmx_ptr_to_phys (curPtr->b_next);
6742 curPtr->b_prev = (Buffer*)cvmx_ptr_to_phys (curPtr->b_prev);
6745 /* Convert the pointers of Minfo to Physical addr */
6746 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6748 if (minfoPtr->endptr)
6750 minfoPtr->endptr = (Buffer*)cvmx_ptr_to_phys (minfoPtr->endptr);
6754 minfoPtr->next = (Buffer*)cvmx_ptr_to_phys (minfoPtr->next);
6757 curPtr->b_rptr = (U8*)cvmx_ptr_to_phys (curPtr->b_rptr);
6759 curPtr->b_wptr = (U8*)cvmx_ptr_to_phys (curPtr->b_wptr);
6761 /* Convert the pointers of Dblock to Physical addr */
6762 dblkPtr = (SsDblk*)curPtr->b_datap;
6765 #ifdef SS_DBLK_FREE_RTN
6766 frtnPtr = dblkPtr->db_frtnp;
6767 if( frtnPtr != NULLP)
6769 if (frtnPtr->free_func)
6771 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6773 if (frtnPtr->free_arg)
6775 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6778 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6782 dblkPtr->db_base = (U8*)cvmx_ptr_to_phys (dblkPtr->db_base);
6783 dblkPtr->db_lim = (U8*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6785 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6787 /* second block onwards is dblk */
6792 nextPtr = curPtr->b_cont;
6794 /* Get the physical address of the Pointer */
6797 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6800 curPtr->b_rptr = (U8*)cvmx_ptr_to_phys (curPtr->b_rptr);
6801 curPtr->b_wptr = (U8*)cvmx_ptr_to_phys (curPtr->b_wptr);
6803 /* Convert the pointers of Dblock to Physical addr */
6804 dblkPtr = (SsDblk*)curPtr->b_datap;
6807 #ifdef SS_DBLK_FREE_RTN
6808 frtnPtr = dblkPtr->db_frtnp;
6809 if( frtnPtr != NULLP)
6811 if (frtnPtr->free_func)
6813 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6815 if (frtnPtr->free_arg)
6817 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6820 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6824 dblkPtr->db_base = (U8*)cvmx_ptr_to_phys (dblkPtr->db_base);
6825 dblkPtr->db_lim = (U8*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6827 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6833 *mBuf = (Buffer*)cvmx_ptr_to_phys (*mBuf);
6843 * Desc: This function will converts the physical address
6846 * Ret: On Success - Pointer to converted buffer
6847 * On Failuer - Returns NULL
6849 * Notes: Function to Convert the Physical address to Pointer
6850 * (Virtual address) This will take work buffer as input
6851 * and will convert all address associated with that to
6858 PUBLIC S16 SConvPhyPtr
6863 PUBLIC S16 SConvPhyPtr (workPtr)
6870 SsMsgInfo *minfoPtr;
6877 /* check workPtr for NULLP */
6878 if ( (workPtr == NULLP) || (*workPtr == NULLP) )
6883 /* Convert the buffer address to pointer */
6884 mBuf = (Buffer*)cvmx_phys_to_ptr ((U64)(*workPtr));
6888 /* first block is mblk */
6891 curPtr->b_next = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_next);
6896 curPtr->b_prev = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_prev);
6901 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_cont);
6904 curPtr->b_rptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_rptr);
6906 /* Get the pointer for minfo */
6907 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6909 if (minfoPtr->endptr)
6911 minfoPtr->endptr = (Buffer*)cvmx_phys_to_ptr ((U64)minfoPtr->endptr);
6915 minfoPtr->next = (Buffer*)cvmx_phys_to_ptr ((U64)minfoPtr->next);
6918 curPtr->b_wptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_wptr);
6920 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((U64)curPtr->b_datap);
6922 /* Get the Dblock pointers */
6923 dblkPtr = (SsDblk*)curPtr->b_datap;
6926 #ifdef SS_DBLK_FREE_RTN
6927 if (dblkPtr->db_frtnp)
6929 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((U64)dblkPtr->db_frtnp);
6930 frtnPtr = dblkPtr->db_frtnp;
6932 if (frtnPtr->free_func)
6934 frtnPtr->free_func = cvmx_phys_to_ptr ((U64)frtnPtr->free_func);
6936 if (frtnPtr->free_arg)
6938 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((U64)frtnPtr->free_arg);
6943 dblkPtr->db_base = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_base);
6944 dblkPtr->db_lim = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_lim);
6946 curPtr = curPtr->b_cont;
6948 /* after the first block is dblk */
6953 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_cont);
6956 curPtr->b_rptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_rptr);
6958 curPtr->b_wptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_wptr);
6960 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((U64)curPtr->b_datap);
6962 /* Get the Dblock pointers */
6963 dblkPtr = (SsDblk*)curPtr->b_datap;
6966 #ifdef SS_DBLK_FREE_RTN
6967 if (dblkPtr->db_frtnp)
6969 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((U64)dblkPtr->db_frtnp);
6971 frtnPtr = dblkPtr->db_frtnp;
6973 if (frtnPtr->free_func)
6975 frtnPtr->free_func = cvmx_phys_to_ptr ((U64)frtnPtr->free_func);
6977 if (frtnPtr->free_arg)
6979 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((U64)frtnPtr->free_arg);
6984 dblkPtr->db_base = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_base);
6985 dblkPtr->db_lim = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_lim);
6987 curPtr = curPtr->b_cont;
6990 /* Place the converted buffer */
7001 * Desc: This function will copy the message from FPA region
7004 * Ret: On Success - ROK
7005 * On Failuer - RFAILED
7007 * Notes: Function to copy the message from FPA region to
7008 * other region. This will internally allocates the
7009 * memory for the destination buffer and copies the
7010 * message in the same chain list
7016 PUBLIC S16 SCpyFpaMsg
7024 PUBLIC S16 SCpyFpaMsg (srcBuf, dstRegion, dstPool, dstBuf)
7035 Buffer *curPtr = NULLP;
7037 Buffer *tmpblk = NULLP;
7038 Buffer *newblk = NULLP;
7039 Buffer *prevblk = NULLP;
7040 SsMsgInfo *minfoSrc = NULLP;
7041 SsMsgInfo *minfoDst = NULLP;
7042 SsDblk *dblkPtr = NULLP;
7043 SsDblk *dptr = NULLP;
7048 if ( srcBuf == (Buffer*)NULLP )
7053 if ((dstRegion >= SS_MAX_REGS) || (dstPool >= SS_MAX_POOLS_PER_REG))
7055 /* Free the source buffer and return failure */
7060 /* Allocate memory for destination buffer */
7061 if(SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
7063 /* Free the source buffer and return failure */
7068 /* get the minfo of dest and src buffers */
7069 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
7070 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
7072 curPtr = srcBuf->b_cont;
7074 /* Copy all the blocks associated with this Buffer */
7077 /* Allocate the memeory for dblock */
7079 dblkPtr = (SsDblk*)curPtr->b_datap;
7080 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
7081 size = numBytes + MDBSIZE;
7083 ret = SAlloc( dstRegion, &size, 0, (Data**)&tmpblk);
7087 /* Free all allocated buffers before returning */
7090 tmpblk = newblk->b_cont;
7091 (Void) SPutDBuf(dstRegion, dstPool, newblk);
7094 (Void) SPutMsg(*dstBuf);
7095 /* Free the source buffer and return failure */
7100 dat = (Data *)tmpblk + MDBSIZE;
7101 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
7104 /* Initialize the pointer and copy the data */
7105 INITB( tmpblk, dptr, dat, size, NULLP );
7106 #ifndef SS_DBUF_REFLOCK_DISABLE
7107 SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX);
7109 numBytes = curPtr->b_wptr - curPtr->b_rptr;
7110 /* Copy the data part if its present */
7113 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
7114 tmpblk->b_wptr += numBytes;
7123 prevblk->b_cont = tmpblk;
7127 curPtr = curPtr->b_cont;
7132 tmpblk->b_cont = NULLP;
7135 *minfoDst = *minfoSrc;
7136 minfoDst->region = 0;
7138 minfoDst->len = minfoSrc->len;
7139 minfoDst->endptr = tmpblk;
7140 minfoDst->next = NULLP;
7142 (*dstBuf)->b_cont = newblk;
7144 /* Free the source buffer after copying it */
7155 * Desc: This function will copy the message from any region
7158 * Ret: On Success - ROK
7159 * On Failuer - RFAILED
7161 * Notes: Function will copy the mbuf from msg to FPA.
7162 * This function allocates the memory internally
7163 * and copies the message to newly allocated mBuf.
7164 * The size of mBuf should be either of one
7165 * pre-difined sizes otherwise mBuf is dopped.
7171 PUBLIC S16 SCpyMsgFpa
7177 PUBLIC S16 SCpyMsgFpa (srcBuf, dstBuf)
7183 Buffer *curPtr = NULLP;
7185 Buffer *tmpblk = NULLP;
7186 Buffer *prevblk = NULLP;
7187 Buffer *newblk = NULLP;
7188 SsMsgInfo *minfoSrc = NULLP;
7189 SsMsgInfo *minfoDst = NULLP;
7190 SsDblk *dblkPtr = NULLP;
7191 SsDblk *dptr = NULLP;
7198 if (srcBuf == (Buffer*)NULLP)
7203 *dstBuf = (Buffer*)cvmx_fpa_alloc(SS_CVMX_POOL_0);
7205 if ( *dstBuf == NULLP )
7207 /* Free the source buffer before returning */
7212 dat = (Data *)(*dstBuf) + MDBSIZE;
7213 dptr = (SsDblk*) ((Data *)(*dstBuf) + MBSIZE);
7214 numBytes = SS_CVMX_POOL_0_SIZE - MDBSIZE;
7216 /* Initialize the pointers of new block */
7217 INITB((*dstBuf), dptr, dat, numBytes, NULLP);
7219 (*dstBuf)->b_datap->db_type = SS_M_PROTO;
7220 (*dstBuf)->b_wptr = (*dstBuf)->b_rptr + sizeof(SsMsgInfo);
7222 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
7223 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
7224 curPtr = srcBuf->b_cont;
7228 dblkPtr = (SsDblk*)curPtr->b_datap;
7230 /* Get the size required which is to be allocated */
7231 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
7232 numBytes += MDBSIZE;
7234 /* get the pool depending on the size need to be allocated */
7237 case SS_CVMX_POOL_0_SIZE:
7239 pool = SS_CVMX_POOL_0;
7242 case SS_CVMX_POOL_1_SIZE:
7244 pool = SS_CVMX_POOL_1;
7247 case SS_CVMX_POOL_2_SIZE:
7249 pool = SS_CVMX_POOL_2;
7252 case SS_CVMX_POOL_3_SIZE:
7254 pool = SS_CVMX_POOL_3;
7258 /* size doesn't match, drop the mBuf and returning
7260 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SCpyMsgFpa: Invalid\
7261 buffer size, dropping the message");
7263 (*dstBuf)->b_cont = newblk;
7264 SPutFpaMsg(*dstBuf);
7265 /* Free the source buffer before returning */
7270 /* Allocate for mBuf and copy both the header and contents */
7271 tmpblk = (Buffer*)cvmx_fpa_alloc(pool);
7273 if ( tmpblk == NULLP )
7275 /* Return error if fails to allocate memory */
7277 (*dstBuf)->b_cont = newblk;
7278 SPutFpaMsg(*dstBuf);
7279 /* Free the source buffer before returning */
7284 dat = (Data *)tmpblk + MDBSIZE;
7285 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
7286 numBytes -= MDBSIZE;
7288 /* Initialize the pointers of new block */
7289 INITB( tmpblk, dptr, dat, numBytes, NULLP );
7291 numBytes = curPtr->b_wptr - curPtr->b_rptr;
7292 /* Copy the message contents */
7295 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
7296 tmpblk->b_wptr += numBytes;
7299 /* Add the mew mBuf to the Buffer chain */
7306 prevblk->b_cont = tmpblk;
7310 /* Get the next block */
7311 curPtr = curPtr->b_cont;
7314 /* Initialize the last mBuf */
7317 tmpblk->b_cont = NULLP;
7320 *minfoDst = *minfoSrc;
7321 minfoDst->region = 0;
7323 minfoDst->len = minfoSrc->len;
7324 minfoDst->endptr = tmpblk;
7325 minfoDst->next = NULLP;
7327 (*dstBuf)->b_cont = newblk;
7329 /* Free the source buffer after copying it */
7340 * Desc: This function will free the Buffer associated with
7343 * Ret: On Success - ROK
7344 * On Failuer - RFAILED
7346 * Notes: Function free the all buffer associated with wqBuf
7347 * This will get the pool id by the size of the buffer
7348 * and same will be used to free the buffer.
7354 PUBLIC S16 SPutFpaMsg
7359 PUBLIC S16 SPutFpaMsg(fpaBuf)
7370 if( fpaBuf == NULLP )
7375 curBlk = fpaBuf->b_cont;
7379 nextBlk = curBlk->b_cont;
7381 dblkPtr = (SsDblk*)curBlk->b_datap;
7383 size = dblkPtr->db_lim - dblkPtr->db_base + MDBSIZE;
7385 /* Free the dblock according to its size */
7388 case SS_CVMX_POOL_0_SIZE:
7389 cvmx_fpa_free(curBlk, SS_CVMX_POOL_0, 0);
7392 case SS_CVMX_POOL_1_SIZE:
7393 cvmx_fpa_free(curBlk, SS_CVMX_POOL_1, 0);
7396 case SS_CVMX_POOL_2_SIZE:
7397 cvmx_fpa_free(curBlk, SS_CVMX_POOL_2, 0);
7400 case SS_CVMX_POOL_3_SIZE:
7401 cvmx_fpa_free(curBlk, SS_CVMX_POOL_3, 0);
7405 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SPutFpaMsg: Invalid\
7406 buffer size, dropping the message");
7413 cvmx_fpa_free(fpaBuf, SS_CVMX_POOL_0, 0);
7419 #endif /* SS_SEUM_CAVIUM */
7421 /* ss006.301 : new buffer management APIs, start */
7426 * Desc: This function is used to copy a portion of message(srcBuf) into
7427 * another msg(dstBuf)
7430 * RFAILED - failed, general (optional)
7431 * ROUTRES - failed, out of resources (optional) - In this case
7432 * caller shall reclaim the resources allocated for dstBuf.
7441 PUBLIC S16 SCpyPartMsg
7449 PUBLIC S16 SCpyPartMsg(srcBuf, idx, cnt, dstBuf)
7467 #if (ERRCLASS & ERRCLS_INT_PAR)
7470 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null src Buffer");
7473 if (srcBuf->b_datap->db_type != SS_M_PROTO)
7475 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7481 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null dst Buffer");
7484 if (dstBuf->b_datap->db_type != SS_M_PROTO)
7486 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7490 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
7492 /* if index > length of mBuf, return */
7493 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
7494 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
7496 if (idx >= sMinfo->len)
7498 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7503 sBuf = srcBuf->b_cont;
7504 FIND_OFFSET(sBuf, idx)
7508 dBuf = (dMinfo->endptr) ? (dMinfo->endptr) : (dstBuf->b_cont);
7512 crnt = dPrev->b_cont;
7516 crnt = crnt->b_cont;
7523 sCnt = sBuf->b_wptr - (sBuf->b_rptr + idx);
7526 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
7530 /* allocate a data buffer */
7531 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
7533 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyPartMsg : SGetDBuf\
7537 dCnt = MIN(cnt, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
7538 dPrev->b_cont = dBuf;
7541 if(sCnt > cnt) /* src Dblk has enough data to copy */
7545 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7547 dBuf->b_wptr += dCnt;
7548 dBuf = dBuf->b_cont;
7554 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), cnt);
7555 dBuf->b_wptr += cnt;
7556 dBuf->b_cont = NULLP;
7562 else /* src dBlk has partial data to be copied */
7566 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7567 dBuf->b_wptr += dCnt;
7568 dBuf = dBuf->b_cont;
7575 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), sCnt);
7576 dBuf->b_wptr += sCnt;
7578 sBuf = sBuf->b_cont;
7584 /* update the msgLen in dstBuf */
7585 dMinfo->len += numCpd;
7586 dMinfo->endptr = dBuf;
7595 * Desc: This function is used to replace a portion of message(mBuf) with the
7599 * RFAILED - failed, general (optional)
7608 PUBLIC S16 SRepPartMsg
7616 PUBLIC S16 SRepPartMsg(srcBuf, idx, cnt, dstBuf)
7634 #if (ERRCLASS & ERRCLS_INT_PAR)
7637 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null dstBuf");
7640 if (dstBuf->b_datap->db_type != SS_M_PROTO)
7642 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7643 dstBuf buffer type");
7648 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null Src Buffer ");
7651 if (srcBuf->b_datap->db_type != SS_M_PROTO)
7653 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7657 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
7659 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
7660 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
7662 if(((idx + cnt) > dMinfo->len) || (cnt < sMinfo->len))
7664 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7669 dBuf = dstBuf->b_cont;
7670 FIND_OFFSET(dBuf, idx)
7671 sBuf = srcBuf->b_cont;
7673 while(cnt && dBuf && sBuf)
7675 dCnt = (dBuf->b_wptr - (dBuf->b_rptr + idx));
7676 sCnt = sBuf->b_wptr - (sBuf->b_rptr + sIdx);
7677 cpBytes = MIN(cnt, sCnt);
7678 cpBytes = MIN(cpBytes, dCnt);
7679 SMemCpy((void*)(dBuf->b_rptr + idx), (void*)(sBuf->b_rptr + sIdx), cpBytes);
7685 /* move to next DBlk in srcBuf */
7686 sBuf = sBuf->b_cont;
7690 else /* cpBytes equals dCnt */
7692 /* move to the next DBlk in dstBuf */
7693 dBuf = dBuf->b_cont;
7707 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : unable to replace\
7719 * Desc: This function will move a portion of the first msg to second msg
7722 * ROKDNA - ok, data not available
7723 * RFAILED - failed, general (optional)
7724 * ROUTRES - failed, out of resources (optional)
7726 * Notes: message 1 is the message from which the segment will be copied
7728 * message 2 is the updated message.
7730 * index is 0 based and indicates location in message 1
7731 * up to which the data will be copied to message 2
7733 * if index is equal to 0, message 1 will not be changed and no data
7734 shall be copied to message 2.
7735 * message 1 is not returned to memory. return is ok.
7737 * if index is not equal to 0 and less than the length of
7738 * the message minus 1: data upto index, shall be copied to message 2
7739 * and read/write pointers of message 1 will be updated accordingly
7741 * if index is not equal to 0 and greater than or equal to
7742 * the length of the message minus 1: all of the message 1 data.
7743 * shall be copied to message 2. return is ok.
7751 PUBLIC S16 SMovPartMsg
7753 Buffer *srcBuf, /* message 1 */
7754 MsgLen idx, /* index */
7755 Buffer *dstBuf /* message 2 */
7758 PUBLIC S16 SMovPartMsg(srcBuf, idx, dstBuf)
7759 Buffer *srcBuf; /* message 1 */
7760 MsgLen idx; /* index */
7761 Buffer *dstBuf; /* message 2 */
7771 #ifdef T2K_MEM_LEAK_DBG
7772 char* file = __FILE__;
7773 U32 line = __LINE__;
7778 #if (ERRCLASS & ERRCLS_INT_PAR)
7779 /* check message buffer 1 */
7780 if ((!srcBuf) || (!dstBuf ))
7782 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SMovPartMsg : Null Buffer (src or Dst)");
7787 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SMovPartMsg : Invalid index");
7790 if ((srcBuf->b_datap->db_type != SS_M_PROTO) || (dstBuf->b_datap->db_type != SS_M_PROTO))
7792 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SMovPartMsg : Incorrect buffer\
7798 /* get the SsMsgInfo of srcBuf */
7799 sMinfo = (SsMsgInfo*) srcBuf->b_rptr;
7801 /* get the SsMsgInfo of dstBuf */
7802 dMinfo = (SsMsgInfo*) dstBuf->b_rptr;
7804 /* if index > length of mBuf, return */
7806 if (idx > sMinfo->len)
7811 /* one block might not sufficient - Check for generic implementation */
7812 sBuf = srcBuf->b_cont;
7813 /* dBuf = dMinfo->endptr; */
7814 dPrev = (dBuf = dMinfo->endptr) ? dBuf : dstBuf;
7816 /* adjust the lengths of srcBuf, dstBuf */
7822 sCnt = sBuf->b_wptr - sBuf->b_rptr;
7825 /* allocate a data buffer */
7826 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
7828 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyMsgPartMsg : SGetDBuf\
7832 dCnt = MIN(idx, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
7833 dPrev->b_cont = dBuf;
7838 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
7840 if(sCnt > idx) /* src Dblk has enough data to copy */
7844 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7845 dBuf->b_wptr += dCnt;
7846 dBuf = dBuf->b_cont;
7848 sBuf->b_rptr += dCnt;
7852 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), idx);
7853 dBuf->b_wptr += idx;
7854 dBuf->b_cont = NULLP;
7855 sBuf->b_rptr += idx;
7860 else /* src dBlk has partial data to be copied */
7864 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7865 dBuf->b_wptr += dCnt;
7866 dBuf = dBuf->b_cont;
7868 sBuf->b_rptr += dCnt;
7873 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), sCnt);
7874 dBuf->b_wptr += sCnt;
7876 /* deallocate the sBuf here */
7878 /* printf("SMovPartMsg() sBuf is completely copied sBuf->b_cont(%p)\n", sBuf->b_cont); */
7879 (Void)SPutDBuf(sMinfo->region, sMinfo->pool, sBuf);
7880 srcBuf->b_cont = sBuf = tmp;
7884 dMinfo->endptr = dBuf;
7889 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SMovPartMsg : unable to copy\
7901 * Desc: This function copies consecutive bytes of data to the
7902 * beginning of a message.
7905 * RFAILED - failed, general (optional)
7906 * ROUTRES - failed, out of resources (optional)
7908 * Notes: if message is empty: data is placed in the message. message
7909 * length is incremented. return is ok.
7911 * if message is not empty: data is read by source pointer,
7912 * data is placed in front of all other data in message.
7913 * message length is incremented. return is ok.
7915 * the first byte of data pointed to by the source pointer
7916 * will be placed at the front of the message first (i.e. it
7917 * will become the first byte of the message) and the last
7918 * byte will be placed in front of the existing msg contents,
7919 * i.e. order of the source is preserved.
7926 PUBLIC S16 SPkMsgMult
7933 PUBLIC S16 SPkMsgMult(src, cnt, mBuf)
7939 SsMsgInfo *minfo; /* Message info */
7942 MsgLen numBytes; /* no. of bytes to be copied */
7947 #if (ERRCLASS & ERRCLS_INT_PAR)
7948 /* check message buffer */
7951 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SPkMsgMult:Null Buffer");
7957 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SPkMsgMult:Null Buffer");
7963 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SPkMsgMult: Invalid\
7967 if (mBuf->b_datap->db_type != SS_M_PROTO)
7969 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SPkMsgMult: Incorrect\
7975 /* get the SsMsgInfo of mBuf */
7976 minfo = (SsMsgInfo*) mBuf->b_rptr;
7978 /* ss014.13: Addition */
7981 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
7982 (tmp->b_datap->db_base < tmp->b_rptr))
7984 /* store the offset of the read pointer of tmp */
7985 offset = tmp->b_rptr - tmp->b_datap->db_base;
7987 /* determine the number of bytes to copy */
7988 numBytes = MIN(cnt, offset);
7993 /* update the read ptr */
7994 tmp->b_rptr -= numBytes;
7996 memcpy((U8*)tmp->b_rptr, (src + cnt), numBytes);
7997 minfo->len += numBytes;
8005 char * file = __FILE__;
8006 U32 line = __LINE__;
8009 /* allocate a DBlk minimum of size Cnt to pack the data */
8011 if (ssGetDBufOfSize(minfo->region, cnt, &newblk) != ROK)
8015 newblk->b_datap->db_type = SS_M_DATA;
8016 newblk->b_rptr = newblk->b_datap->db_lim - cnt;
8017 newblk->b_wptr = newblk->b_datap->db_lim;
8018 memcpy((U8*)newblk->b_rptr, src, cnt);
8019 /* attach the newblk chain into mBuf */
8020 newblk->b_cont = tmp;
8021 mBuf->b_cont = newblk;
8023 minfo->endptr = newblk;
8027 /* ss006.301 : new buffer management APIs, end */
8032 * Desc: This function retunrs the pointer to the read the message from mBuf
8035 * RFAILED - failed, general (optional)
8043 PUBLIC S16 SGetReadPtr
8050 PUBLIC S16 SGetReadPtr (mBuf, data, len)
8058 if (mBuf && mBuf->b_cont)
8060 *data = mBuf->b_cont->b_rptr;
8061 *len = ((SsMsgInfo*)(mBuf->b_rptr))->len;
8071 #ifdef SS_USE_ZBC_MEMORY
8074 * Fun: SAttachPtrToBuf
8076 * Desc: This function attaches the Pointer provided into a new
8077 * message buffer after allocating the same. It allocates
8078 * header (M-Block) and an additional dBuf (D-Block) and attaches
8079 * the provided pointer to it.
8082 * RFAILED - failed, general (optional)
8083 * ROUTRES - failed, out of resources (optional)
8091 #ifdef T2K_MEM_LEAK_DBG
8092 PUBLIC S16 SAttachPtrToBufNew
8104 PUBLIC S16 SAttachPtrToBuf
8113 PUBLIC S16 SAttachPtrToBuf(region, pool, ptr, totalLen, mBuf)
8122 SsMsgInfo *minfo; /* Message info */
8126 /* Void *iccHdlr; */
8128 TRC1(SAttachPtrToBuf)
8130 #if (ERRCLASS & ERRCLS_INT_PAR)
8133 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8138 #ifdef XEON_SPECIFIC_CHANGES
8141 if(SGetMsg(region, pool, mBuf) != ROK)
8143 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8149 #ifdef SS_HISTOGRAM_SUPPORT
8150 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
8152 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8153 #endif /* SS_HISTOGRAM_SUPPORT */
8155 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8160 (*mBuf)->b_cont = newblk;
8162 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8164 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8167 newblk->b_datap->db_base = ptr;
8168 newblk->b_datap->db_lim = ptr + totalLen;
8169 newblk->b_rptr = newblk->b_datap->db_base;
8170 newblk->b_wptr = newblk->b_rptr + totalLen;
8172 #ifndef SS_DBUF_REFLOCK_DISABLE
8173 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8175 printf("Falied to destroy lock\n");
8179 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8181 /* get the SsMsgInfo of mBuf */
8182 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8183 minfo->len = totalLen;
8184 minfo->endptr = newblk;
8193 * Desc: This function deallocates a buffer back to the
8194 * dynamic memory pool which is allocated for ZBC
8197 * RFAILED - failed, general (optional)
8205 #ifdef T2K_MEM_LEAK_DBG
8206 PRIVATE S16 SPutZbcDBufNew
8215 PRIVATE S16 SPutZbcDBuf
8221 PRIVATE S16 SPutZbcDBuf(region, buf)
8227 register SsDblk *dptr;
8233 dptr = buf->b_datap;
8234 /* Get the length of the buffer */
8235 bufLen = buf->b_datap->db_lim - buf->b_datap->db_base;
8237 /* If the buffer is not shared, free the buffer */
8240 #ifndef SS_DBUF_REFLOCK_DISABLE
8241 SDestroyLock(&dptr->dBufLock);
8244 /* Free the ZBC buffer first and then free the block allocated for the
8247 #ifdef SS_HISTOGRAM_SUPPORT
8248 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
8249 (U8*) __FILE__, ENTNC);
8251 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
8252 #endif /* SS_HISTOGRAM_SUPPORT */
8254 /* if the data block is not shared, free the buffer, checks not reqd */
8255 #ifdef SS_HISTOGRAM_SUPPORT
8256 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__,
8259 ret = SFree(region, (Data *) buf, MDBSIZE);
8260 #endif /* SS_HISTOGRAM_SUPPORT */
8262 /* If the buffer is shared, reduce the refernce count and free the buffer
8263 * if reference count falls to zero */
8266 #ifndef SS_DBUF_REFLOCK_DISABLE
8267 if((ret=SLock(&dptr->dBufLock)))
8269 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
8270 "Could not lock the mBuf Ref Lock");
8275 /* if buffer's message blk is obtained during dupb */
8276 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
8278 #ifdef SS_HISTOGRAM_SUPPORT
8279 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__, ENTNC);
8281 ret = SFree(region, (Data *) buf, MDBSIZE);
8282 #endif /* SS_HISTOGRAM_SUPPORT */
8283 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
8285 /* if reference count falls to zero */
8288 #ifndef SS_DBUF_REFLOCK_DISABLE
8289 ret = SUnlock(&dptr->dBufLock) ;
8290 if((SDestroyLock(&dptr->dBufLock)) != 0)
8292 printf("Falied to destroy lock\n");
8295 #ifdef SS_HISTOGRAM_SUPPORT
8296 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
8297 (U8*) __FILE__, ENTNC);
8299 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
8300 #endif /* SS_HISTOGRAM_SUPPORT */
8302 #ifdef SS_HISTOGRAM_SUPPORT
8303 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__,
8306 ret = SFree(region, (Data *) buf, MDBSIZE);
8307 #endif /* SS_HISTOGRAM_SUPPORT */
8310 #ifndef SS_DBUF_REFLOCK_DISABLE
8311 ret = SUnlock(&(dptr->dBufLock));
8317 #endif /* SS_USE_ZBC_MEMORY */
8323 * Fun: SAttachPtrToMBuf
8325 * Desc: This function attaches the Pointer provided into a new
8326 * message buffer after allocating the same. It allocates
8327 * header (M-Block) and an additional dBuf (D-Block) and attaches
8328 * the provided pointer to it.
8331 * RFAILED - failed, general (optional)
8332 * ROUTRES - failed, out of resources (optional)
8339 #ifdef T2K_MEM_LEAK_DBG
8340 PUBLIC S16 SAttachPtrToMBuf1
8353 PUBLIC S16 SAttachPtrToMBuf
8363 PUBLIC S16 SAttachPtrToMBuf(region, pool, ptr, totalLen, ptrLen, mBuf)
8373 SsMsgInfo *minfo; /* Message info */
8377 /* Void *iccHdlr; */
8379 TRC1(SAttachPtrToMBuf)
8381 #if (ERRCLASS & ERRCLS_INT_PAR)
8384 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8389 if(SGetMsg(region, pool, mBuf) != ROK)
8391 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8398 #ifdef SS_HISTOGRAM_SUPPORT
8399 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
8401 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8402 #endif /* SS_HISTOGRAM_SUPPORT */
8404 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8409 (*mBuf)->b_cont = newblk;
8411 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8413 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8416 newblk->b_datap->db_base = ptr;
8417 newblk->b_datap->db_lim = ptr + ptrLen;
8418 newblk->b_rptr = newblk->b_datap->db_base;
8419 newblk->b_wptr = newblk->b_rptr + totalLen;
8421 #ifndef SS_DBUF_REFLOCK_DISABLE
8422 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8424 printf("Falied to destroy lock\n");
8428 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8430 /* get the SsMsgInfo of mBuf */
8431 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8432 minfo->len = totalLen;
8433 minfo->endptr = newblk;
8435 //printf("Mbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
8438 #endif /* INTEL_WLS */
8439 PUBLIC S16 SIncMsgRef(Buffer *srcBuf,Region dstRegion, Pool dstPool,Buffer **dstBuf)
8442 RETVALUE(SAddMsgRef(srcBuf,dstRegion, dstPool,dstBuf));
8449 PUBLIC Void SResetMBuf(Buffer *mbuf)
8455 minfo = (SsMsgInfo *) mbuf->b_rptr;
8456 //tmp = minfo->endptr;
8463 // 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 );
8464 // tmp->b_wptr = tmp->b_rptr = tmp->b_datap->db_base;
8465 tmp->b_wptr = tmp->b_rptr = (tmp->b_datap->db_base + 5);
8466 tmp->b_datap->db_ref = 1;
8467 tmp->b_datap->shared = 0;
8479 * Fun: SAttachWlsPtrToMBuf
8481 * Desc: This function attaches the Pointer provided into a new
8482 * message buffer after allocating the same. It allocates
8483 * header (M-Block) and an additional dBuf (D-Block) and attaches
8484 * the provided pointer to it.
8487 * RFAILED - failed, general (optional)
8488 * ROUTRES - failed, out of resources (optional)
8495 #ifdef T2K_MEM_LEAK_DBG
8496 PUBLIC S16 SAttachWlsPtrToMBuf1
8510 PUBLIC S16 SAttachWlsPtrToMBuf
8521 PUBLIC S16 SAttachWlsPtrToMBuf(region, pool, ptr, readPtr, totalLen, ptrLen, mBuf)
8532 SsMsgInfo *minfo; /* Message info */
8536 /* Void *iccHdlr; */
8538 TRC1(SAttachWlsPtrToMBuf)
8540 #if (ERRCLASS & ERRCLS_INT_PAR)
8543 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8549 if(SGetMsg(region, pool, mBuf) != ROK)
8551 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8557 #ifdef SS_HISTOGRAM_SUPPORT
8558 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
8560 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8561 #endif /* SS_HISTOGRAM_SUPPORT */
8563 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8568 (*mBuf)->b_cont = newblk;
8570 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8572 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8575 newblk->b_datap->db_base = ptr;
8576 newblk->b_datap->db_lim = ptr + ptrLen;
8577 newblk->b_rptr = readPtr;
8578 newblk->b_wptr = newblk->b_rptr + totalLen;
8580 #ifndef SS_DBUF_REFLOCK_DISABLE
8581 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8583 printf("Falied to destroy lock\n");
8587 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8589 /* get the SsMsgInfo of mBuf */
8590 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8591 minfo->len = totalLen;
8592 minfo->endptr = newblk;
8594 //printf("Mbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
8598 #ifdef TENB_DPDK_BUF
8602 PUBLIC S16 SGetSBufDpdk
8604 Data **ptr, /* pointer to buffer */
8605 Size size /* size requested */
8610 *ptr = ntl_alloc(mtGetNtlHdl(), size);
8615 PUBLIC S16 SPutSBufDpdk
8617 Data *ptr /* pointer to buffer */
8623 ntl_free(mtGetNtlHdl(), ptr);
8628 PUBLIC S16 SDetachDpdkPtrFrmDBuf
8638 //msgBlk = mBuf->b_cont;
8639 //*ptr = msgBlk->b_rptr;;
8640 *ptr = mBuf->b_datap->db_base;;
8642 mBuf->b_cont = NULL;
8644 //minfo = (SsMsgInfo*) mBuf->b_rptr;
8652 PUBLIC S16 SDetachDpdkPtrFrmMBuf
8661 register SsDblk *dptr;
8665 msgBlk = mBuf->b_cont;
8672 dptr = msgBlk->b_datap;
8673 if(dptr->db_type != SS_MEM_TYPE_DPDK_ZBC)
8679 *ptr = msgBlk->b_rptr;;
8681 mBuf->b_cont = NULL;
8683 minfo = (SsMsgInfo*) mBuf->b_rptr;
8691 PUBLIC S16 SAttachDpdkPtrToMBuf
8702 PUBLIC S16 SAttachDpdkPtrToMBuf(region, pool, ptr, readPtr, msgLen, totalLen, mBuf)
8718 SAttachWlsPtrToMBuf(region, pool, ptr, readPtr, msgLen, totalLen, mBuf);
8719 dptr = (SsDblk*) (((Data *) ((*mBuf)->b_cont)) + MBSIZE);
8721 dptr->db_type = SS_MEM_TYPE_DPDK_ZBC;
8726 #endif /* TENB_DPDK_BUF */
8728 #endif /* INTEL_WLS */
8730 /**********************************************************************
8732 **********************************************************************/