iPXE
intelvf.h File Reference

Intel 10/100/1000 virtual function network card driver. More...

#include "intel.h"

Go to the source code of this file.

Data Structures

struct  intelvf_msg_mac
 MAC address mailbox message. More...
struct  intelvf_msg_version
 Version number mailbox message. More...
struct  intelvf_msg_mtu
 MTU mailbox message. More...
struct  intelvf_msg_queues
 Queue configuration mailbox message (API v1.1+ only) More...
struct  intelvf_msg_raw
 Raw mailbox message. More...
union  intelvf_msg
 Mailbox message. More...

Macros

#define INTELVF_BAR_SIZE   ( 16 * 1024 )
 Intel VF BAR size.
#define INTELVF_MBCTRL   0x0c40UL
 Mailbox Control Register.
#define INTELVF_MBCTRL_REQ   0x00000001UL
 Request for PF ready.
#define INTELVF_MBCTRL_ACK   0x00000002UL
 PF message received.
#define INTELVF_MBCTRL_VFU   0x00000004UL
 Buffer taken by VF.
#define INTELVF_MBCTRL_PFU   0x00000008UL
 Buffer taken to PF.
#define INTELVF_MBCTRL_PFSTS   0x00000010UL
 PF wrote a message.
#define INTELVF_MBCTRL_PFACK   0x00000020UL
 PF acknowledged message.
#define INTELVF_MBCTRL_RSTI   0x00000040UL
 PF reset in progress.
#define INTELVF_MBCTRL_RSTD   0x00000080UL
 PF reset complete.
#define INTELVF_MBMEM   0x0800UL
 Mailbox Memory Register Base.
#define INTELVF_MSG_TYPE_RESET   0x00000001UL
 Reset mailbox message.
#define INTELVF_MSG_TYPE_SET_MAC   0x00000002UL
 Set MAC address mailbox message.
#define INTELVF_MSG_TYPE_SET_MTU   0x00000005UL
 Set MTU mailbox message.
#define INTELVF_MSG_TYPE_GET_QUEUES   0x00000009UL
 Get queue configuration message.
#define INTELVF_MSG_TYPE_CONTROL   0x00000100UL
 Control ("ping") mailbox message.
#define INTELVF_MSG_TYPE_MASK   0x0000ffffUL
 Message type mask.
#define INTELVF_MSG_NACK   0x40000000UL
 Message NACK flag.
#define INTELVF_MSG_ACK   0x80000000UL
 Message ACK flag.
#define INTELVF_MSG_RESPONSE   ( INTELVF_MSG_ACK | INTELVF_MSG_NACK )
 Message is a response.
#define INTELVF_MBOX_MAX_WAIT_MS   500
 Maximum time to wait for mailbox message.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int intelvf_mbox_msg (struct intel_nic *intel, union intelvf_msg *msg)
 Send/receive mailbox message.
int intelvf_mbox_poll (struct intel_nic *intel)
 Poll mailbox.
int intelvf_mbox_wait (struct intel_nic *intel)
 Wait for PF reset to complete.
int intelvf_mbox_reset (struct intel_nic *intel, uint8_t *hw_addr)
 Send reset message and get initial MAC address.
int intelvf_mbox_set_mac (struct intel_nic *intel, const uint8_t *ll_addr)
 Send set MAC address message.
int intelvf_mbox_set_mtu (struct intel_nic *intel, size_t mtu)
 Send set MTU message.

Detailed Description

Intel 10/100/1000 virtual function network card driver.

Definition in file intelvf.h.

Macro Definition Documentation

◆ INTELVF_BAR_SIZE

#define INTELVF_BAR_SIZE   ( 16 * 1024 )

Intel VF BAR size.

Definition at line 16 of file intelvf.h.

Referenced by intelxvf_probe().

◆ INTELVF_MBCTRL

#define INTELVF_MBCTRL   0x0c40UL

Mailbox Control Register.

Definition at line 19 of file intelvf.h.

◆ INTELVF_MBCTRL_REQ

#define INTELVF_MBCTRL_REQ   0x00000001UL

Request for PF ready.

Definition at line 20 of file intelvf.h.

Referenced by intelvf_mbox_msg().

◆ INTELVF_MBCTRL_ACK

#define INTELVF_MBCTRL_ACK   0x00000002UL

PF message received.

Definition at line 21 of file intelvf.h.

Referenced by intelvf_mbox_msg(), and intelvf_mbox_poll().

◆ INTELVF_MBCTRL_VFU

#define INTELVF_MBCTRL_VFU   0x00000004UL

Buffer taken by VF.

Definition at line 22 of file intelvf.h.

