net/liquidio: add APIs to enable and disable IO queues
[dpdk.git] / drivers / net / liquidio / base / lio_23xx_vf.c
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Cavium, Inc.. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Cavium, Inc. nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <rte_ethdev.h>
35 #include <rte_cycles.h>
36 #include <rte_malloc.h>
37
38 #include "lio_logs.h"
39 #include "lio_23xx_vf.h"
40 #include "lio_23xx_reg.h"
41 #include "lio_mbox.h"
42
43 static int
44 cn23xx_vf_reset_io_queues(struct lio_device *lio_dev, uint32_t num_queues)
45 {
46         uint32_t loop = CN23XX_VF_BUSY_READING_REG_LOOP_COUNT;
47         uint64_t d64, q_no;
48         int ret_val = 0;
49
50         PMD_INIT_FUNC_TRACE();
51
52         for (q_no = 0; q_no < num_queues; q_no++) {
53                 /* set RST bit to 1. This bit applies to both IQ and OQ */
54                 d64 = lio_read_csr64(lio_dev,
55                                      CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
56                 d64 = d64 | CN23XX_PKT_INPUT_CTL_RST;
57                 lio_write_csr64(lio_dev, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
58                                 d64);
59         }
60
61         /* wait until the RST bit is clear or the RST and QUIET bits are set */
62         for (q_no = 0; q_no < num_queues; q_no++) {
63                 volatile uint64_t reg_val;
64
65                 reg_val = lio_read_csr64(lio_dev,
66                                          CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
67                 while ((reg_val & CN23XX_PKT_INPUT_CTL_RST) &&
68                                 !(reg_val & CN23XX_PKT_INPUT_CTL_QUIET) &&
69                                 loop) {
70                         reg_val = lio_read_csr64(
71                                         lio_dev,
72                                         CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
73                         loop = loop - 1;
74                 }
75
76                 if (loop == 0) {
77                         lio_dev_err(lio_dev,
78                                     "clearing the reset reg failed or setting the quiet reg failed for qno: %lu\n",
79                                     (unsigned long)q_no);
80                         return -1;
81                 }
82
83                 reg_val = reg_val & ~CN23XX_PKT_INPUT_CTL_RST;
84                 lio_write_csr64(lio_dev, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
85                                 reg_val);
86
87                 reg_val = lio_read_csr64(
88                     lio_dev, CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
89                 if (reg_val & CN23XX_PKT_INPUT_CTL_RST) {
90                         lio_dev_err(lio_dev,
91                                     "clearing the reset failed for qno: %lu\n",
92                                     (unsigned long)q_no);
93                         ret_val = -1;
94                 }
95         }
96
97         return ret_val;
98 }
99
100 static int
101 cn23xx_vf_setup_global_input_regs(struct lio_device *lio_dev)
102 {
103         uint64_t q_no;
104         uint64_t d64;
105
106         PMD_INIT_FUNC_TRACE();
107
108         if (cn23xx_vf_reset_io_queues(lio_dev,
109                                       lio_dev->sriov_info.rings_per_vf))
110                 return -1;
111
112         for (q_no = 0; q_no < (lio_dev->sriov_info.rings_per_vf); q_no++) {
113                 lio_write_csr64(lio_dev, CN23XX_SLI_IQ_DOORBELL(q_no),
114                                 0xFFFFFFFF);
115
116                 d64 = lio_read_csr64(lio_dev,
117                                      CN23XX_SLI_IQ_INSTR_COUNT64(q_no));
118
119                 d64 &= 0xEFFFFFFFFFFFFFFFL;
120
121                 lio_write_csr64(lio_dev, CN23XX_SLI_IQ_INSTR_COUNT64(q_no),
122                                 d64);
123
124                 /* Select ES, RO, NS, RDSIZE,DPTR Fomat#0 for
125                  * the Input Queues
126                  */
127                 lio_write_csr64(lio_dev, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
128                                 CN23XX_PKT_INPUT_CTL_MASK);
129         }
130
131         return 0;
132 }
133
134 static void
135 cn23xx_vf_setup_global_output_regs(struct lio_device *lio_dev)
136 {
137         uint32_t reg_val;
138         uint32_t q_no;
139
140         PMD_INIT_FUNC_TRACE();
141
142         for (q_no = 0; q_no < lio_dev->sriov_info.rings_per_vf; q_no++) {
143                 lio_write_csr(lio_dev, CN23XX_SLI_OQ_PKTS_CREDIT(q_no),
144                               0xFFFFFFFF);
145
146                 reg_val =
147                     lio_read_csr(lio_dev, CN23XX_SLI_OQ_PKTS_SENT(q_no));
148
149                 reg_val &= 0xEFFFFFFFFFFFFFFFL;
150
151                 reg_val =
152                     lio_read_csr(lio_dev, CN23XX_SLI_OQ_PKT_CONTROL(q_no));
153
154                 /* set IPTR & DPTR */
155                 reg_val |=
156                     (CN23XX_PKT_OUTPUT_CTL_IPTR | CN23XX_PKT_OUTPUT_CTL_DPTR);
157
158                 /* reset BMODE */
159                 reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_BMODE);
160
161                 /* No Relaxed Ordering, No Snoop, 64-bit Byte swap
162                  * for Output Queue Scatter List
163                  * reset ROR_P, NSR_P
164                  */
165                 reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_ROR_P);
166                 reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_NSR_P);
167
168 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
169                 reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_ES_P);
170 #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
171                 reg_val |= (CN23XX_PKT_OUTPUT_CTL_ES_P);
172 #endif
173                 /* No Relaxed Ordering, No Snoop, 64-bit Byte swap
174                  * for Output Queue Data
175                  * reset ROR, NSR
176                  */
177                 reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_ROR);
178                 reg_val &= ~(CN23XX_PKT_OUTPUT_CTL_NSR);
179                 /* set the ES bit */
180                 reg_val |= (CN23XX_PKT_OUTPUT_CTL_ES);
181
182                 /* write all the selected settings */
183                 lio_write_csr(lio_dev, CN23XX_SLI_OQ_PKT_CONTROL(q_no),
184                               reg_val);
185         }
186 }
187
188 static int
189 cn23xx_vf_setup_device_regs(struct lio_device *lio_dev)
190 {
191         PMD_INIT_FUNC_TRACE();
192
193         if (cn23xx_vf_setup_global_input_regs(lio_dev))
194                 return -1;
195
196         cn23xx_vf_setup_global_output_regs(lio_dev);
197
198         return 0;
199 }
200
201 static void
202 cn23xx_vf_setup_iq_regs(struct lio_device *lio_dev, uint32_t iq_no)
203 {
204         struct lio_instr_queue *iq = lio_dev->instr_queue[iq_no];
205         uint64_t pkt_in_done = 0;
206
207         PMD_INIT_FUNC_TRACE();
208
209         /* Write the start of the input queue's ring and its size */
210         lio_write_csr64(lio_dev, CN23XX_SLI_IQ_BASE_ADDR64(iq_no),
211                         iq->base_addr_dma);
212         lio_write_csr(lio_dev, CN23XX_SLI_IQ_SIZE(iq_no), iq->max_count);
213
214         /* Remember the doorbell & instruction count register addr
215          * for this queue
216          */
217         iq->doorbell_reg = (uint8_t *)lio_dev->hw_addr +
218                                 CN23XX_SLI_IQ_DOORBELL(iq_no);
219         iq->inst_cnt_reg = (uint8_t *)lio_dev->hw_addr +
220                                 CN23XX_SLI_IQ_INSTR_COUNT64(iq_no);
221         lio_dev_dbg(lio_dev, "InstQ[%d]:dbell reg @ 0x%p instcnt_reg @ 0x%p\n",
222                     iq_no, iq->doorbell_reg, iq->inst_cnt_reg);
223
224         /* Store the current instruction counter (used in flush_iq
225          * calculation)
226          */
227         pkt_in_done = rte_read64(iq->inst_cnt_reg);
228
229         /* Clear the count by writing back what we read, but don't
230          * enable data traffic here
231          */
232         rte_write64(pkt_in_done, iq->inst_cnt_reg);
233 }
234
235 static void
236 cn23xx_vf_setup_oq_regs(struct lio_device *lio_dev, uint32_t oq_no)
237 {
238         struct lio_droq *droq = lio_dev->droq[oq_no];
239
240         PMD_INIT_FUNC_TRACE();
241
242         lio_write_csr64(lio_dev, CN23XX_SLI_OQ_BASE_ADDR64(oq_no),
243                         droq->desc_ring_dma);
244         lio_write_csr(lio_dev, CN23XX_SLI_OQ_SIZE(oq_no), droq->max_count);
245
246         lio_write_csr(lio_dev, CN23XX_SLI_OQ_BUFF_INFO_SIZE(oq_no),
247                       (droq->buffer_size | (OCTEON_RH_SIZE << 16)));
248
249         /* Get the mapped address of the pkt_sent and pkts_credit regs */
250         droq->pkts_sent_reg = (uint8_t *)lio_dev->hw_addr +
251                                         CN23XX_SLI_OQ_PKTS_SENT(oq_no);
252         droq->pkts_credit_reg = (uint8_t *)lio_dev->hw_addr +
253                                         CN23XX_SLI_OQ_PKTS_CREDIT(oq_no);
254 }
255
256 static void
257 cn23xx_vf_free_mbox(struct lio_device *lio_dev)
258 {
259         PMD_INIT_FUNC_TRACE();
260
261         rte_free(lio_dev->mbox[0]);
262         lio_dev->mbox[0] = NULL;
263
264         rte_free(lio_dev->mbox);
265         lio_dev->mbox = NULL;
266 }
267
268 static int
269 cn23xx_vf_setup_mbox(struct lio_device *lio_dev)
270 {
271         struct lio_mbox *mbox;
272
273         PMD_INIT_FUNC_TRACE();
274
275         if (lio_dev->mbox == NULL) {
276                 lio_dev->mbox = rte_zmalloc(NULL, sizeof(void *), 0);
277                 if (lio_dev->mbox == NULL)
278                         return -ENOMEM;
279         }
280
281         mbox = rte_zmalloc(NULL, sizeof(struct lio_mbox), 0);
282         if (mbox == NULL) {
283                 rte_free(lio_dev->mbox);
284                 lio_dev->mbox = NULL;
285                 return -ENOMEM;
286         }
287
288         rte_spinlock_init(&mbox->lock);
289
290         mbox->lio_dev = lio_dev;
291
292         mbox->q_no = 0;
293
294         mbox->state = LIO_MBOX_STATE_IDLE;
295
296         /* VF mbox interrupt reg */
297         mbox->mbox_int_reg = (uint8_t *)lio_dev->hw_addr +
298                                 CN23XX_VF_SLI_PKT_MBOX_INT(0);
299         /* VF reads from SIG0 reg */
300         mbox->mbox_read_reg = (uint8_t *)lio_dev->hw_addr +
301                                 CN23XX_SLI_PKT_PF_VF_MBOX_SIG(0, 0);
302         /* VF writes into SIG1 reg */
303         mbox->mbox_write_reg = (uint8_t *)lio_dev->hw_addr +
304                                 CN23XX_SLI_PKT_PF_VF_MBOX_SIG(0, 1);
305
306         lio_dev->mbox[0] = mbox;
307
308         rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg);
309
310         return 0;
311 }
312
313 static int
314 cn23xx_vf_enable_io_queues(struct lio_device *lio_dev)
315 {
316         uint32_t q_no;
317
318         PMD_INIT_FUNC_TRACE();
319
320         for (q_no = 0; q_no < lio_dev->num_iqs; q_no++) {
321                 uint64_t reg_val;
322
323                 /* set the corresponding IQ IS_64B bit */
324                 if (lio_dev->io_qmask.iq64B & (1ULL << q_no)) {
325                         reg_val = lio_read_csr64(
326                                         lio_dev,
327                                         CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
328                         reg_val = reg_val | CN23XX_PKT_INPUT_CTL_IS_64B;
329                         lio_write_csr64(lio_dev,
330                                         CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
331                                         reg_val);
332                 }
333
334                 /* set the corresponding IQ ENB bit */
335                 if (lio_dev->io_qmask.iq & (1ULL << q_no)) {
336                         reg_val = lio_read_csr64(
337                                         lio_dev,
338                                         CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
339                         reg_val = reg_val | CN23XX_PKT_INPUT_CTL_RING_ENB;
340                         lio_write_csr64(lio_dev,
341                                         CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
342                                         reg_val);
343                 }
344         }
345         for (q_no = 0; q_no < lio_dev->num_oqs; q_no++) {
346                 uint32_t reg_val;
347
348                 /* set the corresponding OQ ENB bit */
349                 if (lio_dev->io_qmask.oq & (1ULL << q_no)) {
350                         reg_val = lio_read_csr(
351                                         lio_dev,
352                                         CN23XX_SLI_OQ_PKT_CONTROL(q_no));
353                         reg_val = reg_val | CN23XX_PKT_OUTPUT_CTL_RING_ENB;
354                         lio_write_csr(lio_dev,
355                                       CN23XX_SLI_OQ_PKT_CONTROL(q_no),
356                                       reg_val);
357                 }
358         }
359
360         return 0;
361 }
362
363 static void
364 cn23xx_vf_disable_io_queues(struct lio_device *lio_dev)
365 {
366         uint32_t num_queues;
367
368         PMD_INIT_FUNC_TRACE();
369
370         /* per HRM, rings can only be disabled via reset operation,
371          * NOT via SLI_PKT()_INPUT/OUTPUT_CONTROL[ENB]
372          */
373         num_queues = lio_dev->num_iqs;
374         if (num_queues < lio_dev->num_oqs)
375                 num_queues = lio_dev->num_oqs;
376
377         cn23xx_vf_reset_io_queues(lio_dev, num_queues);
378 }
379
380 void
381 cn23xx_vf_ask_pf_to_do_flr(struct lio_device *lio_dev)
382 {
383         struct lio_mbox_cmd mbox_cmd;
384
385         mbox_cmd.msg.mbox_msg64 = 0;
386         mbox_cmd.msg.s.type = LIO_MBOX_REQUEST;
387         mbox_cmd.msg.s.resp_needed = 0;
388         mbox_cmd.msg.s.cmd = LIO_VF_FLR_REQUEST;
389         mbox_cmd.msg.s.len = 1;
390         mbox_cmd.q_no = 0;
391         mbox_cmd.recv_len = 0;
392         mbox_cmd.recv_status = 0;
393         mbox_cmd.fn = NULL;
394         mbox_cmd.fn_arg = 0;
395
396         lio_mbox_write(lio_dev, &mbox_cmd);
397 }
398
399 static void
400 cn23xx_pfvf_hs_callback(struct lio_device *lio_dev,
401                         struct lio_mbox_cmd *cmd, void *arg)
402 {
403         uint32_t major = 0;
404
405         PMD_INIT_FUNC_TRACE();
406
407         rte_memcpy((uint8_t *)&lio_dev->pfvf_hsword, cmd->msg.s.params, 6);
408         if (cmd->recv_len > 1) {
409                 struct lio_version *lio_ver = (struct lio_version *)cmd->data;
410
411                 major = lio_ver->major;
412                 major = major << 16;
413         }
414
415         rte_atomic64_set((rte_atomic64_t *)arg, major | 1);
416 }
417
418 int
419 cn23xx_pfvf_handshake(struct lio_device *lio_dev)
420 {
421         struct lio_mbox_cmd mbox_cmd;
422         struct lio_version *lio_ver = (struct lio_version *)&mbox_cmd.data[0];
423         uint32_t q_no, count = 0;
424         rte_atomic64_t status;
425         uint32_t pfmajor;
426         uint32_t vfmajor;
427         uint32_t ret;
428
429         PMD_INIT_FUNC_TRACE();
430
431         /* Sending VF_ACTIVE indication to the PF driver */
432         lio_dev_dbg(lio_dev, "requesting info from PF\n");
433
434         mbox_cmd.msg.mbox_msg64 = 0;
435         mbox_cmd.msg.s.type = LIO_MBOX_REQUEST;
436         mbox_cmd.msg.s.resp_needed = 1;
437         mbox_cmd.msg.s.cmd = LIO_VF_ACTIVE;
438         mbox_cmd.msg.s.len = 2;
439         mbox_cmd.data[0] = 0;
440         lio_ver->major = LIO_BASE_MAJOR_VERSION;
441         lio_ver->minor = LIO_BASE_MINOR_VERSION;
442         lio_ver->micro = LIO_BASE_MICRO_VERSION;
443         mbox_cmd.q_no = 0;
444         mbox_cmd.recv_len = 0;
445         mbox_cmd.recv_status = 0;
446         mbox_cmd.fn = (lio_mbox_callback)cn23xx_pfvf_hs_callback;
447         mbox_cmd.fn_arg = (void *)&status;
448
449         if (lio_mbox_write(lio_dev, &mbox_cmd)) {
450                 lio_dev_err(lio_dev, "Write to mailbox failed\n");
451                 return -1;
452         }
453
454         rte_atomic64_set(&status, 0);
455
456         do {
457                 rte_delay_ms(1);
458         } while ((rte_atomic64_read(&status) == 0) && (count++ < 10000));
459
460         ret = rte_atomic64_read(&status);
461         if (ret == 0) {
462                 lio_dev_err(lio_dev, "cn23xx_pfvf_handshake timeout\n");
463                 return -1;
464         }
465
466         for (q_no = 0; q_no < lio_dev->num_iqs; q_no++)
467                 lio_dev->instr_queue[q_no]->txpciq.s.pkind =
468                                                 lio_dev->pfvf_hsword.pkind;
469
470         vfmajor = LIO_BASE_MAJOR_VERSION;
471         pfmajor = ret >> 16;
472         if (pfmajor != vfmajor) {
473                 lio_dev_err(lio_dev,
474                             "VF LiquidIO driver (major version %d) is not compatible with LiquidIO PF driver (major version %d)\n",
475                             vfmajor, pfmajor);
476                 ret = -EPERM;
477         } else {
478                 lio_dev_dbg(lio_dev,
479                             "VF LiquidIO driver (major version %d), LiquidIO PF driver (major version %d)\n",
480                             vfmajor, pfmajor);
481                 ret = 0;
482         }
483
484         lio_dev_dbg(lio_dev, "got data from PF pkind is %d\n",
485                     lio_dev->pfvf_hsword.pkind);
486
487         return ret;
488 }
489
490 void
491 cn23xx_vf_handle_mbox(struct lio_device *lio_dev)
492 {
493         uint64_t mbox_int_val;
494
495         /* read and clear by writing 1 */
496         mbox_int_val = rte_read64(lio_dev->mbox[0]->mbox_int_reg);
497         rte_write64(mbox_int_val, lio_dev->mbox[0]->mbox_int_reg);
498         if (lio_mbox_read(lio_dev->mbox[0]))
499                 lio_mbox_process_message(lio_dev->mbox[0]);
500 }
501
502 int
503 cn23xx_vf_setup_device(struct lio_device *lio_dev)
504 {
505         uint64_t reg_val;
506
507         PMD_INIT_FUNC_TRACE();
508
509         /* INPUT_CONTROL[RPVF] gives the VF IOq count */
510         reg_val = lio_read_csr64(lio_dev, CN23XX_SLI_IQ_PKT_CONTROL64(0));
511
512         lio_dev->pf_num = (reg_val >> CN23XX_PKT_INPUT_CTL_PF_NUM_POS) &
513                                 CN23XX_PKT_INPUT_CTL_PF_NUM_MASK;
514         lio_dev->vf_num = (reg_val >> CN23XX_PKT_INPUT_CTL_VF_NUM_POS) &
515                                 CN23XX_PKT_INPUT_CTL_VF_NUM_MASK;
516
517         reg_val = reg_val >> CN23XX_PKT_INPUT_CTL_RPVF_POS;
518
519         lio_dev->sriov_info.rings_per_vf =
520                                 reg_val & CN23XX_PKT_INPUT_CTL_RPVF_MASK;
521
522         lio_dev->default_config = lio_get_conf(lio_dev);
523         if (lio_dev->default_config == NULL)
524                 return -1;
525
526         lio_dev->fn_list.setup_iq_regs          = cn23xx_vf_setup_iq_regs;
527         lio_dev->fn_list.setup_oq_regs          = cn23xx_vf_setup_oq_regs;
528         lio_dev->fn_list.setup_mbox             = cn23xx_vf_setup_mbox;
529         lio_dev->fn_list.free_mbox              = cn23xx_vf_free_mbox;
530
531         lio_dev->fn_list.setup_device_regs      = cn23xx_vf_setup_device_regs;
532
533         lio_dev->fn_list.enable_io_queues       = cn23xx_vf_enable_io_queues;
534         lio_dev->fn_list.disable_io_queues      = cn23xx_vf_disable_io_queues;
535
536         return 0;
537 }
538
539 int
540 cn23xx_vf_set_io_queues_off(struct lio_device *lio_dev)
541 {
542         uint32_t loop = CN23XX_VF_BUSY_READING_REG_LOOP_COUNT;
543         uint64_t q_no;
544
545         /* Disable the i/p and o/p queues for this Octeon.
546          * IOQs will already be in reset.
547          * If RST bit is set, wait for Quiet bit to be set
548          * Once Quiet bit is set, clear the RST bit
549          */
550         PMD_INIT_FUNC_TRACE();
551
552         for (q_no = 0; q_no < lio_dev->sriov_info.rings_per_vf; q_no++) {
553                 volatile uint64_t reg_val;
554
555                 reg_val = lio_read_csr64(lio_dev,
556                                          CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
557                 while ((reg_val & CN23XX_PKT_INPUT_CTL_RST) && !(reg_val &
558                                          CN23XX_PKT_INPUT_CTL_QUIET) && loop) {
559                         reg_val = lio_read_csr64(
560                                         lio_dev,
561                                         CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
562                         loop = loop - 1;
563                 }
564
565                 if (loop == 0) {
566                         lio_dev_err(lio_dev,
567                                     "clearing the reset reg failed or setting the quiet reg failed for qno %lu\n",
568                                     (unsigned long)q_no);
569                         return -1;
570                 }
571
572                 reg_val = reg_val & ~CN23XX_PKT_INPUT_CTL_RST;
573                 lio_write_csr64(lio_dev, CN23XX_SLI_IQ_PKT_CONTROL64(q_no),
574                                 reg_val);
575
576                 reg_val = lio_read_csr64(lio_dev,
577                                          CN23XX_SLI_IQ_PKT_CONTROL64(q_no));
578                 if (reg_val & CN23XX_PKT_INPUT_CTL_RST) {
579                         lio_dev_err(lio_dev, "unable to reset qno %lu\n",
580                                     (unsigned long)q_no);
581                         return -1;
582                 }
583         }
584
585         return 0;
586 }