AFHBA404
AFHBA404 connects ACQ2106 to PCI-Express
afhba_stream_drv.h
Go to the documentation of this file.
1 /*
2  * afhba_stream_drv.h
3  *
4  * Created on: 19 Jan 2015
5  * Author: pgm
6  */
7 
8 #ifndef AFHBA_STREAM_DRV_H_
9 #define AFHBA_STREAM_DRV_H_
10 
11 #include "rtm-t_ioctl.h"
12 
13 /* idea by John: make it a multiple of 3 to handle 96ch align case */
14 #define NBUFFERS 66
15 
16 #define NBUFFERS_FIFO NBUFFERS
17 
18 #define NBUFFERS_MASK 127
19 
20 #define BUFFER_LEN 0x100000
21 
22 
23 #define NSTATES 4
24 #define N_DRV_STATES 3
25 
26 #define AFDMAC_PAGE 0x400 /* 1K pages */
27 #define AFDMAC_LL_PAGE 64 /* page length in LL */
28 
29 #define AFDMAC_DESC_ADDR_MASK 0xfffffc00 /* base address */
30 
31 #define AFDMAC_DESC_WRITE 0x00000200 /* Write BIT */
32 #define AFDMAC_DESC_EOT 0x00000100 /* End Of Transfer interrupt */
33 
34 #define AFDMAC_DESC_LEN_MASK 0x000000f0 /* length (pages) */
35 #define AFDMAC_DESC_LEN_SHL 4
36 
37 #define AFDMAC_DESC_ID_MASK 0x0000000f /* ID 0..15 */
38 #define AFDMAC_DESC_ID 0x0000000f /* ID 0..15 */
39 
40 #define AFDMAC_DESCR(pa, pages, id) \
41  (((pa)&AFDMAC_DESC_ADDR_MASK)| \
42  ((((pages)-1) << AFDMAC_DESC_LEN_SHL)&AFDMAC_DESC_LEN_MASK)| \
43  (id))
44 
45 /* we wanted an elegant multi-vector solution, but we can only have one int */
46 #define MSI_DMA 0
47 #ifdef MSI_BLOCK_WORKS
48 #define MSI_UART 1
49 #else
50 #define MSI_UART 0
51 #endif
52 
54 
55 /* Linux RT kernel does not have dynamic debug enabled :-(
56  * define PGM_DEBUG_REGS_ACCESS to enable globally
57  */
58 #if defined(PGM_DEBUG_REGS_ACCESS)
59 #define DEV_DBG dev_info
60 #else
61 #define DEV_DBG dev_dbg
62 #endif
63 
64 
65 
67 
68  struct mutex list_mutex;
69 
70  struct BOTTLING_PLANT {
71  struct list_head list;
72  struct proc_dir_entry *proc;
73  }
75 
76 #define bp_empties bp[BS_EMPTY]
77 #define bp_filling bp[BS_FILLING]
78 #define bp_full bp[BS_FULL]
79 /* BS_FULL_APP : in list in path buffer */
80 
81 
82  int nbuffers;
84  struct HostBuffer *hbx; /* streaming host buffers [nbuffers] */
85 
86 
87  struct proc_dir_entry *proc_dir_root;
88 
89  struct JOB {
90  unsigned buffers_demand;
91  unsigned buffers_queued;
92  unsigned buffers_received;
93  unsigned ints;
96  unsigned int_previous;
97  unsigned rx_rate;
98  unsigned int_rate;
99  unsigned errors;
101 
104 
105  struct XLLC_DEF push_llc_def;
106  struct XLLC_DEF pull_llc_def;
107  int (* on_push_dma_timeout)(struct AFHBA_DEV *adev);
108  int (* on_pull_dma_timeout)(struct AFHBA_DEV *adev);
109  }
111  spinlock_t job_lock;
112 
115  unsigned *data_fifo_histo;
116  unsigned *desc_fifo_histo;
117 
118  void (*init_descriptors)(struct AFHBA_STREAM_DEV *sdev);
119 
120  struct WORK { /* ISR BH processing */
121  wait_queue_head_t w_waitq;
122  unsigned long w_to_do;
123  struct task_struct* w_task;
124 #define WORK_REQUEST 0
125  struct task_struct* mon_task;
126  } work;
127 
128  wait_queue_head_t return_waitq;
129 
131 
132  unsigned pid; /* pid of dma_read process */
133  int req_len; /* request len .. not part of job ? */
134  void (* onStopPull)(struct AFHBA_DEV *adev);
135  void (* onStopPush)(struct AFHBA_DEV *adev);
138 
139 
140 
142 
143  char irq_names[4][32];
144 
146  bool push_descr_ram; /* use ram descriptor on PUSH */
147  bool pull_descr_ram; /* use ram descriptor on PULL */
148  enum ZI_REPORT { ZI_BAD = -1, ZI_NULL = 0, ZI_GOOD = 1 } zi_report;
149 
150  int shot;
151  void *user; // opaque user buffer, kfree on close
152 };
153 
154 struct AO_BURST_DEV {
155  struct AO_BURST ao_burst;
156  wait_queue_head_t w_waitq;
157  struct task_struct* w_task;
158  unsigned srcdesc; // internal use only
159 };
160 #define AO_BURST_DEV(sdev) ((struct AO_BURST_DEV*)sdev->user)
161 
162 #define MIRROR(adev, ix) (adev->stream_dev->dma_regs[ix])
163 
164 void _afs_write_pcireg(struct AFHBA_DEV *adev, int regoff, u32 value);
165 u32 _afs_read_pcireg(struct AFHBA_DEV *adev, int regoff);
166 
167 int afs_comms_ready(struct AFHBA_DEV *adev);
168 
169 #define PCI_REG_WRITE(adev, regoff, value) \
170  _afs_write_pcireg(adev, regoff, value)
171 
172 #define PCI_REG_READ(adev, regoff) \
173  _afs_read_pcireg(adev, regoff)
174 
175 void _afs_write_dmareg(struct AFHBA_DEV *adev, int regoff, u32 value);
176 u32 _afs_read_dmareg(struct AFHBA_DEV *adev, int regoff);
177 
178 #define DMA_CTRL_WR(adev, value) \
179  _afs_write_dmareg(adev, DMA_CTRL, MIRROR(adev, DMA_CTRL) = value)
180 
181 
182 #define DMA_CTRL_RD(adev) \
183  (MIRROR(adev, DMA_CTRL) = _afs_read_dmareg(adev, DMA_CTRL))
184 
185 #define DMA_CTRL_CLR(adev, bits) do { \
186  u32 ctrl = DMA_CTRL_RD(adev); \
187  _afs_write_dmareg(adev, DMA_CTRL, MIRROR(adev, DMA_CTRL) &= ~(bits)); \
188  ctrl = DMA_CTRL_RD(adev); \
189  if ((ctrl&bits) != 0){ \
190  dev_err(pdev(adev), \
191  "DMA_CTRL_CLR sfp:%c wanted to clear:%08x but got %08x", \
192  adev->sfp+'A', bits, ctrl); \
193  } \
194 } while(0)
195 
196 #define DMA_CTRL_SET(adev, bits) do { \
197  u32 ctrl = DMA_CTRL_RD(adev); \
198  _afs_write_dmareg(adev, DMA_CTRL, MIRROR(adev, DMA_CTRL) |= (bits)); \
199  ctrl = DMA_CTRL_RD(adev); \
200  if ((ctrl&bits) == 0){ \
201  dev_err(pdev(adev), \
202  "DMA_CTRL_SET sfp:%c wanted to set:%08x but got %08x", \
203  adev->sfp+'A', bits, ctrl); \
204  } \
205 } while(0)
206 
207 
208 #define DMA_TEST_WR(adev, value) \
209  _afs_write_dmareg(adev, DMA_TEST, MIRROR(adev, DMA_TEST) = (value))
210 
211 #define DMA_TEST_RD(adev) \
212  (MIRROR(adev, DMA_TEST) = _afs_read_dmareg(adev, DMA_TEST))
213 
214 void _afs_write_comreg(struct AFHBA_DEV *adev, int regoff, u32 value);
215 
216 void __afs_dma_reset(struct AFHBA_DEV *adev, u32 dma_sel);
217 
218 
219 #define afs_dma_reset(adev, dma_sel) do { \
220  DEV_DBG(pdev(adev), "afs_dma_reset, called from %s %d", __FILE__, __LINE__); \
221  __afs_dma_reset(adev, dma_sel); \
222  } while(0)
223 
224 void __afs_start_dma(struct AFHBA_DEV *adev, u32 dma_sel);
225 
226 #define afs_start_dma(adev, dma_sel) do { \
227  DEV_DBG(pdev(adev), "afs_start_dma, called from %s %d", __FILE__, __LINE__); \
228  __afs_start_dma(adev, dma_sel); \
229  } while(0)
230 
231 void __afs_stop_dma(struct AFHBA_DEV *adev, u32 dma_sel);
232 
233 #define afs_stop_dma(adev, dma_sel) do { \
234  DEV_DBG(pdev(adev), "afs_stop_dma, called from %s %d", __FILE__, __LINE__); \
235  __afs_stop_dma(adev, dma_sel); \
236  } while(0)
237 
238 #define DMA_DATA_FIFSTA_RD(adev) _afs_read_dmareg(adev, DMA_DATA_FIFSTA)
239 #define DMA_DESC_FIFSTA_RD(adev) _afs_read_dmareg(adev, DMA_DESC_FIFSTA)
240 #define DMA_PUSH_DESC_STA_RD(adev) _afs_read_dmareg(adev, DMA_PUSH_DESC_STA)
241 #define DMA_PULL_DESC_STA_RD(adev) _afs_read_dmareg(adev, DMA_PULL_DESC_STA)
242 
243 
244 #define EMPTY1 0xee11ee11
245 #define EMPTY2 0x22ee22ee
246 
247 #define RTDMAC_DATA_FIFO_CNT 0x1000
248 #define RTDMAC_DESC_FIFO_CNT 0x1000
249 
250 #define HB_ENTRY(plist) list_entry(plist, struct HostBuffer, list)
251 
252 
253 
254 int afs_init_procfs(struct AFHBA_DEV *adev);
255 int afs_reset_buffers(struct AFHBA_DEV *adev);
256 int afs_comms_init(struct AFHBA_DEV *adev);
257 
258 
259 static inline char aurora_id(struct AFHBA_DEV *adev)
260 {
261  return adev->sfp - SFP_A + 'A';
262 }
263 
264 #endif /* AFHBA_STREAM_DRV_H_ */
AFHBA_STREAM_DEV::push_descr_ram
bool push_descr_ram
Definition: afhba_stream_drv.h:146
AFHBA_DEV::sfp
enum AFHBA_DEV::SFP sfp
AFHBA_STREAM_DEV::push_dma_timeouts
int push_dma_timeouts
Definition: afhba_stream_drv.h:113
__afs_stop_dma
void __afs_stop_dma(struct AFHBA_DEV *adev, u32 dma_sel)
Definition: afhba_stream_drv.c:563
AFHBA_STREAM_DEV::ZI_NULL
@ ZI_NULL
Definition: afhba_stream_drv.h:148
AFHBA_STREAM_DEV::nbuffers
int nbuffers
Definition: afhba_stream_drv.h:82
AFHBA_STREAM_DEV::hbx
struct HostBuffer * hbx
Definition: afhba_stream_drv.h:84
_afs_write_pcireg
void _afs_write_pcireg(struct AFHBA_DEV *adev, int regoff, u32 value)
Definition: afhba_stream_drv.c:322
N_DRV_STATES
#define N_DRV_STATES
Definition: afhba_stream_drv.h:24
AFHBA_STREAM_DEV::JOB::pull_llc_def
struct XLLC_DEF pull_llc_def
Definition: afhba_stream_drv.h:106
AFHBA_STREAM_DEV::WORK::w_to_do
unsigned long w_to_do
Definition: afhba_stream_drv.h:122
AO_BURST_DEV::srcdesc
unsigned srcdesc
Definition: afhba_stream_drv.h:158
AFHBA_STREAM_DEV::WORK::w_waitq
wait_queue_head_t w_waitq
Definition: afhba_stream_drv.h:121
AFHBA_STREAM_DEV::shot
int shot
Definition: afhba_stream_drv.h:150
AFHBA_STREAM_DEV::job_lock
spinlock_t job_lock
Definition: afhba_stream_drv.h:111
AFHBA_STREAM_DEV::bp
struct AFHBA_STREAM_DEV::BOTTLING_PLANT bp[N_DRV_STATES]
AFHBA_STREAM_DEV::JOB::buffers_discarded
unsigned buffers_discarded
Definition: afhba_stream_drv.h:100
AFHBA_STREAM_DEV::BOTTLING_PLANT
Definition: afhba_stream_drv.h:70
AFHBA_STREAM_DEV::ZI_REPORT
ZI_REPORT
Definition: afhba_stream_drv.h:148
AFHBA_STREAM_DEV::JOB::rx_buffers_previous
unsigned rx_buffers_previous
Definition: afhba_stream_drv.h:95
AFHBA_STREAM_DEV::dma_regs
u32 dma_regs[DMA_REGS_COUNT]
Definition: afhba_stream_drv.h:130
AFHBA_STREAM_DEV::pull_dma_timeouts
int pull_dma_timeouts
Definition: afhba_stream_drv.h:114
AFHBA_STREAM_DEV::JOB::push_llc_def
struct XLLC_DEF push_llc_def
Definition: afhba_stream_drv.h:105
NBUFFERS
#define NBUFFERS
Definition: afhba_stream_drv.h:14
AFHBA_STREAM_DEV::ZI_GOOD
@ ZI_GOOD
Definition: afhba_stream_drv.h:148
PS_OFF
@ PS_OFF
Definition: afhba_stream_drv.h:53
XLLC_DEF
Definition: rtm-t_ioctl.h:45
AFHBA_STREAM_DEV::req_len
int req_len
Definition: afhba_stream_drv.h:133
AFHBA_STREAM_DEV::pull_ram_cursor
int pull_ram_cursor
Definition: afhba_stream_drv.h:137
AFHBA_STREAM_DEV::WORK::mon_task
struct task_struct * mon_task
Definition: afhba_stream_drv.h:125
AFHBA_STREAM_DEV::irq_names
char irq_names[4][32]
Definition: afhba_stream_drv.h:143
AFHBA_STREAM_DEV::list_mutex
struct mutex list_mutex
Definition: afhba_stream_drv.h:68
AFHBA_STREAM_DEV::onStopPull
void(* onStopPull)(struct AFHBA_DEV *adev)
Definition: afhba_stream_drv.h:134
AFHBA_STREAM_DEV::desc_fifo_histo
unsigned * desc_fifo_histo
Definition: afhba_stream_drv.h:116
AFHBA_STREAM_DEV::init_descriptors
void(* init_descriptors)(struct AFHBA_STREAM_DEV *sdev)
Definition: afhba_stream_drv.h:118
AFHBA_STREAM_DEV::JOB::on_push_dma_timeout
int(* on_push_dma_timeout)(struct AFHBA_DEV *adev)
Definition: afhba_stream_drv.h:107
AFHBA_STREAM_DEV::proc_dir_root
struct proc_dir_entry * proc_dir_root
Definition: afhba_stream_drv.h:87
rtm-t_ioctl.h
AFHBA_STREAM_DEV::zi_report
enum AFHBA_STREAM_DEV::ZI_REPORT zi_report
AO_BURST
Definition: rtm-t_ioctl.h:67
AO_BURST_DEV::ao_burst
struct AO_BURST ao_burst
Definition: afhba_stream_drv.h:155
afs_comms_init
int afs_comms_init(struct AFHBA_DEV *adev)
Definition: afhba_stream_drv.c:749
AFHBA_STREAM_DEV::pull_descr_ram
bool pull_descr_ram
Definition: afhba_stream_drv.h:147
afs_init_procfs
int afs_init_procfs(struct AFHBA_DEV *adev)
Definition: afs_procfs.c:296
AFHBA_STREAM_DEV::JOB::please_stop
int please_stop
Definition: afhba_stream_drv.h:94
AFHBA_STREAM_DEV::JOB::int_previous
unsigned int_previous
Definition: afhba_stream_drv.h:96
AFHBA_STREAM_DEV::aurora_fail_detected
bool aurora_fail_detected
Definition: afhba_stream_drv.h:145
afs_comms_ready
int afs_comms_ready(struct AFHBA_DEV *adev)
Definition: afhba_stream_drv.c:773
AFHBA_STREAM_DEV::JOB::buffers_queued
unsigned buffers_queued
Definition: afhba_stream_drv.h:91
AFHBA_STREAM_DEV::JOB::buffers_received
unsigned buffers_received
Definition: afhba_stream_drv.h:92
AFHBA_STREAM_DEV::JOB::rx_rate
unsigned rx_rate
Definition: afhba_stream_drv.h:97
AFHBA_STREAM_DEV::JOB::catchup_histo
unsigned catchup_histo[NBUFFERS]
Definition: afhba_stream_drv.h:102
AFHBA_STREAM_DEV::JOB::int_rate
unsigned int_rate
Definition: afhba_stream_drv.h:98
_afs_read_pcireg
u32 _afs_read_pcireg(struct AFHBA_DEV *adev, int regoff)
Definition: afhba_stream_drv.c:332
AFHBA_STREAM_DEV::JOB
Definition: afhba_stream_drv.h:89
AFHBA_STREAM_DEV::return_waitq
wait_queue_head_t return_waitq
Definition: afhba_stream_drv.h:128
AFHBA_DEV
Definition: acq-fiber-hba.h:111
_afs_write_comreg
void _afs_write_comreg(struct AFHBA_DEV *adev, int regoff, u32 value)
Definition: afhba_stream_drv.c:296
AFHBA_STREAM_DEV::job
struct AFHBA_STREAM_DEV::JOB job
AFHBA_STREAM_DEV::onStopPush
void(* onStopPush)(struct AFHBA_DEV *adev)
Definition: afhba_stream_drv.h:135
AO_BURST_DEV::w_waitq
wait_queue_head_t w_waitq
Definition: afhba_stream_drv.h:156
AO_BURST_DEV
Definition: afhba_stream_drv.h:154
AFHBA_STREAM_DEV::JOB::dma_started
int dma_started
Definition: afhba_stream_drv.h:103
PS_PLEASE_STOP
@ PS_PLEASE_STOP
Definition: afhba_stream_drv.h:53
AFHBA_STREAM_DEV::JOB::errors
unsigned errors
Definition: afhba_stream_drv.h:99
AFHBA_STREAM_DEV::BOTTLING_PLANT::proc
struct proc_dir_entry * proc
Definition: afhba_stream_drv.h:72
AFHBA_STREAM_DEV::buffer_len
int buffer_len
Definition: afhba_stream_drv.h:83
AFHBA_STREAM_DEV::BOTTLING_PLANT::list
struct list_head list
Definition: afhba_stream_drv.h:71
AFHBA_STREAM_DEV::comms_init_done
int comms_init_done
Definition: afhba_stream_drv.h:141
AFHBA_STREAM_DEV::work
struct AFHBA_STREAM_DEV::WORK work
AFHBA_STREAM_DEV::WORK::w_task
struct task_struct * w_task
Definition: afhba_stream_drv.h:123
AFHBA_STREAM_DEV
Definition: afhba_stream_drv.h:66
_afs_read_dmareg
u32 _afs_read_dmareg(struct AFHBA_DEV *adev, int regoff)
Definition: afhba_stream_drv.c:313
__afs_dma_reset
void __afs_dma_reset(struct AFHBA_DEV *adev, u32 dma_sel)
Definition: afhba_stream_drv.c:555
AFHBA_STREAM_DEV::data_fifo_histo
unsigned * data_fifo_histo
Definition: afhba_stream_drv.h:115
__afs_start_dma
void __afs_start_dma(struct AFHBA_DEV *adev, u32 dma_sel)
Definition: afhba_stream_drv.c:570
AFHBA_STREAM_DEV::pid
unsigned pid
Definition: afhba_stream_drv.h:132
AFHBA_STREAM_DEV::ZI_BAD
@ ZI_BAD
Definition: afhba_stream_drv.h:148
AFHBA_STREAM_DEV::push_ram_cursor
int push_ram_cursor
Definition: afhba_stream_drv.h:136
PS_STOP_DONE
@ PS_STOP_DONE
Definition: afhba_stream_drv.h:53
afs_reset_buffers
int afs_reset_buffers(struct AFHBA_DEV *adev)
Definition: afhba_stream_drv.c:1390
HostBuffer
Definition: acq-fiber-hba.h:94
AFHBA_STREAM_DEV::user
void * user
Definition: afhba_stream_drv.h:151
AFHBA_STREAM_DEV::JOB::on_pull_dma_timeout
int(* on_pull_dma_timeout)(struct AFHBA_DEV *adev)
Definition: afhba_stream_drv.h:108
AFHBA_STREAM_DEV::WORK
Definition: afhba_stream_drv.h:120
AFHBA_STREAM_DEV::JOB::buffers_demand
unsigned buffers_demand
Definition: afhba_stream_drv.h:90
u32
unsigned u32
Definition: local.h:60
_afs_write_dmareg
void _afs_write_dmareg(struct AFHBA_DEV *adev, int regoff, u32 value)
Definition: afhba_stream_drv.c:304
AFHBA_STREAM_DEV::JOB::ints
unsigned ints
Definition: afhba_stream_drv.h:93
AO_BURST_DEV::w_task
struct task_struct * w_task
Definition: afhba_stream_drv.h:157
DMA_REGS_COUNT
@ DMA_REGS_COUNT
Definition: acq-fiber-hba.h:309