2 * Copyright 2007-2009 Solarflare Communications Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
31 #include "efx_types.h"
39 __in efsys_mem_t *esmp,
44 uint32_t stop = start + n;
45 efsys_dma_addr_t addr;
50 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
51 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
53 if (stop >= EFX_BUF_TBL_SIZE) {
58 /* Add the entries into the buffer table */
59 addr = EFSYS_MEM_ADDR(esmp);
60 for (id = start; id != stop; id++) {
61 EFX_POPULATE_QWORD_5(qword,
62 FRF_AZ_IP_DAT_BUF_SIZE, 0, FRF_AZ_BUF_ADR_REGION, 0,
63 FRF_AZ_BUF_ADR_FBUF_DW0,
64 (uint32_t)((addr >> 12) & 0xffffffff),
65 FRF_AZ_BUF_ADR_FBUF_DW1,
66 (uint32_t)((addr >> 12) >> 32),
67 FRF_AZ_BUF_OWNER_ID_FBUF, 0);
69 EFX_BAR_TBL_WRITEQ(enp, FR_AZ_BUF_FULL_TBL,
75 EFSYS_PROBE2(buf, uint32_t, start, uint32_t, stop - 1);
77 /* Flush the write buffer */
78 EFX_POPULATE_OWORD_2(oword, FRF_AZ_BUF_UPD_CMD, 1,
79 FRF_AZ_BUF_CLR_CMD, 0);
80 EFX_BAR_WRITEO(enp, FR_AZ_BUF_TBL_UPD_REG, &oword);
82 /* Poll for the last entry being written to the buffer table */
83 EFSYS_ASSERT3U(id, ==, stop);
88 EFSYS_PROBE1(wait, unsigned int, count);
93 EFX_BAR_TBL_READQ(enp, FR_AZ_BUF_FULL_TBL,
96 if (EFX_QWORD_FIELD(qword, FRF_AZ_BUF_ADR_FBUF_DW0) ==
97 (uint32_t)((addr >> 12) & 0xffffffff) &&
98 EFX_QWORD_FIELD(qword, FRF_AZ_BUF_ADR_FBUF_DW1) ==
99 (uint32_t)((addr >> 12) >> 32))
102 } while (++count < 100);
108 /* Verify the rest of the entries in the buffer table */
109 while (--id != start) {
110 addr -= EFX_BUF_SIZE;
112 /* Read the buffer table entry */
113 EFX_BAR_TBL_READQ(enp, FR_AZ_BUF_FULL_TBL,
116 if (EFX_QWORD_FIELD(qword, FRF_AZ_BUF_ADR_FBUF_DW0) !=
117 (uint32_t)((addr >> 12) & 0xffffffff) ||
118 EFX_QWORD_FIELD(qword, FRF_AZ_BUF_ADR_FBUF_DW1) !=
119 (uint32_t)((addr >> 12) >> 32)) {
135 EFX_POPULATE_OWORD_4(oword, FRF_AZ_BUF_UPD_CMD, 0,
136 FRF_AZ_BUF_CLR_CMD, 1, FRF_AZ_BUF_CLR_END_ID, id - 1,
137 FRF_AZ_BUF_CLR_START_ID, start);
138 EFX_BAR_WRITEO(enp, FR_AZ_BUF_TBL_UPD_REG, &oword);
141 EFSYS_PROBE1(fail1, int, rc);
147 efx_sram_buf_tbl_clear(
154 uint32_t stop = start + n;
156 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
157 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
159 EFSYS_ASSERT3U(stop, <, EFX_BUF_TBL_SIZE);
161 EFSYS_PROBE2(buf, uint32_t, start, uint32_t, stop - 1);
163 EFX_POPULATE_OWORD_4(oword, FRF_AZ_BUF_UPD_CMD, 0,
164 FRF_AZ_BUF_CLR_CMD, 1, FRF_AZ_BUF_CLR_END_ID, stop - 1,
165 FRF_AZ_BUF_CLR_START_ID, start);
166 EFX_BAR_WRITEO(enp, FR_AZ_BUF_TBL_UPD_REG, &oword);
173 efx_sram_byte_increment_set(
175 __in boolean_t negate,
176 __out efx_qword_t *eqp)
178 size_t offset = row * FR_AZ_SRM_DBG_REG_STEP;
181 _NOTE(ARGUNUSED(negate))
183 for (index = 0; index < sizeof (efx_qword_t); index++)
184 eqp->eq_u8[index] = offset + index;
188 efx_sram_all_the_same_set(
190 __in boolean_t negate,
191 __out efx_qword_t *eqp)
193 _NOTE(ARGUNUSED(row))
198 EFX_ZERO_QWORD(*eqp);
202 efx_sram_bit_alternate_set(
204 __in boolean_t negate,
205 __out efx_qword_t *eqp)
207 _NOTE(ARGUNUSED(row))
209 EFX_POPULATE_QWORD_2(*eqp,
210 EFX_DWORD_0, (negate) ? 0x55555555 : 0xaaaaaaaa,
211 EFX_DWORD_1, (negate) ? 0x55555555 : 0xaaaaaaaa);
215 efx_sram_byte_alternate_set(
217 __in boolean_t negate,
218 __out efx_qword_t *eqp)
220 _NOTE(ARGUNUSED(row))
222 EFX_POPULATE_QWORD_2(*eqp,
223 EFX_DWORD_0, (negate) ? 0x00ff00ff : 0xff00ff00,
224 EFX_DWORD_1, (negate) ? 0x00ff00ff : 0xff00ff00);
228 efx_sram_byte_changing_set(
230 __in boolean_t negate,
231 __out efx_qword_t *eqp)
233 size_t offset = row * FR_AZ_SRM_DBG_REG_STEP;
236 for (index = 0; index < sizeof (efx_qword_t); index++) {
239 if (offset / 256 == 0)
240 byte = (uint8_t)((offset % 257) % 256);
242 byte = (uint8_t)(~((offset - 8) % 257) % 256);
244 eqp->eq_u8[index] = (negate) ? ~byte : byte;
249 efx_sram_bit_sweep_set(
251 __in boolean_t negate,
252 __out efx_qword_t *eqp)
254 size_t offset = row * FR_AZ_SRM_DBG_REG_STEP;
258 EFX_CLEAR_QWORD_BIT(*eqp, (offset / sizeof (efx_qword_t)) % 64);
260 EFX_ZERO_QWORD(*eqp);
261 EFX_SET_QWORD_BIT(*eqp, (offset / sizeof (efx_qword_t)) % 64);
265 efx_sram_pattern_fn_t __cs __efx_sram_pattern_fns[] = {
266 efx_sram_byte_increment_set,
267 efx_sram_all_the_same_set,
268 efx_sram_bit_alternate_set,
269 efx_sram_byte_alternate_set,
270 efx_sram_byte_changing_set,
271 efx_sram_bit_sweep_set
277 __in efx_pattern_type_t type)
279 efx_nic_ops_t *enop = enp->en_enop;
280 efx_sram_pattern_fn_t func;
282 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
284 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_NIC);
286 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_RX));
287 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_TX));
288 EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_EV));
290 /* Select pattern generator */
291 EFSYS_ASSERT3U(type, <, EFX_PATTERN_NTYPES);
292 func = __efx_sram_pattern_fns[type];
294 return (enop->eno_sram_test(enp, func));
297 #endif /* EFSYS_OPT_DIAG */