^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) 2003-2018, Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Intel Management Engine Interface (Intel MEI) Linux driver
^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/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/mei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "mei_dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "hbm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "client.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * mei_irq_compl_handler - dispatch complete handlers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * for the completed callbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * @dev: mei device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * @cmpl_list: list of completed cbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) void mei_irq_compl_handler(struct mei_device *dev, struct list_head *cmpl_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct mei_cl_cb *cb, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct mei_cl *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) list_for_each_entry_safe(cb, next, cmpl_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) cl = cb->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) list_del_init(&cb->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) dev_dbg(dev->dev, "completing call back.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) mei_cl_complete(cl, cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) EXPORT_SYMBOL_GPL(mei_irq_compl_handler);
^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) * mei_cl_hbm_equal - check if hbm is addressed to the client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @cl: host client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @mei_hdr: header of mei client message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Return: true if matches, false otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static inline int mei_cl_hbm_equal(struct mei_cl *cl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct mei_msg_hdr *mei_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return mei_cl_host_addr(cl) == mei_hdr->host_addr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) mei_cl_me_id(cl) == mei_hdr->me_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * mei_irq_discard_msg - discard received message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * @dev: mei device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * @hdr: message header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * @discard_len: the length of the message to discard (excluding header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static void mei_irq_discard_msg(struct mei_device *dev, struct mei_msg_hdr *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) size_t discard_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (hdr->dma_ring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) mei_dma_ring_read(dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) hdr->extension[dev->rd_msg_hdr_count - 2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) discard_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * no need to check for size as it is guarantied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * that length fits into rd_msg_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) mei_read_slots(dev, dev->rd_msg_buf, discard_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) dev_dbg(dev->dev, "discarding message " MEI_HDR_FMT "\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) MEI_HDR_PRM(hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * mei_cl_irq_read_msg - process client message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * @cl: reading client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * @mei_hdr: header of mei client message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * @meta: extend meta header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * @cmpl_list: completion list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Return: always 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int mei_cl_irq_read_msg(struct mei_cl *cl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct mei_msg_hdr *mei_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct mei_ext_meta_hdr *meta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct list_head *cmpl_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct mei_device *dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct mei_cl_cb *cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) size_t buf_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) u32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int ext_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) length = mei_hdr->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ext_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (mei_hdr->extended) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ext_len = sizeof(*meta) + mei_slots2data(meta->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) length -= ext_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) cb = list_first_entry_or_null(&cl->rd_pending, struct mei_cl_cb, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (!cb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (!mei_cl_is_fixed_address(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) cl_err(dev, cl, "pending read cb not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) cb = mei_cl_alloc_cb(cl, mei_cl_mtu(cl), MEI_FOP_READ, cl->fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (!cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) list_add_tail(&cb->list, &cl->rd_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (mei_hdr->extended) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct mei_ext_hdr *ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct mei_ext_hdr *vtag = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ext = mei_ext_begin(meta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) switch (ext->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) case MEI_EXT_HDR_VTAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) vtag = ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) case MEI_EXT_HDR_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) cb->status = -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ext = mei_ext_next(ext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) } while (!mei_ext_last(meta, ext));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (!vtag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) cl_dbg(dev, cl, "vtag not found in extended header.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) cb->status = -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) cl_dbg(dev, cl, "vtag: %d\n", vtag->ext_payload[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (cb->vtag && cb->vtag != vtag->ext_payload[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) cl_err(dev, cl, "mismatched tag: %d != %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) cb->vtag, vtag->ext_payload[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) cb->status = -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) cb->vtag = vtag->ext_payload[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (!mei_cl_is_connected(cl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) cl_dbg(dev, cl, "not connected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) cb->status = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) goto discard;
^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) if (mei_hdr->dma_ring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) length = mei_hdr->extension[mei_data2slots(ext_len)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) buf_sz = length + cb->buf_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* catch for integer overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (buf_sz < cb->buf_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) cl_err(dev, cl, "message is too big len %d idx %zu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) length, cb->buf_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) cb->status = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (cb->buf.size < buf_sz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) cl_dbg(dev, cl, "message overflow. size %zu len %d idx %zu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) cb->buf.size, length, cb->buf_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) cb->status = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (mei_hdr->dma_ring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) mei_dma_ring_read(dev, cb->buf.data + cb->buf_idx, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* for DMA read 0 length to generate interrupt to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) mei_read_slots(dev, cb->buf.data + cb->buf_idx, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) mei_read_slots(dev, cb->buf.data + cb->buf_idx, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) cb->buf_idx += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (mei_hdr->msg_complete) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) cl_dbg(dev, cl, "completed read length = %zu\n", cb->buf_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) list_move_tail(&cb->list, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) pm_runtime_mark_last_busy(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) pm_request_autosuspend(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) list_move_tail(&cb->list, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) mei_irq_discard_msg(dev, mei_hdr, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * mei_cl_irq_disconnect_rsp - send disconnection response message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * @cl: client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * @cb: callback block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * @cmpl_list: complete list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * Return: 0, OK; otherwise, error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct list_head *cmpl_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct mei_device *dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) u32 msg_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) int slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) msg_slots = mei_hbm2slots(sizeof(struct hbm_client_connect_response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) slots = mei_hbuf_empty_slots(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (slots < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if ((u32)slots < msg_slots)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) ret = mei_hbm_cl_disconnect_rsp(dev, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) list_move_tail(&cb->list, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * mei_cl_irq_read - processes client read related operation from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * interrupt thread context - request for flow control credits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * @cl: client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * @cb: callback block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * @cmpl_list: complete list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * Return: 0, OK; otherwise, error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int mei_cl_irq_read(struct mei_cl *cl, struct mei_cl_cb *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct list_head *cmpl_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct mei_device *dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) u32 msg_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) int slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (!list_empty(&cl->rd_pending))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) msg_slots = mei_hbm2slots(sizeof(struct hbm_flow_control));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) slots = mei_hbuf_empty_slots(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (slots < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if ((u32)slots < msg_slots)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ret = mei_hbm_cl_flow_control_req(dev, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) cl->status = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) cb->buf_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) list_move_tail(&cb->list, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) pm_runtime_mark_last_busy(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) pm_request_autosuspend(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) list_move_tail(&cb->list, &cl->rd_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return 0;
^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) static inline bool hdr_is_hbm(struct mei_msg_hdr *mei_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return mei_hdr->host_addr == 0 && mei_hdr->me_addr == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static inline bool hdr_is_fixed(struct mei_msg_hdr *mei_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return mei_hdr->host_addr == 0 && mei_hdr->me_addr != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static inline int hdr_is_valid(u32 msg_hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct mei_msg_hdr *mei_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) u32 expected_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) mei_hdr = (struct mei_msg_hdr *)&msg_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (!msg_hdr || mei_hdr->reserved)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (mei_hdr->dma_ring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) expected_len += MEI_SLOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (mei_hdr->extended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) expected_len += MEI_SLOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (mei_hdr->length < expected_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * mei_irq_read_handler - bottom half read routine after ISR to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * handle the read processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * @dev: the device structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * @cmpl_list: An instance of our list structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * @slots: slots to read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * Return: 0 on success, <0 on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) int mei_irq_read_handler(struct mei_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct list_head *cmpl_list, s32 *slots)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct mei_msg_hdr *mei_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct mei_ext_meta_hdr *meta_hdr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct mei_cl *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) u32 ext_meta_hdr_u32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) u32 hdr_size_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) u32 hdr_size_ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) int ext_hdr_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (!dev->rd_msg_hdr[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) dev->rd_msg_hdr[0] = mei_read_hdr(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) dev->rd_msg_hdr_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) (*slots)--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) dev_dbg(dev->dev, "slots =%08x.\n", *slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) ret = hdr_is_valid(dev->rd_msg_hdr[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) dev_err(dev->dev, "corrupted message header 0x%08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) dev->rd_msg_hdr[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^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) mei_hdr = (struct mei_msg_hdr *)dev->rd_msg_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(mei_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (mei_slots2data(*slots) < mei_hdr->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) dev_err(dev->dev, "less data available than length=%08x.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) *slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /* we can't read the message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) ret = -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) ext_hdr_end = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) hdr_size_left = mei_hdr->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (mei_hdr->extended) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (!dev->rd_msg_hdr[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ext_meta_hdr_u32 = mei_read_hdr(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) dev->rd_msg_hdr[1] = ext_meta_hdr_u32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) dev->rd_msg_hdr_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) (*slots)--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) dev_dbg(dev->dev, "extended header is %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ext_meta_hdr_u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) meta_hdr = ((struct mei_ext_meta_hdr *)dev->rd_msg_hdr + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (check_add_overflow((u32)sizeof(*meta_hdr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) mei_slots2data(meta_hdr->size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) &hdr_size_ext)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) dev_err(dev->dev, "extended message size too big %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) meta_hdr->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (hdr_size_left < hdr_size_ext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) dev_err(dev->dev, "corrupted message header len %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) mei_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) hdr_size_left -= hdr_size_ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) ext_hdr_end = meta_hdr->size + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) for (i = dev->rd_msg_hdr_count; i < ext_hdr_end; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) dev->rd_msg_hdr[i] = mei_read_hdr(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) dev_dbg(dev->dev, "extended header %d is %08x\n", i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) dev->rd_msg_hdr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) dev->rd_msg_hdr_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) (*slots)--;
^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) if (mei_hdr->dma_ring) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (hdr_size_left != sizeof(dev->rd_msg_hdr[ext_hdr_end])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) dev_err(dev->dev, "corrupted message header len %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) mei_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) dev->rd_msg_hdr[ext_hdr_end] = mei_read_hdr(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) dev->rd_msg_hdr_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) (*slots)--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) mei_hdr->length -= sizeof(dev->rd_msg_hdr[ext_hdr_end]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) /* HBM message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (hdr_is_hbm(mei_hdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) ret = mei_hbm_dispatch(dev, mei_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) dev_dbg(dev->dev, "mei_hbm_dispatch failed ret = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) goto reset_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /* find recipient cl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) list_for_each_entry(cl, &dev->file_list, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (mei_cl_hbm_equal(cl, mei_hdr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) cl_dbg(dev, cl, "got a message\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) ret = mei_cl_irq_read_msg(cl, mei_hdr, meta_hdr, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) goto reset_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* if no recipient cl was found we assume corrupted header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /* A message for not connected fixed address clients
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * should be silently discarded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * On power down client may be force cleaned,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * silently discard such messages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (hdr_is_fixed(mei_hdr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) dev->dev_state == MEI_DEV_POWER_DOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) mei_irq_discard_msg(dev, mei_hdr, mei_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) goto reset_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) dev_err(dev->dev, "no destination client found 0x%08X\n", dev->rd_msg_hdr[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) ret = -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) reset_slots:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* reset the number of slots and header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) memset(dev->rd_msg_hdr, 0, sizeof(dev->rd_msg_hdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) dev->rd_msg_hdr_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) *slots = mei_count_full_read_slots(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (*slots == -EOVERFLOW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /* overflow - reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) dev_err(dev->dev, "resetting due to slots overflow.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /* set the event since message has been read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) ret = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) EXPORT_SYMBOL_GPL(mei_irq_read_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * mei_irq_write_handler - dispatch write requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * after irq received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * @dev: the device structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * @cmpl_list: An instance of our list structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * Return: 0 on success, <0 on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int mei_irq_write_handler(struct mei_device *dev, struct list_head *cmpl_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct mei_cl *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct mei_cl_cb *cb, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) s32 slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (!mei_hbuf_acquire(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) slots = mei_hbuf_empty_slots(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (slots < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (slots == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /* complete all waiting for write CB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) dev_dbg(dev->dev, "complete all waiting for write cb.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) list_for_each_entry_safe(cb, next, &dev->write_waiting_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) cl = cb->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) cl->status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) cl_dbg(dev, cl, "MEI WRITE COMPLETE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) cl->writing_state = MEI_WRITE_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) list_move_tail(&cb->list, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /* complete control write list CB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) dev_dbg(dev->dev, "complete control write list cb.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) list_for_each_entry_safe(cb, next, &dev->ctrl_wr_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) cl = cb->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) switch (cb->fop_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) case MEI_FOP_DISCONNECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /* send disconnect message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ret = mei_cl_irq_disconnect(cl, cb, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) case MEI_FOP_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* send flow control message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) ret = mei_cl_irq_read(cl, cb, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) case MEI_FOP_CONNECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* connect message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) ret = mei_cl_irq_connect(cl, cb, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) case MEI_FOP_DISCONNECT_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) /* send disconnect resp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) ret = mei_cl_irq_disconnect_rsp(cl, cb, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) case MEI_FOP_NOTIFY_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) case MEI_FOP_NOTIFY_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) ret = mei_cl_irq_notify(cl, cb, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) /* complete write list CB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) dev_dbg(dev->dev, "complete write list cb.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) list_for_each_entry_safe(cb, next, &dev->write_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) cl = cb->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) ret = mei_cl_irq_write(cl, cb, cmpl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) EXPORT_SYMBOL_GPL(mei_irq_write_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * mei_connect_timeout - connect/disconnect timeouts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * @cl: host client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static void mei_connect_timeout(struct mei_cl *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) struct mei_device *dev = cl->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (cl->state == MEI_FILE_CONNECTING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (dev->hbm_f_dot_supported) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) cl->state = MEI_FILE_DISCONNECT_REQUIRED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) wake_up(&cl->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) mei_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) #define MEI_STALL_TIMER_FREQ (2 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) * mei_schedule_stall_timer - re-arm stall_timer work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * Schedule stall timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) * @dev: the device structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) void mei_schedule_stall_timer(struct mei_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) schedule_delayed_work(&dev->timer_work, MEI_STALL_TIMER_FREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) * mei_timer - timer function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) * @work: pointer to the work_struct structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) void mei_timer(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct mei_cl *cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) struct mei_device *dev = container_of(work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct mei_device, timer_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) bool reschedule_timer = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) mutex_lock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) /* Catch interrupt stalls during HBM init handshake */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) dev->hbm_state != MEI_HBM_IDLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (dev->init_clients_timer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (--dev->init_clients_timer == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) dev_err(dev->dev, "timer: init clients timeout hbm_state = %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) dev->hbm_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) mei_reset(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) reschedule_timer = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) if (dev->dev_state != MEI_DEV_ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) /*** connect/disconnect timeouts ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) list_for_each_entry(cl, &dev->file_list, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) if (cl->timer_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (--cl->timer_count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) dev_err(dev->dev, "timer: connect/disconnect timeout.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) mei_connect_timeout(cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) reschedule_timer = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (dev->dev_state != MEI_DEV_DISABLED && reschedule_timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) mei_schedule_stall_timer(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) mutex_unlock(&dev->device_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }