38 #include <linux/tcp.h>
46 static void nes_replenish_mgt_rq(
struct nes_vnic_mgt *mgtvnic)
55 u32 rx_wqes_posted = 0;
57 nesmgt = &mgtvnic->
mgt;
58 nesdev = mgtvnic->
nesvnic->nesdev;
64 spin_unlock_irqrestore(&nesmgt->
rq_lock, flags);
68 spin_unlock_irqrestore(&nesmgt->
rq_lock, flags);
73 spin_unlock_irqrestore(&nesmgt->
rq_lock, flags);
75 skb = dev_alloc_skb(mgtvnic->
nesvnic->max_frame_size);
79 bus_address = pci_map_single(nesdev->
pcidev,
98 if (++rx_wqes_posted == 255) {
107 spin_unlock_irqrestore(&nesmgt->
rq_lock, flags);
111 spin_unlock_irqrestore(&nesmgt->
rq_lock, flags);
125 static void nes_mgt_rq_wqes_timeout(
unsigned long parm)
131 nes_replenish_mgt_rq(mgtvnic);
157 for (i = 0; i < fpdu_info->
frag_cnt; i++) {
158 skb = fpdu_info->
frags[
i].skb;
159 if (fpdu_info->
frags[i].cmplt) {
178 struct tcphdr *tcph = (
struct tcphdr *)(((
char *)iph) + (4 * iph->ihl));
182 *fin_rcvd = tcph->fin;
183 *rst_rcvd = tcph->rst;
206 if (skb_queue_empty(&nesqp->
pau_list))
213 seq = nes_get_seq(skb, ack, wnd, fin_rcvd, rst_rcvd);
214 if (seq == nextseq) {
215 if (skb->
len || processacks)
217 }
else if (
after(seq, nextseq)) {
246 struct pau_fpdu_info *fpdu_info =
NULL;
261 *pau_fpdu_info =
NULL;
264 skb = nes_get_next_skb(nesdev, nesqp,
NULL, nesqp->
pau_rcv_nxt, &ack, &wnd, &fin_rcvd, &rst_rcvd);
266 spin_unlock_irqrestore(&nesqp->
pau_lock, flags);
272 fpdu_len = (fpdu_len + 3) & 0xfffffffc;
277 memset(&frags, 0,
sizeof frags);
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);
294 spin_unlock_irqrestore(&nesqp->
pau_lock, flags);
296 }
else if (rst_rcvd) {
298 for (; i >= 0; i--) {
303 frags[0].physaddr = cb->
busaddr;
305 frags[0].frag_len = skb->
len;
307 frags[0].cmplt =
true;
316 frags[0].physaddr = cb->
busaddr;
317 frags[0].frag_len = 0;
319 frags[0].cmplt =
true;
323 spin_unlock_irqrestore(&nesqp->
pau_lock, flags);
326 fpdu_info = kzalloc(
sizeof(*fpdu_info),
GFP_ATOMIC);
327 if (fpdu_info ==
NULL) {
342 tcph = (
struct tcphdr *)(((
char *)iph) + (4 * iph->ihl));
343 fpdu_info->
hdr_len = (((
unsigned char *)tcph) + 4 * (tcph->doff)) - cb->
data_start;
347 if (frags[0].cmplt) {
362 tcph = (
struct tcphdr *)(((
char *)iph) + (4 * iph->ihl));
376 fpdu_info->
nesqp = nesqp;
377 *pau_fpdu_info = fpdu_info;
380 for (i = 0; i < frag_cnt; i++) {
382 skb_pull(frags[i].skb, frags[i].frag_len);
384 if (frags[i].skb->len == 0) {
388 spin_unlock_irqrestore(&nesqp->
pau_lock, flags);
392 tcph = (
struct tcphdr *)(((
char *)iph) + (4 * iph->ihl));
411 static int forward_fpdus(
struct nes_vnic *nesvnic,
struct nes_qp *nesqp)
414 struct pau_fpdu_info *fpdu_info;
422 rc = get_fpdu_info(nesdev, nesqp, &fpdu_info);
423 if (fpdu_info ==
NULL)
427 cqp_wqe = &cqp_request->
cqp_wqe;
428 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
433 u32tmp = fpdu_info->
hdr_len << 16;
438 u32tmp = (fpdu_info->
frags[1].frag_len << 16) | fpdu_info->
frags[0].frag_len;
442 u32tmp = (fpdu_info->
frags[3].frag_len << 16) | fpdu_info->
frags[2].frag_len;
483 static void process_fpdus(
struct nes_vnic *nesvnic,
struct nes_qp *nesqp)
490 forward_fpdus(nesvnic, nesqp);
500 spin_unlock_irqrestore(&nesqp->
pau_lock, flags);
513 unsigned char *tcph_end;
518 bool process_it =
false;
523 tcph = (
struct tcphdr *)(((
char *)iph) + (4 * iph->ihl));
525 tcph_end = (((
char *)tcph) + (4 * tcph->doff));
539 if (!between(seqnum, rcv_nxt, (rcv_nxt + rcv_wnd))) {
553 if (skb_queue_len(&nesqp->
pau_list) == 0) {
561 tmpskb = tmpskb->
next;
567 spin_unlock_irqrestore(&nesqp->
pau_lock, flags);
570 process_fpdus(nesvnic, nesqp);
578 static int mgt_thread(
void *
context)
593 queue_fpdus(skb, nesvnic, cb->
nesqp);
629 while (skb_queue_len(&nesqp->
pau_list)) {
634 spin_unlock_irqrestore(&nesqp->
pau_lock, flags);
649 nesqp = qh_chg->
nesqp;
663 if (new_request ==
NULL) {
669 memset(&nes_quad, 0,
sizeof(nes_quad));
670 nes_quad.DstIpAdrIndex =
677 crc_value = get_crc_value(&nes_quad);
687 cqp_wqe = &new_request->
cqp_wqe;
688 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
717 static int nes_change_quad_hash(
struct nes_device *nesdev,
727 if (cqp_request ==
NULL) {
734 if (qh_chg ==
NULL) {
741 qh_chg->
nesqp = nesqp;
744 cqp_wqe = &cqp_request->
cqp_wqe;
745 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
802 if (qp_id < nesadapter->
max_qp) {
813 skb_queue_head_init(&nesqp->
pau_list);
816 nes_change_quad_hash(nesdev, mgtvnic->
nesvnic, nesqp);
819 rx_skb = mgtvnic->
mgt.rx_skb[mgtvnic->
mgt.rq_tail];
821 skb_put(rx_skb, cqe_misc & 0x0000ffff);
826 mgtvnic->
mgt.rq_tail++;
827 mgtvnic->
mgt.rq_tail &= mgtvnic->
mgt.rq_size - 1;
837 if (++head >= cq_size)
840 if (cqe_count == 255) {
848 if (skbs_needed > (mgtvnic->
mgt.rq_size >> 1))
849 nes_replenish_mgt_rq(mgtvnic);
885 if (mgtvnic ==
NULL) {
895 sizeof(struct nes_hw_nic_qp_context);
915 memset(mgt_vbase, 0, mgt_mem_size);
917 mgt_vbase, (
unsigned long)mgt_pbase, mgt_mem_size);
919 vmem = (
void *)(((
unsigned long)mgt_vbase + (256 - 1)) &
920 ~(
unsigned long)(256 - 1));
921 pmem = (
dma_addr_t)(((
unsigned long long)mgt_pbase + (256 - 1)) &
922 ~(
unsigned long long)(256 - 1));
927 mgtvnic->
mgt.rq_vbase = vmem;
928 mgtvnic->
mgt.rq_pbase = pmem;
929 mgtvnic->
mgt.rq_head = 0;
930 mgtvnic->
mgt.rq_tail = 0;
937 mgtvnic->
mgt_cq.cq_number = mgtvnic->
mgt.qp_id;
938 mgtvnic->
mgt_cq.cq_vbase = vmem;
939 mgtvnic->
mgt_cq.cq_pbase = pmem;
940 mgtvnic->
mgt_cq.cq_head = 0;
943 mgtvnic->
mgt_cq.ce_handler = nes_mgt_ce_handler;
947 cqp_head = nesdev->
cqp.sq_head;
949 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
950 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
966 if (++cqp_head >= nesdev->
cqp.sq_size)
968 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
969 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
972 mgt_context = (
void *)(&mgtvnic->
mgt_cq.cq_vbase[mgtvnic->
mgt_cq.cq_size]);
976 nes_debug(
NES_DBG_INIT,
"RX_WINDOW_BUFFER_PAGE_TABLE_SIZE = 0x%08X, RX_WINDOW_BUFFER_SIZE = 0x%08X\n",
982 u64temp = (
u64)mgtvnic->
mgt.rq_pbase;
985 u64temp = (
u64)mgtvnic->
mgt.rq_pbase;
992 u64temp = (
u64)mgtvnic->
mgt_cq.cq_pbase +
996 if (++cqp_head >= nesdev->
cqp.sq_size)
998 nesdev->
cqp.sq_head = cqp_head;
1005 spin_unlock_irqrestore(&nesdev->
cqp.lock, flags);
1007 mgtvnic->
mgt.qp_id);
1012 mgtvnic->
mgt.qp_id, ret);
1026 for (counter = 0; counter < (NES_MGT_WQ_COUNT - 1); counter++) {
1035 pmem = pci_map_single(nesdev->
pcidev, skb->
data,
1041 mgt_rqe = &mgtvnic->
mgt.rq_vbase[counter];
1053 wqe_count = NES_MGT_WQ_COUNT - 1;
1057 counter =
min(wqe_count, ((
u32)255));
1060 }
while (wqe_count);
1063 mgtvnic->
mgt_cq.cq_number);
1066 mgt_vbase += mgt_mem_size;
1067 mgt_pbase += mgt_mem_size;
1079 unsigned long flags;
1089 first_mgtvnic = nesvnic->
mgtvnic[0];
1092 if (mgtvnic ==
NULL)
1095 while (mgtvnic->
mgt.rq_head != mgtvnic->
mgt.rq_tail) {
1096 rx_skb = mgtvnic->
mgt.rx_skb[mgtvnic->
mgt.rq_tail];
1098 mgtvnic->
mgt.rq_tail++;
1099 mgtvnic->
mgt.rq_tail &= (mgtvnic->
mgt.rq_size - 1);
1105 cqp_head = nesdev->
cqp.sq_head;
1106 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1107 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1112 mgtvnic->
mgt.qp_id);
1114 if (++cqp_head >= nesdev->
cqp.sq_size)
1117 cqp_wqe = &nesdev->
cqp.sq_vbase[cqp_head];
1120 nes_fill_init_cqp_wqe(cqp_wqe, nesdev);
1126 if (++cqp_head >= nesdev->
cqp.sq_size)
1129 nesdev->
cqp.sq_head = cqp_head;
1135 spin_unlock_irqrestore(&nesdev->
cqp.lock, flags);
1137 " cqp.sq_tail=%u, cqp.sq_size=%u\n",
1138 cqp_head, nesdev->
cqp.sq_head,
1139 nesdev->
cqp.sq_tail, nesdev->
cqp.sq_size);
1145 " cqp.sq_head=%u, cqp.sq_tail=%u\n",
1146 ret, cqp_head, nesdev->
cqp.sq_head, nesdev->
cqp.sq_tail);
1149 mgtvnic->
mgt.qp_id);
1161 kfree(first_mgtvnic);