Commit 8fdd4019 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull rdma updates from Jason Gunthorpe:
 "A very quiet cycle with few notable changes. Mostly the usual list of
  one or two patches to drivers changing something that isn't quite rc
  worthy. The subsystem seems to be seeing a larger number of rework and
  cleanup style patches right now, I feel that several vendors are
  prepping their drivers for new silicon.

  Summary:

   - Driver updates and cleanup for qedr, bnxt_re, hns, siw, mlx5, mlx4,
     rxe, i40iw

   - Larger series doing cleanup and rework for hns and hfi1.

   - Some general reworking of the CM code to make it a little more
     understandable

   - Unify the different code paths connected to the uverbs FD scheme

   - New UAPI ioctls conversions for get context and get async fd

   - Trace points for CQ and CM portions of the RDMA stack

   - mlx5 driver support for virtio-net formatted rings as RDMA raw
     ethernet QPs

   - verbs support for setting the PCI-E relaxed ordering bit on DMA
     traffic connected to a MR

   - A couple of bug fixes that came too late to make rc7"

* tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma: (108 commits)
  RDMA/core: Make the entire API tree static
  RDMA/efa: Mask access flags with the correct optional range
  RDMA/cma: Fix unbalanced cm_id reference count during address resolve
  RDMA/umem: Fix ib_umem_find_best_pgsz()
  IB/mlx4: Fix leak in id_map_find_del
  IB/opa_vnic: Spelling correction of 'erorr' to 'error'
  IB/hfi1: Fix logical condition in msix_request_irq
  RDMA/cm: Remove CM message structs
  RDMA/cm: Use IBA functions for complex structure members
  RDMA/cm: Use IBA functions for simple structure members
  RDMA/cm: Use IBA functions for swapping get/set acessors
  RDMA/cm: Use IBA functions for simple get/set acessors
  RDMA/cm: Add SET/GET implementations to hide IBA wire format
  RDMA/cm: Add accessors for CM_REQ transport_type
  IB/mlx5: Return the administrative GUID if exists
  RDMA/core: Ensure that rdma_user_mmap_entry_remove() is a fence
  IB/mlx4: Fix memory leak in add_gid error flow
  IB/mlx5: Expose RoCE accelerator counters
  RDMA/mlx5: Set relaxed ordering when requested
  RDMA/core: Add the core support field to METHOD_GET_CONTEXT
  ...
parents 68b62e5d 8889f6fa
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -11,7 +11,8 @@ ib_core-y := packer.o ud_header.o verbs.o cq.o rw.o sysfs.o \
				device.o fmr_pool.o cache.o netlink.o \
				roce_gid_mgmt.o mr_pool.o addr.o sa_query.o \
				multicast.o mad.o smi.o agent.o mad_rmpp.o \
				nldev.o restrack.o counters.o ib_core_uverbs.o
				nldev.o restrack.o counters.o ib_core_uverbs.o \
				trace.o

ib_core-$(CONFIG_SECURITY_INFINIBAND) += security.o
ib_core-$(CONFIG_CGROUP_RDMA) += cgroup.o
@@ -20,7 +21,8 @@ ib_cm-y := cm.o

iw_cm-y :=			iwcm.o iwpm_util.o iwpm_msg.o

rdma_cm-y :=			cma.o
CFLAGS_cma_trace.o +=		-I$(src)
rdma_cm-y :=			cma.o cma_trace.o

rdma_cm-$(CONFIG_INFINIBAND_ADDR_TRANS_CONFIGFS) += cma_configfs.o

@@ -33,6 +35,7 @@ ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_marshall.o \
				uverbs_std_types_cq.o \
				uverbs_std_types_flow_action.o uverbs_std_types_dm.o \
				uverbs_std_types_mr.o uverbs_std_types_counters.o \
				uverbs_uapi.o uverbs_std_types_device.o
				uverbs_uapi.o uverbs_std_types_device.o \
				uverbs_std_types_async_fd.o
ib_uverbs-$(CONFIG_INFINIBAND_USER_MEM) += umem.o
ib_uverbs-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += umem_odp.o
+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ int ib_nl_handle_ip_res_resp(struct sk_buff *skb,
	if (ib_nl_is_good_ip_resp(nlh))
		ib_nl_process_good_ip_rsep(nlh);

	return skb->len;
	return 0;
}

