[CENTEC] Fix compile issues for centec x86 platform image build under 4.19 (#4605)

* centec x86 update for buster
* optimize dal code
This commit is contained in:
taochengyi 2020-05-16 05:49:22 +08:00 committed by GitHub
parent d90fdbf3f9
commit edde1222b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 14 additions and 4893 deletions

View File

@ -580,25 +580,6 @@ _dal_set_msi_enabe(unsigned int lchip, unsigned int irq_num)
msi_irq_base[lchip] = dal_dev[lchip].pci_dev->irq;
msi_irq_num[lchip] = 1;
}
else
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 79))
ret = pci_enable_msi_exact(dal_dev[lchip].pci_dev, irq_num);
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 26, 32))
ret = pci_enable_msi_block(dal_dev[lchip].pci_dev, irq_num);
#else
ret = -1;
#endif
if (ret)
{
printk ("msi enable failed!!! lchip = %d, irq_num = %d\n", lchip, irq_num);
pci_disable_msi(dal_dev[lchip].pci_dev);
msi_used = 0;
}
msi_irq_base[lchip] = dal_dev[lchip].pci_dev->irq;
msi_irq_num[lchip] = irq_num;
}
return ret;
}

View File

@ -10,8 +10,9 @@ $(DOCKER_SYNCD_CENTEC_RPC)_DEPENDS += $(SYNCD_RPC_DBG) \
$(LIBSAIMETADATA_DBG) \
$(LIBSAIREDIS_DBG)
endif
$(DOCKER_SYNCD_CENTEC_RPC)_LOAD_DOCKERS += $(DOCKER_SYNCD_CENTEC)
$(DOCKER_SYNCD_CENTEC_RPC)_LOAD_DOCKERS += $(DOCKER_SYNCD_BASE)
SONIC_DOCKER_IMAGES += $(DOCKER_SYNCD_CENTEC_RPC)
SONIC_STRETCH_DOCKERS += $(DOCKER_SYNCD_CENTEC_RPC)
ifeq ($(ENABLE_SYNCD_RPC),y)
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_SYNCD_CENTEC_RPC)
endif

View File

@ -1,22 +1,16 @@
# docker image for centec syncd
DOCKER_SYNCD_CENTEC = docker-syncd-centec.gz
$(DOCKER_SYNCD_CENTEC)_PATH = $(PLATFORM_PATH)/docker-syncd-centec
$(DOCKER_SYNCD_CENTEC)_DEPENDS += $(SYNCD)
$(DOCKER_SYNCD_CENTEC)_FILES += $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT)
ifeq ($(INSTALL_DEBUG_TOOLS), y)
DOCKER_SYNCD_PLATFORM_CODE = centec
include $(PLATFORM_PATH)/../template/docker-syncd-base.mk
$(DOCKER_SYNCD_BASE)_DEPENDS += $(SYNCD)
$(DOCKER_SYNCD_CENTEC)_DEPENDS += $(SYNCD_DBG) \
$(LIBSWSSCOMMON_DBG) \
$(LIBSAIMETADATA_DBG) \
$(LIBSAIREDIS_DBG)
endif
$(DOCKER_SYNCD_CENTEC)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_STRETCH)
SONIC_DOCKER_IMAGES += $(DOCKER_SYNCD_CENTEC)
ifneq ($(ENABLE_SYNCD_RPC),y)
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_SYNCD_CENTEC)
endif
$(DOCKER_SYNCD_CENTEC)_CONTAINER_NAME = syncd
$(DOCKER_SYNCD_CENTEC)_RUN_OPT += --privileged -t
$(DOCKER_SYNCD_CENTEC)_RUN_OPT += -v /host/machine.conf:/etc/machine.conf
$(DOCKER_SYNCD_CENTEC)_RUN_OPT += -v /var/run/docker-syncd:/var/run/sswsyncd

View File

@ -7,8 +7,7 @@ include $(PLATFORM_PATH)/one-image.mk
include $(PLATFORM_PATH)/libsaithrift-dev.mk
include $(PLATFORM_PATH)/docker-ptf-centec.mk
SONIC_ALL += $(SONIC_ONE_IMAGE) \
$(DOCKER_SYNCD_CENTEC_RPC)
SONIC_ALL += $(SONIC_ONE_IMAGE)
# Inject centec sai into sairedis
$(LIBSAIREDIS)_DEPENDS += $(CENTEC_SAI)

View File

@ -1,2 +1 @@
obj-m := centec_e582_48x2q4z_platform.o dal.o centec_at24c64.o
dal-y := dal_kernel.o dal_mpool.o
obj-m := centec_e582_48x2q4z_platform.o centec_at24c64.o

View File

@ -1,2 +1 @@
obj-m := centec_e582_48x6q_platform.o dal.o centec_at24c64.o
dal-y := dal_kernel.o dal_mpool.o
obj-m := centec_e582_48x6q_platform.o centec_at24c64.o

View File

