Example #1
0
/**
 * rw_piot_get_flow_ctrl()
 *
 * Get flow-control on an Ethernet device
 */
int
rw_piot_get_flow_ctrl(rw_piot_api_handle_t api_handle,
		      rw_piot_port_fc_conf_t *fc_cfgp)
{
  int rc = 0;
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(NULL != fc_cfgp);
  

  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    rc = -1;
  }
  else {
    if (rw_piot_dev->device_group->device_group_type == PIOT_PCI) {
      rc = rte_eth_dev_flow_ctrl_get(rw_piot_dev->rte_port_id, fc_cfgp);
      if (rc != 0) {
        RW_PIOT_LOG(RTE_LOG_ERR, "PIOT rte_eth_dev_flow_ctrl_set() returned error_code=%d\n",rc);
      }
    }
  }
  
  return rc;
}
Example #2
0
int
rw_piot_update_mtu(rw_piot_api_handle_t api_handle, uint32_t mtu)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }
  return(rte_eth_dev_set_mtu(rw_piot_dev->rte_port_id, mtu));  
}
Example #3
0
int
rw_piot_get_vlan_offload(rw_piot_api_handle_t api_handle)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }
  return rte_eth_dev_get_vlan_offload(rw_piot_dev->rte_port_id);
}
Example #4
0
int
rw_piot_mac_addr_delete(rw_piot_api_handle_t api_handle, struct ether_addr *addr)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }
  return(rte_eth_dev_mac_addr_remove(rw_piot_dev->rte_port_id, addr));
}
Example #5
0
void 
rw_piot_reset_link_stats(rw_piot_api_handle_t api_handle)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle or invalid input param\n");
    return;
  }
  rte_eth_stats_reset(rw_piot_dev->rte_port_id);
  return;
}
Example #6
0
void 
rw_piot_get_link_info(rw_piot_api_handle_t api_handle, rw_piot_link_info_t *eth_link_info)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev || NULL == eth_link_info) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle or invalid input param\n");
    return;
  }
  rte_eth_link_get_nowait(rw_piot_dev->rte_port_id, eth_link_info);
  return;
}
Example #7
0
int rw_piot_dev_callback_unregister(rw_piot_api_handle_t api_handle,
                                  enum rte_eth_event_type event,
                                  rte_eth_dev_cb_fn cb_fn, void *cb_arg)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }
  return(rte_eth_dev_callback_unregister(rw_piot_dev->rte_port_id, event, cb_fn, cb_arg));
}
Example #8
0
int
rw_piot_set_rx_queue_stats_mapping(rw_piot_api_handle_t api_handle, uint16_t rx_queue_id, uint8_t stat_idx)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  int ret;
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }
  ret = rte_eth_dev_set_rx_queue_stats_mapping(rw_piot_dev->rte_port_id, rx_queue_id, stat_idx);
  return(ret);
}
Example #9
0
int
rw_piot_get_extended_stats(rw_piot_api_handle_t api_handle,
                           struct rte_eth_xstats *xstats, unsigned n)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle or invalid input param\n");
    return -1;
  }
  return rte_eth_xstats_get(rw_piot_dev->rte_port_id,
                            xstats, n);
}
Example #10
0
int 
rw_piot_get_device_info(rw_piot_api_handle_t api_handle,
                        struct rte_eth_dev_info *dev_info)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }
  ASSERT(dev_info);
  rte_eth_dev_info_get(rw_piot_dev->rte_port_id, dev_info);
  return 0;
}
Example #11
0
int
rw_piot_update_vlan_filter(rw_piot_api_handle_t api_handle, uint16_t vlan_id,
                           int on)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }

  return rte_eth_dev_vlan_filter(rw_piot_dev->rte_port_id,
                                 vlan_id, on);
}
Example #12
0
int
rw_piot_set_mc_addr_list(rw_piot_api_handle_t api_handle,
                         struct ether_addr *mc_addr_set,
                         uint32_t nb_mc_addr)
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle to set multicast addresses\n");
    return -1;
  }

  
  return rte_eth_dev_set_mc_addr_list(rw_piot_dev->rte_port_id, mc_addr_set, nb_mc_addr);  
}
Example #13
0
int 
rw_piot_tx_queue_setup(rw_piot_api_handle_t api_handle,
                       uint16_t tx_queue_id,
                       uint16_t nb_tx_desc, 
                       unsigned int socket_id,
                       const struct rte_eth_txconf *tx_conf)

