ath9k: merge a few bugfixes
[openwrt.git] / package / lqtapi / src / mps / mps-msg.h
1 #ifndef __MPS_MSG_H__
2 #define __MPS_MSG_H__
3
4 #include <linux/slab.h>
5
6 struct mps_message {
7         uint32_t header;
8         uint32_t data[0];
9 };
10
11 #define MPS_MSG_HEADER(_rw, _sc, _bc, _cmd, _chan, _mode, _ecmd, _length) \
12         (((_rw) << 31) | ((_sc) << 30) | ((_bc) << 29) | ((_cmd) << 24) | \
13         ((_chan) << 16) | ((_mode) << 13) | ((_ecmd) << 8) | (_length))
14
15 #define MPS_MSG_INIT(_msg, _rw, _sc, _bc, _cmd, _chan, _mode, _ecmd, _length) \
16         do { \
17                 (_msg)->header = MPS_MSG_HEADER(_rw, _sc, _bc, _cmd, _chan, _mode, \
18                         _ecmd, _length); \
19         } while(0)
20
21
22 static inline void mps_msg_init(struct mps_message *msg, uint32_t rw, uint32_t sc,
23         uint32_t bc, uint32_t cmd, uint32_t chan, uint32_t mode, uint32_t ecmd,
24         uint32_t length)
25 {
26         msg->header = MPS_MSG_HEADER(rw, sc, bc, cmd, chan, mode, ecmd, length);
27 }
28
29 #define DECLARE_MESSAGE(_name, _size) struct mps_message _name; \
30         uint32_t __mps_msg_data_ ## __FUNCTION__ ## __LINE__[_size]
31
32 static inline struct mps_message *mps_message_alloc(size_t size)
33 {
34         return kmalloc(sizeof(struct mps_message) + size * sizeof(uint32_t), GFP_KERNEL);
35 }
36
37 static inline size_t mps_message_size(const struct mps_message *msg)
38 {
39         return msg->header & 0xff;
40 }
41
42 enum {
43         MPS_MSG_WRITE = 0,
44         MPS_MSG_READ = 1,
45 };
46
47 enum {
48         MPS_CMD_ALI = 1,
49         MPS_CMD_DECT = 3,
50         MPS_CMD_SDD = 4,
51         MPS_CMD_EOP = 6,
52 };
53
54 #define MOD_PCM 0
55 #define MOD_SDD 0
56 #define MOD_ALI 1
57 #define MOD_SIGNALING 2
58 #define MOD_CODER 3
59 #define MOD_RESOURCE 6
60 #define MOD_SYSTEM 7
61 #define ECMD_SYS_VER 6
62 #define SYS_CAP_ECMD 7
63 #define ECMD_CIDS_DATA 9
64 #define ECMD_DCCTL_DEBUG 0x0a
65
66 #define ALI_CHAN_CMD 6
67 #define ALI_CHAN_ECMD 1
68
69 #define MPS_MSG_HEADER_W(_sc, _bc, _cmd, _chan, _mode, _ecmd, _length) \
70         MPS_MSG_HEADER(MPS_MSG_WRITE, _sc, _bc, _cmd, _chan, _mode, _ecmd, _length)
71
72 #define MPS_MSG_HEADER_R(_sc, _bc, _cmd, _chan, _mode, _ecmd, _length) \
73         MPS_MSG_HEADER(MPS_MSG_READ, _sc, _bc, _cmd, _chan, _mode, _ecmd, _length)
74
75 #define MPS_MSG_CMD_EOP(_mode, _ecmd, _length) \
76         MPS_MSG_HEADER_R(0, 0, MPS_CMD_EOP, 0, _mode, _ecmd, _length)
77
78 #define MPS_MSG_CMD_EOP_SYSTEM(_ecmd, _length) \
79         MPS_MSG_CMD_EOP(MOD_SYSTEM, _ecmd, _length)
80
81 #define MPS_CMD_GET_VERSION \
82         MPS_MSG_CMD_EOP_SYSTEM(ECMD_SYS_VER, 4)
83
84 #define MPS_CMD_ALI(_chan) \
85         MPS_MSG_HEADER_W(0, 0, ALI_CHAN_CMD, _chan, MOD_ALI, ALI_CHAN_ECMD, 12)
86
87 #endif