1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
3 */
4
5 #ifndef _ROC_SSO_H_
6 #define _ROC_SSO_H_
7
8 struct roc_sso_hwgrp_qos {
9 uint16_t hwgrp;
10 uint8_t xaq_prcnt;
11 uint8_t iaq_prcnt;
12 uint8_t taq_prcnt;
13 };
14
15 struct roc_sso_hws_stats {
16 uint64_t arbitration;
17 };
18
19 struct roc_sso_hwgrp_stats {
20 uint64_t ws_pc;
21 uint64_t ext_pc;
22 uint64_t wa_pc;
23 uint64_t ts_pc;
24 uint64_t ds_pc;
25 uint64_t dq_pc;
26 uint64_t aw_status;
27 uint64_t page_cnt;
28 };
29
30 struct roc_sso_xaq_data {
31 uint32_t nb_xaq;
32 uint32_t nb_xae;
33 uint32_t xaq_lmt;
34 uint64_t aura_handle;
35 void *fc;
36 void *mem;
37 };
38
39 struct roc_sso {
40 struct plt_pci_device *pci_dev;
41 /* Public data. */
42 uint16_t max_hwgrp;
43 uint16_t max_hws;
44 uint16_t nb_hwgrp;
45 uint8_t nb_hws;
46 uintptr_t lmt_base;
47 struct roc_sso_xaq_data xaq;
48 /* HW Const. */
49 uint32_t xae_waes;
50 uint32_t xaq_buf_size;
51 uint32_t iue;
52 /* Private data. */
53 #define ROC_SSO_MEM_SZ (16 * 1024)
54 uint8_t reserved[ROC_SSO_MEM_SZ] __plt_cache_aligned;
55 } __plt_cache_aligned;
56
57 static __plt_always_inline uint64_t
roc_sso_hws_head_wait(uintptr_t base)58 roc_sso_hws_head_wait(uintptr_t base)
59 {
60 uintptr_t tag_op = base + SSOW_LF_GWS_TAG;
61 uint64_t tag;
62
63 #if defined(__aarch64__)
64 asm volatile(PLT_CPU_FEATURE_PREAMBLE
65 " ldr %[tag], [%[tag_op]] \n"
66 " tbnz %[tag], 35, done%= \n"
67 " sevl \n"
68 "rty%=: wfe \n"
69 " ldr %[tag], [%[tag_op]] \n"
70 " tbz %[tag], 35, rty%= \n"
71 "done%=: \n"
72 : [tag] "=&r"(tag)
73 : [tag_op] "r"(tag_op));
74 #else
75 do {
76 tag = plt_read64(tag_op);
77 } while (!(tag & BIT_ULL(35)));
78 #endif
79 return tag;
80 }
81
82 /* SSO device initialization */
83 int __roc_api roc_sso_dev_init(struct roc_sso *roc_sso);
84 int __roc_api roc_sso_dev_fini(struct roc_sso *roc_sso);
85
86 /* SSO device configuration */
87 int __roc_api roc_sso_rsrc_init(struct roc_sso *roc_sso, uint8_t nb_hws,
88 uint16_t nb_hwgrp);
89 void __roc_api roc_sso_rsrc_fini(struct roc_sso *roc_sso);
90 int __roc_api roc_sso_hwgrp_qos_config(struct roc_sso *roc_sso,
91 struct roc_sso_hwgrp_qos *qos,
92 uint8_t nb_qos, uint32_t nb_xaq);
93 int __roc_api roc_sso_hwgrp_alloc_xaq(struct roc_sso *roc_sso,
94 uint32_t npa_aura_id, uint16_t hwgrps);
95 int __roc_api roc_sso_hwgrp_release_xaq(struct roc_sso *roc_sso,
96 uint16_t hwgrps);
97 int __roc_api roc_sso_hwgrp_set_priority(struct roc_sso *roc_sso,
98 uint16_t hwgrp, uint8_t weight,
99 uint8_t affinity, uint8_t priority);
100 uint64_t __roc_api roc_sso_ns_to_gw(struct roc_sso *roc_sso, uint64_t ns);
101 int __roc_api roc_sso_hws_link(struct roc_sso *roc_sso, uint8_t hws,
102 uint16_t hwgrp[], uint16_t nb_hwgrp);
103 int __roc_api roc_sso_hws_unlink(struct roc_sso *roc_sso, uint8_t hws,
104 uint16_t hwgrp[], uint16_t nb_hwgrp);
105 int __roc_api roc_sso_hwgrp_hws_link_status(struct roc_sso *roc_sso,
106 uint8_t hws, uint16_t hwgrp);
107 uintptr_t __roc_api roc_sso_hws_base_get(struct roc_sso *roc_sso, uint8_t hws);
108 uintptr_t __roc_api roc_sso_hwgrp_base_get(struct roc_sso *roc_sso,
109 uint16_t hwgrp);
110 int __roc_api roc_sso_hwgrp_init_xaq_aura(struct roc_sso *roc_sso,
111 uint32_t nb_xae);
112 int __roc_api roc_sso_hwgrp_free_xaq_aura(struct roc_sso *roc_sso,
113 uint16_t nb_hwgrp);
114
115 /* Debug */
116 void __roc_api roc_sso_dump(struct roc_sso *roc_sso, uint8_t nb_hws,
117 uint16_t hwgrp, FILE *f);
118 int __roc_api roc_sso_hwgrp_stats_get(struct roc_sso *roc_sso, uint8_t hwgrp,
119 struct roc_sso_hwgrp_stats *stats);
120 int __roc_api roc_sso_hws_stats_get(struct roc_sso *roc_sso, uint8_t hws,
121 struct roc_sso_hws_stats *stats);
122
123 #endif /* _ROC_SSOW_H_ */
124