linux/drivers/net/plip/plip.c

// SPDX-License-Identifier: GPL-2.0-or-later
/* $Id: plip.c,v 1.3.6.2 1997/04/16 15:07:56 phil Exp $ */
/* PLIP: A parallel port "network" driver for Linux. */
/* This driver is for parallel port with 5-bit cable (LapLink (R) cable). */
/*
 * Authors:	Donald Becker <[email protected]>
 *		Tommy Thorn <[email protected]>
 *		Tanabe Hiroyasu <[email protected]>
 *		Alan Cox <[email protected]>
 *		Peter Bauer <[email protected]>
 *		Niibe Yutaka <[email protected]>
 *		Nimrod Zimerman <[email protected]>
 *
 * Enhancements:
 *		Modularization and ifreq/ifmap support by Alan Cox.
 *		Rewritten by Niibe Yutaka.
 *		parport-sharing awareness code by Philip Blundell.
 *		SMP locking by Niibe Yutaka.
 *		Support for parallel ports with no IRQ (poll mode),
 *		Modifications to use the parallel port API
 *		by Nimrod Zimerman.
 *
 * Fixes:
 *		Niibe Yutaka
 *		  - Module initialization.
 *		  - MTU fix.
 *		  - Make sure other end is OK, before sending a packet.
 *		  - Fix immediate timer problem.
 *
 *		Al Viro
 *		  - Changed {enable,disable}_irq handling to make it work
 *		    with new ("stack") semantics.
 */

/*
 * Original version and the name 'PLIP' from Donald Becker <[email protected]>
 * inspired by Russ Nelson's parallel port packet driver.
 *
 * NOTE:
 *     Tanabe Hiroyasu had changed the protocol, and it was in Linux v1.0.
 *     Because of the necessity to communicate to DOS machines with the
 *     Crynwr packet driver, Peter Bauer changed the protocol again
 *     back to original protocol.
 *
 *     This version follows original PLIP protocol.
 *     So, this PLIP can't communicate the PLIP of Linux v1.0.
 */

/*
 *     To use with DOS box, please do (Turn on ARP switch):
 *	# ifconfig plip[0-2] arp
 */
static const char version[] =;

/*
  Sources:
	Ideas and protocols came from Russ Nelson's <[email protected]>
	"parallel.asm" parallel port packet driver.

  The "Crynwr" parallel port standard specifies the following protocol:
    Trigger by sending nibble '0x8' (this causes interrupt on other end)
    count-low octet
    count-high octet
    ... data octets
    checksum octet
  Each octet is sent as <wait for rx. '0x1?'> <send 0x10+(octet&0x0F)>
			<wait for rx. '0x0?'> <send 0x00+((octet>>4)&0x0F)>

  The packet is encapsulated as if it were ethernet.

  The cable used is a de facto standard parallel null cable -- sold as
  a "LapLink" cable by various places.  You'll need a 12-conductor cable to
  make one yourself.  The wiring is:
    SLCTIN	17 - 17
    GROUND	25 - 25
    D0->ERROR	2 - 15		15 - 2
    D1->SLCT	3 - 13		13 - 3
    D2->PAPOUT	4 - 12		12 - 4
    D3->ACK	5 - 10		10 - 5
    D4->BUSY	6 - 11		11 - 6
  Do not connect the other pins.  They are
    D5,D6,D7 are 7,8,9
    STROBE is 1, FEED is 14, INIT is 16
    extra grounds are 18,19,20,21,22,23,24
*/

#include <linux/compat.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/interrupt.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/if_ether.h>
#include <linux/in.h>
#include <linux/errno.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/inetdevice.h>
#include <linux/skbuff.h>
#include <linux/if_plip.h>
#include <linux/workqueue.h>
#include <linux/spinlock.h>
#include <linux/completion.h>
#include <linux/parport.h>
#include <linux/bitops.h>

#include <net/neighbour.h>

#include <asm/irq.h>
#include <asm/byteorder.h>

/* Maximum number of devices to support. */
#define PLIP_MAX

