Skip to content

Commit c2f30b4

Browse files
chorkinigaw
authored andcommitted
mi-mctp: Fix compile bug in test/mi-mctp.c when !HAVE_LINUX_MCTP_H
The test/mi-mctp.c fails to compile in certain cases where HAVE_LINUX_MCTP_H is false. There's a workaround for this condition in src/mi-mctp.c but not here. This change makes a common header and includes it in both cases. Signed-off-by: Chuck Horkin <chorkin@microsoft.com>
1 parent 6ff20a2 commit c2f30b4

File tree

3 files changed

+48
-35
lines changed

3 files changed

+48
-35
lines changed

src/nvme/mi-mctp-compat.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2+
3+
#ifndef _MI_MCTP_COMPAT_H
4+
#define _MI_MCTP_COMPAT_H
5+
6+
#include <linux/types.h>
7+
8+
/* As of kernel v5.15, these AF_MCTP-related definitions are provided by
9+
* linux/mctp.h. However, we provide a set here while that header percolates
10+
* through to standard includes.
11+
*
12+
* These were all introduced in the same version as AF_MCTP was defined,
13+
* so we can key off the presence of that.
14+
*/
15+
16+
typedef __u8 mctp_eid_t;
17+
18+
struct mctp_addr {
19+
mctp_eid_t s_addr;
20+
};
21+
22+
struct sockaddr_mctp {
23+
unsigned short int smctp_family;
24+
__u16 __smctp_pad0;
25+
unsigned int smctp_network;
26+
struct mctp_addr smctp_addr;
27+
__u8 smctp_type;
28+
__u8 smctp_tag;
29+
__u8 __smctp_pad1;
30+
};
31+
32+
#define MCTP_NET_ANY 0x0
33+
34+
#define MCTP_ADDR_NULL 0x00
35+
#define MCTP_ADDR_ANY 0xff
36+
37+
#define MCTP_TAG_MASK 0x07
38+
#define MCTP_TAG_OWNER 0x08
39+
40+
#endif /* _MI_MCTP_COMPAT_H */

src/nvme/mi-mctp.c

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#if HAVE_LINUX_MCTP_H
2222
#include <linux/mctp.h>
23+
#else
24+
#include "nvme/mi-mctp-compat.h"
2325
#endif
2426

2527
#include <ccan/endian/endian.h>
@@ -41,41 +43,6 @@
4143
#define AF_MCTP 45
4244
#endif
4345

44-
#if !HAVE_LINUX_MCTP_H
45-
/* As of kernel v5.15, these AF_MCTP-related definitions are provided by
46-
* linux/mctp.h. However, we provide a set here while that header percolates
47-
* through to standard includes.
48-
*
49-
* These were all introduced in the same version as AF_MCTP was defined,
50-
* so we can key off the presence of that.
51-
*/
52-
53-
typedef __u8 mctp_eid_t;
54-
55-
struct mctp_addr {
56-
mctp_eid_t s_addr;
57-
};
58-
59-
struct sockaddr_mctp {
60-
unsigned short int smctp_family;
61-
__u16 __smctp_pad0;
62-
unsigned int smctp_network;
63-
struct mctp_addr smctp_addr;
64-
__u8 smctp_type;
65-
__u8 smctp_tag;
66-
__u8 __smctp_pad1;
67-
};
68-
69-
#define MCTP_NET_ANY 0x0
70-
71-
#define MCTP_ADDR_NULL 0x00
72-
#define MCTP_ADDR_ANY 0xff
73-
74-
#define MCTP_TAG_MASK 0x07
75-
#define MCTP_TAG_OWNER 0x08
76-
77-
#endif /* !AF_MCTP */
78-
7946
#if !defined(MCTP_TAG_PREALLOC)
8047
/*Adding this here for users with older build MCTP header
8148
*that require SIOCMCTPALLOC/DROP

test/mi-mctp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
#include "nvme/private.h"
2323
#include "utils.h"
2424

25+
#if HAVE_LINUX_MCTP_H
26+
#include <linux/mctp.h>
27+
#else
28+
#include "nvme/mi-mctp-compat.h"
29+
#endif
30+
2531
/* 4096 byte max MCTP message, plus space for header data */
2632
#define MAX_BUFSIZ 8192
2733

0 commit comments

Comments
 (0)