Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
0003  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
0004  * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
0005  *
0006  * This software is available to you under a choice of one of two
0007  * licenses.  You may choose to be licensed under the terms of the GNU
0008  * General Public License (GPL) Version 2, available from the file
0009  * COPYING in the main directory of this source tree, or the
0010  * OpenIB.org BSD license below:
0011  *
0012  *     Redistribution and use in source and binary forms, with or
0013  *     without modification, are permitted provided that the following
0014  *     conditions are met:
0015  *
0016  *      - Redistributions of source code must retain the above
0017  *        copyright notice, this list of conditions and the following
0018  *        disclaimer.
0019  *
0020  *      - Redistributions in binary form must reproduce the above
0021  *        copyright notice, this list of conditions and the following
0022  *        disclaimer in the documentation and/or other materials
0023  *        provided with the distribution.
0024  *
0025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0026  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0027  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0028  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0029  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0030  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0031  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0032  * SOFTWARE.
0033  */
0034 
0035 #ifndef _IPOIB_H
0036 #define _IPOIB_H
0037 
0038 #include <linux/list.h>
0039 #include <linux/skbuff.h>
0040 #include <linux/netdevice.h>
0041 #include <linux/workqueue.h>
0042 #include <linux/kref.h>
0043 #include <linux/if_infiniband.h>
0044 #include <linux/mutex.h>
0045 
0046 #include <net/neighbour.h>
0047 #include <net/sch_generic.h>
0048 
0049 #include <linux/atomic.h>
0050 
0051 #include <rdma/ib_verbs.h>
0052 #include <rdma/ib_pack.h>
0053 #include <rdma/ib_sa.h>
0054 #include <linux/sched.h>
0055 /* constants */
0056 
0057 enum ipoib_flush_level {
0058     IPOIB_FLUSH_LIGHT,
0059     IPOIB_FLUSH_NORMAL,
0060     IPOIB_FLUSH_HEAVY
0061 };
0062 
0063 enum {
0064     IPOIB_ENCAP_LEN       = 4,
0065     IPOIB_PSEUDO_LEN      = 20,
0066     IPOIB_HARD_LEN        = IPOIB_ENCAP_LEN + IPOIB_PSEUDO_LEN,
0067 
0068     IPOIB_UD_HEAD_SIZE    = IB_GRH_BYTES + IPOIB_ENCAP_LEN,
0069     IPOIB_UD_RX_SG        = 2, /* max buffer needed for 4K mtu */
0070 
0071     IPOIB_CM_MTU          = 0x10000 - 0x10, /* padding to align header to 16 */
0072     IPOIB_CM_BUF_SIZE     = IPOIB_CM_MTU  + IPOIB_ENCAP_LEN,
0073     IPOIB_CM_HEAD_SIZE    = IPOIB_CM_BUF_SIZE % PAGE_SIZE,
0074     IPOIB_CM_RX_SG        = ALIGN(IPOIB_CM_BUF_SIZE, PAGE_SIZE) / PAGE_SIZE,
0075     IPOIB_RX_RING_SIZE    = 256,
0076     IPOIB_TX_RING_SIZE    = 128,
0077     IPOIB_MAX_QUEUE_SIZE      = 8192,
0078     IPOIB_MIN_QUEUE_SIZE      = 2,
0079     IPOIB_CM_MAX_CONN_QP      = 4096,
0080 
0081     IPOIB_NUM_WC          = 4,
0082 
0083     IPOIB_MAX_PATH_REC_QUEUE  = 3,
0084     IPOIB_MAX_MCAST_QUEUE     = 64,
0085 
0086     IPOIB_FLAG_OPER_UP    = 0,
0087     IPOIB_FLAG_INITIALIZED    = 1,
0088     IPOIB_FLAG_ADMIN_UP   = 2,
0089     IPOIB_PKEY_ASSIGNED   = 3,
0090     IPOIB_FLAG_SUBINTERFACE   = 5,
0091     IPOIB_STOP_REAPER     = 7,
0092     IPOIB_FLAG_ADMIN_CM   = 9,
0093     IPOIB_FLAG_UMCAST     = 10,
0094     IPOIB_NEIGH_TBL_FLUSH     = 12,
0095     IPOIB_FLAG_DEV_ADDR_SET   = 13,
0096     IPOIB_FLAG_DEV_ADDR_CTRL  = 14,
0097 
0098     IPOIB_MAX_BACKOFF_SECONDS = 16,
0099 
0100     IPOIB_MCAST_FLAG_FOUND    = 0,  /* used in set_multicast_list */
0101     IPOIB_MCAST_FLAG_SENDONLY = 1,
0102     /*
0103      * For IPOIB_MCAST_FLAG_BUSY
0104      * When set, in flight join and mcast->mc is unreliable
0105      * When clear and mcast->mc IS_ERR_OR_NULL, need to restart or
0106      *   haven't started yet
0107      * When clear and mcast->mc is valid pointer, join was successful
0108      */
0109     IPOIB_MCAST_FLAG_BUSY     = 2,
0110     IPOIB_MCAST_FLAG_ATTACHED = 3,
0111 
0112     MAX_SEND_CQE          = 64,
0113     IPOIB_CM_COPYBREAK    = 256,
0114 
0115     IPOIB_NON_CHILD       = 0,
0116     IPOIB_LEGACY_CHILD    = 1,
0117     IPOIB_RTNL_CHILD      = 2,
0118 };
0119 
0120 #define IPOIB_OP_RECV   (1ul << 31)
0121 #ifdef CONFIG_INFINIBAND_IPOIB_CM
0122 #define IPOIB_OP_CM     (1ul << 30)
0123 #else
0124 #define IPOIB_OP_CM     (0)
0125 #endif
0126 
0127 #define IPOIB_QPN_MASK ((__force u32) cpu_to_be32(0xFFFFFF))
0128 
0129 /* structs */
0130 
0131 struct ipoib_header {
0132     __be16  proto;
0133     u16 reserved;
0134 };
0135 
0136 struct ipoib_pseudo_header {
0137     u8  hwaddr[INFINIBAND_ALEN];
0138 };
0139 
0140 static inline void skb_add_pseudo_hdr(struct sk_buff *skb)
0141 {
0142     char *data = skb_push(skb, IPOIB_PSEUDO_LEN);
0143 
0144     /*
0145      * only the ipoib header is present now, make room for a dummy
0146      * pseudo header and set skb field accordingly
0147      */
0148     memset(data, 0, IPOIB_PSEUDO_LEN);
0149     skb_reset_mac_header(skb);
0150     skb_pull(skb, IPOIB_HARD_LEN);
0151 }
0152 
0153 static inline struct ipoib_dev_priv *ipoib_priv(const struct net_device *dev)
0154 {
0155     struct rdma_netdev *rn = netdev_priv(dev);
0156 
0157     return rn->clnt_priv;
0158 }
0159 
0160 /* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
0161 struct ipoib_mcast {
0162     struct ib_sa_mcmember_rec mcmember;
0163     struct ib_sa_multicast   *mc;
0164     struct ipoib_ah      *ah;
0165 
0166     struct rb_node    rb_node;
0167     struct list_head  list;
0168 
0169     unsigned long created;
0170     unsigned long backoff;
0171     unsigned long delay_until;
0172 
0173     unsigned long flags;
0174     unsigned char logcount;
0175 
0176     struct list_head  neigh_list;
0177 
0178     struct sk_buff_head pkt_queue;
0179 
0180     struct net_device *dev;
0181     struct completion done;
0182 };
0183 
0184 struct ipoib_rx_buf {
0185     struct sk_buff *skb;
0186     u64     mapping[IPOIB_UD_RX_SG];
0187 };
0188 
0189 struct ipoib_tx_buf {
0190     struct sk_buff *skb;
0191     u64     mapping[MAX_SKB_FRAGS + 1];
0192 };
0193 
0194 struct ib_cm_id;
0195 
0196 struct ipoib_cm_data {
0197     __be32 qpn; /* High byte MUST be ignored on receive */
0198     __be32 mtu;
0199 };
0200 
0201 /*
0202  * Quoting 10.3.1 Queue Pair and EE Context States:
0203  *
0204  * Note, for QPs that are associated with an SRQ, the Consumer should take the
0205  * QP through the Error State before invoking a Destroy QP or a Modify QP to the
0206  * Reset State.  The Consumer may invoke the Destroy QP without first performing
0207  * a Modify QP to the Error State and waiting for the Affiliated Asynchronous
0208  * Last WQE Reached Event. However, if the Consumer does not wait for the
0209  * Affiliated Asynchronous Last WQE Reached Event, then WQE and Data Segment
0210  * leakage may occur. Therefore, it is good programming practice to tear down a
0211  * QP that is associated with an SRQ by using the following process:
0212  *
0213  * - Put the QP in the Error State
0214  * - Wait for the Affiliated Asynchronous Last WQE Reached Event;
0215  * - either:
0216  *       drain the CQ by invoking the Poll CQ verb and either wait for CQ
0217  *       to be empty or the number of Poll CQ operations has exceeded
0218  *       CQ capacity size;
0219  * - or
0220  *       post another WR that completes on the same CQ and wait for this
0221  *       WR to return as a WC;
0222  * - and then invoke a Destroy QP or Reset QP.
0223  *
0224  * We use the second option and wait for a completion on the
0225  * same CQ before destroying QPs attached to our SRQ.
0226  */
0227 
0228 enum ipoib_cm_state {
0229     IPOIB_CM_RX_LIVE,
0230     IPOIB_CM_RX_ERROR, /* Ignored by stale task */
0231     IPOIB_CM_RX_FLUSH  /* Last WQE Reached event observed */
0232 };
0233 
0234 struct ipoib_cm_rx {
0235     struct ib_cm_id        *id;
0236     struct ib_qp           *qp;
0237     struct ipoib_cm_rx_buf *rx_ring;
0238     struct list_head    list;
0239     struct net_device      *dev;
0240     unsigned long       jiffies;
0241     enum ipoib_cm_state state;
0242     int         recv_count;
0243 };
0244 
0245 struct ipoib_cm_tx {
0246     struct ib_cm_id     *id;
0247     struct ib_qp        *qp;
0248     struct list_head     list;
0249     struct net_device   *dev;
0250     struct ipoib_neigh  *neigh;
0251     struct ipoib_tx_buf *tx_ring;
0252     unsigned int         tx_head;
0253     unsigned int         tx_tail;
0254     unsigned long        flags;
0255     u32          mtu;
0256     unsigned int         max_send_sge;
0257 };
0258 
0259 struct ipoib_cm_rx_buf {
0260     struct sk_buff *skb;
0261     u64 mapping[IPOIB_CM_RX_SG];
0262 };
0263 
0264 struct ipoib_cm_dev_priv {
0265     struct ib_srq          *srq;
0266     struct ipoib_cm_rx_buf *srq_ring;
0267     struct ib_cm_id        *id;
0268     struct list_head    passive_ids;   /* state: LIVE */
0269     struct list_head    rx_error_list; /* state: ERROR */
0270     struct list_head    rx_flush_list; /* state: FLUSH, drain not started */
0271     struct list_head    rx_drain_list; /* state: FLUSH, drain started */
0272     struct list_head    rx_reap_list;  /* state: FLUSH, drain done */
0273     struct work_struct      start_task;
0274     struct work_struct      reap_task;
0275     struct work_struct      skb_task;
0276     struct work_struct      rx_reap_task;
0277     struct delayed_work     stale_task;
0278     struct sk_buff_head     skb_queue;
0279     struct list_head    start_list;
0280     struct list_head    reap_list;
0281     struct ib_wc        ibwc[IPOIB_NUM_WC];
0282     struct ib_sge       rx_sge[IPOIB_CM_RX_SG];
0283     struct ib_recv_wr       rx_wr;
0284     int         nonsrq_conn_qp;
0285     int         max_cm_mtu;
0286     int         num_frags;
0287 };
0288 
0289 struct ipoib_ethtool_st {
0290     u16     coalesce_usecs;
0291     u16     max_coalesced_frames;
0292 };
0293 
0294 struct ipoib_neigh_table;
0295 
0296 struct ipoib_neigh_hash {
0297     struct ipoib_neigh_table       *ntbl;
0298     struct ipoib_neigh __rcu      **buckets;
0299     struct rcu_head         rcu;
0300     u32             mask;
0301     u32             size;
0302 };
0303 
0304 struct ipoib_neigh_table {
0305     struct ipoib_neigh_hash __rcu  *htbl;
0306     atomic_t            entries;
0307     struct completion       flushed;
0308     struct completion       deleted;
0309 };
0310 
0311 struct ipoib_qp_state_validate {
0312     struct work_struct work;
0313     struct ipoib_dev_priv   *priv;
0314 };
0315 
0316 /*
0317  * Device private locking: network stack tx_lock protects members used
0318  * in TX fast path, lock protects everything else.  lock nests inside
0319  * of tx_lock (ie tx_lock must be acquired first if needed).
0320  */
0321 struct ipoib_dev_priv {
0322     spinlock_t lock;
0323 
0324     struct net_device *dev;
0325     void (*next_priv_destructor)(struct net_device *dev);
0326 
0327     struct napi_struct send_napi;
0328     struct napi_struct recv_napi;
0329 
0330     unsigned long flags;
0331 
0332     /*
0333      * This protects access to the child_intfs list.
0334      * To READ from child_intfs the RTNL or vlan_rwsem read side must be
0335      * held.  To WRITE RTNL and the vlan_rwsem write side must be held (in
0336      * that order) This lock exists because we have a few contexts where
0337      * we need the child_intfs, but do not want to grab the RTNL.
0338      */
0339     struct rw_semaphore vlan_rwsem;
0340     struct mutex mcast_mutex;
0341 
0342     struct rb_root  path_tree;
0343     struct list_head path_list;
0344 
0345     struct ipoib_neigh_table ntbl;
0346 
0347     struct ipoib_mcast *broadcast;
0348     struct list_head multicast_list;
0349     struct rb_root multicast_tree;
0350 
0351     struct workqueue_struct *wq;
0352     struct delayed_work mcast_task;
0353     struct work_struct carrier_on_task;
0354     struct work_struct flush_light;
0355     struct work_struct flush_normal;
0356     struct work_struct flush_heavy;
0357     struct work_struct restart_task;
0358     struct delayed_work ah_reap_task;
0359     struct delayed_work neigh_reap_task;
0360     struct ib_device *ca;
0361     u8        port;
0362     u16       pkey;
0363     u16       pkey_index;
0364     struct ib_pd     *pd;
0365     struct ib_cq     *recv_cq;
0366     struct ib_cq     *send_cq;
0367     struct ib_qp     *qp;
0368     u32       qkey;
0369 
0370     union ib_gid local_gid;
0371     u32      local_lid;
0372 
0373     unsigned int admin_mtu;
0374     unsigned int mcast_mtu;
0375     unsigned int max_ib_mtu;
0376 
0377     struct ipoib_rx_buf *rx_ring;
0378 
0379     struct ipoib_tx_buf *tx_ring;
0380     /* cyclic ring variables for managing tx_ring, for UD only */
0381     unsigned int         tx_head;
0382     unsigned int         tx_tail;
0383     /* cyclic ring variables for counting overall outstanding send WRs */
0384     unsigned int         global_tx_head;
0385     unsigned int         global_tx_tail;
0386     struct ib_sge        tx_sge[MAX_SKB_FRAGS + 1];
0387     struct ib_ud_wr      tx_wr;
0388     struct ib_wc         send_wc[MAX_SEND_CQE];
0389 
0390     struct ib_recv_wr    rx_wr;
0391     struct ib_sge        rx_sge[IPOIB_UD_RX_SG];
0392 
0393     struct ib_wc ibwc[IPOIB_NUM_WC];
0394 
0395     struct list_head dead_ahs;
0396 
0397     struct ib_event_handler event_handler;
0398 
0399     struct net_device *parent;
0400     struct list_head child_intfs;
0401     struct list_head list;
0402     int    child_type;
0403 
0404 #ifdef CONFIG_INFINIBAND_IPOIB_CM
0405     struct ipoib_cm_dev_priv cm;
0406 #endif
0407 
0408 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
0409     struct list_head fs_list;
0410     struct dentry *mcg_dentry;
0411     struct dentry *path_dentry;
0412 #endif
0413     u64 hca_caps;
0414     u64 kernel_caps;
0415     struct ipoib_ethtool_st ethtool;
0416     unsigned int max_send_sge;
0417     const struct net_device_ops *rn_ops;
0418 };
0419 
0420 struct ipoib_ah {
0421     struct net_device *dev;
0422     struct ib_ah      *ah;
0423     struct list_head   list;
0424     struct kref    ref;
0425     unsigned int       last_send;
0426     int            valid;
0427 };
0428 
0429 struct ipoib_path {
0430     struct net_device    *dev;
0431     struct sa_path_rec pathrec;
0432     struct ipoib_ah      *ah;
0433     struct sk_buff_head   queue;
0434 
0435     struct list_head      neigh_list;
0436 
0437     int           query_id;
0438     struct ib_sa_query   *query;
0439     struct completion     done;
0440 
0441     struct rb_node        rb_node;
0442     struct list_head      list;
0443 };
0444 
0445 struct ipoib_neigh {
0446     struct ipoib_ah    *ah;
0447 #ifdef CONFIG_INFINIBAND_IPOIB_CM
0448     struct ipoib_cm_tx *cm;
0449 #endif
0450     u8     daddr[INFINIBAND_ALEN];
0451     struct sk_buff_head queue;
0452 
0453     struct net_device *dev;
0454 
0455     struct list_head    list;
0456     struct ipoib_neigh __rcu *hnext;
0457     struct rcu_head     rcu;
0458     refcount_t      refcnt;
0459     unsigned long       alive;
0460 };
0461 
0462 #define IPOIB_UD_MTU(ib_mtu)        (ib_mtu - IPOIB_ENCAP_LEN)
0463 #define IPOIB_UD_BUF_SIZE(ib_mtu)   (ib_mtu + IB_GRH_BYTES)
0464 
0465 void ipoib_neigh_dtor(struct ipoib_neigh *neigh);
0466 static inline void ipoib_neigh_put(struct ipoib_neigh *neigh)
0467 {
0468     if (refcount_dec_and_test(&neigh->refcnt))
0469         ipoib_neigh_dtor(neigh);
0470 }
0471 struct ipoib_neigh *ipoib_neigh_get(struct net_device *dev, u8 *daddr);
0472 struct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr,
0473                       struct net_device *dev);
0474 void ipoib_neigh_free(struct ipoib_neigh *neigh);
0475 void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid);
0476 
0477 extern struct workqueue_struct *ipoib_workqueue;
0478 
0479 /* functions */
0480 
0481 int ipoib_rx_poll(struct napi_struct *napi, int budget);
0482 int ipoib_tx_poll(struct napi_struct *napi, int budget);
0483 void ipoib_ib_rx_completion(struct ib_cq *cq, void *ctx_ptr);
0484 void ipoib_ib_tx_completion(struct ib_cq *cq, void *ctx_ptr);
0485 
0486 struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
0487                  struct ib_pd *pd, struct rdma_ah_attr *attr);
0488 void ipoib_free_ah(struct kref *kref);
0489 static inline void ipoib_put_ah(struct ipoib_ah *ah)
0490 {
0491     kref_put(&ah->ref, ipoib_free_ah);
0492 }
0493 int ipoib_open(struct net_device *dev);
0494 void ipoib_intf_free(struct net_device *dev);
0495 int ipoib_add_pkey_attr(struct net_device *dev);
0496 int ipoib_add_umcast_attr(struct net_device *dev);
0497 
0498 int ipoib_send(struct net_device *dev, struct sk_buff *skb,
0499            struct ib_ah *address, u32 dqpn);
0500 void ipoib_reap_ah(struct work_struct *work);
0501 
0502 struct ipoib_path *__path_find(struct net_device *dev, void *gid);
0503 void ipoib_mark_paths_invalid(struct net_device *dev);
0504 void ipoib_flush_paths(struct net_device *dev);
0505 struct net_device *ipoib_intf_alloc(struct ib_device *hca, u32 port,
0506                     const char *format);
0507 int ipoib_intf_init(struct ib_device *hca, u32 port, const char *format,
0508             struct net_device *dev);
0509 void ipoib_ib_tx_timer_func(struct timer_list *t);
0510 void ipoib_ib_dev_flush_light(struct work_struct *work);
0511 void ipoib_ib_dev_flush_normal(struct work_struct *work);
0512 void ipoib_ib_dev_flush_heavy(struct work_struct *work);
0513 void ipoib_pkey_event(struct work_struct *work);
0514 void ipoib_ib_dev_cleanup(struct net_device *dev);
0515 
0516 int ipoib_ib_dev_open_default(struct net_device *dev);
0517 int ipoib_ib_dev_open(struct net_device *dev);
0518 void ipoib_ib_dev_stop(struct net_device *dev);
0519 void ipoib_ib_dev_up(struct net_device *dev);
0520 void ipoib_ib_dev_down(struct net_device *dev);
0521 int ipoib_ib_dev_stop_default(struct net_device *dev);
0522 void ipoib_pkey_dev_check_presence(struct net_device *dev);
0523 
0524 void ipoib_mcast_join_task(struct work_struct *work);
0525 void ipoib_mcast_carrier_on_task(struct work_struct *work);
0526 void ipoib_mcast_send(struct net_device *dev, u8 *daddr, struct sk_buff *skb);
0527 
0528 void ipoib_mcast_restart_task(struct work_struct *work);
0529 void ipoib_mcast_start_thread(struct net_device *dev);
0530 void ipoib_mcast_stop_thread(struct net_device *dev);
0531 
0532 void ipoib_mcast_dev_down(struct net_device *dev);
0533 void ipoib_mcast_dev_flush(struct net_device *dev);
0534 
0535 int ipoib_dma_map_tx(struct ib_device *ca, struct ipoib_tx_buf *tx_req);
0536 void ipoib_dma_unmap_tx(struct ipoib_dev_priv *priv,
0537             struct ipoib_tx_buf *tx_req);
0538 
0539 struct rtnl_link_ops *ipoib_get_link_ops(void);
0540 
0541 static inline void ipoib_build_sge(struct ipoib_dev_priv *priv,
0542                    struct ipoib_tx_buf *tx_req)
0543 {
0544     int i, off;
0545     struct sk_buff *skb = tx_req->skb;
0546     skb_frag_t *frags = skb_shinfo(skb)->frags;
0547     int nr_frags = skb_shinfo(skb)->nr_frags;
0548     u64 *mapping = tx_req->mapping;
0549 
0550     if (skb_headlen(skb)) {
0551         priv->tx_sge[0].addr         = mapping[0];
0552         priv->tx_sge[0].length       = skb_headlen(skb);
0553         off = 1;
0554     } else
0555         off = 0;
0556 
0557     for (i = 0; i < nr_frags; ++i) {
0558         priv->tx_sge[i + off].addr = mapping[i + off];
0559         priv->tx_sge[i + off].length = skb_frag_size(&frags[i]);
0560     }
0561     priv->tx_wr.wr.num_sge       = nr_frags + off;
0562 }
0563 
0564 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
0565 struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev);
0566 int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter);
0567 void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter,
0568                   union ib_gid *gid,
0569                   unsigned long *created,
0570                   unsigned int *queuelen,
0571                   unsigned int *complete,
0572                   unsigned int *send_only);
0573 
0574 struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev);
0575 int ipoib_path_iter_next(struct ipoib_path_iter *iter);
0576 void ipoib_path_iter_read(struct ipoib_path_iter *iter,
0577               struct ipoib_path *path);
0578 #endif
0579 
0580 int ipoib_mcast_attach(struct net_device *dev, struct ib_device *hca,
0581                union ib_gid *mgid, u16 mlid, int set_qkey, u32 qkey);
0582 int ipoib_mcast_detach(struct net_device *dev, struct ib_device *hca,
0583                union ib_gid *mgid, u16 mlid);
0584 void ipoib_mcast_remove_list(struct list_head *remove_list);
0585 void ipoib_check_and_add_mcast_sendonly(struct ipoib_dev_priv *priv, u8 *mgid,
0586                 struct list_head *remove_list);
0587 
0588 int ipoib_init_qp(struct net_device *dev);
0589 int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca);
0590 void ipoib_transport_dev_cleanup(struct net_device *dev);
0591 
0592 void ipoib_event(struct ib_event_handler *handler,
0593          struct ib_event *record);
0594 
0595 int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey);
0596 int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey);
0597 
0598 int __ipoib_vlan_add(struct ipoib_dev_priv *ppriv, struct ipoib_dev_priv *priv,
0599              u16 pkey, int child_type);
0600 
0601 int  __init ipoib_netlink_init(void);
0602 void __exit ipoib_netlink_fini(void);
0603 
0604 void ipoib_set_umcast(struct net_device *ndev, int umcast_val);
0605 int  ipoib_set_mode(struct net_device *dev, const char *buf);
0606 
0607 void ipoib_setup_common(struct net_device *dev);
0608 
0609 void ipoib_pkey_open(struct ipoib_dev_priv *priv);
0610 void ipoib_drain_cq(struct net_device *dev);
0611 
0612 void ipoib_set_ethtool_ops(struct net_device *dev);
0613 
0614 #define IPOIB_FLAGS_RC      0x80
0615 #define IPOIB_FLAGS_UC      0x40
0616 
0617 /* We don't support UC connections at the moment */
0618 #define IPOIB_CM_SUPPORTED(ha)   (ha[0] & (IPOIB_FLAGS_RC))
0619 
0620 #ifdef CONFIG_INFINIBAND_IPOIB_CM
0621 
0622 extern int ipoib_max_conn_qp;
0623 
0624 static inline int ipoib_cm_admin_enabled(struct net_device *dev)
0625 {
0626     struct ipoib_dev_priv *priv = ipoib_priv(dev);
0627     return IPOIB_CM_SUPPORTED(dev->dev_addr) &&
0628         test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
0629 }
0630 
0631 static inline int ipoib_cm_enabled(struct net_device *dev, u8 *hwaddr)
0632 {
0633     struct ipoib_dev_priv *priv = ipoib_priv(dev);
0634     return IPOIB_CM_SUPPORTED(hwaddr) &&
0635         test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
0636 }
0637 
0638 static inline int ipoib_cm_up(struct ipoib_neigh *neigh)
0639 
0640 {
0641     return test_bit(IPOIB_FLAG_OPER_UP, &neigh->cm->flags);
0642 }
0643 
0644 static inline struct ipoib_cm_tx *ipoib_cm_get(struct ipoib_neigh *neigh)
0645 {
0646     return neigh->cm;
0647 }
0648 
0649 static inline void ipoib_cm_set(struct ipoib_neigh *neigh, struct ipoib_cm_tx *tx)
0650 {
0651     neigh->cm = tx;
0652 }
0653 
0654 static inline int ipoib_cm_has_srq(struct net_device *dev)
0655 {
0656     struct ipoib_dev_priv *priv = ipoib_priv(dev);
0657     return !!priv->cm.srq;
0658 }
0659 
0660 static inline unsigned int ipoib_cm_max_mtu(struct net_device *dev)
0661 {
0662     struct ipoib_dev_priv *priv = ipoib_priv(dev);
0663     return priv->cm.max_cm_mtu;
0664 }
0665 
0666 void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_tx *tx);
0667 int ipoib_cm_dev_open(struct net_device *dev);
0668 void ipoib_cm_dev_stop(struct net_device *dev);
0669 int ipoib_cm_dev_init(struct net_device *dev);
0670 int ipoib_cm_add_mode_attr(struct net_device *dev);
0671 void ipoib_cm_dev_cleanup(struct net_device *dev);
0672 struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path,
0673                     struct ipoib_neigh *neigh);
0674 void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx);
0675 void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
0676                unsigned int mtu);
0677 void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc);
0678 void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc);
0679 #else
0680 
0681 #define ipoib_max_conn_qp 0
0682 
0683 static inline int ipoib_cm_admin_enabled(struct net_device *dev)
0684 {
0685     return 0;
0686 }
0687 static inline int ipoib_cm_enabled(struct net_device *dev, u8 *hwaddr)
0688 
0689 {
0690     return 0;
0691 }
0692 
0693 static inline int ipoib_cm_up(struct ipoib_neigh *neigh)
0694 
0695 {
0696     return 0;
0697 }
0698 
0699 static inline struct ipoib_cm_tx *ipoib_cm_get(struct ipoib_neigh *neigh)
0700 {
0701     return NULL;
0702 }
0703 
0704 static inline void ipoib_cm_set(struct ipoib_neigh *neigh, struct ipoib_cm_tx *tx)
0705 {
0706 }
0707 
0708 static inline int ipoib_cm_has_srq(struct net_device *dev)
0709 {
0710     return 0;
0711 }
0712 
0713 static inline unsigned int ipoib_cm_max_mtu(struct net_device *dev)
0714 {
0715     return 0;
0716 }
0717 
0718 static inline
0719 void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_tx *tx)
0720 {
0721     return;
0722 }
0723 
0724 static inline
0725 int ipoib_cm_dev_open(struct net_device *dev)
0726 {
0727     return 0;
0728 }
0729 
0730 static inline
0731 void ipoib_cm_dev_stop(struct net_device *dev)
0732 {
0733     return;
0734 }
0735 
0736 static inline
0737 int ipoib_cm_dev_init(struct net_device *dev)
0738 {
0739     return -EOPNOTSUPP;
0740 }
0741 
0742 static inline
0743 void ipoib_cm_dev_cleanup(struct net_device *dev)
0744 {
0745     return;
0746 }
0747 
0748 static inline
0749 struct ipoib_cm_tx *ipoib_cm_create_tx(struct net_device *dev, struct ipoib_path *path,
0750                     struct ipoib_neigh *neigh)
0751 {
0752     return NULL;
0753 }
0754 
0755 static inline
0756 void ipoib_cm_destroy_tx(struct ipoib_cm_tx *tx)
0757 {
0758     return;
0759 }
0760 
0761 static inline
0762 int ipoib_cm_add_mode_attr(struct net_device *dev)
0763 {
0764     return 0;
0765 }
0766 
0767 static inline void ipoib_cm_skb_too_long(struct net_device *dev, struct sk_buff *skb,
0768                      unsigned int mtu)
0769 {
0770     dev_kfree_skb_any(skb);
0771 }
0772 
0773 static inline void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
0774 {
0775 }
0776 
0777 static inline void ipoib_cm_handle_tx_wc(struct net_device *dev, struct ib_wc *wc)
0778 {
0779 }
0780 #endif
0781 
0782 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
0783 void ipoib_create_debug_files(struct net_device *dev);
0784 void ipoib_delete_debug_files(struct net_device *dev);
0785 void ipoib_register_debugfs(void);
0786 void ipoib_unregister_debugfs(void);
0787 #else
0788 static inline void ipoib_create_debug_files(struct net_device *dev) { }
0789 static inline void ipoib_delete_debug_files(struct net_device *dev) { }
0790 static inline void ipoib_register_debugfs(void) { }
0791 static inline void ipoib_unregister_debugfs(void) { }
0792 #endif
0793 
0794 #define ipoib_printk(level, priv, format, arg...)   \
0795     printk(level "%s: " format, ((struct ipoib_dev_priv *) priv)->dev->name , ## arg)
0796 #define ipoib_warn(priv, format, arg...)        \
0797 do {                            \
0798     static DEFINE_RATELIMIT_STATE(_rs,      \
0799         10 * HZ /*10 seconds */,        \
0800         100);       \
0801     if (__ratelimit(&_rs))              \
0802         ipoib_printk(KERN_WARNING, priv, format , ## arg);\
0803 } while (0)
0804 
0805 extern int ipoib_sendq_size;
0806 extern int ipoib_recvq_size;
0807 
0808 extern struct ib_sa_client ipoib_sa_client;
0809 
0810 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
0811 extern int ipoib_debug_level;
0812 
0813 #define ipoib_dbg(priv, format, arg...)         \
0814     do {                        \
0815         if (ipoib_debug_level > 0)          \
0816             ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
0817     } while (0)
0818 #define ipoib_dbg_mcast(priv, format, arg...)       \
0819     do {                        \
0820         if (mcast_debug_level > 0)      \
0821             ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
0822     } while (0)
0823 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG */
0824 #define ipoib_dbg(priv, format, arg...)         \
0825     do { (void) (priv); } while (0)
0826 #define ipoib_dbg_mcast(priv, format, arg...)       \
0827     do { (void) (priv); } while (0)
0828 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
0829 
0830 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
0831 #define ipoib_dbg_data(priv, format, arg...)        \
0832     do {                        \
0833         if (data_debug_level > 0)       \
0834             ipoib_printk(KERN_DEBUG, priv, format , ## arg); \
0835     } while (0)
0836 #else /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
0837 #define ipoib_dbg_data(priv, format, arg...)        \
0838     do { (void) (priv); } while (0)
0839 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG_DATA */
0840 
0841 #define IPOIB_QPN(ha) (be32_to_cpup((__be32 *) ha) & 0xffffff)
0842 
0843 #endif /* _IPOIB_H */