]>
git.proxmox.com Git - ceph.git/blob - ceph/src/dpdk/lib/librte_power/guest_channel.c
4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 #include "guest_channel.h"
47 #include "channel_commands.h"
49 #define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1
51 static int global_fds
[RTE_MAX_LCORE
];
54 guest_channel_host_connect(const char *path
, unsigned lcore_id
)
57 struct channel_packet pkt
;
58 char fd_path
[PATH_MAX
];
61 if (lcore_id
>= RTE_MAX_LCORE
) {
62 RTE_LOG(ERR
, GUEST_CHANNEL
, "Channel(%u) is out of range 0...%d\n",
63 lcore_id
, RTE_MAX_LCORE
-1);
66 /* check if path is already open */
67 if (global_fds
[lcore_id
] != 0) {
68 RTE_LOG(ERR
, GUEST_CHANNEL
, "Channel(%u) is already open with fd %d\n",
69 lcore_id
, global_fds
[lcore_id
]);
73 snprintf(fd_path
, PATH_MAX
, "%s.%u", path
, lcore_id
);
74 RTE_LOG(INFO
, GUEST_CHANNEL
, "Opening channel '%s' for lcore %u\n",
76 fd
= open(fd_path
, O_RDWR
);
78 RTE_LOG(ERR
, GUEST_CHANNEL
, "Unable to to connect to '%s' with error "
79 "%s\n", fd_path
, strerror(errno
));
83 flags
= fcntl(fd
, F_GETFL
, 0);
85 RTE_LOG(ERR
, GUEST_CHANNEL
, "Failed on fcntl get flags for file %s\n",
91 if (fcntl(fd
, F_SETFL
, flags
) < 0) {
92 RTE_LOG(ERR
, GUEST_CHANNEL
, "Failed on setting non-blocking mode for "
96 /* QEMU needs a delay after connection */
99 /* Send a test packet, this command is ignored by the host, but a successful
100 * send indicates that the host endpoint is monitoring.
102 pkt
.command
= CPU_POWER_CONNECT
;
103 global_fds
[lcore_id
] = fd
;
104 ret
= guest_channel_send_msg(&pkt
, lcore_id
);
106 RTE_LOG(ERR
, GUEST_CHANNEL
,
107 "Error on channel '%s' communications test: %s\n",
108 fd_path
, ret
> 0 ? strerror(ret
) :
109 "channel not connected");
112 RTE_LOG(INFO
, GUEST_CHANNEL
, "Channel '%s' is now connected\n", fd_path
);
116 global_fds
[lcore_id
] = 0;
121 guest_channel_send_msg(struct channel_packet
*pkt
, unsigned lcore_id
)
123 int ret
, buffer_len
= sizeof(*pkt
);
126 if (lcore_id
>= RTE_MAX_LCORE
) {
127 RTE_LOG(ERR
, GUEST_CHANNEL
, "Channel(%u) is out of range 0...%d\n",
128 lcore_id
, RTE_MAX_LCORE
-1);
132 if (global_fds
[lcore_id
] == 0) {
133 RTE_LOG(ERR
, GUEST_CHANNEL
, "Channel is not connected\n");
136 while (buffer_len
> 0) {
137 ret
= write(global_fds
[lcore_id
], buffer
, buffer_len
);
138 if (ret
== buffer_len
)
145 buffer
= (char *)buffer
+ ret
;
152 guest_channel_host_disconnect(unsigned lcore_id
)
154 if (lcore_id
>= RTE_MAX_LCORE
) {
155 RTE_LOG(ERR
, GUEST_CHANNEL
, "Channel(%u) is out of range 0...%d\n",
156 lcore_id
, RTE_MAX_LCORE
-1);
159 if (global_fds
[lcore_id
] == 0)
161 close(global_fds
[lcore_id
]);
162 global_fds
[lcore_id
] = 0;