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

linux-bde.h (8093B)


      1 /*
      2  * Copyright 2017 Broadcom
      3  * 
      4  * This program is free software; you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License, version 2, as
      6  * published by the Free Software Foundation (the "GPL").
      7  * 
      8  * This program is distributed in the hope that it will be useful, but
      9  * WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     11  * General Public License version 2 (GPLv2) for more details.
     12  * 
     13  * You should have received a copy of the GNU General Public License
     14  * version 2 (GPLv2) along with this source code.
     15  */
     16 /***********************************************************************
     17  *
     18  * $Id: linux-bde.h,v 1.24 Broadcom SDK $
     19  * $Copyright: (c) 2005 Broadcom Corp.
     20  * All Rights Reserved.$
     21  *
     22  * Linux Broadcom Device Enumerators
     23  *
     24  *
     25  * There are two Linux BDEs:
     26  *
     27  * 1. Linux Kernel BDE
     28  *
     29  *	This is a kernel module implementing a BDE
     30  *	for the driver running as part of the kernel. 
     31  * 	
     32  *	It manages the devices through the linux PCI interfaces, 
     33  *	and manages a chunk of contiguous, boot-time allocated
     34  *	DMA memory. This is all that is needed if the BCM driver
     35  *	is run as part of the kernel (in another module). 
     36  *
     37  * 2. Linux User BDE
     38  *
     39  *	This is a kernel module and userland library which implement
     40  * 	a complete BDE for applications running in userland. 
     41  *	
     42  *	The kernel module relies upon the real kernel bde, 
     43  *	and allows a user space application (through the user library)
     44  *	to talk directly to the devices. It also virtualized the device 
     45  *	interrupts, so the entire driver can be run as a userspace 
     46  *	application. 
     47  *	
     48  *	While this causes a significant degradation in performance, 
     49  *	because the system runs as a user application, the development
     50  *	and debugging process is about a gillion times easier. 
     51  *	After the core logic is debugged, it can be retargeted using
     52  *	only the kernel bde and run in the kernel. 
     53  *	
     54  *
     55  **********************************************************************/
     56 
     57 #ifndef __LINUX_BDE_H__
     58 #define __LINUX_BDE_H__
     59 
     60 #include <sal/types.h>
     61 
     62 #include <ibde.h>
     63 
     64 
     65 /* 
     66  * Device Major Numbers
     67  * 
     68  * The kernel and user bdes need unique major numbers
     69  * on systems that do not use devfs. 
     70  * 
     71  * They are defined here, along with the module names, 
     72  * to document them if you need to mknod them (or open) them, 
     73  * and to keep them unique. 
     74  *
     75  */
     76 
     77 #include <linux/version.h>
     78 
     79 #ifdef __KERNEL__
     80 #include <linux/types.h>
     81 /* Key stone and Raptor has 2.6.21 but don't have definition */
     82 #if defined(KEYSTONE) || defined(RAPTOR)
     83 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21))
     84     #ifdef PHYS_ADDRS_ARE_64BITS
     85     typedef u64 phys_addr_t;
     86     #else
     87     typedef u32 phys_addr_t;
     88     #endif
     89   #endif
     90 #endif
     91 #endif
     92 
     93 
     94 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
     95 #define LINUX_BDE_DMA_DEVICE_SUPPORT
     96 #endif
     97 
     98 #define LINUX_KERNEL_BDE_NAME 	"linux-kernel-bde"
     99 #define LINUX_KERNEL_BDE_MAJOR 	127
    100 
    101 #define LINUX_USER_BDE_NAME 	"linux-user-bde"
    102 #define LINUX_USER_BDE_MAJOR   	126
    103 
    104 
    105 /* Max devices */
    106 /* 16 switch chips + 2 out-of-band Ethernet + 2 CPUs */
    107 #define LINUX_BDE_MAX_SWITCH_DEVICES    16
    108 #define LINUX_BDE_MAX_ETHER_DEVICES     2
    109 #define LINUX_BDE_MAX_CPU_DEVICES       2
    110 #define LINUX_BDE_MAX_DEVICES           (LINUX_BDE_MAX_SWITCH_DEVICES + \
    111                                          LINUX_BDE_MAX_ETHER_DEVICES + \
    112                                          LINUX_BDE_MAX_CPU_DEVICES) 
    113 
    114 /* 
    115  * PCI devices will be initialized by the Linux Kernel, 
    116  * regardless of architecture.
    117  *
    118  * You need only provide bus endian settings. 
    119  */
    120 
    121 typedef struct linux_bde_bus_s {
    122     int be_pio;
    123     int be_packet;
    124     int be_other;
    125 } linux_bde_bus_t;
    126 
    127 
    128 
    129 /* Device state used for PCI hot swap case. */
    130 /*
    131  * BDE_DEV_STATE_NORMAL : A device is probed normally. Or when the device 
    132  * resource has been updated after "CHANGED", the state will move back to 
    133  * "NORMAL".
    134  */
    135 #define BDE_DEV_STATE_NORMAL       (0)
    136 /*
    137  * BDE_DEV_STATE_REMOVED : A previous probed device was removed.
    138  * We will avoid any device access while the device is in this state.
    139  * The state will be moved to "CHANGED" if the device is re-inserted
    140  * and re-probed.
    141  */
    142 #define BDE_DEV_STATE_REMOVED      (1)
    143 /* 
    144  * BDE_DEV_STATE_CHANGED : The device is re-probed after having been removed.
    145  * The resouces assigned to the device might have been changed after
    146  * re-probing, so we need to re-initialize our resource database accordingly. 
    147  * The state will change to "NORMAL" when the resource have been updated.
    148  */
    149 #define BDE_DEV_STATE_CHANGED      (2)
    150 
    151 extern int linux_bde_create(linux_bde_bus_t* bus, ibde_t** bde);
    152 extern int linux_bde_destroy(ibde_t* bde);
    153 #ifdef BCM_INSTANCE_SUPPORT
    154 extern int linux_bde_instance_attach(unsigned int dev_mask,unsigned int dma_size);
    155 #endif
    156 
    157 #ifdef __KERNEL__
    158 
    159 /*
    160  *  Backdoors provided by the kernel bde
    161  *
    162  */
    163 
    164 /*
    165  * The user bde needs to get cpu physical address for
    166  * the userland code to mmap.
    167  * And the second address is bus address, it is either
    168  * identical to cpu physical address or another address
    169  * (IOVA) translated by IOMMU.
    170  */
    171 extern int lkbde_get_dma_info(phys_addr_t *cpu_pbase, phys_addr_t *dma_pbase, ssize_t *size);
    172 extern uint32 lkbde_get_dev_phys(int d);
    173 extern uint32 lkbde_get_dev_phys_hi(int d);
    174 
    175 /*
    176  * Virtual device address needed by kernel space
    177  * interrupt handler.
    178  */
    179 extern void *lkbde_get_dev_virt(int d);
    180 
    181 /*
    182  * The user bde needs to get some physical addresses for
    183  * the userland code to mmap. The following functions
    184  * supports multiple resources for a single device.
    185  */
    186 extern int lkbde_get_dev_resource(int d, int rsrc, uint32 *flags,
    187                                   uint32 *phys_lo, uint32 *phys_hi); 
    188 
    189 /*
    190  * Backdoor to retrieve OS device structure to be used for
    191  * DMA operations.
    192  */
    193 extern void *lkbde_get_dma_dev(int d);
    194 
    195 /*
    196  * Backdoor to retrieve original hardware/OS device.
    197  */
    198 extern void *lkbde_get_hw_dev(int d);
    199 
    200 /*
    201  * Backdoor to retrieve number of switch devices probed.
    202  */
    203 extern int lkbde_get_num_devices(int type);
    204 
    205 /*
    206  * Retrive the device state from Kernel BDE.
    207  * Used for KNET and User BDE for pci hot swap case.
    208  */
    209 extern int lkbde_dev_state_get(int d, uint32 *state);
    210 extern int lkbde_dev_state_set(int d, uint32 state);
    211 
    212 /*
    213  * Retrive the mapping between emulated HW device and instance id
    214  */
    215 extern int lkbde_dev_instid_get(int d, uint32 *instid);
    216 extern int lkbde_dev_instid_set(int d, uint32 instid);
    217 
    218 /*
    219  * Functions that allow an interrupt handler in user mode to
    220  * coexist with interrupt handler in kernel module.
    221  */
    222 extern int lkbde_irq_mask_set(int d, uint32 addr, uint32 mask, uint32 fmask);
    223 extern int lkbde_irq_mask_get(int d, uint32 *mask, uint32 *fmask);
    224 
    225 #ifdef BCM_SAND_SUPPORT
    226 extern int lkbde_cpu_write(int d, uint32 addr, uint32 *buf);
    227 extern int lkbde_cpu_read(int d, uint32 addr, uint32 *buf);
    228 extern int lkbde_cpu_pci_register(int d);
    229 #endif
    230 
    231 /*
    232  * This flag must be OR'ed onto the device number when calling
    233  * interrupt_connect/disconnect and irq_mask_set functions from
    234  * a secondary device driver.
    235  */
    236 #define LKBDE_ISR2_DEV  0x8000
    237 /*
    238  * This flag should be OR'ed onto the device number when calling
    239  * irq_mask_set functions from a secondary device driver if the
    240  * mask register is iProc register.
    241  */
    242 #define LKBDE_IPROC_REG 0x4000
    243 
    244 #ifdef BCM_SAND_SUPPORT
    245 #include <linux/version.h>
    246 #if defined(__DUNE_LINUX_BCM_CPU_PCIE__) && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
    247 #ifndef _SIMPLE_MEMORY_ALLOCATION_
    248 #define _SIMPLE_MEMORY_ALLOCATION_ 1
    249 #endif
    250 #endif
    251 #endif
    252 
    253 #if defined(IPROC_CMICD) && defined(CONFIG_CMA)
    254 #ifndef _SIMPLE_MEMORY_ALLOCATION_
    255 #define _SIMPLE_MEMORY_ALLOCATION_ 1
    256 #endif
    257 #endif
    258 
    259 /* Allocation via dma_alloc_coherent is turned off by default */
    260 #ifndef _SIMPLE_MEMORY_ALLOCATION_
    261 #define _SIMPLE_MEMORY_ALLOCATION_ 9 /* compile in the allocation method, but do not use it by default */
    262 #endif
    263 
    264 /* By default we use our private mmap for DMA pool */
    265 #ifndef USE_LINUX_BDE_MMAP
    266 #define USE_LINUX_BDE_MMAP 1
    267 #endif
    268 
    269 #endif /* __KERNEL__ */
    270 
    271 #endif /* __LINUX_BDE_H__ */