openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

bcm_utils.h (3702B)


      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  * File:       bcm_utils.h
      8  */
      9  
     10 #ifndef _BCM_UTILS_H_
     11 #define _BCM_UTILS_H_
     12 
     13 #include <stdio.h>
     14 #include "types.h"
     15 
     16 
     17 #define SAL_USECS_SUB(_t2, _t1)        (((int) ((_t2) - (_t1))))
     18 #define SAL_USECS_ADD(_t, _us)        ((_t) + (_us))
     19 
     20 typedef uint32 sal_usecs_t;
     21 typedef int     soc_module_t;
     22 
     23 typedef struct soc_timeout_s {
     24     sal_usecs_t		expire;
     25     sal_usecs_t		usec;
     26     int			    min_polls;
     27     int			    polls;
     28     sal_usecs_t		exp_delay;
     29 } soc_timeout_t;
     30 
     31 #define NUM_MODULES     4
     32 /* We use 4 phy device ids.                                           */
     33 /* PHY0_DEV_ID specifies the first phy id in a sequential series of 4 */
     34 /* eg: 0, 1, 2, 3                                                     */
     35 #define PHY0_DEV_ID      0
     36 #define PHY_DEVAD        1
     37 
     38 /* Data Structures */
     39 typedef struct phy_ctrl_s {
     40     int                 unit;               /* BCM unit number */
     41     soc_module_t        module;             /* BCM module number */
     42     uint16              phy_id;             /* phy dev ID */
     43     uint8               phy_devad;          /* phy device addr */
     44     int                 flags;              /* PHY flags for internal use */
     45     soc_timeout_t       to;                 /* timer for multi pass initialization */
     46     uint8               *firmware;          /* firmware pointer */
     47     int                 firmware_len;       /* firmware length in bytes */
     48     int                 dl_dividend;        /* divident for MDC during firmware download */
     49     int                 dl_divisor;         /* divisor for MDC during firmware download */
     50     int                 tsc_sys_port;       /* used to identify tsc system port */
     51     int                 lane_mask;          /* specify port lane */
     52 } phy_ctrl_t; 
     53 
     54 extern phy_ctrl_t phyctrl[];
     55 #define EXT_PHY_SW_STATE(unit, module)  (&phyctrl[module])
     56 
     57 extern int bcm_mdio_read(int unit, phy_ctrl_t *pc, uint16 phy_reg_addr, uint16 *val);
     58 extern int bcm_mdio_write(int unit, phy_ctrl_t *pc, uint16 phy_reg_addr, uint16 val);
     59 extern int bcm_mdio_modify(int unit, phy_ctrl_t *pc, uint16 phy_reg_addr, uint16 val, uint16 mask);
     60 
     61 #define READ_PHY_REG(_unit, _pc,  _addr, _value) \
     62             (bcm_mdio_read((_unit), (_pc), (_addr), (_value)))
     63 #define WRITE_PHY_REG(_unit, _pc, _addr, _value) \
     64             (bcm_mdio_write((_unit), (_pc), (_addr), (_value)))
     65 #define MODIFY_PHY_REG(_unit, _pc, _addr, _value, _mask) \
     66             (bcm_mdio_modify((_unit), (_pc), (_addr), (_value), (_mask)))
     67 
     68 extern void
     69 bcm_timeout_init(soc_timeout_t *to, uint32 usec, int min_polls);
     70 extern int
     71 bcm_timeout_check(soc_timeout_t *to);
     72 void
     73 bcm_udelay(int usec);
     74 
     75 extern void *
     76 bcm_memcpy(void *dst_void, const void *src_void, uint32 len);
     77 extern void *
     78 bcm_memset(void *dst_void, int val, size_t len);
     79 
     80 #define do_nothing(fmt, args...) {}
     81 
     82 /* Any layer log macros */
     83 #define BCM_LOG_ERR printf
     84 #define BCM_LOG_WARN printf
     85 #define BCM_LOG_CLI printf
     86 #define BCM_LOG_DEBUG do_nothing
     87 
     88 #define sal_mutex_FOREVER	(-1)
     89 #define sal_mutex_NOWAIT	0
     90 typedef struct sal_sem_s{
     91     char sal_opaque_type;
     92 } *sal_sem_t;
     93 
     94 typedef struct sal_mutex_s{
     95     char mutex_opaque_type;
     96 } *sal_mutex_t;
     97 
     98 /*
     99  * bcm_mutex_t
    100  */
    101 typedef struct bcm_mutex_s {
    102     sal_sem_t       sem;
    103     char            *desc;
    104 } bcm_mutex_t;
    105 
    106 extern sal_mutex_t sbus_lock;
    107 extern sal_mutex_t bcm_mutex_create(char *desc);
    108 extern void bcm_mutex_destroy(sal_mutex_t m);
    109 extern int bcm_mutex_take(sal_mutex_t m, int usec);
    110 extern int bcm_mutex_give(sal_mutex_t m);
    111 #endif /* _BCM_UTILS_H_ */