Referenced by intelvf_mbox_msg().

◆ INTELVF_MBCTRL_PFU

#define INTELVF_MBCTRL_PFU   0x00000008UL

Buffer taken to PF.

Definition at line 23 of file intelvf.h.

◆ INTELVF_MBCTRL_PFSTS

#define INTELVF_MBCTRL_PFSTS   0x00000010UL

PF wrote a message.

Definition at line 24 of file intelvf.h.

Referenced by intelvf_mbox_msg(), and intelvf_mbox_poll().

◆ INTELVF_MBCTRL_PFACK

#define INTELVF_MBCTRL_PFACK   0x00000020UL

PF acknowledged message.

Definition at line 25 of file intelvf.h.

Referenced by intelvf_mbox_msg().

◆ INTELVF_MBCTRL_RSTI

#define INTELVF_MBCTRL_RSTI   0x00000040UL

PF reset in progress.

Definition at line 26 of file intelvf.h.

Referenced by intelvf_mbox_msg(), and intelvf_mbox_poll().

◆ INTELVF_MBCTRL_RSTD

#define INTELVF_MBCTRL_RSTD   0x00000080UL

PF reset complete.

Definition at line 27 of file intelvf.h.

◆ INTELVF_MBMEM

#define INTELVF_MBMEM   0x0800UL

Mailbox Memory Register Base.

Definition at line 30 of file intelvf.h.

◆ INTELVF_MSG_TYPE_RESET

#define INTELVF_MSG_TYPE_RESET   0x00000001UL

Reset mailbox message.

Definition at line 33 of file intelvf.h.

Referenced by intelvf_mbox_reset().

◆ INTELVF_MSG_TYPE_SET_MAC

#define INTELVF_MSG_TYPE_SET_MAC   0x00000002UL

Set MAC address mailbox message.

Definition at line 36 of file intelvf.h.

Referenced by intelvf_mbox_set_mac().

◆ INTELVF_MSG_TYPE_SET_MTU

#define INTELVF_MSG_TYPE_SET_MTU   0x00000005UL

Set MTU mailbox message.

Definition at line 39 of file intelvf.h.

Referenced by intelvf_mbox_set_mtu().

◆ INTELVF_MSG_TYPE_GET_QUEUES

#define INTELVF_MSG_TYPE_GET_QUEUES   0x00000009UL

Get queue configuration message.

Definition at line 42 of file intelvf.h.

Referenced by intelxvf_mbox_queues().

◆ INTELVF_MSG_TYPE_CONTROL

#define INTELVF_MSG_TYPE_CONTROL   0x00000100UL

Control ("ping") mailbox message.

Definition at line 45 of file intelvf.h.

◆ INTELVF_MSG_TYPE_MASK

#define INTELVF_MSG_TYPE_MASK   0x0000ffffUL

◆ INTELVF_MSG_NACK

#define INTELVF_MSG_NACK   0x40000000UL

Message NACK flag.

Definition at line 51 of file intelvf.h.

◆ INTELVF_MSG_ACK

#define INTELVF_MSG_ACK   0x80000000UL

◆ INTELVF_MSG_RESPONSE

#define INTELVF_MSG_RESPONSE   ( INTELVF_MSG_ACK | INTELVF_MSG_NACK )

Message is a response.

Definition at line 57 of file intelvf.h.

Referenced by intelvf_mbox_msg().

◆ INTELVF_MBOX_MAX_WAIT_MS

#define INTELVF_MBOX_MAX_WAIT_MS   500

Maximum time to wait for mailbox message.

This is a policy decision.

Definition at line 149 of file intelvf.h.

Referenced by intelvf_mbox_msg(), and intelvf_mbox_wait().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ intelvf_mbox_msg()

int intelvf_mbox_msg ( struct intel_nic * intel,
union intelvf_msg * msg )
extern

Send/receive mailbox message.

Parameters
intelIntel device
msgMessage buffer
Return values
rcReturn status code

Definition at line 152 of file intelvf.c.