static int ib_nl_ip_send_msg(struct rdma_dev_addr *dev_addr,
+90 −61
Original line number Diff line number Diff line
@@ -51,8 +51,7 @@ struct ib_pkey_cache {

struct ib_update_work {
	struct work_struct work;
	struct ib_device  *device;
	u8                 port_num;
	struct ib_event event;
	bool enforce_security;
};

@@ -130,7 +129,7 @@ static void dispatch_gid_change_event(struct ib_device *ib_dev, u8 port)
	event.element.port_num	= port;
	event.event		= IB_EVENT_GID_CHANGE;

	ib_dispatch_event(&event);
	ib_dispatch_event_clients(&event);
}

static const char * const gid_type_str[] = {
@@ -1034,7 +1033,7 @@ int ib_get_cached_pkey(struct ib_device *device,
	if (!rdma_is_port_valid(device, port_num))
		return -EINVAL;

	read_lock_irqsave(&device->cache.lock, flags);
	read_lock_irqsave(&device->cache_lock, flags);

	cache = device->port_data[port_num].cache.pkey;

@@ -1043,7 +1042,7 @@ int ib_get_cached_pkey(struct ib_device *device,
	else
		*pkey = cache->table[index];

	read_unlock_irqrestore(&device->cache.lock, flags);
	read_unlock_irqrestore(&device->cache_lock, flags);

	return ret;
}
@@ -1058,9 +1057,9 @@ int ib_get_cached_subnet_prefix(struct ib_device *device,
	if (!rdma_is_port_valid(device, port_num))
		return -EINVAL;

	read_lock_irqsave(&device->cache.lock, flags);
	read_lock_irqsave(&device->cache_lock, flags);
	*sn_pfx = device->port_data[port_num].cache.subnet_prefix;
	read_unlock_irqrestore(&device->cache.lock, flags);
	read_unlock_irqrestore(&device->cache_lock, flags);

	return 0;
}
@@ -1080,7 +1079,7 @@ int ib_find_cached_pkey(struct ib_device *device,
	if (!rdma_is_port_valid(device, port_num))
		return -EINVAL;

	read_lock_irqsave(&device->cache.lock, flags);
	read_lock_irqsave(&device->cache_lock, flags);

	cache = device->port_data[port_num].cache.pkey;

@@ -1101,7 +1100,7 @@ int ib_find_cached_pkey(struct ib_device *device,
		ret = 0;
	}

	read_unlock_irqrestore(&device->cache.lock, flags);
	read_unlock_irqrestore(&device->cache_lock, flags);

	return ret;
}
@@ -1120,7 +1119,7 @@ int ib_find_exact_cached_pkey(struct ib_device *device,
	if (!rdma_is_port_valid(device, port_num))
		return -EINVAL;

	read_lock_irqsave(&device->cache.lock, flags);
	read_lock_irqsave(&device->cache_lock, flags);

	cache = device->port_data[port_num].cache.pkey;

@@ -1133,7 +1132,7 @@ int ib_find_exact_cached_pkey(struct ib_device *device,
			break;
		}

	read_unlock_irqrestore(&device->cache.lock, flags);
	read_unlock_irqrestore(&device->cache_lock, flags);

	return ret;
}
@@ -1149,9 +1148,9 @@ int ib_get_cached_lmc(struct ib_device *device,
	if (!rdma_is_port_valid(device, port_num))
		return -EINVAL;

	read_lock_irqsave(&device->cache.lock, flags);
	read_lock_irqsave(&device->cache_lock, flags);
	*lmc = device->port_data[port_num].cache.lmc;
	read_unlock_irqrestore(&device->cache.lock, flags);
	read_unlock_irqrestore(&device->cache_lock, flags);

	return ret;
}
@@ -1167,9 +1166,9 @@ int ib_get_cached_port_state(struct ib_device *device,
	if (!rdma_is_port_valid(device, port_num))
		return -EINVAL;

	read_lock_irqsave(&device->cache.lock, flags);
	read_lock_irqsave(&device->cache_lock, flags);
	*port_state = device->port_data[port_num].cache.port_state;
	read_unlock_irqrestore(&device->cache.lock, flags);
	read_unlock_irqrestore(&device->cache_lock, flags);

	return ret;
}
@@ -1381,9 +1380,8 @@ static int config_non_roce_gid_cache(struct ib_device *device,
	return ret;
}

static void ib_cache_update(struct ib_device *device,
			    u8                port,
			    bool	      enforce_security)
static int
ib_cache_update(struct ib_device *device, u8 port, bool enforce_security)
{
	struct ib_port_attr       *tprops = NULL;
	struct ib_pkey_cache      *pkey_cache = NULL, *old_pkey_cache;
@@ -1391,11 +1389,11 @@ static void ib_cache_update(struct ib_device *device,
	int                        ret;

	if (!rdma_is_port_valid(device, port))
		return;
		return -EINVAL;

	tprops = kmalloc(sizeof *tprops, GFP_KERNEL);
	if (!tprops)
		return;
		return -ENOMEM;

	ret = ib_query_port(device, port, tprops);
	if (ret) {
@@ -1413,8 +1411,10 @@ static void ib_cache_update(struct ib_device *device,
	pkey_cache = kmalloc(struct_size(pkey_cache, table,
					 tprops->pkey_tbl_len),
			     GFP_KERNEL);
	if (!pkey_cache)
	if (!pkey_cache) {
		ret = -ENOMEM;
		goto err;
	}

	pkey_cache->table_len = tprops->pkey_tbl_len;

@@ -1428,7 +1428,7 @@ static void ib_cache_update(struct ib_device *device,
		}
	}

	write_lock_irq(&device->cache.lock);
	write_lock_irq(&device->cache_lock);

	old_pkey_cache = device->port_data[port].cache.pkey;

@@ -1437,7 +1437,7 @@ static void ib_cache_update(struct ib_device *device,
	device->port_data[port].cache.port_state = tprops->state;

	device->port_data[port].cache.subnet_prefix = tprops->subnet_prefix;
	write_unlock_irq(&device->cache.lock);
	write_unlock_irq(&device->cache_lock);

	if (enforce_security)
		ib_security_cache_change(device,
@@ -1446,57 +1446,91 @@ static void ib_cache_update(struct ib_device *device,

	kfree(old_pkey_cache);
	kfree(tprops);
	return;
	return 0;

err:
	kfree(pkey_cache);
	kfree(tprops);
	return ret;
}

static void ib_cache_task(struct work_struct *_work)
static void ib_cache_event_task(struct work_struct *_work)
{
	struct ib_update_work *work =
		container_of(_work, struct ib_update_work, work);
	int ret;

	ib_cache_update(work->device,
			work->port_num,
	/* Before distributing the cache update event, first sync
	 * the cache.
	 */
	ret = ib_cache_update(work->event.device, work->event.element.port_num,
			      work->enforce_security);

	/* GID event is notified already for individual GID entries by
	 * dispatch_gid_change_event(). Hence, notifiy for rest of the
	 * events.
	 */
	if (!ret && work->event.event != IB_EVENT_GID_CHANGE)
		ib_dispatch_event_clients(&work->event);

	kfree(work);
}

static void ib_cache_event(struct ib_event_handler *handler,
			   struct ib_event *event)
static void ib_generic_event_task(struct work_struct *_work)
{
	struct ib_update_work *work;
	struct ib_update_work *work =
		container_of(_work, struct ib_update_work, work);

	if (event->event == IB_EVENT_PORT_ERR    ||
	ib_dispatch_event_clients(&work->event);
	kfree(work);
}

static bool is_cache_update_event(const struct ib_event *event)
{
	return (event->event == IB_EVENT_PORT_ERR    ||
		event->event == IB_EVENT_PORT_ACTIVE ||
		event->event == IB_EVENT_LID_CHANGE  ||
		event->event == IB_EVENT_PKEY_CHANGE ||
		event->event == IB_EVENT_CLIENT_REREGISTER ||
	    event->event == IB_EVENT_GID_CHANGE) {
		work = kmalloc(sizeof *work, GFP_ATOMIC);
		if (work) {
			INIT_WORK(&work->work, ib_cache_task);
			work->device   = event->device;
			work->port_num = event->element.port_num;
		event->event == IB_EVENT_GID_CHANGE);
}

/**
 * ib_dispatch_event - Dispatch an asynchronous event
 * @event:Event to dispatch
 *
 * Low-level drivers must call ib_dispatch_event() to dispatch the
 * event to all registered event handlers when an asynchronous event
 * occurs.
 */
void ib_dispatch_event(const struct ib_event *event)
{
	struct ib_update_work *work;

	work = kzalloc(sizeof(*work), GFP_ATOMIC);
	if (!work)
		return;

	if (is_cache_update_event(event))
		INIT_WORK(&work->work, ib_cache_event_task);
	else
		INIT_WORK(&work->work, ib_generic_event_task);

	work->event = *event;
	if (event->event == IB_EVENT_PKEY_CHANGE ||
	    event->event == IB_EVENT_GID_CHANGE)
		work->enforce_security = true;
			else
				work->enforce_security = false;

	queue_work(ib_wq, &work->work);
}
	}
}
EXPORT_SYMBOL(ib_dispatch_event);

int ib_cache_setup_one(struct ib_device *device)
{
	unsigned int p;
	int err;

	rwlock_init(&device->cache.lock);
	rwlock_init(&device->cache_lock);

	err = gid_table_setup_one(device);
	if (err)
@@ -1505,9 +1539,6 @@ int ib_cache_setup_one(struct ib_device *device)
	rdma_for_each_port (device, p)
		ib_cache_update(device, p, true);

	INIT_IB_EVENT_HANDLER(&device->cache.event_handler,
			      device, ib_cache_event);
	ib_register_event_handler(&device->cache.event_handler);
	return 0;
}

@@ -1529,14 +1560,12 @@ void ib_cache_release_one(struct ib_device *device)

void ib_cache_cleanup_one(struct ib_device *device)
{
	/* The cleanup function unregisters the event handler,
	 * waits for all in-progress workqueue elements and cleans
	 * up the GID cache. This function should be called after
	 * the device was removed from the devices list and all
	 * clients were removed, so the cache exists but is
	/* The cleanup function waits for all in-progress workqueue
	 * elements and cleans up the GID cache. This function should be
	 * called after the device was removed from the devices list and
	 * all clients were removed, so the cache exists but is
	 * non-functional and shouldn't be updated anymore.
	 */
	ib_unregister_event_handler(&device->cache.event_handler);
	flush_workqueue(ib_wq);
	gid_table_cleanup_one(device);

+496 −504

File changed.

Preview size limit exceeded, changes collapsed.

+10 −745
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
#ifndef CM_MSGS_H
#define CM_MSGS_H

#include <rdma/ibta_vol1_c12.h>
#include <rdma/ib_mad.h>
#include <rdma/ib_cm.h>

@@ -18,120 +19,14 @@

#define IB_CM_CLASS_VERSION	2 /* IB specification 1.2 */

struct cm_req_msg {
	struct ib_mad_hdr hdr;

	__be32 local_comm_id;
	__be32 rsvd4;
	__be64 service_id;
	__be64 local_ca_guid;
	__be32 rsvd24;
	__be32 local_qkey;
	/* local QPN:24, responder resources:8 */
	__be32 offset32;
	/* local EECN:24, initiator depth:8 */
	__be32 offset36;
	/*
	 * remote EECN:24, remote CM response timeout:5,
	 * transport service type:2, end-to-end flow control:1
	 */
	__be32 offset40;
	/* starting PSN:24, local CM response timeout:5, retry count:3 */
	__be32 offset44;
	__be16 pkey;
	/* path MTU:4, RDC exists:1, RNR retry count:3. */
	u8 offset50;
	/* max CM Retries:4, SRQ:1, extended transport type:3 */
	u8 offset51;

	__be16 primary_local_lid;
	__be16 primary_remote_lid;
	union ib_gid primary_local_gid;
	union ib_gid primary_remote_gid;
	/* flow label:20, rsvd:6, packet rate:6 */
	__be32 primary_offset88;
	u8 primary_traffic_class;
	u8 primary_hop_limit;
	/* SL:4, subnet local:1, rsvd:3 */
	u8 primary_offset94;
	/* local ACK timeout:5, rsvd:3 */
	u8 primary_offset95;

	__be16 alt_local_lid;
	__be16 alt_remote_lid;
	union ib_gid alt_local_gid;
	union ib_gid alt_remote_gid;
	/* flow label:20, rsvd:6, packet rate:6 */
	__be32 alt_offset132;
	u8 alt_traffic_class;
	u8 alt_hop_limit;
	/* SL:4, subnet local:1, rsvd:3 */
	u8 alt_offset138;
	/* local ACK timeout:5, rsvd:3 */
	u8 alt_offset139;

	u32 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE / sizeof(u32)];

} __packed;

static inline __be32 cm_req_get_local_qpn(struct cm_req_msg *req_msg)
{
	return cpu_to_be32(be32_to_cpu(req_msg->offset32) >> 8);
}

static inline void cm_req_set_local_qpn(struct cm_req_msg *req_msg, __be32 qpn)
{
	req_msg->offset32 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
					 (be32_to_cpu(req_msg->offset32) &
					  0x000000FF));
}

static inline u8 cm_req_get_resp_res(struct cm_req_msg *req_msg)
{
	return (u8) be32_to_cpu(req_msg->offset32);
}

static inline void cm_req_set_resp_res(struct cm_req_msg *req_msg, u8 resp_res)
{
	req_msg->offset32 = cpu_to_be32(resp_res |
					(be32_to_cpu(req_msg->offset32) &
					 0xFFFFFF00));
}

static inline u8 cm_req_get_init_depth(struct cm_req_msg *req_msg)
{
	return (u8) be32_to_cpu(req_msg->offset36);
}

static inline void cm_req_set_init_depth(struct cm_req_msg *req_msg,
					 u8 init_depth)
{
	req_msg->offset36 = cpu_to_be32(init_depth |
					(be32_to_cpu(req_msg->offset36) &
					 0xFFFFFF00));
}

static inline u8 cm_req_get_remote_resp_timeout(struct cm_req_msg *req_msg)
{
	return (u8) ((be32_to_cpu(req_msg->offset40) & 0xF8) >> 3);
}

static inline void cm_req_set_remote_resp_timeout(struct cm_req_msg *req_msg,
						  u8 resp_timeout)
{
	req_msg->offset40 = cpu_to_be32((resp_timeout << 3) |
					 (be32_to_cpu(req_msg->offset40) &
					  0xFFFFFF07));
}

static inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg)
{
	u8 transport_type = (u8) (be32_to_cpu(req_msg->offset40) & 0x06) >> 1;
	u8 transport_type = IBA_GET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg);
	switch(transport_type) {
	case 0: return IB_QPT_RC;
	case 1: return IB_QPT_UC;
	case 3:
		switch (req_msg->offset51 & 0x7) {
		switch (IBA_GET(CM_REQ_EXTENDED_TRANSPORT_TYPE, req_msg)) {
		case 1: return IB_QPT_XRC_TGT;
		default: return 0;
		}
@@ -144,238 +39,15 @@ static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
{
	switch(qp_type) {
	case IB_QPT_UC:
		req_msg->offset40 = cpu_to_be32((be32_to_cpu(
						  req_msg->offset40) &
						   0xFFFFFFF9) | 0x2);
		IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 1);
		break;
	case IB_QPT_XRC_INI:
		req_msg->offset40 = cpu_to_be32((be32_to_cpu(
						 req_msg->offset40) &
						   0xFFFFFFF9) | 0x6);
		req_msg->offset51 = (req_msg->offset51 & 0xF8) | 1;
		IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 3);
		IBA_SET(CM_REQ_EXTENDED_TRANSPORT_TYPE, req_msg, 1);
		break;
	default:
		req_msg->offset40 = cpu_to_be32(be32_to_cpu(
						 req_msg->offset40) &
						  0xFFFFFFF9);
	}
}

static inline u8 cm_req_get_flow_ctrl(struct cm_req_msg *req_msg)
{
	return be32_to_cpu(req_msg->offset40) & 0x1;
}

static inline void cm_req_set_flow_ctrl(struct cm_req_msg *req_msg,
					u8 flow_ctrl)
{
	req_msg->offset40 = cpu_to_be32((flow_ctrl & 0x1) |
					 (be32_to_cpu(req_msg->offset40) &
					  0xFFFFFFFE));
		IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 0);
	}

static inline __be32 cm_req_get_starting_psn(struct cm_req_msg *req_msg)
{
	return cpu_to_be32(be32_to_cpu(req_msg->offset44) >> 8);
}

static inline void cm_req_set_starting_psn(struct cm_req_msg *req_msg,
					   __be32 starting_psn)
{
	req_msg->offset44 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) |
			    (be32_to_cpu(req_msg->offset44) & 0x000000FF));
}

static inline u8 cm_req_get_local_resp_timeout(struct cm_req_msg *req_msg)
{
	return (u8) ((be32_to_cpu(req_msg->offset44) & 0xF8) >> 3);
}

static inline void cm_req_set_local_resp_timeout(struct cm_req_msg *req_msg,
						 u8 resp_timeout)
{
	req_msg->offset44 = cpu_to_be32((resp_timeout << 3) |
			    (be32_to_cpu(req_msg->offset44) & 0xFFFFFF07));
}

static inline u8 cm_req_get_retry_count(struct cm_req_msg *req_msg)
{
	return (u8) (be32_to_cpu(req_msg->offset44) & 0x7);
}

static inline void cm_req_set_retry_count(struct cm_req_msg *req_msg,
					  u8 retry_count)
{
	req_msg->offset44 = cpu_to_be32((retry_count & 0x7) |
			    (be32_to_cpu(req_msg->offset44) & 0xFFFFFFF8));
}

static inline u8 cm_req_get_path_mtu(struct cm_req_msg *req_msg)
{
	return req_msg->offset50 >> 4;
}

static inline void cm_req_set_path_mtu(struct cm_req_msg *req_msg, u8 path_mtu)
{
	req_msg->offset50 = (u8) ((req_msg->offset50 & 0xF) | (path_mtu << 4));
}

static inline u8 cm_req_get_rnr_retry_count(struct cm_req_msg *req_msg)
{
	return req_msg->offset50 & 0x7;
}

static inline void cm_req_set_rnr_retry_count(struct cm_req_msg *req_msg,
					      u8 rnr_retry_count)
{
	req_msg->offset50 = (u8) ((req_msg->offset50 & 0xF8) |
				  (rnr_retry_count & 0x7));
}

static inline u8 cm_req_get_max_cm_retries(struct cm_req_msg *req_msg)
{
	return req_msg->offset51 >> 4;
}

static inline void cm_req_set_max_cm_retries(struct cm_req_msg *req_msg,
					     u8 retries)
{
	req_msg->offset51 = (u8) ((req_msg->offset51 & 0xF) | (retries << 4));
}

static inline u8 cm_req_get_srq(struct cm_req_msg *req_msg)
{
	return (req_msg->offset51 & 0x8) >> 3;
}

static inline void cm_req_set_srq(struct cm_req_msg *req_msg, u8 srq)
{
	req_msg->offset51 = (u8) ((req_msg->offset51 & 0xF7) |
				  ((srq & 0x1) << 3));
}

static inline __be32 cm_req_get_primary_flow_label(struct cm_req_msg *req_msg)
{
	return cpu_to_be32(be32_to_cpu(req_msg->primary_offset88) >> 12);
}

static inline void cm_req_set_primary_flow_label(struct cm_req_msg *req_msg,
						 __be32 flow_label)
{
	req_msg->primary_offset88 = cpu_to_be32(
				    (be32_to_cpu(req_msg->primary_offset88) &
				     0x00000FFF) |
				     (be32_to_cpu(flow_label) << 12));
}

static inline u8 cm_req_get_primary_packet_rate(struct cm_req_msg *req_msg)
{
	return (u8) (be32_to_cpu(req_msg->primary_offset88) & 0x3F);
}

static inline void cm_req_set_primary_packet_rate(struct cm_req_msg *req_msg,
						  u8 rate)
{
	req_msg->primary_offset88 = cpu_to_be32(
				    (be32_to_cpu(req_msg->primary_offset88) &
				     0xFFFFFFC0) | (rate & 0x3F));
}

static inline u8 cm_req_get_primary_sl(struct cm_req_msg *req_msg)
{
	return (u8) (req_msg->primary_offset94 >> 4);
}

static inline void cm_req_set_primary_sl(struct cm_req_msg *req_msg, u8 sl)
{
	req_msg->primary_offset94 = (u8) ((req_msg->primary_offset94 & 0x0F) |
					  (sl << 4));
}

static inline u8 cm_req_get_primary_subnet_local(struct cm_req_msg *req_msg)
{
	return (u8) ((req_msg->primary_offset94 & 0x08) >> 3);
}

static inline void cm_req_set_primary_subnet_local(struct cm_req_msg *req_msg,
						   u8 subnet_local)
{
	req_msg->primary_offset94 = (u8) ((req_msg->primary_offset94 & 0xF7) |
					  ((subnet_local & 0x1) << 3));
}

static inline u8 cm_req_get_primary_local_ack_timeout(struct cm_req_msg *req_msg)
{
	return (u8) (req_msg->primary_offset95 >> 3);
}

static inline void cm_req_set_primary_local_ack_timeout(struct cm_req_msg *req_msg,
							u8 local_ack_timeout)
{
	req_msg->primary_offset95 = (u8) ((req_msg->primary_offset95 & 0x07) |
					  (local_ack_timeout << 3));
}

static inline __be32 cm_req_get_alt_flow_label(struct cm_req_msg *req_msg)
{
	return cpu_to_be32(be32_to_cpu(req_msg->alt_offset132) >> 12);
}

static inline void cm_req_set_alt_flow_label(struct cm_req_msg *req_msg,
					     __be32 flow_label)
{
	req_msg->alt_offset132 = cpu_to_be32(
				 (be32_to_cpu(req_msg->alt_offset132) &
				  0x00000FFF) |
				  (be32_to_cpu(flow_label) << 12));
}

static inline u8 cm_req_get_alt_packet_rate(struct cm_req_msg *req_msg)
{
	return (u8) (be32_to_cpu(req_msg->alt_offset132) & 0x3F);
}

static inline void cm_req_set_alt_packet_rate(struct cm_req_msg *req_msg,
					      u8 rate)
{
	req_msg->alt_offset132 = cpu_to_be32(
				 (be32_to_cpu(req_msg->alt_offset132) &
				  0xFFFFFFC0) | (rate & 0x3F));
}

static inline u8 cm_req_get_alt_sl(struct cm_req_msg *req_msg)
{
	return (u8) (req_msg->alt_offset138 >> 4);
}

static inline void cm_req_set_alt_sl(struct cm_req_msg *req_msg, u8 sl)
{
	req_msg->alt_offset138 = (u8) ((req_msg->alt_offset138 & 0x0F) |
				       (sl << 4));
}

static inline u8 cm_req_get_alt_subnet_local(struct cm_req_msg *req_msg)
{
	return (u8) ((req_msg->alt_offset138 & 0x08) >> 3);
}

static inline void cm_req_set_alt_subnet_local(struct cm_req_msg *req_msg,
					       u8 subnet_local)
{
	req_msg->alt_offset138 = (u8) ((req_msg->alt_offset138 & 0xF7) |
				       ((subnet_local & 0x1) << 3));
}

static inline u8 cm_req_get_alt_local_ack_timeout(struct cm_req_msg *req_msg)
{
	return (u8) (req_msg->alt_offset139 >> 3);
}

static inline void cm_req_set_alt_local_ack_timeout(struct cm_req_msg *req_msg,
						    u8 local_ack_timeout)
{
	req_msg->alt_offset139 = (u8) ((req_msg->alt_offset139 & 0x07) |
				       (local_ack_timeout << 3));
}

/* Message REJected or MRAed */
@@ -385,419 +57,12 @@ enum cm_msg_response {
	CM_MSG_RESPONSE_OTHER = 0x2
};

 struct cm_mra_msg {
	struct ib_mad_hdr hdr;

	__be32 local_comm_id;
	__be32 remote_comm_id;
	/* message MRAed:2, rsvd:6 */
	u8 offset8;
	/* service timeout:5, rsvd:3 */
	u8 offset9;

	u8 private_data[IB_CM_MRA_PRIVATE_DATA_SIZE];

} __packed;

static inline u8 cm_mra_get_msg_mraed(struct cm_mra_msg *mra_msg)
{
	return (u8) (mra_msg->offset8 >> 6);
}

static inline void cm_mra_set_msg_mraed(struct cm_mra_msg *mra_msg, u8 msg)
{
	mra_msg->offset8 = (u8) ((mra_msg->offset8 & 0x3F) | (msg << 6));
}

static inline u8 cm_mra_get_service_timeout(struct cm_mra_msg *mra_msg)
{
	return (u8) (mra_msg->offset9 >> 3);
}

static inline void cm_mra_set_service_timeout(struct cm_mra_msg *mra_msg,
					      u8 service_timeout)
{
	mra_msg->offset9 = (u8) ((mra_msg->offset9 & 0x07) |
				 (service_timeout << 3));
}

struct cm_rej_msg {
	struct ib_mad_hdr hdr;

	__be32 local_comm_id;
	__be32 remote_comm_id;
	/* message REJected:2, rsvd:6 */
	u8 offset8;
	/* reject info length:7, rsvd:1. */
	u8 offset9;
	__be16 reason;
	u8 ari[IB_CM_REJ_ARI_LENGTH];

	u8 private_data[IB_CM_REJ_PRIVATE_DATA_SIZE];

} __packed;

static inline u8 cm_rej_get_msg_rejected(struct cm_rej_msg *rej_msg)
{
	return (u8) (rej_msg->offset8 >> 6);
}

static inline void cm_rej_set_msg_rejected(struct cm_rej_msg *rej_msg, u8 msg)
{
	rej_msg->offset8 = (u8) ((rej_msg->offset8 & 0x3F) | (msg << 6));
}

static inline u8 cm_rej_get_reject_info_len(struct cm_rej_msg *rej_msg)
{
	return (u8) (rej_msg->offset9 >> 1);
}

static inline void cm_rej_set_reject_info_len(struct cm_rej_msg *rej_msg,
					      u8 len)
{
	rej_msg->offset9 = (u8) ((rej_msg->offset9 & 0x1) | (len << 1));
}

struct cm_rep_msg {
	struct ib_mad_hdr hdr;

	__be32 local_comm_id;
	__be32 remote_comm_id;
	__be32 local_qkey;
	/* local QPN:24, rsvd:8 */
	__be32 offset12;
	/* local EECN:24, rsvd:8 */
	__be32 offset16;
	/* starting PSN:24 rsvd:8 */
	__be32 offset20;
	u8 resp_resources;
	u8 initiator_depth;
	/* target ACK delay:5, failover accepted:2, end-to-end flow control:1 */
	u8 offset26;
	/* RNR retry count:3, SRQ:1, rsvd:5 */
	u8 offset27;
	__be64 local_ca_guid;

	u8 private_data[IB_CM_REP_PRIVATE_DATA_SIZE];

} __packed;

static inline __be32 cm_rep_get_local_qpn(struct cm_rep_msg *rep_msg)
{
	return cpu_to_be32(be32_to_cpu(rep_msg->offset12) >> 8);
}

static inline void cm_rep_set_local_qpn(struct cm_rep_msg *rep_msg, __be32 qpn)
{
	rep_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
			    (be32_to_cpu(rep_msg->offset12) & 0x000000FF));
}

static inline __be32 cm_rep_get_local_eecn(struct cm_rep_msg *rep_msg)
{
	return cpu_to_be32(be32_to_cpu(rep_msg->offset16) >> 8);
}

static inline void cm_rep_set_local_eecn(struct cm_rep_msg *rep_msg, __be32 eecn)
{
	rep_msg->offset16 = cpu_to_be32((be32_to_cpu(eecn) << 8) |
			    (be32_to_cpu(rep_msg->offset16) & 0x000000FF));
}

static inline __be32 cm_rep_get_qpn(struct cm_rep_msg *rep_msg, enum ib_qp_type qp_type)
{
	return (qp_type == IB_QPT_XRC_INI) ?
		cm_rep_get_local_eecn(rep_msg) : cm_rep_get_local_qpn(rep_msg);
}

static inline __be32 cm_rep_get_starting_psn(struct cm_rep_msg *rep_msg)
{
	return cpu_to_be32(be32_to_cpu(rep_msg->offset20) >> 8);
}

static inline void cm_rep_set_starting_psn(struct cm_rep_msg *rep_msg,
					   __be32 starting_psn)
{
	rep_msg->offset20 = cpu_to_be32((be32_to_cpu(starting_psn) << 8) |
			    (be32_to_cpu(rep_msg->offset20) & 0x000000FF));
}

static inline u8 cm_rep_get_target_ack_delay(struct cm_rep_msg *rep_msg)
{
	return (u8) (rep_msg->offset26 >> 3);
}

static inline void cm_rep_set_target_ack_delay(struct cm_rep_msg *rep_msg,
					       u8 target_ack_delay)
{
	rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0x07) |
				  (target_ack_delay << 3));
}

static inline u8 cm_rep_get_failover(struct cm_rep_msg *rep_msg)
{
	return (u8) ((rep_msg->offset26 & 0x06) >> 1);
}

static inline void cm_rep_set_failover(struct cm_rep_msg *rep_msg, u8 failover)
{
	rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xF9) |
				  ((failover & 0x3) << 1));
}

