* This function is used to check whether a passed pbuf contains only buffers * resident in regions of memory that the Ethernet MAC can access. If any * buffers in the chain are outside a directly-DMAable section of memory, * the pbuf is copied to SRAM and a different pointer returned. If all * buffers are safe, the pbuf reference count is incremented and the original * pointer returned. */
| 484 | * pointer returned. |
| 485 | */ |
| 486 | static struct pbuf * |
| 487 | tivaif_check_pbuf(struct pbuf *p) |
| 488 | { |
| 489 | struct pbuf *pBuf; |
| 490 | rt_err_t Err; |
| 491 | |
| 492 | pBuf = p; |
| 493 | |
| 494 | #ifdef DEBUG |
| 495 | tivaif_trace_pbuf("Original:", p); |
| 496 | #endif |
| 497 | |
| 498 | /* Walk the list of buffers in the pbuf checking each. */ |
| 499 | do |
| 500 | { |
| 501 | /* Does this pbuf's payload reside in memory that the Ethernet DMA |
| 502 | * can access? |
| 503 | */ |
| 504 | if(!PTR_SAFE_FOR_EMAC_DMA(pBuf->payload)) |
| 505 | { |
| 506 | /* This buffer is outside the DMA-able memory space so we need |
| 507 | * to copy the pbuf. |
| 508 | */ |
| 509 | pBuf = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_POOL); |
| 510 | |
| 511 | /* If we got a new pbuf... */ |
| 512 | if(pBuf) |
| 513 | { |
| 514 | /* ...copy the old pbuf into the new one. */ |
| 515 | Err = pbuf_copy(pBuf, p); |
| 516 | |
| 517 | /* If we failed to copy the pbuf, free the newly allocated one |
| 518 | * and make sure we return a NULL to show a problem. |
| 519 | */ |
| 520 | if(Err != RT_EOK) |
| 521 | { |
| 522 | DRIVER_STATS_INC(TXCopyFailCount); |
| 523 | pbuf_free(pBuf); |
| 524 | pBuf = NULL; |
| 525 | } |
| 526 | else |
| 527 | { |
| 528 | #ifdef DEBUG |
| 529 | tivaif_trace_pbuf("Copied:", pBuf); |
| 530 | #endif |
| 531 | DRIVER_STATS_INC(TXCopyCount); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | /* Reduce the reference count on the original pbuf since we're not |
| 536 | * going to hold on to it after returning from tivaif_transmit. |
| 537 | * Note that we already bumped the reference count at the top of |
| 538 | * tivaif_transmit. |
| 539 | */ |
| 540 | pbuf_free(p); |
| 541 | |
| 542 | /* Send back the new pbuf pointer or NULL if an error occurred. */ |
| 543 | return(pBuf); |
no test coverage detected