iPXE
mlx_pci_gw.c File Reference

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
static mlx_status mlx_pci_gw_check_capability_id (IN mlx_utils *utils, IN mlx_uint8 cap_pointer, OUT mlx_boolean *result)
static mlx_status mlx_pci_gw_get_ownership (IN mlx_utils *utils)
static mlx_status mlx_pci_gw_free_ownership (IN mlx_utils *utils)
static mlx_status mlx_pci_gw_set_space (IN mlx_utils *utils, IN mlx_pci_gw_space space)
static mlx_status mlx_pci_gw_wait_for_flag_value (IN mlx_utils *utils, IN mlx_boolean value)
static mlx_status mlx_pci_gw_search_capability (IN mlx_utils *utils, OUT mlx_uint32 *cap_offset)
mlx_status mlx_pci_gw_init (IN mlx_utils *utils)
mlx_status mlx_pci_gw_teardown (IN mlx_utils *utils)
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)
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)

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER )

◆ mlx_pci_gw_check_capability_id()

mlx_status mlx_pci_gw_check_capability_id ( IN mlx_utils * utils,
IN mlx_uint8 cap_pointer,
OUT mlx_boolean * result )
static

Definition at line 32 of file mlx_pci_gw.c.

37{
40 mlx_uint8 id = 0;
42 1, &id);
43 MLX_CHECK_STATUS(utils, status, read_err,"failed to read capability id");
44 *result = ( id == PCI_GW_CAPABILITY_ID );
45read_err:
46 return status;
47}
uint16_t result
Definition hyperv.h:33
uint16_t offset
Offset to command line.
Definition bzimage.h:3
uint8_t status
Status.
Definition ena.h:5
#define MLX_CHECK_STATUS(id, status, label, message)
Definition mlx_bail.h:37
mlx_status mlx_pci_read(IN mlx_utils *utils, IN mlx_pci_width width, IN mlx_uint32 offset, IN mlx_uintn count, OUT mlx_void *buffer)
Definition mlx_pci.c:58
@ MlxPciWidthUint8
Definition mlx_pci.h:28
#define PCI_GW_CAPABILITY_ID
Definition mlx_pci_gw.h:29
#define PCI_GW_CAPABILITY_ID_OFFSET
Definition mlx_pci_gw.h:31
#define MLX_SUCCESS
int mlx_status
uint8_t mlx_uint8

References IN, MLX_CHECK_STATUS, mlx_pci_read(), MLX_SUCCESS, MlxPciWidthUint8, offset, OUT, PCI_GW_CAPABILITY_ID, PCI_GW_CAPABILITY_ID_OFFSET, result, and status.

Referenced by mlx_pci_gw_search_capability().

◆ mlx_pci_gw_get_ownership()

mlx_status mlx_pci_gw_get_ownership ( IN mlx_utils * utils)
static

Definition at line 51 of file mlx_pci_gw.c.

54{
56 mlx_uint32 cap_offset = utils->pci_gw.pci_cmd_offset;
57 mlx_uint32 semaphore = 0;
58 mlx_uint32 counter = 0;
59 mlx_uint32 get_semaphore_try = 0;
60 mlx_uint32 get_ownership_try = 0;
61
62 for( ; get_ownership_try < PCI_GW_GET_OWNERSHIP_TRIES; get_ownership_try ++){
63 for( ; get_semaphore_try <= PCI_GW_SEMPHORE_TRIES ; get_semaphore_try++){
65 1, &semaphore);
66 MLX_CHECK_STATUS(utils, status, read_err,"failed to read semaphore");
67 if( semaphore == 0 ){
68 break;
69 }
71 }
72 if( semaphore != 0 ){
74 goto semaphore_err;
75 }
76
78 1, &counter);
79 MLX_CHECK_STATUS(utils, status, read_err, "failed to read counter");
80
82 1, &counter);
83 MLX_CHECK_STATUS(utils, status, write_err,"failed to write semaphore");
84
86 1, &semaphore);
87 MLX_CHECK_STATUS(utils, status, read_err,"failed to read semaphore");
88 if( counter == semaphore ){
89 break;
90 }
91 }
92 if( counter != semaphore ){
94 }
95write_err:
96read_err:
97semaphore_err:
98 return status;
99}
mlx_status mlx_pci_write(IN mlx_utils *utils, IN mlx_pci_width width, IN mlx_uint32 offset, IN mlx_uintn count, IN mlx_void *buffer)
Definition mlx_pci.c:77
@ MlxPciWidthUint32
Definition mlx_pci.h:30
#define PCI_GW_CAPABILITY_COUNTER_OFFSET
Definition mlx_pci_gw.h:35
#define PCI_GW_GET_OWNERSHIP_TRIES
Definition mlx_pci_gw.h:42
#define PCI_GW_CAPABILITY_SEMAPHORE_OFFSET
Definition mlx_pci_gw.h:36
#define PCI_GW_SEMPHORE_TRIES
Definition mlx_pci_gw.h:41
uint32_t mlx_uint32
#define MLX_FAILED
mlx_status mlx_utils_delay_in_us(IN mlx_uint32 usecs)
Definition mlx_utils.c:65

