RDMA: Globally allocate and release QP memory
[linux-2.6-microblaze.git] / include / rdma / ib_verbs.h
index 7e2f369..6737582 100644 (file)
@@ -50,6 +50,8 @@ struct ib_uqp_object;
 struct ib_usrq_object;
 struct ib_uwq_object;
 struct rdma_cm_id;
+struct ib_port;
+struct hw_stats_device_data;
 
 extern struct workqueue_struct *ib_wq;
 extern struct workqueue_struct *ib_comp_wq;
@@ -2139,7 +2141,6 @@ struct ib_flow_action {
 };
 
 struct ib_mad;
-struct ib_grh;
 
 enum ib_process_mad_flags {
        IB_MAD_IGNORE_MKEY      = 1,
@@ -2175,15 +2176,17 @@ struct ib_port_data {
        struct ib_port_immutable immutable;
 
        spinlock_t pkey_list_lock;
+
+       spinlock_t netdev_lock;
+
        struct list_head pkey_list;
 
        struct ib_port_cache cache;
 
-       spinlock_t netdev_lock;
        struct net_device __rcu *netdev;
        struct hlist_node ndev_hash_link;
        struct rdma_port_counter port_counter;
-       struct rdma_hw_stats *hw_stats;
+       struct ib_port *sysfs;
 };
 
 /* rdma netdev type - specifies protocol type */
@@ -2265,8 +2268,13 @@ struct iw_cm_conn_param;
                         !__same_type(((struct drv_struct *)NULL)->member,     \
                                      struct ib_struct)))
 
