static int
tim_fill_msix(struct roc_tim *roc_tim, uint16_t nb_ring)
{
- struct dev *dev = &roc_sso_to_sso_priv(roc_tim->roc_sso)->dev;
+ struct sso *sso = roc_sso_to_sso_priv(roc_tim->roc_sso);
struct tim *tim = roc_tim_to_tim_priv(roc_tim);
+ struct dev *dev = &sso->dev;
struct msix_offset_rsp *rsp;
int i, rc;
mbox_alloc_msg_msix_offset(dev->mbox);
rc = mbox_process_msg(dev->mbox, (void **)&rsp);
- if (rc < 0)
- return rc;
+ if (rc)
+ return -EIO;
for (i = 0; i < nb_ring; i++)
tim->tim_msix_offsets[i] = rsp->timlf_msixoff[i];
roc_tim_lf_enable(struct roc_tim *roc_tim, uint8_t ring_id, uint64_t *start_tsc,
uint32_t *cur_bkt)
{
- struct dev *dev = &roc_sso_to_sso_priv(roc_tim->roc_sso)->dev;
+ struct sso *sso = roc_sso_to_sso_priv(roc_tim->roc_sso);
+ struct dev *dev = &sso->dev;
struct tim_enable_rsp *rsp;
struct tim_ring_req *req;
int rc = -ENOSPC;
+ plt_spinlock_lock(&sso->mbox_lock);
req = mbox_alloc_msg_tim_enable_ring(dev->mbox);
if (req == NULL)
- return rc;
+ goto fail;
req->ring = ring_id;
rc = mbox_process_msg(dev->mbox, (void **)&rsp);
- if (rc < 0) {
+ if (rc) {
tim_err_desc(rc);
- return rc;
+ rc = -EIO;
+ goto fail;
}
if (cur_bkt)
if (start_tsc)
*start_tsc = rsp->timestarted;
- return 0;
+fail:
+ plt_spinlock_unlock(&sso->mbox_lock);
+ return rc;
}
int
roc_tim_lf_disable(struct roc_tim *roc_tim, uint8_t ring_id)
{
- struct dev *dev = &roc_sso_to_sso_priv(roc_tim->roc_sso)->dev;
+ struct sso *sso = roc_sso_to_sso_priv(roc_tim->roc_sso);
+ struct dev *dev = &sso->dev;
struct tim_ring_req *req;
int rc = -ENOSPC;
+ plt_spinlock_lock(&sso->mbox_lock);
req = mbox_alloc_msg_tim_disable_ring(dev->mbox);
if (req == NULL)
- return rc;
+ goto fail;
req->ring = ring_id;
rc = mbox_process(dev->mbox);
- if (rc < 0) {
+ if (rc) {
tim_err_desc(rc);
- return rc;
+ rc = -EIO;
}
- return 0;
+fail:
+ plt_spinlock_unlock(&sso->mbox_lock);
+ return rc;
}
uintptr_t
roc_tim_lf_config(struct roc_tim *roc_tim, uint8_t ring_id,
enum roc_tim_clk_src clk_src, uint8_t ena_periodic,
uint8_t ena_dfb, uint32_t bucket_sz, uint32_t chunk_sz,
- uint32_t interval)
+ uint32_t interval, uint64_t intervalns, uint64_t clockfreq)
{
- struct dev *dev = &roc_sso_to_sso_priv(roc_tim->roc_sso)->dev;
+ struct sso *sso = roc_sso_to_sso_priv(roc_tim->roc_sso);
+ struct dev *dev = &sso->dev;
struct tim_config_req *req;
int rc = -ENOSPC;
+ plt_spinlock_lock(&sso->mbox_lock);
req = mbox_alloc_msg_tim_config_ring(dev->mbox);
if (req == NULL)
- return rc;
+ goto fail;
req->ring = ring_id;
req->bigendian = false;
req->bucketsize = bucket_sz;
req->enableperiodic = ena_periodic;
req->enabledontfreebuffer = ena_dfb;
req->interval = interval;
+ req->intervalns = intervalns;
+ req->clockfreq = clockfreq;
req->gpioedge = TIM_GPIO_LTOH_TRANS;
rc = mbox_process(dev->mbox);
- if (rc < 0) {
+ if (rc) {
tim_err_desc(rc);
- return rc;
+ rc = -EIO;
}
- return 0;
+fail:
+ plt_spinlock_unlock(&sso->mbox_lock);
+ return rc;
+}
+
+int
+roc_tim_lf_interval(struct roc_tim *roc_tim, enum roc_tim_clk_src clk_src,
+ uint64_t clockfreq, uint64_t *intervalns,
+ uint64_t *interval)
+{
+ struct sso *sso = roc_sso_to_sso_priv(roc_tim->roc_sso);
+ struct dev *dev = &sso->dev;
+ struct tim_intvl_req *req;
+ struct tim_intvl_rsp *rsp;
+ int rc = -ENOSPC;
+
+ plt_spinlock_lock(&sso->mbox_lock);
+ req = mbox_alloc_msg_tim_get_min_intvl(dev->mbox);
+ if (req == NULL)
+ goto fail;
+
+ req->clockfreq = clockfreq;
+ req->clocksource = clk_src;
+ rc = mbox_process_msg(dev->mbox, (void **)&rsp);
+ if (rc) {
+ tim_err_desc(rc);
+ rc = -EIO;
+ goto fail;
+ }
+
+ *intervalns = rsp->intvl_ns;
+ *interval = rsp->intvl_cyc;
+
+fail:
+ plt_spinlock_unlock(&sso->mbox_lock);
+ return rc;
}
int
struct dev *dev = &sso->dev;
int rc = -ENOSPC;
+ plt_spinlock_lock(&sso->mbox_lock);
req = mbox_alloc_msg_tim_lf_alloc(dev->mbox);
if (req == NULL)
- return rc;
+ goto fail;
req->npa_pf_func = idev_npa_pffunc_get();
req->sso_pf_func = idev_sso_pffunc_get();
req->ring = ring_id;
rc = mbox_process_msg(dev->mbox, (void **)&rsp);
- if (rc < 0) {
+ if (rc) {
tim_err_desc(rc);
- return rc;
+ rc = -EIO;
+ goto fail;
}
if (clk)
*clk = rsp->tenns_clk;
- rc = tim_register_irq_priv(roc_tim, &sso->pci_dev->intr_handle, ring_id,
+ rc = tim_register_irq_priv(roc_tim, sso->pci_dev->intr_handle, ring_id,
tim->tim_msix_offsets[ring_id]);
if (rc < 0) {
plt_tim_dbg("Failed to register Ring[%d] IRQ", ring_id);
free_req = mbox_alloc_msg_tim_lf_free(dev->mbox);
- if (free_req == NULL)
- return -ENOSPC;
+ if (free_req == NULL) {
+ rc = -ENOSPC;
+ goto fail;
+ }
free_req->ring = ring_id;
- mbox_process(dev->mbox);
+ rc = mbox_process(dev->mbox);
+ if (rc)
+ rc = -EIO;
}
+fail:
+ plt_spinlock_unlock(&sso->mbox_lock);
return rc;
}
struct tim_ring_req *req;
int rc = -ENOSPC;
- tim_unregister_irq_priv(roc_tim, &sso->pci_dev->intr_handle, ring_id,
+ tim_unregister_irq_priv(roc_tim, sso->pci_dev->intr_handle, ring_id,
tim->tim_msix_offsets[ring_id]);
+ plt_spinlock_lock(&sso->mbox_lock);
req = mbox_alloc_msg_tim_lf_free(dev->mbox);
if (req == NULL)
- return rc;
+ goto fail;
req->ring = ring_id;
rc = mbox_process(dev->mbox);
if (rc < 0) {
tim_err_desc(rc);
- return rc;
+ rc = -EIO;
}
+fail:
+ plt_spinlock_unlock(&sso->mbox_lock);
return 0;
}
struct rsrc_attach_req *attach_req;
struct rsrc_detach_req *detach_req;
struct free_rsrcs_rsp *free_rsrc;
- struct dev *dev;
+ struct sso *sso;
uint16_t nb_lfs;
+ struct dev *dev;
int rc;
if (roc_tim == NULL || roc_tim->roc_sso == NULL)
return TIM_ERR_PARAM;
+ sso = roc_sso_to_sso_priv(roc_tim->roc_sso);
+ dev = &sso->dev;
PLT_STATIC_ASSERT(sizeof(struct tim) <= TIM_MEM_SZ);
- dev = &roc_sso_to_sso_priv(roc_tim->roc_sso)->dev;
nb_lfs = roc_tim->nb_lfs;
+ plt_spinlock_lock(&sso->mbox_lock);
mbox_alloc_msg_free_rsrc_cnt(dev->mbox);
rc = mbox_process_msg(dev->mbox, (void *)&free_rsrc);
- if (rc < 0) {
+ if (rc) {
plt_err("Unable to get free rsrc count.");
- return 0;
+ nb_lfs = 0;
+ goto fail;
}
if (nb_lfs && (free_rsrc->tim < nb_lfs)) {
plt_tim_dbg("Requested LFs : %d Available LFs : %d", nb_lfs,
free_rsrc->tim);
- return 0;
+ nb_lfs = 0;
+ goto fail;
}
attach_req = mbox_alloc_msg_attach_resources(dev->mbox);
- if (attach_req == NULL)
- return -ENOSPC;
+ if (attach_req == NULL) {
+ nb_lfs = 0;
+ goto fail;
+ }
attach_req->modify = true;
attach_req->timlfs = nb_lfs ? nb_lfs : free_rsrc->tim;
nb_lfs = attach_req->timlfs;
rc = mbox_process(dev->mbox);
- if (rc < 0) {
+ if (rc) {
plt_err("Unable to attach TIM LFs.");
- return 0;
+ nb_lfs = 0;
+ goto fail;
}
rc = tim_fill_msix(roc_tim, nb_lfs);
plt_err("Unable to get TIM MSIX vectors");
detach_req = mbox_alloc_msg_detach_resources(dev->mbox);
- if (detach_req == NULL)
- return -ENOSPC;
+ if (detach_req == NULL) {
+ nb_lfs = 0;
+ goto fail;
+ }
detach_req->partial = true;
detach_req->timlfs = true;
mbox_process(dev->mbox);
-
- return 0;
+ nb_lfs = 0;
}
+fail:
+ plt_spinlock_unlock(&sso->mbox_lock);
return nb_lfs;
}
void
roc_tim_fini(struct roc_tim *roc_tim)
{
- struct dev *dev = &roc_sso_to_sso_priv(roc_tim->roc_sso)->dev;
+ struct sso *sso = roc_sso_to_sso_priv(roc_tim->roc_sso);
struct rsrc_detach_req *detach_req;
+ struct dev *dev = &sso->dev;
+ plt_spinlock_lock(&sso->mbox_lock);
detach_req = mbox_alloc_msg_detach_resources(dev->mbox);
PLT_ASSERT(detach_req);
detach_req->partial = true;
detach_req->timlfs = true;
mbox_process(dev->mbox);
+ plt_spinlock_unlock(&sso->mbox_lock);
}