hw-txe.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. /*
  2. *
  3. * Intel Management Engine Interface (Intel MEI) Linux driver
  4. * Copyright (c) 2013-2014, Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. */
  16. #include <linux/pci.h>
  17. #include <linux/jiffies.h>
  18. #include <linux/ktime.h>
  19. #include <linux/delay.h>
  20. #include <linux/kthread.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/pm_runtime.h>
  23. #include <linux/mei.h>
  24. #include "mei_dev.h"
  25. #include "hw-txe.h"
  26. #include "client.h"
  27. #include "hbm.h"
  28. #include "mei-trace.h"
  29. /**
  30. * mei_txe_reg_read - Reads 32bit data from the txe device
  31. *
  32. * @base_addr: registers base address
  33. * @offset: register offset
  34. *
  35. * Return: register value
  36. */
  37. static inline u32 mei_txe_reg_read(void __iomem *base_addr,
  38. unsigned long offset)
  39. {
  40. return ioread32(base_addr + offset);
  41. }
  42. /**
  43. * mei_txe_reg_write - Writes 32bit data to the txe device
  44. *
  45. * @base_addr: registers base address
  46. * @offset: register offset
  47. * @value: the value to write
  48. */
  49. static inline void mei_txe_reg_write(void __iomem *base_addr,
  50. unsigned long offset, u32 value)
  51. {
  52. iowrite32(value, base_addr + offset);
  53. }
  54. /**
  55. * mei_txe_sec_reg_read_silent - Reads 32bit data from the SeC BAR
  56. *
  57. * @hw: the txe hardware structure
  58. * @offset: register offset
  59. *
  60. * Doesn't check for aliveness while Reads 32bit data from the SeC BAR
  61. *
  62. * Return: register value
  63. */
  64. static inline u32 mei_txe_sec_reg_read_silent(struct mei_txe_hw *hw,
  65. unsigned long offset)
  66. {
  67. return mei_txe_reg_read(hw->mem_addr[SEC_BAR], offset);
  68. }
  69. /**
  70. * mei_txe_sec_reg_read - Reads 32bit data from the SeC BAR
  71. *
  72. * @hw: the txe hardware structure
  73. * @offset: register offset
  74. *
  75. * Reads 32bit data from the SeC BAR and shout loud if aliveness is not set
  76. *
  77. * Return: register value
  78. */
  79. static inline u32 mei_txe_sec_reg_read(struct mei_txe_hw *hw,
  80. unsigned long offset)
  81. {
  82. WARN(!hw->aliveness, "sec read: aliveness not asserted\n");
  83. return mei_txe_sec_reg_read_silent(hw, offset);
  84. }
  85. /**
  86. * mei_txe_sec_reg_write_silent - Writes 32bit data to the SeC BAR
  87. * doesn't check for aliveness
  88. *
  89. * @hw: the txe hardware structure
  90. * @offset: register offset
  91. * @value: value to write
  92. *
  93. * Doesn't check for aliveness while writes 32bit data from to the SeC BAR
  94. */
  95. static inline void mei_txe_sec_reg_write_silent(struct mei_txe_hw *hw,
  96. unsigned long offset, u32 value)
  97. {
  98. mei_txe_reg_write(hw->mem_addr[SEC_BAR], offset, value);
  99. }
  100. /**
  101. * mei_txe_sec_reg_write - Writes 32bit data to the SeC BAR
  102. *
  103. * @hw: the txe hardware structure
  104. * @offset: register offset
  105. * @value: value to write
  106. *
  107. * Writes 32bit data from the SeC BAR and shout loud if aliveness is not set
  108. */
  109. static inline void mei_txe_sec_reg_write(struct mei_txe_hw *hw,
  110. unsigned long offset, u32 value)
  111. {
  112. WARN(!hw->aliveness, "sec write: aliveness not asserted\n");
  113. mei_txe_sec_reg_write_silent(hw, offset, value);
  114. }
  115. /**
  116. * mei_txe_br_reg_read - Reads 32bit data from the Bridge BAR
  117. *
  118. * @hw: the txe hardware structure
  119. * @offset: offset from which to read the data
  120. *
  121. * Return: the byte read.
  122. */
  123. static inline u32 mei_txe_br_reg_read(struct mei_txe_hw *hw,
  124. unsigned long offset)
  125. {
  126. return mei_txe_reg_read(hw->mem_addr[BRIDGE_BAR], offset);
  127. }
  128. /**
  129. * mei_txe_br_reg_write - Writes 32bit data to the Bridge BAR
  130. *
  131. * @hw: the txe hardware structure
  132. * @offset: offset from which to write the data
  133. * @value: the byte to write
  134. */
  135. static inline void mei_txe_br_reg_write(struct mei_txe_hw *hw,
  136. unsigned long offset, u32 value)
  137. {
  138. mei_txe_reg_write(hw->mem_addr[BRIDGE_BAR], offset, value);
  139. }
  140. /**
  141. * mei_txe_aliveness_set - request for aliveness change
  142. *
  143. * @dev: the device structure
  144. * @req: requested aliveness value
  145. *
  146. * Request for aliveness change and returns true if the change is
  147. * really needed and false if aliveness is already
  148. * in the requested state
  149. *
  150. * Locking: called under "dev->device_lock" lock
  151. *
  152. * Return: true if request was send
  153. */
  154. static bool mei_txe_aliveness_set(struct mei_device *dev, u32 req)
  155. {
  156. struct mei_txe_hw *hw = to_txe_hw(dev);
  157. bool do_req = hw->aliveness != req;
  158. dev_dbg(dev->dev, "Aliveness current=%d request=%d\n",
  159. hw->aliveness, req);
  160. if (do_req) {
  161. dev->pg_event = MEI_PG_EVENT_WAIT;
  162. mei_txe_br_reg_write(hw, SICR_HOST_ALIVENESS_REQ_REG, req);
  163. }
  164. return do_req;
  165. }
  166. /**
  167. * mei_txe_aliveness_req_get - get aliveness requested register value
  168. *
  169. * @dev: the device structure
  170. *
  171. * Extract HICR_HOST_ALIVENESS_RESP_ACK bit from
  172. * from HICR_HOST_ALIVENESS_REQ register value
  173. *
  174. * Return: SICR_HOST_ALIVENESS_REQ_REQUESTED bit value
  175. */
  176. static u32 mei_txe_aliveness_req_get(struct mei_device *dev)
  177. {
  178. struct mei_txe_hw *hw = to_txe_hw(dev);
  179. u32 reg;
  180. reg = mei_txe_br_reg_read(hw, SICR_HOST_ALIVENESS_REQ_REG);
  181. return reg & SICR_HOST_ALIVENESS_REQ_REQUESTED;
  182. }
  183. /**
  184. * mei_txe_aliveness_get - get aliveness response register value
  185. *
  186. * @dev: the device structure
  187. *
  188. * Return: HICR_HOST_ALIVENESS_RESP_ACK bit from HICR_HOST_ALIVENESS_RESP
  189. * register
  190. */
  191. static u32 mei_txe_aliveness_get(struct mei_device *dev)
  192. {
  193. struct mei_txe_hw *hw = to_txe_hw(dev);
  194. u32 reg;
  195. reg = mei_txe_br_reg_read(hw, HICR_HOST_ALIVENESS_RESP_REG);
  196. return reg & HICR_HOST_ALIVENESS_RESP_ACK;
  197. }
  198. /**
  199. * mei_txe_aliveness_poll - waits for aliveness to settle
  200. *
  201. * @dev: the device structure
  202. * @expected: expected aliveness value
  203. *
  204. * Polls for HICR_HOST_ALIVENESS_RESP.ALIVENESS_RESP to be set
  205. *
  206. * Return: 0 if the expected value was received, -ETIME otherwise
  207. */
  208. static int mei_txe_aliveness_poll(struct mei_device *dev, u32 expected)
  209. {
  210. struct mei_txe_hw *hw = to_txe_hw(dev);
  211. ktime_t stop, start;
  212. start = ktime_get();
  213. stop = ktime_add(start, ms_to_ktime(SEC_ALIVENESS_WAIT_TIMEOUT));
  214. do {
  215. hw->aliveness = mei_txe_aliveness_get(dev);
  216. if (hw->aliveness == expected) {
  217. dev->pg_event = MEI_PG_EVENT_IDLE;
  218. dev_dbg(dev->dev, "aliveness settled after %lld usecs\n",
  219. ktime_to_us(ktime_sub(ktime_get(), start)));
  220. return 0;
  221. }
  222. usleep_range(20, 50);
  223. } while (ktime_before(ktime_get(), stop));
  224. dev->pg_event = MEI_PG_EVENT_IDLE;
  225. dev_err(dev->dev, "aliveness timed out\n");
  226. return -ETIME;
  227. }
  228. /**
  229. * mei_txe_aliveness_wait - waits for aliveness to settle
  230. *
  231. * @dev: the device structure
  232. * @expected: expected aliveness value
  233. *
  234. * Waits for HICR_HOST_ALIVENESS_RESP.ALIVENESS_RESP to be set
  235. *
  236. * Return: 0 on success and < 0 otherwise
  237. */
  238. static int mei_txe_aliveness_wait(struct mei_device *dev, u32 expected)
  239. {
  240. struct mei_txe_hw *hw = to_txe_hw(dev);
  241. const unsigned long timeout =
  242. msecs_to_jiffies(SEC_ALIVENESS_WAIT_TIMEOUT);
  243. long err;
  244. int ret;
  245. hw->aliveness = mei_txe_aliveness_get(dev);
  246. if (hw->aliveness == expected)
  247. return 0;
  248. mutex_unlock(&dev->device_lock);
  249. err = wait_event_timeout(hw->wait_aliveness_resp,
  250. dev->pg_event == MEI_PG_EVENT_RECEIVED, timeout);
  251. mutex_lock(&dev->device_lock);
  252. hw->aliveness = mei_txe_aliveness_get(dev);
  253. ret = hw->aliveness == expected ? 0 : -ETIME;
  254. if (ret)
  255. dev_warn(dev->dev, "aliveness timed out = %ld aliveness = %d event = %d\n",
  256. err, hw->aliveness, dev->pg_event);
  257. else
  258. dev_dbg(dev->dev, "aliveness settled after = %d msec aliveness = %d event = %d\n",
  259. jiffies_to_msecs(timeout - err),
  260. hw->aliveness, dev->pg_event);
  261. dev->pg_event = MEI_PG_EVENT_IDLE;
  262. return ret;
  263. }
  264. /**
  265. * mei_txe_aliveness_set_sync - sets an wait for aliveness to complete
  266. *
  267. * @dev: the device structure
  268. * @req: requested aliveness value
  269. *
  270. * Return: 0 on success and < 0 otherwise
  271. */
  272. int mei_txe_aliveness_set_sync(struct mei_device *dev, u32 req)
  273. {
  274. if (mei_txe_aliveness_set(dev, req))
  275. return mei_txe_aliveness_wait(dev, req);
  276. return 0;
  277. }
  278. /**
  279. * mei_txe_pg_in_transition - is device now in pg transition
  280. *
  281. * @dev: the device structure
  282. *
  283. * Return: true if in pg transition, false otherwise
  284. */
  285. static bool mei_txe_pg_in_transition(struct mei_device *dev)
  286. {
  287. return dev->pg_event == MEI_PG_EVENT_WAIT;
  288. }
  289. /**
  290. * mei_txe_pg_is_enabled - detect if PG is supported by HW
  291. *
  292. * @dev: the device structure
  293. *
  294. * Return: true is pg supported, false otherwise
  295. */
  296. static bool mei_txe_pg_is_enabled(struct mei_device *dev)
  297. {
  298. return true;
  299. }
  300. /**
  301. * mei_txe_pg_state - translate aliveness register value
  302. * to the mei power gating state
  303. *
  304. * @dev: the device structure
  305. *
  306. * Return: MEI_PG_OFF if aliveness is on and MEI_PG_ON otherwise
  307. */
  308. static inline enum mei_pg_state mei_txe_pg_state(struct mei_device *dev)
  309. {
  310. struct mei_txe_hw *hw = to_txe_hw(dev);
  311. return hw->aliveness ? MEI_PG_OFF : MEI_PG_ON;
  312. }
  313. /**
  314. * mei_txe_input_ready_interrupt_enable - sets the Input Ready Interrupt
  315. *
  316. * @dev: the device structure
  317. */
  318. static void mei_txe_input_ready_interrupt_enable(struct mei_device *dev)
  319. {
  320. struct mei_txe_hw *hw = to_txe_hw(dev);
  321. u32 hintmsk;
  322. /* Enable the SEC_IPC_HOST_INT_MASK_IN_RDY interrupt */
  323. hintmsk = mei_txe_sec_reg_read(hw, SEC_IPC_HOST_INT_MASK_REG);
  324. hintmsk |= SEC_IPC_HOST_INT_MASK_IN_RDY;
  325. mei_txe_sec_reg_write(hw, SEC_IPC_HOST_INT_MASK_REG, hintmsk);
  326. }
  327. /**
  328. * mei_txe_input_doorbell_set - sets bit 0 in
  329. * SEC_IPC_INPUT_DOORBELL.IPC_INPUT_DOORBELL.
  330. *
  331. * @hw: the txe hardware structure
  332. */
  333. static void mei_txe_input_doorbell_set(struct mei_txe_hw *hw)
  334. {
  335. /* Clear the interrupt cause */
  336. clear_bit(TXE_INTR_IN_READY_BIT, &hw->intr_cause);
  337. mei_txe_sec_reg_write(hw, SEC_IPC_INPUT_DOORBELL_REG, 1);
  338. }
  339. /**
  340. * mei_txe_output_ready_set - Sets the SICR_SEC_IPC_OUTPUT_STATUS bit to 1
  341. *
  342. * @hw: the txe hardware structure
  343. */
  344. static void mei_txe_output_ready_set(struct mei_txe_hw *hw)
  345. {
  346. mei_txe_br_reg_write(hw,
  347. SICR_SEC_IPC_OUTPUT_STATUS_REG,
  348. SEC_IPC_OUTPUT_STATUS_RDY);
  349. }
  350. /**
  351. * mei_txe_is_input_ready - check if TXE is ready for receiving data
  352. *
  353. * @dev: the device structure
  354. *
  355. * Return: true if INPUT STATUS READY bit is set
  356. */
  357. static bool mei_txe_is_input_ready(struct mei_device *dev)
  358. {
  359. struct mei_txe_hw *hw = to_txe_hw(dev);
  360. u32 status;
  361. status = mei_txe_sec_reg_read(hw, SEC_IPC_INPUT_STATUS_REG);
  362. return !!(SEC_IPC_INPUT_STATUS_RDY & status);
  363. }
  364. /**
  365. * mei_txe_intr_clear - clear all interrupts
  366. *
  367. * @dev: the device structure
  368. */
  369. static inline void mei_txe_intr_clear(struct mei_device *dev)
  370. {
  371. struct mei_txe_hw *hw = to_txe_hw(dev);
  372. mei_txe_sec_reg_write_silent(hw, SEC_IPC_HOST_INT_STATUS_REG,
  373. SEC_IPC_HOST_INT_STATUS_PENDING);
  374. mei_txe_br_reg_write(hw, HISR_REG, HISR_INT_STS_MSK);
  375. mei_txe_br_reg_write(hw, HHISR_REG, IPC_HHIER_MSK);
  376. }
  377. /**
  378. * mei_txe_intr_disable - disable all interrupts
  379. *
  380. * @dev: the device structure
  381. */
  382. static void mei_txe_intr_disable(struct mei_device *dev)
  383. {
  384. struct mei_txe_hw *hw = to_txe_hw(dev);
  385. mei_txe_br_reg_write(hw, HHIER_REG, 0);
  386. mei_txe_br_reg_write(hw, HIER_REG, 0);
  387. }
  388. /**
  389. * mei_txe_intr_enable - enable all interrupts
  390. *
  391. * @dev: the device structure
  392. */
  393. static void mei_txe_intr_enable(struct mei_device *dev)
  394. {
  395. struct mei_txe_hw *hw = to_txe_hw(dev);
  396. mei_txe_br_reg_write(hw, HHIER_REG, IPC_HHIER_MSK);
  397. mei_txe_br_reg_write(hw, HIER_REG, HIER_INT_EN_MSK);
  398. }
  399. /**
  400. * mei_txe_synchronize_irq - wait for pending IRQ handlers
  401. *
  402. * @dev: the device structure
  403. */
  404. static void mei_txe_synchronize_irq(struct mei_device *dev)
  405. {
  406. struct pci_dev *pdev = to_pci_dev(dev->dev);
  407. synchronize_irq(pdev->irq);
  408. }
  409. /**
  410. * mei_txe_pending_interrupts - check if there are pending interrupts
  411. * only Aliveness, Input ready, and output doorbell are of relevance
  412. *
  413. * @dev: the device structure
  414. *
  415. * Checks if there are pending interrupts
  416. * only Aliveness, Readiness, Input ready, and Output doorbell are relevant
  417. *
  418. * Return: true if there are pending interrupts
  419. */
  420. static bool mei_txe_pending_interrupts(struct mei_device *dev)
  421. {
  422. struct mei_txe_hw *hw = to_txe_hw(dev);
  423. bool ret = (hw->intr_cause & (TXE_INTR_READINESS |
  424. TXE_INTR_ALIVENESS |
  425. TXE_INTR_IN_READY |
  426. TXE_INTR_OUT_DB));
  427. if (ret) {
  428. dev_dbg(dev->dev,
  429. "Pending Interrupts InReady=%01d Readiness=%01d, Aliveness=%01d, OutDoor=%01d\n",
  430. !!(hw->intr_cause & TXE_INTR_IN_READY),
  431. !!(hw->intr_cause & TXE_INTR_READINESS),
  432. !!(hw->intr_cause & TXE_INTR_ALIVENESS),
  433. !!(hw->intr_cause & TXE_INTR_OUT_DB));
  434. }
  435. return ret;
  436. }
  437. /**
  438. * mei_txe_input_payload_write - write a dword to the host buffer
  439. * at offset idx
  440. *
  441. * @dev: the device structure
  442. * @idx: index in the host buffer
  443. * @value: value
  444. */
  445. static void mei_txe_input_payload_write(struct mei_device *dev,
  446. unsigned long idx, u32 value)
  447. {
  448. struct mei_txe_hw *hw = to_txe_hw(dev);
  449. mei_txe_sec_reg_write(hw, SEC_IPC_INPUT_PAYLOAD_REG +
  450. (idx * sizeof(u32)), value);
  451. }
  452. /**
  453. * mei_txe_out_data_read - read dword from the device buffer
  454. * at offset idx
  455. *
  456. * @dev: the device structure
  457. * @idx: index in the device buffer
  458. *
  459. * Return: register value at index
  460. */
  461. static u32 mei_txe_out_data_read(const struct mei_device *dev,
  462. unsigned long idx)
  463. {
  464. struct mei_txe_hw *hw = to_txe_hw(dev);
  465. return mei_txe_br_reg_read(hw,
  466. BRIDGE_IPC_OUTPUT_PAYLOAD_REG + (idx * sizeof(u32)));
  467. }
  468. /* Readiness */
  469. /**
  470. * mei_txe_readiness_set_host_rdy - set host readiness bit
  471. *
  472. * @dev: the device structure
  473. */
  474. static void mei_txe_readiness_set_host_rdy(struct mei_device *dev)
  475. {
  476. struct mei_txe_hw *hw = to_txe_hw(dev);
  477. mei_txe_br_reg_write(hw,
  478. SICR_HOST_IPC_READINESS_REQ_REG,
  479. SICR_HOST_IPC_READINESS_HOST_RDY);
  480. }
  481. /**
  482. * mei_txe_readiness_clear - clear host readiness bit
  483. *
  484. * @dev: the device structure
  485. */
  486. static void mei_txe_readiness_clear(struct mei_device *dev)
  487. {
  488. struct mei_txe_hw *hw = to_txe_hw(dev);
  489. mei_txe_br_reg_write(hw, SICR_HOST_IPC_READINESS_REQ_REG,
  490. SICR_HOST_IPC_READINESS_RDY_CLR);
  491. }
  492. /**
  493. * mei_txe_readiness_get - Reads and returns
  494. * the HICR_SEC_IPC_READINESS register value
  495. *
  496. * @dev: the device structure
  497. *
  498. * Return: the HICR_SEC_IPC_READINESS register value
  499. */
  500. static u32 mei_txe_readiness_get(struct mei_device *dev)
  501. {
  502. struct mei_txe_hw *hw = to_txe_hw(dev);
  503. return mei_txe_br_reg_read(hw, HICR_SEC_IPC_READINESS_REG);
  504. }
  505. /**
  506. * mei_txe_readiness_is_sec_rdy - check readiness
  507. * for HICR_SEC_IPC_READINESS_SEC_RDY
  508. *
  509. * @readiness: cached readiness state
  510. *
  511. * Return: true if readiness bit is set
  512. */
  513. static inline bool mei_txe_readiness_is_sec_rdy(u32 readiness)
  514. {
  515. return !!(readiness & HICR_SEC_IPC_READINESS_SEC_RDY);
  516. }
  517. /**
  518. * mei_txe_hw_is_ready - check if the hw is ready
  519. *
  520. * @dev: the device structure
  521. *
  522. * Return: true if sec is ready
  523. */
  524. static bool mei_txe_hw_is_ready(struct mei_device *dev)
  525. {
  526. u32 readiness = mei_txe_readiness_get(dev);
  527. return mei_txe_readiness_is_sec_rdy(readiness);
  528. }
  529. /**
  530. * mei_txe_host_is_ready - check if the host is ready
  531. *
  532. * @dev: the device structure
  533. *
  534. * Return: true if host is ready
  535. */
  536. static inline bool mei_txe_host_is_ready(struct mei_device *dev)
  537. {
  538. struct mei_txe_hw *hw = to_txe_hw(dev);
  539. u32 reg = mei_txe_br_reg_read(hw, HICR_SEC_IPC_READINESS_REG);
  540. return !!(reg & HICR_SEC_IPC_READINESS_HOST_RDY);
  541. }
  542. /**
  543. * mei_txe_readiness_wait - wait till readiness settles
  544. *
  545. * @dev: the device structure
  546. *
  547. * Return: 0 on success and -ETIME on timeout
  548. */
  549. static int mei_txe_readiness_wait(struct mei_device *dev)
  550. {
  551. if (mei_txe_hw_is_ready(dev))
  552. return 0;
  553. mutex_unlock(&dev->device_lock);
  554. wait_event_timeout(dev->wait_hw_ready, dev->recvd_hw_ready,
  555. msecs_to_jiffies(SEC_RESET_WAIT_TIMEOUT));
  556. mutex_lock(&dev->device_lock);
  557. if (!dev->recvd_hw_ready) {
  558. dev_err(dev->dev, "wait for readiness failed\n");
  559. return -ETIME;
  560. }
  561. dev->recvd_hw_ready = false;
  562. return 0;
  563. }
  564. static const struct mei_fw_status mei_txe_fw_sts = {
  565. .count = 2,
  566. .status[0] = PCI_CFG_TXE_FW_STS0,
  567. .status[1] = PCI_CFG_TXE_FW_STS1
  568. };
  569. /**
  570. * mei_txe_fw_status - read fw status register from pci config space
  571. *
  572. * @dev: mei device
  573. * @fw_status: fw status register values
  574. *
  575. * Return: 0 on success, error otherwise
  576. */
  577. static int mei_txe_fw_status(struct mei_device *dev,
  578. struct mei_fw_status *fw_status)
  579. {
  580. const struct mei_fw_status *fw_src = &mei_txe_fw_sts;
  581. struct pci_dev *pdev = to_pci_dev(dev->dev);
  582. int ret;
  583. int i;
  584. if (!fw_status)
  585. return -EINVAL;
  586. fw_status->count = fw_src->count;
  587. for (i = 0; i < fw_src->count && i < MEI_FW_STATUS_MAX; i++) {
  588. ret = pci_read_config_dword(pdev, fw_src->status[i],
  589. &fw_status->status[i]);
  590. trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HSF_X",
  591. fw_src->status[i],
  592. fw_status->status[i]);
  593. if (ret)
  594. return ret;
  595. }
  596. return 0;
  597. }
  598. /**
  599. * mei_txe_hw_config - configure hardware at the start of the devices
  600. *
  601. * @dev: the device structure
  602. *
  603. * Configure hardware at the start of the device should be done only
  604. * once at the device probe time
  605. */
  606. static void mei_txe_hw_config(struct mei_device *dev)
  607. {
  608. struct mei_txe_hw *hw = to_txe_hw(dev);
  609. /* Doesn't change in runtime */
  610. dev->hbuf_depth = PAYLOAD_SIZE / 4;
  611. hw->aliveness = mei_txe_aliveness_get(dev);
  612. hw->readiness = mei_txe_readiness_get(dev);
  613. dev_dbg(dev->dev, "aliveness_resp = 0x%08x, readiness = 0x%08x.\n",
  614. hw->aliveness, hw->readiness);
  615. }
  616. /**
  617. * mei_txe_write - writes a message to device.
  618. *
  619. * @dev: the device structure
  620. * @header: header of message
  621. * @buf: message buffer will be written
  622. *
  623. * Return: 0 if success, <0 - otherwise.
  624. */
  625. static int mei_txe_write(struct mei_device *dev,
  626. struct mei_msg_hdr *header,
  627. const unsigned char *buf)
  628. {
  629. struct mei_txe_hw *hw = to_txe_hw(dev);
  630. unsigned long rem;
  631. unsigned long length;
  632. int slots = dev->hbuf_depth;
  633. u32 *reg_buf = (u32 *)buf;
  634. u32 dw_cnt;
  635. int i;
  636. if (WARN_ON(!header || !buf))
  637. return -EINVAL;
  638. length = header->length;
  639. dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(header));
  640. dw_cnt = mei_data2slots(length);
  641. if (dw_cnt > slots)
  642. return -EMSGSIZE;
  643. if (WARN(!hw->aliveness, "txe write: aliveness not asserted\n"))
  644. return -EAGAIN;
  645. /* Enable Input Ready Interrupt. */
  646. mei_txe_input_ready_interrupt_enable(dev);
  647. if (!mei_txe_is_input_ready(dev)) {
  648. char fw_sts_str[MEI_FW_STATUS_STR_SZ];
  649. mei_fw_status_str(dev, fw_sts_str, MEI_FW_STATUS_STR_SZ);
  650. dev_err(dev->dev, "Input is not ready %s\n", fw_sts_str);
  651. return -EAGAIN;
  652. }
  653. mei_txe_input_payload_write(dev, 0, *((u32 *)header));
  654. for (i = 0; i < length / 4; i++)
  655. mei_txe_input_payload_write(dev, i + 1, reg_buf[i]);
  656. rem = length & 0x3;
  657. if (rem > 0) {
  658. u32 reg = 0;
  659. memcpy(&reg, &buf[length - rem], rem);
  660. mei_txe_input_payload_write(dev, i + 1, reg);
  661. }
  662. /* after each write the whole buffer is consumed */
  663. hw->slots = 0;
  664. /* Set Input-Doorbell */
  665. mei_txe_input_doorbell_set(hw);
  666. return 0;
  667. }
  668. /**
  669. * mei_txe_hbuf_max_len - mimics the me hbuf circular buffer
  670. *
  671. * @dev: the device structure
  672. *
  673. * Return: the PAYLOAD_SIZE - 4
  674. */
  675. static size_t mei_txe_hbuf_max_len(const struct mei_device *dev)
  676. {
  677. return PAYLOAD_SIZE - sizeof(struct mei_msg_hdr);
  678. }
  679. /**
  680. * mei_txe_hbuf_empty_slots - mimics the me hbuf circular buffer
  681. *
  682. * @dev: the device structure
  683. *
  684. * Return: always hbuf_depth
  685. */
  686. static int mei_txe_hbuf_empty_slots(struct mei_device *dev)
  687. {
  688. struct mei_txe_hw *hw = to_txe_hw(dev);
  689. return hw->slots;
  690. }
  691. /**
  692. * mei_txe_count_full_read_slots - mimics the me device circular buffer
  693. *
  694. * @dev: the device structure
  695. *
  696. * Return: always buffer size in dwords count
  697. */
  698. static int mei_txe_count_full_read_slots(struct mei_device *dev)
  699. {
  700. /* read buffers has static size */
  701. return PAYLOAD_SIZE / 4;
  702. }
  703. /**
  704. * mei_txe_read_hdr - read message header which is always in 4 first bytes
  705. *
  706. * @dev: the device structure
  707. *
  708. * Return: mei message header
  709. */
  710. static u32 mei_txe_read_hdr(const struct mei_device *dev)
  711. {
  712. return mei_txe_out_data_read(dev, 0);
  713. }
  714. /**
  715. * mei_txe_read - reads a message from the txe device.
  716. *
  717. * @dev: the device structure
  718. * @buf: message buffer will be written
  719. * @len: message size will be read
  720. *
  721. * Return: -EINVAL on error wrong argument and 0 on success
  722. */
  723. static int mei_txe_read(struct mei_device *dev,
  724. unsigned char *buf, unsigned long len)
  725. {
  726. struct mei_txe_hw *hw = to_txe_hw(dev);
  727. u32 *reg_buf, reg;
  728. u32 rem;
  729. u32 i;
  730. if (WARN_ON(!buf || !len))
  731. return -EINVAL;
  732. reg_buf = (u32 *)buf;
  733. rem = len & 0x3;
  734. dev_dbg(dev->dev, "buffer-length = %lu buf[0]0x%08X\n",
  735. len, mei_txe_out_data_read(dev, 0));
  736. for (i = 0; i < len / 4; i++) {
  737. /* skip header: index starts from 1 */
  738. reg = mei_txe_out_data_read(dev, i + 1);
  739. dev_dbg(dev->dev, "buf[%d] = 0x%08X\n", i, reg);
  740. *reg_buf++ = reg;
  741. }
  742. if (rem) {
  743. reg = mei_txe_out_data_read(dev, i + 1);
  744. memcpy(reg_buf, &reg, rem);
  745. }
  746. mei_txe_output_ready_set(hw);
  747. return 0;
  748. }
  749. /**
  750. * mei_txe_hw_reset - resets host and fw.
  751. *
  752. * @dev: the device structure
  753. * @intr_enable: if interrupt should be enabled after reset.
  754. *
  755. * Return: 0 on success and < 0 in case of error
  756. */
  757. static int mei_txe_hw_reset(struct mei_device *dev, bool intr_enable)
  758. {
  759. struct mei_txe_hw *hw = to_txe_hw(dev);
  760. u32 aliveness_req;
  761. /*
  762. * read input doorbell to ensure consistency between Bridge and SeC
  763. * return value might be garbage return
  764. */
  765. (void)mei_txe_sec_reg_read_silent(hw, SEC_IPC_INPUT_DOORBELL_REG);
  766. aliveness_req = mei_txe_aliveness_req_get(dev);
  767. hw->aliveness = mei_txe_aliveness_get(dev);
  768. /* Disable interrupts in this stage we will poll */
  769. mei_txe_intr_disable(dev);
  770. /*
  771. * If Aliveness Request and Aliveness Response are not equal then
  772. * wait for them to be equal
  773. * Since we might have interrupts disabled - poll for it
  774. */
  775. if (aliveness_req != hw->aliveness)
  776. if (mei_txe_aliveness_poll(dev, aliveness_req) < 0) {
  777. dev_err(dev->dev, "wait for aliveness settle failed ... bailing out\n");
  778. return -EIO;
  779. }
  780. /*
  781. * If Aliveness Request and Aliveness Response are set then clear them
  782. */
  783. if (aliveness_req) {
  784. mei_txe_aliveness_set(dev, 0);
  785. if (mei_txe_aliveness_poll(dev, 0) < 0) {
  786. dev_err(dev->dev, "wait for aliveness failed ... bailing out\n");
  787. return -EIO;
  788. }
  789. }
  790. /*
  791. * Set readiness RDY_CLR bit
  792. */
  793. mei_txe_readiness_clear(dev);
  794. return 0;
  795. }
  796. /**
  797. * mei_txe_hw_start - start the hardware after reset
  798. *
  799. * @dev: the device structure
  800. *
  801. * Return: 0 on success an error code otherwise
  802. */
  803. static int mei_txe_hw_start(struct mei_device *dev)
  804. {
  805. struct mei_txe_hw *hw = to_txe_hw(dev);
  806. int ret;
  807. u32 hisr;
  808. /* bring back interrupts */
  809. mei_txe_intr_enable(dev);
  810. ret = mei_txe_readiness_wait(dev);
  811. if (ret < 0) {
  812. dev_err(dev->dev, "waiting for readiness failed\n");
  813. return ret;
  814. }
  815. /*
  816. * If HISR.INT2_STS interrupt status bit is set then clear it.
  817. */
  818. hisr = mei_txe_br_reg_read(hw, HISR_REG);
  819. if (hisr & HISR_INT_2_STS)
  820. mei_txe_br_reg_write(hw, HISR_REG, HISR_INT_2_STS);
  821. /* Clear the interrupt cause of OutputDoorbell */
  822. clear_bit(TXE_INTR_OUT_DB_BIT, &hw->intr_cause);
  823. ret = mei_txe_aliveness_set_sync(dev, 1);
  824. if (ret < 0) {
  825. dev_err(dev->dev, "wait for aliveness failed ... bailing out\n");
  826. return ret;
  827. }
  828. pm_runtime_set_active(dev->dev);
  829. /* enable input ready interrupts:
  830. * SEC_IPC_HOST_INT_MASK.IPC_INPUT_READY_INT_MASK
  831. */
  832. mei_txe_input_ready_interrupt_enable(dev);
  833. /* Set the SICR_SEC_IPC_OUTPUT_STATUS.IPC_OUTPUT_READY bit */
  834. mei_txe_output_ready_set(hw);
  835. /* Set bit SICR_HOST_IPC_READINESS.HOST_RDY
  836. */
  837. mei_txe_readiness_set_host_rdy(dev);
  838. return 0;
  839. }
  840. /**
  841. * mei_txe_check_and_ack_intrs - translate multi BAR interrupt into
  842. * single bit mask and acknowledge the interrupts
  843. *
  844. * @dev: the device structure
  845. * @do_ack: acknowledge interrupts
  846. *
  847. * Return: true if found interrupts to process.
  848. */
  849. static bool mei_txe_check_and_ack_intrs(struct mei_device *dev, bool do_ack)
  850. {
  851. struct mei_txe_hw *hw = to_txe_hw(dev);
  852. u32 hisr;
  853. u32 hhisr;
  854. u32 ipc_isr;
  855. u32 aliveness;
  856. bool generated;
  857. /* read interrupt registers */
  858. hhisr = mei_txe_br_reg_read(hw, HHISR_REG);
  859. generated = (hhisr & IPC_HHIER_MSK);
  860. if (!generated)
  861. goto out;
  862. hisr = mei_txe_br_reg_read(hw, HISR_REG);
  863. aliveness = mei_txe_aliveness_get(dev);
  864. if (hhisr & IPC_HHIER_SEC && aliveness) {
  865. ipc_isr = mei_txe_sec_reg_read_silent(hw,
  866. SEC_IPC_HOST_INT_STATUS_REG);
  867. } else {
  868. ipc_isr = 0;
  869. hhisr &= ~IPC_HHIER_SEC;
  870. }
  871. generated = generated ||
  872. (hisr & HISR_INT_STS_MSK) ||
  873. (ipc_isr & SEC_IPC_HOST_INT_STATUS_PENDING);
  874. if (generated && do_ack) {
  875. /* Save the interrupt causes */
  876. hw->intr_cause |= hisr & HISR_INT_STS_MSK;
  877. if (ipc_isr & SEC_IPC_HOST_INT_STATUS_IN_RDY)
  878. hw->intr_cause |= TXE_INTR_IN_READY;
  879. mei_txe_intr_disable(dev);
  880. /* Clear the interrupts in hierarchy:
  881. * IPC and Bridge, than the High Level */
  882. mei_txe_sec_reg_write_silent(hw,
  883. SEC_IPC_HOST_INT_STATUS_REG, ipc_isr);
  884. mei_txe_br_reg_write(hw, HISR_REG, hisr);
  885. mei_txe_br_reg_write(hw, HHISR_REG, hhisr);
  886. }
  887. out:
  888. return generated;
  889. }
  890. /**
  891. * mei_txe_irq_quick_handler - The ISR of the MEI device
  892. *
  893. * @irq: The irq number
  894. * @dev_id: pointer to the device structure
  895. *
  896. * Return: IRQ_WAKE_THREAD if interrupt is designed for the device
  897. * IRQ_NONE otherwise
  898. */
  899. irqreturn_t mei_txe_irq_quick_handler(int irq, void *dev_id)
  900. {
  901. struct mei_device *dev = dev_id;
  902. if (mei_txe_check_and_ack_intrs(dev, true))
  903. return IRQ_WAKE_THREAD;
  904. return IRQ_NONE;
  905. }
  906. /**
  907. * mei_txe_irq_thread_handler - txe interrupt thread
  908. *
  909. * @irq: The irq number
  910. * @dev_id: pointer to the device structure
  911. *
  912. * Return: IRQ_HANDLED
  913. */
  914. irqreturn_t mei_txe_irq_thread_handler(int irq, void *dev_id)
  915. {
  916. struct mei_device *dev = (struct mei_device *) dev_id;
  917. struct mei_txe_hw *hw = to_txe_hw(dev);
  918. struct list_head cmpl_list;
  919. s32 slots;
  920. int rets = 0;
  921. dev_dbg(dev->dev, "irq thread: Interrupt Registers HHISR|HISR|SEC=%02X|%04X|%02X\n",
  922. mei_txe_br_reg_read(hw, HHISR_REG),
  923. mei_txe_br_reg_read(hw, HISR_REG),
  924. mei_txe_sec_reg_read_silent(hw, SEC_IPC_HOST_INT_STATUS_REG));
  925. /* initialize our complete list */
  926. mutex_lock(&dev->device_lock);
  927. INIT_LIST_HEAD(&cmpl_list);
  928. if (pci_dev_msi_enabled(to_pci_dev(dev->dev)))
  929. mei_txe_check_and_ack_intrs(dev, true);
  930. /* show irq events */
  931. mei_txe_pending_interrupts(dev);
  932. hw->aliveness = mei_txe_aliveness_get(dev);
  933. hw->readiness = mei_txe_readiness_get(dev);
  934. /* Readiness:
  935. * Detection of TXE driver going through reset
  936. * or TXE driver resetting the HECI interface.
  937. */
  938. if (test_and_clear_bit(TXE_INTR_READINESS_BIT, &hw->intr_cause)) {
  939. dev_dbg(dev->dev, "Readiness Interrupt was received...\n");
  940. /* Check if SeC is going through reset */
  941. if (mei_txe_readiness_is_sec_rdy(hw->readiness)) {
  942. dev_dbg(dev->dev, "we need to start the dev.\n");
  943. dev->recvd_hw_ready = true;
  944. } else {
  945. dev->recvd_hw_ready = false;
  946. if (dev->dev_state != MEI_DEV_RESETTING) {
  947. dev_warn(dev->dev, "FW not ready: resetting.\n");
  948. schedule_work(&dev->reset_work);
  949. goto end;
  950. }
  951. }
  952. wake_up(&dev->wait_hw_ready);
  953. }
  954. /************************************************************/
  955. /* Check interrupt cause:
  956. * Aliveness: Detection of SeC acknowledge of host request that
  957. * it remain alive or host cancellation of that request.
  958. */
  959. if (test_and_clear_bit(TXE_INTR_ALIVENESS_BIT, &hw->intr_cause)) {
  960. /* Clear the interrupt cause */
  961. dev_dbg(dev->dev,
  962. "Aliveness Interrupt: Status: %d\n", hw->aliveness);
  963. dev->pg_event = MEI_PG_EVENT_RECEIVED;
  964. if (waitqueue_active(&hw->wait_aliveness_resp))
  965. wake_up(&hw->wait_aliveness_resp);
  966. }
  967. /* Output Doorbell:
  968. * Detection of SeC having sent output to host
  969. */
  970. slots = mei_count_full_read_slots(dev);
  971. if (test_and_clear_bit(TXE_INTR_OUT_DB_BIT, &hw->intr_cause)) {
  972. /* Read from TXE */
  973. rets = mei_irq_read_handler(dev, &cmpl_list, &slots);
  974. if (rets && dev->dev_state != MEI_DEV_RESETTING) {
  975. dev_err(dev->dev,
  976. "mei_irq_read_handler ret = %d.\n", rets);
  977. schedule_work(&dev->reset_work);
  978. goto end;
  979. }
  980. }
  981. /* Input Ready: Detection if host can write to SeC */
  982. if (test_and_clear_bit(TXE_INTR_IN_READY_BIT, &hw->intr_cause)) {
  983. dev->hbuf_is_ready = true;
  984. hw->slots = dev->hbuf_depth;
  985. }
  986. if (hw->aliveness && dev->hbuf_is_ready) {
  987. /* get the real register value */
  988. dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
  989. rets = mei_irq_write_handler(dev, &cmpl_list);
  990. if (rets && rets != -EMSGSIZE)
  991. dev_err(dev->dev, "mei_irq_write_handler ret = %d.\n",
  992. rets);
  993. dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
  994. }
  995. mei_irq_compl_handler(dev, &cmpl_list);
  996. end:
  997. dev_dbg(dev->dev, "interrupt thread end ret = %d\n", rets);
  998. mutex_unlock(&dev->device_lock);
  999. mei_enable_interrupts(dev);
  1000. return IRQ_HANDLED;
  1001. }
  1002. static const struct mei_hw_ops mei_txe_hw_ops = {
  1003. .host_is_ready = mei_txe_host_is_ready,
  1004. .fw_status = mei_txe_fw_status,
  1005. .pg_state = mei_txe_pg_state,
  1006. .hw_is_ready = mei_txe_hw_is_ready,
  1007. .hw_reset = mei_txe_hw_reset,
  1008. .hw_config = mei_txe_hw_config,
  1009. .hw_start = mei_txe_hw_start,
  1010. .pg_in_transition = mei_txe_pg_in_transition,
  1011. .pg_is_enabled = mei_txe_pg_is_enabled,
  1012. .intr_clear = mei_txe_intr_clear,
  1013. .intr_enable = mei_txe_intr_enable,
  1014. .intr_disable = mei_txe_intr_disable,
  1015. .synchronize_irq = mei_txe_synchronize_irq,
  1016. .hbuf_free_slots = mei_txe_hbuf_empty_slots,
  1017. .hbuf_is_ready = mei_txe_is_input_ready,
  1018. .hbuf_max_len = mei_txe_hbuf_max_len,
  1019. .write = mei_txe_write,
  1020. .rdbuf_full_slots = mei_txe_count_full_read_slots,
  1021. .read_hdr = mei_txe_read_hdr,
  1022. .read = mei_txe_read,
  1023. };
  1024. /**
  1025. * mei_txe_dev_init - allocates and initializes txe hardware specific structure
  1026. *
  1027. * @pdev: pci device
  1028. *
  1029. * Return: struct mei_device * on success or NULL
  1030. */
  1031. struct mei_device *mei_txe_dev_init(struct pci_dev *pdev)
  1032. {
  1033. struct mei_device *dev;
  1034. struct mei_txe_hw *hw;
  1035. dev = devm_kzalloc(&pdev->dev, sizeof(struct mei_device) +
  1036. sizeof(struct mei_txe_hw), GFP_KERNEL);
  1037. if (!dev)
  1038. return NULL;
  1039. mei_device_init(dev, &pdev->dev, &mei_txe_hw_ops);
  1040. hw = to_txe_hw(dev);
  1041. init_waitqueue_head(&hw->wait_aliveness_resp);
  1042. return dev;
  1043. }
  1044. /**
  1045. * mei_txe_setup_satt2 - SATT2 configuration for DMA support.
  1046. *
  1047. * @dev: the device structure
  1048. * @addr: physical address start of the range
  1049. * @range: physical range size
  1050. *
  1051. * Return: 0 on success an error code otherwise
  1052. */
  1053. int mei_txe_setup_satt2(struct mei_device *dev, phys_addr_t addr, u32 range)
  1054. {
  1055. struct mei_txe_hw *hw = to_txe_hw(dev);
  1056. u32 lo32 = lower_32_bits(addr);
  1057. u32 hi32 = upper_32_bits(addr);
  1058. u32 ctrl;
  1059. /* SATT is limited to 36 Bits */
  1060. if (hi32 & ~0xF)
  1061. return -EINVAL;
  1062. /* SATT has to be 16Byte aligned */
  1063. if (lo32 & 0xF)
  1064. return -EINVAL;
  1065. /* SATT range has to be 4Bytes aligned */
  1066. if (range & 0x4)
  1067. return -EINVAL;
  1068. /* SATT is limited to 32 MB range*/
  1069. if (range > SATT_RANGE_MAX)
  1070. return -EINVAL;
  1071. ctrl = SATT2_CTRL_VALID_MSK;
  1072. ctrl |= hi32 << SATT2_CTRL_BR_BASE_ADDR_REG_SHIFT;
  1073. mei_txe_br_reg_write(hw, SATT2_SAP_SIZE_REG, range);
  1074. mei_txe_br_reg_write(hw, SATT2_BRG_BA_LSB_REG, lo32);
  1075. mei_txe_br_reg_write(hw, SATT2_CTRL_REG, ctrl);
  1076. dev_dbg(dev->dev, "SATT2: SAP_SIZE_OFFSET=0x%08X, BRG_BA_LSB_OFFSET=0x%08X, CTRL_OFFSET=0x%08X\n",
  1077. range, lo32, ctrl);
  1078. return 0;
  1079. }