{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }
  return(rte_eth_tx_queue_setup(rw_piot_dev->rte_port_id, tx_queue_id, nb_tx_desc, socket_id, tx_conf));
}
Example #14
0
void 
rw_piot_set_promiscuous(rw_piot_api_handle_t api_handle, int on) 
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return;
  }
  if (on) {
     rte_eth_promiscuous_enable(rw_piot_dev->rte_port_id);
  }
  else {
     rte_eth_promiscuous_disable(rw_piot_dev->rte_port_id);
  }
  return;
}
Example #15
0
int 
rw_piot_set_led(rw_piot_api_handle_t api_handle, int on) 
{
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  int ret;
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }
  if (on) {
    ret = rte_eth_led_on(rw_piot_dev->rte_port_id);
  }
  else {
    ret = rte_eth_led_off(rw_piot_dev->rte_port_id);
  }
  return ret;
}
Example #16
0
int
rw_piot_dev_reconfigure(rw_piot_api_handle_t api_handle,
                        rw_piot_open_request_info_t *req_info,
                        rw_piot_open_response_info_t *rsp_info)
{
  int ret;
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }
  if (rw_piot_dev->device_group->device_group_type != PIOT_PCI) {
    req_info->dev_conf.intr_conf.lsc = 0;
  }
  ret = rw_piot_config_device(api_handle, req_info, rsp_info);

  return ret;
}
Example #17
0
int
rw_piot_get_device_offload_capability(rw_piot_api_handle_t api_handle,
                                      uint32_t  *rx_offload_capa,                   
                                      uint32_t  *tx_offload_capa)
{
  struct rte_eth_dev_info dev_info;
  rw_piot_device_t *rw_piot_dev = RWPIOT_GET_DEVICE(api_handle);
  ASSERT(RWPIOT_VALID_DEVICE(rw_piot_dev));
  if (NULL == rw_piot_dev) {
    RW_PIOT_LOG(RTE_LOG_ERR, "PIOT Could not find device by handle\n");
    return -1;
  }
  ASSERT(rx_offload_capa);
  ASSERT(tx_offload_capa);
  memset(&dev_info, 0, sizeof(dev_info));
  rte_eth_dev_info_get(rw_piot_dev->rte_port_id, &dev_info);
  *rx_offload_capa = dev_info.rx_offload_capa;
  *tx_offload_capa = dev_info.tx_offload_capa;
  return 0;
}
Example #18
0
/*
 * Initialize PIOT Module
 */
