32 #include <linux/module.h>
33 #include <linux/list.h>
34 #include <linux/slab.h>
51 static char *states[] = {
71 static int ep_timeout_secs = 60;
74 "in seconds (default=60)");
76 static int mpa_rev = 1;
79 "1 is spec compliant. (default=1)");
81 static int markers_enabled = 0;
83 MODULE_PARM_DESC(markers_enabled,
"Enable MPA MARKERS (default(0)=disabled)");
85 static int crc_enabled = 1;
89 static int rcv_win = 256 * 1024;
93 static int snd_win = 32 * 1024;
97 static unsigned int nocong = 0;
101 static unsigned int cong_flavor = 1;
110 static void ep_timeout(
unsigned long arg);
111 static void connect_reply_upcall(
struct iwch_ep *ep,
int status);
113 static void start_ep_timer(
struct iwch_ep *ep)
115 PDBG(
"%s ep %p\n", __func__, ep);
116 if (timer_pending(&ep->
timer)) {
117 PDBG(
"%s stopped / restarted timer ep %p\n", __func__, ep);
123 ep->
timer.function = ep_timeout;
127 static void stop_ep_timer(
struct iwch_ep *ep)
129 PDBG(
"%s ep %p\n", __func__, ep);
130 if (!timer_pending(&ep->
timer)) {
131 printk(
KERN_ERR "%s timer stopped when its not running! ep %p state %u\n",
132 __func__, ep, ep->
com.state);
146 if (cxio_fatal_error(rdev)) {
150 error = l2t_send(tdev, skb, l2e);
162 if (cxio_fatal_error(rdev)) {
172 static void release_tid(
struct t3cdev *tdev,
u32 hwtid,
struct sk_buff *skb)
231 PDBG(
"%s ep %p opt %u\n", __func__, ep, opt);
247 spin_unlock_irqrestore(&epc->
lock, flags);
261 PDBG(
"%s - %s -> %s\n", __func__, states[epc->
state], states[
new]);
262 __state_set(epc,
new);
263 spin_unlock_irqrestore(&epc->
lock, flags);
267 static void *alloc_ep(
int size,
gfp_t gfp)
271 epc = kzalloc(size, gfp);
273 kref_init(&epc->
kref);
277 PDBG(
"%s alloc ep %p\n", __func__, epc);
290 l2t_release(ep->
com.tdev, ep->
l2t);
295 static void release_ep_resources(
struct iwch_ep *ep)
297 PDBG(
"%s ep %p tid %d\n", __func__, ep, ep->
hwtid);
302 static int status2errno(
int status)
327 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
331 skb = alloc_skb(len, gfp);
343 rt = ip_route_output_ports(&
init_net, &fl4,
NULL, peer_ip, local_ip,
351 static unsigned int find_best_mtu(
const struct t3c_data *
d,
unsigned short mtu)
355 while (i < d->nmtus - 1 && d->
mtus[i + 1] <= mtu)
360 static void arp_failure_discard(
struct t3cdev *dev,
struct sk_buff *skb)
362 PDBG(
"%s t3cdev %p\n", __func__, dev);
369 static void act_open_req_arp_failure(
struct t3cdev *dev,
struct sk_buff *skb)
379 static void abort_arp_failure(
struct t3cdev *dev,
struct sk_buff *skb)
383 PDBG(
"%s t3cdev %p\n", __func__, dev);
388 static int send_halfclose(
struct iwch_ep *ep,
gfp_t gfp)
393 PDBG(
"%s ep %p\n", __func__, ep);
394 skb = get_skb(
NULL,
sizeof(*req), gfp);
400 set_arp_failure_handler(skb, arp_failure_discard);
405 return iwch_l2t_send(ep->
com.tdev, skb, ep->
l2t);
412 PDBG(
"%s ep %p\n", __func__, ep);
413 skb = get_skb(skb,
sizeof(*req), gfp);
420 set_arp_failure_handler(skb, abort_arp_failure);
426 return iwch_l2t_send(ep->
com.tdev, skb, ep->
l2t);
429 static int send_connect(
struct iwch_ep *ep)
433 u32 opt0h, opt0l, opt2;
434 unsigned int mtu_idx;
437 PDBG(
"%s ep %p\n", __func__, ep);
445 mtu_idx = find_best_mtu(
T3C_DATA(ep->
com.tdev), dst_mtu(ep->
dst));
446 wscale = compute_wscale(rcv_win);
458 set_arp_failure_handler(skb, act_open_req_arp_failure);
465 req->
local_ip = ep->
com.local_addr.sin_addr.s_addr;
466 req->
peer_ip = ep->
com.remote_addr.sin_addr.s_addr;
471 return iwch_l2t_send(ep->
com.tdev, skb, ep->
l2t);
481 PDBG(
"%s ep %p pd_len %d\n", __func__, ep, ep->
plen);
485 mpalen =
sizeof(*mpa) + ep->
plen;
486 if (skb->
data + mpalen +
sizeof(*req) > skb_end_pointer(skb)) {
488 skb=alloc_skb(mpalen +
sizeof(*req),
GFP_KERNEL);
490 connect_reply_upcall(ep, -
ENOMEM);
495 skb_reserve(skb,
sizeof(*req));
499 memset(mpa, 0,
sizeof(*mpa));
515 set_arp_failure_handler(skb, arp_failure_discard);
516 skb_reset_transport_header(skb);
528 iwch_l2t_send(ep->
com.tdev, skb, ep->
l2t);
541 PDBG(
"%s ep %p plen %d\n", __func__, ep, plen);
543 mpalen =
sizeof(*mpa) +
plen;
550 skb_reserve(skb,
sizeof(*req));
552 memset(mpa, 0,
sizeof(*mpa));
567 set_arp_failure_handler(skb, arp_failure_discard);
568 skb_reset_transport_header(skb);
579 return iwch_l2t_send(ep->
com.tdev, skb, ep->
l2t);
582 static int send_mpa_reply(
struct iwch_ep *ep,
const void *pdata,
u8 plen)
590 PDBG(
"%s ep %p plen %d\n", __func__, ep, plen);
592 mpalen =
sizeof(*mpa) +
plen;
600 skb_reserve(skb,
sizeof(*req));
602 memset(mpa, 0,
sizeof(*mpa));
605 (markers_enabled ? MPA_MARKERS : 0);
617 set_arp_failure_handler(skb, arp_failure_discard);
618 skb_reset_transport_header(skb);
630 return iwch_l2t_send(ep->
com.tdev, skb, ep->
l2t);
633 static int act_establish(
struct t3cdev *tdev,
struct sk_buff *skb,
void *
ctx)
639 PDBG(
"%s ep %p tid %d\n", __func__, ep, tid);
641 dst_confirm(ep->
dst);
656 send_mpa_req(ep, skb);
663 PDBG(
"%s ep %p\n", __FILE__, ep);
665 send_abort(ep, skb, gfp);
668 static void close_complete_upcall(
struct iwch_ep *ep)
672 PDBG(
"%s ep %p\n", __func__, ep);
676 PDBG(
"close complete delivered ep %p cm_id %p tid %d\n",
678 ep->
com.cm_id->event_handler(ep->
com.cm_id, &
event);
679 ep->
com.cm_id->rem_ref(ep->
com.cm_id);
685 static void peer_close_upcall(
struct iwch_ep *ep)
689 PDBG(
"%s ep %p\n", __func__, ep);
693 PDBG(
"peer close delivered ep %p cm_id %p tid %d\n",
695 ep->
com.cm_id->event_handler(ep->
com.cm_id, &
event);
699 static void peer_abort_upcall(
struct iwch_ep *ep)
703 PDBG(
"%s ep %p\n", __func__, ep);
708 PDBG(
"abort delivered ep %p cm_id %p tid %d\n", ep,
710 ep->
com.cm_id->event_handler(ep->
com.cm_id, &
event);
711 ep->
com.cm_id->rem_ref(ep->
com.cm_id);
717 static void connect_reply_upcall(
struct iwch_ep *ep,
int status)
721 PDBG(
"%s ep %p status %d\n", __func__, ep, status);
725 event.local_addr = ep->
com.local_addr;
726 event.remote_addr = ep->
com.remote_addr;
729 event.private_data_len = ep->
plen;
733 PDBG(
"%s ep %p tid %d status %d\n", __func__, ep,
735 ep->
com.cm_id->event_handler(ep->
com.cm_id, &
event);
738 ep->
com.cm_id->rem_ref(ep->
com.cm_id);
744 static void connect_request_upcall(
struct iwch_ep *ep)
748 PDBG(
"%s ep %p tid %d\n", __func__, ep, ep->
hwtid);
751 event.local_addr = ep->
com.local_addr;
752 event.remote_addr = ep->
com.remote_addr;
753 event.private_data_len = ep->
plen;
755 event.provider_data = ep;
760 event.
ird =
event.ord = 8;
771 static void established_upcall(
struct iwch_ep *ep)
775 PDBG(
"%s ep %p\n", __func__, ep);
782 event.ird =
event.ord = 8;
784 PDBG(
"%s ep %p tid %d\n", __func__, ep, ep->
hwtid);
785 ep->
com.cm_id->event_handler(ep->
com.cm_id, &
event);
789 static int update_rx_credits(
struct iwch_ep *ep,
u32 credits)
794 PDBG(
"%s ep %p credits %u\n", __func__, ep, credits);
810 static void process_mpa_reply(
struct iwch_ep *ep,
struct sk_buff *skb)
818 PDBG(
"%s ep %p\n", __func__, ep);
902 ep->
mpa_attr.recv_marker_enabled = markers_enabled;
903 ep->
mpa_attr.xmit_marker_enabled = mpa->
flags & MPA_MARKERS ? 1 : 0;
905 PDBG(
"%s - crc_enabled=%d, recv_marker_enabled=%d, "
906 "xmit_marker_enabled=%d, version=%d\n", __func__,
911 attrs.max_ird = ep->
ird;
912 attrs.max_ord = ep->
ord;
913 attrs.llp_stream_handle = ep;
922 ep->
com.qp, mask, &attrs, 1);
934 connect_reply_upcall(ep, err);
938 static void process_mpa_request(
struct iwch_ep *ep,
struct sk_buff *skb)
943 PDBG(
"%s ep %p\n", __func__, ep);
963 PDBG(
"%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
978 PDBG(
"%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1025 ep->
mpa_attr.recv_marker_enabled = markers_enabled;
1026 ep->
mpa_attr.xmit_marker_enabled = mpa->
flags & MPA_MARKERS ? 1 : 0;
1028 PDBG(
"%s - crc_enabled=%d, recv_marker_enabled=%d, "
1029 "xmit_marker_enabled=%d, version=%d\n", __func__,
1036 connect_request_upcall(ep);
1040 static int rx_data(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1046 PDBG(
"%s ep %p dlen %u\n", __func__, ep, dlen);
1056 process_mpa_reply(ep, skb);
1059 process_mpa_request(ep, skb);
1065 " ep %p state %d tid %d\n",
1076 update_rx_credits(ep, dlen);
1086 static int tx_ack(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1091 unsigned long flags;
1094 PDBG(
"%s ep %p credits %u\n", __func__, ep, credits);
1097 PDBG(
"%s 0 credit ack ep %p state %u\n",
1104 dst_confirm(ep->
dst);
1106 PDBG(
"%s rdma_init wr_ack ep %p state %u\n",
1107 __func__, ep, ep->
com.state);
1109 PDBG(
"%s initiator ep %p state %u\n",
1110 __func__, ep, ep->
com.state);
1114 PDBG(
"%s responder ep %p state %u\n",
1115 __func__, ep, ep->
com.state);
1117 ep->
com.rpl_done = 1;
1122 PDBG(
"%s lsm ack ep %p state %u freeing skb\n",
1123 __func__, ep, ep->
com.state);
1127 spin_unlock_irqrestore(&ep->
com.lock, flags);
1133 static int abort_rpl(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1136 unsigned long flags;
1139 PDBG(
"%s ep %p\n", __func__, ep);
1151 switch (ep->
com.state) {
1153 close_complete_upcall(ep);
1159 __func__, ep, ep->
com.state);
1162 spin_unlock_irqrestore(&ep->
com.lock, flags);
1165 release_ep_resources(ep);
1172 static inline int act_open_has_tid(
int status)
1178 static int act_open_rpl(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1183 PDBG(
"%s ep %p status %u errno %d\n", __func__, ep, rpl->
status,
1184 status2errno(rpl->
status));
1185 connect_reply_upcall(ep, status2errno(rpl->
status));
1187 if (ep->
com.tdev->type !=
T3A && act_open_has_tid(rpl->
status))
1191 l2t_release(ep->
com.tdev, ep->
l2t);
1201 PDBG(
"%s ep %p\n", __func__, ep);
1212 req->
local_ip = ep->
com.local_addr.sin_addr.s_addr;
1224 static int pass_open_rpl(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1229 PDBG(
"%s ep %p status %d error %d\n", __func__, ep,
1231 ep->
com.rpl_err = status2errno(rpl->
status);
1232 ep->
com.rpl_done = 1;
1243 PDBG(
"%s ep %p\n", __func__, ep);
1257 static int close_listsrv_rpl(
struct t3cdev *tdev,
struct sk_buff *skb,
1263 PDBG(
"%s ep %p\n", __func__, ep);
1264 ep->
com.rpl_err = status2errno(rpl->
status);
1265 ep->
com.rpl_done = 1;
1273 unsigned int mtu_idx;
1277 PDBG(
"%s ep %p\n", __func__, ep);
1281 mtu_idx = find_best_mtu(
T3C_DATA(ep->
com.tdev), dst_mtu(ep->
dst));
1282 wscale = compute_wscale(rcv_win);
1303 iwch_l2t_send(ep->
com.tdev, skb, ep->
l2t);
1311 PDBG(
"%s t3cdev %p tid %u peer_ip %x\n", __func__, tdev, hwtid,
1318 release_tid(tdev, hwtid, skb);
1336 static int pass_accept_req(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1340 unsigned int hwtid =
GET_TID(req);
1346 PDBG(
"%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
1366 rt = find_route(tdev,
1384 child_ep = alloc_ep(
sizeof(*child_ep),
GFP_KERNEL);
1388 l2t_release(tdev, l2t);
1393 child_ep->
com.tdev = tdev;
1395 child_ep->
com.local_addr.sin_family =
PF_INET;
1397 child_ep->
com.local_addr.sin_addr.s_addr = req->
local_ip;
1398 child_ep->
com.remote_addr.sin_family =
PF_INET;
1400 child_ep->
com.remote_addr.sin_addr.s_addr = req->
peer_ip;
1404 child_ep->
l2t = l2t;
1406 child_ep->
hwtid = hwtid;
1409 accept_cr(child_ep, req->
peer_ip, skb);
1412 reject_cr(tdev, hwtid, req->
peer_ip, skb);
1417 static int pass_establish(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1422 PDBG(
"%s ep %p\n", __func__, ep);
1428 dst_confirm(ep->
dst);
1435 static int peer_close(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1439 unsigned long flags;
1443 PDBG(
"%s ep %p\n", __func__, ep);
1444 dst_confirm(ep->
dst);
1447 switch (ep->
com.state) {
1464 ep->
com.rpl_done = 1;
1466 PDBG(
"waking up ep %p\n", ep);
1471 ep->
com.rpl_done = 1;
1473 PDBG(
"waking up ep %p\n", ep);
1482 peer_close_upcall(ep);
1493 if (ep->
com.cm_id && ep->
com.qp) {
1498 close_complete_upcall(ep);
1509 spin_unlock_irqrestore(&ep->
com.lock, flags);
1513 release_ep_resources(ep);
1520 static int is_neg_adv_abort(
unsigned int status)
1526 static int peer_abort(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1535 unsigned long flags;
1537 if (is_neg_adv_abort(req->
status)) {
1538 PDBG(
"%s neg_adv_abort ep %p tid %d\n", __func__, ep,
1553 PDBG(
"%s ep %p state %u\n", __func__, ep, ep->
com.state);
1554 switch (ep->
com.state) {
1565 ep->
com.rpl_done = 1;
1567 PDBG(
"waking up ep %p\n", ep);
1578 ep->
com.rpl_done = 1;
1580 PDBG(
"waking up ep %p\n", ep);
1588 if (ep->
com.cm_id && ep->
com.qp) {
1595 "%s - qp <- error failed!\n",
1598 peer_abort_upcall(ep);
1603 PDBG(
"%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
1604 spin_unlock_irqrestore(&ep->
com.lock, flags);
1610 dst_confirm(ep->
dst);
1615 spin_unlock_irqrestore(&ep->
com.lock, flags);
1617 rpl_skb = get_skb(skb,
sizeof(*rpl),
GFP_KERNEL);
1633 release_ep_resources(ep);
1637 static int close_con_rpl(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1641 unsigned long flags;
1644 PDBG(
"%s ep %p\n", __func__, ep);
1649 switch (ep->
com.state) {
1655 if ((ep->
com.cm_id) && (ep->
com.qp)) {
1662 close_complete_upcall(ep);
1673 spin_unlock_irqrestore(&ep->
com.lock, flags);
1675 release_ep_resources(ep);
1691 static int terminate(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1698 PDBG(
"%s ep %p\n", __func__, ep);
1700 PDBG(
"%s saving %d bytes of term msg\n", __func__, skb->
len);
1701 skb_copy_from_linear_data(skb, ep->
com.qp->attr.terminate_buffer,
1703 ep->
com.qp->attr.terminate_msg_len = skb->
len;
1704 ep->
com.qp->attr.is_terminate_local = 0;
1708 static int ec_status(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
1713 PDBG(
"%s ep %p tid %u status %d\n", __func__, ep, ep->
hwtid,
1719 __func__, ep->
hwtid);
1730 static void ep_timeout(
unsigned long arg)
1734 unsigned long flags;
1738 PDBG(
"%s ep %p tid %u state %d\n", __func__, ep, ep->
hwtid,
1740 switch (ep->
com.state) {
1750 if (ep->
com.cm_id && ep->
com.qp) {
1760 __func__, ep, ep->
com.state);
1764 spin_unlock_irqrestore(&ep->
com.lock, flags);
1773 struct iwch_ep *ep = to_ep(cm_id);
1774 PDBG(
"%s ep %p tid %u\n", __func__, ep, ep->
hwtid);
1784 err = send_mpa_reject(ep, pdata, pdata_len);
1796 struct iwch_ep *ep = to_ep(cm_id);
1798 struct iwch_qp *qp = get_qhp(h, conn_param->
qpn);
1800 PDBG(
"%s ep %p tid %u\n", __func__, ep, ep->
hwtid);
1809 if ((conn_param->
ord > qp->
rhp->attr.max_rdma_read_qp_depth) ||
1810 (conn_param->
ird > qp->
rhp->attr.max_rdma_reads_per_qp)) {
1817 ep->
com.cm_id = cm_id;
1820 ep->
ird = conn_param->
ird;
1821 ep->
ord = conn_param->
ord;
1826 PDBG(
"%s %d ird %d ord %d\n", __func__, __LINE__, ep->
ird, ep->
ord);
1843 ep->
com.qp, mask, &attrs, 1);
1850 err = ep->
com.rpl_err;
1862 established_upcall(ep);
1892 if (is_loopback_dst(cm_id)) {
1908 ep->
ird = conn_param->
ird;
1909 ep->
ord = conn_param->
ord;
1914 ep->
com.tdev = h->
rdev.t3cdev_p;
1917 ep->
com.cm_id = cm_id;
1918 ep->
com.qp = get_qhp(h, conn_param->
qpn);
1920 PDBG(
"%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->
qpn,
1927 if (ep->
atid == -1) {
1934 rt = find_route(h->
rdev.t3cdev_p,
1959 err = send_connect(ep);
1963 l2t_release(h->
rdev.t3cdev_p, ep->
l2t);
1990 PDBG(
"%s ep %p\n", __func__, ep);
1991 ep->
com.tdev = h->
rdev.t3cdev_p;
1993 ep->
com.cm_id = cm_id;
2001 if (ep->
stid == -1) {
2008 err = listen_start(ep);
2014 err = ep->
com.rpl_err;
2034 PDBG(
"%s ep %p\n", __func__, ep);
2038 ep->
com.rpl_done = 0;
2039 ep->
com.rpl_err = 0;
2040 err = listen_stop(ep);
2046 err = ep->
com.rpl_err;
2055 unsigned long flags;
2063 PDBG(
"%s ep %p state %s, abrupt %d\n", __func__, ep,
2064 states[ep->
com.state], abrupt);
2068 if (cxio_fatal_error(rdev)) {
2070 close_complete_upcall(ep);
2073 switch (ep->
com.state) {
2101 PDBG(
"%s ignoring disconnect ep %p state %u\n",
2102 __func__, ep, ep->
com.state);
2109 spin_unlock_irqrestore(&ep->
com.lock, flags);
2112 ret = send_abort(ep,
NULL, gfp);
2114 ret = send_halfclose(ep, gfp);
2119 release_ep_resources(ep);
2131 PDBG(
"%s ep %p redirect to dst %p l2t %p\n", __func__, ep,
new,
2134 l2t_release(ep->
com.tdev, ep->
l2t);
2171 ep = *((
void **) (skb->cb));
2172 tdev = *((
struct t3cdev **) (skb->cb +
sizeof(
void *)));
2195 *((
void **) skb->cb) =
ctx;
2196 *((
struct t3cdev **) (skb->cb +
sizeof(
void *))) = tdev;
2206 static int set_tcb_rpl(
struct t3cdev *tdev,
struct sk_buff *skb,
void *ctx)
2242 skb_queue_head_init(&rxq);