aboutsummaryrefslogtreecommitdiff
path: root/drivers/net/danipc/ipc_cfg.c
blob: 5cbc52218632f659194b420694a27836f7396c79 (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
	All files except if stated otherwise in the begining of the file
	are under the ISC license:
	----------------------------------------------------------------------

	Copyright (c) 2010-2012 Design Art Networks Ltd.

	Permission to use, copy, modify, and/or distribute this software for any
	purpose with or without fee is hereby granted, provided that the above
	copyright notice and this permission notice appear in all copies.

	THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
	WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
	MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
	ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
	WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
	ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
	OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


/* -----------------------------------------------------------
 * Include section
 * -----------------------------------------------------------
 */

#include <linux/string.h>

#include "ipc_api.h"
#include "ipc_cfg.h"
#include "danipc_lowlevel.h"


/* -----------------------------------------------------------
 * Type definition section
 * -----------------------------------------------------------
 */
/* Entry of Route-How table providing information how
 * information passes when Source and Destination Nodes are known.
 */
struct ipc_route {
	uint8_t src_node;
	uint8_t dst_node;
	struct ipc_trns_func const *trns_funs;
};


/* -----------------------------------------------------------
 * Global data section
 * -----------------------------------------------------------
 */

const struct ipc_trns_func ipc_fifo_utils = {
	ipc_trns_fifo_buf_alloc,
	ipc_trns_fifo_buf_free,
	ipc_trns_fifo_buf_send
};

static const struct ipc_trns_func ipc_fifo2eth_utils = {
	ipc_trns_fifo2eth_buf_alloc,
	ipc_trns_fifo2eth_buf_free,
	ipc_trns_fifo2eth_buf_send
};

static const struct ipc_trns_func ipc_proxy2eth_utils = {
	NULL,
	NULL,
	NULL,
};

static const struct ipc_route ipc_routes[] = {
	{dan3400_e,		dan3400_e,	&ipc_fifo_utils},
	{dan3400_e,		ext_eth_e,	&ipc_fifo2eth_utils},
	{dan3400_eth_e,		ext_eth_e,	&ipc_proxy2eth_utils}
};

/* The static constant table contains information about the location
 * of each node.
 */
static const enum ipc_node_type node_type[PLATFORM_MAX_NUM_OF_NODES] = {
		dan3400_e,		/* Node #0 */
		dan3400_e,		/* Node #1 */
		dan3400_e,		/* Node #2 */
		dan3400_e,		/* Node #3 */
		ext_eth_e,		/* Node #4 */
		ext_fser_e,		/* Node #5 */
		ext_uart_e,		/* Node #6 */
		undef_e,		/* Node #7 */
		dan3400_e,		/* Node #8 */
		dan3400_e,		/* Node #9 */
		dan3400_e,		/* Node #10 */
		dan3400_e,		/* Node #11 */
		dan3400_e,		/* Node #12 */
		dan3400_e,		/* Node #13 */
		dan3400_e,		/* Node #14 */
		dan3400_e,		/* Node #15 */
};


/* Routing table is maintained globaly per 'board' */
static struct ipc_trns_func const *ipc_routing[PLATFORM_MAX_NUM_OF_NODES];

struct agent_entry __iomem	*agent_table;


/* -----------------------------------------------------------
 * Global prototypes section
 * -----------------------------------------------------------
 */

/* ===========================================================================
 * ipc_get_own_node
 * ===========================================================================
 * Description:  Get Node ID for current node
 *
 * Parameters: none
 *
 * Returns: IPC node ID (0:31)
 *
 */
uint8_t ipc_get_own_node(void)
{
	return LOCAL_IPC_ID;
}


/* ===========================================================================
 * ipc_cfg_get_util_vec
 * ===========================================================================
 * Description:	Fetch the node util function vector
 *
 * Parameters:		srcNode		- source Node Id
 *			destNode	- destination Node Id
 *
 * Returns: Location Type
 *
 */
static struct ipc_trns_func const *ipc_cfg_get_util_vec(uint8_t srcNode,
							 uint8_t destNode)
{
	unsigned i;

	for (i = 0; i < ARRAY_SIZE(ipc_routes); i++) {
		if ((ipc_routes[i].src_node == node_type[srcNode]) &&
			(ipc_routes[i].dst_node == node_type[destNode]))
			return ipc_routes[i].trns_funs;
	}

	return NULL;
}


void ipc_agent_table_clean(void)
{
	int		len = (sizeof(struct agent_entry) * MAX_LOCAL_AGENT)
					/ sizeof(uint32_t);
	const unsigned	aid = __IPC_AGENT_ID(LOCAL_IPC_ID, 0);
	uint32_t	*p = (uint32_t *)&agent_table[aid];

	/* Clean only my part of the global table. This is necessary so I may
	 * register agents but do not hurt other cores.
	 * Vladik, 18.08,2011
	 */
	while (--len >= 0) {
		if (*p)
			*p = 0;
		p++;
	}
}

/* ===========================================================================
 * ipc_trns_func
 * ===========================================================================
 * Description:	Fetch the utility function's vector from the IPC
 *		routing table.
 *
 * Parameters:	CPU-Id
 *
 * Returns: Pointer to function's pointers structure
 *
 */
struct ipc_trns_func const *get_trns_funcs(uint8_t cpuid)
{
	return (cpuid < PLATFORM_MAX_NUM_OF_NODES) ?
						ipc_routing[cpuid] : NULL;
}

/* ===========================================================================
 * ipc_route_table_init
 * ===========================================================================
 * Description:  Initialize routing table .
 *
 * Parameters: pointer to default transport function
 *
 * Returns:
 *
 *   Note: The routing table
 *   is unique per CPU as it maintains the information how to communicate
 *   with any other CPU from this CPU.
 *
 *   This is just a preliminary implementation. Need to decide how each CPU
 *   maintains the correct routing table
 */
void ipc_route_table_init(struct ipc_trns_func const *def_trns_funcs)
{
	unsigned i;

	/* For every potential destination fill the associated function
	 * vector or set to the node default transport functions
	 */
	for (i = 0; i < PLATFORM_MAX_NUM_OF_NODES; i++) {
		ipc_routing[i] = (struct ipc_trns_func *)
				ipc_cfg_get_util_vec(ipc_own_node, i);
		if (ipc_routing[i] == NULL)
			ipc_routing[i] = def_trns_funcs;
	}
}