src/dpdk/drivers/net/nfp/nfp_net.c
static int
nfp_cpp_bridge_serve_read(int sockfd, struct nfp_cpp *cpp)
{
	struct nfp_cpp_area *area;
	off_t offset, nfp_offset;
	uint32_t cpp_id, pos, len;
	uint32_t tmpbuf[16];
	size_t count, curlen, totlen = 0;
	int err = 0;

	PMD_CPP_LOG(DEBUG, "%s: offset size %zu, count_size: %zu\n", __func__,
		sizeof(off_t), sizeof(size_t));

	/* Reading the count param */
	err = recv(sockfd, &count, sizeof(off_t), 0);
	if (err != sizeof(off_t))
		return -EINVAL;

	curlen = count;

	/* Reading the offset param */
	err = recv(sockfd, &offset, sizeof(off_t), 0);
	if (err != sizeof(off_t))
		return -EINVAL;

	/* Obtain target's CPP ID and offset in target */
	cpp_id = (offset >> 40) << 8;
	nfp_offset = offset & ((1ull << 40) - 1);

	PMD_CPP_LOG(DEBUG, "%s: count %zu and offset %jd\n", __func__, count,
			   offset);
	PMD_CPP_LOG(DEBUG, "%s: cpp_id %08x and nfp_offset %jd\n", __func__,
			   cpp_id, nfp_offset);

	/* Adjust length if not aligned */
	if (((nfp_offset + (off_t)count - 1) & ~(NFP_CPP_MEMIO_BOUNDARY - 1)) !=
	    (nfp_offset & ~(NFP_CPP_MEMIO_BOUNDARY - 1))) {
		curlen = NFP_CPP_MEMIO_BOUNDARY -
			(nfp_offset & (NFP_CPP_MEMIO_BOUNDARY - 1));
	}

	while (count > 0) {
		area = nfp_cpp_area_alloc_with_name(cpp, cpp_id, "nfp.cdev",
						    nfp_offset, curlen);
		if (!area) {
			RTE_LOG(ERR, PMD, "%s: area alloc failed\n", __func__);
			return -EIO;
		}

		err = nfp_cpp_area_acquire(area);
		if (err < 0) {
			RTE_LOG(ERR, PMD, "area acquire failed\n");
			nfp_cpp_area_free(area);
			return -EIO;
		}

		for (pos = 0; pos < curlen; pos += len) {
			len = curlen - pos;
			if (len > sizeof(tmpbuf))
				len = sizeof(tmpbuf);

			err = nfp_cpp_area_read(area, pos, tmpbuf, len);
			if (err < 0) {
				RTE_LOG(ERR, PMD, "nfp_cpp_area_read error\n");
				nfp_cpp_area_release(area);
				nfp_cpp_area_free(area);
				return -EIO;
			}
			PMD_CPP_LOG(DEBUG, "%s: sending %u of %zu\n", __func__,
					   len, count);

			err = send(sockfd, tmpbuf, len, 0);
			if (err != (int)len) {
				RTE_LOG(ERR, PMD,
					"%s: error when sending: %d of %zu\n",
					__func__, err, count);
				nfp_cpp_area_release(area);
				nfp_cpp_area_free(area);
				return -EIO;
			}
		}

		nfp_offset += pos;
		totlen += pos;
		nfp_cpp_area_release(area);
		nfp_cpp_area_free(area);

		count -= pos;
		curlen = (count > NFP_CPP_MEMIO_BOUNDARY) ?
			NFP_CPP_MEMIO_BOUNDARY : count;
	}
	return 0;
}
/*
 * Serving a read request to NFP from host programs. The request
 * sends the read size and the CPP target. The bridge makes use
 * of CPP interface handler configured by the PMD setup. The read
 * data is sent to the requester using the same socket.
 */
