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.
static const void const void void * result
Definition: crypto.h:335
static unsigned int unsigned int reg
Definition: myson.h:162
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
#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
#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.
static unsigned int unsigned int reg
Definition: myson.h:162
#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
#define VELOCITY_MIICR
Definition: velocity.h:287
#define DBGC2(...)
Definition: compiler.h:522
#define writew
Definition: w89c840.c:159
uint8_t data[48]
Additional event data.
Definition: ena.h:22
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
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:133
unsigned long tmp
Definition: linux_pci.h:53
#define BMCR_SPEED1000
Definition: mii.h:43
#define MII_CTRL1000
Definition: mii.h:24
#define MII_BMCR
Definition: atl1e.h:871
#define ADVERTISE_1000HALF
Definition: mii.h:134
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
unsigned long tmp
Definition: linux_pci.h:53
#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
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:230
#define VELOCITY_PHYSTS0_LINK
Definition: velocity.h:285
void * priv
Driver private data.
Definition: netdevice.h:431
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:774
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;
325  if ( ! vlc->rx_ring )
326  return -ENOMEM;
327 
328  memset ( vlc->rx_ring, 0, VELOCITY_RXDESC_SIZE );
329 
330  DBGC2 ( vlc, "VELOCITY %p RX ring start address: %p(phys: %#08lx)\n",
331  vlc, vlc->rx_ring, virt_to_bus ( vlc->rx_ring ) );
332 
333  /* Allocate TX descriptor ring */
334  vlc->tx_prod = 0;
335  vlc->tx_cons = 0;
338  if ( ! vlc->tx_ring ) {
339  rc = -ENOMEM;
340  goto err_tx_alloc;
341  }
342 
343  memset ( vlc->tx_ring, 0, VELOCITY_TXDESC_SIZE );
344 
345  /* Send RX ring to the card */
346  writel ( virt_to_bus ( vlc->rx_ring ),
347  vlc->regs + VELOCITY_RXDESC_ADDR_LO );
349 
350  /* Send TX ring to the card */
351  writel ( virt_to_bus ( vlc->tx_ring ),
354 
355  DBGC2 ( vlc, "VELOCITY %p TX ring start address: %p(phys: %#08lx)\n",
356  vlc, vlc->tx_ring, virt_to_bus ( vlc->tx_ring ) );
357 
358  return 0;
359 
360 err_tx_alloc:
362  return rc;
363 }
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
static void *__malloc malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.h:62
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 free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
#define VELOCITY_RXDESC_SIZE
Definition: velocity.h:85
#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_phys(), malloc_phys(), 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 370 of file velocity.c.

370  {
372  struct io_buffer *iobuf;
373  int rx_idx, i = 0;
374 
375  /* Check for new packets */
376  while ( ( vlc->rx_prod - vlc->rx_cons ) < VELOCITY_RXDESC_NUM ) {
377  iobuf = alloc_iob ( VELOCITY_RX_MAX_LEN );
378 
379  /* Memory pressure: try again next poll */
380  if ( ! iobuf )
381  break;
382 
383  rx_idx = ( vlc->rx_prod++ % VELOCITY_RXDESC_NUM );
384  desc = &vlc->rx_ring[rx_idx];
385 
386  /* Set descrptor fields */
387  desc->des1 = 0;
388  desc->addr = virt_to_le32bus ( iobuf-> data );
389  desc->des2 = cpu_to_le32 (
392 
393  vlc->rx_buffs[rx_idx] = iobuf;
394  i++;
395 
396  /* Return RX descriptors in blocks of 4 (hw requirement) */
397  if ( rx_idx % 4 == 3 ) {
398  int j;
399  for (j = 0; j < 4; j++) {
400  desc = &vlc->rx_ring[rx_idx - j];
401  desc->des0 = cpu_to_le32 ( VELOCITY_DES0_OWN );
402  }
403  vlc->rx_commit += 4;
404  }
405  }
406 
407  wmb();
408 
409  if ( vlc->rx_commit ) {
410  writew ( vlc->rx_commit,
412  vlc->rx_commit = 0;
413  }
414 
415  if ( i > 0 )
416  DBGC2 ( vlc, "VELOCITY %p refilled %d RX descriptors\n",
417  vlc, i );
418 }
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
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#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:129
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
uint8_t data[48]
Additional event data.
Definition: ena.h:22
void * regs
Registers.
Definition: velocity.h:327
A persistent I/O buffer.
Definition: iobuf.h:33

References alloc_iob(), cpu_to_le32, data, DBGC2, desc, 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 426 of file velocity.c.

426  {
427  struct velocity_nic *vlc = netdev->priv;
428  int rc;
429 
430  DBGC ( vlc, "VELOCITY %p open\n", vlc );
431  DBGC ( vlc, "VELOCITY %p regs at: %p\n", vlc, vlc->regs );
432 
433  /* Allocate descriptor rings */
434  if ( ( rc = velocity_alloc_rings ( vlc ) ) != 0 )
435  return rc;
436 
437  velocity_refill_rx ( vlc );
438 
439  /* Enable TX/RX queue */
442  vlc->regs + VELOCITY_RXQCSRS );
443 
444  /* Enable interrupts */
445  writeb ( 0xff, vlc->regs + VELOCITY_IMR0 );
446  writeb ( 0xff, vlc->regs + VELOCITY_IMR1 );
447 
448  /* Start MAC */
452  vlc->regs + VELOCITY_CRS0 );
453 
454  /* Receive all packets */
455  writeb ( 0xff, vlc->regs + VELOCITY_RCR );
456 
457  /* Set initial link state */
459 
460  velocity_autopoll_start ( vlc );
461 
462  DBGC2 ( vlc, "VELOCITY %p CR3 %02x\n",
463  vlc, readb ( vlc->regs + 0x0B ) );
464 
465  return 0;
466 }
#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:431
#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:370
#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 473 of file velocity.c.

