Whamcloud - gitweb
9fd218254e19924c5623a0684291b517ef99893c
[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 int gmnal_small_msg_size = 525312;
26 /*
27  *      -1 indicates default value.
28  *      This is 1 thread per cpu
29  *      See start_kernel_threads
30  */
31 int num_rx_threads = -1;
32 int num_stxds = 5;
33 int gm_port_id = 4;
34
35 int 
36 gmnal_cmd(struct portals_cfg *pcfg, void *private)
37 {
38         gmnal_data_t    *nal_data = NULL;
39         char            *name = NULL;
40         int             nid = -2;
41         int             gnid;
42         gm_status_t     gm_status;
43
44
45         CDEBUG(D_TRACE, "gmnal_cmd [%d] private [%p]\n", 
46                pcfg->pcfg_command, private);
47         nal_data = (gmnal_data_t*)private;
48         switch(pcfg->pcfg_command) {
49         /*
50          * just reuse already defined GET_NID. Should define GMNAL version
51          */
52         case(GMNAL_IOC_GET_GNID):
53
54                 PORTAL_ALLOC(name, pcfg->pcfg_plen1);
55                 copy_from_user(name, pcfg->pcfg_pbuf1, pcfg->pcfg_plen1);
56         
57                 GMNAL_GM_LOCK(nal_data);
58                 //nid = gm_host_name_to_node_id(nal_data->gm_port, name);
59                 gm_status = gm_host_name_to_node_id_ex (nal_data->gm_port, 0, name, &nid);
60                 GMNAL_GM_UNLOCK(nal_data);
61                 if (gm_status != GM_SUCCESS) {
62                         CDEBUG(D_INFO, "gm_host_name_to_node_id_ex(...host %s) failed[%d]\n",
63                                 name, gm_status);
64                         return (-1);
65                 } else
66                         CDEBUG(D_INFO, "Local node %s id is [%d]\n", name, nid);
67                 GMNAL_GM_LOCK(nal_data);
68                 gm_status = gm_node_id_to_global_id(nal_data->gm_port, 
69                                                     nid, &gnid);
70                 GMNAL_GM_UNLOCK(nal_data);
71                 if (gm_status != GM_SUCCESS) {
72                         CDEBUG(D_INFO, "gm_node_id_to_global_id failed[%d]\n", 
73                                gm_status);
74                         return(-1);
75                 }
76                 CDEBUG(D_INFO, "Global node is is [%u][%x]\n", gnid, gnid);
77                 copy_to_user(pcfg->pcfg_pbuf2, &gnid, pcfg->pcfg_plen2);
78         break;
79         default:
80                 CDEBUG(D_INFO, "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_INFO, "Calling gmnal_init\n");
97         status = gmnal_init();
98         if (status == PTL_OK) {
99                 CDEBUG(D_INFO, "Portals GMNAL initialised ok\n");
100         } else {
101                 CDEBUG(D_INFO, "Portals GMNAL Failed to initialise\n");
102                 return(-ENODEV);
103                 
104         }
105
106         CDEBUG(D_INFO, "This is the end of the gmnal init routine");
107
108
109         return(0);
110 }
111
112
113 static void __exit
114 gmnal_unload(void)
115 {
116         gmnal_fini();
117         return;
118 }
119
120
121 module_init(gmnal_load);
122
123 module_exit(gmnal_unload);
124
125 MODULE_PARM(gmnal_small_msg_size, "i");
126 MODULE_PARM(num_rx_threads, "i");
127 MODULE_PARM(num_stxds, "i");
128 MODULE_PARM(gm_port_id, "i");
129
130 MODULE_AUTHOR("Morgan Doyle");
131
132 MODULE_DESCRIPTION("A Portals kernel NAL for Myrinet GM.");
133
134 MODULE_LICENSE("GPL");