static inline u8 cm_rep_get_flow_ctrl(struct cm_rep_msg *rep_msg)
{
	return (u8) (rep_msg->offset26 & 0x01);
}

static inline void cm_rep_set_flow_ctrl(struct cm_rep_msg *rep_msg,
					    u8 flow_ctrl)
{
	rep_msg->offset26 = (u8) ((rep_msg->offset26 & 0xFE) |
				  (flow_ctrl & 0x1));
}

static inline u8 cm_rep_get_rnr_retry_count(struct cm_rep_msg *rep_msg)
{
	return (u8) (rep_msg->offset27 >> 5);
}

static inline void cm_rep_set_rnr_retry_count(struct cm_rep_msg *rep_msg,
					      u8 rnr_retry_count)
{
	rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0x1F) |
				  (rnr_retry_count << 5));
}

static inline u8 cm_rep_get_srq(struct cm_rep_msg *rep_msg)
{
	return (u8) ((rep_msg->offset27 >> 4) & 0x1);
}

static inline void cm_rep_set_srq(struct cm_rep_msg *rep_msg, u8 srq)
{
	rep_msg->offset27 = (u8) ((rep_msg->offset27 & 0xEF) |
				  ((srq & 0x1) << 4));
}

struct cm_rtu_msg {
	struct ib_mad_hdr hdr;