152 {
153 struct intel_mailbox *mbox = &intel->mbox;
155 uint32_t seen = 0;
156 unsigned int i;
157
158 /* Sanity check */
159 assert ( ! ( msg->hdr & INTELVF_MSG_RESPONSE ) );
160
161 /* Handle mailbox */
162 for ( i = 0 ; i < INTELVF_MBOX_MAX_WAIT_MS ; i++ ) {
163
164 /* Attempt to claim mailbox, if we have not yet sent
165 * our message.
166 */
167 if ( ! ( seen & INTELVF_MBCTRL_VFU ) )
168 writel ( INTELVF_MBCTRL_VFU, intel->regs + mbox->ctrl );
169
170 /* Get mailbox status and record observed flags */
171 ctrl = readl ( intel->regs + mbox->ctrl );
172 seen |= ctrl;
173
174 /* If a reset is in progress, clear VFU and abort */
175 if ( ctrl & INTELVF_MBCTRL_RSTI ) {
176 writel ( 0, intel->regs + mbox->ctrl );
177 return -EPIPE;
178 }
179
180 /* Write message to mailbox, if applicable. This
181 * potentially overwrites a message sent by the PF (if
182 * the PF has simultaneously released PFU (thus
183 * allowing our VFU) and asserted PFSTS), but that
184 * doesn't really matter since there are no
185 * unsolicited PF->VF messages that require the actual
186 * message content to be observed.
187 */
188 if ( ctrl & INTELVF_MBCTRL_VFU )
189 intelvf_mbox_write ( intel, msg );
190
191 /* Read message from mailbox, if applicable. */
192 if ( ( seen & INTELVF_MBCTRL_VFU ) &&
193 ( seen & INTELVF_MBCTRL_PFACK ) &&
195 intelvf_mbox_read ( intel, msg );
196
197 /* Acknowledge received message (if applicable),
198 * release VFU lock, and send message (if applicable).
199 */
200 ctrl = ( ( ( ctrl & INTELVF_MBCTRL_PFSTS ) ?
201 INTELVF_MBCTRL_ACK : 0 ) |
202 ( ( ctrl & INTELVF_MBCTRL_VFU ) ?
203 INTELVF_MBCTRL_REQ : 0 ) );
204 writel ( ctrl, intel->regs + mbox->ctrl );
205
206 /* Exit successfully if we have received a response */
207 if ( msg->hdr & INTELVF_MSG_RESPONSE ) {
208
209 /* Sanity check */
210 assert ( seen & INTELVF_MBCTRL_VFU );
211 assert ( seen & INTELVF_MBCTRL_PFACK );
212 assert ( seen & INTELVF_MBCTRL_PFSTS );
213
214 return 0;
215 }
216
217 /* Delay */
218 mdelay ( 1 );
219 }
220
221 DBGC ( intel, "INTEL %p timed out waiting for mailbox (seen %08x)\n",
222 intel, seen );
223 return -ETIMEDOUT;
224}
unsigned int uint32_t
Definition stdint.h:12
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint8_t ctrl
Ring control.
Definition dwmac.h:7
#define DBGC(...)
Definition compiler.h:505
#define ETIMEDOUT
Connection timed out.
Definition errno.h:670
#define EPIPE
Broken pipe.
Definition errno.h:620
static void intelvf_mbox_write(struct intel_nic *intel, const union intelvf_msg *msg)
Write message to mailbox.
Definition intelvf.c:54
static void intelvf_mbox_read(struct intel_nic *intel, union intelvf_msg *msg)
Read message from mailbox.
Definition intelvf.c:75
#define INTELVF_MBCTRL_PFACK
PF acknowledged message.
Definition intelvf.h:25
#define INTELVF_MBCTRL_ACK
PF message received.
Definition intelvf.h:21
#define INTELVF_MSG_RESPONSE
Message is a response.
Definition intelvf.h:57
#define INTELVF_MBCTRL_VFU
Buffer taken by VF.
Definition intelvf.h:22
#define INTELVF_MBOX_MAX_WAIT_MS
Maximum time to wait for mailbox message.
Definition intelvf.h:149
#define INTELVF_MBCTRL_REQ
Request for PF ready.
Definition intelvf.h:20
#define INTELVF_MBCTRL_PFSTS
PF wrote a message.
Definition intelvf.h:24
#define INTELVF_MBCTRL_RSTI
PF reset in progress.
Definition intelvf.h:26
void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition message.c:62
An Intel virtual function mailbox.
Definition intel.h:266
struct intel_mailbox mbox
Mailbox.
Definition intel.h:309
void * regs
Registers.
Definition intel.h:291
Definition golan.c:120
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79
#define readl
Definition w89c840.c:157
#define writel
Definition w89c840.c:160

References assert, ctrl, DBGC, EPIPE, ETIMEDOUT, INTELVF_MBCTRL_ACK, INTELVF_MBCTRL_PFACK, INTELVF_MBCTRL_PFSTS, INTELVF_MBCTRL_REQ, INTELVF_MBCTRL_RSTI, INTELVF_MBCTRL_VFU, INTELVF_MBOX_MAX_WAIT_MS, intelvf_mbox_read(), intelvf_mbox_write(), INTELVF_MSG_RESPONSE, intel_nic::mbox, mdelay(), msg(), readl, intel_nic::regs, and writel.

Referenced by intelvf_mbox_reset(), intelvf_mbox_set_mac(), intelvf_mbox_set_mtu(), intelxvf_mbox_queues(), and intelxvf_mbox_version().

◆ intelvf_mbox_poll()

int intelvf_mbox_poll ( struct intel_nic * intel)
extern

Poll mailbox.

Parameters
intelIntel device
Return values
rcReturn status code

Note that polling the mailbox may fail if the underlying PF is reset.

Definition at line 99 of file intelvf.c.

99 {
100 struct intel_mailbox *mbox = &intel->mbox;
101 union intelvf_msg msg;
103
104 /* Get mailbox status */
105 ctrl = readl ( intel->regs + mbox->ctrl );
106
107 /* Fail if a reset is in progress */
109 return -EPIPE;
110
111 /* Acknowledge (and ignore) any received messages */
112 if ( ctrl & INTELVF_MBCTRL_PFSTS ) {
113 intelvf_mbox_read ( intel, &msg );
114 writel ( INTELVF_MBCTRL_ACK, intel->regs + mbox->ctrl );
115 }
116
117 return 0;
118}
Mailbox message.
Definition intelvf.h:130

References ctrl, EPIPE, INTELVF_MBCTRL_ACK, INTELVF_MBCTRL_PFSTS, INTELVF_MBCTRL_RSTI, intelvf_mbox_read(), intel_nic::mbox, msg(), readl, intel_nic::regs, and writel.

Referenced by intelvf_mbox_wait(), and intelxvf_poll().

◆ intelvf_mbox_wait()

int intelvf_mbox_wait ( struct intel_nic * intel)
extern

Wait for PF reset to complete.

Parameters
intelIntel device
Return values
rcReturn status code

Definition at line 126 of file intelvf.c.

126 {
127 unsigned int i;
128 int rc;
129
130 /* Wait until a poll completes successfully */
131 for ( i = 0 ; i < INTELVF_MBOX_MAX_WAIT_MS ; i++ ) {
132
133 /* Check for successful poll */
134 if ( ( rc = intelvf_mbox_poll ( intel ) ) == 0 )
135 return 0;
136
137 /* Delay */
138 mdelay ( 1 );
139 }
140
141 DBGC ( intel, "INTEL %p timed out waiting for reset\n", intel );
142 return -ETIMEDOUT;
143}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
int intelvf_mbox_poll(struct intel_nic *intel)
Poll mailbox.
Definition intelvf.c:99

References DBGC, ETIMEDOUT, INTELVF_MBOX_MAX_WAIT_MS, intelvf_mbox_poll(), mdelay(), and rc.

◆ intelvf_mbox_reset()

int intelvf_mbox_reset ( struct intel_nic * intel,
uint8_t * hw_addr )
extern

Send reset message and get initial MAC address.

Parameters
intelIntel device
hw_addrHardware address to fill in, or NULL
Return values
rcReturn status code

Definition at line 233 of file intelvf.c.

233 {
234 union intelvf_msg msg;
235 int rc;
236
237 /* Send reset message */
238 memset ( &msg, 0, sizeof ( msg ) );
240 if ( ( rc = intelvf_mbox_msg ( intel, &msg ) ) != 0 ) {
241 DBGC ( intel, "INTEL %p reset failed: %s\n",
242 intel, strerror ( rc ) );
243 return rc;
244 }
245
246 /* Check response */
248 DBGC ( intel, "INTEL %p reset unexpected response:\n", intel );
249 DBGC_HDA ( intel, 0, &msg, sizeof ( msg ) );
250 return -EPROTO;
251 }
252
253 /* Fill in MAC address, if applicable */
254 if ( hw_addr ) {
255 if ( msg.hdr & INTELVF_MSG_ACK ) {
256 memcpy ( hw_addr, msg.mac.mac, sizeof ( msg.mac.mac ) );
257 DBGC ( intel, "INTEL %p reset assigned MAC address "
258 "%s\n", intel, eth_ntoa ( hw_addr ) );
259 } else {
260 eth_random_addr ( hw_addr );
261 DBGC ( intel, "INTEL %p reset generated MAC address "
262 "%s\n", intel, eth_ntoa ( hw_addr ) );
263 }
264 }
265
266 return 0;
267}
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition ethernet.c:176
void eth_random_addr(void *hw_addr)
Generate random Ethernet address.
Definition ethernet.c:160
#define DBGC_HDA(...)
Definition compiler.h:506
#define EPROTO
Protocol error.
Definition errno.h:625
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
int intelvf_mbox_msg(struct intel_nic *intel, union intelvf_msg *msg)
Send/receive mailbox message.
Definition intelvf.c:152
#define INTELVF_MSG_TYPE_RESET
Reset mailbox message.
Definition intelvf.h:33
#define INTELVF_MSG_ACK
Message ACK flag.
Definition intelvf.h:54
#define INTELVF_MSG_TYPE_MASK
Message type mask.
Definition intelvf.h:48
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79

