summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/plcdrv/inc/frame.h
blob: 191bf4f965c723419c09ac9104ab7c14ed564bcb (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
#ifndef inc_frame_h
#define inc_frame_h
/* Cleopatre project {{{
 *
 * Copyright (C) 2012 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    inc/frame.h
 * \brief   Interfaces to send/receive/alloc/free frames for firmware.
 * \ingroup plcdrv
 */
#include <linux/types.h>
#include <linux/list.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>

#include "plcdrv.h"

/**
 * Max size of an Ethernet frame (size for all buffers).
 * It must be align on 4 bytes.
 */
#define PKT_BUF_SZ 1524

/**
 * Allocate buffers and give them to firmware.
 * \param  priv  PLC device private context
 * \return  true if all buffers have been allocated, false otherwise
 */
bool
frame_buffer_alloc (plcdrv_t *priv);

/**
 * Free a buffer after being used by firmware.
 * \param  priv  PLC device private context
 * \param  buffer  buffer to release (physical address)
 */
void
frame_buffer_free (plcdrv_t *priv, uint32_t buffer);

/**
 * Resume device queue if possible.
 * \param  priv  PLC device private context
 */
static inline void
frame_wake_queue (plcdrv_t *priv)
{
    if (skb_queue_len (&priv->tx_pool_data) < PLCDRV_TX_POOL_DATA)
        netif_wake_queue (priv->dev);
}

/**
 * Handle a data buffer from firmware.
 * \param  priv  PLC device private context
 * \param  data_addr  data physical address
 * \param  data_length  data length in byte
 */
void
frame_rx_data (plcdrv_t *priv, uint32_t data_addr,
               uint32_t data_length);

/**
 * Handle a private MME buffer from firmware.
 * \param  priv  PLC device private context
 * \param  data_addr  data physical address
 * \param  data_length  data length in byte
 */
void
frame_rx_mme_priv (plcdrv_t *priv, uint32_t data_addr,
                   uint32_t data_length);

/**
 * Handle a debug dump buffer from firmware.
 * \param  priv  PLC device private context
 * \param  data_addr  data physical address
 * \param  data_length  data length in byte
 */
void
frame_rx_debug_dump (plcdrv_t *priv, uint32_t data_addr,
                     uint32_t data_length);

/**
 * Transmit a data frame to firmware.
 * \param  skb  frame structure
 * \param  dev  device structure
 * \return  error code
 */
int
frame_tx_data (struct sk_buff *skb, struct net_device *dev);

/**
 * Transmit a private MME frame to firmware.
 * \param  priv  PLC device private context
 * \param  skb  frame structure
 */
void
frame_tx_mbx_mme_priv (plcdrv_t *priv, struct sk_buff *skb);

/**
 * Transmit a debug dump buffer to firmware.
 * \param  priv  PLC device private context
 * \param  buffer  debug dump virtual address
 * \param  length  debug dump buffer length
 */
void
frame_tx_mbx_debug_dump (plcdrv_t *priv, uint32_t *buffer,
                         unsigned int length);

#endif /* inc_frame_h */