staging/rdma/hfi1: diag.c add missing braces
[deliverable/linux.git] / drivers / staging / rdma / hfi1 / diag.c
index 88414d720469f17599b6e98766496529fc1f9a0f..ed9cfccc860b4b23a384f7e568a2dc5f3a434f67 100644 (file)
@@ -78,8 +78,8 @@
        hfi1_cdbg(SNOOP, fmt, ##__VA_ARGS__)
 
 /* Snoop option mask */
-#define SNOOP_DROP_SEND        (1 << 0)
-#define SNOOP_USE_METADATA     (1 << 1)
+#define SNOOP_DROP_SEND                BIT(0)
+#define SNOOP_USE_METADATA     BIT(1)
 
 static u8 snoop_flags;
 
@@ -135,7 +135,7 @@ static struct cdev diagpkt_cdev;
 static struct device *diagpkt_device;
 
 static ssize_t diagpkt_write(struct file *fp, const char __user *data,
-                                size_t count, loff_t *off);
+                            size_t count, loff_t *off);
 
 static const struct file_operations diagpkt_file_ops = {
        .owner = THIS_MODULE,
@@ -177,37 +177,37 @@ struct hfi1_link_info {
 #define HFI1_SNOOP_IOCGETLINKSTATE \
        _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ)
 #define HFI1_SNOOP_IOCSETLINKSTATE \
-       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+1)
+       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 1)
 #define HFI1_SNOOP_IOCCLEARQUEUE \
-       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+2)
+       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 2)
 #define HFI1_SNOOP_IOCCLEARFILTER \
-       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+3)
+       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 3)
 #define HFI1_SNOOP_IOCSETFILTER \
-       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+4)
+       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 4)
 #define HFI1_SNOOP_IOCGETVERSION \
-       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+5)
+       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 5)
 #define HFI1_SNOOP_IOCSET_OPTS \
-       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+6)
+       _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 6)
 
 /*
  * These offsets +6/+7 could change, but these are already known and used
  * IOCTL numbers so don't change them without a good reason.
  */
 #define HFI1_SNOOP_IOCGETLINKSTATE_EXTRA \
-       _IOWR(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+6, \
+       _IOWR(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 6, \
                struct hfi1_link_info)
 #define HFI1_SNOOP_IOCSETLINKSTATE_EXTRA \
-       _IOWR(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ+7, \
+       _IOWR(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 7, \
                struct hfi1_link_info)
 
 static int hfi1_snoop_open(struct inode *in, struct file *fp);
 static ssize_t hfi1_snoop_read(struct file *fp, char __user *data,
-                               size_t pkt_len, loff_t *off);
+                              size_t pkt_len, loff_t *off);
 static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data,
-                                size_t count, loff_t *off);
+                               size_t count, loff_t *off);
 static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
 static unsigned int hfi1_snoop_poll(struct file *fp,
-                                       struct poll_table_struct *wait);
+                                   struct poll_table_struct *wait);
 static int hfi1_snoop_release(struct inode *in, struct file *fp);
 
 struct hfi1_packet_filter_command {
@@ -323,14 +323,12 @@ static void hfi1_snoop_remove(struct hfi1_devdata *dd)
 
 void hfi1_diag_remove(struct hfi1_devdata *dd)
 {
-
        hfi1_snoop_remove(dd);
        if (atomic_dec_and_test(&diagpkt_count))
                hfi1_cdev_cleanup(&diagpkt_cdev, &diagpkt_device);
        hfi1_cdev_cleanup(&dd->diag_cdev, &dd->diag_device);
 }
 
-
 /*
  * Allocated structure shared between the credit return mechanism and
  * diagpkt_send().
@@ -379,6 +377,7 @@ static ssize_t diagpkt_send(struct diag_pkt *dp)
        pio_release_cb credit_cb = NULL;
        void *credit_arg = NULL;
        struct diagpkt_wait *wait = NULL;
+       int trycount = 0;
 
        dd = hfi1_lookup(dp->unit);
        if (!dd || !(dd->flags & HFI1_PRESENT) || !dd->kregbase) {
@@ -393,7 +392,7 @@ static ssize_t diagpkt_send(struct diag_pkt *dp)
 
        if (dp->version != _DIAG_PKT_VERS) {
                dd_dev_err(dd, "Invalid version %u for diagpkt_write\n",
-                           dp->version);
+                          dp->version);
                ret = -EINVAL;
                goto bail;
        }
@@ -440,7 +439,7 @@ static ssize_t diagpkt_send(struct diag_pkt *dp)
        }
 
        if (copy_from_user(tmpbuf,
-                          (const void __user *) (unsigned long) dp->data,
+                          (const void __user *)(unsigned long)dp->data,
                           dp->len)) {
                ret = -EFAULT;
                goto bail;
@@ -493,8 +492,15 @@ static ssize_t diagpkt_send(struct diag_pkt *dp)
                credit_arg = wait;
        }
 
+retry:
        pbuf = sc_buffer_alloc(sc, total_len, credit_cb, credit_arg);
        if (!pbuf) {
+               if (trycount == 0) {
+                       /* force a credit return and try again */
+                       sc_return_credits(sc);
+                       trycount = 1;
+                       goto retry;
+               }
                /*
                 * No send buffer means no credit callback.  Undo
                 * the wait set-up that was done above.  We free wait
@@ -530,9 +536,9 @@ static ssize_t diagpkt_send(struct diag_pkt *dp)
                 * NOTE: PRC_FILL_ERR is at best informational and cannot
                 * be depended on.
                 */