473  {
474  struct velocity_nic *vlc = netdev->priv;
475  int i;
476 
477  /* Stop NIC */
479  vlc->regs + VELOCITY_CRC0 );
481 
482  /* Clear RX ring information */
483  writel ( 0, vlc->regs + VELOCITY_RXDESC_ADDR_LO );
484  writew ( 0, vlc->regs + VELOCITY_RXDESCNUM );
485 
486  /* Destroy RX ring */
488  vlc->rx_ring = NULL;
489  vlc->rx_prod = 0;
490  vlc->rx_cons = 0;
491 
492  /* Discard receive buffers */
493  for ( i = 0 ; i < VELOCITY_RXDESC_NUM ; i++ ) {
494  if ( vlc->rx_buffs[i] )
495  free_iob ( vlc->rx_buffs[i] );
496  vlc->rx_buffs[i] = NULL;
497  }
498 
499  /* Clear TX ring information */
500  writel ( 0, vlc->regs + VELOCITY_TXDESC_ADDR_LO0 );
501  writew ( 0, vlc->regs + VELOCITY_TXDESCNUM );
502 
503  /* Destroy TX ring */
505  vlc->tx_ring = NULL;
506  vlc->tx_prod = 0;
507  vlc->tx_cons = 0;
508 }
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:146
#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:431
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
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
#define VELOCITY_RXDESC_SIZE
Definition: velocity.h:85
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#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_iob(), free_phys(), 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 517 of file velocity.c.

518  {
519  struct velocity_nic *vlc = netdev->priv;
521  unsigned int tx_idx;
522 
523  /* Pad packet to minimum length */
524  iob_pad ( iobuf, ETH_ZLEN );
525 
526  tx_idx = ( vlc->tx_prod++ % VELOCITY_TXDESC_NUM );
527  desc = &vlc->tx_ring[tx_idx];
528 
529  /* Set packet size and transfer ownership to NIC */
531  VELOCITY_DES2_SIZE ( iob_len ( iobuf ) ) );
532  /* Data in first desc fragment, only desc for packet, generate INT */
533  desc->des1 = cpu_to_le32 ( VELOCITY_DES1_FRAG ( 1 ) |
536 
537  desc->frags[0].addr = virt_to_le32bus ( iobuf->data );
538  desc->frags[0].des2 = cpu_to_le32 (
539  VELOCITY_DES2_SIZE ( iob_len ( iobuf ) ) );
540 
541  wmb();
542 
543  /* Initiate TX */
545 
546  DBGC2 ( vlc, "VELOCITY %p tx_prod=%d desc=%p iobuf=%p len=%zd\n",
547  vlc, tx_idx, desc, iobuf->data, iob_len ( iobuf ) );
548 
549  return 0;
550 }
#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()
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#define virt_to_le32bus(x)
Definition: velocity.c:37
#define VELOCITY_TXDESC_NUM
Number of transmit descriptors.
Definition: velocity.h:89
void * priv
Driver private data.
Definition: netdevice.h:431
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:155
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:48
#define VELOCITY_DES1_TCPLS
Definition: velocity.h:67
#define VELOCITY_TXQCSRS_WAK0
Definition: velocity.h:247
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 cpu_to_le32, io_buffer::data, DBGC2, desc, ETH_ZLEN, 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 557 of file velocity.c.

