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))
656 if(ROK == mtAddBufToRing(SS_RNG_BUF_MAC_FREE_RING,(Void *)mBuf,0))
662 #ifdef RLC_FREE_RING_BUF
663 else if(pthread_self() == gRlcTId)
665 if(ROK == mtAddBufToRing(SS_RNG_BUF_RLC_FREE_RING,(Void *)mBuf,0))
675 #if (ERRCLASS & ERRCLS_INT_PAR)
678 SSLOGERROR(ERRCLS_INT_PAR, ESS060, ERRZERO, "SPutMsg: Null Buffer");
681 if (mBuf->b_datap->db_type != SS_M_PROTO)
683 SSLOGERROR(ERRCLS_INT_PAR, ESS061, ERRZERO, "SPutMsg: Incorrect buffer\
689 #ifdef SS_MEM_WL_DEBUG
690 CM_MEM_GET_REGION(tmpThrReg)
691 if(tmpThrReg == 0xFF)
693 printf("\n Not able to get region \n");
698 /* get the message info */
699 minfo = (SsMsgInfo *) mBuf->b_rptr;
701 while ((tmp = mBuf->b_cont))
703 /* set b_cont of mBuf to point to the b_cont of tmp */
704 mBuf->b_cont = tmp->b_cont;
705 #ifdef SS_MEM_WL_DEBUG
706 (Void) SPutDBuf(tmpThrReg, minfo->pool, tmp);
708 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
712 /* ss001.301: additions */
713 #ifdef SS_HISTOGRAM_SUPPORT
714 SGetEntInd(&entId, fileName);
715 #endif /* SS_HISTOGRAM_SUPPORT */
717 /* ss012.13: Addition */
718 #ifdef SS_M_PROTO_REGION
719 /* ss021.103 - Addition to check return value of SFree */
720 #ifdef SS_HISTOGRAM_SUPPORT
721 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE, line, fileName, entId) == RFAILED)
723 #ifdef SS_MEM_WL_DEBUG
724 if (SFree(tmpThrReg, (Data *) mBuf, MSGSIZE) == RFAILED)
726 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE) == RFAILED)
728 #endif /* SS_HISTOGRAM_SUPPORT */
730 #else /* SS_M_PROTO_REGION */
731 /* ss021.103 - Addition to check return value of SFree */
732 #ifdef SS_HISTOGRAM_SUPPORT
733 if (SFree(SS_DFLT_REGION, (Data *) mBuf, MSGSIZE, line, fileName, entId) == RFAILED)
735 if (SFree(minfo->region, (Data *) mBuf, MSGSIZE) == RFAILED)
736 #endif /* SS_HISTOGRAM_SUPPORT */
738 #endif /* SS_M_PROTO_REGION */
743 #ifdef SS_LOCKLESS_MEMORY
746 * Fun: SPutStaticBuffer
748 * Desc: Returns a buffer to the specified static pool in the
749 * specified memory region.
752 * RFAILED - failed, general (optional)
759 /* ss001.301: additions */
760 #ifdef T2K_MEM_LEAK_DBG
761 PUBLIC S16 SPutStaticBufferNew
763 Region region, /* region ID */
764 Pool pool, /* pool ID */
765 Data *ptr, /* pointer to buffer */
766 Size size, /* size */
767 U8 memType, /* memory type used if shareable or not */
773 PUBLIC S16 SPutStaticBuffer
775 Region region, /* region ID */
776 Pool pool, /* pool ID */
777 Data *ptr, /* pointer to buffer */
778 Size size, /* size */
779 U8 memType /* memory type used if shareable or not */
782 PUBLIC S16 SPutStaticBuffer(region, pool, ptr, size)
783 Region region; /* region ID */
784 Pool pool; /* pool ID */
785 Data *ptr; /* pointer to buffer */
786 Size size; /* size */
787 U8 memType; /* memory type used if shareable or not */
793 TRC1(SPutStaticBuffer);
795 #if (ERRCLASS & ERRCLS_INT_PAR)
796 /* validate region ID */
797 if (region >= SS_MAX_REGS)
799 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
803 /* validate pool ID */
804 if (pool >= SS_MAX_POOLS_PER_REG)
806 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
809 /* validate data pointer */
812 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
819 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
823 #if (defined (MAC_FREE_RING_BUF) || defined (RLC_FREE_RING_BUF))
825 extern pthread_t gMacTId,gRlcTId;
827 if(clusterMode == RADIO_CLUSTER_MODE)
829 #ifdef MAC_FREE_RING_BUF
830 if(pthread_self() == gMacTId)
831 //if(pthread_equal(pthread_self(),gMacTId))
833 if(ROK == mtAddBufToRing(SS_RNG_BUF_MAC_FREE_RING,(Void *)ptr,1))
839 #ifdef RLC_FREE_RING_BUF
840 else if(pthread_self() == gRlcTId)
842 if(ROK == mtAddBufToRing(SS_RNG_BUF_RLC_FREE_RING,(Void *)ptr,1))
851 region = SS_GET_THREAD_MEM_REGION();
854 #if (ERRCLASS & ERRCLS_INT_PAR)
855 /* verify that this region is present */
856 if (((memType == SS_NON_SHARABLE_MEMORY) &&
857 (osCp.regionTbl[region].used == FALSE)) ||
858 ((memType == SS_SHARABLE_MEMORY) &&
859 (osCp.dynRegionTbl[region].used == FALSE)))
861 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
866 /* call the memory manager, to allocate this memory */
867 #ifndef SS_DBUF_REFLOCK_DISABLE
868 if(memType == SS_NON_SHARABLE_MEMORY)
870 #ifndef T2K_MEM_LEAK_DBG
871 ret = (osCp.regionTbl[region].free)
872 (osCp.regionTbl[region].regCb, ptr, size);
874 ret = (osCp.regionTbl[region].free)
875 (osCp.regionTbl[region].regCb, ptr, size, file, line);
879 else if(memType == SS_SHARABLE_MEMORY)
883 #ifndef T2K_MEM_LEAK_DBG
884 ret = (osCp.dynRegionTbl[region].free)
885 (osCp.dynRegionTbl[region].regCb, ptr, size);
887 ret = (osCp.dynRegionTbl[region].free)
888 (osCp.dynRegionTbl[region].regCb, ptr, size,file,line);
890 #ifndef SS_DBUF_REFLOCK_DISABLE
899 * Fun: SGetStaticBuffer
901 * Desc: Allocates a buffer from the specified static memory pool
902 * in the specified region. Depending on the type wheather
903 * the buffer is sharable or non-sharable indicated by the
904 * memType prameter allocation region is choosen
908 * RFAILED - failed, general (optional)
915 #ifdef T2K_MEM_LEAK_DBG
916 PUBLIC S16 SGetStaticBufferNew
918 Region region, /* region ID */
919 Pool pool, /* pool ID */
920 Data **ptr, /* pointer to buffer */
921 Size size, /* size requested */
922 U8 memType, /* memory type used if shareable or not */
928 PUBLIC S16 SGetStaticBuffer
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 */
937 PUBLIC S16 SGetStaticBuffer(region, pool, ptr, size)
938 Region region; /* region ID */
939 Pool pool; /* pool ID */
940 Data **ptr; /* pointer to buffer */
941 Size size; /* size requested */
942 U8 memType; /* memory type used if shareable or not */
949 TRC1(SGetStaticBuffer);
951 #if (ERRCLASS & ERRCLS_INT_PAR)
952 /* validate region ID */
953 if (region >= SS_MAX_REGS)
955 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
959 /* validate pool ID */
960 if (pool >= SS_MAX_POOLS_PER_REG)
962 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
965 /* validate data pointer */
968 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
975 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
980 #if (ERRCLASS & ERRCLS_INT_PAR)
981 /* verify that this region is present */
982 if (((memType == SS_NON_SHARABLE_MEMORY) &&
983 (osCp.regionTbl[region].used == FALSE)) ||
984 ((memType == SS_SHARABLE_MEMORY) &&
985 (osCp.dynRegionTbl[region].used == FALSE)))
987 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
994 region = SS_GET_THREAD_MEM_REGION();
996 if (region == SS_STATIC_REGION)
1000 /* call the memory manager, to allocate this memory */
1001 #ifndef SS_DBUF_REFLOCK_DISABLE
1002 if(memType == SS_NON_SHARABLE_MEMORY)
1004 #ifndef T2K_MEM_LEAK_DBG
1005 ret = (osCp.regionTbl[region].alloc)
1006 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1008 ret = (osCp.regionTbl[region].alloc)
1009 (osCp.regionTbl[region].regCb, &size, flags, ptr, file,line);
1012 else if(memType == SS_SHARABLE_MEMORY)
1015 #ifndef T2K_MEM_LEAK_DBG
1016 ret = (osCp.dynRegionTbl[region].alloc)
1017 (osCp.dynRegionTbl[region].regCb, &size, flags, ptr);
1019 ret = (osCp.dynRegionTbl[region].alloc)
1020 (osCp.dynRegionTbl[region].regCb, &size, flags, ptr,file,line);
1022 #ifndef SS_DBUF_REFLOCK_DISABLE
1028 #endif /* SS_LOCKLESS_MEMORY */
1031 #ifndef SS_LOCKLESS_MEMORY
1033 PUBLIC S16 SGetStaticBuffer
1035 Region region, /* region ID */
1036 Pool pool, /* pool ID */
1037 Data **ptr, /* pointer to buffer */
1038 Size size, /* size requested */
1039 U8 memType /* memory type used if shareable or not */
1042 PUBLIC S16 SGetStaticBuffer(region, pool, ptr, size)
1043 Region region; /* region ID */
1044 Pool pool; /* pool ID */
1045 Data **ptr; /* pointer to buffer */
1046 Size size; /* size requested */
1047 U8 memType; /* memory type used if shareable or not */
1052 ret = SGetSBuf(region, pool, ptr, size);
1059 PUBLIC S16 SPutStaticBuffer
1061 Region region, /* region ID */
1062 Pool pool, /* pool ID */
1063 Data *ptr, /* pointer to buffer */
1064 Size size, /* size */
1065 U8 memType /* memory type used if shareable or not */
1068 PUBLIC S16 SPutStaticBuffer(region, pool, ptr, size)
1069 Region region; /* region ID */
1070 Pool pool; /* pool ID */
1071 Data *ptr; /* pointer to buffer */
1072 Size size; /* size */
1073 U8 memType; /* memory type used if shareable or not */
1079 ret = SPutSBuf(region, pool, ptr, size);
1085 #ifdef T2K_MEM_LEAK_DBG
1086 PUBLIC S16 SGetSBufWls1
1088 Region region, /* region ID */
1089 Pool pool, /* pool ID */
1090 Data **ptr, /* pointer to buffer */
1091 Size size, /* size requested */
1096 PUBLIC S16 SGetSBufWls
1098 Region region, /* region ID */
1099 Pool pool, /* pool ID */
1100 Data **ptr, /* pointer to buffer */
1101 Size size /* size requested */
1108 #ifdef SS_LOCKLESS_MEMORY
1109 region = SS_GET_THREAD_MEM_REGION();
1110 ret = SAlloc(region, &size, 0, ptr);
1113 #ifdef T2K_MEM_LEAK_DBG
1114 ret = (osCp.regionTbl[region].alloc)
1115 (osCp.regionTbl[region].regCb, &size, flags, ptr,file,line);
1117 ret = (osCp.regionTbl[region].alloc)
1118 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1125 #ifdef T2K_MEM_LEAK_DBG
1126 PUBLIC S16 SPutSBufWls1
1128 Region region, /* region ID */
1129 Pool pool, /* pool ID */
1130 Data *ptr, /* pointer to buffer */
1131 Size size, /* size */
1136 PUBLIC S16 SPutSBufWls
1138 Region region, /* region ID */
1139 Pool pool, /* pool ID */
1140 Data *ptr, /* pointer to buffer */
1141 Size size /* size */
1147 #ifdef SS_LOCKLESS_MEMORY
1148 region = SS_GET_THREAD_MEM_REGION();
1149 ret = SFree(region, ptr, size);
1152 #ifdef T2K_MEM_LEAK_DBG
1153 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,file,line);
1155 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1162 #endif /* INTEL_WLS */
1169 * Desc: Allocates a buffer from the specified static memory pool
1170 * in the specified region.
1173 * RFAILED - failed, general (optional)
1175 * Notes: The new memory management scheme eliminates the concept
1176 * of pools. This call maps directly to a call to the memory
1182 /* ss001.301: additions */
1183 #ifdef SS_HISTOGRAM_SUPPORT
1185 PUBLIC S16 SGetSBufNew
1187 Region region, /* region ID */
1188 Pool pool, /* pool ID */
1189 Data **ptr, /* pointer to buffer */
1190 Size size, /* size requested */
1195 PUBLIC S16 SGetSBufNew(region, pool, ptr, size, line, fileName)
1196 Region region; /* region ID */
1197 Pool pool; /* pool ID */
1198 Data **ptr; /* pointer to buffer */
1199 Size size; /* size requested */
1203 #else /* SS_HISTOGRAM_SUPPORT */
1204 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1206 PUBLIC S16 SGetSBuf1
1208 Region region, /* region ID */
1209 Pool pool, /* pool ID */
1210 Data **ptr, /* pointer to buffer */
1211 Size size, /* size requested */
1216 PUBLIC S16 SGetSBuf1(region, pool, ptr, size, file, line)
1217 Region region; /* region ID */
1218 Pool pool; /* pool ID */
1219 Data **ptr; /* pointer to buffer */
1220 Size size; /* size requested */
1228 Region region, /* region ID */
1229 Pool pool, /* pool ID */
1230 Data **ptr, /* pointer to buffer */
1231 Size size /* size requested */
1234 PUBLIC S16 SGetSBuf(region, pool, ptr, size)
1235 Region region; /* region ID */
1236 Pool pool; /* pool ID */
1237 Data **ptr; /* pointer to buffer */
1238 Size size; /* size requested */
1241 #endif /* SS_HISTOGRAM_SUPPORT */
1245 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1249 #ifdef SS_HISTOGRAM_SUPPORT
1251 Bool hstReg = FALSE;
1252 #endif /* SS_HISTOGRAM_SUPPORT */
1256 region = SS_GET_THREAD_MEM_REGION();
1259 #endif /* INTEL_WLS */
1261 #if (ERRCLASS & ERRCLS_INT_PAR)
1262 /* validate region ID */
1263 if (region >= SS_MAX_REGS)
1265 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
1269 /* validate pool ID */
1270 if (pool >= SS_MAX_POOLS_PER_REG)
1272 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
1275 /* ss008.13: addition */
1276 /* validate data pointer */
1279 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
1286 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
1290 /* ss037.103 Removed the semaphore operation for performance enhancement */
1292 #ifndef RGL_SPECIFIC_CHANGES
1293 region = SS_GET_THREAD_MEM_REGION();
1296 /* acquire one semaphore, to protect against deregistration */
1297 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1301 #if (ERRCLASS & ERRCLS_DEBUG)
1302 SSLOGERROR(ERRCLS_DEBUG, ESS216, (ErrVal) ret,
1303 "Could not lock region table");
1311 #if (ERRCLASS & ERRCLS_INT_PAR)
1312 /* verify that this region is present */
1313 if (osCp.regionTbl[region].used == FALSE)
1317 /* ss006.13: addition */
1318 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1320 #if (ERRCLASS & ERRCLS_DEBUG)
1321 SSLOGERROR(ERRCLS_DEBUG, ESS217, ERRZERO,
1322 "Could not release semaphore");
1327 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
1336 /* ss024.103 - Addition for memory calculator tool */
1338 if (region == SS_STATIC_REGION)
1342 /* ss001.301: additions */
1343 #ifdef SS_HISTOGRAM_SUPPORT
1345 SGetEntInd(&entId, fileName);
1346 /* Get the Information from the oscp that the tapa task with the entity
1347 id (entid) is registed for histogram or not */
1348 SGetHstGrmInfo(&entId, &hstReg);
1349 /* call the memory manager, to allocate this memory */
1350 #ifdef SSI_DEBUG_LEVEL1
1351 ret = (osCp.regionTbl[region].alloc)
1352 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1353 SS_STATIC_MEM_FLAG, line, fileName, entId, hstReg);
1355 ret = (osCp.regionTbl[region].alloc)
1356 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1357 line, fileName, entId, hstReg);
1358 #endif /* SSI_DEBUG_LEVEL1 */
1362 /* call the memory manager, to allocate this memory */
1363 /* ss036.103 - addition for passing additional parameter memType as static */
1364 #ifdef SSI_DEBUG_LEVEL1
1365 ret = (osCp.regionTbl[region].alloc)
1366 (osCp.regionTbl[region].regCb, &size, flags, ptr, SS_STATIC_MEM_FLAG);
1368 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1369 /* Static mem leak detection changes */
1371 #ifdef T2K_MEM_LEAK_DBG
1372 ret = (osCp.regionTbl[region].alloc)
1373 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr, file, line);
1375 ret = (osCp.regionTbl[region].alloc)
1376 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr);
1378 /*size = tmpSize - 4;*/
1380 /*printf("ptr = %p *ptr = %p\n",ptr,*ptr);*/
1381 #ifdef XEON_SPECIFIC_CHANGES
1382 pthread_mutex_lock(&(memLock));
1384 U32 idx = GetNextFreeIdx(&SMemLeakInfo[region]);
1385 U8* allocatedPtr = *ptr;
1386 void* actualPtr = allocatedPtr + 4;
1388 /* store the index in the memory allocated itself */
1389 /**((U32*)*((U32*)allocatedPtr)) = idx;*/
1390 *((U32*)allocatedPtr) = idx;
1391 /*printf("region = %d idx = %d ptr = %p *ptr = %p actual = %p allocated = %p content = %d\n",region, idx, ptr, *ptr, actualPtr, allocatedPtr, *((U32*)allocatedPtr));*/
1393 LogForStaticMemLeak(&SMemLeakInfo[region],
1399 #ifdef XEON_SPECIFIC_CHANGES
1400 pthread_mutex_unlock(&(memLock));
1404 #ifndef T2K_MEM_LEAK_DBG
1405 ret = (osCp.regionTbl[region].alloc)
1406 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1408 ret = (osCp.regionTbl[region].alloc)
1409 (osCp.regionTbl[region].regCb, &size, flags, ptr, file, line);
1413 #endif /* SSI_DEBUG_LEVEL1 */
1415 #endif /* SS_HISTOGRAM_SUPPORT */
1417 /* release the semaphore we took */
1420 /* ss006.13: addition */
1421 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1423 #if (ERRCLASS & ERRCLS_DEBUG)
1424 SSLOGERROR(ERRCLS_DEBUG, ESS219, ERRZERO,
1425 "Could not release semaphore");
1430 /* ss036.103 - Addition to handle the memory trampling return value
1431 * This in turn might invoke SRegMemErrHdlr
1433 #ifdef SSI_DEBUG_LEVEL1
1434 if (ret == RTRAMPLINGNOK)
1436 SRegMemErrHdlr( region, *ptr, ret);
1438 #endif /* SSI_DEBUG_LEVEL1 */
1448 * Desc: Returns a buffer to the specified static pool in the
1449 * specified memory region.
1452 * RFAILED - failed, general (optional)
1459 /* ss001.301: additions */
1460 #ifdef SS_HISTOGRAM_SUPPORT
1462 PUBLIC S16 SPutSBufNew
1464 Region region, /* region ID */
1465 Pool pool, /* pool ID */
1466 Data *ptr, /* pointer to buffer */
1467 Size size, /* size */
1472 PUBLIC S16 SPutSBufNew(region, pool, ptr, size, line, fileName)
1473 Region region; /* region ID */
1474 Pool pool; /* pool ID */
1475 Data *ptr; /* pointer to buffer */
1476 Size size; /* size */
1480 #else /* SS_HISTOGRAM_SUPPORT */
1481 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1483 PUBLIC S16 SPutSBuf1
1485 Region region, /* region ID */
1486 Pool pool, /* pool ID */
1487 Data *ptr, /* pointer to buffer */
1488 Size size, /* size */
1493 PUBLIC S16 SPutSBuf1(region, pool, ptr, size, file, line)
1494 Region region; /* region ID */
1495 Pool pool; /* pool ID */
1496 Data *ptr; /* pointer to buffer */
1497 Size size; /* size */
1505 Region region, /* region ID */
1506 Pool pool, /* pool ID */
1507 Data *ptr, /* pointer to buffer */
1508 Size size /* size */
1511 PUBLIC S16 SPutSBuf(region, pool, ptr, size)
1512 Region region; /* region ID */
1513 Pool pool; /* pool ID */
1514 Data *ptr; /* pointer to buffer */
1515 Size size; /* size */
1518 #endif /* SS_HISTOGRAM_SUPPORT */
1522 #ifdef SS_HISTOGRAM_SUPPORT
1524 Bool hstReg = FALSE;
1525 #endif /* SS_HISTOGRAM_SUPPORT */
1530 region = SS_GET_THREAD_MEM_REGION();
1531 #if (!defined(SS_LOCKLESS_MEMORY) && defined(INTEL_WLS))
1533 #endif /* INTEL_WLS */
1535 #if (ERRCLASS & ERRCLS_INT_PAR)
1536 /* validate region ID */
1537 if (region >= SS_MAX_REGS)
1539 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
1543 /* validate pool ID */
1544 if (pool >= SS_MAX_POOLS_PER_REG)
1546 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
1549 /* ss008.13: addition */
1550 /* validate data pointer */
1553 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
1560 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
1564 /* ss037.103 Removed the semaphore operation for performance enhancement */
1565 #ifndef RGL_SPECIFIC_CHANGES
1566 region = SS_GET_THREAD_MEM_REGION();
1569 /* acquire one semaphore, to protect against deregistration */
1570 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1574 #if (ERRCLASS & ERRCLS_DEBUG)
1575 SSLOGERROR(ERRCLS_DEBUG, ESS225, (ErrVal) ret,
1576 "Could not lock region table");
1583 #if (ERRCLASS & ERRCLS_INT_PAR)
1584 /* verify that this region is around */
1585 if (osCp.regionTbl[region].used == FALSE)
1589 /* ss006.13: addition */
1590 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1592 #if (ERRCLASS & ERRCLS_DEBUG)
1593 SSLOGERROR(ERRCLS_DEBUG, ESS226, ERRZERO,
1594 "Could not release semaphore");
1599 SSLOGERROR(ERRCLS_INT_PAR, ESS227, region, "Region not registered");
1604 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1605 /* Static mem leak detection changes */
1607 #ifdef XEON_SPECIFIC_CHANGES
1608 pthread_mutex_lock(&(memLock));
1610 U32 idx = *((U32*)((U8 *)ptr - 4));
1611 FreeIdx(ptr,idx,&SMemLeakInfo[region],size,file,line);
1612 #ifdef XEON_SPECIFIC_CHANGES
1613 pthread_mutex_unlock(&(memLock));
1616 /* Static mem leak detection changes */
1619 /* ss001.301: additions */
1620 #ifdef SS_HISTOGRAM_SUPPORT
1621 SGetEntInd(&entId, fileName);
1622 /* Get the Information from the oscp that the tapa task with the entity
1623 id (entid) is registed for histogram or not */
1624 SGetHstGrmInfo(&entId, &hstReg);
1626 /* call the memory manager to free this memory */
1627 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,
1628 line, fileName, entId, hstReg);
1630 /* call the memory manager to free this memory */
1631 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1632 #ifdef T2K_MEM_LEAK_DBG
1633 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4, file, line);
1635 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4);
1638 #ifndef T2K_MEM_LEAK_DBG
1639 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1641 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size, file, line);
1644 #endif /* SS_HISTOGRAM_SUPPORT */
1645 /* ss037.103 Removed the semaphore operation for performance enhancement */
1648 /* release the semaphore we took */
1650 /* ss006.13: addition */
1651 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1653 #if (ERRCLASS & ERRCLS_DEBUG)
1654 SSLOGERROR(ERRCLS_DEBUG, ESS228, ERRZERO,
1655 "Could not release semaphore");
1660 /* ss036.103 - addition to handle double free and trampling return values
1661 * This might invoke SRegMemErrHdlr
1663 #ifdef SSI_DEBUG_LEVEL1
1664 /* handle the double free error here by calling the OS specific error handling function */
1665 if ((ret == RDBLFREE) || (ret == RTRAMPLINGNOK))
1667 SRegMemErrHdlr( region, ptr, ret);
1669 #endif /* SSI_DEBUG_LEVEL1 */
1679 * Desc: This function deallocates a message back and then
1680 * reinitializes the message.
1683 * RFAILED - failed, general (optional)
1685 * Notes: all data attached to message is returned to memory.
1686 * message is set to empty. message is not returned to
1687 * memory. return is ok.
1699 PUBLIC S16 SInitMsg(mBuf)
1709 #if (ERRCLASS & ERRCLS_INT_PAR)
1710 /* check message buffer */
1713 SSLOGERROR(ERRCLS_INT_PAR, ESS062, ERRZERO, "SInitMsg: Null Buffer");
1716 if (mBuf->b_datap->db_type != SS_M_PROTO)
1718 SSLOGERROR(ERRCLS_INT_PAR, ESS063, ERRZERO, "SInitMsg: Incorrect buffer\
1724 /* get the message info */
1727 CM_MEM_GET_REGION(tmpRegId);
1728 if(tmpRegId == 0xFF)
1733 minfo = (SsMsgInfo*) mBuf->b_rptr;
1735 /* free all SS_M_DATA blks */
1736 while ((tmp = mBuf->b_cont))
1738 mBuf->b_cont = tmp->b_cont;
1741 #ifdef T2K_MEM_LEAK_DBG
1742 char * file = __FILE__;
1743 U32 line = __LINE__;
1746 (Void) SPutDBuf(tmpRegId, minfo->pool, tmp);
1748 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
1751 /* initialise the length and endptr variables of mBuf */
1754 minfo->endptr = NULLP;
1755 minfo->next = NULLP;
1760 /* ss016.301 - Added a new API - SAddPreMsgMultInOrder. This preserves the
1761 * byte order while adding the data bytes to the beginning of the message.
1765 * Fun: SAddPreMsgMultInOrder
1767 * Desc: This function copies consecutive bytes of data to the
1768 * beginning of a message and keeps the bytes order preserved.
1770 * Ret: ROK - Appended the bytes to the beginning of the message.
1771 * RFAILED - Failed to append the bytes.
1772 * ROUTRES - Out of resources - Possibly insufficient memory.
1774 * Notes: If the message is empty,data is placed in the message. Message
1775 * length is incremented. Return is ROK.
1777 * If the message is not empty,data is read by source pointer
1778 * and appended at the beginning of the message.
1779 * Message length is incremented. Return is ROK.
1785 PUBLIC S16 SAddPreMsgMultInOrder
1792 PUBLIC S16 SAddPreMsgMultInOrder(src, cnt, mBuf)
1798 SsMsgInfo *minfo; /* Message info */
1800 Buffer *curblk=NULLP;
1803 MsgLen numBytes; /* no. of bytes to be copied */
1808 TRC1(SAddPreMsgMultInOrder)
1810 #if (ERRCLASS & ERRCLS_INT_PAR)
1811 /* check message buffer */
1814 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMultInOrder:\
1821 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMultInOrder:\
1828 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMultInOrder:\
1832 if (mBuf->b_datap->db_type != SS_M_PROTO)
1834 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMultInOrder:\
1835 Incorrect buffer type");
1840 /* get the SsMsgInfo of mBuf */
1841 minfo = (SsMsgInfo*) mBuf->b_rptr;
1842 #ifdef RGL_SPECIFIC_CHANGES
1846 /* store cnt in length */
1851 /* point to the end of the source buffer */
1852 revSrc = src + cnt ;
1854 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
1855 (tmp->b_datap->db_base < tmp->b_rptr))
1857 /* store the offset of the read pointer of tmp */
1858 offset = tmp->b_rptr - tmp->b_datap->db_base;
1860 /* determine the number of bytes to copy */
1861 numBytes = MIN(cnt, offset);
1863 /* traverse back from the end of the source buffer*/
1869 /* move the read pointer towards the left */
1870 tmp->b_rptr -= numBytes ;
1871 SMemCpy((Void *)(tmp->b_rptr ), (Void *) revSrc, (size_t) numBytes);
1879 newblk = prevblk = NULLP;
1882 /* allocate a message blk */
1883 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
1885 while ((curblk = prevblk))
1887 prevblk = prevblk->b_cont;
1888 #ifdef T2K_MEM_LEAK_DBG
1889 char * file = __FILE__;
1890 U32 line = __LINE__;
1893 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
1898 tmp->b_rptr = tmp->b_datap->db_base + offset;
1903 /* attach curblk in the newblk chain */
1906 curblk->b_cont = prevblk; /* stack them up */
1914 /* set the read and write pointers to the end of the data buffer */
1915 /* subsequent prepends have all the buffer to insert data into */
1916 curblk->b_wptr = curblk->b_datap->db_lim;
1917 rptr = curblk->b_datap->db_lim;
1920 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
1925 /* move the read pointer towards the left */
1928 /* traverse back the source buffer */
1931 SMemCpy((Void *)(rptr), (Void *) revSrc, (size_t) numBytes);
1933 curblk->b_rptr = rptr;
1936 /* attach the newblk chain into mBuf */
1937 newblk->b_cont = tmp;
1938 mBuf->b_cont = curblk;
1940 /* update endptr of mBuf */
1943 minfo->endptr = newblk;
1945 /* update length of message */
1954 * Desc: This function copies one byte of data to the
1955 * beginning of a message.
1958 * RFAILED - failed, general (optional)
1959 * ROUTRES - failed, out of resources (optional)
1961 * Notes: if message is empty: data is placed in the message. message
1962 * length is incremented. return is ok.
1964 * if message is not empty: data is placed in front of all
1965 * other data in message. message length is incremented.
1974 PUBLIC S16 SAddPreMsg
1980 PUBLIC S16 SAddPreMsg (data, mBuf)
1991 #if (ERRCLASS & ERRCLS_INT_PAR)
1992 /* check message buffer */
1995 SSLOGERROR(ERRCLS_INT_PAR, ESS064, ERRZERO, "SAddPreMsg: Null Buffer");
1998 if (mBuf->b_datap->db_type != SS_M_PROTO)
2000 SSLOGERROR(ERRCLS_INT_PAR, ESS065, ERRZERO, "SAddPreMsg: Incorrect\
2006 minfo = (SsMsgInfo *) mBuf->b_rptr;
2008 /* ss021.103 - Addition to check if exceeding maximum message length */
2010 if (minfo->len == 0x7FFFFFFF)
2012 if (minfo->len == 0x7FFF)
2019 * allocate a message blk using SGetDBuf(), if there are no data blks in the
2020 * message, mBuf, or if the reference count of the first data blk is greater
2021 * than 1, or if there is no space to append databytes in front of the read
2022 * pointer of the first data blk
2024 if (!(tmp = mBuf->b_cont) || (tmp->b_datap->db_ref > 1) ||
2025 (tmp->b_rptr == tmp->b_datap->db_base))
2027 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
2029 SSLOGERROR(ERRCLS_DEBUG, ESS066, ERRZERO, "SAddPreMsg:Failed in\
2033 /* set the read and write pointers to end of data buffer */
2034 /* subsequent prepends have all the buffer to insert data into */
2035 newb->b_wptr = newb->b_datap->db_lim;
2036 newb->b_rptr = newb->b_datap->db_lim;
2038 /* insert newb before tmp */
2039 newb -> b_cont = tmp;
2040 mBuf->b_cont = newb;
2042 /* if endptr of mBuf is NULLP, set it to newb */
2044 minfo->endptr = newb;
2047 /* insert data, increment length */
2048 *--tmp->b_rptr = data;
2058 * Desc: This function copies one byte of data to the
2062 * RFAILED - failed, general (optional)
2063 * ROUTRES - failed, out of resources (optional)
2065 * Notes: if message is empty: data is placed in the message. message
2066 * length is incremented. return is ok.
2068 * if message is not empty: data is placed in back of all
2069 * other data in message. message length is incremented.
2078 PUBLIC S16 SAddPstMsg
2084 PUBLIC S16 SAddPstMsg (data, mBuf)
2095 #if (ERRCLASS & ERRCLS_INT_PAR)
2096 /* check message buffer */
2099 SSLOGERROR(ERRCLS_INT_PAR, ESS067, ERRZERO, "SAddPstMsg: Null Buffer");
2102 if (mBuf->b_datap->db_type != SS_M_PROTO)
2104 SSLOGERROR(ERRCLS_INT_PAR, ESS068, ERRZERO, "SAddPstMsg: Incorrect\
2110 /* get the message info */
2111 minfo = (SsMsgInfo *) mBuf->b_rptr;
2113 if (!(tmp = minfo->endptr) || (tmp->b_datap->db_ref > 1) ||
2114 (tmp->b_wptr == tmp->b_datap->db_lim))
2116 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
2118 SSLOGERROR(ERRCLS_DEBUG, ESS069, ERRZERO, "SAddPstMsg: Failed in\
2123 /* append newb to the end of the mBuf chain */
2127 mBuf->b_cont = newb;
2129 /* set the endptr of mBuf to newb */
2130 minfo->endptr = newb;
2134 /* insert data, increment length */
2135 *tmp->b_wptr++ = data;
2143 * Fun: SAddPreMsgMult
2145 * Desc: This function copies consecutive bytes of data to the
2146 * beginning of a message.
2149 * RFAILED - failed, general (optional)
2150 * ROUTRES - failed, out of resources (optional)
2152 * Notes: if message is empty: data is placed in the message. message
2153 * length is incremented. return is ok.
2155 * if message is not empty: data is read by source pointer,
2156 * data is placed in front of all other data in message.
2157 * message length is incremented. return is ok.
2159 * the first byte of data pointed to by the source pointer will
2160 * be placed at the front of the message first, the last byte of
2161 * data pointed to by the source pointer will be placed at the
2162 * front of the message last (i.e. it will become the first
2163 * byte of the message).
2169 #ifdef T2K_MEM_LEAK_DBG
2170 PUBLIC S16 SAddPreMsgMult1
2181 PUBLIC S16 SAddPreMsgMult
2188 PUBLIC S16 SAddPreMsgMult(src, cnt, mBuf)
2195 SsMsgInfo *minfo; /* Message info */
2197 Buffer *curblk=NULLP;
2200 MsgLen numBytes; /* no. of bytes to be copied */
2205 TRC1(SAddPreMsgMult)
2207 #if (ERRCLASS & ERRCLS_INT_PAR)
2208 /* check message buffer */
2211 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMult:Null Buffer");
2217 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMult:Null Buffer");
2223 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMult: Invalid\
2227 if (mBuf->b_datap->db_type != SS_M_PROTO)
2229 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMult: Incorrect\
2235 /* get the SsMsgInfo of mBuf */
2236 minfo = (SsMsgInfo*) mBuf->b_rptr;
2238 /* store cnt in length */
2240 /* ss014.13: Addition */
2243 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
2244 (tmp->b_datap->db_base < tmp->b_rptr))
2246 /* store the offset of the read pointer of tmp */
2247 offset = tmp->b_rptr - tmp->b_datap->db_base;
2249 /* determine the number of bytes to copy */
2250 numBytes = MIN(cnt, offset);
2257 *--tmp->b_rptr = *src++;
2264 newblk = prevblk = NULLP;
2267 /* allocate a message blk */
2268 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2270 while ((curblk = prevblk))
2272 prevblk = prevblk->b_cont;
2273 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2278 tmp->b_rptr = tmp->b_datap->db_base + offset;
2283 /* attach curblk in the newblk chain */
2285 curblk->b_cont = prevblk; /* stack them up */
2290 /* set the read and write pointers to the end of the data buffer */
2291 /* subsequent prepends have all the buffer to insert data into */
2292 curblk->b_wptr = curblk->b_datap->db_lim;
2293 rptr = curblk->b_datap->db_lim;
2296 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
2303 curblk->b_rptr = rptr;
2306 /* attach the newblk chain into mBuf */
2307 newblk -> b_cont = tmp;
2308 mBuf -> b_cont = curblk;
2310 /* update endptr of mBuf */
2312 minfo -> endptr = newblk;
2314 /* update length of message */
2322 * Fun: SAddPstMsgMult
2324 * Desc: This function copies consecutive bytes of data to the
2328 * RFAILED - failed, general (optional)
2329 * ROUTRES - failed, out of resources (optional)
2331 * Notes: if message is empty: data is placed in the message. message
2332 * length is incremented. return is ok.
2334 * if message is not empty: data is read by source pointer,
2335 * data is placed in back of all other data in message.
2336 * message length is incremented. return is ok.
2338 * the first byte of data pointed to by the source pointer will
2339 * be placed at the back of the message first, the last byte of
2340 * data pointed to by the source pointer will be placed at the
2341 * back of the message last (i.e. it will become the last
2342 * byte of the message).
2348 #ifdef T2K_MEM_LEAK_DBG
2349 PUBLIC S16 SAddPstMsgMult1
2359 PUBLIC S16 SAddPstMsgMult
2366 PUBLIC S16 SAddPstMsgMult(src, cnt, mBuf)
2376 Buffer *curblk=NULLP;
2383 TRC1(SAddPstMsgMult)
2385 #if (ERRCLASS & ERRCLS_INT_PAR)
2386 /* check message buffer */
2389 SSLOGERROR(ERRCLS_INT_PAR, ESS074, ERRZERO, "SAddPstMsgMult:Null Buffer");
2395 SSLOGERROR(ERRCLS_INT_PAR, ESS075, ERRZERO, "SAddPstMsgMult:Null Buffer");
2401 SSLOGERROR(ERRCLS_INT_PAR, ESS076, ERRZERO, "SAddPstMsgMult:Invalid\
2405 if (mBuf->b_datap->db_type != SS_M_PROTO)
2407 SSLOGERROR(ERRCLS_INT_PAR, ESS077, ERRZERO, "SAddPstMsgMult: Incorrect\
2413 /* get the SsMsgInfo of mBuf */
2414 minfo = (SsMsgInfo*) mBuf->b_rptr;
2416 /* store cnt in len */
2419 /* ss014.13: Addition */
2422 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
2423 (tmp->b_datap->db_lim > tmp->b_wptr))
2425 /* store offset of the write pointer */
2426 /* incase subsequent allocations fail, offset is read reset to original */
2427 offset = tmp->b_datap->db_lim - tmp->b_wptr;
2429 /* determine the number of bytes to copy */
2430 numBytes = MIN(cnt, offset);
2436 /* ss002.13: addition */
2438 /* ss004.13: addition */
2439 SMemCpy((Void *) tmp->b_wptr, (Void *) src, (size_t) numBytes);
2441 tmp->b_wptr += numBytes;
2451 newblk = prevblk = NULLP;
2455 /* allocate a message blk */
2456 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2458 while ((curblk = newblk))
2460 newblk = newblk->b_cont;
2461 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2466 tmp->b_wptr = tmp->b_datap->db_lim - offset;
2472 /* insert curblk in the newblk chain */
2474 prevblk->b_cont = curblk; /* stack them down */
2480 wptr = curblk->b_wptr;
2481 numBytes = MIN(cnt, curblk->b_datap->db_lim - wptr);
2487 /* ss002.13: addition */
2488 /* ss003.13: addition */
2489 SMemCpy( (Void *) wptr, (Void *) src, (size_t) numBytes);
2491 src = src + numBytes;
2493 curblk->b_wptr += numBytes;
2495 /* insert newblk chain into mBuf */
2497 tmp->b_cont = newblk;
2499 mBuf->b_cont = newblk;
2500 minfo->endptr = curblk;
2508 /* #ifdef SS_LOCKLESS_MEMORY */
2516 * Desc: This function copies and then removes one byte of
2517 * data from the beginning of a message.
2520 * ROKDNA - ok, data not available
2521 * RFAILED - failed, general (optional)
2523 * Notes: if message is empty: message is unchanged. return is ok,
2524 * data not available.
2526 * if message is not empty: data is removed from front of
2527 * message, data is returned via pointer to data. message
2528 * length is decremented. return is ok.
2536 PUBLIC S16 SRemPreMsg
2542 PUBLIC S16 SRemPreMsg(dataPtr, mBuf)
2549 #ifdef T2K_MEM_LEAK_DBG
2550 char* file = __FILE__;
2551 U32 line = __LINE__;
2556 #if (ERRCLASS & ERRCLS_INT_PAR)
2557 /* check data pointer */
2560 SSLOGERROR(ERRCLS_INT_PAR, ESS078, ERRZERO, "SRemPreMsg : Null Buffer");
2563 /* check message buffer */
2566 SSLOGERROR(ERRCLS_INT_PAR, ESS079, ERRZERO, "SRemPreMsg : Null Buffer");
2569 if (mBuf->b_datap->db_type != SS_M_PROTO)
2571 SSLOGERROR(ERRCLS_INT_PAR, ESS080, ERRZERO, "SRemPreMsg : Incorrect\
2577 if (!(tmp = mBuf->b_cont))
2580 /* get SsMsgInfo of mBuf */
2581 minfo = (SsMsgInfo *) mBuf->b_rptr;
2583 /* read databyte into dataPtr and incrment read ptr */
2584 *dataPtr = *tmp->b_rptr++;
2586 /* if all data is exhausted, release the blk */
2587 if (tmp->b_rptr == tmp->b_wptr)
2589 mBuf->b_cont = tmp->b_cont;
2590 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2592 /* update SsMsgInfo */
2594 minfo->endptr = NULLP;
2603 * Desc: This function copies and then removes one byte of
2604 * data from the end of a message.
2607 * ROKDNA - ok, data not available
2608 * RFAILED - failed, general (optional)
2610 * Notes: if message is empty: message is unchanged. return is ok,
2611 * data not available.
2613 * if message is not empty: data is removed from back of
2614 * message, data is returned via pointer to data. message
2615 * length is decremented. return is ok.
2623 PUBLIC S16 SRemPstMsg
2625 Data *dataPtr, /* pointer to data */
2629 PUBLIC S16 SRemPstMsg(dataPtr, mBuf)
2630 Data *dataPtr; /* pointer to data */
2631 Buffer *mBuf; /* message buffer */
2637 #ifdef T2K_MEM_LEAK_DBG
2638 char* file = __FILE__;
2639 U32 line = __LINE__;
2644 #if (ERRCLASS & ERRCLS_INT_PAR)
2645 /* check data pointer */
2646 if (dataPtr == NULLP)
2648 SSLOGERROR(ERRCLS_INT_PAR, ESS081, ERRZERO, "SRemPstMsg : Null Buffer");
2651 /* check message buffer */
2654 SSLOGERROR(ERRCLS_INT_PAR, ESS082, ERRZERO, "SRemPstMsg : Null Buffer");
2657 if (mBuf->b_datap->db_type != SS_M_PROTO)
2659 SSLOGERROR(ERRCLS_INT_PAR, ESS083, ERRZERO, "SRemPstMsg : Incorrect\
2665 /* get the SsMsgInfo */
2666 minfo = (SsMsgInfo*) mBuf->b_rptr;
2668 if (!(last = minfo->endptr))
2671 /* read databyte into dataPtr and decrement write ptr */
2672 *dataPtr = *--last->b_wptr;
2674 /* if all data is exhausted, release the blk */
2675 if (last->b_rptr == last->b_wptr)
2677 for (tmp = mBuf; tmp->b_cont != last;)
2679 tmp->b_cont = NULLP;
2680 (Void) SPutDBuf(minfo->region, minfo->pool, last);
2684 minfo->endptr = tmp;
2686 minfo->endptr = NULLP;
2688 /* update SsMsgInfo */
2697 * Fun: SRemPreMsgMult
2699 * Desc: This function copies and then removes consecutive bytes of
2700 * data from the beginning of a message.
2703 * ROKDNA - ok, data not available
2704 * RFAILED - failed, general (optional)
2706 * Notes: if message is empty: message is unchanged. return is ok,
2707 * data not available.
2709 * if the destination buffer is NULL, data is not copied.
2711 * if message is not empty: data is removed from front of
2712 * message, data is returned by destination pointer. message
2713 * length is decremented. return is ok.
2715 * the first byte of data read from the message will be placed
2716 * in the destination buffer first (i.e. this was the first byte
2717 * of the message), the last byte of data read from the message
2718 * will be placed in the destination buffer last.
2725 PUBLIC S16 SRemPreMsgMult
2727 Data *dst, /* destination */
2728 MsgLen cnt, /* count */
2732 PUBLIC S16 SRemPreMsgMult(dst, cnt, mBuf)
2733 Data *dst; /* destination */
2734 MsgLen cnt; /* count */
2735 Buffer *mBuf; /* message buffer */
2741 #ifdef T2K_MEM_LEAK_DBG
2742 char* file = __FILE__;
2743 U32 line = __LINE__;
2746 TRC1(SRemPreMsgMult)
2748 /* ss023.103 - Modification of SRemPreMsgMult for bug fix */
2750 #if (ERRCLASS & ERRCLS_INT_PAR)
2754 SSLOGERROR(ERRCLS_INT_PAR, ESS084, ERRZERO, "SRemPreMsgMult:Invalid\
2758 /* check message buffer */
2761 SSLOGERROR(ERRCLS_INT_PAR, ESS085, ERRZERO, "SRemPreMsgMult:Null Buffer");
2764 /* ss021.103 - Addition to check for NULL pointer */
2765 /* check data pointer */
2766 /* ss022.103 - Removed check for NULL pointer */
2767 if (mBuf->b_datap->db_type != SS_M_PROTO)
2769 SSLOGERROR(ERRCLS_INT_PAR, ESS086, ERRZERO, "SRemPreMsgMult : Incorrect\
2775 /* get the SsMsgInfo */
2776 minfo = (SsMsgInfo*) mBuf->b_rptr;
2778 /* check if data present */
2779 if (minfo->len < cnt)
2786 /* get the first SS_M_DATA blk */
2789 /* determine the number of bytes to be copy */
2790 numBytes = MIN(cnt, tmp->b_wptr - tmp->b_rptr);
2795 /* move data into dst */
2799 SMemCpy( (Void *) dst, (Void *) tmp->b_rptr, (size_t) numBytes);
2803 tmp->b_rptr += numBytes;
2805 if (tmp->b_rptr == tmp->b_wptr)
2807 mBuf->b_cont = tmp->b_cont;
2808 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2811 /* update SsMsgInfo */
2813 minfo->endptr = NULLP;
2820 * Fun: SRemPstMsgMult
2822 * Desc: This function copies and then removes consecutive bytes of
2823 * data from the end of a message.
2826 * ROKDNA - ok, data not available
2827 * RFAILED - failed, general (optional)
2829 * Notes: if message is empty: message is unchanged. return is ok,
2830 * data not available.
2832 * if the destination buffer is NULL, data is not copied.
2834 * if message is not empty: data is removed from front of
2835 * message, data is returned by destination pointer. message
2836 * length is decremented. return is ok.
2838 * the first byte of data read from the message will be placed
2839 * in the destination buffer first (i.e. this was the last byte
2840 * of the message), the last byte of data read from the message
2841 * will be placed in the destination buffer last.
2848 PUBLIC S16 SRemPstMsgMult
2850 Data *dst, /* destination */
2851 MsgLen cnt, /* count */
2855 PUBLIC S16 SRemPstMsgMult(dst, cnt, mBuf)
2856 Data *dst; /* destination */
2857 MsgLen cnt; /* count */
2858 Buffer *mBuf; /* message buffer */
2867 #ifdef T2K_MEM_LEAK_DBG
2868 char* file = __FILE__;
2869 U32 line = __LINE__;
2872 TRC1(SRemPstMsgMult)
2874 #if (ERRCLASS & ERRCLS_INT_PAR)
2878 SSLOGERROR(ERRCLS_INT_PAR, ESS087, ERRZERO, "SRemPstMsgMult:Invalid\
2882 /* check message buffer */
2885 SSLOGERROR(ERRCLS_INT_PAR, ESS088, ERRZERO, "SRemPstMsgMult:Null Buffer");
2888 if (mBuf->b_datap->db_type != SS_M_PROTO)
2890 SSLOGERROR(ERRCLS_INT_PAR, ESS089, ERRZERO, "SRemPstMsgMult : Incorrect\
2894 /* ss021.103 - Addition to check dst data pointer */
2895 /* check data pointer */
2896 /* ss022.103 - Removed check for NULL destination pointer */
2899 /* get the SsMsgInfo */
2900 minfo = (SsMsgInfo*) mBuf->b_rptr;
2902 /* check if data present */
2903 if (minfo->len < cnt)
2913 /* determine blk containing offset, and prev node */
2914 FIND_OFFSET_AND_PREV(prev, tmp, count)
2921 numBytes = MIN(cnt, (tmp->b_wptr - tmp->b_rptr - count));
2923 tmp->b_wptr -= numBytes;
2935 if (tmp->b_rptr == tmp->b_wptr)
2937 prev->b_cont = tmp->b_cont;
2938 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2947 minfo->endptr = NULLP;
2949 minfo->endptr = prev;
2958 * Desc: This function copies one byte of data from a message
2959 * without modifying the message.
2962 * ROKDNA - ok, data not available
2963 * RFAILED - failed, general (optional)
2965 * Notes: index is 0 based and indicates location in message
2967 * if index is less than the length of the message:
2968 * message is unchanged and data is examined at specified
2969 * index and returned via pointer to data. message length
2970 * is unchanged. return is ok.
2972 * if index is greater than or equal to
2973 * the length of the message: message is unchanged and 0
2974 * is returned via pointer to data. return is ok, data
2985 Data *dataPtr, /* pointer to data */
2986 Buffer *mBuf, /* message buffer */
2990 PUBLIC S16 SExamMsg(dataPtr, mBuf, idx)
2991 Data *dataPtr; /* pointer to data */
2992 Buffer *mBuf; /* message buffer */
2993 MsgLen idx; /* index */
3001 #if (ERRCLASS & ERRCLS_INT_PAR)
3002 /* check data pointer */
3005 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SExamMsg : Null Buffer");
3008 /* check message buffer */
3011 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SExamMsg : Null Buffer");
3017 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SExamMsg : Invalid Index");
3020 if (mBuf->b_datap->db_type != SS_M_PROTO)
3022 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SExamMsg : Incorrect buffer\
3028 /* get the SsMsgInfo */
3029 minfo = (SsMsgInfo*) mBuf->b_rptr;
3031 if (minfo->len <= idx)
3036 /* get the first SS_M_DATA blk */
3039 /* determine offset */
3040 FIND_OFFSET(tmp, idx)
3042 *dataPtr = *(tmp->b_rptr + idx);
3051 * Fun: SGetDataFrmMsg
3053 * Desc: This function copies requested byte of data from a message
3054 * without modifying the message.
3057 * ROKDNA - ok, data not available
3058 * RFAILED - failed, general (optional)
3060 * Notes: index is 0 based and indicates location in message
3062 * if index is less than the length of the message:
3063 * message is unchanged and data is examined at specified
3064 * index and returned via pointer to data. message length
3065 * is unchanged. return is ok.
3067 * if index is greater than or equal to
3068 * the length of the message: message is unchanged and 0
3069 * is returned via pointer to data. return is ok, data
3078 PUBLIC S16 SGetDataFrmMsg
3080 Buffer *mBuf, /* message buffer */
3081 Data *dataPtr, /* pointer to data */
3086 PUBLIC S16 SGetDataFrmMsg(mBuf, dataPtr, idx, dataLen)
3087 Buffer *mBuf; /* message buffer */
3088 Data *dataPtr; /* pointer to data */
3089 MsgLen idx; /* index */
3096 Data *tmpDataPtr = dataPtr;
3098 TRC1(SGetDataFrmMsg)
3100 #if (ERRCLASS & ERRCLS_INT_PAR)
3101 /* check data pointer */
3104 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SGetDataFrmMsg: Null Buffer");
3107 /* check message buffer */
3110 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SGetDataFrmMsg: Null Buffer");
3116 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SGetDataFrmMsg: Invalid Index");
3119 if (mBuf->b_datap->db_type != SS_M_PROTO)
3121 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SGetDataFrmMsg: Incorrect buffer\
3127 /* get the SsMsgInfo */
3128 minfo = (SsMsgInfo*) mBuf->b_rptr;
3130 if (minfo->len <= (idx + dataLen) )
3135 /* get the first SS_M_DATA blk */
3138 /* determine offset */
3145 FIND_OFFSET(tmp, idx)
3146 offSetLen = ((tmp->b_wptr - (tmp->b_rptr + idx)));
3148 for(;(offSetLen < dataLen && tmp != NULLP);)
3150 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)offSetLen);
3151 dataLen = dataLen - offSetLen;
3154 tmpDataPtr = tmpDataPtr + offSetLen;
3155 offSetLen = tmp->b_wptr - tmp->b_rptr;
3161 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)dataLen);
3165 } /* End of SGetDataFrmMsg() */
3171 * Desc: This function determines the length of data within
3175 * RFAILED - failed, general (optional)
3177 * Notes: length of message is determined, message is unchanged
3178 * and length is returned via pointer to length. return is ok.
3186 PUBLIC S16 SFndLenMsg
3188 REG1 Buffer *mBuf, /* message buffer */
3192 PUBLIC S16 SFndLenMsg(mBuf, lngPtr)
3193 REG1 Buffer *mBuf; /* message buffer */
3194 MsgLen *lngPtr; /* pointer to length */
3201 #if (ERRCLASS & ERRCLS_INT_PAR)
3202 /* check message buffer */
3205 SSLOGERROR(ERRCLS_INT_PAR, ESS094, ERRZERO, "SFndLenMsg : Null Buffer");
3208 /* check length pointer */
3209 if (lngPtr == NULLP)
3211 SSLOGERROR(ERRCLS_INT_PAR, ESS095, ERRZERO, "SFndLenMsg : Null Buffer");
3214 if (mBuf->b_datap->db_type != SS_M_PROTO)
3216 SSLOGERROR(ERRCLS_INT_PAR, ESS096, ERRZERO, "SFndLenMsg : Incorrect\
3222 /* get the SsMsgInfo */
3223 minfo = (SsMsgInfo*) mBuf->b_rptr;
3226 *lngPtr = minfo->len;
3232 /* #ifdef SS_LOCKLESS_MEMORY */
3238 * Desc: This function will segment one specified message into two
3242 * ROKDNA - ok, data not available
3243 * RFAILED - failed, general (optional)
3244 * ROUTRES - failed, out of resources (optional)
3246 * Notes: message 1 is the original message.
3248 * message 2 is the new message.
3250 * index is 0 based and indicates location in message 1
3251 * from which message 2 will be created.
3253 * if index is equal to 0: message 2 is created and all data
3254 * attached to message 1 is moved to message 2. message 1
3255 * is not returned to memory. return is ok.
3257 * if index is not equal to 0 and less than the length of
3258 * the message minus 1: message 2 is created, all data
3259 * attached to message 1 from index (inclusive) is moved to
3260 * message 2. message 1 contains data from index 0 to index
3261 * minus 1. return is ok.
3263 * if index is not equal to 0 and greater than or equal to
3264 * the length of the message minus 1: message 1 is unchanged.
3265 * message 2 is set to null. return is ok, data not available.
3270 #ifdef T2K_MEM_LEAK_DBG
3271 PUBLIC S16 SSegMsgNew
3273 Buffer *mBuf1, /* message 1 */
3274 MsgLen idx, /* index */
3283 Buffer *mBuf1, /* message 1 */
3284 MsgLen idx, /* index */
3288 PUBLIC S16 SSegMsg(mBuf1, idx, mBuf2)
3289 Buffer *mBuf1; /* message 1 */
3290 MsgLen idx; /* index */
3291 Buffer **mBuf2; /* message 2 */
3303 #if (ERRCLASS & ERRCLS_INT_PAR)
3304 /* check message buffer 1 */
3307 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SSegMsg : Null Buffer");
3310 /* check message buffer 2 */
3313 SSLOGERROR(ERRCLS_INT_PAR, ESS098, ERRZERO, "SSegMsg : Null Buffer");
3318 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SSegMsg : Invalid index");
3321 if (mBuf1->b_datap->db_type != SS_M_PROTO)
3323 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SSegMsg : Incorrect buffer\
3329 /* get the SsMsgInfo of mBuf1 */
3330 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
3331 #ifdef RGL_SPECIFIC_CHANGES
3335 /* if index > length of mBuf, return */
3336 if (idx >= minfo1->len)
3341 /* allocate message buffer */
3342 if (SGetMsg(minfo1->region, minfo1->pool, mBuf2) != ROK)
3344 SSLOGERROR(ERRCLS_DEBUG, ESS101, ERRZERO, "SSegMsg : SGetMsg failed");
3348 /* get the SsMsgInfo of mBuf2 */
3349 minfo2 = (SsMsgInfo*) (*mBuf2)->b_rptr;
3351 /* adjust the lengths of mBuf1, mBuf2 */
3352 minfo2->len = minfo1->len - idx;
3355 /* set the endptr of mBuf2 to mBuf1 */
3356 minfo2->endptr = minfo1->endptr;
3358 /* if index is zero ... */
3361 (*mBuf2)->b_cont = mBuf1->b_cont;
3363 /* set the endptr and b_cont of mBuf1 to NULLP */
3364 minfo1->endptr = NULLP;
3365 mBuf1->b_cont = NULLP;
3370 /* get the first SS_M_DATA blk */
3371 tmp = mBuf1->b_cont;
3374 FIND_OFFSET_AND_PREV(prev, tmp, idx)
3376 /* segmented at the start of a blk */
3379 (*mBuf2)->b_cont = tmp;
3380 prev->b_cont = NULLP;
3381 minfo1->endptr = prev;
3385 #ifndef SS_MULTICORE_SUPPORT
3386 /* allocate a message blk without a data blk */
3387 /* ssDupB internally increments the reference count */
3388 #ifdef SS_M_PROTO_REGION
3389 if (!(next = DupMsg(minfo1->region, tmp)))
3391 if (!(next = ssDupB(tmp)))
3392 #endif /* SS_M_PROTO_REGION */
3395 minfo1->len += minfo2->len;
3396 (Void) SPutMsg(*mBuf2);
3400 (*mBuf2)->b_cont = next;
3402 tmp->b_cont = NULLP;
3404 tmp->b_wptr = tmp->b_rptr + idx;
3405 next->b_rptr = tmp->b_wptr;
3407 /* If the index was in the last mblk of the message, the
3408 * end pointer of the new message needs to be set to the
3409 * dup'ped mblk. Otherwise, the end pointer of the first
3410 * message will be set to the mblk in which the index
3411 * was found, and the end pointer of the new message can
3412 * remain where it is.
3414 if (minfo1->endptr == tmp)
3416 minfo2->endptr = next;
3420 minfo1->endptr = tmp;
3422 #else /*SS_MULTICORE_SUPPORT*/
3426 #ifdef SS_M_PROTO_REGION
3427 if (!(next = DupMsg(minfo1->region, tmp)))
3429 if (!(next = ssDupB(tmp)))
3430 #endif /* SS_M_PROTO_REGION */
3433 minfo1->len += minfo2->len;
3434 (Void) SPutMsg(*mBuf2);
3437 (*mBuf2)->b_cont = next;
3438 tmp->b_wptr = tmp->b_rptr + idx;
3439 next->b_rptr += idx;
3442 /* copy rest of the blocks */
3446 prev->b_cont = NULLP;
3447 minfo2->endptr = minfo1->endptr;
3448 minfo1->endptr = prev;
3452 next->b_cont = NULLP;
3453 minfo2->endptr = next;
3456 #endif /*SS_MULTICORE_SUPPORT*/
3466 * Desc: This function copies data from a fixed buffer to a
3470 * RFAILED - failed, general (optional)
3479 PUBLIC S16 SCpyFixMsg
3481 Data *srcBuf, /* source buffer */
3482 Buffer *dstMbuf, /* destination message buffer */
3483 MsgLen dstIdx, /* destination index */
3484 MsgLen cnt, /* count */
3488 PUBLIC S16 SCpyFixMsg(srcBuf, dstMbuf, dstIdx, cnt, cCnt)
3489 Data *srcBuf; /* source buffer */
3490 Buffer *dstMbuf; /* destination message buffer */
3491 MsgLen dstIdx; /* destination index */
3492 MsgLen cnt; /* count */
3493 MsgLen *cCnt; /* copied count */
3502 #if (ERRCLASS & ERRCLS_INT_PAR)
3503 /* check source message buffer */
3504 if (srcBuf == NULLP)
3506 SSLOGERROR(ERRCLS_INT_PAR, ESS102, ERRZERO, "SCpyFixMsg : Null Buffer");
3509 /* check destination message buffer */
3510 if (dstMbuf == NULLP)
3512 SSLOGERROR(ERRCLS_INT_PAR, ESS103, ERRZERO, "SCpyFixMsg : Null Buffer");
3515 /* check copied count buffer */
3518 SSLOGERROR(ERRCLS_INT_PAR, ESS104, ERRZERO, "SCpyFixMsg : Null Buffer");
3521 /* check copy count */
3524 SSLOGERROR(ERRCLS_INT_PAR, ESS105, ERRZERO, "SCpyFixMsg : Invalid count");
3527 if (dstMbuf->b_datap->db_type != SS_M_PROTO)
3529 SSLOGERROR(ERRCLS_INT_PAR, ESS106, ERRZERO, "SCpyFixMsg : Incorrect\
3535 minfo = (SsMsgInfo*) dstMbuf->b_rptr;
3537 if (minfo->len < dstIdx)
3539 #if (ERRCLASS & ERRCLS_DEBUG)
3540 SSLOGERROR(ERRCLS_DEBUG, ESS107, ERRZERO, "SCpyFixMsg : Invalid Index");
3545 /* ss021.103 - Addition test if message length will exceed max msg length */
3546 #if (ERRCLASS & ERRCLS_INT_PAR)
3548 if (minfo->len > 0x7FFFFFFF - cnt)
3550 if (minfo->len > 0x7FFF - cnt)
3555 SSLOGERROR(ERRCLS_INT_PAR, ESS108, ERRZERO, "SCpyFixMsg : msgLen + cnt > maxS16");
3560 /* add data at the start of dst buffer */
3563 if ((ret = SAddPreMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3565 #if (ERRCLASS & ERRCLS_DEBUG)
3566 SSLOGERROR(ERRCLS_DEBUG, ESS109, ERRZERO, "SCpyFixMsg : Failed in\
3576 /* add data at the end of the dst buffer */
3577 if (minfo->len == dstIdx)
3579 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3588 /* segment the message into dstMbuf and right */
3589 if ((ret = SSegMsg(dstMbuf, dstIdx, &right)) != ROK)
3594 /* append data at the end of dstMbuf */
3595 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3597 /* ss020.103 - Addition for cleanup */
3598 (Void) SPutMsg(right);
3602 /* cancatenate dstMbuf and right */
3603 if ((ret = SCatMsg(dstMbuf, right, M1M2)) != ROK)
3605 /* ss020.103 - Addition for cleanup */
3606 (Void) SPutMsg(right);
3612 (Void) SPutMsg(right);
3621 * Desc: This function copies data from a message
3622 * into a fixed buffer.
3625 * RFAILED - failed, general (optional)
3634 PUBLIC S16 SCpyMsgFix
3636 Buffer *srcMbuf, /* source message buffer */
3637 MsgLen srcIdx, /* source index */
3638 MsgLen cnt, /* count */
3639 Data *dstBuf, /* destination buffer */
3643 PUBLIC S16 SCpyMsgFix(srcMbuf, srcIdx, cnt, dstBuf, cCnt)
3644 Buffer *srcMbuf; /* source message buffer */
3645 MsgLen srcIdx; /* source index */
3646 MsgLen cnt; /* count */
3647 Data *dstBuf; /* destination buffer */
3648 MsgLen *cCnt; /* copied count */
3658 #if (ERRCLASS & ERRCLS_INT_PAR)
3659 /* check source message buffer */
3660 if (srcMbuf == NULLP)
3662 SSLOGERROR(ERRCLS_INT_PAR, ESS110, ERRZERO, "SCpyMsgFix : Null Buffer");
3665 /* check destination message buffer */
3666 if (dstBuf == NULLP)
3668 SSLOGERROR(ERRCLS_INT_PAR, ESS111, ERRZERO, "SCpyMsgFix : Null Buffer");
3673 SSLOGERROR(ERRCLS_INT_PAR, ESS112, ERRZERO, "SCpyMsgFix : Invalid Index");
3679 SSLOGERROR(ERRCLS_INT_PAR, ESS113, ERRZERO, "SCpyMsgFix : Invalid Index");
3684 SSLOGERROR(ERRCLS_INT_PAR, ESS114, ERRZERO, "SCpyMsgFix : Null Buffer");
3687 if (srcMbuf->b_datap->db_type != SS_M_PROTO)
3689 SSLOGERROR(ERRCLS_INT_PAR, ESS115, ERRZERO, "SCpyMsgFix : Incorrect\
3696 minfo = (SsMsgInfo*) srcMbuf->b_rptr;
3698 if ((srcIdx + cnt) > minfo->len)
3704 /* get the first SS_M_DATA blk */
3705 tmp = srcMbuf->b_cont;
3707 /* get to the srcIdx-th offset */
3708 FIND_OFFSET(tmp, srcIdx)
3712 /* set cptr to the read ptr of tmp + offset */
3713 cptr = tmp->b_rptr + srcIdx;
3717 /* determine the number of bytes to be copied */
3718 numBytes = MIN(cnt, (tmp->b_wptr - cptr));
3725 /* ss002.13 addition */
3727 /* ss003.13 addition */
3728 SMemCpy((Void *) dstBuf, (Void *) cptr, (size_t) numBytes);
3734 /* get the next blk */
3735 if ((tmp = tmp->b_cont))
3736 /* set cptr to the read ptr of tmp */
3749 * Desc: This function is used to copy a message into
3750 * a new region and or pool of memory.
3753 * RFAILED - failed, general (optional)
3754 * ROUTRES - failed, out of resources (optional)
3762 #ifdef T2K_MEM_LEAK_DBG
3763 PUBLIC S16 SCpyMsgMsgNew
3774 PUBLIC S16 SCpyMsgMsg
3782 PUBLIC S16 SCpyMsgMsg(srcBuf, dstRegion, dstPool, dstBuf)
3797 /* ss021.103 - Addition of return value */
3799 #if (ERRCLASS & ERRCLS_INT_PAR)
3806 #if (ERRCLASS & ERRCLS_INT_PAR)
3809 SSLOGERROR(ERRCLS_INT_PAR, ESS116, ERRZERO, "SCpyMsgMsg : Null Buffer");
3812 if (srcBuf->b_datap->db_type != SS_M_PROTO)
3814 SSLOGERROR(ERRCLS_INT_PAR, ESS117, ERRZERO, "SCpyMsgMsg : Incorrect\
3818 /* ss021.103 - Addition to validate region and pool */
3819 if (dstRegion >= SS_MAX_REGS)
3821 SSLOGERROR(ERRCLS_INT_PAR, ESS118, ERRZERO,
3822 "SCpyMsgMsg : Invalid region id");
3826 if (dstPool >= SS_MAX_POOLS_PER_REG)
3828 SSLOGERROR(ERRCLS_INT_PAR, ESS119, ERRZERO,
3829 "SCpyMsgMsg : Invalid pool id");
3832 /* ss037.103 Removed the semaphore operation for performance enhancement */
3835 /* ss021.103 - Addition to check if region is valid */
3836 /* acquire one semaphore, to protect against deregistration */
3837 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
3841 #if (ERRCLASS & ERRCLS_DEBUG)
3842 SSLOGERROR(ERRCLS_DEBUG, ESS120, (ErrVal) ret,
3843 "Could not lock region table");
3850 #if (ERRCLASS & ERRCLS_INT_PAR)
3851 /* verify that this region is present */
3852 if (osCp.regionTbl[dstRegion].used == FALSE)
3855 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3857 #if (ERRCLASS & ERRCLS_DEBUG)
3858 SSLOGERROR(ERRCLS_DEBUG, ESS121, ERRZERO,
3859 "Could not release semaphore");
3864 SSLOGERROR(ERRCLS_INT_PAR, ESS122, dstRegion, "Region not registered");
3868 /* ss037.103 Removed the semaphore operation for performance enhancement */
3871 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3873 #if (ERRCLASS & ERRCLS_DEBUG)
3874 SSLOGERROR(ERRCLS_DEBUG, ESS123, ERRZERO,
3875 "Could not release semaphore");
3882 #ifdef XEON_SPECIFIC_CHANGES
3886 /* allocate a message buffer */
3887 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
3889 #if (ERRCLASS & ERRCLS_DEBUG)
3890 SSLOGERROR(ERRCLS_DEBUG, ESS124, ERRZERO, "SCpyMsgMsg : SGetMsg failed");
3894 /* get the SsMsgInfo from srcBuf */
3895 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
3897 /* get the SsMsgInfo from srcBuf */
3898 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
3900 /* get the first SS_M_DATA blk of srcBuf */
3901 tmp = srcBuf->b_cont;
3903 /* if srcBuf and dstBuf belong to the same region, increment the reference
3912 #ifdef SS_M_PROTO_REGION
3913 if ((curblk = DupMsg(dstRegion,tmp)) == NULLP)
3915 if ((curblk = ssDupB(tmp)) == NULLP)
3916 #endif /* SS_M_PROTO_REGION */
3920 curblk = newblk->b_cont;
3921 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
3924 printf("Failed to get the buffer of size %s %d\n", __FILE__, __LINE__);
3925 (Void) SPutMsg(*dstBuf);
3932 prevblk->b_cont = curblk;
3938 curblk->b_cont = NULLP;
3940 minfo2->len = minfo1->len;
3941 minfo2->endptr = curblk;
3942 (*dstBuf)->b_cont = newblk;
3953 * Desc: This function is used to copy a message into
3954 * a new region and or pool of memory.
3957 * RFAILED - failed, general (optional)
3958 * ROUTRES - failed, out of resources (optional)
3965 #ifdef T2K_MEM_LEAK_DBG
3966 PUBLIC S16 SAddMsgRefNew
3977 PUBLIC S16 SAddMsgRef
3985 PUBLIC S16 SAddMsgRef(srcBuf, dstRegion, dstPool, dstBuf)
4005 #if (ERRCLASS & ERRCLS_INT_PAR)
4008 SSLOGERROR(ERRCLS_INT_PAR, ESS126, ERRZERO, "SAddMsgRef : Null Buffer");
4011 if (srcBuf->b_datap->db_type != SS_M_PROTO)
4013 SSLOGERROR(ERRCLS_INT_PAR, ESS127, ERRZERO, "SAddMsgRef : Incorrect\
4018 #ifdef XEON_SPECIFIC_CHANGES
4023 /* allocate a message buffer */
4024 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
4026 #if (ERRCLASS & ERRCLS_DEBUG)
4027 SSLOGERROR(ERRCLS_DEBUG, ESS128, ERRZERO, "SAddMsgRef : SGetMsg failed");
4031 /* get the SsMsgInfo from srcBuf */
4032 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
4034 /* get the SsMsgInfo from srcBuf */
4035 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
4037 /* get the first SS_M_DATA blk of srcBuf */
4038 tmp = srcBuf->b_cont;
4040 /* if srcBuf and dstBuf belong to the same region, increment the reference
4043 if (dstRegion == minfo1->region)
4051 #ifdef SS_M_PROTO_REGION
4052 if ((curblk = DupMsg(dstRegion, tmp)) == NULLP)
4054 if ((curblk = ssDupB(tmp)) == NULLP)
4055 #endif /* SS_M_PROTO_REGION */
4059 curblk = newblk->b_cont;
4060 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
4063 (Void) SPutMsg(*dstBuf);
4070 prevblk->b_cont = curblk;
4076 curblk->b_cont = NULLP;
4078 minfo2->len = minfo1->len;
4079 minfo2->endptr = curblk;
4080 (*dstBuf)->b_cont = newblk;
4085 /* allocate a data buffer */
4086 if (ssGetDBufOfSize(dstRegion, minfo1->len, &dBuf) != ROK)
4088 /* ss016.13: addition */
4089 (Void) SPutMsg(*dstBuf);
4090 SSLOGERROR(ERRCLS_DEBUG, ESS129, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
4094 dBuf->b_datap->db_type = SS_M_DATA;
4098 numBytes = tmp->b_wptr - tmp->b_rptr;
4101 *dBuf->b_wptr++ = *cptr++;
4104 minfo2->len = minfo1->len;
4105 /* set the endptr and b_cont of dstBuf to point to dBuf */
4106 minfo2->endptr = dBuf;
4107 (*dstBuf)->b_cont = dBuf;
4111 /* ss012.13: Addition */
4112 #ifdef SS_M_PROTO_REGION
4117 * Desc: Duplicates the specified message block, copying it
4118 * into a newly-allocated message block. Increments
4119 * the reference count of the data block that is pointed
4120 * at by the original message block descriptor.
4122 * Ret: non-NULL - ok
4130 #ifdef T2K_MEM_LEAK_DBG
4131 PRIVATE Buffer *DupMsgNew
4133 Region region, /* region id */
4134 Buffer *mp, /* message block */
4140 PRIVATE Buffer *DupMsg
4142 Region region, /* region id */
4143 Buffer *mp /* message block */
4146 PRIVATE Buffer *DupMsg(region, mp)
4147 Region region; /* region id */
4148 Buffer *mp; /* message block */
4152 Buffer *bp; /* mblk for iteration */
4153 S16 r; /* return value */
4154 Size m; /* temporary */
4159 #if (ERRCLASS & ERRCLS_INT_PAR)
4162 SSLOGERROR(ERRCLS_INT_PAR, ESS130, ERRZERO, "Null pointer");
4166 if (region >= SS_MAX_REGS)
4168 SSLOGERROR(ERRCLS_INT_PAR, ESS131, ERRZERO, "DupMsg : Invalid region\
4175 /* allocate a single block for the mblock and the dblock */
4177 m = (sizeof(SsMblk) + sizeof(SsDblk));
4179 numBytes = mp->b_wptr - mp->b_rptr;
4180 m = MDBSIZE + numBytes;
4181 #endif /* SS_MULTICORE_SUPPORT */
4182 /* ss001.301: additions */
4183 #ifdef SS_HISTOGRAM_SUPPORT
4184 r = SAlloc(region, &m, 0, (Data **)&bp, __LINE__, (U8*) __FILE__, ENTNC);
4186 r = SAlloc(region, &m, 0, (Data **)&bp);
4187 #endif /* SS_HISTOGRAM_SUPPORT */
4190 #if (ERRCLASS & ERRCLS_ADD_RES)
4191 SSLOGERROR(ERRCLS_ADD_RES, ESS132, (ErrVal) r, "SAlloc() failed");
4196 /* generic set-up-message function */
4198 #ifndef SS_DBUF_REFLOCK_DISABLE
4199 SS_STRM_INITB(bp, (SsDblk *)(((U8 *)bp) + sizeof(SsMblk)), NULLP, 0, NULLP);
4202 data = (Data *) (bp) + MDBSIZE;
4203 SS_STRM_INITB(bp,(SsDblk *)(((U8 *)bp) + sizeof(SsMblk)), data, numBytes, NULLP);
4204 #endif /* SS_MULTICORE_SUPPORT */
4207 /* make the new message block identical to the one to be dup'ed.
4208 * notice that an mblk/dblk pair is allocated but only the mblk
4209 * is used,, this is for optimum performance in the average case.
4211 SMemCpy( (Void *)bp, (Void *)mp, (size_t)sizeof(SsMblk));
4213 /* ss006.301 - added the Lock */
4214 #ifndef SS_DBUF_REFLOCK_DISABLE
4215 if((SLock(&(mp->b_datap->dBufLock))) != ROK)
4217 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
4218 "Could not lock the mBuf Ref Lock");
4222 /* increment the reference count of the dblock */
4223 /* increment the reference count of the dblock */
4224 mp->b_datap->db_ref++;
4225 mp->b_datap->shared = TRUE;
4226 #ifndef SS_DBUF_REFLOCK_DISABLE
4227 if((SUnlock(&(mp->b_datap->dBufLock))) != ROK)
4229 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
4230 "Could not lock the mBuf Ref Lock");
4238 #endif /* SS_M_PROTO_REGION */
4244 * Desc: This function allocates a buffer from the dynamic
4245 * memory pool indicated by the caller.
4248 * RFAILED - failed, general (optional)
4249 * ROUTRES - failed, out of resources (optional)
4251 * Notes: The dynamic memory pools are used to create and
4252 * manipulate messages.
4254 * SGetDBuf is never called by a protocol layer.
4256 * SGetDBuf assumes that interrupts are already disabled.
4262 #ifdef T2K_MEM_LEAK_DBG
4263 PUBLIC S16 SGetDBufNew
4265 Region region, /* region id */
4266 Pool pool, /* pool id */
4275 Region region, /* region id */
4276 Pool pool, /* pool id */
4280 PUBLIC S16 SGetDBuf(region, pool, bufPtr)
4281 Region region; /* region id */
4282 Pool pool; /* pool id */
4283 Buffer **bufPtr; /* pointer to buffer */
4291 #ifdef SS_LOCKLESS_MEMORY
4292 #ifdef SS_USE_ICC_MEMORY
4293 CmMmDynRegCb *regCb;
4295 CmMmGlobRegCb *regCb;
4298 SsRegionEntry *regp;
4299 #endif /* SS_LOCKLESS_MEMORY */
4300 /* ss021.103 - Addition of return value */
4302 #if (ERRCLASS & ERRCLS_INT_PAR)
4309 #if (ERRCLASS & ERRCLS_INT_PAR)
4310 /* check buffer pointer */
4313 SSLOGERROR(ERRCLS_INT_PAR, ESS133, ERRZERO, "SGetDBuf : Null Buffer");
4316 if (region >= SS_MAX_REGS)
4318 SSLOGERROR(ERRCLS_INT_PAR, ESS134, ERRZERO, "SGetDBuf : Invalid region\
4323 if (pool >= SS_MAX_POOLS_PER_REG)
4325 SSLOGERROR(ERRCLS_INT_PAR, ESS135, ERRZERO, "SGetDBuf : Invalid pool id");
4328 /* ss037.103 Removed the semaphore operation for performance enhancement */
4331 /* ss021.103 - Addition to check if region is registered */
4332 /* acquire one semaphore, to protect against deregistration */
4333 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
4337 #if (ERRCLASS & ERRCLS_DEBUG)
4338 SSLOGERROR(ERRCLS_DEBUG, ESS136, (ErrVal) ret,
4339 "Could not lock region table");
4347 #if (ERRCLASS & ERRCLS_INT_PAR)
4348 /* verify that this region is present */
4349 if (osCp.regionTbl[region].used == FALSE)
4351 /* ss037.103 Removed the semaphore operation for performance enhancement */
4354 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4356 #if (ERRCLASS & ERRCLS_DEBUG)
4357 SSLOGERROR(ERRCLS_DEBUG, ESS137, ERRZERO,
4358 "Could not release semaphore");
4363 SSLOGERROR(ERRCLS_INT_PAR, ESS138, region, "Region not registered");
4367 /* ss037.103 Removed the semaphore operation for performance enhancement */
4370 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4372 #if (ERRCLASS & ERRCLS_DEBUG)
4373 SSLOGERROR(ERRCLS_DEBUG, ESS139, ERRZERO,
4374 "Could not release semaphore");
4381 #ifdef SS_LOCKLESS_MEMORY
4382 #ifdef SS_USE_ICC_MEMORY
4383 regCb = (CmMmDynRegCb *)(osCp.dynRegionTbl[region].regCb);
4384 mdsize = regCb->bktSize[pool];
4385 #else /* SS_USE_ICC_MEMORY */
4386 regCb = osCp.globRegCb;
4387 #ifdef SS_MEM_WL_DEBUG
4388 mdsize = regCb->bktTbl[pool].size - 4;
4389 #else /* SS_MEM_WL_DEBUG */
4390 mdsize = regCb->bktTbl[pool].size;
4391 #endif /* SS_MEM_WL_DEBUG */
4392 #endif /* SS_USE_ICC_MEMORY */
4394 regp = &osCp.regionTbl[region];
4395 size = regp->poolTbl[pool].u.dpool.size;
4396 /* ss006.301 : optimized this function */
4397 mdsize = MDBSIZE + size;
4398 #endif /* SS_LOCKLESS_MEMORY */
4400 /* ss006.301 : optimized this function */
4401 /* ss001.301: additions */
4402 #ifdef SS_HISTOGRAM_SUPPORT
4403 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
4405 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr) != ROK)
4406 #endif /* SS_HISTOGRAM_SUPPORT */
4410 data = (Data *) (*bufPtr) + MDBSIZE;
4411 size = mdsize - MDBSIZE;
4413 dptr = (SsDblk*) (((Data *) (*bufPtr)) + MBSIZE);
4415 INITB((*bufPtr), dptr, data, size, NULLP)
4416 #ifndef SS_DBUF_REFLOCK_DISABLE
4417 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
4419 printf("Falied to destroy lock\n");
4430 * Desc: This function deallocates a buffer back to the
4431 * dynamic memory pool indicated by the caller.
4434 * RFAILED - failed, general (optional)
4436 * Notes: The dynamic memory pools are used to create and
4437 * manipulate messages.
4439 * SPutDBuf is never called by a protocol layer.
4441 * SPutDBuf assumes that interrupts are already disabled.
4447 #ifdef T2K_MEM_LEAK_DBG
4448 PUBLIC S16 SPutDBufNew
4465 PUBLIC S16 SPutDBuf(region, pool, buf)
4472 register SsDblk *dptr;
4473 /* ss021.103 - Addition to check return value of SFree */
4475 #if (defined(SS_USE_ZBC_MEMORY) && defined (TENB_DPDK_BUF))
4481 /* ss021.103 - Addition of ret initialization */
4484 #if (ERRCLASS & ERRCLS_INT_PAR)
4485 if (region >= SS_MAX_REGS)
4487 SSLOGERROR(ERRCLS_INT_PAR, ESS141, ERRZERO, "SPutDBuf:Invalid region");
4491 if (pool >= SS_MAX_POOLS_PER_REG)
4493 SSLOGERROR(ERRCLS_INT_PAR, ESS142, ERRZERO, "SPutDBuf:Invalid pool");
4499 SSLOGERROR(ERRCLS_INT_PAR, ESS143, ERRZERO, "SPutDBuf:Null pointer");
4503 if ( (buf->b_datap->db_type != SS_M_DATA) && (buf->b_datap->db_type != SS_M_PROTO))
4505 SSLOGERROR(ERRCLS_INT_PAR, ESS144, ERRZERO, "SPutDBuf:Incorrect\
4510 /* ss016.13: Addition */
4511 dptr = buf->b_datap;
4513 #ifdef SS_USE_ZBC_MEMORY
4514 if(dptr->db_type == SS_MEM_TYPE_SSI_ZBC)
4516 ret = SPutZbcDBuf(region, buf);
4520 #ifdef TENB_DPDK_BUF
4521 if(dptr->db_type == SS_MEM_TYPE_DPDK_ZBC)
4523 /* Not considering referances for DPDK buffer for now */
4524 SDetachDpdkPtrFrmDBuf(buf, &dpdkBuf);
4525 SPutSBufDpdk(dpdkBuf);
4526 ret = SFree(region, (Data *) buf, MDBSIZE);
4529 #endif /* TENB_DPDK_BUF */
4530 #endif /* SS_USE_ZBC_MEMORY */
4532 /* ss028.103 - Addition of lock for mBuf reference count */
4533 /* ss006.301 : optimized this funciton */
4537 #ifndef SS_DBUF_REFLOCK_DISABLE
4538 SDestroyLock(&dptr->dBufLock);
4540 /* if the data block is not shared, free the buffer, checks not reqd */
4541 #ifdef SS_HISTOGRAM_SUPPORT
4542 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4543 , __LINE__, (U8*) __FILE__, ENTNC);
4545 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4546 #endif /* SS_HISTOGRAM_SUPPORT */
4550 #ifndef SS_DBUF_REFLOCK_DISABLE
4551 if((ret=SLock(&dptr->dBufLock)))
4553 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
4554 "Could not lock the mBuf Ref Lock");
4559 /* if buffer's message blk is obtained during dupb */
4560 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
4563 SsDblk* dupdptr = (SsDblk *)((U8 *)buf + MBSIZE);
4565 if(dupdptr->db_ref == 0)
4568 #ifdef SS_HISTOGRAM_SUPPORT
4569 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__, ENTNC);
4571 ret = SFree(region, (Data *) buf, MDBSIZE);
4573 #endif /* SS_HISTOGRAM_SUPPORT */
4575 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
4577 /* if reference count falls to zero */
4580 #ifndef SS_DBUF_REFLOCK_DISABLE
4581 ret = SUnlock(&dptr->dBufLock) ;
4582 if((SDestroyLock(&dptr->dBufLock)) != 0)
4584 printf("Falied to destroy lock\n");
4587 /* free buffer to region */
4588 #ifdef SS_HISTOGRAM_SUPPORT
4589 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4590 , __LINE__, (U8*) __FILE__, ENTNC);
4592 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4593 #endif /* SS_HISTOGRAM_SUPPORT */
4596 #ifndef SS_DBUF_REFLOCK_DISABLE
4597 ret = SUnlock(&(dptr->dBufLock));
4600 #else /* SS_MULTICORE_SUPPORT */
4601 /* If MultiCore Support enabled, Dblk never be shared */
4602 #ifdef SS_HISTOGRAM_SUPPORT
4603 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4604 , __LINE__, (U8*) __FILE__, ENTNC);
4606 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4607 #endif /* SS_HISTOGRAM_SUPPORT */
4608 #endif /* SS_MULTICORE_SUPPORT */
4613 /* #ifdef SS_LOCKLESS_MEMORY */
4620 * Desc: This function will concatenate the two specified messages
4624 * RFAILED - failed, general (optional)
4626 * Notes: if order equal M1M2: all data attached to message 2 is
4627 * moved to the end of message 1. message 2 is set to empty.
4628 * message 1 length is increased by length of message 2.
4629 * message 2 length is set to zero. message 2 is not returned
4630 * to memory. return is ok.
4632 * if order equal M2M1: all data attached to message 2 is
4633 * moved to the front of message 1. message 2 is set to empty.
4634 * message 1 length is increased by length of message 2.
4635 * message 2 length is set to zero. message 2 is not returned
4636 * to memory. return is ok.
4646 Buffer *mBuf1, /* message 1 */
4647 Buffer *mBuf2, /* message 2 */
4651 PUBLIC S16 SCatMsg(mBuf1, mBuf2, order)
4652 Buffer *mBuf1; /* message 1 */
4653 Buffer *mBuf2; /* message 2 */
4654 Order order; /* order */
4664 #if (ERRCLASS & ERRCLS_INT_PAR)
4665 /* check message buffer 1 */
4668 SSLOGERROR(ERRCLS_INT_PAR, ESS148, ERRZERO, "SCatMsg : Null Buffer");
4671 /* check message buffer 2 */
4674 SSLOGERROR(ERRCLS_INT_PAR, ESS149, ERRZERO, "SCatMsg : Null Buffer");
4677 /* ss021.103 - Addition to test if same buffer */
4678 /* check message buffer 1 and 2 not same buffer */
4681 SSLOGERROR(ERRCLS_INT_PAR, ESS150, ERRZERO, "SCatMsg : mBuf1 == mBuf2");
4684 if ((order != M1M2) && (order != M2M1))
4686 SSLOGERROR(ERRCLS_INT_PAR, ESS151, ERRZERO, "SCatMsg : Invalid Order");
4689 if ((mBuf1->b_datap->db_type != SS_M_PROTO) ||
4690 (mBuf2->b_datap->db_type != SS_M_PROTO))
4692 SSLOGERROR(ERRCLS_INT_PAR, ESS152, ERRZERO,
4693 "SCatMsg : Incorrect buffer type");
4698 /* no data to append or prepend */
4702 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
4703 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
4705 /* ss021.103 - Addition to test max length of message is not exceeded */
4706 #if (ERRCLASS & ERRCLS_INT_PAR)
4708 if (minfo1->len > 0x7FFFFFFF - minfo2->len)
4710 if (minfo1->len > 0x7FFF - minfo2->len)
4713 SSLOGERROR(ERRCLS_INT_PAR, ESS153, ERRZERO, "SCpyFixMsg : messages too big");
4718 if (minfo1->region != minfo2->region)
4720 /* duplicate mBuf2 from the region/pool of mBuf1, initialise mBuf2 */
4721 /*ss015.13: addition */
4722 if (SCpyMsgMsg(mBuf2, minfo1->region, minfo1->pool, &newb) != ROK)
4725 minfo2 = (SsMsgInfo*) newb->b_rptr;
4730 if ((tmp = mBuf1->b_cont) == NULLP)
4732 mBuf1->b_cont = newb->b_cont;
4733 minfo1->endptr = minfo2->endptr;
4738 /* attach newb after mBuf1 */
4740 minfo1->endptr->b_cont = newb->b_cont;
4741 minfo1->endptr = minfo2->endptr;
4746 /* attach newb before mBuf1 */
4748 minfo2->endptr->b_cont = mBuf1->b_cont;
4749 mBuf1->b_cont = newb->b_cont;
4751 else /* invalid order */
4753 #if (ERRCLASS & ERRCLS_DEBUG)
4754 SSLOGERROR(ERRCLS_DEBUG, ESS154, ERRZERO, "SCatMsg:Invalid order");
4756 if (newb && (newb != mBuf2))
4757 (Void) SPutMsg(newb);
4762 minfo1->len += minfo2->len;
4765 minfo2->endptr = NULLP;
4768 newb->b_cont = NULLP;
4772 (Void) SPutMsg(newb);
4773 (Void) SInitMsg(mBuf2);
4783 * Desc: This function replaces one byte of data in a message.
4786 * ROKDNA - ok, data not available
4787 * RFAILED - failed, general (optional)
4789 * Notes: index is 0 based and indicates location in message
4791 * if index is less than the length of the message:
4792 * data is replaced at specified index. message length
4793 * is unchanged. return is ok.
4795 * if index is greater than or equal to
4796 * the length of the message: message is unchanged.
4797 * return is ok, data not available.
4807 Data data, /* data */
4808 Buffer *mBuf, /* message buffer */
4812 PUBLIC S16 SRepMsg(data, mBuf, idx)
4813 Data data; /* data */
4814 Buffer *mBuf; /* message buffer */
4815 MsgLen idx; /* index */
4826 #ifdef T2K_MEM_LEAK_DBG
4827 char* file = __FILE__;
4828 U32 line = __LINE__;
4830 #if ( ERRCLASS & ERRCLS_INT_PAR)
4831 /* check message buffer */
4834 SSLOGERROR(ERRCLS_INT_PAR, ESS155, ERRZERO, "SRepMsg : Null Buffer");
4839 SSLOGERROR(ERRCLS_INT_PAR, ESS156, ERRZERO, "SRepMsg : Invalid index");
4842 if (mBuf->b_datap->db_type != SS_M_PROTO)
4844 SSLOGERROR(ERRCLS_INT_PAR, ESS157, ERRZERO, "SRepMsg : Incorrect buffer\
4850 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4852 /* if index > length of the buffer */
4853 if (minfo->len <= idx)
4858 tmp = mBuf->b_cont; /* get the first SS_M_DATA blk */
4859 prev = mBuf; /* parent */
4861 FIND_OFFSET_AND_PREV(prev, tmp, idx)
4863 /* if ref cnt is greater than 1, duplicate tmp */
4864 if (tmp->b_datap->db_ref > 1)
4866 /* allocate a message blk of message size of tmp */
4867 numBytes = tmp->b_wptr - tmp->b_rptr;
4868 if (ssGetDBufOfSize(minfo->region, numBytes, &newb) != ROK)
4870 SSLOGERROR(ERRCLS_DEBUG, ESS158, ERRZERO, "SRepMsg : ssGetDBufOfSize\
4875 *newb->b_wptr++ = *tmp->b_rptr++;
4877 newb->b_cont = tmp->b_cont;
4878 prev->b_cont = newb;
4879 if (minfo->endptr == tmp)
4880 minfo->endptr = newb;
4883 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
4886 *(tmp->b_rptr + idx) = data;
4895 * Desc: Update a message with a new dBuf
4909 Buffer *mBuf, /* message buffer */
4910 Buffer *dBuf, /* data buffer */
4914 PUBLIC S16 SUpdMsg(mBuf, dBuf, dLen)
4915 Buffer *mBuf; /* message buffer */
4916 Buffer *dBuf; /* data buffer */
4917 MsgLen dLen; /* data length */
4924 #if (ERRCLASS & ERRCLS_INT_PAR)
4927 SSLOGERROR(ERRCLS_INT_PAR, ESS159, ERRZERO, "SUpdMsg : Null Buffer");
4932 SSLOGERROR(ERRCLS_INT_PAR, ESS160, ERRZERO, "SUpdMsg : Null Buffer");
4937 SSLOGERROR(ERRCLS_INT_PAR, ESS161, ERRZERO, "SUpdMsg : Invalid length");
4940 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4941 (dBuf->b_datap->db_type != SS_M_DATA))
4943 SSLOGERROR(ERRCLS_INT_PAR, ESS162, ERRZERO, "SUpdMsg : Incorrect buffer\
4949 /* get the message info of mBuf */
4950 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4952 /* accept zero length data */
4954 /* buffer offset out of bounds */
4955 if ((dBuf->b_rptr + dLen) > dBuf->b_datap->db_lim)
4957 SSLOGERROR(ERRCLS_DEBUG, ESS163, ERRZERO, "SUpdMsg:Offset out of bounds");
4961 /* offset write ptr from read ptr by dLen */
4962 dBuf->b_wptr = dBuf->b_rptr + dLen;
4964 /* attach dBuf at the end of mBuf */
4966 minfo->endptr->b_cont = dBuf;
4968 mBuf->b_cont = dBuf;
4970 /* update SsMsgInfo */
4971 minfo->endptr = dBuf;
4982 * Desc: This function queues a data buffer to the
4983 * back of the specified message buffer .
4986 * RFAILED - failed, general (optional)
4988 * Notes: if queue is empty: buffer is placed in the queue.
4989 * queue length is incremented.
4991 * if queue is not empty: buffer is placed behind all
4992 * other buffers in queue. queue length is incremented.
5000 PUBLIC S16 SAddDBufPst
5002 Buffer *mBuf, /* message buffer */
5006 PUBLIC S16 SAddDBufPst(mBuf, dBuf)
5007 Buffer *mBuf; /* message buffer */
5008 Buffer *dBuf; /* data buffer */
5015 #if (ERRCLASS & ERRCLS_INT_PAR)
5016 /* check buffer queue */
5019 SSLOGERROR(ERRCLS_INT_PAR, ESS164, ERRZERO, "SAddDBufPst : Null Buffer");
5022 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
5023 (dBuf->b_datap->db_type != SS_M_DATA))
5025 SSLOGERROR(ERRCLS_INT_PAR, ESS165, ERRZERO, "SAddDBufPst : Incorrect\
5031 /* no data, return */
5032 if (dBuf->b_wptr == dBuf->b_rptr)
5035 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5037 /* attach dBuf at the end of mBuf */
5039 minfo->endptr->b_cont = dBuf;
5041 mBuf->b_cont = dBuf;
5043 /* update SsMsgInfo */
5044 minfo->endptr = dBuf;
5046 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
5055 * Desc: This function queues a data buffer to the
5056 * front of the specified message buffer.
5059 * RFAILED - failed, general (optional)
5061 * Notes: if buffer queue is empty: buffer is placed in the queue. queue
5062 * length is incremented.
5064 * if buffer queue is not empty: buffer is placed in front of all
5065 * other buffers in queue. queue length is incremented.
5073 PUBLIC S16 SAddDBufPre
5075 Buffer *mBuf, /* message buffer */
5079 PUBLIC S16 SAddDBufPre(mBuf, dBuf)
5080 Buffer *mBuf; /* message buffer */
5081 Buffer *dBuf; /* data buffer */
5089 #if (ERRCLASS & ERRCLS_INT_PAR)
5090 /* check buffer queue */
5093 SSLOGERROR(ERRCLS_INT_PAR, ESS166, ERRZERO, "SAddDBufPre : Null Buffer");
5096 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
5097 (dBuf->b_datap->db_type != SS_M_DATA))
5099 SSLOGERROR(ERRCLS_INT_PAR, ESS167, ERRZERO, "SAddDBufPre : Incorrect\
5105 /* no data, return */
5106 if (dBuf->b_wptr == dBuf->b_rptr)
5109 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5113 /* attach dBuf at the start of mBuf */
5114 mBuf->b_cont = dBuf;
5117 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
5120 minfo->endptr = dBuf;
5129 * Desc: This function dequeues a data buffer from
5130 * the front of the specified message buffer.
5133 * ROKDNA - ok, data not available
5134 * RFAILED - failed, general (optional)
5136 * Notes: if queue is empty: pointer to buffer is set to null and
5137 * return is ok, data not available. queue length is unchanged.
5139 * if queue is not empty: pointer to buffer is set to first
5140 * buffer in queue, first buffer in queue is removed and
5141 * return is ok. queue length is decremented.
5149 PUBLIC S16 SRemDBufPre
5151 Buffer *mBuf, /* message buffer */
5155 PUBLIC S16 SRemDBufPre(mBuf, dBufPtr)
5156 Buffer *mBuf; /* message buffer */
5157 Buffer **dBufPtr; /* pointer to data buffer */
5164 #if (ERRCLASS & ERRCLS_INT_PAR)
5165 /* check buffer pointer */
5166 if (dBufPtr == NULLP)
5168 SSLOGERROR(ERRCLS_INT_PAR, ESS168, ERRZERO, "SRemDBufPre : Null Buffer");
5174 SSLOGERROR(ERRCLS_INT_PAR, ESS169, ERRZERO, "SRemDBufPre : Null Buffer");
5177 if (mBuf->b_datap->db_type != SS_M_PROTO)
5179 SSLOGERROR(ERRCLS_INT_PAR, ESS170, ERRZERO, "SRemDBufPre : Incorrect\
5185 /* no data blk, return */
5186 if ((*dBufPtr = mBuf->b_cont) == NULLP)
5190 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5192 mBuf->b_cont = (*dBufPtr)->b_cont;
5193 (*dBufPtr)->b_cont = NULLP;
5195 /* update SsMsgInfo */
5196 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
5197 minfo->endptr = NULLP;
5206 * Desc: This function dequeues a data or message buffer from the
5207 * back of the specified message buffer.
5210 * ROKDNA - ok, data not available
5211 * RFAILED - failed, general (optional)
5213 * Notes: if queue is empty: pointer to buffer is set to null and
5214 * return is ok, data not available. queue length is unchanged.
5216 * if queue is not empty: pointer to buffer is set to last
5217 * buffer in queue, last buffer in queue is removed and
5218 * return is ok. queue length is decremented.
5226 PUBLIC S16 SRemDBufPst
5228 Buffer *mBuf, /* message buffer */
5232 PUBLIC S16 SRemDBufPst(mBuf, dBufPtr)
5233 Buffer *mBuf; /* message buffer */
5234 Buffer **dBufPtr; /* pointer to data buffer */
5242 #if (ERRCLASS & ERRCLS_INT_PAR)
5243 /* check buffer pointer */
5246 SSLOGERROR(ERRCLS_INT_PAR, ESS171, ERRZERO, "SRemDBufPst : Null Buffer");
5252 SSLOGERROR(ERRCLS_INT_PAR, ESS172, ERRZERO, "SRemDBufPst : Null Buffer");
5255 if (mBuf->b_datap->db_type != SS_M_PROTO)
5257 SSLOGERROR(ERRCLS_INT_PAR, ESS173, ERRZERO, "SRemDBufPst : Incorrect\
5263 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5265 /* no data blk, return */
5266 if ((*dBufPtr = minfo->endptr) == NULLP)
5270 for (tmp = mBuf; tmp->b_cont != (*dBufPtr); )
5273 tmp->b_cont = NULLP;
5275 /* update SsMsgInfo */
5276 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
5277 minfo->endptr = NULLP;
5279 minfo->endptr = tmp;
5288 * Desc: Initialize next Data Buffer Id
5292 * Notes: Must be called prior to SGetNxtDBuf
5300 PUBLIC S16 SInitNxtDBuf
5305 PUBLIC S16 SInitNxtDBuf(mBuf)
5306 Buffer *mBuf; /* message buffer */
5313 #if (ERRCLASS & ERRCLS_INT_PAR)
5316 SSLOGERROR(ERRCLS_INT_PAR, ESS174, ERRZERO, "SInitNxtDBuf : Null Buffer");
5319 if (mBuf->b_datap->db_type != SS_M_PROTO)
5321 SSLOGERROR(ERRCLS_INT_PAR, ESS175, ERRZERO, "SInitNxtDBuf : Incorrect\
5327 minfo = (SsMsgInfo*) mBuf->b_rptr;
5329 /* set the next ptr of mBuf to point to the first SS_M_DATA blk */
5330 minfo->next = mBuf->b_cont;
5339 * Desc: Get next dBuf in message chain
5343 * Notes: Must be called after SInitNxtDBuf
5351 PUBLIC S16 SGetNxtDBuf
5353 Buffer *mBuf, /* message buffer */
5357 PUBLIC S16 SGetNxtDBuf(mBuf, dBuf)
5358 Buffer *mBuf; /* message buffer */
5359 Buffer **dBuf; /* data buffer return */
5366 #if (ERRCLASS & ERRCLS_INT_PAR)
5369 SSLOGERROR(ERRCLS_INT_PAR, ESS176, ERRZERO, "SGetNxtDBuf : Null Buffer");
5374 SSLOGERROR(ERRCLS_INT_PAR, ESS177, ERRZERO, "SGetNxtDBuf : Null Buffer");
5377 if (mBuf->b_datap->db_type != SS_M_PROTO)
5379 SSLOGERROR(ERRCLS_INT_PAR, ESS178, ERRZERO, "SGetNxtDBuf : Incorrect\
5385 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5387 /* if next ptr of mBuf is NULLP, return */
5388 if ((*dBuf = minfo->next) == NULLP)
5392 minfo->next = (*dBuf)->b_cont;
5401 * Desc: check if next data buffer exists.
5403 * Ret: ROK/ROKDNA/RFAILED
5405 * Notes: doesn't modify nxtDBuf
5412 PUBLIC S16 SChkNxtDBuf
5417 PUBLIC S16 SChkNxtDBuf(mBuf)
5418 Buffer *mBuf; /* message buffer */
5425 #if (ERRCLASS & ERRCLS_INT_PAR)
5428 SSLOGERROR(ERRCLS_INT_PAR, ESS179, ERRZERO, "SChkNxtDBuf : Null Buffer");
5431 if (mBuf->b_datap->db_type != SS_M_PROTO)
5433 SSLOGERROR(ERRCLS_INT_PAR, ESS180, ERRZERO, "SChkNxtDBuf : Incorrect\
5437 #endif /* ERRCLASS */
5439 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5441 /* if next is valid, return ROK */
5452 * Desc: Given a data buffer, return a pointer to the
5453 * data payload, and the length of the payload
5459 * Notes: This assumes an uninitialized dBuf
5467 PUBLIC S16 SGetDataRx
5469 Buffer *dBuf, /* data buffer */
5470 MsgLen pad, /* pad */
5471 Data **retDatPtr, /* return data pointer */
5475 PUBLIC S16 SGetDataRx(dBuf, pad, retDatPtr, retDatLen)
5476 Buffer *dBuf; /* data buffer */
5477 MsgLen pad; /* pad */
5478 Data **retDatPtr; /* return data pointer */
5479 MsgLen *retDatLen; /* return data length */
5484 #if (ERRCLASS & ERRCLS_INT_PAR)
5487 SSLOGERROR(ERRCLS_INT_PAR, ESS181, ERRZERO, "SGetDataRx : Null Buffer");
5490 if (!retDatLen || (pad < 0))
5492 SSLOGERROR(ERRCLS_INT_PAR, ESS182, ERRZERO, "SGetDataRx : Null Buffer");
5497 SSLOGERROR(ERRCLS_INT_PAR, ESS183, ERRZERO, "SGetDataRx : Null Buffer");
5500 if (dBuf->b_datap->db_type != SS_M_DATA)
5502 SSLOGERROR(ERRCLS_INT_PAR, ESS184, ERRZERO, "SGetDataRx : Incorrect\
5506 #endif /* ERRCLASS */
5508 if (dBuf->b_datap->db_ref > 1) /* cannot write to a shared buffer */
5510 #if (ERRCLASS & ERRCLS_DEBUG)
5511 SSLOGERROR(ERRCLS_DEBUG, ESS185, ERRZERO, "SGetDataRx : Reference\
5517 /* return the write ptr loc(with padding) if there is data to write to */
5518 if ((*retDatLen = (dBuf->b_datap->db_lim - dBuf->b_wptr - pad)) > 0)
5519 *retDatPtr = dBuf->b_wptr + pad;
5523 #if (ERRCLASS & ERRCLS_DEBUG)
5524 SSLOGERROR(ERRCLS_DEBUG, ESS186, ERRZERO, "SGetDataRx:No data available");
5536 * Desc: Given a data buffer, return a pointer to the
5537 * data payload, and the length of the payload
5543 * Notes: This assumes an initialized dBuf
5551 PUBLIC S16 SGetDataTx
5553 Buffer *dBuf, /* data buffer */
5554 Data **retDatPtr, /* return data pointer */
5555 MsgLen *retDatLen /* return data length */
5558 PUBLIC S16 SGetDataTx(dBuf, retDatPtr, retDatLen)
5559 Buffer *dBuf; /* data buffer */
5560 Data **retDatPtr; /* return data pointer */
5561 MsgLen *retDatLen; /* return data length */
5566 #if (ERRCLASS & ERRCLS_INT_PAR)
5567 /* ss021.103 - Modification to check parameters */
5570 SSLOGERROR(ERRCLS_INT_PAR, ESS187, ERRZERO, "SGetDataTx : Null Buffer");
5575 SSLOGERROR(ERRCLS_INT_PAR, ESS188, ERRZERO, "SGetDataTx : Null Buffer");
5576 *retDatPtr = (Data *)NULLP;
5581 SSLOGERROR(ERRCLS_INT_PAR, ESS189, ERRZERO, "SGetDataTx : Null Buffer");
5584 if (dBuf->b_datap->db_type != SS_M_DATA)
5586 SSLOGERROR(ERRCLS_INT_PAR, ESS190, ERRZERO, "SGetDataTx : Incorrect\
5588 *retDatPtr = (Data *)NULLP;
5591 #endif /* ERRCLASS */
5593 /* if there is data, return read ptr */
5594 if ((*retDatLen = dBuf->b_wptr - dBuf->b_rptr))
5595 *retDatPtr = dBuf->b_rptr;
5599 #if (ERRCLASS & ERRCLS_DEBUG)
5600 SSLOGERROR(ERRCLS_DEBUG, ESS191, ERRZERO, "SGetDataTx : Buffer empty");
5608 #ifndef SS_ENABLE_MACROS
5612 * Fun: SGetBufRegionPool
5614 * Desc: returns the region and pool of the message buffer
5616 * Ret: ROK on success
5625 PUBLIC S16 SGetBufRegionPool
5627 Buffer *mBuf, /* message buffer */
5628 Region *region, /* region */
5629 Pool *pool /* pool */
5632 PUBLIC S16 SGetBufRegionPool(mBuf, region, pool)
5633 Buffer *mBuf; /* message buffer */
5634 Region *region; /* region */
5635 Pool *pool; /* pool */
5638 SsMsgInfo *mInfo; /* message info pointer */
5640 TRC1(SGetBufRegionPool)
5642 #if (ERRCLASS & ERRCLS_INT_PAR)
5646 SSLOGERROR(ERRCLS_INT_PAR, ESS192, ERRZERO,
5647 "SGetBufRegionPool : Null Buffer");
5650 if ((region == NULLP) && (pool == NULLP))
5652 SSLOGERROR(ERRCLS_INT_PAR, ESS193, ERRZERO,
5653 "SGetBufRegionPool : Null region and pool pointers");
5656 if (mBuf->b_datap->db_type != SS_M_PROTO)
5658 SSLOGERROR(ERRCLS_INT_PAR, ESS194, ERRZERO,
5659 "SUpdMsg : Incorrect buffer type");
5662 #endif /* (ERRCLASS & ERRCLS_INT_PAR */
5664 /* get message info of mBuf */
5665 if ((mInfo = (SsMsgInfo *) mBuf->b_rptr) == NULLP)
5667 #if (ERRCLASS & ERRCLS_DEBUG)
5668 SSLOGERROR(ERRCLS_DEBUG, ESS195, ERRZERO,
5669 "SGetBufRegionPool : mBuf's control data is null");
5674 if (region != NULLP)
5675 *region = mInfo->region;
5677 *pool = mInfo->pool;
5680 } /* end of SGetBufRegionPool */
5682 #endif /* SS_ENABLE_MACROS */
5688 * Desc: This function is used to compress a message into
5689 * the minimum number of data buffers needed.
5692 * RFAILED - failed, general (optional)
5693 * ROUTRES - failed, out of resources (optional)
5703 PUBLIC S16 SCompressMsg
5708 PUBLIC S16 SCompressMsg(mBuf)
5709 Buffer *mBuf; /* message buffer */
5719 #ifdef T2K_MEM_LEAK_DBG
5720 char* file = __FILE__;
5721 U32 line = __LINE__;
5725 #if (ERRCLASS & ERRCLS_INT_PAR)
5728 SSLOGERROR(ERRCLS_INT_PAR, ESS196, ERRZERO, "SCompressMsg : Null Buffer");
5731 if (mBuf->b_datap->db_type != SS_M_PROTO)
5733 SSLOGERROR(ERRCLS_INT_PAR, ESS197, ERRZERO, "SCompressMsg : Incorrect\
5739 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5741 if ((tmp = mBuf->b_cont) == minfo->endptr)
5746 /* allocate a data buffer of size bytes*/
5747 if ((ret = ssGetDBufOfSize(minfo->region, minfo->len, &dBuf)) != ROK)
5749 SSLOGERROR(ERRCLS_DEBUG, ESS198, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
5753 dBuf->b_datap->db_type = SS_M_DATA;
5757 /* determine number of bytes to be copied */
5758 numBytes = tmp->b_wptr - tmp->b_rptr;
5762 /* ss002.13: addition */
5763 /* ss003.13: addition */
5764 SMemCpy( (Void *)dBuf->b_wptr, (Void *)tmp->b_rptr, (size_t)numBytes);
5766 dBuf->b_wptr += numBytes;
5767 tmp->b_rptr += numBytes;
5771 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
5774 /* update mBuf and SsMsgInfo */
5775 mBuf->b_cont = dBuf;
5776 minfo->endptr = dBuf;
5785 * Desc: This function prints the contents of a message. The
5786 * following information is printed: queue length,
5787 * message length, direction, hexadecimal and ASCII
5788 * (if appropriate) values of all bytes in the message.
5790 * This function should be used for debugging only.
5803 Buffer *mBuf, /* message buffer */
5804 S16 src, /* source id */
5805 S16 dst /* destination id */
5808 PUBLIC S16 SPrntMsg(mBuf, src, dst)
5809 Buffer *mBuf; /* message buffer */
5810 S16 src; /* source id */
5811 S16 dst; /* destination id */
5814 QLen qlen; /* queue length */
5815 MsgLen mlen; /* message length */
5819 /* ss038.103 : 102061 Changed to MsgLen from S16 */
5820 MsgLen i; /* counter */
5821 S16 j; /* counter */
5822 S16 k; /* counter */
5824 U8 tdata[16] = {0}; /* temporary data */
5825 S8 prntBuf[256]; /* print buffer */
5826 Buffer *tmp; /* buffer ptr */
5828 /* ss012.13: Addition */
5836 sprintf(prntBuf,"\nmsg: empty\n");
5838 SPrint( (S8*)"\n\n");
5842 for (qlen = 0, tmp = mBuf->b_cont; tmp; qlen++)
5844 mlen = ((SsMsgInfo*)(mBuf->b_rptr))->len;
5845 reg = ((SsMsgInfo*)(mBuf->b_rptr))->region;
5846 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
5847 sprintf(prntBuf,"\nmsg: qlen: %04d mlen: %04d %02d-->%02d region: %02d\n",
5848 (U16)qlen,(U16)mlen,src,dst,reg);
5850 #ifdef XEON_SPECIFIC_CHANGES
5851 printf("%s\n", prntBuf);
5853 SPrint((S8*) "dat: ");
5854 #ifdef XEON_SPECIFIC_CHANGES
5860 sprintf(prntBuf," empty\n");
5862 SPrint( (S8*)"\n\n");
5872 for( j = 0; j < 16; j++)
5878 sprintf( prntBuf,"%02x ",(U16) data);
5880 #ifdef XEON_SPECIFIC_CHANGES
5881 printf("%s\n", prntBuf);
5883 if (cptr == tmp->b_wptr)
5889 /* ss024.103 - Modification to fix bug */
5896 sprintf( prntBuf," ");
5898 #ifdef XEON_SPECIFIC_CHANGES
5899 printf("%s\n", prntBuf);
5903 for (k = 0; k < 16; k++)
5905 if( (i >= mlen) && (k>=(mlen%16)) && mlen%16 != 0)
5907 if (AIsAscii(tdata[k]))
5909 /* print character if printable */
5910 sprintf(prntBuf,"%c",tdata[k]);
5912 #ifdef XEON_SPECIFIC_CHANGES
5913 printf("%s\n", prntBuf);
5918 /* print . if non printable */
5920 #ifdef XEON_SPECIFIC_CHANGES
5925 sprintf(prntBuf,"\n ");
5927 #ifdef XEON_SPECIFIC_CHANGES
5928 printf("%s\n", prntBuf);
5933 } /* end of SPrntMsg */
5939 * Fun: SGetPstMsgMult
5941 * Desc: This function allocates consecutive bytes of data at the
5945 * RFAILED - failed, general (optional)
5946 * ROUTRES - failed, out of resources (optional)
5948 * Notes: if message is empty: message length is incremented.
5951 * if message is not empty: space is allocated in back of
5952 * all other data in message. message length is incremented.
5959 PUBLIC S16 SGetPstMsgMult
5961 MsgLen cnt, /* count */
5962 Buffer *mBuf /* message buffer */
5965 PUBLIC S16 SGetPstMsgMult(cnt, mBuf)
5966 MsgLen cnt; /* count */
5967 Buffer *mBuf; /* message buffer */
5976 TRC1(SGetPstMsgMult)
5978 #if ( ERRCLASS & ERRCLS_INT_PAR )
5979 /* check message buffer */
5989 if (mBuf->b_datap->db_type != SS_M_PROTO)
5994 /* get the message info */
5995 minfo = (SsMsgInfo *) (mBuf->b_rptr);
6000 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
6001 ((avail = tmp->b_datap->db_lim - tmp->b_wptr)))
6003 numBytes = MIN(cnt, avail);
6006 minfo->len += numBytes;
6009 /* ss002.13 addition */
6010 /* ss003.13 addition */
6011 SMemSet( (Void *)tmp->b_wptr, (Data)'\0', (size_t)numBytes);
6013 tmp->b_wptr += numBytes;
6017 if (ssGetDBufOfSize(minfo->region, cnt, &newb) != ROK)
6019 /* ss027.103 - Modification to fix bug in SGetPstMsgMult */
6020 if ((avail) && (tmp))
6021 tmp->b_wptr = tmp->b_datap->db_lim - avail;
6022 minfo->len -= avail;
6029 /* ss002.13: addition */
6030 /* ss003.13: addition */
6031 SMemSet( (Void *)newb->b_wptr, (Data)'\0', (size_t)cnt);
6033 newb->b_wptr += cnt;
6039 mBuf->b_cont = newb;
6041 minfo->endptr = newb;
6050 * Desc: Check Message
6052 * Ret: ROK on success
6055 * Notes: Check that the first buffer in a message
6056 * contains at least two bytes. This check is required
6057 * by 68302/68360 processors to insure accurate fisu
6069 PUBLIC S16 SChkMsg(mBuf)
6078 #if ( ERRCLASS & ERRCLS_INT_PAR )
6079 /* check message buffer */
6084 if (mBuf->b_datap->db_type != SS_M_PROTO)
6089 /* get the message info */
6090 minfo = (SsMsgInfo *) (mBuf->b_rptr);
6095 /* get the first M_DATA blk*/
6098 if (((tmp->b_rptr + 2) <= tmp->b_wptr) || (SCompressMsg(mBuf) == ROK))
6106 * Fun: SAlignDBufEven
6108 * Desc: align data portion of a data buffer on an even
6113 * Notes: required for SS7 microcode on the 68302
6119 PUBLIC S16 SAlignDBufEven
6121 Buffer *dBuf /* data buffer */
6124 PUBLIC S16 SAlignDBufEven(dBuf)
6125 Buffer *dBuf; /* data buffer */
6131 TRC1(SAlignDBufEven)
6133 #if (ERRCLASS & ERRCLS_INT_PAR)
6136 SSLOGERROR(ERRCLS_INT_PAR, ESS199, ERRZERO, "SAlignDBufEven : Null\
6140 if (dBuf->b_datap->db_type != SS_M_DATA)
6142 SSLOGERROR(ERRCLS_INT_PAR, ESS200, ERRZERO, "SAlignDBufEven : Incorrect\
6149 /* ss008.13: addition */
6150 if (!((PTR)src % (PTR)2))
6153 if (dBuf->b_datap->db_ref > 1)
6156 len = dBuf->b_wptr - dBuf->b_rptr;
6158 if (dBuf->b_datap->db_base < dBuf->b_rptr)
6160 dBuf->b_wptr = --dBuf->b_rptr;
6162 *dBuf->b_wptr++ = *src++;
6165 if (dBuf->b_datap->db_lim > dBuf->b_wptr)
6167 src = dBuf->b_wptr - 1;
6168 dBuf->b_rptr = ++dBuf->b_wptr;
6170 *--dBuf->b_rptr = *src--;
6178 /* ss004.13: addition */
6183 * Desc: Align data portion of a data buffer on the specified
6184 * boundary. No restriction is imposed on the alignment.
6188 * Notes: required by drivers (68360, 860)
6194 PUBLIC S16 SAlignDBuf
6196 Buffer *dBuf, /* data buffer */
6197 U32 align /* alignemnt required */
6200 PUBLIC S16 SAlignDBuf(dBuf, align)
6201 Buffer *dBuf; /* data buffer */
6202 U32 align; /* alignemnt required */
6207 U32 upShift; /* no. of bytes to be shifted up */
6208 U32 downShift; /* no. of bytes to be shifted down */
6212 #if (ERRCLASS & ERRCLS_INT_PAR)
6215 SSLOGERROR(ERRCLS_INT_PAR, ESS201, ERRZERO, "SAlignDBuf: Null\
6219 if (dBuf->b_datap->db_type != SS_M_DATA)
6221 SSLOGERROR(ERRCLS_INT_PAR, ESS202, ERRZERO, "SAlignDBuf: Incorrect\
6228 /* ss008.13: addition */
6229 upShift = (PTR)src % (PTR)align; /* no. of bytes by which to shift up
6230 * the read and write pointers */
6235 if (dBuf->b_datap->db_ref > 1)
6238 downShift = align - upShift; /* no of bytes by which to shift down
6239 * the read and write pointers */
6240 len = dBuf->b_wptr - dBuf->b_rptr;
6242 if (dBuf->b_datap->db_base <= (dBuf->b_rptr - upShift))
6244 /* there is space to shift up the read and write pointers */
6246 dBuf->b_rptr -= upShift; /* align the read pointer */
6247 dBuf->b_wptr = dBuf->b_rptr;
6248 SMemCpy( (Void *) dBuf->b_wptr, (Void *) src, (size_t) len);
6249 dBuf->b_wptr = dBuf->b_wptr + len;
6253 if (dBuf->b_datap->db_lim > dBuf->b_wptr + downShift)
6255 src = dBuf->b_wptr - 1;
6256 dBuf->b_wptr = dBuf->b_wptr + downShift;
6257 dBuf->b_rptr = dBuf->b_wptr;
6259 *--dBuf->b_rptr = *src--;
6273 * Desc: Allocates a static buffer pool within the specified
6277 * RFAILED - failed, general (optional)
6279 * Notes: The new memory management scheme makes this function
6280 * meaningless. It merely sets the pool ID to zero and
6289 Region region, /* region ID */
6290 Size size, /* size */
6291 Pool *pool /* pointer to pool ID */
6294 PUBLIC S16 SGetSMem(region, size, pool)
6295 Region region; /* region ID */
6296 Size size; /* size */
6297 Pool *pool; /* pointer to pool ID */
6306 #if (ERRCLASS & ERRCLS_INT_PAR)
6307 /* validate region ID */
6308 if (region >= SS_MAX_REGS)
6310 SSLOGERROR(ERRCLS_INT_PAR, ESS203, region, "Invalid region");
6314 /* validate pointer to pool ID */
6317 SSLOGERROR(ERRCLS_INT_PAR, ESS204, region, "Null pointer");
6323 /* set the pool ID to zero and return success */
6335 * Desc: Deallocates a static buffer pool within the specified
6339 * RFAILED - failed, general (optional)
6341 * Notes: The new memory management scheme makes this function
6342 * meaningless. It does nothing.
6350 Region region, /* region ID */
6351 Pool pool /* pool ID */
6354 PUBLIC S16 SPutSMem(region, pool)
6355 Region region; /* region ID */
6356 Pool pool; /* pool ID */
6359 /* ss021.103 - Addition of return value */
6360 #if (ERRCLASS & ERRCLS_INT_PAR)
6367 #if (ERRCLASS & ERRCLS_INT_PAR)
6368 /* validate region ID */
6369 if (region >= SS_MAX_REGS)
6371 SSLOGERROR(ERRCLS_INT_PAR, ESS205, region, "Invalid region");
6375 /* validate pool ID */
6376 if (pool >= SS_MAX_POOLS_PER_REG)
6378 SSLOGERROR(ERRCLS_INT_PAR, ESS206, region, "Invalid pool");
6382 /* ss021.103 - Addition to check if region is registered */
6383 /* acquire one semaphore, to protect against deregistration */
6384 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
6388 #if (ERRCLASS & ERRCLS_DEBUG)
6389 SSLOGERROR(ERRCLS_DEBUG, ESS207, (ErrVal) ret,
6390 "Could not lock region table");
6397 #if (ERRCLASS & ERRCLS_INT_PAR)
6398 /* verify that this region is present */
6399 if (osCp.regionTbl[region].used == FALSE)
6401 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6403 #if (ERRCLASS & ERRCLS_DEBUG)
6404 SSLOGERROR(ERRCLS_DEBUG, ESS208, ERRZERO,
6405 "Could not release semaphore");
6410 SSLOGERROR(ERRCLS_INT_PAR, ESS209, region, "Region not registered");
6415 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6417 #if (ERRCLASS & ERRCLS_DEBUG)
6418 SSLOGERROR(ERRCLS_DEBUG, ESS210, ERRZERO,
6419 "Could not release semaphore");
6433 * Desc: Checks the available system resources (memory).
6436 * RFAILED - failed, general (optional)
6446 Region region, /* region ID */
6447 Pool pool, /* pool ID */
6448 Status *status /* pointer to status */
6451 PUBLIC S16 SChkRes(region, pool, status)
6452 Region region; /* region ID */
6453 Pool pool; /* pool ID */
6454 Status *status; /* pointer to status */
6464 #if (ERRCLASS & ERRCLS_INT_PAR)
6465 /* validate region ID */
6466 if (region >= SS_MAX_REGS)
6468 SSLOGERROR(ERRCLS_INT_PAR, ESS229, region, "Invalid region");
6472 /* validate pool ID */
6473 if (pool >= SS_MAX_POOLS_PER_REG)
6475 SSLOGERROR(ERRCLS_INT_PAR, ESS230, region, "Invalid pool");
6479 /* validate status pointer */
6480 if (status == NULLP)
6482 SSLOGERROR(ERRCLS_INT_PAR, ESS231, ERRZERO, "Null pointer");
6486 /* ss037.103 Removed the semaphore operation for performance enhancement */
6489 /* acquire one semaphore, to protect against deregistration */
6490 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
6494 #if (ERRCLASS & ERRCLS_DEBUG)
6495 SSLOGERROR(ERRCLS_DEBUG, ESS232, (ErrVal) ret,
6496 "Could not lock region table");
6503 #if (ERRCLASS & ERRCLS_INT_PAR)
6504 /* verify that this region is around */
6505 if (osCp.regionTbl[region].used == FALSE)
6508 /* ss006.13: addition */
6509 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6511 #if (ERRCLASS & ERRCLS_DEBUG)
6512 SSLOGERROR(ERRCLS_DEBUG, ESS233, ERRZERO,
6513 "Could not release semaphore");
6518 SSLOGERROR(ERRCLS_INT_PAR, ESS234, region, "Region not registered");
6522 /* verify that this is a valid pool */
6523 if (osCp.regionTbl[region].poolTbl[pool].type != SS_POOL_DYNAMIC)
6525 SSLOGERROR(ERRCLS_DEBUG, ESS235, ERRZERO, "Invalid pool");
6531 /* call the memory manager to check resources */
6532 mctl.op = SS_MEM_CHK_RES;
6533 mctl.u.chkres.size = osCp.regionTbl[region].poolTbl[pool].u.dpool.size;
6534 mctl.u.chkres.status = status;
6535 ret = (osCp.regionTbl[region].ctl)
6536 (osCp.regionTbl[region].regCb, SS_MEM_CHK_RES, &mctl);
6538 /* release the semaphore we took */
6540 /* ss006.13: addition */
6541 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6543 #if (ERRCLASS & ERRCLS_DEBUG)
6544 SSLOGERROR(ERRCLS_DEBUG, ESS236, ERRZERO,
6545 "Could not release semaphore");
6558 * Desc: This function will swap two message data contents.
6559 * The original mBuf pointers are unchanged.
6574 Buffer *mBuf1, /* message 1 */
6575 Buffer *mBuf2 /* message 2 */
6578 PUBLIC S16 SSwapMsg(mBuf1, mBuf2)
6579 Buffer *mBuf1; /* message 1 */
6580 Buffer *mBuf2; /* message 2 */
6585 #if (ERRCLASS & ERRCLS_INT_PAR)
6594 #if (ERRCLASS & ERRCLS_INT_PAR)
6595 /* check message buffer 1 */
6598 SSLOGERROR(ERRCLS_INT_PAR, ESS237, ERRZERO, "SSwapMsg : Null Buffer");
6601 /* check message buffer 2 */
6604 SSLOGERROR(ERRCLS_INT_PAR, ESS238, ERRZERO, "SSwapMsg : Null Buffer");
6607 if (mBuf1->b_datap->db_type != SS_M_PROTO)
6609 SSLOGERROR(ERRCLS_INT_PAR, ESS239, ERRZERO, "SSwapMsg: Incorrect buffer\
6613 if (mBuf2->b_datap->db_type != SS_M_PROTO)
6615 SSLOGERROR(ERRCLS_INT_PAR, ESS240, ERRZERO, "SSwapMsg: Incorrect buffer\
6619 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
6620 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
6621 if (minfo1->region != minfo2->region)
6623 SSLOGERROR(ERRCLS_INT_PAR, ESS241, ERRZERO, "SSwapMsg: differnt regions\
6630 tmp = mBuf1->b_next;
6631 mBuf1->b_next = mBuf2->b_next;
6632 mBuf2->b_next = tmp;
6634 tmp = mBuf1->b_prev;
6635 mBuf1->b_prev = mBuf2->b_prev;
6636 mBuf2->b_prev = tmp;
6638 tmp = mBuf1->b_cont;
6639 mBuf1->b_cont = mBuf2->b_cont;
6640 mBuf2->b_cont = tmp;
6643 #ifdef SS_DBLK_FREE_RTN
6644 tmp = (Buffer *) mBuf1->b_datap->db_frtnp;
6645 mBuf1->b_datap->db_frtnp = mBuf2->b_datap->db_frtnp;
6646 mBuf2->b_datap->db_frtnp = (struct ssfree_rtn *) tmp;
6649 tmp2 = mBuf1->b_datap->db_ref;
6650 mBuf1->b_datap->db_ref = mBuf2->b_datap->db_ref;
6651 mBuf2->b_datap->db_ref = tmp2;
6656 SMemCpy((Void *) minfop, (Void *) (mBuf1->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6657 SMemCpy((Void *) (mBuf1->b_datap->db_base), (Void *) (mBuf2->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6658 SMemCpy((Void *) (mBuf2->b_datap->db_base), (Void *) minfop, (size_t)(sizeof(SsMsgInfo)));
6662 /* ss004.301 : Cavium changes */
6663 #ifdef SS_SEUM_CAVIUM
6669 * Desc: This function will converts the pointer to
6673 * RFAILED - failed, general (optional)
6675 * Notes: Function to convert the Pointer (Virtual address) to
6676 * Physical Address. This will take the Buffer type as
6677 * input and will convert all pointer associated with
6678 * that to Physical Address
6684 PUBLIC S16 SConvPtrPhy
6689 PUBLIC S16 SConvPtrPhy (mBuf)
6696 SsMsgInfo *minfoPtr;
6703 /* check mBuf for NULLP */
6704 if ( (mBuf == NULLP) || (*mBuf == NULLP ) )
6709 /* first block in Buffer is head */
6711 nextPtr = curPtr->b_cont;
6713 /* Get the physical address of the Pointer */
6716 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6721 curPtr->b_next = (Buffer*)cvmx_ptr_to_phys (curPtr->b_next);
6726 curPtr->b_prev = (Buffer*)cvmx_ptr_to_phys (curPtr->b_prev);
6729 /* Convert the pointers of Minfo to Physical addr */
6730 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6732 if (minfoPtr->endptr)
6734 minfoPtr->endptr = (Buffer*)cvmx_ptr_to_phys (minfoPtr->endptr);
6738 minfoPtr->next = (Buffer*)cvmx_ptr_to_phys (minfoPtr->next);
6741 curPtr->b_rptr = (U8*)cvmx_ptr_to_phys (curPtr->b_rptr);
6743 curPtr->b_wptr = (U8*)cvmx_ptr_to_phys (curPtr->b_wptr);
6745 /* Convert the pointers of Dblock to Physical addr */
6746 dblkPtr = (SsDblk*)curPtr->b_datap;
6749 #ifdef SS_DBLK_FREE_RTN
6750 frtnPtr = dblkPtr->db_frtnp;
6751 if( frtnPtr != NULLP)
6753 if (frtnPtr->free_func)
6755 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6757 if (frtnPtr->free_arg)
6759 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6762 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6766 dblkPtr->db_base = (U8*)cvmx_ptr_to_phys (dblkPtr->db_base);
6767 dblkPtr->db_lim = (U8*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6769 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6771 /* second block onwards is dblk */
6776 nextPtr = curPtr->b_cont;
6778 /* Get the physical address of the Pointer */
6781 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6784 curPtr->b_rptr = (U8*)cvmx_ptr_to_phys (curPtr->b_rptr);
6785 curPtr->b_wptr = (U8*)cvmx_ptr_to_phys (curPtr->b_wptr);
6787 /* Convert the pointers of Dblock to Physical addr */
6788 dblkPtr = (SsDblk*)curPtr->b_datap;
6791 #ifdef SS_DBLK_FREE_RTN
6792 frtnPtr = dblkPtr->db_frtnp;
6793 if( frtnPtr != NULLP)
6795 if (frtnPtr->free_func)
6797 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6799 if (frtnPtr->free_arg)
6801 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6804 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6808 dblkPtr->db_base = (U8*)cvmx_ptr_to_phys (dblkPtr->db_base);
6809 dblkPtr->db_lim = (U8*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6811 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6817 *mBuf = (Buffer*)cvmx_ptr_to_phys (*mBuf);
6827 * Desc: This function will converts the physical address
6830 * Ret: On Success - Pointer to converted buffer
6831 * On Failuer - Returns NULL
6833 * Notes: Function to Convert the Physical address to Pointer
6834 * (Virtual address) This will take work buffer as input
6835 * and will convert all address associated with that to
6842 PUBLIC S16 SConvPhyPtr
6847 PUBLIC S16 SConvPhyPtr (workPtr)
6854 SsMsgInfo *minfoPtr;
6861 /* check workPtr for NULLP */
6862 if ( (workPtr == NULLP) || (*workPtr == NULLP) )
6867 /* Convert the buffer address to pointer */
6868 mBuf = (Buffer*)cvmx_phys_to_ptr ((U64)(*workPtr));
6872 /* first block is mblk */
6875 curPtr->b_next = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_next);
6880 curPtr->b_prev = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_prev);
6885 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_cont);
6888 curPtr->b_rptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_rptr);
6890 /* Get the pointer for minfo */
6891 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6893 if (minfoPtr->endptr)
6895 minfoPtr->endptr = (Buffer*)cvmx_phys_to_ptr ((U64)minfoPtr->endptr);
6899 minfoPtr->next = (Buffer*)cvmx_phys_to_ptr ((U64)minfoPtr->next);
6902 curPtr->b_wptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_wptr);
6904 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((U64)curPtr->b_datap);
6906 /* Get the Dblock pointers */
6907 dblkPtr = (SsDblk*)curPtr->b_datap;
6910 #ifdef SS_DBLK_FREE_RTN
6911 if (dblkPtr->db_frtnp)
6913 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((U64)dblkPtr->db_frtnp);
6914 frtnPtr = dblkPtr->db_frtnp;
6916 if (frtnPtr->free_func)
6918 frtnPtr->free_func = cvmx_phys_to_ptr ((U64)frtnPtr->free_func);
6920 if (frtnPtr->free_arg)
6922 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((U64)frtnPtr->free_arg);
6927 dblkPtr->db_base = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_base);
6928 dblkPtr->db_lim = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_lim);
6930 curPtr = curPtr->b_cont;
6932 /* after the first block is dblk */
6937 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_cont);
6940 curPtr->b_rptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_rptr);
6942 curPtr->b_wptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_wptr);
6944 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((U64)curPtr->b_datap);
6946 /* Get the Dblock pointers */
6947 dblkPtr = (SsDblk*)curPtr->b_datap;
6950 #ifdef SS_DBLK_FREE_RTN
6951 if (dblkPtr->db_frtnp)
6953 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((U64)dblkPtr->db_frtnp);
6955 frtnPtr = dblkPtr->db_frtnp;
6957 if (frtnPtr->free_func)
6959 frtnPtr->free_func = cvmx_phys_to_ptr ((U64)frtnPtr->free_func);
6961 if (frtnPtr->free_arg)
6963 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((U64)frtnPtr->free_arg);
6968 dblkPtr->db_base = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_base);
6969 dblkPtr->db_lim = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_lim);
6971 curPtr = curPtr->b_cont;
6974 /* Place the converted buffer */
6985 * Desc: This function will copy the message from FPA region
6988 * Ret: On Success - ROK
6989 * On Failuer - RFAILED
6991 * Notes: Function to copy the message from FPA region to
6992 * other region. This will internally allocates the
6993 * memory for the destination buffer and copies the
6994 * message in the same chain list
7000 PUBLIC S16 SCpyFpaMsg
7008 PUBLIC S16 SCpyFpaMsg (srcBuf, dstRegion, dstPool, dstBuf)
7019 Buffer *curPtr = NULLP;
7021 Buffer *tmpblk = NULLP;
7022 Buffer *newblk = NULLP;
7023 Buffer *prevblk = NULLP;
7024 SsMsgInfo *minfoSrc = NULLP;
7025 SsMsgInfo *minfoDst = NULLP;
7026 SsDblk *dblkPtr = NULLP;
7027 SsDblk *dptr = NULLP;
7032 if ( srcBuf == (Buffer*)NULLP )
7037 if ((dstRegion >= SS_MAX_REGS) || (dstPool >= SS_MAX_POOLS_PER_REG))
7039 /* Free the source buffer and return failure */
7044 /* Allocate memory for destination buffer */
7045 if(SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
7047 /* Free the source buffer and return failure */
7052 /* get the minfo of dest and src buffers */
7053 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
7054 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
7056 curPtr = srcBuf->b_cont;
7058 /* Copy all the blocks associated with this Buffer */
7061 /* Allocate the memeory for dblock */
7063 dblkPtr = (SsDblk*)curPtr->b_datap;
7064 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
7065 size = numBytes + MDBSIZE;
7067 ret = SAlloc( dstRegion, &size, 0, (Data**)&tmpblk);
7071 /* Free all allocated buffers before returning */
7074 tmpblk = newblk->b_cont;
7075 (Void) SPutDBuf(dstRegion, dstPool, newblk);
7078 (Void) SPutMsg(*dstBuf);
7079 /* Free the source buffer and return failure */
7084 dat = (Data *)tmpblk + MDBSIZE;
7085 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
7088 /* Initialize the pointer and copy the data */
7089 INITB( tmpblk, dptr, dat, size, NULLP );
7090 #ifndef SS_DBUF_REFLOCK_DISABLE
7091 SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX);
7093 numBytes = curPtr->b_wptr - curPtr->b_rptr;
7094 /* Copy the data part if its present */
7097 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
7098 tmpblk->b_wptr += numBytes;
7107 prevblk->b_cont = tmpblk;
7111 curPtr = curPtr->b_cont;
7116 tmpblk->b_cont = NULLP;
7119 *minfoDst = *minfoSrc;
7120 minfoDst->region = 0;
7122 minfoDst->len = minfoSrc->len;
7123 minfoDst->endptr = tmpblk;
7124 minfoDst->next = NULLP;
7126 (*dstBuf)->b_cont = newblk;
7128 /* Free the source buffer after copying it */
7139 * Desc: This function will copy the message from any region
7142 * Ret: On Success - ROK
7143 * On Failuer - RFAILED
7145 * Notes: Function will copy the mbuf from msg to FPA.
7146 * This function allocates the memory internally
7147 * and copies the message to newly allocated mBuf.
7148 * The size of mBuf should be either of one
7149 * pre-difined sizes otherwise mBuf is dopped.
7155 PUBLIC S16 SCpyMsgFpa
7161 PUBLIC S16 SCpyMsgFpa (srcBuf, dstBuf)
7167 Buffer *curPtr = NULLP;
7169 Buffer *tmpblk = NULLP;
7170 Buffer *prevblk = NULLP;
7171 Buffer *newblk = NULLP;
7172 SsMsgInfo *minfoSrc = NULLP;
7173 SsMsgInfo *minfoDst = NULLP;
7174 SsDblk *dblkPtr = NULLP;
7175 SsDblk *dptr = NULLP;
7182 if (srcBuf == (Buffer*)NULLP)
7187 *dstBuf = (Buffer*)cvmx_fpa_alloc(SS_CVMX_POOL_0);
7189 if ( *dstBuf == NULLP )
7191 /* Free the source buffer before returning */
7196 dat = (Data *)(*dstBuf) + MDBSIZE;
7197 dptr = (SsDblk*) ((Data *)(*dstBuf) + MBSIZE);
7198 numBytes = SS_CVMX_POOL_0_SIZE - MDBSIZE;
7200 /* Initialize the pointers of new block */
7201 INITB((*dstBuf), dptr, dat, numBytes, NULLP);
7203 (*dstBuf)->b_datap->db_type = SS_M_PROTO;
7204 (*dstBuf)->b_wptr = (*dstBuf)->b_rptr + sizeof(SsMsgInfo);
7206 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
7207 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
7208 curPtr = srcBuf->b_cont;
7212 dblkPtr = (SsDblk*)curPtr->b_datap;
7214 /* Get the size required which is to be allocated */
7215 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
7216 numBytes += MDBSIZE;
7218 /* get the pool depending on the size need to be allocated */
7221 case SS_CVMX_POOL_0_SIZE:
7223 pool = SS_CVMX_POOL_0;
7226 case SS_CVMX_POOL_1_SIZE:
7228 pool = SS_CVMX_POOL_1;
7231 case SS_CVMX_POOL_2_SIZE:
7233 pool = SS_CVMX_POOL_2;
7236 case SS_CVMX_POOL_3_SIZE:
7238 pool = SS_CVMX_POOL_3;
7242 /* size doesn't match, drop the mBuf and returning
7244 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SCpyMsgFpa: Invalid\
7245 buffer size, dropping the message");
7247 (*dstBuf)->b_cont = newblk;
7248 SPutFpaMsg(*dstBuf);
7249 /* Free the source buffer before returning */
7254 /* Allocate for mBuf and copy both the header and contents */
7255 tmpblk = (Buffer*)cvmx_fpa_alloc(pool);
7257 if ( tmpblk == NULLP )
7259 /* Return error if fails to allocate memory */
7261 (*dstBuf)->b_cont = newblk;
7262 SPutFpaMsg(*dstBuf);
7263 /* Free the source buffer before returning */
7268 dat = (Data *)tmpblk + MDBSIZE;
7269 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
7270 numBytes -= MDBSIZE;
7272 /* Initialize the pointers of new block */
7273 INITB( tmpblk, dptr, dat, numBytes, NULLP );
7275 numBytes = curPtr->b_wptr - curPtr->b_rptr;
7276 /* Copy the message contents */
7279 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
7280 tmpblk->b_wptr += numBytes;
7283 /* Add the mew mBuf to the Buffer chain */
7290 prevblk->b_cont = tmpblk;
7294 /* Get the next block */
7295 curPtr = curPtr->b_cont;
7298 /* Initialize the last mBuf */
7301 tmpblk->b_cont = NULLP;
7304 *minfoDst = *minfoSrc;
7305 minfoDst->region = 0;
7307 minfoDst->len = minfoSrc->len;
7308 minfoDst->endptr = tmpblk;
7309 minfoDst->next = NULLP;
7311 (*dstBuf)->b_cont = newblk;
7313 /* Free the source buffer after copying it */
7324 * Desc: This function will free the Buffer associated with
7327 * Ret: On Success - ROK
7328 * On Failuer - RFAILED
7330 * Notes: Function free the all buffer associated with wqBuf
7331 * This will get the pool id by the size of the buffer
7332 * and same will be used to free the buffer.
7338 PUBLIC S16 SPutFpaMsg
7343 PUBLIC S16 SPutFpaMsg(fpaBuf)
7354 if( fpaBuf == NULLP )
7359 curBlk = fpaBuf->b_cont;
7363 nextBlk = curBlk->b_cont;
7365 dblkPtr = (SsDblk*)curBlk->b_datap;
7367 size = dblkPtr->db_lim - dblkPtr->db_base + MDBSIZE;
7369 /* Free the dblock according to its size */
7372 case SS_CVMX_POOL_0_SIZE:
7373 cvmx_fpa_free(curBlk, SS_CVMX_POOL_0, 0);
7376 case SS_CVMX_POOL_1_SIZE:
7377 cvmx_fpa_free(curBlk, SS_CVMX_POOL_1, 0);
7380 case SS_CVMX_POOL_2_SIZE:
7381 cvmx_fpa_free(curBlk, SS_CVMX_POOL_2, 0);
7384 case SS_CVMX_POOL_3_SIZE:
7385 cvmx_fpa_free(curBlk, SS_CVMX_POOL_3, 0);
7389 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SPutFpaMsg: Invalid\
7390 buffer size, dropping the message");
7397 cvmx_fpa_free(fpaBuf, SS_CVMX_POOL_0, 0);
7403 #endif /* SS_SEUM_CAVIUM */
7405 /* ss006.301 : new buffer management APIs, start */
7410 * Desc: This function is used to copy a portion of message(srcBuf) into
7411 * another msg(dstBuf)
7414 * RFAILED - failed, general (optional)
7415 * ROUTRES - failed, out of resources (optional) - In this case
7416 * caller shall reclaim the resources allocated for dstBuf.
7425 PUBLIC S16 SCpyPartMsg
7433 PUBLIC S16 SCpyPartMsg(srcBuf, idx, cnt, dstBuf)
7451 #if (ERRCLASS & ERRCLS_INT_PAR)
7454 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null src Buffer");
7457 if (srcBuf->b_datap->db_type != SS_M_PROTO)
7459 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7465 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null dst Buffer");
7468 if (dstBuf->b_datap->db_type != SS_M_PROTO)
7470 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7474 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
7476 /* if index > length of mBuf, return */
7477 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
7478 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
7480 if (idx >= sMinfo->len)
7482 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7487 sBuf = srcBuf->b_cont;
7488 FIND_OFFSET(sBuf, idx)
7492 dBuf = (dMinfo->endptr) ? (dMinfo->endptr) : (dstBuf->b_cont);
7496 crnt = dPrev->b_cont;
7500 crnt = crnt->b_cont;
7507 sCnt = sBuf->b_wptr - (sBuf->b_rptr + idx);
7510 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
7514 /* allocate a data buffer */
7515 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
7517 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyPartMsg : SGetDBuf\
7521 dCnt = MIN(cnt, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
7522 dPrev->b_cont = dBuf;
7525 if(sCnt > cnt) /* src Dblk has enough data to copy */
7529 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7531 dBuf->b_wptr += dCnt;
7532 dBuf = dBuf->b_cont;
7538 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), cnt);
7539 dBuf->b_wptr += cnt;
7540 dBuf->b_cont = NULLP;
7546 else /* src dBlk has partial data to be copied */
7550 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7551 dBuf->b_wptr += dCnt;
7552 dBuf = dBuf->b_cont;
7559 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), sCnt);
7560 dBuf->b_wptr += sCnt;
7562 sBuf = sBuf->b_cont;
7568 /* update the msgLen in dstBuf */
7569 dMinfo->len += numCpd;
7570 dMinfo->endptr = dBuf;
7579 * Desc: This function is used to replace a portion of message(mBuf) with the
7583 * RFAILED - failed, general (optional)
7592 PUBLIC S16 SRepPartMsg
7600 PUBLIC S16 SRepPartMsg(srcBuf, idx, cnt, dstBuf)
7618 #if (ERRCLASS & ERRCLS_INT_PAR)
7621 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null dstBuf");
7624 if (dstBuf->b_datap->db_type != SS_M_PROTO)
7626 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7627 dstBuf buffer type");
7632 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null Src Buffer ");
7635 if (srcBuf->b_datap->db_type != SS_M_PROTO)
7637 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7641 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
7643 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
7644 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
7646 if(((idx + cnt) > dMinfo->len) || (cnt < sMinfo->len))
7648 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7653 dBuf = dstBuf->b_cont;
7654 FIND_OFFSET(dBuf, idx)
7655 sBuf = srcBuf->b_cont;
7657 while(cnt && dBuf && sBuf)
7659 dCnt = (dBuf->b_wptr - (dBuf->b_rptr + idx));
7660 sCnt = sBuf->b_wptr - (sBuf->b_rptr + sIdx);
7661 cpBytes = MIN(cnt, sCnt);
7662 cpBytes = MIN(cpBytes, dCnt);
7663 SMemCpy((void*)(dBuf->b_rptr + idx), (void*)(sBuf->b_rptr + sIdx), cpBytes);
7669 /* move to next DBlk in srcBuf */
7670 sBuf = sBuf->b_cont;
7674 else /* cpBytes equals dCnt */
7676 /* move to the next DBlk in dstBuf */
7677 dBuf = dBuf->b_cont;
7691 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : unable to replace\
7703 * Desc: This function will move a portion of the first msg to second msg
7706 * ROKDNA - ok, data not available
7707 * RFAILED - failed, general (optional)
7708 * ROUTRES - failed, out of resources (optional)
7710 * Notes: message 1 is the message from which the segment will be copied
7712 * message 2 is the updated message.
7714 * index is 0 based and indicates location in message 1
7715 * up to which the data will be copied to message 2
7717 * if index is equal to 0, message 1 will not be changed and no data
7718 shall be copied to message 2.
7719 * message 1 is not returned to memory. return is ok.
7721 * if index is not equal to 0 and less than the length of
7722 * the message minus 1: data upto index, shall be copied to message 2
7723 * and read/write pointers of message 1 will be updated accordingly
7725 * if index is not equal to 0 and greater than or equal to
7726 * the length of the message minus 1: all of the message 1 data.
7727 * shall be copied to message 2. return is ok.
7735 PUBLIC S16 SMovPartMsg
7737 Buffer *srcBuf, /* message 1 */
7738 MsgLen idx, /* index */
7739 Buffer *dstBuf /* message 2 */
7742 PUBLIC S16 SMovPartMsg(srcBuf, idx, dstBuf)
7743 Buffer *srcBuf; /* message 1 */
7744 MsgLen idx; /* index */
7745 Buffer *dstBuf; /* message 2 */
7755 #ifdef T2K_MEM_LEAK_DBG
7756 char* file = __FILE__;
7757 U32 line = __LINE__;
7762 #if (ERRCLASS & ERRCLS_INT_PAR)
7763 /* check message buffer 1 */
7764 if ((!srcBuf) || (!dstBuf ))
7766 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SMovPartMsg : Null Buffer (src or Dst)");
7771 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SMovPartMsg : Invalid index");
7774 if ((srcBuf->b_datap->db_type != SS_M_PROTO) || (dstBuf->b_datap->db_type != SS_M_PROTO))
7776 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SMovPartMsg : Incorrect buffer\
7782 /* get the SsMsgInfo of srcBuf */
7783 sMinfo = (SsMsgInfo*) srcBuf->b_rptr;
7785 /* get the SsMsgInfo of dstBuf */
7786 dMinfo = (SsMsgInfo*) dstBuf->b_rptr;
7788 /* if index > length of mBuf, return */
7790 if (idx > sMinfo->len)
7795 /* one block might not sufficient - Check for generic implementation */
7796 sBuf = srcBuf->b_cont;
7797 /* dBuf = dMinfo->endptr; */
7798 dPrev = (dBuf = dMinfo->endptr) ? dBuf : dstBuf;
7800 /* adjust the lengths of srcBuf, dstBuf */
7806 sCnt = sBuf->b_wptr - sBuf->b_rptr;
7809 /* allocate a data buffer */
7810 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
7812 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyMsgPartMsg : SGetDBuf\
7816 dCnt = MIN(idx, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
7817 dPrev->b_cont = dBuf;
7822 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
7824 if(sCnt > idx) /* src Dblk has enough data to copy */
7828 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7829 dBuf->b_wptr += dCnt;
7830 dBuf = dBuf->b_cont;
7832 sBuf->b_rptr += dCnt;
7836 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), idx);
7837 dBuf->b_wptr += idx;
7838 dBuf->b_cont = NULLP;
7839 sBuf->b_rptr += idx;
7844 else /* src dBlk has partial data to be copied */
7848 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7849 dBuf->b_wptr += dCnt;
7850 dBuf = dBuf->b_cont;
7852 sBuf->b_rptr += dCnt;
7857 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), sCnt);
7858 dBuf->b_wptr += sCnt;
7860 /* deallocate the sBuf here */
7862 /* printf("SMovPartMsg() sBuf is completely copied sBuf->b_cont(%p)\n", sBuf->b_cont); */
7863 (Void)SPutDBuf(sMinfo->region, sMinfo->pool, sBuf);
7864 srcBuf->b_cont = sBuf = tmp;
7868 dMinfo->endptr = dBuf;
7873 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SMovPartMsg : unable to copy\
7885 * Desc: This function copies consecutive bytes of data to the
7886 * beginning of a message.
7889 * RFAILED - failed, general (optional)
7890 * ROUTRES - failed, out of resources (optional)
7892 * Notes: if message is empty: data is placed in the message. message
7893 * length is incremented. return is ok.
7895 * if message is not empty: data is read by source pointer,
7896 * data is placed in front of all other data in message.
7897 * message length is incremented. return is ok.
7899 * the first byte of data pointed to by the source pointer
7900 * will be placed at the front of the message first (i.e. it
7901 * will become the first byte of the message) and the last
7902 * byte will be placed in front of the existing msg contents,
7903 * i.e. order of the source is preserved.
7910 PUBLIC S16 SPkMsgMult
7917 PUBLIC S16 SPkMsgMult(src, cnt, mBuf)
7923 SsMsgInfo *minfo; /* Message info */
7926 MsgLen numBytes; /* no. of bytes to be copied */
7931 #if (ERRCLASS & ERRCLS_INT_PAR)
7932 /* check message buffer */
7935 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SPkMsgMult:Null Buffer");
7941 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SPkMsgMult:Null Buffer");
7947 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SPkMsgMult: Invalid\
7951 if (mBuf->b_datap->db_type != SS_M_PROTO)
7953 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SPkMsgMult: Incorrect\
7959 /* get the SsMsgInfo of mBuf */
7960 minfo = (SsMsgInfo*) mBuf->b_rptr;
7962 /* ss014.13: Addition */
7965 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
7966 (tmp->b_datap->db_base < tmp->b_rptr))
7968 /* store the offset of the read pointer of tmp */
7969 offset = tmp->b_rptr - tmp->b_datap->db_base;
7971 /* determine the number of bytes to copy */
7972 numBytes = MIN(cnt, offset);
7977 /* update the read ptr */
7978 tmp->b_rptr -= numBytes;
7980 memcpy((U8*)tmp->b_rptr, (src + cnt), numBytes);
7981 minfo->len += numBytes;
7988 /* allocate a DBlk minimum of size Cnt to pack the data */
7990 if (ssGetDBufOfSize(minfo->region, cnt, &newblk) != ROK)
7994 newblk->b_datap->db_type = SS_M_DATA;
7995 newblk->b_rptr = newblk->b_datap->db_lim - cnt;
7996 newblk->b_wptr = newblk->b_datap->db_lim;
7997 memcpy((U8*)newblk->b_rptr, src, cnt);
7998 /* attach the newblk chain into mBuf */
7999 newblk->b_cont = tmp;
8000 mBuf->b_cont = newblk;
8002 minfo->endptr = newblk;
8006 /* ss006.301 : new buffer management APIs, end */
8011 * Desc: This function retunrs the pointer to the read the message from mBuf
8014 * RFAILED - failed, general (optional)
8022 PUBLIC S16 SGetReadPtr
8029 PUBLIC S16 SGetReadPtr (mBuf, data, len)
8037 if (mBuf && mBuf->b_cont)
8039 *data = mBuf->b_cont->b_rptr;
8040 *len = ((SsMsgInfo*)(mBuf->b_rptr))->len;
8050 #ifdef SS_USE_ZBC_MEMORY
8053 * Fun: SAttachPtrToBuf
8055 * Desc: This function attaches the Pointer provided into a new
8056 * message buffer after allocating the same. It allocates
8057 * header (M-Block) and an additional dBuf (D-Block) and attaches
8058 * the provided pointer to it.
8061 * RFAILED - failed, general (optional)
8062 * ROUTRES - failed, out of resources (optional)
8070 #ifdef T2K_MEM_LEAK_DBG
8071 PUBLIC S16 SAttachPtrToBufNew
8083 PUBLIC S16 SAttachPtrToBuf
8092 PUBLIC S16 SAttachPtrToBuf(region, pool, ptr, totalLen, mBuf)
8101 SsMsgInfo *minfo; /* Message info */
8105 /* Void *iccHdlr; */
8107 TRC1(SAttachPtrToBuf)
8109 #if (ERRCLASS & ERRCLS_INT_PAR)
8112 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8117 #ifdef XEON_SPECIFIC_CHANGES
8120 if(SGetMsg(region, pool, mBuf) != ROK)
8122 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8128 #ifdef SS_HISTOGRAM_SUPPORT
8129 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
8131 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8132 #endif /* SS_HISTOGRAM_SUPPORT */
8134 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8139 (*mBuf)->b_cont = newblk;
8141 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8143 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8146 newblk->b_datap->db_base = ptr;
8147 newblk->b_datap->db_lim = ptr + totalLen;
8148 newblk->b_rptr = newblk->b_datap->db_base;
8149 newblk->b_wptr = newblk->b_rptr + totalLen;
8151 #ifndef SS_DBUF_REFLOCK_DISABLE
8152 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8154 printf("Falied to destroy lock\n");
8158 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8160 /* get the SsMsgInfo of mBuf */
8161 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8162 minfo->len = totalLen;
8163 minfo->endptr = newblk;
8172 * Desc: This function deallocates a buffer back to the
8173 * dynamic memory pool which is allocated for ZBC
8176 * RFAILED - failed, general (optional)
8184 #ifdef T2K_MEM_LEAK_DBG
8185 PRIVATE S16 SPutZbcDBufNew
8194 PRIVATE S16 SPutZbcDBuf
8200 PRIVATE S16 SPutZbcDBuf(region, buf)
8206 register SsDblk *dptr;
8212 dptr = buf->b_datap;
8213 /* Get the length of the buffer */
8214 bufLen = buf->b_datap->db_lim - buf->b_datap->db_base;
8216 /* If the buffer is not shared, free the buffer */
8219 #ifndef SS_DBUF_REFLOCK_DISABLE
8220 SDestroyLock(&dptr->dBufLock);
8223 /* Free the ZBC buffer first and then free the block allocated for the
8226 #ifdef SS_HISTOGRAM_SUPPORT
8227 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
8228 (U8*) __FILE__, ENTNC);
8230 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
8231 #endif /* SS_HISTOGRAM_SUPPORT */
8233 /* if the data block is not shared, free the buffer, checks not reqd */
8234 #ifdef SS_HISTOGRAM_SUPPORT
8235 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__,
8238 ret = SFree(region, (Data *) buf, MDBSIZE);
8239 #endif /* SS_HISTOGRAM_SUPPORT */
8241 /* If the buffer is shared, reduce the refernce count and free the buffer
8242 * if reference count falls to zero */
8245 #ifndef SS_DBUF_REFLOCK_DISABLE
8246 if((ret=SLock(&dptr->dBufLock)))
8248 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
8249 "Could not lock the mBuf Ref Lock");
8254 /* if buffer's message blk is obtained during dupb */
8255 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
8257 #ifdef SS_HISTOGRAM_SUPPORT
8258 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__, ENTNC);
8260 ret = SFree(region, (Data *) buf, MDBSIZE);
8261 #endif /* SS_HISTOGRAM_SUPPORT */
8262 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
8264 /* if reference count falls to zero */
8267 #ifndef SS_DBUF_REFLOCK_DISABLE
8268 ret = SUnlock(&dptr->dBufLock) ;
8269 if((SDestroyLock(&dptr->dBufLock)) != 0)
8271 printf("Falied to destroy lock\n");
8274 #ifdef SS_HISTOGRAM_SUPPORT
8275 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
8276 (U8*) __FILE__, ENTNC);
8278 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
8279 #endif /* SS_HISTOGRAM_SUPPORT */
8281 #ifdef SS_HISTOGRAM_SUPPORT
8282 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__,
8285 ret = SFree(region, (Data *) buf, MDBSIZE);
8286 #endif /* SS_HISTOGRAM_SUPPORT */
8289 #ifndef SS_DBUF_REFLOCK_DISABLE
8290 ret = SUnlock(&(dptr->dBufLock));
8296 #endif /* SS_USE_ZBC_MEMORY */
8302 * Fun: SAttachPtrToMBuf
8304 * Desc: This function attaches the Pointer provided into a new
8305 * message buffer after allocating the same. It allocates
8306 * header (M-Block) and an additional dBuf (D-Block) and attaches
8307 * the provided pointer to it.
8310 * RFAILED - failed, general (optional)
8311 * ROUTRES - failed, out of resources (optional)
8318 #ifdef T2K_MEM_LEAK_DBG
8319 PUBLIC S16 SAttachPtrToMBuf1
8332 PUBLIC S16 SAttachPtrToMBuf
8342 PUBLIC S16 SAttachPtrToMBuf(region, pool, ptr, totalLen, ptrLen, mBuf)
8352 SsMsgInfo *minfo; /* Message info */
8356 /* Void *iccHdlr; */
8358 TRC1(SAttachPtrToMBuf)
8360 #if (ERRCLASS & ERRCLS_INT_PAR)
8363 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8368 if(SGetMsg(region, pool, mBuf) != ROK)
8370 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8377 #ifdef SS_HISTOGRAM_SUPPORT
8378 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
8380 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8381 #endif /* SS_HISTOGRAM_SUPPORT */
8383 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8388 (*mBuf)->b_cont = newblk;
8390 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8392 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8395 newblk->b_datap->db_base = ptr;
8396 newblk->b_datap->db_lim = ptr + ptrLen;
8397 newblk->b_rptr = newblk->b_datap->db_base;
8398 newblk->b_wptr = newblk->b_rptr + totalLen;
8400 #ifndef SS_DBUF_REFLOCK_DISABLE
8401 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8403 printf("Falied to destroy lock\n");
8407 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8409 /* get the SsMsgInfo of mBuf */
8410 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8411 minfo->len = totalLen;
8412 minfo->endptr = newblk;
8414 //printf("Mbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
8417 #endif /* INTEL_WLS */
8418 PUBLIC S16 SIncMsgRef(Buffer *srcBuf,Region dstRegion, Pool dstPool,Buffer **dstBuf)
8421 RETVALUE(SAddMsgRef(srcBuf,dstRegion, dstPool,dstBuf));
8428 PUBLIC Void SResetMBuf(Buffer *mbuf)
8434 minfo = (SsMsgInfo *) mbuf->b_rptr;
8435 //tmp = minfo->endptr;
8442 // 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 );
8443 // tmp->b_wptr = tmp->b_rptr = tmp->b_datap->db_base;
8444 tmp->b_wptr = tmp->b_rptr = (tmp->b_datap->db_base + 5);
8445 tmp->b_datap->db_ref = 1;
8446 tmp->b_datap->shared = 0;
8458 * Fun: SAttachWlsPtrToMBuf
8460 * Desc: This function attaches the Pointer provided into a new
8461 * message buffer after allocating the same. It allocates
8462 * header (M-Block) and an additional dBuf (D-Block) and attaches
8463 * the provided pointer to it.
8466 * RFAILED - failed, general (optional)
8467 * ROUTRES - failed, out of resources (optional)
8474 #ifdef T2K_MEM_LEAK_DBG
8475 PUBLIC S16 SAttachWlsPtrToMBuf1
8489 PUBLIC S16 SAttachWlsPtrToMBuf
8500 PUBLIC S16 SAttachWlsPtrToMBuf(region, pool, ptr, readPtr, totalLen, ptrLen, mBuf)
8511 SsMsgInfo *minfo; /* Message info */
8515 /* Void *iccHdlr; */
8517 TRC1(SAttachWlsPtrToMBuf)
8519 #if (ERRCLASS & ERRCLS_INT_PAR)
8522 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8528 if(SGetMsg(region, pool, mBuf) != ROK)
8530 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8536 #ifdef SS_HISTOGRAM_SUPPORT
8537 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
8539 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8540 #endif /* SS_HISTOGRAM_SUPPORT */
8542 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8547 (*mBuf)->b_cont = newblk;
8549 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8551 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8554 newblk->b_datap->db_base = ptr;
8555 newblk->b_datap->db_lim = ptr + ptrLen;
8556 newblk->b_rptr = readPtr;
8557 newblk->b_wptr = newblk->b_rptr + totalLen;
8559 #ifndef SS_DBUF_REFLOCK_DISABLE
8560 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8562 printf("Falied to destroy lock\n");
8566 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8568 /* get the SsMsgInfo of mBuf */
8569 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8570 minfo->len = totalLen;
8571 minfo->endptr = newblk;
8573 //printf("Mbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
8577 #ifdef TENB_DPDK_BUF
8581 PUBLIC S16 SGetSBufDpdk
8583 Data **ptr, /* pointer to buffer */
8584 Size size /* size requested */
8589 *ptr = ntl_alloc(mtGetNtlHdl(), size);
8594 PUBLIC S16 SPutSBufDpdk
8596 Data *ptr /* pointer to buffer */
8602 ntl_free(mtGetNtlHdl(), ptr);
8607 PUBLIC S16 SDetachDpdkPtrFrmDBuf
8617 //msgBlk = mBuf->b_cont;
8618 //*ptr = msgBlk->b_rptr;;
8619 *ptr = mBuf->b_datap->db_base;;
8621 mBuf->b_cont = NULL;
8623 //minfo = (SsMsgInfo*) mBuf->b_rptr;
8631 PUBLIC S16 SDetachDpdkPtrFrmMBuf
8640 register SsDblk *dptr;
8644 msgBlk = mBuf->b_cont;
8651 dptr = msgBlk->b_datap;
8652 if(dptr->db_type != SS_MEM_TYPE_DPDK_ZBC)
8658 *ptr = msgBlk->b_rptr;;
8660 mBuf->b_cont = NULL;
8662 minfo = (SsMsgInfo*) mBuf->b_rptr;
8670 PUBLIC S16 SAttachDpdkPtrToMBuf
8681 PUBLIC S16 SAttachDpdkPtrToMBuf(region, pool, ptr, readPtr, msgLen, totalLen, mBuf)
8697 SAttachWlsPtrToMBuf(region, pool, ptr, readPtr, msgLen, totalLen, mBuf);
8698 dptr = (SsDblk*) (((Data *) ((*mBuf)->b_cont)) + MBSIZE);
8700 dptr->db_type = SS_MEM_TYPE_DPDK_ZBC;
8705 #endif /* TENB_DPDK_BUF */
8707 #endif /* INTEL_WLS */
8709 /**********************************************************************
8711 **********************************************************************/