aerdrv_core.c 19 KB

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