@ -1,171 +0,0 @@
/**
@file dal_kernel_io.h
@author Copyright (C) 2012 Centec Networks Inc. All rights reserved.
@date 2012-4-9
@version v2.0
*/
#ifndef _DAL_KERNEL_H_
#define _DAL_KERNEL_H_
#ifdef __cplusplus
extern "C" {
#endif
#if defined(CONFIG_RESOURCES_64BIT) || defined(CONFIG_PHYS_ADDR_T_64BIT)
#define PHYS_ADDR_IS_64BIT
#endif
#ifndef SDK_IN_USERMODE
#ifdef PHYS_ADDR_IS_64BIT
typedef long long intptr;
typedef unsigned long long uintptr;
#else
typedef int intptr;
typedef unsigned int uintptr;
#endif
#endif
#define DAL_PCI_READ_ADDR 0x0
#define DAL_PCI_READ_DATA 0xc
#define DAL_PCI_WRITE_ADDR 0x8
#define DAL_PCI_WRITE_DATA 0x4
#define DAL_PCI_STATUS 0x10
#define DAL_PCI_STATUS_IN_PROCESS 31
#define DAL_PCI_STATUS_BAD_PARITY 5
#define DAL_PCI_STATUS_CPU_ACCESS_ERR 4
#define DAL_PCI_STATUS_READ_CMD 3
#define DAL_PCI_STATUS_REGISTER_ERR 1
#define DAL_PCI_STATUS_REGISTER_ACK 0
#define DAL_PCI_ACCESS_TIMEOUT 0x64
#define DAL_NAME "linux_dal" /* "linux_dal" */
#define DAL_DEV_MAJOR 198
#define DAL_DEV_INTR_MAJOR_BASE 200
#define DAL_DEV_NAME "/dev/" DAL_NAME
#define DAL_ONE_KB 1024
#define DAL_ONE_MB (1024*1024)
struct dal_chip_parm_s
{
unsigned int lchip; /*tmp should be uint8*/
unsigned int fpga_id; /*tmp add*/
unsigned int reg_addr;
unsigned int value;
};
typedef struct dal_chip_parm_s dal_chip_parm_t;
struct dal_intr_parm_s
{
unsigned int irq;
unsigned int enable;
};
typedef struct dal_intr_parm_s dal_intr_parm_t;
struct dal_irq_mapping_s
{
unsigned int hw_irq;
unsigned int sw_irq;
};
typedef struct dal_irq_mapping_s dal_irq_mapping_t;
struct dal_user_dev_s
{
unsigned int chip_num; /*output: local chip number*/
unsigned int lchip; /*input: local chip id*/
unsigned int phy_base0; /* low 32bits physical base address */
unsigned int phy_base1; /* high 32bits physical base address */
unsigned int bus_no;
unsigned int dev_no;
unsigned int fun_no;
void* virt_base[2]; /* Virtual base address; this must be last member */
};
typedef struct dal_user_dev_s dal_user_dev_t;
struct dma_info_s
{
unsigned int lchip;
unsigned int phy_base;
unsigned int phy_base_hi;
unsigned int size;
unsigned int* virt_base;
};
typedef struct dma_info_s dma_info_t;
struct dal_pci_cfg_ioctl_s
{
unsigned int lchip; /* Device ID */
unsigned int offset;
unsigned int value;
};
typedef struct dal_pci_cfg_ioctl_s dal_pci_cfg_ioctl_t;
struct dal_msi_info_s
{
unsigned int lchip;
unsigned int irq_base;
unsigned int irq_num;
};
typedef struct dal_msi_info_s dal_msi_info_t;
struct dal_intr_info_s
{
unsigned int irq;
unsigned int irq_idx;
};
typedef struct dal_intr_info_s dal_intr_info_t;
struct dal_dma_cache_info_s
{
unsigned long ptr;
unsigned int length;
};
typedef struct dal_dma_cache_info_s dal_dma_cache_info_t;
#define CMD_MAGIC 'C'
#define CMD_WRITE_CHIP _IO(CMD_MAGIC, 0) /* for humber ioctrol*/
#define CMD_READ_CHIP _IO(CMD_MAGIC, 1) /* for humber ioctrol*/
#define CMD_GET_DEVICES _IO(CMD_MAGIC, 2)
#define CMD_GET_DAL_VERSION _IO(CMD_MAGIC, 3)
#define CMD_PCI_CONFIG_WRITE _IO(CMD_MAGIC, 4)
#define CMD_PCI_CONFIG_READ _IO(CMD_MAGIC, 5)
#define CMD_GET_DMA_INFO _IO(CMD_MAGIC, 6)
#define CMD_REG_INTERRUPTS _IO(CMD_MAGIC, 7)
#define CMD_UNREG_INTERRUPTS _IO(CMD_MAGIC, 8)
#define CMD_EN_INTERRUPTS _IO(CMD_MAGIC, 9)
#define CMD_I2C_READ _IO(CMD_MAGIC, 10)
#define CMD_I2C_WRITE _IO(CMD_MAGIC, 11)
#define CMD_GET_MSI_INFO _IO(CMD_MAGIC, 12)
#define CMD_SET_MSI_CAP _IO(CMD_MAGIC, 13)
#define CMD_IRQ_MAPPING _IO(CMD_MAGIC, 14)
#define CMD_GET_INTR_INFO _IO(CMD_MAGIC, 15)
#define CMD_CACHE_INVAL _IO(CMD_MAGIC, 16)
#define CMD_CACHE_FLUSH _IO(CMD_MAGIC, 17)
enum dal_version_e
{
VERSION_MIN,
VERSION_1DOT0,
VERSION_1DOT1,
VERSION_1DOT2,
VERSION_MAX
};
typedef enum dal_version_e dal_version_t;
/* We try to assemble a contiguous segment from chunks of this size */
#define DMA_BLOCK_SIZE (512 * DAL_ONE_KB)
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,350 +0,0 @@
#include "dal_mpool.h"
#ifdef __KERNEL__
#include <linux/spinlock.h>
#include <linux/slab.h>
#define DAL_MALLOC(x) kmalloc(x, GFP_ATOMIC)
#define DAL_FREE(x) kfree(x)
static spinlock_t dal_mpool_lock;
#define MPOOL_LOCK_INIT() spin_lock_init(&dal_mpool_lock)
#define MPOOL_LOCK() unsigned long flags; spin_lock_irqsave(&dal_mpool_lock, flags)
#define MPOOL_UNLOCK() spin_unlock_irqrestore(&dal_mpool_lock, flags)
#define DAL_PRINT(fmt,arg...) printk(fmt,##arg)
#else /* !__KERNEL__*/
#include <stdlib.h>
#include "sal.h"
#define DAL_MALLOC(x) malloc(x)
#define DAL_FREE(x) free(x)
static sal_mutex_t* dal_mpool_lock;
#define MPOOL_LOCK_INIT() sal_mutex_create(&dal_mpool_lock)
#define MPOOL_LOCK() sal_mutex_lock(dal_mpool_lock)
#define MPOOL_UNLOCK() sal_mutex_unlock(dal_mpool_lock)
#define DAL_PRINT(fmt,arg...) sal_printf(fmt,##arg)
#endif /* __KERNEL__ */
dal_mpool_mem_t* g_free_block_ptr = NULL;
/* System cache line size */
#ifndef DAL_CACHE_LINE_BYTES
#define DAL_CACHE_LINE_BYTES 256
#endif
#define DAL_MAX_CHIP_NUM 32
static dal_mpool_mem_t* p_desc_pool[DAL_MAX_CHIP_NUM] = {0};
static dal_mpool_mem_t* p_data_pool[DAL_MAX_CHIP_NUM] = {0};
int
dal_mpool_init(void)
{
MPOOL_LOCK_INIT();
return 0;
}
dal_mpool_mem_t*
_dal_mpool_create(void* base, int size, int type)
{
dal_mpool_mem_t* head = NULL;
dal_mpool_mem_t* tail = NULL;
head = (dal_mpool_mem_t*)DAL_MALLOC(sizeof(dal_mpool_mem_t));
if (head == NULL)
{
return NULL;
}
tail = (dal_mpool_mem_t*)DAL_MALLOC(sizeof(dal_mpool_mem_t));
if (tail == NULL)
{
DAL_FREE(head);
return NULL;
}
head->size = tail->size = 0;
head->type = type;
head->address = base;
tail->address = head->address + size;
head->next = tail;
tail->next = NULL;
return head;
}
dal_mpool_mem_t*
dal_mpool_create(unsigned char lchip, void* base, int size)
{
dal_mpool_mem_t* head = NULL;
int mod = (int)(((unsigned long)base) & (DAL_CACHE_LINE_BYTES - 1));
MPOOL_LOCK();
if (mod)
{
base = (char*)base + (DAL_CACHE_LINE_BYTES - mod);
size -= (DAL_CACHE_LINE_BYTES - mod);
}
size &= ~(DAL_CACHE_LINE_BYTES - 1);
/* init for common linkptr, only used for GB */
head = _dal_mpool_create(base, size, DAL_MPOOL_TYPE_USELESS);
if (NULL == head)
{
MPOOL_UNLOCK();
return NULL;
}
/* init for desc linkptr */
p_desc_pool[lchip] = _dal_mpool_create(base, DAL_MPOOL_MAX_DESX_SIZE, DAL_MPOOL_TYPE_DESC);
if (NULL == p_desc_pool[lchip])
{
MPOOL_UNLOCK();
DAL_FREE(head->next);
DAL_FREE(head);
return NULL;
}
/* init for data linkptr */
p_data_pool[lchip] = _dal_mpool_create(((char*)base+DAL_MPOOL_MAX_DESX_SIZE), (size - DAL_MPOOL_MAX_DESX_SIZE), DAL_MPOOL_TYPE_DATA);
if (NULL == p_data_pool[lchip])
{
MPOOL_UNLOCK();
DAL_FREE(head->next);
DAL_FREE(head);
DAL_FREE(p_desc_pool[lchip]->next);
DAL_FREE(p_desc_pool[lchip]);
return NULL;
}
MPOOL_UNLOCK();
return head;
}
dal_mpool_mem_t*
_dal_mpool_alloc_comon(dal_mpool_mem_t* ptr, int size, int type)
{
dal_mpool_mem_t* new_ptr = NULL;
while (ptr && ptr->next)
{
if (ptr->next->address - (ptr->address + ptr->size) >= size)
{
break;
}
ptr = ptr->next;
}
if (!(ptr && ptr->next))
{
return NULL;
}
new_ptr = DAL_MALLOC(sizeof(dal_mpool_mem_t));
if (!new_ptr)
{
return NULL;
}
new_ptr->type = type;
new_ptr->address = ptr->address + ptr->size;
new_ptr->size = size;
new_ptr->next = ptr->next;
ptr->next = new_ptr;
return new_ptr;
}
void*
dal_mpool_alloc(unsigned char lchip, dal_mpool_mem_t* pool, int size, int type)
{
dal_mpool_mem_t* ptr = NULL;
dal_mpool_mem_t* new_ptr = NULL;
int mod;
MPOOL_LOCK();
mod = size & (DAL_CACHE_LINE_BYTES - 1);
if (mod != 0)
{
size += (DAL_CACHE_LINE_BYTES - mod);
}
switch(type)
{
case DAL_MPOOL_TYPE_USELESS:
ptr = pool;
new_ptr = _dal_mpool_alloc_comon(ptr, size, type);
if (NULL == new_ptr)
{
MPOOL_UNLOCK();
return NULL;
}
break;
case DAL_MPOOL_TYPE_DESC:
ptr = p_desc_pool[lchip];
new_ptr = _dal_mpool_alloc_comon(ptr, size, type);
if (NULL == new_ptr)
{
MPOOL_UNLOCK();
return NULL;
}
break;
case DAL_MPOOL_TYPE_DATA:
ptr = p_data_pool[lchip];
new_ptr = _dal_mpool_alloc_comon(ptr, size, type);
if (NULL == new_ptr)
{
MPOOL_UNLOCK();
return NULL;
}
break;
default:
MPOOL_UNLOCK();
return NULL;
break;
}
MPOOL_UNLOCK();
if( NULL == new_ptr )
{
return NULL;
}
return new_ptr->address;
}
void
_dal_mpool_free(dal_mpool_mem_t* ptr, void* addr, int type)
{
unsigned char* address = (unsigned char*)addr;
dal_mpool_mem_t* prev = NULL;
while (ptr && ptr->next)
{
if (ptr->next->address == address)
{
break;
}
ptr = ptr->next;
}
if (ptr && ptr->next)
{
prev = ptr;
ptr = ptr->next;
prev->next = ptr->next;
DAL_FREE(ptr);
}
return;
}
void
dal_mpool_free(unsigned char lchip, dal_mpool_mem_t* pool, void* addr)
{
dal_mpool_mem_t* ptr = pool;
MPOOL_LOCK();
switch(pool->type)
{
case DAL_MPOOL_TYPE_USELESS:
ptr = pool;
_dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_USELESS);
break;
case DAL_MPOOL_TYPE_DESC:
ptr = p_desc_pool[lchip];
_dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_DESC);
break;
case DAL_MPOOL_TYPE_DATA:
ptr = p_data_pool[lchip];
_dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_DATA);
break;
default:
break;
}
MPOOL_UNLOCK();
return;
}
int
dal_mpool_destroy(unsigned char lchip, dal_mpool_mem_t* pool)
{
dal_mpool_mem_t* ptr, * next;
MPOOL_LOCK();
for (ptr = pool; ptr; ptr = next)
{
next = ptr->next;
DAL_FREE(ptr);
}
for (ptr = p_desc_pool[lchip]; ptr; ptr = next)
{
next = ptr->next;
DAL_FREE(ptr);
}
for (ptr = p_data_pool[lchip]; ptr; ptr = next)
{
next = ptr->next;
DAL_FREE(ptr);
}
MPOOL_UNLOCK();
return 0;
}
int
dal_mpool_usage(dal_mpool_mem_t* pool, int type)
{
int usage = 0;
dal_mpool_mem_t* ptr;
MPOOL_LOCK();
for (ptr = pool; ptr; ptr = ptr->next)
{
if (ptr->type == type || ptr->type == -1)
{
usage += ptr->size;
}
}
MPOOL_UNLOCK();
return usage;
}
int
dal_mpool_debug(dal_mpool_mem_t* pool)
{
dal_mpool_mem_t* ptr;
int index = 0;
MPOOL_LOCK();
for (ptr = pool; ptr; ptr = ptr->next)
{
// DAL_PRINT("%2dst mpool block: address=0x%8x, size=0x%x \n", index, (unsigned int)ptr->address, ptr->size);
DAL_PRINT("%2dst mpool block: address=%p, size=0x%x \n", index, ptr->address, ptr->size); // note
index++;
}
MPOOL_UNLOCK();
return 0;
}

