2 /**************************************************************************
4 Copyright (c) 2007, Chelsio Inc.
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
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.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
29 ***************************************************************************/
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <sys/pciio.h>
41 #include <machine/bus.h>
42 #include <machine/resource.h>
43 #include <sys/bus_dma.h>
45 #include <sys/ioccom.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>
54 #include <sys/sysctl.h>
55 #include <sys/syslog.h>
56 #include <sys/queue.h>
57 #include <sys/taskqueue.h>
59 #include <sys/queue.h>
60 #include <sys/libkern.h>
62 #include <netinet/in.h>
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>
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>
81 cxio_rdma_get_mem(struct cxio_rdev *rdev, struct ch_mem_range *m)
83 struct adapter *sc = rdev->adap;
86 if ((m->addr & 7) || (m->len & 7))
88 if (m->mem_id == MEM_CM)
90 else if (m->mem_id == MEM_PMRX)
92 else if (m->mem_id == MEM_PMTX)
97 return (t3_mc7_bd_read(mem, m->addr/8, m->len/8, (u64 *)m->buf));
100 void cxio_dump_tpt(struct cxio_rdev *rdev, uint32_t stag)
102 struct ch_mem_range m;
108 m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
110 CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
114 m.addr = (stag >> 8) * 32 + rdev->rnic_info.tpt_base;
116 CTR3(KTR_IW_CXGB, "%s TPT addr 0x%x len %d", __FUNCTION__, m.addr, m.len);
118 rc = cxio_rdma_get_mem(rdev, &m);
120 CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
121 free(m.buf, M_DEVBUF);
128 CTR2(KTR_IW_CXGB, "TPT %08x: %016llx", addr, (unsigned long long) *data);
133 free(m.buf, M_DEVBUF);
136 void cxio_dump_pbl(struct cxio_rdev *rdev, uint32_t pbl_addr, uint32_t len, u8 shift)
138 struct ch_mem_range m;
145 npages = (len + (1ULL << shift) - 1) >> shift;
146 size = npages * sizeof(u64);
147 m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
149 CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
155 CTR4(KTR_IW_CXGB, "%s PBL addr 0x%x len %d depth %d",
156 __FUNCTION__, m.addr, m.len, npages);
158 rc = cxio_rdma_get_mem(rdev, &m);
160 CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
161 free(m.buf, M_DEVBUF);
168 CTR2(KTR_IW_CXGB, "PBL %08x: %016llx", addr, (unsigned long long) *data);
173 free(m.buf, M_DEVBUF);
176 void cxio_dump_wqe(union t3_wr *wqe)
178 uint64_t *data = (uint64_t *)wqe;
179 uint32_t size = (uint32_t)(be64toh(*data) & 0xff);
184 CTR2(KTR_IW_CXGB, "WQE %p: %016llx", data,
185 (unsigned long long) be64toh(*data));
191 void cxio_dump_wce(struct t3_cqe *wce)
193 uint64_t *data = (uint64_t *)wce;
194 int size = sizeof(*wce);
197 CTR2(KTR_IW_CXGB, "WCE %p: %016llx", data,
198 (unsigned long long) be64toh(*data));
204 void cxio_dump_rqt(struct cxio_rdev *rdev, uint32_t hwtid, int nents)
206 struct ch_mem_range m;
207 int size = nents * 64;
212 m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
214 CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
218 m.addr = ((hwtid)<<10) + rdev->rnic_info.rqt_base;
220 CTR3(KTR_IW_CXGB, "%s RQT addr 0x%x len %d", __FUNCTION__, m.addr, m.len);
222 rc = cxio_rdma_get_mem(rdev, &m);
224 CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
225 free(m.buf, M_DEVBUF);
232 CTR2(KTR_IW_CXGB, "RQT %08x: %016llx", addr, (unsigned long long) *data);
237 free(m.buf, M_DEVBUF);
240 void cxio_dump_tcb(struct cxio_rdev *rdev, uint32_t hwtid)
242 struct ch_mem_range m;
248 m.buf = malloc(size, M_DEVBUF, M_NOWAIT);
250 CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
254 m.addr = hwtid * size;
256 CTR3(KTR_IW_CXGB, "%s TCB %d len %d", __FUNCTION__, m.addr, m.len);
258 rc = cxio_rdma_get_mem(rdev, &m);
260 CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
261 free(m.buf, M_DEVBUF);
265 data = (uint32_t *)m.buf;
268 printf("%2u: %08x %08x %08x %08x %08x %08x %08x %08x\n",
270 *(data+2), *(data+3), *(data),*(data+1),
271 *(data+6), *(data+7), *(data+4), *(data+5));
276 free(m.buf, M_DEVBUF);