-               if (!ret && (((wait->code & PRC_STATUS_ERR)
-                               || (wait->code & PRC_FILL_ERR)
-                               || (wait->code & PRC_SC_DISABLE))))
+               if (!ret && (((wait->code & PRC_STATUS_ERR) ||
+                             (wait->code & PRC_FILL_ERR) ||
+                             (wait->code & PRC_SC_DISABLE))))
                        ret = -EIO;
 
                put_diagpkt_wait(wait); /* finished with the structure */
@@ -545,7 +551,7 @@ bail:
 }
 
 static ssize_t diagpkt_write(struct file *fp, const char __user *data,
-                                size_t count, loff_t *off)
+                            size_t count, loff_t *off)
 {
        struct hfi1_devdata *dd;
        struct send_context *sc;
@@ -565,7 +571,7 @@ static ssize_t diagpkt_write(struct file *fp, const char __user *data,
        */
        if (dp.pbc) {
                dd = hfi1_lookup(dp.unit);
-               if (dd == NULL)
+               if (!dd)
                        return -ENODEV;
                vl = (dp.pbc >> PBC_VL_SHIFT) & PBC_VL_MASK;
                sc = dd->vld[vl].sc;
@@ -598,7 +604,7 @@ static int hfi1_snoop_add(struct hfi1_devdata *dd, const char *name)
        if (ret) {
                dd_dev_err(dd, "Couldn't create %s device: %d", name, ret);
                hfi1_cdev_cleanup(&dd->hfi1_snoop.cdev,
-                                &dd->hfi1_snoop.class_dev);
+                                 &dd->hfi1_snoop.class_dev);
        }
 
        return ret;
@@ -611,7 +617,6 @@ static struct hfi1_devdata *hfi1_dd_from_sc_inode(struct inode *in)
 
        dd = hfi1_lookup(unit);
        return dd;
-
 }
 
 /* clear or restore send context integrity checks */
@@ -652,7 +657,7 @@ static int hfi1_snoop_open(struct inode *in, struct file *fp)
        mutex_lock(&hfi1_mutex);
 
        dd = hfi1_dd_from_sc_inode(in);
-       if (dd == NULL) {
+       if (!dd) {
                ret = -ENODEV;
                goto bail;
        }
@@ -739,7 +744,7 @@ static int hfi1_snoop_release(struct inode *in, struct file *fp)
        int mode_flag;
 
        dd = hfi1_dd_from_sc_inode(in);
-       if (dd == NULL)
+       if (!dd)
                return -ENODEV;
 
        spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags);
@@ -794,7 +799,7 @@ static unsigned int hfi1_snoop_poll(struct file *fp,
        struct hfi1_devdata *dd;
 
        dd = hfi1_dd_from_sc_inode(fp->f_inode);
-       if (dd == NULL)
+       if (!dd)
                return -ENODEV;
 
        spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags);
@@ -805,7 +810,6 @@ static unsigned int hfi1_snoop_poll(struct file *fp,
 
        spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags);
        return ret;
-
 }
 
 static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data,
