/* 
 * $Id: zfcp_zh.h,v 1.3.2.1 2004/01/26 17:26:34 mschwide Exp $
 *
 * Module providing an interface for HBA API (FC-HBA) implementation
 * to the zfcp driver.
 *
 * (C) Copyright IBM Corp. 2002, 2003
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. See the file COPYING for more
 * information.
 *
 * Authors:
 *       Stefan Voelkel <Stefan.Voelkel@millenux.com>
 *       Andreas Herrmann <aherrman@de.ibm.com>
 */


#ifndef _ZFCP_ZH_H_
#define _ZFCP_ZH_H_

#include "zfcp.h"
#include <scsi/scsi_ioctl.h>
#include <asm/scatterlist.h>

/*
 * Besides a punch of standard error codes we use some newly defined error
 * codes.
 */
#define ENOADA 200 /* no such adapter */
#define ENOPOR 201 /* no such port */
#define ENOUNI 202 /* no such unit */

/*
 * flags for get_config
 * */
#define ZH_GET_CONFIG_ADAPTERS 0
#define ZH_GET_CONFIG_PORTS 1
#define ZH_GET_CONFIG_UNITS 2

/**
 * struct zfcp_zh_callbacks
 * @adapter_add: callback for adapter add events
 *
 * structure containing all the callbacks
 */
struct zfcp_zh_callbacks
{
	void (*adapter_add) (struct file *, devno_t, wwn_t, wwn_t);
	void (*port_add) (struct file *, devno_t, wwn_t, wwn_t, fc_id_t);
	void (*unit_add) (struct file *, devno_t, wwn_t, fcp_lun_t,
			  unsigned int, unsigned int,
			  unsigned int, unsigned int);
	void (*incomming_els) (const devno_t, const fc_id_t, const void *);
	void (*link_down) (const fc_id_t);
	void (*link_up) (const fc_id_t);
};

/**
 * struct zfcp_callbacks
 * @lock: rw-lock
 * @callbacks: relevant callbacks into zh module
 *
 * callbacks and according lock
 */
struct zfcp_callbacks
{
	rwlock_t lock;
	struct zfcp_zh_callbacks *callbacks;
};

extern struct zfcp_callbacks zfcp_callback;

/**
 * struct zfcp_adapter_attributes
 */
struct zfcp_adapter_attributes
{
	char		manufacturer[64];
	char		serial_number[64];
	char		model[256];
	char		model_description[256];
	wwn_t		node_wwn;
	char		node_symbolic_name[256];
	char		hardware_version[256];
	char		driver_version[256];
	char		option_rom_version[256];
	char		firmware_version[256];
	u32		vendor_specific_id;
	u32		number_of_ports;
	char		driver_name[256];
};

/**
 * struct zfcp_port_attributes
 */
struct zfcp_port_attributes {
	wwn_t wwnn;
	wwn_t wwpn;
	wwn_t fabric_name;
	u32 fcid;
	u32 type;
	u32 state;
	u32 supported_class_of_service;
	u32 supported_speed;
	u32 speed;
	u32 max_frame_size;
	u32 discovered_ports;
	u8 supported_fc4_types[32];
	u8 active_fc4_types[32];
	char symbolic_name[256];
};

/**
 * struct zfcp_port_statistics
 */
struct zfcp_port_statistics {
	u64 last_reset;
	u64 tx_frames;
	u64 tx_words;
	u64 rx_frames;
	u64 rx_words;
	u64 lip;
	u64 nos;
	u64 error_frames;
	u64 dumped_frames;
	u64 link_failure;
	u64 loss_of_sync;
	u64 loss_of_signal;
	u64 prim_seq_prot_error;
	u64 invalid_tx_words;
	u64 invalid_crc;
	u64 input_requests;
	u64 output_requests;
	u64 control_requests;
	u64 input_megabytes;
	u64 output_megabytes;
};

/*
 * functions needed by zfcp_hbaapi in zfcp
 */
int zfcp_zh_callbacks_register(struct zfcp_zh_callbacks *);
int zfcp_zh_callbacks_unregister(struct zfcp_zh_callbacks *);
int zfcp_zh_get_config(struct file *, devno_t, wwn_t, unsigned int);
int zfcp_zh_get_adapter_attributes(devno_t, struct zfcp_adapter_attributes *);
int zfcp_zh_get_port_attributes(devno_t, struct zfcp_port_attributes *);
int zfcp_zh_get_port_statistics(devno_t, struct zfcp_port_statistics *);
int zfcp_zh_get_dport_attributes(devno_t, wwn_t, struct zfcp_port_attributes *);
int zfcp_zh_send_ct(devno_t, struct scatterlist *, unsigned int,
		    struct scatterlist *, unsigned int);
int zfcp_zh_send_els(devno_t, wwn_t, struct scatterlist*, unsigned int,
		     struct scatterlist*, unsigned int);
int zfcp_zh_send_scsi(devno_t, wwn_t, fcp_lun_t, Scsi_Cmnd *);
int zfcp_zh_assert_fclun_zero(devno_t, wwn_t); /* needed for ReportLUNs */

/*
 * functions needed for callbacks into zfcp_hbaapi
 */
void zfcp_callback_do_adapter_add(struct file *, const zfcp_adapter_t *);
void zfcp_callback_do_port_add(struct file *, const zfcp_adapter_t *,
			       const zfcp_port_t *);
void zfcp_callback_do_unit_add(struct file *, const zfcp_adapter_t *,
			       const zfcp_port_t *, const zfcp_unit_t *);
void zfcp_callback_do_incomming_els(const zfcp_adapter_t *, const void *);
void zfcp_callback_do_link_down(const zfcp_adapter_t *);
void zfcp_callback_do_link_up(const zfcp_adapter_t *);

#endif /* _ZFCP_ZH_H_ */
