IB/ipath: merge ipath_core and ib_ipath drivers
[firefly-linux-kernel-4.4.55.git] / drivers / infiniband / hw / ipath / ipath_layer.c
index 9ec4ac77b87f88df622d5b1d3bc3acf421d3c9b1..acc32200cc0e8a906a32f497b4f34f4dfb63323e 100644 (file)
@@ -1,4 +1,5 @@
 /*
+ * Copyright (c) 2006 QLogic, Inc. All rights reserved.
  * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
 #include <asm/byteorder.h>
 
 #include "ipath_kernel.h"
-#include "ips_common.h"
 #include "ipath_layer.h"
+#include "ipath_verbs.h"
+#include "ipath_common.h"
 
 /* Acquire before ipath_devs_lock. */
 static DEFINE_MUTEX(ipath_layer_mutex);
 
-static int ipath_verbs_registered;
-
 u16 ipath_layer_rcv_opcode;
 
 static int (*layer_intr)(void *, u32);
 static int (*layer_rcv)(void *, void *, struct sk_buff *);
 static int (*layer_rcv_lid)(void *, void *);
-static int (*verbs_piobufavail)(void *);
-static void (*verbs_rcv)(void *, void *, void *, u32);
 
 static void *(*layer_add_one)(int, struct ipath_devdata *);
 static void (*layer_remove_one)(void *);
-static void *(*verbs_add_one)(int, struct ipath_devdata *);
-static void (*verbs_remove_one)(void *);
-static void (*verbs_timer_cb)(void *);
 
 int __ipath_layer_intr(struct ipath_devdata *dd, u32 arg)
 {
@@ -106,29 +101,6 @@ int __ipath_layer_rcv_lid(struct ipath_devdata *dd, void *hdr)
        return ret;
 }
 
-int __ipath_verbs_piobufavail(struct ipath_devdata *dd)
-{
-       int ret = -ENODEV;
-
-       if (dd->verbs_layer.l_arg && verbs_piobufavail)
-               ret = verbs_piobufavail(dd->verbs_layer.l_arg);
-
-       return ret;
-}
-
-int __ipath_verbs_rcv(struct ipath_devdata *dd, void *rc, void *ebuf,
-                     u32 tlen)
-{
-       int ret = -ENODEV;
-
-       if (dd->verbs_layer.l_arg && verbs_rcv) {
-               verbs_rcv(dd->verbs_layer.l_arg, rc, ebuf, tlen);
-               ret = 0;
-       }
-
-       return ret;
-}
-
 int ipath_layer_set_linkstate(struct ipath_devdata *dd, u8 newstate)
 {
        u32 lstate;
@@ -211,8 +183,6 @@ bail:
        return ret;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_set_linkstate);
-
 /**
  * ipath_layer_set_mtu - set the MTU
  * @dd: the infinipath device
@@ -297,11 +267,8 @@ bail:
        return ret;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_set_mtu);
-
-int ipath_set_sps_lid(struct ipath_devdata *dd, u32 arg, u8 lmc)
+int ipath_set_lid(struct ipath_devdata *dd, u32 arg, u8 lmc)
 {
-       ipath_stats.sps_lid[dd->ipath_unit] = arg;
        dd->ipath_lid = arg;
        dd->ipath_lmc = lmc;
 
@@ -315,8 +282,6 @@ int ipath_set_sps_lid(struct ipath_devdata *dd, u32 arg, u8 lmc)
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_set_sps_lid);
-
 int ipath_layer_set_guid(struct ipath_devdata *dd, __be64 guid)
 {
        /* XXX - need to inform anyone who cares this just happened. */
@@ -324,70 +289,56 @@ int ipath_layer_set_guid(struct ipath_devdata *dd, __be64 guid)
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_set_guid);
-
 __be64 ipath_layer_get_guid(struct ipath_devdata *dd)
 {
        return dd->ipath_guid;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_guid);
