Blame include/opa_user.h

Packit 961e70
/*
Packit 961e70
Packit 961e70
  This file is provided under a dual BSD/GPLv2 license.  When using or
Packit 961e70
  redistributing this file, you may do so under either license.
Packit 961e70
Packit 961e70
  GPL LICENSE SUMMARY
Packit 961e70
Packit 961e70
  Copyright(c) 2015 Intel Corporation.
Packit 961e70
Packit 961e70
  This program is free software; you can redistribute it and/or modify
Packit 961e70
  it under the terms of version 2 of the GNU General Public License as
Packit 961e70
  published by the Free Software Foundation.
Packit 961e70
Packit 961e70
  This program is distributed in the hope that it will be useful, but
Packit 961e70
  WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 961e70
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 961e70
  General Public License for more details.
Packit 961e70
Packit 961e70
  Contact Information:
Packit 961e70
  Intel Corporation, www.intel.com
Packit 961e70
Packit 961e70
  BSD LICENSE
Packit 961e70
Packit 961e70
  Copyright(c) 2015 Intel Corporation.
Packit 961e70
Packit 961e70
  Redistribution and use in source and binary forms, with or without
Packit 961e70
  modification, are permitted provided that the following conditions
Packit 961e70
  are met:
Packit 961e70
Packit 961e70
    * Redistributions of source code must retain the above copyright
Packit 961e70
      notice, this list of conditions and the following disclaimer.
Packit 961e70
    * Redistributions in binary form must reproduce the above copyright
Packit 961e70
      notice, this list of conditions and the following disclaimer in
Packit 961e70
      the documentation and/or other materials provided with the
Packit 961e70
      distribution.
Packit 961e70
    * Neither the name of Intel Corporation nor the names of its
Packit 961e70
      contributors may be used to endorse or promote products derived
Packit 961e70
      from this software without specific prior written permission.
Packit 961e70
Packit 961e70
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 961e70
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 961e70
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 961e70
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit 961e70
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit 961e70
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 961e70
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 961e70
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 961e70
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 961e70
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 961e70
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 961e70
Packit 961e70
*/
Packit 961e70
Packit 961e70
#ifndef OPA_USER_H
Packit 961e70
#define OPA_USER_H
Packit 961e70
Packit 961e70
/* This file contains all of the data structures and routines that are
Packit 961e70
   publicly visible and usable (to low level infrastructure code; it is
Packit 961e70
   not expected that any application, or even normal application-level library,
Packit 961e70
   will ever need to use any of this).
Packit 961e70
Packit 961e70
   Additional entry points and data structures that are used by these routines
Packit 961e70
   may be referenced in this file, but they should not be generally available;
Packit 961e70
   they are visible here only to allow use in inlined functions.  Any variable,
Packit 961e70
   data structure, or function that starts with a leading "_" is in this
Packit 961e70
   category.
Packit 961e70
*/
Packit 961e70
Packit 961e70
/* Include header files we need that are unlikely to otherwise be needed by */
Packit 961e70
/* programs. */
Packit 961e70
#include <stddef.h>
Packit 961e70
#include <stdarg.h>
Packit 961e70
#include <unistd.h>
Packit 961e70
#include <errno.h>
Packit 961e70
#include <string.h>
Packit 961e70
#include <sys/stat.h>
Packit 961e70
#include <sys/mman.h>
Packit 961e70
#include <sys/user.h>
Packit 961e70
#include <syslog.h>
Packit 961e70
#include "opa_intf.h"
Packit 961e70
#include "opa_byteorder.h"
Packit 961e70
#include "opa_udebug.h"
Packit 961e70
#include "opa_service.h"
Packit 961e70
Packit 961e70
#define HFI_TF_NFLOWS                       32
Packit 961e70
Packit 961e70
/* IB - LRH header consts */
Packit 961e70
#define HFI_LRH_BTH 0x0002	/* 1. word of IB LRH - next header: BTH */
Packit 961e70
#define HFI_LRH_SC_SHIFT 12
Packit 961e70
#define HFI_LRH_SC_MASK 0xf
Packit 961e70
#define HFI_LRH_SL_SHIFT 4
Packit 961e70
#define HFI_LRH_SL_MASK 0xf
Packit 961e70
#define HFI_LRH_PKTLEN_MASK 0xfff
Packit 961e70
Packit 961e70
/* IB - BTH header consts */
Packit 961e70
#define HFI_BTH_OPCODE_SHIFT 24
Packit 961e70
#define HFI_BTH_OPCODE_MASK 0xff
Packit 961e70
#define HFI_BTH_BECN_SHIFT 30
Packit 961e70
#define HFI_BTH_FECN_SHIFT 31
Packit 961e70
#define HFI_BTH_QP_SHIFT 16
Packit 961e70
#define HFI_BTH_QP_MASK 0xff
Packit 961e70
#define HFI_BTH_FLOWID_SHIFT 11
Packit 961e70
#define HFI_BTH_FLOWID_MASK 0x1f
Packit 961e70
#define HFI_BTH_SUBCTXT_SHIFT 8
Packit 961e70
#define HFI_BTH_SUBCTXT_MASK 0x7
Packit 961e70
Packit 961e70
#define HFI_BTH_SEQ_SHIFT 0
Packit 961e70
#define HFI_BTH_SEQ_MASK 0x7ff
Packit 961e70
#define HFI_BTH_GEN_SHIFT 11
Packit 961e70
#define HFI_BTH_GEN_MASK 0xfffff
Packit 961e70
#define HFI_BTH_ACK_SHIFT 31
Packit 961e70
Packit 961e70
/* KDETH header consts */
Packit 961e70
#define HFI_KHDR_OFFSET_MASK 0x7fff
Packit 961e70
#define HFI_KHDR_OM_SHIFT 15
Packit 961e70
#define HFI_KHDR_TID_SHIFT 16
Packit 961e70
#define HFI_KHDR_TID_MASK 0x3ff
Packit 961e70
#define HFI_KHDR_TIDCTRL_SHIFT 26
Packit 961e70
#define HFI_KHDR_TIDCTRL_MASK 0x3
Packit 961e70
#define HFI_KHDR_INTR_SHIFT 28
Packit 961e70
#define HFI_KHDR_SH_SHIFT 29
Packit 961e70
#define HFI_KHDR_KVER_SHIFT 30
Packit 961e70
#define HFI_KHDR_KVER_MASK 0x3
Packit 961e70
Packit 961e70
#define HFI_KHDR_MSGSEQ_MASK 0xffff
Packit 961e70
#define HFI_KHDR_TINYLEN_MASK 0xf
Packit 961e70
#define HFI_KHDR_TINYLEN_SHIFT 16
Packit 961e70
Packit 961e70
#define GET_HFI_KHDR_TIDCTRL(val) \
Packit 961e70
	(((val) >> HFI_KHDR_TIDCTRL_SHIFT) & \
Packit 961e70
	HFI_KHDR_TIDCTRL_MASK)
