aerdrv_core.c 20 KB

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