View File

@ -1,72 +0,0 @@
/**
@file dal_mpool.h
@author Copyright (C) 2011 Centec Networks Inc. All rights reserved.
@date 2012-5-10
@version v2.0
This file contains the dma memory init, allocation and free APIs
*/
#ifndef _DMA_MPOOL_H
#define _DMA_MPOOL_H
#ifdef __cplusplus
extern "C" {
#endif
#define DAL_MPOOL_MAX_DESX_SIZE (1024*1024)
enum dal_mpool_type_e
{
DAL_MPOOL_TYPE_USELESS, /* just compatible with GB */
DAL_MPOOL_TYPE_DESC, /* dma mpool op for desc */
DAL_MPOOL_TYPE_DATA /* dma mpool op for data */
};
typedef enum dal_mpool_type_e dal_mpool_type_t;
struct dal_mpool_mem_s
{
unsigned char* address;
int size;
int type;
struct dal_mpool_mem_s* next;
};
typedef struct dal_mpool_mem_s dal_mpool_mem_t;
/**
@brief This function is to alloc dma memory
@param[in] size size of memory
@return NULL
*/
extern int
dal_mpool_init(void);
extern dal_mpool_mem_t*
dal_mpool_create(unsigned char lchip, void* base_ptr, int size);
extern void*
dal_mpool_alloc(unsigned char lchip, dal_mpool_mem_t* pool, int size, int type);
extern void
dal_mpool_free(unsigned char lchip, dal_mpool_mem_t* pool, void* addr);
extern int
dal_mpool_destroy(unsigned char lchip, dal_mpool_mem_t* pool);
extern int
dal_mpool_usage(dal_mpool_mem_t* pool, int type);
extern int
dal_mpool_debug(dal_mpool_mem_t* pool);
#ifdef __cplusplus
}
#endif
#endif /* !_DMA_MPOOL_H */

