X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fcxgbe%2Fcxgbe_compat.h;h=cce51c2f975b7c9afb5e91a656e81a46ec782d76;hb=b26d65bee9961dae25f8ba050130a4aa4adf5054;hp=3b871eeca9db51e41bc00e9a24b533ecfa7ea4ab;hpb=8318984927ff621c687be9299c52ddde3357734e;p=dpdk.git diff --git a/drivers/net/cxgbe/cxgbe_compat.h b/drivers/net/cxgbe/cxgbe_compat.h index 3b871eeca9..cce51c2f97 100644 --- a/drivers/net/cxgbe/cxgbe_compat.h +++ b/drivers/net/cxgbe/cxgbe_compat.h @@ -1,34 +1,6 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2014-2015 Chelsio Communications. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Chelsio Communications nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2014-2018 Chelsio Communications. + * All rights reserved. */ #ifndef _CXGBE_COMPAT_H_ @@ -45,42 +17,48 @@ #include #include #include +#include +#include -#define dev_printf(level, fmt, args...) \ - RTE_LOG(level, PMD, "rte_cxgbe_pmd: " fmt, ## args) +#define dev_printf(level, fmt, ...) \ + RTE_LOG(level, PMD, "rte_cxgbe_pmd: " fmt, ##__VA_ARGS__) -#define dev_err(x, args...) dev_printf(ERR, args) -#define dev_info(x, args...) dev_printf(INFO, args) -#define dev_warn(x, args...) dev_printf(WARNING, args) +#define dev_err(x, fmt, ...) dev_printf(ERR, fmt, ##__VA_ARGS__) +#define dev_info(x, fmt, ...) dev_printf(INFO, fmt, ##__VA_ARGS__) +#define dev_warn(x, fmt, ...) dev_printf(WARNING, fmt, ##__VA_ARGS__) #ifdef RTE_LIBRTE_CXGBE_DEBUG -#define dev_debug(x, args...) dev_printf(DEBUG, args) +#define dev_debug(x, fmt, ...) dev_printf(INFO, fmt, ##__VA_ARGS__) #else -#define dev_debug(x, args...) do { } while (0) +#define dev_debug(x, fmt, ...) do { } while (0) #endif #ifdef RTE_LIBRTE_CXGBE_DEBUG_REG -#define CXGBE_DEBUG_REG(x, args...) dev_printf(DEBUG, "REG:" args) +#define CXGBE_DEBUG_REG(x, fmt, ...) \ + dev_printf(INFO, "REG:" fmt, ##__VA_ARGS__) #else -#define CXGBE_DEBUG_REG(x, args...) do { } while (0) +#define CXGBE_DEBUG_REG(x, fmt, ...) do { } while (0) #endif #ifdef RTE_LIBRTE_CXGBE_DEBUG_MBOX -#define CXGBE_DEBUG_MBOX(x, args...) dev_printf(DEBUG, "MBOX:" args) +#define CXGBE_DEBUG_MBOX(x, fmt, ...) \ + dev_printf(INFO, "MBOX:" fmt, ##__VA_ARGS__) #else -#define CXGBE_DEBUG_MBOX(x, args...) do { } while (0) +#define CXGBE_DEBUG_MBOX(x, fmt, ...) do { } while (0) #endif #ifdef RTE_LIBRTE_CXGBE_DEBUG_TX -#define CXGBE_DEBUG_TX(x, args...) dev_printf(DEBUG, "TX:" args) +#define CXGBE_DEBUG_TX(x, fmt, ...) \ + dev_printf(INFO, "TX:" fmt, ##__VA_ARGS__) #else -#define CXGBE_DEBUG_TX(x, args...) do { } while (0) +#define CXGBE_DEBUG_TX(x, fmt, ...) do { } while (0) #endif #ifdef RTE_LIBRTE_CXGBE_DEBUG_RX -#define CXGBE_DEBUG_RX(x, args...) dev_printf(DEBUG, "RX:" args) +#define CXGBE_DEBUG_RX(x, fmt, ...) \ + dev_printf(INFO, "RX:" fmt, ##__VA_ARGS__) #else -#define CXGBE_DEBUG_RX(x, args...) do { } while (0) +#define CXGBE_DEBUG_RX(x, fmt, ...) do { } while (0) #endif #ifdef RTE_LIBRTE_CXGBE_DEBUG @@ -90,9 +68,9 @@ #define CXGBE_FUNC_TRACE() do { } while (0) #endif -#define pr_err(y, args...) dev_err(0, y, ##args) -#define pr_warn(y, args...) dev_warn(0, y, ##args) -#define pr_info(y, args...) dev_info(0, y, ##args) +#define pr_err(fmt, ...) dev_err(0, fmt, ##__VA_ARGS__) +#define pr_warn(fmt, ...) dev_warn(0, fmt, ##__VA_ARGS__) +#define pr_info(fmt, ...) dev_info(0, fmt, ##__VA_ARGS__) #define BUG() pr_err("BUG at %s:%d", __func__, __LINE__) #define ASSERT(x) do {\ @@ -119,10 +97,11 @@ #define L1_CACHE_BYTES BIT(L1_CACHE_SHIFT) #define PAGE_SHIFT 12 -#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) -#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) +#define CXGBE_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define PTR_ALIGN(p, a) ((typeof(p))CXGBE_ALIGN((unsigned long)(p), (a))) #define VLAN_HLEN 4 +#define ETHER_ADDR_LEN 6 #define rmb() rte_rmb() /* dpdk rte provided rmb */ #define wmb() rte_wmb() /* dpdk rte provided wmb */ @@ -172,18 +151,24 @@ typedef uint64_t dma_addr_t; #define false 0 #define true 1 +#ifndef min #define min(a, b) RTE_MIN(a, b) +#endif + +#ifndef max #define max(a, b) RTE_MAX(a, b) +#endif /* * round up val _p to a power of 2 size _s */ -#define roundup(_p, _s) (((unsigned long)(_p) + (_s - 1)) & ~(_s - 1)) +#define cxgbe_roundup(_p, _s) (((unsigned long)(_p) + (_s - 1)) & ~(_s - 1)) -#undef container_of +#ifndef container_of #define container_of(ptr, type, member) ({ \ typeof(((type *)0)->member)(*__mptr) = (ptr); \ (type *)((char *)__mptr - offsetof(type, member)); }) +#endif #define ARRAY_SIZE(arr) RTE_DIM(arr) @@ -196,6 +181,26 @@ typedef uint64_t dma_addr_t; #define be64_to_cpu(o) rte_be_to_cpu_64(o) #define le32_to_cpu(o) rte_le_to_cpu_32(o) +#ifndef ntohs +#define ntohs(o) be16_to_cpu(o) +#endif + +#ifndef ntohl +#define ntohl(o) be32_to_cpu(o) +#endif + +#ifndef htons +#define htons(o) cpu_to_be16(o) +#endif + +#ifndef htonl +#define htonl(o) cpu_to_be32(o) +#endif + +#ifndef caddr_t +typedef char *caddr_t; +#endif + #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) #define DELAY(x) rte_delay_us(x) #define udelay(x) DELAY(x) @@ -214,13 +219,13 @@ static inline uint8_t hweight32(uint32_t word32) } /* weight32 */ /** - * fls - find last (most-significant) bit set + * cxgbe_fls - find last (most-significant) bit set * @x: the word to search * * This is defined the same way as ffs. - * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. + * Note cxgbe_fls(0) = 0, cxgbe_fls(1) = 1, cxgbe_fls(0x80000000) = 32. */ -static inline int fls(int x) +static inline int cxgbe_fls(int x) { return x ? sizeof(x) * 8 - __builtin_clz(x) : 0; } @@ -254,7 +259,7 @@ static inline unsigned long ilog2(unsigned long n) static inline void writel(unsigned int val, volatile void __iomem *addr) { - *(volatile unsigned int *)addr = val; + rte_write32(val, addr); } static inline void writeq(u64 val, volatile void __iomem *addr) @@ -263,4 +268,21 @@ static inline void writeq(u64 val, volatile void __iomem *addr) writel(val >> 32, (void *)((uintptr_t)addr + 4)); } +static inline void writel_relaxed(unsigned int val, volatile void __iomem *addr) +{ + rte_write32_relaxed(val, addr); +} + +/* + * Multiplies an integer by a fraction, while avoiding unnecessary + * overflow or loss of precision. + */ +static inline unsigned int mult_frac(unsigned int x, unsigned int numer, + unsigned int denom) +{ + unsigned int quot = x / denom; + unsigned int rem = x % denom; + + return (quot * numer) + ((rem * numer) / denom); +} #endif /* _CXGBE_COMPAT_H_ */