4 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it would be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * Further, this software is distributed without any warranty that it is
15 * free of the rightful claim of any third person regarding infringement
16 * or the like. Any license provided herein, whether implied or
17 * otherwise, applies only to this software file. Patent licenses, if
18 * any, provided herein do not apply to combinations of this program with
19 * other software, or any other product whatsoever.
21 * You should have received a copy of the GNU General Public
22 * License along with this program; if not, write the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
25 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26 * Mountain View, CA 94043, or:
30 * For further information regarding this notice, see:
32 * http://oss.sgi.com/projects/GenInfo/NoticeExplan
36 #ifndef _ASM_IA64_SN_BTE_H
37 #define _ASM_IA64_SN_BTE_H
39 #include <linux/timer.h>
40 #include <linux/spinlock.h>
41 #include <linux/cache.h>
42 #include <asm/sn/io.h>
43 #include <asm/delay.h>
46 /* #define BTE_DEBUG */
47 /* #define BTE_DEBUG_VERBOSE */
50 # define BTE_PRINTK(x) printk x /* Terse */
51 # ifdef BTE_DEBUG_VERBOSE
52 # define BTE_PRINTKV(x) printk x /* Verbose */
54 # define BTE_PRINTKV(x)
55 # endif /* BTE_DEBUG_VERBOSE */
57 # define BTE_PRINTK(x)
58 # define BTE_PRINTKV(x)
59 #endif /* BTE_DEBUG */
62 /* BTE status register only supports 16 bits for length field */
63 #define BTE_LEN_BITS (16)
64 #define BTE_LEN_MASK ((1 << BTE_LEN_BITS) - 1)
65 #define BTE_MAX_XFER ((1 << BTE_LEN_BITS) * L1_CACHE_BYTES)
69 #define BTES_PER_NODE 2
72 /* Define hardware modes */
73 #define BTE_NOTIFY (IBCT_NOTIFY)
74 #define BTE_NORMAL BTE_NOTIFY
75 #define BTE_ZERO_FILL (BTE_NOTIFY | IBCT_ZFIL_MODE)
76 /* Use a reserved bit to let the caller specify a wait for any BTE */
77 #define BTE_WACQUIRE (0x4000)
78 /* macro to force the IBCT0 value valid */
79 #define BTE_VALID_MODE(x) ((x) & (IBCT_NOTIFY | IBCT_ZFIL_MODE))
83 * Handle locking of the bte interfaces.
85 * All transfers spinlock the interface before setting up the SHUB
86 * registers. Sync transfers hold the lock until all processing is
87 * complete. Async transfers release the lock as soon as the transfer
90 * To determine if an interface is available, we must check both the
91 * busy bit and the spinlock for that interface.
93 #define BTE_LOCK_IF_AVAIL(_x) (\
94 (*pda->cpu_bte_if[_x]->most_rcnt_na & (IBLS_BUSY | IBLS_ERROR)) && \
95 (!(spin_trylock(&(pda->cpu_bte_if[_x]->spinlock)))) \
99 * Some macros to simplify reading.
100 * Start with macros to locate the BTE control registers.
102 #define BTEREG_LNSTAT_ADDR ((u64 *)(bte->bte_base_addr))
103 #define BTEREG_SRC_ADDR ((u64 *)(bte->bte_base_addr + BTEOFF_SRC))
104 #define BTEREG_DEST_ADDR ((u64 *)(bte->bte_base_addr + BTEOFF_DEST))
105 #define BTEREG_CTRL_ADDR ((u64 *)(bte->bte_base_addr + BTEOFF_CTRL))
106 #define BTEREG_NOTIF_ADDR ((u64 *)(bte->bte_base_addr + BTEOFF_NOTIFY))
109 /* Possible results from bte_copy and bte_unaligned_copy */
111 BTE_SUCCESS, /* 0 is success */
112 BTEFAIL_NOTAVAIL, /* BTE not available */
113 BTEFAIL_POISON, /* poison page */
114 BTEFAIL_PROT, /* Protection violation */
115 BTEFAIL_ACCESS, /* access error */
116 BTEFAIL_TOUT, /* Time out */
117 BTEFAIL_XTERR, /* Diretory error */
118 BTEFAIL_DIR, /* Diretory error */
119 BTEFAIL_ERROR, /* Generic error */
124 * Structure defining a bte. An instance of this
125 * structure is created in the nodepda for each
126 * bte on that node (as defined by BTES_PER_NODE)
127 * This structure contains everything necessary
128 * to work with a BTE.
131 u64 volatile notify ____cacheline_aligned;
132 char *bte_base_addr ____cacheline_aligned;
134 cnodeid_t bte_cnode; /* cnode */
135 int bte_error_count; /* Number of errors encountered */
136 int bte_num; /* 0 --> BTE0, 1 --> BTE1 */
137 int cleanup_active; /* Interface is locked for cleanup */
138 volatile bte_result_t bh_error; /* error while processing */
139 u64 volatile *most_rcnt_na;
140 void *scratch_buf; /* Node local scratch buffer */
145 * Function prototypes (functions defined in bte.c, used elsewhere)
147 extern bte_result_t bte_copy(u64, u64, u64, u64, void *);
148 extern bte_result_t bte_unaligned_copy(u64, u64, u64, u64);
149 extern void bte_error_handler(unsigned long);
153 * The following is the prefered way of calling bte_unaligned_copy
154 * If the copy is fully cache line aligned, then bte_copy is
155 * used instead. Since bte_copy is inlined, this saves a call
156 * stack. NOTE: bte_copy is called synchronously and does block
157 * until the transfer is complete. In order to get the asynch
158 * version of bte_copy, you must perform this check yourself.
160 #define BTE_UNALIGNED_COPY(src, dest, len, mode) \
161 (((len & L1_CACHE_MASK) || (src & L1_CACHE_MASK) || \
162 (dest & L1_CACHE_MASK)) ? \
163 bte_unaligned_copy(src, dest, len, mode) : \
164 bte_copy(src, dest, len, mode, NULL))
167 #endif /* _ASM_IA64_SN_BTE_H */