From 140c7553231dcd119ebda8c27dec7f06aef7e323 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Thu, 2 Oct 2014 13:39:31 +0300 Subject: mei: drop unneeded client NULL check in cb structure The pointer to client in the callback structure (cb->cl) can't be NULL with current locking. We can drop check and warnings as in some cases this just uselessly complicates the code flow. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/amthif.c | 24 +++++++++--------------- drivers/misc/mei/client.c | 2 +- drivers/misc/mei/hbm.c | 5 ----- drivers/misc/mei/interrupt.c | 12 +----------- 4 files changed, 11 insertions(+), 32 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c index 6cdce84..0b5a315 100644 --- a/drivers/misc/mei/amthif.c +++ b/drivers/misc/mei/amthif.c @@ -360,8 +360,7 @@ int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *cb) void mei_amthif_run_next_cmd(struct mei_device *dev) { struct mei_cl_cb *cb; - struct mei_cl_cb *next; - int status; + int ret; if (!dev) return; @@ -376,16 +375,14 @@ void mei_amthif_run_next_cmd(struct mei_device *dev) dev_dbg(dev->dev, "complete amthif cmd_list cb.\n"); - list_for_each_entry_safe(cb, next, &dev->amthif_cmd_list.list, list) { - list_del(&cb->list); - if (!cb->cl) - continue; - status = mei_amthif_send_cmd(dev, cb); - if (status) - dev_warn(dev->dev, "amthif write failed status = %d\n", - status); - break; - } + cb = list_first_entry_or_null(&dev->amthif_cmd_list.list, + typeof(*cb), list); + if (!cb) + return; + list_del(&cb->list); + ret = mei_amthif_send_cmd(dev, cb); + if (ret) + dev_warn(dev->dev, "amthif write failed status = %d\n", ret); } @@ -536,9 +533,6 @@ int mei_amthif_irq_read_msg(struct mei_device *dev, cb = dev->iamthif_current_cb; dev->iamthif_current_cb = NULL; - if (!cb->cl) - return -ENODEV; - dev->iamthif_stall_timer = 0; cb->buf_idx = dev->iamthif_msg_buf_index; cb->read_time = jiffies; diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index bc9ba53..1382d55 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c @@ -146,7 +146,7 @@ static void __mei_io_list_flush(struct mei_cl_cb *list, /* enable removing everything if no cl is specified */ list_for_each_entry_safe(cb, next, &list->list, list) { - if (!cl || (cb->cl && mei_cl_cmp_id(cl, cb->cl))) { + if (!cl || mei_cl_cmp_id(cl, cb->cl)) { list_del(&cb->list); if (free) mei_io_cb_free(cb); diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c index 49a2653..57c1bde 100644 --- a/drivers/misc/mei/hbm.c +++ b/drivers/misc/mei/hbm.c @@ -637,11 +637,6 @@ static void mei_hbm_cl_res(struct mei_device *dev, list_for_each_entry_safe(cb, next, &dev->ctrl_rd_list.list, list) { cl = cb->cl; - /* this should not happen */ - if (WARN_ON(!cl)) { - list_del_init(&cb->list); - continue; - } if (cb->fop_type != fop_type) continue; diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c index 20c6c511..711cddf 100644 --- a/drivers/misc/mei/interrupt.c +++ b/drivers/misc/mei/interrupt.c @@ -44,8 +44,6 @@ void mei_irq_compl_handler(struct mei_device *dev, struct mei_cl_cb *compl_list) list_for_each_entry_safe(cb, next, &compl_list->list, list) { cl = cb->cl; list_del(&cb->list); - if (!cl) - continue; dev_dbg(dev->dev, "completing call back.\n"); if (cl == &dev->iamthif_cl) @@ -105,7 +103,7 @@ static int mei_cl_irq_read_msg(struct mei_device *dev, list_for_each_entry_safe(cb, next, &dev->read_list.list, list) { cl = cb->cl; - if (!cl || !mei_cl_is_reading(cl, mei_hdr)) + if (!mei_cl_is_reading(cl, mei_hdr)) continue; cl->reading_state = MEI_READING; @@ -449,8 +447,6 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) list = &dev->write_waiting_list; list_for_each_entry_safe(cb, next, &list->list, list) { cl = cb->cl; - if (cl == NULL) - continue; cl->status = 0; list_del(&cb->list); @@ -489,10 +485,6 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) dev_dbg(dev->dev, "complete control write list cb.\n"); list_for_each_entry_safe(cb, next, &dev->ctrl_wr_list.list, list) { cl = cb->cl; - if (!cl) { - list_del(&cb->list); - return -ENODEV; - } switch (cb->fop_type) { case MEI_FOP_DISCONNECT: /* send disconnect message */ @@ -530,8 +522,6 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) dev_dbg(dev->dev, "complete write list cb.\n"); list_for_each_entry_safe(cb, next, &dev->write_list.list, list) { cl = cb->cl; - if (cl == NULL) - continue; if (cl == &dev->iamthif_cl) ret = mei_amthif_irq_write(cl, cb, cmpl_list); else -- cgit v1.1 From 3d32cf02241e307d3be92046a8cbd3deb8cda307 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Thu, 2 Oct 2014 13:39:32 +0300 Subject: mei: use local cl variables in wd and amthif Use local cl variable instead of dev->iamthif_cl and dev->wd_cl as the first step to use dynamic allocation of these clients as their are not supported on all platforms Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/amthif.c | 10 ++++++---- drivers/misc/mei/wd.c | 9 ++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/mei/amthif.c b/drivers/misc/mei/amthif.c index 0b5a315..79f53941 100644 --- a/drivers/misc/mei/amthif.c +++ b/drivers/misc/mei/amthif.c @@ -262,6 +262,7 @@ out: static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb) { struct mei_msg_hdr mei_hdr; + struct mei_cl *cl; int ret; if (!dev || !cb) @@ -277,8 +278,9 @@ static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb) dev->iamthif_msg_buf_size = cb->request_buffer.size; memcpy(dev->iamthif_msg_buf, cb->request_buffer.data, cb->request_buffer.size); + cl = &dev->iamthif_cl; - ret = mei_cl_flow_ctrl_creds(&dev->iamthif_cl); + ret = mei_cl_flow_ctrl_creds(cl); if (ret < 0) return ret; @@ -292,8 +294,8 @@ static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb) mei_hdr.msg_complete = 1; } - mei_hdr.host_addr = dev->iamthif_cl.host_client_id; - mei_hdr.me_addr = dev->iamthif_cl.me_client_id; + mei_hdr.host_addr = cl->host_client_id; + mei_hdr.me_addr = cl->me_client_id; mei_hdr.reserved = 0; mei_hdr.internal = 0; dev->iamthif_msg_buf_index += mei_hdr.length; @@ -302,7 +304,7 @@ static int mei_amthif_send_cmd(struct mei_device *dev, struct mei_cl_cb *cb) return ret; if (mei_hdr.msg_complete) { - if (mei_cl_flow_ctrl_reduce(&dev->iamthif_cl)) + if (mei_cl_flow_ctrl_reduce(cl)) return -EIO; dev->iamthif_flow_control_pending = true; dev->iamthif_state = MEI_IAMTHIF_FLOW_CONTROL; diff --git a/drivers/misc/mei/wd.c b/drivers/misc/mei/wd.c index b836dff..b1d892c 100644 --- a/drivers/misc/mei/wd.c +++ b/drivers/misc/mei/wd.c @@ -270,15 +270,18 @@ static int mei_wd_ops_stop(struct watchdog_device *wd_dev) static int mei_wd_ops_ping(struct watchdog_device *wd_dev) { struct mei_device *dev; + struct mei_cl *cl; int ret; dev = watchdog_get_drvdata(wd_dev); if (!dev) return -ENODEV; + cl = &dev->wd_cl; + mutex_lock(&dev->device_lock); - if (dev->wd_cl.state != MEI_FILE_CONNECTED) { + if (cl->state != MEI_FILE_CONNECTED) { dev_err(dev->dev, "wd: not connected.\n"); ret = -ENODEV; goto end; @@ -286,12 +289,12 @@ static int mei_wd_ops_ping(struct watchdog_device *wd_dev) dev->wd_state = MEI_WD_RUNNING; - ret = mei_cl_flow_ctrl_creds(&dev->wd_cl); + ret = mei_cl_flow_ctrl_creds(cl); if (ret < 0) goto end; + /* Check if we can send the ping to HW*/ if (ret && mei_hbuf_acquire(dev)) { - dev_dbg(dev->dev, "wd: sending ping\n"); ret = mei_wd_send(dev); -- cgit v1.1 From 4ade435214a59ac1f7b3dc97fb5486c74bd37c79 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Tue, 28 Oct 2014 09:39:39 +0200 Subject: mei: debugfs: display also connectionless clients meiX/meclients: display also fixed/connectionless clients Use better name for fixed client field: fixed_address is boolean and indicates whether a client is fixed or dynamic. Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/debugfs.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/mei/debugfs.c b/drivers/misc/mei/debugfs.c index ce15667..b60b426 100644 --- a/drivers/misc/mei/debugfs.c +++ b/drivers/misc/mei/debugfs.c @@ -34,7 +34,7 @@ static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, int pos = 0; int ret; -#define HDR " |id|addr| UUID |con|msg len|sb|\n" +#define HDR " |id|fix| UUID |con|msg len|sb|\n" mutex_lock(&dev->device_lock); @@ -56,12 +56,8 @@ static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, list_for_each_entry(me_cl, &dev->me_clients, list) { - /* skip me clients that cannot be connected */ - if (me_cl->props.max_number_of_connections == 0) - continue; - pos += scnprintf(buf + pos, bufsz - pos, - "%2d|%2d|%4d|%pUl|%3d|%7d|%2d|\n", + "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|\n", i++, me_cl->client_id, me_cl->props.fixed_address, &me_cl->props.protocol_name, -- cgit v1.1 From d512c2098b1af6069e47ca457d7034d7cc82d420 Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Wed, 29 Oct 2014 23:50:58 +0200 Subject: mei: hbm: use client specific print functions We have host client in connect/disconnect response processors, so use client print functions to simplify and unify code. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/hbm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c index 57c1bde..256fc46 100644 --- a/drivers/misc/mei/hbm.c +++ b/drivers/misc/mei/hbm.c @@ -562,17 +562,17 @@ int mei_hbm_cl_disconnect_rsp(struct mei_device *dev, struct mei_cl *cl) * mei_hbm_cl_disconnect_res - update the client state according * disconnect response * + * @dev: the device structure * @cl: mei host client * @cmd: disconnect client response host bus message */ -static void mei_hbm_cl_disconnect_res(struct mei_cl *cl, +static void mei_hbm_cl_disconnect_res(struct mei_device *dev, struct mei_cl *cl, struct mei_hbm_cl_cmd *cmd) { struct hbm_client_connect_response *rs = (struct hbm_client_connect_response *)cmd; - dev_dbg(cl->dev->dev, "hbm: disconnect response cl:host=%02d me=%02d status=%d\n", - rs->me_addr, rs->host_addr, rs->status); + cl_dbg(dev, cl, "hbm: disconnect response status=%d\n", rs->status); if (rs->status == MEI_CL_DISCONN_SUCCESS) cl->state = MEI_FILE_DISCONNECTED; @@ -598,17 +598,17 @@ int mei_hbm_cl_connect_req(struct mei_device *dev, struct mei_cl *cl) * mei_hbm_cl_connect_res - update the client state according * connection response * + * @dev: the device structure * @cl: mei host client * @cmd: connect client response host bus message */ -static void mei_hbm_cl_connect_res(struct mei_cl *cl, +static void mei_hbm_cl_connect_res(struct mei_device *dev, struct mei_cl *cl, struct mei_hbm_cl_cmd *cmd) { struct hbm_client_connect_response *rs = (struct hbm_client_connect_response *)cmd; - dev_dbg(cl->dev->dev, "hbm: connect response cl:host=%02d me=%02d status=%s\n", - rs->me_addr, rs->host_addr, + cl_dbg(dev, cl, "hbm: connect response status=%s\n", mei_cl_conn_status_str(rs->status)); if (rs->status == MEI_CL_CONN_SUCCESS) @@ -652,10 +652,10 @@ static void mei_hbm_cl_res(struct mei_device *dev, switch (fop_type) { case MEI_FOP_CONNECT: - mei_hbm_cl_connect_res(cl, rs); + mei_hbm_cl_connect_res(dev, cl, rs); break; case MEI_FOP_DISCONNECT: - mei_hbm_cl_disconnect_res(cl, rs); + mei_hbm_cl_disconnect_res(dev, cl, rs); break; default: return; -- cgit v1.1 From 49af54ff0fc7abb6457caed982ddfcfda487e3f7 Mon Sep 17 00:00:00 2001 From: Bo Shen Date: Wed, 24 Sep 2014 17:33:55 +0800 Subject: misc: atmel-ssc: prepare clock only when request Prepare SSC clock only when request SSC channel, the clock will be enabled when initialize the SSC. Signed-off-by: Bo Shen Acked-by: Nicolas Ferre Signed-off-by: Greg Kroah-Hartman --- drivers/misc/atmel-ssc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c index 60843a2..f9807a7 100644 --- a/drivers/misc/atmel-ssc.c +++ b/drivers/misc/atmel-ssc.c @@ -57,7 +57,7 @@ struct ssc_device *ssc_request(unsigned int ssc_num) ssc->user++; spin_unlock(&user_lock); - clk_prepare_enable(ssc->clk); + clk_prepare(ssc->clk); return ssc; } @@ -77,7 +77,7 @@ void ssc_free(struct ssc_device *ssc) spin_unlock(&user_lock); if (disable_clk) - clk_disable_unprepare(ssc->clk); + clk_unprepare(ssc->clk); } EXPORT_SYMBOL(ssc_free); -- cgit v1.1 From a176c24dc9a82b3304a31233bfc37e97c42de09b Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Wed, 5 Nov 2014 18:18:52 +0200 Subject: mei: nfc: clean nfc internal struct on host exit NFC internal structure cleaning was dropped by commit commit 487056932d372cc4f6c636f21a928d6667b151d7 Author: Tomas Winkler Date: Mon Feb 17 15:13:19 2014 +0200 mei: Remove all bus devices from the mei_dev list when stopping the MEI When stopping the MEI, we should remove and potentially unregister all bus devices queued on the mei_dev linked list. We allocate nfc_dev and free it across the reset so we do not keep it in dirty state Signed-off-by: Tomas Winkler Signed-off-by: Alexander Usyskin Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/bus.c | 4 ++-- drivers/misc/mei/mei_dev.h | 1 + drivers/misc/mei/nfc.c | 52 ++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 11 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index 4d20d60..b3a72bc 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -140,7 +140,7 @@ static struct device_type mei_cl_device_type = { .release = mei_cl_dev_release, }; -static struct mei_cl *mei_bus_find_mei_cl_by_uuid(struct mei_device *dev, +struct mei_cl *mei_cl_bus_find_cl_by_uuid(struct mei_device *dev, uuid_le uuid) { struct mei_cl *cl; @@ -160,7 +160,7 @@ struct mei_cl_device *mei_cl_add_device(struct mei_device *dev, struct mei_cl *cl; int status; - cl = mei_bus_find_mei_cl_by_uuid(dev, uuid); + cl = mei_cl_bus_find_cl_by_uuid(dev, uuid); if (cl == NULL) return NULL; diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index 71744b1..1288a5c 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h @@ -349,6 +349,7 @@ void mei_cl_bus_rx_event(struct mei_cl *cl); void mei_cl_bus_remove_devices(struct mei_device *dev); int mei_cl_bus_init(void); void mei_cl_bus_exit(void); +struct mei_cl *mei_cl_bus_find_cl_by_uuid(struct mei_device *dev, uuid_le uuid); /** diff --git a/drivers/misc/mei/nfc.c b/drivers/misc/mei/nfc.c index 6226543..60ca924 100644 --- a/drivers/misc/mei/nfc.c +++ b/drivers/misc/mei/nfc.c @@ -117,8 +117,6 @@ struct mei_nfc_dev { u16 recv_req_id; }; -static struct mei_nfc_dev nfc_dev; - /* UUIDs for NFC F/W clients */ const uuid_le mei_nfc_guid = UUID_LE(0x0bb17a78, 0x2a8e, 0x4c50, 0x94, 0xd4, 0x50, 0x26, @@ -138,6 +136,9 @@ static const uuid_le mei_nfc_info_guid = UUID_LE(0xd2de1625, 0x382d, 0x417d, static void mei_nfc_free(struct mei_nfc_dev *ndev) { + if (!ndev) + return; + if (ndev->cl) { list_del(&ndev->cl->device_link); mei_cl_unlink(ndev->cl); @@ -150,7 +151,7 @@ static void mei_nfc_free(struct mei_nfc_dev *ndev) kfree(ndev->cl_info); } - memset(ndev, 0, sizeof(struct mei_nfc_dev)); + kfree(ndev); } static int mei_nfc_build_bus_name(struct mei_nfc_dev *ndev) @@ -319,9 +320,10 @@ err: static int mei_nfc_enable(struct mei_cl_device *cldev) { struct mei_device *dev; - struct mei_nfc_dev *ndev = &nfc_dev; + struct mei_nfc_dev *ndev; int ret; + ndev = (struct mei_nfc_dev *)cldev->priv_data; dev = ndev->cl->dev; ret = mei_nfc_connect(ndev); @@ -479,15 +481,25 @@ err: int mei_nfc_host_init(struct mei_device *dev) { - struct mei_nfc_dev *ndev = &nfc_dev; + struct mei_nfc_dev *ndev; struct mei_cl *cl_info, *cl = NULL; struct mei_me_client *me_cl; int ret; - /* already initialized */ - if (ndev->cl_info) + + /* in case of internal reset bail out + * as the device is already setup + */ + cl = mei_cl_bus_find_cl_by_uuid(dev, mei_nfc_guid); + if (cl) return 0; + ndev = kzalloc(sizeof(struct mei_nfc_dev), GFP_KERNEL); + if (!ndev) { + ret = -ENOMEM; + goto err; + } + ndev->cl_info = mei_cl_allocate(dev); ndev->cl = mei_cl_allocate(dev); @@ -550,9 +562,31 @@ err: void mei_nfc_host_exit(struct mei_device *dev) { - struct mei_nfc_dev *ndev = &nfc_dev; + struct mei_nfc_dev *ndev; + struct mei_cl *cl; + struct mei_cl_device *cldev; + + cl = mei_cl_bus_find_cl_by_uuid(dev, mei_nfc_guid); + if (!cl) + return; + + cldev = cl->device; + if (!cldev) + return; - cancel_work_sync(&ndev->init_work); + ndev = (struct mei_nfc_dev *)cldev->priv_data; + if (ndev) + cancel_work_sync(&ndev->init_work); + + cldev->priv_data = NULL; + + mutex_lock(&dev->device_lock); + /* Need to remove the device here + * since mei_nfc_free will unlink the clients + */ + mei_cl_remove_device(cldev); + mei_nfc_free(ndev); + mutex_unlock(&dev->device_lock); } -- cgit v1.1 From 5ebdc364588a5b988fdaf56e2ec01815f1876e9a Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Wed, 5 Nov 2014 11:44:48 +0200 Subject: mei: fix hbm MEI_HBM_STARTED ambiguity We have MEI_HBM_STARTED in two contexts one after start message was received and second after enumeration was completed. Because after start message reception we move immediately to the enumeration state, we need only the later meaning. Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/hbm.c | 2 -- drivers/misc/mei/hbm.h | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c index 256fc46..239d7f5 100644 --- a/drivers/misc/mei/hbm.c +++ b/drivers/misc/mei/hbm.c @@ -806,8 +806,6 @@ int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) return -EPROTO; } - dev->hbm_state = MEI_HBM_STARTED; - if (mei_hbm_enum_clients_req(dev)) { dev_err(dev->dev, "hbm: start: failed to send enumeration request\n"); return -EIO; diff --git a/drivers/misc/mei/hbm.h b/drivers/misc/mei/hbm.h index b7cd3d8..2544db7 100644 --- a/drivers/misc/mei/hbm.h +++ b/drivers/misc/mei/hbm.h @@ -26,17 +26,17 @@ struct mei_cl; * * @MEI_HBM_IDLE : protocol not started * @MEI_HBM_STARTING : start request message was sent - * @MEI_HBM_STARTED : start reply message was received * @MEI_HBM_ENUM_CLIENTS : enumeration request was sent * @MEI_HBM_CLIENT_PROPERTIES : acquiring clients properties + * @MEI_HBM_STARTED : enumeration was completed * @MEI_HBM_STOPPED : stopping exchange */ enum mei_hbm_state { MEI_HBM_IDLE = 0, MEI_HBM_STARTING, - MEI_HBM_STARTED, MEI_HBM_ENUM_CLIENTS, MEI_HBM_CLIENT_PROPERTIES, + MEI_HBM_STARTED, MEI_HBM_STOPPED, }; -- cgit v1.1 From cf35d6e0475982667b0d2d318fb27be4b8849827 Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 6 Nov 2014 16:23:39 +0000 Subject: misc: genwqe: check for error from get_user_pages_fast() `genwqe_user_vmap()` calls `get_user_pages_fast()` and if the return value is less than the number of pages requested, it frees the pages and returns an error (`-EFAULT`). However, it fails to consider a negative error return value from `get_user_pages_fast()`. In that case, the test `if (rc < m->nr_pages)` will be false (due to promotion of `rc` to a large `unsigned int`) and the code will continue on to call `genwqe_map_pages()` with an invalid list of page pointers. Fix it by bailing out if `get_user_pages_fast()` returns a negative error value. Signed-off-by: Ian Abbott Cc: # 3.14.x # 3.15.x # 3.16.x # 3.17.x Signed-off-by: Greg Kroah-Hartman --- drivers/misc/genwqe/card_utils.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/misc') diff --git a/drivers/misc/genwqe/card_utils.c b/drivers/misc/genwqe/card_utils.c index 7cb3b7e..1ca94e6 100644 --- a/drivers/misc/genwqe/card_utils.c +++ b/drivers/misc/genwqe/card_utils.c @@ -590,6 +590,8 @@ int genwqe_user_vmap(struct genwqe_dev *cd, struct dma_mapping *m, void *uaddr, m->nr_pages, 1, /* write by caller */ m->page_list); /* ptrs to pages */ + if (rc < 0) + goto fail_get_user_pages; /* assumption: get_user_pages can be killed by signals. */ if (rc < m->nr_pages) { -- cgit v1.1 From 7750efd59a290ab089bfc5c121787f4c630fe606 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 2 Oct 2014 09:26:16 +0200 Subject: pch_phub: Build context save/restore only for PM The pch_phub_save_reg_conf() and pch_phub_restore_reg_conf() functions are only used for suspend/resume support (i.e. when PM is enabled). If PM is disabled they don't need to be built. Signed-off-by: Thierry Reding Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pch_phub.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/misc') diff --git a/drivers/misc/pch_phub.c b/drivers/misc/pch_phub.c index 9565973..9a17a9b 100644 --- a/drivers/misc/pch_phub.c +++ b/drivers/misc/pch_phub.c @@ -158,6 +158,7 @@ static void pch_phub_read_modify_write_reg(struct pch_phub_reg *chip, iowrite32(((ioread32(reg_addr) & ~mask)) | data, reg_addr); } +#ifdef CONFIG_PM /* pch_phub_save_reg_conf - saves register configuration */ static void pch_phub_save_reg_conf(struct pci_dev *pdev) { @@ -280,6 +281,7 @@ static void pch_phub_restore_reg_conf(struct pci_dev *pdev) if ((chip->ioh_type == 2) || (chip->ioh_type == 4)) iowrite32(chip->funcsel_reg, p + FUNCSEL_REG_OFFSET); } +#endif /** * pch_phub_read_serial_rom() - Reading Serial ROM -- cgit v1.1 From c380b862ba46dcd0fe0b720dddaa8d821e787652 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Mon, 10 Nov 2014 16:09:56 +0100 Subject: misc: Remove unused subdirectory Commit 783c8f4c8445 ("soc/tegra: Add efuse driver for Tegra") added a fuse directory in drivers/misc along with a Makefile that were never used. They were leftovers from an earlier version of the patch series. Reported-by: Shawn Guo Signed-off-by: Thierry Reding Signed-off-by: Greg Kroah-Hartman --- drivers/misc/fuse/Makefile | 1 - 1 file changed, 1 deletion(-) delete mode 100644 drivers/misc/fuse/Makefile (limited to 'drivers/misc') diff --git a/drivers/misc/fuse/Makefile b/drivers/misc/fuse/Makefile deleted file mode 100644 index 0679c4f..0000000 --- a/drivers/misc/fuse/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-$(CONFIG_ARCH_TEGRA) += tegra/ -- cgit v1.1 From 18caeb70f3aa694a3147709e6425f749bfd04ea7 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Wed, 12 Nov 2014 23:42:14 +0200 Subject: mei: kill cached host and me csr values Kill host_hw_status and me_hw_state from me hw structure that used to cache host and me csr values. We do not use the cached values across the function calls anymore Signed-off-by: Tomas Winkler Signed-off-by: Alexander Usyskin Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/hw-me.c | 30 ++++++++++++++++-------------- drivers/misc/mei/hw-me.h | 7 ------- 2 files changed, 16 insertions(+), 21 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c index 4f2fd6f..7ce7cf4 100644 --- a/drivers/misc/mei/hw-me.c +++ b/drivers/misc/mei/hw-me.c @@ -270,10 +270,10 @@ static int mei_me_hw_reset(struct mei_device *dev, bool intr_enable) static void mei_me_host_set_ready(struct mei_device *dev) { struct mei_me_hw *hw = to_me_hw(dev); + u32 hcsr = mei_hcsr_read(hw); - hw->host_hw_state = mei_hcsr_read(hw); - hw->host_hw_state |= H_IE | H_IG | H_RDY; - mei_hcsr_set(hw, hw->host_hw_state); + hcsr |= H_IE | H_IG | H_RDY; + mei_hcsr_set(hw, hcsr); } /** @@ -285,9 +285,9 @@ static void mei_me_host_set_ready(struct mei_device *dev) static bool mei_me_host_is_ready(struct mei_device *dev) { struct mei_me_hw *hw = to_me_hw(dev); + u32 hcsr = mei_hcsr_read(hw); - hw->host_hw_state = mei_hcsr_read(hw); - return (hw->host_hw_state & H_RDY) == H_RDY; + return (hcsr & H_RDY) == H_RDY; } /** @@ -299,9 +299,9 @@ static bool mei_me_host_is_ready(struct mei_device *dev) static bool mei_me_hw_is_ready(struct mei_device *dev) { struct mei_me_hw *hw = to_me_hw(dev); + u32 mecsr = mei_me_mecsr_read(hw); - hw->me_hw_state = mei_me_mecsr_read(hw); - return (hw->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA; + return (mecsr & ME_RDY_HRA) == ME_RDY_HRA; } /** @@ -356,12 +356,13 @@ static int mei_me_hw_start(struct mei_device *dev) static unsigned char mei_hbuf_filled_slots(struct mei_device *dev) { struct mei_me_hw *hw = to_me_hw(dev); + u32 hcsr; char read_ptr, write_ptr; - hw->host_hw_state = mei_hcsr_read(hw); + hcsr = mei_hcsr_read(hw); - read_ptr = (char) ((hw->host_hw_state & H_CBRP) >> 8); - write_ptr = (char) ((hw->host_hw_state & H_CBWP) >> 16); + read_ptr = (char) ((hcsr & H_CBRP) >> 8); + write_ptr = (char) ((hcsr & H_CBWP) >> 16); return (unsigned char) (write_ptr - read_ptr); } @@ -474,13 +475,14 @@ static int mei_me_write_message(struct mei_device *dev, static int mei_me_count_full_read_slots(struct mei_device *dev) { struct mei_me_hw *hw = to_me_hw(dev); + u32 me_csr; char read_ptr, write_ptr; unsigned char buffer_depth, filled_slots; - hw->me_hw_state = mei_me_mecsr_read(hw); - buffer_depth = (unsigned char)((hw->me_hw_state & ME_CBD_HRA) >> 24); - read_ptr = (char) ((hw->me_hw_state & ME_CBRP_HRA) >> 8); - write_ptr = (char) ((hw->me_hw_state & ME_CBWP_HRA) >> 16); + me_csr = mei_me_mecsr_read(hw); + buffer_depth = (unsigned char)((me_csr & ME_CBD_HRA) >> 24); + read_ptr = (char) ((me_csr & ME_CBRP_HRA) >> 8); + write_ptr = (char) ((me_csr & ME_CBWP_HRA) >> 16); filled_slots = (unsigned char) (write_ptr - read_ptr); /* check for overflow */ diff --git a/drivers/misc/mei/hw-me.h b/drivers/misc/mei/hw-me.h index e6a59a6..e44ed1d 100644 --- a/drivers/misc/mei/hw-me.h +++ b/drivers/misc/mei/hw-me.h @@ -51,18 +51,11 @@ struct mei_cfg { * * @cfg: per device generation config and ops * @mem_addr: io memory address - * @host_hw_state: cached host state - * @me_hw_state: cached me (fw) state * @pg_state: power gating state */ struct mei_me_hw { const struct mei_cfg *cfg; void __iomem *mem_addr; - /* - * hw states of host and fw(ME) - */ - u32 host_hw_state; - u32 me_hw_state; enum mei_pg_state pg_state; }; -- cgit v1.1 From e88281edd4b4496600f2ab423ee2a2363a5e27f7 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Tue, 18 Nov 2014 00:13:21 +0200 Subject: mei: txe: add cherrytrail device id Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/pci-txe.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/misc') diff --git a/drivers/misc/mei/pci-txe.c b/drivers/misc/mei/pci-txe.c index bee1c6fb..1b1a6e5 100644 --- a/drivers/misc/mei/pci-txe.c +++ b/drivers/misc/mei/pci-txe.c @@ -37,6 +37,7 @@ static const struct pci_device_id mei_txe_pci_tbl[] = { {PCI_VDEVICE(INTEL, 0x0F18)}, /* Baytrail */ + {PCI_VDEVICE(INTEL, 0x2298)}, /* Cherrytrail */ {0, } }; -- cgit v1.1 From edca5ea3ff3323b4526d70642d115992df73c9bc Mon Sep 17 00:00:00 2001 From: Alexander Usyskin Date: Wed, 19 Nov 2014 17:01:38 +0200 Subject: mei: read and print all six FW status registers ME devices prior to PCH8 (Lynx Point) have two FW status registers, on PCH8 and newer excluding txe there are six FW status registers. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/hw-me-regs.h | 12 ++++++++---- drivers/misc/mei/hw-me.c | 19 ++++++++++++++++--- drivers/misc/mei/hw-me.h | 3 ++- drivers/misc/mei/hw-txe.c | 7 +++---- drivers/misc/mei/init.c | 38 +++++++++++++++++++++++++++++++++----- drivers/misc/mei/mei_dev.h | 38 ++++++++++++++++++++++++++++++++------ drivers/misc/mei/pci-me.c | 12 ++++++------ 7 files changed, 100 insertions(+), 29 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/mei/hw-me-regs.h b/drivers/misc/mei/hw-me-regs.h index c5feafd..9eb7ed7 100644 --- a/drivers/misc/mei/hw-me-regs.h +++ b/drivers/misc/mei/hw-me-regs.h @@ -117,14 +117,18 @@ #define MEI_DEV_ID_WPT_LP 0x9CBA /* Wildcat Point LP */ #define MEI_DEV_ID_WPT_LP_2 0x9CBB /* Wildcat Point LP 2 */ -/* Host Firmware Status Registers in PCI Config Space */ -#define PCI_CFG_HFS_1 0x40 -#define PCI_CFG_HFS_2 0x48 - /* * MEI HW Section */ +/* Host Firmware Status Registers in PCI Config Space */ +#define PCI_CFG_HFS_1 0x40 +#define PCI_CFG_HFS_2 0x48 +#define PCI_CFG_HFS_3 0x60 +#define PCI_CFG_HFS_4 0x64 +#define PCI_CFG_HFS_5 0x68 +#define PCI_CFG_HFS_6 0x6C + /* MEI registers */ /* H_CB_WW - Host Circular Buffer (CB) Write Window register */ #define H_CB_WW 0 diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c index 7ce7cf4..ff27550 100644 --- a/drivers/misc/mei/hw-me.c +++ b/drivers/misc/mei/hw-me.c @@ -835,6 +835,14 @@ static bool mei_me_fw_type_sps(struct pci_dev *pdev) .fw_status.status[0] = PCI_CFG_HFS_1, \ .fw_status.status[1] = PCI_CFG_HFS_2 +#define MEI_CFG_PCH8_HFS \ + .fw_status.count = 6, \ + .fw_status.status[0] = PCI_CFG_HFS_1, \ + .fw_status.status[1] = PCI_CFG_HFS_2, \ + .fw_status.status[2] = PCI_CFG_HFS_3, \ + .fw_status.status[3] = PCI_CFG_HFS_4, \ + .fw_status.status[4] = PCI_CFG_HFS_5, \ + .fw_status.status[5] = PCI_CFG_HFS_6 /* ICH Legacy devices */ const struct mei_cfg mei_me_legacy_cfg = { @@ -858,9 +866,14 @@ const struct mei_cfg mei_me_pch_cpt_pbg_cfg = { MEI_CFG_FW_NM, }; -/* PCH Lynx Point with quirk for SPS Firmware exclusion */ -const struct mei_cfg mei_me_lpt_cfg = { - MEI_CFG_PCH_HFS, +/* PCH8 Lynx Point and newer devices */ +const struct mei_cfg mei_me_pch8_cfg = { + MEI_CFG_PCH8_HFS, +}; + +/* PCH8 Lynx Point with quirk for SPS Firmware exclusion */ +const struct mei_cfg mei_me_pch8_sps_cfg = { + MEI_CFG_PCH8_HFS, MEI_CFG_FW_SPS, }; diff --git a/drivers/misc/mei/hw-me.h b/drivers/misc/mei/hw-me.h index e44ed1d..d6567af 100644 --- a/drivers/misc/mei/hw-me.h +++ b/drivers/misc/mei/hw-me.h @@ -65,7 +65,8 @@ extern const struct mei_cfg mei_me_legacy_cfg; extern const struct mei_cfg mei_me_ich_cfg; extern const struct mei_cfg mei_me_pch_cfg; extern const struct mei_cfg mei_me_pch_cpt_pbg_cfg; -extern const struct mei_cfg mei_me_lpt_cfg; +extern const struct mei_cfg mei_me_pch8_cfg; +extern const struct mei_cfg mei_me_pch8_sps_cfg; struct mei_device *mei_me_dev_init(struct pci_dev *pdev, const struct mei_cfg *cfg); diff --git a/drivers/misc/mei/hw-txe.c b/drivers/misc/mei/hw-txe.c index c5e1902..618ea72 100644 --- a/drivers/misc/mei/hw-txe.c +++ b/drivers/misc/mei/hw-txe.c @@ -700,11 +700,10 @@ static int mei_txe_write(struct mei_device *dev, mei_txe_input_ready_interrupt_enable(dev); if (!mei_txe_is_input_ready(dev)) { - struct mei_fw_status fw_status; + char fw_sts_str[MEI_FW_STATUS_STR_SZ]; - mei_fw_status(dev, &fw_status); - dev_err(dev->dev, "Input is not ready " FW_STS_FMT "\n", - FW_STS_PRM(fw_status)); + mei_fw_status_str(dev, fw_sts_str, MEI_FW_STATUS_STR_SZ); + dev_err(dev->dev, "Input is not ready %s\n", fw_sts_str); return -EAGAIN; } diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c index 7901d07..9306219 100644 --- a/drivers/misc/mei/init.c +++ b/drivers/misc/mei/init.c @@ -54,6 +54,35 @@ const char *mei_pg_state_str(enum mei_pg_state state) #undef MEI_PG_STATE } +/** + * mei_fw_status2str - convert fw status registers to printable string + * + * @fw_status: firmware status + * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ + * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ + * + * Return: number of bytes written or -EINVAL if buffer is to small + */ +ssize_t mei_fw_status2str(struct mei_fw_status *fw_status, + char *buf, size_t len) +{ + ssize_t cnt = 0; + int i; + + buf[0] = '\0'; + + if (len < MEI_FW_STATUS_STR_SZ) + return -EINVAL; + + for (i = 0; i < fw_status->count; i++) + cnt += scnprintf(buf + cnt, len - cnt, "%08X ", + fw_status->status[i]); + + /* drop last space */ + buf[cnt] = '\0'; + return cnt; +} +EXPORT_SYMBOL_GPL(mei_fw_status2str); /** * mei_cancel_work - Cancel mei background jobs @@ -86,12 +115,11 @@ int mei_reset(struct mei_device *dev) state != MEI_DEV_DISABLED && state != MEI_DEV_POWER_DOWN && state != MEI_DEV_POWER_UP) { - struct mei_fw_status fw_status; + char fw_sts_str[MEI_FW_STATUS_STR_SZ]; - mei_fw_status(dev, &fw_status); - dev_warn(dev->dev, - "unexpected reset: dev_state = %s " FW_STS_FMT "\n", - mei_dev_state_str(state), FW_STS_PRM(fw_status)); + mei_fw_status_str(dev, fw_sts_str, MEI_FW_STATUS_STR_SZ); + dev_warn(dev->dev, "unexpected reset: dev_state = %s fw status = %s\n", + mei_dev_state_str(state), fw_sts_str); } /* we're already in reset, cancel the init timer diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index 1288a5c..c90c16b 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h @@ -152,7 +152,10 @@ struct mei_msg_data { }; /* Maximum number of processed FW status registers */ -#define MEI_FW_STATUS_MAX 2 +#define MEI_FW_STATUS_MAX 6 +/* Minimal buffer for FW status string (8 bytes in dw + space or '\0') */ +#define MEI_FW_STATUS_STR_SZ (MEI_FW_STATUS_MAX * (8 + 1)) + /* * struct mei_fw_status - storage of FW status data @@ -805,11 +808,6 @@ static inline int mei_fw_status(struct mei_device *dev, return dev->ops->fw_status(dev, fw_status); } -#define FW_STS_FMT "%08X %08X" -#define FW_STS_PRM(fw_status) \ - (fw_status).count > 0 ? (fw_status).status[0] : 0xDEADBEEF, \ - (fw_status).count > 1 ? (fw_status).status[1] : 0xDEADBEEF - bool mei_hbuf_acquire(struct mei_device *dev); bool mei_write_is_idle(struct mei_device *dev); @@ -833,4 +831,32 @@ void mei_deregister(struct mei_device *dev); (hdr)->host_addr, (hdr)->me_addr, \ (hdr)->length, (hdr)->internal, (hdr)->msg_complete +ssize_t mei_fw_status2str(struct mei_fw_status *fw_sts, char *buf, size_t len); +/** + * mei_fw_status_str - fetch and convert fw status registers to printable string + * + * @dev: the device structure + * @buf: string buffer at minimal size MEI_FW_STATUS_STR_SZ + * @len: buffer len must be >= MEI_FW_STATUS_STR_SZ + * + * Return: number of bytes written or < 0 on failure + */ +static inline ssize_t mei_fw_status_str(struct mei_device *dev, + char *buf, size_t len) +{ + struct mei_fw_status fw_status; + int ret; + + buf[0] = '\0'; + + ret = mei_fw_status(dev, &fw_status); + if (ret) + return ret; + + ret = mei_fw_status2str(&fw_status, buf, MEI_FW_STATUS_STR_SZ); + + return ret; +} + + #endif diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c index f3225b1..b0da60f 100644 --- a/drivers/misc/mei/pci-me.c +++ b/drivers/misc/mei/pci-me.c @@ -76,12 +76,12 @@ static const struct pci_device_id mei_me_pci_tbl[] = { {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_1, mei_me_pch_cfg)}, {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_2, mei_me_pch_cfg)}, {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_3, mei_me_pch_cfg)}, - {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_H, mei_me_lpt_cfg)}, - {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_W, mei_me_lpt_cfg)}, - {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_LP, mei_me_pch_cfg)}, - {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_HR, mei_me_lpt_cfg)}, - {MEI_PCI_DEVICE(MEI_DEV_ID_WPT_LP, mei_me_pch_cfg)}, - {MEI_PCI_DEVICE(MEI_DEV_ID_WPT_LP_2, mei_me_pch_cfg)}, + {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_H, mei_me_pch8_sps_cfg)}, + {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_W, mei_me_pch8_sps_cfg)}, + {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_LP, mei_me_pch8_cfg)}, + {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_HR, mei_me_pch8_sps_cfg)}, + {MEI_PCI_DEVICE(MEI_DEV_ID_WPT_LP, mei_me_pch8_cfg)}, + {MEI_PCI_DEVICE(MEI_DEV_ID_WPT_LP_2, mei_me_pch8_cfg)}, /* required last entry */ {0, } -- cgit v1.1 From 55c4e6405d434e2db1e3fb3618b84741bb17d862 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Wed, 19 Nov 2014 17:01:39 +0200 Subject: mei: export fw status registers through sysfs The interface is for applications that monitor the fw health. We use device_create_with_groups interface to register attribute with the mei class device Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/main.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c index beedc91..ae56ba6 100644 --- a/drivers/misc/mei/main.c +++ b/drivers/misc/mei/main.c @@ -631,6 +631,44 @@ out: return mask; } +/** + * fw_status_show - mei device attribute show method + * + * @device: device pointer + * @attr: attribute pointer + * @buf: char out buffer + * + * Return: number of the bytes printed into buf or error + */ +static ssize_t fw_status_show(struct device *device, + struct device_attribute *attr, char *buf) +{ + struct mei_device *dev = dev_get_drvdata(device); + struct mei_fw_status fw_status; + int err, i; + ssize_t cnt = 0; + + mutex_lock(&dev->device_lock); + err = mei_fw_status(dev, &fw_status); + mutex_unlock(&dev->device_lock); + if (err) { + dev_err(device, "read fw_status error = %d\n", err); + return err; + } + + for (i = 0; i < fw_status.count; i++) + cnt += scnprintf(buf + cnt, PAGE_SIZE - cnt, "%08X\n", + fw_status.status[i]); + return cnt; +} +static DEVICE_ATTR_RO(fw_status); + +static struct attribute *mei_attrs[] = { + &dev_attr_fw_status.attr, + NULL +}; +ATTRIBUTE_GROUPS(mei); + /* * file operations structure will be used for mei char device. */ @@ -710,8 +748,9 @@ int mei_register(struct mei_device *dev, struct device *parent) goto err_dev_add; } - clsdev = device_create(mei_class, parent, devno, - NULL, "mei%d", dev->minor); + clsdev = device_create_with_groups(mei_class, parent, devno, + dev, mei_groups, + "mei%d", dev->minor); if (IS_ERR(clsdev)) { dev_err(parent, "unable to create device %d:%d\n", -- cgit v1.1 From 27bbcef20a47c1b0f1ec6cc6b0d27470dbcaa05a Mon Sep 17 00:00:00 2001 From: Ian Munsie Date: Fri, 14 Nov 2014 17:37:50 +1100 Subject: CXL: Return error to PSL if IRQ demultiplexing fails & print clearer warning If an AFU has a hardware bug that causes it to acknowledge a context terminate or remove while that context has outstanding transactions, it is possible for the kernel to receive an interrupt for that context after we have removed it from the context list. The kernel will not be able to demultiplex the interrupt (or worse - if we have already reallocated the process handle we could mis-attribute it to the new context), and printed a big scary warning. It did not acknowledge the interrupt, which would effectively halt further translation fault processing on the PSL. This patch makes the warning clearer about the likely cause of the issue (i.e. hardware bug) to make it obvious to future AFU designers of what needs to be fixed. It also prints out the process handle which can then be matched up with hardware and software traces for debugging. It also acknowledges the interrupt to the PSL with either an address error or acknowledge, so that the PSL can continue with other translations. Signed-off-by: Ian Munsie Signed-off-by: Greg Kroah-Hartman --- drivers/misc/cxl/cxl.h | 2 +- drivers/misc/cxl/irq.c | 46 +++++++++++++++++++++++++++++----------------- drivers/misc/cxl/native.c | 14 +++++++------- 3 files changed, 37 insertions(+), 25 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h index 3d2b867..64a4aa3 100644 --- a/drivers/misc/cxl/cxl.h +++ b/drivers/misc/cxl/cxl.h @@ -612,7 +612,7 @@ int cxl_attach_process(struct cxl_context *ctx, bool kernel, u64 wed, u64 amr); int cxl_detach_process(struct cxl_context *ctx); -int cxl_get_irq(struct cxl_context *ctx, struct cxl_irq_info *info); +int cxl_get_irq(struct cxl_afu *afu, struct cxl_irq_info *info); int cxl_ack_irq(struct cxl_context *ctx, u64 tfc, u64 psl_reset_mask); int cxl_check_error(struct cxl_afu *afu); diff --git a/drivers/misc/cxl/irq.c b/drivers/misc/cxl/irq.c index 336020c..35fcb3d 100644 --- a/drivers/misc/cxl/irq.c +++ b/drivers/misc/cxl/irq.c @@ -92,20 +92,13 @@ static irqreturn_t schedule_cxl_fault(struct cxl_context *ctx, u64 dsisr, u64 da return IRQ_HANDLED; } -static irqreturn_t cxl_irq(int irq, void *data) +static irqreturn_t cxl_irq(int irq, void *data, struct cxl_irq_info *irq_info) { struct cxl_context *ctx = data; - struct cxl_irq_info irq_info; u64 dsisr, dar; - int result; - if ((result = cxl_get_irq(ctx, &irq_info))) { - WARN(1, "Unable to get CXL IRQ Info: %i\n", result); - return IRQ_HANDLED; - } - - dsisr = irq_info.dsisr; - dar = irq_info.dar; + dsisr = irq_info->dsisr; + dar = irq_info->dar; pr_devel("CXL interrupt %i for afu pe: %i DSISR: %#llx DAR: %#llx\n", irq, ctx->pe, dsisr, dar); @@ -149,9 +142,9 @@ static irqreturn_t cxl_irq(int irq, void *data) if (dsisr & CXL_PSL_DSISR_An_UR) pr_devel("CXL interrupt: AURP PTE not found\n"); if (dsisr & CXL_PSL_DSISR_An_PE) - return handle_psl_slice_error(ctx, dsisr, irq_info.errstat); + return handle_psl_slice_error(ctx, dsisr, irq_info->errstat); if (dsisr & CXL_PSL_DSISR_An_AE) { - pr_devel("CXL interrupt: AFU Error %.llx\n", irq_info.afu_err); + pr_devel("CXL interrupt: AFU Error %.llx\n", irq_info->afu_err); if (ctx->pending_afu_err) { /* @@ -163,10 +156,10 @@ static irqreturn_t cxl_irq(int irq, void *data) */ dev_err_ratelimited(&ctx->afu->dev, "CXL AFU Error " "undelivered to pe %i: %.llx\n", - ctx->pe, irq_info.afu_err); + ctx->pe, irq_info->afu_err); } else { spin_lock(&ctx->lock); - ctx->afu_err = irq_info.afu_err; + ctx->afu_err = irq_info->afu_err; ctx->pending_afu_err = 1; spin_unlock(&ctx->lock); @@ -182,24 +175,43 @@ static irqreturn_t cxl_irq(int irq, void *data) return IRQ_HANDLED; } +static irqreturn_t fail_psl_irq(struct cxl_afu *afu, struct cxl_irq_info *irq_info) +{ + if (irq_info->dsisr & CXL_PSL_DSISR_TRANS) + cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_AE); + else + cxl_p2n_write(afu, CXL_PSL_TFC_An, CXL_PSL_TFC_An_A); + + return IRQ_HANDLED; +} + static irqreturn_t cxl_irq_multiplexed(int irq, void *data) { struct cxl_afu *afu = data; struct cxl_context *ctx; + struct cxl_irq_info irq_info; int ph = cxl_p2n_read(afu, CXL_PSL_PEHandle_An) & 0xffff; int ret; + if ((ret = cxl_get_irq(afu, &irq_info))) { + WARN(1, "Unable to get CXL IRQ Info: %i\n", ret); + return fail_psl_irq(afu, &irq_info); + } + rcu_read_lock(); ctx = idr_find(&afu->contexts_idr, ph); if (ctx) { - ret = cxl_irq(irq, ctx); + ret = cxl_irq(irq, ctx, &irq_info); rcu_read_unlock(); return ret; } rcu_read_unlock(); - WARN(1, "Unable to demultiplex CXL PSL IRQ\n"); - return IRQ_HANDLED; + WARN(1, "Unable to demultiplex CXL PSL IRQ for PE %i DSISR %.16llx DAR" + " %.16llx\n(Possible AFU HW issue - was a term/remove acked" + " with outstanding transactions?)\n", ph, irq_info.dsisr, + irq_info.dar); + return fail_psl_irq(afu, &irq_info); } static irqreturn_t cxl_irq_afu(int irq, void *data) diff --git a/drivers/misc/cxl/native.c b/drivers/misc/cxl/native.c index d47532e..9a5a442 100644 --- a/drivers/misc/cxl/native.c +++ b/drivers/misc/cxl/native.c @@ -637,18 +637,18 @@ int cxl_detach_process(struct cxl_context *ctx) return detach_process_native_afu_directed(ctx); } -int cxl_get_irq(struct cxl_context *ctx, struct cxl_irq_info *info) +int cxl_get_irq(struct cxl_afu *afu, struct cxl_irq_info *info) { u64 pidtid; - info->dsisr = cxl_p2n_read(ctx->afu, CXL_PSL_DSISR_An); - info->dar = cxl_p2n_read(ctx->afu, CXL_PSL_DAR_An); - info->dsr = cxl_p2n_read(ctx->afu, CXL_PSL_DSR_An); - pidtid = cxl_p2n_read(ctx->afu, CXL_PSL_PID_TID_An); + info->dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); + info->dar = cxl_p2n_read(afu, CXL_PSL_DAR_An); + info->dsr = cxl_p2n_read(afu, CXL_PSL_DSR_An); + pidtid = cxl_p2n_read(afu, CXL_PSL_PID_TID_An); info->pid = pidtid >> 32; info->tid = pidtid & 0xffffffff; - info->afu_err = cxl_p2n_read(ctx->afu, CXL_AFU_ERR_An); - info->errstat = cxl_p2n_read(ctx->afu, CXL_PSL_ErrStat_An); + info->afu_err = cxl_p2n_read(afu, CXL_AFU_ERR_An); + info->errstat = cxl_p2n_read(afu, CXL_PSL_ErrStat_An); return 0; } -- cgit v1.1 From ca4f8280ff227e215f44e10f8f110b4c882b084b Mon Sep 17 00:00:00 2001 From: Michael Neuling Date: Fri, 14 Nov 2014 18:09:28 +1100 Subject: cxl: Name interrupts in /proc/interrupt Currently all interrupts generated by cxl are named "cxl". This is not very informative as we can't distinguish between cards, AFUs, error interrupts, user contexts and user interrupts numbers. Being able to distinguish them is useful for setting affinity. This patch gives each of these names in /proc/interrupts. A two card CAPI system, with afu0.0 having 2 active contexts each with 4 user IRQs each, will now look like this: % grep cxl /proc/interrupts 444: 0 OPAL ICS 141312 Level cxl-card1-err 445: 0 OPAL ICS 141313 Level cxl-afu1.0-err 446: 0 OPAL ICS 141314 Level cxl-afu1.0 462: 0 OPAL ICS 2052 Level cxl-afu0.0-pe0-1 463: 75517 OPAL ICS 2053 Level cxl-afu0.0-pe0-2 468: 0 OPAL ICS 2054 Level cxl-afu0.0-pe0-3 469: 0 OPAL ICS 2055 Level cxl-afu0.0-pe0-4 470: 0 OPAL ICS 2056 Level cxl-afu0.0-pe1-1 471: 75506 OPAL ICS 2057 Level cxl-afu0.0-pe1-2 472: 0 OPAL ICS 2058 Level cxl-afu0.0-pe1-3 473: 0 OPAL ICS 2059 Level cxl-afu0.0-pe1-4 502: 1066 OPAL ICS 2050 Level cxl-afu0.0 514: 0 OPAL ICS 2048 Level cxl-card0-err 515: 0 OPAL ICS 2049 Level cxl-afu0.0-err Signed-off-by: Michael Neuling Signed-off-by: Ian Munsie Signed-off-by: Greg Kroah-Hartman --- drivers/misc/cxl/cxl.h | 13 +++++-- drivers/misc/cxl/irq.c | 98 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 98 insertions(+), 13 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h index 64a4aa3..b5b6bda 100644 --- a/drivers/misc/cxl/cxl.h +++ b/drivers/misc/cxl/cxl.h @@ -336,6 +336,8 @@ struct cxl_sste { struct cxl_afu { irq_hw_number_t psl_hwirq; irq_hw_number_t serr_hwirq; + char *err_irq_name; + char *psl_irq_name; unsigned int serr_virq; void __iomem *p1n_mmio; void __iomem *p2n_mmio; @@ -379,6 +381,12 @@ struct cxl_afu { bool enabled; }; + +struct cxl_irq_name { + struct list_head list; + char *name; +}; + /* * This is a cxl context. If the PSL is in dedicated mode, there will be one * of these per AFU. If in AFU directed there can be lots of these. @@ -403,6 +411,7 @@ struct cxl_context { unsigned long *irq_bitmap; /* Accessed from IRQ context */ struct cxl_irq_ranges irqs; + struct list_head irq_names; u64 fault_addr; u64 fault_dsisr; u64 afu_err; @@ -444,6 +453,7 @@ struct cxl { struct dentry *trace; struct dentry *psl_err_chk; struct dentry *debugfs; + char *irq_name; struct bin_attribute cxl_attr; int adapter_num; int user_irqs; @@ -563,9 +573,6 @@ int _cxl_afu_deactivate_mode(struct cxl_afu *afu, int mode); int cxl_afu_deactivate_mode(struct cxl_afu *afu); int cxl_afu_select_best_mode(struct cxl_afu *afu); -unsigned int cxl_map_irq(struct cxl *adapter, irq_hw_number_t hwirq, - irq_handler_t handler, void *cookie); -void cxl_unmap_irq(unsigned int virq, void *cookie); int cxl_register_psl_irq(struct cxl_afu *afu); void cxl_release_psl_irq(struct cxl_afu *afu); int cxl_register_psl_err_irq(struct cxl *adapter); diff --git a/drivers/misc/cxl/irq.c b/drivers/misc/cxl/irq.c index 35fcb3d..08fb4a7 100644 --- a/drivers/misc/cxl/irq.c +++ b/drivers/misc/cxl/irq.c @@ -255,7 +255,7 @@ static irqreturn_t cxl_irq_afu(int irq, void *data) } unsigned int cxl_map_irq(struct cxl *adapter, irq_hw_number_t hwirq, - irq_handler_t handler, void *cookie) + irq_handler_t handler, void *cookie, const char *name) { unsigned int virq; int result; @@ -271,7 +271,7 @@ unsigned int cxl_map_irq(struct cxl *adapter, irq_hw_number_t hwirq, pr_devel("hwirq %#lx mapped to virq %u\n", hwirq, virq); - result = request_irq(virq, handler, 0, "cxl", cookie); + result = request_irq(virq, handler, 0, name, cookie); if (result) { dev_warn(&adapter->dev, "cxl_map_irq: request_irq failed: %i\n", result); return 0; @@ -290,14 +290,15 @@ static int cxl_register_one_irq(struct cxl *adapter, irq_handler_t handler, void *cookie, irq_hw_number_t *dest_hwirq, - unsigned int *dest_virq) + unsigned int *dest_virq, + const char *name) { int hwirq, virq; if ((hwirq = cxl_alloc_one_irq(adapter)) < 0) return hwirq; - if (!(virq = cxl_map_irq(adapter, hwirq, handler, cookie))) + if (!(virq = cxl_map_irq(adapter, hwirq, handler, cookie, name))) goto err; *dest_hwirq = hwirq; @@ -314,10 +315,19 @@ int cxl_register_psl_err_irq(struct cxl *adapter) { int rc; + adapter->irq_name = kasprintf(GFP_KERNEL,"cxl-%s-err", + dev_name(&adapter->dev)); + if (!adapter->irq_name) + return -ENOMEM; + if ((rc = cxl_register_one_irq(adapter, cxl_irq_err, adapter, &adapter->err_hwirq, - &adapter->err_virq))) + &adapter->err_virq, + adapter->irq_name))) { + kfree(adapter->irq_name); + adapter->irq_name = NULL; return rc; + } cxl_p1_write(adapter, CXL_PSL_ErrIVTE, adapter->err_hwirq & 0xffff); @@ -329,6 +339,7 @@ void cxl_release_psl_err_irq(struct cxl *adapter) cxl_p1_write(adapter, CXL_PSL_ErrIVTE, 0x0000000000000000); cxl_unmap_irq(adapter->err_virq, adapter); cxl_release_one_irq(adapter, adapter->err_hwirq); + kfree(adapter->irq_name); } int cxl_register_serr_irq(struct cxl_afu *afu) @@ -336,10 +347,18 @@ int cxl_register_serr_irq(struct cxl_afu *afu) u64 serr; int rc; + afu->err_irq_name = kasprintf(GFP_KERNEL,"cxl-%s-err", + dev_name(&afu->dev)); + if (!afu->err_irq_name) + return -ENOMEM; + if ((rc = cxl_register_one_irq(afu->adapter, cxl_slice_irq_err, afu, &afu->serr_hwirq, - &afu->serr_virq))) + &afu->serr_virq, afu->err_irq_name))) { + kfree(afu->err_irq_name); + afu->err_irq_name = NULL; return rc; + } serr = cxl_p1n_read(afu, CXL_PSL_SERR_An); serr = (serr & 0x00ffffffffff0000ULL) | (afu->serr_hwirq & 0xffff); @@ -353,24 +372,50 @@ void cxl_release_serr_irq(struct cxl_afu *afu) cxl_p1n_write(afu, CXL_PSL_SERR_An, 0x0000000000000000); cxl_unmap_irq(afu->serr_virq, afu); cxl_release_one_irq(afu->adapter, afu->serr_hwirq); + kfree(afu->err_irq_name); } int cxl_register_psl_irq(struct cxl_afu *afu) { - return cxl_register_one_irq(afu->adapter, cxl_irq_multiplexed, afu, - &afu->psl_hwirq, &afu->psl_virq); + int rc; + + afu->psl_irq_name = kasprintf(GFP_KERNEL,"cxl-%s", + dev_name(&afu->dev)); + if (!afu->psl_irq_name) + return -ENOMEM; + + if ((rc = cxl_register_one_irq(afu->adapter, cxl_irq_multiplexed, afu, + &afu->psl_hwirq, &afu->psl_virq, + afu->psl_irq_name))) { + kfree(afu->psl_irq_name); + afu->psl_irq_name = NULL; + } + return rc; } void cxl_release_psl_irq(struct cxl_afu *afu) { cxl_unmap_irq(afu->psl_virq, afu); cxl_release_one_irq(afu->adapter, afu->psl_hwirq); + kfree(afu->psl_irq_name); +} + +void afu_irq_name_free(struct cxl_context *ctx) +{ + struct cxl_irq_name *irq_name, *tmp; + + list_for_each_entry_safe(irq_name, tmp, &ctx->irq_names, list) { + kfree(irq_name->name); + list_del(&irq_name->list); + kfree(irq_name); + } } int afu_register_irqs(struct cxl_context *ctx, u32 count) { irq_hw_number_t hwirq; - int rc, r, i; + int rc, r, i, j = 1; + struct cxl_irq_name *irq_name; if ((rc = cxl_alloc_irq_ranges(&ctx->irqs, ctx->afu->adapter, count))) return rc; @@ -384,15 +429,47 @@ int afu_register_irqs(struct cxl_context *ctx, u32 count) sizeof(*ctx->irq_bitmap), GFP_KERNEL); if (!ctx->irq_bitmap) return -ENOMEM; + + /* + * Allocate names first. If any fail, bail out before allocating + * actual hardware IRQs. + */ + INIT_LIST_HEAD(&ctx->irq_names); + for (r = 1; r < CXL_IRQ_RANGES; r++) { + for (i = 0; i < ctx->irqs.range[r]; hwirq++, i++) { + irq_name = kmalloc(sizeof(struct cxl_irq_name), + GFP_KERNEL); + if (!irq_name) + goto out; + irq_name->name = kasprintf(GFP_KERNEL, "cxl-%s-pe%i-%i", + dev_name(&ctx->afu->dev), + ctx->pe, j); + if (!irq_name->name) { + kfree(irq_name); + goto out; + } + /* Add to tail so next look get the correct order */ + list_add_tail(&irq_name->list, &ctx->irq_names); + j++; + } + } + + /* We've allocated all memory now, so let's do the irq allocations */ + irq_name = list_first_entry(&ctx->irq_names, struct cxl_irq_name, list); for (r = 1; r < CXL_IRQ_RANGES; r++) { hwirq = ctx->irqs.offset[r]; for (i = 0; i < ctx->irqs.range[r]; hwirq++, i++) { cxl_map_irq(ctx->afu->adapter, hwirq, - cxl_irq_afu, ctx); + cxl_irq_afu, ctx, irq_name->name); + irq_name = list_next_entry(irq_name, list); } } return 0; + +out: + afu_irq_name_free(ctx); + return -ENOMEM; } void afu_release_irqs(struct cxl_context *ctx) @@ -410,5 +487,6 @@ void afu_release_irqs(struct cxl_context *ctx) } } + afu_irq_name_free(ctx); cxl_release_irq_ranges(&ctx->irqs, ctx->afu->adapter); } -- cgit v1.1 From e976a725e075be8efe6950735603c88dd6e01be0 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sun, 23 Nov 2014 15:23:48 +0100 Subject: carma-fpga-program.c: fix compile errors drivers/misc/carma/carma-fpga-program.c: In function 'fpga_program_dma': drivers/misc/carma/carma-fpga-program.c:529:2: error: expected ';' before 'if' if (ret) { ^ drivers/misc/carma/carma-fpga-program.c: In function 'fpga_read': drivers/misc/carma/carma-fpga-program.c:752:45: error: 'ppos' undeclared (first use in this function) return simple_read_from_buffer(buf, count, ppos, ^ drivers/misc/carma/carma-fpga-program.c:752:45: note: each undeclared identifier is reported only once for each function it appears in drivers/misc/carma/carma-fpga-program.c: In function 'fpga_llseek': drivers/misc/carma/carma-fpga-program.c:765:27: error: 'file' undeclared (first use in this function) return fixed_size_llseek(file, offset, origin, priv->fw_size); ^ drivers/misc/carma/carma-fpga-program.c:759:9: warning: unused variable 'newpos' [-Wunused-variable] loff_t newpos; ^ drivers/misc/carma/carma-fpga-program.c: In function 'fpga_read': drivers/misc/carma/carma-fpga-program.c:754:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ drivers/misc/carma/carma-fpga-program.c: In function 'fpga_llseek': drivers/misc/carma/carma-fpga-program.c:766:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ scripts/Makefile.build:263: recipe for target 'drivers/misc/carma/carma-fpga-program.o' failed Signed-off-by: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/misc/carma/carma-fpga-program.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/carma/carma-fpga-program.c b/drivers/misc/carma/carma-fpga-program.c index 339b252..eb8942b 100644 --- a/drivers/misc/carma/carma-fpga-program.c +++ b/drivers/misc/carma/carma-fpga-program.c @@ -525,7 +525,7 @@ static noinline int fpga_program_dma(struct fpga_dev *priv) goto out_dma_unmap; } - ret = fsl_dma_external_start(chan, 1) + ret = fsl_dma_external_start(chan, 1); if (ret) { dev_err(priv->dev, "DMA external control setup failed\n"); goto out_dma_unmap; @@ -749,20 +749,19 @@ static ssize_t fpga_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos) { struct fpga_dev *priv = filp->private_data; - return simple_read_from_buffer(buf, count, ppos, + return simple_read_from_buffer(buf, count, f_pos, priv->vb.vaddr, priv->bytes); } static loff_t fpga_llseek(struct file *filp, loff_t offset, int origin) { struct fpga_dev *priv = filp->private_data; - loff_t newpos; /* only read-only opens are allowed to seek */ if ((filp->f_flags & O_ACCMODE) != O_RDONLY) return -EINVAL; - return fixed_size_llseek(file, offset, origin, priv->fw_size); + return fixed_size_llseek(filp, offset, origin, priv->fw_size); } static const struct file_operations fpga_fops = { -- cgit v1.1 From 27361ff56d88d6cae16bd032aa94898c45b7ec4c Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sun, 23 Nov 2014 15:23:49 +0100 Subject: carma-fpga: drop videobuf dependency This driver abuses videobuf helper functions. This is a bad idea because: 1) this driver is completely unrelated to media drivers 2) the videobuf API is deprecated and will be removed eventually This patch replaces the videobuf functions with the normal DMA kernel API. Signed-off-by: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/misc/carma/Kconfig | 3 +- drivers/misc/carma/carma-fpga.c | 98 ++++++++++++++++++++++++++++++++++------- 2 files changed, 82 insertions(+), 19 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/carma/Kconfig b/drivers/misc/carma/Kconfig index c90370e..c6047fb 100644 --- a/drivers/misc/carma/Kconfig +++ b/drivers/misc/carma/Kconfig @@ -1,7 +1,6 @@ config CARMA_FPGA tristate "CARMA DATA-FPGA Access Driver" - depends on FSL_SOC && PPC_83xx && MEDIA_SUPPORT && HAS_DMA && FSL_DMA - select VIDEOBUF_DMA_SG + depends on FSL_SOC && PPC_83xx && HAS_DMA && FSL_DMA default n help Say Y here to include support for communicating with the data diff --git a/drivers/misc/carma/carma-fpga.c b/drivers/misc/carma/carma-fpga.c index 55e913b..5b12149 100644 --- a/drivers/misc/carma/carma-fpga.c +++ b/drivers/misc/carma/carma-fpga.c @@ -98,6 +98,7 @@ #include #include #include +#include #include #include #include @@ -105,8 +106,6 @@ #include #include -#include - /* system controller registers */ #define SYS_IRQ_SOURCE_CTL 0x24 #define SYS_IRQ_OUTPUT_EN 0x28 @@ -142,7 +141,10 @@ struct fpga_info { struct data_buf { struct list_head entry; - struct videobuf_dmabuf vb; + void *vaddr; + struct scatterlist *sglist; + int sglen; + int nr_pages; size_t size; }; @@ -207,6 +209,68 @@ static void fpga_device_release(struct kref *ref) * Data Buffer Allocation Helpers */ +static int carma_dma_init(struct data_buf *buf, int nr_pages) +{ + struct page *pg; + int i; + + buf->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT); + if (NULL == buf->vaddr) { + pr_debug("vmalloc_32(%d pages) failed\n", nr_pages); + return -ENOMEM; + } + + pr_debug("vmalloc is at addr 0x%08lx, size=%d\n", + (unsigned long)buf->vaddr, + nr_pages << PAGE_SHIFT); + + memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); + buf->nr_pages = nr_pages; + + buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist)); + if (NULL == buf->sglist) + goto vzalloc_err; + + sg_init_table(buf->sglist, buf->nr_pages); + for (i = 0; i < buf->nr_pages; i++) { + pg = vmalloc_to_page(buf->vaddr + i * PAGE_SIZE); + if (NULL == pg) + goto vmalloc_to_page_err; + sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0); + } + return 0; + +vmalloc_to_page_err: + vfree(buf->sglist); + buf->sglist = NULL; +vzalloc_err: + vfree(buf->vaddr); + buf->vaddr = NULL; + return -ENOMEM; +} + +static int carma_dma_map(struct device *dev, struct data_buf *buf) +{ + buf->sglen = dma_map_sg(dev, buf->sglist, + buf->nr_pages, DMA_FROM_DEVICE); + + if (0 == buf->sglen) { + pr_warn("%s: dma_map_sg failed\n", __func__); + return -ENOMEM; + } + return 0; +} + +static int carma_dma_unmap(struct device *dev, struct data_buf *buf) +{ + if (!buf->sglen) + return 0; + + dma_unmap_sg(dev, buf->sglist, buf->sglen, DMA_FROM_DEVICE); + buf->sglen = 0; + return 0; +} + /** * data_free_buffer() - free a single data buffer and all allocated memory * @buf: the buffer to free @@ -221,7 +285,8 @@ static void data_free_buffer(struct data_buf *buf) return; /* free all memory */ - videobuf_dma_free(&buf->vb); + vfree(buf->sglist); + vfree(buf->vaddr); kfree(buf); } @@ -230,7 +295,7 @@ static void data_free_buffer(struct data_buf *buf) * @bytes: the number of bytes required * * This allocates all space needed for a data buffer. It must be mapped before - * use in a DMA transaction using videobuf_dma_map(). + * use in a DMA transaction using carma_dma_map(). * * Returns NULL on failure */ @@ -252,9 +317,8 @@ static struct data_buf *data_alloc_buffer(const size_t bytes) INIT_LIST_HEAD(&buf->entry); buf->size = bytes; - /* allocate the videobuf */ - videobuf_dma_init(&buf->vb); - ret = videobuf_dma_init_kernel(&buf->vb, DMA_FROM_DEVICE, nr_pages); + /* allocate the buffer */ + ret = carma_dma_init(buf, nr_pages); if (ret) goto out_free_buf; @@ -285,13 +349,13 @@ static void data_free_buffers(struct fpga_device *priv) list_for_each_entry_safe(buf, tmp, &priv->free, entry) { list_del_init(&buf->entry); - videobuf_dma_unmap(priv->dev, &buf->vb); + carma_dma_unmap(priv->dev, buf); data_free_buffer(buf); } list_for_each_entry_safe(buf, tmp, &priv->used, entry) { list_del_init(&buf->entry); - videobuf_dma_unmap(priv->dev, &buf->vb); + carma_dma_unmap(priv->dev, buf); data_free_buffer(buf); } @@ -330,7 +394,7 @@ static int data_alloc_buffers(struct fpga_device *priv) break; /* map it for DMA */ - ret = videobuf_dma_map(priv->dev, &buf->vb); + ret = carma_dma_map(priv->dev, buf); if (ret) { data_free_buffer(buf); break; @@ -634,8 +698,8 @@ static int data_submit_dma(struct fpga_device *priv, struct data_buf *buf) dma_addr_t dst, src; unsigned long dma_flags = 0; - dst_sg = buf->vb.sglist; - dst_nents = buf->vb.sglen; + dst_sg = buf->sglist; + dst_nents = buf->sglen; src_sg = priv->corl_table.sgl; src_nents = priv->corl_nents; @@ -1134,7 +1198,7 @@ static ssize_t data_read(struct file *filp, char __user *ubuf, size_t count, spin_unlock_irq(&priv->lock); /* Buffers are always mapped: unmap it */ - videobuf_dma_unmap(priv->dev, &dbuf->vb); + carma_dma_unmap(priv->dev, dbuf); /* save the buffer for later */ reader->buf = dbuf; @@ -1143,7 +1207,7 @@ static ssize_t data_read(struct file *filp, char __user *ubuf, size_t count, have_buffer: /* Get the number of bytes available */ avail = dbuf->size - reader->buf_start; - data = dbuf->vb.vaddr + reader->buf_start; + data = dbuf->vaddr + reader->buf_start; /* Get the number of bytes we can transfer */ count = min(count, avail); @@ -1171,7 +1235,7 @@ have_buffer: * If it fails, we pretend that the read never happed and return * -EFAULT to userspace. The read will be retried. */ - ret = videobuf_dma_map(priv->dev, &dbuf->vb); + ret = carma_dma_map(priv->dev, dbuf); if (ret) { dev_err(priv->dev, "unable to remap buffer for DMA\n"); return -EFAULT; @@ -1203,7 +1267,7 @@ out_unlock: spin_unlock_irq(&priv->lock); if (drop_buffer) { - videobuf_dma_unmap(priv->dev, &dbuf->vb); + carma_dma_unmap(priv->dev, dbuf); data_free_buffer(dbuf); } -- cgit v1.1 From 2180a0d41a896ea590868cded5fb22de297c6b72 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sun, 23 Nov 2014 15:23:50 +0100 Subject: carma-fpga-program: drop videobuf dependency This driver abuses videobuf helper functions. This is a bad idea because: 1) this driver is completely unrelated to media drivers 2) the videobuf API is deprecated and will be removed eventually This patch replaces the videobuf functions with the normal DMA kernel API. Signed-off-by: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/misc/carma/Kconfig | 3 +- drivers/misc/carma/carma-fpga-program.c | 97 +++++++++++++++++++++++++++------ 2 files changed, 81 insertions(+), 19 deletions(-) (limited to 'drivers/misc') diff --git a/drivers/misc/carma/Kconfig b/drivers/misc/carma/Kconfig index c6047fb..295882b 100644 --- a/drivers/misc/carma/Kconfig +++ b/drivers/misc/carma/Kconfig @@ -8,8 +8,7 @@ config CARMA_FPGA config CARMA_FPGA_PROGRAM tristate "CARMA DATA-FPGA Programmer" - depends on FSL_SOC && PPC_83xx && MEDIA_SUPPORT && HAS_DMA && FSL_DMA - select VIDEOBUF_DMA_SG + depends on FSL_SOC && PPC_83xx && HAS_DMA && FSL_DMA default n help Say Y here to include support for programming the data processing diff --git a/drivers/misc/carma/carma-fpga-program.c b/drivers/misc/carma/carma-fpga-program.c index eb8942b..a7496e3 100644 --- a/drivers/misc/carma/carma-fpga-program.c +++ b/drivers/misc/carma/carma-fpga-program.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -30,8 +31,6 @@ #include #include -#include - /* MPC8349EMDS specific get_immrbase() */ #include @@ -67,14 +66,79 @@ struct fpga_dev { /* FPGA Bitfile */ struct mutex lock; - struct videobuf_dmabuf vb; - bool vb_allocated; + void *vaddr; + struct scatterlist *sglist; + int sglen; + int nr_pages; + bool buf_allocated; /* max size and written bytes */ size_t fw_size; size_t bytes; }; +static int fpga_dma_init(struct fpga_dev *priv, int nr_pages) +{ + struct page *pg; + int i; + + priv->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT); + if (NULL == priv->vaddr) { + pr_debug("vmalloc_32(%d pages) failed\n", nr_pages); + return -ENOMEM; + } + + pr_debug("vmalloc is at addr 0x%08lx, size=%d\n", + (unsigned long)priv->vaddr, + nr_pages << PAGE_SHIFT); + + memset(priv->vaddr, 0, nr_pages << PAGE_SHIFT); + priv->nr_pages = nr_pages; + + priv->sglist = vzalloc(priv->nr_pages * sizeof(*priv->sglist)); + if (NULL == priv->sglist) + goto vzalloc_err; + + sg_init_table(priv->sglist, priv->nr_pages); + for (i = 0; i < priv->nr_pages; i++) { + pg = vmalloc_to_page(priv->vaddr + i * PAGE_SIZE); + if (NULL == pg) + goto vmalloc_to_page_err; + sg_set_page(&priv->sglist[i], pg, PAGE_SIZE, 0); + } + return 0; + +vmalloc_to_page_err: + vfree(priv->sglist); + priv->sglist = NULL; +vzalloc_err: + vfree(priv->vaddr); + priv->vaddr = NULL; + return -ENOMEM; +} + +static int fpga_dma_map(struct fpga_dev *priv) +{ + priv->sglen = dma_map_sg(priv->dev, priv->sglist, + priv->nr_pages, DMA_TO_DEVICE); + + if (0 == priv->sglen) { + pr_warn("%s: dma_map_sg failed\n", __func__); + return -ENOMEM; + } + return 0; +} + +static int fpga_dma_unmap(struct fpga_dev *priv) +{ + if (!priv->sglen) + return 0; + + dma_unmap_sg(priv->dev, priv->sglist, priv->sglen, DMA_TO_DEVICE); + priv->sglen = 0; + return 0; +} + /* * FPGA Bitfile Helpers */ @@ -87,8 +151,9 @@ struct fpga_dev { */ static void fpga_drop_firmware_data(struct fpga_dev *priv) { - videobuf_dma_free(&priv->vb); - priv->vb_allocated = false; + vfree(priv->sglist); + vfree(priv->vaddr); + priv->buf_allocated = false; priv->bytes = 0; } @@ -427,7 +492,7 @@ static noinline int fpga_program_cpu(struct fpga_dev *priv) dev_dbg(priv->dev, "enabled the controller\n"); /* Write each chunk of the FPGA bitfile to FPGA programmer */ - ret = fpga_program_block(priv, priv->vb.vaddr, priv->bytes); + ret = fpga_program_block(priv, priv->vaddr, priv->bytes); if (ret) goto out_disable_controller; @@ -463,7 +528,6 @@ out_disable_controller: */ static noinline int fpga_program_dma(struct fpga_dev *priv) { - struct videobuf_dmabuf *vb = &priv->vb; struct dma_chan *chan = priv->chan; struct dma_async_tx_descriptor *tx; size_t num_pages, len, avail = 0; @@ -505,7 +569,7 @@ static noinline int fpga_program_dma(struct fpga_dev *priv) } /* Map the buffer for DMA */ - ret = videobuf_dma_map(priv->dev, &priv->vb); + ret = fpga_dma_map(priv); if (ret) { dev_err(priv->dev, "Unable to map buffer for DMA\n"); goto out_free_table; @@ -534,7 +598,7 @@ static noinline int fpga_program_dma(struct fpga_dev *priv) /* setup and submit the DMA transaction */ tx = dmaengine_prep_dma_sg(chan, table.sgl, num_pages, - vb->sglist, vb->sglen, 0); + priv->sglist, priv->sglen, 0); if (!tx) { dev_err(priv->dev, "Unable to prep DMA transaction\n"); ret = -ENOMEM; @@ -572,7 +636,7 @@ static noinline int fpga_program_dma(struct fpga_dev *priv) out_disable_controller: fpga_programmer_disable(priv); out_dma_unmap: - videobuf_dma_unmap(priv->dev, vb); + fpga_dma_unmap(priv); out_free_table: sg_free_table(&table); out_return: @@ -702,12 +766,12 @@ static int fpga_open(struct inode *inode, struct file *filp) priv->bytes = 0; /* Check if we have already allocated a buffer */ - if (priv->vb_allocated) + if (priv->buf_allocated) return 0; /* Allocate a buffer to hold enough data for the bitfile */ nr_pages = DIV_ROUND_UP(priv->fw_size, PAGE_SIZE); - ret = videobuf_dma_init_kernel(&priv->vb, DMA_TO_DEVICE, nr_pages); + ret = fpga_dma_init(priv, nr_pages); if (ret) { dev_err(priv->dev, "unable to allocate data buffer\n"); mutex_unlock(&priv->lock); @@ -715,7 +779,7 @@ static int fpga_open(struct inode *inode, struct file *filp) return ret; } - priv->vb_allocated = true; + priv->buf_allocated = true; return 0; } @@ -738,7 +802,7 @@ static ssize_t fpga_write(struct file *filp, const char __user *buf, return -ENOSPC; count = min_t(size_t, priv->fw_size - priv->bytes, count); - if (copy_from_user(priv->vb.vaddr + priv->bytes, buf, count)) + if (copy_from_user(priv->vaddr + priv->bytes, buf, count)) return -EFAULT; priv->bytes += count; @@ -750,7 +814,7 @@ static ssize_t fpga_read(struct file *filp, char __user *buf, size_t count, { struct fpga_dev *priv = filp->private_data; return simple_read_from_buffer(buf, count, f_pos, - priv->vb.vaddr, priv->bytes); + priv->vaddr, priv->bytes); } static loff_t fpga_llseek(struct file *filp, loff_t offset, int origin) @@ -952,7 +1016,6 @@ static int fpga_of_probe(struct platform_device *op) priv->dev = &op->dev; mutex_init(&priv->lock); init_completion(&priv->completion); - videobuf_dma_init(&priv->vb); dev_set_drvdata(priv->dev, priv); dma_cap_zero(mask); -- cgit v1.1