1
2
3
4
5
6#include <linux/kernel.h>
7#include <linux/fsl/mc.h>
8
9#include "fsl-mc-private.h"
10
11
12
13
14
15
16
17
18
19
20
21
22int dprc_open(struct fsl_mc_io *mc_io,
23 u32 cmd_flags,
24 int container_id,
25 u16 *token)
26{
27 struct fsl_mc_command cmd = { 0 };
28 struct dprc_cmd_open *cmd_params;
29 int err;
30
31
32 cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
33 0);
34 cmd_params = (struct dprc_cmd_open *)cmd.params;
35 cmd_params->container_id = cpu_to_le32(container_id);
36
37
38 err = mc_send_command(mc_io, &cmd);
39 if (err)
40 return err;
41
42
43 *token = mc_cmd_hdr_read_token(&cmd);
44
45 return 0;
46}
47EXPORT_SYMBOL_GPL(dprc_open);
48
49
50
51
52
53
54
55
56
57
58
59
60int dprc_close(struct fsl_mc_io *mc_io,
61 u32 cmd_flags,
62 u16 token)
63{
64 struct fsl_mc_command cmd = { 0 };
65
66
67 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
68 token);
69
70
71 return mc_send_command(mc_io, &cmd);
72}
73EXPORT_SYMBOL_GPL(dprc_close);
74
75
76
77
78
79
80
81
82
83
84
85int dprc_set_irq(struct fsl_mc_io *mc_io,
86 u32 cmd_flags,
87 u16 token,
88 u8 irq_index,
89 struct dprc_irq_cfg *irq_cfg)
90{
91 struct fsl_mc_command cmd = { 0 };
92 struct dprc_cmd_set_irq *cmd_params;
93
94
95 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
96 cmd_flags,
97 token);
98 cmd_params = (struct dprc_cmd_set_irq *)cmd.params;
99 cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
100 cmd_params->irq_index = irq_index;
101 cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
102 cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
103
104
105 return mc_send_command(mc_io, &cmd);
106}
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
124 u32 cmd_flags,
125 u16 token,
126 u8 irq_index,
127 u8 en)
128{
129 struct fsl_mc_command cmd = { 0 };
130 struct dprc_cmd_set_irq_enable *cmd_params;
131
132
133 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
134 cmd_flags, token);
135 cmd_params = (struct dprc_cmd_set_irq_enable *)cmd.params;
136 cmd_params->enable = en & DPRC_ENABLE;
137 cmd_params->irq_index = irq_index;
138
139
140 return mc_send_command(mc_io, &cmd);
141}
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
160 u32 cmd_flags,
161 u16 token,
162 u8 irq_index,
163 u32 mask)
164{
165 struct fsl_mc_command cmd = { 0 };
166 struct dprc_cmd_set_irq_mask *cmd_params;
167
168
169 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
170 cmd_flags, token);
171 cmd_params = (struct dprc_cmd_set_irq_mask *)cmd.params;
172 cmd_params->mask = cpu_to_le32(mask);
173 cmd_params->irq_index = irq_index;
174
175
176 return mc_send_command(mc_io, &cmd);
177}
178
179
180
181
182
183
184
185
186
187
188
189
190
191int dprc_get_irq_status(struct fsl_mc_io *mc_io,
192 u32 cmd_flags,
193 u16 token,
194 u8 irq_index,
195 u32 *status)
196{
197 struct fsl_mc_command cmd = { 0 };
198 struct dprc_cmd_get_irq_status *cmd_params;
199 struct dprc_rsp_get_irq_status *rsp_params;
200 int err;
201
202
203 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
204 cmd_flags, token);
205 cmd_params = (struct dprc_cmd_get_irq_status *)cmd.params;
206 cmd_params->status = cpu_to_le32(*status);
207 cmd_params->irq_index = irq_index;
208
209
210 err = mc_send_command(mc_io, &cmd);
211 if (err)
212 return err;
213
214
215 rsp_params = (struct dprc_rsp_get_irq_status *)cmd.params;
216 *status = le32_to_cpu(rsp_params->status);
217
218 return 0;
219}
220
221
222
223
224
225
226
227
228
229
230
231
232
233int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
234 u32 cmd_flags,
235 u16 token,
236 u8 irq_index,
237 u32 status)
238{
239 struct fsl_mc_command cmd = { 0 };
240 struct dprc_cmd_clear_irq_status *cmd_params;
241
242
243 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
244 cmd_flags, token);
245 cmd_params = (struct dprc_cmd_clear_irq_status *)cmd.params;
246 cmd_params->status = cpu_to_le32(status);
247 cmd_params->irq_index = irq_index;
248
249
250 return mc_send_command(mc_io, &cmd);
251}
252
253
254
255
256
257
258
259
260
261
262int dprc_get_attributes(struct fsl_mc_io *mc_io,
263 u32 cmd_flags,
264 u16 token,
265 struct dprc_attributes *attr)
266{
267 struct fsl_mc_command cmd = { 0 };
268 struct dprc_rsp_get_attributes *rsp_params;
269 int err;
270
271
272 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
273 cmd_flags,
274 token);
275
276
277 err = mc_send_command(mc_io, &cmd);
278 if (err)
279 return err;
280
281
282 rsp_params = (struct dprc_rsp_get_attributes *)cmd.params;
283 attr->container_id = le32_to_cpu(rsp_params->container_id);
284 attr->icid = le16_to_cpu(rsp_params->icid);
285 attr->options = le32_to_cpu(rsp_params->options);
286 attr->portal_id = le32_to_cpu(rsp_params->portal_id);
287
288 return 0;
289}
290
291
292
293
294
295
296
297
298
299
300int dprc_get_obj_count(struct fsl_mc_io *mc_io,
301 u32 cmd_flags,
302 u16 token,
303 int *obj_count)
304{
305 struct fsl_mc_command cmd = { 0 };
306 struct dprc_rsp_get_obj_count *rsp_params;
307 int err;
308
309
310 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
311 cmd_flags, token);
312
313
314 err = mc_send_command(mc_io, &cmd);
315 if (err)
316 return err;
317
318
319 rsp_params = (struct dprc_rsp_get_obj_count *)cmd.params;
320 *obj_count = le32_to_cpu(rsp_params->obj_count);
321
322 return 0;
323}
324EXPORT_SYMBOL_GPL(dprc_get_obj_count);
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341int dprc_get_obj(struct fsl_mc_io *mc_io,
342 u32 cmd_flags,
343 u16 token,
344 int obj_index,
345 struct fsl_mc_obj_desc *obj_desc)
346{
347 struct fsl_mc_command cmd = { 0 };
348 struct dprc_cmd_get_obj *cmd_params;
349 struct dprc_rsp_get_obj *rsp_params;
350 int err;
351
352
353 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
354 cmd_flags,
355 token);
356 cmd_params = (struct dprc_cmd_get_obj *)cmd.params;
357 cmd_params->obj_index = cpu_to_le32(obj_index);
358
359
360 err = mc_send_command(mc_io, &cmd);
361 if (err)
362 return err;
363
364
365 rsp_params = (struct dprc_rsp_get_obj *)cmd.params;
366 obj_desc->id = le32_to_cpu(rsp_params->id);
367 obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
368 obj_desc->irq_count = rsp_params->irq_count;
369 obj_desc->region_count = rsp_params->region_count;
370 obj_desc->state = le32_to_cpu(rsp_params->state);
371 obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
372 obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
373 obj_desc->flags = le16_to_cpu(rsp_params->flags);
374 strncpy(obj_desc->type, rsp_params->type, 16);
375 obj_desc->type[15] = '\0';
376 strncpy(obj_desc->label, rsp_params->label, 16);
377 obj_desc->label[15] = '\0';
378 return 0;
379}
380EXPORT_SYMBOL_GPL(dprc_get_obj);
381
382
383
384
385
386
387
388
389
390
391
392
393
394int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
395 u32 cmd_flags,
396 u16 token,
397 char *obj_type,
398 int obj_id,
399 u8 irq_index,
400 struct dprc_irq_cfg *irq_cfg)
401{
402 struct fsl_mc_command cmd = { 0 };
403 struct dprc_cmd_set_obj_irq *cmd_params;
404
405
406 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
407 cmd_flags,
408 token);
409 cmd_params = (struct dprc_cmd_set_obj_irq *)cmd.params;
410 cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
411 cmd_params->irq_index = irq_index;
412 cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
413 cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
414 cmd_params->obj_id = cpu_to_le32(obj_id);
415 strncpy(cmd_params->obj_type, obj_type, 16);
416 cmd_params->obj_type[15] = '\0';
417
418
419 return mc_send_command(mc_io, &cmd);
420}
421EXPORT_SYMBOL_GPL(dprc_set_obj_irq);
422
423
424
425
426
427
428
429
430
431
432
433
434
435int dprc_get_obj_region(struct fsl_mc_io *mc_io,
436 u32 cmd_flags,
437 u16 token,
438 char *obj_type,
439 int obj_id,
440 u8 region_index,
441 struct dprc_region_desc *region_desc)
442{
443 struct fsl_mc_command cmd = { 0 };
444 struct dprc_cmd_get_obj_region *cmd_params;
445 struct dprc_rsp_get_obj_region *rsp_params;
446 u16 major_ver, minor_ver;
447 int err;
448
449
450 err = dprc_get_api_version(mc_io, 0,
451 &major_ver,
452 &minor_ver);
453 if (err)
454 return err;
455
456
457
458
459
460
461
462 if (major_ver > 6 || (major_ver == 6 && minor_ver >= 3))
463 cmd.header =
464 mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG_V2,
465 cmd_flags, token);
466 else
467 cmd.header =
468 mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
469 cmd_flags, token);
470
471 cmd_params = (struct dprc_cmd_get_obj_region *)cmd.params;
472 cmd_params->obj_id = cpu_to_le32(obj_id);
473 cmd_params->region_index = region_index;
474 strncpy(cmd_params->obj_type, obj_type, 16);
475 cmd_params->obj_type[15] = '\0';
476
477
478 err = mc_send_command(mc_io, &cmd);
479 if (err)
480 return err;
481
482
483 rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params;
484 region_desc->base_offset = le64_to_cpu(rsp_params->base_offset);
485 region_desc->size = le32_to_cpu(rsp_params->size);
486 if (major_ver > 6 || (major_ver == 6 && minor_ver >= 3))
487 region_desc->base_address = le64_to_cpu(rsp_params->base_addr);
488 else
489 region_desc->base_address = 0;
490
491 return 0;
492}
493EXPORT_SYMBOL_GPL(dprc_get_obj_region);
494
495
496
497
498
499
500
501
502
503
504int dprc_get_api_version(struct fsl_mc_io *mc_io,
505 u32 cmd_flags,
506 u16 *major_ver,
507 u16 *minor_ver)
508{
509 struct fsl_mc_command cmd = { 0 };
510 int err;
511
512
513 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
514 cmd_flags, 0);
515
516
517 err = mc_send_command(mc_io, &cmd);
518 if (err)
519 return err;
520
521
522 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
523
524 return 0;
525}
526
527
528
529
530
531
532
533
534
535int dprc_get_container_id(struct fsl_mc_io *mc_io,
536 u32 cmd_flags,
537 int *container_id)
538{
539 struct fsl_mc_command cmd = { 0 };
540 int err;
541
542
543 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
544 cmd_flags,
545 0);
546
547
548 err = mc_send_command(mc_io, &cmd);
549 if (err)
550 return err;
551
552
553 *container_id = (int)mc_cmd_read_object_id(&cmd);
554
555 return 0;
556}
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573int dprc_get_connection(struct fsl_mc_io *mc_io,
574 u32 cmd_flags,
575 u16 token,
576 const struct dprc_endpoint *endpoint1,
577 struct dprc_endpoint *endpoint2,
578 int *state)
579{
580 struct dprc_cmd_get_connection *cmd_params;
581 struct dprc_rsp_get_connection *rsp_params;
582 struct fsl_mc_command cmd = { 0 };
583 int err, i;
584
585
586 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
587 cmd_flags,
588 token);
589 cmd_params = (struct dprc_cmd_get_connection *)cmd.params;
590 cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
591 cmd_params->ep1_interface_id = cpu_to_le16(endpoint1->if_id);
592 for (i = 0; i < 16; i++)
593 cmd_params->ep1_type[i] = endpoint1->type[i];
594
595
596 err = mc_send_command(mc_io, &cmd);
597 if (err)
598 return -ENOTCONN;
599
600
601 rsp_params = (struct dprc_rsp_get_connection *)cmd.params;
602 endpoint2->id = le32_to_cpu(rsp_params->ep2_id);
603 endpoint2->if_id = le16_to_cpu(rsp_params->ep2_interface_id);
604 *state = le32_to_cpu(rsp_params->state);
605 for (i = 0; i < 16; i++)
606 endpoint2->type[i] = rsp_params->ep2_type[i];
607
608 return 0;
609}
610