1 /* $Id: shubio.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 1992 - 1997, 2000,2002-2003 Silicon Graphics, Inc. All rights reserved.
11 #include <linux/types.h>
12 #include <linux/slab.h>
14 #include <asm/sn/sgi.h>
15 #include <asm/sn/io.h>
16 #include <asm/sn/iograph.h>
17 #include <asm/sn/invent.h>
18 #include <asm/sn/hcl.h>
19 #include <asm/sn/labelcl.h>
20 #include <asm/sn/sn_private.h>
21 #include <asm/sn/klconfig.h>
22 #include <asm/sn/sn_cpuid.h>
23 #include <asm/sn/pci/pciio.h>
24 #include <asm/sn/pci/pcibr.h>
25 #include <asm/sn/xtalk/xtalk.h>
26 #include <asm/sn/pci/pcibr_private.h>
27 #include <asm/sn/intr.h>
28 #include <asm/sn/ioerror_handling.h>
29 #include <asm/sn/ioerror.h>
30 #include <asm/sn/sn2/shubio.h>
33 error_state_t error_state_get(vertex_hdl_t v);
34 error_return_code_t error_state_set(vertex_hdl_t v,error_state_t new_state);
38 * Get the xtalk provider function pointer for the
54 error_state_t e_state;
58 * Before walking down to the next level, check if
59 * the I/O link is up. If it's been disabled by the
60 * hub ii for some reason, we can't even touch the
63 iio_imem = REMOTE_HUB_L(nasid, IIO_IMEM);
65 if (!(iio_imem & (IIO_IMEM_B0ESD|IIO_IMEM_W0ESD))){
67 * IIO_IMEM_B0ESD getting set, indicates II shutdown
68 * on HUB0 parts.. Hopefully that's not true for
72 * If either one of them is shut down, can't
75 return IOERROR_XTALKLEVEL;
78 /* Get the error state of the hub */
79 e_state = error_state_get(hub_v);
81 cnode = NASID_TO_COMPACT_NODEID(nasid);
83 xswitch = NODEPDA(cnode)->basew_xc;
85 /* Set the error state of the crosstalk device to that of
88 if (error_state_set(xswitch , e_state) ==
89 ERROR_RETURN_CODE_CANNOT_SET_STATE)
90 return(IOERROR_UNHANDLED);
92 /* Clean the error state of the hub if we are in the action handling
95 if (e_state == ERROR_STATE_ACTION)
96 (void)error_state_set(hub_v, ERROR_STATE_NONE);
97 /* hand the error off to the switch or the directly
98 * connected crosstalk device.
100 return xtalk_error_handler(xswitch,
101 error_code, mode, ioerror);
106 * Check if the widget in error has been enabled for PIO accesses
109 is_widget_pio_enabled(ioerror_t *ioerror)
117 /* Get the node where the PIO error occurred */
118 IOERROR_GETVALUE(p,ioerror, srcnode);
120 if (src_node == CNODEID_NONE)
123 /* Get the nasid for the cnode */
124 src_nasid = COMPACT_TO_NASID_NODEID(src_node);
125 if (src_nasid == INVALID_NASID)
128 /* Read the Outbound widget access register for this hub */
129 ii_iowa = REMOTE_HUB_L(src_nasid, IIO_IOWA);
130 IOERROR_GETVALUE(p,ioerror, widgetnum);
133 /* Check if the PIOs to the widget with PIO error have been
136 if (ii_iowa & IIO_IOWA_WIDGET(widget))
143 * Hub IO error handling.
145 * Gets invoked for different types of errors found at the hub.
146 * Typically this includes situations from bus error or due to
147 * an error interrupt (mostly generated at the hub).
154 struct io_error_s *ioerror)
156 hubinfo_t hinfo; /* Hub info pointer */
163 IOERROR_DUMP("hub_ioerror_handler", error_code, mode, ioerror);
165 hubinfo_get(hub_v, &hinfo);
168 /* Print an error message and return */
171 nasid = hinfo->h_nasid;
177 * Cpu got a bus error while accessing IO space.
178 * hubaddr field in ioerror structure should have
179 * the IO address that caused access error.
183 * Identify if the physical address in hub_error_data
184 * corresponds to small/large window, and accordingly,
185 * get the xtalk address.
189 * Evaluate the widget number and the widget address that
190 * caused the error. Use 'vaddr' if it's there.
191 * This is typically true either during probing
192 * or a kernel driver getting into trouble.
193 * Otherwise, use paddr to figure out widget details
194 * This is typically true for user mode bus errors while
195 * accessing I/O space.
197 IOERROR_GETVALUE(cp,ioerror,vaddr);
200 * If neither in small window nor in large window range,
201 * outright reject it.
203 IOERROR_GETVALUE(cp,ioerror,vaddr);
204 if (NODE_SWIN_ADDR(nasid, (paddr_t)cp)){
206 xwidgetnum_t widgetnum;
209 IOERROR_GETVALUE(p,ioerror,hubaddr);
211 widgetnum = SWIN_WIDGETNUM(hubaddr);
212 xtalkaddr = SWIN_WIDGETADDR(hubaddr);
214 * differentiate local register vs IO space access
216 IOERROR_SETVALUE(ioerror,widgetnum,widgetnum);
217 IOERROR_SETVALUE(ioerror,xtalkaddr,xtalkaddr);
220 } else if (NODE_BWIN_ADDR(nasid, (paddr_t)cp)){
222 * Address corresponds to large window space.
223 * Convert it to xtalk address.
226 hub_piomap_t bw_piomap;
227 xtalk_piomap_t xt_pmap = NULL;
229 xwidgetnum_t widgetnum;
232 IOERROR_GETVALUE(p,ioerror,hubaddr);
236 * Have to loop to find the correct xtalk_piomap
237 * because the're not allocated on a one-to-one
238 * basis to the window number.
240 for (bigwin=0; bigwin < HUB_NUM_BIG_WINDOW; bigwin++) {
241 bw_piomap = hubinfo_bwin_piomap_get(hinfo,
244 if (bw_piomap->hpio_bigwin_num ==
245 (BWIN_WINDOWNUM(hubaddr) - 1)) {
246 xt_pmap = hub_piomap_xt_piomap(bw_piomap);
253 widgetnum = xtalk_pio_target_get(xt_pmap);
254 xtalkaddr = xtalk_pio_xtalk_addr_get(xt_pmap) + BWIN_WIDGETADDR(hubaddr);
256 IOERROR_SETVALUE(ioerror,widgetnum,widgetnum);
257 IOERROR_SETVALUE(ioerror,xtalkaddr,xtalkaddr);
260 * Make sure that widgetnum doesnot map to hub
261 * register widget number, as we never use
262 * big window to access hub registers.
264 ASSERT(widgetnum != HUB_REGISTER_WIDGET);
266 } else if (IOERROR_FIELDVALID(ioerror,hubaddr)) {
268 xwidgetnum_t widgetnum;
271 IOERROR_GETVALUE(p,ioerror,hubaddr);
273 if (BWIN_WINDOWNUM(hubaddr)){
274 int window = BWIN_WINDOWNUM(hubaddr) - 1;
276 itte = (hubreg_t)HUB_L(IIO_ITTE_GET(nasid, window));
277 widgetnum = (itte >> IIO_ITTE_WIDGET_SHIFT) &
278 IIO_ITTE_WIDGET_MASK;
279 xtalkaddr = (((itte >> IIO_ITTE_OFFSET_SHIFT) &
280 IIO_ITTE_OFFSET_MASK) <<
282 BWIN_WIDGETADDR(hubaddr);
284 widgetnum = SWIN_WIDGETNUM(hubaddr);
285 xtalkaddr = SWIN_WIDGETADDR(hubaddr);
287 IOERROR_SETVALUE(ioerror,widgetnum,widgetnum);
288 IOERROR_SETVALUE(ioerror,xtalkaddr,xtalkaddr);
290 IOERROR_DUMP("hub_ioerror_handler", error_code,
293 "hub_ioerror_handler: Invalid address passed"));
295 return IOERROR_INVALIDADDR;
299 IOERROR_GETVALUE(p,ioerror,widgetnum);
300 if ((p) == HUB_REGISTER_WIDGET) {
302 * Error in accessing Hub local register
303 * This should happen mostly in SABLE mode..
307 /* Make sure that the outbound widget access for this
310 if (!is_widget_pio_enabled(ioerror)) {
311 if (error_state_get(hub_v) ==
313 snia_ioerror_dump("No outbound widget access - ",
314 error_code, mode, ioerror);
315 return(IOERROR_HANDLED);
319 retval = hub_xp_error_handler(
320 hub_v, nasid, error_code, mode, ioerror);
325 "hub_ioerror_handler:PIO_READ_ERROR return: %d",
330 case PIO_WRITE_ERROR:
332 * This hub received an interrupt indicating a widget
333 * attached to this hub got a timeout.
334 * widgetnum field should be filled to indicate the
335 * widget that caused error.
337 * NOTE: This hub may have nothing to do with this error.
338 * We are here since the widget attached to the xbow
339 * gets its PIOs through this hub.
341 * There is nothing that can be done at this level.
342 * Just invoke the xtalk error handling mechanism.
344 IOERROR_GETVALUE(p,ioerror,widgetnum);
345 if ((p) == HUB_REGISTER_WIDGET) {
347 /* Make sure that the outbound widget access for this
351 if (!is_widget_pio_enabled(ioerror)) {
352 if (error_state_get(hub_v) ==
354 snia_ioerror_dump("No outbound widget access - ",
355 error_code, mode, ioerror);
356 return(IOERROR_HANDLED);
359 retval = hub_xp_error_handler(
360 hub_v, nasid, error_code, mode, ioerror);
366 * DMA Read error always ends up generating an interrupt
367 * at the widget level, and never at the hub level. So,
368 * we don't expect to come here any time
371 retval = IOERROR_UNHANDLED;
374 case DMA_WRITE_ERROR:
376 * DMA Write error is generated when a write by an I/O
377 * device could not be completed. Problem is, device is
378 * totally unaware of this problem, and would continue
379 * writing to system memory. So, hub has a way to send
380 * an error interrupt on the first error, and bitbucket
381 * all further write transactions.
382 * Coming here indicates that hub detected one such error,
383 * and we need to handle it.
385 * Hub interrupt handler would have extracted physaddr,
386 * widgetnum, and widgetdevice from the CRB
388 * There is nothing special to do here, since gathering
389 * data from crb's is done elsewhere. Just pass the
390 * error to xtalk layer.
392 retval = hub_xp_error_handler(hub_v, nasid, error_code, mode,
398 return IOERROR_BADERRORCODE;
403 * If error was not handled, we may need to take certain action
404 * based on the error code.
405 * For e.g. in case of PIO_READ_ERROR, we may need to release the
406 * PIO Read entry table (they are sticky after errors).
407 * Similarly other cases.
412 if (retval == IOERROR_HWGRAPH_LOOKUP) {
414 * If we get errors very early, we can't traverse
415 * the path using hardware graph.
416 * To handle this situation, we need a functions
417 * which don't depend on the hardware graph vertex to
418 * handle errors. This break the modularity of the
419 * existing code. Instead we print out the reason for
420 * not handling error, and return. On return, all the
421 * info collected would be dumped. This should provide
422 * sufficient info to analyse the error.
424 printk("Unable to handle IO error: hardware graph not setup\n");
430 #define INFO_LBL_ERROR_STATE "error_state"
432 #define v_error_state_get(v,s) \
433 (hwgraph_info_get_LBL(v,INFO_LBL_ERROR_STATE, (arbitrary_info_t *)&s))
435 #define v_error_state_set(v,s,replace) \
437 hwgraph_info_replace_LBL(v,INFO_LBL_ERROR_STATE,(arbitrary_info_t)s,0) :\
438 hwgraph_info_add_LBL(v,INFO_LBL_ERROR_STATE, (arbitrary_info_t)s))
441 #define v_error_state_clear(v) \
442 (hwgraph_info_remove_LBL(v,INFO_LBL_ERROR_STATE,0))
446 * Get the state of the vertex.
447 * Returns ERROR_STATE_INVALID on failure
448 * current state otherwise
451 error_state_get(vertex_hdl_t v)
455 /* Check if we have a valid hwgraph vertex */
456 if ( v == (vertex_hdl_t)0 )
457 return(ERROR_STATE_NONE);
459 /* Get the labelled info hanging off the vertex which corresponds
462 if (v_error_state_get(v, s) != GRAPH_SUCCESS) {
463 return(ERROR_STATE_NONE);
471 * Set the state of the vertex
472 * Returns ERROR_RETURN_CODE_CANNOT_SET_STATE on failure
473 * ERROR_RETURN_CODE_SUCCESS otherwise
476 error_state_set(vertex_hdl_t v,error_state_t new_state)
478 error_state_t old_state;
481 /* Check if we have a valid hwgraph vertex */
482 if ( v == (vertex_hdl_t)0 )
483 return(ERROR_RETURN_CODE_GENERAL_FAILURE);
486 /* This means that the error state needs to be cleaned */
487 if (new_state == ERROR_STATE_NONE) {
488 /* Make sure that we have an error state */
489 if (v_error_state_get(v,old_state) == GRAPH_SUCCESS)
490 v_error_state_clear(v);
491 return(ERROR_RETURN_CODE_SUCCESS);
494 /* Check if the state information has been set at least once
497 if (v_error_state_get(v,old_state) != GRAPH_SUCCESS)
500 if (v_error_state_set(v,new_state,replace) != GRAPH_SUCCESS) {
501 return(ERROR_RETURN_CODE_CANNOT_SET_STATE);
503 return(ERROR_RETURN_CODE_SUCCESS);