Re: [PATCH 1/2] IFC hardware operation layer

From: Mark D Rustad
Date: Sat Nov 09 2019 - 15:07:15 EST


On Tue, Nov 05, 2019 at 05:37:39PM +0800, Zhu Lingshan wrote:
This commit introduced ifcvf_base layer, which handles hardware
operations and configurations.

Signed-off-by: Zhu Lingshan <lingshan.zhu@xxxxxxxxx>
---
drivers/vhost/ifcvf/ifcvf_base.c | 344 +++++++++++++++++++++++++++++++++++++++
drivers/vhost/ifcvf/ifcvf_base.h | 132 +++++++++++++++
2 files changed, 476 insertions(+)
create mode 100644 drivers/vhost/ifcvf/ifcvf_base.c
create mode 100644 drivers/vhost/ifcvf/ifcvf_base.h

diff --git a/drivers/vhost/ifcvf/ifcvf_base.c b/drivers/vhost/ifcvf/ifcvf_base.c
new file mode 100644
index 0000000..0659f41
--- /dev/null
+++ b/drivers/vhost/ifcvf/ifcvf_base.c
@@ -0,0 +1,344 @@

<snip>

+ while (pos) {
+ ret = ifcvf_read_config_range(dev, (u32 *)&cap,
+ sizeof(cap), pos);
+
+ if (ret < 0) {
+ IFC_ERR(&dev->dev, "Failed to get PCI capability at %x",

Missing a \n on the message.

+ pos);
+ break;
+ }
+
+ if (cap.cap_vndr != PCI_CAP_ID_VNDR)
+ goto next;
+
+ IFC_DBG(&dev->dev, "read PCI config: config type: %u, PCI bar: %u,\
+ PCI bar offset: %u, PCI config len: %u.\n",

Really do not continue strings in this way. Again, just start the format on the second line and let it be as long as it needs to be. Also drop the . on the end of the log messages (there are many in this patch).

+ cap.cfg_type, cap.bar, cap.offset, cap.length);

<snip>

+ hw->lm_cfg = hw->mem_resource[IFCVF_LM_BAR].addr;
+
+ IFC_DBG(&dev->dev, "PCI capability mapping: common cfg: %p,\
+ notify base: %p\n, isr cfg: %p, device cfg: %p,\
+ multiplier: %u\n",

Another continued long format string to go onto one line.

+ hw->common_cfg, hw->notify_base, hw->isr,
+ hw->net_cfg, hw->notify_off_multiplier);
+
+ return 0;
+}
+
+u8 ifcvf_get_status(struct ifcvf_hw *hw)
+{
+ u8 old_gen, new_gen, status;
+
+ do {
+ old_gen = ioread8(&hw->common_cfg->config_generation);
+ status = ioread8(&hw->common_cfg->device_status);
+ new_gen = ioread8(&hw->common_cfg->config_generation);
+ } while (old_gen != new_gen);
+
+ return status;
+}
+
+void ifcvf_set_status(struct ifcvf_hw *hw, u8 status)
+{
+ iowrite8(status, &hw->common_cfg->device_status);
+}
+
+void ifcvf_reset(struct ifcvf_hw *hw)
+{
+ ifcvf_set_status(hw, 0);
+ ifcvf_get_status(hw);
+}
+
+static void ifcvf_add_status(struct ifcvf_hw *hw, u8 status)
+{
+ if (status != 0)
+ status |= ifcvf_get_status(hw);
+
+ ifcvf_set_status(hw, status);
+ ifcvf_get_status(hw);
+}
+
+u64 ifcvf_get_features(struct ifcvf_hw *hw)
+{
+ struct virtio_pci_common_cfg *cfg = hw->common_cfg;
+ u32 features_lo, features_hi;
+
+ iowrite32(0, &cfg->device_feature_select);
+ features_lo = ioread32(&cfg->device_feature);
+
+ iowrite32(1, &cfg->device_feature_select);
+ features_hi = ioread32(&cfg->device_feature);
+
+ return ((u64)features_hi << 32) | features_lo;
+}
+
+void ifcvf_read_net_config(struct ifcvf_hw *hw, u64 offset,
+ void *dst, int length)
+{
+ u8 old_gen, new_gen, *p;
+ int i;
+
+ WARN_ON(offset + length > sizeof (struct ifcvf_net_config));
+
+ do {
+ old_gen = ioread8(&hw->common_cfg->config_generation);
+ p = dst;
+
+ for (i = 0; i < length; i++)
+ *p++ = ioread8((u8 *)hw->net_cfg + offset + i);
+
+ new_gen = ioread8(&hw->common_cfg->config_generation);
+ } while (old_gen != new_gen);
+}
+
+void ifcvf_write_net_config(struct ifcvf_hw *hw, u64 offset,
+ const void *src, int length)
+{
+ const u8 *p;
+ int i;
+
+ p = src;
+ WARN_ON(offset + length > sizeof (struct ifcvf_net_config));

No space after sizeof.

<snip>

--
Mark Rustad, MRustad@xxxxxxxxx

Attachment: signature.asc
Description: Message signed with OpenPGP