2 * Copyright (C) 2009-2012 Cray, Inc.
4 * Author: Nic Henke <nic@cray.com>
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.
22 #ifndef _GNILND_API_WRAP_H
23 #define _GNILND_API_WRAP_H
25 /* LNet is allocated failure locations 0xe000 to 0xffff */
27 /* GNILND has 0xf0XX */
28 #define CFS_FAIL_GNI 0xf000
29 #define CFS_FAIL_GNI_PHYS_MAP 0xf001
30 #define CFS_FAIL_GNI_VIRT_MAP 0xf002
31 #define CFS_FAIL_GNI_GET_UNMAP 0xf003
32 #define CFS_FAIL_GNI_PUT_UNMAP 0xf004
33 #define CFS_FAIL_GNI_MAP_TX 0xf005
34 #define CFS_FAIL_GNI_SMSG_SEND 0xf006
35 #define CFS_FAIL_GNI_CLOSE_SEND 0xf007
36 #define CFS_FAIL_GNI_CDM_CREATE 0xf008
37 #define CFS_FAIL_GNI_CDM_DESTROY 0xf009
38 #define CFS_FAIL_GNI_CDM_ATTACH 0xf00a
39 #define CFS_FAIL_GNI_CQ_CREATE 0xf00b
40 #define CFS_FAIL_GNI_CQ_DESTROY 0xf00c
41 #define CFS_FAIL_GNI_EP_BIND 0xf00d
42 #define CFS_FAIL_GNI_EP_UNBIND 0xf00e
43 #define CFS_FAIL_GNI_EP_SET_EVDATA 0xf00f
44 #define CFS_FAIL_GNI_SMSG_INIT 0xf010
45 #define CFS_FAIL_GNI_SMSG_RELEASE 0xf011
46 #define CFS_FAIL_GNI_POST_RDMA 0xf012
47 #define CFS_FAIL_GNI_GET_COMPLETED 0xf013
48 #define CFS_FAIL_GNI_EP_DESTROY 0xf015
49 #define CFS_FAIL_GNI_VIRT_UNMAP 0xf016
50 #define CFS_FAIL_GNI_MDD_RELEASE 0xf017
51 #define CFS_FAIL_GNI_NOOP_SEND 0xf018
52 #define CFS_FAIL_GNI_ERR_SUBSCRIBE 0xf01a
53 #define CFS_FAIL_GNI_QUIESCE_RACE 0xf01b
54 #define CFS_FAIL_GNI_DG_TERMINATE 0xf01c
55 #define CFS_FAIL_GNI_REG_QUIESCE 0xf01d
56 #define CFS_FAIL_GNI_IN_QUIESCE 0xf01e
57 #define CFS_FAIL_GNI_DELAY_RDMA 0xf01f
58 #define CFS_FAIL_GNI_SR_DOWN_RACE 0xf020
59 #define CFS_FAIL_GNI_ALLOC_TX 0xf021
60 #define CFS_FAIL_GNI_FMABLK_AVAIL 0xf022
61 #define CFS_FAIL_GNI_EP_CREATE 0xf023
62 #define CFS_FAIL_GNI_CQ_GET_EVENT 0xf024
63 #define CFS_FAIL_GNI_PROBE 0xf025
64 #define CFS_FAIL_GNI_EP_TEST 0xf026
65 #define CFS_FAIL_GNI_CONNREQ_DROP 0xf027
66 #define CFS_FAIL_GNI_CONNREQ_PROTO 0xf028
67 #define CFS_FAIL_GNI_CONND_PILEUP 0xf029
68 #define CFS_FAIL_GNI_PHYS_SETUP 0xf02a
69 #define CFS_FAIL_GNI_FIND_TARGET 0xf02b
70 #define CFS_FAIL_GNI_WC_DGRAM_FREE 0xf02c
71 #define CFS_FAIL_GNI_DROP_CLOSING 0xf02d
72 #define CFS_FAIL_GNI_RX_CLOSE_CLOSING 0xf02e
73 #define CFS_FAIL_GNI_RX_CLOSE_CLOSED 0xf02f
74 #define CFS_FAIL_GNI_EP_POST 0xf030
75 #define CFS_FAIL_GNI_PACK_SRCNID 0xf031
76 #define CFS_FAIL_GNI_PACK_DSTNID 0xf032
77 #define CFS_FAIL_GNI_PROBE_WAIT 0xf033
78 #define CFS_FAIL_GNI_SMSG_CKSUM1 0xf034
79 #define CFS_FAIL_GNI_SMSG_CKSUM2 0xf035
80 #define CFS_FAIL_GNI_SMSG_CKSUM3 0xf036
81 #define CFS_FAIL_GNI_DROP_DESTROY_EP 0xf037
82 #define CFS_FAIL_GNI_SMSG_GETNEXT 0xf038
83 #define CFS_FAIL_GNI_FINISH_PURG 0xf039
84 #define CFS_FAIL_GNI_PURG_REL_DELAY 0xf03a
85 #define CFS_FAIL_GNI_DONT_NOTIFY 0xf03b
86 #define CFS_FAIL_GNI_VIRT_SMALL_MAP 0xf03c
87 #define CFS_FAIL_GNI_DELAY_RDMAQ 0xf03d
88 #define CFS_FAIL_GNI_PAUSE_SHUTDOWN 0xf03e
89 #define CFS_FAIL_GNI_PAUSE_DGRAM_COMP 0xf03f
90 #define CFS_FAIL_GNI_NET_LOOKUP 0xf040
91 #define CFS_FAIL_GNI_RECV_TIMEOUT 0xf041
92 #define CFS_FAIL_GNI_SEND_TIMEOUT 0xf042
93 #define CFS_FAIL_GNI_ONLY_NOOP 0xf043
94 #define CFS_FAIL_GNI_FINISH_PURG2 0xf044
95 #define CFS_FAIL_GNI_RACE_RESET 0xf045
96 #define CFS_FAIL_GNI_GNP_CONNECTING1 0xf046
97 #define CFS_FAIL_GNI_GNP_CONNECTING2 0xf047
98 #define CFS_FAIL_GNI_GNP_CONNECTING3 0xf048
99 #define CFS_FAIL_GNI_SCHEDULE_COMPLETE 0xf049
100 #define CFS_FAIL_GNI_PUT_ACK_AGAIN 0xf050
101 #define CFS_FAIL_GNI_GET_REQ_AGAIN 0xf051
102 #define CFS_FAIL_GNI_SCHED_DEADLINE 0xf052
103 #define CFS_FAIL_GNI_DGRAM_DEADLINE 0xf053
104 #define CFS_FAIL_GNI_DGRAM_DROP_TX 0xf054
106 extern uint32_t kgni_driver_version;
109 kgnilnd_check_kgni_version(void)
113 kgnilnd_data.kgn_enable_gl_mutex = 1;
114 kdv = symbol_get(kgni_driver_version);
116 LCONSOLE_INFO("Not using thread safe locking -"
117 " no symbol kgni_driver_version\n");
121 /* Thread-safe kgni implemented in minor ver 0x44/45, code rev 0xb9 */
122 if (*kdv < GNI_VERSION_CHECK(0, GNILND_KGNI_TS_MINOR_VER, 0xb9)) {
123 symbol_put(kgni_driver_version);
124 LCONSOLE_INFO("Not using thread safe locking, gni version 0x%x,"
125 " need >= 0x%x\n", *kdv,
126 GNI_VERSION_CHECK(0, GNILND_KGNI_TS_MINOR_VER, 0xb9));
130 symbol_put(kgni_driver_version);
131 /* Use thread-safe locking */
132 kgnilnd_data.kgn_enable_gl_mutex = 0;
137 _kgnilnd_api_rc_lbug(const char *rcstr, int rc, struct libcfs_debug_msg_data *data,
138 const char *fmt, ...)
139 __attribute__ ((format (printf, 4, 5)));
141 #define kgnilnd_api_rc_lbug(msgdata, rc, fmt, a...) \
143 CFS_CHECK_STACK(msgdata, D_ERROR, NULL); \
144 /* we don't mask this - it is always at D_ERROR */ \
145 _kgnilnd_api_rc_lbug(kgnilnd_api_rc2str(rc), (rc), msgdata, fmt, ##a); \
148 #define DO_RETCODE(x) case x: return #x;
149 static inline const char *
150 kgnilnd_api_rc2str(gni_return_t rrc)
154 DO_RETCODE(GNI_RC_SUCCESS)
155 DO_RETCODE(GNI_RC_NOT_DONE);
156 DO_RETCODE(GNI_RC_INVALID_PARAM);
157 DO_RETCODE(GNI_RC_ERROR_RESOURCE);
158 DO_RETCODE(GNI_RC_TIMEOUT);
159 DO_RETCODE(GNI_RC_PERMISSION_ERROR);
160 DO_RETCODE(GNI_RC_DESCRIPTOR_ERROR);
161 DO_RETCODE(GNI_RC_ALIGNMENT_ERROR);
162 DO_RETCODE(GNI_RC_INVALID_STATE);
163 DO_RETCODE(GNI_RC_NO_MATCH);
164 DO_RETCODE(GNI_RC_SIZE_ERROR);
165 DO_RETCODE(GNI_RC_TRANSACTION_ERROR);
166 DO_RETCODE(GNI_RC_ILLEGAL_OP);
167 DO_RETCODE(GNI_RC_ERROR_NOMEM);
173 /* log an error and LBUG for unhandled rc from gni api function
174 * the fmt should be something like:
175 * gni_api_call(arg1, arg2, arg3)
178 /* apick_fn and apick_fmt should be defined for each site */
182 #define GNILND_API_RC_LBUG(args...) \
184 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL); \
185 kgnilnd_api_rc_lbug(&msgdata, rrc, apick_fn"("apick_fmt")", ##args); \
188 #define GNILND_API_SWBUG(args...) \
190 CERROR("likely SOFTWARE BUG "apick_fn"("apick_fmt") rc %s\n", \
191 ##args, kgnilnd_api_rc2str(rrc)); \
194 #define GNILND_API_EINVAL(args...) \
196 CERROR("invalid parameter to "apick_fn"("apick_fmt") rc %s\n", \
197 ##args, kgnilnd_api_rc2str(rrc)); \
200 #define GNILND_API_RESOURCE(args...) \
202 CERROR("no resources for "apick_fn"("apick_fmt") rc %s\n", \
203 ##args, kgnilnd_api_rc2str(rrc)); \
206 #define GNILND_API_BUSY(args...) \
208 CERROR("resources busy for "apick_fn"("apick_fmt") rc %s\n", \
209 ##args, kgnilnd_api_rc2str(rrc)); \
212 #undef DEBUG_SMSG_CREDITS
213 #ifdef DEBUG_SMSG_CREDITS
214 #define CRAY_CONFIG_GHAL_GEMINI
215 #include <gni_priv.h>
216 #define GNIDBG_SMSG_CREDS(level, conn) \
218 gni_ep_smsg_mbox_t *smsg = conn->gnc_ephandle->smsg; \
219 CDEBUG(level, "SMSGDBG: conn %p mcred %d/%d bcred %d/%d " \
220 "s_seq %d/%d/%d r_seq %d/%d/%d retr %d\n", \
221 conn, smsg->mbox_credits, smsg->back_mbox_credits, \
222 smsg->buffer_credits, smsg->back_buffer_credits, \
223 smsg->s_seqno, smsg->s_seqno_back_mbox_credits, \
224 smsg->s_seqno_back_buffer_credits, smsg->r_seqno, \
225 smsg->r_seqno_back_mbox_credits, \
226 smsg->r_seqno_back_buffer_credits, smsg->retransmit_count); \
229 #define GNIDBG_SMSG_CREDS(level, conn) do {} while(0)
232 /* these are all wrappers around gni_XXX functions.
233 * This allows us to handle all the return codes and api checks without
234 * dirtying up the logic code */
236 /* TODO: RETURN wrapper that translates integer to GNI API RC string */
238 #define apick_fn "kgnilnd_cdm_create"
239 #define apick_fmt "%u, %u, %u, %u, 0x%p"
240 static inline gni_return_t kgnilnd_cdm_create(
245 OUT gni_cdm_handle_t *cdm_hndl
250 /* Error injection */
251 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_CDM_CREATE)) {
252 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
254 rrc = gni_cdm_create(inst_id, ptag, cookie, modes, cdm_hndl);
260 case GNI_RC_ERROR_RESOURCE:
261 case GNI_RC_INVALID_PARAM:
262 /* Try to bail gracefully */
264 inst_id, ptag, cookie, modes, cdm_hndl);
268 inst_id, ptag, cookie, modes, cdm_hndl);
270 /* LBUG never returns, but just for style and consistency */
279 #define apick_fn "kgnilnd_cdm_attach"
280 #define apick_fmt "0x%p, %u, 0x%p, 0x%p"
281 static inline gni_return_t kgnilnd_cdm_attach(
282 IN gni_cdm_handle_t cdm_hndl,
283 IN uint32_t device_id,
284 OUT uint32_t *local_addr,
285 OUT gni_nic_handle_t *nic_hndl
290 /* Error injection */
291 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_CDM_ATTACH)) {
292 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
294 rrc = gni_cdm_attach(cdm_hndl, device_id, local_addr, nic_hndl);
300 case GNI_RC_NO_MATCH:
301 case GNI_RC_INVALID_PARAM:
303 cdm_hndl, device_id, local_addr, nic_hndl);
305 case GNI_RC_ERROR_RESOURCE:
306 case GNI_RC_INVALID_STATE:
308 cdm_hndl, device_id, local_addr, nic_hndl);
312 cdm_hndl, device_id, local_addr, nic_hndl);
314 /* LBUG never returns, but just for style and consistency */
322 #define apick_fn "kgnilnd_cdm_destroy"
323 #define apick_fmt "0x%p"
324 static inline gni_return_t kgnilnd_cdm_destroy(
325 IN gni_cdm_handle_t cdm_hndl
330 /* Error injection */
331 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_CQ_DESTROY)) {
332 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
334 rrc = gni_cdm_destroy(
341 case GNI_RC_INVALID_PARAM:
349 /* LBUG never returns, but just for style and consistency */
357 #define apick_fn "kgnilnd_subscribe_errors"
358 #define apick_fmt "0x%p,%x,%u,0x%p,0x%p,0x%p"
359 static inline gni_return_t kgnilnd_subscribe_errors(
360 IN gni_nic_handle_t nic_handle,
361 IN gni_error_mask_t mask,
362 IN uint32_t EEQ_size,
363 IN void (*EQ_new_event)(gni_err_handle_t),
364 IN void (*app_crit_err)(gni_err_handle_t),
365 OUT gni_err_handle_t *err_handle
370 /* Error injection */
371 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_ERR_SUBSCRIBE)) {
372 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
374 rrc = gni_subscribe_errors(
375 nic_handle, mask, EEQ_size, EQ_new_event, app_crit_err,
382 case GNI_RC_INVALID_PARAM:
384 nic_handle, mask, EEQ_size, EQ_new_event, app_crit_err,
387 case GNI_RC_ERROR_RESOURCE:
389 nic_handle, mask, EEQ_size, EQ_new_event, app_crit_err,
394 nic_handle, mask, EEQ_size, EQ_new_event, app_crit_err,
396 /* LBUG never returns, but just for style and consistency */
404 #define apick_fn "kgnilnd_release_errors"
405 #define apick_fmt "0x%p"
406 static inline gni_return_t kgnilnd_release_errors(
407 IN gni_err_handle_t err_handle
412 rrc = gni_release_errors(
418 case GNI_RC_INVALID_PARAM:
419 case GNI_RC_NOT_DONE:
426 /* LBUG never returns, but just for style and consistency */
434 #define apick_fn "kgnilnd_set_quiesce_callback"
435 #define apick_fmt "0x%p,0x%p"
436 static inline gni_return_t kgnilnd_set_quiesce_callback(
437 IN gni_nic_handle_t nic_handle,
438 IN void (*qsce_func)(gni_nic_handle_t, uint64_t msecs)
443 /* Error injection */
444 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_REG_QUIESCE)) {
445 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
447 rrc = gni_set_quiesce_callback(
448 nic_handle, qsce_func);
454 case GNI_RC_INVALID_STATE:
455 case GNI_RC_INVALID_PARAM:
457 nic_handle, qsce_func);
461 nic_handle, qsce_func);
462 /* LBUG never returns, but just for style and consistency */
470 #define apick_fn "kgnilnd_get_quiesce_status"
471 #define apick_fmt "0x%p"
472 static inline gni_return_t kgnilnd_get_quiesce_status(
473 IN gni_nic_handle_t nic_handle
478 /* this has weird RC -
479 * 0 - quiesce not in progress
480 * 1 - quiesce is turned on
483 /* Error injection */
484 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_IN_QUIESCE)) {
487 rrc = gni_get_quiesce_status(
498 /* LBUG never returns, but just for style and consistency */
506 #define apick_fn "kgnilnd_cq_create"
507 #define apick_fmt "0x%p, %u, %u, 0x%p, "LPX64", 0x%p"
508 static inline gni_return_t kgnilnd_cq_create(
509 IN gni_nic_handle_t nic_hndl,
510 IN uint32_t entry_count,
511 IN uint32_t delay_index,
512 IN gni_cq_event_hndlr_f *event_handler,
513 IN uint64_t usr_event_data,
514 OUT gni_cq_handle_t *cq_hndl
519 /* Error injection */
520 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_CQ_CREATE)) {
521 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
524 nic_hndl, entry_count, delay_index, event_handler,
525 usr_event_data, cq_hndl);
531 case GNI_RC_INVALID_PARAM:
533 nic_hndl, entry_count, delay_index, event_handler,
534 usr_event_data, cq_hndl);
536 case GNI_RC_ERROR_RESOURCE:
538 nic_hndl, entry_count, delay_index, event_handler,
539 usr_event_data, cq_hndl);
543 nic_hndl, entry_count, delay_index, event_handler,
544 usr_event_data, cq_hndl);
546 /* LBUG never returns, but just for style and consistency */
554 #define apick_fn "kgnilnd_cq_destroy"
555 #define apick_fmt "0x%p"
556 static inline gni_return_t kgnilnd_cq_destroy(
557 IN gni_cq_handle_t cq_hndl
562 /* Error injection */
563 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_CQ_DESTROY)) {
564 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
567 rrc = gni_cq_destroy(
574 case GNI_RC_INVALID_PARAM:
578 case GNI_RC_ERROR_RESOURCE:
586 /* LBUG never returns, but just for style and consistency */
594 #define apick_fn "kgnilnd_cq_get_event"
595 #define apick_fmt "0x%p, 0x%p"
596 static inline gni_return_t kgnilnd_cq_get_event(
597 IN gni_cq_handle_t cq_hndl,
598 OUT gni_cq_entry_t *event_data
603 /* no error injection - CQs are touchy about the data.
604 * where appropriate, we'll do this on the CQs that should be able to
605 * handle the various errors */
606 rrc = gni_cq_get_event(
607 cq_hndl, event_data);
611 case GNI_RC_NOT_DONE:
612 case GNI_RC_TRANSACTION_ERROR:
614 case GNI_RC_ERROR_RESOURCE:
615 LASSERTF(GNI_CQ_OVERRUN(*event_data),
616 "kgni returned ERROR_RESOURCE but cq_hndl 0x%p is not "
617 "overrun\n", cq_hndl);
619 case GNI_RC_INVALID_PARAM:
621 cq_hndl, event_data);
625 cq_hndl, event_data);
627 /* LBUG never returns, but just for style and consistency */
635 #define apick_fn "kgnilnd_smsg_init"
636 #define apick_fmt "0x%p, 0x%p, 0x%p"
637 static inline gni_return_t kgnilnd_smsg_init(
638 IN gni_ep_handle_t ep_hndl,
639 IN gni_smsg_attr_t *local_smsg_attr,
640 IN gni_smsg_attr_t *remote_smsg_attr
645 /* Error injection */
646 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_SMSG_INIT)) {
647 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_ERROR_RESOURCE;
650 ep_hndl, local_smsg_attr, remote_smsg_attr);
654 /* both of these are OK, upper SW needs to handle */
656 case GNI_RC_NOT_DONE:
658 case GNI_RC_INVALID_PARAM:
659 case GNI_RC_INVALID_STATE:
661 ep_hndl, local_smsg_attr, remote_smsg_attr);
663 case GNI_RC_ERROR_RESOURCE:
665 ep_hndl, local_smsg_attr, remote_smsg_attr);
669 ep_hndl, local_smsg_attr, remote_smsg_attr);
671 /* LBUG never returns, but just for style and consistency */
679 #define apick_fn "kgnilnd_smsg_send"
680 #define apick_fmt "0x%p, 0x%p, %d, 0x%p, %u %u"
681 static inline gni_return_t kgnilnd_smsg_send(
682 IN gni_ep_handle_t ep_hndl,
684 IN uint32_t header_length,
686 IN uint32_t data_length,
692 /* Error injection */
693 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_SMSG_SEND)) {
694 if (cfs_fail_loc & CFS_FAIL_RAND) {
695 rrc = GNI_RC_NOT_DONE;
697 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_NOT_DONE;
701 ep_hndl, header, header_length, data, data_length, msg_id);
705 /* both of these are OK, upper SW needs to handle */
707 case GNI_RC_NOT_DONE:
709 case GNI_RC_INVALID_PARAM:
711 ep_hndl, header, header_length, data, data_length, msg_id);
713 case GNI_RC_ERROR_RESOURCE:
715 ep_hndl, header, header_length, data, data_length, msg_id);
719 ep_hndl, header, header_length, data, data_length, msg_id);
721 /* LBUG never returns, but just for style and consistency */
729 #define apick_fn "kgnilnd_smsg_getnext"
730 #define apick_fmt "0x%p,0x%p"
731 static inline gni_return_t kgnilnd_smsg_getnext(
732 IN gni_ep_handle_t ep_hndl,
738 /* Error injection */
739 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_SMSG_RELEASE)) {
740 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_NOT_DONE;
742 rrc = gni_smsg_getnext(
747 /* both of these are OK, upper SW needs to handle */
749 case GNI_RC_NOT_DONE:
750 case GNI_RC_INVALID_STATE:
752 case GNI_RC_INVALID_PARAM:
760 /* LBUG never returns, but just for style and consistency */
768 #define apick_fn "kgnilnd_smsg_release"
769 #define apick_fmt "0x%p"
770 static inline gni_return_t kgnilnd_smsg_release(
771 IN gni_ep_handle_t ep_hndl
776 /* Error injection */
777 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_SMSG_RELEASE)) {
778 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
780 rrc = gni_smsg_release(
785 /* both of these are OK, upper SW needs to handle */
787 case GNI_RC_NOT_DONE:
789 case GNI_RC_INVALID_PARAM:
797 /* LBUG never returns, but just for style and consistency */
805 #define apick_fn "kgnilnd_ep_create"
806 #define apick_fmt "0x%p, 0x%p, 0x%p"
807 static inline gni_return_t kgnilnd_ep_create(
808 IN gni_nic_handle_t nic_hndl,
809 IN gni_cq_handle_t src_cq_hndl,
810 OUT gni_ep_handle_t *ep_hndl
815 /* error injection */
816 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_EP_CREATE)) {
817 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_ERROR_NOMEM;
820 nic_hndl, src_cq_hndl, ep_hndl);
826 case GNI_RC_INVALID_PARAM:
828 nic_hndl, src_cq_hndl, ep_hndl);
830 case GNI_RC_ERROR_NOMEM:
832 nic_hndl, src_cq_hndl, ep_hndl);
836 nic_hndl, src_cq_hndl, ep_hndl);
838 /* lbug never returns, but just for style and consistency */
846 #define apick_fn "kgnilnd_ep_bind"
847 #define apick_fmt "0x%p, %x, %x"
848 static inline gni_return_t kgnilnd_ep_bind(
849 IN gni_ep_handle_t ep_hndl,
850 IN uint32_t remote_addr,
851 IN uint32_t remote_id
856 /* error injection */
857 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_EP_BIND)) {
858 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_NOT_DONE;
861 ep_hndl, remote_addr, remote_id);
865 /* both of these are ok, upper sw needs to handle */
867 case GNI_RC_NOT_DONE:
869 case GNI_RC_INVALID_PARAM:
871 ep_hndl, remote_addr, remote_id);
875 ep_hndl, remote_addr, remote_id);
877 /* lbug never returns, but just for style and consistency */
885 #define apick_fn "kgnilnd_ep_set_eventdata"
886 #define apick_fmt "0x%p, %x, %x"
887 static inline gni_return_t kgnilnd_ep_set_eventdata(
888 IN gni_ep_handle_t ep_hndl,
889 IN uint32_t local_event,
890 IN uint32_t remote_event
895 /* Error injection */
896 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_EP_SET_EVDATA)) {
897 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
899 rrc = gni_ep_set_eventdata(
900 ep_hndl, local_event, remote_event);
906 case GNI_RC_INVALID_PARAM:
908 ep_hndl, local_event, remote_event);
912 ep_hndl, local_event, remote_event);
914 /* LBUG never returns, but just for style and consistency */
922 #define apick_fn "kgnilnd_ep_unbind"
923 #define apick_fmt "0x%p"
924 static inline gni_return_t kgnilnd_ep_unbind(
925 IN gni_ep_handle_t ep_hndl
930 /* Error injection */
931 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_EP_UNBIND)) {
932 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_NOT_DONE;
939 /* both of these are OK, upper SW needs to handle */
940 case GNI_RC_NOT_DONE:
943 case GNI_RC_INVALID_PARAM:
951 /* LBUG never returns, but just for style and consistency */
959 #define apick_fn "kgnilnd_ep_destroy"
960 #define apick_fmt "0x%p"
961 static inline gni_return_t kgnilnd_ep_destroy(
962 IN gni_ep_handle_t ep_hndl
967 /* Error injection */
968 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_EP_DESTROY)) {
969 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_NOT_DONE;
971 rrc = gni_ep_destroy(
978 case GNI_RC_INVALID_PARAM:
986 /* LBUG never returns, but just for style and consistency */
994 #define apick_fn "kgnilnd_ep_postdata_w_id"
995 #define apick_fmt "0x%p, 0x%p, %d, 0x%p, %d, "LPU64""
996 static inline gni_return_t kgnilnd_ep_postdata_w_id(
997 IN gni_ep_handle_t ep_hndl,
999 IN uint16_t data_len,
1001 IN uint16_t buf_size,
1002 IN uint64_t datagram_id
1007 /* Error injection */
1008 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_EP_POST)) {
1009 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_SIZE_ERROR;
1011 rrc = gni_ep_postdata_w_id(
1012 ep_hndl, in_data, data_len, out_buf, buf_size,
1017 case GNI_RC_SUCCESS:
1018 case GNI_RC_ERROR_NOMEM:
1019 case GNI_RC_ERROR_RESOURCE:
1021 case GNI_RC_INVALID_PARAM:
1022 case GNI_RC_SIZE_ERROR:
1024 ep_hndl, in_data, data_len, out_buf, buf_size,
1029 ep_hndl, in_data, data_len, out_buf, buf_size,
1032 /* LBUG never returns, but just for style and consistency */
1040 #define apick_fn "kgnilnd_ep_postdata_test_by_id"
1041 #define apick_fmt "0x%p, "LPU64", 0x%p, 0x%p, 0x%p"
1042 static inline gni_return_t kgnilnd_ep_postdata_test_by_id(
1043 IN gni_ep_handle_t ep_hndl,
1044 IN uint64_t datagram_id,
1045 OUT gni_post_state_t *post_state,
1046 OUT uint32_t *remote_addr,
1047 OUT uint32_t *remote_id
1052 /* Error injection */
1053 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_EP_TEST)) {
1054 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_ERROR_NOMEM;
1056 rrc = gni_ep_postdata_test_by_id(
1057 ep_hndl, datagram_id, post_state, remote_addr,
1060 /* we want to lie, but we need to do the actual work first
1061 * so we don't keep getting the event saying a dgram is ready */
1062 if (rrc == GNI_RC_SUCCESS && CFS_FAIL_CHECK(CFS_FAIL_GNI_DG_TERMINATE)) {
1063 /* don't use fail_val, allows us to do FAIL_SOME */
1064 *post_state = GNI_POST_TERMINATED;
1069 case GNI_RC_SUCCESS:
1070 case GNI_RC_NO_MATCH:
1072 case GNI_RC_SIZE_ERROR:
1073 case GNI_RC_INVALID_PARAM:
1075 ep_hndl, datagram_id, post_state, remote_addr,
1078 case GNI_RC_ERROR_NOMEM:
1079 GNILND_API_RESOURCE(
1080 ep_hndl, datagram_id, post_state, remote_addr,
1085 ep_hndl, datagram_id, post_state, remote_addr,
1088 /* LBUG never returns, but just for style and consistency */
1096 #define apick_fn "kgnilnd_ep_postdata_cancel_by_id"
1097 #define apick_fmt "0x%p, "LPU64""
1098 static inline gni_return_t kgnilnd_ep_postdata_cancel_by_id(
1099 IN gni_ep_handle_t ep_hndl,
1100 IN uint64_t datagram_id
1105 /* no error injection as the only thing we'd do is LBUG */
1107 rrc = gni_ep_postdata_cancel_by_id(
1108 ep_hndl, datagram_id);
1111 case GNI_RC_SUCCESS:
1112 case GNI_RC_NO_MATCH:
1114 case GNI_RC_INVALID_PARAM:
1116 ep_hndl, datagram_id);
1120 ep_hndl, datagram_id);
1122 /* LBUG never returns, but just for style and consistency */
1130 #define apick_fn "kgnilnd_postdata_probe_by_id"
1131 #define apick_fmt "0x%p, 0x%p"
1132 static inline gni_return_t kgnilnd_postdata_probe_by_id(
1133 IN gni_nic_handle_t nic_hndl,
1134 OUT uint64_t *datagram_id
1139 /* Error injection */
1140 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_PROBE)) {
1141 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_NO_MATCH;
1143 rrc = gni_postdata_probe_by_id(
1144 nic_hndl, datagram_id);
1148 case GNI_RC_SUCCESS:
1149 case GNI_RC_NO_MATCH:
1151 case GNI_RC_INVALID_PARAM:
1153 nic_hndl, datagram_id);
1157 nic_hndl, datagram_id);
1159 /* LBUG never returns, but just for style and consistency */
1167 #define apick_fn "kgnilnd_postdata_probe_wait_by_id"
1168 #define apick_fmt "0x%p, %d, 0x%p"
1169 static inline gni_return_t kgnilnd_postdata_probe_wait_by_id(
1170 IN gni_nic_handle_t nic_hndl,
1171 IN uint32_t timeout,
1172 OUT uint64_t *datagram_id
1177 /* Error injection */
1178 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_PROBE_WAIT)) {
1179 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_TIMEOUT;
1181 rrc = gni_postdata_probe_wait_by_id(
1182 nic_hndl, timeout, datagram_id);
1186 case GNI_RC_SUCCESS:
1187 case GNI_RC_TIMEOUT:
1189 case GNI_RC_INVALID_PARAM:
1191 nic_hndl, timeout, datagram_id);
1195 nic_hndl, timeout, datagram_id);
1197 /* LBUG never returns, but just for style and consistency */
1205 #define apick_fn "kgnilnd_post_rdma"
1206 #define apick_fmt "0x%p, 0x%p"
1207 static inline gni_return_t kgnilnd_post_rdma(
1208 IN gni_ep_handle_t ep_hndl,
1209 IN gni_post_descriptor_t *post_descr
1214 /* Error injection */
1215 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_POST_RDMA)) {
1216 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
1218 rrc = gni_post_rdma(
1219 ep_hndl, post_descr);
1223 case GNI_RC_SUCCESS:
1225 case GNI_RC_ALIGNMENT_ERROR:
1226 case GNI_RC_INVALID_PARAM:
1228 ep_hndl, post_descr);
1230 case GNI_RC_ERROR_RESOURCE:
1231 CDEBUG(D_NET, "no resources for kgnilnd_post_rdma (0x%p, 0x%p)"
1232 " rc %s\n", ep_hndl, post_descr,
1233 kgnilnd_api_rc2str(rrc));
1237 ep_hndl, post_descr);
1239 /* LBUG never returns, but just for style and consistency */
1247 #define apick_fn "kgnilnd_get_completed"
1248 #define apick_fmt "0x%p,"LPX64",0x%p"
1249 static inline gni_return_t kgnilnd_get_completed(
1250 IN gni_cq_handle_t cq_hndl,
1251 IN gni_cq_entry_t event_data,
1252 OUT gni_post_descriptor_t **post_descr
1258 rrc = gni_get_completed(cq_hndl, event_data, post_descr);
1261 case GNI_RC_TRANSACTION_ERROR:
1262 case GNI_RC_SUCCESS:
1264 case GNI_RC_DESCRIPTOR_ERROR:
1265 case GNI_RC_INVALID_PARAM:
1266 GNILND_API_SWBUG(cq_hndl, event_data, post_descr);
1269 GNILND_API_RC_LBUG(cq_hndl, event_data, post_descr);
1270 /* LBUG never returns, but just for style and consistency */
1274 /* Error injection - we need a valid desc, so let kgni give us one
1276 if (rrc == GNI_RC_SUCCESS &&
1277 (CFS_FAIL_CHECK(CFS_FAIL_GNI_GET_COMPLETED))) {
1278 /* We only trigger TRANSACTION_ERROR for now */
1279 gni_post_descriptor_t *desc;
1280 rrc = GNI_RC_TRANSACTION_ERROR;
1283 /* recoverable decision made from cfs_fail_val in
1284 * kgnilnd_cq_error_str and
1285 * kgnilnd_cq_error_recoverable */
1292 #define apick_fn "kgnilnd_cq_error_str"
1293 #define apick_fmt LPX64",0x%p,%d"
1294 static inline gni_return_t kgnilnd_cq_error_str(
1295 IN gni_cq_entry_t entry,
1302 /* Error injection - set string if we injected a
1303 * TRANSACTION_ERROR earlier */
1304 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_GET_COMPLETED)) {
1305 /* if we just set persistent error, we can't ever
1306 * break in via ssh to clear, so use a count > 10 to indicate fatal */
1307 sprintf(buffer, "INJECT:%s", cfs_fail_val > 10 ?
1308 "FATAL" : "RECOVERABLE");
1309 rrc = GNI_RC_SUCCESS;
1311 rrc = gni_cq_error_str(
1312 entry, buffer, len);
1316 case GNI_RC_SUCCESS:
1318 case GNI_RC_SIZE_ERROR:
1319 case GNI_RC_INVALID_PARAM:
1321 entry, buffer, len);
1322 /* give them something to use */
1323 snprintf(buffer, len, "UNDEF:UNDEF");
1327 entry, buffer, len);
1329 /* LBUG never returns, but just for style and consistency */
1337 #define apick_fn "kgnilnd_cq_error_recoverable"
1338 #define apick_fmt LPX64",0x%p"
1339 static inline gni_return_t kgnilnd_cq_error_recoverable(
1340 IN gni_cq_entry_t entry,
1341 IN uint32_t *recoverable
1346 /* Error injection - set string if we injected a
1347 * TRANSACTION_ERROR earlier */
1348 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_GET_COMPLETED)) {
1349 *recoverable = cfs_fail_val > 10 ? 0 : 1;
1350 rrc = GNI_RC_SUCCESS;
1352 rrc = gni_cq_error_recoverable(
1353 entry, recoverable);
1357 case GNI_RC_SUCCESS:
1359 case GNI_RC_INVALID_STATE:
1360 case GNI_RC_INVALID_PARAM:
1362 entry, recoverable);
1367 entry, recoverable);
1369 /* LBUG never returns, but just for style and consistency */
1377 #define apick_fn "kgnilnd_mem_register_segments"
1378 #define apick_fmt "0x%p,0x%p,%u,0x%p,%x,0x%p"
1379 static inline gni_return_t
1380 kgnilnd_mem_register_segments(
1381 IN gni_nic_handle_t nic_hndl,
1382 IN gni_mem_segment_t *mem_segments,
1383 IN uint32_t segments_cnt,
1384 IN gni_cq_handle_t dst_cq_hndl,
1386 OUT gni_mem_handle_t *mem_hndl
1391 /* Error injection */
1392 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_PHYS_MAP)) {
1393 rrc = GNI_RC_ERROR_RESOURCE;
1395 rrc = gni_mem_register_segments(
1396 nic_hndl, mem_segments, segments_cnt,
1397 dst_cq_hndl, flags, mem_hndl);
1401 case GNI_RC_SUCCESS:
1402 case GNI_RC_ERROR_RESOURCE:
1404 case GNI_RC_INVALID_PARAM:
1406 nic_hndl, mem_segments, segments_cnt,
1407 dst_cq_hndl, flags, mem_hndl);
1411 nic_hndl, mem_segments, segments_cnt,
1412 dst_cq_hndl, flags, mem_hndl);
1414 /* LBUG never returns, but just for style and consistency */
1422 #define apick_fn "kgnilnd_mem_register"
1423 #define apick_fmt "0x%p,"LPX64","LPX64"0x%p,%u,0x%p"
1424 static inline gni_return_t kgnilnd_mem_register(
1425 IN gni_nic_handle_t nic_hndl,
1426 IN uint64_t address,
1428 IN gni_cq_handle_t dst_cq_hndl,
1430 OUT gni_mem_handle_t *mem_hndl
1435 /* Error injection */
1436 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_VIRT_MAP)) {
1437 rrc = GNI_RC_ERROR_RESOURCE;
1438 } else if (CFS_FAIL_CHECK(CFS_FAIL_GNI_VIRT_SMALL_MAP) &&
1439 length <= *kgnilnd_tunables.kgn_max_immediate) {
1440 rrc = GNI_RC_INVALID_PARAM;
1442 rrc = gni_mem_register(
1443 nic_hndl, address, length,
1444 dst_cq_hndl, flags, mem_hndl);
1448 case GNI_RC_SUCCESS:
1449 case GNI_RC_ERROR_RESOURCE:
1451 case GNI_RC_INVALID_PARAM:
1453 nic_hndl, address, length,
1454 dst_cq_hndl, flags, mem_hndl);
1458 nic_hndl, address, length,
1459 dst_cq_hndl, flags, mem_hndl);
1461 /* LBUG never returns, but just for style and consistency */
1469 #define apick_fn "kgnilnd_mem_deregister"
1470 #define apick_fmt "0x%p,0x%p,%d"
1471 static inline gni_return_t kgnilnd_mem_deregister(
1472 IN gni_nic_handle_t nic_hndl,
1473 IN gni_mem_handle_t *mem_hndl,
1479 /* Error injection */
1480 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_VIRT_UNMAP)) {
1481 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_INVALID_PARAM;
1483 rrc = gni_mem_deregister(
1484 nic_hndl, mem_hndl, hold_timeout);
1488 case GNI_RC_SUCCESS:
1490 case GNI_RC_INVALID_PARAM:
1492 nic_hndl, mem_hndl, hold_timeout);
1496 nic_hndl, mem_hndl, hold_timeout);
1498 /* LBUG never returns, but just for style and consistency */
1506 #define apick_fn "kgnilnd_mem_mdd_release"
1507 #define apick_fmt "0x%p,0x%p"
1508 static inline gni_return_t kgnilnd_mem_mdd_release(
1509 IN gni_nic_handle_t nic_hndl,
1510 IN gni_mem_handle_t *mem_hndl
1515 /* Error injection */
1516 if (CFS_FAIL_CHECK(CFS_FAIL_GNI_MDD_RELEASE)) {
1517 rrc = cfs_fail_val ? cfs_fail_val : GNI_RC_NO_MATCH;
1519 rrc = gni_mem_mdd_release(
1520 nic_hndl, mem_hndl);
1524 case GNI_RC_SUCCESS:
1525 case GNI_RC_NO_MATCH:
1529 nic_hndl, mem_hndl);
1531 /* LBUG never returns, but just for style and consistency */
1539 #endif /* _GNILND_API_WRAP_H */