iPXE
dm96xx.h
Go to the documentation of this file.
1 #ifndef _DM96XX_H
2 #define _DM96XX_H
3 
4 /** @file
5  *
6  * Davicom DM96xx USB Ethernet driver
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <ipxe/usb.h>
13 #include <ipxe/usbnet.h>
14 #include <ipxe/if_ether.h>
15 
16 /** Read register(s) */
17 #define DM96XX_READ_REGISTER \
18  ( USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
19  USB_REQUEST_TYPE ( 0x00 ) )
20 
21 /** Write register(s) */
22 #define DM96XX_WRITE_REGISTER \
23  ( USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
24  USB_REQUEST_TYPE ( 0x01 ) )
25 
26 /** Write single register */
27 #define DM96XX_WRITE1_REGISTER \
28  ( USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE | \
29  USB_REQUEST_TYPE ( 0x03 ) )
30 
31 /** Network control register */
32 #define DM96XX_NCR 0x00
33 #define DM96XX_NCR_RST 0x01 /**< Software reset */
34 
35 /** Network status register */
36 #define DM96XX_NSR 0x01
37 #define DM96XX_NSR_LINKST 0x40 /**< Link status */
38 
39 /** Receive control register */
40 #define DM96XX_RCR 0x05
41 #define DM96XX_RCR_ALL 0x08 /**< Pass all multicast */
42 #define DM96XX_RCR_RUNT 0x04 /**< Pass runt packet */
43 #define DM96XX_RCR_PRMSC 0x02 /**< Promiscuous mode */
44 #define DM96XX_RCR_RXEN 0x01 /**< RX enable */
45 
46 /** Receive status register */
47 #define DM96XX_RSR 0x06
48 #define DM96XX_RSR_MF 0x40 /**< Multicast frame */
49 
50 /** PHY address registers */
51 #define DM96XX_PAR 0x10
52 
53 /** Chip revision register */
54 #define DM96XX_CHIPR 0x2c
55 #define DM96XX_CHIPR_9601 0x00 /**< DM9601 */
56 #define DM96XX_CHIPR_9620 0x01 /**< DM9620 */
57 
58 /** RX header control/status register (DM9620+ only) */
59 #define DM96XX_MODE_CTL 0x91
60 #define DM96XX_MODE_CTL_MODE 0x80 /**< 4-byte header mode */
61 
62 /** DM96xx interrupt data */
64  /** Network status register */
66  /** Transmit status registers */
68  /** Receive status register */
70  /** Receive overflow counter register */
72  /** Receive packet counter */
74  /** Transmit packet counter */
76  /** General purpose register */
78 } __attribute__ (( packed ));
79 
80 /** DM96xx receive header */
82  /** Packet status */
84  /** Packet length (excluding this header, including CRC) */
86 } __attribute__ (( packed ));
87 
88 /** DM96xx transmit header */
90  /** Packet length (excluding this header) */
92 } __attribute__ (( packed ));
93 
94 /** A DM96xx network device */
95 struct dm96xx_device {
96  /** USB device */
97  struct usb_device *usb;
98  /** USB bus */
99  struct usb_bus *bus;
100  /** Network device */
102  /** USB network device */
104 };
105 
106 /**
107  * Read registers
108  *
109  * @v dm96xx DM96xx device
110  * @v offset Register offset
111  * @v data Data buffer
112  * @v len Length of data
113  * @ret rc Return status code
114  */
115 static inline __attribute__ (( always_inline )) int
116 dm96xx_read_registers ( struct dm96xx_device *dm96xx, unsigned int offset,
117  void *data, size_t len ) {
118 
119  return usb_control ( dm96xx->usb, DM96XX_READ_REGISTER, 0, offset,
120  data, len );
121 }
122 
123 /**
124  * Read register
125  *
126  * @v dm96xx DM96xx device
127  * @v offset Register offset
128  * @ret value Register value, or negative error
129  */
130 static inline __attribute__ (( always_inline )) int
131 dm96xx_read_register ( struct dm96xx_device *dm96xx, unsigned int offset ) {
132  uint8_t value;
133  int rc;
134 
135  if ( ( rc = dm96xx_read_registers ( dm96xx, offset, &value,
136  sizeof ( value ) ) ) != 0 )
137  return rc;
138  return value;
139 }
140 
141 /**
142  * Write registers
143  *
144  * @v dm96xx DM96xx device
145  * @v offset Register offset
146  * @v data Data buffer
147  * @v len Length of data
148  * @ret rc Return status code
149  */
150 static inline __attribute__ (( always_inline )) int
151 dm96xx_write_registers ( struct dm96xx_device *dm96xx, unsigned int offset,
152  void *data, size_t len ) {
153 
154  return usb_control ( dm96xx->usb, DM96XX_WRITE_REGISTER, 0, offset,
155  data, len );
156 }
157 
158 /**
159  * Write register
160  *
161  * @v dm96xx DM96xx device
162  * @v offset Register offset
163  * @v value Register value
164  * @ret rc Return status code
165  */
166 static inline __attribute__ (( always_inline )) int
167 dm96xx_write_register ( struct dm96xx_device *dm96xx, unsigned int offset,
168  uint8_t value ) {
169 
170  return usb_control ( dm96xx->usb, DM96XX_WRITE1_REGISTER, value,
171  offset, NULL, 0 );
172 }
173 
174 /** Reset delay (in microseconds) */
175 #define DM96XX_RESET_DELAY_US 10
176 
177 /** Interrupt maximum fill level
178  *
179  * This is a policy decision.
180  */
181 #define DM96XX_INTR_MAX_FILL 2
182 
183 /** Bulk IN maximum fill level
184  *
185  * This is a policy decision.
186  */
187 #define DM96XX_IN_MAX_FILL 8
188 
189 /** Bulk IN buffer size */
190 #define DM96XX_IN_MTU \
191  ( 4 /* DM96xx header */ + ETH_FRAME_LEN + \
192  4 /* possible VLAN header */ + 4 /* CRC */ )
193 
194 #endif /* _DM96XX_H */
#define __attribute__(x)
Definition: compiler.h:10
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
static int dm96xx_write_registers(struct dm96xx_device *dm96xx, unsigned int offset, void *data, size_t len)
Write registers.
Definition: dm96xx.h:151
struct usb_device * usb
USB device.
Definition: dm96xx.h:97
struct usb_bus * bus
USB bus.
Definition: dm96xx.h:99
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition: usb.c:753
uint8_t rocr
Receive overflow counter register.
Definition: dm96xx.h:71
uint8_t tsr[2]
Transmit status registers.
Definition: dm96xx.h:67
DM96xx interrupt data.
Definition: dm96xx.h:63
uint16_t len
Packet length (excluding this header)
Definition: dm96xx.h:91
static int dm96xx_read_register(struct dm96xx_device *dm96xx, unsigned int offset)
Read register.
Definition: dm96xx.h:131
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
A USB device.
Definition: usb.h:706
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static int dm96xx_write_register(struct dm96xx_device *dm96xx, unsigned int offset, uint8_t value)
Write register.
Definition: dm96xx.h:167
A USB network device.
Definition: usbnet.h:15
A network device.
Definition: netdevice.h:348
unsigned char uint8_t
Definition: stdint.h:10
#define DM96XX_WRITE_REGISTER
Write register(s)
Definition: dm96xx.h:22
uint8_t txc
Transmit packet counter.
Definition: dm96xx.h:75
uint8_t rsr
Receive status register.
Definition: dm96xx.h:69
DM96xx receive header.
Definition: dm96xx.h:81
USB network devices.
struct net_device * netdev
Network device.
Definition: dm96xx.h:101
uint32_t len
Length.
Definition: ena.h:14
DM96xx transmit header.
Definition: dm96xx.h:89
Universal Serial Bus (USB)
#define DM96XX_READ_REGISTER
Read register(s)
Definition: dm96xx.h:17
A DM96xx network device.
Definition: dm96xx.h:95
uint8_t rxc
Receive packet counter.
Definition: dm96xx.h:73
uint8_t rsr
Packet status.
Definition: dm96xx.h:83
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint8_t gpr
General purpose register.
Definition: dm96xx.h:77
#define DM96XX_WRITE1_REGISTER
Write single register.
Definition: dm96xx.h:27
uint8_t nsr
Network status register.
Definition: dm96xx.h:65
uint16_t len
Packet length (excluding this header, including CRC)
Definition: dm96xx.h:85
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A USB bus.
Definition: usb.h:949
struct usbnet_device usbnet
USB network device.
Definition: dm96xx.h:103
static int dm96xx_read_registers(struct dm96xx_device *dm96xx, unsigned int offset, void *data, size_t len)
Read registers.
Definition: dm96xx.h:116