Whamcloud - gitweb
* cleaned up startup/shutdown handling
[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  *
6  *   This file is part of Lustre, http://www.lustre.org/
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22
23 /*
24  *      Portals GM kernel NAL header file
25  *      This file makes all declaration and prototypes 
26  *      for the API side and CB side of the NAL
27  */
28 #ifndef __INCLUDE_GMNAL_H__
29 #define __INCLUDE_GMNAL_H__
30
31 /* XXX Lustre as of V1.2.2 drop defines VERSION, which causes problems
32  * when including <GM>/include/gm_lanai.h which defines a structure field
33  * with the name VERSION XXX */
34 #ifdef VERSION
35 # undef VERSION
36 #endif
37
38 #ifndef EXPORT_SYMTAB
39 # define EXPORT_SYMTAB
40 #endif
41
42 #include "linux/config.h"
43 #include "linux/module.h"
44 #include "linux/tty.h"
45 #include "linux/kernel.h"
46 #include "linux/mm.h"
47 #include "linux/string.h"
48 #include "linux/stat.h"
49 #include "linux/errno.h"
50 #include "linux/version.h"
51 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
52 #include "linux/buffer_head.h"
53 #include "linux/fs.h"
54 #else
55 #include "linux/locks.h"
56 #endif
57 #include "linux/unistd.h"
58 #include "linux/init.h"
59 #include "linux/sem.h"
60 #include "linux/vmalloc.h"
61 #include "linux/sysctl.h"
62
63 #define DEBUG_SUBSYSTEM S_NAL
64
65 #include "portals/nal.h"
66 #include "portals/api.h"
67 #include "portals/errno.h"
68 #include "libcfs/kp30.h"
69 #include "portals/p30.h"
70
71 #include "portals/nal.h"
72 #include "portals/lib-p30.h"
73
74 /* undefine these before including the GM headers which clash */
75 #undef PACKAGE_BUGREPORT
76 #undef PACKAGE_NAME
77 #undef PACKAGE_STRING
78 #undef PACKAGE_TARNAME
79 #undef PACKAGE_VERSION
80
81 #define GM_STRONG_TYPES 1
82 #ifdef VERSION
83 #undef VERSION
84 #endif
85 #include "gm.h"
86 #include "gm_internal.h"
87
88 /*
89  *      Defines for the API NAL
90  */
91
92 /* Wire protocol */
93
94 typedef struct {
95         ptl_hdr_t       gmim_hdr;               /* portals header */
96         char            gmim_payload[0];        /* payload */
97 } gmnal_immediate_msg_t;
98
99 typedef struct {
100         /* First 2 fields fixed FOR ALL TIME */
101         __u32           gmm_magic;              /* I'm a GM message */
102         __u16           gmm_version;            /* this is my version number */
103
104         __u16           gmm_type;               /* msg type */
105         __u64           gmm_srcnid;             /* sender's NID */
106         __u64           gmm_dstnid;             /* destination's NID */
107         union {
108                 gmnal_immediate_msg_t   immediate;
109         }               gmm_u;
110 } WIRE_ATTR gmnal_msg_t;
111
112 #define GMNAL_MSG_MAGIC                 0x6d797269 /* 'myri'! */
113 #define GMNAL_MSG_VERSION               1
114 #define GMNAL_MSG_IMMEDIATE             1
115
116 typedef struct gmnal_tx {
117         struct gmnal_tx         *tx_next;
118         gmnal_msg_t             *tx_msg;
119         int                      tx_buffer_size;
120         gm_size_t                tx_gm_size;
121         int                      tx_msg_size;
122         int                      tx_gmlid;
123         int                      tx_gm_priority;
124         ptl_nid_t                tx_nid;
125         struct gmnal_ni         *tx_gmni;
126         lib_msg_t               *tx_libmsg;
127         int                      tx_rxt; 
128 } gmnal_tx_t;
129
130 /*
131  *      as for gmnal_tx_t 
132  *      a hash table in nal_data find rxs from
133  *      the rx buffer address. hash table populated at init time
134  */
135 typedef struct gmnal_rx {
136         struct list_head         rx_list;
137         gmnal_msg_t             *rx_msg;
138         int                      rx_size;
139         gm_size_t                rx_gmsize;
140         unsigned int             rx_recv_nob;
141         __u16                    rx_recv_gmid;
142         __u8                     rx_recv_port;
143         __u8                     rx_recv_type;
144         struct gmnal_rx         *rx_next;
145 } gmnal_rx_t;
146
147
148 /*
149  *      1 receive thread started on each CPU
150  */
151 #define NRXTHREADS 10 /* max number of receiver threads */
152
153 typedef struct gmnal_ni {
154         spinlock_t       gmni_tx_lock;
155         struct semaphore gmni_tx_token;
156         gmnal_tx_t      *gmni_tx;
157         spinlock_t       gmni_rxt_tx_lock;
158         struct semaphore gmni_rxt_tx_token;
159         gmnal_tx_t      *gmni_rxt_tx;
160         gmnal_rx_t      *gmni_rx;
161         struct gm_hash  *gmni_rx_hash;
162         lib_nal_t       *gmni_libnal;
163         struct gm_port  *gmni_port;
164         spinlock_t       gmni_gm_lock;          /* serialise GM calls */
165         long             gmni_rxthread_pid[NRXTHREADS];
166         int              gmni_rxthread_stop_flag;
167         spinlock_t       gmni_rxthread_flag_lock;
168         long             gmni_rxthread_flag;
169         long             gmni_ctthread_pid;
170         int              gmni_ctthread_flag;
171         gm_alarm_t       gmni_ctthread_alarm;
172         int              gmni_msg_size;
173         struct list_head gmni_rxq;
174         spinlock_t       gmni_rxq_lock;
175         struct semaphore gmni_rxq_wait;
176 } gmnal_ni_t;
177
178 /*
179  *      Flags to start/stop and check status of threads
180  *      each rxthread sets 1 bit (any bit) of the flag on startup
181  *      and clears 1 bit when exiting
182  */
183 #define GMNAL_THREAD_RESET      0
184 #define GMNAL_THREAD_STOP       666
185 #define GMNAL_CTTHREAD_STARTED  333
186 #define GMNAL_RXTHREADS_STARTED ( (1<<num_rx_threads)-1)
187
188
189 /*
190  * for ioctl get pid
191  */
192 #define GMNAL_IOC_GET_GNID 1    
193
194
195 /* gmnal_api.c */
196 int gmnal_init(void);
197 void  gmnal_fini(void);
198
199 /* gmnal_cb.c */
200 ptl_err_t gmnal_cb_recv(lib_nal_t *libnal, void *private, 
201                         lib_msg_t *libmsg,
202                         unsigned int niov, struct iovec *iov, 
203                         size_t offset, size_t mlen, size_t rlen);
204 ptl_err_t gmnal_cb_recv_pages(lib_nal_t *libnal, void *private, 
205                               lib_msg_t *libmsg, 
206                               unsigned int nkiov, ptl_kiov_t *kiov, 
207                               size_t offset, size_t mlen, size_t rlen);
208 ptl_err_t gmnal_cb_send(lib_nal_t *libnal, void *private, 
209                         lib_msg_t *libmsg, ptl_hdr_t *hdr, int type, 
210                         ptl_nid_t nid, ptl_pid_t pid,
211                         unsigned int niov, struct iovec *iov, 
212                         size_t offset, size_t len);
213 ptl_err_t gmnal_cb_send_pages(lib_nal_t *libnal, void *private,
214                               lib_msg_t *libmsg, ptl_hdr_t *hdr, int type,
215                               ptl_nid_t nid, ptl_pid_t pid, 
216                               unsigned int nkiov, ptl_kiov_t *kiov, 
217                               size_t offset, size_t len);
218 int gmnal_cb_dist(lib_nal_t *libnal, ptl_nid_t nid, unsigned long *dist);
219
220 /* gmnal_util.c */
221 int gmnal_is_rxthread(gmnal_ni_t *gmnalni);
222 int gmnal_alloc_txs(gmnal_ni_t *gmnalni);
223 void gmnal_free_txs(gmnal_ni_t *gmnalni);
224 gmnal_tx_t *gmnal_get_tx(gmnal_ni_t *gmnalni, int block);
225 void gmnal_return_tx(gmnal_ni_t *gmnalni, gmnal_tx_t *tx);
226 int gmnal_alloc_rxs(gmnal_ni_t *gmnalni);
227 void gmnal_free_rxs(gmnal_ni_t *gmnalni);
228 void gmnal_stop_rxthread(gmnal_ni_t *gmnalni);
229 void gmnal_stop_ctthread(gmnal_ni_t *gmnalni);
230 char *gmnal_gmstatus2str(gm_status_t status);
231 char *gmnal_rxevent2str(gm_recv_event_t *ev);
232 void gmnal_yield(int delay);
233 int gmnal_enqueue_rx(gmnal_ni_t *gmnalni, gm_recv_t *recv);
234 gmnal_rx_t *gmnal_dequeue_rx(gmnal_ni_t *gmnalni);
235 int gmnal_start_kernel_threads(gmnal_ni_t *gmnalni);
236
237 /* gmnal_comm.c */
238 void gmnal_pack_msg(gmnal_ni_t *gmnalni, gmnal_tx_t *tx,
239                     ptl_nid_t dstnid, int type);
240 int gmnal_ct_thread(void *arg);
241 int gmnal_rx_thread(void *arg);
242 void gmnal_post_rx(gmnal_ni_t *gmnalni, gmnal_rx_t *rx);
243 ptl_err_t gmnal_post_tx(gmnal_ni_t *gmnalni, gmnal_tx_t *tx, 
244                         lib_msg_t *libmsg, ptl_nid_t nid, int nob);
245
246
247 /* Module Parameters */
248 extern  int num_rx_threads;
249 extern  int num_txds;
250 extern  int gm_port_id;
251
252 #endif /*__INCLUDE_GMNAL_H__*/