aerdrv_core.c 20 KB

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