ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcdrv_pci.h
Go to the documentation of this file.
1#ifndef NGCDRV_PCI_H
2#define NGCDRV_PCI_H
3
4/******************************************************************************
5* E.S.O. - European Southern Observatory
6*
7* "@(#) $Id: ngcdrv_pci.h 354209 2022-03-29 10:19:20Z jstegmei $"
8*
9* who when what
10* -------- ---------- ----------------------------------------------
11* jstegmei 2005-02-16 created
12* jstegmei 2007-05-23 use PAGE_SIZE (instead of 4096) for NGCDRV_DMA_MAX
13* jstegmei 2008-01-10 added up-link configuration
14* jstegmei 2010-12-21 some functions renamed
15* jstegmei 2011-05-09 removed unused test-function declaration
16* jstegmei 2011-05-11 prepared interrupt post-processing capability
17* jstegmei 2011-05-15 added PCIe latency counter
18* jstegmei 2011-05-15 declared run-time counters as volatile
19* jstegmei 2011-05-16 added work-queue capability
20* jstegmei 2011-05-19 changed some type definitions
21* jstegmei 2011-06-28 activated DMA channel selection register
22* jstegmei 2013-03-09 GFP allocation flags for X86_64/32
23* jstegmei 2013-03-21 application specific work structure for work-queues
24* jstegmei 2014-07-04 create_proc_entry is deprecated since Linux 3.10
25* jstegmei 2014-07-08 re-integrated procfs interface
26* jstegmei 2016-05-23 VLTSW-12311 - reduced i/o-space from 1K to 256 bytes
27*/
28
29/************************************************************************
30 *
31 * ngcdrv_pci.h - ngcdrv driver
32 *
33 *----------------------------------------------------------------------
34 */
35
36/*
37 * Kernel and system headers
38 */
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/version.h>
42/*
43#include <linux/config.h>
44*/
45
46#if defined(CONFIG_SMP) && !defined(__SMP__)
47#define __SMP__
48#endif
49
50#ifdef CONFIG_DEVFS_FS
51/*
52 * Uncomment the following to have the automatic /dev file system supported
53 */
54/* #define NGCDRV_DEVFS */
55#endif
56
57#include <linux/kernel.h>
58#include <linux/compat.h>
59#include <linux/errno.h>
60#include <linux/types.h>
61#include <linux/major.h>
62#include <linux/fs.h>
63#ifdef NGCDRV_DEVFS
64#include <linux/devfs_fs_kernel.h>
65#endif
66#ifdef CONFIG_PROC_FS
67#include <linux/proc_fs.h>
68#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
69#define NGCDRV_PROC_FS_v1
70#else
71#include <linux/seq_file.h>
72#define NGCDRV_PROC_FS_v2
73#endif
74#endif
75#include <linux/mm.h>
76#include <linux/sched.h>
77#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
78#include <linux/sched/signal.h>
79#endif
80#include <linux/interrupt.h>
81#include <linux/pci.h>
82#include <linux/poll.h>
83#include <linux/delay.h>
84#include <linux/ioport.h> /* for request_region */
85#include <asm/io.h> /* for ioremap */
86#include <asm/uaccess.h> /* for copy_to/from_user */
87#include <asm/atomic.h> /* for sync-counter */
88
89/*
90 * Local headers
91 */
92#include "ngcdrv_tcb.h"
93#include "ngcdrv.h"
94
98#ifdef CONFIG_X86_64
99#define NGCDRV_GFP GFP_KERNEL|GFP_DMA32
100#else
101#define NGCDRV_GFP GFP_KERNEL
102#endif
103
107#define NGCDRV_MINOR2INST(minor) (minor >> 4)
108
112#define NGCDRV_MINOR2SUBDEV(minor) (minor & 0x0f)
113
117#define NGCDRV_MINOR(instance,i) ((instance << 4) | (i))
118
129
130/*
131 * Vendor-id and device-id - this is used to assign the
132 * device driver to our physical device
133 */
134#define NGCDRV_PCI_VENDOR_ID 0x10ee
135#define NGCDRV_PCI_DEVICE_ID 0x5043
136
137/*
138 * Supported board types (subsystem-id)
139 */
140#define NGCDRV_BTYPE_XILINX_PCI 0x1111
141#define NGCDRV_BTYPE_XILINX_PCIE 0x0007
142
143/*
144 * Latency
145 */
146/*#define NGCDRV_PCI_LATENCY (SMP_CACHE_BYTES >> 2) */
147/*#define NGCDRV_PCI_LATENCY 248 */
148
149/*
150 * Macros for done-count wrap around
151 */
152#define NGCDRV_WRAP_CNT 0xffffffff
153#define NGCDRV_INC(x) if(*x==NGCDRV_WRAP_CNT) {*x=0;} else {(*x)++;}
154#define NGCDRV_DEC(x) if(*x==0) {*x=NGCDRV_WRAP_CNT;} else {(*x)--;}
155#define NGCDRV_DIFF(x,a,b) if(b<a){*x=(NGCDRV_WRAP_CNT-a)+b;}else{*x=b-a;}
156
160#define NGCDRV_CFG_REG_SIZE 256
161
165#define NGCDRV_NUM_CHAN 4
166
167/*
168 * Communication port registers
169 */
170#define NGCDRV_REG_CTRL 0x1C
171#define NGCDRV_REG_CTRL_X1 0x2C
172#define NGCDRV_REG_CTRL_X2 0x3C
173#define NGCDRV_REG_CTRL_X3 0x4C
174#define NGCDRV_REG_STAT 0x14
175#define NGCDRV_REG_STAT_X1 0x24
176#define NGCDRV_REG_STAT_X2 0x34
177#define NGCDRV_REG_STAT_X3 0x44
178#define NGCDRV_REG_FIFO 0x10
179#define NGCDRV_REG_FIFO_X1 0x20
180#define NGCDRV_REG_FIFO_X2 0x30
181#define NGCDRV_REG_FIFO_X3 0x40
182#define NGCDRV_CTRL_CLRCOM 0x00000001
183#define NGCDRV_CTRL_CLRDMA 0x00000002
184#define NGCDRV_CTRL_TRANSFER 0x00000010
185#define NGCDRV_CTRL_RESET 0x00008000
186
187/*
188 * DMA registers
189 */
190#define NGCDRV_DMA_REG_DESCR 0x90
191#define NGCDRV_DMA_REG_CMD 0xA8
192#define NGCDRV_DMA_REG_IRQ 0x68
193#define NGCDRV_DMA_REG_LCNT 0xA4
194#define NGCDRV_DMA_REG_CHAN 0xC4
195
196/*
197 * Descriptor pointer register bits
198 */
199#define NGCDRV_DMA_DESCR_EOC 0x2
200#define NGCDRV_DMA_DESCR_INTR 0x4
201
202
203/*
204 * DMA command register bits
205 */
206#define NGCDRV_DMA_CMD_START 0x0002
207#define NGCDRV_DMA_CMD_ABORT 0x0004
208#define NGCDRV_DMA_CMD_INTR_CLR 0x0008
209#define NGCDRV_DMA_CMD_LCNT_MODE 0x0100
210#define NGCDRV_DMA_CMD_LCNT_STOP 0x0200
211#define NGCDRV_DMA_CMD_LCNT_CLR 0x0400
212
213/*
214 * DMA interrupt register bits
215 */
216#define NGCDRV_DMA_IRQ (1<<21)
217
218/*
219 * DMA FIFO
220 */
221#define NGCDRV_DMA_REG_FIFO NGCDRV_REG_CTRL
222#define NGCDRV_DMA_FIFO_CLR NGCDRV_CTRL_CLRDMA
223
228#define NGCDRV_DMA_MAX PAGE_SIZE
229
230/*
231 * DMA address space
232 */
233#define NGCDRV_DMA_KERNEL 0
234#define NGCDRV_DMA_USER 1
235
239#define NGCDRV_USE_VAR(x) do {(void)(x);} while (0)
240
244typedef struct
245{
246 unsigned int pid;
247#ifdef CONFIG_DEVFS_FS
248 devfs_handle_t devfs;
249#endif
251
255typedef struct {
256 uint32_t addr;
257 uint32_t addr_high;
258 uint32_t count;
259 uint32_t descptr;
261
262/*
263 * Configuration register type
264 */
265typedef uint8_t ngcdrv_reg_t;
266
270typedef struct
271{
272 struct work_struct work;
273 unsigned long data;
275
279typedef struct
280{
281 uint32_t mode;
282 uint32_t mode_req;
283 struct tasklet_struct tasklet;
284 struct workqueue_struct *wq;
286 int init;
288 void **dma_buffer;
289 uint32_t dma_buffer_num;
291 uint32_t dma_rn;
292 unsigned long dma_rsize;
293 volatile uint32_t done_count;
294 volatile uint32_t dma_count;
295 volatile uint32_t idx_in;
296 volatile uint32_t idx_out;
297 volatile uint32_t scnt;
298 uint32_t snum;
299 void *mem;
301 int taskId;
306
310typedef struct
311{
313 uint32_t tmo;
314 uint32_t rstLink;
315 uint32_t routeThrough;
316 uint32_t *fifoBuf;
321
325typedef struct
326{
328 volatile uint32_t done_count;
329 uint32_t sg_len;
330 spinlock_t lock;
331 volatile uint32_t overflow;
335 int valid;
336 void **km_buffer;
337 uint32_t km_buffer_num;
338 uint32_t km_buffer_size;
339 uint32_t km_rn;
340 unsigned long km_rsize;
341 void **buffer;
342 uint32_t buffer_num;
343 uint32_t buffer_size;
344 uint32_t rn;
345 unsigned rsize;
347 uint32_t descr_num;
348 unsigned long descr_addr;
349 struct semaphore sem_wake;
350 struct semaphore sem_buf;
351 wait_queue_head_t wait_queue;
353 uint32_t lcnt_mode;
354 atomic_t sync_cnt;
355 uint32_t sync_mode;
357
361typedef struct
362{
363 struct pci_dev* pcidev;
364 int id;
365 char name[32];
367 caddr_t reg_page;
370 int irq;
375 unsigned long irq_count;
378 int btype;
380 spinlock_t lock;
381
382 /*
383 * These are "volatile" because interrupt handlers might change them
384 * or, in the case of the registers, they talk to memory-mapped IO.
385 */
386 volatile const char* err_status;
387 volatile unsigned int dma_errors;
388 volatile unsigned int dma_report;
389
390} ngcdrv_t;
391
395#ifndef SA_SHIRQ
396#define NGCDRV_IRQ_SHARED IRQF_SHARED
397#else
398#define NGCDRV_IRQ_SHARED SA_SHIRQ
399#endif
400
401#endif /* !NGCDRV_PCI_H */
402
403
#define NGCDRV_MAX_PARAM
Definition ngcdrv.h:91
#define NGCDRV_NUM_CHAN
Definition ngcdrv_pci.h:165
uint8_t ngcdrv_reg_t
Definition ngcdrv_pci.h:265
ngcdrv_minors
Definition ngcdrv_pci.h:122
@ COMX3_MINOR
Definition ngcdrv_pci.h:126
@ COM_MINOR
Definition ngcdrv_pci.h:123
@ DMA_MINOR
Definition ngcdrv_pci.h:127
@ COMX2_MINOR
Definition ngcdrv_pci.h:125
@ COMX1_MINOR
Definition ngcdrv_pci.h:124
#define NGCDRV_MAX_TCB
Definition ngcdrv_tcb.h:68
Definition ngcdrv_pci.h:311
ngcdrv_state_t state
Definition ngcdrv_pci.h:312
volatile ngcdrv_reg_t * regFifo
Definition ngcdrv_pci.h:319
uint32_t tmo
Definition ngcdrv_pci.h:313
volatile ngcdrv_reg_t * regStat
Definition ngcdrv_pci.h:318
uint32_t rstLink
Definition ngcdrv_pci.h:314
volatile ngcdrv_reg_t * regCtrl
Definition ngcdrv_pci.h:317
uint32_t routeThrough
Definition ngcdrv_pci.h:315
uint32_t * fifoBuf
Definition ngcdrv_pci.h:316
Definition ngcdrv_pci.h:255
uint32_t count
Definition ngcdrv_pci.h:258
uint32_t addr_high
Definition ngcdrv_pci.h:257
uint32_t descptr
Definition ngcdrv_pci.h:259
uint32_t addr
Definition ngcdrv_pci.h:256
Definition ngcdrv_pci.h:326
volatile uint32_t overflow
Definition ngcdrv_pci.h:331
ngcdrv_descr_t ** descriptors
Definition ngcdrv_pci.h:346
ngcdrv_state_t state
Definition ngcdrv_pci.h:327
spinlock_t lock
Definition ngcdrv_pci.h:330
int sustained
Definition ngcdrv_pci.h:334
uint32_t rn
Definition ngcdrv_pci.h:344
uint32_t lcnt_mode
Definition ngcdrv_pci.h:353
wait_queue_head_t wait_queue
Definition ngcdrv_pci.h:351
struct semaphore sem_buf
Definition ngcdrv_pci.h:350
int dma_inprogress
Definition ngcdrv_pci.h:333
void ** km_buffer
Definition ngcdrv_pci.h:336
unsigned long descr_addr
Definition ngcdrv_pci.h:348
void ** buffer
Definition ngcdrv_pci.h:341
struct semaphore sem_wake
Definition ngcdrv_pci.h:349
unsigned long km_rsize
Definition ngcdrv_pci.h:340
uint32_t sync_mode
Definition ngcdrv_pci.h:355
uint32_t km_buffer_size
Definition ngcdrv_pci.h:338
atomic_t sync_cnt
Definition ngcdrv_pci.h:354
ngcdrv_ipp_t ipp
Definition ngcdrv_pci.h:352
int valid
Definition ngcdrv_pci.h:335
uint32_t sg_len
Definition ngcdrv_pci.h:329
uint32_t km_buffer_num
Definition ngcdrv_pci.h:337
int aborted
Definition ngcdrv_pci.h:332
uint32_t buffer_size
Definition ngcdrv_pci.h:343
unsigned rsize
Definition ngcdrv_pci.h:345
uint32_t km_rn
Definition ngcdrv_pci.h:339
volatile uint32_t done_count
Definition ngcdrv_pci.h:328
uint32_t buffer_num
Definition ngcdrv_pci.h:342
uint32_t descr_num
Definition ngcdrv_pci.h:347
Definition ngcdrv_pci.h:280
int init
Definition ngcdrv_pci.h:286
volatile uint32_t scnt
Definition ngcdrv_pci.h:297
volatile uint32_t done_count
Definition ngcdrv_pci.h:293
volatile uint32_t dma_count
Definition ngcdrv_pci.h:294
int realloc
Definition ngcdrv_pci.h:304
void ** dma_buffer
Definition ngcdrv_pci.h:288
uint32_t dma_rn
Definition ngcdrv_pci.h:291
volatile uint32_t idx_out
Definition ngcdrv_pci.h:296
void * mem
Definition ngcdrv_pci.h:299
volatile uint32_t idx_in
Definition ngcdrv_pci.h:295
int32_t param[NGCDRV_MAX_PARAM]
Definition ngcdrv_pci.h:302
uint32_t dma_buffer_num
Definition ngcdrv_pci.h:289
uint32_t dma_buffer_size
Definition ngcdrv_pci.h:290
uint32_t mode
Definition ngcdrv_pci.h:281
unsigned long dma_rsize
Definition ngcdrv_pci.h:292
ngcdrv_tcb_t * task
Definition ngcdrv_pci.h:300
uint32_t snum
Definition ngcdrv_pci.h:298
int enabled
Definition ngcdrv_pci.h:287
uint32_t mode_req
Definition ngcdrv_pci.h:282
struct workqueue_struct * wq
Definition ngcdrv_pci.h:284
struct tasklet_struct tasklet
Definition ngcdrv_pci.h:283
ngcdrv_tcb_t * task_reg[NGCDRV_MAX_TCB]
Definition ngcdrv_pci.h:303
ngcdrv_work_t work
Definition ngcdrv_pci.h:285
int taskId
Definition ngcdrv_pci.h:301
Definition ngcdrv_pci.h:245
unsigned int pid
Definition ngcdrv_pci.h:246
Definition ngcdrv_pci.h:362
int irq
Definition ngcdrv_pci.h:370
int dma_width
Definition ngcdrv_pci.h:379
spinlock_t lock
Definition ngcdrv_pci.h:380
volatile unsigned int dma_report
Definition ngcdrv_pci.h:388
int btype
Definition ngcdrv_pci.h:378
ngcdrv_dma_t DMA
Definition ngcdrv_pci.h:369
volatile unsigned int dma_errors
Definition ngcdrv_pci.h:387
int irq_realtime
Definition ngcdrv_pci.h:371
int irq_same
Definition ngcdrv_pci.h:373
int version
Definition ngcdrv_pci.h:377
char name[32]
Definition ngcdrv_pci.h:365
int id
Definition ngcdrv_pci.h:364
volatile const char * err_status
Definition ngcdrv_pci.h:386
int irq_sharable
Definition ngcdrv_pci.h:372
unsigned long irq_count
Definition ngcdrv_pci.h:375
int latency
Definition ngcdrv_pci.h:376
ngcdrv_com_t COM[NGCDRV_NUM_CHAN]
Definition ngcdrv_pci.h:368
volatile ngcdrv_reg_t * reg_base
Definition ngcdrv_pci.h:366
struct pci_dev * pcidev
Definition ngcdrv_pci.h:363
caddr_t reg_page
Definition ngcdrv_pci.h:367
int irq_init
Definition ngcdrv_pci.h:374
Definition ngcdrv_tcb.h:56
Definition ngcdrv_pci.h:271
unsigned long data
Definition ngcdrv_pci.h:273
struct work_struct work
Definition ngcdrv_pci.h:272