1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:cindent:
4 * Copyright (C) 2003 High Performance Computing Center North (HPC2N)
5 * Author: Niklas Edmundsson <nikke@hpc2n.umu.se>
7 * Based on gmnal, which is based on ksocknal and qswnal
9 * This file is part of Portals, http://www.sf.net/projects/lustre/
11 * Portals is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Portals is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Portals; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "scimacnal.h"
29 ptl_handle_ni_t kscimacnal_ni;
32 kscimacnal_data_t kscimacnal_data;
34 kpr_nal_interface_t kscimacnal_router_interface = {
35 kprni_nalid: SCIMACNAL,
37 kprni_fwd: kscimacnal_fwd_packet,
41 int kscimacnal_cmd (struct portal_ioctl_data *data, void *private)
43 LASSERT (data != NULL);
45 switch (data->ioc_nal_cmd) {
46 case NAL_CMD_REGISTER_MYNID:
47 if(kscimacnal_lib.ni.nid == data->ioc_nid) {
50 CDEBUG (D_IOCTL, "Can't change NID from "LPX64" to "LPX64")\n", kscimacnal_lib.ni.nid, data->ioc_nid);
59 static int kscimacnal_forward(nal_t *nal,
61 void *args, size_t args_len,
62 void *ret, size_t ret_len)
64 kscimacnal_data_t *ksci = nal->nal_data;
65 nal_cb_t *nal_cb = ksci->ksci_cb;
67 LASSERT (nal == &kscimacnal_api);
68 LASSERT (ksci == &kscimacnal_data);
69 LASSERT (nal_cb == &kscimacnal_lib);
71 lib_dispatch(nal_cb, ksci, id, args, ret); /* nal needs ksci */
76 static void kscimacnal_lock(nal_t *nal, unsigned long *flags)
78 kscimacnal_data_t *ksci = nal->nal_data;
79 nal_cb_t *nal_cb = ksci->ksci_cb;
82 LASSERT (nal == &kscimacnal_api);
83 LASSERT (ksci == &kscimacnal_data);
84 LASSERT (nal_cb == &kscimacnal_lib);
86 nal_cb->cb_cli(nal_cb,flags);
90 static void kscimacnal_unlock(nal_t *nal, unsigned long *flags)
92 kscimacnal_data_t *ksci = nal->nal_data;
93 nal_cb_t *nal_cb = ksci->ksci_cb;
96 LASSERT (nal == &kscimacnal_api);
97 LASSERT (ksci == &kscimacnal_data);
98 LASSERT (nal_cb == &kscimacnal_lib);
100 nal_cb->cb_sti(nal_cb,flags);
104 static int kscimacnal_shutdown(nal_t *nal, int ni)
106 LASSERT (nal == &kscimacnal_api);
111 static void kscimacnal_yield( nal_t *nal )
113 LASSERT (nal == &kscimacnal_api);
115 if (current->need_resched)
121 static nal_t *kscimacnal_init(int interface, ptl_pt_index_t ptl_size,
122 ptl_ac_index_t ac_size, ptl_pid_t requested_pid)
124 int nnids = 512; /* FIXME: Need ScaMac funktion to get #nodes */
126 CDEBUG(D_NET, "calling lib_init with nid "LPX64" nnids %d\n", kscimacnal_data.ksci_nid, nnids);
127 lib_init(&kscimacnal_lib, kscimacnal_data.ksci_nid, 0, nnids,ptl_size, ac_size);
128 return &kscimacnal_api;
132 /* Called by kernel at module unload time */
133 static void /*__exit*/
134 kscimacnal_finalize(void)
136 /* FIXME: How should the shutdown procedure really look? */
137 kscimacnal_data.ksci_shuttingdown=1;
139 PORTAL_SYMBOL_UNREGISTER(kscimacnal_ni);
141 PtlNIFini(kscimacnal_ni);
142 lib_fini(&kscimacnal_lib);
144 mac_finish(kscimacnal_data.ksci_machandle);
146 CDEBUG (D_MALLOC, "done kmem %d\n", atomic_read (&portal_kmemory));
152 /* Called by kernel at module insertion time */
154 kscimacnal_initialize(void)
158 mac_handle_t *machandle = NULL;
161 CDEBUG (D_MALLOC, "start kmem %d\n", atomic_read (&portal_kmemory));
163 kscimacnal_api.forward = kscimacnal_forward;
164 kscimacnal_api.shutdown = kscimacnal_shutdown;
165 kscimacnal_api.yield = kscimacnal_yield;
166 kscimacnal_api.validate = NULL; /* our api validate is a NOOP */
167 kscimacnal_api.lock= kscimacnal_lock;
168 kscimacnal_api.unlock= kscimacnal_unlock;
169 kscimacnal_api.nal_data = &kscimacnal_data;
171 kscimacnal_lib.nal_data = &kscimacnal_data;
173 memset(&kscimacnal_data, 0, sizeof(kscimacnal_data));
175 kscimacnal_data.ksci_cb = &kscimacnal_lib;
177 /* We're not using this, but cli/sti callbacks does... ??? */
178 spin_lock_init(&kscimacnal_data.ksci_dispatch_lock);
180 /* FIXME: We only support one adapter for now */
181 machandle = mac_init(0, MAC_SAPID_LUSTRE, kscimacnal_rx,
185 CERROR("mac_init() failed\n");
189 kscimacnal_data.ksci_machandle = machandle;
191 /* Make sure the scimac MTU is tuned */
192 if(mac_get_mtusize(machandle) < SCIMACNAL_MTU) {
193 CERROR("scimac mtu of %ld smaller than SCIMACNAL MTU of %d\n",
194 mac_get_mtusize(machandle), SCIMACNAL_MTU);
195 CERROR("Consult README.scimacnal for more information\n");
196 mac_finish(machandle);
200 /* Get the node ID */
201 /* mac_get_physaddrlen() is a function instead of define, sigh */
202 LASSERT(mac_get_physaddrlen(machandle) <= sizeof(nid));
203 if(mac_get_physaddr(machandle, (mac_physaddr_t *) &nid)) {
204 CERROR("mac_get_physaddr() failed\n");
205 mac_finish(machandle);
209 kscimacnal_data.ksci_nid = nid;
212 /* Initialize Network Interface */
213 /* FIXME: What do the magic numbers mean? Documentation anyone? */
214 rc = PtlNIInit(kscimacnal_init, 32, 4, 0, &kscimacnal_ni);
216 CERROR("PtlNIInit failed %d\n", rc);
217 mac_finish(machandle);
221 /* Init command interface */
222 rc = kportal_nal_register (SCIMACNAL, &kscimacnal_cmd, NULL);
224 CERROR ("Can't initialise command interface (rc = %d)\n", rc);
225 PtlNIFini(kscimacnal_ni);
226 mac_finish(machandle);
231 PORTAL_SYMBOL_REGISTER(kscimacnal_ni);
233 /* We're done now, it's OK for the RX callback to do stuff */
234 kscimacnal_data.ksci_init = 1;
240 MODULE_AUTHOR("Niklas Edmundsson <nikke@hpc2n.umu.se>");
241 MODULE_DESCRIPTION("Kernel Scali ScaMAC SCI NAL v0.1");
242 MODULE_LICENSE("GPL");
244 module_init (kscimacnal_initialize);
245 module_exit (kscimacnal_finalize);
247 EXPORT_SYMBOL(kscimacnal_ni);