-
-u32 ipath_layer_get_nguid(struct ipath_devdata *dd)
+u32 ipath_layer_get_majrev(struct ipath_devdata *dd)
 {
-       return dd->ipath_nguid;
+       return dd->ipath_majrev;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_nguid);
-
-int ipath_layer_query_device(struct ipath_devdata *dd, u32 * vendor,
-                            u32 * boardrev, u32 * majrev, u32 * minrev)
+u32 ipath_layer_get_minrev(struct ipath_devdata *dd)
 {
-       *vendor = dd->ipath_vendorid;
-       *boardrev = dd->ipath_boardrev;
-       *majrev = dd->ipath_majrev;
-       *minrev = dd->ipath_minrev;
-
-       return 0;
+       return dd->ipath_minrev;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_query_device);
+u32 ipath_layer_get_pcirev(struct ipath_devdata *dd)
+{
+       return dd->ipath_pcirev;
+}
 
 u32 ipath_layer_get_flags(struct ipath_devdata *dd)
 {
        return dd->ipath_flags;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_flags);
-
 struct device *ipath_layer_get_device(struct ipath_devdata *dd)
 {
        return &dd->pcidev->dev;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_device);
-
 u16 ipath_layer_get_deviceid(struct ipath_devdata *dd)
 {
        return dd->ipath_deviceid;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_deviceid);
+u32 ipath_layer_get_vendorid(struct ipath_devdata *dd)
+{
+       return dd->ipath_vendorid;
+}
 
 u64 ipath_layer_get_lastibcstat(struct ipath_devdata *dd)
 {
        return dd->ipath_lastibcstat;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_lastibcstat);
-
 u32 ipath_layer_get_ibmtu(struct ipath_devdata *dd)
 {
        return dd->ipath_ibmtu;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_ibmtu);
-
 void ipath_layer_add(struct ipath_devdata *dd)
 {
        mutex_lock(&ipath_layer_mutex);
@@ -396,14 +347,10 @@ void ipath_layer_add(struct ipath_devdata *dd)
                dd->ipath_layer.l_arg =
                        layer_add_one(dd->ipath_unit, dd);
 
-       if (verbs_add_one)
-               dd->verbs_layer.l_arg =
-                       verbs_add_one(dd->ipath_unit, dd);
-
        mutex_unlock(&ipath_layer_mutex);
 }
 
-void ipath_layer_del(struct ipath_devdata *dd)
+void ipath_layer_remove(struct ipath_devdata *dd)
 {
        mutex_lock(&ipath_layer_mutex);
 
@@ -412,11 +359,6 @@ void ipath_layer_del(struct ipath_devdata *dd)
                dd->ipath_layer.l_arg = NULL;
        }
 
-       if (dd->verbs_layer.l_arg && verbs_remove_one) {
-               verbs_remove_one(dd->verbs_layer.l_arg);
-               dd->verbs_layer.l_arg = NULL;
-       }
-
        mutex_unlock(&ipath_layer_mutex);
 }
 
@@ -506,95 +448,10 @@ static void __ipath_verbs_timer(unsigned long arg)
                ipath_kreceive(dd);
 
        /* Handle verbs layer timeouts. */
