Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006 Chelsio, Inc. All rights reserved. |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 3 | * |
| 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: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 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. |
| 22 | * |
| 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 |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/moduleparam.h> |
| 34 | |
| 35 | #include <rdma/ib_verbs.h> |
| 36 | |
| 37 | #include "cxgb3_offload.h" |
| 38 | #include "iwch_provider.h" |
| 39 | #include "iwch_user.h" |
| 40 | #include "iwch.h" |
| 41 | #include "iwch_cm.h" |
| 42 | |
| 43 | #define DRV_VERSION "1.1" |
| 44 | |
| 45 | MODULE_AUTHOR("Boyd Faulkner, Steve Wise"); |
| 46 | MODULE_DESCRIPTION("Chelsio T3 RDMA Driver"); |
| 47 | MODULE_LICENSE("Dual BSD/GPL"); |
| 48 | MODULE_VERSION(DRV_VERSION); |
| 49 | |
| 50 | cxgb3_cpl_handler_func t3c_handlers[NUM_CPL_CMDS]; |
| 51 | |
| 52 | static void open_rnic_dev(struct t3cdev *); |
| 53 | static void close_rnic_dev(struct t3cdev *); |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 54 | static void iwch_event_handler(struct t3cdev *, u32, u32); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 55 | |
| 56 | struct cxgb3_client t3c_client = { |
| 57 | .name = "iw_cxgb3", |
| 58 | .add = open_rnic_dev, |
| 59 | .remove = close_rnic_dev, |
| 60 | .handlers = t3c_handlers, |
Divy Le Ray | a73efd0 | 2009-01-26 22:22:19 -0800 | [diff] [blame] | 61 | .redirect = iwch_ep_redirect, |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 62 | .event_handler = iwch_event_handler |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | static LIST_HEAD(dev_list); |
| 66 | static DEFINE_MUTEX(dev_mutex); |
| 67 | |
Steve Wise | e998f24 | 2010-01-27 17:03:34 +0000 | [diff] [blame] | 68 | static int disable_qp_db(int id, void *p, void *data) |
| 69 | { |
| 70 | struct iwch_qp *qhp = p; |
| 71 | |
| 72 | cxio_disable_wq_db(&qhp->wq); |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static int enable_qp_db(int id, void *p, void *data) |
| 77 | { |
| 78 | struct iwch_qp *qhp = p; |
| 79 | |
| 80 | if (data) |
| 81 | ring_doorbell(qhp->rhp->rdev.ctrl_qp.doorbell, qhp->wq.qpid); |
| 82 | cxio_enable_wq_db(&qhp->wq); |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static void disable_dbs(struct iwch_dev *rnicp) |
| 87 | { |
| 88 | spin_lock_irq(&rnicp->lock); |
| 89 | idr_for_each(&rnicp->qpidr, disable_qp_db, NULL); |
| 90 | spin_unlock_irq(&rnicp->lock); |
| 91 | } |
| 92 | |
| 93 | static void enable_dbs(struct iwch_dev *rnicp, int ring_db) |
| 94 | { |
| 95 | spin_lock_irq(&rnicp->lock); |
| 96 | idr_for_each(&rnicp->qpidr, enable_qp_db, |
| 97 | (void *)(unsigned long)ring_db); |
| 98 | spin_unlock_irq(&rnicp->lock); |
| 99 | } |
| 100 | |
| 101 | static void iwch_db_drop_task(struct work_struct *work) |
| 102 | { |
| 103 | struct iwch_dev *rnicp = container_of(work, struct iwch_dev, |
| 104 | db_drop_task.work); |
| 105 | enable_dbs(rnicp, 1); |
| 106 | } |
| 107 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 108 | static void rnic_init(struct iwch_dev *rnicp) |
| 109 | { |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 110 | PDBG("%s iwch_dev %p\n", __func__, rnicp); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 111 | idr_init(&rnicp->cqidr); |
| 112 | idr_init(&rnicp->qpidr); |
| 113 | idr_init(&rnicp->mmidr); |
| 114 | spin_lock_init(&rnicp->lock); |
Steve Wise | e998f24 | 2010-01-27 17:03:34 +0000 | [diff] [blame] | 115 | INIT_DELAYED_WORK(&rnicp->db_drop_task, iwch_db_drop_task); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 116 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 117 | rnicp->attr.max_qps = T3_MAX_NUM_QP - 32; |
Steve Wise | 97d1cc8 | 2008-07-14 23:48:47 -0700 | [diff] [blame] | 118 | rnicp->attr.max_wrs = T3_MAX_QP_DEPTH; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 119 | rnicp->attr.max_sge_per_wr = T3_MAX_SGE; |
| 120 | rnicp->attr.max_sge_per_rdma_write_wr = T3_MAX_SGE; |
| 121 | rnicp->attr.max_cqs = T3_MAX_NUM_CQ - 1; |
Steve Wise | 97d1cc8 | 2008-07-14 23:48:47 -0700 | [diff] [blame] | 122 | rnicp->attr.max_cqes_per_cq = T3_MAX_CQ_DEPTH; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 123 | rnicp->attr.max_mem_regs = cxio_num_stags(&rnicp->rdev); |
| 124 | rnicp->attr.max_phys_buf_entries = T3_MAX_PBL_SIZE; |
| 125 | rnicp->attr.max_pds = T3_MAX_NUM_PD - 1; |
Jon Mason | 52c8084 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 126 | rnicp->attr.mem_pgsizes_bitmask = T3_PAGESIZE_MASK; |
Steve Wise | ccaf10d | 2008-04-29 13:46:52 -0700 | [diff] [blame] | 127 | rnicp->attr.max_mr_size = T3_MAX_MR_SIZE; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 128 | rnicp->attr.can_resize_wq = 0; |
| 129 | rnicp->attr.max_rdma_reads_per_qp = 8; |
| 130 | rnicp->attr.max_rdma_read_resources = |
| 131 | rnicp->attr.max_rdma_reads_per_qp * rnicp->attr.max_qps; |
| 132 | rnicp->attr.max_rdma_read_qp_depth = 8; /* IRD */ |
| 133 | rnicp->attr.max_rdma_read_depth = |
| 134 | rnicp->attr.max_rdma_read_qp_depth * rnicp->attr.max_qps; |
| 135 | rnicp->attr.rq_overflow_handled = 0; |
| 136 | rnicp->attr.can_modify_ird = 0; |
| 137 | rnicp->attr.can_modify_ord = 0; |
| 138 | rnicp->attr.max_mem_windows = rnicp->attr.max_mem_regs - 1; |
| 139 | rnicp->attr.stag0_value = 1; |
| 140 | rnicp->attr.zbva_support = 1; |
| 141 | rnicp->attr.local_invalidate_fence = 1; |
| 142 | rnicp->attr.cq_overflow_detection = 1; |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | static void open_rnic_dev(struct t3cdev *tdev) |
| 147 | { |
| 148 | struct iwch_dev *rnicp; |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 149 | |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 150 | PDBG("%s t3cdev %p\n", __func__, tdev); |
Marcin Slusarz | f1aa78b | 2009-09-05 20:24:24 -0700 | [diff] [blame] | 151 | printk_once(KERN_INFO MOD "Chelsio T3 RDMA Driver - version %s\n", |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 152 | DRV_VERSION); |
| 153 | rnicp = (struct iwch_dev *)ib_alloc_device(sizeof(*rnicp)); |
| 154 | if (!rnicp) { |
| 155 | printk(KERN_ERR MOD "Cannot allocate ib device\n"); |
| 156 | return; |
| 157 | } |
| 158 | rnicp->rdev.ulp = rnicp; |
| 159 | rnicp->rdev.t3cdev_p = tdev; |
| 160 | |
| 161 | mutex_lock(&dev_mutex); |
| 162 | |
| 163 | if (cxio_rdev_open(&rnicp->rdev)) { |
| 164 | mutex_unlock(&dev_mutex); |
| 165 | printk(KERN_ERR MOD "Unable to open CXIO rdev\n"); |
| 166 | ib_dealloc_device(&rnicp->ibdev); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | rnic_init(rnicp); |
| 171 | |
| 172 | list_add_tail(&rnicp->entry, &dev_list); |
| 173 | mutex_unlock(&dev_mutex); |
| 174 | |
| 175 | if (iwch_register_device(rnicp)) { |
| 176 | printk(KERN_ERR MOD "Unable to register device\n"); |
| 177 | close_rnic_dev(tdev); |
| 178 | } |
| 179 | printk(KERN_INFO MOD "Initialized device %s\n", |
| 180 | pci_name(rnicp->rdev.rnic_info.pdev)); |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | static void close_rnic_dev(struct t3cdev *tdev) |
| 185 | { |
| 186 | struct iwch_dev *dev, *tmp; |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 187 | PDBG("%s t3cdev %p\n", __func__, tdev); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 188 | mutex_lock(&dev_mutex); |
| 189 | list_for_each_entry_safe(dev, tmp, &dev_list, entry) { |
| 190 | if (dev->rdev.t3cdev_p == tdev) { |
Steve Wise | 68baf49 | 2010-02-22 22:07:22 +0000 | [diff] [blame^] | 191 | dev->rdev.flags = CXIO_ERROR_FATAL; |
Steve Wise | e998f24 | 2010-01-27 17:03:34 +0000 | [diff] [blame] | 192 | cancel_delayed_work_sync(&dev->db_drop_task); |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 193 | list_del(&dev->entry); |
| 194 | iwch_unregister_device(dev); |
| 195 | cxio_rdev_close(&dev->rdev); |
| 196 | idr_destroy(&dev->cqidr); |
| 197 | idr_destroy(&dev->qpidr); |
| 198 | idr_destroy(&dev->mmidr); |
| 199 | ib_dealloc_device(&dev->ibdev); |
| 200 | break; |
| 201 | } |
| 202 | } |
| 203 | mutex_unlock(&dev_mutex); |
| 204 | } |
| 205 | |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 206 | static void iwch_event_handler(struct t3cdev *tdev, u32 evt, u32 port_id) |
Divy Le Ray | a73efd0 | 2009-01-26 22:22:19 -0800 | [diff] [blame] | 207 | { |
| 208 | struct cxio_rdev *rdev = tdev->ulp; |
Steve Wise | ffc40c6 | 2009-09-09 11:25:56 -0700 | [diff] [blame] | 209 | struct iwch_dev *rnicp; |
Steve Wise | 04b5d02 | 2009-03-30 08:37:56 -0700 | [diff] [blame] | 210 | struct ib_event event; |
Steve Wise | e998f24 | 2010-01-27 17:03:34 +0000 | [diff] [blame] | 211 | u32 portnum = port_id + 1; |
| 212 | int dispatch = 0; |
Divy Le Ray | a73efd0 | 2009-01-26 22:22:19 -0800 | [diff] [blame] | 213 | |
Steve Wise | ffc40c6 | 2009-09-09 11:25:56 -0700 | [diff] [blame] | 214 | if (!rdev) |
| 215 | return; |
| 216 | rnicp = rdev_to_iwch_dev(rdev); |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 217 | switch (evt) { |
| 218 | case OFFLOAD_STATUS_DOWN: { |
Divy Le Ray | a73efd0 | 2009-01-26 22:22:19 -0800 | [diff] [blame] | 219 | rdev->flags = CXIO_ERROR_FATAL; |
Steve Wise | 04b5d02 | 2009-03-30 08:37:56 -0700 | [diff] [blame] | 220 | event.event = IB_EVENT_DEVICE_FATAL; |
Steve Wise | e998f24 | 2010-01-27 17:03:34 +0000 | [diff] [blame] | 221 | dispatch = 1; |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 222 | break; |
| 223 | } |
| 224 | case OFFLOAD_PORT_DOWN: { |
| 225 | event.event = IB_EVENT_PORT_ERR; |
Steve Wise | e998f24 | 2010-01-27 17:03:34 +0000 | [diff] [blame] | 226 | dispatch = 1; |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 227 | break; |
| 228 | } |
| 229 | case OFFLOAD_PORT_UP: { |
| 230 | event.event = IB_EVENT_PORT_ACTIVE; |
Steve Wise | e998f24 | 2010-01-27 17:03:34 +0000 | [diff] [blame] | 231 | dispatch = 1; |
| 232 | break; |
| 233 | } |
| 234 | case OFFLOAD_DB_FULL: { |
| 235 | disable_dbs(rnicp); |
| 236 | break; |
| 237 | } |
| 238 | case OFFLOAD_DB_EMPTY: { |
| 239 | enable_dbs(rnicp, 1); |
| 240 | break; |
| 241 | } |
| 242 | case OFFLOAD_DB_DROP: { |
| 243 | unsigned long delay = 1000; |
| 244 | unsigned short r; |
| 245 | |
| 246 | disable_dbs(rnicp); |
| 247 | get_random_bytes(&r, 2); |
| 248 | delay += r & 1023; |
| 249 | |
| 250 | /* |
| 251 | * delay is between 1000-2023 usecs. |
| 252 | */ |
| 253 | schedule_delayed_work(&rnicp->db_drop_task, |
| 254 | usecs_to_jiffies(delay)); |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 255 | break; |
| 256 | } |
Steve Wise | 04b5d02 | 2009-03-30 08:37:56 -0700 | [diff] [blame] | 257 | } |
Divy Le Ray | a73efd0 | 2009-01-26 22:22:19 -0800 | [diff] [blame] | 258 | |
Steve Wise | e998f24 | 2010-01-27 17:03:34 +0000 | [diff] [blame] | 259 | if (dispatch) { |
| 260 | event.device = &rnicp->ibdev; |
| 261 | event.element.port_num = portnum; |
| 262 | ib_dispatch_event(&event); |
| 263 | } |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 264 | |
Steve Wise | 04b5d02 | 2009-03-30 08:37:56 -0700 | [diff] [blame] | 265 | return; |
Divy Le Ray | a73efd0 | 2009-01-26 22:22:19 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Steve Wise | b038ced | 2007-02-12 16:16:18 -0800 | [diff] [blame] | 268 | static int __init iwch_init_module(void) |
| 269 | { |
| 270 | int err; |
| 271 | |
| 272 | err = cxio_hal_init(); |
| 273 | if (err) |
| 274 | return err; |
| 275 | err = iwch_cm_init(); |
| 276 | if (err) |
| 277 | return err; |
| 278 | cxio_register_ev_cb(iwch_ev_dispatch); |
| 279 | cxgb3_register_client(&t3c_client); |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static void __exit iwch_exit_module(void) |
| 284 | { |
| 285 | cxgb3_unregister_client(&t3c_client); |
| 286 | cxio_unregister_ev_cb(iwch_ev_dispatch); |
| 287 | iwch_cm_term(); |
| 288 | cxio_hal_exit(); |
| 289 | } |
| 290 | |
| 291 | module_init(iwch_init_module); |
| 292 | module_exit(iwch_exit_module); |