iPXE
dm96xx.c File Reference

Davicom DM96xx USB Ethernet driver. More...

#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <ipxe/ethernet.h>
#include <ipxe/usb.h>
#include <ipxe/usbnet.h>
#include "dm96xx.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static int dm96xx_reset (struct dm96xx_device *dm96xx)
 Reset device.
static int dm96xx_read_mac (struct dm96xx_device *dm96xx, uint8_t *mac)
 Read MAC address.
static int dm96xx_write_mac (struct dm96xx_device *dm96xx, uint8_t *mac)
 Write MAC address.
static void dm96xx_link_nsr (struct dm96xx_device *dm96xx, unsigned int nsr)
 Update link status based on network status register.
static int dm96xx_check_link (struct dm96xx_device *dm96xx)
 Get link status.
static int dm96xx_rx_mode (struct dm96xx_device *dm96xx)
 Set DM9601-compatible RX header mode.
static void dm96xx_intr_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete interrupt transfer.
static void dm96xx_in_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk IN transfer.
static int dm96xx_out_transmit (struct dm96xx_device *dm96xx, struct io_buffer *iobuf)
 Transmit packet.
static void dm96xx_out_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk OUT transfer.
static int dm96xx_open (struct net_device *netdev)
 Open network device.
static void dm96xx_close (struct net_device *netdev)
 Close network device.
static int dm96xx_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet.
static void dm96xx_poll (struct net_device *netdev)
 Poll for completed and received packets.
static int dm96xx_probe (struct usb_function *func, struct usb_configuration_descriptor *config)
 Probe device.
static void dm96xx_remove (struct usb_function *func)
 Remove device.

Variables

static struct usb_endpoint_driver_operations dm96xx_intr_operations
 Interrupt endpoint operations.
static struct usb_endpoint_driver_operations dm96xx_in_operations
 Bulk IN endpoint operations.
static struct usb_endpoint_driver_operations dm96xx_out_operations
 Bulk OUT endpoint operations.
static struct net_device_operations dm96xx_operations
 DM96xx network device operations.
static struct usb_device_id dm96xx_ids []
 DM96xx device IDs.
struct usb_driver dm96xx_driver __usb_driver
 Davicom DM96xx driver.

Detailed Description

Davicom DM96xx USB Ethernet driver.

Definition in file dm96xx.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ dm96xx_reset()

int dm96xx_reset ( struct dm96xx_device * dm96xx)
static

Reset device.

Parameters
dm96xxDM96xx device
Return values
rcReturn status code

Definition at line 54 of file dm96xx.c.

54 {
55 int ncr;
56 int rc;
57
58 /* Reset device */
59 if ( ( rc = dm96xx_write_register ( dm96xx, DM96XX_NCR,
60 DM96XX_NCR_RST ) ) != 0 ) {
61 DBGC ( dm96xx, "DM96XX %p could not reset: %s\n",
62 dm96xx, strerror ( rc ) );
63 return rc;
64 }
65
66 /* Wait for reset to complete */
68
69 /* Check that reset has completed */
70 ncr = dm96xx_read_register ( dm96xx, DM96XX_NCR );
71 if ( ncr < 0 ) {
72 rc = ncr;
73 DBGC ( dm96xx, "DM96XX %p failed to reset: %s\n",
74 dm96xx, strerror ( rc ) );
75 return rc;
76 }
77 if ( ncr & DM96XX_NCR_RST ) {
78 DBGC ( dm96xx, "DM96XX %p failed to reset (NCR=%#02x)\n",
79 dm96xx, ncr );
80 return -EIO;
81 }
82
83 return 0;
84}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define DM96XX_NCR
Network control register.
Definition dm96xx.h:33
static int dm96xx_write_register(struct dm96xx_device *dm96xx, unsigned int offset, uint8_t value)
Write register.
Definition dm96xx.h:168
static int dm96xx_read_register(struct dm96xx_device *dm96xx, unsigned int offset)
Read register.
Definition dm96xx.h:132
#define DM96XX_NCR_RST
Software reset.
Definition dm96xx.h:34
#define DM96XX_RESET_DELAY_US
Reset delay (in microseconds)
Definition dm96xx.h:176
#define DBGC(...)
Definition compiler.h:505
#define EIO
Input/output error.
Definition errno.h:434
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition timer.c:61

References DBGC, DM96XX_NCR, DM96XX_NCR_RST, dm96xx_read_register(), DM96XX_RESET_DELAY_US, dm96xx_write_register(), EIO, rc, strerror(), and udelay().

Referenced by dm96xx_close(), and dm96xx_probe().

◆ dm96xx_read_mac()

