Blame psm_hal_gen1/opa_service_gen1.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_SERVICE_GEN1_H
Packit 961e70
#define OPA_SERVICE_GEN1_H
Packit 961e70
Packit 961e70
/* This file contains all the lowest level routines calling into sysfs */
Packit 961e70
/* and qib driver. All other calls are based on these routines. */
Packit 961e70
Packit 961e70
#include <libgen.h>
Packit 961e70
Packit 961e70
#include "opa_intf.h"
Packit 961e70
#include "opa_common_gen1.h"
Packit 961e70
#include "opa_udebug.h"
Packit 961e70
#include "opa_byteorder.h"
Packit 961e70
Packit 961e70
/* upper and lower bounds for HFI port numbers */
Packit 961e70
#define HFI_MIN_PORT 1
Packit 961e70
#define HFI_MAX_PORT 1
Packit 961e70
#ifndef HFI_NUM_PORTS_GEN1
Packit 961e70
#define HFI_NUM_PORTS_GEN1 (HFI_MAX_PORT - HFI_MIN_PORT + 1)
Packit 961e70
#endif
Packit 961e70
/* any unit id to match. */
Packit 961e70
#define HFI_UNIT_ID_ANY ((long)-1)
Packit 961e70
/* any port num to match. */
Packit 961e70
#define HFI_PORT_NUM_ANY ((long)0)
Packit 961e70
Packit 961e70
/* base name of path (without unit #) for qib driver */
Packit 961e70
#ifndef HFI_DEVICE_PATH_GEN1
Packit 961e70
#define HFI_DEVICE_PATH_GEN1 "/dev/hfi1"
Packit 961e70
#endif
Packit 961e70
Packit 961e70
#ifdef PSM_CUDA
Packit 961e70
#define GDR_DEVICE_PATH "/dev/hfi1_gdr"
Packit 961e70
#endif
Packit 961e70
Packit 961e70
/* The major and minor versions of driver that support non-DW multiple SDMA */
Packit 961e70
#define HFI1_USER_SWMAJOR_NON_DW_MUL_MSG_SIZE_ALLOWED 6
Packit 961e70
#define HFI1_USER_SWMINOR_NON_DW_MUL_MSG_SIZE_ALLOWED 2
Packit 961e70
Packit 961e70
/* Commands used to communicate with driver. */
Packit 961e70
enum PSMI_HFI_CMD {
Packit 961e70
    PSMI_HFI_CMD_ASSIGN_CTXT = 0,   /* allocate HFI and context */
Packit 961e70
    PSMI_HFI_CMD_CTXT_INFO,         /* find out what resources we got */
Packit 961e70
    PSMI_HFI_CMD_USER_INFO,         /* set up userspace */
Packit 961e70
    PSMI_HFI_CMD_TID_UPDATE,        /* update expected TID entries */
Packit 961e70
    PSMI_HFI_CMD_TID_FREE,          /* free expected TID entries */
Packit 961e70
    PSMI_HFI_CMD_CREDIT_UPD,        /* force an update of PIO credit */
Packit 961e70
    PSMI_HFI_CMD_RECV_CTRL,         /* control receipt of packets */
Packit 961e70
    PSMI_HFI_CMD_POLL_TYPE,         /* set the kind of polling we want */
Packit 961e70
    PSMI_HFI_CMD_ACK_EVENT,         /* ack & clear user status bits */
Packit 961e70
    PSMI_HFI_CMD_SET_PKEY,          /* set context's pkey */
Packit 961e70
    PSMI_HFI_CMD_CTXT_RESET,        /* reset context's HW send context */
Packit 961e70
    PSMI_HFI_CMD_TID_INVAL_READ,    /* read TID cache invalidations */
Packit 961e70
    PSMI_HFI_CMD_GET_VERS,          /* get the version of the user cdev */
Packit 961e70
Packit 961e70
#ifdef PSM_CUDA
Packit 961e70
    PSMI_HFI_CMD_TID_UPDATE_V2 = 28,
Packit 961e70
#endif
Packit 961e70
    PSMI_HFI_CMD_LAST,
Packit 961e70
};
Packit 961e70
Packit 961e70
/* Legacy commands used to communicate with driver using 'write' */
Packit 961e70
enum LEGACY_HFI1_CMD {
Packit 961e70
    LEGACY_HFI1_CMD_ASSIGN_CTXT     = 1,     /* allocate HFI and context */
Packit 961e70
    LEGACY_HFI1_CMD_CTXT_INFO       = 2,     /* find out what resources we got */
Packit 961e70
    LEGACY_HFI1_CMD_USER_INFO       = 3,     /* set up userspace */
Packit 961e70
    LEGACY_HFI1_CMD_TID_UPDATE      = 4,     /* update expected TID entries */
Packit 961e70
    LEGACY_HFI1_CMD_TID_FREE        = 5,     /* free expected TID entries */
Packit 961e70
    LEGACY_HFI1_CMD_CREDIT_UPD      = 6,     /* force an update of PIO credit */
Packit 961e70
Packit 961e70
    LEGACY_HFI1_CMD_RECV_CTRL       = 8,     /* control receipt of packets */
Packit 961e70
    LEGACY_HFI1_CMD_POLL_TYPE       = 9,     /* set the kind of polling we want */
Packit 961e70
    LEGACY_HFI1_CMD_ACK_EVENT       = 10,    /* ack & clear user status bits */
Packit 961e70
    LEGACY_HFI1_CMD_SET_PKEY        = 11,    /* set context's pkey */
Packit 961e70
    LEGACY_HFI1_CMD_CTXT_RESET      = 12,    /* reset context's HW send context */
Packit 961e70
    LEGACY_HFI1_CMD_TID_INVAL_READ  = 13,    /* read TID cache invalidations */
Packit 961e70
    LEGACY_HFI1_CMD_GET_VERS        = 14    /* get the version of the user cdev */
Packit 961e70
};
Packit 961e70
Packit 961e70
/* Given a unit number and port number, returns 1 if the unit and port are active.
Packit 961e70
   returns 0 if the unit and port are not active. returns -1 when an error occurred. */