	__be32 local_comm_id;
	__be32 remote_comm_id;

	u8 private_data[IB_CM_RTU_PRIVATE_DATA_SIZE];

} __packed;

struct cm_dreq_msg {
	struct ib_mad_hdr hdr;

	__be32 local_comm_id;
	__be32 remote_comm_id;
	/* remote QPN/EECN:24, rsvd:8 */
	__be32 offset8;

	u8 private_data[IB_CM_DREQ_PRIVATE_DATA_SIZE];

} __packed;

static inline __be32 cm_dreq_get_remote_qpn(struct cm_dreq_msg *dreq_msg)
{
	return cpu_to_be32(be32_to_cpu(dreq_msg->offset8) >> 8);
}

static inline void cm_dreq_set_remote_qpn(struct cm_dreq_msg *dreq_msg, __be32 qpn)
{
	dreq_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
			    (be32_to_cpu(dreq_msg->offset8) & 0x000000FF));
}

struct cm_drep_msg {
	struct ib_mad_hdr hdr;

	__be32 local_comm_id;
	__be32 remote_comm_id;

	u8 private_data[IB_CM_DREP_PRIVATE_DATA_SIZE];

} __packed;

struct cm_lap_msg {
	struct ib_mad_hdr hdr;

	__be32 local_comm_id;
	__be32 remote_comm_id;