View File

@ -5,7 +5,7 @@ export INSTALL_MOD_DIR:=extra
KVERSION ?= $(shell uname -r)
KERNEL_SRC := /lib/modules/$(KVERSION)
MOD_SRC_DIR:= $(shell pwd)
MODULE_DIRS:= 48x6q 48x2q4z
MODULE_DIRS:= 48x6q 48x2q4z ../centec-dal
%:
dh $@

View File

@ -7,6 +7,6 @@ Standards-Version: 3.9.3
Package: platform-modules-embedway-es6220
Architecture: amd64
Depends: linux-image-4.9.0-9-2-amd64
Depends: linux-image-4.19.0-6-amd64-unsigned
Description: kernel modules for platform devices such as fan, led, sfp

View File

@ -5,7 +5,7 @@ export INSTALL_MOD_DIR:=extra
KVERSION ?= $(shell uname -r)
KERNEL_SRC := /lib/modules/$(KVERSION)
MOD_SRC_DIR:= $(shell pwd)
MODULE_DIRS:= es6220
MODULE_DIRS:= ../centec-dal
%:
dh $@

View File

@ -1,171 +0,0 @@
/**
@file dal_kernel_io.h
@author Copyright (C) 2012 Centec Networks Inc. All rights reserved.
@date 2012-4-9
@version v2.0
*/
#ifndef _DAL_KERNEL_H_
#define _DAL_KERNEL_H_
#ifdef __cplusplus
extern "C" {
#endif
#if defined(CONFIG_RESOURCES_64BIT) || defined(CONFIG_PHYS_ADDR_T_64BIT)
#define PHYS_ADDR_IS_64BIT
#endif
#ifndef SDK_IN_USERMODE
#ifdef PHYS_ADDR_IS_64BIT
typedef long long intptr;
typedef unsigned long long uintptr;
#else
typedef int intptr;
typedef unsigned int uintptr;
#endif
#endif
#define DAL_PCI_READ_ADDR 0x0
#define DAL_PCI_READ_DATA 0xc
#define DAL_PCI_WRITE_ADDR 0x8
#define DAL_PCI_WRITE_DATA 0x4
#define DAL_PCI_STATUS 0x10
#define DAL_PCI_STATUS_IN_PROCESS 31
#define DAL_PCI_STATUS_BAD_PARITY 5
#define DAL_PCI_STATUS_CPU_ACCESS_ERR 4
#define DAL_PCI_STATUS_READ_CMD 3
#define DAL_PCI_STATUS_REGISTER_ERR 1
#define DAL_PCI_STATUS_REGISTER_ACK 0
#define DAL_PCI_ACCESS_TIMEOUT 0x64
#define DAL_NAME "linux_dal" /* "linux_dal" */
#define DAL_DEV_MAJOR 198
#define DAL_DEV_INTR_MAJOR_BASE 200
#define DAL_DEV_NAME "/dev/" DAL_NAME
#define DAL_ONE_KB 1024
#define DAL_ONE_MB (1024*1024)
struct dal_chip_parm_s
{
unsigned int lchip; /*tmp should be uint8*/
unsigned int fpga_id; /*tmp add*/
unsigned int reg_addr;
unsigned int value;
};
typedef struct dal_chip_parm_s dal_chip_parm_t;
struct dal_intr_parm_s
{
unsigned int irq;
unsigned int enable;
};
typedef struct dal_intr_parm_s dal_intr_parm_t;
struct dal_irq_mapping_s
{
unsigned int hw_irq;
unsigned int sw_irq;
};
typedef struct dal_irq_mapping_s dal_irq_mapping_t;
struct dal_user_dev_s
{
unsigned int chip_num; /*output: local chip number*/
unsigned int lchip; /*input: local chip id*/
unsigned int phy_base0; /* low 32bits physical base address */
unsigned int phy_base1; /* high 32bits physical base address */
unsigned int bus_no;
unsigned int dev_no;
unsigned int fun_no;
void* virt_base[2]; /* Virtual base address; this must be last member */
};
typedef struct dal_user_dev_s dal_user_dev_t;
struct dma_info_s
{
unsigned int lchip;
unsigned int phy_base;
unsigned int phy_base_hi;
unsigned int size;
unsigned int* virt_base;
};
typedef struct dma_info_s dma_info_t;
struct dal_pci_cfg_ioctl_s
{
unsigned int lchip; /* Device ID */
unsigned int offset;
unsigned int value;
};
typedef struct dal_pci_cfg_ioctl_s dal_pci_cfg_ioctl_t;
struct dal_msi_info_s
{
unsigned int lchip;
unsigned int irq_base;
unsigned int irq_num;
};
typedef struct dal_msi_info_s dal_msi_info_t;
struct dal_intr_info_s
{
unsigned int irq;
unsigned int irq_idx;
};
typedef struct dal_intr_info_s dal_intr_info_t;
struct dal_dma_cache_info_s
{
unsigned long ptr;
unsigned int length;
};
typedef struct dal_dma_cache_info_s dal_dma_cache_info_t;
#define CMD_MAGIC 'C'
#define CMD_WRITE_CHIP _IO(CMD_MAGIC, 0) /* for humber ioctrol*/
#define CMD_READ_CHIP _IO(CMD_MAGIC, 1) /* for humber ioctrol*/
#define CMD_GET_DEVICES _IO(CMD_MAGIC, 2)
#define CMD_GET_DAL_VERSION _IO(CMD_MAGIC, 3)
#define CMD_PCI_CONFIG_WRITE _IO(CMD_MAGIC, 4)
#define CMD_PCI_CONFIG_READ _IO(CMD_MAGIC, 5)
#define CMD_GET_DMA_INFO _IO(CMD_MAGIC, 6)
#define CMD_REG_INTERRUPTS _IO(CMD_MAGIC, 7)
#define CMD_UNREG_INTERRUPTS _IO(CMD_MAGIC, 8)
#define CMD_EN_INTERRUPTS _IO(CMD_MAGIC, 9)
#define CMD_I2C_READ _IO(CMD_MAGIC, 10)
#define CMD_I2C_WRITE _IO(CMD_MAGIC, 11)
#define CMD_GET_MSI_INFO _IO(CMD_MAGIC, 12)
#define CMD_SET_MSI_CAP _IO(CMD_MAGIC, 13)
#define CMD_IRQ_MAPPING _IO(CMD_MAGIC, 14)
#define CMD_GET_INTR_INFO _IO(CMD_MAGIC, 15)
#define CMD_CACHE_INVAL _IO(CMD_MAGIC, 16)
#define CMD_CACHE_FLUSH _IO(CMD_MAGIC, 17)
enum dal_version_e
{
VERSION_MIN,
VERSION_1DOT0,
VERSION_1DOT1,
VERSION_1DOT2,
VERSION_MAX
};
typedef enum dal_version_e dal_version_t;
/* We try to assemble a contiguous segment from chunks of this size */
#define DMA_BLOCK_SIZE (512 * DAL_ONE_KB)
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,350 +0,0 @@
#include "dal_mpool.h"
#ifdef __KERNEL__
#include <linux/spinlock.h>
#include <linux/slab.h>
#define DAL_MALLOC(x) kmalloc(x, GFP_ATOMIC)
#define DAL_FREE(x) kfree(x)
static spinlock_t dal_mpool_lock;
#define MPOOL_LOCK_INIT() spin_lock_init(&dal_mpool_lock)
#define MPOOL_LOCK() unsigned long flags; spin_lock_irqsave(&dal_mpool_lock, flags)
#define MPOOL_UNLOCK() spin_unlock_irqrestore(&dal_mpool_lock, flags)
#define DAL_PRINT(fmt,arg...) printk(fmt,##arg)
#else /* !__KERNEL__*/
#include <stdlib.h>
#include "sal.h"
#define DAL_MALLOC(x) malloc(x)
#define DAL_FREE(x) free(x)
static sal_mutex_t* dal_mpool_lock;
#define MPOOL_LOCK_INIT() sal_mutex_create(&dal_mpool_lock)
#define MPOOL_LOCK() sal_mutex_lock(dal_mpool_lock)
#define MPOOL_UNLOCK() sal_mutex_unlock(dal_mpool_lock)
#define DAL_PRINT(fmt,arg...) sal_printf(fmt,##arg)
#endif /* __KERNEL__ */
dal_mpool_mem_t* g_free_block_ptr = NULL;
/* System cache line size */
#ifndef DAL_CACHE_LINE_BYTES
#define DAL_CACHE_LINE_BYTES 256
#endif
#define DAL_MAX_CHIP_NUM 32
static dal_mpool_mem_t* p_desc_pool[DAL_MAX_CHIP_NUM] = {0};
static dal_mpool_mem_t* p_data_pool[DAL_MAX_CHIP_NUM] = {0};
int
dal_mpool_init(void)
{
MPOOL_LOCK_INIT();
return 0;
}
dal_mpool_mem_t*
_dal_mpool_create(void* base, int size, int type)
{
dal_mpool_mem_t* head = NULL;
dal_mpool_mem_t* tail = NULL;
head = (dal_mpool_mem_t*)DAL_MALLOC(sizeof(dal_mpool_mem_t));
if (head == NULL)
{
return NULL;
}
tail = (dal_mpool_mem_t*)DAL_MALLOC(sizeof(dal_mpool_mem_t));
if (tail == NULL)
{
DAL_FREE(head);
return NULL;
}
head->size = tail->size = 0;
head->type = type;
head->address = base;
tail->address = head->address + size;
head->next = tail;
tail->next = NULL;
return head;
}
dal_mpool_mem_t*
dal_mpool_create(unsigned char lchip, void* base, int size)
{
dal_mpool_mem_t* head = NULL;
int mod = (int)(((unsigned long)base) & (DAL_CACHE_LINE_BYTES - 1));
MPOOL_LOCK();
if (mod)
{
base = (char*)base + (DAL_CACHE_LINE_BYTES - mod);
size -= (DAL_CACHE_LINE_BYTES - mod);
}
size &= ~(DAL_CACHE_LINE_BYTES - 1);
/* init for common linkptr, only used for GB */
head = _dal_mpool_create(base, size, DAL_MPOOL_TYPE_USELESS);
if (NULL == head)
{
MPOOL_UNLOCK();
return NULL;
}
/* init for desc linkptr */
p_desc_pool[lchip] = _dal_mpool_create(base, DAL_MPOOL_MAX_DESX_SIZE, DAL_MPOOL_TYPE_DESC);
if (NULL == p_desc_pool[lchip])
{
MPOOL_UNLOCK();
DAL_FREE(head->next);
DAL_FREE(head);
return NULL;
}
/* init for data linkptr */
p_data_pool[lchip] = _dal_mpool_create(((char*)base+DAL_MPOOL_MAX_DESX_SIZE), (size - DAL_MPOOL_MAX_DESX_SIZE), DAL_MPOOL_TYPE_DATA);
if (NULL == p_data_pool[lchip])
{
MPOOL_UNLOCK();
DAL_FREE(head->next);
DAL_FREE(head);
DAL_FREE(p_desc_pool[lchip]->next);
DAL_FREE(p_desc_pool[lchip]);
return NULL;
}
MPOOL_UNLOCK();
return head;
}
dal_mpool_mem_t*
_dal_mpool_alloc_comon(dal_mpool_mem_t* ptr, int size, int type)
{
dal_mpool_mem_t* new_ptr = NULL;
while (ptr && ptr->next)
{
if (ptr->next->address - (ptr->address + ptr->size) >= size)
{
break;
}
ptr = ptr->next;
}
if (!(ptr && ptr->next))
{
return NULL;
}
new_ptr = DAL_MALLOC(sizeof(dal_mpool_mem_t));
if (!new_ptr)
{
return NULL;
}
new_ptr->type = type;
new_ptr->address = ptr->address + ptr->size;
new_ptr->size = size;
new_ptr->next = ptr->next;
ptr->next = new_ptr;
return new_ptr;
}
void*
dal_mpool_alloc(unsigned char lchip, dal_mpool_mem_t* pool, int size, int type)
{
dal_mpool_mem_t* ptr = NULL;
dal_mpool_mem_t* new_ptr = NULL;
int mod;
MPOOL_LOCK();
mod = size & (DAL_CACHE_LINE_BYTES - 1);
if (mod != 0)
{
size += (DAL_CACHE_LINE_BYTES - mod);
}
switch(type)
{
case DAL_MPOOL_TYPE_USELESS:
ptr = pool;
new_ptr = _dal_mpool_alloc_comon(ptr, size, type);
if (NULL == new_ptr)
{
MPOOL_UNLOCK();
return NULL;
}
break;
case DAL_MPOOL_TYPE_DESC:
ptr = p_desc_pool[lchip];
new_ptr = _dal_mpool_alloc_comon(ptr, size, type);
if (NULL == new_ptr)
{
MPOOL_UNLOCK();
return NULL;
}
break;
case DAL_MPOOL_TYPE_DATA:
ptr = p_data_pool[lchip];
new_ptr = _dal_mpool_alloc_comon(ptr, size, type);
if (NULL == new_ptr)
{
MPOOL_UNLOCK();
return NULL;
}
break;
default:
MPOOL_UNLOCK();
return NULL;
break;
}
MPOOL_UNLOCK();
if( NULL == new_ptr )
{
return NULL;
}
return new_ptr->address;
}
void
_dal_mpool_free(dal_mpool_mem_t* ptr, void* addr, int type)
{
unsigned char* address = (unsigned char*)addr;
dal_mpool_mem_t* prev = NULL;
while (ptr && ptr->next)
{
if (ptr->next->address == address)
{
break;
}
ptr = ptr->next;
}
if (ptr && ptr->next)
{
prev = ptr;
ptr = ptr->next;
prev->next = ptr->next;
DAL_FREE(ptr);
}
return;
}
void
dal_mpool_free(unsigned char lchip, dal_mpool_mem_t* pool, void* addr)
{
dal_mpool_mem_t* ptr = pool;
MPOOL_LOCK();
switch(pool->type)
{
case DAL_MPOOL_TYPE_USELESS:
ptr = pool;
_dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_USELESS);
break;
case DAL_MPOOL_TYPE_DESC:
ptr = p_desc_pool[lchip];
_dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_DESC);
break;
case DAL_MPOOL_TYPE_DATA:
ptr = p_data_pool[lchip];
_dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_DATA);
break;
default:
break;
}
MPOOL_UNLOCK();
return;
}
int
dal_mpool_destroy(unsigned char lchip, dal_mpool_mem_t* pool)
{
dal_mpool_mem_t* ptr, * next;
MPOOL_LOCK();
for (ptr = pool; ptr; ptr = next)
{
next = ptr->next;
DAL_FREE(ptr);
}
for (ptr = p_desc_pool[lchip]; ptr; ptr = next)
{
next = ptr->next;
DAL_FREE(ptr);
}
for (ptr = p_data_pool[lchip]; ptr; ptr = next)
{
next = ptr->next;
DAL_FREE(ptr);
}
MPOOL_UNLOCK();
return 0;
}
int
dal_mpool_usage(dal_mpool_mem_t* pool, int type)
{
int usage = 0;
dal_mpool_mem_t* ptr;
MPOOL_LOCK();
for (ptr = pool; ptr; ptr = ptr->next)
{
if (ptr->type == type || ptr->type == -1)
{
usage += ptr->size;
}
}
MPOOL_UNLOCK();
return usage;
}
int
dal_mpool_debug(dal_mpool_mem_t* pool)
{
dal_mpool_mem_t* ptr;
int index = 0;
MPOOL_LOCK();
for (ptr = pool; ptr; ptr = ptr->next)
{
// DAL_PRINT("%2dst mpool block: address=0x%8x, size=0x%x \n", index, (unsigned int)ptr->address, ptr->size);
DAL_PRINT("%2dst mpool block: address=%p, size=0x%x \n", index, ptr->address, ptr->size); // note
index++;
}
MPOOL_UNLOCK();
return 0;
}

