dpdk-kvs/cvmcs-kvs-main.c
/** 
 *
 * \brief Send the packet to the host over pci queue.
 * @param wqe Work to send to host
 * @param ifidx physical interface index the packet belongs to
 * @param rxq_idx PF/VF queue that packet needs to be sent to
 * @param l3_offset Starting of the L3 header
 * @param l4_offset Starting of the L4 header
 * @param flags  Packet metadata flags. See cvmcs-nic-mdata.h for various
 * 		 possible metadata flags
 * @return 0 on success, -1 on failure
 */
\brief Send the packet to the host over pci queue.
\ brief Send the packet to the host over pci queue .
int kvs_send_packet_to_pci_port(cvmx_wqe_t * wqe, int ifidx, int rxq_idx, int l3_offset,
				int l4_offset, int flags)
{
	union octeon_rh *rh;
	int port, queue, rxq;
	int ret = 0;
	uint64_t nextptr;
	cvmx_buf_ptr_pki_t *pki_lptr;
	cvmcs_nic_metadata_t *mdata = CVMCS_NIC_METADATA(wqe);
	uint8_t from_if = mdata->from_interface;
	int from_idx = mdata->from_ifidx;
	uint32_t hash = (uint32_t)-1; 
	uint32_t hashtype = 0;
	int len = 0;
	int fromq_idx = -1;
	int offset = 0;
	vnic_port_info_t *nicport = &octnic->port[ifidx];
	if (!nicport->state.rx_on) {
		kvsprintf("%s: RX is OFF for %d\n", __func__, ifidx);
		cvm_free_wqe_wrapper(wqe);
		return -1;
	}
	if(from_if == METADATA_PORT_DPI) {
		fromq_idx = (mdata->from_port-0x100) - octnic->port[mdata->from_ifidx].iq_base;
		 if(!((fromq_idx >= 0) && (fromq_idx < MAX_IOQS_PER_NICIF))) {
			printf("%s fromq_idx is invalid:%d\n", __func__, fromq_idx);
		}
	}
	nextptr = *((uint64_t *)
		    cvmx_phys_to_ptr(cvmx_wqe_get_pki_pkt_ptr(wqe).addr - 8));
	pki_lptr = (cvmx_buf_ptr_pki_t *) & wqe->packet_ptr;
	pki_lptr->addr -= OCT_RH_SIZE + 8;
	pki_lptr->size += OCT_RH_SIZE + 8;
	*(uint64_t *) cvmx_phys_to_ptr(pki_lptr->addr - 8) = nextptr;
	rh = (union octeon_rh *)cvmx_phys_to_ptr(pki_lptr->addr);
	cvmx_wqe_set_len(wqe, (cvmx_wqe_get_len(wqe) + OCT_RH_SIZE + 8));
	len = cvmx_wqe_get_len(wqe);
	rxq = OCT_NIC_OQ_NUM(nicport, rxq_idx);
	rh->u64 = 0;
	rh->r_dh.opcode = OPCODE_NIC;
	rh->r_dh.subcode = OPCODE_NIC_NW_DATA;
	rh->r_dh.csum_verified = CNNIC_CSUM_VERIFIED;
	rh->r_dh.encap_on = 0;
	rh->r_dh.has_hwtstamp = 0;
	rh->r_dh.len = 0;
	offset += OCT_RH_SIZE;
	*(uint32_t *)(rh+1) = hash;
        *(((uint32_t *)(rh+1)) + 1) = hashtype;
	rh->r_dh.has_hash = 0x1; 
	rh->r_dh.len += 1;
	offset += 8;
	len += 8;
	if (CVMCS_NIC_METADATA_VLAN_TCI(mdata)) {
		rh->r_dh.priority = CVMCS_NIC_METADATA_PRIORITY(mdata);
		rh->r_dh.vlan = CVMCS_NIC_METADATA_VLAN_ID(mdata);
	}
	port = cvm_pci_get_oq_pkoport(rxq);
	queue = cvm_pci_get_oq_pkoqueue(rxq);
	if (cvmx_unlikely(port == -1 || queue == -1)) {
		cvm_free_wqe_wrapper(wqe);
		return -1;
	}
	if(!(CVMCS_NIC_METADATA_CSUM_L3(mdata) || CVMCS_NIC_METADATA_CSUM_L4(mdata)))
	{
		l3_offset = l4_offset = 0;
	} else {
		l3_offset += offset;
		l4_offset += offset;
	} 
	ret = cvmcs_kvs_send_to_pko3(wqe, 1, port, queue, l3_offset,
					l4_offset, flags, nicport);
	if(ret != 0) {
		kvsprintf("%s:core %d,  PKO3 send on ifidx %d, pci port %d, queue %d, Failed \n",
		  __func__, cvmx_get_core_num(), ifidx, port, queue);
		cvm_free_wqe_wrapper(wqe);
		cvmcs_kvs_update_rx_err_stats(from_if, from_idx, ifidx);
		return -1;
	}
	cvmcs_kvs_update_rx_fwd_stats(from_if, from_idx, ifidx, len, fromq_idx, rxq_idx);
	return ret;
}
int kvs_send_packet_to_pci_port ( cvmx_wqe_t * wqe , int ifidx , int rxq_idx , int l3_offset , int l4_offset , int flags ) { union octeon_rh * rh ; int port , queue , rxq ; int ret = 0 ; uint64_t nextptr ; cvmx_buf_ptr_pki_t * pki_lptr ; cvmcs_nic_metadata_t * mdata = CVMCS_NIC_METADATA ( wqe ) ; uint8_t from_if = mdata -> from_interface ; int from_idx = mdata -> from_ifidx ; uint32_t hash = ( uint32_t ) -1 ; uint32_t hashtype = 0 ; int len = 0 ; int fromq_idx = -1 ; int offset = 0 ; vnic_port_info_t * nicport = & octnic -> port [ ifidx ] ; if ( ! nicport -> state . rx_on ) { kvsprintf ( " \n " , __func__ , ifidx ) ; cvm_free_wqe_wrapper ( wqe ) ; return -1 ; } if ( from_if == METADATA_PORT_DPI ) { fromq_idx = ( mdata -> from_port - 0x100 ) - octnic -> port [ mdata -> from_ifidx ] . iq_base ; if ( ! ( ( fromq_idx >= 0 ) && ( fromq_idx < MAX_IOQS_PER_NICIF ) ) ) { printf ( " \n " , __func__ , fromq_idx ) ; } } nextptr = * ( ( uint64_t * ) cvmx_phys_to_ptr ( cvmx_wqe_get_pki_pkt_ptr ( wqe ) . addr - 8 ) ) ; pki_lptr = ( cvmx_buf_ptr_pki_t * ) & wqe -> packet_ptr ; pki_lptr -> addr -= OCT_RH_SIZE + 8 ; pki_lptr -> size += OCT_RH_SIZE + 8 ; * ( uint64_t * ) cvmx_phys_to_ptr ( pki_lptr -> addr - 8 ) = nextptr ; rh = ( union octeon_rh * ) cvmx_phys_to_ptr ( pki_lptr -> addr ) ; cvmx_wqe_set_len ( wqe , ( cvmx_wqe_get_len ( wqe ) + OCT_RH_SIZE + 8 ) ) ; len = cvmx_wqe_get_len ( wqe ) ; rxq = OCT_NIC_OQ_NUM ( nicport , rxq_idx ) ; rh -> u64 = 0 ; rh -> r_dh . opcode = OPCODE_NIC ; rh -> r_dh . subcode = OPCODE_NIC_NW_DATA ; rh -> r_dh . csum_verified = CNNIC_CSUM_VERIFIED ; rh -> r_dh . encap_on = 0 ; rh -> r_dh . has_hwtstamp = 0 ; rh -> r_dh . len = 0 ; offset += OCT_RH_SIZE ; * ( uint32_t * ) ( rh + 1 ) = hash ; * ( ( ( uint32_t * ) ( rh + 1 ) ) + 1 ) = hashtype ; rh -> r_dh . has_hash = 0x1 ; rh -> r_dh . len += 1 ; offset += 8 ; len += 8 ; if ( CVMCS_NIC_METADATA_VLAN_TCI ( mdata ) ) { rh -> r_dh . priority = CVMCS_NIC_METADATA_PRIORITY ( mdata ) ; rh -> r_dh . vlan = CVMCS_NIC_METADATA_VLAN_ID ( mdata ) ; } port = cvm_pci_get_oq_pkoport ( rxq ) ; queue = cvm_pci_get_oq_pkoqueue ( rxq ) ; if ( cvmx_unlikely ( port == -1 || queue == -1 ) ) { cvm_free_wqe_wrapper ( wqe ) ; return -1 ; } if ( ! ( CVMCS_NIC_METADATA_CSUM_L3 ( mdata ) || CVMCS_NIC_METADATA_CSUM_L4 ( mdata ) ) ) { l3_offset = l4_offset = 0 ; } else { l3_offset += offset ; l4_offset += offset ; } ret = cvmcs_kvs_send_to_pko3 ( wqe , 1 , port , queue , l3_offset , l4_offset , flags , nicport ) ; if ( ret != 0 ) { kvsprintf ( " \n " , __func__ , cvmx_get_core_num ( ) , ifidx , port , queue ) ; cvm_free_wqe_wrapper ( wqe ) ; cvmcs_kvs_update_rx_err_stats ( from_if , from_idx , ifidx ) ; return -1 ; } cvmcs_kvs_update_rx_fwd_stats ( from_if , from_idx , ifidx , len , fromq_idx , rxq_idx ) ; return ret ; }
\brief Send the packet to the host over pci queue.
\ brief Send the packet to the host over pci queue .
/* All ones !*/ /* indicate hash */ //Vlan offload support. //VLAN is already stripped and present in metadata. //currently only supported for PF.  