aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-27 12:09:07 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-27 12:09:07 -0400
commit7da59d2fe30d8169c7c9e7b488beb1b9af932608 (patch)
tree02438ff9c258cf80d3a3955215fbcff7bd7e392e /drivers/misc
parentfea7a08acb13524b47711625eebea40a0ede69a0 (diff)
parent877cdf3949cc67d00677a1dfb913001f324ac40d (diff)
Merge v3.6-rc3 into 'char-misc-next'
This resolves a conflict in: drivers/misc/mei/interrupt.c Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/bmp085-i2c.c7
-rw-r--r--drivers/misc/carma/carma-fpga-program.c1
-rw-r--r--drivers/misc/carma/carma-fpga.c2
-rw-r--r--drivers/misc/mei/hw.h79
-rw-r--r--drivers/misc/mei/init.c93
-rw-r--r--drivers/misc/mei/interface.h10
-rw-r--r--drivers/misc/mei/interrupt.c35
-rw-r--r--drivers/misc/mei/iorw.c59
-rw-r--r--drivers/misc/mei/main.c78
-rw-r--r--drivers/misc/mei/mei_dev.h57
-rw-r--r--drivers/misc/mei/wd.c91
-rw-r--r--drivers/misc/pch_phub.c15
-rw-r--r--drivers/misc/ti-st/st_core.c12
-rw-r--r--drivers/misc/ti-st/st_kim.c109
14 files changed, 312 insertions, 336 deletions
diff --git a/drivers/misc/bmp085-i2c.c b/drivers/misc/bmp085-i2c.c
index 9943971c13e3..a4f33c995ea1 100644
--- a/drivers/misc/bmp085-i2c.c
+++ b/drivers/misc/bmp085-i2c.c
@@ -57,12 +57,6 @@ static int bmp085_i2c_remove(struct i2c_client *client)
57 return bmp085_remove(&client->dev); 57 return bmp085_remove(&client->dev);
58} 58}
59 59
60static const struct of_device_id bmp085_of_match[] = {
61 { .compatible = "bosch,bmp085", },
62 { },
63};
64MODULE_DEVICE_TABLE(of, bmp085_of_match);
65
66static const struct i2c_device_id bmp085_id[] = { 60static const struct i2c_device_id bmp085_id[] = {
67 { BMP085_NAME, 0 }, 61 { BMP085_NAME, 0 },
68 { "bmp180", 0 }, 62 { "bmp180", 0 },
@@ -74,7 +68,6 @@ static struct i2c_driver bmp085_i2c_driver = {
74 .driver = { 68 .driver = {
75 .owner = THIS_MODULE, 69 .owner = THIS_MODULE,
76 .name = BMP085_NAME, 70 .name = BMP085_NAME,
77 .of_match_table = bmp085_of_match
78 }, 71 },
79 .id_table = bmp085_id, 72 .id_table = bmp085_id,
80 .probe = bmp085_i2c_probe, 73 .probe = bmp085_i2c_probe,
diff --git a/drivers/misc/carma/carma-fpga-program.c b/drivers/misc/carma/carma-fpga-program.c
index a2d25e4857e3..eaddfe9db149 100644
--- a/drivers/misc/carma/carma-fpga-program.c
+++ b/drivers/misc/carma/carma-fpga-program.c
@@ -978,7 +978,6 @@ static int fpga_of_probe(struct platform_device *op)
978 dev_set_drvdata(priv->dev, priv); 978 dev_set_drvdata(priv->dev, priv);
979 dma_cap_zero(mask); 979 dma_cap_zero(mask);
980 dma_cap_set(DMA_MEMCPY, mask); 980 dma_cap_set(DMA_MEMCPY, mask);
981 dma_cap_set(DMA_INTERRUPT, mask);
982 dma_cap_set(DMA_SLAVE, mask); 981 dma_cap_set(DMA_SLAVE, mask);
983 dma_cap_set(DMA_SG, mask); 982 dma_cap_set(DMA_SG, mask);
984 983
diff --git a/drivers/misc/carma/carma-fpga.c b/drivers/misc/carma/carma-fpga.c
index 8c279da07410..0c43297ed9ac 100644
--- a/drivers/misc/carma/carma-fpga.c
+++ b/drivers/misc/carma/carma-fpga.c
@@ -666,7 +666,7 @@ static int data_submit_dma(struct fpga_device *priv, struct data_buf *buf)
666 src = SYS_FPGA_BLOCK; 666 src = SYS_FPGA_BLOCK;
667 tx = chan->device->device_prep_dma_memcpy(chan, dst, src, 667 tx = chan->device->device_prep_dma_memcpy(chan, dst, src,
668 REG_BLOCK_SIZE, 668 REG_BLOCK_SIZE,
669 DMA_PREP_INTERRUPT); 669 0);
670 if (!tx) { 670 if (!tx) {
671 dev_err(priv->dev, "unable to prep SYS-FPGA DMA\n"); 671 dev_err(priv->dev, "unable to prep SYS-FPGA DMA\n");
672 return -ENOMEM; 672 return -ENOMEM;
diff --git a/drivers/misc/mei/hw.h b/drivers/misc/mei/hw.h
index 24c4c962819e..b3b4c6dcbaa7 100644
--- a/drivers/misc/mei/hw.h
+++ b/drivers/misc/mei/hw.h
@@ -40,46 +40,45 @@
40/* 40/*
41 * MEI device IDs 41 * MEI device IDs
42 */ 42 */
43#define MEI_DEV_ID_82946GZ 0x2974 /* 82946GZ/GL */ 43#define MEI_DEV_ID_82946GZ 0x2974 /* 82946GZ/GL */
44#define MEI_DEV_ID_82G35 0x2984 /* 82G35 Express */ 44#define MEI_DEV_ID_82G35 0x2984 /* 82G35 Express */
45#define MEI_DEV_ID_82Q965 0x2994 /* 82Q963/Q965 */ 45#define MEI_DEV_ID_82Q965 0x2994 /* 82Q963/Q965 */
46#define MEI_DEV_ID_82G965 0x29A4 /* 82P965/G965 */ 46#define MEI_DEV_ID_82G965 0x29A4 /* 82P965/G965 */
47 47
48#define MEI_DEV_ID_82GM965 0x2A04 /* Mobile PM965/GM965 */ 48#define MEI_DEV_ID_82GM965 0x2A04 /* Mobile PM965/GM965 */
49#define MEI_DEV_ID_82GME965 0x2A14 /* Mobile GME965/GLE960 */ 49#define MEI_DEV_ID_82GME965 0x2A14 /* Mobile GME965/GLE960 */
50 50
51#define MEI_DEV_ID_ICH9_82Q35 0x29B4 /* 82Q35 Express */ 51#define MEI_DEV_ID_ICH9_82Q35 0x29B4 /* 82Q35 Express */
52#define MEI_DEV_ID_ICH9_82G33 0x29C4 /* 82G33/G31/P35/P31 Express */ 52#define MEI_DEV_ID_ICH9_82G33 0x29C4 /* 82G33/G31/P35/P31 Express */
53#define MEI_DEV_ID_ICH9_82Q33 0x29D4 /* 82Q33 Express */ 53#define MEI_DEV_ID_ICH9_82Q33 0x29D4 /* 82Q33 Express */
54#define MEI_DEV_ID_ICH9_82X38 0x29E4 /* 82X38/X48 Express */ 54#define MEI_DEV_ID_ICH9_82X38 0x29E4 /* 82X38/X48 Express */
55#define MEI_DEV_ID_ICH9_3200 0x29F4 /* 3200/3210 Server */ 55#define MEI_DEV_ID_ICH9_3200 0x29F4 /* 3200/3210 Server */
56 56
57#define MEI_DEV_ID_ICH9_6 0x28B4 /* Bearlake */ 57#define MEI_DEV_ID_ICH9_6 0x28B4 /* Bearlake */
58#define MEI_DEV_ID_ICH9_7 0x28C4 /* Bearlake */ 58#define MEI_DEV_ID_ICH9_7 0x28C4 /* Bearlake */
59#define MEI_DEV_ID_ICH9_8 0x28D4 /* Bearlake */ 59#define MEI_DEV_ID_ICH9_8 0x28D4 /* Bearlake */
60#define MEI_DEV_ID_ICH9_9 0x28E4 /* Bearlake */ 60#define MEI_DEV_ID_ICH9_9 0x28E4 /* Bearlake */
61#define MEI_DEV_ID_ICH9_10 0x28F4 /* Bearlake */ 61#define MEI_DEV_ID_ICH9_10 0x28F4 /* Bearlake */
62 62
63#define MEI_DEV_ID_ICH9M_1 0x2A44 /* Cantiga */ 63#define MEI_DEV_ID_ICH9M_1 0x2A44 /* Cantiga */
64#define MEI_DEV_ID_ICH9M_2 0x2A54 /* Cantiga */ 64#define MEI_DEV_ID_ICH9M_2 0x2A54 /* Cantiga */
65#define MEI_DEV_ID_ICH9M_3 0x2A64 /* Cantiga */ 65#define MEI_DEV_ID_ICH9M_3 0x2A64 /* Cantiga */
66#define MEI_DEV_ID_ICH9M_4 0x2A74 /* Cantiga */ 66#define MEI_DEV_ID_ICH9M_4 0x2A74 /* Cantiga */
67 67
68#define MEI_DEV_ID_ICH10_1 0x2E04 /* Eaglelake */ 68#define MEI_DEV_ID_ICH10_1 0x2E04 /* Eaglelake */
69#define MEI_DEV_ID_ICH10_2 0x2E14 /* Eaglelake */ 69#define MEI_DEV_ID_ICH10_2 0x2E14 /* Eaglelake */
70#define MEI_DEV_ID_ICH10_3 0x2E24 /* Eaglelake */ 70#define MEI_DEV_ID_ICH10_3 0x2E24 /* Eaglelake */
71#define MEI_DEV_ID_ICH10_4 0x2E34 /* Eaglelake */ 71#define MEI_DEV_ID_ICH10_4 0x2E34 /* Eaglelake */
72 72
73#define MEI_DEV_ID_IBXPK_1 0x3B64 /* Calpella */ 73#define MEI_DEV_ID_IBXPK_1 0x3B64 /* Calpella */
74#define MEI_DEV_ID_IBXPK_2 0x3B65 /* Calpella */ 74#define MEI_DEV_ID_IBXPK_2 0x3B65 /* Calpella */
75 75
76#define MEI_DEV_ID_CPT_1 0x1C3A /* Cougerpoint */ 76#define MEI_DEV_ID_CPT_1 0x1C3A /* Couger Point */
77#define MEI_DEV_ID_PBG_1 0x1D3A /* PBG */ 77#define MEI_DEV_ID_PBG_1 0x1D3A /* C600/X79 Patsburg */
78 78
79#define MEI_DEV_ID_PPT_1 0x1E3A /* Pantherpoint PPT */ 79#define MEI_DEV_ID_PPT_1 0x1E3A /* Panther Point */
80#define MEI_DEV_ID_PPT_2 0x1CBA /* Pantherpoint PPT */ 80#define MEI_DEV_ID_PPT_2 0x1CBA /* Panther Point */
81#define MEI_DEV_ID_PPT_3 0x1DBA /* Pantherpoint PPT */ 81#define MEI_DEV_ID_PPT_3 0x1DBA /* Panther Point */
82
83 82
84/* 83/*
85 * MEI HW Section 84 * MEI HW Section
diff --git a/drivers/misc/mei/init.c b/drivers/misc/mei/init.c
index e77f86e69fb5..98f1430e3e14 100644
--- a/drivers/misc/mei/init.c
+++ b/drivers/misc/mei/init.c
@@ -24,6 +24,25 @@
24#include "interface.h" 24#include "interface.h"
25#include <linux/mei.h> 25#include <linux/mei.h>
26 26
27const char *mei_dev_state_str(int state)
28{
29#define MEI_DEV_STATE(state) case MEI_DEV_##state: return #state
30 switch (state) {
31 MEI_DEV_STATE(INITIALIZING);
32 MEI_DEV_STATE(INIT_CLIENTS);
33 MEI_DEV_STATE(ENABLED);
34 MEI_DEV_STATE(RESETING);
35 MEI_DEV_STATE(DISABLED);
36 MEI_DEV_STATE(RECOVERING_FROM_RESET);
37 MEI_DEV_STATE(POWER_DOWN);
38 MEI_DEV_STATE(POWER_UP);
39 default:
40 return "unkown";
41 }
42#undef MEI_DEV_STATE
43}
44
45
27const uuid_le mei_amthi_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, 0xac, 46const uuid_le mei_amthi_guid = UUID_LE(0x12f80028, 0xb4b7, 0x4b2d, 0xac,
28 0xa8, 0x46, 0xe0, 0xff, 0x65, 47 0xa8, 0x46, 0xe0, 0xff, 0x65,
29 0x81, 0x4c); 48 0x81, 0x4c);
@@ -123,7 +142,7 @@ struct mei_device *mei_device_init(struct pci_dev *pdev)
123 mutex_init(&dev->device_lock); 142 mutex_init(&dev->device_lock);
124 init_waitqueue_head(&dev->wait_recvd_msg); 143 init_waitqueue_head(&dev->wait_recvd_msg);
125 init_waitqueue_head(&dev->wait_stop_wd); 144 init_waitqueue_head(&dev->wait_stop_wd);
126 dev->mei_state = MEI_INITIALIZING; 145 dev->dev_state = MEI_DEV_INITIALIZING;
127 dev->iamthif_state = MEI_IAMTHIF_IDLE; 146 dev->iamthif_state = MEI_IAMTHIF_IDLE;
128 dev->wd_interface_reg = false; 147 dev->wd_interface_reg = false;
129 148
@@ -182,7 +201,7 @@ int mei_hw_init(struct mei_device *dev)
182 } 201 }
183 202
184 if (err <= 0 && !dev->recvd_msg) { 203 if (err <= 0 && !dev->recvd_msg) {
185 dev->mei_state = MEI_DISABLED; 204 dev->dev_state = MEI_DEV_DISABLED;
186 dev_dbg(&dev->pdev->dev, 205 dev_dbg(&dev->pdev->dev,
187 "wait_event_interruptible_timeout failed" 206 "wait_event_interruptible_timeout failed"
188 "on wait for ME to turn on ME_RDY.\n"); 207 "on wait for ME to turn on ME_RDY.\n");
@@ -192,7 +211,7 @@ int mei_hw_init(struct mei_device *dev)
192 211
193 if (!(((dev->host_hw_state & H_RDY) == H_RDY) && 212 if (!(((dev->host_hw_state & H_RDY) == H_RDY) &&
194 ((dev->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA))) { 213 ((dev->me_hw_state & ME_RDY_HRA) == ME_RDY_HRA))) {
195 dev->mei_state = MEI_DISABLED; 214 dev->dev_state = MEI_DEV_DISABLED;
196 dev_dbg(&dev->pdev->dev, 215 dev_dbg(&dev->pdev->dev,
197 "host_hw_state = 0x%08x, me_hw_state = 0x%08x.\n", 216 "host_hw_state = 0x%08x, me_hw_state = 0x%08x.\n",
198 dev->host_hw_state, dev->me_hw_state); 217 dev->host_hw_state, dev->me_hw_state);
@@ -258,15 +277,15 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
258 struct mei_cl_cb *cb_next = NULL; 277 struct mei_cl_cb *cb_next = NULL;
259 bool unexpected; 278 bool unexpected;
260 279
261 if (dev->mei_state == MEI_RECOVERING_FROM_RESET) { 280 if (dev->dev_state == MEI_DEV_RECOVERING_FROM_RESET) {
262 dev->need_reset = true; 281 dev->need_reset = true;
263 return; 282 return;
264 } 283 }
265 284
266 unexpected = (dev->mei_state != MEI_INITIALIZING && 285 unexpected = (dev->dev_state != MEI_DEV_INITIALIZING &&
267 dev->mei_state != MEI_DISABLED && 286 dev->dev_state != MEI_DEV_DISABLED &&
268 dev->mei_state != MEI_POWER_DOWN && 287 dev->dev_state != MEI_DEV_POWER_DOWN &&
269 dev->mei_state != MEI_POWER_UP); 288 dev->dev_state != MEI_DEV_POWER_UP);
270 289
271 dev->host_hw_state = mei_hcsr_read(dev); 290 dev->host_hw_state = mei_hcsr_read(dev);
272 291
@@ -285,10 +304,10 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
285 304
286 dev->need_reset = false; 305 dev->need_reset = false;
287 306
288 if (dev->mei_state != MEI_INITIALIZING) { 307 if (dev->dev_state != MEI_DEV_INITIALIZING) {
289 if (dev->mei_state != MEI_DISABLED && 308 if (dev->dev_state != MEI_DEV_DISABLED &&
290 dev->mei_state != MEI_POWER_DOWN) 309 dev->dev_state != MEI_DEV_POWER_DOWN)
291 dev->mei_state = MEI_RESETING; 310 dev->dev_state = MEI_DEV_RESETING;
292 311
293 list_for_each_entry_safe(cl_pos, 312 list_for_each_entry_safe(cl_pos,
294 cl_next, &dev->file_list, link) { 313 cl_next, &dev->file_list, link) {
@@ -311,7 +330,6 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
311 330
312 dev->me_clients_num = 0; 331 dev->me_clients_num = 0;
313 dev->rd_msg_hdr = 0; 332 dev->rd_msg_hdr = 0;
314 dev->stop = false;
315 dev->wd_pending = false; 333 dev->wd_pending = false;
316 334
317 /* update the state of the registers after reset */ 335 /* update the state of the registers after reset */
@@ -322,7 +340,8 @@ void mei_reset(struct mei_device *dev, int interrupts_enabled)
322 dev->host_hw_state, dev->me_hw_state); 340 dev->host_hw_state, dev->me_hw_state);
323 341
324 if (unexpected) 342 if (unexpected)
325 dev_warn(&dev->pdev->dev, "unexpected reset.\n"); 343 dev_warn(&dev->pdev->dev, "unexpected reset: dev_state = %s\n",
344 mei_dev_state_str(dev->dev_state));
326 345
327 /* Wake up all readings so they can be interrupted */ 346 /* Wake up all readings so they can be interrupted */
328 list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) { 347 list_for_each_entry_safe(cl_pos, cl_next, &dev->file_list, link) {
@@ -371,7 +390,7 @@ void mei_host_start_message(struct mei_device *dev)
371 if (mei_write_message(dev, mei_hdr, (unsigned char *)host_start_req, 390 if (mei_write_message(dev, mei_hdr, (unsigned char *)host_start_req,
372 mei_hdr->length)) { 391 mei_hdr->length)) {
373 dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n"); 392 dev_dbg(&dev->pdev->dev, "write send version message to FW fail.\n");
374 dev->mei_state = MEI_RESETING; 393 dev->dev_state = MEI_DEV_RESETING;
375 mei_reset(dev, 1); 394 mei_reset(dev, 1);
376 } 395 }
377 dev->init_clients_state = MEI_START_MESSAGE; 396 dev->init_clients_state = MEI_START_MESSAGE;
@@ -403,7 +422,7 @@ void mei_host_enum_clients_message(struct mei_device *dev)
403 host_enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; 422 host_enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
404 if (mei_write_message(dev, mei_hdr, (unsigned char *)host_enum_req, 423 if (mei_write_message(dev, mei_hdr, (unsigned char *)host_enum_req,
405 mei_hdr->length)) { 424 mei_hdr->length)) {
406 dev->mei_state = MEI_RESETING; 425 dev->dev_state = MEI_DEV_RESETING;
407 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); 426 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n");
408 mei_reset(dev, 1); 427 mei_reset(dev, 1);
409 } 428 }
@@ -444,7 +463,7 @@ void mei_allocate_me_clients_storage(struct mei_device *dev)
444 sizeof(struct mei_me_client), GFP_KERNEL); 463 sizeof(struct mei_me_client), GFP_KERNEL);
445 if (!clients) { 464 if (!clients) {
446 dev_dbg(&dev->pdev->dev, "memory allocation for ME clients failed.\n"); 465 dev_dbg(&dev->pdev->dev, "memory allocation for ME clients failed.\n");
447 dev->mei_state = MEI_RESETING; 466 dev->dev_state = MEI_DEV_RESETING;
448 mei_reset(dev, 1); 467 mei_reset(dev, 1);
449 return ; 468 return ;
450 } 469 }
@@ -490,7 +509,7 @@ int mei_host_client_properties(struct mei_device *dev)
490 if (mei_write_message(dev, mei_header, 509 if (mei_write_message(dev, mei_header,
491 (unsigned char *)host_cli_req, 510 (unsigned char *)host_cli_req,
492 mei_header->length)) { 511 mei_header->length)) {
493 dev->mei_state = MEI_RESETING; 512 dev->dev_state = MEI_DEV_RESETING;
494 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n"); 513 dev_dbg(&dev->pdev->dev, "write send enumeration request message to FW fail.\n");
495 mei_reset(dev, 1); 514 mei_reset(dev, 1);
496 return -EIO; 515 return -EIO;
@@ -522,12 +541,12 @@ void mei_cl_init(struct mei_cl *priv, struct mei_device *dev)
522 priv->dev = dev; 541 priv->dev = dev;
523} 542}
524 543
525int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid) 544int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid)
526{ 545{
527 int i, res = -1; 546 int i, res = -ENOENT;
528 547
529 for (i = 0; i < dev->me_clients_num; ++i) 548 for (i = 0; i < dev->me_clients_num; ++i)
530 if (uuid_le_cmp(cuuid, 549 if (uuid_le_cmp(*cuuid,
531 dev->me_clients[i].props.protocol_name) == 0) { 550 dev->me_clients[i].props.protocol_name) == 0) {
532 res = i; 551 res = i;
533 break; 552 break;
@@ -538,35 +557,35 @@ int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid)
538 557
539 558
540/** 559/**
541 * mei_find_me_client_update_filext - searches for ME client guid 560 * mei_me_cl_update_filext - searches for ME client guid
542 * sets client_id in mei_file_private if found 561 * sets client_id in mei_file_private if found
543 * @dev: the device structure 562 * @dev: the device structure
544 * @priv: private file structure to set client_id in 563 * @cl: private file structure to set client_id in
545 * @cguid: searched guid of ME client 564 * @cuuid: searched uuid of ME client
546 * @client_id: id of host client to be set in file private structure 565 * @client_id: id of host client to be set in file private structure
547 * 566 *
548 * returns ME client index 567 * returns ME client index
549 */ 568 */
550u8 mei_find_me_client_update_filext(struct mei_device *dev, struct mei_cl *priv, 569int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
551 const uuid_le *cguid, u8 client_id) 570 const uuid_le *cuuid, u8 host_cl_id)
552{ 571{
553 int i; 572 int i;
554 573
555 if (!dev || !priv || !cguid) 574 if (!dev || !cl || !cuuid)
556 return 0; 575 return -EINVAL;
557 576
558 /* check for valid client id */ 577 /* check for valid client id */
559 i = mei_find_me_client_index(dev, *cguid); 578 i = mei_me_cl_by_uuid(dev, cuuid);
560 if (i >= 0) { 579 if (i >= 0) {
561 priv->me_client_id = dev->me_clients[i].client_id; 580 cl->me_client_id = dev->me_clients[i].client_id;
562 priv->state = MEI_FILE_CONNECTING; 581 cl->state = MEI_FILE_CONNECTING;
563 priv->host_client_id = client_id; 582 cl->host_client_id = host_cl_id;
564 583
565 list_add_tail(&priv->link, &dev->file_list); 584 list_add_tail(&cl->link, &dev->file_list);
566 return (u8)i; 585 return (u8)i;
567 } 586 }
568 587
569 return 0; 588 return -ENOENT;
570} 589}
571 590
572/** 591/**
@@ -577,16 +596,16 @@ u8 mei_find_me_client_update_filext(struct mei_device *dev, struct mei_cl *priv,
577 */ 596 */
578void mei_host_init_iamthif(struct mei_device *dev) 597void mei_host_init_iamthif(struct mei_device *dev)
579{ 598{
580 u8 i; 599 int i;
581 unsigned char *msg_buf; 600 unsigned char *msg_buf;
582 601
583 mei_cl_init(&dev->iamthif_cl, dev); 602 mei_cl_init(&dev->iamthif_cl, dev);
584 dev->iamthif_cl.state = MEI_FILE_DISCONNECTED; 603 dev->iamthif_cl.state = MEI_FILE_DISCONNECTED;
585 604
586 /* find ME amthi client */ 605 /* find ME amthi client */
587 i = mei_find_me_client_update_filext(dev, &dev->iamthif_cl, 606 i = mei_me_cl_update_filext(dev, &dev->iamthif_cl,
588 &mei_amthi_guid, MEI_IAMTHIF_HOST_CLIENT_ID); 607 &mei_amthi_guid, MEI_IAMTHIF_HOST_CLIENT_ID);
589 if (dev->iamthif_cl.state != MEI_FILE_CONNECTING) { 608 if (i < 0) {
590 dev_dbg(&dev->pdev->dev, "failed to find iamthif client.\n"); 609 dev_dbg(&dev->pdev->dev, "failed to find iamthif client.\n");
591 return; 610 return;
592 } 611 }
diff --git a/drivers/misc/mei/interface.h b/drivers/misc/mei/interface.h
index fb5c7db4723b..ec6c785a3961 100644
--- a/drivers/misc/mei/interface.h
+++ b/drivers/misc/mei/interface.h
@@ -23,14 +23,6 @@
23#include "mei_dev.h" 23#include "mei_dev.h"
24 24
25 25
26#define AMT_WD_DEFAULT_TIMEOUT 120 /* seconds */
27#define AMT_WD_MIN_TIMEOUT 120 /* seconds */
28#define AMT_WD_MAX_TIMEOUT 65535 /* seconds */
29
30#define MEI_WATCHDOG_DATA_SIZE 16
31#define MEI_START_WD_DATA_SIZE 20
32#define MEI_WD_PARAMS_SIZE 4
33
34 26
35void mei_read_slots(struct mei_device *dev, 27void mei_read_slots(struct mei_device *dev,
36 unsigned char *buffer, 28 unsigned char *buffer,
@@ -64,7 +56,7 @@ int mei_flow_ctrl_creds(struct mei_device *dev, struct mei_cl *cl);
64 56
65 57
66int mei_wd_send(struct mei_device *dev); 58int mei_wd_send(struct mei_device *dev);
67int mei_wd_stop(struct mei_device *dev, bool preserve); 59int mei_wd_stop(struct mei_device *dev);
68int mei_wd_host_init(struct mei_device *dev); 60int mei_wd_host_init(struct mei_device *dev);
69/* 61/*
70 * mei_watchdog_register - Registering watchdog interface 62 * mei_watchdog_register - Registering watchdog interface
diff --git a/drivers/misc/mei/interrupt.c b/drivers/misc/mei/interrupt.c
index d78c05e693f7..0900a711badd 100644
--- a/drivers/misc/mei/interrupt.c
+++ b/drivers/misc/mei/interrupt.c
@@ -633,7 +633,7 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
633 if (version_res->host_version_supported) { 633 if (version_res->host_version_supported) {
634 dev->version.major_version = HBM_MAJOR_VERSION; 634 dev->version.major_version = HBM_MAJOR_VERSION;
635 dev->version.minor_version = HBM_MINOR_VERSION; 635 dev->version.minor_version = HBM_MINOR_VERSION;
636 if (dev->mei_state == MEI_INIT_CLIENTS && 636 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
637 dev->init_clients_state == MEI_START_MESSAGE) { 637 dev->init_clients_state == MEI_START_MESSAGE) {
638 dev->init_clients_timer = 0; 638 dev->init_clients_timer = 0;
639 mei_host_enum_clients_message(dev); 639 mei_host_enum_clients_message(dev);
@@ -707,7 +707,7 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
707 dev->me_clients[dev->me_client_presentation_num].props 707 dev->me_clients[dev->me_client_presentation_num].props
708 = props_res->client_properties; 708 = props_res->client_properties;
709 709
710 if (dev->mei_state == MEI_INIT_CLIENTS && 710 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
711 dev->init_clients_state == 711 dev->init_clients_state ==
712 MEI_CLIENT_PROPERTIES_MESSAGE) { 712 MEI_CLIENT_PROPERTIES_MESSAGE) {
713 dev->me_client_index++; 713 dev->me_client_index++;
@@ -734,7 +734,7 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
734 * Client ID 2 - Reserved for AMTHI 734 * Client ID 2 - Reserved for AMTHI
735 */ 735 */
736 bitmap_set(dev->host_clients_map, 0, 3); 736 bitmap_set(dev->host_clients_map, 0, 3);
737 dev->mei_state = MEI_ENABLED; 737 dev->dev_state = MEI_DEV_ENABLED;
738 738
739 /* if wd initialization fails, initialization the AMTHI client, 739 /* if wd initialization fails, initialization the AMTHI client,
740 * otherwise the AMTHI client will be initialized after the WD client connect response 740 * otherwise the AMTHI client will be initialized after the WD client connect response
@@ -759,7 +759,7 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
759 case HOST_ENUM_RES_CMD: 759 case HOST_ENUM_RES_CMD:
760 enum_res = (struct hbm_host_enum_response *) mei_msg; 760 enum_res = (struct hbm_host_enum_response *) mei_msg;
761 memcpy(dev->me_clients_map, enum_res->valid_addresses, 32); 761 memcpy(dev->me_clients_map, enum_res->valid_addresses, 32);
762 if (dev->mei_state == MEI_INIT_CLIENTS && 762 if (dev->dev_state == MEI_DEV_INIT_CLIENTS &&
763 dev->init_clients_state == MEI_ENUM_CLIENTS_MESSAGE) { 763 dev->init_clients_state == MEI_ENUM_CLIENTS_MESSAGE) {
764 dev->init_clients_timer = 0; 764 dev->init_clients_timer = 0;
765 dev->me_client_presentation_num = 0; 765 dev->me_client_presentation_num = 0;
@@ -776,7 +776,7 @@ static void mei_irq_thread_read_bus_message(struct mei_device *dev,
776 break; 776 break;
777 777
778 case HOST_STOP_RES_CMD: 778 case HOST_STOP_RES_CMD:
779 dev->mei_state = MEI_DISABLED; 779 dev->dev_state = MEI_DEV_DISABLED;
780 dev_dbg(&dev->pdev->dev, "resetting because of FW stop response.\n"); 780 dev_dbg(&dev->pdev->dev, "resetting because of FW stop response.\n");
781 mei_reset(dev, 1); 781 mei_reset(dev, 1);
782 break; 782 break;
@@ -1224,10 +1224,9 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
1224 } 1224 }
1225 } 1225 }
1226 1226
1227 if (dev->stop && !dev->wd_pending) { 1227 if (dev->wd_state == MEI_WD_STOPPING) {
1228 dev->wd_stopped = true; 1228 dev->wd_state = MEI_WD_IDLE;
1229 wake_up_interruptible(&dev->wait_stop_wd); 1229 wake_up_interruptible(&dev->wait_stop_wd);
1230 return 0;
1231 } 1230 }
1232 1231
1233 if (dev->extra_write_index) { 1232 if (dev->extra_write_index) {
@@ -1240,7 +1239,7 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
1240 *slots -= dev->extra_write_index; 1239 *slots -= dev->extra_write_index;
1241 dev->extra_write_index = 0; 1240 dev->extra_write_index = 0;
1242 } 1241 }
1243 if (dev->mei_state == MEI_ENABLED) { 1242 if (dev->dev_state == MEI_DEV_ENABLED) {
1244 if (dev->wd_pending && 1243 if (dev->wd_pending &&
1245 mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) { 1244 mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) {
1246 if (mei_wd_send(dev)) 1245 if (mei_wd_send(dev))
@@ -1250,14 +1249,12 @@ static int mei_irq_thread_write_handler(struct mei_io_list *cmpl_list,
1250 1249
1251 dev->wd_pending = false; 1250 dev->wd_pending = false;
1252 1251
1253 if (dev->wd_timeout) 1252 if (dev->wd_state == MEI_WD_RUNNING)
1254 *slots -= mei_data2slots(MEI_START_WD_DATA_SIZE); 1253 *slots -= mei_data2slots(MEI_WD_START_MSG_SIZE);
1255 else 1254 else
1256 *slots -= mei_data2slots(MEI_WD_PARAMS_SIZE); 1255 *slots -= mei_data2slots(MEI_WD_STOP_MSG_SIZE);
1257 } 1256 }
1258 } 1257 }
1259 if (dev->stop)
1260 return -ENODEV;
1261 1258
1262 /* complete control write list CB */ 1259 /* complete control write list CB */
1263 dev_dbg(&dev->pdev->dev, "complete control write list cb.\n"); 1260 dev_dbg(&dev->pdev->dev, "complete control write list cb.\n");
@@ -1361,8 +1358,8 @@ void mei_timer(struct work_struct *work)
1361 1358
1362 1359
1363 mutex_lock(&dev->device_lock); 1360 mutex_lock(&dev->device_lock);
1364 if (dev->mei_state != MEI_ENABLED) { 1361 if (dev->dev_state != MEI_DEV_ENABLED) {
1365 if (dev->mei_state == MEI_INIT_CLIENTS) { 1362 if (dev->dev_state == MEI_DEV_INIT_CLIENTS) {
1366 if (dev->init_clients_timer) { 1363 if (dev->init_clients_timer) {
1367 if (--dev->init_clients_timer == 0) { 1364 if (--dev->init_clients_timer == 0) {
1368 dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n", 1365 dev_dbg(&dev->pdev->dev, "IMEI reset due to init clients timeout ,init clients state = %d.\n",
@@ -1484,8 +1481,8 @@ irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
1484 1481
1485 /* check if ME wants a reset */ 1482 /* check if ME wants a reset */
1486 if ((dev->me_hw_state & ME_RDY_HRA) == 0 && 1483 if ((dev->me_hw_state & ME_RDY_HRA) == 0 &&
1487 dev->mei_state != MEI_RESETING && 1484 dev->dev_state != MEI_DEV_RESETING &&
1488 dev->mei_state != MEI_INITIALIZING) { 1485 dev->dev_state != MEI_DEV_INITIALIZING) {
1489 dev_dbg(&dev->pdev->dev, "FW not ready.\n"); 1486 dev_dbg(&dev->pdev->dev, "FW not ready.\n");
1490 mei_reset(dev, 1); 1487 mei_reset(dev, 1);
1491 mutex_unlock(&dev->device_lock); 1488 mutex_unlock(&dev->device_lock);
@@ -1498,7 +1495,7 @@ irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id)
1498 dev_dbg(&dev->pdev->dev, "we need to start the dev.\n"); 1495 dev_dbg(&dev->pdev->dev, "we need to start the dev.\n");
1499 dev->host_hw_state |= (H_IE | H_IG | H_RDY); 1496 dev->host_hw_state |= (H_IE | H_IG | H_RDY);
1500 mei_hcsr_set(dev); 1497 mei_hcsr_set(dev);
1501 dev->mei_state = MEI_INIT_CLIENTS; 1498 dev->dev_state = MEI_DEV_INIT_CLIENTS;
1502 dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n"); 1499 dev_dbg(&dev->pdev->dev, "link is established start sending messages.\n");
1503 /* link is established 1500 /* link is established
1504 * start sending messages. 1501 * start sending messages.
diff --git a/drivers/misc/mei/iorw.c b/drivers/misc/mei/iorw.c
index 50f52e21f587..fcba98eb892e 100644
--- a/drivers/misc/mei/iorw.c
+++ b/drivers/misc/mei/iorw.c
@@ -38,7 +38,31 @@
38#include <linux/mei.h> 38#include <linux/mei.h>
39#include "interface.h" 39#include "interface.h"
40 40
41/**
42 * mei_me_cl_by_id return index to me_clients for client_id
43 *
44 * @dev: the device structure
45 * @client_id: me client id
46 *
47 * Locking: called under "dev->device_lock" lock
48 *
49 * returns index on success, -ENOENT on failure.
50 */
41 51
52int mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
53{
54 int i;
55 for (i = 0; i < dev->me_clients_num; i++)
56 if (dev->me_clients[i].client_id == client_id)
57 break;
58 if (WARN_ON(dev->me_clients[i].client_id != client_id))
59 return -ENOENT;
60
61 if (i == dev->me_clients_num)
62 return -ENOENT;
63
64 return i;
65}
42 66
43/** 67/**
44 * mei_ioctl_connect_client - the connect to fw client IOCTL function 68 * mei_ioctl_connect_client - the connect to fw client IOCTL function
@@ -84,7 +108,7 @@ int mei_ioctl_connect_client(struct file *file,
84 108
85 cb->major_file_operations = MEI_IOCTL; 109 cb->major_file_operations = MEI_IOCTL;
86 110
87 if (dev->mei_state != MEI_ENABLED) { 111 if (dev->dev_state != MEI_DEV_ENABLED) {
88 rets = -ENODEV; 112 rets = -ENODEV;
89 goto end; 113 goto end;
90 } 114 }
@@ -95,7 +119,7 @@ int mei_ioctl_connect_client(struct file *file,
95 } 119 }
96 120
97 /* find ME client we're trying to connect to */ 121 /* find ME client we're trying to connect to */
98 i = mei_find_me_client_index(dev, data->in_client_uuid); 122 i = mei_me_cl_by_uuid(dev, &data->in_client_uuid);
99 if (i >= 0 && !dev->me_clients[i].props.fixed_address) { 123 if (i >= 0 && !dev->me_clients[i].props.fixed_address) {
100 cl->me_client_id = dev->me_clients[i].client_id; 124 cl->me_client_id = dev->me_clients[i].client_id;
101 cl->state = MEI_FILE_CONNECTING; 125 cl->state = MEI_FILE_CONNECTING;
@@ -273,19 +297,12 @@ int amthi_read(struct mei_device *dev, struct file *file,
273 return -ETIMEDOUT; 297 return -ETIMEDOUT;
274 } 298 }
275 299
276 for (i = 0; i < dev->me_clients_num; i++) { 300 i = mei_me_cl_by_id(dev, dev->iamthif_cl.me_client_id);
277 if (dev->me_clients[i].client_id ==
278 dev->iamthif_cl.me_client_id)
279 break;
280 }
281 301
282 if (i == dev->me_clients_num) { 302 if (i < 0) {
283 dev_dbg(&dev->pdev->dev, "amthi client not found.\n"); 303 dev_dbg(&dev->pdev->dev, "amthi client not found.\n");
284 return -ENODEV; 304 return -ENODEV;
285 } 305 }
286 if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id))
287 return -ENODEV;
288
289 dev_dbg(&dev->pdev->dev, "checking amthi data\n"); 306 dev_dbg(&dev->pdev->dev, "checking amthi data\n");
290 cb = find_amthi_read_list_entry(dev, file); 307 cb = find_amthi_read_list_entry(dev, file);
291 308
@@ -316,8 +333,7 @@ int amthi_read(struct mei_device *dev, struct file *file,
316 dev->iamthif_timer = 0; 333 dev->iamthif_timer = 0;
317 334
318 if (cb) { 335 if (cb) {
319 timeout = cb->read_time + 336 timeout = cb->read_time + msecs_to_jiffies(IAMTHIF_READ_TIMER);
320 msecs_to_jiffies(IAMTHIF_READ_TIMER);
321 dev_dbg(&dev->pdev->dev, "amthi timeout = %lud\n", 337 dev_dbg(&dev->pdev->dev, "amthi timeout = %lud\n",
322 timeout); 338 timeout);
323 339
@@ -386,7 +402,7 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl)
386 if (cl->state != MEI_FILE_CONNECTED) 402 if (cl->state != MEI_FILE_CONNECTED)
387 return -ENODEV; 403 return -ENODEV;
388 404
389 if (dev->mei_state != MEI_ENABLED) 405 if (dev->dev_state != MEI_DEV_ENABLED)
390 return -ENODEV; 406 return -ENODEV;
391 407
392 dev_dbg(&dev->pdev->dev, "check if read is pending.\n"); 408 dev_dbg(&dev->pdev->dev, "check if read is pending.\n");
@@ -401,19 +417,8 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl)
401 417
402 dev_dbg(&dev->pdev->dev, "allocation call back successful. host client = %d, ME client = %d\n", 418 dev_dbg(&dev->pdev->dev, "allocation call back successful. host client = %d, ME client = %d\n",
403 cl->host_client_id, cl->me_client_id); 419 cl->host_client_id, cl->me_client_id);
404 420 i = mei_me_cl_by_id(dev, cl->me_client_id);
405 for (i = 0; i < dev->me_clients_num; i++) { 421 if (i < 0) {
406 if (dev->me_clients[i].client_id == cl->me_client_id)
407 break;
408
409 }
410
411 if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id)) {
412 rets = -ENODEV;
413 goto unlock;
414 }
415
416 if (i == dev->me_clients_num) {
417 rets = -ENODEV; 422 rets = -ENODEV;
418 goto unlock; 423 goto unlock;
419 } 424 }
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index 7422c7652845..9a595338ae15 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -41,8 +41,6 @@
41#include <linux/mei.h> 41#include <linux/mei.h>
42#include "interface.h" 42#include "interface.h"
43 43
44static const char mei_driver_name[] = "mei";
45
46/* The device pointer */ 44/* The device pointer */
47/* Currently this driver works as long as there is only a single AMT device. */ 45/* Currently this driver works as long as there is only a single AMT device. */
48struct pci_dev *mei_device; 46struct pci_dev *mei_device;
@@ -234,9 +232,9 @@ static int mei_open(struct inode *inode, struct file *file)
234 goto out_unlock; 232 goto out_unlock;
235 233
236 err = -ENODEV; 234 err = -ENODEV;
237 if (dev->mei_state != MEI_ENABLED) { 235 if (dev->dev_state != MEI_DEV_ENABLED) {
238 dev_dbg(&dev->pdev->dev, "mei_state != MEI_ENABLED mei_state= %d\n", 236 dev_dbg(&dev->pdev->dev, "dev_state != MEI_ENABLED dev_state = %s\n",
239 dev->mei_state); 237 mei_dev_state_str(dev->dev_state));
240 goto out_unlock; 238 goto out_unlock;
241 } 239 }
242 err = -EMFILE; 240 err = -EMFILE;
@@ -386,17 +384,16 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
386 dev = cl->dev; 384 dev = cl->dev;
387 385
388 mutex_lock(&dev->device_lock); 386 mutex_lock(&dev->device_lock);
389 if (dev->mei_state != MEI_ENABLED) { 387 if (dev->dev_state != MEI_DEV_ENABLED) {
390 rets = -ENODEV; 388 rets = -ENODEV;
391 goto out; 389 goto out;
392 } 390 }
393 391
394 if ((cl->sm_state & MEI_WD_STATE_INDEPENDENCE_MSG_SENT) == 0) { 392 if ((cl->sm_state & MEI_WD_STATE_INDEPENDENCE_MSG_SENT) == 0) {
395 /* Do not allow to read watchdog client */ 393 /* Do not allow to read watchdog client */
396 i = mei_find_me_client_index(dev, mei_wd_guid); 394 i = mei_me_cl_by_uuid(dev, &mei_wd_guid);
397 if (i >= 0) { 395 if (i >= 0) {
398 struct mei_me_client *me_client = &dev->me_clients[i]; 396 struct mei_me_client *me_client = &dev->me_clients[i];
399
400 if (cl->me_client_id == me_client->client_id) { 397 if (cl->me_client_id == me_client->client_id) {
401 rets = -EBADF; 398 rets = -EBADF;
402 goto out; 399 goto out;
@@ -541,7 +538,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
541 538
542 mutex_lock(&dev->device_lock); 539 mutex_lock(&dev->device_lock);
543 540
544 if (dev->mei_state != MEI_ENABLED) { 541 if (dev->dev_state != MEI_DEV_ENABLED) {
545 mutex_unlock(&dev->device_lock); 542 mutex_unlock(&dev->device_lock);
546 return -ENODEV; 543 return -ENODEV;
547 } 544 }
@@ -616,26 +613,16 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
616 rets = -ENOMEM; 613 rets = -ENOMEM;
617 goto unlock_dev; 614 goto unlock_dev;
618 } 615 }
619 if (dev->mei_state != MEI_ENABLED) { 616 if (dev->dev_state != MEI_DEV_ENABLED) {
620 rets = -ENODEV; 617 rets = -ENODEV;
621 goto unlock_dev; 618 goto unlock_dev;
622 } 619 }
623 for (i = 0; i < dev->me_clients_num; i++) { 620 i = mei_me_cl_by_id(dev, dev->iamthif_cl.me_client_id);
624 if (dev->me_clients[i].client_id == 621 if (i < 0) {
625 dev->iamthif_cl.me_client_id)
626 break;
627 }
628
629 if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id)) {
630 rets = -ENODEV; 622 rets = -ENODEV;
631 goto unlock_dev; 623 goto unlock_dev;
632 } 624 }
633 if (i == dev->me_clients_num || 625 if (length > dev->me_clients[i].props.max_msg_length ||
634 (dev->me_clients[i].client_id !=
635 dev->iamthif_cl.me_client_id)) {
636 rets = -ENODEV;
637 goto unlock_dev;
638 } else if (length > dev->me_clients[i].props.max_msg_length ||
639 length <= 0) { 626 length <= 0) {
640 rets = -EMSGSIZE; 627 rets = -EMSGSIZE;
641 goto unlock_dev; 628 goto unlock_dev;
@@ -688,16 +675,8 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
688 cl->me_client_id); 675 cl->me_client_id);
689 goto unlock_dev; 676 goto unlock_dev;
690 } 677 }
691 for (i = 0; i < dev->me_clients_num; i++) { 678 i = mei_me_cl_by_id(dev, cl->me_client_id);
692 if (dev->me_clients[i].client_id == 679 if (i < 0) {
693 cl->me_client_id)
694 break;
695 }
696 if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id)) {
697 rets = -ENODEV;
698 goto unlock_dev;
699 }
700 if (i == dev->me_clients_num) {
701 rets = -ENODEV; 680 rets = -ENODEV;
702 goto unlock_dev; 681 goto unlock_dev;
703 } 682 }
@@ -790,7 +769,7 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)
790 dev_dbg(&dev->pdev->dev, "IOCTL cmd = 0x%x", cmd); 769 dev_dbg(&dev->pdev->dev, "IOCTL cmd = 0x%x", cmd);
791 770
792 mutex_lock(&dev->device_lock); 771 mutex_lock(&dev->device_lock);
793 if (dev->mei_state != MEI_ENABLED) { 772 if (dev->dev_state != MEI_DEV_ENABLED) {
794 rets = -ENODEV; 773 rets = -ENODEV;
795 goto out; 774 goto out;
796 } 775 }
@@ -869,7 +848,7 @@ static unsigned int mei_poll(struct file *file, poll_table *wait)
869 848
870 mutex_lock(&dev->device_lock); 849 mutex_lock(&dev->device_lock);
871 850
872 if (dev->mei_state != MEI_ENABLED) 851 if (dev->dev_state != MEI_DEV_ENABLED)
873 goto out; 852 goto out;
874 853
875 854
@@ -979,7 +958,7 @@ static int __devinit mei_probe(struct pci_dev *pdev,
979 /* set PCI host mastering */ 958 /* set PCI host mastering */
980 pci_set_master(pdev); 959 pci_set_master(pdev);
981 /* pci request regions for mei driver */ 960 /* pci request regions for mei driver */
982 err = pci_request_regions(pdev, mei_driver_name); 961 err = pci_request_regions(pdev, KBUILD_MODNAME);
983 if (err) { 962 if (err) {
984 dev_err(&pdev->dev, "failed to get pci regions.\n"); 963 dev_err(&pdev->dev, "failed to get pci regions.\n");
985 goto disable_device; 964 goto disable_device;
@@ -1004,12 +983,12 @@ static int __devinit mei_probe(struct pci_dev *pdev,
1004 err = request_threaded_irq(pdev->irq, 983 err = request_threaded_irq(pdev->irq,
1005 NULL, 984 NULL,
1006 mei_interrupt_thread_handler, 985 mei_interrupt_thread_handler,
1007 IRQF_ONESHOT, mei_driver_name, dev); 986 IRQF_ONESHOT, KBUILD_MODNAME, dev);
1008 else 987 else
1009 err = request_threaded_irq(pdev->irq, 988 err = request_threaded_irq(pdev->irq,
1010 mei_interrupt_quick_handler, 989 mei_interrupt_quick_handler,
1011 mei_interrupt_thread_handler, 990 mei_interrupt_thread_handler,
1012 IRQF_SHARED, mei_driver_name, dev); 991 IRQF_SHARED, KBUILD_MODNAME, dev);
1013 992
1014 if (err) { 993 if (err) {
1015 dev_err(&pdev->dev, "request_threaded_irq failure. irq = %d\n", 994 dev_err(&pdev->dev, "request_threaded_irq failure. irq = %d\n",
@@ -1081,7 +1060,9 @@ static void __devexit mei_remove(struct pci_dev *pdev)
1081 1060
1082 mutex_lock(&dev->device_lock); 1061 mutex_lock(&dev->device_lock);
1083 1062
1084 mei_wd_stop(dev, false); 1063 cancel_delayed_work(&dev->timer_work);
1064
1065 mei_wd_stop(dev);
1085 1066
1086 mei_device = NULL; 1067 mei_device = NULL;
1087 1068
@@ -1136,12 +1117,15 @@ static int mei_pci_suspend(struct device *device)
1136 if (!dev) 1117 if (!dev)
1137 return -ENODEV; 1118 return -ENODEV;
1138 mutex_lock(&dev->device_lock); 1119 mutex_lock(&dev->device_lock);
1120
1121 cancel_delayed_work(&dev->timer_work);
1122
1139 /* Stop watchdog if exists */ 1123 /* Stop watchdog if exists */
1140 err = mei_wd_stop(dev, true); 1124 err = mei_wd_stop(dev);
1141 /* Set new mei state */ 1125 /* Set new mei state */
1142 if (dev->mei_state == MEI_ENABLED || 1126 if (dev->dev_state == MEI_DEV_ENABLED ||
1143 dev->mei_state == MEI_RECOVERING_FROM_RESET) { 1127 dev->dev_state == MEI_DEV_RECOVERING_FROM_RESET) {
1144 dev->mei_state = MEI_POWER_DOWN; 1128 dev->dev_state = MEI_DEV_POWER_DOWN;
1145 mei_reset(dev, 0); 1129 mei_reset(dev, 0);
1146 } 1130 }
1147 mutex_unlock(&dev->device_lock); 1131 mutex_unlock(&dev->device_lock);
@@ -1169,12 +1153,12 @@ static int mei_pci_resume(struct device *device)
1169 err = request_threaded_irq(pdev->irq, 1153 err = request_threaded_irq(pdev->irq,
1170 NULL, 1154 NULL,
1171 mei_interrupt_thread_handler, 1155 mei_interrupt_thread_handler,
1172 IRQF_ONESHOT, mei_driver_name, dev); 1156 IRQF_ONESHOT, KBUILD_MODNAME, dev);
1173 else 1157 else
1174 err = request_threaded_irq(pdev->irq, 1158 err = request_threaded_irq(pdev->irq,
1175 mei_interrupt_quick_handler, 1159 mei_interrupt_quick_handler,
1176 mei_interrupt_thread_handler, 1160 mei_interrupt_thread_handler,
1177 IRQF_SHARED, mei_driver_name, dev); 1161 IRQF_SHARED, KBUILD_MODNAME, dev);
1178 1162
1179 if (err) { 1163 if (err) {
1180 dev_err(&pdev->dev, "request_threaded_irq failed: irq = %d.\n", 1164 dev_err(&pdev->dev, "request_threaded_irq failed: irq = %d.\n",
@@ -1183,7 +1167,7 @@ static int mei_pci_resume(struct device *device)
1183 } 1167 }
1184 1168
1185 mutex_lock(&dev->device_lock); 1169 mutex_lock(&dev->device_lock);
1186 dev->mei_state = MEI_POWER_UP; 1170 dev->dev_state = MEI_DEV_POWER_UP;
1187 mei_reset(dev, 1); 1171 mei_reset(dev, 1);
1188 mutex_unlock(&dev->device_lock); 1172 mutex_unlock(&dev->device_lock);
1189 1173
@@ -1201,7 +1185,7 @@ static SIMPLE_DEV_PM_OPS(mei_pm_ops, mei_pci_suspend, mei_pci_resume);
1201 * PCI driver structure 1185 * PCI driver structure
1202 */ 1186 */
1203static struct pci_driver mei_driver = { 1187static struct pci_driver mei_driver = {
1204 .name = mei_driver_name, 1188 .name = KBUILD_MODNAME,
1205 .id_table = mei_pci_tbl, 1189 .id_table = mei_pci_tbl,
1206 .probe = mei_probe, 1190 .probe = mei_probe,
1207 .remove = __devexit_p(mei_remove), 1191 .remove = __devexit_p(mei_remove),
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index d61c4ddfc80c..c8660c0eb1c7 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -25,9 +25,16 @@
25/* 25/*
26 * watch dog definition 26 * watch dog definition
27 */ 27 */
28#define MEI_WATCHDOG_DATA_SIZE 16 28#define MEI_WD_HDR_SIZE 4
29#define MEI_START_WD_DATA_SIZE 20 29#define MEI_WD_STOP_MSG_SIZE MEI_WD_HDR_SIZE
30#define MEI_WD_PARAMS_SIZE 4 30#define MEI_WD_START_MSG_SIZE (MEI_WD_HDR_SIZE + 16)
31
32#define MEI_WD_DEFAULT_TIMEOUT 120 /* seconds */
33#define MEI_WD_MIN_TIMEOUT 120 /* seconds */
34#define MEI_WD_MAX_TIMEOUT 65535 /* seconds */
35
36#define MEI_WD_STOP_TIMEOUT 10 /* msecs */
37
31#define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0) 38#define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
32 39
33#define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32)) 40#define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
@@ -78,17 +85,19 @@ enum file_state {
78}; 85};
79 86
80/* MEI device states */ 87/* MEI device states */
81enum mei_states { 88enum mei_dev_state {
82 MEI_INITIALIZING = 0, 89 MEI_DEV_INITIALIZING = 0,
83 MEI_INIT_CLIENTS, 90 MEI_DEV_INIT_CLIENTS,
84 MEI_ENABLED, 91 MEI_DEV_ENABLED,
85 MEI_RESETING, 92 MEI_DEV_RESETING,
86 MEI_DISABLED, 93 MEI_DEV_DISABLED,
87 MEI_RECOVERING_FROM_RESET, 94 MEI_DEV_RECOVERING_FROM_RESET,
88 MEI_POWER_DOWN, 95 MEI_DEV_POWER_DOWN,
89 MEI_POWER_UP 96 MEI_DEV_POWER_UP
90}; 97};
91 98
99const char *mei_dev_state_str(int state);
100
92/* init clients states*/ 101/* init clients states*/
93enum mei_init_clients_states { 102enum mei_init_clients_states {
94 MEI_START_MESSAGE = 0, 103 MEI_START_MESSAGE = 0,
@@ -113,6 +122,12 @@ enum mei_file_transaction_states {
113 MEI_READ_COMPLETE 122 MEI_READ_COMPLETE
114}; 123};
115 124
125enum mei_wd_states {
126 MEI_WD_IDLE,
127 MEI_WD_RUNNING,
128 MEI_WD_STOPPING,
129};
130
116/* MEI CB */ 131/* MEI CB */
117enum mei_cb_major_types { 132enum mei_cb_major_types {
118 MEI_READ = 0, 133 MEI_READ = 0,
@@ -218,10 +233,9 @@ struct mei_device {
218 /* 233 /*
219 * mei device states 234 * mei device states
220 */ 235 */
221 enum mei_states mei_state; 236 enum mei_dev_state dev_state;
222 enum mei_init_clients_states init_clients_state; 237 enum mei_init_clients_states init_clients_state;
223 u16 init_clients_timer; 238 u16 init_clients_timer;
224 bool stop;
225 bool need_reset; 239 bool need_reset;
226 240
227 u32 extra_write_index; 241 u32 extra_write_index;
@@ -241,12 +255,11 @@ struct mei_device {
241 bool mei_host_buffer_is_empty; 255 bool mei_host_buffer_is_empty;
242 256
243 struct mei_cl wd_cl; 257 struct mei_cl wd_cl;
258 enum mei_wd_states wd_state;
244 bool wd_interface_reg; 259 bool wd_interface_reg;
245 bool wd_pending; 260 bool wd_pending;
246 bool wd_stopped; 261 u16 wd_timeout;
247 bool wd_bypass; /* if false, don't refresh watchdog ME client */ 262 unsigned char wd_data[MEI_WD_START_MSG_SIZE];
248 u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
249 unsigned char wd_data[MEI_START_WD_DATA_SIZE];
250 263
251 264
252 struct file *iamthif_file_object; 265 struct file *iamthif_file_object;
@@ -279,9 +292,10 @@ void mei_host_init_iamthif(struct mei_device *dev);
279void mei_allocate_me_clients_storage(struct mei_device *dev); 292void mei_allocate_me_clients_storage(struct mei_device *dev);
280 293
281 294
282u8 mei_find_me_client_update_filext(struct mei_device *dev, 295int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
283 struct mei_cl *priv, 296 const uuid_le *cguid, u8 host_client_id);
284 const uuid_le *cguid, u8 client_id); 297int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
298int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
285 299
286/* 300/*
287 * MEI IO List Functions 301 * MEI IO List Functions
@@ -348,7 +362,6 @@ void mei_run_next_iamthif_cmd(struct mei_device *dev);
348 362
349void mei_free_cb_private(struct mei_cl_cb *priv_cb); 363void mei_free_cb_private(struct mei_cl_cb *priv_cb);
350 364
351int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
352 365
353/* 366/*
354 * Register Access Function 367 * Register Access Function
diff --git a/drivers/misc/mei/wd.c b/drivers/misc/mei/wd.c
index 5133fd77b91c..d96c537f046f 100644
--- a/drivers/misc/mei/wd.c
+++ b/drivers/misc/mei/wd.c
@@ -48,8 +48,8 @@ const uuid_le mei_wd_guid = UUID_LE(0x05B79A6F, 0x4628, 0x4D7F, 0x89,
48static void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout) 48static void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout)
49{ 49{
50 dev_dbg(&dev->pdev->dev, "wd: set timeout=%d.\n", timeout); 50 dev_dbg(&dev->pdev->dev, "wd: set timeout=%d.\n", timeout);
51 memcpy(dev->wd_data, mei_start_wd_params, MEI_WD_PARAMS_SIZE); 51 memcpy(dev->wd_data, mei_start_wd_params, MEI_WD_HDR_SIZE);
52 memcpy(dev->wd_data + MEI_WD_PARAMS_SIZE, &timeout, sizeof(u16)); 52 memcpy(dev->wd_data + MEI_WD_HDR_SIZE, &timeout, sizeof(u16));
53} 53}
54 54
55/** 55/**
@@ -66,10 +66,11 @@ int mei_wd_host_init(struct mei_device *dev)
66 66
67 /* look for WD client and connect to it */ 67 /* look for WD client and connect to it */
68 dev->wd_cl.state = MEI_FILE_DISCONNECTED; 68 dev->wd_cl.state = MEI_FILE_DISCONNECTED;
69 dev->wd_timeout = AMT_WD_DEFAULT_TIMEOUT; 69 dev->wd_timeout = MEI_WD_DEFAULT_TIMEOUT;
70 dev->wd_state = MEI_WD_IDLE;
70 71
71 /* find ME WD client */ 72 /* find ME WD client */
72 mei_find_me_client_update_filext(dev, &dev->wd_cl, 73 mei_me_cl_update_filext(dev, &dev->wd_cl,
73 &mei_wd_guid, MEI_WD_HOST_CLIENT_ID); 74 &mei_wd_guid, MEI_WD_HOST_CLIENT_ID);
74 75
75 dev_dbg(&dev->pdev->dev, "wd: check client\n"); 76 dev_dbg(&dev->pdev->dev, "wd: check client\n");
@@ -108,10 +109,10 @@ int mei_wd_send(struct mei_device *dev)
108 mei_hdr->msg_complete = 1; 109 mei_hdr->msg_complete = 1;
109 mei_hdr->reserved = 0; 110 mei_hdr->reserved = 0;
110 111
111 if (!memcmp(dev->wd_data, mei_start_wd_params, MEI_WD_PARAMS_SIZE)) 112 if (!memcmp(dev->wd_data, mei_start_wd_params, MEI_WD_HDR_SIZE))
112 mei_hdr->length = MEI_START_WD_DATA_SIZE; 113 mei_hdr->length = MEI_WD_START_MSG_SIZE;
113 else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_PARAMS_SIZE)) 114 else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_HDR_SIZE))
114 mei_hdr->length = MEI_WD_PARAMS_SIZE; 115 mei_hdr->length = MEI_WD_STOP_MSG_SIZE;
115 else 116 else
116 return -EINVAL; 117 return -EINVAL;
117 118
@@ -128,18 +129,17 @@ int mei_wd_send(struct mei_device *dev)
128 * -EIO when message send fails 129 * -EIO when message send fails
129 * -EINVAL when invalid message is to be sent 130 * -EINVAL when invalid message is to be sent
130 */ 131 */
131int mei_wd_stop(struct mei_device *dev, bool preserve) 132int mei_wd_stop(struct mei_device *dev)
132{ 133{
133 int ret; 134 int ret;
134 u16 wd_timeout = dev->wd_timeout;
135 135
136 cancel_delayed_work(&dev->timer_work); 136 if (dev->wd_cl.state != MEI_FILE_CONNECTED ||
137 if (dev->wd_cl.state != MEI_FILE_CONNECTED || !dev->wd_timeout) 137 dev->wd_state != MEI_WD_RUNNING)
138 return 0; 138 return 0;
139 139
140 dev->wd_timeout = 0; 140 memcpy(dev->wd_data, mei_stop_wd_params, MEI_WD_STOP_MSG_SIZE);
141 memcpy(dev->wd_data, mei_stop_wd_params, MEI_WD_PARAMS_SIZE); 141
142 dev->stop = true; 142 dev->wd_state = MEI_WD_STOPPING;
143 143
144 ret = mei_flow_ctrl_creds(dev, &dev->wd_cl); 144 ret = mei_flow_ctrl_creds(dev, &dev->wd_cl);
145 if (ret < 0) 145 if (ret < 0)
@@ -161,13 +161,14 @@ int mei_wd_stop(struct mei_device *dev, bool preserve)
161 } else { 161 } else {
162 dev->wd_pending = true; 162 dev->wd_pending = true;
163 } 163 }
164 dev->wd_stopped = false; 164
165 mutex_unlock(&dev->device_lock); 165 mutex_unlock(&dev->device_lock);
166 166
167 ret = wait_event_interruptible_timeout(dev->wait_stop_wd, 167 ret = wait_event_interruptible_timeout(dev->wait_stop_wd,
168 dev->wd_stopped, 10 * HZ); 168 dev->wd_state == MEI_WD_IDLE,
169 msecs_to_jiffies(MEI_WD_STOP_TIMEOUT));
169 mutex_lock(&dev->device_lock); 170 mutex_lock(&dev->device_lock);
170 if (dev->wd_stopped) { 171 if (dev->wd_state == MEI_WD_IDLE) {
171 dev_dbg(&dev->pdev->dev, "wd: stop completed ret=%d.\n", ret); 172 dev_dbg(&dev->pdev->dev, "wd: stop completed ret=%d.\n", ret);
172 ret = 0; 173 ret = 0;
173 } else { 174 } else {
@@ -177,9 +178,6 @@ int mei_wd_stop(struct mei_device *dev, bool preserve)
177 "wd: stop failed to complete ret=%d.\n", ret); 178 "wd: stop failed to complete ret=%d.\n", ret);
178 } 179 }
179 180
180 if (preserve)
181 dev->wd_timeout = wd_timeout;
182
183out: 181out:
184 return ret; 182 return ret;
185} 183}
@@ -196,16 +194,16 @@ static int mei_wd_ops_start(struct watchdog_device *wd_dev)
196 int err = -ENODEV; 194 int err = -ENODEV;
197 struct mei_device *dev; 195 struct mei_device *dev;
198 196
199 dev = pci_get_drvdata(mei_device); 197 dev = watchdog_get_drvdata(wd_dev);
200 if (!dev) 198 if (!dev)
201 return -ENODEV; 199 return -ENODEV;
202 200
203 mutex_lock(&dev->device_lock); 201 mutex_lock(&dev->device_lock);
204 202
205 if (dev->mei_state != MEI_ENABLED) { 203 if (dev->dev_state != MEI_DEV_ENABLED) {
206 dev_dbg(&dev->pdev->dev, 204 dev_dbg(&dev->pdev->dev,
207 "wd: mei_state != MEI_ENABLED mei_state = %d\n", 205 "wd: dev_state != MEI_DEV_ENABLED dev_state = %s\n",
208 dev->mei_state); 206 mei_dev_state_str(dev->dev_state));
209 goto end_unlock; 207 goto end_unlock;
210 } 208 }
211 209
@@ -233,13 +231,13 @@ end_unlock:
233static int mei_wd_ops_stop(struct watchdog_device *wd_dev) 231static int mei_wd_ops_stop(struct watchdog_device *wd_dev)
234{ 232{
235 struct mei_device *dev; 233 struct mei_device *dev;
236 dev = pci_get_drvdata(mei_device);
237 234
235 dev = watchdog_get_drvdata(wd_dev);
238 if (!dev) 236 if (!dev)
239 return -ENODEV; 237 return -ENODEV;
240 238
241 mutex_lock(&dev->device_lock); 239 mutex_lock(&dev->device_lock);
242 mei_wd_stop(dev, false); 240 mei_wd_stop(dev);
243 mutex_unlock(&dev->device_lock); 241 mutex_unlock(&dev->device_lock);
244 242
245 return 0; 243 return 0;
@@ -256,8 +254,8 @@ static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
256{ 254{
257 int ret = 0; 255 int ret = 0;
258 struct mei_device *dev; 256 struct mei_device *dev;
259 dev = pci_get_drvdata(mei_device);
260 257
258 dev = watchdog_get_drvdata(wd_dev);
261 if (!dev) 259 if (!dev)
262 return -ENODEV; 260 return -ENODEV;
263 261
@@ -269,6 +267,8 @@ static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
269 goto end; 267 goto end;
270 } 268 }
271 269
270 dev->wd_state = MEI_WD_RUNNING;
271
272 /* Check if we can send the ping to HW*/ 272 /* Check if we can send the ping to HW*/
273 if (dev->mei_host_buffer_is_empty && 273 if (dev->mei_host_buffer_is_empty &&
274 mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) { 274 mei_flow_ctrl_creds(dev, &dev->wd_cl) > 0) {
@@ -309,13 +309,13 @@ end:
309static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev, unsigned int timeout) 309static int mei_wd_ops_set_timeout(struct watchdog_device *wd_dev, unsigned int timeout)
310{ 310{
311 struct mei_device *dev; 311 struct mei_device *dev;
312 dev = pci_get_drvdata(mei_device);
313 312
313 dev = watchdog_get_drvdata(wd_dev);
314 if (!dev) 314 if (!dev)
315 return -ENODEV; 315 return -ENODEV;
316 316
317 /* Check Timeout value */ 317 /* Check Timeout value */
318 if (timeout < AMT_WD_MIN_TIMEOUT || timeout > AMT_WD_MAX_TIMEOUT) 318 if (timeout < MEI_WD_MIN_TIMEOUT || timeout > MEI_WD_MAX_TIMEOUT)
319 return -EINVAL; 319 return -EINVAL;
320 320
321 mutex_lock(&dev->device_lock); 321 mutex_lock(&dev->device_lock);
@@ -341,37 +341,42 @@ static const struct watchdog_ops wd_ops = {
341}; 341};
342static const struct watchdog_info wd_info = { 342static const struct watchdog_info wd_info = {
343 .identity = INTEL_AMT_WATCHDOG_ID, 343 .identity = INTEL_AMT_WATCHDOG_ID,
344 .options = WDIOF_KEEPALIVEPING | WDIOF_ALARMONLY, 344 .options = WDIOF_KEEPALIVEPING |
345 WDIOF_SETTIMEOUT |
346 WDIOF_ALARMONLY,
345}; 347};
346 348
347static struct watchdog_device amt_wd_dev = { 349static struct watchdog_device amt_wd_dev = {
348 .info = &wd_info, 350 .info = &wd_info,
349 .ops = &wd_ops, 351 .ops = &wd_ops,
350 .timeout = AMT_WD_DEFAULT_TIMEOUT, 352 .timeout = MEI_WD_DEFAULT_TIMEOUT,
351 .min_timeout = AMT_WD_MIN_TIMEOUT, 353 .min_timeout = MEI_WD_MIN_TIMEOUT,
352 .max_timeout = AMT_WD_MAX_TIMEOUT, 354 .max_timeout = MEI_WD_MAX_TIMEOUT,
353}; 355};
354 356
355 357
356void mei_watchdog_register(struct mei_device *dev) 358void mei_watchdog_register(struct mei_device *dev)
357{ 359{
358 dev_dbg(&dev->pdev->dev, "dev->wd_timeout =%d.\n", dev->wd_timeout);
359
360 if (watchdog_register_device(&amt_wd_dev)) { 360 if (watchdog_register_device(&amt_wd_dev)) {
361 dev_err(&dev->pdev->dev, 361 dev_err(&dev->pdev->dev,
362 "wd: unable to register watchdog device.\n"); 362 "wd: unable to register watchdog device.\n");
363 dev->wd_interface_reg = false; 363 dev->wd_interface_reg = false;
364 } else { 364 return;
365 dev_dbg(&dev->pdev->dev,
366 "wd: successfully register watchdog interface.\n");
367 dev->wd_interface_reg = true;
368 } 365 }
366
367 dev_dbg(&dev->pdev->dev,
368 "wd: successfully register watchdog interface.\n");
369 dev->wd_interface_reg = true;
370 watchdog_set_drvdata(&amt_wd_dev, dev);
369} 371}
370 372
371void mei_watchdog_unregister(struct mei_device *dev) 373void mei_watchdog_unregister(struct mei_device *dev)
372{ 374{
373 if (dev->wd_interface_reg) 375 if (!dev->wd_interface_reg)
374 watchdog_unregister_device(&amt_wd_dev); 376 return;
377
378 watchdog_set_drvdata(&amt_wd_dev, NULL);
379 watchdog_unregister_device(&amt_wd_dev);
375 dev->wd_interface_reg = false; 380 dev->wd_interface_reg = false;
376} 381}
377 382
diff --git a/drivers/misc/pch_phub.c b/drivers/misc/pch_phub.c
index 9fbcacd703d5..c9f20dae1855 100644
--- a/drivers/misc/pch_phub.c
+++ b/drivers/misc/pch_phub.c
@@ -699,7 +699,7 @@ static int __devinit pch_phub_probe(struct pci_dev *pdev,
699 chip->pch_phub_base_address = pci_iomap(pdev, 1, 0); 699 chip->pch_phub_base_address = pci_iomap(pdev, 1, 0);
700 700
701 701
702 if (chip->pch_phub_base_address == 0) { 702 if (chip->pch_phub_base_address == NULL) {
703 dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__); 703 dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__);
704 ret = -ENOMEM; 704 ret = -ENOMEM;
705 goto err_pci_iomap; 705 goto err_pci_iomap;
@@ -893,18 +893,7 @@ static struct pci_driver pch_phub_driver = {
893 .resume = pch_phub_resume 893 .resume = pch_phub_resume
894}; 894};
895 895
896static int __init pch_phub_pci_init(void) 896module_pci_driver(pch_phub_driver);
897{
898 return pci_register_driver(&pch_phub_driver);
899}
900
901static void __exit pch_phub_pci_exit(void)
902{
903 pci_unregister_driver(&pch_phub_driver);
904}
905
906module_init(pch_phub_pci_init);
907module_exit(pch_phub_pci_exit);
908 897
909MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7223) PHUB"); 898MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7223) PHUB");
910MODULE_LICENSE("GPL"); 899MODULE_LICENSE("GPL");
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index acfaeeb9e01a..46937b107261 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -30,11 +30,13 @@
30 30
31#include <linux/ti_wilink_st.h> 31#include <linux/ti_wilink_st.h>
32 32
33extern void st_kim_recv(void *, const unsigned char *, long);
34void st_int_recv(void *, const unsigned char *, long);
33/* function pointer pointing to either, 35/* function pointer pointing to either,
34 * st_kim_recv during registration to receive fw download responses 36 * st_kim_recv during registration to receive fw download responses
35 * st_int_recv after registration to receive proto stack responses 37 * st_int_recv after registration to receive proto stack responses
36 */ 38 */
37void (*st_recv) (void*, const unsigned char*, long); 39static void (*st_recv) (void *, const unsigned char *, long);
38 40
39/********************************************************************/ 41/********************************************************************/
40static void add_channel_to_table(struct st_data_s *st_gdata, 42static void add_channel_to_table(struct st_data_s *st_gdata,
@@ -100,7 +102,7 @@ int st_int_write(struct st_data_s *st_gdata,
100 * push the skb received to relevant 102 * push the skb received to relevant
101 * protocol stacks 103 * protocol stacks
102 */ 104 */
103void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata) 105static void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata)
104{ 106{
105 pr_debug(" %s(prot:%d) ", __func__, chnl_id); 107 pr_debug(" %s(prot:%d) ", __func__, chnl_id);
106 108
@@ -140,7 +142,7 @@ void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata)
140 * This function is being called with spin lock held, protocol drivers are 142 * This function is being called with spin lock held, protocol drivers are
141 * only expected to complete their waits and do nothing more than that. 143 * only expected to complete their waits and do nothing more than that.
142 */ 144 */
143void st_reg_complete(struct st_data_s *st_gdata, char err) 145static void st_reg_complete(struct st_data_s *st_gdata, char err)
144{ 146{
145 unsigned char i = 0; 147 unsigned char i = 0;
146 pr_info(" %s ", __func__); 148 pr_info(" %s ", __func__);
@@ -379,7 +381,7 @@ done:
379 * completely, return that skb which has the pending data. 381 * completely, return that skb which has the pending data.
380 * In normal cases, return top of txq. 382 * In normal cases, return top of txq.
381 */ 383 */
382struct sk_buff *st_int_dequeue(struct st_data_s *st_gdata) 384static struct sk_buff *st_int_dequeue(struct st_data_s *st_gdata)
383{ 385{
384 struct sk_buff *returning_skb; 386 struct sk_buff *returning_skb;
385 387
@@ -401,7 +403,7 @@ struct sk_buff *st_int_dequeue(struct st_data_s *st_gdata)
401 * txq and waitq needs protection since the other contexts 403 * txq and waitq needs protection since the other contexts
402 * may be sending data, waking up chip. 404 * may be sending data, waking up chip.
403 */ 405 */
404void st_int_enqueue(struct st_data_s *st_gdata, struct sk_buff *skb) 406static void st_int_enqueue(struct st_data_s *st_gdata, struct sk_buff *skb)
405{ 407{
406 unsigned long flags = 0; 408 unsigned long flags = 0;
407 409
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index 7c14f8fd98db..04a819944f6b 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -63,10 +63,27 @@ static struct platform_device *st_get_plat_device(int id)
63 * in case of error don't complete so that waiting for proper 63 * in case of error don't complete so that waiting for proper
64 * response times out 64 * response times out
65 */ 65 */
66void validate_firmware_response(struct kim_data_s *kim_gdata) 66static void validate_firmware_response(struct kim_data_s *kim_gdata)
67{ 67{
68 struct sk_buff *skb = kim_gdata->rx_skb; 68 struct sk_buff *skb = kim_gdata->rx_skb;
69 if (unlikely(skb->data[5] != 0)) { 69 if (!skb)
70 return;
71
72 /* these magic numbers are the position in the response buffer which
73 * allows us to distinguish whether the response is for the read
74 * version info. command
75 */
76 if (skb->data[2] == 0x01 && skb->data[3] == 0x01 &&
77 skb->data[4] == 0x10 && skb->data[5] == 0x00) {
78 /* fw version response */
79 memcpy(kim_gdata->resp_buffer,
80 kim_gdata->rx_skb->data,
81 kim_gdata->rx_skb->len);
82 complete_all(&kim_gdata->kim_rcvd);
83 kim_gdata->rx_state = ST_W4_PACKET_TYPE;
84 kim_gdata->rx_skb = NULL;
85 kim_gdata->rx_count = 0;
86 } else if (unlikely(skb->data[5] != 0)) {
70 pr_err("no proper response during fw download"); 87 pr_err("no proper response during fw download");
71 pr_err("data6 %x", skb->data[5]); 88 pr_err("data6 %x", skb->data[5]);
72 kfree_skb(skb); 89 kfree_skb(skb);
@@ -119,7 +136,7 @@ static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len)
119 * have been observed to come in bursts of different 136 * have been observed to come in bursts of different
120 * tty_receive and hence the logic 137 * tty_receive and hence the logic
121 */ 138 */
122void kim_int_recv(struct kim_data_s *kim_gdata, 139static void kim_int_recv(struct kim_data_s *kim_gdata,
123 const unsigned char *data, long count) 140 const unsigned char *data, long count)
124{ 141{
125 const unsigned char *ptr; 142 const unsigned char *ptr;
@@ -207,16 +224,19 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
207 return -EIO; 224 return -EIO;
208 } 225 }
209 226
210 if (!wait_for_completion_timeout 227 if (!wait_for_completion_interruptible_timeout(
211 (&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) { 228 &kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) {
212 pr_err(" waiting for ver info- timed out "); 229 pr_err(" waiting for ver info- timed out ");
213 return -ETIMEDOUT; 230 return -ETIMEDOUT;
214 } 231 }
215 INIT_COMPLETION(kim_gdata->kim_rcvd); 232 INIT_COMPLETION(kim_gdata->kim_rcvd);
233 /* the positions 12 & 13 in the response buffer provide with the
234 * chip, major & minor numbers
235 */
216 236
217 version = 237 version =
218 MAKEWORD(kim_gdata->resp_buffer[13], 238 MAKEWORD(kim_gdata->resp_buffer[12],
219 kim_gdata->resp_buffer[14]); 239 kim_gdata->resp_buffer[13]);
220 chip = (version & 0x7C00) >> 10; 240 chip = (version & 0x7C00) >> 10;
221 min_ver = (version & 0x007F); 241 min_ver = (version & 0x007F);
222 maj_ver = (version & 0x0380) >> 7; 242 maj_ver = (version & 0x0380) >> 7;
@@ -236,7 +256,7 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
236 return 0; 256 return 0;
237} 257}
238 258
239void skip_change_remote_baud(unsigned char **ptr, long *len) 259static void skip_change_remote_baud(unsigned char **ptr, long *len)
240{ 260{
241 unsigned char *nxt_action, *cur_action; 261 unsigned char *nxt_action, *cur_action;
242 cur_action = *ptr; 262 cur_action = *ptr;
@@ -370,9 +390,9 @@ static long download_firmware(struct kim_data_s *kim_gdata)
370 break; 390 break;
371 case ACTION_WAIT_EVENT: /* wait */ 391 case ACTION_WAIT_EVENT: /* wait */
372 pr_debug("W"); 392 pr_debug("W");
373 if (!wait_for_completion_timeout 393 if (!wait_for_completion_interruptible_timeout(
374 (&kim_gdata->kim_rcvd, 394 &kim_gdata->kim_rcvd,
375 msecs_to_jiffies(CMD_RESP_TIME))) { 395 msecs_to_jiffies(CMD_RESP_TIME))) {
376 pr_err("response timeout during fw download "); 396 pr_err("response timeout during fw download ");
377 /* timed out */ 397 /* timed out */
378 release_firmware(kim_gdata->fw_entry); 398 release_firmware(kim_gdata->fw_entry);
@@ -410,16 +430,10 @@ void st_kim_recv(void *disc_data, const unsigned char *data, long count)
410 struct st_data_s *st_gdata = (struct st_data_s *)disc_data; 430 struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
411 struct kim_data_s *kim_gdata = st_gdata->kim_data; 431 struct kim_data_s *kim_gdata = st_gdata->kim_data;
412 432
413 /* copy to local buffer */ 433 /* proceed to gather all data and distinguish read fw version response
414 if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) { 434 * from other fw responses when data gathering is complete
415 /* must be the read_ver_cmd */ 435 */
416 memcpy(kim_gdata->resp_buffer, data, count); 436 kim_int_recv(kim_gdata, data, count);
417 complete_all(&kim_gdata->kim_rcvd);
418 return;
419 } else {
420 kim_int_recv(kim_gdata, data, count);
421 /* either completes or times out */
422 }
423 return; 437 return;
424} 438}
425 439
@@ -454,11 +468,6 @@ long st_kim_start(void *kim_data)
454 if (pdata->chip_enable) 468 if (pdata->chip_enable)
455 pdata->chip_enable(kim_gdata); 469 pdata->chip_enable(kim_gdata);
456 470
457 /* Configure BT nShutdown to HIGH state */
458 gpio_set_value(kim_gdata->nshutdown, GPIO_LOW);
459 mdelay(5); /* FIXME: a proper toggle */
460 gpio_set_value(kim_gdata->nshutdown, GPIO_HIGH);
461 mdelay(100);
462 /* re-initialize the completion */ 471 /* re-initialize the completion */
463 INIT_COMPLETION(kim_gdata->ldisc_installed); 472 INIT_COMPLETION(kim_gdata->ldisc_installed);
464 /* send notification to UIM */ 473 /* send notification to UIM */
@@ -467,8 +476,8 @@ long st_kim_start(void *kim_data)
467 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, 476 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj,
468 NULL, "install"); 477 NULL, "install");
469 /* wait for ldisc to be installed */ 478 /* wait for ldisc to be installed */
470 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, 479 err = wait_for_completion_interruptible_timeout(
471 msecs_to_jiffies(LDISC_TIME)); 480 &kim_gdata->ldisc_installed, msecs_to_jiffies(LDISC_TIME));
472 if (!err) { 481 if (!err) {
473 /* ldisc installation timeout, 482 /* ldisc installation timeout,
474 * flush uart, power cycle BT_EN */ 483 * flush uart, power cycle BT_EN */
@@ -500,8 +509,7 @@ long st_kim_start(void *kim_data)
500 * (b) upon failure to either install ldisc or download firmware. 509 * (b) upon failure to either install ldisc or download firmware.
501 * The function is responsible to (a) notify UIM about un-installation, 510 * The function is responsible to (a) notify UIM about un-installation,
502 * (b) flush UART if the ldisc was installed. 511 * (b) flush UART if the ldisc was installed.
503 * (c) reset BT_EN - pull down nshutdown at the end. 512 * (c) invoke platform's chip disabling routine.
504 * (d) invoke platform's chip disabling routine.
505 */ 513 */
506long st_kim_stop(void *kim_data) 514long st_kim_stop(void *kim_data)
507{ 515{
@@ -526,20 +534,13 @@ long st_kim_stop(void *kim_data)
526 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, NULL, "install"); 534 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, NULL, "install");
527 535
528 /* wait for ldisc to be un-installed */ 536 /* wait for ldisc to be un-installed */
529 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, 537 err = wait_for_completion_interruptible_timeout(
530 msecs_to_jiffies(LDISC_TIME)); 538 &kim_gdata->ldisc_installed, msecs_to_jiffies(LDISC_TIME));
531 if (!err) { /* timeout */ 539 if (!err) { /* timeout */
532 pr_err(" timed out waiting for ldisc to be un-installed"); 540 pr_err(" timed out waiting for ldisc to be un-installed");
533 return -ETIMEDOUT; 541 err = -ETIMEDOUT;
534 } 542 }
535 543
536 /* By default configure BT nShutdown to LOW state */
537 gpio_set_value(kim_gdata->nshutdown, GPIO_LOW);
538 mdelay(1);
539 gpio_set_value(kim_gdata->nshutdown, GPIO_HIGH);
540 mdelay(1);
541 gpio_set_value(kim_gdata->nshutdown, GPIO_LOW);
542
543 /* platform specific disable */ 544 /* platform specific disable */
544 if (pdata->chip_disable) 545 if (pdata->chip_disable)
545 pdata->chip_disable(kim_gdata); 546 pdata->chip_disable(kim_gdata);
@@ -701,7 +702,7 @@ static const struct file_operations list_debugfs_fops = {
701 * board-*.c file 702 * board-*.c file
702 */ 703 */
703 704
704struct dentry *kim_debugfs_dir; 705static struct dentry *kim_debugfs_dir;
705static int kim_probe(struct platform_device *pdev) 706static int kim_probe(struct platform_device *pdev)
706{ 707{
707 long status; 708 long status;
@@ -731,20 +732,6 @@ static int kim_probe(struct platform_device *pdev)
731 /* refer to itself */ 732 /* refer to itself */
732 kim_gdata->core_data->kim_data = kim_gdata; 733 kim_gdata->core_data->kim_data = kim_gdata;
733 734
734 /* Claim the chip enable nShutdown gpio from the system */
735 kim_gdata->nshutdown = pdata->nshutdown_gpio;
736 status = gpio_request(kim_gdata->nshutdown, "kim");
737 if (unlikely(status)) {
738 pr_err(" gpio %ld request failed ", kim_gdata->nshutdown);
739 return status;
740 }
741
742 /* Configure nShutdown GPIO as output=0 */
743 status = gpio_direction_output(kim_gdata->nshutdown, 0);
744 if (unlikely(status)) {
745 pr_err(" unable to configure gpio %ld", kim_gdata->nshutdown);
746 return status;
747 }
748 /* get reference of pdev for request_firmware 735 /* get reference of pdev for request_firmware
749 */ 736 */
750 kim_gdata->kim_pdev = pdev; 737 kim_gdata->kim_pdev = pdev;
@@ -780,18 +767,10 @@ static int kim_probe(struct platform_device *pdev)
780 767
781static int kim_remove(struct platform_device *pdev) 768static int kim_remove(struct platform_device *pdev)
782{ 769{
783 /* free the GPIOs requested */
784 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
785 struct kim_data_s *kim_gdata; 770 struct kim_data_s *kim_gdata;
786 771
787 kim_gdata = dev_get_drvdata(&pdev->dev); 772 kim_gdata = dev_get_drvdata(&pdev->dev);
788 773
789 /* Free the Bluetooth/FM/GPIO
790 * nShutdown gpio from the system
791 */
792 gpio_free(pdata->nshutdown_gpio);
793 pr_info("nshutdown GPIO Freed");
794
795 debugfs_remove_recursive(kim_debugfs_dir); 774 debugfs_remove_recursive(kim_debugfs_dir);
796 sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp); 775 sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp);
797 pr_info("sysfs entries removed"); 776 pr_info("sysfs entries removed");
@@ -804,7 +783,7 @@ static int kim_remove(struct platform_device *pdev)
804 return 0; 783 return 0;
805} 784}
806 785
807int kim_suspend(struct platform_device *pdev, pm_message_t state) 786static int kim_suspend(struct platform_device *pdev, pm_message_t state)
808{ 787{
809 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 788 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
810 789
@@ -814,7 +793,7 @@ int kim_suspend(struct platform_device *pdev, pm_message_t state)
814 return -EOPNOTSUPP; 793 return -EOPNOTSUPP;
815} 794}
816 795
817int kim_resume(struct platform_device *pdev) 796static int kim_resume(struct platform_device *pdev)
818{ 797{
819 struct ti_st_plat_data *pdata = pdev->dev.platform_data; 798 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
820 799