2 * Copyright (C) 2002 Cluster File Systems, Inc.
3 * Author: Eric Barton <eric@bartonsoftware.com>
5 * Copyright (C) 2002, Lawrence Livermore National Labs (LLNL)
6 * W. Marcus Miller - Based on ksocknal
8 * This file is part of Portals, http://www.sf.net/projects/lustre/
10 * Portals is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Portals is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Portals; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 ptl_handle_ni_t kqswnal_ni;
29 kqswnal_data_t kqswnal_data;
31 kpr_nal_interface_t kqswnal_router_interface = {
34 kprni_fwd: kqswnal_fwd_packet,
35 kprni_notify: NULL, /* we're connectionless */
39 #define QSWNAL_SYSCTL 201
41 #define QSWNAL_SYSCTL_OPTIMIZED_GETS 1
42 #define QSWNAL_SYSCTL_COPY_SMALL_FWD 2
44 static ctl_table kqswnal_ctl_table[] = {
45 {QSWNAL_SYSCTL_OPTIMIZED_GETS, "optimized_gets",
46 &kqswnal_data.kqn_optimized_gets, sizeof (int),
47 0644, NULL, &proc_dointvec},
48 {QSWNAL_SYSCTL_COPY_SMALL_FWD, "copy_small_fwd",
49 &kqswnal_data.kqn_copy_small_fwd, sizeof (int),
50 0644, NULL, &proc_dointvec},
54 static ctl_table kqswnal_top_ctl_table[] = {
55 {QSWNAL_SYSCTL, "qswnal", NULL, 0, 0555, kqswnal_ctl_table},
61 kqswnal_forward(nal_t *nal,
63 void *args, size_t args_len,
64 void *ret, size_t ret_len)
66 kqswnal_data_t *k = nal->nal_data;
67 nal_cb_t *nal_cb = k->kqn_cb;
69 LASSERT (nal == &kqswnal_api);
70 LASSERT (k == &kqswnal_data);
71 LASSERT (nal_cb == &kqswnal_lib);
73 lib_dispatch(nal_cb, k, id, args, ret); /* nal needs k */
78 kqswnal_lock (nal_t *nal, unsigned long *flags)
80 kqswnal_data_t *k = nal->nal_data;
81 nal_cb_t *nal_cb = k->kqn_cb;
83 LASSERT (nal == &kqswnal_api);
84 LASSERT (k == &kqswnal_data);
85 LASSERT (nal_cb == &kqswnal_lib);
87 nal_cb->cb_cli(nal_cb,flags);
91 kqswnal_unlock(nal_t *nal, unsigned long *flags)
93 kqswnal_data_t *k = nal->nal_data;
94 nal_cb_t *nal_cb = k->kqn_cb;
96 LASSERT (nal == &kqswnal_api);
97 LASSERT (k == &kqswnal_data);
98 LASSERT (nal_cb == &kqswnal_lib);
100 nal_cb->cb_sti(nal_cb,flags);
104 kqswnal_shutdown(nal_t *nal, int ni)
106 CDEBUG (D_NET, "shutdown\n");
108 LASSERT (nal == &kqswnal_api);
113 kqswnal_yield( nal_t *nal )
115 CDEBUG (D_NET, "yield\n");
117 if (current->need_resched)
123 kqswnal_init(int interface, ptl_pt_index_t ptl_size, ptl_ac_index_t ac_size,
124 ptl_pid_t requested_pid)
126 ptl_nid_t mynid = kqswnal_elanid2nid (kqswnal_data.kqn_elanid);
127 int nnids = kqswnal_data.kqn_nnodes;
129 CDEBUG(D_NET, "calling lib_init with nid "LPX64" of %d\n", mynid, nnids);
131 lib_init(&kqswnal_lib, mynid, 0, nnids, ptl_size, ac_size);
133 return (&kqswnal_api);
137 kqswnal_get_tx_desc (struct portals_cfg *pcfg)
140 struct list_head *tmp;
142 int index = pcfg->pcfg_count;
145 spin_lock_irqsave (&kqswnal_data.kqn_idletxd_lock, flags);
147 list_for_each (tmp, &kqswnal_data.kqn_activetxds) {
151 ktx = list_entry (tmp, kqswnal_tx_t, ktx_list);
153 pcfg->pcfg_pbuf1 = (char *)ktx;
154 pcfg->pcfg_count = NTOH__u32(ktx->ktx_wire_hdr->type);
155 pcfg->pcfg_size = NTOH__u32(ktx->ktx_wire_hdr->payload_length);
156 pcfg->pcfg_nid = NTOH__u64(ktx->ktx_wire_hdr->dest_nid);
157 pcfg->pcfg_nid2 = ktx->ktx_nid;
158 pcfg->pcfg_misc = ktx->ktx_launcher;
159 pcfg->pcfg_flags = (list_empty (&ktx->ktx_delayed_list) ? 0 : 1) |
160 (!ktx->ktx_isnblk ? 0 : 2) |
161 (ktx->ktx_state << 2);
166 spin_unlock_irqrestore (&kqswnal_data.kqn_idletxd_lock, flags);
171 kqswnal_cmd (struct portals_cfg *pcfg, void *private)
173 LASSERT (pcfg != NULL);
175 switch (pcfg->pcfg_command) {
176 case NAL_CMD_GET_TXDESC:
177 return (kqswnal_get_tx_desc (pcfg));
179 case NAL_CMD_REGISTER_MYNID:
180 CDEBUG (D_IOCTL, "setting NID offset to "LPX64" (was "LPX64")\n",
181 pcfg->pcfg_nid - kqswnal_data.kqn_elanid,
182 kqswnal_data.kqn_nid_offset);
183 kqswnal_data.kqn_nid_offset =
184 pcfg->pcfg_nid - kqswnal_data.kqn_elanid;
185 kqswnal_lib.ni.nid = pcfg->pcfg_nid;
194 kqswnal_finalise (void)
196 switch (kqswnal_data.kqn_init)
203 if (kqswnal_data.kqn_sysctl != NULL)
204 unregister_sysctl_table (kqswnal_data.kqn_sysctl);
206 PORTAL_SYMBOL_UNREGISTER (kqswnal_ni);
207 kportal_nal_unregister(QSWNAL);
211 PtlNIFini (kqswnal_ni);
212 lib_fini (&kqswnal_lib);
218 case KQN_INIT_NOTHING:
222 /**********************************************************************/
223 /* Make router stop her calling me and fail any more call-ins */
224 kpr_shutdown (&kqswnal_data.kqn_router);
226 /**********************************************************************/
227 /* flag threads we've started to terminate and wait for all to ack */
229 kqswnal_data.kqn_shuttingdown = 1;
230 wake_up_all (&kqswnal_data.kqn_sched_waitq);
232 while (atomic_read (&kqswnal_data.kqn_nthreads_running) != 0) {
233 CDEBUG(D_NET, "waiting for %d threads to start shutting down\n",
234 atomic_read (&kqswnal_data.kqn_nthreads_running));
235 set_current_state (TASK_UNINTERRUPTIBLE);
236 schedule_timeout (HZ);
239 /**********************************************************************/
240 /* close elan comms */
242 if (kqswnal_data.kqn_eprx_small != NULL)
243 ep_free_rcvr (kqswnal_data.kqn_eprx_small);
245 if (kqswnal_data.kqn_eprx_large != NULL)
246 ep_free_rcvr (kqswnal_data.kqn_eprx_large);
248 if (kqswnal_data.kqn_eptx != NULL)
249 ep_free_xmtr (kqswnal_data.kqn_eptx);
251 /* freeing the xmtr completes all txs pdq */
252 LASSERT(list_empty(&kqswnal_data.kqn_activetxds));
254 if (kqswnal_data.kqn_eprx_small != NULL)
255 ep_remove_large_rcvr (kqswnal_data.kqn_eprx_small);
257 if (kqswnal_data.kqn_eprx_large != NULL)
258 ep_remove_large_rcvr (kqswnal_data.kqn_eprx_large);
260 /* wait for transmits to complete */
261 while (!list_empty(&kqswnal_data.kqn_activetxds)) {
262 CWARN("waiting for active transmits to complete\n");
263 set_current_state(TASK_UNINTERRUPTIBLE);
264 schedule_timeout(HZ);
267 if (kqswnal_data.kqn_eptx != NULL)
268 ep_free_large_xmtr (kqswnal_data.kqn_eptx);
270 /**********************************************************************/
271 /* flag threads to terminate, wake them and wait for them to die */
273 kqswnal_data.kqn_shuttingdown = 2;
274 wake_up_all (&kqswnal_data.kqn_sched_waitq);
276 while (atomic_read (&kqswnal_data.kqn_nthreads) != 0) {
277 CDEBUG(D_NET, "waiting for %d threads to terminate\n",
278 atomic_read (&kqswnal_data.kqn_nthreads));
279 set_current_state (TASK_UNINTERRUPTIBLE);
280 schedule_timeout (HZ);
283 /**********************************************************************/
284 /* No more threads. No more portals, router or comms callbacks!
285 * I control the horizontals and the verticals...
289 LASSERT (list_empty (&kqswnal_data.kqn_readyrxds));
292 /**********************************************************************/
293 /* Complete any blocked forwarding packets with error
296 while (!list_empty (&kqswnal_data.kqn_idletxd_fwdq))
298 kpr_fwd_desc_t *fwd = list_entry (kqswnal_data.kqn_idletxd_fwdq.next,
299 kpr_fwd_desc_t, kprfd_list);
300 list_del (&fwd->kprfd_list);
301 kpr_fwd_done (&kqswnal_data.kqn_router, fwd, -EHOSTUNREACH);
304 while (!list_empty (&kqswnal_data.kqn_delayedfwds))
306 kpr_fwd_desc_t *fwd = list_entry (kqswnal_data.kqn_delayedfwds.next,
307 kpr_fwd_desc_t, kprfd_list);
308 list_del (&fwd->kprfd_list);
309 kpr_fwd_done (&kqswnal_data.kqn_router, fwd, -EHOSTUNREACH);
312 /**********************************************************************/
313 /* Wait for router to complete any packets I sent her
316 kpr_deregister (&kqswnal_data.kqn_router);
319 /**********************************************************************/
320 /* Unmap message buffers and free all descriptors and buffers
324 /* FTTB, we need to unmap any remaining mapped memory. When
325 * ep_dvma_release() get fixed (and releases any mappings in the
326 * region), we can delete all the code from here --------> */
328 if (kqswnal_data.kqn_txds != NULL) {
331 for (i = 0; i < KQSW_NTXMSGS + KQSW_NNBLK_TXMSGS; i++) {
332 kqswnal_tx_t *ktx = &kqswnal_data.kqn_txds[i];
334 /* If ktx has a buffer, it got mapped; unmap now.
335 * NB only the pre-mapped stuff is still mapped
336 * since all tx descs must be idle */
338 if (ktx->ktx_buffer != NULL)
339 ep_dvma_unload(kqswnal_data.kqn_ep,
340 kqswnal_data.kqn_ep_tx_nmh,
345 if (kqswnal_data.kqn_rxds != NULL) {
348 for (i = 0; i < KQSW_NRXMSGS_SMALL + KQSW_NRXMSGS_LARGE; i++) {
349 kqswnal_rx_t *krx = &kqswnal_data.kqn_rxds[i];
351 /* If krx_kiov[0].kiov_page got allocated, it got mapped.
352 * NB subsequent pages get merged */
354 if (krx->krx_kiov[0].kiov_page != NULL)
355 ep_dvma_unload(kqswnal_data.kqn_ep,
356 kqswnal_data.kqn_ep_rx_nmh,
357 &krx->krx_elanbuffer);
360 /* <----------- to here */
362 if (kqswnal_data.kqn_ep_rx_nmh != NULL)
363 ep_dvma_release(kqswnal_data.kqn_ep, kqswnal_data.kqn_ep_rx_nmh);
365 if (kqswnal_data.kqn_ep_tx_nmh != NULL)
366 ep_dvma_release(kqswnal_data.kqn_ep, kqswnal_data.kqn_ep_tx_nmh);
368 if (kqswnal_data.kqn_eprxdmahandle != NULL)
370 elan3_dvma_unload(kqswnal_data.kqn_ep->DmaState,
371 kqswnal_data.kqn_eprxdmahandle, 0,
372 KQSW_NRXMSGPAGES_SMALL * KQSW_NRXMSGS_SMALL +
373 KQSW_NRXMSGPAGES_LARGE * KQSW_NRXMSGS_LARGE);
375 elan3_dma_release(kqswnal_data.kqn_ep->DmaState,
376 kqswnal_data.kqn_eprxdmahandle);
379 if (kqswnal_data.kqn_eptxdmahandle != NULL)
381 elan3_dvma_unload(kqswnal_data.kqn_ep->DmaState,
382 kqswnal_data.kqn_eptxdmahandle, 0,
383 KQSW_NTXMSGPAGES * (KQSW_NTXMSGS +
386 elan3_dma_release(kqswnal_data.kqn_ep->DmaState,
387 kqswnal_data.kqn_eptxdmahandle);
391 if (kqswnal_data.kqn_txds != NULL)
395 for (i = 0; i < KQSW_NTXMSGS + KQSW_NNBLK_TXMSGS; i++)
397 kqswnal_tx_t *ktx = &kqswnal_data.kqn_txds[i];
399 if (ktx->ktx_buffer != NULL)
400 PORTAL_FREE(ktx->ktx_buffer,
401 KQSW_TX_BUFFER_SIZE);
404 PORTAL_FREE(kqswnal_data.kqn_txds,
405 sizeof (kqswnal_tx_t) * (KQSW_NTXMSGS +
409 if (kqswnal_data.kqn_rxds != NULL)
414 for (i = 0; i < KQSW_NRXMSGS_SMALL + KQSW_NRXMSGS_LARGE; i++)
416 kqswnal_rx_t *krx = &kqswnal_data.kqn_rxds[i];
418 for (j = 0; j < krx->krx_npages; j++)
419 if (krx->krx_kiov[j].kiov_page != NULL)
420 __free_page (krx->krx_kiov[j].kiov_page);
423 PORTAL_FREE(kqswnal_data.kqn_rxds,
424 sizeof(kqswnal_rx_t) * (KQSW_NRXMSGS_SMALL +
425 KQSW_NRXMSGS_LARGE));
428 /* resets flags, pointers to NULL etc */
429 memset(&kqswnal_data, 0, sizeof (kqswnal_data));
431 CDEBUG (D_MALLOC, "done kmem %d\n", atomic_read(&portal_kmemory));
433 printk (KERN_INFO "Lustre: Routing QSW NAL unloaded (final mem %d)\n",
434 atomic_read(&portal_kmemory));
438 kqswnal_initialise (void)
441 EP_RAILMASK all_rails = EP_RAILMASK_ALL;
443 ELAN3_DMA_REQUEST dmareq;
448 int pkmem = atomic_read(&portal_kmemory);
450 LASSERT (kqswnal_data.kqn_init == KQN_INIT_NOTHING);
452 CDEBUG (D_MALLOC, "start kmem %d\n", atomic_read(&portal_kmemory));
454 kqswnal_api.forward = kqswnal_forward;
455 kqswnal_api.shutdown = kqswnal_shutdown;
456 kqswnal_api.yield = kqswnal_yield;
457 kqswnal_api.validate = NULL; /* our api validate is a NOOP */
458 kqswnal_api.lock = kqswnal_lock;
459 kqswnal_api.unlock = kqswnal_unlock;
460 kqswnal_api.nal_data = &kqswnal_data;
462 kqswnal_lib.nal_data = &kqswnal_data;
464 memset(&kqswnal_rpc_success, 0, sizeof(kqswnal_rpc_success));
465 memset(&kqswnal_rpc_failed, 0, sizeof(kqswnal_rpc_failed));
467 kqswnal_rpc_failed.Data[0] = -ECONNREFUSED;
469 kqswnal_rpc_failed.Status = -ECONNREFUSED;
471 /* ensure all pointers NULL etc */
472 memset (&kqswnal_data, 0, sizeof (kqswnal_data));
474 kqswnal_data.kqn_optimized_gets = KQSW_OPTIMIZED_GETS;
475 kqswnal_data.kqn_copy_small_fwd = KQSW_COPY_SMALL_FWD;
477 kqswnal_data.kqn_cb = &kqswnal_lib;
479 INIT_LIST_HEAD (&kqswnal_data.kqn_idletxds);
480 INIT_LIST_HEAD (&kqswnal_data.kqn_nblk_idletxds);
481 INIT_LIST_HEAD (&kqswnal_data.kqn_activetxds);
482 spin_lock_init (&kqswnal_data.kqn_idletxd_lock);
483 init_waitqueue_head (&kqswnal_data.kqn_idletxd_waitq);
484 INIT_LIST_HEAD (&kqswnal_data.kqn_idletxd_fwdq);
486 INIT_LIST_HEAD (&kqswnal_data.kqn_delayedfwds);
487 INIT_LIST_HEAD (&kqswnal_data.kqn_delayedtxds);
488 INIT_LIST_HEAD (&kqswnal_data.kqn_readyrxds);
490 spin_lock_init (&kqswnal_data.kqn_sched_lock);
491 init_waitqueue_head (&kqswnal_data.kqn_sched_waitq);
493 spin_lock_init (&kqswnal_data.kqn_statelock);
495 /* pointers/lists/locks initialised */
496 kqswnal_data.kqn_init = KQN_INIT_DATA;
499 kqswnal_data.kqn_ep = ep_system();
500 if (kqswnal_data.kqn_ep == NULL) {
501 CERROR("Can't initialise EKC\n");
505 if (ep_waitfor_nodeid(kqswnal_data.kqn_ep) == ELAN_INVALID_NODE) {
506 CERROR("Can't get elan ID\n");
511 /**********************************************************************/
512 /* Find the first Elan device */
514 kqswnal_data.kqn_ep = ep_device (0);
515 if (kqswnal_data.kqn_ep == NULL)
517 CERROR ("Can't get elan device 0\n");
522 kqswnal_data.kqn_nid_offset = 0;
523 kqswnal_data.kqn_nnodes = ep_numnodes (kqswnal_data.kqn_ep);
524 kqswnal_data.kqn_elanid = ep_nodeid (kqswnal_data.kqn_ep);
526 /**********************************************************************/
527 /* Get the transmitter */
529 kqswnal_data.kqn_eptx = ep_alloc_xmtr (kqswnal_data.kqn_ep);
530 if (kqswnal_data.kqn_eptx == NULL)
532 CERROR ("Can't allocate transmitter\n");
537 /**********************************************************************/
538 /* Get the receivers */
540 kqswnal_data.kqn_eprx_small = ep_alloc_rcvr (kqswnal_data.kqn_ep,
541 EP_MSG_SVC_PORTALS_SMALL,
542 KQSW_EP_ENVELOPES_SMALL);
543 if (kqswnal_data.kqn_eprx_small == NULL)
545 CERROR ("Can't install small msg receiver\n");
550 kqswnal_data.kqn_eprx_large = ep_alloc_rcvr (kqswnal_data.kqn_ep,
551 EP_MSG_SVC_PORTALS_LARGE,
552 KQSW_EP_ENVELOPES_LARGE);
553 if (kqswnal_data.kqn_eprx_large == NULL)
555 CERROR ("Can't install large msg receiver\n");
560 /**********************************************************************/
561 /* Reserve Elan address space for transmit descriptors NB we may
562 * either send the contents of associated buffers immediately, or
563 * map them for the peer to suck/blow... */
565 kqswnal_data.kqn_ep_tx_nmh =
566 ep_dvma_reserve(kqswnal_data.kqn_ep,
567 KQSW_NTXMSGPAGES*(KQSW_NTXMSGS+KQSW_NNBLK_TXMSGS),
569 if (kqswnal_data.kqn_ep_tx_nmh == NULL) {
570 CERROR("Can't reserve tx dma space\n");
575 dmareq.Waitfn = DDI_DMA_SLEEP;
576 dmareq.ElanAddr = (E3_Addr) 0;
577 dmareq.Attr = PTE_LOAD_LITTLE_ENDIAN;
578 dmareq.Perm = ELAN_PERM_REMOTEWRITE;
580 rc = elan3_dma_reserve(kqswnal_data.kqn_ep->DmaState,
581 KQSW_NTXMSGPAGES*(KQSW_NTXMSGS+KQSW_NNBLK_TXMSGS),
582 &dmareq, &kqswnal_data.kqn_eptxdmahandle);
583 if (rc != DDI_SUCCESS)
585 CERROR ("Can't reserve rx dma space\n");
590 /**********************************************************************/
591 /* Reserve Elan address space for receive buffers */
593 kqswnal_data.kqn_ep_rx_nmh =
594 ep_dvma_reserve(kqswnal_data.kqn_ep,
595 KQSW_NRXMSGPAGES_SMALL * KQSW_NRXMSGS_SMALL +
596 KQSW_NRXMSGPAGES_LARGE * KQSW_NRXMSGS_LARGE,
598 if (kqswnal_data.kqn_ep_tx_nmh == NULL) {
599 CERROR("Can't reserve rx dma space\n");
604 dmareq.Waitfn = DDI_DMA_SLEEP;
605 dmareq.ElanAddr = (E3_Addr) 0;
606 dmareq.Attr = PTE_LOAD_LITTLE_ENDIAN;
607 dmareq.Perm = ELAN_PERM_REMOTEWRITE;
609 rc = elan3_dma_reserve (kqswnal_data.kqn_ep->DmaState,
610 KQSW_NRXMSGPAGES_SMALL * KQSW_NRXMSGS_SMALL +
611 KQSW_NRXMSGPAGES_LARGE * KQSW_NRXMSGS_LARGE,
612 &dmareq, &kqswnal_data.kqn_eprxdmahandle);
613 if (rc != DDI_SUCCESS)
615 CERROR ("Can't reserve rx dma space\n");
620 /**********************************************************************/
621 /* Allocate/Initialise transmit descriptors */
623 PORTAL_ALLOC(kqswnal_data.kqn_txds,
624 sizeof(kqswnal_tx_t) * (KQSW_NTXMSGS + KQSW_NNBLK_TXMSGS));
625 if (kqswnal_data.kqn_txds == NULL)
631 /* clear flags, null pointers etc */
632 memset(kqswnal_data.kqn_txds, 0,
633 sizeof(kqswnal_tx_t) * (KQSW_NTXMSGS + KQSW_NNBLK_TXMSGS));
634 for (i = 0; i < (KQSW_NTXMSGS + KQSW_NNBLK_TXMSGS); i++)
637 kqswnal_tx_t *ktx = &kqswnal_data.kqn_txds[i];
638 int basepage = i * KQSW_NTXMSGPAGES;
640 PORTAL_ALLOC (ktx->ktx_buffer, KQSW_TX_BUFFER_SIZE);
641 if (ktx->ktx_buffer == NULL)
647 /* Map pre-allocated buffer NOW, to save latency on transmit */
648 premapped_pages = kqswnal_pages_spanned(ktx->ktx_buffer,
649 KQSW_TX_BUFFER_SIZE);
651 ep_dvma_load(kqswnal_data.kqn_ep, NULL,
652 ktx->ktx_buffer, KQSW_TX_BUFFER_SIZE,
653 kqswnal_data.kqn_ep_tx_nmh, basepage,
654 &all_rails, &ktx->ktx_ebuffer);
656 elan3_dvma_kaddr_load (kqswnal_data.kqn_ep->DmaState,
657 kqswnal_data.kqn_eptxdmahandle,
658 ktx->ktx_buffer, KQSW_TX_BUFFER_SIZE,
659 basepage, &ktx->ktx_ebuffer);
661 ktx->ktx_basepage = basepage + premapped_pages; /* message mapping starts here */
662 ktx->ktx_npages = KQSW_NTXMSGPAGES - premapped_pages; /* for this many pages */
664 INIT_LIST_HEAD (&ktx->ktx_delayed_list);
666 ktx->ktx_state = KTX_IDLE;
667 ktx->ktx_isnblk = (i >= KQSW_NTXMSGS);
668 list_add_tail (&ktx->ktx_list,
669 ktx->ktx_isnblk ? &kqswnal_data.kqn_nblk_idletxds :
670 &kqswnal_data.kqn_idletxds);
673 /**********************************************************************/
674 /* Allocate/Initialise receive descriptors */
676 PORTAL_ALLOC (kqswnal_data.kqn_rxds,
677 sizeof (kqswnal_rx_t) * (KQSW_NRXMSGS_SMALL + KQSW_NRXMSGS_LARGE));
678 if (kqswnal_data.kqn_rxds == NULL)
684 memset(kqswnal_data.kqn_rxds, 0, /* clear flags, null pointers etc */
685 sizeof(kqswnal_rx_t) * (KQSW_NRXMSGS_SMALL+KQSW_NRXMSGS_LARGE));
688 for (i = 0; i < KQSW_NRXMSGS_SMALL + KQSW_NRXMSGS_LARGE; i++)
696 kqswnal_rx_t *krx = &kqswnal_data.kqn_rxds[i];
698 if (i < KQSW_NRXMSGS_SMALL)
700 krx->krx_npages = KQSW_NRXMSGPAGES_SMALL;
701 krx->krx_eprx = kqswnal_data.kqn_eprx_small;
705 krx->krx_npages = KQSW_NRXMSGPAGES_LARGE;
706 krx->krx_eprx = kqswnal_data.kqn_eprx_large;
709 LASSERT (krx->krx_npages > 0);
710 for (j = 0; j < krx->krx_npages; j++)
712 struct page *page = alloc_page(GFP_KERNEL);
719 krx->krx_kiov[j].kiov_page = page;
720 LASSERT(page_address(page) != NULL);
723 ep_dvma_load(kqswnal_data.kqn_ep, NULL,
725 PAGE_SIZE, kqswnal_data.kqn_ep_rx_nmh,
726 elan_page_idx, &all_rails, &elanbuffer);
729 krx->krx_elanbuffer = elanbuffer;
731 rc = ep_nmd_merge(&krx->krx_elanbuffer,
732 &krx->krx_elanbuffer,
734 /* NB contiguous mapping */
738 elan3_dvma_kaddr_load(kqswnal_data.kqn_ep->DmaState,
739 kqswnal_data.kqn_eprxdmahandle,
741 PAGE_SIZE, elan_page_idx,
744 krx->krx_elanbuffer = elanbuffer;
746 /* NB contiguous mapping */
747 LASSERT (elanbuffer == krx->krx_elanbuffer + j * PAGE_SIZE);
753 LASSERT (elan_page_idx ==
754 (KQSW_NRXMSGS_SMALL * KQSW_NRXMSGPAGES_SMALL) +
755 (KQSW_NRXMSGS_LARGE * KQSW_NRXMSGPAGES_LARGE));
757 /**********************************************************************/
758 /* Network interface ready to initialise */
760 rc = PtlNIInit(kqswnal_init, 32, 4, 0, &kqswnal_ni);
763 CERROR ("PtlNIInit failed %d\n", rc);
768 kqswnal_data.kqn_init = KQN_INIT_PTL;
770 /**********************************************************************/
771 /* Queue receives, now that it's OK to run their completion callbacks */
773 for (i = 0; i < KQSW_NRXMSGS_SMALL + KQSW_NRXMSGS_LARGE; i++)
775 kqswnal_rx_t *krx = &kqswnal_data.kqn_rxds[i];
777 /* NB this enqueue can allocate/sleep (attr == 0) */
779 rc = ep_queue_receive(krx->krx_eprx, kqswnal_rxhandler, krx,
780 &krx->krx_elanbuffer, 0);
782 rc = ep_queue_receive(krx->krx_eprx, kqswnal_rxhandler, krx,
784 krx->krx_npages * PAGE_SIZE, 0);
786 if (rc != EP_SUCCESS)
788 CERROR ("failed ep_queue_receive %d\n", rc);
794 /**********************************************************************/
795 /* Spawn scheduling threads */
796 for (i = 0; i < smp_num_cpus; i++)
798 rc = kqswnal_thread_start (kqswnal_scheduler, NULL);
801 CERROR ("failed to spawn scheduling thread: %d\n", rc);
807 /**********************************************************************/
808 /* Connect to the router */
809 rc = kpr_register (&kqswnal_data.kqn_router, &kqswnal_router_interface);
810 CDEBUG(D_NET, "Can't initialise routing interface (rc = %d): not routing\n",rc);
812 rc = kportal_nal_register (QSWNAL, &kqswnal_cmd, NULL);
814 CERROR ("Can't initialise command interface (rc = %d)\n", rc);
820 /* Press on regardless even if registering sysctl doesn't work */
821 kqswnal_data.kqn_sysctl = register_sysctl_table (kqswnal_top_ctl_table, 0);
824 PORTAL_SYMBOL_REGISTER(kqswnal_ni);
825 kqswnal_data.kqn_init = KQN_INIT_ALL;
827 printk(KERN_INFO "Lustre: Routing QSW NAL loaded on node %d of %d "
828 "(Routing %s, initial mem %d)\n",
829 kqswnal_data.kqn_elanid, kqswnal_data.kqn_nnodes,
830 kpr_routing (&kqswnal_data.kqn_router) ? "enabled" : "disabled",
837 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
838 MODULE_DESCRIPTION("Kernel Quadrics/Elan NAL v1.01");
839 MODULE_LICENSE("GPL");
841 module_init (kqswnal_initialise);
842 module_exit (kqswnal_finalise);
844 EXPORT_SYMBOL (kqswnal_ni);