References DBGC, DBGC_HDA, EPROTO, eth_ntoa(), eth_random_addr(), intelvf_mbox_msg(), INTELVF_MSG_ACK, INTELVF_MSG_TYPE_MASK, INTELVF_MSG_TYPE_RESET, memcpy(), memset(), msg(), rc, and strerror().

Referenced by intelxvf_open(), and intelxvf_probe().

◆ intelvf_mbox_set_mac()

int intelvf_mbox_set_mac ( struct intel_nic * intel,
const uint8_t * ll_addr )
extern

Send set MAC address message.

Parameters
intelIntel device
ll_addrLink-layer address
Return values
rcReturn status code

Definition at line 276 of file intelvf.c.

276 {
277 union intelvf_msg msg;
278 int rc;
279
280 /* Send set MAC address message */
281 memset ( &msg, 0, sizeof ( msg ) );
283 memcpy ( msg.mac.mac, ll_addr, sizeof ( msg.mac.mac ) );
284 if ( ( rc = intelvf_mbox_msg ( intel, &msg ) ) != 0 ) {
285 DBGC ( intel, "INTEL %p set MAC address failed: %s\n",
286 intel, strerror ( rc ) );
287 return rc;
288 }
289
290 /* Check response */
292 DBGC ( intel, "INTEL %p set MAC address unexpected response:\n",
293 intel );
294 DBGC_HDA ( intel, 0, &msg, sizeof ( msg ) );
295 return -EPROTO;
296 }
297
298 /* Check that we were allowed to set the MAC address */
299 if ( ! ( msg.hdr & INTELVF_MSG_ACK ) ) {
300 DBGC ( intel, "INTEL %p set MAC address refused\n", intel );
301 return -EPERM;
302 }
303
304 return 0;
305}
#define EPERM
Operation not permitted.
Definition errno.h:615
#define INTELVF_MSG_TYPE_SET_MAC
Set MAC address mailbox message.
Definition intelvf.h:36

