1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
10 #include "tf_session.h"
19 #include "tf_common.h"
23 tf_open_session(struct tf *tfp,
24 struct tf_open_session_parms *parms)
27 unsigned int domain, bus, slot, device;
28 struct tf_session_open_session_parms oparms;
30 TF_CHECK_PARMS2(tfp, parms);
32 /* Filter out any non-supported device types on the Core
33 * side. It is assumed that the Firmware will be supported if
34 * firmware open session succeeds.
36 if (parms->device_type != TF_DEVICE_TYPE_WH) {
38 "Unsupported device type %d\n",
43 /* Verify control channel and build the beginning of session_id */
44 rc = sscanf(parms->ctrl_chan_name,
52 "Failed to scan device ctrl_chan_name\n");
56 parms->session_id.internal.domain = domain;
57 parms->session_id.internal.bus = bus;
58 parms->session_id.internal.device = device;
59 oparms.open_cfg = parms;
61 rc = tf_session_open_session(tfp, &oparms);
62 /* Logging handled by tf_session_open_session */
67 "Session created, session_id:%d\n",
68 parms->session_id.id);
71 "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
72 parms->session_id.internal.domain,
73 parms->session_id.internal.bus,
74 parms->session_id.internal.device,
75 parms->session_id.internal.fw_session_id);
81 tf_attach_session(struct tf *tfp,
82 struct tf_attach_session_parms *parms)
85 unsigned int domain, bus, slot, device;
86 struct tf_session_attach_session_parms aparms;
88 TF_CHECK_PARMS2(tfp, parms);
90 /* Verify control channel */
91 rc = sscanf(parms->ctrl_chan_name,
99 "Failed to scan device ctrl_chan_name\n");
103 /* Verify 'attach' channel */
104 rc = sscanf(parms->attach_chan_name,
112 "Failed to scan device attach_chan_name\n");
116 /* Prepare return value of session_id, using ctrl_chan_name
117 * device values as it becomes the session id.
119 parms->session_id.internal.domain = domain;
120 parms->session_id.internal.bus = bus;
121 parms->session_id.internal.device = device;
122 aparms.attach_cfg = parms;
123 rc = tf_session_attach_session(tfp,
125 /* Logging handled by dev_bind */
130 "Attached to session, session_id:%d\n",
131 parms->session_id.id);
134 "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
135 parms->session_id.internal.domain,
136 parms->session_id.internal.bus,
137 parms->session_id.internal.device,
138 parms->session_id.internal.fw_session_id);
144 tf_close_session(struct tf *tfp)
147 struct tf_session_close_session_parms cparms = { 0 };
148 union tf_session_id session_id = { 0 };
151 TF_CHECK_PARMS1(tfp);
153 cparms.ref_count = &ref_count;
154 cparms.session_id = &session_id;
155 rc = tf_session_close_session(tfp,
157 /* Logging handled by tf_session_close_session */
162 "Closed session, session_id:%d, ref_count:%d\n",
163 cparms.session_id->id,
167 "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
168 cparms.session_id->internal.domain,
169 cparms.session_id->internal.bus,
170 cparms.session_id->internal.device,
171 cparms.session_id->internal.fw_session_id);
176 /** insert EM hash entry API
182 int tf_insert_em_entry(struct tf *tfp,
183 struct tf_insert_em_entry_parms *parms)
185 struct tf_session *tfs;
186 struct tf_dev_info *dev;
189 TF_CHECK_PARMS2(tfp, parms);
191 /* Retrieve the session information */
192 rc = tf_session_get_session(tfp, &tfs);
195 "%s: Failed to lookup session, rc:%s\n",
196 tf_dir_2_str(parms->dir),
201 /* Retrieve the device information */
202 rc = tf_session_get_device(tfs, &dev);
205 "%s: Failed to lookup device, rc:%s\n",
206 tf_dir_2_str(parms->dir),
211 if (parms->mem == TF_MEM_EXTERNAL &&
212 dev->ops->tf_dev_insert_ext_em_entry != NULL)
213 rc = dev->ops->tf_dev_insert_ext_em_entry(tfp, parms);
214 else if (parms->mem == TF_MEM_INTERNAL &&
215 dev->ops->tf_dev_insert_int_em_entry != NULL)
216 rc = dev->ops->tf_dev_insert_int_em_entry(tfp, parms);
222 "%s: EM insert failed, rc:%s\n",
223 tf_dir_2_str(parms->dir),
231 /** Delete EM hash entry API
237 int tf_delete_em_entry(struct tf *tfp,
238 struct tf_delete_em_entry_parms *parms)
240 struct tf_session *tfs;
241 struct tf_dev_info *dev;
244 TF_CHECK_PARMS2(tfp, parms);
246 /* Retrieve the session information */
247 rc = tf_session_get_session(tfp, &tfs);
250 "%s: Failed to lookup session, rc:%s\n",
251 tf_dir_2_str(parms->dir),
256 /* Retrieve the device information */
257 rc = tf_session_get_device(tfs, &dev);
260 "%s: Failed to lookup device, rc:%s\n",
261 tf_dir_2_str(parms->dir),
266 if (parms->mem == TF_MEM_EXTERNAL)
267 rc = dev->ops->tf_dev_delete_ext_em_entry(tfp, parms);
268 else if (parms->mem == TF_MEM_INTERNAL)
269 rc = dev->ops->tf_dev_delete_int_em_entry(tfp, parms);
275 "%s: EM delete failed, rc:%s\n",
276 tf_dir_2_str(parms->dir),
285 tf_alloc_identifier(struct tf *tfp,
286 struct tf_alloc_identifier_parms *parms)
289 struct tf_session *tfs;
290 struct tf_dev_info *dev;
291 struct tf_ident_alloc_parms aparms;
294 TF_CHECK_PARMS2(tfp, parms);
296 /* Can't do static initialization due to UT enum check */
297 memset(&aparms, 0, sizeof(struct tf_ident_alloc_parms));
299 /* Retrieve the session information */
300 rc = tf_session_get_session(tfp, &tfs);
303 "%s: Failed to lookup session, rc:%s\n",
304 tf_dir_2_str(parms->dir),
309 /* Retrieve the device information */
310 rc = tf_session_get_device(tfs, &dev);
313 "%s: Failed to lookup device, rc:%s\n",
314 tf_dir_2_str(parms->dir),
319 if (dev->ops->tf_dev_alloc_ident == NULL) {
322 "%s: Operation not supported, rc:%s\n",
323 tf_dir_2_str(parms->dir),
328 aparms.dir = parms->dir;
329 aparms.type = parms->ident_type;
331 rc = dev->ops->tf_dev_alloc_ident(tfp, &aparms);
334 "%s: Identifier allocation failed, rc:%s\n",
335 tf_dir_2_str(parms->dir),
346 tf_free_identifier(struct tf *tfp,
347 struct tf_free_identifier_parms *parms)
350 struct tf_session *tfs;
351 struct tf_dev_info *dev;
352 struct tf_ident_free_parms fparms;
354 TF_CHECK_PARMS2(tfp, parms);
356 /* Can't do static initialization due to UT enum check */
357 memset(&fparms, 0, sizeof(struct tf_ident_free_parms));
359 /* Retrieve the session information */
360 rc = tf_session_get_session(tfp, &tfs);
363 "%s: Failed to lookup session, rc:%s\n",
364 tf_dir_2_str(parms->dir),
369 /* Retrieve the device information */
370 rc = tf_session_get_device(tfs, &dev);
373 "%s: Failed to lookup device, rc:%s\n",
374 tf_dir_2_str(parms->dir),
379 if (dev->ops->tf_dev_free_ident == NULL) {
382 "%s: Operation not supported, rc:%s\n",
383 tf_dir_2_str(parms->dir),
388 fparms.dir = parms->dir;
389 fparms.type = parms->ident_type;
390 fparms.id = parms->id;
391 rc = dev->ops->tf_dev_free_ident(tfp, &fparms);
394 "%s: Identifier free failed, rc:%s\n",
395 tf_dir_2_str(parms->dir),
404 tf_alloc_tcam_entry(struct tf *tfp,
405 struct tf_alloc_tcam_entry_parms *parms)
408 struct tf_session *tfs;
409 struct tf_dev_info *dev;
410 struct tf_tcam_alloc_parms aparms = { 0 };
412 TF_CHECK_PARMS2(tfp, parms);
414 /* Retrieve the session information */
415 rc = tf_session_get_session(tfp, &tfs);
418 "%s: Failed to lookup session, rc:%s\n",
419 tf_dir_2_str(parms->dir),
424 /* Retrieve the device information */
425 rc = tf_session_get_device(tfs, &dev);
428 "%s: Failed to lookup device, rc:%s\n",
429 tf_dir_2_str(parms->dir),
434 if (dev->ops->tf_dev_alloc_tcam == NULL) {
437 "%s: Operation not supported, rc:%s\n",
438 tf_dir_2_str(parms->dir),
443 aparms.dir = parms->dir;
444 aparms.type = parms->tcam_tbl_type;
445 aparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
446 aparms.priority = parms->priority;
447 rc = dev->ops->tf_dev_alloc_tcam(tfp, &aparms);
450 "%s: TCAM allocation failed, rc:%s\n",
451 tf_dir_2_str(parms->dir),
456 parms->idx = aparms.idx;
462 tf_set_tcam_entry(struct tf *tfp,
463 struct tf_set_tcam_entry_parms *parms)
466 struct tf_session *tfs;
467 struct tf_dev_info *dev;
468 struct tf_tcam_set_parms sparms = { 0 };
470 TF_CHECK_PARMS2(tfp, parms);
472 /* Retrieve the session information */
473 rc = tf_session_get_session(tfp, &tfs);
476 "%s: Failed to lookup session, rc:%s\n",
477 tf_dir_2_str(parms->dir),
482 /* Retrieve the device information */
483 rc = tf_session_get_device(tfs, &dev);
486 "%s: Failed to lookup device, rc:%s\n",
487 tf_dir_2_str(parms->dir),
492 if (dev->ops->tf_dev_set_tcam == NULL) {
495 "%s: Operation not supported, rc:%s\n",
496 tf_dir_2_str(parms->dir),
501 sparms.dir = parms->dir;
502 sparms.type = parms->tcam_tbl_type;
503 sparms.idx = parms->idx;
504 sparms.key = parms->key;
505 sparms.mask = parms->mask;
506 sparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
507 sparms.result = parms->result;
508 sparms.result_size = TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits);
510 rc = dev->ops->tf_dev_set_tcam(tfp, &sparms);
513 "%s: TCAM set failed, rc:%s\n",
514 tf_dir_2_str(parms->dir),
523 tf_get_tcam_entry(struct tf *tfp __rte_unused,
524 struct tf_get_tcam_entry_parms *parms __rte_unused)
526 TF_CHECK_PARMS2(tfp, parms);
531 tf_free_tcam_entry(struct tf *tfp,
532 struct tf_free_tcam_entry_parms *parms)
535 struct tf_session *tfs;
536 struct tf_dev_info *dev;
537 struct tf_tcam_free_parms fparms = { 0 };
539 TF_CHECK_PARMS2(tfp, parms);
541 /* Retrieve the session information */
542 rc = tf_session_get_session(tfp, &tfs);
545 "%s: Failed to lookup session, rc:%s\n",
546 tf_dir_2_str(parms->dir),
551 /* Retrieve the device information */
552 rc = tf_session_get_device(tfs, &dev);
555 "%s: Failed to lookup device, rc:%s\n",
556 tf_dir_2_str(parms->dir),
561 if (dev->ops->tf_dev_free_tcam == NULL) {
564 "%s: Operation not supported, rc:%s\n",
565 tf_dir_2_str(parms->dir),
570 fparms.dir = parms->dir;
571 fparms.type = parms->tcam_tbl_type;
572 fparms.idx = parms->idx;
573 rc = dev->ops->tf_dev_free_tcam(tfp, &fparms);
576 "%s: TCAM free failed, rc:%s\n",
577 tf_dir_2_str(parms->dir),
586 tf_alloc_tbl_entry(struct tf *tfp,
587 struct tf_alloc_tbl_entry_parms *parms)
590 struct tf_session *tfs;
591 struct tf_dev_info *dev;
592 struct tf_tbl_alloc_parms aparms;
595 TF_CHECK_PARMS2(tfp, parms);
597 /* Can't do static initialization due to UT enum check */
598 memset(&aparms, 0, sizeof(struct tf_tbl_alloc_parms));
600 /* Retrieve the session information */
601 rc = tf_session_get_session(tfp, &tfs);
604 "%s: Failed to lookup session, rc:%s\n",
605 tf_dir_2_str(parms->dir),
610 /* Retrieve the device information */
611 rc = tf_session_get_device(tfs, &dev);
614 "%s: Failed to lookup device, rc:%s\n",
615 tf_dir_2_str(parms->dir),
620 aparms.dir = parms->dir;
621 aparms.type = parms->type;
623 aparms.tbl_scope_id = parms->tbl_scope_id;
625 if (parms->type == TF_TBL_TYPE_EXT) {
626 if (dev->ops->tf_dev_alloc_ext_tbl == NULL) {
629 "%s: Operation not supported, rc:%s\n",
630 tf_dir_2_str(parms->dir),
635 rc = dev->ops->tf_dev_alloc_ext_tbl(tfp, &aparms);
638 "%s: External table allocation failed, rc:%s\n",
639 tf_dir_2_str(parms->dir),
645 if (dev->ops->tf_dev_alloc_tbl == NULL) {
648 "%s: Operation not supported, rc:%s\n",
649 tf_dir_2_str(parms->dir),
654 rc = dev->ops->tf_dev_alloc_tbl(tfp, &aparms);
657 "%s: Table allocation failed, rc:%s\n",
658 tf_dir_2_str(parms->dir),
670 tf_free_tbl_entry(struct tf *tfp,
671 struct tf_free_tbl_entry_parms *parms)
674 struct tf_session *tfs;
675 struct tf_dev_info *dev;
676 struct tf_tbl_free_parms fparms;
678 TF_CHECK_PARMS2(tfp, parms);
680 /* Can't do static initialization due to UT enum check */
681 memset(&fparms, 0, sizeof(struct tf_tbl_free_parms));
683 /* Retrieve the session information */
684 rc = tf_session_get_session(tfp, &tfs);
687 "%s: Failed to lookup session, rc:%s\n",
688 tf_dir_2_str(parms->dir),
693 /* Retrieve the device information */
694 rc = tf_session_get_device(tfs, &dev);
697 "%s: Failed to lookup device, rc:%s\n",
698 tf_dir_2_str(parms->dir),
703 fparms.dir = parms->dir;
704 fparms.type = parms->type;
705 fparms.idx = parms->idx;
706 fparms.tbl_scope_id = parms->tbl_scope_id;
708 if (parms->type == TF_TBL_TYPE_EXT) {
709 if (dev->ops->tf_dev_free_ext_tbl == NULL) {
712 "%s: Operation not supported, rc:%s\n",
713 tf_dir_2_str(parms->dir),
718 rc = dev->ops->tf_dev_free_ext_tbl(tfp, &fparms);
721 "%s: Table free failed, rc:%s\n",
722 tf_dir_2_str(parms->dir),
727 if (dev->ops->tf_dev_free_tbl == NULL) {
730 "%s: Operation not supported, rc:%s\n",
731 tf_dir_2_str(parms->dir),
736 rc = dev->ops->tf_dev_free_tbl(tfp, &fparms);
739 "%s: Table free failed, rc:%s\n",
740 tf_dir_2_str(parms->dir),
750 tf_set_tbl_entry(struct tf *tfp,
751 struct tf_set_tbl_entry_parms *parms)
754 struct tf_session *tfs;
755 struct tf_dev_info *dev;
756 struct tf_tbl_set_parms sparms;
758 TF_CHECK_PARMS3(tfp, parms, parms->data);
760 /* Can't do static initialization due to UT enum check */
761 memset(&sparms, 0, sizeof(struct tf_tbl_set_parms));
763 /* Retrieve the session information */
764 rc = tf_session_get_session(tfp, &tfs);
767 "%s: Failed to lookup session, rc:%s\n",
768 tf_dir_2_str(parms->dir),
773 /* Retrieve the device information */
774 rc = tf_session_get_device(tfs, &dev);
777 "%s: Failed to lookup device, rc:%s\n",
778 tf_dir_2_str(parms->dir),
783 sparms.dir = parms->dir;
784 sparms.type = parms->type;
785 sparms.data = parms->data;
786 sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
787 sparms.idx = parms->idx;
788 sparms.tbl_scope_id = parms->tbl_scope_id;
790 if (parms->type == TF_TBL_TYPE_EXT) {
791 if (dev->ops->tf_dev_set_ext_tbl == NULL) {
794 "%s: Operation not supported, rc:%s\n",
795 tf_dir_2_str(parms->dir),
800 rc = dev->ops->tf_dev_set_ext_tbl(tfp, &sparms);
803 "%s: Table set failed, rc:%s\n",
804 tf_dir_2_str(parms->dir),
809 if (dev->ops->tf_dev_set_tbl == NULL) {
812 "%s: Operation not supported, rc:%s\n",
813 tf_dir_2_str(parms->dir),
818 rc = dev->ops->tf_dev_set_tbl(tfp, &sparms);
821 "%s: Table set failed, rc:%s\n",
822 tf_dir_2_str(parms->dir),
832 tf_get_tbl_entry(struct tf *tfp,
833 struct tf_get_tbl_entry_parms *parms)
836 struct tf_session *tfs;
837 struct tf_dev_info *dev;
838 struct tf_tbl_get_parms gparms;
840 TF_CHECK_PARMS3(tfp, parms, parms->data);
842 /* Can't do static initialization due to UT enum check */
843 memset(&gparms, 0, sizeof(struct tf_tbl_get_parms));
845 /* Retrieve the session information */
846 rc = tf_session_get_session(tfp, &tfs);
849 "%s: Failed to lookup session, rc:%s\n",
850 tf_dir_2_str(parms->dir),
855 /* Retrieve the device information */
856 rc = tf_session_get_device(tfs, &dev);
859 "%s: Failed to lookup device, rc:%s\n",
860 tf_dir_2_str(parms->dir),
865 if (dev->ops->tf_dev_get_tbl == NULL) {
868 "%s: Operation not supported, rc:%s\n",
869 tf_dir_2_str(parms->dir),
874 gparms.dir = parms->dir;
875 gparms.type = parms->type;
876 gparms.data = parms->data;
877 gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
878 gparms.idx = parms->idx;
879 rc = dev->ops->tf_dev_get_tbl(tfp, &gparms);
882 "%s: Table get failed, rc:%s\n",
883 tf_dir_2_str(parms->dir),
892 tf_bulk_get_tbl_entry(struct tf *tfp,
893 struct tf_bulk_get_tbl_entry_parms *parms)
896 struct tf_session *tfs;
897 struct tf_dev_info *dev;
898 struct tf_tbl_get_bulk_parms bparms;
900 TF_CHECK_PARMS2(tfp, parms);
902 /* Can't do static initialization due to UT enum check */
903 memset(&bparms, 0, sizeof(struct tf_tbl_get_bulk_parms));
905 /* Retrieve the session information */
906 rc = tf_session_get_session(tfp, &tfs);
909 "%s: Failed to lookup session, rc:%s\n",
910 tf_dir_2_str(parms->dir),
915 /* Retrieve the device information */
916 rc = tf_session_get_device(tfs, &dev);
919 "%s: Failed to lookup device, rc:%s\n",
920 tf_dir_2_str(parms->dir),
925 if (parms->type == TF_TBL_TYPE_EXT) {
926 /* Not supported, yet */
929 "%s, External table type not supported, rc:%s\n",
930 tf_dir_2_str(parms->dir),
936 /* Internal table type processing */
938 if (dev->ops->tf_dev_get_bulk_tbl == NULL) {
941 "%s: Operation not supported, rc:%s\n",
942 tf_dir_2_str(parms->dir),
947 bparms.dir = parms->dir;
948 bparms.type = parms->type;
949 bparms.starting_idx = parms->starting_idx;
950 bparms.num_entries = parms->num_entries;
951 bparms.entry_sz_in_bytes = parms->entry_sz_in_bytes;
952 bparms.physical_mem_addr = parms->physical_mem_addr;
953 rc = dev->ops->tf_dev_get_bulk_tbl(tfp, &bparms);
956 "%s: Table get bulk failed, rc:%s\n",
957 tf_dir_2_str(parms->dir),
966 tf_alloc_tbl_scope(struct tf *tfp,
967 struct tf_alloc_tbl_scope_parms *parms)
969 struct tf_session *tfs;
970 struct tf_dev_info *dev;
973 TF_CHECK_PARMS2(tfp, parms);
975 /* Retrieve the session information */
976 rc = tf_session_get_session(tfp, &tfs);
979 "Failed to lookup session, rc:%s\n",
984 /* Retrieve the device information */
985 rc = tf_session_get_device(tfs, &dev);
988 "Failed to lookup device, rc:%s\n",
993 if (dev->ops->tf_dev_alloc_tbl_scope != NULL) {
994 rc = dev->ops->tf_dev_alloc_tbl_scope(tfp, parms);
997 "Alloc table scope not supported by device\n");
1005 tf_free_tbl_scope(struct tf *tfp,
1006 struct tf_free_tbl_scope_parms *parms)
1008 struct tf_session *tfs;
1009 struct tf_dev_info *dev;
1012 TF_CHECK_PARMS2(tfp, parms);
1014 /* Retrieve the session information */
1015 rc = tf_session_get_session(tfp, &tfs);
1018 "Failed to lookup session, rc:%s\n",
1023 /* Retrieve the device information */
1024 rc = tf_session_get_device(tfs, &dev);
1027 "Failed to lookup device, rc:%s\n",
1032 if (dev->ops->tf_dev_free_tbl_scope) {
1033 rc = dev->ops->tf_dev_free_tbl_scope(tfp, parms);
1036 "Free table scope not supported by device\n");