int dm96xx_read_mac ( struct dm96xx_device * dm96xx,
uint8_t * mac )
static

Read MAC address.

Parameters
dm96xxDM96xx device
macMAC address to fill in
Return values
rcReturn status code

Definition at line 93 of file dm96xx.c.

93 {
94 int rc;
95
96 /* Read MAC address */
97 if ( ( rc = dm96xx_read_registers ( dm96xx, DM96XX_PAR, mac,
98 ETH_ALEN ) ) != 0 ) {
99 DBGC ( dm96xx, "DM96XX %p could not read MAC address: %s\n",
100 dm96xx, strerror ( rc ) );
101 return rc;
102 }
103
104 return 0;
105}
static int dm96xx_read_registers(struct dm96xx_device *dm96xx, unsigned int offset, void *data, size_t len)
Read registers.
Definition dm96xx.h:117
#define DM96XX_PAR
PHY address registers.
Definition dm96xx.h:52
uint8_t mac[ETH_ALEN]
MAC address.
Definition ena.h:13
#define ETH_ALEN
Definition if_ether.h:9

References DBGC, DM96XX_PAR, dm96xx_read_registers(), ETH_ALEN, mac, rc, and strerror().

Referenced by dm96xx_probe().

◆ dm96xx_write_mac()

int dm96xx_write_mac ( struct dm96xx_device * dm96xx,
uint8_t * mac )
static

Write MAC address.

Parameters
dm96xxDM96xx device
macMAC address
Return values
rcReturn status code

Definition at line 114 of file dm96xx.c.

114 {
115 int rc;
116
117 /* Write MAC address */
118 if ( ( rc = dm96xx_write_registers ( dm96xx, DM96XX_PAR, mac,
119 ETH_ALEN ) ) != 0 ) {
120 DBGC ( dm96xx, "DM96XX %p could not write MAC address: %s\n",
121 dm96xx, strerror ( rc ) );
122 return rc;
123 }
124
125 return 0;
126}
static int dm96xx_write_registers(struct dm96xx_device *dm96xx, unsigned int offset, void *data, size_t len)
Write registers.
Definition dm96xx.h:152

References DBGC, DM96XX_PAR, dm96xx_write_registers(), ETH_ALEN, mac, rc, and strerror().

Referenced by dm96xx_open().

◆ dm96xx_link_nsr()

void dm96xx_link_nsr ( struct dm96xx_device * dm96xx,
unsigned int nsr )
static

Update link status based on network status register.

Parameters
dm96xxDM96xx device
nsrNetwork status register

Definition at line 134 of file dm96xx.c.

134 {
135 struct net_device *netdev = dm96xx->netdev;
136
137 if ( nsr & DM96XX_NSR_LINKST ) {
138 if ( ! netdev_link_ok ( netdev ) )
140 } else {
141 if ( netdev_link_ok ( netdev ) )
143 }
144}
#define DM96XX_NSR_LINKST
Link status.
Definition dm96xx.h:38
static struct net_device * netdev
Definition gdbudp.c:53
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition netdevice.c:231
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition netdevice.h:640
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition netdevice.h:789
struct net_device * netdev
Network device.
Definition dm96xx.h:102
A network device.
Definition netdevice.h:353

References DM96XX_NSR_LINKST, dm96xx_device::netdev, netdev, netdev_link_down(), netdev_link_ok(), and netdev_link_up().

Referenced by dm96xx_check_link(), and dm96xx_intr_complete().

◆ dm96xx_check_link()

int dm96xx_check_link ( struct dm96xx_device * dm96xx)
static

Get link status.

Parameters
dm96xxDM96xx device
Return values
rcReturn status code

Definition at line 152 of file dm96xx.c.

152 {
153 int nsr;
154 int rc;
155
156 /* Read network status register */
157 nsr = dm96xx_read_register ( dm96xx, DM96XX_NSR );
158 if ( nsr < 0 ) {
159 rc = nsr;
160 DBGC ( dm96xx, "DM96XX %p could not read network status: %s\n",
161 dm96xx, strerror ( rc ) );
162 return rc;
163 }
164
165 /* Update link status */
166 dm96xx_link_nsr ( dm96xx, nsr );
167
168 return 0;
169}
static void dm96xx_link_nsr(struct dm96xx_device *dm96xx, unsigned int nsr)
Update link status based on network status register.
Definition dm96xx.c:134
#define DM96XX_NSR
Network status register.
Definition dm96xx.h:37

References DBGC, dm96xx_link_nsr(), DM96XX_NSR, dm96xx_read_register(), rc, and strerror().

Referenced by dm96xx_open(), and dm96xx_probe().

◆ dm96xx_rx_mode()

