1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
32 * Copyright (c) 2003 Los Alamos National Laboratory (LANL)
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
40 * Implements the API NAL functions
48 .lnd_startup = gmnal_startup,
49 .lnd_shutdown = gmnal_shutdown,
51 .lnd_send = gmnal_send,
52 .lnd_recv = gmnal_recv,
55 gmnal_ni_t *the_gmni = NULL;
58 gmnal_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg)
60 struct libcfs_ioctl_data *data = arg;
63 case IOC_LIBCFS_REGISTER_MYNID:
64 if (data->ioc_nid == ni->ni_nid)
67 LASSERT (LNET_NIDNET(data->ioc_nid) == LNET_NIDNET(ni->ni_nid));
69 CERROR("obsolete IOC_LIBCFS_REGISTER_MYNID for %s(%s)\n",
70 libcfs_nid2str(data->ioc_nid),
71 libcfs_nid2str(ni->ni_nid));
80 gmnal_set_local_nid (gmnal_ni_t *gmni)
82 lnet_ni_t *ni = gmni->gmni_ni;
85 gm_status_t gm_status;
87 /* Called before anything initialised: no need to lock */
88 gm_status = gm_get_node_id(gmni->gmni_port, &local_gmid);
89 if (gm_status != GM_SUCCESS)
92 CDEBUG(D_NET, "Local node id is [%u]\n", local_gmid);
94 gm_status = gm_node_id_to_global_id(gmni->gmni_port,
97 if (gm_status != GM_SUCCESS)
100 CDEBUG(D_NET, "Global node id is [%u]\n", global_gmid);
102 ni->ni_nid = LNET_MKNID(LNET_NIDNET(ni->ni_nid), global_gmid);
107 gmnal_shutdown(lnet_ni_t *ni)
109 gmnal_ni_t *gmni = ni->ni_data;
111 CDEBUG(D_TRACE, "gmnal_api_shutdown: gmni [%p]\n", gmni);
113 LASSERT (gmni == the_gmni);
115 /* stop processing messages */
116 gmnal_stop_threads(gmni);
118 /* stop all network callbacks */
119 gm_close(gmni->gmni_port);
120 gmni->gmni_port = NULL;
124 gmnal_free_ltxbufs(gmni);
125 gmnal_free_txs(gmni);
126 gmnal_free_rxs(gmni);
128 LIBCFS_FREE(gmni, sizeof(*gmni));
135 gmnal_startup(lnet_ni_t *ni)
137 gmnal_ni_t *gmni = NULL;
138 gmnal_rx_t *rx = NULL;
139 gm_status_t gm_status;
142 LASSERT (ni->ni_lnd == &the_gmlnd);
144 ni->ni_maxtxcredits = *gmnal_tunables.gm_credits;
145 ni->ni_peertxcredits = *gmnal_tunables.gm_peer_credits;
147 if (the_gmni != NULL) {
148 CERROR("Only 1 instance supported\n");
152 LIBCFS_ALLOC(gmni, sizeof(*gmni));
154 CERROR("can't allocate gmni\n");
160 memset(gmni, 0, sizeof(*gmni));
162 spin_lock_init(&gmni->gmni_tx_lock);
163 spin_lock_init(&gmni->gmni_gm_lock);
164 INIT_LIST_HEAD(&gmni->gmni_idle_txs);
165 INIT_LIST_HEAD(&gmni->gmni_idle_ltxbs);
166 INIT_LIST_HEAD(&gmni->gmni_buf_txq);
167 INIT_LIST_HEAD(&gmni->gmni_cred_txq);
168 sema_init(&gmni->gmni_rx_mutex, 1);
172 * initialise the interface,
174 CDEBUG(D_NET, "Calling gm_init\n");
175 if (gm_init() != GM_SUCCESS) {
176 CERROR("call to gm_init failed\n");
180 CDEBUG(D_NET, "Calling gm_open with port [%d], version [%d]\n",
181 *gmnal_tunables.gm_port, GM_API_VERSION);
183 gm_status = gm_open(&gmni->gmni_port, 0, *gmnal_tunables.gm_port,
184 "gmnal", GM_API_VERSION);
186 if (gm_status != GM_SUCCESS) {
187 CERROR("Can't open GM port %d: %d (%s)\n",
188 *gmnal_tunables.gm_port, gm_status,
189 gmnal_gmstatus2str(gm_status));
193 CDEBUG(D_NET,"gm_open succeeded port[%p]\n",gmni->gmni_port);
195 if (!gmnal_set_local_nid(gmni))
198 CDEBUG(D_NET, "portals_nid is %s\n", libcfs_nid2str(ni->ni_nid));
200 gmni->gmni_large_msgsize =
201 offsetof(gmnal_msg_t, gmm_u.immediate.gmim_payload[LNET_MAX_PAYLOAD]);
202 gmni->gmni_large_gmsize =
203 gm_min_size_for_length(gmni->gmni_large_msgsize);
204 gmni->gmni_large_pages =
205 (gmni->gmni_large_msgsize + PAGE_SIZE - 1)/PAGE_SIZE;
207 gmni->gmni_small_msgsize = MIN(GM_MTU, PAGE_SIZE);
208 gmni->gmni_small_gmsize =
209 gm_min_size_for_length(gmni->gmni_small_msgsize);
211 gmni->gmni_netaddr_base = GMNAL_NETADDR_BASE;
212 gmni->gmni_netaddr_size = 0;
214 CDEBUG(D_NET, "Msg size %08x/%08x [%d/%d]\n",
215 gmni->gmni_large_msgsize, gmni->gmni_small_msgsize,
216 gmni->gmni_large_gmsize, gmni->gmni_small_gmsize);
218 if (gmnal_alloc_rxs(gmni) != 0) {
219 CERROR("Failed to allocate rx descriptors\n");
223 if (gmnal_alloc_txs(gmni) != 0) {
224 CERROR("Failed to allocate tx descriptors\n");
228 if (gmnal_alloc_ltxbufs(gmni) != 0) {
229 CERROR("Failed to allocate large tx buffers\n");
233 rc = gmnal_start_threads(gmni);
235 CERROR("Can't start threads: %d\n", rc);
239 /* Start listening */
240 for (rx = gmni->gmni_rxs; rx != NULL; rx = rx->rx_next)
241 gmnal_post_rx(gmni, rx);
245 CDEBUG(D_NET, "gmnal_init finished\n");
249 gm_close(gmni->gmni_port);
250 gmni->gmni_port = NULL;
256 /* safe to free descriptors after network has been shut down */
257 gmnal_free_ltxbufs(gmni);
258 gmnal_free_txs(gmni);
259 gmnal_free_rxs(gmni);
261 LIBCFS_FREE(gmni, sizeof(*gmni));
268 * Called when module loaded
272 lnet_register_lnd(&the_gmlnd);
277 * Called when module removed
281 lnet_unregister_lnd(&the_gmlnd);