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

Variables

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

Detailed Description

Davicom DM96xx USB Ethernet driver.

Definition in file dm96xx.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ dm96xx_reset()

static int dm96xx_reset ( struct dm96xx_device dm96xx)
static

Reset device.

Parameters
dm96xxDM96xx device
Return values
rcReturn status code

Definition at line 53 of file dm96xx.c.

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

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()

static 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 92 of file dm96xx.c.

92  {
93  int rc;
94 
95  /* Read MAC address */
96  if ( ( rc = dm96xx_read_registers ( dm96xx, DM96XX_PAR, mac,
97  ETH_ALEN ) ) != 0 ) {
98  DBGC ( dm96xx, "DM96XX %p could not read MAC address: %s\n",
99  dm96xx, strerror ( rc ) );
100  return rc;
101  }
102 
103  return 0;
104 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DM96XX_PAR
PHY address registers.
Definition: dm96xx.h:51
#define DBGC(...)
Definition: compiler.h:505
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define ETH_ALEN
Definition: if_ether.h:8
static int dm96xx_read_registers(struct dm96xx_device *dm96xx, unsigned int offset, void *data, size_t len)
Read registers.
Definition: dm96xx.h:116

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

Referenced by dm96xx_probe().

◆ dm96xx_write_mac()

static 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 113 of file dm96xx.c.

113  {
114  int rc;
115 
116  /* Write MAC address */
117  if ( ( rc = dm96xx_write_registers ( dm96xx, DM96XX_PAR, mac,
118  ETH_ALEN ) ) != 0 ) {
119  DBGC ( dm96xx, "DM96XX %p could not write MAC address: %s\n",
120  dm96xx, strerror ( rc ) );
121  return rc;
122  }
123 
124  return 0;
125 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DM96XX_PAR
PHY address registers.
Definition: dm96xx.h:51
static int dm96xx_write_registers(struct dm96xx_device *dm96xx, unsigned int offset, void *data, size_t len)
Write registers.
Definition: dm96xx.h:151
#define DBGC(...)
Definition: compiler.h:505
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define ETH_ALEN
Definition: if_ether.h:8

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

Referenced by dm96xx_open().

◆ dm96xx_link_nsr()

static 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 133 of file dm96xx.c.

133  {
134  struct net_device *netdev = dm96xx->netdev;
135 
136  if ( nsr & DM96XX_NSR_LINKST ) {
137  if ( ! netdev_link_ok ( netdev ) )
139  } else {
140  if ( netdev_link_ok ( netdev ) )
142  }
143 }
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:630
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:348
#define DM96XX_NSR_LINKST
Link status.
Definition: dm96xx.h:37
struct net_device * netdev
Network device.
Definition: dm96xx.h:101

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

Referenced by dm96xx_check_link(), and dm96xx_intr_complete().

◆ dm96xx_check_link()

static int dm96xx_check_link ( struct dm96xx_device dm96xx)
static

Get link status.

Parameters
dm96xxDM96xx device
Return values
rcReturn status code

Definition at line 151 of file dm96xx.c.

151  {
152  int nsr;
153  int rc;
154 
155  /* Read network status register */
156  nsr = dm96xx_read_register ( dm96xx, DM96XX_NSR );
157  if ( nsr < 0 ) {
158  rc = nsr;
159  DBGC ( dm96xx, "DM96XX %p could not read network status: %s\n",
160  dm96xx, strerror ( rc ) );
161  return rc;
162  }
163 
164  /* Update link status */
165  dm96xx_link_nsr ( dm96xx, nsr );
166 
167  return 0;
168 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static int dm96xx_read_register(struct dm96xx_device *dm96xx, unsigned int offset)
Read register.
Definition: dm96xx.h:131
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void dm96xx_link_nsr(struct dm96xx_device *dm96xx, unsigned int nsr)
Update link status based on network status register.
Definition: dm96xx.c:133
#define DM96XX_NSR
Network status register.
Definition: dm96xx.h:36

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

Referenced by dm96xx_open(), and dm96xx_probe().

◆ dm96xx_rx_mode()

static 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 176 of file dm96xx.c.

176  {
177  int chipr;
178  int mode_ctl;
179  int rc;
180 
181  /* Get chip revision */
182  chipr = dm96xx_read_register ( dm96xx, DM96XX_CHIPR );
183  if ( chipr < 0 ) {
184  rc = chipr;
185  DBGC ( dm96xx, "DM96XX %p could not read chip revision: %s\n",
186  dm96xx, strerror ( rc ) );
187  return rc;
188  }
189 
190  /* Do nothing if device is a DM9601 anyway */
191  if ( chipr == DM96XX_CHIPR_9601 )
192  return 0;
193 
194  /* Read current mode control */
195  mode_ctl = dm96xx_read_register ( dm96xx, DM96XX_MODE_CTL );
196  if ( mode_ctl < 0 ) {
197  rc = mode_ctl;
198  DBGC ( dm96xx, "DM96XX %p could not read mode control: %s\n",
199  dm96xx, strerror ( rc ) );
200  return rc;
201  }
202 
203  /* Write mode control */
204  mode_ctl &= ~DM96XX_MODE_CTL_MODE;
205  if ( ( rc = dm96xx_write_register ( dm96xx, DM96XX_MODE_CTL,
206  mode_ctl ) ) != 0 ) {
207  DBGC ( dm96xx, "DM96XX %p could not write mode control: %s\n",
208  dm96xx, strerror ( rc ) );
209  return rc;
210  }
211 
212  return 0;
213 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DM96XX_MODE_CTL_MODE
4-byte header mode
Definition: dm96xx.h:60
#define DBGC(...)
Definition: compiler.h:505
#define DM96XX_MODE_CTL
RX header control/status register (DM9620+ only)
Definition: dm96xx.h:59
static int dm96xx_read_register(struct dm96xx_device *dm96xx, unsigned int offset)
Read register.
Definition: dm96xx.h:131
#define DM96XX_CHIPR_9601
DM9601.
Definition: dm96xx.h:55
static int dm96xx_write_register(struct dm96xx_device *dm96xx, unsigned int offset, uint8_t value)
Write register.
Definition: dm96xx.h:167
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define DM96XX_CHIPR
Chip revision register.
Definition: dm96xx.h:54

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()

static 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 229 of file dm96xx.c.

230  {
231  struct dm96xx_device *dm96xx = container_of ( ep, struct dm96xx_device,
232  usbnet.intr );
233  struct net_device *netdev = dm96xx->netdev;
234  struct dm96xx_interrupt *intr;
235  size_t len = iob_len ( iobuf );
236 
237  /* Ignore packets cancelled when the endpoint closes */
238  if ( ! ep->open )
239  goto done;
240 
241  /* Record USB errors against the network device */
242  if ( rc != 0 ) {
243  DBGC ( dm96xx, "DM96XX %p interrupt failed: %s\n",
244  dm96xx, strerror ( rc ) );
245  DBGC_HDA ( dm96xx, 0, iobuf->data, iob_len ( iobuf ) );
246  netdev_rx_err ( netdev, NULL, rc );
247  goto done;
248  }
249 
250  /* Extract message header */
251  if ( len < sizeof ( *intr ) ) {
252  DBGC ( dm96xx, "DM96XX %p underlength interrupt:\n", dm96xx );
253  DBGC_HDA ( dm96xx, 0, iobuf->data, iob_len ( iobuf ) );
255  goto done;
256  }
257  intr = iobuf->data;
258 
259  /* Update link status */
260  dm96xx_link_nsr ( dm96xx, intr->nsr );
261 
262  done:
263  /* Free I/O buffer */
264  free_iob ( iobuf );
265 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:404
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:27
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
#define DBGC_HDA(...)
Definition: compiler.h:506
DM96xx interrupt data.
Definition: dm96xx.h:63
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
A network device.
Definition: netdevice.h:348
struct net_device * netdev
Network device.
Definition: dm96xx.h:101
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:44
A DM96xx network device.
Definition: dm96xx.h:95
static void dm96xx_link_nsr(struct dm96xx_device *dm96xx, unsigned int nsr)
Update link status based on network status register.
Definition: dm96xx.c:133
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct usbnet_device usbnet
USB network device.
Definition: dm96xx.h:103
struct bofm_section_header done
Definition: bofm_test.c:46

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

◆ dm96xx_in_complete()

static 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 279 of file dm96xx.c.

280  {
281  struct dm96xx_device *dm96xx = container_of ( ep, struct dm96xx_device,
282  usbnet.in );
283  struct net_device *netdev = dm96xx->netdev;
284  struct dm96xx_rx_header *header;
285 
286  /* Ignore packets cancelled when the endpoint closes */
287  if ( ! ep->open ) {
288  free_iob ( iobuf );
289  return;
290  }
291 
292  /* Record USB errors against the network device */
293  if ( rc != 0 ) {
294  DBGC ( dm96xx, "DM96XX %p bulk IN failed: %s\n",
295  dm96xx, strerror ( rc ) );
296  goto err;
297  }
298 
299  /* Sanity check */
300  if ( iob_len ( iobuf ) < ( sizeof ( *header ) + 4 /* CRC */ ) ) {
301  DBGC ( dm96xx, "DM96XX %p underlength bulk IN\n", dm96xx );
302  DBGC_HDA ( dm96xx, 0, iobuf->data, iob_len ( iobuf ) );
303  rc = -EINVAL;
304  goto err;
305  }
306 
307  /* Strip header and CRC */
308  header = iobuf->data;
309  iob_pull ( iobuf, sizeof ( *header ) );
310  iob_unput ( iobuf, 4 /* CRC */ );
311 
312  /* Check status */
313  if ( header->rsr & ~DM96XX_RSR_MF ) {
314  DBGC ( dm96xx, "DM96XX %p receive error %02x:\n",
315  dm96xx, header->rsr );
316  DBGC_HDA ( dm96xx, 0, iobuf->data, iob_len ( iobuf ) );
317  rc = -EIO;
318  goto err;
319  }
320 
321  /* Hand off to network stack */
322  netdev_rx ( netdev, iob_disown ( iobuf ) );
323  return;
324 
325  err:
326  /* Hand off to network stack */
327  netdev_rx_err ( netdev, iob_disown ( iobuf ), rc );
328 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:98
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:404
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:208
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define DBGC_HDA(...)
Definition: compiler.h:506
static struct net_device * netdev
Definition: gdbudp.c:52
#define iob_unput(iobuf, len)
Definition: iobuf.h:131
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
A network device.
Definition: netdevice.h:348
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
#define DM96XX_RSR_MF
Multicast frame.
Definition: dm96xx.h:48
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
DM96xx receive header.
Definition: dm96xx.h:81
struct net_device * netdev
Network device.
Definition: dm96xx.h:101
void * data
Start of data.
Definition: iobuf.h:44
#define EIO
Input/output error.
Definition: errno.h:433
struct ena_aq_header header
Header.
Definition: ena.h:12
A DM96xx network device.
Definition: dm96xx.h:95
struct usbnet_device usbnet
USB network device.
Definition: dm96xx.h:103

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, netdev, dm96xx_device::netdev, netdev_rx(), netdev_rx_err(), usb_endpoint::open, rc, strerror(), and dm96xx_device::usbnet.

◆ dm96xx_out_transmit()

static 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 342 of file dm96xx.c.

343  {
344  struct dm96xx_tx_header *header;
345  size_t len = iob_len ( iobuf );
346  int rc;
347 
348  /* Prepend header */
349  if ( ( rc = iob_ensure_headroom ( iobuf, sizeof ( *header ) ) ) != 0 )
350  return rc;
351  header = iob_push ( iobuf, sizeof ( *header ) );
352  header->len = cpu_to_le16 ( len );
353 
354  /* Enqueue I/O buffer */
355  if ( ( rc = usb_stream ( &dm96xx->usbnet.out, iobuf, 0 ) ) != 0 )
356  return rc;
357 
358  return 0;
359 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_push(iobuf, len)
Definition: iobuf.h:80
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:528
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
uint32_t len
Length.
Definition: ena.h:14
DM96xx transmit header.
Definition: dm96xx.h:89
struct ena_aq_header header
Header.
Definition: ena.h:12
#define cpu_to_le16(value)
Definition: byteswap.h:106
int iob_ensure_headroom(struct io_buffer *iobuf, size_t len)
Ensure I/O buffer has sufficient headroom.
Definition: iobuf.c:183
struct usbnet_device usbnet
USB network device.
Definition: dm96xx.h:103

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()

static 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 368 of file dm96xx.c.

369  {
370  struct dm96xx_device *dm96xx = container_of ( ep, struct dm96xx_device,
371  usbnet.out );
372  struct net_device *netdev = dm96xx->netdev;
373 
374  /* Report TX completion */
375  netdev_tx_complete_err ( netdev, iobuf, rc );
376 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:348
struct net_device * netdev
Network device.
Definition: dm96xx.h:101
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:395
A DM96xx network device.
Definition: dm96xx.h:95
struct usbnet_device usbnet
USB network device.
Definition: dm96xx.h:103

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

◆ dm96xx_open()

static int dm96xx_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 396 of file dm96xx.c.

396  {
397  struct dm96xx_device *dm96xx = netdev->priv;
398  unsigned int rcr;
399  int rc;
400 
401  /* Set DM9601-compatible RX header mode */
402  if ( ( rc = dm96xx_rx_mode ( dm96xx ) ) != 0 )
403  goto err_rx_mode;
404 
405  /* Write MAC address */
406  if ( ( rc = dm96xx_write_mac ( dm96xx, netdev->ll_addr ) ) != 0 )
407  goto err_write_mac;
408 
409  /* Open USB network device */
410  if ( ( rc = usbnet_open ( &dm96xx->usbnet ) ) != 0 ) {
411  DBGC ( dm96xx, "DM96XX %p could not open: %s\n",
412  dm96xx, strerror ( rc ) );
413  goto err_open;
414  }
415 
416  /* Set receive filters */
418  DM96XX_RCR_RXEN );
419  if ( ( rc = dm96xx_write_register ( dm96xx, DM96XX_RCR, rcr ) ) != 0 ) {
420  DBGC ( dm96xx, "DM96XX %p could not write receive filters: "
421  "%s\n", dm96xx, strerror ( rc ) );
422  goto err_write_rcr;
423  }
424 
425  /* Update link status */
426  if ( ( rc = dm96xx_check_link ( dm96xx ) ) != 0 )
427  goto err_check_link;
428 
429  return 0;
430 
431  err_check_link:
432  err_write_rcr:
433  usbnet_close ( &dm96xx->usbnet );
434  err_open:
435  err_write_mac:
436  err_rx_mode:
437  return rc;
438 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
#define DM96XX_RCR
Receive control register.
Definition: dm96xx.h:40
static int dm96xx_check_link(struct dm96xx_device *dm96xx)
Get link status.
Definition: dm96xx.c:151
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
static int dm96xx_write_register(struct dm96xx_device *dm96xx, unsigned int offset, uint8_t value)
Write register.
Definition: dm96xx.h:167
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static int dm96xx_rx_mode(struct dm96xx_device *dm96xx)
Set DM9601-compatible RX header mode.
Definition: dm96xx.c:176
#define DM96XX_RCR_RXEN
RX enable.
Definition: dm96xx.h:44
#define DM96XX_RCR_RUNT
Pass runt packet.
Definition: dm96xx.h:42
#define DM96XX_RCR_PRMSC
Promiscuous mode.
Definition: dm96xx.h:43
static int dm96xx_write_mac(struct dm96xx_device *dm96xx, uint8_t *mac)
Write MAC address.
Definition: dm96xx.c:113
A DM96xx network device.
Definition: dm96xx.h:95
#define DM96XX_RCR_ALL
Pass all multicast.
Definition: dm96xx.h:41
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127
struct usbnet_device usbnet
USB network device.
Definition: dm96xx.h:103
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition: usbnet.c:54

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(), net_device::ll_addr, netdev, net_device::priv, rc, strerror(), dm96xx_device::usbnet, usbnet_close(), and usbnet_open().

◆ dm96xx_close()

static void dm96xx_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 445 of file dm96xx.c.

445  {
446  struct dm96xx_device *dm96xx = netdev->priv;
447 
448  /* Close USB network device */
449  usbnet_close ( &dm96xx->usbnet );
450 
451  /* Reset device */
452  dm96xx_reset ( dm96xx );
453 }
void * priv
Driver private data.
Definition: netdevice.h:425
static int dm96xx_reset(struct dm96xx_device *dm96xx)
Reset device.
Definition: dm96xx.c:53
static struct net_device * netdev
Definition: gdbudp.c:52
A DM96xx network device.
Definition: dm96xx.h:95
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127
struct usbnet_device usbnet
USB network device.
Definition: dm96xx.h:103

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

◆ dm96xx_transmit()

static 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 462 of file dm96xx.c.

463  {
464  struct dm96xx_device *dm96xx = netdev->priv;
465  int rc;
466 
467  /* Transmit packet */
468  if ( ( rc = dm96xx_out_transmit ( dm96xx, iobuf ) ) != 0 )
469  return rc;
470 
471  return 0;
472 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int dm96xx_out_transmit(struct dm96xx_device *dm96xx, struct io_buffer *iobuf)
Transmit packet.
Definition: dm96xx.c:342
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
A DM96xx network device.
Definition: dm96xx.h:95

References dm96xx_out_transmit(), netdev, net_device::priv, and rc.

◆ dm96xx_poll()

static void dm96xx_poll ( struct net_device netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 479 of file dm96xx.c.

479  {
480  struct dm96xx_device *dm96xx = netdev->priv;
481  int rc;
482 
483  /* Poll USB bus */
484  usb_poll ( dm96xx->bus );
485 
486  /* Refill endpoints */
487  if ( ( rc = usbnet_refill ( &dm96xx->usbnet ) ) != 0 )
488  netdev_rx_err ( netdev, NULL, rc );
489 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
struct usb_bus * bus
USB bus.
Definition: dm96xx.h:99
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition: usbnet.c:151
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1049
A DM96xx network device.
Definition: dm96xx.h:95
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct usbnet_device usbnet
USB network device.
Definition: dm96xx.h:103

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

◆ dm96xx_probe()

static 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 513 of file dm96xx.c.

514  {
515  struct usb_device *usb = func->usb;
516  struct net_device *netdev;
517  struct dm96xx_device *dm96xx;
518  int rc;
519 
520  /* Allocate and initialise structure */
521  netdev = alloc_etherdev ( sizeof ( *dm96xx ) );
522  if ( ! netdev ) {
523  rc = -ENOMEM;
524  goto err_alloc;
525  }
527  netdev->dev = &func->dev;
528  dm96xx = netdev->priv;
529  memset ( dm96xx, 0, sizeof ( *dm96xx ) );
530  dm96xx->usb = usb;
531  dm96xx->bus = usb->port->hub->bus;
532  dm96xx->netdev = netdev;
533  usbnet_init ( &dm96xx->usbnet, func, &dm96xx_intr_operations,
535  usb_refill_init ( &dm96xx->usbnet.intr, 0, 0, DM96XX_INTR_MAX_FILL );
536  usb_refill_init ( &dm96xx->usbnet.in, 0, DM96XX_IN_MTU,
538  DBGC ( dm96xx, "DM96XX %p on %s\n", dm96xx, func->name );
539 
540  /* Describe USB network device */
541  if ( ( rc = usbnet_describe ( &dm96xx->usbnet, config ) ) != 0 ) {
542  DBGC ( dm96xx, "DM96XX %p could not describe: %s\n",
543  dm96xx, strerror ( rc ) );
544  goto err_describe;
545  }
546 
547  /* Reset device */
548  if ( ( rc = dm96xx_reset ( dm96xx ) ) != 0 )
549  goto err_reset;
550 
551  /* Read MAC address */
552  if ( ( rc = dm96xx_read_mac ( dm96xx, netdev->hw_addr ) ) != 0 )
553  goto err_read_mac;
554 
555  /* Get initial link status */
556  if ( ( rc = dm96xx_check_link ( dm96xx ) ) != 0 )
557  goto err_check_link;
558 
559  /* Register network device */
560  if ( ( rc = register_netdev ( netdev ) ) != 0 )
561  goto err_register;
562 
563  usb_func_set_drvdata ( func, netdev );
564  return 0;
565 
567  err_register:
568  err_check_link:
569  err_read_mac:
570  err_reset:
571  err_describe:
573  netdev_put ( netdev );
574  err_alloc:
575  return rc;
576 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Name.
Definition: usb.h:659
static struct usb_endpoint_driver_operations dm96xx_in_operations
Bulk IN endpoint operations.
Definition: dm96xx.c:331
#define DBGC(...)
Definition: compiler.h:505
#define DM96XX_INTR_MAX_FILL
Interrupt maximum fill level.
Definition: dm96xx.h:181
struct usb_device * usb
USB device.
Definition: dm96xx.h:97
struct usb_bus * bus
USB bus.
Definition: dm96xx.h:99
static int dm96xx_check_link(struct dm96xx_device *dm96xx)
Get link status.
Definition: dm96xx.c:151
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:27
static int dm96xx_read_mac(struct dm96xx_device *dm96xx, uint8_t *mac)
Read MAC address.
Definition: dm96xx.c:92
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct usb_port * port
USB port.
Definition: usb.h:710
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
void * priv
Driver private data.
Definition: netdevice.h:425
static struct usb_endpoint_driver_operations dm96xx_intr_operations
Interrupt endpoint operations.
Definition: dm96xx.c:268
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:601
static int dm96xx_reset(struct dm96xx_device *dm96xx)
Reset device.
Definition: dm96xx.c:53
static struct net_device * netdev
Definition: gdbudp.c:52
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition: usb.h:690
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
A USB device.
Definition: usb.h:706
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static struct net_device_operations dm96xx_operations
DM96xx network device operations.
Definition: dm96xx.c:492
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
A network device.
Definition: netdevice.h:348
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
struct usb_device * usb
USB device.
Definition: usb.h:661
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
struct net_device * netdev
Network device.
Definition: dm96xx.h:101
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:44
struct usb_hub * hub
USB hub.
Definition: usb.h:798
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
A DM96xx network device.
Definition: dm96xx.h:95
#define DM96XX_IN_MAX_FILL
Bulk IN maximum fill level.
Definition: dm96xx.h:187
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition: usbnet.c:277
struct device dev
Generic device.
Definition: usb.h:665
struct usb_bus * bus
USB bus.
Definition: usb.h:828
#define DM96XX_IN_MTU
Bulk IN buffer size.
Definition: dm96xx.h:190
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
static struct usb_endpoint_driver_operations dm96xx_out_operations
Bulk OUT endpoint operations.
Definition: dm96xx.c:379
struct usbnet_device usbnet
USB network device.
Definition: dm96xx.h:103
void * memset(void *dest, int character, size_t len) __nonnull

References alloc_etherdev(), dm96xx_device::bus, usb_hub::bus, DBGC, net_device::dev, 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, net_device::hw_addr, usbnet_device::in, usbnet_device::intr, memset(), usb_function::name, netdev, dm96xx_device::netdev, netdev_init(), netdev_nullify(), netdev_put(), usb_device::port, net_device::priv, 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()

static void dm96xx_remove ( struct usb_function func)
static

Remove device.

Parameters
funcUSB function

Definition at line 583 of file dm96xx.c.

583  {
584  struct net_device *netdev = usb_func_get_drvdata ( func );
585 
588  netdev_put ( netdev );
589 }
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition: usb.h:701
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
A network device.
Definition: netdevice.h:348
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511

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:229

Interrupt endpoint operations.

Definition at line 268 of file dm96xx.c.

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:279

Bulk IN endpoint operations.

Definition at line 331 of file dm96xx.c.

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:368

Bulk OUT endpoint operations.

Definition at line 379 of file dm96xx.c.

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 void dm96xx_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: dm96xx.c:479
static int dm96xx_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: dm96xx.c:462
static int dm96xx_open(struct net_device *netdev)
Open network device.
Definition: dm96xx.c:396
static void dm96xx_close(struct net_device *netdev)
Close network device.
Definition: dm96xx.c:445

DM96xx network device operations.

Definition at line 492 of file dm96xx.c.

Referenced by dm96xx_probe().

◆ dm96xx_ids

struct usb_device_id dm96xx_ids[]
static

DM96xx device IDs.

Definition at line 592 of file dm96xx.c.

◆ __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 void dm96xx_remove(struct usb_function *func)
Remove device.
Definition: dm96xx.c:583
static int dm96xx_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition: dm96xx.c:513
#define USB_CLASS_ID(base, subclass, protocol)
Construct USB class ID.
Definition: usb.h:1345
Normal driver.
Definition: usb.h:1406
static struct usb_device_id dm96xx_ids[]
DM96xx device IDs.
Definition: dm96xx.c:592
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1329

Davicom DM96xx driver.

Definition at line 666 of file dm96xx.c.