From nobody Sun Apr 6 22:18:24 2025 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1735921188; cv=none; d=zohomail.com; s=zohoarc; b=WNdO4x8wLzjRNXXfsfHf7BvIAYEoOmMrunVQLvErmuPPWVT2tt0a/UTgMeXA1Y3LjbLhwxwcXZyNwdXhmaiYslApn8HtJIkiD6K+WBiikNUw/LAs3NwAWk6ug5svHxSI4YB2KcRQnBNcd5fMGW4zuHNyxiuFdMN4nLiovOHXGQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1735921188; 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=CuDHuDyJo61Bht/Frh3EbeppFefMiMEU8rDVGG5Ba2o=; b=G5iEW1v90UlFqm4SGsvlRU/4x2SdugWd77pBbC5v0Ih6dLi/6FP4BvsoaDnjMhxzD4a5m+M6BkWcV+m7929lNaAGu14vAaaWnvCgQt6Ji5nYwMMql8x1KtNrZkXoWrXMqpwnj9044QXsSYbB9hW192ylwPH9AogkykL9f+KYgsI= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1735921188270801.6513969764407; Fri, 3 Jan 2025 08:19:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTkO8-0005aM-Sf; Fri, 03 Jan 2025 11:19:04 -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 1tTkO7-0005ZI-Vq; Fri, 03 Jan 2025 11:19:04 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tTkO5-0001Yg-3Y; Fri, 03 Jan 2025 11:19:03 -0500 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50385nm9003848; Fri, 3 Jan 2025 16:18:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43xc32spqk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:18:51 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 503GIoTF006302; Fri, 3 Jan 2025 16:18:50 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43xc32spqf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:18:50 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 503FP3Gk014064; Fri, 3 Jan 2025 16:18:50 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 43tv1yf0yn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:18:49 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 503GIkZ421627534 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Jan 2025 16:18:46 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DFD5A2004D; Fri, 3 Jan 2025 16:18:45 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A5D5020040; Fri, 3 Jan 2025 16:18:43 +0000 (GMT) Received: from gfwr515.rchland.ibm.com (unknown [9.10.239.103]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 3 Jan 2025 16:18:43 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=CuDHuDyJo61Bht/Fr h3EbeppFefMiMEU8rDVGG5Ba2o=; b=fNEG5hsrReYqg0NmQ8MQnSoyU2dI/N7v6 r7v2jY3KSDbG/VCl69XXctMF2gDHj4ebzToiqXmxwRAmxRvVDwQUN+KoN4ZtSM8G WeDIINB7H3mTdhMRDuYmJYZP5d/qrmiUUIHSmspmF70FS28cTgBiZZ4Bg1iCAcIR FYTgwpIjG3GJDDMA9IDKmNnfQCekwT0L2Ld11uSeJMue2RFtbXlzzMAnffPJLDK1 /4OjNHlz/8YFAglybPWbt+Of7Kpq6ztT/W5t46m66ra0nx+QSQ0w5OFMeXfQ+8p0 B+qblrhQv414mQNapPOlv2vJ7XVdPnQoyzDj21B8td3pVQGFZOahg== From: Chalapathi V To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, fbarrat@linux.ibm.com, npiggin@gmail.com, clg@kaod.org, calebs@linux.ibm.com, chalapathi.v@ibm.com, chalapathi.v@linux.ibm.com, saif.abrar@linux.ibm.com, dantan@linux.vnet.ibm.com, milesg@linux.ibm.com, philmd@linaro.org, alistair@alistair23.me Subject: [PATCH v5 1/4] hw/ssi/pnv_spi: Replace PnvXferBuffer with Fifo8 structure Date: Fri, 3 Jan 2025 10:18:21 -0600 Message-Id: <20250103161824.22469-2-chalapathi.v@linux.ibm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250103161824.22469-1-chalapathi.v@linux.ibm.com> References: <20250103161824.22469-1-chalapathi.v@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: u8RaeZotQErEhqr5D63CjD73JOkHZYMb X-Proofpoint-ORIG-GUID: z2LPNJzYKZnL7MBVqKD7yEUheBNQh8GB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 phishscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501030137 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=148.163.158.5; envelope-from=chalapathi.v@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ibm.com) X-ZM-MESSAGEID: 1735921190419116600 Content-Type: text/plain; charset="utf-8" In PnvXferBuffer dynamically allocating and freeing is a process overhead. Hence used an existing Fifo8 buffer with capacity of 16 bytes. Signed-off-by: Chalapathi V --- include/hw/ssi/pnv_spi.h | 3 + hw/ssi/pnv_spi.c | 237 +++++++++++++-------------------------- 2 files changed, 81 insertions(+), 159 deletions(-) diff --git a/include/hw/ssi/pnv_spi.h b/include/hw/ssi/pnv_spi.h index 8815f67d45..9878d9a25f 100644 --- a/include/hw/ssi/pnv_spi.h +++ b/include/hw/ssi/pnv_spi.h @@ -23,6 +23,7 @@ =20 #include "hw/ssi/ssi.h" #include "hw/sysbus.h" +#include "qemu/fifo8.h" =20 #define TYPE_PNV_SPI "pnv-spi" OBJECT_DECLARE_SIMPLE_TYPE(PnvSpi, PNV_SPI) @@ -37,6 +38,8 @@ typedef struct PnvSpi { SSIBus *ssi_bus; qemu_irq *cs_line; MemoryRegion xscom_spic_regs; + Fifo8 tx_fifo; + Fifo8 rx_fifo; /* SPI object number */ uint32_t spic_num; uint8_t transfer_len; diff --git a/hw/ssi/pnv_spi.c b/hw/ssi/pnv_spi.c index 15e25bd1be..63d298980d 100644 --- a/hw/ssi/pnv_spi.c +++ b/hw/ssi/pnv_spi.c @@ -19,6 +19,7 @@ =20 #define PNV_SPI_OPCODE_LO_NIBBLE(x) (x & 0x0F) #define PNV_SPI_MASKED_OPCODE(x) (x & 0xF0) +#define PNV_SPI_FIFO_SIZE 16 =20 /* * Macro from include/hw/ppc/fdt.h @@ -35,48 +36,14 @@ } \ } while (0) =20 -/* PnvXferBuffer */ -typedef struct PnvXferBuffer { - - uint32_t len; - uint8_t *data; - -} PnvXferBuffer; - -/* pnv_spi_xfer_buffer_methods */ -static PnvXferBuffer *pnv_spi_xfer_buffer_new(void) -{ - PnvXferBuffer *payload =3D g_malloc0(sizeof(*payload)); - - return payload; -} - -static void pnv_spi_xfer_buffer_free(PnvXferBuffer *payload) -{ - g_free(payload->data); - g_free(payload); -} - -static uint8_t *pnv_spi_xfer_buffer_write_ptr(PnvXferBuffer *payload, - uint32_t offset, uint32_t length) -{ - if (payload->len < (offset + length)) { - payload->len =3D offset + length; - payload->data =3D g_realloc(payload->data, payload->len); - } - return &payload->data[offset]; -} - static bool does_rdr_match(PnvSpi *s) { /* * According to spec, the mask bits that are 0 are compared and the * bits that are 1 are ignored. */ - uint16_t rdr_match_mask =3D GETFIELD(SPI_MM_RDR_MATCH_MASK, - s->regs[SPI_MM_REG]); - uint16_t rdr_match_val =3D GETFIELD(SPI_MM_RDR_MATCH_VAL, - s->regs[SPI_MM_REG]); + uint16_t rdr_match_mask =3D GETFIELD(SPI_MM_RDR_MATCH_MASK, s->regs[SP= I_MM_REG]); + uint16_t rdr_match_val =3D GETFIELD(SPI_MM_RDR_MATCH_VAL, s->regs[SPI_= MM_REG]); =20 if ((~rdr_match_mask & rdr_match_val) =3D=3D ((~rdr_match_mask) & GETFIELD(PPC_BITMASK(48, 63), s->regs[SPI_RCV_DATA_REG]))) { @@ -107,8 +74,8 @@ static uint8_t get_from_offset(PnvSpi *s, uint8_t offset) return byte; } =20 -static uint8_t read_from_frame(PnvSpi *s, uint8_t *read_buf, uint8_t nr_by= tes, - uint8_t ecc_count, uint8_t shift_in_count) +static uint8_t read_from_frame(PnvSpi *s, uint8_t nr_bytes, uint8_t ecc_co= unt, + uint8_t shift_in_count) { uint8_t byte; int count =3D 0; @@ -118,20 +85,23 @@ static uint8_t read_from_frame(PnvSpi *s, uint8_t *rea= d_buf, uint8_t nr_bytes, if ((ecc_count !=3D 0) && (shift_in_count =3D=3D (PNV_SPI_REG_SIZE + ecc_count))) { shift_in_count =3D 0; - } else { - byte =3D read_buf[count]; + } else if (!fifo8_is_empty(&s->rx_fifo)) { + byte =3D fifo8_pop(&s->rx_fifo); trace_pnv_spi_shift_rx(byte, count); s->regs[SPI_RCV_DATA_REG] =3D (s->regs[SPI_RCV_DATA_REG] << 8)= | byte; + } else { + qemu_log_mask(LOG_GUEST_ERROR, "pnv_spi: Reading empty RX_FIFO= \n"); } count++; } /* end of while */ return shift_in_count; } =20 -static void spi_response(PnvSpi *s, int bits, PnvXferBuffer *rsp_payload) +static void spi_response(PnvSpi *s) { uint8_t ecc_count; uint8_t shift_in_count; + uint32_t rx_len; =20 /* * Processing here must handle: @@ -144,13 +114,14 @@ static void spi_response(PnvSpi *s, int bits, PnvXfer= Buffer *rsp_payload) * First check that the response payload is the exact same * number of bytes as the request payload was */ - if (rsp_payload->len !=3D (s->N1_bytes + s->N2_bytes)) { + rx_len =3D fifo8_num_used(&s->rx_fifo); + if (rx_len !=3D (s->N1_bytes + s->N2_bytes)) { qemu_log_mask(LOG_GUEST_ERROR, "Invalid response payload size in " "bytes, expected %d, got %d\n", - (s->N1_bytes + s->N2_bytes), rsp_payload->len); + (s->N1_bytes + s->N2_bytes), rx_len); } else { uint8_t ecc_control; - trace_pnv_spi_rx_received(rsp_payload->len); + trace_pnv_spi_rx_received(rx_len); trace_pnv_spi_log_Ncounts(s->N1_bits, s->N1_bytes, s->N1_tx, s->N1_rx, s->N2_bits, s->N2_bytes, s->N2_tx, s->N2= _rx); /* @@ -175,15 +146,12 @@ static void spi_response(PnvSpi *s, int bits, PnvXfer= Buffer *rsp_payload) /* Handle the N1 portion of the frame first */ if (s->N1_rx !=3D 0) { trace_pnv_spi_rx_read_N1frame(); - shift_in_count =3D read_from_frame(s, &rsp_payload->data[0], - s->N1_bytes, ecc_count, shift_in_count); + shift_in_count =3D read_from_frame(s, s->N1_bytes, ecc_count, = shift_in_count); } /* Handle the N2 portion of the frame */ if (s->N2_rx !=3D 0) { trace_pnv_spi_rx_read_N2frame(); - shift_in_count =3D read_from_frame(s, - &rsp_payload->data[s->N1_bytes], s->N2_bytes, - ecc_count, shift_in_count); + shift_in_count =3D read_from_frame(s, s->N2_bytes, ecc_count, = shift_in_count); } if ((s->N1_rx + s->N2_rx) > 0) { /* @@ -210,36 +178,38 @@ static void spi_response(PnvSpi *s, int bits, PnvXfer= Buffer *rsp_payload) } /* end of else */ } /* end of spi_response() */ =20 -static void transfer(PnvSpi *s, PnvXferBuffer *payload) +static void transfer(PnvSpi *s) { - uint32_t tx; - uint32_t rx; - PnvXferBuffer *rsp_payload =3D NULL; + uint32_t tx, rx, payload_len; + uint8_t rx_byte; =20 - rsp_payload =3D pnv_spi_xfer_buffer_new(); - if (!rsp_payload) { - return; - } - for (int offset =3D 0; offset < payload->len; offset +=3D s->transfer_= len) { + payload_len =3D fifo8_num_used(&s->tx_fifo); + for (int offset =3D 0; offset < payload_len; offset +=3D s->transfer_l= en) { tx =3D 0; for (int i =3D 0; i < s->transfer_len; i++) { - if ((offset + i) >=3D payload->len) { + if ((offset + i) >=3D payload_len) { tx <<=3D 8; + } else if (!fifo8_is_empty(&s->tx_fifo)) { + tx =3D (tx << 8) | fifo8_pop(&s->tx_fifo); } else { - tx =3D (tx << 8) | payload->data[offset + i]; + qemu_log_mask(LOG_GUEST_ERROR, "pnv_spi: TX_FIFO underflow= \n"); } } rx =3D ssi_transfer(s->ssi_bus, tx); for (int i =3D 0; i < s->transfer_len; i++) { - if ((offset + i) >=3D payload->len) { + if (((offset + i) >=3D payload_len) || fifo8_is_full(&s->rx_fi= fo)) { break; } - *(pnv_spi_xfer_buffer_write_ptr(rsp_payload, rsp_payload->len,= 1)) =3D - (rx >> (8 * (s->transfer_len - 1) - i * 8)) & 0xFF; + rx_byte =3D (rx >> (8 * (s->transfer_len - 1) - i * 8)) & 0xFF; + if (!fifo8_is_full(&s->rx_fifo)) { + fifo8_push(&s->rx_fifo, rx_byte); + } } } - spi_response(s, s->N1_bits, rsp_payload); - pnv_spi_xfer_buffer_free(rsp_payload); + spi_response(s); + /* Reset fifo for next frame */ + fifo8_reset(&s->tx_fifo); + fifo8_reset(&s->rx_fifo); } =20 static inline uint8_t get_seq_index(PnvSpi *s) @@ -310,13 +280,11 @@ static void calculate_N1(PnvSpi *s, uint8_t opcode) * If Forced Implicit mode and count control doesn't * indicate transmit then reset the tx count to 0 */ - if (GETFIELD(SPI_CTR_CFG_N1_CTRL_B2, - s->regs[SPI_CTR_CFG_REG]) =3D=3D 0) { + if (GETFIELD(SPI_CTR_CFG_N1_CTRL_B2, s->regs[SPI_CTR_CFG_REG])= =3D=3D 0) { s->N1_tx =3D 0; } /* If rx count control for N1 is set, load the rx value */ - if (GETFIELD(SPI_CTR_CFG_N1_CTRL_B3, - s->regs[SPI_CTR_CFG_REG]) =3D=3D 1) { + if (GETFIELD(SPI_CTR_CFG_N1_CTRL_B3, s->regs[SPI_CTR_CFG_REG])= =3D=3D 1) { s->N1_rx =3D s->N1_bytes; } } @@ -328,8 +296,7 @@ static void calculate_N1(PnvSpi *s, uint8_t opcode) * cap the size at a max of 64 bits or 72 bits and set the sequencer F= SM * error bit. */ - uint8_t ecc_control =3D GETFIELD(SPI_CLK_CFG_ECC_CTRL, - s->regs[SPI_CLK_CFG_REG]); + uint8_t ecc_control =3D GETFIELD(SPI_CLK_CFG_ECC_CTRL, s->regs[SPI_CLK= _CFG_REG]); if (ecc_control =3D=3D 0 || ecc_control =3D=3D 2) { if (s->N1_bytes > (PNV_SPI_REG_SIZE + 1)) { qemu_log_mask(LOG_GUEST_ERROR, "Unsupported N1 shift size when= " @@ -340,8 +307,7 @@ static void calculate_N1(PnvSpi *s, uint8_t opcode) } } else if (s->N1_bytes > PNV_SPI_REG_SIZE) { qemu_log_mask(LOG_GUEST_ERROR, "Unsupported N1 shift size, " - "bytes =3D 0x%x, bits =3D 0x%x\n", - s->N1_bytes, s->N1_bits); + "bytes =3D 0x%x, bits =3D 0x%x\n", s->N1_bytes, s->N= 1_bits); s->N1_bytes =3D PNV_SPI_REG_SIZE; s->N1_bits =3D s->N1_bytes * 8; } @@ -350,19 +316,10 @@ static void calculate_N1(PnvSpi *s, uint8_t opcode) /* * Shift_N1 operation handler method */ -static bool operation_shiftn1(PnvSpi *s, uint8_t opcode, - PnvXferBuffer **payload, bool send_n1_alone) +static bool operation_shiftn1(PnvSpi *s, uint8_t opcode, bool send_n1_alon= e) { uint8_t n1_count; bool stop =3D false; - - /* - * If there isn't a current payload left over from a stopped sequence - * create a new one. - */ - if (*payload =3D=3D NULL) { - *payload =3D pnv_spi_xfer_buffer_new(); - } /* * Use a combination of N1 counters to build the N1 portion of the * transmit payload. @@ -413,9 +370,10 @@ static bool operation_shiftn1(PnvSpi *s, uint8_t opcod= e, */ uint8_t n1_byte =3D 0x00; n1_byte =3D get_from_offset(s, n1_count); - trace_pnv_spi_tx_append("n1_byte", n1_byte, n1_count); - *(pnv_spi_xfer_buffer_write_ptr(*payload, (*payload)->len,= 1)) =3D - n1_byte; + if (!fifo8_is_full(&s->tx_fifo)) { + trace_pnv_spi_tx_append("n1_byte", n1_byte, n1_count); + fifo8_push(&s->tx_fifo, n1_byte); + } } else { /* * We hit a shift_n1 opcode TX but the TDR is empty, tell = the @@ -436,16 +394,14 @@ static bool operation_shiftn1(PnvSpi *s, uint8_t opco= de, * - we are receiving and the RDR is empty so we allow the ope= ration * to proceed. */ - if ((s->N1_rx !=3D 0) && (GETFIELD(SPI_STS_RDR_FULL, - s->status) =3D=3D 1)) { + if ((s->N1_rx !=3D 0) && (GETFIELD(SPI_STS_RDR_FULL, s->status= ) =3D=3D 1)) { trace_pnv_spi_sequencer_stop_requested("shift N1" "set for receive but RDR is full"); stop =3D true; break; - } else { + } else if (!fifo8_is_full(&s->tx_fifo)) { trace_pnv_spi_tx_append_FF("n1_byte"); - *(pnv_spi_xfer_buffer_write_ptr(*payload, (*payload)->len,= 1)) - =3D 0xff; + fifo8_push(&s->tx_fifo, 0xff); } } n1_count++; @@ -486,15 +442,13 @@ static bool operation_shiftn1(PnvSpi *s, uint8_t opco= de, */ if (send_n1_alone && !stop) { /* We have a TX and a full TDR or an RX and an empty RDR */ - trace_pnv_spi_tx_request("Shifting N1 frame", (*payload)->len); - transfer(s, *payload); + trace_pnv_spi_tx_request("Shifting N1 frame", fifo8_num_used(&s->t= x_fifo)); + transfer(s); /* The N1 frame shift is complete so reset the N1 counters */ s->N2_bits =3D 0; s->N2_bytes =3D 0; s->N2_tx =3D 0; s->N2_rx =3D 0; - pnv_spi_xfer_buffer_free(*payload); - *payload =3D NULL; } return stop; } /* end of operation_shiftn1() */ @@ -552,13 +506,11 @@ static void calculate_N2(PnvSpi *s, uint8_t opcode) * If Forced Implicit mode and count control doesn't * indicate a receive then reset the rx count to 0 */ - if (GETFIELD(SPI_CTR_CFG_N2_CTRL_B3, - s->regs[SPI_CTR_CFG_REG]) =3D=3D 0) { + if (GETFIELD(SPI_CTR_CFG_N2_CTRL_B3, s->regs[SPI_CTR_CFG_REG])= =3D=3D 0) { s->N2_rx =3D 0; } /* If tx count control for N2 is set, load the tx value */ - if (GETFIELD(SPI_CTR_CFG_N2_CTRL_B2, - s->regs[SPI_CTR_CFG_REG]) =3D=3D 1) { + if (GETFIELD(SPI_CTR_CFG_N2_CTRL_B2, s->regs[SPI_CTR_CFG_REG])= =3D=3D 1) { s->N2_tx =3D s->N2_bytes; } } @@ -571,8 +523,7 @@ static void calculate_N2(PnvSpi *s, uint8_t opcode) * cap the size at a max of 64 bits or 72 bits and set the sequencer F= SM * error bit. */ - uint8_t ecc_control =3D GETFIELD(SPI_CLK_CFG_ECC_CTRL, - s->regs[SPI_CLK_CFG_REG]); + uint8_t ecc_control =3D GETFIELD(SPI_CLK_CFG_ECC_CTRL, s->regs[SPI_CLK= _CFG_REG]); if (ecc_control =3D=3D 0 || ecc_control =3D=3D 2) { if (s->N2_bytes > (PNV_SPI_REG_SIZE + 1)) { /* Unsupported N2 shift size when ECC enabled */ @@ -590,19 +541,10 @@ static void calculate_N2(PnvSpi *s, uint8_t opcode) * Shift_N2 operation handler method */ =20 -static bool operation_shiftn2(PnvSpi *s, uint8_t opcode, - PnvXferBuffer **payload) +static bool operation_shiftn2(PnvSpi *s, uint8_t opcode) { uint8_t n2_count; bool stop =3D false; - - /* - * If there isn't a current payload left over from a stopped sequence - * create a new one. - */ - if (*payload =3D=3D NULL) { - *payload =3D pnv_spi_xfer_buffer_new(); - } /* * Use a combination of N2 counters to build the N2 portion of the * transmit payload. @@ -629,44 +571,41 @@ static bool operation_shiftn2(PnvSpi *s, uint8_t opco= de, * code continue will end up building the payload twice in the same * buffer since RDR full causes a sequence stop and restart. */ - if ((s->N2_rx !=3D 0) && - (GETFIELD(SPI_STS_RDR_FULL, s->status) =3D=3D 1)) { + if ((s->N2_rx !=3D 0) && (GETFIELD(SPI_STS_RDR_FULL, s->status) = =3D=3D 1)) { trace_pnv_spi_sequencer_stop_requested("shift N2 set" "for receive but RDR is full"); stop =3D true; break; } - if ((s->N2_tx !=3D 0) && ((s->N1_tx + n2_count) < - PNV_SPI_REG_SIZE)) { + if ((s->N2_tx !=3D 0) && ((s->N1_tx + n2_count) < PNV_SPI_REG_SIZE= )) { /* Always append data for the N2 segment if it is set for TX */ uint8_t n2_byte =3D 0x00; n2_byte =3D get_from_offset(s, (s->N1_tx + n2_count)); - trace_pnv_spi_tx_append("n2_byte", n2_byte, (s->N1_tx + n2_cou= nt)); - *(pnv_spi_xfer_buffer_write_ptr(*payload, (*payload)->len, 1)) - =3D n2_byte; - } else { + if (!fifo8_is_full(&s->tx_fifo)) { + trace_pnv_spi_tx_append("n2_byte", n2_byte, (s->N1_tx + n2= _count)); + fifo8_push(&s->tx_fifo, n2_byte); + } + } else if (!fifo8_is_full(&s->tx_fifo)) { /* * Regardless of whether or not N2 is set for TX or RX, we need * the number of bytes in the payload to match the overall len= gth * of the operation. */ trace_pnv_spi_tx_append_FF("n2_byte"); - *(pnv_spi_xfer_buffer_write_ptr(*payload, (*payload)->len, 1)) - =3D 0xff; + fifo8_push(&s->tx_fifo, 0xff); } n2_count++; } /* end of while */ if (!stop) { /* We have a TX and a full TDR or an RX and an empty RDR */ - trace_pnv_spi_tx_request("Shifting N2 frame", (*payload)->len); - transfer(s, *payload); + trace_pnv_spi_tx_request("Shifting N2 frame", fifo8_num_used(&s->t= x_fifo)); + transfer(s); /* * If we are doing an N2 TX and the TDR is full we need to clear t= he * TDR_full status. Do this here instead of up in the loop above s= o we * don't log the message in every loop iteration. */ - if ((s->N2_tx !=3D 0) && - (GETFIELD(SPI_STS_TDR_FULL, s->status) =3D=3D 1)) { + if ((s->N2_tx !=3D 0) && (GETFIELD(SPI_STS_TDR_FULL, s->status) = =3D=3D 1)) { s->status =3D SETFIELD(SPI_STS_TDR_FULL, s->status, 0); } /* @@ -682,8 +621,6 @@ static bool operation_shiftn2(PnvSpi *s, uint8_t opcode, s->N1_bytes =3D 0; s->N1_tx =3D 0; s->N1_rx =3D 0; - pnv_spi_xfer_buffer_free(*payload); - *payload =3D NULL; } return stop; } /* end of operation_shiftn2()*/ @@ -701,19 +638,6 @@ static void operation_sequencer(PnvSpi *s) uint8_t opcode =3D 0; uint8_t masked_opcode =3D 0; =20 - /* - * PnvXferBuffer for containing the payload of the SPI frame. - * This is a static because there are cases where a sequence has to st= op - * and wait for the target application to unload the RDR. If this occ= urs - * during a sequence where N1 is not sent alone and instead combined w= ith - * N2 since the N1 tx length + the N2 tx length is less than the size = of - * the TDR. - */ - static PnvXferBuffer *payload; - - if (payload =3D=3D NULL) { - payload =3D pnv_spi_xfer_buffer_new(); - } /* * Clear the sequencer FSM error bit - general_SPI_status[3] * before starting a sequence. @@ -775,10 +699,8 @@ static void operation_sequencer(PnvSpi *s) s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, FSM= _DONE); } else if (s->responder_select !=3D 1) { qemu_log_mask(LOG_GUEST_ERROR, "Slave selection other than= 1 " - "not supported, select =3D 0x%x\n", - s->responder_select); - trace_pnv_spi_sequencer_stop_requested("invalid " - "responder select"); + "not supported, select =3D 0x%x\n", s->respo= nder_select); + trace_pnv_spi_sequencer_stop_requested("invalid responder = select"); s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, FSM= _IDLE); stop =3D true; } else { @@ -840,9 +762,8 @@ static void operation_sequencer(PnvSpi *s) =3D=3D SEQ_OP_SHIFT_N2) { send_n1_alone =3D false; } - s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, - FSM_SHIFT_N1); - stop =3D operation_shiftn1(s, opcode, &payload, send_n1_al= one); + s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, FSM= _SHIFT_N1); + stop =3D operation_shiftn1(s, opcode, send_n1_alone); if (stop) { /* * The operation code says to stop, this can occur if: @@ -858,7 +779,7 @@ static void operation_sequencer(PnvSpi *s) if (GETFIELD(SPI_STS_TDR_UNDERRUN, s->status)) { s->shift_n1_done =3D true; s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->sta= tus, - FSM_SHIFT_N2); + FSM_SHIFT_N2); s->status =3D SETFIELD(SPI_STS_SEQ_INDEX, s->statu= s, (get_seq_index(s) + 1)); } else { @@ -866,8 +787,7 @@ static void operation_sequencer(PnvSpi *s) * This is case (1) or (2) so the sequencer needs = to * wait and NOT go to the next sequence yet. */ - s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->sta= tus, - FSM_WAIT); + s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->sta= tus, FSM_WAIT); } } else { /* Ok to move on to the next index */ @@ -890,21 +810,18 @@ static void operation_sequencer(PnvSpi *s) * error bit 3 (general_SPI_status[3]) in status reg. */ s->status =3D SETFIELD(SPI_STS_GEN_STATUS_B3, s->status, 1= ); - trace_pnv_spi_sequencer_stop_requested("shift_n2 " - "w/no shift_n1 done"); + trace_pnv_spi_sequencer_stop_requested("shift_n2 w/no shif= t_n1 done"); stop =3D true; } else { /* Ok to do a Shift_N2 */ - s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, - FSM_SHIFT_N2); - stop =3D operation_shiftn2(s, opcode, &payload); + s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, FSM= _SHIFT_N2); + stop =3D operation_shiftn2(s, opcode); /* * If the operation code says to stop set the shifter stat= e to * wait and stop */ if (stop) { - s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, - FSM_WAIT); + s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status,= FSM_WAIT); } else { /* Ok to move on to the next index */ next_sequencer_fsm(s); @@ -988,8 +905,7 @@ static void operation_sequencer(PnvSpi *s) case SEQ_OP_BRANCH_IFNEQ_INC_2: s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_E= XECUTE); trace_pnv_spi_sequencer_op("BRANCH_IFNEQ_INC_2", get_seq_index= (s)); - uint8_t condition2 =3D GETFIELD(SPI_CTR_CFG_CMP2, - s->regs[SPI_CTR_CFG_REG]); + uint8_t condition2 =3D GETFIELD(SPI_CTR_CFG_CMP2, s->regs[SPI_= CTR_CFG_REG]); /* * The spec says the loop should execute count compare + 1 tim= es. * However we learned from engineering that we really only loop @@ -1209,6 +1125,9 @@ static void pnv_spi_realize(DeviceState *dev, Error *= *errp) s->cs_line =3D g_new0(qemu_irq, 1); qdev_init_gpio_out_named(DEVICE(s), s->cs_line, "cs", 1); =20 + fifo8_create(&s->tx_fifo, PNV_SPI_FIFO_SIZE); + fifo8_create(&s->rx_fifo, PNV_SPI_FIFO_SIZE); + /* spi scoms */ pnv_xscom_region_init(&s->xscom_spic_regs, OBJECT(s), &pnv_spi_xscom_o= ps, s, "xscom-spi", PNV10_XSCOM_PIB_SPIC_SIZE); --=20 2.39.5 From nobody Sun Apr 6 22:18:24 2025 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1735921233; cv=none; d=zohomail.com; s=zohoarc; b=MKYWhHFt4LMWtcD2zYQRgq1oSAy12X3Tn3X0AmvqLSx+GqPsSd/VoFZRqxm5++D7WKF8QIFOvKLR4atOH3KrXkxdv6uZZjdQHSGB/GlafdQtMV9T0UWDOmrcAzmgLF4xHRfwHJJOItAY9hAve26mFwe0bTkVnOVVAC/pAT1rTME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1735921233; 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=frlGmMKMy1zn6RXlIyljbnFZsq8GDAkaRT7v7Z1Yb+g=; b=XB48cZMruthClO0q9SUStGOTRXDO6VYfc0ZWEz2fhDUXAXVNUJ/Egc2pLq/qKulDW1O0zaFjPT6kVjaMEPPrRUPnAw9PGQx0QotZJVT6iSJzToNazTWnUwKWZxxflN+bayw3aZRgD7Tqc7huyt/Sf/PDeSBozV5W22WZVG/gEz8= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1735921233642962.8064913498399; Fri, 3 Jan 2025 08:20:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTkOG-0005dg-KW; Fri, 03 Jan 2025 11:19:12 -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 1tTkOE-0005dM-Vt; Fri, 03 Jan 2025 11:19:11 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tTkOC-0001Zq-PT; Fri, 03 Jan 2025 11:19:10 -0500 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 503FuAem017700; Fri, 3 Jan 2025 16:18:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43x8chakh7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:18:56 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 503GIu5L027175; Fri, 3 Jan 2025 16:18:56 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43x8chakgn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:18:55 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 503Bhri9004188; Fri, 3 Jan 2025 16:18:53 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 43twvk6qka-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:18:53 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 503GIndA62783854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Jan 2025 16:18:49 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3CCC2004D; Fri, 3 Jan 2025 16:18:49 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 95FD120040; Fri, 3 Jan 2025 16:18:47 +0000 (GMT) Received: from gfwr515.rchland.ibm.com (unknown [9.10.239.103]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 3 Jan 2025 16:18:47 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=frlGmMKMy1zn6RXlI yljbnFZsq8GDAkaRT7v7Z1Yb+g=; b=cHx1rNMK0mowG2j14+cR5Rx5yNagOroZ7 7IYM+DJxC5gq4pYW6AFGgiSm2rs4YuEw8amvM2xFVeNVJz6+WhQab6uVRc0J7NN/ h4/sEG6Z1JppGs1VsU8T5BeYhCH1pOvzDHbII+W/nVyq2jm96DOKryLmVtRaqCTx sHfRj55T9z3jCqo7N5jsPhFR8f5rVcqaYFIcLoVhvwJV7/fQMQwjz2jVds7UzYmY 0kUQ8a8RlslluBZ2wGcoxuR+kl07no/ShSe+Ij3mGDjfxJ6J8J3pRWLBWRvicFZK odCBliZ+JmQjyT2JVaZU47w35vinAeXHbXrJUM/bnZmbVT3l+2bPA== From: Chalapathi V To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, fbarrat@linux.ibm.com, npiggin@gmail.com, clg@kaod.org, calebs@linux.ibm.com, chalapathi.v@ibm.com, chalapathi.v@linux.ibm.com, saif.abrar@linux.ibm.com, dantan@linux.vnet.ibm.com, milesg@linux.ibm.com, philmd@linaro.org, alistair@alistair23.me Subject: [PATCH v5 2/4] hw/ssi/pnv_spi: Coverity CID 1558827: Use local var seq_index instead of get_seq_index(). Date: Fri, 3 Jan 2025 10:18:22 -0600 Message-Id: <20250103161824.22469-3-chalapathi.v@linux.ibm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250103161824.22469-1-chalapathi.v@linux.ibm.com> References: <20250103161824.22469-1-chalapathi.v@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: IOMMmtMP5qOsN5Reum_fsEbQhYUPfbT5 X-Proofpoint-GUID: KEIYGlRh67u3QYITwIVwkI7EyEKwYxyT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 spamscore=0 malwarescore=0 mlxlogscore=915 bulkscore=0 priorityscore=1501 lowpriorityscore=0 mlxscore=0 phishscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501030141 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=148.163.156.1; envelope-from=chalapathi.v@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ibm.com) X-ZM-MESSAGEID: 1735921264628116600 Content-Type: text/plain; charset="utf-8" Use a local variable seq_index instead of repeatedly calling get_seq_index() method and open-code next_sequencer_fsm(). Signed-off-by: Chalapathi V Reviewed-by: Nicholas Piggin --- hw/ssi/pnv_spi.c | 93 +++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/hw/ssi/pnv_spi.c b/hw/ssi/pnv_spi.c index 63d298980d..87eac666bb 100644 --- a/hw/ssi/pnv_spi.c +++ b/hw/ssi/pnv_spi.c @@ -212,18 +212,6 @@ static void transfer(PnvSpi *s) fifo8_reset(&s->rx_fifo); } =20 -static inline uint8_t get_seq_index(PnvSpi *s) -{ - return GETFIELD(SPI_STS_SEQ_INDEX, s->status); -} - -static inline void next_sequencer_fsm(PnvSpi *s) -{ - uint8_t seq_index =3D get_seq_index(s); - s->status =3D SETFIELD(SPI_STS_SEQ_INDEX, s->status, (seq_index + 1)); - s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_INDEX_INC= REMENT); -} - /* * Calculate the N1 counters based on passed in opcode and * internal register values. @@ -637,6 +625,7 @@ static void operation_sequencer(PnvSpi *s) bool stop =3D false; /* Flag to stop the sequencer */ uint8_t opcode =3D 0; uint8_t masked_opcode =3D 0; + uint8_t seq_index; =20 /* * Clear the sequencer FSM error bit - general_SPI_status[3] @@ -650,12 +639,13 @@ static void operation_sequencer(PnvSpi *s) if (GETFIELD(SPI_STS_SEQ_FSM, s->status) =3D=3D SEQ_STATE_IDLE) { s->status =3D SETFIELD(SPI_STS_SEQ_INDEX, s->status, 0); } + seq_index =3D GETFIELD(SPI_STS_SEQ_INDEX, s->status); /* * There are only 8 possible operation IDs to iterate through though * some operations may cause more than one frame to be sequenced. */ - while (get_seq_index(s) < NUM_SEQ_OPS) { - opcode =3D s->seq_op[get_seq_index(s)]; + while (seq_index < NUM_SEQ_OPS) { + opcode =3D s->seq_op[seq_index]; /* Set sequencer state to decode */ s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_DECOD= E); /* @@ -672,7 +662,7 @@ static void operation_sequencer(PnvSpi *s) case SEQ_OP_STOP: s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_E= XECUTE); /* A stop operation in any position stops the sequencer */ - trace_pnv_spi_sequencer_op("STOP", get_seq_index(s)); + trace_pnv_spi_sequencer_op("STOP", seq_index); =20 stop =3D true; s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, FSM_IDL= E); @@ -683,7 +673,7 @@ static void operation_sequencer(PnvSpi *s) =20 case SEQ_OP_SELECT_SLAVE: s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_E= XECUTE); - trace_pnv_spi_sequencer_op("SELECT_SLAVE", get_seq_index(s)); + trace_pnv_spi_sequencer_op("SELECT_SLAVE", seq_index); /* * This device currently only supports a single responder * connection at position 0. De-selecting a responder is fine @@ -694,8 +684,7 @@ static void operation_sequencer(PnvSpi *s) if (s->responder_select =3D=3D 0) { trace_pnv_spi_shifter_done(); qemu_set_irq(s->cs_line[0], 1); - s->status =3D SETFIELD(SPI_STS_SEQ_INDEX, s->status, - (get_seq_index(s) + 1)); + seq_index++; s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, FSM= _DONE); } else if (s->responder_select !=3D 1) { qemu_log_mask(LOG_GUEST_ERROR, "Slave selection other than= 1 " @@ -720,13 +709,15 @@ static void operation_sequencer(PnvSpi *s) * applies once a valid responder select has occurred. */ s->shift_n1_done =3D false; - next_sequencer_fsm(s); + seq_index++; + s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, + SEQ_STATE_INDEX_INCREMENT); } break; =20 case SEQ_OP_SHIFT_N1: s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_E= XECUTE); - trace_pnv_spi_sequencer_op("SHIFT_N1", get_seq_index(s)); + trace_pnv_spi_sequencer_op("SHIFT_N1", seq_index); /* * Only allow a shift_n1 when the state is not IDLE or DONE. * In either of those two cases the sequencer is not in a prop= er @@ -758,8 +749,9 @@ static void operation_sequencer(PnvSpi *s) * transmission to the responder without requiring a refil= l of * the TDR between the two operations. */ - if (PNV_SPI_MASKED_OPCODE(s->seq_op[get_seq_index(s) + 1]) - =3D=3D SEQ_OP_SHIFT_N2) { + if ((seq_index !=3D 7) && + PNV_SPI_MASKED_OPCODE(s->seq_op[(seq_index + 1)]) =3D= =3D + SEQ_OP_SHIFT_N2) { send_n1_alone =3D false; } s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, FSM= _SHIFT_N1); @@ -779,9 +771,8 @@ static void operation_sequencer(PnvSpi *s) if (GETFIELD(SPI_STS_TDR_UNDERRUN, s->status)) { s->shift_n1_done =3D true; s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->sta= tus, - FSM_SHIFT_N2); - s->status =3D SETFIELD(SPI_STS_SEQ_INDEX, s->statu= s, - (get_seq_index(s) + 1)); + FSM_SHIFT_N2); + seq_index++; } else { /* * This is case (1) or (2) so the sequencer needs = to @@ -792,14 +783,16 @@ static void operation_sequencer(PnvSpi *s) } else { /* Ok to move on to the next index */ s->shift_n1_done =3D true; - next_sequencer_fsm(s); + seq_index++; + s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, + SEQ_STATE_INDEX_INCREMENT); } } break; =20 case SEQ_OP_SHIFT_N2: s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_E= XECUTE); - trace_pnv_spi_sequencer_op("SHIFT_N2", get_seq_index(s)); + trace_pnv_spi_sequencer_op("SHIFT_N2", seq_index); if (!s->shift_n1_done) { qemu_log_mask(LOG_GUEST_ERROR, "Shift_N2 is not allowed if= a " "Shift_N1 is not done, shifter state =3D 0x%= llx", @@ -824,14 +817,16 @@ static void operation_sequencer(PnvSpi *s) s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status,= FSM_WAIT); } else { /* Ok to move on to the next index */ - next_sequencer_fsm(s); + seq_index++; + s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, + SEQ_STATE_INDEX_INCREMENT); } } break; =20 case SEQ_OP_BRANCH_IFNEQ_RDR: s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_E= XECUTE); - trace_pnv_spi_sequencer_op("BRANCH_IFNEQ_RDR", get_seq_index(s= )); + trace_pnv_spi_sequencer_op("BRANCH_IFNEQ_RDR", seq_index); /* * The memory mapping register RDR match value is compared aga= inst * the 16 rightmost bytes of the RDR (potentially with masking= ). @@ -847,15 +842,16 @@ static void operation_sequencer(PnvSpi *s) if (rdr_matched) { trace_pnv_spi_RDR_match("success"); /* A match occurred, increment the sequencer index. */ - next_sequencer_fsm(s); + seq_index++; + s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, + SEQ_STATE_INDEX_INCREMENT); } else { trace_pnv_spi_RDR_match("failed"); /* * Branch the sequencer to the index coded into the op * code. */ - s->status =3D SETFIELD(SPI_STS_SEQ_INDEX, s->status, - PNV_SPI_OPCODE_LO_NIBBLE(opcode)); + seq_index =3D PNV_SPI_OPCODE_LO_NIBBLE(opcode); } /* * Regardless of where the branch ended up we want the @@ -874,12 +870,13 @@ static void operation_sequencer(PnvSpi *s) case SEQ_OP_TRANSFER_TDR: s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_E= XECUTE); qemu_log_mask(LOG_GUEST_ERROR, "Transfer TDR is not supported\= n"); - next_sequencer_fsm(s); + seq_index++; + s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_I= NDEX_INCREMENT); break; =20 case SEQ_OP_BRANCH_IFNEQ_INC_1: s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_E= XECUTE); - trace_pnv_spi_sequencer_op("BRANCH_IFNEQ_INC_1", get_seq_index= (s)); + trace_pnv_spi_sequencer_op("BRANCH_IFNEQ_INC_1", seq_index); /* * The spec says the loop should execute count compare + 1 tim= es. * However we learned from engineering that we really only loop @@ -893,19 +890,21 @@ static void operation_sequencer(PnvSpi *s) * mask off all but the first three bits so we don't try to * access beyond the sequencer_operation_reg boundary. */ - s->status =3D SETFIELD(SPI_STS_SEQ_INDEX, s->status, - PNV_SPI_OPCODE_LO_NIBBLE(opcode)); + seq_index =3D PNV_SPI_OPCODE_LO_NIBBLE(opcode); s->loop_counter_1++; } else { /* Continue to next index if loop counter is reached */ - next_sequencer_fsm(s); + seq_index++; + s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, + SEQ_STATE_INDEX_INCREMENT); } break; =20 case SEQ_OP_BRANCH_IFNEQ_INC_2: s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_E= XECUTE); - trace_pnv_spi_sequencer_op("BRANCH_IFNEQ_INC_2", get_seq_index= (s)); - uint8_t condition2 =3D GETFIELD(SPI_CTR_CFG_CMP2, s->regs[SPI_= CTR_CFG_REG]); + trace_pnv_spi_sequencer_op("BRANCH_IFNEQ_INC_2", seq_index); + uint8_t condition2 =3D GETFIELD(SPI_CTR_CFG_CMP2, + s->regs[SPI_CTR_CFG_REG]); /* * The spec says the loop should execute count compare + 1 tim= es. * However we learned from engineering that we really only loop @@ -918,19 +917,21 @@ static void operation_sequencer(PnvSpi *s) * mask off all but the first three bits so we don't try to * access beyond the sequencer_operation_reg boundary. */ - s->status =3D SETFIELD(SPI_STS_SEQ_INDEX, - s->status, PNV_SPI_OPCODE_LO_NIBBLE(opcode= )); + seq_index =3D PNV_SPI_OPCODE_LO_NIBBLE(opcode); s->loop_counter_2++; } else { /* Continue to next index if loop counter is reached */ - next_sequencer_fsm(s); + seq_index++; + s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, + SEQ_STATE_INDEX_INCREMENT); } break; =20 default: s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_E= XECUTE); /* Ignore unsupported operations. */ - next_sequencer_fsm(s); + seq_index++; + s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_I= NDEX_INCREMENT); break; } /* end of switch */ /* @@ -938,10 +939,10 @@ static void operation_sequencer(PnvSpi *s) * we need to go ahead and end things as if there was a STOP at the * end. */ - if (get_seq_index(s) =3D=3D NUM_SEQ_OPS) { + if (seq_index =3D=3D NUM_SEQ_OPS) { /* All 8 opcodes completed, sequencer idling */ s->status =3D SETFIELD(SPI_STS_SHIFTER_FSM, s->status, FSM_IDL= E); - s->status =3D SETFIELD(SPI_STS_SEQ_INDEX, s->status, 0); + seq_index =3D 0; s->loop_counter_1 =3D 0; s->loop_counter_2 =3D 0; s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_I= DLE); @@ -952,6 +953,8 @@ static void operation_sequencer(PnvSpi *s) break; } } /* end of while */ + /* Update sequencer index field in status.*/ + s->status =3D SETFIELD(SPI_STS_SEQ_INDEX, s->status, seq_index); return; } /* end of operation_sequencer() */ =20 --=20 2.39.5 From nobody Sun Apr 6 22:18:24 2025 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1735921256; cv=none; d=zohomail.com; s=zohoarc; b=Eyz3INI/E9I+4aD7Dlg/xZ9SN0PTRlnnpGB0NI3+8y72ZadpQxig/MONDZRdWAWrTCdoTa/Df3Ydc7L8fGspzdBZKgESvhzyHi8j/0I+3Cgu9POoMd48tm2T0Z5cY5EUw5pB/14q8sCc3wzjTW5Cvo9sdel3ZsUT5i1lhaLYGAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1735921256; 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=sNkzVD5c5AjnmSOBxLcPqDH/iO1gv+HYC3LTpzW1U9Y=; b=Sxe/6/beoJCvZlvG+ss3MAq9MPsSzHiwPj9L1ibNmK3DF1kz/SixqNavf/xFNJ0Mh68j70/6BUdq05rMemTGkvIaxdTqclBNfnu2UWkLsDmy4Hsf5ulw9CHVakm/k7T/pgiBz98qxR4fWgJmSg9u1ZcIWmgVosW91MIR1Qb33cg= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1735921256762294.2842744629909; Fri, 3 Jan 2025 08:20:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTkOE-0005d6-Ha; Fri, 03 Jan 2025 11:19:10 -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 1tTkOC-0005c1-BS; Fri, 03 Jan 2025 11:19:08 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tTkOA-0001Zf-KG; Fri, 03 Jan 2025 11:19:08 -0500 Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5033skp6008387; Fri, 3 Jan 2025 16:19:00 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43x8cbjjt1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:18:59 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 503GGBmw009226; Fri, 3 Jan 2025 16:18:59 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43x8cbjjsv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:18:59 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 503BaoHF016711; Fri, 3 Jan 2025 16:18:58 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 43tw5kpv27-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:18:57 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 503GIsMk49217910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Jan 2025 16:18:54 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 17B0F2004B; Fri, 3 Jan 2025 16:18:54 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DC94620049; Fri, 3 Jan 2025 16:18:51 +0000 (GMT) Received: from gfwr515.rchland.ibm.com (unknown [9.10.239.103]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 3 Jan 2025 16:18:51 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=sNkzVD5c5AjnmSOBx LcPqDH/iO1gv+HYC3LTpzW1U9Y=; b=kAGNudsRJ+lGsn33xB9va42aVIt9bzLo/ Xn/i0pQABIsaLQDYH6H8u3gpnsmRfbnAsKof1sWYPFBY9seldhUvgCbS8EDYYOAj 3JDkbCOEDdVkdWXBbThRecCVu6jHBh+LIQVtSCsmyRhCdLGtwRhRK387yZDKPfxr j7yZVhqSX1Gz9dOPgZ7jR1O79xOQlm3ZxVNaILCaN5rBypvdO+8oN4wqyFSRGln/ e5f5zpjJ+1SO4/JsOCH03v9VqDFlzconBCz81lPMhEREUchD1bLSLUNpVzxKp/hO DUJ2qtrp5EyO84B76fFC7bUczx7cG1pLBkRSywVZtFun+iXLIUezw== From: Chalapathi V To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, fbarrat@linux.ibm.com, npiggin@gmail.com, clg@kaod.org, calebs@linux.ibm.com, chalapathi.v@ibm.com, chalapathi.v@linux.ibm.com, saif.abrar@linux.ibm.com, dantan@linux.vnet.ibm.com, milesg@linux.ibm.com, philmd@linaro.org, alistair@alistair23.me Subject: [PATCH v5 3/4] hw/ssi/pnv_spi: Make bus names distinct for each controllers of a socket Date: Fri, 3 Jan 2025 10:18:23 -0600 Message-Id: <20250103161824.22469-4-chalapathi.v@linux.ibm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250103161824.22469-1-chalapathi.v@linux.ibm.com> References: <20250103161824.22469-1-chalapathi.v@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ZA3GJPObaeeaqf7hE1HOQhfmQDjq6X3_ X-Proofpoint-ORIG-GUID: qr5bmYjxzXUMs49Z1_SqyC2ct0c7h8eq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 spamscore=0 suspectscore=0 clxscore=1015 adultscore=0 impostorscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501030137 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=148.163.156.1; envelope-from=chalapathi.v@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ibm.com) X-ZM-MESSAGEID: 1735921258457116600 Content-Type: text/plain; charset="utf-8" Create a spi buses with distict names on each socket so that responders are attached to correct SPI controllers. QOM tree on a 2 socket machine: (qemu) info qom-tree /machine (powernv10-machine) /chip[0] (power10_v2.0-pnv-chip) /pib_spic[0] (pnv-spi) /chip0.pnv.spi.bus.0 (SSI) /xscom-spi[0] (memory-region) /chip[1] (power10_v2.0-pnv-chip) /pib_spic[0] (pnv-spi) /chip1.pnv.spi.bus.0 (SSI) /xscom-spi[0] (memory-region) Signed-off-by: Chalapathi V --- include/hw/ssi/pnv_spi.h | 3 ++- hw/ppc/pnv.c | 2 ++ hw/ssi/pnv_spi.c | 5 +++-- tests/qtest/pnv-spi-seeprom-test.c | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/hw/ssi/pnv_spi.h b/include/hw/ssi/pnv_spi.h index 9878d9a25f..7fc5da1f84 100644 --- a/include/hw/ssi/pnv_spi.h +++ b/include/hw/ssi/pnv_spi.h @@ -31,7 +31,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(PnvSpi, PNV_SPI) #define PNV_SPI_REG_SIZE 8 #define PNV_SPI_REGS 7 =20 -#define TYPE_PNV_SPI_BUS "pnv-spi-bus" +#define TYPE_PNV_SPI_BUS "pnv.spi.bus" typedef struct PnvSpi { SysBusDevice parent_obj; =20 @@ -42,6 +42,7 @@ typedef struct PnvSpi { Fifo8 rx_fifo; /* SPI object number */ uint32_t spic_num; + uint32_t chip_id; uint8_t transfer_len; uint8_t responder_select; /* To verify if shift_n1 happens prior to shift_n2 */ diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 11fd477b71..ce23892fdf 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -2226,6 +2226,8 @@ static void pnv_chip_power10_realize(DeviceState *dev= , Error **errp) /* pib_spic[2] connected to 25csm04 which implements 1 byte transf= er */ object_property_set_int(OBJECT(&chip10->pib_spic[i]), "transfer_le= n", (i =3D=3D 2) ? 1 : 4, &error_fatal); + object_property_set_int(OBJECT(&chip10->pib_spic[i]), "chip-id", + chip->chip_id, &error_fatal); if (!sysbus_realize(SYS_BUS_DEVICE(OBJECT (&chip10->pib_spic[i])), errp)) { return; diff --git a/hw/ssi/pnv_spi.c b/hw/ssi/pnv_spi.c index 87eac666bb..41beb559c6 100644 --- a/hw/ssi/pnv_spi.c +++ b/hw/ssi/pnv_spi.c @@ -1116,14 +1116,15 @@ static const MemoryRegionOps pnv_spi_xscom_ops =3D { =20 static const Property pnv_spi_properties[] =3D { DEFINE_PROP_UINT32("spic_num", PnvSpi, spic_num, 0), + DEFINE_PROP_UINT32("chip-id", PnvSpi, chip_id, 0), DEFINE_PROP_UINT8("transfer_len", PnvSpi, transfer_len, 4), }; =20 static void pnv_spi_realize(DeviceState *dev, Error **errp) { PnvSpi *s =3D PNV_SPI(dev); - g_autofree char *name =3D g_strdup_printf(TYPE_PNV_SPI_BUS ".%d", - s->spic_num); + g_autofree char *name =3D g_strdup_printf("chip%d." TYPE_PNV_SPI_BUS "= .%d", + s->chip_id, s->spic_num); s->ssi_bus =3D ssi_create_bus(dev, name); s->cs_line =3D g_new0(qemu_irq, 1); qdev_init_gpio_out_named(DEVICE(s), s->cs_line, "cs", 1); diff --git a/tests/qtest/pnv-spi-seeprom-test.c b/tests/qtest/pnv-spi-seepr= om-test.c index 57f20af76e..ef1005a926 100644 --- a/tests/qtest/pnv-spi-seeprom-test.c +++ b/tests/qtest/pnv-spi-seeprom-test.c @@ -92,7 +92,7 @@ static void test_spi_seeprom(const void *data) qts =3D qtest_initf("-machine powernv10 -smp 2,cores=3D2," "threads=3D1 -accel tcg,thread=3Dsingle -nographic " "-blockdev node-name=3Dpib_spic2,driver=3Dfile," - "filename=3D%s -device 25csm04,bus=3Dpnv-spi-bus.2,c= s=3D0," + "filename=3D%s -device 25csm04,bus=3Dchip0.pnv.spi.b= us.2,cs=3D0," "drive=3Dpib_spic2", tmp_path); spi_seeprom_transaction(qts, chip); qtest_quit(qts); --=20 2.39.5 From nobody Sun Apr 6 22:18:24 2025 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=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1735921243; cv=none; d=zohomail.com; s=zohoarc; b=BkKEqsnxdwSuSdP1RBQiq90mQza4mVFpbY419r1+SMtcrsj2/29bwx70LrweSpxCh6fkQ0TmT2jbenhu60s8y+KKJtKKHRJT6Y325/0rX2WlRLWRl7RJIlY6G9gQPgyO4NqwWZtJxN0DeDW7VTeXWJefjPTzr+c5TklfSVeiQX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1735921243; 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=iixKk5Q0dYDDrARCZDFFwcYNAdJEzOCoUjmmBfG6iF8=; b=Lnyrv02RZsI+WvImNgcjc5HnSpsFj808uYKLEW0xVIdtrEAiwJ7m4QMVqL+R0+Uy52gvcg5owUuc6NVqvQ6Ix4KzXUkqKpDVnFJmlYIL3dZltW3727G+bgz6YVsc5P8RjstvYBDnfK8P0CLYdOz9WyhfFQOH0s3ZGOmJXgaxhKg= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1735921243903145.01622366700087; Fri, 3 Jan 2025 08:20:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTkOJ-0005ei-Ok; Fri, 03 Jan 2025 11:19:15 -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 1tTkOI-0005eK-3s; Fri, 03 Jan 2025 11:19:14 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tTkOG-0001aI-MW; Fri, 03 Jan 2025 11:19:13 -0500 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 503E4Gje026493; Fri, 3 Jan 2025 16:19:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43x4mab1qk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:19:02 +0000 (GMT) Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 503G5wVD002309; Fri, 3 Jan 2025 16:19:02 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 43x4mab1qg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:19:02 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 503CKMBb004365; Fri, 3 Jan 2025 16:19:01 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 43twvk6qkv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Jan 2025 16:19:01 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 503GIwtP32112940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Jan 2025 16:18:58 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EDD4320049; Fri, 3 Jan 2025 16:18:57 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C000220040; Fri, 3 Jan 2025 16:18:55 +0000 (GMT) Received: from gfwr515.rchland.ibm.com (unknown [9.10.239.103]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 3 Jan 2025 16:18:55 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=iixKk5Q0dYDDrARCZ DFFwcYNAdJEzOCoUjmmBfG6iF8=; b=e7dJKOxXrgL/aXuKXKZRgH12cyKVvVp9+ S6oB0vdGV4fijnrQOswZfcQIk785MMnSUpwpiExu6WAbnYQOQ+zey4fkbIUWk6O8 C9Hl2PHEZRVfqn+5NlVCPNBEG4jc1a24CsvOE6r4vutqH40mcvGJjCgfR8i+SPyV K0/cPwSNbuEaVZ3Q3CM5XhiZr5twj1VWNNEsRsSoXRxccARMfNp2DAR5nBYRvsdG hUoUf9dB0hOZpyEGYA2E7B+I1YDwOY8wMVuWe1jk4Nj1Rj8ah27FyJGoPyEjZoj9 D62PY/VPsdWFOuh1Dn6EtCqux1uvQB9GismWtN4W/raS7+PnDgVRw== From: Chalapathi V To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, fbarrat@linux.ibm.com, npiggin@gmail.com, clg@kaod.org, calebs@linux.ibm.com, chalapathi.v@ibm.com, chalapathi.v@linux.ibm.com, saif.abrar@linux.ibm.com, dantan@linux.vnet.ibm.com, milesg@linux.ibm.com, philmd@linaro.org, alistair@alistair23.me Subject: [PATCH v5 4/4] hw/ssi/pnv_spi: Put a limit to RDR match failures Date: Fri, 3 Jan 2025 10:18:24 -0600 Message-Id: <20250103161824.22469-5-chalapathi.v@linux.ibm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250103161824.22469-1-chalapathi.v@linux.ibm.com> References: <20250103161824.22469-1-chalapathi.v@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: vWoRzg3feIU3L7dmhPJLkzO_tjjw7saS X-Proofpoint-ORIG-GUID: Q2VhpmavniXestWuDPCNPVDYrOnpKBGT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 bulkscore=0 malwarescore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 impostorscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=983 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501030141 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=148.163.158.5; envelope-from=chalapathi.v@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 @ibm.com) X-ZM-MESSAGEID: 1735921264456116600 Content-Type: text/plain; charset="utf-8" There is a possibility that SPI controller can get into loop due to indefin= ite RDR match failures. Hence put a limit to failures and stop the sequencer. Signed-off-by: Chalapathi V Reviewed-by: Nicholas Piggin --- hw/ssi/pnv_spi.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/ssi/pnv_spi.c b/hw/ssi/pnv_spi.c index 41beb559c6..d605fa8b46 100644 --- a/hw/ssi/pnv_spi.c +++ b/hw/ssi/pnv_spi.c @@ -20,6 +20,7 @@ #define PNV_SPI_OPCODE_LO_NIBBLE(x) (x & 0x0F) #define PNV_SPI_MASKED_OPCODE(x) (x & 0xF0) #define PNV_SPI_FIFO_SIZE 16 +#define RDR_MATCH_FAILURE_LIMIT 16 =20 /* * Macro from include/hw/ppc/fdt.h @@ -838,21 +839,31 @@ static void operation_sequencer(PnvSpi *s) */ if (GETFIELD(SPI_STS_RDR_FULL, s->status) =3D=3D 1) { bool rdr_matched =3D false; + static int fail_count; rdr_matched =3D does_rdr_match(s); if (rdr_matched) { trace_pnv_spi_RDR_match("success"); + fail_count =3D 0; /* A match occurred, increment the sequencer index. */ seq_index++; s->status =3D SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_INDEX_INCREMENT); } else { trace_pnv_spi_RDR_match("failed"); + fail_count++; /* * Branch the sequencer to the index coded into the op * code. */ seq_index =3D PNV_SPI_OPCODE_LO_NIBBLE(opcode); } + if (fail_count >=3D RDR_MATCH_FAILURE_LIMIT) { + qemu_log_mask(LOG_GUEST_ERROR, "pnv_spi: RDR match fai= lure" + " limit crossed %d times hence requestin= g " + "sequencer to stop.\n", + RDR_MATCH_FAILURE_LIMIT); + stop =3D true; + } /* * Regardless of where the branch ended up we want the * sequencer to continue shifting so we have to clear --=20 2.39.5