int
rw_piot_init(int argc, char **argv, void *instance_ptr, f_rw_piot_log_t log_fn)
{

  int rc, ret;
  int i, no_huge = 0, memory_req = 0;
  struct rte_config *cfg = rte_eal_get_configuration();

/*
 * TBD - thread safety
 */

  if (piot_initialized) {
    int num_arg;

    for (num_arg = 0; num_arg < argc; num_arg ++) {
      if (strcmp(argv[num_arg], "--") == 0) {
        break;
      } 
    }
    return num_arg;
  }
  piot_initialized = 1;


  memset(&rw_piot_global_config, 0, sizeof(rw_piot_global_config));
  ASSERT(instance_ptr);
  rw_piot_global_config.instance_ptr = instance_ptr;
  rw_piot_global_config.log_fn = log_fn;

  memset(&(rw_piot_lcore[0]), 0, sizeof(rw_piot_lcore));
  
  for (i=0; i<argc; i++) {
    if (strcmp("--no-huge", argv[i]) == 0) {
      no_huge = 1;
      RW_PIOT_LOG(RTE_LOG_INFO, "PIOT: Huge pages disabled by --no-huge cmdarg\n");
    }
    if (strcmp("-m", argv[i]) == 0) {
      if ((i+1) <argc) {
        memory_req = atoi(argv[i+1]);
        RW_PIOT_LOG(RTE_LOG_INFO, "PIOT: -m cmdarg setting requested memory to %d mb\n", memory_req);
      }
    }
    if (strcmp("--", argv[i]) == 0) {
      break;
    }
  }
  /*
   * setup system environment for DPDK
   */
  rc = dpdk_system_setup(no_huge, memory_req);
  if (rc < 0) {
    return rc;
  }

  rte_set_application_log_hook(rw_piot_log_handler);

  /*
   * Init DPDK EAL without doing thread related inits
   */
  ret = rte_eal_init_no_thread(argc, argv);
  if (ret < 0) {
    return ret;
  }
  if (geteuid() == 0){
    rte_kni_init(RWPIOT_MAX_KNI_DEVICES);
  }
 /*
  * Assign master lcore-id. Should be passed in the init - TBD
  */

  cfg->master_lcore = 0;  /* This wil be fixed with RW.Sched integration -  TBD */

  /* set the lcore ID in per-lcore memory area */
  RTE_PER_LCORE(_lcore_id) = cfg->master_lcore;

  /* set CPU affinity for master thread ??? TBD*/
  // if (eal_thread_set_affinity() < 0)
  //    rte_panic("cannot set affinity\n");

  rte_timer_subsystem_init();

  return ret; /* number of args consumed by rte_eal_init_no_thread */
}
Example #19
0
rw_piot_api_handle_t
rw_piot_open(char *device_name,
             rw_piot_open_request_info_t *req_info,
             rw_piot_open_response_info_t *rsp_info)
{
  int n;
  uint32_t i;
  char *devname_split[2];
  char *split_args[2];
  char *dev_arg;
  char received_name[RW_PIOT_DEVICE_NAME_LEN];
  struct rte_eth_dev *eth_dev = NULL;
  rw_piot_device_t *rw_piot_dev = NULL;

  ASSERT(device_name);
  ASSERT(req_info);
  ASSERT(rsp_info);

  if (NULL == device_name ||
      NULL == req_info ||
      NULL == rsp_info) {
    /* failure */
    return(0);
  }

  /*
   * copy device name to a buffer, which can be give to split
   */
  strncpy(received_name, device_name, sizeof(received_name));

  /* parse the device name */
  //printf("split %s\n", received_name);
  n = rte_strsplit(received_name, strlen(received_name), devname_split, 2, ':'); 
  if (n != 2) {
     RW_PIOT_LOG(RTE_LOG_CRIT, "PIOT: rw_piot_open: split failed %s, %d\n", device_name, n);
    return(0);
  }

  //printf("Token 1 %s Token 2 %s \n",devname_split[0], devname_split[1]);

  /* check the device is already opened */
 for (i=0; i<RWPIOT_MAX_DEVICES; i++) {
    if (rw_piot_global_config.device[i].used) {
      if (!strncmp(received_name, rw_piot_global_config.device[i].device_name, sizeof(rw_piot_global_config.device[i].device_name))) {
        RW_PIOT_LOG(RTE_LOG_CRIT, "PIOT: rw_piot_open: failed, found already opened device\n");
        return(0);
      }
    }
  }

   if (strcmp(devname_split[0], "eth_pcap"))  {
     /* if the device is not pcap, strip-off = and characters before */
      n = rte_strsplit(devname_split[1], strlen(devname_split[1]), split_args, 2, '='); 
      if (n != 2) {
          return 0;
       }
       dev_arg = split_args[1];
   }
   else {
       dev_arg = devname_split[1]; 
   }

   for (i=0; i<NUM_SUPPORTED_DEVICETYPES; i++) {
     if (!strncmp(rw_piot_devgroup[i].device_group_name, devname_split[0], 32)) {
       char dev_inst_name[RW_PIOT_DEVICE_NAME_LEN];

       sprintf(dev_inst_name, "%s%d",devname_split[0], rw_piot_devgroup[i].num_open_instances);
       switch (rw_piot_devgroup[i].device_group_type) {
         case PIOT_PCI: {
           struct rte_pci_device *pci_dev;

           //printf("pci address %s\n",dev_arg);
           pci_dev = rte_eal_pci_probe_by_pci_addr(dev_arg);
             if (pci_dev) {
               eth_dev = rte_eth_dev_find_dev_by_pci(pci_dev);
               if (eth_dev == NULL) {
                 RW_PIOT_LOG(RTE_LOG_CRIT, "PIOT: rw_piot_open: rte_eth_dev_find_dev_by_pci failed\n");
               }
             }
             else {
               RW_PIOT_LOG(RTE_LOG_CRIT, "PIOT: rw_piot_open: rte_eal_pci_probe_by_pci_addr failed\n");
             }
           }
         break;
         case PIOT_NON_PCI: {
           req_info->dev_conf.intr_conf.lsc = 0;
           //printf("Non-PCI %s %s\n", dev_inst_name, dev_arg);
           if (!rte_eal_non_pci_ethdev_init_by_devname(devname_split[0],
                                                       dev_inst_name, dev_arg)) {
             /*
              * Caution - DIRTY Code here.
              * Assumption is not to change DPDDK existing code, but can add new
              * functions to DPDK.
              * This is the only way to get the eth_dev for the init we have
              * done here from dpdk
              * This will be cleaned up later - TBD
              */
             //printf("Non-PCI Init success\n");
             eth_dev = rte_eth_dev_get_last_eth_dev(); /* Assume the last eth_dev is added for this case, BAD code, temporarily */
             if (!eth_dev) {
               RW_PIOT_LOG(RTE_LOG_CRIT, "PIOT: rw_piot_open: Non-PCI couldnot find ethdev\n");
             }
           }
         }
         break;
         default:
           break;
       }
       break;
     }
   }

   if (eth_dev) {
     rw_piot_dev = rw_piot_device_alloc(&rw_piot_devgroup[i]);
     if (rw_piot_dev) {
       rw_piot_dev->rte_port_id = eth_dev->data->port_id;
       strncpy(rw_piot_dev->device_name, device_name, sizeof(rw_piot_dev->device_name));
       
       if(rw_piot_config_device(rw_piot_dev, req_info, rsp_info) != 0) {
         /* device config failed */
          RW_PIOT_LOG(RTE_LOG_CRIT, "PIOT: rw_piot_open: Device config failed \n");
          rw_piot_close(rw_piot_dev->piot_api_handle);
          return(0);
       }
       rsp_info->NUMA_affinity = rte_eth_dev_socket_id( eth_dev->data->port_id);
       return(rw_piot_dev->piot_api_handle);
     }
     else {
       RW_PIOT_LOG(RTE_LOG_CRIT, "PIOT: rw_piot_open: rw_piot_device_alloc failed\n");
     }
   }
   return(0);
}