1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
23 #define DEBUG_SUBSYSTEM S_RPC
25 #include <linux/module.h>
26 #include <linux/lustre_net.h>
28 ptl_handle_eq_t request_out_eq, reply_in_eq, reply_out_eq, bulk_source_eq,
30 static const ptl_handle_ni_t *socknal_nip = NULL, *qswnal_nip = NULL;
33 * Free the packet when it has gone out
35 static int request_out_callback(ptl_event_t *ev)
39 if (ev->type != PTL_EVENT_SENT) {
40 // XXX make sure we understand all events, including ACK's
41 CERROR("Unknown event %d\n", ev->type);
50 * Free the packet when it has gone out
52 static int reply_out_callback(ptl_event_t *ev)
56 if (ev->type == PTL_EVENT_SENT) {
57 OBD_FREE(ev->mem_desc.start, ev->mem_desc.length);
59 // XXX make sure we understand all events, including ACK's
60 CERROR("Unknown event %d\n", ev->type);
68 * Wake up the thread waiting for the reply once it comes in.
70 static int reply_in_callback(ptl_event_t *ev)
72 struct ptlrpc_request *rpc = ev->mem_desc.user_ptr;
75 if (ev->type == PTL_EVENT_PUT) {
76 rpc->rq_repmsg = ev->mem_desc.start + ev->offset;
78 wake_up_interruptible(&rpc->rq_wait_for_rep);
80 // XXX make sure we understand all events, including ACK's
81 CERROR("Unknown event %d\n", ev->type);
88 int request_in_callback(ptl_event_t *ev)
90 struct ptlrpc_service *service = ev->mem_desc.user_ptr;
93 if (ev->rlength != ev->mlength)
94 CERROR("Warning: Possibly truncated rpc (%d/%d)\n",
95 ev->mlength, ev->rlength);
97 spin_lock(&service->srv_lock);
98 for (index = 0; index < service->srv_ring_length; index++)
99 if ( service->srv_buf[index] == ev->mem_desc.start)
102 if (index == service->srv_ring_length)
105 service->srv_ref_count[index]++;
107 if (ptl_is_valid_handle(&ev->unlinked_me)) {
110 for (idx = 0; idx < service->srv_ring_length; idx++)
111 if (service->srv_me_h[idx].handle_idx ==
112 ev->unlinked_me.handle_idx)
114 if (idx == service->srv_ring_length)
117 CDEBUG(D_NET, "unlinked %d\n", idx);
118 ptl_set_inv_handle(&(service->srv_me_h[idx]));
120 if (service->srv_ref_count[idx] == 0)
121 ptlrpc_link_svc_me(service, idx);
124 spin_unlock(&service->srv_lock);
125 if (ev->type == PTL_EVENT_PUT)
126 wake_up(&service->srv_waitq);
128 CERROR("Unexpected event type: %d\n", ev->type);
133 static int bulk_source_callback(ptl_event_t *ev)
135 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
136 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
139 if (ev->type == PTL_EVENT_SENT) {
140 CDEBUG(D_NET, "got SENT event\n");
141 } else if (ev->type == PTL_EVENT_ACK) {
142 CDEBUG(D_NET, "got ACK event\n");
143 if (bulk->b_cb != NULL)
145 if (atomic_dec_and_test(&desc->b_finished_count)) {
146 desc->b_flags |= PTL_BULK_FL_SENT;
147 wake_up_interruptible(&desc->b_waitq);
148 if (desc->b_cb != NULL)
149 desc->b_cb(desc, desc->b_cb_data);
152 CERROR("Unexpected event type!\n");
159 static int bulk_sink_callback(ptl_event_t *ev)
161 struct ptlrpc_bulk_page *bulk = ev->mem_desc.user_ptr;
162 struct ptlrpc_bulk_desc *desc = bulk->b_desc;
165 if (ev->type == PTL_EVENT_PUT) {
166 if (bulk->b_buf != ev->mem_desc.start + ev->offset)
167 CERROR("bulkbuf != mem_desc -- why?\n");
168 if (bulk->b_cb != NULL)
170 if (atomic_dec_and_test(&desc->b_finished_count)) {
171 desc->b_flags |= PTL_BULK_FL_RCVD;
172 wake_up_interruptible(&desc->b_waitq);
173 if (desc->b_cb != NULL)
174 desc->b_cb(desc, desc->b_cb_data);
177 CERROR("Unexpected event type!\n");
184 int ptlrpc_init_portals(void)
189 socknal_nip = inter_module_get_request("ksocknal_ni", "ksocknal");
190 qswnal_nip = inter_module_get_request("kqswnal_ni", "kqswnal");
191 if (socknal_nip == NULL && qswnal_nip == NULL) {
192 CERROR("get_ni failed: is a NAL module loaded?\n");
196 /* Use the qswnal if it's there */
197 if (qswnal_nip != NULL)
202 rc = PtlEQAlloc(ni, 128, request_out_callback, &request_out_eq);
204 CERROR("PtlEQAlloc failed: %d\n", rc);
206 rc = PtlEQAlloc(ni, 128, reply_out_callback, &reply_out_eq);
208 CERROR("PtlEQAlloc failed: %d\n", rc);
210 rc = PtlEQAlloc(ni, 128, reply_in_callback, &reply_in_eq);
212 CERROR("PtlEQAlloc failed: %d\n", rc);
214 rc = PtlEQAlloc(ni, 128, bulk_source_callback, &bulk_source_eq);
216 CERROR("PtlEQAlloc failed: %d\n", rc);
218 rc = PtlEQAlloc(ni, 128, bulk_sink_callback, &bulk_sink_eq);
220 CERROR("PtlEQAlloc failed: %d\n", rc);
225 void ptlrpc_exit_portals(void)
227 PtlEQFree(request_out_eq);
228 PtlEQFree(reply_out_eq);
229 PtlEQFree(reply_in_eq);
230 PtlEQFree(bulk_source_eq);
231 PtlEQFree(bulk_sink_eq);
233 if (qswnal_nip != NULL)
234 inter_module_put("kqswnal_ni");
235 if (socknal_nip != NULL)
236 inter_module_put("ksocknal_ni");