eeh_pseries.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. /*
  2. * The file intends to implement the platform dependent EEH operations on pseries.
  3. * Actually, the pseries platform is built based on RTAS heavily. That means the
  4. * pseries platform dependent EEH operations will be built on RTAS calls. The functions
  5. * are devired from arch/powerpc/platforms/pseries/eeh.c and necessary cleanup has
  6. * been done.
  7. *
  8. * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2011.
  9. * Copyright IBM Corporation 2001, 2005, 2006
  10. * Copyright Dave Engebretsen & Todd Inglett 2001
  11. * Copyright Linas Vepstas 2005, 2006
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #include <linux/atomic.h>
  28. #include <linux/delay.h>
  29. #include <linux/export.h>
  30. #include <linux/init.h>
  31. #include <linux/list.h>
  32. #include <linux/of.h>
  33. #include <linux/pci.h>
  34. #include <linux/proc_fs.h>
  35. #include <linux/rbtree.h>
  36. #include <linux/sched.h>
  37. #include <linux/seq_file.h>
  38. #include <linux/spinlock.h>
  39. #include <asm/eeh.h>
  40. #include <asm/eeh_event.h>
  41. #include <asm/io.h>
  42. #include <asm/machdep.h>
  43. #include <asm/ppc-pci.h>
  44. #include <asm/rtas.h>
  45. /* RTAS tokens */
  46. static int ibm_set_eeh_option;
  47. static int ibm_set_slot_reset;
  48. static int ibm_read_slot_reset_state;
  49. static int ibm_read_slot_reset_state2;
  50. static int ibm_slot_error_detail;
  51. static int ibm_get_config_addr_info;
  52. static int ibm_get_config_addr_info2;
  53. static int ibm_configure_bridge;
  54. static int ibm_configure_pe;
  55. /*
  56. * Buffer for reporting slot-error-detail rtas calls. Its here
  57. * in BSS, and not dynamically alloced, so that it ends up in
  58. * RMO where RTAS can access it.
  59. */
  60. static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX];
  61. static DEFINE_SPINLOCK(slot_errbuf_lock);
  62. static int eeh_error_buf_size;
  63. /**
  64. * pseries_eeh_init - EEH platform dependent initialization
  65. *
  66. * EEH platform dependent initialization on pseries.
  67. */
  68. static int pseries_eeh_init(void)
  69. {
  70. /* figure out EEH RTAS function call tokens */
  71. ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
  72. ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
  73. ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
  74. ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
  75. ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
  76. ibm_get_config_addr_info2 = rtas_token("ibm,get-config-addr-info2");
  77. ibm_get_config_addr_info = rtas_token("ibm,get-config-addr-info");
  78. ibm_configure_pe = rtas_token("ibm,configure-pe");
  79. ibm_configure_bridge = rtas_token("ibm,configure-bridge");
  80. /*
  81. * Necessary sanity check. We needn't check "get-config-addr-info"
  82. * and its variant since the old firmware probably support address
  83. * of domain/bus/slot/function for EEH RTAS operations.
  84. */
  85. if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE ||
  86. ibm_set_slot_reset == RTAS_UNKNOWN_SERVICE ||
  87. (ibm_read_slot_reset_state2 == RTAS_UNKNOWN_SERVICE &&
  88. ibm_read_slot_reset_state == RTAS_UNKNOWN_SERVICE) ||
  89. ibm_slot_error_detail == RTAS_UNKNOWN_SERVICE ||
  90. (ibm_configure_pe == RTAS_UNKNOWN_SERVICE &&
  91. ibm_configure_bridge == RTAS_UNKNOWN_SERVICE)) {
  92. pr_info("EEH functionality not supported\n");
  93. return -EINVAL;
  94. }
  95. /* Initialize error log lock and size */
  96. spin_lock_init(&slot_errbuf_lock);
  97. eeh_error_buf_size = rtas_token("rtas-error-log-max");
  98. if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
  99. pr_info("%s: unknown EEH error log size\n",
  100. __func__);
  101. eeh_error_buf_size = 1024;
  102. } else if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
  103. pr_info("%s: EEH error log size %d exceeds the maximal %d\n",
  104. __func__, eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
  105. eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
  106. }
  107. /* Set EEH probe mode */
  108. eeh_add_flag(EEH_PROBE_MODE_DEVTREE | EEH_ENABLE_IO_FOR_LOG);
  109. return 0;
  110. }
  111. static int pseries_eeh_cap_start(struct device_node *dn)
  112. {
  113. struct pci_dn *pdn = PCI_DN(dn);
  114. u32 status;
  115. if (!pdn)
  116. return 0;
  117. rtas_read_config(pdn, PCI_STATUS, 2, &status);
  118. if (!(status & PCI_STATUS_CAP_LIST))
  119. return 0;
  120. return PCI_CAPABILITY_LIST;
  121. }
  122. static int pseries_eeh_find_cap(struct device_node *dn, int cap)
  123. {
  124. struct pci_dn *pdn = PCI_DN(dn);
  125. int pos = pseries_eeh_cap_start(dn);
  126. int cnt = 48; /* Maximal number of capabilities */
  127. u32 id;
  128. if (!pos)
  129. return 0;
  130. while (cnt--) {
  131. rtas_read_config(pdn, pos, 1, &pos);
  132. if (pos < 0x40)
  133. break;
  134. pos &= ~3;
  135. rtas_read_config(pdn, pos + PCI_CAP_LIST_ID, 1, &id);
  136. if (id == 0xff)
  137. break;
  138. if (id == cap)
  139. return pos;
  140. pos += PCI_CAP_LIST_NEXT;
  141. }
  142. return 0;
  143. }
  144. static int pseries_eeh_find_ecap(struct device_node *dn, int cap)
  145. {
  146. struct pci_dn *pdn = PCI_DN(dn);
  147. struct eeh_dev *edev = of_node_to_eeh_dev(dn);
  148. u32 header;
  149. int pos = 256;
  150. int ttl = (4096 - 256) / 8;
  151. if (!edev || !edev->pcie_cap)
  152. return 0;
  153. if (rtas_read_config(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
  154. return 0;
  155. else if (!header)
  156. return 0;
  157. while (ttl-- > 0) {
  158. if (PCI_EXT_CAP_ID(header) == cap && pos)
  159. return pos;
  160. pos = PCI_EXT_CAP_NEXT(header);
  161. if (pos < 256)
  162. break;
  163. if (rtas_read_config(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
  164. break;
  165. }
  166. return 0;
  167. }
  168. /**
  169. * pseries_eeh_of_probe - EEH probe on the given device
  170. * @dn: OF node
  171. * @flag: Unused
  172. *
  173. * When EEH module is installed during system boot, all PCI devices
  174. * are checked one by one to see if it supports EEH. The function
  175. * is introduced for the purpose.
  176. */
  177. static void *pseries_eeh_of_probe(struct device_node *dn, void *flag)
  178. {
  179. struct eeh_dev *edev;
  180. struct eeh_pe pe;
  181. struct pci_dn *pdn = PCI_DN(dn);
  182. const __be32 *classp, *vendorp, *devicep;
  183. u32 class_code;
  184. const __be32 *regs;
  185. u32 pcie_flags;
  186. int enable = 0;
  187. int ret;
  188. /* Retrieve OF node and eeh device */
  189. edev = of_node_to_eeh_dev(dn);
  190. if (edev->pe || !of_device_is_available(dn))
  191. return NULL;
  192. /* Retrieve class/vendor/device IDs */
  193. classp = of_get_property(dn, "class-code", NULL);
  194. vendorp = of_get_property(dn, "vendor-id", NULL);
  195. devicep = of_get_property(dn, "device-id", NULL);
  196. /* Skip for bad OF node or PCI-ISA bridge */
  197. if (!classp || !vendorp || !devicep)
  198. return NULL;
  199. if (dn->type && !strcmp(dn->type, "isa"))
  200. return NULL;
  201. class_code = of_read_number(classp, 1);
  202. /*
  203. * Update class code and mode of eeh device. We need
  204. * correctly reflects that current device is root port
  205. * or PCIe switch downstream port.
  206. */
  207. edev->class_code = class_code;
  208. edev->pcix_cap = pseries_eeh_find_cap(dn, PCI_CAP_ID_PCIX);
  209. edev->pcie_cap = pseries_eeh_find_cap(dn, PCI_CAP_ID_EXP);
  210. edev->aer_cap = pseries_eeh_find_ecap(dn, PCI_EXT_CAP_ID_ERR);
  211. edev->mode &= 0xFFFFFF00;
  212. if ((edev->class_code >> 8) == PCI_CLASS_BRIDGE_PCI) {
  213. edev->mode |= EEH_DEV_BRIDGE;
  214. if (edev->pcie_cap) {
  215. rtas_read_config(pdn, edev->pcie_cap + PCI_EXP_FLAGS,
  216. 2, &pcie_flags);
  217. pcie_flags = (pcie_flags & PCI_EXP_FLAGS_TYPE) >> 4;
  218. if (pcie_flags == PCI_EXP_TYPE_ROOT_PORT)
  219. edev->mode |= EEH_DEV_ROOT_PORT;
  220. else if (pcie_flags == PCI_EXP_TYPE_DOWNSTREAM)
  221. edev->mode |= EEH_DEV_DS_PORT;
  222. }
  223. }
  224. /* Retrieve the device address */
  225. regs = of_get_property(dn, "reg", NULL);
  226. if (!regs) {
  227. pr_warn("%s: OF node property %s::reg not found\n",
  228. __func__, dn->full_name);
  229. return NULL;
  230. }
  231. /* Initialize the fake PE */
  232. memset(&pe, 0, sizeof(struct eeh_pe));
  233. pe.phb = edev->phb;
  234. pe.config_addr = of_read_number(regs, 1);
  235. /* Enable EEH on the device */
  236. ret = eeh_ops->set_option(&pe, EEH_OPT_ENABLE);
  237. if (!ret) {
  238. edev->config_addr = of_read_number(regs, 1);
  239. /* Retrieve PE address */
  240. edev->pe_config_addr = eeh_ops->get_pe_addr(&pe);
  241. pe.addr = edev->pe_config_addr;
  242. /* Some older systems (Power4) allow the ibm,set-eeh-option
  243. * call to succeed even on nodes where EEH is not supported.
  244. * Verify support explicitly.
  245. */
  246. ret = eeh_ops->get_state(&pe, NULL);
  247. if (ret > 0 && ret != EEH_STATE_NOT_SUPPORT)
  248. enable = 1;
  249. if (enable) {
  250. eeh_add_flag(EEH_ENABLED);
  251. eeh_add_to_parent_pe(edev);
  252. pr_debug("%s: EEH enabled on %s PHB#%d-PE#%x, config addr#%x\n",
  253. __func__, dn->full_name, pe.phb->global_number,
  254. pe.addr, pe.config_addr);
  255. } else if (dn->parent && of_node_to_eeh_dev(dn->parent) &&
  256. (of_node_to_eeh_dev(dn->parent))->pe) {
  257. /* This device doesn't support EEH, but it may have an
  258. * EEH parent, in which case we mark it as supported.
  259. */
  260. edev->config_addr = of_node_to_eeh_dev(dn->parent)->config_addr;
  261. edev->pe_config_addr = of_node_to_eeh_dev(dn->parent)->pe_config_addr;
  262. eeh_add_to_parent_pe(edev);
  263. }
  264. }
  265. /* Save memory bars */
  266. eeh_save_bars(edev);
  267. return NULL;
  268. }
  269. /**
  270. * pseries_eeh_set_option - Initialize EEH or MMIO/DMA reenable
  271. * @pe: EEH PE
  272. * @option: operation to be issued
  273. *
  274. * The function is used to control the EEH functionality globally.
  275. * Currently, following options are support according to PAPR:
  276. * Enable EEH, Disable EEH, Enable MMIO and Enable DMA
  277. */
  278. static int pseries_eeh_set_option(struct eeh_pe *pe, int option)
  279. {
  280. int ret = 0;
  281. int config_addr;
  282. /*
  283. * When we're enabling or disabling EEH functioality on
  284. * the particular PE, the PE config address is possibly
  285. * unavailable. Therefore, we have to figure it out from
  286. * the FDT node.
  287. */
  288. switch (option) {
  289. case EEH_OPT_DISABLE:
  290. case EEH_OPT_ENABLE:
  291. case EEH_OPT_THAW_MMIO:
  292. case EEH_OPT_THAW_DMA:
  293. config_addr = pe->config_addr;
  294. if (pe->addr)
  295. config_addr = pe->addr;
  296. break;
  297. case EEH_OPT_FREEZE_PE:
  298. /* Not support */
  299. return 0;
  300. default:
  301. pr_err("%s: Invalid option %d\n",
  302. __func__, option);
  303. return -EINVAL;
  304. }
  305. ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
  306. config_addr, BUID_HI(pe->phb->buid),
  307. BUID_LO(pe->phb->buid), option);
  308. return ret;
  309. }
  310. /**
  311. * pseries_eeh_get_pe_addr - Retrieve PE address
  312. * @pe: EEH PE
  313. *
  314. * Retrieve the assocated PE address. Actually, there're 2 RTAS
  315. * function calls dedicated for the purpose. We need implement
  316. * it through the new function and then the old one. Besides,
  317. * you should make sure the config address is figured out from
  318. * FDT node before calling the function.
  319. *
  320. * It's notable that zero'ed return value means invalid PE config
  321. * address.
  322. */
  323. static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
  324. {
  325. int ret = 0;
  326. int rets[3];
  327. if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) {
  328. /*
  329. * First of all, we need to make sure there has one PE
  330. * associated with the device. Otherwise, PE address is
  331. * meaningless.
  332. */
  333. ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
  334. pe->config_addr, BUID_HI(pe->phb->buid),
  335. BUID_LO(pe->phb->buid), 1);
  336. if (ret || (rets[0] == 0))
  337. return 0;
  338. /* Retrieve the associated PE config address */
  339. ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
  340. pe->config_addr, BUID_HI(pe->phb->buid),
  341. BUID_LO(pe->phb->buid), 0);
  342. if (ret) {
  343. pr_warn("%s: Failed to get address for PHB#%d-PE#%x\n",
  344. __func__, pe->phb->global_number, pe->config_addr);
  345. return 0;
  346. }
  347. return rets[0];
  348. }
  349. if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
  350. ret = rtas_call(ibm_get_config_addr_info, 4, 2, rets,
  351. pe->config_addr, BUID_HI(pe->phb->buid),
  352. BUID_LO(pe->phb->buid), 0);
  353. if (ret) {
  354. pr_warn("%s: Failed to get address for PHB#%d-PE#%x\n",
  355. __func__, pe->phb->global_number, pe->config_addr);
  356. return 0;
  357. }
  358. return rets[0];
  359. }
  360. return ret;
  361. }
  362. /**
  363. * pseries_eeh_get_state - Retrieve PE state
  364. * @pe: EEH PE
  365. * @state: return value
  366. *
  367. * Retrieve the state of the specified PE. On RTAS compliant
  368. * pseries platform, there already has one dedicated RTAS function
  369. * for the purpose. It's notable that the associated PE config address
  370. * might be ready when calling the function. Therefore, endeavour to
  371. * use the PE config address if possible. Further more, there're 2
  372. * RTAS calls for the purpose, we need to try the new one and back
  373. * to the old one if the new one couldn't work properly.
  374. */
  375. static int pseries_eeh_get_state(struct eeh_pe *pe, int *state)
  376. {
  377. int config_addr;
  378. int ret;
  379. int rets[4];
  380. int result;
  381. /* Figure out PE config address if possible */
  382. config_addr = pe->config_addr;
  383. if (pe->addr)
  384. config_addr = pe->addr;
  385. if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
  386. ret = rtas_call(ibm_read_slot_reset_state2, 3, 4, rets,
  387. config_addr, BUID_HI(pe->phb->buid),
  388. BUID_LO(pe->phb->buid));
  389. } else if (ibm_read_slot_reset_state != RTAS_UNKNOWN_SERVICE) {
  390. /* Fake PE unavailable info */
  391. rets[2] = 0;
  392. ret = rtas_call(ibm_read_slot_reset_state, 3, 3, rets,
  393. config_addr, BUID_HI(pe->phb->buid),
  394. BUID_LO(pe->phb->buid));
  395. } else {
  396. return EEH_STATE_NOT_SUPPORT;
  397. }
  398. if (ret)
  399. return ret;
  400. /* Parse the result out */
  401. result = 0;
  402. if (rets[1]) {
  403. switch(rets[0]) {
  404. case 0:
  405. result &= ~EEH_STATE_RESET_ACTIVE;
  406. result |= EEH_STATE_MMIO_ACTIVE;
  407. result |= EEH_STATE_DMA_ACTIVE;
  408. break;
  409. case 1:
  410. result |= EEH_STATE_RESET_ACTIVE;
  411. result |= EEH_STATE_MMIO_ACTIVE;
  412. result |= EEH_STATE_DMA_ACTIVE;
  413. break;
  414. case 2:
  415. result &= ~EEH_STATE_RESET_ACTIVE;
  416. result &= ~EEH_STATE_MMIO_ACTIVE;
  417. result &= ~EEH_STATE_DMA_ACTIVE;
  418. break;
  419. case 4:
  420. result &= ~EEH_STATE_RESET_ACTIVE;
  421. result &= ~EEH_STATE_MMIO_ACTIVE;
  422. result &= ~EEH_STATE_DMA_ACTIVE;
  423. result |= EEH_STATE_MMIO_ENABLED;
  424. break;
  425. case 5:
  426. if (rets[2]) {
  427. if (state) *state = rets[2];
  428. result = EEH_STATE_UNAVAILABLE;
  429. } else {
  430. result = EEH_STATE_NOT_SUPPORT;
  431. }
  432. break;
  433. default:
  434. result = EEH_STATE_NOT_SUPPORT;
  435. }
  436. } else {
  437. result = EEH_STATE_NOT_SUPPORT;
  438. }
  439. return result;
  440. }
  441. /**
  442. * pseries_eeh_reset - Reset the specified PE
  443. * @pe: EEH PE
  444. * @option: reset option
  445. *
  446. * Reset the specified PE
  447. */
  448. static int pseries_eeh_reset(struct eeh_pe *pe, int option)
  449. {
  450. int config_addr;
  451. int ret;
  452. /* Figure out PE address */
  453. config_addr = pe->config_addr;
  454. if (pe->addr)
  455. config_addr = pe->addr;
  456. /* Reset PE through RTAS call */
  457. ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL,
  458. config_addr, BUID_HI(pe->phb->buid),
  459. BUID_LO(pe->phb->buid), option);
  460. /* If fundamental-reset not supported, try hot-reset */
  461. if (option == EEH_RESET_FUNDAMENTAL &&
  462. ret == -8) {
  463. option = EEH_RESET_HOT;
  464. ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL,
  465. config_addr, BUID_HI(pe->phb->buid),
  466. BUID_LO(pe->phb->buid), option);
  467. }
  468. /* We need reset hold or settlement delay */
  469. if (option == EEH_RESET_FUNDAMENTAL ||
  470. option == EEH_RESET_HOT)
  471. msleep(EEH_PE_RST_HOLD_TIME);
  472. else
  473. msleep(EEH_PE_RST_SETTLE_TIME);
  474. return ret;
  475. }
  476. /**
  477. * pseries_eeh_wait_state - Wait for PE state
  478. * @pe: EEH PE
  479. * @max_wait: maximal period in microsecond
  480. *
  481. * Wait for the state of associated PE. It might take some time
  482. * to retrieve the PE's state.
  483. */
  484. static int pseries_eeh_wait_state(struct eeh_pe *pe, int max_wait)
  485. {
  486. int ret;
  487. int mwait;
  488. /*
  489. * According to PAPR, the state of PE might be temporarily
  490. * unavailable. Under the circumstance, we have to wait
  491. * for indicated time determined by firmware. The maximal
  492. * wait time is 5 minutes, which is acquired from the original
  493. * EEH implementation. Also, the original implementation
  494. * also defined the minimal wait time as 1 second.
  495. */
  496. #define EEH_STATE_MIN_WAIT_TIME (1000)
  497. #define EEH_STATE_MAX_WAIT_TIME (300 * 1000)
  498. while (1) {
  499. ret = pseries_eeh_get_state(pe, &mwait);
  500. /*
  501. * If the PE's state is temporarily unavailable,
  502. * we have to wait for the specified time. Otherwise,
  503. * the PE's state will be returned immediately.
  504. */
  505. if (ret != EEH_STATE_UNAVAILABLE)
  506. return ret;
  507. if (max_wait <= 0) {
  508. pr_warn("%s: Timeout when getting PE's state (%d)\n",
  509. __func__, max_wait);
  510. return EEH_STATE_NOT_SUPPORT;
  511. }
  512. if (mwait <= 0) {
  513. pr_warn("%s: Firmware returned bad wait value %d\n",
  514. __func__, mwait);
  515. mwait = EEH_STATE_MIN_WAIT_TIME;
  516. } else if (mwait > EEH_STATE_MAX_WAIT_TIME) {
  517. pr_warn("%s: Firmware returned too long wait value %d\n",
  518. __func__, mwait);
  519. mwait = EEH_STATE_MAX_WAIT_TIME;
  520. }
  521. max_wait -= mwait;
  522. msleep(mwait);
  523. }
  524. return EEH_STATE_NOT_SUPPORT;
  525. }
  526. /**
  527. * pseries_eeh_get_log - Retrieve error log
  528. * @pe: EEH PE
  529. * @severity: temporary or permanent error log
  530. * @drv_log: driver log to be combined with retrieved error log
  531. * @len: length of driver log
  532. *
  533. * Retrieve the temporary or permanent error from the PE.
  534. * Actually, the error will be retrieved through the dedicated
  535. * RTAS call.
  536. */
  537. static int pseries_eeh_get_log(struct eeh_pe *pe, int severity, char *drv_log, unsigned long len)
  538. {
  539. int config_addr;
  540. unsigned long flags;
  541. int ret;
  542. spin_lock_irqsave(&slot_errbuf_lock, flags);
  543. memset(slot_errbuf, 0, eeh_error_buf_size);
  544. /* Figure out the PE address */
  545. config_addr = pe->config_addr;
  546. if (pe->addr)
  547. config_addr = pe->addr;
  548. ret = rtas_call(ibm_slot_error_detail, 8, 1, NULL, config_addr,
  549. BUID_HI(pe->phb->buid), BUID_LO(pe->phb->buid),
  550. virt_to_phys(drv_log), len,
  551. virt_to_phys(slot_errbuf), eeh_error_buf_size,
  552. severity);
  553. if (!ret)
  554. log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
  555. spin_unlock_irqrestore(&slot_errbuf_lock, flags);
  556. return ret;
  557. }
  558. /**
  559. * pseries_eeh_configure_bridge - Configure PCI bridges in the indicated PE
  560. * @pe: EEH PE
  561. *
  562. * The function will be called to reconfigure the bridges included
  563. * in the specified PE so that the mulfunctional PE would be recovered
  564. * again.
  565. */
  566. static int pseries_eeh_configure_bridge(struct eeh_pe *pe)
  567. {
  568. int config_addr;
  569. int ret;
  570. /* Figure out the PE address */
  571. config_addr = pe->config_addr;
  572. if (pe->addr)
  573. config_addr = pe->addr;
  574. /* Use new configure-pe function, if supported */
  575. if (ibm_configure_pe != RTAS_UNKNOWN_SERVICE) {
  576. ret = rtas_call(ibm_configure_pe, 3, 1, NULL,
  577. config_addr, BUID_HI(pe->phb->buid),
  578. BUID_LO(pe->phb->buid));
  579. } else if (ibm_configure_bridge != RTAS_UNKNOWN_SERVICE) {
  580. ret = rtas_call(ibm_configure_bridge, 3, 1, NULL,
  581. config_addr, BUID_HI(pe->phb->buid),
  582. BUID_LO(pe->phb->buid));
  583. } else {
  584. return -EFAULT;
  585. }
  586. if (ret)
  587. pr_warn("%s: Unable to configure bridge PHB#%d-PE#%x (%d)\n",
  588. __func__, pe->phb->global_number, pe->addr, ret);
  589. return ret;
  590. }
  591. /**
  592. * pseries_eeh_read_config - Read PCI config space
  593. * @dn: device node
  594. * @where: PCI address
  595. * @size: size to read
  596. * @val: return value
  597. *
  598. * Read config space from the speicifed device
  599. */
  600. static int pseries_eeh_read_config(struct device_node *dn, int where, int size, u32 *val)
  601. {
  602. struct pci_dn *pdn;
  603. pdn = PCI_DN(dn);
  604. return rtas_read_config(pdn, where, size, val);
  605. }
  606. /**
  607. * pseries_eeh_write_config - Write PCI config space
  608. * @dn: device node
  609. * @where: PCI address
  610. * @size: size to write
  611. * @val: value to be written
  612. *
  613. * Write config space to the specified device
  614. */
  615. static int pseries_eeh_write_config(struct device_node *dn, int where, int size, u32 val)
  616. {
  617. struct pci_dn *pdn;
  618. pdn = PCI_DN(dn);
  619. return rtas_write_config(pdn, where, size, val);
  620. }
  621. static struct eeh_ops pseries_eeh_ops = {
  622. .name = "pseries",
  623. .init = pseries_eeh_init,
  624. .of_probe = pseries_eeh_of_probe,
  625. .dev_probe = NULL,
  626. .set_option = pseries_eeh_set_option,
  627. .get_pe_addr = pseries_eeh_get_pe_addr,
  628. .get_state = pseries_eeh_get_state,
  629. .reset = pseries_eeh_reset,
  630. .wait_state = pseries_eeh_wait_state,
  631. .get_log = pseries_eeh_get_log,
  632. .configure_bridge = pseries_eeh_configure_bridge,
  633. .err_inject = NULL,
  634. .read_config = pseries_eeh_read_config,
  635. .write_config = pseries_eeh_write_config,
  636. .next_error = NULL,
  637. .restore_config = NULL
  638. };
  639. /**
  640. * eeh_pseries_init - Register platform dependent EEH operations
  641. *
  642. * EEH initialization on pseries platform. This function should be
  643. * called before any EEH related functions.
  644. */
  645. static int __init eeh_pseries_init(void)
  646. {
  647. int ret;
  648. ret = eeh_ops_register(&pseries_eeh_ops);
  649. if (!ret)
  650. pr_info("EEH: pSeries platform initialized\n");
  651. else
  652. pr_info("EEH: pSeries platform initialization failure (%d)\n",
  653. ret);
  654. return ret;
  655. }
  656. machine_early_initcall(pseries, eeh_pseries_init);