Debian Codegraph @

langford.h

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 4 — not the installed (fully patched) source.
4 Debian patches touch this file
1 /***********************************************************************
2 * The langford header. This includes the memory location and offset
3 * for various items in the PCIe BAR device.
4 *
5 * (c) 2013 Per Vices Corporation
6 *
7 * This code is licensed under the GPLv3
8 ************************************************************************/
9
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/pci.h>
13 #include <linux/pci_regs.h>
14 #include <linux/io.h>
15 #include <linux/cdev.h>
16 #include <linux/types.h>
17 #include <linux/fs.h>
18 #include <linux/kthread.h>
19 #include <linux/version.h>
20 #include <asm/uaccess.h>
21 #include "langford_ioctl.h"
22
23
24 /** Data structure to hold data specific to each instance of the device on the system
25
26 This data structure can be "attached" to a device using dev_set_drvdata:
27 \code
28 DevPrivDataType *DevPrivData;
29 DevPrivData = kmalloc(sizeof(DevPrivDataType), GFP_KERNEL);
30 dev_set_drvdata(&dev->dev, DevPrivData);
31 \endcode
32
33 To access the contents of this data structure after it has been allocated, you can use dev_get_drvdata:
34 \code
35 DevPrivDataType *DevPrivData = dev_get_drvdata(&dev->dev);
36 \endcode
37
38 This data structure should only be allocated once per device. It should be destroyed when the device is unloaded.
39 */
40 typedef struct {
41 struct pci_dev *dev; /**< PCI device which this data structure belongs to*/
42 unsigned int DevVer; /**< Version of the device as seen from the PCI configuartion registers*/
43 void __iomem *pBar0; /**< Pointer to BAR0 accessible in program space*/
44 void __iomem *pBar1; /**< Pointer to BAR1 accessible in program space*/
45 int OpenCtr; /**< Number of open handles (need to close device as many items as it is opened)*/
46 dma_addr_t BusTranslationMask; /**< Mask used to remove LSBs from memory address prior to being writen to translation table*/
47 uint8_t **pRxDmaBuffs; /**< Rx DMA buffers*/
48 uint8_t **pTxDmaBuffs; /**< Rx DMA buffers*/
49 dma_addr_t *RxDmaBuffsBusAddr; /**< Addresses of pRxDmaBuffs as seen by the PCI bus*/
50 dma_addr_t *TxDmaBuffsBusAddr; /**< Addresses of pTxDmaBuffs as seen by the PCI bus*/
51 } DevPrivDataType;
52
53 /*Delete this define and the block of code it contains in production*/
54 #define DELETEME 0
55
56 /*Program constants*/
57 #define DRIVER_NAME "langford" /**< Driver name as how it shows up in the kernel logs*/
58 #define VERBOSE_LOGGING_R 0 /**< Extra verbose logging in rx DMA thread*/
59 #define VERBOSE_LOGGING_W 0 /**< Extra verbose logging in tx DMA thread*/
60 #define EMPTY_LOGGING 0 /**< Print messages if read or write buffers are empty*/
61 #define CDEVBUFFSIZE 200000000 /**< Size of buffers for the character device read and write buffers*/
62
63 /*Data required for DMA*/
64 #define DMAPAGEWIDTH 20 /**< Size of address page (i.e. number of pass through bits)*/
65 #define DMARXBUFFS 32 /**< Number of buffers for Rx (device to memory). Combined with DMATXBUFFS must not exceed number of address pages.*/
66 #define DMARXDESCS 128 /**< Maximum number of descriptors for rx that the device can handle*/
67 #define DMARXDESCDELAY 4 /**< Number of rx descriptors to complete before a read will take place*/
68 #define DMATXBUFFS 32 /**< Number of buffers for Tx (memory to device). Combined with DMARXBUFFS must not exceed number of address pages.*/
69 #define DMATXDESCS 128 /**< Maximum number of descriptors for tx that the device can handle*/
70 #define DMATXDESCDELAY 4 /**< Number of rx descriptors to complete before a read will take place*/
71 #define DMABUFFSIZE 262144 /**< Size of each Rx or Tx buffer*/
72
73 /*Offsets for BAR0*/
74 #define CRA 0x00000000 /**< Base address of CRA port of the HIP*/
75 #define CRA_ATT 0x00001000 /**< Location of address translation table for Altera HIP (on CRA)*/
76 #define PIO0 0x00008000 /**< Base address of PIO0 relative to BAR0*/
77 #define PIO1 0x00008100 /**< Base address of PIO1 relative to BAR0*/
78 #define PIO2 0x00008200 /**< Base address of PIO2 relative to BAR0*/
79 #define PIO3 0x00008300 /**< Base address of PIO3 relative to BAR0*/
80 #define PIO4 0x00008400 /**< Base address of PIO4 relative to BAR0*/
81 #define PIO5 0x00008500 /**< Base address of PIO5 relative to BAR0*/
82
83 /*Offsets for BAR1*/
84 #define WRCSR 0x00000000 /**< Write DMA controller (FPGA to memory, radio rx) command and status registers*/
85 #define WRCSRSTAT 0x00000000 /**< Write DMA controller CSR - status register*/
86 #define WRCSRCTRL 0x00000004 /**< Write DMA controller CSR - control register*/
87 #define WRCSRFILLLEVEL 0x00000008 /**< Write DMA controller CSR - fill level of write descriptor buffer */
88 #define WRDESC 0x00001000 /**< Write DMA controller (FPGA to memory, radio rx) descriptor registers*/
89 #define WRDESCWRADDR 0x00001004 /**< Write DMA controller - Descriptor write address*/
90 #define WRDESCLEN 0x00001008 /**< Write DMA controller - Descriptor length*/
91 #define WRDESCCTRL 0x0000100C /**< Write DMA controller - Descriptor control*/
92 #define RDCSR 0x00002000 /**< Read DMA controller (memory to FPGA, radio tx) command and status registers*/
93 #define RDCSRSTAT 0x00002000 /**< Read DMA controller - status register*/
94 #define RDCSRCTRL 0x00002004 /**< Read DMA controller - control register*/
95 #define RDCSRFILLLEVEL 0x00002008 /**< Read DMA controller - fill level of read descriptor buffer */
96 #define RDDESC 0x00003000 /**< Read DMA controller (memory to FPGA, radio tx) descriptor registers*/
97 #define RDDESCRDADDR 0x00003000 /**< Read DMA controller - Descriptor read address*/
98 #define RDDESCLEN 0x00003008 /**< Read DMA controller - Descriptor length*/
99 #define RDDESCCTRL 0x0000300C /**< Read DMA controller - Descriptor control*/
100
101 /*Bits for WRCSR and RDCSR*/
102 #define CSR_STAT_RESETTING (1 << 6) /**< Status bit indicating that reset is still underway*/
103 #define CSR_CTRL_RESET (1 << 1) /**< Reset bit for the CSR control register*/
104
105 /*Bits for WRDESC and RDDESC*/
106 #define DESC_CTRL_GO (1 << 31) /**< Commit descriptor to buffer*/
107
108
109 /*Program macros*/
110
111 /**Given 2 numbers, return the larger one*/
112 #define MAX(a, b) ((a > b) ? a : b)
113
114 /**Given 2 numbers, return the smaller one*/
115 #define MIN(a, b) ((a < b) ? a : b)