iPXE
Macros | Functions | Variables
velocity.c File Reference

VIA Velocity network driver. More...

#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/mii.h>
#include "velocity.h"

Go to the source code of this file.

Macros

#define velocity_setbit(_reg, _mask)   writeb ( readb ( _reg ) | _mask, _reg )
 
#define virt_to_le32bus(x)   ( cpu_to_le32 ( virt_to_bus ( x ) ) )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
static int velocity_autopoll_stop (struct velocity_nic *vlc)
 Stop MII auto-polling. More...
 
static int velocity_autopoll_start (struct velocity_nic *vlc)
 Start MII auto-polling. More...
 
static int velocity_mii_read (struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg)
 Read from MII register. More...
 
static int velocity_mii_write (struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg, unsigned int data)
 Write to MII register. More...
 
static void velocity_set_link (struct velocity_nic *vlc)
 Set Link speed. More...
 
static int velocity_reload_eeprom (struct velocity_nic *vlc)
 Reload eeprom contents. More...
 
static int velocity_reset (struct velocity_nic *vlc)
 Reset hardware. More...
 
static void velocity_check_link (struct net_device *netdev)
 Check link state. More...
 
static int velocity_alloc_rings (struct velocity_nic *vlc)
 Allocate descriptor rings. More...
 
static void velocity_refill_rx (struct velocity_nic *vlc)
 Refill receive descriptor ring. More...
 
static int velocity_open (struct net_device *netdev)
 Open network device. More...
 
static void velocity_close (struct net_device *netdev)
 Close network device. More...
 
static int velocity_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void velocity_poll_rx (struct velocity_nic *vlc)
 Poll for received packets. More...
 
static void velocity_poll_tx (struct velocity_nic *vlc)
 Poll for completed packets. More...
 
static void velocity_poll (struct net_device *netdev)
 Poll for completed and received packets. More...
 
static void velocity_irq (struct net_device *netdev, int enable)
 Enable or disable interrupts. More...
 
static int velocity_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void velocity_remove (struct pci_device *pci)
 Remove PCI device. More...
 

Variables

static struct mii_operations velocity_mii_operations
 Velocity MII operations. More...
 
static struct net_device_operations velocity_operations
 Velocity network device operations. More...
 
static struct pci_device_id velocity_nics []
 Velocity PCI device IDs. More...
 
struct pci_driver velocity_driver __pci_driver
 Velocity PCI driver. More...
 

Detailed Description

VIA Velocity network driver.

Definition in file velocity.c.

Macro Definition Documentation

◆ velocity_setbit

#define velocity_setbit (   _reg,
  _mask 
)    writeb ( readb ( _reg ) | _mask, _reg )

Definition at line 36 of file velocity.c.

◆ virt_to_le32bus

#define virt_to_le32bus (   x)    ( cpu_to_le32 ( virt_to_bus ( x ) ) )

Definition at line 37 of file velocity.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ velocity_autopoll_stop()

static int velocity_autopoll_stop ( struct velocity_nic vlc)
static

Stop MII auto-polling.

Parameters
vlcVelocity device
Return values
rcReturn status code

Definition at line 58 of file velocity.c.

