iPXE
mlx_icmd.c File Reference

Go to the source code of this file.

Macros

#define ICMD_GET_SEMAPHORE_TRIES   2560
#define MLX_ICMD_OPCODE_ALIGN   16
#define MLX_ICMD_OPCODE_MASK   0xffff
#define MLX_ICMD_BUSY_ALIGN   0
#define MLX_ICMD_BUSY_MASK   0x1
#define MLX_ICMD_BUSY_MAX_ITERATIONS   1024
#define MLX_ICMD_STATUS_ALIGN   8
#define MLX_ICMD_STATUS_MASK   0xff

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static mlx_status mlx_icmd_get_semaphore (IN mlx_utils *utils)
static mlx_status mlx_icmd_clear_semaphore (IN mlx_utils *utils)
static mlx_status mlx_icmd_init (IN mlx_utils *utils)
static mlx_status mlx_icmd_set_opcode (IN mlx_utils *utils, IN mlx_uint16 opcode)
static mlx_status mlx_icmd_go (IN mlx_utils *utils)
static mlx_status mlx_icmd_get_status (IN mlx_utils *utils, OUT mlx_uint32 *out_status)
static mlx_status mlx_icmd_write_buffer (IN mlx_utils *utils, IN mlx_void *data, IN mlx_uint32 data_size)
static mlx_status mlx_icmd_read_buffer (IN mlx_utils *utils, OUT mlx_void *data, IN mlx_uint32 data_size)
mlx_status mlx_icmd_send_command (IN mlx_utils *utils, IN mlx_uint16 opcode, IN OUT mlx_void *data, IN mlx_uint32 write_data_size, IN mlx_uint32 read_data_size)

Macro Definition Documentation

◆ ICMD_GET_SEMAPHORE_TRIES

#define ICMD_GET_SEMAPHORE_TRIES   2560

Referenced by mlx_icmd_get_semaphore().

◆ MLX_ICMD_OPCODE_ALIGN

#define MLX_ICMD_OPCODE_ALIGN   16

Referenced by mlx_icmd_set_opcode().

◆ MLX_ICMD_OPCODE_MASK

#define MLX_ICMD_OPCODE_MASK   0xffff

Referenced by mlx_icmd_set_opcode().

◆ MLX_ICMD_BUSY_ALIGN

#define MLX_ICMD_BUSY_ALIGN   0

Referenced by mlx_icmd_go().

◆ MLX_ICMD_BUSY_MASK

#define MLX_ICMD_BUSY_MASK   0x1

Referenced by mlx_icmd_go().

◆ MLX_ICMD_BUSY_MAX_ITERATIONS

#define MLX_ICMD_BUSY_MAX_ITERATIONS   1024

Referenced by mlx_icmd_go().

◆ MLX_ICMD_STATUS_ALIGN

#define MLX_ICMD_STATUS_ALIGN   8

Referenced by mlx_icmd_get_status().

◆ MLX_ICMD_STATUS_MASK

#define MLX_ICMD_STATUS_MASK   0xff

Referenced by mlx_icmd_get_status().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER )

◆ mlx_icmd_get_semaphore()

mlx_status mlx_icmd_get_semaphore ( IN mlx_utils * utils)
static

Definition at line 30 of file mlx_icmd.c.

33{
35 mlx_uint32 retries = 0;
36 mlx_uint32 semaphore_id;
38 if (utils == NULL) {
40 goto invalid_param;
41 }
42
43 status = mlx_utils_rand(utils, &semaphore_id);
44 MLX_CHECK_STATUS(utils, status, rand_err, "failed to get random number");
45#define ICMD_GET_SEMAPHORE_TRIES 2560
46 for (retries = 0 ; retries < ICMD_GET_SEMAPHORE_TRIES ; retries++) {
49 MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd semaphore");
50 if (buffer != 0) {
52 continue;
53 }
55 MLX_ICMD_SEMAPHORE_ADDR, semaphore_id);
56 MLX_CHECK_STATUS(utils, status, set_err, "failed to set icmd semaphore");
59 MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd semaphore");
60 if (semaphore_id == buffer) {
62 utils->icmd.took_semaphore = TRUE;
63 break;
64 }
66 }
67 if (semaphore_id != buffer) {
69 }
70read_err:
71set_err:
72rand_err:
73invalid_param:
74 return status;
75}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
uint8_t status
Status.
Definition ena.h:5
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
#define MLX_CHECK_STATUS(id, status, label, message)
Definition mlx_bail.h:37
#define ICMD_GET_SEMAPHORE_TRIES
#define MLX_ICMD_SEMAPHORE_ADDR
Definition mlx_icmd.h:31
#define PCI_GW_SPACE_SEMAPHORE
Definition mlx_pci_gw.h:49
mlx_status mlx_pci_gw_read(IN mlx_utils *utils, IN mlx_pci_gw_space space, IN mlx_uint32 address, OUT mlx_pci_gw_buffer *buffer)
Definition mlx_pci_gw.c:258
mlx_status mlx_pci_gw_write(IN mlx_utils *utils, IN mlx_pci_gw_space space, IN mlx_uint32 address, IN mlx_pci_gw_buffer buffer)
Definition mlx_pci_gw.c:328
uint32_t mlx_uint32
#define MLX_FAILED
#define MLX_INVALID_PARAMETER
#define MLX_SUCCESS
int mlx_status
mlx_status mlx_utils_delay_in_ms(IN mlx_uint32 msecs)
Definition mlx_utils.c:57
mlx_status mlx_utils_rand(IN mlx_utils *utils, OUT mlx_uint32 *rand_num)
Definition mlx_utils.c:116
#define TRUE
Definition tlan.h:46