int dm96xx_rx_mode ( struct dm96xx_device * dm96xx)
static

Set DM9601-compatible RX header mode.

Parameters
dm96xxDM96xx device
Return values
rcReturn status code

Definition at line 177 of file dm96xx.c.

177 {
178 int chipr;
179 int mode_ctl;
180 int rc;
181
182 /* Get chip revision */
183 chipr = dm96xx_read_register ( dm96xx, DM96XX_CHIPR );
184 if ( chipr < 0 ) {
185 rc = chipr;
186 DBGC ( dm96xx, "DM96XX %p could not read chip revision: %s\n",
187 dm96xx, strerror ( rc ) );
188 return rc;
189 }
190
191 /* Do nothing if device is a DM9601 anyway */
192 if ( chipr == DM96XX_CHIPR_9601 )
193 return 0;
194
195 /* Read current mode control */
196 mode_ctl = dm96xx_read_register ( dm96xx, DM96XX_MODE_CTL );
197 if ( mode_ctl < 0 ) {
198 rc = mode_ctl;
199 DBGC ( dm96xx, "DM96XX %p could not read mode control: %s\n",
200 dm96xx, strerror ( rc ) );
201 return rc;
202 }
203
204 /* Write mode control */
205 mode_ctl &= ~DM96XX_MODE_CTL_MODE;
206 if ( ( rc = dm96xx_write_register ( dm96xx, DM96XX_MODE_CTL,
207 mode_ctl ) ) != 0 ) {
208 DBGC ( dm96xx, "DM96XX %p could not write mode control: %s\n",
209 dm96xx, strerror ( rc ) );
210 return rc;
211 }
212
213 return 0;
214}
#define DM96XX_CHIPR
Chip revision register.
Definition dm96xx.h:55
#define DM96XX_MODE_CTL_MODE
4-byte header mode
Definition dm96xx.h:61
#define DM96XX_CHIPR_9601
DM9601.
Definition dm96xx.h:56
#define DM96XX_MODE_CTL
RX header control/status register (DM9620+ only)
Definition dm96xx.h:60

References DBGC, DM96XX_CHIPR, DM96XX_CHIPR_9601, DM96XX_MODE_CTL, DM96XX_MODE_CTL_MODE, dm96xx_read_register(), dm96xx_write_register(), rc, and strerror().

Referenced by dm96xx_open().

◆ dm96xx_intr_complete()

void dm96xx_intr_complete ( struct usb_endpoint * ep,
struct io_buffer * iobuf,
int rc )
static

Complete interrupt transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 230 of file dm96xx.c.

231 {
232 struct dm96xx_device *dm96xx = container_of ( ep, struct dm96xx_device,
233 usbnet.intr );
234 struct net_device *netdev = dm96xx->netdev;
235 struct dm96xx_interrupt *intr;
236 size_t len = iob_len ( iobuf );
237
238 /* Ignore packets cancelled when the endpoint closes */
239 if ( ! ep->open )
240 goto done;
241
242 /* Record USB errors against the network device */
243 if ( rc != 0 ) {
244 DBGC ( dm96xx, "DM96XX %p interrupt failed: %s\n",
245 dm96xx, strerror ( rc ) );
246 DBGC_HDA ( dm96xx, 0, iobuf->data, iob_len ( iobuf ) );
248 goto done;
249 }
250
251 /* Extract message header */
252 if ( len < sizeof ( *intr ) ) {
253 DBGC ( dm96xx, "DM96XX %p underlength interrupt:\n", dm96xx );
254 DBGC_HDA ( dm96xx, 0, iobuf->data, iob_len ( iobuf ) );
256 goto done;
257 }
258 intr = iobuf->data;
259
260 /* Update link status */
261 dm96xx_link_nsr ( dm96xx, intr->nsr );
262
263 done:
264 /* Free I/O buffer */
265 free_iob ( iobuf );
266}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct bofm_section_header done
Definition bofm_test.c:46
ring len
Length.
Definition dwmac.h:226
uint8_t intr
Interrupts enabled.
Definition ena.h:3
#define DBGC_HDA(...)
Definition compiler.h:506
#define EINVAL
Invalid argument.
Definition errno.h:429
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition netdevice.c:587
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
A DM96xx network device.
Definition dm96xx.h:96
struct usbnet_device usbnet
USB network device.
Definition dm96xx.h:104
DM96xx interrupt data.
Definition dm96xx.h:64
void * data
Start of data.
Definition iobuf.h:53
int open
Endpoint is open.
Definition usb.h:419
struct usb_endpoint intr
Interrupt endpoint.
Definition usbnet.h:28

