| 573 | } |
| 574 | |
| 575 | static int |
| 576 | decompress_zlib(struct rte_comp_op *op, |
| 577 | const struct rte_comp_xform *xform) |
| 578 | { |
| 579 | z_stream stream; |
| 580 | int window_bits; |
| 581 | int zlib_flush; |
| 582 | int ret = TEST_FAILED; |
| 583 | uint8_t *single_src_buf = NULL; |
| 584 | uint8_t *single_dst_buf = NULL; |
| 585 | |
| 586 | /* initialize zlib stream */ |
| 587 | stream.zalloc = Z_NULL; |
| 588 | stream.zfree = Z_NULL; |
| 589 | stream.opaque = Z_NULL; |
| 590 | |
| 591 | /* |
| 592 | * Window bits is the base two logarithm of the window size (in bytes). |
| 593 | * When doing raw DEFLATE, this number will be negative. |
| 594 | */ |
| 595 | window_bits = -(xform->decompress.window_size); |
| 596 | ret = inflateInit2(&stream, window_bits); |
| 597 | |
| 598 | if (ret != Z_OK) { |
| 599 | printf("Zlib deflate could not be initialized\n"); |
| 600 | goto exit; |
| 601 | } |
| 602 | |
| 603 | /* Assuming stateless operation */ |
| 604 | /* SGL */ |
| 605 | if (op->m_src->nb_segs > 1) { |
| 606 | single_src_buf = rte_malloc(NULL, |
| 607 | rte_pktmbuf_pkt_len(op->m_src), 0); |
| 608 | if (single_src_buf == NULL) { |
| 609 | RTE_LOG(ERR, USER1, "Buffer could not be allocated\n"); |
| 610 | goto exit; |
| 611 | } |
| 612 | single_dst_buf = rte_malloc(NULL, |
| 613 | rte_pktmbuf_pkt_len(op->m_dst), 0); |
| 614 | if (single_dst_buf == NULL) { |
| 615 | RTE_LOG(ERR, USER1, "Buffer could not be allocated\n"); |
| 616 | goto exit; |
| 617 | } |
| 618 | if (rte_pktmbuf_read(op->m_src, 0, |
| 619 | rte_pktmbuf_pkt_len(op->m_src), |
| 620 | single_src_buf) == NULL) { |
| 621 | RTE_LOG(ERR, USER1, |
| 622 | "Buffer could not be read entirely\n"); |
| 623 | goto exit; |
| 624 | } |
| 625 | |
| 626 | stream.avail_in = op->src.length; |
| 627 | stream.next_in = single_src_buf; |
| 628 | stream.avail_out = rte_pktmbuf_pkt_len(op->m_dst); |
| 629 | stream.next_out = single_dst_buf; |
| 630 | |
| 631 | } else { |
| 632 | stream.avail_in = op->src.length; |
no test coverage detected