04b9ce8e32
Manual verification on switch (TH3 device) admin@str2-xxxxx-01:~$ bcmcmd bsv bsv BRCM SAI ver: [6.0.0.10], OCP SAI ver: [1.9.1], SDK ver: [sdk-6.5.23] drivshell> admin@str2-xxxxx-01:~$ bcmcmd version version Broadcom Command Monitor: Copyright (c) 1998-2021 Broadcom Release: sdk-6.5.23 built 20211020 (Wed Oct 20 06:52:58 2021) From root@fedbbfdbee81:/__w/2/s/output/x86-xgsall-deb/hsdk Platform: X86 OS: Unix (Posix) Chips: BCM56640_A0, BCM56850_A0, BCM56340_A0, BCM56960_A0, BCM56860_A0, BCM56970_A0, BCM56870_A0, BCM56980_A0, BCM56980_B0, BCM56370_A0, BCM56275_A0, BCM56770_A0, Chips: BCM56780_A0, BCM56782_A0, BCM56784_A0, BCM56785_A0, BCM56786_A0, BCM56787_A0, BCM56788_A0, BCM56789_A0, BCM56880_A0, BCM56880_B0, BCM56881_A0, BCM56881_B0, BCM56883_A0, BCM56883_B0, BCM56990_A0, BCM56990_B0, BCM56991_B0, BCM56992_B0, BCM56996_A0, BCM56996_B0, BCM56997_A0, BCM56997_B0 Variant drivers: BCM56780_A0_CNA_1_2_10, BCM56780_A0_DNA_2_7_6_0, BCM56880_A0_CNA_1_2_9, BCM56880_A0_DNA_4_9_5_0 PHYs: BCM5400, BCM54182, BCM54185, BCM54180, BCM54140, BCM54192, BCM54195, BCM54190, BCM54194, BCM54210, BCM54220, BCM54280, BCM54282, BCM54240, BCM54285, BCM5428X, BCM54290, BCM54292, BCM54294, BCM54295, BCM54296, BCM56160-GPHY, BCM53540-GPHY, BCM56275-GPHY, BCM8750, BCM8752, BCM8754, BCM84740, BCM84164, BCM84758, BCM84780, BCM84784, BCM84318, BCM84328, Sesto, BCM82780, copper sfp drivshell>
174 lines
3.2 KiB
C
174 lines
3.2 KiB
C
/*! \file ngknet_linux.c
|
|
*
|
|
* Utility routines for Linux kernel APIs abstraction.
|
|
*
|
|
*/
|
|
/*
|
|
* $Copyright: Copyright 2018-2021 Broadcom. All rights reserved.
|
|
* The term 'Broadcom' refers to Broadcom Inc. and/or its subsidiaries.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* version 2 as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* A copy of the GNU General Public License version 2 (GPLv2) can
|
|
* be found in the LICENSES folder.$
|
|
*/
|
|
|
|
#include <linux/kconfig.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/string.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/unistd.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/kthread.h>
|
|
#include <linux/semaphore.h>
|
|
#include <linux/spinlock.h>
|
|
|
|
#include "ngknet_linux.h"
|
|
|
|
/*!
|
|
* Time
|
|
*/
|
|
|
|
unsigned long
|
|
sal_time_usecs(void)
|
|
{
|
|
struct timeval tv;
|
|
|
|
kal_time_val_get(&tv);
|
|
|
|
return tv.tv_sec * 1000000 + tv.tv_usec;
|
|
}
|
|
|
|
void
|
|
sal_usleep(unsigned long usec)
|
|
{
|
|
unsigned long then, now, hz;
|
|
|
|
hz = usec * HZ / 1000000;
|
|
if (hz) {
|
|
schedule_timeout(hz);
|
|
}
|
|
usec = usec * HZ % 1000000 / HZ;
|
|
if (usec) {
|
|
then = sal_time_usecs();
|
|
do {
|
|
schedule();
|
|
now = sal_time_usecs();
|
|
} while (now > then && (now - then) < usec);
|
|
}
|
|
}
|
|
|
|
/*!
|
|
* Synchronization
|
|
*/
|
|
|
|
typedef struct {
|
|
struct semaphore sem;
|
|
char *desc;
|
|
int binary;
|
|
} sem_ctrl_t;
|
|
|
|
sal_sem_t
|
|
sal_sem_create(char *desc, int binary, int count)
|
|
{
|
|
sem_ctrl_t *sc = kmalloc(sizeof(*sc), GFP_KERNEL);
|
|
|
|
if (sc != NULL) {
|
|
sema_init(&sc->sem, count);
|
|
sc->desc = desc;
|
|
sc->binary = binary;
|
|
}
|
|
|
|
return (sal_sem_t)sc;
|
|
}
|
|
|
|
void
|
|
sal_sem_destroy(sal_sem_t sem)
|
|
{
|
|
sem_ctrl_t *sc = (sem_ctrl_t *)sem;
|
|
|
|
kfree(sc);
|
|
}
|
|
|
|
int
|
|
sal_sem_take(sal_sem_t sem, int usec)
|
|
{
|
|
sem_ctrl_t *sc = (sem_ctrl_t *)sem;
|
|
int rv;
|
|
|
|
if (usec == SAL_SEM_FOREVER) {
|
|
do {
|
|
rv = down_interruptible(&sc->sem);
|
|
} while (rv == -EINTR);
|
|
return rv ? -1 : 0;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
int
|
|
sal_sem_give(sal_sem_t sem)
|
|
{
|
|
sem_ctrl_t *sc = (sem_ctrl_t *)sem;
|
|
|
|
up(&sc->sem);
|
|
|
|
return 0;
|
|
}
|
|
|
|
typedef struct spinlock_ctrl_s {
|
|
spinlock_t spinlock;
|
|
unsigned long flags;
|
|
char *desc;
|
|
} *spinlock_ctrl_t;
|
|
|
|
sal_spinlock_t
|
|
sal_spinlock_create(char *desc)
|
|
{
|
|
spinlock_ctrl_t sl = kmalloc(sizeof(*sl), GFP_KERNEL);
|
|
|
|
if (sl != NULL) {
|
|
spin_lock_init(&sl->spinlock);
|
|
sl->flags = 0;
|
|
sl->desc = desc;
|
|
}
|
|
|
|
return (sal_spinlock_t)sl;
|
|
}
|
|
|
|
void
|
|
sal_spinlock_destroy(sal_spinlock_t lock)
|
|
{
|
|
spinlock_ctrl_t sl = (spinlock_ctrl_t)lock;
|
|
|
|
kfree(sl);
|
|
}
|
|
|
|
int
|
|
sal_spinlock_lock(sal_spinlock_t lock)
|
|
{
|
|
spinlock_ctrl_t sl = (spinlock_ctrl_t)lock;
|
|
|
|
spin_lock_irqsave(&sl->spinlock, sl->flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
sal_spinlock_unlock(sal_spinlock_t lock)
|
|
{
|
|
spinlock_ctrl_t sl = (spinlock_ctrl_t)lock;
|
|
|
|
spin_unlock_irqrestore(&sl->spinlock, sl->flags);
|
|
|
|
return 0;
|
|
}
|
|
|