References container_of, io_buffer::data, DBGC, DBGC_HDA, dm96xx_link_nsr(), done, EINVAL, free_iob(), intr, usbnet_device::intr, iob_len(), len, dm96xx_device::netdev, netdev, netdev_rx_err(), NULL, usb_endpoint::open, rc, strerror(), and dm96xx_device::usbnet.

◆ dm96xx_in_complete()

void dm96xx_in_complete ( struct usb_endpoint * ep,
struct io_buffer * iobuf,
int rc )
static

Complete bulk IN transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 280 of file dm96xx.c.

281 {
282 struct dm96xx_device *dm96xx = container_of ( ep, struct dm96xx_device,
283 usbnet.in );
284 struct net_device *netdev = dm96xx->netdev;
285 struct dm96xx_rx_header *header;
286
287 /* Ignore packets cancelled when the endpoint closes */
288 if ( ! ep->open ) {
289 free_iob ( iobuf );
290 return;
291 }
292
293 /* Record USB errors against the network device */
294 if ( rc != 0 ) {
295 DBGC ( dm96xx, "DM96XX %p bulk IN failed: %s\n",
296 dm96xx, strerror ( rc ) );
297 goto err;
298 }
299
300 /* Sanity check */
301 if ( iob_len ( iobuf ) < ( sizeof ( *header ) + 4 /* CRC */ ) ) {
302 DBGC ( dm96xx, "DM96XX %p underlength bulk IN\n", dm96xx );
303 DBGC_HDA ( dm96xx, 0, iobuf->data, iob_len ( iobuf ) );
304 rc = -EINVAL;
305 goto err;
306 }
307
308 /* Strip header and CRC */
309 header = iobuf->data;
310 iob_pull ( iobuf, sizeof ( *header ) );
311 iob_unput ( iobuf, 4 /* CRC */ );
312
313 /* Check status */
314 if ( header->rsr & ~DM96XX_RSR_MF ) {
315 DBGC ( dm96xx, "DM96XX %p receive error %02x:\n",
316 dm96xx, header->rsr );
317 DBGC_HDA ( dm96xx, 0, iobuf->data, iob_len ( iobuf ) );
318 rc = -EIO;
319 goto err;
320 }
321
322 /* Hand off to network stack */
323 netdev_rx ( netdev, iob_disown ( iobuf ) );
324 return;
325
326 err:
327 /* Hand off to network stack */
328 netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
329}
#define DM96XX_RSR_MF
Multicast frame.
Definition dm96xx.h:49
struct ena_llq_option header
Header locations.
Definition ena.h:5
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition iobuf.h:217
#define iob_pull(iobuf, len)
Definition iobuf.h:107
#define iob_unput(iobuf, len)
Definition iobuf.h:140
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition netdevice.c:549
DM96xx receive header.
Definition dm96xx.h:82
struct usb_endpoint in
Bulk IN endpoint.
Definition usbnet.h:30

References container_of, io_buffer::data, DBGC, DBGC_HDA, DM96XX_RSR_MF, EINVAL, EIO, free_iob(), header, usbnet_device::in, iob_disown, iob_len(), iob_pull, iob_unput, dm96xx_device::netdev, netdev, netdev_rx(), netdev_rx_err(), usb_endpoint::open, rc, strerror(), and dm96xx_device::usbnet.

◆ dm96xx_out_transmit()

int dm96xx_out_transmit ( struct dm96xx_device * dm96xx,
struct io_buffer * iobuf )
static

Transmit packet.

Parameters
dm96xxDM96xx device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 343 of file dm96xx.c.

344 {
345 struct dm96xx_tx_header *header;
346 size_t len = iob_len ( iobuf );
347 int rc;
348
349 /* Prepend header */
350 if ( ( rc = iob_ensure_headroom ( iobuf, sizeof ( *header ) ) ) != 0 )
351 return rc;
352 header = iob_push ( iobuf, sizeof ( *header ) );
353 header->len = cpu_to_le16 ( len );
354
355 /* Enqueue I/O buffer */
356 if ( ( rc = usb_stream ( &dm96xx->usbnet.out, iobuf, 0 ) ) != 0 )
357 return rc;
358
359 return 0;
360}
#define cpu_to_le16(value)
Definition byteswap.h:107
int iob_ensure_headroom(struct io_buffer *iobuf, size_t len)
Ensure I/O buffer has sufficient headroom.
Definition iobuf.c:235
#define iob_push(iobuf, len)
Definition iobuf.h:89
DM96xx transmit header.
Definition dm96xx.h:90
struct usb_endpoint out
Bulk OUT endpoint.
Definition usbnet.h:32
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition usb.c:546

