From nobody Wed Nov 27 02:31:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1702002858; cv=none; d=zohomail.com; s=zohoarc; b=K5DBRXiOiUQ2CvKb34ZqXrMQ776Sg2MKyBtpWPkL9oyC+eA2GotsDXCFAaJxpzCoNpAfcyFcy0BawBSr4A6wDnzrW9oWMlccO1/O3zapFbWfIpXG1cnUYjg1tXk3xc+ua6FILBO8Ofmy3UIBGoh2oyezuQPCpfyilvLOGA8PCso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702002858; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eoic2SJMSZx65HVKTXZRhdGUrx/jLGrSNvb3iX2VkKs=; b=fxePJFPCPt4HuXysLcqi/D45uRxBtVnJRa3ErxyeoYmKORWjHnMRIwnVKr+72qfpHNaRV9mcfhz2SmkQbCX+uNvjIQ9R4j08C95SInpAH6AJloVPzH0gA2NuKaPbjuO0+x76M6TxtZTNYIeeISqeWw/oyLNwaHN7pDuGbiKcUQ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1702002858425784.7606829160983; Thu, 7 Dec 2023 18:34:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rBQg9-00050f-LI; Thu, 07 Dec 2023 21:33:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rBQfx-0004jt-Dh; Thu, 07 Dec 2023 21:33:14 -0500 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rBQfv-0002ZJ-FN; Thu, 07 Dec 2023 21:33:13 -0500 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2ca0c36f5beso20174161fa.1; Thu, 07 Dec 2023 18:33:10 -0800 (PST) Received: from localhost.localdomain ([185.200.240.39]) by smtp.gmail.com with ESMTPSA id r1-20020a2e94c1000000b002c9e6cbf78esm99062ljh.19.2023.12.07.18.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 18:33:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702002789; x=1702607589; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eoic2SJMSZx65HVKTXZRhdGUrx/jLGrSNvb3iX2VkKs=; b=ZG39J1MlyDwrnzirb/x/guimj4OGilXw/bSPQcG4WbEPAYduU2gUJ+yxATGN8BAsUX I1L5RJcVzHXPTjGRaAH5h4yCFRXHTywm8y+id+HU0Hoyx52NGn0YetpGIJHxkgS/0Fxx S4JNiLblmXaSqoSkDNXrdLnyY/bwZj8RW7iRAIUKJrraJb2ttp+ohzMs1jWC0qB1TmSX DSOPddjWI3wGHsLG+8Kw1Aje7ws83zvBDTbAy1BKFflPTVGUFYy4TqNXFX+B6OZXl8JP kcPHo0eqhbELxwg6WosEBGCloLc6/3212tK+o6HDAix/+G8l6uX3/HwdGAos8XuvgTA7 YfOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702002789; x=1702607589; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eoic2SJMSZx65HVKTXZRhdGUrx/jLGrSNvb3iX2VkKs=; b=tx/rQUOZCoGtOU6JX4cmLRy1Y3+s3eLlrNEaTSgCbMsI5Kipi5lqllvXnXIBOcBXnV 59U4ENsoNABIbAmvBCyWB+LkuU63t2GARkelGcwvnqWR2LAqMxlSBiF0zZg7RndFVAqP 4QBLY2UeU2nHr0CfU5vegklXLbrbYiA7Z79yStWdL+0iWUrqzTmJUPEfNWZsBN+s6BLO cud9Jd2gAoCe0erTj3daN1DFP62vni0dFXCnYuGOMXuvILNrLFXjD8rPPuu8VOrsfHnW pm7DjHTZyeuutjex0DAKsJ2SeMNASyPvSUP4MmCpO4clhke9bz2QfgYby2w2BRDsQggN gD3A== X-Gm-Message-State: AOJu0Yx6i1mJ1GpE4XxmQAAj6niUfR+d8Vm/4nQ108fJnw7AP73IevyE o6w5TfkunP1GtvH4thEPq7CoZ2O6WHP07g== X-Google-Smtp-Source: AGHT+IE9VUtlD2ChviNiIngBzIbBxa5crwFWnVUzpNR91BkdAr7QTQxHiO8UfuHGCg7X7FzyAPKDkg== X-Received: by 2002:a2e:6a19:0:b0:2ca:17ce:23d7 with SMTP id f25-20020a2e6a19000000b002ca17ce23d7mr2103972ljc.95.1702002788988; Thu, 07 Dec 2023 18:33:08 -0800 (PST) From: Sergey Kambalin X-Google-Original-From: Sergey Kambalin To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, Sergey Kambalin Subject: [PATCH v4 22/45] Add GENET stub Date: Thu, 7 Dec 2023 20:31:22 -0600 Message-Id: <20231208023145.1385775-23-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231208023145.1385775-1-sergey.kambalin@auriga.com> References: <20231208023145.1385775-1-sergey.kambalin@auriga.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::230; envelope-from=serg.oker@gmail.com; helo=mail-lj1-x230.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1702002859094100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Sergey Kambalin --- hw/misc/bcm2838_thermal.c | 2 +- hw/net/bcm2838_genet.c | 99 ++++++++++++++++++++++++++++++++++ hw/net/meson.build | 2 + hw/net/trace-events | 16 ++++++ include/hw/net/bcm2838_genet.h | 40 ++++++++++++++ 5 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 hw/net/bcm2838_genet.c create mode 100644 include/hw/net/bcm2838_genet.h diff --git a/hw/misc/bcm2838_thermal.c b/hw/misc/bcm2838_thermal.c index 2301f657d0..372962b9ba 100644 --- a/hw/misc/bcm2838_thermal.c +++ b/hw/misc/bcm2838_thermal.c @@ -80,7 +80,7 @@ static void bcm2838_thermal_class_init(ObjectClass *klass= , void *data) =20 dc->realize =3D bcm2838_thermal_realize; =20 - /* This device has no state: no need for vmstate or reset */ + /* This device has nothing to save: no need for vmstate or reset */ } =20 static const TypeInfo bcm2838_thermal_info =3D { diff --git a/hw/net/bcm2838_genet.c b/hw/net/bcm2838_genet.c new file mode 100644 index 0000000000..4420486e00 --- /dev/null +++ b/hw/net/bcm2838_genet.c @@ -0,0 +1,99 @@ +/* + * BCM2838 Gigabit Ethernet emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qemu/log.h" +#include "qemu/error-report.h" +#include "net/eth.h" +#include "qapi/error.h" +#include "hw/irq.h" +#include "net/checksum.h" +#include "sysemu/dma.h" +#include "hw/net/bcm2838_genet.h" +#include "trace.h" + + +static uint64_t bcm2838_genet_read(void *opaque, hwaddr offset, unsigned s= ize) +{ + uint64_t value =3D ~0; + + qemu_log_mask( + LOG_GUEST_ERROR, + "%s: out-of-range access, %u bytes @ offset 0x%04" PRIx64 "\n", + __func__, size, offset); + + trace_bcm2838_genet_read(size, offset, value); + return value; +} + +static void bcm2838_genet_write(void *opaque, hwaddr offset, uint64_t valu= e, + unsigned size) { + qemu_log_mask( + LOG_GUEST_ERROR, + "%s: out-of-range access, %u bytes @ offset 0x%04" PRIx64 "\n", + __func__, size, offset); +} + +static const MemoryRegionOps bcm2838_genet_ops =3D { + .read =3D bcm2838_genet_read, + .write =3D bcm2838_genet_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D {.max_access_size =3D 4}, + .valid =3D {.min_access_size =3D 4}, +}; + + +static void bcm2838_genet_realize(DeviceState *dev, Error **errp) +{ + BCM2838GenetState *s =3D BCM2838_GENET(dev); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); + + /* Controller registers */ + memory_region_init_io(&s->regs_mr, OBJECT(s), &bcm2838_genet_ops, s, + "bcm2838_genet_regs", sizeof(s->regs)); + sysbus_init_mmio(sbd, &s->regs_mr); +} + +static void bcm2838_genet_phy_reset(BCM2838GenetState *s) +{ + trace_bcm2838_genet_phy_reset("done"); +} + +static void bcm2838_genet_reset(DeviceState *d) +{ + BCM2838GenetState *s =3D BCM2838_GENET(d); + + memset(&s->regs, 0x00, sizeof(s->regs)); + + trace_bcm2838_genet_reset("done"); + + bcm2838_genet_phy_reset(s); +} + +static void bcm2838_genet_class_init(ObjectClass *class, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(class); + + dc->realize =3D bcm2838_genet_realize; + dc->reset =3D bcm2838_genet_reset; +} + +static const TypeInfo bcm2838_genet_info =3D { + .name =3D TYPE_BCM2838_GENET, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(BCM2838GenetState), + .class_init =3D bcm2838_genet_class_init, +}; + +static void bcm2838_genet_register(void) +{ + type_register_static(&bcm2838_genet_info); +} + +type_init(bcm2838_genet_register) diff --git a/hw/net/meson.build b/hw/net/meson.build index f64651c467..d513a8d029 100644 --- a/hw/net/meson.build +++ b/hw/net/meson.build @@ -72,4 +72,6 @@ system_ss.add(when: 'CONFIG_ROCKER', if_true: files( system_ss.add(when: 'CONFIG_ALL', if_true: files('rocker/qmp-norocker.c')) system_ss.add(files('rocker/rocker-hmp-cmds.c')) =20 +system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2838_genet.c')) + subdir('can') diff --git a/hw/net/trace-events b/hw/net/trace-events index 387e32e153..4081bd09d6 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -494,3 +494,19 @@ xen_netdev_connect(int dev, unsigned int tx, unsigned = int rx, int port) "vif%u t xen_netdev_frontend_changed(const char *dev, int state) "vif%s state %d" xen_netdev_tx(int dev, int ref, int off, int len, unsigned int flags, cons= t char *c, const char *d, const char *m, const char *e) "vif%u ref %u off %= u len %u flags 0x%x%s%s%s%s" xen_netdev_rx(int dev, int idx, int status, int flags) "vif%u idx %d statu= s %d flags 0x%x" +# bcm2838_genet.c +bcm2838_genet_read(unsigned int size, uint64_t offset, uint64_t value) "%u= bytes @ 0x%04" PRIx64 ": 0x%016" PRIx64 +bcm2838_genet_write(unsigned int size, uint64_t offset, uint64_t value) "%= u bytes @ 0x%04" PRIx64 ": 0x%016" PRIx64 +bcm2838_genet_can_receive(const char *state) "receive is %s" +bcm2838_genet_receive(ssize_t bytes_received) "%zd bytes received" +bcm2838_genet_phy_update_link(const char *link_state) "link is %s" +bcm2838_genet_phy_reset(const char *status) "PHY reset %s" +bcm2838_genet_reset(const char *status) "MAC reset %s" +bcm2838_genet_mac_address(const char *info) "%s" +bcm2838_genet_tx_dma(const char *dma_state) "TX DMA %s" +bcm2838_genet_tx_dma_ring(uint32_t ring_en) "TX DMA enabled rings: 0x%05x" +bcm2838_genet_tx_dma_ring_buf(uint32_t ring_buf_en) "TX DMA enabled ring b= uffers: 0x%05x" +bcm2838_genet_tx_dma_ring_active(unsigned int ring, const char *ring_state= ) "ring %u is %s" +bcm2838_genet_tx_request(unsigned int ring_idx, uint32_t prod_idx, uint32_= t cons_idx) "ring %u, PROD_INDEX %u, CONS_INDEX %u" +bcm2838_genet_tx(unsigned int ring_idx, uint64_t desc_idx, uint32_t desc_s= tatus, uint64_t data_addr) "ring %u, descriptor %" PRIu64 ": 0x%08x, data @= 0x%08" PRIx64 +bcm2838_genet_rx_dma_ring_active(unsigned int ring, const char *ring_state= ) "ring %u is %s" diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h new file mode 100644 index 0000000000..d166a5c24c --- /dev/null +++ b/include/hw/net/bcm2838_genet.h @@ -0,0 +1,40 @@ +/* + * BCM2838 Gigabit Ethernet emulation + * + * Copyright (C) 2022 Ovchinnikov Vitalii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef BCM2838_GENET_H +#define BCM2838_GENET_H + +#include "net/net.h" +#include "hw/sysbus.h" + +#define TYPE_BCM2838_GENET "bcm2838-genet" +OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GenetState, BCM2838_GENET) + +#define BCM2838_GENET_REV_MAJOR 6 +#define BCM2838_GENET_REV_MINOR 0 + +typedef struct { + uint8_t stub_area[0x10000]; /* temporary stub */ +} BCM2838GenetRegs; + +struct BCM2838GenetState { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + + MemoryRegion regs_mr; + AddressSpace dma_as; + + BCM2838GenetRegs regs; + + qemu_irq irq_default; + qemu_irq irq_prio; +}; + +#endif /* BCM2838_GENET_H */ --=20 2.34.1