-       if (dd->verbs_layer.l_arg && verbs_timer_cb)
-               verbs_timer_cb(dd->verbs_layer.l_arg);
-
-       mod_timer(&dd->verbs_layer.l_timer, jiffies + 1);
-}
-
-/**
- * ipath_verbs_register - verbs layer registration
- * @l_piobufavail: callback for when PIO buffers become available
- * @l_rcv: callback for receiving a packet
- * @l_timer_cb: timer callback
- * @ipath_devdata: device data structure is put here
- */
-int ipath_verbs_register(void *(*l_add)(int, struct ipath_devdata *),
-                        void (*l_remove)(void *arg),
-                        int (*l_piobufavail) (void *arg),
-                        void (*l_rcv) (void *arg, void *rhdr,
-                                       void *data, u32 tlen),
-                        void (*l_timer_cb) (void *arg))
-{
-       struct ipath_devdata *dd, *tmp;
-       unsigned long flags;
-
-       mutex_lock(&ipath_layer_mutex);
-
-       verbs_add_one = l_add;
-       verbs_remove_one = l_remove;
-       verbs_piobufavail = l_piobufavail;
-       verbs_rcv = l_rcv;
-       verbs_timer_cb = l_timer_cb;
-
-       spin_lock_irqsave(&ipath_devs_lock, flags);
-
-       list_for_each_entry_safe(dd, tmp, &ipath_dev_list, ipath_list) {
-               if (!(dd->ipath_flags & IPATH_INITTED))
-                       continue;
-
-               if (dd->verbs_layer.l_arg)
-                       continue;
-
-               spin_unlock_irqrestore(&ipath_devs_lock, flags);
-               dd->verbs_layer.l_arg = l_add(dd->ipath_unit, dd);
-               spin_lock_irqsave(&ipath_devs_lock, flags);
-       }
-
-       spin_unlock_irqrestore(&ipath_devs_lock, flags);
-       mutex_unlock(&ipath_layer_mutex);
-
-       ipath_verbs_registered = 1;
-
-       return 0;
-}
-
-EXPORT_SYMBOL_GPL(ipath_verbs_register);
-
-void ipath_verbs_unregister(void)
-{
-       struct ipath_devdata *dd, *tmp;
-       unsigned long flags;
-
-       mutex_lock(&ipath_layer_mutex);
-       spin_lock_irqsave(&ipath_devs_lock, flags);
-
-       list_for_each_entry_safe(dd, tmp, &ipath_dev_list, ipath_list) {
-               *dd->ipath_statusp &= ~IPATH_STATUS_OIB_SMA;
-
-               if (dd->verbs_layer.l_arg && verbs_remove_one) {
-                       spin_unlock_irqrestore(&ipath_devs_lock, flags);
-                       verbs_remove_one(dd->verbs_layer.l_arg);
-                       spin_lock_irqsave(&ipath_devs_lock, flags);
-                       dd->verbs_layer.l_arg = NULL;
-               }
-       }
-
-       spin_unlock_irqrestore(&ipath_devs_lock, flags);
-
-       verbs_add_one = NULL;
-       verbs_remove_one = NULL;
-       verbs_piobufavail = NULL;
-       verbs_rcv = NULL;
-       verbs_timer_cb = NULL;
-
-       ipath_verbs_registered = 0;
-
-       mutex_unlock(&ipath_layer_mutex);
+       ipath_ib_timer(dd->verbs_dev);
+       mod_timer(&dd->verbs_timer, jiffies + 1);
 }
 
-EXPORT_SYMBOL_GPL(ipath_verbs_unregister);
-
 int ipath_layer_open(struct ipath_devdata *dd, u32 * pktmax)
 {
        int ret;
@@ -607,7 +464,7 @@ int ipath_layer_open(struct ipath_devdata *dd, u32 * pktmax)
                goto bail;
        }
 
-       ret = ipath_setrcvhdrsize(dd, NUM_OF_EXTRA_WORDS_IN_HEADER_QUEUE);
+       ret = ipath_setrcvhdrsize(dd, IPATH_HEADER_QUEUE_WORDS);
 
        if (ret < 0)
                goto bail;
@@ -616,9 +473,9 @@ int ipath_layer_open(struct ipath_devdata *dd, u32 * pktmax)
 
        if (*dd->ipath_statusp & IPATH_STATUS_IB_READY)
                intval |= IPATH_LAYER_INT_IF_UP;
-       if (ipath_stats.sps_lid[dd->ipath_unit])
+       if (dd->ipath_lid)
                intval |= IPATH_LAYER_INT_LID;
