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>
49 c4iw_release_dev_ucontext(struct c4iw_rdev *rdev,
50 struct c4iw_dev_ucontext *uctx)
52 struct list_head *pos, *nxt;
53 struct c4iw_qid_list *entry;
55 mutex_lock(&uctx->lock);
56 list_for_each_safe(pos, nxt, &uctx->qpids) {
57 entry = list_entry(pos, struct c4iw_qid_list, entry);
58 list_del_init(&entry->entry);
59 if (!(entry->qid & rdev->qpmask)) {
60 c4iw_put_resource(&rdev->resource.qid_table,
62 mutex_lock(&rdev->stats.lock);
63 rdev->stats.qid.cur -= rdev->qpmask + 1;
64 mutex_unlock(&rdev->stats.lock);
69 list_for_each_safe(pos, nxt, &uctx->qpids) {
70 entry = list_entry(pos, struct c4iw_qid_list, entry);
71 list_del_init(&entry->entry);
74 mutex_unlock(&uctx->lock);
78 c4iw_init_dev_ucontext(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx)
81 INIT_LIST_HEAD(&uctx->qpids);
82 INIT_LIST_HEAD(&uctx->cqids);
83 mutex_init(&uctx->lock);
87 c4iw_rdev_open(struct c4iw_rdev *rdev)
89 struct adapter *sc = rdev->adap;
90 struct sge_params *sp = &sc->params.sge;
93 c4iw_init_dev_ucontext(rdev, &rdev->uctx);
95 /* XXX: we can probably make this work */
96 if (sp->eq_s_qpp > PAGE_SHIFT || sp->iq_s_qpp > PAGE_SHIFT) {
97 device_printf(sc->dev,
98 "doorbell density too high (eq %d, iq %d, pg %d).\n",
99 sp->eq_s_qpp, sp->eq_s_qpp, PAGE_SHIFT);
104 rdev->qpshift = PAGE_SHIFT - sp->eq_s_qpp;
105 rdev->qpmask = (1 << sp->eq_s_qpp) - 1;
106 rdev->cqshift = PAGE_SHIFT - sp->iq_s_qpp;
107 rdev->cqmask = (1 << sp->iq_s_qpp) - 1;
109 if (c4iw_num_stags(rdev) == 0) {
114 rdev->stats.pd.total = T4_MAX_NUM_PD;
115 rdev->stats.stag.total = sc->vres.stag.size;
116 rdev->stats.pbl.total = sc->vres.pbl.size;
117 rdev->stats.rqt.total = sc->vres.rq.size;
118 rdev->stats.qid.total = sc->vres.qp.size;
120 rc = c4iw_init_resource(rdev, c4iw_num_stags(rdev), T4_MAX_NUM_PD);
122 device_printf(sc->dev, "error %d initializing resources\n", rc);
125 rc = c4iw_pblpool_create(rdev);
127 device_printf(sc->dev, "error %d initializing pbl pool\n", rc);
130 rc = c4iw_rqtpool_create(rdev);
132 device_printf(sc->dev, "error %d initializing rqt pool\n", rc);
138 c4iw_pblpool_destroy(rdev);
140 c4iw_destroy_resource(&rdev->resource);
145 static void c4iw_rdev_close(struct c4iw_rdev *rdev)
147 c4iw_pblpool_destroy(rdev);
148 c4iw_rqtpool_destroy(rdev);
149 c4iw_destroy_resource(&rdev->resource);
153 c4iw_dealloc(struct c4iw_dev *iwsc)
156 c4iw_rdev_close(&iwsc->rdev);
157 idr_destroy(&iwsc->cqidr);
158 idr_destroy(&iwsc->qpidr);
159 idr_destroy(&iwsc->mmidr);
160 ib_dealloc_device(&iwsc->ibdev);
163 static struct c4iw_dev *
164 c4iw_alloc(struct adapter *sc)
166 struct c4iw_dev *iwsc;
169 iwsc = (struct c4iw_dev *)ib_alloc_device(sizeof(*iwsc));
171 device_printf(sc->dev, "Cannot allocate ib device.\n");
172 return (ERR_PTR(-ENOMEM));
174 iwsc->rdev.adap = sc;
176 rc = c4iw_rdev_open(&iwsc->rdev);
178 device_printf(sc->dev, "Unable to open CXIO rdev (%d)\n", rc);
179 ib_dealloc_device(&iwsc->ibdev);
180 return (ERR_PTR(rc));
183 idr_init(&iwsc->cqidr);
184 idr_init(&iwsc->qpidr);
185 idr_init(&iwsc->mmidr);
186 spin_lock_init(&iwsc->lock);
187 mutex_init(&iwsc->rdev.stats.lock);
192 static int c4iw_mod_load(void);
193 static int c4iw_mod_unload(void);
194 static int c4iw_activate(struct adapter *);
195 static int c4iw_deactivate(struct adapter *);
197 static struct uld_info c4iw_uld_info = {
199 .activate = c4iw_activate,
200 .deactivate = c4iw_deactivate,
204 c4iw_activate(struct adapter *sc)
206 struct c4iw_dev *iwsc;
209 ASSERT_SYNCHRONIZED_OP(sc);
211 if (uld_active(sc, ULD_IWARP)) {
212 KASSERT(0, ("%s: RDMA already eanbled on sc %p", __func__, sc));
216 if (sc->rdmacaps == 0) {
217 device_printf(sc->dev,
218 "RDMA not supported or RDMA cap is not enabled.\n");
222 iwsc = c4iw_alloc(sc);
225 device_printf(sc->dev, "initialization failed: %d\n", rc);
229 sc->iwarp_softc = iwsc;
230 c4iw_cm_init_cpl(sc);
232 rc = -c4iw_register_device(iwsc);
234 device_printf(sc->dev, "RDMA registration failed: %d\n", rc);
236 sc->iwarp_softc = NULL;
243 c4iw_deactivate(struct adapter *sc)
245 struct c4iw_dev *iwsc = sc->iwarp_softc;
247 ASSERT_SYNCHRONIZED_OP(sc);
249 c4iw_unregister_device(iwsc);
251 sc->iwarp_softc = NULL;
257 c4iw_activate_all(struct adapter *sc, void *arg __unused)
260 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4iwact") != 0)
263 /* Activate iWARP if any port on this adapter has IFCAP_TOE enabled. */
264 if (sc->offload_map && !uld_active(sc, ULD_IWARP))
265 (void) t4_activate_uld(sc, ULD_IWARP);
267 end_synchronized_op(sc, 0);
271 c4iw_deactivate_all(struct adapter *sc, void *arg __unused)
274 if (begin_synchronized_op(sc, NULL, SLEEP_OK | INTR_OK, "t4iwdea") != 0)
277 if (uld_active(sc, ULD_IWARP))
278 (void) t4_deactivate_uld(sc, ULD_IWARP);
280 end_synchronized_op(sc, 0);
288 rc = -c4iw_cm_init();
292 rc = t4_register_uld(&c4iw_uld_info);
298 t4_iterate(c4iw_activate_all, NULL);
304 c4iw_mod_unload(void)
307 t4_iterate(c4iw_deactivate_all, NULL);
311 if (t4_unregister_uld(&c4iw_uld_info) == EBUSY)
318 #undef MODULE_VERSION
319 #include <sys/module.h>
322 * t4_tom won't load on kernels without TCP_OFFLOAD and this module's dependency
323 * on t4_tom ensures that it won't either. So we don't directly check for
327 c4iw_modevent(module_t mod, int cmd, void *arg)
334 rc = c4iw_mod_load();
336 printf("iw_cxgbe: Chelsio T4/T5 RDMA driver loaded.\n");
340 rc = c4iw_mod_unload();
347 printf("t4_tom: compiled without TCP_OFFLOAD support.\n");
353 static moduledata_t c4iw_mod_data = {
359 MODULE_VERSION(iw_cxgbe, 1);
360 MODULE_DEPEND(iw_cxgbe, t4nex, 1, 1, 1);
361 MODULE_DEPEND(iw_cxgbe, t4_tom, 1, 1, 1);
362 MODULE_DEPEND(iw_cxgbe, ibcore, 1, 1, 1);
363 DECLARE_MODULE(iw_cxgbe, c4iw_mod_data, SI_SUB_EXEC, SI_ORDER_ANY);