2 * Copyright (c) 2009-2013 Chelsio, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
39 #include <linux/module.h>
40 #include <linux/moduleparam.h>
42 #include <rdma/ib_verbs.h>
43 #include <linux/idr.h>
48 int spg_creds = 2; /* Default status page size is 2 credits = 128B */
51 c4iw_release_dev_ucontext(struct c4iw_rdev *rdev,
52 struct c4iw_dev_ucontext *uctx)
54 struct list_head *pos, *nxt;
55 struct c4iw_qid_list *entry;
57 mutex_lock(&uctx->lock);
58 list_for_each_safe(pos, nxt, &uctx->qpids) {
59 entry = list_entry(pos, struct c4iw_qid_list, entry);
60 list_del_init(&entry->entry);
61 if (!(entry->qid & rdev->qpmask)) {
62 c4iw_put_resource(&rdev->resource.qid_table,
64 mutex_lock(&rdev->stats.lock);
65 rdev->stats.qid.cur -= rdev->qpmask + 1;
66 mutex_unlock(&rdev->stats.lock);
71 list_for_each_safe(pos, nxt, &uctx->qpids) {
72 entry = list_entry(pos, struct c4iw_qid_list, entry);
73 list_del_init(&entry->entry);
76 mutex_unlock(&uctx->lock);
80 c4iw_init_dev_ucontext(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx)
83 INIT_LIST_HEAD(&uctx->qpids);
84 INIT_LIST_HEAD(&uctx->cqids);
85 mutex_init(&uctx->lock);
89 c4iw_rdev_open(struct c4iw_rdev *rdev)
91 struct adapter *sc = rdev->adap;
94 c4iw_init_dev_ucontext(rdev, &rdev->uctx);
96 /* Save the status page size set by if_cxgbe */
97 spg_creds = (t4_read_reg(sc, A_SGE_CONTROL) & F_EGRSTATUSPAGESIZE) ?
100 /* XXX: we can probably make this work */
101 if (sc->sge.eq_s_qpp > PAGE_SHIFT || sc->sge.iq_s_qpp > PAGE_SHIFT) {
102 device_printf(sc->dev,
103 "doorbell density too high (eq %d, iq %d, pg %d).\n",
104 sc->sge.eq_s_qpp, sc->sge.eq_s_qpp, PAGE_SHIFT);
109 rdev->qpshift = PAGE_SHIFT - sc->sge.eq_s_qpp;
110 rdev->qpmask = (1 << sc->sge.eq_s_qpp) - 1;
111 rdev->cqshift = PAGE_SHIFT - sc->sge.iq_s_qpp;
112 rdev->cqmask = (1 << sc->sge.iq_s_qpp) - 1;
114 if (c4iw_num_stags(rdev) == 0) {
119 rdev->stats.pd.total = T4_MAX_NUM_PD;
120 rdev->stats.stag.total = sc->vres.stag.size;
121 rdev->stats.pbl.total = sc->vres.pbl.size;
122 rdev->stats.rqt.total = sc->vres.rq.size;
123 rdev->stats.qid.total = sc->vres.qp.size;
125 rc = c4iw_init_resource(rdev, c4iw_num_stags(rdev), T4_MAX_NUM_PD);
127 device_printf(sc->dev, "error %d initializing resources\n", rc);
130 rc = c4iw_pblpool_create(rdev);
132 device_printf(sc->dev, "error %d initializing pbl pool\n", rc);
135 rc = c4iw_rqtpool_create(rdev);
137 device_printf(sc->dev, "error %d initializing rqt pool\n", rc);
143 c4iw_pblpool_destroy(rdev);
145 c4iw_destroy_resource(&rdev->resource);
150 static void c4iw_rdev_close(struct c4iw_rdev *rdev)
152 c4iw_pblpool_destroy(rdev);
153 c4iw_rqtpool_destroy(rdev);
154 c4iw_destroy_resource(&rdev->resource);
158 c4iw_dealloc(struct c4iw_dev *iwsc)
161 c4iw_rdev_close(&iwsc->rdev);
162 idr_destroy(&iwsc->cqidr);
163 idr_destroy(&iwsc->qpidr);
164 idr_destroy(&iwsc->mmidr);
165 ib_dealloc_device(&iwsc->ibdev);
168 static struct c4iw_dev *
169 c4iw_alloc(struct adapter *sc)
171 struct c4iw_dev *iwsc;
174 iwsc = (struct c4iw_dev *)ib_alloc_device(sizeof(*iwsc));
176 device_printf(sc->dev, "Cannot allocate ib device.\n");
177 return (ERR_PTR(-ENOMEM));
179 iwsc->rdev.adap = sc;
181 rc = c4iw_rdev_open(&iwsc->rdev);
183 device_printf(sc->dev, "Unable to open CXIO rdev (%d)\n", rc);
184 ib_dealloc_device(&iwsc->ibdev);
185 return (ERR_PTR(rc));
188 idr_init(&iwsc->cqidr);
189 idr_init(&iwsc->qpidr);
190 idr_init(&iwsc->mmidr);
191 spin_lock_init(&iwsc->lock);
192 mutex_init(&iwsc->rdev.stats.lock);
197 static int c4iw_mod_load(void);
198 static int c4iw_mod_unload(void);
199 static int c4iw_activate(struct adapter *);
200 static int c4iw_deactivate(struct adapter *);
202 static struct uld_info c4iw_uld_info = {
204 .activate = c4iw_activate,
205 .deactivate = c4iw_deactivate,
209 c4iw_activate(struct adapter *sc)
211 struct c4iw_dev *iwsc;
214 ASSERT_SYNCHRONIZED_OP(sc);
216 if (isset(&sc->offload_map, MAX_NPORTS)) {
217 KASSERT(0, ("%s: RDMA already eanbled on sc %p", __func__, sc));
221 if (sc->rdmacaps == 0) {
222 device_printf(sc->dev,
223 "RDMA not supported or RDMA cap is not enabled.\n");
227 iwsc = c4iw_alloc(sc);
230 device_printf(sc->dev, "initialization failed: %d\n", rc);
234 sc->iwarp_softc = iwsc;
235 c4iw_cm_init_cpl(sc);
237 rc = -c4iw_register_device(iwsc);
239 device_printf(sc->dev, "RDMA registration failed: %d\n", rc);
241 sc->iwarp_softc = NULL;
248 c4iw_deactivate(struct adapter *sc)
250 struct c4iw_dev *iwsc = sc->iwarp_softc;
252 ASSERT_SYNCHRONIZED_OP(sc);
254 c4iw_unregister_device(iwsc);
256 sc->iwarp_softc = NULL;
262 c4iw_activate_all(struct adapter *sc, void *arg __unused)
265 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4iwact") != 0)
268 if (!isset(&sc->offload_map, MAX_NPORTS) &&
269 t4_activate_uld(sc, ULD_IWARP) == 0)
270 setbit(&sc->offload_map, MAX_NPORTS);
272 end_synchronized_op(sc, 0);
276 c4iw_deactivate_all(struct adapter *sc, void *arg __unused)
279 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4iwdea") != 0)
282 if (isset(&sc->offload_map, MAX_NPORTS) &&
283 t4_deactivate_uld(sc, ULD_IWARP) == 0)
284 clrbit(&sc->offload_map, MAX_NPORTS);
286 end_synchronized_op(sc, 0);
294 rc = -c4iw_cm_init();
298 rc = t4_register_uld(&c4iw_uld_info);
304 t4_iterate(c4iw_activate_all, NULL);
310 c4iw_mod_unload(void)
313 t4_iterate(c4iw_deactivate_all, NULL);
317 if (t4_unregister_uld(&c4iw_uld_info) == EBUSY)
326 * t4_tom won't load on kernels without TCP_OFFLOAD and this module's dependency
327 * on t4_tom ensures that it won't either. So we don't directly check for
331 c4iw_modevent(module_t mod, int cmd, void *arg)
338 rc = c4iw_mod_load();
340 printf("iw_cxgbe: Chelsio T4/T5 RDMA driver loaded.\n");
344 rc = c4iw_mod_unload();
351 printf("t4_tom: compiled without TCP_OFFLOAD support.\n");
357 static moduledata_t c4iw_mod_data = {
363 MODULE_VERSION(iw_cxgbe, 1);
364 MODULE_DEPEND(iw_cxgbe, t4nex, 1, 1, 1);
365 MODULE_DEPEND(iw_cxgbe, t4_tom, 1, 1, 1);
366 MODULE_DEPEND(iw_cxgbe, ibcore, 1, 1, 1);
367 MODULE_DEPEND(iw_cxgbe, linuxapi, 1, 1, 1);
368 DECLARE_MODULE(iw_cxgbe, c4iw_mod_data, SI_SUB_EXEC, SI_ORDER_ANY);