8686
8787#include <endian.h>
8888#include <stdint.h>
89+ #include <ccan/endian/endian.h>
8990
9091#include "types.h"
9192#include "tree.h"
@@ -327,9 +328,6 @@ struct nvme_mi_aem_supported_list_header {
327328 __le16 aest ;
328329 __u8 aeslhl ; //Should be 5
329330} __attribute__((packed ));
330- _Static_assert (sizeof (struct nvme_mi_aem_supported_list_header ) == 5 ,
331- "size_of_nvme_mi_aem_supported_list_header_is_not_5_bytes" );
332-
333331
334332/**
335333 * struct nvme_mi_aem_supported_item - AE Supported List Item
@@ -341,14 +339,33 @@ _Static_assert(sizeof(struct nvme_mi_aem_supported_list_header) == 5,
341339 */
342340struct nvme_mi_aem_supported_item {
343341 __u8 aesl ;//Length of this item. Set to 3
344- struct {
345- __le16 aeis : 8 ; //Identifier of supported ae
346- __le16 reserved : 7 ;
347- __le16 aese : 1 ; //AE Support Enabled
348- } __attribute__((packed )) aesi ;
342+ __le16 aesi ;
349343} __attribute__((packed ));
350- _Static_assert (sizeof (struct nvme_mi_aem_supported_item ) == 3 ,
351- "sizeof_nvme_mi_aem_supported_item_is_not_3_bytes" );
344+
345+ static inline bool nvme_mi_aem_aesi_get_aese (__le16 aesi )
346+ {
347+ return !!(le16_to_cpu (aesi ) & 0x8000 );
348+ }
349+
350+ static inline __u8 nvme_mi_aem_aesi_get_aesid (__le16 aesi )
351+ {
352+ return le16_to_cpu (aesi ) & 0xff ;
353+ }
354+
355+ static inline void nvme_mi_aem_aesi_set_aesid (__u8 aesid , struct nvme_mi_aem_supported_item * item )
356+ {
357+ __u16 temp = le16_to_cpu (item -> aesi );
358+
359+ item -> aesi = cpu_to_le16 ((temp & 0xFF00 ) | aesid );
360+ }
361+
362+ static inline void nvme_mi_aem_aesi_set_aee (bool enabled , struct nvme_mi_aem_supported_item * item )
363+ {
364+ __u16 temp = le16_to_cpu (item -> aesi );
365+ __u8 bit = (enabled ) ? 1 : 0 ;
366+
367+ item -> aesi = cpu_to_le16 ((temp & 0xFF ) | (bit << 15 ));
368+ }
352369
353370/**
354371 * struct nvme_mi_aem_supported_list - AE Supported List received with GET CONFIG Asynchronous Event
@@ -369,14 +386,33 @@ struct nvme_mi_aem_supported_list {
369386 */
370387struct nvme_mi_aem_enable_item {
371388 __u8 aeel ;
372- struct {
373- __le16 aeeid : 8 ; //AE identifier
374- __le16 reserved : 7 ;
375- __le16 aee : 1 ; //AE enabled bit
376- } __attribute__((packed )) aeei ;
377- };
378- _Static_assert (sizeof (struct nvme_mi_aem_enable_item ) == 3 ,
379- "size_of_ae_enable_item_t_is_not_3_bytes" );
389+ __le16 aeei ;
390+ }__attribute__((packed )) ;
391+
392+ static inline bool nvme_mi_aem_aeei_get_aee (__le16 aeei )
393+ {
394+ return !!(le16_to_cpu (aeei ) & 0x8000 );
395+ }
396+
397+ static inline __u8 nvme_mi_aem_aeei_get_aeeid (__le16 aeei )
398+ {
399+ return (le16_to_cpu (aeei ) & 0xFF );
400+ }
401+
402+ static inline void nvme_mi_aem_aeei_set_aeeid (__u8 aeeid , struct nvme_mi_aem_enable_item * item )
403+ {
404+ __u16 temp = le16_to_cpu (item -> aeei );
405+
406+ item -> aeei = cpu_to_le16 ((temp & 0xFF00 ) | aeeid );
407+ }
408+
409+ static inline void nvme_mi_aem_aeei_set_aee (bool enabled , struct nvme_mi_aem_enable_item * item )
410+ {
411+ __u16 temp = le16_to_cpu (item -> aeei );
412+ __u8 bit = (enabled ) ? 1 : 0 ;
413+
414+ item -> aeei = cpu_to_le16 ((temp & 0xFF ) | (bit << 15 ));
415+ }
380416
381417/**
382418 * struct nvme_mi_aem_enable_list_header - AE Enable list header
@@ -391,8 +427,6 @@ struct nvme_mi_aem_enable_list_header {
391427 __le16 aeetl ;
392428 __u8 aeelhl ;
393429} __attribute__((packed ));
394- _Static_assert (sizeof (struct nvme_mi_aem_enable_list_header ) == 5 ,
395- "size_of_nvme_mi_aem_enable_list_header_is_not_5_bytes" );
396430
397431/**
398432 * struct nvme_mi_aem_enable_list - AE enable list sent with SET CONFIG Asyncronous Event
@@ -428,8 +462,6 @@ struct nvme_mi_aem_occ_data {
428462 __u8 aessi ;
429463 } __attribute__((packed )) aeoui ;
430464} __attribute__((packed ));
431- _Static_assert (sizeof (struct nvme_mi_aem_occ_data ) == 9 ,
432- "size_of_nvme_mi_aem_occ_data_is_not_9_bytes" );
433465
434466/**
435467 * struct nvme_mi_aem_occ_list_hdr - AE occurrence list header
@@ -446,18 +478,33 @@ _Static_assert(sizeof(struct nvme_mi_aem_occ_data) == 9,
446478struct nvme_mi_aem_occ_list_hdr {
447479 __u8 numaeo ;
448480 __u8 aelver ;
449- struct {
450- unsigned int aeoltl : 23 ;
451- unsigned int overflow : 1 ;
452- } __attribute__((packed )) aeolli ;
481+ __u8 aeolli [3 ];//24-bits
453482 __u8 aeolhl ;
454- struct {
455- unsigned int aemrc : 3 ;
456- unsigned int aemgn : 5 ;
457- } __attribute__((packed )) aemti ;
483+ __u8 aemti ;
458484} __attribute__((packed ));
459- _Static_assert (sizeof (struct nvme_mi_aem_occ_list_hdr ) == 7 ,
460- "size_of_nvme_mi_aem_occ_list_hdr_is_not_7_bytes" );
485+
486+ static inline __u8 nvme_mi_aem_aemti_get_aemgn (__u8 aemti )
487+ {
488+ return aemti >> 3 & 0x1f ;
489+ }
490+
491+ static inline __u32 nvme_mi_aem_aeolli_get_aeoltl (__u8 * aeolli )
492+ {
493+ //First 23-bits contain the aeoltl
494+ __u32 aeoltl = le32_to_cpu (aeolli [0 ] | (aeolli [1 ] << 8 ) | (aeolli [2 ] << 16 ));
495+
496+ return aeoltl & 0x7FFFFF ;
497+ }
498+
499+ static inline void nvme_mi_aem_aeolli_set_aeoltl (__u32 aeoltl , struct nvme_mi_aem_occ_list_hdr * hdr )
500+ {
501+ //First 23-bits contain the aeoltl
502+ __u32 le_bytes = cpu_to_le32 (aeoltl );
503+
504+ hdr -> aeolli [0 ] = le_bytes & 0xFF ;
505+ hdr -> aeolli [1 ] = (le_bytes >> 8 ) & 0xFF ;
506+ hdr -> aeolli [2 ] = (hdr -> aeolli [2 ] & 0b10000000 ) | ((le_bytes >> 16 ) & 0x7F );
507+ }
461508
462509
463510/**
@@ -1013,7 +1060,7 @@ int nvme_mi_mi_read_mi_data_ctrl(nvme_mi_ep_t ep, __u16 ctrl_id,
10131060 *
10141061 * See &struct nvme_mi_nvm_ss_health_status.
10151062 *
1016- * Return: The nvme command status if a response was received (see
1063+ * Return` The nvme command status if a response was received (see
10171064 * &enum nvme_status_field) or -1 with errno set otherwise..
10181065 */
10191066int nvme_mi_mi_subsystem_health_status_poll (nvme_mi_ep_t ep , bool clear ,
@@ -1249,9 +1296,9 @@ int nvme_mi_mi_config_set_async_event(nvme_mi_ep_t ep,
12491296 struct nvme_mi_aem_occ_list_hdr * occ_list ,
12501297 size_t * occ_list_num_bytes );
12511298
1252- static inline int aem_ack (nvme_mi_ep_t ep ,
1253- struct nvme_mi_aem_occ_list_hdr * occ_list ,
1254- size_t * occ_list_num_bytes )
1299+ static inline int nvme_mi_aem_ack (nvme_mi_ep_t ep ,
1300+ struct nvme_mi_aem_occ_list_hdr * occ_list ,
1301+ size_t * occ_list_num_bytes )
12551302{
12561303 //An AEM Ack is defined as a SET CONFIG AE with no AE enable items
12571304 struct nvme_mi_aem_enable_list list = {0 };
0 commit comments