References DBGC, DBGC_HDA, EPERM, EPROTO, intelvf_mbox_msg(), INTELVF_MSG_ACK, INTELVF_MSG_TYPE_MASK, INTELVF_MSG_TYPE_SET_MAC, memcpy(), memset(), msg(), rc, and strerror().

Referenced by intelxvf_open().

◆ intelvf_mbox_set_mtu()

int intelvf_mbox_set_mtu ( struct intel_nic * intel,
size_t mtu )
extern

Send set MTU message.

Parameters
intelIntel device
mtuMaximum packet size
Return values
rcReturn status code

Definition at line 314 of file intelvf.c.

314 {
315 union intelvf_msg msg;
316 int rc;
317
318 /* Send set MTU message */
319 memset ( &msg, 0, sizeof ( msg ) );
321 msg.mtu.mtu = mtu;
322 if ( ( rc = intelvf_mbox_msg ( intel, &msg ) ) != 0 ) {
323 DBGC ( intel, "INTEL %p set MTU failed: %s\n",
324 intel, strerror ( rc ) );
325 return rc;
326 }
327
328 /* Check response */
330 DBGC ( intel, "INTEL %p set MTU unexpected response:\n",
331 intel );
332 DBGC_HDA ( intel, 0, &msg, sizeof ( msg ) );
333 return -EPROTO;
334 }
335
336 /* Check that we were allowed to set the MTU */
337 if ( ! ( msg.hdr & INTELVF_MSG_ACK ) ) {
338 DBGC ( intel, "INTEL %p set MTU refused\n", intel );
339 return -EPERM;
340 }
341
342 return 0;
343}
uint32_t mtu
Maximum MTU.
Definition ena.h:17
#define INTELVF_MSG_TYPE_SET_MTU
Set MTU mailbox message.
Definition intelvf.h:39

References DBGC, DBGC_HDA, EPERM, EPROTO, intelvf_mbox_msg(), INTELVF_MSG_ACK, INTELVF_MSG_TYPE_MASK, INTELVF_MSG_TYPE_SET_MTU, memset(), msg(), mtu, rc, and strerror().

Referenced by intelxvf_open().