blob: c93210f99dda2929f49f913e0a85467f85c8a161 [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 }
Raghu Vatsavayi60441882016-06-21 22:53:08 -070057 spin_lock_init(&oct->cmd_resp_wqlock);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070058
Bhaktipriya Shridhar523a61b2016-06-04 20:21:40 +053059 oct->dma_comp_wq.wq = alloc_workqueue("dma-comp", WQ_MEM_RECLAIM, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070060 if (!oct->dma_comp_wq.wq) {
61 dev_err(&oct->pci_dev->dev, "failed to create wq thread\n");
62 return -ENOMEM;
63 }
64
65 cwq = &oct->dma_comp_wq;
66 INIT_DELAYED_WORK(&cwq->wk.work, oct_poll_req_completion);
67 cwq->wk.ctxptr = oct;
Raghu Vatsavayi60441882016-06-21 22:53:08 -070068 oct->cmd_resp_state = OCT_DRV_ONLINE;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070069 queue_delayed_work(cwq->wq, &cwq->wk.work, msecs_to_jiffies(100));
70
71 return ret;
72}
73
74void octeon_delete_response_list(struct octeon_device *oct)
75{
76 cancel_delayed_work_sync(&oct->dma_comp_wq.wk.work);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070077 destroy_workqueue(oct->dma_comp_wq.wq);
78}
79
80int lio_process_ordered_list(struct octeon_device *octeon_dev,
81 u32 force_quit)
82{
83 struct octeon_response_list *ordered_sc_list;
84 struct octeon_soft_command *sc;
85 int request_complete = 0;
86 int resp_to_process = MAX_ORD_REQS_TO_PROCESS;
87 u32 status;
88 u64 status64;
89 struct octeon_instr_rdp *rdp;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070090 u64 rptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070091
92 ordered_sc_list = &octeon_dev->response_list[OCTEON_ORDERED_SC_LIST];
93
94 do {
95 spin_lock_bh(&ordered_sc_list->lock);
96
97 if (ordered_sc_list->head.next == &ordered_sc_list->head) {
98 /* ordered_sc_list is empty; there is
99 * nothing to process
100 */
101 spin_unlock_bh
102 (&ordered_sc_list->lock);
103 return 1;
104 }
105
106 sc = (struct octeon_soft_command *)ordered_sc_list->
107 head.next;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -0700108 rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd2.rdp;
109 rptr = sc->cmd.cmd2.rptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700110
111 status = OCTEON_REQUEST_PENDING;
112
113 /* check if octeon has finished DMA'ing a response
114 * to where rptr is pointing to
115 */
116 dma_sync_single_for_cpu(&octeon_dev->pci_dev->dev,
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -0700117 rptr, rdp->rlen,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700118 DMA_FROM_DEVICE);
119 status64 = *sc->status_word;
120
121 if (status64 != COMPLETION_WORD_INIT) {
122 if ((status64 & 0xff) != 0xff) {
123 octeon_swap_8B_data(&status64, 1);
124 if (((status64 & 0xff) != 0xff)) {
125 status = (u32)(status64 &
126 0xffffffffULL);
127 }
128 }
129 } else if (force_quit || (sc->timeout &&
130 time_after(jiffies, (unsigned long)sc->timeout))) {
131 status = OCTEON_REQUEST_TIMEOUT;
132 }
133
134 if (status != OCTEON_REQUEST_PENDING) {
135 /* we have received a response or we have timed out */
136 /* remove node from linked list */
137 list_del(&sc->node);
138 atomic_dec(&octeon_dev->response_list
139 [OCTEON_ORDERED_SC_LIST].
140 pending_req_count);
141 spin_unlock_bh
142 (&ordered_sc_list->lock);
143
144 if (sc->callback)
145 sc->callback(octeon_dev, status,
146 sc->callback_arg);
147
148 request_complete++;
149
150 } else {
151 /* no response yet */
152 request_complete = 0;
153 spin_unlock_bh
154 (&ordered_sc_list->lock);
155 }
156
157 /* If we hit the Max Ordered requests to process every loop,
158 * we quit
159 * and let this function be invoked the next time the poll
160 * thread runs
161 * to process the remaining requests. This function can take up
162 * the entire CPU if there is no upper limit to the requests
163 * processed.
164 */
165 if (request_complete >= resp_to_process)
166 break;
167 } while (request_complete);
168
169 return 0;
170}
171
172static void oct_poll_req_completion(struct work_struct *work)
173{
174 struct cavium_wk *wk = (struct cavium_wk *)work;
175 struct octeon_device *oct = (struct octeon_device *)wk->ctxptr;
176 struct cavium_wq *cwq = &oct->dma_comp_wq;
177
178 lio_process_ordered_list(oct, 0);
179
180 queue_delayed_work(cwq->wq, &cwq->wk.work, msecs_to_jiffies(100));
181}