View File

@ -1,72 +0,0 @@
/**
@file dal_mpool.h
@author Copyright (C) 2011 Centec Networks Inc. All rights reserved.
@date 2012-5-10
@version v2.0
This file contains the dma memory init, allocation and free APIs
*/
#ifndef _DMA_MPOOL_H
#define _DMA_MPOOL_H
#ifdef __cplusplus
extern "C" {
#endif
#define DAL_MPOOL_MAX_DESX_SIZE (1024*1024)
enum dal_mpool_type_e
{
DAL_MPOOL_TYPE_USELESS, /* just compatible with GB */
DAL_MPOOL_TYPE_DESC, /* dma mpool op for desc */
DAL_MPOOL_TYPE_DATA /* dma mpool op for data */
};
typedef enum dal_mpool_type_e dal_mpool_type_t;
struct dal_mpool_mem_s
{
unsigned char* address;
int size;
int type;
struct dal_mpool_mem_s* next;
};
typedef struct dal_mpool_mem_s dal_mpool_mem_t;
/**
@brief This function is to alloc dma memory
@param[in] size size of memory
@return NULL
*/
extern int
dal_mpool_init(void);
extern dal_mpool_mem_t*
dal_mpool_create(unsigned char lchip, void* base_ptr, int size);
extern void*
dal_mpool_alloc(unsigned char lchip, dal_mpool_mem_t* pool, int size, int type);
extern void
dal_mpool_free(unsigned char lchip, dal_mpool_mem_t* pool, void* addr);
extern int
dal_mpool_destroy(unsigned char lchip, dal_mpool_mem_t* pool);
extern int
dal_mpool_usage(dal_mpool_mem_t* pool, int type);
extern int
dal_mpool_debug(dal_mpool_mem_t* pool);
#ifdef __cplusplus
}
#endif
#endif /* !_DMA_MPOOL_H */