eeh_pseries.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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 pci_dn *pdn)
  112. {
  113. u32 status;
  114. if (!pdn)
  115. return 0;
  116. rtas_read_config(pdn, PCI_STATUS, 2, &status);
  117. if (!(status & PCI_STATUS_CAP_LIST))
  118. return 0;
  119. return PCI_CAPABILITY_LIST;
  120. }
  121. static int pseries_eeh_find_cap(struct pci_dn *pdn, int cap)
  122. {
  123. int pos = pseries_eeh_cap_start(pdn);
  124. int cnt = 48; /* Maximal number of capabilities */
  125. u32 id;
  126. if (!pos)
  127. return 0;
  128. while (cnt--) {
  129. rtas_read_config(pdn, pos, 1, &pos);
  130. if (pos < 0x40)
  131. break;
  132. pos &= ~3;
  133. rtas_read_config(pdn, pos + PCI_CAP_LIST_ID, 1, &id);
  134. if (id == 0xff)
  135. break;
  136. if (id == cap)
  137. return pos;
  138. pos += PCI_CAP_LIST_NEXT;
  139. }
  140. return 0;
  141. }
  142. static int pseries_eeh_find_ecap(struct pci_dn *pdn, int cap)
  143. {
  144. struct eeh_dev *edev = pdn_to_eeh_dev(pdn);
  145. u32 header;
  146. int pos = 256;
  147. int ttl = (4096 - 256) / 8;
  148. if (!edev || !edev->pcie_cap)
  149. return 0;
  150. if (rtas_read_config(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
  151. return 0;
  152. else if (!header)
  153. return 0;
  154. while (ttl-- > 0) {
  155. if (PCI_EXT_CAP_ID(header) == cap && pos)
  156. return pos;
  157. pos = PCI_EXT_CAP_NEXT(header);
  158. if (pos < 256)
  159. break;
  160. if (rtas_read_config(pdn, pos, 4, &header) != PCIBIOS_SUCCESSFUL)
  161. break;
  162. }
  163. return 0;
  164. }
  165. /**
  166. * pseries_eeh_probe - EEH probe on the given device
  167. * @pdn: PCI device node
  168. * @data: Unused
  169. *
  170. * When EEH module is installed during system boot, all PCI devices
  171. * are checked one by one to see if it supports EEH. The function
  172. * is introduced for the purpose.
  173. */
  174. static void *pseries_eeh_probe(struct pci_dn *pdn, void *data)
  175. {
  176. struct eeh_dev *edev;
  177. struct eeh_pe pe;
  178. u32 pcie_flags;
  179. int enable = 0;
  180. int ret;
  181. /* Retrieve OF node and eeh device */
  182. edev = pdn_to_eeh_dev(pdn);
  183. if (!edev || edev->pe)
  184. return NULL;
  185. /* Check class/vendor/device IDs */
  186. if (!pdn->vendor_id || !pdn->device_id || !pdn->class_code)
  187. return NULL;
  188. /* Skip for PCI-ISA bridge */
  189. if ((pdn->class_code >> 8) == PCI_CLASS_BRIDGE_ISA)
  190. return NULL;
  191. /*
  192. * Update class code and mode of eeh device. We need
  193. * correctly reflects that current device is root port
  194. * or PCIe switch downstream port.
  195. */
  196. edev->class_code = pdn->class_code;
  197. edev->pcix_cap = pseries_eeh_find_cap(pdn, PCI_CAP_ID_PCIX);
  198. edev->pcie_cap = pseries_eeh_find_cap(pdn, PCI_CAP_ID_EXP);
  199. edev->aer_cap = pseries_eeh_find_ecap(pdn, PCI_EXT_CAP_ID_ERR);
  200. edev->mode &= 0xFFFFFF00;
  201. if ((edev->class_code >> 8) == PCI_CLASS_BRIDGE_PCI) {
  202. edev->mode |= EEH_DEV_BRIDGE;
  203. if (edev->pcie_cap) {
  204. rtas_read_config(pdn, edev->pcie_cap + PCI_EXP_FLAGS,
  205. 2, &pcie_flags);
  206. pcie_flags = (pcie_flags & PCI_EXP_FLAGS_TYPE) >> 4;
  207. if (pcie_flags == PCI_EXP_TYPE_ROOT_PORT)
  208. edev->mode |= EEH_DEV_ROOT_PORT;
  209. else if (pcie_flags == PCI_EXP_TYPE_DOWNSTREAM)
  210. edev->mode |= EEH_DEV_DS_PORT;
  211. }
  212. }
  213. /* Initialize the fake PE */
  214. memset(&pe, 0, sizeof(struct eeh_pe));
  215. pe.phb = edev->phb;
  216. pe.config_addr = (pdn->busno << 16) | (pdn->devfn << 8);
  217. /* Enable EEH on the device */
  218. ret = eeh_ops->set_option(&pe, EEH_OPT_ENABLE);
  219. if (!ret) {
  220. /* Retrieve PE address */
  221. edev->config_addr = (pdn->busno << 16) | (pdn->devfn << 8);
  222. edev->pe_config_addr = eeh_ops->get_pe_addr(&pe);
  223. pe.addr = edev->pe_config_addr;
  224. /* Some older systems (Power4) allow the ibm,set-eeh-option
  225. * call to succeed even on nodes where EEH is not supported.
  226. * Verify support explicitly.
  227. */
  228. ret = eeh_ops->get_state(&pe, NULL);
  229. if (ret > 0 && ret != EEH_STATE_NOT_SUPPORT)
  230. enable = 1;
  231. if (enable) {
  232. eeh_add_flag(EEH_ENABLED);
  233. eeh_add_to_parent_pe(edev);
  234. pr_debug("%s: EEH enabled on %02x:%02x.%01x PHB#%d-PE#%x\n",
  235. __func__, pdn->busno, PCI_SLOT(pdn->devfn),
  236. PCI_FUNC(pdn->devfn), pe.phb->global_number,
  237. pe.addr);
  238. } else if (pdn->parent && pdn_to_eeh_dev(pdn->parent) &&
  239. (pdn_to_eeh_dev(pdn->parent))->pe) {
  240. /* This device doesn't support EEH, but it may have an
  241. * EEH parent, in which case we mark it as supported.
  242. */
  243. edev->config_addr = pdn_to_eeh_dev(pdn->parent)->config_addr;
  244. edev->pe_config_addr = pdn_to_eeh_dev(pdn->parent)->pe_config_addr;
  245. eeh_add_to_parent_pe(edev);
  246. }
  247. }
  248. /* Save memory bars */
  249. eeh_save_bars(edev);
  250. return NULL;
  251. }
  252. /**
  253. * pseries_eeh_set_option - Initialize EEH or MMIO/DMA reenable
  254. * @pe: EEH PE
  255. * @option: operation to be issued
  256. *
  257. * The function is used to control the EEH functionality globally.
  258. * Currently, following options are support according to PAPR:
  259. * Enable EEH, Disable EEH, Enable MMIO and Enable DMA
  260. */
  261. static int pseries_eeh_set_option(struct eeh_pe *pe, int option)
  262. {
  263. int ret = 0;
  264. int config_addr;
  265. /*
  266. * When we're enabling or disabling EEH functioality on
  267. * the particular PE, the PE config address is possibly
  268. * unavailable. Therefore, we have to figure it out from
  269. * the FDT node.
  270. */
  271. switch (option) {
  272. case EEH_OPT_DISABLE:
  273. case EEH_OPT_ENABLE:
  274. case EEH_OPT_THAW_MMIO:
  275. case EEH_OPT_THAW_DMA:
  276. config_addr = pe->config_addr;
  277. if (pe->addr)
  278. config_addr = pe->addr;
  279. break;
  280. case EEH_OPT_FREEZE_PE:
  281. /* Not support */
  282. return 0;
  283. default:
  284. pr_err("%s: Invalid option %d\n",
  285. __func__, option);
  286. return -EINVAL;
  287. }
  288. ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
  289. config_addr, BUID_HI(pe->phb->buid),
  290. BUID_LO(pe->phb->buid), option);
  291. return ret;
  292. }
  293. /**
  294. * pseries_eeh_get_pe_addr - Retrieve PE address
  295. * @pe: EEH PE
  296. *
  297. * Retrieve the assocated PE address. Actually, there're 2 RTAS
  298. * function calls dedicated for the purpose. We need implement
  299. * it through the new function and then the old one. Besides,
  300. * you should make sure the config address is figured out from
  301. * FDT node before calling the function.
  302. *
  303. * It's notable that zero'ed return value means invalid PE config
  304. * address.
  305. */
  306. static int pseries_eeh_get_pe_addr(struct eeh_pe *pe)
  307. {
  308. int ret = 0;
  309. int rets[3];
  310. if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) {
  311. /*
  312. * First of all, we need to make sure there has one PE
  313. * associated with the device. Otherwise, PE address is
  314. * meaningless.
  315. */
  316. ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
  317. pe->config_addr, BUID_HI(pe->phb->buid),
  318. BUID_LO(pe->phb->buid), 1);
  319. if (ret || (rets[0] == 0))
  320. return 0;
  321. /* Retrieve the associated PE config address */
  322. ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
  323. pe->config_addr, BUID_HI(pe->phb->buid),
  324. BUID_LO(pe->phb->buid), 0);
  325. if (ret) {
  326. pr_warn("%s: Failed to get address for PHB#%d-PE#%x\n",
  327. __func__, pe->phb->global_number, pe->config_addr);
  328. return 0;
  329. }
  330. return rets[0];
  331. }
  332. if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
  333. ret = rtas_call(ibm_get_config_addr_info, 4, 2, rets,
  334. pe->config_addr, BUID_HI(pe->phb->buid),
  335. BUID_LO(pe->phb->buid), 0);
  336. if (ret) {
  337. pr_warn("%s: Failed to get address for PHB#%d-PE#%x\n",
  338. __func__, pe->phb->global_number, pe->config_addr);
  339. return 0;
  340. }
  341. return rets[0];
  342. }
  343. return ret;
  344. }
  345. /**
  346. * pseries_eeh_get_state - Retrieve PE state
  347. * @pe: EEH PE
  348. * @state: return value
  349. *
  350. * Retrieve the state of the specified PE. On RTAS compliant
  351. * pseries platform, there already has one dedicated RTAS function
  352. * for the purpose. It's notable that the associated PE config address
  353. * might be ready when calling the function. Therefore, endeavour to
  354. * use the PE config address if possible. Further more, there're 2
  355. * RTAS calls for the purpose, we need to try the new one and back
  356. * to the old one if the new one couldn't work properly.
  357. */
  358. static int pseries_eeh_get_state(struct eeh_pe *pe, int *state)
  359. {
  360. int config_addr;
  361. int ret;
  362. int rets[4];
  363. int result;
  364. /* Figure out PE config address if possible */
  365. config_addr = pe->config_addr;
  366. if (pe->addr)
  367. config_addr = pe->addr;
  368. if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
  369. ret = rtas_call(ibm_read_slot_reset_state2, 3, 4, rets,
  370. config_addr, BUID_HI(pe->phb->buid),
  371. BUID_LO(pe->phb->buid));
  372. } else if (ibm_read_slot_reset_state != RTAS_UNKNOWN_SERVICE) {
  373. /* Fake PE unavailable info */
  374. rets[2] = 0;
  375. ret = rtas_call(ibm_read_slot_reset_state, 3, 3, rets,
  376. config_addr, BUID_HI(pe->phb->buid),
  377. BUID_LO(pe->phb->buid));
  378. } else {
  379. return EEH_STATE_NOT_SUPPORT;
  380. }
  381. if (ret)
  382. return ret;
  383. /* Parse the result out */
  384. if (!rets[1])
  385. return EEH_STATE_NOT_SUPPORT;
  386. switch(rets[0]) {
  387. case 0:
  388. result = EEH_STATE_MMIO_ACTIVE |
  389. EEH_STATE_DMA_ACTIVE;
  390. break;
  391. case 1:
  392. result = EEH_STATE_RESET_ACTIVE |
  393. EEH_STATE_MMIO_ACTIVE |
  394. EEH_STATE_DMA_ACTIVE;
  395. break;
  396. case 2:
  397. result = 0;
  398. break;
  399. case 4:
  400. result = EEH_STATE_MMIO_ENABLED;
  401. break;
  402. case 5:
  403. if (rets[2]) {
  404. if (state) *state = rets[2];
  405. result = EEH_STATE_UNAVAILABLE;
  406. } else {
  407. result = EEH_STATE_NOT_SUPPORT;
  408. }
  409. break;
  410. default:
  411. result = EEH_STATE_NOT_SUPPORT;
  412. }
  413. return result;
  414. }
  415. /**
  416. * pseries_eeh_reset - Reset the specified PE
  417. * @pe: EEH PE
  418. * @option: reset option
  419. *
  420. * Reset the specified PE
  421. */
  422. static int pseries_eeh_reset(struct eeh_pe *pe, int option)
  423. {
  424. int config_addr;
  425. int ret;
  426. /* Figure out PE address */
  427. config_addr = pe->config_addr;
  428. if (pe->addr)
  429. config_addr = pe->addr;
  430. /* Reset PE through RTAS call */
  431. ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL,
  432. config_addr, BUID_HI(pe->phb->buid),
  433. BUID_LO(pe->phb->buid), option);
  434. /* If fundamental-reset not supported, try hot-reset */
  435. if (option == EEH_RESET_FUNDAMENTAL &&
  436. ret == -8) {
  437. option = EEH_RESET_HOT;
  438. ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL,
  439. config_addr, BUID_HI(pe->phb->buid),
  440. BUID_LO(pe->phb->buid), option);
  441. }
  442. /* We need reset hold or settlement delay */
  443. if (option == EEH_RESET_FUNDAMENTAL ||
  444. option == EEH_RESET_HOT)
  445. msleep(EEH_PE_RST_HOLD_TIME);
  446. else
  447. msleep(EEH_PE_RST_SETTLE_TIME);
  448. return ret;
  449. }
  450. /**
  451. * pseries_eeh_wait_state - Wait for PE state
  452. * @pe: EEH PE
  453. * @max_wait: maximal period in millisecond
  454. *
  455. * Wait for the state of associated PE. It might take some time
  456. * to retrieve the PE's state.
  457. */
  458. static int pseries_eeh_wait_state(struct eeh_pe *pe, int max_wait)
  459. {
  460. int ret;
  461. int mwait;
  462. /*
  463. * According to PAPR, the state of PE might be temporarily
  464. * unavailable. Under the circumstance, we have to wait
  465. * for indicated time determined by firmware. The maximal
  466. * wait time is 5 minutes, which is acquired from the original
  467. * EEH implementation. Also, the original implementation
  468. * also defined the minimal wait time as 1 second.
  469. */
  470. #define EEH_STATE_MIN_WAIT_TIME (1000)
  471. #define EEH_STATE_MAX_WAIT_TIME (300 * 1000)
  472. while (1) {
  473. ret = pseries_eeh_get_state(pe, &mwait);
  474. /*
  475. * If the PE's state is temporarily unavailable,
  476. * we have to wait for the specified time. Otherwise,
  477. * the PE's state will be returned immediately.
  478. */
  479. if (ret != EEH_STATE_UNAVAILABLE)
  480. return ret;
  481. if (max_wait <= 0) {
  482. pr_warn("%s: Timeout when getting PE's state (%d)\n",
  483. __func__, max_wait);
  484. return EEH_STATE_NOT_SUPPORT;
  485. }
  486. if (mwait <= 0) {
  487. pr_warn("%s: Firmware returned bad wait value %d\n",
  488. __func__, mwait);
  489. mwait = EEH_STATE_MIN_WAIT_TIME;
  490. } else if (mwait > EEH_STATE_MAX_WAIT_TIME) {
  491. pr_warn("%s: Firmware returned too long wait value %d\n",
  492. __func__, mwait);
  493. mwait = EEH_STATE_MAX_WAIT_TIME;
  494. }
  495. max_wait -= mwait;
  496. msleep(mwait);
  497. }
  498. return EEH_STATE_NOT_SUPPORT;
  499. }
  500. /**
  501. * pseries_eeh_get_log - Retrieve error log
  502. * @pe: EEH PE
  503. * @severity: temporary or permanent error log
  504. * @drv_log: driver log to be combined with retrieved error log
  505. * @len: length of driver log
  506. *
  507. * Retrieve the temporary or permanent error from the PE.
  508. * Actually, the error will be retrieved through the dedicated
  509. * RTAS call.
  510. */
  511. static int pseries_eeh_get_log(struct eeh_pe *pe, int severity, char *drv_log, unsigned long len)
  512. {
  513. int config_addr;
  514. unsigned long flags;
  515. int ret;
  516. spin_lock_irqsave(&slot_errbuf_lock, flags);
  517. memset(slot_errbuf, 0, eeh_error_buf_size);
  518. /* Figure out the PE address */
  519. config_addr = pe->config_addr;
  520. if (pe->addr)
  521. config_addr = pe->addr;
  522. ret = rtas_call(ibm_slot_error_detail, 8, 1, NULL, config_addr,
  523. BUID_HI(pe->phb->buid), BUID_LO(pe->phb->buid),
  524. virt_to_phys(drv_log), len,
  525. virt_to_phys(slot_errbuf), eeh_error_buf_size,
  526. severity);
  527. if (!ret)
  528. log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0);
  529. spin_unlock_irqrestore(&slot_errbuf_lock, flags);
  530. return ret;
  531. }
  532. /**
  533. * pseries_eeh_configure_bridge - Configure PCI bridges in the indicated PE
  534. * @pe: EEH PE
  535. *
  536. * The function will be called to reconfigure the bridges included
  537. * in the specified PE so that the mulfunctional PE would be recovered
  538. * again.
  539. */
  540. static int pseries_eeh_configure_bridge(struct eeh_pe *pe)
  541. {
  542. int config_addr;
  543. int ret;
  544. /* Waiting 0.2s maximum before skipping configuration */
  545. int max_wait = 200;
  546. /* Figure out the PE address */
  547. config_addr = pe->config_addr;
  548. if (pe->addr)
  549. config_addr = pe->addr;
  550. while (max_wait > 0) {
  551. /* Use new configure-pe function, if supported */
  552. if (ibm_configure_pe != RTAS_UNKNOWN_SERVICE) {
  553. ret = rtas_call(ibm_configure_pe, 3, 1, NULL,
  554. config_addr, BUID_HI(pe->phb->buid),
  555. BUID_LO(pe->phb->buid));
  556. } else if (ibm_configure_bridge != RTAS_UNKNOWN_SERVICE) {
  557. ret = rtas_call(ibm_configure_bridge, 3, 1, NULL,
  558. config_addr, BUID_HI(pe->phb->buid),
  559. BUID_LO(pe->phb->buid));
  560. } else {
  561. return -EFAULT;
  562. }
  563. if (!ret)
  564. return ret;
  565. /*
  566. * If RTAS returns a delay value that's above 100ms, cut it
  567. * down to 100ms in case firmware made a mistake. For more
  568. * on how these delay values work see rtas_busy_delay_time
  569. */
  570. if (ret > RTAS_EXTENDED_DELAY_MIN+2 &&
  571. ret <= RTAS_EXTENDED_DELAY_MAX)
  572. ret = RTAS_EXTENDED_DELAY_MIN+2;
  573. max_wait -= rtas_busy_delay_time(ret);
  574. if (max_wait < 0)
  575. break;
  576. rtas_busy_delay(ret);
  577. }
  578. pr_warn("%s: Unable to configure bridge PHB#%d-PE#%x (%d)\n",
  579. __func__, pe->phb->global_number, pe->addr, ret);
  580. return ret;
  581. }
  582. /**
  583. * pseries_eeh_read_config - Read PCI config space
  584. * @pdn: PCI device node
  585. * @where: PCI address
  586. * @size: size to read
  587. * @val: return value
  588. *
  589. * Read config space from the speicifed device
  590. */
  591. static int pseries_eeh_read_config(struct pci_dn *pdn, int where, int size, u32 *val)
  592. {
  593. return rtas_read_config(pdn, where, size, val);
  594. }
  595. /**
  596. * pseries_eeh_write_config - Write PCI config space
  597. * @pdn: PCI device node
  598. * @where: PCI address
  599. * @size: size to write
  600. * @val: value to be written
  601. *
  602. * Write config space to the specified device
  603. */
  604. static int pseries_eeh_write_config(struct pci_dn *pdn, int where, int size, u32 val)
  605. {
  606. return rtas_write_config(pdn, where, size, val);
  607. }
  608. static struct eeh_ops pseries_eeh_ops = {
  609. .name = "pseries",
  610. .init = pseries_eeh_init,
  611. .probe = pseries_eeh_probe,
  612. .set_option = pseries_eeh_set_option,
  613. .get_pe_addr = pseries_eeh_get_pe_addr,
  614. .get_state = pseries_eeh_get_state,
  615. .reset = pseries_eeh_reset,
  616. .wait_state = pseries_eeh_wait_state,
  617. .get_log = pseries_eeh_get_log,
  618. .configure_bridge = pseries_eeh_configure_bridge,
  619. .err_inject = NULL,
  620. .read_config = pseries_eeh_read_config,
  621. .write_config = pseries_eeh_write_config,
  622. .next_error = NULL,
  623. .restore_config = NULL
  624. };
  625. /**
  626. * eeh_pseries_init - Register platform dependent EEH operations
  627. *
  628. * EEH initialization on pseries platform. This function should be
  629. * called before any EEH related functions.
  630. */
  631. static int __init eeh_pseries_init(void)
  632. {
  633. int ret;
  634. ret = eeh_ops_register(&pseries_eeh_ops);
  635. if (!ret)
  636. pr_info("EEH: pSeries platform initialized\n");
  637. else
  638. pr_info("EEH: pSeries platform initialization failure (%d)\n",
  639. ret);
  640. return ret;
  641. }
  642. machine_early_initcall(pseries, eeh_pseries_init);