1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/pci.h>
23#include <linux/netdevice.h>
24#include "liquidio_common.h"
25#include "octeon_droq.h"
26#include "octeon_iq.h"
27#include "response_manager.h"
28#include "octeon_device.h"
29#include "octeon_main.h"
30
31static void oct_poll_req_completion(struct work_struct *work);
32
33int octeon_setup_response_list(struct octeon_device *oct)
34{
35 int i, ret = 0;
36 struct cavium_wq *cwq;
37
38 for (i = 0; i < MAX_RESPONSE_LISTS; i++) {
39 INIT_LIST_HEAD(&oct->response_list[i].head);
40 spin_lock_init(&oct->response_list[i].lock);
41 atomic_set(&oct->response_list[i].pending_req_count, 0);
42 }
43 spin_lock_init(&oct->cmd_resp_wqlock);
44
45 oct->dma_comp_wq.wq = alloc_workqueue("dma-comp", WQ_MEM_RECLAIM, 0);
46 if (!oct->dma_comp_wq.wq) {
47 dev_err(&oct->pci_dev->dev, "failed to create wq thread\n");
48 return -ENOMEM;
49 }
50
51 cwq = &oct->dma_comp_wq;
52 INIT_DELAYED_WORK(&cwq->wk.work, oct_poll_req_completion);
53 cwq->wk.ctxptr = oct;
54 oct->cmd_resp_state = OCT_DRV_ONLINE;
55 queue_delayed_work(cwq->wq, &cwq->wk.work, msecs_to_jiffies(50));
56
57 return ret;
58}
59
60void octeon_delete_response_list(struct octeon_device *oct)
61{
62 cancel_delayed_work_sync(&oct->dma_comp_wq.wk.work);
63 destroy_workqueue(oct->dma_comp_wq.wq);
64}
65
66int lio_process_ordered_list(struct octeon_device *octeon_dev,
67 u32 force_quit)
68{
69 struct octeon_response_list *ordered_sc_list;
70 struct octeon_soft_command *sc;
71 int request_complete = 0;
72 int resp_to_process = MAX_ORD_REQS_TO_PROCESS;
73 u32 status;
74 u64 status64;
75 struct octeon_instr_rdp *rdp;
76 u64 rptr;
77
78 ordered_sc_list = &octeon_dev->response_list[OCTEON_ORDERED_SC_LIST];
79
80 do {
81 spin_lock_bh(&ordered_sc_list->lock);
82
83 if (ordered_sc_list->head.next == &ordered_sc_list->head) {
84
85
86
87 spin_unlock_bh
88 (&ordered_sc_list->lock);
89 return 1;
90 }
91
92 sc = (struct octeon_soft_command *)ordered_sc_list->
93 head.next;
94 if (OCTEON_CN23XX_PF(octeon_dev)) {
95 rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd3.rdp;
96 rptr = sc->cmd.cmd3.rptr;
97 } else {
98 rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd2.rdp;
99 rptr = sc->cmd.cmd2.rptr;
100 }
101
102 status = OCTEON_REQUEST_PENDING;
103
104
105
106
107 dma_sync_single_for_cpu(&octeon_dev->pci_dev->dev,
108 rptr, rdp->rlen,
109 DMA_FROM_DEVICE);
110 status64 = *sc->status_word;
111
112 if (status64 != COMPLETION_WORD_INIT) {
113 if ((status64 & 0xff) != 0xff) {
114 octeon_swap_8B_data(&status64, 1);
115 if (((status64 & 0xff) != 0xff)) {
116 status = (u32)(status64 &
117 0xffffffffULL);
118 }
119 }
120 } else if (force_quit || (sc->timeout &&
121 time_after(jiffies, (unsigned long)sc->timeout))) {
122 status = OCTEON_REQUEST_TIMEOUT;
123 }
124
125 if (status != OCTEON_REQUEST_PENDING) {
126
127
128 list_del(&sc->node);
129 atomic_dec(&octeon_dev->response_list
130 [OCTEON_ORDERED_SC_LIST].
131 pending_req_count);
132 spin_unlock_bh
133 (&ordered_sc_list->lock);
134
135 if (sc->callback)
136 sc->callback(octeon_dev, status,
137 sc->callback_arg);
138
139 request_complete++;
140
141 } else {
142
143 request_complete = 0;
144 spin_unlock_bh
145 (&ordered_sc_list->lock);
146 }
147
148
149
150
151
152
153
154
155
156 if (request_complete >= resp_to_process)
157 break;
158 } while (request_complete);
159
160 return 0;
161}
162
163static void oct_poll_req_completion(struct work_struct *work)
164{
165 struct cavium_wk *wk = (struct cavium_wk *)work;
166 struct octeon_device *oct = (struct octeon_device *)wk->ctxptr;
167 struct cavium_wq *cwq = &oct->dma_comp_wq;
168
169 lio_process_ordered_list(oct, 0);
170 queue_delayed_work(cwq->wq, &cwq->wk.work, msecs_to_jiffies(50));
171}
172