/*
 * $Header: /smsa/bsd:include/dev/econet.h:bsd  1.13  $
 * $Source: /smsa/bsd:include/dev/econet.h: $
 *
 * Copyright (c) 1988 Acorn Computers Ltd., Cambridge, England
 *
 */

#ifndef	__dev_econet_h
#define	__dev_econet_h

/* Interface to econet device ioctls */

#ifndef	__sys_ioctl_h
#include "../sys/ioctl.h"
#endif

/* use:
 *       #include <dev/econet.h>
 *
 * applications:
 *    int h, port_number, tx_tries = N;
 *    h = open("/dev/eco0",0,0);
 *    rc = ioctl( h, ECO<op>,       &structure );
 *    rc = ioctl( h, ECO<op>PORT,   &port_number );
 *    rc = ioctl( h, ECOSETTXTRIES, &tx_tries );
 *
 * within the kernel:
 *    rc = eco_ioctl( x, ECO<op>, &structure );
 *    rc = eco_ioctl( x, ECO<op>, &port_number );
 * where x is 128 or greater, and less than 255.
 * to use a port for reception, you must still have
 * claimed it using such an x.  using x = 255 gives
 * you use of unclaimed ports, but doesn't claim
 * the port in any way, so chaos can ensue.
 * If you use x < 128, the system will believe this is
 * a user call, and try various data copying things,
 * and chaos will ensue.
 */

#define ECOCLAIMPORT              _IOW('e', 0, int)      /* claim a port of my choice */
#define ECOCHOOSEPORT             _IOR('e', 1, int)      /* choose a port for me      */
#define ECOFREEPORT               _IOW('e', 2, int)      /* let it go                 */

/* this structure is used for all other operations except statistics inquiry */
/* various aliases are provided for the extra parms, depending on use.      */
struct eco_op {
  int eco_word1;
  int eco_word2;
  unsigned char eco_station, eco_net, eco_control, eco_port;
} ;

/* enable or disable a reception as specified by station, net, port.
 * control is ignored.
 * buffers is the number of buffers this rx can occupy.
 * for simple operation, set rx_group to zero.  On return, it will be
 * filled.  If you leave it alone for subsequent enables, they are grouped
 * together so that a wait for activity on any one of the group (see below)
 * returns after activity on any of them.  If you cancel the "master" enable
 * (the first one) the others become ungrouped, as if you had set their
 * rx_group to zero.  rx_group is ignored on disable.
 */
#define eco_buffers               eco_word1
#define eco_rx_group              eco_word2
#define ECOENABLERECEPTION        _IOWR('e', 3, struct eco_op)
#define ECODISABLERECEPTION       _IOW('e', 4, struct eco_op)

/* find out about an enabled reception, specified by station, net, port.
 * control is ignored going in.
 * afterwards, station, net, control and port are updated to describe
 * the reception concerned.
 * data_length is the amount of data there, or zero if none.
 * handle is a number to quote below, or zero if no data.
 */
#define eco_data_length           eco_word1
#define eco_handle                eco_word2
#define ECOBUFFERSTATUS           _IOWR('e', 5, struct eco_op)

/* either read or discard the data you found out about above.  Leave the
 * handle in the same place in the record, put the address where you want
 * the data placed in data_ptr.
 */
#define eco_data_ptr              eco_word1
#define ECOBUFFERREAD             _IOW('e', 6, struct eco_op)
#define ECOBUFFERKILL             _IOW('e', 7, struct eco_op)

/* wait for some activity, sleeping, on the reception specified by
 * station, net, port.  If using the timed version provide a time,
 * in centiseconds, in time_wait.
 */
#define eco_time_wait           eco_word1
#define ECOAWAITRECEPTION       _IOW('e', 8, struct eco_op)
#define ECOAWAITRECEPTIONTIMED  _IOW('e', 9, struct eco_op)

/* to transmit a packet: fill in station, net, control, port, and
 * the address and length of the data and away we go.  A set number
 * of tries with a useful backoff strategy will be performed for you.
 * A Broadcast is specified by station == net == 0xFF.
 */
#define eco_tx_data_ptr           eco_word1
#define eco_tx_data_length        eco_word2
#define ECOTRANSMIT               _IOW('e', 40, struct eco_op)

/* after a machine type operation, the machine type is returned.
 */
#define eco_machine_type          eco_word1
#define ECOMACHINETYPE            _IOWR('e', 41, struct eco_op)

/* this allows you to set the number of attempts at transmitting in
 * the event of an error.  The default is 64.  It only sets the tries
 * used for normal transmits by *this* *user* handle, ie for minor
 * devices less than 32.  Other handles and kernel tries are not
 * affected.  You are advised to keep to multiples of 16 to preserve
 * the average delay between tries, so that one machine does not have
 * an advantage, or use one of you must, to do all retrying yourself.
 * This is not advised.  Closing a device then reopening sets the
 * value back to the default.  255 is the largest value accepted.
 */
#define ECOSETTXTRIES             _IOW('e', 42, int)

/* and read the current value
 */
#define ECOGETTXTRIES             _IOR('e', 43, int)

/* loads more information about the state of the world.
 */
struct eco_stats {
  unsigned char eco_this_station;
  unsigned char eco_this_net;
  int eco_transmits;
  int eco_pended_transmits;
  int eco_tried_transmits;
  int eco_failed_transmits;
  int eco_receives;
  int eco_discarded_receives;
  int eco_last_tx_error;
} ;

#define ECOSTATS                 _IOR('e', 80, struct eco_stats)
#define ECOSTATSCLEAR            _IOR('e', 81, struct eco_stats)

#define eco_status eco_stats
#define ECOSTATUS ECOSTATS
#define ECOSTATUSCLEAR ECOSTATSCLEAR

/* a use-once call at the start of the world, in rc.net I assume. */
#define eco_large_buffers        eco_word1
#define eco_small_buffers        eco_word2
#define ECOINITIALISE            _IOWR('e', 120, struct eco_op)

#endif/*__dev_econet_h*/

/* EOF econet.h */
