Blame src/smp.h

Packit 7e09eb
/*
Packit 7e09eb
 * Intel(R) Enclosure LED Utilities
Packit 7e09eb
 * Copyright (C) 2011-2017 Intel Corporation.
Packit 7e09eb
 *
Packit 7e09eb
 * This program is free software; you can redistribute it and/or modify it
Packit 7e09eb
 * under the terms and conditions of the GNU General Public License,
Packit 7e09eb
 * version 2, as published by the Free Software Foundation.
Packit 7e09eb
 *
Packit 7e09eb
 * This program is distributed in the hope it will be useful, but WITHOUT
Packit 7e09eb
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit 7e09eb
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
Packit 7e09eb
 * more details.
Packit 7e09eb
 *
Packit 7e09eb
 * You should have received a copy of the GNU General Public License along with
Packit 7e09eb
 * this program; if not, write to the Free Software Foundation, Inc.,
Packit 7e09eb
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
Packit 7e09eb
 *
Packit 7e09eb
 */
Packit 7e09eb
Packit 7e09eb
#include "ibpi.h"
Packit 7e09eb
#include "block.h"
Packit 7e09eb
Packit 7e09eb
#ifndef _SMP_H_INCLUDED
Packit 7e09eb
#define _SMP_H_INCLUDED
Packit 7e09eb
Packit 7e09eb
/* smp constants */
Packit 7e09eb
#define SMP_FRAME_TYPE_REQ	0x40
Packit 7e09eb
#define SMP_FRAME_TYPE_RESP	0x41
Packit 7e09eb
Packit 7e09eb
#define SMP_FUNC_GPIO_READ	0x02
Packit 7e09eb
#define SMP_FUNC_GPIO_WRITE	0x82
Packit 7e09eb
Packit 7e09eb
#define SMP_FRAME_CRC_LEN		sizeof(uint32_t)
Packit 7e09eb
#define SMP_DATA_CHUNK_SIZE	sizeof(uint32_t)
Packit 7e09eb
Packit 7e09eb
/* gpio constants */
Packit 7e09eb
/* gpio register types */
Packit 7e09eb
#define GPIO_REG_TYPE_CFG		0x00
Packit 7e09eb
#define GPIO_REG_TYPE_RX		0x01
Packit 7e09eb
#define GPIO_REG_TYPE_RX_GP	0x02
Packit 7e09eb
#define GPIO_REG_TYPE_TX		0x03
Packit 7e09eb
#define GPIO_REG_TYPE_TX_GP	0x04
Packit 7e09eb
Packit 7e09eb
/* gpio register indexes */
Packit 7e09eb
#define GPIO_REG_IND_CFG_0	0x00
Packit 7e09eb
#define GPIO_REG_IND_CFG_1	0x01
Packit 7e09eb
Packit 7e09eb
#define GPIO_REG_IND_RX_0		0x00
Packit 7e09eb
#define GPIO_REG_IND_RX_1		0x01
Packit 7e09eb
Packit 7e09eb
#define GPIO_REG_IND_TX_0		0x00
Packit 7e09eb
#define GPIO_REG_IND_TX_1		0x01
Packit 7e09eb
Packit 7e09eb
#define SG_RESPONSE_TIMEOUT (5 * 1000)	/* 1000 as miliseconds multiplier */
Packit 7e09eb
#define SCSI_MAX_CDB_LENGTH	0x10
Packit 7e09eb
Packit 7e09eb
#define GPIO_STATUS_OK			0x00
Packit 7e09eb
#define GPIO_STATUS_FAILURE 0x80
Packit 7e09eb
Packit 7e09eb
struct gpio_tx_register_byte {
Packit 7e09eb
	unsigned char error:3;
Packit 7e09eb
	unsigned char locate:2;
Packit 7e09eb
	unsigned char activity:3;
Packit 7e09eb
} __attribute__ ((__packed__));
Packit 7e09eb
Packit 7e09eb
/**
Packit 7e09eb
 * @brief Sends message to SES processor of an enclosure.
Packit 7e09eb
 *
Packit 7e09eb
 * This function send a message to an enclosure in order to control LEDs of
Packit 7e09eb
 * the given slot/component. It uses interface of ENCLOSURE kernel module to
Packit 7e09eb
 * control LEDs.
Packit 7e09eb
 *
Packit 7e09eb
 * @param[in]      device         Path to an enclosure device in sysfs.
Packit 7e09eb
 * @param[in]      ibpi           IBPI pattern to visualize.
Packit 7e09eb
 *
Packit 7e09eb
 * @return Number of characters written if successful or -1 in case of error
Packit 7e09eb
 *         and errno is set to appropriate error code.
Packit 7e09eb
 */
