18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Linux header file for the ATP pocket ethernet adapter. */
38c2ecf20Sopenharmony_ci/* v1.09 8/9/2000 becker@scyld.com. */
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/if_ether.h>
68c2ecf20Sopenharmony_ci#include <linux/types.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/* The header prepended to received packets. */
98c2ecf20Sopenharmony_cistruct rx_header {
108c2ecf20Sopenharmony_ci	ushort pad;		/* Pad. */
118c2ecf20Sopenharmony_ci	ushort rx_count;
128c2ecf20Sopenharmony_ci	ushort rx_status;	/* Unknown bit assignments :-<.  */
138c2ecf20Sopenharmony_ci	ushort cur_addr;	/* Apparently the current buffer address(?) */
148c2ecf20Sopenharmony_ci};
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define PAR_DATA	0
178c2ecf20Sopenharmony_ci#define PAR_STATUS	1
188c2ecf20Sopenharmony_ci#define PAR_CONTROL 2
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define Ctrl_LNibRead	0x08	/* LP_PSELECP */
218c2ecf20Sopenharmony_ci#define Ctrl_HNibRead	0
228c2ecf20Sopenharmony_ci#define Ctrl_LNibWrite	0x08	/* LP_PSELECP */
238c2ecf20Sopenharmony_ci#define Ctrl_HNibWrite	0
248c2ecf20Sopenharmony_ci#define Ctrl_SelData	0x04	/* LP_PINITP */
258c2ecf20Sopenharmony_ci#define Ctrl_IRQEN	0x10	/* LP_PINTEN */
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define EOW	0xE0
288c2ecf20Sopenharmony_ci#define EOC	0xE0
298c2ecf20Sopenharmony_ci#define WrAddr	0x40	/* Set address of EPLC read, write register. */
308c2ecf20Sopenharmony_ci#define RdAddr	0xC0
318c2ecf20Sopenharmony_ci#define HNib	0x10
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cienum page0_regs {
348c2ecf20Sopenharmony_ci	/* The first six registers hold
358c2ecf20Sopenharmony_ci	 * the ethernet physical station address.
368c2ecf20Sopenharmony_ci	 */
378c2ecf20Sopenharmony_ci	PAR0 = 0, PAR1 = 1, PAR2 = 2, PAR3 = 3, PAR4 = 4, PAR5 = 5,
388c2ecf20Sopenharmony_ci	TxCNT0 = 6, TxCNT1 = 7,		/* The transmit byte count. */
398c2ecf20Sopenharmony_ci	TxSTAT = 8, RxSTAT = 9,		/* Tx and Rx status. */
408c2ecf20Sopenharmony_ci	ISR = 10, IMR = 11,		/* Interrupt status and mask. */
418c2ecf20Sopenharmony_ci	CMR1 = 12,			/* Command register 1. */
428c2ecf20Sopenharmony_ci	CMR2 = 13,			/* Command register 2. */
438c2ecf20Sopenharmony_ci	MODSEL = 14,		/* Mode select register. */
448c2ecf20Sopenharmony_ci	MAR = 14,			/* Memory address register (?). */
458c2ecf20Sopenharmony_ci	CMR2_h = 0x1d,
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cienum eepage_regs {
498c2ecf20Sopenharmony_ci	PROM_CMD = 6,
508c2ecf20Sopenharmony_ci	PROM_DATA = 7	/* Note that PROM_CMD is in the "high" bits. */
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define ISR_TxOK	0x01
548c2ecf20Sopenharmony_ci#define ISR_RxOK	0x04
558c2ecf20Sopenharmony_ci#define ISR_TxErr	0x02
568c2ecf20Sopenharmony_ci#define ISRh_RxErr	0x11	/* ISR, high nibble */
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define CMR1h_MUX	0x08	/* Select printer multiplexor on 8012. */
598c2ecf20Sopenharmony_ci#define CMR1h_RESET	0x04	/* Reset. */
608c2ecf20Sopenharmony_ci#define CMR1h_RxENABLE	0x02	/* Rx unit enable.  */
618c2ecf20Sopenharmony_ci#define CMR1h_TxENABLE	0x01	/* Tx unit enable.  */
628c2ecf20Sopenharmony_ci#define CMR1h_TxRxOFF	0x00
638c2ecf20Sopenharmony_ci#define CMR1_ReXmit	0x08	/* Trigger a retransmit. */
648c2ecf20Sopenharmony_ci#define CMR1_Xmit	0x04	/* Trigger a transmit. */
658c2ecf20Sopenharmony_ci#define	CMR1_IRQ	0x02	/* Interrupt active. */
668c2ecf20Sopenharmony_ci#define	CMR1_BufEnb	0x01	/* Enable the buffer(?). */
678c2ecf20Sopenharmony_ci#define	CMR1_NextPkt	0x01	/* Enable the buffer(?). */
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define CMR2_NULL	8
708c2ecf20Sopenharmony_ci#define CMR2_IRQOUT	9
718c2ecf20Sopenharmony_ci#define CMR2_RAMTEST	10
728c2ecf20Sopenharmony_ci#define CMR2_EEPROM	12	/* Set to page 1, for reading the EEPROM. */
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define CMR2h_OFF	0	/* No accept mode. */
758c2ecf20Sopenharmony_ci#define CMR2h_Physical	1	/* Accept a physical address match only. */
768c2ecf20Sopenharmony_ci#define CMR2h_Normal	2	/* Accept physical and broadcast address. */
778c2ecf20Sopenharmony_ci#define CMR2h_PROMISC	3	/* Promiscuous mode. */
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/* An inline function used below: it differs from inb() by explicitly
808c2ecf20Sopenharmony_ci * return an unsigned char, saving a truncation.
818c2ecf20Sopenharmony_ci */
828c2ecf20Sopenharmony_cistatic inline unsigned char inbyte(unsigned short port)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci	unsigned char _v;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	__asm__ __volatile__ ("inb %w1,%b0" : "=a" (_v) : "d" (port));
878c2ecf20Sopenharmony_ci	return _v;
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* Read register OFFSET.
918c2ecf20Sopenharmony_ci * This command should always be terminated with read_end().
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_cistatic inline unsigned char read_nibble(short port, unsigned char offset)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	unsigned char retval;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	outb(EOC+offset, port + PAR_DATA);
988c2ecf20Sopenharmony_ci	outb(RdAddr+offset, port + PAR_DATA);
998c2ecf20Sopenharmony_ci	inbyte(port + PAR_STATUS);	/* Settling time delay */
1008c2ecf20Sopenharmony_ci	retval = inbyte(port + PAR_STATUS);
1018c2ecf20Sopenharmony_ci	outb(EOC+offset, port + PAR_DATA);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	return retval;
1048c2ecf20Sopenharmony_ci}
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* Functions for bulk data read.  The interrupt line is always disabled. */
1078c2ecf20Sopenharmony_ci/* Get a byte using read mode 0, reading data from the control lines. */
1088c2ecf20Sopenharmony_cistatic inline unsigned char read_byte_mode0(short ioaddr)
1098c2ecf20Sopenharmony_ci{
1108c2ecf20Sopenharmony_ci	unsigned char low_nib;
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	outb(Ctrl_LNibRead, ioaddr + PAR_CONTROL);
1138c2ecf20Sopenharmony_ci	inbyte(ioaddr + PAR_STATUS);
1148c2ecf20Sopenharmony_ci	low_nib = (inbyte(ioaddr + PAR_STATUS) >> 3) & 0x0f;
1158c2ecf20Sopenharmony_ci	outb(Ctrl_HNibRead, ioaddr + PAR_CONTROL);
1168c2ecf20Sopenharmony_ci	inbyte(ioaddr + PAR_STATUS);	/* Settling time delay -- needed!  */
1178c2ecf20Sopenharmony_ci	inbyte(ioaddr + PAR_STATUS);	/* Settling time delay -- needed!  */
1188c2ecf20Sopenharmony_ci	return low_nib | ((inbyte(ioaddr + PAR_STATUS) << 1) & 0xf0);
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/* The same as read_byte_mode0(), but does multiple inb()s for stability. */
1228c2ecf20Sopenharmony_cistatic inline unsigned char read_byte_mode2(short ioaddr)
1238c2ecf20Sopenharmony_ci{
1248c2ecf20Sopenharmony_ci	unsigned char low_nib;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	outb(Ctrl_LNibRead, ioaddr + PAR_CONTROL);
1278c2ecf20Sopenharmony_ci	inbyte(ioaddr + PAR_STATUS);
1288c2ecf20Sopenharmony_ci	low_nib = (inbyte(ioaddr + PAR_STATUS) >> 3) & 0x0f;
1298c2ecf20Sopenharmony_ci	outb(Ctrl_HNibRead, ioaddr + PAR_CONTROL);
1308c2ecf20Sopenharmony_ci	inbyte(ioaddr + PAR_STATUS);	/* Settling time delay -- needed!  */
1318c2ecf20Sopenharmony_ci	return low_nib | ((inbyte(ioaddr + PAR_STATUS) << 1) & 0xf0);
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci/* Read a byte through the data register. */
1358c2ecf20Sopenharmony_cistatic inline unsigned char read_byte_mode4(short ioaddr)
1368c2ecf20Sopenharmony_ci{
1378c2ecf20Sopenharmony_ci	unsigned char low_nib;
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	outb(RdAddr | MAR, ioaddr + PAR_DATA);
1408c2ecf20Sopenharmony_ci	low_nib = (inbyte(ioaddr + PAR_STATUS) >> 3) & 0x0f;
1418c2ecf20Sopenharmony_ci	outb(RdAddr | HNib | MAR, ioaddr + PAR_DATA);
1428c2ecf20Sopenharmony_ci	return low_nib | ((inbyte(ioaddr + PAR_STATUS) << 1) & 0xf0);
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* Read a byte through the data register, double reading to allow settling. */
1468c2ecf20Sopenharmony_cistatic inline unsigned char read_byte_mode6(short ioaddr)
1478c2ecf20Sopenharmony_ci{
1488c2ecf20Sopenharmony_ci	unsigned char low_nib;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	outb(RdAddr | MAR, ioaddr + PAR_DATA);
1518c2ecf20Sopenharmony_ci	inbyte(ioaddr + PAR_STATUS);
1528c2ecf20Sopenharmony_ci	low_nib = (inbyte(ioaddr + PAR_STATUS) >> 3) & 0x0f;
1538c2ecf20Sopenharmony_ci	outb(RdAddr | HNib | MAR, ioaddr + PAR_DATA);
1548c2ecf20Sopenharmony_ci	inbyte(ioaddr + PAR_STATUS);
1558c2ecf20Sopenharmony_ci	return low_nib | ((inbyte(ioaddr + PAR_STATUS) << 1) & 0xf0);
1568c2ecf20Sopenharmony_ci}
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistatic inline void
1598c2ecf20Sopenharmony_ciwrite_reg(short port, unsigned char reg, unsigned char value)
1608c2ecf20Sopenharmony_ci{
1618c2ecf20Sopenharmony_ci	unsigned char outval;
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	outb(EOC | reg, port + PAR_DATA);
1648c2ecf20Sopenharmony_ci	outval = WrAddr | reg;
1658c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);
1668c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);	/* Double write for PS/2. */
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	outval &= 0xf0;
1698c2ecf20Sopenharmony_ci	outval |= value;
1708c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);
1718c2ecf20Sopenharmony_ci	outval &= 0x1f;
1728c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);
1738c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	outb(EOC | outval, port + PAR_DATA);
1768c2ecf20Sopenharmony_ci}
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cistatic inline void
1798c2ecf20Sopenharmony_ciwrite_reg_high(short port, unsigned char reg, unsigned char value)
1808c2ecf20Sopenharmony_ci{
1818c2ecf20Sopenharmony_ci	unsigned char outval = EOC | HNib | reg;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);
1848c2ecf20Sopenharmony_ci	outval &= WrAddr | HNib | 0x0f;
1858c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);
1868c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);	/* Double write for PS/2. */
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	outval = WrAddr | HNib | value;
1898c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);
1908c2ecf20Sopenharmony_ci	outval &= HNib | 0x0f;		/* HNib | value */
1918c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);
1928c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	outb(EOC | HNib | outval, port + PAR_DATA);
1958c2ecf20Sopenharmony_ci}
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci/* Write a byte out using nibble mode.  The low nibble is written first. */
1988c2ecf20Sopenharmony_cistatic inline void
1998c2ecf20Sopenharmony_ciwrite_reg_byte(short port, unsigned char reg, unsigned char value)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	unsigned char outval;
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	outb(EOC | reg, port + PAR_DATA); /* Reset the address register. */
2048c2ecf20Sopenharmony_ci	outval = WrAddr | reg;
2058c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);
2068c2ecf20Sopenharmony_ci	outb(outval, port + PAR_DATA);	/* Double write for PS/2. */
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	outb((outval & 0xf0) | (value & 0x0f), port + PAR_DATA);
2098c2ecf20Sopenharmony_ci	outb(value & 0x0f, port + PAR_DATA);
2108c2ecf20Sopenharmony_ci	value >>= 4;
2118c2ecf20Sopenharmony_ci	outb(value, port + PAR_DATA);
2128c2ecf20Sopenharmony_ci	outb(0x10 | value, port + PAR_DATA);
2138c2ecf20Sopenharmony_ci	outb(0x10 | value, port + PAR_DATA);
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	outb(EOC  | value, port + PAR_DATA); /* Reset the address register. */
2168c2ecf20Sopenharmony_ci}
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/* Bulk data writes to the packet buffer.  The interrupt line remains enabled.
2198c2ecf20Sopenharmony_ci * The first, faster method uses only the dataport (data modes 0, 2 & 4).
2208c2ecf20Sopenharmony_ci * The second (backup) method uses data and control regs (modes 1, 3 & 5).
2218c2ecf20Sopenharmony_ci * It should only be needed when there is skew between the individual data
2228c2ecf20Sopenharmony_ci * lines.
2238c2ecf20Sopenharmony_ci */
2248c2ecf20Sopenharmony_cistatic inline void write_byte_mode0(short ioaddr, unsigned char value)
2258c2ecf20Sopenharmony_ci{
2268c2ecf20Sopenharmony_ci	outb(value & 0x0f, ioaddr + PAR_DATA);
2278c2ecf20Sopenharmony_ci	outb((value>>4) | 0x10, ioaddr + PAR_DATA);
2288c2ecf20Sopenharmony_ci}
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_cistatic inline void write_byte_mode1(short ioaddr, unsigned char value)
2318c2ecf20Sopenharmony_ci{
2328c2ecf20Sopenharmony_ci	outb(value & 0x0f, ioaddr + PAR_DATA);
2338c2ecf20Sopenharmony_ci	outb(Ctrl_IRQEN | Ctrl_LNibWrite, ioaddr + PAR_CONTROL);
2348c2ecf20Sopenharmony_ci	outb((value>>4) | 0x10, ioaddr + PAR_DATA);
2358c2ecf20Sopenharmony_ci	outb(Ctrl_IRQEN | Ctrl_HNibWrite, ioaddr + PAR_CONTROL);
2368c2ecf20Sopenharmony_ci}
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci/* Write 16bit VALUE to the packet buffer: the same as above just doubled. */
2398c2ecf20Sopenharmony_cistatic inline void write_word_mode0(short ioaddr, unsigned short value)
2408c2ecf20Sopenharmony_ci{
2418c2ecf20Sopenharmony_ci	outb(value & 0x0f, ioaddr + PAR_DATA);
2428c2ecf20Sopenharmony_ci	value >>= 4;
2438c2ecf20Sopenharmony_ci	outb((value & 0x0f) | 0x10, ioaddr + PAR_DATA);
2448c2ecf20Sopenharmony_ci	value >>= 4;
2458c2ecf20Sopenharmony_ci	outb(value & 0x0f, ioaddr + PAR_DATA);
2468c2ecf20Sopenharmony_ci	value >>= 4;
2478c2ecf20Sopenharmony_ci	outb((value & 0x0f) | 0x10, ioaddr + PAR_DATA);
2488c2ecf20Sopenharmony_ci}
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci/*  EEPROM_Ctrl bits. */
2518c2ecf20Sopenharmony_ci#define EE_SHIFT_CLK	0x04	/* EEPROM shift clock. */
2528c2ecf20Sopenharmony_ci#define EE_CS		0x02	/* EEPROM chip select. */
2538c2ecf20Sopenharmony_ci#define EE_CLK_HIGH	0x12
2548c2ecf20Sopenharmony_ci#define EE_CLK_LOW	0x16
2558c2ecf20Sopenharmony_ci#define EE_DATA_WRITE	0x01	/* EEPROM chip data in. */
2568c2ecf20Sopenharmony_ci#define EE_DATA_READ	0x08	/* EEPROM chip data out. */
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci/* Delay between EEPROM clock transitions. */
2598c2ecf20Sopenharmony_ci#define eeprom_delay(ticks) \
2608c2ecf20Sopenharmony_cido { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; } } while (0)
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci/* The EEPROM commands include the alway-set leading bit. */
2638c2ecf20Sopenharmony_ci#define EE_WRITE_CMD(offset)	(((5 << 6) + (offset)) << 17)
2648c2ecf20Sopenharmony_ci#define EE_READ(offset)		(((6 << 6) + (offset)) << 17)
2658c2ecf20Sopenharmony_ci#define EE_ERASE(offset)	(((7 << 6) + (offset)) << 17)
2668c2ecf20Sopenharmony_ci#define EE_CMD_SIZE	27	/* The command+address+data size. */
267