summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2018-07-23 06:21:23 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-07-24 08:16:57 -0400
commit8c8d964ce90f16877b76c3f00b27165bf865af69 (patch)
treef78cebf528642d8f2875a6b00f2c5465efc3f93c
parent9fc5f0f8ad28405145b30fd3b905e368063ee14c (diff)
mei: move hbuf_depth from the mei device to the hw modules
The host buffer depth is hardware specific so it's better to handle it inside the me and txe hw modules. In me the depth is read from register in txe it's a constant number. The value is now retrieved via mei_hbuf_depth accessor, while it replaces mei_hbuf_max_len. Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/misc/mei/client.c53
-rw-r--r--drivers/misc/mei/hw-me.c19
-rw-r--r--drivers/misc/mei/hw-me.h2
-rw-r--r--drivers/misc/mei/hw-txe.c22
-rw-r--r--drivers/misc/mei/mei_dev.h11
5 files changed, 58 insertions, 49 deletions
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 79e200d71652..ca917b84ca5e 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -1556,8 +1556,8 @@ int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
1556 struct mei_msg_data *buf; 1556 struct mei_msg_data *buf;
1557 struct mei_msg_hdr mei_hdr; 1557 struct mei_msg_hdr mei_hdr;
1558 size_t len; 1558 size_t len;
1559 u32 msg_slots; 1559 size_t hbuf_len;
1560 int slots; 1560 int hbuf_slots;
1561 int rets; 1561 int rets;
1562 bool first_chunk; 1562 bool first_chunk;
1563 1563
@@ -1579,29 +1579,30 @@ int mei_cl_irq_write(struct mei_cl *cl, struct mei_cl_cb *cb,
1579 return 0; 1579 return 0;
1580 } 1580 }
1581 1581
1582 slots = mei_hbuf_empty_slots(dev);
1583 if (slots < 0)
1584 return -EOVERFLOW;
1585
1586 len = buf->size - cb->buf_idx;
1587 msg_slots = mei_data2slots(len);
1588
1589 mei_hdr.host_addr = mei_cl_host_addr(cl); 1582 mei_hdr.host_addr = mei_cl_host_addr(cl);
1590 mei_hdr.me_addr = mei_cl_me_id(cl); 1583 mei_hdr.me_addr = mei_cl_me_id(cl);
1591 mei_hdr.reserved = 0; 1584 mei_hdr.reserved = 0;
1585 mei_hdr.msg_complete = 0;
1592 mei_hdr.internal = cb->internal; 1586 mei_hdr.internal = cb->internal;
1593 1587
1594 if ((u32)slots >= msg_slots) { 1588 len = buf->size - cb->buf_idx;
1589 hbuf_slots = mei_hbuf_empty_slots(dev);
1590 if (hbuf_slots < 0) {
1591 rets = -EOVERFLOW;
1592 goto err;
1593 }
1594 hbuf_len = mei_slots2data(hbuf_slots) - sizeof(struct mei_msg_hdr);
1595
1596 /**
1597 * Split the message only if we can write the whole host buffer
1598 * otherwise wait for next time the host buffer is empty.
1599 */
1600 if (hbuf_len >= len) {
1595 mei_hdr.length = len; 1601 mei_hdr.length = len;
1596 mei_hdr.msg_complete = 1; 1602 mei_hdr.msg_complete = 1;
1597 /* Split the message only if we can write the whole host buffer */ 1603 } else if ((u32)hbuf_slots == mei_hbuf_depth(dev)) {
1598 } else if ((u32)slots == dev->hbuf_depth) { 1604 mei_hdr.length = hbuf_len;
1599 msg_slots = slots;
1600 len = mei_slots2data(slots) - sizeof(struct mei_msg_hdr);
1601 mei_hdr.length = len;
1602 mei_hdr.msg_complete = 0;
1603 } else { 1605 } else {
1604 /* wait for next time the host buffer is empty */
1605 return 0; 1606 return 0;
1606 } 1607 }
1607 1608
@@ -1650,6 +1651,8 @@ ssize_t mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb)
1650 struct mei_msg_data *buf; 1651 struct mei_msg_data *buf;
1651 struct mei_msg_hdr mei_hdr; 1652 struct mei_msg_hdr mei_hdr;
1652 size_t len; 1653 size_t len;
1654 size_t hbuf_len;
1655 int hbuf_slots;
1653 ssize_t rets; 1656 ssize_t rets;
1654 bool blocking; 1657 bool blocking;
1655 1658
@@ -1692,19 +1695,25 @@ ssize_t mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb)
1692 rets = len; 1695 rets = len;
1693 goto out; 1696 goto out;
1694 } 1697 }
1698
1695 if (!mei_hbuf_acquire(dev)) { 1699 if (!mei_hbuf_acquire(dev)) {
1696 cl_dbg(dev, cl, "Cannot acquire the host buffer: not sending.\n"); 1700 cl_dbg(dev, cl, "Cannot acquire the host buffer: not sending.\n");
1697 rets = len; 1701 rets = len;
1698 goto out; 1702 goto out;
1699 } 1703 }
1700 1704
1701 /* Check for a maximum length */ 1705 hbuf_slots = mei_hbuf_empty_slots(dev);
1702 if (len > mei_hbuf_max_len(dev)) { 1706 if (hbuf_slots < 0) {
1703 mei_hdr.length = mei_hbuf_max_len(dev); 1707 rets = -EOVERFLOW;
1704 mei_hdr.msg_complete = 0; 1708 goto out;
1705 } else { 1709 }
1710
1711 hbuf_len = mei_slots2data(hbuf_slots) - sizeof(struct mei_msg_hdr);
1712 if (hbuf_len >= len) {
1706 mei_hdr.length = len; 1713 mei_hdr.length = len;
1707 mei_hdr.msg_complete = 1; 1714 mei_hdr.msg_complete = 1;
1715 } else {
1716 mei_hdr.length = hbuf_len;
1708 } 1717 }
1709 1718
1710 rets = mei_write_message(dev, &mei_hdr, buf->data); 1719 rets = mei_write_message(dev, &mei_hdr, buf->data);
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index 016b7c956f18..c50671cf47eb 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -228,7 +228,7 @@ static void mei_me_hw_config(struct mei_device *dev)
228 228
229 /* Doesn't change in runtime */ 229 /* Doesn't change in runtime */
230 hcsr = mei_hcsr_read(dev); 230 hcsr = mei_hcsr_read(dev);
231 dev->hbuf_depth = (hcsr & H_CBD) >> 24; 231 hw->hbuf_depth = (hcsr & H_CBD) >> 24;
232 232
233 reg = 0; 233 reg = 0;
234 pci_read_config_dword(pdev, PCI_CFG_HFS_1, &reg); 234 pci_read_config_dword(pdev, PCI_CFG_HFS_1, &reg);
@@ -490,28 +490,31 @@ static bool mei_me_hbuf_is_empty(struct mei_device *dev)
490 */ 490 */
491static int mei_me_hbuf_empty_slots(struct mei_device *dev) 491static int mei_me_hbuf_empty_slots(struct mei_device *dev)
492{ 492{
493 struct mei_me_hw *hw = to_me_hw(dev);
493 unsigned char filled_slots, empty_slots; 494 unsigned char filled_slots, empty_slots;
494 495
495 filled_slots = mei_hbuf_filled_slots(dev); 496 filled_slots = mei_hbuf_filled_slots(dev);
496 empty_slots = dev->hbuf_depth - filled_slots; 497 empty_slots = hw->hbuf_depth - filled_slots;
497 498
498 /* check for overflow */ 499 /* check for overflow */
499 if (filled_slots > dev->hbuf_depth) 500 if (filled_slots > hw->hbuf_depth)
500 return -EOVERFLOW; 501 return -EOVERFLOW;
501 502
502 return empty_slots; 503 return empty_slots;
503} 504}
504 505
505/** 506/**
506 * mei_me_hbuf_max_len - returns size of hw buffer. 507 * mei_me_hbuf_depth - returns depth of the hw buffer.
507 * 508 *
508 * @dev: the device structure 509 * @dev: the device structure
509 * 510 *
510 * Return: size of hw buffer in bytes 511 * Return: size of hw buffer in slots
511 */ 512 */
512static size_t mei_me_hbuf_max_len(const struct mei_device *dev) 513static u32 mei_me_hbuf_depth(const struct mei_device *dev)
513{ 514{
514 return mei_slots2data(dev->hbuf_depth) - sizeof(struct mei_msg_hdr); 515 struct mei_me_hw *hw = to_me_hw(dev);
516
517 return hw->hbuf_depth;
515} 518}
516 519
517 520
@@ -1317,7 +1320,7 @@ static const struct mei_hw_ops mei_me_hw_ops = {
1317 1320
1318 .hbuf_free_slots = mei_me_hbuf_empty_slots, 1321 .hbuf_free_slots = mei_me_hbuf_empty_slots,
1319 .hbuf_is_ready = mei_me_hbuf_is_empty, 1322 .hbuf_is_ready = mei_me_hbuf_is_empty,
1320 .hbuf_max_len = mei_me_hbuf_max_len, 1323 .hbuf_depth = mei_me_hbuf_depth,
1321 1324
1322 .write = mei_me_hbuf_write, 1325 .write = mei_me_hbuf_write,
1323 1326
diff --git a/drivers/misc/mei/hw-me.h b/drivers/misc/mei/hw-me.h
index 67892533576e..0c6fe71d1212 100644
--- a/drivers/misc/mei/hw-me.h
+++ b/drivers/misc/mei/hw-me.h
@@ -52,12 +52,14 @@ struct mei_cfg {
52 * @mem_addr: io memory address 52 * @mem_addr: io memory address
53 * @pg_state: power gating state 53 * @pg_state: power gating state
54 * @d0i3_supported: di03 support 54 * @d0i3_supported: di03 support
55 * @hbuf_depth: depth of hardware host/write buffer in slots
55 */ 56 */
56struct mei_me_hw { 57struct mei_me_hw {
57 const struct mei_cfg *cfg; 58 const struct mei_cfg *cfg;
58 void __iomem *mem_addr; 59 void __iomem *mem_addr;
59 enum mei_pg_state pg_state; 60 enum mei_pg_state pg_state;
60 bool d0i3_supported; 61 bool d0i3_supported;
62 u8 hbuf_depth;
61}; 63};
62 64
63#define to_me_hw(dev) (struct mei_me_hw *)((dev)->hw) 65#define to_me_hw(dev) (struct mei_me_hw *)((dev)->hw)
diff --git a/drivers/misc/mei/hw-txe.c b/drivers/misc/mei/hw-txe.c
index 0facd823634e..7e2026894e9f 100644
--- a/drivers/misc/mei/hw-txe.c
+++ b/drivers/misc/mei/hw-txe.c
@@ -31,6 +31,7 @@
31 31
32#include "mei-trace.h" 32#include "mei-trace.h"
33 33
34#define TXE_HBUF_DEPTH (PAYLOAD_SIZE / MEI_SLOT_SIZE)
34 35
35/** 36/**
36 * mei_txe_reg_read - Reads 32bit data from the txe device 37 * mei_txe_reg_read - Reads 32bit data from the txe device
@@ -681,9 +682,6 @@ static void mei_txe_hw_config(struct mei_device *dev)
681 682
682 struct mei_txe_hw *hw = to_txe_hw(dev); 683 struct mei_txe_hw *hw = to_txe_hw(dev);
683 684
684 /* Doesn't change in runtime */
685 dev->hbuf_depth = PAYLOAD_SIZE / MEI_SLOT_SIZE;
686
687 hw->aliveness = mei_txe_aliveness_get(dev); 685 hw->aliveness = mei_txe_aliveness_get(dev);
688 hw->readiness = mei_txe_readiness_get(dev); 686 hw->readiness = mei_txe_readiness_get(dev);
689 687
@@ -710,7 +708,7 @@ static int mei_txe_write(struct mei_device *dev,
710 unsigned long rem; 708 unsigned long rem;
711 unsigned long length; 709 unsigned long length;
712 unsigned long i; 710 unsigned long i;
713 u32 slots = dev->hbuf_depth; 711 u32 slots = TXE_HBUF_DEPTH;
714 u32 *reg_buf = (u32 *)buf; 712 u32 *reg_buf = (u32 *)buf;
715 u32 dw_cnt; 713 u32 dw_cnt;
716 714
@@ -762,15 +760,15 @@ static int mei_txe_write(struct mei_device *dev,
762} 760}
763 761
764/** 762/**
765 * mei_txe_hbuf_max_len - mimics the me hbuf circular buffer 763 * mei_txe_hbuf_depth - mimics the me hbuf circular buffer
766 * 764 *
767 * @dev: the device structure 765 * @dev: the device structure
768 * 766 *
769 * Return: the PAYLOAD_SIZE - header size 767 * Return: the TXE_HBUF_DEPTH
770 */ 768 */
771static size_t mei_txe_hbuf_max_len(const struct mei_device *dev) 769static u32 mei_txe_hbuf_depth(const struct mei_device *dev)
772{ 770{
773 return PAYLOAD_SIZE - sizeof(struct mei_msg_hdr); 771 return TXE_HBUF_DEPTH;
774} 772}
775 773
776/** 774/**
@@ -778,7 +776,7 @@ static size_t mei_txe_hbuf_max_len(const struct mei_device *dev)
778 * 776 *
779 * @dev: the device structure 777 * @dev: the device structure
780 * 778 *
781 * Return: always hbuf_depth 779 * Return: always TXE_HBUF_DEPTH
782 */ 780 */
783static int mei_txe_hbuf_empty_slots(struct mei_device *dev) 781static int mei_txe_hbuf_empty_slots(struct mei_device *dev)
784{ 782{
@@ -797,7 +795,7 @@ static int mei_txe_hbuf_empty_slots(struct mei_device *dev)
797static int mei_txe_count_full_read_slots(struct mei_device *dev) 795static int mei_txe_count_full_read_slots(struct mei_device *dev)
798{ 796{
799 /* read buffers has static size */ 797 /* read buffers has static size */
800 return PAYLOAD_SIZE / MEI_SLOT_SIZE; 798 return TXE_HBUF_DEPTH;
801} 799}
802 800
803/** 801/**
@@ -1140,7 +1138,7 @@ irqreturn_t mei_txe_irq_thread_handler(int irq, void *dev_id)
1140 /* Input Ready: Detection if host can write to SeC */ 1138 /* Input Ready: Detection if host can write to SeC */
1141 if (test_and_clear_bit(TXE_INTR_IN_READY_BIT, &hw->intr_cause)) { 1139 if (test_and_clear_bit(TXE_INTR_IN_READY_BIT, &hw->intr_cause)) {
1142 dev->hbuf_is_ready = true; 1140 dev->hbuf_is_ready = true;
1143 hw->slots = dev->hbuf_depth; 1141 hw->slots = TXE_HBUF_DEPTH;
1144 } 1142 }
1145 1143
1146 if (hw->aliveness && dev->hbuf_is_ready) { 1144 if (hw->aliveness && dev->hbuf_is_ready) {
@@ -1186,7 +1184,7 @@ static const struct mei_hw_ops mei_txe_hw_ops = {
1186 1184
1187 .hbuf_free_slots = mei_txe_hbuf_empty_slots, 1185 .hbuf_free_slots = mei_txe_hbuf_empty_slots,
1188 .hbuf_is_ready = mei_txe_is_input_ready, 1186 .hbuf_is_ready = mei_txe_is_input_ready,
1189 .hbuf_max_len = mei_txe_hbuf_max_len, 1187 .hbuf_depth = mei_txe_hbuf_depth,
1190 1188
1191 .write = mei_txe_write, 1189 .write = mei_txe_write,
1192 1190
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index 897126dca5d0..fa543dcfc111 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -29,7 +29,6 @@
29#define MEI_SLOT_SIZE sizeof(u32) 29#define MEI_SLOT_SIZE sizeof(u32)
30#define MEI_RD_MSG_BUF_SIZE (128 * MEI_SLOT_SIZE) 30#define MEI_RD_MSG_BUF_SIZE (128 * MEI_SLOT_SIZE)
31 31
32
33/* 32/*
34 * Number of Maximum MEI Clients 33 * Number of Maximum MEI Clients
35 */ 34 */
@@ -271,7 +270,7 @@ struct mei_cl {
271 * 270 *
272 * @hbuf_free_slots : query for write buffer empty slots 271 * @hbuf_free_slots : query for write buffer empty slots
273 * @hbuf_is_ready : query if write buffer is empty 272 * @hbuf_is_ready : query if write buffer is empty
274 * @hbuf_max_len : query for write buffer max len 273 * @hbuf_depth : query for write buffer depth
275 * 274 *
276 * @write : write a message to FW 275 * @write : write a message to FW
277 * 276 *
@@ -301,7 +300,7 @@ struct mei_hw_ops {
301 300
302 int (*hbuf_free_slots)(struct mei_device *dev); 301 int (*hbuf_free_slots)(struct mei_device *dev);
303 bool (*hbuf_is_ready)(struct mei_device *dev); 302 bool (*hbuf_is_ready)(struct mei_device *dev);
304 size_t (*hbuf_max_len)(const struct mei_device *dev); 303 u32 (*hbuf_depth)(const struct mei_device *dev);
305 int (*write)(struct mei_device *dev, 304 int (*write)(struct mei_device *dev,
306 struct mei_msg_hdr *hdr, 305 struct mei_msg_hdr *hdr,
307 const unsigned char *buf); 306 const unsigned char *buf);
@@ -411,7 +410,6 @@ struct mei_fw_version {
411 * @rd_msg_buf : control messages buffer 410 * @rd_msg_buf : control messages buffer
412 * @rd_msg_hdr : read message header storage 411 * @rd_msg_hdr : read message header storage
413 * 412 *
414 * @hbuf_depth : depth of hardware host/write buffer is slots
415 * @hbuf_is_ready : query if the host host/write buffer is ready 413 * @hbuf_is_ready : query if the host host/write buffer is ready
416 * 414 *
417 * @version : HBM protocol version in use 415 * @version : HBM protocol version in use
@@ -489,7 +487,6 @@ struct mei_device {
489 u32 rd_msg_hdr; 487 u32 rd_msg_hdr;
490 488
491 /* write buffer */ 489 /* write buffer */
492 u8 hbuf_depth;
493 bool hbuf_is_ready; 490 bool hbuf_is_ready;
494 491
495 struct hbm_version version; 492 struct hbm_version version;
@@ -655,9 +652,9 @@ static inline int mei_hbuf_empty_slots(struct mei_device *dev)
655 return dev->ops->hbuf_free_slots(dev); 652 return dev->ops->hbuf_free_slots(dev);
656} 653}
657 654
658static inline size_t mei_hbuf_max_len(const struct mei_device *dev) 655static inline u32 mei_hbuf_depth(const struct mei_device *dev)
659{ 656{
660 return dev->ops->hbuf_max_len(dev); 657 return dev->ops->hbuf_depth(dev);
661} 658}
662 659
663static inline int mei_write_message(struct mei_device *dev, 660static inline int mei_write_message(struct mei_device *dev,