References IN, MLX_CHECK_STATUS, MLX_FAILED, mlx_pci_read(), mlx_pci_write(), MLX_SUCCESS, mlx_utils_delay_in_us(), MlxPciWidthUint32, PCI_GW_CAPABILITY_COUNTER_OFFSET, PCI_GW_CAPABILITY_SEMAPHORE_OFFSET, PCI_GW_GET_OWNERSHIP_TRIES, PCI_GW_SEMPHORE_TRIES, and status.

Referenced by mlx_pci_gw_init(), mlx_pci_gw_read(), and mlx_pci_gw_write().

◆ mlx_pci_gw_free_ownership()

mlx_status mlx_pci_gw_free_ownership ( IN mlx_utils * utils)
static

Definition at line 103 of file mlx_pci_gw.c.

106{
108 mlx_uint32 cap_offset = utils->pci_gw.pci_cmd_offset;
109 mlx_uint32 value = 0;
110
112 1, &value);
113 MLX_CHECK_STATUS(utils, status, write_err,"failed to write semaphore");
114write_err:
115 return status;
116}
pseudo_bit_t value[0x00020]
Definition arbel.h:2

References IN, MLX_CHECK_STATUS, mlx_pci_write(), MLX_SUCCESS, MlxPciWidthUint32, PCI_GW_CAPABILITY_SEMAPHORE_OFFSET, status, and value.

Referenced by mlx_pci_gw_read(), mlx_pci_gw_teardown(), and mlx_pci_gw_write().

◆ mlx_pci_gw_set_space()

mlx_status mlx_pci_gw_set_space ( IN mlx_utils * utils,
IN mlx_pci_gw_space space )
static

Definition at line 120 of file mlx_pci_gw.c.

124{
126 mlx_uint32 cap_offset = utils->pci_gw.pci_cmd_offset;;
127 mlx_uint8 space_status = 0;
128
129 /* set nodnic*/
130 status = mlx_pci_write(utils, MlxPciWidthUint16, cap_offset + PCI_GW_CAPABILITY_SPACE_OFFSET, 1, &space);
131 MLX_CHECK_STATUS(utils, status, read_error,"failed to write capability space");
132
133 status = mlx_pci_read(utils, MlxPciWidthUint8, cap_offset + PCI_GW_CAPABILITY_STATUS_OFFSET, 1, &space_status);
134 MLX_CHECK_STATUS(utils, status, read_error,"failed to read capability status");
135 if( (space_status & 0x20) == 0){
137 goto space_unsupported;
138 }
139read_error:
140space_unsupported:
141 return status;
142}
@ MlxPciWidthUint16
Definition mlx_pci.h:29
#define PCI_GW_CAPABILITY_SPACE_OFFSET
Definition mlx_pci_gw.h:33
#define PCI_GW_CAPABILITY_STATUS_OFFSET
Definition mlx_pci_gw.h:34

References IN, MLX_CHECK_STATUS, MLX_FAILED, mlx_pci_read(), mlx_pci_write(), MLX_SUCCESS, MlxPciWidthUint16, MlxPciWidthUint8, PCI_GW_CAPABILITY_SPACE_OFFSET, PCI_GW_CAPABILITY_STATUS_OFFSET, and status.

Referenced by mlx_pci_gw_read(), and mlx_pci_gw_write().

◆ mlx_pci_gw_wait_for_flag_value()