Packit 961e70
int hfi_get_port_active(int, int);
Packit 961e70
Packit 961e70
/* Given the unit number and port, return an error, or the corresponding LID */
Packit 961e70
/* Returns an int, so -1 indicates a general error.  -2 indicates that the unit/port
Packit 961e70
   are not active.  0 indicates that the unit is valid, but no LID has been assigned. */
Packit 961e70
int hfi_get_port_lid(int, int);
Packit 961e70
Packit 961e70
/* Given the unit number and port, return an error, or the corresponding GID */
Packit 961e70
/* Returns an int, so -1 indicates an error. */
Packit 961e70
int hfi_get_port_gid(int, int, uint64_t *hi, uint64_t *lo);
Packit 961e70
Packit 961e70
/* Given the unit number, return an error, or the corresponding LMC value
Packit 961e70
   for the port */
Packit 961e70
/* Returns an int, so -1 indicates an error.  0 */
Packit 961e70
int hfi_get_port_lmc(int unit, int port);
Packit 961e70
Packit 961e70
/* Given the unit number, return an error, or the corresponding link rate
Packit 961e70
   for the port */
Packit 961e70
/* Returns an int, so -1 indicates an error. */
Packit 961e70
int hfi_get_port_rate(int unit, int port);
Packit 961e70
Packit 961e70
/* Given a unit, port and SL, return an error, or the corresponding SC for the
Packit 961e70
   SL as programmed by the SM */
Packit 961e70
/* Returns an int, so -1 indicates an error. */
Packit 961e70
int hfi_get_port_sl2sc(int unit, int port, int sl);
Packit 961e70
Packit 961e70
/* Given a unit, port and SC, return an error, or the corresponding VL for the
Packit 961e70
   SC as programmed by the SM */
