blob: e2e9103e6ebd0e37839eb554530e67f5b388e549 [file] [log] [blame]
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001/**********************************************************************
2 * Author: Cavium, Inc.
3 *
4 * Contact: support@cavium.com
5 * Please include "LiquidIO" in the subject.
6 *
7 * Copyright (c) 2003-2015 Cavium, Inc.
8 *
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.
12 *
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
17 * details.
18 *
19 * This file may also be available under a different license from Cavium.
20 * Contact Cavium, Inc. for more information
21 **********************************************************************/
22#include <linux/version.h>
23#include <linux/types.h>
24#include <linux/list.h>
25#include <linux/interrupt.h>
26#include <linux/dma-mapping.h>
27#include <linux/pci.h>
28#include <linux/kthread.h>
29#include <linux/netdevice.h>
30#include "octeon_config.h"
31#include "liquidio_common.h"
32#include "octeon_droq.h"
33#include "octeon_iq.h"
34#include "response_manager.h"
35#include "octeon_device.h"
36#include "octeon_nic.h"
37#include "octeon_main.h"
38#include "octeon_network.h"
39#include "cn66xx_regs.h"
40#include "cn66xx_device.h"
41#include "cn68xx_regs.h"
42#include "cn68xx_device.h"
43#include "liquidio_image.h"
44
45static void oct_poll_req_completion(struct work_struct *work);
46
47int octeon_setup_response_list(struct octeon_device *oct)
48{
49 int i, ret = 0;
50 struct cavium_wq *cwq;
51
52 for (i = 0; i < MAX_RESPONSE_LISTS; i++) {
53 INIT_LIST_HEAD(&oct->response_list[i].head);
54 spin_lock_init(&oct->response_list[i].lock);
55 atomic_set(&oct->response_list[i].pending_req_count, 0);
56 }
57
Bhaktipriya Shridhar523a61b2016-06-04 20:21:40 +053058 oct->dma_comp_wq.wq = alloc_workqueue("dma-comp", WQ_MEM_RECLAIM, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070059 if (!oct->dma_comp_wq.wq) {
60 dev_err(&oct->pci_dev->dev, "failed to create wq thread\n");
61 return -ENOMEM;
62 }
63
64 cwq = &oct->dma_comp_wq;
65 INIT_DELAYED_WORK(&cwq->wk.work, oct_poll_req_completion);
66 cwq->wk.ctxptr = oct;
67 queue_delayed_work(cwq->wq, &cwq->wk.work, msecs_to_jiffies(100));
68
69 return ret;
70}
71
72void octeon_delete_response_list(struct octeon_device *oct)
73{
74 cancel_delayed_work_sync(&oct->dma_comp_wq.wk.work);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070075 destroy_workqueue(oct->dma_comp_wq.wq);
76}
77
78int lio_process_ordered_list(struct octeon_device *octeon_dev,
79 u32 force_quit)
80{
81 struct octeon_response_list *ordered_sc_list;
82 struct octeon_soft_command *sc;
83 int request_complete = 0;
84 int resp_to_process = MAX_ORD_REQS_TO_PROCESS;
85 u32 status;
86 u64 status64;
87 struct octeon_instr_rdp *rdp;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070088 u64 rptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070089
90 ordered_sc_list = &octeon_dev->response_list[OCTEON_ORDERED_SC_LIST];
91
92 do {
93 spin_lock_bh(&ordered_sc_list->lock);
94
95 if (ordered_sc_list->head.next == &ordered_sc_list->head) {
96 /* ordered_sc_list is empty; there is
97 * nothing to process
98 */
99 spin_unlock_bh
100 (&ordered_sc_list->lock);
101 return 1;
102 }
103
104 sc = (struct octeon_soft_command *)ordered_sc_list->
105 head.next;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -0700106 rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd2.rdp;
107 rptr = sc->cmd.cmd2.rptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700108
109 status = OCTEON_REQUEST_PENDING;
110
111 /* check if octeon has finished DMA'ing a response
112 * to where rptr is pointing to
113 */
114 dma_sync_single_for_cpu(&octeon_dev->pci_dev->dev,
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -0700115 rptr, rdp->rlen,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700116 DMA_FROM_DEVICE);
117 status64 = *sc->status_word;
118
119 if (status64 != COMPLETION_WORD_INIT) {
120 if ((status64 & 0xff) != 0xff) {
121 octeon_swap_8B_data(&status64, 1);
122 if (((status64 & 0xff) != 0xff)) {
123 status = (u32)(status64 &
124 0xffffffffULL);
125 }
126 }
127 } else if (force_quit || (sc->timeout &&
128 time_after(jiffies, (unsigned long)sc->timeout))) {
129 status = OCTEON_REQUEST_TIMEOUT;
130 }
131
132 if (status != OCTEON_REQUEST_PENDING) {
133 /* we have received a response or we have timed out */
134 /* remove node from linked list */
135 list_del(&sc->node);
136 atomic_dec(&octeon_dev->response_list
137 [OCTEON_ORDERED_SC_LIST].
138 pending_req_count);
139 spin_unlock_bh
140 (&ordered_sc_list->lock);
141
142 if (sc->callback)
143 sc->callback(octeon_dev, status,
144 sc->callback_arg);
145
146 request_complete++;
147
148 } else {
149 /* no response yet */
150 request_complete = 0;
151 spin_unlock_bh
152 (&ordered_sc_list->lock);
153 }
154
155 /* If we hit the Max Ordered requests to process every loop,
156 * we quit
157 * and let this function be invoked the next time the poll
158 * thread runs
159 * to process the remaining requests. This function can take up
160 * the entire CPU if there is no upper limit to the requests
161 * processed.
162 */
163 if (request_complete >= resp_to_process)
164 break;
165 } while (request_complete);
166
167 return 0;
168}
169
170static void oct_poll_req_completion(struct work_struct *work)
171{
172 struct cavium_wk *wk = (struct cavium_wk *)work;
173 struct octeon_device *oct = (struct octeon_device *)wk->ctxptr;
174 struct cavium_wq *cwq = &oct->dma_comp_wq;
175
176 lio_process_ordered_list(oct, 0);
177
178 queue_delayed_work(cwq->wq, &cwq->wk.work, msecs_to_jiffies(100));
179}