Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[cascardo/linux.git] / drivers / infiniband / hw / cxgb4 / cm.c
index c3c678f..71c8867 100644 (file)
@@ -240,15 +240,13 @@ int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
 
 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
 {
-       struct cpl_tid_release *req;
+       u32 len = roundup(sizeof(struct cpl_tid_release), 16);
 
-       skb = get_skb(skb, sizeof *req, GFP_KERNEL);
+       skb = get_skb(skb, len, GFP_KERNEL);
        if (!skb)
                return;
-       req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
-       INIT_TP_WR(req, hwtid);
-       OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
-       set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
+
+       cxgb_mk_tid_release(skb, len, hwtid, 0);
        c4iw_ofld_send(rdev, skb);
        return;
 }
@@ -334,6 +332,8 @@ static void remove_ep_tid(struct c4iw_ep *ep)
 
        spin_lock_irqsave(&ep->com.dev->lock, flags);
        _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
+       if (idr_is_empty(&ep->com.dev->hwtid_idr))
+               wake_up(&ep->com.dev->wait);
        spin_unlock_irqrestore(&ep->com.dev->lock, flags);
 }
 
@@ -639,41 +639,31 @@ static int send_flowc(struct c4iw_ep *ep)
 
 static int send_halfclose(struct c4iw_ep *ep)
 {
-       struct cpl_close_con_req *req;
        struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
-       int wrlen = roundup(sizeof *req, 16);
+       u32 wrlen = roundup(sizeof(struct cpl_close_con_req), 16);
 
        PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
        if (WARN_ON(!skb))
                return -ENOMEM;
 
-       set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
-       t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
-       req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
-       memset(req, 0, wrlen);
-       INIT_TP_WR(req, ep->hwtid);
-       OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
-                                                   ep->hwtid));
+       cxgb_mk_close_con_req(skb, wrlen, ep->hwtid, ep->txq_idx,
+                             NULL, arp_failure_discard);
+
        return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
 }
 
 static int send_abort(struct c4iw_ep *ep)
 {
-       struct cpl_abort_req *req;
-       int wrlen = roundup(sizeof *req, 16);
+       u32 wrlen = roundup(sizeof(struct cpl_abort_req), 16);
        struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
 
        PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
        if (WARN_ON(!req_skb))
                return -ENOMEM;
 
-       set_wr_txq(req_skb, CPL_PRIORITY_DATA, ep->txq_idx);
-       t4_set_arp_err_handler(req_skb, ep, abort_arp_failure);
-       req = (struct cpl_abort_req *)skb_put(req_skb, wrlen);
-       memset(req, 0, wrlen);
-       INIT_TP_WR(req, ep->hwtid);
-       OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
-       req->cmd = CPL_ABORT_SEND_RST;
+       cxgb_mk_abort_req(req_skb, wrlen, ep->hwtid, ep->txq_idx,
+                         ep, abort_arp_failure);
+
        return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
 }
 
@@ -689,7 +679,7 @@ static int send_connect(struct c4iw_ep *ep)
        u64 opt0;
        u32 opt2;
        unsigned int mtu_idx;
-       int wscale;
+       u32 wscale;
        int win, sizev4, sizev6, wrlen;
        struct sockaddr_in *la = (struct sockaddr_in *)
                                 &ep->com.local_addr;
@@ -739,7 +729,7 @@ static int send_connect(struct c4iw_ep *ep)
        cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
                      enable_tcp_timestamps,
                      (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
-       wscale = compute_wscale(rcv_win);
+       wscale = cxgb_compute_wscale(rcv_win);
 
        /*
         * Specify the largest window that will fit in opt0. The
@@ -1366,9 +1356,9 @@ static void established_upcall(struct c4iw_ep *ep)
 
 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
 {
-       struct cpl_rx_data_ack *req;
        struct sk_buff *skb;
-       int wrlen = roundup(sizeof *req, 16);
+       u32 wrlen = roundup(sizeof(struct cpl_rx_data_ack), 16);
+       u32 credit_dack;
 
        PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
        skb = get_skb(NULL, wrlen, GFP_KERNEL);
@@ -1385,15 +1375,12 @@ static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
        if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
                credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
 
-       req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
-       memset(req, 0, wrlen);
-       INIT_TP_WR(req, ep->hwtid);
-       OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
-                                                   ep->hwtid));
-       req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
-                                      RX_DACK_CHANGE_F |
-                                      RX_DACK_MODE_V(dack_mode));
-       set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
+       credit_dack = credits | RX_FORCE_ACK_F | RX_DACK_CHANGE_F |
+                     RX_DACK_MODE_V(dack_mode);
+
+       cxgb_mk_rx_data_ack(skb, wrlen, ep->hwtid, ep->ctrlq_idx,
+                           credit_dack);
+
        c4iw_ofld_send(&ep->com.dev->rdev, skb);
        return credits;
 }
@@ -1891,7 +1878,7 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
        struct sk_buff *skb;
        struct fw_ofld_connection_wr *req;
        unsigned int mtu_idx;
-       int wscale;
+       u32 wscale;
        struct sockaddr_in *sin;
        int win;
 
@@ -1919,7 +1906,7 @@ static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
        cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
                      enable_tcp_timestamps,
                      (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
-       wscale = compute_wscale(rcv_win);
+       wscale = cxgb_compute_wscale(rcv_win);
 
        /*
         * Specify the largest window that will fit in opt0. The
@@ -2029,8 +2016,10 @@ static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
                }
                ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
                                        n, pdev, rt_tos2priority(tos));
-               if (!ep->l2t)
+               if (!ep->l2t) {
+                       dev_put(pdev);
                        goto out;
+               }
                ep->mtu = pdev->mtu;
                ep->tx_chan = cxgb4_port_chan(pdev);
                ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
@@ -2339,7 +2328,7 @@ static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
        unsigned int mtu_idx;
        u64 opt0;
        u32 opt2;
-       int wscale;
+       u32 wscale;
        struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
        int win;
        enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
@@ -2363,7 +2352,7 @@ static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
        cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
                      enable_tcp_timestamps && req->tcpopt.tstamp,
                      (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
-       wscale = compute_wscale(rcv_win);
+       wscale = cxgb_compute_wscale(rcv_win);
 
        /*
         * Specify the largest window that will fit in opt0. The
@@ -2717,12 +2706,12 @@ static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
 {
        struct cpl_abort_req_rss *req = cplhdr(skb);
        struct c4iw_ep *ep;
-       struct cpl_abort_rpl *rpl;
        struct sk_buff *rpl_skb;
        struct c4iw_qp_attributes attrs;
        int ret;
        int release = 0;
        unsigned int tid = GET_TID(req);
+       u32 len = roundup(sizeof(struct cpl_abort_rpl), 16);
 
        ep = get_ep_from_tid(dev, tid);
        if (!ep)
@@ -2821,11 +2810,9 @@ static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
                release = 1;
                goto out;
        }
-       set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
-       rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
-       INIT_TP_WR(rpl, ep->hwtid);
-       OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
-       rpl->cmd = CPL_ABORT_NO_RST;
+
+       cxgb_mk_abort_rpl(rpl_skb, len, ep->hwtid, ep->txq_idx);
+
        c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
 out:
        if (release)