^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) /* Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2018-2020 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/qrtr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/soc/qcom/qmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "ipa.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "ipa_endpoint.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "ipa_mem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "ipa_table.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "ipa_modem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "ipa_qmi_msg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * DOC: AP/Modem QMI Handshake
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * The AP and modem perform a "handshake" at initialization time to ensure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * both sides know when everything is ready to begin operating. The AP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * driver (this code) uses two QMI handles (endpoints) for this; a client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * using a service on the modem, and server to service modem requests (and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * to supply an indication message from the AP). Once the handshake is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * complete, the AP and modem may begin IPA operation. This occurs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * only when the AP IPA driver, modem IPA driver, and IPA microcontroller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * are ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * The QMI service on the modem expects to receive an INIT_DRIVER request from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * the AP, which contains parameters used by the modem during initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * The AP sends this request as soon as it is knows the modem side service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * is available. The modem responds to this request, and if this response
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * contains a success result, the AP knows the modem IPA driver is ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * The modem is responsible for loading firmware on the IPA microcontroller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * This occurs only during the initial modem boot. The modem sends a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * separate DRIVER_INIT_COMPLETE request to the AP to report that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * microcontroller is ready. The AP may assume the microcontroller is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * ready and remain so (even if the modem reboots) once it has received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * and responded to this request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * There is one final exchange involved in the handshake. It is required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * on the initial modem boot, but optional (but in practice does occur) on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * subsequent boots. The modem expects to receive a final INIT_COMPLETE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * indication message from the AP when it is about to begin its normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * operation. The AP will only send this message after it has received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * and responded to an INDICATION_REGISTER request from the modem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * So in summary:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * - Whenever the AP learns the modem has booted and its IPA QMI service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * is available, it sends an INIT_DRIVER request to the modem. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * modem supplies a success response when it is ready to operate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * - On the initial boot, the modem sets up the IPA microcontroller, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * sends a DRIVER_INIT_COMPLETE request to the AP when this is done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * - When the modem is ready to receive an INIT_COMPLETE indication from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * the AP, it sends an INDICATION_REGISTER request to the AP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * - On the initial modem boot, everything is ready when:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * - AP has received a success response from its INIT_DRIVER request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * - AP has responded to a DRIVER_INIT_COMPLETE request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * - AP has responded to an INDICATION_REGISTER request from the modem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * - AP has sent an INIT_COMPLETE indication to the modem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * - On subsequent modem boots, everything is ready when:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * - AP has received a success response from its INIT_DRIVER request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * - AP has responded to a DRIVER_INIT_COMPLETE request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * - The INDICATION_REGISTER request and INIT_COMPLETE indication are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * optional for non-initial modem boots, and have no bearing on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * determination of when things are "ready"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define IPA_HOST_SERVICE_SVC_ID 0x31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define IPA_HOST_SVC_VERS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define IPA_HOST_SERVICE_INS_ID 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define IPA_MODEM_SERVICE_SVC_ID 0x31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define IPA_MODEM_SERVICE_INS_ID 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define IPA_MODEM_SVC_VERS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define QMI_INIT_DRIVER_TIMEOUT 60000 /* A minute in milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* Send an INIT_COMPLETE indication message to the modem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static void ipa_server_init_complete(struct ipa_qmi *ipa_qmi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct ipa *ipa = container_of(ipa_qmi, struct ipa, qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct qmi_handle *qmi = &ipa_qmi->server_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct sockaddr_qrtr *sq = &ipa_qmi->modem_sq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct ipa_init_complete_ind ind = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ind.status.result = QMI_RESULT_SUCCESS_V01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ind.status.error = QMI_ERR_NONE_V01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ret = qmi_send_indication(qmi, sq, IPA_QMI_INIT_COMPLETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) IPA_QMI_INIT_COMPLETE_IND_SZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ipa_init_complete_ind_ei, &ind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) dev_err(&ipa->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) "error %d sending init complete indication\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ipa_qmi->indication_sent = true;
^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) /* If requested (and not already sent) send the INIT_COMPLETE indication */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static void ipa_qmi_indication(struct ipa_qmi *ipa_qmi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (!ipa_qmi->indication_requested)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (ipa_qmi->indication_sent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ipa_server_init_complete(ipa_qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* Determine whether everything is ready to start normal operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * We know everything (else) is ready when we know the IPA driver on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * the modem is ready, and the microcontroller is ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * When the modem boots (or reboots), the handshake sequence starts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * with the AP sending the modem an INIT_DRIVER request. Within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * that request, the uc_loaded flag will be zero (false) for an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * initial boot, non-zero (true) for a subsequent (SSR) boot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static void ipa_qmi_ready(struct ipa_qmi *ipa_qmi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct ipa *ipa = container_of(ipa_qmi, struct ipa, qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /* We aren't ready until the modem and microcontroller are */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (!ipa_qmi->modem_ready || !ipa_qmi->uc_ready)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* Send the indication message if it was requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ipa_qmi_indication(ipa_qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /* The initial boot requires us to send the indication. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (ipa_qmi->initial_boot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (!ipa_qmi->indication_sent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* The initial modem boot completed successfully */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ipa_qmi->initial_boot = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* We're ready. Start up normal operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ipa = container_of(ipa_qmi, struct ipa, qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ret = ipa_modem_start(ipa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) dev_err(&ipa->pdev->dev, "error %d starting modem\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* All QMI clients from the modem node are gone (modem shut down or crashed). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static void ipa_server_bye(struct qmi_handle *qmi, unsigned int node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct ipa_qmi *ipa_qmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ipa_qmi = container_of(qmi, struct ipa_qmi, server_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* The modem client and server go away at the same time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) memset(&ipa_qmi->modem_sq, 0, sizeof(ipa_qmi->modem_sq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* initial_boot doesn't change when modem reboots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* uc_ready doesn't change when modem reboots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ipa_qmi->modem_ready = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ipa_qmi->indication_requested = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ipa_qmi->indication_sent = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static struct qmi_ops ipa_server_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) .bye = ipa_server_bye,
^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) /* Callback function to handle an INDICATION_REGISTER request message from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * modem. This informs the AP that the modem is now ready to receive the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * INIT_COMPLETE indication message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static void ipa_server_indication_register(struct qmi_handle *qmi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct sockaddr_qrtr *sq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct qmi_txn *txn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) const void *decoded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct ipa_indication_register_rsp rsp = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct ipa_qmi *ipa_qmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct ipa *ipa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ipa_qmi = container_of(qmi, struct ipa_qmi, server_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ipa = container_of(ipa_qmi, struct ipa, qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) rsp.rsp.result = QMI_RESULT_SUCCESS_V01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) rsp.rsp.error = QMI_ERR_NONE_V01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ret = qmi_send_response(qmi, sq, txn, IPA_QMI_INDICATION_REGISTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) IPA_QMI_INDICATION_REGISTER_RSP_SZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ipa_indication_register_rsp_ei, &rsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ipa_qmi->indication_requested = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ipa_qmi_ready(ipa_qmi); /* We might be ready now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) dev_err(&ipa->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) "error %d sending register indication response\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* Respond to a DRIVER_INIT_COMPLETE request message from the modem. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static void ipa_server_driver_init_complete(struct qmi_handle *qmi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct sockaddr_qrtr *sq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct qmi_txn *txn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) const void *decoded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct ipa_driver_init_complete_rsp rsp = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct ipa_qmi *ipa_qmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct ipa *ipa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) ipa_qmi = container_of(qmi, struct ipa_qmi, server_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ipa = container_of(ipa_qmi, struct ipa, qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) rsp.rsp.result = QMI_RESULT_SUCCESS_V01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) rsp.rsp.error = QMI_ERR_NONE_V01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ret = qmi_send_response(qmi, sq, txn, IPA_QMI_DRIVER_INIT_COMPLETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) IPA_QMI_DRIVER_INIT_COMPLETE_RSP_SZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ipa_driver_init_complete_rsp_ei, &rsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) ipa_qmi->uc_ready = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) ipa_qmi_ready(ipa_qmi); /* We might be ready now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) dev_err(&ipa->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) "error %d sending init complete response\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* The server handles two request message types sent by the modem. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static struct qmi_msg_handler ipa_server_msg_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .type = QMI_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .msg_id = IPA_QMI_INDICATION_REGISTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .ei = ipa_indication_register_req_ei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .decoded_size = IPA_QMI_INDICATION_REGISTER_REQ_SZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .fn = ipa_server_indication_register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .type = QMI_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .msg_id = IPA_QMI_DRIVER_INIT_COMPLETE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) .ei = ipa_driver_init_complete_req_ei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) .decoded_size = IPA_QMI_DRIVER_INIT_COMPLETE_REQ_SZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .fn = ipa_server_driver_init_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* Handle an INIT_DRIVER response message from the modem. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static void ipa_client_init_driver(struct qmi_handle *qmi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct sockaddr_qrtr *sq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct qmi_txn *txn, const void *decoded)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) txn->result = 0; /* IPA_QMI_INIT_DRIVER request was successful */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) complete(&txn->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /* The client handles one response message type sent by the modem. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static struct qmi_msg_handler ipa_client_msg_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .type = QMI_RESPONSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) .msg_id = IPA_QMI_INIT_DRIVER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) .ei = ipa_init_modem_driver_rsp_ei,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .decoded_size = IPA_QMI_INIT_DRIVER_RSP_SZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .fn = ipa_client_init_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) },
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* Return a pointer to an init modem driver request structure, which contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * configuration parameters for the modem. The modem may be started multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * times, but generally these parameters don't change so we can reuse the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * request structure once it's initialized. The only exception is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * skip_uc_load field, which will be set only after the microcontroller has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * reported it has completed its initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static const struct ipa_init_modem_driver_req *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) init_modem_driver_req(struct ipa_qmi *ipa_qmi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct ipa *ipa = container_of(ipa_qmi, struct ipa, qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static struct ipa_init_modem_driver_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) const struct ipa_mem *mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* The microcontroller is initialized on the first boot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) req.skip_uc_load_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) req.skip_uc_load = ipa->uc_loaded ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /* We only have to initialize most of it once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (req.platform_type_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return &req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) req.platform_type_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) req.platform_type = IPA_QMI_PLATFORM_TYPE_MSM_ANDROID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) mem = &ipa->mem[IPA_MEM_MODEM_HEADER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (mem->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) req.hdr_tbl_info_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) req.hdr_tbl_info.start = ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) req.hdr_tbl_info.end = req.hdr_tbl_info.start + mem->size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) mem = &ipa->mem[IPA_MEM_V4_ROUTE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) req.v4_route_tbl_info_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) req.v4_route_tbl_info.start = ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) req.v4_route_tbl_info.count = mem->size / IPA_TABLE_ENTRY_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) mem = &ipa->mem[IPA_MEM_V6_ROUTE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) req.v6_route_tbl_info_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) req.v6_route_tbl_info.start = ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) req.v6_route_tbl_info.count = mem->size / IPA_TABLE_ENTRY_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) mem = &ipa->mem[IPA_MEM_V4_FILTER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) req.v4_filter_tbl_start_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) req.v4_filter_tbl_start = ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) mem = &ipa->mem[IPA_MEM_V6_FILTER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) req.v6_filter_tbl_start_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) req.v6_filter_tbl_start = ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) mem = &ipa->mem[IPA_MEM_MODEM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (mem->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) req.modem_mem_info_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) req.modem_mem_info.start = ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) req.modem_mem_info.size = mem->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) req.ctrl_comm_dest_end_pt_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) req.ctrl_comm_dest_end_pt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]->endpoint_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* skip_uc_load_valid and skip_uc_load are set above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) mem = &ipa->mem[IPA_MEM_MODEM_PROC_CTX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (mem->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) req.hdr_proc_ctx_tbl_info_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) req.hdr_proc_ctx_tbl_info.start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) req.hdr_proc_ctx_tbl_info.end =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) req.hdr_proc_ctx_tbl_info.start + mem->size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* Nothing to report for the compression table (zip_tbl_info) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) mem = &ipa->mem[IPA_MEM_V4_ROUTE_HASHED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (mem->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) req.v4_hash_route_tbl_info_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) req.v4_hash_route_tbl_info.start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) req.v4_hash_route_tbl_info.count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) mem->size / IPA_TABLE_ENTRY_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) mem = &ipa->mem[IPA_MEM_V6_ROUTE_HASHED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (mem->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) req.v6_hash_route_tbl_info_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) req.v6_hash_route_tbl_info.start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) req.v6_hash_route_tbl_info.count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) mem->size / IPA_TABLE_ENTRY_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) mem = &ipa->mem[IPA_MEM_V4_FILTER_HASHED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (mem->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) req.v4_hash_filter_tbl_start_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) req.v4_hash_filter_tbl_start = ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) mem = &ipa->mem[IPA_MEM_V6_FILTER_HASHED];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (mem->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) req.v6_hash_filter_tbl_start_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) req.v6_hash_filter_tbl_start = ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) /* None of the stats fields are valid (IPA v4.0 and above) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (ipa->version != IPA_VERSION_3_5_1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) mem = &ipa->mem[IPA_MEM_STATS_QUOTA];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (mem->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) req.hw_stats_quota_base_addr_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) req.hw_stats_quota_base_addr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) req.hw_stats_quota_size_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) req.hw_stats_quota_size = ipa->mem_offset + mem->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) mem = &ipa->mem[IPA_MEM_STATS_DROP];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (mem->size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) req.hw_stats_drop_base_addr_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) req.hw_stats_drop_base_addr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) ipa->mem_offset + mem->offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) req.hw_stats_drop_size_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) req.hw_stats_drop_size = ipa->mem_offset + mem->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return &req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* Send an INIT_DRIVER request to the modem, and wait for it to complete. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static void ipa_client_init_driver_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) unsigned long timeout = msecs_to_jiffies(QMI_INIT_DRIVER_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) const struct ipa_init_modem_driver_req *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) struct ipa_qmi *ipa_qmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct qmi_handle *qmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct qmi_txn txn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) struct ipa *ipa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) ipa_qmi = container_of(work, struct ipa_qmi, init_driver_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) qmi = &ipa_qmi->client_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) ipa = container_of(ipa_qmi, struct ipa, qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) dev = &ipa->pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) ret = qmi_txn_init(qmi, &txn, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) dev_err(dev, "error %d preparing init driver request\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /* Send the request, and if successful wait for its response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) req = init_modem_driver_req(ipa_qmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) ret = qmi_send_request(qmi, &ipa_qmi->modem_sq, &txn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) IPA_QMI_INIT_DRIVER, IPA_QMI_INIT_DRIVER_REQ_SZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) ipa_init_modem_driver_req_ei, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) dev_err(dev, "error %d sending init driver request\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) else if ((ret = qmi_txn_wait(&txn, timeout)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) dev_err(dev, "error %d awaiting init driver response\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) ipa_qmi->modem_ready = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) ipa_qmi_ready(ipa_qmi); /* We might be ready now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) /* If any error occurs we need to cancel the transaction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) qmi_txn_cancel(&txn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /* The modem server is now available. We will send an INIT_DRIVER request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * to the modem, but can't wait for it to complete in this callback thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * Schedule a worker on the global workqueue to do that for us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) ipa_client_new_server(struct qmi_handle *qmi, struct qmi_service *svc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct ipa_qmi *ipa_qmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) ipa_qmi = container_of(qmi, struct ipa_qmi, client_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) ipa_qmi->modem_sq.sq_family = AF_QIPCRTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) ipa_qmi->modem_sq.sq_node = svc->node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) ipa_qmi->modem_sq.sq_port = svc->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) schedule_work(&ipa_qmi->init_driver_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static struct qmi_ops ipa_client_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) .new_server = ipa_client_new_server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /* This is called by ipa_setup(). We can be informed via remoteproc that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * the modem has shut down, in which case this function will be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * again to prepare for it coming back up again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) int ipa_qmi_setup(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct ipa_qmi *ipa_qmi = &ipa->qmi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) ipa_qmi->initial_boot = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /* The server handle is used to handle the DRIVER_INIT_COMPLETE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * request on the first modem boot. It also receives the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * INDICATION_REGISTER request on the first boot and (optionally)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * subsequent boots. The INIT_COMPLETE indication message is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) * sent over the server handle if requested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) ret = qmi_handle_init(&ipa_qmi->server_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) IPA_QMI_SERVER_MAX_RCV_SZ, &ipa_server_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) ipa_server_msg_handlers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) ret = qmi_add_server(&ipa_qmi->server_handle, IPA_HOST_SERVICE_SVC_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) IPA_HOST_SVC_VERS, IPA_HOST_SERVICE_INS_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) goto err_server_handle_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /* The client handle is only used for sending an INIT_DRIVER request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * to the modem, and receiving its response message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) ret = qmi_handle_init(&ipa_qmi->client_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) IPA_QMI_CLIENT_MAX_RCV_SZ, &ipa_client_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) ipa_client_msg_handlers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) goto err_server_handle_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /* We need this ready before the service lookup is added */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) INIT_WORK(&ipa_qmi->init_driver_work, ipa_client_init_driver_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) ret = qmi_add_lookup(&ipa_qmi->client_handle, IPA_MODEM_SERVICE_SVC_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) IPA_MODEM_SVC_VERS, IPA_MODEM_SERVICE_INS_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) goto err_client_handle_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) err_client_handle_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /* Releasing the handle also removes registered lookups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) qmi_handle_release(&ipa_qmi->client_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) memset(&ipa_qmi->client_handle, 0, sizeof(ipa_qmi->client_handle));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) err_server_handle_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) /* Releasing the handle also removes registered services */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) qmi_handle_release(&ipa_qmi->server_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) memset(&ipa_qmi->server_handle, 0, sizeof(ipa_qmi->server_handle));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) void ipa_qmi_teardown(struct ipa *ipa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) cancel_work_sync(&ipa->qmi.init_driver_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) qmi_handle_release(&ipa->qmi.client_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) memset(&ipa->qmi.client_handle, 0, sizeof(ipa->qmi.client_handle));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) qmi_handle_release(&ipa->qmi.server_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) memset(&ipa->qmi.server_handle, 0, sizeof(ipa->qmi.server_handle));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }