aerdrv_core.c 19 KB

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