From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 80658C5BA for ; Fri, 29 Jan 2016 09:56:49 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 29 Jan 2016 00:56:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,363,1449561600"; d="scan'208";a="891726581" Received: from yliu-dev.sh.intel.com (HELO yliu-dev) ([10.239.66.49]) by fmsmga001.fm.intel.com with ESMTP; 29 Jan 2016 00:56:36 -0800 Date: Fri, 29 Jan 2016 16:57:23 +0800 From: Yuanhan Liu To: Tetsuya Mukawa Message-ID: <20160129085723.GV4257@yliu-dev.sh.intel.com> References: <1453108389-21006-2-git-send-email-mukawa@igel.co.jp> <1453374478-30996-6-git-send-email-mukawa@igel.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1453374478-30996-6-git-send-email-mukawa@igel.co.jp> User-Agent: Mutt/1.5.23 (2014-03-12) Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [RFC PATCH 5/5] virtio: Extend virtio-net PMD to support container environment X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jan 2016 08:56:50 -0000 On Thu, Jan 21, 2016 at 08:07:58PM +0900, Tetsuya Mukawa wrote: > +static int > +virt_read_pci_cfg(struct virtio_hw *hw, void *buf, size_t len, off_t offset) > +{ > + qtest_read_pci_cfg(hw, "virtio-net", buf, len, offset); > + return 0; > +} > + > +static void * > +virt_get_mapped_addr(struct virtio_hw *hw, uint8_t bar, > + uint32_t offset, uint32_t length) > +{ > + uint64_t base; > + uint64_t size; > + > + if (qtest_get_bar_size(hw, "virtio-net", bar, &size) < 0) { > + PMD_INIT_LOG(ERR, "invalid bar: %u", bar); > + return NULL; > + } > + > + if (offset + length < offset) { > + PMD_INIT_LOG(ERR, "offset(%u) + lenght(%u) overflows", > + offset, length); > + return NULL; > + } > + > + if (offset + length > size) { > + PMD_INIT_LOG(ERR, > + "invalid cap: overflows bar space: %u > %"PRIu64, > + offset + length, size); > + return NULL; > + } > + > + if (qtest_get_bar_addr(hw, "virtio-net", bar, &base) < 0) { > + PMD_INIT_LOG(ERR, "invalid bar: %u", bar); > + return NULL; > + } So, I understood the usage now, and the cfg_ops abstraction doesn't look good yet necessary to me. For EAL managed pci device, bar length and addr are stored at memory_resources[], and for your case, it's from the qtest. And judging that it's compile time decision, I'd like it to be: #ifdef /* RTE_LIBRTE_VIRTIO_HOST_MODE */ static uint32_t get_bar_size(...) { return qtest_get_bar_size(..); } static uint64-t get_bar_addr(...) { return qtest_get_bar_addr(..); } ... ... #else static uint32_t get_bar_size(...) { return dev->mem_resource[bar].addr; } ... } #endif And then you just need do related changes at virtio_read_caps() and get_cfg_addr(). That'd be much simpler, without introducing duplicate code and uncessary complex. What do you think of that? --yliu > + > + return (void *)(base + offset); > +} > + > +static const struct virtio_pci_cfg_ops virt_cfg_ops = { > + .map = virt_map_pci_cfg, > + .unmap = virt_unmap_pci_cfg, > + .get_mapped_addr = virt_get_mapped_addr, > + .read = virt_read_pci_cfg, > +}; > +#endif /* RTE_LIBRTE_VIRTIO_HOST_MODE */