Re: [PATCH 08/11] IB/cma: Add net_dev and private data checks to RDMA CM

2015-06-17 Thread Jason Gunthorpe
On Tue, Jun 16, 2015 at 08:26:26AM +0300, Haggai Eran wrote:
> On 15/06/2015 20:08, Jason Gunthorpe wrote:
> > On Mon, Jun 15, 2015 at 11:47:13AM +0300, Haggai Eran wrote:
> >> Instead of relying on a the ib_cm module to check an incoming CM request's
> >> private data header, add these checks to the RDMA CM module. This allows a
> >> following patch to to clean up the ib_cm interface and remove the code that
> >> looks into the private headers. It will also allow supporting namespaces in
> >> RDMA CM by making these checks namespace aware later on.
> > 
> > I was expecting one of these patches to flow the net_device from here:
> > 
> >> +static struct net_device *cma_get_net_dev(struct ib_cm_event *ib_event,
> >> +const struct cma_req_info *req)
> >> +{
> > 
> > Down through cma_req_handler and cma_new_conn_id so that we get rid of
> > the cma_translate_addr on the ingress side.
> > 
> > Having the ingress side use one ingress net_device for all processing
> > seems very important to me...
> 
> Is it really very important? I thought the bound_dev_if of a passive
> connection id is only used by the netlink statistics mechanism.

I mean 'very important' in the sense it makes the RDMA-CM *make
logical sense*, not so much in the 'can user space tell'.

So yes, cleaning this seems very important to establish that logical
narrative of how the packet flows through this code.

Plus, there is an init_net in the cma_translate_addr path that needs to
be addressed - so purging cma_translate_addr is a great way to handle
that. That would leave only the call in rdma_bind_addr, and for bind,
the process net namespace is the correct thing to use.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 04/11] IB/cm: Expose DGID in SIDR request events

2015-06-17 Thread Jason Gunthorpe
On Tue, Jun 16, 2015 at 02:25:07PM +0300, Haggai Eran wrote:

> > But how is that going to work? How is the sender to know it should be
> > sending a GRH with the CM message?
> 
> If the admin wants to use SIDR with alias GIDs, they will need to
> configure the system to enable GRH for such GMPs. (This series doesn't
> include such a patch).

Gross.

> Regarding APM, currently the ib_cm code always sends the GMP to the
> primary path anyway, right? And in any case, one would expect the
> primary path's GID to have a valid net_device and local routing rules,
> so I think for the purpose of demuxing and validating the request using
> the primary path should be fine.

The current code works that way, but it is not what I'd expect
generally.

For instance, future APM support will be able to drive dual-rail and
policy will decide which rail is the current best rail for data
transfer. So the GMP may be directed to the IPoIB device with port 1,
but the data transfer may happen on the RDMA port 2. [Note, I already
have very rough patches that do this de-coupling]

> Why do you think the GMP's net_device should be used over the one of the
> future RDMA channel?

The code needs to match the incoming GMP with the logical netdev that
rx's *that GMP*. The fact that goes on to setup an RDMA channel is not
relevant, the nature of the future RDMA channel should not impact how
the GMP is recieved.

> So far we can work without GRH for CM requests, and also without GRH for
> SIDR requests if we rely on layer 3 for the interface resolution. I'm
> not against adding a LLADDR to the protocol somehow, but I don't think
> we should abandon all these use cases and the interoperability with
> existing software.

Well, there is a middle ground. Lets say we get the LLADDR in the GMP
somehow, then we get 100% correct operation when it is present.

For degraded operation we have the (device,port,pkey) and possibly
(device,port,pkey,gid) if there was a GRH. We also have the IP address
hack.

So, I'd say, search in this sequence:
 - If the LLADDR is present, just find the right netdev
 - Otherwise search for (device,port,pkey) / (device,port,pkey,gid)
   If there is only one match then that is unambiguously the correct
   device to use.
 - Repeat the above search, but add the IP address. This is the hack
   we perform for compatibility.

There is no reason to hackily look at the GMP path parameters if we are
relying on #3 above as the hack to save us in the legacy ambiguous case.

.. and to answer your question in the other email, I think we should
keep the hack clearly distinct from the proper operation (in fact,
perhaps it should be user configurable). So #3 should be a distinct
step taken when all else fails, not integrated into earlier steps.

So, this series as it stands just needs to do #2/#3 above and you guys
can figure out the LLADDR business later.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/41] IB/hfi1: add char device instantiation code

2015-06-17 Thread Jason Gunthorpe
On Wed, Jun 17, 2015 at 12:05:08PM +, Marciniszyn, Mike wrote:

> Jason, what is your take on ioctl vs. write.

Well, I think the global view keeps changing, so I'm not sure what is
trendy now..

But personally, I hate seeing write() used to emulate ioctl() because
'ioctl is bad'. ie if you are 'writing' a struct that contains user
pointers and you expect the kernel to read/write to user memory, then
use ioctl. (and that is the 'badness' of ioctl, so pretending it is
write doesn't help anything)

If you can formulate your communication like netlink does, where it is
more like a network RPC, where *everything* is in the buffer passed
to write and you have to call read to get a reply, then use
read/write. This is generally considered preferable, and is what
people mean when they say write is preferred. As I understand
it.

netlink is a reasonable low speed format to use for this kind of
serialization, either via the common mux or via your own char device.

I also wonder about all those sysfs files. I think the over reliance
on sysfs in rdma may have been a mistake, sending the same information
over netlink would be more consistent with what netdev is doing. (eg
you can't view the netdev IP addresses via sysfs, but you can view
rdma guids via sysfs)

Overall, I'd be alot happier with your driver patchset if it was split
as 'core only, no UAPI changes' followed up by 'Add UAPI for X'.

If you can't make a verbs provider work under 'core only' then I think
something is very wrong...

UAPI stuff in drivers is often a red flag, and you guys should think
really carefully about what OPA elements should be buried in the
driver and what elements should be common to all OPA adapters.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH 00/41] Add OPA gen1 driver

2015-06-17 Thread Hefty, Sean
> Ummm.. Could we get some more descriptions as to what this code is for?
> 
> Do we have a new OmniPath protocol here as well or is it IB? Which
> standards are followed?
> 
> I think the APIs that the driver uses need to be documented somewhere in
> particular if new sysfs entries etc are created.
> 
> Are there any user space tools to control/exercise the driver and the
> protocol stack?

Christoph's questions are fair.  There should at least be a short write-up that 
describes how this driver fits into the RDMA stack.  (Maybe there are links 
with additional details that could be provided?)  For example, we know from 
Ira's patches and comments that OPA uses IB like management and supports the 
same verbs as the qib driver.  It's hard to piece this together from separate 
email threads or by looking at 56,000 lines of code.  I'm less concerned about 
the PSM support myself, as that's self-contained to this driver and doesn't 
impact the rest of the stack.  But at least clarify how it relates to other 
kernel modules (ib_cm, rdma_cm, ipoib, etc.), if at all.

- Sean

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 39/49] IB/hfi1: add sysfs routines

2015-06-17 Thread Or Gerlitz
On Wed, Jun 17, 2015 at 2:48 PM, Marciniszyn, Mike
 wrote:
>> what's SC and what's SC-to-VL? aren't you using SM to do such mappings? if 
>> this
>> and the below sysfs work-around/s for the maybe current lack of SM to
>> configure the port? why do the upstream kernel has to carry ~hundreds of 
>> sysfs
>> entries forever for such non-documented things?

> This sysfs entries are used by PSM2 to form packets from user space.

You didn't explain what's SC and what's SC-to-VL and why PSM2 can't
talk to the SM to query that.

>> >> +HFI1_SL2SC_ATTR(0);
>>
>> same comment on SL2SC

same response as the above

>> >> +HFI1_VL2MTU_ATTR(0);

>> same comment on VL2MTU, why in sysfs?!

> Same answer.

same response as the above

Or.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v2 01/49] IB/core: Add OPA Port header definitions

2015-06-17 Thread Hefty, Sean
> >>>  include/rdma/opa_port_info.h  |  433
> >>
> >> This matches the current code structure, but is this the best location
> for this file?
> >
> > Do you have a suggestion?
> 
> Couldn't it be a header in the hfi1 driver directory ? Isn't it OPA
> specific ?

I don't have a specific suggestion.  If the contents are specific to this 
driver, I would move them into the driver directory.  For values that are OPA, 
but not driver, specific, include/rdma is probably the best option for now.  If 
the content is mixed (I didn't look closely), I would split the file.


RE: [PATCH 06/41] IB/hfi1: add char device instantiation code

2015-06-17 Thread Hefty, Sean
> PSM2 (and PSM) uses this to dialog with the driver for hardware specific
> setup.
> 
> I'm suspected at some point in the past, this was ioctl based and changed
> due to bias against ioctl.

Could this be distinguished based on a common command header?
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] libibverbs init.c: conditionally emit warning if no userspace driver found

2015-06-17 Thread Doug Ledford

> On Jun 16, 2015, at 10:25 AM, Jeff Squyres (jsquyres)  
> wrote:
> 
> Ping.
> 
> This is just a periodic query to see if there has been any progress on 
> accepting this patch into libibverbs.

The patch is accepted, I just haven’t pushed it out yet.

> 
> 
>> On Jun 3, 2015, at 12:50 PM, Doug Ledford  wrote:
>> 
>> On Mon, 2015-06-01 at 22:02 +, Jeff Squyres (jsquyres) wrote:
>>> On May 22, 2015, at 9:44 AM, Doug Ledford  wrote:
 
> Did that happen yet?
 
 I don't think so.  I didn't file a specific ticket for it at k.o yet
 (the k.o tickets take a while to process, so I didn't want to file it
 until after the comment period here on list).
>>> 
>>> Ping.
>>> 
>>> This is just a periodic query to see if there has been any progress on 
>>> accepting this patch into libibverbs.
>>> 
>> 
>> I have a ticket with kernel.org helpdesk to change the permissions on
>> the libibverbs.git repo, and they are waiting on Roland to ACK the
>> change.  Until then, I can't do much.
>> 
>> --
>> Doug Ledford 
>> GPG KeyID: 0E572FDD
>> 
> 
> 
> --
> Jeff Squyres
> jsquy...@cisco.com
> For corporate legal information go to: 
> http://www.cisco.com/web/about/doing_business/legal/cri/
> 

—
Doug Ledford 
GPG Key ID: 0E572FDD







signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [PATCH v3 01/49] IB/core: Add header definitions

2015-06-17 Thread Hal Rosenstock
On 6/17/2015 8:28 AM, Mike Marciniszyn wrote:
> From: Ira Weiny 
> 
> Add common OPA header definitions for driver
> build:
> - opa_port_info.h
> - opa_smi.h
> - hfi1_user.sh
> 
> Additionally, ib_mad.h, has additional definitions
> that are common to ib_drivers including:
> - trap support
> - cca support
> 
> The qib driver has the duplication removed in favor
> those in ib_mad.h
> 
> Reviewed-by: Mike Marciniszyn 
> Reviewed-by: John, Jubin 
> Signed-off-by: Ira Weiny 
> ---
>  drivers/infiniband/hw/qib/qib_mad.h |  147 +---
>  include/rdma/ib_mad.h   |  138 +++
>  include/rdma/opa_port_info.h|  433 
> +++

Should opa_port_info.h be in include/rdma or in drivers/infiniband/hw/hfi1 ?

>  include/rdma/opa_smi.h  |   47 
>  include/uapi/rdma/hfi/hfi1_user.h   |  427 
> +++
>  5 files changed, 1053 insertions(+), 139 deletions(-)
>  create mode 100644 include/rdma/opa_port_info.h
>  create mode 100644 include/uapi/rdma/hfi/hfi1_user.h
> 
> diff --git a/drivers/infiniband/hw/qib/qib_mad.h 
> b/drivers/infiniband/hw/qib/qib_mad.h
> index 941d4d5..57e99dc 100644
> --- a/drivers/infiniband/hw/qib/qib_mad.h
> +++ b/drivers/infiniband/hw/qib/qib_mad.h
> @@ -36,148 +36,17 @@
>  
>  #include 
>  
> -#define IB_SMP_UNSUP_VERSIONcpu_to_be16(0x0004)
> -#define IB_SMP_UNSUP_METHOD cpu_to_be16(0x0008)
> -#define IB_SMP_UNSUP_METH_ATTR  cpu_to_be16(0x000C)
> -#define IB_SMP_INVALID_FIELDcpu_to_be16(0x001C)
> +#define IB_SMP_UNSUP_VERSION \
> +cpu_to_be16(IB_MGMT_MAD_STATUS_BAD_VERSION)
>  
> -struct ib_node_info {
> - u8 base_version;
> - u8 class_version;
> - u8 node_type;
> - u8 num_ports;
> - __be64 sys_guid;
> - __be64 node_guid;
> - __be64 port_guid;
> - __be16 partition_cap;
> - __be16 device_id;
> - __be32 revision;
> - u8 local_port_num;
> - u8 vendor_id[3];
> -} __packed;
> -
> -struct ib_mad_notice_attr {
> - u8 generic_type;
> - u8 prod_type_msb;
> - __be16 prod_type_lsb;
> - __be16 trap_num;
> - __be16 issuer_lid;
> - __be16 toggle_count;
> -
> - union {
> - struct {
> - u8  details[54];
> - } raw_data;
> -
> - struct {
> - __be16  reserved;
> - __be16  lid;/* where violation happened */
> - u8  port_num;   /* where violation happened */
> - } __packed ntc_129_131;
> -
> - struct {
> - __be16  reserved;
> - __be16  lid;/* LID where change occurred */
> - u8  reserved2;
> - u8  local_changes;  /* low bit - local changes */
> - __be32  new_cap_mask;   /* new capability mask */
> - u8  reserved3;
> - u8  change_flags;   /* low 3 bits only */
> - } __packed ntc_144;
> -
> - struct {
> - __be16  reserved;
> - __be16  lid;/* lid where sys guid changed */
> - __be16  reserved2;
> - __be64  new_sys_guid;
> - } __packed ntc_145;
> -
> - struct {
> - __be16  reserved;
> - __be16  lid;
> - __be16  dr_slid;
> - u8  method;
> - u8  reserved2;
> - __be16  attr_id;
> - __be32  attr_mod;
> - __be64  mkey;
> - u8  reserved3;
> - u8  dr_trunc_hop;
> - u8  dr_rtn_path[30];
> - } __packed ntc_256;
> -
> - struct {
> - __be16  reserved;
> - __be16  lid1;
> - __be16  lid2;
> - __be32  key;
> - __be32  sl_qp1; /* SL: high 4 bits */
> - __be32  qp2;/* high 8 bits reserved */
> - union ib_gidgid1;
> - union ib_gidgid2;
> - } __packed ntc_257_258;
> -
> - } details;
> -};
> -
> -/*
> - * Generic trap/notice types
> - */
> -#define IB_NOTICE_TYPE_FATAL 0x80
> -#define IB_NOTICE_TYPE_URGENT0x81
> -#define IB_NOTICE_TYPE_SECURITY  0x82
> -#define IB_NOTICE_TYPE_SM0x83
> -#define IB_NOTICE_TYPE_INFO  0x84
> +#define IB_SMP_UNSUP_METHOD \
> +cpu_to_be16(IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD)
>  
> -/*
> - * Generic trap/notice producers
> - */
> -#define IB_NOTICE_PROD_CAcpu_to_be16(1)
> -#define IB_NOTICE_PROD_SWITCHcpu_to_be16(2)
> -#define IB_NOTICE_PROD_ROUTERcpu_to_be16(3)
> -#define IB_NOTICE_PROD_CLASS_MGR cpu_to_be16

RE: [PATCH 14/14] IB/mad: Add final OPA MAD processing

2015-06-17 Thread Weiny, Ira
> 
> ib_verbs define an *extensive* direct HW access API, which is constantly
> evolving.

This is the problem with verbs...

> You cannot describe the intricate object relations and semantics through an
> API.
> In addition, you can't abstract anything or fix stuff in SW.
> The only way to *truly* know what to expect when performing Verbs calls is to
> check the node type.

How can you say this?

mthca, mlx4, mlx5, and qib all have different sets of functionality... all with 
the same node type.  OPA has the same set as qib...  same node type.

> 
> ib_verbs was never only an API. It started as the Linux implementation of the
> IBTA standard, with guaranteed semantics and wire protocol.
> Later, the interface was reused to support additional RDMA devices. However,
> you could *always* check the node type if you wanted to, thereby retaining the
> standard guarantees. Win-win situation...

Not true at all.  For example, Qib does not support XRC and yet has the same 
node type as mlx4 (5)...

> 
> This is a very strong property; we should not give up on it.

On the contrary the property is weak and implies functionality or lack of 
functionality rather than being explicit.  This was done because getting 
changes to kernel ABIs was hard and we took a shortcut with node type which we 
should not have.  OPA attempts to stop this madness and supports the 
functionality of verbs _As_ _Defined_ rather than creating yet another set of 
things which applications need to check against.

> 
> >
> > You're right that apps can be coded to other CA types, like RNICs and
> > USNICs.  However, those are all very different from an IB_CA due to
> > limited queue pair types or limited primitives.  If OPA had that same
> > limitation then I would agree it needs a different node type.
> >
> 
> How do you know that it doesn't?

Up until now you have had to take my word for it.  Now that the driver has been 
posted it should be clear what verbs we support (same as qib).

Ira



RE: [PATCH 36/41] IB/hfi1: add low level page locking

2015-06-17 Thread Marciniszyn, Mike
> > + * hfi1_get_user_pages - lock user pages into memory
> > + * @start_page: the start page
> > + * @num_pages: the number of pages
> > + * @p: the output page structures
> > + *
> > + * This function takes a given start page (page aligned user virtual
> > + * address) and pins it and the following specified number of pages.
> > +For
> > + * now, num_pages is always 1, but that will probably change at some
> > +point
> > + * (because caller is doing expected sends on a single virtually
> > +contiguous
> > + * buffer, so we can do all pages at once).
> > + */
> > +int hfi1_get_user_pages(unsigned long start_page, size_t num_pages,
> > +   struct page **p) {
> > +   int ret;
> > +
> > +   down_write(¤t->mm->mmap_sem);
> > +
> > +   ret = __hfi1_get_user_pages(start_page, num_pages, p);
> > +
> > +   up_write(¤t->mm->mmap_sem);
> > +
> > +   return ret;
> > +}
> > +
> 
> anything wrong with the umem services provided by the IB core that
> requires this implementation? what?
> 

We are currently investigating this.

