net/ice/base: fix adding PPPoE switch rule
[dpdk.git] / drivers / net / ice / base / ice_osdep.h
index 252c8f4..27c1830 100644 (file)
@@ -126,11 +126,19 @@ do {                                                                      \
 #define ICE_PCI_REG(reg)     rte_read32(reg)
 #define ICE_PCI_REG_ADDR(a, reg) \
        ((volatile uint32_t *)((char *)(a)->hw_addr + (reg)))
+#define ICE_PCI_REG64(reg)     rte_read64(reg)
+#define ICE_PCI_REG_ADDR64(a, reg) \
+       ((volatile uint64_t *)((char *)(a)->hw_addr + (reg)))
 static inline uint32_t ice_read_addr(volatile void *addr)
 {
        return rte_le_to_cpu_32(ICE_PCI_REG(addr));
 }
 
+static inline uint64_t ice_read_addr64(volatile void *addr)
+{
+       return rte_le_to_cpu_64(ICE_PCI_REG64(addr));
+}
+
 #define ICE_PCI_REG_WRITE(reg, value) \
        rte_write32((rte_cpu_to_le_32(value)), reg)
 
@@ -145,97 +153,9 @@ static inline uint32_t ice_read_addr(volatile void *addr)
        ICE_PCI_REG_WRITE(ICE_PCI_REG_ADDR((a), (reg)), (value))
 #define flush(a) ice_read_addr(ICE_PCI_REG_ADDR((a), (GLGEN_STAT)))
 #define div64_long(n, d) ((n) / (d))
+#define rd64(a, reg) ice_read_addr64(ICE_PCI_REG_ADDR64((a), (reg)))
 
 #define BITS_PER_BYTE       8
-typedef u32 ice_bitmap_t;
-#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
-#define BITS_TO_CHUNKS(nr)   DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(ice_bitmap_t))
-#define ice_declare_bitmap(name, bits) \
-       ice_bitmap_t name[BITS_TO_CHUNKS(bits)]
-
-#define BITS_CHUNK_MASK(nr)    (((ice_bitmap_t)~0) >>                  \
-               ((BITS_PER_BYTE * sizeof(ice_bitmap_t)) -               \
-               (((nr) - 1) % (BITS_PER_BYTE * sizeof(ice_bitmap_t))    \
-                + 1)))
-#define BITS_PER_CHUNK          (BITS_PER_BYTE * sizeof(ice_bitmap_t))
-#define BIT_CHUNK(nr)           ((nr) / BITS_PER_CHUNK)
-#define BIT_IN_CHUNK(nr)        BIT((nr) % BITS_PER_CHUNK)
-
-static inline bool ice_is_bit_set(const ice_bitmap_t *bitmap, u16 nr)
-{
-       return !!(bitmap[BIT_CHUNK(nr)] & BIT_IN_CHUNK(nr));
-}
-
-#define ice_and_bitmap(d, b1, b2, sz) \
-       ice_intersect_bitmaps((u8 *)d, (u8 *)b1, (const u8 *)b2, (u16)sz)
-static inline int
-ice_intersect_bitmaps(u8 *dst, const u8 *bmp1, const u8 *bmp2, u16 sz)
-{
-       u32 res = 0;
-       int cnt;
-       u16 i;
-
-       /* Utilize 32-bit operations */
-       cnt = (sz % BITS_PER_BYTE) ?
-               (sz / BITS_PER_BYTE) + 1 : sz / BITS_PER_BYTE;
-       for (i = 0; i < cnt / 4; i++) {
-               ((u32 *)dst)[i] = ((const u32 *)bmp1)[i] &
-               ((const u32 *)bmp2)[i];
-               res |= ((u32 *)dst)[i];
-       }
-
-       for (i *= 4; i < cnt; i++) {
-               if ((sz % 8 == 0) || (i + 1 < cnt)) {
-                       dst[i] = bmp1[i] & bmp2[i];
-               } else {
-                       /* Remaining bits that do not occupy the whole byte */
-                       u8 mask = ~0u >> (8 - (sz % 8));
-
-                       dst[i] = bmp1[i] & bmp2[i] & mask;
-               }
-
-               res |= dst[i];
-       }
-
-       return res != 0;
-}
-
-static inline int ice_find_first_bit(ice_bitmap_t *name, u16 size)
-{
-       u16 i;
-
-       for (i = 0; i < BITS_PER_BYTE * (size / BITS_PER_BYTE); i++)
-               if (ice_is_bit_set(name, i))
-                       return i;
-       return size;
-}
-
-static inline int ice_find_next_bit(ice_bitmap_t *name, u16 size, u16 bits)
-{
-       u16 i;
-
-       for (i = bits; i < BITS_PER_BYTE * (size / BITS_PER_BYTE); i++)
-               if (ice_is_bit_set(name, i))
-                       return i;
-       return bits;
-}
-
-#define for_each_set_bit(bit, addr, size)                              \
-       for ((bit) = ice_find_first_bit((addr), (size));                \
-       (bit) < (size);                                                 \
-       (bit) = ice_find_next_bit((addr), (size), (bit) + 1))
-
-static inline bool ice_is_any_bit_set(ice_bitmap_t *bitmap, u32 bits)
-{
-       u32 max_index = BITS_TO_CHUNKS(bits);
-       u32 i;
-
-       for (i = 0; i < max_index; i++) {
-               if (bitmap[i])
-                       return true;
-       }
-       return false;
-}
 
 /* memory allocation tracking */
 struct ice_dma_mem {
@@ -273,85 +193,6 @@ struct ice_virt_mem {
 #define HTONS(a) rte_cpu_to_be_16(a)
 #define HTONL(a) rte_cpu_to_be_32(a)
 
-static inline void
-ice_set_bit(unsigned int nr, volatile ice_bitmap_t *addr)
-{
-       __sync_fetch_and_or(addr, (1UL << nr));
-}
-
-static inline void
-ice_clear_bit(unsigned int nr, volatile ice_bitmap_t *addr)
-{
-       __sync_fetch_and_and(addr, (0UL << nr));
-}
-
-static inline void
-ice_zero_bitmap(ice_bitmap_t *bmp, u16 size)
-{
-       unsigned long mask;
-       u16 i;
-
-       for (i = 0; i < BITS_TO_CHUNKS(size) - 1; i++)
-               bmp[i] = 0;
-       mask = BITS_CHUNK_MASK(size);
-       bmp[i] &= ~mask;
-}
-
-static inline void
-ice_or_bitmap(ice_bitmap_t *dst, const ice_bitmap_t *bmp1,
-             const ice_bitmap_t *bmp2, u16 size)
-{
-       unsigned long mask;
-       u16 i;
-
-       /* Handle all but last chunk*/
-       for (i = 0; i < BITS_TO_CHUNKS(size) - 1; i++)
-               dst[i] = bmp1[i] | bmp2[i];
-
-       /* We want to only OR bits within the size. Furthermore, we also do
-        * not want to modify destination bits which are beyond the specified
-        * size. Use a bitmask to ensure that we only modify the bits that are
-        * within the specified size.
-        */
-       mask = BITS_CHUNK_MASK(size);
-       dst[i] &= ~mask;
-       dst[i] |= (bmp1[i] | bmp2[i]) & mask;
-}
-
-static inline void ice_cp_bitmap(ice_bitmap_t *dst, ice_bitmap_t *src, u16 size)
-{
-       ice_bitmap_t mask;
-       u16 i;
-
-       /* Handle all but last chunk*/
-       for (i = 0; i < BITS_TO_CHUNKS(size) - 1; i++)
-               dst[i] = src[i];
-
-       /* We want to only copy bits within the size.*/
-       mask = BITS_CHUNK_MASK(size);
-       dst[i] &= ~mask;
-       dst[i] |= src[i] & mask;
-}
-
-static inline bool
-ice_cmp_bitmap(ice_bitmap_t *bmp1, ice_bitmap_t *bmp2, u16 size)
-{
-       ice_bitmap_t mask;
-       u16 i;
-
-       /* Handle all but last chunk*/
-       for (i = 0; i < BITS_TO_CHUNKS(size) - 1; i++)
-               if (bmp1[i] != bmp2[i])
-                       return false;
-
-       /* We want to only compare bits within the size.*/
-       mask = BITS_CHUNK_MASK(size);
-       if ((bmp1[i] & mask) != (bmp2[i] & mask))
-               return false;
-
-       return true;
-}
-
 /* SW spinlock */
 struct ice_lock {
        rte_spinlock_t spinlock;
@@ -435,9 +276,23 @@ ice_hweight8(u32 num)
        return bits;
 }
 
+static inline u8
+ice_hweight32(u32 num)
+{
+       u8 bits = 0;
+       u32 i;
+
+       for (i = 0; i < 32; i++) {
+               bits += (u8)(num & 0x1);
+               num >>= 1;
+       }
+
+       return bits;
+}
+
 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
 #define DELAY(x) rte_delay_us(x)
-#define ice_usec_delay(x) rte_delay_us(x)
+#define ice_usec_delay(x, y) rte_delay_us(x)
 #define ice_msec_delay(x, y) rte_delay_us(1000 * (x))
 #define udelay(x) DELAY(x)
 #define msleep(x) DELAY(1000 * (x))
@@ -462,6 +317,22 @@ LIST_HEAD(ice_list_head, ice_list_entry);
 #define LIST_ADD(entry, list_head)    LIST_INSERT_HEAD(list_head, entry, next)
 #define LIST_ADD_AFTER(entry, list_entry) \
        LIST_INSERT_AFTER(list_entry, entry, next)
+
+static inline void list_add_tail(struct ice_list_entry *entry,
+                                struct ice_list_head *head)
+{
+       struct ice_list_entry *tail = head->lh_first;
+
+       if (tail == NULL) {
+               LIST_INSERT_HEAD(head, entry, next);
+               return;
+       }
+       while (tail->next.le_next != NULL)
+               tail = tail->next.le_next;
+       LIST_INSERT_AFTER(tail, entry, next);
+}
+
+#define LIST_ADD_TAIL(entry, head) list_add_tail(entry, head)
 #define LIST_FOR_EACH_ENTRY(pos, head, type, member)                          \
        for ((pos) = (head)->lh_first ?                                        \
                     container_of((head)->lh_first, struct type, member) :     \