Lines Matching defs:cm_node
105 static int send_ack(struct nes_cm_node *cm_node, struct sk_buff *skb);
106 static int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb);
113 static void free_retrans_entry(struct nes_cm_node *cm_node);
114 static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph, struct sk_buff *skb, int optionsize, int passive);
122 static void handle_recv_entry(struct nes_cm_node *cm_node, u32 rem_node);
159 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
161 return add_ref_cm_node(cm_node);
164 int nes_rem_ref_cm_node(struct nes_cm_node *cm_node)
166 return rem_ref_cm_node(cm_node->cm_core, cm_node);
172 static struct nes_cm_event *create_event(struct nes_cm_node * cm_node,
177 if (!cm_node->cm_id)
187 event->cm_node = cm_node;
188 event->cm_info.rem_addr = cm_node->rem_addr;
189 event->cm_info.loc_addr = cm_node->loc_addr;
190 event->cm_info.rem_port = cm_node->rem_port;
191 event->cm_info.loc_port = cm_node->loc_port;
192 event->cm_info.cm_id = cm_node->cm_id;
194 nes_debug(NES_DBG_CM, "cm_node=%p Created event=%p, type=%u, "
196 cm_node, event, type, event->cm_info.loc_addr,
208 static int send_mpa_request(struct nes_cm_node *cm_node, struct sk_buff *skb)
221 cm_build_mpa_frame(cm_node, start_buff, &buff_len, NULL, MPA_KEY_REQUEST);
222 form_cm_frame(skb, cm_node, NULL, 0, *start_buff, buff_len, SET_ACK);
224 return schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
229 static int send_mpa_reject(struct nes_cm_node *cm_node)
245 cm_build_mpa_frame(cm_node, start_buff, &buff_len, NULL, MPA_KEY_REPLY);
248 form_cm_frame(skb, cm_node, NULL, 0, *start_buff, buff_len, SET_ACK | SET_FIN);
250 cm_node->state = NES_CM_STATE_FIN_WAIT1;
251 return schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
259 static int parse_mpa(struct nes_cm_node *cm_node, u8 *buffer, u32 *type,
300 if (mpa_frame->rev > cm_node->mpa_frame_rev) {
305 cm_node->mpa_frame_rev = mpa_frame->rev;
308 if (cm_node->state != NES_CM_STATE_MPAREQ_SENT) {
335 cm_node->mpa_frame_size = priv_data_len;
346 cm_node->mpa_frame_size -= IETF_RTR_MSG_SIZE;
360 if (cm_node->state != NES_CM_STATE_MPAREQ_SENT) {
362 if (cm_node->ord_size > ird_size)
363 cm_node->ord_size = ird_size;
366 if (cm_node->ord_size > ird_size)
367 cm_node->ord_size = ird_size;
369 if (cm_node->ird_size < ord_size) {
377 cm_node->send_rdma0_op = SEND_RDMA_READ_ZERO;
379 cm_node->send_rdma0_op = SEND_RDMA_WRITE_ZERO;
390 /* copy entire MPA frame to our cm_node's frame */
391 memcpy(cm_node->mpa_frame_buf, buffer + mpa_hdr_len, cm_node->mpa_frame_size);
404 struct nes_cm_node *cm_node, void *options, u32 optionsize,
437 memcpy(ethh->h_dest, cm_node->rem_mac, ETH_ALEN);
438 memcpy(ethh->h_source, cm_node->loc_mac, ETH_ALEN);
445 iph->id = htons(++cm_node->tcp_cntxt.loc_id);
451 iph->saddr = htonl(cm_node->loc_addr);
452 iph->daddr = htonl(cm_node->rem_addr);
454 tcph->source = htons(cm_node->loc_port);
455 tcph->dest = htons(cm_node->rem_port);
456 tcph->seq = htonl(cm_node->tcp_cntxt.loc_seq_num);
459 cm_node->tcp_cntxt.loc_ack_num = cm_node->tcp_cntxt.rcv_nxt;
460 tcph->ack_seq = htonl(cm_node->tcp_cntxt.loc_ack_num);
467 cm_node->tcp_cntxt.loc_seq_num++;
470 cm_node->tcp_cntxt.loc_seq_num += datasize;
474 cm_node->tcp_cntxt.loc_seq_num++;
482 tcph->window = htons(cm_node->tcp_cntxt.rcv_wnd);
518 static int cm_build_mpa_frame(struct nes_cm_node *cm_node, u8 **start_buff,
523 *start_buff = (pci_mem) ? pci_mem : &cm_node->mpa_frame_buf[0];
525 switch (cm_node->mpa_frame_rev) {
528 *buff_len = sizeof(struct ietf_mpa_v1) + cm_node->mpa_frame_size;
529 build_mpa_v1(cm_node, *start_buff, mpa_key);
532 *buff_len = sizeof(struct ietf_mpa_v2) + cm_node->mpa_frame_size;
533 build_mpa_v2(cm_node, *start_buff, mpa_key);
544 static void build_mpa_v2(struct nes_cm_node *cm_node,
553 build_mpa_v1(cm_node, start_addr, mpa_key);
558 ctrl_ird = (cm_node->ird_size > IETF_NO_IRD_ORD) ?
559 IETF_NO_IRD_ORD : cm_node->ird_size;
560 ctrl_ord = (cm_node->ord_size > IETF_NO_IRD_ORD) ?
561 IETF_NO_IRD_ORD : cm_node->ord_size;
572 switch (cm_node->send_rdma0_op) {
588 static void build_mpa_v1(struct nes_cm_node *cm_node, void *start_addr, u8 mpa_key)
601 mpa_frame->rev = cm_node->mpa_frame_rev;
602 mpa_frame->priv_data_len = htons(cm_node->mpa_frame_size);
605 static void build_rdma0_msg(struct nes_cm_node *cm_node, struct nes_qp **nesqp_addr)
618 switch (cm_node->send_rdma0_op) {
630 if (cm_node->send_rdma0_op != SEND_RDMA_READ_ZERO) {
632 __func__, __LINE__, cm_node->send_rdma0_op);
661 * note - cm_node needs to be protected before calling this. Encase in:
662 * rem_ref_cm_node(cm_core, cm_node);add_ref_cm_node(cm_node);
664 int schedule_nes_timer(struct nes_cm_node *cm_node, struct sk_buff *skb,
669 struct nes_cm_core *cm_core = cm_node->cm_core;
684 new_send->netdev = cm_node->netdev;
690 if (cm_node->recv_entry) {
695 cm_node->recv_entry = new_send;
701 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
702 cm_node->send_entry = new_send;
703 add_ref_cm_node(cm_node);
704 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
707 ret = nes_nic_cm_xmit(new_send->skb, cm_node->netdev);
716 cleanup_retrans_entry(cm_node);
718 rem_ref_cm_node(cm_core, cm_node);
734 static void nes_retrans_expired(struct nes_cm_node *cm_node)
736 struct iw_cm_id *cm_id = cm_node->cm_id;
737 enum nes_cm_node_state state = cm_node->state;
738 cm_node->state = NES_CM_STATE_CLOSED;
743 rem_ref_cm_node(cm_node->cm_core, cm_node);
747 if (cm_node->cm_id)
749 send_reset(cm_node, NULL);
752 add_ref_cm_node(cm_node);
753 send_reset(cm_node, NULL);
754 create_event(cm_node, NES_CM_EVENT_ABORTED);
758 static void handle_recv_entry(struct nes_cm_node *cm_node, u32 rem_node)
760 struct nes_timer_entry *recv_entry = cm_node->recv_entry;
761 struct iw_cm_id *cm_id = cm_node->cm_id;
791 rem_ref_cm_node(cm_node->cm_core, cm_node);
793 if (cm_node->cm_id)
796 cm_node->recv_entry = NULL;
806 struct nes_cm_node *cm_node;
822 cm_node = container_of(list_node, struct nes_cm_node, list);
823 if ((cm_node->recv_entry) || (cm_node->send_entry)) {
824 add_ref_cm_node(cm_node);
825 list_add(&cm_node->timer_entry, &timer_list);
831 cm_node = container_of(list_node, struct nes_cm_node,
833 recv_entry = cm_node->recv_entry;
843 handle_recv_entry(cm_node, 1);
847 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
849 send_entry = cm_node->send_entry;
853 if (cm_node->state != NES_CM_STATE_TSA) {
862 free_retrans_entry(cm_node);
867 if ((cm_node->state == NES_CM_STATE_TSA) ||
868 (cm_node->state == NES_CM_STATE_CLOSED)) {
869 free_retrans_entry(cm_node);
876 free_retrans_entry(cm_node);
879 &cm_node->retrans_list_lock, flags);
880 nes_retrans_expired(cm_node);
881 cm_node->state = NES_CM_STATE_CLOSED;
882 spin_lock_irqsave(&cm_node->retrans_list_lock,
891 "0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
892 "0x%08X\n", send_entry, cm_node, jiffies,
896 cm_node->tcp_cntxt.rem_ack_num);
898 spin_unlock_irqrestore(&cm_node->retrans_list_lock,
900 ret = nes_nic_cm_xmit(send_entry->skb, cm_node->netdev);
901 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
904 "node=%p\n", cm_node);
933 nes_debug(NES_DBG_CM, "cm_node=%p state=%d\n",
934 cm_node, cm_node->state);
935 free_retrans_entry(cm_node);
937 rem_ref_cm_node(cm_node->cm_core,
938 cm_node);
942 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
943 rem_ref_cm_node(cm_node->cm_core, cm_node);
958 static int send_syn(struct nes_cm_node *cm_node, u32 sendack,
971 if (!cm_node)
977 options->as_mss.mss = htons(cm_node->tcp_cntxt.mss);
983 options->as_windowscale.shiftcount = cm_node->tcp_cntxt.rcv_wscale;
1014 form_cm_frame(skb, cm_node, optionsbuffer, optionssize, NULL, 0, flags);
1015 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
1024 static int send_reset(struct nes_cm_node *cm_node, struct sk_buff *skb)
1036 form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, flags);
1037 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 0, 1);
1046 static int send_ack(struct nes_cm_node *cm_node, struct sk_buff *skb)
1058 form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, SET_ACK);
1059 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 0, 0);
1068 static int send_fin(struct nes_cm_node *cm_node, struct sk_buff *skb)
1081 form_cm_frame(skb, cm_node, NULL, 0, NULL, 0, SET_ACK | SET_FIN);
1082 ret = schedule_nes_timer(cm_node, skb, NES_TIMER_TYPE_SEND, 1, 0);
1096 struct nes_cm_node *cm_node;
1101 /* walk list and find cm_node associated with this session ID */
1103 list_for_each_entry(cm_node, hte, list) {
1106 cm_node->loc_addr, cm_node->loc_port,
1108 cm_node->rem_addr, cm_node->rem_port,
1110 if ((cm_node->loc_addr == loc_addr) && (cm_node->loc_port == loc_port) &&
1111 (cm_node->rem_addr == rem_addr) && (cm_node->rem_port == rem_port)) {
1112 add_ref_cm_node(cm_node);
1114 return cm_node;
1133 /* walk list and find cm_node associated with this session ID */
1156 static int add_hte_node(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
1161 if (!cm_node || !cm_core)
1165 cm_node);
1171 list_add_tail(&cm_node->list, hte);
1191 struct nes_cm_node *cm_node = NULL;
1203 cm_node = container_of(list_pos, struct nes_cm_node,
1205 if ((cm_node->listener == listener) &&
1206 (!cm_node->accelerated)) {
1207 add_ref_cm_node(cm_node);
1208 list_add(&cm_node->reset_entry, &reset_list);
1215 cm_node = container_of(list_pos, struct nes_cm_node,
1218 struct nes_cm_node *loopback = cm_node->loopbackpartner;
1220 if (NES_CM_STATE_FIN_WAIT1 <= cm_node->state) {
1221 rem_ref_cm_node(cm_node->cm_core, cm_node);
1224 cleanup_retrans_entry(cm_node);
1225 err = send_reset(cm_node, NULL);
1227 cm_node->state =
1231 old_state = cm_node->state;
1232 cm_node->state = NES_CM_STATE_LISTENER_DESTROYED;
1235 cm_node->cm_core,
1236 cm_node);
1241 event.cm_node = loopback;
1254 cm_node->state = NES_CM_STATE_LISTENER_DESTROYED;
1256 rem_ref_cm_node(cm_node->cm_core,
1257 cm_node);
1313 struct nes_cm_node *cm_node)
1317 cm_node->accelerated = 1;
1319 if (cm_node->accept_pend) {
1320 BUG_ON(!cm_node->listener);
1321 atomic_dec(&cm_node->listener->pend_accepts_cnt);
1322 cm_node->accept_pend = 0;
1323 BUG_ON(atomic_read(&cm_node->listener->pend_accepts_cnt) < 0);
1405 struct nes_cm_node *cm_node;
1412 /* create an hte and cm_node for this instance */
1413 cm_node = kzalloc(sizeof(*cm_node), GFP_ATOMIC);
1414 if (!cm_node)
1418 cm_node->loc_addr = cm_info->loc_addr;
1419 cm_node->rem_addr = cm_info->rem_addr;
1420 cm_node->loc_port = cm_info->loc_port;
1421 cm_node->rem_port = cm_info->rem_port;
1423 cm_node->mpa_frame_rev = mpa_version;
1424 cm_node->send_rdma0_op = SEND_RDMA_READ_ZERO;
1425 cm_node->ird_size = IETF_NO_IRD_ORD;
1426 cm_node->ord_size = IETF_NO_IRD_ORD;
1429 &cm_node->loc_addr, cm_node->loc_port,
1430 &cm_node->rem_addr, cm_node->rem_port);
1431 cm_node->listener = listener;
1432 cm_node->netdev = nesvnic->netdev;
1433 cm_node->cm_id = cm_info->cm_id;
1434 memcpy(cm_node->loc_mac, nesvnic->netdev->dev_addr, ETH_ALEN);
1436 nes_debug(NES_DBG_CM, "listener=%p, cm_id=%p\n", cm_node->listener,
1437 cm_node->cm_id);
1439 spin_lock_init(&cm_node->retrans_list_lock);
1441 cm_node->loopbackpartner = NULL;
1442 atomic_set(&cm_node->ref_count, 1);
1444 cm_node->cm_core = cm_core;
1445 cm_node->tcp_cntxt.loc_id = NES_CM_DEF_LOCAL_ID;
1446 cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
1447 cm_node->tcp_cntxt.rcv_wnd = NES_CM_DEFAULT_RCV_WND_SCALED >>
1450 cm_node->tcp_cntxt.loc_seq_num = htonl(ts.tv_nsec);
1451 cm_node->tcp_cntxt.mss = nesvnic->max_frame_size - sizeof(struct iphdr) -
1453 cm_node->tcp_cntxt.rcv_nxt = 0;
1456 cm_node->conn_type = cm_info->conn_type;
1457 cm_node->apbvt_set = 0;
1458 cm_node->accept_pend = 0;
1460 cm_node->nesvnic = nesvnic;
1465 cm_node->loopbackpartner = NULL;
1468 if (ipv4_is_loopback(htonl(cm_node->rem_addr))) {
1471 oldarpindex = nes_arp_table(nesdev, cm_node->rem_addr, NULL, NES_ARP_RESOLVE);
1475 kfree(cm_node);
1480 memcpy(cm_node->rem_mac, nesadapter->arp_table[arpindex].mac_addr, ETH_ALEN);
1482 cm_node->rem_mac);
1484 add_hte_node(cm_core, cm_node);
1487 return cm_node;
1494 static int add_ref_cm_node(struct nes_cm_node *cm_node)
1496 atomic_inc(&cm_node->ref_count);
1505 struct nes_cm_node *cm_node)
1510 if (!cm_node)
1513 spin_lock_irqsave(&cm_node->cm_core->ht_lock, flags);
1514 if (atomic_dec_return(&cm_node->ref_count)) {
1515 spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
1518 list_del(&cm_node->list);
1520 spin_unlock_irqrestore(&cm_node->cm_core->ht_lock, flags);
1523 if (!cm_node->accelerated && cm_node->accept_pend) {
1524 BUG_ON(!cm_node->listener);
1525 atomic_dec(&cm_node->listener->pend_accepts_cnt);
1526 BUG_ON(atomic_read(&cm_node->listener->pend_accepts_cnt) < 0);
1528 WARN_ON(cm_node->send_entry);
1529 if (cm_node->recv_entry)
1530 handle_recv_entry(cm_node, 0);
1531 if (cm_node->listener) {
1532 mini_cm_dec_refcnt_listen(cm_core, cm_node->listener, 0);
1534 if (cm_node->apbvt_set && cm_node->nesvnic) {
1535 nes_manage_apbvt(cm_node->nesvnic, cm_node->loc_port,
1537 cm_node->nesvnic->nesdev->pcidev->devfn),
1544 nesqp = cm_node->nesqp;
1546 nesqp->cm_node = NULL;
1548 cm_node->nesqp = NULL;
1551 kfree(cm_node);
1558 static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
1585 cm_node->tcp_cntxt.mss)
1586 cm_node->tcp_cntxt.mss = tmp;
1590 cm_node->tcp_cntxt.snd_wscale =
1601 cm_node->tcp_cntxt.mss = NES_CM_DEFAULT_MSS;
1611 static void handle_fin_pkt(struct nes_cm_node *cm_node)
1613 nes_debug(NES_DBG_CM, "Received FIN, cm_node = %p, state = %u. "
1614 "refcnt=%d\n", cm_node, cm_node->state,
1615 atomic_read(&cm_node->ref_count));
1616 switch (cm_node->state) {
1621 cm_node->tcp_cntxt.rcv_nxt++;
1622 cleanup_retrans_entry(cm_node);
1623 cm_node->state = NES_CM_STATE_LAST_ACK;
1624 send_fin(cm_node, NULL);
1627 create_event(cm_node, NES_CM_EVENT_ABORTED);
1628 cm_node->tcp_cntxt.rcv_nxt++;
1629 cleanup_retrans_entry(cm_node);
1630 cm_node->state = NES_CM_STATE_CLOSED;
1631 add_ref_cm_node(cm_node);
1632 send_reset(cm_node, NULL);
1635 cm_node->tcp_cntxt.rcv_nxt++;
1636 cleanup_retrans_entry(cm_node);
1637 cm_node->state = NES_CM_STATE_CLOSING;
1638 send_ack(cm_node, NULL);
1644 cm_node->tcp_cntxt.rcv_nxt++;
1645 cleanup_retrans_entry(cm_node);
1646 cm_node->state = NES_CM_STATE_TIME_WAIT;
1647 send_ack(cm_node, NULL);
1648 schedule_nes_timer(cm_node, NULL, NES_TIMER_TYPE_CLOSE, 1, 0);
1651 cm_node->tcp_cntxt.rcv_nxt++;
1652 cleanup_retrans_entry(cm_node);
1653 cm_node->state = NES_CM_STATE_CLOSED;
1654 rem_ref_cm_node(cm_node->cm_core, cm_node);
1659 cm_node, cm_node->state);
1665 static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1671 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
1672 " refcnt=%d\n", cm_node, cm_node->state,
1673 atomic_read(&cm_node->ref_count));
1674 cleanup_retrans_entry(cm_node);
1675 switch (cm_node->state) {
1678 nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
1679 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1680 cm_node->listener, cm_node->state);
1681 switch (cm_node->mpa_frame_rev) {
1683 cm_node->mpa_frame_rev = IETF_MPA_V1;
1685 cm_node->state = NES_CM_STATE_SYN_SENT;
1686 if (send_syn(cm_node, 0, NULL)) {
1687 active_open_err(cm_node, skb, reset);
1692 active_open_err(cm_node, skb, reset);
1697 atomic_inc(&cm_node->passive_state);
1704 passive_open_err(cm_node, skb, reset);
1707 active_open_err(cm_node, skb, reset);
1715 cm_node->cm_id->rem_ref(cm_node->cm_id);
1717 cm_node->state = NES_CM_STATE_CLOSED;
1718 rem_ref_cm_node(cm_node->cm_core, cm_node);
1728 static void handle_rcv_mpa(struct nes_cm_node *cm_node, struct sk_buff *skb)
1737 ret = parse_mpa(cm_node, dataloc, &res_type, datasize);
1740 if (cm_node->state == NES_CM_STATE_MPAREQ_SENT) {
1742 "cm_node=%p listener=%p state=%d\n", __func__,
1743 __LINE__, cm_node, cm_node->listener,
1744 cm_node->state);
1745 active_open_err(cm_node, skb, 1);
1747 passive_open_err(cm_node, skb, 1);
1752 switch (cm_node->state) {
1759 cm_node->state = NES_CM_STATE_MPAREQ_RCVD;
1761 atomic_set(&cm_node->passive_state,
1765 cleanup_retrans_entry(cm_node);
1768 cm_node->state = NES_CM_STATE_MPAREJ_RCVD;
1771 cm_node->state = NES_CM_STATE_TSA;
1780 create_event(cm_node, type);
1783 static void indicate_pkt_err(struct nes_cm_node *cm_node, struct sk_buff *skb)
1785 switch (cm_node->state) {
1788 nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
1789 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1790 cm_node->listener, cm_node->state);
1791 active_open_err(cm_node, skb, 1);
1795 passive_open_err(cm_node, skb, 1);
1803 static int check_syn(struct nes_cm_node *cm_node, struct tcphdr *tcph,
1808 err = ((ntohl(tcph->ack_seq) == cm_node->tcp_cntxt.loc_seq_num)) ? 0 : 1;
1810 active_open_err(cm_node, skb, 1);
1815 static int check_seq(struct nes_cm_node *cm_node, struct tcphdr *tcph,
1821 u32 loc_seq_num = cm_node->tcp_cntxt.loc_seq_num;
1822 u32 rcv_nxt = cm_node->tcp_cntxt.rcv_nxt;
1827 rcv_wnd = cm_node->tcp_cntxt.rcv_wnd;
1833 nes_debug(NES_DBG_CM, "%s[%u] create abort for cm_node=%p "
1834 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1835 cm_node->listener, cm_node->state);
1836 indicate_pkt_err(cm_node, skb);
1837 nes_debug(NES_DBG_CM, "seq ERROR cm_node =%p seq=0x%08X "
1838 "rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node, seq, rcv_nxt,
1849 static void handle_syn_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1860 switch (cm_node->state) {
1864 active_open_err(cm_node, skb, 1);
1868 if (atomic_read(&cm_node->listener->pend_accepts_cnt) >
1869 cm_node->listener->backlog) {
1873 passive_open_err(cm_node, skb, 0);
1876 ret = handle_tcp_options(cm_node, tcph, skb, optionsize,
1879 passive_open_err(cm_node, skb, 0);
1883 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + 1;
1884 BUG_ON(cm_node->send_entry);
1885 cm_node->accept_pend = 1;
1886 atomic_inc(&cm_node->listener->pend_accepts_cnt);
1888 cm_node->state = NES_CM_STATE_SYN_RCVD;
1889 send_syn(cm_node, 1, skb);
1892 cleanup_retrans_entry(cm_node);
1893 add_ref_cm_node(cm_node);
1894 send_reset(cm_node, skb);
1910 static void handle_synack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1920 switch (cm_node->state) {
1922 cleanup_retrans_entry(cm_node);
1924 if (check_syn(cm_node, tcph, skb))
1926 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
1928 ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 0);
1930 nes_debug(NES_DBG_CM, "cm_node=%p tcp_options failed\n",
1931 cm_node);
1934 cleanup_retrans_entry(cm_node);
1935 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + 1;
1936 send_mpa_request(cm_node, skb);
1937 cm_node->state = NES_CM_STATE_MPAREQ_SENT;
1941 passive_open_err(cm_node, skb, 1);
1944 cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
1945 cleanup_retrans_entry(cm_node);
1946 cm_node->state = NES_CM_STATE_CLOSED;
1947 send_reset(cm_node, skb);
1950 cm_node->tcp_cntxt.loc_seq_num = ntohl(tcph->ack_seq);
1951 cleanup_retrans_entry(cm_node);
1952 add_ref_cm_node(cm_node);
1953 send_reset(cm_node, skb);
1969 static int handle_ack_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1979 if (check_seq(cm_node, tcph, skb))
1985 switch (cm_node->state) {
1988 cleanup_retrans_entry(cm_node);
1989 ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 1);
1992 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
1993 cm_node->state = NES_CM_STATE_ESTABLISHED;
1995 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
1996 handle_rcv_mpa(cm_node, skb);
2003 cleanup_retrans_entry(cm_node);
2005 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
2006 handle_rcv_mpa(cm_node, skb);
2012 cm_node->tcp_cntxt.rem_ack_num = ntohl(tcph->ack_seq);
2014 cm_node->tcp_cntxt.rcv_nxt = inc_sequence + datasize;
2015 handle_rcv_mpa(cm_node, skb);
2021 cleanup_retrans_entry(cm_node);
2022 cm_node->state = NES_CM_STATE_CLOSED;
2023 send_reset(cm_node, skb);
2026 cleanup_retrans_entry(cm_node);
2027 add_ref_cm_node(cm_node);
2028 send_reset(cm_node, skb);
2032 cleanup_retrans_entry(cm_node);
2033 cm_node->state = NES_CM_STATE_CLOSED;
2034 cm_node->cm_id->rem_ref(cm_node->cm_id);
2035 rem_ref_cm_node(cm_node->cm_core, cm_node);
2039 cleanup_retrans_entry(cm_node);
2041 cm_node->state = NES_CM_STATE_FIN_WAIT2;
2049 cleanup_retrans_entry(cm_node);
2058 static int handle_tcp_options(struct nes_cm_node *cm_node, struct tcphdr *tcph,
2064 if (process_options(cm_node, optionsloc, optionsize,
2067 __func__, cm_node);
2069 passive_open_err(cm_node, skb, 1);
2071 active_open_err(cm_node, skb, 1);
2076 cm_node->tcp_cntxt.snd_wnd = ntohs(tcph->window) <<
2077 cm_node->tcp_cntxt.snd_wscale;
2079 if (cm_node->tcp_cntxt.snd_wnd > cm_node->tcp_cntxt.max_snd_wnd)
2080 cm_node->tcp_cntxt.max_snd_wnd = cm_node->tcp_cntxt.snd_wnd;
2088 static void active_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
2091 cleanup_retrans_entry(cm_node);
2093 nes_debug(NES_DBG_CM, "ERROR active err called for cm_node=%p, "
2094 "state=%d\n", cm_node, cm_node->state);
2095 add_ref_cm_node(cm_node);
2096 send_reset(cm_node, skb);
2101 cm_node->state = NES_CM_STATE_CLOSED;
2102 create_event(cm_node, NES_CM_EVENT_ABORTED);
2107 * remove the cm_node.
2109 static void passive_open_err(struct nes_cm_node *cm_node, struct sk_buff *skb,
2112 cleanup_retrans_entry(cm_node);
2113 cm_node->state = NES_CM_STATE_CLOSED;
2116 "cm_node=%p state =%d\n", cm_node, cm_node->state);
2117 send_reset(cm_node, skb);
2120 rem_ref_cm_node(cm_node->cm_core, cm_node);
2128 static void free_retrans_entry(struct nes_cm_node *cm_node)
2132 send_entry = cm_node->send_entry;
2134 cm_node->send_entry = NULL;
2137 rem_ref_cm_node(cm_node->cm_core, cm_node);
2141 static void cleanup_retrans_entry(struct nes_cm_node *cm_node)
2145 spin_lock_irqsave(&cm_node->retrans_list_lock, flags);
2146 free_retrans_entry(cm_node);
2147 spin_unlock_irqrestore(&cm_node->retrans_list_lock, flags);
2154 static void process_packet(struct nes_cm_node *cm_node, struct sk_buff *skb,
2164 nes_debug(NES_DBG_CM, "process_packet: cm_node=%p state =%d syn=%d "
2165 "ack=%d rst=%d fin=%d\n", cm_node, cm_node->state, tcph->syn,
2182 handle_syn_pkt(cm_node, skb, tcph);
2185 handle_synack_pkt(cm_node, skb, tcph);
2188 ret = handle_ack_pkt(cm_node, skb, tcph);
2190 handle_fin_pkt(cm_node);
2193 handle_rst_pkt(cm_node, skb, tcph);
2196 if ((fin_set) && (!check_seq(cm_node, tcph, skb)))
2197 handle_fin_pkt(cm_node);
2279 struct nes_cm_node *cm_node;
2286 cm_node = make_cm_node(cm_core, nesvnic, cm_info, NULL);
2287 if (!cm_node)
2291 cm_node->tcp_cntxt.client = 1;
2292 cm_node->tcp_cntxt.rcv_wscale = NES_CM_DEFAULT_RCV_WND_SCALE;
2296 ntohl(nesvnic->local_ipaddr), cm_node->rem_port,
2299 create_event(cm_node, NES_CM_EVENT_ABORTED);
2308 rem_ref_cm_node(cm_node->cm_core, cm_node);
2312 loopbackremotenode->loopbackpartner = cm_node;
2315 cm_node->loopbackpartner = loopbackremotenode;
2322 cm_node->state = NES_CM_STATE_TSA;
2323 cm_node->tcp_cntxt.rcv_nxt =
2326 cm_node->tcp_cntxt.loc_seq_num;
2327 cm_node->tcp_cntxt.max_snd_wnd =
2330 cm_node->tcp_cntxt.rcv_wnd;
2331 cm_node->tcp_cntxt.snd_wnd =
2334 cm_node->tcp_cntxt.rcv_wnd;
2335 cm_node->tcp_cntxt.snd_wscale =
2338 cm_node->tcp_cntxt.rcv_wscale;
2342 return cm_node;
2345 start_buff = &cm_node->mpa_frame_buf[0] + sizeof(struct ietf_mpa_v2);
2346 cm_node->mpa_frame_size = private_data_len;
2351 cm_node->state = NES_CM_STATE_SYN_SENT;
2352 ret = send_syn(cm_node, 0, NULL);
2355 /* error in sending the syn free up the cm_node struct */
2357 "addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
2358 cm_node->rem_addr, cm_node->rem_port, cm_node,
2359 cm_node->cm_id);
2360 rem_ref_cm_node(cm_node->cm_core, cm_node);
2361 cm_node = NULL;
2364 if (cm_node) {
2366 "port=0x%04x, cm_node=%p, cm_id = %p.\n",
2367 cm_node->rem_addr, cm_node->rem_port, cm_node,
2368 cm_node->cm_id);
2371 return cm_node;
2379 static int mini_cm_accept(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
2388 static int mini_cm_reject(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
2394 struct iw_cm_id *cm_id = cm_node->cm_id;
2395 struct nes_cm_node *loopback = cm_node->loopbackpartner;
2397 nes_debug(NES_DBG_CM, "%s cm_node=%p type=%d state=%d\n",
2398 __func__, cm_node, cm_node->tcp_cntxt.client, cm_node->state);
2400 if (cm_node->tcp_cntxt.client)
2402 cleanup_retrans_entry(cm_node);
2405 passive_state = atomic_add_return(1, &cm_node->passive_state);
2407 cm_node->state = NES_CM_STATE_CLOSED;
2408 rem_ref_cm_node(cm_core, cm_node);
2410 if (cm_node->state == NES_CM_STATE_LISTENER_DESTROYED) {
2411 rem_ref_cm_node(cm_core, cm_node);
2413 ret = send_mpa_reject(cm_node);
2415 cm_node->state = NES_CM_STATE_CLOSED;
2416 err = send_reset(cm_node, NULL);
2425 cm_node->cm_id = NULL;
2426 if (cm_node->state == NES_CM_STATE_LISTENER_DESTROYED) {
2427 rem_ref_cm_node(cm_core, cm_node);
2430 event.cm_node = loopback;
2437 rem_ref_cm_node(cm_core, cm_node);
2453 static int mini_cm_close(struct nes_cm_core *cm_core, struct nes_cm_node *cm_node)
2457 if (!cm_core || !cm_node)
2460 switch (cm_node->state) {
2468 cleanup_retrans_entry(cm_node);
2469 send_reset(cm_node, NULL);
2472 cm_node->state = NES_CM_STATE_LAST_ACK;
2473 send_fin(cm_node, NULL);
2483 cleanup_retrans_entry(cm_node);
2484 send_reset(cm_node, NULL);
2491 ret = rem_ref_cm_node(cm_core, cm_node);
2494 if (cm_node->send_entry)
2496 "send_entry=%p\n", cm_node->send_entry);
2497 ret = rem_ref_cm_node(cm_core, cm_node);
2511 struct nes_cm_node *cm_node = NULL;
2539 cm_node = find_node(cm_core,
2543 if (!cm_node) {
2562 cm_node = make_cm_node(cm_core, nesvnic, &nfo,
2564 if (!cm_node) {
2573 cm_node->state = NES_CM_STATE_LISTENING;
2576 rem_ref_cm_node(cm_core, cm_node);
2580 add_ref_cm_node(cm_node);
2581 } else if (cm_node->state == NES_CM_STATE_TSA) {
2582 if (cm_node->nesqp->pau_mode)
2583 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
2585 rem_ref_cm_node(cm_core, cm_node);
2594 process_packet(cm_node, skb, cm_core);
2595 rem_ref_cm_node(cm_core, cm_node);
2704 static int nes_cm_init_tsa_conn(struct nes_qp *nesqp, struct nes_cm_node *cm_node)
2715 if (cm_node->tcp_cntxt.snd_wscale || cm_node->tcp_cntxt.rcv_wscale)
2720 nesqp->nesqp_context->mss |= cpu_to_le32(((u32)cm_node->tcp_cntxt.mss) << 16);
2726 (cm_node->tcp_cntxt.snd_wscale << NES_QPCONTEXT_PDWSCALE_SND_WSCALE_SHIFT) &
2730 (cm_node->tcp_cntxt.rcv_wscale << NES_QPCONTEXT_PDWSCALE_RCV_WSCALE_SHIFT) &
2736 nesqp->nesqp_context->snd_nxt = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2737 nesqp->nesqp_context->snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.snd_wnd);
2738 nesqp->nesqp_context->rcv_nxt = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
2739 nesqp->nesqp_context->rcv_wnd = cpu_to_le32(cm_node->tcp_cntxt.rcv_wnd <<
2740 cm_node->tcp_cntxt.rcv_wscale);
2741 nesqp->nesqp_context->snd_max = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2742 nesqp->nesqp_context->snd_una = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2746 nesqp->nesqp_context->cwnd = cpu_to_le32(2 * cm_node->tcp_cntxt.mss);
2747 nesqp->nesqp_context->snd_wl1 = cpu_to_le32(cm_node->tcp_cntxt.rcv_nxt);
2748 nesqp->nesqp_context->snd_wl2 = cpu_to_le32(cm_node->tcp_cntxt.loc_seq_num);
2749 nesqp->nesqp_context->max_snd_wnd = cpu_to_le32(cm_node->tcp_cntxt.max_snd_wnd);
2755 cm_node->tcp_cntxt.mss, le32_to_cpu(nesqp->nesqp_context->pd_index_wscale),
2762 nes_debug(NES_DBG_CM, "Change cm_node state to TSA\n");
2763 cm_node->state = NES_CM_STATE_TSA;
2976 if (nesqp->cm_node) {
2979 g_cm_core->api->close(g_cm_core, nesqp->cm_node);
2996 struct nes_cm_node *cm_node;
3027 cm_node = (struct nes_cm_node *)cm_id->provider_data;
3028 nes_debug(NES_DBG_CM, "nes_accept: cm_node= %p nesvnic=%p, netdev=%p,"
3029 "%s\n", cm_node, nesvnic, nesvnic->netdev,
3032 if (NES_CM_STATE_LISTENER_DESTROYED == cm_node->state) {
3033 if (cm_node->loopbackpartner)
3034 rem_ref_cm_node(cm_node->cm_core, cm_node->loopbackpartner);
3035 rem_ref_cm_node(cm_node->cm_core, cm_node);
3039 passive_state = atomic_add_return(1, &cm_node->passive_state);
3041 rem_ref_cm_node(cm_node->cm_core, cm_node);
3046 nesqp->cm_node = (void *)cm_node;
3047 cm_node->nesqp = nesqp;
3049 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
3050 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
3068 if (cm_node->mpa_frame_rev == IETF_MPA_V1)
3074 cm_build_mpa_frame(cm_node, start_buff, &buff_len, nesqp->ietf_frame, MPA_KEY_REPLY);
3094 "for lSMM for cm_node = %p \n",
3095 cm_node);
3138 cm_node->cm_id = cm_id;
3140 /* nesqp->cm_node = (void *)cm_id->provider_data; */
3144 if (cm_node->state == NES_CM_STATE_TSA)
3145 nes_debug(NES_DBG_CM, "Already state = TSA for cm_node=%p\n",
3146 cm_node);
3148 nes_cm_init_tsa_conn(nesqp, cm_node);
3200 cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
3227 if (cm_node->loopbackpartner) {
3228 cm_node->loopbackpartner->mpa_frame_size =
3230 /* copy entire MPA frame to our cm_node's frame */
3231 memcpy(cm_node->loopbackpartner->mpa_frame_buf,
3233 create_event(cm_node->loopbackpartner, NES_CM_EVENT_CONNECTED);
3248 struct nes_cm_node *cm_node;
3254 cm_node = (struct nes_cm_node *)cm_id->provider_data;
3255 loopback = cm_node->loopbackpartner;
3256 cm_core = cm_node->cm_core;
3257 cm_node->cm_id = cm_id;
3267 start_buff = &cm_node->mpa_frame_buf[0] + sizeof(struct ietf_mpa_v2);
3268 cm_node->mpa_frame_size = pdata_len;
3271 return cm_core->api->reject(cm_core, cm_node);
3285 struct nes_cm_node *cm_node;
3345 cm_node = g_cm_core->api->connect(g_cm_core, nesvnic,
3348 if (!cm_node) {
3358 cm_node->apbvt_set = apbvt_set;
3359 nesqp->cm_node = cm_node;
3360 cm_node->nesqp = nesqp;
3373 struct nes_cm_listener *cm_node;
3399 cm_node = g_cm_core->api->listen(g_cm_core, nesvnic, &cm_info);
3400 if (!cm_node) {
3406 cm_id->provider_data = cm_node;
3408 if (!cm_node->reused_node) {
3416 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
3423 cm_id->provider_data = (void *)cm_node;
3500 struct nes_cm_node *cm_node;
3510 cm_node = event->cm_node;
3511 cm_id = cm_node->cm_id;
3512 nes_debug(NES_DBG_CM, "cm_event_connected - %p - cm_id = %p\n", cm_node, cm_id);
3529 nes_cm_init_tsa_conn(nesqp, cm_node);
3560 build_rdma0_msg(cm_node, &nesqp);
3585 nesqp->ietf_frame = &cm_node->mpa_frame;
3586 nesqp->private_data_len = (u8)cm_node->mpa_frame_size;
3587 cm_node->cm_core->api->accelerated(cm_node->cm_core, cm_node);
3597 cm_event.private_data = (void *)event->cm_node->mpa_frame_buf;
3598 cm_event.private_data_len = (u8)event->cm_node->mpa_frame_size;
3599 cm_event.ird = cm_node->ird_size;
3600 cm_event.ord = cm_node->ord_size;
3630 if (!event->cm_node)
3633 cm_id = event->cm_node->cm_id;
3637 nes_debug(NES_DBG_CM, "cm_node=%p, cm_id=%p\n", event->cm_node, cm_id);
3666 rem_ref_cm_node(event->cm_node->cm_core, event->cm_node);
3682 if (!event->cm_node)
3685 if (!event->cm_node->cm_id)
3688 cm_id = event->cm_node->cm_id;
3690 nes_debug(NES_DBG_CM, "%p - cm_id = %p\n", event->cm_node, cm_id);
3715 nes_debug(NES_DBG_CM, "NODE %p Generating CLOSE\n", event->cm_node);
3736 struct nes_cm_node *cm_node;
3738 cm_node = event->cm_node;
3739 if (!cm_node)
3741 cm_id = cm_node->cm_id;
3744 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3745 cm_node, cm_id, jiffies);
3749 cm_event.provider_data = (void *)cm_node;
3758 cm_event.private_data = cm_node->mpa_frame_buf;
3759 cm_event.private_data_len = (u8)cm_node->mpa_frame_size;
3760 cm_event.ird = cm_node->ird_size;
3761 cm_event.ord = cm_node->ord_size;
3775 struct nes_cm_node *cm_node;
3778 cm_node = event->cm_node;
3779 if (!cm_node)
3781 cm_id = cm_node->cm_id;
3784 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
3785 cm_node, cm_id, jiffies);
3799 cm_event.private_data = cm_node->mpa_frame_buf;
3800 cm_event.private_data_len = (u8)cm_node->mpa_frame_size;
3824 atomic_inc(&event->cm_node->cm_core->events_posted);
3825 add_ref_cm_node(event->cm_node);
3828 nes_debug(NES_DBG_CM, "cm_node=%p queue_work, event=%p\n",
3829 event->cm_node, event);
3831 queue_work(event->cm_node->cm_core->event_wq, &event->event_work);
3849 if ((!event) || (!event->cm_node) || (!event->cm_node->cm_core))
3852 cm_core = event->cm_node->cm_core;
3859 nes_debug(NES_DBG_CM, "cm_node=%p CM Event: MPA REQUEST\n",
3860 event->cm_node);
3863 nes_debug(NES_DBG_CM, "cm_node = %p CM Event: RESET\n",
3864 event->cm_node);
3868 if ((!event->cm_node->cm_id) ||
3869 (event->cm_node->state != NES_CM_STATE_TSA))
3875 if ((!event->cm_node->cm_id) ||
3876 (event->cm_node->state == NES_CM_STATE_TSA))
3883 if ((!event->cm_node->cm_id) ||
3884 (event->cm_node->state == NES_CM_STATE_TSA))
3899 rem_ref_cm_node(cm_core, event->cm_node);