Whamcloud - gitweb
Land b_release_1_4_3 onto HEAD (20050619_0305)
[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 = sizeof(gmnal_msghdr_t) + sizeof(ptl_hdr_t) + PTL_MTU;
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_PBUF(pcfg, 1), 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,
60                                                        name, &nid);
61                 GMNAL_GM_UNLOCK(nal_data);
62                 if (gm_status != GM_SUCCESS) {
63                         CDEBUG(D_INFO, "gm_host_name_to_node_id_ex(...host %s) "
64                                "failed[%d]\n", name, gm_status);
65                         return (-1);
66                 } else
67                         CDEBUG(D_INFO, "Local node %s id is [%d]\n", name, nid);
68                 GMNAL_GM_LOCK(nal_data);
69                 gm_status = gm_node_id_to_global_id(nal_data->gm_port,
70                                                     nid, &gnid);
71                 GMNAL_GM_UNLOCK(nal_data);
72                 if (gm_status != GM_SUCCESS) {
73                         CDEBUG(D_INFO, "gm_node_id_to_global_id failed[%d]\n",
74                                gm_status);
75                         return(-1);
76                 }
77                 CDEBUG(D_INFO, "Global node is is [%u][%x]\n", gnid, gnid);
78                 copy_to_user(PCFG_PBUF(pcfg, 2), &gnid, pcfg->pcfg_plen2);
79         break;
80         default:
81                 CDEBUG(D_INFO, "gmnal_cmd UNKNOWN[%d]\n", pcfg->pcfg_command);
82                 pcfg->pcfg_nid2 = -1;
83         }
84
85
86         return(0);
87 }
88
89
90 static int __init
91 gmnal_load(void)
92 {
93         int     status;
94         CDEBUG(D_TRACE, "This is the gmnal module initialisation routine\n");
95
96
97         CDEBUG(D_INFO, "Calling gmnal_init\n");
98         status = gmnal_init();
99         if (status == PTL_OK) {
100                 CDEBUG(D_INFO, "Portals GMNAL initialised ok\n");
101         } else {
102                 CDEBUG(D_INFO, "Portals GMNAL Failed to initialise\n");
103                 return(-ENODEV);
104         }
105
106         CDEBUG(D_INFO, "This is the end of the gmnal init routine");
107
108         return(0);
109 }
110
111
112 static void __exit
113 gmnal_unload(void)
114 {
115         gmnal_fini();
116         return;
117 }
118
119
120 module_init(gmnal_load);
121
122 module_exit(gmnal_unload);
123
124 MODULE_PARM(gmnal_small_msg_size, "i");
125 MODULE_PARM(num_rx_threads, "i");
126 MODULE_PARM(num_stxds, "i");
127 MODULE_PARM(gm_port_id, "i");
128
129 MODULE_AUTHOR("Morgan Doyle");
130
131 MODULE_DESCRIPTION("A Portals kernel NAL for Myrinet GM.");
132
133 MODULE_LICENSE("GPL");