@@ -822,7 +826,7 @@ static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data,
        struct hfi1_pportdata *ppd;
 
        dd = hfi1_dd_from_sc_inode(fp->f_inode);
-       if (dd == NULL)
+       if (!dd)
                return -ENODEV;
 
        ppd = dd->pport;
@@ -847,7 +851,7 @@ static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data,
                if (copy_from_user(&byte_one, data, 1))
                        return -EINVAL;
 
-               if (copy_from_user(&byte_two, data+1, 1))
+               if (copy_from_user(&byte_two, data + 1, 1))
                        return -EINVAL;
 
                sc4 = (byte_one >> 4) & 0xf;
@@ -920,7 +924,7 @@ static ssize_t hfi1_snoop_read(struct file *fp, char __user *data,
        struct hfi1_devdata *dd;
 
        dd = hfi1_dd_from_sc_inode(fp->f_inode);
-       if (dd == NULL)
+       if (!dd)
                return -ENODEV;
 
        spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags);
@@ -946,16 +950,18 @@ static ssize_t hfi1_snoop_read(struct file *fp, char __user *data,
                spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags);
                if (pkt_len >= packet->total_len) {
                        if (copy_to_user(data, packet->data,
-                               packet->total_len))
+                                        packet->total_len))
                                ret = -EFAULT;
                        else
                                ret = packet->total_len;
-               } else
+               } else {
                        ret = -EINVAL;
+               }
 
                kfree(packet);
-       } else
+       } else {
                spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags);
+       }
 
        return ret;
 }
@@ -978,7 +984,7 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
        struct hfi1_link_info link_info;
 
        dd = hfi1_dd_from_sc_inode(fp->f_inode);
-       if (dd == NULL)
+       if (!dd)
                return -ENODEV;
 
        spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags);
