Whamcloud - gitweb
* GMNAL
[fs/lustre-release.git] / lnet / klnds / gmlnd / gmlnd_module.c
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 #include "gmnal.h"
23
24
25 /*
26  *      -1 indicates default value.
27  *      This is 1 thread per cpu
28  *      See start_kernel_threads
29  */
30 int num_rx_threads = -1;
31 int num_stxds = 5;
32 int gm_port_id = 4;
33
34 int
35 gmnal_cmd(struct portals_cfg *pcfg, void *private)
36 {
37         gmnal_ni_t      *gmnalni = NULL;
38         char            *name = NULL;
39         int             nid = -2;
40         int             gmid;
41         gm_status_t     gm_status;
42
43
44         CDEBUG(D_TRACE, "gmnal_cmd [%d] private [%p]\n",
45                pcfg->pcfg_command, private);
46         gmnalni = (gmnal_ni_t*)private;
47         switch(pcfg->pcfg_command) {
48         /*
49          * just reuse already defined GET_NID. Should define GMNAL version
50          */
51         case(GMNAL_IOC_GET_GNID):
52
53                 PORTAL_ALLOC(name, pcfg->pcfg_plen1);
54                 copy_from_user(name, PCFG_PBUF(pcfg, 1), pcfg->pcfg_plen1);
55
56                 spin_lock(&gmnalni->gmni_gm_lock);
57                 //nid = gm_host_name_to_node_id(gmnalni->gmni_port, name);
58                 gm_status = gm_host_name_to_node_id_ex(gmnalni->gmni_port, 0,
59                                                        name, &nid);
60                 spin_unlock(&gmnalni->gmni_gm_lock);
61                 if (gm_status != GM_SUCCESS) {
62                         CDEBUG(D_NET, "gm_host_name_to_node_id_ex(...host %s) "
63                                "failed[%d]\n", name, gm_status);
64                         return (-1);
65                 } else
66                         CDEBUG(D_NET, "Local node %s id is [%d]\n", name, nid);
67                 spin_lock(&gmnalni->gmni_gm_lock);
68                 gm_status = gm_node_id_to_global_id(gmnalni->gmni_port,
69                                                     nid, &gmid);
70                 spin_unlock(&gmnalni->gmni_gm_lock);
71                 if (gm_status != GM_SUCCESS) {
72                         CDEBUG(D_NET, "gm_node_id_to_global_id failed[%d]\n",
73                                gm_status);
74                         return(-1);
75                 }
76                 CDEBUG(D_NET, "Global node is is [%u][%x]\n", gmid, gmid);
77                 copy_to_user(PCFG_PBUF(pcfg, 2), &gmid, pcfg->pcfg_plen2);
78         break;
79         default:
80                 CDEBUG(D_NET, "gmnal_cmd UNKNOWN[%d]\n", pcfg->pcfg_command);
81                 pcfg->pcfg_nid2 = -1;
82         }
83
84
85         return(0);
86 }
87
88
89 static int __init
90 gmnal_load(void)
91 {
92         int     status;
93         CDEBUG(D_TRACE, "This is the gmnal module initialisation routine\n");
94
95
96         CDEBUG(D_NET, "Calling gmnal_init\n");
97         status = gmnal_init();
98         if (status == PTL_OK) {
99                 CDEBUG(D_NET, "Portals GMNAL initialised ok\n");
100         } else {
101                 CDEBUG(D_NET, "Portals GMNAL Failed to initialise\n");
102                 return(-ENODEV);
103         }
104
105         CDEBUG(D_NET, "This is the end of the gmnal init routine");
106
107         return(0);
108 }
109
110
111 static void __exit
112 gmnal_unload(void)
113 {
114         gmnal_fini();
115         return;
116 }
117
118
119 module_init(gmnal_load);
120
121 module_exit(gmnal_unload);
122
123 MODULE_PARM(num_rx_threads, "i");
124 MODULE_PARM(num_stxds, "i");
125 MODULE_PARM(gm_port_id, "i");
126
127 MODULE_AUTHOR("Morgan Doyle");
128
129 MODULE_DESCRIPTION("A Portals kernel NAL for Myrinet GM.");
130
131 MODULE_LICENSE("GPL");