References buffer, ICMD_GET_SEMAPHORE_TRIES, IN, MLX_CHECK_STATUS, MLX_FAILED, MLX_ICMD_SEMAPHORE_ADDR, MLX_INVALID_PARAMETER, mlx_pci_gw_read(), mlx_pci_gw_write(), MLX_SUCCESS, mlx_utils_delay_in_ms(), mlx_utils_rand(), NULL, PCI_GW_SPACE_SEMAPHORE, status, and TRUE.

Referenced by mlx_icmd_send_command().

◆ mlx_icmd_clear_semaphore()

mlx_status mlx_icmd_clear_semaphore ( IN mlx_utils * utils)
static

Definition at line 78 of file mlx_icmd.c.

81{
83
84 if (utils == NULL) {
86 goto invalid_param;
87 }
88
89 if (utils->icmd.took_semaphore == FALSE) {
90 goto semaphore_not_taken;
91 }
94 MLX_CHECK_STATUS(utils, status, read_err, "failed to clear icmd semaphore");
95
96 utils->icmd.took_semaphore = FALSE;
97read_err:
98semaphore_not_taken:
99invalid_param:
100 return status;
101}
#define FALSE
Definition tlan.h:45

References FALSE, IN, MLX_CHECK_STATUS, MLX_ICMD_SEMAPHORE_ADDR, MLX_INVALID_PARAMETER, mlx_pci_gw_write(), MLX_SUCCESS, NULL, PCI_GW_SPACE_SEMAPHORE, and status.

Referenced by mlx_icmd_send_command().

◆ mlx_icmd_init()

mlx_status mlx_icmd_init ( IN mlx_utils * utils)
static

Definition at line 105 of file mlx_icmd.c.

108{
110
111 if (utils == NULL) {
113 goto invalid_param;
114 }
115 if (utils->icmd.icmd_opened == TRUE) {
116 goto already_opened;
117 }
118
119 utils->icmd.took_semaphore = FALSE;
120
122 MLX_ICMD_MB_SIZE_ADDR, &utils->icmd.max_cmd_size);
123 MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd mail box size");
124
125 utils->icmd.icmd_opened = TRUE;
126read_err:
127already_opened:
128invalid_param:
129 return status;
130}
#define MLX_ICMD_MB_SIZE_ADDR
Definition mlx_icmd.h:28
#define PCI_GW_SPACE_ALL_ICMD
Definition mlx_pci_gw.h:48

References FALSE, IN, MLX_CHECK_STATUS, MLX_ICMD_MB_SIZE_ADDR, MLX_INVALID_PARAMETER, mlx_pci_gw_read(), MLX_SUCCESS, NULL, PCI_GW_SPACE_ALL_ICMD, status, and TRUE.

Referenced by mlx_icmd_send_command().

◆ mlx_icmd_set_opcode()

mlx_status mlx_icmd_set_opcode ( IN mlx_utils * utils,
IN mlx_uint16 opcode )
static

Definition at line 134 of file mlx_icmd.c.

138{
141
142 if (utils == NULL) {
144 goto invalid_param;
145 }
146
149 MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd ctrl");
150
151#define MLX_ICMD_OPCODE_ALIGN 16
152#define MLX_ICMD_OPCODE_MASK 0xffff
153
156
159 MLX_CHECK_STATUS(utils, status, write_err, "failed to write icmd ctrl");
160write_err:
161read_err:
162invalid_param:
163 return status;
164}
uint8_t opcode
Opcode.
Definition ena.h:5
#define MLX_ICMD_OPCODE_MASK
#define MLX_ICMD_OPCODE_ALIGN
#define MLX_ICMD_CTRL_ADDR
Definition mlx_icmd.h:29

References buffer, IN, MLX_CHECK_STATUS, MLX_ICMD_CTRL_ADDR, MLX_ICMD_OPCODE_ALIGN, MLX_ICMD_OPCODE_MASK, MLX_INVALID_PARAMETER, mlx_pci_gw_read(), mlx_pci_gw_write(), MLX_SUCCESS, NULL, opcode, PCI_GW_SPACE_ALL_ICMD, and status.

