1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */
6 #define FBNIC_BOUNDS(section) { \
7 .start = FBNIC_CSR_START_##section, \
8 .end = FBNIC_CSR_END_##section + 1, \
11 struct fbnic_csr_bounds
{
16 static const struct fbnic_csr_bounds fbnic_csr_sects
[] = {
18 FBNIC_BOUNDS(INTR_CQ
),
22 FBNIC_BOUNDS(TCE_RAM
),
31 FBNIC_BOUNDS(MAC_MAC
),
33 FBNIC_BOUNDS(PUL_USER
),
35 FBNIC_BOUNDS(RPC_RAM
),
38 #define FBNIC_RPC_TCAM_ACT_DW_PER_ENTRY 14
39 #define FBNIC_RPC_TCAM_ACT_NUM_ENTRIES 64
41 #define FBNIC_RPC_TCAM_MACDA_DW_PER_ENTRY 4
42 #define FBNIC_RPC_TCAM_MACDA_NUM_ENTRIES 32
44 #define FBNIC_RPC_TCAM_OUTER_IPSRC_DW_PER_ENTRY 9
45 #define FBNIC_RPC_TCAM_OUTER_IPSRC_NUM_ENTRIES 8
47 #define FBNIC_RPC_TCAM_OUTER_IPDST_DW_PER_ENTRY 9
48 #define FBNIC_RPC_TCAM_OUTER_IPDST_NUM_ENTRIES 8
50 #define FBNIC_RPC_TCAM_IPSRC_DW_PER_ENTRY 9
51 #define FBNIC_RPC_TCAM_IPSRC_NUM_ENTRIES 8
53 #define FBNIC_RPC_TCAM_IPDST_DW_PER_ENTRY 9
54 #define FBNIC_RPC_TCAM_IPDST_NUM_ENTRIES 8
56 #define FBNIC_RPC_RSS_TBL_DW_PER_ENTRY 2
57 #define FBNIC_RPC_RSS_TBL_NUM_ENTRIES 256
59 static void fbnic_csr_get_regs_rpc_ram(struct fbnic_dev
*fbd
, u32
**data_p
)
61 u32 start
= FBNIC_CSR_START_RPC_RAM
;
62 u32 end
= FBNIC_CSR_END_RPC_RAM
;
69 /* FBNIC_RPC_TCAM_ACT */
70 for (i
= 0; i
< FBNIC_RPC_TCAM_ACT_NUM_ENTRIES
; i
++) {
71 for (j
= 0; j
< FBNIC_RPC_TCAM_ACT_DW_PER_ENTRY
; j
++)
72 *(data
++) = rd32(fbd
, FBNIC_RPC_TCAM_ACT(i
, j
));
75 /* FBNIC_RPC_TCAM_MACDA */
76 for (i
= 0; i
< FBNIC_RPC_TCAM_MACDA_NUM_ENTRIES
; i
++) {
77 for (j
= 0; j
< FBNIC_RPC_TCAM_MACDA_DW_PER_ENTRY
; j
++)
78 *(data
++) = rd32(fbd
, FBNIC_RPC_TCAM_MACDA(i
, j
));
81 /* FBNIC_RPC_TCAM_OUTER_IPSRC */
82 for (i
= 0; i
< FBNIC_RPC_TCAM_OUTER_IPSRC_NUM_ENTRIES
; i
++) {
83 for (j
= 0; j
< FBNIC_RPC_TCAM_OUTER_IPSRC_DW_PER_ENTRY
; j
++)
84 *(data
++) = rd32(fbd
, FBNIC_RPC_TCAM_OUTER_IPSRC(i
, j
));
87 /* FBNIC_RPC_TCAM_OUTER_IPDST */
88 for (i
= 0; i
< FBNIC_RPC_TCAM_OUTER_IPDST_NUM_ENTRIES
; i
++) {
89 for (j
= 0; j
< FBNIC_RPC_TCAM_OUTER_IPDST_DW_PER_ENTRY
; j
++)
90 *(data
++) = rd32(fbd
, FBNIC_RPC_TCAM_OUTER_IPDST(i
, j
));
93 /* FBNIC_RPC_TCAM_IPSRC */
94 for (i
= 0; i
< FBNIC_RPC_TCAM_IPSRC_NUM_ENTRIES
; i
++) {
95 for (j
= 0; j
< FBNIC_RPC_TCAM_IPSRC_DW_PER_ENTRY
; j
++)
96 *(data
++) = rd32(fbd
, FBNIC_RPC_TCAM_IPSRC(i
, j
));
99 /* FBNIC_RPC_TCAM_IPDST */
100 for (i
= 0; i
< FBNIC_RPC_TCAM_IPDST_NUM_ENTRIES
; i
++) {
101 for (j
= 0; j
< FBNIC_RPC_TCAM_IPDST_DW_PER_ENTRY
; j
++)
102 *(data
++) = rd32(fbd
, FBNIC_RPC_TCAM_IPDST(i
, j
));
105 /* FBNIC_RPC_RSS_TBL */
106 for (i
= 0; i
< FBNIC_RPC_RSS_TBL_NUM_ENTRIES
; i
++) {
107 for (j
= 0; j
< FBNIC_RPC_RSS_TBL_DW_PER_ENTRY
; j
++)
108 *(data
++) = rd32(fbd
, FBNIC_RPC_RSS_TBL(i
, j
));
114 void fbnic_csr_get_regs(struct fbnic_dev
*fbd
, u32
*data
, u32
*regs_version
)
116 const struct fbnic_csr_bounds
*bound
;
122 /* Skip RPC_RAM section which cannot be dumped linearly */
123 for (i
= 0, bound
= fbnic_csr_sects
;
124 i
< ARRAY_SIZE(fbnic_csr_sects
) - 1; i
++, ++bound
) {
125 *(data
++) = bound
->start
;
126 *(data
++) = bound
->end
- 1;
127 for (j
= bound
->start
; j
< bound
->end
; j
++)
128 *(data
++) = rd32(fbd
, j
);
131 /* Dump the RPC_RAM as special case registers */
132 fbnic_csr_get_regs_rpc_ram(fbd
, &data
);
134 WARN_ON(data
- start
!= fbnic_csr_regs_len(fbd
));
137 int fbnic_csr_regs_len(struct fbnic_dev
*fbd
)
141 /* Dump includes start and end information of each section
142 * which results in an offset of 2
144 for (i
= 0; i
< ARRAY_SIZE(fbnic_csr_sects
); i
++)
145 len
+= fbnic_csr_sects
[i
].end
- fbnic_csr_sects
[i
].start
+ 2;