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