2021-01-28 10:38:47 -06:00
|
|
|
/*! \file ngknet_linux.h
|
|
|
|
*
|
|
|
|
* Data structure and macro definitions for Linux kernel APIs abstraction.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/*
|
[BCMSAI] Update BCMSAI debian to 6.0.0.10 with 6.5.23 SDK, and opennsl module to 6.5.23 (#9046)
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>
2021-10-28 02:12:32 -05:00
|
|
|
* $Copyright: Copyright 2018-2021 Broadcom. All rights reserved.
|
2021-01-28 10:38:47 -06:00
|
|
|
* 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.$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NGKNET_LINUX_H
|
|
|
|
#define NGKNET_LINUX_H
|
|
|
|
|
|
|
|
#include <linux/version.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Kernel abstraction
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MODULE_PARAM(n, t, p) module_param(n, t, p)
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
|
|
|
|
#define kal_vlan_hwaccel_put_tag(skb, proto, tci) \
|
|
|
|
__vlan_hwaccel_put_tag(skb, tci)
|
|
|
|
#define NETIF_F_HW_VLAN_CTAG_RX NETIF_F_HW_VLAN_RX
|
|
|
|
#define NETIF_F_HW_VLAN_CTAG_TX NETIF_F_HW_VLAN_TX
|
|
|
|
#else
|
|
|
|
#define kal_vlan_hwaccel_put_tag(skb, proto, tci) \
|
|
|
|
__vlan_hwaccel_put_tag(skb, htons(proto), tci)
|
|
|
|
#endif /* KERNEL_VERSION(3,10,0) */
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0)
|
|
|
|
static inline int
|
|
|
|
kal_support_paged_skb(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int
|
|
|
|
kal_support_paged_skb(void)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif /* KERNEL_VERSION(3,6,0) */
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0)
|
|
|
|
static inline struct page *
|
|
|
|
kal_dev_alloc_page(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#elif LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0)
|
|
|
|
static inline struct page *
|
|
|
|
kal_dev_alloc_page(void)
|
|
|
|
{
|
|
|
|
return alloc_pages(GFP_ATOMIC | __GFP_ZERO | __GFP_COLD |
|
|
|
|
__GFP_COMP | __GFP_MEMALLOC, 0);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline struct page *
|
|
|
|
kal_dev_alloc_page(void)
|
|
|
|
{
|
|
|
|
return dev_alloc_page();
|
|
|
|
}
|
|
|
|
#endif /* KERNEL_VERSION(3,6,0) */
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0)
|
|
|
|
static inline struct sk_buff *
|
|
|
|
kal_build_skb(void *data, unsigned int frag_size)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline struct sk_buff *
|
|
|
|
kal_build_skb(void *data, unsigned int frag_size)
|
|
|
|
{
|
|
|
|
return build_skb(data, frag_size);
|
|
|
|
}
|
|
|
|
#endif /* KERNEL_VERSION(3,6,0) */
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,7,0)
|
|
|
|
static inline void
|
|
|
|
kal_netif_trans_update(struct net_device *dev)
|
|
|
|
{
|
|
|
|
dev->trans_start = jiffies;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void
|
|
|
|
kal_netif_trans_update(struct net_device *dev)
|
|
|
|
{
|
|
|
|
netif_trans_update(dev);
|
|
|
|
}
|
|
|
|
#endif /* KERNEL_VERSION(4,7,0) */
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,17,0)
|
|
|
|
static inline void
|
|
|
|
kal_time_val_get(struct timeval *tv)
|
|
|
|
{
|
|
|
|
do_gettimeofday(tv);
|
|
|
|
}
|
2021-07-08 19:30:01 -05:00
|
|
|
#elif LINUX_VERSION_CODE < KERNEL_VERSION(5,6,0)
|
2021-01-28 10:38:47 -06:00
|
|
|
static inline void
|
|
|
|
kal_time_val_get(struct timeval *tv)
|
|
|
|
{
|
|
|
|
struct timespec64 ts;
|
|
|
|
ktime_get_real_ts64(&ts);
|
|
|
|
tv->tv_sec = ts.tv_sec;
|
|
|
|
tv->tv_usec = ts.tv_nsec / 1000;
|
|
|
|
}
|
2021-07-08 19:30:01 -05:00
|
|
|
#else
|
|
|
|
static inline void
|
|
|
|
kal_time_val_get(struct timespec64 *tv)
|
|
|
|
{
|
|
|
|
ktime_get_real_ts64(tv);
|
|
|
|
}
|
2021-01-28 10:38:47 -06:00
|
|
|
#endif /* KERNEL_VERSION(3,17,0) */
|
|
|
|
|
|
|
|
static inline unsigned long
|
|
|
|
kal_copy_from_user(void *to, const void __user *from,
|
|
|
|
unsigned int dl, unsigned int sl)
|
|
|
|
{
|
|
|
|
unsigned int len = dl;
|
|
|
|
|
|
|
|
if (unlikely(len != sl)) {
|
|
|
|
printk(KERN_WARNING "Unmatched linux_ngknet.ko, please use the latest.\n");
|
|
|
|
len = min(dl, sl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return copy_from_user(to, from, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long
|
|
|
|
kal_copy_to_user(void __user *to, const void *from,
|
|
|
|
unsigned int dl, unsigned int sl)
|
|
|
|
{
|
|
|
|
unsigned int len = dl;
|
|
|
|
|
|
|
|
if (unlikely(len != sl)) {
|
|
|
|
printk(KERN_WARNING "Unmatched linux_ngknet.ko, please use the latest.\n");
|
|
|
|
len = min(dl, sl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return copy_to_user(to, from, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* System abstraction
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
sal_alloc(unsigned int sz, char *s)
|
|
|
|
{
|
|
|
|
return kmalloc(sz, GFP_KERNEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
sal_free(void *addr)
|
|
|
|
{
|
|
|
|
kfree(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
sal_memset(void *dest, int c, size_t cnt)
|
|
|
|
{
|
|
|
|
return memset(dest, c, cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
sal_memcpy(void *dest, const void *src, size_t cnt)
|
|
|
|
{
|
|
|
|
return memcpy(dest, src, cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *
|
|
|
|
sal_strncpy(char *dest, const char *src, size_t cnt)
|
|
|
|
{
|
|
|
|
return strncpy(dest, src, cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Time
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern unsigned long
|
|
|
|
sal_time_usecs(void);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
sal_usleep(unsigned long usec);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Synchronization
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct sal_sem_s {
|
|
|
|
char semaphore_opaque_type;
|
|
|
|
} *sal_sem_t;
|
|
|
|
|
|
|
|
typedef struct sal_spinlock_s {
|
|
|
|
char spinlock_opaque_type;
|
|
|
|
} *sal_spinlock_t;
|
|
|
|
|
|
|
|
#define SAL_SEM_FOREVER -1
|
|
|
|
#define SAL_SEM_BINARY 1
|
|
|
|
#define SAL_SEM_COUNTING 0
|
|
|
|
|
|
|
|
extern sal_sem_t
|
|
|
|
sal_sem_create(char *desc, int binary, int count);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
sal_sem_destroy(sal_sem_t sem);
|
|
|
|
|
|
|
|
extern int
|
|
|
|
sal_sem_take(sal_sem_t sem, int usec);
|
|
|
|
|
|
|
|
extern int
|
|
|
|
sal_sem_give(sal_sem_t sem);
|
|
|
|
|
|
|
|
extern sal_spinlock_t
|
|
|
|
sal_spinlock_create(char *desc);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
sal_spinlock_destroy(sal_spinlock_t lock);
|
|
|
|
|
|
|
|
extern int
|
|
|
|
sal_spinlock_lock(sal_spinlock_t lock);
|
|
|
|
|
|
|
|
extern int
|
|
|
|
sal_spinlock_unlock(sal_spinlock_t lock);
|
|
|
|
|
|
|
|
#endif /* NGKNET_LINUX_H */
|
|
|
|
|