eeh_pseries.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. * pseries_eeh_init - EEH platform dependent initialization
  57. *
  58. * EEH platform dependent initialization on pseries.
  59. */
  60. static int pseries_eeh_init(void)
  61. {
  62. /* figure out EEH RTAS function call tokens */
  63. ibm_set_eeh_option = rtas_token("ibm,set-eeh-option");
  64. ibm_set_slot_reset = rtas_token("ibm,set-slot-reset");
  65. ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");
  66. ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");
  67. ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");
  68. ibm_get_config_addr_info2 = rtas_token("ibm,get-config-addr-info2");
  69. ibm_get_config_addr_info = rtas_token("ibm,get-config-addr-info");
  70. ibm_configure_pe = rtas_token("ibm,configure-pe");
  71. ibm_configure_bridge = rtas_token ("ibm,configure-bridge");
  72. /* necessary sanity check */
  73. if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE) {
  74. pr_warning("%s: RTAS service <ibm,set-eeh-option> invalid\n",
  75. __func__);
  76. return -EINVAL;
  77. } else if (ibm_set_slot_reset == RTAS_UNKNOWN_SERVICE) {
  78. pr_warning("%s: RTAS service <ibm, set-slot-reset> invalid\n",
  79. __func__);
  80. return -EINVAL;
  81. } else if (ibm_read_slot_reset_state2 == RTAS_UNKNOWN_SERVICE &&
  82. ibm_read_slot_reset_state == RTAS_UNKNOWN_SERVICE) {
  83. pr_warning("%s: RTAS service <ibm,read-slot-reset-state2> and "
  84. "<ibm,read-slot-reset-state> invalid\n",
  85. __func__);
  86. return -EINVAL;
  87. } else if (ibm_slot_error_detail == RTAS_UNKNOWN_SERVICE) {
  88. pr_warning("%s: RTAS service <ibm,slot-error-detail> invalid\n",
  89. __func__);
  90. return -EINVAL;
  91. } else if (ibm_get_config_addr_info2 == RTAS_UNKNOWN_SERVICE &&
  92. ibm_get_config_addr_info == RTAS_UNKNOWN_SERVICE) {
  93. pr_warning("%s: RTAS service <ibm,get-config-addr-info2> and "
  94. "<ibm,get-config-addr-info> invalid\n",
  95. __func__);
  96. return -EINVAL;
  97. } else if (ibm_configure_pe == RTAS_UNKNOWN_SERVICE &&
  98. ibm_configure_bridge == RTAS_UNKNOWN_SERVICE) {
  99. pr_warning("%s: RTAS service <ibm,configure-pe> and "
  100. "<ibm,configure-bridge> invalid\n",
  101. __func__);
  102. return -EINVAL;
  103. }
  104. return 0;
  105. }
  106. /**
  107. * pseries_eeh_set_option - Initialize EEH or MMIO/DMA reenable
  108. * @dn: device node
  109. * @option: operation to be issued
  110. *
  111. * The function is used to control the EEH functionality globally.
  112. * Currently, following options are support according to PAPR:
  113. * Enable EEH, Disable EEH, Enable MMIO and Enable DMA
  114. */
  115. static int pseries_eeh_set_option(struct device_node *dn, int option)
  116. {
  117. int ret = 0;
  118. struct pci_dn *pdn;
  119. const u32 *reg;
  120. int config_addr;
  121. pdn = PCI_DN(dn);
  122. /*
  123. * When we're enabling or disabling EEH functioality on
  124. * the particular PE, the PE config address is possibly
  125. * unavailable. Therefore, we have to figure it out from
  126. * the FDT node.
  127. */
  128. switch (option) {
  129. case EEH_OPT_DISABLE:
  130. case EEH_OPT_ENABLE:
  131. reg = of_get_property(dn, "reg", NULL);
  132. config_addr = reg[0];
  133. break;
  134. case EEH_OPT_THAW_MMIO:
  135. case EEH_OPT_THAW_DMA:
  136. config_addr = pdn->eeh_config_addr;
  137. if (pdn->eeh_pe_config_addr)
  138. config_addr = pdn->eeh_pe_config_addr;
  139. break;
  140. default:
  141. pr_err("%s: Invalid option %d\n",
  142. __func__, option);
  143. return -EINVAL;
  144. }
  145. ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL,
  146. config_addr, BUID_HI(pdn->phb->buid),
  147. BUID_LO(pdn->phb->buid), option);
  148. return ret;
  149. }
  150. /**
  151. * pseries_eeh_get_pe_addr - Retrieve PE address
  152. * @dn: device node
  153. *
  154. * Retrieve the assocated PE address. Actually, there're 2 RTAS
  155. * function calls dedicated for the purpose. We need implement
  156. * it through the new function and then the old one. Besides,
  157. * you should make sure the config address is figured out from
  158. * FDT node before calling the function.
  159. *
  160. * It's notable that zero'ed return value means invalid PE config
  161. * address.
  162. */
  163. static int pseries_eeh_get_pe_addr(struct device_node *dn)
  164. {
  165. struct pci_dn *pdn;
  166. int ret = 0;
  167. int rets[3];
  168. pdn = PCI_DN(dn);
  169. if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) {
  170. /*
  171. * First of all, we need to make sure there has one PE
  172. * associated with the device. Otherwise, PE address is
  173. * meaningless.
  174. */
  175. ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
  176. pdn->eeh_config_addr, BUID_HI(pdn->phb->buid),
  177. BUID_LO(pdn->phb->buid), 1);
  178. if (ret || (rets[0] == 0))
  179. return 0;
  180. /* Retrieve the associated PE config address */
  181. ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets,
  182. pdn->eeh_config_addr, BUID_HI(pdn->phb->buid),
  183. BUID_LO(pdn->phb->buid), 0);
  184. if (ret) {
  185. pr_warning("%s: Failed to get PE address for %s\n",
  186. __func__, dn->full_name);
  187. return 0;
  188. }
  189. return rets[0];
  190. }
  191. if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {
  192. ret = rtas_call(ibm_get_config_addr_info, 4, 2, rets,
  193. pdn->eeh_config_addr, BUID_HI(pdn->phb->buid),
  194. BUID_LO(pdn->phb->buid), 0);
  195. if (ret) {
  196. pr_warning("%s: Failed to get PE address for %s\n",
  197. __func__, dn->full_name);
  198. return 0;
  199. }
  200. return rets[0];
  201. }
  202. return ret;
  203. }
  204. /**
  205. * pseries_eeh_get_state - Retrieve PE state
  206. * @dn: PE associated device node
  207. * @state: return value
  208. *
  209. * Retrieve the state of the specified PE. On RTAS compliant
  210. * pseries platform, there already has one dedicated RTAS function
  211. * for the purpose. It's notable that the associated PE config address
  212. * might be ready when calling the function. Therefore, endeavour to
  213. * use the PE config address if possible. Further more, there're 2
  214. * RTAS calls for the purpose, we need to try the new one and back
  215. * to the old one if the new one couldn't work properly.
  216. */
  217. static int pseries_eeh_get_state(struct device_node *dn, int *state)
  218. {
  219. struct pci_dn *pdn;
  220. int config_addr;
  221. int ret;
  222. int rets[4];
  223. int result;
  224. /* Figure out PE config address if possible */
  225. pdn = PCI_DN(dn);
  226. config_addr = pdn->eeh_config_addr;
  227. if (pdn->eeh_pe_config_addr)
  228. config_addr = pdn->eeh_pe_config_addr;
  229. if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {
  230. ret = rtas_call(ibm_read_slot_reset_state2, 3, 4, rets,
  231. config_addr, BUID_HI(pdn->phb->buid),
  232. BUID_LO(pdn->phb->buid));
  233. } else if (ibm_read_slot_reset_state != RTAS_UNKNOWN_SERVICE) {
  234. /* Fake PE unavailable info */
  235. rets[2] = 0;
  236. ret = rtas_call(ibm_read_slot_reset_state, 3, 3, rets,
  237. config_addr, BUID_HI(pdn->phb->buid),
  238. BUID_LO(pdn->phb->buid));
  239. } else {
  240. return EEH_STATE_NOT_SUPPORT;
  241. }
  242. if (ret)
  243. return ret;
  244. /* Parse the result out */
  245. result = 0;
  246. if (rets[1]) {
  247. switch(rets[0]) {
  248. case 0:
  249. result &= ~EEH_STATE_RESET_ACTIVE;
  250. result |= EEH_STATE_MMIO_ACTIVE;
  251. result |= EEH_STATE_DMA_ACTIVE;
  252. break;
  253. case 1:
  254. result |= EEH_STATE_RESET_ACTIVE;
  255. result |= EEH_STATE_MMIO_ACTIVE;
  256. result |= EEH_STATE_DMA_ACTIVE;
  257. break;
  258. case 2:
  259. result &= ~EEH_STATE_RESET_ACTIVE;
  260. result &= ~EEH_STATE_MMIO_ACTIVE;
  261. result &= ~EEH_STATE_DMA_ACTIVE;
  262. break;
  263. case 4:
  264. result &= ~EEH_STATE_RESET_ACTIVE;
  265. result &= ~EEH_STATE_MMIO_ACTIVE;
  266. result &= ~EEH_STATE_DMA_ACTIVE;
  267. result |= EEH_STATE_MMIO_ENABLED;
  268. break;
  269. case 5:
  270. if (rets[2]) {
  271. if (state) *state = rets[2];
  272. result = EEH_STATE_UNAVAILABLE;
  273. } else {
  274. result = EEH_STATE_NOT_SUPPORT;
  275. }
  276. default:
  277. result = EEH_STATE_NOT_SUPPORT;
  278. }
  279. } else {
  280. result = EEH_STATE_NOT_SUPPORT;
  281. }
  282. return result;
  283. }
  284. /**
  285. * pseries_eeh_reset - Reset the specified PE
  286. * @dn: PE associated device node
  287. * @option: reset option
  288. *
  289. * Reset the specified PE
  290. */
  291. static int pseries_eeh_reset(struct device_node *dn, int option)
  292. {
  293. return 0;
  294. }
  295. /**
  296. * pseries_eeh_wait_state - Wait for PE state
  297. * @dn: PE associated device node
  298. * @max_wait: maximal period in microsecond
  299. *
  300. * Wait for the state of associated PE. It might take some time
  301. * to retrieve the PE's state.
  302. */
  303. static int pseries_eeh_wait_state(struct device_node *dn, int max_wait)
  304. {
  305. int ret;
  306. int mwait;
  307. /*
  308. * According to PAPR, the state of PE might be temporarily
  309. * unavailable. Under the circumstance, we have to wait
  310. * for indicated time determined by firmware. The maximal
  311. * wait time is 5 minutes, which is acquired from the original
  312. * EEH implementation. Also, the original implementation
  313. * also defined the minimal wait time as 1 second.
  314. */
  315. #define EEH_STATE_MIN_WAIT_TIME (1000)
  316. #define EEH_STATE_MAX_WAIT_TIME (300 * 1000)
  317. while (1) {
  318. ret = pseries_eeh_get_state(dn, &mwait);
  319. /*
  320. * If the PE's state is temporarily unavailable,
  321. * we have to wait for the specified time. Otherwise,
  322. * the PE's state will be returned immediately.
  323. */
  324. if (ret != EEH_STATE_UNAVAILABLE)
  325. return ret;
  326. if (max_wait <= 0) {
  327. pr_warning("%s: Timeout when getting PE's state (%d)\n",
  328. __func__, max_wait);
  329. return EEH_STATE_NOT_SUPPORT;
  330. }
  331. if (mwait <= 0) {
  332. pr_warning("%s: Firmware returned bad wait value %d\n",
  333. __func__, mwait);
  334. mwait = EEH_STATE_MIN_WAIT_TIME;
  335. } else if (mwait > EEH_STATE_MAX_WAIT_TIME) {
  336. pr_warning("%s: Firmware returned too long wait value %d\n",
  337. __func__, mwait);
  338. mwait = EEH_STATE_MAX_WAIT_TIME;
  339. }
  340. max_wait -= mwait;
  341. msleep(mwait);
  342. }
  343. return EEH_STATE_NOT_SUPPORT;
  344. }
  345. /**
  346. * pseries_eeh_get_log - Retrieve error log
  347. * @dn: device node
  348. * @severity: temporary or permanent error log
  349. * @drv_log: driver log to be combined with retrieved error log
  350. * @len: length of driver log
  351. *
  352. * Retrieve the temporary or permanent error from the PE.
  353. * Actually, the error will be retrieved through the dedicated
  354. * RTAS call.
  355. */
  356. static int pseries_eeh_get_log(struct device_node *dn, int severity, char *drv_log, unsigned long len)
  357. {
  358. return 0;
  359. }
  360. /**
  361. * pseries_eeh_configure_bridge - Configure PCI bridges in the indicated PE
  362. * @dn: PE associated device node
  363. *
  364. * The function will be called to reconfigure the bridges included
  365. * in the specified PE so that the mulfunctional PE would be recovered
  366. * again.
  367. */
  368. static int pseries_eeh_configure_bridge(struct device_node *dn)
  369. {
  370. return 0;
  371. }
  372. static struct eeh_ops pseries_eeh_ops = {
  373. .name = "pseries",
  374. .init = pseries_eeh_init,
  375. .set_option = pseries_eeh_set_option,
  376. .get_pe_addr = pseries_eeh_get_pe_addr,
  377. .get_state = pseries_eeh_get_state,
  378. .reset = pseries_eeh_reset,
  379. .wait_state = pseries_eeh_wait_state,
  380. .get_log = pseries_eeh_get_log,
  381. .configure_bridge = pseries_eeh_configure_bridge
  382. };
  383. /**
  384. * eeh_pseries_init - Register platform dependent EEH operations
  385. *
  386. * EEH initialization on pseries platform. This function should be
  387. * called before any EEH related functions.
  388. */
  389. int __init eeh_pseries_init(void)
  390. {
  391. return eeh_ops_register(&pseries_eeh_ops);
  392. }