On Wed, 8 Apr 2015 15:06:13 -0400 Vladimir Medvedkin <medvedkinv at gmail.com> wrote:
> Software implementation of the Toeplitz hash function used by RSS. > Can be used either for packet distribution on single queue NIC > or for simulating of RSS computation on specific NIC (for example > after GRE header decapsulating). > > Signed-off-by: Vladimir Medvedkin <medvedkinv at gmail.com> > +enum rte_thash_flag { > + RTE_THASH_L3 = 0, //calculate hash tacking into account only l3 > header > + RTE_THASH_L4 //calculate hash tacking into account l4 + l4 > headers > +}; > + > +/** > + * Prepare special converted key to use with rte_softrss_be() > + * @param orig > + * pointer to original RSS key > + * @param targ > + * pointer to target RSS key > + */ > + > +static inline void > +rte_convert_rss_key(uint32_t *orig, uint32_t *targ) orig should be const > +{ > + int i; > + for (i = 0; i < 10; i++) { > + targ[i] = rte_be_to_cpu_32(orig[i]); > + } > +} > +static inline uint32_t > +rte_softrss(uint32_t sip, uint32_t dip, uint16_t sp, uint16_t dp, enum > rte_thash_flag flag, uint32_t *rss_key) rss_key should be const > +{ > + uint32_t ret = 0; > + int i; > + for (i = 0; i < 32; i++) { blank line after declaration please > + if (sip & (1 << (31 - i))) { > + ret ^= (rte_cpu_to_be_32(*rss_key) << > i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i)); Long expression > 80 characters. Repeated multiple times (should be inline) Extra parens () Extension to 64 bits is only to avoid compiler warning? > + } > + } > + rss_key++; > + for (i = 0; i < 32; i++) { > + if (dip & (1 << (31 - i))) { > + ret ^= (rte_cpu_to_be_32(*rss_key) << > i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i)); > + } > + } > + if (flag == RTE_THASH_L4) { > + rss_key++; > + for (i = 0; i < 32; i++) { > + if (((sp<<16)|dp) & (1 << (31 - i))) { > + ret ^= (rte_cpu_to_be_32(*rss_key) << > i)|(uint32_t)((uint64_t)(rte_cpu_to_be_32(*(rss_key + 1))) >> (32 - i)); > + } > + } > + } > + return ret; > +} > + > +/** > + * Optimized implementation. > + * If you want the calculated hash value matches NIC RSS value > + * you have to use special converted key. > + * All ip's and ports have to be CPU byte order. > + * @param sip > + * Source ip address. > + * @param dip > + * Destination ip address. > + * @param sp > + * Source TCP|UDP port. > + * @param dp > + * Destination TCP|UDP port. > + * @param flag > + * RTE_THASH_L3: calculate hash tacking into account only sip and dip > + * RTE_THASH_L4: calculate hash tacking into account sip, dip, sp and dp > + * @param *rss_key > + * Pointer to 40-byte RSS hash key. > + * @return > + * Calculated hash value. > + */ > + > +static inline uint32_t > +rte_softrss_be(uint32_t sip, uint32_t dip, uint16_t sp, uint16_t dp, enum > rte_thash_flag flag, uint32_t *rss_key) > +{ Same problems as previous code. Also lots of copy paste (see Do Not Repeat Yourself principle).