Packit 961e70
Packit 961e70
#ifdef PSM_CUDA
Packit 961e70
extern int is_driver_gpudirect_enabled;
Packit 961e70
Packit Service 7ed5cc
#define PSMI_IS_DRIVER_GPUDIRECT_ENABLED  likely(is_driver_gpudirect_enabled)
Packit Service 7ed5cc
#define PSMI_IS_DRIVER_GPUDIRECT_DISABLED unlikely(!is_driver_gpudirect_enabled)
Packit 961e70
#endif
Packit 961e70
Packit 961e70
/* hfi kdeth header format */
Packit 961e70
struct hfi_kdeth {
Packit 961e70
	__u32 kdeth0;
Packit 961e70
Packit 961e70
	union {
Packit 961e70
		struct {
Packit 961e70
			__u16 job_key;
Packit 961e70
			__u16 hcrc;
Packit 961e70
		};
Packit 961e70
		__u32 kdeth1;
Packit 961e70
	};
Packit 961e70
};
Packit 961e70
Packit 961e70
/* misc. */
Packit 961e70
#define HFI_CRC_SIZE_IN_BYTES 4
Packit 961e70
Packit 961e70
#define HFI_DEFAULT_SERVICE_ID 0x1000117500000000ULL
Packit 961e70
#define HFI_DEFAULT_P_KEY 0x8001 /* fabric default pkey for app traffic */
Packit 961e70
Packit 961e70
#if 0
Packit 961e70
#define HFI_PERMISSIVE_LID 0xFFFF
Packit 961e70
#define HFI_AETH_CREDIT_SHIFT 24
Packit 961e70
#define HFI_AETH_CREDIT_MASK 0x1F
Packit 961e70
#define HFI_AETH_CREDIT_INVAL 0x1F
Packit 961e70
#define HFI_PSN_MASK 0xFFFFFF
Packit 961e70
#define HFI_MSN_MASK 0xFFFFFF
Packit 961e70
#define HFI_QPN_MASK 0xFFFFFF
Packit 961e70
#define HFI_MULTICAST_LID_BASE 0xC000
Packit 961e70
#define HFI_MULTICAST_QPN 0xFFFFFF
Packit 961e70
#endif
Packit 961e70
Packit 961e70
/* Receive Header Queue: receive type (from hfi) */
Packit 961e70
#define RCVHQ_RCV_TYPE_EXPECTED  0
Packit 961e70
#define RCVHQ_RCV_TYPE_EAGER     1
Packit 961e70
#define RCVHQ_RCV_TYPE_NON_KD    2
Packit 961e70
#define RCVHQ_RCV_TYPE_ERROR     3
Packit 961e70
Packit 961e70
/* OPA PSM assumes that the message header is always 56 bytes. */
Packit 961e70
#define HFI_MESSAGE_HDR_SIZE	56
Packit 961e70
Packit 961e70
/* interval timing routines */
Packit 961e70
/* Convert a count of cycles to elapsed nanoseconds */
Packit 961e70
/* this is only accurate for reasonably large numbers of cycles (at least tens)
Packit 961e70
*/
Packit 961e70
static __inline__ uint64_t cycles_to_nanosecs(uint64_t)
Packit 961e70
					  __attribute__ ((always_inline));