	__be32 rsvd8;
	/* remote QPN/EECN:24, remote CM response timeout:5, rsvd:3 */
	__be32 offset12;
	__be32 rsvd16;

	__be16 alt_local_lid;
	__be16 alt_remote_lid;
	union ib_gid alt_local_gid;
	union ib_gid alt_remote_gid;
	/* flow label:20, rsvd:4, traffic class:8 */
	__be32 offset56;
	u8 alt_hop_limit;
	/* rsvd:2, packet rate:6 */
	u8 offset61;
	/* SL:4, subnet local:1, rsvd:3 */
	u8 offset62;
	/* local ACK timeout:5, rsvd:3 */
	u8 offset63;

	u8 private_data[IB_CM_LAP_PRIVATE_DATA_SIZE];
} __packed;

static inline __be32 cm_lap_get_remote_qpn(struct cm_lap_msg *lap_msg)
{
	return cpu_to_be32(be32_to_cpu(lap_msg->offset12) >> 8);
}

static inline void cm_lap_set_remote_qpn(struct cm_lap_msg *lap_msg, __be32 qpn)
{
	lap_msg->offset12 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
					 (be32_to_cpu(lap_msg->offset12) &
					  0x000000FF));
}

static inline u8 cm_lap_get_remote_resp_timeout(struct cm_lap_msg *lap_msg)
{
	return (u8) ((be32_to_cpu(lap_msg->offset12) & 0xF8) >> 3);
}

