iPXE
Functions | Variables
mii_bit.c File Reference
#include <stdint.h>
#include <unistd.h>
#include <ipxe/bitbash.h>
#include <ipxe/mii_bit.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static uint32_t mii_bit_xfer (struct bit_basher *basher, uint32_t mask, uint32_t write)
 Transfer bits over MII bit-bashing interface. More...
 
static unsigned int mii_bit_rw (struct bit_basher *basher, unsigned int phy, unsigned int reg, unsigned int data, unsigned int cmd)
 Read or write via MII bit-bashing interface. More...
 
static int mii_bit_read (struct mii_interface *mdio, unsigned int phy, unsigned int reg)
 Read from MII register. More...
 
static int mii_bit_write (struct mii_interface *mdio, unsigned int phy, unsigned int reg, unsigned int data)
 Write to MII register. More...
 
void init_mii_bit_basher (struct mii_bit_basher *miibit)
 Initialise bit-bashing interface. More...
 

Variables

static struct mii_operations mii_bit_op
 MII bit basher operations. More...
 

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ mii_bit_xfer()

static uint32_t mii_bit_xfer ( struct bit_basher basher,
uint32_t  mask,
uint32_t  write 
)
static

Transfer bits over MII bit-bashing interface.

Parameters
basherBit basher
maskMask
writeData to write
Return values
readData read

Definition at line 39 of file mii_bit.c.

