iPXE
Functions | Variables
smscusb.c File Reference

SMSC USB Ethernet drivers. More...

#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <ipxe/usb.h>
#include <ipxe/usbnet.h>
#include <ipxe/ethernet.h>
#include <ipxe/profile.h>
#include <ipxe/fdt.h>
#include "smscusb.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int smscusb_raw_writel (struct smscusb_device *smscusb, unsigned int address, uint32_t value)
 Write register (without byte-swapping) More...
 
int smscusb_raw_readl (struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
 Read register (without byte-swapping) More...
 
static int smscusb_eeprom_wait (struct smscusb_device *smscusb, unsigned int e2p_base)
 Wait for EEPROM to become idle. More...
 
static int smscusb_eeprom_read_byte (struct smscusb_device *smscusb, unsigned int e2p_base, unsigned int address)
 Read byte from EEPROM. More...
 
static int smscusb_eeprom_read (struct smscusb_device *smscusb, unsigned int e2p_base, unsigned int address, void *data, size_t len)
 Read data from EEPROM. More...
 
int smscusb_eeprom_fetch_mac (struct smscusb_device *smscusb, unsigned int e2p_base)
 Fetch MAC address from EEPROM. More...
 
static int smscusb_otp_power_up (struct smscusb_device *smscusb, unsigned int otp_base)
 Power up OTP. More...
 
static int smscusb_otp_wait (struct smscusb_device *smscusb, unsigned int otp_base)
 Wait for OTP to become idle. More...
 
static int smscusb_otp_read_byte (struct smscusb_device *smscusb, unsigned int otp_base, unsigned int address)
 Read byte from OTP. More...
 
static int smscusb_otp_read (struct smscusb_device *smscusb, unsigned int otp_base, unsigned int address, void *data, size_t len)
 Read data from OTP. More...
 
int smscusb_otp_fetch_mac (struct smscusb_device *smscusb, unsigned int otp_base)
 Fetch MAC address from OTP. More...
 
int smscusb_fdt_fetch_mac (struct smscusb_device *smscusb)
 Fetch MAC address from device tree. More...
 
static int smscusb_mii_wait (struct smscusb_device *smscusb)
 Wait for MII to become idle. More...
 
static int smscusb_mii_read (struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg)
 Read from MII register. More...
 
static int smscusb_mii_write (struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg, unsigned int data)
 Write to MII register. More...
 
int smscusb_mii_check_link (struct smscusb_device *smscusb)
 Check link status. More...
 
int smscusb_mii_open (struct smscusb_device *smscusb, unsigned int phy_mask, unsigned int intrs)
 Enable PHY interrupts and update link status. More...
 
int smscusb_set_address (struct smscusb_device *smscusb, unsigned int addr_base)
 Set receive address. More...
 
int smscusb_set_filter (struct smscusb_device *smscusb, unsigned int filt_base)
 Set receive filter. More...
 
static void smscusb_intr_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete interrupt transfer. More...
 
static void smscusb_out_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk OUT transfer. More...
 

Variables

static struct profiler smscusb_intr_profiler __profiler
 Interrupt completion profiler. More...
 
struct mii_operations smscusb_mii_operations
 MII operations. More...
 
struct usb_endpoint_driver_operations smscusb_intr_operations
 Interrupt endpoint operations. More...
 
struct usb_endpoint_driver_operations smscusb_out_operations
 Bulk OUT endpoint operations. More...
 

Detailed Description

SMSC USB Ethernet drivers.

Definition in file smscusb.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ smscusb_raw_writel()

int smscusb_raw_writel ( struct smscusb_device smscusb,
unsigned int  address,
uint32_t  value 
)

Write register (without byte-swapping)

Parameters
smscusbSmscusb device
addressRegister address
valueRegister value
Return values
rcReturn status code

Definition at line 61 of file smscusb.c.

62  {
63  int rc;
64 
65  /* Write register */
66  DBGCIO ( smscusb, "SMSCUSB %p [%03x] <= %08x\n",
67  smscusb, address, le32_to_cpu ( value ) );
68  if ( ( rc = usb_control ( smscusb->usb, SMSCUSB_REGISTER_WRITE, 0,
69  address, &value, sizeof ( value ) ) ) != 0 ) {
70  DBGC ( smscusb, "SMSCUSB %p could not write %03x: %s\n",
71  smscusb, address, strerror ( rc ) );
72  return rc;
73  }
74 
75  return 0;
76 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define le32_to_cpu(value)
Definition: byteswap.h:113
#define SMSCUSB_REGISTER_WRITE
Register write command.
Definition: smscusb.h:22
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
struct usb_device * usb
USB device.
Definition: smscusb.h:149
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition: usb.c:783
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define DBGCIO(...)
Definition: compiler.h:556

References address, DBGC, DBGCIO, le32_to_cpu, rc, SMSCUSB_REGISTER_WRITE, strerror(), smscusb_device::usb, usb_control(), and value.

Referenced by smscusb_set_address(), and smscusb_set_filter().

◆ smscusb_raw_readl()

int smscusb_raw_readl ( struct smscusb_device smscusb,
unsigned int  address,
uint32_t value 
)

Read register (without byte-swapping)

Parameters
smscusbSMSC USB device
addressRegister address
Return values
valueRegister value
rcReturn status code

Definition at line 86 of file smscusb.c.

87  {
88  int rc;
89 
90  /* Read register */
91  if ( ( rc = usb_control ( smscusb->usb, SMSCUSB_REGISTER_READ, 0,
92  address, value, sizeof ( *value ) ) ) != 0 ) {
93  DBGC ( smscusb, "SMSCUSB %p could not read %03x: %s\n",
94  smscusb, address, strerror ( rc ) );
95  return rc;
96  }
97  DBGCIO ( smscusb, "SMSCUSB %p [%03x] => %08x\n",
98  smscusb, address, le32_to_cpu ( *value ) );
99 
100  return 0;
101 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define le32_to_cpu(value)
Definition: byteswap.h:113
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
struct usb_device * usb
USB device.
Definition: smscusb.h:149
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition: usb.c:783
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define DBGCIO(...)
Definition: compiler.h:556
#define SMSCUSB_REGISTER_READ
Register read command.
Definition: smscusb.h:27

References address, DBGC, DBGCIO, le32_to_cpu, rc, SMSCUSB_REGISTER_READ, strerror(), smscusb_device::usb, usb_control(), and value.

◆ smscusb_eeprom_wait()

static int smscusb_eeprom_wait ( struct smscusb_device smscusb,
unsigned int  e2p_base 
)
static

Wait for EEPROM to become idle.

Parameters
smscusbSMSC USB device
e2p_baseE2P register base
Return values
rcReturn status code

Definition at line 117 of file smscusb.c.

118  {
119  uint32_t e2p_cmd;
120  unsigned int i;
121  int rc;
122 
123  /* Wait for EPC_BSY to become clear */
124  for ( i = 0 ; i < SMSCUSB_EEPROM_MAX_WAIT_MS ; i++ ) {
125 
126  /* Read E2P_CMD and check EPC_BSY */
127  if ( ( rc = smscusb_readl ( smscusb,
128  ( e2p_base + SMSCUSB_E2P_CMD ),
129  &e2p_cmd ) ) != 0 )
130  return rc;
131  if ( ! ( e2p_cmd & SMSCUSB_E2P_CMD_EPC_BSY ) )
132  return 0;
133 
134  /* Delay */
135  mdelay ( 1 );
136  }
137 
138  DBGC ( smscusb, "SMSCUSB %p timed out waiting for EEPROM\n",
139  smscusb );
140  return -ETIMEDOUT;
141 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static int smscusb_readl(struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
Read register.
Definition: smscusb.h:203
#define SMSCUSB_E2P_CMD_EPC_BSY
EPC busy.
Definition: smscusb.h:38
unsigned int uint32_t
Definition: stdint.h:12
#define SMSCUSB_EEPROM_MAX_WAIT_MS
Maximum time to wait for EEPROM (in milliseconds)
Definition: smscusb.h:52
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define SMSCUSB_E2P_CMD
EEPROM command register offset.
Definition: smscusb.h:37
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References DBGC, ETIMEDOUT, mdelay(), rc, SMSCUSB_E2P_CMD, SMSCUSB_E2P_CMD_EPC_BSY, SMSCUSB_EEPROM_MAX_WAIT_MS, and smscusb_readl().

Referenced by smscusb_eeprom_read_byte().

◆ smscusb_eeprom_read_byte()

static int smscusb_eeprom_read_byte ( struct smscusb_device smscusb,
unsigned int  e2p_base,
unsigned int  address 
)
static

Read byte from EEPROM.

Parameters
smscusbSMSC USB device
e2p_baseE2P register base
addressEEPROM address
Return values
byteByte read, or negative error

Definition at line 151 of file smscusb.c.

153  {
154  uint32_t e2p_cmd;
155  uint32_t e2p_data;
156  int rc;
157 
158  /* Wait for EEPROM to become idle */
159  if ( ( rc = smscusb_eeprom_wait ( smscusb, e2p_base ) ) != 0 )
160  return rc;
161 
162  /* Initiate read command */
165  if ( ( rc = smscusb_writel ( smscusb, ( e2p_base + SMSCUSB_E2P_CMD ),
166  e2p_cmd ) ) != 0 )
167  return rc;
168 
169  /* Wait for command to complete */
170  if ( ( rc = smscusb_eeprom_wait ( smscusb, e2p_base ) ) != 0 )
171  return rc;
172 
173  /* Read EEPROM data */
174  if ( ( rc = smscusb_readl ( smscusb, ( e2p_base + SMSCUSB_E2P_DATA ),
175  &e2p_data ) ) != 0 )
176  return rc;
177 
178  return SMSCUSB_E2P_DATA_GET ( e2p_data );
179 }
#define SMSCUSB_E2P_CMD_EPC_ADDR(addr)
EPC address.
Definition: smscusb.h:40
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t address
Base address.
Definition: ena.h:24
static int smscusb_writel(struct smscusb_device *smscusb, unsigned int address, uint32_t value)
Write register.
Definition: smscusb.h:182
static int smscusb_readl(struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
Read register.
Definition: smscusb.h:203
#define SMSCUSB_E2P_CMD_EPC_BSY
EPC busy.
Definition: smscusb.h:38
#define SMSCUSB_E2P_DATA_GET(e2p_data)
EEPROM data.
Definition: smscusb.h:44
static int smscusb_eeprom_wait(struct smscusb_device *smscusb, unsigned int e2p_base)
Wait for EEPROM to become idle.
Definition: smscusb.c:117
unsigned int uint32_t
Definition: stdint.h:12
#define SMSCUSB_E2P_CMD
EEPROM command register offset.
Definition: smscusb.h:37
#define SMSCUSB_E2P_CMD_EPC_CMD_READ
READ command.
Definition: smscusb.h:39
#define SMSCUSB_E2P_DATA
EEPROM data register offset.
Definition: smscusb.h:43

References address, rc, SMSCUSB_E2P_CMD, SMSCUSB_E2P_CMD_EPC_ADDR, SMSCUSB_E2P_CMD_EPC_BSY, SMSCUSB_E2P_CMD_EPC_CMD_READ, SMSCUSB_E2P_DATA, SMSCUSB_E2P_DATA_GET, smscusb_eeprom_wait(), smscusb_readl(), and smscusb_writel().

Referenced by smscusb_eeprom_read().

◆ smscusb_eeprom_read()

static int smscusb_eeprom_read ( struct smscusb_device smscusb,
unsigned int  e2p_base,
unsigned int  address,
void *  data,
size_t  len 
)
static

Read data from EEPROM.

Parameters
smscusbSMSC USB device
e2p_baseE2P register base
addressEEPROM address
dataData buffer
lenLength of data
Return values
rcReturn status code

Definition at line 191 of file smscusb.c.

193  {
194  uint8_t *bytes;
195  int byte;
196 
197  /* Read bytes */
198  for ( bytes = data ; len-- ; address++, bytes++ ) {
199  byte = smscusb_eeprom_read_byte ( smscusb, e2p_base, address );
200  if ( byte < 0 )
201  return byte;
202  *bytes = byte;
203  }
204 
205  return 0;
206 }
uint64_t address
Base address.
Definition: ena.h:24
unsigned char uint8_t
Definition: stdint.h:10
unsigned char byte
Definition: smc9000.h:38
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static int smscusb_eeprom_read_byte(struct smscusb_device *smscusb, unsigned int e2p_base, unsigned int address)
Read byte from EEPROM.
Definition: smscusb.c:151
uint8_t bytes[64]
Definition: ib_mad.h:16

References address, bytes, data, len, and smscusb_eeprom_read_byte().

Referenced by smscusb_eeprom_fetch_mac().

◆ smscusb_eeprom_fetch_mac()

int smscusb_eeprom_fetch_mac ( struct smscusb_device smscusb,
unsigned int  e2p_base 
)

Fetch MAC address from EEPROM.

Parameters
smscusbSMSC USB device
e2p_baseE2P register base
Return values
rcReturn status code

Definition at line 215 of file smscusb.c.

216  {
217  struct net_device *netdev = smscusb->netdev;
218  int rc;
219 
220  /* Read MAC address from EEPROM */
221  if ( ( rc = smscusb_eeprom_read ( smscusb, e2p_base, SMSCUSB_EEPROM_MAC,
222  netdev->hw_addr, ETH_ALEN ) ) != 0 )
223  return rc;
224 
225  /* Check that EEPROM is physically present */
226  if ( ! is_valid_ether_addr ( netdev->hw_addr ) ) {
227  DBGC ( smscusb, "SMSCUSB %p has no EEPROM MAC (%s)\n",
228  smscusb, eth_ntoa ( netdev->hw_addr ) );
229  return -ENODEV;
230  }
231 
232  DBGC ( smscusb, "SMSCUSB %p using EEPROM MAC %s\n",
233  smscusb, eth_ntoa ( netdev->hw_addr ) );
234  return 0;
235 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define SMSCUSB_EEPROM_MAC
MAC address EEPROM address.
Definition: smscusb.h:49
#define DBGC(...)
Definition: compiler.h:505
static struct net_device * netdev
Definition: gdbudp.c:52
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
A network device.
Definition: netdevice.h:352
#define ENODEV
No such device.
Definition: errno.h:509
#define ETH_ALEN
Definition: if_ether.h:8
static int is_valid_ether_addr(const void *addr)
Check if Ethernet address is valid.
Definition: ethernet.h:77
static int smscusb_eeprom_read(struct smscusb_device *smscusb, unsigned int e2p_base, unsigned int address, void *data, size_t len)
Read data from EEPROM.
Definition: smscusb.c:191
struct net_device * netdev
Network device.
Definition: smscusb.h:153
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381

References DBGC, ENODEV, ETH_ALEN, eth_ntoa(), net_device::hw_addr, is_valid_ether_addr(), netdev, smscusb_device::netdev, rc, SMSCUSB_EEPROM_MAC, and smscusb_eeprom_read().

Referenced by lan78xx_eeprom_fetch_mac(), smsc75xx_probe(), and smsc95xx_fetch_mac().

◆ smscusb_otp_power_up()

static int smscusb_otp_power_up ( struct smscusb_device smscusb,
unsigned int  otp_base 
)
static

Power up OTP.

Parameters
smscusbSMSC USB device
otp_baseOTP register base
Return values
rcReturn status code

Definition at line 251 of file smscusb.c.

252  {
253  uint32_t otp_power;
254  unsigned int i;
255  int rc;
256 
257  /* Power up OTP */
258  if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_POWER ),
259  0 ) ) != 0 )
260  return rc;
261 
262  /* Wait for OTP_POWER_DOWN to become clear */
263  for ( i = 0 ; i < SMSCUSB_OTP_MAX_WAIT_MS ; i++ ) {
264 
265  /* Read OTP_POWER and check OTP_POWER_DOWN */
266  if ( ( rc = smscusb_readl ( smscusb,
267  ( otp_base + SMSCUSB_OTP_POWER ),
268  &otp_power ) ) != 0 )
269  return rc;
270  if ( ! ( otp_power & SMSCUSB_OTP_POWER_DOWN ) )
271  return 0;
272 
273  /* Delay */
274  mdelay ( 1 );
275  }
276 
277  DBGC ( smscusb, "SMSCUSB %p timed out waiting for OTP power up\n",
278  smscusb );
279  return -ETIMEDOUT;
280 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static int smscusb_writel(struct smscusb_device *smscusb, unsigned int address, uint32_t value)
Write register.
Definition: smscusb.h:182
#define SMSCUSB_OTP_MAX_WAIT_MS
Maximum time to wait for OTP (in milliseconds)
Definition: smscusb.h:83
static int smscusb_readl(struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
Read register.
Definition: smscusb.h:203
unsigned int uint32_t
Definition: stdint.h:12
#define SMSCUSB_OTP_POWER_DOWN
OTP power down.
Definition: smscusb.h:56
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define SMSCUSB_OTP_POWER
OTP power register offset.
Definition: smscusb.h:55
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References DBGC, ETIMEDOUT, mdelay(), rc, SMSCUSB_OTP_MAX_WAIT_MS, SMSCUSB_OTP_POWER, SMSCUSB_OTP_POWER_DOWN, smscusb_readl(), and smscusb_writel().

Referenced by smscusb_otp_read().

◆ smscusb_otp_wait()

static int smscusb_otp_wait ( struct smscusb_device smscusb,
unsigned int  otp_base 
)
static

Wait for OTP to become idle.

Parameters
smscusbSMSC USB device
otp_baseOTP register base
Return values
rcReturn status code

Definition at line 289 of file smscusb.c.

290  {
291  uint32_t otp_status;
292  unsigned int i;
293  int rc;
294 
295  /* Wait for OTP_STATUS_BUSY to become clear */
296  for ( i = 0 ; i < SMSCUSB_OTP_MAX_WAIT_MS ; i++ ) {
297 
298  /* Read OTP_STATUS and check OTP_STATUS_BUSY */
299  if ( ( rc = smscusb_readl ( smscusb,
300  ( otp_base + SMSCUSB_OTP_STATUS ),
301  &otp_status ) ) != 0 )
302  return rc;
303  if ( ! ( otp_status & SMSCUSB_OTP_STATUS_BUSY ) )
304  return 0;
305 
306  /* Delay */
307  mdelay ( 1 );
308  }
309 
310  DBGC ( smscusb, "SMSCUSB %p timed out waiting for OTP\n",
311  smscusb );
312  return -ETIMEDOUT;
313 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define SMSCUSB_OTP_STATUS
OTP status register offset.
Definition: smscusb.h:79
#define DBGC(...)
Definition: compiler.h:505
#define SMSCUSB_OTP_MAX_WAIT_MS
Maximum time to wait for OTP (in milliseconds)
Definition: smscusb.h:83
static int smscusb_readl(struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
Read register.
Definition: smscusb.h:203
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define SMSCUSB_OTP_STATUS_BUSY
OTP busy.
Definition: smscusb.h:80
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References DBGC, ETIMEDOUT, mdelay(), rc, SMSCUSB_OTP_MAX_WAIT_MS, SMSCUSB_OTP_STATUS, SMSCUSB_OTP_STATUS_BUSY, and smscusb_readl().

Referenced by smscusb_otp_read_byte().

◆ smscusb_otp_read_byte()

static int smscusb_otp_read_byte ( struct smscusb_device smscusb,
unsigned int  otp_base,
unsigned int  address 
)
static

Read byte from OTP.

Parameters
smscusbSMSC USB device
otp_baseOTP register base
addressOTP address
Return values
byteByte read, or negative error

Definition at line 323 of file smscusb.c.

325  {
326  uint8_t addrh = ( address >> 8 );
327  uint8_t addrl = ( address >> 0 );
328  uint32_t otp_data;
329  int rc;
330 
331  /* Wait for OTP to become idle */
332  if ( ( rc = smscusb_otp_wait ( smscusb, otp_base ) ) != 0 )
333  return rc;
334 
335  /* Initiate read command */
336  if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_ADDRH ),
337  addrh ) ) != 0 )
338  return rc;
339  if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_ADDRL ),
340  addrl ) ) != 0 )
341  return rc;
342  if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_CMD ),
343  SMSCUSB_OTP_CMD_READ ) ) != 0 )
344  return rc;
345  if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_GO ),
346  SMSCUSB_OTP_GO_GO ) ) != 0 )
347  return rc;
348 
349  /* Wait for command to complete */
350  if ( ( rc = smscusb_otp_wait ( smscusb, otp_base ) ) != 0 )
351  return rc;
352 
353  /* Read OTP data */
354  if ( ( rc = smscusb_readl ( smscusb, ( otp_base + SMSCUSB_OTP_DATA ),
355  &otp_data ) ) != 0 )
356  return rc;
357 
358  return SMSCUSB_OTP_DATA_GET ( otp_data );
359 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t address
Base address.
Definition: ena.h:24
static int smscusb_writel(struct smscusb_device *smscusb, unsigned int address, uint32_t value)
Write register.
Definition: smscusb.h:182
#define SMSCUSB_OTP_DATA_GET(otp_data)
OTP data.
Definition: smscusb.h:66
#define SMSCUSB_OTP_CMD
OTP command selection register offset.
Definition: smscusb.h:71
#define SMSCUSB_OTP_GO_GO
Initiate command.
Definition: smscusb.h:76
#define SMSCUSB_OTP_CMD_READ
Read command.
Definition: smscusb.h:72
static int smscusb_otp_wait(struct smscusb_device *smscusb, unsigned int otp_base)
Wait for OTP to become idle.
Definition: smscusb.c:289
static int smscusb_readl(struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
Read register.
Definition: smscusb.h:203
#define SMSCUSB_OTP_ADDRH
OTP address high byte register offset.
Definition: smscusb.h:59
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
#define SMSCUSB_OTP_DATA
OTP data register offset.
Definition: smscusb.h:65
#define SMSCUSB_OTP_GO
OTP command initiation register offset.
Definition: smscusb.h:75
#define SMSCUSB_OTP_ADDRL
OTP address low byte register offset.
Definition: smscusb.h:62

References address, rc, SMSCUSB_OTP_ADDRH, SMSCUSB_OTP_ADDRL, SMSCUSB_OTP_CMD, SMSCUSB_OTP_CMD_READ, SMSCUSB_OTP_DATA, SMSCUSB_OTP_DATA_GET, SMSCUSB_OTP_GO, SMSCUSB_OTP_GO_GO, smscusb_otp_wait(), smscusb_readl(), and smscusb_writel().

Referenced by smscusb_otp_read().

◆ smscusb_otp_read()

static int smscusb_otp_read ( struct smscusb_device smscusb,
unsigned int  otp_base,
unsigned int  address,
void *  data,
size_t  len 
)
static

Read data from OTP.

Parameters
smscusbSMSC USB device
otp_baseOTP register base
addressOTP address
dataData buffer
lenLength of data
Return values
rcReturn status code

Definition at line 371 of file smscusb.c.

373  {
374  uint8_t *bytes;
375  int byte;
376  int rc;
377 
378  /* Power up OTP */
379  if ( ( rc = smscusb_otp_power_up ( smscusb, otp_base ) ) != 0 )
380  return rc;
381 
382  /* Read bytes */
383  for ( bytes = data ; len-- ; address++, bytes++ ) {
384  byte = smscusb_otp_read_byte ( smscusb, otp_base, address );
385  if ( byte < 0 )
386  return byte;
387  *bytes = byte;
388  }
389 
390  return 0;
391 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int smscusb_otp_read_byte(struct smscusb_device *smscusb, unsigned int otp_base, unsigned int address)
Read byte from OTP.
Definition: smscusb.c:323
uint64_t address
Base address.
Definition: ena.h:24
static int smscusb_otp_power_up(struct smscusb_device *smscusb, unsigned int otp_base)
Power up OTP.
Definition: smscusb.c:251
unsigned char uint8_t
Definition: stdint.h:10
unsigned char byte
Definition: smc9000.h:38
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint8_t bytes[64]
Definition: ib_mad.h:16

References address, bytes, data, len, rc, smscusb_otp_power_up(), and smscusb_otp_read_byte().

Referenced by smscusb_otp_fetch_mac().

◆ smscusb_otp_fetch_mac()

int smscusb_otp_fetch_mac ( struct smscusb_device smscusb,
unsigned int  otp_base 
)

Fetch MAC address from OTP.

Parameters
smscusbSMSC USB device
otp_baseOTP register base
Return values
rcReturn status code

Definition at line 400 of file smscusb.c.

401  {
402  struct net_device *netdev = smscusb->netdev;
404  unsigned int address;
405  int rc;
406 
407  /* Read OTP signature byte */
408  if ( ( rc = smscusb_otp_read ( smscusb, otp_base, 0, &signature,
409  sizeof ( signature ) ) ) != 0 )
410  return rc;
411 
412  /* Determine location of MAC address */
413  switch ( signature ) {
414  case SMSCUSB_OTP_1_SIG:
416  break;
417  case SMSCUSB_OTP_2_SIG:
419  break;
420  default:
421  DBGC ( smscusb, "SMSCUSB %p unknown OTP signature %#02x\n",
422  smscusb, signature );
423  return -ENOTSUP;
424  }
425 
426  /* Read MAC address from OTP */
427  if ( ( rc = smscusb_otp_read ( smscusb, otp_base, address,
428  netdev->hw_addr, ETH_ALEN ) ) != 0 )
429  return rc;
430 
431  /* Check that OTP is valid */
432  if ( ! is_valid_ether_addr ( netdev->hw_addr ) ) {
433  DBGC ( smscusb, "SMSCUSB %p has no layout %#02x OTP MAC (%s)\n",
434  smscusb, signature, eth_ntoa ( netdev->hw_addr ) );
435  return -ENODEV;
436  }
437 
438  DBGC ( smscusb, "SMSCUSB %p using layout %#02x OTP MAC %s\n",
439  smscusb, signature, eth_ntoa ( netdev->hw_addr ) );
440  return 0;
441 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t address
Base address.
Definition: ena.h:24
#define SMSCUSB_OTP_1_MAC
OTP layout 1 MAC address offset.
Definition: smscusb.h:89
#define DBGC(...)
Definition: compiler.h:505
#define SMSCUSB_OTP_2_MAC
OTP layout 2 MAC address offset.
Definition: smscusb.h:95
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define SMSCUSB_OTP_2_SIG
OTP layout 2 signature.
Definition: smscusb.h:92
static struct net_device * netdev
Definition: gdbudp.c:52
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
A network device.
Definition: netdevice.h:352
#define ENODEV
No such device.
Definition: errno.h:509
unsigned char uint8_t
Definition: stdint.h:10
#define ETH_ALEN
Definition: if_ether.h:8
static int is_valid_ether_addr(const void *addr)
Check if Ethernet address is valid.
Definition: ethernet.h:77
struct net_device * netdev
Network device.
Definition: smscusb.h:153
static int smscusb_otp_read(struct smscusb_device *smscusb, unsigned int otp_base, unsigned int address, void *data, size_t len)
Read data from OTP.
Definition: smscusb.c:371
#define SMSCUSB_OTP_1_SIG
OTP layout 1 signature.
Definition: smscusb.h:86
u8 signature
Signature.
Definition: CIB_PRM.h:35
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381

References address, DBGC, ENODEV, ENOTSUP, ETH_ALEN, eth_ntoa(), net_device::hw_addr, is_valid_ether_addr(), netdev, smscusb_device::netdev, rc, signature, SMSCUSB_OTP_1_MAC, SMSCUSB_OTP_1_SIG, SMSCUSB_OTP_2_MAC, SMSCUSB_OTP_2_SIG, and smscusb_otp_read().

Referenced by lan78xx_fetch_mac().

◆ smscusb_fdt_fetch_mac()

int smscusb_fdt_fetch_mac ( struct smscusb_device smscusb)

Fetch MAC address from device tree.

Parameters
smscusbSMSC USB device
Return values
rcReturn status code

Definition at line 456 of file smscusb.c.

456  {
457  struct net_device *netdev = smscusb->netdev;
458  unsigned int offset;
459  int rc;
460 
461  /* Look for "ethernet[0]" alias */
462  if ( ( rc = fdt_alias ( "ethernet", &offset ) != 0 ) &&
463  ( rc = fdt_alias ( "ethernet0", &offset ) != 0 ) ) {
464  return rc;
465  }
466 
467  /* Fetch MAC address */
468  if ( ( rc = fdt_mac ( offset, netdev ) ) != 0 )
469  return rc;
470 
471  DBGC ( smscusb, "SMSCUSB %p using FDT MAC %s\n",
472  smscusb, eth_ntoa ( netdev->hw_addr ) );
473  return 0;
474 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int fdt_mac(unsigned int offset, struct net_device *netdev)
Get MAC address from property.
Definition: fdt.c:377
#define DBGC(...)
Definition: compiler.h:505
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static struct net_device * netdev
Definition: gdbudp.c:52
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
A network device.
Definition: netdevice.h:352
struct net_device * netdev
Network device.
Definition: smscusb.h:153
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
int fdt_alias(const char *name, unsigned int *offset)
Find node by alias.
Definition: fdt.c:284

References DBGC, eth_ntoa(), fdt_alias(), fdt_mac(), net_device::hw_addr, netdev, smscusb_device::netdev, offset, and rc.

Referenced by lan78xx_fetch_mac(), and smsc95xx_fetch_mac().

◆ smscusb_mii_wait()

static int smscusb_mii_wait ( struct smscusb_device smscusb)
static

Wait for MII to become idle.

Parameters
smscusbSMSC USB device
Return values
rcReturn status code

Definition at line 489 of file smscusb.c.

489  {
490  unsigned int base = smscusb->mii_base;
491  uint32_t mii_access;
492  unsigned int i;
493  int rc;
494 
495  /* Wait for MIIBZY to become clear */
496  for ( i = 0 ; i < SMSCUSB_MII_MAX_WAIT_MS ; i++ ) {
497 
498  /* Read MII_ACCESS and check MIIBZY */
499  if ( ( rc = smscusb_readl ( smscusb,
500  ( base + SMSCUSB_MII_ACCESS ),
501  &mii_access ) ) != 0 )
502  return rc;
503  if ( ! ( mii_access & SMSCUSB_MII_ACCESS_MIIBZY ) )
504  return 0;
505 
506  /* Delay */
507  mdelay ( 1 );
508  }
509 
510  DBGC ( smscusb, "SMSCUSB %p timed out waiting for MII\n",
511  smscusb );
512  return -ETIMEDOUT;
513 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static const void * base
Base address.
Definition: crypto.h:335
#define SMSCUSB_MII_MAX_WAIT_MS
Maximum time to wait for MII (in milliseconds)
Definition: smscusb.h:112
static int smscusb_readl(struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
Read register.
Definition: smscusb.h:203
#define SMSCUSB_MII_ACCESS_MIIBZY
MII busy.
Definition: smscusb.h:102
unsigned int uint32_t
Definition: stdint.h:12
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define SMSCUSB_MII_ACCESS
MII access register offset.
Definition: smscusb.h:98
uint16_t mii_base
MII register base.
Definition: smscusb.h:161
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References base, DBGC, ETIMEDOUT, mdelay(), smscusb_device::mii_base, rc, SMSCUSB_MII_ACCESS, SMSCUSB_MII_ACCESS_MIIBZY, SMSCUSB_MII_MAX_WAIT_MS, and smscusb_readl().

Referenced by smscusb_mii_read(), and smscusb_mii_write().

◆ smscusb_mii_read()

static int smscusb_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 523 of file smscusb.c.

524  {
525  struct smscusb_device *smscusb =
526  container_of ( mdio, struct smscusb_device, mdio );
527  unsigned int base = smscusb->mii_base;
528  uint32_t mii_access;
529  uint32_t mii_data;
530  int rc;
531 
532  /* Wait for MII to become idle */
533  if ( ( rc = smscusb_mii_wait ( smscusb ) ) != 0 )
534  return rc;
535 
536  /* Initiate read command */
537  mii_access = ( SMSCUSB_MII_ACCESS_PHY_ADDRESS |
540  if ( ( rc = smscusb_writel ( smscusb, ( base + SMSCUSB_MII_ACCESS ),
541  mii_access ) ) != 0 )
542  return rc;
543 
544  /* Wait for command to complete */
545  if ( ( rc = smscusb_mii_wait ( smscusb ) ) != 0 )
546  return rc;
547 
548  /* Read MII data */
549  if ( ( rc = smscusb_readl ( smscusb, ( base + SMSCUSB_MII_DATA ),
550  &mii_data ) ) != 0 )
551  return rc;
552 
553  return SMSCUSB_MII_DATA_GET ( mii_data );
554 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static unsigned int unsigned int reg
Definition: myson.h:162
An SMSC USB device.
Definition: smscusb.h:147
static int smscusb_writel(struct smscusb_device *smscusb, unsigned int address, uint32_t value)
Write register.
Definition: smscusb.h:182
static const void * base
Base address.
Definition: crypto.h:335
#define SMSCUSB_MII_DATA
MII data register offset.
Definition: smscusb.h:105
#define SMSCUSB_MII_ACCESS_MIIRINDA(addr)
MII register.
Definition: smscusb.h:100
#define SMSCUSB_MII_DATA_GET(mii_data)
Get data.
Definition: smscusb.h:107
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define SMSCUSB_MII_ACCESS_PHY_ADDRESS
PHY address.
Definition: smscusb.h:99
static int smscusb_readl(struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
Read register.
Definition: smscusb.h:203
#define SMSCUSB_MII_ACCESS_MIIBZY
MII busy.
Definition: smscusb.h:102
static int smscusb_mii_wait(struct smscusb_device *smscusb)
Wait for MII to become idle.
Definition: smscusb.c:489
struct mii_interface mdio
MII interface.
Definition: smscusb.h:157
unsigned int uint32_t
Definition: stdint.h:12
#define SMSCUSB_MII_ACCESS
MII access register offset.
Definition: smscusb.h:98
uint16_t mii_base
MII register base.
Definition: smscusb.h:161

References base, container_of, smscusb_device::mdio, smscusb_device::mii_base, rc, reg, SMSCUSB_MII_ACCESS, SMSCUSB_MII_ACCESS_MIIBZY, SMSCUSB_MII_ACCESS_MIIRINDA, SMSCUSB_MII_ACCESS_PHY_ADDRESS, SMSCUSB_MII_DATA, SMSCUSB_MII_DATA_GET, smscusb_mii_wait(), smscusb_readl(), and smscusb_writel().

◆ smscusb_mii_write()

static int smscusb_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 565 of file smscusb.c.

567  {
568  struct smscusb_device *smscusb =
569  container_of ( mdio, struct smscusb_device, mdio );
570  unsigned int base = smscusb->mii_base;
571  uint32_t mii_access;
572  uint32_t mii_data;
573  int rc;
574 
575  /* Wait for MII to become idle */
576  if ( ( rc = smscusb_mii_wait ( smscusb ) ) != 0 )
577  return rc;
578 
579  /* Write MII data */
580  mii_data = SMSCUSB_MII_DATA_SET ( data );
581  if ( ( rc = smscusb_writel ( smscusb, ( base + SMSCUSB_MII_DATA ),
582  mii_data ) ) != 0 )
583  return rc;
584 
585  /* Initiate write command */
586  mii_access = ( SMSCUSB_MII_ACCESS_PHY_ADDRESS |
590  if ( ( rc = smscusb_writel ( smscusb, ( base + SMSCUSB_MII_ACCESS ),
591  mii_access ) ) != 0 )
592  return rc;
593 
594  /* Wait for command to complete */
595  if ( ( rc = smscusb_mii_wait ( smscusb ) ) != 0 )
596  return rc;
597 
598  return 0;
599 }
#define SMSCUSB_MII_ACCESS_MIIWNR
MII write.
Definition: smscusb.h:101
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static unsigned int unsigned int reg
Definition: myson.h:162
An SMSC USB device.
Definition: smscusb.h:147
static int smscusb_writel(struct smscusb_device *smscusb, unsigned int address, uint32_t value)
Write register.
Definition: smscusb.h:182
static const void * base
Base address.
Definition: crypto.h:335
#define SMSCUSB_MII_DATA
MII data register offset.
Definition: smscusb.h:105
#define SMSCUSB_MII_ACCESS_MIIRINDA(addr)
MII register.
Definition: smscusb.h:100
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define SMSCUSB_MII_ACCESS_PHY_ADDRESS
PHY address.
Definition: smscusb.h:99
#define SMSCUSB_MII_ACCESS_MIIBZY
MII busy.
Definition: smscusb.h:102
#define SMSCUSB_MII_DATA_SET(data)
Set data.
Definition: smscusb.h:106
static int smscusb_mii_wait(struct smscusb_device *smscusb)
Wait for MII to become idle.
Definition: smscusb.c:489
struct mii_interface mdio
MII interface.
Definition: smscusb.h:157
unsigned int uint32_t
Definition: stdint.h:12
#define SMSCUSB_MII_ACCESS
MII access register offset.
Definition: smscusb.h:98
uint16_t mii_base
MII register base.
Definition: smscusb.h:161
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References base, container_of, data, smscusb_device::mdio, smscusb_device::mii_base, rc, reg, SMSCUSB_MII_ACCESS, SMSCUSB_MII_ACCESS_MIIBZY, SMSCUSB_MII_ACCESS_MIIRINDA, SMSCUSB_MII_ACCESS_MIIWNR, SMSCUSB_MII_ACCESS_PHY_ADDRESS, SMSCUSB_MII_DATA, SMSCUSB_MII_DATA_SET, smscusb_mii_wait(), and smscusb_writel().

◆ smscusb_mii_check_link()

int smscusb_mii_check_link ( struct smscusb_device smscusb)

Check link status.

Parameters
smscusbSMSC USB device
Return values
rcReturn status code

Definition at line 613 of file smscusb.c.

613  {
614  struct net_device *netdev = smscusb->netdev;
615  int intr;
616  int rc;
617 
618  /* Read PHY interrupt source */
619  intr = mii_read ( &smscusb->mii, smscusb->phy_source );
620  if ( intr < 0 ) {
621  rc = intr;
622  DBGC ( smscusb, "SMSCUSB %p could not get PHY interrupt "
623  "source: %s\n", smscusb, strerror ( rc ) );
624  return rc;
625  }
626 
627  /* Acknowledge PHY interrupt */
628  if ( ( rc = mii_write ( &smscusb->mii, smscusb->phy_source,
629  intr ) ) != 0 ) {
630  DBGC ( smscusb, "SMSCUSB %p could not acknowledge PHY "
631  "interrupt: %s\n", smscusb, strerror ( rc ) );
632  return rc;
633  }
634 
635  /* Check link status */
636  if ( ( rc = mii_check_link ( &smscusb->mii, netdev ) ) != 0 ) {
637  DBGC ( smscusb, "SMSCUSB %p could not check link: %s\n",
638  smscusb, strerror ( rc ) );
639  return rc;
640  }
641 
642  DBGC ( smscusb, "SMSCUSB %p link %s (intr %#04x)\n",
643  smscusb, ( netdev_link_ok ( netdev ) ? "up" : "down" ), intr );
644  return 0;
645 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
uint16_t phy_source
PHY interrupt source register.
Definition: smscusb.h:163
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:636
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A network device.
Definition: netdevice.h:352
struct mii_device mii
MII device.
Definition: smscusb.h:159
int mii_check_link(struct mii_device *mii, struct net_device *netdev)
Update link status via MII.
Definition: mii.c:126
static int mii_read(int phy_id, int location)
Definition: epic100.c:499
struct net_device * netdev
Network device.
Definition: smscusb.h:153
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:104

References DBGC, intr, smscusb_device::mii, mii_check_link(), mii_read(), mii_write(), netdev, smscusb_device::netdev, netdev_link_ok(), smscusb_device::phy_source, rc, and strerror().

Referenced by smsc75xx_poll(), smsc95xx_poll(), and smscusb_mii_open().

◆ smscusb_mii_open()

int smscusb_mii_open ( struct smscusb_device smscusb,
unsigned int  phy_mask,
unsigned int  intrs 
)

Enable PHY interrupts and update link status.

Parameters
smscusbSMSC USB device
phy_maskPHY interrupt mask register
intrsPHY interrupts to enable
Return values
rcReturn status code

Definition at line 655 of file smscusb.c.

656  {
657  int rc;
658 
659  /* Enable PHY interrupts */
660  if ( ( rc = mii_write ( &smscusb->mii, phy_mask, intrs ) ) != 0 ) {
661  DBGC ( smscusb, "SMSCUSB %p could not set PHY interrupt "
662  "mask: %s\n", smscusb, strerror ( rc ) );
663  return rc;
664  }
665 
666  /* Update link status */
667  smscusb_mii_check_link ( smscusb );
668 
669  return 0;
670 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct mii_device mii
MII device.
Definition: smscusb.h:159
int smscusb_mii_check_link(struct smscusb_device *smscusb)
Check link status.
Definition: smscusb.c:613
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:104

References DBGC, smscusb_device::mii, mii_write(), rc, smscusb_mii_check_link(), and strerror().

Referenced by lan78xx_open(), smsc75xx_open(), and smsc95xx_open().

◆ smscusb_set_address()

int smscusb_set_address ( struct smscusb_device smscusb,
unsigned int  addr_base 
)

Set receive address.

Parameters
smscusbSMSC USB device
addr_baseReceive address register base
Return values
rcReturn status code

Definition at line 686 of file smscusb.c.

687  {
688  struct net_device *netdev = smscusb->netdev;
689  union smscusb_mac mac;
690  int rc;
691 
692  /* Copy MAC address */
693  memset ( &mac, 0, sizeof ( mac ) );
694  memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN );
695 
696  /* Write MAC address high register */
697  if ( ( rc = smscusb_raw_writel ( smscusb,
698  ( addr_base + SMSCUSB_RX_ADDRH ),
699  mac.addr.h ) ) != 0 )
700  return rc;
701 
702  /* Write MAC address low register */
703  if ( ( rc = smscusb_raw_writel ( smscusb,
704  ( addr_base + SMSCUSB_RX_ADDRL ),
705  mac.addr.l ) ) != 0 )
706  return rc;
707 
708  return 0;
709 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
#define SMSCUSB_RX_ADDRH
MAC receive address high register offset.
Definition: smscusb.h:128
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct net_device * netdev
Definition: gdbudp.c:52
int smscusb_raw_writel(struct smscusb_device *smscusb, unsigned int address, uint32_t value)
Write register (without byte-swapping)
Definition: smscusb.c:61
MAC address.
Definition: smscusb.h:115
A network device.
Definition: netdevice.h:352
#define ETH_ALEN
Definition: if_ether.h:8
#define SMSCUSB_RX_ADDRL
MAC receive address low register offset.
Definition: smscusb.h:131
struct net_device * netdev
Network device.
Definition: smscusb.h:153
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
void * memset(void *dest, int character, size_t len) __nonnull

References ETH_ALEN, net_device::ll_addr, mac, memcpy(), memset(), netdev, smscusb_device::netdev, rc, smscusb_raw_writel(), SMSCUSB_RX_ADDRH, and SMSCUSB_RX_ADDRL.

Referenced by lan78xx_open(), smsc75xx_open(), and smsc95xx_open().

◆ smscusb_set_filter()

int smscusb_set_filter ( struct smscusb_device smscusb,
unsigned int  filt_base 
)

Set receive filter.

Parameters
smscusbSMSC USB device
filt_baseReceive filter register base
Return values
rcReturn status code

Definition at line 718 of file smscusb.c.

719  {
720  struct net_device *netdev = smscusb->netdev;
721  union smscusb_mac mac;
722  int rc;
723 
724  /* Copy MAC address */
725  memset ( &mac, 0, sizeof ( mac ) );
726  memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN );
728 
729  /* Write MAC address perfect filter high register */
730  if ( ( rc = smscusb_raw_writel ( smscusb,
731  ( filt_base + SMSCUSB_ADDR_FILTH(0) ),
732  mac.addr.h ) ) != 0 )
733  return rc;
734 
735  /* Write MAC address perfect filter low register */
736  if ( ( rc = smscusb_raw_writel ( smscusb,
737  ( filt_base + SMSCUSB_ADDR_FILTL(0) ),
738  mac.addr.l ) ) != 0 )
739  return rc;
740 
741  return 0;
742 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define SMSCUSB_ADDR_FILTH_VALID
Address valid.
Definition: smscusb.h:135
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct net_device * netdev
Definition: gdbudp.c:52
int smscusb_raw_writel(struct smscusb_device *smscusb, unsigned int address, uint32_t value)
Write register (without byte-swapping)
Definition: smscusb.c:61
#define SMSCUSB_ADDR_FILTL(n)
MAC address perfect filter N low register offset.
Definition: smscusb.h:138
MAC address.
Definition: smscusb.h:115
#define cpu_to_le32(value)
Definition: byteswap.h:107
A network device.
Definition: netdevice.h:352
#define SMSCUSB_ADDR_FILTH(n)
MAC address perfect filter N high register offset.
Definition: smscusb.h:134
#define ETH_ALEN
Definition: if_ether.h:8
struct net_device * netdev
Network device.
Definition: smscusb.h:153
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
void * memset(void *dest, int character, size_t len) __nonnull

References cpu_to_le32, ETH_ALEN, net_device::ll_addr, mac, memcpy(), memset(), netdev, smscusb_device::netdev, rc, SMSCUSB_ADDR_FILTH, SMSCUSB_ADDR_FILTH_VALID, SMSCUSB_ADDR_FILTL, and smscusb_raw_writel().

Referenced by lan78xx_open(), and smsc75xx_open().

◆ smscusb_intr_complete()

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

Complete interrupt transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 758 of file smscusb.c.

759  {
760  struct smscusb_device *smscusb =
761  container_of ( ep, struct smscusb_device, usbnet.intr );
762  struct net_device *netdev = smscusb->netdev;
763  struct smscusb_interrupt *intr;
764 
765  /* Profile completions */
766  profile_start ( &smscusb_intr_profiler );
767 
768  /* Ignore packets cancelled when the endpoint closes */
769  if ( ! ep->open )
770  goto done;
771 
772  /* Record USB errors against the network device */
773  if ( rc != 0 ) {
774  DBGC ( smscusb, "SMSCUSB %p interrupt failed: %s\n",
775  smscusb, strerror ( rc ) );
776  DBGC_HDA ( smscusb, 0, iobuf->data, iob_len ( iobuf ) );
777  netdev_rx_err ( netdev, NULL, rc );
778  goto done;
779  }
780 
781  /* Extract interrupt data */
782  if ( iob_len ( iobuf ) != sizeof ( *intr ) ) {
783  DBGC ( smscusb, "SMSCUSB %p malformed interrupt\n",
784  smscusb );
785  DBGC_HDA ( smscusb, 0, iobuf->data, iob_len ( iobuf ) );
786  netdev_rx_err ( netdev, NULL, rc );
787  goto done;
788  }
789  intr = iobuf->data;
790 
791  /* Record interrupt status */
792  smscusb->int_sts = le32_to_cpu ( intr->int_sts );
793  profile_stop ( &smscusb_intr_profiler );
794 
795  done:
796  /* Free I/O buffer */
797  free_iob ( iobuf );
798 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
Interrupt packet format.
Definition: smscusb.h:141
#define le32_to_cpu(value)
Definition: byteswap.h:113
An SMSC USB device.
Definition: smscusb.h:147
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:404
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:27
uint32_t int_sts
Interrupt status.
Definition: smscusb.h:165
struct usbnet_device usbnet
USB network device.
Definition: smscusb.h:155
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
#define DBGC_HDA(...)
Definition: compiler.h:506
static struct net_device * netdev
Definition: gdbudp.c:52
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
A network device.
Definition: netdevice.h:352
void * data
Start of data.
Definition: iobuf.h:48
struct net_device * netdev
Network device.
Definition: smscusb.h:153
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct bofm_section_header done
Definition: bofm_test.c:46

References container_of, io_buffer::data, DBGC, DBGC_HDA, done, free_iob(), smscusb_device::int_sts, intr, usbnet_device::intr, iob_len(), le32_to_cpu, netdev, smscusb_device::netdev, netdev_rx_err(), NULL, usb_endpoint::open, profile_start(), profile_stop(), rc, strerror(), and smscusb_device::usbnet.

◆ smscusb_out_complete()

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

Complete bulk OUT transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 812 of file smscusb.c.

813  {
814  struct smscusb_device *smscusb =
815  container_of ( ep, struct smscusb_device, usbnet.out );
816  struct net_device *netdev = smscusb->netdev;
817 
818  /* Report TX completion */
819  netdev_tx_complete_err ( netdev, iobuf, rc );
820 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An SMSC USB device.
Definition: smscusb.h:147
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
struct usbnet_device usbnet
USB network device.
Definition: smscusb.h:155
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:352
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:470
struct net_device * netdev
Network device.
Definition: smscusb.h:153

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

Variable Documentation

◆ __profiler

struct profiler smscusb_intr_profiler __profiler
static
Initial value:
=
{ .name = "smscusb.intr" }

Interrupt completion profiler.

Definition at line 43 of file smscusb.c.

◆ smscusb_mii_operations

struct mii_operations smscusb_mii_operations
Initial value:
= {
}
static int smscusb_mii_read(struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg)
Read from MII register.
Definition: smscusb.c:523
static int smscusb_mii_write(struct mii_interface *mdio, unsigned int phy __unused, unsigned int reg, unsigned int data)
Write to MII register.
Definition: smscusb.c:565

MII operations.

Definition at line 602 of file smscusb.c.

◆ smscusb_intr_operations

struct usb_endpoint_driver_operations smscusb_intr_operations
Initial value:
= {
.complete = smscusb_intr_complete,
}
static void smscusb_intr_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete interrupt transfer.
Definition: smscusb.c:758

Interrupt endpoint operations.

Definition at line 801 of file smscusb.c.

◆ smscusb_out_operations

struct usb_endpoint_driver_operations smscusb_out_operations
Initial value:
= {
.complete = smscusb_out_complete,
}
static void smscusb_out_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk OUT transfer.
Definition: smscusb.c:812

Bulk OUT endpoint operations.

Definition at line 823 of file smscusb.c.