Referenced by mlx_icmd_send_command().

◆ mlx_icmd_go()

mlx_status mlx_icmd_go ( IN mlx_utils * utils)
static

Definition at line 168 of file mlx_icmd.c.

171{
174 mlx_uint32 busy;
175 mlx_uint32 wait_iteration = 0;
176
177 if (utils == NULL) {
179 goto invalid_param;
180 }
181
184 MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd ctrl");
185
186#define MLX_ICMD_BUSY_ALIGN 0
187#define MLX_ICMD_BUSY_MASK 0x1
188
190 if (busy != 0) {
192 goto already_busy;
193 }
194
196
199 MLX_CHECK_STATUS(utils, status, write_err, "failed to write icmd ctrl");
200
201#define MLX_ICMD_BUSY_MAX_ITERATIONS 1024
202 do {
203 if (++wait_iteration > MLX_ICMD_BUSY_MAX_ITERATIONS) {
205 MLX_DEBUG_ERROR(utils, "ICMD time out");
206 goto busy_timeout;
207 }
208
212 MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd ctrl");
214 } while (busy != 0);
215
216busy_timeout:
217write_err:
218already_busy:
219read_err:
220invalid_param:
221 return status;
222}
#define MLX_ICMD_BUSY_MASK
#define MLX_ICMD_BUSY_ALIGN
#define MLX_ICMD_BUSY_MAX_ITERATIONS
#define MLX_DEBUG_ERROR(...)
Definition mlx_logging.h:29

References buffer, IN, MLX_CHECK_STATUS, MLX_DEBUG_ERROR, MLX_FAILED, MLX_ICMD_BUSY_ALIGN, MLX_ICMD_BUSY_MASK, MLX_ICMD_BUSY_MAX_ITERATIONS, MLX_ICMD_CTRL_ADDR, MLX_INVALID_PARAMETER, mlx_pci_gw_read(), mlx_pci_gw_write(), MLX_SUCCESS, mlx_utils_delay_in_ms(), NULL, PCI_GW_SPACE_ALL_ICMD, and status.

Referenced by mlx_icmd_send_command().

◆ mlx_icmd_get_status()

mlx_status mlx_icmd_get_status ( IN mlx_utils * utils,
OUT mlx_uint32 * out_status )
static

Definition at line 226 of file mlx_icmd.c.

230{
233
234 if (utils == NULL || out_status == NULL) {
236 goto invalid_param;
237 }
238
241 MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd ctrl");
242
243#define MLX_ICMD_STATUS_ALIGN 8
244#define MLX_ICMD_STATUS_MASK 0xff
245
247
248read_err:
249invalid_param:
250 return status;
251}
#define MLX_ICMD_STATUS_ALIGN
#define MLX_ICMD_STATUS_MASK

References buffer, IN, MLX_CHECK_STATUS, MLX_ICMD_CTRL_ADDR, MLX_ICMD_STATUS_ALIGN, MLX_ICMD_STATUS_MASK, MLX_INVALID_PARAMETER, mlx_pci_gw_read(), MLX_SUCCESS, NULL, OUT, PCI_GW_SPACE_ALL_ICMD, and status.

Referenced by mlx_icmd_send_command().

◆ mlx_icmd_write_buffer()

mlx_status mlx_icmd_write_buffer ( IN mlx_utils * utils,
IN mlx_void * data,
IN mlx_uint32 data_size )
static

Definition at line 255 of file mlx_icmd.c.

260{
262 mlx_uint32 data_offset = 0;
263 mlx_size dword_size = sizeof(mlx_uint32);
264
265 if (utils == NULL || data == NULL) {
267 goto invalid_param;
268 }
269
270 for (data_offset = 0 ; data_offset*dword_size < data_size ; data_offset++) {
272 MLX_ICMD_MB_ADDR + data_offset*dword_size,
273 ((mlx_uint32*)data)[data_offset]);
274 MLX_CHECK_STATUS(utils, status, write_err, "failed to write icmd MB");
275 }
276write_err:
277invalid_param:
278 return status;
279}
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define MLX_ICMD_MB_ADDR
Definition mlx_icmd.h:27
size_t mlx_size

References data, IN, MLX_CHECK_STATUS, MLX_ICMD_MB_ADDR, MLX_INVALID_PARAMETER, mlx_pci_gw_write(), MLX_SUCCESS, NULL, PCI_GW_SPACE_ALL_ICMD, and status.

Referenced by mlx_icmd_send_command().

◆ mlx_icmd_read_buffer()

mlx_status mlx_icmd_read_buffer ( IN mlx_utils * utils,
OUT mlx_void * data,
IN mlx_uint32 data_size )
static

