2 * Copyright (c) 2006 - 2011 Intel-NE, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/skbuff.h>
35 #include <linux/etherdevice.h>
36 #include <linux/kthread.h>
38 #include <linux/tcp.h>
43 atomic_t pau_qps_created
;
44 atomic_t pau_qps_destroyed
;
46 static void nes_replenish_mgt_rq(struct nes_vnic_mgt
*mgtvnic
)
49 dma_addr_t bus_address
;
51 struct nes_hw_nic_rq_wqe
*nic_rqe
;
52 struct nes_hw_mgt
*nesmgt
;
53 struct nes_device
*nesdev
;
54 struct nes_rskb_cb
*cb
;
55 u32 rx_wqes_posted
= 0;
57 nesmgt
= &mgtvnic
->mgt
;
58 nesdev
= mgtvnic
->nesvnic
->nesdev
;
59 spin_lock_irqsave(&nesmgt
->rq_lock
, flags
);
60 if (nesmgt
->replenishing_rq
!= 0) {
61 if (((nesmgt
->rq_size
- 1) == atomic_read(&mgtvnic
->rx_skbs_needed
)) &&
62 (atomic_read(&mgtvnic
->rx_skb_timer_running
) == 0)) {
63 atomic_set(&mgtvnic
->rx_skb_timer_running
, 1);
64 spin_unlock_irqrestore(&nesmgt
->rq_lock
, flags
);
65 mgtvnic
->rq_wqes_timer
.expires
= jiffies
+ (HZ
/ 2); /* 1/2 second */
66 add_timer(&mgtvnic
->rq_wqes_timer
);
68 spin_unlock_irqrestore(&nesmgt
->rq_lock
, flags
);
72 nesmgt
->replenishing_rq
= 1;
73 spin_unlock_irqrestore(&nesmgt
->rq_lock
, flags
);
75 skb
= dev_alloc_skb(mgtvnic
->nesvnic
->max_frame_size
);
77 skb
->dev
= mgtvnic
->nesvnic
->netdev
;
79 bus_address
= pci_map_single(nesdev
->pcidev
,
80 skb
->data
, mgtvnic
->nesvnic
->max_frame_size
, PCI_DMA_FROMDEVICE
);
81 cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
82 cb
->busaddr
= bus_address
;
83 cb
->maplen
= mgtvnic
->nesvnic
->max_frame_size
;
85 nic_rqe
= &nesmgt
->rq_vbase
[mgtvnic
->mgt
.rq_head
];
86 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_LENGTH_1_0_IDX
] =
87 cpu_to_le32(mgtvnic
->nesvnic
->max_frame_size
);
88 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_LENGTH_3_2_IDX
] = 0;
89 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_LOW_IDX
] =
90 cpu_to_le32((u32
)bus_address
);
91 nic_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX
] =
92 cpu_to_le32((u32
)((u64
)bus_address
>> 32));
93 nesmgt
->rx_skb
[nesmgt
->rq_head
] = skb
;
95 nesmgt
->rq_head
&= nesmgt
->rq_size
- 1;
96 atomic_dec(&mgtvnic
->rx_skbs_needed
);
98 if (++rx_wqes_posted
== 255) {
99 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
, (rx_wqes_posted
<< 24) | nesmgt
->qp_id
);
103 spin_lock_irqsave(&nesmgt
->rq_lock
, flags
);
104 if (((nesmgt
->rq_size
- 1) == atomic_read(&mgtvnic
->rx_skbs_needed
)) &&
105 (atomic_read(&mgtvnic
->rx_skb_timer_running
) == 0)) {
106 atomic_set(&mgtvnic
->rx_skb_timer_running
, 1);
107 spin_unlock_irqrestore(&nesmgt
->rq_lock
, flags
);
108 mgtvnic
->rq_wqes_timer
.expires
= jiffies
+ (HZ
/ 2); /* 1/2 second */
109 add_timer(&mgtvnic
->rq_wqes_timer
);
111 spin_unlock_irqrestore(&nesmgt
->rq_lock
, flags
);
115 } while (atomic_read(&mgtvnic
->rx_skbs_needed
));
118 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
, (rx_wqes_posted
<< 24) | nesmgt
->qp_id
);
119 nesmgt
->replenishing_rq
= 0;
123 * nes_mgt_rq_wqes_timeout
125 static void nes_mgt_rq_wqes_timeout(struct timer_list
*t
)
127 struct nes_vnic_mgt
*mgtvnic
= from_timer(mgtvnic
, t
,
130 atomic_set(&mgtvnic
->rx_skb_timer_running
, 0);
131 if (atomic_read(&mgtvnic
->rx_skbs_needed
))
132 nes_replenish_mgt_rq(mgtvnic
);
136 * nes_mgt_free_skb - unmap and free skb
138 static void nes_mgt_free_skb(struct nes_device
*nesdev
, struct sk_buff
*skb
, u32 dir
)
140 struct nes_rskb_cb
*cb
;
142 cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
143 pci_unmap_single(nesdev
->pcidev
, cb
->busaddr
, cb
->maplen
, dir
);
145 dev_kfree_skb_any(skb
);
149 * nes_download_callback - handle download completions
151 static void nes_download_callback(struct nes_device
*nesdev
, struct nes_cqp_request
*cqp_request
)
153 struct pau_fpdu_info
*fpdu_info
= cqp_request
->cqp_callback_pointer
;
154 struct nes_qp
*nesqp
= fpdu_info
->nesqp
;
158 for (i
= 0; i
< fpdu_info
->frag_cnt
; i
++) {
159 skb
= fpdu_info
->frags
[i
].skb
;
160 if (fpdu_info
->frags
[i
].cmplt
) {
161 nes_mgt_free_skb(nesdev
, skb
, PCI_DMA_TODEVICE
);
162 nes_rem_ref_cm_node(nesqp
->cm_node
);
166 if (fpdu_info
->hdr_vbase
)
167 pci_free_consistent(nesdev
->pcidev
, fpdu_info
->hdr_len
,
168 fpdu_info
->hdr_vbase
, fpdu_info
->hdr_pbase
);
173 * nes_get_seq - Get the seq, ack_seq and window from the packet
175 static u32
nes_get_seq(struct sk_buff
*skb
, u32
*ack
, u16
*wnd
, u32
*fin_rcvd
, u32
*rst_rcvd
)
177 struct nes_rskb_cb
*cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
178 struct iphdr
*iph
= (struct iphdr
*)(cb
->data_start
+ ETH_HLEN
);
179 struct tcphdr
*tcph
= (struct tcphdr
*)(((char *)iph
) + (4 * iph
->ihl
));
181 *ack
= be32_to_cpu(tcph
->ack_seq
);
182 *wnd
= be16_to_cpu(tcph
->window
);
183 *fin_rcvd
= tcph
->fin
;
184 *rst_rcvd
= tcph
->rst
;
185 return be32_to_cpu(tcph
->seq
);
189 * nes_get_next_skb - Get the next skb based on where current skb is in the queue
191 static struct sk_buff
*nes_get_next_skb(struct nes_device
*nesdev
, struct nes_qp
*nesqp
,
192 struct sk_buff
*skb
, u32 nextseq
, u32
*ack
,
193 u16
*wnd
, u32
*fin_rcvd
, u32
*rst_rcvd
)
197 struct sk_buff
*old_skb
;
200 /* Continue processing fpdu */
201 if (skb
->next
== (struct sk_buff
*)&nesqp
->pau_list
)
206 /* Starting a new one */
207 if (skb_queue_empty(&nesqp
->pau_list
))
209 skb
= skb_peek(&nesqp
->pau_list
);
214 if (skb_queue_empty(&nesqp
->pau_list
))
217 seq
= nes_get_seq(skb
, ack
, wnd
, fin_rcvd
, rst_rcvd
);
218 if (seq
== nextseq
) {
219 if (skb
->len
|| processacks
)
221 } else if (after(seq
, nextseq
)) {
227 skb_unlink(old_skb
, &nesqp
->pau_list
);
228 nes_mgt_free_skb(nesdev
, old_skb
, PCI_DMA_TODEVICE
);
229 nes_rem_ref_cm_node(nesqp
->cm_node
);
230 if (skb
== (struct sk_buff
*)&nesqp
->pau_list
)
240 * get_fpdu_info - Find the next complete fpdu and return its fragments.
242 static int get_fpdu_info(struct nes_device
*nesdev
, struct nes_qp
*nesqp
,
243 struct pau_fpdu_info
**pau_fpdu_info
)
248 struct nes_rskb_cb
*cb
;
249 struct pau_fpdu_info
*fpdu_info
= NULL
;
250 struct pau_fpdu_frag frags
[MAX_FPDU_FRAGS
];
263 *pau_fpdu_info
= NULL
;
265 skb
= nes_get_next_skb(nesdev
, nesqp
, NULL
, nesqp
->pau_rcv_nxt
, &ack
, &wnd
, &fin_rcvd
, &rst_rcvd
);
269 cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
271 fpdu_len
= be16_to_cpu(*(__be16
*) skb
->data
) + MPA_FRAMING
;
272 fpdu_len
= (fpdu_len
+ 3) & 0xfffffffc;
275 /* See if we have all of the fpdu */
277 memset(&frags
, 0, sizeof frags
);
278 for (i
= 0; i
< MAX_FPDU_FRAGS
; i
++) {
279 frags
[i
].physaddr
= cb
->busaddr
;
280 frags
[i
].physaddr
+= skb
->data
- cb
->data_start
;
281 frags
[i
].frag_len
= min(tmp_len
, skb
->len
);
283 frags
[i
].cmplt
= (skb
->len
== frags
[i
].frag_len
);
284 frag_tot
+= frags
[i
].frag_len
;
287 tmp_len
-= frags
[i
].frag_len
;
291 skb
= nes_get_next_skb(nesdev
, nesqp
, skb
,
292 nesqp
->pau_rcv_nxt
+ frag_tot
, &ack
, &wnd
, &fin_rcvd
, &rst_rcvd
);
296 /* rst received in the middle of fpdu */
297 for (; i
>= 0; i
--) {
298 skb_unlink(frags
[i
].skb
, &nesqp
->pau_list
);
299 nes_mgt_free_skb(nesdev
, frags
[i
].skb
, PCI_DMA_TODEVICE
);
301 cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
302 frags
[0].physaddr
= cb
->busaddr
;
303 frags
[0].physaddr
+= skb
->data
- cb
->data_start
;
304 frags
[0].frag_len
= skb
->len
;
306 frags
[0].cmplt
= true;
311 cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
315 frags
[0].physaddr
= cb
->busaddr
;
316 frags
[0].frag_len
= 0;
318 frags
[0].cmplt
= true;
323 fpdu_info
= kzalloc(sizeof(*fpdu_info
), GFP_ATOMIC
);
329 fpdu_info
->cqp_request
= nes_get_cqp_request(nesdev
);
330 if (fpdu_info
->cqp_request
== NULL
) {
331 nes_debug(NES_DBG_PAU
, "Failed to get a cqp_request.\n");
336 cb
= (struct nes_rskb_cb
*)&frags
[0].skb
->cb
[0];
337 iph
= (struct iphdr
*)(cb
->data_start
+ ETH_HLEN
);
338 tcph
= (struct tcphdr
*)(((char *)iph
) + (4 * iph
->ihl
));
339 fpdu_info
->hdr_len
= (((unsigned char *)tcph
) + 4 * (tcph
->doff
)) - cb
->data_start
;
340 fpdu_info
->data_len
= fpdu_len
;
341 tot_len
= fpdu_info
->hdr_len
+ fpdu_len
- ETH_HLEN
;
343 if (frags
[0].cmplt
) {
344 fpdu_info
->hdr_pbase
= cb
->busaddr
;
345 fpdu_info
->hdr_vbase
= NULL
;
347 fpdu_info
->hdr_vbase
= pci_alloc_consistent(nesdev
->pcidev
,
348 fpdu_info
->hdr_len
, &fpdu_info
->hdr_pbase
);
349 if (!fpdu_info
->hdr_vbase
) {
350 nes_debug(NES_DBG_PAU
, "Unable to allocate memory for pau first frag\n");
355 /* Copy hdrs, adjusting len and seqnum */
356 memcpy(fpdu_info
->hdr_vbase
, cb
->data_start
, fpdu_info
->hdr_len
);
357 iph
= (struct iphdr
*)(fpdu_info
->hdr_vbase
+ ETH_HLEN
);
358 tcph
= (struct tcphdr
*)(((char *)iph
) + (4 * iph
->ihl
));
361 iph
->tot_len
= cpu_to_be16(tot_len
);
362 iph
->saddr
= cpu_to_be32(0x7f000001);
364 tcph
->seq
= cpu_to_be32(nesqp
->pau_rcv_nxt
);
365 tcph
->ack_seq
= cpu_to_be32(ack
);
366 tcph
->window
= cpu_to_be16(wnd
);
368 nesqp
->pau_rcv_nxt
+= fpdu_len
+ fin_rcvd
;
370 memcpy(fpdu_info
->frags
, frags
, sizeof(fpdu_info
->frags
));
371 fpdu_info
->frag_cnt
= frag_cnt
;
372 fpdu_info
->nesqp
= nesqp
;
373 *pau_fpdu_info
= fpdu_info
;
375 /* Update skb's for next pass */
376 for (i
= 0; i
< frag_cnt
; i
++) {
377 cb
= (struct nes_rskb_cb
*)&frags
[i
].skb
->cb
[0];
378 skb_pull(frags
[i
].skb
, frags
[i
].frag_len
);
380 if (frags
[i
].skb
->len
== 0) {
381 /* Pull skb off the list - it will be freed in the callback */
382 if (!skb_queue_empty(&nesqp
->pau_list
))
383 skb_unlink(frags
[i
].skb
, &nesqp
->pau_list
);
385 /* Last skb still has data so update the seq */
386 iph
= (struct iphdr
*)(cb
->data_start
+ ETH_HLEN
);
387 tcph
= (struct tcphdr
*)(((char *)iph
) + (4 * iph
->ihl
));
388 tcph
->seq
= cpu_to_be32(nesqp
->pau_rcv_nxt
);
395 if (fpdu_info
->cqp_request
)
396 nes_put_cqp_request(nesdev
, fpdu_info
->cqp_request
);
404 * forward_fpdu - send complete fpdus, one at a time
406 static int forward_fpdus(struct nes_vnic
*nesvnic
, struct nes_qp
*nesqp
)
408 struct nes_device
*nesdev
= nesvnic
->nesdev
;
409 struct pau_fpdu_info
*fpdu_info
;
410 struct nes_hw_cqp_wqe
*cqp_wqe
;
411 struct nes_cqp_request
*cqp_request
;
418 spin_lock_irqsave(&nesqp
->pau_lock
, flags
);
419 rc
= get_fpdu_info(nesdev
, nesqp
, &fpdu_info
);
420 if (rc
|| (fpdu_info
== NULL
)) {
421 spin_unlock_irqrestore(&nesqp
->pau_lock
, flags
);
425 cqp_request
= fpdu_info
->cqp_request
;
426 cqp_wqe
= &cqp_request
->cqp_wqe
;
427 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
428 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_DL_OPCODE_IDX
,
429 NES_CQP_DOWNLOAD_SEGMENT
|
430 (((u32
)nesvnic
->logical_port
) << NES_CQP_OP_LOGICAL_PORT_SHIFT
));
432 u32tmp
= fpdu_info
->hdr_len
<< 16;
433 u32tmp
|= fpdu_info
->hdr_len
+ (u32
)fpdu_info
->data_len
;
434 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_DL_LENGTH_0_TOTAL_IDX
,
437 u32tmp
= (fpdu_info
->frags
[1].frag_len
<< 16) | fpdu_info
->frags
[0].frag_len
;
438 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_LENGTH_2_1_IDX
,
441 u32tmp
= (fpdu_info
->frags
[3].frag_len
<< 16) | fpdu_info
->frags
[2].frag_len
;
442 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_LENGTH_4_3_IDX
,
445 u64tmp
= (u64
)fpdu_info
->hdr_pbase
;
446 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG0_LOW_IDX
,
447 lower_32_bits(u64tmp
));
448 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG0_HIGH_IDX
,
449 upper_32_bits(u64tmp
));
451 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG1_LOW_IDX
,
452 lower_32_bits(fpdu_info
->frags
[0].physaddr
));
453 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG1_HIGH_IDX
,
454 upper_32_bits(fpdu_info
->frags
[0].physaddr
));
456 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG2_LOW_IDX
,
457 lower_32_bits(fpdu_info
->frags
[1].physaddr
));
458 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG2_HIGH_IDX
,
459 upper_32_bits(fpdu_info
->frags
[1].physaddr
));
461 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG3_LOW_IDX
,
462 lower_32_bits(fpdu_info
->frags
[2].physaddr
));
463 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG3_HIGH_IDX
,
464 upper_32_bits(fpdu_info
->frags
[2].physaddr
));
466 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG4_LOW_IDX
,
467 lower_32_bits(fpdu_info
->frags
[3].physaddr
));
468 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG4_HIGH_IDX
,
469 upper_32_bits(fpdu_info
->frags
[3].physaddr
));
471 cqp_request
->cqp_callback_pointer
= fpdu_info
;
472 cqp_request
->callback
= 1;
473 cqp_request
->cqp_callback
= nes_download_callback
;
475 atomic_set(&cqp_request
->refcount
, 1);
476 nes_post_cqp_request(nesdev
, cqp_request
);
477 spin_unlock_irqrestore(&nesqp
->pau_lock
, flags
);
483 static void process_fpdus(struct nes_vnic
*nesvnic
, struct nes_qp
*nesqp
)
489 /* Ignore rc - if it failed, tcp retries will cause it to try again */
490 forward_fpdus(nesvnic
, nesqp
);
492 spin_lock_irqsave(&nesqp
->pau_lock
, flags
);
493 if (nesqp
->pau_pending
) {
494 nesqp
->pau_pending
= 0;
500 spin_unlock_irqrestore(&nesqp
->pau_lock
, flags
);
505 * queue_fpdus - Handle fpdu's that hw passed up to sw
507 static void queue_fpdus(struct sk_buff
*skb
, struct nes_vnic
*nesvnic
, struct nes_qp
*nesqp
)
509 struct sk_buff
*tmpskb
;
510 struct nes_rskb_cb
*cb
;
513 unsigned char *tcph_end
;
518 bool process_it
= false;
521 /* Move data ptr to after tcp header */
522 iph
= (struct iphdr
*)skb
->data
;
523 tcph
= (struct tcphdr
*)(((char *)iph
) + (4 * iph
->ihl
));
524 seqnum
= be32_to_cpu(tcph
->seq
);
525 tcph_end
= (((char *)tcph
) + (4 * tcph
->doff
));
527 len
= be16_to_cpu(iph
->tot_len
);
530 skb_pull(skb
, tcph_end
- skb
->data
);
532 /* Initialize tracking values */
533 cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
536 /* Make sure data is in the receive window */
537 rcv_nxt
= nesqp
->pau_rcv_nxt
;
538 rcv_wnd
= le32_to_cpu(nesqp
->nesqp_context
->rcv_wnd
);
539 if (!between(seqnum
, rcv_nxt
, (rcv_nxt
+ rcv_wnd
))) {
540 nes_mgt_free_skb(nesvnic
->nesdev
, skb
, PCI_DMA_TODEVICE
);
541 nes_rem_ref_cm_node(nesqp
->cm_node
);
545 spin_lock_irqsave(&nesqp
->pau_lock
, flags
);
548 nesqp
->pau_pending
= 1;
552 /* Queue skb by sequence number */
553 if (skb_queue_len(&nesqp
->pau_list
) == 0) {
554 skb_queue_head(&nesqp
->pau_list
, skb
);
556 tmpskb
= nesqp
->pau_list
.next
;
557 while (tmpskb
!= (struct sk_buff
*)&nesqp
->pau_list
) {
558 cb
= (struct nes_rskb_cb
*)&tmpskb
->cb
[0];
559 if (before(seqnum
, cb
->seqnum
))
561 tmpskb
= tmpskb
->next
;
563 skb_insert(tmpskb
, skb
, &nesqp
->pau_list
);
565 if (nesqp
->pau_state
== PAU_READY
)
567 spin_unlock_irqrestore(&nesqp
->pau_lock
, flags
);
570 process_fpdus(nesvnic
, nesqp
);
576 * mgt_thread - Handle mgt skbs in a safe context
578 static int mgt_thread(void *context
)
580 struct nes_vnic
*nesvnic
= context
;
582 struct nes_rskb_cb
*cb
;
584 while (!kthread_should_stop()) {
585 wait_event_interruptible(nesvnic
->mgt_wait_queue
,
586 skb_queue_len(&nesvnic
->mgt_skb_list
) || kthread_should_stop());
587 while ((skb_queue_len(&nesvnic
->mgt_skb_list
)) && !kthread_should_stop()) {
588 skb
= skb_dequeue(&nesvnic
->mgt_skb_list
);
589 cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
590 cb
->data_start
= skb
->data
- ETH_HLEN
;
591 cb
->busaddr
= pci_map_single(nesvnic
->nesdev
->pcidev
, cb
->data_start
,
592 nesvnic
->max_frame_size
, PCI_DMA_TODEVICE
);
593 queue_fpdus(skb
, nesvnic
, cb
->nesqp
);
597 /* Closing down so delete any entries on the queue */
598 while (skb_queue_len(&nesvnic
->mgt_skb_list
)) {
599 skb
= skb_dequeue(&nesvnic
->mgt_skb_list
);
600 cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
601 nes_rem_ref_cm_node(cb
->nesqp
->cm_node
);
602 dev_kfree_skb_any(skb
);
608 * nes_queue_skbs - Queue skb so it can be handled in a thread context
610 void nes_queue_mgt_skbs(struct sk_buff
*skb
, struct nes_vnic
*nesvnic
, struct nes_qp
*nesqp
)
612 struct nes_rskb_cb
*cb
;
614 cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
616 skb_queue_tail(&nesvnic
->mgt_skb_list
, skb
);
617 wake_up_interruptible(&nesvnic
->mgt_wait_queue
);
620 void nes_destroy_pau_qp(struct nes_device
*nesdev
, struct nes_qp
*nesqp
)
624 atomic_inc(&pau_qps_destroyed
);
626 /* Free packets that have not yet been forwarded */
627 /* Lock is acquired by skb_dequeue when removing the skb */
628 spin_lock_irqsave(&nesqp
->pau_lock
, flags
);
629 while (skb_queue_len(&nesqp
->pau_list
)) {
630 skb
= skb_dequeue(&nesqp
->pau_list
);
631 nes_mgt_free_skb(nesdev
, skb
, PCI_DMA_TODEVICE
);
632 nes_rem_ref_cm_node(nesqp
->cm_node
);
634 spin_unlock_irqrestore(&nesqp
->pau_lock
, flags
);
637 static void nes_chg_qh_handler(struct nes_device
*nesdev
, struct nes_cqp_request
*cqp_request
)
639 struct pau_qh_chg
*qh_chg
= cqp_request
->cqp_callback_pointer
;
640 struct nes_cqp_request
*new_request
;
641 struct nes_hw_cqp_wqe
*cqp_wqe
;
642 struct nes_adapter
*nesadapter
;
643 struct nes_qp
*nesqp
;
644 struct nes_v4_quad nes_quad
;
648 nesadapter
= nesdev
->nesadapter
;
649 nesqp
= qh_chg
->nesqp
;
651 /* Should we handle the bad completion */
652 if (cqp_request
->major_code
)
653 WARN(1, PFX
"Invalid cqp_request major_code=0x%x\n",
654 cqp_request
->major_code
);
656 switch (nesqp
->pau_state
) {
658 /* Old hash code deleted, now set the new one */
659 nesqp
->pau_state
= PAU_ADD_LB_QH
;
660 new_request
= nes_get_cqp_request(nesdev
);
661 if (new_request
== NULL
) {
662 nes_debug(NES_DBG_PAU
, "Failed to get a new_request.\n");
667 memset(&nes_quad
, 0, sizeof(nes_quad
));
668 nes_quad
.DstIpAdrIndex
=
669 cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 24);
670 nes_quad
.SrcIpadr
= cpu_to_be32(0x7f000001);
671 nes_quad
.TcpPorts
[0] = swab16(nesqp
->nesqp_context
->tcpPorts
[1]);
672 nes_quad
.TcpPorts
[1] = swab16(nesqp
->nesqp_context
->tcpPorts
[0]);
674 /* Produce hash key */
675 crc_value
= get_crc_value(&nes_quad
);
676 nesqp
->hte_index
= cpu_to_be32(crc_value
^ 0xffffffff);
677 nes_debug(NES_DBG_PAU
, "new HTE Index = 0x%08X, CRC = 0x%08X\n",
678 nesqp
->hte_index
, nesqp
->hte_index
& nesadapter
->hte_index_mask
);
680 nesqp
->hte_index
&= nesadapter
->hte_index_mask
;
681 nesqp
->nesqp_context
->hte_index
= cpu_to_le32(nesqp
->hte_index
);
682 nesqp
->nesqp_context
->ip0
= cpu_to_le32(0x7f000001);
683 nesqp
->nesqp_context
->rcv_nxt
= cpu_to_le32(nesqp
->pau_rcv_nxt
);
685 cqp_wqe
= &new_request
->cqp_wqe
;
686 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
687 set_wqe_32bit_value(cqp_wqe
->wqe_words
,
688 NES_CQP_WQE_OPCODE_IDX
, NES_CQP_MANAGE_QUAD_HASH
|
689 NES_CQP_QP_TYPE_IWARP
| NES_CQP_QP_CONTEXT_VALID
| NES_CQP_QP_IWARP_STATE_RTS
);
690 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
, nesqp
->hwqp
.qp_id
);
691 u64temp
= (u64
)nesqp
->nesqp_context_pbase
;
692 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_QP_WQE_CONTEXT_LOW_IDX
, u64temp
);
694 nes_debug(NES_DBG_PAU
, "Waiting for CQP completion for adding the quad hash.\n");
696 new_request
->cqp_callback_pointer
= qh_chg
;
697 new_request
->callback
= 1;
698 new_request
->cqp_callback
= nes_chg_qh_handler
;
699 atomic_set(&new_request
->refcount
, 1);
700 nes_post_cqp_request(nesdev
, new_request
);
704 /* Start processing the queued fpdu's */
705 nesqp
->pau_state
= PAU_READY
;
706 process_fpdus(qh_chg
->nesvnic
, qh_chg
->nesqp
);
713 * nes_change_quad_hash
715 static int nes_change_quad_hash(struct nes_device
*nesdev
,
716 struct nes_vnic
*nesvnic
, struct nes_qp
*nesqp
)
718 struct nes_cqp_request
*cqp_request
= NULL
;
719 struct pau_qh_chg
*qh_chg
= NULL
;
721 struct nes_hw_cqp_wqe
*cqp_wqe
;
724 cqp_request
= nes_get_cqp_request(nesdev
);
725 if (cqp_request
== NULL
) {
726 nes_debug(NES_DBG_PAU
, "Failed to get a cqp_request.\n");
731 qh_chg
= kmalloc(sizeof *qh_chg
, GFP_ATOMIC
);
736 qh_chg
->nesdev
= nesdev
;
737 qh_chg
->nesvnic
= nesvnic
;
738 qh_chg
->nesqp
= nesqp
;
739 nesqp
->pau_state
= PAU_DEL_QH
;
741 cqp_wqe
= &cqp_request
->cqp_wqe
;
742 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
743 set_wqe_32bit_value(cqp_wqe
->wqe_words
,
744 NES_CQP_WQE_OPCODE_IDX
, NES_CQP_MANAGE_QUAD_HASH
| NES_CQP_QP_DEL_HTE
|
745 NES_CQP_QP_TYPE_IWARP
| NES_CQP_QP_CONTEXT_VALID
| NES_CQP_QP_IWARP_STATE_RTS
);
746 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
, nesqp
->hwqp
.qp_id
);
747 u64temp
= (u64
)nesqp
->nesqp_context_pbase
;
748 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_QP_WQE_CONTEXT_LOW_IDX
, u64temp
);
750 nes_debug(NES_DBG_PAU
, "Waiting for CQP completion for deleting the quad hash.\n");
752 cqp_request
->cqp_callback_pointer
= qh_chg
;
753 cqp_request
->callback
= 1;
754 cqp_request
->cqp_callback
= nes_chg_qh_handler
;
755 atomic_set(&cqp_request
->refcount
, 1);
756 nes_post_cqp_request(nesdev
, cqp_request
);
763 nes_put_cqp_request(nesdev
, cqp_request
);
769 * This management code deals with any packed and unaligned (pau) fpdu's
770 * that the hardware cannot handle.
772 static void nes_mgt_ce_handler(struct nes_device
*nesdev
, struct nes_hw_nic_cq
*cq
)
774 struct nes_vnic_mgt
*mgtvnic
= container_of(cq
, struct nes_vnic_mgt
, mgt_cq
);
775 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
782 unsigned long context
;
783 struct nes_qp
*nesqp
;
784 struct sk_buff
*rx_skb
;
785 struct nes_rskb_cb
*cb
;
788 cq_size
= cq
->cq_size
;
791 cqe_misc
= le32_to_cpu(cq
->cq_vbase
[head
].cqe_words
[NES_NIC_CQE_MISC_IDX
]);
792 if (!(cqe_misc
& NES_NIC_CQE_VALID
))
796 if (cqe_misc
& NES_NIC_CQE_ACCQP_VALID
) {
797 qp_id
= le32_to_cpu(cq
->cq_vbase
[head
].cqe_words
[NES_NIC_CQE_ACCQP_ID_IDX
]);
799 if (qp_id
< nesadapter
->max_qp
) {
800 context
= (unsigned long)nesadapter
->qp_table
[qp_id
- NES_FIRST_QPN
];
801 nesqp
= (struct nes_qp
*)context
;
806 if (nesqp
->pau_mode
== false) {
807 nesqp
->pau_mode
= true; /* First time for this qp */
808 nesqp
->pau_rcv_nxt
= le32_to_cpu(
809 cq
->cq_vbase
[head
].cqe_words
[NES_NIC_CQE_HASH_RCVNXT
]);
810 skb_queue_head_init(&nesqp
->pau_list
);
811 spin_lock_init(&nesqp
->pau_lock
);
812 atomic_inc(&pau_qps_created
);
813 nes_change_quad_hash(nesdev
, mgtvnic
->nesvnic
, nesqp
);
816 rx_skb
= mgtvnic
->mgt
.rx_skb
[mgtvnic
->mgt
.rq_tail
];
818 skb_put(rx_skb
, cqe_misc
& 0x0000ffff);
819 rx_skb
->protocol
= eth_type_trans(rx_skb
, mgtvnic
->nesvnic
->netdev
);
820 cb
= (struct nes_rskb_cb
*)&rx_skb
->cb
[0];
821 pci_unmap_single(nesdev
->pcidev
, cb
->busaddr
, cb
->maplen
, PCI_DMA_FROMDEVICE
);
823 mgtvnic
->mgt
.rq_tail
++;
824 mgtvnic
->mgt
.rq_tail
&= mgtvnic
->mgt
.rq_size
- 1;
826 nes_add_ref_cm_node(nesqp
->cm_node
);
827 nes_queue_mgt_skbs(rx_skb
, mgtvnic
->nesvnic
, nesqp
);
829 printk(KERN_ERR PFX
"Invalid QP %d for packed/unaligned handling\n", qp_id
);
832 cq
->cq_vbase
[head
].cqe_words
[NES_NIC_CQE_MISC_IDX
] = 0;
834 if (++head
>= cq_size
)
837 if (cqe_count
== 255) {
838 /* Replenish mgt CQ */
839 nes_write32(nesdev
->regs
+ NES_CQE_ALLOC
, cq
->cq_number
| (cqe_count
<< 16));
840 nesdev
->currcq_count
+= cqe_count
;
844 skbs_needed
= atomic_inc_return(&mgtvnic
->rx_skbs_needed
);
845 if (skbs_needed
> (mgtvnic
->mgt
.rq_size
>> 1))
846 nes_replenish_mgt_rq(mgtvnic
);
850 nes_write32(nesdev
->regs
+ NES_CQE_ALLOC
, NES_CQE_ALLOC_NOTIFY_NEXT
|
851 cq
->cq_number
| (cqe_count
<< 16));
852 nes_read32(nesdev
->regs
+ NES_CQE_ALLOC
);
853 nesdev
->currcq_count
+= cqe_count
;
859 int nes_init_mgt_qp(struct nes_device
*nesdev
, struct net_device
*netdev
, struct nes_vnic
*nesvnic
)
861 struct nes_vnic_mgt
*mgtvnic
;
865 struct nes_hw_cqp_wqe
*cqp_wqe
;
868 struct nes_hw_nic_qp_context
*mgt_context
;
870 struct nes_hw_nic_rq_wqe
*mgt_rqe
;
873 struct nes_rskb_cb
*cb
;
876 dma_addr_t mgt_pbase
;
880 /* Allocate space the all mgt QPs once */
881 mgtvnic
= kzalloc(NES_MGT_QP_COUNT
* sizeof(struct nes_vnic_mgt
), GFP_KERNEL
);
885 /* Allocate fragment, RQ, and CQ; Reuse CEQ based on the PCI function */
886 /* We are not sending from this NIC so sq is not allocated */
888 (NES_MGT_WQ_COUNT
* sizeof(struct nes_hw_nic_rq_wqe
)) +
889 (NES_MGT_WQ_COUNT
* sizeof(struct nes_hw_nic_cqe
)) +
890 sizeof(struct nes_hw_nic_qp_context
);
891 mgt_mem_size
= (mgt_mem_size
+ PAGE_SIZE
- 1) & ~(PAGE_SIZE
- 1);
892 mgt_vbase
= pci_alloc_consistent(nesdev
->pcidev
, NES_MGT_QP_COUNT
* mgt_mem_size
, &mgt_pbase
);
895 nes_debug(NES_DBG_INIT
, "Unable to allocate memory for mgt host descriptor rings\n");
899 nesvnic
->mgt_mem_size
= NES_MGT_QP_COUNT
* mgt_mem_size
;
900 nesvnic
->mgt_vbase
= mgt_vbase
;
901 nesvnic
->mgt_pbase
= mgt_pbase
;
903 skb_queue_head_init(&nesvnic
->mgt_skb_list
);
904 init_waitqueue_head(&nesvnic
->mgt_wait_queue
);
905 nesvnic
->mgt_thread
= kthread_run(mgt_thread
, nesvnic
, "nes_mgt_thread");
907 for (i
= 0; i
< NES_MGT_QP_COUNT
; i
++) {
908 mgtvnic
->nesvnic
= nesvnic
;
909 mgtvnic
->mgt
.qp_id
= nesdev
->mac_index
+ NES_MGT_QP_OFFSET
+ i
;
910 memset(mgt_vbase
, 0, mgt_mem_size
);
911 nes_debug(NES_DBG_INIT
, "Allocated mgt QP structures at %p (phys = %016lX), size = %u.\n",
912 mgt_vbase
, (unsigned long)mgt_pbase
, mgt_mem_size
);
914 vmem
= (void *)(((unsigned long)mgt_vbase
+ (256 - 1)) &
915 ~(unsigned long)(256 - 1));
916 pmem
= (dma_addr_t
)(((unsigned long long)mgt_pbase
+ (256 - 1)) &
917 ~(unsigned long long)(256 - 1));
919 spin_lock_init(&mgtvnic
->mgt
.rq_lock
);
922 mgtvnic
->mgt
.rq_vbase
= vmem
;
923 mgtvnic
->mgt
.rq_pbase
= pmem
;
924 mgtvnic
->mgt
.rq_head
= 0;
925 mgtvnic
->mgt
.rq_tail
= 0;
926 mgtvnic
->mgt
.rq_size
= NES_MGT_WQ_COUNT
;
929 vmem
+= (NES_MGT_WQ_COUNT
* sizeof(struct nes_hw_nic_rq_wqe
));
930 pmem
+= (NES_MGT_WQ_COUNT
* sizeof(struct nes_hw_nic_rq_wqe
));
932 mgtvnic
->mgt_cq
.cq_number
= mgtvnic
->mgt
.qp_id
;
933 mgtvnic
->mgt_cq
.cq_vbase
= vmem
;
934 mgtvnic
->mgt_cq
.cq_pbase
= pmem
;
935 mgtvnic
->mgt_cq
.cq_head
= 0;
936 mgtvnic
->mgt_cq
.cq_size
= NES_MGT_WQ_COUNT
;
938 mgtvnic
->mgt_cq
.ce_handler
= nes_mgt_ce_handler
;
940 /* Send CreateCQ request to CQP */
941 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
942 cqp_head
= nesdev
->cqp
.sq_head
;
944 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
945 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
947 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] = cpu_to_le32(
948 NES_CQP_CREATE_CQ
| NES_CQP_CQ_CEQ_VALID
|
949 ((u32
)mgtvnic
->mgt_cq
.cq_size
<< 16));
950 cqp_wqe
->wqe_words
[NES_CQP_WQE_ID_IDX
] = cpu_to_le32(
951 mgtvnic
->mgt_cq
.cq_number
| ((u32
)nesdev
->ceq_index
<< 16));
952 u64temp
= (u64
)mgtvnic
->mgt_cq
.cq_pbase
;
953 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_CQ_WQE_PBL_LOW_IDX
, u64temp
);
954 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX
] = 0;
955 u64temp
= (unsigned long)&mgtvnic
->mgt_cq
;
956 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX
] = cpu_to_le32((u32
)(u64temp
>> 1));
957 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX
] =
958 cpu_to_le32(((u32
)((u64temp
) >> 33)) & 0x7FFFFFFF);
959 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX
] = 0;
961 if (++cqp_head
>= nesdev
->cqp
.sq_size
)
963 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
964 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
966 /* Send CreateQP request to CQP */
967 mgt_context
= (void *)(&mgtvnic
->mgt_cq
.cq_vbase
[mgtvnic
->mgt_cq
.cq_size
]);
968 mgt_context
->context_words
[NES_NIC_CTX_MISC_IDX
] =
969 cpu_to_le32((u32
)NES_MGT_CTX_SIZE
|
970 ((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 12));
971 nes_debug(NES_DBG_INIT
, "RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x%08X, RX_WINDOW_BUFFER_SIZE = 0x%08X\n",
972 nes_read_indexed(nesdev
, NES_IDX_RX_WINDOW_BUFFER_PAGE_TABLE_SIZE
),
973 nes_read_indexed(nesdev
, NES_IDX_RX_WINDOW_BUFFER_SIZE
));
974 if (nes_read_indexed(nesdev
, NES_IDX_RX_WINDOW_BUFFER_SIZE
) != 0)
975 mgt_context
->context_words
[NES_NIC_CTX_MISC_IDX
] |= cpu_to_le32(NES_NIC_BACK_STORE
);
977 u64temp
= (u64
)mgtvnic
->mgt
.rq_pbase
;
978 mgt_context
->context_words
[NES_NIC_CTX_SQ_LOW_IDX
] = cpu_to_le32((u32
)u64temp
);
979 mgt_context
->context_words
[NES_NIC_CTX_SQ_HIGH_IDX
] = cpu_to_le32((u32
)(u64temp
>> 32));
980 u64temp
= (u64
)mgtvnic
->mgt
.rq_pbase
;
981 mgt_context
->context_words
[NES_NIC_CTX_RQ_LOW_IDX
] = cpu_to_le32((u32
)u64temp
);
982 mgt_context
->context_words
[NES_NIC_CTX_RQ_HIGH_IDX
] = cpu_to_le32((u32
)(u64temp
>> 32));
984 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] = cpu_to_le32(NES_CQP_CREATE_QP
|
985 NES_CQP_QP_TYPE_NIC
);
986 cqp_wqe
->wqe_words
[NES_CQP_WQE_ID_IDX
] = cpu_to_le32(mgtvnic
->mgt
.qp_id
);
987 u64temp
= (u64
)mgtvnic
->mgt_cq
.cq_pbase
+
988 (mgtvnic
->mgt_cq
.cq_size
* sizeof(struct nes_hw_nic_cqe
));
989 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_QP_WQE_CONTEXT_LOW_IDX
, u64temp
);
991 if (++cqp_head
>= nesdev
->cqp
.sq_size
)
993 nesdev
->cqp
.sq_head
= cqp_head
;
997 /* Ring doorbell (2 WQEs) */
998 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
, 0x02800000 | nesdev
->cqp
.qp_id
);
1000 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
1001 nes_debug(NES_DBG_INIT
, "Waiting for create MGT QP%u to complete.\n",
1002 mgtvnic
->mgt
.qp_id
);
1004 ret
= wait_event_timeout(nesdev
->cqp
.waitq
, (nesdev
->cqp
.sq_tail
== cqp_head
),
1006 nes_debug(NES_DBG_INIT
, "Create MGT QP%u completed, wait_event_timeout ret = %u.\n",
1007 mgtvnic
->mgt
.qp_id
, ret
);
1009 nes_debug(NES_DBG_INIT
, "MGT QP%u create timeout expired\n", mgtvnic
->mgt
.qp_id
);
1011 pci_free_consistent(nesdev
->pcidev
, nesvnic
->mgt_mem_size
, nesvnic
->mgt_vbase
,
1012 nesvnic
->mgt_pbase
);
1015 nes_destroy_mgt(nesvnic
);
1020 /* Populate the RQ */
1021 for (counter
= 0; counter
< (NES_MGT_WQ_COUNT
- 1); counter
++) {
1022 skb
= dev_alloc_skb(nesvnic
->max_frame_size
);
1024 nes_debug(NES_DBG_INIT
, "%s: out of memory for receive skb\n", netdev
->name
);
1030 pmem
= pci_map_single(nesdev
->pcidev
, skb
->data
,
1031 nesvnic
->max_frame_size
, PCI_DMA_FROMDEVICE
);
1032 cb
= (struct nes_rskb_cb
*)&skb
->cb
[0];
1034 cb
->maplen
= nesvnic
->max_frame_size
;
1036 mgt_rqe
= &mgtvnic
->mgt
.rq_vbase
[counter
];
1037 mgt_rqe
->wqe_words
[NES_NIC_RQ_WQE_LENGTH_1_0_IDX
] = cpu_to_le32((u32
)nesvnic
->max_frame_size
);
1038 mgt_rqe
->wqe_words
[NES_NIC_RQ_WQE_LENGTH_3_2_IDX
] = 0;
1039 mgt_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_LOW_IDX
] = cpu_to_le32((u32
)pmem
);
1040 mgt_rqe
->wqe_words
[NES_NIC_RQ_WQE_FRAG0_HIGH_IDX
] = cpu_to_le32((u32
)((u64
)pmem
>> 32));
1041 mgtvnic
->mgt
.rx_skb
[counter
] = skb
;
1044 timer_setup(&mgtvnic
->rq_wqes_timer
, nes_mgt_rq_wqes_timeout
,
1047 wqe_count
= NES_MGT_WQ_COUNT
- 1;
1048 mgtvnic
->mgt
.rq_head
= wqe_count
;
1051 counter
= min(wqe_count
, ((u32
)255));
1052 wqe_count
-= counter
;
1053 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
, (counter
<< 24) | mgtvnic
->mgt
.qp_id
);
1054 } while (wqe_count
);
1056 nes_write32(nesdev
->regs
+ NES_CQE_ALLOC
, NES_CQE_ALLOC_NOTIFY_NEXT
|
1057 mgtvnic
->mgt_cq
.cq_number
);
1058 nes_read32(nesdev
->regs
+ NES_CQE_ALLOC
);
1060 mgt_vbase
+= mgt_mem_size
;
1061 mgt_pbase
+= mgt_mem_size
;
1062 nesvnic
->mgtvnic
[i
] = mgtvnic
++;
1068 void nes_destroy_mgt(struct nes_vnic
*nesvnic
)
1070 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1071 struct nes_vnic_mgt
*mgtvnic
;
1072 struct nes_vnic_mgt
*first_mgtvnic
;
1073 unsigned long flags
;
1074 struct nes_hw_cqp_wqe
*cqp_wqe
;
1076 struct sk_buff
*rx_skb
;
1080 kthread_stop(nesvnic
->mgt_thread
);
1082 /* Free remaining NIC receive buffers */
1083 first_mgtvnic
= nesvnic
->mgtvnic
[0];
1084 for (i
= 0; i
< NES_MGT_QP_COUNT
; i
++) {
1085 mgtvnic
= nesvnic
->mgtvnic
[i
];
1086 if (mgtvnic
== NULL
)
1089 while (mgtvnic
->mgt
.rq_head
!= mgtvnic
->mgt
.rq_tail
) {
1090 rx_skb
= mgtvnic
->mgt
.rx_skb
[mgtvnic
->mgt
.rq_tail
];
1091 nes_mgt_free_skb(nesdev
, rx_skb
, PCI_DMA_FROMDEVICE
);
1092 mgtvnic
->mgt
.rq_tail
++;
1093 mgtvnic
->mgt
.rq_tail
&= (mgtvnic
->mgt
.rq_size
- 1);
1096 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
1098 /* Destroy NIC QP */
1099 cqp_head
= nesdev
->cqp
.sq_head
;
1100 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1101 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1103 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
,
1104 (NES_CQP_DESTROY_QP
| NES_CQP_QP_TYPE_NIC
));
1105 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
,
1106 mgtvnic
->mgt
.qp_id
);
1108 if (++cqp_head
>= nesdev
->cqp
.sq_size
)
1111 cqp_wqe
= &nesdev
->cqp
.sq_vbase
[cqp_head
];
1113 /* Destroy NIC CQ */
1114 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1115 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
,
1116 (NES_CQP_DESTROY_CQ
| ((u32
)mgtvnic
->mgt_cq
.cq_size
<< 16)));
1117 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
,
1118 (mgtvnic
->mgt_cq
.cq_number
| ((u32
)nesdev
->ceq_index
<< 16)));
1120 if (++cqp_head
>= nesdev
->cqp
.sq_size
)
1123 nesdev
->cqp
.sq_head
= cqp_head
;
1126 /* Ring doorbell (2 WQEs) */
1127 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
, 0x02800000 | nesdev
->cqp
.qp_id
);
1129 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
1130 nes_debug(NES_DBG_SHUTDOWN
, "Waiting for CQP, cqp_head=%u, cqp.sq_head=%u,"
1131 " cqp.sq_tail=%u, cqp.sq_size=%u\n",
1132 cqp_head
, nesdev
->cqp
.sq_head
,
1133 nesdev
->cqp
.sq_tail
, nesdev
->cqp
.sq_size
);
1135 ret
= wait_event_timeout(nesdev
->cqp
.waitq
, (nesdev
->cqp
.sq_tail
== cqp_head
),
1138 nes_debug(NES_DBG_SHUTDOWN
, "Destroy MGT QP returned, wait_event_timeout ret = %u, cqp_head=%u,"
1139 " cqp.sq_head=%u, cqp.sq_tail=%u\n",
1140 ret
, cqp_head
, nesdev
->cqp
.sq_head
, nesdev
->cqp
.sq_tail
);
1142 nes_debug(NES_DBG_SHUTDOWN
, "MGT QP%u destroy timeout expired\n",
1143 mgtvnic
->mgt
.qp_id
);
1145 nesvnic
->mgtvnic
[i
] = NULL
;
1148 if (nesvnic
->mgt_vbase
) {
1149 pci_free_consistent(nesdev
->pcidev
, nesvnic
->mgt_mem_size
, nesvnic
->mgt_vbase
,
1150 nesvnic
->mgt_pbase
);
1151 nesvnic
->mgt_vbase
= NULL
;
1152 nesvnic
->mgt_pbase
= 0;
1155 kfree(first_mgtvnic
);