58  {
60 
61  /* Disable MII auto polling */
62  writeb ( 0, vlc->regs + VELOCITY_MIICR );
63 
64  /* Wait for disabling to take effect */
65  while ( timeout-- ) {
66  udelay ( 1 );
67  if ( readb ( vlc->regs + VELOCITY_MIISR ) &
69  return 0;
70  }
71 
72  DBGC ( vlc, "MII autopoll stop timeout\n" );
73  return -ETIMEDOUT;
74 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define VELOCITY_TIMEOUT_US
Default timeout.
Definition: velocity.h:16
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
#define VELOCITY_MIISR
Definition: velocity.h:282
#define VELOCITY_MIISR_IDLE
Definition: velocity.h:283
#define VELOCITY_MIICR
Definition: velocity.h:287
void timeout(int)
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
void * regs
Registers.
Definition: velocity.h:327

References DBGC, ETIMEDOUT, readb(), velocity_nic::regs, timeout(), udelay(), VELOCITY_MIICR, VELOCITY_MIISR, VELOCITY_MIISR_IDLE, VELOCITY_TIMEOUT_US, and writeb().

Referenced by velocity_mii_read(), and velocity_mii_write().

◆ velocity_autopoll_start()

static int velocity_autopoll_start ( struct velocity_nic vlc)
static

Start MII auto-polling.

Parameters
vlcVelocity device
Return values
rcReturn status code

Definition at line 82 of file velocity.c.

82  {
84 
85  /* Enable MII auto polling */
87 
88  /* Wait for enabling to take effect */
89  while ( timeout-- ) {
90  udelay ( 1 );
91  if ( ( readb ( vlc->regs + VELOCITY_MIISR ) &
92  VELOCITY_MIISR_IDLE ) == 0 )
93  return 0;
94  }
95 
96  DBGC ( vlc, "MII autopoll start timeout\n" );
97  return -ETIMEDOUT;
98 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define VELOCITY_TIMEOUT_US
Default timeout.
Definition: velocity.h:16
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
#define VELOCITY_MIISR
Definition: velocity.h:282
#define VELOCITY_MIISR_IDLE
Definition: velocity.h:283
#define VELOCITY_MIICR
Definition: velocity.h:287
#define VELOCITY_MIICR_MAUTO
Definition: velocity.h:288
void timeout(int)
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
void * regs
Registers.
Definition: velocity.h:327

References DBGC, ETIMEDOUT, readb(), velocity_nic::regs, timeout(), udelay(), VELOCITY_MIICR, VELOCITY_MIICR_MAUTO, VELOCITY_MIISR, VELOCITY_MIISR_IDLE, VELOCITY_TIMEOUT_US, and writeb().

Referenced by velocity_check_link(), velocity_mii_read(), velocity_mii_write(), and velocity_open().

◆ velocity_mii_read()

static int velocity_mii_read ( struct mii_interface mdio,
unsigned int phy  __unused,
unsigned int  reg 
)
static

Read from MII register.

Parameters
mdioMII interface
phyPHY address
regRegister address
Return values
valueData read, or negative error

Definition at line 108 of file velocity.c.

109  {
110  struct velocity_nic *vlc =
111  container_of ( mdio, struct velocity_nic, mdio );
113  int result;
114 
115  DBGC2 ( vlc, "VELOCITY %p MII read reg %d\n", vlc, reg );
116 
117  /* Disable autopolling before we can access MII */
118  velocity_autopoll_stop ( vlc );
119 
120  /* Send read command and address */
121  writeb ( reg, vlc->regs + VELOCITY_MIIADDR );
123 
124  /* Wait for read to complete */
125  while ( timeout-- ) {
126  udelay ( 1 );
127  if ( ( readb ( vlc->regs + VELOCITY_MIICR ) &
128  VELOCITY_MIICR_RCMD ) == 0 ) {
129  result = readw ( vlc->regs + VELOCITY_MIIDATA );
130  velocity_autopoll_start ( vlc );
131  return result;
132  }
133  }
134 
135  /* Restart autopolling */
136  velocity_autopoll_start ( vlc );
137 
138  DBGC ( vlc, "MII read timeout\n" );
139  return -ETIMEDOUT;
140 }
#define VELOCITY_MIIADDR
Definition: velocity.h:297
#define velocity_setbit(_reg, _mask)
Definition: velocity.c:36
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
uint16_t readw(volatile uint16_t *io_addr)
Read 16-bit word from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define VELOCITY_MIIDATA
Definition: velocity.h:298
static int velocity_autopoll_stop(struct velocity_nic *vlc)
Stop MII auto-polling.
Definition: velocity.c:58
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define VELOCITY_TIMEOUT_US
Default timeout.
Definition: velocity.h:16
int result
Definition: bigint.h:148
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
A Velocity network card.
Definition: velocity.h:325
static unsigned int unsigned int reg
Definition: intel.h:245
#define VELOCITY_MIICR
Definition: velocity.h:287
#define DBGC2(...)
Definition: compiler.h:522
void timeout(int)
struct mii_interface mdio
MII interface.
Definition: velocity.h:329
static int velocity_autopoll_start(struct velocity_nic *vlc)
Start MII auto-polling.
Definition: velocity.c:82
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
#define VELOCITY_MIICR_RCMD
Definition: velocity.h:289
void * regs
Registers.
Definition: velocity.h:327

References container_of, DBGC, DBGC2, ETIMEDOUT, velocity_nic::mdio, readb(), readw(), reg, velocity_nic::regs, result, timeout(), udelay(), velocity_autopoll_start(), velocity_autopoll_stop(), VELOCITY_MIIADDR, VELOCITY_MIICR, VELOCITY_MIICR_RCMD, VELOCITY_MIIDATA, velocity_setbit, VELOCITY_TIMEOUT_US, and writeb().

◆ velocity_mii_write()

static int velocity_mii_write ( struct mii_interface mdio,
unsigned int phy  __unused,
unsigned int  reg,
unsigned int  data 
)
static

Write to MII register.

Parameters
mdioMII interface
phyPHY address
regRegister address
dataData to write
Return values
rcReturn status code

Definition at line 151 of file velocity.c.

153  {
154  struct velocity_nic *vlc =
155  container_of ( mdio, struct velocity_nic, mdio );
157 
158  DBGC2 ( vlc, "VELOCITY %p MII write reg %d data 0x%04x\n",
159  vlc, reg, data );
160 
161  /* Disable autopolling before we can access MII */
162  velocity_autopoll_stop ( vlc );
163 
164  /* Send write command, data and destination register */
165  writeb ( reg, vlc->regs + VELOCITY_MIIADDR );
166  writew ( data, vlc->regs + VELOCITY_MIIDATA );
168 
169  /* Wait for write to complete */
170  while ( timeout-- ) {
171  udelay ( 1 );
172  if ( ( readb ( vlc->regs + VELOCITY_MIICR ) &
173  VELOCITY_MIICR_WCMD ) == 0 ) {
174  velocity_autopoll_start ( vlc );
175  return 0;
176  }
177  }
178 
179  /* Restart autopolling */
180  velocity_autopoll_start ( vlc );
181 
182  DBGC ( vlc, "MII write timeout\n" );
183  return -ETIMEDOUT;
184 }
#define VELOCITY_MIIADDR
Definition: velocity.h:297
#define velocity_setbit(_reg, _mask)
Definition: velocity.c:36
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define VELOCITY_MIIDATA
Definition: velocity.h:298
static int velocity_autopoll_stop(struct velocity_nic *vlc)
Stop MII auto-polling.
Definition: velocity.c:58
#define VELOCITY_MIICR_WCMD
Definition: velocity.h:290
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define VELOCITY_TIMEOUT_US
Default timeout.
Definition: velocity.h:16
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
A Velocity network card.
Definition: velocity.h:325
static unsigned int unsigned int reg
Definition: intel.h:245
#define VELOCITY_MIICR
Definition: velocity.h:287
#define DBGC2(...)
Definition: compiler.h:522
#define writew
Definition: w89c840.c:159
void timeout(int)
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
struct mii_interface mdio
MII interface.
Definition: velocity.h:329
static int velocity_autopoll_start(struct velocity_nic *vlc)
Start MII auto-polling.
Definition: velocity.c:82
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
void * regs
Registers.
Definition: velocity.h:327

References container_of, data, DBGC, DBGC2, ETIMEDOUT, velocity_nic::mdio, readb(), reg, velocity_nic::regs, timeout(), udelay(), velocity_autopoll_start(), velocity_autopoll_stop(), VELOCITY_MIIADDR, VELOCITY_MIICR, VELOCITY_MIICR_WCMD, VELOCITY_MIIDATA, velocity_setbit, VELOCITY_TIMEOUT_US, writeb(), and writew.

◆ velocity_set_link()

static void velocity_set_link ( struct velocity_nic vlc)
static

Set Link speed.

Parameters
vlcVelocity device

Definition at line 197 of file velocity.c.

197  {
198  int tmp;
199 
200  /* Advertise 1000MBit */
201  tmp = mii_read ( &vlc->mii, MII_CTRL1000 );
203  mii_write ( &vlc->mii, MII_CTRL1000, tmp );
204 
205  /* Enable GBit operation in MII Control Register */
206  tmp = mii_read ( &vlc->mii, MII_BMCR );
207  tmp |= BMCR_SPEED1000;
208  mii_write ( &vlc->mii, MII_BMCR, tmp );
209 }
#define ADVERTISE_1000FULL
Definition: mii.h:131
#define BMCR_SPEED1000
Definition: mii.h:41
#define MII_CTRL1000
Definition: mii.h:24
uint8_t * tmp
Definition: entropy.h:156
#define MII_BMCR
Definition: atl1e.h:871
#define ADVERTISE_1000HALF
Definition: mii.h:132
struct mii_device mii
MII device.
Definition: velocity.h:331
static int mii_read(int phy_id, int location)
Definition: epic100.c:499
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:104

References ADVERTISE_1000FULL, ADVERTISE_1000HALF, BMCR_SPEED1000, velocity_nic::mii, MII_BMCR, MII_CTRL1000, mii_read(), mii_write(), and tmp.

Referenced by velocity_probe().

◆ velocity_reload_eeprom()

static int velocity_reload_eeprom ( struct velocity_nic vlc)
static

Reload eeprom contents.

Parameters
vlcVelocity device

Definition at line 223 of file velocity.c.

223  {
225 
226  /* Initiate reload */
228 
229  /* Wait for reload to complete */
230  while ( timeout-- ) {
231  udelay ( 1 );
232  if ( ( readb ( vlc->regs + VELOCITY_EECSR ) &
233  VELOCITY_EECSR_RELOAD ) == 0 )
234  return 0;
235  }
236 
237  DBGC ( vlc, "VELOCITY %p EEPROM reload timeout\n", vlc );
238  return -ETIMEDOUT;
239 }
#define velocity_setbit(_reg, _mask)
Definition: velocity.c:36
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define VELOCITY_EECSR
Definition: velocity.h:318
#define DBGC(...)
Definition: compiler.h:505
#define VELOCITY_TIMEOUT_US
Default timeout.
Definition: velocity.h:16
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
#define VELOCITY_EECSR_RELOAD
Definition: velocity.h:319
void timeout(int)
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
void * regs
Registers.
Definition: velocity.h:327

References DBGC, ETIMEDOUT, readb(), velocity_nic::regs, timeout(), udelay(), VELOCITY_EECSR, VELOCITY_EECSR_RELOAD, velocity_setbit, and VELOCITY_TIMEOUT_US.

Referenced by velocity_probe().

◆ velocity_reset()

static int velocity_reset ( struct velocity_nic vlc)
static

Reset hardware.

Parameters
vlcVelocity device
Return values
rcReturn status code

Definition at line 247 of file velocity.c.

247  {
249  uint8_t tmp;
250 
251  DBGC ( vlc, "VELOCITY %p reset\n", vlc );
252 
253  /* clear sticky Power state bits */
254  tmp = readb ( vlc->regs + VELOCITY_STICKY );
256  writeb ( tmp, vlc->regs + VELOCITY_STICKY );
257 
258  /* clear PACPI, which might have been enabled by the EEPROM reload */
259  tmp = readb ( vlc->regs + VELOCITY_CFGA );
261  writeb ( tmp, vlc->regs + VELOCITY_CFGA );
262 
264 
265  /* Wait for reset to complete */
266  while ( timeout-- ) {
267  udelay ( 1 );
268  if ( ( readb ( vlc->regs + VELOCITY_CRS1 ) &
269  VELOCITY_CR1_SFRST ) == 0 )
270  return 0;
271  }
272 
273  return -EINVAL;
274 }
#define velocity_setbit(_reg, _mask)
Definition: velocity.c:36
#define EINVAL
Invalid argument.
Definition: errno.h:428
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define VELOCITY_CR1_SFRST
Definition: velocity.h:134
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define VELOCITY_STICKY_DS1
Definition: velocity.h:314
#define VELOCITY_CRS1
Command register 1 (set)
Definition: velocity.h:133
#define VELOCITY_TIMEOUT_US
Default timeout.
Definition: velocity.h:16
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
uint8_t * tmp
Definition: entropy.h:156
unsigned char uint8_t
Definition: stdint.h:10
#define VELOCITY_STICKY
Power Management Sticky Register.
Definition: velocity.h:312
#define VELOCITY_CFGA_PACPI
Definition: velocity.h:309
void timeout(int)
#define VELOCITY_CFGA
Chip Configuration Register A.
Definition: velocity.h:308
#define VELOCITY_STICKY_DS0
Definition: velocity.h:313
void * regs
Registers.
Definition: velocity.h:327

References DBGC, EINVAL, readb(), velocity_nic::regs, timeout(), tmp, udelay(), VELOCITY_CFGA, VELOCITY_CFGA_PACPI, VELOCITY_CR1_SFRST, VELOCITY_CRS1, velocity_setbit, VELOCITY_STICKY, VELOCITY_STICKY_DS0, VELOCITY_STICKY_DS1, VELOCITY_TIMEOUT_US, and writeb().

Referenced by velocity_probe(), and velocity_remove().

◆ velocity_check_link()

static void velocity_check_link ( struct net_device netdev)
static

Check link state.

Parameters
netdevNetwork device

Definition at line 288 of file velocity.c.

288  {
289  struct velocity_nic *vlc = netdev->priv;
290 
291  if ( readb ( vlc->regs + VELOCITY_PHYSTS0 ) & VELOCITY_PHYSTS0_LINK ) {
293  DBGC ( vlc, "VELOCITY %p link up\n", vlc );
294  } else {
296  DBGC ( vlc, "VELOCITY %p link down\n", vlc );
297  }
298 
299  /* The card disables auto-poll after a link change */
300  velocity_autopoll_start ( vlc );
301 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
#define VELOCITY_PHYSTS0_LINK
Definition: velocity.h:285
void * priv
Driver private data.
Definition: netdevice.h:425
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
static struct net_device * netdev
Definition: gdbudp.c:52
A Velocity network card.
Definition: velocity.h:325
#define VELOCITY_PHYSTS0
Definition: velocity.h:284
static int velocity_autopoll_start(struct velocity_nic *vlc)
Start MII auto-polling.
Definition: velocity.c:82
void * regs
Registers.
Definition: velocity.h:327

References DBGC, netdev, netdev_link_down(), netdev_link_up(), net_device::priv, readb(), velocity_nic::regs, velocity_autopoll_start(), VELOCITY_PHYSTS0, and VELOCITY_PHYSTS0_LINK.

Referenced by velocity_open(), and velocity_poll().

◆ velocity_alloc_rings()

static int velocity_alloc_rings ( struct velocity_nic vlc)
static

Allocate descriptor rings.

Parameters
vlcVelocity device
Return values
rcReturn status code

Definition at line 316 of file velocity.c.

316  {
317  int rc = 0;
318 
319  /* Allocate RX descriptor ring */
320  vlc->rx_prod = 0;
321  vlc->rx_cons = 0;
322  vlc->rx_commit = 0;
324  if ( ! vlc->rx_ring )
325  return -ENOMEM;
326 
327  memset ( vlc->rx_ring, 0, VELOCITY_RXDESC_SIZE );
328 
329  DBGC2 ( vlc, "VELOCITY %p RX ring start address: %p(phys: %#08lx)\n",
330  vlc, vlc->rx_ring, virt_to_bus ( vlc->rx_ring ) );
331 
332  /* Allocate TX descriptor ring */
333  vlc->tx_prod = 0;
334  vlc->tx_cons = 0;
336  if ( ! vlc->tx_ring ) {
337  rc = -ENOMEM;
338  goto err_tx_alloc;
339  }
340 
341  memset ( vlc->tx_ring, 0, VELOCITY_TXDESC_SIZE );
342 
343  /* Send RX ring to the card */
344  writel ( virt_to_bus ( vlc->rx_ring ),
345  vlc->regs + VELOCITY_RXDESC_ADDR_LO );
347 
348  /* Send TX ring to the card */
349  writel ( virt_to_bus ( vlc->tx_ring ),
352 
353  DBGC2 ( vlc, "VELOCITY %p TX ring start address: %p(phys: %#08lx)\n",
354  vlc, vlc->tx_ring, virt_to_bus ( vlc->tx_ring ) );
355 
356  return 0;
357 
358 err_tx_alloc:
360  return rc;
361 }
struct velocity_tx_descriptor * tx_ring
Transmit descriptor ring.
Definition: velocity.h:351
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct velocity_rx_descriptor * rx_ring
Receive descriptor ring.
Definition: velocity.h:336
unsigned int rx_cons
Receive consumer index.
Definition: velocity.h:342
#define VELOCITY_RXDESCNUM
Definition: velocity.h:269
unsigned int rx_commit
Receive commit number.
Definition: velocity.h:348
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define VELOCITY_RING_ALIGN
Descriptor alignment.
Definition: velocity.h:94
#define VELOCITY_RXDESC_NUM
Number of receive descriptors.
Definition: velocity.h:84
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
#define VELOCITY_TXDESC_NUM
Number of transmit descriptors.
Definition: velocity.h:89
unsigned int rx_prod
Receive producer index.
Definition: velocity.h:340
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
unsigned int tx_prod
Transmit producer index.
Definition: velocity.h:353
#define VELOCITY_TXDESC_SIZE
Definition: velocity.h:90
#define VELOCITY_TXDESC_ADDR_LO0
Definition: velocity.h:265
#define DBGC2(...)
Definition: compiler.h:522
#define writew
Definition: w89c840.c:159
#define VELOCITY_RXDESC_ADDR_LO
Definition: velocity.h:261
unsigned int tx_cons
Transmit consumer index.
Definition: velocity.h:355
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
#define VELOCITY_RXDESC_SIZE
Definition: velocity.h:85
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define VELOCITY_TXDESCNUM
Definition: velocity.h:270
void * regs
Registers.
Definition: velocity.h:327
void * memset(void *dest, int character, size_t len) __nonnull

References DBGC2, ENOMEM, free_dma(), malloc_dma(), memset(), rc, velocity_nic::regs, velocity_nic::rx_commit, velocity_nic::rx_cons, velocity_nic::rx_prod, velocity_nic::rx_ring, velocity_nic::tx_cons, velocity_nic::tx_prod, velocity_nic::tx_ring, VELOCITY_RING_ALIGN, VELOCITY_RXDESC_ADDR_LO, VELOCITY_RXDESC_NUM, VELOCITY_RXDESC_SIZE, VELOCITY_RXDESCNUM, VELOCITY_TXDESC_ADDR_LO0, VELOCITY_TXDESC_NUM, VELOCITY_TXDESC_SIZE, VELOCITY_TXDESCNUM, virt_to_bus(), writel(), and writew.

Referenced by velocity_open().

◆ velocity_refill_rx()

static void velocity_refill_rx ( struct velocity_nic vlc)
static

Refill receive descriptor ring.

Parameters
vlcVelocity device

Definition at line 368 of file velocity.c.

368  {
369  struct velocity_rx_descriptor *desc;
370  struct io_buffer *iobuf;
371  int rx_idx, i = 0;
372 
373  /* Check for new packets */
374  while ( ( vlc->rx_prod - vlc->rx_cons ) < VELOCITY_RXDESC_NUM ) {
375  iobuf = alloc_iob ( VELOCITY_RX_MAX_LEN );
376 
377  /* Memory pressure: try again next poll */
378  if ( ! iobuf )
379  break;
380 
381  rx_idx = ( vlc->rx_prod++ % VELOCITY_RXDESC_NUM );
382  desc = &vlc->rx_ring[rx_idx];
383 
384  /* Set descrptor fields */
385  desc->des1 = 0;
386  desc->addr = virt_to_le32bus ( iobuf-> data );
387  desc->des2 = cpu_to_le32 (
390 
391  vlc->rx_buffs[rx_idx] = iobuf;
392  i++;
393 
394  /* Return RX descriptors in blocks of 4 (hw requirement) */
395  if ( rx_idx % 4 == 3 ) {
396  int j;
397  for (j = 0; j < 4; j++) {
398  desc = &vlc->rx_ring[rx_idx - j];
399  desc->des0 = cpu_to_le32 ( VELOCITY_DES0_OWN );
400  }
401  vlc->rx_commit += 4;
402  }
403  }
404 
405  wmb();
406 
407  if ( vlc->rx_commit ) {
408  writew ( vlc->rx_commit,
410  vlc->rx_commit = 0;
411  }
412 
413  if ( i > 0 )
414  DBGC2 ( vlc, "VELOCITY %p refilled %d RX descriptors\n",
415  vlc, i );
416 }
struct velocity_rx_descriptor * rx_ring
Receive descriptor ring.
Definition: velocity.h:336
wmb()
unsigned int rx_cons
Receive consumer index.
Definition: velocity.h:342
#define VELOCITY_DES2_IC
Definition: velocity.h:77
struct io_buffer * rx_buffs[VELOCITY_RXDESC_NUM]
Receive I/O buffers.
Definition: velocity.h:338
#define VELOCITY_RXDESC_RESIDUECNT
Definition: velocity.h:276
#define virt_to_le32bus(x)
Definition: velocity.c:37
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
unsigned int rx_commit
Receive commit number.
Definition: velocity.h:348
#define VELOCITY_RXDESC_NUM
Number of receive descriptors.
Definition: velocity.h:84
unsigned int rx_prod
Receive producer index.
Definition: velocity.h:340
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define VELOCITY_DES2_SIZE(_n)
Definition: velocity.h:78
#define VELOCITY_DES0_OWN
Definition: velocity.h:39
#define VELOCITY_RX_MAX_LEN
Receive buffer length.
Definition: velocity.h:97
#define DBGC2(...)
Definition: compiler.h:522
#define writew
Definition: w89c840.c:159
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
void * regs
Registers.
Definition: velocity.h:327
A persistent I/O buffer.
Definition: iobuf.h:32

References velocity_rx_descriptor::addr, alloc_iob(), cpu_to_le32, data, DBGC2, velocity_rx_descriptor::des0, velocity_rx_descriptor::des1, velocity_rx_descriptor::des2, velocity_nic::regs, velocity_nic::rx_buffs, velocity_nic::rx_commit, velocity_nic::rx_cons, velocity_nic::rx_prod, velocity_nic::rx_ring, VELOCITY_DES0_OWN, VELOCITY_DES2_IC, VELOCITY_DES2_SIZE, VELOCITY_RX_MAX_LEN, VELOCITY_RXDESC_NUM, VELOCITY_RXDESC_RESIDUECNT, virt_to_le32bus, wmb(), and writew.

Referenced by velocity_open(), and velocity_poll().

◆ velocity_open()

static int velocity_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 424 of file velocity.c.

424  {
425  struct velocity_nic *vlc = netdev->priv;
426  int rc;
427 
428  DBGC ( vlc, "VELOCITY %p open\n", vlc );
429  DBGC ( vlc, "VELOCITY %p regs at: %p\n", vlc, vlc->regs );
430 
431  /* Allocate descriptor rings */
432  if ( ( rc = velocity_alloc_rings ( vlc ) ) != 0 )
433  return rc;
434 
435  velocity_refill_rx ( vlc );
436 
437  /* Enable TX/RX queue */
440  vlc->regs + VELOCITY_RXQCSRS );
441 
442  /* Enable interrupts */
443  writeb ( 0xff, vlc->regs + VELOCITY_IMR0 );
444  writeb ( 0xff, vlc->regs + VELOCITY_IMR1 );
445 
446  /* Start MAC */
450  vlc->regs + VELOCITY_CRS0 );
451 
452  /* Receive all packets */
453  writeb ( 0xff, vlc->regs + VELOCITY_RCR );
454 
455  /* Set initial link state */
457 
458  velocity_autopoll_start ( vlc );
459 
460  DBGC2 ( vlc, "VELOCITY %p CR3 %02x\n",
461  vlc, readb ( vlc->regs + 0x0B ) );
462 
463  return 0;
464 }
#define VELOCITY_TXQCSRS
Definition: velocity.h:232
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define VELOCITY_TXQCSRS_RUN0
Definition: velocity.h:249
#define VELOCITY_IMR1
Interrupt mask register 1.
Definition: velocity.h:223
#define DBGC(...)
Definition: compiler.h:505
static int velocity_alloc_rings(struct velocity_nic *vlc)
Allocate descriptor rings.
Definition: velocity.c:316
#define VELOCITY_RXQCSR_RUN
Definition: velocity.h:257
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
static void velocity_check_link(struct net_device *netdev)
Check link state.
Definition: velocity.c:288
#define VELOCITY_CR1_DPOLL
Definition: velocity.h:137
#define VELOCITY_RCR
Receive control register.
Definition: velocity.h:108
void * priv
Driver private data.
Definition: netdevice.h:425
#define VELOCITY_IMR0
Interrupt mask register 0.
Definition: velocity.h:220
static struct net_device * netdev
Definition: gdbudp.c:52
#define VELOCITY_CR0_TXON
Definition: velocity.h:127
A Velocity network card.
Definition: velocity.h:325
#define VELOCITY_CRS0
Command register 0 (set)
Definition: velocity.h:126
#define VELOCITY_RXQCSRS
Definition: velocity.h:251
#define VELOCITY_RXQCSR_WAK
Definition: velocity.h:255
#define VELOCITY_CR0_RXON
Definition: velocity.h:128
#define DBGC2(...)
Definition: compiler.h:522
#define writew
Definition: w89c840.c:159
static void velocity_refill_rx(struct velocity_nic *vlc)
Refill receive descriptor ring.
Definition: velocity.c:368
#define VELOCITY_CR0_STOP
Definition: velocity.h:129
static int velocity_autopoll_start(struct velocity_nic *vlc)
Start MII auto-polling.
Definition: velocity.c:82
#define VELOCITY_CRC0
Command register 0 (clear)
Definition: velocity.h:157
void * regs
Registers.
Definition: velocity.h:327
#define VELOCITY_CR0_START
Definition: velocity.h:130

References DBGC, DBGC2, netdev, net_device::priv, rc, readb(), velocity_nic::regs, velocity_alloc_rings(), velocity_autopoll_start(), velocity_check_link(), VELOCITY_CR0_RXON, VELOCITY_CR0_START, VELOCITY_CR0_STOP, VELOCITY_CR0_TXON, VELOCITY_CR1_DPOLL, VELOCITY_CRC0, VELOCITY_CRS0, VELOCITY_IMR0, VELOCITY_IMR1, VELOCITY_RCR, velocity_refill_rx(), VELOCITY_RXQCSR_RUN, VELOCITY_RXQCSR_WAK, VELOCITY_RXQCSRS, VELOCITY_TXQCSRS, VELOCITY_TXQCSRS_RUN0, writeb(), and writew.

◆ velocity_close()

static void velocity_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 471 of file velocity.c.

471  {
472  struct velocity_nic *vlc = netdev->priv;
473  int i;
474 
475  /* Stop NIC */
477  vlc->regs + VELOCITY_CRC0 );
479 
480  /* Clear RX ring information */
481  writel ( 0, vlc->regs + VELOCITY_RXDESC_ADDR_LO );
482  writew ( 0, vlc->regs + VELOCITY_RXDESCNUM );
483 
484  /* Destroy RX ring */
486  vlc->rx_ring = NULL;
487  vlc->rx_prod = 0;
488  vlc->rx_cons = 0;
489 
490  /* Discard receive buffers */
491  for ( i = 0 ; i < VELOCITY_RXDESC_NUM ; i++ ) {
492  if ( vlc->rx_buffs[i] )
493  free_iob ( vlc->rx_buffs[i] );
494  vlc->rx_buffs[i] = NULL;
495  }
496 
497  /* Clear TX ring information */
498  writel ( 0, vlc->regs + VELOCITY_TXDESC_ADDR_LO0 );
499  writew ( 0, vlc->regs + VELOCITY_TXDESCNUM );
500 
501  /* Destroy TX ring */
503  vlc->tx_ring = NULL;
504  vlc->tx_prod = 0;
505  vlc->tx_cons = 0;
506 }
struct velocity_tx_descriptor * tx_ring
Transmit descriptor ring.
Definition: velocity.h:351
struct velocity_rx_descriptor * rx_ring
Receive descriptor ring.
Definition: velocity.h:336
unsigned int rx_cons
Receive consumer index.
Definition: velocity.h:342
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define VELOCITY_RXDESCNUM
Definition: velocity.h:269
struct io_buffer * rx_buffs[VELOCITY_RXDESC_NUM]
Receive I/O buffers.
Definition: velocity.h:338
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define VELOCITY_RXDESC_NUM
Number of receive descriptors.
Definition: velocity.h:84
void * priv
Driver private data.
Definition: netdevice.h:425
unsigned int rx_prod
Receive producer index.
Definition: velocity.h:340
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static struct net_device * netdev
Definition: gdbudp.c:52
#define VELOCITY_CR0_TXON
Definition: velocity.h:127
A Velocity network card.
Definition: velocity.h:325
unsigned int tx_prod
Transmit producer index.
Definition: velocity.h:353
#define VELOCITY_CRS0
Command register 0 (set)
Definition: velocity.h:126
#define VELOCITY_TXDESC_SIZE
Definition: velocity.h:90
#define VELOCITY_TXDESC_ADDR_LO0
Definition: velocity.h:265
#define VELOCITY_CR0_RXON
Definition: velocity.h:128
#define writew
Definition: w89c840.c:159
#define VELOCITY_RXDESC_ADDR_LO
Definition: velocity.h:261
unsigned int tx_cons
Transmit consumer index.
Definition: velocity.h:355
#define VELOCITY_CR0_STOP
Definition: velocity.h:129
#define VELOCITY_RXDESC_SIZE
Definition: velocity.h:85
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define VELOCITY_CRC0
Command register 0 (clear)
Definition: velocity.h:157
#define VELOCITY_TXDESCNUM
Definition: velocity.h:270
void * regs
Registers.
Definition: velocity.h:327

References free_dma(), free_iob(), netdev, NULL, net_device::priv, velocity_nic::regs, velocity_nic::rx_buffs, velocity_nic::rx_cons, velocity_nic::rx_prod, velocity_nic::rx_ring, velocity_nic::tx_cons, velocity_nic::tx_prod, velocity_nic::tx_ring, VELOCITY_CR0_RXON, VELOCITY_CR0_STOP, VELOCITY_CR0_TXON, VELOCITY_CRC0, VELOCITY_CRS0, VELOCITY_RXDESC_ADDR_LO, VELOCITY_RXDESC_NUM, VELOCITY_RXDESC_SIZE, VELOCITY_RXDESCNUM, VELOCITY_TXDESC_ADDR_LO0, VELOCITY_TXDESC_SIZE, VELOCITY_TXDESCNUM, writeb(), writel(), and writew.

◆ velocity_transmit()

static int velocity_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 515 of file velocity.c.

516  {
517  struct velocity_nic *vlc = netdev->priv;
518  struct velocity_tx_descriptor *desc;
519  unsigned int tx_idx;
520 
521  /* Pad packet to minimum length */
522  iob_pad ( iobuf, ETH_ZLEN );
523 
524  tx_idx = ( vlc->tx_prod++ % VELOCITY_TXDESC_NUM );
525  desc = &vlc->tx_ring[tx_idx];
526 
527  /* Set packet size and transfer ownership to NIC */
529  VELOCITY_DES2_SIZE ( iob_len ( iobuf ) ) );
530  /* Data in first desc fragment, only desc for packet, generate INT */
531  desc->des1 = cpu_to_le32 ( VELOCITY_DES1_FRAG ( 1 ) |
534 
535  desc->frags[0].addr = virt_to_le32bus ( iobuf->data );
536  desc->frags[0].des2 = cpu_to_le32 (
537  VELOCITY_DES2_SIZE ( iob_len ( iobuf ) ) );
538 
539  wmb();
540 
541  /* Initiate TX */
543 
544  DBGC2 ( vlc, "VELOCITY %p tx_prod=%d desc=%p iobuf=%p len=%zd\n",
545  vlc, tx_idx, desc, iobuf->data, iob_len ( iobuf ) );
546 
547  return 0;
548 }
#define VELOCITY_TXQCSRS
Definition: velocity.h:232
#define velocity_setbit(_reg, _mask)
Definition: velocity.c:36
struct velocity_tx_descriptor * tx_ring
Transmit descriptor ring.
Definition: velocity.h:351
#define VELOCITY_DES1_INTR
Definition: velocity.h:68
wmb()
uint32_t des2
Definition: velocity.h:20
#define virt_to_le32bus(x)
Definition: velocity.c:37
struct velocity_frag frags[7]
Definition: velocity.h:28
#define VELOCITY_TXDESC_NUM
Number of transmit descriptors.
Definition: velocity.h:89
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
#define cpu_to_le32(value)
Definition: byteswap.h:107
A Velocity network card.
Definition: velocity.h:325
#define VELOCITY_DES2_SIZE(_n)
Definition: velocity.h:78
unsigned int tx_prod
Transmit producer index.
Definition: velocity.h:353
#define VELOCITY_DES0_OWN
Definition: velocity.h:39
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
Velocity descriptor format.
Definition: velocity.h:24
#define ETH_ZLEN
Definition: if_ether.h:10
#define VELOCITY_DES1_FRAG(_n)
TX descriptor fragment number.
Definition: velocity.h:66
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:44
#define VELOCITY_DES1_TCPLS
Definition: velocity.h:67
#define VELOCITY_TXQCSRS_WAK0
Definition: velocity.h:247
uint32_t addr
Definition: velocity.h:19
void iob_pad(struct io_buffer *iobuf, size_t min_len)
Pad I/O buffer.
Definition: iobpad.c:49
void * regs
Registers.
Definition: velocity.h:327

References velocity_frag::addr, cpu_to_le32, io_buffer::data, DBGC2, velocity_tx_descriptor::des0, velocity_tx_descriptor::des1, velocity_frag::des2, ETH_ZLEN, velocity_tx_descriptor::frags, iob_len(), iob_pad(), netdev, net_device::priv, velocity_nic::regs, velocity_nic::tx_prod, velocity_nic::tx_ring, VELOCITY_DES0_OWN, VELOCITY_DES1_FRAG, VELOCITY_DES1_INTR, VELOCITY_DES1_TCPLS, VELOCITY_DES2_SIZE, velocity_setbit, VELOCITY_TXDESC_NUM, VELOCITY_TXQCSRS, VELOCITY_TXQCSRS_WAK0, virt_to_le32bus, and wmb().

◆ velocity_poll_rx()

static void velocity_poll_rx ( struct velocity_nic vlc)
static

Poll for received packets.

Parameters
vlcVelocity device

Definition at line 555 of file velocity.c.

555  {
556  struct velocity_rx_descriptor *desc;
557  struct io_buffer *iobuf;
558  int rx_idx;
559  size_t len;
560  uint32_t des0;
561 
562  /* Check for packets */
563  while ( vlc->rx_cons != vlc->rx_prod ) {
564  rx_idx = ( vlc->rx_cons % VELOCITY_RXDESC_NUM );
565  desc = &vlc->rx_ring[rx_idx];
566 
567  des0 = cpu_to_le32 ( desc->des0 );
568 
569  /* Return if descriptor still in use */
570  if ( des0 & VELOCITY_DES0_OWN )
571  return;
572 
573  iobuf = vlc->rx_buffs[rx_idx];
574 
575  /* Get length, strip CRC */
576  len = VELOCITY_DES0_RMBC ( des0 ) - 4;
577  iob_put ( iobuf, len );
578 
579  DBGC2 ( vlc, "VELOCITY %p got packet on idx=%d (prod=%d), len %zd\n",
580  vlc, rx_idx, vlc->rx_prod % VELOCITY_RXDESC_NUM, len );
581 
582  if ( des0 & VELOCITY_DES0_RX_ERR ) {
583  /* Report receive error */
584  netdev_rx_err ( vlc->netdev, iobuf, -EINVAL );
585  DBGC ( vlc, "VELOCITY %p receive error, status: %02x\n",
586  vlc, des0 );
587  } else if ( des0 & VELOCITY_DES0_RXOK ) {
588  /* Report receive success */
589  netdev_rx( vlc->netdev, iobuf );
590  } else {
591  /* Card indicated neither success nor failure
592  * Technically this shouldn't happen, but we saw it
593  * in debugging once. */
594  DBGC ( vlc, "VELOCITY %p RX neither ERR nor OK: %04x\n",
595  vlc, des0 );
596  DBGC ( vlc, "packet len: %zd\n", len );
597  DBGC_HD ( vlc, iobuf->data, 64 );
598 
599  /* we don't know what it is, treat is as an error */
600  netdev_rx_err ( vlc->netdev, iobuf, -EINVAL );
601  }
602 
603  vlc->rx_cons++;
604  }
605 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
#define VELOCITY_DES0_RX_ERR
Definition: velocity.h:59
struct velocity_rx_descriptor * rx_ring
Receive descriptor ring.
Definition: velocity.h:336
unsigned int rx_cons
Receive consumer index.
Definition: velocity.h:342
#define iob_put(iobuf, len)
Definition: iobuf.h:116
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
#define VELOCITY_DES0_RMBC(_n)
Definition: velocity.h:38
#define DBGC(...)
Definition: compiler.h:505
struct io_buffer * rx_buffs[VELOCITY_RXDESC_NUM]
Receive I/O buffers.
Definition: velocity.h:338
uint32_t des0
Definition: rhine.h:11
#define VELOCITY_RXDESC_NUM
Number of receive descriptors.
Definition: velocity.h:84
#define VELOCITY_DES0_RXOK
Definition: velocity.h:41
unsigned int rx_prod
Receive producer index.
Definition: velocity.h:340
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define VELOCITY_DES0_OWN
Definition: velocity.h:39
#define DBGC_HD(...)
Definition: compiler.h:507
unsigned int uint32_t
Definition: stdint.h:12
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:44
struct net_device * netdev
Netdev.
Definition: velocity.h:333
A persistent I/O buffer.
Definition: iobuf.h:32

References cpu_to_le32, io_buffer::data, DBGC, DBGC2, DBGC_HD, des0, velocity_rx_descriptor::des0, EINVAL, iob_put, len, velocity_nic::netdev, netdev_rx(), netdev_rx_err(), velocity_nic::rx_buffs, velocity_nic::rx_cons, velocity_nic::rx_prod, velocity_nic::rx_ring, VELOCITY_DES0_OWN, VELOCITY_DES0_RMBC, VELOCITY_DES0_RX_ERR, VELOCITY_DES0_RXOK, and VELOCITY_RXDESC_NUM.

Referenced by velocity_poll().

◆ velocity_poll_tx()

static void velocity_poll_tx ( struct velocity_nic vlc)
static

Poll for completed packets.

Parameters
vlcVelocity device

Definition at line 612 of file velocity.c.

612  {
613  struct velocity_tx_descriptor *desc;
614  int tx_idx;
615 
616  /* Check for packets */
617  while ( vlc->tx_cons != vlc->tx_prod ) {
618  tx_idx = ( vlc->tx_cons % VELOCITY_TXDESC_NUM );
619  desc = &vlc->tx_ring[tx_idx];
620 
621  /* Return if descriptor still in use */
622  if ( le32_to_cpu ( desc->des0 ) & VELOCITY_DES0_OWN )
623  return;
624 
625  /* Report errors */
626  if ( le32_to_cpu ( desc->des0 ) & VELOCITY_DES0_TERR ) {
628  return;
629  }
630 
632 
633  DBGC2 ( vlc, "VELOCITY %p poll_tx cons=%d prod=%d tsr=%04x\n",
634  vlc, tx_idx, vlc->tx_prod % VELOCITY_TXDESC_NUM,
635  ( desc->des0 & 0xffff ) );
636  vlc->tx_cons++;
637  }
638 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct velocity_tx_descriptor * tx_ring
Transmit descriptor ring.
Definition: velocity.h:351
#define le32_to_cpu(value)
Definition: byteswap.h:113
static void netdev_tx_complete_next(struct net_device *netdev)
Complete network transmission.
Definition: netdevice.h:758
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
Definition: netdevice.c:434
#define VELOCITY_TXDESC_NUM
Number of transmit descriptors.
Definition: velocity.h:89
unsigned int tx_prod
Transmit producer index.
Definition: velocity.h:353
#define VELOCITY_DES0_OWN
Definition: velocity.h:39
Velocity descriptor format.
Definition: velocity.h:24
#define DBGC2(...)
Definition: compiler.h:522
#define VELOCITY_DES0_TERR
Definition: velocity.h:40
unsigned int tx_cons
Transmit consumer index.
Definition: velocity.h:355
struct net_device * netdev
Netdev.
Definition: velocity.h:333

References DBGC2, velocity_tx_descriptor::des0, EINVAL, le32_to_cpu, velocity_nic::netdev, netdev_tx_complete_next(), netdev_tx_complete_next_err(), velocity_nic::tx_cons, velocity_nic::tx_prod, velocity_nic::tx_ring, VELOCITY_DES0_OWN, VELOCITY_DES0_TERR, and VELOCITY_TXDESC_NUM.

Referenced by velocity_poll().

◆ velocity_poll()

static void velocity_poll ( struct net_device netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 645 of file velocity.c.

645  {
646  struct velocity_nic *vlc = netdev->priv;
647  uint8_t isr1;
648 
649  isr1 = readb ( vlc->regs + VELOCITY_ISR1 );
650 
651  /* ACK interrupts */
652  writew ( 0xFFFF, vlc->regs + VELOCITY_ISR0 );
653 
654  /* Check for competed packets */
655  velocity_poll_rx ( vlc );
656  velocity_poll_tx ( vlc );
657 
658  if ( isr1 & VELOCITY_ISR1_SRCI ) {
659  /* Update linkstate */
660  DBGC2 ( vlc, "VELOCITY %p link status interrupt\n", vlc );
662  }
663 
664  velocity_refill_rx ( vlc );
665 
666  /* deal with potential RX stall caused by RX ring underrun */
668  vlc->regs + VELOCITY_RXQCSRS );
669 }
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define VELOCITY_ISR1_SRCI
Definition: velocity.h:198
#define VELOCITY_ISR0
Interrupt status register 0.
Definition: velocity.h:186
#define VELOCITY_ISR1
Interrupt status register 1.
Definition: velocity.h:197
#define VELOCITY_RXQCSR_RUN
Definition: velocity.h:257
static void velocity_check_link(struct net_device *netdev)
Check link state.
Definition: velocity.c:288
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
static void velocity_poll_rx(struct velocity_nic *vlc)
Poll for received packets.
Definition: velocity.c:555
static void velocity_poll_tx(struct velocity_nic *vlc)
Poll for completed packets.
Definition: velocity.c:612
A Velocity network card.
Definition: velocity.h:325
#define VELOCITY_RXQCSRS
Definition: velocity.h:251
#define VELOCITY_RXQCSR_WAK
Definition: velocity.h:255
unsigned char uint8_t
Definition: stdint.h:10
#define DBGC2(...)
Definition: compiler.h:522
#define writew
Definition: w89c840.c:159
static void velocity_refill_rx(struct velocity_nic *vlc)
Refill receive descriptor ring.
Definition: velocity.c:368
void * regs
Registers.
Definition: velocity.h:327

References DBGC2, netdev, net_device::priv, readb(), velocity_nic::regs, velocity_check_link(), VELOCITY_ISR0, VELOCITY_ISR1, VELOCITY_ISR1_SRCI, velocity_poll_rx(), velocity_poll_tx(), velocity_refill_rx(), VELOCITY_RXQCSR_RUN, VELOCITY_RXQCSR_WAK, VELOCITY_RXQCSRS, and writew.

◆ velocity_irq()

static void velocity_irq ( struct net_device netdev,
int  enable 
)
static

Enable or disable interrupts.

Parameters
netdevNetwork device
enableInterrupts should be enabled

Definition at line 677 of file velocity.c.

677  {
678  struct velocity_nic *vlc = netdev->priv;
679 
680  DBGC ( vlc, "VELOCITY %p interrupts %s\n", vlc,
681  enable ? "enable" : "disable" );
682 
683  if (enable) {
684  /* Enable interrupts */
686  } else {
687  /* Disable interrupts */
689  }
690 }
#define DBGC(...)
Definition: compiler.h:505
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
A Velocity network card.
Definition: velocity.h:325
#define VELOCITY_CRC3
Command register 3 (clear.
Definition: velocity.h:166
#define VELOCITY_CRS3
Command register 3 (set)
Definition: velocity.h:148
#define VELOCITY_CR3_GINTMSK1
Definition: velocity.h:153
void * regs
Registers.
Definition: velocity.h:327

References DBGC, netdev, net_device::priv, velocity_nic::regs, VELOCITY_CR3_GINTMSK1, VELOCITY_CRC3, VELOCITY_CRS3, and writeb().

◆ velocity_probe()

static int velocity_probe ( struct pci_device pci)
static

Probe PCI device.

Parameters
pciPCI device
Return values
rcReturn status code

Definition at line 714 of file velocity.c.

714  {
715  struct net_device *netdev;
716  struct velocity_nic *vlc;
717  int rc;
718 
719  /* Allocate and initialise net device */
720  netdev = alloc_etherdev ( sizeof ( *vlc ) );
721  if ( ! netdev ) {
722  rc = -ENOMEM;
723  goto err_alloc;
724  }
726  vlc = netdev->priv;
727  pci_set_drvdata ( pci, netdev );
728  netdev->dev = &pci->dev;
729 
730  /* Fix up PCI device */
731  adjust_pci_device ( pci );
732 
733  /* Map registers */
734  vlc->regs = ioremap ( pci->membase, VELOCITY_BAR_SIZE );
735  vlc->netdev = netdev;
736 
737  /* Reset the NIC */
738  if ( ( rc = velocity_reset ( vlc ) ) != 0 )
739  goto err_reset;
740 
741  /* Reload EEPROM */
742  if ( ( rc = velocity_reload_eeprom ( vlc ) ) != 0 )
743  goto err_reset;
744 
745  /* Get MAC address */
746  netdev->hw_addr[0] = readb ( vlc->regs + VELOCITY_MAC0 );
747  netdev->hw_addr[1] = readb ( vlc->regs + VELOCITY_MAC1 );
748  netdev->hw_addr[2] = readb ( vlc->regs + VELOCITY_MAC2 );
749  netdev->hw_addr[3] = readb ( vlc->regs + VELOCITY_MAC3 );
750  netdev->hw_addr[4] = readb ( vlc->regs + VELOCITY_MAC4 );
751  netdev->hw_addr[5] = readb ( vlc->regs + VELOCITY_MAC5 );
752 
753  /* Initialise and reset MII interface */
755  mii_init ( &vlc->mii, &vlc->mdio, 0 );
756  if ( ( rc = mii_reset ( &vlc->mii ) ) != 0 ) {
757  DBGC ( vlc, "VELOCITY %p could not reset MII: %s\n",
758  vlc, strerror ( rc ) );
759  goto err_mii_reset;
760  }
761 
762  /* Enable proper link advertising */
763  velocity_set_link ( vlc );
764 
765  /* Register network device */
766  if ( ( rc = register_netdev ( netdev ) ) != 0 )
767  goto err_register_netdev;
768 
769  return 0;
770 
771  err_register_netdev:
772  err_mii_reset:
773  velocity_reset ( vlc );
774  err_reset:
776  netdev_put ( netdev );
777  err_alloc:
778  return rc;
779 }
unsigned long membase
Memory base.
Definition: pci.h:194
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define VELOCITY_MAC0
MAC address registers.
Definition: velocity.h:100
#define VELOCITY_MAC3
Definition: velocity.h:103
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:149
struct device dev
Generic device.
Definition: pci.h:189
static void mdio_init(struct mii_interface *mdio, struct mii_operations *op)
Initialise MII interface.
Definition: mii.h:63
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:338
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define VELOCITY_MAC1
Definition: velocity.h:101
static struct mii_operations velocity_mii_operations
Velocity MII operations.
Definition: velocity.c:187
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 int velocity_reload_eeprom(struct velocity_nic *vlc)
Reload eeprom contents.
Definition: velocity.c:223
static struct net_device * netdev
Definition: gdbudp.c:52
static struct net_device_operations velocity_operations
Velocity network device operations.
Definition: velocity.c:693
A Velocity network card.
Definition: velocity.h:325
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define VELOCITY_BAR_SIZE
Skeleton BAR size.
Definition: velocity.h:13
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
A network device.
Definition: netdevice.h:348
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
static int velocity_reset(struct velocity_nic *vlc)
Reset hardware.
Definition: velocity.c:247
int mii_reset(struct mii_device *mii)
Reset MII device.
Definition: mii.c:74
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
static void mii_init(struct mii_device *mii, struct mii_interface *mdio, unsigned int address)
Initialise MII device.
Definition: mii.h:75
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
static void velocity_set_link(struct velocity_nic *vlc)
Set Link speed.
Definition: velocity.c:197
#define VELOCITY_MAC4
Definition: velocity.h:104
#define VELOCITY_MAC5
Definition: velocity.h:105
struct mii_device mii
MII device.
Definition: velocity.h:331
struct mii_interface mdio
MII interface.
Definition: velocity.h:329
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
struct net_device * netdev
Netdev.
Definition: velocity.h:333
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
#define VELOCITY_MAC2
Definition: velocity.h:102
void * regs
Registers.
Definition: velocity.h:327

References adjust_pci_device(), alloc_etherdev(), DBGC, pci_device::dev, net_device::dev, ENOMEM, net_device::hw_addr, ioremap(), velocity_nic::mdio, mdio_init(), pci_device::membase, velocity_nic::mii, mii_init(), mii_reset(), netdev, velocity_nic::netdev, netdev_init(), netdev_nullify(), netdev_put(), pci_set_drvdata(), net_device::priv, rc, readb(), register_netdev(), velocity_nic::regs, strerror(), VELOCITY_BAR_SIZE, VELOCITY_MAC0, VELOCITY_MAC1, VELOCITY_MAC2, VELOCITY_MAC3, VELOCITY_MAC4, VELOCITY_MAC5, velocity_mii_operations, velocity_operations, velocity_reload_eeprom(), velocity_reset(), and velocity_set_link().

◆ velocity_remove()

static void velocity_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 786 of file velocity.c.

786  {
787  struct net_device *netdev = pci_get_drvdata ( pci );
788  struct velocity_nic *vlc = netdev->priv;
789 
790  /* Unregister network device */
792 
793  /* Reset card */
794  velocity_reset ( vlc );
795 
796  /* Free network device */
798  netdev_put ( netdev );
799 }
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 net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
A Velocity network card.
Definition: velocity.h:325
A network device.
Definition: netdevice.h:348
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
static int velocity_reset(struct velocity_nic *vlc)
Reset hardware.
Definition: velocity.c:247
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:348

References netdev, netdev_nullify(), netdev_put(), pci_get_drvdata(), net_device::priv, unregister_netdev(), and velocity_reset().

Variable Documentation

◆ velocity_mii_operations

struct mii_operations velocity_mii_operations
static
Initial value:
= {
}
static int velocity_mii_read(struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg)
Read from MII register.
Definition: velocity.c:108
static int velocity_mii_write(struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg, unsigned int data)
Write to MII register.
Definition: velocity.c:151

Velocity MII operations.

Definition at line 187 of file velocity.c.

Referenced by velocity_probe().

◆ velocity_operations

struct net_device_operations velocity_operations
static
Initial value:
= {
.open = velocity_open,
.close = velocity_close,
.transmit = velocity_transmit,
.poll = velocity_poll,
.irq = velocity_irq,
}
static int velocity_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: velocity.c:515
static void velocity_close(struct net_device *netdev)
Close network device.
Definition: velocity.c:471
static void velocity_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: velocity.c:645
static int velocity_open(struct net_device *netdev)
Open network device.
Definition: velocity.c:424
static void velocity_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: velocity.c:677

Velocity network device operations.

Definition at line 693 of file velocity.c.

Referenced by velocity_probe().

◆ velocity_nics

struct pci_device_id velocity_nics[]
static
Initial value:
= {
PCI_ROM ( 0x1106, 0x3119, "vt6122", "VIA Velocity", 0 ),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:283

Velocity PCI device IDs.

Definition at line 802 of file velocity.c.

◆ __pci_driver

struct pci_driver velocity_driver __pci_driver
Initial value:
= {
.ids = velocity_nics,
.id_count = ( sizeof ( velocity_nics ) / sizeof ( velocity_nics[0] ) ),
.probe = velocity_probe,
}
static int velocity_probe(struct pci_device *pci)
Probe PCI device.
Definition: velocity.c:714
static void velocity_remove(struct pci_device *pci)
Remove PCI device.
Definition: velocity.c:786
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
static struct pci_device_id velocity_nics[]
Velocity PCI device IDs.
Definition: velocity.c:802

Velocity PCI driver.

Definition at line 807 of file velocity.c.