Whamcloud - gitweb
b=21816 allow querying quota stats even when some OSTs are down
[fs/lustre-release.git] / lnet / klnds / gmlnd / gmlnd.h
1 /*
2  * -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
3  * vim:expandtab:shiftwidth=8:tabstop=8:
4  *
5  * GPL HEADER START
6  *
7  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 only,
11  * as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License version 2 for more details (a copy is included
17  * in the LICENSE file that accompanied this code).
18  *
19  * You should have received a copy of the GNU General Public License
20  * version 2 along with this program; If not, see
21  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22  *
23  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24  * CA 95054 USA or visit www.sun.com if you need additional information or
25  * have any questions.
26  *
27  * GPL HEADER END
28  */
29 /*
30  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
31  * Use is subject to license terms.
32  *
33  * Copyright (c) 2003 Los Alamos National Laboratory (LANL)
34  */
35 /*
36  * This file is part of Lustre, http://www.lustre.org/
37  * Lustre is a trademark of Sun Microsystems, Inc.
38  */
39
40 /*
41  *      Portals GM kernel NAL header file
42  *      This file makes all declaration and prototypes 
43  *      for the API side and CB side of the NAL
44  */
45 #ifndef __INCLUDE_GMNAL_H__
46 #define __INCLUDE_GMNAL_H__
47
48 /* XXX Lustre as of V1.2.2 drop defines VERSION, which causes problems
49  * when including <GM>/include/gm_lanai.h which defines a structure field
50  * with the name VERSION XXX */
51 #ifdef VERSION
52 # undef VERSION
53 #endif
54
55 #ifndef EXPORT_SYMTAB
56 # define EXPORT_SYMTAB
57 #endif
58 #ifndef AUTOCONF_INCLUDED
59 #include <linux/config.h>
60 #endif
61 #include "linux/module.h"
62 #include "linux/tty.h"
63 #include "linux/kernel.h"
64 #include "linux/mm.h"
65 #include "linux/string.h"
66 #include "linux/stat.h"
67 #include "linux/errno.h"
68 #include "linux/version.h"
69 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
70 #include "linux/buffer_head.h"
71 #include "linux/fs.h"
72 #else
73 #include "linux/locks.h"
74 #endif
75 #include "linux/unistd.h"
76 #include "linux/init.h"
77 #include "linux/sem.h"
78 #include "linux/vmalloc.h"
79 #include "linux/sysctl.h"
80
81 #define DEBUG_SUBSYSTEM S_LND
82
83 #include "libcfs/libcfs.h"
84 #include "lnet/lnet.h"
85 #include "lnet/lib-lnet.h"
86 #include "lnet/lnet-sysctl.h"
87
88 /* undefine these before including the GM headers which clash */
89 #undef PACKAGE_BUGREPORT
90 #undef PACKAGE_NAME
91 #undef PACKAGE_STRING
92 #undef PACKAGE_TARNAME
93 #undef PACKAGE_VERSION
94
95 #define GM_STRONG_TYPES 1
96 #ifdef VERSION
97 #undef VERSION
98 #endif
99 #include "gm.h"
100 #include "gm_internal.h"
101
102 /* Fixed tunables */
103 #define GMNAL_RESCHED              100          /* # busy loops to force scheduler to yield */
104 #define GMNAL_NETADDR_BASE         0x10000000   /* where we start in network VM */
105 #define GMNAL_LARGE_PRIORITY       GM_LOW_PRIORITY /* large message GM priority */
106 #define GMNAL_SMALL_PRIORITY       GM_LOW_PRIORITY /* small message GM priority */
107
108 /* Wire protocol */
109 typedef struct {
110         lnet_hdr_t      gmim_hdr;               /* portals header */
111         char            gmim_payload[0];        /* payload */
112 } gmnal_immediate_msg_t;
113
114 typedef struct {
115         /* First 2 fields fixed FOR ALL TIME */
116         __u32           gmm_magic;              /* I'm a GM message */
117         __u16           gmm_version;            /* this is my version number */
118
119         __u16           gmm_type;               /* msg type */
120         __u64           gmm_srcnid;             /* sender's NID */
121         __u64           gmm_dstnid;             /* destination's NID */
122         union {
123                 gmnal_immediate_msg_t   immediate;
124         }               gmm_u;
125 } WIRE_ATTR gmnal_msg_t;
126
127 #define GMNAL_MSG_MAGIC                 LNET_PROTO_GM_MAGIC
128 #define GMNAL_MSG_VERSION               1
129 #define GMNAL_MSG_IMMEDIATE             1
130
131 typedef struct netbuf {
132         __u64                    nb_netaddr;    /* network VM address */
133         lnet_kiov_t              nb_kiov[1];    /* the pages (at least 1) */
134 } gmnal_netbuf_t;
135
136 #define GMNAL_NETBUF_MSG(nb)            ((gmnal_msg_t *)page_address((nb)->nb_kiov[0].kiov_page))
137 #define GMNAL_NETBUF_LOCAL_NETADDR(nb)  ((void *)((unsigned long)(nb)->nb_netaddr))
138
139 typedef struct gmnal_txbuf {
140         cfs_list_t               txb_list;      /* queue on gmni_idle_ltxbs */
141         struct gmnal_txbuf      *txb_next;      /* stash on gmni_ltxs */
142         gmnal_netbuf_t           txb_buf;       /* space */
143 } gmnal_txbuf_t;
144
145 typedef struct gmnal_tx {
146         cfs_list_t               tx_list;       /* queue */
147         int                      tx_credit:1;   /* consumed a credit? */
148         int                      tx_large_iskiov:1; /* large is in kiovs? */
149         struct gmnal_ni         *tx_gmni;       /* owning NI */
150         lnet_nid_t               tx_nid;        /* destination NID */
151         int                      tx_gmlid;      /* destination GM local ID */
152         lnet_msg_t              *tx_lntmsg;     /* lntmsg to finalize on completion */
153
154         gmnal_netbuf_t           tx_buf;        /* small tx buffer */
155         gmnal_txbuf_t           *tx_ltxb;       /* large buffer (to free on completion) */
156         int                      tx_msgnob;     /* message size (so far) */
157
158         int                      tx_large_nob;  /* # bytes large buffer payload */
159         int                      tx_large_offset; /* offset within frags */
160         int                      tx_large_niov; /* # VM frags */
161         union {
162                 struct iovec    *iov;           /* mapped frags */
163                 lnet_kiov_t     *kiov;          /* page frags */
164         }                        tx_large_frags;
165         cfs_time_t               tx_launchtime; /* when (in jiffies) the
166                                                  * transmit was launched */
167         struct gmnal_tx         *tx_next;       /* stash on gmni_txs */
168 } gmnal_tx_t;
169
170 typedef struct gmnal_rx {
171         cfs_list_t               rx_list;       /* enqueue on gmni_rxq for handling */
172         int                      rx_islarge:1;  /* large receive buffer? */
173         unsigned int             rx_recv_nob;   /* bytes received */
174         __u16                    rx_recv_gmid;  /* sender */
175         __u8                     rx_recv_port;  /* sender's port */
176         __u8                     rx_recv_type;  /* ?? */
177         struct gmnal_rx         *rx_next;       /* stash on gmni_rxs */
178         gmnal_netbuf_t           rx_buf;        /* the buffer */
179 } gmnal_rx_t;
180
181 typedef struct gmnal_ni {
182         lnet_ni_t           *gmni_ni;           /* generic NI */
183         struct gm_port      *gmni_port;         /* GM port */
184         cfs_spinlock_t       gmni_gm_lock;      /* serialise GM calls */
185         int                  gmni_large_pages;  /* # pages in a large message buffer */
186         int                  gmni_large_msgsize;/* nob in large message buffers */
187         int                  gmni_large_gmsize; /* large message GM bucket */
188         int                  gmni_small_msgsize;/* nob in small message buffers */
189         int                  gmni_small_gmsize; /* small message GM bucket */
190         __u64                gmni_netaddr_base; /* base of mapped network VM */
191         int                  gmni_netaddr_size; /* # bytes of mapped network VM */
192
193         gmnal_tx_t          *gmni_txs;          /* all txs */
194         gmnal_rx_t          *gmni_rxs;          /* all rx descs */
195         gmnal_txbuf_t       *gmni_ltxbs;        /* all large tx bufs */
196
197         cfs_atomic_t         gmni_nthreads;     /* total # threads */
198         gm_alarm_t           gmni_alarm;        /* alarm to wake caretaker */
199         int                  gmni_shutdown;     /* tell all threads to exit */
200
201         cfs_list_t           gmni_idle_txs;     /* idle tx's */
202         int                  gmni_tx_credits;   /* # transmits still possible */
203         cfs_list_t           gmni_idle_ltxbs;   /* idle large tx buffers */
204         cfs_list_t           gmni_buf_txq;      /* tx's waiting for buffers */
205         cfs_list_t           gmni_cred_txq;     /* tx's waiting for credits */
206         cfs_spinlock_t       gmni_tx_lock;      /* serialise */
207
208         struct gm_hash      *gmni_rx_hash;      /* buffer->rx lookup */
209         cfs_semaphore_t      gmni_rx_mutex;    /* serialise blocking on GM */
210 } gmnal_ni_t;
211
212 typedef struct {
213         int              *gm_port;
214         int              *gm_ntx;
215         int              *gm_credits;
216         int              *gm_peer_credits;
217         int              *gm_nlarge_tx_bufs;
218         int              *gm_nrx_small;
219         int              *gm_nrx_large;
220
221 #if defined(CONFIG_SYSCTL) && !CFS_SYSFS_MODULE_PARM
222         cfs_sysctl_table_header_t *gm_sysctl;   /* sysctl interface */
223 #endif
224 } gmnal_tunables_t;
225
226
227 /* gmnal_api.c */
228 int gmnal_init(void);
229 void gmnal_fini(void);
230 int gmnal_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg);
231 int gmnal_startup(lnet_ni_t *ni);
232 void gmnal_shutdown(lnet_ni_t *ni);
233
234 /* gmnal_cb.c */
235 int gmnal_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg,
236                int delayed, unsigned int niov, 
237                struct iovec *iov, lnet_kiov_t *kiov,
238                unsigned int offset, unsigned int mlen, unsigned int rlen);
239 int gmnal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg);
240
241 /* gmnal_util.c */
242 void gmnal_free_ltxbufs(gmnal_ni_t *gmni);
243 int gmnal_alloc_ltxbufs(gmnal_ni_t *gmni);
244 void gmnal_free_txs(gmnal_ni_t *gmni);
245 int gmnal_alloc_txs(gmnal_ni_t *gmni);
246 void gmnal_free_rxs(gmnal_ni_t *gmni);
247 int gmnal_alloc_rxs(gmnal_ni_t *gmni);
248 char *gmnal_gmstatus2str(gm_status_t status);
249 char *gmnal_rxevent2str(gm_recv_event_t *ev);
250 void gmnal_yield(int delay);
251
252 /* gmnal_comm.c */
253 void gmnal_post_rx(gmnal_ni_t *gmni, gmnal_rx_t *rx);
254 gmnal_tx_t *gmnal_get_tx(gmnal_ni_t *gmni);
255 void gmnal_tx_done(gmnal_tx_t *tx, int rc);
256 void gmnal_pack_msg(gmnal_ni_t *gmni, gmnal_msg_t *msg,
257                     lnet_nid_t dstnid, int type);
258 void gmnal_stop_threads(gmnal_ni_t *gmni);
259 int gmnal_start_threads(gmnal_ni_t *gmni);
260 void gmnal_check_txqueues_locked (gmnal_ni_t *gmni);
261
262 /* Module Parameters */
263 extern gmnal_tunables_t gmnal_tunables;
264
265 #endif /*__INCLUDE_GMNAL_H__*/