iw_cxgb_dbg.c revision 237263
1
2/**************************************************************************
3
4Copyright (c) 2007, Chelsio Inc.
5All rights reserved.
6
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions are met:
9
10 1. Redistributions of source code must retain the above copyright notice,
11    this list of conditions and the following disclaimer.
12
13 2. Neither the name of the Chelsio Corporation nor the names of its
14    contributors may be used to endorse or promote products derived from
15    this software without specific prior written permission.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27POSSIBILITY OF SUCH DAMAGE.
28
29***************************************************************************/
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_dbg.c 237263 2012-06-19 07:34:13Z np $");
32
33#include "opt_inet.h"
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/bus.h>
39#include <sys/pciio.h>
40#include <sys/conf.h>
41#include <machine/bus.h>
42#include <machine/resource.h>
43#include <sys/bus_dma.h>
44#include <sys/rman.h>
45#include <sys/ioccom.h>
46#include <sys/mbuf.h>
47#include <sys/mutex.h>
48#include <sys/rwlock.h>
49#include <sys/linker.h>
50#include <sys/firmware.h>
51#include <sys/socket.h>
52#include <sys/sockio.h>
53#include <sys/smp.h>
54#include <sys/sysctl.h>
55#include <sys/syslog.h>
56#include <sys/queue.h>
57#include <sys/taskqueue.h>
58#include <sys/proc.h>
59#include <sys/queue.h>
60#include <sys/libkern.h>
61
62#include <netinet/in.h>
63
64#include <rdma/ib_verbs.h>
65#include <rdma/ib_umem.h>
66#include <rdma/ib_user_verbs.h>
67#include <linux/idr.h>
68#include <ulp/iw_cxgb/iw_cxgb_ib_intfc.h>
69
70#if defined(INVARIANTS) && defined(TCP_OFFLOAD)
71#include <cxgb_include.h>
72#include <ulp/iw_cxgb/iw_cxgb_wr.h>
73#include <ulp/iw_cxgb/iw_cxgb_hal.h>
74#include <ulp/iw_cxgb/iw_cxgb_provider.h>
75#include <ulp/iw_cxgb/iw_cxgb_cm.h>
76#include <ulp/iw_cxgb/iw_cxgb.h>
77#include <ulp/iw_cxgb/iw_cxgb_resource.h>
78#include <ulp/iw_cxgb/iw_cxgb_user.h>
79
80static int
81cxio_rdma_get_mem(struct cxio_rdev *rdev, struct ch_mem_range *m)
82{
83	struct adapter *sc = rdev->adap;
84	struct mc7 *mem;
85
86	if ((m->addr & 7) || (m->len & 7))
87		return (EINVAL);
88	if (m->mem_id == MEM_CM)
89		mem = &sc->cm;
90	else if (m->mem_id == MEM_PMRX)
91		mem = &sc->pmrx;
92	else if (m->mem_id == MEM_PMTX)
93		mem = &sc->pmtx;
94	else
95		return (EINVAL);
96
97	return (t3_mc7_bd_read(mem, m->addr/8, m->len/8, (u64 *)m->buf));
98}
99
100void cxio_dump_tpt(struct cxio_rdev *rdev, uint32_t stag)
101{
102	struct ch_mem_range m;
103	u64 *data;
104	u32 addr;
105	int rc;
106	int size = 32;
107
108	m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
109	if (m.buf == NULL) {
110		CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
111		return;
112	}
113	m.mem_id = MEM_PMRX;
114	m.addr = (stag >> 8) * 32 + rdev->rnic_info.tpt_base;
115	m.len = size;
116	CTR3(KTR_IW_CXGB, "%s TPT addr 0x%x len %d", __FUNCTION__, m.addr, m.len);
117
118	rc = cxio_rdma_get_mem(rdev, &m);
119	if (rc) {
120		CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
121		free(m.buf, M_DEVBUF);
122		return;
123	}
124
125	data = (u64 *)m.buf;
126	addr = m.addr;
127	while (size > 0) {
128		CTR2(KTR_IW_CXGB, "TPT %08x: %016llx", addr, (unsigned long long) *data);
129		size -= 8;
130		data++;
131		addr += 8;
132	}
133	free(m.buf, M_DEVBUF);
134}
135
136void cxio_dump_pbl(struct cxio_rdev *rdev, uint32_t pbl_addr, uint32_t len, u8 shift)
137{
138	struct ch_mem_range m;
139	u64 *data;
140	u32 addr;
141	int rc;
142	int size, npages;
143
144	shift += 12;
145	npages = (len + (1ULL << shift) - 1) >> shift;
146	size = npages * sizeof(u64);
147	m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
148	if (m.buf == NULL) {
149		CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
150		return;
151	}
152	m.mem_id = MEM_PMRX;
153	m.addr = pbl_addr;
154	m.len = size;
155	CTR4(KTR_IW_CXGB, "%s PBL addr 0x%x len %d depth %d",
156		__FUNCTION__, m.addr, m.len, npages);
157
158	rc = cxio_rdma_get_mem(rdev, &m);
159	if (rc) {
160		CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
161		free(m.buf, M_DEVBUF);
162		return;
163	}
164
165	data = (u64 *)m.buf;
166	addr = m.addr;
167	while (size > 0) {
168		CTR2(KTR_IW_CXGB, "PBL %08x: %016llx", addr, (unsigned long long) *data);
169		size -= 8;
170		data++;
171		addr += 8;
172	}
173	free(m.buf, M_DEVBUF);
174}
175
176void cxio_dump_wqe(union t3_wr *wqe)
177{
178	uint64_t *data = (uint64_t *)wqe;
179	uint32_t size = (uint32_t)(be64toh(*data) & 0xff);
180
181	if (size == 0)
182		size = 8;
183	while (size > 0) {
184		CTR2(KTR_IW_CXGB, "WQE %p: %016llx", data,
185		     (unsigned long long) be64toh(*data));
186		size--;
187		data++;
188	}
189}
190
191void cxio_dump_wce(struct t3_cqe *wce)
192{
193	uint64_t *data = (uint64_t *)wce;
194	int size = sizeof(*wce);
195
196	while (size > 0) {
197		CTR2(KTR_IW_CXGB, "WCE %p: %016llx", data,
198		     (unsigned long long) be64toh(*data));
199		size -= 8;
200		data++;
201	}
202}
203
204void cxio_dump_rqt(struct cxio_rdev *rdev, uint32_t hwtid, int nents)
205{
206	struct ch_mem_range m;
207	int size = nents * 64;
208	u64 *data;
209	u32 addr;
210	int rc;
211
212	m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
213	if (m.buf == NULL) {
214		CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
215		return;
216	}
217	m.mem_id = MEM_PMRX;
218	m.addr = ((hwtid)<<10) + rdev->rnic_info.rqt_base;
219	m.len = size;
220	CTR3(KTR_IW_CXGB, "%s RQT addr 0x%x len %d", __FUNCTION__, m.addr, m.len);
221
222	rc = cxio_rdma_get_mem(rdev, &m);
223	if (rc) {
224		CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
225		free(m.buf, M_DEVBUF);
226		return;
227	}
228
229	data = (u64 *)m.buf;
230	addr = m.addr;
231	while (size > 0) {
232		CTR2(KTR_IW_CXGB, "RQT %08x: %016llx", addr, (unsigned long long) *data);
233		size -= 8;
234		data++;
235		addr += 8;
236	}
237	free(m.buf, M_DEVBUF);
238}
239
240void cxio_dump_tcb(struct cxio_rdev *rdev, uint32_t hwtid)
241{
242	struct ch_mem_range m;
243	int size = TCB_SIZE;
244	uint32_t *data;
245	uint32_t addr;
246	int rc;
247
248	m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
249	if (m.buf == NULL) {
250		CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
251		return;
252	}
253	m.mem_id = MEM_CM;
254	m.addr = hwtid * size;
255	m.len = size;
256	CTR3(KTR_IW_CXGB, "%s TCB %d len %d", __FUNCTION__, m.addr, m.len);
257
258	rc = cxio_rdma_get_mem(rdev, &m);
259	if (rc) {
260		CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
261		free(m.buf, M_DEVBUF);
262		return;
263	}
264
265	data = (uint32_t *)m.buf;
266	addr = m.addr;
267	while (size > 0) {
268		printf("%2u: %08x %08x %08x %08x %08x %08x %08x %08x\n",
269			addr,
270			*(data+2), *(data+3), *(data),*(data+1),
271			*(data+6), *(data+7), *(data+4), *(data+5));
272		size -= 32;
273		data += 8;
274		addr += 32;
275	}
276	free(m.buf, M_DEVBUF);
277}
278#endif
279