ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ia64 / sn / io / sn2 / bte_error.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) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
7  */
8
9
10 #include <linux/types.h>
11 #include <linux/slab.h>
12 #include <asm/smp.h>
13 #include <asm/sn/sgi.h>
14 #include <asm/sn/io.h>
15 #include <asm/sn/hcl.h>
16 #include <asm/sn/labelcl.h>
17 #include <asm/sn/sn_private.h>
18 #include <asm/sn/klconfig.h>
19 #include <asm/sn/sn_cpuid.h>
20 #include <asm/sn/pci/pciio.h>
21 #include <asm/sn/pci/pcibr.h>
22 #include <asm/sn/xtalk/xtalk.h>
23 #include <asm/sn/pci/pcibr_private.h>
24 #include <asm/sn/intr.h>
25 #include <asm/sn/ioerror.h>
26 #include <asm/sn/sn2/shubio.h>
27 #include <asm/sn/bte.h>
28
29
30 /*
31  * Bte error handling is done in two parts.  The first captures
32  * any crb related errors.  Since there can be multiple crbs per
33  * interface and multiple interfaces active, we need to wait until
34  * all active crbs are completed.  This is the first job of the
35  * second part error handler.  When all bte related CRBs are cleanly
36  * completed, it resets the interfaces and gets them ready for new
37  * transfers to be queued.
38  */
39
40
41 void bte_error_handler(unsigned long);
42
43
44 /*
45  * First part error handler.  This is called whenever any error CRB interrupt
46  * is generated by the II.
47  */
48 void
49 bte_crb_error_handler(vertex_hdl_t hub_v, int btenum,
50                       int crbnum, ioerror_t * ioe, int bteop)
51 {
52         hubinfo_t hinfo;
53         struct bteinfo_s *bte;
54
55
56         hubinfo_get(hub_v, &hinfo);
57         bte = &hinfo->h_nodepda->bte_if[btenum];
58
59         /*
60          * The caller has already figured out the error type, we save that
61          * in the bte handle structure for the thread excercising the
62          * interface to consume.
63          */
64         bte->bh_error = ioe->ie_errortype + BTEFAIL_OFFSET;
65         bte->bte_error_count++;
66
67         BTE_PRINTK(("Got an error on cnode %d bte %d: HW error type 0x%x\n",
68                     bte->bte_cnode, bte->bte_num, ioe->ie_errortype));
69         bte_error_handler((unsigned long) hinfo->h_nodepda);
70 }
71
72
73 /*
74  * Second part error handler.  Wait until all BTE related CRBs are completed
75  * and then reset the interfaces.
76  */
77 void
78 bte_error_handler(unsigned long _nodepda)
79 {
80         struct nodepda_s *err_nodepda = (struct nodepda_s *) _nodepda;
81         spinlock_t *recovery_lock = &err_nodepda->bte_recovery_lock;
82         struct timer_list *recovery_timer = &err_nodepda->bte_recovery_timer;
83         nasid_t nasid;
84         int i;
85         int valid_crbs;
86         unsigned long irq_flags;
87         volatile u64 *notify;
88         bte_result_t bh_error;
89         ii_imem_u_t imem;       /* II IMEM Register */
90         ii_icrb0_d_u_t icrbd;   /* II CRB Register D */
91         ii_ibcr_u_t ibcr;
92         ii_icmr_u_t icmr;
93
94
95         BTE_PRINTK(("bte_error_handler(%p) - %d\n", err_nodepda,
96                     smp_processor_id()));
97
98         spin_lock_irqsave(recovery_lock, irq_flags);
99
100         if ((err_nodepda->bte_if[0].bh_error == BTE_SUCCESS) &&
101             (err_nodepda->bte_if[1].bh_error == BTE_SUCCESS)) {
102                 BTE_PRINTK(("eh:%p:%d Nothing to do.\n", err_nodepda,
103                             smp_processor_id()));
104                 spin_unlock_irqrestore(recovery_lock, irq_flags);
105                 return;
106         }
107         /*
108          * Lock all interfaces on this node to prevent new transfers
109          * from being queued.
110          */
111         for (i = 0; i < BTES_PER_NODE; i++) {
112                 if (err_nodepda->bte_if[i].cleanup_active) {
113                         continue;
114                 }
115                 spin_lock(&err_nodepda->bte_if[i].spinlock);
116                 BTE_PRINTK(("eh:%p:%d locked %d\n", err_nodepda,
117                             smp_processor_id(), i));
118                 err_nodepda->bte_if[i].cleanup_active = 1;
119         }
120
121         /* Determine information about our hub */
122         nasid = cnodeid_to_nasid(err_nodepda->bte_if[0].bte_cnode);
123
124
125         /*
126          * A BTE transfer can use multiple CRBs.  We need to make sure
127          * that all the BTE CRBs are complete (or timed out) before
128          * attempting to clean up the error.  Resetting the BTE while
129          * there are still BTE CRBs active will hang the BTE.
130          * We should look at all the CRBs to see if they are allocated
131          * to the BTE and see if they are still active.  When none
132          * are active, we can continue with the cleanup.
133          *
134          * We also want to make sure that the local NI port is up.
135          * When a router resets the NI port can go down, while it
136          * goes through the LLP handshake, but then comes back up.
137          */
138         icmr.ii_icmr_regval = REMOTE_HUB_L(nasid, IIO_ICMR);
139         if (icmr.ii_icmr_fld_s.i_crb_mark != 0) {
140                 /*
141                  * There are errors which still need to be cleaned up by
142                  * hubiio_crb_error_handler
143                  */
144                 mod_timer(recovery_timer, HZ * 5);
145                 BTE_PRINTK(("eh:%p:%d Marked Giving up\n", err_nodepda,
146                             smp_processor_id()));
147                 spin_unlock_irqrestore(recovery_lock, irq_flags);
148                 return;
149         }
150         if (icmr.ii_icmr_fld_s.i_crb_vld != 0) {
151
152                 valid_crbs = icmr.ii_icmr_fld_s.i_crb_vld;
153
154                 for (i = 0; i < IIO_NUM_CRBS; i++) {
155                         if (!((1 << i) & valid_crbs)) {
156                                 /* This crb was not marked as valid, ignore */
157                                 continue;
158                         }
159                         icrbd.ii_icrb0_d_regval =
160                             REMOTE_HUB_L(nasid, IIO_ICRB_D(i));
161                         if (icrbd.d_bteop) {
162                                 mod_timer(recovery_timer, HZ * 5);
163                                 BTE_PRINTK(("eh:%p:%d Valid %d, Giving up\n",
164                                          err_nodepda, smp_processor_id(), i));
165                                 spin_unlock_irqrestore(recovery_lock,
166                                                        irq_flags);
167                                 return;
168                         }
169                 }
170         }
171
172
173         BTE_PRINTK(("eh:%p:%d Cleaning up\n", err_nodepda,
174                     smp_processor_id()));
175         /* Reenable both bte interfaces */
176         imem.ii_imem_regval = REMOTE_HUB_L(nasid, IIO_IMEM);
177         imem.ii_imem_fld_s.i_b0_esd = imem.ii_imem_fld_s.i_b1_esd = 1;
178         REMOTE_HUB_S(nasid, IIO_IMEM, imem.ii_imem_regval);
179
180         /* Reinitialize both BTE state machines. */
181         ibcr.ii_ibcr_regval = REMOTE_HUB_L(nasid, IIO_IBCR);
182         ibcr.ii_ibcr_fld_s.i_soft_reset = 1;
183         REMOTE_HUB_S(nasid, IIO_IBCR, ibcr.ii_ibcr_regval);
184
185
186         for (i = 0; i < BTES_PER_NODE; i++) {
187                 bh_error = err_nodepda->bte_if[i].bh_error;
188                 if (bh_error != BTE_SUCCESS) {
189                         /* There is an error which needs to be notified */
190                         notify = err_nodepda->bte_if[i].most_rcnt_na;
191                         BTE_PRINTK(("cnode %d bte %d error=0x%lx\n",
192                                     err_nodepda->bte_if[i].bte_cnode,
193                                     err_nodepda->bte_if[i].bte_num,
194                                     IBLS_ERROR | (u64) bh_error));
195                         *notify = IBLS_ERROR | bh_error;
196                         err_nodepda->bte_if[i].bh_error = BTE_SUCCESS;
197                 }
198
199                 err_nodepda->bte_if[i].cleanup_active = 0;
200                 BTE_PRINTK(("eh:%p:%d Unlocked %d\n", err_nodepda,
201                             smp_processor_id(), i));
202                 spin_unlock(&pda->cpu_bte_if[i]->spinlock);
203         }
204
205         del_timer(recovery_timer);
206
207         spin_unlock_irqrestore(recovery_lock, irq_flags);
208 }