diff options
Diffstat (limited to 'drivers/staging/mei')
-rw-r--r-- | drivers/staging/mei/TODO | 3 | ||||
-rw-r--r-- | drivers/staging/mei/hw.h | 47 | ||||
-rw-r--r-- | drivers/staging/mei/init.c | 24 | ||||
-rw-r--r-- | drivers/staging/mei/interface.c | 72 | ||||
-rw-r--r-- | drivers/staging/mei/interface.h | 7 | ||||
-rw-r--r-- | drivers/staging/mei/interrupt.c | 106 | ||||
-rw-r--r-- | drivers/staging/mei/iorw.c | 17 | ||||
-rw-r--r-- | drivers/staging/mei/main.c | 14 | ||||
-rw-r--r-- | drivers/staging/mei/mei-amt-version.c | 481 | ||||
-rw-r--r-- | drivers/staging/mei/mei.h | 127 | ||||
-rw-r--r-- | drivers/staging/mei/mei.txt | 6 | ||||
-rw-r--r-- | drivers/staging/mei/mei_dev.h | 10 | ||||
-rw-r--r-- | drivers/staging/mei/mei_version.h | 31 | ||||
-rw-r--r-- | drivers/staging/mei/wd.c | 8 |
14 files changed, 687 insertions, 266 deletions
diff --git a/drivers/staging/mei/TODO b/drivers/staging/mei/TODO index 7d9a13b0f2d..fc266018355 100644 --- a/drivers/staging/mei/TODO +++ b/drivers/staging/mei/TODO @@ -3,5 +3,8 @@ TODO: Upon Unstaging: - move mei.h to include/linux/mei.h - Documentation/ioctl/ioctl-number.txt + - move mei.txt under Documentation/mei/ + - move mei-amt-version.c under Documentation/mei + - add hostprogs-y for mei-amt-version.c - drop mei_version.h - Updated MAINTAINERS diff --git a/drivers/staging/mei/hw.h b/drivers/staging/mei/hw.h index 9b9008cb693..24c4c962819 100644 --- a/drivers/staging/mei/hw.h +++ b/drivers/staging/mei/hw.h @@ -1,7 +1,7 @@ /* * * Intel Management Engine Interface (Intel MEI) Linux driver - * Copyright (c) 2003-2011, Intel Corporation. + * Copyright (c) 2003-2012, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -141,6 +141,11 @@ access to ME_CBD */ #define HBM_MAJOR_VERSION 1 #define HBM_TIMEOUT 1 /* 1 second */ +/* Host bus message command opcode */ +#define MEI_HBM_CMD_OP_MSK 0x7f +/* Host bus message command RESPONSE */ +#define MEI_HBM_CMD_RES_MSK 0x80 + /* * MEI Bus Message Command IDs */ @@ -164,7 +169,7 @@ access to ME_CBD */ #define CLIENT_DISCONNECT_REQ_CMD 0x07 #define CLIENT_DISCONNECT_RES_CMD 0x87 -#define MEI_FLOW_CONTROL_CMD 0x08 +#define MEI_FLOW_CONTROL_CMD 0x08 /* * MEI Stop Reason @@ -213,15 +218,9 @@ struct mei_msg_hdr { } __packed; -struct hbm_cmd { - u8 cmd:7; - u8 is_response:1; -} __packed; - - struct mei_bus_message { - struct hbm_cmd cmd; - u8 command_specific_data[]; + u8 hbm_cmd; + u8 data[0]; } __packed; struct hbm_version { @@ -230,41 +229,41 @@ struct hbm_version { } __packed; struct hbm_host_version_request { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 reserved; struct hbm_version host_version; } __packed; struct hbm_host_version_response { - struct hbm_cmd cmd; - int host_version_supported; + u8 hbm_cmd; + u8 host_version_supported; struct hbm_version me_max_version; } __packed; struct hbm_host_stop_request { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 reason; u8 reserved[2]; } __packed; struct hbm_host_stop_response { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 reserved[3]; } __packed; struct hbm_me_stop_request { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 reason; u8 reserved[2]; } __packed; struct hbm_host_enum_request { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 reserved[3]; } __packed; struct hbm_host_enum_response { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 reserved[3]; u8 valid_addresses[32]; } __packed; @@ -279,14 +278,14 @@ struct mei_client_properties { } __packed; struct hbm_props_request { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 address; u8 reserved[2]; } __packed; struct hbm_props_response { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 address; u8 status; u8 reserved[1]; @@ -294,21 +293,21 @@ struct hbm_props_response { } __packed; struct hbm_client_connect_request { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 me_addr; u8 host_addr; u8 reserved; } __packed; struct hbm_client_connect_response { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 me_addr; u8 host_addr; u8 status; } __packed; struct hbm_client_disconnect_request { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 me_addr; u8 host_addr; u8 reserved[1]; @@ -317,7 +316,7 @@ struct hbm_client_disconnect_request { #define MEI_FC_MESSAGE_RESERVED_LENGTH 5 struct hbm_flow_control { - struct hbm_cmd cmd; + u8 hbm_cmd; u8 me_addr; u8 host_addr; u8 reserved[MEI_FC_MESSAGE_RESERVED_LENGTH]; diff --git a/drivers/staging/mei/init.c b/drivers/staging/mei/init.c index 4ac3696883c..eab711fb5fc 100644 --- a/drivers/staging/mei/init.c +++ b/drivers/staging/mei/init.c @@ -1,7 +1,7 @@ /* * * Intel Management Engine Interface (Intel MEI) Linux driver - * Copyright (c) 2003-2011, Intel Corporation. + * Copyright (c) 2003-2012, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -362,11 +362,11 @@ void mei_host_start_message(struct mei_device *dev) host_start_req = (struct hbm_host_version_request *) &dev->wr_msg_buf[1]; memset(host_start_req, 0, sizeof(struct hbm_host_version_request)); - host_start_req->cmd.cmd = HOST_START_REQ_CMD; + host_start_req->hbm_cmd = HOST_START_REQ_CMD; host_start_req->host_version.major_version = HBM_MAJOR_VERSION; host_start_req->host_version.minor_version = HBM_MINOR_VERSION; dev->recvd_msg = false; - if (!mei_write_message(dev, mei_hdr, (unsigned char *)host_start_req, + if (mei_write_message(dev, mei_hdr, (unsigned char *)host_start_req, mei_hdr->length)) { dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n"); dev->mei_state = MEI_RESETING; @@ -398,8 +398,8 @@ void mei_host_enum_clients_message(struct mei_device *dev) host_enum_req = (struct hbm_host_enum_request *) &dev->wr_msg_buf[1]; memset(host_enum_req, 0, sizeof(struct hbm_host_enum_request)); - host_enum_req->cmd.cmd = HOST_ENUM_REQ_CMD; - if (!mei_write_message(dev, mei_hdr, (unsigned char *)host_enum_req, + host_enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; + if (mei_write_message(dev, mei_hdr, (unsigned char *)host_enum_req, mei_hdr->length)) { dev->mei_state = MEI_RESETING; dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); @@ -407,7 +407,7 @@ void mei_host_enum_clients_message(struct mei_device *dev) } dev->init_clients_state = MEI_ENUM_CLIENTS_MESSAGE; dev->init_clients_timer = INIT_CLIENTS_TIMEOUT; - return ; + return; } @@ -482,10 +482,10 @@ int mei_host_client_properties(struct mei_device *dev) memset(host_cli_req, 0, sizeof(struct hbm_props_request)); - host_cli_req->cmd.cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; + host_cli_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; host_cli_req->address = b; - if (!mei_write_message(dev, mei_header, + if (mei_write_message(dev, mei_header, (unsigned char *)host_cli_req, mei_header->length)) { dev->mei_state = MEI_RESETING; @@ -608,7 +608,7 @@ void mei_host_init_iamthif(struct mei_device *dev) dev->iamthif_msg_buf = msg_buf; - if (!mei_connect(dev, &dev->iamthif_cl)) { + if (mei_connect(dev, &dev->iamthif_cl)) { dev_dbg(&dev->pdev->dev, "Failed to connect to AMTHI client\n"); dev->iamthif_cl.state = MEI_FILE_DISCONNECTED; dev->iamthif_cl.host_client_id = 0; @@ -670,14 +670,12 @@ int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl) if (dev->mei_host_buffer_is_empty) { dev->mei_host_buffer_is_empty = false; if (mei_disconnect(dev, cl)) { - mdelay(10); /* Wait for hardware disconnection ready */ - list_add_tail(&cb->cb_list, - &dev->ctrl_rd_list.mei_cb.cb_list); - } else { rets = -ENODEV; dev_dbg(&dev->pdev->dev, "failed to call mei_disconnect.\n"); goto free; } + mdelay(10); /* Wait for hardware disconnection ready */ + list_add_tail(&cb->cb_list, &dev->ctrl_rd_list.mei_cb.cb_list); } else { dev_dbg(&dev->pdev->dev, "add disconnect cb to control write list\n"); list_add_tail(&cb->cb_list, diff --git a/drivers/staging/mei/interface.c b/drivers/staging/mei/interface.c index eb5df7fc226..9a2cfafc52a 100644 --- a/drivers/staging/mei/interface.c +++ b/drivers/staging/mei/interface.c @@ -1,7 +1,7 @@ /* * * Intel Management Engine Interface (Intel MEI) Linux driver - * Copyright (c) 2003-2011, Intel Corporation. + * Copyright (c) 2003-2012, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -125,7 +125,7 @@ int mei_count_empty_write_slots(struct mei_device *dev) * @write_buffer: message buffer will be written * @write_length: message size will be written * - * returns 1 if success, 0 - otherwise. + * This function returns -EIO if write has failed */ int mei_write_message(struct mei_device *dev, struct mei_msg_hdr *header, @@ -157,7 +157,7 @@ int mei_write_message(struct mei_device *dev, dw_to_write = ((write_length + 3) / 4); if (dw_to_write > empty_slots) - return 0; + return -EIO; mei_reg_write(dev, H_CB_WW, *((u32 *) header)); @@ -177,9 +177,9 @@ int mei_write_message(struct mei_device *dev, mei_hcsr_set(dev); dev->me_hw_state = mei_mecsr_read(dev); if ((dev->me_hw_state & ME_RDY_HRA) != ME_RDY_HRA) - return 0; + return -EIO; - return 1; + return 0; } /** @@ -215,26 +215,17 @@ int mei_count_full_read_slots(struct mei_device *dev) * @buffer: message buffer will be written * @buffer_length: message size will be read */ -void mei_read_slots(struct mei_device *dev, - unsigned char *buffer, unsigned long buffer_length) +void mei_read_slots(struct mei_device *dev, unsigned char *buffer, + unsigned long buffer_length) { - u32 i = 0; - unsigned char temp_buf[sizeof(u32)]; - - while (buffer_length >= sizeof(u32)) { - ((u32 *) buffer)[i] = mei_mecbrw_read(dev); + u32 *reg_buf = (u32 *)buffer; - dev_dbg(&dev->pdev->dev, - "buffer[%d]= %d\n", - i, ((u32 *) buffer)[i]); - - i++; - buffer_length -= sizeof(u32); - } + for (; buffer_length >= sizeof(u32); buffer_length -= sizeof(u32)) + *reg_buf++ = mei_mecbrw_read(dev); if (buffer_length > 0) { - *((u32 *) &temp_buf) = mei_mecbrw_read(dev); - memcpy(&buffer[i * 4], temp_buf, buffer_length); + u32 reg = mei_mecbrw_read(dev); + memcpy(reg_buf, ®, buffer_length); } dev->host_hw_state |= H_IG; @@ -284,7 +275,7 @@ int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl) * @returns * 0 on success * -ENOENT when me client is not found - * -EINVAL wehn ctrl credits are <= 0 + * -EINVAL when ctrl credits are <= 0 */ int mei_flow_ctrl_reduce(struct mei_device *dev, struct mei_cl *cl) { @@ -317,7 +308,7 @@ int mei_flow_ctrl_reduce(struct mei_device *dev, struct mei_cl *cl) * @dev: the device structure * @cl: private data of the file object * - * returns 1 if success, 0 - otherwise. + * This function returns -EIO on write failure */ int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl) { @@ -335,18 +326,15 @@ int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl) memset(mei_flow_control, 0, sizeof(*mei_flow_control)); mei_flow_control->host_addr = cl->host_client_id; mei_flow_control->me_addr = cl->me_client_id; - mei_flow_control->cmd.cmd = MEI_FLOW_CONTROL_CMD; + mei_flow_control->hbm_cmd = MEI_FLOW_CONTROL_CMD; memset(mei_flow_control->reserved, 0, sizeof(mei_flow_control->reserved)); dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n", - cl->host_client_id, cl->me_client_id); - if (!mei_write_message(dev, mei_hdr, - (unsigned char *) mei_flow_control, - sizeof(struct hbm_flow_control))) - return 0; - - return 1; + cl->host_client_id, cl->me_client_id); + return mei_write_message(dev, mei_hdr, + (unsigned char *) mei_flow_control, + sizeof(struct hbm_flow_control)); } /** @@ -380,7 +368,7 @@ int mei_other_client_is_connecting(struct mei_device *dev, * @dev: the device structure * @cl: private data of the file object * - * returns 1 if success, 0 - otherwise. + * This function returns -EIO on write failure */ int mei_disconnect(struct mei_device *dev, struct mei_cl *cl) { @@ -399,15 +387,12 @@ int mei_disconnect(struct mei_device *dev, struct mei_cl *cl) memset(mei_cli_disconnect, 0, sizeof(*mei_cli_disconnect)); mei_cli_disconnect->host_addr = cl->host_client_id; mei_cli_disconnect->me_addr = cl->me_client_id; - mei_cli_disconnect->cmd.cmd = CLIENT_DISCONNECT_REQ_CMD; + mei_cli_disconnect->hbm_cmd = CLIENT_DISCONNECT_REQ_CMD; mei_cli_disconnect->reserved[0] = 0; - if (!mei_write_message(dev, mei_hdr, + return mei_write_message(dev, mei_hdr, (unsigned char *) mei_cli_disconnect, - sizeof(struct hbm_client_disconnect_request))) - return 0; - - return 1; + sizeof(struct hbm_client_disconnect_request)); } /** @@ -416,7 +401,7 @@ int mei_disconnect(struct mei_device *dev, struct mei_cl *cl) * @dev: the device structure * @cl: private data of the file object * - * returns 1 if success, 0 - otherwise. + * This function returns -EIO on write failure */ int mei_connect(struct mei_device *dev, struct mei_cl *cl) { @@ -434,13 +419,10 @@ int mei_connect(struct mei_device *dev, struct mei_cl *cl) (struct hbm_client_connect_request *) &dev->wr_msg_buf[1]; mei_cli_connect->host_addr = cl->host_client_id; mei_cli_connect->me_addr = cl->me_client_id; - mei_cli_connect->cmd.cmd = CLIENT_CONNECT_REQ_CMD; + mei_cli_connect->hbm_cmd = CLIENT_CONNECT_REQ_CMD; mei_cli_connect->reserved = 0; - if (!mei_write_message(dev, mei_hdr, + return mei_write_message(dev, mei_hdr, (unsigned char *) mei_cli_connect, - sizeof(struct hbm_client_connect_request))) - return 0; - - return 1; + sizeof(struct hbm_client_connect_request)); } diff --git a/drivers/staging/mei/interface.h b/drivers/staging/mei/interface.h index aeae511419c..fb90c6f8a75 100644 --- a/drivers/staging/mei/interface.h +++ b/drivers/staging/mei/interface.h @@ -1,7 +1,7 @@ /* * * Intel Management Engine Interface (Intel MEI) Linux driver - * Copyright (c) 2003-2011, Intel Corporation. + * Copyright (c) 2003-2012, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -33,7 +33,8 @@ void mei_read_slots(struct mei_device *dev, - unsigned char *buffer, unsigned long buffer_length); + unsigned char *buffer, + unsigned long buffer_length); int mei_write_message(struct mei_device *dev, struct mei_msg_hdr *header, @@ -59,7 +60,7 @@ void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout); */ void mei_watchdog_register(struct mei_device *dev); /* - * mei_watchdog_unregister - Uegistering watchdog interface + * mei_watchdog_unregister - Unregistering watchdog interface * @dev - mei device */ void mei_watchdog_unregister(struct mei_device *dev); diff --git a/drivers/staging/mei/interrupt.c b/drivers/staging/mei/interrupt.c index 3544fee34e4..2007d2447b1 100644 --- a/drivers/staging/mei/interrupt.c +++ b/drivers/staging/mei/interrupt.c @@ -1,7 +1,7 @@ /* * * Intel Management Engine Interface (Intel MEI) Linux driver - * Copyright (c) 2003-2011, Intel Corporation. + * Copyright (c) 2003-2012, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -123,8 +123,7 @@ static int mei_irq_thread_read_amthi_message(struct mei_io_list *complete_list, BUG_ON(mei_hdr->me_addr != dev->iamthif_cl.me_client_id); BUG_ON(dev->iamthif_state != MEI_IAMTHIF_READING); - buffer = (unsigned char *) (dev->iamthif_msg_buf + - dev->iamthif_msg_buf_index); + buffer = dev->iamthif_msg_buf + dev->iamthif_msg_buf_index; BUG_ON(dev->iamthif_mtu < dev->iamthif_msg_buf_index + mei_hdr->length); mei_read_slots(dev, buffer, mei_hdr->length); @@ -206,9 +205,7 @@ static int mei_irq_thread_read_client_message(struct mei_io_list *complete_list, cl = (struct mei_cl *)cb_pos->file_private; if (cl && _mei_irq_thread_state_ok(cl, mei_hdr)) { cl->reading_state = MEI_READING; - buffer = (unsigned char *) - (cb_pos->response_buffer.data + - cb_pos->information); + buffer = cb_pos->response_buffer.data + cb_pos->information; if (cb_pos->response_buffer.size < mei_hdr->length + cb_pos->information) { @@ -247,8 +244,7 @@ static int mei_irq_thread_read_client_message(struct mei_io_list *complete_list, quit: dev_dbg(&dev->pdev->dev, "message read\n"); if (!buffer) { - mei_read_slots(dev, (unsigned char *) dev->rd_msg_buf, - mei_hdr->length); + mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length); dev_dbg(&dev->pdev->dev, "discarding message, header =%08x.\n", *(u32 *) dev->rd_msg_buf); } @@ -267,26 +263,25 @@ quit: static int _mei_irq_thread_iamthif_read(struct mei_device *dev, s32 *slots) { - if (((*slots) * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) + if (((*slots) * sizeof(u32)) < (sizeof(struct mei_msg_hdr) + sizeof(struct hbm_flow_control))) { - *slots -= (sizeof(struct mei_msg_hdr) + - sizeof(struct hbm_flow_control) + 3) / 4; - if (!mei_send_flow_control(dev, &dev->iamthif_cl)) { - dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n"); - } else { - dev_dbg(&dev->pdev->dev, "iamthif flow control success\n"); - dev->iamthif_state = MEI_IAMTHIF_READING; - dev->iamthif_flow_control_pending = false; - dev->iamthif_msg_buf_index = 0; - dev->iamthif_msg_buf_size = 0; - dev->iamthif_stall_timer = IAMTHIF_STALL_TIMER; - dev->mei_host_buffer_is_empty = - mei_host_buffer_is_empty(dev); - } - return 0; - } else { return -EMSGSIZE; } + *slots -= (sizeof(struct mei_msg_hdr) + + sizeof(struct hbm_flow_control) + 3) / 4; + if (mei_send_flow_control(dev, &dev->iamthif_cl)) { + dev_dbg(&dev->pdev->dev, "iamthif flow control failed\n"); + return -EIO; + } + + dev_dbg(&dev->pdev->dev, "iamthif flow control success\n"); + dev->iamthif_state = MEI_IAMTHIF_READING; + dev->iamthif_flow_control_pending = false; + dev->iamthif_msg_buf_index = 0; + dev->iamthif_msg_buf_size = 0; + dev->iamthif_stall_timer = IAMTHIF_STALL_TIMER; + dev->mei_host_buffer_is_empty = mei_host_buffer_is_empty(dev); + return 0; } /** @@ -310,7 +305,7 @@ static int _mei_irq_thread_close(struct mei_device *dev, s32 *slots, *slots -= (sizeof(struct mei_msg_hdr) + sizeof(struct hbm_client_disconnect_request) + 3) / 4; - if (!mei_disconnect(dev, cl)) { + if (mei_disconnect(dev, cl)) { cl->status = 0; cb_pos->information = 0; list_move_tail(&cb_pos->cb_list, @@ -601,8 +596,7 @@ static void mei_client_disconnect_request(struct mei_device *dev, &dev->ext_msg_buf[1]; disconnect_res->host_addr = cl_pos->host_client_id; disconnect_res->me_addr = cl_pos->me_client_id; - *(u8 *) (&disconnect_res->cmd) = - CLIENT_DISCONNECT_RES_CMD; + disconnect_res->hbm_cmd = CLIENT_DISCONNECT_RES_CMD; disconnect_res->status = 0; dev->extra_write_index = 2; break; @@ -632,15 +626,13 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev, struct hbm_host_stop_request *host_stop_req; int res; - unsigned char *buffer; /* read the message to our buffer */ - buffer = (unsigned char *) dev->rd_msg_buf; BUG_ON(mei_hdr->length >= sizeof(dev->rd_msg_buf)); - mei_read_slots(dev, buffer, mei_hdr->length); - mei_msg = (struct mei_bus_message *) buffer; + mei_read_slots(dev, dev->rd_msg_buf, mei_hdr->length); + mei_msg = (struct mei_bus_message *)dev->rd_msg_buf; - switch (*(u8 *) mei_msg) { + switch (mei_msg->hbm_cmd) { case HOST_START_RES_CMD: version_res = (struct hbm_host_version_response *) mei_msg; if (version_res->host_version_supported) { @@ -659,6 +651,7 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev, } else { dev->version = version_res->me_max_version; /* send stop message */ + mei_hdr = (struct mei_msg_hdr *)&dev->wr_msg_buf[0]; mei_hdr->host_addr = 0; mei_hdr->me_addr = 0; mei_hdr->length = sizeof(struct hbm_host_stop_request); @@ -671,7 +664,7 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev, memset(host_stop_req, 0, sizeof(struct hbm_host_stop_request)); - host_stop_req->cmd.cmd = HOST_STOP_REQ_CMD; + host_stop_req->hbm_cmd = HOST_STOP_REQ_CMD; host_stop_req->reason = DRIVER_STOP_REQUEST; mei_write_message(dev, mei_hdr, (unsigned char *) (host_stop_req), @@ -725,7 +718,7 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev, dev->me_client_index++; dev->me_client_presentation_num++; - /** Send Client Propeties request **/ + /** Send Client Properties request **/ res = mei_host_client_properties(dev); if (res < 0) { dev_dbg(&dev->pdev->dev, "mei_host_client_properties() failed"); @@ -811,7 +804,7 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev, host_stop_req = (struct hbm_host_stop_request *) &dev->ext_msg_buf[1]; memset(host_stop_req, 0, sizeof(struct hbm_host_stop_request)); - host_stop_req->cmd.cmd = HOST_STOP_REQ_CMD; + host_stop_req->hbm_cmd = HOST_STOP_REQ_CMD; host_stop_req->reason = DRIVER_STOP_REQUEST; host_stop_req->reserved[0] = 0; host_stop_req->reserved[1] = 0; @@ -844,24 +837,21 @@ static int _mei_irq_thread_read(struct mei_device *dev, s32 *slots, { if ((*slots * sizeof(u32)) >= (sizeof(struct mei_msg_hdr) + sizeof(struct hbm_flow_control))) { - *slots -= (sizeof(struct mei_msg_hdr) + - sizeof(struct hbm_flow_control) + 3) / 4; - if (!mei_send_flow_control(dev, cl)) { - cl->status = -ENODEV; - cb_pos->information = 0; - list_move_tail(&cb_pos->cb_list, - &cmpl_list->mei_cb.cb_list); - return -ENODEV; - } else { - list_move_tail(&cb_pos->cb_list, - &dev->read_list.mei_cb.cb_list); - } - } else { /* return the cancel routine */ list_del(&cb_pos->cb_list); return -EBADMSG; } + *slots -= (sizeof(struct mei_msg_hdr) + + sizeof(struct hbm_flow_control) + 3) / 4; + if (mei_send_flow_control(dev, cl)) { + cl->status = -ENODEV; + cb_pos->information = 0; + list_move_tail(&cb_pos->cb_list, &cmpl_list->mei_cb.cb_list); + return -ENODEV; + } + list_move_tail(&cb_pos->cb_list, &dev->read_list.mei_cb.cb_list); + return 0; } @@ -887,7 +877,7 @@ static int _mei_irq_thread_ioctl(struct mei_device *dev, s32 *slots, cl->state = MEI_FILE_CONNECTING; *slots -= (sizeof(struct mei_msg_hdr) + sizeof(struct hbm_client_connect_request) + 3) / 4; - if (!mei_connect(dev, cl)) { + if (mei_connect(dev, cl)) { cl->status = -ENODEV; cb_pos->information = 0; list_del(&cb_pos->cb_list); @@ -944,7 +934,7 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots, mei_hdr->length); *slots -= (sizeof(struct mei_msg_hdr) + mei_hdr->length + 3) / 4; - if (!mei_write_message(dev, mei_hdr, + if (mei_write_message(dev, mei_hdr, (unsigned char *) (cb_pos->request_buffer.data + cb_pos->information), @@ -973,7 +963,7 @@ static int _mei_irq_thread_cmpl(struct mei_device *dev, s32 *slots, (*slots) -= (sizeof(struct mei_msg_hdr) + mei_hdr->length + 3) / 4; - if (!mei_write_message(dev, mei_hdr, + if (mei_write_message(dev, mei_hdr, (unsigned char *) (cb_pos->request_buffer.data + cb_pos->information), @@ -1034,7 +1024,7 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots, *slots -= (sizeof(struct mei_msg_hdr) + mei_hdr->length + 3) / 4; - if (!mei_write_message(dev, mei_hdr, + if (mei_write_message(dev, mei_hdr, (dev->iamthif_msg_buf + dev->iamthif_msg_buf_index), mei_hdr->length)) { @@ -1069,7 +1059,7 @@ static int _mei_irq_thread_cmpl_iamthif(struct mei_device *dev, s32 *slots, *slots -= (sizeof(struct mei_msg_hdr) + mei_hdr->length + 3) / 4; - if (!mei_write_message(dev, mei_hdr, + if (mei_write_message(dev, mei_hdr, (dev->iamthif_msg_buf + dev->iamthif_msg_buf_index), mei_hdr->length)) { @@ -1286,7 +1276,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list, } } if (dev->stop) - return ~ENODEV; + return -ENODEV; /* complete control write list CB */ dev_dbg(&dev->pdev->dev, "complete control write list cb.\n"); @@ -1423,7 +1413,7 @@ void mei_timer(struct work_struct *work) if (dev->iamthif_stall_timer) { if (--dev->iamthif_stall_timer == 0) { - dev_dbg(&dev->pdev->dev, "reseting because of hang to amthi.\n"); + dev_dbg(&dev->pdev->dev, "resetting because of hang to amthi.\n"); mei_reset(dev, 1); dev->iamthif_msg_buf_size = 0; dev->iamthif_msg_buf_index = 0; @@ -1513,7 +1503,7 @@ irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id) dev->host_hw_state = mei_hcsr_read(dev); /* Ack the interrupt here - * In case of MSI we don't go throuhg the quick handler */ + * In case of MSI we don't go through the quick handler */ if (pci_dev_msi_enabled(dev->pdev)) mei_reg_write(dev, H_CSR, dev->host_hw_state); @@ -1549,7 +1539,7 @@ irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id) return IRQ_HANDLED; } } - /* check slots avalable for reading */ + /* check slots available for reading */ slots = mei_count_full_read_slots(dev); dev_dbg(&dev->pdev->dev, "slots =%08x extra_write_index =%08x.\n", slots, dev->extra_write_index); diff --git a/drivers/staging/mei/iorw.c b/drivers/staging/mei/iorw.c index 0752ead4269..0a80dc4e62f 100644 --- a/drivers/staging/mei/iorw.c +++ b/drivers/staging/mei/iorw.c @@ -1,7 +1,7 @@ /* * * Intel Management Engine Interface (Intel MEI) Linux driver - * Copyright (c) 2003-2011, Intel Corporation. + * Copyright (c) 2003-2012, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -37,7 +37,6 @@ #include "hw.h" #include "mei.h" #include "interface.h" -#include "mei_version.h" @@ -109,8 +108,8 @@ int mei_ioctl_connect_client(struct file *file, dev_dbg(&dev->pdev->dev, "FW Client - Max Msg Len = %d\n", dev->me_clients[i].props.max_msg_length); - /* if we're connecting to amthi client so we will use the exist - * connection + /* if we're connecting to amthi client then we will use the + * existing connection */ if (uuid_le_cmp(data->in_client_uuid, mei_amthi_guid) == 0) { dev_dbg(&dev->pdev->dev, "FW Client is amthi\n"); @@ -162,7 +161,7 @@ int mei_ioctl_connect_client(struct file *file, && !mei_other_client_is_connecting(dev, cl)) { dev_dbg(&dev->pdev->dev, "Sending Connect Message\n"); dev->mei_host_buffer_is_empty = false; - if (!mei_connect(dev, cl)) { + if (mei_connect(dev, cl)) { dev_dbg(&dev->pdev->dev, "Sending connect message - failed\n"); rets = -ENODEV; goto end; @@ -434,13 +433,11 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl) cl->read_cb = cb; if (dev->mei_host_buffer_is_empty) { dev->mei_host_buffer_is_empty = false; - if (!mei_send_flow_control(dev, cl)) { + if (mei_send_flow_control(dev, cl)) { rets = -ENODEV; goto unlock; - } else { - list_add_tail(&cb->cb_list, - &dev->read_list.mei_cb.cb_list); } + list_add_tail(&cb->cb_list, &dev->read_list.mei_cb.cb_list); } else { list_add_tail(&cb->cb_list, &dev->ctrl_wr_list.mei_cb.cb_list); } @@ -500,7 +497,7 @@ int amthi_write(struct mei_device *dev, struct mei_cl_cb *cb) mei_hdr.me_addr = dev->iamthif_cl.me_client_id; mei_hdr.reserved = 0; dev->iamthif_msg_buf_index += mei_hdr.length; - if (!mei_write_message(dev, &mei_hdr, + if (mei_write_message(dev, &mei_hdr, (unsigned char *)(dev->iamthif_msg_buf), mei_hdr.length)) return -ENODEV; diff --git a/drivers/staging/mei/main.c b/drivers/staging/mei/main.c index 1e1a9f996e7..7c9321fa7bb 100644 --- a/drivers/staging/mei/main.c +++ b/drivers/staging/mei/main.c @@ -1,7 +1,7 @@ /* * * Intel Management Engine Interface (Intel MEI) Linux driver - * Copyright (c) 2003-2011, Intel Corporation. + * Copyright (c) 2003-2012, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -38,7 +38,6 @@ #include "mei_dev.h" #include "mei.h" #include "interface.h" -#include "mei_version.h" #define MEI_READ_TIMEOUT 45 @@ -50,7 +49,6 @@ */ static char mei_driver_name[] = MEI_DRIVER_NAME; static const char mei_driver_string[] = "Intel(R) Management Engine Interface"; -static const char mei_driver_version[] = MEI_DRIVER_VERSION; /* The device pointer */ /* Currently this driver works as long as there is only a single AMT device. */ @@ -430,7 +428,7 @@ static ssize_t mei_read(struct file *file, char __user *ubuf, goto free; } else if ((!cl->read_cb || !cl->read_cb->information) && *offset > 0) { - /*Offset needs to be cleaned for contingous reads*/ + /*Offset needs to be cleaned for contiguous reads*/ *offset = 0; rets = 0; goto out; @@ -493,7 +491,7 @@ copy_buffer: goto free; } - /* length is being turncated to PAGE_SIZE, however, */ + /* length is being truncated to PAGE_SIZE, however, */ /* information size may be longer */ length = min_t(size_t, length, (cb->information - *offset)); @@ -740,7 +738,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, mei_hdr.reserved = 0; dev_dbg(&dev->pdev->dev, "call mei_write_message header=%08x.\n", *((u32 *) &mei_hdr)); - if (!mei_write_message(dev, &mei_hdr, + if (mei_write_message(dev, &mei_hdr, (unsigned char *) (write_cb->request_buffer.data), mei_hdr.length)) { rets = -ENODEV; @@ -1206,8 +1204,7 @@ static int __init mei_init_module(void) { int ret; - pr_debug("mei: %s - version %s\n", - mei_driver_string, mei_driver_version); + pr_debug("mei: %s\n", mei_driver_string); /* init pci module */ ret = pci_register_driver(&mei_driver); if (ret < 0) @@ -1238,4 +1235,3 @@ module_exit(mei_exit_module); MODULE_AUTHOR("Intel Corporation"); MODULE_DESCRIPTION("Intel(R) Management Engine Interface"); MODULE_LICENSE("GPL v2"); -MODULE_VERSION(MEI_DRIVER_VERSION); diff --git a/drivers/staging/mei/mei-amt-version.c b/drivers/staging/mei/mei-amt-version.c new file mode 100644 index 00000000000..ac2a507be25 --- /dev/null +++ b/drivers/staging/mei/mei-amt-version.c @@ -0,0 +1,481 @@ +/****************************************************************************** + * Intel Management Engine Interface (Intel MEI) Linux driver + * Intel MEI Interface Header + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2012 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, + * USA + * + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation. + * linux-mei@linux.intel.com + * http://www.intel.com + * + * BSD LICENSE + * + * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <unistd.h> +#include <errno.h> +#include <stdint.h> +#include <stdbool.h> +#include <bits/wordsize.h> +#include "mei.h" + +/***************************************************************************** + * Intel Management Engine Interface + *****************************************************************************/ + +#define mei_msg(_me, fmt, ARGS...) do { \ + if (_me->verbose) \ + fprintf(stderr, fmt, ##ARGS); \ +} while (0) + +#define mei_err(_me, fmt, ARGS...) do { \ + fprintf(stderr, "Error: " fmt, ##ARGS); \ +} while (0) + +struct mei { + uuid_le guid; + bool initialized; + bool verbose; + unsigned int buf_size; + unsigned char prot_ver; + int fd; +}; + +static void mei_deinit(struct mei *cl) +{ + if (cl->fd != -1) + close(cl->fd); + cl->fd = -1; + cl->buf_size = 0; + cl->prot_ver = 0; + cl->initialized = false; +} + +static bool mei_init(struct mei *me, const uuid_le *guid, + unsigned char req_protocol_version, bool verbose) +{ + int result; + struct mei_client *cl; + struct mei_connect_client_data data; + + mei_deinit(me); + + me->verbose = verbose; + + me->fd = open("/dev/mei", O_RDWR); + if (me->fd == -1) { + mei_err(me, "Cannot establish a handle to the Intel MEI driver\n"); + goto err; + } + memcpy(&me->guid, guid, sizeof(*guid)); + memset(&data, 0, sizeof(data)); + me->initialized = true; + + memcpy(&data.in_client_uuid, &me->guid, sizeof(me->guid)); + result = ioctl(me->fd, IOCTL_MEI_CONNECT_CLIENT, &data); + if (result) { + mei_err(me, "IOCTL_MEI_CONNECT_CLIENT receive message. err=%d\n", result); + goto err; + } + cl = &data.out_client_properties; + mei_msg(me, "max_message_length %d\n", cl->max_msg_length); + mei_msg(me, "protocol_version %d\n", cl->protocol_version); + + if ((req_protocol_version > 0) && + (cl->protocol_version != req_protocol_version)) { + mei_err(me, "Intel MEI protocol version not supported\n"); + goto err; + } + + me->buf_size = cl->max_msg_length; + me->prot_ver = cl->protocol_version; + + return true; +err: + mei_deinit(me); + return false; +} + +static ssize_t mei_recv_msg(struct mei *me, unsigned char *buffer, + ssize_t len, unsigned long timeout) +{ + ssize_t rc; + + mei_msg(me, "call read length = %zd\n", len); + + rc = read(me->fd, buffer, len); + if (rc < 0) { + mei_err(me, "read failed with status %zd %s\n", + rc, strerror(errno)); + mei_deinit(me); + } else { + mei_msg(me, "read succeeded with result %zd\n", rc); + } + return rc; +} + +static ssize_t mei_send_msg(struct mei *me, const unsigned char *buffer, + ssize_t len, unsigned long timeout) +{ + struct timeval tv; + ssize_t written; + ssize_t rc; + fd_set set; + + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000000; + + mei_msg(me, "call write length = %zd\n", len); + + written = write(me->fd, buffer, len); + if (written < 0) { + rc = -errno; + mei_err(me, "write failed with status %zd %s\n", + written, strerror(errno)); + goto out; + } + + FD_ZERO(&set); + FD_SET(me->fd, &set); + rc = select(me->fd + 1 , &set, NULL, NULL, &tv); + if (rc > 0 && FD_ISSET(me->fd, &set)) { + mei_msg(me, "write success\n"); + } else if (rc == 0) { + mei_err(me, "write failed on timeout with status\n"); + goto out; + } else { /* rc < 0 */ + mei_err(me, "write failed on select with status %zd\n", rc); + goto out; + } + + rc = written; +out: + if (rc < 0) + mei_deinit(me); + + return rc; +} + +/*************************************************************************** + * Intel Advanced Management Technolgy ME Client + ***************************************************************************/ + +#define AMT_MAJOR_VERSION 1 +#define AMT_MINOR_VERSION 1 + +#define AMT_STATUS_SUCCESS 0x0 +#define AMT_STATUS_INTERNAL_ERROR 0x1 +#define AMT_STATUS_NOT_READY 0x2 +#define AMT_STATUS_INVALID_AMT_MODE 0x3 +#define AMT_STATUS_INVALID_MESSAGE_LENGTH 0x4 + +#define AMT_STATUS_HOST_IF_EMPTY_RESPONSE 0x4000 +#define AMT_STATUS_SDK_RESOURCES 0x1004 + + +#define AMT_BIOS_VERSION_LEN 65 +#define AMT_VERSIONS_NUMBER 50 +#define AMT_UNICODE_STRING_LEN 20 + +struct amt_unicode_string { + uint16_t length; + char string[AMT_UNICODE_STRING_LEN]; +} __attribute__((packed)); + +struct amt_version_type { + struct amt_unicode_string description; + struct amt_unicode_string version; +} __attribute__((packed)); + +struct amt_version { + uint8_t major; + uint8_t minor; +} __attribute__((packed)); + +struct amt_code_versions { + uint8_t bios[AMT_BIOS_VERSION_LEN]; + uint32_t count; + struct amt_version_type versions[AMT_VERSIONS_NUMBER]; +} __attribute__((packed)); + +/*************************************************************************** + * Intel Advanced Management Technolgy Host Interface + ***************************************************************************/ + +struct amt_host_if_msg_header { + struct amt_version version; + uint16_t _reserved; + uint32_t command; + uint32_t length; +} __attribute__((packed)); + +struct amt_host_if_resp_header { + struct amt_host_if_msg_header header; + uint32_t status; + unsigned char data[0]; +} __attribute__((packed)); + +const uuid_le MEI_IAMTHIF = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, \ + 0xac, 0xa8, 0x46, 0xe0, 0xff, 0x65, 0x81, 0x4c); + +#define AMT_HOST_IF_CODE_VERSIONS_REQUEST 0x0400001A +#define AMT_HOST_IF_CODE_VERSIONS_RESPONSE 0x0480001A + +const struct amt_host_if_msg_header CODE_VERSION_REQ = { + .version = {AMT_MAJOR_VERSION, AMT_MINOR_VERSION}, + ._reserved = 0, + .command = AMT_HOST_IF_CODE_VERSIONS_REQUEST, + .length = 0 +}; + + +struct amt_host_if { + struct mei mei_cl; + unsigned long send_timeout; + bool initialized; +}; + + +static bool amt_host_if_init(struct amt_host_if *acmd, + unsigned long send_timeout, bool verbose) +{ + acmd->send_timeout = (send_timeout) ? send_timeout : 20000; + acmd->initialized = mei_init(&acmd->mei_cl, &MEI_IAMTHIF, 0, verbose); + return acmd->initialized; +} + +static void amt_host_if_deinit(struct amt_host_if *acmd) +{ + mei_deinit(&acmd->mei_cl); + acmd->initialized = false; +} + +static uint32_t amt_verify_code_versions(const struct amt_host_if_resp_header *resp) +{ + uint32_t status = AMT_STATUS_SUCCESS; + struct amt_code_versions *code_ver; + size_t code_ver_len; + uint32_t ver_type_cnt; + uint32_t len; + uint32_t i; + + code_ver = (struct amt_code_versions *)resp->data; + /* length - sizeof(status) */ + code_ver_len = resp->header.length - sizeof(uint32_t); + ver_type_cnt = code_ver_len - + sizeof(code_ver->bios) - + sizeof(code_ver->count); + if (code_ver->count != ver_type_cnt / sizeof(struct amt_version_type)) { + status = AMT_STATUS_INTERNAL_ERROR; + goto out; + } + + for (i = 0; i < code_ver->count; i++) { + len = code_ver->versions[i].description.length; + + if (len > AMT_UNICODE_STRING_LEN) { + status = AMT_STATUS_INTERNAL_ERROR; + goto out; + } + + len = code_ver->versions[i].version.length; + if (code_ver->versions[i].version.string[len] != '\0' || + len != strlen(code_ver->versions[i].version.string)) { + status = AMT_STATUS_INTERNAL_ERROR; + goto out; + } + } +out: + return status; +} + +static uint32_t amt_verify_response_header(uint32_t command, + const struct amt_host_if_msg_header *resp_hdr, + uint32_t response_size) +{ + if (response_size < sizeof(struct amt_host_if_resp_header)) { + return AMT_STATUS_INTERNAL_ERROR; + } else if (response_size != (resp_hdr->length + + sizeof(struct amt_host_if_msg_header))) { + return AMT_STATUS_INTERNAL_ERROR; + } else if (resp_hdr->command != command) { + return AMT_STATUS_INTERNAL_ERROR; + } else if (resp_hdr->_reserved != 0) { + return AMT_STATUS_INTERNAL_ERROR; + } else if (resp_hdr->version.major != AMT_MAJOR_VERSION || + resp_hdr->version.minor < AMT_MINOR_VERSION) { + return AMT_STATUS_INTERNAL_ERROR; + } + return AMT_STATUS_SUCCESS; +} + +static uint32_t amt_host_if_call(struct amt_host_if *acmd, + const unsigned char *command, ssize_t command_sz, + uint8_t **read_buf, uint32_t rcmd, + unsigned int expected_sz) +{ + uint32_t in_buf_sz; + uint32_t out_buf_sz; + ssize_t written; + uint32_t status; + struct amt_host_if_resp_header *msg_hdr; + + in_buf_sz = acmd->mei_cl.buf_size; + *read_buf = (uint8_t *)malloc(sizeof(uint8_t) * in_buf_sz); + if (*read_buf == NULL) + return AMT_STATUS_SDK_RESOURCES; + memset(*read_buf, 0, in_buf_sz); + msg_hdr = (struct amt_host_if_resp_header *)*read_buf; + + written = mei_send_msg(&acmd->mei_cl, + command, command_sz, acmd->send_timeout); + if (written != command_sz) + return AMT_STATUS_INTERNAL_ERROR; + + out_buf_sz = mei_recv_msg(&acmd->mei_cl, *read_buf, in_buf_sz, 2000); + if (out_buf_sz <= 0) + return AMT_STATUS_HOST_IF_EMPTY_RESPONSE; + + status = msg_hdr->status; + if (status != AMT_STATUS_SUCCESS) + return status; + + status = amt_verify_response_header(rcmd, + &msg_hdr->header, out_buf_sz); + if (status != AMT_STATUS_SUCCESS) + return status; + + if (expected_sz && expected_sz != out_buf_sz) + return AMT_STATUS_INTERNAL_ERROR; + + return AMT_STATUS_SUCCESS; +} + + +static uint32_t amt_get_code_versions(struct amt_host_if *cmd, + struct amt_code_versions *versions) +{ + struct amt_host_if_resp_header *response = NULL; + uint32_t status; + + status = amt_host_if_call(cmd, + (const unsigned char *)&CODE_VERSION_REQ, + sizeof(CODE_VERSION_REQ), + (uint8_t **)&response, + AMT_HOST_IF_CODE_VERSIONS_RESPONSE, 0); + + if (status != AMT_STATUS_SUCCESS) + goto out; + + status = amt_verify_code_versions(response); + if (status != AMT_STATUS_SUCCESS) + goto out; + + memcpy(versions, response->data, sizeof(struct amt_code_versions)); +out: + if (response != NULL) + free(response); + + return status; +} + +/************************** end of amt_host_if_command ***********************/ +int main(int argc, char **argv) +{ + struct amt_code_versions ver; + struct amt_host_if acmd; + unsigned int i; + uint32_t status; + int ret; + bool verbose; + + verbose = (argc > 1 && strcmp(argv[1], "-v") == 0); + + if (!amt_host_if_init(&acmd, 5000, verbose)) { + ret = 1; + goto out; + } + + status = amt_get_code_versions(&acmd, &ver); + + amt_host_if_deinit(&acmd); + + switch (status) { + case AMT_STATUS_HOST_IF_EMPTY_RESPONSE: + printf("Intel AMT: DISABLED\n"); + ret = 0; + break; + case AMT_STATUS_SUCCESS: + printf("Intel AMT: ENABLED\n"); + for (i = 0; i < ver.count; i++) { + printf("%s:\t%s\n", ver.versions[i].description.string, + ver.versions[i].version.string); + } + ret = 0; + break; + default: + printf("An error has occurred\n"); + ret = 1; + break; + } + +out: + return ret; +} diff --git a/drivers/staging/mei/mei.h b/drivers/staging/mei/mei.h index 6da7c4f33f9..bc0d8b69c49 100644 --- a/drivers/staging/mei/mei.h +++ b/drivers/staging/mei/mei.h @@ -1,63 +1,68 @@ -/* - - Intel Management Engine Interface (Intel MEI) Linux driver - Intel MEI Interface Header - - This file is provided under a dual BSD/GPLv2 license. When using or - redistributing this file, you may do so under either license. - - GPL LICENSE SUMMARY - - Copyright(c) 2003-2011 Intel Corporation. All rights reserved. - - This program is free software; you can redistribute it and/or modify - it under the terms of version 2 of the GNU General Public License as - published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - Contact Information: - Intel Corporation. - linux-mei@linux.intel.com - http://www.intel.com - - - BSD LICENSE - - Copyright(c) 2003-2011 Intel Corporation. All rights reserved. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - * Neither the name of Intel Corporation nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - +/****************************************************************************** + * Intel Management Engine Interface (Intel MEI) Linux driver + * Intel MEI Interface Header + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, + * USA + * + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation. + * linux-mei@linux.intel.com + * http://www.intel.com + * + * BSD LICENSE + * + * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ #ifndef _LINUX_MEI_H #define _LINUX_MEI_H @@ -72,7 +77,7 @@ * Only in close() (file_operation release()) the communication between * the clients is disconnected * - * The IOCTL argument is a struct with a union the contains + * The IOCTL argument is a struct with a union that contains * the input parameter and the output parameter for this IOCTL. * * The input parameter is UUID of the FW Client. diff --git a/drivers/staging/mei/mei.txt b/drivers/staging/mei/mei.txt index 516bfe7319a..2785697da59 100644 --- a/drivers/staging/mei/mei.txt +++ b/drivers/staging/mei/mei.txt @@ -4,7 +4,7 @@ Intel(R) Management Engine Interface (Intel(R) MEI) Introduction ======================= -The Intel Management Engine (Intel ME) is an isolated andprotected computing +The Intel Management Engine (Intel ME) is an isolated and protected computing resource (Co-processor) residing inside certain Intel chipsets. The Intel ME provides support for computer/IT management features. The feature set depends on the Intel chipset SKU. @@ -176,8 +176,8 @@ Intel AMT OS Health Watchdog: ============================= The Intel AMT Watchdog is an OS Health (Hang/Crash) watchdog. Whenever the OS hangs or crashes, Intel AMT will send an event -to any subsciber to this event. This mechanism means that -IT knows when a platform crashes even when there is a hard failureon the host. +to any subscriber to this event. This mechanism means that +IT knows when a platform crashes even when there is a hard failure on the host. The Intel AMT Watchdog is composed of two parts: 1) Firmware feature - receives the heartbeats diff --git a/drivers/staging/mei/mei_dev.h b/drivers/staging/mei/mei_dev.h index 82bacfc624c..10b1b4e2f8a 100644 --- a/drivers/staging/mei/mei_dev.h +++ b/drivers/staging/mei/mei_dev.h @@ -1,7 +1,7 @@ /* * * Intel Management Engine Interface (Intel MEI) Linux driver - * Copyright (c) 2003-2011, Intel Corporation. + * Copyright (c) 2003-2012, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -30,6 +30,8 @@ #define MEI_WD_PARAMS_SIZE 4 #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0) +#define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32)) + /* * MEI PCI Device object */ @@ -87,7 +89,7 @@ enum mei_states { MEI_POWER_UP }; -/* init clients states*/ +/* init clients states*/ enum mei_init_clients_states { MEI_START_MESSAGE = 0, MEI_ENUM_CLIENTS_MESSAGE, @@ -125,7 +127,7 @@ enum mei_cb_major_types { */ struct mei_message_data { u32 size; - char *data; + unsigned char *data; } __packed; @@ -219,7 +221,7 @@ struct mei_device { bool need_reset; u32 extra_write_index; - u32 rd_msg_buf[128]; /* used for control messages */ + unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */ u32 wr_msg_buf[128]; /* used for control messages */ u32 ext_msg_buf[8]; /* for control responses */ u32 rd_msg_hdr; diff --git a/drivers/staging/mei/mei_version.h b/drivers/staging/mei/mei_version.h deleted file mode 100644 index 075bad8f0bf..00000000000 --- a/drivers/staging/mei/mei_version.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * - * Intel Management Engine Interface (Intel MEI) Linux driver - * Copyright (c) 2003-2011, Intel Corporation. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - */ - - -#ifndef MEI_VERSION_H -#define MEI_VERSION_H - -#define MAJOR_VERSION 7 -#define MINOR_VERSION 1 -#define QUICK_FIX_NUMBER 20 -#define VER_BUILD 1 - -#define MEI_DRV_VER1 __stringify(MAJOR_VERSION) "." __stringify(MINOR_VERSION) -#define MEI_DRV_VER2 __stringify(QUICK_FIX_NUMBER) "." __stringify(VER_BUILD) - -#define MEI_DRIVER_VERSION MEI_DRV_VER1 "." MEI_DRV_VER2 - -#endif diff --git a/drivers/staging/mei/wd.c b/drivers/staging/mei/wd.c index 8094941a98f..a6910da78a6 100644 --- a/drivers/staging/mei/wd.c +++ b/drivers/staging/mei/wd.c @@ -1,7 +1,7 @@ /* * * Intel Management Engine Interface (Intel MEI) Linux driver - * Copyright (c) 2003-2011, Intel Corporation. + * Copyright (c) 2003-2012, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -74,7 +74,7 @@ bool mei_wd_host_init(struct mei_device *dev) dev_dbg(&dev->pdev->dev, "check wd_cl\n"); if (MEI_FILE_CONNECTING == dev->wd_cl.state) { - if (!mei_connect(dev, &dev->wd_cl)) { + if (mei_connect(dev, &dev->wd_cl)) { dev_dbg(&dev->pdev->dev, "Failed to connect to WD client\n"); dev->wd_cl.state = MEI_FILE_DISCONNECTED; dev->wd_cl.host_client_id = 0; @@ -119,9 +119,7 @@ int mei_wd_send(struct mei_device *dev) else return -EINVAL; - if (mei_write_message(dev, mei_hdr, dev->wd_data, mei_hdr->length)) - return 0; - return -EIO; + return mei_write_message(dev, mei_hdr, dev->wd_data, mei_hdr->length); } /** |