Received: by 10.223.164.202 with SMTP id h10csp4217078wrb; Mon, 20 Nov 2017 11:48:08 -0800 (PST) X-Google-Smtp-Source: AGs4zMbinhYEGKLshv0yfa0hyMc0erDvBsb51mGvQlhNMDnEMc1W3v7e8pswM73s5ddb+anjzqHd X-Received: by 10.99.43.71 with SMTP id r68mr14818926pgr.348.1511207288196; Mon, 20 Nov 2017 11:48:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511207288; cv=none; d=google.com; s=arc-20160816; b=uGK4k5DO/SbA5MLA7tCUFMbePwddsTVmOKrqRMDr5gizgce7icS+hFM719AhMVh8f2 1uShfYVp4Dh5kZV4/Hq+Gp6RCfX5oy//CU6rVKV2S5JBpWhGXmDOcyNumlTIYj2NNlxB JYcVrdof2eRDfBP9Kmn5YVnLmR3iGbZ+bImdvtEmg+EcxbBfdq1LACSdHb2urTsiJtVM zvquaTl2UZzl9tM5w1TQZ2nsEetQt3iM57lBClFnuq0/jqEgjGDESUnsvK0W4mgXqwfb xM4jsh1vFt3d7OL9Vs/PMiRCJ+s0sx+RcUjYTJ7mAgSBxrwfd2T3bowGN6SprfS5UIiV rLSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=G8U+LOho0LXjGJO4bvqxPUQbDOMF9oupsszVcWuSV2w=; b=bv1hbtifRrffpMso02dMVC/RI3SnBT3ULGcBeTJ/xlsIoKDAjC0jcx7jH9VkID9jFQ /6faNi7Ni8CJ8o2NksXbcFf/8x9Gsq0hMwr6EXWZsGHLA48bqSA4aKgCz/PFQ7XtC1Ej VPsRjwQtqK2iXkEp8T99mDlljKc53OZaX6iuB5noow+v/7qrIjyVrOAijQuPpdttXjeV ZOR/y0LomnMRqLp8swtt7sroRL5ahUoBRV+0Eske/Ln87l65AIj2og6kotbIklyXLgG7 xCfGHBJuXUKbCpAHleakiUpjMWH970Hs4OQUggHe0RP40B6yohzkaFX5iehYhWTAV8cv aXfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d76si9817289pfk.321.2017.11.20.11.47.57; Mon, 20 Nov 2017 11:48:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752709AbdKTTrO (ORCPT + 67 others); Mon, 20 Nov 2017 14:47:14 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:50892 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752365AbdKTTrJ (ORCPT ); Mon, 20 Nov 2017 14:47:09 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAKJib4v145026 for ; Mon, 20 Nov 2017 14:47:08 -0500 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ec3bhpea2-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 20 Nov 2017 14:47:08 -0500 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 Nov 2017 12:47:07 -0700 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 20 Nov 2017 12:47:04 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAKJl3MZ131502; Mon, 20 Nov 2017 12:47:03 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B4002C6043; Mon, 20 Nov 2017 12:47:03 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.41.174.252]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 3195DC603E; Mon, 20 Nov 2017 12:47:03 -0700 (MST) From: Eddie James To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, devicetree@vger.kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, bradleyb@fuzziesquirrel.com, cbostic@linux.vnet.ibm.com, joel@jms.id.au, eajames@linux.vnet.ibm.com, "Edward A. James" Subject: [PATCH v5 2/8] drivers/fsi: Add SBEFIFO FSI client device driver Date: Mon, 20 Nov 2017 13:46:51 -0600 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1511207217-14075-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1511207217-14075-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112019-0004-0000-0000-0000133FC76B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008100; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000240; SDB=6.00948744; UDB=6.00479090; IPR=6.00729025; BA=6.00005702; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018111; XFM=3.00000015; UTC=2017-11-20 19:47:06 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112019-0005-0000-0000-000084F39F30 Message-Id: <1511207217-14075-3-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-20_11:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711200264 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Edward A. James" IBM POWER9 processors contain some embedded hardware and software bits collectively referred to as the self boot engine (SBE). One role of the SBE is to act as a proxy that provides access to the registers of the POWER chip from other (embedded) systems. The POWER9 chip contains a hardware frontend for communicating with the SBE from remote systems called the SBEFIFO. The SBEFIFO logic is contained within an FSI CFAM and as such the driver implements an FSI bus device. The SBE expects to communicate using a defined wire protocol; however, the driver knows nothing of the protocol and only provides raw access to the fifo device to userspace applications wishing to communicate with the SBE using the wire protocol. The SBEFIFO consists of two hardware fifos. The upstream fifo is used by the driver to transfer data to the SBE on the POWER chip, from the system hosting the driver. The downstream fifo is used by the driver to transfer data from the SBE on the power chip to the system hosting the driver. Contributions from Brad Bishop Signed-off-by: Edward A. James --- drivers/fsi/Kconfig | 7 + drivers/fsi/Makefile | 1 + drivers/fsi/fsi-sbefifo.c | 577 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 585 insertions(+) create mode 100644 drivers/fsi/fsi-sbefifo.c diff --git a/drivers/fsi/Kconfig b/drivers/fsi/Kconfig index 6821ed0..8c4d903 100644 --- a/drivers/fsi/Kconfig +++ b/drivers/fsi/Kconfig @@ -33,6 +33,13 @@ config FSI_SCOM ---help--- This option enables an FSI based SCOM device driver. +config FSI_SBEFIFO + tristate "SBEFIFO FSI client device driver" + ---help--- + This option enables an FSI based SBEFIFO device driver. The SBEFIFO is + a pipe-like FSI device for communicating with the self boot engine + (SBE) on POWER processors. + endif endmenu diff --git a/drivers/fsi/Makefile b/drivers/fsi/Makefile index 65eb99d..851182e 100644 --- a/drivers/fsi/Makefile +++ b/drivers/fsi/Makefile @@ -3,3 +3,4 @@ obj-$(CONFIG_FSI) += fsi-core.o obj-$(CONFIG_FSI_MASTER_HUB) += fsi-master-hub.o obj-$(CONFIG_FSI_MASTER_GPIO) += fsi-master-gpio.o obj-$(CONFIG_FSI_SCOM) += fsi-scom.o +obj-$(CONFIG_FSI_SBEFIFO) += fsi-sbefifo.o diff --git a/drivers/fsi/fsi-sbefifo.c b/drivers/fsi/fsi-sbefifo.c new file mode 100644 index 0000000..6ba190a --- /dev/null +++ b/drivers/fsi/fsi-sbefifo.c @@ -0,0 +1,577 @@ +/* + * Copyright (C) IBM Corporation 2017 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERGCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * The SBEFIFO is a pipe-like FSI device for communicating with + * the self boot engine on POWER processors. + */ + +#define DEVICE_NAME "sbefifo" +#define FSI_ENGID_SBE 0x22 +#define SBEFIFO_BUF_CNT 32 + +#define SBEFIFO_UP 0x00 /* Up register offset */ +#define SBEFIFO_DWN 0x40 /* Down register offset */ + +#define SBEFIFO_STS 0x04 +#define SBEFIFO_EMPTY BIT(20) +#define SBEFIFO_STS_RESET_REQ BIT(25) +#define SBEFIFO_EOT_RAISE 0x08 +#define SBEFIFO_EOT_MAGIC 0xffffffff +#define SBEFIFO_REQ_RESET 0x0C +#define SBEFIFO_EOT_ACK 0x14 + +#define SBEFIFO_RESCHEDULE msecs_to_jiffies(500) +#define SBEFIFO_MAX_RESCHDULE msecs_to_jiffies(5000) + +struct sbefifo { + struct timer_list poll_timer; + struct fsi_device *fsi_dev; + wait_queue_head_t wait; + struct list_head xfrs; + struct kref kref; + spinlock_t lock; + char name[32]; + int idx; + int rc; +}; + +struct sbefifo_buf { + u32 buf[SBEFIFO_BUF_CNT]; + unsigned long flags; +#define SBEFIFO_BUF_FULL 1 + u32 *rpos; + u32 *wpos; +}; + +struct sbefifo_xfr { + unsigned long wait_data_timeout; + struct sbefifo_buf *rbuf; + struct sbefifo_buf *wbuf; + struct list_head client; + struct list_head xfrs; + unsigned long flags; +#define SBEFIFO_XFR_WRITE_DONE 1 +#define SBEFIFO_XFR_RESP_PENDING 2 +#define SBEFIFO_XFR_COMPLETE 3 +#define SBEFIFO_XFR_CANCEL 4 +}; + +struct sbefifo_client { + struct sbefifo_buf rbuf; + struct sbefifo_buf wbuf; + struct list_head xfrs; + struct sbefifo *dev; + struct kref kref; +}; + +static DEFINE_IDA(sbefifo_ida); + +static int sbefifo_inw(struct sbefifo *sbefifo, int reg, u32 *word) +{ + int rc; + __be32 raw_word; + + rc = fsi_device_read(sbefifo->fsi_dev, reg, &raw_word, + sizeof(raw_word)); + if (rc) + return rc; + + *word = be32_to_cpu(raw_word); + + return 0; +} + +static int sbefifo_outw(struct sbefifo *sbefifo, int reg, u32 word) +{ + __be32 raw_word = cpu_to_be32(word); + + return fsi_device_write(sbefifo->fsi_dev, reg, &raw_word, + sizeof(raw_word)); +} + +/* Don't flip endianness of data to/from FIFO, just pass through. */ +static int sbefifo_readw(struct sbefifo *sbefifo, u32 *word) +{ + return fsi_device_read(sbefifo->fsi_dev, SBEFIFO_DWN, word, + sizeof(*word)); +} + +static int sbefifo_writew(struct sbefifo *sbefifo, u32 word) +{ + return fsi_device_write(sbefifo->fsi_dev, SBEFIFO_UP, &word, + sizeof(word)); +} + +static int sbefifo_ack_eot(struct sbefifo *sbefifo) +{ + u32 discard; + int ret; + + /* Discard the EOT word. */ + ret = sbefifo_readw(sbefifo, &discard); + if (ret) + return ret; + + return sbefifo_outw(sbefifo, SBEFIFO_DWN | SBEFIFO_EOT_ACK, + SBEFIFO_EOT_MAGIC); +} + +static size_t sbefifo_dev_nwreadable(u32 sts) +{ + static const u32 FIFO_NTRY_CNT_MSK = 0x000f0000; + static const unsigned int FIFO_NTRY_CNT_SHIFT = 16; + + return (sts & FIFO_NTRY_CNT_MSK) >> FIFO_NTRY_CNT_SHIFT; +} + +static size_t sbefifo_dev_nwwriteable(u32 sts) +{ + static const size_t FIFO_DEPTH = 8; + + return FIFO_DEPTH - sbefifo_dev_nwreadable(sts); +} + +static void sbefifo_buf_init(struct sbefifo_buf *buf) +{ + WRITE_ONCE(buf->flags, 0); + WRITE_ONCE(buf->rpos, buf->buf); + WRITE_ONCE(buf->wpos, buf->buf); +} + +static size_t sbefifo_buf_nbreadable(struct sbefifo_buf *buf) +{ + size_t n; + u32 *rpos = READ_ONCE(buf->rpos); + u32 *wpos = READ_ONCE(buf->wpos); + + if (test_bit(SBEFIFO_BUF_FULL, &buf->flags)) + n = SBEFIFO_BUF_CNT; + else if (rpos <= wpos) + n = wpos - rpos; + else + n = (buf->buf + SBEFIFO_BUF_CNT) - rpos; + + return n << 2; +} + +static size_t sbefifo_buf_nbwriteable(struct sbefifo_buf *buf) +{ + size_t n; + u32 *rpos = READ_ONCE(buf->rpos); + u32 *wpos = READ_ONCE(buf->wpos); + + if (test_bit(SBEFIFO_BUF_FULL, &buf->flags)) + n = 0; + else if (wpos < rpos) + n = rpos - wpos; + else + n = (buf->buf + SBEFIFO_BUF_CNT) - wpos; + + return n << 2; +} + +/* + * Update pointers and flags after doing a buffer read. Return true if the + * buffer is now empty; + */ +static bool sbefifo_buf_readnb(struct sbefifo_buf *buf, size_t n) +{ + u32 *rpos = READ_ONCE(buf->rpos); + u32 *wpos = READ_ONCE(buf->wpos); + + if (n) + clear_bit(SBEFIFO_BUF_FULL, &buf->flags); + + rpos += (n >> 2); + if (rpos == buf->buf + SBEFIFO_BUF_CNT) + rpos = buf->buf; + + WRITE_ONCE(buf->rpos, rpos); + + return rpos == wpos; +} + +/* + * Update pointers and flags after doing a buffer write. Return true if the + * buffer is now full. + */ +static bool sbefifo_buf_wrotenb(struct sbefifo_buf *buf, size_t n) +{ + u32 *rpos = READ_ONCE(buf->rpos); + u32 *wpos = READ_ONCE(buf->wpos); + + wpos += (n >> 2); + if (wpos == buf->buf + SBEFIFO_BUF_CNT) + wpos = buf->buf; + if (wpos == rpos) + set_bit(SBEFIFO_BUF_FULL, &buf->flags); + + WRITE_ONCE(buf->wpos, wpos); + + return rpos == wpos; +} + +static void sbefifo_free(struct kref *kref) +{ + struct sbefifo *sbefifo = container_of(kref, struct sbefifo, kref); + + kfree(sbefifo); +} + +static void sbefifo_get(struct sbefifo *sbefifo) +{ + kref_get(&sbefifo->kref); +} + +static void sbefifo_put(struct sbefifo *sbefifo) +{ + kref_put(&sbefifo->kref, sbefifo_free); +} + +static struct sbefifo_xfr *sbefifo_next_xfr(struct sbefifo *sbefifo) +{ + struct sbefifo_xfr *xfr, *tmp; + + list_for_each_entry_safe(xfr, tmp, &sbefifo->xfrs, xfrs) { + if (unlikely(test_bit(SBEFIFO_XFR_CANCEL, &xfr->flags))) { + /* Discard cancelled transfers. */ + list_del(&xfr->xfrs); + kfree(xfr); + continue; + } + + return xfr; + } + + return NULL; +} + +static void sbefifo_poll_timer(unsigned long data) +{ + static const unsigned long EOT_MASK = 0x000000ff; + unsigned long flags; + struct sbefifo *sbefifo = (void *)data; + struct sbefifo_buf *rbuf, *wbuf; + struct sbefifo_xfr *xfr, *tmp; + struct sbefifo_buf drain; + size_t devn, bufn; + int eot = 0; + int ret = 0; + u32 sts; + int i; + + spin_lock_irqsave(&sbefifo->lock, flags); + xfr = list_first_entry_or_null(&sbefifo->xfrs, struct sbefifo_xfr, + xfrs); + if (!xfr) + goto out_unlock; + + rbuf = xfr->rbuf; + wbuf = xfr->wbuf; + + if (unlikely(test_bit(SBEFIFO_XFR_CANCEL, &xfr->flags))) { + /* The client left. */ + rbuf = &drain; + wbuf = &drain; + sbefifo_buf_init(&drain); + if (!test_bit(SBEFIFO_XFR_RESP_PENDING, &xfr->flags)) + set_bit(SBEFIFO_XFR_WRITE_DONE, &xfr->flags); + } + + /* Drain the write buffer. */ + while ((bufn = sbefifo_buf_nbreadable(wbuf))) { + ret = sbefifo_inw(sbefifo, SBEFIFO_UP | SBEFIFO_STS, &sts); + if (ret) + goto out; + + devn = sbefifo_dev_nwwriteable(sts); + if (devn == 0) { + /* No open slot for write. Reschedule. */ + sbefifo->poll_timer.expires = jiffies + + SBEFIFO_RESCHEDULE; + add_timer(&sbefifo->poll_timer); + goto out_unlock; + } + + devn = min_t(size_t, devn, bufn >> 2); + for (i = 0; i < devn; i++) { + ret = sbefifo_writew(sbefifo, *wbuf->rpos); + if (ret) + goto out; + + sbefifo_buf_readnb(wbuf, 1 << 2); + } + } + + /* Send EOT if the writer is finished. */ + if (test_and_clear_bit(SBEFIFO_XFR_WRITE_DONE, &xfr->flags)) { + ret = sbefifo_outw(sbefifo, SBEFIFO_UP | SBEFIFO_EOT_RAISE, + SBEFIFO_EOT_MAGIC); + if (ret) + goto out; + + /* Inform reschedules that the writer is finished. */ + set_bit(SBEFIFO_XFR_RESP_PENDING, &xfr->flags); + } + + /* Nothing left to do if the writer is not finished. */ + if (!test_bit(SBEFIFO_XFR_RESP_PENDING, &xfr->flags)) + goto out; + + /* Fill the read buffer. */ + while ((bufn = sbefifo_buf_nbwriteable(rbuf))) { + ret = sbefifo_inw(sbefifo, SBEFIFO_DWN | SBEFIFO_STS, &sts); + if (ret) + goto out; + + devn = sbefifo_dev_nwreadable(sts); + if (devn == 0) { + /* + * Limit the maximum waiting period for data in the + * FIFO. If the SBE isn't running, we will wait + * forever. + */ + if (!xfr->wait_data_timeout) { + xfr->wait_data_timeout = + jiffies + SBEFIFO_MAX_RESCHDULE; + } else if (time_after(jiffies, + xfr->wait_data_timeout)) { + ret = -ETIME; + goto out; + } + + /* No data yet. Reschedule. */ + sbefifo->poll_timer.expires = jiffies + + SBEFIFO_RESCHEDULE; + add_timer(&sbefifo->poll_timer); + goto out_unlock; + } else { + xfr->wait_data_timeout = 0; + } + + /* Fill. The EOT word is discarded. */ + devn = min_t(size_t, devn, bufn >> 2); + eot = (sts & EOT_MASK) != 0; + if (eot) + devn--; + + for (i = 0; i < devn; i++) { + ret = sbefifo_readw(sbefifo, rbuf->wpos); + if (ret) + goto out; + + if (likely(!test_bit(SBEFIFO_XFR_CANCEL, &xfr->flags))) + sbefifo_buf_wrotenb(rbuf, 1 << 2); + } + + if (eot) { + ret = sbefifo_ack_eot(sbefifo); + if (ret) + goto out; + + set_bit(SBEFIFO_XFR_COMPLETE, &xfr->flags); + list_del(&xfr->xfrs); + if (unlikely(test_bit(SBEFIFO_XFR_CANCEL, + &xfr->flags))) + kfree(xfr); + break; + } + } + +out: + if (unlikely(ret)) { + sbefifo->rc = ret; + dev_err(&sbefifo->fsi_dev->dev, + "Fatal bus access failure: %d\n", ret); + list_for_each_entry_safe(xfr, tmp, &sbefifo->xfrs, xfrs) { + list_del(&xfr->xfrs); + kfree(xfr); + } + INIT_LIST_HEAD(&sbefifo->xfrs); + + } else if (eot && sbefifo_next_xfr(sbefifo)) { + sbefifo_get(sbefifo); + sbefifo->poll_timer.expires = jiffies; + add_timer(&sbefifo->poll_timer); + } + + sbefifo_put(sbefifo); + wake_up_interruptible(&sbefifo->wait); + +out_unlock: + spin_unlock_irqrestore(&sbefifo->lock, flags); +} + +static int sbefifo_request_reset(struct sbefifo *sbefifo) +{ + int ret; + u32 status; + unsigned long start; + const unsigned int wait_time = 5; /* jiffies */ + const unsigned long timeout = msecs_to_jiffies(250); + + ret = sbefifo_outw(sbefifo, SBEFIFO_UP | SBEFIFO_REQ_RESET, 1); + if (ret) + return ret; + + start = jiffies; + + do { + ret = sbefifo_inw(sbefifo, SBEFIFO_UP | SBEFIFO_STS, &status); + if (ret) + return ret; + + if (!(status & SBEFIFO_STS_RESET_REQ)) + return 0; + + set_current_state(TASK_INTERRUPTIBLE); + if (schedule_timeout(wait_time) > 0) + return -EINTR; + } while (time_after(start + timeout, jiffies)); + + return -ETIME; +} + +static int sbefifo_probe(struct device *dev) +{ + struct fsi_device *fsi_dev = to_fsi_dev(dev); + struct sbefifo *sbefifo; + u32 up, down; + int ret; + + dev_dbg(dev, "Found sbefifo device\n"); + sbefifo = kzalloc(sizeof(*sbefifo), GFP_KERNEL); + if (!sbefifo) + return -ENOMEM; + + sbefifo->fsi_dev = fsi_dev; + + ret = sbefifo_inw(sbefifo, SBEFIFO_UP | SBEFIFO_STS, &up); + if (ret) + return ret; + + ret = sbefifo_inw(sbefifo, SBEFIFO_DWN | SBEFIFO_STS, &down); + if (ret) + return ret; + + if (!(up & SBEFIFO_EMPTY) || !(down & SBEFIFO_EMPTY)) { + ret = sbefifo_request_reset(sbefifo); + if (ret) { + dev_err(dev, + "fifos weren't empty and failed the reset\n"); + return ret; + } + } + + spin_lock_init(&sbefifo->lock); + kref_init(&sbefifo->kref); + init_waitqueue_head(&sbefifo->wait); + INIT_LIST_HEAD(&sbefifo->xfrs); + + sbefifo->idx = ida_simple_get(&sbefifo_ida, 1, INT_MAX, GFP_KERNEL); + snprintf(sbefifo->name, sizeof(sbefifo->name), "sbefifo%d", + sbefifo->idx); + + /* This bit of silicon doesn't offer any interrupts... */ + setup_timer(&sbefifo->poll_timer, sbefifo_poll_timer, + (unsigned long)sbefifo); + + dev_set_drvdata(dev, sbefifo); + + return 0; +} + +static int sbefifo_remove(struct device *dev) +{ + unsigned long flags; + struct sbefifo *sbefifo = dev_get_drvdata(dev); + struct sbefifo_xfr *xfr, *tmp; + + spin_lock_irqsave(&sbefifo->lock, flags); + + WRITE_ONCE(sbefifo->rc, -ENODEV); + list_for_each_entry_safe(xfr, tmp, &sbefifo->xfrs, xfrs) { + list_del(&xfr->xfrs); + kfree(xfr); + } + + INIT_LIST_HEAD(&sbefifo->xfrs); + + spin_unlock_irqrestore(&sbefifo->lock, flags); + + wake_up_all(&sbefifo->wait); + + ida_simple_remove(&sbefifo_ida, sbefifo->idx); + + if (del_timer_sync(&sbefifo->poll_timer)) + sbefifo_put(sbefifo); + + sbefifo_put(sbefifo); + + return 0; +} + +static struct fsi_device_id sbefifo_ids[] = { + { + .engine_type = FSI_ENGID_SBE, + .version = FSI_VERSION_ANY, + }, + { 0 } +}; + +static struct fsi_driver sbefifo_drv = { + .id_table = sbefifo_ids, + .drv = { + .name = DEVICE_NAME, + .bus = &fsi_bus_type, + .probe = sbefifo_probe, + .remove = sbefifo_remove, + } +}; + +static int sbefifo_init(void) +{ + return fsi_driver_register(&sbefifo_drv); +} + +static void sbefifo_exit(void) +{ + fsi_driver_unregister(&sbefifo_drv); + + ida_destroy(&sbefifo_ida); +} + +module_init(sbefifo_init); +module_exit(sbefifo_exit); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Brad Bishop "); +MODULE_AUTHOR("Eddie James "); +MODULE_DESCRIPTION("Linux device interface to the POWER Self Boot Engine"); -- 1.8.3.1 From 1584623759825776706@xxx Mon Nov 20 21:56:20 +0000 2017 X-GM-THRID: 1584623759825776706 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread