1 /* 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 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 * $Id: ipoib.h 1358 2004-12-17 22:00:11Z roland $ 33 */ 34 35 #ifndef _IPOIB_H 36 #define _IPOIB_H 37 38 #include <linux/list.h> 39 #include <linux/skbuff.h> 40 #include <linux/netdevice.h> 41 #include <linux/workqueue.h> 42 #include <linux/pci.h> 43 #include <linux/config.h> 44 #include <linux/kref.h> 45 #include <linux/if_infiniband.h> 46 47 #include <net/neighbour.h> 48 49 #include <asm/atomic.h> 50 #include <asm/semaphore.h> 51 52 #include <ib_verbs.h> 53 #include <ib_pack.h> 54 #include <ib_sa.h> 55 56 /* constants */ 57 58 enum { 59 IPOIB_PACKET_SIZE = 2048, 60 IPOIB_BUF_SIZE = IPOIB_PACKET_SIZE + IB_GRH_BYTES, 61 62 IPOIB_ENCAP_LEN = 4, 63 64 IPOIB_RX_RING_SIZE = 128, 65 IPOIB_TX_RING_SIZE = 64, 66 67 IPOIB_NUM_WC = 4, 68 69 IPOIB_MAX_PATH_REC_QUEUE = 3, 70 IPOIB_MAX_MCAST_QUEUE = 3, 71 72 IPOIB_FLAG_OPER_UP = 0, 73 IPOIB_FLAG_ADMIN_UP = 1, 74 IPOIB_PKEY_ASSIGNED = 2, 75 IPOIB_PKEY_STOP = 3, 76 IPOIB_FLAG_SUBINTERFACE = 4, 77 IPOIB_MCAST_RUN = 5, 78 IPOIB_STOP_REAPER = 6, 79 80 IPOIB_MAX_BACKOFF_SECONDS = 16, 81 82 IPOIB_MCAST_FLAG_FOUND = 0, /* used in set_multicast_list */ 83 IPOIB_MCAST_FLAG_SENDONLY = 1, 84 IPOIB_MCAST_FLAG_BUSY = 2, /* joining or already joined */ 85 IPOIB_MCAST_FLAG_ATTACHED = 3, 86 }; 87 88 /* structs */ 89 90 struct ipoib_header { 91 u16 proto; 92 u16 reserved; 93 }; 94 95 struct ipoib_pseudoheader { 96 u8 hwaddr[INFINIBAND_ALEN]; 97 }; 98 99 struct ipoib_mcast; 100 101 struct ipoib_buf { 102 struct sk_buff *skb; 103 DECLARE_PCI_UNMAP_ADDR(mapping) 104 }; 105 106 /* 107 * Device private locking: tx_lock protects members used in TX fast 108 * path (and we use LLTX so upper layers don't do extra locking). 109 * lock protects everything else. lock nests inside of tx_lock (ie 110 * tx_lock must be acquired first if needed). 111 */ 112 struct ipoib_dev_priv { 113 spinlock_t lock; 114 115 struct net_device *dev; 116 117 unsigned long flags; 118 119 struct semaphore mcast_mutex; 120 struct semaphore vlan_mutex; 121 122 struct rb_root path_tree; 123 struct list_head path_list; 124 125 struct ipoib_mcast *broadcast; 126 struct list_head multicast_list; 127 struct rb_root multicast_tree; 128 129 struct work_struct pkey_task; 130 struct work_struct mcast_task; 131 struct work_struct flush_task; 132 struct work_struct restart_task; 133 struct work_struct ah_reap_task; 134 135 struct ib_device *ca; 136 u8 port; 137 u16 pkey; 138 struct ib_pd *pd; 139 struct ib_mr *mr; 140 struct ib_cq *cq; 141 struct ib_qp *qp; 142 u32 qkey; 143 144 union ib_gid local_gid; 145 u16 local_lid; 146 u8 local_rate; 147 148 unsigned int admin_mtu; 149 unsigned int mcast_mtu; 150 151 struct ipoib_buf *rx_ring; 152 153 spinlock_t tx_lock; 154 struct ipoib_buf *tx_ring; 155 unsigned tx_head; 156 unsigned tx_tail; 157 struct ib_sge tx_sge; 158 struct ib_send_wr tx_wr; 159 160 struct ib_wc ibwc[IPOIB_NUM_WC]; 161 162 struct list_head dead_ahs; 163 164 struct ib_event_handler event_handler; 165 166 struct net_device_stats stats; 167 168 struct net_device *parent; 169 struct list_head child_intfs; 170 struct list_head list; 171 172 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG 173 struct list_head fs_list; 174 struct dentry *mcg_dentry; 175 #endif 176 }; 177 178 struct ipoib_ah { 179 struct net_device *dev; 180 struct ib_ah *ah; 181 struct list_head list; 182 struct kref ref; 183 unsigned last_send; 184 }; 185 186 struct ipoib_path { 187 struct net_device *dev; 188 struct ib_sa_path_rec pathrec; 189 struct ipoib_ah *ah; 190 struct sk_buff_head queue; 191 192 struct list_head neigh_list; 193 194 int query_id; 195 struct ib_sa_query *query; 196 struct completion done; 197 198 struct rb_node rb_node; 199 struct list_head list; 200 }; 201 202 struct ipoib_neigh { 203 struct ipoib_ah *ah; 204 struct sk_buff_head queue; 205 206 struct neighbour *neighbour; 207 208 struct list_head list; 209 }; 210 211 static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh) 212 { 213 return (struct ipoib_neigh **) (neigh->ha + 24 - 214 (offsetof(struct neighbour, ha) & 4)); 215 } 216 217 extern struct workqueue_struct *ipoib_workqueue; 218 219 /* functions */ 220 221 void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr); 222 223 struct ipoib_ah *ipoib_create_ah(struct net_device *dev, 224 struct ib_pd *pd, struct ib_ah_attr *attr); 225 void ipoib_free_ah(struct kref *kref); 226 static inline void ipoib_put_ah(struct ipoib_ah *ah) 227 { 228 kref_put(&ah->ref, ipoib_free_ah); 229 } 230 231 int ipoib_add_pkey_attr(struct net_device *dev); 232 233 void ipoib_send(struct net_device *dev, struct sk_buff *skb, 234 struct ipoib_ah *address, u32 qpn); 235 void ipoib_reap_ah(void *dev_ptr); 236 237 void ipoib_flush_paths(struct net_device *dev); 238 struct ipoib_dev_priv *ipoib_intf_alloc(const char *format); 239 240 int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port); 241 void ipoib_ib_dev_flush(void *dev); 242 void ipoib_ib_dev_cleanup(struct net_device *dev); 243 244 int ipoib_ib_dev_open(struct net_device *dev); 245 int ipoib_ib_dev_up(struct net_device *dev); 246 int ipoib_ib_dev_down(struct net_device *dev); 247 int ipoib_ib_dev_stop(struct net_device *dev); 248 249 int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port); 250 void ipoib_dev_cleanup(struct net_device *dev); 251 252 void ipoib_mcast_join_task(void *dev_ptr); 253 void ipoib_mcast_send(struct net_device *dev, union ib_gid *mgid, 254 struct sk_buff *skb); 255 256 void ipoib_mcast_restart_task(void *dev_ptr); 257 int ipoib_mcast_start_thread(struct net_device *dev); 258 int ipoib_mcast_stop_thread(struct net_device *dev); 259 260 void ipoib_mcast_dev_down(struct net_device *dev); 261 void ipoib_mcast_dev_flush(struct net_device *dev); 262 263 struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev); 264 void ipoib_mcast_iter_free(struct ipoib_mcast_iter *iter); 265 int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter); 266 void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter, 267 union ib_gid *gid, 268 unsigned long *created, 269 unsigned int *queuelen, 270 unsigned int *complete, 271 unsigned int *send_only); 272 273 int ipoib_mcast_attach(struct net_device *dev, u16 mlid, 274 union ib_gid *mgid); 275 int ipoib_mcast_detach(struct net_device *dev, u16 mlid, 276 union ib_gid *mgid); 277 278 int ipoib_qp_create(struct net_device *dev); 279 int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca); 280 void ipoib_transport_dev_cleanup(struct net_device *dev); 281 282 void ipoib_event(struct ib_event_handler *handler, 283 struct ib_event *record); 284 285 int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey); 286 int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey); 287 288 void ipoib_pkey_poll(void *dev); 289 int ipoib_pkey_dev_delay_open(struct net_device *dev); 290 291 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG 292 int ipoib_create_debug_file(struct net_device *dev); 293 void ipoib_delete_debug_file(struct net_device *dev); 294 int ipoib_register_debugfs(void); 295 void ipoib_unregister_debugfs(void); 296 #else 297 static inline int ipoib_create_debug_file(struct net_device *dev) { return 0; } 298 static inline void ipoib_delete_debug_file(struct net_device *dev) { } 299 static inline int ipoib_register_debugfs(void) { return 0; } 300 static inline void ipoib_unregister_debugfs(void) { } 301 #endif 302 303 304 #define ipoib_printk(level, priv, format, arg...) \ 305 printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg) 306 #define ipoib_warn(priv, format, arg...) \ 307 ipoib_printk(KERN_WARNING, priv, format , ## arg) 308 309 310 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG 311 extern int ipoib_debug_level; 312 313 #define ipoib_dbg(priv, format, arg...) \ 314 do { \ 315 if (ipoib_debug_level > 0) \ 316 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ 317 } while (0) 318 #define ipoib_dbg_mcast(priv, format, arg...) \ 319 do { \ 320 if (mcast_debug_level > 0) \ 321 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ 322 } while (0) 323 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */ 324 #define ipoib_dbg(priv, format, arg...) \ 325 do { (void) (priv); } while (0) 326 #define ipoib_dbg_mcast(priv, format, arg...) \ 327 do { (void) (priv); } while (0) 328 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */ 329 330 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA 331 #define ipoib_dbg_data(priv, format, arg...) \ 332 do { \ 333 if (data_debug_level > 0) \ 334 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ 335 } while (0) 336 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */ 337 #define ipoib_dbg_data(priv, format, arg...) \ 338 do { (void) (priv); } while (0) 339 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */ 340 341 342 #define IPOIB_GID_FMT "%x:%x:%x:%x:%x:%x:%x:%x" 343 344 #define IPOIB_GID_ARG(gid) be16_to_cpup((__be16 *) ((gid).raw + 0)), \ 345 be16_to_cpup((__be16 *) ((gid).raw + 2)), \ 346 be16_to_cpup((__be16 *) ((gid).raw + 4)), \ 347 be16_to_cpup((__be16 *) ((gid).raw + 6)), \ 348 be16_to_cpup((__be16 *) ((gid).raw + 8)), \ 349 be16_to_cpup((__be16 *) ((gid).raw + 10)), \ 350 be16_to_cpup((__be16 *) ((gid).raw + 12)), \ 351 be16_to_cpup((__be16 *) ((gid).raw + 14)) 352 353 #endif /* _IPOIB_H */ 354