Merge git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[linux-2.6] / drivers / infiniband / hw / ipath / ipath_layer.h
1 /*
2  * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32
33 #ifndef _IPATH_LAYER_H
34 #define _IPATH_LAYER_H
35
36 /*
37  * This header file is for symbols shared between the infinipath driver
38  * and drivers layered upon it (such as ipath).
39  */
40
41 struct sk_buff;
42 struct ipath_sge_state;
43 struct ipath_devdata;
44 struct ether_header;
45
46 struct ipath_layer_counters {
47         u64 symbol_error_counter;
48         u64 link_error_recovery_counter;
49         u64 link_downed_counter;
50         u64 port_rcv_errors;
51         u64 port_rcv_remphys_errors;
52         u64 port_xmit_discards;
53         u64 port_xmit_data;
54         u64 port_rcv_data;
55         u64 port_xmit_packets;
56         u64 port_rcv_packets;
57 };
58
59 /*
60  * A segment is a linear region of low physical memory.
61  * XXX Maybe we should use phys addr here and kmap()/kunmap().
62  * Used by the verbs layer.
63  */
64 struct ipath_seg {
65         void *vaddr;
66         size_t length;
67 };
68
69 /* The number of ipath_segs that fit in a page. */
70 #define IPATH_SEGSZ     (PAGE_SIZE / sizeof (struct ipath_seg))
71
72 struct ipath_segarray {
73         struct ipath_seg segs[IPATH_SEGSZ];
74 };
75
76 struct ipath_mregion {
77         u64 user_base;          /* User's address for this region */
78         u64 iova;               /* IB start address of this region */
79         size_t length;
80         u32 lkey;
81         u32 offset;             /* offset (bytes) to start of region */
82         int access_flags;
83         u32 max_segs;           /* number of ipath_segs in all the arrays */
84         u32 mapsz;              /* size of the map array */
85         struct ipath_segarray *map[0];  /* the segments */
86 };
87
88 /*
89  * These keep track of the copy progress within a memory region.
90  * Used by the verbs layer.
91  */
92 struct ipath_sge {
93         struct ipath_mregion *mr;
94         void *vaddr;            /* current pointer into the segment */
95         u32 sge_length;         /* length of the SGE */
96         u32 length;             /* remaining length of the segment */
97         u16 m;                  /* current index: mr->map[m] */
98         u16 n;                  /* current index: mr->map[m]->segs[n] */
99 };
100
101 struct ipath_sge_state {
102         struct ipath_sge *sg_list;      /* next SGE to be used if any */
103         struct ipath_sge sge;   /* progress state for the current SGE */
104         u8 num_sge;
105 };
106
107 int ipath_layer_register(void *(*l_add)(int, struct ipath_devdata *),
108                          void (*l_remove)(void *),
109                          int (*l_intr)(void *, u32),
110                          int (*l_rcv)(void *, void *,
111                                       struct sk_buff *),
112                          u16 rcv_opcode,
113                          int (*l_rcv_lid)(void *, void *));
114 int ipath_verbs_register(void *(*l_add)(int, struct ipath_devdata *),
115                          void (*l_remove)(void *arg),
116                          int (*l_piobufavail)(void *arg),
117                          void (*l_rcv)(void *arg, void *rhdr,
118                                        void *data, u32 tlen),
119                          void (*l_timer_cb)(void *arg));
120 void ipath_layer_unregister(void);
121 void ipath_verbs_unregister(void);
122 int ipath_layer_open(struct ipath_devdata *, u32 * pktmax);
123 u16 ipath_layer_get_lid(struct ipath_devdata *dd);
124 int ipath_layer_get_mac(struct ipath_devdata *dd, u8 *);
125 u16 ipath_layer_get_bcast(struct ipath_devdata *dd);
126 u32 ipath_layer_get_cr_errpkey(struct ipath_devdata *dd);
127 int ipath_layer_set_linkstate(struct ipath_devdata *dd, u8 state);
128 int ipath_layer_set_mtu(struct ipath_devdata *, u16);
129 int ipath_set_sps_lid(struct ipath_devdata *, u32, u8);
130 int ipath_layer_send_hdr(struct ipath_devdata *dd,
131                          struct ether_header *hdr);
132 int ipath_verbs_send(struct ipath_devdata *dd, u32 hdrwords,
133                      u32 * hdr, u32 len, struct ipath_sge_state *ss);
134 int ipath_layer_set_piointbufavail_int(struct ipath_devdata *dd);
135 int ipath_layer_get_boardname(struct ipath_devdata *dd, char *name,
136                               size_t namelen);
137 int ipath_layer_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
138                                   u64 *rwords, u64 *spkts, u64 *rpkts,
139                                   u64 *xmit_wait);
140 int ipath_layer_get_counters(struct ipath_devdata *dd,
141                              struct ipath_layer_counters *cntrs);
142 int ipath_layer_want_buffer(struct ipath_devdata *dd);
143 int ipath_layer_set_guid(struct ipath_devdata *, __be64 guid);
144 __be64 ipath_layer_get_guid(struct ipath_devdata *);
145 u32 ipath_layer_get_nguid(struct ipath_devdata *);
146 int ipath_layer_query_device(struct ipath_devdata *, u32 * vendor,
147                              u32 * boardrev, u32 * majrev, u32 * minrev);
148 u32 ipath_layer_get_flags(struct ipath_devdata *dd);
149 struct device *ipath_layer_get_device(struct ipath_devdata *dd);
150 u16 ipath_layer_get_deviceid(struct ipath_devdata *dd);
151 u64 ipath_layer_get_lastibcstat(struct ipath_devdata *dd);
152 u32 ipath_layer_get_ibmtu(struct ipath_devdata *dd);
153 int ipath_layer_enable_timer(struct ipath_devdata *dd);
154 int ipath_layer_disable_timer(struct ipath_devdata *dd);
155 int ipath_layer_set_verbs_flags(struct ipath_devdata *dd, unsigned flags);
156 unsigned ipath_layer_get_npkeys(struct ipath_devdata *dd);
157 unsigned ipath_layer_get_pkey(struct ipath_devdata *dd, unsigned index);
158 int ipath_layer_get_pkeys(struct ipath_devdata *dd, u16 *pkeys);
159 int ipath_layer_set_pkeys(struct ipath_devdata *dd, u16 *pkeys);
160 int ipath_layer_get_linkdowndefaultstate(struct ipath_devdata *dd);
161 int ipath_layer_set_linkdowndefaultstate(struct ipath_devdata *dd,
162                                          int sleep);
163 int ipath_layer_get_phyerrthreshold(struct ipath_devdata *dd);
164 int ipath_layer_set_phyerrthreshold(struct ipath_devdata *dd, unsigned n);
165 int ipath_layer_get_overrunthreshold(struct ipath_devdata *dd);
166 int ipath_layer_set_overrunthreshold(struct ipath_devdata *dd, unsigned n);
167 u32 ipath_layer_get_rcvhdrentsize(struct ipath_devdata *dd);
168
169 /* ipath_ether interrupt values */
170 #define IPATH_LAYER_INT_IF_UP 0x2
171 #define IPATH_LAYER_INT_IF_DOWN 0x4
172 #define IPATH_LAYER_INT_LID 0x8
173 #define IPATH_LAYER_INT_SEND_CONTINUE 0x10
174 #define IPATH_LAYER_INT_BCAST 0x40
175
176 /* _verbs_layer.l_flags */
177 #define IPATH_VERBS_KERNEL_SMA 0x1
178
179 extern unsigned ipath_debug; /* debugging bit mask */
180
181 #endif                          /* _IPATH_LAYER_H */