Packit 7e09eb
int scsi_ses_write(struct block_device *device, enum ibpi_pattern ibpi);
Packit 7e09eb
Packit 7e09eb
/**
Packit 7e09eb
 * @brief Write message to outbound raw byte stream buffer.
Packit 7e09eb
 *
Packit 7e09eb
 * @param[in]      device         Path to a smp device in sysfs.
Packit 7e09eb
 * @param[in]      ibpi           IBPI pattern to visualize.
Packit 7e09eb
 *
Packit 7e09eb
 * @return 1 if successful or -1 in case of error
Packit 7e09eb
 *         and errno is set to appropriate error code.
Packit 7e09eb
 */
Packit 7e09eb
int scsi_smp_fill_buffer(struct block_device *device, enum ibpi_pattern ibpi);
Packit 7e09eb
Packit 7e09eb
/**
Packit 7e09eb
 * @brief Sends message to SMP device.
Packit 7e09eb
 *
Packit 7e09eb
 * This function triggers gpio order to control LEDs of
Packit 7e09eb
 * the given component.
Packit 7e09eb
 *
Packit 7e09eb
 * @param[in]      device         Path to a smp device in sysfs.
Packit 7e09eb
 *
Packit 7e09eb
 * @return Number of bytes written to device if successful or -1 in case of error
Packit 7e09eb
 *         and errno is set to appropriate error code.
Packit 7e09eb
 */
Packit 7e09eb
int scsi_smp_write_buffer(struct block_device *device);
Packit 7e09eb
Packit 7e09eb
/**
Packit 7e09eb
 * @brief Init smp and gets phy index,
Packit 7e09eb
 *
Packit 7e09eb
 * @param[in]      path            Path to the device in sysfs. It can be NULL
Packit 7e09eb
 *                                 to just initialize cntrl and not to get the
Packit 7e09eb
 *                                 phy.
Packit 7e09eb
 * @param[in]      cntrl           Controller device to be initialized.
Packit 7e09eb
 *
Packit 7e09eb
 * @return Phy index on success if path and cntrl weren't NULL
Packit 7e09eb
 *         0 if error occurred or path was NULL.
Packit 7e09eb
 */
Packit 7e09eb
int cntrl_init_smp(const char *path, struct cntrl_device *cntrl);
Packit 7e09eb
Packit 7e09eb
/**
Packit 7e09eb
 * @brief Write GPIO data
Packit 7e09eb
 *
Packit 7e09eb
 * @param[in]      path            Path to the device in sysfs.
Packit 7e09eb
 *                                 phy.
Packit 7e09eb
 *
Packit 7e09eb
 * @param[in]      smp_reg_type    GPIO register type
Packit 7e09eb
 *
Packit 7e09eb
 * @param[in]      smp_reg_index   GPIO register index
Packit 7e09eb
 *
Packit 7e09eb
 * @param[in]      smp_reg_count   GPIO register count
Packit 7e09eb
 *
Packit 7e09eb
 * @param[in]      data            Data to be written
Packit 7e09eb
 *
Packit 7e09eb
 * @return written register count
Packit 7e09eb
 *         <0 if error occurred
Packit 7e09eb
 */
Packit 7e09eb
int smp_write_gpio(const char *path, int smp_reg_type,
Packit 7e09eb
			   int smp_reg_index, int smp_reg_count, void *data,
Packit 7e09eb
			   size_t len);
Packit 7e09eb
Packit 7e09eb
#endif				/* _SCSI_H_INCLUDED_ */