Pull percpu-dtc into release branch
[pandora-kernel.git] / arch / ia64 / sn / kernel / huberror.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1992 - 1997, 2000,2002-2007 Silicon Graphics, Inc. All rights reserved.
7  */
8
9 #include <linux/types.h>
10 #include <linux/interrupt.h>
11 #include <linux/pci.h>
12 #include <asm/delay.h>
13 #include <asm/sn/sn_sal.h>
14 #include "ioerror.h"
15 #include <asm/sn/addrs.h>
16 #include <asm/sn/shubio.h>
17 #include <asm/sn/geo.h>
18 #include "xtalk/xwidgetdev.h"
19 #include "xtalk/hubdev.h"
20 #include <asm/sn/bte.h>
21
22 void hubiio_crb_error_handler(struct hubdev_info *hubdev_info);
23 extern void bte_crb_error_handler(cnodeid_t, int, int, ioerror_t *,
24                                   int);
25 static irqreturn_t hub_eint_handler(int irq, void *arg)
26 {
27         struct hubdev_info *hubdev_info;
28         struct ia64_sal_retval ret_stuff;
29         nasid_t nasid;
30
31         ret_stuff.status = 0;
32         ret_stuff.v0 = 0;
33         hubdev_info = (struct hubdev_info *)arg;
34         nasid = hubdev_info->hdi_nasid;
35
36         if (is_shub1()) {
37                 SAL_CALL_NOLOCK(ret_stuff, SN_SAL_HUB_ERROR_INTERRUPT,
38                         (u64) nasid, 0, 0, 0, 0, 0, 0);
39
40                 if ((int)ret_stuff.v0)
41                         panic("%s: Fatal %s Error", __FUNCTION__,
42                                 ((nasid & 1) ? "TIO" : "HUBII"));
43
44                 if (!(nasid & 1)) /* Not a TIO, handle CRB errors */
45                         (void)hubiio_crb_error_handler(hubdev_info);
46         } else
47                 if (nasid & 1) {        /* TIO errors */
48                         SAL_CALL_NOLOCK(ret_stuff, SN_SAL_HUB_ERROR_INTERRUPT,
49                                 (u64) nasid, 0, 0, 0, 0, 0, 0);
50
51                         if ((int)ret_stuff.v0)
52                                 panic("%s: Fatal TIO Error", __FUNCTION__);
53                 } else
54                         bte_error_handler((unsigned long)NODEPDA(nasid_to_cnodeid(nasid)));
55
56         return IRQ_HANDLED;
57 }
58
59 /*
60  * Free the hub CRB "crbnum" which encountered an error.
61  * Assumption is, error handling was successfully done,
62  * and we now want to return the CRB back to Hub for normal usage.
63  *
64  * In order to free the CRB, all that's needed is to de-allocate it
65  *
66  * Assumption:
67  *      No other processor is mucking around with the hub control register.
68  *      So, upper layer has to single thread this.
69  */
70 void hubiio_crb_free(struct hubdev_info *hubdev_info, int crbnum)
71 {
72         ii_icrb0_b_u_t icrbb;
73
74         /*
75          * The hardware does NOT clear the mark bit, so it must get cleared
76          * here to be sure the error is not processed twice.
77          */
78         icrbb.ii_icrb0_b_regval = REMOTE_HUB_L(hubdev_info->hdi_nasid,
79                                                IIO_ICRB_B(crbnum));
80         icrbb.b_mark = 0;
81         REMOTE_HUB_S(hubdev_info->hdi_nasid, IIO_ICRB_B(crbnum),
82                      icrbb.ii_icrb0_b_regval);
83         /*
84          * Deallocate the register wait till hub indicates it's done.
85          */
86         REMOTE_HUB_S(hubdev_info->hdi_nasid, IIO_ICDR, (IIO_ICDR_PND | crbnum));
87         while (REMOTE_HUB_L(hubdev_info->hdi_nasid, IIO_ICDR) & IIO_ICDR_PND)
88                 cpu_relax();
89
90 }
91
92 /*
93  * hubiio_crb_error_handler
94  *
95  *      This routine gets invoked when a hub gets an error 
96  *      interrupt. So, the routine is running in interrupt context
97  *      at error interrupt level.
98  * Action:
99  *      It's responsible for identifying ALL the CRBs that are marked
100  *      with error, and process them. 
101  *      
102  *      If you find the CRB that's marked with error, map this to the
103  *      reason it caused error, and invoke appropriate error handler.
104  *
105  *      XXX Be aware of the information in the context register.
106  *
107  * NOTE:
108  *      Use REMOTE_HUB_* macro instead of LOCAL_HUB_* so that the interrupt
109  *      handler can be run on any node. (not necessarily the node 
110  *      corresponding to the hub that encountered error).
111  */
112
113 void hubiio_crb_error_handler(struct hubdev_info *hubdev_info)
114 {
115         nasid_t nasid;
116         ii_icrb0_a_u_t icrba;   /* II CRB Register A */
117         ii_icrb0_b_u_t icrbb;   /* II CRB Register B */
118         ii_icrb0_c_u_t icrbc;   /* II CRB Register C */
119         ii_icrb0_d_u_t icrbd;   /* II CRB Register D */
120         ii_icrb0_e_u_t icrbe;   /* II CRB Register D */
121         int i;
122         int num_errors = 0;     /* Num of errors handled */
123         ioerror_t ioerror;
124
125         nasid = hubdev_info->hdi_nasid;
126
127         /*
128          * XXX - Add locking for any recovery actions
129          */
130         /*
131          * Scan through all CRBs in the Hub, and handle the errors
132          * in any of the CRBs marked.
133          */
134         for (i = 0; i < IIO_NUM_CRBS; i++) {
135                 /* Check this crb entry to see if it is in error. */
136                 icrbb.ii_icrb0_b_regval = REMOTE_HUB_L(nasid, IIO_ICRB_B(i));
137
138                 if (icrbb.b_mark == 0) {
139                         continue;
140                 }
141
142                 icrba.ii_icrb0_a_regval = REMOTE_HUB_L(nasid, IIO_ICRB_A(i));
143
144                 IOERROR_INIT(&ioerror);
145
146                 /* read other CRB error registers. */
147                 icrbc.ii_icrb0_c_regval = REMOTE_HUB_L(nasid, IIO_ICRB_C(i));
148                 icrbd.ii_icrb0_d_regval = REMOTE_HUB_L(nasid, IIO_ICRB_D(i));
149                 icrbe.ii_icrb0_e_regval = REMOTE_HUB_L(nasid, IIO_ICRB_E(i));
150
151                 IOERROR_SETVALUE(&ioerror, errortype, icrbb.b_ecode);
152
153                 /* Check if this error is due to BTE operation,
154                  * and handle it separately.
155                  */
156                 if (icrbd.d_bteop ||
157                     ((icrbb.b_initiator == IIO_ICRB_INIT_BTE0 ||
158                       icrbb.b_initiator == IIO_ICRB_INIT_BTE1) &&
159                      (icrbb.b_imsgtype == IIO_ICRB_IMSGT_BTE ||
160                       icrbb.b_imsgtype == IIO_ICRB_IMSGT_SN1NET))) {
161
162                         int bte_num;
163
164                         if (icrbd.d_bteop)
165                                 bte_num = icrbc.c_btenum;
166                         else    /* b_initiator bit 2 gives BTE number */
167                                 bte_num = (icrbb.b_initiator & 0x4) >> 2;
168
169                         hubiio_crb_free(hubdev_info, i);
170
171                         bte_crb_error_handler(nasid_to_cnodeid(nasid), bte_num,
172                                               i, &ioerror, icrbd.d_bteop);
173                         num_errors++;
174                         continue;
175                 }
176         }
177 }
178
179 /*
180  * Function     : hub_error_init
181  * Purpose      : initialize the error handling requirements for a given hub.
182  * Parameters   : cnode, the compact nodeid.
183  * Assumptions  : Called only once per hub, either by a local cpu. Or by a
184  *                      remote cpu, when this hub is headless.(cpuless)
185  * Returns      : None
186  */
187 void hub_error_init(struct hubdev_info *hubdev_info)
188 {
189         if (request_irq(SGI_II_ERROR, hub_eint_handler, IRQF_SHARED,
190                         "SN_hub_error", (void *)hubdev_info))
191                 printk("hub_error_init: Failed to request_irq for 0x%p\n",
192                     hubdev_info);
193         return;
194 }
195
196
197 /*
198  * Function     : ice_error_init
199  * Purpose      : initialize the error handling requirements for a given tio.
200  * Parameters   : cnode, the compact nodeid.
201  * Assumptions  : Called only once per tio.
202  * Returns      : None
203  */
204 void ice_error_init(struct hubdev_info *hubdev_info)
205 {
206         if (request_irq
207             (SGI_TIO_ERROR, (void *)hub_eint_handler, IRQF_SHARED, "SN_TIO_error",
208              (void *)hubdev_info))
209                 printk("ice_error_init: request_irq() error hubdev_info 0x%p\n",
210                        hubdev_info);
211         return;
212 }
213