/** * DOC: AP/Modem QMI Handshake * * The AP and modem perform a "handshake" at initialization time to ensure * both sides know when everything is ready to begin operating. The AP * driver (this code) uses two QMI handles (endpoints) for this; a client * using a service on the modem, and server to service modem requests (and * to supply an indication message from the AP). Once the handshake is * complete, the AP and modem may begin IPA operation. This occurs * only when the AP IPA driver, modem IPA driver, and IPA microcontroller * are ready. * * The QMI service on the modem expects to receive an INIT_DRIVER request from * the AP, which contains parameters used by the modem during initialization. * The AP sends this request as soon as it is knows the modem side service * is available. The modem responds to this request, and if this response * contains a success result, the AP knows the modem IPA driver is ready. * * The modem is responsible for loading firmware on the IPA microcontroller. * This occurs only during the initial modem boot. The modem sends a * separate DRIVER_INIT_COMPLETE request to the AP to report that the * microcontroller is ready. The AP may assume the microcontroller is * ready and remain so (even if the modem reboots) once it has received * and responded to this request. * * There is one final exchange involved in the handshake. It is required * on the initial modem boot, but optional (but in practice does occur) on * subsequent boots. The modem expects to receive a final INIT_COMPLETE * indication message from the AP when it is about to begin its normal * operation. The AP will only send this message after it has received * and responded to an INDICATION_REGISTER request from the modem. * * So in summary: * - Whenever the AP learns the modem has booted and its IPA QMI service * is available, it sends an INIT_DRIVER request to the modem. The * modem supplies a success response when it is ready to operate. * - On the initial boot, the modem sets up the IPA microcontroller, and * sends a DRIVER_INIT_COMPLETE request to the AP when this is done. * - When the modem is ready to receive an INIT_COMPLETE indication from * the AP, it sends an INDICATION_REGISTER request to the AP. * - On the initial modem boot, everything is ready when: * - AP has received a success response from its INIT_DRIVER request * - AP has responded to a DRIVER_INIT_COMPLETE request * - AP has responded to an INDICATION_REGISTER request from the modem * - AP has sent an INIT_COMPLETE indication to the modem * - On subsequent modem boots, everything is ready when: * - AP has received a success response from its INIT_DRIVER request * - AP has responded to a DRIVER_INIT_COMPLETE request * - The INDICATION_REGISTER request and INIT_COMPLETE indication are * optional for non-initial modem boots, and have no bearing on the * determination of when things are "ready"
*/
/* If requested (and not already sent) send the INIT_COMPLETE indication */ staticvoid ipa_qmi_indication(struct ipa_qmi *ipa_qmi)
{ if (!ipa_qmi->indication_requested) return;
if (ipa_qmi->indication_sent) return;
ipa_server_init_complete(ipa_qmi);
}
/* Determine whether everything is ready to start normal operation. * We know everything (else) is ready when we know the IPA driver on * the modem is ready, and the microcontroller is ready. * * When the modem boots (or reboots), the handshake sequence starts * with the AP sending the modem an INIT_DRIVER request. Within * that request, the uc_loaded flag will be zero (false) for an * initial boot, non-zero (true) for a subsequent (SSR) boot.
*/ staticvoid ipa_qmi_ready(struct ipa_qmi *ipa_qmi)
{ struct ipa *ipa; int ret;
/* We aren't ready until the modem and microcontroller are */ if (!ipa_qmi->modem_ready || !ipa_qmi->uc_ready) return;
/* Send the indication message if it was requested */
ipa_qmi_indication(ipa_qmi);
/* The initial boot requires us to send the indication. */ if (ipa_qmi->initial_boot) { if (!ipa_qmi->indication_sent) return;
/* We're ready. Start up normal operation */
ipa = container_of(ipa_qmi, struct ipa, qmi);
ret = ipa_modem_start(ipa); if (ret)
dev_err(ipa->dev, "error %d starting modem\n", ret);
}
/* All QMI clients from the modem node are gone (modem shut down or crashed). */ staticvoid ipa_server_bye(struct qmi_handle *qmi, unsignedint node)
{ struct ipa_qmi *ipa_qmi;
/* Callback function to handle an INDICATION_REGISTER request message from the * modem. This informs the AP that the modem is now ready to receive the * INIT_COMPLETE indication message.
*/ staticvoid ipa_server_indication_register(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, struct qmi_txn *txn, constvoid *decoded)
{ struct ipa_indication_register_rsp rsp = { }; struct ipa_qmi *ipa_qmi; struct ipa *ipa; int ret;
ret = qmi_send_response(qmi, sq, txn, IPA_QMI_DRIVER_INIT_COMPLETE,
IPA_QMI_DRIVER_INIT_COMPLETE_RSP_SZ,
ipa_driver_init_complete_rsp_ei, &rsp); if (!ret) {
ipa_qmi->uc_ready = true;
ipa_qmi_ready(ipa_qmi); /* We might be ready now */
} else {
dev_err(ipa->dev, "error %d sending init complete response\n", ret);
}
}
/* The server handles two request message types sent by the modem. */ staticconststruct qmi_msg_handler ipa_server_msg_handlers[] = {
{
.type = QMI_REQUEST,
.msg_id = IPA_QMI_INDICATION_REGISTER,
.ei = ipa_indication_register_req_ei,
.decoded_size = IPA_QMI_INDICATION_REGISTER_REQ_SZ,
.fn = ipa_server_indication_register,
},
{
.type = QMI_REQUEST,
.msg_id = IPA_QMI_DRIVER_INIT_COMPLETE,
.ei = ipa_driver_init_complete_req_ei,
.decoded_size = IPA_QMI_DRIVER_INIT_COMPLETE_REQ_SZ,
.fn = ipa_server_driver_init_complete,
},
{ },
};
/* Handle an INIT_DRIVER response message from the modem. */ staticvoid ipa_client_init_driver(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, struct qmi_txn *txn, constvoid *decoded)
{
txn->result = 0; /* IPA_QMI_INIT_DRIVER request was successful */
complete(&txn->completion);
}
/* The client handles one response message type sent by the modem. */ staticconststruct qmi_msg_handler ipa_client_msg_handlers[] = {
{
.type = QMI_RESPONSE,
.msg_id = IPA_QMI_INIT_DRIVER,
.ei = ipa_init_modem_driver_rsp_ei,
.decoded_size = IPA_QMI_INIT_DRIVER_RSP_SZ,
.fn = ipa_client_init_driver,
},
{ },
};
/* Return a pointer to an init modem driver request structure, which contains * configuration parameters for the modem. The modem may be started multiple * times, but generally these parameters don't change so we can reuse the * request structure once it's initialized. The only exception is the * skip_uc_load field, which will be set only after the microcontroller has * reported it has completed its initialization.
*/ staticconststruct ipa_init_modem_driver_req *
init_modem_driver_req(struct ipa_qmi *ipa_qmi)
{ struct ipa *ipa = container_of(ipa_qmi, struct ipa, qmi);
u32 modem_route_count = ipa->modem_route_count; staticstruct ipa_init_modem_driver_req req; conststruct ipa_mem *mem;
/* The microcontroller is initialized on the first boot */
req.skip_uc_load_valid = 1;
req.skip_uc_load = ipa->uc_loaded ? 1 : 0;
/* We only have to initialize most of it once */ if (req.platform_type_valid) return &req;
mem = ipa_mem_find(ipa, IPA_MEM_V4_FILTER_HASHED); if (mem->size) {
req.v4_hash_filter_tbl_start_valid = 1;
req.v4_hash_filter_tbl_start = ipa->mem_offset + mem->offset;
}
mem = ipa_mem_find(ipa, IPA_MEM_V6_FILTER_HASHED); if (mem->size) {
req.v6_hash_filter_tbl_start_valid = 1;
req.v6_hash_filter_tbl_start = ipa->mem_offset + mem->offset;
}
/* The stats fields are only valid for IPA v4.0+ */ if (ipa->version >= IPA_VERSION_4_0) {
mem = ipa_mem_find(ipa, IPA_MEM_STATS_QUOTA_MODEM); if (mem->size) {
req.hw_stats_quota_base_addr_valid = 1;
req.hw_stats_quota_base_addr =
ipa->mem_offset + mem->offset;
req.hw_stats_quota_size_valid = 1;
req.hw_stats_quota_size = ipa->mem_offset + mem->size;
}
/* If the DROP stats region is defined, include it */
mem = ipa_mem_find(ipa, IPA_MEM_STATS_DROP); if (mem && mem->size) {
req.hw_stats_drop_base_addr_valid = 1;
req.hw_stats_drop_base_addr =
ipa->mem_offset + mem->offset;
req.hw_stats_drop_size_valid = 1;
req.hw_stats_drop_size = ipa->mem_offset + mem->size;
}
}
return &req;
}
/* Send an INIT_DRIVER request to the modem, and wait for it to complete. */ staticvoid ipa_client_init_driver_work(struct work_struct *work)
{ unsignedlong timeout = msecs_to_jiffies(QMI_INIT_DRIVER_TIMEOUT); conststruct ipa_init_modem_driver_req *req; struct ipa_qmi *ipa_qmi; struct qmi_handle *qmi; struct qmi_txn txn; struct device *dev; struct ipa *ipa; int ret;
/* Send the request, and if successful wait for its response */
req = init_modem_driver_req(ipa_qmi);
ret = qmi_send_request(qmi, &ipa_qmi->modem_sq, &txn,
IPA_QMI_INIT_DRIVER, IPA_QMI_INIT_DRIVER_REQ_SZ,
ipa_init_modem_driver_req_ei, req); if (ret)
dev_err(dev, "error %d sending init driver request\n", ret); elseif ((ret = qmi_txn_wait(&txn, timeout)))
dev_err(dev, "error %d awaiting init driver response\n", ret);
if (!ret) {
ipa_qmi->modem_ready = true;
ipa_qmi_ready(ipa_qmi); /* We might be ready now */
} else { /* If any error occurs we need to cancel the transaction */
qmi_txn_cancel(&txn);
}
}
/* The modem server is now available. We will send an INIT_DRIVER request * to the modem, but can't wait for it to complete in this callback thread. * Schedule a worker on the global workqueue to do that for us.
*/ staticint
ipa_client_new_server(struct qmi_handle *qmi, struct qmi_service *svc)
{ struct ipa_qmi *ipa_qmi;
/* Set up for QMI message exchange */ int ipa_qmi_setup(struct ipa *ipa)
{ struct ipa_qmi *ipa_qmi = &ipa->qmi; int ret;
ipa_qmi->initial_boot = true;
/* The server handle is used to handle the DRIVER_INIT_COMPLETE * request on the first modem boot. It also receives the * INDICATION_REGISTER request on the first boot and (optionally) * subsequent boots. The INIT_COMPLETE indication message is * sent over the server handle if requested.
*/
ret = qmi_handle_init(&ipa_qmi->server_handle,
IPA_QMI_SERVER_MAX_RCV_SZ, &ipa_server_ops,
ipa_server_msg_handlers); if (ret) return ret;
ret = qmi_add_server(&ipa_qmi->server_handle, IPA_HOST_SERVICE_SVC_ID,
IPA_HOST_SVC_VERS, IPA_HOST_SERVICE_INS_ID); if (ret) goto err_server_handle_release;
/* The client handle is only used for sending an INIT_DRIVER request * to the modem, and receiving its response message.
*/
ret = qmi_handle_init(&ipa_qmi->client_handle,
IPA_QMI_CLIENT_MAX_RCV_SZ, &ipa_client_ops,
ipa_client_msg_handlers); if (ret) goto err_server_handle_release;
/* We need this ready before the service lookup is added */
INIT_WORK(&ipa_qmi->init_driver_work, ipa_client_init_driver_work);
ret = qmi_add_lookup(&ipa_qmi->client_handle, IPA_MODEM_SERVICE_SVC_ID,
IPA_MODEM_SVC_VERS, IPA_MODEM_SERVICE_INS_ID); if (ret) goto err_client_handle_release;
return 0;
err_client_handle_release: /* Releasing the handle also removes registered lookups */
qmi_handle_release(&ipa_qmi->client_handle);
memset(&ipa_qmi->client_handle, 0, sizeof(ipa_qmi->client_handle));
err_server_handle_release: /* Releasing the handle also removes registered services */
qmi_handle_release(&ipa_qmi->server_handle);
memset(&ipa_qmi->server_handle, 0, sizeof(ipa_qmi->server_handle));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.