mlx_status mlx_pci_gw_wait_for_flag_value ( IN mlx_utils * utils,
IN mlx_boolean value )
static

Definition at line 146 of file mlx_pci_gw.c.

150{
152 mlx_uint32 try = 0;
153 mlx_uint32 cap_offset = utils->pci_gw.pci_cmd_offset;
154 mlx_uint32 flag = 0;
155
156 for(; try < PCI_GW_READ_FLAG_TRIES ; try ++ ) {
158 MLX_CHECK_STATUS(utils, status, read_error, "failed to read capability flag");
159 if( ((flag & 0x80000000) != 0) == value ){
160 goto flag_valid;
161 }
163 }
165flag_valid:
166read_error:
167 return status;
168}
uint32_t flag
Flag number.
Definition aqc1xx.h:2
#define PCI_GW_READ_FLAG_TRIES
Definition mlx_pci_gw.h:43
#define PCI_GW_CAPABILITY_FLAG_OFFSET
Definition mlx_pci_gw.h:38

References flag, IN, MLX_CHECK_STATUS, MLX_FAILED, mlx_pci_read(), MLX_SUCCESS, mlx_utils_delay_in_us(), MlxPciWidthUint32, PCI_GW_CAPABILITY_FLAG_OFFSET, PCI_GW_READ_FLAG_TRIES, status, and value.

Referenced by mlx_pci_gw_read(), and mlx_pci_gw_write().

◆ mlx_pci_gw_search_capability()

mlx_status mlx_pci_gw_search_capability ( IN mlx_utils * utils,
OUT mlx_uint32 * cap_offset )
static

Definition at line 171 of file mlx_pci_gw.c.

175{
177 mlx_uint8 cap_pointer = 0;
178 mlx_boolean is_capability = FALSE;
179
180 if( cap_offset == NULL || utils == NULL){
182 goto bad_param;
183 }
184
185 //get first capability pointer
187 1, &cap_pointer);
188 MLX_CHECK_STATUS(utils, status, read_err,
189 "failed to read capability pointer");
190
191 //search the right capability
192 while( cap_pointer != 0 ){
193 status = mlx_pci_gw_check_capability_id(utils, cap_pointer, &is_capability);
194 MLX_CHECK_STATUS(utils, status, check_err
195 ,"failed to check capability id");
196
197 if( is_capability == TRUE ){
198 *cap_offset = cap_pointer;
199 break;
200 }
201
202 status = mlx_pci_read(utils, MlxPciWidthUint8, cap_pointer +
204 1, &cap_pointer);
205 MLX_CHECK_STATUS(utils, status, read_err,
206 "failed to read capability pointer");
207 }
208 if( is_capability != TRUE ){
210 }
211check_err:
212read_err:
213bad_param:
214 return status;
215}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
static mlx_status mlx_pci_gw_check_capability_id(IN mlx_utils *utils, IN mlx_uint8 cap_pointer, OUT mlx_boolean *result)
Definition mlx_pci_gw.c:32
#define PCI_GW_FIRST_CAPABILITY_POINTER_OFFSET
Definition mlx_pci_gw.h:27
#define PCI_GW_CAPABILITY_NEXT_POINTER_OFFSET
Definition mlx_pci_gw.h:32
#define MLX_INVALID_PARAMETER
#define MLX_NOT_FOUND
uint8_t mlx_boolean
#define TRUE
Definition tlan.h:46
#define FALSE
Definition tlan.h:45

References FALSE, IN, MLX_CHECK_STATUS, MLX_INVALID_PARAMETER, MLX_NOT_FOUND, mlx_pci_gw_check_capability_id(), mlx_pci_read(), MLX_SUCCESS, MlxPciWidthUint8, NULL, OUT, PCI_GW_CAPABILITY_NEXT_POINTER_OFFSET, PCI_GW_FIRST_CAPABILITY_POINTER_OFFSET, status, and TRUE.

Referenced by mlx_pci_gw_init().

◆ mlx_pci_gw_init()

mlx_status mlx_pci_gw_init ( IN mlx_utils * utils)

Definition at line 218 of file mlx_pci_gw.c.