References cpu_to_le16, header, iob_ensure_headroom(), iob_len(), iob_push, len, usbnet_device::out, rc, usb_stream(), and dm96xx_device::usbnet.

Referenced by dm96xx_transmit().

◆ dm96xx_out_complete()

void dm96xx_out_complete ( struct usb_endpoint * ep,
struct io_buffer * iobuf,
int rc )
static

Complete bulk OUT transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 369 of file dm96xx.c.

370 {
371 struct dm96xx_device *dm96xx = container_of ( ep, struct dm96xx_device,
372 usbnet.out );
373 struct net_device *netdev = dm96xx->netdev;
374
375 /* Report TX completion */
376 netdev_tx_complete_err ( netdev, iobuf, rc );
377}
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition netdevice.c:471

References container_of, dm96xx_device::netdev, netdev, netdev_tx_complete_err(), usbnet_device::out, rc, and dm96xx_device::usbnet.

◆ dm96xx_open()

int dm96xx_open ( struct net_device * netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 397 of file dm96xx.c.

397 {
398 struct dm96xx_device *dm96xx = netdev->priv;
399 unsigned int rcr;
400 int rc;
401
402 /* Set DM9601-compatible RX header mode */
403 if ( ( rc = dm96xx_rx_mode ( dm96xx ) ) != 0 )
404 goto err_rx_mode;
405
406 /* Write MAC address */
407 if ( ( rc = dm96xx_write_mac ( dm96xx, netdev->ll_addr ) ) != 0 )
408 goto err_write_mac;
409
410 /* Open USB network device */
411 if ( ( rc = usbnet_open ( &dm96xx->usbnet ) ) != 0 ) {
412 DBGC ( dm96xx, "DM96XX %p could not open: %s\n",
413 dm96xx, strerror ( rc ) );
414 goto err_open;
415 }
416
417 /* Set receive filters */
420 if ( ( rc = dm96xx_write_register ( dm96xx, DM96XX_RCR, rcr ) ) != 0 ) {
421 DBGC ( dm96xx, "DM96XX %p could not write receive filters: "
422 "%s\n", dm96xx, strerror ( rc ) );
423 goto err_write_rcr;
424 }
425
426 /* Update link status */
427 if ( ( rc = dm96xx_check_link ( dm96xx ) ) != 0 )
428 goto err_check_link;
429
430 return 0;
431
432 err_check_link:
433 err_write_rcr:
434 usbnet_close ( &dm96xx->usbnet );
435 err_open:
436 err_write_mac:
437 err_rx_mode:
438 return rc;
439}
static int dm96xx_rx_mode(struct dm96xx_device *dm96xx)
Set DM9601-compatible RX header mode.
Definition dm96xx.c:177
static int dm96xx_write_mac(struct dm96xx_device *dm96xx, uint8_t *mac)
Write MAC address.
Definition dm96xx.c:114
static int dm96xx_check_link(struct dm96xx_device *dm96xx)
Get link status.
Definition dm96xx.c:152
#define DM96XX_RCR_RXEN
RX enable.
Definition dm96xx.h:45
#define DM96XX_RCR
Receive control register.
Definition dm96xx.h:41
#define DM96XX_RCR_RUNT
Pass runt packet.
Definition dm96xx.h:43
#define DM96XX_RCR_PRMSC
Promiscuous mode.
Definition dm96xx.h:44
#define DM96XX_RCR_ALL
Pass all multicast.
Definition dm96xx.h:42
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition usbnet.c:55
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition usbnet.c:128

References DBGC, dm96xx_check_link(), DM96XX_RCR, DM96XX_RCR_ALL, DM96XX_RCR_PRMSC, DM96XX_RCR_RUNT, DM96XX_RCR_RXEN, dm96xx_rx_mode(), dm96xx_write_mac(), dm96xx_write_register(), netdev, rc, strerror(), dm96xx_device::usbnet, usbnet_close(), and usbnet_open().

◆ dm96xx_close()

void dm96xx_close ( struct net_device * netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 446 of file dm96xx.c.

446 {
447 struct dm96xx_device *dm96xx = netdev->priv;
448
449 /* Close USB network device */
450 usbnet_close ( &dm96xx->usbnet );
451
452 /* Reset device */
453 dm96xx_reset ( dm96xx );
454}
static int dm96xx_reset(struct dm96xx_device *dm96xx)
Reset device.
Definition dm96xx.c:54

References dm96xx_reset(), netdev, dm96xx_device::usbnet, and usbnet_close().

◆ dm96xx_transmit()

int dm96xx_transmit ( struct net_device * netdev,
struct io_buffer * iobuf )
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 463 of file dm96xx.c.

464 {
465 struct dm96xx_device *dm96xx = netdev->priv;
466 int rc;
467
468 /* Transmit packet */
469 if ( ( rc = dm96xx_out_transmit ( dm96xx, iobuf ) ) != 0 )
470 return rc;
471
472 return 0;
473}
static int dm96xx_out_transmit(struct dm96xx_device *dm96xx, struct io_buffer *iobuf)
Transmit packet.
Definition dm96xx.c:343

References dm96xx_out_transmit(), netdev, and rc.

◆ dm96xx_poll()

void dm96xx_poll ( struct net_device * netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 480 of file dm96xx.c.

480 {
481 struct dm96xx_device *dm96xx = netdev->priv;
482 int rc;
483
484 /* Poll USB bus */
485 usb_poll ( dm96xx->bus );
486
487 /* Refill endpoints */
488 if ( ( rc = usbnet_refill ( &dm96xx->usbnet ) ) != 0 )
490}
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition usb.h:1072
struct usb_bus * bus
USB bus.
Definition dm96xx.h:100
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition usbnet.c:152

References dm96xx_device::bus, netdev, netdev_rx_err(), NULL, rc, usb_poll(), dm96xx_device::usbnet, and usbnet_refill().

◆ dm96xx_probe()

int dm96xx_probe ( struct usb_function * func,
struct usb_configuration_descriptor * config )
static

Probe device.

Parameters
funcUSB function
configConfiguration descriptor
Return values
rcReturn status code

Definition at line 514 of file dm96xx.c.

515 {
516 struct usb_device *usb = func->usb;
517 struct net_device *netdev;
518 struct dm96xx_device *dm96xx;
519 int rc;
520
521 /* Allocate and initialise structure */
522 netdev = alloc_etherdev ( sizeof ( *dm96xx ) );
523 if ( ! netdev ) {
524 rc = -ENOMEM;
525 goto err_alloc;
526 }
528 netdev->dev = &func->dev;
529 dm96xx = netdev->priv;
530 memset ( dm96xx, 0, sizeof ( *dm96xx ) );
531 dm96xx->usb = usb;
532 dm96xx->bus = usb->port->hub->bus;
533 dm96xx->netdev = netdev;
534 usbnet_init ( &dm96xx->usbnet, func, &dm96xx_intr_operations,
537 usb_refill_init ( &dm96xx->usbnet.in, 0, DM96XX_IN_MTU,
539 DBGC ( dm96xx, "DM96XX %p on %s\n", dm96xx, func->name );
540
541 /* Describe USB network device */
542 if ( ( rc = usbnet_describe ( &dm96xx->usbnet, config ) ) != 0 ) {
543 DBGC ( dm96xx, "DM96XX %p could not describe: %s\n",
544 dm96xx, strerror ( rc ) );
545 goto err_describe;
546 }
547
548 /* Reset device */
549 if ( ( rc = dm96xx_reset ( dm96xx ) ) != 0 )
550 goto err_reset;
551
552 /* Read MAC address */
553 if ( ( rc = dm96xx_read_mac ( dm96xx, netdev->hw_addr ) ) != 0 )
554 goto err_read_mac;
555
556 /* Get initial link status */
557 if ( ( rc = dm96xx_check_link ( dm96xx ) ) != 0 )
558 goto err_check_link;
559
560 /* Register network device */
561 if ( ( rc = register_netdev ( netdev ) ) != 0 )
562 goto err_register;
563
565 return 0;
566
568 err_register:
569 err_check_link:
570 err_read_mac:
571 err_reset:
572 err_describe:
574 netdev_put ( netdev );
575 err_alloc:
576 return rc;
577}
static struct net_device_operations dm96xx_operations
DM96xx network device operations.
Definition dm96xx.c:493
static int dm96xx_read_mac(struct dm96xx_device *dm96xx, uint8_t *mac)
Read MAC address.
Definition dm96xx.c:93
static struct usb_endpoint_driver_operations dm96xx_intr_operations
Interrupt endpoint operations.
Definition dm96xx.c:269
static struct usb_endpoint_driver_operations dm96xx_in_operations
Bulk IN endpoint operations.
Definition dm96xx.c:332
static struct usb_endpoint_driver_operations dm96xx_out_operations
Bulk OUT endpoint operations.
Definition dm96xx.c:380
#define DM96XX_IN_MTU
Bulk IN buffer size.
Definition dm96xx.h:191
#define DM96XX_IN_MAX_FILL
Bulk IN maximum fill level.
Definition dm96xx.h:188
#define DM96XX_INTR_MAX_FILL
Interrupt maximum fill level.
Definition dm96xx.h:182
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:265
#define ENOMEM
Not enough space.
Definition errno.h:535
static void usb_refill_init(struct usb_endpoint *ep, size_t reserve, size_t len, unsigned int max)
Initialise USB endpoint refill.
Definition usb.h:617
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition usb.h:707
void * memset(void *dest, int character, size_t len) __nonnull
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:942
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:519
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:532
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
struct usb_device * usb
USB device.
Definition dm96xx.h:98
A USB device.
Definition usb.h:723
struct usb_port * port
USB port.
Definition usb.h:727
struct usb_device * usb
USB device.
Definition usb.h:678
struct device dev
Generic device.
Definition usb.h:682
const char * name
Name.
Definition usb.h:676
struct usb_bus * bus
USB bus.
Definition usb.h:845
struct usb_hub * hub
USB hub.
Definition usb.h:815
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition usbnet.c:278
static void usbnet_init(struct usbnet_device *usbnet, struct usb_function *func, struct usb_endpoint_driver_operations *intr, struct usb_endpoint_driver_operations *in, struct usb_endpoint_driver_operations *out)
Initialise USB network device.
Definition usbnet.h:45

References alloc_etherdev(), dm96xx_device::bus, usb_hub::bus, DBGC, usb_function::dev, dm96xx_check_link(), DM96XX_IN_MAX_FILL, DM96XX_IN_MTU, dm96xx_in_operations, DM96XX_INTR_MAX_FILL, dm96xx_intr_operations, dm96xx_operations, dm96xx_out_operations, dm96xx_read_mac(), dm96xx_reset(), ENOMEM, usb_port::hub, usbnet_device::in, usbnet_device::intr, memset(), usb_function::name, dm96xx_device::netdev, netdev, netdev_init(), netdev_nullify(), netdev_put(), usb_device::port, rc, register_netdev(), strerror(), unregister_netdev(), dm96xx_device::usb, usb_function::usb, usb_func_set_drvdata(), usb_refill_init(), dm96xx_device::usbnet, usbnet_describe(), and usbnet_init().

◆ dm96xx_remove()

void dm96xx_remove ( struct usb_function * func)
static

Remove device.

Parameters
funcUSB function

Definition at line 584 of file dm96xx.c.

584 {
585 struct net_device *netdev = usb_func_get_drvdata ( func );
586
589 netdev_put ( netdev );
590}
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition usb.h:718

References netdev, netdev_nullify(), netdev_put(), unregister_netdev(), and usb_func_get_drvdata().

Variable Documentation

◆ dm96xx_intr_operations

struct usb_endpoint_driver_operations dm96xx_intr_operations
static
Initial value:
= {
.complete = dm96xx_intr_complete,
}
static void dm96xx_intr_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete interrupt transfer.
Definition dm96xx.c:230

Interrupt endpoint operations.

Definition at line 269 of file dm96xx.c.

269 {
270 .complete = dm96xx_intr_complete,
271};

Referenced by dm96xx_probe().

◆ dm96xx_in_operations

struct usb_endpoint_driver_operations dm96xx_in_operations
static
Initial value:
= {
.complete = dm96xx_in_complete,
}
static void dm96xx_in_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk IN transfer.
Definition dm96xx.c:280

Bulk IN endpoint operations.

Definition at line 332 of file dm96xx.c.

332 {
333 .complete = dm96xx_in_complete,
334};

Referenced by dm96xx_probe().

◆ dm96xx_out_operations

struct usb_endpoint_driver_operations dm96xx_out_operations
static
Initial value:
= {
.complete = dm96xx_out_complete,
}
static void dm96xx_out_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk OUT transfer.
Definition dm96xx.c:369

Bulk OUT endpoint operations.

Definition at line 380 of file dm96xx.c.

380 {
381 .complete = dm96xx_out_complete,
382};

Referenced by dm96xx_probe().

◆ dm96xx_operations

struct net_device_operations dm96xx_operations
static
Initial value:
= {
.open = dm96xx_open,
.close = dm96xx_close,
.transmit = dm96xx_transmit,
.poll = dm96xx_poll,
}
static int dm96xx_open(struct net_device *netdev)
Open network device.
Definition dm96xx.c:397
static int dm96xx_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition dm96xx.c:463
static void dm96xx_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition dm96xx.c:480
static void dm96xx_close(struct net_device *netdev)
Close network device.
Definition dm96xx.c:446

DM96xx network device operations.

Definition at line 493 of file dm96xx.c.

493 {
494 .open = dm96xx_open,
495 .close = dm96xx_close,
496 .transmit = dm96xx_transmit,
497 .poll = dm96xx_poll,
498};

Referenced by dm96xx_probe().

◆ dm96xx_ids

struct usb_device_id dm96xx_ids[]
static
Initial value:
= {
USB_ROM ( 0x07aa, 0x9601, "dm9601-corega", "Corega FEther", 0 ),
USB_ROM ( 0x0a46, 0x9601, "dm9601", "DM9601", 0 ),
USB_ROM ( 0x0a46, 0x6688, "zt6688", "ZT6688", 0 ),
USB_ROM ( 0x0a46, 0x0268, "st268", "ST268", 0 ),
USB_ROM ( 0x0a46, 0x8515, "adm8515", "ADMtek ADM8515", 0 ),
USB_ROM ( 0x0a47, 0x9601, "dm9601-hirose", "DM9601 (Hirose)", 0 ),
USB_ROM ( 0x0fe6, 0x8101, "dm9601-8101", "DM9601 (ICS8101)", 0 ),
USB_ROM ( 0x0fe6, 0x9700, "dm9601-9700", "DM9601 (ICS9700)", 0 ),
USB_ROM ( 0x0a46, 0x9000, "dm9000e", "DM9000E", 0 ),
USB_ROM ( 0x0a46, 0x9620, "dm9620", "DM9620", 0 ),
USB_ROM ( 0x0a46, 0x9621, "dm9621A", "DM9621A", 0 ),
USB_ROM ( 0x0a46, 0x9622, "dm9622", "DM9622", 0 ),
USB_ROM ( 0x0a46, 0x0269, "dm962Oa", "DM9620A", 0 ),
USB_ROM ( 0x0a46, 0x1269, "dm9621a", "DM9621A", 0 ),
}
#define USB_ROM(_vendor, _product, _name, _description, _data)
Definition usb.h:1381

DM96xx device IDs.

Definition at line 593 of file dm96xx.c.

593 {
594 USB_ROM ( 0x07aa, 0x9601, "dm9601-corega", "Corega FEther", 0 ),
595 USB_ROM ( 0x0a46, 0x9601, "dm9601", "DM9601", 0 ),
596 USB_ROM ( 0x0a46, 0x6688, "zt6688", "ZT6688", 0 ),
597 USB_ROM ( 0x0a46, 0x0268, "st268", "ST268", 0 ),
598 USB_ROM ( 0x0a46, 0x8515, "adm8515", "ADMtek ADM8515", 0 ),
599 USB_ROM ( 0x0a47, 0x9601, "dm9601-hirose", "DM9601 (Hirose)", 0 ),
600 USB_ROM ( 0x0fe6, 0x8101, "dm9601-8101", "DM9601 (ICS8101)", 0 ),
601 USB_ROM ( 0x0fe6, 0x9700, "dm9601-9700", "DM9601 (ICS9700)", 0 ),
602 USB_ROM ( 0x0a46, 0x9000, "dm9000e", "DM9000E", 0 ),
603 USB_ROM ( 0x0a46, 0x9620, "dm9620", "DM9620", 0 ),
604 USB_ROM ( 0x0a46, 0x9621, "dm9621A", "DM9621A", 0 ),
605 USB_ROM ( 0x0a46, 0x9622, "dm9622", "DM9622", 0 ),
606 USB_ROM ( 0x0a46, 0x0269, "dm962Oa", "DM9620A", 0 ),
607 USB_ROM ( 0x0a46, 0x1269, "dm9621a", "DM9621A", 0 ),
608};

◆ __usb_driver

struct usb_driver dm96xx_driver __usb_driver
Initial value:
= {
.ids = dm96xx_ids,
.id_count = ( sizeof ( dm96xx_ids ) / sizeof ( dm96xx_ids[0] ) ),
.score = USB_SCORE_NORMAL,
.probe = dm96xx_probe,
.remove = dm96xx_remove,
}
static struct usb_device_id dm96xx_ids[]
DM96xx device IDs.
Definition dm96xx.c:593
static int dm96xx_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition dm96xx.c:514
static void dm96xx_remove(struct usb_function *func)
Remove device.
Definition dm96xx.c:584
#define USB_ANY_ID
Match-anything ID.
Definition usb.h:1385
#define USB_CLASS_ID(base, subclass, protocol)
Construct USB class ID.
Definition usb.h:1401
@ USB_SCORE_NORMAL
Normal driver.
Definition usb.h:1465

Davicom DM96xx driver.

Definition at line 611 of file dm96xx.c.

611 {
612 .ids = dm96xx_ids,
613 .id_count = ( sizeof ( dm96xx_ids ) / sizeof ( dm96xx_ids[0] ) ),
615 .score = USB_SCORE_NORMAL,
616 .probe = dm96xx_probe,
617 .remove = dm96xx_remove,
618};