RTEMS 6.1-rc5
Loading...
Searching...
No Matches
grspw_pkt.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * GRSPW/GRSPW2 SpaceWire Kernel Library Interface
5 *
6 * COPYRIGHT (c) 2011
7 * Cobham Gaisler AB
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __GRSPW_PKT_H__
32#define __GRSPW_PKT_H__
33
34struct grspw_pkt;
35
36/* Maximum number of GRSPW devices supported by driver */
37#define GRSPW_MAX 32
38
39/* Weak overridable variable the user can use to define the worker-task
40 * priority (0..255) or to disable (-1) the creation of the worker-task
41 * and the message queue to save space */
42extern int grspw_work_task_priority;
43
44#ifndef GRSPW_PKT_FLAGS
45#define GRSPW_PKT_FLAGS
46/*** TX Packet flags ***/
47
48/* Enable IRQ generation */
49#define TXPKT_FLAG_IE 0x0040
50
51/* Enable Header CRC generation (if CRC is available in HW)
52 * Header CRC will be appended (one byte at end of header)
53 */
54#define TXPKT_FLAG_HCRC 0x0100
55
56/* Enable Data CRC generation (if CRC is available in HW)
57 * Data CRC will be appended (one or two byte at end of packet, depending on
58 * Data CRC type)
59 */
60#define TXPKT_FLAG_DCRC 0x0200
61
62/* Data CRC type */
63#define TXPKT_FLAG_DCRCT_MASK 0x0c00
64/* RMAP CRC. 1 byte */
65#define TXPKT_FLAG_DCRCT_RMAP 0x0000
66/* CCSDS/CCITT CRC-16. 2 byte */
67#define TXPKT_FLAG_DCRCT_CCSDS 0x0400
68/* 16-bit ISO-checksum (J.G. Fletcher, ISO 8473-1:1998). 2 byte */
69#define TXPKT_FLAG_DCRCT_ISO16 0x0800
70
71/* Control how many bytes the beginning of the Header
72 * the CRC should not be calculated for */
73#define TXPKT_FLAG_NOCRC_MASK 0x0000000f
74#define TXPKT_FLAG_NOCRC_LEN0 0x00000000
75#define TXPKT_FLAG_NOCRC_LEN1 0x00000001
76#define TXPKT_FLAG_NOCRC_LEN2 0x00000002
77#define TXPKT_FLAG_NOCRC_LEN3 0x00000003
78#define TXPKT_FLAG_NOCRC_LEN4 0x00000004
79#define TXPKT_FLAG_NOCRC_LEN5 0x00000005
80#define TXPKT_FLAG_NOCRC_LEN6 0x00000006
81#define TXPKT_FLAG_NOCRC_LEN7 0x00000007
82#define TXPKT_FLAG_NOCRC_LEN8 0x00000008
83#define TXPKT_FLAG_NOCRC_LEN9 0x00000009
84#define TXPKT_FLAG_NOCRC_LENa 0x0000000a
85#define TXPKT_FLAG_NOCRC_LENb 0x0000000b
86#define TXPKT_FLAG_NOCRC_LENc 0x0000000c
87#define TXPKT_FLAG_NOCRC_LENd 0x0000000d
88#define TXPKT_FLAG_NOCRC_LENe 0x0000000e
89#define TXPKT_FLAG_NOCRC_LENf 0x0000000f
90
91#define TXPKT_FLAG_INPUT_MASK (TXPKT_FLAG_NOCRC_MASK | TXPKT_FLAG_IE | \
92 TXPKT_FLAG_HCRC | TXPKT_FLAG_DCRC | \
93 TXPKT_FLAG_DCRCT_MASK)
94
95/* Marks if packet was transmitted or not */
96#define TXPKT_FLAG_TX 0x4000
97
98/* Link Error */
99#define TXPKT_FLAG_LINKERR 0x8000
100
101#define TXPKT_FLAG_OUTPUT_MASK (TXPKT_FLAG_TX | TXPKT_FLAG_LINKERR)
102
103/*** RX Packet Flags ***/
104
105/* Enable IRQ generation */
106#define RXPKT_FLAG_IE 0x0010
107
108#define RXPKT_FLAG_INPUT_MASK (RXPKT_FLAG_IE)
109
110/* Packet was truncated */
111#define RXPKT_FLAG_TRUNK 0x0800
112/* Data CRC error (only valid if RMAP CRC is enabled) */
113#define RXPKT_FLAG_DCRC 0x0400
114/* Header CRC error (only valid if RMAP CRC is enabled) */
115#define RXPKT_FLAG_HCRC 0x0200
116/* Error in End-of-Packet */
117#define RXPKT_FLAG_EEOP 0x0100
118/* Marks if packet was recevied or not */
119#define RXPKT_FLAG_RX 0x8000
120
121#define RXPKT_FLAG_OUTPUT_MASK (RXPKT_FLAG_TRUNK | RXPKT_FLAG_DCRC | \
122 RXPKT_FLAG_HCRC | RXPKT_FLAG_EEOP)
123
124/*** General packet flag options ***/
125
126/* Translate Hdr and/or Payload address */
127#define PKT_FLAG_TR_DATA 0x1000
128#define PKT_FLAG_TR_HDR 0x2000
129/* All General options */
130#define PKT_FLAG_MASK 0x3000
131
132#endif
133/* GRSPW RX/TX Packet structure.
134 *
135 * - For RX the 'hdr' and 'hlen' fields are not used, they are not written
136 * by driver.
137 *
138 * - The 'pkt_id' field is untouched by driver, it is intended for packet
139 * numbering or user-custom data.
140 *
141 * - The last packet in a list must have 'next' set to NULL.
142 *
143 * - data and hdr pointers are written without modification to hardware,
144 * this means that caller must do address translation to hardware
145 * address itself.
146 *
147 * - the 'flags' field are interpreted differently depending on transfer
148 * type (RX/TX). See XXPKT_FLAG_* options above.
149 */
150struct grspw_pkt {
151 struct grspw_pkt *next; /* Next packet in list. NULL if last packet */
152 unsigned int pkt_id; /* User assigned ID (not touched by driver) */
153 unsigned short flags; /* RX/TX Options and status */
154 unsigned char reserved; /* Reserved, must be zero */
155 unsigned char hlen; /* Length of Header Buffer (only TX) */
156 unsigned int dlen; /* Length of Data Buffer */
157 void *data; /* 4-byte or byte aligned depends on HW */
158 void *hdr; /* 4-byte or byte aligned depends on HW (only TX) */
159};
160
161/* GRSPW SpaceWire Packet List */
163 struct grspw_pkt *head;
164 struct grspw_pkt *tail;
165};
166
167/* SpaceWire Link State */
168typedef enum {
169 SPW_LS_ERRRST = 0,
170 SPW_LS_ERRWAIT = 1,
171 SPW_LS_READY = 2,
172 SPW_LS_STARTED = 3,
173 SPW_LS_CONNECTING = 4,
174 SPW_LS_RUN = 5
175} spw_link_state_t;
176
177/* Address Configuration */
179 /* Ignore address field and put all received packets to first
180 * DMA channel.
181 */
182 int promiscuous;
183
184 /* Default Node Address and Mask */
185 unsigned char def_addr;
186 unsigned char def_mask;
187 /* DMA Channel custom Node Address and Mask */
188 struct {
189 char node_en; /* Enable Separate Addr */
190 unsigned char node_addr; /* Node address */
191 unsigned char node_mask; /* Node address mask */
192 } dma_nacfg[4];
193};
194
195/* Hardware Support in GRSPW Core */
197 char rmap; /* If RMAP in HW is available */
198 char rmap_crc; /* If RMAP CRC is available */
199 char rx_unalign; /* RX unaligned (byte boundary) access allowed*/
200 char nports; /* Number of Ports (1 or 2) */
201 char ndma_chans; /* Number of DMA Channels (1..4) */
202 char strip_adr; /* Hardware can strip ADR from packet data */
203 char strip_pid; /* Hardware can strip PID from packet data */
204 int hw_version; /* GRSPW Hardware Version */
205 char reserved[2];
206 char irq; /* SpW Distributed Interrupt available if 1 */
207 char irq_num; /* Number of interrupts that can be generated */
208 char itmr_width; /* SpW Intr. ISR timers bit width. 0=no timer */
209 char ccsds_crc; /* CCSDS CRC-16 and 16-bit ISO is available */
210};
211
213 int irq_cnt;
214 int err_credit;
215 int err_eeop;
216 int err_addr;
217 int err_parity;
218 int err_disconnect;
219 int err_escape;
220 int err_wsync; /* only in GRSPW1 */
221};
222
223/* grspw_link_ctrl() options */
224#define LINKOPTS_ENABLE 0x0000
225#define LINKOPTS_DISABLE 0x0001
226#define LINKOPTS_START 0x0002
227#define LINKOPTS_AUTOSTART 0x0004
228#define LINKOPTS_DIS_ONERR 0x0008 /* Disable DMA transmitter on link error
229 * Controls LE bit in DMACTRL register.
230 */
231#define LINKOPTS_DIS_ON_CE 0x0020000/* Disable Link on Credit error */
232#define LINKOPTS_DIS_ON_ER 0x0040000/* Disable Link on Escape error */
233#define LINKOPTS_DIS_ON_DE 0x0080000/* Disable Link on Disconnect error */
234#define LINKOPTS_DIS_ON_PE 0x0100000/* Disable Link on Parity error */
235#define LINKOPTS_DIS_ON_WE 0x0400000/* Disable Link on write synchonization
236 * error (GRSPW1 only)
237 */
238#define LINKOPTS_DIS_ON_EE 0x1000000/* Disable Link on Early EOP/EEP error*/
239
240/*#define LINKOPTS_TICK_OUT_IRQ 0x0100*//* Enable Tick-out IRQ */
241#define LINKOPTS_EIRQ 0x0200 /* Enable Error Link IRQ */
242
243#define LINKOPTS_MASK 0x15e020f/* All above options */
244#define LINKOPTS_MASK_DIS_ON 0x15e0000/* All disable link on error options
245 * On a certain error the link disable
246 * bit will be written and the work
247 * task will call dma_stop() for all
248 * channels.
249 */
250
251#define LINKSTS_CE 0x002 /* Credit error */
252#define LINKSTS_ER 0x004 /* Escape error */
253#define LINKSTS_DE 0x008 /* Disconnect error */
254#define LINKSTS_PE 0x010 /* Parity error */
255#define LINKSTS_WE 0x040 /* Write synchonization error (GRSPW1 only) */
256#define LINKSTS_IA 0x080 /* Invalid address */
257#define LINKSTS_EE 0x100 /* Early EOP/EEP */
258#define LINKSTS_MASK 0x1de
259
260/* grspw_tc_ctrl() options */
261#define TCOPTS_EN_RXIRQ 0x0001 /* Tick-Out IRQ */
262#define TCOPTS_EN_TX 0x0004
263#define TCOPTS_EN_RX 0x0008
264
265/* grspw_ic_ctrl() options:
266 * Corresponds code duplicatingly to GRSPW_CTRL_XX_BIT defines
267 */
268#define ICOPTS_INTNUM (0x1f << 27)
269#define ICOPTS_EN_SPWIRQ_ON_EE (1 << 24)
270#define ICOPTS_EN_SPWIRQ_ON_IA (1 << 23)
271#define ICOPTS_EN_PRIO (1 << 22)
272#define ICOPTS_EN_TIMEOUTIRQ (1 << 20)
273#define ICOPTS_EN_ACKIRQ (1 << 19)
274#define ICOPTS_EN_TICKOUTIRQ (1 << 18)
275#define ICOPTS_EN_RX (1 << 17)
276#define ICOPTS_EN_TX (1 << 16)
277#define ICOPTS_BASEIRQ (0x1f << 8)
278#define ICOPTS_EN_FLAGFILTER (1 << 0) /* NOTE: Not in icctrl. CTRL.bit12 */
279
280/* grspw_ic_rlisr() and grspw_ic_rlintack() */
281#define ICRELOAD_EN (1 << 31)
282#define ICRELOAD_MASK 0x7fffffff
283
284/* grspw_rmap_ctrl() options */
285#define RMAPOPTS_EN_RMAP 0x0001
286#define RMAPOPTS_EN_BUF 0x0002
287
288/* grspw_dma_config.flags options */
289#define DMAFLAG_NO_SPILL 0x0001 /* See HW doc DMA-CTRL NS bit */
290#define DMAFLAG_RESV1 0x0002 /* HAS NO EFFECT */
291#define DMAFLAG_STRIP_ADR 0x0004 /* See HW doc DMA-CTRL SA bit */
292#define DMAFLAG_STRIP_PID 0x0008 /* See HW doc DMA-CTRL SP bit */
293#define DMAFLAG_RESV2 0x0010 /* HAS NO EFFECT */
294#define DMAFLAG_MASK (DMAFLAG_NO_SPILL|DMAFLAG_STRIP_ADR|DMAFLAG_STRIP_PID)
295/* grspw_dma_config.flags misc options (not shifted internally) */
296#define DMAFLAG2_TXIE 0x00100000 /* See HW doc DMA-CTRL TI bit.
297 * Used to enable TX DMA interrupt
298 * when tx_irq_en_cnt=0.
299 */
300#define DMAFLAG2_RXIE 0x00200000 /* See HW doc DMA-CTRL RI bit.
301 * Used to enable RX DMA interrupt
302 * when rx_irq_en_cnt=0.
303 */
304/* Defines how the ISR will disable RX/TX DMA interrupt source when a DMA RX/TX
305 * interrupt has happended. DMA Error Interrupt always disables both RX/TX DMA
306 * interrupt. By default both RX/TX IRQs are disabled when either a RX, TX or
307 * both RX/TX DMA interrupt has been requested. The work-task, custom
308 * application handler or custom ISR handler is responsible to re-enable
309 * DMA interrupts.
310 */
311#define DMAFLAG2_IRQD_SRC 0x01000000 /* Disable triggering RX/TX source */
312#define DMAFLAG2_IRQD_NONE 0x00c00000 /* Never disable RX/TX IRQ in ISR */
313#define DMAFLAG2_IRQD_BOTH 0x00000000 /* Always disable both RX/TX sources */
314#define DMAFLAG2_IRQD_MASK 0x01c00000 /* Mask of options */
315#define DMAFLAG2_IRQD_BIT 22
316
317#define DMAFLAG2_MASK (DMAFLAG2_TXIE | DMAFLAG2_RXIE | DMAFLAG2_IRQD_MASK)
318
319struct grspw_dma_config {
320 int flags; /* DMA config flags, see DMAFLAG1&2_* options */
321 int rxmaxlen; /* RX Max Packet Length */
322 int rx_irq_en_cnt; /* Enable RX IRQ every cnt descriptors */
323 int tx_irq_en_cnt; /* Enable TX IRQ every cnt descriptors */
324};
325
326/* Statistics per DMA channel */
327struct grspw_dma_stats {
328 /* IRQ Statistics */
329 int irq_cnt; /* Number of DMA IRQs generated by channel */
330
331 /* Descriptor Statistics */
332 int tx_pkts; /* Number of Transmitted packets */
333 int tx_err_link; /* Number of Transmitted packets with Link Error*/
334 int rx_pkts; /* Number of Received packets */
335 int rx_err_trunk; /* Number of Received Truncated packets */
336 int rx_err_endpkt; /* Number of Received packets with bad ending */
337
338 /* Diagnostics to help developers sizing their number buffers to avoid
339 * out-of-buffers or other phenomenons.
340 */
341 int send_cnt_min; /* Minimum number of packets in TX SEND Q */
342 int send_cnt_max; /* Maximum number of packets in TX SEND Q */
343 int tx_sched_cnt_min; /* Minimum number of packets in TX SCHED Q */
344 int tx_sched_cnt_max; /* Maximum number of packets in TX SCHED Q */
345 int sent_cnt_max; /* Maximum number of packets in TX SENT Q */
346 int tx_work_cnt; /* Times the work thread processed TX BDs */
347 int tx_work_enabled; /* No. RX BDs enabled by work thread */
348
349 int ready_cnt_min; /* Minimum number of packets in RX READY Q */
350 int ready_cnt_max; /* Maximum number of packets in RX READY Q */
351 int rx_sched_cnt_min; /* Minimum number of packets in RX SCHED Q */
352 int rx_sched_cnt_max; /* Maximum number of packets in RX SCHED Q */
353 int recv_cnt_max; /* Maximum number of packets in RX RECV Q */
354 int rx_work_cnt; /* Times the work thread processed RX BDs */
355 int rx_work_enabled; /* No. RX BDs enabled by work thread */
356};
357
358/* ISR message sending call back. Compatible with rtems_message_queue_send().
359 * The 'buf' parameter has a pointer to a WORK-TASK message defined by the
360 * WORK_* macros below. The message indicates what GRSPW device operations
361 * are pending, thus what caused the interrupt.
362 *
363 * \param data defined by grspw_work_config.msgisr_arg, default a rtems_id.
364 * \param buf Pointer to a 32-bit message word
365 * \param n Always 4 (byte size of buf).
366 */
367typedef int (*grspw_msgqisr_t)(void *data, unsigned int *buf, unsigned int n);
368
369/* Work message definitions, the int sent to *buf
370 * Bits 31..24: reserved.
371 * Bits 23..16: GRSPW device number message is associated with.
372 * Bit 15: reserved.
373 * Bit 14: work-task shall delete message queue on exit.
374 * Bit 13: work-task shall exit and delete itself.
375 * Bit 12: link error - shut down all DMA operations (stop DMA channels).
376 * Bit 11..8: Indicats DMA error on DMA channel 3..0.
377 * Bit 7..0: Indicats RX and/or TX packets completed on channel 3..0.
378 */
379#define WORK_NONE 0
380#define WORK_SHUTDOWN 0x1000 /* Signal shut down */
381#define WORK_QUIT_TASK 0x2000 /* Work task shall exit (delete itself) */
382#define WORK_FREE_MSGQ 0x4000 /* Delete MsgQ (valid when WORK_QUIT_TASK) */
383#define WORK_DMA(chan, rxtx) (((rxtx) & 0x3) << ((chan) * 2))
384#define WORK_DMA_TX(chan) WORK_DMA(chan, 1)
385#define WORK_DMA_RX(chan) WORK_DMA(chan, 2)
386#define WORK_DMA_ER(chan) (0x1 << ((chan) + 8))
387#define WORK_DMA_MASK 0xfff /* max 4 channels all work */
388#define WORK_DMA_TX_MASK 0x055 /* max 4 channels TX work */
389#define WORK_DMA_RX_MASK 0x0aa /* max 4 channels RX work */
390#define WORK_DMA_ER_MASK 0xf00 /* max 4 channels Error work */
391#define WORK_DMA_CHAN_MASK(chan) (WORK_DMA_ER(chan) | WORK_DMA(chan, 0x3))
392#define WORK_CORE_BIT 16
393#define WORK_CORE_MASK 0x00ff0000
394#define WORK_CORE(device) ((device) << WORK_CORE_BIT)
395
396/* Message Q used to send messages to work task */
397struct grspw_work_config {
398 grspw_msgqisr_t msgisr;
399 void *msgisr_arg; /* example: rtems_id to Msg Q */
400};
401
402extern void grspw_initialize_user(
403 /* Callback every time a GRSPW device is found. Args: DeviceIndex */
404 void *(*devfound)(int),
405 /* Callback every time a GRSPW device is removed. Args:
406 * int = DeviceIndex
407 * void* = Return Value from devfound()
408 */
409 void (*devremove)(int,void*)
410 );
411
412/* Creates a MsgQ (optional) and spawns a worker task associated with the
413 * message Q. The task can also be associated with a custom msgQ if *msgQ.
414 * is non-zero.
415 *
416 * \param prio Task priority, set to -1 for default.
417 * \param stack Task stack size, set to 0 for default.
418 * \param msgQ pMsgQ=NULL: illegal,
419 * pMsqQ==0: create new MsgQ with task and place in *pMsgQ,
420 * *pmsqQ!=0: pointer to MsgQ used for task.
421 * \param msgMax Maximum number of messages, set to 0 for default.
422 * \return 0 on failure, task id on success.
423 */
424extern rtems_id grspw_work_spawn(int prio, int stack, rtems_id *pMsgQ, int msgMax);
425
426/* Free task associated with message queue and optionally also the message
427 * queue itself. The message queue is deleted by the work task and is therefore
428 * delayed until it the work task resumes its execution.
429 */
430extern rtems_status_code grspw_work_free(rtems_id msgQ, int freeMsgQ);
431
432/* Configure a GRSPW device Work task and Message Q set up.
433 * This affects messages to:
434 * - DMA AHB error interrupt handling (mandatory)
435 * - Link status interrupt handling (optional)
436 * - RX DMA, defaults to common msgQ (configured per DMA channel)
437 */
438extern void grspw_work_cfg(void *d, struct grspw_work_config *wc);
439
440/* Work-task function, called only from the work task. The function is provided
441 * as a way for the user to create its own work tasks.
442 * The argument determines which message queue the task shall read its
443 * work jobs from.
444 *
445 * The messages are always 32-bit words and follows the format defined by the
446 * WORK_* macros above.
447 */
448extern void grspw_work_func(rtems_id msgQ);
449
450enum grspw_worktask_ev {
451 WORKTASK_EV_NONE = 0,
452 WORKTASK_EV_QUIT = 1,
453 WORKTASK_EV_SHUTDOWN = 2,
454 WORKTASK_EV_DMA_STOP = 3,
455};
456
457/* Weak function to let user override. Function called every time one of the
458 * events above is handled by the work-task. The message 'msg' is the current
459 * message being processed by the work-task.
460 * The user can for example add custom code to invoke on a DMA error, link
461 * error or monitor when the work-task exits after a call to grspw_work_free().
462 */
463extern void grspw_work_event(enum grspw_worktask_ev ev, unsigned int msg);
464
465#ifdef RTEMS_SMP
466/* Set ISR interrupt affinity. The LEON IRQCtrl requires that the cpumask shall
467 * always have one bit set.
468 */
469extern int grspw_isr_affinity(void *d, const cpu_set_t *cpus);
470#endif
471
472extern int grspw_dev_count(void);
473extern void *grspw_open(int dev_no);
474extern int grspw_close(void *d);
475extern void grspw_hw_support(void *d, struct grspw_hw_sup *hw);
476extern void grspw_stats_read(void *d, struct grspw_core_stats *sts);
477extern void grspw_stats_clr(void *d);
478
479/* Set and Read current node address configuration. The dma_nacfg[N] field
480 * represents the configuration for DMA Channel N.
481 *
482 * Set cfg->promiscous to -1 in order to only read current configuration.
483 */
484extern void grspw_addr_ctrl(void *d, struct grspw_addr_config *cfg);
485
486/*** Link Control interface ***/
487/* Read Link State */
488extern spw_link_state_t grspw_link_state(void *d);
489/* options [in/out]: set to -1 to only read current config
490 *
491 * CLKDIV register contain:
492 * bits 7..0 : Clock Div RUN (only run-state)
493 * bits 15..8 : Clock Div During Startup (all link states except run-state)
494 */
495extern void grspw_link_ctrl(void *d, int *options, int *stscfg, int *clkdiv);
496/* Read the current value of the status register */
497extern unsigned int grspw_link_status(void *d);
498/* Clear bits in the status register */
499extern void grspw_link_status_clr(void *d, unsigned int clearmask);
501/*** Time Code Interface ***/
502/* Generate Tick-In (increment Time Counter, Send Time Code) */
503extern void grspw_tc_tx(void *d);
504/* Control Timcode settings of core */
505extern void grspw_tc_ctrl(void *d, int *options);
506/* Assign ISR Function to TimeCode RX IRQ */
507extern void grspw_tc_isr(void *d, void (*tcisr)(void *data, int tc), void *data);
508/* Read/Write TCTRL and TIMECNT. Write if not -1, always read current value
509 * TCTRL = bits 7 and 6
510 * TIMECNT = bits 5 to 0
511 */
512extern void grspw_tc_time(void *d, int *time);
513
514/*** Interrupt-code Interface ***/
515struct spwpkt_ic_config {
516 unsigned int tomask;
517 unsigned int aamask;
518 unsigned int scaler;
519 unsigned int isr_reload;
520 unsigned int ack_reload;
521};
522/* Function Interrupt-Code ISR callback prototype. Called when respective
523 * interrupt handling option has been enabled by grspw_ic_ctrl(), the
524 * arguments rxirq, rxack and intto are read from the registers of the
525 * GRSPW core read by the GRSPW ISR, they are individually valid only when
526 * repective handling been turned on.
527 *
528 * data - Custom data provided by user
529 * rxirq - Interrupt-Code Recevie register of the GRSPW core read by ISR
530 * (only defined if IQ bit enabled through grspw_ic_ctrl())
531 * rxack - Interrupt-Ack-Code Recevie register of the GRSPW core read by ISR
532 * (only defined if AQ bit enabled through grspw_ic_ctrl())
533 * intto - Interrupt Tick-out Recevie register of the GRSPW core read by ISR
534 * (only defined if TQ bit enabled through grspw_ic_ctrl())
535 */
536typedef void (*spwpkt_ic_isr_t)(void *data, unsigned int rxirq,
537 unsigned int rxack, unsigned int intto);
538/* Control Interrupt-code settings of core
539 * Write if 'options' not pointing to -1, always read current value
540 */
541extern void grspw_ic_ctrl(void *d, unsigned int *options);
542/* Write (rw&1 == 1) configuration parameters to registers and/or,
543 * Read (rw&2 == 1) configuration parameters from registers, in that sequence.
544 */
545extern void grspw_ic_config(void *d, int rw, struct spwpkt_ic_config *cfg);
546/* Read or Write Interrupt-code status registers.
547 * If pointer argument *ptr == 0 then only read, if *ptr != 0 then only write.
548 * If *ptr is NULL no operation.
549 */
550extern void grspw_ic_sts(void *d, unsigned int *rxirq, unsigned int *rxack,
551 unsigned int *intto);
552/* Generate Tick-In for the given Interrupt-code
553 * Returns zero on success and non-zero on failure
554 *
555 * Interrupt code bits (ic):
556 * Bit 5 - ACK if 1
557 * Bits 4-0 Interrupt-code number
558 */
559extern int grspw_ic_tickin(void *d, int ic);
560/* Assign handler function to Interrupt-code timeout IRQ */
561extern void grspw_ic_isr(void *d, spwpkt_ic_isr_t handler, void *data);
562
563/*** RMAP Control Interface ***/
564/* Set (not -1) and/or read RMAP options. */
565extern int grspw_rmap_ctrl(void *d, int *options, int *dstkey);
566extern void grspw_rmap_support(void *d, char *rmap, char *rmap_crc);
567
568/*** SpW Port Control Interface ***/
569
570/* Select port, if
571 * -1=The current selected port is returned
572 * 0=Port 0
573 * 1=Port 1
574 * Other positive values=Both Port0 and Port1
575 */
576extern int grspw_port_ctrl(void *d, int *port);
577/* Returns Number ports available in hardware */
578extern int grspw_port_count(void *d);
579/* Returns the current active port */
580extern int grspw_port_active(void *d);
581
582/*** DMA Interface ***/
583extern void *grspw_dma_open(void *d, int chan_no);
584extern int grspw_dma_close(void *c);
585
586extern int grspw_dma_start(void *c);
587extern void grspw_dma_stop(void *c);
588
589/* Enable interrupt manually */
590extern unsigned int grspw_dma_enable_int(void *c, int rxtx, int force);
591
592/* Return Current DMA Control & Status Register */
593extern unsigned int grspw_dma_ctrlsts(void *c);
594
595/* Schedule List of packets for transmission at some point in
596 * future.
597 *
598 * 1. Move transmitted packets to SENT List (SCHED->SENT)
599 * 2. Add the requested packets to the SEND List (USER->SEND)
600 * 3. Schedule as many packets as possible for transmission (SEND->SCHED)
601 *
602 * Call this function with pkts=NULL to just do step 1 and 3. This may be
603 * required in Polling-mode.
604 *
605 * The above steps 1 and 3 may be skipped by setting 'opts':
606 * bit0 = 1: Skip Step 1.
607 * bit1 = 1: Skip Step 3.
608 * Skipping both step 1 and 3 may be usefull when IRQ is enabled, then
609 * the work queue will be totaly responsible for handling descriptors.
610 *
611 * The fastest solution in retreiving sent TX packets and sending new frames
612 * is to call:
613 * A. grspw_dma_tx_reclaim(opts=0)
614 * B. grspw_dma_tx_send(opts=1)
615 *
616 * NOTE: the TXPKT_FLAG_TX flag must not be set.
617 *
618 * Return Code
619 * -1 Error
620 * 0 Successfully added pkts to send/sched list
621 * 1 DMA stopped. No operation.
622 */
623extern int grspw_dma_tx_send(void *c, int opts, struct grspw_list *pkts, int count);
624
625/* Reclaim TX packet buffers that has previously been scheduled for transmission
626 * with grspw_dma_tx_send().
627 *
628 * 1. Move transmitted packets to SENT List (SCHED->SENT)
629 * 2. Move all SENT List to pkts list (SENT->USER)
630 * 3. Schedule as many packets as possible for transmission (SEND->SCHED)
631 *
632 * The above steps 1 may be skipped by setting 'opts':
633 * bit0 = 1: Skip Step 1.
634 * bit1 = 1: Skip Step 3.
635 *
636 * The fastest solution in retreiving sent TX packets and sending new frames
637 * is to call:
638 * A. grspw_dma_tx_reclaim(opts=2) (Skip step 3)
639 * B. grspw_dma_tx_send(opts=1) (Skip step 1)
640 *
641 * Return Code
642 * -1 Error
643 * 0 Successful. pkts list filled with all packets from sent list
644 * 1 Same as 0, but indicates that DMA stopped
645 */
646extern int grspw_dma_tx_reclaim(void *c, int opts, struct grspw_list *pkts, int *count);
647
648/* Get current number of Packets in respective TX Queue. */
649extern void grspw_dma_tx_count(void *c, int *send, int *sched, int *sent, int *hw);
650
651#define GRSPW_OP_AND 0
652#define GRSPW_OP_OR 1
653/* Block until send_cnt or fewer packets are Queued in "Send and Scheduled" Q,
654 * op (AND or OR), sent_cnt or more packet "have been sent" (Sent Q) condition
655 * is met.
656 * If a link error occurs and the Stop on Link error is defined, this function
657 * will also return to caller.
658 * The timeout argument is used to return after timeout ticks, regardless of
659 * the other conditions. If timeout is zero, the function will wait forever
660 * until the condition is satisfied.
661 *
662 * NOTE: if IRQ of TX descriptors are not enabled conditions are never
663 * checked, this may hang infinitely unless a timeout has been specified
664 *
665 * Return Code
666 * -1 Error
667 * 0 Returing to caller because specified conditions are now fullfilled
668 * 1 DMA stopped
669 * 2 Timeout, conditions are not met
670 * 3 Another task is already waiting. Service is Busy.
671 */
672extern int grspw_dma_tx_wait(void *c, int send_cnt, int op, int sent_cnt, int timeout);
673
674/* Get received RX packet buffers that has previously been scheduled for
675 * reception with grspw_dma_rx_prepare().
676 *
677 * 1. Move Scheduled packets to RECV List (SCHED->RECV)
678 * 2. Move all RECV packet to the callers list (RECV->USER)
679 * 3. Schedule as many free packet buffers as possible (READY->SCHED)
680 *
681 * The above steps 1 may be skipped by setting 'opts':
682 * bit0 = 1: Skip Step 1.
683 * bit1 = 1: Skip Step 3.
684 *
685 * The fastest solution in retreiving received RX packets and preparing new
686 * packet buffers for future receive, is to call:
687 * A. grspw_dma_rx_recv(opts=2, &recvlist) (Skip step 3)
688 * B. grspw_dma_rx_prepare(opts=1, &freelist) (Skip step 1)
689 *
690 * Return Code
691 * -1 Error
692 * 0 Successfully filled pkts list with packets from recv list.
693 * 1 DMA stopped
694 */
695extern int grspw_dma_rx_recv(void *c, int opts, struct grspw_list *pkts, int *count);
696
697/* Add more RX packet buffers for future for reception. The received packets
698 * can later be read out with grspw_dma_rx_recv().
699 *
700 * 1. Move Received packets to RECV List (SCHED->RECV)
701 * 2. Add the "free/ready" packet buffers to the READY List (USER->READY)
702 * 3. Schedule as many packets as possible (READY->SCHED)
703 *
704 * The above steps 1 may be skipped by setting 'opts':
705 * bit0 = 1: Skip Step 1.
706 * bit1 = 1: Skip Step 3.
707 *
708 * The fastest solution in retreiving received RX packets and preparing new
709 * packet buffers for future receive, is to call:
710 * A. grspw_dma_rx_recv(opts=2, &recvlist) (Skip step 3)
711 * B. grspw_dma_rx_prepare(opts=1, &freelist) (Skip step 1)
712 *
713 * Return Code
714 * -1 Error
715 * 0 Successfully added packet buffers from pkt list into the ready queue
716 * 1 DMA stopped
717 */
718extern int grspw_dma_rx_prepare(void *c, int opts, struct grspw_list *pkts, int count);
719
720/* Get current number of Packets in respective RX Queue. */
721extern void grspw_dma_rx_count(void *c, int *ready, int *sched, int *recv, int *hw);
722
723/* Block until recv_cnt or more packets are Queued in RECV Q, op (AND or OR),
724 * ready_cnt or fewer packet buffers are available in the "READY and Scheduled" Q,
725 * condition is met.
726 * If a link error occurs and the Stop on Link error is defined, this function
727 * will also return to caller, however with an error.
728 * The timeout argument is used to return after timeout ticks, regardless of
729 * the other conditions. If timeout is zero, the function will wait forever
730 * until the condition is satisfied.
731 *
732 * NOTE: if IRQ of RX descriptors are not enabled conditions are never
733 * checked, this may hang infinitely unless a timeout has been specified
734 *
735 * Return Code
736 * -1 Error
737 * 0 Returing to caller because specified conditions are now fullfilled
738 * 1 DMA stopped
739 * 2 Timeout, conditions are not met
740 * 3 Another task is already waiting. Service is Busy.
741 */
742extern int grspw_dma_rx_wait(void *c, int recv_cnt, int op, int ready_cnt, int timeout);
743
744extern int grspw_dma_config(void *c, struct grspw_dma_config *cfg);
745extern void grspw_dma_config_read(void *c, struct grspw_dma_config *cfg);
746
747extern void grspw_dma_stats_read(void *c, struct grspw_dma_stats *sts);
748extern void grspw_dma_stats_clr(void *c);
749
750/* Register GRSPW packet driver to Driver Manager */
751void grspw2_register_drv (void);
752
753/*** GRSPW SpaceWire Packet List Handling Routines ***/
754
755static inline void grspw_list_clr(struct grspw_list *list)
756{
757 list->head = NULL;
758 list->tail = NULL;
759}
760
761static inline int grspw_list_is_empty(struct grspw_list *list)
762{
763 return (list->head == NULL);
764}
765
766/* Return Number of entries in list */
767static inline int grspw_list_cnt(struct grspw_list *list)
768{
769 struct grspw_pkt *lastpkt = NULL, *pkt = list->head;
770 int cnt = 0;
771 while ( pkt ) {
772 cnt++;
773 lastpkt = pkt;
774 pkt = pkt->next;
775 }
776 if ( lastpkt && (list->tail != lastpkt) )
777 return -1;
778 return cnt;
779}
780
781static inline void
782grspw_list_append(struct grspw_list *list, struct grspw_pkt *pkt)
783{
784 pkt->next = NULL;
785 if ( list->tail == NULL ) {
786 list->head = pkt;
787 } else {
788 list->tail->next = pkt;
789 }
790 list->tail = pkt;
791}
792
793static inline void
794grspw_list_prepend(struct grspw_list *list, struct grspw_pkt *pkt)
795{
796 pkt->next = list->head;
797 if ( list->head == NULL ) {
798 list->tail = pkt;
799 }
800 list->head = pkt;
801}
802
803static inline void
804grspw_list_append_list(struct grspw_list *list, struct grspw_list *alist)
805{
806 if (grspw_list_is_empty(alist)) {
807 return;
808 }
809 alist->tail->next = NULL;
810 if ( list->tail == NULL ) {
811 list->head = alist->head;
812 } else {
813 list->tail->next = alist->head;
814 }
815 list->tail = alist->tail;
816}
817
818static inline void
819grspw_list_prepend_list(struct grspw_list *list, struct grspw_list *alist)
820{
821 if (grspw_list_is_empty(alist)) {
822 return;
823 }
824 if ( list->head == NULL ) {
825 list->tail = alist->tail;
826 alist->tail->next = NULL;
827 } else {
828 alist->tail->next = list->head;
829 }
830 list->head = alist->head;
831}
832
833/* Remove dlist (delete-list) from head of list */
834static inline void
835grspw_list_remove_head_list(struct grspw_list *list, struct grspw_list *dlist)
836{
837 if (grspw_list_is_empty(dlist)) {
838 return;
839 }
840 list->head = dlist->tail->next;
841 if ( list->head == NULL ) {
842 list->tail = NULL;
843 }
844 dlist->tail->next = NULL;
845}
846
847/* Take A number of entries from head of list 'list' and put the entires
848 * to rlist (result list).
849 */
850static inline int
851grspw_list_take_head_list(struct grspw_list *list, struct grspw_list *rlist, int max)
852{
853 int cnt;
854 struct grspw_pkt *pkt, *last;
855
856 pkt = list->head;
857
858 if ( (max < 1) || (pkt == NULL) ) {
859 grspw_list_clr(rlist);
860 return 0;
861 }
862
863 cnt = 0;
864 rlist->head = pkt;
865 last = pkt;
866 while ((cnt < max) && pkt) {
867 last = pkt;
868 pkt = pkt->next;
869 cnt++;
870 }
871 rlist->tail = last;
872 grspw_list_remove_head_list(list, rlist);
873 return cnt;
874}
875
876#endif
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
Objects_Id rtems_id
This type represents RTEMS object identifiers.
Definition: types.h:94
Definition: grspw_pkt.h:178
Definition: grspw_pkt.h:212
Definition: grspw_pkt.h:304
Definition: grspw_pkt.h:312
Definition: grspw_pkt.h:196
Definition: grspw_pkt.h:162
Definition: grspw_pkt.h:150
Definition: grspw_pkt.h:382
Definition: b1553brm.c:94
Definition: grspw_pkt.h:500