221{
223 mlx_pci_gw *pci_gw = NULL;
224
225 if( utils == NULL){
227 goto bad_param;
228 }
229
230 pci_gw = &utils->pci_gw;
231
233 MLX_CHECK_STATUS(utils, status, cap_err,
234 "mlx_pci_gw_search_capability failed");
235
236#if ! defined ( VSEC_DEBUG )
238 MLX_CHECK_STATUS(utils, status, ownership_err,"failed to get ownership");
239ownership_err:
240#endif
241cap_err:
242bad_param:
243 return status;
244}
static mlx_status mlx_pci_gw_search_capability(IN mlx_utils *utils, OUT mlx_uint32 *cap_offset)
Definition mlx_pci_gw.c:171
static mlx_status mlx_pci_gw_get_ownership(IN mlx_utils *utils)
Definition mlx_pci_gw.c:51
mlx_uint32 pci_cmd_offset
Definition mlx_utils.h:34

References IN, MLX_CHECK_STATUS, MLX_INVALID_PARAMETER, mlx_pci_gw_get_ownership(), mlx_pci_gw_search_capability(), MLX_SUCCESS, NULL, mlx_pci_gw::pci_cmd_offset, and status.

Referenced by flexboot_nodnic_is_supported(), and init_mlx_utils().

◆ mlx_pci_gw_teardown()

mlx_status mlx_pci_gw_teardown ( IN mlx_utils * utils)

Definition at line 247 of file mlx_pci_gw.c.

250{
251#if ! defined ( VSEC_DEBUG )
253#endif
254 return MLX_SUCCESS;
255}
static mlx_status mlx_pci_gw_free_ownership(IN mlx_utils *utils)
Definition mlx_pci_gw.c:103

References __attribute__, IN, mlx_pci_gw_free_ownership(), MLX_SUCCESS, and unused.

Referenced by flexboot_nodnic_is_supported(), free_mlx_utils(), and init_mlx_utils().

◆ mlx_pci_gw_read()

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 at line 258 of file mlx_pci_gw.c.

264{
266 mlx_pci_gw *pci_gw = NULL;
267 mlx_uint32 cap_offset = 0;
268
269 if (utils == NULL || buffer == NULL || utils->pci_gw.pci_cmd_offset == 0) {
271 goto bad_param;
272 }
273
275
276 pci_gw = &utils->pci_gw;
277 cap_offset = pci_gw->pci_cmd_offset;
278
279#if ! defined ( VSEC_DEBUG )
280 if (pci_gw->space != space) {
281 status = mlx_pci_gw_set_space(utils, space);
282 MLX_CHECK_STATUS(utils, status, space_error,"failed to set space");
283 pci_gw->space = space;
284 }
285#else
287 MLX_CHECK_STATUS(utils, status, ownership_err,"failed to get ownership");
288
289 status = mlx_pci_gw_set_space(utils, space);
290 MLX_CHECK_STATUS(utils, status, space_error,"failed to set space");
291 pci_gw->space = space;
292#endif
293
295 MLX_CHECK_STATUS(utils, status, read_error,"failed to write capability address");
296
297#if defined ( DEVICE_CX3 )
298 /* WA for PCI issue (race) */
300#endif
301
303 MLX_CHECK_STATUS(utils, status, read_error, "flag failed to change");
304
306 MLX_CHECK_STATUS(utils, status, read_error,"failed to read capability data");
307
308#if defined ( VSEC_DEBUG )
310 MLX_CHECK_STATUS(utils, status, free_err,
311 "mlx_pci_gw_free_ownership failed");
312free_err:
314 return status;
315#endif
316read_error:
317space_error:
318#if defined ( VSEC_DEBUG )
320ownership_err:
321#endif
323bad_param:
324 return status;
325}
uint64_t address
Base address.
Definition ena.h:13
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
static mlx_status mlx_pci_gw_wait_for_flag_value(IN mlx_utils *utils, IN mlx_boolean value)
Definition mlx_pci_gw.c:146
static mlx_status mlx_pci_gw_set_space(IN mlx_utils *utils, IN mlx_pci_gw_space space)
Definition mlx_pci_gw.c:120
#define PCI_GW_CAPABILITY_ADDRESS_OFFSET
Definition mlx_pci_gw.h:37
#define PCI_GW_CAPABILITY_DATA_OFFSET
Definition mlx_pci_gw.h:39
mlx_status mlx_utils_release_lock(IN OUT mlx_utils *utils)
Definition mlx_utils.c:108
mlx_status mlx_utils_acquire_lock(IN OUT mlx_utils *utils)
Definition mlx_utils.c:100
mlx_pci_gw_space space
Definition mlx_utils.h:35