/* Use 0 for production, 1 for verification, >2 for debug */
#ifndef NET_DEBUG
#define NET_DEBUG
#endif
static const unsigned int net_debug =;

#define ENABLE(irq)
#define DISABLE(irq)

/* In micro second */
#define PLIP_DELAY_UNIT

/* Connection time out = PLIP_TRIGGER_WAIT * PLIP_DELAY_UNIT usec */
#define PLIP_TRIGGER_WAIT

/* Nibble time out = PLIP_NIBBLE_WAIT * PLIP_DELAY_UNIT usec */
#define PLIP_NIBBLE_WAIT

/* Bottom halves */
static void plip_kick_bh(struct work_struct *work);
static void plip_bh(struct work_struct *work);
static void plip_timer_bh(struct work_struct *work);

/* Interrupt handler */
static void plip_interrupt(void *dev_id);

/* Functions for DEV methods */
static netdev_tx_t plip_tx_packet(struct sk_buff *skb, struct net_device *dev);
static int plip_hard_header(struct sk_buff *skb, struct net_device *dev,
                            unsigned short type, const void *daddr,
			    const void *saddr, unsigned len);
static int plip_hard_header_cache(const struct neighbour *neigh,
                                  struct hh_cache *hh, __be16 type);
static int plip_open(struct net_device *dev);
static int plip_close(struct net_device *dev);
static int plip_siocdevprivate(struct net_device *dev, struct ifreq *ifr,
			       void __user *data, int cmd);
static int plip_preempt(void *handle);
static void plip_wakeup(void *handle);

enum plip_connection_state {};

enum plip_packet_state {};

enum plip_nibble_state {};

struct plip_local {};

struct net_local {};

static inline void enable_parport_interrupts (struct net_device *dev)
{}

static inline void disable_parport_interrupts (struct net_device *dev)
{}

static inline void write_data (struct net_device *dev, unsigned char data)
{}

static inline unsigned char read_status (struct net_device *dev)
{}

static const struct header_ops plip_header_ops =;

static const struct net_device_ops plip_netdev_ops =;

/* Entry point of PLIP driver.
   Probe the hardware, and register/initialize the driver.

   PLIP is rather weird, because of the way it interacts with the parport
   system.  It is _not_ initialised from Space.c.  Instead, plip_init()
   is called, and that function makes up a "struct net_device" for each port, and
   then calls us here.

   */
static void
plip_init_netdev(struct net_device *dev)
{}

/* Bottom half handler for the delayed request.
   This routine is kicked by do_timer().
   Request `plip_bh' to be invoked. */
static void
plip_kick_bh(struct work_struct *work)
{}

/* Forward declarations of internal routines */
static int plip_none(struct net_device *, struct net_local *,
		     struct plip_local *, struct plip_local *);
static int plip_receive_packet(struct net_device *, struct net_local *,
			       struct plip_local *, struct plip_local *);
static int plip_send_packet(struct net_device *, struct net_local *,
			    struct plip_local *, struct plip_local *);
static int plip_connection_close(struct net_device *, struct net_local *,
				 struct plip_local *, struct plip_local *);
static int plip_error(struct net_device *, struct net_local *,
		      struct plip_local *, struct plip_local *);
static int plip_bh_timeout_error(struct net_device *dev, struct net_local *nl,
				 struct plip_local *snd,
				 struct plip_local *rcv,
				 int error);

#define OK
#define TIMEOUT
#define ERROR
#define HS_TIMEOUT

plip_func;

static const plip_func connection_state_table[] =;

/* Bottom half handler of PLIP. */
static void
plip_bh(struct work_struct *work)
{}

static void
plip_timer_bh(struct work_struct *work)
{}

static int
plip_bh_timeout_error(struct net_device *dev, struct net_local *nl,
		      struct plip_local *snd, struct plip_local *rcv,
		      int error)
{}

static int
plip_none(struct net_device *dev, struct net_local *nl,
	  struct plip_local *snd, struct plip_local *rcv)
{}

