^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Sample in-kernel QMI client driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2017 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/qrtr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/soc/qcom/qmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define PING_REQ1_TLV_TYPE 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define PING_RESP1_TLV_TYPE 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PING_OPT1_TLV_TYPE 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define PING_OPT2_TLV_TYPE 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define DATA_REQ1_TLV_TYPE 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define DATA_RESP1_TLV_TYPE 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define DATA_OPT1_TLV_TYPE 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define DATA_OPT2_TLV_TYPE 0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define TEST_MED_DATA_SIZE_V01 8192
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define TEST_MAX_NAME_SIZE_V01 255
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define TEST_PING_REQ_MSG_ID_V01 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define TEST_DATA_REQ_MSG_ID_V01 0x21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define TEST_PING_REQ_MAX_MSG_LEN_V01 266
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define TEST_DATA_REQ_MAX_MSG_LEN_V01 8456
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct test_name_type_v01 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u32 name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) char name[TEST_MAX_NAME_SIZE_V01];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static struct qmi_elem_info test_name_type_v01_ei[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .data_type = QMI_DATA_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .elem_size = sizeof(u8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .tlv_type = QMI_COMMON_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .offset = offsetof(struct test_name_type_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) name_len),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .data_type = QMI_UNSIGNED_1_BYTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .elem_len = TEST_MAX_NAME_SIZE_V01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .elem_size = sizeof(char),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .array_type = VAR_LEN_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .tlv_type = QMI_COMMON_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .offset = offsetof(struct test_name_type_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct test_ping_req_msg_v01 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) char ping[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u8 client_name_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct test_name_type_v01 client_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static struct qmi_elem_info test_ping_req_msg_v01_ei[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .data_type = QMI_UNSIGNED_1_BYTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .elem_len = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .elem_size = sizeof(char),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .array_type = STATIC_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .tlv_type = PING_REQ1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .offset = offsetof(struct test_ping_req_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ping),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .data_type = QMI_OPT_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .elem_size = sizeof(u8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .tlv_type = PING_OPT1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .offset = offsetof(struct test_ping_req_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) client_name_valid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .data_type = QMI_STRUCT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .elem_size = sizeof(struct test_name_type_v01),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .tlv_type = PING_OPT1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .offset = offsetof(struct test_ping_req_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) client_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .ei_array = test_name_type_v01_ei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct test_ping_resp_msg_v01 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct qmi_response_type_v01 resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) u8 pong_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) char pong[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) u8 service_name_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct test_name_type_v01 service_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static struct qmi_elem_info test_ping_resp_msg_v01_ei[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .data_type = QMI_STRUCT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .elem_size = sizeof(struct qmi_response_type_v01),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .tlv_type = PING_RESP1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .offset = offsetof(struct test_ping_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) resp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .ei_array = qmi_response_type_v01_ei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .data_type = QMI_OPT_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .elem_size = sizeof(u8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .tlv_type = PING_OPT1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .offset = offsetof(struct test_ping_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) pong_valid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .data_type = QMI_UNSIGNED_1_BYTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .elem_len = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .elem_size = sizeof(char),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .array_type = STATIC_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .tlv_type = PING_OPT1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .offset = offsetof(struct test_ping_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) pong),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .data_type = QMI_OPT_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .elem_size = sizeof(u8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .tlv_type = PING_OPT2_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .offset = offsetof(struct test_ping_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) service_name_valid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .data_type = QMI_STRUCT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .elem_size = sizeof(struct test_name_type_v01),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .tlv_type = PING_OPT2_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .offset = offsetof(struct test_ping_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) service_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .ei_array = test_name_type_v01_ei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) },
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct test_data_req_msg_v01 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) u32 data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) u8 data[TEST_MED_DATA_SIZE_V01];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) u8 client_name_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct test_name_type_v01 client_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static struct qmi_elem_info test_data_req_msg_v01_ei[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .data_type = QMI_DATA_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) .elem_size = sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .tlv_type = DATA_REQ1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .offset = offsetof(struct test_data_req_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) data_len),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .data_type = QMI_UNSIGNED_1_BYTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .elem_len = TEST_MED_DATA_SIZE_V01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) .elem_size = sizeof(u8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .array_type = VAR_LEN_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .tlv_type = DATA_REQ1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) .offset = offsetof(struct test_data_req_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) data),
^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) .data_type = QMI_OPT_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .elem_size = sizeof(u8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .tlv_type = DATA_OPT1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .offset = offsetof(struct test_data_req_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) client_name_valid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .data_type = QMI_STRUCT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) .elem_size = sizeof(struct test_name_type_v01),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .tlv_type = DATA_OPT1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) .offset = offsetof(struct test_data_req_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) client_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) .ei_array = test_name_type_v01_ei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct test_data_resp_msg_v01 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct qmi_response_type_v01 resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) u8 data_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) u32 data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) u8 data[TEST_MED_DATA_SIZE_V01];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) u8 service_name_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct test_name_type_v01 service_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static struct qmi_elem_info test_data_resp_msg_v01_ei[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .data_type = QMI_STRUCT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) .elem_size = sizeof(struct qmi_response_type_v01),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .tlv_type = DATA_RESP1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .offset = offsetof(struct test_data_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) resp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .ei_array = qmi_response_type_v01_ei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .data_type = QMI_OPT_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .elem_size = sizeof(u8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .tlv_type = DATA_OPT1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .offset = offsetof(struct test_data_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) data_valid),
^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) .data_type = QMI_DATA_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .elem_size = sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .tlv_type = DATA_OPT1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) .offset = offsetof(struct test_data_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) data_len),
^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) .data_type = QMI_UNSIGNED_1_BYTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) .elem_len = TEST_MED_DATA_SIZE_V01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .elem_size = sizeof(u8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .array_type = VAR_LEN_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) .tlv_type = DATA_OPT1_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .offset = offsetof(struct test_data_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .data_type = QMI_OPT_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) .elem_size = sizeof(u8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .tlv_type = DATA_OPT2_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .offset = offsetof(struct test_data_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) service_name_valid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) .data_type = QMI_STRUCT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) .elem_len = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) .elem_size = sizeof(struct test_name_type_v01),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) .array_type = NO_ARRAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .tlv_type = DATA_OPT2_TLV_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .offset = offsetof(struct test_data_resp_msg_v01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) service_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) .ei_array = test_name_type_v01_ei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * ping_write() - ping_pong debugfs file write handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * @file: debugfs file context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * @user_buf: reference to the user data (ignored)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * @count: number of bytes in @user_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * @ppos: offset in @file to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * This function allows user space to send out a ping_pong QMI encoded message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * to the associated remote test service and will return with the result of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * transaction. It serves as an example of how to provide a custom response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * Return: @count, or negative errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static ssize_t ping_write(struct file *file, const char __user *user_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct qmi_handle *qmi = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct test_ping_req_msg_v01 req = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct qmi_txn txn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) memcpy(req.ping, "ping", sizeof(req.ping));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) ret = qmi_txn_init(qmi, &txn, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ret = qmi_send_request(qmi, NULL, &txn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) TEST_PING_REQ_MSG_ID_V01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) TEST_PING_REQ_MAX_MSG_LEN_V01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) test_ping_req_msg_v01_ei, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) qmi_txn_cancel(&txn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) ret = qmi_txn_wait(&txn, 5 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) count = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) static const struct file_operations ping_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .write = ping_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static void ping_pong_cb(struct qmi_handle *qmi, struct sockaddr_qrtr *sq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct qmi_txn *txn, const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) const struct test_ping_resp_msg_v01 *resp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (!txn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) pr_err("spurious ping response\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (resp->resp.result == QMI_RESULT_FAILURE_V01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) txn->result = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) else if (!resp->pong_valid || memcmp(resp->pong, "pong", 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) txn->result = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) complete(&txn->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * data_write() - data debugfs file write handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * @file: debugfs file context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * @user_buf: reference to the user data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * @count: number of bytes in @user_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * @ppos: offset in @file to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * This function allows user space to send out a data QMI encoded message to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * the associated remote test service and will return with the result of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * transaction. It serves as an example of how to have the QMI helpers decode a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * transaction response into a provided object automatically.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * Return: @count, or negative errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static ssize_t data_write(struct file *file, const char __user *user_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) size_t count, loff_t *ppos)
^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) struct qmi_handle *qmi = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct test_data_resp_msg_v01 *resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) struct test_data_req_msg_v01 *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct qmi_txn txn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) req = kzalloc(sizeof(*req), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) resp = kzalloc(sizeof(*resp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (!resp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) req->data_len = min_t(size_t, sizeof(req->data), count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (copy_from_user(req->data, user_buf, req->data_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ret = qmi_txn_init(qmi, &txn, test_data_resp_msg_v01_ei, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ret = qmi_send_request(qmi, NULL, &txn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) TEST_DATA_REQ_MSG_ID_V01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) TEST_DATA_REQ_MAX_MSG_LEN_V01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) test_data_req_msg_v01_ei, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) qmi_txn_cancel(&txn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) goto out;
^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) ret = qmi_txn_wait(&txn, 5 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) } else if (!resp->data_valid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) resp->data_len != req->data_len ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) memcmp(resp->data, req->data, req->data_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) pr_err("response data doesn't match expectation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) ret = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) kfree(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static const struct file_operations data_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) .write = data_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static struct qmi_msg_handler qmi_sample_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) .type = QMI_RESPONSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) .msg_id = TEST_PING_REQ_MSG_ID_V01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) .ei = test_ping_resp_msg_v01_ei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) .decoded_size = sizeof(struct test_ping_req_msg_v01),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) .fn = ping_pong_cb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct qmi_sample {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct qmi_handle qmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct dentry *de_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct dentry *de_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct dentry *de_ping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static struct dentry *qmi_debug_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) static int qmi_sample_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct sockaddr_qrtr *sq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct qmi_sample *sample;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) char path[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) sample = devm_kzalloc(&pdev->dev, sizeof(*sample), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (!sample)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) ret = qmi_handle_init(&sample->qmi, TEST_DATA_REQ_MAX_MSG_LEN_V01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) qmi_sample_handlers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) sq = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) ret = kernel_connect(sample->qmi.sock, (struct sockaddr *)sq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) sizeof(*sq), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) pr_err("failed to connect to remote service port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) goto err_release_qmi_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) snprintf(path, sizeof(path), "%d:%d", sq->sq_node, sq->sq_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) sample->de_dir = debugfs_create_dir(path, qmi_debug_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (IS_ERR(sample->de_dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) ret = PTR_ERR(sample->de_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) goto err_release_qmi_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) sample->de_data = debugfs_create_file("data", 0600, sample->de_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) sample, &data_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (IS_ERR(sample->de_data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) ret = PTR_ERR(sample->de_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) goto err_remove_de_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) sample->de_ping = debugfs_create_file("ping", 0600, sample->de_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) sample, &ping_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (IS_ERR(sample->de_ping)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) ret = PTR_ERR(sample->de_ping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) goto err_remove_de_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) platform_set_drvdata(pdev, sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) err_remove_de_data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) debugfs_remove(sample->de_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) err_remove_de_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) debugfs_remove(sample->de_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) err_release_qmi_handle:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) qmi_handle_release(&sample->qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static int qmi_sample_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct qmi_sample *sample = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) debugfs_remove(sample->de_ping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) debugfs_remove(sample->de_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) debugfs_remove(sample->de_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) qmi_handle_release(&sample->qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) static struct platform_driver qmi_sample_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) .probe = qmi_sample_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) .remove = qmi_sample_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) .name = "qmi_sample_client",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) static int qmi_sample_new_server(struct qmi_handle *qmi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) struct qmi_service *service)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) struct sockaddr_qrtr sq = { AF_QIPCRTR, service->node, service->port };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) pdev = platform_device_alloc("qmi_sample_client", PLATFORM_DEVID_AUTO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (!pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) ret = platform_device_add_data(pdev, &sq, sizeof(sq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) goto err_put_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) ret = platform_device_add(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) goto err_put_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) service->priv = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) err_put_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) platform_device_put(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static void qmi_sample_del_server(struct qmi_handle *qmi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) struct qmi_service *service)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) struct platform_device *pdev = service->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) platform_device_unregister(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static struct qmi_handle lookup_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static struct qmi_ops lookup_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) .new_server = qmi_sample_new_server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) .del_server = qmi_sample_del_server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static int qmi_sample_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) qmi_debug_dir = debugfs_create_dir("qmi_sample", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (IS_ERR(qmi_debug_dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) pr_err("failed to create qmi_sample dir\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return PTR_ERR(qmi_debug_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) ret = platform_driver_register(&qmi_sample_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) goto err_remove_debug_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) ret = qmi_handle_init(&lookup_client, 0, &lookup_ops, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) goto err_unregister_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) qmi_add_lookup(&lookup_client, 15, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) err_unregister_driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) platform_driver_unregister(&qmi_sample_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) err_remove_debug_dir:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) debugfs_remove(qmi_debug_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static void qmi_sample_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) qmi_handle_release(&lookup_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) platform_driver_unregister(&qmi_sample_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) debugfs_remove(qmi_debug_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) module_init(qmi_sample_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) module_exit(qmi_sample_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) MODULE_DESCRIPTION("Sample QMI client driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) MODULE_LICENSE("GPL v2");