40  {
41  uint32_t read = 0;
42  int bit;
43 
44  for ( ; mask ; mask >>= 1 ) {
45 
46  /* Delay */
47  udelay ( 1 );
48 
49  /* Write bit to basher */
50  write_bit ( basher, MII_BIT_MDIO, ( write & mask ) );
51 
52  /* Read bit from basher */
53  bit = read_bit ( basher, MII_BIT_MDIO );
54  read <<= 1;
55  read |= ( bit & 1 );
56 
57  /* Set clock high */
58  write_bit ( basher, MII_BIT_MDC, 1 );
59 
60  /* Delay */
61  udelay ( 1 );
62 
63  /* Set clock low */
64  write_bit ( basher, MII_BIT_MDC, 0 );
65  }
66  return read;
67 }
struct option_descriptor read[1]
Definition: nvo_cmd.c:115
static unsigned int unsigned int bit
Definition: bigint.h:208
MII data.
Definition: mii_bit.h:45
MII clock.
Definition: mii_bit.h:43
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
device nvs write
Definition: threewire.h:61
unsigned int uint32_t
Definition: stdint.h:12
int read_bit(struct bit_basher *basher, unsigned int bit_id)
Read input bit.
Definition: bitbash.c:60
void write_bit(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Set/clear output bit.
Definition: bitbash.c:44

References bit, MII_BIT_MDC, MII_BIT_MDIO, read, read_bit(), udelay(), write, and write_bit().

Referenced by mii_bit_rw().

◆ mii_bit_rw()

static unsigned int mii_bit_rw ( struct bit_basher basher,
unsigned int  phy,
unsigned int  reg,
unsigned int  data,
unsigned int  cmd 
)
static

Read or write via MII bit-bashing interface.

Parameters
basherBit basher
phyPHY address
regRegister address
dataData to write
cmdCommand
Return values
dataData read

Definition at line 79 of file mii_bit.c.

81  {
82 
83  /* Initiate drive for write */
84  write_bit ( basher, MII_BIT_DRIVE, 1 );
85 
86  /* Write start */
88 
89  /* Write command */
90  mii_bit_xfer ( basher, MII_BIT_CMD_MASK, cmd );
91 
92  /* Write PHY address */
93  mii_bit_xfer ( basher, MII_BIT_PHY_MASK, phy );
94 
95  /* Write register address */
96  mii_bit_xfer ( basher, MII_BIT_REG_MASK, reg );
97 
98  /* Switch drive to read if applicable */
99  write_bit ( basher, MII_BIT_DRIVE, ( cmd & MII_BIT_CMD_RW ) );
100 
101  /* Allow space for turnaround */
103 
104  /* Read or write data */
105  data = mii_bit_xfer (basher, MII_BIT_DATA_MASK, data );
106 
107  /* Initiate drive for read */
108  write_bit ( basher, MII_BIT_DRIVE, 0 );
109 
110  return data;
111 }
#define MII_BIT_DATA_MASK
Data mask.
Definition: mii_bit.h:30
MII data direction.
Definition: mii_bit.h:47
static unsigned int unsigned int reg
Definition: myson.h:162
#define MII_BIT_START_MASK
Start mask.
Definition: mii_bit.h:16
#define MII_BIT_SWITCH_MASK
Switch mask.
Definition: mii_bit.h:28
#define MII_BIT_CMD_RW
Command read or write.
Definition: mii_bit.h:21
#define MII_BIT_SWITCH
Switch.
Definition: mii_bit.h:27
static uint32_t mii_bit_xfer(struct bit_basher *basher, uint32_t mask, uint32_t write)
Transfer bits over MII bit-bashing interface.
Definition: mii_bit.c:39
#define MII_BIT_PHY_MASK
PHY mask.
Definition: mii_bit.h:23
#define MII_BIT_CMD_MASK
Command mask.
Definition: mii_bit.h:18
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define MII_BIT_START
Start.
Definition: mii_bit.h:15
#define MII_BIT_REG_MASK
Register mask.
Definition: mii_bit.h:25
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
void write_bit(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Set/clear output bit.
Definition: bitbash.c:44

References cmd, data, MII_BIT_CMD_MASK, MII_BIT_CMD_RW, MII_BIT_DATA_MASK, MII_BIT_DRIVE, MII_BIT_PHY_MASK, MII_BIT_REG_MASK, MII_BIT_START, MII_BIT_START_MASK, MII_BIT_SWITCH, MII_BIT_SWITCH_MASK, mii_bit_xfer(), reg, and write_bit().

Referenced by mii_bit_read(), and mii_bit_write().

◆ mii_bit_read()

static int mii_bit_read ( struct mii_interface mdio,
unsigned int  phy,
unsigned int  reg 
)
static

Read from MII register.

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

Definition at line 121 of file mii_bit.c.

122  {
123  struct mii_bit_basher *miibit =
124  container_of ( mdio, struct mii_bit_basher, mdio );
125  struct bit_basher *basher = &miibit->basher;
126 
127  return mii_bit_rw ( basher, phy, reg, 0, MII_BIT_CMD_READ );
128 }
struct mii_interface mdio
MII interface.
Definition: mii_bit.h:35
static unsigned int unsigned int reg
Definition: myson.h:162
static unsigned int mii_bit_rw(struct bit_basher *basher, unsigned int phy, unsigned int reg, unsigned int data, unsigned int cmd)
Read or write via MII bit-bashing interface.
Definition: mii_bit.c:79
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
A bit-bashing interface.
Definition: bitbash.h:55
#define MII_BIT_CMD_READ
Command read.
Definition: mii_bit.h:19
struct bit_basher basher
Bit-bashing interface.
Definition: mii_bit.h:37
A bit-bashing MII interface.
Definition: mii_bit.h:33

References mii_bit_basher::basher, container_of, mii_bit_basher::mdio, MII_BIT_CMD_READ, mii_bit_rw(), and reg.

◆ mii_bit_write()

static int mii_bit_write ( struct mii_interface mdio,
unsigned int  phy,
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 139 of file mii_bit.c.

140  {
141  struct mii_bit_basher *miibit =
142  container_of ( mdio, struct mii_bit_basher, mdio );
143  struct bit_basher *basher = &miibit->basher;
144 
145  mii_bit_rw ( basher, phy, reg, data, MII_BIT_CMD_WRITE );
146  return 0;
147 }
struct mii_interface mdio
MII interface.
Definition: mii_bit.h:35
static unsigned int unsigned int reg
Definition: myson.h:162
static unsigned int mii_bit_rw(struct bit_basher *basher, unsigned int phy, unsigned int reg, unsigned int data, unsigned int cmd)
Read or write via MII bit-bashing interface.
Definition: mii_bit.c:79
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define MII_BIT_CMD_WRITE
Command write.
Definition: mii_bit.h:20
A bit-bashing interface.
Definition: bitbash.h:55
struct bit_basher basher
Bit-bashing interface.
Definition: mii_bit.h:37
uint8_t data[48]
Additional event data.
Definition: ena.h:22
A bit-bashing MII interface.
Definition: mii_bit.h:33

References mii_bit_basher::basher, container_of, data, mii_bit_basher::mdio, MII_BIT_CMD_WRITE, mii_bit_rw(), and reg.

◆ init_mii_bit_basher()

void init_mii_bit_basher ( struct mii_bit_basher miibit)

Initialise bit-bashing interface.

Parameters
miibitMII bit basher

Definition at line 160 of file mii_bit.c.

160  {
161  mdio_init ( &miibit->mdio, &mii_bit_op );
162 };
struct mii_interface mdio
MII interface.
Definition: mii_bit.h:35
static void mdio_init(struct mii_interface *mdio, struct mii_operations *op)
Initialise MII interface.
Definition: mii.h:63
static struct mii_operations mii_bit_op
MII bit basher operations.
Definition: mii_bit.c:150

References mii_bit_basher::mdio, mdio_init(), and mii_bit_op.

Referenced by icplus_probe().

Variable Documentation

◆ mii_bit_op

struct mii_operations mii_bit_op
static
Initial value:
= {
.read = mii_bit_read,
.write = mii_bit_write,
}
static int mii_bit_write(struct mii_interface *mdio, unsigned int phy, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii_bit.c:139
static int mii_bit_read(struct mii_interface *mdio, unsigned int phy, unsigned int reg)
Read from MII register.
Definition: mii_bit.c:121

MII bit basher operations.

Definition at line 150 of file mii_bit.c.

Referenced by init_mii_bit_basher().