Definition at line 284 of file mlx_icmd.c.

289{
291 mlx_uint32 data_offset = 0;
292 mlx_size dword_size = sizeof(mlx_uint32);
293
294 if (utils == NULL || data == NULL) {
296 goto invalid_param;
297 }
298
299 for (data_offset = 0 ; data_offset*dword_size < data_size ; data_offset++) {
301 MLX_ICMD_MB_ADDR + data_offset*dword_size,
302 (mlx_uint32*)data + data_offset);
303 MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd MB");
304 }
305read_err:
306invalid_param:
307 return status;
308}

References data, IN, MLX_CHECK_STATUS, MLX_ICMD_MB_ADDR, MLX_INVALID_PARAMETER, mlx_pci_gw_read(), MLX_SUCCESS, NULL, OUT, PCI_GW_SPACE_ALL_ICMD, and status.

Referenced by mlx_icmd_send_command().

◆ mlx_icmd_send_command()

mlx_status mlx_icmd_send_command ( IN mlx_utils * utils,
IN mlx_uint16 opcode,
IN OUT mlx_void * data,
IN mlx_uint32 write_data_size,
IN mlx_uint32 read_data_size )

Definition at line 310 of file mlx_icmd.c.

317{
319 mlx_uint32 icmd_status = 0;
320
321 if (utils == NULL || data == NULL) {
323 goto invalid_param;
324 }
325 status = mlx_icmd_init(utils);
326 MLX_CHECK_STATUS(utils, status, open_err, "failed to open icmd");
327
328 if (write_data_size > utils->icmd.max_cmd_size ||
329 read_data_size > utils->icmd.max_cmd_size) {
331 goto size_err;
332 }
333
335 MLX_CHECK_STATUS(utils, status, semaphore_err, "failed to get icmd semaphore");
336
338 MLX_CHECK_STATUS(utils, status, opcode_err, "failed to set icmd opcode");
339
340 if (write_data_size != 0) {
341 status = mlx_icmd_write_buffer(utils, data, write_data_size);
342 MLX_CHECK_STATUS(utils, status, opcode_err, "failed to write icmd MB");
343 }
344
345 status = mlx_icmd_go(utils);
346 MLX_CHECK_STATUS(utils, status, go_err, "failed to activate icmd");
347
348 status = mlx_icmd_get_status(utils, &icmd_status);
349 MLX_CHECK_STATUS(utils, status, get_status_err, "failed to set icmd opcode");
350
351 if (icmd_status != 0) {
352 MLX_DEBUG_ERROR(utils, "icmd failed with status = %d\n", icmd_status);
354 goto icmd_failed;
355 }
356 if (read_data_size != 0) {
357 status = mlx_icmd_read_buffer(utils, data, read_data_size);
358 MLX_CHECK_STATUS(utils, status, read_err, "failed to read icmd MB");
359 }
360read_err:
361icmd_failed:
362get_status_err:
363go_err:
364opcode_err:
366semaphore_err:
367size_err:
368open_err:
369invalid_param:
370 return status;
371}
static mlx_status mlx_icmd_go(IN mlx_utils *utils)
Definition mlx_icmd.c:168
static mlx_status mlx_icmd_write_buffer(IN mlx_utils *utils, IN mlx_void *data, IN mlx_uint32 data_size)
Definition mlx_icmd.c:255
static mlx_status mlx_icmd_clear_semaphore(IN mlx_utils *utils)
Definition mlx_icmd.c:78
static mlx_status mlx_icmd_get_status(IN mlx_utils *utils, OUT mlx_uint32 *out_status)
Definition mlx_icmd.c:226
static mlx_status mlx_icmd_set_opcode(IN mlx_utils *utils, IN mlx_uint16 opcode)
Definition mlx_icmd.c:134
static mlx_status mlx_icmd_read_buffer(IN mlx_utils *utils, OUT mlx_void *data, IN mlx_uint32 data_size)
Definition mlx_icmd.c:284
static mlx_status mlx_icmd_init(IN mlx_utils *utils)
Definition mlx_icmd.c:105
static mlx_status mlx_icmd_get_semaphore(IN mlx_utils *utils)
Definition mlx_icmd.c:30

References data, IN, MLX_CHECK_STATUS, MLX_DEBUG_ERROR, MLX_FAILED, mlx_icmd_clear_semaphore(), mlx_icmd_get_semaphore(), mlx_icmd_get_status(), mlx_icmd_go(), mlx_icmd_init(), mlx_icmd_read_buffer(), mlx_icmd_set_opcode(), mlx_icmd_write_buffer(), MLX_INVALID_PARAMETER, MLX_SUCCESS, NULL, opcode, OUT, and status.

Referenced by mlx_reg_access(), mlx_vmac_query_virt_mac(), and mlx_vmac_set_virt_mac().