blob: bd833ea3ba495e77040a754f203ad42f68f709ea [file] [log] [blame]
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +08001/*
2 * Copyright (C) 2006 Intel Corp.
3 * Tom Long Nguyen (tom.l.nguyen@intel.com)
4 * Zhang Yanmin (yanmin.zhang@intel.com)
5 *
6 */
7
8#ifndef _AERDRV_H_
9#define _AERDRV_H_
10
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040011#include <linux/workqueue.h>
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080012#include <linux/pcieport_if.h>
13#include <linux/aer.h>
Huang Ying634deb02009-04-24 10:45:23 +080014#include <linux/interrupt.h>
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080015
16#define AER_NONFATAL 0
17#define AER_FATAL 1
18#define AER_CORRECTABLE 2
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080019
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080020/* Root Error Status Register Bits */
Hidetoshi Setoc9a91882009-09-07 17:07:29 +090021#define ROOT_ERR_STATUS_MASKS 0x0f
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080022
23#define SYSTEM_ERROR_INTR_ON_MESG_MASK (PCI_EXP_RTCTL_SECEE| \
24 PCI_EXP_RTCTL_SENFEE| \
25 PCI_EXP_RTCTL_SEFEE)
26#define ROOT_PORT_INTR_ON_MESG_MASK (PCI_ERR_ROOT_CMD_COR_EN| \
27 PCI_ERR_ROOT_CMD_NONFATAL_EN| \
28 PCI_ERR_ROOT_CMD_FATAL_EN)
29#define ERR_COR_ID(d) (d & 0xffff)
30#define ERR_UNCOR_ID(d) (d >> 16)
31
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080032#define AER_ERROR_SOURCES_MAX 100
33
34#define AER_LOG_TLP_MASKS (PCI_ERR_UNC_POISON_TLP| \
35 PCI_ERR_UNC_ECRC| \
36 PCI_ERR_UNC_UNSUP| \
37 PCI_ERR_UNC_COMP_ABORT| \
38 PCI_ERR_UNC_UNX_COMP| \
39 PCI_ERR_UNC_MALF_TLP)
40
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080041struct header_log_regs {
42 unsigned int dw0;
43 unsigned int dw1;
44 unsigned int dw2;
45 unsigned int dw3;
46};
47
Zhang, Yanmin3d5505c2009-06-16 13:35:16 +080048#define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080049struct aer_err_info {
Zhang, Yanmin3d5505c2009-06-16 13:35:16 +080050 struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES];
51 int error_dev_num;
Hidetoshi Seto273024d2009-09-07 17:16:20 +090052
53 unsigned int id:16;
54
55 unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */
56 unsigned int __pad1:5;
57 unsigned int multi_error_valid:1;
58
59 unsigned int first_error:5;
60 unsigned int __pad2:2;
61 unsigned int tlp_header_valid:1;
62
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080063 unsigned int status; /* COR/UNCOR Error Status */
Hidetoshi Seto0d90c3a2009-09-07 17:12:25 +090064 unsigned int mask; /* COR/UNCOR Error Mask */
Hidetoshi Setoc9a91882009-09-07 17:07:29 +090065 struct header_log_regs tlp; /* TLP Header */
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080066};
67
68struct aer_err_source {
69 unsigned int status;
70 unsigned int id;
71};
72
73struct aer_rpc {
74 struct pcie_device *rpd; /* Root Port device */
75 struct work_struct dpc_handler;
76 struct aer_err_source e_sources[AER_ERROR_SOURCES_MAX];
77 unsigned short prod_idx; /* Error Producer Index */
78 unsigned short cons_idx; /* Error Consumer Index */
79 int isr;
80 spinlock_t e_lock; /*
81 * Lock access to Error Status/ID Regs
82 * and error producer/consumer index
83 */
84 struct mutex rpc_mutex; /*
85 * only one thread could do
86 * recovery on the same
Uwe Kleine-König1b3c3712007-02-17 19:23:03 +010087 * root port hierarchy
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080088 */
89 wait_queue_head_t wait_release;
90};
91
92struct aer_broadcast_data {
93 enum pci_channel_state state;
94 enum pci_ers_result result;
95};
96
97static inline pci_ers_result_t merge_result(enum pci_ers_result orig,
98 enum pci_ers_result new)
99{
Zhang, Yanmin029091d2009-04-30 14:48:29 +0800100 if (new == PCI_ERS_RESULT_NONE)
101 return orig;
102
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800103 switch (orig) {
104 case PCI_ERS_RESULT_CAN_RECOVER:
105 case PCI_ERS_RESULT_RECOVERED:
106 orig = new;
107 break;
108 case PCI_ERS_RESULT_DISCONNECT:
109 if (new == PCI_ERS_RESULT_NEED_RESET)
110 orig = new;
111 break;
112 default:
113 break;
114 }
115
116 return orig;
117}
118
119extern struct bus_type pcie_port_bus_type;
120extern void aer_enable_rootport(struct aer_rpc *rpc);
121extern void aer_delete_rootport(struct aer_rpc *rpc);
122extern int aer_init(struct pcie_device *dev);
David Howells65f27f32006-11-22 14:55:48 +0000123extern void aer_isr(struct work_struct *work);
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800124extern void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
Hidetoshi Seto79e4b892009-09-07 17:16:45 +0900125extern void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info);
Huang Ying634deb02009-04-24 10:45:23 +0800126extern irqreturn_t aer_irq(int irq, void *context);
Zhang, Yanmin8d29bfb2007-06-06 11:44:16 +0800127
128#ifdef CONFIG_ACPI
129extern int aer_osc_setup(struct pcie_device *pciedev);
130#else
131static inline int aer_osc_setup(struct pcie_device *pciedev)
132{
133 return 0;
134}
135#endif
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800136
Hidetoshi Setoc9a91882009-09-07 17:07:29 +0900137#endif /* _AERDRV_H_ */