eeh_pseries.c 19 KB

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