557  {
559  struct io_buffer *iobuf;
560  int rx_idx;
561  size_t len;
562  uint32_t des0;
563 
564  /* Check for packets */
565  while ( vlc->rx_cons != vlc->rx_prod ) {
566  rx_idx = ( vlc->rx_cons % VELOCITY_RXDESC_NUM );
567  desc = &vlc->rx_ring[rx_idx];
568 
569  des0 = cpu_to_le32 ( desc->des0 );
570 
571  /* Return if descriptor still in use */
572  if ( des0 & VELOCITY_DES0_OWN )
573  return;
574 
575  iobuf = vlc->rx_buffs[rx_idx];
576 
577  /* Get length, strip CRC */
578  len = VELOCITY_DES0_RMBC ( des0 ) - 4;
579  iob_put ( iobuf, len );
580 
581  DBGC2 ( vlc, "VELOCITY %p got packet on idx=%d (prod=%d), len %zd\n",
582  vlc, rx_idx, vlc->rx_prod % VELOCITY_RXDESC_NUM, len );
583 
584  if ( des0 & VELOCITY_DES0_RX_ERR ) {
585  /* Report receive error */
586  netdev_rx_err ( vlc->netdev, iobuf, -EINVAL );
587  DBGC ( vlc, "VELOCITY %p receive error, status: %02x\n",
588  vlc, des0 );
589  } else if ( des0 & VELOCITY_DES0_RXOK ) {
590  /* Report receive success */
591  netdev_rx( vlc->netdev, iobuf );
592  } else {
593  /* Card indicated neither success nor failure
594  * Technically this shouldn't happen, but we saw it
595  * in debugging once. */
596  DBGC ( vlc, "VELOCITY %p RX neither ERR nor OK: %04x\n",
597  vlc, des0 );
598  DBGC ( vlc, "packet len: %zd\n", len );
599  DBGC_HD ( vlc, iobuf->data, 64 );
600 
601  /* we don't know what it is, treat is as an error */
602  netdev_rx_err ( vlc->netdev, iobuf, -EINVAL );
603  }
604 
605  vlc->rx_cons++;
606  }
607 }
#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:120
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
#define VELOCITY_DES0_RMBC(_n)
Definition: velocity.h:38
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#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:548
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:48
struct net_device * netdev
Netdev.
Definition: velocity.h:333
A persistent I/O buffer.
Definition: iobuf.h:33

References cpu_to_le32, io_buffer::data, DBGC, DBGC2, DBGC_HD, des0, desc, 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 614 of file velocity.c.

614  {
616  int tx_idx;
617 
618  /* Check for packets */
619  while ( vlc->tx_cons != vlc->tx_prod ) {
620  tx_idx = ( vlc->tx_cons % VELOCITY_TXDESC_NUM );
621  desc = &vlc->tx_ring[tx_idx];
622 
623  /* Return if descriptor still in use */
624  if ( le32_to_cpu ( desc->des0 ) & VELOCITY_DES0_OWN )
625  return;
626 
627  /* Report errors */
628  if ( le32_to_cpu ( desc->des0 ) & VELOCITY_DES0_TERR ) {
630  return;
631  }
632 
634 
635  DBGC2 ( vlc, "VELOCITY %p poll_tx cons=%d prod=%d tsr=%04x\n",
636  vlc, tx_idx, vlc->tx_prod % VELOCITY_TXDESC_NUM,
637  ( desc->des0 & 0xffff ) );
638  vlc->tx_cons++;
639  }
640 }
#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:764
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
Definition: netdevice.c:509
#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, desc, 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 647 of file velocity.c.

647  {
648  struct velocity_nic *vlc = netdev->priv;
649  uint8_t isr1;
650 
651  isr1 = readb ( vlc->regs + VELOCITY_ISR1 );
652 
653  /* ACK interrupts */
654  writew ( 0xFFFF, vlc->regs + VELOCITY_ISR0 );
655 
656  /* Check for competed packets */
657  velocity_poll_rx ( vlc );
658  velocity_poll_tx ( vlc );
659 
660  if ( isr1 & VELOCITY_ISR1_SRCI ) {
661  /* Update linkstate */
662  DBGC2 ( vlc, "VELOCITY %p link status interrupt\n", vlc );
664  }
665 
666  velocity_refill_rx ( vlc );
667 
668  /* deal with potential RX stall caused by RX ring underrun */
670  vlc->regs + VELOCITY_RXQCSRS );
671 }
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:431
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:557
static void velocity_poll_tx(struct velocity_nic *vlc)
Poll for completed packets.
Definition: velocity.c:614
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:370
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 679 of file velocity.c.

