1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2009-2012 Emulex. All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 
  28 
  29 /*
  30  * Driver Utility  function prototypes
  31  */
  32 
  33 #ifndef _OCE_UTILS_H_
  34 #define _OCE_UTILS_H_
  35 
  36 #ifdef __cplusplus
  37 extern "C" {
  38 #endif
  39 
  40 #include <sys/types.h>
  41 #include <sys/list.h>
  42 
  43 /* logging macro */
  44 #define MOD_CONFIG      0x0001
  45 #define MOD_TX          0x0002
  46 #define MOD_RX          0x0004
  47 #define MOD_ISR         0x0008
  48 
  49 #define OCE_DEFAULT_LOG_SETTINGS        (CE_WARN        |       \
  50         ((MOD_CONFIG | MOD_TX | MOD_RX) << 16UL))
  51 
  52 #define OCE_MAX_LOG_SETTINGS            (CE_IGNORE | ((MOD_CONFIG | MOD_TX | \
  53         MOD_RX | MOD_ISR) << 16UL))
  54 
  55 #define oce_log(dev_p, level, module, fmt, arg...) {    \
  56         if (dev_p) {                                    \
  57                 if ((dev_p->mod_mask & module) &&        \
  58                     (dev_p->severity < CE_IGNORE) &&      \
  59                     ((uint32_t)level >= dev_p->severity))         \
  60                         cmn_err(level, "%s[%d]: " fmt, OCE_MOD_NAME,    \
  61                             dev_p->dev_id, ## arg);                  \
  62         } else {                                                        \
  63                 cmn_err(level, "%s[%d]: " fmt, OCE_MOD_NAME,            \
  64                     0, ## arg);                                         \
  65         }                                                               \
  66 }
  67 
  68 
  69 /* Time related */
  70 #define OCE_USDELAY(x) drv_usecwait((x))
  71 #define OCE_MSDELAY(x) OCE_USDELAY((x) * 1000)
  72 
  73 /* Misc Macros */
  74 #define OCE_LOG2(x) (highbit((x)) - 1)
  75 #define ADDR_LO(addr) (uint32_t)BMASK_32(addr) /* low 32 bits */
  76 #define ADDR_HI(addr) (uint32_t)BMASK_32((addr >> 32)) /* high 32 bits */
  77 #define ADDR_64(_HI, _LO) ((uint64_t)(((uint64_t)(_HI) << 32)|(_LO)))
  78 #define voidptr(x)      (void *)((x))
  79 #define u32ptr(x)       (uint32_t *)voidptr((x))
  80 #define ptrtou32(x)     (uint32_t)((uint32_t *)(void *)(x))
  81 
  82 #define PAGE_4K         (0x1UL << 12)
  83 #define OFFSET_IN_4K_PAGE(addr) ((off_t)((uint64_t)addr & (PAGE_4K - 1)))
  84 #define OCE_NUM_PAGES(size) howmany(size, PAGE_4K)
  85 
  86 
  87 /* Utility Functions */
  88 
  89 #define OCE_DW_SWAP(datap, length)      {                       \
  90         int len;                                        \
  91         uint32_t *wptr = (uint32_t *)(datap);                 \
  92         len = (length) + (((length)  %4) ? (4  - (4 %(length))) : 0); \
  93         for (len = len/4; len > 0; len--) {          \
  94                 *wptr = LE_32(*wptr);                   \
  95                 wptr++;                     \
  96         }                                                               \
  97 }
  98 
  99 
 100 #ifdef _BIG_ENDIAN
 101 #define DW_SWAP(_PTR, _LEN) OCE_DW_SWAP(_PTR, _LEN)
 102 #else
 103 #define DW_SWAP(_PTR, _LEN)
 104 #endif
 105 
 106 /* externs for  list manipulation functions */
 107 
 108 int oce_atomic_reserve(uint32_t *count_p, uint32_t n);
 109 
 110 void oce_gen_hkey(char *hkey, int key_size);
 111 void oce_insert_vtag(mblk_t *mp, uint16_t vlan_tag);
 112 void oce_remove_vtag(mblk_t *mp);
 113 
 114 #ifdef __cplusplus
 115 }
 116 #endif
 117 
 118 #endif /* _OCE_UTILS_H_ */