iPXE
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.
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.
static int mii_bit_read (struct mii_interface *mdio, unsigned int phy, unsigned int reg)
 Read from MII register.
static int mii_bit_write (struct mii_interface *mdio, unsigned int phy, unsigned int reg, unsigned int data)
 Write to MII register.
void init_mii_bit_basher (struct mii_bit_basher *miibit)
 Initialise bit-bashing interface.

Variables

static struct mii_operations mii_bit_op
 MII bit basher operations.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ mii_bit_xfer()

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}
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:61
void write_bit(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Set/clear output bit.
Definition bitbash.c:45
device nvs write
Definition threewire.h:62
static unsigned int unsigned int bit
Definition bigint.h:392
@ MII_BIT_MDC
MII clock.
Definition mii_bit.h:43
@ MII_BIT_MDIO
MII data.
Definition mii_bit.h:45
struct option_descriptor read[1]
Definition nvo_cmd.c:116
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition timer.c:61

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

Referenced by mii_bit_rw().

◆ mii_bit_rw()

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 */
91
92 /* Write PHY address */
93 mii_bit_xfer ( basher, MII_BIT_PHY_MASK, phy );
94
95 /* Write register address */
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 */
106
107 /* Initiate drive for read */
108 write_bit ( basher, MII_BIT_DRIVE, 0 );
109
110 return data;
111}
struct golan_eqe_cmd cmd
Definition CIB_PRM.h:1
uint8_t data[48]
Additional event data.
Definition ena.h:11
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_CMD_MASK
Command mask.
Definition mii_bit.h:18
#define MII_BIT_START
Start.
Definition mii_bit.h:15
#define MII_BIT_SWITCH_MASK
Switch mask.
Definition mii_bit.h:28
#define MII_BIT_START_MASK
Start mask.
Definition mii_bit.h:16
@ MII_BIT_DRIVE
MII data direction.
Definition mii_bit.h:47
#define MII_BIT_CMD_RW
Command read or write.
Definition mii_bit.h:21
#define MII_BIT_DATA_MASK
Data mask.
Definition mii_bit.h:30
#define MII_BIT_REG_MASK
Register mask.
Definition mii_bit.h:25
#define MII_BIT_SWITCH
Switch.
Definition mii_bit.h:27
#define MII_BIT_PHY_MASK
PHY mask.
Definition mii_bit.h:23
static unsigned int unsigned int reg
Definition myson.h:162

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

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 =
125 struct bit_basher *basher = &miibit->basher;
126
127 return mii_bit_rw ( basher, phy, reg, 0, MII_BIT_CMD_READ );
128}
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 MII_BIT_CMD_READ
Command read.
Definition mii_bit.h:19
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
A bit-bashing interface.
Definition bitbash.h:56
A bit-bashing MII interface.
Definition mii_bit.h:33
struct bit_basher basher
Bit-bashing interface.
Definition mii_bit.h:37
struct mii_interface mdio
MII interface.
Definition mii_bit.h:35

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

◆ mii_bit_write()

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 =
143 struct bit_basher *basher = &miibit->basher;
144
145 mii_bit_rw ( basher, phy, reg, data, MII_BIT_CMD_WRITE );
146 return 0;
147}
#define MII_BIT_CMD_WRITE
Command write.
Definition mii_bit.h:20

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};
static void mdio_init(struct mii_interface *mdio, struct mii_operations *op)
Initialise MII interface.
Definition mii.h:64
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_read(struct mii_interface *mdio, unsigned int phy, unsigned int reg)
Read from MII register.
Definition mii_bit.c:121
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

MII bit basher operations.

Definition at line 150 of file mii_bit.c.

150 {
151 .read = mii_bit_read,
152 .write = mii_bit_write,
153};

Referenced by init_mii_bit_basher().