Commit c6a6a5e3bb7120e1eb33eca6364a290229c1e72e

Authored by aliguori
1 parent 48c64363

e1000: use common checksumming code

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4972 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 6 additions and 14 deletions
hw/e1000.c
... ... @@ -279,26 +279,18 @@ flash_eerd_read(E1000State *s, int x)
279 279 E1000_EEPROM_RW_REG_DONE | r;
280 280 }
281 281  
282   -static unsigned int
283   -do_cksum(uint8_t *dp, uint8_t *de)
284   -{
285   - unsigned int bsum[2] = {0, 0}, i, sum;
286   -
287   - for (i = 1; dp < de; bsum[i^=1] += *dp++)
288   - ;
289   - sum = (bsum[0] << 8) + bsum[1];
290   - sum = (sum >> 16) + (sum & 0xffff);
291   - return ~(sum + (sum >> 16));
292   -}
293   -
294 282 static void
295 283 putsum(uint8_t *data, uint32_t n, uint32_t sloc, uint32_t css, uint32_t cse)
296 284 {
  285 + uint32_t sum;
  286 +
297 287 if (cse && cse < n)
298 288 n = cse + 1;
299   - if (sloc < n-1)
  289 + if (sloc < n-1) {
  290 + sum = net_checksum_add(n-css, data+css);
300 291 cpu_to_be16wu((uint16_t *)(data + sloc),
301   - do_cksum(data + css, data + n));
  292 + net_checksum_finish(sum));
  293 + }
302 294 }
303 295  
304 296 static void
... ...