679  {
680  struct velocity_nic *vlc = netdev->priv;
681 
682  DBGC ( vlc, "VELOCITY %p interrupts %s\n", vlc,
683  enable ? "enable" : "disable" );
684 
685  if (enable) {
686  /* Enable interrupts */
688  } else {
689  /* Disable interrupts */
691  }
692 }
#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:431
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 716 of file velocity.c.

716  {
717  struct net_device *netdev;
718  struct velocity_nic *vlc;
719  int rc;
720 
721  /* Allocate and initialise net device */
722  netdev = alloc_etherdev ( sizeof ( *vlc ) );
723  if ( ! netdev ) {
724  rc = -ENOMEM;
725  goto err_alloc;
726  }
728  vlc = netdev->priv;
729  pci_set_drvdata ( pci, netdev );
730  netdev->dev = &pci->dev;
731 
732  /* Fix up PCI device */
733  adjust_pci_device ( pci );
734 
735  /* Map registers */
736  vlc->regs = pci_ioremap ( pci, pci->membase, VELOCITY_BAR_SIZE );
737  vlc->netdev = netdev;
738 
739  /* Reset the NIC */
740  if ( ( rc = velocity_reset ( vlc ) ) != 0 )
741  goto err_reset;
742 
743  /* Reload EEPROM */
744  if ( ( rc = velocity_reload_eeprom ( vlc ) ) != 0 )
745  goto err_reset;
746 
747  /* Get MAC address */
748  netdev->hw_addr[0] = readb ( vlc->regs + VELOCITY_MAC0 );
749  netdev->hw_addr[1] = readb ( vlc->regs + VELOCITY_MAC1 );
750  netdev->hw_addr[2] = readb ( vlc->regs + VELOCITY_MAC2 );
751  netdev->hw_addr[3] = readb ( vlc->regs + VELOCITY_MAC3 );
752  netdev->hw_addr[4] = readb ( vlc->regs + VELOCITY_MAC4 );
753  netdev->hw_addr[5] = readb ( vlc->regs + VELOCITY_MAC5 );
754 
755  /* Initialise and reset MII interface */
757  mii_init ( &vlc->mii, &vlc->mdio, 0 );
758  if ( ( rc = mii_reset ( &vlc->mii ) ) != 0 ) {
759  DBGC ( vlc, "VELOCITY %p could not reset MII: %s\n",
760  vlc, strerror ( rc ) );
761  goto err_mii_reset;
762  }
763 
764  /* Enable proper link advertising */
765  velocity_set_link ( vlc );
766 
767  /* Register network device */
768  if ( ( rc = register_netdev ( netdev ) ) != 0 )
769  goto err_register_netdev;
770 
771  return 0;
772 
773  err_register_netdev:
774  err_mii_reset:
775  velocity_reset ( vlc );
776  err_reset:
778  netdev_put ( netdev );
779  err_alloc:
780  return rc;
781 }
unsigned long membase
Memory base.
Definition: pci.h:215
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:154
struct device dev
Generic device.
Definition: pci.h:208
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:515
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:359
#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:572
void * priv
Driver private data.
Definition: netdevice.h:431
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:695
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:759
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
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:364
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
struct net_device * netdev
Netdev.
Definition: velocity.h:333
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#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, 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_ioremap(), 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 788 of file velocity.c.

788  {
789  struct net_device *netdev = pci_get_drvdata ( pci );
790  struct velocity_nic *vlc = netdev->priv;
791 
792  /* Unregister network device */
794 
795  /* Reset card */
796  velocity_reset ( vlc );
797 
798  /* Free network device */
800  netdev_put ( netdev );
801 }
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
A Velocity network card.
Definition: velocity.h:325
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:528
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:369

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:517
static void velocity_close(struct net_device *netdev)
Close network device.
Definition: velocity.c:473
static void velocity_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: velocity.c:647
static int velocity_open(struct net_device *netdev)
Open network device.
Definition: velocity.c:426
static void velocity_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: velocity.c:679

Velocity network device operations.

Definition at line 695 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:303

Velocity PCI device IDs.

Definition at line 804 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:716
static void velocity_remove(struct pci_device *pci)
Remove PCI device.
Definition: velocity.c:788
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:804

Velocity PCI driver.

Definition at line 809 of file velocity.c.