-       if (ipath_stats.sps_mlid[dd->ipath_unit])
+       if (dd->ipath_mlid)
                intval |= IPATH_LAYER_INT_BCAST;
        /*
         * do this on open, in case low level is already up and
@@ -688,8 +545,6 @@ u32 ipath_layer_get_cr_errpkey(struct ipath_devdata *dd)
        return ipath_read_creg32(dd, dd->ipath_cregs->cr_errpkey);
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_cr_errpkey);
-
 static void update_sge(struct ipath_sge_state *ss, u32 length)
 {
        struct ipath_sge *sge = &ss->sge;
@@ -884,7 +739,7 @@ static void copy_io(u32 __iomem *piobuf, struct ipath_sge_state *ss,
 /**
  * ipath_verbs_send - send a packet from the verbs layer
  * @dd: the infinipath device
- * @hdrwords: the number of works in the header
+ * @hdrwords: the number of words in the header
  * @hdr: the packet header
  * @len: the length of the packet in bytes
  * @ss: the SGE to send
@@ -966,8 +821,6 @@ bail:
        return ret;
 }
 
-EXPORT_SYMBOL_GPL(ipath_verbs_send);
-
 int ipath_layer_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
                                  u64 *rwords, u64 *spkts, u64 *rpkts,
                                  u64 *xmit_wait)
@@ -992,8 +845,6 @@ bail:
        return ret;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_snapshot_counters);
-
 /**
  * ipath_layer_get_counters - get various chip counters
  * @dd: the infinipath device
@@ -1016,19 +867,22 @@ int ipath_layer_get_counters(struct ipath_devdata *dd,
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_ibsymbolerrcnt);
        cntrs->link_error_recovery_counter =
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkerrrecovcnt);
+       /*
+        * The link downed counter counts when the other side downs the
+        * connection.  We add in the number of times we downed the link
+        * due to local link integrity errors to compensate.
+        */
        cntrs->link_downed_counter =
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkdowncnt);
        cntrs->port_rcv_errors =
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_rxdroppktcnt) +
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvovflcnt) +
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_portovflcnt) +
-               ipath_snap_cntr(dd, dd->ipath_cregs->cr_errrcvflowctrlcnt) +
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_err_rlencnt) +
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_invalidrlencnt) +
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_erricrccnt) +
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_errvcrccnt) +
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_errlpcrccnt) +
-               ipath_snap_cntr(dd, dd->ipath_cregs->cr_errlinkcnt) +
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_badformatcnt);
        cntrs->port_rcv_remphys_errors =
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvebpcnt);
@@ -1042,6 +896,8 @@ int ipath_layer_get_counters(struct ipath_devdata *dd,
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
        cntrs->port_rcv_packets =
                ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
+       cntrs->local_link_integrity_errors = dd->ipath_lli_errors;
+       cntrs->excessive_buffer_overrun_errors = 0; /* XXX */
 
        ret = 0;
 
@@ -1049,8 +905,6 @@ bail:
        return ret;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_counters);
-
 int ipath_layer_want_buffer(struct ipath_devdata *dd)
 {
        set_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
@@ -1060,8 +914,6 @@ int ipath_layer_want_buffer(struct ipath_devdata *dd)
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_want_buffer);
-
 int ipath_layer_send_hdr(struct ipath_devdata *dd, struct ether_header *hdr)
 {
        int ret = 0;
@@ -1086,10 +938,10 @@ int ipath_layer_send_hdr(struct ipath_devdata *dd, struct ether_header *hdr)
                }
 
        vlsllnh = *((__be16 *) hdr);
-       if (vlsllnh != htons(IPS_LRH_BTH)) {
+       if (vlsllnh != htons(IPATH_LRH_BTH)) {
                ipath_dbg("Warning: lrh[0] wrong (%x, not %x); "
                          "not sending\n", be16_to_cpu(vlsllnh),
-                         IPS_LRH_BTH);
+                         IPATH_LRH_BTH);
                ret = -EINVAL;
        }
        if (ret)
@@ -1154,30 +1006,26 @@ int ipath_layer_enable_timer(struct ipath_devdata *dd)
                                 (u64) (1 << 2));
        }
 
-       init_timer(&dd->verbs_layer.l_timer);
-       dd->verbs_layer.l_timer.function = __ipath_verbs_timer;
-       dd->verbs_layer.l_timer.data = (unsigned long)dd;
-       dd->verbs_layer.l_timer.expires = jiffies + 1;
-       add_timer(&dd->verbs_layer.l_timer);
+       init_timer(&dd->verbs_timer);
+       dd->verbs_timer.function = __ipath_verbs_timer;
+       dd->verbs_timer.data = (unsigned long)dd;
+       dd->verbs_timer.expires = jiffies + 1;
+       add_timer(&dd->verbs_timer);
 
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_enable_timer);
-
 int ipath_layer_disable_timer(struct ipath_devdata *dd)
 {
        /* Disable GPIO bit 2 interrupt */
        if (dd->ipath_flags & IPATH_GPIO_INTR)
                ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask, 0);
 