@@ -1321,7 +1327,6 @@ static int hfi1_filter_mad_mgmt_class(void *ibhdr, void *packet_data,
 
 static int hfi1_filter_qp_number(void *ibhdr, void *packet_data, void *value)
 {
-
        struct hfi1_ib_header *hdr;
        struct hfi1_other_headers *ohdr = NULL;
        int ret;
@@ -1404,7 +1409,6 @@ static int hfi1_filter_ib_service_level(void *ibhdr, void *packet_data,
 
 static int hfi1_filter_ib_pkey(void *ibhdr, void *packet_data, void *value)
 {
-
        u32 lnh = 0;
        struct hfi1_ib_header *hdr;
        struct hfi1_other_headers *ohdr = NULL;
@@ -1476,7 +1480,6 @@ static struct snoop_packet *allocate_snoop_packet(u32 hdr_len,
                                                  u32 data_len,
                                                  u32 md_len)
 {
-
        struct snoop_packet *packet;
 
        packet = kzalloc(sizeof(struct snoop_packet) + hdr_len + data_len
@@ -1485,7 +1488,6 @@ static struct snoop_packet *allocate_snoop_packet(u32 hdr_len,
        if (likely(packet))
                INIT_LIST_HEAD(&packet->list);
 
-
        return packet;
 }
 
@@ -1542,12 +1544,11 @@ int snoop_recv_handler(struct hfi1_packet *packet)
                    unlikely(snoop_flags & SNOOP_USE_METADATA))
                        md_len = sizeof(struct capture_md);
 
-
                s_packet = allocate_snoop_packet(header_size,
                                                 tlen - header_size,
                                                 md_len);
 
-               if (unlikely(s_packet == NULL)) {
+               if (unlikely(!s_packet)) {
                        dd_dev_warn_ratelimited(ppd->dd, "Unable to allocate snoop/capture packet\n");
                        break;
                }
@@ -1618,14 +1619,12 @@ int snoop_recv_handler(struct hfi1_packet *packet)
 /*
  * Handle snooping and capturing packets when sdma is being used.
  */
-int snoop_send_dma_handler(struct hfi1_qp *qp, struct ahg_ib_header *ibhdr,
-                          u32 hdrwords, struct hfi1_sge_state *ss, u32 len,
-                          u32 plen, u32 dwords, u64 pbc)
+int snoop_send_dma_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
+                          u64 pbc)
 {
-       pr_alert("Snooping/Capture of  Send DMA Packets Is Not Supported!\n");
+       pr_alert("Snooping/Capture of Send DMA Packets Is Not Supported!\n");
        snoop_dbg("Unsupported Operation");
-       return hfi1_verbs_send_dma(qp, ibhdr, hdrwords, ss, len, plen, dwords,
-                                 0);
+       return hfi1_verbs_send_dma(qp, ps, 0);
 }
 
 /*
@@ -1633,12 +1632,16 @@ int snoop_send_dma_handler(struct hfi1_qp *qp, struct ahg_ib_header *ibhdr,
  * bypass packets. The only way to send a bypass packet currently is to use the
  * diagpkt interface. When that interface is enable snoop/capture is not.
  */
-int snoop_send_pio_handler(struct hfi1_qp *qp, struct ahg_ib_header *ahdr,
-                          u32 hdrwords, struct hfi1_sge_state *ss, u32 len,
-                          u32 plen, u32 dwords, u64 pbc)
+int snoop_send_pio_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
+                          u64 pbc)
 {
-       struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
-       struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
+       struct ahg_ib_header *ahdr = qp->s_hdr;
+       u32 hdrwords = qp->s_hdrwords;
+       struct hfi1_sge_state *ss = qp->s_cur_sge;
+       u32 len = qp->s_cur_size;
+       u32 dwords = (len + 3) >> 2;
+       u32 plen = hdrwords + dwords + 2; /* includes pbc */
+       struct hfi1_pportdata *ppd = ps->ppd;
        struct snoop_packet *s_packet = NULL;
        u32 *hdr = (u32 *)&ahdr->ibh;
        u32 length = 0;
@@ -1666,7 +1669,7 @@ int snoop_send_pio_handler(struct hfi1_qp *qp, struct ahg_ib_header *ahdr,
        /* not using ss->total_len as arg 2 b/c that does not count CRC */
        s_packet = allocate_snoop_packet(hdr_len, tlen - hdr_len, md_len);
 
-       if (unlikely(s_packet == NULL)) {
+       if (unlikely(!s_packet)) {
                dd_dev_warn_ratelimited(ppd->dd, "Unable to allocate snoop/capture packet\n");
                goto out;
        }
@@ -1783,8 +1786,7 @@ int snoop_send_pio_handler(struct hfi1_qp *qp, struct ahg_ib_header *ahdr,
                break;
        }
 out:
-       return hfi1_verbs_send_pio(qp, ahdr, hdrwords, ss, len, plen, dwords,
-                                 md.u.pbc);
+       return hfi1_verbs_send_pio(qp, ps, md.u.pbc);
 }
 
 /*
@@ -1836,7 +1838,7 @@ void snoop_inline_pio_send(struct hfi1_devdata *dd, struct pio_buf *pbuf,
 
                s_packet = allocate_snoop_packet(packet_len, 0, md_len);
 
-               if (unlikely(s_packet == NULL)) {
+               if (unlikely(!s_packet)) {
                        dd_dev_warn_ratelimited(dd, "Unable to allocate snoop/capture packet\n");
                        goto inline_pio_out;
                }
@@ -1868,5 +1870,4 @@ void snoop_inline_pio_send(struct hfi1_devdata *dd, struct pio_buf *pbuf,
 
 inline_pio_out:
        pio_copy(dd, pbuf, pbc, from, count);
-
 }
This page took 0.030393 seconds and 5 git commands to generate.