35 #define TCPOPT_TIMESTAMP 8
40 #include <linux/tcp.h>
42 #include <linux/if_arp.h>
43 #include <linux/if_vlan.h>
45 #include <linux/net.h>
46 #include <linux/types.h>
48 #include <linux/time.h>
51 #include <linux/netdevice.h>
52 #include <linux/random.h>
53 #include <linux/list.h>
56 #include <linux/slab.h>
88 static int mini_cm_dealloc_core(
struct nes_cm_core *);
96 static int nes_cm_disconn_true(
struct nes_qp *);
98 static int nes_disconnect(
struct nes_qp *
nesqp,
int abrupt);
111 static void cleanup_retrans_entry(
struct nes_cm_node *);
113 static void free_retrans_entry(
struct nes_cm_node *cm_node);
118 static void cm_event_connect_error(
struct nes_cm_event *);
122 static void handle_recv_entry(
struct nes_cm_node *cm_node,
u32 rem_node);
144 mini_cm_dealloc_core,
161 return add_ref_cm_node(cm_node);
166 return rem_ref_cm_node(cm_node->
cm_core, 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;
195 "dst_addr=%08x[%x], src_addr=%08x[%x]\n",
196 cm_node, event, type, event->
cm_info.loc_addr,
200 nes_cm_post_event(event);
212 u8 **start_buff = &start_ptr;
222 form_cm_frame(skb, cm_node,
NULL, 0, *start_buff, buff_len,
SET_ACK);
229 static int send_mpa_reject(
struct nes_cm_node *cm_node)
234 u8 **start_buff = &start_ptr;
284 " Data field exceeds 512 octets\n");
294 " is not supported\n");
302 " can not be interoperated\n");
321 if (priv_data_len + mpa_hdr_len != len) {
323 " complete (%x + %x != %x)\n",
324 priv_data_len, mpa_hdr_len, len);
330 " (%x + %x != %x)\n",
331 priv_data_len, mpa_hdr_len, len);
337 switch (mpa_frame->
rev) {
347 rtr_msg = &mpa_v2_frame->
rtr_msg;
403 static void form_cm_frame(
struct sk_buff *skb,
411 u16 packetsize =
sizeof(*iph);
413 packetsize +=
sizeof(*tcph);
414 packetsize += optionsize + datasize;
421 ethh = (
struct ethhdr *)buf;
424 iph = (
struct iphdr *)buf;
426 tcph = (
struct tcphdr *)buf;
427 skb_reset_mac_header(skb);
428 skb_set_network_header(skb,
ETH_HLEN);
429 skb_set_transport_header(skb,
ETH_HLEN +
sizeof(*iph));
430 buf +=
sizeof(*tcph);
472 cm_node->
tcp_cntxt.loc_seq_num += datasize;
483 tcph->doff = (
u16)((
sizeof(*tcph) + optionsize + 3) >> 2);
487 memcpy(buf, options, optionsize);
490 memcpy(buf, data, datasize);
492 skb_shinfo(skb)->nr_frags = 0;
520 static int cm_build_mpa_frame(
struct nes_cm_node *cm_node,
u8 **start_buff,
521 u16 *buff_len,
u8 *pci_mem,
u8 mpa_key)
525 *start_buff = (pci_mem) ? pci_mem : &cm_node->
mpa_frame_buf[0];
530 *buff_len =
sizeof(
struct ietf_mpa_v1) + cm_node->mpa_frame_size;
531 build_mpa_v1(cm_node, *start_buff, mpa_key);
534 *buff_len =
sizeof(
struct ietf_mpa_v2) + cm_node->mpa_frame_size;
535 build_mpa_v2(cm_node, *start_buff, mpa_key);
546 static void build_mpa_v2(
struct nes_cm_node *cm_node,
547 void *start_addr,
u8 mpa_key)
555 build_mpa_v1(cm_node, start_addr, mpa_key);
561 IETF_NO_IRD_ORD : cm_node->
ird_size;
562 ctrl_ord = (cm_node->
ord_size > IETF_NO_IRD_ORD) ?
563 IETF_NO_IRD_ORD : cm_node->
ord_size;
590 static void build_mpa_v1(
struct nes_cm_node *cm_node,
void *start_addr,
u8 mpa_key)
607 static void build_rdma0_msg(
struct nes_cm_node *cm_node,
struct nes_qp **nesqp_addr)
610 struct nes_qp *nesqp = *nesqp_addr;
613 u64temp = (
unsigned long)nesqp;
658 nesqp->
hwqp.sq_tail = 0;
668 int close_when_complete)
676 new_send = kzalloc(
sizeof(*new_send),
GFP_ATOMIC);
705 add_ref_cm_node(cm_node);
712 "(jiffies = %lu)\n", new_send,
jiffies);
718 cleanup_retrans_entry(cm_node);
719 if (close_when_complete)
720 rem_ref_cm_node(cm_core, cm_node);
726 was_timer_set = timer_pending(&cm_core->
tcp_timer);
728 if (!was_timer_set) {
736 static void nes_retrans_expired(
struct nes_cm_node *cm_node)
745 rem_ref_cm_node(cm_node->
cm_core, cm_node);
751 send_reset(cm_node,
NULL);
754 add_ref_cm_node(cm_node);
755 send_reset(cm_node,
NULL);
760 static void handle_recv_entry(
struct nes_cm_node *cm_node,
u32 rem_node)
765 unsigned long qplockflags;
769 nesqp = (
struct nes_qp *)recv_entry->
skb;
774 "refcount = %d: HIT A "
775 "NES_TIMER_TYPE_CLOSE with something "
776 "to do!!!\n", nesqp->
hwqp.qp_id, cm_id,
781 spin_unlock_irqrestore(&nesqp->
lock, qplockflags);
784 spin_unlock_irqrestore(&nesqp->
lock, qplockflags);
786 "refcount = %d: HIT A "
787 "NES_TIMER_TYPE_CLOSE with nothing "
788 "to do!!!\n", nesqp->
hwqp.qp_id, cm_id,
791 }
else if (rem_node) {
793 rem_ref_cm_node(cm_node->
cm_core, cm_node);
804 static void nes_cm_timer_tick(
unsigned long pass)
814 unsigned long timetosend;
826 add_ref_cm_node(cm_node);
830 spin_unlock_irqrestore(&cm_core->
ht_lock, flags);
845 handle_recv_entry(cm_node, 1);
864 free_retrans_entry(cm_node);
871 free_retrans_entry(cm_node);
878 free_retrans_entry(cm_node);
880 spin_unlock_irqrestore(
882 nes_retrans_expired(cm_node);
891 "for node %p, jiffies = %lu, time to send = "
892 "%lu, retranscount = %u, send_entry->seq_num = "
893 "0x%08X, cm_node->tcp_cntxt.rem_ack_num = "
894 "0x%08X\n", send_entry, cm_node, jiffies,
906 "node=%p\n", cm_node);
916 "%u, retry count = %u.\n",
932 int close_when_complete;
933 close_when_complete =
936 cm_node, cm_node->
state);
937 free_retrans_entry(cm_node);
938 if (close_when_complete)
939 rem_ref_cm_node(cm_node->
cm_core,
945 rem_ref_cm_node(cm_node->
cm_core, cm_node);
949 if (!timer_pending(&cm_core->
tcp_timer)) {
950 cm_core->
tcp_timer.expires = nexttimeout;
965 char optionsbuffer[
sizeof(
struct option_mss) +
1016 form_cm_frame(skb, cm_node, optionsbuffer, optionssize,
NULL, 0, flags);
1029 int flags = SET_RST |
SET_ACK;
1038 form_cm_frame(skb, cm_node,
NULL, 0,
NULL, 0, flags);
1060 form_cm_frame(skb, cm_node,
NULL, 0,
NULL, 0, SET_ACK);
1083 form_cm_frame(skb, cm_node,
NULL, 0,
NULL, 0, SET_ACK | SET_FIN);
1096 unsigned long flags;
1111 rem_addr, rem_port);
1114 add_ref_cm_node(cm_node);
1115 spin_unlock_irqrestore(&cm_core->
ht_lock, flags);
1119 spin_unlock_irqrestore(&cm_core->
ht_lock, flags);
1132 unsigned long flags;
1139 if (((listen_node->
loc_addr == dst_addr) ||
1140 listen_node->
loc_addr == 0x00000000) &&
1141 (listen_node->
loc_port == dst_port) &&
1160 unsigned long flags;
1163 if (!cm_node || !cm_core)
1176 spin_unlock_irqrestore(&cm_core->
ht_lock, flags);
1185 static int mini_cm_dec_refcnt_listen(
struct nes_cm_core *cm_core,
1190 unsigned long flags;
1197 "refcnt=%d\n", listener, free_hanging_nodes,
1200 INIT_LIST_HEAD(&reset_list);
1201 if (free_hanging_nodes) {
1207 if ((cm_node->
listener == listener) &&
1209 add_ref_cm_node(cm_node);
1213 spin_unlock_irqrestore(&cm_core->
ht_lock, flags);
1222 if (NES_CM_STATE_FIN_WAIT1 <= cm_node->state) {
1223 rem_ref_cm_node(cm_node->
cm_core, cm_node);
1226 cleanup_retrans_entry(cm_node);
1227 err = send_reset(cm_node,
NULL);
1233 old_state = cm_node->
state;
1244 event.cm_info.rem_addr =
1246 event.cm_info.loc_addr =
1248 event.cm_info.rem_port =
1250 event.cm_info.loc_port =
1252 event.cm_info.cm_id = loopback->
cm_id;
1253 add_ref_cm_node(loopback);
1255 cm_event_connect_error(&event);
1258 rem_ref_cm_node(cm_node->
cm_core,
1291 " with non-zero pending accepts=%u\n",
1302 static int mini_cm_del_listen(
struct nes_cm_core *cm_core,
1307 return mini_cm_dec_refcnt_listen(cm_core, listener, 1);
1314 static inline int mini_cm_accelerated(
struct nes_cm_core *cm_core,
1328 was_timer_set = timer_pending(&cm_core->
tcp_timer);
1329 if (!was_timer_set) {
1341 static int nes_addr_resolve_neigh(
struct nes_vnic *nesvnic,
u32 dst_ip,
int arpindex)
1356 if (netif_is_bond_slave(nesvnic->
netdev))
1357 netdev = nesvnic->
netdev->master;
1359 netdev = nesvnic->
netdev;
1367 " is %pM, Gateway is 0x%08X \n", dst_ip,
1370 if (arpindex >= 0) {
1378 nesadapter->
arp_table[arpindex].mac_addr,
1387 neigh_event_send(neigh,
NULL);
1394 neigh_release(neigh);
1409 int oldarpindex = 0;
1415 cm_node = kzalloc(
sizeof(*cm_node),
GFP_ATOMIC);
1464 nesdev = nesvnic->
nesdev;
1471 arpindex = nes_addr_resolve_neigh(nesvnic, cm_info->
rem_addr, oldarpindex);
1482 add_hte_node(cm_core, cm_node);
1492 static int add_ref_cm_node(
struct nes_cm_node *cm_node)
1502 static int rem_ref_cm_node(
struct nes_cm_core *cm_core,
1505 unsigned long flags;
1513 spin_unlock_irqrestore(&cm_node->
cm_core->ht_lock, flags);
1518 spin_unlock_irqrestore(&cm_node->
cm_core->ht_lock, flags);
1528 handle_recv_entry(cm_node, 0);
1530 mini_cm_dec_refcnt_listen(cm_core, cm_node->
listener, 0);
1535 cm_node->
nesvnic->nesdev->pcidev->devfn),
1542 nesqp = cm_node->
nesqp;
1556 static int process_options(
struct nes_cm_node *cm_node,
u8 *optionsloc,
1557 u32 optionsize,
u32 syn_packet)
1562 char got_mss_option = 0;
1564 while (offset < optionsize) {
1566 switch (all_options->
as_base.optionnum) {
1568 offset = optionsize;
1575 "Size: %d\n", __func__,
1576 all_options->
as_mss.length, offset, optionsize);
1578 if (all_options->
as_mss.length != 4) {
1582 if (tmp > 0 && tmp <
1593 all_options->
as_base.optionnum);
1596 offset += all_options->
as_base.length;
1598 if ((!got_mss_option) && (syn_packet))
1603 static void drop_packet(
struct sk_buff *skb)
1609 static void handle_fin_pkt(
struct nes_cm_node *cm_node)
1612 "refcnt=%d\n", cm_node, cm_node->
state,
1614 switch (cm_node->
state) {
1620 cleanup_retrans_entry(cm_node);
1622 send_fin(cm_node,
NULL);
1627 cleanup_retrans_entry(cm_node);
1629 add_ref_cm_node(cm_node);
1630 send_reset(cm_node,
NULL);
1634 cleanup_retrans_entry(cm_node);
1636 send_ack(cm_node,
NULL);
1643 cleanup_retrans_entry(cm_node);
1645 send_ack(cm_node,
NULL);
1650 cleanup_retrans_entry(cm_node);
1652 rem_ref_cm_node(cm_node->
cm_core, cm_node);
1657 cm_node, cm_node->
state);
1670 " refcnt=%d\n", cm_node, cm_node->
state,
1672 cleanup_retrans_entry(cm_node);
1673 switch (cm_node->
state) {
1677 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1684 if (send_syn(cm_node, 0,
NULL)) {
1685 active_open_err(cm_node, skb, reset);
1690 active_open_err(cm_node, skb, reset);
1702 passive_open_err(cm_node, skb, reset);
1705 active_open_err(cm_node, skb, reset);
1716 rem_ref_cm_node(cm_node->
cm_core, cm_node);
1729 int datasize = skb->
len;
1735 ret = parse_mpa(cm_node, dataloc, &res_type, datasize);
1740 "cm_node=%p listener=%p state=%d\n", __func__,
1741 __LINE__, cm_node, cm_node->
listener,
1743 active_open_err(cm_node, skb, 1);
1745 passive_open_err(cm_node, skb, 1);
1750 switch (cm_node->
state) {
1763 cleanup_retrans_entry(cm_node);
1778 create_event(cm_node, type);
1783 switch (cm_node->
state) {
1787 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1789 active_open_err(cm_node, skb, 1);
1793 passive_open_err(cm_node, skb, 1);
1808 active_open_err(cm_node, skb, 1);
1826 if (ack_seq != loc_seq_num)
1828 else if (!between(seq, rcv_nxt, (rcv_nxt + rcv_wnd)))
1832 "listener=%p state=%d\n", __func__, __LINE__, cm_node,
1834 indicate_pkt_err(cm_node, skb);
1836 "rcv_nxt=0x%08X rcv_wnd=0x%x\n", cm_node, seq, rcv_nxt,
1854 optionsize = (tcph->doff << 2) -
sizeof(
struct tcphdr);
1858 switch (cm_node->
state) {
1862 active_open_err(cm_node, skb, 1);
1871 passive_open_err(cm_node, skb, 0);
1874 ret = handle_tcp_options(cm_node, tcph, skb, optionsize,
1877 passive_open_err(cm_node, skb, 0);
1881 cm_node->
tcp_cntxt.rcv_nxt = inc_sequence + 1;
1887 send_syn(cm_node, 1, skb);
1890 cleanup_retrans_entry(cm_node);
1891 add_ref_cm_node(cm_node);
1892 send_reset(cm_node, skb);
1915 optionsize = (tcph->doff << 2) -
sizeof(
struct tcphdr);
1918 switch (cm_node->
state) {
1920 cleanup_retrans_entry(cm_node);
1922 if (check_syn(cm_node, tcph, skb))
1926 ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 0);
1932 cleanup_retrans_entry(cm_node);
1933 cm_node->
tcp_cntxt.rcv_nxt = inc_sequence + 1;
1934 send_mpa_request(cm_node, skb);
1939 passive_open_err(cm_node, skb, 1);
1943 cleanup_retrans_entry(cm_node);
1945 send_reset(cm_node, skb);
1949 cleanup_retrans_entry(cm_node);
1950 add_ref_cm_node(cm_node);
1951 send_reset(cm_node, skb);
1975 optionsize = (tcph->doff << 2) -
sizeof(
struct tcphdr);
1977 if (check_seq(cm_node, tcph, skb))
1982 datasize = skb->
len;
1983 switch (cm_node->
state) {
1986 cleanup_retrans_entry(cm_node);
1987 ret = handle_tcp_options(cm_node, tcph, skb, optionsize, 1);
1993 cm_node->
tcp_cntxt.rcv_nxt = inc_sequence + datasize;
1994 handle_rcv_mpa(cm_node, skb);
2001 cleanup_retrans_entry(cm_node);
2003 cm_node->
tcp_cntxt.rcv_nxt = inc_sequence + datasize;
2004 handle_rcv_mpa(cm_node, skb);
2012 cm_node->
tcp_cntxt.rcv_nxt = inc_sequence + datasize;
2013 handle_rcv_mpa(cm_node, skb);
2019 cleanup_retrans_entry(cm_node);
2021 send_reset(cm_node, skb);
2024 cleanup_retrans_entry(cm_node);
2025 add_ref_cm_node(cm_node);
2026 send_reset(cm_node, skb);
2030 cleanup_retrans_entry(cm_node);
2033 rem_ref_cm_node(cm_node->
cm_core, cm_node);
2037 cleanup_retrans_entry(cm_node);
2047 cleanup_retrans_entry(cm_node);
2057 struct sk_buff *skb,
int optionsize,
int passive)
2059 u8 *optionsloc = (
u8 *)&tcph[1];
2062 if (process_options(cm_node, optionsloc, optionsize,
2067 passive_open_err(cm_node, skb, 1);
2069 active_open_err(cm_node, skb, 1);
2089 cleanup_retrans_entry(cm_node);
2092 "state=%d\n", cm_node, cm_node->
state);
2093 add_ref_cm_node(cm_node);
2094 send_reset(cm_node, skb);
2110 cleanup_retrans_entry(cm_node);
2114 "cm_node=%p state =%d\n", cm_node, cm_node->
state);
2115 send_reset(cm_node, skb);
2118 rem_ref_cm_node(cm_node->
cm_core, cm_node);
2126 static void free_retrans_entry(
struct nes_cm_node *cm_node)
2135 rem_ref_cm_node(cm_node->
cm_core, cm_node);
2139 static void cleanup_retrans_entry(
struct nes_cm_node *cm_node)
2141 unsigned long flags;
2144 free_retrans_entry(cm_node);
2156 struct tcphdr *tcph = tcp_hdr(skb);
2160 skb_pull(skb, ip_hdr(skb)->ihl << 2);
2163 "ack=%d rst=%d fin=%d\n", cm_node, cm_node->
state, tcph->syn,
2164 tcph->ack, tcph->rst, tcph->fin);
2168 }
else if (tcph->syn) {
2172 }
else if (tcph->ack) {
2180 handle_syn_pkt(cm_node, skb, tcph);
2183 handle_synack_pkt(cm_node, skb, tcph);
2186 ret = handle_ack_pkt(cm_node, skb, tcph);
2187 if (fin_set && !ret)
2188 handle_fin_pkt(cm_node);
2191 handle_rst_pkt(cm_node, skb, tcph);
2194 if ((fin_set) && (!check_seq(cm_node, tcph, skb)))
2195 handle_fin_pkt(cm_node);
2208 unsigned long flags;
2225 listener = kzalloc(
sizeof(*listener),
GFP_ATOMIC);
2261 " listener = %p, backlog = %d, cm_id = %p.\n",
2284 cm_node = make_cm_node(cm_core, nesvnic, cm_info,
NULL);
2293 loopbackremotelistener = find_listener(cm_core,
2296 if (loopbackremotelistener ==
NULL) {
2299 loopback_cm_info = *cm_info;
2301 loopback_cm_info.rem_port = cm_info->
loc_port;
2302 loopback_cm_info.cm_id = loopbackremotelistener->
cm_id;
2303 loopbackremotenode = make_cm_node(cm_core, nesvnic,
2304 &loopback_cm_info, loopbackremotelistener);
2305 if (!loopbackremotenode) {
2306 rem_ref_cm_node(cm_node->
cm_core, cm_node);
2311 loopbackremotenode->
tcp_cntxt.rcv_wscale =
2322 loopbackremotenode->
tcp_cntxt.loc_seq_num;
2327 loopbackremotenode->
tcp_cntxt.max_snd_wnd =
2334 loopbackremotenode->
tcp_cntxt.rcv_wscale;
2335 loopbackremotenode->
tcp_cntxt.snd_wscale =
2346 memcpy(start_buff, private_data, private_data_len);
2350 ret = send_syn(cm_node, 0,
NULL);
2355 "addr=0x%08X, port=0x%04x, cm_node=%p, cm_id = %p.\n",
2358 rem_ref_cm_node(cm_node->
cm_core, cm_node);
2364 "port=0x%04x, cm_node=%p, cm_id = %p.\n",
2400 cleanup_retrans_entry(cm_node);
2406 rem_ref_cm_node(cm_core, cm_node);
2409 rem_ref_cm_node(cm_core, cm_node);
2411 ret = send_mpa_reject(cm_node);
2414 err = send_reset(cm_node,
NULL);
2425 rem_ref_cm_node(cm_core, cm_node);
2426 rem_ref_cm_node(cm_core, loopback);
2429 event.cm_info.rem_addr = loopback->
rem_addr;
2430 event.cm_info.loc_addr = loopback->
loc_addr;
2431 event.cm_info.rem_port = loopback->
rem_port;
2432 event.cm_info.loc_port = loopback->
loc_port;
2433 event.cm_info.cm_id = loopback->
cm_id;
2434 cm_event_mpa_reject(&event);
2435 rem_ref_cm_node(cm_core, cm_node);
2438 cm_id = loopback->
cm_id;
2439 rem_ref_cm_node(cm_core, loopback);
2455 if (!cm_core || !cm_node)
2458 switch (cm_node->
state) {
2466 cleanup_retrans_entry(cm_node);
2467 send_reset(cm_node,
NULL);
2471 send_fin(cm_node,
NULL);
2481 cleanup_retrans_entry(cm_node);
2482 send_reset(cm_node,
NULL);
2489 ret = rem_ref_cm_node(cm_core, cm_node);
2495 ret = rem_ref_cm_node(cm_core, cm_node);
2506 static int mini_cm_recv_pkt(
struct nes_cm_core *cm_core,
2514 int skb_handled = 1;
2515 __be32 tmp_daddr, tmp_saddr;
2534 &tmp_daddr, tcph->
dest, &tmp_saddr, tcph->
source);
2537 cm_node = find_node(cm_core,
2538 nfo.rem_port, nfo.rem_addr,
2539 nfo.loc_port, nfo.loc_addr);
2544 if ((!tcph->syn) || (tcph->ack)) {
2548 listener = find_listener(cm_core, nfo.loc_addr,
2558 nfo.cm_id = listener->
cm_id;
2560 cm_node = make_cm_node(cm_core, nesvnic, &nfo,
2570 if (!tcph->rst && !tcph->fin) {
2574 rem_ref_cm_node(cm_core, cm_node);
2578 add_ref_cm_node(cm_node);
2580 if (cm_node->
nesqp->pau_mode)
2583 rem_ref_cm_node(cm_core, cm_node);
2589 skb_reset_network_header(skb);
2590 skb_set_transport_header(skb,
sizeof(*tcph));
2592 process_packet(cm_node, skb, cm_core);
2593 rem_ref_cm_node(cm_core, cm_node);
2602 static struct nes_cm_core *nes_cm_alloc_core(
void)
2608 cm_core = kzalloc(
sizeof(*cm_core),
GFP_KERNEL);
2614 cm_core->
tcp_timer.function = nes_cm_timer_tick;
2622 cm_core->
api = &nes_cm_api;
2637 print_core(cm_core);
2645 static int mini_cm_dealloc_core(
struct nes_cm_core *cm_core)
2669 static int mini_cm_get(
struct nes_cm_core *cm_core)
2671 return cm_core->
state;
2702 static int nes_cm_init_tsa_conn(
struct nes_qp *nesqp,
struct nes_cm_node *cm_node)
2750 " Setting MSS to %u, PDWscale = 0x%08X, rcv_wnd = %u, context misc = 0x%08X.\n",
2797 nes_cm_disconn_true(nesqp);
2805 static int nes_cm_disconn_true(
struct nes_qp *nesqp)
2807 unsigned long flags;
2813 u8 original_hw_tcp_state;
2814 u8 original_ibqp_state;
2815 int disconn_status = 0;
2816 int issue_disconn = 0;
2817 int issue_close = 0;
2818 int issue_flush = 0;
2828 cm_id = nesqp->
cm_id;
2833 spin_unlock_irqrestore(&nesqp->
lock, flags);
2837 nesvnic = to_nesvnic(nesqp->
ibqp.device);
2873 spin_unlock_irqrestore(&nesqp->
lock, flags);
2875 if ((issue_flush) && (nesqp->
destroyed == 0)) {
2882 ibevent.device = nesqp->
ibqp.device;
2884 ibevent.element.qp = &nesqp->
ibqp;
2885 if (nesqp->
ibqp.event_handler)
2886 nesqp->
ibqp.event_handler(&ibevent, nesqp->
ibqp.qp_context);
2891 if (issue_disconn) {
2894 cm_event.status = disconn_status;
2897 cm_event.private_data =
NULL;
2898 cm_event.private_data_len = 0;
2901 " for QP%u, SQ Head = %u, SQ Tail = %u. "
2902 "cm_id = %p, refcount = %u.\n",
2903 nesqp->
hwqp.qp_id, nesqp->
hwqp.sq_head,
2904 nesqp->
hwqp.sq_tail, cm_id,
2910 "returned, ret=%d\n", ret);
2915 nes_disconnect(nesqp, 1);
2920 cm_event.status = 0;
2924 cm_event.private_data =
NULL;
2925 cm_event.private_data_len = 0;
2942 static int nes_disconnect(
struct nes_qp *nesqp,
int abrupt)
2949 nesvnic = to_nesvnic(nesqp->
ibqp.device);
2953 nesdev = nesvnic->
nesdev;
2978 g_cm_core->
api->close(g_cm_core, nesqp->
cm_node);
3009 u8 mpa_frame_offset = 0;
3013 u8 **start_buff = &start_ptr;
3021 nesqp = to_nesqp(ibqp);
3022 nesvnic = to_nesvnic(nesqp->
ibqp.device);
3023 nesdev = nesvnic->
nesdev;
3028 "%s\n", cm_node, nesvnic, nesvnic->
netdev,
3034 rem_ref_cm_node(cm_node->
cm_core, cm_node);
3040 rem_ref_cm_node(cm_node->
cm_core, cm_node);
3045 nesqp->
cm_node = (
void *)cm_node;
3068 mpa_frame_offset = 4;
3077 wqe = &nesqp->
hwqp.sq_vbase[0];
3081 u64temp = (
unsigned long)nesqp;
3083 nespd = nesqp->
nespd;
3085 ibphysbuf.
size = buff_len;
3086 tagged_offset = (
u64)(
unsigned long)*start_buff;
3087 ibmr = nesibdev->
ibdev.reg_phys_mr((
struct ib_pd *)nespd,
3093 "for lSMM for cm_node = %p \n",
3116 (
u64)(
unsigned long)(*start_buff));
3136 nesqp->
cm_id = cm_id;
3137 cm_node->
cm_id = cm_id;
3147 nes_cm_init_tsa_conn(nesqp, cm_node);
3176 memset(&nes_quad, 0,
sizeof(nes_quad));
3184 crc_value = get_crc_value(&nes_quad);
3195 "0x%08X:0x%04X, rcv_nxt=0x%08X, snd_nxt=0x%08X, mpa + "
3196 "private data length=%u.\n", nesqp->
hwqp.qp_id,
3229 "ret=%d\n", __func__, __LINE__, ret);
3249 cm_node->
cm_id = cm_id;
3256 loopback->
mpa_frame.priv_data_len = pdata_len;
3261 memcpy(start_buff, pdata, pdata_len);
3263 return cm_core->
api->reject(cm_core, cm_node);
3284 nesqp = to_nesqp(ibqp);
3287 nesvnic = to_nesvnic(nesqp->
ibqp.device);
3290 nesdev = nesvnic->
nesdev;
3298 "0x%08X:0x%04X, local = 0x%08X:0x%04X.\n", nesqp->
hwqp.qp_id,
3316 if (conn_param->
ord == 0)
3341 cm_node = g_cm_core->
api->connect(g_cm_core, nesvnic,
3356 cm_node->
nesqp = nesqp;
3376 nesvnic = to_nesvnic(cm_id->
device);
3395 cm_node = g_cm_core->
api->listen(g_cm_core, nesvnic, &cm_info);
3398 __func__, __LINE__);
3412 g_cm_core->
api->stop_listener(g_cm_core, (
void *)cm_node);
3450 if ((g_cm_core) && (g_cm_core->
api))
3451 rc = g_cm_core->
api->recv_pkt(g_cm_core, netdev_priv(netdevice), skb);
3454 " cm is not setup properly.\n");
3468 g_cm_core = nes_cm_alloc_core();
3482 g_cm_core->
api->destroy_cm_core(g_cm_core);
3491 static void cm_event_connected(
struct nes_cm_event *event)
3506 cm_node =
event->cm_node;
3507 cm_id = cm_node->
cm_id;
3510 nesvnic = to_nesvnic(nesqp->
ibqp.device);
3511 nesdev = nesvnic->
nesdev;
3518 " local port 0x%04X. jiffies = %lu.\n",
3525 nes_cm_init_tsa_conn(nesqp, cm_node);
3552 build_rdma0_msg(cm_node, &nesqp);
3555 (1 << 24) | 0x00800000 | nesqp->
hwqp.qp_id);
3557 memset(&nes_quad, 0,
sizeof(nes_quad));
3559 nes_quad.DstIpAdrIndex =
3561 nes_quad.SrcIpadr = cm_id->
remote_addr.sin_addr.s_addr;
3562 nes_quad.TcpPorts[0] = cm_id->
remote_addr.sin_port;
3563 nes_quad.TcpPorts[1] = cm_id->
local_addr.sin_port;
3566 crc_value = get_crc_value(&nes_quad);
3580 cm_event.status = 0;
3582 cm_event.local_addr.sin_family =
AF_INET;
3583 cm_event.local_addr.sin_port = cm_id->
local_addr.sin_port;
3586 cm_event.private_data = (
void *)event->
cm_node->mpa_frame_buf;
3587 cm_event.private_data_len = (
u8)
event->cm_node->mpa_frame_size;
3591 cm_event.local_addr.sin_addr.s_addr =
event->cm_info.rem_addr;
3597 "ret=%d\n", __func__, __LINE__, ret);
3602 "%lu\n", nesqp->
hwqp.qp_id, jiffies);
3611 static void cm_event_connect_error(
struct nes_cm_event *event)
3622 cm_id =
event->cm_node->cm_id;
3641 cm_event.private_data =
NULL;
3642 cm_event.private_data_len = 0;
3645 "remove_addr=%08x\n", cm_event.local_addr.sin_addr.s_addr,
3646 cm_event.remote_addr.sin_addr.s_addr);
3652 "ret=%d\n", __func__, __LINE__, ret);
3677 cm_id =
event->cm_node->cm_id;
3691 cm_event.private_data =
NULL;
3692 cm_event.private_data_len = 0;
3698 cm_event.status = 0;
3702 cm_event.private_data =
NULL;
3703 cm_event.private_data_len = 0;
3720 static void cm_event_mpa_req(
struct nes_cm_event *event)
3727 cm_node =
event->cm_node;
3730 cm_id = cm_node->
cm_id;
3734 cm_node, cm_id, jiffies);
3737 cm_event.status = 0;
3738 cm_event.provider_data = (
void *)cm_node;
3740 cm_event.local_addr.sin_family =
AF_INET;
3741 cm_event.local_addr.sin_port =
htons(event->
cm_info.loc_port);
3742 cm_event.local_addr.sin_addr.s_addr =
htonl(event->
cm_info.loc_addr);
3744 cm_event.remote_addr.sin_family =
AF_INET;
3745 cm_event.remote_addr.sin_port =
htons(event->
cm_info.rem_port);
3746 cm_event.remote_addr.sin_addr.s_addr =
htonl(event->
cm_info.rem_addr);
3754 printk(
KERN_ERR "%s[%u] OFA CM event_handler returned, ret=%d\n",
3755 __func__, __LINE__, ret);
3760 static void cm_event_mpa_reject(
struct nes_cm_event *event)
3767 cm_node =
event->cm_node;
3770 cm_id = cm_node->
cm_id;
3774 cm_node, cm_id, jiffies);
3780 cm_event.local_addr.sin_family =
AF_INET;
3781 cm_event.local_addr.sin_port =
htons(event->
cm_info.loc_port);
3782 cm_event.local_addr.sin_addr.s_addr =
htonl(event->
cm_info.loc_addr);
3784 cm_event.remote_addr.sin_family =
AF_INET;
3785 cm_event.remote_addr.sin_port =
htons(event->
cm_info.rem_port);
3786 cm_event.remote_addr.sin_addr.s_addr =
htonl(event->
cm_info.rem_addr);
3792 "remove_addr=%08x\n",
3793 cm_event.local_addr.sin_addr.s_addr,
3794 cm_event.remote_addr.sin_addr.s_addr);
3798 printk(
KERN_ERR "%s[%u] OFA CM event_handler returned, ret=%d\n",
3799 __func__, __LINE__, ret);
3805 static void nes_cm_event_handler(
struct work_struct *);
3811 static int nes_cm_post_event(
struct nes_cm_event *event)
3814 add_ref_cm_node(event->
cm_node);
3815 event->cm_info.cm_id->add_ref(event->
cm_info.cm_id);
3841 cm_core =
event->cm_node->cm_core;
3845 switch (event->
type) {
3847 cm_event_mpa_req(event);
3854 cm_event_reset(event);
3857 if ((!event->
cm_node->cm_id) ||
3860 cm_event_connected(event);
3864 if ((!event->
cm_node->cm_id) ||
3867 cm_event_mpa_reject(event);
3872 if ((!event->
cm_node->cm_id) ||
3875 cm_event_connect_error(event);
3887 event->cm_info.cm_id->rem_ref(event->
cm_info.cm_id);
3888 rem_ref_cm_node(cm_core, event->
cm_node);