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) 2006 Myricom, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lnet/klnds/mxlnd/mxlnd.c
40 * Author: Eric Barton <eric@bartonsoftware.com>
41 * Author: Scott Atchley <atchley at myri.com>
48 .lnd_startup = mxlnd_startup,
49 .lnd_shutdown = mxlnd_shutdown,
51 .lnd_send = mxlnd_send,
52 .lnd_recv = mxlnd_recv,
55 kmx_data_t kmxlnd_data;
58 * mxlnd_ctx_free - free ctx struct
59 * @ctx - a kmx_peer pointer
61 * The calling function should remove the ctx from the ctx list first
65 mxlnd_ctx_free(struct kmx_ctx *ctx)
67 if (ctx == NULL) return;
69 if (ctx->mxc_page != NULL) {
70 __free_page(ctx->mxc_page);
71 spin_lock(&kmxlnd_data.kmx_global_lock);
72 kmxlnd_data.kmx_mem_used -= MXLND_EAGER_SIZE;
73 spin_unlock(&kmxlnd_data.kmx_global_lock);
76 if (ctx->mxc_seg_list != NULL) {
77 LASSERT(ctx->mxc_nseg > 0);
78 MXLND_FREE(ctx->mxc_seg_list, ctx->mxc_nseg * sizeof(mx_ksegment_t));
81 MXLND_FREE (ctx, sizeof (*ctx));
86 * mxlnd_ctx_alloc - allocate and initialize a new ctx struct
87 * @ctxp - address of a kmx_ctx pointer
89 * Returns 0 on success and -EINVAL, -ENOMEM on failure
92 mxlnd_ctx_alloc(struct kmx_ctx **ctxp, enum kmx_req_type type)
95 struct kmx_ctx *ctx = NULL;
97 if (ctxp == NULL) return -EINVAL;
99 MXLND_ALLOC(ctx, sizeof (*ctx));
101 CDEBUG(D_NETERROR, "Cannot allocate ctx\n");
104 memset(ctx, 0, sizeof(*ctx));
105 spin_lock_init(&ctx->mxc_lock);
107 ctx->mxc_type = type;
108 ctx->mxc_page = alloc_page (GFP_KERNEL);
109 if (ctx->mxc_page == NULL) {
110 CDEBUG(D_NETERROR, "Can't allocate page\n");
114 spin_lock(&kmxlnd_data.kmx_global_lock);
115 kmxlnd_data.kmx_mem_used += MXLND_EAGER_SIZE;
116 spin_unlock(&kmxlnd_data.kmx_global_lock);
117 ctx->mxc_msg = (struct kmx_msg *)((char *)page_address(ctx->mxc_page));
118 ctx->mxc_seg.segment_ptr = MX_PA_TO_U64(lnet_page2phys(ctx->mxc_page));
119 ctx->mxc_state = MXLND_CTX_IDLE;
130 * mxlnd_ctx_init - reset ctx struct to the default values
131 * @ctx - a kmx_ctx pointer
134 mxlnd_ctx_init(struct kmx_ctx *ctx)
136 if (ctx == NULL) return;
138 /* do not change mxc_type */
139 ctx->mxc_incarnation = 0;
140 ctx->mxc_deadline = 0;
141 ctx->mxc_state = MXLND_CTX_IDLE;
142 /* ignore mxc_global_list */
143 if (ctx->mxc_list.next != NULL && !list_empty(&ctx->mxc_list)) {
144 if (ctx->mxc_peer != NULL) spin_lock(&ctx->mxc_lock);
145 list_del_init(&ctx->mxc_list);
146 if (ctx->mxc_peer != NULL) spin_unlock(&ctx->mxc_lock);
148 /* ignore mxc_rx_list */
149 /* ignore mxc_lock */
151 ctx->mxc_peer = NULL;
152 ctx->mxc_conn = NULL;
154 /* ignore mxc_page */
155 ctx->mxc_lntmsg[0] = NULL;
156 ctx->mxc_lntmsg[1] = NULL;
157 ctx->mxc_msg_type = 0;
158 ctx->mxc_cookie = 0LL;
159 ctx->mxc_match = 0LL;
160 /* ctx->mxc_seg.segment_ptr points to mxc_page */
161 ctx->mxc_seg.segment_length = 0;
162 if (ctx->mxc_seg_list != NULL) {
163 LASSERT(ctx->mxc_nseg > 0);
164 MXLND_FREE(ctx->mxc_seg_list, ctx->mxc_nseg * sizeof(mx_ksegment_t));
166 ctx->mxc_seg_list = NULL;
169 ctx->mxc_mxreq = NULL;
170 memset(&ctx->mxc_status, 0, sizeof(mx_status_t));
174 ctx->mxc_msg->mxm_type = 0;
175 ctx->mxc_msg->mxm_credits = 0;
176 ctx->mxc_msg->mxm_nob = 0;
177 ctx->mxc_msg->mxm_seq = 0;
183 * mxlnd_free_txs - free kmx_txs and associated pages
185 * Called from mxlnd_shutdown()
190 struct kmx_ctx *tx = NULL;
191 struct kmx_ctx *next = NULL;
193 list_for_each_entry_safe(tx, next, &kmxlnd_data.kmx_txs, mxc_global_list) {
194 list_del_init(&tx->mxc_global_list);
201 * mxlnd_init_txs - allocate tx descriptors then stash on txs and idle tx lists
203 * Called from mxlnd_startup()
204 * returns 0 on success, else -ENOMEM
211 struct kmx_ctx *tx = NULL;
213 for (i = 0; i < *kmxlnd_tunables.kmx_ntx; i++) {
214 ret = mxlnd_ctx_alloc(&tx, MXLND_REQ_TX);
220 /* in startup(), no locks required */
221 list_add_tail(&tx->mxc_global_list, &kmxlnd_data.kmx_txs);
222 list_add_tail(&tx->mxc_list, &kmxlnd_data.kmx_tx_idle);
228 * mxlnd_free_rxs - free initial kmx_rx descriptors and associated pages
230 * Called from mxlnd_shutdown()
235 struct kmx_ctx *rx = NULL;
236 struct kmx_ctx *next = NULL;
238 list_for_each_entry_safe(rx, next, &kmxlnd_data.kmx_rxs, mxc_global_list) {
239 list_del_init(&rx->mxc_global_list);
246 * mxlnd_init_rxs - allocate initial rx descriptors
248 * Called from startup(). We create MXLND_MAX_PEERS plus MXLND_NTX
249 * rx descriptors. We create one for each potential peer to handle
250 * the initial connect request. We create on for each tx in case the
251 * send requires a non-eager receive.
253 * Returns 0 on success, else -ENOMEM
260 struct kmx_ctx *rx = NULL;
262 for (i = 0; i < (*kmxlnd_tunables.kmx_ntx + *kmxlnd_tunables.kmx_max_peers); i++) {
263 ret = mxlnd_ctx_alloc(&rx, MXLND_REQ_RX);
269 /* in startup(), no locks required */
270 list_add_tail(&rx->mxc_global_list, &kmxlnd_data.kmx_rxs);
271 list_add_tail(&rx->mxc_list, &kmxlnd_data.kmx_rx_idle);
277 * mxlnd_free_peers - free peers
279 * Called from mxlnd_shutdown()
282 mxlnd_free_peers(void)
285 struct kmx_peer *peer = NULL;
286 struct kmx_peer *next = NULL;
288 for (i = 0; i < MXLND_HASH_SIZE; i++) {
289 list_for_each_entry_safe(peer, next, &kmxlnd_data.kmx_peers[i], mxp_peers) {
290 list_del_init(&peer->mxp_peers);
291 if (peer->mxp_conn) mxlnd_conn_decref(peer->mxp_conn);
292 mxlnd_peer_decref(peer);
298 mxlnd_host_alloc(struct kmx_host **hostp)
300 struct kmx_host *host = NULL;
302 MXLND_ALLOC(host, sizeof (*host));
304 CDEBUG(D_NETERROR, "Cannot allocate host\n");
307 memset(host, 0, sizeof(*host));
308 spin_lock_init(&host->mxh_lock);
316 mxlnd_host_free(struct kmx_host *host)
318 if (host == NULL) return;
320 if (host->mxh_hostname != NULL)
321 MXLND_FREE(host->mxh_hostname, strlen(host->mxh_hostname) + 1);
323 MXLND_FREE(host, sizeof(*host));
328 * mxlnd_free_hosts - free kmx_hosts
330 * Called from mxlnd_shutdown()
333 mxlnd_free_hosts(void)
335 struct kmx_host *host = NULL;
336 struct kmx_host *next = NULL;
338 list_for_each_entry_safe(host, next, &kmxlnd_data.kmx_hosts, mxh_list) {
339 list_del_init(&host->mxh_list);
340 mxlnd_host_free(host);
346 #define str(s) xstr(s)
347 #define MXLND_MAX_BOARD 4 /* we expect hosts to have fewer NICs than this */
348 #define MXLND_MAX_EP_ID 16 /* we expect hosts to have less than this endpoints */
350 /* this parses a line that consists of:
352 * IP HOSTNAME BOARD ENDPOINT ID
353 * 169.192.0.113 mds01 0 3
355 * By default MX uses the alias (short hostname). If you override
356 * it using mx_hostname to use the FQDN or some other name, the hostname
357 * here must match exactly.
360 /* MX_MAX_HOSTNAME_LEN = 80. See myriexpress.h */
362 mxlnd_parse_line(char *line)
367 u32 ip[4] = { 0, 0, 0, 0 };
368 char hostname[MX_MAX_HOSTNAME_LEN];
371 struct kmx_host *host = NULL;
373 if (line == NULL) return -1;
377 if (len == 0) return -1;
379 /* convert tabs to spaces */
380 for (i = 0; i < len; i++) {
381 if (line[i] == '\t') line[i] = ' ';
384 memset(&hostname, 0 , sizeof(hostname));
385 ret = sscanf(line, "%d.%d.%d.%d %" str(MX_MAX_HOSTNAME_LEN) "s %d %d",
386 &ip[0], &ip[1], &ip[2], &ip[3], hostname, &board, &ep_id);
392 /* check for valid values */
393 /* we assume a valid IP address (all <= 255), number of NICs,
394 * and number of endpoint IDs */
395 if (ip[0] > 255 || ip [1] > 255 || ip[2] > 255 || ip[3] > 255 ||
396 board > MXLND_MAX_BOARD || ep_id > MXLND_MAX_EP_ID) {
397 CDEBUG(D_NETERROR, "Illegal value in \"%s\". Ignoring "
398 "this host.\n", line);
402 ret = mxlnd_host_alloc(&host);
403 if (ret != 0) return -1;
405 host->mxh_addr = ((ip[0]<<24)|(ip[1]<<16)|(ip[2]<<8)|ip[3]);
406 len = strlen(hostname);
407 MXLND_ALLOC(host->mxh_hostname, len + 1);
408 if (host->mxh_hostname == NULL) {
409 mxlnd_host_free(host);
412 memset(host->mxh_hostname, 0, len + 1);
413 strncpy(host->mxh_hostname, hostname, len);
414 host->mxh_board = board;
415 host->mxh_ep_id = ep_id;
417 spin_lock(&kmxlnd_data.kmx_hosts_lock);
418 list_add_tail(&host->mxh_list, &kmxlnd_data.kmx_hosts);
419 spin_unlock(&kmxlnd_data.kmx_hosts_lock);
425 mxlnd_print_hosts(void)
428 struct kmx_host *host = NULL;
430 list_for_each_entry(host, &kmxlnd_data.kmx_hosts, mxh_list) {
432 u32 addr = host->mxh_addr;
434 ip[0] = (addr >> 24) & 0xff;
435 ip[1] = (addr >> 16) & 0xff;
436 ip[2] = (addr >> 8) & 0xff;
438 CDEBUG(D_NET, "\tip= %d.%d.%d.%d\n\thost= %s\n\tboard= %d\n\tep_id= %d\n\n",
439 ip[0], ip[1], ip[2], ip[3],
440 host->mxh_hostname, host->mxh_board, host->mxh_ep_id);
446 #define MXLND_BUFSIZE (PAGE_SIZE - 1)
449 mxlnd_parse_hosts(char *filename)
453 s32 bufsize = MXLND_BUFSIZE;
456 struct file *filp = NULL;
457 struct inode *inode = NULL;
463 if (filename == NULL) return -1;
465 filp = filp_open(filename, O_RDONLY, 0);
467 CERROR("filp_open() failed for %s\n", filename);
471 inode = filp->f_dentry->d_inode;
472 if (!S_ISREG(inode->i_mode)) {
473 CERROR("%s is not a regular file\n", filename);
477 size = (s32) inode->i_size;
478 if (size < MXLND_BUFSIZE) bufsize = size;
480 MXLND_ALLOC(buf, allocd + 1);
482 CERROR("Cannot allocate buf\n");
483 filp_close(filp, current->files);
487 while (offset < size) {
488 memset(buf, 0, bufsize + 1);
489 ret = kernel_read(filp, (unsigned long) offset, buf, (unsigned long) bufsize);
491 CDEBUG(D_NETERROR, "kernel_read() returned %d - closing %s\n", ret, filename);
492 filp_close(filp, current->files);
493 MXLND_FREE(buf, allocd + 1);
497 if (ret < bufsize) bufsize = ret;
499 while (buf_off < bufsize) {
500 sep = strchr(buf + buf_off, '\n');
503 line = buf + buf_off;
505 ret = mxlnd_parse_line(line);
506 if (ret != 0 && strlen(line) != 0) {
507 CDEBUG(D_NETERROR, "Failed to parse \"%s\". Ignoring this host.\n", line);
509 buf_off += strlen(line) + 1;
511 /* last line or we need to read more */
512 line = buf + buf_off;
513 ret = mxlnd_parse_line(line);
515 bufsize -= strlen(line) + 1;
517 buf_off += strlen(line) + 1;
521 bufsize = MXLND_BUFSIZE;
524 MXLND_FREE(buf, allocd + 1);
525 filp_close(filp, current->files);
532 * mxlnd_init_mx - open the endpoint, set out ID, register the EAGER callback
533 * @ni - the network interface
535 * Returns 0 on success, -1 on failure
538 mxlnd_init_mx(lnet_ni_t *ni)
543 mx_endpoint_addr_t addr;
544 u32 board = *kmxlnd_tunables.kmx_board;
545 u32 ep_id = *kmxlnd_tunables.kmx_ep_id;
547 struct kmx_host *host = NULL;
550 if (mxret != MX_SUCCESS) {
551 CERROR("mx_init() failed with %s (%d)\n", mx_strerror(mxret), mxret);
555 ret = mxlnd_parse_hosts(*kmxlnd_tunables.kmx_hosts);
557 if (*kmxlnd_tunables.kmx_hosts != NULL) {
558 CERROR("mxlnd_parse_hosts(%s) failed\n", *kmxlnd_tunables.kmx_hosts);
564 list_for_each_entry(host, &kmxlnd_data.kmx_hosts, mxh_list) {
565 if (strcmp(host->mxh_hostname, system_utsname.nodename) == 0) {
566 /* override the defaults and module parameters with
567 * the info from the hosts file */
568 board = host->mxh_board;
569 ep_id = host->mxh_ep_id;
570 kmxlnd_data.kmx_localhost = host;
571 CDEBUG(D_NET, "my hostname is %s board %d ep_id %d\n", kmxlnd_data.kmx_localhost->mxh_hostname, kmxlnd_data.kmx_localhost->mxh_board, kmxlnd_data.kmx_localhost->mxh_ep_id);
578 CERROR("no host entry found for localhost\n");
583 mxret = mx_open_endpoint(board, ep_id, MXLND_MSG_MAGIC,
584 NULL, 0, &kmxlnd_data.kmx_endpt);
585 if (mxret != MX_SUCCESS) {
586 CERROR("mx_open_endpoint() failed with %d\n", mxret);
591 mx_get_endpoint_addr(kmxlnd_data.kmx_endpt, &addr);
592 mx_decompose_endpoint_addr(addr, &nic_id, &ep_id);
594 LASSERT(host != NULL);
595 ni->ni_nid = LNET_MKNID(LNET_NIDNET(ni->ni_nid), host->mxh_addr);
597 CDEBUG(D_NET, "My NID is 0x%llx\n", ni->ni_nid);
599 /* this will catch all unexpected receives. */
600 mxret = mx_register_unexp_handler(kmxlnd_data.kmx_endpt,
601 (mx_unexp_handler_t) mxlnd_unexpected_recv,
603 if (mxret != MX_SUCCESS) {
604 CERROR("mx_register_unexp_callback() failed with %s\n",
606 mx_close_endpoint(kmxlnd_data.kmx_endpt);
610 mxret = mx_set_request_timeout(kmxlnd_data.kmx_endpt, NULL, MXLND_COMM_TIMEOUT/HZ*1000);
611 if (mxret != MX_SUCCESS) {
612 CERROR("mx_set_request_timeout() failed with %s\n",
614 mx_close_endpoint(kmxlnd_data.kmx_endpt);
623 * mxlnd_thread_start - spawn a kernel thread with this function
624 * @fn - function pointer
625 * @arg - pointer to the parameter data
627 * Returns 0 on success and a negative value on failure
630 mxlnd_thread_start(int (*fn)(void *arg), void *arg)
633 int i = (int) ((long) arg);
635 atomic_inc(&kmxlnd_data.kmx_nthreads);
636 init_completion(&kmxlnd_data.kmx_completions[i]);
638 pid = kernel_thread (fn, arg, 0);
640 CERROR("kernel_thread() failed with %d\n", pid);
641 atomic_dec(&kmxlnd_data.kmx_nthreads);
647 * mxlnd_thread_stop - decrement thread counter
649 * The thread returns 0 when it detects shutdown.
650 * We are simply decrementing the thread counter.
653 mxlnd_thread_stop(long id)
656 atomic_dec (&kmxlnd_data.kmx_nthreads);
657 complete(&kmxlnd_data.kmx_completions[i]);
661 * mxlnd_shutdown - stop IO, clean up state
662 * @ni - LNET interface handle
664 * No calls to the LND should be made after calling this function.
667 mxlnd_shutdown (lnet_ni_t *ni)
670 int nthreads = 2 + *kmxlnd_tunables.kmx_n_waitd;
672 LASSERT (ni == kmxlnd_data.kmx_ni);
673 LASSERT (ni->ni_data == &kmxlnd_data);
674 CDEBUG(D_NET, "in shutdown()\n");
676 CDEBUG(D_MALLOC, "before MXLND cleanup: libcfs_kmemory %d "
677 "kmx_mem_used %ld\n", atomic_read (&libcfs_kmemory),
678 kmxlnd_data.kmx_mem_used);
680 switch (kmxlnd_data.kmx_init) {
684 CDEBUG(D_NET, "setting shutdown = 1\n");
685 /* set shutdown and wakeup request_waitds */
686 kmxlnd_data.kmx_shutdown = 1;
688 mx_wakeup(kmxlnd_data.kmx_endpt);
689 up(&kmxlnd_data.kmx_tx_queue_sem);
694 case MXLND_INIT_THREADS:
696 CDEBUG(D_NET, "waiting on threads\n");
697 /* wait for threads to complete */
698 for (i = 0; i < nthreads; i++) {
699 wait_for_completion(&kmxlnd_data.kmx_completions[i]);
701 LASSERT(atomic_read(&kmxlnd_data.kmx_nthreads) == 0);
703 CDEBUG(D_NET, "freeing completions\n");
704 MXLND_FREE(kmxlnd_data.kmx_completions,
705 MXLND_NCOMPLETIONS * sizeof(struct completion));
711 CDEBUG(D_NET, "stopping mx\n");
713 /* wakeup waiters if they missed the above.
714 * close endpoint to stop all traffic.
715 * this will cancel and cleanup all requests, etc. */
717 mx_wakeup(kmxlnd_data.kmx_endpt);
718 mx_close_endpoint(kmxlnd_data.kmx_endpt);
721 CDEBUG(D_NET, "mxlnd_free_hosts();\n");
728 CDEBUG(D_NET, "freeing rxs\n");
730 /* free all rxs and associated pages */
737 CDEBUG(D_NET, "freeing txs\n");
739 /* free all txs and associated pages */
744 case MXLND_INIT_DATA:
746 CDEBUG(D_NET, "freeing peers\n");
753 case MXLND_INIT_NOTHING:
756 CDEBUG(D_NET, "shutdown complete\n");
758 CDEBUG(D_MALLOC, "after MXLND cleanup: libcfs_kmemory %d "
759 "kmx_mem_used %ld\n", atomic_read (&libcfs_kmemory),
760 kmxlnd_data.kmx_mem_used);
762 kmxlnd_data.kmx_init = MXLND_INIT_NOTHING;
768 * mxlnd_startup - initialize state, open an endpoint, start IO
769 * @ni - LNET interface handle
771 * Initialize state, open an endpoint, start monitoring threads.
772 * Should only be called once.
775 mxlnd_startup (lnet_ni_t *ni)
779 int nthreads = 2; /* for timeoutd and tx_queued */
782 LASSERT (ni->ni_lnd == &the_kmxlnd);
784 if (kmxlnd_data.kmx_init != MXLND_INIT_NOTHING) {
785 CERROR("Only 1 instance supported\n");
788 CDEBUG(D_MALLOC, "before MXLND startup: libcfs_kmemory %d "
789 "kmx_mem_used %ld\n", atomic_read (&libcfs_kmemory),
790 kmxlnd_data.kmx_mem_used);
792 /* reserve 1/2 of tx for connect request messages */
793 ni->ni_maxtxcredits = *kmxlnd_tunables.kmx_ntx / 2;
794 ni->ni_peertxcredits = *kmxlnd_tunables.kmx_credits;
795 if (ni->ni_maxtxcredits < ni->ni_peertxcredits)
796 ni->ni_maxtxcredits = ni->ni_peertxcredits;
799 memset (&kmxlnd_data, 0, sizeof (kmxlnd_data));
801 kmxlnd_data.kmx_ni = ni;
802 ni->ni_data = &kmxlnd_data;
804 do_gettimeofday(&tv);
805 kmxlnd_data.kmx_incarnation = (((__u64)tv.tv_sec) * 1000000) + tv.tv_usec;
806 CDEBUG(D_NET, "my incarnation is %lld\n", kmxlnd_data.kmx_incarnation);
808 spin_lock_init (&kmxlnd_data.kmx_global_lock);
810 INIT_LIST_HEAD (&kmxlnd_data.kmx_conn_req);
811 spin_lock_init (&kmxlnd_data.kmx_conn_lock);
812 sema_init(&kmxlnd_data.kmx_conn_sem, 0);
814 INIT_LIST_HEAD (&kmxlnd_data.kmx_hosts);
815 spin_lock_init (&kmxlnd_data.kmx_hosts_lock);
817 for (i = 0; i < MXLND_HASH_SIZE; i++) {
818 INIT_LIST_HEAD (&kmxlnd_data.kmx_peers[i]);
820 rwlock_init (&kmxlnd_data.kmx_peers_lock);
822 INIT_LIST_HEAD (&kmxlnd_data.kmx_txs);
823 INIT_LIST_HEAD (&kmxlnd_data.kmx_tx_idle);
824 spin_lock_init (&kmxlnd_data.kmx_tx_idle_lock);
825 kmxlnd_data.kmx_tx_next_cookie = 1;
826 INIT_LIST_HEAD (&kmxlnd_data.kmx_tx_queue);
827 spin_lock_init (&kmxlnd_data.kmx_tx_queue_lock);
828 sema_init(&kmxlnd_data.kmx_tx_queue_sem, 0);
830 INIT_LIST_HEAD (&kmxlnd_data.kmx_rxs);
831 spin_lock_init (&kmxlnd_data.kmx_rxs_lock);
832 INIT_LIST_HEAD (&kmxlnd_data.kmx_rx_idle);
833 spin_lock_init (&kmxlnd_data.kmx_rx_idle_lock);
835 kmxlnd_data.kmx_init = MXLND_INIT_DATA;
836 /*****************************************************/
838 ret = mxlnd_init_txs();
840 CERROR("Can't alloc tx descs: %d\n", ret);
843 kmxlnd_data.kmx_init = MXLND_INIT_TXS;
844 /*****************************************************/
846 ret = mxlnd_init_rxs();
848 CERROR("Can't alloc rx descs: %d\n", ret);
851 kmxlnd_data.kmx_init = MXLND_INIT_RXS;
852 /*****************************************************/
854 ret = mxlnd_init_mx(ni);
856 CERROR("Can't init mx\n");
860 kmxlnd_data.kmx_init = MXLND_INIT_MX;
861 /*****************************************************/
865 nthreads += *kmxlnd_tunables.kmx_n_waitd;
866 MXLND_ALLOC (kmxlnd_data.kmx_completions,
867 nthreads * sizeof(struct completion));
868 if (kmxlnd_data.kmx_completions == NULL) {
869 CERROR("failed to alloc kmxlnd_data.kmx_completions\n");
872 memset(kmxlnd_data.kmx_completions, 0,
873 nthreads * sizeof(struct completion));
876 CDEBUG(D_NET, "using %d %s in mx_wait_any()\n",
877 *kmxlnd_tunables.kmx_n_waitd,
878 *kmxlnd_tunables.kmx_n_waitd == 1 ? "thread" : "threads");
880 for (i = 0; i < *kmxlnd_tunables.kmx_n_waitd; i++) {
881 ret = mxlnd_thread_start(mxlnd_request_waitd, (void*)((long)i));
883 CERROR("Starting mxlnd_request_waitd[%d] failed with %d\n", i, ret);
884 kmxlnd_data.kmx_shutdown = 1;
885 mx_wakeup(kmxlnd_data.kmx_endpt);
886 for (--i; i >= 0; i--) {
887 wait_for_completion(&kmxlnd_data.kmx_completions[i]);
889 LASSERT(atomic_read(&kmxlnd_data.kmx_nthreads) == 0);
890 MXLND_FREE(kmxlnd_data.kmx_completions,
891 MXLND_NCOMPLETIONS * sizeof(struct completion));
896 ret = mxlnd_thread_start(mxlnd_tx_queued, (void*)((long)i++));
898 CERROR("Starting mxlnd_tx_queued failed with %d\n", ret);
899 kmxlnd_data.kmx_shutdown = 1;
900 mx_wakeup(kmxlnd_data.kmx_endpt);
901 for (--i; i >= 0; i--) {
902 wait_for_completion(&kmxlnd_data.kmx_completions[i]);
904 LASSERT(atomic_read(&kmxlnd_data.kmx_nthreads) == 0);
905 MXLND_FREE(kmxlnd_data.kmx_completions,
906 MXLND_NCOMPLETIONS * sizeof(struct completion));
909 ret = mxlnd_thread_start(mxlnd_timeoutd, (void*)((long)i++));
911 CERROR("Starting mxlnd_timeoutd failed with %d\n", ret);
912 kmxlnd_data.kmx_shutdown = 1;
913 mx_wakeup(kmxlnd_data.kmx_endpt);
914 up(&kmxlnd_data.kmx_tx_queue_sem);
915 for (--i; i >= 0; i--) {
916 wait_for_completion(&kmxlnd_data.kmx_completions[i]);
918 LASSERT(atomic_read(&kmxlnd_data.kmx_nthreads) == 0);
919 MXLND_FREE(kmxlnd_data.kmx_completions,
920 MXLND_NCOMPLETIONS * sizeof(struct completion));
925 kmxlnd_data.kmx_init = MXLND_INIT_THREADS;
926 /*****************************************************/
928 kmxlnd_data.kmx_init = MXLND_INIT_ALL;
929 CDEBUG(D_MALLOC, "startup complete (kmx_mem_used %ld)\n", kmxlnd_data.kmx_mem_used);
933 CERROR("mxlnd_startup failed\n");
938 static int mxlnd_init(void)
940 lnet_register_lnd(&the_kmxlnd);
944 static void mxlnd_exit(void)
946 lnet_unregister_lnd(&the_kmxlnd);
950 module_init(mxlnd_init);
951 module_exit(mxlnd_exit);
953 MODULE_LICENSE("GPL");
954 MODULE_AUTHOR("Myricom, Inc. - help@myri.com");
955 MODULE_DESCRIPTION("Kernel MyrinetExpress LND");
956 MODULE_VERSION("0.5.0");