summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/plcdrv/arm/inc/linux_drv.h
blob: 84dbc7019ab832289a09f310ba764ca1f2fd9a74 (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
#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
 */

#include <linux/netdevice.h>
#include "common.h"
#include "hal.h"

#ifdef __UTESTS__
#include "linux_drv_utests.h"
#endif

/**  */
enum pkt_dest {
    OTHER = 0,
    NETLINK = 1,
};

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

/** 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
};

/** Driver Private datas */
struct net_priv {
    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_sock;
    uint32_t plcd_pid;
    uint8_t firmware_written;
    uint8_t version[ROM_VERSION_SIZE];
};

/**
 * 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);

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

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

#endif /* linux_drv_h */