static inline void cm_lap_set_remote_resp_timeout(struct cm_lap_msg *lap_msg,
						  u8 resp_timeout)
{
	lap_msg->offset12 = cpu_to_be32((resp_timeout << 3) |
					 (be32_to_cpu(lap_msg->offset12) &
					  0xFFFFFF07));
}

static inline __be32 cm_lap_get_flow_label(struct cm_lap_msg *lap_msg)
{
	return cpu_to_be32(be32_to_cpu(lap_msg->offset56) >> 12);
}

static inline void cm_lap_set_flow_label(struct cm_lap_msg *lap_msg,
					 __be32 flow_label)
{
	lap_msg->offset56 = cpu_to_be32(
				 (be32_to_cpu(lap_msg->offset56) & 0x00000FFF) |
				 (be32_to_cpu(flow_label) << 12));
}

static inline u8 cm_lap_get_traffic_class(struct cm_lap_msg *lap_msg)
{
	return (u8) be32_to_cpu(lap_msg->offset56);
}

static inline void cm_lap_set_traffic_class(struct cm_lap_msg *lap_msg,
					    u8 traffic_class)
{
	lap_msg->offset56 = cpu_to_be32(traffic_class |
					 (be32_to_cpu(lap_msg->offset56) &
					  0xFFFFFF00));
}

