blob: 3a69ddefe361eabae7457763e636618d6cd69741 [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
19#define AER_UNCORRECTABLE 4
20#define AER_ERROR_MASK 0x001fffff
21#define AER_ERROR(d) (d & AER_ERROR_MASK)
22
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080023/* Root Error Status Register Bits */
24#define ROOT_ERR_STATUS_MASKS 0x0f
25
26#define SYSTEM_ERROR_INTR_ON_MESG_MASK (PCI_EXP_RTCTL_SECEE| \
27 PCI_EXP_RTCTL_SENFEE| \
28 PCI_EXP_RTCTL_SEFEE)
29#define ROOT_PORT_INTR_ON_MESG_MASK (PCI_ERR_ROOT_CMD_COR_EN| \
30 PCI_ERR_ROOT_CMD_NONFATAL_EN| \
31 PCI_ERR_ROOT_CMD_FATAL_EN)
32#define ERR_COR_ID(d) (d & 0xffff)
33#define ERR_UNCOR_ID(d) (d >> 16)
34
35#define AER_SUCCESS 0
36#define AER_UNSUCCESS 1
37#define AER_ERROR_SOURCES_MAX 100
38
39#define AER_LOG_TLP_MASKS (PCI_ERR_UNC_POISON_TLP| \
40 PCI_ERR_UNC_ECRC| \
41 PCI_ERR_UNC_UNSUP| \
42 PCI_ERR_UNC_COMP_ABORT| \
43 PCI_ERR_UNC_UNX_COMP| \
44 PCI_ERR_UNC_MALF_TLP)
45
46/* AER Error Info Flags */
47#define AER_TLP_HEADER_VALID_FLAG 0x00000001
48#define AER_MULTI_ERROR_VALID_FLAG 0x00000002
49
50#define ERR_CORRECTABLE_ERROR_MASK 0x000031c1
51#define ERR_UNCORRECTABLE_ERROR_MASK 0x001ff010
52
53struct header_log_regs {
54 unsigned int dw0;
55 unsigned int dw1;
56 unsigned int dw2;
57 unsigned int dw3;
58};
59
60struct aer_err_info {
61 int severity; /* 0:NONFATAL | 1:FATAL | 2:COR */
62 int flags;
63 unsigned int status; /* COR/UNCOR Error Status */
64 struct header_log_regs tlp; /* TLP Header */
65};
66
67struct aer_err_source {
68 unsigned int status;
69 unsigned int id;
70};
71
72struct aer_rpc {
73 struct pcie_device *rpd; /* Root Port device */
74 struct work_struct dpc_handler;
75 struct aer_err_source e_sources[AER_ERROR_SOURCES_MAX];
76 unsigned short prod_idx; /* Error Producer Index */
77 unsigned short cons_idx; /* Error Consumer Index */
78 int isr;
79 spinlock_t e_lock; /*
80 * Lock access to Error Status/ID Regs
81 * and error producer/consumer index
82 */
83 struct mutex rpc_mutex; /*
84 * only one thread could do
85 * recovery on the same
Uwe Kleine-König1b3c3712007-02-17 19:23:03 +010086 * root port hierarchy
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080087 */
88 wait_queue_head_t wait_release;
89};
90
91struct aer_broadcast_data {
92 enum pci_channel_state state;
93 enum pci_ers_result result;
94};
95
96static inline pci_ers_result_t merge_result(enum pci_ers_result orig,
97 enum pci_ers_result new)
98{
Zhang, Yanmin029091d2009-04-30 14:48:29 +080099 if (new == PCI_ERS_RESULT_NONE)
100 return orig;
101
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800102 switch (orig) {
103 case PCI_ERS_RESULT_CAN_RECOVER:
104 case PCI_ERS_RESULT_RECOVERED:
105 orig = new;
106 break;
107 case PCI_ERS_RESULT_DISCONNECT:
108 if (new == PCI_ERS_RESULT_NEED_RESET)
109 orig = new;
110 break;
111 default:
112 break;
113 }
114
115 return orig;
116}
117
118extern struct bus_type pcie_port_bus_type;
119extern void aer_enable_rootport(struct aer_rpc *rpc);
120extern void aer_delete_rootport(struct aer_rpc *rpc);
121extern int aer_init(struct pcie_device *dev);
David Howells65f27f32006-11-22 14:55:48 +0000122extern void aer_isr(struct work_struct *work);
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800123extern void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
Huang Ying634deb02009-04-24 10:45:23 +0800124extern irqreturn_t aer_irq(int irq, void *context);
Zhang, Yanmin8d29bfb2007-06-06 11:44:16 +0800125
126#ifdef CONFIG_ACPI
127extern int aer_osc_setup(struct pcie_device *pciedev);
128#else
129static inline int aer_osc_setup(struct pcie_device *pciedev)
130{
131 return 0;
132}
133#endif
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800134
135#endif //_AERDRV_H_