]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_dbg.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / dev / cxgb / ulp / iw_cxgb / iw_cxgb_dbg.c
1
2 /**************************************************************************
3
4 Copyright (c) 2007, Chelsio Inc.
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, 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
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.
28
29 ***************************************************************************/
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/bus.h>
37 #include <sys/module.h>
38 #include <sys/pciio.h>
39 #include <sys/conf.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
42 #include <sys/bus_dma.h>
43 #include <sys/rman.h>
44 #include <sys/ioccom.h>
45 #include <sys/mbuf.h>
46 #include <sys/mutex.h>
47 #include <sys/rwlock.h>
48 #include <sys/linker.h>
49 #include <sys/firmware.h>
50 #include <sys/socket.h>
51 #include <sys/sockio.h>
52 #include <sys/smp.h>
53 #include <sys/sysctl.h>
54 #include <sys/syslog.h>
55 #include <sys/queue.h>
56 #include <sys/taskqueue.h>
57 #include <sys/proc.h>
58 #include <sys/queue.h>
59 #include <sys/libkern.h>
60
61 #include <netinet/in.h>
62
63 #include <contrib/rdma/ib_verbs.h>
64 #include <contrib/rdma/ib_umem.h>
65 #include <contrib/rdma/ib_user_verbs.h>
66
67 #ifdef DEBUG
68 #include <cxgb_include.h>
69 #include <ulp/iw_cxgb/iw_cxgb_wr.h>
70 #include <ulp/iw_cxgb/iw_cxgb_hal.h>
71 #include <ulp/iw_cxgb/iw_cxgb_provider.h>
72 #include <ulp/iw_cxgb/iw_cxgb_cm.h>
73 #include <ulp/iw_cxgb/iw_cxgb.h>
74 #include <ulp/iw_cxgb/iw_cxgb_resource.h>
75 #include <ulp/iw_cxgb/iw_cxgb_user.h>
76
77 void cxio_dump_tpt(struct cxio_rdev *rdev, uint32_t stag)
78 {
79         struct ch_mem_range *m;
80         u64 *data;
81         int rc;
82         int size = 32;
83
84         m = kmalloc(sizeof(*m) + size, M_NOWAIT);
85         if (!m) {
86                 CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
87                 return;
88         }
89         m->mem_id = MEM_PMRX;
90         m->addr = (stag>>8) * 32 + rdev->rnic_info.tpt_base;
91         m->len = size;
92         CTR3(KTR_IW_CXGB, "%s TPT addr 0x%x len %d", __FUNCTION__, m->addr, m->len);
93         rc = rdev->t3cdev_p->ctl(rdev->t3cdev_p, RDMA_GET_MEM, m);
94         if (rc) {
95                 CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
96                 free(m, M_DEVBUF);
97                 return;
98         }
99
100         data = (u64 *)m->buf;
101         while (size > 0) {
102                 CTR2(KTR_IW_CXGB, "TPT %08x: %016llx", m->addr, (unsigned long long) *data);
103                 size -= 8;
104                 data++;
105                 m->addr += 8;
106         }
107         free(m, M_DEVBUF);
108 }
109
110 void cxio_dump_pbl(struct cxio_rdev *rdev, uint32_t pbl_addr, uint32_t len, u8 shift)
111 {
112         struct ch_mem_range *m;
113         u64 *data;
114         int rc;
115         int size, npages;
116
117         shift += 12;
118         npages = (len + (1ULL << shift) - 1) >> shift;
119         size = npages * sizeof(u64);
120
121         m = kmalloc(sizeof(*m) + size, M_NOWAIT);
122         if (!m) {
123                 CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
124                 return;
125         }
126         m->mem_id = MEM_PMRX;
127         m->addr = pbl_addr;
128         m->len = size;
129         CTR4(KTR_IW_CXGB, "%s PBL addr 0x%x len %d depth %d",
130                 __FUNCTION__, m->addr, m->len, npages);
131         rc = rdev->t3cdev_p->ctl(rdev->t3cdev_p, RDMA_GET_MEM, m);
132         if (rc) {
133                 CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
134                 free(m, M_DEVBUF);
135                 return;
136         }
137
138         data = (u64 *)m->buf;
139         while (size > 0) {
140                 CTR2(KTR_IW_CXGB, "PBL %08x: %016llx", m->addr, (unsigned long long) *data);
141                 size -= 8;
142                 data++;
143                 m->addr += 8;
144         }
145         free(m, M_DEVBUF);
146 }
147
148 void cxio_dump_wqe(union t3_wr *wqe)
149 {
150         uint64_t *data = (uint64_t *)wqe;
151         uint32_t size = (uint32_t)(be64toh(*data) & 0xff);
152
153         if (size == 0)
154                 size = 8;
155         while (size > 0) {
156                 CTR2(KTR_IW_CXGB, "WQE %p: %016llx", data,
157                      (unsigned long long) be64toh(*data));
158                 size--;
159                 data++;
160         }
161 }
162
163 void cxio_dump_wce(struct t3_cqe *wce)
164 {
165         uint64_t *data = (uint64_t *)wce;
166         int size = sizeof(*wce);
167
168         while (size > 0) {
169                 CTR2(KTR_IW_CXGB, "WCE %p: %016llx", data,
170                      (unsigned long long) be64toh(*data));
171                 size -= 8;
172                 data++;
173         }
174 }
175
176 void cxio_dump_rqt(struct cxio_rdev *rdev, uint32_t hwtid, int nents)
177 {
178         struct ch_mem_range *m;
179         int size = nents * 64;
180         u64 *data;
181         int rc;
182
183         m = kmalloc(sizeof(*m) + size, M_NOWAIT);
184         if (!m) {
185                 CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
186                 return;
187         }
188         m->mem_id = MEM_PMRX;
189         m->addr = ((hwtid)<<10) + rdev->rnic_info.rqt_base;
190         m->len = size;
191         CTR3(KTR_IW_CXGB, "%s RQT addr 0x%x len %d", __FUNCTION__, m->addr, m->len);
192         rc = rdev->t3cdev_p->ctl(rdev->t3cdev_p, RDMA_GET_MEM, m);
193         if (rc) {
194                 CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
195                 free(m, M_DEVBUF);
196                 return;
197         }
198
199         data = (u64 *)m->buf;
200         while (size > 0) {
201                 CTR2(KTR_IW_CXGB, "RQT %08x: %016llx", m->addr, (unsigned long long) *data);
202                 size -= 8;
203                 data++;
204                 m->addr += 8;
205         }
206         free(m, M_DEVBUF);
207 }
208
209 void cxio_dump_tcb(struct cxio_rdev *rdev, uint32_t hwtid)
210 {
211         struct ch_mem_range *m;
212         int size = TCB_SIZE;
213         uint32_t *data;
214         int rc;
215
216         m = kmalloc(sizeof(*m) + size, M_NOWAIT);
217         if (!m) {
218                 CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__);
219                 return;
220         }
221         m->mem_id = MEM_CM;
222         m->addr = hwtid * size;
223         m->len = size;
224         CTR3(KTR_IW_CXGB, "%s TCB %d len %d", __FUNCTION__, m->addr, m->len);
225         rc = rdev->t3cdev_p->ctl(rdev->t3cdev_p, RDMA_GET_MEM, m);
226         if (rc) {
227                 CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc);
228                 free(m, M_DEVBUF);
229                 return;
230         }
231
232         data = (uint32_t *)m->buf;
233         while (size > 0) {
234                 printf("%2u: %08x %08x %08x %08x %08x %08x %08x %08x\n",
235                         m->addr,
236                         *(data+2), *(data+3), *(data),*(data+1),
237                         *(data+6), *(data+7), *(data+4), *(data+5));
238                 size -= 32;
239                 data += 8;
240                 m->addr += 32;
241         }
242         free(m, M_DEVBUF);
243 }
244 #endif