util.h (4276B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * Driver utility routines 8 */ 9 10 #ifndef _SOC_UTIL_H 11 #define _SOC_UTIL_H 12 13 #include <sal/core/time.h> 14 #include <shared/util.h> 15 /* 16 * Timeout support based on SAL microsecond timer 17 */ 18 #define SOC_TIGHTLOOP_DELAY_LIMIT_USECS 10 19 20 typedef struct soc_timeout_s { 21 sal_usecs_t expire; 22 sal_usecs_t usec; 23 int min_polls; 24 int polls; 25 sal_usecs_t exp_delay; 26 } soc_timeout_t; 27 28 extern void soc_timeout_init(soc_timeout_t *to, uint32 usec, int min_polls); 29 extern int soc_timeout_check(soc_timeout_t *to); 30 extern sal_usecs_t soc_timeout_elapsed(soc_timeout_t *to); 31 extern int soc_tightdelay_timeout_check(soc_timeout_t *to); 32 33 extern void soc_bits_get(uint32 *str, uint32 minbit, uint32 maxbit, void *data_vp); 34 35 #if defined(BCM_ESW_SUPPORT) || defined(BCM_SIRIUS_SUPPORT) || defined(BCM_SAND_SUPPORT) || defined(BCM_CALADAN3_SUPPORT) 36 extern int _soc_max_blocks_per_entry_get(void); 37 #endif 38 39 /* 40 * The following load/store routines interpret 2 or 4 arbitrarily 41 * aligned bytes, usually in a packet buffer and representing a value in 42 * network-endian byte order, as unsigned integer values. 43 */ 44 45 extern uint32 soc_ntohl_load(const void *); 46 extern uint16 soc_ntohs_load(const void *); 47 extern uint32 soc_htonl_store(void *, uint32); 48 extern uint16 soc_htons_store(void *, uint16); 49 50 extern uint32 soc_letohl_load(const void *a); 51 extern uint16 soc_letohs_load(const void *a); 52 extern uint32 soc_htolel_store(void *a, uint32 v); 53 extern uint16 soc_htoles_store(void *a, uint16 v); 54 55 /* General operations for shift & mask for flags */ 56 /* mask is always justified to low order bits; 2^n - 1 where n is width. */ 57 #define SOC_SM_FLAGS_GET(flags, shift, mask) (((flags) >> (shift)) & (mask)) 58 #define SOC_SM_FLAGS_SET(flags, val, shift, mask) \ 59 do { \ 60 ((flags) &= (~((uint32)((mask) << (shift))))); \ 61 ((flags) |= (((val)&(mask)) << (shift))); \ 62 } while (0) 63 64 /* 65 * Macro: 66 * soc_htonl (soc_htons) 67 * Purpose: 68 * Convert host-endian 32-bit value (16-bit value) to big-endian. 69 * Notes: 70 * Only swaps if endian conversion is required for current host type. 71 * 72 * Macro: 73 * soc_ntohl (soc_ntohs) 74 * Purpose: 75 * Convert big-endian 32-bit value (16-bit value) to host-endian. 76 * Notes: 77 * Only swaps if endian conversion is required for current host type. 78 */ 79 80 #if defined(LE_HOST) 81 82 #define soc_htonl(_l) _shr_swap32(_l) 83 #define soc_htons(_s) _shr_swap16(_s) 84 #define soc_ntohl(_l) _shr_swap32(_l) 85 #define soc_ntohs(_s) _shr_swap16(_s) 86 87 #else /* BE_HOST */ 88 89 #define soc_htonl(_l) (_l) 90 #define soc_htons(_s) (_s) 91 #define soc_ntohl(_l) (_l) 92 #define soc_ntohs(_s) (_s) 93 94 #endif /* BE_HOST */ 95 96 /* 97 * Macro: 98 * soc_letohl (soc_letohs) 99 * Purpose: 100 * Convert little-endian 32-bit value (16-bit value) to host-endian. 101 * Notes: 102 * Only swaps if endian conversion is required for current host type. 103 */ 104 105 #if defined(LE_HOST) 106 107 #define soc_letohl(_l) (_l) 108 #define soc_letohs(_s) (_s) 109 110 #else /* BE_HOST */ 111 112 #define soc_letohl(_l) _shr_swap32(_l) 113 #define soc_letohs(_s) _shr_swap16(_s) 114 115 #endif /* BE_HOST */ 116 117 118 #define MAX_DEV_NAME_LEN 25 119 #define MAX_FW_TYPES 8 120 #define NO_FW ((uint8 *) -1) 121 #define MAX_FW_BUF_LEN 0x80000 122 123 typedef struct fw_desc_s { 124 const char *dev_name; 125 uint8 *fw; 126 int fw_len; 127 } fw_desc_t; 128 129 typedef struct misc_desc_s { 130 const char *dev_name; 131 void *arg; 132 } misc_desc_t; 133 134 extern void soc_phy_fw_init(void); 135 extern void soc_phy_misc_init(void); 136 extern int soc_phy_fw_get(char *dev_name, uint8 **fw, int *fw_len); 137 extern void soc_phy_fw_put_all(void); 138 139 extern int (*soc_phy_fw_acquire)(const char *dev_name, uint8 **fw, int *fw_len); 140 extern int (*soc_phy_fw_release)(const char *dev_name, uint8 *fw, int fw_len); 141 142 extern void soc_format_uint64(char *buf, uint64 n); 143 extern uint64 soc_parse_uint64(char *str); 144 extern uint32 soc_parse_integer(char *str); 145 146 extern int soc_phy_misc(const char *dev_name, void *arg); 147 extern int (*soc_phy_misc_launch)(const char *dev_name, void *arg); 148 149 #endif /* !_SOC_UTIL_H */