#define SAHARA_HELLO_CMD 0x1 /* Min protocol version 1.0 */ #define SAHARA_HELLO_RESP_CMD 0x2 /* Min protocol version 1.0 */ #define SAHARA_READ_DATA_CMD 0x3 /* Min protocol version 1.0 */ #define SAHARA_END_OF_IMAGE_CMD 0x4 /* Min protocol version 1.0 */ #define SAHARA_DONE_CMD 0x5 /* Min protocol version 1.0 */ #define SAHARA_DONE_RESP_CMD 0x6 /* Min protocol version 1.0 */ #define SAHARA_RESET_CMD 0x7 /* Min protocol version 1.0 */ #define SAHARA_RESET_RESP_CMD 0x8 /* Min protocol version 1.0 */ #define SAHARA_MEM_DEBUG_CMD 0x9 /* Min protocol version 2.0 */ #define SAHARA_MEM_READ_CMD 0xa /* Min protocol version 2.0 */ #define SAHARA_CMD_READY_CMD 0xb /* Min protocol version 2.1 */ #define SAHARA_SWITCH_MODE_CMD 0xc /* Min protocol version 2.1 */ #define SAHARA_EXECUTE_CMD 0xd /* Min protocol version 2.1 */ #define SAHARA_EXECUTE_RESP_CMD 0xe /* Min protocol version 2.1 */ #define SAHARA_EXECUTE_DATA_CMD 0xf /* Min protocol version 2.1 */ #define SAHARA_MEM_DEBUG64_CMD 0x10 /* Min protocol version 2.5 */ #define SAHARA_MEM_READ64_CMD 0x11 /* Min protocol version 2.5 */ #define SAHARA_READ_DATA64_CMD 0x12 /* Min protocol version 2.8 */ #define SAHARA_RESET_STATE_CMD 0x13 /* Min protocol version 2.9 */ #define SAHARA_WRITE_DATA_CMD 0x14 /* Min protocol version 3.0 */
/* * Layout of crashdump provided to user via devcoredump * +------------------------------------------+ * | Crashdump Meta structure | * | type: struct sahara_memory_dump_meta_v1 | * +------------------------------------------+ * | Crashdump Table | * | type: array of struct | * | sahara_dump_table_entry | * | | * | | * +------------------------------------------+ * | Crashdump | * | | * | | * | | * | | * | | * +------------------------------------------+ * * First is the metadata header. Userspace can use the magic number to verify * the content type, and then check the version for the rest of the format. * New versions should keep the magic number location/value, and version * location, but increment the version value. * * For v1, the metadata lists the size of the entire dump (header + table + * dump) and the size of the table. Then the dump image table, which describes * the contents of the dump. Finally all the images are listed in order, with * no deadspace in between. Userspace can use the sizes listed in the image * table to reconstruct the individual images.
*/
staticint sahara_find_image(struct sahara_context *context, u32 image_id)
{ int ret;
if (image_id == context->active_image_id) return 0;
if (context->active_image_id != SAHARA_IMAGE_ID_NONE) {
dev_err(&context->mhi_dev->dev, "image id %d is not valid as %d is active\n",
image_id, context->active_image_id); return -EINVAL;
}
if (image_id >= context->table_size || !context->image_table[image_id]) {
dev_err(&context->mhi_dev->dev, "request for unknown image: %d\n", image_id); return -EINVAL;
}
/* * This image might be optional. The device may continue without it. * Only the device knows. Suppress error messages that could suggest an * a problem when we were actually able to continue.
*/
ret = firmware_request_nowarn(&context->firmware,
context->image_table[image_id],
&context->mhi_dev->dev); if (ret) {
dev_dbg(&context->mhi_dev->dev, "request for image id %d / file %s failed %d\n",
image_id, context->image_table[image_id], ret); return ret;
}
ret = sahara_find_image(context, image_id); if (ret) {
sahara_send_reset(context); return;
}
/* * Image is released when the device is done with it via * SAHARA_END_OF_IMAGE_CMD. sahara_send_reset() will either cause the * device to retry the operation with a modification, or decide to be * done with the image and trigger SAHARA_END_OF_IMAGE_CMD. * release_image() is called from SAHARA_END_OF_IMAGE_CMD. processing * and is not needed here on error.
*/
if (data_len > SAHARA_TRANSFER_MAX_SIZE) {
dev_err(&context->mhi_dev->dev, "Malformed read_data packet - data len %d exceeds max xfer size %d\n",
data_len, SAHARA_TRANSFER_MAX_SIZE);
sahara_send_reset(context); return;
}
if (context->active_image_id != SAHARA_IMAGE_ID_NONE &&
le32_to_cpu(context->rx->end_of_image.image) != context->active_image_id) {
dev_err(&context->mhi_dev->dev, "Malformed end_of_image packet - image %d is not the active image\n",
le32_to_cpu(context->rx->end_of_image.image)); return;
}
sahara_release_image(context);
if (le32_to_cpu(context->rx->end_of_image.status)) return;
/* * From this point, the protocol flips. We make memory_read requests to * the device, and the device responds with the raw data. If the device * has an error, it will send an End of Image command. First we need to * request the memory dump table so that we know where all the pieces * of the dump are that we can consume.
*/
context->is_mem_dump_mode = true;
/* * Assume that the table is smaller than our MTU so that we can read it * in one shot. The spec does not put an upper limit on the table, but * no known device will exceed this.
*/ if (context->dump_table_length > SAHARA_PACKET_MAX_SIZE) {
dev_err(&context->mhi_dev->dev, "Memory dump table length %lld exceeds supported size. Discarding dump\n",
context->dump_table_length);
sahara_send_reset(context); return;
}
ret = mhi_queue_buf(context->mhi_dev, DMA_TO_DEVICE, context->tx[0],
SAHARA_MEM_READ64_LENGTH, MHI_EOT); if (ret)
dev_err(&context->mhi_dev->dev, "Unable to send read for dump table %d\n", ret);
}
switch (le32_to_cpu(context->rx->cmd)) { case SAHARA_HELLO_CMD:
sahara_hello(context); break; case SAHARA_READ_DATA_CMD:
sahara_read_data(context); break; case SAHARA_END_OF_IMAGE_CMD:
sahara_end_of_image(context); break; case SAHARA_DONE_RESP_CMD: /* Intentional do nothing as we don't need to exit an app */ break; case SAHARA_RESET_RESP_CMD: /* Intentional do nothing as we don't need to exit an app */ break; case SAHARA_MEM_DEBUG64_CMD:
sahara_memory_debug64(context); break; default:
dev_err(&context->mhi_dev->dev, "Unknown command %d\n",
le32_to_cpu(context->rx->cmd)); break;
}
ret = mhi_queue_buf(context->mhi_dev, DMA_FROM_DEVICE, context->rx,
SAHARA_PACKET_MAX_SIZE, MHI_EOT); if (ret)
dev_err(&context->mhi_dev->dev, "Unable to requeue rx buf %d\n", ret);
}
dev_table = (struct sahara_debug_table_entry64 *)(context->rx); for (i = 0; i < table_nents; ++i) { /* Do not trust the device, ensure the strings are terminated */
dev_table[i].description[SAHARA_TABLE_ENTRY_STR_LEN - 1] = 0;
dev_table[i].filename[SAHARA_TABLE_ENTRY_STR_LEN - 1] = 0;
dump_length = size_add(dump_length, le64_to_cpu(dev_table[i].length)); if (dump_length == SIZE_MAX) { /* Discard the dump */
sahara_send_reset(context); return;
}
/* Done parsing the table, switch to image dump mode */
context->dump_table_length = 0;
/* Request the first chunk of the first image */
context->dump_image = &image_out_table[0];
dump_length = min(context->dump_image->length, SAHARA_READ_MAX_SIZE); /* Avoid requesting EOI sized data so that we can identify errors */ if (dump_length == SAHARA_END_OF_IMAGE_LENGTH)
dump_length = SAHARA_END_OF_IMAGE_LENGTH / 2;
ret = mhi_queue_buf(context->mhi_dev, DMA_TO_DEVICE, context->tx[0],
SAHARA_MEM_READ64_LENGTH, MHI_EOT); if (ret)
dev_err(&context->mhi_dev->dev, "Unable to send read for dump content %d\n", ret);
}
staticvoid sahara_parse_dump_image(struct sahara_context *context)
{
u64 dump_length; int ret;
if (context->dump_image_offset >= context->dump_image->length) { /* Need to move to next image */
context->dump_image++;
context->dump_images_left--;
context->dump_image_offset = 0;
/* Get next image chunk */
dump_length = context->dump_image->length - context->dump_image_offset;
dump_length = min(dump_length, SAHARA_READ_MAX_SIZE); /* Avoid requesting EOI sized data so that we can identify errors */ if (dump_length == SAHARA_END_OF_IMAGE_LENGTH)
dump_length = SAHARA_END_OF_IMAGE_LENGTH / 2;
ret = mhi_queue_buf(context->mhi_dev, DMA_TO_DEVICE, context->tx[0],
SAHARA_MEM_READ64_LENGTH, MHI_EOT); if (ret)
dev_err(&context->mhi_dev->dev, "Unable to send read for dump content %d\n", ret);
}
/* * We should get the expected raw data, but if the device has an error * it is supposed to send EOI with an error code.
*/ if (context->rx_size != context->rx_size_requested &&
context->rx_size != SAHARA_END_OF_IMAGE_LENGTH) {
dev_err(&context->mhi_dev->dev, "Unexpected response to read_data. Expected size: %#zx got: %#zx\n",
context->rx_size_requested,
context->rx_size); goto error;
}
/* * Need to know if we received the dump table, or part of a dump image. * Since we get raw data, we cannot tell from the data itself. Instead, * we use the stored dump_table_length, which we zero after we read and * process the entire table.
*/ if (context->dump_table_length)
sahara_parse_dump_table(context); else
sahara_parse_dump_image(context);
ret = mhi_queue_buf(context->mhi_dev, DMA_FROM_DEVICE, context->rx,
SAHARA_PACKET_MAX_SIZE, MHI_EOT); if (ret)
dev_err(&context->mhi_dev->dev, "Unable to requeue rx buf %d\n", ret);
staticint sahara_mhi_probe(struct mhi_device *mhi_dev, conststruct mhi_device_id *id)
{ struct sahara_context *context; int ret; int i;
context = devm_kzalloc(&mhi_dev->dev, sizeof(*context), GFP_KERNEL); if (!context) return -ENOMEM;
context->rx = devm_kzalloc(&mhi_dev->dev, SAHARA_PACKET_MAX_SIZE, GFP_KERNEL); if (!context->rx) return -ENOMEM;
/* * AIC100 defines SAHARA_TRANSFER_MAX_SIZE as the largest value it * will request for READ_DATA. This is larger than * SAHARA_PACKET_MAX_SIZE, and we need 9x SAHARA_PACKET_MAX_SIZE to * cover SAHARA_TRANSFER_MAX_SIZE. When the remote side issues a * READ_DATA, it requires a transfer of the exact size requested. We * can use MHI_CHAIN to link multiple buffers into a single transfer * but the remote side will not consume the buffers until it sees an * EOT, thus we need to allocate enough buffers to put in the tx fifo * to cover an entire READ_DATA request of the max size.
*/ for (i = 0; i < SAHARA_NUM_TX_BUF; ++i) {
context->tx[i] = devm_kzalloc(&mhi_dev->dev, SAHARA_PACKET_MAX_SIZE, GFP_KERNEL); if (!context->tx[i]) return -ENOMEM;
}
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.