iw_cxgb_dbg.c revision 237263
1139825Simp
2148078Srwatson/**************************************************************************
3148078Srwatson
4148078SrwatsonCopyright (c) 2007, Chelsio Inc.
592654SjeffAll rights reserved.
692654Sjeff
792654SjeffRedistribution and use in source and binary forms, with or without
892654Sjeffmodification, are permitted provided that the following conditions are met:
992654Sjeff
1092654Sjeff 1. Redistributions of source code must retain the above copyright notice,
1192654Sjeff    this list of conditions and the following disclaimer.
1292654Sjeff
1392654Sjeff 2. Neither the name of the Chelsio Corporation nor the names of its
1492654Sjeff    contributors may be used to endorse or promote products derived from
1592654Sjeff    this software without specific prior written permission.
1692654Sjeff
1792654SjeffTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1892654SjeffAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1992654SjeffIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2092654SjeffARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2192654SjeffLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2292654SjeffCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2392654SjeffSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2492654SjeffINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2592654SjeffCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2692654SjeffARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2792654SjeffPOSSIBILITY OF SUCH DAMAGE.
2892654Sjeff
2992654Sjeff***************************************************************************/
3092654Sjeff#include <sys/cdefs.h>
3192654Sjeff__FBSDID("$FreeBSD: head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_dbg.c 237263 2012-06-19 07:34:13Z np $");
3292654Sjeff
3392654Sjeff#include "opt_inet.h"
3492654Sjeff
3592654Sjeff#include <sys/param.h>
3692654Sjeff#include <sys/systm.h>
3792654Sjeff#include <sys/kernel.h>
3892654Sjeff#include <sys/bus.h>
3992654Sjeff#include <sys/pciio.h>
4092654Sjeff#include <sys/conf.h>
4192654Sjeff#include <machine/bus.h>
4292654Sjeff#include <machine/resource.h>
4392654Sjeff#include <sys/bus_dma.h>
4492654Sjeff#include <sys/rman.h>
4592654Sjeff#include <sys/ioccom.h>
4692654Sjeff#include <sys/mbuf.h>
47129906Sbmilekic#include <sys/mutex.h>
4892654Sjeff#include <sys/rwlock.h>
4992654Sjeff#include <sys/linker.h>
5092654Sjeff#include <sys/firmware.h>
51166213Smohans#include <sys/socket.h>
52166213Smohans#include <sys/sockio.h>
5392654Sjeff#include <sys/smp.h>
5492654Sjeff#include <sys/sysctl.h>
5592654Sjeff#include <sys/syslog.h>
5692654Sjeff#include <sys/queue.h>
5792654Sjeff#include <sys/taskqueue.h>
5892654Sjeff#include <sys/proc.h>
5992654Sjeff#include <sys/queue.h>
60132987Sgreen#include <sys/libkern.h>
6192654Sjeff
6292654Sjeff#include <netinet/in.h>
63132987Sgreen
64132987Sgreen#include <rdma/ib_verbs.h>
6592654Sjeff#include <rdma/ib_umem.h>
6692654Sjeff#include <rdma/ib_user_verbs.h>
6792654Sjeff#include <linux/idr.h>
68105689Ssheldonh#include <ulp/iw_cxgb/iw_cxgb_ib_intfc.h>
6992654Sjeff
70132987Sgreen#if defined(INVARIANTS) && defined(TCP_OFFLOAD)
7192654Sjeff#include <cxgb_include.h>
7292654Sjeff#include <ulp/iw_cxgb/iw_cxgb_wr.h>
7392654Sjeff#include <ulp/iw_cxgb/iw_cxgb_hal.h>
7492654Sjeff#include <ulp/iw_cxgb/iw_cxgb_provider.h>
7592654Sjeff#include <ulp/iw_cxgb/iw_cxgb_cm.h>
7692654Sjeff#include <ulp/iw_cxgb/iw_cxgb.h>
7792654Sjeff#include <ulp/iw_cxgb/iw_cxgb_resource.h>
7892654Sjeff#include <ulp/iw_cxgb/iw_cxgb_user.h>
7992654Sjeff
8092654Sjeffstatic int
8192654Sjeffcxio_rdma_get_mem(struct cxio_rdev *rdev, struct ch_mem_range *m)
8292654Sjeff{
8392654Sjeff	struct adapter *sc = rdev->adap;
8492654Sjeff	struct mc7 *mem;
8592654Sjeff
8692654Sjeff	if ((m->addr & 7) || (m->len & 7))
8792654Sjeff		return (EINVAL);
8892654Sjeff	if (m->mem_id == MEM_CM)
8992654Sjeff		mem = &sc->cm;
9092654Sjeff	else if (m->mem_id == MEM_PMRX)
9192654Sjeff		mem = &sc->pmrx;
9292654Sjeff	else if (m->mem_id == MEM_PMTX)
9392654Sjeff		mem = &sc->pmtx;
9492654Sjeff	else
9592654Sjeff		return (EINVAL);
96132987Sgreen
9792654Sjeff	return (t3_mc7_bd_read(mem, m->addr/8, m->len/8, (u64 *)m->buf));
9892654Sjeff}
99132987Sgreen
100132987Sgreenvoid cxio_dump_tpt(struct cxio_rdev *rdev, uint32_t stag)
10192654Sjeff{
10292654Sjeff	struct ch_mem_range m;
10392654Sjeff	u64 *data;
10492654Sjeff	u32 addr;
10592654Sjeff	int rc;
106132987Sgreen	int size = 32;
10792654Sjeff
10892654Sjeff	m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
10992654Sjeff	if (m.buf == NULL) {
11092654Sjeff		CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
11192654Sjeff		return;
11292654Sjeff	}
11392654Sjeff	m.mem_id = MEM_PMRX;
11492654Sjeff	m.addr = (stag >> 8) * 32 + rdev->rnic_info.tpt_base;
11592654Sjeff	m.len = size;
11692654Sjeff	CTR3(KTR_IW_CXGB, "%s TPT addr 0x%x len %d", __FUNCTION__, m.addr, m.len);
11792654Sjeff
11892654Sjeff	rc = cxio_rdma_get_mem(rdev, &m);
11992654Sjeff	if (rc) {
12092654Sjeff		CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
12192654Sjeff		free(m.buf, M_DEVBUF);
12292654Sjeff		return;
12392654Sjeff	}
12492654Sjeff
12592654Sjeff	data = (u64 *)m.buf;
12692654Sjeff	addr = m.addr;
12792654Sjeff	while (size > 0) {
12892654Sjeff		CTR2(KTR_IW_CXGB, "TPT %08x: %016llx", addr, (unsigned long long) *data);
12992654Sjeff		size -= 8;
13092654Sjeff		data++;
13192654Sjeff		addr += 8;
13292654Sjeff	}
13392654Sjeff	free(m.buf, M_DEVBUF);
13492654Sjeff}
13592654Sjeff
136105689Ssheldonhvoid cxio_dump_pbl(struct cxio_rdev *rdev, uint32_t pbl_addr, uint32_t len, u8 shift)
13792654Sjeff{
13892654Sjeff	struct ch_mem_range m;
13992654Sjeff	u64 *data;
14092654Sjeff	u32 addr;
14192654Sjeff	int rc;
14292654Sjeff	int size, npages;
14392654Sjeff
14492654Sjeff	shift += 12;
14592654Sjeff	npages = (len + (1ULL << shift) - 1) >> shift;
14692654Sjeff	size = npages * sizeof(u64);
14792654Sjeff	m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
14892654Sjeff	if (m.buf == NULL) {
14992654Sjeff		CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
15092654Sjeff		return;
15192654Sjeff	}
15292654Sjeff	m.mem_id = MEM_PMRX;
15392654Sjeff	m.addr = pbl_addr;
15492654Sjeff	m.len = size;
15592654Sjeff	CTR4(KTR_IW_CXGB, "%s PBL addr 0x%x len %d depth %d",
15692654Sjeff		__FUNCTION__, m.addr, m.len, npages);
15792654Sjeff
15892654Sjeff	rc = cxio_rdma_get_mem(rdev, &m);
15992654Sjeff	if (rc) {
16092654Sjeff		CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
16192654Sjeff		free(m.buf, M_DEVBUF);
16292654Sjeff		return;
16392654Sjeff	}
16492654Sjeff
16592654Sjeff	data = (u64 *)m.buf;
16692654Sjeff	addr = m.addr;
16795925Sarr	while (size > 0) {
16892654Sjeff		CTR2(KTR_IW_CXGB, "PBL %08x: %016llx", addr, (unsigned long long) *data);
169148072Ssilby		size -= 8;
17092654Sjeff		data++;
171120223Sjeff		addr += 8;
172129906Sbmilekic	}
173129906Sbmilekic	free(m.buf, M_DEVBUF);
174129906Sbmilekic}
175129906Sbmilekic
176129906Sbmilekicvoid cxio_dump_wqe(union t3_wr *wqe)
177129906Sbmilekic{
178129906Sbmilekic	uint64_t *data = (uint64_t *)wqe;
179129906Sbmilekic	uint32_t size = (uint32_t)(be64toh(*data) & 0xff);
180129906Sbmilekic
181129906Sbmilekic	if (size == 0)
182129906Sbmilekic		size = 8;
183129906Sbmilekic	while (size > 0) {
184129906Sbmilekic		CTR2(KTR_IW_CXGB, "WQE %p: %016llx", data,
185129906Sbmilekic		     (unsigned long long) be64toh(*data));
186129906Sbmilekic		size--;
187129906Sbmilekic		data++;
188129906Sbmilekic	}
189129906Sbmilekic}
190129906Sbmilekic
191129906Sbmilekicvoid cxio_dump_wce(struct t3_cqe *wce)
192129906Sbmilekic{
193129906Sbmilekic	uint64_t *data = (uint64_t *)wce;
194129906Sbmilekic	int size = sizeof(*wce);
195129913Sbmilekic
196129913Sbmilekic	while (size > 0) {
197129913Sbmilekic		CTR2(KTR_IW_CXGB, "WCE %p: %016llx", data,
198129906Sbmilekic		     (unsigned long long) be64toh(*data));
199129906Sbmilekic		size -= 8;
200129906Sbmilekic		data++;
201129906Sbmilekic	}
202129906Sbmilekic}
203129906Sbmilekic
204129906Sbmilekicvoid cxio_dump_rqt(struct cxio_rdev *rdev, uint32_t hwtid, int nents)
205129906Sbmilekic{
206129906Sbmilekic	struct ch_mem_range m;
207120223Sjeff	int size = nents * 64;
208120223Sjeff	u64 *data;
209120223Sjeff	u32 addr;
210148072Ssilby	int rc;
211120223Sjeff
21292654Sjeff	m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
21392654Sjeff	if (m.buf == NULL) {
21492654Sjeff		CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
21592654Sjeff		return;
21692654Sjeff	}
21792654Sjeff	m.mem_id = MEM_PMRX;
21892654Sjeff	m.addr = ((hwtid)<<10) + rdev->rnic_info.rqt_base;
21992654Sjeff	m.len = size;
22095758Sjeff	CTR3(KTR_IW_CXGB, "%s RQT addr 0x%x len %d", __FUNCTION__, m.addr, m.len);
221103531Sjeff
222103531Sjeff	rc = cxio_rdma_get_mem(rdev, &m);
223103531Sjeff	if (rc) {
224103531Sjeff		CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
225103531Sjeff		free(m.buf, M_DEVBUF);
226103531Sjeff		return;
227103531Sjeff	}
228103531Sjeff
229129906Sbmilekic	data = (u64 *)m.buf;
230129906Sbmilekic	addr = m.addr;
231129906Sbmilekic	while (size > 0) {
23292654Sjeff		CTR2(KTR_IW_CXGB, "RQT %08x: %016llx", addr, (unsigned long long) *data);
23392654Sjeff		size -= 8;
23492654Sjeff		data++;
23592654Sjeff		addr += 8;
23692654Sjeff	}
23792654Sjeff	free(m.buf, M_DEVBUF);
23892654Sjeff}
239166654Srwatson
24092654Sjeffvoid cxio_dump_tcb(struct cxio_rdev *rdev, uint32_t hwtid)
24192654Sjeff{
24294161Sjeff	struct ch_mem_range m;
24392654Sjeff	int size = TCB_SIZE;
24492654Sjeff	uint32_t *data;
24592654Sjeff	uint32_t addr;
24692654Sjeff	int rc;
24792654Sjeff
24894161Sjeff	m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
24992654Sjeff	if (m.buf == NULL) {
25092654Sjeff		CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
25192654Sjeff		return;
25292654Sjeff	}
25392654Sjeff	m.mem_id = MEM_CM;
25492654Sjeff	m.addr = hwtid * size;
25592654Sjeff	m.len = size;
25695766Sjeff	CTR3(KTR_IW_CXGB, "%s TCB %d len %d", __FUNCTION__, m.addr, m.len);
25792654Sjeff
25892654Sjeff	rc = cxio_rdma_get_mem(rdev, &m);
25992654Sjeff	if (rc) {
260111119Simp		CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
26192654Sjeff		free(m.buf, M_DEVBUF);
26292654Sjeff		return;
26392654Sjeff	}
26495766Sjeff
26592654Sjeff	data = (uint32_t *)m.buf;
26692654Sjeff	addr = m.addr;
26792654Sjeff	while (size > 0) {
26892654Sjeff		printf("%2u: %08x %08x %08x %08x %08x %08x %08x %08x\n",
26992654Sjeff			addr,
27092654Sjeff			*(data+2), *(data+3), *(data),*(data+1),
27192654Sjeff			*(data+6), *(data+7), *(data+4), *(data+5));
27295766Sjeff		size -= 32;
27392654Sjeff		data += 8;
27492654Sjeff		addr += 32;
27595766Sjeff	}
27692654Sjeff	free(m.buf, M_DEVBUF);
27795766Sjeff}
27892654Sjeff#endif
27992654Sjeff