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