/* PLIP_RECEIVE --- receive a byte(two nibbles)
   Returns OK on success, TIMEOUT on timeout */
static inline int
plip_receive(unsigned short nibble_timeout, struct net_device *dev,
	     enum plip_nibble_state *ns_p, unsigned char *data_p)
{}

/*
 *	Determine the packet's protocol ID. The rule here is that we
 *	assume 802.3 if the type field is short enough to be a length.
 *	This is normal practice and works for any 'now in use' protocol.
 *
 *	PLIP is ethernet ish but the daddr might not be valid if unicast.
 *	PLIP fortunately has no bus architecture (its Point-to-point).
 *
 *	We can't fix the daddr thing as that quirk (more bug) is embedded
 *	in far too many old systems not all even running Linux.
 */

static __be16 plip_type_trans(struct sk_buff *skb, struct net_device *dev)
{}

/* PLIP_RECEIVE_PACKET --- receive a packet */
static int
plip_receive_packet(struct net_device *dev, struct net_local *nl,
		    struct plip_local *snd, struct plip_local *rcv)
{}

/* PLIP_SEND --- send a byte (two nibbles)
   Returns OK on success, TIMEOUT when timeout    */
static inline int
plip_send(unsigned short nibble_timeout, struct net_device *dev,
	  enum plip_nibble_state *ns_p, unsigned char data)
{}

/* PLIP_SEND_PACKET --- send a packet */
static int
plip_send_packet(struct net_device *dev, struct net_local *nl,
		 struct plip_local *snd, struct plip_local *rcv)
{}

static int
plip_connection_close(struct net_device *dev, struct net_local *nl,
		      struct plip_local *snd, struct plip_local *rcv)
{}

/* PLIP_ERROR --- wait till other end settled */
static int
plip_error(struct net_device *dev, struct net_local *nl,
	   struct plip_local *snd, struct plip_local *rcv)
{}

/* Handle the parallel port interrupts. */
static void
plip_interrupt(void *dev_id)
{}

static netdev_tx_t
plip_tx_packet(struct sk_buff *skb, struct net_device *dev)
{}

static void
plip_rewrite_address(const struct net_device *dev, struct ethhdr *eth)
{}

static int
plip_hard_header(struct sk_buff *skb, struct net_device *dev,
		 unsigned short type, const void *daddr,
		 const void *saddr, unsigned len)
{}

static int plip_hard_header_cache(const struct neighbour *neigh,
				  struct hh_cache *hh, __be16 type)
{}

/* Open/initialize the board.  This is called (in the current kernel)
   sometime after booting when the 'ifconfig' program is run.

   This routine gets exclusive access to the parallel port by allocating
   its IRQ line.
 */
static int
plip_open(struct net_device *dev)
{}

/* The inverse routine to plip_open (). */
static int
plip_close(struct net_device *dev)
{}

static int
plip_preempt(void *handle)
{}

static void
plip_wakeup(void *handle)
{}

static int
plip_siocdevprivate(struct net_device *dev, struct ifreq *rq,
		    void __user *data, int cmd)
{}

static int parport[PLIP_MAX] =;
static int timid;

module_param_array();
module_param(timid, int, 0);
MODULE_PARM_DESC();

static struct net_device *dev_plip[PLIP_MAX] =;

static inline int
plip_searchfor(int list[], int a)
{}

/* plip_attach() is called (by the parport code) when a port is
 * available to use. */
static void plip_attach (struct parport *port)
{}

/* plip_detach() is called (by the parport code) when a port is
 * no longer available to use. */
static void plip_detach (struct parport *port)
{}

static int plip_probe(struct pardevice *par_dev)
{}

static struct parport_driver plip_driver =;

static void __exit plip_cleanup_module (void)
{}

#ifndef MODULE

static int parport_ptr;

static int __init plip_setup(char *str)
{}

__setup();

#endif /* !MODULE */

static int __init plip_init (void)
{}

module_init();
module_exit(plip_cleanup_module);
MODULE_DESCRIPTION();
MODULE_LICENSE();