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 */
1106 #ifndef SS_LOCKLESS_MEMORY
1110 #ifdef SS_LOCKLESS_MEMORY
1111 region = SS_GET_THREAD_MEM_REGION();
1112 ret = SAlloc(region, &size, 0, ptr);
1115 #ifdef T2K_MEM_LEAK_DBG
1116 ret = (osCp.regionTbl[region].alloc)
1117 (osCp.regionTbl[region].regCb, &size, flags, ptr,file,line);
1119 ret = (osCp.regionTbl[region].alloc)
1120 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1127 #ifdef T2K_MEM_LEAK_DBG
1128 PUBLIC S16 SPutSBufWls1
1130 Region region, /* region ID */
1131 Pool pool, /* pool ID */
1132 Data *ptr, /* pointer to buffer */
1133 Size size, /* size */
1138 PUBLIC S16 SPutSBufWls
1140 Region region, /* region ID */
1141 Pool pool, /* pool ID */
1142 Data *ptr, /* pointer to buffer */
1143 Size size /* size */
1149 #ifdef SS_LOCKLESS_MEMORY
1150 region = SS_GET_THREAD_MEM_REGION();
1151 ret = SFree(region, ptr, size);
1154 #ifdef T2K_MEM_LEAK_DBG
1155 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,file,line);
1157 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1164 #endif /* INTEL_WLS */
1171 * Desc: Allocates a buffer from the specified static memory pool
1172 * in the specified region.
1175 * RFAILED - failed, general (optional)
1177 * Notes: The new memory management scheme eliminates the concept
1178 * of pools. This call maps directly to a call to the memory
1184 /* ss001.301: additions */
1185 #ifdef SS_HISTOGRAM_SUPPORT
1187 PUBLIC S16 SGetSBufNew
1189 Region region, /* region ID */
1190 Pool pool, /* pool ID */
1191 Data **ptr, /* pointer to buffer */
1192 Size size, /* size requested */
1197 PUBLIC S16 SGetSBufNew(region, pool, ptr, size, line, fileName)
1198 Region region; /* region ID */
1199 Pool pool; /* pool ID */
1200 Data **ptr; /* pointer to buffer */
1201 Size size; /* size requested */
1205 #else /* SS_HISTOGRAM_SUPPORT */
1206 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1208 PUBLIC S16 SGetSBuf1
1210 Region region, /* region ID */
1211 Pool pool, /* pool ID */
1212 Data **ptr, /* pointer to buffer */
1213 Size size, /* size requested */
1218 PUBLIC S16 SGetSBuf1(region, pool, ptr, size, file, line)
1219 Region region; /* region ID */
1220 Pool pool; /* pool ID */
1221 Data **ptr; /* pointer to buffer */
1222 Size size; /* size requested */
1230 Region region, /* region ID */
1231 Pool pool, /* pool ID */
1232 Data **ptr, /* pointer to buffer */
1233 Size size /* size requested */
1236 PUBLIC S16 SGetSBuf(region, pool, ptr, size)
1237 Region region; /* region ID */
1238 Pool pool; /* pool ID */
1239 Data **ptr; /* pointer to buffer */
1240 Size size; /* size requested */
1243 #endif /* SS_HISTOGRAM_SUPPORT */
1247 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1251 #ifdef SS_HISTOGRAM_SUPPORT
1253 Bool hstReg = FALSE;
1254 #endif /* SS_HISTOGRAM_SUPPORT */
1258 region = SS_GET_THREAD_MEM_REGION();
1261 #endif /* INTEL_WLS */
1263 #if (ERRCLASS & ERRCLS_INT_PAR)
1264 /* validate region ID */
1265 if (region >= SS_MAX_REGS)
1267 SSLOGERROR(ERRCLS_INT_PAR, ESS211, region, "Invalid region");
1271 /* validate pool ID */
1272 if (pool >= SS_MAX_POOLS_PER_REG)
1274 SSLOGERROR(ERRCLS_INT_PAR, ESS212, pool, "Invalid pool");
1277 /* ss008.13: addition */
1278 /* validate data pointer */
1281 SSLOGERROR(ERRCLS_INT_PAR, ESS214, (ErrVal)0 , "NULL data pointer");
1288 SSLOGERROR(ERRCLS_INT_PAR, ESS215, size, "Invalid size");
1292 /* ss037.103 Removed the semaphore operation for performance enhancement */
1294 #ifndef RGL_SPECIFIC_CHANGES
1295 region = SS_GET_THREAD_MEM_REGION();
1298 /* acquire one semaphore, to protect against deregistration */
1299 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1303 #if (ERRCLASS & ERRCLS_DEBUG)
1304 SSLOGERROR(ERRCLS_DEBUG, ESS216, (ErrVal) ret,
1305 "Could not lock region table");
1313 #if (ERRCLASS & ERRCLS_INT_PAR)
1314 /* verify that this region is present */
1315 if (osCp.regionTbl[region].used == FALSE)
1319 /* ss006.13: addition */
1320 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1322 #if (ERRCLASS & ERRCLS_DEBUG)
1323 SSLOGERROR(ERRCLS_DEBUG, ESS217, ERRZERO,
1324 "Could not release semaphore");
1329 SSLOGERROR(ERRCLS_INT_PAR, ESS218, region, "Region not registered");
1338 /* ss024.103 - Addition for memory calculator tool */
1340 if (region == SS_STATIC_REGION)
1344 /* ss001.301: additions */
1345 #ifdef SS_HISTOGRAM_SUPPORT
1347 SGetEntInd(&entId, fileName);
1348 /* Get the Information from the oscp that the tapa task with the entity
1349 id (entid) is registed for histogram or not */
1350 SGetHstGrmInfo(&entId, &hstReg);
1351 /* call the memory manager, to allocate this memory */
1352 #ifdef SSI_DEBUG_LEVEL1
1353 ret = (osCp.regionTbl[region].alloc)
1354 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1355 SS_STATIC_MEM_FLAG, line, fileName, entId, hstReg);
1357 ret = (osCp.regionTbl[region].alloc)
1358 (osCp.regionTbl[region].regCb, &size, flags, ptr,
1359 line, fileName, entId, hstReg);
1360 #endif /* SSI_DEBUG_LEVEL1 */
1364 /* call the memory manager, to allocate this memory */
1365 /* ss036.103 - addition for passing additional parameter memType as static */
1366 #ifdef SSI_DEBUG_LEVEL1
1367 ret = (osCp.regionTbl[region].alloc)
1368 (osCp.regionTbl[region].regCb, &size, flags, ptr, SS_STATIC_MEM_FLAG);
1370 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1371 /* Static mem leak detection changes */
1373 #ifdef T2K_MEM_LEAK_DBG
1374 ret = (osCp.regionTbl[region].alloc)
1375 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr, file, line);
1377 ret = (osCp.regionTbl[region].alloc)
1378 (osCp.regionTbl[region].regCb, &tmpSize, flags, ptr);
1380 /*size = tmpSize - 4;*/
1382 /*printf("ptr = %p *ptr = %p\n",ptr,*ptr);*/
1383 #ifdef XEON_SPECIFIC_CHANGES
1384 pthread_mutex_lock(&(memLock));
1386 U32 idx = GetNextFreeIdx(&SMemLeakInfo[region]);
1387 U8* allocatedPtr = *ptr;
1388 void* actualPtr = allocatedPtr + 4;
1390 /* store the index in the memory allocated itself */
1391 /**((U32*)*((U32*)allocatedPtr)) = idx;*/
1392 *((U32*)allocatedPtr) = idx;
1393 /*printf("region = %d idx = %d ptr = %p *ptr = %p actual = %p allocated = %p content = %d\n",region, idx, ptr, *ptr, actualPtr, allocatedPtr, *((U32*)allocatedPtr));*/
1395 LogForStaticMemLeak(&SMemLeakInfo[region],
1401 #ifdef XEON_SPECIFIC_CHANGES
1402 pthread_mutex_unlock(&(memLock));
1406 #ifndef T2K_MEM_LEAK_DBG
1407 ret = (osCp.regionTbl[region].alloc)
1408 (osCp.regionTbl[region].regCb, &size, flags, ptr);
1410 ret = (osCp.regionTbl[region].alloc)
1411 (osCp.regionTbl[region].regCb, &size, flags, ptr, file, line);
1415 #endif /* SSI_DEBUG_LEVEL1 */
1417 #endif /* SS_HISTOGRAM_SUPPORT */
1419 /* release the semaphore we took */
1422 /* ss006.13: addition */
1423 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1425 #if (ERRCLASS & ERRCLS_DEBUG)
1426 SSLOGERROR(ERRCLS_DEBUG, ESS219, ERRZERO,
1427 "Could not release semaphore");
1432 /* ss036.103 - Addition to handle the memory trampling return value
1433 * This in turn might invoke SRegMemErrHdlr
1435 #ifdef SSI_DEBUG_LEVEL1
1436 if (ret == RTRAMPLINGNOK)
1438 SRegMemErrHdlr( region, *ptr, ret);
1440 #endif /* SSI_DEBUG_LEVEL1 */
1450 * Desc: Returns a buffer to the specified static pool in the
1451 * specified memory region.
1454 * RFAILED - failed, general (optional)
1461 /* ss001.301: additions */
1462 #ifdef SS_HISTOGRAM_SUPPORT
1464 PUBLIC S16 SPutSBufNew
1466 Region region, /* region ID */
1467 Pool pool, /* pool ID */
1468 Data *ptr, /* pointer to buffer */
1469 Size size, /* size */
1474 PUBLIC S16 SPutSBufNew(region, pool, ptr, size, line, fileName)
1475 Region region; /* region ID */
1476 Pool pool; /* pool ID */
1477 Data *ptr; /* pointer to buffer */
1478 Size size; /* size */
1482 #else /* SS_HISTOGRAM_SUPPORT */
1483 #if (defined(SSI_STATIC_MEM_LEAK_DETECTION) || defined(T2K_MEM_LEAK_DBG))
1485 PUBLIC S16 SPutSBuf1
1487 Region region, /* region ID */
1488 Pool pool, /* pool ID */
1489 Data *ptr, /* pointer to buffer */
1490 Size size, /* size */
1495 PUBLIC S16 SPutSBuf1(region, pool, ptr, size, file, line)
1496 Region region; /* region ID */
1497 Pool pool; /* pool ID */
1498 Data *ptr; /* pointer to buffer */
1499 Size size; /* size */
1507 Region region, /* region ID */
1508 Pool pool, /* pool ID */
1509 Data *ptr, /* pointer to buffer */
1510 Size size /* size */
1513 PUBLIC S16 SPutSBuf(region, pool, ptr, size)
1514 Region region; /* region ID */
1515 Pool pool; /* pool ID */
1516 Data *ptr; /* pointer to buffer */
1517 Size size; /* size */
1520 #endif /* SS_HISTOGRAM_SUPPORT */
1524 #ifdef SS_HISTOGRAM_SUPPORT
1526 Bool hstReg = FALSE;
1527 #endif /* SS_HISTOGRAM_SUPPORT */
1532 region = SS_GET_THREAD_MEM_REGION();
1533 #if (!defined(SS_LOCKLESS_MEMORY) && defined(INTEL_WLS))
1535 #endif /* INTEL_WLS */
1537 #if (ERRCLASS & ERRCLS_INT_PAR)
1538 /* validate region ID */
1539 if (region >= SS_MAX_REGS)
1541 SSLOGERROR(ERRCLS_INT_PAR, ESS220, region, "Invalid region");
1545 /* validate pool ID */
1546 if (pool >= SS_MAX_POOLS_PER_REG)
1548 SSLOGERROR(ERRCLS_INT_PAR, ESS221, pool, "Invalid pool");
1551 /* ss008.13: addition */
1552 /* validate data pointer */
1555 SSLOGERROR(ERRCLS_INT_PAR, ESS223, (ErrVal)0, "NULL data pointe");
1562 SSLOGERROR(ERRCLS_INT_PAR, ESS224, size, "Invalid size");
1566 /* ss037.103 Removed the semaphore operation for performance enhancement */
1567 #ifndef RGL_SPECIFIC_CHANGES
1568 region = SS_GET_THREAD_MEM_REGION();
1571 /* acquire one semaphore, to protect against deregistration */
1572 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
1576 #if (ERRCLASS & ERRCLS_DEBUG)
1577 SSLOGERROR(ERRCLS_DEBUG, ESS225, (ErrVal) ret,
1578 "Could not lock region table");
1585 #if (ERRCLASS & ERRCLS_INT_PAR)
1586 /* verify that this region is around */
1587 if (osCp.regionTbl[region].used == FALSE)
1591 /* ss006.13: addition */
1592 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1594 #if (ERRCLASS & ERRCLS_DEBUG)
1595 SSLOGERROR(ERRCLS_DEBUG, ESS226, ERRZERO,
1596 "Could not release semaphore");
1601 SSLOGERROR(ERRCLS_INT_PAR, ESS227, region, "Region not registered");
1606 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1607 /* Static mem leak detection changes */
1609 #ifdef XEON_SPECIFIC_CHANGES
1610 pthread_mutex_lock(&(memLock));
1612 U32 idx = *((U32*)((U8 *)ptr - 4));
1613 FreeIdx(ptr,idx,&SMemLeakInfo[region],size,file,line);
1614 #ifdef XEON_SPECIFIC_CHANGES
1615 pthread_mutex_unlock(&(memLock));
1618 /* Static mem leak detection changes */
1621 /* ss001.301: additions */
1622 #ifdef SS_HISTOGRAM_SUPPORT
1623 SGetEntInd(&entId, fileName);
1624 /* Get the Information from the oscp that the tapa task with the entity
1625 id (entid) is registed for histogram or not */
1626 SGetHstGrmInfo(&entId, &hstReg);
1628 /* call the memory manager to free this memory */
1629 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size,
1630 line, fileName, entId, hstReg);
1632 /* call the memory manager to free this memory */
1633 #ifdef SSI_STATIC_MEM_LEAK_DETECTION
1634 #ifdef T2K_MEM_LEAK_DBG
1635 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4, file, line);
1637 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr - 4, size + 4);
1640 #ifndef T2K_MEM_LEAK_DBG
1641 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size);
1643 ret = (osCp.regionTbl[region].free)(osCp.regionTbl[region].regCb, ptr, size, file, line);
1646 #endif /* SS_HISTOGRAM_SUPPORT */
1647 /* ss037.103 Removed the semaphore operation for performance enhancement */
1650 /* release the semaphore we took */
1652 /* ss006.13: addition */
1653 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
1655 #if (ERRCLASS & ERRCLS_DEBUG)
1656 SSLOGERROR(ERRCLS_DEBUG, ESS228, ERRZERO,
1657 "Could not release semaphore");
1662 /* ss036.103 - addition to handle double free and trampling return values
1663 * This might invoke SRegMemErrHdlr
1665 #ifdef SSI_DEBUG_LEVEL1
1666 /* handle the double free error here by calling the OS specific error handling function */
1667 if ((ret == RDBLFREE) || (ret == RTRAMPLINGNOK))
1669 SRegMemErrHdlr( region, ptr, ret);
1671 #endif /* SSI_DEBUG_LEVEL1 */
1681 * Desc: This function deallocates a message back and then
1682 * reinitializes the message.
1685 * RFAILED - failed, general (optional)
1687 * Notes: all data attached to message is returned to memory.
1688 * message is set to empty. message is not returned to
1689 * memory. return is ok.
1701 PUBLIC S16 SInitMsg(mBuf)
1711 #if (ERRCLASS & ERRCLS_INT_PAR)
1712 /* check message buffer */
1715 SSLOGERROR(ERRCLS_INT_PAR, ESS062, ERRZERO, "SInitMsg: Null Buffer");
1718 if (mBuf->b_datap->db_type != SS_M_PROTO)
1720 SSLOGERROR(ERRCLS_INT_PAR, ESS063, ERRZERO, "SInitMsg: Incorrect buffer\
1726 /* get the message info */
1729 CM_MEM_GET_REGION(tmpRegId);
1730 if(tmpRegId == 0xFF)
1735 minfo = (SsMsgInfo*) mBuf->b_rptr;
1737 /* free all SS_M_DATA blks */
1738 while ((tmp = mBuf->b_cont))
1740 mBuf->b_cont = tmp->b_cont;
1743 #ifdef T2K_MEM_LEAK_DBG
1744 char * file = __FILE__;
1745 U32 line = __LINE__;
1748 (Void) SPutDBuf(tmpRegId, minfo->pool, tmp);
1750 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
1753 /* initialise the length and endptr variables of mBuf */
1756 minfo->endptr = NULLP;
1757 minfo->next = NULLP;
1762 /* ss016.301 - Added a new API - SAddPreMsgMultInOrder. This preserves the
1763 * byte order while adding the data bytes to the beginning of the message.
1767 * Fun: SAddPreMsgMultInOrder
1769 * Desc: This function copies consecutive bytes of data to the
1770 * beginning of a message and keeps the bytes order preserved.
1772 * Ret: ROK - Appended the bytes to the beginning of the message.
1773 * RFAILED - Failed to append the bytes.
1774 * ROUTRES - Out of resources - Possibly insufficient memory.
1776 * Notes: If the message is empty,data is placed in the message. Message
1777 * length is incremented. Return is ROK.
1779 * If the message is not empty,data is read by source pointer
1780 * and appended at the beginning of the message.
1781 * Message length is incremented. Return is ROK.
1787 PUBLIC S16 SAddPreMsgMultInOrder
1794 PUBLIC S16 SAddPreMsgMultInOrder(src, cnt, mBuf)
1800 SsMsgInfo *minfo; /* Message info */
1802 Buffer *curblk=NULLP;
1805 MsgLen numBytes; /* no. of bytes to be copied */
1810 TRC1(SAddPreMsgMultInOrder)
1812 #if (ERRCLASS & ERRCLS_INT_PAR)
1813 /* check message buffer */
1816 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMultInOrder:\
1823 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMultInOrder:\
1830 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMultInOrder:\
1834 if (mBuf->b_datap->db_type != SS_M_PROTO)
1836 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMultInOrder:\
1837 Incorrect buffer type");
1842 /* get the SsMsgInfo of mBuf */
1843 minfo = (SsMsgInfo*) mBuf->b_rptr;
1844 #ifdef RGL_SPECIFIC_CHANGES
1848 /* store cnt in length */
1853 /* point to the end of the source buffer */
1854 revSrc = src + cnt ;
1856 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
1857 (tmp->b_datap->db_base < tmp->b_rptr))
1859 /* store the offset of the read pointer of tmp */
1860 offset = tmp->b_rptr - tmp->b_datap->db_base;
1862 /* determine the number of bytes to copy */
1863 numBytes = MIN(cnt, offset);
1865 /* traverse back from the end of the source buffer*/
1871 /* move the read pointer towards the left */
1872 tmp->b_rptr -= numBytes ;
1873 SMemCpy((Void *)(tmp->b_rptr ), (Void *) revSrc, (size_t) numBytes);
1881 newblk = prevblk = NULLP;
1884 /* allocate a message blk */
1885 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
1887 while ((curblk = prevblk))
1889 prevblk = prevblk->b_cont;
1890 #ifdef T2K_MEM_LEAK_DBG
1891 char * file = __FILE__;
1892 U32 line = __LINE__;
1895 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
1900 tmp->b_rptr = tmp->b_datap->db_base + offset;
1905 /* attach curblk in the newblk chain */
1908 curblk->b_cont = prevblk; /* stack them up */
1916 /* set the read and write pointers to the end of the data buffer */
1917 /* subsequent prepends have all the buffer to insert data into */
1918 curblk->b_wptr = curblk->b_datap->db_lim;
1919 rptr = curblk->b_datap->db_lim;
1922 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
1927 /* move the read pointer towards the left */
1930 /* traverse back the source buffer */
1933 SMemCpy((Void *)(rptr), (Void *) revSrc, (size_t) numBytes);
1935 curblk->b_rptr = rptr;
1938 /* attach the newblk chain into mBuf */
1939 newblk->b_cont = tmp;
1940 mBuf->b_cont = curblk;
1942 /* update endptr of mBuf */
1945 minfo->endptr = newblk;
1947 /* update length of message */
1956 * Desc: This function copies one byte of data to the
1957 * beginning of a message.
1960 * RFAILED - failed, general (optional)
1961 * ROUTRES - failed, out of resources (optional)
1963 * Notes: if message is empty: data is placed in the message. message
1964 * length is incremented. return is ok.
1966 * if message is not empty: data is placed in front of all
1967 * other data in message. message length is incremented.
1976 PUBLIC S16 SAddPreMsg
1982 PUBLIC S16 SAddPreMsg (data, mBuf)
1993 #if (ERRCLASS & ERRCLS_INT_PAR)
1994 /* check message buffer */
1997 SSLOGERROR(ERRCLS_INT_PAR, ESS064, ERRZERO, "SAddPreMsg: Null Buffer");
2000 if (mBuf->b_datap->db_type != SS_M_PROTO)
2002 SSLOGERROR(ERRCLS_INT_PAR, ESS065, ERRZERO, "SAddPreMsg: Incorrect\
2008 minfo = (SsMsgInfo *) mBuf->b_rptr;
2010 /* ss021.103 - Addition to check if exceeding maximum message length */
2012 if (minfo->len == 0x7FFFFFFF)
2014 if (minfo->len == 0x7FFF)
2021 * allocate a message blk using SGetDBuf(), if there are no data blks in the
2022 * message, mBuf, or if the reference count of the first data blk is greater
2023 * than 1, or if there is no space to append databytes in front of the read
2024 * pointer of the first data blk
2026 if (!(tmp = mBuf->b_cont) || (tmp->b_datap->db_ref > 1) ||
2027 (tmp->b_rptr == tmp->b_datap->db_base))
2029 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
2031 SSLOGERROR(ERRCLS_DEBUG, ESS066, ERRZERO, "SAddPreMsg:Failed in\
2035 /* set the read and write pointers to end of data buffer */
2036 /* subsequent prepends have all the buffer to insert data into */
2037 newb->b_wptr = newb->b_datap->db_lim;
2038 newb->b_rptr = newb->b_datap->db_lim;
2040 /* insert newb before tmp */
2041 newb -> b_cont = tmp;
2042 mBuf->b_cont = newb;
2044 /* if endptr of mBuf is NULLP, set it to newb */
2046 minfo->endptr = newb;
2049 /* insert data, increment length */
2050 *--tmp->b_rptr = data;
2060 * Desc: This function copies one byte of data to the
2064 * RFAILED - failed, general (optional)
2065 * ROUTRES - failed, out of resources (optional)
2067 * Notes: if message is empty: data is placed in the message. message
2068 * length is incremented. return is ok.
2070 * if message is not empty: data is placed in back of all
2071 * other data in message. message length is incremented.
2080 PUBLIC S16 SAddPstMsg
2086 PUBLIC S16 SAddPstMsg (data, mBuf)
2097 #if (ERRCLASS & ERRCLS_INT_PAR)
2098 /* check message buffer */
2101 SSLOGERROR(ERRCLS_INT_PAR, ESS067, ERRZERO, "SAddPstMsg: Null Buffer");
2104 if (mBuf->b_datap->db_type != SS_M_PROTO)
2106 SSLOGERROR(ERRCLS_INT_PAR, ESS068, ERRZERO, "SAddPstMsg: Incorrect\
2112 /* get the message info */
2113 minfo = (SsMsgInfo *) mBuf->b_rptr;
2115 if (!(tmp = minfo->endptr) || (tmp->b_datap->db_ref > 1) ||
2116 (tmp->b_wptr == tmp->b_datap->db_lim))
2118 if (SGetDBuf(minfo->region, minfo->pool, &newb) != ROK)
2120 SSLOGERROR(ERRCLS_DEBUG, ESS069, ERRZERO, "SAddPstMsg: Failed in\
2125 /* append newb to the end of the mBuf chain */
2129 mBuf->b_cont = newb;
2131 /* set the endptr of mBuf to newb */
2132 minfo->endptr = newb;
2136 /* insert data, increment length */
2137 *tmp->b_wptr++ = data;
2145 * Fun: SAddPreMsgMult
2147 * Desc: This function copies consecutive bytes of data to the
2148 * beginning of a message.
2151 * RFAILED - failed, general (optional)
2152 * ROUTRES - failed, out of resources (optional)
2154 * Notes: if message is empty: data is placed in the message. message
2155 * length is incremented. return is ok.
2157 * if message is not empty: data is read by source pointer,
2158 * data is placed in front of all other data in message.
2159 * message length is incremented. return is ok.
2161 * the first byte of data pointed to by the source pointer will
2162 * be placed at the front of the message first, the last byte of
2163 * data pointed to by the source pointer will be placed at the
2164 * front of the message last (i.e. it will become the first
2165 * byte of the message).
2171 #ifdef T2K_MEM_LEAK_DBG
2172 PUBLIC S16 SAddPreMsgMult1
2183 PUBLIC S16 SAddPreMsgMult
2190 PUBLIC S16 SAddPreMsgMult(src, cnt, mBuf)
2197 SsMsgInfo *minfo; /* Message info */
2199 Buffer *curblk=NULLP;
2202 MsgLen numBytes; /* no. of bytes to be copied */
2207 TRC1(SAddPreMsgMult)
2209 #if (ERRCLASS & ERRCLS_INT_PAR)
2210 /* check message buffer */
2213 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SAddPreMsgMult:Null Buffer");
2219 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SAddPreMsgMult:Null Buffer");
2225 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SAddPreMsgMult: Invalid\
2229 if (mBuf->b_datap->db_type != SS_M_PROTO)
2231 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SAddPreMsgMult: Incorrect\
2237 /* get the SsMsgInfo of mBuf */
2238 minfo = (SsMsgInfo*) mBuf->b_rptr;
2240 /* store cnt in length */
2242 /* ss014.13: Addition */
2245 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
2246 (tmp->b_datap->db_base < tmp->b_rptr))
2248 /* store the offset of the read pointer of tmp */
2249 offset = tmp->b_rptr - tmp->b_datap->db_base;
2251 /* determine the number of bytes to copy */
2252 numBytes = MIN(cnt, offset);
2259 *--tmp->b_rptr = *src++;
2266 newblk = prevblk = NULLP;
2269 /* allocate a message blk */
2270 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2272 while ((curblk = prevblk))
2274 prevblk = prevblk->b_cont;
2275 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2280 tmp->b_rptr = tmp->b_datap->db_base + offset;
2285 /* attach curblk in the newblk chain */
2287 curblk->b_cont = prevblk; /* stack them up */
2292 /* set the read and write pointers to the end of the data buffer */
2293 /* subsequent prepends have all the buffer to insert data into */
2294 curblk->b_wptr = curblk->b_datap->db_lim;
2295 rptr = curblk->b_datap->db_lim;
2298 numBytes = MIN(cnt, (rptr - curblk->b_datap->db_base));
2305 curblk->b_rptr = rptr;
2308 /* attach the newblk chain into mBuf */
2309 newblk -> b_cont = tmp;
2310 mBuf -> b_cont = curblk;
2312 /* update endptr of mBuf */
2314 minfo -> endptr = newblk;
2316 /* update length of message */
2324 * Fun: SAddPstMsgMult
2326 * Desc: This function copies consecutive bytes of data to the
2330 * RFAILED - failed, general (optional)
2331 * ROUTRES - failed, out of resources (optional)
2333 * Notes: if message is empty: data is placed in the message. message
2334 * length is incremented. return is ok.
2336 * if message is not empty: data is read by source pointer,
2337 * data is placed in back of all other data in message.
2338 * message length is incremented. return is ok.
2340 * the first byte of data pointed to by the source pointer will
2341 * be placed at the back of the message first, the last byte of
2342 * data pointed to by the source pointer will be placed at the
2343 * back of the message last (i.e. it will become the last
2344 * byte of the message).
2350 #ifdef T2K_MEM_LEAK_DBG
2351 PUBLIC S16 SAddPstMsgMult1
2361 PUBLIC S16 SAddPstMsgMult
2368 PUBLIC S16 SAddPstMsgMult(src, cnt, mBuf)
2378 Buffer *curblk=NULLP;
2385 TRC1(SAddPstMsgMult)
2387 #if (ERRCLASS & ERRCLS_INT_PAR)
2388 /* check message buffer */
2391 SSLOGERROR(ERRCLS_INT_PAR, ESS074, ERRZERO, "SAddPstMsgMult:Null Buffer");
2397 SSLOGERROR(ERRCLS_INT_PAR, ESS075, ERRZERO, "SAddPstMsgMult:Null Buffer");
2403 SSLOGERROR(ERRCLS_INT_PAR, ESS076, ERRZERO, "SAddPstMsgMult:Invalid\
2407 if (mBuf->b_datap->db_type != SS_M_PROTO)
2409 SSLOGERROR(ERRCLS_INT_PAR, ESS077, ERRZERO, "SAddPstMsgMult: Incorrect\
2415 /* get the SsMsgInfo of mBuf */
2416 minfo = (SsMsgInfo*) mBuf->b_rptr;
2418 /* store cnt in len */
2421 /* ss014.13: Addition */
2424 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
2425 (tmp->b_datap->db_lim > tmp->b_wptr))
2427 /* store offset of the write pointer */
2428 /* incase subsequent allocations fail, offset is read reset to original */
2429 offset = tmp->b_datap->db_lim - tmp->b_wptr;
2431 /* determine the number of bytes to copy */
2432 numBytes = MIN(cnt, offset);
2438 /* ss002.13: addition */
2440 /* ss004.13: addition */
2441 SMemCpy((Void *) tmp->b_wptr, (Void *) src, (size_t) numBytes);
2443 tmp->b_wptr += numBytes;
2453 newblk = prevblk = NULLP;
2457 /* allocate a message blk */
2458 if (SGetDBuf(minfo->region, minfo->pool, &curblk) != ROK)
2460 while ((curblk = newblk))
2462 newblk = newblk->b_cont;
2463 (Void) SPutDBuf(minfo->region, minfo->pool, curblk);
2468 tmp->b_wptr = tmp->b_datap->db_lim - offset;
2474 /* insert curblk in the newblk chain */
2476 prevblk->b_cont = curblk; /* stack them down */
2482 wptr = curblk->b_wptr;
2483 numBytes = MIN(cnt, curblk->b_datap->db_lim - wptr);
2489 /* ss002.13: addition */
2490 /* ss003.13: addition */
2491 SMemCpy( (Void *) wptr, (Void *) src, (size_t) numBytes);
2493 src = src + numBytes;
2495 curblk->b_wptr += numBytes;
2497 /* insert newblk chain into mBuf */
2499 tmp->b_cont = newblk;
2501 mBuf->b_cont = newblk;
2502 minfo->endptr = curblk;
2510 /* #ifdef SS_LOCKLESS_MEMORY */
2518 * Desc: This function copies and then removes one byte of
2519 * data from the beginning of a message.
2522 * ROKDNA - ok, data not available
2523 * RFAILED - failed, general (optional)
2525 * Notes: if message is empty: message is unchanged. return is ok,
2526 * data not available.
2528 * if message is not empty: data is removed from front of
2529 * message, data is returned via pointer to data. message
2530 * length is decremented. return is ok.
2538 PUBLIC S16 SRemPreMsg
2544 PUBLIC S16 SRemPreMsg(dataPtr, mBuf)
2551 #ifdef T2K_MEM_LEAK_DBG
2552 char* file = __FILE__;
2553 U32 line = __LINE__;
2558 #if (ERRCLASS & ERRCLS_INT_PAR)
2559 /* check data pointer */
2562 SSLOGERROR(ERRCLS_INT_PAR, ESS078, ERRZERO, "SRemPreMsg : Null Buffer");
2565 /* check message buffer */
2568 SSLOGERROR(ERRCLS_INT_PAR, ESS079, ERRZERO, "SRemPreMsg : Null Buffer");
2571 if (mBuf->b_datap->db_type != SS_M_PROTO)
2573 SSLOGERROR(ERRCLS_INT_PAR, ESS080, ERRZERO, "SRemPreMsg : Incorrect\
2579 if (!(tmp = mBuf->b_cont))
2582 /* get SsMsgInfo of mBuf */
2583 minfo = (SsMsgInfo *) mBuf->b_rptr;
2585 /* read databyte into dataPtr and incrment read ptr */
2586 *dataPtr = *tmp->b_rptr++;
2588 /* if all data is exhausted, release the blk */
2589 if (tmp->b_rptr == tmp->b_wptr)
2591 mBuf->b_cont = tmp->b_cont;
2592 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2594 /* update SsMsgInfo */
2596 minfo->endptr = NULLP;
2605 * Desc: This function copies and then removes one byte of
2606 * data from the end of a message.
2609 * ROKDNA - ok, data not available
2610 * RFAILED - failed, general (optional)
2612 * Notes: if message is empty: message is unchanged. return is ok,
2613 * data not available.
2615 * if message is not empty: data is removed from back of
2616 * message, data is returned via pointer to data. message
2617 * length is decremented. return is ok.
2625 PUBLIC S16 SRemPstMsg
2627 Data *dataPtr, /* pointer to data */
2631 PUBLIC S16 SRemPstMsg(dataPtr, mBuf)
2632 Data *dataPtr; /* pointer to data */
2633 Buffer *mBuf; /* message buffer */
2639 #ifdef T2K_MEM_LEAK_DBG
2640 char* file = __FILE__;
2641 U32 line = __LINE__;
2646 #if (ERRCLASS & ERRCLS_INT_PAR)
2647 /* check data pointer */
2648 if (dataPtr == NULLP)
2650 SSLOGERROR(ERRCLS_INT_PAR, ESS081, ERRZERO, "SRemPstMsg : Null Buffer");
2653 /* check message buffer */
2656 SSLOGERROR(ERRCLS_INT_PAR, ESS082, ERRZERO, "SRemPstMsg : Null Buffer");
2659 if (mBuf->b_datap->db_type != SS_M_PROTO)
2661 SSLOGERROR(ERRCLS_INT_PAR, ESS083, ERRZERO, "SRemPstMsg : Incorrect\
2667 /* get the SsMsgInfo */
2668 minfo = (SsMsgInfo*) mBuf->b_rptr;
2670 if (!(last = minfo->endptr))
2673 /* read databyte into dataPtr and decrement write ptr */
2674 *dataPtr = *--last->b_wptr;
2676 /* if all data is exhausted, release the blk */
2677 if (last->b_rptr == last->b_wptr)
2679 for (tmp = mBuf; tmp->b_cont != last;)
2681 tmp->b_cont = NULLP;
2682 (Void) SPutDBuf(minfo->region, minfo->pool, last);
2686 minfo->endptr = tmp;
2688 minfo->endptr = NULLP;
2690 /* update SsMsgInfo */
2699 * Fun: SRemPreMsgMult
2701 * Desc: This function copies and then removes consecutive bytes of
2702 * data from the beginning of a message.
2705 * ROKDNA - ok, data not available
2706 * RFAILED - failed, general (optional)
2708 * Notes: if message is empty: message is unchanged. return is ok,
2709 * data not available.
2711 * if the destination buffer is NULL, data is not copied.
2713 * if message is not empty: data is removed from front of
2714 * message, data is returned by destination pointer. message
2715 * length is decremented. return is ok.
2717 * the first byte of data read from the message will be placed
2718 * in the destination buffer first (i.e. this was the first byte
2719 * of the message), the last byte of data read from the message
2720 * will be placed in the destination buffer last.
2727 PUBLIC S16 SRemPreMsgMult
2729 Data *dst, /* destination */
2730 MsgLen cnt, /* count */
2734 PUBLIC S16 SRemPreMsgMult(dst, cnt, mBuf)
2735 Data *dst; /* destination */
2736 MsgLen cnt; /* count */
2737 Buffer *mBuf; /* message buffer */
2743 #ifdef T2K_MEM_LEAK_DBG
2744 char* file = __FILE__;
2745 U32 line = __LINE__;
2748 TRC1(SRemPreMsgMult)
2750 /* ss023.103 - Modification of SRemPreMsgMult for bug fix */
2752 #if (ERRCLASS & ERRCLS_INT_PAR)
2756 SSLOGERROR(ERRCLS_INT_PAR, ESS084, ERRZERO, "SRemPreMsgMult:Invalid\
2760 /* check message buffer */
2763 SSLOGERROR(ERRCLS_INT_PAR, ESS085, ERRZERO, "SRemPreMsgMult:Null Buffer");
2766 /* ss021.103 - Addition to check for NULL pointer */
2767 /* check data pointer */
2768 /* ss022.103 - Removed check for NULL pointer */
2769 if (mBuf->b_datap->db_type != SS_M_PROTO)
2771 SSLOGERROR(ERRCLS_INT_PAR, ESS086, ERRZERO, "SRemPreMsgMult : Incorrect\
2777 /* get the SsMsgInfo */
2778 minfo = (SsMsgInfo*) mBuf->b_rptr;
2780 /* check if data present */
2781 if (minfo->len < cnt)
2788 /* get the first SS_M_DATA blk */
2791 /* determine the number of bytes to be copy */
2792 numBytes = MIN(cnt, tmp->b_wptr - tmp->b_rptr);
2797 /* move data into dst */
2801 SMemCpy( (Void *) dst, (Void *) tmp->b_rptr, (size_t) numBytes);
2805 tmp->b_rptr += numBytes;
2807 if (tmp->b_rptr == tmp->b_wptr)
2809 mBuf->b_cont = tmp->b_cont;
2810 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2813 /* update SsMsgInfo */
2815 minfo->endptr = NULLP;
2822 * Fun: SRemPstMsgMult
2824 * Desc: This function copies and then removes consecutive bytes of
2825 * data from the end of a message.
2828 * ROKDNA - ok, data not available
2829 * RFAILED - failed, general (optional)
2831 * Notes: if message is empty: message is unchanged. return is ok,
2832 * data not available.
2834 * if the destination buffer is NULL, data is not copied.
2836 * if message is not empty: data is removed from front of
2837 * message, data is returned by destination pointer. message
2838 * length is decremented. return is ok.
2840 * the first byte of data read from the message will be placed
2841 * in the destination buffer first (i.e. this was the last byte
2842 * of the message), the last byte of data read from the message
2843 * will be placed in the destination buffer last.
2850 PUBLIC S16 SRemPstMsgMult
2852 Data *dst, /* destination */
2853 MsgLen cnt, /* count */
2857 PUBLIC S16 SRemPstMsgMult(dst, cnt, mBuf)
2858 Data *dst; /* destination */
2859 MsgLen cnt; /* count */
2860 Buffer *mBuf; /* message buffer */
2869 #ifdef T2K_MEM_LEAK_DBG
2870 char* file = __FILE__;
2871 U32 line = __LINE__;
2874 TRC1(SRemPstMsgMult)
2876 #if (ERRCLASS & ERRCLS_INT_PAR)
2880 SSLOGERROR(ERRCLS_INT_PAR, ESS087, ERRZERO, "SRemPstMsgMult:Invalid\
2884 /* check message buffer */
2887 SSLOGERROR(ERRCLS_INT_PAR, ESS088, ERRZERO, "SRemPstMsgMult:Null Buffer");
2890 if (mBuf->b_datap->db_type != SS_M_PROTO)
2892 SSLOGERROR(ERRCLS_INT_PAR, ESS089, ERRZERO, "SRemPstMsgMult : Incorrect\
2896 /* ss021.103 - Addition to check dst data pointer */
2897 /* check data pointer */
2898 /* ss022.103 - Removed check for NULL destination pointer */
2901 /* get the SsMsgInfo */
2902 minfo = (SsMsgInfo*) mBuf->b_rptr;
2904 /* check if data present */
2905 if (minfo->len < cnt)
2915 /* determine blk containing offset, and prev node */
2916 FIND_OFFSET_AND_PREV(prev, tmp, count)
2923 numBytes = MIN(cnt, (tmp->b_wptr - tmp->b_rptr - count));
2925 tmp->b_wptr -= numBytes;
2937 if (tmp->b_rptr == tmp->b_wptr)
2939 prev->b_cont = tmp->b_cont;
2940 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
2949 minfo->endptr = NULLP;
2951 minfo->endptr = prev;
2960 * Desc: This function copies one byte of data from a message
2961 * without modifying the message.
2964 * ROKDNA - ok, data not available
2965 * RFAILED - failed, general (optional)
2967 * Notes: index is 0 based and indicates location in message
2969 * if index is less than the length of the message:
2970 * message is unchanged and data is examined at specified
2971 * index and returned via pointer to data. message length
2972 * is unchanged. return is ok.
2974 * if index is greater than or equal to
2975 * the length of the message: message is unchanged and 0
2976 * is returned via pointer to data. return is ok, data
2987 Data *dataPtr, /* pointer to data */
2988 Buffer *mBuf, /* message buffer */
2992 PUBLIC S16 SExamMsg(dataPtr, mBuf, idx)
2993 Data *dataPtr; /* pointer to data */
2994 Buffer *mBuf; /* message buffer */
2995 MsgLen idx; /* index */
3003 #if (ERRCLASS & ERRCLS_INT_PAR)
3004 /* check data pointer */
3007 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SExamMsg : Null Buffer");
3010 /* check message buffer */
3013 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SExamMsg : Null Buffer");
3019 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SExamMsg : Invalid Index");
3022 if (mBuf->b_datap->db_type != SS_M_PROTO)
3024 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SExamMsg : Incorrect buffer\
3030 /* get the SsMsgInfo */
3031 minfo = (SsMsgInfo*) mBuf->b_rptr;
3033 if (minfo->len <= idx)
3038 /* get the first SS_M_DATA blk */
3041 /* determine offset */
3042 FIND_OFFSET(tmp, idx)
3044 *dataPtr = *(tmp->b_rptr + idx);
3053 * Fun: SGetDataFrmMsg
3055 * Desc: This function copies requested byte of data from a message
3056 * without modifying the message.
3059 * ROKDNA - ok, data not available
3060 * RFAILED - failed, general (optional)
3062 * Notes: index is 0 based and indicates location in message
3064 * if index is less than the length of the message:
3065 * message is unchanged and data is examined at specified
3066 * index and returned via pointer to data. message length
3067 * is unchanged. return is ok.
3069 * if index is greater than or equal to
3070 * the length of the message: message is unchanged and 0
3071 * is returned via pointer to data. return is ok, data
3080 PUBLIC S16 SGetDataFrmMsg
3082 Buffer *mBuf, /* message buffer */
3083 Data *dataPtr, /* pointer to data */
3088 PUBLIC S16 SGetDataFrmMsg(mBuf, dataPtr, idx, dataLen)
3089 Buffer *mBuf; /* message buffer */
3090 Data *dataPtr; /* pointer to data */
3091 MsgLen idx; /* index */
3098 Data *tmpDataPtr = dataPtr;
3100 TRC1(SGetDataFrmMsg)
3102 #if (ERRCLASS & ERRCLS_INT_PAR)
3103 /* check data pointer */
3106 SSLOGERROR(ERRCLS_INT_PAR, ESS090, ERRZERO, "SGetDataFrmMsg: Null Buffer");
3109 /* check message buffer */
3112 SSLOGERROR(ERRCLS_INT_PAR, ESS091, ERRZERO, "SGetDataFrmMsg: Null Buffer");
3118 SSLOGERROR(ERRCLS_INT_PAR, ESS092, ERRZERO, "SGetDataFrmMsg: Invalid Index");
3121 if (mBuf->b_datap->db_type != SS_M_PROTO)
3123 SSLOGERROR(ERRCLS_INT_PAR, ESS093, ERRZERO, "SGetDataFrmMsg: Incorrect buffer\
3129 /* get the SsMsgInfo */
3130 minfo = (SsMsgInfo*) mBuf->b_rptr;
3132 if (minfo->len <= (idx + dataLen) )
3137 /* get the first SS_M_DATA blk */
3140 /* determine offset */
3147 FIND_OFFSET(tmp, idx)
3148 offSetLen = ((tmp->b_wptr - (tmp->b_rptr + idx)));
3150 for(;(offSetLen < dataLen && tmp != NULLP);)
3152 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)offSetLen);
3153 dataLen = dataLen - offSetLen;
3156 tmpDataPtr = tmpDataPtr + offSetLen;
3157 offSetLen = tmp->b_wptr - tmp->b_rptr;
3163 SMemCpy((Void *)tmpDataPtr, (Void *)(tmp->b_rptr + idx), (size_t)dataLen);
3167 } /* End of SGetDataFrmMsg() */
3173 * Desc: This function determines the length of data within
3177 * RFAILED - failed, general (optional)
3179 * Notes: length of message is determined, message is unchanged
3180 * and length is returned via pointer to length. return is ok.
3188 PUBLIC S16 SFndLenMsg
3190 REG1 Buffer *mBuf, /* message buffer */
3194 PUBLIC S16 SFndLenMsg(mBuf, lngPtr)
3195 REG1 Buffer *mBuf; /* message buffer */
3196 MsgLen *lngPtr; /* pointer to length */
3203 #if (ERRCLASS & ERRCLS_INT_PAR)
3204 /* check message buffer */
3207 SSLOGERROR(ERRCLS_INT_PAR, ESS094, ERRZERO, "SFndLenMsg : Null Buffer");
3210 /* check length pointer */
3211 if (lngPtr == NULLP)
3213 SSLOGERROR(ERRCLS_INT_PAR, ESS095, ERRZERO, "SFndLenMsg : Null Buffer");
3216 if (mBuf->b_datap->db_type != SS_M_PROTO)
3218 SSLOGERROR(ERRCLS_INT_PAR, ESS096, ERRZERO, "SFndLenMsg : Incorrect\
3224 /* get the SsMsgInfo */
3225 minfo = (SsMsgInfo*) mBuf->b_rptr;
3228 *lngPtr = minfo->len;
3234 /* #ifdef SS_LOCKLESS_MEMORY */
3240 * Desc: This function will segment one specified message into two
3244 * ROKDNA - ok, data not available
3245 * RFAILED - failed, general (optional)
3246 * ROUTRES - failed, out of resources (optional)
3248 * Notes: message 1 is the original message.
3250 * message 2 is the new message.
3252 * index is 0 based and indicates location in message 1
3253 * from which message 2 will be created.
3255 * if index is equal to 0: message 2 is created and all data
3256 * attached to message 1 is moved to message 2. message 1
3257 * is not returned to memory. return is ok.
3259 * if index is not equal to 0 and less than the length of
3260 * the message minus 1: message 2 is created, all data
3261 * attached to message 1 from index (inclusive) is moved to
3262 * message 2. message 1 contains data from index 0 to index
3263 * minus 1. return is ok.
3265 * if index is not equal to 0 and greater than or equal to
3266 * the length of the message minus 1: message 1 is unchanged.
3267 * message 2 is set to null. return is ok, data not available.
3272 #ifdef T2K_MEM_LEAK_DBG
3273 PUBLIC S16 SSegMsgNew
3275 Buffer *mBuf1, /* message 1 */
3276 MsgLen idx, /* index */
3285 Buffer *mBuf1, /* message 1 */
3286 MsgLen idx, /* index */
3290 PUBLIC S16 SSegMsg(mBuf1, idx, mBuf2)
3291 Buffer *mBuf1; /* message 1 */
3292 MsgLen idx; /* index */
3293 Buffer **mBuf2; /* message 2 */
3305 #if (ERRCLASS & ERRCLS_INT_PAR)
3306 /* check message buffer 1 */
3309 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SSegMsg : Null Buffer");
3312 /* check message buffer 2 */
3315 SSLOGERROR(ERRCLS_INT_PAR, ESS098, ERRZERO, "SSegMsg : Null Buffer");
3320 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SSegMsg : Invalid index");
3323 if (mBuf1->b_datap->db_type != SS_M_PROTO)
3325 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SSegMsg : Incorrect buffer\
3331 /* get the SsMsgInfo of mBuf1 */
3332 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
3333 #ifdef RGL_SPECIFIC_CHANGES
3337 /* if index > length of mBuf, return */
3338 if (idx >= minfo1->len)
3343 /* allocate message buffer */
3344 if (SGetMsg(minfo1->region, minfo1->pool, mBuf2) != ROK)
3346 SSLOGERROR(ERRCLS_DEBUG, ESS101, ERRZERO, "SSegMsg : SGetMsg failed");
3350 /* get the SsMsgInfo of mBuf2 */
3351 minfo2 = (SsMsgInfo*) (*mBuf2)->b_rptr;
3353 /* adjust the lengths of mBuf1, mBuf2 */
3354 minfo2->len = minfo1->len - idx;
3357 /* set the endptr of mBuf2 to mBuf1 */
3358 minfo2->endptr = minfo1->endptr;
3360 /* if index is zero ... */
3363 (*mBuf2)->b_cont = mBuf1->b_cont;
3365 /* set the endptr and b_cont of mBuf1 to NULLP */
3366 minfo1->endptr = NULLP;
3367 mBuf1->b_cont = NULLP;
3372 /* get the first SS_M_DATA blk */
3373 tmp = mBuf1->b_cont;
3376 FIND_OFFSET_AND_PREV(prev, tmp, idx)
3378 /* segmented at the start of a blk */
3381 (*mBuf2)->b_cont = tmp;
3382 prev->b_cont = NULLP;
3383 minfo1->endptr = prev;
3387 #ifndef SS_MULTICORE_SUPPORT
3388 /* allocate a message blk without a data blk */
3389 /* ssDupB internally increments the reference count */
3390 #ifdef SS_M_PROTO_REGION
3391 if (!(next = DupMsg(minfo1->region, tmp)))
3393 if (!(next = ssDupB(tmp)))
3394 #endif /* SS_M_PROTO_REGION */
3397 minfo1->len += minfo2->len;
3398 (Void) SPutMsg(*mBuf2);
3402 (*mBuf2)->b_cont = next;
3404 tmp->b_cont = NULLP;
3406 tmp->b_wptr = tmp->b_rptr + idx;
3407 next->b_rptr = tmp->b_wptr;
3409 /* If the index was in the last mblk of the message, the
3410 * end pointer of the new message needs to be set to the
3411 * dup'ped mblk. Otherwise, the end pointer of the first
3412 * message will be set to the mblk in which the index
3413 * was found, and the end pointer of the new message can
3414 * remain where it is.
3416 if (minfo1->endptr == tmp)
3418 minfo2->endptr = next;
3422 minfo1->endptr = tmp;
3424 #else /*SS_MULTICORE_SUPPORT*/
3428 #ifdef SS_M_PROTO_REGION
3429 if (!(next = DupMsg(minfo1->region, tmp)))
3431 if (!(next = ssDupB(tmp)))
3432 #endif /* SS_M_PROTO_REGION */
3435 minfo1->len += minfo2->len;
3436 (Void) SPutMsg(*mBuf2);
3439 (*mBuf2)->b_cont = next;
3440 tmp->b_wptr = tmp->b_rptr + idx;
3441 next->b_rptr += idx;
3444 /* copy rest of the blocks */
3448 prev->b_cont = NULLP;
3449 minfo2->endptr = minfo1->endptr;
3450 minfo1->endptr = prev;
3454 next->b_cont = NULLP;
3455 minfo2->endptr = next;
3458 #endif /*SS_MULTICORE_SUPPORT*/
3468 * Desc: This function copies data from a fixed buffer to a
3472 * RFAILED - failed, general (optional)
3481 PUBLIC S16 SCpyFixMsg
3483 Data *srcBuf, /* source buffer */
3484 Buffer *dstMbuf, /* destination message buffer */
3485 MsgLen dstIdx, /* destination index */
3486 MsgLen cnt, /* count */
3490 PUBLIC S16 SCpyFixMsg(srcBuf, dstMbuf, dstIdx, cnt, cCnt)
3491 Data *srcBuf; /* source buffer */
3492 Buffer *dstMbuf; /* destination message buffer */
3493 MsgLen dstIdx; /* destination index */
3494 MsgLen cnt; /* count */
3495 MsgLen *cCnt; /* copied count */
3504 #if (ERRCLASS & ERRCLS_INT_PAR)
3505 /* check source message buffer */
3506 if (srcBuf == NULLP)
3508 SSLOGERROR(ERRCLS_INT_PAR, ESS102, ERRZERO, "SCpyFixMsg : Null Buffer");
3511 /* check destination message buffer */
3512 if (dstMbuf == NULLP)
3514 SSLOGERROR(ERRCLS_INT_PAR, ESS103, ERRZERO, "SCpyFixMsg : Null Buffer");
3517 /* check copied count buffer */
3520 SSLOGERROR(ERRCLS_INT_PAR, ESS104, ERRZERO, "SCpyFixMsg : Null Buffer");
3523 /* check copy count */
3526 SSLOGERROR(ERRCLS_INT_PAR, ESS105, ERRZERO, "SCpyFixMsg : Invalid count");
3529 if (dstMbuf->b_datap->db_type != SS_M_PROTO)
3531 SSLOGERROR(ERRCLS_INT_PAR, ESS106, ERRZERO, "SCpyFixMsg : Incorrect\
3537 minfo = (SsMsgInfo*) dstMbuf->b_rptr;
3539 if (minfo->len < dstIdx)
3541 #if (ERRCLASS & ERRCLS_DEBUG)
3542 SSLOGERROR(ERRCLS_DEBUG, ESS107, ERRZERO, "SCpyFixMsg : Invalid Index");
3547 /* ss021.103 - Addition test if message length will exceed max msg length */
3548 #if (ERRCLASS & ERRCLS_INT_PAR)
3550 if (minfo->len > 0x7FFFFFFF - cnt)
3552 if (minfo->len > 0x7FFF - cnt)
3557 SSLOGERROR(ERRCLS_INT_PAR, ESS108, ERRZERO, "SCpyFixMsg : msgLen + cnt > maxS16");
3562 /* add data at the start of dst buffer */
3565 if ((ret = SAddPreMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3567 #if (ERRCLASS & ERRCLS_DEBUG)
3568 SSLOGERROR(ERRCLS_DEBUG, ESS109, ERRZERO, "SCpyFixMsg : Failed in\
3578 /* add data at the end of the dst buffer */
3579 if (minfo->len == dstIdx)
3581 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3590 /* segment the message into dstMbuf and right */
3591 if ((ret = SSegMsg(dstMbuf, dstIdx, &right)) != ROK)
3596 /* append data at the end of dstMbuf */
3597 if ((ret = SAddPstMsgMult(srcBuf, cnt, dstMbuf)) != ROK)
3599 /* ss020.103 - Addition for cleanup */
3600 (Void) SPutMsg(right);
3604 /* cancatenate dstMbuf and right */
3605 if ((ret = SCatMsg(dstMbuf, right, M1M2)) != ROK)
3607 /* ss020.103 - Addition for cleanup */
3608 (Void) SPutMsg(right);
3614 (Void) SPutMsg(right);
3623 * Desc: This function copies data from a message
3624 * into a fixed buffer.
3627 * RFAILED - failed, general (optional)
3636 PUBLIC S16 SCpyMsgFix
3638 Buffer *srcMbuf, /* source message buffer */
3639 MsgLen srcIdx, /* source index */
3640 MsgLen cnt, /* count */
3641 Data *dstBuf, /* destination buffer */
3645 PUBLIC S16 SCpyMsgFix(srcMbuf, srcIdx, cnt, dstBuf, cCnt)
3646 Buffer *srcMbuf; /* source message buffer */
3647 MsgLen srcIdx; /* source index */
3648 MsgLen cnt; /* count */
3649 Data *dstBuf; /* destination buffer */
3650 MsgLen *cCnt; /* copied count */
3660 #if (ERRCLASS & ERRCLS_INT_PAR)
3661 /* check source message buffer */
3662 if (srcMbuf == NULLP)
3664 SSLOGERROR(ERRCLS_INT_PAR, ESS110, ERRZERO, "SCpyMsgFix : Null Buffer");
3667 /* check destination message buffer */
3668 if (dstBuf == NULLP)
3670 SSLOGERROR(ERRCLS_INT_PAR, ESS111, ERRZERO, "SCpyMsgFix : Null Buffer");
3675 SSLOGERROR(ERRCLS_INT_PAR, ESS112, ERRZERO, "SCpyMsgFix : Invalid Index");
3681 SSLOGERROR(ERRCLS_INT_PAR, ESS113, ERRZERO, "SCpyMsgFix : Invalid Index");
3686 SSLOGERROR(ERRCLS_INT_PAR, ESS114, ERRZERO, "SCpyMsgFix : Null Buffer");
3689 if (srcMbuf->b_datap->db_type != SS_M_PROTO)
3691 SSLOGERROR(ERRCLS_INT_PAR, ESS115, ERRZERO, "SCpyMsgFix : Incorrect\
3698 minfo = (SsMsgInfo*) srcMbuf->b_rptr;
3700 if ((srcIdx + cnt) > minfo->len)
3706 /* get the first SS_M_DATA blk */
3707 tmp = srcMbuf->b_cont;
3709 /* get to the srcIdx-th offset */
3710 FIND_OFFSET(tmp, srcIdx)
3714 /* set cptr to the read ptr of tmp + offset */
3715 cptr = tmp->b_rptr + srcIdx;
3719 /* determine the number of bytes to be copied */
3720 numBytes = MIN(cnt, (tmp->b_wptr - cptr));
3727 /* ss002.13 addition */
3729 /* ss003.13 addition */
3730 SMemCpy((Void *) dstBuf, (Void *) cptr, (size_t) numBytes);
3736 /* get the next blk */
3737 if ((tmp = tmp->b_cont))
3738 /* set cptr to the read ptr of tmp */
3751 * Desc: This function is used to copy a message into
3752 * a new region and or pool of memory.
3755 * RFAILED - failed, general (optional)
3756 * ROUTRES - failed, out of resources (optional)
3764 #ifdef T2K_MEM_LEAK_DBG
3765 PUBLIC S16 SCpyMsgMsgNew
3776 PUBLIC S16 SCpyMsgMsg
3784 PUBLIC S16 SCpyMsgMsg(srcBuf, dstRegion, dstPool, dstBuf)
3799 /* ss021.103 - Addition of return value */
3801 #if (ERRCLASS & ERRCLS_INT_PAR)
3808 #if (ERRCLASS & ERRCLS_INT_PAR)
3811 SSLOGERROR(ERRCLS_INT_PAR, ESS116, ERRZERO, "SCpyMsgMsg : Null Buffer");
3814 if (srcBuf->b_datap->db_type != SS_M_PROTO)
3816 SSLOGERROR(ERRCLS_INT_PAR, ESS117, ERRZERO, "SCpyMsgMsg : Incorrect\
3820 /* ss021.103 - Addition to validate region and pool */
3821 if (dstRegion >= SS_MAX_REGS)
3823 SSLOGERROR(ERRCLS_INT_PAR, ESS118, ERRZERO,
3824 "SCpyMsgMsg : Invalid region id");
3828 if (dstPool >= SS_MAX_POOLS_PER_REG)
3830 SSLOGERROR(ERRCLS_INT_PAR, ESS119, ERRZERO,
3831 "SCpyMsgMsg : Invalid pool id");
3834 /* ss037.103 Removed the semaphore operation for performance enhancement */
3837 /* ss021.103 - Addition to check if region is valid */
3838 /* acquire one semaphore, to protect against deregistration */
3839 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
3843 #if (ERRCLASS & ERRCLS_DEBUG)
3844 SSLOGERROR(ERRCLS_DEBUG, ESS120, (ErrVal) ret,
3845 "Could not lock region table");
3852 #if (ERRCLASS & ERRCLS_INT_PAR)
3853 /* verify that this region is present */
3854 if (osCp.regionTbl[dstRegion].used == FALSE)
3857 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3859 #if (ERRCLASS & ERRCLS_DEBUG)
3860 SSLOGERROR(ERRCLS_DEBUG, ESS121, ERRZERO,
3861 "Could not release semaphore");
3866 SSLOGERROR(ERRCLS_INT_PAR, ESS122, dstRegion, "Region not registered");
3870 /* ss037.103 Removed the semaphore operation for performance enhancement */
3873 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
3875 #if (ERRCLASS & ERRCLS_DEBUG)
3876 SSLOGERROR(ERRCLS_DEBUG, ESS123, ERRZERO,
3877 "Could not release semaphore");
3884 #ifdef XEON_SPECIFIC_CHANGES
3888 /* allocate a message buffer */
3889 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
3891 #if (ERRCLASS & ERRCLS_DEBUG)
3892 SSLOGERROR(ERRCLS_DEBUG, ESS124, ERRZERO, "SCpyMsgMsg : SGetMsg failed");
3896 /* get the SsMsgInfo from srcBuf */
3897 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
3899 /* get the SsMsgInfo from srcBuf */
3900 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
3902 /* get the first SS_M_DATA blk of srcBuf */
3903 tmp = srcBuf->b_cont;
3905 /* if srcBuf and dstBuf belong to the same region, increment the reference
3914 #ifdef SS_M_PROTO_REGION
3915 if ((curblk = DupMsg(dstRegion,tmp)) == NULLP)
3917 if ((curblk = ssDupB(tmp)) == NULLP)
3918 #endif /* SS_M_PROTO_REGION */
3922 curblk = newblk->b_cont;
3923 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
3926 printf("Failed to get the buffer of size %s %d\n", __FILE__, __LINE__);
3927 (Void) SPutMsg(*dstBuf);
3934 prevblk->b_cont = curblk;
3940 curblk->b_cont = NULLP;
3942 minfo2->len = minfo1->len;
3943 minfo2->endptr = curblk;
3944 (*dstBuf)->b_cont = newblk;
3955 * Desc: This function is used to copy a message into
3956 * a new region and or pool of memory.
3959 * RFAILED - failed, general (optional)
3960 * ROUTRES - failed, out of resources (optional)
3967 #ifdef T2K_MEM_LEAK_DBG
3968 PUBLIC S16 SAddMsgRefNew
3979 PUBLIC S16 SAddMsgRef
3987 PUBLIC S16 SAddMsgRef(srcBuf, dstRegion, dstPool, dstBuf)
4007 #if (ERRCLASS & ERRCLS_INT_PAR)
4010 SSLOGERROR(ERRCLS_INT_PAR, ESS126, ERRZERO, "SAddMsgRef : Null Buffer");
4013 if (srcBuf->b_datap->db_type != SS_M_PROTO)
4015 SSLOGERROR(ERRCLS_INT_PAR, ESS127, ERRZERO, "SAddMsgRef : Incorrect\
4020 #ifdef XEON_SPECIFIC_CHANGES
4025 /* allocate a message buffer */
4026 if (SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
4028 #if (ERRCLASS & ERRCLS_DEBUG)
4029 SSLOGERROR(ERRCLS_DEBUG, ESS128, ERRZERO, "SAddMsgRef : SGetMsg failed");
4033 /* get the SsMsgInfo from srcBuf */
4034 minfo1 = (SsMsgInfo*) srcBuf->b_rptr;
4036 /* get the SsMsgInfo from srcBuf */
4037 minfo2 = (SsMsgInfo*) (*dstBuf)->b_rptr;
4039 /* get the first SS_M_DATA blk of srcBuf */
4040 tmp = srcBuf->b_cont;
4042 /* if srcBuf and dstBuf belong to the same region, increment the reference
4045 if (dstRegion == minfo1->region)
4053 #ifdef SS_M_PROTO_REGION
4054 if ((curblk = DupMsg(dstRegion, tmp)) == NULLP)
4056 if ((curblk = ssDupB(tmp)) == NULLP)
4057 #endif /* SS_M_PROTO_REGION */
4061 curblk = newblk->b_cont;
4062 (Void) SPutDBuf(minfo1->region, minfo1->pool, newblk);
4065 (Void) SPutMsg(*dstBuf);
4072 prevblk->b_cont = curblk;
4078 curblk->b_cont = NULLP;
4080 minfo2->len = minfo1->len;
4081 minfo2->endptr = curblk;
4082 (*dstBuf)->b_cont = newblk;
4087 /* allocate a data buffer */
4088 if (ssGetDBufOfSize(dstRegion, minfo1->len, &dBuf) != ROK)
4090 /* ss016.13: addition */
4091 (Void) SPutMsg(*dstBuf);
4092 SSLOGERROR(ERRCLS_DEBUG, ESS129, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
4096 dBuf->b_datap->db_type = SS_M_DATA;
4100 numBytes = tmp->b_wptr - tmp->b_rptr;
4103 *dBuf->b_wptr++ = *cptr++;
4106 minfo2->len = minfo1->len;
4107 /* set the endptr and b_cont of dstBuf to point to dBuf */
4108 minfo2->endptr = dBuf;
4109 (*dstBuf)->b_cont = dBuf;
4113 /* ss012.13: Addition */
4114 #ifdef SS_M_PROTO_REGION
4119 * Desc: Duplicates the specified message block, copying it
4120 * into a newly-allocated message block. Increments
4121 * the reference count of the data block that is pointed
4122 * at by the original message block descriptor.
4124 * Ret: non-NULL - ok
4132 #ifdef T2K_MEM_LEAK_DBG
4133 PRIVATE Buffer *DupMsgNew
4135 Region region, /* region id */
4136 Buffer *mp, /* message block */
4142 PRIVATE Buffer *DupMsg
4144 Region region, /* region id */
4145 Buffer *mp /* message block */
4148 PRIVATE Buffer *DupMsg(region, mp)
4149 Region region; /* region id */
4150 Buffer *mp; /* message block */
4154 Buffer *bp; /* mblk for iteration */
4155 S16 r; /* return value */
4156 Size m; /* temporary */
4161 #if (ERRCLASS & ERRCLS_INT_PAR)
4164 SSLOGERROR(ERRCLS_INT_PAR, ESS130, ERRZERO, "Null pointer");
4168 if (region >= SS_MAX_REGS)
4170 SSLOGERROR(ERRCLS_INT_PAR, ESS131, ERRZERO, "DupMsg : Invalid region\
4177 /* allocate a single block for the mblock and the dblock */
4179 m = (sizeof(SsMblk) + sizeof(SsDblk));
4181 numBytes = mp->b_wptr - mp->b_rptr;
4182 m = MDBSIZE + numBytes;
4183 #endif /* SS_MULTICORE_SUPPORT */
4184 /* ss001.301: additions */
4185 #ifdef SS_HISTOGRAM_SUPPORT
4186 r = SAlloc(region, &m, 0, (Data **)&bp, __LINE__, (U8*) __FILE__, ENTNC);
4188 r = SAlloc(region, &m, 0, (Data **)&bp);
4189 #endif /* SS_HISTOGRAM_SUPPORT */
4192 #if (ERRCLASS & ERRCLS_ADD_RES)
4193 SSLOGERROR(ERRCLS_ADD_RES, ESS132, (ErrVal) r, "SAlloc() failed");
4198 /* generic set-up-message function */
4200 #ifndef SS_DBUF_REFLOCK_DISABLE
4201 SS_STRM_INITB(bp, (SsDblk *)(((U8 *)bp) + sizeof(SsMblk)), NULLP, 0, NULLP);
4204 data = (Data *) (bp) + MDBSIZE;
4205 SS_STRM_INITB(bp,(SsDblk *)(((U8 *)bp) + sizeof(SsMblk)), data, numBytes, NULLP);
4206 #endif /* SS_MULTICORE_SUPPORT */
4209 /* make the new message block identical to the one to be dup'ed.
4210 * notice that an mblk/dblk pair is allocated but only the mblk
4211 * is used,, this is for optimum performance in the average case.
4213 SMemCpy( (Void *)bp, (Void *)mp, (size_t)sizeof(SsMblk));
4215 /* ss006.301 - added the Lock */
4216 #ifndef SS_DBUF_REFLOCK_DISABLE
4217 if((SLock(&(mp->b_datap->dBufLock))) != ROK)
4219 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
4220 "Could not lock the mBuf Ref Lock");
4224 /* increment the reference count of the dblock */
4225 /* increment the reference count of the dblock */
4226 mp->b_datap->db_ref++;
4227 mp->b_datap->shared = TRUE;
4228 #ifndef SS_DBUF_REFLOCK_DISABLE
4229 if((SUnlock(&(mp->b_datap->dBufLock))) != ROK)
4231 SSLOGERROR(ERRCLS_DEBUG, ESS335, ERRZERO,
4232 "Could not lock the mBuf Ref Lock");
4240 #endif /* SS_M_PROTO_REGION */
4246 * Desc: This function allocates a buffer from the dynamic
4247 * memory pool indicated by the caller.
4250 * RFAILED - failed, general (optional)
4251 * ROUTRES - failed, out of resources (optional)
4253 * Notes: The dynamic memory pools are used to create and
4254 * manipulate messages.
4256 * SGetDBuf is never called by a protocol layer.
4258 * SGetDBuf assumes that interrupts are already disabled.
4264 #ifdef T2K_MEM_LEAK_DBG
4265 PUBLIC S16 SGetDBufNew
4267 Region region, /* region id */
4268 Pool pool, /* pool id */
4277 Region region, /* region id */
4278 Pool pool, /* pool id */
4282 PUBLIC S16 SGetDBuf(region, pool, bufPtr)
4283 Region region; /* region id */
4284 Pool pool; /* pool id */
4285 Buffer **bufPtr; /* pointer to buffer */
4293 #ifdef SS_LOCKLESS_MEMORY
4294 #ifdef SS_USE_ICC_MEMORY
4295 CmMmDynRegCb *regCb;
4297 CmMmGlobRegCb *regCb;
4300 SsRegionEntry *regp;
4301 #endif /* SS_LOCKLESS_MEMORY */
4302 /* ss021.103 - Addition of return value */
4304 #if (ERRCLASS & ERRCLS_INT_PAR)
4311 #if (ERRCLASS & ERRCLS_INT_PAR)
4312 /* check buffer pointer */
4315 SSLOGERROR(ERRCLS_INT_PAR, ESS133, ERRZERO, "SGetDBuf : Null Buffer");
4318 if (region >= SS_MAX_REGS)
4320 SSLOGERROR(ERRCLS_INT_PAR, ESS134, ERRZERO, "SGetDBuf : Invalid region\
4325 if (pool >= SS_MAX_POOLS_PER_REG)
4327 SSLOGERROR(ERRCLS_INT_PAR, ESS135, ERRZERO, "SGetDBuf : Invalid pool id");
4330 /* ss037.103 Removed the semaphore operation for performance enhancement */
4333 /* ss021.103 - Addition to check if region is registered */
4334 /* acquire one semaphore, to protect against deregistration */
4335 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
4339 #if (ERRCLASS & ERRCLS_DEBUG)
4340 SSLOGERROR(ERRCLS_DEBUG, ESS136, (ErrVal) ret,
4341 "Could not lock region table");
4349 #if (ERRCLASS & ERRCLS_INT_PAR)
4350 /* verify that this region is present */
4351 if (osCp.regionTbl[region].used == FALSE)
4353 /* ss037.103 Removed the semaphore operation for performance enhancement */
4356 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4358 #if (ERRCLASS & ERRCLS_DEBUG)
4359 SSLOGERROR(ERRCLS_DEBUG, ESS137, ERRZERO,
4360 "Could not release semaphore");
4365 SSLOGERROR(ERRCLS_INT_PAR, ESS138, region, "Region not registered");
4369 /* ss037.103 Removed the semaphore operation for performance enhancement */
4372 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
4374 #if (ERRCLASS & ERRCLS_DEBUG)
4375 SSLOGERROR(ERRCLS_DEBUG, ESS139, ERRZERO,
4376 "Could not release semaphore");
4383 #ifdef SS_LOCKLESS_MEMORY
4384 #ifdef SS_USE_ICC_MEMORY
4385 regCb = (CmMmDynRegCb *)(osCp.dynRegionTbl[region].regCb);
4386 mdsize = regCb->bktSize[pool];
4387 #else /* SS_USE_ICC_MEMORY */
4388 regCb = osCp.globRegCb;
4389 #ifdef SS_MEM_WL_DEBUG
4390 mdsize = regCb->bktTbl[pool].size - 4;
4391 #else /* SS_MEM_WL_DEBUG */
4392 mdsize = regCb->bktTbl[pool].size;
4393 #endif /* SS_MEM_WL_DEBUG */
4394 #endif /* SS_USE_ICC_MEMORY */
4396 regp = &osCp.regionTbl[region];
4397 size = regp->poolTbl[pool].u.dpool.size;
4398 /* ss006.301 : optimized this function */
4399 mdsize = MDBSIZE + size;
4400 #endif /* SS_LOCKLESS_MEMORY */
4402 /* ss006.301 : optimized this function */
4403 /* ss001.301: additions */
4404 #ifdef SS_HISTOGRAM_SUPPORT
4405 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
4407 if (SAlloc(region, &mdsize, 0, (Data **) bufPtr) != ROK)
4408 #endif /* SS_HISTOGRAM_SUPPORT */
4412 data = (Data *) (*bufPtr) + MDBSIZE;
4413 size = mdsize - MDBSIZE;
4415 dptr = (SsDblk*) (((Data *) (*bufPtr)) + MBSIZE);
4417 INITB((*bufPtr), dptr, data, size, NULLP)
4418 #ifndef SS_DBUF_REFLOCK_DISABLE
4419 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
4421 printf("Falied to destroy lock\n");
4432 * Desc: This function deallocates a buffer back to the
4433 * dynamic memory pool indicated by the caller.
4436 * RFAILED - failed, general (optional)
4438 * Notes: The dynamic memory pools are used to create and
4439 * manipulate messages.
4441 * SPutDBuf is never called by a protocol layer.
4443 * SPutDBuf assumes that interrupts are already disabled.
4449 #ifdef T2K_MEM_LEAK_DBG
4450 PUBLIC S16 SPutDBufNew
4467 PUBLIC S16 SPutDBuf(region, pool, buf)
4474 register SsDblk *dptr;
4475 /* ss021.103 - Addition to check return value of SFree */
4477 #if (defined(SS_USE_ZBC_MEMORY) && defined (TENB_DPDK_BUF))
4483 /* ss021.103 - Addition of ret initialization */
4486 #if (ERRCLASS & ERRCLS_INT_PAR)
4487 if (region >= SS_MAX_REGS)
4489 SSLOGERROR(ERRCLS_INT_PAR, ESS141, ERRZERO, "SPutDBuf:Invalid region");
4493 if (pool >= SS_MAX_POOLS_PER_REG)
4495 SSLOGERROR(ERRCLS_INT_PAR, ESS142, ERRZERO, "SPutDBuf:Invalid pool");
4501 SSLOGERROR(ERRCLS_INT_PAR, ESS143, ERRZERO, "SPutDBuf:Null pointer");
4505 if ( (buf->b_datap->db_type != SS_M_DATA) && (buf->b_datap->db_type != SS_M_PROTO))
4507 SSLOGERROR(ERRCLS_INT_PAR, ESS144, ERRZERO, "SPutDBuf:Incorrect\
4512 /* ss016.13: Addition */
4513 dptr = buf->b_datap;
4515 #ifdef SS_USE_ZBC_MEMORY
4516 if(dptr->db_type == SS_MEM_TYPE_SSI_ZBC)
4518 ret = SPutZbcDBuf(region, buf);
4522 #ifdef TENB_DPDK_BUF
4523 if(dptr->db_type == SS_MEM_TYPE_DPDK_ZBC)
4525 /* Not considering referances for DPDK buffer for now */
4526 SDetachDpdkPtrFrmDBuf(buf, &dpdkBuf);
4527 SPutSBufDpdk(dpdkBuf);
4528 ret = SFree(region, (Data *) buf, MDBSIZE);
4531 #endif /* TENB_DPDK_BUF */
4532 #endif /* SS_USE_ZBC_MEMORY */
4534 /* ss028.103 - Addition of lock for mBuf reference count */
4535 /* ss006.301 : optimized this funciton */
4539 #ifndef SS_DBUF_REFLOCK_DISABLE
4540 SDestroyLock(&dptr->dBufLock);
4542 /* if the data block is not shared, free the buffer, checks not reqd */
4543 #ifdef SS_HISTOGRAM_SUPPORT
4544 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4545 , __LINE__, (U8*) __FILE__, ENTNC);
4547 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4548 #endif /* SS_HISTOGRAM_SUPPORT */
4552 #ifndef SS_DBUF_REFLOCK_DISABLE
4553 if((ret=SLock(&dptr->dBufLock)))
4555 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
4556 "Could not lock the mBuf Ref Lock");
4561 /* if buffer's message blk is obtained during dupb */
4562 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
4565 SsDblk* dupdptr = (SsDblk *)((U8 *)buf + MBSIZE);
4567 if(dupdptr->db_ref == 0)
4570 #ifdef SS_HISTOGRAM_SUPPORT
4571 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__, ENTNC);
4573 ret = SFree(region, (Data *) buf, MDBSIZE);
4575 #endif /* SS_HISTOGRAM_SUPPORT */
4577 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
4579 /* if reference count falls to zero */
4582 #ifndef SS_DBUF_REFLOCK_DISABLE
4583 ret = SUnlock(&dptr->dBufLock) ;
4584 if((SDestroyLock(&dptr->dBufLock)) != 0)
4586 printf("Falied to destroy lock\n");
4589 /* free buffer to region */
4590 #ifdef SS_HISTOGRAM_SUPPORT
4591 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4592 , __LINE__, (U8*) __FILE__, ENTNC);
4594 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4595 #endif /* SS_HISTOGRAM_SUPPORT */
4598 #ifndef SS_DBUF_REFLOCK_DISABLE
4599 ret = SUnlock(&(dptr->dBufLock));
4602 #else /* SS_MULTICORE_SUPPORT */
4603 /* If MultiCore Support enabled, Dblk never be shared */
4604 #ifdef SS_HISTOGRAM_SUPPORT
4605 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base
4606 , __LINE__, (U8*) __FILE__, ENTNC);
4608 ret = SFree(region, (Data *) buf, MDBSIZE + dptr->db_lim - dptr->db_base);
4609 #endif /* SS_HISTOGRAM_SUPPORT */
4610 #endif /* SS_MULTICORE_SUPPORT */
4615 /* #ifdef SS_LOCKLESS_MEMORY */
4622 * Desc: This function will concatenate the two specified messages
4626 * RFAILED - failed, general (optional)
4628 * Notes: if order equal M1M2: all data attached to message 2 is
4629 * moved to the end of message 1. message 2 is set to empty.
4630 * message 1 length is increased by length of message 2.
4631 * message 2 length is set to zero. message 2 is not returned
4632 * to memory. return is ok.
4634 * if order equal M2M1: all data attached to message 2 is
4635 * moved to the front of message 1. message 2 is set to empty.
4636 * message 1 length is increased by length of message 2.
4637 * message 2 length is set to zero. message 2 is not returned
4638 * to memory. return is ok.
4648 Buffer *mBuf1, /* message 1 */
4649 Buffer *mBuf2, /* message 2 */
4653 PUBLIC S16 SCatMsg(mBuf1, mBuf2, order)
4654 Buffer *mBuf1; /* message 1 */
4655 Buffer *mBuf2; /* message 2 */
4656 Order order; /* order */
4666 #if (ERRCLASS & ERRCLS_INT_PAR)
4667 /* check message buffer 1 */
4670 SSLOGERROR(ERRCLS_INT_PAR, ESS148, ERRZERO, "SCatMsg : Null Buffer");
4673 /* check message buffer 2 */
4676 SSLOGERROR(ERRCLS_INT_PAR, ESS149, ERRZERO, "SCatMsg : Null Buffer");
4679 /* ss021.103 - Addition to test if same buffer */
4680 /* check message buffer 1 and 2 not same buffer */
4683 SSLOGERROR(ERRCLS_INT_PAR, ESS150, ERRZERO, "SCatMsg : mBuf1 == mBuf2");
4686 if ((order != M1M2) && (order != M2M1))
4688 SSLOGERROR(ERRCLS_INT_PAR, ESS151, ERRZERO, "SCatMsg : Invalid Order");
4691 if ((mBuf1->b_datap->db_type != SS_M_PROTO) ||
4692 (mBuf2->b_datap->db_type != SS_M_PROTO))
4694 SSLOGERROR(ERRCLS_INT_PAR, ESS152, ERRZERO,
4695 "SCatMsg : Incorrect buffer type");
4700 /* no data to append or prepend */
4704 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
4705 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
4707 /* ss021.103 - Addition to test max length of message is not exceeded */
4708 #if (ERRCLASS & ERRCLS_INT_PAR)
4710 if (minfo1->len > 0x7FFFFFFF - minfo2->len)
4712 if (minfo1->len > 0x7FFF - minfo2->len)
4715 SSLOGERROR(ERRCLS_INT_PAR, ESS153, ERRZERO, "SCpyFixMsg : messages too big");
4720 if (minfo1->region != minfo2->region)
4722 /* duplicate mBuf2 from the region/pool of mBuf1, initialise mBuf2 */
4723 /*ss015.13: addition */
4724 if (SCpyMsgMsg(mBuf2, minfo1->region, minfo1->pool, &newb) != ROK)
4727 minfo2 = (SsMsgInfo*) newb->b_rptr;
4732 if ((tmp = mBuf1->b_cont) == NULLP)
4734 mBuf1->b_cont = newb->b_cont;
4735 minfo1->endptr = minfo2->endptr;
4740 /* attach newb after mBuf1 */
4742 minfo1->endptr->b_cont = newb->b_cont;
4743 minfo1->endptr = minfo2->endptr;
4748 /* attach newb before mBuf1 */
4750 minfo2->endptr->b_cont = mBuf1->b_cont;
4751 mBuf1->b_cont = newb->b_cont;
4753 else /* invalid order */
4755 #if (ERRCLASS & ERRCLS_DEBUG)
4756 SSLOGERROR(ERRCLS_DEBUG, ESS154, ERRZERO, "SCatMsg:Invalid order");
4758 if (newb && (newb != mBuf2))
4759 (Void) SPutMsg(newb);
4764 minfo1->len += minfo2->len;
4767 minfo2->endptr = NULLP;
4770 newb->b_cont = NULLP;
4774 (Void) SPutMsg(newb);
4775 (Void) SInitMsg(mBuf2);
4785 * Desc: This function replaces one byte of data in a message.
4788 * ROKDNA - ok, data not available
4789 * RFAILED - failed, general (optional)
4791 * Notes: index is 0 based and indicates location in message
4793 * if index is less than the length of the message:
4794 * data is replaced at specified index. message length
4795 * is unchanged. return is ok.
4797 * if index is greater than or equal to
4798 * the length of the message: message is unchanged.
4799 * return is ok, data not available.
4809 Data data, /* data */
4810 Buffer *mBuf, /* message buffer */
4814 PUBLIC S16 SRepMsg(data, mBuf, idx)
4815 Data data; /* data */
4816 Buffer *mBuf; /* message buffer */
4817 MsgLen idx; /* index */
4828 #ifdef T2K_MEM_LEAK_DBG
4829 char* file = __FILE__;
4830 U32 line = __LINE__;
4832 #if ( ERRCLASS & ERRCLS_INT_PAR)
4833 /* check message buffer */
4836 SSLOGERROR(ERRCLS_INT_PAR, ESS155, ERRZERO, "SRepMsg : Null Buffer");
4841 SSLOGERROR(ERRCLS_INT_PAR, ESS156, ERRZERO, "SRepMsg : Invalid index");
4844 if (mBuf->b_datap->db_type != SS_M_PROTO)
4846 SSLOGERROR(ERRCLS_INT_PAR, ESS157, ERRZERO, "SRepMsg : Incorrect buffer\
4852 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4854 /* if index > length of the buffer */
4855 if (minfo->len <= idx)
4860 tmp = mBuf->b_cont; /* get the first SS_M_DATA blk */
4861 prev = mBuf; /* parent */
4863 FIND_OFFSET_AND_PREV(prev, tmp, idx)
4865 /* if ref cnt is greater than 1, duplicate tmp */
4866 if (tmp->b_datap->db_ref > 1)
4868 /* allocate a message blk of message size of tmp */
4869 numBytes = tmp->b_wptr - tmp->b_rptr;
4870 if (ssGetDBufOfSize(minfo->region, numBytes, &newb) != ROK)
4872 SSLOGERROR(ERRCLS_DEBUG, ESS158, ERRZERO, "SRepMsg : ssGetDBufOfSize\
4877 *newb->b_wptr++ = *tmp->b_rptr++;
4879 newb->b_cont = tmp->b_cont;
4880 prev->b_cont = newb;
4881 if (minfo->endptr == tmp)
4882 minfo->endptr = newb;
4885 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
4888 *(tmp->b_rptr + idx) = data;
4897 * Desc: Update a message with a new dBuf
4911 Buffer *mBuf, /* message buffer */
4912 Buffer *dBuf, /* data buffer */
4916 PUBLIC S16 SUpdMsg(mBuf, dBuf, dLen)
4917 Buffer *mBuf; /* message buffer */
4918 Buffer *dBuf; /* data buffer */
4919 MsgLen dLen; /* data length */
4926 #if (ERRCLASS & ERRCLS_INT_PAR)
4929 SSLOGERROR(ERRCLS_INT_PAR, ESS159, ERRZERO, "SUpdMsg : Null Buffer");
4934 SSLOGERROR(ERRCLS_INT_PAR, ESS160, ERRZERO, "SUpdMsg : Null Buffer");
4939 SSLOGERROR(ERRCLS_INT_PAR, ESS161, ERRZERO, "SUpdMsg : Invalid length");
4942 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
4943 (dBuf->b_datap->db_type != SS_M_DATA))
4945 SSLOGERROR(ERRCLS_INT_PAR, ESS162, ERRZERO, "SUpdMsg : Incorrect buffer\
4951 /* get the message info of mBuf */
4952 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
4954 /* accept zero length data */
4956 /* buffer offset out of bounds */
4957 if ((dBuf->b_rptr + dLen) > dBuf->b_datap->db_lim)
4959 SSLOGERROR(ERRCLS_DEBUG, ESS163, ERRZERO, "SUpdMsg:Offset out of bounds");
4963 /* offset write ptr from read ptr by dLen */
4964 dBuf->b_wptr = dBuf->b_rptr + dLen;
4966 /* attach dBuf at the end of mBuf */
4968 minfo->endptr->b_cont = dBuf;
4970 mBuf->b_cont = dBuf;
4972 /* update SsMsgInfo */
4973 minfo->endptr = dBuf;
4984 * Desc: This function queues a data buffer to the
4985 * back of the specified message buffer .
4988 * RFAILED - failed, general (optional)
4990 * Notes: if queue is empty: buffer is placed in the queue.
4991 * queue length is incremented.
4993 * if queue is not empty: buffer is placed behind all
4994 * other buffers in queue. queue length is incremented.
5002 PUBLIC S16 SAddDBufPst
5004 Buffer *mBuf, /* message buffer */
5008 PUBLIC S16 SAddDBufPst(mBuf, dBuf)
5009 Buffer *mBuf; /* message buffer */
5010 Buffer *dBuf; /* data buffer */
5017 #if (ERRCLASS & ERRCLS_INT_PAR)
5018 /* check buffer queue */
5021 SSLOGERROR(ERRCLS_INT_PAR, ESS164, ERRZERO, "SAddDBufPst : Null Buffer");
5024 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
5025 (dBuf->b_datap->db_type != SS_M_DATA))
5027 SSLOGERROR(ERRCLS_INT_PAR, ESS165, ERRZERO, "SAddDBufPst : Incorrect\
5033 /* no data, return */
5034 if (dBuf->b_wptr == dBuf->b_rptr)
5037 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5039 /* attach dBuf at the end of mBuf */
5041 minfo->endptr->b_cont = dBuf;
5043 mBuf->b_cont = dBuf;
5045 /* update SsMsgInfo */
5046 minfo->endptr = dBuf;
5048 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
5057 * Desc: This function queues a data buffer to the
5058 * front of the specified message buffer.
5061 * RFAILED - failed, general (optional)
5063 * Notes: if buffer queue is empty: buffer is placed in the queue. queue
5064 * length is incremented.
5066 * if buffer queue is not empty: buffer is placed in front of all
5067 * other buffers in queue. queue length is incremented.
5075 PUBLIC S16 SAddDBufPre
5077 Buffer *mBuf, /* message buffer */
5081 PUBLIC S16 SAddDBufPre(mBuf, dBuf)
5082 Buffer *mBuf; /* message buffer */
5083 Buffer *dBuf; /* data buffer */
5091 #if (ERRCLASS & ERRCLS_INT_PAR)
5092 /* check buffer queue */
5095 SSLOGERROR(ERRCLS_INT_PAR, ESS166, ERRZERO, "SAddDBufPre : Null Buffer");
5098 if ((mBuf->b_datap->db_type != SS_M_PROTO) ||
5099 (dBuf->b_datap->db_type != SS_M_DATA))
5101 SSLOGERROR(ERRCLS_INT_PAR, ESS167, ERRZERO, "SAddDBufPre : Incorrect\
5107 /* no data, return */
5108 if (dBuf->b_wptr == dBuf->b_rptr)
5111 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5115 /* attach dBuf at the start of mBuf */
5116 mBuf->b_cont = dBuf;
5119 minfo->len += dBuf->b_wptr - dBuf->b_rptr;
5122 minfo->endptr = dBuf;
5131 * Desc: This function dequeues a data buffer from
5132 * the front of the specified message buffer.
5135 * ROKDNA - ok, data not available
5136 * RFAILED - failed, general (optional)
5138 * Notes: if queue is empty: pointer to buffer is set to null and
5139 * return is ok, data not available. queue length is unchanged.
5141 * if queue is not empty: pointer to buffer is set to first
5142 * buffer in queue, first buffer in queue is removed and
5143 * return is ok. queue length is decremented.
5151 PUBLIC S16 SRemDBufPre
5153 Buffer *mBuf, /* message buffer */
5157 PUBLIC S16 SRemDBufPre(mBuf, dBufPtr)
5158 Buffer *mBuf; /* message buffer */
5159 Buffer **dBufPtr; /* pointer to data buffer */
5166 #if (ERRCLASS & ERRCLS_INT_PAR)
5167 /* check buffer pointer */
5168 if (dBufPtr == NULLP)
5170 SSLOGERROR(ERRCLS_INT_PAR, ESS168, ERRZERO, "SRemDBufPre : Null Buffer");
5176 SSLOGERROR(ERRCLS_INT_PAR, ESS169, ERRZERO, "SRemDBufPre : Null Buffer");
5179 if (mBuf->b_datap->db_type != SS_M_PROTO)
5181 SSLOGERROR(ERRCLS_INT_PAR, ESS170, ERRZERO, "SRemDBufPre : Incorrect\
5187 /* no data blk, return */
5188 if ((*dBufPtr = mBuf->b_cont) == NULLP)
5192 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5194 mBuf->b_cont = (*dBufPtr)->b_cont;
5195 (*dBufPtr)->b_cont = NULLP;
5197 /* update SsMsgInfo */
5198 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
5199 minfo->endptr = NULLP;
5208 * Desc: This function dequeues a data or message buffer from the
5209 * back of the specified message buffer.
5212 * ROKDNA - ok, data not available
5213 * RFAILED - failed, general (optional)
5215 * Notes: if queue is empty: pointer to buffer is set to null and
5216 * return is ok, data not available. queue length is unchanged.
5218 * if queue is not empty: pointer to buffer is set to last
5219 * buffer in queue, last buffer in queue is removed and
5220 * return is ok. queue length is decremented.
5228 PUBLIC S16 SRemDBufPst
5230 Buffer *mBuf, /* message buffer */
5234 PUBLIC S16 SRemDBufPst(mBuf, dBufPtr)
5235 Buffer *mBuf; /* message buffer */
5236 Buffer **dBufPtr; /* pointer to data buffer */
5244 #if (ERRCLASS & ERRCLS_INT_PAR)
5245 /* check buffer pointer */
5248 SSLOGERROR(ERRCLS_INT_PAR, ESS171, ERRZERO, "SRemDBufPst : Null Buffer");
5254 SSLOGERROR(ERRCLS_INT_PAR, ESS172, ERRZERO, "SRemDBufPst : Null Buffer");
5257 if (mBuf->b_datap->db_type != SS_M_PROTO)
5259 SSLOGERROR(ERRCLS_INT_PAR, ESS173, ERRZERO, "SRemDBufPst : Incorrect\
5265 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5267 /* no data blk, return */
5268 if ((*dBufPtr = minfo->endptr) == NULLP)
5272 for (tmp = mBuf; tmp->b_cont != (*dBufPtr); )
5275 tmp->b_cont = NULLP;
5277 /* update SsMsgInfo */
5278 if (!(minfo->len -= (*dBufPtr)->b_wptr - (*dBufPtr)->b_rptr))
5279 minfo->endptr = NULLP;
5281 minfo->endptr = tmp;
5290 * Desc: Initialize next Data Buffer Id
5294 * Notes: Must be called prior to SGetNxtDBuf
5302 PUBLIC S16 SInitNxtDBuf
5307 PUBLIC S16 SInitNxtDBuf(mBuf)
5308 Buffer *mBuf; /* message buffer */
5315 #if (ERRCLASS & ERRCLS_INT_PAR)
5318 SSLOGERROR(ERRCLS_INT_PAR, ESS174, ERRZERO, "SInitNxtDBuf : Null Buffer");
5321 if (mBuf->b_datap->db_type != SS_M_PROTO)
5323 SSLOGERROR(ERRCLS_INT_PAR, ESS175, ERRZERO, "SInitNxtDBuf : Incorrect\
5329 minfo = (SsMsgInfo*) mBuf->b_rptr;
5331 /* set the next ptr of mBuf to point to the first SS_M_DATA blk */
5332 minfo->next = mBuf->b_cont;
5341 * Desc: Get next dBuf in message chain
5345 * Notes: Must be called after SInitNxtDBuf
5353 PUBLIC S16 SGetNxtDBuf
5355 Buffer *mBuf, /* message buffer */
5359 PUBLIC S16 SGetNxtDBuf(mBuf, dBuf)
5360 Buffer *mBuf; /* message buffer */
5361 Buffer **dBuf; /* data buffer return */
5368 #if (ERRCLASS & ERRCLS_INT_PAR)
5371 SSLOGERROR(ERRCLS_INT_PAR, ESS176, ERRZERO, "SGetNxtDBuf : Null Buffer");
5376 SSLOGERROR(ERRCLS_INT_PAR, ESS177, ERRZERO, "SGetNxtDBuf : Null Buffer");
5379 if (mBuf->b_datap->db_type != SS_M_PROTO)
5381 SSLOGERROR(ERRCLS_INT_PAR, ESS178, ERRZERO, "SGetNxtDBuf : Incorrect\
5387 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5389 /* if next ptr of mBuf is NULLP, return */
5390 if ((*dBuf = minfo->next) == NULLP)
5394 minfo->next = (*dBuf)->b_cont;
5403 * Desc: check if next data buffer exists.
5405 * Ret: ROK/ROKDNA/RFAILED
5407 * Notes: doesn't modify nxtDBuf
5414 PUBLIC S16 SChkNxtDBuf
5419 PUBLIC S16 SChkNxtDBuf(mBuf)
5420 Buffer *mBuf; /* message buffer */
5427 #if (ERRCLASS & ERRCLS_INT_PAR)
5430 SSLOGERROR(ERRCLS_INT_PAR, ESS179, ERRZERO, "SChkNxtDBuf : Null Buffer");
5433 if (mBuf->b_datap->db_type != SS_M_PROTO)
5435 SSLOGERROR(ERRCLS_INT_PAR, ESS180, ERRZERO, "SChkNxtDBuf : Incorrect\
5439 #endif /* ERRCLASS */
5441 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5443 /* if next is valid, return ROK */
5454 * Desc: Given a data buffer, return a pointer to the
5455 * data payload, and the length of the payload
5461 * Notes: This assumes an uninitialized dBuf
5469 PUBLIC S16 SGetDataRx
5471 Buffer *dBuf, /* data buffer */
5472 MsgLen pad, /* pad */
5473 Data **retDatPtr, /* return data pointer */
5477 PUBLIC S16 SGetDataRx(dBuf, pad, retDatPtr, retDatLen)
5478 Buffer *dBuf; /* data buffer */
5479 MsgLen pad; /* pad */
5480 Data **retDatPtr; /* return data pointer */
5481 MsgLen *retDatLen; /* return data length */
5486 #if (ERRCLASS & ERRCLS_INT_PAR)
5489 SSLOGERROR(ERRCLS_INT_PAR, ESS181, ERRZERO, "SGetDataRx : Null Buffer");
5492 if (!retDatLen || (pad < 0))
5494 SSLOGERROR(ERRCLS_INT_PAR, ESS182, ERRZERO, "SGetDataRx : Null Buffer");
5499 SSLOGERROR(ERRCLS_INT_PAR, ESS183, ERRZERO, "SGetDataRx : Null Buffer");
5502 if (dBuf->b_datap->db_type != SS_M_DATA)
5504 SSLOGERROR(ERRCLS_INT_PAR, ESS184, ERRZERO, "SGetDataRx : Incorrect\
5508 #endif /* ERRCLASS */
5510 if (dBuf->b_datap->db_ref > 1) /* cannot write to a shared buffer */
5512 #if (ERRCLASS & ERRCLS_DEBUG)
5513 SSLOGERROR(ERRCLS_DEBUG, ESS185, ERRZERO, "SGetDataRx : Reference\
5519 /* return the write ptr loc(with padding) if there is data to write to */
5520 if ((*retDatLen = (dBuf->b_datap->db_lim - dBuf->b_wptr - pad)) > 0)
5521 *retDatPtr = dBuf->b_wptr + pad;
5525 #if (ERRCLASS & ERRCLS_DEBUG)
5526 SSLOGERROR(ERRCLS_DEBUG, ESS186, ERRZERO, "SGetDataRx:No data available");
5538 * Desc: Given a data buffer, return a pointer to the
5539 * data payload, and the length of the payload
5545 * Notes: This assumes an initialized dBuf
5553 PUBLIC S16 SGetDataTx
5555 Buffer *dBuf, /* data buffer */
5556 Data **retDatPtr, /* return data pointer */
5557 MsgLen *retDatLen /* return data length */
5560 PUBLIC S16 SGetDataTx(dBuf, retDatPtr, retDatLen)
5561 Buffer *dBuf; /* data buffer */
5562 Data **retDatPtr; /* return data pointer */
5563 MsgLen *retDatLen; /* return data length */
5568 #if (ERRCLASS & ERRCLS_INT_PAR)
5569 /* ss021.103 - Modification to check parameters */
5572 SSLOGERROR(ERRCLS_INT_PAR, ESS187, ERRZERO, "SGetDataTx : Null Buffer");
5577 SSLOGERROR(ERRCLS_INT_PAR, ESS188, ERRZERO, "SGetDataTx : Null Buffer");
5578 *retDatPtr = (Data *)NULLP;
5583 SSLOGERROR(ERRCLS_INT_PAR, ESS189, ERRZERO, "SGetDataTx : Null Buffer");
5586 if (dBuf->b_datap->db_type != SS_M_DATA)
5588 SSLOGERROR(ERRCLS_INT_PAR, ESS190, ERRZERO, "SGetDataTx : Incorrect\
5590 *retDatPtr = (Data *)NULLP;
5593 #endif /* ERRCLASS */
5595 /* if there is data, return read ptr */
5596 if ((*retDatLen = dBuf->b_wptr - dBuf->b_rptr))
5597 *retDatPtr = dBuf->b_rptr;
5601 #if (ERRCLASS & ERRCLS_DEBUG)
5602 SSLOGERROR(ERRCLS_DEBUG, ESS191, ERRZERO, "SGetDataTx : Buffer empty");
5610 #ifndef SS_ENABLE_MACROS
5614 * Fun: SGetBufRegionPool
5616 * Desc: returns the region and pool of the message buffer
5618 * Ret: ROK on success
5627 PUBLIC S16 SGetBufRegionPool
5629 Buffer *mBuf, /* message buffer */
5630 Region *region, /* region */
5631 Pool *pool /* pool */
5634 PUBLIC S16 SGetBufRegionPool(mBuf, region, pool)
5635 Buffer *mBuf; /* message buffer */
5636 Region *region; /* region */
5637 Pool *pool; /* pool */
5640 SsMsgInfo *mInfo; /* message info pointer */
5642 TRC1(SGetBufRegionPool)
5644 #if (ERRCLASS & ERRCLS_INT_PAR)
5648 SSLOGERROR(ERRCLS_INT_PAR, ESS192, ERRZERO,
5649 "SGetBufRegionPool : Null Buffer");
5652 if ((region == NULLP) && (pool == NULLP))
5654 SSLOGERROR(ERRCLS_INT_PAR, ESS193, ERRZERO,
5655 "SGetBufRegionPool : Null region and pool pointers");
5658 if (mBuf->b_datap->db_type != SS_M_PROTO)
5660 SSLOGERROR(ERRCLS_INT_PAR, ESS194, ERRZERO,
5661 "SUpdMsg : Incorrect buffer type");
5664 #endif /* (ERRCLASS & ERRCLS_INT_PAR */
5666 /* get message info of mBuf */
5667 if ((mInfo = (SsMsgInfo *) mBuf->b_rptr) == NULLP)
5669 #if (ERRCLASS & ERRCLS_DEBUG)
5670 SSLOGERROR(ERRCLS_DEBUG, ESS195, ERRZERO,
5671 "SGetBufRegionPool : mBuf's control data is null");
5676 if (region != NULLP)
5677 *region = mInfo->region;
5679 *pool = mInfo->pool;
5682 } /* end of SGetBufRegionPool */
5684 #endif /* SS_ENABLE_MACROS */
5690 * Desc: This function is used to compress a message into
5691 * the minimum number of data buffers needed.
5694 * RFAILED - failed, general (optional)
5695 * ROUTRES - failed, out of resources (optional)
5705 PUBLIC S16 SCompressMsg
5710 PUBLIC S16 SCompressMsg(mBuf)
5711 Buffer *mBuf; /* message buffer */
5721 #ifdef T2K_MEM_LEAK_DBG
5722 char* file = __FILE__;
5723 U32 line = __LINE__;
5727 #if (ERRCLASS & ERRCLS_INT_PAR)
5730 SSLOGERROR(ERRCLS_INT_PAR, ESS196, ERRZERO, "SCompressMsg : Null Buffer");
5733 if (mBuf->b_datap->db_type != SS_M_PROTO)
5735 SSLOGERROR(ERRCLS_INT_PAR, ESS197, ERRZERO, "SCompressMsg : Incorrect\
5741 minfo = (SsMsgInfo*) (mBuf)->b_rptr;
5743 if ((tmp = mBuf->b_cont) == minfo->endptr)
5748 /* allocate a data buffer of size bytes*/
5749 if ((ret = ssGetDBufOfSize(minfo->region, minfo->len, &dBuf)) != ROK)
5751 SSLOGERROR(ERRCLS_DEBUG, ESS198, ERRZERO, "SAddMsgRef : ssGetDBufOfSize\
5755 dBuf->b_datap->db_type = SS_M_DATA;
5759 /* determine number of bytes to be copied */
5760 numBytes = tmp->b_wptr - tmp->b_rptr;
5764 /* ss002.13: addition */
5765 /* ss003.13: addition */
5766 SMemCpy( (Void *)dBuf->b_wptr, (Void *)tmp->b_rptr, (size_t)numBytes);
5768 dBuf->b_wptr += numBytes;
5769 tmp->b_rptr += numBytes;
5773 (Void) SPutDBuf(minfo->region, minfo->pool, tmp);
5776 /* update mBuf and SsMsgInfo */
5777 mBuf->b_cont = dBuf;
5778 minfo->endptr = dBuf;
5787 * Desc: This function prints the contents of a message. The
5788 * following information is printed: queue length,
5789 * message length, direction, hexadecimal and ASCII
5790 * (if appropriate) values of all bytes in the message.
5792 * This function should be used for debugging only.
5805 Buffer *mBuf, /* message buffer */
5806 S16 src, /* source id */
5807 S16 dst /* destination id */
5810 PUBLIC S16 SPrntMsg(mBuf, src, dst)
5811 Buffer *mBuf; /* message buffer */
5812 S16 src; /* source id */
5813 S16 dst; /* destination id */
5816 QLen qlen; /* queue length */
5817 MsgLen mlen; /* message length */
5821 /* ss038.103 : 102061 Changed to MsgLen from S16 */
5822 MsgLen i; /* counter */
5823 S16 j; /* counter */
5824 S16 k; /* counter */
5826 U8 tdata[16] = {0}; /* temporary data */
5827 S8 prntBuf[256]; /* print buffer */
5828 Buffer *tmp; /* buffer ptr */
5830 /* ss012.13: Addition */
5838 sprintf(prntBuf,"\nmsg: empty\n");
5840 SPrint( (S8*)"\n\n");
5844 for (qlen = 0, tmp = mBuf->b_cont; tmp; qlen++)
5846 mlen = ((SsMsgInfo*)(mBuf->b_rptr))->len;
5847 reg = ((SsMsgInfo*)(mBuf->b_rptr))->region;
5848 /*ss013.301: Fixed Warnings for 32/64 bit compilation*/
5849 sprintf(prntBuf,"\nmsg: qlen: %04d mlen: %04d %02d-->%02d region: %02d\n",
5850 (U16)qlen,(U16)mlen,src,dst,reg);
5852 #ifdef XEON_SPECIFIC_CHANGES
5853 printf("%s\n", prntBuf);
5855 SPrint((S8*) "dat: ");
5856 #ifdef XEON_SPECIFIC_CHANGES
5862 sprintf(prntBuf," empty\n");
5864 SPrint( (S8*)"\n\n");
5874 for( j = 0; j < 16; j++)
5880 sprintf( prntBuf,"%02x ",(U16) data);
5882 #ifdef XEON_SPECIFIC_CHANGES
5883 printf("%s\n", prntBuf);
5885 if (cptr == tmp->b_wptr)
5891 /* ss024.103 - Modification to fix bug */
5898 sprintf( prntBuf," ");
5900 #ifdef XEON_SPECIFIC_CHANGES
5901 printf("%s\n", prntBuf);
5905 for (k = 0; k < 16; k++)
5907 if( (i >= mlen) && (k>=(mlen%16)) && mlen%16 != 0)
5909 if (AIsAscii(tdata[k]))
5911 /* print character if printable */
5912 sprintf(prntBuf,"%c",tdata[k]);
5914 #ifdef XEON_SPECIFIC_CHANGES
5915 printf("%s\n", prntBuf);
5920 /* print . if non printable */
5922 #ifdef XEON_SPECIFIC_CHANGES
5927 sprintf(prntBuf,"\n ");
5929 #ifdef XEON_SPECIFIC_CHANGES
5930 printf("%s\n", prntBuf);
5935 } /* end of SPrntMsg */
5941 * Fun: SGetPstMsgMult
5943 * Desc: This function allocates consecutive bytes of data at the
5947 * RFAILED - failed, general (optional)
5948 * ROUTRES - failed, out of resources (optional)
5950 * Notes: if message is empty: message length is incremented.
5953 * if message is not empty: space is allocated in back of
5954 * all other data in message. message length is incremented.
5961 PUBLIC S16 SGetPstMsgMult
5963 MsgLen cnt, /* count */
5964 Buffer *mBuf /* message buffer */
5967 PUBLIC S16 SGetPstMsgMult(cnt, mBuf)
5968 MsgLen cnt; /* count */
5969 Buffer *mBuf; /* message buffer */
5978 TRC1(SGetPstMsgMult)
5980 #if ( ERRCLASS & ERRCLS_INT_PAR )
5981 /* check message buffer */
5991 if (mBuf->b_datap->db_type != SS_M_PROTO)
5996 /* get the message info */
5997 minfo = (SsMsgInfo *) (mBuf->b_rptr);
6002 if ((tmp = minfo->endptr) && (tmp->b_datap->db_ref == 1) &&
6003 ((avail = tmp->b_datap->db_lim - tmp->b_wptr)))
6005 numBytes = MIN(cnt, avail);
6008 minfo->len += numBytes;
6011 /* ss002.13 addition */
6012 /* ss003.13 addition */
6013 SMemSet( (Void *)tmp->b_wptr, (Data)'\0', (size_t)numBytes);
6015 tmp->b_wptr += numBytes;
6019 if (ssGetDBufOfSize(minfo->region, cnt, &newb) != ROK)
6021 /* ss027.103 - Modification to fix bug in SGetPstMsgMult */
6022 if ((avail) && (tmp))
6023 tmp->b_wptr = tmp->b_datap->db_lim - avail;
6024 minfo->len -= avail;
6031 /* ss002.13: addition */
6032 /* ss003.13: addition */
6033 SMemSet( (Void *)newb->b_wptr, (Data)'\0', (size_t)cnt);
6035 newb->b_wptr += cnt;
6041 mBuf->b_cont = newb;
6043 minfo->endptr = newb;
6052 * Desc: Check Message
6054 * Ret: ROK on success
6057 * Notes: Check that the first buffer in a message
6058 * contains at least two bytes. This check is required
6059 * by 68302/68360 processors to insure accurate fisu
6071 PUBLIC S16 SChkMsg(mBuf)
6080 #if ( ERRCLASS & ERRCLS_INT_PAR )
6081 /* check message buffer */
6086 if (mBuf->b_datap->db_type != SS_M_PROTO)
6091 /* get the message info */
6092 minfo = (SsMsgInfo *) (mBuf->b_rptr);
6097 /* get the first M_DATA blk*/
6100 if (((tmp->b_rptr + 2) <= tmp->b_wptr) || (SCompressMsg(mBuf) == ROK))
6108 * Fun: SAlignDBufEven
6110 * Desc: align data portion of a data buffer on an even
6115 * Notes: required for SS7 microcode on the 68302
6121 PUBLIC S16 SAlignDBufEven
6123 Buffer *dBuf /* data buffer */
6126 PUBLIC S16 SAlignDBufEven(dBuf)
6127 Buffer *dBuf; /* data buffer */
6133 TRC1(SAlignDBufEven)
6135 #if (ERRCLASS & ERRCLS_INT_PAR)
6138 SSLOGERROR(ERRCLS_INT_PAR, ESS199, ERRZERO, "SAlignDBufEven : Null\
6142 if (dBuf->b_datap->db_type != SS_M_DATA)
6144 SSLOGERROR(ERRCLS_INT_PAR, ESS200, ERRZERO, "SAlignDBufEven : Incorrect\
6151 /* ss008.13: addition */
6152 if (!((PTR)src % (PTR)2))
6155 if (dBuf->b_datap->db_ref > 1)
6158 len = dBuf->b_wptr - dBuf->b_rptr;
6160 if (dBuf->b_datap->db_base < dBuf->b_rptr)
6162 dBuf->b_wptr = --dBuf->b_rptr;
6164 *dBuf->b_wptr++ = *src++;
6167 if (dBuf->b_datap->db_lim > dBuf->b_wptr)
6169 src = dBuf->b_wptr - 1;
6170 dBuf->b_rptr = ++dBuf->b_wptr;
6172 *--dBuf->b_rptr = *src--;
6180 /* ss004.13: addition */
6185 * Desc: Align data portion of a data buffer on the specified
6186 * boundary. No restriction is imposed on the alignment.
6190 * Notes: required by drivers (68360, 860)
6196 PUBLIC S16 SAlignDBuf
6198 Buffer *dBuf, /* data buffer */
6199 U32 align /* alignemnt required */
6202 PUBLIC S16 SAlignDBuf(dBuf, align)
6203 Buffer *dBuf; /* data buffer */
6204 U32 align; /* alignemnt required */
6209 U32 upShift; /* no. of bytes to be shifted up */
6210 U32 downShift; /* no. of bytes to be shifted down */
6214 #if (ERRCLASS & ERRCLS_INT_PAR)
6217 SSLOGERROR(ERRCLS_INT_PAR, ESS201, ERRZERO, "SAlignDBuf: Null\
6221 if (dBuf->b_datap->db_type != SS_M_DATA)
6223 SSLOGERROR(ERRCLS_INT_PAR, ESS202, ERRZERO, "SAlignDBuf: Incorrect\
6230 /* ss008.13: addition */
6231 upShift = (PTR)src % (PTR)align; /* no. of bytes by which to shift up
6232 * the read and write pointers */
6237 if (dBuf->b_datap->db_ref > 1)
6240 downShift = align - upShift; /* no of bytes by which to shift down
6241 * the read and write pointers */
6242 len = dBuf->b_wptr - dBuf->b_rptr;
6244 if (dBuf->b_datap->db_base <= (dBuf->b_rptr - upShift))
6246 /* there is space to shift up the read and write pointers */
6248 dBuf->b_rptr -= upShift; /* align the read pointer */
6249 dBuf->b_wptr = dBuf->b_rptr;
6250 SMemCpy( (Void *) dBuf->b_wptr, (Void *) src, (size_t) len);
6251 dBuf->b_wptr = dBuf->b_wptr + len;
6255 if (dBuf->b_datap->db_lim > dBuf->b_wptr + downShift)
6257 src = dBuf->b_wptr - 1;
6258 dBuf->b_wptr = dBuf->b_wptr + downShift;
6259 dBuf->b_rptr = dBuf->b_wptr;
6261 *--dBuf->b_rptr = *src--;
6275 * Desc: Allocates a static buffer pool within the specified
6279 * RFAILED - failed, general (optional)
6281 * Notes: The new memory management scheme makes this function
6282 * meaningless. It merely sets the pool ID to zero and
6291 Region region, /* region ID */
6292 Size size, /* size */
6293 Pool *pool /* pointer to pool ID */
6296 PUBLIC S16 SGetSMem(region, size, pool)
6297 Region region; /* region ID */
6298 Size size; /* size */
6299 Pool *pool; /* pointer to pool ID */
6308 #if (ERRCLASS & ERRCLS_INT_PAR)
6309 /* validate region ID */
6310 if (region >= SS_MAX_REGS)
6312 SSLOGERROR(ERRCLS_INT_PAR, ESS203, region, "Invalid region");
6316 /* validate pointer to pool ID */
6319 SSLOGERROR(ERRCLS_INT_PAR, ESS204, region, "Null pointer");
6325 /* set the pool ID to zero and return success */
6337 * Desc: Deallocates a static buffer pool within the specified
6341 * RFAILED - failed, general (optional)
6343 * Notes: The new memory management scheme makes this function
6344 * meaningless. It does nothing.
6352 Region region, /* region ID */
6353 Pool pool /* pool ID */
6356 PUBLIC S16 SPutSMem(region, pool)
6357 Region region; /* region ID */
6358 Pool pool; /* pool ID */
6361 /* ss021.103 - Addition of return value */
6362 #if (ERRCLASS & ERRCLS_INT_PAR)
6369 #if (ERRCLASS & ERRCLS_INT_PAR)
6370 /* validate region ID */
6371 if (region >= SS_MAX_REGS)
6373 SSLOGERROR(ERRCLS_INT_PAR, ESS205, region, "Invalid region");
6377 /* validate pool ID */
6378 if (pool >= SS_MAX_POOLS_PER_REG)
6380 SSLOGERROR(ERRCLS_INT_PAR, ESS206, region, "Invalid pool");
6384 /* ss021.103 - Addition to check if region is registered */
6385 /* acquire one semaphore, to protect against deregistration */
6386 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
6390 #if (ERRCLASS & ERRCLS_DEBUG)
6391 SSLOGERROR(ERRCLS_DEBUG, ESS207, (ErrVal) ret,
6392 "Could not lock region table");
6399 #if (ERRCLASS & ERRCLS_INT_PAR)
6400 /* verify that this region is present */
6401 if (osCp.regionTbl[region].used == FALSE)
6403 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6405 #if (ERRCLASS & ERRCLS_DEBUG)
6406 SSLOGERROR(ERRCLS_DEBUG, ESS208, ERRZERO,
6407 "Could not release semaphore");
6412 SSLOGERROR(ERRCLS_INT_PAR, ESS209, region, "Region not registered");
6417 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6419 #if (ERRCLASS & ERRCLS_DEBUG)
6420 SSLOGERROR(ERRCLS_DEBUG, ESS210, ERRZERO,
6421 "Could not release semaphore");
6435 * Desc: Checks the available system resources (memory).
6438 * RFAILED - failed, general (optional)
6448 Region region, /* region ID */
6449 Pool pool, /* pool ID */
6450 Status *status /* pointer to status */
6453 PUBLIC S16 SChkRes(region, pool, status)
6454 Region region; /* region ID */
6455 Pool pool; /* pool ID */
6456 Status *status; /* pointer to status */
6466 #if (ERRCLASS & ERRCLS_INT_PAR)
6467 /* validate region ID */
6468 if (region >= SS_MAX_REGS)
6470 SSLOGERROR(ERRCLS_INT_PAR, ESS229, region, "Invalid region");
6474 /* validate pool ID */
6475 if (pool >= SS_MAX_POOLS_PER_REG)
6477 SSLOGERROR(ERRCLS_INT_PAR, ESS230, region, "Invalid pool");
6481 /* validate status pointer */
6482 if (status == NULLP)
6484 SSLOGERROR(ERRCLS_INT_PAR, ESS231, ERRZERO, "Null pointer");
6488 /* ss037.103 Removed the semaphore operation for performance enhancement */
6491 /* acquire one semaphore, to protect against deregistration */
6492 SS_ACQUIRE_SEMA(&osCp.regionTblSem, ret);
6496 #if (ERRCLASS & ERRCLS_DEBUG)
6497 SSLOGERROR(ERRCLS_DEBUG, ESS232, (ErrVal) ret,
6498 "Could not lock region table");
6505 #if (ERRCLASS & ERRCLS_INT_PAR)
6506 /* verify that this region is around */
6507 if (osCp.regionTbl[region].used == FALSE)
6510 /* ss006.13: addition */
6511 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6513 #if (ERRCLASS & ERRCLS_DEBUG)
6514 SSLOGERROR(ERRCLS_DEBUG, ESS233, ERRZERO,
6515 "Could not release semaphore");
6520 SSLOGERROR(ERRCLS_INT_PAR, ESS234, region, "Region not registered");
6524 /* verify that this is a valid pool */
6525 if (osCp.regionTbl[region].poolTbl[pool].type != SS_POOL_DYNAMIC)
6527 SSLOGERROR(ERRCLS_DEBUG, ESS235, ERRZERO, "Invalid pool");
6533 /* call the memory manager to check resources */
6534 mctl.op = SS_MEM_CHK_RES;
6535 mctl.u.chkres.size = osCp.regionTbl[region].poolTbl[pool].u.dpool.size;
6536 mctl.u.chkres.status = status;
6537 ret = (osCp.regionTbl[region].ctl)
6538 (osCp.regionTbl[region].regCb, SS_MEM_CHK_RES, &mctl);
6540 /* release the semaphore we took */
6542 /* ss006.13: addition */
6543 if( SS_RELEASE_SEMA(&osCp.regionTblSem) != ROK)
6545 #if (ERRCLASS & ERRCLS_DEBUG)
6546 SSLOGERROR(ERRCLS_DEBUG, ESS236, ERRZERO,
6547 "Could not release semaphore");
6560 * Desc: This function will swap two message data contents.
6561 * The original mBuf pointers are unchanged.
6576 Buffer *mBuf1, /* message 1 */
6577 Buffer *mBuf2 /* message 2 */
6580 PUBLIC S16 SSwapMsg(mBuf1, mBuf2)
6581 Buffer *mBuf1; /* message 1 */
6582 Buffer *mBuf2; /* message 2 */
6587 #if (ERRCLASS & ERRCLS_INT_PAR)
6596 #if (ERRCLASS & ERRCLS_INT_PAR)
6597 /* check message buffer 1 */
6600 SSLOGERROR(ERRCLS_INT_PAR, ESS237, ERRZERO, "SSwapMsg : Null Buffer");
6603 /* check message buffer 2 */
6606 SSLOGERROR(ERRCLS_INT_PAR, ESS238, ERRZERO, "SSwapMsg : Null Buffer");
6609 if (mBuf1->b_datap->db_type != SS_M_PROTO)
6611 SSLOGERROR(ERRCLS_INT_PAR, ESS239, ERRZERO, "SSwapMsg: Incorrect buffer\
6615 if (mBuf2->b_datap->db_type != SS_M_PROTO)
6617 SSLOGERROR(ERRCLS_INT_PAR, ESS240, ERRZERO, "SSwapMsg: Incorrect buffer\
6621 minfo1 = (SsMsgInfo*) mBuf1->b_rptr;
6622 minfo2 = (SsMsgInfo*) mBuf2->b_rptr;
6623 if (minfo1->region != minfo2->region)
6625 SSLOGERROR(ERRCLS_INT_PAR, ESS241, ERRZERO, "SSwapMsg: differnt regions\
6632 tmp = mBuf1->b_next;
6633 mBuf1->b_next = mBuf2->b_next;
6634 mBuf2->b_next = tmp;
6636 tmp = mBuf1->b_prev;
6637 mBuf1->b_prev = mBuf2->b_prev;
6638 mBuf2->b_prev = tmp;
6640 tmp = mBuf1->b_cont;
6641 mBuf1->b_cont = mBuf2->b_cont;
6642 mBuf2->b_cont = tmp;
6645 #ifdef SS_DBLK_FREE_RTN
6646 tmp = (Buffer *) mBuf1->b_datap->db_frtnp;
6647 mBuf1->b_datap->db_frtnp = mBuf2->b_datap->db_frtnp;
6648 mBuf2->b_datap->db_frtnp = (struct ssfree_rtn *) tmp;
6651 tmp2 = mBuf1->b_datap->db_ref;
6652 mBuf1->b_datap->db_ref = mBuf2->b_datap->db_ref;
6653 mBuf2->b_datap->db_ref = tmp2;
6658 SMemCpy((Void *) minfop, (Void *) (mBuf1->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6659 SMemCpy((Void *) (mBuf1->b_datap->db_base), (Void *) (mBuf2->b_datap->db_base), (size_t)(sizeof(SsMsgInfo)));
6660 SMemCpy((Void *) (mBuf2->b_datap->db_base), (Void *) minfop, (size_t)(sizeof(SsMsgInfo)));
6664 /* ss004.301 : Cavium changes */
6665 #ifdef SS_SEUM_CAVIUM
6671 * Desc: This function will converts the pointer to
6675 * RFAILED - failed, general (optional)
6677 * Notes: Function to convert the Pointer (Virtual address) to
6678 * Physical Address. This will take the Buffer type as
6679 * input and will convert all pointer associated with
6680 * that to Physical Address
6686 PUBLIC S16 SConvPtrPhy
6691 PUBLIC S16 SConvPtrPhy (mBuf)
6698 SsMsgInfo *minfoPtr;
6705 /* check mBuf for NULLP */
6706 if ( (mBuf == NULLP) || (*mBuf == NULLP ) )
6711 /* first block in Buffer is head */
6713 nextPtr = curPtr->b_cont;
6715 /* Get the physical address of the Pointer */
6718 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6723 curPtr->b_next = (Buffer*)cvmx_ptr_to_phys (curPtr->b_next);
6728 curPtr->b_prev = (Buffer*)cvmx_ptr_to_phys (curPtr->b_prev);
6731 /* Convert the pointers of Minfo to Physical addr */
6732 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6734 if (minfoPtr->endptr)
6736 minfoPtr->endptr = (Buffer*)cvmx_ptr_to_phys (minfoPtr->endptr);
6740 minfoPtr->next = (Buffer*)cvmx_ptr_to_phys (minfoPtr->next);
6743 curPtr->b_rptr = (U8*)cvmx_ptr_to_phys (curPtr->b_rptr);
6745 curPtr->b_wptr = (U8*)cvmx_ptr_to_phys (curPtr->b_wptr);
6747 /* Convert the pointers of Dblock to Physical addr */
6748 dblkPtr = (SsDblk*)curPtr->b_datap;
6751 #ifdef SS_DBLK_FREE_RTN
6752 frtnPtr = dblkPtr->db_frtnp;
6753 if( frtnPtr != NULLP)
6755 if (frtnPtr->free_func)
6757 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6759 if (frtnPtr->free_arg)
6761 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6764 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6768 dblkPtr->db_base = (U8*)cvmx_ptr_to_phys (dblkPtr->db_base);
6769 dblkPtr->db_lim = (U8*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6771 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6773 /* second block onwards is dblk */
6778 nextPtr = curPtr->b_cont;
6780 /* Get the physical address of the Pointer */
6783 curPtr->b_cont = (Buffer*)cvmx_ptr_to_phys (curPtr->b_cont);
6786 curPtr->b_rptr = (U8*)cvmx_ptr_to_phys (curPtr->b_rptr);
6787 curPtr->b_wptr = (U8*)cvmx_ptr_to_phys (curPtr->b_wptr);
6789 /* Convert the pointers of Dblock to Physical addr */
6790 dblkPtr = (SsDblk*)curPtr->b_datap;
6793 #ifdef SS_DBLK_FREE_RTN
6794 frtnPtr = dblkPtr->db_frtnp;
6795 if( frtnPtr != NULLP)
6797 if (frtnPtr->free_func)
6799 frtnPtr->free_func = (Void*)cvmx_ptr_to_phys (frtnPtr->free_func);
6801 if (frtnPtr->free_arg)
6803 frtnPtr->free_arg = (S8*)cvmx_ptr_to_phys (frtnPtr->free_arg);
6806 dblkPtr->db_frtnp = (SsFrtn*)cvmx_ptr_to_phys (dblkPtr->db_frtnp);
6810 dblkPtr->db_base = (U8*)cvmx_ptr_to_phys (dblkPtr->db_base);
6811 dblkPtr->db_lim = (U8*)cvmx_ptr_to_phys (dblkPtr->db_lim);
6813 curPtr->b_datap = (SsDblk*)cvmx_ptr_to_phys (curPtr->b_datap);
6819 *mBuf = (Buffer*)cvmx_ptr_to_phys (*mBuf);
6829 * Desc: This function will converts the physical address
6832 * Ret: On Success - Pointer to converted buffer
6833 * On Failuer - Returns NULL
6835 * Notes: Function to Convert the Physical address to Pointer
6836 * (Virtual address) This will take work buffer as input
6837 * and will convert all address associated with that to
6844 PUBLIC S16 SConvPhyPtr
6849 PUBLIC S16 SConvPhyPtr (workPtr)
6856 SsMsgInfo *minfoPtr;
6863 /* check workPtr for NULLP */
6864 if ( (workPtr == NULLP) || (*workPtr == NULLP) )
6869 /* Convert the buffer address to pointer */
6870 mBuf = (Buffer*)cvmx_phys_to_ptr ((U64)(*workPtr));
6874 /* first block is mblk */
6877 curPtr->b_next = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_next);
6882 curPtr->b_prev = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_prev);
6887 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_cont);
6890 curPtr->b_rptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_rptr);
6892 /* Get the pointer for minfo */
6893 minfoPtr = (SsMsgInfo*)curPtr->b_rptr;
6895 if (minfoPtr->endptr)
6897 minfoPtr->endptr = (Buffer*)cvmx_phys_to_ptr ((U64)minfoPtr->endptr);
6901 minfoPtr->next = (Buffer*)cvmx_phys_to_ptr ((U64)minfoPtr->next);
6904 curPtr->b_wptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_wptr);
6906 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((U64)curPtr->b_datap);
6908 /* Get the Dblock pointers */
6909 dblkPtr = (SsDblk*)curPtr->b_datap;
6912 #ifdef SS_DBLK_FREE_RTN
6913 if (dblkPtr->db_frtnp)
6915 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((U64)dblkPtr->db_frtnp);
6916 frtnPtr = dblkPtr->db_frtnp;
6918 if (frtnPtr->free_func)
6920 frtnPtr->free_func = cvmx_phys_to_ptr ((U64)frtnPtr->free_func);
6922 if (frtnPtr->free_arg)
6924 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((U64)frtnPtr->free_arg);
6929 dblkPtr->db_base = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_base);
6930 dblkPtr->db_lim = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_lim);
6932 curPtr = curPtr->b_cont;
6934 /* after the first block is dblk */
6939 curPtr->b_cont = (Buffer*)cvmx_phys_to_ptr ((U64)curPtr->b_cont);
6942 curPtr->b_rptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_rptr);
6944 curPtr->b_wptr = (U8*)cvmx_phys_to_ptr ((U64)curPtr->b_wptr);
6946 curPtr->b_datap = (SsDblk*)cvmx_phys_to_ptr ((U64)curPtr->b_datap);
6948 /* Get the Dblock pointers */
6949 dblkPtr = (SsDblk*)curPtr->b_datap;
6952 #ifdef SS_DBLK_FREE_RTN
6953 if (dblkPtr->db_frtnp)
6955 dblkPtr->db_frtnp = (SsFrtn*)cvmx_phys_to_ptr ((U64)dblkPtr->db_frtnp);
6957 frtnPtr = dblkPtr->db_frtnp;
6959 if (frtnPtr->free_func)
6961 frtnPtr->free_func = cvmx_phys_to_ptr ((U64)frtnPtr->free_func);
6963 if (frtnPtr->free_arg)
6965 frtnPtr->free_arg = (S8*)cvmx_phys_to_ptr ((U64)frtnPtr->free_arg);
6970 dblkPtr->db_base = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_base);
6971 dblkPtr->db_lim = (U8*)cvmx_phys_to_ptr ((U64)dblkPtr->db_lim);
6973 curPtr = curPtr->b_cont;
6976 /* Place the converted buffer */
6987 * Desc: This function will copy the message from FPA region
6990 * Ret: On Success - ROK
6991 * On Failuer - RFAILED
6993 * Notes: Function to copy the message from FPA region to
6994 * other region. This will internally allocates the
6995 * memory for the destination buffer and copies the
6996 * message in the same chain list
7002 PUBLIC S16 SCpyFpaMsg
7010 PUBLIC S16 SCpyFpaMsg (srcBuf, dstRegion, dstPool, dstBuf)
7021 Buffer *curPtr = NULLP;
7023 Buffer *tmpblk = NULLP;
7024 Buffer *newblk = NULLP;
7025 Buffer *prevblk = NULLP;
7026 SsMsgInfo *minfoSrc = NULLP;
7027 SsMsgInfo *minfoDst = NULLP;
7028 SsDblk *dblkPtr = NULLP;
7029 SsDblk *dptr = NULLP;
7034 if ( srcBuf == (Buffer*)NULLP )
7039 if ((dstRegion >= SS_MAX_REGS) || (dstPool >= SS_MAX_POOLS_PER_REG))
7041 /* Free the source buffer and return failure */
7046 /* Allocate memory for destination buffer */
7047 if(SGetMsg(dstRegion, dstPool, dstBuf) != ROK)
7049 /* Free the source buffer and return failure */
7054 /* get the minfo of dest and src buffers */
7055 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
7056 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
7058 curPtr = srcBuf->b_cont;
7060 /* Copy all the blocks associated with this Buffer */
7063 /* Allocate the memeory for dblock */
7065 dblkPtr = (SsDblk*)curPtr->b_datap;
7066 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
7067 size = numBytes + MDBSIZE;
7069 ret = SAlloc( dstRegion, &size, 0, (Data**)&tmpblk);
7073 /* Free all allocated buffers before returning */
7076 tmpblk = newblk->b_cont;
7077 (Void) SPutDBuf(dstRegion, dstPool, newblk);
7080 (Void) SPutMsg(*dstBuf);
7081 /* Free the source buffer and return failure */
7086 dat = (Data *)tmpblk + MDBSIZE;
7087 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
7090 /* Initialize the pointer and copy the data */
7091 INITB( tmpblk, dptr, dat, size, NULLP );
7092 #ifndef SS_DBUF_REFLOCK_DISABLE
7093 SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX);
7095 numBytes = curPtr->b_wptr - curPtr->b_rptr;
7096 /* Copy the data part if its present */
7099 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
7100 tmpblk->b_wptr += numBytes;
7109 prevblk->b_cont = tmpblk;
7113 curPtr = curPtr->b_cont;
7118 tmpblk->b_cont = NULLP;
7121 *minfoDst = *minfoSrc;
7122 minfoDst->region = 0;
7124 minfoDst->len = minfoSrc->len;
7125 minfoDst->endptr = tmpblk;
7126 minfoDst->next = NULLP;
7128 (*dstBuf)->b_cont = newblk;
7130 /* Free the source buffer after copying it */
7141 * Desc: This function will copy the message from any region
7144 * Ret: On Success - ROK
7145 * On Failuer - RFAILED
7147 * Notes: Function will copy the mbuf from msg to FPA.
7148 * This function allocates the memory internally
7149 * and copies the message to newly allocated mBuf.
7150 * The size of mBuf should be either of one
7151 * pre-difined sizes otherwise mBuf is dopped.
7157 PUBLIC S16 SCpyMsgFpa
7163 PUBLIC S16 SCpyMsgFpa (srcBuf, dstBuf)
7169 Buffer *curPtr = NULLP;
7171 Buffer *tmpblk = NULLP;
7172 Buffer *prevblk = NULLP;
7173 Buffer *newblk = NULLP;
7174 SsMsgInfo *minfoSrc = NULLP;
7175 SsMsgInfo *minfoDst = NULLP;
7176 SsDblk *dblkPtr = NULLP;
7177 SsDblk *dptr = NULLP;
7184 if (srcBuf == (Buffer*)NULLP)
7189 *dstBuf = (Buffer*)cvmx_fpa_alloc(SS_CVMX_POOL_0);
7191 if ( *dstBuf == NULLP )
7193 /* Free the source buffer before returning */
7198 dat = (Data *)(*dstBuf) + MDBSIZE;
7199 dptr = (SsDblk*) ((Data *)(*dstBuf) + MBSIZE);
7200 numBytes = SS_CVMX_POOL_0_SIZE - MDBSIZE;
7202 /* Initialize the pointers of new block */
7203 INITB((*dstBuf), dptr, dat, numBytes, NULLP);
7205 (*dstBuf)->b_datap->db_type = SS_M_PROTO;
7206 (*dstBuf)->b_wptr = (*dstBuf)->b_rptr + sizeof(SsMsgInfo);
7208 minfoSrc = (SsMsgInfo*) srcBuf->b_rptr;
7209 minfoDst = (SsMsgInfo*) (*dstBuf)->b_rptr;
7210 curPtr = srcBuf->b_cont;
7214 dblkPtr = (SsDblk*)curPtr->b_datap;
7216 /* Get the size required which is to be allocated */
7217 numBytes = dblkPtr->db_lim - dblkPtr->db_base;
7218 numBytes += MDBSIZE;
7220 /* get the pool depending on the size need to be allocated */
7223 case SS_CVMX_POOL_0_SIZE:
7225 pool = SS_CVMX_POOL_0;
7228 case SS_CVMX_POOL_1_SIZE:
7230 pool = SS_CVMX_POOL_1;
7233 case SS_CVMX_POOL_2_SIZE:
7235 pool = SS_CVMX_POOL_2;
7238 case SS_CVMX_POOL_3_SIZE:
7240 pool = SS_CVMX_POOL_3;
7244 /* size doesn't match, drop the mBuf and returning
7246 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SCpyMsgFpa: Invalid\
7247 buffer size, dropping the message");
7249 (*dstBuf)->b_cont = newblk;
7250 SPutFpaMsg(*dstBuf);
7251 /* Free the source buffer before returning */
7256 /* Allocate for mBuf and copy both the header and contents */
7257 tmpblk = (Buffer*)cvmx_fpa_alloc(pool);
7259 if ( tmpblk == NULLP )
7261 /* Return error if fails to allocate memory */
7263 (*dstBuf)->b_cont = newblk;
7264 SPutFpaMsg(*dstBuf);
7265 /* Free the source buffer before returning */
7270 dat = (Data *)tmpblk + MDBSIZE;
7271 dptr = (SsDblk*) (((Data *) tmpblk) + MBSIZE);
7272 numBytes -= MDBSIZE;
7274 /* Initialize the pointers of new block */
7275 INITB( tmpblk, dptr, dat, numBytes, NULLP );
7277 numBytes = curPtr->b_wptr - curPtr->b_rptr;
7278 /* Copy the message contents */
7281 SMemCpy( (Void *) tmpblk->b_wptr, (Void *) curPtr->b_rptr, numBytes);
7282 tmpblk->b_wptr += numBytes;
7285 /* Add the mew mBuf to the Buffer chain */
7292 prevblk->b_cont = tmpblk;
7296 /* Get the next block */
7297 curPtr = curPtr->b_cont;
7300 /* Initialize the last mBuf */
7303 tmpblk->b_cont = NULLP;
7306 *minfoDst = *minfoSrc;
7307 minfoDst->region = 0;
7309 minfoDst->len = minfoSrc->len;
7310 minfoDst->endptr = tmpblk;
7311 minfoDst->next = NULLP;
7313 (*dstBuf)->b_cont = newblk;
7315 /* Free the source buffer after copying it */
7326 * Desc: This function will free the Buffer associated with
7329 * Ret: On Success - ROK
7330 * On Failuer - RFAILED
7332 * Notes: Function free the all buffer associated with wqBuf
7333 * This will get the pool id by the size of the buffer
7334 * and same will be used to free the buffer.
7340 PUBLIC S16 SPutFpaMsg
7345 PUBLIC S16 SPutFpaMsg(fpaBuf)
7356 if( fpaBuf == NULLP )
7361 curBlk = fpaBuf->b_cont;
7365 nextBlk = curBlk->b_cont;
7367 dblkPtr = (SsDblk*)curBlk->b_datap;
7369 size = dblkPtr->db_lim - dblkPtr->db_base + MDBSIZE;
7371 /* Free the dblock according to its size */
7374 case SS_CVMX_POOL_0_SIZE:
7375 cvmx_fpa_free(curBlk, SS_CVMX_POOL_0, 0);
7378 case SS_CVMX_POOL_1_SIZE:
7379 cvmx_fpa_free(curBlk, SS_CVMX_POOL_1, 0);
7382 case SS_CVMX_POOL_2_SIZE:
7383 cvmx_fpa_free(curBlk, SS_CVMX_POOL_2, 0);
7386 case SS_CVMX_POOL_3_SIZE:
7387 cvmx_fpa_free(curBlk, SS_CVMX_POOL_3, 0);
7391 SSLOGERROR(ERRCLS_INT_PAR, ESS048, ERRZERO, "SPutFpaMsg: Invalid\
7392 buffer size, dropping the message");
7399 cvmx_fpa_free(fpaBuf, SS_CVMX_POOL_0, 0);
7405 #endif /* SS_SEUM_CAVIUM */
7407 /* ss006.301 : new buffer management APIs, start */
7412 * Desc: This function is used to copy a portion of message(srcBuf) into
7413 * another msg(dstBuf)
7416 * RFAILED - failed, general (optional)
7417 * ROUTRES - failed, out of resources (optional) - In this case
7418 * caller shall reclaim the resources allocated for dstBuf.
7427 PUBLIC S16 SCpyPartMsg
7435 PUBLIC S16 SCpyPartMsg(srcBuf, idx, cnt, dstBuf)
7453 #if (ERRCLASS & ERRCLS_INT_PAR)
7456 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null src Buffer");
7459 if (srcBuf->b_datap->db_type != SS_M_PROTO)
7461 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7467 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Null dst Buffer");
7470 if (dstBuf->b_datap->db_type != SS_M_PROTO)
7472 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7476 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
7478 /* if index > length of mBuf, return */
7479 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
7480 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
7482 if (idx >= sMinfo->len)
7484 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SCpyPartMsg : Incorrect\
7489 sBuf = srcBuf->b_cont;
7490 FIND_OFFSET(sBuf, idx)
7494 dBuf = (dMinfo->endptr) ? (dMinfo->endptr) : (dstBuf->b_cont);
7498 crnt = dPrev->b_cont;
7502 crnt = crnt->b_cont;
7509 sCnt = sBuf->b_wptr - (sBuf->b_rptr + idx);
7512 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
7516 /* allocate a data buffer */
7517 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
7519 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyPartMsg : SGetDBuf\
7523 dCnt = MIN(cnt, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
7524 dPrev->b_cont = dBuf;
7527 if(sCnt > cnt) /* src Dblk has enough data to copy */
7531 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7533 dBuf->b_wptr += dCnt;
7534 dBuf = dBuf->b_cont;
7540 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), cnt);
7541 dBuf->b_wptr += cnt;
7542 dBuf->b_cont = NULLP;
7548 else /* src dBlk has partial data to be copied */
7552 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), dCnt);
7553 dBuf->b_wptr += dCnt;
7554 dBuf = dBuf->b_cont;
7561 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr + idx), sCnt);
7562 dBuf->b_wptr += sCnt;
7564 sBuf = sBuf->b_cont;
7570 /* update the msgLen in dstBuf */
7571 dMinfo->len += numCpd;
7572 dMinfo->endptr = dBuf;
7581 * Desc: This function is used to replace a portion of message(mBuf) with the
7585 * RFAILED - failed, general (optional)
7594 PUBLIC S16 SRepPartMsg
7602 PUBLIC S16 SRepPartMsg(srcBuf, idx, cnt, dstBuf)
7620 #if (ERRCLASS & ERRCLS_INT_PAR)
7623 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null dstBuf");
7626 if (dstBuf->b_datap->db_type != SS_M_PROTO)
7628 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7629 dstBuf buffer type");
7634 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Null Src Buffer ");
7637 if (srcBuf->b_datap->db_type != SS_M_PROTO)
7639 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7643 #endif /* (ERRCLASS & ERRCLS_INT_PAR) */
7645 dMinfo = (SsMsgInfo*)dstBuf->b_rptr;
7646 sMinfo = (SsMsgInfo*)srcBuf->b_rptr;
7648 if(((idx + cnt) > dMinfo->len) || (cnt < sMinfo->len))
7650 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : Incorrect\
7655 dBuf = dstBuf->b_cont;
7656 FIND_OFFSET(dBuf, idx)
7657 sBuf = srcBuf->b_cont;
7659 while(cnt && dBuf && sBuf)
7661 dCnt = (dBuf->b_wptr - (dBuf->b_rptr + idx));
7662 sCnt = sBuf->b_wptr - (sBuf->b_rptr + sIdx);
7663 cpBytes = MIN(cnt, sCnt);
7664 cpBytes = MIN(cpBytes, dCnt);
7665 SMemCpy((void*)(dBuf->b_rptr + idx), (void*)(sBuf->b_rptr + sIdx), cpBytes);
7671 /* move to next DBlk in srcBuf */
7672 sBuf = sBuf->b_cont;
7676 else /* cpBytes equals dCnt */
7678 /* move to the next DBlk in dstBuf */
7679 dBuf = dBuf->b_cont;
7693 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SRepPartMsg : unable to replace\
7705 * Desc: This function will move a portion of the first msg to second msg
7708 * ROKDNA - ok, data not available
7709 * RFAILED - failed, general (optional)
7710 * ROUTRES - failed, out of resources (optional)
7712 * Notes: message 1 is the message from which the segment will be copied
7714 * message 2 is the updated message.
7716 * index is 0 based and indicates location in message 1
7717 * up to which the data will be copied to message 2
7719 * if index is equal to 0, message 1 will not be changed and no data
7720 shall be copied to message 2.
7721 * message 1 is not returned to memory. return is ok.
7723 * if index is not equal to 0 and less than the length of
7724 * the message minus 1: data upto index, shall be copied to message 2
7725 * and read/write pointers of message 1 will be updated accordingly
7727 * if index is not equal to 0 and greater than or equal to
7728 * the length of the message minus 1: all of the message 1 data.
7729 * shall be copied to message 2. return is ok.
7737 PUBLIC S16 SMovPartMsg
7739 Buffer *srcBuf, /* message 1 */
7740 MsgLen idx, /* index */
7741 Buffer *dstBuf /* message 2 */
7744 PUBLIC S16 SMovPartMsg(srcBuf, idx, dstBuf)
7745 Buffer *srcBuf; /* message 1 */
7746 MsgLen idx; /* index */
7747 Buffer *dstBuf; /* message 2 */
7757 #ifdef T2K_MEM_LEAK_DBG
7758 char* file = __FILE__;
7759 U32 line = __LINE__;
7764 #if (ERRCLASS & ERRCLS_INT_PAR)
7765 /* check message buffer 1 */
7766 if ((!srcBuf) || (!dstBuf ))
7768 SSLOGERROR(ERRCLS_INT_PAR, ESS097, ERRZERO, "SMovPartMsg : Null Buffer (src or Dst)");
7773 SSLOGERROR(ERRCLS_INT_PAR, ESS099, ERRZERO, "SMovPartMsg : Invalid index");
7776 if ((srcBuf->b_datap->db_type != SS_M_PROTO) || (dstBuf->b_datap->db_type != SS_M_PROTO))
7778 SSLOGERROR(ERRCLS_INT_PAR, ESS100, ERRZERO, "SMovPartMsg : Incorrect buffer\
7784 /* get the SsMsgInfo of srcBuf */
7785 sMinfo = (SsMsgInfo*) srcBuf->b_rptr;
7787 /* get the SsMsgInfo of dstBuf */
7788 dMinfo = (SsMsgInfo*) dstBuf->b_rptr;
7790 /* if index > length of mBuf, return */
7792 if (idx > sMinfo->len)
7797 /* one block might not sufficient - Check for generic implementation */
7798 sBuf = srcBuf->b_cont;
7799 /* dBuf = dMinfo->endptr; */
7800 dPrev = (dBuf = dMinfo->endptr) ? dBuf : dstBuf;
7802 /* adjust the lengths of srcBuf, dstBuf */
7808 sCnt = sBuf->b_wptr - sBuf->b_rptr;
7811 /* allocate a data buffer */
7812 if (SGetDBuf(dMinfo->region, dMinfo->pool, &dBuf) != ROK)
7814 SSLOGERROR(ERRCLS_DEBUG, ESS125, ERRZERO, "SCpyMsgPartMsg : SGetDBuf\
7818 dCnt = MIN(idx, (dBuf->b_datap->db_lim - dBuf->b_datap->db_base));
7819 dPrev->b_cont = dBuf;
7824 dCnt = dBuf->b_datap->db_lim - dBuf->b_wptr;
7826 if(sCnt > idx) /* src Dblk has enough data to copy */
7830 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7831 dBuf->b_wptr += dCnt;
7832 dBuf = dBuf->b_cont;
7834 sBuf->b_rptr += dCnt;
7838 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), idx);
7839 dBuf->b_wptr += idx;
7840 dBuf->b_cont = NULLP;
7841 sBuf->b_rptr += idx;
7846 else /* src dBlk has partial data to be copied */
7850 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), dCnt);
7851 dBuf->b_wptr += dCnt;
7852 dBuf = dBuf->b_cont;
7854 sBuf->b_rptr += dCnt;
7859 SMemCpy((void*)dBuf->b_wptr, (void*)(sBuf->b_rptr), sCnt);
7860 dBuf->b_wptr += sCnt;
7862 /* deallocate the sBuf here */
7864 /* printf("SMovPartMsg() sBuf is completely copied sBuf->b_cont(%p)\n", sBuf->b_cont); */
7865 (Void)SPutDBuf(sMinfo->region, sMinfo->pool, sBuf);
7866 srcBuf->b_cont = sBuf = tmp;
7870 dMinfo->endptr = dBuf;
7875 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SMovPartMsg : unable to copy\
7887 * Desc: This function copies consecutive bytes of data to the
7888 * beginning of a message.
7891 * RFAILED - failed, general (optional)
7892 * ROUTRES - failed, out of resources (optional)
7894 * Notes: if message is empty: data is placed in the message. message
7895 * length is incremented. return is ok.
7897 * if message is not empty: data is read by source pointer,
7898 * data is placed in front of all other data in message.
7899 * message length is incremented. return is ok.
7901 * the first byte of data pointed to by the source pointer
7902 * will be placed at the front of the message first (i.e. it
7903 * will become the first byte of the message) and the last
7904 * byte will be placed in front of the existing msg contents,
7905 * i.e. order of the source is preserved.
7912 PUBLIC S16 SPkMsgMult
7919 PUBLIC S16 SPkMsgMult(src, cnt, mBuf)
7925 SsMsgInfo *minfo; /* Message info */
7928 MsgLen numBytes; /* no. of bytes to be copied */
7933 #if (ERRCLASS & ERRCLS_INT_PAR)
7934 /* check message buffer */
7937 SSLOGERROR(ERRCLS_INT_PAR, ESS070, ERRZERO, "SPkMsgMult:Null Buffer");
7943 SSLOGERROR(ERRCLS_INT_PAR, ESS071, ERRZERO, "SPkMsgMult:Null Buffer");
7949 SSLOGERROR(ERRCLS_INT_PAR, ESS072, ERRZERO, "SPkMsgMult: Invalid\
7953 if (mBuf->b_datap->db_type != SS_M_PROTO)
7955 SSLOGERROR(ERRCLS_INT_PAR, ESS073, ERRZERO, "SPkMsgMult: Incorrect\
7961 /* get the SsMsgInfo of mBuf */
7962 minfo = (SsMsgInfo*) mBuf->b_rptr;
7964 /* ss014.13: Addition */
7967 if ((tmp = mBuf->b_cont) && (tmp->b_datap->db_ref == 1) &&
7968 (tmp->b_datap->db_base < tmp->b_rptr))
7970 /* store the offset of the read pointer of tmp */
7971 offset = tmp->b_rptr - tmp->b_datap->db_base;
7973 /* determine the number of bytes to copy */
7974 numBytes = MIN(cnt, offset);
7979 /* update the read ptr */
7980 tmp->b_rptr -= numBytes;
7982 memcpy((U8*)tmp->b_rptr, (src + cnt), numBytes);
7983 minfo->len += numBytes;
7990 /* allocate a DBlk minimum of size Cnt to pack the data */
7992 if (ssGetDBufOfSize(minfo->region, cnt, &newblk) != ROK)
7996 newblk->b_datap->db_type = SS_M_DATA;
7997 newblk->b_rptr = newblk->b_datap->db_lim - cnt;
7998 newblk->b_wptr = newblk->b_datap->db_lim;
7999 memcpy((U8*)newblk->b_rptr, src, cnt);
8000 /* attach the newblk chain into mBuf */
8001 newblk->b_cont = tmp;
8002 mBuf->b_cont = newblk;
8004 minfo->endptr = newblk;
8008 /* ss006.301 : new buffer management APIs, end */
8013 * Desc: This function retunrs the pointer to the read the message from mBuf
8016 * RFAILED - failed, general (optional)
8024 PUBLIC S16 SGetReadPtr
8031 PUBLIC S16 SGetReadPtr (mBuf, data, len)
8039 if (mBuf && mBuf->b_cont)
8041 *data = mBuf->b_cont->b_rptr;
8042 *len = ((SsMsgInfo*)(mBuf->b_rptr))->len;
8052 #ifdef SS_USE_ZBC_MEMORY
8055 * Fun: SAttachPtrToBuf
8057 * Desc: This function attaches the Pointer provided into a new
8058 * message buffer after allocating the same. It allocates
8059 * header (M-Block) and an additional dBuf (D-Block) and attaches
8060 * the provided pointer to it.
8063 * RFAILED - failed, general (optional)
8064 * ROUTRES - failed, out of resources (optional)
8072 #ifdef T2K_MEM_LEAK_DBG
8073 PUBLIC S16 SAttachPtrToBufNew
8085 PUBLIC S16 SAttachPtrToBuf
8094 PUBLIC S16 SAttachPtrToBuf(region, pool, ptr, totalLen, mBuf)
8103 SsMsgInfo *minfo; /* Message info */
8107 /* Void *iccHdlr; */
8109 TRC1(SAttachPtrToBuf)
8111 #if (ERRCLASS & ERRCLS_INT_PAR)
8114 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8119 #ifdef XEON_SPECIFIC_CHANGES
8122 if(SGetMsg(region, pool, mBuf) != ROK)
8124 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8130 #ifdef SS_HISTOGRAM_SUPPORT
8131 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
8133 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8134 #endif /* SS_HISTOGRAM_SUPPORT */
8136 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8141 (*mBuf)->b_cont = newblk;
8143 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8145 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8148 newblk->b_datap->db_base = ptr;
8149 newblk->b_datap->db_lim = ptr + totalLen;
8150 newblk->b_rptr = newblk->b_datap->db_base;
8151 newblk->b_wptr = newblk->b_rptr + totalLen;
8153 #ifndef SS_DBUF_REFLOCK_DISABLE
8154 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8156 printf("Falied to destroy lock\n");
8160 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8162 /* get the SsMsgInfo of mBuf */
8163 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8164 minfo->len = totalLen;
8165 minfo->endptr = newblk;
8174 * Desc: This function deallocates a buffer back to the
8175 * dynamic memory pool which is allocated for ZBC
8178 * RFAILED - failed, general (optional)
8186 #ifdef T2K_MEM_LEAK_DBG
8187 PRIVATE S16 SPutZbcDBufNew
8196 PRIVATE S16 SPutZbcDBuf
8202 PRIVATE S16 SPutZbcDBuf(region, buf)
8208 register SsDblk *dptr;
8214 dptr = buf->b_datap;
8215 /* Get the length of the buffer */
8216 bufLen = buf->b_datap->db_lim - buf->b_datap->db_base;
8218 /* If the buffer is not shared, free the buffer */
8221 #ifndef SS_DBUF_REFLOCK_DISABLE
8222 SDestroyLock(&dptr->dBufLock);
8225 /* Free the ZBC buffer first and then free the block allocated for the
8228 #ifdef SS_HISTOGRAM_SUPPORT
8229 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
8230 (U8*) __FILE__, ENTNC);
8232 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
8233 #endif /* SS_HISTOGRAM_SUPPORT */
8235 /* if the data block is not shared, free the buffer, checks not reqd */
8236 #ifdef SS_HISTOGRAM_SUPPORT
8237 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__,
8240 ret = SFree(region, (Data *) buf, MDBSIZE);
8241 #endif /* SS_HISTOGRAM_SUPPORT */
8243 /* If the buffer is shared, reduce the refernce count and free the buffer
8244 * if reference count falls to zero */
8247 #ifndef SS_DBUF_REFLOCK_DISABLE
8248 if((ret=SLock(&dptr->dBufLock)))
8250 SSLOGERROR(ERRCLS_DEBUG, ESSXXX, ERRZERO,
8251 "Could not lock the mBuf Ref Lock");
8256 /* if buffer's message blk is obtained during dupb */
8257 if (buf != (SsMblk *) (((Data*) dptr) - MBSIZE))
8259 #ifdef SS_HISTOGRAM_SUPPORT
8260 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__, ENTNC);
8262 ret = SFree(region, (Data *) buf, MDBSIZE);
8263 #endif /* SS_HISTOGRAM_SUPPORT */
8264 buf = (SsMblk *) (((Data*) dptr) - MBSIZE);
8266 /* if reference count falls to zero */
8269 #ifndef SS_DBUF_REFLOCK_DISABLE
8270 ret = SUnlock(&dptr->dBufLock) ;
8271 if((SDestroyLock(&dptr->dBufLock)) != 0)
8273 printf("Falied to destroy lock\n");
8276 #ifdef SS_HISTOGRAM_SUPPORT
8277 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen, __LINE__,
8278 (U8*) __FILE__, ENTNC);
8280 ret = SFree(region, (Data *) buf->b_datap->db_base, bufLen);
8281 #endif /* SS_HISTOGRAM_SUPPORT */
8283 #ifdef SS_HISTOGRAM_SUPPORT
8284 ret = SFree(region, (Data *) buf, MDBSIZE, __LINE__, (U8*) __FILE__,
8287 ret = SFree(region, (Data *) buf, MDBSIZE);
8288 #endif /* SS_HISTOGRAM_SUPPORT */
8291 #ifndef SS_DBUF_REFLOCK_DISABLE
8292 ret = SUnlock(&(dptr->dBufLock));
8298 #endif /* SS_USE_ZBC_MEMORY */
8304 * Fun: SAttachPtrToMBuf
8306 * Desc: This function attaches the Pointer provided into a new
8307 * message buffer after allocating the same. It allocates
8308 * header (M-Block) and an additional dBuf (D-Block) and attaches
8309 * the provided pointer to it.
8312 * RFAILED - failed, general (optional)
8313 * ROUTRES - failed, out of resources (optional)
8320 #ifdef T2K_MEM_LEAK_DBG
8321 PUBLIC S16 SAttachPtrToMBuf1
8334 PUBLIC S16 SAttachPtrToMBuf
8344 PUBLIC S16 SAttachPtrToMBuf(region, pool, ptr, totalLen, ptrLen, mBuf)
8354 SsMsgInfo *minfo; /* Message info */
8358 /* Void *iccHdlr; */
8360 TRC1(SAttachPtrToMBuf)
8362 #if (ERRCLASS & ERRCLS_INT_PAR)
8365 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8370 if(SGetMsg(region, pool, mBuf) != ROK)
8372 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8379 #ifdef SS_HISTOGRAM_SUPPORT
8380 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
8382 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8383 #endif /* SS_HISTOGRAM_SUPPORT */
8385 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8390 (*mBuf)->b_cont = newblk;
8392 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8394 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8397 newblk->b_datap->db_base = ptr;
8398 newblk->b_datap->db_lim = ptr + ptrLen;
8399 newblk->b_rptr = newblk->b_datap->db_base;
8400 newblk->b_wptr = newblk->b_rptr + totalLen;
8402 #ifndef SS_DBUF_REFLOCK_DISABLE
8403 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8405 printf("Falied to destroy lock\n");
8409 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8411 /* get the SsMsgInfo of mBuf */
8412 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8413 minfo->len = totalLen;
8414 minfo->endptr = newblk;
8416 //printf("Mbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
8419 #endif /* INTEL_WLS */
8420 PUBLIC S16 SIncMsgRef(Buffer *srcBuf,Region dstRegion, Pool dstPool,Buffer **dstBuf)
8423 RETVALUE(SAddMsgRef(srcBuf,dstRegion, dstPool,dstBuf));
8430 PUBLIC Void SResetMBuf(Buffer *mbuf)
8436 minfo = (SsMsgInfo *) mbuf->b_rptr;
8437 //tmp = minfo->endptr;
8444 // 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 );
8445 // tmp->b_wptr = tmp->b_rptr = tmp->b_datap->db_base;
8446 tmp->b_wptr = tmp->b_rptr = (tmp->b_datap->db_base + 5);
8447 tmp->b_datap->db_ref = 1;
8448 tmp->b_datap->shared = 0;
8460 * Fun: SAttachWlsPtrToMBuf
8462 * Desc: This function attaches the Pointer provided into a new
8463 * message buffer after allocating the same. It allocates
8464 * header (M-Block) and an additional dBuf (D-Block) and attaches
8465 * the provided pointer to it.
8468 * RFAILED - failed, general (optional)
8469 * ROUTRES - failed, out of resources (optional)
8476 #ifdef T2K_MEM_LEAK_DBG
8477 PUBLIC S16 SAttachWlsPtrToMBuf1
8491 PUBLIC S16 SAttachWlsPtrToMBuf
8502 PUBLIC S16 SAttachWlsPtrToMBuf(region, pool, ptr, readPtr, totalLen, ptrLen, mBuf)
8513 SsMsgInfo *minfo; /* Message info */
8517 /* Void *iccHdlr; */
8519 TRC1(SAttachWlsPtrToMBuf)
8521 #if (ERRCLASS & ERRCLS_INT_PAR)
8524 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: Null PTR");
8530 if(SGetMsg(region, pool, mBuf) != ROK)
8532 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SGetMsg Failed");
8538 #ifdef SS_HISTOGRAM_SUPPORT
8539 if (SAlloc(region, &mdsize, 0, (Data **) &newblk, __LINE__, (U8*) __FILE__, ENTNC) != ROK)
8541 if (SAlloc(region, &mdsize, 0, (Data **) &newblk) != ROK)
8542 #endif /* SS_HISTOGRAM_SUPPORT */
8544 SSLOGERROR(ERRCLS_INT_PAR, ESSXXX, ERRZERO, "SAttachPtrToBuf: SAlloc Failed");
8549 (*mBuf)->b_cont = newblk;
8551 dptr = (SsDblk*) (((Data *) (newblk)) + MBSIZE);
8553 INITB((newblk), dptr, (Data*) NULL, 0, NULLP)
8556 newblk->b_datap->db_base = ptr;
8557 newblk->b_datap->db_lim = ptr + ptrLen;
8558 newblk->b_rptr = readPtr;
8559 newblk->b_wptr = newblk->b_rptr + totalLen;
8561 #ifndef SS_DBUF_REFLOCK_DISABLE
8562 if((SInitLock (&(dptr->dBufLock), SS_LOCK_MUTEX)) != 0)
8564 printf("Falied to destroy lock\n");
8568 dptr->db_type = SS_MEM_TYPE_SSI_ZBC;
8570 /* get the SsMsgInfo of mBuf */
8571 minfo = (SsMsgInfo*) (*mBuf)->b_rptr;
8572 minfo->len = totalLen;
8573 minfo->endptr = newblk;
8575 //printf("Mbuf PTR = %x, DBlk PTR = %x, PTR = %x\n", *mBuf, newblk, ptr);
8579 #ifdef TENB_DPDK_BUF
8583 PUBLIC S16 SGetSBufDpdk
8585 Data **ptr, /* pointer to buffer */
8586 Size size /* size requested */
8591 *ptr = ntl_alloc(mtGetNtlHdl(), size);
8596 PUBLIC S16 SPutSBufDpdk
8598 Data *ptr /* pointer to buffer */
8604 ntl_free(mtGetNtlHdl(), ptr);
8609 PUBLIC S16 SDetachDpdkPtrFrmDBuf
8619 //msgBlk = mBuf->b_cont;
8620 //*ptr = msgBlk->b_rptr;;
8621 *ptr = mBuf->b_datap->db_base;;
8623 mBuf->b_cont = NULL;
8625 //minfo = (SsMsgInfo*) mBuf->b_rptr;
8633 PUBLIC S16 SDetachDpdkPtrFrmMBuf
8642 register SsDblk *dptr;
8646 msgBlk = mBuf->b_cont;
8653 dptr = msgBlk->b_datap;
8654 if(dptr->db_type != SS_MEM_TYPE_DPDK_ZBC)
8660 *ptr = msgBlk->b_rptr;;
8662 mBuf->b_cont = NULL;
8664 minfo = (SsMsgInfo*) mBuf->b_rptr;
8672 PUBLIC S16 SAttachDpdkPtrToMBuf
8683 PUBLIC S16 SAttachDpdkPtrToMBuf(region, pool, ptr, readPtr, msgLen, totalLen, mBuf)
8699 SAttachWlsPtrToMBuf(region, pool, ptr, readPtr, msgLen, totalLen, mBuf);
8700 dptr = (SsDblk*) (((Data *) ((*mBuf)->b_cont)) + MBSIZE);
8702 dptr->db_type = SS_MEM_TYPE_DPDK_ZBC;
8707 #endif /* TENB_DPDK_BUF */
8709 #endif /* INTEL_WLS */
8711 /**********************************************************************
8713 **********************************************************************/