aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/ntb/ntb_transport.c
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2016-07-28 10:48:20 +0000
committerAlexander Motin <mav@FreeBSD.org>2016-07-28 10:48:20 +0000
commit4490696b3edf3ed9be81e695fb9dba03c94f89c8 (patch)
tree14aa7c882c4f61eb1585ef04136f31df54d67e1e /sys/dev/ntb/ntb_transport.c
parentb4a395a41ba6f5f888c20c07de2334d23bc89726 (diff)
downloadsrc-4490696b3edf3ed9be81e695fb9dba03c94f89c8.tar.gz
src-4490696b3edf3ed9be81e695fb9dba03c94f89c8.zip
Once more refactor KPI between NTB hardware and consumers.
New design allows hardware resources to be split between several consumers. For example, one BAR can be dedicated for remote memory access, while other resources can be used for packet transport for virtual Ethernet interface. And even without resource split, this code allows to specify which consumer driver should attach the hardware. From some points this makes the code even closer to Linux one, even though Linux does not provide the described flexibility.
Notes
Notes: svn path=/head/; revision=303429
Diffstat (limited to 'sys/dev/ntb/ntb_transport.c')
-rw-r--r--sys/dev/ntb/ntb_transport.c89
1 files changed, 42 insertions, 47 deletions
diff --git a/sys/dev/ntb/ntb_transport.c b/sys/dev/ntb/ntb_transport.c
index 6c1c5519fc28..d3ea6df1591d 100644
--- a/sys/dev/ntb/ntb_transport.c
+++ b/sys/dev/ntb/ntb_transport.c
@@ -130,7 +130,7 @@ struct ntb_rx_info {
struct ntb_transport_qp {
struct ntb_transport_ctx *transport;
- device_t ntb;
+ device_t dev;
void *cb_data;
@@ -202,7 +202,6 @@ struct ntb_transport_mw {
struct ntb_transport_ctx {
device_t dev;
- device_t ntb;
struct ntb_transport_mw *mw_vec;
struct ntb_transport_qp *qp_vec;
struct _qpset qp_bitmap;
@@ -317,7 +316,7 @@ xeon_link_watchdog_hb(void *arg)
struct ntb_transport_ctx *nt;
nt = arg;
- NTB_SPAD_WRITE(nt->ntb, NTBT_WATCHDOG_SPAD, 0);
+ ntb_spad_write(nt->dev, NTBT_WATCHDOG_SPAD, 0);
callout_reset(&nt->link_watchdog, 1 * hz, xeon_link_watchdog_hb, nt);
}
@@ -333,21 +332,19 @@ static int
ntb_transport_attach(device_t dev)
{
struct ntb_transport_ctx *nt = device_get_softc(dev);
- device_t ntb = device_get_parent(dev);
struct ntb_transport_mw *mw;
uint64_t qp_bitmap;
int rc;
unsigned i;
nt->dev = dev;
- nt->ntb = ntb;
- nt->mw_count = NTB_MW_COUNT(ntb);
+ nt->mw_count = ntb_mw_count(dev);
nt->mw_vec = malloc(nt->mw_count * sizeof(*nt->mw_vec), M_NTB_T,
M_WAITOK | M_ZERO);
for (i = 0; i < nt->mw_count; i++) {
mw = &nt->mw_vec[i];
- rc = NTB_MW_GET_RANGE(ntb, i, &mw->phys_addr, &mw->vbase,
+ rc = ntb_mw_get_range(dev, i, &mw->phys_addr, &mw->vbase,
&mw->phys_size, &mw->xlat_align, &mw->xlat_align_size,
&mw->addr_limit);
if (rc != 0)
@@ -358,12 +355,12 @@ ntb_transport_attach(device_t dev)
mw->virt_addr = NULL;
mw->dma_addr = 0;
- rc = NTB_MW_SET_WC(nt->ntb, i, VM_MEMATTR_WRITE_COMBINING);
+ rc = ntb_mw_set_wc(dev, i, VM_MEMATTR_WRITE_COMBINING);
if (rc)
ntb_printf(0, "Unable to set mw%d caching\n", i);
}
- qp_bitmap = NTB_DB_VALID_MASK(ntb);
+ qp_bitmap = ntb_db_valid_mask(dev);
nt->qp_count = flsll(qp_bitmap);
KASSERT(nt->qp_count != 0, ("bogus db bitmap"));
nt->qp_count -= 1;
@@ -387,12 +384,12 @@ ntb_transport_attach(device_t dev)
callout_init(&nt->link_watchdog, 0);
TASK_INIT(&nt->link_cleanup, 0, ntb_transport_link_cleanup_work, nt);
- rc = NTB_SET_CTX(ntb, nt, &ntb_transport_ops);
+ rc = ntb_set_ctx(dev, nt, &ntb_transport_ops);
if (rc != 0)
goto err;
nt->link_is_up = false;
- NTB_LINK_ENABLE(ntb, NTB_SPEED_AUTO, NTB_WIDTH_AUTO);
+ ntb_link_enable(dev, NTB_SPEED_AUTO, NTB_WIDTH_AUTO);
if (enable_xeon_watchdog != 0)
callout_reset(&nt->link_watchdog, 0, xeon_link_watchdog_hb, nt);
@@ -413,7 +410,6 @@ static int
ntb_transport_detach(device_t dev)
{
struct ntb_transport_ctx *nt = device_get_softc(dev);
- device_t ntb = nt->ntb;
struct _qpset qp_bitmap_alloc;
uint8_t i;
@@ -433,8 +429,8 @@ ntb_transport_detach(device_t dev)
if (test_bit(i, &qp_bitmap_alloc))
ntb_transport_free_queue(&nt->qp_vec[i]);
- NTB_LINK_DISABLE(ntb);
- NTB_CLEAR_CTX(ntb);
+ ntb_link_disable(dev);
+ ntb_clear_ctx(dev);
for (i = 0; i < nt->mw_count; i++)
ntb_free_mw(nt, i);
@@ -461,7 +457,7 @@ ntb_transport_init_queue(struct ntb_transport_ctx *nt, unsigned int qp_num)
qp = &nt->qp_vec[qp_num];
qp->qp_num = qp_num;
qp->transport = nt;
- qp->ntb = nt->ntb;
+ qp->dev = nt->dev;
qp->client_ready = false;
qp->event_handler = NULL;
ntb_qp_link_down_reset(qp);
@@ -518,7 +514,7 @@ ntb_transport_free_queue(struct ntb_transport_qp *qp)
callout_drain(&qp->link_work);
- NTB_DB_SET_MASK(qp->ntb, 1ull << qp->qp_num);
+ ntb_db_set_mask(qp->dev, 1ull << qp->qp_num);
taskqueue_drain_all(qp->rxc_tq);
taskqueue_free(qp->rxc_tq);
@@ -558,7 +554,6 @@ ntb_transport_create_queue(void *data, device_t dev,
const struct ntb_queue_handlers *handlers)
{
struct ntb_transport_ctx *nt = device_get_softc(dev);
- device_t ntb = device_get_parent(dev);
struct ntb_queue_entry *entry;
struct ntb_transport_qp *qp;
unsigned int free_queue;
@@ -593,7 +588,7 @@ ntb_transport_create_queue(void *data, device_t dev,
ntb_list_add(&qp->ntb_tx_free_q_lock, entry, &qp->tx_free_q);
}
- NTB_DB_CLEAR(ntb, 1ull << qp->qp_num);
+ ntb_db_clear(dev, 1ull << qp->qp_num);
return (qp);
}
@@ -680,7 +675,7 @@ ntb_tx_copy_callback(void *data)
iowrite32(entry->flags | NTBT_DESC_DONE_FLAG, &hdr->flags);
CTR1(KTR_NTB, "TX: hdr %p set DESC_DONE", hdr);
- NTB_PEER_DB_SET(qp->ntb, 1ull << qp->qp_num);
+ ntb_peer_db_set(qp->dev, 1ull << qp->qp_num);
/*
* The entry length can only be zero if the packet is intended to be a
@@ -790,9 +785,9 @@ again:
;
CTR1(KTR_NTB, "RX: process_rxc returned %d", rc);
- if ((NTB_DB_READ(qp->ntb) & (1ull << qp->qp_num)) != 0) {
+ if ((ntb_db_read(qp->dev) & (1ull << qp->qp_num)) != 0) {
/* If db is set, clear it and check queue once more. */
- NTB_DB_CLEAR(qp->ntb, 1ull << qp->qp_num);
+ ntb_db_clear(qp->dev, 1ull << qp->qp_num);
goto again;
}
}
@@ -956,9 +951,9 @@ ntb_transport_doorbell_callback(void *data, uint32_t vector)
BIT_COPY(QP_SETSIZE, &nt->qp_bitmap, &db_bits);
BIT_NAND(QP_SETSIZE, &db_bits, &nt->qp_bitmap_free);
- vec_mask = NTB_DB_VECTOR_MASK(nt->ntb, vector);
+ vec_mask = ntb_db_vector_mask(nt->dev, vector);
if ((vec_mask & (vec_mask - 1)) != 0)
- vec_mask &= NTB_DB_READ(nt->ntb);
+ vec_mask &= ntb_db_read(nt->dev);
while (vec_mask != 0) {
qp_num = ffsll(vec_mask) - 1;
@@ -978,7 +973,7 @@ ntb_transport_event_callback(void *data)
{
struct ntb_transport_ctx *nt = data;
- if (NTB_LINK_IS_UP(nt->ntb, NULL, NULL)) {
+ if (ntb_link_is_up(nt->dev, NULL, NULL)) {
ntb_printf(1, "HW link up\n");
callout_reset(&nt->link_work, 0, ntb_transport_link_work, nt);
} else {
@@ -992,7 +987,7 @@ static void
ntb_transport_link_work(void *arg)
{
struct ntb_transport_ctx *nt = arg;
- device_t ntb = nt->ntb;
+ device_t dev = nt->dev;
struct ntb_transport_qp *qp;
uint64_t val64, size;
uint32_t val;
@@ -1006,36 +1001,36 @@ ntb_transport_link_work(void *arg)
if (max_mw_size != 0 && size > max_mw_size)
size = max_mw_size;
- NTB_PEER_SPAD_WRITE(ntb, NTBT_MW0_SZ_HIGH + (i * 2),
+ ntb_peer_spad_write(dev, NTBT_MW0_SZ_HIGH + (i * 2),
size >> 32);
- NTB_PEER_SPAD_WRITE(ntb, NTBT_MW0_SZ_LOW + (i * 2), size);
+ ntb_peer_spad_write(dev, NTBT_MW0_SZ_LOW + (i * 2), size);
}
- NTB_PEER_SPAD_WRITE(ntb, NTBT_NUM_MWS, nt->mw_count);
+ ntb_peer_spad_write(dev, NTBT_NUM_MWS, nt->mw_count);
- NTB_PEER_SPAD_WRITE(ntb, NTBT_NUM_QPS, nt->qp_count);
+ ntb_peer_spad_write(dev, NTBT_NUM_QPS, nt->qp_count);
- NTB_PEER_SPAD_WRITE(ntb, NTBT_VERSION, NTB_TRANSPORT_VERSION);
+ ntb_peer_spad_write(dev, NTBT_VERSION, NTB_TRANSPORT_VERSION);
/* Query the remote side for its info */
val = 0;
- NTB_SPAD_READ(ntb, NTBT_VERSION, &val);
+ ntb_spad_read(dev, NTBT_VERSION, &val);
if (val != NTB_TRANSPORT_VERSION)
goto out;
- NTB_SPAD_READ(ntb, NTBT_NUM_QPS, &val);
+ ntb_spad_read(dev, NTBT_NUM_QPS, &val);
if (val != nt->qp_count)
goto out;
- NTB_SPAD_READ(ntb, NTBT_NUM_MWS, &val);
+ ntb_spad_read(dev, NTBT_NUM_MWS, &val);
if (val != nt->mw_count)
goto out;
for (i = 0; i < nt->mw_count; i++) {
- NTB_SPAD_READ(ntb, NTBT_MW0_SZ_HIGH + (i * 2), &val);
+ ntb_spad_read(dev, NTBT_MW0_SZ_HIGH + (i * 2), &val);
val64 = (uint64_t)val << 32;
- NTB_SPAD_READ(ntb, NTBT_MW0_SZ_LOW + (i * 2), &val);
+ ntb_spad_read(dev, NTBT_MW0_SZ_LOW + (i * 2), &val);
val64 |= val;
rc = ntb_set_mw(nt, i, val64);
@@ -1061,7 +1056,7 @@ free_mws:
for (i = 0; i < nt->mw_count; i++)
ntb_free_mw(nt, i);
out:
- if (NTB_LINK_IS_UP(ntb, NULL, NULL))
+ if (ntb_link_is_up(dev, NULL, NULL))
callout_reset(&nt->link_work,
NTB_LINK_DOWN_TIMEOUT * hz / 1000, ntb_transport_link_work, nt);
}
@@ -1116,7 +1111,7 @@ ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, size_t size)
}
/* Notify HW the memory location of the receive buffer */
- rc = NTB_MW_SET_TRANS(nt->ntb, num_mw, mw->dma_addr, mw->xlat_size);
+ rc = ntb_mw_set_trans(nt->dev, num_mw, mw->dma_addr, mw->xlat_size);
if (rc) {
ntb_printf(0, "Unable to set mw%d translation\n", num_mw);
ntb_free_mw(nt, num_mw);
@@ -1134,7 +1129,7 @@ ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw)
if (mw->virt_addr == NULL)
return;
- NTB_MW_CLEAR_TRANS(nt->ntb, num_mw);
+ ntb_mw_clear_trans(nt->dev, num_mw);
contigfree(mw->virt_addr, mw->xlat_size, M_NTB_T);
mw->xlat_size = 0;
mw->buff_size = 0;
@@ -1194,16 +1189,16 @@ static void
ntb_qp_link_work(void *arg)
{
struct ntb_transport_qp *qp = arg;
- device_t ntb = qp->ntb;
+ device_t dev = qp->dev;
struct ntb_transport_ctx *nt = qp->transport;
uint32_t val, dummy;
- NTB_SPAD_READ(ntb, NTBT_QP_LINKS, &val);
+ ntb_spad_read(dev, NTBT_QP_LINKS, &val);
- NTB_PEER_SPAD_WRITE(ntb, NTBT_QP_LINKS, val | (1ull << qp->qp_num));
+ ntb_peer_spad_write(dev, NTBT_QP_LINKS, val | (1ull << qp->qp_num));
/* query remote spad for qp ready bits */
- NTB_PEER_SPAD_READ(ntb, NTBT_QP_LINKS, &dummy);
+ ntb_peer_spad_read(dev, NTBT_QP_LINKS, &dummy);
/* See if the remote side is up */
if ((val & (1ull << qp->qp_num)) != 0) {
@@ -1213,7 +1208,7 @@ ntb_qp_link_work(void *arg)
if (qp->event_handler != NULL)
qp->event_handler(qp->cb_data, NTB_LINK_UP);
- NTB_DB_CLEAR_MASK(ntb, 1ull << qp->qp_num);
+ ntb_db_clear_mask(dev, 1ull << qp->qp_num);
} else if (nt->link_is_up)
callout_reset(&qp->link_work,
NTB_LINK_DOWN_TIMEOUT * hz / 1000, ntb_qp_link_work, qp);
@@ -1247,7 +1242,7 @@ ntb_transport_link_cleanup(struct ntb_transport_ctx *nt)
* time they are accessed
*/
for (i = 0; i < NTBT_MAX_SPAD; i++)
- NTB_SPAD_WRITE(nt->ntb, i, 0);
+ ntb_spad_write(nt->dev, i, 0);
}
static void
@@ -1269,7 +1264,7 @@ ntb_qp_link_down_reset(struct ntb_transport_qp *qp)
{
qp->link_is_up = false;
- NTB_DB_SET_MASK(qp->ntb, 1ull << qp->qp_num);
+ ntb_db_set_mask(qp->dev, 1ull << qp->qp_num);
qp->tx_index = qp->rx_index = 0;
qp->tx_bytes = qp->rx_bytes = 0;
@@ -1312,9 +1307,9 @@ ntb_transport_link_down(struct ntb_transport_qp *qp)
qp->client_ready = false;
- NTB_SPAD_READ(qp->ntb, NTBT_QP_LINKS, &val);
+ ntb_spad_read(qp->dev, NTBT_QP_LINKS, &val);
- NTB_PEER_SPAD_WRITE(qp->ntb, NTBT_QP_LINKS,
+ ntb_peer_spad_write(qp->dev, NTBT_QP_LINKS,
val & ~(1 << qp->qp_num));
if (qp->link_is_up)