1 /**********************************************************************
4 * Contact: support@cavium.com
5 * Please include "LiquidIO" in the subject.
7 * Copyright (c) 2003-2016 Cavium, Inc.
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more
18 **********************************************************************/
19 #include <linux/pci.h>
20 #include <linux/netdevice.h>
21 #include <linux/vmalloc.h>
22 #include "liquidio_common.h"
23 #include "octeon_droq.h"
24 #include "octeon_iq.h"
25 #include "response_manager.h"
26 #include "octeon_device.h"
27 #include "octeon_main.h"
28 #include "octeon_network.h"
29 #include "cn66xx_device.h"
30 #include "cn23xx_pf_device.h"
31 #include "cn23xx_vf_device.h"
33 struct iq_post_status {
38 static void check_db_timeout(struct work_struct *work);
39 static void __check_db_timeout(struct octeon_device *oct, u64 iq_no);
41 static void (*reqtype_free_fn[MAX_OCTEON_DEVICES][REQTYPE_LAST + 1]) (void *);
43 static inline int IQ_INSTR_MODE_64B(struct octeon_device *oct, int iq_no)
45 struct octeon_instr_queue *iq =
46 (struct octeon_instr_queue *)oct->instr_queue[iq_no];
50 #define IQ_INSTR_MODE_32B(oct, iq_no) (!IQ_INSTR_MODE_64B(oct, iq_no))
52 /* Define this to return the request status comaptible to old code */
53 /*#define OCTEON_USE_OLD_REQ_STATUS*/
55 /* Return 0 on success, 1 on failure */
56 int octeon_init_instr_queue(struct octeon_device *oct,
57 union oct_txpciq txpciq,
60 struct octeon_instr_queue *iq;
61 struct octeon_iq_config *conf = NULL;
62 u32 iq_no = (u32)txpciq.s.q_no;
64 struct cavium_wq *db_wq;
65 int numa_node = dev_to_node(&oct->pci_dev->dev);
67 if (OCTEON_CN6XXX(oct))
68 conf = &(CFG_GET_IQ_CFG(CHIP_CONF(oct, cn6xxx)));
69 else if (OCTEON_CN23XX_PF(oct))
70 conf = &(CFG_GET_IQ_CFG(CHIP_CONF(oct, cn23xx_pf)));
71 else if (OCTEON_CN23XX_VF(oct))
72 conf = &(CFG_GET_IQ_CFG(CHIP_CONF(oct, cn23xx_vf)));
75 dev_err(&oct->pci_dev->dev, "Unsupported Chip %x\n",
80 q_size = (u32)conf->instr_type * num_descs;
82 iq = oct->instr_queue[iq_no];
86 iq->base_addr = lio_dma_alloc(oct, q_size, &iq->base_addr_dma);
88 dev_err(&oct->pci_dev->dev, "Cannot allocate memory for instr queue %d\n",
93 iq->max_count = num_descs;
95 /* Initialize a list to holds requests that have been posted to Octeon
96 * but has yet to be fetched by octeon
98 iq->request_list = vmalloc_node((sizeof(*iq->request_list) * num_descs),
100 if (!iq->request_list)
101 iq->request_list = vmalloc(sizeof(*iq->request_list) *
103 if (!iq->request_list) {
104 lio_dma_free(oct, q_size, iq->base_addr, iq->base_addr_dma);
105 dev_err(&oct->pci_dev->dev, "Alloc failed for IQ[%d] nr free list\n",
110 memset(iq->request_list, 0, sizeof(*iq->request_list) * num_descs);
112 dev_dbg(&oct->pci_dev->dev, "IQ[%d]: base: %p basedma: %llx count: %d\n",
113 iq_no, iq->base_addr, iq->base_addr_dma, iq->max_count);
115 iq->txpciq.u64 = txpciq.u64;
116 iq->fill_threshold = (u32)conf->db_min;
118 iq->host_write_index = 0;
119 iq->octeon_read_index = 0;
121 iq->last_db_time = 0;
122 iq->do_auto_flush = 1;
123 iq->db_timeout = (u32)conf->db_timeout;
124 atomic_set(&iq->instr_pending, 0);
125 iq->pkts_processed = 0;
127 /* Initialize the spinlock for this instruction queue */
128 spin_lock_init(&iq->lock);
129 spin_lock_init(&iq->post_lock);
131 spin_lock_init(&iq->iq_flush_running_lock);
133 oct->io_qmask.iq |= BIT_ULL(iq_no);
135 /* Set the 32B/64B mode for each input queue */
136 oct->io_qmask.iq64B |= ((conf->instr_type == 64) << iq_no);
137 iq->iqcmd_64B = (conf->instr_type == 64);
139 oct->fn_list.setup_iq_regs(oct, iq_no);
141 oct->check_db_wq[iq_no].wq = alloc_workqueue("check_iq_db",
144 if (!oct->check_db_wq[iq_no].wq) {
145 vfree(iq->request_list);
146 iq->request_list = NULL;
147 lio_dma_free(oct, q_size, iq->base_addr, iq->base_addr_dma);
148 dev_err(&oct->pci_dev->dev, "check db wq create failed for iq %d\n",
153 db_wq = &oct->check_db_wq[iq_no];
155 INIT_DELAYED_WORK(&db_wq->wk.work, check_db_timeout);
156 db_wq->wk.ctxptr = oct;
157 db_wq->wk.ctxul = iq_no;
158 queue_delayed_work(db_wq->wq, &db_wq->wk.work, msecs_to_jiffies(1));
163 int octeon_delete_instr_queue(struct octeon_device *oct, u32 iq_no)
165 u64 desc_size = 0, q_size;
166 struct octeon_instr_queue *iq = oct->instr_queue[iq_no];
168 cancel_delayed_work_sync(&oct->check_db_wq[iq_no].wk.work);
169 destroy_workqueue(oct->check_db_wq[iq_no].wq);
171 if (OCTEON_CN6XXX(oct))
173 CFG_GET_IQ_INSTR_TYPE(CHIP_CONF(oct, cn6xxx));
174 else if (OCTEON_CN23XX_PF(oct))
176 CFG_GET_IQ_INSTR_TYPE(CHIP_CONF(oct, cn23xx_pf));
177 else if (OCTEON_CN23XX_VF(oct))
179 CFG_GET_IQ_INSTR_TYPE(CHIP_CONF(oct, cn23xx_vf));
181 vfree(iq->request_list);
184 q_size = iq->max_count * desc_size;
185 lio_dma_free(oct, (u32)q_size, iq->base_addr,
187 oct->io_qmask.iq &= ~(1ULL << iq_no);
188 vfree(oct->instr_queue[iq_no]);
189 oct->instr_queue[iq_no] = NULL;
196 /* Return 0 on success, 1 on failure */
197 int octeon_setup_iq(struct octeon_device *oct,
200 union oct_txpciq txpciq,
204 u32 iq_no = (u32)txpciq.s.q_no;
205 int numa_node = dev_to_node(&oct->pci_dev->dev);
207 if (oct->instr_queue[iq_no]) {
208 dev_dbg(&oct->pci_dev->dev, "IQ is in use. Cannot create the IQ: %d again\n",
210 oct->instr_queue[iq_no]->txpciq.u64 = txpciq.u64;
211 oct->instr_queue[iq_no]->app_ctx = app_ctx;
214 oct->instr_queue[iq_no] =
215 vmalloc_node(sizeof(struct octeon_instr_queue), numa_node);
216 if (!oct->instr_queue[iq_no])
217 oct->instr_queue[iq_no] =
218 vmalloc(sizeof(struct octeon_instr_queue));
219 if (!oct->instr_queue[iq_no])
222 memset(oct->instr_queue[iq_no], 0,
223 sizeof(struct octeon_instr_queue));
225 oct->instr_queue[iq_no]->q_index = q_index;
226 oct->instr_queue[iq_no]->app_ctx = app_ctx;
227 oct->instr_queue[iq_no]->ifidx = ifidx;
229 if (octeon_init_instr_queue(oct, txpciq, num_descs)) {
230 vfree(oct->instr_queue[iq_no]);
231 oct->instr_queue[iq_no] = NULL;
236 if (oct->fn_list.enable_io_queues(oct)) {
237 octeon_delete_instr_queue(oct, iq_no);
244 int lio_wait_for_instr_fetch(struct octeon_device *oct)
246 int i, retry = 1000, pending, instr_cnt = 0;
251 for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
252 if (!(oct->io_qmask.iq & BIT_ULL(i)))
255 atomic_read(&oct->instr_queue[i]->instr_pending);
257 __check_db_timeout(oct, i);
258 instr_cnt += pending;
264 schedule_timeout_uninterruptible(1);
266 } while (retry-- && instr_cnt);
272 ring_doorbell(struct octeon_device *oct, struct octeon_instr_queue *iq)
274 if (atomic_read(&oct->status) == OCT_DEV_RUNNING) {
275 writel(iq->fill_cnt, iq->doorbell_reg);
276 /* make sure doorbell write goes through */
279 iq->last_db_time = jiffies;
284 static inline void __copy_cmd_into_iq(struct octeon_instr_queue *iq,
289 cmdsize = ((iq->iqcmd_64B) ? 64 : 32);
290 iqptr = iq->base_addr + (cmdsize * iq->host_write_index);
292 memcpy(iqptr, cmd, cmdsize);
295 static inline struct iq_post_status
296 __post_command2(struct octeon_instr_queue *iq, u8 *cmd)
298 struct iq_post_status st;
300 st.status = IQ_SEND_OK;
302 /* This ensures that the read index does not wrap around to the same
303 * position if queue gets full before Octeon could fetch any instr.
305 if (atomic_read(&iq->instr_pending) >= (s32)(iq->max_count - 1)) {
306 st.status = IQ_SEND_FAILED;
311 if (atomic_read(&iq->instr_pending) >= (s32)(iq->max_count - 2))
312 st.status = IQ_SEND_STOP;
314 __copy_cmd_into_iq(iq, cmd);
316 /* "index" is returned, host_write_index is modified. */
317 st.index = iq->host_write_index;
318 iq->host_write_index = incr_index(iq->host_write_index, 1,
322 /* Flush the command into memory. We need to be sure the data is in
323 * memory before indicating that the instruction is pending.
327 atomic_inc(&iq->instr_pending);
333 octeon_register_reqtype_free_fn(struct octeon_device *oct, int reqtype,
336 if (reqtype > REQTYPE_LAST) {
337 dev_err(&oct->pci_dev->dev, "%s: Invalid reqtype: %d\n",
342 reqtype_free_fn[oct->octeon_id][reqtype] = fn;
348 __add_to_request_list(struct octeon_instr_queue *iq,
349 int idx, void *buf, int reqtype)
351 iq->request_list[idx].buf = buf;
352 iq->request_list[idx].reqtype = reqtype;
355 /* Can only run in process context */
357 lio_process_iq_request_list(struct octeon_device *oct,
358 struct octeon_instr_queue *iq, u32 napi_budget)
362 u32 old = iq->flush_index;
364 unsigned int pkts_compl = 0, bytes_compl = 0;
365 struct octeon_soft_command *sc;
366 struct octeon_instr_irh *irh;
369 while (old != iq->octeon_read_index) {
370 reqtype = iq->request_list[old].reqtype;
371 buf = iq->request_list[old].buf;
373 if (reqtype == REQTYPE_NONE)
376 octeon_update_tx_completion_counters(buf, reqtype, &pkts_compl,
380 case REQTYPE_NORESP_NET:
381 case REQTYPE_NORESP_NET_SG:
382 case REQTYPE_RESP_NET_SG:
383 reqtype_free_fn[oct->octeon_id][reqtype](buf);
385 case REQTYPE_RESP_NET:
386 case REQTYPE_SOFT_COMMAND:
389 if (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct))
390 irh = (struct octeon_instr_irh *)
393 irh = (struct octeon_instr_irh *)
396 /* We're expecting a response from Octeon.
397 * It's up to lio_process_ordered_list() to
398 * process sc. Add sc to the ordered soft
399 * command response list because we expect
400 * a response from Octeon.
404 [OCTEON_ORDERED_SC_LIST].lock,
406 atomic_inc(&oct->response_list
407 [OCTEON_ORDERED_SC_LIST].
409 list_add_tail(&sc->node, &oct->response_list
410 [OCTEON_ORDERED_SC_LIST].head);
411 spin_unlock_irqrestore
413 [OCTEON_ORDERED_SC_LIST].lock,
417 /* This callback must not sleep */
418 sc->callback(oct, OCTEON_REQUEST_DONE,
424 dev_err(&oct->pci_dev->dev,
425 "%s Unknown reqtype: %d buf: %p at idx %d\n",
426 __func__, reqtype, buf, old);
429 iq->request_list[old].buf = NULL;
430 iq->request_list[old].reqtype = 0;
434 old = incr_index(old, 1, iq->max_count);
436 if ((napi_budget) && (inst_count >= napi_budget))
440 octeon_report_tx_completion_to_bql(iq->app_ctx, pkts_compl,
442 iq->flush_index = old;
447 /* Can only be called from process context */
449 octeon_flush_iq(struct octeon_device *oct, struct octeon_instr_queue *iq,
452 u32 inst_processed = 0;
453 u32 tot_inst_processed = 0;
456 if (!spin_trylock(&iq->iq_flush_running_lock))
459 spin_lock_bh(&iq->lock);
461 iq->octeon_read_index = oct->fn_list.update_iq_read_idx(iq);
464 /* Process any outstanding IQ packets. */
465 if (iq->flush_index == iq->octeon_read_index)
470 lio_process_iq_request_list(oct, iq,
475 lio_process_iq_request_list(oct, iq, 0);
477 if (inst_processed) {
478 iq->pkts_processed += inst_processed;
479 atomic_sub(inst_processed, &iq->instr_pending);
480 iq->stats.instr_processed += inst_processed;
483 tot_inst_processed += inst_processed;
486 } while (tot_inst_processed < napi_budget);
488 if (napi_budget && (tot_inst_processed >= napi_budget))
491 iq->last_db_time = jiffies;
493 spin_unlock_bh(&iq->lock);
495 spin_unlock(&iq->iq_flush_running_lock);
500 /* Process instruction queue after timeout.
501 * This routine gets called from a workqueue or when removing the module.
503 static void __check_db_timeout(struct octeon_device *oct, u64 iq_no)
505 struct octeon_instr_queue *iq;
511 iq = oct->instr_queue[iq_no];
515 /* return immediately, if no work pending */
516 if (!atomic_read(&iq->instr_pending))
518 /* If jiffies - last_db_time < db_timeout do nothing */
519 next_time = iq->last_db_time + iq->db_timeout;
520 if (!time_after(jiffies, (unsigned long)next_time))
522 iq->last_db_time = jiffies;
524 /* Flush the instruction queue */
525 octeon_flush_iq(oct, iq, 0);
527 lio_enable_irq(NULL, iq);
530 /* Called by the Poll thread at regular intervals to check the instruction
531 * queue for commands to be posted and for commands that were fetched by Octeon.
533 static void check_db_timeout(struct work_struct *work)
535 struct cavium_wk *wk = (struct cavium_wk *)work;
536 struct octeon_device *oct = (struct octeon_device *)wk->ctxptr;
537 u64 iq_no = wk->ctxul;
538 struct cavium_wq *db_wq = &oct->check_db_wq[iq_no];
541 __check_db_timeout(oct, iq_no);
542 queue_delayed_work(db_wq->wq, &db_wq->wk.work, msecs_to_jiffies(delay));
546 octeon_send_command(struct octeon_device *oct, u32 iq_no,
547 u32 force_db, void *cmd, void *buf,
548 u32 datasize, u32 reqtype)
550 struct iq_post_status st;
551 struct octeon_instr_queue *iq = oct->instr_queue[iq_no];
553 /* Get the lock and prevent other tasks and tx interrupt handler from
556 spin_lock_bh(&iq->post_lock);
558 st = __post_command2(iq, cmd);
560 if (st.status != IQ_SEND_FAILED) {
561 octeon_report_sent_bytes_to_bql(buf, reqtype);
562 __add_to_request_list(iq, st.index, buf, reqtype);
563 INCR_INSTRQUEUE_PKT_COUNT(oct, iq_no, bytes_sent, datasize);
564 INCR_INSTRQUEUE_PKT_COUNT(oct, iq_no, instr_posted, 1);
567 ring_doorbell(oct, iq);
569 INCR_INSTRQUEUE_PKT_COUNT(oct, iq_no, instr_dropped, 1);
572 spin_unlock_bh(&iq->post_lock);
574 /* This is only done here to expedite packets being flushed
575 * for cases where there are no IQ completion interrupts.
582 octeon_prepare_soft_command(struct octeon_device *oct,
583 struct octeon_soft_command *sc,
590 struct octeon_config *oct_cfg;
591 struct octeon_instr_ih2 *ih2;
592 struct octeon_instr_ih3 *ih3;
593 struct octeon_instr_pki_ih3 *pki_ih3;
594 struct octeon_instr_irh *irh;
595 struct octeon_instr_rdp *rdp;
597 WARN_ON(opcode > 15);
598 WARN_ON(subcode > 127);
600 oct_cfg = octeon_get_conf(oct);
602 if (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct)) {
603 ih3 = (struct octeon_instr_ih3 *)&sc->cmd.cmd3.ih3;
605 ih3->pkind = oct->instr_queue[sc->iq_no]->txpciq.s.pkind;
607 pki_ih3 = (struct octeon_instr_pki_ih3 *)&sc->cmd.cmd3.pki_ih3;
613 oct->instr_queue[sc->iq_no]->txpciq.s.use_qpg;
615 pki_ih3->tag = LIO_CONTROL;
616 pki_ih3->tagtype = ATOMIC_TAG;
618 oct->instr_queue[sc->iq_no]->txpciq.s.qpg;
623 ih3->dlengsz = sc->datasize;
625 irh = (struct octeon_instr_irh *)&sc->cmd.cmd3.irh;
626 irh->opcode = opcode;
627 irh->subcode = subcode;
629 /* opcode/subcode specific parameters (ossp) */
630 irh->ossp = irh_ossp;
631 sc->cmd.cmd3.ossp[0] = ossp0;
632 sc->cmd.cmd3.ossp[1] = ossp1;
635 rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd3.rdp;
636 rdp->pcie_port = oct->pcie_port;
637 rdp->rlen = sc->rdatasize;
641 /* pki_ih3 irh+ossp[0]+ossp[1]+rdp+rptr = 48 bytes */
642 ih3->fsz = LIO_SOFTCMDRESP_IH3;
646 /* pki_h3 + irh + ossp[0] + ossp[1] = 32 bytes */
647 ih3->fsz = LIO_PCICMD_O3;
651 ih2 = (struct octeon_instr_ih2 *)&sc->cmd.cmd2.ih2;
652 ih2->tagtype = ATOMIC_TAG;
653 ih2->tag = LIO_CONTROL;
655 ih2->grp = CFG_GET_CTRL_Q_GRP(oct_cfg);
658 ih2->dlengsz = sc->datasize;
662 irh = (struct octeon_instr_irh *)&sc->cmd.cmd2.irh;
663 irh->opcode = opcode;
664 irh->subcode = subcode;
666 /* opcode/subcode specific parameters (ossp) */
667 irh->ossp = irh_ossp;
668 sc->cmd.cmd2.ossp[0] = ossp0;
669 sc->cmd.cmd2.ossp[1] = ossp1;
672 rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd2.rdp;
673 rdp->pcie_port = oct->pcie_port;
674 rdp->rlen = sc->rdatasize;
677 /* irh+ossp[0]+ossp[1]+rdp+rptr = 40 bytes */
678 ih2->fsz = LIO_SOFTCMDRESP_IH2;
681 /* irh + ossp[0] + ossp[1] = 24 bytes */
682 ih2->fsz = LIO_PCICMD_O2;
687 int octeon_send_soft_command(struct octeon_device *oct,
688 struct octeon_soft_command *sc)
690 struct octeon_instr_ih2 *ih2;
691 struct octeon_instr_ih3 *ih3;
692 struct octeon_instr_irh *irh;
695 if (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct)) {
696 ih3 = (struct octeon_instr_ih3 *)&sc->cmd.cmd3.ih3;
698 WARN_ON(!sc->dmadptr);
699 sc->cmd.cmd3.dptr = sc->dmadptr;
701 irh = (struct octeon_instr_irh *)&sc->cmd.cmd3.irh;
703 WARN_ON(!sc->dmarptr);
704 WARN_ON(!sc->status_word);
705 *sc->status_word = COMPLETION_WORD_INIT;
706 sc->cmd.cmd3.rptr = sc->dmarptr;
708 len = (u32)ih3->dlengsz;
710 ih2 = (struct octeon_instr_ih2 *)&sc->cmd.cmd2.ih2;
712 WARN_ON(!sc->dmadptr);
713 sc->cmd.cmd2.dptr = sc->dmadptr;
715 irh = (struct octeon_instr_irh *)&sc->cmd.cmd2.irh;
717 WARN_ON(!sc->dmarptr);
718 WARN_ON(!sc->status_word);
719 *sc->status_word = COMPLETION_WORD_INIT;
720 sc->cmd.cmd2.rptr = sc->dmarptr;
722 len = (u32)ih2->dlengsz;
726 sc->timeout = jiffies + sc->wait_time;
728 return (octeon_send_command(oct, sc->iq_no, 1, &sc->cmd, sc,
729 len, REQTYPE_SOFT_COMMAND));
732 int octeon_setup_sc_buffer_pool(struct octeon_device *oct)
736 struct octeon_soft_command *sc;
738 INIT_LIST_HEAD(&oct->sc_buf_pool.head);
739 spin_lock_init(&oct->sc_buf_pool.lock);
740 atomic_set(&oct->sc_buf_pool.alloc_buf_count, 0);
742 for (i = 0; i < MAX_SOFT_COMMAND_BUFFERS; i++) {
743 sc = (struct octeon_soft_command *)
745 SOFT_COMMAND_BUFFER_SIZE,
746 (dma_addr_t *)&dma_addr);
748 octeon_free_sc_buffer_pool(oct);
752 sc->dma_addr = dma_addr;
753 sc->size = SOFT_COMMAND_BUFFER_SIZE;
755 list_add_tail(&sc->node, &oct->sc_buf_pool.head);
761 int octeon_free_sc_buffer_pool(struct octeon_device *oct)
763 struct list_head *tmp, *tmp2;
764 struct octeon_soft_command *sc;
766 spin_lock_bh(&oct->sc_buf_pool.lock);
768 list_for_each_safe(tmp, tmp2, &oct->sc_buf_pool.head) {
771 sc = (struct octeon_soft_command *)tmp;
773 lio_dma_free(oct, sc->size, sc, sc->dma_addr);
776 INIT_LIST_HEAD(&oct->sc_buf_pool.head);
778 spin_unlock_bh(&oct->sc_buf_pool.lock);
783 struct octeon_soft_command *octeon_alloc_soft_command(struct octeon_device *oct,
790 u32 offset = sizeof(struct octeon_soft_command);
791 struct octeon_soft_command *sc = NULL;
792 struct list_head *tmp;
794 WARN_ON((offset + datasize + rdatasize + ctxsize) >
795 SOFT_COMMAND_BUFFER_SIZE);
797 spin_lock_bh(&oct->sc_buf_pool.lock);
799 if (list_empty(&oct->sc_buf_pool.head)) {
800 spin_unlock_bh(&oct->sc_buf_pool.lock);
804 list_for_each(tmp, &oct->sc_buf_pool.head)
809 atomic_inc(&oct->sc_buf_pool.alloc_buf_count);
811 spin_unlock_bh(&oct->sc_buf_pool.lock);
813 sc = (struct octeon_soft_command *)tmp;
815 dma_addr = sc->dma_addr;
818 memset(sc, 0, sc->size);
820 sc->dma_addr = dma_addr;
824 sc->ctxptr = (u8 *)sc + offset;
825 sc->ctxsize = ctxsize;
828 /* Start data at 128 byte boundary */
829 offset = (offset + ctxsize + 127) & 0xffffff80;
832 sc->virtdptr = (u8 *)sc + offset;
833 sc->dmadptr = dma_addr + offset;
834 sc->datasize = datasize;
837 /* Start rdata at 128 byte boundary */
838 offset = (offset + datasize + 127) & 0xffffff80;
841 WARN_ON(rdatasize < 16);
842 sc->virtrptr = (u8 *)sc + offset;
843 sc->dmarptr = dma_addr + offset;
844 sc->rdatasize = rdatasize;
845 sc->status_word = (u64 *)((u8 *)(sc->virtrptr) + rdatasize - 8);
851 void octeon_free_soft_command(struct octeon_device *oct,
852 struct octeon_soft_command *sc)
854 spin_lock_bh(&oct->sc_buf_pool.lock);
856 list_add_tail(&sc->node, &oct->sc_buf_pool.head);
858 atomic_dec(&oct->sc_buf_pool.alloc_buf_count);
860 spin_unlock_bh(&oct->sc_buf_pool.lock);