Lines Matching full:context

108 static int sahara_find_image(struct sahara_context *context, u32 image_id)  in sahara_find_image()  argument
112 if (image_id == context->active_image_id) in sahara_find_image()
115 if (context->active_image_id != SAHARA_IMAGE_ID_NONE) { in sahara_find_image()
116 dev_err(&context->mhi_dev->dev, "image id %d is not valid as %d is active\n", in sahara_find_image()
117 image_id, context->active_image_id); in sahara_find_image()
121 if (image_id >= context->table_size || !context->image_table[image_id]) { in sahara_find_image()
122 dev_err(&context->mhi_dev->dev, "request for unknown image: %d\n", image_id); in sahara_find_image()
131 ret = firmware_request_nowarn(&context->firmware, in sahara_find_image()
132 context->image_table[image_id], in sahara_find_image()
133 &context->mhi_dev->dev); in sahara_find_image()
135 dev_dbg(&context->mhi_dev->dev, "request for image id %d / file %s failed %d\n", in sahara_find_image()
136 image_id, context->image_table[image_id], ret); in sahara_find_image()
140 context->active_image_id = image_id; in sahara_find_image()
145 static void sahara_release_image(struct sahara_context *context) in sahara_release_image() argument
147 if (context->active_image_id != SAHARA_IMAGE_ID_NONE) in sahara_release_image()
148 release_firmware(context->firmware); in sahara_release_image()
149 context->active_image_id = SAHARA_IMAGE_ID_NONE; in sahara_release_image()
152 static void sahara_send_reset(struct sahara_context *context) in sahara_send_reset() argument
156 context->tx[0]->cmd = cpu_to_le32(SAHARA_RESET_CMD); in sahara_send_reset()
157 context->tx[0]->length = cpu_to_le32(SAHARA_RESET_LENGTH); in sahara_send_reset()
159 ret = mhi_queue_buf(context->mhi_dev, DMA_TO_DEVICE, context->tx[0], in sahara_send_reset()
162 dev_err(&context->mhi_dev->dev, "Unable to send reset response %d\n", ret); in sahara_send_reset()
165 static void sahara_hello(struct sahara_context *context) in sahara_hello() argument
169 dev_dbg(&context->mhi_dev->dev, in sahara_hello()
171 le32_to_cpu(context->rx->length), in sahara_hello()
172 le32_to_cpu(context->rx->hello.version), in sahara_hello()
173 le32_to_cpu(context->rx->hello.version_compat), in sahara_hello()
174 le32_to_cpu(context->rx->hello.max_length), in sahara_hello()
175 le32_to_cpu(context->rx->hello.mode)); in sahara_hello()
177 if (le32_to_cpu(context->rx->length) != SAHARA_HELLO_LENGTH) { in sahara_hello()
178 dev_err(&context->mhi_dev->dev, "Malformed hello packet - length %d\n", in sahara_hello()
179 le32_to_cpu(context->rx->length)); in sahara_hello()
182 if (le32_to_cpu(context->rx->hello.version) != SAHARA_VERSION) { in sahara_hello()
183 dev_err(&context->mhi_dev->dev, "Unsupported hello packet - version %d\n", in sahara_hello()
184 le32_to_cpu(context->rx->hello.version)); in sahara_hello()
188 if (le32_to_cpu(context->rx->hello.mode) != SAHARA_MODE_IMAGE_TX_PENDING && in sahara_hello()
189 le32_to_cpu(context->rx->hello.mode) != SAHARA_MODE_IMAGE_TX_COMPLETE) { in sahara_hello()
190 dev_err(&context->mhi_dev->dev, "Unsupported hello packet - mode %d\n", in sahara_hello()
191 le32_to_cpu(context->rx->hello.mode)); in sahara_hello()
195 context->tx[0]->cmd = cpu_to_le32(SAHARA_HELLO_RESP_CMD); in sahara_hello()
196 context->tx[0]->length = cpu_to_le32(SAHARA_HELLO_LENGTH); in sahara_hello()
197 context->tx[0]->hello_resp.version = cpu_to_le32(SAHARA_VERSION); in sahara_hello()
198 context->tx[0]->hello_resp.version_compat = cpu_to_le32(SAHARA_VERSION); in sahara_hello()
199 context->tx[0]->hello_resp.status = cpu_to_le32(SAHARA_SUCCESS); in sahara_hello()
200 context->tx[0]->hello_resp.mode = context->rx->hello_resp.mode; in sahara_hello()
202 ret = mhi_queue_buf(context->mhi_dev, DMA_TO_DEVICE, context->tx[0], in sahara_hello()
205 dev_err(&context->mhi_dev->dev, "Unable to send hello response %d\n", ret); in sahara_hello()
208 static void sahara_read_data(struct sahara_context *context) in sahara_read_data() argument
214 dev_dbg(&context->mhi_dev->dev, in sahara_read_data()
216 le32_to_cpu(context->rx->length), in sahara_read_data()
217 le32_to_cpu(context->rx->read_data.image), in sahara_read_data()
218 le32_to_cpu(context->rx->read_data.offset), in sahara_read_data()
219 le32_to_cpu(context->rx->read_data.length)); in sahara_read_data()
221 if (le32_to_cpu(context->rx->length) != SAHARA_READ_DATA_LENGTH) { in sahara_read_data()
222 dev_err(&context->mhi_dev->dev, "Malformed read_data packet - length %d\n", in sahara_read_data()
223 le32_to_cpu(context->rx->length)); in sahara_read_data()
227 image_id = le32_to_cpu(context->rx->read_data.image); in sahara_read_data()
228 data_offset = le32_to_cpu(context->rx->read_data.offset); in sahara_read_data()
229 data_len = le32_to_cpu(context->rx->read_data.length); in sahara_read_data()
231 ret = sahara_find_image(context, image_id); in sahara_read_data()
233 sahara_send_reset(context); in sahara_read_data()
247 …dev_err(&context->mhi_dev->dev, "Malformed read_data packet - data len %d exceeds max xfer size %d… in sahara_read_data()
249 sahara_send_reset(context); in sahara_read_data()
253 if (data_offset >= context->firmware->size) { in sahara_read_data()
254 …dev_err(&context->mhi_dev->dev, "Malformed read_data packet - data offset %d exceeds file size %zu… in sahara_read_data()
255 data_offset, context->firmware->size); in sahara_read_data()
256 sahara_send_reset(context); in sahara_read_data()
260 if (size_add(data_offset, data_len) > context->firmware->size) { in sahara_read_data()
261 …dev_err(&context->mhi_dev->dev, "Malformed read_data packet - data offset %d and length %d exceeds… in sahara_read_data()
262 data_offset, data_len, context->firmware->size); in sahara_read_data()
263 sahara_send_reset(context); in sahara_read_data()
270 memcpy(context->tx[i], &context->firmware->data[data_offset], pkt_data_len); in sahara_read_data()
275 ret = mhi_queue_buf(context->mhi_dev, DMA_TO_DEVICE, in sahara_read_data()
276 context->tx[i], pkt_data_len, in sahara_read_data()
279 dev_err(&context->mhi_dev->dev, "Unable to send read_data response %d\n", in sahara_read_data()
286 static void sahara_end_of_image(struct sahara_context *context) in sahara_end_of_image() argument
290 dev_dbg(&context->mhi_dev->dev, in sahara_end_of_image()
292 le32_to_cpu(context->rx->length), in sahara_end_of_image()
293 le32_to_cpu(context->rx->end_of_image.image), in sahara_end_of_image()
294 le32_to_cpu(context->rx->end_of_image.status)); in sahara_end_of_image()
296 if (le32_to_cpu(context->rx->length) != SAHARA_END_OF_IMAGE_LENGTH) { in sahara_end_of_image()
297 dev_err(&context->mhi_dev->dev, "Malformed end_of_image packet - length %d\n", in sahara_end_of_image()
298 le32_to_cpu(context->rx->length)); in sahara_end_of_image()
302 if (context->active_image_id != SAHARA_IMAGE_ID_NONE && in sahara_end_of_image()
303 le32_to_cpu(context->rx->end_of_image.image) != context->active_image_id) { in sahara_end_of_image()
304 …dev_err(&context->mhi_dev->dev, "Malformed end_of_image packet - image %d is not the active image\… in sahara_end_of_image()
305 le32_to_cpu(context->rx->end_of_image.image)); in sahara_end_of_image()
309 sahara_release_image(context); in sahara_end_of_image()
311 if (le32_to_cpu(context->rx->end_of_image.status)) in sahara_end_of_image()
314 context->tx[0]->cmd = cpu_to_le32(SAHARA_DONE_CMD); in sahara_end_of_image()
315 context->tx[0]->length = cpu_to_le32(SAHARA_DONE_LENGTH); in sahara_end_of_image()
317 ret = mhi_queue_buf(context->mhi_dev, DMA_TO_DEVICE, context->tx[0], in sahara_end_of_image()
320 dev_dbg(&context->mhi_dev->dev, "Unable to send done response %d\n", ret); in sahara_end_of_image()
325 struct sahara_context *context = container_of(work, struct sahara_context, work); in sahara_processing() local
328 switch (le32_to_cpu(context->rx->cmd)) { in sahara_processing()
330 sahara_hello(context); in sahara_processing()
333 sahara_read_data(context); in sahara_processing()
336 sahara_end_of_image(context); in sahara_processing()
342 dev_err(&context->mhi_dev->dev, "Unknown command %d\n", in sahara_processing()
343 le32_to_cpu(context->rx->cmd)); in sahara_processing()
347 ret = mhi_queue_buf(context->mhi_dev, DMA_FROM_DEVICE, context->rx, in sahara_processing()
350 dev_err(&context->mhi_dev->dev, "Unable to requeue rx buf %d\n", ret); in sahara_processing()
355 struct sahara_context *context; in sahara_mhi_probe() local
359 context = devm_kzalloc(&mhi_dev->dev, sizeof(*context), GFP_KERNEL); in sahara_mhi_probe()
360 if (!context) in sahara_mhi_probe()
363 context->rx = devm_kzalloc(&mhi_dev->dev, SAHARA_PACKET_MAX_SIZE, GFP_KERNEL); in sahara_mhi_probe()
364 if (!context->rx) in sahara_mhi_probe()
379 context->tx[i] = devm_kzalloc(&mhi_dev->dev, SAHARA_PACKET_MAX_SIZE, GFP_KERNEL); in sahara_mhi_probe()
380 if (!context->tx[i]) in sahara_mhi_probe()
384 context->mhi_dev = mhi_dev; in sahara_mhi_probe()
385 INIT_WORK(&context->work, sahara_processing); in sahara_mhi_probe()
386 context->image_table = aic100_image_table; in sahara_mhi_probe()
387 context->table_size = ARRAY_SIZE(aic100_image_table); in sahara_mhi_probe()
388 context->active_image_id = SAHARA_IMAGE_ID_NONE; in sahara_mhi_probe()
389 dev_set_drvdata(&mhi_dev->dev, context); in sahara_mhi_probe()
395 ret = mhi_queue_buf(mhi_dev, DMA_FROM_DEVICE, context->rx, SAHARA_PACKET_MAX_SIZE, MHI_EOT); in sahara_mhi_probe()
406 struct sahara_context *context = dev_get_drvdata(&mhi_dev->dev); in sahara_mhi_remove() local
408 cancel_work_sync(&context->work); in sahara_mhi_remove()
409 sahara_release_image(context); in sahara_mhi_remove()
419 struct sahara_context *context = dev_get_drvdata(&mhi_dev->dev); in sahara_mhi_dl_xfer_cb() local
422 schedule_work(&context->work); in sahara_mhi_dl_xfer_cb()