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 allocation 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 if (dev->ops->tf_dev_alloc_tbl == NULL) {
623 "%s: Operation not supported, rc:%s\n",
624 tf_dir_2_str(parms->dir),
629 aparms.dir = parms->dir;
630 aparms.type = parms->type;
632 rc = dev->ops->tf_dev_alloc_tbl(tfp, &aparms);
635 "%s: Table allocation failed, rc:%s\n",
636 tf_dir_2_str(parms->dir),
647 tf_free_tbl_entry(struct tf *tfp,
648 struct tf_free_tbl_entry_parms *parms)
651 struct tf_session *tfs;
652 struct tf_dev_info *dev;
653 struct tf_tbl_free_parms fparms;
655 TF_CHECK_PARMS2(tfp, parms);
657 /* Can't do static initialization due to UT enum check */
658 memset(&fparms, 0, sizeof(struct tf_tbl_free_parms));
660 /* Retrieve the session information */
661 rc = tf_session_get_session(tfp, &tfs);
664 "%s: Failed to lookup session, rc:%s\n",
665 tf_dir_2_str(parms->dir),
670 /* Retrieve the device information */
671 rc = tf_session_get_device(tfs, &dev);
674 "%s: Failed to lookup device, rc:%s\n",
675 tf_dir_2_str(parms->dir),
680 if (dev->ops->tf_dev_free_tbl == NULL) {
683 "%s: Operation not supported, rc:%s\n",
684 tf_dir_2_str(parms->dir),
689 fparms.dir = parms->dir;
690 fparms.type = parms->type;
691 fparms.idx = parms->idx;
692 rc = dev->ops->tf_dev_free_tbl(tfp, &fparms);
695 "%s: Table free failed, rc:%s\n",
696 tf_dir_2_str(parms->dir),
705 tf_set_tbl_entry(struct tf *tfp,
706 struct tf_set_tbl_entry_parms *parms)
709 struct tf_session *tfs;
710 struct tf_dev_info *dev;
711 struct tf_tbl_set_parms sparms;
713 TF_CHECK_PARMS3(tfp, parms, parms->data);
715 /* Can't do static initialization due to UT enum check */
716 memset(&sparms, 0, sizeof(struct tf_tbl_set_parms));
718 /* Retrieve the session information */
719 rc = tf_session_get_session(tfp, &tfs);
722 "%s: Failed to lookup session, rc:%s\n",
723 tf_dir_2_str(parms->dir),
728 /* Retrieve the device information */
729 rc = tf_session_get_device(tfs, &dev);
732 "%s: Failed to lookup device, rc:%s\n",
733 tf_dir_2_str(parms->dir),
738 if (dev->ops->tf_dev_set_tbl == NULL) {
741 "%s: Operation not supported, rc:%s\n",
742 tf_dir_2_str(parms->dir),
747 sparms.dir = parms->dir;
748 sparms.type = parms->type;
749 sparms.data = parms->data;
750 sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
751 sparms.idx = parms->idx;
752 rc = dev->ops->tf_dev_set_tbl(tfp, &sparms);
755 "%s: Table set failed, rc:%s\n",
756 tf_dir_2_str(parms->dir),
765 tf_get_tbl_entry(struct tf *tfp,
766 struct tf_get_tbl_entry_parms *parms)
769 struct tf_session *tfs;
770 struct tf_dev_info *dev;
771 struct tf_tbl_get_parms gparms;
773 TF_CHECK_PARMS3(tfp, parms, parms->data);
775 /* Can't do static initialization due to UT enum check */
776 memset(&gparms, 0, sizeof(struct tf_tbl_get_parms));
778 /* Retrieve the session information */
779 rc = tf_session_get_session(tfp, &tfs);
782 "%s: Failed to lookup session, rc:%s\n",
783 tf_dir_2_str(parms->dir),
788 /* Retrieve the device information */
789 rc = tf_session_get_device(tfs, &dev);
792 "%s: Failed to lookup device, rc:%s\n",
793 tf_dir_2_str(parms->dir),
798 if (dev->ops->tf_dev_get_tbl == NULL) {
801 "%s: Operation not supported, rc:%s\n",
802 tf_dir_2_str(parms->dir),
807 gparms.dir = parms->dir;
808 gparms.type = parms->type;
809 gparms.data = parms->data;
810 gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
811 gparms.idx = parms->idx;
812 rc = dev->ops->tf_dev_get_tbl(tfp, &gparms);
815 "%s: Table get failed, rc:%s\n",
816 tf_dir_2_str(parms->dir),
825 tf_bulk_get_tbl_entry(struct tf *tfp,
826 struct tf_bulk_get_tbl_entry_parms *parms)
829 struct tf_session *tfs;
830 struct tf_dev_info *dev;
831 struct tf_tbl_get_bulk_parms bparms;
833 TF_CHECK_PARMS2(tfp, parms);
835 /* Can't do static initialization due to UT enum check */
836 memset(&bparms, 0, sizeof(struct tf_tbl_get_bulk_parms));
838 /* Retrieve the session information */
839 rc = tf_session_get_session(tfp, &tfs);
842 "%s: Failed to lookup session, rc:%s\n",
843 tf_dir_2_str(parms->dir),
848 /* Retrieve the device information */
849 rc = tf_session_get_device(tfs, &dev);
852 "%s: Failed to lookup device, rc:%s\n",
853 tf_dir_2_str(parms->dir),
858 if (parms->type == TF_TBL_TYPE_EXT) {
859 /* Not supported, yet */
862 "%s, External table type not supported, rc:%s\n",
863 tf_dir_2_str(parms->dir),
869 /* Internal table type processing */
871 if (dev->ops->tf_dev_get_bulk_tbl == NULL) {
874 "%s: Operation not supported, rc:%s\n",
875 tf_dir_2_str(parms->dir),
880 bparms.dir = parms->dir;
881 bparms.type = parms->type;
882 bparms.starting_idx = parms->starting_idx;
883 bparms.num_entries = parms->num_entries;
884 bparms.entry_sz_in_bytes = parms->entry_sz_in_bytes;
885 bparms.physical_mem_addr = parms->physical_mem_addr;
886 rc = dev->ops->tf_dev_get_bulk_tbl(tfp, &bparms);
889 "%s: Table get bulk failed, rc:%s\n",
890 tf_dir_2_str(parms->dir),
899 tf_alloc_tbl_scope(struct tf *tfp,
900 struct tf_alloc_tbl_scope_parms *parms)
902 struct tf_session *tfs;
903 struct tf_dev_info *dev;
906 TF_CHECK_PARMS2(tfp, parms);
908 /* Retrieve the session information */
909 rc = tf_session_get_session(tfp, &tfs);
912 "Failed to lookup session, rc:%s\n",
917 /* Retrieve the device information */
918 rc = tf_session_get_device(tfs, &dev);
921 "Failed to lookup device, rc:%s\n",
926 if (dev->ops->tf_dev_alloc_tbl_scope != NULL) {
927 rc = dev->ops->tf_dev_alloc_tbl_scope(tfp, parms);
930 "Alloc table scope not supported by device\n");
938 tf_free_tbl_scope(struct tf *tfp,
939 struct tf_free_tbl_scope_parms *parms)
941 struct tf_session *tfs;
942 struct tf_dev_info *dev;
945 TF_CHECK_PARMS2(tfp, parms);
947 /* Retrieve the session information */
948 rc = tf_session_get_session(tfp, &tfs);
951 "Failed to lookup session, rc:%s\n",
956 /* Retrieve the device information */
957 rc = tf_session_get_device(tfs, &dev);
960 "Failed to lookup device, rc:%s\n",
965 if (dev->ops->tf_dev_free_tbl_scope) {
966 rc = dev->ops->tf_dev_free_tbl_scope(tfp, parms);
969 "Free table scope not supported by device\n");