@@ -107,6 +107,33 @@ Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
107107 LINUX_VERSION_CODE >= KERNEL_VERSION (3 ,10 ,0 )
108108#define ENA_BUSY_POLL_SUPPORT
109109#endif
110+
111+ /* Distribution kernel version comparison macros.
112+ * Distribution kernel versioning format may be A.B.C-D.E.F and standard
113+ * KERNEL_VERSION macro covers only the first 3 subversions.
114+ * Using 20bit per subversion, as in some cases, subversion D may be a large
115+ * number (6 digits).
116+ */
117+ #define ENA_KERNEL_VERSION_16BIT (SV1 , SV2 , SV3 ) ((SV1 << 40) | (SV2 << 20) | (SV3))
118+ #define ENA_KERNEL_VERSION_MAJOR (SV1 , SV2 , SV3 ) ENA_KERNEL_VERSION_16BIT(SV1, SV2, SV3)
119+ #define ENA_KERNEL_VERSION_MINOR (SV1 , SV2 , SV3 ) ENA_KERNEL_VERSION_16BIT(SV1, SV2, SV3)
120+
121+ #define ENA_KERNEL_VERSION_GTE (SV1 , SV2 , SV3 , SV4 , SV5 , SV6 ) \
122+ ((ENA_KERNEL_VERSION_MAJOR(ENA_KERNEL_SUBVERSION_1, ENA_KERNEL_SUBVERSION_2, ENA_KERNEL_SUBVERSION_3) > \
123+ ENA_KERNEL_VERSION_MAJOR((SV1), (SV2), (SV3))) || \
124+ (ENA_KERNEL_VERSION_MAJOR(ENA_KERNEL_SUBVERSION_1, ENA_KERNEL_SUBVERSION_2, ENA_KERNEL_SUBVERSION_3) == \
125+ ENA_KERNEL_VERSION_MAJOR((SV1), (SV2), (SV3)) && \
126+ ENA_KERNEL_VERSION_MINOR(ENA_KERNEL_SUBVERSION_4, ENA_KERNEL_SUBVERSION_5, ENA_KERNEL_SUBVERSION_6) >= \
127+ ENA_KERNEL_VERSION_MINOR((SV4), (SV5), (SV6))))
128+
129+ #define ENA_KERNEL_VERSION_LTE (SV1 , SV2 , SV3 , SV4 , SV5 , SV6 ) \
130+ ((ENA_KERNEL_VERSION_MAJOR(ENA_KERNEL_SUBVERSION_1, ENA_KERNEL_SUBVERSION_2, ENA_KERNEL_SUBVERSION_3) < \
131+ ENA_KERNEL_VERSION_MAJOR((SV1), (SV2), (SV3))) || \
132+ (ENA_KERNEL_VERSION_MAJOR(ENA_KERNEL_SUBVERSION_1, ENA_KERNEL_SUBVERSION_2, ENA_KERNEL_SUBVERSION_3) == \
133+ ENA_KERNEL_VERSION_MAJOR((SV1), (SV2), (SV3)) && \
134+ ENA_KERNEL_VERSION_MINOR(ENA_KERNEL_SUBVERSION_4, ENA_KERNEL_SUBVERSION_5, ENA_KERNEL_SUBVERSION_6) <= \
135+ ENA_KERNEL_VERSION_MINOR((SV4), (SV5), (SV6))))
136+
110137/******************************************************************************/
111138/************************** Ubuntu macros *************************************/
112139/******************************************************************************/
@@ -177,7 +204,6 @@ Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
177204#define SUSE_VERSION 0
178205#endif /* SUSE_VERSION */
179206
180-
181207/******************************************************************************/
182208/**************************** RHEL macros *************************************/
183209/******************************************************************************/
@@ -822,17 +848,32 @@ static inline void netdev_rss_key_fill(void *buffer, size_t len)
822848
823849#if ((LINUX_VERSION_CODE < KERNEL_VERSION (4 , 6 ,0 )) && \
824850 !(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION (7 ,3 )))
825- /* Linux versions 4.4.216 - 4.5 (non inclusive) back propagated page_ref_count
826- * function from kernel 4.6. To make things more difficult, Ubuntu didn't add
827- * these changes to its 4.4.* kernels
851+ /* Linux versions 4.4.216 - 4.5 (non inclusive) back propagated
852+ * page_ref_count() from kernel 4.6.
853+ * Ubuntu didn't add these changes to its 4.4.* kernels.
854+ * UEK added this function in kernel 4.1.12-124.43.1
855+ * Here is a figure that shows all of the cases:
856+ * Legend:
857+ * -------- page_ref_count() is present in the kernel
858+ * ******** page_ref_count() is missing in the kernel
859+ *
860+ * Distro\Kernel 4.1.12-124.43.1 4.4.216 4.5 4.6
861+ * | | | |
862+ * Upstrem kernel ***********|**************|--------|******|
863+ * | | | |
864+ * Ubuntu ***********|**************|********|******|
865+ * | | | |
866+ * UEK ***********|--------------|--------|------|
828867 */
829- #if !(KERNEL_VERSION (4 , 4 ,216 ) <= LINUX_VERSION_CODE && LINUX_VERSION_CODE < KERNEL_VERSION (4 , 5 ,0 )) || \
830- defined(UBUNTU_VERSION_CODE )
868+ #if (defined(IS_UEK ) && !ENA_KERNEL_VERSION_GTE (4 , 1 , 12 , 124 , 43 , 1 )) || \
869+ (defined(ubuntu )) || \
870+ (!defined(IS_UEK ) && !defined(ubuntu ) && \
871+ !(KERNEL_VERSION (4 , 4 , 216 ) <= LINUX_VERSION_CODE && LINUX_VERSION_CODE < KERNEL_VERSION (4 , 5 , 0 )))
831872static inline int page_ref_count (struct page * page )
832873{
833874 return atomic_read (& page -> _count );
834875}
835- #endif /* !(KERNEL_VERSION(4, 4 ,216) <= LINUX_VERSION_CODE && LINUX_VERSION_CODE < KERNEL_VERSION (4, 5 ,0)) */
876+ #endif /* (defined(IS_UEK) && !ENA_KERNEL_VERSION_GTE (4, 1, 12, 124, 43, 1)) ... */
836877
837878static inline void page_ref_inc (struct page * page )
838879{
@@ -881,32 +922,16 @@ static inline int numa_mem_id(void)
881922
882923#if LINUX_VERSION_CODE >= KERNEL_VERSION (3 , 5 , 0 )
883924#define ENA_LINEAR_FRAG_SUPPORTED
884- static __always_inline struct sk_buff *
885- ena_build_skb (void * data , unsigned int frag_size )
886- {
887- #if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 12 , 0 )
888- return napi_build_skb (data , frag_size );
889- #else
890- return build_skb (data , frag_size );
891- #endif
892- }
893- #endif
894-
895- #if LINUX_VERSION_CODE < KERNEL_VERSION (4 , 6 , 0 ) && \
896- !(defined(RHEL_RELEASE_CODE ) && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION (7 , 3 )) && \
897- !(defined(UBUNTU_VERSION_CODE ) && UBUNTU_VERSION_CODE >= UBUNTU_VERSION (4 , 2 , 0 , 42 ))
898- static __always_inline
899- void napi_consume_skb (struct sk_buff * skb , int budget )
900- {
901- dev_kfree_skb_any (skb );
902- }
903925#endif
904926
905927#if LINUX_VERSION_CODE >= KERNEL_VERSION (3 , 17 , 0 )
906928#define ENA_NETDEV_LOGS_WITHOUT_RV
907929#endif
908930
909- #if defined(ENA_XDP_SUPPORT ) && LINUX_VERSION_CODE < KERNEL_VERSION (5 , 12 , 0 )
931+ #if defined(ENA_XDP_SUPPORT ) && \
932+ (LINUX_VERSION_CODE < KERNEL_VERSION (5 , 12 , 0 ) && \
933+ !(defined(SUSE_VERSION ) && (SUSE_VERSION == 15 && SUSE_PATCHLEVEL == 3 ) && \
934+ ENA_KERNEL_VERSION_GTE (5 , 3 , 18 , 150300 , 59 , 49 )))
910935static __always_inline void
911936xdp_init_buff (struct xdp_buff * xdp , u32 frame_sz , struct xdp_rxq_info * rxq )
912937{
@@ -928,7 +953,7 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
928953 xdp -> data_meta = meta_valid ? data : data + 1 ;
929954}
930955
931- #endif /* defined(ENA_XDP_SUPPORT) && LINUX_VERSION_CODE <= KERNEL_VERSION(5, 12, 0) */
956+ #endif /* defined(ENA_XDP_SUPPORT) && ( LINUX_VERSION_CODE <= KERNEL_VERSION(5, 12, 0) && !SUSE_VERSION(...) ) */
932957
933958#if LINUX_VERSION_CODE < KERNEL_VERSION (5 , 13 , 0 )
934959#define ethtool_sprintf (data , fmt , args ...) \
@@ -944,7 +969,9 @@ xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
944969
945970#if LINUX_VERSION_CODE < KERNEL_VERSION (5 , 15 , 0 ) && \
946971 !(defined(RHEL_RELEASE_CODE ) && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION (8 , 6 )) && \
947- !(defined(SUSE_VERSION ) && (SUSE_VERSION == 15 && SUSE_PATCHLEVEL >= 4 ))
972+ !(defined(SUSE_VERSION ) && (SUSE_VERSION == 15 && SUSE_PATCHLEVEL >= 4 )) && \
973+ !(defined(SUSE_VERSION ) && (SUSE_VERSION == 15 && SUSE_PATCHLEVEL == 3 ) && \
974+ ENA_KERNEL_VERSION_GTE (5 , 3 , 18 , 150300 , 59 , 43 ))
948975static inline void eth_hw_addr_set (struct net_device * dev , const u8 * addr )
949976{
950977 memcpy (dev -> dev_addr , addr , ETH_ALEN );
@@ -1065,7 +1092,8 @@ static inline void ena_netif_napi_add(struct net_device *dev,
10651092 struct napi_struct * napi ,
10661093 int (* poll )(struct napi_struct * , int ))
10671094{
1068- #if LINUX_VERSION_CODE < KERNEL_VERSION (6 , 1 , 0 )
1095+ #if (LINUX_VERSION_CODE < KERNEL_VERSION (6 , 1 , 0 )) && \
1096+ !(RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION (9 , 2 )))
10691097#ifndef NAPI_POLL_WEIGHT
10701098#define NAPI_POLL_WEIGHT 64
10711099#endif
@@ -1075,4 +1103,52 @@ static inline void ena_netif_napi_add(struct net_device *dev,
10751103#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0) */
10761104}
10771105
1106+ #if (RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION (7 , 4 ))) || \
1107+ (defined(UBUNTU_VERSION_CODE ) && UBUNTU_VERSION_CODE < UBUNTU_VERSION (4 , 5 , 0 , 0 )) || \
1108+ (defined(IS_UEK ) && !ENA_KERNEL_VERSION_GTE (4 , 1 , 12 , 105 , 0 , 0 ))
1109+ static inline void dma_unmap_page_attrs (struct device * dev ,
1110+ dma_addr_t addr , size_t size ,
1111+ enum dma_data_direction dir ,
1112+ struct dma_attrs * attrs )
1113+ {
1114+ struct dma_map_ops * ops = get_dma_ops (dev );
1115+
1116+ BUG_ON (!valid_dma_direction (dir ));
1117+ if (ops -> unmap_page )
1118+ ops -> unmap_page (dev , addr , size , dir , attrs );
1119+ debug_dma_unmap_page (dev , addr , size , dir , false);
1120+ }
1121+ #endif /* RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION(7, 4)) */
1122+
1123+ #if (RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION (7 , 9 )) && \
1124+ (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION (7 , 0 )) && \
1125+ (LINUX_VERSION_CODE != KERNEL_VERSION (4 , 14 , 0 ))) || \
1126+ (defined(UBUNTU_VERSION_CODE ) && UBUNTU_VERSION_CODE < UBUNTU_VERSION (4 , 5 , 0 , 0 )) || \
1127+ (defined(IS_UEK ) && LINUX_VERSION_CODE < KERNEL_VERSION (4 , 1 , 13 ))
1128+ #define ENA_DMA_ATTR_SKIP_CPU_SYNC (1 << DMA_ATTR_SKIP_CPU_SYNC)
1129+ #elif (RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION (6 , 10 )))
1130+ #define ENA_DMA_ATTR_SKIP_CPU_SYNC 0
1131+ #else
1132+ #define ENA_DMA_ATTR_SKIP_CPU_SYNC DMA_ATTR_SKIP_CPU_SYNC
1133+ #endif
1134+
1135+ static inline void ena_dma_unmap_page_attrs (struct device * dev ,
1136+ dma_addr_t addr , size_t size ,
1137+ enum dma_data_direction dir ,
1138+ unsigned long attrs )
1139+ {
1140+ #if (RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION (7 , 9 )) && \
1141+ (LINUX_VERSION_CODE != KERNEL_VERSION (4 , 14 , 0 ))) || \
1142+ (defined(UBUNTU_VERSION_CODE ) && UBUNTU_VERSION_CODE < UBUNTU_VERSION (4 , 5 , 0 , 0 )) || \
1143+ (defined(IS_UEK ) && LINUX_VERSION_CODE < KERNEL_VERSION (4 , 1 , 13 ))
1144+ struct dma_attrs dma_attrs ;
1145+
1146+ init_dma_attrs (& dma_attrs );
1147+ dma_attrs .flags [0 ] = attrs ;
1148+ dma_unmap_page_attrs (dev , addr , size , dir , & dma_attrs );
1149+ #else
1150+ dma_unmap_page_attrs (dev , addr , size , dir , attrs );
1151+ #endif
1152+ }
1153+
10781154#endif /* _KCOMPAT_H_ */
0 commit comments