448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn/*
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * CDDL HEADER START
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn *
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * The contents of this file are subject to the terms of the
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * Common Development and Distribution License (the "License").
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * You may not use this file except in compliance with the License.
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn *
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * or http://www.opensolaris.org/os/licensing.
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * See the License for the specific language governing permissions
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * and limitations under the License.
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn *
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * When distributing Covered Code, include this CDDL HEADER in each
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * If applicable, add the following below this CDDL HEADER, with the
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * fields enclosed by brackets "[]" replaced with your own identifying
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * information: Portions Copyright [yyyy] [name of copyright owner]
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn *
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * CDDL HEADER END
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn/*
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#ifndef _SYS_IB_CLIENTS_OF_SOL_UMAD_SOL_UMAD_H
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#define _SYS_IB_CLIENTS_OF_SOL_UMAD_SOL_UMAD_H
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#ifdef __cplusplus
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornextern "C" {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#endif
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn/*
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * map between minor node #s and HCA indexes and Port #s. This leaves
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * room for 16 boards with up to 16 ports each.
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#define GET_UMAD_MINOR(node, port) ((node << 4) | port)
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#define GET_ISSM_MINOR(node, port) ((node << 4) | port | 0x8000)
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#define GET_NODE(minor) ((minor >> 4) & 0xf)
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#define GET_PORT(minor) ((minor) & 0xf)
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#define ISSM_MINOR(minor) (minor & 0x8000)
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#define GET_UCTX(minor) (minor >> 8)
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#define GET_NEW_UCTX_MINOR(minor, uctxnum) ((uctxnum << 8) | minor)
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn/* UMAD KA instance, only one instance allowed */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#define UMAD_INSTANCE 0
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#define MAX_UCTX 16 /* Maximum number of contexts. */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horntypedef struct umad_port_info_s umad_port_info_t;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn/*
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * User context. One per open file descriptor.
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horntypedef struct umad_uctx_s {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn kmutex_t uctx_lock; /* protects agent_list */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn umad_port_info_t *uctx_port;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn struct pollhead uctx_pollhead;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn llist_head_t uctx_agent_list; /* list of agents registered */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn kmutex_t uctx_recv_lock; /* protects recv_list below */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn genlist_t uctx_recv_list; /* Queue of received MADs */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn kcondvar_t uctx_recv_cv; /* wait on for received data */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn} umad_uctx_t;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horntypedef struct umad_agent_s {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn llist_head_t agent_list;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn struct ib_user_mad_reg_req agent_req; /* Params given during */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn /* registration */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn struct ibmf_reg_info *agent_reg; /* IBMF information */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn umad_uctx_t *agent_uctx; /* User context to which */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn /* this agent belongs. */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn int agent_outstanding_msgs; /* # of msgs waiting */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn /* for a response */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn kmutex_t agent_lock; /* protects this structure */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn int agent_flags;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn kcondvar_t agent_cv; /* used to wake up unregister */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn} umad_agent_t;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornenum umad_agent_flags {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn UMAD_AGENT_UNREGISTERING = 1 << 0,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn UMAD_HANDLING_ASYNC = 1 << 1
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn};
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horntypedef struct umad_hca_info_s {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ib_guid_t hca_guid;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ibt_hca_hdl_t hca_handle;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ibt_hca_attr_t hca_attr;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn uint8_t hca_nports;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn umad_port_info_t *hca_ports;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn} umad_hca_info_t;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstruct umad_port_info_s {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn kmutex_t port_lock;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn const umad_hca_info_t *port_hca; /* backpointer to hca */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn unsigned int port_minor_name; /* number in device name. */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn uint8_t port_num;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ib_guid_t port_guid;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn int port_issm_open_cnt;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ib_lid_t port_lid;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn bool port_has_umad_minor_node;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn bool port_has_issm_minor_node;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn llist_head_t port_ibmf_regs;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn};
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horntypedef struct umad_info_s {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn dev_info_t *info_dip; /* back pointer to devinfo */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn kmutex_t info_mutex; /* protects this device */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ibt_clnt_hdl_t info_clnt_hdl;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn uint32_t info_hca_count;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ib_guid_t *info_hca_guids;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn umad_hca_info_t *info_hcas; /* hca list */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn umad_uctx_t *info_uctx[MAX_UCTX];
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn} umad_info_t;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horntypedef struct ib_umad_msg_s {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn struct ib_user_mad_hdr umad_msg_hdr;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ibmf_msg_t *umad_msg_ibmf_msg;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn} ib_umad_msg_t;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn/*
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn * A UMAD we send is linked to a user context.
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstruct umad_send {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn struct umad_agent_s *send_agent; /* agent that sent the MAD */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn size_t send_len;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn uint8_t send_umad[]; /* MAD from userspace */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn};
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstruct ibmf_reg_info {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ibmf_handle_t ibmf_reg_handle;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn unsigned int ibmf_reg_refcnt;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn umad_uctx_t *ibmf_reg_uctx;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn kmutex_t ibmf_reg_lock;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn kcondvar_t ibmf_cv;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn unsigned int ibmf_flags;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn enum _ibmf_client_type_t ibmf_class;
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn};
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn/* Flags values for ibmf_flags above */
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornenum ibmf_flag_values {
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn UMAD_IBMF_UNREGISTERING = 1 << 0
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn};
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic inline int
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornis_supported_mad_method(int nr, void *addr)
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn{
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn return (1 & (((uint32_t *)addr)[nr >> 5] >> (nr & 31)));
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn}
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn void **resultp);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn int flags, char *name, caddr_t valuep,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn int *lengthp);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_open(dev_t *devp, int flag, int otyp, cred_t *cred);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_close(dev_t dev, int flag, int otyp, cred_t *cred);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_read(dev_t dev, struct uio *uiop, cred_t *credp);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_write(dev_t dev, struct uio *uiop, cred_t *credp);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_poll(dev_t dev, short events, int anyyet,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn short *reventsp, struct pollhead **phpp);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn cred_t *credp, int *rvalp);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic void umad_async_handler(void *private, ibt_hca_hdl_t hca_hdl,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ibt_async_code_t code,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ibt_async_event_t *event);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_register(struct ib_user_mad_reg_req *req,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn umad_uctx_t *uctx);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic int umad_unregister(struct ib_user_mad_reg_req *agent,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn umad_uctx_t *uctx);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Hornstatic void umad_unsolicited_cb(ibmf_handle_t ibmf_handle,
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn ibmf_msg_t *msgp, void *args);
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#ifdef __cplusplus
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn}
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#endif
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn
448bf8594153765bb5fce82a8888e01e3f6c3badLida.Horn#endif /* _SYS_IB_CLIENTS_OF_SOL_UMAD_SOL_UMAD_H */