Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. |
Roland Dreier | 2a1d9b7 | 2005-08-10 23:03:10 -0700 | [diff] [blame] | 3 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
| 4 | * Copyright (c) 2004 Voltaire, Inc. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * This software is available to you under a choice of one of two |
| 7 | * licenses. You may choose to be licensed under the terms of the GNU |
| 8 | * General Public License (GPL) Version 2, available from the file |
| 9 | * COPYING in the main directory of this source tree, or the |
| 10 | * OpenIB.org BSD license below: |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or |
| 13 | * without modification, are permitted provided that the following |
| 14 | * conditions are met: |
| 15 | * |
| 16 | * - Redistributions of source code must retain the above |
| 17 | * copyright notice, this list of conditions and the following |
| 18 | * disclaimer. |
| 19 | * |
| 20 | * - Redistributions in binary form must reproduce the above |
| 21 | * copyright notice, this list of conditions and the following |
| 22 | * disclaimer in the documentation and/or other materials |
| 23 | * provided with the distribution. |
| 24 | * |
| 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 32 | * SOFTWARE. |
| 33 | * |
| 34 | * $Id: ipoib.h 1358 2004-12-17 22:00:11Z roland $ |
| 35 | */ |
| 36 | |
| 37 | #ifndef _IPOIB_H |
| 38 | #define _IPOIB_H |
| 39 | |
| 40 | #include <linux/list.h> |
| 41 | #include <linux/skbuff.h> |
| 42 | #include <linux/netdevice.h> |
| 43 | #include <linux/workqueue.h> |
| 44 | #include <linux/pci.h> |
| 45 | #include <linux/config.h> |
| 46 | #include <linux/kref.h> |
| 47 | #include <linux/if_infiniband.h> |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 48 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #include <net/neighbour.h> |
| 51 | |
| 52 | #include <asm/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Roland Dreier | a4d61e8 | 2005-08-25 13:40:04 -0700 | [diff] [blame] | 54 | #include <rdma/ib_verbs.h> |
| 55 | #include <rdma/ib_pack.h> |
| 56 | #include <rdma/ib_sa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | /* constants */ |
| 59 | |
| 60 | enum { |
| 61 | IPOIB_PACKET_SIZE = 2048, |
| 62 | IPOIB_BUF_SIZE = IPOIB_PACKET_SIZE + IB_GRH_BYTES, |
| 63 | |
| 64 | IPOIB_ENCAP_LEN = 4, |
| 65 | |
| 66 | IPOIB_RX_RING_SIZE = 128, |
| 67 | IPOIB_TX_RING_SIZE = 64, |
| 68 | |
| 69 | IPOIB_NUM_WC = 4, |
| 70 | |
| 71 | IPOIB_MAX_PATH_REC_QUEUE = 3, |
| 72 | IPOIB_MAX_MCAST_QUEUE = 3, |
| 73 | |
| 74 | IPOIB_FLAG_OPER_UP = 0, |
Leonid Arsh | 7a343d4 | 2006-03-23 19:52:51 +0200 | [diff] [blame] | 75 | IPOIB_FLAG_INITIALIZED = 1, |
| 76 | IPOIB_FLAG_ADMIN_UP = 2, |
| 77 | IPOIB_PKEY_ASSIGNED = 3, |
| 78 | IPOIB_PKEY_STOP = 4, |
| 79 | IPOIB_FLAG_SUBINTERFACE = 5, |
| 80 | IPOIB_MCAST_RUN = 6, |
| 81 | IPOIB_STOP_REAPER = 7, |
| 82 | IPOIB_MCAST_STARTED = 8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | IPOIB_MAX_BACKOFF_SECONDS = 16, |
| 85 | |
| 86 | IPOIB_MCAST_FLAG_FOUND = 0, /* used in set_multicast_list */ |
| 87 | IPOIB_MCAST_FLAG_SENDONLY = 1, |
| 88 | IPOIB_MCAST_FLAG_BUSY = 2, /* joining or already joined */ |
| 89 | IPOIB_MCAST_FLAG_ATTACHED = 3, |
| 90 | }; |
| 91 | |
| 92 | /* structs */ |
| 93 | |
| 94 | struct ipoib_header { |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 95 | __be16 proto; |
| 96 | u16 reserved; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | struct ipoib_pseudoheader { |
| 100 | u8 hwaddr[INFINIBAND_ALEN]; |
| 101 | }; |
| 102 | |
| 103 | struct ipoib_mcast; |
| 104 | |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 105 | struct ipoib_rx_buf { |
| 106 | struct sk_buff *skb; |
| 107 | dma_addr_t mapping; |
| 108 | }; |
| 109 | |
| 110 | struct ipoib_tx_buf { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | struct sk_buff *skb; |
| 112 | DECLARE_PCI_UNMAP_ADDR(mapping) |
| 113 | }; |
| 114 | |
| 115 | /* |
| 116 | * Device private locking: tx_lock protects members used in TX fast |
| 117 | * path (and we use LLTX so upper layers don't do extra locking). |
| 118 | * lock protects everything else. lock nests inside of tx_lock (ie |
| 119 | * tx_lock must be acquired first if needed). |
| 120 | */ |
| 121 | struct ipoib_dev_priv { |
| 122 | spinlock_t lock; |
| 123 | |
| 124 | struct net_device *dev; |
| 125 | |
| 126 | unsigned long flags; |
| 127 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 128 | struct mutex mcast_mutex; |
| 129 | struct mutex vlan_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | struct rb_root path_tree; |
| 132 | struct list_head path_list; |
| 133 | |
| 134 | struct ipoib_mcast *broadcast; |
| 135 | struct list_head multicast_list; |
| 136 | struct rb_root multicast_tree; |
| 137 | |
| 138 | struct work_struct pkey_task; |
| 139 | struct work_struct mcast_task; |
| 140 | struct work_struct flush_task; |
| 141 | struct work_struct restart_task; |
| 142 | struct work_struct ah_reap_task; |
| 143 | |
| 144 | struct ib_device *ca; |
| 145 | u8 port; |
| 146 | u16 pkey; |
| 147 | struct ib_pd *pd; |
| 148 | struct ib_mr *mr; |
| 149 | struct ib_cq *cq; |
| 150 | struct ib_qp *qp; |
| 151 | u32 qkey; |
| 152 | |
| 153 | union ib_gid local_gid; |
| 154 | u16 local_lid; |
| 155 | u8 local_rate; |
| 156 | |
| 157 | unsigned int admin_mtu; |
| 158 | unsigned int mcast_mtu; |
| 159 | |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 160 | struct ipoib_rx_buf *rx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Roland Dreier | 1993d68 | 2005-10-28 15:30:34 -0700 | [diff] [blame] | 162 | spinlock_t tx_lock; |
| 163 | struct ipoib_tx_buf *tx_ring; |
| 164 | unsigned tx_head; |
| 165 | unsigned tx_tail; |
| 166 | struct ib_sge tx_sge; |
| 167 | struct ib_send_wr tx_wr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | struct ib_wc ibwc[IPOIB_NUM_WC]; |
| 170 | |
| 171 | struct list_head dead_ahs; |
| 172 | |
| 173 | struct ib_event_handler event_handler; |
| 174 | |
| 175 | struct net_device_stats stats; |
| 176 | |
| 177 | struct net_device *parent; |
| 178 | struct list_head child_intfs; |
| 179 | struct list_head list; |
| 180 | |
| 181 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 182 | struct list_head fs_list; |
| 183 | struct dentry *mcg_dentry; |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 184 | struct dentry *path_dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | #endif |
| 186 | }; |
| 187 | |
| 188 | struct ipoib_ah { |
| 189 | struct net_device *dev; |
| 190 | struct ib_ah *ah; |
| 191 | struct list_head list; |
| 192 | struct kref ref; |
| 193 | unsigned last_send; |
| 194 | }; |
| 195 | |
| 196 | struct ipoib_path { |
| 197 | struct net_device *dev; |
| 198 | struct ib_sa_path_rec pathrec; |
| 199 | struct ipoib_ah *ah; |
| 200 | struct sk_buff_head queue; |
| 201 | |
| 202 | struct list_head neigh_list; |
| 203 | |
| 204 | int query_id; |
| 205 | struct ib_sa_query *query; |
| 206 | struct completion done; |
| 207 | |
| 208 | struct rb_node rb_node; |
| 209 | struct list_head list; |
| 210 | }; |
| 211 | |
| 212 | struct ipoib_neigh { |
| 213 | struct ipoib_ah *ah; |
| 214 | struct sk_buff_head queue; |
| 215 | |
| 216 | struct neighbour *neighbour; |
| 217 | |
| 218 | struct list_head list; |
| 219 | }; |
| 220 | |
Michael S. Tsirkin | 44af79f | 2006-02-20 21:50:39 -0800 | [diff] [blame] | 221 | /* |
| 222 | * We stash a pointer to our private neighbour information after our |
| 223 | * hardware address in neigh->ha. The ALIGN() expression here makes |
| 224 | * sure that this pointer is stored aligned so that an unaligned |
| 225 | * load is not needed to dereference it. |
| 226 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh) |
| 228 | { |
Michael S. Tsirkin | 44af79f | 2006-02-20 21:50:39 -0800 | [diff] [blame] | 229 | return (void*) neigh + ALIGN(offsetof(struct neighbour, ha) + |
| 230 | INFINIBAND_ALEN, sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | extern struct workqueue_struct *ipoib_workqueue; |
| 234 | |
| 235 | /* functions */ |
| 236 | |
| 237 | void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr); |
| 238 | |
| 239 | struct ipoib_ah *ipoib_create_ah(struct net_device *dev, |
| 240 | struct ib_pd *pd, struct ib_ah_attr *attr); |
| 241 | void ipoib_free_ah(struct kref *kref); |
| 242 | static inline void ipoib_put_ah(struct ipoib_ah *ah) |
| 243 | { |
| 244 | kref_put(&ah->ref, ipoib_free_ah); |
| 245 | } |
| 246 | |
Roland Dreier | 8ae5a8a | 2005-11-02 20:51:01 -0800 | [diff] [blame] | 247 | int ipoib_open(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | int ipoib_add_pkey_attr(struct net_device *dev); |
| 249 | |
| 250 | void ipoib_send(struct net_device *dev, struct sk_buff *skb, |
| 251 | struct ipoib_ah *address, u32 qpn); |
| 252 | void ipoib_reap_ah(void *dev_ptr); |
| 253 | |
| 254 | void ipoib_flush_paths(struct net_device *dev); |
| 255 | struct ipoib_dev_priv *ipoib_intf_alloc(const char *format); |
| 256 | |
| 257 | int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port); |
| 258 | void ipoib_ib_dev_flush(void *dev); |
| 259 | void ipoib_ib_dev_cleanup(struct net_device *dev); |
| 260 | |
| 261 | int ipoib_ib_dev_open(struct net_device *dev); |
| 262 | int ipoib_ib_dev_up(struct net_device *dev); |
Jack Morgenstein | 0b3ea08 | 2006-03-20 10:08:24 -0800 | [diff] [blame] | 263 | int ipoib_ib_dev_down(struct net_device *dev, int flush); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | int ipoib_ib_dev_stop(struct net_device *dev); |
| 265 | |
| 266 | int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port); |
| 267 | void ipoib_dev_cleanup(struct net_device *dev); |
| 268 | |
| 269 | void ipoib_mcast_join_task(void *dev_ptr); |
| 270 | void ipoib_mcast_send(struct net_device *dev, union ib_gid *mgid, |
| 271 | struct sk_buff *skb); |
| 272 | |
| 273 | void ipoib_mcast_restart_task(void *dev_ptr); |
| 274 | int ipoib_mcast_start_thread(struct net_device *dev); |
Roland Dreier | 8d2cae0 | 2005-09-20 10:52:04 -0700 | [diff] [blame] | 275 | int ipoib_mcast_stop_thread(struct net_device *dev, int flush); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | void ipoib_mcast_dev_down(struct net_device *dev); |
| 278 | void ipoib_mcast_dev_flush(struct net_device *dev); |
| 279 | |
Roland Dreier | 8ae5a8a | 2005-11-02 20:51:01 -0800 | [diff] [blame] | 280 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter); |
| 283 | void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter, |
| 284 | union ib_gid *gid, |
| 285 | unsigned long *created, |
| 286 | unsigned int *queuelen, |
| 287 | unsigned int *complete, |
| 288 | unsigned int *send_only); |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 289 | |
| 290 | struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev); |
| 291 | int ipoib_path_iter_next(struct ipoib_path_iter *iter); |
| 292 | void ipoib_path_iter_read(struct ipoib_path_iter *iter, |
| 293 | struct ipoib_path *path); |
Roland Dreier | 8ae5a8a | 2005-11-02 20:51:01 -0800 | [diff] [blame] | 294 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | int ipoib_mcast_attach(struct net_device *dev, u16 mlid, |
| 297 | union ib_gid *mgid); |
| 298 | int ipoib_mcast_detach(struct net_device *dev, u16 mlid, |
| 299 | union ib_gid *mgid); |
| 300 | |
Roland Dreier | 5b6810e | 2005-10-11 11:08:24 -0700 | [diff] [blame] | 301 | int ipoib_init_qp(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca); |
| 303 | void ipoib_transport_dev_cleanup(struct net_device *dev); |
| 304 | |
| 305 | void ipoib_event(struct ib_event_handler *handler, |
| 306 | struct ib_event *record); |
| 307 | |
| 308 | int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey); |
| 309 | int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey); |
| 310 | |
| 311 | void ipoib_pkey_poll(void *dev); |
| 312 | int ipoib_pkey_dev_delay_open(struct net_device *dev); |
| 313 | |
| 314 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 315 | void ipoib_create_debug_files(struct net_device *dev); |
| 316 | void ipoib_delete_debug_files(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | int ipoib_register_debugfs(void); |
| 318 | void ipoib_unregister_debugfs(void); |
| 319 | #else |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 320 | static inline void ipoib_create_debug_files(struct net_device *dev) { } |
| 321 | static inline void ipoib_delete_debug_files(struct net_device *dev) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | static inline int ipoib_register_debugfs(void) { return 0; } |
| 323 | static inline void ipoib_unregister_debugfs(void) { } |
| 324 | #endif |
| 325 | |
| 326 | |
| 327 | #define ipoib_printk(level, priv, format, arg...) \ |
| 328 | printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg) |
| 329 | #define ipoib_warn(priv, format, arg...) \ |
| 330 | ipoib_printk(KERN_WARNING, priv, format , ## arg) |
| 331 | |
| 332 | |
| 333 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 334 | extern int ipoib_debug_level; |
| 335 | |
| 336 | #define ipoib_dbg(priv, format, arg...) \ |
| 337 | do { \ |
| 338 | if (ipoib_debug_level > 0) \ |
| 339 | ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ |
| 340 | } while (0) |
| 341 | #define ipoib_dbg_mcast(priv, format, arg...) \ |
| 342 | do { \ |
| 343 | if (mcast_debug_level > 0) \ |
| 344 | ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ |
| 345 | } while (0) |
| 346 | #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */ |
| 347 | #define ipoib_dbg(priv, format, arg...) \ |
| 348 | do { (void) (priv); } while (0) |
| 349 | #define ipoib_dbg_mcast(priv, format, arg...) \ |
| 350 | do { (void) (priv); } while (0) |
| 351 | #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */ |
| 352 | |
| 353 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA |
| 354 | #define ipoib_dbg_data(priv, format, arg...) \ |
| 355 | do { \ |
| 356 | if (data_debug_level > 0) \ |
| 357 | ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ |
| 358 | } while (0) |
| 359 | #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */ |
| 360 | #define ipoib_dbg_data(priv, format, arg...) \ |
| 361 | do { (void) (priv); } while (0) |
| 362 | #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */ |
| 363 | |
| 364 | |
| 365 | #define IPOIB_GID_FMT "%x:%x:%x:%x:%x:%x:%x:%x" |
| 366 | |
| 367 | #define IPOIB_GID_ARG(gid) be16_to_cpup((__be16 *) ((gid).raw + 0)), \ |
| 368 | be16_to_cpup((__be16 *) ((gid).raw + 2)), \ |
| 369 | be16_to_cpup((__be16 *) ((gid).raw + 4)), \ |
| 370 | be16_to_cpup((__be16 *) ((gid).raw + 6)), \ |
| 371 | be16_to_cpup((__be16 *) ((gid).raw + 8)), \ |
| 372 | be16_to_cpup((__be16 *) ((gid).raw + 10)), \ |
| 373 | be16_to_cpup((__be16 *) ((gid).raw + 12)), \ |
| 374 | be16_to_cpup((__be16 *) ((gid).raw + 14)) |
| 375 | |
| 376 | #endif /* _IPOIB_H */ |