1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2003 Los Alamos National Laboratory (LANL)
6 * This file is part of Lustre, http://www.lustre.org/
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.
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.
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.
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
28 #ifndef __INCLUDE_GMNAL_H__
29 #define __INCLUDE_GMNAL_H__
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 */
39 # define EXPORT_SYMTAB
42 #include "linux/config.h"
43 #include "linux/module.h"
44 #include "linux/tty.h"
45 #include "linux/kernel.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"
55 #include "linux/locks.h"
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"
63 #define DEBUG_SUBSYSTEM S_NAL
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"
71 #include "portals/nal.h"
72 #include "portals/lib-p30.h"
74 /* undefine these before including the GM headers which clash */
75 #undef PACKAGE_BUGREPORT
78 #undef PACKAGE_TARNAME
79 #undef PACKAGE_VERSION
81 #define GM_STRONG_TYPES 1
86 #include "gm_internal.h"
89 * Defines for the API NAL
95 ptl_hdr_t gmim_hdr; /* portals header */
96 char gmim_payload[0]; /* payload */
97 } gmnal_immediate_msg_t;
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 */
104 __u16 gmm_type; /* msg type */
105 __u64 gmm_srcnid; /* sender's NID */
106 __u64 gmm_dstnid; /* destination's NID */
108 gmnal_immediate_msg_t immediate;
110 } WIRE_ATTR gmnal_msg_t;
112 #define GMNAL_MSG_MAGIC 0x6d797269 /* 'myri'! */
113 #define GMNAL_MSG_VERSION 1
114 #define GMNAL_MSG_IMMEDIATE 1
116 typedef struct gmnal_tx {
117 struct gmnal_tx *tx_next;
120 gm_size_t tx_gm_size;
125 struct gmnal_ni *tx_gmni;
126 lib_msg_t *tx_libmsg;
132 * a hash table in nal_data find rxs from
133 * the rx buffer address. hash table populated at init time
135 typedef struct gmnal_rx {
136 struct list_head rx_list;
140 unsigned int rx_recv_nob;
144 struct gmnal_rx *rx_next;
149 * 1 receive thread started on each CPU
151 #define NRXTHREADS 10 /* max number of receiver threads */
153 typedef struct gmnal_ni {
154 spinlock_t gmni_tx_lock;
155 struct semaphore gmni_tx_token;
157 spinlock_t gmni_rxt_tx_lock;
158 struct semaphore gmni_rxt_tx_token;
159 gmnal_tx_t *gmni_rxt_tx;
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;
173 struct list_head gmni_rxq;
174 spinlock_t gmni_rxq_lock;
175 struct semaphore gmni_rxq_wait;
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
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)
192 #define GMNAL_IOC_GET_GNID 1
196 int gmnal_init(void);
197 void gmnal_fini(void);
200 ptl_err_t gmnal_cb_recv(lib_nal_t *libnal, void *private,
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,
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);
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);
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);
247 /* Module Parameters */
248 extern int num_rx_threads;
250 extern int gm_port_id;
252 #endif /*__INCLUDE_GMNAL_H__*/