summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/bridgedma.h
blob: 7702fa1433a32db0baf2cc166fe54e35b1685e9a (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
#ifndef hal_phy_bridgedma_h
#define hal_phy_bridgedma_h
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/phy/bridgedma.h
 * \brief   HAL Phy Bridge DMA public interface.
 * \ingroup hal_phy
 */
#include "lib/blk.h"
#include "hal/phy/phy.h"

/** BRIDGE DMA job structure */
struct phy_bridgedma_job_t
{
    /** Pointer to the next job descriptor. */
    struct phy_bridgedma_job_t *next;
    /** Address of data in ethernet buffer (not word aligned). */
    u8 *data_addr;
    BITFIELDS_WORD(
    /** Mac frame header length */
    u32 header_len:4;,
    u32 :12;,
    /** Length of data in ethernet buffer. max 1518 */
    u32 data_len:11;,
    u32 :5;)
    /** Pointer to the pb descriptor list head */
    blk_t *first_pb_desc;
    BITFIELDS_WORD(
        /** Start offset in first pb descriptor */
        u32 first_pb_offset:16;,
        /** length of segmentation block default = 512 */
        u32 segment_len:16;
    )

    BITFIELDS_WORD(
        /** indication of last job. If set, bridge will stop after this one */
        u32 last:1;,
        /** transfer direction: 0 for Segmentation (TX), 1 for Reassembly(RX) */
        u32 direction:1;,
        /** crc_error:
         * Reassembly : set by HW. 0 for crc ok, 1 for crc ko.
         * Segmentation : set by SW. 0 to compute crc, 1 to copy crc from bridgedma
         * icv substitution register.
         */
        u32 crc_error:1;,
        /** Reset crc computation before transfer */
        u32 crc_reset:1;,
        /** presence of crc : set by SW.
         * Reassembly : 0 for no crc, 1 for crc after data.
         * Segmentation : 0 to not add crc after data, 1 else.
         */
        u32 crc_store:1;,
        /** append zero after data+crc */
        u32 append_zero:1;,
        /** interrupt mask : if 0, HW will not throw interruption at the end of
         * job.
         */
        u32 job_it:1;,
        /** defines a rollover mask for ethernet buffer.
         * Used for circular buffer, this is the MSB of 32 bit mask which defines
         * which address bits are constant and which should be incremented on each
         * word
         */
        u32 eth_buffer_mask:25;
    )
    /** mac frame header part 1 */
    u32 mf_header1;
    /** mac frame header part 2 */
    u32 mf_header2;
};
typedef struct phy_bridgedma_job_t phy_bridgedma_job_t;

/** BRIDGE DMA status given back after a interrupt. */
struct phy_bridgedma_status_t
{
    BITFIELDS_WORD(
    /** AHB response error */
    u32 ahb_response_error:1;,
    u32 :15;,
    /** Debug : ctrl fsm */
    u32 ctrl_fsm:2;,
    /** running bit sets when bridge dma works */
    u32 running:1;,
    /** Correspond to the stop bit in job descriptor. It means that dma will or has stop */
    u32 stop:1;,
    u32 :12;)
};
typedef struct phy_bridgedma_status_t phy_bridgedma_status_t;

/**
 * Bridge DMA callback called when an interrupt occurs.
 * \param  user  user data
 * \param  status_word  status read from PB DMA
 * \return  true if a DSR is requested
 */
typedef bool (*phy_bridgedma_cb_t) (void *user, u32 status_word);

/** Cast a u32 word to the \c phy_bridgedma_status_t structure.  The reason
 * behind this macro is that the callback receive the status as a u32 in order
 * to use a register, not a pointer, to pass the parameter. */
#define PHY_BRIDGEDMA_STATUS(w) (*(phy_bridgedma_status_t *) (void *) &(w))

BEGIN_DECLS

/**
 * Initialise the Bridge DMA.
 * \param  user_data  User data passed to any callback
 * \param  bridgedma_cb  Bridge DMA interrupt callback
 * \param  deferred_cb  DSR callback
 * \return  the newly created context
 */
phy_bridgedma_t *
phy_bridgedma_init (void *user_data, phy_bridgedma_cb_t bridgedma_cb,
                    phy_deferred_cb_t deferred_cb);

/**
 * Reset and uninitialise the Bridge DMA.
 * \param  ctx  Bridge DMA context
 */
void
phy_bridgedma_uninit (phy_bridgedma_t *ctx);

/**
 * Enqueue and start a list of jobs.
 * \param  ctx  Bridge DMA context
 * \param  job_first  first job to enqueue
 * \param  job_last  last job to enqueue
 *
 * The new jobs are added to the Bridge DMA queue and the Bridge DMA is
 * restarted if it was stopped.  The \c last flag must be set in the last
 * enqueued job.
 */
void
phy_bridgedma_start (phy_bridgedma_t *ctx, phy_bridgedma_job_t *job_first,
                     phy_bridgedma_job_t *job_last);

END_DECLS

#endif /* hal_phy_bridgedma_h */