static inline u8 cm_lap_get_packet_rate(struct cm_lap_msg *lap_msg)
{
	return lap_msg->offset61 & 0x3F;
}

static inline void cm_lap_set_packet_rate(struct cm_lap_msg *lap_msg,
					  u8 packet_rate)
{
	lap_msg->offset61 = (packet_rate & 0x3F) | (lap_msg->offset61 & 0xC0);
}

static inline u8 cm_lap_get_sl(struct cm_lap_msg *lap_msg)
{
	return lap_msg->offset62 >> 4;
}

static inline void cm_lap_set_sl(struct cm_lap_msg *lap_msg, u8 sl)
{
	lap_msg->offset62 = (sl << 4) | (lap_msg->offset62 & 0x0F);
}

static inline u8 cm_lap_get_subnet_local(struct cm_lap_msg *lap_msg)
{
	return (lap_msg->offset62 >> 3) & 0x1;
}

static inline void cm_lap_set_subnet_local(struct cm_lap_msg *lap_msg,
					   u8 subnet_local)
{
	lap_msg->offset62 = ((subnet_local & 0x1) << 3) |
			     (lap_msg->offset61 & 0xF7);
}
static inline u8 cm_lap_get_local_ack_timeout(struct cm_lap_msg *lap_msg)
{
	return lap_msg->offset63 >> 3;
}

