1
2
3
4
5 #ifndef _SJA1105_STATIC_CONFIG_H
6 #define _SJA1105_STATIC_CONFIG_H
7
8 #include <linux/packing.h>
9 #include <linux/types.h>
10 #include <asm/types.h>
11
12 #define SJA1105_SIZE_DEVICE_ID 4
13 #define SJA1105_SIZE_TABLE_HEADER 12
14 #define SJA1105_SIZE_SCHEDULE_ENTRY 8
15 #define SJA1105_SIZE_SCHEDULE_ENTRY_POINTS_ENTRY 4
16 #define SJA1105_SIZE_L2_POLICING_ENTRY 8
17 #define SJA1105_SIZE_VLAN_LOOKUP_ENTRY 8
18 #define SJA1105_SIZE_L2_FORWARDING_ENTRY 8
19 #define SJA1105_SIZE_L2_FORWARDING_PARAMS_ENTRY 12
20 #define SJA1105_SIZE_XMII_PARAMS_ENTRY 4
21 #define SJA1105_SIZE_SCHEDULE_PARAMS_ENTRY 12
22 #define SJA1105_SIZE_SCHEDULE_ENTRY_POINTS_PARAMS_ENTRY 4
23 #define SJA1105ET_SIZE_L2_LOOKUP_ENTRY 12
24 #define SJA1105ET_SIZE_MAC_CONFIG_ENTRY 28
25 #define SJA1105ET_SIZE_L2_LOOKUP_PARAMS_ENTRY 4
26 #define SJA1105ET_SIZE_GENERAL_PARAMS_ENTRY 40
27 #define SJA1105ET_SIZE_AVB_PARAMS_ENTRY 12
28 #define SJA1105PQRS_SIZE_L2_LOOKUP_ENTRY 20
29 #define SJA1105PQRS_SIZE_MAC_CONFIG_ENTRY 32
30 #define SJA1105PQRS_SIZE_L2_LOOKUP_PARAMS_ENTRY 16
31 #define SJA1105PQRS_SIZE_GENERAL_PARAMS_ENTRY 44
32 #define SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY 16
33
34
35 enum {
36 BLKID_SCHEDULE = 0x00,
37 BLKID_SCHEDULE_ENTRY_POINTS = 0x01,
38 BLKID_L2_LOOKUP = 0x05,
39 BLKID_L2_POLICING = 0x06,
40 BLKID_VLAN_LOOKUP = 0x07,
41 BLKID_L2_FORWARDING = 0x08,
42 BLKID_MAC_CONFIG = 0x09,
43 BLKID_SCHEDULE_PARAMS = 0x0A,
44 BLKID_SCHEDULE_ENTRY_POINTS_PARAMS = 0x0B,
45 BLKID_L2_LOOKUP_PARAMS = 0x0D,
46 BLKID_L2_FORWARDING_PARAMS = 0x0E,
47 BLKID_AVB_PARAMS = 0x10,
48 BLKID_GENERAL_PARAMS = 0x11,
49 BLKID_XMII_PARAMS = 0x4E,
50 };
51
52 enum sja1105_blk_idx {
53 BLK_IDX_SCHEDULE = 0,
54 BLK_IDX_SCHEDULE_ENTRY_POINTS,
55 BLK_IDX_L2_LOOKUP,
56 BLK_IDX_L2_POLICING,
57 BLK_IDX_VLAN_LOOKUP,
58 BLK_IDX_L2_FORWARDING,
59 BLK_IDX_MAC_CONFIG,
60 BLK_IDX_SCHEDULE_PARAMS,
61 BLK_IDX_SCHEDULE_ENTRY_POINTS_PARAMS,
62 BLK_IDX_L2_LOOKUP_PARAMS,
63 BLK_IDX_L2_FORWARDING_PARAMS,
64 BLK_IDX_AVB_PARAMS,
65 BLK_IDX_GENERAL_PARAMS,
66 BLK_IDX_XMII_PARAMS,
67 BLK_IDX_MAX,
68
69 BLK_IDX_MGMT_ROUTE,
70 BLK_IDX_MAX_DYN,
71 BLK_IDX_INVAL = -1,
72 };
73
74 #define SJA1105_MAX_SCHEDULE_COUNT 1024
75 #define SJA1105_MAX_SCHEDULE_ENTRY_POINTS_COUNT 2048
76 #define SJA1105_MAX_L2_LOOKUP_COUNT 1024
77 #define SJA1105_MAX_L2_POLICING_COUNT 45
78 #define SJA1105_MAX_VLAN_LOOKUP_COUNT 4096
79 #define SJA1105_MAX_L2_FORWARDING_COUNT 13
80 #define SJA1105_MAX_MAC_CONFIG_COUNT 5
81 #define SJA1105_MAX_SCHEDULE_PARAMS_COUNT 1
82 #define SJA1105_MAX_SCHEDULE_ENTRY_POINTS_PARAMS_COUNT 1
83 #define SJA1105_MAX_L2_LOOKUP_PARAMS_COUNT 1
84 #define SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT 1
85 #define SJA1105_MAX_GENERAL_PARAMS_COUNT 1
86 #define SJA1105_MAX_XMII_PARAMS_COUNT 1
87 #define SJA1105_MAX_AVB_PARAMS_COUNT 1
88
89 #define SJA1105_MAX_FRAME_MEMORY 929
90
91 #define SJA1105E_DEVICE_ID 0x9C00000Cull
92 #define SJA1105T_DEVICE_ID 0x9E00030Eull
93 #define SJA1105PR_DEVICE_ID 0xAF00030Eull
94 #define SJA1105QS_DEVICE_ID 0xAE00030Eull
95
96 #define SJA1105ET_PART_NO 0x9A83
97 #define SJA1105P_PART_NO 0x9A84
98 #define SJA1105Q_PART_NO 0x9A85
99 #define SJA1105R_PART_NO 0x9A86
100 #define SJA1105S_PART_NO 0x9A87
101
102 struct sja1105_schedule_entry {
103 u64 winstindex;
104 u64 winend;
105 u64 winst;
106 u64 destports;
107 u64 setvalid;
108 u64 txen;
109 u64 resmedia_en;
110 u64 resmedia;
111 u64 vlindex;
112 u64 delta;
113 };
114
115 struct sja1105_schedule_params_entry {
116 u64 subscheind[8];
117 };
118
119 struct sja1105_general_params_entry {
120 u64 vllupformat;
121 u64 mirr_ptacu;
122 u64 switchid;
123 u64 hostprio;
124 u64 mac_fltres1;
125 u64 mac_fltres0;
126 u64 mac_flt1;
127 u64 mac_flt0;
128 u64 incl_srcpt1;
129 u64 incl_srcpt0;
130 u64 send_meta1;
131 u64 send_meta0;
132 u64 casc_port;
133 u64 host_port;
134 u64 mirr_port;
135 u64 vlmarker;
136 u64 vlmask;
137 u64 tpid;
138 u64 ignore2stf;
139 u64 tpid2;
140
141 u64 queue_ts;
142 u64 egrmirrvid;
143 u64 egrmirrpcp;
144 u64 egrmirrdei;
145 u64 replay_port;
146 };
147
148 struct sja1105_schedule_entry_points_entry {
149 u64 subschindx;
150 u64 delta;
151 u64 address;
152 };
153
154 struct sja1105_schedule_entry_points_params_entry {
155 u64 clksrc;
156 u64 actsubsch;
157 };
158
159 struct sja1105_vlan_lookup_entry {
160 u64 ving_mirr;
161 u64 vegr_mirr;
162 u64 vmemb_port;
163 u64 vlan_bc;
164 u64 tag_port;
165 u64 vlanid;
166 };
167
168 struct sja1105_l2_lookup_entry {
169 u64 vlanid;
170 u64 macaddr;
171 u64 destports;
172 u64 enfport;
173 u64 index;
174
175 u64 mask_iotag;
176 u64 mask_vlanid;
177 u64 mask_macaddr;
178 u64 iotag;
179 u64 lockeds;
180 union {
181
182 struct {
183 u64 tsreg;
184 u64 mirrvlan;
185 u64 takets;
186 u64 mirr;
187 u64 retag;
188 };
189
190 struct {
191 u64 touched;
192 u64 age;
193 };
194 };
195 };
196
197 struct sja1105_l2_lookup_params_entry {
198 u64 maxaddrp[5];
199 u64 start_dynspc;
200 u64 drpnolearn;
201 u64 use_static;
202 u64 owr_dyn;
203 u64 learn_once;
204 u64 maxage;
205 u64 dyn_tbsz;
206 u64 poly;
207 u64 shared_learn;
208 u64 no_enf_hostprt;
209 u64 no_mgmt_learn;
210 };
211
212 struct sja1105_l2_forwarding_entry {
213 u64 bc_domain;
214 u64 reach_port;
215 u64 fl_domain;
216 u64 vlan_pmap[8];
217 };
218
219 struct sja1105_l2_forwarding_params_entry {
220 u64 max_dynp;
221 u64 part_spc[8];
222 };
223
224 struct sja1105_l2_policing_entry {
225 u64 sharindx;
226 u64 smax;
227 u64 rate;
228 u64 maxlen;
229 u64 partition;
230 };
231
232 struct sja1105_avb_params_entry {
233 u64 destmeta;
234 u64 srcmeta;
235 };
236
237 struct sja1105_mac_config_entry {
238 u64 top[8];
239 u64 base[8];
240 u64 enabled[8];
241 u64 ifg;
242 u64 speed;
243 u64 tp_delin;
244 u64 tp_delout;
245 u64 maxage;
246 u64 vlanprio;
247 u64 vlanid;
248 u64 ing_mirr;
249 u64 egr_mirr;
250 u64 drpnona664;
251 u64 drpdtag;
252 u64 drpuntag;
253 u64 retag;
254 u64 dyn_learn;
255 u64 egress;
256 u64 ingress;
257 };
258
259 struct sja1105_xmii_params_entry {
260 u64 phy_mac[5];
261 u64 xmii_mode[5];
262 };
263
264 struct sja1105_table_header {
265 u64 block_id;
266 u64 len;
267 u64 crc;
268 };
269
270 struct sja1105_table_ops {
271 size_t (*packing)(void *buf, void *entry_ptr, enum packing_op op);
272 size_t unpacked_entry_size;
273 size_t packed_entry_size;
274 size_t max_entry_count;
275 };
276
277 struct sja1105_table {
278 const struct sja1105_table_ops *ops;
279 size_t entry_count;
280 void *entries;
281 };
282
283 struct sja1105_static_config {
284 u64 device_id;
285 struct sja1105_table tables[BLK_IDX_MAX];
286 };
287
288 extern struct sja1105_table_ops sja1105e_table_ops[BLK_IDX_MAX];
289 extern struct sja1105_table_ops sja1105t_table_ops[BLK_IDX_MAX];
290 extern struct sja1105_table_ops sja1105p_table_ops[BLK_IDX_MAX];
291 extern struct sja1105_table_ops sja1105q_table_ops[BLK_IDX_MAX];
292 extern struct sja1105_table_ops sja1105r_table_ops[BLK_IDX_MAX];
293 extern struct sja1105_table_ops sja1105s_table_ops[BLK_IDX_MAX];
294
295 size_t sja1105_table_header_packing(void *buf, void *hdr, enum packing_op op);
296 void
297 sja1105_table_header_pack_with_crc(void *buf, struct sja1105_table_header *hdr);
298 size_t
299 sja1105_static_config_get_length(const struct sja1105_static_config *config);
300
301 typedef enum {
302 SJA1105_CONFIG_OK = 0,
303 SJA1105_TTETHERNET_NOT_SUPPORTED,
304 SJA1105_INCORRECT_TTETHERNET_CONFIGURATION,
305 SJA1105_MISSING_L2_POLICING_TABLE,
306 SJA1105_MISSING_L2_FORWARDING_TABLE,
307 SJA1105_MISSING_L2_FORWARDING_PARAMS_TABLE,
308 SJA1105_MISSING_GENERAL_PARAMS_TABLE,
309 SJA1105_MISSING_VLAN_TABLE,
310 SJA1105_MISSING_XMII_TABLE,
311 SJA1105_MISSING_MAC_TABLE,
312 SJA1105_OVERCOMMITTED_FRAME_MEMORY,
313 } sja1105_config_valid_t;
314
315 extern const char *sja1105_static_config_error_msg[];
316
317 sja1105_config_valid_t
318 sja1105_static_config_check_valid(const struct sja1105_static_config *config);
319 void
320 sja1105_static_config_pack(void *buf, struct sja1105_static_config *config);
321 int sja1105_static_config_init(struct sja1105_static_config *config,
322 const struct sja1105_table_ops *static_ops,
323 u64 device_id);
324 void sja1105_static_config_free(struct sja1105_static_config *config);
325
326 int sja1105_table_delete_entry(struct sja1105_table *table, int i);
327 int sja1105_table_resize(struct sja1105_table *table, size_t new_count);
328
329 u32 sja1105_crc32(const void *buf, size_t len);
330
331 void sja1105_pack(void *buf, const u64 *val, int start, int end, size_t len);
332 void sja1105_unpack(const void *buf, u64 *val, int start, int end, size_t len);
333 void sja1105_packing(void *buf, u64 *val, int start, int end,
334 size_t len, enum packing_op op);
335
336 #endif