-#define rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, gfp)                         \
-       ((struct ib_type *)kzalloc(ib_dev->ops.size_##ib_type, gfp))
+#define rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, gfp)                          \
+       ((struct ib_type *)rdma_zalloc_obj(ib_dev, ib_dev->ops.size_##ib_type, \
+                                          gfp, false))
+
+#define rdma_zalloc_drv_obj_numa(ib_dev, ib_type)                              \
+       ((struct ib_type *)rdma_zalloc_obj(ib_dev, ib_dev->ops.size_##ib_type, \
+                                          GFP_KERNEL, true))
 
 #define rdma_zalloc_drv_obj(ib_dev, ib_type)                                   \
        rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, GFP_KERNEL)
@@ -2299,6 +2307,14 @@ struct ib_device_ops {
        u32 uverbs_abi_ver;
        unsigned int uverbs_no_driver_id_binding:1;
 
+       /*
+        * NOTE: New drivers should not make use of device_group; instead new
+        * device parameter should be exposed via netlink command. This
+        * mechanism exists only for existing drivers.
+        */
+       const struct attribute_group *device_group;
+       const struct attribute_group **port_groups;
+
        int (*post_send)(struct ib_qp *qp, const struct ib_send_wr *send_wr,
                         const struct ib_send_wr **bad_send_wr);
        int (*post_recv)(struct ib_qp *qp, const struct ib_recv_wr *recv_wr,
@@ -2424,9 +2440,8 @@ struct ib_device_ops {
                          struct ib_udata *udata);
        int (*query_srq)(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
        int (*destroy_srq)(struct ib_srq *srq, struct ib_udata *udata);
-       struct ib_qp *(*create_qp)(struct ib_pd *pd,
-                                  struct ib_qp_init_attr *qp_init_attr,
-                                  struct ib_udata *udata);
+       int (*create_qp)(struct ib_qp *qp, struct ib_qp_init_attr *qp_init_attr,
+                        struct ib_udata *udata);
        int (*modify_qp)(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
                         int qp_attr_mask, struct ib_udata *udata);
        int (*query_qp)(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
@@ -2459,6 +2474,14 @@ struct ib_device_ops {
                         enum ib_uverbs_advise_mr_advice advice, u32 flags,
                         struct ib_sge *sg_list, u32 num_sge,
                         struct uverbs_attr_bundle *attrs);
+
+       /*
+        * Kernel users should universally support relaxed ordering (RO), as
+        * they are designed to read data only after observing the CQE and use
+        * the DMA API correctly.
+        *
+        * Some drivers implicitly enable RO if platform supports it.
+        */
        int (*map_mr_sg)(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
                         unsigned int *sg_offset);
        int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
@@ -2523,13 +2546,14 @@ struct ib_device_ops {
                            unsigned int *meta_sg_offset);
 
        /**
-        * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
-        *   driver initialized data.  The struct is kfree()'ed by the sysfs
-        *   core when the device is removed.  A lifespan of -1 in the return
-        *   struct tells the core to set a default lifespan.
+        * alloc_hw_[device,port]_stats - Allocate a struct rdma_hw_stats and
+        *   fill in the driver initialized data.  The struct is kfree()'ed by
+        *   the sysfs core when the device is removed.  A lifespan of -1 in the
+        *   return struct tells the core to set a default lifespan.
         */
-       struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device,
-                                               u32 port_num);
+       struct rdma_hw_stats *(*alloc_hw_device_stats)(struct ib_device *device);
+       struct rdma_hw_stats *(*alloc_hw_port_stats)(struct ib_device *device,
+                                                    u32 port_num);
        /**
         * get_hw_stats - Fill in the counter value(s) in the stats struct.
         * @index - The index in the value array we wish to have updated, or
@@ -2544,12 +2568,7 @@ struct ib_device_ops {
         */
        int (*get_hw_stats)(struct ib_device *device,
                            struct rdma_hw_stats *stats, u32 port, int index);
-       /*
-        * This function is called once for each port when a ib device is
-        * registered.
-        */
-       int (*init_port)(struct ib_device *device, u32 port_num,
-                        struct kobject *port_sysfs);
+
        /**
         * Allows rdma drivers to add their own restrack attributes.
         */
@@ -2620,11 +2639,18 @@ struct ib_device_ops {
        int (*query_ucontext)(struct ib_ucontext *context,
                              struct uverbs_attr_bundle *attrs);
 
+       /*
+        * Provide NUMA node. This API exists for rdmavt/hfi1 only.
+        * Everyone else relies on Linux memory management model.
+        */
+       int (*get_numa_node)(struct ib_device *dev);
+
        DECLARE_RDMA_OBJ_SIZE(ib_ah);
        DECLARE_RDMA_OBJ_SIZE(ib_counters);
        DECLARE_RDMA_OBJ_SIZE(ib_cq);
        DECLARE_RDMA_OBJ_SIZE(ib_mw);
        DECLARE_RDMA_OBJ_SIZE(ib_pd);
+       DECLARE_RDMA_OBJ_SIZE(ib_qp);
        DECLARE_RDMA_OBJ_SIZE(ib_rwq_ind_table);
        DECLARE_RDMA_OBJ_SIZE(ib_srq);
        DECLARE_RDMA_OBJ_SIZE(ib_ucontext);
@@ -2675,11 +2701,12 @@ struct ib_device {
                struct ib_core_device   coredev;
        };
 
-       /* First group for device attributes,
-        * Second group for driver provided attributes (optional).
-        * It is NULL terminated array.
+       /* First group is for device attributes,
+        * Second group is for driver provided attributes (optional).
+        * Third group is for the hw_stats
+        * It is a NULL terminated array.
         */
-       const struct attribute_group    *groups[3];
+       const struct attribute_group    *groups[4];
 
        u64                          uverbs_cmd_mask;
 
@@ -2694,8 +2721,7 @@ struct ib_device {
        u8                           node_type;
        u32                          phys_port_cnt;
        struct ib_device_attr        attrs;
-       struct attribute_group       *hw_stats_ag;
-       struct rdma_hw_stats         *hw_stats;
+       struct hw_stats_device_data *hw_stats_data;
 
 #ifdef CONFIG_CGROUP_RDMA
        struct rdmacg_device         cg_device;
@@ -2731,6 +2757,15 @@ struct ib_device {
        u32 lag_flags;
 };
 
+static inline void *rdma_zalloc_obj(struct ib_device *dev, size_t size,
+                                   gfp_t gfp, bool is_numa_aware)
+{
+       if (is_numa_aware && dev->ops.get_numa_node)
+               return kzalloc_node(size, gfp, dev->ops.get_numa_node(dev));
+
+       return kzalloc(size, gfp);
+}
+
 struct ib_client_nl_info;
 struct ib_client {
        const char *name;
@@ -4286,8 +4321,6 @@ struct net_device *ib_device_netdev(struct ib_device *dev, u32 port);
 struct ib_wq *ib_create_wq(struct ib_pd *pd,
                           struct ib_wq_init_attr *init_attr);
 int ib_destroy_wq_user(struct ib_wq *wq, struct ib_udata *udata);
-int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr,
-                u32 wq_attr_mask);
 
 int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
                 unsigned int *sg_offset, unsigned int page_size);
@@ -4570,28 +4603,6 @@ int rdma_init_netdev(struct ib_device *device, u32 port_num,
                     void (*setup)(struct net_device *),
                     struct net_device *netdev);
 
-/**
- * rdma_set_device_sysfs_group - Set device attributes group to have
- *                              driver specific sysfs entries at
- *                              for infiniband class.
- *
- * @device:    device pointer for which attributes to be created
- * @group:     Pointer to group which should be added when device
- *             is registered with sysfs.
- * rdma_set_device_sysfs_group() allows existing drivers to expose one
- * group per device to have sysfs attributes.
- *
- * NOTE: New drivers should not make use of this API; instead new device
- * parameter should be exposed via netlink command. This API and mechanism
- * exist only for existing drivers.
- */
-static inline void
-rdma_set_device_sysfs_group(struct ib_device *dev,
-                           const struct attribute_group *group)
-{
-       dev->groups[1] = group;
-}
-
 /**
  * rdma_device_to_ibdev - Get ib_device pointer from device pointer
  *
@@ -4627,7 +4638,7 @@ static inline int ibdev_to_node(struct ib_device *ibdev)
  *
  * NOTE: New drivers should not make use of this API; This API is only for
  * existing drivers who have exposed sysfs entries using
- * rdma_set_device_sysfs_group().
+ * ops->device_group.
  */
 #define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member)           \
        container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member)