1 /* 2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 4 * Copyright (c) 2004 Voltaire, Inc. All rights reserved. 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 35 #ifndef _IPOIB_H 36 #define _IPOIB_H 37 38 #include "opt_inet.h" 39 #include "opt_inet6.h" 40 #include "opt_ofed.h" 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/kernel.h> 45 #include <sys/lock.h> 46 #include <sys/malloc.h> 47 #include <sys/mbuf.h> 48 #include <sys/random.h> 49 #include <sys/rwlock.h> 50 #include <sys/socket.h> 51 #include <sys/sockio.h> 52 #include <sys/sysctl.h> 53 54 #include <net/if.h> 55 #include <net/if_var.h> 56 #include <net/if_arp.h> 57 #include <net/netisr.h> 58 #include <net/route.h> 59 #include <net/if_llc.h> 60 #include <net/if_dl.h> 61 #include <net/if_types.h> 62 #include <net/bpf.h> 63 #include <net/if_llatbl.h> 64 #include <net/vnet.h> 65 66 #if defined(INET) || defined(INET6) 67 #include <netinet/in.h> 68 #include <netinet/in_var.h> 69 #include <netinet/if_ether.h> 70 #include <netinet/ip_var.h> 71 #endif 72 #ifdef INET6 73 #include <netinet6/nd6.h> 74 #endif 75 76 #include <security/mac/mac_framework.h> 77 78 #include <linux/list.h> 79 80 #include <linux/workqueue.h> 81 #include <linux/kref.h> 82 #include <linux/mutex.h> 83 #include <linux/rbtree.h> 84 85 #include <asm/atomic.h> 86 87 #include <rdma/ib_verbs.h> 88 #include <rdma/ib_pack.h> 89 #include <rdma/ib_sa.h> 90 91 /* constants */ 92 93 #define INFINIBAND_ALEN 20 /* Octets in IPoIB HW addr */ 94 95 #ifdef IPOIB_CM 96 #define CONFIG_INFINIBAND_IPOIB_CM 97 #endif 98 99 #ifdef IPOIB_DEBUG 100 #define CONFIG_INFINIBAND_IPOIB_DEBUG 101 #define CONFIG_INFINIBAND_IPOIB_DEBUG_DATA 102 #endif 103 104 enum ipoib_flush_level { 105 IPOIB_FLUSH_LIGHT, 106 IPOIB_FLUSH_NORMAL, 107 IPOIB_FLUSH_HEAVY 108 }; 109 110 enum { 111 IPOIB_ENCAP_LEN = 4, 112 IPOIB_HEADER_LEN = IPOIB_ENCAP_LEN + INFINIBAND_ALEN, 113 IPOIB_UD_MAX_MTU = 4 * 1024, 114 // IPOIB_UD_RX_SG = (IPOIB_UD_MAX_MTU / MJUMPAGESIZE), 115 IPOIB_UD_RX_SG = 2, 116 IPOIB_UD_TX_SG = (IPOIB_UD_MAX_MTU / MCLBYTES) + 2, 117 IPOIB_CM_MAX_MTU = (64 * 1024), 118 IPOIB_CM_TX_SG = (IPOIB_CM_MAX_MTU / MCLBYTES) + 2, 119 IPOIB_CM_RX_SG = (IPOIB_CM_MAX_MTU / MJUMPAGESIZE), 120 IPOIB_RX_RING_SIZE = 256, 121 IPOIB_TX_RING_SIZE = 128, 122 IPOIB_MAX_RX_SG = MAX(IPOIB_CM_RX_SG, IPOIB_UD_RX_SG), 123 IPOIB_MAX_TX_SG = MAX(IPOIB_CM_TX_SG, IPOIB_UD_TX_SG), 124 IPOIB_MAX_QUEUE_SIZE = 8192, 125 IPOIB_MIN_QUEUE_SIZE = 2, 126 IPOIB_CM_MAX_CONN_QP = 4096, 127 128 IPOIB_NUM_WC = 4, 129 130 IPOIB_MAX_PATH_REC_QUEUE = 3, 131 IPOIB_MAX_MCAST_QUEUE = 3, 132 133 IPOIB_FLAG_OPER_UP = 0, 134 IPOIB_FLAG_INITIALIZED = 1, 135 IPOIB_FLAG_ADMIN_UP = 2, 136 IPOIB_PKEY_ASSIGNED = 3, 137 IPOIB_PKEY_STOP = 4, 138 IPOIB_FLAG_SUBINTERFACE = 5, 139 IPOIB_MCAST_RUN = 6, 140 IPOIB_STOP_REAPER = 7, 141 IPOIB_FLAG_UMCAST = 10, 142 IPOIB_FLAG_CSUM = 11, 143 144 IPOIB_MAX_BACKOFF_SECONDS = 16, 145 146 IPOIB_MCAST_FLAG_FOUND = 0, /* used in set_multicast_list */ 147 IPOIB_MCAST_FLAG_SENDONLY = 1, 148 IPOIB_MCAST_FLAG_BUSY = 2, /* joining or already joined */ 149 IPOIB_MCAST_FLAG_ATTACHED = 3, 150 151 IPOIB_MAX_LRO_DESCRIPTORS = 8, 152 IPOIB_LRO_MAX_AGGR = 64, 153 154 MAX_SEND_CQE = 16, 155 IPOIB_CM_COPYBREAK = 256, 156 }; 157 158 #define IPOIB_OP_RECV (1ul << 31) 159 #ifdef CONFIG_INFINIBAND_IPOIB_CM 160 #define IPOIB_OP_CM (1ul << 30) 161 #else 162 #define IPOIB_OP_CM (0) 163 #endif 164 165 /* structs */ 166 167 struct ipoib_header { 168 u8 hwaddr[INFINIBAND_ALEN]; 169 __be16 proto; 170 u16 reserved; 171 }; 172 173 struct ipoib_pseudoheader { 174 u8 hwaddr[INFINIBAND_ALEN]; 175 }; 176 177 /* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */ 178 struct ipoib_mcast { 179 struct ib_sa_mcmember_rec mcmember; 180 struct ib_sa_multicast *mc; 181 struct ipoib_ah *ah; 182 183 struct rb_node rb_node; 184 struct list_head list; 185 186 unsigned long created; 187 unsigned long backoff; 188 189 unsigned long flags; 190 unsigned char logcount; 191 192 struct ifqueue pkt_queue; 193 194 struct ipoib_dev_priv *priv; 195 }; 196 197 struct ipoib_cm_rx_buf { 198 struct mbuf *mb; 199 u64 mapping[IPOIB_CM_RX_SG]; 200 }; 201 202 struct ipoib_cm_tx_buf { 203 struct mbuf *mb; 204 u64 mapping[IPOIB_CM_TX_SG]; 205 }; 206 207 struct ipoib_rx_buf { 208 struct mbuf *mb; 209 u64 mapping[IPOIB_UD_RX_SG]; 210 }; 211 212 struct ipoib_tx_buf { 213 struct mbuf *mb; 214 u64 mapping[IPOIB_UD_TX_SG]; 215 }; 216 217 struct ib_cm_id; 218 219 struct ipoib_cm_data { 220 __be32 qpn; /* High byte MUST be ignored on receive */ 221 __be32 mtu; 222 }; 223 224 /* 225 * Quoting 10.3.1 Queue Pair and EE Context States: 226 * 227 * Note, for QPs that are associated with an SRQ, the Consumer should take the 228 * QP through the Error State before invoking a Destroy QP or a Modify QP to the 229 * Reset State. The Consumer may invoke the Destroy QP without first performing 230 * a Modify QP to the Error State and waiting for the Affiliated Asynchronous 231 * Last WQE Reached Event. However, if the Consumer does not wait for the 232 * Affiliated Asynchronous Last WQE Reached Event, then WQE and Data Segment 233 * leakage may occur. Therefore, it is good programming practice to tear down a 234 * QP that is associated with an SRQ by using the following process: 235 * 236 * - Put the QP in the Error State 237 * - Wait for the Affiliated Asynchronous Last WQE Reached Event; 238 * - either: 239 * drain the CQ by invoking the Poll CQ verb and either wait for CQ 240 * to be empty or the number of Poll CQ operations has exceeded 241 * CQ capacity size; 242 * - or 243 * post another WR that completes on the same CQ and wait for this 244 * WR to return as a WC; 245 * - and then invoke a Destroy QP or Reset QP. 246 * 247 * We use the second option and wait for a completion on the 248 * same CQ before destroying QPs attached to our SRQ. 249 */ 250 251 enum ipoib_cm_state { 252 IPOIB_CM_RX_LIVE, 253 IPOIB_CM_RX_ERROR, /* Ignored by stale task */ 254 IPOIB_CM_RX_FLUSH /* Last WQE Reached event observed */ 255 }; 256 257 struct ipoib_cm_rx { 258 struct ib_cm_id *id; 259 struct ib_qp *qp; 260 struct ipoib_cm_rx_buf *rx_ring; 261 struct list_head list; 262 struct ipoib_dev_priv *priv; 263 unsigned long jiffies; 264 enum ipoib_cm_state state; 265 int recv_count; 266 }; 267 268 struct ipoib_cm_tx { 269 struct ib_cm_id *id; 270 struct ib_qp *qp; 271 struct list_head list; 272 struct ipoib_dev_priv *priv; 273 struct ipoib_path *path; 274 struct ipoib_cm_tx_buf *tx_ring; 275 unsigned tx_head; 276 unsigned tx_tail; 277 unsigned long flags; 278 u32 mtu; /* remote specified mtu, with grh. */ 279 }; 280 281 struct ipoib_cm_dev_priv { 282 struct ib_srq *srq; 283 struct ipoib_cm_rx_buf *srq_ring; 284 struct ib_cm_id *id; 285 struct list_head passive_ids; /* state: LIVE */ 286 struct list_head rx_error_list; /* state: ERROR */ 287 struct list_head rx_flush_list; /* state: FLUSH, drain not started */ 288 struct list_head rx_drain_list; /* state: FLUSH, drain started */ 289 struct list_head rx_reap_list; /* state: FLUSH, drain done */ 290 struct work_struct start_task; 291 struct work_struct reap_task; 292 struct work_struct mb_task; 293 struct work_struct rx_reap_task; 294 struct delayed_work stale_task; 295 struct ifqueue mb_queue; 296 struct list_head start_list; 297 struct list_head reap_list; 298 struct ib_sge rx_sge[IPOIB_CM_RX_SG]; 299 struct ib_recv_wr rx_wr; 300 int nonsrq_conn_qp; 301 int max_cm_mtu; /* Actual buf size. */ 302 int num_frags; 303 }; 304 305 struct ipoib_ethtool_st { 306 u16 coalesce_usecs; 307 u16 max_coalesced_frames; 308 }; 309 310 /* 311 * Device private locking: network stack tx_lock protects members used 312 * in TX fast path, lock protects everything else. lock nests inside 313 * of tx_lock (ie tx_lock must be acquired first if needed). 314 */ 315 struct ipoib_dev_priv { 316 spinlock_t lock; 317 spinlock_t drain_lock; 318 319 struct ifnet *dev; 320 321 u8 broadcastaddr[INFINIBAND_ALEN]; 322 323 unsigned long flags; 324 325 int gone; 326 327 struct mutex vlan_mutex; 328 329 struct rb_root path_tree; 330 struct list_head path_list; 331 332 struct ipoib_mcast *broadcast; 333 struct list_head multicast_list; 334 struct rb_root multicast_tree; 335 336 struct delayed_work pkey_poll_task; 337 struct delayed_work mcast_task; 338 struct work_struct carrier_on_task; 339 struct work_struct flush_light; 340 struct work_struct flush_normal; 341 struct work_struct flush_heavy; 342 struct work_struct restart_task; 343 struct delayed_work ah_reap_task; 344 345 struct ib_device *ca; 346 u8 port; 347 u16 pkey; 348 u16 pkey_index; 349 struct ib_pd *pd; 350 struct ib_mr *mr; 351 struct ib_cq *recv_cq; 352 struct ib_cq *send_cq; 353 struct ib_qp *qp; 354 u32 qkey; 355 356 union ib_gid local_gid; 357 u16 local_lid; 358 359 unsigned int admin_mtu; /* User selected MTU, no GRH. */ 360 unsigned int mcast_mtu; /* Minus GRH bytes, from mcast group. */ 361 unsigned int max_ib_mtu; /* Without header, actual buf size. */ 362 363 struct ipoib_rx_buf *rx_ring; 364 365 struct ipoib_tx_buf *tx_ring; 366 unsigned tx_head; 367 unsigned tx_tail; 368 struct ib_sge tx_sge[IPOIB_MAX_TX_SG]; 369 struct ib_send_wr tx_wr; 370 unsigned tx_outstanding; 371 struct ib_wc send_wc[MAX_SEND_CQE]; 372 373 struct ib_recv_wr rx_wr; 374 struct ib_sge rx_sge[IPOIB_MAX_RX_SG]; 375 376 struct ib_wc ibwc[IPOIB_NUM_WC]; 377 378 struct list_head dead_ahs; 379 380 struct ib_event_handler event_handler; 381 382 struct ifnet *parent; 383 struct list_head child_intfs; 384 struct list_head list; 385 386 #ifdef CONFIG_INFINIBAND_IPOIB_CM 387 struct ipoib_cm_dev_priv cm; 388 #endif 389 390 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG 391 struct list_head fs_list; 392 struct dentry *mcg_dentry; 393 struct dentry *path_dentry; 394 #endif 395 int hca_caps; 396 struct ipoib_ethtool_st ethtool; 397 struct timer_list poll_timer; 398 }; 399 400 struct ipoib_ah { 401 struct ipoib_dev_priv *priv; 402 struct ib_ah *ah; 403 struct list_head list; 404 struct kref ref; 405 unsigned last_send; 406 }; 407 408 struct ipoib_path { 409 struct ipoib_dev_priv *priv; 410 struct rb_node rb_node; 411 struct list_head list; 412 #ifdef CONFIG_INFINIBAND_IPOIB_CM 413 uint8_t hwaddr[INFINIBAND_ALEN]; 414 struct ipoib_cm_tx *cm; 415 #endif 416 struct ipoib_ah *ah; 417 struct ib_sa_path_rec pathrec; 418 struct ifqueue queue; 419 420 int query_id; 421 struct ib_sa_query *query; 422 struct completion done; 423 424 int valid; 425 }; 426 427 /* UD Only transmits encap len but we want the two sizes to be symmetrical. */ 428 #define IPOIB_UD_MTU(ib_mtu) (ib_mtu - IPOIB_ENCAP_LEN) 429 #define IPOIB_CM_MTU(ib_mtu) (ib_mtu - 0x10) 430 431 #define IPOIB_IS_MULTICAST(addr) ((addr)[4] == 0xff) 432 433 extern struct workqueue_struct *ipoib_workqueue; 434 435 #define IPOIB_MTAP_PROTO(_ifp, _m, _proto) \ 436 do { \ 437 if (bpf_peers_present((_ifp)->if_bpf)) { \ 438 M_ASSERTVALID(_m); \ 439 ipoib_mtap_proto((_ifp), (_m), (_proto)); \ 440 } \ 441 } while (0) 442 443 /* functions */ 444 void ipoib_mtap_proto(struct ifnet *ifp, struct mbuf *mb, uint16_t proto); 445 void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr); 446 void ipoib_send_comp_handler(struct ib_cq *cq, void *dev_ptr); 447 448 struct ipoib_ah *ipoib_create_ah(struct ipoib_dev_priv *, 449 struct ib_pd *pd, struct ib_ah_attr *attr); 450 void ipoib_free_ah(struct kref *kref); 451 static inline void ipoib_put_ah(struct ipoib_ah *ah) 452 { 453 kref_put(&ah->ref, ipoib_free_ah); 454 } 455 456 int ipoib_open(struct ipoib_dev_priv *priv); 457 int ipoib_add_pkey_attr(struct ipoib_dev_priv *priv); 458 int ipoib_add_umcast_attr(struct ipoib_dev_priv *priv); 459 460 void ipoib_demux(struct ifnet *ifp, struct mbuf *m, u_short proto); 461 462 void ipoib_send(struct ipoib_dev_priv *priv, struct mbuf *mb, 463 struct ipoib_ah *address, u32 qpn); 464 void ipoib_reap_ah(struct work_struct *work); 465 466 void ipoib_mark_paths_invalid(struct ipoib_dev_priv *priv); 467 void ipoib_flush_paths(struct ipoib_dev_priv *priv); 468 struct ipoib_dev_priv *ipoib_intf_alloc(const char *format); 469 470 int ipoib_ib_dev_init(struct ipoib_dev_priv *priv, struct ib_device *ca, 471 int port); 472 void ipoib_ib_dev_flush_light(struct work_struct *work); 473 void ipoib_ib_dev_flush_normal(struct work_struct *work); 474 void ipoib_ib_dev_flush_heavy(struct work_struct *work); 475 void ipoib_pkey_event(struct work_struct *work); 476 void ipoib_ib_dev_cleanup(struct ipoib_dev_priv *priv); 477 478 int ipoib_ib_dev_open(struct ipoib_dev_priv *priv); 479 int ipoib_ib_dev_up(struct ipoib_dev_priv *priv); 480 int ipoib_ib_dev_down(struct ipoib_dev_priv *priv, int flush); 481 int ipoib_ib_dev_stop(struct ipoib_dev_priv *priv, int flush); 482 483 int ipoib_dev_init(struct ipoib_dev_priv *priv, struct ib_device *ca, int port); 484 void ipoib_dev_cleanup(struct ipoib_dev_priv *priv); 485 486 void ipoib_mcast_join_task(struct work_struct *work); 487 void ipoib_mcast_carrier_on_task(struct work_struct *work); 488 void ipoib_mcast_send(struct ipoib_dev_priv *priv, void *mgid, struct mbuf *mb); 489 490 void ipoib_mcast_restart_task(struct work_struct *work); 491 void ipoib_mcast_restart(struct ipoib_dev_priv *); 492 int ipoib_mcast_start_thread(struct ipoib_dev_priv *priv); 493 int ipoib_mcast_stop_thread(struct ipoib_dev_priv *priv, int flush); 494 495 void ipoib_mcast_dev_down(struct ipoib_dev_priv *priv); 496 void ipoib_mcast_dev_flush(struct ipoib_dev_priv *priv); 497 498 void ipoib_path_free(struct ipoib_dev_priv *priv, struct ipoib_path *path); 499 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG 500 struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct ipoib_dev_priv *priv); 501 int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter); 502 void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter, 503 union ib_gid *gid, 504 unsigned long *created, 505 unsigned int *queuelen, 506 unsigned int *complete, 507 unsigned int *send_only); 508 509 struct ipoib_path_iter *ipoib_path_iter_init(struct ipoib_dev_priv *priv); 510 int ipoib_path_iter_next(struct ipoib_path_iter *iter); 511 void ipoib_path_iter_read(struct ipoib_path_iter *iter, 512 struct ipoib_path *path); 513 #endif 514 515 int ipoib_change_mtu(struct ipoib_dev_priv *priv, int new_mtu); 516 517 int ipoib_mcast_attach(struct ipoib_dev_priv *priv, u16 mlid, 518 union ib_gid *mgid, int set_qkey); 519 520 int ipoib_init_qp(struct ipoib_dev_priv *priv); 521 int ipoib_transport_dev_init(struct ipoib_dev_priv *priv, struct ib_device *ca); 522 void ipoib_transport_dev_cleanup(struct ipoib_dev_priv *priv); 523 524 void ipoib_event(struct ib_event_handler *handler, 525 struct ib_event *record); 526 527 void ipoib_pkey_poll(struct work_struct *work); 528 int ipoib_pkey_dev_delay_open(struct ipoib_dev_priv *priv); 529 void ipoib_drain_cq(struct ipoib_dev_priv *priv); 530 531 int ipoib_dma_map_tx(struct ib_device *ca, struct ipoib_tx_buf *tx_req, int max); 532 void ipoib_dma_unmap_tx(struct ib_device *ca, struct ipoib_tx_buf *tx_req); 533 int ipoib_poll_tx(struct ipoib_dev_priv *priv); 534 535 void ipoib_dma_unmap_rx(struct ipoib_dev_priv *priv, struct ipoib_rx_buf *rx_req); 536 void ipoib_dma_mb(struct ipoib_dev_priv *priv, struct mbuf *mb, unsigned int length); 537 struct mbuf *ipoib_alloc_map_mb(struct ipoib_dev_priv *priv, struct ipoib_rx_buf *rx_req, int size); 538 539 540 void ipoib_set_ethtool_ops(struct ifnet *dev); 541 int ipoib_set_dev_features(struct ipoib_dev_priv *priv, struct ib_device *hca); 542 543 #ifdef CONFIG_INFINIBAND_IPOIB_CM 544 545 #define IPOIB_FLAGS_RC 0x80 546 #define IPOIB_FLAGS_UC 0x40 547 548 /* We don't support UC connections at the moment */ 549 #define IPOIB_CM_SUPPORTED(ha) (ha[0] & (IPOIB_FLAGS_RC)) 550 551 extern int ipoib_max_conn_qp; 552 553 static inline int ipoib_cm_admin_enabled(struct ipoib_dev_priv *priv) 554 { 555 return IPOIB_CM_SUPPORTED(IF_LLADDR(priv->dev)); 556 } 557 558 static inline int ipoib_cm_enabled(struct ipoib_dev_priv *priv, uint8_t *hwaddr) 559 { 560 return IPOIB_CM_SUPPORTED(hwaddr); 561 } 562 563 static inline int ipoib_cm_up(struct ipoib_path *path) 564 565 { 566 return test_bit(IPOIB_FLAG_OPER_UP, &path->cm->flags); 567 } 568 569 static inline struct ipoib_cm_tx *ipoib_cm_get(struct ipoib_path *path) 570 { 571 return path->cm; 572 } 573 574 static inline void ipoib_cm_set(struct ipoib_path *path, struct ipoib_cm_tx *tx) 575 { 576 path->cm = tx; 577 } 578 579 static inline int ipoib_cm_has_srq(struct ipoib_dev_priv *priv) 580 { 581 return !!priv->cm.srq; 582 } 583 584 static inline unsigned int ipoib_cm_max_mtu(struct ipoib_dev_priv *priv) 585 { 586 return priv->cm.max_cm_mtu; 587 } 588 589 void ipoib_cm_send(struct ipoib_dev_priv *priv, struct mbuf *mb, struct ipoib_cm_tx *tx); 590 int ipoib_cm_dev_open(struct ipoib_dev_priv *priv); 591 void ipoib_cm_dev_stop(struct ipoib_dev_priv *priv); 592 int ipoib_cm_dev_init(struct ipoib_dev_priv *priv); 593 int ipoib_cm_add_mode_attr(struct ipoib_dev_priv *priv); 594 void ipoib_cm_dev_cleanup(struct ipoib_dev_priv *priv); 595 struct ipoib_cm_tx *ipoib_cm_create_tx(struct ipoib_dev_priv *priv, 596 struct ipoib_path *path); 597 void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx); 598 void ipoib_cm_mb_too_long(struct ipoib_dev_priv *priv, struct mbuf *mb, 599 unsigned int mtu); 600 void ipoib_cm_handle_rx_wc(struct ipoib_dev_priv *priv, struct ib_wc *wc); 601 void ipoib_cm_handle_tx_wc(struct ipoib_dev_priv *priv, struct ib_wc *wc); 602 #else 603 604 struct ipoib_cm_tx; 605 606 #define ipoib_max_conn_qp 0 607 608 static inline int ipoib_cm_admin_enabled(struct ipoib_dev_priv *priv) 609 { 610 return 0; 611 } 612 static inline int ipoib_cm_enabled(struct ipoib_dev_priv *priv, uint8_t *hwaddr) 613 614 { 615 return 0; 616 } 617 618 static inline int ipoib_cm_up(struct ipoib_path *path) 619 620 { 621 return 0; 622 } 623 624 static inline struct ipoib_cm_tx *ipoib_cm_get(struct ipoib_path *path) 625 { 626 return NULL; 627 } 628 629 static inline void ipoib_cm_set(struct ipoib_path *path, struct ipoib_cm_tx *tx) 630 { 631 } 632 633 static inline int ipoib_cm_has_srq(struct ipoib_dev_priv *priv) 634 { 635 return 0; 636 } 637 638 static inline unsigned int ipoib_cm_max_mtu(struct ipoib_dev_priv *priv) 639 { 640 return 0; 641 } 642 643 static inline 644 void ipoib_cm_send(struct ipoib_dev_priv *priv, struct mbuf *mb, struct ipoib_cm_tx *tx) 645 { 646 return; 647 } 648 649 static inline 650 int ipoib_cm_dev_open(struct ipoib_dev_priv *priv) 651 { 652 return 0; 653 } 654 655 static inline 656 void ipoib_cm_dev_stop(struct ipoib_dev_priv *priv) 657 { 658 return; 659 } 660 661 static inline 662 int ipoib_cm_dev_init(struct ipoib_dev_priv *priv) 663 { 664 return -ENOSYS; 665 } 666 667 static inline 668 void ipoib_cm_dev_cleanup(struct ipoib_dev_priv *priv) 669 { 670 return; 671 } 672 673 static inline 674 struct ipoib_cm_tx *ipoib_cm_create_tx(struct ipoib_dev_priv *priv, struct ipoib_path *path) 675 { 676 return NULL; 677 } 678 679 static inline 680 void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx) 681 { 682 return; 683 } 684 685 static inline 686 int ipoib_cm_add_mode_attr(struct ipoib_dev_priv *priv) 687 { 688 return 0; 689 } 690 691 static inline void ipoib_cm_mb_too_long(struct ipoib_dev_priv *priv, struct mbuf *mb, 692 unsigned int mtu) 693 { 694 m_freem(mb); 695 } 696 697 static inline void ipoib_cm_handle_rx_wc(struct ipoib_dev_priv *priv, struct ib_wc *wc) 698 { 699 } 700 701 static inline void ipoib_cm_handle_tx_wc(struct ipoib_dev_priv *priv, struct ib_wc *wc) 702 { 703 } 704 #endif 705 706 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG 707 void ipoib_create_debug_files(struct ipoib_dev_priv *priv); 708 void ipoib_delete_debug_files(struct ipoib_dev_priv *priv); 709 int ipoib_register_debugfs(void); 710 void ipoib_unregister_debugfs(void); 711 #else 712 static inline void ipoib_create_debug_files(struct ipoib_dev_priv *priv) { } 713 static inline void ipoib_delete_debug_files(struct ipoib_dev_priv *priv) { } 714 static inline int ipoib_register_debugfs(void) { return 0; } 715 static inline void ipoib_unregister_debugfs(void) { } 716 #endif 717 718 #define ipoib_printk(level, priv, format, arg...) \ 719 printk(level "%s: " format, if_name(((struct ipoib_dev_priv *) priv)->dev), ## arg) 720 #define ipoib_warn(priv, format, arg...) \ 721 ipoib_printk(KERN_WARNING, priv, format , ## arg) 722 723 extern int ipoib_sendq_size; 724 extern int ipoib_recvq_size; 725 726 extern struct ib_sa_client ipoib_sa_client; 727 728 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG 729 extern int ipoib_debug_level; 730 731 #define ipoib_dbg(priv, format, arg...) \ 732 do { \ 733 if (ipoib_debug_level > 0) \ 734 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ 735 } while (0) 736 #define ipoib_dbg_mcast(priv, format, arg...) \ 737 do { \ 738 if (mcast_debug_level > 0) \ 739 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ 740 } while (0) 741 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */ 742 #define ipoib_dbg(priv, format, arg...) \ 743 do { (void) (priv); } while (0) 744 #define ipoib_dbg_mcast(priv, format, arg...) \ 745 do { (void) (priv); } while (0) 746 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */ 747 748 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA 749 #define ipoib_dbg_data(priv, format, arg...) \ 750 do { \ 751 if (data_debug_level > 0) \ 752 ipoib_printk(KERN_DEBUG, priv, format , ## arg); \ 753 } while (0) 754 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */ 755 #define ipoib_dbg_data(priv, format, arg...) \ 756 do { (void) (priv); } while (0) 757 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */ 758 759 #define IPOIB_QPN(ha) (be32_to_cpup((__be32 *) ha) & 0xffffff) 760 761 #endif /* _IPOIB_H */ 762