aerdrv_core.c 20 KB

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