-       del_timer_sync(&dd->verbs_layer.l_timer);
+       del_timer_sync(&dd->verbs_timer);
 
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_disable_timer);
-
 /**
  * ipath_layer_set_verbs_flags - set the verbs layer flags
  * @dd: the infinipath device
@@ -1205,8 +1053,6 @@ int ipath_layer_set_verbs_flags(struct ipath_devdata *dd, unsigned flags)
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_set_verbs_flags);
-
 /**
  * ipath_layer_get_npkeys - return the size of the PKEY table for port 0
  * @dd: the infinipath device
@@ -1216,8 +1062,6 @@ unsigned ipath_layer_get_npkeys(struct ipath_devdata *dd)
        return ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys);
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_npkeys);
-
 /**
  * ipath_layer_get_pkey - return the indexed PKEY from the port 0 PKEY table
  * @dd: the infinipath device
@@ -1235,8 +1079,6 @@ unsigned ipath_layer_get_pkey(struct ipath_devdata *dd, unsigned index)
        return ret;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_pkey);
-
 /**
  * ipath_layer_get_pkeys - return the PKEY table for port 0
  * @dd: the infinipath device
@@ -1251,8 +1093,6 @@ int ipath_layer_get_pkeys(struct ipath_devdata *dd, u16 * pkeys)
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_pkeys);
-
 /**
  * rm_pkey - decrecment the reference count for the given PKEY
  * @dd: the infinipath device
@@ -1399,8 +1239,6 @@ int ipath_layer_set_pkeys(struct ipath_devdata *dd, u16 * pkeys)
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_set_pkeys);
-
 /**
  * ipath_layer_get_linkdowndefaultstate - get the default linkdown state
  * @dd: the infinipath device
@@ -1412,8 +1250,6 @@ int ipath_layer_get_linkdowndefaultstate(struct ipath_devdata *dd)
        return !!(dd->ipath_ibcctrl & INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE);
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_linkdowndefaultstate);
-
 /**
  * ipath_layer_set_linkdowndefaultstate - set the default linkdown state
  * @dd: the infinipath device
@@ -1433,8 +1269,6 @@ int ipath_layer_set_linkdowndefaultstate(struct ipath_devdata *dd,
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_set_linkdowndefaultstate);
-
 int ipath_layer_get_phyerrthreshold(struct ipath_devdata *dd)
 {
        return (dd->ipath_ibcctrl >>
@@ -1442,8 +1276,6 @@ int ipath_layer_get_phyerrthreshold(struct ipath_devdata *dd)
                INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_phyerrthreshold);
-
 /**
  * ipath_layer_set_phyerrthreshold - set the physical error threshold
  * @dd: the infinipath device
@@ -1469,8 +1301,6 @@ int ipath_layer_set_phyerrthreshold(struct ipath_devdata *dd, unsigned n)
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_set_phyerrthreshold);
-
 int ipath_layer_get_overrunthreshold(struct ipath_devdata *dd)
 {
        return (dd->ipath_ibcctrl >>
@@ -1478,8 +1308,6 @@ int ipath_layer_get_overrunthreshold(struct ipath_devdata *dd)
                INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_get_overrunthreshold);
-
 /**
  * ipath_layer_set_overrunthreshold - set the overrun threshold
  * @dd: the infinipath device
@@ -1505,17 +1333,13 @@ int ipath_layer_set_overrunthreshold(struct ipath_devdata *dd, unsigned n)
        return 0;
 }
 
-EXPORT_SYMBOL_GPL(ipath_layer_set_overrunthreshold);
-
 int ipath_layer_get_boardname(struct ipath_devdata *dd, char *name,
                              size_t namelen)
 {
        return dd->ipath_f_get_boardname(dd, name, namelen);
 }
-EXPORT_SYMBOL_GPL(ipath_layer_get_boardname);
 
 u32 ipath_layer_get_rcvhdrentsize(struct ipath_devdata *dd)
 {
        return dd->ipath_rcvhdrentsize;
 }
-EXPORT_SYMBOL_GPL(ipath_layer_get_rcvhdrentsize);