Serving a read request to NFP from host programs. The request
sends the read size and the CPP target. The bridge makes use
of CPP interface handler configured by the PMD setup. The read
data is sent to the requester using the same socket.
Serving a read request to NFP from host programs . The request sends the read size and the CPP target . The bridge makes use of CPP interface handler configured by the PMD setup . The read data is sent to the requester using the same socket .
static int
nfp_cpp_bridge_serve_read(int sockfd, struct nfp_cpp *cpp)
{
	struct nfp_cpp_area *area;
	off_t offset, nfp_offset;
	uint32_t cpp_id, pos, len;
	uint32_t tmpbuf[16];
	size_t count, curlen, totlen = 0;
	int err = 0;
	PMD_CPP_LOG(DEBUG, "%s: offset size %zu, count_size: %zu\n", __func__,
		sizeof(off_t), sizeof(size_t));
	err = recv(sockfd, &count, sizeof(off_t), 0);
	if (err != sizeof(off_t))
		return -EINVAL;
	curlen = count;
	err = recv(sockfd, &offset, sizeof(off_t), 0);
	if (err != sizeof(off_t))
		return -EINVAL;
	cpp_id = (offset >> 40) << 8;
	nfp_offset = offset & ((1ull << 40) - 1);
	PMD_CPP_LOG(DEBUG, "%s: count %zu and offset %jd\n", __func__, count,
			   offset);
	PMD_CPP_LOG(DEBUG, "%s: cpp_id %08x and nfp_offset %jd\n", __func__,
			   cpp_id, nfp_offset);
	if (((nfp_offset + (off_t)count - 1) & ~(NFP_CPP_MEMIO_BOUNDARY - 1)) !=
	    (nfp_offset & ~(NFP_CPP_MEMIO_BOUNDARY - 1))) {
		curlen = NFP_CPP_MEMIO_BOUNDARY -
			(nfp_offset & (NFP_CPP_MEMIO_BOUNDARY - 1));
	}
	while (count > 0) {
		area = nfp_cpp_area_alloc_with_name(cpp, cpp_id, "nfp.cdev",
						    nfp_offset, curlen);
		if (!area) {
			RTE_LOG(ERR, PMD, "%s: area alloc failed\n", __func__);
			return -EIO;
		}
		err = nfp_cpp_area_acquire(area);
		if (err < 0) {
			RTE_LOG(ERR, PMD, "area acquire failed\n");
			nfp_cpp_area_free(area);
			return -EIO;
		}
		for (pos = 0; pos < curlen; pos += len) {
			len = curlen - pos;
			if (len > sizeof(tmpbuf))
				len = sizeof(tmpbuf);
			err = nfp_cpp_area_read(area, pos, tmpbuf, len);
			if (err < 0) {
				RTE_LOG(ERR, PMD, "nfp_cpp_area_read error\n");
				nfp_cpp_area_release(area);
				nfp_cpp_area_free(area);
				return -EIO;
			}
			PMD_CPP_LOG(DEBUG, "%s: sending %u of %zu\n", __func__,
					   len, count);
			err = send(sockfd, tmpbuf, len, 0);
			if (err != (int)len) {
				RTE_LOG(ERR, PMD,
					"%s: error when sending: %d of %zu\n",
					__func__, err, count);
				nfp_cpp_area_release(area);
				nfp_cpp_area_free(area);
				return -EIO;
			}
		}
		nfp_offset += pos;
		totlen += pos;
		nfp_cpp_area_release(area);
		nfp_cpp_area_free(area);
		count -= pos;
		curlen = (count > NFP_CPP_MEMIO_BOUNDARY) ?
			NFP_CPP_MEMIO_BOUNDARY : count;
	}
	return 0;
}
static int nfp_cpp_bridge_serve_read ( int sockfd , struct nfp_cpp * cpp ) { struct nfp_cpp_area * area ; off_t offset , nfp_offset ; uint32_t cpp_id , pos , len ; uint32_t tmpbuf [ 16 ] ; size_t count , curlen , totlen = 0 ; int err = 0 ; PMD_CPP_LOG ( DEBUG , " \n " , __func__ , sizeof ( off_t ) , sizeof ( size_t ) ) ; err = recv ( sockfd , & count , sizeof ( off_t ) , 0 ) ; if ( err != sizeof ( off_t ) ) return - EINVAL ; curlen = count ; err = recv ( sockfd , & offset , sizeof ( off_t ) , 0 ) ; if ( err != sizeof ( off_t ) ) return - EINVAL ; cpp_id = ( offset >> 40 ) << 8 ; nfp_offset = offset & ( ( 1ull << 40 ) - 1 ) ; PMD_CPP_LOG ( DEBUG , " \n " , __func__ , count , offset ) ; PMD_CPP_LOG ( DEBUG , " \n " , __func__ , cpp_id , nfp_offset ) ; if ( ( ( nfp_offset + ( off_t ) count - 1 ) & ~ ( NFP_CPP_MEMIO_BOUNDARY - 1 ) ) != ( nfp_offset & ~ ( NFP_CPP_MEMIO_BOUNDARY - 1 ) ) ) { curlen = NFP_CPP_MEMIO_BOUNDARY - ( nfp_offset & ( NFP_CPP_MEMIO_BOUNDARY - 1 ) ) ; } while ( count > 0 ) { area = nfp_cpp_area_alloc_with_name ( cpp , cpp_id , " " , nfp_offset , curlen ) ; if ( ! area ) { RTE_LOG ( ERR , PMD , " \n " , __func__ ) ; return - EIO ; } err = nfp_cpp_area_acquire ( area ) ; if ( err < 0 ) { RTE_LOG ( ERR , PMD , " \n " ) ; nfp_cpp_area_free ( area ) ; return - EIO ; } for ( pos = 0 ; pos < curlen ; pos += len ) { len = curlen - pos ; if ( len > sizeof ( tmpbuf ) ) len = sizeof ( tmpbuf ) ; err = nfp_cpp_area_read ( area , pos , tmpbuf , len ) ; if ( err < 0 ) { RTE_LOG ( ERR , PMD , " \n " ) ; nfp_cpp_area_release ( area ) ; nfp_cpp_area_free ( area ) ; return - EIO ; } PMD_CPP_LOG ( DEBUG , " \n " , __func__ , len , count ) ; err = send ( sockfd , tmpbuf , len , 0 ) ; if ( err != ( int ) len ) { RTE_LOG ( ERR , PMD , " \n " , __func__ , err , count ) ; nfp_cpp_area_release ( area ) ; nfp_cpp_area_free ( area ) ; return - EIO ; } } nfp_offset += pos ; totlen += pos ; nfp_cpp_area_release ( area ) ; nfp_cpp_area_free ( area ) ; count -= pos ; curlen = ( count > NFP_CPP_MEMIO_BOUNDARY ) ? NFP_CPP_MEMIO_BOUNDARY : count ; } return 0 ; }
Serving a read request to NFP from host programs.
Serving a read request to NFP from host programs .
/* Reading the count param */ /* Reading the offset param */ /* Obtain target's CPP ID and offset in target */ /* Adjust length if not aligned */