2017-11-24 22:00:36 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-04-16 20:14:44 +08:00
|
|
|
/*
|
|
|
|
* s390 specific pci instructions
|
|
|
|
*
|
|
|
|
* Copyright IBM Corp. 2013
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/delay.h>
|
2019-04-14 21:38:01 +08:00
|
|
|
#include <linux/jump_label.h>
|
2017-10-30 21:38:58 +08:00
|
|
|
#include <asm/facility.h>
|
2013-04-16 20:14:44 +08:00
|
|
|
#include <asm/pci_insn.h>
|
2015-08-19 01:39:27 +08:00
|
|
|
#include <asm/pci_debug.h>
|
2019-04-14 22:25:54 +08:00
|
|
|
#include <asm/pci_io.h>
|
2013-04-16 20:16:14 +08:00
|
|
|
#include <asm/processor.h>
|
2013-04-16 20:14:44 +08:00
|
|
|
|
|
|
|
#define ZPCI_INSN_BUSY_DELAY 1 /* 1 microsecond */
|
|
|
|
|
2015-08-19 01:39:27 +08:00
|
|
|
static inline void zpci_err_insn(u8 cc, u8 status, u64 req, u64 offset)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
u64 req;
|
|
|
|
u64 offset;
|
2015-10-09 17:07:06 +08:00
|
|
|
u8 cc;
|
|
|
|
u8 status;
|
|
|
|
} __packed data = {req, offset, cc, status};
|
2015-08-19 01:39:27 +08:00
|
|
|
|
|
|
|
zpci_err_hex(&data, sizeof(data));
|
|
|
|
}
|
|
|
|
|
2013-04-16 20:14:44 +08:00
|
|
|
/* Modify PCI Function Controls */
|
|
|
|
static inline u8 __mpcifc(u64 req, struct zpci_fib *fib, u8 *status)
|
|
|
|
{
|
|
|
|
u8 cc;
|
|
|
|
|
|
|
|
asm volatile (
|
|
|
|
" .insn rxy,0xe300000000d0,%[req],%[fib]\n"
|
|
|
|
" ipm %[cc]\n"
|
|
|
|
" srl %[cc],28\n"
|
|
|
|
: [cc] "=d" (cc), [req] "+d" (req), [fib] "+Q" (*fib)
|
|
|
|
: : "cc");
|
|
|
|
*status = req >> 24 & 0xff;
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
2017-06-10 19:54:44 +08:00
|
|
|
u8 zpci_mod_fc(u64 req, struct zpci_fib *fib, u8 *status)
|
2013-04-16 20:14:44 +08:00
|
|
|
{
|
2017-06-10 19:54:44 +08:00
|
|
|
u8 cc;
|
2013-04-16 20:14:44 +08:00
|
|
|
|
|
|
|
do {
|
2017-06-10 19:54:44 +08:00
|
|
|
cc = __mpcifc(req, fib, status);
|
2013-04-16 20:14:44 +08:00
|
|
|
if (cc == 2)
|
|
|
|
msleep(ZPCI_INSN_BUSY_DELAY);
|
|
|
|
} while (cc == 2);
|
|
|
|
|
|
|
|
if (cc)
|
2017-06-10 19:54:44 +08:00
|
|
|
zpci_err_insn(cc, *status, req, 0);
|
2015-08-19 01:39:27 +08:00
|
|
|
|
2017-06-10 19:54:44 +08:00
|
|
|
return cc;
|
2013-04-16 20:14:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Refresh PCI Translations */
|
|
|
|
static inline u8 __rpcit(u64 fn, u64 addr, u64 range, u8 *status)
|
|
|
|
{
|
|
|
|
register u64 __addr asm("2") = addr;
|
|
|
|
register u64 __range asm("3") = range;
|
|
|
|
u8 cc;
|
|
|
|
|
|
|
|
asm volatile (
|
|
|
|
" .insn rre,0xb9d30000,%[fn],%[addr]\n"
|
|
|
|
" ipm %[cc]\n"
|
|
|
|
" srl %[cc],28\n"
|
|
|
|
: [cc] "=d" (cc), [fn] "+d" (fn)
|
|
|
|
: [addr] "d" (__addr), "d" (__range)
|
|
|
|
: "cc");
|
|
|
|
*status = fn >> 24 & 0xff;
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
2013-06-25 20:52:23 +08:00
|
|
|
int zpci_refresh_trans(u64 fn, u64 addr, u64 range)
|
2013-04-16 20:14:44 +08:00
|
|
|
{
|
|
|
|
u8 cc, status;
|
|
|
|
|
|
|
|
do {
|
|
|
|
cc = __rpcit(fn, addr, range, &status);
|
|
|
|
if (cc == 2)
|
|
|
|
udelay(ZPCI_INSN_BUSY_DELAY);
|
|
|
|
} while (cc == 2);
|
|
|
|
|
|
|
|
if (cc)
|
2015-08-19 01:39:27 +08:00
|
|
|
zpci_err_insn(cc, status, addr, range);
|
|
|
|
|
2017-12-02 01:47:32 +08:00
|
|
|
if (cc == 1 && (status == 4 || status == 16))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-04-16 20:14:44 +08:00
|
|
|
return (cc) ? -EIO : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Interruption Controls */
|
2018-09-27 19:57:12 +08:00
|
|
|
int __zpci_set_irq_ctrl(u16 ctl, u8 isc, union zpci_sic_iib *iib)
|
2013-04-16 20:14:44 +08:00
|
|
|
{
|
2017-10-30 21:38:58 +08:00
|
|
|
if (!test_facility(72))
|
|
|
|
return -EIO;
|
2018-09-27 19:57:12 +08:00
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
".insn rsy,0xeb00000000d1,%[ctl],%[isc],%[iib]\n"
|
|
|
|
: : [ctl] "d" (ctl), [isc] "d" (isc << 27), [iib] "Q" (*iib));
|
|
|
|
|
2017-10-30 21:38:58 +08:00
|
|
|
return 0;
|
2013-04-16 20:14:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PCI Load */
|
2016-06-20 20:03:25 +08:00
|
|
|
static inline int ____pcilg(u64 *data, u64 req, u64 offset, u8 *status)
|
2013-04-16 20:14:44 +08:00
|
|
|
{
|
|
|
|
register u64 __req asm("2") = req;
|
|
|
|
register u64 __offset asm("3") = offset;
|
2013-04-16 20:16:14 +08:00
|
|
|
int cc = -ENXIO;
|
2013-04-16 20:14:44 +08:00
|
|
|
u64 __data;
|
|
|
|
|
|
|
|
asm volatile (
|
|
|
|
" .insn rre,0xb9d20000,%[data],%[req]\n"
|
2013-04-16 20:16:14 +08:00
|
|
|
"0: ipm %[cc]\n"
|
2013-04-16 20:14:44 +08:00
|
|
|
" srl %[cc],28\n"
|
2013-04-16 20:16:14 +08:00
|
|
|
"1:\n"
|
|
|
|
EX_TABLE(0b, 1b)
|
|
|
|
: [cc] "+d" (cc), [data] "=d" (__data), [req] "+d" (__req)
|
2013-04-16 20:14:44 +08:00
|
|
|
: "d" (__offset)
|
|
|
|
: "cc");
|
|
|
|
*status = __req >> 24 & 0xff;
|
2016-06-20 20:03:25 +08:00
|
|
|
*data = __data;
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __pcilg(u64 *data, u64 req, u64 offset, u8 *status)
|
|
|
|
{
|
|
|
|
u64 __data;
|
|
|
|
int cc;
|
|
|
|
|
|
|
|
cc = ____pcilg(&__data, req, offset, status);
|
2013-04-16 20:17:15 +08:00
|
|
|
if (!cc)
|
|
|
|
*data = __data;
|
|
|
|
|
2013-04-16 20:14:44 +08:00
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
2019-04-14 22:25:54 +08:00
|
|
|
int __zpci_load(u64 *data, u64 req, u64 offset)
|
2013-04-16 20:14:44 +08:00
|
|
|
{
|
2013-04-16 20:16:14 +08:00
|
|
|
u8 status;
|
|
|
|
int cc;
|
2013-04-16 20:14:44 +08:00
|
|
|
|
|
|
|
do {
|
|
|
|
cc = __pcilg(data, req, offset, &status);
|
|
|
|
if (cc == 2)
|
|
|
|
udelay(ZPCI_INSN_BUSY_DELAY);
|
|
|
|
} while (cc == 2);
|
|
|
|
|
2013-04-16 20:16:14 +08:00
|
|
|
if (cc)
|
2015-08-19 01:39:27 +08:00
|
|
|
zpci_err_insn(cc, status, req, offset);
|
|
|
|
|
2013-04-16 20:16:14 +08:00
|
|
|
return (cc > 0) ? -EIO : cc;
|
2013-04-16 20:14:44 +08:00
|
|
|
}
|
2019-04-14 22:25:54 +08:00
|
|
|
EXPORT_SYMBOL_GPL(__zpci_load);
|
|
|
|
|
2019-04-14 21:38:01 +08:00
|
|
|
static inline int zpci_load_fh(u64 *data, const volatile void __iomem *addr,
|
|
|
|
unsigned long len)
|
2019-04-14 22:25:54 +08:00
|
|
|
{
|
|
|
|
struct zpci_iomap_entry *entry = &zpci_iomap_start[ZPCI_IDX(addr)];
|
|
|
|
u64 req = ZPCI_CREATE_REQ(entry->fh, entry->bar, len);
|
|
|
|
|
|
|
|
return __zpci_load(data, req, ZPCI_OFFSET(addr));
|
|
|
|
}
|
2019-04-14 21:38:01 +08:00
|
|
|
|
|
|
|
static inline int __pcilg_mio(u64 *data, u64 ioaddr, u64 len, u8 *status)
|
|
|
|
{
|
|
|
|
register u64 addr asm("2") = ioaddr;
|
|
|
|
register u64 r3 asm("3") = len;
|
|
|
|
int cc = -ENXIO;
|
|
|
|
u64 __data;
|
|
|
|
|
|
|
|
asm volatile (
|
|
|
|
" .insn rre,0xb9d60000,%[data],%[ioaddr]\n"
|
|
|
|
"0: ipm %[cc]\n"
|
|
|
|
" srl %[cc],28\n"
|
|
|
|
"1:\n"
|
|
|
|
EX_TABLE(0b, 1b)
|
|
|
|
: [cc] "+d" (cc), [data] "=d" (__data), "+d" (r3)
|
|
|
|
: [ioaddr] "d" (addr)
|
|
|
|
: "cc");
|
|
|
|
*status = r3 >> 24 & 0xff;
|
|
|
|
*data = __data;
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int zpci_load(u64 *data, const volatile void __iomem *addr, unsigned long len)
|
|
|
|
{
|
|
|
|
u8 status;
|
|
|
|
int cc;
|
|
|
|
|
|
|
|
if (!static_branch_unlikely(&have_mio))
|
|
|
|
return zpci_load_fh(data, addr, len);
|
|
|
|
|
|
|
|
cc = __pcilg_mio(data, (__force u64) addr, len, &status);
|
|
|
|
if (cc)
|
|
|
|
zpci_err_insn(cc, status, 0, (__force u64) addr);
|
|
|
|
|
|
|
|
return (cc > 0) ? -EIO : cc;
|
|
|
|
}
|
2013-06-25 20:52:23 +08:00
|
|
|
EXPORT_SYMBOL_GPL(zpci_load);
|
2013-04-16 20:14:44 +08:00
|
|
|
|
|
|
|
/* PCI Store */
|
2013-04-16 20:16:14 +08:00
|
|
|
static inline int __pcistg(u64 data, u64 req, u64 offset, u8 *status)
|
2013-04-16 20:14:44 +08:00
|
|
|
{
|
|
|
|
register u64 __req asm("2") = req;
|
|
|
|
register u64 __offset asm("3") = offset;
|
2013-04-16 20:16:14 +08:00
|
|
|
int cc = -ENXIO;
|
2013-04-16 20:14:44 +08:00
|
|
|
|
|
|
|
asm volatile (
|
|
|
|
" .insn rre,0xb9d00000,%[data],%[req]\n"
|
2013-04-16 20:16:14 +08:00
|
|
|
"0: ipm %[cc]\n"
|
2013-04-16 20:14:44 +08:00
|
|
|
" srl %[cc],28\n"
|
2013-04-16 20:16:14 +08:00
|
|
|
"1:\n"
|
|
|
|
EX_TABLE(0b, 1b)
|
|
|
|
: [cc] "+d" (cc), [req] "+d" (__req)
|
2013-04-16 20:14:44 +08:00
|
|
|
: "d" (__offset), [data] "d" (data)
|
|
|
|
: "cc");
|
|
|
|
*status = __req >> 24 & 0xff;
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
2019-04-14 22:25:54 +08:00
|
|
|
int __zpci_store(u64 data, u64 req, u64 offset)
|
2013-04-16 20:14:44 +08:00
|
|
|
{
|
2013-04-16 20:16:14 +08:00
|
|
|
u8 status;
|
|
|
|
int cc;
|
2013-04-16 20:14:44 +08:00
|
|
|
|
|
|
|
do {
|
|
|
|
cc = __pcistg(data, req, offset, &status);
|
|
|
|
if (cc == 2)
|
|
|
|
udelay(ZPCI_INSN_BUSY_DELAY);
|
|
|
|
} while (cc == 2);
|
|
|
|
|
|
|
|
if (cc)
|
2015-08-19 01:39:27 +08:00
|
|
|
zpci_err_insn(cc, status, req, offset);
|
|
|
|
|
2013-04-16 20:16:14 +08:00
|
|
|
return (cc > 0) ? -EIO : cc;
|
2013-04-16 20:14:44 +08:00
|
|
|
}
|
2019-04-14 22:25:54 +08:00
|
|
|
EXPORT_SYMBOL_GPL(__zpci_store);
|
|
|
|
|
2019-04-14 21:38:01 +08:00
|
|
|
static inline int zpci_store_fh(const volatile void __iomem *addr, u64 data,
|
|
|
|
unsigned long len)
|
2019-04-14 22:25:54 +08:00
|
|
|
{
|
|
|
|
struct zpci_iomap_entry *entry = &zpci_iomap_start[ZPCI_IDX(addr)];
|
|
|
|
u64 req = ZPCI_CREATE_REQ(entry->fh, entry->bar, len);
|
|
|
|
|
|
|
|
return __zpci_store(data, req, ZPCI_OFFSET(addr));
|
|
|
|
}
|
2019-04-14 21:38:01 +08:00
|
|
|
|
|
|
|
static inline int __pcistg_mio(u64 data, u64 ioaddr, u64 len, u8 *status)
|
|
|
|
{
|
|
|
|
register u64 addr asm("2") = ioaddr;
|
|
|
|
register u64 r3 asm("3") = len;
|
|
|
|
int cc = -ENXIO;
|
|
|
|
|
|
|
|
asm volatile (
|
|
|
|
" .insn rre,0xb9d40000,%[data],%[ioaddr]\n"
|
|
|
|
"0: ipm %[cc]\n"
|
|
|
|
" srl %[cc],28\n"
|
|
|
|
"1:\n"
|
|
|
|
EX_TABLE(0b, 1b)
|
|
|
|
: [cc] "+d" (cc), "+d" (r3)
|
|
|
|
: [data] "d" (data), [ioaddr] "d" (addr)
|
|
|
|
: "cc");
|
|
|
|
*status = r3 >> 24 & 0xff;
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int zpci_store(const volatile void __iomem *addr, u64 data, unsigned long len)
|
|
|
|
{
|
|
|
|
u8 status;
|
|
|
|
int cc;
|
|
|
|
|
|
|
|
if (!static_branch_unlikely(&have_mio))
|
|
|
|
return zpci_store_fh(addr, data, len);
|
|
|
|
|
|
|
|
cc = __pcistg_mio(data, (__force u64) addr, len, &status);
|
|
|
|
if (cc)
|
|
|
|
zpci_err_insn(cc, status, 0, (__force u64) addr);
|
|
|
|
|
|
|
|
return (cc > 0) ? -EIO : cc;
|
|
|
|
}
|
2013-06-25 20:52:23 +08:00
|
|
|
EXPORT_SYMBOL_GPL(zpci_store);
|
2013-04-16 20:14:44 +08:00
|
|
|
|
|
|
|
/* PCI Store Block */
|
2013-04-16 20:16:14 +08:00
|
|
|
static inline int __pcistb(const u64 *data, u64 req, u64 offset, u8 *status)
|
2013-04-16 20:14:44 +08:00
|
|
|
{
|
2013-04-16 20:16:14 +08:00
|
|
|
int cc = -ENXIO;
|
2013-04-16 20:14:44 +08:00
|
|
|
|
|
|
|
asm volatile (
|
|
|
|
" .insn rsy,0xeb00000000d0,%[req],%[offset],%[data]\n"
|
2013-04-16 20:16:14 +08:00
|
|
|
"0: ipm %[cc]\n"
|
2013-04-16 20:14:44 +08:00
|
|
|
" srl %[cc],28\n"
|
2013-04-16 20:16:14 +08:00
|
|
|
"1:\n"
|
|
|
|
EX_TABLE(0b, 1b)
|
|
|
|
: [cc] "+d" (cc), [req] "+d" (req)
|
2013-04-16 20:14:44 +08:00
|
|
|
: [offset] "d" (offset), [data] "Q" (*data)
|
|
|
|
: "cc");
|
|
|
|
*status = req >> 24 & 0xff;
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
2019-04-14 22:25:54 +08:00
|
|
|
int __zpci_store_block(const u64 *data, u64 req, u64 offset)
|
2013-04-16 20:14:44 +08:00
|
|
|
{
|
2013-04-16 20:16:14 +08:00
|
|
|
u8 status;
|
|
|
|
int cc;
|
2013-04-16 20:14:44 +08:00
|
|
|
|
|
|
|
do {
|
|
|
|
cc = __pcistb(data, req, offset, &status);
|
|
|
|
if (cc == 2)
|
|
|
|
udelay(ZPCI_INSN_BUSY_DELAY);
|
|
|
|
} while (cc == 2);
|
|
|
|
|
|
|
|
if (cc)
|
2015-08-19 01:39:27 +08:00
|
|
|
zpci_err_insn(cc, status, req, offset);
|
|
|
|
|
2013-04-16 20:16:14 +08:00
|
|
|
return (cc > 0) ? -EIO : cc;
|
2013-04-16 20:14:44 +08:00
|
|
|
}
|
2019-04-14 22:25:54 +08:00
|
|
|
EXPORT_SYMBOL_GPL(__zpci_store_block);
|
|
|
|
|
2019-04-14 21:38:01 +08:00
|
|
|
static inline int zpci_write_block_fh(volatile void __iomem *dst,
|
|
|
|
const void *src, unsigned long len)
|
2019-04-14 22:25:54 +08:00
|
|
|
{
|
|
|
|
struct zpci_iomap_entry *entry = &zpci_iomap_start[ZPCI_IDX(dst)];
|
|
|
|
u64 req = ZPCI_CREATE_REQ(entry->fh, entry->bar, len);
|
|
|
|
u64 offset = ZPCI_OFFSET(dst);
|
|
|
|
|
|
|
|
return __zpci_store_block(src, req, offset);
|
|
|
|
}
|
2019-04-14 21:38:01 +08:00
|
|
|
|
|
|
|
static inline int __pcistb_mio(const u64 *data, u64 ioaddr, u64 len, u8 *status)
|
|
|
|
{
|
|
|
|
int cc = -ENXIO;
|
|
|
|
|
|
|
|
asm volatile (
|
|
|
|
" .insn rsy,0xeb00000000d4,%[len],%[ioaddr],%[data]\n"
|
|
|
|
"0: ipm %[cc]\n"
|
|
|
|
" srl %[cc],28\n"
|
|
|
|
"1:\n"
|
|
|
|
EX_TABLE(0b, 1b)
|
|
|
|
: [cc] "+d" (cc), [len] "+d" (len)
|
|
|
|
: [ioaddr] "d" (ioaddr), [data] "Q" (*data)
|
|
|
|
: "cc");
|
|
|
|
*status = len >> 24 & 0xff;
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int zpci_write_block(volatile void __iomem *dst,
|
|
|
|
const void *src, unsigned long len)
|
|
|
|
{
|
|
|
|
u8 status;
|
|
|
|
int cc;
|
|
|
|
|
|
|
|
if (!static_branch_unlikely(&have_mio))
|
|
|
|
return zpci_write_block_fh(dst, src, len);
|
|
|
|
|
|
|
|
cc = __pcistb_mio(src, (__force u64) dst, len, &status);
|
|
|
|
if (cc)
|
|
|
|
zpci_err_insn(cc, status, 0, (__force u64) dst);
|
|
|
|
|
|
|
|
return (cc > 0) ? -EIO : cc;
|
|
|
|
}
|
2019-04-14 22:25:54 +08:00
|
|
|
EXPORT_SYMBOL_GPL(zpci_write_block);
|
2019-04-14 21:38:01 +08:00
|
|
|
|
|
|
|
static inline void __pciwb_mio(void)
|
|
|
|
{
|
|
|
|
unsigned long unused = 0;
|
|
|
|
|
|
|
|
asm volatile (".insn rre,0xb9d50000,%[op],%[op]\n"
|
|
|
|
: [op] "+d" (unused));
|
|
|
|
}
|
|
|
|
|
|
|
|
void zpci_barrier(void)
|
|
|
|
{
|
|
|
|
if (static_branch_likely(&have_mio))
|
|
|
|
__pciwb_mio();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(zpci_barrier);
|