summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/plcdrv/arm/inc/linux_drv.h
blob: 71f541a0ad7e034c6228a3eeadd07b5188bf1898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#ifndef linux_drv_h
#define linux_drv_h
/* Cleopatre project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    linux_drv.h
 * \brief   interfaces for linux_drv layer
 * \ingroup Cleopatre - PlcDrv
 *
 * this file content interfaces and exported macros, variables... For the
 * linux_drv layer
 */

#ifndef __UTESTS__
#include <linux/netdevice.h>
#include <net/seq_check.h>
#else
#include <linux/types.h>
#include <linux/wait.h>
#include <linux/interrupt.h>
#include <linux/dma-mapping.h>
#include <linux/netdevice.h>
#endif

#include "common.h"
#include "hal.h"

/**  */
enum pkt_dest {
    OTHER = 0,
    NETLINK_DRV = 1,
    NETLINK_MME = 2,
};

/** why do you want to free the buffer */
enum free_reason {
    RX_DROP = 0,
    TX_DROP = 1,
    TX_COMPLETE = 2,
};

/** Data direction. */
enum data_direction {
    DATA_TO_FW = DMA_TO_DEVICE,
    DATA_FROM_FW = DMA_FROM_DEVICE,
    DATA_BIDIR = DMA_BIDIRECTIONAL,
};

/** Define plc.rom informations */
#define ROM_INFO_DELIMITER      '\n'
#define ROM_INFO_KEY_DELIMITER  ':'
#define ROM_INFO_MAX_SIZE       1024
#define ROM_VERSION_SIZE        64
#define ROM_VERSION_KEY         "version"

/** PLC private stats */
struct plc_stats {
    uint32_t tx_pool; // number of allocated skbuff for Tx
    uint32_t rx_pool; // number of allocated skbuff for Rx
};

/** Select function private data */
struct plc_select
{
    atomic_t plc_error;
    wait_queue_head_t wq; 
};

/** Driver private data */
struct net_priv
{
    struct plc_select plc_select;
    uint32_t num_mbx_it;
    uint32_t num_mbx_it_ack;
    uint32_t num_mbx_it_wd;
    uint32_t phys_ring_base_addr;
    uint32_t virt_ring_base_addr;
    spinlock_t lock;
    struct list_head list_head_skbs;
    struct net_device_stats stats;
    struct plc_stats plc_stats;
    struct tasklet_struct tasklet_it_rx;
    struct halctx *halctx;
    struct sock *nl_drv_sock;
    struct sock *nl_mme_sock;
    uint32_t nl_drv_pid;
    uint32_t nl_mme_pid;
    uint8_t firmware_written;
    uint8_t version[ROM_VERSION_SIZE];

#ifdef CONFIG_SEQ_CHECK
    struct seq_check_ctx seq_check_ctx;
#endif
};

/**
 * Debug dump buffer length of the buffer received from Cesar by the mailbox.
 * Set to -1 at initialization and to 0 when there is nothing more to read
 * from Cesar.
 */
extern int debug_dump_buffer_length_received;
/**
 * Debug dump buffer location.
 * When debug dump buffer has been sent to Cesar, this variable is set to
 * true, otherwise, this is set to false.
 */
extern bool debug_dump_waiting_for_buffer;
/**
 * Debug dump buffer length allocated by Cleopatra.
 */
extern const uint debug_dump_buffer_length;
/**
 * Debug dump wait queue shared between the mailbox received and the read
 * proc from the kernel.
 */
extern wait_queue_head_t debug_dump_wait_queue;

/**
 * Receive a packet.
 *
 * \param  packet  packet pointer.
 * \param  length  packet length.
 * \param  dest  packet destination.
 * \return  error code.
 */
int plcdrv_rx(void *packet, int length, enum pkt_dest dst);

/**
 * Release a buffer.
 *
 * \param  packet  packet pointer.
 * \param  reason  freeing reason.
 * \return  error code.
 */
int free_buffer(void *packet, enum free_reason reason);

/**
 * Allocate a buffer to the pool
 * and send to the communication layer.
 *
 * \param  type  type of buffer to allocate.
 * \return  error code.
 */
int alloc_buffer(enum buffer_type type);

/**
 * Allocate a debug dump buffer for CESAR and return its.
 *
 * \param  debug_dump_buffer  the debug dump buffer to allocate
 * \param  debug_dump_buffer_length  the length of the debug dump buffer
 * \return  error code
 *
 * \note  the address returned is a virtual one, not a physical one: you need
 * to convert it before using it.
 */
int alloc_debug_dump_buffer(void **debug_dump_buffer,
                            int debug_dump_buffer_length);

/**
 * Free a debug dump buffer.
 *
 * \param  debug_dump_buffer  the debug dump buffer to free
 * \param  debug_dump_buffer_length  the length of the debug dump buffer
 *
 * \note  the address of debug_dump_buffer should be a virtual one.
 */
void free_debug_dump_buffer(void *debug_dump_buffer,
                            int debug_dump_buffer_length);

/**
 * Changed a virtual address to its corresponding physical address
 * and manage the cache.
 *
 * \param  addr  buffer virtual address.
 * \param  len  buffer length.
 * \param  data_dir  data direction.
 * \return  buffer physical address.
 */
uint32_t prepare_buffer_to_hw(uint32_t addr, unsigned int len,
                              enum data_direction data_dir);

/**
 * Changed a physical address to its corresponding virtual address
 * and manage the cache.
 *
 * \param  addr  buffer physical address.
 * \param  len  buffer length.
 * \param  data_dir  data direction.
 * \return  buffer virtual address.
 */
uint32_t prepare_buffer_from_hw(uint32_t addr, unsigned int len,
                                enum data_direction data_dir);

#endif /* linux_drv_h */