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