smmisc.c revision 285809
1/*******************************************************************************
2*Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3*
4*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5*that the following conditions are met:
6*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7*following disclaimer.
8*2. Redistributions in binary form must reproduce the above copyright notice,
9*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10*with the distribution.
11*
12*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20
21********************************************************************************/
22#include <sys/cdefs.h>
23__FBSDID("$FreeBSD$");
24#include <dev/pms/config.h>
25
26#include <dev/pms/freebsd/driver/common/osenv.h>
27#include <dev/pms/freebsd/driver/common/ostypes.h>
28#include <dev/pms/freebsd/driver/common/osdebug.h>
29
30#include <dev/pms/RefTisa/tisa/api/titypes.h>
31
32#include <dev/pms/RefTisa/sallsdk/api/sa.h>
33#include <dev/pms/RefTisa/sallsdk/api/saapi.h>
34#include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
35
36#include <dev/pms/RefTisa/sat/api/sm.h>
37#include <dev/pms/RefTisa/sat/api/smapi.h>
38#include <dev/pms/RefTisa/sat/api/tdsmapi.h>
39
40#include <dev/pms/RefTisa/sat/src/smdefs.h>
41#include <dev/pms/RefTisa/sat/src/smproto.h>
42#include <dev/pms/RefTisa/sat/src/smtypes.h>
43
44FORCEINLINE void*
45sm_memset(void *s, int c, bit32 n)
46{
47/*  bit32   i;
48
49  char *dst = (char *)s;
50  for (i=0; i < n; i++)
51  {
52    dst[i] = (char) c;
53  }
54  return (void *)(&dst[i-n]);
55*/
56  return memset(s, c, n);
57}
58
59FORCEINLINE void*
60sm_memcpy(void *dst, const void *src, bit32 count)
61{
62/*
63  bit32 x;
64  unsigned char *dst1 = (unsigned char *)dst;
65  unsigned char *src1 = (unsigned char *)src;
66
67  for (x=0; x < count; x++)
68    dst1[x] = src1[x];
69
70  return dst;
71*/
72  return memcpy(dst, src, count);
73}
74
75osGLOBAL char
76*sm_strncpy(char *dst, const char *src, bit32 len)
77{
78/*  char *ret = dst;
79    do {
80        if (!len--)
81            return ret;
82    } while ((*dst++ = *src++));
83    while (len--)
84        *dst++ = 0;
85    return ret;
86*/ return strncpy(dst, src, len);
87}
88
89/** hexidecimal dump */
90osGLOBAL void
91smhexdump(const char *ptitle, bit8 *pbuf, size_t len)
92{
93  size_t i;
94  SM_DBG1(("%s - smhexdump(len=%d):\n", ptitle, (int)len));
95  if (!pbuf)
96  {
97    SM_DBG1(("pbuf is NULL\n"));
98    return;
99  }
100  for (i = 0; i < len; )
101  {
102    if (len - i > 4)
103    {
104      SM_DBG1((" 0x%02x, 0x%02x, 0x%02x, 0x%02x,\n", pbuf[i], pbuf[i+1], pbuf[i+2], pbuf[i+3]));
105      i += 4;
106    }
107    else
108    {
109      SM_DBG1((" 0x%02x,", pbuf[i]));
110      i++;
111    }
112  }
113  SM_DBG1(("\n"));
114}
115
116
117