Re: [PATCH v4 iproute2 2/7] rdma: Add dev object

2 messages, 2 authors, 2017-08-15 · open the first message on its own page

Re: [PATCH v4 iproute2 2/7] rdma: Add dev object

From: Leon Romanovsky <hidden>
Date: 2017-08-15 16:47:20

On Tue, Aug 15, 2017 at 04:23:11PM +0000, David Laight wrote:
From: Stephen Hemminger
quoted
Sent: 15 August 2017 17:12
On Tue, 15 Aug 2017 16:00:15 +0300
Leon Romanovsky [off-list ref] wrote:
quoted
+
+static const char *dev_caps_to_str(uint32_t idx)
+{
+	uint64_t cap = 1 << idx;
+
+	switch (cap) {
+	case RDMA_DEV_RESIZE_MAX_WR: return "RESIZE_MAX_WR";
+	case RDMA_DEV_BAD_PKEY_CNTR: return "BAD_PKEY_CNTR";
...
quoted
quoted
+	case RDMA_DEV_RAW_SCATTER_FCS: return "RAW_SCATTER_FCS";
+	case RDMA_DEV_RDMA_NETDEV_OPA_VNIC: return "RDMA_NETDEV_OPA_VNIC";
+	default: return "UNKNOWN";
+	}
Could this be a table in future versions?
Potentially you could define the constants using some pre-processor
'magic' that would create the table for you.
Something like (but not compiled):

#define RDMA_DEV_FLAGS(x) \
	x(RESIZE_MAX_WR, 0) \
	x(BAD_PKEY_CNTR, 1) \
(continue for all the bits)

#define RDMA_DEV_ENUM(name, bit_no) RDMA_DEV_##name = BIT(bit_no),
enum {RDMA_DEV_FLAGS(RDMA_DEV_ENUM)};
#undef RDMA_DEV_ENUM

#define RDMA_DEV_NAMES(name, bit_no) [bit_no] = #name,
static const char rdma_dev_names[] = {RDMA_DEV_FLAGS(RDMA_DEV_NAMES)};
David,

How should I handle "uknown" fields without names?

Thanks
	David

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

RE: [PATCH v4 iproute2 2/7] rdma: Add dev object

From: David Laight <hidden>
Date: 2017-08-15 17:01:09

From: Leon Romanovsky
Sent: 15 August 2017 17:47
On Tue, Aug 15, 2017 at 04:23:11PM +0000, David Laight wrote:
quoted
From: Stephen Hemminger
quoted
Sent: 15 August 2017 17:12
On Tue, 15 Aug 2017 16:00:15 +0300
Leon Romanovsky [off-list ref] wrote:
quoted
+
+static const char *dev_caps_to_str(uint32_t idx)
+{
+	uint64_t cap = 1 << idx;
+
+	switch (cap) {
+	case RDMA_DEV_RESIZE_MAX_WR: return "RESIZE_MAX_WR";
+	case RDMA_DEV_BAD_PKEY_CNTR: return "BAD_PKEY_CNTR";
...
quoted
quoted
+	case RDMA_DEV_RAW_SCATTER_FCS: return "RAW_SCATTER_FCS";
+	case RDMA_DEV_RDMA_NETDEV_OPA_VNIC: return "RDMA_NETDEV_OPA_VNIC";
+	default: return "UNKNOWN";
+	}
Could this be a table in future versions?
Potentially you could define the constants using some pre-processor
'magic' that would create the table for you.
Something like (but not compiled):

#define RDMA_DEV_FLAGS(x) \
	x(RESIZE_MAX_WR, 0) \
	x(BAD_PKEY_CNTR, 1) \
(continue for all the bits)

#define RDMA_DEV_ENUM(name, bit_no) RDMA_DEV_##name = BIT(bit_no),
enum {RDMA_DEV_FLAGS(RDMA_DEV_ENUM)};
#undef RDMA_DEV_ENUM

#define RDMA_DEV_NAMES(name, bit_no) [bit_no] = #name,
static const char rdma_dev_names[] = {RDMA_DEV_FLAGS(RDMA_DEV_NAMES)};
I missed the #undef
quoted
David,

How should I handle "uknown" fields without names?
The function that accesses rdma_dev_names[] checks ARRAY_SIZE()
and for a NULL pointer.

WRT the other comment, the spare pointers consume far less space than
the code for your switch statement.

	David
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help