Packit 961e70
/* Returns an int, so -1 indicates an error. */
Packit 961e70
int hfi_get_port_sc2vl(int unit, int port, int sc);
Packit 961e70
Packit 961e70
/* Given a unit, port and VL, return an error, or the corresponding MTU for the
Packit 961e70
   VL as programmed by the SM */
Packit 961e70
/* Returns an int, so -1 indicates an error. */
Packit 961e70
int hfi_get_port_vl2mtu(int unit, int port, int vl);
Packit 961e70
Packit 961e70
/* Given a unit, port and index, return an error, or the corresponding pkey for
Packit 961e70
   the index as programmed by the SM */
Packit 961e70
/* Returns an int, so -1 indicates an error. */
Packit 961e70
int hfi_get_port_index2pkey(int unit, int port, int index);
Packit 961e70
Packit 961e70
/* Get the number of units supported by the driver.  Does not guarantee
Packit 961e70
   that a working chip has been found for each possible unit #.
Packit 961e70
   Returns -1 with errno set, or number of units >=0 (0 means none found). */
Packit Service 7ed5cc
int hfi_get_num_units();
Packit 961e70
Packit 961e70
/* Given a unit number, returns 1 if any port on the unit is active.
Packit 961e70
   returns 0 if no port on the unit is active.
Packit 961e70
   returns -1 when an error occurred. */
Packit 961e70
int hfi_get_unit_active(int unit);
Packit 961e70
Packit Service 7ed5cc
/* get the number of contexts from the unit id. */
Packit Service 7ed5cc
int hfi_get_num_contexts(int unit);
Packit 961e70
Packit 961e70
/* Open hfi device file, return -1 on error. */
Packit 961e70
int hfi_context_open(int unit, int port, uint64_t open_timeout);
Packit 961e70
int hfi_context_open_ex(int unit, int port, uint64_t open_timeout,
Packit 961e70
		     char *dev_name,size_t dev_name_len);
Packit 961e70
Packit 961e70
uint32_t hfi_check_non_dw_mul_sdma(void);
Packit 961e70
Packit 961e70
void hfi_context_close(int fd);
Packit 961e70
Packit 961e70
/* hfi_get_user_major_version() returns the major version of the driver
Packit 961e70
   that should be used for this session of psm. Valid only after
Packit 961e70
   hfi_context_open has been called. */
Packit 961e70
uint16_t hfi_get_user_major_version(void);
Packit 961e70
Packit 961e70
/* hfi_get_user_minor_version() return the minor version of the driver */
Packit 961e70
uint16_t hfi_get_user_minor_version(void);
Packit 961e70
Packit 961e70
void hfi_set_user_version(uint32_t version);
Packit 961e70
void hfi_set_user_major_version(uint16_t major_version);
Packit 961e70
Packit 961e70
int hfi_cmd_write(int fd, struct hfi1_cmd *, size_t count);
Packit 961e70
Packit 961e70
int hfi_cmd_writev(int fd, const struct iovec *iov, int iovcnt);
Packit 961e70
Packit 961e70
/* hfi_get_cc_settings_bin() returns less than or equal to 0 on failure,
Packit 961e70
   returns greater than 0 on success. */
Packit 961e70
 int hfi_get_cc_settings_bin(int unit, int port, char *ccabuf, size_t len_ccabuf);
Packit 961e70
int hfi_get_cc_table_bin(int unit, int port, uint16_t **cctp);
Packit 961e70
Packit 961e70
/* We use mmap64() because we compile in both 32 and 64 bit mode,
Packit 961e70
   and we have to map physical addresses that are > 32 bits long.
Packit 961e70
   While linux implements mmap64, it doesn't have a man page,
Packit 961e70
   and isn't declared in any header file, so we declare it here ourselves. */
Packit 961e70
Packit 961e70
/* We'd like to just use -D_LARGEFILE64_SOURCE, to make off_t 64 bits and
Packit 961e70
   redirects mmap to mmap64 for us, but at least through suse10 and fc4,
Packit 961e70
   it doesn't work when the address being mapped is > 32 bits.  It chips
Packit 961e70
   off bits 32 and above.   So we stay with mmap64. */
