hw-me.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  1. /*
  2. *
  3. * Intel Management Engine Interface (Intel MEI) Linux driver
  4. * Copyright (c) 2003-2012, 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/kthread.h>
  18. #include <linux/interrupt.h>
  19. #include "mei_dev.h"
  20. #include "hbm.h"
  21. #include "hw-me.h"
  22. #include "hw-me-regs.h"
  23. #include "mei-trace.h"
  24. /**
  25. * mei_me_reg_read - Reads 32bit data from the mei device
  26. *
  27. * @hw: the me hardware structure
  28. * @offset: offset from which to read the data
  29. *
  30. * Return: register value (u32)
  31. */
  32. static inline u32 mei_me_reg_read(const struct mei_me_hw *hw,
  33. unsigned long offset)
  34. {
  35. return ioread32(hw->mem_addr + offset);
  36. }
  37. /**
  38. * mei_me_reg_write - Writes 32bit data to the mei device
  39. *
  40. * @hw: the me hardware structure
  41. * @offset: offset from which to write the data
  42. * @value: register value to write (u32)
  43. */
  44. static inline void mei_me_reg_write(const struct mei_me_hw *hw,
  45. unsigned long offset, u32 value)
  46. {
  47. iowrite32(value, hw->mem_addr + offset);
  48. }
  49. /**
  50. * mei_me_mecbrw_read - Reads 32bit data from ME circular buffer
  51. * read window register
  52. *
  53. * @dev: the device structure
  54. *
  55. * Return: ME_CB_RW register value (u32)
  56. */
  57. static inline u32 mei_me_mecbrw_read(const struct mei_device *dev)
  58. {
  59. return mei_me_reg_read(to_me_hw(dev), ME_CB_RW);
  60. }
  61. /**
  62. * mei_me_hcbww_write - write 32bit data to the host circular buffer
  63. *
  64. * @dev: the device structure
  65. * @data: 32bit data to be written to the host circular buffer
  66. */
  67. static inline void mei_me_hcbww_write(struct mei_device *dev, u32 data)
  68. {
  69. mei_me_reg_write(to_me_hw(dev), H_CB_WW, data);
  70. }
  71. /**
  72. * mei_me_mecsr_read - Reads 32bit data from the ME CSR
  73. *
  74. * @dev: the device structure
  75. *
  76. * Return: ME_CSR_HA register value (u32)
  77. */
  78. static inline u32 mei_me_mecsr_read(const struct mei_device *dev)
  79. {
  80. u32 reg;
  81. reg = mei_me_reg_read(to_me_hw(dev), ME_CSR_HA);
  82. trace_mei_reg_read(dev->dev, "ME_CSR_HA", ME_CSR_HA, reg);
  83. return reg;
  84. }
  85. /**
  86. * mei_hcsr_read - Reads 32bit data from the host CSR
  87. *
  88. * @dev: the device structure
  89. *
  90. * Return: H_CSR register value (u32)
  91. */
  92. static inline u32 mei_hcsr_read(const struct mei_device *dev)
  93. {
  94. u32 reg;
  95. reg = mei_me_reg_read(to_me_hw(dev), H_CSR);
  96. trace_mei_reg_read(dev->dev, "H_CSR", H_CSR, reg);
  97. return reg;
  98. }
  99. /**
  100. * mei_hcsr_write - writes H_CSR register to the mei device
  101. *
  102. * @dev: the device structure
  103. * @reg: new register value
  104. */
  105. static inline void mei_hcsr_write(struct mei_device *dev, u32 reg)
  106. {
  107. trace_mei_reg_write(dev->dev, "H_CSR", H_CSR, reg);
  108. mei_me_reg_write(to_me_hw(dev), H_CSR, reg);
  109. }
  110. /**
  111. * mei_hcsr_set - writes H_CSR register to the mei device,
  112. * and ignores the H_IS bit for it is write-one-to-zero.
  113. *
  114. * @dev: the device structure
  115. * @reg: new register value
  116. */
  117. static inline void mei_hcsr_set(struct mei_device *dev, u32 reg)
  118. {
  119. reg &= ~H_CSR_IS_MASK;
  120. mei_hcsr_write(dev, reg);
  121. }
  122. /**
  123. * mei_me_d0i3c_read - Reads 32bit data from the D0I3C register
  124. *
  125. * @dev: the device structure
  126. *
  127. * Return: H_D0I3C register value (u32)
  128. */
  129. static inline u32 mei_me_d0i3c_read(const struct mei_device *dev)
  130. {
  131. u32 reg;
  132. reg = mei_me_reg_read(to_me_hw(dev), H_D0I3C);
  133. trace_mei_reg_read(dev->dev, "H_D0I3C", H_D0I3C, reg);
  134. return reg;
  135. }
  136. /**
  137. * mei_me_d0i3c_write - writes H_D0I3C register to device
  138. *
  139. * @dev: the device structure
  140. * @reg: new register value
  141. */
  142. static inline void mei_me_d0i3c_write(struct mei_device *dev, u32 reg)
  143. {
  144. trace_mei_reg_write(dev->dev, "H_D0I3C", H_D0I3C, reg);
  145. mei_me_reg_write(to_me_hw(dev), H_D0I3C, reg);
  146. }
  147. /**
  148. * mei_me_fw_status - read fw status register from pci config space
  149. *
  150. * @dev: mei device
  151. * @fw_status: fw status register values
  152. *
  153. * Return: 0 on success, error otherwise
  154. */
  155. static int mei_me_fw_status(struct mei_device *dev,
  156. struct mei_fw_status *fw_status)
  157. {
  158. struct pci_dev *pdev = to_pci_dev(dev->dev);
  159. struct mei_me_hw *hw = to_me_hw(dev);
  160. const struct mei_fw_status *fw_src = &hw->cfg->fw_status;
  161. int ret;
  162. int i;
  163. if (!fw_status)
  164. return -EINVAL;
  165. fw_status->count = fw_src->count;
  166. for (i = 0; i < fw_src->count && i < MEI_FW_STATUS_MAX; i++) {
  167. ret = pci_read_config_dword(pdev, fw_src->status[i],
  168. &fw_status->status[i]);
  169. trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HSF_X",
  170. fw_src->status[i],
  171. fw_status->status[i]);
  172. if (ret)
  173. return ret;
  174. }
  175. return 0;
  176. }
  177. /**
  178. * mei_me_hw_config - configure hw dependent settings
  179. *
  180. * @dev: mei device
  181. */
  182. static void mei_me_hw_config(struct mei_device *dev)
  183. {
  184. struct pci_dev *pdev = to_pci_dev(dev->dev);
  185. struct mei_me_hw *hw = to_me_hw(dev);
  186. u32 hcsr, reg;
  187. /* Doesn't change in runtime */
  188. hcsr = mei_hcsr_read(dev);
  189. dev->hbuf_depth = (hcsr & H_CBD) >> 24;
  190. reg = 0;
  191. pci_read_config_dword(pdev, PCI_CFG_HFS_1, &reg);
  192. trace_mei_pci_cfg_read(dev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg);
  193. hw->d0i3_supported =
  194. ((reg & PCI_CFG_HFS_1_D0I3_MSK) == PCI_CFG_HFS_1_D0I3_MSK);
  195. hw->pg_state = MEI_PG_OFF;
  196. if (hw->d0i3_supported) {
  197. reg = mei_me_d0i3c_read(dev);
  198. if (reg & H_D0I3C_I3)
  199. hw->pg_state = MEI_PG_ON;
  200. }
  201. }
  202. /**
  203. * mei_me_pg_state - translate internal pg state
  204. * to the mei power gating state
  205. *
  206. * @dev: mei device
  207. *
  208. * Return: MEI_PG_OFF if aliveness is on and MEI_PG_ON otherwise
  209. */
  210. static inline enum mei_pg_state mei_me_pg_state(struct mei_device *dev)
  211. {
  212. struct mei_me_hw *hw = to_me_hw(dev);
  213. return hw->pg_state;
  214. }
  215. /**
  216. * mei_me_intr_clear - clear and stop interrupts
  217. *
  218. * @dev: the device structure
  219. */
  220. static void mei_me_intr_clear(struct mei_device *dev)
  221. {
  222. u32 hcsr = mei_hcsr_read(dev);
  223. if (hcsr & H_CSR_IS_MASK)
  224. mei_hcsr_write(dev, hcsr);
  225. }
  226. /**
  227. * mei_me_intr_enable - enables mei device interrupts
  228. *
  229. * @dev: the device structure
  230. */
  231. static void mei_me_intr_enable(struct mei_device *dev)
  232. {
  233. u32 hcsr = mei_hcsr_read(dev);
  234. hcsr |= H_CSR_IE_MASK;
  235. mei_hcsr_set(dev, hcsr);
  236. }
  237. /**
  238. * mei_me_intr_disable - disables mei device interrupts
  239. *
  240. * @dev: the device structure
  241. */
  242. static void mei_me_intr_disable(struct mei_device *dev)
  243. {
  244. u32 hcsr = mei_hcsr_read(dev);
  245. hcsr &= ~H_CSR_IE_MASK;
  246. mei_hcsr_set(dev, hcsr);
  247. }
  248. /**
  249. * mei_me_hw_reset_release - release device from the reset
  250. *
  251. * @dev: the device structure
  252. */
  253. static void mei_me_hw_reset_release(struct mei_device *dev)
  254. {
  255. u32 hcsr = mei_hcsr_read(dev);
  256. hcsr |= H_IG;
  257. hcsr &= ~H_RST;
  258. mei_hcsr_set(dev, hcsr);
  259. /* complete this write before we set host ready on another CPU */
  260. mmiowb();
  261. }
  262. /**
  263. * mei_me_host_set_ready - enable device
  264. *
  265. * @dev: mei device
  266. */
  267. static void mei_me_host_set_ready(struct mei_device *dev)
  268. {
  269. u32 hcsr = mei_hcsr_read(dev);
  270. hcsr |= H_CSR_IE_MASK | H_IG | H_RDY;
  271. mei_hcsr_set(dev, hcsr);
  272. }
  273. /**
  274. * mei_me_host_is_ready - check whether the host has turned ready
  275. *
  276. * @dev: mei device
  277. * Return: bool
  278. */
  279. static bool mei_me_host_is_ready(struct mei_device *dev)
  280. {
  281. u32 hcsr = mei_hcsr_read(dev);
  282. return (hcsr & H_RDY) == H_RDY;
  283. }
  284. /**
  285. * mei_me_hw_is_ready - check whether the me(hw) has turned ready
  286. *
  287. * @dev: mei device
  288. * Return: bool
  289. */
  290. static bool mei_me_hw_is_ready(struct mei_device *dev)
  291. {
  292. u32 mecsr = mei_me_mecsr_read(dev);
  293. return (mecsr & ME_RDY_HRA) == ME_RDY_HRA;
  294. }
  295. /**
  296. * mei_me_hw_ready_wait - wait until the me(hw) has turned ready
  297. * or timeout is reached
  298. *
  299. * @dev: mei device
  300. * Return: 0 on success, error otherwise
  301. */
  302. static int mei_me_hw_ready_wait(struct mei_device *dev)
  303. {
  304. mutex_unlock(&dev->device_lock);
  305. wait_event_timeout(dev->wait_hw_ready,
  306. dev->recvd_hw_ready,
  307. mei_secs_to_jiffies(MEI_HW_READY_TIMEOUT));
  308. mutex_lock(&dev->device_lock);
  309. if (!dev->recvd_hw_ready) {
  310. dev_err(dev->dev, "wait hw ready failed\n");
  311. return -ETIME;
  312. }
  313. mei_me_hw_reset_release(dev);
  314. dev->recvd_hw_ready = false;
  315. return 0;
  316. }
  317. /**
  318. * mei_me_hw_start - hw start routine
  319. *
  320. * @dev: mei device
  321. * Return: 0 on success, error otherwise
  322. */
  323. static int mei_me_hw_start(struct mei_device *dev)
  324. {
  325. int ret = mei_me_hw_ready_wait(dev);
  326. if (ret)
  327. return ret;
  328. dev_dbg(dev->dev, "hw is ready\n");
  329. mei_me_host_set_ready(dev);
  330. return ret;
  331. }
  332. /**
  333. * mei_hbuf_filled_slots - gets number of device filled buffer slots
  334. *
  335. * @dev: the device structure
  336. *
  337. * Return: number of filled slots
  338. */
  339. static unsigned char mei_hbuf_filled_slots(struct mei_device *dev)
  340. {
  341. u32 hcsr;
  342. char read_ptr, write_ptr;
  343. hcsr = mei_hcsr_read(dev);
  344. read_ptr = (char) ((hcsr & H_CBRP) >> 8);
  345. write_ptr = (char) ((hcsr & H_CBWP) >> 16);
  346. return (unsigned char) (write_ptr - read_ptr);
  347. }
  348. /**
  349. * mei_me_hbuf_is_empty - checks if host buffer is empty.
  350. *
  351. * @dev: the device structure
  352. *
  353. * Return: true if empty, false - otherwise.
  354. */
  355. static bool mei_me_hbuf_is_empty(struct mei_device *dev)
  356. {
  357. return mei_hbuf_filled_slots(dev) == 0;
  358. }
  359. /**
  360. * mei_me_hbuf_empty_slots - counts write empty slots.
  361. *
  362. * @dev: the device structure
  363. *
  364. * Return: -EOVERFLOW if overflow, otherwise empty slots count
  365. */
  366. static int mei_me_hbuf_empty_slots(struct mei_device *dev)
  367. {
  368. unsigned char filled_slots, empty_slots;
  369. filled_slots = mei_hbuf_filled_slots(dev);
  370. empty_slots = dev->hbuf_depth - filled_slots;
  371. /* check for overflow */
  372. if (filled_slots > dev->hbuf_depth)
  373. return -EOVERFLOW;
  374. return empty_slots;
  375. }
  376. /**
  377. * mei_me_hbuf_max_len - returns size of hw buffer.
  378. *
  379. * @dev: the device structure
  380. *
  381. * Return: size of hw buffer in bytes
  382. */
  383. static size_t mei_me_hbuf_max_len(const struct mei_device *dev)
  384. {
  385. return dev->hbuf_depth * sizeof(u32) - sizeof(struct mei_msg_hdr);
  386. }
  387. /**
  388. * mei_me_write_message - writes a message to mei device.
  389. *
  390. * @dev: the device structure
  391. * @header: mei HECI header of message
  392. * @buf: message payload will be written
  393. *
  394. * Return: -EIO if write has failed
  395. */
  396. static int mei_me_write_message(struct mei_device *dev,
  397. struct mei_msg_hdr *header,
  398. unsigned char *buf)
  399. {
  400. unsigned long rem;
  401. unsigned long length = header->length;
  402. u32 *reg_buf = (u32 *)buf;
  403. u32 hcsr;
  404. u32 dw_cnt;
  405. int i;
  406. int empty_slots;
  407. dev_dbg(dev->dev, MEI_HDR_FMT, MEI_HDR_PRM(header));
  408. empty_slots = mei_hbuf_empty_slots(dev);
  409. dev_dbg(dev->dev, "empty slots = %hu.\n", empty_slots);
  410. dw_cnt = mei_data2slots(length);
  411. if (empty_slots < 0 || dw_cnt > empty_slots)
  412. return -EMSGSIZE;
  413. mei_me_hcbww_write(dev, *((u32 *) header));
  414. for (i = 0; i < length / 4; i++)
  415. mei_me_hcbww_write(dev, reg_buf[i]);
  416. rem = length & 0x3;
  417. if (rem > 0) {
  418. u32 reg = 0;
  419. memcpy(&reg, &buf[length - rem], rem);
  420. mei_me_hcbww_write(dev, reg);
  421. }
  422. hcsr = mei_hcsr_read(dev) | H_IG;
  423. mei_hcsr_set(dev, hcsr);
  424. if (!mei_me_hw_is_ready(dev))
  425. return -EIO;
  426. return 0;
  427. }
  428. /**
  429. * mei_me_count_full_read_slots - counts read full slots.
  430. *
  431. * @dev: the device structure
  432. *
  433. * Return: -EOVERFLOW if overflow, otherwise filled slots count
  434. */
  435. static int mei_me_count_full_read_slots(struct mei_device *dev)
  436. {
  437. u32 me_csr;
  438. char read_ptr, write_ptr;
  439. unsigned char buffer_depth, filled_slots;
  440. me_csr = mei_me_mecsr_read(dev);
  441. buffer_depth = (unsigned char)((me_csr & ME_CBD_HRA) >> 24);
  442. read_ptr = (char) ((me_csr & ME_CBRP_HRA) >> 8);
  443. write_ptr = (char) ((me_csr & ME_CBWP_HRA) >> 16);
  444. filled_slots = (unsigned char) (write_ptr - read_ptr);
  445. /* check for overflow */
  446. if (filled_slots > buffer_depth)
  447. return -EOVERFLOW;
  448. dev_dbg(dev->dev, "filled_slots =%08x\n", filled_slots);
  449. return (int)filled_slots;
  450. }
  451. /**
  452. * mei_me_read_slots - reads a message from mei device.
  453. *
  454. * @dev: the device structure
  455. * @buffer: message buffer will be written
  456. * @buffer_length: message size will be read
  457. *
  458. * Return: always 0
  459. */
  460. static int mei_me_read_slots(struct mei_device *dev, unsigned char *buffer,
  461. unsigned long buffer_length)
  462. {
  463. u32 *reg_buf = (u32 *)buffer;
  464. u32 hcsr;
  465. for (; buffer_length >= sizeof(u32); buffer_length -= sizeof(u32))
  466. *reg_buf++ = mei_me_mecbrw_read(dev);
  467. if (buffer_length > 0) {
  468. u32 reg = mei_me_mecbrw_read(dev);
  469. memcpy(reg_buf, &reg, buffer_length);
  470. }
  471. hcsr = mei_hcsr_read(dev) | H_IG;
  472. mei_hcsr_set(dev, hcsr);
  473. return 0;
  474. }
  475. /**
  476. * mei_me_pg_set - write pg enter register
  477. *
  478. * @dev: the device structure
  479. */
  480. static void mei_me_pg_set(struct mei_device *dev)
  481. {
  482. struct mei_me_hw *hw = to_me_hw(dev);
  483. u32 reg;
  484. reg = mei_me_reg_read(hw, H_HPG_CSR);
  485. trace_mei_reg_read(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
  486. reg |= H_HPG_CSR_PGI;
  487. trace_mei_reg_write(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
  488. mei_me_reg_write(hw, H_HPG_CSR, reg);
  489. }
  490. /**
  491. * mei_me_pg_unset - write pg exit register
  492. *
  493. * @dev: the device structure
  494. */
  495. static void mei_me_pg_unset(struct mei_device *dev)
  496. {
  497. struct mei_me_hw *hw = to_me_hw(dev);
  498. u32 reg;
  499. reg = mei_me_reg_read(hw, H_HPG_CSR);
  500. trace_mei_reg_read(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
  501. WARN(!(reg & H_HPG_CSR_PGI), "PGI is not set\n");
  502. reg |= H_HPG_CSR_PGIHEXR;
  503. trace_mei_reg_write(dev->dev, "H_HPG_CSR", H_HPG_CSR, reg);
  504. mei_me_reg_write(hw, H_HPG_CSR, reg);
  505. }
  506. /**
  507. * mei_me_pg_legacy_enter_sync - perform legacy pg entry procedure
  508. *
  509. * @dev: the device structure
  510. *
  511. * Return: 0 on success an error code otherwise
  512. */
  513. static int mei_me_pg_legacy_enter_sync(struct mei_device *dev)
  514. {
  515. struct mei_me_hw *hw = to_me_hw(dev);
  516. unsigned long timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT);
  517. int ret;
  518. dev->pg_event = MEI_PG_EVENT_WAIT;
  519. ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_ENTRY_REQ_CMD);
  520. if (ret)
  521. return ret;
  522. mutex_unlock(&dev->device_lock);
  523. wait_event_timeout(dev->wait_pg,
  524. dev->pg_event == MEI_PG_EVENT_RECEIVED, timeout);
  525. mutex_lock(&dev->device_lock);
  526. if (dev->pg_event == MEI_PG_EVENT_RECEIVED) {
  527. mei_me_pg_set(dev);
  528. ret = 0;
  529. } else {
  530. ret = -ETIME;
  531. }
  532. dev->pg_event = MEI_PG_EVENT_IDLE;
  533. hw->pg_state = MEI_PG_ON;
  534. return ret;
  535. }
  536. /**
  537. * mei_me_pg_legacy_exit_sync - perform legacy pg exit procedure
  538. *
  539. * @dev: the device structure
  540. *
  541. * Return: 0 on success an error code otherwise
  542. */
  543. static int mei_me_pg_legacy_exit_sync(struct mei_device *dev)
  544. {
  545. struct mei_me_hw *hw = to_me_hw(dev);
  546. unsigned long timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT);
  547. int ret;
  548. if (dev->pg_event == MEI_PG_EVENT_RECEIVED)
  549. goto reply;
  550. dev->pg_event = MEI_PG_EVENT_WAIT;
  551. mei_me_pg_unset(dev);
  552. mutex_unlock(&dev->device_lock);
  553. wait_event_timeout(dev->wait_pg,
  554. dev->pg_event == MEI_PG_EVENT_RECEIVED, timeout);
  555. mutex_lock(&dev->device_lock);
  556. reply:
  557. if (dev->pg_event != MEI_PG_EVENT_RECEIVED) {
  558. ret = -ETIME;
  559. goto out;
  560. }
  561. dev->pg_event = MEI_PG_EVENT_INTR_WAIT;
  562. ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_EXIT_RES_CMD);
  563. if (ret)
  564. return ret;
  565. mutex_unlock(&dev->device_lock);
  566. wait_event_timeout(dev->wait_pg,
  567. dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED, timeout);
  568. mutex_lock(&dev->device_lock);
  569. if (dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED)
  570. ret = 0;
  571. else
  572. ret = -ETIME;
  573. out:
  574. dev->pg_event = MEI_PG_EVENT_IDLE;
  575. hw->pg_state = MEI_PG_OFF;
  576. return ret;
  577. }
  578. /**
  579. * mei_me_pg_in_transition - is device now in pg transition
  580. *
  581. * @dev: the device structure
  582. *
  583. * Return: true if in pg transition, false otherwise
  584. */
  585. static bool mei_me_pg_in_transition(struct mei_device *dev)
  586. {
  587. return dev->pg_event >= MEI_PG_EVENT_WAIT &&
  588. dev->pg_event <= MEI_PG_EVENT_INTR_WAIT;
  589. }
  590. /**
  591. * mei_me_pg_is_enabled - detect if PG is supported by HW
  592. *
  593. * @dev: the device structure
  594. *
  595. * Return: true is pg supported, false otherwise
  596. */
  597. static bool mei_me_pg_is_enabled(struct mei_device *dev)
  598. {
  599. struct mei_me_hw *hw = to_me_hw(dev);
  600. u32 reg = mei_me_mecsr_read(dev);
  601. if (hw->d0i3_supported)
  602. return true;
  603. if ((reg & ME_PGIC_HRA) == 0)
  604. goto notsupported;
  605. if (!dev->hbm_f_pg_supported)
  606. goto notsupported;
  607. return true;
  608. notsupported:
  609. dev_dbg(dev->dev, "pg: not supported: d0i3 = %d HGP = %d hbm version %d.%d ?= %d.%d\n",
  610. hw->d0i3_supported,
  611. !!(reg & ME_PGIC_HRA),
  612. dev->version.major_version,
  613. dev->version.minor_version,
  614. HBM_MAJOR_VERSION_PGI,
  615. HBM_MINOR_VERSION_PGI);
  616. return false;
  617. }
  618. /**
  619. * mei_me_d0i3_set - write d0i3 register bit on mei device.
  620. *
  621. * @dev: the device structure
  622. * @intr: ask for interrupt
  623. *
  624. * Return: D0I3C register value
  625. */
  626. static u32 mei_me_d0i3_set(struct mei_device *dev, bool intr)
  627. {
  628. u32 reg = mei_me_d0i3c_read(dev);
  629. reg |= H_D0I3C_I3;
  630. if (intr)
  631. reg |= H_D0I3C_IR;
  632. else
  633. reg &= ~H_D0I3C_IR;
  634. mei_me_d0i3c_write(dev, reg);
  635. /* read it to ensure HW consistency */
  636. reg = mei_me_d0i3c_read(dev);
  637. return reg;
  638. }
  639. /**
  640. * mei_me_d0i3_unset - clean d0i3 register bit on mei device.
  641. *
  642. * @dev: the device structure
  643. *
  644. * Return: D0I3C register value
  645. */
  646. static u32 mei_me_d0i3_unset(struct mei_device *dev)
  647. {
  648. u32 reg = mei_me_d0i3c_read(dev);
  649. reg &= ~H_D0I3C_I3;
  650. reg |= H_D0I3C_IR;
  651. mei_me_d0i3c_write(dev, reg);
  652. /* read it to ensure HW consistency */
  653. reg = mei_me_d0i3c_read(dev);
  654. return reg;
  655. }
  656. /**
  657. * mei_me_d0i3_enter_sync - perform d0i3 entry procedure
  658. *
  659. * @dev: the device structure
  660. *
  661. * Return: 0 on success an error code otherwise
  662. */
  663. static int mei_me_d0i3_enter_sync(struct mei_device *dev)
  664. {
  665. struct mei_me_hw *hw = to_me_hw(dev);
  666. unsigned long d0i3_timeout = mei_secs_to_jiffies(MEI_D0I3_TIMEOUT);
  667. unsigned long pgi_timeout = mei_secs_to_jiffies(MEI_PGI_TIMEOUT);
  668. int ret;
  669. u32 reg;
  670. reg = mei_me_d0i3c_read(dev);
  671. if (reg & H_D0I3C_I3) {
  672. /* we are in d0i3, nothing to do */
  673. dev_dbg(dev->dev, "d0i3 set not needed\n");
  674. ret = 0;
  675. goto on;
  676. }
  677. /* PGI entry procedure */
  678. dev->pg_event = MEI_PG_EVENT_WAIT;
  679. ret = mei_hbm_pg(dev, MEI_PG_ISOLATION_ENTRY_REQ_CMD);
  680. if (ret)
  681. /* FIXME: should we reset here? */
  682. goto out;
  683. mutex_unlock(&dev->device_lock);
  684. wait_event_timeout(dev->wait_pg,
  685. dev->pg_event == MEI_PG_EVENT_RECEIVED, pgi_timeout);
  686. mutex_lock(&dev->device_lock);
  687. if (dev->pg_event != MEI_PG_EVENT_RECEIVED) {
  688. ret = -ETIME;
  689. goto out;
  690. }
  691. /* end PGI entry procedure */
  692. dev->pg_event = MEI_PG_EVENT_INTR_WAIT;
  693. reg = mei_me_d0i3_set(dev, true);
  694. if (!(reg & H_D0I3C_CIP)) {
  695. dev_dbg(dev->dev, "d0i3 enter wait not needed\n");
  696. ret = 0;
  697. goto on;
  698. }
  699. mutex_unlock(&dev->device_lock);
  700. wait_event_timeout(dev->wait_pg,
  701. dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED, d0i3_timeout);
  702. mutex_lock(&dev->device_lock);
  703. if (dev->pg_event != MEI_PG_EVENT_INTR_RECEIVED) {
  704. reg = mei_me_d0i3c_read(dev);
  705. if (!(reg & H_D0I3C_I3)) {
  706. ret = -ETIME;
  707. goto out;
  708. }
  709. }
  710. ret = 0;
  711. on:
  712. hw->pg_state = MEI_PG_ON;
  713. out:
  714. dev->pg_event = MEI_PG_EVENT_IDLE;
  715. dev_dbg(dev->dev, "d0i3 enter ret = %d\n", ret);
  716. return ret;
  717. }
  718. /**
  719. * mei_me_d0i3_enter - perform d0i3 entry procedure
  720. * no hbm PG handshake
  721. * no waiting for confirmation; runs with interrupts
  722. * disabled
  723. *
  724. * @dev: the device structure
  725. *
  726. * Return: 0 on success an error code otherwise
  727. */
  728. static int mei_me_d0i3_enter(struct mei_device *dev)
  729. {
  730. struct mei_me_hw *hw = to_me_hw(dev);
  731. u32 reg;
  732. reg = mei_me_d0i3c_read(dev);
  733. if (reg & H_D0I3C_I3) {
  734. /* we are in d0i3, nothing to do */
  735. dev_dbg(dev->dev, "already d0i3 : set not needed\n");
  736. goto on;
  737. }
  738. mei_me_d0i3_set(dev, false);
  739. on:
  740. hw->pg_state = MEI_PG_ON;
  741. dev->pg_event = MEI_PG_EVENT_IDLE;
  742. dev_dbg(dev->dev, "d0i3 enter\n");
  743. return 0;
  744. }
  745. /**
  746. * mei_me_d0i3_exit_sync - perform d0i3 exit procedure
  747. *
  748. * @dev: the device structure
  749. *
  750. * Return: 0 on success an error code otherwise
  751. */
  752. static int mei_me_d0i3_exit_sync(struct mei_device *dev)
  753. {
  754. struct mei_me_hw *hw = to_me_hw(dev);
  755. unsigned long timeout = mei_secs_to_jiffies(MEI_D0I3_TIMEOUT);
  756. int ret;
  757. u32 reg;
  758. dev->pg_event = MEI_PG_EVENT_INTR_WAIT;
  759. reg = mei_me_d0i3c_read(dev);
  760. if (!(reg & H_D0I3C_I3)) {
  761. /* we are not in d0i3, nothing to do */
  762. dev_dbg(dev->dev, "d0i3 exit not needed\n");
  763. ret = 0;
  764. goto off;
  765. }
  766. reg = mei_me_d0i3_unset(dev);
  767. if (!(reg & H_D0I3C_CIP)) {
  768. dev_dbg(dev->dev, "d0i3 exit wait not needed\n");
  769. ret = 0;
  770. goto off;
  771. }
  772. mutex_unlock(&dev->device_lock);
  773. wait_event_timeout(dev->wait_pg,
  774. dev->pg_event == MEI_PG_EVENT_INTR_RECEIVED, timeout);
  775. mutex_lock(&dev->device_lock);
  776. if (dev->pg_event != MEI_PG_EVENT_INTR_RECEIVED) {
  777. reg = mei_me_d0i3c_read(dev);
  778. if (reg & H_D0I3C_I3) {
  779. ret = -ETIME;
  780. goto out;
  781. }
  782. }
  783. ret = 0;
  784. off:
  785. hw->pg_state = MEI_PG_OFF;
  786. out:
  787. dev->pg_event = MEI_PG_EVENT_IDLE;
  788. dev_dbg(dev->dev, "d0i3 exit ret = %d\n", ret);
  789. return ret;
  790. }
  791. /**
  792. * mei_me_pg_legacy_intr - perform legacy pg processing
  793. * in interrupt thread handler
  794. *
  795. * @dev: the device structure
  796. */
  797. static void mei_me_pg_legacy_intr(struct mei_device *dev)
  798. {
  799. struct mei_me_hw *hw = to_me_hw(dev);
  800. if (dev->pg_event != MEI_PG_EVENT_INTR_WAIT)
  801. return;
  802. dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED;
  803. hw->pg_state = MEI_PG_OFF;
  804. if (waitqueue_active(&dev->wait_pg))
  805. wake_up(&dev->wait_pg);
  806. }
  807. /**
  808. * mei_me_d0i3_intr - perform d0i3 processing in interrupt thread handler
  809. *
  810. * @dev: the device structure
  811. */
  812. static void mei_me_d0i3_intr(struct mei_device *dev)
  813. {
  814. struct mei_me_hw *hw = to_me_hw(dev);
  815. if (dev->pg_event == MEI_PG_EVENT_INTR_WAIT &&
  816. (hw->intr_source & H_D0I3C_IS)) {
  817. dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED;
  818. if (hw->pg_state == MEI_PG_ON) {
  819. hw->pg_state = MEI_PG_OFF;
  820. if (dev->hbm_state != MEI_HBM_IDLE) {
  821. /*
  822. * force H_RDY because it could be
  823. * wiped off during PG
  824. */
  825. dev_dbg(dev->dev, "d0i3 set host ready\n");
  826. mei_me_host_set_ready(dev);
  827. }
  828. } else {
  829. hw->pg_state = MEI_PG_ON;
  830. }
  831. wake_up(&dev->wait_pg);
  832. }
  833. if (hw->pg_state == MEI_PG_ON && (hw->intr_source & H_IS)) {
  834. /*
  835. * HW sent some data and we are in D0i3, so
  836. * we got here because of HW initiated exit from D0i3.
  837. * Start runtime pm resume sequence to exit low power state.
  838. */
  839. dev_dbg(dev->dev, "d0i3 want resume\n");
  840. mei_hbm_pg_resume(dev);
  841. }
  842. }
  843. /**
  844. * mei_me_pg_intr - perform pg processing in interrupt thread handler
  845. *
  846. * @dev: the device structure
  847. */
  848. static void mei_me_pg_intr(struct mei_device *dev)
  849. {
  850. struct mei_me_hw *hw = to_me_hw(dev);
  851. if (hw->d0i3_supported)
  852. mei_me_d0i3_intr(dev);
  853. else
  854. mei_me_pg_legacy_intr(dev);
  855. }
  856. /**
  857. * mei_me_pg_enter_sync - perform runtime pm entry procedure
  858. *
  859. * @dev: the device structure
  860. *
  861. * Return: 0 on success an error code otherwise
  862. */
  863. int mei_me_pg_enter_sync(struct mei_device *dev)
  864. {
  865. struct mei_me_hw *hw = to_me_hw(dev);
  866. if (hw->d0i3_supported)
  867. return mei_me_d0i3_enter_sync(dev);
  868. else
  869. return mei_me_pg_legacy_enter_sync(dev);
  870. }
  871. /**
  872. * mei_me_pg_exit_sync - perform runtime pm exit procedure
  873. *
  874. * @dev: the device structure
  875. *
  876. * Return: 0 on success an error code otherwise
  877. */
  878. int mei_me_pg_exit_sync(struct mei_device *dev)
  879. {
  880. struct mei_me_hw *hw = to_me_hw(dev);
  881. if (hw->d0i3_supported)
  882. return mei_me_d0i3_exit_sync(dev);
  883. else
  884. return mei_me_pg_legacy_exit_sync(dev);
  885. }
  886. /**
  887. * mei_me_hw_reset - resets fw via mei csr register.
  888. *
  889. * @dev: the device structure
  890. * @intr_enable: if interrupt should be enabled after reset.
  891. *
  892. * Return: 0 on success an error code otherwise
  893. */
  894. static int mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
  895. {
  896. struct mei_me_hw *hw = to_me_hw(dev);
  897. int ret;
  898. u32 hcsr;
  899. if (intr_enable) {
  900. mei_me_intr_enable(dev);
  901. if (hw->d0i3_supported) {
  902. ret = mei_me_d0i3_exit_sync(dev);
  903. if (ret)
  904. return ret;
  905. }
  906. }
  907. hcsr = mei_hcsr_read(dev);
  908. /* H_RST may be found lit before reset is started,
  909. * for example if preceding reset flow hasn't completed.
  910. * In that case asserting H_RST will be ignored, therefore
  911. * we need to clean H_RST bit to start a successful reset sequence.
  912. */
  913. if ((hcsr & H_RST) == H_RST) {
  914. dev_warn(dev->dev, "H_RST is set = 0x%08X", hcsr);
  915. hcsr &= ~H_RST;
  916. mei_hcsr_set(dev, hcsr);
  917. hcsr = mei_hcsr_read(dev);
  918. }
  919. hcsr |= H_RST | H_IG | H_CSR_IS_MASK;
  920. if (!intr_enable)
  921. hcsr &= ~H_CSR_IE_MASK;
  922. dev->recvd_hw_ready = false;
  923. mei_hcsr_write(dev, hcsr);
  924. /*
  925. * Host reads the H_CSR once to ensure that the
  926. * posted write to H_CSR completes.
  927. */
  928. hcsr = mei_hcsr_read(dev);
  929. if ((hcsr & H_RST) == 0)
  930. dev_warn(dev->dev, "H_RST is not set = 0x%08X", hcsr);
  931. if ((hcsr & H_RDY) == H_RDY)
  932. dev_warn(dev->dev, "H_RDY is not cleared 0x%08X", hcsr);
  933. if (!intr_enable) {
  934. mei_me_hw_reset_release(dev);
  935. if (hw->d0i3_supported) {
  936. ret = mei_me_d0i3_enter(dev);
  937. if (ret)
  938. return ret;
  939. }
  940. }
  941. return 0;
  942. }
  943. /**
  944. * mei_me_irq_quick_handler - The ISR of the MEI device
  945. *
  946. * @irq: The irq number
  947. * @dev_id: pointer to the device structure
  948. *
  949. * Return: irqreturn_t
  950. */
  951. irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id)
  952. {
  953. struct mei_device *dev = (struct mei_device *)dev_id;
  954. struct mei_me_hw *hw = to_me_hw(dev);
  955. u32 hcsr;
  956. hcsr = mei_hcsr_read(dev);
  957. if (!(hcsr & H_CSR_IS_MASK))
  958. return IRQ_NONE;
  959. hw->intr_source = hcsr & H_CSR_IS_MASK;
  960. dev_dbg(dev->dev, "interrupt source 0x%08X.\n", hw->intr_source);
  961. /* clear H_IS and H_D0I3C_IS bits in H_CSR to clear the interrupts */
  962. mei_hcsr_write(dev, hcsr);
  963. return IRQ_WAKE_THREAD;
  964. }
  965. /**
  966. * mei_me_irq_thread_handler - function called after ISR to handle the interrupt
  967. * processing.
  968. *
  969. * @irq: The irq number
  970. * @dev_id: pointer to the device structure
  971. *
  972. * Return: irqreturn_t
  973. *
  974. */
  975. irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
  976. {
  977. struct mei_device *dev = (struct mei_device *) dev_id;
  978. struct mei_cl_cb complete_list;
  979. s32 slots;
  980. int rets = 0;
  981. dev_dbg(dev->dev, "function called after ISR to handle the interrupt processing.\n");
  982. /* initialize our complete list */
  983. mutex_lock(&dev->device_lock);
  984. mei_io_list_init(&complete_list);
  985. /* check if ME wants a reset */
  986. if (!mei_hw_is_ready(dev) && dev->dev_state != MEI_DEV_RESETTING) {
  987. dev_warn(dev->dev, "FW not ready: resetting.\n");
  988. schedule_work(&dev->reset_work);
  989. goto end;
  990. }
  991. mei_me_pg_intr(dev);
  992. /* check if we need to start the dev */
  993. if (!mei_host_is_ready(dev)) {
  994. if (mei_hw_is_ready(dev)) {
  995. dev_dbg(dev->dev, "we need to start the dev.\n");
  996. dev->recvd_hw_ready = true;
  997. wake_up(&dev->wait_hw_ready);
  998. } else {
  999. dev_dbg(dev->dev, "Spurious Interrupt\n");
  1000. }
  1001. goto end;
  1002. }
  1003. /* check slots available for reading */
  1004. slots = mei_count_full_read_slots(dev);
  1005. while (slots > 0) {
  1006. dev_dbg(dev->dev, "slots to read = %08x\n", slots);
  1007. rets = mei_irq_read_handler(dev, &complete_list, &slots);
  1008. /* There is a race between ME write and interrupt delivery:
  1009. * Not all data is always available immediately after the
  1010. * interrupt, so try to read again on the next interrupt.
  1011. */
  1012. if (rets == -ENODATA)
  1013. break;
  1014. if (rets && dev->dev_state != MEI_DEV_RESETTING) {
  1015. dev_err(dev->dev, "mei_irq_read_handler ret = %d.\n",
  1016. rets);
  1017. schedule_work(&dev->reset_work);
  1018. goto end;
  1019. }
  1020. }
  1021. dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
  1022. /*
  1023. * During PG handshake only allowed write is the replay to the
  1024. * PG exit message, so block calling write function
  1025. * if the pg event is in PG handshake
  1026. */
  1027. if (dev->pg_event != MEI_PG_EVENT_WAIT &&
  1028. dev->pg_event != MEI_PG_EVENT_RECEIVED) {
  1029. rets = mei_irq_write_handler(dev, &complete_list);
  1030. dev->hbuf_is_ready = mei_hbuf_is_ready(dev);
  1031. }
  1032. mei_irq_compl_handler(dev, &complete_list);
  1033. end:
  1034. dev_dbg(dev->dev, "interrupt thread end ret = %d\n", rets);
  1035. mutex_unlock(&dev->device_lock);
  1036. return IRQ_HANDLED;
  1037. }
  1038. static const struct mei_hw_ops mei_me_hw_ops = {
  1039. .fw_status = mei_me_fw_status,
  1040. .pg_state = mei_me_pg_state,
  1041. .host_is_ready = mei_me_host_is_ready,
  1042. .hw_is_ready = mei_me_hw_is_ready,
  1043. .hw_reset = mei_me_hw_reset,
  1044. .hw_config = mei_me_hw_config,
  1045. .hw_start = mei_me_hw_start,
  1046. .pg_in_transition = mei_me_pg_in_transition,
  1047. .pg_is_enabled = mei_me_pg_is_enabled,
  1048. .intr_clear = mei_me_intr_clear,
  1049. .intr_enable = mei_me_intr_enable,
  1050. .intr_disable = mei_me_intr_disable,
  1051. .hbuf_free_slots = mei_me_hbuf_empty_slots,
  1052. .hbuf_is_ready = mei_me_hbuf_is_empty,
  1053. .hbuf_max_len = mei_me_hbuf_max_len,
  1054. .write = mei_me_write_message,
  1055. .rdbuf_full_slots = mei_me_count_full_read_slots,
  1056. .read_hdr = mei_me_mecbrw_read,
  1057. .read = mei_me_read_slots
  1058. };
  1059. static bool mei_me_fw_type_nm(struct pci_dev *pdev)
  1060. {
  1061. u32 reg;
  1062. pci_read_config_dword(pdev, PCI_CFG_HFS_2, &reg);
  1063. trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_2", PCI_CFG_HFS_2, reg);
  1064. /* make sure that bit 9 (NM) is up and bit 10 (DM) is down */
  1065. return (reg & 0x600) == 0x200;
  1066. }
  1067. #define MEI_CFG_FW_NM \
  1068. .quirk_probe = mei_me_fw_type_nm
  1069. static bool mei_me_fw_type_sps(struct pci_dev *pdev)
  1070. {
  1071. u32 reg;
  1072. /* Read ME FW Status check for SPS Firmware */
  1073. pci_read_config_dword(pdev, PCI_CFG_HFS_1, &reg);
  1074. trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg);
  1075. /* if bits [19:16] = 15, running SPS Firmware */
  1076. return (reg & 0xf0000) == 0xf0000;
  1077. }
  1078. #define MEI_CFG_FW_SPS \
  1079. .quirk_probe = mei_me_fw_type_sps
  1080. #define MEI_CFG_LEGACY_HFS \
  1081. .fw_status.count = 0
  1082. #define MEI_CFG_ICH_HFS \
  1083. .fw_status.count = 1, \
  1084. .fw_status.status[0] = PCI_CFG_HFS_1
  1085. #define MEI_CFG_PCH_HFS \
  1086. .fw_status.count = 2, \
  1087. .fw_status.status[0] = PCI_CFG_HFS_1, \
  1088. .fw_status.status[1] = PCI_CFG_HFS_2
  1089. #define MEI_CFG_PCH8_HFS \
  1090. .fw_status.count = 6, \
  1091. .fw_status.status[0] = PCI_CFG_HFS_1, \
  1092. .fw_status.status[1] = PCI_CFG_HFS_2, \
  1093. .fw_status.status[2] = PCI_CFG_HFS_3, \
  1094. .fw_status.status[3] = PCI_CFG_HFS_4, \
  1095. .fw_status.status[4] = PCI_CFG_HFS_5, \
  1096. .fw_status.status[5] = PCI_CFG_HFS_6
  1097. /* ICH Legacy devices */
  1098. const struct mei_cfg mei_me_legacy_cfg = {
  1099. MEI_CFG_LEGACY_HFS,
  1100. };
  1101. /* ICH devices */
  1102. const struct mei_cfg mei_me_ich_cfg = {
  1103. MEI_CFG_ICH_HFS,
  1104. };
  1105. /* PCH devices */
  1106. const struct mei_cfg mei_me_pch_cfg = {
  1107. MEI_CFG_PCH_HFS,
  1108. };
  1109. /* PCH Cougar Point and Patsburg with quirk for Node Manager exclusion */
  1110. const struct mei_cfg mei_me_pch_cpt_pbg_cfg = {
  1111. MEI_CFG_PCH_HFS,
  1112. MEI_CFG_FW_NM,
  1113. };
  1114. /* PCH8 Lynx Point and newer devices */
  1115. const struct mei_cfg mei_me_pch8_cfg = {
  1116. MEI_CFG_PCH8_HFS,
  1117. };
  1118. /* PCH8 Lynx Point with quirk for SPS Firmware exclusion */
  1119. const struct mei_cfg mei_me_pch8_sps_cfg = {
  1120. MEI_CFG_PCH8_HFS,
  1121. MEI_CFG_FW_SPS,
  1122. };
  1123. /**
  1124. * mei_me_dev_init - allocates and initializes the mei device structure
  1125. *
  1126. * @pdev: The pci device structure
  1127. * @cfg: per device generation config
  1128. *
  1129. * Return: The mei_device_device pointer on success, NULL on failure.
  1130. */
  1131. struct mei_device *mei_me_dev_init(struct pci_dev *pdev,
  1132. const struct mei_cfg *cfg)
  1133. {
  1134. struct mei_device *dev;
  1135. struct mei_me_hw *hw;
  1136. dev = kzalloc(sizeof(struct mei_device) +
  1137. sizeof(struct mei_me_hw), GFP_KERNEL);
  1138. if (!dev)
  1139. return NULL;
  1140. hw = to_me_hw(dev);
  1141. mei_device_init(dev, &pdev->dev, &mei_me_hw_ops);
  1142. hw->cfg = cfg;
  1143. return dev;
  1144. }