^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * An implementation of key value pair (KVP) functionality for Linux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2010, Novell, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This program is free software; you can redistribute it and/or modify it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * under the terms of the GNU General Public License version 2 as published
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This program is distributed in the hope that it will be useful, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * NON INFRINGEMENT. See the GNU General Public License for more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * You should have received a copy of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * along with this program; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/nls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/connector.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/hyperv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/hyperv-tlfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "hyperv_vmbus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "hv_utils_transport.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Pre win8 version numbers used in ws2008 and ws 2008 r2 (win7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define WS2008_SRV_MAJOR 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define WS2008_SRV_MINOR 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define WS2008_SRV_VERSION (WS2008_SRV_MAJOR << 16 | WS2008_SRV_MINOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define WIN7_SRV_MAJOR 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define WIN7_SRV_MINOR 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define WIN7_SRV_VERSION (WIN7_SRV_MAJOR << 16 | WIN7_SRV_MINOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define WIN8_SRV_MAJOR 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define WIN8_SRV_MINOR 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define WIN8_SRV_VERSION (WIN8_SRV_MAJOR << 16 | WIN8_SRV_MINOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define KVP_VER_COUNT 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static const int kvp_versions[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) WIN8_SRV_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) WIN7_SRV_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) WS2008_SRV_VERSION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define FW_VER_COUNT 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static const int fw_versions[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) UTIL_FW_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) UTIL_WS2K8_FW_VERSION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * Global state maintained for transaction that is being processed. For a class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * of integration services, including the "KVP service", the specified protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * is a "request/response" protocol which means that there can only be single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * outstanding transaction from the host at any given point in time. We use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * this to simplify memory management in this driver - we cache and process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * only one message at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * While the request/response protocol is guaranteed by the host, we further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * ensure this by serializing packet processing in this driver - we do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * read additional packets from the VMBUS until the current packet is fully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * handled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int state; /* hvutil_device_state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int recv_len; /* number of bytes received. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct hv_kvp_msg *kvp_msg; /* current message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct vmbus_channel *recv_channel; /* chn we got the request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u64 recv_req_id; /* request ID. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) } kvp_transaction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * This state maintains the version number registered by the daemon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static int dm_reg_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static void kvp_send_key(struct work_struct *dummy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static void kvp_respond_to_host(struct hv_kvp_msg *msg, int error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static void kvp_timeout_func(struct work_struct *dummy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static void kvp_host_handshake_func(struct work_struct *dummy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static void kvp_register(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static DECLARE_DELAYED_WORK(kvp_timeout_work, kvp_timeout_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static DECLARE_DELAYED_WORK(kvp_host_handshake_work, kvp_host_handshake_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static DECLARE_WORK(kvp_sendkey_work, kvp_send_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static const char kvp_devname[] = "vmbus/hv_kvp";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static u8 *recv_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static struct hvutil_transport *hvt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * Register the kernel component with the user-level daemon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * As part of this registration, pass the LIC version number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * This number has no meaning, it satisfies the registration protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define HV_DRV_VERSION "3.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void kvp_poll_wrapper(void *channel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* Transaction is finished, reset the state here to avoid races. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) kvp_transaction.state = HVUTIL_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) tasklet_schedule(&((struct vmbus_channel *)channel)->callback_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static void kvp_register_done(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * If we're still negotiating with the host cancel the timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * work to not poll the channel twice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) pr_debug("KVP: userspace daemon registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) cancel_delayed_work_sync(&kvp_host_handshake_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) hv_poll_channel(kvp_transaction.recv_channel, kvp_poll_wrapper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) kvp_register(int reg_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct hv_kvp_msg *kvp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) char *version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) kvp_msg = kzalloc(sizeof(*kvp_msg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (kvp_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) version = kvp_msg->body.kvp_register.version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) kvp_msg->kvp_hdr.operation = reg_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) strcpy(version, HV_DRV_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) hvutil_transport_send(hvt, kvp_msg, sizeof(*kvp_msg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) kvp_register_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) kfree(kvp_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static void kvp_timeout_func(struct work_struct *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * If the timer fires, the user-mode component has not responded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * process the pending transaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) kvp_respond_to_host(NULL, HV_E_FAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) hv_poll_channel(kvp_transaction.recv_channel, kvp_poll_wrapper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void kvp_host_handshake_func(struct work_struct *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) tasklet_schedule(&kvp_transaction.recv_channel->callback_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int kvp_handle_handshake(struct hv_kvp_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) switch (msg->kvp_hdr.operation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) case KVP_OP_REGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) dm_reg_value = KVP_OP_REGISTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) pr_info("KVP: IP injection functionality not available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) pr_info("KVP: Upgrade the KVP daemon\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) case KVP_OP_REGISTER1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) dm_reg_value = KVP_OP_REGISTER1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) pr_info("KVP: incompatible daemon\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) pr_info("KVP: KVP version: %d, Daemon version: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) KVP_OP_REGISTER1, msg->kvp_hdr.operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * We have a compatible daemon; complete the handshake.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) pr_debug("KVP: userspace daemon ver. %d connected\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) msg->kvp_hdr.operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) kvp_register(dm_reg_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * Callback when data is received from user mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static int kvp_on_msg(void *msg, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct hv_kvp_msg *message = (struct hv_kvp_msg *)msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct hv_kvp_msg_enumerate *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (len < sizeof(*message))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * If we are negotiating the version information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * with the daemon; handle that first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (kvp_transaction.state < HVUTIL_READY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return kvp_handle_handshake(message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* We didn't send anything to userspace so the reply is spurious */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (kvp_transaction.state < HVUTIL_USERSPACE_REQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) kvp_transaction.state = HVUTIL_USERSPACE_RECV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Based on the version of the daemon, we propagate errors from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * daemon differently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) data = &message->body.kvp_enum_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) switch (dm_reg_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) case KVP_OP_REGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * Null string is used to pass back error condition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (data->data.key[0] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) error = HV_S_CONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) case KVP_OP_REGISTER1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * We use the message header information from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * the user level daemon to transmit errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) error = message->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * Complete the transaction by forwarding the key value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * to the host. But first, cancel the timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (cancel_delayed_work_sync(&kvp_timeout_work)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) kvp_respond_to_host(message, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) hv_poll_channel(kvp_transaction.recv_channel, kvp_poll_wrapper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int process_ob_ipinfo(void *in_msg, void *out_msg, int op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct hv_kvp_msg *in = in_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct hv_kvp_ip_msg *out = out_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) switch (op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) case KVP_OP_GET_IP_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * Transform all parameters into utf16 encoding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.ip_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) strlen((char *)in->body.kvp_ip_val.ip_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) UTF16_HOST_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) (wchar_t *)out->kvp_ip_val.ip_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) MAX_IP_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.sub_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) strlen((char *)in->body.kvp_ip_val.sub_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) UTF16_HOST_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) (wchar_t *)out->kvp_ip_val.sub_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) MAX_IP_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.gate_way,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) strlen((char *)in->body.kvp_ip_val.gate_way),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) UTF16_HOST_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) (wchar_t *)out->kvp_ip_val.gate_way,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) MAX_GATEWAY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.dns_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) strlen((char *)in->body.kvp_ip_val.dns_addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) UTF16_HOST_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) (wchar_t *)out->kvp_ip_val.dns_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) MAX_IP_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) len = utf8s_to_utf16s((char *)in->body.kvp_ip_val.adapter_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) strlen((char *)in->body.kvp_ip_val.adapter_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) UTF16_HOST_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) (wchar_t *)out->kvp_ip_val.adapter_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) MAX_ADAPTER_ID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) out->kvp_ip_val.dhcp_enabled =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) in->body.kvp_ip_val.dhcp_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) out->kvp_ip_val.addr_family =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) in->body.kvp_ip_val.addr_family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static void process_ib_ipinfo(void *in_msg, void *out_msg, int op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct hv_kvp_ip_msg *in = in_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct hv_kvp_msg *out = out_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) switch (op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) case KVP_OP_SET_IP_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * Transform all parameters into utf8 encoding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.ip_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) MAX_IP_ADDR_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) UTF16_LITTLE_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) (__u8 *)out->body.kvp_ip_val.ip_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) MAX_IP_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.sub_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) MAX_IP_ADDR_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) UTF16_LITTLE_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) (__u8 *)out->body.kvp_ip_val.sub_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) MAX_IP_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.gate_way,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) MAX_GATEWAY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) UTF16_LITTLE_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) (__u8 *)out->body.kvp_ip_val.gate_way,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) MAX_GATEWAY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.dns_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) MAX_IP_ADDR_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) UTF16_LITTLE_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) (__u8 *)out->body.kvp_ip_val.dns_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) MAX_IP_ADDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) out->body.kvp_ip_val.dhcp_enabled = in->kvp_ip_val.dhcp_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) case KVP_OP_GET_IP_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) utf16s_to_utf8s((wchar_t *)in->kvp_ip_val.adapter_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) MAX_ADAPTER_ID_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) UTF16_LITTLE_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) (__u8 *)out->body.kvp_ip_val.adapter_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) MAX_ADAPTER_ID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) out->body.kvp_ip_val.addr_family = in->kvp_ip_val.addr_family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) kvp_send_key(struct work_struct *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct hv_kvp_msg *message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct hv_kvp_msg *in_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) __u8 operation = kvp_transaction.kvp_msg->kvp_hdr.operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) __u8 pool = kvp_transaction.kvp_msg->kvp_hdr.pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) __u32 val32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) __u64 val64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* The transaction state is wrong. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (kvp_transaction.state != HVUTIL_HOSTMSG_RECEIVED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) message = kzalloc(sizeof(*message), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (!message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) message->kvp_hdr.operation = operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) message->kvp_hdr.pool = pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) in_msg = kvp_transaction.kvp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * The key/value strings sent from the host are encoded in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * in utf16; convert it to utf8 strings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * The host assures us that the utf16 strings will not exceed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) * the max lengths specified. We will however, reserve room
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * for the string terminating character - in the utf16s_utf8s()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * function we limit the size of the buffer where the converted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * string is placed to HV_KVP_EXCHANGE_MAX_*_SIZE -1 to guarantee
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * that the strings can be properly terminated!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) switch (message->kvp_hdr.operation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) case KVP_OP_SET_IP_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) process_ib_ipinfo(in_msg, message, KVP_OP_SET_IP_INFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) case KVP_OP_GET_IP_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * We only need to pass on the info of operation, adapter_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * and addr_family to the userland kvp daemon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) process_ib_ipinfo(in_msg, message, KVP_OP_GET_IP_INFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) case KVP_OP_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) switch (in_msg->body.kvp_set.data.value_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) case REG_SZ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * The value is a string - utf16 encoding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) message->body.kvp_set.data.value_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) utf16s_to_utf8s(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) (wchar_t *)in_msg->body.kvp_set.data.value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) in_msg->body.kvp_set.data.value_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) UTF16_LITTLE_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) message->body.kvp_set.data.value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) HV_KVP_EXCHANGE_MAX_VALUE_SIZE - 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) case REG_U32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * The value is a 32 bit scalar.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * We save this as a utf8 string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) val32 = in_msg->body.kvp_set.data.value_u32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) message->body.kvp_set.data.value_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) sprintf(message->body.kvp_set.data.value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) "%u", val32) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) case REG_U64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * The value is a 64 bit scalar.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * We save this as a utf8 string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) val64 = in_msg->body.kvp_set.data.value_u64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) message->body.kvp_set.data.value_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) sprintf(message->body.kvp_set.data.value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) "%llu", val64) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * The key is always a string - utf16 encoding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) message->body.kvp_set.data.key_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) utf16s_to_utf8s(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) (wchar_t *)in_msg->body.kvp_set.data.key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) in_msg->body.kvp_set.data.key_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) UTF16_LITTLE_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) message->body.kvp_set.data.key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) case KVP_OP_GET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) message->body.kvp_get.data.key_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) utf16s_to_utf8s(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) (wchar_t *)in_msg->body.kvp_get.data.key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) in_msg->body.kvp_get.data.key_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) UTF16_LITTLE_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) message->body.kvp_get.data.key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) case KVP_OP_DELETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) message->body.kvp_delete.key_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) utf16s_to_utf8s(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) (wchar_t *)in_msg->body.kvp_delete.key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) in_msg->body.kvp_delete.key_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) UTF16_LITTLE_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) message->body.kvp_delete.key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) HV_KVP_EXCHANGE_MAX_KEY_SIZE - 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) case KVP_OP_ENUMERATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) message->body.kvp_enum_data.index =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) in_msg->body.kvp_enum_data.index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) kvp_transaction.state = HVUTIL_USERSPACE_REQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) rc = hvutil_transport_send(hvt, message, sizeof(*message), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) pr_debug("KVP: failed to communicate to the daemon: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (cancel_delayed_work_sync(&kvp_timeout_work)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) kvp_respond_to_host(message, HV_E_FAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) kvp_transaction.state = HVUTIL_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) kfree(message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * Send a response back to the host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) kvp_respond_to_host(struct hv_kvp_msg *msg_to_host, int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct hv_kvp_msg *kvp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct hv_kvp_exchg_msg_value *kvp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) char *key_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) char *value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct icmsg_hdr *icmsghdrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) int keylen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) int valuelen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) u32 buf_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) struct vmbus_channel *channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) u64 req_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * Copy the global state for completing the transaction. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * only one transaction can be active at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) buf_len = kvp_transaction.recv_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) channel = kvp_transaction.recv_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) req_id = kvp_transaction.recv_req_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) icmsghdrp = (struct icmsg_hdr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) &recv_buffer[sizeof(struct vmbuspipe_hdr)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (channel->onchannel_callback == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * We have raced with util driver being unloaded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * silently return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) icmsghdrp->status = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * If the error parameter is set, terminate the host's enumeration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * on this pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * Something failed or we have timed out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * terminate the current host-side iteration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) goto response_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) kvp_msg = (struct hv_kvp_msg *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) &recv_buffer[sizeof(struct vmbuspipe_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) sizeof(struct icmsg_hdr)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) switch (kvp_transaction.kvp_msg->kvp_hdr.operation) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) case KVP_OP_GET_IP_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) ret = process_ob_ipinfo(msg_to_host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) (struct hv_kvp_ip_msg *)kvp_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) KVP_OP_GET_IP_INFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) icmsghdrp->status = HV_E_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) goto response_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) case KVP_OP_SET_IP_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) goto response_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) case KVP_OP_GET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) kvp_data = &kvp_msg->body.kvp_get.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) goto copy_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) case KVP_OP_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) case KVP_OP_DELETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) goto response_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) kvp_data = &kvp_msg->body.kvp_enum_data.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) key_name = msg_to_host->body.kvp_enum_data.data.key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * The windows host expects the key/value pair to be encoded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) * in utf16. Ensure that the key/value size reported to the host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) * will be less than or equal to the MAX size (including the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * terminating character).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) keylen = utf8s_to_utf16s(key_name, strlen(key_name), UTF16_HOST_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) (wchar_t *) kvp_data->key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) (HV_KVP_EXCHANGE_MAX_KEY_SIZE / 2) - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) kvp_data->key_size = 2*(keylen + 1); /* utf16 encoding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) copy_value:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) value = msg_to_host->body.kvp_enum_data.data.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) valuelen = utf8s_to_utf16s(value, strlen(value), UTF16_HOST_ENDIAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) (wchar_t *) kvp_data->value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) (HV_KVP_EXCHANGE_MAX_VALUE_SIZE / 2) - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) kvp_data->value_size = 2*(valuelen + 1); /* utf16 encoding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * If the utf8s to utf16s conversion failed; notify host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) * of the error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if ((keylen < 0) || (valuelen < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) icmsghdrp->status = HV_E_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) kvp_data->value_type = REG_SZ; /* all our values are strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) response_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) vmbus_sendpacket(channel, recv_buffer, buf_len, req_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) VM_PKT_DATA_INBAND, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) * This callback is invoked when we get a KVP message from the host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) * The host ensures that only one KVP transaction can be active at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) * KVP implementation in Linux needs to forward the key to a user-mde
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) * component to retrieve the corresponding value. Consequently, we cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) * respond to the host in the context of this callback. Since the host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) * guarantees that at most only one transaction can be active at a time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) * we stash away the transaction state in a set of global variables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) void hv_kvp_onchannelcallback(void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct vmbus_channel *channel = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) u32 recvlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) u64 requestid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) struct hv_kvp_msg *kvp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) struct icmsg_hdr *icmsghdrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) int kvp_srv_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) static enum {NEGO_NOT_STARTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) NEGO_IN_PROGRESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) NEGO_FINISHED} host_negotiatied = NEGO_NOT_STARTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (kvp_transaction.state < HVUTIL_READY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) * If userspace daemon is not connected and host is asking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * us to negotiate we need to delay to not lose messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * This is important for Failover IP setting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (host_negotiatied == NEGO_NOT_STARTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) host_negotiatied = NEGO_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) schedule_delayed_work(&kvp_host_handshake_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) HV_UTIL_NEGO_TIMEOUT * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (kvp_transaction.state > HVUTIL_READY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) vmbus_recvpacket(channel, recv_buffer, HV_HYP_PAGE_SIZE * 4, &recvlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) &requestid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if (recvlen > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) icmsghdrp = (struct icmsg_hdr *)&recv_buffer[
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) sizeof(struct vmbuspipe_hdr)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (vmbus_prep_negotiate_resp(icmsghdrp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) recv_buffer, fw_versions, FW_VER_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) kvp_versions, KVP_VER_COUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) NULL, &kvp_srv_version)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) pr_info("KVP IC version %d.%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) kvp_srv_version >> 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) kvp_srv_version & 0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) kvp_msg = (struct hv_kvp_msg *)&recv_buffer[
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) sizeof(struct vmbuspipe_hdr) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) sizeof(struct icmsg_hdr)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) * Stash away this global state for completing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) * transaction; note transactions are serialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) kvp_transaction.recv_len = recvlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) kvp_transaction.recv_req_id = requestid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) kvp_transaction.kvp_msg = kvp_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (kvp_transaction.state < HVUTIL_READY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) /* Userspace is not registered yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) kvp_respond_to_host(NULL, HV_E_FAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) kvp_transaction.state = HVUTIL_HOSTMSG_RECEIVED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * Get the information from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * user-mode component.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * component. This transaction will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * completed when we get the value from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * the user-mode component.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) * Set a timeout to deal with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) * user-mode not responding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) schedule_work(&kvp_sendkey_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) schedule_delayed_work(&kvp_timeout_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) HV_UTIL_TIMEOUT * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) | ICMSGHDRFLAG_RESPONSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) vmbus_sendpacket(channel, recv_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) recvlen, requestid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) VM_PKT_DATA_INBAND, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) host_negotiatied = NEGO_FINISHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) hv_poll_channel(kvp_transaction.recv_channel, kvp_poll_wrapper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) static void kvp_on_reset(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (cancel_delayed_work_sync(&kvp_timeout_work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) kvp_respond_to_host(NULL, HV_E_FAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) kvp_transaction.state = HVUTIL_DEVICE_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) hv_kvp_init(struct hv_util_service *srv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) recv_buffer = srv->recv_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) kvp_transaction.recv_channel = srv->channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * When this driver loads, the user level daemon that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * processes the host requests may not yet be running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) * Defer processing channel callbacks until the daemon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) * has registered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) kvp_transaction.state = HVUTIL_DEVICE_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) hvt = hvutil_transport_init(kvp_devname, CN_KVP_IDX, CN_KVP_VAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) kvp_on_msg, kvp_on_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) if (!hvt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) static void hv_kvp_cancel_work(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) cancel_delayed_work_sync(&kvp_host_handshake_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) cancel_delayed_work_sync(&kvp_timeout_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) cancel_work_sync(&kvp_sendkey_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) int hv_kvp_pre_suspend(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) struct vmbus_channel *channel = kvp_transaction.recv_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) tasklet_disable(&channel->callback_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) * If there is a pending transtion, it's unnecessary to tell the host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * that the transaction will fail, because that is implied when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) * util_suspend() calls vmbus_close() later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) hv_kvp_cancel_work();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) * Forece the state to READY to handle the ICMSGTYPE_NEGOTIATE message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) * later. The user space daemon may go out of order and its write()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) * may fail with EINVAL: this doesn't matter since the daemon will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) * reset the device by closing and re-opening it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) kvp_transaction.state = HVUTIL_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) int hv_kvp_pre_resume(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) struct vmbus_channel *channel = kvp_transaction.recv_channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) tasklet_enable(&channel->callback_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) void hv_kvp_deinit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) kvp_transaction.state = HVUTIL_DEVICE_DYING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) hv_kvp_cancel_work();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) hvutil_transport_destroy(hvt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }