12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253 |
- #include <linux/pci.h>
- #include <linux/jiffies.h>
- #include <linux/ktime.h>
- #include <linux/delay.h>
- #include <linux/kthread.h>
- #include <linux/irqreturn.h>
- #include <linux/pm_runtime.h>
- #include <linux/mei.h>
- #include "mei_dev.h"
- #include "hw-txe.h"
- #include "client.h"
- #include "hbm.h"
- #include "mei-trace.h"
- static inline u32 mei_txe_reg_read(void __iomem *base_addr,
- unsigned long offset)
- {
- return ioread32(base_addr + offset);
- }
- static inline void mei_txe_reg_write(void __iomem *base_addr,
- unsigned long offset, u32 value)
- {
- iowrite32(value, base_addr + offset);
- }
- static inline u32 mei_txe_sec_reg_read_silent(struct mei_txe_hw *hw,
- unsigned long offset)
- {
- return mei_txe_reg_read(hw->mem_addr[SEC_BAR], offset);
- }
- static inline u32 mei_txe_sec_reg_read(struct mei_txe_hw *hw,
- unsigned long offset)
- {
- WARN(!hw->aliveness, "sec read: aliveness not asserted\n");
- return mei_txe_sec_reg_read_silent(hw, offset);
- }
- static inline void mei_txe_sec_reg_write_silent(struct mei_txe_hw *hw,
- unsigned long offset, u32 value)
- {
- mei_txe_reg_write(hw->mem_addr[SEC_BAR], offset, value);
- }
- static inline void mei_txe_sec_reg_write(struct mei_txe_hw *hw,
- unsigned long offset, u32 value)
- {
- WARN(!hw->aliveness, "sec write: aliveness not asserted\n");
- mei_txe_sec_reg_write_silent(hw, offset, value);
- }
- static inline u32 mei_txe_br_reg_read(struct mei_txe_hw *hw,
- unsigned long offset)
- {
- return mei_txe_reg_read(hw->mem_addr[BRIDGE_BAR], offset);
- }
- static inline void mei_txe_br_reg_write(struct mei_txe_hw *hw,
- unsigned long offset, u32 value)
- {
- mei_txe_reg_write(hw->mem_addr[BRIDGE_BAR], offset, value);
- }
- static bool mei_txe_aliveness_set(struct mei_device *dev, u32 req)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- bool do_req = hw->aliveness != req;
- dev_dbg(dev->dev, "Aliveness current=%d request=%d\n",
- hw->aliveness, req);
- if (do_req) {
- dev->pg_event = MEI_PG_EVENT_WAIT;
- mei_txe_br_reg_write(hw, SICR_HOST_ALIVENESS_REQ_REG, req);
- }
- return do_req;
- }
- static u32 mei_txe_aliveness_req_get(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- u32 reg;
- reg = mei_txe_br_reg_read(hw, SICR_HOST_ALIVENESS_REQ_REG);
- return reg & SICR_HOST_ALIVENESS_REQ_REQUESTED;
- }
- static u32 mei_txe_aliveness_get(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- u32 reg;
- reg = mei_txe_br_reg_read(hw, HICR_HOST_ALIVENESS_RESP_REG);
- return reg & HICR_HOST_ALIVENESS_RESP_ACK;
- }
- static int mei_txe_aliveness_poll(struct mei_device *dev, u32 expected)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- ktime_t stop, start;
- start = ktime_get();
- stop = ktime_add(start, ms_to_ktime(SEC_ALIVENESS_WAIT_TIMEOUT));
- do {
- hw->aliveness = mei_txe_aliveness_get(dev);
- if (hw->aliveness == expected) {
- dev->pg_event = MEI_PG_EVENT_IDLE;
- dev_dbg(dev->dev, "aliveness settled after %lld usecs\n",
- ktime_to_us(ktime_sub(ktime_get(), start)));
- return 0;
- }
- usleep_range(20, 50);
- } while (ktime_before(ktime_get(), stop));
- dev->pg_event = MEI_PG_EVENT_IDLE;
- dev_err(dev->dev, "aliveness timed out\n");
- return -ETIME;
- }
- static int mei_txe_aliveness_wait(struct mei_device *dev, u32 expected)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- const unsigned long timeout =
- msecs_to_jiffies(SEC_ALIVENESS_WAIT_TIMEOUT);
- long err;
- int ret;
- hw->aliveness = mei_txe_aliveness_get(dev);
- if (hw->aliveness == expected)
- return 0;
- mutex_unlock(&dev->device_lock);
- err = wait_event_timeout(hw->wait_aliveness_resp,
- dev->pg_event == MEI_PG_EVENT_RECEIVED, timeout);
- mutex_lock(&dev->device_lock);
- hw->aliveness = mei_txe_aliveness_get(dev);
- ret = hw->aliveness == expected ? 0 : -ETIME;
- if (ret)
- dev_warn(dev->dev, "aliveness timed out = %ld aliveness = %d event = %d\n",
- err, hw->aliveness, dev->pg_event);
- else
- dev_dbg(dev->dev, "aliveness settled after = %d msec aliveness = %d event = %d\n",
- jiffies_to_msecs(timeout - err),
- hw->aliveness, dev->pg_event);
- dev->pg_event = MEI_PG_EVENT_IDLE;
- return ret;
- }
- int mei_txe_aliveness_set_sync(struct mei_device *dev, u32 req)
- {
- if (mei_txe_aliveness_set(dev, req))
- return mei_txe_aliveness_wait(dev, req);
- return 0;
- }
- static bool mei_txe_pg_in_transition(struct mei_device *dev)
- {
- return dev->pg_event == MEI_PG_EVENT_WAIT;
- }
- static bool mei_txe_pg_is_enabled(struct mei_device *dev)
- {
- return true;
- }
- static inline enum mei_pg_state mei_txe_pg_state(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- return hw->aliveness ? MEI_PG_OFF : MEI_PG_ON;
- }
- static void mei_txe_input_ready_interrupt_enable(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- u32 hintmsk;
-
- hintmsk = mei_txe_sec_reg_read(hw, SEC_IPC_HOST_INT_MASK_REG);
- hintmsk |= SEC_IPC_HOST_INT_MASK_IN_RDY;
- mei_txe_sec_reg_write(hw, SEC_IPC_HOST_INT_MASK_REG, hintmsk);
- }
- static void mei_txe_input_doorbell_set(struct mei_txe_hw *hw)
- {
-
- clear_bit(TXE_INTR_IN_READY_BIT, &hw->intr_cause);
- mei_txe_sec_reg_write(hw, SEC_IPC_INPUT_DOORBELL_REG, 1);
- }
- static void mei_txe_output_ready_set(struct mei_txe_hw *hw)
- {
- mei_txe_br_reg_write(hw,
- SICR_SEC_IPC_OUTPUT_STATUS_REG,
- SEC_IPC_OUTPUT_STATUS_RDY);
- }
- static bool mei_txe_is_input_ready(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- u32 status;
- status = mei_txe_sec_reg_read(hw, SEC_IPC_INPUT_STATUS_REG);
- return !!(SEC_IPC_INPUT_STATUS_RDY & status);
- }
- static inline void mei_txe_intr_clear(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- mei_txe_sec_reg_write_silent(hw, SEC_IPC_HOST_INT_STATUS_REG,
- SEC_IPC_HOST_INT_STATUS_PENDING);
- mei_txe_br_reg_write(hw, HISR_REG, HISR_INT_STS_MSK);
- mei_txe_br_reg_write(hw, HHISR_REG, IPC_HHIER_MSK);
- }
- static void mei_txe_intr_disable(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- mei_txe_br_reg_write(hw, HHIER_REG, 0);
- mei_txe_br_reg_write(hw, HIER_REG, 0);
- }
- static void mei_txe_intr_enable(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- mei_txe_br_reg_write(hw, HHIER_REG, IPC_HHIER_MSK);
- mei_txe_br_reg_write(hw, HIER_REG, HIER_INT_EN_MSK);
- }
- static bool mei_txe_pending_interrupts(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- bool ret = (hw->intr_cause & (TXE_INTR_READINESS |
- TXE_INTR_ALIVENESS |
- TXE_INTR_IN_READY |
- TXE_INTR_OUT_DB));
- if (ret) {
- dev_dbg(dev->dev,
- "Pending Interrupts InReady=%01d Readiness=%01d, Aliveness=%01d, OutDoor=%01d\n",
- !!(hw->intr_cause & TXE_INTR_IN_READY),
- !!(hw->intr_cause & TXE_INTR_READINESS),
- !!(hw->intr_cause & TXE_INTR_ALIVENESS),
- !!(hw->intr_cause & TXE_INTR_OUT_DB));
- }
- return ret;
- }
- static void mei_txe_input_payload_write(struct mei_device *dev,
- unsigned long idx, u32 value)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- mei_txe_sec_reg_write(hw, SEC_IPC_INPUT_PAYLOAD_REG +
- (idx * sizeof(u32)), value);
- }
- static u32 mei_txe_out_data_read(const struct mei_device *dev,
- unsigned long idx)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- return mei_txe_br_reg_read(hw,
- BRIDGE_IPC_OUTPUT_PAYLOAD_REG + (idx * sizeof(u32)));
- }
- static void mei_txe_readiness_set_host_rdy(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- mei_txe_br_reg_write(hw,
- SICR_HOST_IPC_READINESS_REQ_REG,
- SICR_HOST_IPC_READINESS_HOST_RDY);
- }
- static void mei_txe_readiness_clear(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- mei_txe_br_reg_write(hw, SICR_HOST_IPC_READINESS_REQ_REG,
- SICR_HOST_IPC_READINESS_RDY_CLR);
- }
- static u32 mei_txe_readiness_get(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- return mei_txe_br_reg_read(hw, HICR_SEC_IPC_READINESS_REG);
- }
- static inline bool mei_txe_readiness_is_sec_rdy(u32 readiness)
- {
- return !!(readiness & HICR_SEC_IPC_READINESS_SEC_RDY);
- }
- static bool mei_txe_hw_is_ready(struct mei_device *dev)
- {
- u32 readiness = mei_txe_readiness_get(dev);
- return mei_txe_readiness_is_sec_rdy(readiness);
- }
- static inline bool mei_txe_host_is_ready(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- u32 reg = mei_txe_br_reg_read(hw, HICR_SEC_IPC_READINESS_REG);
- return !!(reg & HICR_SEC_IPC_READINESS_HOST_RDY);
- }
- static int mei_txe_readiness_wait(struct mei_device *dev)
- {
- if (mei_txe_hw_is_ready(dev))
- return 0;
- mutex_unlock(&dev->device_lock);
- wait_event_timeout(dev->wait_hw_ready, dev->recvd_hw_ready,
- msecs_to_jiffies(SEC_RESET_WAIT_TIMEOUT));
- mutex_lock(&dev->device_lock);
- if (!dev->recvd_hw_ready) {
- dev_err(dev->dev, "wait for readiness failed\n");
- return -ETIME;
- }
- dev->recvd_hw_ready = false;
- return 0;
- }
- static const struct mei_fw_status mei_txe_fw_sts = {
- .count = 2,
- .status[0] = PCI_CFG_TXE_FW_STS0,
- .status[1] = PCI_CFG_TXE_FW_STS1
- };
- static int mei_txe_fw_status(struct mei_device *dev,
- struct mei_fw_status *fw_status)
- {
- const struct mei_fw_status *fw_src = &mei_txe_fw_sts;
- struct pci_dev *pdev = to_pci_dev(dev->dev);
- int ret;
- int i;
- if (!fw_status)
- return -EINVAL;
- fw_status->count = fw_src->count;
- for (i = 0; i < fw_src->count && i < MEI_FW_STATUS_MAX; i++) {
- ret = pci_read_config_dword(pdev, fw_src->status[i],
- &fw_status->status[i]);
- trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HSF_X",
- fw_src->status[i],
- fw_status->status[i]);
- if (ret)
- return ret;
- }
- return 0;
- }
- static void mei_txe_hw_config(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
-
- dev->hbuf_depth = PAYLOAD_SIZE / 4;
- hw->aliveness = mei_txe_aliveness_get(dev);
- hw->readiness = mei_txe_readiness_get(dev);
- dev_dbg(dev->dev, "aliveness_resp = 0x%08x, readiness = 0x%08x.\n",
- hw->aliveness, hw->readiness);
- }
- static int mei_txe_write(struct mei_device *dev,
- struct mei_msg_hdr *header, unsigned char *buf)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- unsigned long rem;
- unsigned long length;
- int slots = dev->hbuf_depth;
- u32 *reg_buf = (u32 *)buf;
- u32 dw_cnt;
- int i;
- if (WARN_ON(!header || !buf))
- return -EINVAL;
- length = header->length;
- dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(header));
- dw_cnt = mei_data2slots(length);
- if (dw_cnt > slots)
- return -EMSGSIZE;
- if (WARN(!hw->aliveness, "txe write: aliveness not asserted\n"))
- return -EAGAIN;
-
- mei_txe_input_ready_interrupt_enable(dev);
- if (!mei_txe_is_input_ready(dev)) {
- char fw_sts_str[MEI_FW_STATUS_STR_SZ];
- mei_fw_status_str(dev, fw_sts_str, MEI_FW_STATUS_STR_SZ);
- dev_err(dev->dev, "Input is not ready %s\n", fw_sts_str);
- return -EAGAIN;
- }
- mei_txe_input_payload_write(dev, 0, *((u32 *)header));
- for (i = 0; i < length / 4; i++)
- mei_txe_input_payload_write(dev, i + 1, reg_buf[i]);
- rem = length & 0x3;
- if (rem > 0) {
- u32 reg = 0;
- memcpy(®, &buf[length - rem], rem);
- mei_txe_input_payload_write(dev, i + 1, reg);
- }
-
- hw->slots = 0;
-
- mei_txe_input_doorbell_set(hw);
- return 0;
- }
- static size_t mei_txe_hbuf_max_len(const struct mei_device *dev)
- {
- return PAYLOAD_SIZE - sizeof(struct mei_msg_hdr);
- }
- static int mei_txe_hbuf_empty_slots(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- return hw->slots;
- }
- static int mei_txe_count_full_read_slots(struct mei_device *dev)
- {
-
- return PAYLOAD_SIZE / 4;
- }
- static u32 mei_txe_read_hdr(const struct mei_device *dev)
- {
- return mei_txe_out_data_read(dev, 0);
- }
- static int mei_txe_read(struct mei_device *dev,
- unsigned char *buf, unsigned long len)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- u32 *reg_buf, reg;
- u32 rem;
- u32 i;
- if (WARN_ON(!buf || !len))
- return -EINVAL;
- reg_buf = (u32 *)buf;
- rem = len & 0x3;
- dev_dbg(dev->dev, "buffer-length = %lu buf[0]0x%08X\n",
- len, mei_txe_out_data_read(dev, 0));
- for (i = 0; i < len / 4; i++) {
-
- reg = mei_txe_out_data_read(dev, i + 1);
- dev_dbg(dev->dev, "buf[%d] = 0x%08X\n", i, reg);
- *reg_buf++ = reg;
- }
- if (rem) {
- reg = mei_txe_out_data_read(dev, i + 1);
- memcpy(reg_buf, ®, rem);
- }
- mei_txe_output_ready_set(hw);
- return 0;
- }
- static int mei_txe_hw_reset(struct mei_device *dev, bool intr_enable)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- u32 aliveness_req;
-
- (void)mei_txe_sec_reg_read_silent(hw, SEC_IPC_INPUT_DOORBELL_REG);
- aliveness_req = mei_txe_aliveness_req_get(dev);
- hw->aliveness = mei_txe_aliveness_get(dev);
-
- mei_txe_intr_disable(dev);
-
- if (aliveness_req != hw->aliveness)
- if (mei_txe_aliveness_poll(dev, aliveness_req) < 0) {
- dev_err(dev->dev, "wait for aliveness settle failed ... bailing out\n");
- return -EIO;
- }
-
- if (aliveness_req) {
- mei_txe_aliveness_set(dev, 0);
- if (mei_txe_aliveness_poll(dev, 0) < 0) {
- dev_err(dev->dev, "wait for aliveness failed ... bailing out\n");
- return -EIO;
- }
- }
-
- mei_txe_readiness_clear(dev);
- return 0;
- }
- static int mei_txe_hw_start(struct mei_device *dev)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- int ret;
- u32 hisr;
-
- mei_txe_intr_enable(dev);
- ret = mei_txe_readiness_wait(dev);
- if (ret < 0) {
- dev_err(dev->dev, "waiting for readiness failed\n");
- return ret;
- }
-
- hisr = mei_txe_br_reg_read(hw, HISR_REG);
- if (hisr & HISR_INT_2_STS)
- mei_txe_br_reg_write(hw, HISR_REG, HISR_INT_2_STS);
-
- clear_bit(TXE_INTR_OUT_DB_BIT, &hw->intr_cause);
- ret = mei_txe_aliveness_set_sync(dev, 1);
- if (ret < 0) {
- dev_err(dev->dev, "wait for aliveness failed ... bailing out\n");
- return ret;
- }
- pm_runtime_set_active(dev->dev);
-
- mei_txe_input_ready_interrupt_enable(dev);
-
- mei_txe_output_ready_set(hw);
-
- mei_txe_readiness_set_host_rdy(dev);
- return 0;
- }
- static bool mei_txe_check_and_ack_intrs(struct mei_device *dev, bool do_ack)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- u32 hisr;
- u32 hhisr;
- u32 ipc_isr;
- u32 aliveness;
- bool generated;
-
- hhisr = mei_txe_br_reg_read(hw, HHISR_REG);
- generated = (hhisr & IPC_HHIER_MSK);
- if (!generated)
- goto out;
- hisr = mei_txe_br_reg_read(hw, HISR_REG);
- aliveness = mei_txe_aliveness_get(dev);
- if (hhisr & IPC_HHIER_SEC && aliveness) {
- ipc_isr = mei_txe_sec_reg_read_silent(hw,
- SEC_IPC_HOST_INT_STATUS_REG);
- } else {
- ipc_isr = 0;
- hhisr &= ~IPC_HHIER_SEC;
- }
- generated = generated ||
- (hisr & HISR_INT_STS_MSK) ||
- (ipc_isr & SEC_IPC_HOST_INT_STATUS_PENDING);
- if (generated && do_ack) {
-
- hw->intr_cause |= hisr & HISR_INT_STS_MSK;
- if (ipc_isr & SEC_IPC_HOST_INT_STATUS_IN_RDY)
- hw->intr_cause |= TXE_INTR_IN_READY;
- mei_txe_intr_disable(dev);
-
- mei_txe_sec_reg_write_silent(hw,
- SEC_IPC_HOST_INT_STATUS_REG, ipc_isr);
- mei_txe_br_reg_write(hw, HISR_REG, hisr);
- mei_txe_br_reg_write(hw, HHISR_REG, hhisr);
- }
- out:
- return generated;
- }
- irqreturn_t mei_txe_irq_quick_handler(int irq, void *dev_id)
- {
- struct mei_device *dev = dev_id;
- if (mei_txe_check_and_ack_intrs(dev, true))
- return IRQ_WAKE_THREAD;
- return IRQ_NONE;
- }
- irqreturn_t mei_txe_irq_thread_handler(int irq, void *dev_id)
- {
- struct mei_device *dev = (struct mei_device *) dev_id;
- struct mei_txe_hw *hw = to_txe_hw(dev);
- struct mei_cl_cb complete_list;
- s32 slots;
- int rets = 0;
- dev_dbg(dev->dev, "irq thread: Interrupt Registers HHISR|HISR|SEC=%02X|%04X|%02X\n",
- mei_txe_br_reg_read(hw, HHISR_REG),
- mei_txe_br_reg_read(hw, HISR_REG),
- mei_txe_sec_reg_read_silent(hw, SEC_IPC_HOST_INT_STATUS_REG));
-
- mutex_lock(&dev->device_lock);
- mei_io_list_init(&complete_list);
- if (pci_dev_msi_enabled(to_pci_dev(dev->dev)))
- mei_txe_check_and_ack_intrs(dev, true);
-
- mei_txe_pending_interrupts(dev);
- hw->aliveness = mei_txe_aliveness_get(dev);
- hw->readiness = mei_txe_readiness_get(dev);
-
- if (test_and_clear_bit(TXE_INTR_READINESS_BIT, &hw->intr_cause)) {
- dev_dbg(dev->dev, "Readiness Interrupt was received...\n");
-
- if (mei_txe_readiness_is_sec_rdy(hw->readiness)) {
- dev_dbg(dev->dev, "we need to start the dev.\n");
- dev->recvd_hw_ready = true;
- } else {
- dev->recvd_hw_ready = false;
- if (dev->dev_state != MEI_DEV_RESETTING) {
- dev_warn(dev->dev, "FW not ready: resetting.\n");
- schedule_work(&dev->reset_work);
- goto end;
- }
- }
- wake_up(&dev->wait_hw_ready);
- }
-
-
- if (test_and_clear_bit(TXE_INTR_ALIVENESS_BIT, &hw->intr_cause)) {
-
- dev_dbg(dev->dev,
- "Aliveness Interrupt: Status: %d\n", hw->aliveness);
- dev->pg_event = MEI_PG_EVENT_RECEIVED;
- if (waitqueue_active(&hw->wait_aliveness_resp))
- wake_up(&hw->wait_aliveness_resp);
- }
-
- slots = mei_count_full_read_slots(dev);
- if (test_and_clear_bit(TXE_INTR_OUT_DB_BIT, &hw->intr_cause)) {
-
- rets = mei_irq_read_handler(dev, &complete_list, &slots);
- if (rets && dev->dev_state != MEI_DEV_RESETTING) {
- dev_err(dev->dev,
- "mei_irq_read_handler ret = %d.\n", rets);
- schedule_work(&dev->reset_work);
- goto end;
- }
- }
-
- if (test_and_clear_bit(TXE_INTR_IN_READY_BIT, &hw->intr_cause)) {
- dev->hbuf_is_ready = true;
- hw->slots = dev->hbuf_depth;
- }
- if (hw->aliveness && dev->hbuf_is_ready) {
-
- dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
- rets = mei_irq_write_handler(dev, &complete_list);
- if (rets && rets != -EMSGSIZE)
- dev_err(dev->dev, "mei_irq_write_handler ret = %d.\n",
- rets);
- dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
- }
- mei_irq_compl_handler(dev, &complete_list);
- end:
- dev_dbg(dev->dev, "interrupt thread end ret = %d\n", rets);
- mutex_unlock(&dev->device_lock);
- mei_enable_interrupts(dev);
- return IRQ_HANDLED;
- }
- static const struct mei_hw_ops mei_txe_hw_ops = {
- .host_is_ready = mei_txe_host_is_ready,
- .fw_status = mei_txe_fw_status,
- .pg_state = mei_txe_pg_state,
- .hw_is_ready = mei_txe_hw_is_ready,
- .hw_reset = mei_txe_hw_reset,
- .hw_config = mei_txe_hw_config,
- .hw_start = mei_txe_hw_start,
- .pg_in_transition = mei_txe_pg_in_transition,
- .pg_is_enabled = mei_txe_pg_is_enabled,
- .intr_clear = mei_txe_intr_clear,
- .intr_enable = mei_txe_intr_enable,
- .intr_disable = mei_txe_intr_disable,
- .hbuf_free_slots = mei_txe_hbuf_empty_slots,
- .hbuf_is_ready = mei_txe_is_input_ready,
- .hbuf_max_len = mei_txe_hbuf_max_len,
- .write = mei_txe_write,
- .rdbuf_full_slots = mei_txe_count_full_read_slots,
- .read_hdr = mei_txe_read_hdr,
- .read = mei_txe_read,
- };
- struct mei_device *mei_txe_dev_init(struct pci_dev *pdev)
- {
- struct mei_device *dev;
- struct mei_txe_hw *hw;
- dev = kzalloc(sizeof(struct mei_device) +
- sizeof(struct mei_txe_hw), GFP_KERNEL);
- if (!dev)
- return NULL;
- mei_device_init(dev, &pdev->dev, &mei_txe_hw_ops);
- hw = to_txe_hw(dev);
- init_waitqueue_head(&hw->wait_aliveness_resp);
- return dev;
- }
- int mei_txe_setup_satt2(struct mei_device *dev, phys_addr_t addr, u32 range)
- {
- struct mei_txe_hw *hw = to_txe_hw(dev);
- u32 lo32 = lower_32_bits(addr);
- u32 hi32 = upper_32_bits(addr);
- u32 ctrl;
-
- if (hi32 & ~0xF)
- return -EINVAL;
-
- if (lo32 & 0xF)
- return -EINVAL;
-
- if (range & 0x4)
- return -EINVAL;
-
- if (range > SATT_RANGE_MAX)
- return -EINVAL;
- ctrl = SATT2_CTRL_VALID_MSK;
- ctrl |= hi32 << SATT2_CTRL_BR_BASE_ADDR_REG_SHIFT;
- mei_txe_br_reg_write(hw, SATT2_SAP_SIZE_REG, range);
- mei_txe_br_reg_write(hw, SATT2_BRG_BA_LSB_REG, lo32);
- mei_txe_br_reg_write(hw, SATT2_CTRL_REG, ctrl);
- dev_dbg(dev->dev, "SATT2: SAP_SIZE_OFFSET=0x%08X, BRG_BA_LSB_OFFSET=0x%08X, CTRL_OFFSET=0x%08X\n",
- range, lo32, ctrl);
- return 0;
- }
|