References address, buffer, IN, MLX_CHECK_STATUS, MLX_INVALID_PARAMETER, mlx_pci_gw_free_ownership(), mlx_pci_gw_get_ownership(), mlx_pci_gw_set_space(), mlx_pci_gw_wait_for_flag_value(), mlx_pci_read(), mlx_pci_write(), MLX_SUCCESS, mlx_utils_acquire_lock(), mlx_utils_delay_in_us(), mlx_utils_release_lock(), MlxPciWidthUint32, NULL, OUT, mlx_pci_gw::pci_cmd_offset, PCI_GW_CAPABILITY_ADDRESS_OFFSET, PCI_GW_CAPABILITY_DATA_OFFSET, mlx_pci_gw::space, status, and TRUE.

Referenced by flexboot_nodnic_is_supported(), mlx_icmd_get_semaphore(), mlx_icmd_get_status(), mlx_icmd_go(), mlx_icmd_init(), mlx_icmd_read_buffer(), mlx_icmd_set_opcode(), and nodnic_cmd_read().

◆ mlx_pci_gw_write()

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 at line 328 of file mlx_pci_gw.c.

334{
336 mlx_pci_gw *pci_gw = NULL;
337 mlx_uint32 cap_offset = 0;
338 mlx_uint32 fixed_address = address | PCI_GW_WRITE_FLAG;
339
340 if (utils == NULL || utils->pci_gw.pci_cmd_offset == 0) {
342 goto bad_param;
343 }
344
346
347 pci_gw = &utils->pci_gw;
348 cap_offset = pci_gw->pci_cmd_offset;
349
350#if ! defined ( VSEC_DEBUG )
351 if (pci_gw->space != space) {
352 status = mlx_pci_gw_set_space(utils, space);
353 MLX_CHECK_STATUS(utils, status, space_error,"failed to set space");
354 pci_gw->space = space;
355 }
356#else
358 MLX_CHECK_STATUS(utils, status, ownership_err,"failed to get ownership");
359
360 status = mlx_pci_gw_set_space(utils, space);
361 MLX_CHECK_STATUS(utils, status, space_error,"failed to set space");
362 pci_gw->space = space;
363#endif
365 MLX_CHECK_STATUS(utils, status, read_error,"failed to write capability data");
366
367 status = mlx_pci_write(utils, MlxPciWidthUint32, cap_offset + PCI_GW_CAPABILITY_ADDRESS_OFFSET, 1, &fixed_address);
368 MLX_CHECK_STATUS(utils, status, read_error,"failed to write capability address");
369
371 MLX_CHECK_STATUS(utils, status, read_error, "flag failed to change");
372#if defined ( VSEC_DEBUG )
374 MLX_CHECK_STATUS(utils, status, free_err,
375 "mlx_pci_gw_free_ownership failed");
376free_err:
378 return status;
379#endif
380read_error:
381space_error:
382#if defined ( VSEC_DEBUG )
384ownership_err:
385#endif
387bad_param:
388 return status;
389}
#define PCI_GW_WRITE_FLAG
Definition mlx_pci_gw.h:45

References address, buffer, FALSE, IN, MLX_CHECK_STATUS, MLX_INVALID_PARAMETER, mlx_pci_gw_free_ownership(), mlx_pci_gw_get_ownership(), mlx_pci_gw_set_space(), mlx_pci_gw_wait_for_flag_value(), mlx_pci_write(), MLX_SUCCESS, mlx_utils_acquire_lock(), mlx_utils_release_lock(), MlxPciWidthUint32, NULL, mlx_pci_gw::pci_cmd_offset, PCI_GW_CAPABILITY_ADDRESS_OFFSET, PCI_GW_CAPABILITY_DATA_OFFSET, PCI_GW_WRITE_FLAG, mlx_pci_gw::space, and status.

Referenced by mlx_icmd_clear_semaphore(), mlx_icmd_get_semaphore(), mlx_icmd_go(), mlx_icmd_set_opcode(), mlx_icmd_write_buffer(), and nodnic_cmd_write().