]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - include/linux/etherdevice.h
dsa: mv88e6xxx: Optimise atu_get
[karo-tx-linux.git] / include / linux / etherdevice.h
index 6fec9e81bd70d9e0646a240e09b2395f74fd6f79..42add77ae47d7ef7f0203949f42a89338f05e97e 100644 (file)
@@ -396,6 +396,66 @@ static inline bool ether_addr_equal_masked(const u8 *addr1, const u8 *addr2,
        return true;
 }
 
+/**
+ * ether_addr_to_u64 - Convert an Ethernet address into a u64 value.
+ * @addr: Pointer to a six-byte array containing the Ethernet address
+ *
+ * Return a u64 value of the address
+ */
+static inline u64 ether_addr_to_u64(const u8 *addr)
+{
+       u64 u = 0;
+       int i;
+
+       for (i = 0; i < ETH_ALEN; i++)
+               u = u << 8 | addr[i];
+
+       return u;
+}
+
+/**
+ * u64_to_ether_addr - Convert a u64 to an Ethernet address.
+ * @u: u64 to convert to an Ethernet MAC address
+ * @addr: Pointer to a six-byte array to contain the Ethernet address
+ */
+static inline void u64_to_ether_addr(u64 u, u8 *addr)
+{
+       int i;
+
+       for (i = ETH_ALEN - 1; i >= 0; i--) {
+               addr[i] = u & 0xff;
+               u = u >> 8;
+       }
+}
+
+/**
+ * eth_addr_dec - Decrement the given MAC address
+ *
+ * @addr: Pointer to a six-byte array containing Ethernet address to decrement
+ */
+static inline void eth_addr_dec(u8 *addr)
+{
+       u64 u = ether_addr_to_u64(addr);
+
+       u--;
+       u64_to_ether_addr(u, addr);
+}
+
+/**
+ * ether_addr_greater - Compare two Ethernet addresses
+ * @addr1: Pointer to a six-byte array containing the Ethernet address
+ * @addr2: Pointer other six-byte array containing the Ethernet address
+ *
+ * Compare two Ethernet addresses, returns true addr1 is greater than addr2
+ */
+static inline bool ether_addr_greater(const u8 *addr1, const u8 *addr2)
+{
+       u64 u1 = ether_addr_to_u64(addr1);
+       u64 u2 = ether_addr_to_u64(addr2);
+
+       return u1 > u2;
+}
+
 /**
  * is_etherdev_addr - Tell if given Ethernet address belongs to the device.
  * @dev: Pointer to a device structure