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