Hi Jianfeng, > -----Original Message----- > From: Tan, Jianfeng > Sent: Monday, January 11, 2016 7:39 AM > To: Ananyev, Konstantin; N?lio Laranjeiro; dev at dpdk.org > Subject: Re: [dpdk-dev] [PATCH 01/12] ethdev: add API to query what/if packet > type is set > > Hi, > > According to the proposal, I'm going to fix the definition of this API > as below: > /** > * Retrieve the contextual information of an Ethernet device. > * > * @param port_id > * The port identifier of the Ethernet device. > * @param ptype_mask > * A hint of what kind of packet type which the caller is interested in > * @param ptypes > * An array of packet types to be filled with > * @param num > * Size of ptypes[] > * @return > * - (>=0) if successful. Indicate number of valid values in ptypes > array. > * - (-ENOTSUP) if hardware-assisted VLAN stripping not configured. > * - (-ENODEV) if *port_id* invalid. > */ > extern int rte_eth_dev_get_ptype_info(uint8_t port_id, > uint32_t ptype_mask, uint32_t ptypes[], > uint32_t num); > > Unresolved issues: > 1) When num is exceeded, we just stop there and return num, or return > -ENOMEM?
I think when num is exceeded it should return number of entries enough to return all requested packet types. Same as snprintf() does when it has to truncate the output buffer. > The first way has a bug when: what app is exactly asking for is not > filled in ptypes[] because of > exceeding num, but app believes this API returns with success. It is a caller responsibility to check the return value and handle it properly. When return value exceeds num - caller can resize ptypes[] and call get_ptype_info() again. > > 2) if RTE_PTYPE_*_MAX_NUM macros necessary? Without them, we could calculate > num through 2^(number of bit 1 in RTE_PTPE_*_MASK). I don't think caller has to guess somehow what number of entries in ptypes[] he need . He can retrieve that information from get_ptype_info() itself. Something like that for example: num = rte_eth_dev_get_ptype_info(port, UINT32_MAX, NULL, 0); if (num < 0) return num; ptypes = alloca(num * sizeof(ptypes[0]); ret = rte_eth_dev_get_ptype_info(port, UINT32_MAX, ptypes, num); if (ret != num) return -1; .... Konstantin > > Thanks, > Jianfeng