static inline void cm_lap_set_local_ack_timeout(struct cm_lap_msg *lap_msg,
						u8 local_ack_timeout)
{
	lap_msg->offset63 = (local_ack_timeout << 3) |
			    (lap_msg->offset63 & 0x07);
}

struct cm_apr_msg {
	struct ib_mad_hdr hdr;

	__be32 local_comm_id;
	__be32 remote_comm_id;

	u8 info_length;
	u8 ap_status;
	__be16 rsvd;
	u8 info[IB_CM_APR_INFO_LENGTH];

	u8 private_data[IB_CM_APR_PRIVATE_DATA_SIZE];
} __packed;

struct cm_sidr_req_msg {
	struct ib_mad_hdr hdr;

	__be32 request_id;
	__be16 pkey;
	__be16 rsvd;
	__be64 service_id;

	u32 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE / sizeof(u32)];
} __packed;

struct cm_sidr_rep_msg {
	struct ib_mad_hdr hdr;

	__be32 request_id;
	u8 status;
	u8 info_length;
	__be16 rsvd;
	/* QPN:24, rsvd:8 */
	__be32 offset8;
	__be64 service_id;
	__be32 qkey;
	u8 info[IB_CM_SIDR_REP_INFO_LENGTH];

	u8 private_data[IB_CM_SIDR_REP_PRIVATE_DATA_SIZE];
} __packed;

static inline __be32 cm_sidr_rep_get_qpn(struct cm_sidr_rep_msg *sidr_rep_msg)
{
	return cpu_to_be32(be32_to_cpu(sidr_rep_msg->offset8) >> 8);
}

static inline void cm_sidr_rep_set_qpn(struct cm_sidr_rep_msg *sidr_rep_msg,
				       __be32 qpn)
{
	sidr_rep_msg->offset8 = cpu_to_be32((be32_to_cpu(qpn) << 8) |
					(be32_to_cpu(sidr_rep_msg->offset8) &
					 0x000000FF));
		       cpu_to_be32(IBA_GET(CM_REP_LOCAL_EE_CONTEXT_NUMBER,
					   rep_msg)) :
		       cpu_to_be32(IBA_GET(CM_REP_LOCAL_QPN, rep_msg));
}

#endif /* CM_MSGS_H */
Loading