Packit 961e70
/* convert elapsed nanoseconds to elapsed cycles */
Packit 961e70
/* this is only accurate for reasonably large numbers of nsecs (at least tens)
Packit 961e70
*/
Packit 961e70
static __inline__ uint64_t nanosecs_to_cycles(uint64_t)
Packit 961e70
					  __attribute__ ((always_inline));
Packit 961e70
Packit 961e70
/* Statistics maintained by the driver */
Packit 961e70
const char *hfi_get_next_name(char **names);
Packit 961e70
int hfi_get_stats_names_count(void);
Packit 961e70
/* Counters maintained in the chip, globally, and per-prot */
Packit 961e70
int hfi_get_ctrs_unit_names_count(int unitno);
Packit 961e70
int hfi_get_ctrs_port_names_count(int unitno);
Packit 961e70
Packit 961e70
uint64_t hfi_get_single_unitctr(int unit, const char *attr, uint64_t *s);
Packit 961e70
int hfi_get_single_portctr(int unit, int port, const char *attr, uint64_t *c);
Packit 961e70
void hfi_release_names(char *namep);
Packit 961e70
Packit 961e70
/* Syslog wrapper
Packit 961e70
Packit 961e70
   level is one of LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING,
Packit 961e70
   LOG_NOTICE, LOG_INFO, LOG_DEBUG.
Packit 961e70
Packit 961e70
   prefix should be a short string to describe which part of the software stack
Packit 961e70
   is using syslog, i.e. "PSM", "mpi", "mpirun".
Packit 961e70
*/
Packit 961e70
void hfi_syslog(const char *prefix, int to_console, int level,
Packit 961e70
		const char *format, ...)
Packit 961e70
		__attribute__((format(printf, 4, 5)));
Packit 961e70
Packit 961e70
void hfi_vsyslog(const char *prefix, int to_console, int level,
Packit 961e70
		 const char *format, va_list ap);
Packit 961e70
Packit 961e70
/*
Packit 961e70
 * Copy routine that may copy a byte multiple times but optimized for througput
Packit 961e70
 * This is not safe to use for PIO routines where we want a guarantee that a
Packit 961e70
 * byte is only copied/moved across the bus once.
Packit 961e70
 */
Packit 961e70
void hfi_dwordcpy(volatile uint32_t *dest, const uint32_t *src,
Packit 961e70
		  uint32_t ndwords);
Packit 961e70
Packit 961e70
extern uint32_t __hfi_pico_per_cycle;	/* only for use in these functions */
Packit 961e70
Packit 961e70
/* this is only accurate for reasonably large numbers of cycles (at least tens) */
Packit 961e70
static __inline__ uint64_t cycles_to_nanosecs(uint64_t cycs)
Packit 961e70
{
Packit 961e70
	return (__hfi_pico_per_cycle * cycs) / 1000ULL;
Packit 961e70
}
Packit 961e70
Packit 961e70
/* this is only accurate for reasonably large numbers of nsecs (at least tens) */
Packit 961e70
static __inline__ uint64_t nanosecs_to_cycles(uint64_t ns)
Packit 961e70
{
Packit 961e70
	return (ns * 1000ULL) / __hfi_pico_per_cycle;
Packit 961e70
}
Packit 961e70
Packit 961e70
#endif /* OPA_USER_H */