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

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 62 of file smscusb.c.

63  {
64  int rc;
65 
66  /* Write register */
67  DBGCIO ( smscusb, "SMSCUSB %p [%03x] <= %08x\n",
68  smscusb, address, le32_to_cpu ( value ) );
69  if ( ( rc = usb_control ( smscusb->usb, SMSCUSB_REGISTER_WRITE, 0,
70  address, &value, sizeof ( value ) ) ) != 0 ) {
71  DBGC ( smscusb, "SMSCUSB %p could not write %03x: %s\n",
72  smscusb, address, strerror ( rc ) );
73  return rc;
74  }
75 
76  return 0;
77 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define le32_to_cpu(value)
Definition: byteswap.h:114
#define SMSCUSB_REGISTER_WRITE
Register write command.
Definition: smscusb.h:23
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
struct usb_device * usb
USB device.
Definition: smscusb.h:150
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:784
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#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 87 of file smscusb.c.

88  {
89  int rc;
90 
91  /* Read register */
92  if ( ( rc = usb_control ( smscusb->usb, SMSCUSB_REGISTER_READ, 0,
93  address, value, sizeof ( *value ) ) ) != 0 ) {
94  DBGC ( smscusb, "SMSCUSB %p could not read %03x: %s\n",
95  smscusb, address, strerror ( rc ) );
96  return rc;
97  }
98  DBGCIO ( smscusb, "SMSCUSB %p [%03x] => %08x\n",
99  smscusb, address, le32_to_cpu ( *value ) );
100 
101  return 0;
102 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define le32_to_cpu(value)
Definition: byteswap.h:114
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
struct usb_device * usb
USB device.
Definition: smscusb.h:150
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:784
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define DBGCIO(...)
Definition: compiler.h:556
#define SMSCUSB_REGISTER_READ
Register read command.
Definition: smscusb.h:28

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 118 of file smscusb.c.

119  {
120  uint32_t e2p_cmd;
121  unsigned int i;
122  int rc;
123 
124  /* Wait for EPC_BSY to become clear */
125  for ( i = 0 ; i < SMSCUSB_EEPROM_MAX_WAIT_MS ; i++ ) {
126 
127  /* Read E2P_CMD and check EPC_BSY */
128  if ( ( rc = smscusb_readl ( smscusb,
129  ( e2p_base + SMSCUSB_E2P_CMD ),
130  &e2p_cmd ) ) != 0 )
131  return rc;
132  if ( ! ( e2p_cmd & SMSCUSB_E2P_CMD_EPC_BSY ) )
133  return 0;
134 
135  /* Delay */
136  mdelay ( 1 );
137  }
138 
139  DBGC ( smscusb, "SMSCUSB %p timed out waiting for EEPROM\n",
140  smscusb );
141  return -ETIMEDOUT;
142 }
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:204
#define SMSCUSB_E2P_CMD_EPC_BSY
EPC busy.
Definition: smscusb.h:39
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:53
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
#define SMSCUSB_E2P_CMD
EEPROM command register offset.
Definition: smscusb.h:38
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:670

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 152 of file smscusb.c.

154  {
155  uint32_t e2p_cmd;
156  uint32_t e2p_data;
157  int rc;
158 
159  /* Wait for EEPROM to become idle */
160  if ( ( rc = smscusb_eeprom_wait ( smscusb, e2p_base ) ) != 0 )
161  return rc;
162 
163  /* Initiate read command */
166  if ( ( rc = smscusb_writel ( smscusb, ( e2p_base + SMSCUSB_E2P_CMD ),
167  e2p_cmd ) ) != 0 )
168  return rc;
169 
170  /* Wait for command to complete */
171  if ( ( rc = smscusb_eeprom_wait ( smscusb, e2p_base ) ) != 0 )
172  return rc;
173 
174  /* Read EEPROM data */
175  if ( ( rc = smscusb_readl ( smscusb, ( e2p_base + SMSCUSB_E2P_DATA ),
176  &e2p_data ) ) != 0 )
177  return rc;
178 
179  return SMSCUSB_E2P_DATA_GET ( e2p_data );
180 }
#define SMSCUSB_E2P_CMD_EPC_ADDR(addr)
EPC address.
Definition: smscusb.h:41
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:183
static int smscusb_readl(struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
Read register.
Definition: smscusb.h:204
#define SMSCUSB_E2P_CMD_EPC_BSY
EPC busy.
Definition: smscusb.h:39
#define SMSCUSB_E2P_DATA_GET(e2p_data)
EEPROM data.
Definition: smscusb.h:45
static int smscusb_eeprom_wait(struct smscusb_device *smscusb, unsigned int e2p_base)
Wait for EEPROM to become idle.
Definition: smscusb.c:118
unsigned int uint32_t
Definition: stdint.h:12
#define SMSCUSB_E2P_CMD
EEPROM command register offset.
Definition: smscusb.h:38
#define SMSCUSB_E2P_CMD_EPC_CMD_READ
READ command.
Definition: smscusb.h:40
#define SMSCUSB_E2P_DATA
EEPROM data register offset.
Definition: smscusb.h:44

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 192 of file smscusb.c.

194  {
195  uint8_t *bytes;
196  int byte;
197 
198  /* Read bytes */
199  for ( bytes = data ; len-- ; address++, bytes++ ) {
200  byte = smscusb_eeprom_read_byte ( smscusb, e2p_base, address );
201  if ( byte < 0 )
202  return byte;
203  *bytes = byte;
204  }
205 
206  return 0;
207 }
uint64_t address
Base address.
Definition: ena.h:24
ring len
Length.
Definition: dwmac.h:231
unsigned char uint8_t
Definition: stdint.h:10
unsigned char byte
Definition: smc9000.h:38
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:152
uint8_t bytes[64]
Definition: ib_mad.h:17

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 216 of file smscusb.c.

217  {
218  struct net_device *netdev = smscusb->netdev;
219  int rc;
220 
221  /* Read MAC address from EEPROM */
222  if ( ( rc = smscusb_eeprom_read ( smscusb, e2p_base, SMSCUSB_EEPROM_MAC,
223  netdev->hw_addr, ETH_ALEN ) ) != 0 )
224  return rc;
225 
226  /* Check that EEPROM is physically present */
227  if ( ! is_valid_ether_addr ( netdev->hw_addr ) ) {
228  DBGC ( smscusb, "SMSCUSB %p has no EEPROM MAC (%s)\n",
229  smscusb, eth_ntoa ( netdev->hw_addr ) );
230  return -ENODEV;
231  }
232 
233  DBGC ( smscusb, "SMSCUSB %p using EEPROM MAC %s\n",
234  smscusb, eth_ntoa ( netdev->hw_addr ) );
235  return 0;
236 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define SMSCUSB_EEPROM_MAC
MAC address EEPROM address.
Definition: smscusb.h:50
#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:176
A network device.
Definition: netdevice.h:353
#define ENODEV
No such device.
Definition: errno.h:510
#define ETH_ALEN
Definition: if_ether.h:9
static int is_valid_ether_addr(const void *addr)
Check if Ethernet address is valid.
Definition: ethernet.h:78
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:192
struct net_device * netdev
Network device.
Definition: smscusb.h:154
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:382

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 252 of file smscusb.c.

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

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 290 of file smscusb.c.

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

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 324 of file smscusb.c.

326  {
327  uint8_t addrh = ( address >> 8 );
328  uint8_t addrl = ( address >> 0 );
329  uint32_t otp_data;
330  int rc;
331 
332  /* Wait for OTP to become idle */
333  if ( ( rc = smscusb_otp_wait ( smscusb, otp_base ) ) != 0 )
334  return rc;
335 
336  /* Initiate read command */
337  if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_ADDRH ),
338  addrh ) ) != 0 )
339  return rc;
340  if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_ADDRL ),
341  addrl ) ) != 0 )
342  return rc;
343  if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_CMD ),
344  SMSCUSB_OTP_CMD_READ ) ) != 0 )
345  return rc;
346  if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_GO ),
347  SMSCUSB_OTP_GO_GO ) ) != 0 )
348  return rc;
349 
350  /* Wait for command to complete */
351  if ( ( rc = smscusb_otp_wait ( smscusb, otp_base ) ) != 0 )
352  return rc;
353 
354  /* Read OTP data */
355  if ( ( rc = smscusb_readl ( smscusb, ( otp_base + SMSCUSB_OTP_DATA ),
356  &otp_data ) ) != 0 )
357  return rc;
358 
359  return SMSCUSB_OTP_DATA_GET ( otp_data );
360 }
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:183
#define SMSCUSB_OTP_DATA_GET(otp_data)
OTP data.
Definition: smscusb.h:67
uint32_t addrl
Definition: dwmac.h:232
#define SMSCUSB_OTP_CMD
OTP command selection register offset.
Definition: smscusb.h:72
#define SMSCUSB_OTP_GO_GO
Initiate command.
Definition: smscusb.h:77
#define SMSCUSB_OTP_CMD_READ
Read command.
Definition: smscusb.h:73
static int smscusb_otp_wait(struct smscusb_device *smscusb, unsigned int otp_base)
Wait for OTP to become idle.
Definition: smscusb.c:290
static int smscusb_readl(struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
Read register.
Definition: smscusb.h:204
#define SMSCUSB_OTP_ADDRH
OTP address high byte register offset.
Definition: smscusb.h:60
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:66
#define SMSCUSB_OTP_GO
OTP command initiation register offset.
Definition: smscusb.h:76
#define SMSCUSB_OTP_ADDRL
OTP address low byte register offset.
Definition: smscusb.h:63
uint32_t addrh
Definition: dwmac.h:233

References address, addrh, addrl, 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 372 of file smscusb.c.

374  {
375  uint8_t *bytes;
376  int byte;
377  int rc;
378 
379  /* Power up OTP */
380  if ( ( rc = smscusb_otp_power_up ( smscusb, otp_base ) ) != 0 )
381  return rc;
382 
383  /* Read bytes */
384  for ( bytes = data ; len-- ; address++, bytes++ ) {
385  byte = smscusb_otp_read_byte ( smscusb, otp_base, address );
386  if ( byte < 0 )
387  return byte;
388  *bytes = byte;
389  }
390 
391  return 0;
392 }
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:324
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:252
ring len
Length.
Definition: dwmac.h:231
unsigned char uint8_t
Definition: stdint.h:10
unsigned char byte
Definition: smc9000.h:38
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint8_t bytes[64]
Definition: ib_mad.h:17

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 401 of file smscusb.c.

402  {
403  struct net_device *netdev = smscusb->netdev;
405  unsigned int address;
406  int rc;
407 
408  /* Read OTP signature byte */
409  if ( ( rc = smscusb_otp_read ( smscusb, otp_base, 0, &signature,
410  sizeof ( signature ) ) ) != 0 )
411  return rc;
412 
413  /* Determine location of MAC address */
414  switch ( signature ) {
415  case SMSCUSB_OTP_1_SIG:
417  break;
418  case SMSCUSB_OTP_2_SIG:
420  break;
421  default:
422  DBGC ( smscusb, "SMSCUSB %p unknown OTP signature %#02x\n",
423  smscusb, signature );
424  return -ENOTSUP;
425  }
426 
427  /* Read MAC address from OTP */
428  if ( ( rc = smscusb_otp_read ( smscusb, otp_base, address,
429  netdev->hw_addr, ETH_ALEN ) ) != 0 )
430  return rc;
431 
432  /* Check that OTP is valid */
433  if ( ! is_valid_ether_addr ( netdev->hw_addr ) ) {
434  DBGC ( smscusb, "SMSCUSB %p has no layout %#02x OTP MAC (%s)\n",
435  smscusb, signature, eth_ntoa ( netdev->hw_addr ) );
436  return -ENODEV;
437  }
438 
439  DBGC ( smscusb, "SMSCUSB %p using layout %#02x OTP MAC %s\n",
440  smscusb, signature, eth_ntoa ( netdev->hw_addr ) );
441  return 0;
442 }
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:90
#define DBGC(...)
Definition: compiler.h:505
#define SMSCUSB_OTP_2_MAC
OTP layout 2 MAC address offset.
Definition: smscusb.h:96
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
#define SMSCUSB_OTP_2_SIG
OTP layout 2 signature.
Definition: smscusb.h:93
static struct net_device * netdev
Definition: gdbudp.c:52
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:176
A network device.
Definition: netdevice.h:353
#define ENODEV
No such device.
Definition: errno.h:510
unsigned char uint8_t
Definition: stdint.h:10
#define ETH_ALEN
Definition: if_ether.h:9
static int is_valid_ether_addr(const void *addr)
Check if Ethernet address is valid.
Definition: ethernet.h:78
struct net_device * netdev
Network device.
Definition: smscusb.h:154
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:372
#define SMSCUSB_OTP_1_SIG
OTP layout 1 signature.
Definition: smscusb.h:87
u8 signature
CPU signature.
Definition: CIB_PRM.h:35
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:382

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 457 of file smscusb.c.

457  {
458  struct net_device *netdev = smscusb->netdev;
459  unsigned int offset;
460  int rc;
461 
462  /* Look for "ethernet[0]" alias */
463  if ( ( rc = fdt_alias ( &sysfdt, "ethernet", &offset ) != 0 ) &&
464  ( rc = fdt_alias ( &sysfdt, "ethernet0", &offset ) != 0 ) ) {
465  return rc;
466  }
467 
468  /* Fetch MAC address */
469  if ( ( rc = fdt_mac ( &sysfdt, offset, netdev ) ) != 0 )
470  return rc;
471 
472  DBGC ( smscusb, "SMSCUSB %p using FDT MAC %s\n",
473  smscusb, eth_ntoa ( netdev->hw_addr ) );
474  return 0;
475 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int fdt_alias(struct fdt *fdt, const char *name, unsigned int *offset)
Find node by alias.
Definition: fdt.c:466
#define DBGC(...)
Definition: compiler.h:505
int fdt_mac(struct fdt *fdt, unsigned int offset, struct net_device *netdev)
Get MAC address from property.
Definition: fdt.c:867
static struct net_device * netdev
Definition: gdbudp.c:52
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:176
A network device.
Definition: netdevice.h:353
struct net_device * netdev
Network device.
Definition: smscusb.h:154
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:382
struct fdt sysfdt
The system flattened device tree (if present)
Definition: fdt.c:45

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

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 490 of file smscusb.c.

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

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 524 of file smscusb.c.

525  {
526  struct smscusb_device *smscusb =
527  container_of ( mdio, struct smscusb_device, mdio );
528  unsigned int base = smscusb->mii_base;
529  uint32_t mii_access;
530  uint32_t mii_data;
531  int rc;
532 
533  /* Wait for MII to become idle */
534  if ( ( rc = smscusb_mii_wait ( smscusb ) ) != 0 )
535  return rc;
536 
537  /* Initiate read command */
538  mii_access = ( SMSCUSB_MII_ACCESS_PHY_ADDRESS |
541  if ( ( rc = smscusb_writel ( smscusb, ( base + SMSCUSB_MII_ACCESS ),
542  mii_access ) ) != 0 )
543  return rc;
544 
545  /* Wait for command to complete */
546  if ( ( rc = smscusb_mii_wait ( smscusb ) ) != 0 )
547  return rc;
548 
549  /* Read MII data */
550  if ( ( rc = smscusb_readl ( smscusb, ( base + SMSCUSB_MII_DATA ),
551  &mii_data ) ) != 0 )
552  return rc;
553 
554  return SMSCUSB_MII_DATA_GET ( mii_data );
555 }
uint32_t base
Base.
Definition: librm.h:138
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:148
static int smscusb_writel(struct smscusb_device *smscusb, unsigned int address, uint32_t value)
Write register.
Definition: smscusb.h:183
#define SMSCUSB_MII_DATA
MII data register offset.
Definition: smscusb.h:106
#define SMSCUSB_MII_ACCESS_MIIRINDA(addr)
MII register.
Definition: smscusb.h:101
#define SMSCUSB_MII_DATA_GET(mii_data)
Get data.
Definition: smscusb.h:108
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
#define SMSCUSB_MII_ACCESS_PHY_ADDRESS
PHY address.
Definition: smscusb.h:100
static int smscusb_readl(struct smscusb_device *smscusb, unsigned int address, uint32_t *value)
Read register.
Definition: smscusb.h:204
#define SMSCUSB_MII_ACCESS_MIIBZY
MII busy.
Definition: smscusb.h:103
static int smscusb_mii_wait(struct smscusb_device *smscusb)
Wait for MII to become idle.
Definition: smscusb.c:490
struct mii_interface mdio
MII interface.
Definition: smscusb.h:158
unsigned int uint32_t
Definition: stdint.h:12
#define SMSCUSB_MII_ACCESS
MII access register offset.
Definition: smscusb.h:99
uint16_t mii_base
MII register base.
Definition: smscusb.h:162

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 566 of file smscusb.c.

568  {
569  struct smscusb_device *smscusb =
570  container_of ( mdio, struct smscusb_device, mdio );
571  unsigned int base = smscusb->mii_base;
572  uint32_t mii_access;
573  uint32_t mii_data;
574  int rc;
575 
576  /* Wait for MII to become idle */
577  if ( ( rc = smscusb_mii_wait ( smscusb ) ) != 0 )
578  return rc;
579 
580  /* Write MII data */
581  mii_data = SMSCUSB_MII_DATA_SET ( data );
582  if ( ( rc = smscusb_writel ( smscusb, ( base + SMSCUSB_MII_DATA ),
583  mii_data ) ) != 0 )
584  return rc;
585 
586  /* Initiate write command */
587  mii_access = ( SMSCUSB_MII_ACCESS_PHY_ADDRESS |
591  if ( ( rc = smscusb_writel ( smscusb, ( base + SMSCUSB_MII_ACCESS ),
592  mii_access ) ) != 0 )
593  return rc;
594 
595  /* Wait for command to complete */
596  if ( ( rc = smscusb_mii_wait ( smscusb ) ) != 0 )
597  return rc;
598 
599  return 0;
600 }
#define SMSCUSB_MII_ACCESS_MIIWNR
MII write.
Definition: smscusb.h:102
uint32_t base
Base.
Definition: librm.h:138
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:148
static int smscusb_writel(struct smscusb_device *smscusb, unsigned int address, uint32_t value)
Write register.
Definition: smscusb.h:183
#define SMSCUSB_MII_DATA
MII data register offset.
Definition: smscusb.h:106
#define SMSCUSB_MII_ACCESS_MIIRINDA(addr)
MII register.
Definition: smscusb.h:101
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
#define SMSCUSB_MII_ACCESS_PHY_ADDRESS
PHY address.
Definition: smscusb.h:100
#define SMSCUSB_MII_ACCESS_MIIBZY
MII busy.
Definition: smscusb.h:103
#define SMSCUSB_MII_DATA_SET(data)
Set data.
Definition: smscusb.h:107
static int smscusb_mii_wait(struct smscusb_device *smscusb)
Wait for MII to become idle.
Definition: smscusb.c:490
struct mii_interface mdio
MII interface.
Definition: smscusb.h:158
unsigned int uint32_t
Definition: stdint.h:12
#define SMSCUSB_MII_ACCESS
MII access register offset.
Definition: smscusb.h:99
uint16_t mii_base
MII register base.
Definition: smscusb.h:162
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 614 of file smscusb.c.

614  {
615  struct net_device *netdev = smscusb->netdev;
616  int intr;
617  int rc;
618 
619  /* Read PHY interrupt source */
620  intr = mii_read ( &smscusb->mii, smscusb->phy_source );
621  if ( intr < 0 ) {
622  rc = intr;
623  DBGC ( smscusb, "SMSCUSB %p could not get PHY interrupt "
624  "source: %s\n", smscusb, strerror ( rc ) );
625  return rc;
626  }
627 
628  /* Acknowledge PHY interrupt */
629  if ( ( rc = mii_write ( &smscusb->mii, smscusb->phy_source,
630  intr ) ) != 0 ) {
631  DBGC ( smscusb, "SMSCUSB %p could not acknowledge PHY "
632  "interrupt: %s\n", smscusb, strerror ( rc ) );
633  return rc;
634  }
635 
636  /* Check link status */
637  if ( ( rc = mii_check_link ( &smscusb->mii, netdev ) ) != 0 ) {
638  DBGC ( smscusb, "SMSCUSB %p could not check link: %s\n",
639  smscusb, strerror ( rc ) );
640  return rc;
641  }
642 
643  DBGC ( smscusb, "SMSCUSB %p link %s (intr %#04x)\n",
644  smscusb, ( netdev_link_ok ( netdev ) ? "up" : "down" ), intr );
645  return 0;
646 }
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:164
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:640
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
A network device.
Definition: netdevice.h:353
struct mii_device mii
MII device.
Definition: smscusb.h:160
int mii_check_link(struct mii_device *mii, struct net_device *netdev)
Update link status via MII.
Definition: mii.c:127
static int mii_read(int phy_id, int location)
Definition: epic100.c:500
struct net_device * netdev
Network device.
Definition: smscusb.h:154
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:105

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 656 of file smscusb.c.

657  {
658  int rc;
659 
660  /* Enable PHY interrupts */
661  if ( ( rc = mii_write ( &smscusb->mii, phy_mask, intrs ) ) != 0 ) {
662  DBGC ( smscusb, "SMSCUSB %p could not set PHY interrupt "
663  "mask: %s\n", smscusb, strerror ( rc ) );
664  return rc;
665  }
666 
667  /* Update link status */
668  smscusb_mii_check_link ( smscusb );
669 
670  return 0;
671 }
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:79
struct mii_device mii
MII device.
Definition: smscusb.h:160
int smscusb_mii_check_link(struct smscusb_device *smscusb)
Check link status.
Definition: smscusb.c:614
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:105

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 687 of file smscusb.c.

688  {
689  struct net_device *netdev = smscusb->netdev;
690  union smscusb_mac mac;
691  int rc;
692 
693  /* Copy MAC address */
694  memset ( &mac, 0, sizeof ( mac ) );
695  memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN );
696 
697  /* Write MAC address high register */
698  if ( ( rc = smscusb_raw_writel ( smscusb,
699  ( addr_base + SMSCUSB_RX_ADDRH ),
700  mac.addr.h ) ) != 0 )
701  return rc;
702 
703  /* Write MAC address low register */
704  if ( ( rc = smscusb_raw_writel ( smscusb,
705  ( addr_base + SMSCUSB_RX_ADDRL ),
706  mac.addr.l ) ) != 0 )
707  return rc;
708 
709  return 0;
710 }
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:129
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:62
MAC address.
Definition: smscusb.h:116
A network device.
Definition: netdevice.h:353
#define ETH_ALEN
Definition: if_ether.h:9
#define SMSCUSB_RX_ADDRL
MAC receive address low register offset.
Definition: smscusb.h:132
struct net_device * netdev
Network device.
Definition: smscusb.h:154
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
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 719 of file smscusb.c.

720  {
721  struct net_device *netdev = smscusb->netdev;
722  union smscusb_mac mac;
723  int rc;
724 
725  /* Copy MAC address */
726  memset ( &mac, 0, sizeof ( mac ) );
727  memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN );
729 
730  /* Write MAC address perfect filter high register */
731  if ( ( rc = smscusb_raw_writel ( smscusb,
732  ( filt_base + SMSCUSB_ADDR_FILTH(0) ),
733  mac.addr.h ) ) != 0 )
734  return rc;
735 
736  /* Write MAC address perfect filter low register */
737  if ( ( rc = smscusb_raw_writel ( smscusb,
738  ( filt_base + SMSCUSB_ADDR_FILTL(0) ),
739  mac.addr.l ) ) != 0 )
740  return rc;
741 
742  return 0;
743 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define SMSCUSB_ADDR_FILTH_VALID
Address valid.
Definition: smscusb.h:136
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:62
#define SMSCUSB_ADDR_FILTL(n)
MAC address perfect filter N low register offset.
Definition: smscusb.h:139
MAC address.
Definition: smscusb.h:116
#define cpu_to_le32(value)
Definition: byteswap.h:108
A network device.
Definition: netdevice.h:353
#define SMSCUSB_ADDR_FILTH(n)
MAC address perfect filter N high register offset.
Definition: smscusb.h:135
#define ETH_ALEN
Definition: if_ether.h:9
struct net_device * netdev
Network device.
Definition: smscusb.h:154
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
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 759 of file smscusb.c.

760  {
761  struct smscusb_device *smscusb =
762  container_of ( ep, struct smscusb_device, usbnet.intr );
763  struct net_device *netdev = smscusb->netdev;
764  struct smscusb_interrupt *intr;
765 
766  /* Profile completions */
767  profile_start ( &smscusb_intr_profiler );
768 
769  /* Ignore packets cancelled when the endpoint closes */
770  if ( ! ep->open )
771  goto done;
772 
773  /* Record USB errors against the network device */
774  if ( rc != 0 ) {
775  DBGC ( smscusb, "SMSCUSB %p interrupt failed: %s\n",
776  smscusb, strerror ( rc ) );
777  DBGC_HDA ( smscusb, 0, iobuf->data, iob_len ( iobuf ) );
778  netdev_rx_err ( netdev, NULL, rc );
779  goto done;
780  }
781 
782  /* Extract interrupt data */
783  if ( iob_len ( iobuf ) != sizeof ( *intr ) ) {
784  DBGC ( smscusb, "SMSCUSB %p malformed interrupt\n",
785  smscusb );
786  DBGC_HDA ( smscusb, 0, iobuf->data, iob_len ( iobuf ) );
787  netdev_rx_err ( netdev, NULL, rc );
788  goto done;
789  }
790  intr = iobuf->data;
791 
792  /* Record interrupt status */
793  smscusb->int_sts = le32_to_cpu ( intr->int_sts );
794  profile_stop ( &smscusb_intr_profiler );
795 
796  done:
797  /* Free I/O buffer */
798  free_iob ( iobuf );
799 }
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:587
Interrupt packet format.
Definition: smscusb.h:142
#define le32_to_cpu(value)
Definition: byteswap.h:114
An SMSC USB device.
Definition: smscusb.h:148
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:419
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:174
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:28
uint32_t int_sts
Interrupt status.
Definition: smscusb.h:166
struct usbnet_device usbnet
USB network device.
Definition: smscusb.h:156
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
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:161
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
A network device.
Definition: netdevice.h:353
void * data
Start of data.
Definition: iobuf.h:53
struct net_device * netdev
Network device.
Definition: smscusb.h:154
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
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 813 of file smscusb.c.

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

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 44 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:524
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:566

MII operations.

Definition at line 603 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:759

Interrupt endpoint operations.

Definition at line 802 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:813

Bulk OUT endpoint operations.

Definition at line 824 of file smscusb.c.