Mike
N�r��yb�X��ǧv�^�)޺{.n�+{��ٚ�{ay�ʇڙ�,j��f���h���z��w���
���j:+v���w�j�mzZ+�ݢj"��!�i

[PATCH v3 42/49] IB/hfi1: add UC QP handling

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/uc.c |  601 +++
 1 file changed, 601 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/uc.c

diff --git a/drivers/infiniband/hw/hfi1/uc.c b/drivers/infiniband/hw/hfi1/uc.c
new file mode 100644
index 000..a2ff755
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/uc.c
@@ -0,0 +1,601 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "hfi.h"
+#include "sdma.h"
+
+/* cut down ridiculously long IB macro names */
+#define OP(x) IB_OPCODE_UC_##x
+
+/**
+ * hfi1_make_uc_req - construct a request packet (SEND, RDMA write)
+ * @qp: a pointer to the QP
+ *
+ * Return 1 if constructed; otherwise, return 0.
+ */
+int hfi1_make_uc_req(struct hfi1_qp *qp)
+{
+   struct hfi1_other_headers *ohdr;
+   struct hfi1_swqe *wqe;
+   unsigned long flags;
+   u32 hwords = 5;
+   u32 bth0 = 0;
+   u32 len;
+   u32 pmtu = qp->pmtu;
+   int ret = 0;
+   int middle = 0;
+
+   spin_lock_irqsave(&qp->s_lock, flags);
+
+   if (!(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_SEND_OK)) {
+   if (!(ib_hfi1_state_ops[qp->state] & HFI1_FLUSH_SEND))
+   goto bail;
+   /* We are in the error state, flush the work request. */
+   if (qp->s_last == qp->s_head)
+   goto bail;
+   /* If DMAs are in progress, we can't flush immediately. */
+   if (atomic_read(&qp->s_iowait.sdma_busy)) {
+   qp->s_flags |= HFI1_S_WAIT_DMA;
+   goto bail;
+   }
+   clear_ahg(qp);
+   wqe = get_swqe_ptr(qp, qp->s_last);
+   hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
+   goto done;
+   }
+
+   ohdr = &qp->s_hdr->ibh.u.oth;
+   if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
+   ohdr = &qp->s_hdr->ibh.u.l.oth;
+
+   /* Get the next send request. */
+   wqe = get_swqe_ptr(qp, qp->s_cur);
+   qp->s_wqe = NULL;
+   switch (qp->s_st

[PATCH v3 39/49] IB/hfi1: add sysfs routines

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/sysfs.c | 1083 
 1 file changed, 1083 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/sysfs.c

diff --git a/drivers/infiniband/hw/hfi1/sysfs.c 
b/drivers/infiniband/hw/hfi1/sysfs.c
new file mode 100644
index 000..fdedb20
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/sysfs.c
@@ -0,0 +1,1083 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include 
+
+#include "hfi.h"
+#include "mad.h"
+#include "trace.h"
+
+/* start of per-port functions */
+/*
+ * Get/Set heartbeat enable. OR of 1=enabled, 2=auto
+ */
+static ssize_t show_hrtbt_enb(struct hfi1_pportdata *ppd, char *buf)
+{
+   int ret;
+
+   ret = hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_HRTBT);
+   ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
+   return ret;
+}
+
+static ssize_t store_hrtbt_enb(struct hfi1_pportdata *ppd, const char *buf,
+  size_t count)
+{
+   struct hfi1_devdata *dd = ppd->dd;
+   int ret;
+   u16 val;
+
+   ret = kstrtou16(buf, 0, &val);
+   if (ret) {
+   dd_dev_err(dd, "attempt to set invalid Heartbeat enable\n");
+   return ret;
+   }
+
+   /*
+* Set the "intentional" heartbeat enable per either of
+* "Enable" and "Auto", as these are normally set together.
+* This bit is consulted when leaving loopback mode,
+* because entering loopback mode overrides it and automatically
+* disables heartbeat.
+*/
+   ret = hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_HRTBT, val);
+   return ret < 0 ? ret : count;
+}
+
+static ssize_t store_led_override(struct hfi1_pportdata *ppd, const char *buf,
+ size_t count)
+{
+   struct hfi1_devdata *dd = ppd->dd;
+   int ret;
+   u16 val;
+
+   ret = kstrtou16(buf, 0, &val);
+   if (ret) {
+   dd_dev_err(dd, "attempt to set invalid LED override\n");
+   return ret;
+   }
+
+   hfi1_set_led_override(ppd, val);
+   return count;

[PATCH v3 41/49] IB/hfi1: add QSFP twsi routines

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/twsi.c |  518 +
 drivers/infiniband/hw/hfi1/twsi.h |   68 +
 2 files changed, 586 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/twsi.c
 create mode 100644 drivers/infiniband/hw/hfi1/twsi.h

diff --git a/drivers/infiniband/hw/hfi1/twsi.c 
b/drivers/infiniband/hw/hfi1/twsi.c
new file mode 100644
index 000..ea54fd2
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/twsi.c
@@ -0,0 +1,518 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "twsi.h"
+
+/*
+ * "Two Wire Serial Interface" support.
+ *
+ * Originally written for a not-quite-i2c serial eeprom, which is
+ * still used on some supported boards. Later boards have added a
+ * variety of other uses, most board-specific, so the bit-boffing
+ * part has been split off to this file, while the other parts
+ * have been moved to chip-specific files.
+ *
+ * We have also dropped all pretense of fully generic (e.g. pretend
+ * we don't know whether '1' is the higher voltage) interface, as
+ * the restrictions of the generic i2c interface (e.g. no access from
+ * driver itself) make it unsuitable for this use.
+ */
+
+#define READ_CMD 1
+#define WRITE_CMD 0
+
+/**
+ * i2c_wait_for_writes - wait for a write
+ * @dd: the hfi1_ib device
+ *
+ * We use this instead of udelay directly, so we can make sure
+ * that previous register writes have been flushed all the way
+ * to the chip.  Since we are delaying anyway, the cost doesn't
+ * hurt, and makes the bit twiddling more regular
+ */
+static void i2c_wait_for_writes(struct hfi1_devdata *dd, u32 target)
+{
+   /*
+* implicit read of EXTStatus is as good as explicit
+* read of scratch, if all we want to do is flush
+* writes.
+*/
+   hfi1_gpio_mod(dd, target, 0, 0, 0);
+   rmb(); /* inlined, so prevent compiler reordering */
+}
+
+/*
+ * QSFP modules are allowed to hold SCL low for 500uSec. Allow twice that
+ * for "almost compliant" modules
+ */
+#def

[PATCH v3 35/49] IB/hfi1: add routines for RC/UC

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/ruc.c |  944 ++
 1 file changed, 944 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/ruc.c

diff --git a/drivers/infiniband/hw/hfi1/ruc.c b/drivers/infiniband/hw/hfi1/ruc.c
new file mode 100644
index 000..1811e5e
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/ruc.c
@@ -0,0 +1,944 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+
+#include "hfi.h"
+#include "mad.h"
+#include "qp.h"
+#include "sdma.h"
+
+/*
+ * Convert the AETH RNR timeout code into the number of microseconds.
+ */
+const u32 ib_hfi1_rnr_table[32] = {
+   655360, /* 00: 655.36 */
+   10, /* 01:.01 */
+   20, /* 02 .02 */
+   30, /* 03:.03 */
+   40, /* 04:.04 */
+   60, /* 05:.06 */
+   80, /* 06:.08 */
+   120,/* 07:.12 */
+   160,/* 08:.16 */
+   240,/* 09:.24 */
+   320,/* 0A:.32 */
+   480,/* 0B:.48 */
+   640,/* 0C:.64 */
+   960,/* 0D:.96 */
+   1280,   /* 0E:   1.28 */
+   1920,   /* 0F:   1.92 */
+   2560,   /* 10:   2.56 */
+   3840,   /* 11:   3.84 */
+   5120,   /* 12:   5.12 */
+   7680,   /* 13:   7.68 */
+   10240,  /* 14:  10.24 */
+   15360,  /* 15:  15.36 */
+   20480,  /* 16:  20.48 */
+   30720,  /* 17:  30.72 */
+   40960,  /* 18:  40.96 */
+   61440,  /* 19:  61.44 */
+   81920,  /* 1A:  81.92 */
+   122880, /* 1B: 122.88 */
+   163840, /* 1C: 163.84 */
+   245760, /* 1D: 245.76 */
+   327680, /* 1E: 327.68 */
+   491520  /* 1F: 491.52 */
+};
+
+/*
+ * Validate a RWQE and fill in the SGE state.
+ * Return 1 if OK.
+ */
+static int init_sge(struct hfi1_qp *qp, struct hfi1_rwqe *wqe)
+{
+   int i, j, ret;
+   struct ib_wc wc;
+   struct hfi1_lkey_table *rkt;
+   struct hfi1_pd *pd;
+   struct hfi1_sge_state *ss;
+
+   rkt = &to_idev(qp->ibqp.device)->lk_table;
+   pd = to_ipd(qp->ibqp.srq ? qp->i

[PATCH v3 44/49] IB/hfi1: add low level page locking

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/user_pages.c |  156 +++
 1 file changed, 156 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/user_pages.c

diff --git a/drivers/infiniband/hw/hfi1/user_pages.c 
b/drivers/infiniband/hw/hfi1/user_pages.c
new file mode 100644
index 000..9071afb
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/user_pages.c
@@ -0,0 +1,156 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+
+#include "hfi.h"
+
+static void __hfi1_release_user_pages(struct page **p, size_t num_pages,
+ int dirty)
+{
+   size_t i;
+
+   for (i = 0; i < num_pages; i++) {
+   if (dirty)
+   set_page_dirty_lock(p[i]);
+   put_page(p[i]);
+   }
+}
+
+/*
+ * Call with current->mm->mmap_sem held.
+ */
+static int __hfi1_get_user_pages(unsigned long start_page, size_t num_pages,
+struct page **p)
+{
+   unsigned long lock_limit;
+   size_t got;
+   int ret;
+
+   lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
+
+   if (num_pages > lock_limit && !capable(CAP_IPC_LOCK)) {
+   ret = -ENOMEM;
+   goto bail;
+   }
+
+   for (got = 0; got < num_pages; got += ret) {
+   ret = get_user_pages(current, current->mm,
+start_page + got * PAGE_SIZE,
+num_pages - got, 1, 1,
+p + got, NULL);
+   if (ret < 0)
+   goto bail_release;
+   }
+
+   current->mm->pinned_vm += num_pages;
+
+   ret = 0;
+   goto bail;
+
+bail_release:
+   __hfi1_release_user_pages(p, got, 0);
+bail:
+   return ret;
+}
+
+/**
+ * hfi1_map_page - a safety wrapper around pci_map_page()
+ *
+ */
+dma_addr_t hfi1_map_page(struct pci_dev *hwdev, struct page *page,
+unsigned long offset, size_t size, int direction)
+{
+   dma_addr_t phys;
+
+   phys =

[PATCH v3 38/49] IB/hfi1: add SRQ handling

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/srq.c |  397 ++
 1 file changed, 397 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/srq.c

diff --git a/drivers/infiniband/hw/hfi1/srq.c b/drivers/infiniband/hw/hfi1/srq.c
new file mode 100644
index 000..67786d4
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/srq.c
@@ -0,0 +1,397 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include "verbs.h"
+
+/**
+ * hfi1_post_srq_receive - post a receive on a shared receive queue
+ * @ibsrq: the SRQ to post the receive on
+ * @wr: the list of work requests to post
+ * @bad_wr: A pointer to the first WR to cause a problem is put here
+ *
+ * This may be called from interrupt context.
+ */
+int hfi1_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
+ struct ib_recv_wr **bad_wr)
+{
+   struct hfi1_srq *srq = to_isrq(ibsrq);
+   struct hfi1_rwq *wq;
+   unsigned long flags;
+   int ret;
+
+   for (; wr; wr = wr->next) {
+   struct hfi1_rwqe *wqe;
+   u32 next;
+   int i;
+
+   if ((unsigned) wr->num_sge > srq->rq.max_sge) {
+   *bad_wr = wr;
+   ret = -EINVAL;
+   goto bail;
+   }
+
+   spin_lock_irqsave(&srq->rq.lock, flags);
+   wq = srq->rq.wq;
+   next = wq->head + 1;
+   if (next >= srq->rq.size)
+   next = 0;
+   if (next == wq->tail) {
+   spin_unlock_irqrestore(&srq->rq.lock, flags);
+   *bad_wr = wr;
+   ret = -ENOMEM;
+   goto bail;
+   }
+
+   wqe = get_rwqe_ptr(&srq->rq, wq->head);
+   wqe->wr_id = wr->wr_id;
+   wqe->num_sge = wr->num_sge;
+   for (i = 0; i < wr->num_sge; i++)
+   wqe->sg_list[i] = wr->sg_list[i];
+   /* Make sure queue entr

[PATCH v3 43/49] IB/hfi1: add UD QP handling

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/ud.c |  886 +++
 1 file changed, 886 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/ud.c

diff --git a/drivers/infiniband/hw/hfi1/ud.c b/drivers/infiniband/hw/hfi1/ud.c
new file mode 100644
index 000..94c65a4
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/ud.c
@@ -0,0 +1,886 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+
+#include "hfi.h"
+#include "mad.h"
+#include "qp.h"
+
+/**
+ * ud_loopback - handle send on loopback QPs
+ * @sqp: the sending QP
+ * @swqe: the send work request
+ *
+ * This is called from hfi1_make_ud_req() to forward a WQE addressed
+ * to the same HCA.
+ * Note that the receive interrupt handler may be calling hfi1_ud_rcv()
+ * while this is being called.
+ */
+static void ud_loopback(struct hfi1_qp *sqp, struct hfi1_swqe *swqe)
+{
+   struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
+   struct hfi1_pportdata *ppd;
+   struct hfi1_qp *qp;
+   struct ib_ah_attr *ah_attr;
+   unsigned long flags;
+   struct hfi1_sge_state ssge;
+   struct hfi1_sge *sge;
+   struct ib_wc wc;
+   u32 length;
+   enum ib_qp_type sqptype, dqptype;
+
+   qp = hfi1_lookup_qpn(ibp, swqe->wr.wr.ud.remote_qpn);
+   if (!qp) {
+   ibp->n_pkt_drops++;
+   return;
+   }
+
+   sqptype = sqp->ibqp.qp_type == IB_QPT_GSI ?
+   IB_QPT_UD : sqp->ibqp.qp_type;
+   dqptype = qp->ibqp.qp_type == IB_QPT_GSI ?
+   IB_QPT_UD : qp->ibqp.qp_type;
+
+   if (dqptype != sqptype ||
+   !(ib_hfi1_state_ops[qp->state] & HFI1_PROCESS_RECV_OK)) {
+   ibp->n_pkt_drops++;
+   goto drop;
+   }
+
+   ah_attr = &to_iah(swqe->wr.wr.ud.ah)->attr;
+   ppd = ppd_from_ibp(ibp);
+
+   if (qp->ibqp.qp_num > 1) {
+   u16 pkey;
+   u16 slid;
+   u8 sc5 = ibp->sl_to_sc[ah_attr->sl];
+
+   pkey = hfi1_get_pkey(ibp, sqp->s_pke

[PATCH v3 34/49] IB/hfi1: add RC QP handling

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/rc.c | 2456 +++
 1 file changed, 2456 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/rc.c

diff --git a/drivers/infiniband/hw/hfi1/rc.c b/drivers/infiniband/hw/hfi1/rc.c
new file mode 100644
index 000..bb29016
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/rc.c
@@ -0,0 +1,2456 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+
+#include "hfi.h"
+#include "qp.h"
+#include "sdma.h"
+#include "trace.h"
+
+/* cut down ridiculously long IB macro names */
+#define OP(x) IB_OPCODE_RC_##x
+
+static void rc_timeout(unsigned long arg);
+
+static u32 restart_sge(struct hfi1_sge_state *ss, struct hfi1_swqe *wqe,
+  u32 psn, u32 pmtu)
+{
+   u32 len;
+
+   len = delta_psn(psn, wqe->psn) * pmtu;
+   ss->sge = wqe->sg_list[0];
+   ss->sg_list = wqe->sg_list + 1;
+   ss->num_sge = wqe->wr.num_sge;
+   ss->total_len = wqe->length;
+   hfi1_skip_sge(ss, len, 0);
+   return wqe->length - len;
+}
+
+static void start_timer(struct hfi1_qp *qp)
+{
+   qp->s_flags |= HFI1_S_TIMER;
+   qp->s_timer.function = rc_timeout;
+   /* 4.096 usec. * (1 << qp->timeout) */
+   qp->s_timer.expires = jiffies + qp->timeout_jiffies;
+   add_timer(&qp->s_timer);
+}
+
+/**
+ * make_rc_ack - construct a response packet (ACK, NAK, or RDMA read)
+ * @dev: the device for this QP
+ * @qp: a pointer to the QP
+ * @ohdr: a pointer to the IB header being constructed
+ * @pmtu: the path MTU
+ *
+ * Return 1 if constructed; otherwise, return 0.
+ * Note that we are in the responder's side of the QP context.
+ * Note the QP s_lock must be held.
+ */
+static int make_rc_ack(struct hfi1_ibdev *dev, struct hfi1_qp *qp,
+  struct hfi1_other_headers *ohdr, u32 pmtu)
+{
+   struct hfi1_ack_entry *e;
+   u32 hwords;
+   u32 len;
+   u32 bth0;
+   u32 bth2;
+   int middle = 0;
+
+   /* Don't send an ACK if we aren't supposed to. */
+   if (!(ib_hfi1_state_ops[qp->state] &

[PATCH v3 36/49] IB/hfi1: add sdma routines

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/sdma.c | 2950 +
 1 file changed, 2950 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/sdma.c

diff --git a/drivers/infiniband/hw/hfi1/sdma.c 
b/drivers/infiniband/hw/hfi1/sdma.c
new file mode 100644
index 000..792436e
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/sdma.c
@@ -0,0 +1,2950 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "common.h"
+#include "qp.h"
+#include "sdma.h"
+#include "iowait.h"
+#include "trace.h"
+
+/* must be a power of 2 >= 64 <= 32768 */
+#define SDMA_DESCQ_CNT 1024
+#define INVALID_TAIL 0x
+
+static uint sdma_descq_cnt = SDMA_DESCQ_CNT;
+module_param(sdma_descq_cnt, uint, S_IRUGO);
+MODULE_PARM_DESC(sdma_descq_cnt, "Number of SDMA descq entries");
+
+static uint sdma_idle_cnt = 250;
+module_param(sdma_idle_cnt, uint, S_IRUGO);
+MODULE_PARM_DESC(sdma_idle_cnt, "sdma interrupt idle delay (ns,default 250)");
+
+uint mod_num_sdma;
+module_param_named(num_sdma, mod_num_sdma, uint, S_IRUGO);
+MODULE_PARM_DESC(num_sdma, "Set max number SDMA engines to use");
+
+#define SDMA_WAIT_BATCH_SIZE 20
+/* max wait time for a SDMA engine to indicate it has halted */
+#define SDMA_ERR_HALT_TIMEOUT 10 /* ms */
+/* all SDMA engine errors that cause a halt */
+
+#define SD(name) SEND_DMA_##name
+#define ALL_SDMA_ENG_HALT_ERRS \
+   (SD(ENG_ERR_STATUS_SDMA_WRONG_DW_ERR_SMASK) \
+   | SD(ENG_ERR_STATUS_SDMA_GEN_MISMATCH_ERR_SMASK) \
+   | SD(ENG_ERR_STATUS_SDMA_TOO_LONG_ERR_SMASK) \
+   | SD(ENG_ERR_STATUS_SDMA_TAIL_OUT_OF_BOUNDS_ERR_SMASK) \
+   | SD(ENG_ERR_STATUS_SDMA_FIRST_DESC_ERR_SMASK) \
+   | SD(ENG_ERR_STATUS_SDMA_MEM_READ_ERR_SMASK) \
+   | SD(ENG_ERR_STATUS_SDMA_HALT_ERR_SMASK) \
+   | SD(ENG_ERR_STATUS_SDMA_LENGTH_MISMATCH_ERR_SMASK) \
+   | SD(ENG_ERR_STATUS_SDMA_PACKET_DESC_OVERFLOW_ERR_SMASK) \
+   | SD(ENG_ERR_STATUS_SDMA_HEADER_SELECT_ERR_SMASK) \
+   | SD(ENG_ERR_STATUS_SDMA_HEADER

[PATCH v3 46/49] IB/hfi1: add general verbs handling

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/verbs.c | 2215 
 drivers/infiniband/hw/hfi1/verbs.h | 1193 +++
 2 files changed, 3408 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/verbs.c
 create mode 100644 drivers/infiniband/hw/hfi1/verbs.h

diff --git a/drivers/infiniband/hw/hfi1/verbs.c 
b/drivers/infiniband/hw/hfi1/verbs.c
new file mode 100644
index 000..680fd41
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/verbs.c
@@ -0,0 +1,2215 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "common.h"
+#include "device.h"
+#include "trace.h"
+#include "qp.h"
+#include "sdma.h"
+
+unsigned int hfi1_lkey_table_size = 16;
+module_param_named(lkey_table_size, hfi1_lkey_table_size, uint,
+  S_IRUGO);
+MODULE_PARM_DESC(lkey_table_size,
+"LKEY table size in bits (2^n, 1 <= n <= 23)");
+
+static unsigned int hfi1_max_pds = 0x;
+module_param_named(max_pds, hfi1_max_pds, uint, S_IRUGO);
+MODULE_PARM_DESC(max_pds,
+"Maximum number of protection domains to support");
+
+static unsigned int hfi1_max_ahs = 0x;
+module_param_named(max_ahs, hfi1_max_ahs, uint, S_IRUGO);
+MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support");
+
+unsigned int hfi1_max_cqes = 0x2;
+module_param_named(max_cqes, hfi1_max_cqes, uint, S_IRUGO);
+MODULE_PARM_DESC(max_cqes,
+"Maximum number of completion queue entries to support");
+
+unsigned int hfi1_max_cqs = 0x1;
+module_param_named(max_cqs, hfi1_max_cqs, uint, S_IRUGO);
+MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support");
+
+unsigned int hfi1_max_qp_wrs = 0x3FFF;
+module_param_named(max_qp_wrs, hfi1_max_qp_wrs, uint, S_IRUGO);
+MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support");
+
+unsigned int hfi1_max_qps = 16384;
+module_param_named(max_qps, hfi1_max_qps, uint, S_IRUGO);
+MODULE_PARM_DESC(max_qps, "Maximum num

[PATCH v3 47/49] IB/hfi1: add multicast routines

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/verbs_mcast.c |  385 ++
 1 file changed, 385 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/verbs_mcast.c

diff --git a/drivers/infiniband/hw/hfi1/verbs_mcast.c 
b/drivers/infiniband/hw/hfi1/verbs_mcast.c
new file mode 100644
index 000..afc6b4c
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/verbs_mcast.c
@@ -0,0 +1,385 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+
+#include "hfi.h"
+
+/**
+ * mcast_qp_alloc - alloc a struct to link a QP to mcast GID struct
+ * @qp: the QP to link
+ */
+static struct hfi1_mcast_qp *mcast_qp_alloc(struct hfi1_qp *qp)
+{
+   struct hfi1_mcast_qp *mqp;
+
+   mqp = kmalloc(sizeof(*mqp), GFP_KERNEL);
+   if (!mqp)
+   goto bail;
+
+   mqp->qp = qp;
+   atomic_inc(&qp->refcount);
+
+bail:
+   return mqp;
+}
+
+static void mcast_qp_free(struct hfi1_mcast_qp *mqp)
+{
+   struct hfi1_qp *qp = mqp->qp;
+
+   /* Notify hfi1_destroy_qp() if it is waiting. */
+   if (atomic_dec_and_test(&qp->refcount))
+   wake_up(&qp->wait);
+
+   kfree(mqp);
+}
+
+/**
+ * mcast_alloc - allocate the multicast GID structure
+ * @mgid: the multicast GID
+ *
+ * A list of QPs will be attached to this structure.
+ */
+static struct hfi1_mcast *mcast_alloc(union ib_gid *mgid)
+{
+   struct hfi1_mcast *mcast;
+
+   mcast = kmalloc(sizeof(*mcast), GFP_KERNEL);
+   if (!mcast)
+   goto bail;
+
+   mcast->mgid = *mgid;
+   INIT_LIST_HEAD(&mcast->qp_list);
+   init_waitqueue_head(&mcast->wait);
+   atomic_set(&mcast->refcount, 0);
+   mcast->n_attached = 0;
+
+bail:
+   return mcast;
+}
+
+static void mcast_free(struct hfi1_mcast *mcast)
+{
+   struct hfi1_mcast_qp *p, *tmp;
+
+   list_for_each_entry_safe(p, tmp, &mcast->qp_list, list)
+   mcast_qp_free(p);
+
+   kfree(mcast);
+}
+
+/**
+ * hfi1_mcast_find - search the global table for the given multicast GID
+ * @ibp: the IB port structure
+ * @mgid: the mult

[PATCH v3 45/49] IB/hfi1: add PSM sdma hooks

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/user_sdma.c | 1450 
 drivers/infiniband/hw/hfi1/user_sdma.h |   89 ++
 2 files changed, 1539 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/user_sdma.c
 create mode 100644 drivers/infiniband/hw/hfi1/user_sdma.h

diff --git a/drivers/infiniband/hw/hfi1/user_sdma.c 
b/drivers/infiniband/hw/hfi1/user_sdma.c
new file mode 100644
index 000..a74ce8d
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/user_sdma.c
@@ -0,0 +1,1450 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "sdma.h"
+#include "user_sdma.h"
+#include "sdma.h"
+#include "verbs.h"  /* for the headers */
+#include "common.h" /* for struct hfi1_tid_info */
+#include "trace.h"
+
+static uint hfi1_sdma_comp_ring_size = 128;
+module_param_named(sdma_comp_size, hfi1_sdma_comp_ring_size, uint, S_IRUGO);
+MODULE_PARM_DESC(sdma_comp_size, "Size of User SDMA completion ring. Default: 
128");
+
+/* The maximum number of Data io vectors per message/request */
+#define MAX_VECTORS_PER_REQ 8
+/*
+ * Maximum number of packet to send from each message/request
+ * before moving to the next one.
+ */
+#define MAX_PKTS_PER_QUEUE 16
+
+#define num_pages(x) (1 + x) - 1) & PAGE_MASK) >> PAGE_SHIFT))
+
+#define req_opcode(x) \
+   (((x) >> HFI1_SDMA_REQ_OPCODE_SHIFT) & HFI1_SDMA_REQ_OPCODE_MASK)
+#define req_version(x) \
+   (((x) >> HFI1_SDMA_REQ_VERSION_SHIFT) & HFI1_SDMA_REQ_OPCODE_MASK)
+#define req_iovcnt(x) \
+   (((x) >> HFI1_SDMA_REQ_IOVCNT_SHIFT) & HFI1_SDMA_REQ_IOVCNT_MASK)
+
+/* Number of BTH.PSN bits used for sequence number in expected rcvs */
+#define BTH_SEQ_MASK 0x7ffull
+
+/*
+ * Define fields in the KDETH header so we can update the header
+ * template.
+ */
+#define KDETH_OFFSET_SHIFT0
+#define KDETH_OFFSET_MASK 0x7fff
+#define KDETH_OM_SHIFT15
+#define KDETH_OM_MAS

[PATCH v3 37/49] IB/hfi1: add sdma header file

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/sdma.h | 1122 +
 1 file changed, 1122 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/sdma.h

diff --git a/drivers/infiniband/hw/hfi1/sdma.h 
b/drivers/infiniband/hw/hfi1/sdma.h
new file mode 100644
index 000..2d2ff07
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/sdma.h
@@ -0,0 +1,1122 @@
+#ifndef _HFI1_SDMA_H
+#define _HFI1_SDMA_H
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "verbs.h"
+
+/* increased for AHG */
+#define NUM_DESC 6
+/* Hardware limit */
+#define MAX_DESC 64
+/* Hardware limit for SDMA packet size */
+#define MAX_SDMA_PKT_SIZE ((16 * 1024) - 1)
+
+
+#define SDMA_TXREQ_S_OK0
+#define SDMA_TXREQ_S_SENDERROR 1
+#define SDMA_TXREQ_S_ABORTED   2
+#define SDMA_TXREQ_S_SHUTDOWN  3
+
+/* flags bits */
+#define SDMA_TXREQ_F_URGENT   0x0001
+#define SDMA_TXREQ_F_AHG_COPY 0x0002
+#define SDMA_TXREQ_F_USE_AHG  0x0004
+
+#define SDMA_MAP_NONE  0
+#define SDMA_MAP_SINGLE1
+#define SDMA_MAP_PAGE  2
+
+#define SDMA_AHG_VALUE_MASK  0x
+#define SDMA_AHG_VALUE_SHIFT 0
+#define SDMA_AHG_INDEX_MASK  0xf
+#define SDMA_AHG_INDEX_SHIFT 16
+#define SDMA_AHG_FIELD_LEN_MASK  0xf
+#define SDMA_AHG_FIELD_LEN_SHIFT 20
+#define SDMA_AHG_FIELD_START_MASK0x1f
+#define SDMA_AHG_FIELD_START_SHIFT   24
+#define SDMA_AHG_UPDATE_ENABLE_MASK  0x1
+#define SDMA_AHG_UPDATE_ENABLE_SHIFT 31
+
+/* AHG modes */
+
+/*
+ * Be aware the ordering and values
+ * for SDMA_AHG_APPLY_UPDATE[123]
+ * are assumed in generating a skip
+ * count in submit_tx() in sdma.c
+ */
+#define SDMA_AHG_NO_AHG  0
+#define SDMA_AHG_COPY1
+#define SDMA_AHG_APPLY_UPDATE1   2
+#define SDMA_AHG_APPLY_UPDATE2   3
+#define SDMA_AHG_APPLY_UPDATE3   4
+
+/*
+ * Bits defined in the send DMA descriptor.
+ */
+#define SDMA_DESC0_FIRST_DESC_FLAG  (1ULL<<63)
+#define SDMA_DESC0_LAST_DESC_FLAG

[PATCH v3 40/49] IB/hfi1: add tracepoint debug routines

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/trace.c |  211 +
 drivers/infiniband/hw/hfi1/trace.h | 1390 
 2 files changed, 1601 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/trace.c
 create mode 100644 drivers/infiniband/hw/hfi1/trace.h

diff --git a/drivers/infiniband/hw/hfi1/trace.c 
b/drivers/infiniband/hw/hfi1/trace.c
new file mode 100644
index 000..afbb212
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/trace.c
@@ -0,0 +1,211 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#define CREATE_TRACE_POINTS
+#define HFI1_TRACE_DO_NOT_CREATE_INLINES
+#include "trace.h"
+
+u8 ibhdr_exhdr_len(struct hfi1_ib_header *hdr)
+{
+   struct hfi1_other_headers *ohdr;
+   u8 opcode;
+   u8 lnh = (u8)(be16_to_cpu(hdr->lrh[0]) & 3);
+
+   if (lnh == HFI1_LRH_BTH)
+   ohdr = &hdr->u.oth;
+   else
+   ohdr = &hdr->u.l.oth;
+   opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
+   return hdr_len_by_opcode[opcode] == 0 ?
+  0 : hdr_len_by_opcode[opcode] - (12 + 8);
+}
+
+#define IMM_PRN  "imm %d"
+#define RETH_PRN "reth vaddr 0x%.16llx rkey 0x%.8x dlen 0x%.8x"
+#define AETH_PRN "aeth syn 0x%.2x msn 0x%.8x"
+#define DETH_PRN "deth qkey 0x%.8x sqpn 0x%.6x"
+#define ATOMICACKETH_PRN "origdata %lld"
+#define ATOMICETH_PRN "vaddr 0x%llx rkey 0x%.8x sdata %lld cdata %lld"
+
+#define OP(transport, op) IB_OPCODE_## transport ## _ ## op
+
+static u64 ib_u64_get(__be32 *p)
+{
+   return ((u64)be32_to_cpu(p[0]) << 32) | be32_to_cpu(p[1]);
+}
+
+const char *parse_everbs_hdrs(
+   struct trace_seq *p,
+   u8 opcode,
+   void *ehdrs)
+{
+   union ib_ehdrs *eh = ehdrs;
+   const char *ret = trace_seq_buffer_ptr(p);
+
+   switch (opcode) {
+   /* imm */
+   case OP(RC, SEND_LAST_WITH_IMMEDIATE):
+   case OP(UC, SEND_LAST_WITH_IMMEDIATE):
+   case OP(RC, SEND_ONLY_WITH_IMMEDIATE):
+   case OP(UC, SEND_ONLY_WITH_IMMEDIATE):
+   case OP(RC, RDMA_WRITE_LAST_WITH_IMMEDIATE):
+   case OP(UC, RDMA_WRITE_LAST_WITH_IMM

[PATCH v3 49/49] IB/core: Add opa driver to kbuild

2015-06-17 Thread Mike Marciniszyn
From: Jubin John 

Signed-off-by: Jubin John 
Signed-off-by: Mike Marciniszyn 
---
 drivers/infiniband/Kconfig |1 
 drivers/infiniband/hw/Makefile |1 
 drivers/infiniband/hw/hfi1/sysfs.c |  131 
 3 files changed, 3 insertions(+), 130 deletions(-)

diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
index b899531..dd24c3d 100644
--- a/drivers/infiniband/Kconfig
+++ b/drivers/infiniband/Kconfig
@@ -57,6 +57,7 @@ config INFINIBAND_ADDR_TRANS
 source "drivers/infiniband/hw/mthca/Kconfig"
 source "drivers/infiniband/hw/ipath/Kconfig"
 source "drivers/infiniband/hw/qib/Kconfig"
+source "drivers/infiniband/hw/hfi1/Kconfig"
 source "drivers/infiniband/hw/ehca/Kconfig"
 source "drivers/infiniband/hw/amso1100/Kconfig"
 source "drivers/infiniband/hw/cxgb3/Kconfig"
diff --git a/drivers/infiniband/hw/Makefile b/drivers/infiniband/hw/Makefile
index e900b03..f3f4d9d 100644
--- a/drivers/infiniband/hw/Makefile
+++ b/drivers/infiniband/hw/Makefile
@@ -1,6 +1,7 @@
 obj-$(CONFIG_INFINIBAND_MTHCA) += mthca/
 obj-$(CONFIG_INFINIBAND_IPATH) += ipath/
 obj-$(CONFIG_INFINIBAND_QIB)   += qib/
+obj-$(CONFIG_INFINIBAND_HFI1)  += hfi1/
 obj-$(CONFIG_INFINIBAND_EHCA)  += ehca/
 obj-$(CONFIG_INFINIBAND_AMSO1100)  += amso1100/
 obj-$(CONFIG_INFINIBAND_CXGB3) += cxgb3/
diff --git a/drivers/infiniband/hw/hfi1/sysfs.c 
b/drivers/infiniband/hw/hfi1/sysfs.c
index fdedb20..6fad3a6 100644
--- a/drivers/infiniband/hw/hfi1/sysfs.c
+++ b/drivers/infiniband/hw/hfi1/sysfs.c
@@ -619,123 +619,6 @@ static struct kobj_type hfi1_vl2mtu_ktype = {
.default_attrs = vl2mtu_default_attributes
 };
 
-/* Start diag_counters */
-#define HFI1_DIAGC_NORMAL 0x0
-#define HFI1_DIAGC_PCPU   0x1
-
-#define HFI1_DIAGC_ATTR(N) \
-   static struct hfi1_diagc_attr diagc_attr_##N = { \
-   .attr = { .name = __stringify(N), .mode = 0664 }, \
-   .counter = offsetof(struct hfi1_ibport, n_##N), \
-   .type = HFI1_DIAGC_NORMAL, \
-   .vl = CNTR_INVALID_VL \
-   }
-
-#define HFI1_DIAGC_ATTR_PCPU(N, V, L) \
-   static struct hfi1_diagc_attr diagc_attr_##N = { \
-   .attr = { .name = __stringify(N), .mode = 0664 }, \
-   .counter = V, \
-   .type = HFI1_DIAGC_PCPU, \
-   .vl = L \
-   }
-
-struct hfi1_diagc_attr {
-   struct attribute attr;
-   size_t counter;
-   int type;
-   int vl;
-};
-
-HFI1_DIAGC_ATTR(rc_resends);
-HFI1_DIAGC_ATTR_PCPU(rc_acks, C_SW_CPU_RC_ACKS, CNTR_INVALID_VL);
-HFI1_DIAGC_ATTR_PCPU(rc_qacks, C_SW_CPU_RC_QACKS, CNTR_INVALID_VL);
-HFI1_DIAGC_ATTR_PCPU(rc_delayed_comp, C_SW_CPU_RC_DELAYED_COMP,
-   CNTR_INVALID_VL);
-HFI1_DIAGC_ATTR(seq_naks);
-HFI1_DIAGC_ATTR(rdma_seq);
-HFI1_DIAGC_ATTR(rnr_naks);
-HFI1_DIAGC_ATTR(other_naks);
-HFI1_DIAGC_ATTR(rc_timeouts);
-HFI1_DIAGC_ATTR(loop_pkts);
-HFI1_DIAGC_ATTR(pkt_drops);
-HFI1_DIAGC_ATTR(dmawait);
-HFI1_DIAGC_ATTR(unaligned);
-HFI1_DIAGC_ATTR(rc_dupreq);
-HFI1_DIAGC_ATTR(rc_seqnak);
-
-static struct attribute *diagc_default_attributes[] = {
-   &diagc_attr_rc_resends.attr,
-   &diagc_attr_rc_acks.attr,
-   &diagc_attr_rc_qacks.attr,
-   &diagc_attr_rc_delayed_comp.attr,
-   &diagc_attr_seq_naks.attr,
-   &diagc_attr_rdma_seq.attr,
-   &diagc_attr_rnr_naks.attr,
-   &diagc_attr_other_naks.attr,
-   &diagc_attr_rc_timeouts.attr,
-   &diagc_attr_loop_pkts.attr,
-   &diagc_attr_pkt_drops.attr,
-   &diagc_attr_dmawait.attr,
-   &diagc_attr_unaligned.attr,
-   &diagc_attr_rc_dupreq.attr,
-   &diagc_attr_rc_seqnak.attr,
-   NULL
-};
-
-static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
-  char *buf)
-{
-   struct hfi1_diagc_attr *dattr =
-   container_of(attr, struct hfi1_diagc_attr, attr);
-   struct hfi1_pportdata *ppd =
-   container_of(kobj, struct hfi1_pportdata, diagc_kobj);
-   struct hfi1_ibport *hfip = &ppd->ibport_data;
-
-   switch (dattr->type) {
-   case (HFI1_DIAGC_PCPU):
-   return(sprintf(buf, "%lld\n",
-   read_port_cntr(ppd,
-  dattr->counter,
-  dattr->vl)));
-   case (HFI1_DIAGC_NORMAL):
-   /* Fall through */
-   default:
-   return sprintf(buf, "%u\n",
-   *(u32 *)((char *)hfip + dattr->counter));
-   }
-}
-
-static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
-   const char *buf, size_t size)
-{
-   struct hfi1_diagc_attr *dattr =
-   container_of(attr, struct hfi1_diagc_attr, attr);
-   struct hfi1_pportdata *ppd =
-   container_of(kobj, struct hfi1_pportdata, diagc_kobj);
-   struct hfi1_ibport *hfip = &ppd->ibport_data;
-   u

[PATCH v3 48/49] IB/hfi1: add driver make/config files

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/Kconfig  |   27 +++
 drivers/infiniband/hw/hfi1/Makefile |   20 
 2 files changed, 47 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/Kconfig
 create mode 100644 drivers/infiniband/hw/hfi1/Makefile

diff --git a/drivers/infiniband/hw/hfi1/Kconfig 
b/drivers/infiniband/hw/hfi1/Kconfig
new file mode 100644
index 000..4d1ff19
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/Kconfig
@@ -0,0 +1,27 @@
+config INFINIBAND_HFI1
+   tristate "Intel OPA Gen1 support"
+   depends on X86_64
+   default m
+   ---help---
+   This is a low-level driver for Intel OPA Gen1 adapter.
+config HFI1_DEBUG_SDMA_ORDER
+   bool "HFI1 SDMA Order debug"
+   depends on INFINIBAND_HFI1
+   default n
+   ---help---
+   This is a debug flag to test for out of order
+   sdma completions for unit testing
+config HFI1_VERBS_31BIT_PSN
+   bool "HFI1 enable 31 bit PSN"
+   depends on INFINIBAND_HFI1
+   default y
+   ---help---
+   Setting this enables 31 BIT PSN
+   For verbs RC/UC
+config CONFIG_SDMA_VERBOSITY
+   bool "Config SDMA Verbosity"
+   depends on INFINIBAND_HFI1
+   default n
+   ---help---
+   This is a configuration flag to enable verbose
+   SDMA debug
diff --git a/drivers/infiniband/hw/hfi1/Makefile 
b/drivers/infiniband/hw/hfi1/Makefile
new file mode 100644
index 000..7e1c06d
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/Makefile
@@ -0,0 +1,20 @@
+#
+# HFI driver
+#
+#
+#
+# Called from the kernel module build system.
+#
+obj-$(CONFIG_INFINIBAND_HFI1) += hfi1.o
+
+hfi1-y := chip.o cq.o device.o diag.o dma.o driver.o eprom.o file_ops.o 
firmware.o \
+   init.o intr.o keys.o mad.o mmap.o mr.o pcie.o pio.o pio_copy.o \
+   qp.o qsfp.o rc.o ruc.o sdma.o srq.o sysfs.o trace.o twsi.o \
+   uc.o ud.o user_pages.o user_sdma.o verbs_mcast.o verbs.o
+hfi1-$(CONFIG_DEBUG_FS) += debugfs.o
+
+CFLAGS_trace.o = -I$(src)
+ifdef MVERSION
+CFLAGS_driver.o = -DHFI_DRIVER_VERSION_BASE=\"$(MVERSION)\"
+endif
+

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 32/49] IB/hfi1: add qp handling

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/qp.c | 1692 +++
 drivers/infiniband/hw/hfi1/qp.h |  206 +
 2 files changed, 1898 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/qp.c
 create mode 100644 drivers/infiniband/hw/hfi1/qp.h

diff --git a/drivers/infiniband/hw/hfi1/qp.c b/drivers/infiniband/hw/hfi1/qp.c
new file mode 100644
index 000..40db5d7
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/qp.c
@@ -0,0 +1,1692 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "qp.h"
+#include "trace.h"
+#include "sdma.h"
+
+#define BITS_PER_PAGE   (PAGE_SIZE*BITS_PER_BYTE)
+#define BITS_PER_PAGE_MASK  (BITS_PER_PAGE-1)
+
+static unsigned int hfi1_qp_table_size = 256;
+module_param_named(qp_table_size, hfi1_qp_table_size, uint, S_IRUGO);
+MODULE_PARM_DESC(qp_table_size, "QP table size");
+
+static void flush_tx_list(struct hfi1_qp *qp);
+static int iowait_sleep(
+   struct sdma_engine *sde,
+   struct iowait *wait,
+   struct sdma_txreq *stx,
+   unsigned seq);
+static void iowait_wakeup(struct iowait *wait, int reason);
+
+static inline unsigned mk_qpn(struct hfi1_qpn_table *qpt,
+ struct qpn_map *map, unsigned off)
+{
+   return (map - qpt->map) * BITS_PER_PAGE + off;
+}
+
+/*
+ * Convert the AETH credit code into the number of credits.
+ */
+static u32 credit_table[31] = {
+   0,  /* 0 */
+   1,  /* 1 */
+   2,  /* 2 */
+   3,  /* 3 */
+   4,  /* 4 */
+   6,  /* 5 */
+   8,  /* 6 */
+   12, /* 7 */
+   16, /* 8 */
+   24, /* 9 */
+   32, /* A */
+   48, /* B */
+   64, /* C */
+   96, /* D */
+   128,  

[PATCH v3 33/49] IB/hfi1: add qsfp handling

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/qsfp.c |  546 +
 drivers/infiniband/hw/hfi1/qsfp.h |  222 +++
 2 files changed, 768 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/qsfp.c
 create mode 100644 drivers/infiniband/hw/hfi1/qsfp.h

diff --git a/drivers/infiniband/hw/hfi1/qsfp.c 
b/drivers/infiniband/hw/hfi1/qsfp.c
new file mode 100644
index 000..001cfac
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/qsfp.c
@@ -0,0 +1,546 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "twsi.h"
+
+/*
+ * QSFP support for hfi driver, using "Two Wire Serial Interface" driver
+ * in twsi.c
+ */
+#define I2C_MAX_RETRY 4
+
+/*
+ * Unlocked i2c write.  Must hold dd->qsfp_i2c_mutex.
+ */
+static int __i2c_write(struct hfi1_pportdata *ppd, u32 target, int i2c_addr,
+  int offset, void *bp, int len)
+{
+   struct hfi1_devdata *dd = ppd->dd;
+   int ret, cnt;
+   u8 *buff = bp;
+
+   /* Make sure TWSI bus is in sane state. */
+   ret = hfi1_twsi_reset(dd, target);
+   if (ret) {
+   hfi1_dev_porterr(dd, ppd->port,
+"I2C interface Reset for write failed\n");
+   return -EIO;
+   }
+
+   cnt = 0;
+   while (cnt < len) {
+   int wlen = len - cnt;
+
+   ret = hfi1_twsi_blk_wr(dd, target, i2c_addr, offset,
+  buff + cnt, wlen);
+   if (ret) {
+   /* hfi1_twsi_blk_wr() 1 for error, else 0 */
+   return -EIO;
+   }
+   offset += wlen;
+   cnt += wlen;
+   }
+
+   /* Must wait min 20us between qsfp i2c transactions */
+   udelay(20);
+
+   return cnt;
+}
+
+int i2c_write(struct hfi1_pportdata *ppd, u32 target, int i2c_addr, int offset,
+ void *bp, int len)
+{
+   struct hfi1_devdata *dd = ppd->dd;
+   int ret;
+
+   ret = mutex_lock_interruptible(&dd

[PATCH v3 29/49] IB/hfi1: add pcie routines

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/pcie.c | 1254 +
 1 file changed, 1254 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/pcie.c

diff --git a/drivers/infiniband/hw/hfi1/pcie.c 
b/drivers/infiniband/hw/hfi1/pcie.c
new file mode 100644
index 000..c7ad5e4
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/pcie.c
@@ -0,0 +1,1254 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "chip_registers.h"
+
+/* link speed vector for Gen3 speed - not in Linux headers */
+#define GEN1_SPEED_VECTOR 0x1
+#define GEN2_SPEED_VECTOR 0x2
+#define GEN3_SPEED_VECTOR 0x3
+
+/*
+ * This file contains PCIe utility routines.
+ */
+
+/*
+ * Code to adjust PCIe capabilities.
+ */
+static void tune_pcie_caps(struct hfi1_devdata *);
+
+/*
+ * Do all the common PCIe setup and initialization.
+ * devdata is not yet allocated, and is not allocated until after this
+ * routine returns success.  Therefore dd_dev_err() can't be used for error
+ * printing.
+ */
+int hfi1_pcie_init(struct pci_dev *pdev, const struct pci_device_id *ent)
+{
+   int ret;
+
+   ret = pci_enable_device(pdev);
+   if (ret) {
+   /*
+* This can happen (in theory) iff:
+* We did a chip reset, and then failed to reprogram the
+* BAR, or the chip reset due to an internal error.  We then
+* unloaded the driver and reloaded it.
+*
+* Both reset cases set the BAR back to initial state.  For
+* the latter case, the AER sticky error bit at offset 0x718
+* should be set, but the Linux kernel doesn't yet know
+* about that, it appears.  If the original BAR was retained
+* in the kernel data structures, this may be OK.
+*/
+   hfi1_early_err(&pdev->dev, "pci enable failed: error %d\n",
+  -ret);
+   goto done;
+

[PATCH v3 30/49] IB/hfi1: add pio handling

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/pio.c  | 1764 +
 drivers/infiniband/hw/hfi1/pio.h  |  224 
 drivers/infiniband/hw/hfi1/pio_copy.c |  867 
 3 files changed, 2855 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/pio.c
 create mode 100644 drivers/infiniband/hw/hfi1/pio.h
 create mode 100644 drivers/infiniband/hw/hfi1/pio_copy.c

diff --git a/drivers/infiniband/hw/hfi1/pio.c b/drivers/infiniband/hw/hfi1/pio.c
new file mode 100644
index 000..6d89808
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/pio.c
@@ -0,0 +1,1764 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include "hfi.h"
+#include "qp.h"
+#include "trace.h"
+
+#define SC_CTXT_PACKET_EGRESS_TIMEOUT 350 /* in chip cycles */
+
+#define SC(name) SEND_CTXT_##name
+/*
+ * Send Context functions
+ */
+static void sc_wait_for_packet_egress(struct send_context *sc, int pause);
+
+/*
+ * Set the CM reset bit and wait for it to clear.  Use the provided
+ * sendctrl register.  This routine has no locking.
+ */
+void __cm_reset(struct hfi1_devdata *dd, u64 sendctrl)
+{
+   write_csr(dd, SEND_CTRL, sendctrl | SEND_CTRL_CM_RESET_SMASK);
+   while (1) {
+   udelay(1);
+   sendctrl = read_csr(dd, SEND_CTRL);
+   if ((sendctrl & SEND_CTRL_CM_RESET_SMASK) == 0)
+   break;
+   }
+}
+
+/* defined in header release 48 and higher */
+#ifndef SEND_CTRL_UNSUPPORTED_VL_SHIFT
+#define SEND_CTRL_UNSUPPORTED_VL_SHIFT 3
+#define SEND_CTRL_UNSUPPORTED_VL_MASK 0xffull
+#define SEND_CTRL_UNSUPPORTED_VL_SMASK (SEND_CTRL_UNSUPPORTED_VL_MASK \
+   << SEND_CTRL_UNSUPPORTED_VL_SHIFT)
+#endif
+
+/* global control of PIO send */
+void pio_send_control(struct hfi1_devdata *dd, int op)
+{
+   u64 reg;
+   unsigned long flags;
+   int write = 1;  /* write sendctrl back */
+   int flush = 0;  /* re-read sendctrl to make sure it is flushed */
+
+   spin_lock_irqsave(&dd->sendctrl_lock, flags);
+
+   reg = read_csr(dd, SEND_CTRL);

[PATCH v3 31/49] IB/hfi1: add platform config definitions

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/platform_config.h |  286 ++
 1 file changed, 286 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/platform_config.h

diff --git a/drivers/infiniband/hw/hfi1/platform_config.h 
b/drivers/infiniband/hw/hfi1/platform_config.h
new file mode 100644
index 000..8a94a83
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/platform_config.h
@@ -0,0 +1,286 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef __PLATFORM_CONFIG_H
+#define __PLATFORM_CONFIG_H
+
+#define METADATA_TABLE_FIELD_START_SHIFT   0
+#define METADATA_TABLE_FIELD_START_LEN_BITS15
+#define METADATA_TABLE_FIELD_LEN_SHIFT 16
+#define METADATA_TABLE_FIELD_LEN_LEN_BITS  16
+
+/* Header structure */
+#define PLATFORM_CONFIG_HEADER_RECORD_IDX_SHIFT0
+#define PLATFORM_CONFIG_HEADER_RECORD_IDX_LEN_BITS 6
+#define PLATFORM_CONFIG_HEADER_TABLE_LENGTH_SHIFT  16
+#define PLATFORM_CONFIG_HEADER_TABLE_LENGTH_LEN_BITS   12
+#define PLATFORM_CONFIG_HEADER_TABLE_TYPE_SHIFT28
+#define PLATFORM_CONFIG_HEADER_TABLE_TYPE_LEN_BITS 4
+
+enum platform_config_table_type_encoding {
+   PLATFORM_CONFIG_TABLE_RESERVED,
+   PLATFORM_CONFIG_SYSTEM_TABLE,
+   PLATFORM_CONFIG_PORT_TABLE,
+   PLATFORM_CONFIG_RX_PRESET_TABLE,
+   PLATFORM_CONFIG_TX_PRESET_TABLE,
+   PLATFORM_CONFIG_QSFP_ATTEN_TABLE,
+   PLATFORM_CONFIG_VARIABLE_SETTINGS_TABLE,
+   PLATFORM_CONFIG_TABLE_MAX
+};
+
+enum platform_config_system_table_fields {
+   SYSTEM_TABLE_RESERVED,
+   SYSTEM_TABLE_NODE_STRING,
+   SYSTEM_TABLE_SYSTEM_IMAGE_GUID,
+   SYSTEM_TABLE_NODE_GUID,
+   SYSTEM_TABLE_REVISION,
+   SYSTEM_TABLE_VENDOR_OUI,
+   SYSTEM_TABLE_META_VERSION,
+   SYSTEM_TABLE_DEVICE_ID,
+   SYSTEM_TABLE_PARTITION_ENFORCEMENT_CAP,
+   SYSTEM_TABLE_QSFP_POWER_CLASS_MAX,
+   SYSTEM_TABLE_QSFP_ATTENUATION_DEFAULT_12G,
+   SYSTEM_TABLE_QSFP_ATTENUATION_DE

[PATCH v3 21/49] IB/hfi1: add progress delay/restart hooks

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/iowait.h |  186 +++
 1 file changed, 186 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/iowait.h

diff --git a/drivers/infiniband/hw/hfi1/iowait.h 
b/drivers/infiniband/hw/hfi1/iowait.h
new file mode 100644
index 000..fa361b4
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/iowait.h
@@ -0,0 +1,186 @@
+#ifndef _HFI1_IOWAIT_H
+#define _HFI1_IOWAIT_H
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+/*
+ * typedef (*restart_t)() - restart callback
+ * @work: pointer to work structure
+ */
+typedef void (*restart_t)(struct work_struct *work);
+
+struct sdma_txreq;
+struct sdma_engine;
+/**
+ * struct iowait - linkage for delayed progress/waiting
+ * @list: used to add/insert into QP/PQ wait lists
+ * @tx_head: overflow list of sdma_txreq's
+ * @sleep: no space callback
+ * @wakeup: space callback
+ * @iowork: workqueue overhead
+ * @wait_dma: wait for sdma_busy == 0
+ * @sdma_busy: # of packets in flight
+ * @count: total number of descriptors in tx_head'ed list
+ * @tx_limit: limit for overflow queuing
+ * @tx_count: number of tx entry's in tx_head'ed list
+ *
+ * This is to be embedded in user's state structure
+ * (QP or PQ).
+ *
+ * The sleep and wakeup members are a
+ * bit misnamed.   They do not strictly
+ * speaking sleep or wake up, but they
+ * are callbacks for the ULP to implement
+ * what ever queuing/dequeuing of
+ * the embedded iowait and its containing struct
+ * when a resource shortage like SDMA ring space is seen.
+ *
+ * Both potentially have locks help
+ * so sleeping is not allowed.
+ *
+ * The wait_dma member along with the iow
+ */
+
+struct iowait {
+   struct list_head list;
+   struct list_head tx_head;
+   int (*sleep)(
+   struct sdma_engine *sde,
+   struct iowait *wait,
+   struct sdma_txreq *tx,
+   unsigned seq);
+   void (*wakeup)(struct iowait *wait, int reason);
+   struct work_struct iowork;
+   wait_queue_head_t wa

[PATCH v3 25/49] IB/hfi1: add local mad header

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/mad.h |  285 ++
 1 file changed, 285 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/mad.h

diff --git a/drivers/infiniband/hw/hfi1/mad.h b/drivers/infiniband/hw/hfi1/mad.h
new file mode 100644
index 000..220be48
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/mad.h
@@ -0,0 +1,285 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef _HFI1_MAD_H
+#define _HFI1_MAD_H
+
+#include 
+#define USE_PI_LED_ENABLE  1 /* use led enabled bit in struct
+  * opa_port_states, if available */
+#include 
+#include 
+#ifndef PI_LED_ENABLE_SUP
+#define PI_LED_ENABLE_SUP 0
+#endif
+#include "opa_compat.h"
+
+#define IB_SMP_UNSUP_VERSIONcpu_to_be16(0x0004)
+#define IB_SMP_UNSUP_METHOD cpu_to_be16(0x0008)
+#define IB_SMP_UNSUP_METH_ATTR  cpu_to_be16(0x000C)
+#define IB_SMP_INVALID_FIELDcpu_to_be16(0x001C)
+
+#define OPA_MAX_PREEMPT_CAP 32
+#define OPA_VLARB_LOW_ELEMENTS   0
+#define OPA_VLARB_HIGH_ELEMENTS  1
+#define OPA_VLARB_PREEMPT_ELEMENTS   2
+#define OPA_VLARB_PREEMPT_MATRIX 3
+
+#define HFI1_XMIT_RATE_UNSUPPORTED   0x0
+#define HFI1_XMIT_RATE_PICO  0x7
+/* number of 4nsec cycles equaling 2secs */
+#define HFI1_CONG_TIMER_PSINTERVAL   0x1DCD64EC
+
+#define IB_CC_SVCTYPE_RC 0x0
+#define IB_CC_SVCTYPE_UC 0x1
+#define IB_CC_SVCTYPE_RD 0x2
+#define IB_CC_SVCTYPE_UD 0x3
+
+
+/*
+ * There should be an equivalent IB #define for the following, but
+ * I cannot find it.
+ */
+#define OPA_CC_LOG_TYPE_HFI2
+
+struct opa_hfi1_cong_log_event_internal {
+   u32 lqpn;
+   u32 rqpn;
+   u8 sl;
+   u8 svc_type;
+   u32 rlid;
+   s64 timestamp; /* wider than 32 bits to detect 32 bit rollover */
+};
+
+struct opa_hfi1_cong_log_event {
+   u8 local_qp_cn_entry[3];
+   u8 remote_qp_number_cn_entry[3];
+   u8 sl_svc_type_cn_entry; /* 5 bits SL, 3 bits svc type */
+   u8 reserved;
+   __be32 remote_lid_cn_entry;
+   __be

[PATCH v3 20/49] IB/hfi1: add interrupt hooks

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/intr.c |  204 +
 1 file changed, 204 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/intr.c

diff --git a/drivers/infiniband/hw/hfi1/intr.c 
b/drivers/infiniband/hw/hfi1/intr.c
new file mode 100644
index 000..4780b89
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/intr.c
@@ -0,0 +1,204 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+
+#include "hfi.h"
+#include "common.h"
+#include "sdma.h"
+
+/**
+ * format_hwmsg - format a single hwerror message
+ * @msg message buffer
+ * @msgl length of message buffer
+ * @hwmsg message to add to message buffer
+ */
+static void format_hwmsg(char *msg, size_t msgl, const char *hwmsg)
+{
+   strlcat(msg, "[", msgl);
+   strlcat(msg, hwmsg, msgl);
+   strlcat(msg, "]", msgl);
+}
+
+/**
+ * hfi1_format_hwerrors - format hardware error messages for display
+ * @hwerrs hardware errors bit vector
+ * @hwerrmsgs hardware error descriptions
+ * @nhwerrmsgs number of hwerrmsgs
+ * @msg message buffer
+ * @msgl message buffer length
+ */
+void hfi1_format_hwerrors(u64 hwerrs, const struct hfi1_hwerror_msgs 
*hwerrmsgs,
+ size_t nhwerrmsgs, char *msg, size_t msgl)
+{
+   int i;
+
+   for (i = 0; i < nhwerrmsgs; i++)
+   if (hwerrs & hwerrmsgs[i].mask)
+   format_hwmsg(msg, msgl, hwerrmsgs[i].msg);
+}
+
+static void signal_ib_event(struct hfi1_pportdata *ppd, enum ib_event_type ev)
+{
+   struct ib_event event;
+   struct hfi1_devdata *dd = ppd->dd;
+
+   /*
+* Only call ib_dispatch_event() if the IB device has been
+* registered.  HFI1_INITED is set iff the driver has successfully
+* registered with the IB core.
+*/
+   if (!(dd->flags & HFI1_INITTED))
+   return;
+   event.device = &dd->verbs_dev.ibdev;
+   event.element.port_num = ppd->port;
+   event.event = ev;
+   ib_dispatch_event(&event);
+}
+
+/*
+ * Handle a linkup or link down notificatio

[PATCH v3 15/49] IB/hfi1: add eeprom hooks

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/eprom.c |  475 
 drivers/infiniband/hw/hfi1/eprom.h |   55 
 2 files changed, 530 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/eprom.c
 create mode 100644 drivers/infiniband/hw/hfi1/eprom.h

diff --git a/drivers/infiniband/hw/hfi1/eprom.c 
b/drivers/infiniband/hw/hfi1/eprom.c
new file mode 100644
index 000..b61d3ae
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/eprom.c
@@ -0,0 +1,475 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include 
+#include "hfi.h"
+#include "common.h"
+#include "eprom.h"
+
+/*
+ * The EPROM is logically divided into two partitions:
+ * partition 0: the first 128K, visible from PCI ROM BAR
+ * partition 1: the rest
+ */
+#define P0_SIZE (128 * 1024)
+#define P1_START P0_SIZE
+
+/* largest erase size supported by the controller */
+#define SIZE_32KB (32 * 1024)
+#define MASK_32KB (SIZE_32KB - 1)
+
+/* controller page size, in bytes */
+#define EP_PAGE_SIZE 256
+#define EEP_PAGE_MASK (EP_PAGE_SIZE - 1)
+
+/* controller commands */
+#define CMD_SHIFT 24
+#define CMD_NOP(0)
+#define CMD_PAGE_PROGRAM(addr) ((0x02 << CMD_SHIFT) | addr)
+#define CMD_READ_DATA(addr)((0x03 << CMD_SHIFT) | addr)
+#define CMD_READ_SR1   ((0x05 << CMD_SHIFT))
+#define CMD_WRITE_ENABLE   ((0x06 << CMD_SHIFT))
+#define CMD_SECTOR_ERASE_32KB(addr) ((0x52 << CMD_SHIFT) | addr)
+#define CMD_CHIP_ERASE ((0x60 << CMD_SHIFT))
+#define CMD_READ_MANUF_DEV_ID  ((0x90 << CMD_SHIFT))
+#define CMD_RELEASE_POWERDOWN_NOID  ((0xab << CMD_SHIFT))
+
+/* controller interface speeds */
+#define EP_SPEED_FULL 0x2  /* full speed */
+
+/* controller status register 1 bits */
+#define SR1_BUSY 0x1ull/* the BUSY bit in SR1 */
+
+/* sleep length while waiting for controller */
+#define WAIT_SLEEP_US 100  /* must be larger than 5 (see usage) */
+#define COUNT_DELAY_SEC(n) ((n) * (100/WAIT_SLEEP_US))
+
+/* GPIO pins */
+#define EPROM_WP_N (1ull << 14)/

[PATCH v3 22/49] IB/hfi1: add rkey/lkey validation

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/keys.c |  407 +
 1 file changed, 407 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/keys.c

diff --git a/drivers/infiniband/hw/hfi1/keys.c 
b/drivers/infiniband/hw/hfi1/keys.c
new file mode 100644
index 000..3939fc1
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/keys.c
@@ -0,0 +1,407 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "hfi.h"
+
+/**
+ * hfi1_alloc_lkey - allocate an lkey
+ * @mr: memory region that this lkey protects
+ * @dma_region: 0->normal key, 1->restricted DMA key
+ *
+ * Returns 0 if successful, otherwise returns -errno.
+ *
+ * Increments mr reference count as required.
+ *
+ * Sets the lkey field mr for non-dma regions.
+ *
+ */
+
+int hfi1_alloc_lkey(struct hfi1_mregion *mr, int dma_region)
+{
+   unsigned long flags;
+   u32 r;
+   u32 n;
+   int ret = 0;
+   struct hfi1_ibdev *dev = to_idev(mr->pd->device);
+   struct hfi1_lkey_table *rkt = &dev->lk_table;
+
+   hfi1_get_mr(mr);
+   spin_lock_irqsave(&rkt->lock, flags);
+
+   /* special case for dma_mr lkey == 0 */
+   if (dma_region) {
+   struct hfi1_mregion *tmr;
+
+   tmr = rcu_access_pointer(dev->dma_mr);
+   if (!tmr) {
+   rcu_assign_pointer(dev->dma_mr, mr);
+   mr->lkey_published = 1;
+   } else {
+   hfi1_put_mr(mr);
+   }
+   goto success;
+   }
+
+   /* Find the next available LKEY */
+   r = rkt->next;
+   n = r;
+   for (;;) {
+   if (!rcu_access_pointer(rkt->table[r]))
+   break;
+   r = (r + 1) & (rkt->max - 1);
+   if (r == n)
+   goto bail;
+   }
+   rkt->next = (r + 1) & (rkt->max - 1);
+   /*
+* Make sure lkey is never zero which is reserved to indicate an
+* unrestricted LKEY.
+*/
+   rkt->gen++;
+   mr->lkey = (r << (32 - hfi1_lkey_

[PATCH v3 26/49] IB/hfi1: add user/kernel memory sharing hooks

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/mmap.c |  192 +
 1 file changed, 192 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/mmap.c

diff --git a/drivers/infiniband/hw/hfi1/mmap.c 
b/drivers/infiniband/hw/hfi1/mmap.c
new file mode 100644
index 000..5173b1c
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/mmap.c
@@ -0,0 +1,192 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "verbs.h"
+
+/**
+ * hfi1_release_mmap_info - free mmap info structure
+ * @ref: a pointer to the kref within struct hfi1_mmap_info
+ */
+void hfi1_release_mmap_info(struct kref *ref)
+{
+   struct hfi1_mmap_info *ip =
+   container_of(ref, struct hfi1_mmap_info, ref);
+   struct hfi1_ibdev *dev = to_idev(ip->context->device);
+
+   spin_lock_irq(&dev->pending_lock);
+   list_del(&ip->pending_mmaps);
+   spin_unlock_irq(&dev->pending_lock);
+
+   vfree(ip->obj);
+   kfree(ip);
+}
+
+/*
+ * open and close keep track of how many times the CQ is mapped,
+ * to avoid releasing it.
+ */
+static void hfi1_vma_open(struct vm_area_struct *vma)
+{
+   struct hfi1_mmap_info *ip = vma->vm_private_data;
+
+   kref_get(&ip->ref);
+}
+
+static void hfi1_vma_close(struct vm_area_struct *vma)
+{
+   struct hfi1_mmap_info *ip = vma->vm_private_data;
+
+   kref_put(&ip->ref, hfi1_release_mmap_info);
+}
+
+static struct vm_operations_struct hfi1_vm_ops = {
+   .open = hfi1_vma_open,
+   .close =hfi1_vma_close,
+};
+
+/**
+ * hfi1_mmap - create a new mmap region
+ * @context: the IB user context of the process making the mmap() call
+ * @vma: the VMA to be initialized
+ * Return zero if the mmap is OK. Otherwise, return an errno.
+ */
+int hfi1_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
+{
+   struct hfi1_ibdev *dev = to_idev(context->device);
+   unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+   unsigned long size = vma->vm_end - vma->vm_start;
+   

[PATCH v3 16/49] IB/hfi1: add PSM driver control/data path

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/file_ops.c | 2122 +
 1 file changed, 2122 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/file_ops.c

diff --git a/drivers/infiniband/hw/hfi1/file_ops.c 
b/drivers/infiniband/hw/hfi1/file_ops.c
new file mode 100644
index 000..8d794e8
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/file_ops.c
@@ -0,0 +1,2122 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "pio.h"
+#include "device.h"
+#include "common.h"
+#include "trace.h"
+#include "user_sdma.h"
+#include "eprom.h"
+
+#undef pr_fmt
+#define pr_fmt(fmt) DRIVER_NAME ": " fmt
+
+#define SEND_CTXT_HALT_TIMEOUT 1000 /* msecs */
+
+/*
+ * File operation functions
+ */
+static int hfi1_file_open(struct inode *, struct file *);
+static int hfi1_file_close(struct inode *, struct file *);
+static ssize_t hfi1_file_write(struct file *, const char __user *,
+  size_t, loff_t *);
+static ssize_t hfi1_write_iter(struct kiocb *, struct iov_iter *);
+static unsigned int hfi1_poll(struct file *, struct poll_table_struct *);
+static int hfi1_file_mmap(struct file *, struct vm_area_struct *);
+
+static u64 kvirt_to_phys(void *);
+static int assign_ctxt(struct file *, struct hfi1_user_info *);
+static int init_subctxts(struct hfi1_ctxtdata *, const struct hfi1_user_info 
*);
+static int user_init(struct file *);
+static int get_ctxt_info(struct file *, void __user *, __u32);
+static int get_base_info(struct file *, void __user *, __u32);
+static int setup_ctxt(struct file *);
+static int setup_subctxt(struct hfi1_ctxtdata *);
+static int get_user_context(struct file *, struct hfi1_user_info *,
+   int, unsigned);
+static int find_shared_ctxt(struct file *, const struct hfi1_user_info *);
+static int allocate_ctxt(struct file *, struct hfi1_devdata *,
+struct hfi1_us

[PATCH v3 17/49] IB/hfi1: add firmware hooks

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/firmware.c | 1550 +
 1 file changed, 1550 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/firmware.c

diff --git a/drivers/infiniband/hw/hfi1/firmware.c 
b/drivers/infiniband/hw/hfi1/firmware.c
new file mode 100644
index 000..39cafed
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/firmware.c
@@ -0,0 +1,1550 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "trace.h"
+
+/*
+ * Make it easy to toggle firmware file name and if it gets loaded by
+ * editing the following. This may be something we do while in development
+ * but not necessarily something a user would ever need to use.
+ */
+#define DEFAULT_FW_8051_NAME_FPGA "hfi_dc8051.bin"
+#define DEFAULT_FW_8051_NAME_ASIC "hfi1_dc8051.fw"
+#define DEFAULT_FW_FABRIC_NAME "hfi1_fabric.fw"
+#define DEFAULT_FW_SBUS_NAME "hfi1_sbus.fw"
+#define DEFAULT_FW_PCIE_NAME "hfi1_pcie.fw"
+#define DEFAULT_PLATFORM_CONFIG_NAME "hfi1_platform.dat"
+
+static uint fw_8051_load = 1;
+static uint fw_fabric_serdes_load = 1;
+static uint fw_pcie_serdes_load = 1;
+static uint fw_sbus_load = 1;
+static uint platform_config_load = 1;
+
+/* Firmware file names get set in hfi1_firmware_init() based on the above */
+static char *fw_8051_name;
+static char *fw_fabric_serdes_name;
+static char *fw_sbus_name;
+static char *fw_pcie_serdes_name;
+static char *platform_config_name;
+
+#define SBUS_MAX_POLL_COUNT 100
+#define SBUS_COUNTER(reg, name) \
+   (((reg) >> ASIC_STS_SBUS_COUNTERS_##name##_CNT_SHIFT) & \
+ASIC_STS_SBUS_COUNTERS_##name##_CNT_MASK)
+
+/*
+ * Firmware security header.
+ */
+struct css_header {
+   u32 module_type;
+   u32 header_len;
+   u32 header_version;
+   u32 module_id;
+   u32 module_vendor;
+   u32 date;   /* BCD mmdd */
+   u32 size;   /* in DWORDs */
+   u32 key_size;   /* in DWORDs */
+   u32 modulus_size;   /* in DWORDs */
+   u32 

[PATCH v3 19/49] IB/hfi1: add module init hooks

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/init.c | 1709 +
 1 file changed, 1709 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/init.c

diff --git a/drivers/infiniband/hw/hfi1/init.c 
b/drivers/infiniband/hw/hfi1/init.c
new file mode 100644
index 000..99eb9f1
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/init.c
@@ -0,0 +1,1709 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "device.h"
+#include "common.h"
+#include "mad.h"
+#include "sdma.h"
+#include "debugfs.h"
+#include "verbs.h"
+
+#undef pr_fmt
+#define pr_fmt(fmt) DRIVER_NAME ": " fmt
+
+/*
+ * min buffers we want to have per context, after driver
+ */
+#define HFI1_MIN_USER_CTXT_BUFCNT 7
+
+#define HFI1_MIN_HDRQ_EGRBUF_CNT 2
+#define HFI1_MIN_EAGER_BUFFER_SIZE (4 * 1024) /* 4KB */
+#define HFI1_MAX_EAGER_BUFFER_SIZE (256 * 1024) /* 256KB */
+
+/*
+ * Number of receive contexts we are configured to use (to allow for more pio
+ * buffers per ctxt, etc.)  Zero means use chip value.
+ */
+uint num_rcv_contexts;
+module_param_named(num_rcv_contexts, num_rcv_contexts, uint, S_IRUGO);
+MODULE_PARM_DESC(num_rcv_contexts, "Set max number of receive contexts to 
use");
+
+u8 krcvqs[RXE_NUM_DATA_VL];
+int krcvqsset;
+module_param_array(krcvqs, byte, &krcvqsset, S_IRUGO);
+MODULE_PARM_DESC(krcvqs, "Array of the number of kernel receive queues by VL");
+
+/* computed based on above array */
+unsigned n_krcvqs;
+
+static unsigned hfi1_rcvarr_split = 25;
+module_param_named(rcvarr_split, hfi1_rcvarr_split, uint, S_IRUGO);
+MODULE_PARM_DESC(rcvarr_split, "Percent of context's RcvArray entries used for 
Eager buffers");
+
+static uint eager_buffer_size = (2 << 20); /* 2MB */
+module_param(eager_buffer_size, uint, S_IRUGO);
+MODULE_PARM_DESC(eager_buffer_size, "Size of the eager buffers, default: 2MB");
+
+static uint rcvhdrcnt = 2048; /* 2x the max eager buffer count */
+module_param_named(rcvhdrcnt, rcvhdrcnt, uint, S_IRUGO);
+M

[PATCH v3 23/49] IB/hfi1: add OPA mad handling part1

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/mad.c | 2744 ++
 1 file changed, 2744 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/mad.c

diff --git a/drivers/infiniband/hw/hfi1/mad.c b/drivers/infiniband/hw/hfi1/mad.c
new file mode 100644
index 000..77bd455
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/mad.c
@@ -0,0 +1,2744 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#define OPA_NUM_PKEY_BLOCKS_PER_SMP (OPA_SMP_DR_DATA_SIZE \
+   / (OPA_PARTITION_TABLE_BLK_SIZE * sizeof(u16)))
+
+#include "hfi.h"
+#include "mad.h"
+#include "trace.h"
+
+/* the reset value from the FM is supposed to be 0x, handle both */
+#define OPA_LINK_WIDTH_RESET_OLD 0x0fff
+#define OPA_LINK_WIDTH_RESET 0x
+
+static int reply(struct ib_mad_hdr *smp)
+{
+   /*
+* The verbs framework will handle the directed/LID route
+* packet changes.
+*/
+   smp->method = IB_MGMT_METHOD_GET_RESP;
+   if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
+   smp->status |= IB_SMP_DIRECTION;
+   return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
+}
+
+static inline void clear_opa_smp_data(struct opa_smp *smp)
+{
+   void *data = opa_get_smp_data(smp);
+   size_t size = opa_get_smp_data_size(smp);
+
+   memset(data, 0, size);
+}
+
+static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len)
+{
+   struct ib_mad_send_buf *send_buf;
+   struct ib_mad_agent *agent;
+   struct ib_smp *smp;
+   int ret;
+   unsigned long flags;
+   unsigned long timeout;
+   int pkey_idx;
+   u32 qpn = ppd_from_ibp(ibp)->sm_trap_qp;
+
+   agent = ibp->send_agent;
+   if (!agent)
+   return;
+
+   /* o14-3.2.1 */
+   if (ppd_from_ibp(ibp)->lstate != IB_PORT_ACTIVE)
+   return;
+
+   /* o14-2 */
+   if (ibp->trap_timeout && time_before(jiffies, ibp->trap_timeout))
+   return;
+
+   pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY);
+  

[PATCH v3 18/49] IB/hfi1: add general hfi header file

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/hfi.h | 1738 ++
 1 file changed, 1738 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/hfi.h

diff --git a/drivers/infiniband/hw/hfi1/hfi.h b/drivers/infiniband/hw/hfi1/hfi.h
new file mode 100644
index 000..3ebf4ed
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/hfi.h
@@ -0,0 +1,1738 @@
+#ifndef _HFI1_KERNEL_H
+#define _HFI1_KERNEL_H
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "chip_registers.h"
+#include "common.h"
+#include "verbs.h"
+#include "pio.h"
+#include "chip.h"
+#include "mad.h"
+#include "qsfp.h"
+#include "platform_config.h"
+
+/* bumped 1 from s/w major version of TrueScale */
+#define HFI1_CHIP_VERS_MAJ 3U
+
+/* don't care about this except printing */
+#define HFI1_CHIP_VERS_MIN 0U
+
+/* The Organization Unique Identifier (Mfg code), and its position in GUID */
+#define HFI1_OUI 0x001175
+#define HFI1_OUI_LSB 40
+
+#define DROP_PACKET_OFF0
+#define DROP_PACKET_ON 1
+
+extern unsigned long hfi1_cap_mask;
+#define HFI1_CAP_KGET_MASK(mask, cap) ((mask) & HFI1_CAP_##cap)
+#define HFI1_CAP_UGET_MASK(mask, cap) \
+   (((mask) >> HFI1_CAP_USER_SHIFT) & HFI1_CAP_##cap)
+#define HFI1_CAP_KGET(cap) (HFI1_CAP_KGET_MASK(hfi1_cap_mask, cap))
+#define HFI1_CAP_UGET(cap) (HFI1_CAP_UGET_MASK(hfi1_cap_mask, cap))
+#define HFI1_CAP_IS_KSET(cap) (!!HFI1_CAP_KGET(cap))
+#define HFI1_CAP_IS_USET(cap) (!!HFI1_CAP_UGET(cap))
+#define HFI1_MISC_GET() ((hfi1_cap_mask >> HFI1_CAP_MISC_SHIFT) & \
+   HFI1_CAP_MISC_MASK)
+
+/*
+ * per driver stats, either not device nor port-specific, or
+ * summed over all of the devices and ports.
+ * They are described by name via ipathfs filesystem, so layout
+ * and number of elements can change without breaking compatibility.
+ * If members are added or deleted hfi1_statnames[] in debugfs.c must
+ 

[PATCH v3 27/49] IB/hfi1: add memory region handling

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/mr.c |  546 +++
 1 file changed, 546 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/mr.c

diff --git a/drivers/infiniband/hw/hfi1/mr.c b/drivers/infiniband/hw/hfi1/mr.c
new file mode 100644
index 000..23567f8
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/mr.c
@@ -0,0 +1,546 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+
+#include "hfi.h"
+
+/* Fast memory region */
+struct hfi1_fmr {
+   struct ib_fmr ibfmr;
+   struct hfi1_mregion mr;/* must be last */
+};
+
+static inline struct hfi1_fmr *to_ifmr(struct ib_fmr *ibfmr)
+{
+   return container_of(ibfmr, struct hfi1_fmr, ibfmr);
+}
+
+static int init_mregion(struct hfi1_mregion *mr, struct ib_pd *pd,
+   int count)
+{
+   int m, i = 0;
+   int rval = 0;
+
+   m = (count + HFI1_SEGSZ - 1) / HFI1_SEGSZ;
+   for (; i < m; i++) {
+   mr->map[i] = kzalloc(sizeof(*mr->map[0]), GFP_KERNEL);
+   if (!mr->map[i])
+   goto bail;
+   }
+   mr->mapsz = m;
+   init_completion(&mr->comp);
+   /* count returning the ptr to user */
+   atomic_set(&mr->refcount, 1);
+   mr->pd = pd;
+   mr->max_segs = count;
+out:
+   return rval;
+bail:
+   while (i)
+   kfree(mr->map[--i]);
+   rval = -ENOMEM;
+   goto out;
+}
+
+static void deinit_mregion(struct hfi1_mregion *mr)
+{
+   int i = mr->mapsz;
+
+   mr->mapsz = 0;
+   while (i)
+   kfree(mr->map[--i]);
+}
+
+
+/**
+ * hfi1_get_dma_mr - get a DMA memory region
+ * @pd: protection domain for this memory region
+ * @acc: access flags
+ *
+ * Returns the memory region on success, otherwise returns an errno.
+ * Note that all DMA addresses should be created via the
+ * struct ib_dma_mapping_ops functions (see dma.c).
+ */
+struct ib_mr *hfi1_get_dma_mr(struct ib_pd *pd, int acc)
+{
+   struct hfi1_mr *mr = NULL;
+   struct ib_mr *ret;
+   int rval;
+
+   

[PATCH v3 28/49] IB/hfi1: add misc OPA defines

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/opa_compat.h |  132 +++
 1 file changed, 132 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/opa_compat.h

diff --git a/drivers/infiniband/hw/hfi1/opa_compat.h 
b/drivers/infiniband/hw/hfi1/opa_compat.h
new file mode 100644
index 000..c60ab08
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/opa_compat.h
@@ -0,0 +1,132 @@
+#ifndef _LINUX_H
+#define _LINUX_H
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * This header file is for OPA-specific definitions which are
+ * required by the HFI driver, and which aren't yet in the Linux
+ * IB core. We'll collect these all here, then merge them into
+ * the kernel when that's convenient.
+ */
+
+/* OPA SMA attribute IDs */
+#define OPA_ATTRIB_ID_CONGESTION_INFO  cpu_to_be16(0x008b)
+#define OPA_ATTRIB_ID_HFI_CONGESTION_LOG   cpu_to_be16(0x008f)
+#define OPA_ATTRIB_ID_HFI_CONGESTION_SETTING   cpu_to_be16(0x0090)
+#define OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE cpu_to_be16(0x0091)
+
+/* OPA PMA attribute IDs */
+#define OPA_PM_ATTRIB_ID_PORT_STATUS   cpu_to_be16(0x0040)
+#define OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS cpu_to_be16(0x0041)
+#define OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERScpu_to_be16(0x0042)
+#define OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS   cpu_to_be16(0x0043)
+#define OPA_PM_ATTRIB_ID_ERROR_INFOcpu_to_be16(0x0044)
+
+/* OPA status codes */
+#define OPA_PM_STATUS_REQUEST_TOO_LARGEcpu_to_be16(0x100)
+
+static inline u8 port_states_to_logical_state(struct opa_port_states *ps)
+{
+   return ps->portphysstate_portstate & OPA_PI_MASK_PORT_STATE;
+}
+
+static inline u8 port_states_to_phys_state(struct opa_port_states *ps)
+{
+   return ((ps->portphysstate_portstate &
+ OPA_PI_MASK_PORT_PHYSICAL_STATE) >> 4) & 0xf;
+}
+
+/*
+ * OPA port physical states
+ * IB Volume 1, Table 146 PortInfo/IB Volume 2 Section 5.4.2(1) PortPhysState
+ * values.
+ *
+ * When writing, only values 0-3 are valid, other values are ignored.
+ * When reading, 0 is re

[PATCH v3 24/49] IB/hfi1: add OPA mad handling part2

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/mad.c | 1343 ++
 1 file changed, 1343 insertions(+)

diff --git a/drivers/infiniband/hw/hfi1/mad.c b/drivers/infiniband/hw/hfi1/mad.c
index 77bd455..28bef38 100644
--- a/drivers/infiniband/hw/hfi1/mad.c
+++ b/drivers/infiniband/hw/hfi1/mad.c
@@ -2742,3 +2742,1346 @@ static int pma_get_opa_errorinfo(struct opa_pma_mad 
*pmp,
 
tmp &=  RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SC_SMASK;
tmp <<= 2;
+   rsp->excessive_buffer_overrun_ei.status_and_sc = tmp;
+   /* set the status bit */
+   rsp->excessive_buffer_overrun_ei.status_and_sc |= 0x80;
+   }
+
+   rsp->port_xmit_constraint_ei.status =
+   dd->err_info_xmit_constraint.status;
+   rsp->port_xmit_constraint_ei.pkey =
+   cpu_to_be16(dd->err_info_xmit_constraint.pkey);
+   rsp->port_xmit_constraint_ei.slid =
+   cpu_to_be32(dd->err_info_xmit_constraint.slid);
+
+   rsp->port_rcv_constraint_ei.status =
+   dd->err_info_rcv_constraint.status;
+   rsp->port_rcv_constraint_ei.pkey =
+   cpu_to_be16(dd->err_info_rcv_constraint.pkey);
+   rsp->port_rcv_constraint_ei.slid =
+   cpu_to_be32(dd->err_info_rcv_constraint.slid);
+
+   /* UncorrectableErrorInfo */
+   rsp->uncorrectable_ei.status_and_code = dd->err_info_uncorrectable;
+
+   /* FMConfigErrorInfo */
+   rsp->fm_config_ei.status_and_code = dd->err_info_fmconfig;
+
+   return reply((struct ib_mad_hdr *)pmp);
+}
+
+static int pma_set_opa_portstatus(struct opa_pma_mad *pmp,
+ struct ib_device *ibdev, u8 port)
+{
+   struct opa_clear_port_status *req =
+   (struct opa_clear_port_status *)pmp->data;
+   struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
+   struct hfi1_ibport *ibp = to_iport(ibdev, port);
+   struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
+   u32 nports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24;
+   u64 portn = be64_to_cpu(req->port_select_mask[3]);
+   u32 counter_select = be32_to_cpu(req->counter_select_mask);
+   u32 vl_select_mask = VL_MASK_ALL; /* clear all per-vl cnts */
+   unsigned long vl;
+
+   if ((nports != 1) || (portn != 1 << port)) {
+   pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD;
+   return reply((struct ib_mad_hdr *)pmp);
+   }
+   /*
+* only counters returned by pma_get_opa_portstatus() are
+* handled, so when pma_get_opa_portstatus() gets a fix,
+* the corresponding change should be made here as well.
+*/
+
+
+   if (counter_select & CS_PORT_XMIT_DATA)
+   write_dev_cntr(dd, C_DC_XMIT_FLITS, CNTR_INVALID_VL, 0);
+
+   if (counter_select & CS_PORT_RCV_DATA)
+   write_dev_cntr(dd, C_DC_RCV_FLITS, CNTR_INVALID_VL, 0);
+
+   if (counter_select & CS_PORT_XMIT_PKTS)
+   write_dev_cntr(dd, C_DC_XMIT_PKTS, CNTR_INVALID_VL, 0);
+
+   if (counter_select & CS_PORT_RCV_PKTS)
+   write_dev_cntr(dd, C_DC_RCV_PKTS, CNTR_INVALID_VL, 0);
+
+   if (counter_select & CS_PORT_MCAST_XMIT_PKTS)
+   write_dev_cntr(dd, C_DC_MC_XMIT_PKTS, CNTR_INVALID_VL, 0);
+
+   if (counter_select & CS_PORT_MCAST_RCV_PKTS)
+   write_dev_cntr(dd, C_DC_MC_RCV_PKTS, CNTR_INVALID_VL, 0);
+
+   if (counter_select & CS_PORT_XMIT_WAIT)
+   write_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL, 0);
+
+   /* ignore cs_sw_portCongestion for HFIs */
+
+   if (counter_select & CS_PORT_RCV_FECN)
+   write_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL, 0);
+
+   if (counter_select & CS_PORT_RCV_BECN)
+   write_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL, 0);
+
+   /* ignore cs_port_xmit_time_cong for HFIs */
+   /* ignore cs_port_xmit_wasted_bw for now */
+   /* ignore cs_port_xmit_wait_data for now */
+   if (counter_select & CS_PORT_RCV_BUBBLE)
+   write_dev_cntr(dd, C_DC_RCV_BBL, CNTR_INVALID_VL, 0);
+
+   /* Only applicable for switch */
+   /*if (counter_select & CS_PORT_MARK_FECN)
+   write_csr(dd, DCC_PRF_PORT_MARK_FECN_CNT, 0);*/
+
+   if (counter_select & CS_POR

[PATCH v3 13/49] IB/hfi1: add dma operation hooks

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/dma.c |  185 ++
 1 file changed, 185 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/dma.c

diff --git a/drivers/infiniband/hw/hfi1/dma.c b/drivers/infiniband/hw/hfi1/dma.c
new file mode 100644
index 000..6e86a71
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/dma.c
@@ -0,0 +1,185 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include 
+#include 
+
+#include "verbs.h"
+
+#define BAD_DMA_ADDRESS ((u64) 0)
+
+/*
+ * The following functions implement driver specific replacements
+ * for the ib_dma_*() functions.
+ *
+ * These functions return kernel virtual addresses instead of
+ * device bus addresses since the driver uses the CPU to copy
+ * data instead of using hardware DMA.
+ */
+
+static int hfi1_mapping_error(struct ib_device *dev, u64 dma_addr)
+{
+   return dma_addr == BAD_DMA_ADDRESS;
+}
+
+static u64 hfi1_dma_map_single(struct ib_device *dev, void *cpu_addr,
+  size_t size, enum dma_data_direction direction)
+{
+   BUG_ON(!valid_dma_direction(direction));
+   return (u64) cpu_addr;
+}
+
+static void hfi1_dma_unmap_single(struct ib_device *dev, u64 addr, size_t size,
+ enum dma_data_direction direction)
+{
+   BUG_ON(!valid_dma_direction(direction));
+}
+
+static u64 hfi1_dma_map_page(struct ib_device *dev, struct page *page,
+unsigned long offset, size_t size,
+   enum dma_data_direction direction)
+{
+   u64 addr;
+
+   BUG_ON(!valid_dma_direction(direction));
+
+   if (offset + size > PAGE_SIZE) {
+   addr = BAD_DMA_ADDRESS;
+   goto done;
+   }
+
+   addr = (u64) page_address(page);
+   if (addr)
+   addr += offset;
+
+done:
+   return addr;
+}
+
+static void hfi1_dma_unmap_page(struct ib_device *dev, u64 addr, size_t size,
+   enum dma_data_direction direction)
+{
+   BUG_ON(!valid_dma_direction(direction));
+}
+

[PATCH v3 14/49] IB/hfi1: add low lower receive functions

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/driver.c | 1061 +++
 1 file changed, 1061 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/driver.c

diff --git a/drivers/infiniband/hw/hfi1/driver.c 
b/drivers/infiniband/hw/hfi1/driver.c
new file mode 100644
index 000..6db7668
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/driver.c
@@ -0,0 +1,1061 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "trace.h"
+#include "qp.h"
+#include "sdma.h"
+
+#undef pr_fmt
+#define pr_fmt(fmt) DRIVER_NAME ": " fmt
+
+/*
+ * The size has to be longer than this string, so we can append
+ * board/chip information to it in the initialization code.
+ */
+const char ib_hfi1_version[] = HFI1_DRIVER_VERSION "\n";
+
+DEFINE_SPINLOCK(hfi1_devs_lock);
+LIST_HEAD(hfi1_dev_list);
+DEFINE_MUTEX(hfi1_mutex);  /* general driver use */
+
+unsigned int hfi1_max_mtu;
+module_param_named(max_mtu, hfi1_max_mtu, uint, S_IRUGO);
+MODULE_PARM_DESC(max_mtu, "Set max MTU bytes, default is 8192");
+
+unsigned int hfi1_cu = 1;
+module_param_named(cu, hfi1_cu, uint, S_IRUGO);
+MODULE_PARM_DESC(cu, "Credit return units");
+
+unsigned long hfi1_cap_mask = HFI1_CAP_MASK_DEFAULT;
+static int hfi1_caps_set(const char *, const struct kernel_param *);
+static int hfi1_caps_get(char *, const struct kernel_param *);
+static const struct kernel_param_ops cap_ops = {
+   .set = hfi1_caps_set,
+   .get = hfi1_caps_get
+};
+module_param_cb(cap_mask, &cap_ops, &hfi1_cap_mask, S_IWUSR | S_IRUGO);
+MODULE_PARM_DESC(cap_mask, "Bit mask of enabled/disabled HW features");
+
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_DESCRIPTION("Intel Omni-Path Architecture driver");
+MODULE_VERSION(HFI1_DRIVER_VERSION);
+
+/*
+ * MAX_PKT_RCV is the max # if packets processed per receive interrupt.
+ */
+#define MAX_PKT_RECV 64
+#define EGR_HEAD_UPDATE_THRESHOLD 16
+
+struct hfi1_ib_stats hfi1_stats;
+
+static int hfi1_caps_set(const char *val, const st

[PATCH v3 12/49] IB/hfi1: add diagnostic hooks

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/diag.c | 1873 +
 1 file changed, 1873 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/diag.c

diff --git a/drivers/infiniband/hw/hfi1/diag.c 
b/drivers/infiniband/hw/hfi1/diag.c
new file mode 100644
index 000..6461fd4
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/diag.c
@@ -0,0 +1,1873 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * This file contains support for diagnostic functions.  It is accessed by
+ * opening the hfi1_diag device, normally minor number 129.  Diagnostic use
+ * of the chip may render the chip or board unusable until the driver
+ * is unloaded, or in some cases, until the system is rebooted.
+ *
+ * Accesses to the chip through this interface are not similar to going
+ * through the /sys/bus/pci resource mmap interface.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "hfi.h"
+#include "device.h"
+#include "common.h"
+#include "trace.h"
+
+#undef pr_fmt
+#define pr_fmt(fmt) DRIVER_NAME ": " fmt
+#define snoop_dbg(fmt, ...) \
+   hfi1_cdbg(SNOOP, fmt, ##__VA_ARGS__)
+
+/* Snoop option mask */
+#define SNOOP_DROP_SEND(1 << 0)
+#define SNOOP_USE_METADATA (1 << 1)
+
+static u8 snoop_flags;
+
+/*
+ * Extract packet length from LRH header.
+ * Why & 0x7FF? Because len is only 11 bits in case it wasn't 0'd we throw the
+ * bogus bits away. This is in Dwords so multiply by 4 to get size in bytes
+ */
+#define HFI1_GET_PKT_LEN(x)  (((be16_to_cpu((x)->lrh[2]) & 0x7FF)) << 2)
+
+enum hfi1_filter_status {
+   HFI1_FILTER_HIT,
+   HFI1_FILTER_ERR,
+   HFI1_FILTER_MISS
+};
+
+/* snoop processing functions */
+rhf_rcv_function_ptr snoop_rhf_rcv_functions[8] = {
+   [RHF_RCV_TYPE_EXPECTED] = snoop_recv_handler,
+   [RHF_RCV_TYPE_EAGER]= snoop_recv_handler,
+   [RHF_RCV_TYPE_IB]   = snoop_recv_handler,
+   [RHF_RCV_TYPE_ERROR]= snoop_recv_handler,
+   [RHF_RCV_TYPE_BYPASS]   = snoop_recv_handler,
+  

[PATCH v3 11/49] IB/hfi1: add char device instantiation code

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/device.c |  142 +++
 drivers/infiniband/hw/hfi1/device.h |   61 +++
 2 files changed, 203 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/device.c
 create mode 100644 drivers/infiniband/hw/hfi1/device.h

diff --git a/drivers/infiniband/hw/hfi1/device.c 
b/drivers/infiniband/hw/hfi1/device.c
new file mode 100644
index 000..07c87a87
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/device.c
@@ -0,0 +1,142 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "device.h"
+
+static struct class *class;
+static dev_t hfi1_dev;
+
+int hfi1_cdev_init(int minor, const char *name,
+  const struct file_operations *fops,
+  struct cdev *cdev, struct device **devp)
+{
+   const dev_t dev = MKDEV(MAJOR(hfi1_dev), minor);
+   struct device *device = NULL;
+   int ret;
+
+   cdev_init(cdev, fops);
+   cdev->owner = THIS_MODULE;
+   kobject_set_name(&cdev->kobj, name);
+
+   ret = cdev_add(cdev, dev, 1);
+   if (ret < 0) {
+   pr_err("Could not add cdev for minor %d, %s (err %d)\n",
+  minor, name, -ret);
+   goto done;
+   }
+
+   device = device_create(class, NULL, dev, NULL, "%s", name);
+   if (!IS_ERR(device))
+   goto done;
+   ret = PTR_ERR(device);
+   device = NULL;
+   pr_err("Could not create device for minor %d, %s (err %d)\n",
+  minor, name, -ret);
+   cdev_del(cdev);
+done:
+   *devp = device;
+   return ret;
+}
+
+void hfi1_cdev_cleanup(struct cdev *cdev, struct device **devp)
+{
+   struct device *device = *devp;
+
+   if (device) {
+   device_unregister(device);
+   *devp = NULL;
+
+   cdev_del(cdev);
+   }
+}
+
+static const char *hfi1_class_name = "hfi1";
+
+const char *class_name(void)
+{
+   return hfi1_class_name;
+}
+
+int __init dev_init(void)
+{
+  

[PATCH v3 10/49] IB/hfi1: add debugfs handling

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/debugfs.c |  899 ++
 drivers/infiniband/hw/hfi1/debugfs.h |   78 +++
 2 files changed, 977 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/debugfs.c
 create mode 100644 drivers/infiniband/hw/hfi1/debugfs.h

diff --git a/drivers/infiniband/hw/hfi1/debugfs.c 
b/drivers/infiniband/hw/hfi1/debugfs.c
new file mode 100644
index 000..acd2269
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/debugfs.c
@@ -0,0 +1,899 @@
+#ifdef CONFIG_DEBUG_FS
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "debugfs.h"
+#include "device.h"
+#include "qp.h"
+#include "sdma.h"
+
+static struct dentry *hfi1_dbg_root;
+
+#define private2dd(file) (file_inode(file)->i_private)
+#define private2ppd(file) (file_inode(file)->i_private)
+
+#define DEBUGFS_SEQ_FILE_OPS(name) \
+static const struct seq_operations _##name##_seq_ops = { \
+   .start = _##name##_seq_start, \
+   .next  = _##name##_seq_next, \
+   .stop  = _##name##_seq_stop, \
+   .show  = _##name##_seq_show \
+}
+#define DEBUGFS_SEQ_FILE_OPEN(name) \
+static int _##name##_open(struct inode *inode, struct file *s) \
+{ \
+   struct seq_file *seq; \
+   int ret; \
+   ret =  seq_open(s, &_##name##_seq_ops); \
+   if (ret) \
+   return ret; \
+   seq = s->private_data; \
+   seq->private = inode->i_private; \
+   return 0; \
+}
+
+#define DEBUGFS_FILE_OPS(name) \
+static const struct file_operations _##name##_file_ops = { \
+   .owner   = THIS_MODULE, \
+   .open= _##name##_open, \
+   .read= seq_read, \
+   .llseek  = seq_lseek, \
+   .release = seq_release \
+}
+
+#define DEBUGFS_FILE_CREATE(name, parent, data, ops, mode) \
+do { \
+   struct dentry *ent; \
+   ent = debugfs_create_file(name, mode, parent, \
+   data, ops); \
+   if (!ent) \
+   pr_warn("create of %s failed\n", name); \
+} while (0)
+
+
+#define DEBUGFS_SEQ_FILE_CREATE(

[PATCH v3 08/49] IB/hfi1: add common header file definitions

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/common.h |  416 +++
 1 file changed, 416 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/common.h

diff --git a/drivers/infiniband/hw/hfi1/common.h 
b/drivers/infiniband/hw/hfi1/common.h
new file mode 100644
index 000..161af4c
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/common.h
@@ -0,0 +1,416 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _COMMON_H
+#define _COMMON_H
+
+#include 
+
+/*
+ * This file contains defines, structures, etc. that are used
+ * to communicate between kernel and user code.
+ */
+
+/* version of protocol header (known to chip also). In the long run,
+ * we should be able to generate and accept a range of version numbers;
+ * for now we only accept one, and it's compiled in.
+ */
+#define IPS_PROTO_VERSION 2
+
+/*
+ * These are compile time constants that you may want to enable or disable
+ * if you are trying to debug problems with code or performance.
+ * HFI1_VERBOSE_TRACING define as 1 if you want additional tracing in
+ * fast path code
+ * HFI1_TRACE_REGWRITES define as 1 if you want register writes to be
+ * traced in fast path code
+ * _HFI1_TRACING define as 0 if you want to remove all tracing in a
+ * compilation unit
+ */
+
+/*
+ * If a packet's QP[23:16] bits match this value, then it is
+ * a PSM packet and the hardware will expect a KDETH header
+ * following the BTH.
+ */
+#define DEFAULT_KDETH_QP 0x80
+
+/* driver/hw feature set bitmask */
+#define HFI1_CAP_USER_SHIFT  24
+#define HFI1_CAP_MASK((1UL << HFI1_CAP_USER_SHIFT) - 1)
+/* locked flag - if set, only HFI1_CAP_WRITABLE_MASK bits can be set */
+#define HFI1_CAP_LOCKED_SHIFT63
+#define HFI1_CAP_LOCKED_MASK 0x1ULL
+#define HFI1_CAP_LOCKED_SMASK(HFI1_CAP_LOCKED_MASK << 
HFI1_CAP_LOCKED_SHIFT)
+/* extra bits used between kernel and user processes */
+#define HFI1_CAP_MISC_SHIFT  (HFI1_CAP_USER_SHIFT * 2)
+#define HFI1_CAP_MISC_MASK   ((1ULL << (HFI1_CAP_LOCKED_SHIFT - \
+ 

[PATCH v3 09/49] IB/hfi1: add completion queue processing

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/cq.c |  558 +++
 1 file changed, 558 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/cq.c

diff --git a/drivers/infiniband/hw/hfi1/cq.c b/drivers/infiniband/hw/hfi1/cq.c
new file mode 100644
index 000..4f046ff
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/cq.c
@@ -0,0 +1,558 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "verbs.h"
+#include "hfi.h"
+
+/**
+ * hfi1_cq_enter - add a new entry to the completion queue
+ * @cq: completion queue
+ * @entry: work completion entry to add
+ * @sig: true if @entry is a solicited entry
+ *
+ * This may be called with qp->s_lock held.
+ */
+void hfi1_cq_enter(struct hfi1_cq *cq, struct ib_wc *entry, int solicited)
+{
+   struct hfi1_cq_wc *wc;
+   unsigned long flags;
+   u32 head;
+   u32 next;
+
+   spin_lock_irqsave(&cq->lock, flags);
+
+   /*
+* Note that the head pointer might be writable by user processes.
+* Take care to verify it is a sane value.
+*/
+   wc = cq->queue;
+   head = wc->head;
+   if (head >= (unsigned) cq->ibcq.cqe) {
+   head = cq->ibcq.cqe;
+   next = 0;
+   } else
+   next = head + 1;
+   if (unlikely(next == wc->tail)) {
+   spin_unlock_irqrestore(&cq->lock, flags);
+   if (cq->ibcq.event_handler) {
+   struct ib_event ev;
+
+   ev.device = cq->ibcq.device;
+   ev.element.cq = &cq->ibcq;
+   ev.event = IB_EVENT_CQ_ERR;
+   cq->ibcq.event_handler(&ev, cq->ibcq.cq_context);
+   }
+   return;
+   }
+   if (cq->ip) {
+   wc->uqueue[head].wr_id = entry->wr_id;
+   wc->uqueue[head].status = entry->status;
+   wc->uqueue[head].opcode = entry->opcode;
+   wc->uqueue[head].vendor_err = entry->vendor_err;
+   wc->uqueue

[PATCH v3 02/49] IB/hfi1: add chip specific support part1

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/chip.c | 2142 +
 1 file changed, 2142 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/chip.c

diff --git a/drivers/infiniband/hw/hfi1/chip.c 
b/drivers/infiniband/hw/hfi1/chip.c
new file mode 100644
index 000..2bb026d
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/chip.c
@@ -0,0 +1,2142 @@
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * This file contains all of the code that is specific to the HFI chip
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "hfi.h"
+#include "trace.h"
+#include "mad.h"
+#include "pio.h"
+#include "sdma.h"
+#include "eprom.h"
+
+#define NUM_IB_PORTS 1
+
+uint kdeth_qp;
+module_param_named(kdeth_qp, kdeth_qp, uint, S_IRUGO);
+MODULE_PARM_DESC(kdeth_qp, "Set the KDETH queue pair prefix");
+
+uint num_vls = 8;
+module_param(num_vls, uint, S_IRUGO);
+MODULE_PARM_DESC(num_vls, "Set number of Virtual Lanes to use (1-8)");
+
+/*
+ * Default time to aggregate two 10K packets from the idle state
+ * (timer not running). The timer starts at the end of the first packet,
+ * so only the time for one 10K packet and header plus a bit extra is needed.
+ * 10 * 1024 + 64 header byte = 10304 byte
+ * 10304 byte / 12.5 GB/s = 824.32ns
+ */
+uint rcv_intr_timeout = (824 + 16); /* 16 is for coalescing interrupt */
+module_param(rcv_intr_timeout, uint, S_IRUGO);
+MODULE_PARM_DESC(rcv_intr_timeout, "Receive interrupt mitigation timeout in 
ns");
+
+uint rcv_intr_count = 16; /* same as qib */
+module_param(rcv_intr_count, uint, S_IRUGO);
+MODULE_PARM_DESC(rcv_intr_count, "Receive interrupt mitigation count");
+
+ushort link_crc_mask = SUPPORTED_CRCS;
+module_param(link_crc_mask, ushort, S_IRUGO);
+MODULE_PARM_DESC(link_crc_mask, "CRCs to use on the link");
+
+uint loopback;
+module_param_named(loopback, loopback, uint, S_IRUGO);
+MODULE_PARM_DESC(loopback, "Put into loopback mode (1 = serdes, 3 = external 
cable");
+
+/* Other driver tunables */
+uint rcv_intr_dynamic = 1; /* enable dynamic mode for rcv int mitigation*/
+s

[PATCH v3 07/49] IB/hfi1: add chip specific headers

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/chip.h | 1013 +
 1 file changed, 1013 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/chip.h

diff --git a/drivers/infiniband/hw/hfi1/chip.h 
b/drivers/infiniband/hw/hfi1/chip.h
new file mode 100644
index 000..8cb1dfc
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/chip.h
@@ -0,0 +1,1013 @@
+#ifndef _CHIP_H
+#define _CHIP_H
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/*
+ * This file contains all of the defines that is specific to the HFI chip
+ */
+
+/* sizes */
+#define CCE_NUM_MSIX_VECTORS 256
+#define CCE_NUM_INT_CSRS 12
+#define CCE_NUM_INT_MAP_CSRS 96
+#define NUM_INTERRUPT_SOURCES 768
+#define RXE_NUM_CONTEXTS 160
+#define RXE_PER_CONTEXT_SIZE 0x1000/* 4k */
+#define RXE_NUM_TID_FLOWS 32
+#define RXE_NUM_DATA_VL 8
+#define TXE_NUM_CONTEXTS 160
+#define TXE_NUM_SDMA_ENGINES 16
+#define NUM_CONTEXTS_PER_SET 8
+#define VL_ARB_HIGH_PRIO_TABLE_SIZE 16
+#define VL_ARB_LOW_PRIO_TABLE_SIZE 16
+#define VL_ARB_TABLE_SIZE 16
+#define TXE_NUM_32_BIT_COUNTER 7
+#define TXE_NUM_64_BIT_COUNTER 30
+#define TXE_NUM_DATA_VL 8
+#define TXE_PIO_SIZE (32 * 0x10)   /* 32 MB */
+#define PIO_BLOCK_SIZE 64  /* bytes */
+#define SDMA_BLOCK_SIZE 64 /* bytes */
+#define RCV_BUF_BLOCK_SIZE 64   /* bytes */
+#define PIO_CMASK 0x7ff/* counter mask for free and fill counters */
+#define MAX_EAGER_ENTRIES2048  /* max receive eager entries */
+#define MAX_TID_PAIR_ENTRIES 1024  /* max receive expected pairs */
+/* Virtual? Allocation Unit, defined as AU = 8*2^vAU, 64 bytes, AU is fixed
+   at 64 bytes for all generation one devices */
+#define CM_VAU 3
+/* HFI link credit count, AKA receive buffer depth (RBUF_DEPTH) */
+#define CM_GLOBAL_CREDITS 0x940
+/* Number of PKey entries in the HW */
+#define MAX_PKEY_VALUES 16
+
+#include "chip_registers.h"
+
+#define RXE_PER_CONTEXT_USER   (RXE + RXE_PER_CONTEXT_OFFSET)
+#define TXE_PIO_SEND (TXE + TXE_PIO_SEND_OFFSET)
+
+/* PBC flags */
+#define PBC

[PATCH v3 05/49] IB/hfi1: add chip specific support part4

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/chip.c | 2613 +
 1 file changed, 2613 insertions(+)

diff --git a/drivers/infiniband/hw/hfi1/chip.c 
b/drivers/infiniband/hw/hfi1/chip.c
index 7019499..bf40a14 100644
--- a/drivers/infiniband/hw/hfi1/chip.c
+++ b/drivers/infiniband/hw/hfi1/chip.c
@@ -8011,3 +8011,2616 @@ static int init_cntrs(struct hfi1_devdata *dd)
}
}
 
+   /* allocate space for the counter values */
+   dd->cntrs = kcalloc(index, sizeof(u64), GFP_KERNEL);
+   if (!dd->cntrs)
+   goto bail;
+
+   dd->scntrs = kcalloc(index, sizeof(u64), GFP_KERNEL);
+   if (!dd->scntrs)
+   goto bail;
+
+
+   /* allocate space for the counter names */
+   dd->cntrnameslen = sz;
+   dd->cntrnames = kmalloc(sz, GFP_KERNEL);
+   if (!dd->cntrnames)
+   goto bail;
+
+   /* fill in the names */
+   for (p = dd->cntrnames, i = 0, index = 0; i < DEV_CNTR_LAST; i++) {
+   if (dev_cntrs[i].flags & CNTR_DISABLED) {
+   /* Nothing */
+   } else {
+   if (dev_cntrs[i].flags & CNTR_VL) {
+   for (j = 0; j < C_VL_COUNT; j++) {
+   memset(name, '\0', C_MAX_NAME);
+   snprintf(name, C_MAX_NAME, "%s%d",
+   dev_cntrs[i].name,
+   vl_from_idx(j));
+   memcpy(p, name, strlen(name));
+   p += strlen(name);
+   *p++ = '\n';
+   }
+   } else {
+   memcpy(p, dev_cntrs[i].name,
+  strlen(dev_cntrs[i].name));
+   p += strlen(dev_cntrs[i].name);
+   *p++ = '\n';
+   }
+   index++;
+   }
+   }
+
+   /*/
+   /* per port counters */
+   /*/
+
+   /*
+* Go through the counters for the overflows and disable the ones we
+* don't need. This varies based on platform so we need to do it
+* dynamically here.
+*/
+   rcv_ctxts = dd->num_rcv_contexts;
+   for (i = C_RCV_HDR_OVF_FIRST + rcv_ctxts;
+i <= C_RCV_HDR_OVF_LAST; i++) {
+   port_cntrs[i].flags |= CNTR_DISABLED;
+   }
+
+   /* size port counter names and determine how many we have*/
+   sz = 0;
+   dd->nportcntrs = 0;
+   for (i = 0; i < PORT_CNTR_LAST; i++) {
+   hfi1_dbg_early("Init pcntr %s\n", port_cntrs[i].name);
+   if (port_cntrs[i].flags & CNTR_DISABLED) {
+   hfi1_dbg_early("\tSkipping %s\n", port_cntrs[i].name);
+   continue;
+   }
+
+   if (port_cntrs[i].flags & CNTR_VL) {
+   hfi1_dbg_early("\tProcessing VL cntr\n");
+   port_cntrs[i].offset = dd->nportcntrs;
+   for (j = 0; j < C_VL_COUNT; j++) {
+   memset(name, '\0', C_MAX_NAME);
+   snprintf(name, C_MAX_NAME, "%s%d",
+   port_cntrs[i].name,
+   vl_from_idx(j));
+   sz += strlen(name);
+   sz++;
+   hfi1_dbg_early("\t\t%s\n", name);
+   dd->nportcntrs++;
+   }
+   } else {
+   /* +1 for newline  */
+   sz += strlen(port_cntrs[i].name) + 1;
+   port_cntrs[i].offset = dd->nportcntrs;
+   dd->nportcntrs++;
+   hfi1_dbg_early("\tAdding %s\n", port_cntrs[i].name);
+   }
+   }
+
+   /* allocate space for the counter names */
+   dd->portcntrnameslen = sz;
+   dd->portcntrnames = kmalloc(sz, GFP_KERNEL);
+   if (!dd->portcntrnames)
+   goto bail;
+
+   /* fill i

[PATCH v3 00/49] Add OPA gen1 driver

2015-06-17 Thread Mike Marciniszyn
This patch series adds the OPA gen1 driver.

The patches are based on the the following repo/branch:
git://github.com/dledford/linux.git: to-be-rebased/for-4.2

The patches add the files and headers and the last
patch add the build hooks.

Comments address:
- Remove verbs sysfs counters since they can be metered via other mechanisms
- Move ib-ish defintions from mad.h to ib_mad.h since they are driver
  independent
- Modified create_cq to better implements the API changes

Differences from v2 to v3:
- Remove verbs counters since they can be metered via other mechanisms
- Move ib-ish defintions from mad.h to ib_mad.h
  independent
- Modified create_cq to better implements the API changes
  
Differences from v1 to v2:
- larger files split are split up due to filesize issues
- 0 day build issues with cpumask usage
- 0 day RCU sparse issues
- Adjustments for create_cq() and query_device() to compile

---

Ira Weiny (1):
  IB/core: Add header definitions

Jubin John (1):
  IB/core: Add opa driver to kbuild

Mike Marciniszyn (47):
  IB/hfi1: add chip specific support part1
  IB/hfi1: add chip specific support part2
  IB/hfi1: add chip specific support part3
  IB/hfi1: add chip specific support part4
  IB/hfi1: add chip register definitions
  IB/hfi1: add chip specific headers
  IB/hfi1: add common header file definitions
  IB/hfi1: add completion queue processing
  IB/hfi1: add debugfs handling
  IB/hfi1: add char device instantiation code
  IB/hfi1: add diagnostic hooks
  IB/hfi1: add dma operation hooks
  IB/hfi1: add low lower receive functions
  IB/hfi1: add eeprom hooks
  IB/hfi1: add PSM driver control/data path
  IB/hfi1: add firmware hooks
  IB/hfi1: add general hfi header file
  IB/hfi1: add module init hooks
  IB/hfi1: add interrupt hooks
  IB/hfi1: add progress delay/restart hooks
  IB/hfi1: add rkey/lkey validation
  IB/hfi1: add OPA mad handling part1
  IB/hfi1: add OPA mad handling part2
  IB/hfi1: add local mad header
  IB/hfi1: add user/kernel memory sharing hooks
  IB/hfi1: add memory region handling
  IB/hfi1: add misc OPA defines
  IB/hfi1: add pcie routines
  IB/hfi1: add pio handling
  IB/hfi1: add platform config definitions
  IB/hfi1: add qp handling
  IB/hfi1: add qsfp handling
  IB/hfi1: add RC QP handling
  IB/hfi1: add routines for RC/UC
  IB/hfi1: add sdma routines
  IB/hfi1: add sdma header file
  IB/hfi1: add SRQ handling
  IB/hfi1: add sysfs routines
  IB/hfi1: add tracepoint debug routines
  IB/hfi1: add QSFP twsi routines
  IB/hfi1: add UC QP handling
  IB/hfi1: add UD QP handling
  IB/hfi1: add low level page locking
  IB/hfi1: add PSM sdma hooks
  IB/hfi1: add general verbs handling
  IB/hfi1: add multicast routines
  IB/hfi1: add driver make/config files


 drivers/infiniband/Kconfig   |1 
 drivers/infiniband/hw/Makefile   |1 
 drivers/infiniband/hw/hfi1/Kconfig   |   27 
 drivers/infiniband/hw/hfi1/Makefile  |   20 
 drivers/infiniband/hw/hfi1/chip.c|10626 ++
 drivers/infiniband/hw/hfi1/chip.h| 1013 ++
 drivers/infiniband/hw/hfi1/chip_registers.h  | 1285 +++
 drivers/infiniband/hw/hfi1/common.h  |  416 +
 drivers/infiniband/hw/hfi1/cq.c  |  558 +
 drivers/infiniband/hw/hfi1/debugfs.c |  899 ++
 drivers/infiniband/hw/hfi1/debugfs.h |   78 
 drivers/infiniband/hw/hfi1/device.c  |  142 
 drivers/infiniband/hw/hfi1/device.h  |   61 
 drivers/infiniband/hw/hfi1/diag.c| 1873 +
 drivers/infiniband/hw/hfi1/dma.c |  185 
 drivers/infiniband/hw/hfi1/driver.c  | 1061 +++
 drivers/infiniband/hw/hfi1/eprom.c   |  475 +
 drivers/infiniband/hw/hfi1/eprom.h   |   55 
 drivers/infiniband/hw/hfi1/file_ops.c| 2122 +
 drivers/infiniband/hw/hfi1/firmware.c| 1550 
 drivers/infiniband/hw/hfi1/hfi.h | 1738 
 drivers/infiniband/hw/hfi1/init.c| 1709 
 drivers/infiniband/hw/hfi1/intr.c|  204 
 drivers/infiniband/hw/hfi1/iowait.h  |  186 
 drivers/infiniband/hw/hfi1/keys.c|  407 +
 drivers/infiniband/hw/hfi1/mad.c | 4087 ++
 drivers/infiniband/hw/hfi1/mad.h |  285 +
 drivers/infiniband/hw/hfi1/mmap.c|  192 
 drivers/infiniband/hw/hfi1/mr.c  |  546 +
 drivers/infiniband/hw/hfi1/opa_compat.h  |  132 
 drivers/infiniband/hw/hfi1/pcie.c| 1254 +++
 drivers/infiniband/hw/hfi1/pio.c | 1764 
 drivers/infiniband/hw/hfi1/pio.h |  224 +
 drivers/infiniband/hw/hfi1/pio_copy.c|  867 ++
 drivers/infiniband/hw/hfi1/platform_config.h |  286 +
 drivers/infiniband/hw/hfi1/qp.c  | 1692 
 drivers/infiniband/hw/hfi1

[PATCH v3 03/49] IB/hfi1: add chip specific support part2

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/chip.c | 2890 +
 1 file changed, 2890 insertions(+)

diff --git a/drivers/infiniband/hw/hfi1/chip.c 
b/drivers/infiniband/hw/hfi1/chip.c
index 2bb026d..ed03311 100644
--- a/drivers/infiniband/hw/hfi1/chip.c
+++ b/drivers/infiniband/hw/hfi1/chip.c
@@ -2140,3 +2140,2893 @@ static void handle_cce_err(struct hfi1_devdata *dd, 
u32 unused, u64 reg)
}
 }
 
+/*
+ * Check counters for receive errors that do not have an interrupt
+ * associated with them.
+ */
+#define RCVERR_CHECK_TIME 10
+static void update_rcverr_timer(unsigned long opaque)
+{
+   struct hfi1_devdata *dd = (struct hfi1_devdata *)opaque;
+   struct hfi1_pportdata *ppd = dd->pport;
+   u32 cur_ovfl_cnt = read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL);
+
+   if (dd->rcv_ovfl_cnt < cur_ovfl_cnt &&
+   ppd->port_error_action & OPA_PI_MASK_EX_BUFFER_OVERRUN) {
+   dd_dev_info(dd, "%s: PortErrorAction bounce\n", __func__);
+   set_link_down_reason(ppd,
+ OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN, 0,
+   OPA_LINKDOWN_REASON_EXCESSIVE_BUFFER_OVERRUN);
+   start_link(ppd);
+   }
+   dd->rcv_ovfl_cnt = (u32) cur_ovfl_cnt;
+
+   mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
+}
+
+static int init_rcverr(struct hfi1_devdata *dd)
+{
+   init_timer(&dd->rcverr_timer);
+   dd->rcverr_timer.function = update_rcverr_timer;
+   dd->rcverr_timer.data = (unsigned long) dd;
+   /* Assume the hardware counter has been reset */
+   dd->rcv_ovfl_cnt = 0;
+   return mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
+}
+
+static void free_rcverr(struct hfi1_devdata *dd)
+{
+   if (dd->rcverr_timer.data)
+   del_timer_sync(&dd->rcverr_timer);
+   dd->rcverr_timer.data = 0;
+}
+
+static void handle_rxe_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
+{
+   char buf[96];
+
+   dd_dev_info(dd, "Receive Error: %s\n",
+   rxe_err_status_string(buf, sizeof(buf), reg));
+
+   if (reg & ALL_RXE_FREEZE_ERR) {
+   int flags = 0;
+
+   /*
+* Freeze mode recovery is disabled for the errors
+* in RXE_FREEZE_ABORT_MASK
+*/
+   if (is_a0(dd) && (reg & RXE_FREEZE_ABORT_MASK))
+   flags = FREEZE_ABORT;
+
+   start_freeze_handling(dd->pport, flags);
+   }
+}
+
+static void handle_misc_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
+{
+   char buf[96];
+
+   dd_dev_info(dd, "Misc Error: %s",
+   misc_err_status_string(buf, sizeof(buf), reg));
+}
+
+static void handle_pio_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
+{
+   char buf[96];
+
+   dd_dev_info(dd, "PIO Error: %s\n",
+   pio_err_status_string(buf, sizeof(buf), reg));
+
+   if (reg & ALL_PIO_FREEZE_ERR)
+   start_freeze_handling(dd->pport, 0);
+}
+
+static void handle_sdma_err(struct hfi1_devdata *dd, u32 unused, u64 reg)
+{
+   char buf[96];
+
+   dd_dev_info(dd, "SDMA Error: %s\n",
+   sdma_err_status_string(buf, sizeof(buf), reg));
+
+   if (reg & ALL_SDMA_FREEZE_ERR)
+   start_freeze_handling(dd->pport, 0);
+}
+
+static void count_port_inactive(struct hfi1_devdata *dd)
+{
+   struct hfi1_pportdata *ppd = dd->pport;
+
+   if (ppd->port_xmit_discards < ~(u64)0)
+   ppd->port_xmit_discards++;
+}
+
+/*
+ * We have had a "disallowed packet" error during egress. Determine the
+ * integrity check which failed, and update relevant error counter, etc.
+ *
+ * Note that the SEND_EGRESS_ERR_INFO register has only a single
+ * bit of state per integrity check, and so we can miss the reason for an
+ * egress error if more than one packet fails the same integrity check
+ * since we cleared the corresponding bit in SEND_EGRESS_ERR_INFO.
+ */
+static void handle_send_egress_err_info(struct hfi1_devdata *dd)
+{
+   struct hfi1_pportdata *ppd = dd->pport;
+   u64 src = read_csr(dd, SEND_EGRESS_ERR_SOURCE); /* read first */
+   u64 info = read_csr(dd, SEND_EGRESS_ERR_INFO);
+   char buf[96];
+
+   /* clear down all observed info a

[PATCH v3 01/49] IB/core: Add header definitions

2015-06-17 Thread Mike Marciniszyn
From: Ira Weiny 

Add common OPA header definitions for driver
build:
- opa_port_info.h
- opa_smi.h
- hfi1_user.sh

Additionally, ib_mad.h, has additional definitions
that are common to ib_drivers including:
- trap support
- cca support

The qib driver has the duplication removed in favor
those in ib_mad.h

Reviewed-by: Mike Marciniszyn 
Reviewed-by: John, Jubin 
Signed-off-by: Ira Weiny 
---
 drivers/infiniband/hw/qib/qib_mad.h |  147 +---
 include/rdma/ib_mad.h   |  138 +++
 include/rdma/opa_port_info.h|  433 +++
 include/rdma/opa_smi.h  |   47 
 include/uapi/rdma/hfi/hfi1_user.h   |  427 +++
 5 files changed, 1053 insertions(+), 139 deletions(-)
 create mode 100644 include/rdma/opa_port_info.h
 create mode 100644 include/uapi/rdma/hfi/hfi1_user.h

diff --git a/drivers/infiniband/hw/qib/qib_mad.h 
b/drivers/infiniband/hw/qib/qib_mad.h
index 941d4d5..57e99dc 100644
--- a/drivers/infiniband/hw/qib/qib_mad.h
+++ b/drivers/infiniband/hw/qib/qib_mad.h
@@ -36,148 +36,17 @@
 
 #include 
 
-#define IB_SMP_UNSUP_VERSIONcpu_to_be16(0x0004)
-#define IB_SMP_UNSUP_METHOD cpu_to_be16(0x0008)
-#define IB_SMP_UNSUP_METH_ATTR  cpu_to_be16(0x000C)
-#define IB_SMP_INVALID_FIELDcpu_to_be16(0x001C)
+#define IB_SMP_UNSUP_VERSION \
+cpu_to_be16(IB_MGMT_MAD_STATUS_BAD_VERSION)
 
-struct ib_node_info {
-   u8 base_version;
-   u8 class_version;
-   u8 node_type;
-   u8 num_ports;
-   __be64 sys_guid;
-   __be64 node_guid;
-   __be64 port_guid;
-   __be16 partition_cap;
-   __be16 device_id;
-   __be32 revision;
-   u8 local_port_num;
-   u8 vendor_id[3];
-} __packed;
-
-struct ib_mad_notice_attr {
-   u8 generic_type;
-   u8 prod_type_msb;
-   __be16 prod_type_lsb;
-   __be16 trap_num;
-   __be16 issuer_lid;
-   __be16 toggle_count;
-
-   union {
-   struct {
-   u8  details[54];
-   } raw_data;
-
-   struct {
-   __be16  reserved;
-   __be16  lid;/* where violation happened */
-   u8  port_num;   /* where violation happened */
-   } __packed ntc_129_131;
-
-   struct {
-   __be16  reserved;
-   __be16  lid;/* LID where change occurred */
-   u8  reserved2;
-   u8  local_changes;  /* low bit - local changes */
-   __be32  new_cap_mask;   /* new capability mask */
-   u8  reserved3;
-   u8  change_flags;   /* low 3 bits only */
-   } __packed ntc_144;
-
-   struct {
-   __be16  reserved;
-   __be16  lid;/* lid where sys guid changed */
-   __be16  reserved2;
-   __be64  new_sys_guid;
-   } __packed ntc_145;
-
-   struct {
-   __be16  reserved;
-   __be16  lid;
-   __be16  dr_slid;
-   u8  method;
-   u8  reserved2;
-   __be16  attr_id;
-   __be32  attr_mod;
-   __be64  mkey;
-   u8  reserved3;
-   u8  dr_trunc_hop;
-   u8  dr_rtn_path[30];
-   } __packed ntc_256;
-
-   struct {
-   __be16  reserved;
-   __be16  lid1;
-   __be16  lid2;
-   __be32  key;
-   __be32  sl_qp1; /* SL: high 4 bits */
-   __be32  qp2;/* high 8 bits reserved */
-   union ib_gidgid1;
-   union ib_gidgid2;
-   } __packed ntc_257_258;
-
-   } details;
-};
-
-/*
- * Generic trap/notice types
- */
-#define IB_NOTICE_TYPE_FATAL   0x80
-#define IB_NOTICE_TYPE_URGENT  0x81
-#define IB_NOTICE_TYPE_SECURITY0x82
-#define IB_NOTICE_TYPE_SM  0x83
-#define IB_NOTICE_TYPE_INFO0x84
+#define IB_SMP_UNSUP_METHOD \
+cpu_to_be16(IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD)
 
-/*
- * Generic trap/notice producers
- */
-#define IB_NOTICE_PROD_CA  cpu_to_be16(1)
-#define IB_NOTICE_PROD_SWITCH  cpu_to_be16(2)
-#define IB_NOTICE_PROD_ROUTER  cpu_to_be16(3)
-#define IB_NOTICE_PROD_CLASS_MGR   cpu_to_be16(4)
+#define IB_SMP_UNSUP_METH_ATTR \
+cpu_to_be16(IB_MGMT_MAD_STATUS_UNSUPPORTED_METHOD_ATTRIB)
 
-/*
- * Generic trap/notice numbers
- */
-#define IB_NOTICE_TRAP_LLI_THRESH  cpu_to_be16(129)
-#define IB_NOTICE_TRAP_EBO_THRESH  cpu_to_be16(130)
-#define IB_NOTICE_TRAP_FLOW_UPDATE

[PATCH v3 06/49] IB/hfi1: add chip register definitions

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/chip_registers.h | 1285 +++
 1 file changed, 1285 insertions(+)
 create mode 100644 drivers/infiniband/hw/hfi1/chip_registers.h

diff --git a/drivers/infiniband/hw/hfi1/chip_registers.h 
b/drivers/infiniband/hw/hfi1/chip_registers.h
new file mode 100644
index 000..4ae0403
--- /dev/null
+++ b/drivers/infiniband/hw/hfi1/chip_registers.h
@@ -0,0 +1,1285 @@
+#ifndef DEF_CHIP_REG
+#define DEF_CHIP_REG
+
+/*
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  - Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  - Neither the name of Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#define CORE   0x
+#define CCE(CORE + 0x)
+#define ASIC   (CORE + 0x0040)
+#define MISC   (CORE + 0x0050)
+#define DC_TOP_CSRS(CORE + 0x0060)
+#define CHIP_DEBUG (CORE + 0x0070)
+#define RXE(CORE + 0x0100)
+#define TXE(CORE + 0x0180)
+#define DCC_CSRS   (DC_TOP_CSRS + 0x)
+#define DC_LCB_CSRS(DC_TOP_CSRS + 0x1000)
+#define DC_8051_CSRS   (DC_TOP_CSRS + 0x2000)
+#define PCIE   0
+
+#define ASIC_NUM_SCRATCH 4
+#define CCE_ERR_INT_CNT 0
+#define CCE_MISC_INT_CNT 2
+#define CCE_NUM_32_BIT_COUNTERS 3
+#define CCE_NUM_32_BIT_INT_COUNTERS 6
+#define CCE_NUM_INT_CSRS 12
+#define CCE_NUM_INT_MAP_CSRS 96
+#define CCE_NUM_MSIX_PBAS 4
+#define CCE_NUM_MSIX_VECTORS 256
+#define CCE_NUM_SCRATCH 4
+#define CCE_PCIE_POSTED_CRDT_STALL_CNT 2
+#define CCE_PCIE_TRGT_STALL_CNT 0
+#define CCE_PIO_WR_STALL_CNT 1
+#define CCE_RCV_AVAIL_INT_CNT 3
+#define CCE_RCV_URGENT_INT_CNT 4
+#define CCE_SDMA_INT_CNT 1
+#define CCE_SEND_CREDIT_INT_CNT 5
+#define DCC_CFG_LED_CNTRL (DCC_CSRS + 0x0040)
+#define DCC_CFG_LED_CNTRL_LED_CNTRL_SMASK 0x10ull
+#define DCC_CFG_LED_CNTRL_LED_SW_BLINK_RATE_SHIFT 0
+#define DCC_CFG_LED_CNTRL_LED_SW_BLINK_RATE_SMASK 0xFull
+#define DCC_CFG_PORT_CONFIG (DCC_CSRS + 0x0008)
+#define DCC_CFG_PORT_CONFIG1 (DCC_CSRS + 0x0010)
+#define DCC_CFG_PORT_CONFIG1_DLID_MASK_MASK 

[PATCH v3 04/49] IB/hfi1: add chip specific support part3

2015-06-17 Thread Mike Marciniszyn
Signed-off-by: Andrew Friedley 
Signed-off-by: Arthur Kepner 
Signed-off-by: Brendan Cunningham 
Signed-off-by: Brian Welty 
Signed-off-by: Caz Yokoyama 
Signed-off-by: Dean Luick 
Signed-off-by: Dennis Dalessandro 
Signed-off-by: Easwar Hariharan 
Signed-off-by: Harish Chegondi 
Signed-off-by: Ira Weiny 
Signed-off-by: Jim Snow 
Signed-off-by: John Gregor 
Signed-off-by: Jubin John 
Signed-off-by: Kaike Wan 
Signed-off-by: Kevin Pine 
Signed-off-by: Kyle Liddell 
Signed-off-by: Mike Marciniszyn 
Signed-off-by: Mitko Haralanov 
Signed-off-by: Ravi Krishnaswamy 
Signed-off-by: Sadanand Warrier 
Signed-off-by: Sanath Kumar 
Signed-off-by: Sudeep Dutt 
Signed-off-by: Vlad Danushevsky 
---
 drivers/infiniband/hw/hfi1/chip.c | 2981 +
 1 file changed, 2981 insertions(+)

diff --git a/drivers/infiniband/hw/hfi1/chip.c 
b/drivers/infiniband/hw/hfi1/chip.c
index ed03311..7019499 100644
--- a/drivers/infiniband/hw/hfi1/chip.c
+++ b/drivers/infiniband/hw/hfi1/chip.c
@@ -5030,3 +5030,2984 @@ static int read_idle_message(struct hfi1_devdata *dd, 
u64 type, u64 *data_out)
 static int read_idle_sma(struct hfi1_devdata *dd, u64 *data)
 {
return read_idle_message(dd,
+   (u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT, data);
+}
+
+/*
+ * Send an idle LCB message.
+ *
+ * Returns 0 on success, -EINVAL on error
+ */
+static int send_idle_message(struct hfi1_devdata *dd, u64 data)
+{
+   int ret;
+
+   dd_dev_info(dd, "%s: sending idle message 0x%llx\n", __func__, data);
+   ret = do_8051_command(dd, HCMD_SEND_LCB_IDLE_MSG, data, NULL);
+   if (ret != HCMD_SUCCESS) {
+   dd_dev_err(dd, "send idle message: data 0x%llx, err %d\n",
+   data, ret);
+   return -EINVAL;
+   }
+   return 0;
+}
+
+/*
+ * Send an idle SMA message.
+ *
+ * Returns 0 on success, -EINVAL on error
+ */
+int send_idle_sma(struct hfi1_devdata *dd, u64 message)
+{
+   u64 data;
+
+   data = ((message & IDLE_PAYLOAD_MASK) << IDLE_PAYLOAD_SHIFT)
+   | ((u64)IDLE_SMA << IDLE_MSG_TYPE_SHIFT);
+   return send_idle_message(dd, data);
+}
+
+/*
+ * Initialize the LCB then do a quick link up.  This may or may not be
+ * in loopback.
+ *
+ * return 0 on success, -errno on error
+ */
+static int do_quick_linkup(struct hfi1_devdata *dd)
+{
+   u64 reg;
+   unsigned long timeout;
+   int ret;
+
+   lcb_shutdown(dd, 0);
+
+   if (loopback) {
+   /* LCB_CFG_LOOPBACK.VAL = 2 */
+   /* LCB_CFG_LANE_WIDTH.VAL = 0 */
+   write_csr(dd, DC_LCB_CFG_LOOPBACK,
+   IB_PACKET_TYPE << DC_LCB_CFG_LOOPBACK_VAL_SHIFT);
+   write_csr(dd, DC_LCB_CFG_LANE_WIDTH, 0);
+   }
+
+   /* start the LCBs */
+   /* LCB_CFG_TX_FIFOS_RESET.VAL = 0 */
+   write_csr(dd, DC_LCB_CFG_TX_FIFOS_RESET, 0);
+
+   /* simulator only loopback steps */
+   if (loopback && dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
+   /* LCB_CFG_RUN.EN = 1 */
+   write_csr(dd, DC_LCB_CFG_RUN,
+   1ull << DC_LCB_CFG_RUN_EN_SHIFT);
+
+   /* watch LCB_STS_LINK_TRANSFER_ACTIVE */
+   timeout = jiffies + msecs_to_jiffies(10);
+   while (1) {
+   reg = read_csr(dd,
+   DC_LCB_STS_LINK_TRANSFER_ACTIVE);
+   if (reg)
+   break;
+   if (time_after(jiffies, timeout)) {
+   dd_dev_err(dd,
+   "timeout waiting for 
LINK_TRANSFER_ACTIVE\n");
+   return -ETIMEDOUT;
+   }
+   udelay(2);
+   }
+
+   write_csr(dd, DC_LCB_CFG_ALLOW_LINK_UP,
+   1ull << DC_LCB_CFG_ALLOW_LINK_UP_VAL_SHIFT);
+   }
+
+   if (!loopback) {
+   /*
+* When doing quick linkup and not in loopback, both
+* sides must be done with LCB set-up before either
+* starts the quick linkup.  Put a delay here so that
+* both sides can be started and have a chance to be
+* done with LCB set up before resuming.
+*/
+   dd_dev_err(dd,
+   "Pausing for peer to be finished with LCB set up\n");
+   msleep(5000);
+   dd_dev_err(dd,
+   "Continuing with quick linkup\n");
+   }
+
+   write_csr(dd, DC_LCB_ERR_EN, 0); /* mask LCB errors */
+   set_8051_lcb_access(dd);
+
+   /*
+* State "quick" LinkUp request sets the physical link state to
+* LinkUp without a verify capability sequence.
+* This state is in simulator v37 and later.
+*/
+   ret = set_physical_link_state(dd, PLS_QUICK_LINKUP);
+   if (ret != HCMD_SUCCESS) {
+  

Re: [PATCH v2 01/49] IB/core: Add OPA Port header definitions

2015-06-17 Thread Hal Rosenstock
On 6/17/2015 8:08 AM, Marciniszyn, Mike wrote:
>>
>>>  include/rdma/opa_port_info.h  |  433
>>
>> This matches the current code structure, but is this the best location for 
>> this file?
> 
> Do you have a suggestion?

Couldn't it be a header in the hfi1 driver directory ? Isn't it OPA
specific ?

-- Hal

> 
> Mike
> N�r��y���b�X��ǧv�^�)޺{.n�+{��ٚ�{ay�ʇڙ�,j��f���h���z��w���
> ���j:+v���w�j�mzZ+��ݢj"��!tml=

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v2 47/49] IB/hfi1: add multicast routines

2015-06-17 Thread Marciniszyn, Mike
> Ummm... This looks eerily similar to qib_verbs_mcast.c. Sed job on the file? 
> Is
> there any way to get a description as to what the differences are between qib
> and hfi?
> 

We are working  on what can be said on OPA and the hardware.

We chose to impact qib as little as possible with this driver development.

There are differences in the verbs layer associated with the hardware and 
future work that will make that even more the case.

A future work could create a combined driver.

Mike

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v2 01/49] IB/core: Add OPA Port header definitions

2015-06-17 Thread Marciniszyn, Mike
> 
> >  include/rdma/opa_port_info.h  |  433
> 
> This matches the current code structure, but is this the best location for 
> this file?

Do you have a suggestion?

Mike


RE: [PATCH 06/41] IB/hfi1: add char device instantiation code

2015-06-17 Thread Marciniszyn, Mike
> > > Do you have a link to this comment?  I'm missing a bunch of messages
> > > from
> > this thread and can't find anything from Al in the logs.
> >
> 
> This commit appeared in qib and it did not appear on linux-rdma.  I never saw 
> it
> until it appeared.
> 
> I emailed on list to Al in http://marc.info/?l=linux-
> rdma&m=143024595127255&w=2.
> 

Jason, what is your take on ioctl vs. write.

PSM2 (and PSM) uses this to dialog with the driver for hardware specific setup.

I'm suspected at some point in the past, this was ioctl based and changed due 
to bias against ioctl.

Mike
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v2 25/49] IB/hfi1: add local mad header

2015-06-17 Thread Marciniszyn, Mike
> > +/*
> > + * Generic trap/notice types
> > + */
> > +#define IB_NOTICE_TYPE_FATAL   0x80
> > +#define IB_NOTICE_TYPE_URGENT  0x81
> > +#define IB_NOTICE_TYPE_SECURITY0x82
> > +#define IB_NOTICE_TYPE_SM  0x83
> > +#define IB_NOTICE_TYPE_INFO0x84
> 

Moved to ib_mad.h in v3.


RE: [PATCH v2 39/49] IB/hfi1: add sysfs routines

2015-06-17 Thread Marciniszyn, Mike
> 
> what's SC and what's SC-to-VL? aren't you using SM to do such mappings? if 
> this
> and the below sysfs work-around/s for the maybe current lack of SM to
> configure the port? why do the upstream kernel has to carry ~hundreds of sysfs
> entries forever for such non-documented things?
> 

This sysfs entries are used by PSM2 to form packets from user space.

> 
> 
> 
> >> +HFI1_SL2SC_ATTR(0);
> 
> same comment on SL2SC
> 
> >> +HFI1_VL2MTU_ATTR(0);
> 
> same comment on VL2MTU, why in sysfs?!
> 

Same answer.

> >> +HFI1_DIAGC_ATTR(rc_resends);
> >> +HFI1_DIAGC_ATTR_PCPU(rc_acks, C_SW_CPU_RC_ACKS,
> CNTR_INVALID_VL);
> >> +HFI1_DIAGC_ATTR_PCPU(rc_qacks, C_SW_CPU_RC_QACKS,
> CNTR_INVALID_VL);
> >> +HFI1_DIAGC_ATTR_PCPU(rc_delayed_comp,
> C_SW_CPU_RC_DELAYED_COMP,
> >> +   CNTR_INVALID_VL);
> >> +HFI1_DIAGC_ATTR(seq_naks);
> >> +HFI1_DIAGC_ATTR(rdma_seq);
> >> +HFI1_DIAGC_ATTR(rnr_naks);
> >> +HFI1_DIAGC_ATTR(other_naks);
> >> +HFI1_DIAGC_ATTR(rc_timeouts);
> >> +HFI1_DIAGC_ATTR(loop_pkts);
> >> +HFI1_DIAGC_ATTR(pkt_drops);
> >> +HFI1_DIAGC_ATTR(dmawait);
> >> +HFI1_DIAGC_ATTR(unaligned);
> >> +HFI1_DIAGC_ATTR(rc_dupreq);
> >> +HFI1_DIAGC_ATTR(rc_seqnak);
> 

The counters can be metered via other mechanisms.   They will be removed in v3.
N�r��yb�X��ǧv�^�)޺{.n�+{��ٚ�{ay�ʇڙ�,j��f���h���z��w���
���j:+v���w�j�mzZ+�ݢj"��!�i

Re: [PATCH 04/11] IB/cm: Expose DGID in SIDR request events

2015-06-17 Thread Haggai Eran
On Tuesday, June 16, 2015 7:47 PM, Hefty, Sean  wrote:
> To: Haggai Eran; Doug Ledford
> Cc: linux-rdma@vger.kernel.org; net...@vger.kernel.org; Liran Liss; Guy 
> Shapiro; Shachar Raindel; Yotam Kenneth; Jason Gunthorpe
> Subject: RE: [PATCH 04/11] IB/cm: Expose DGID in SIDR request events
> 
>> The idea is to allow SIDR request to be sorted by the GID, when we will
>> have alias GIDs for IPoIB.
> 
> Please limit this series, or at least the early patches in this series, to 
> simply moving the de-mux out of the ib_cm and into the rdma_cm.

Fair enough. I'll remove this patch and the related code from this series.

Haggai
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH acm] acme.c: Fix IPv6 address handling in inet_any_pton

2015-06-17 Thread Hal Rosenstock
On 6/17/2015 1:50 AM, Hefty, Sean wrote:
> Thanks - applied manually

Thanks.

>>  acm/src/acme.c |2 +-
> 
> Path?
> 
>> diff --git a/acm/src/acme.c b/acm/src/acme.c
>> index 9bf7557..d54c8b9 100644
>> --- a/acm/src/acme.c
>> +++ b/acm/src/acme.c
>> @@ -787,7 +787,7 @@ static int inet_any_pton(char *addr, struct sockaddr
> 
> This was off by a couple hundred lines.  Can you check your branch?

My bad; patch I sent was against SSA ACM. I only compared code to see it
was needed upstream and forgot to port it against upstream tree.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html