aerdrv_core.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. /*
  2. * drivers/pci/pcie/aer/aerdrv_core.c
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * This file implements the core part of PCI-Express AER. When an pci-express
  9. * error is delivered, an error message will be collected and printed to
  10. * console, then, an error recovery procedure will be executed by following
  11. * the pci error recovery rules.
  12. *
  13. * Copyright (C) 2006 Intel Corp.
  14. * Tom Long Nguyen (tom.l.nguyen@intel.com)
  15. * Zhang Yanmin (yanmin.zhang@intel.com)
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/pci.h>
  20. #include <linux/kernel.h>
  21. #include <linux/errno.h>
  22. #include <linux/pm.h>
  23. #include <linux/suspend.h>
  24. #include <linux/delay.h>
  25. #include "aerdrv.h"
  26. static int forceload;
  27. module_param(forceload, bool, 0);
  28. int pci_enable_pcie_error_reporting(struct pci_dev *dev)
  29. {
  30. u16 reg16 = 0;
  31. int pos;
  32. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
  33. if (!pos)
  34. return -EIO;
  35. pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
  36. if (!pos)
  37. return -EIO;
  38. pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
  39. reg16 = reg16 |
  40. PCI_EXP_DEVCTL_CERE |
  41. PCI_EXP_DEVCTL_NFERE |
  42. PCI_EXP_DEVCTL_FERE |
  43. PCI_EXP_DEVCTL_URRE;
  44. pci_write_config_word(dev, pos+PCI_EXP_DEVCTL,
  45. reg16);
  46. return 0;
  47. }
  48. int pci_disable_pcie_error_reporting(struct pci_dev *dev)
  49. {
  50. u16 reg16 = 0;
  51. int pos;
  52. pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
  53. if (!pos)
  54. return -EIO;
  55. pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
  56. reg16 = reg16 & ~(PCI_EXP_DEVCTL_CERE |
  57. PCI_EXP_DEVCTL_NFERE |
  58. PCI_EXP_DEVCTL_FERE |
  59. PCI_EXP_DEVCTL_URRE);
  60. pci_write_config_word(dev, pos+PCI_EXP_DEVCTL,
  61. reg16);
  62. return 0;
  63. }
  64. int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
  65. {
  66. int pos;
  67. u32 status, mask;
  68. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
  69. if (!pos)
  70. return -EIO;
  71. pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
  72. pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
  73. if (dev->error_state == pci_channel_io_normal)
  74. status &= ~mask; /* Clear corresponding nonfatal bits */
  75. else
  76. status &= mask; /* Clear corresponding fatal bits */
  77. pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
  78. return 0;
  79. }
  80. #if 0
  81. int pci_cleanup_aer_correct_error_status(struct pci_dev *dev)
  82. {
  83. int pos;
  84. u32 status;
  85. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
  86. if (!pos)
  87. return -EIO;
  88. pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &status);
  89. pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, status);
  90. return 0;
  91. }
  92. #endif /* 0 */
  93. static int set_device_error_reporting(struct pci_dev *dev, void *data)
  94. {
  95. bool enable = *((bool *)data);
  96. if (dev->pcie_type == PCIE_RC_PORT ||
  97. dev->pcie_type == PCIE_SW_UPSTREAM_PORT ||
  98. dev->pcie_type == PCIE_SW_DOWNSTREAM_PORT) {
  99. if (enable)
  100. pci_enable_pcie_error_reporting(dev);
  101. else
  102. pci_disable_pcie_error_reporting(dev);
  103. }
  104. if (enable)
  105. pcie_set_ecrc_checking(dev);
  106. return 0;
  107. }
  108. /**
  109. * set_downstream_devices_error_reporting - enable/disable the error reporting bits on the root port and its downstream ports.
  110. * @dev: pointer to root port's pci_dev data structure
  111. * @enable: true = enable error reporting, false = disable error reporting.
  112. */
  113. static void set_downstream_devices_error_reporting(struct pci_dev *dev,
  114. bool enable)
  115. {
  116. set_device_error_reporting(dev, &enable);
  117. if (!dev->subordinate)
  118. return;
  119. pci_walk_bus(dev->subordinate, set_device_error_reporting, &enable);
  120. }
  121. static int find_device_iter(struct device *device, void *data)
  122. {
  123. struct pci_dev *dev;
  124. u16 id = *(unsigned long *)data;
  125. u8 secondary, subordinate, d_bus = id >> 8;
  126. if (device->bus == &pci_bus_type) {
  127. dev = to_pci_dev(device);
  128. if (id == ((dev->bus->number << 8) | dev->devfn)) {
  129. /*
  130. * Device ID match
  131. */
  132. *(unsigned long*)data = (unsigned long)device;
  133. return 1;
  134. }
  135. /*
  136. * If device is P2P, check if it is an upstream?
  137. */
  138. if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) {
  139. pci_read_config_byte(dev, PCI_SECONDARY_BUS,
  140. &secondary);
  141. pci_read_config_byte(dev, PCI_SUBORDINATE_BUS,
  142. &subordinate);
  143. if (d_bus >= secondary && d_bus <= subordinate) {
  144. *(unsigned long*)data = (unsigned long)device;
  145. return 1;
  146. }
  147. }
  148. }
  149. return 0;
  150. }
  151. /**
  152. * find_source_device - search through device hierarchy for source device
  153. * @parent: pointer to Root Port pci_dev data structure
  154. * @id: device ID of agent who sends an error message to this Root Port
  155. *
  156. * Invoked when error is detected at the Root Port.
  157. */
  158. static struct device* find_source_device(struct pci_dev *parent, u16 id)
  159. {
  160. struct pci_dev *dev = parent;
  161. struct device *device;
  162. unsigned long device_addr;
  163. int status;
  164. /* Is Root Port an agent that sends error message? */
  165. if (id == ((dev->bus->number << 8) | dev->devfn))
  166. return &dev->dev;
  167. do {
  168. device_addr = id;
  169. if ((status = device_for_each_child(&dev->dev,
  170. &device_addr, find_device_iter))) {
  171. device = (struct device*)device_addr;
  172. dev = to_pci_dev(device);
  173. if (id == ((dev->bus->number << 8) | dev->devfn))
  174. return device;
  175. }
  176. }while (status);
  177. return NULL;
  178. }
  179. static int report_error_detected(struct pci_dev *dev, void *data)
  180. {
  181. pci_ers_result_t vote;
  182. struct pci_error_handlers *err_handler;
  183. struct aer_broadcast_data *result_data;
  184. result_data = (struct aer_broadcast_data *) data;
  185. dev->error_state = result_data->state;
  186. if (!dev->driver ||
  187. !dev->driver->err_handler ||
  188. !dev->driver->err_handler->error_detected) {
  189. if (result_data->state == pci_channel_io_frozen &&
  190. !(dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)) {
  191. /*
  192. * In case of fatal recovery, if one of down-
  193. * stream device has no driver. We might be
  194. * unable to recover because a later insmod
  195. * of a driver for this device is unaware of
  196. * its hw state.
  197. */
  198. dev_printk(KERN_DEBUG, &dev->dev, "device has %s\n",
  199. dev->driver ?
  200. "no AER-aware driver" : "no driver");
  201. }
  202. return 0;
  203. }
  204. err_handler = dev->driver->err_handler;
  205. vote = err_handler->error_detected(dev, result_data->state);
  206. result_data->result = merge_result(result_data->result, vote);
  207. return 0;
  208. }
  209. static int report_mmio_enabled(struct pci_dev *dev, void *data)
  210. {
  211. pci_ers_result_t vote;
  212. struct pci_error_handlers *err_handler;
  213. struct aer_broadcast_data *result_data;
  214. result_data = (struct aer_broadcast_data *) data;
  215. if (!dev->driver ||
  216. !dev->driver->err_handler ||
  217. !dev->driver->err_handler->mmio_enabled)
  218. return 0;
  219. err_handler = dev->driver->err_handler;
  220. vote = err_handler->mmio_enabled(dev);
  221. result_data->result = merge_result(result_data->result, vote);
  222. return 0;
  223. }
  224. static int report_slot_reset(struct pci_dev *dev, void *data)
  225. {
  226. pci_ers_result_t vote;
  227. struct pci_error_handlers *err_handler;
  228. struct aer_broadcast_data *result_data;
  229. result_data = (struct aer_broadcast_data *) data;
  230. if (!dev->driver ||
  231. !dev->driver->err_handler ||
  232. !dev->driver->err_handler->slot_reset)
  233. return 0;
  234. err_handler = dev->driver->err_handler;
  235. vote = err_handler->slot_reset(dev);
  236. result_data->result = merge_result(result_data->result, vote);
  237. return 0;
  238. }
  239. static int report_resume(struct pci_dev *dev, void *data)
  240. {
  241. struct pci_error_handlers *err_handler;
  242. dev->error_state = pci_channel_io_normal;
  243. if (!dev->driver ||
  244. !dev->driver->err_handler ||
  245. !dev->driver->err_handler->resume)
  246. return 0;
  247. err_handler = dev->driver->err_handler;
  248. err_handler->resume(dev);
  249. return 0;
  250. }
  251. /**
  252. * broadcast_error_message - handle message broadcast to downstream drivers
  253. * @dev: pointer to from where in a hierarchy message is broadcasted down
  254. * @state: error state
  255. * @error_mesg: message to print
  256. * @cb: callback to be broadcasted
  257. *
  258. * Invoked during error recovery process. Once being invoked, the content
  259. * of error severity will be broadcasted to all downstream drivers in a
  260. * hierarchy in question.
  261. */
  262. static pci_ers_result_t broadcast_error_message(struct pci_dev *dev,
  263. enum pci_channel_state state,
  264. char *error_mesg,
  265. int (*cb)(struct pci_dev *, void *))
  266. {
  267. struct aer_broadcast_data result_data;
  268. dev_printk(KERN_DEBUG, &dev->dev, "broadcast %s message\n", error_mesg);
  269. result_data.state = state;
  270. if (cb == report_error_detected)
  271. result_data.result = PCI_ERS_RESULT_CAN_RECOVER;
  272. else
  273. result_data.result = PCI_ERS_RESULT_RECOVERED;
  274. if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE) {
  275. /*
  276. * If the error is reported by a bridge, we think this error
  277. * is related to the downstream link of the bridge, so we
  278. * do error recovery on all subordinates of the bridge instead
  279. * of the bridge and clear the error status of the bridge.
  280. */
  281. if (cb == report_error_detected)
  282. dev->error_state = state;
  283. pci_walk_bus(dev->subordinate, cb, &result_data);
  284. if (cb == report_resume) {
  285. pci_cleanup_aer_uncorrect_error_status(dev);
  286. dev->error_state = pci_channel_io_normal;
  287. }
  288. }
  289. else {
  290. /*
  291. * If the error is reported by an end point, we think this
  292. * error is related to the upstream link of the end point.
  293. */
  294. pci_walk_bus(dev->bus, cb, &result_data);
  295. }
  296. return result_data.result;
  297. }
  298. struct find_aer_service_data {
  299. struct pcie_port_service_driver *aer_driver;
  300. int is_downstream;
  301. };
  302. static int find_aer_service_iter(struct device *device, void *data)
  303. {
  304. struct device_driver *driver;
  305. struct pcie_port_service_driver *service_driver;
  306. struct find_aer_service_data *result;
  307. result = (struct find_aer_service_data *) data;
  308. if (device->bus == &pcie_port_bus_type) {
  309. struct pcie_port_data *port_data;
  310. port_data = pci_get_drvdata(to_pcie_device(device)->port);
  311. if (port_data->port_type == PCIE_SW_DOWNSTREAM_PORT)
  312. result->is_downstream = 1;
  313. driver = device->driver;
  314. if (driver) {
  315. service_driver = to_service_driver(driver);
  316. if (service_driver->service == PCIE_PORT_SERVICE_AER) {
  317. result->aer_driver = service_driver;
  318. return 1;
  319. }
  320. }
  321. }
  322. return 0;
  323. }
  324. static void find_aer_service(struct pci_dev *dev,
  325. struct find_aer_service_data *data)
  326. {
  327. int retval;
  328. retval = device_for_each_child(&dev->dev, data, find_aer_service_iter);
  329. }
  330. static pci_ers_result_t reset_link(struct pcie_device *aerdev,
  331. struct pci_dev *dev)
  332. {
  333. struct pci_dev *udev;
  334. pci_ers_result_t status;
  335. struct find_aer_service_data data;
  336. if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE)
  337. udev = dev;
  338. else
  339. udev= dev->bus->self;
  340. data.is_downstream = 0;
  341. data.aer_driver = NULL;
  342. find_aer_service(udev, &data);
  343. /*
  344. * Use the aer driver of the error agent firstly.
  345. * If it hasn't the aer driver, use the root port's
  346. */
  347. if (!data.aer_driver || !data.aer_driver->reset_link) {
  348. if (data.is_downstream &&
  349. aerdev->device.driver &&
  350. to_service_driver(aerdev->device.driver)->reset_link) {
  351. data.aer_driver =
  352. to_service_driver(aerdev->device.driver);
  353. } else {
  354. dev_printk(KERN_DEBUG, &dev->dev, "no link-reset "
  355. "support\n");
  356. return PCI_ERS_RESULT_DISCONNECT;
  357. }
  358. }
  359. status = data.aer_driver->reset_link(udev);
  360. if (status != PCI_ERS_RESULT_RECOVERED) {
  361. dev_printk(KERN_DEBUG, &dev->dev, "link reset at upstream "
  362. "device %s failed\n", pci_name(udev));
  363. return PCI_ERS_RESULT_DISCONNECT;
  364. }
  365. return status;
  366. }
  367. /**
  368. * do_recovery - handle nonfatal/fatal error recovery process
  369. * @aerdev: pointer to a pcie_device data structure of root port
  370. * @dev: pointer to a pci_dev data structure of agent detecting an error
  371. * @severity: error severity type
  372. *
  373. * Invoked when an error is nonfatal/fatal. Once being invoked, broadcast
  374. * error detected message to all downstream drivers within a hierarchy in
  375. * question and return the returned code.
  376. */
  377. static pci_ers_result_t do_recovery(struct pcie_device *aerdev,
  378. struct pci_dev *dev,
  379. int severity)
  380. {
  381. pci_ers_result_t status, result = PCI_ERS_RESULT_RECOVERED;
  382. enum pci_channel_state state;
  383. if (severity == AER_FATAL)
  384. state = pci_channel_io_frozen;
  385. else
  386. state = pci_channel_io_normal;
  387. status = broadcast_error_message(dev,
  388. state,
  389. "error_detected",
  390. report_error_detected);
  391. if (severity == AER_FATAL) {
  392. result = reset_link(aerdev, dev);
  393. if (result != PCI_ERS_RESULT_RECOVERED) {
  394. /* TODO: Should panic here? */
  395. return result;
  396. }
  397. }
  398. if (status == PCI_ERS_RESULT_CAN_RECOVER)
  399. status = broadcast_error_message(dev,
  400. state,
  401. "mmio_enabled",
  402. report_mmio_enabled);
  403. if (status == PCI_ERS_RESULT_NEED_RESET) {
  404. /*
  405. * TODO: Should call platform-specific
  406. * functions to reset slot before calling
  407. * drivers' slot_reset callbacks?
  408. */
  409. status = broadcast_error_message(dev,
  410. state,
  411. "slot_reset",
  412. report_slot_reset);
  413. }
  414. if (status == PCI_ERS_RESULT_RECOVERED)
  415. broadcast_error_message(dev,
  416. state,
  417. "resume",
  418. report_resume);
  419. return status;
  420. }
  421. /**
  422. * handle_error_source - handle logging error into an event log
  423. * @aerdev: pointer to pcie_device data structure of the root port
  424. * @dev: pointer to pci_dev data structure of error source device
  425. * @info: comprehensive error information
  426. *
  427. * Invoked when an error being detected by Root Port.
  428. */
  429. static void handle_error_source(struct pcie_device * aerdev,
  430. struct pci_dev *dev,
  431. struct aer_err_info info)
  432. {
  433. pci_ers_result_t status = 0;
  434. int pos;
  435. if (info.severity == AER_CORRECTABLE) {
  436. /*
  437. * Correctable error does not need software intevention.
  438. * No need to go through error recovery process.
  439. */
  440. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
  441. if (pos)
  442. pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS,
  443. info.status);
  444. } else {
  445. status = do_recovery(aerdev, dev, info.severity);
  446. if (status == PCI_ERS_RESULT_RECOVERED) {
  447. dev_printk(KERN_DEBUG, &dev->dev, "AER driver "
  448. "successfully recovered\n");
  449. } else {
  450. /* TODO: Should kernel panic here? */
  451. dev_printk(KERN_DEBUG, &dev->dev, "AER driver didn't "
  452. "recover\n");
  453. }
  454. }
  455. }
  456. /**
  457. * aer_enable_rootport - enable Root Port's interrupts when receiving messages
  458. * @rpc: pointer to a Root Port data structure
  459. *
  460. * Invoked when PCIE bus loads AER service driver.
  461. */
  462. void aer_enable_rootport(struct aer_rpc *rpc)
  463. {
  464. struct pci_dev *pdev = rpc->rpd->port;
  465. int pos, aer_pos;
  466. u16 reg16;
  467. u32 reg32;
  468. pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
  469. /* Clear PCIE Capability's Device Status */
  470. pci_read_config_word(pdev, pos+PCI_EXP_DEVSTA, &reg16);
  471. pci_write_config_word(pdev, pos+PCI_EXP_DEVSTA, reg16);
  472. /* Disable system error generation in response to error messages */
  473. pci_read_config_word(pdev, pos + PCI_EXP_RTCTL, &reg16);
  474. reg16 &= ~(SYSTEM_ERROR_INTR_ON_MESG_MASK);
  475. pci_write_config_word(pdev, pos + PCI_EXP_RTCTL, reg16);
  476. aer_pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
  477. /* Clear error status */
  478. pci_read_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, &reg32);
  479. pci_write_config_dword(pdev, aer_pos + PCI_ERR_ROOT_STATUS, reg32);
  480. pci_read_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, &reg32);
  481. pci_write_config_dword(pdev, aer_pos + PCI_ERR_COR_STATUS, reg32);
  482. pci_read_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, &reg32);
  483. pci_write_config_dword(pdev, aer_pos + PCI_ERR_UNCOR_STATUS, reg32);
  484. /*
  485. * Enable error reporting for the root port device and downstream port
  486. * devices.
  487. */
  488. set_downstream_devices_error_reporting(pdev, true);
  489. /* Enable Root Port's interrupt in response to error messages */
  490. pci_write_config_dword(pdev,
  491. aer_pos + PCI_ERR_ROOT_COMMAND,
  492. ROOT_PORT_INTR_ON_MESG_MASK);
  493. }
  494. /**
  495. * disable_root_aer - disable Root Port's interrupts when receiving messages
  496. * @rpc: pointer to a Root Port data structure
  497. *
  498. * Invoked when PCIE bus unloads AER service driver.
  499. */
  500. static void disable_root_aer(struct aer_rpc *rpc)
  501. {
  502. struct pci_dev *pdev = rpc->rpd->port;
  503. u32 reg32;
  504. int pos;
  505. /*
  506. * Disable error reporting for the root port device and downstream port
  507. * devices.
  508. */
  509. set_downstream_devices_error_reporting(pdev, false);
  510. pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ERR);
  511. /* Disable Root's interrupt in response to error messages */
  512. pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_COMMAND, 0);
  513. /* Clear Root's error status reg */
  514. pci_read_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, &reg32);
  515. pci_write_config_dword(pdev, pos + PCI_ERR_ROOT_STATUS, reg32);
  516. }
  517. /**
  518. * get_e_source - retrieve an error source
  519. * @rpc: pointer to the root port which holds an error
  520. *
  521. * Invoked by DPC handler to consume an error.
  522. */
  523. static struct aer_err_source* get_e_source(struct aer_rpc *rpc)
  524. {
  525. struct aer_err_source *e_source;
  526. unsigned long flags;
  527. /* Lock access to Root error producer/consumer index */
  528. spin_lock_irqsave(&rpc->e_lock, flags);
  529. if (rpc->prod_idx == rpc->cons_idx) {
  530. spin_unlock_irqrestore(&rpc->e_lock, flags);
  531. return NULL;
  532. }
  533. e_source = &rpc->e_sources[rpc->cons_idx];
  534. rpc->cons_idx++;
  535. if (rpc->cons_idx == AER_ERROR_SOURCES_MAX)
  536. rpc->cons_idx = 0;
  537. spin_unlock_irqrestore(&rpc->e_lock, flags);
  538. return e_source;
  539. }
  540. static int get_device_error_info(struct pci_dev *dev, struct aer_err_info *info)
  541. {
  542. int pos;
  543. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
  544. /* The device might not support AER */
  545. if (!pos)
  546. return AER_SUCCESS;
  547. if (info->severity == AER_CORRECTABLE) {
  548. pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS,
  549. &info->status);
  550. if (!(info->status & ERR_CORRECTABLE_ERROR_MASK))
  551. return AER_UNSUCCESS;
  552. } else if (dev->hdr_type & PCI_HEADER_TYPE_BRIDGE ||
  553. info->severity == AER_NONFATAL) {
  554. /* Link is still healthy for IO reads */
  555. pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS,
  556. &info->status);
  557. if (!(info->status & ERR_UNCORRECTABLE_ERROR_MASK))
  558. return AER_UNSUCCESS;
  559. if (info->status & AER_LOG_TLP_MASKS) {
  560. info->flags |= AER_TLP_HEADER_VALID_FLAG;
  561. pci_read_config_dword(dev,
  562. pos + PCI_ERR_HEADER_LOG, &info->tlp.dw0);
  563. pci_read_config_dword(dev,
  564. pos + PCI_ERR_HEADER_LOG + 4, &info->tlp.dw1);
  565. pci_read_config_dword(dev,
  566. pos + PCI_ERR_HEADER_LOG + 8, &info->tlp.dw2);
  567. pci_read_config_dword(dev,
  568. pos + PCI_ERR_HEADER_LOG + 12, &info->tlp.dw3);
  569. }
  570. }
  571. return AER_SUCCESS;
  572. }
  573. /**
  574. * aer_isr_one_error - consume an error detected by root port
  575. * @p_device: pointer to error root port service device
  576. * @e_src: pointer to an error source
  577. */
  578. static void aer_isr_one_error(struct pcie_device *p_device,
  579. struct aer_err_source *e_src)
  580. {
  581. struct device *s_device;
  582. struct aer_err_info e_info = {0, 0, 0,};
  583. int i;
  584. u16 id;
  585. /*
  586. * There is a possibility that both correctable error and
  587. * uncorrectable error being logged. Report correctable error first.
  588. */
  589. for (i = 1; i & ROOT_ERR_STATUS_MASKS ; i <<= 2) {
  590. if (i > 4)
  591. break;
  592. if (!(e_src->status & i))
  593. continue;
  594. /* Init comprehensive error information */
  595. if (i & PCI_ERR_ROOT_COR_RCV) {
  596. id = ERR_COR_ID(e_src->id);
  597. e_info.severity = AER_CORRECTABLE;
  598. } else {
  599. id = ERR_UNCOR_ID(e_src->id);
  600. e_info.severity = ((e_src->status >> 6) & 1);
  601. }
  602. if (e_src->status &
  603. (PCI_ERR_ROOT_MULTI_COR_RCV |
  604. PCI_ERR_ROOT_MULTI_UNCOR_RCV))
  605. e_info.flags |= AER_MULTI_ERROR_VALID_FLAG;
  606. if (!(s_device = find_source_device(p_device->port, id))) {
  607. printk(KERN_DEBUG "%s->can't find device of ID%04x\n",
  608. __func__, id);
  609. continue;
  610. }
  611. if (get_device_error_info(to_pci_dev(s_device), &e_info) ==
  612. AER_SUCCESS) {
  613. aer_print_error(to_pci_dev(s_device), &e_info);
  614. handle_error_source(p_device,
  615. to_pci_dev(s_device),
  616. e_info);
  617. }
  618. }
  619. }
  620. /**
  621. * aer_isr - consume errors detected by root port
  622. * @work: definition of this work item
  623. *
  624. * Invoked, as DPC, when root port records new detected error
  625. */
  626. void aer_isr(struct work_struct *work)
  627. {
  628. struct aer_rpc *rpc = container_of(work, struct aer_rpc, dpc_handler);
  629. struct pcie_device *p_device = rpc->rpd;
  630. struct aer_err_source *e_src;
  631. mutex_lock(&rpc->rpc_mutex);
  632. e_src = get_e_source(rpc);
  633. while (e_src) {
  634. aer_isr_one_error(p_device, e_src);
  635. e_src = get_e_source(rpc);
  636. }
  637. mutex_unlock(&rpc->rpc_mutex);
  638. wake_up(&rpc->wait_release);
  639. }
  640. /**
  641. * aer_delete_rootport - disable root port aer and delete service data
  642. * @rpc: pointer to a root port device being deleted
  643. *
  644. * Invoked when AER service unloaded on a specific Root Port
  645. */
  646. void aer_delete_rootport(struct aer_rpc *rpc)
  647. {
  648. /* Disable root port AER itself */
  649. disable_root_aer(rpc);
  650. kfree(rpc);
  651. }
  652. /**
  653. * aer_init - provide AER initialization
  654. * @dev: pointer to AER pcie device
  655. *
  656. * Invoked when AER service driver is loaded.
  657. */
  658. int aer_init(struct pcie_device *dev)
  659. {
  660. if (aer_osc_setup(dev) && !forceload)
  661. return -ENXIO;
  662. return AER_SUCCESS;
  663. }
  664. EXPORT_SYMBOL_GPL(pci_enable_pcie_error_reporting);
  665. EXPORT_SYMBOL_GPL(pci_disable_pcie_error_reporting);
  666. EXPORT_SYMBOL_GPL(pci_cleanup_aer_uncorrect_error_status);