Packit 961e70
extern void *mmap64(void *, size_t, int, int, int, __off64_t);
Packit 961e70
void *hfi_mmap64(void *, size_t, int, int, int, __off64_t);
Packit 961e70
Packit 961e70
/* Statistics maintained by the driver */
Packit 961e70
int hfi_get_stats(uint64_t *, int);
Packit 961e70
int hfi_get_stats_names(char **namep);
Packit 961e70
/* Counters maintained in the chip, globally, and per-prot */
Packit 961e70
int hfi_get_ctrs_unit(int unitno, uint64_t *, int);
Packit 961e70
int hfi_get_ctrs_unit_names(int unitno, char **namep);
Packit 961e70
int hfi_get_ctrs_port(int unitno, int port, uint64_t *, int);
Packit 961e70
int hfi_get_ctrs_port_names(int unitno, char **namep);
Packit 961e70
Packit 961e70
/* sysfs helper routines (only those currently used are exported;
Packit 961e70
 * try to avoid using others) */
Packit 961e70
Packit 961e70
const char *hfi_sysfs_path(void);
Packit 961e70
Packit 961e70
/* read a string value */
Packit 961e70
int hfi_sysfs_port_read(uint32_t unit, uint32_t port, const char *attr,
Packit 961e70
			char **datap);
Packit 961e70
Packit 961e70
/* read a string value into buff, no more than size bytes.
Packit 961e70
   returns the number of bytes read */
Packit 961e70
size_t hfi_sysfs_unit_port_read(uint32_t unit, uint32_t port, const char *attr,
Packit 961e70
			char *buff, size_t size);
Packit 961e70
Packit 961e70
/* open attribute in unit's sysfs directory via open(2) */
Packit 961e70
int hfi_sysfs_unit_open(uint32_t unit, const char *attr, int flags);
Packit 961e70
int hfi_sysfs_port_open(uint32_t unit, uint32_t port, const char *attr,
Packit 961e70
			int flags);
Packit 961e70
/* print to attribute in {unit,port} sysfs directory */
Packit 961e70
int hfi_sysfs_port_printf(uint32_t unit, uint32_t port, const char *attr,
Packit 961e70
			  const char *fmt, ...)
Packit 961e70
			  __attribute__((format(printf, 4, 5)));
Packit 961e70
int hfi_sysfs_unit_printf(uint32_t unit, const char *attr, const char *fmt, ...)
Packit 961e70
			  __attribute__((format(printf, 3, 4)));
Packit 961e70
Packit 961e70
int hfi_hfifs_unit_write(uint32_t unit, const char *attr, const void *data,
Packit 961e70
			 size_t len);
Packit 961e70
/* read up to one page of malloc'ed data (caller must free), returning
Packit 961e70
   number of bytes read or -1 */
Packit 961e70
int hfi_hfifs_read(const char *attr, char **datap);
Packit 961e70
int hfi_hfifs_unit_read(uint32_t unit, const char *attr, char **data);
Packit 961e70
/* read a signed 64-bit quantity, in some arbitrary base */
Packit 961e70
int hfi_sysfs_unit_read_s64(uint32_t unit, const char *attr,
Packit 961e70
			    int64_t *valp, int base);
Packit 961e70
int hfi_sysfs_port_read_s64(uint32_t unit, uint32_t port, const char *attr,
Packit 961e70
			    int64_t *valp, int base);
Packit 961e70
int64_t hfi_sysfs_unit_read_node_s64(uint32_t unit);
Packit 961e70
/* these read directly into supplied buffer and take a count */
Packit 961e70
int hfi_hfifs_rd(const char *, void *, int);
Packit 961e70
int hfi_hfifs_unit_rd(uint32_t unit, const char *, void *, int);
Packit 961e70
Packit 961e70
int hfi_hfifs_open(const char *relname, int flags);
Packit 961e70
Packit 961e70
int hfi_cmd_wait_for_packet(int fd);
Packit 961e70
Packit 961e70
#endif /* OPA_SERVICE_GEN1_H */