IB/qib: add
Subsystems (2)
PATCH v3 25/52 IB/qib: Add qib_mr.c
In reply to a message not in the archivecreates the qib_mr.c file.
---
drivers/infiniband/hw/qib/qib_mr.c | 503 ++++++++++++++++++++++++++++++++++++ 1 files changed, 503 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_mr.c
drivers/infiniband/hw/qib/qib_mr.c new file +503 -0
@@ -0,0 +1,503 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <rdma/ib_umem.h> +#include <rdma/ib_smi.h> + +#include "qib.h" + +/* Fast memory region */ +struct qib_fmr { +struct ib_fmr ibfmr; +u8 page_shift; +struct qib_mregion mr;/* must be last */ +}; + +static inline struct qib_fmr *to_ifmr (struct ib_fmr *ibfmr) +{ + return container_of(ibfmr, struct qib_fmr, ibfmr); +} + +/** +* qib_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 qib_dma.c). +*/ +struct ib_mr *qib_get_dma_mr (struct ib_pd *pd,int acc) +{ +struct qib_ibdev *dev =to_idev (pd->device); +struct qib_mr *mr; +struct ib_mr *ret; +unsigned long flags; + +if (to_ipd (pd)->user) { + ret =ERR_PTR (-EPERM ); + goto bail; + } + + mr =kzalloc (sizeof *mr,GFP_KERNEL ); +if (!mr) { + ret =ERR_PTR (-ENOMEM ); + goto bail; + } + + mr->mr.access_flags = acc; +atomic_set (&mr->mr.refcount,0 ); + +spin_lock_irqsave (&dev->lk_table.lock, flags); +if (!dev->dma_mr) + dev->dma_mr = &mr->mr; +spin_unlock_irqrestore (&dev->lk_table.lock, flags); + + ret = &mr->ibmr; + +bail: +return ret; +} + +static struct qib_mr *alloc_mr (int count,struct qib_lkey_table *lk_table) +{ +struct qib_mr *mr; +int m, i =0 ; + +/* Allocate struct plus pointers to first level page tables. */ + m = (count +QIB_SEGSZ -1 ) /QIB_SEGSZ ; + mr =kmalloc (sizeof *mr + m *sizeof mr->mr.map[0 ],GFP_KERNEL ); +if (!mr) + goto done; + +/* Allocate first level page tables. */ +for (; i < m; i++) { + mr->mr.map[i] =kmalloc (sizeof *mr->mr.map[0 ],GFP_KERNEL ); +if (!mr->mr.map[i]) + goto bail; + } + mr->mr.mapsz = m; + mr->mr.max_segs = count; + +/* +* ib_reg_phys_mr() will initialize mr->ibmr except for +* lkey and rkey. +*/ +if (!qib_alloc_lkey (lk_table, &mr->mr)) + goto bail; + mr->ibmr.lkey = mr->mr.lkey; + mr->ibmr.rkey = mr->mr.lkey; + +atomic_set (&mr->mr.refcount,0 ); + goto done; + +bail: +while (i) +kfree (mr->mr.map[--i]); +kfree (mr); + mr =NULL ; + +done: +return mr; +} + +/** +* qib_reg_phys_mr - register a physical memory region +* @pd: protection domain for this memory region +* @buffer_list: pointer to the list of physical buffers to register +* @num_phys_buf: the number of physical buffers to register +* @iova_start: the starting address passed over IB which maps to this MR +* +* Returns the memory region on success, otherwise returns an errno. +*/ +struct ib_mr *qib_reg_phys_mr (struct ib_pd *pd, +struct ib_phys_buf *buffer_list, +int num_phys_buf,int acc,u64 *iova_start) +{ +struct qib_mr *mr; +int n, m, i; +struct ib_mr *ret; + + mr =alloc_mr (num_phys_buf, &to_idev (pd->device)->lk_table); +if (mr ==NULL ) { + ret =ERR_PTR (-ENOMEM ); + goto bail; + } + + mr->mr.pd = pd; + mr->mr.user_base = *iova_start; + mr->mr.iova = *iova_start; + mr->mr.length =0 ; + mr->mr.offset =0 ; + mr->mr.access_flags = acc; + mr->umem =NULL ; + + m =0 ; + n =0 ; +for (i =0 ; i < num_phys_buf; i++) { + mr->mr.map[m]->segs[n].vaddr = (void *) buffer_list[i].addr; + mr->mr.map[m]->segs[n].length = buffer_list[i].size; + mr->mr.length += buffer_list[i].size; + n++; +if (n ==QIB_SEGSZ ) { + m++; + n =0 ; + } + } + + ret = &mr->ibmr; + +bail: +return ret; +} + +/** +* qib_reg_user_mr - register a userspace memory region +* @pd: protection domain for this memory region +* @start: starting userspace address +* @length: length of region to register +* @virt_addr: virtual address to use (from HCA's point of view) +* @mr_access_flags: access flags for this memory region +* @udata: unused by the QLogic_IB driver +* +* Returns the memory region on success, otherwise returns an errno. +*/ +struct ib_mr *qib_reg_user_mr (struct ib_pd *pd,u64 start,u64 length, +u64 virt_addr,int mr_access_flags, +struct ib_udata *udata) +{ +struct qib_mr *mr; +struct ib_umem *umem; +struct ib_umem_chunk *chunk; +int n, m, i; +struct ib_mr *ret; + +if (length ==0 ) { + ret =ERR_PTR (-EINVAL ); + goto bail; + } + + umem =ib_umem_get (pd->uobject->context, start, length, + mr_access_flags,0 ); +if (IS_ERR (umem)) +return (void *) umem; + + n =0 ; +list_for_each_entry (chunk, &umem->chunk_list, list) + n += chunk->nents; + + mr =alloc_mr (n, &to_idev (pd->device)->lk_table); +if (!mr) { + ret =ERR_PTR (-ENOMEM ); +ib_umem_release (umem); + goto bail; + } + + mr->mr.pd = pd; + mr->mr.user_base = start; + mr->mr.iova = virt_addr; + mr->mr.length = length; + mr->mr.offset = umem->offset; + mr->mr.access_flags = mr_access_flags; + mr->umem = umem; + + m =0 ; + n =0 ; +list_for_each_entry (chunk, &umem->chunk_list, list) { +for (i =0 ; i < chunk->nents; i++) { +void *vaddr; + + vaddr =page_address (sg_page (&chunk->page_list[i])); +if (!vaddr) { + ret =ERR_PTR (-EINVAL ); + goto bail; + } + mr->mr.map[m]->segs[n].vaddr = vaddr; + mr->mr.map[m]->segs[n].length = umem->page_size; + n++; +if (n ==QIB_SEGSZ ) { + m++; + n =0 ; + } + } + } + ret = &mr->ibmr; + +bail: +return ret; +} + +/** +* qib_dereg_mr - unregister and free a memory region +* @ibmr: the memory region to free +* +* Returns 0 on success. +* +* Note that this is called to free MRs created by qib_get_dma_mr() +* or qib_reg_user_mr(). +*/ +int qib_dereg_mr (struct ib_mr *ibmr) +{ +struct qib_mr *mr =to_imr (ibmr); +struct qib_ibdev *dev =to_idev (ibmr->device); +int ret; +int i; + + ret =qib_free_lkey (dev, &mr->mr); +if (ret) +return ret; + + i = mr->mr.mapsz; +while (i) +kfree (mr->mr.map[--i]); +if (mr->umem) +ib_umem_release (mr->umem); +kfree (mr); +return 0 ; +} + +/* +* Allocate a memory region usable with the +* IB_WR_FAST_REG_MR send work request. +* +* Return the memory region on success, otherwise return an errno. +*/ +struct ib_mr *qib_alloc_fast_reg_mr (struct ib_pd *pd,int max_page_list_len) +{ +struct qib_mr *mr; + + mr =alloc_mr (max_page_list_len, &to_idev (pd->device)->lk_table); +if (mr ==NULL ) +return ERR_PTR (-ENOMEM ); + + mr->mr.pd = pd; + mr->mr.user_base =0 ; + mr->mr.iova =0 ; + mr->mr.length =0 ; + mr->mr.offset =0 ; + mr->mr.access_flags =0 ; + mr->umem =NULL ; + +return &mr->ibmr; +} + +struct ib_fast_reg_page_list * +qib_alloc_fast_reg_page_list (struct ib_device *ibdev,int page_list_len) +{ +unsigned size = page_list_len *sizeof (u64); +struct ib_fast_reg_page_list *pl; + +if (size >PAGE_SIZE ) +return ERR_PTR (-EINVAL ); + + pl =kmalloc (sizeof *pl,GFP_KERNEL ); +if (!pl) +return ERR_PTR (-ENOMEM ); + + pl->page_list =kmalloc (size,GFP_KERNEL ); +if (!pl->page_list) + goto err_free; + +return pl; + +err_free: +kfree (pl); +return ERR_PTR (-ENOMEM ); +} + +void qib_free_fast_reg_page_list (struct ib_fast_reg_page_list *pl) +{ +kfree (pl->page_list); +kfree (pl); +} + +/** +* qib_alloc_fmr - allocate a fast memory region +* @pd: the protection domain for this memory region +* @mr_access_flags: access flags for this memory region +* @fmr_attr: fast memory region attributes +* +* Returns the memory region on success, otherwise returns an errno. +*/ +struct ib_fmr *qib_alloc_fmr (struct ib_pd *pd,int mr_access_flags, +struct ib_fmr_attr *fmr_attr) +{ +struct qib_fmr *fmr; +int m, i =0 ; +struct ib_fmr *ret; + +/* Allocate struct plus pointers to first level page tables. */ + m = (fmr_attr->max_pages +QIB_SEGSZ -1 ) /QIB_SEGSZ ; + fmr =kmalloc (sizeof *fmr + m *sizeof fmr->mr.map[0 ],GFP_KERNEL ); +if (!fmr) + goto bail; + +/* Allocate first level page tables. */ +for (; i < m; i++) { + fmr->mr.map[i] =kmalloc (sizeof *fmr->mr.map[0 ], +GFP_KERNEL ); +if (!fmr->mr.map[i]) + goto bail; + } + fmr->mr.mapsz = m; + +/* +* ib_alloc_fmr() will initialize fmr->ibfmr except for lkey & +* rkey. +*/ +if (!qib_alloc_lkey (&to_idev (pd->device)->lk_table, &fmr->mr)) + goto bail; + fmr->ibfmr.rkey = fmr->mr.lkey; + fmr->ibfmr.lkey = fmr->mr.lkey; +/* +* Resources are allocated but no valid mapping (RKEY can't be +* used). +*/ + fmr->mr.pd = pd; + fmr->mr.user_base =0 ; + fmr->mr.iova =0 ; + fmr->mr.length =0 ; + fmr->mr.offset =0 ; + fmr->mr.access_flags = mr_access_flags; + fmr->mr.max_segs = fmr_attr->max_pages; + fmr->page_shift = fmr_attr->page_shift; + +atomic_set (&fmr->mr.refcount,0 ); + ret = &fmr->ibfmr; + goto done; + +bail: +while (i) +kfree (fmr->mr.map[--i]); +kfree (fmr); + ret =ERR_PTR (-ENOMEM ); + +done: +return ret; +} + +/** +* qib_map_phys_fmr - set up a fast memory region +* @ibmfr: the fast memory region to set up +* @page_list: the list of pages to associate with the fast memory region +* @list_len: the number of pages to associate with the fast memory region +* @iova: the virtual address of the start of the fast memory region +* +* This may be called from interrupt context. +*/ + +int qib_map_phys_fmr (struct ib_fmr *ibfmr,u64 *page_list, +int list_len,u64 iova) +{ +struct qib_fmr *fmr =to_ifmr (ibfmr); +struct qib_lkey_table *rkt; +unsigned long flags; +int m, n, i; +u32 ps; +int ret; + +if (atomic_read (&fmr->mr.refcount)) +return -EBUSY ; + +if (list_len > fmr->mr.max_segs) { + ret = -EINVAL ; + goto bail; + } + rkt = &to_idev (ibfmr->device)->lk_table; +spin_lock_irqsave (&rkt->lock, flags); + fmr->mr.user_base = iova; + fmr->mr.iova = iova; + ps =1 << fmr->page_shift; + fmr->mr.length = list_len * ps; + m =0 ; + n =0 ; +for (i =0 ; i < list_len; i++) { + fmr->mr.map[m]->segs[n].vaddr = (void *) page_list[i]; + fmr->mr.map[m]->segs[n].length = ps; +if (++n ==QIB_SEGSZ ) { + m++; + n =0 ; + } + } +spin_unlock_irqrestore (&rkt->lock, flags); + ret =0 ; + +bail: +return ret; +} + +/** +* qib_unmap_fmr - unmap fast memory regions +* @fmr_list: the list of fast memory regions to unmap +* +* Returns 0 on success. +*/ +int qib_unmap_fmr (struct list_head *fmr_list) +{ +struct qib_fmr *fmr; +struct qib_lkey_table *rkt; +unsigned long flags; + +list_for_each_entry (fmr, fmr_list, ibfmr.list) { + rkt = &to_idev (fmr->ibfmr.device)->lk_table; +spin_lock_irqsave (&rkt->lock, flags); + fmr->mr.user_base =0 ; + fmr->mr.iova =0 ; + fmr->mr.length =0 ; +spin_unlock_irqrestore (&rkt->lock, flags); + } +return 0 ; +} + +/** +* qib_dealloc_fmr - deallocate a fast memory region +* @ibfmr: the fast memory region to deallocate +* +* Returns 0 on success. +*/ +int qib_dealloc_fmr (struct ib_fmr *ibfmr) +{ +struct qib_fmr *fmr =to_ifmr (ibfmr); +int ret; +int i; + + ret =qib_free_lkey (to_idev (ibfmr->device), &fmr->mr); +if (ret) +return ret; + + i = fmr->mr.mapsz; +while (i) +kfree (fmr->mr.map[--i]); +kfree (fmr); +return 0 ; +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 26/52 IB/qib: Add qib_pcie.c
In reply to a message not in the archivecreates the qib_pcie.c file.
---
drivers/infiniband/hw/qib/qib_pcie.c | 738 ++++++++++++++++++++++++++++++++++ 1 files changed, 738 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_pcie.c
drivers/infiniband/hw/qib/qib_pcie.c new file +738 -0
@@ -0,0 +1,738 @@ +/* +* Copyright (c) 2008, 2009 QLogic Corporation. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/pci.h> +#include <linux/io.h> +#include <linux/delay.h> +#include <linux/vmalloc.h> +#include <linux/aer.h> + +#include "qib.h" + +/* +* This file contains PCIe utility routines that are common to the +* various QLogic InfiniPath adapters +*/ + +/* +* Code to adjust PCIe capabilities. +* To minimize the change footprint, we call it +* from qib_pcie_params, which every chip-specific +* file calls, even though this violates some +* expectations of harmlessness. +*/ +static int qib_tune_pcie_caps (struct qib_devdata *); +static int qib_tune_pcie_coalesce (struct qib_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 qib_dev_err() can't be used for error +* printing. +*/ +int qib_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. +*/ +qib_early_err (&pdev->dev,"pci enable failed: error %d\n" , + -ret); + goto done; + } + + ret =pci_request_regions (pdev,QIB_DRV_NAME ); +if (ret) { +qib_devinfo (pdev,"pci_request_regions fails: err %d\n" , -ret); + goto bail; + } + + ret =pci_set_dma_mask (pdev,DMA_BIT_MASK (64 )); +if (ret) { +/* +* If the 64 bit setup fails, try 32 bit. Some systems +* do not setup 64 bit maps on systems with 2GB or less +* memory installed. +*/ + ret =pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )); +if (ret) { +qib_devinfo (pdev,"Unable to set DMA mask: %d\n" , ret); + goto bail; + } + ret =pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (32 )); + }else + ret =pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (64 )); +if (ret) +qib_early_err (&pdev->dev, +"Unable to set DMA consistent mask: %d\n" , ret); + +pci_set_master (pdev); + ret =pci_enable_pcie_error_reporting (pdev); +if (ret) +qib_early_err (&pdev->dev, +"Unable to enable pcie error reporting: %d\n" , + ret); + goto done; + +bail: +pci_disable_device (pdev); +pci_release_regions (pdev); +done: +return ret; +} + +/* +* Do remaining PCIe setup, once dd is allocated, and save away +* fields required to re-initialize after a chip reset, or for +* various other purposes +*/ +int qib_pcie_ddinit (struct qib_devdata *dd,struct pci_dev *pdev, +const struct pci_device_id *ent) +{ +unsigned long len; +resource_size_t addr; + + dd->pcidev = pdev; +pci_set_drvdata (pdev, dd); + + addr =pci_resource_start (pdev,0 ); + len =pci_resource_len (pdev,0 ); + +#if defined(__powerpc__) +/* There isn't a generic way to specify writethrough mappings */ + dd->kregbase =__ioremap (addr, len, _PAGE_NO_CACHE | _PAGE_WRITETHRU); +#else + dd->kregbase =ioremap_nocache (addr, len); +#endif + +if (!dd->kregbase) +return -ENOMEM ; + + dd->kregend = (u64 __iomem *)((void __iomem *) dd->kregbase + len); + dd->physaddr = addr;/* used for io_remap, etc. */ + +/* +* Save BARs to rewrite after device reset. Save all 64 bits of +* BAR, just in case. +*/ + dd->pcibar0 = addr; + dd->pcibar1 = addr >>32 ; + dd->deviceid = ent->device;/* save for later use */ + dd->vendorid = ent->vendor; + +return 0 ; +} + +/* +* Do PCIe cleanup, after chip-specific cleanup, etc. Just prior +* to releasing the dd memory. +* void because none of the core pcie cleanup returns are void +*/ +void qib_pcie_ddcleanup (struct qib_devdata *dd) +{ +u64 __iomem *base = (void __iomem *) dd->kregbase; + + dd->kregbase =NULL ; +iounmap (base); +if (dd->piobase) +iounmap (dd->piobase); +if (dd->userbase) +iounmap (dd->userbase); + +pci_disable_device (dd->pcidev); +pci_release_regions (dd->pcidev); + +pci_set_drvdata (dd->pcidev,NULL ); +} + +static void qib_msix_setup (struct qib_devdata *dd,int pos,u32 *msixcnt, +struct msix_entry *msix_entry) +{ +int ret; +u32 tabsize =0 ; +u16 msix_flags; + +pci_read_config_word (dd->pcidev, pos +PCI_MSIX_FLAGS , &msix_flags); + tabsize =1 + (msix_flags &PCI_MSIX_FLAGS_QSIZE ); +if (tabsize > *msixcnt) + tabsize = *msixcnt; + ret =pci_enable_msix (dd->pcidev, msix_entry, tabsize); +if (ret >0 ) { + tabsize = ret; + ret =pci_enable_msix (dd->pcidev, msix_entry, tabsize); + } +if (ret) { +qib_dev_err (dd,"pci_enable_msix %d vectors failed: %d, " +"falling back to INTx\n" , tabsize, ret); + tabsize =0 ; + } + *msixcnt = tabsize; + +if (ret) +qib_enable_intx (dd->pcidev); + +} + +/** +* We save the msi lo and hi values, so we can restore them after +* chip reset (the kernel PCI infrastructure doesn't yet handle that +* correctly. +*/ +static int qib_msi_setup (struct qib_devdata *dd,int pos) +{ +struct pci_dev *pdev = dd->pcidev; +u16 control; +int ret; + + ret =pci_enable_msi (pdev); +if (ret) +qib_dev_err (dd,"pci_enable_msi failed: %d, " +"interrupts may not work\n" , ret); +/* continue even if it fails, we may still be OK... */ + +pci_read_config_dword (pdev, pos +PCI_MSI_ADDRESS_LO , + &dd->msi_lo); +pci_read_config_dword (pdev, pos +PCI_MSI_ADDRESS_HI , + &dd->msi_hi); +pci_read_config_word (pdev, pos +PCI_MSI_FLAGS , &control); +/* now save the data (vector) info */ +pci_read_config_word (pdev, pos + ((control &PCI_MSI_FLAGS_64BIT ) + ?12 :8 ), + &dd->msi_data); +return ret; +} + +int qib_pcie_params (struct qib_devdata *dd,u32 minw,u32 *nent, +struct msix_entry *entry) +{ +u16 linkstat, speed; +int pos =0 , pose, ret =1 ; + + pose =pci_find_capability (dd->pcidev,PCI_CAP_ID_EXP ); +if (!pose) { +qib_dev_err (dd,"Can't find PCI Express capability!\n" ); +/* set up something... */ + dd->lbus_width =1 ; + dd->lbus_speed =2500 ;/* Gen1, 2.5GHz */ + goto bail; + } + + pos =pci_find_capability (dd->pcidev,PCI_CAP_ID_MSIX ); +if (nent && *nent && pos) { +qib_msix_setup (dd, pos, nent, entry); + ret =0 ;/* did it, either MSIx or INTx */ + }else { + pos =pci_find_capability (dd->pcidev,PCI_CAP_ID_MSI ); +if (pos) + ret =qib_msi_setup (dd, pos); +else +qib_dev_err (dd,"No PCI MSI or MSIx capability!\n" ); + } +if (!pos) +qib_enable_intx (dd->pcidev); + +pci_read_config_word (dd->pcidev, pose +PCI_EXP_LNKSTA , &linkstat); +/* +* speed is bits 0-3, linkwidth is bits 4-8 +* no defines for them in headers +*/ + speed = linkstat &0xf ; + linkstat >>=4 ; + linkstat &=0x1f ; + dd->lbus_width = linkstat; + +switch (speed) { +case 1 : + dd->lbus_speed =2500 ;/* Gen1, 2.5GHz */ +break ; +case 2 : + dd->lbus_speed =5000 ;/* Gen1, 5GHz */ +break ; +default :/* not defined, assume gen1 */ + dd->lbus_speed =2500 ; +break ; + } + +/* +* Check against expected pcie width and complain if "wrong" +* on first initialization, not afterwards (i.e., reset). +*/ +if (minw && linkstat < minw) +qib_dev_err (dd, +"PCIe width %u (x%u HCA), performance reduced\n" , + linkstat, minw); + +qib_tune_pcie_caps (dd); + +qib_tune_pcie_coalesce (dd); + +bail: +/* fill in string, even on errors */ +snprintf (dd->lbus_info,sizeof (dd->lbus_info), +"PCIe,%uMHz,x%u\n" , dd->lbus_speed, dd->lbus_width); +return ret; +} + +/* +* Setup pcie interrupt stuff again after a reset. I'd like to just call +* pci_enable_msi() again for msi, but when I do that, +* the MSI enable bit doesn't get set in the command word, and +* we switch to to a different interrupt vector, which is confusing, +* so I instead just do it all inline. Perhaps somehow can tie this +* into the PCIe hotplug support at some point +*/ +int qib_reinit_intr (struct qib_devdata *dd) +{ +int pos; +u16 control; +int ret =0 ; + +/* If we aren't using MSI, don't restore it */ +if (!dd->msi_lo) + goto bail; + + pos =pci_find_capability (dd->pcidev,PCI_CAP_ID_MSI ); +if (!pos) { +qib_dev_err (dd,"Can't find MSI capability, " +"can't restore MSI settings\n" ); + ret =0 ; +/* nothing special for MSIx, just MSI */ + goto bail; + } +pci_write_config_dword (dd->pcidev, pos +PCI_MSI_ADDRESS_LO , + dd->msi_lo); +pci_write_config_dword (dd->pcidev, pos +PCI_MSI_ADDRESS_HI , + dd->msi_hi); +pci_read_config_word (dd->pcidev, pos +PCI_MSI_FLAGS , &control); +if (!(control &PCI_MSI_FLAGS_ENABLE )) { + control |=PCI_MSI_FLAGS_ENABLE ; +pci_write_config_word (dd->pcidev, pos +PCI_MSI_FLAGS , + control); + } +/* now rewrite the data (vector) info */ +pci_write_config_word (dd->pcidev, pos + + ((control &PCI_MSI_FLAGS_64BIT ) ?12 :8 ), + dd->msi_data); + ret =1 ; +bail: +if (!ret && (dd->flags &QIB_HAS_INTX )) { +qib_enable_intx (dd->pcidev); + ret =1 ; + } + +/* and now set the pci master bit again */ +pci_set_master (dd->pcidev); + +return ret; +} + +/* +* Disable msi interrupt if enabled, and clear msi_lo. +* This is used primarily for the fallback to INTx, but +* is also used in reinit after reset, and during cleanup. +*/ +void qib_nomsi (struct qib_devdata *dd) +{ + dd->msi_lo =0 ; +pci_disable_msi (dd->pcidev); +} + +/* +* Same as qib_nosmi, but for MSIx. +*/ +void qib_nomsix (struct qib_devdata *dd) +{ +pci_disable_msix (dd->pcidev); +} + +/* +* Similar to pci_intx(pdev, 1), except that we make sure +* msi(x) is off. +*/ +void qib_enable_intx (struct pci_dev *pdev) +{ +u16 cw, new; +int pos; + +/* first, turn on INTx */ +pci_read_config_word (pdev,PCI_COMMAND , &cw); + new = cw & ~PCI_COMMAND_INTX_DISABLE ; +if (new != cw) +pci_write_config_word (pdev,PCI_COMMAND , new); + + pos =pci_find_capability (pdev,PCI_CAP_ID_MSI ); +if (pos) { +/* then turn off MSI */ +pci_read_config_word (pdev, pos +PCI_MSI_FLAGS , &cw); + new = cw & ~PCI_MSI_FLAGS_ENABLE ; +if (new != cw) +pci_write_config_word (pdev, pos +PCI_MSI_FLAGS , new); + } + pos =pci_find_capability (pdev,PCI_CAP_ID_MSIX ); +if (pos) { +/* then turn off MSIx */ +pci_read_config_word (pdev, pos +PCI_MSIX_FLAGS , &cw); + new = cw & ~PCI_MSIX_FLAGS_ENABLE ; +if (new != cw) +pci_write_config_word (pdev, pos +PCI_MSIX_FLAGS , new); + } +} + +/* +* These two routines are helper routines for the device reset code +* to move all the pcie code out of the chip-specific driver code. +*/ +void qib_pcie_getcmd (struct qib_devdata *dd,u16 *cmd,u8 *iline,u8 *cline) +{ +pci_read_config_word (dd->pcidev,PCI_COMMAND , cmd); +pci_read_config_byte (dd->pcidev,PCI_INTERRUPT_LINE , iline); +pci_read_config_byte (dd->pcidev,PCI_CACHE_LINE_SIZE , cline); +} + +void qib_pcie_reenable (struct qib_devdata *dd,u16 cmd,u8 iline,u8 cline) +{ +int r; + r =pci_write_config_dword (dd->pcidev,PCI_BASE_ADDRESS_0 , + dd->pcibar0); +if (r) +qib_dev_err (dd,"rewrite of BAR0 failed: %d\n" , r); + r =pci_write_config_dword (dd->pcidev,PCI_BASE_ADDRESS_1 , + dd->pcibar1); +if (r) +qib_dev_err (dd,"rewrite of BAR1 failed: %d\n" , r); +/* now re-enable memory access, and restore cosmetic settings */ +pci_write_config_word (dd->pcidev,PCI_COMMAND , cmd); +pci_write_config_byte (dd->pcidev,PCI_INTERRUPT_LINE , iline); +pci_write_config_byte (dd->pcidev,PCI_CACHE_LINE_SIZE , cline); + r =pci_enable_device (dd->pcidev); +if (r) +qib_dev_err (dd,"pci_enable_device failed after " +"reset: %d\n" , r); +} + +/* code to adjust PCIe capabilities. */ + +static int fld2val (int wd,int mask) +{ +int lsbmask; + +if (!mask) +return 0 ; + wd &= mask; + lsbmask = mask ^ (mask & (mask -1 )); + wd /= lsbmask; +return wd; +} + +static int val2fld (int wd,int mask) +{ +int lsbmask; + +if (!mask) +return 0 ; + lsbmask = mask ^ (mask & (mask -1 )); + wd *= lsbmask; +return wd; +} + +static int qib_pcie_coalesce; +module_param_named (pcie_coalesce, qib_pcie_coalesce, int,S_IRUGO ); +MODULE_PARM_DESC (pcie_coalesce,"tune PCIe colescing on some Intel chipsets" ); + +/* +* Enable PCIe completion and data coalescing, on Intel 5x00 and 7300 +* chipsets. This is known to be unsafe for some revisions of some +* of these chipsets, with some BIOS settings, and enabling it on those +* systems may result in the system crashing, and/or data corruption. +*/ +static int qib_tune_pcie_coalesce (struct qib_devdata *dd) +{ +int r; +struct pci_dev *parent; +int ppos; +u16 devid; +u32 mask, bits, val; + +if (!qib_pcie_coalesce) +return 0 ; + +/* Find out supported and configured values for parent (root) */ + parent = dd->pcidev->bus->self; +if (parent->bus->parent) { +qib_devinfo (dd->pcidev,"Parent not root\n" ); +return 1 ; + } + ppos =pci_find_capability (parent,PCI_CAP_ID_EXP ); +if (!ppos) +return 1 ; +if (parent->vendor !=0x8086 ) +return 1 ; + +/* +* - bit 12: Max_rdcmp_Imt_EN: need to set to 1 +* - bit 11: COALESCE_FORCE: need to set to 0 +* - bit 10: COALESCE_EN: need to set to 1 +* (but limitations on some on some chipsets) +* +* On the Intel 5000, 5100, and 7300 chipsets, there is +* also: - bit 25:24: COALESCE_MODE, need to set to 0 +*/ + devid = parent->device; +if (devid >=0x25e2 && devid <=0x25fa ) { +u8 rev; + +/* 5000 P/V/X/Z */ +pci_read_config_byte (parent,PCI_REVISION_ID , &rev); +if (rev <=0xb2 ) + bits =1U <<10 ; +else + bits =7U <<10 ; + mask = (3U <<24 ) | (7U <<10 ); + }else if (devid >=0x65e2 && devid <=0x65fa ) { +/* 5100 */ + bits =1U <<10 ; + mask = (3U <<24 ) | (7U <<10 ); + }else if (devid >=0x4021 && devid <=0x402e ) { +/* 5400 */ + bits =7U <<10 ; + mask =7U <<10 ; + }else if (devid >=0x3604 && devid <=0x360a ) { +/* 7300 */ + bits =7U <<10 ; + mask = (3U <<24 ) | (7U <<10 ); + }else { +/* not one of the chipsets that we know about */ +return 1 ; + } +pci_read_config_dword (parent,0x48 , &val); + val &= ~mask; + val |= bits; + r =pci_write_config_dword (parent,0x48 , val); +return 0 ; +} + +/* +* BIOS may not set PCIe bus-utilization parameters for best performance. +* Check and optionally adjust them to maximize our throughput. +*/ +static int qib_pcie_caps; +module_param_named (pcie_caps, qib_pcie_caps, int,S_IRUGO ); +MODULE_PARM_DESC (pcie_caps,"Max PCIe tuning: Payload (4lsb), ReadReq (D4..7)" ); + +static int qib_tune_pcie_caps (struct qib_devdata *dd) +{ +int ret =1 ;/* Assume the worst */ +struct pci_dev *parent; +int ppos, epos; +u16 pcaps, pctl, ecaps, ectl; +int rc_sup, ep_sup; +int rc_cur, ep_cur; + +/* Find out supported and configured values for parent (root) */ + parent = dd->pcidev->bus->self; +if (parent->bus->parent) { +qib_devinfo (dd->pcidev,"Parent not root\n" ); + goto bail; + } + ppos =pci_find_capability (parent,PCI_CAP_ID_EXP ); +if (ppos) { +pci_read_config_word (parent, ppos +PCI_EXP_DEVCAP , &pcaps); +pci_read_config_word (parent, ppos +PCI_EXP_DEVCTL , &pctl); + }else + goto bail; +/* Find out supported and configured values for endpoint (us) */ + epos =pci_find_capability (dd->pcidev,PCI_CAP_ID_EXP ); +if (epos) { +pci_read_config_word (dd->pcidev, epos +PCI_EXP_DEVCAP , &ecaps); +pci_read_config_word (dd->pcidev, epos +PCI_EXP_DEVCTL , &ectl); + }else + goto bail; + ret =0 ; +/* Find max payload supported by root, endpoint */ + rc_sup =fld2val (pcaps,PCI_EXP_DEVCAP_PAYLOAD ); + ep_sup =fld2val (ecaps,PCI_EXP_DEVCAP_PAYLOAD ); +if (rc_sup > ep_sup) + rc_sup = ep_sup; + + rc_cur =fld2val (pctl,PCI_EXP_DEVCTL_PAYLOAD ); + ep_cur =fld2val (ectl,PCI_EXP_DEVCTL_PAYLOAD ); + +/* If Supported greater than limit in module param, limit it */ +if (rc_sup > (qib_pcie_caps &7 )) + rc_sup = qib_pcie_caps &7 ; +/* If less than (allowed, supported), bump root payload */ +if (rc_sup > rc_cur) { + rc_cur = rc_sup; + pctl = (pctl & ~PCI_EXP_DEVCTL_PAYLOAD ) | +val2fld (rc_cur,PCI_EXP_DEVCTL_PAYLOAD ); +pci_write_config_word (parent, ppos +PCI_EXP_DEVCTL , pctl); + } +/* If less than (allowed, supported), bump endpoint payload */ +if (rc_sup > ep_cur) { + ep_cur = rc_sup; + ectl = (ectl & ~PCI_EXP_DEVCTL_PAYLOAD ) | +val2fld (ep_cur,PCI_EXP_DEVCTL_PAYLOAD ); +pci_write_config_word (dd->pcidev, epos +PCI_EXP_DEVCTL , ectl); + } + +/* +* Now the Read Request size. +* No field for max supported, but PCIe spec limits it to 4096, +* which is code '5' (log2(4096) - 7) +*/ + rc_sup =5 ; +if (rc_sup > ((qib_pcie_caps >>4 ) &7 )) + rc_sup = (qib_pcie_caps >>4 ) &7 ; + rc_cur =fld2val (pctl,PCI_EXP_DEVCTL_READRQ ); + ep_cur =fld2val (ectl,PCI_EXP_DEVCTL_READRQ ); + +if (rc_sup > rc_cur) { + rc_cur = rc_sup; + pctl = (pctl & ~PCI_EXP_DEVCTL_READRQ ) | +val2fld (rc_cur,PCI_EXP_DEVCTL_READRQ ); +pci_write_config_word (parent, ppos +PCI_EXP_DEVCTL , pctl); + } +if (rc_sup > ep_cur) { + ep_cur = rc_sup; + ectl = (ectl & ~PCI_EXP_DEVCTL_READRQ ) | +val2fld (ep_cur,PCI_EXP_DEVCTL_READRQ ); +pci_write_config_word (dd->pcidev, epos +PCI_EXP_DEVCTL , ectl); + } +bail: +return ret; +} +/* End of PCIe capability tuning */ + +/* +* From here through qib_pci_err_handler definition is invoked via +* PCI error infrastructure, registered via pci +*/ +static pci_ers_result_t +qib_pci_error_detected (struct pci_dev *pdev,pci_channel_state_t state) +{ +struct qib_devdata *dd =pci_get_drvdata (pdev); +pci_ers_result_t ret =PCI_ERS_RESULT_RECOVERED ; + +switch (state) { +case pci_channel_io_normal: +qib_devinfo (pdev,"State Normal, ignoring\n" ); +break ; + +case pci_channel_io_frozen: +qib_devinfo (pdev,"State Frozen, requesting reset\n" ); +pci_disable_device (pdev); + ret =PCI_ERS_RESULT_NEED_RESET ; +break ; + +case pci_channel_io_perm_failure: +qib_devinfo (pdev,"State Permanent Failure, disabling\n" ); +if (dd) { +/* no more register accesses! */ + dd->flags &= ~QIB_PRESENT ; +qib_disable_after_error (dd); + } +/* else early, or other problem */ + ret =PCI_ERS_RESULT_DISCONNECT ; +break ; + +default :/* shouldn't happen */ +qib_devinfo (pdev,"QIB PCI errors detected (state %d)\n" , + state); +break ; + } +return ret; +} + +static pci_ers_result_t +qib_pci_mmio_enabled (struct pci_dev *pdev) +{ +u64 words =0U ; +struct qib_devdata *dd =pci_get_drvdata (pdev); +pci_ers_result_t ret =PCI_ERS_RESULT_RECOVERED ; + +if (dd && dd->pport) { + words = dd->f_portcntr (dd->pport,QIBPORTCNTR_WORDRCV ); +if (words == ~0ULL ) + ret =PCI_ERS_RESULT_NEED_RESET ; + } +qib_devinfo (pdev,"QIB mmio_enabled function called, " +"read wordscntr %Lx, returning %d\n" , words, ret); +return ret; +} + +static pci_ers_result_t +qib_pci_slot_reset (struct pci_dev *pdev) +{ +qib_devinfo (pdev,"QIB link_reset function called, ignored\n" ); +return PCI_ERS_RESULT_CAN_RECOVER ; +} + +static pci_ers_result_t +qib_pci_link_reset (struct pci_dev *pdev) +{ +qib_devinfo (pdev,"QIB link_reset function called, ignored\n" ); +return PCI_ERS_RESULT_CAN_RECOVER ; +} + +static void +qib_pci_resume (struct pci_dev *pdev) +{ +struct qib_devdata *dd =pci_get_drvdata (pdev); +qib_devinfo (pdev,"QIB resume function called\n" ); +pci_cleanup_aer_uncorrect_error_status (pdev); +/* +* Running jobs will fail, since it's asynchronous +* unlike sysfs-requested reset. Better than +* doing nothing. +*/ +qib_init (dd,1 );/* same as re-init after reset */ +} + +struct pci_error_handlers qib_pci_err_handler = { + .error_detected = qib_pci_error_detected, + .mmio_enabled = qib_pci_mmio_enabled, + .link_reset = qib_pci_link_reset, + .slot_reset = qib_pci_slot_reset, + .resume = qib_pci_resume, +};
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 27/52 IB/qib: Add qib_pio_copy.c
In reply to a message not in the archivecreates the qib_pio_copy.c file.
---
drivers/infiniband/hw/qib/qib_pio_copy.c | 64 ++++++++++++++++++++++++++++++ 1 files changed, 64 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_pio_copy.c
drivers/infiniband/hw/qib/qib_pio_copy.c new file +64 -0
@@ -0,0 +1,64 @@ +/* +* Copyright (c) 2009 QLogic Corporation. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include "qib.h" + +/** +* qib_pio_copy - copy data to MMIO space, in multiples of 32-bits +* @to: destination, in MMIO space (must be 64-bit aligned) +* @from: source (must be 64-bit aligned) +* @count: number of 32-bit quantities to copy +* +* Copy data from kernel space to MMIO space, in multiples of 32 bits at a +* time. Order of access is not guaranteed, nor is a memory barrier +* performed afterwards. +*/ +void qib_pio_copy (void __iomem *to,const void *from,size_t count) +{ +#ifdef CONFIG_64BIT +u64 __iomem *dst = to; +const u64 *src = from; +const u64 *end = src + (count >>1 ); + +while (src < end) +__raw_writeq (*src++, dst++); +if (count &1 ) +__raw_writel (*(const u32 *)src, dst); +#else +u32 __iomem *dst = to; +const u32 *src = from; +const u32 *end = src + count; + +while (src < end) +__raw_writel (*src++, dst++); +#endif +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 28/52 IB/qib: Add qib_qp.c
In reply to a message not in the archivecreates the qib_qp.c file.
---
drivers/infiniband/hw/qib/qib_qp.c | 1255 ++++++++++++++++++++++++++++++++++++ 1 files changed, 1255 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_qp.c
drivers/infiniband/hw/qib/qib_qp.c new file +1255 -0
@@ -0,0 +1,1255 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation. +* All rights reserved. +* Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/err.h> +#include <linux/vmalloc.h> + +#include "qib.h" + +#define BITS_PER_PAGE (PAGE_SIZE*BITS_PER_BYTE) +#define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1) + +static inline unsigned mk_qpn (struct qib_qpn_table *qpt, +struct qpn_map *map,unsigned off) +{ +return (map - qpt->map) *BITS_PER_PAGE + off; +} + +static inline unsigned find_next_offset (struct qib_qpn_table *qpt, +struct qpn_map *map,unsigned off, +unsigned r) +{ +if (qpt->mask) { + off++; +if ((off & qpt->mask) >>1 != r) + off = ((off & qpt->mask) ? + (off | qpt->mask) +1 : off) | (r <<1 ); + }else + off =find_next_zero_bit (map->page,BITS_PER_PAGE , off); +return 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 ,/* E */ +192 ,/* F */ +256 ,/* 10 */ +384 ,/* 11 */ +512 ,/* 12 */ +768 ,/* 13 */ +1024 ,/* 14 */ +1536 ,/* 15 */ +2048 ,/* 16 */ +3072 ,/* 17 */ +4096 ,/* 18 */ +6144 ,/* 19 */ +8192 ,/* 1A */ +12288 ,/* 1B */ +16384 ,/* 1C */ +24576 ,/* 1D */ +32768 /* 1E */ +}; + +static void get_map_page (struct qib_qpn_table *qpt,struct qpn_map *map) +{ +unsigned long page =get_zeroed_page (GFP_KERNEL ); + +/* +* Free the page if someone raced with us installing it. +*/ + +spin_lock (&qpt->lock); +if (map->page) +free_page (page); +else + map->page = (void *)page; +spin_unlock (&qpt->lock); +} + +/* +* Allocate the next available QPN or +* zero/one for QP type IB_QPT_SMI/IB_QPT_GSI. +*/ +static int alloc_qpn (struct qib_devdata *dd,struct qib_qpn_table *qpt, +enum ib_qp_type type,u8 port) +{ +u32 i, offset, max_scan, qpn; +struct qpn_map *map; +u32 ret; +int r; + +if (type ==IB_QPT_SMI || type ==IB_QPT_GSI ) { +unsigned n; + + ret = type ==IB_QPT_GSI ; + n =1 << (ret +2 * (port -1 )); +spin_lock (&qpt->lock); +if (qpt->flags & n) + ret = -EINVAL ; +else + qpt->flags |= n; +spin_unlock (&qpt->lock); + goto bail; + } + + r =smp_processor_id (); +if (r >= dd->n_krcv_queues) + r %= dd->n_krcv_queues; + qpn = qpt->last +1 ; +if (qpn >=QPN_MAX ) + qpn =2 ; +if (qpt->mask && ((qpn & qpt->mask) >>1 ) != r) + qpn = ((qpn & qpt->mask) ? (qpn | qpt->mask) +1 : qpn) | + (r <<1 ); + offset = qpn &BITS_PER_PAGE_MASK ; + map = &qpt->map[qpn /BITS_PER_PAGE ]; + max_scan = qpt->nmaps - !offset; +for (i =0 ;;) { +if (unlikely (!map->page)) { +get_map_page (qpt, map); +if (unlikely (!map->page)) +break ; + } +do { +if (!test_and_set_bit (offset, map->page)) { + qpt->last = qpn; + ret = qpn; + goto bail; + } + offset =find_next_offset (qpt, map, offset, r); + qpn =mk_qpn (qpt, map, offset); +/* +* This test differs from alloc_pidmap(). +* If find_next_offset() does find a zero +* bit, we don't need to check for QPN +* wrapping around past our starting QPN. +* We just need to be sure we don't loop +* forever. +*/ + }while (offset <BITS_PER_PAGE && qpn <QPN_MAX ); +/* +* In order to keep the number of pages allocated to a +* minimum, we scan the all existing pages before increasing +* the size of the bitmap table. +*/ +if (++i > max_scan) { +if (qpt->nmaps ==QPNMAP_ENTRIES ) +break ; + map = &qpt->map[qpt->nmaps++]; + offset = qpt->mask ? (r <<1 ) :0 ; + }else if (map < &qpt->map[qpt->nmaps]) { + ++map; + offset = qpt->mask ? (r <<1 ) :0 ; + }else { + map = &qpt->map[0 ]; + offset = qpt->mask ? (r <<1 ) :2 ; + } + qpn =mk_qpn (qpt, map, offset); + } + + ret = -ENOMEM ; + +bail: +return ret; +} + +static void free_qpn (struct qib_qpn_table *qpt,u32 qpn) +{ +struct qpn_map *map; + + map = qpt->map + qpn /BITS_PER_PAGE ; +if (map->page) +clear_bit (qpn &BITS_PER_PAGE_MASK , map->page); +} + +/* +* Put the QP into the hash table. +* The hash table holds a reference to the QP. +*/ +static void insert_qp (struct qib_ibdev *dev,struct qib_qp *qp) +{ +struct qib_ibport *ibp =to_iport (qp->ibqp.device, qp->port_num); +unsigned n = qp->ibqp.qp_num % dev->qp_table_size; +unsigned long flags; + +spin_lock_irqsave (&dev->qpt_lock, flags); + +if (qp->ibqp.qp_num ==0 ) + ibp->qp0 = qp; +else if (qp->ibqp.qp_num ==1 ) + ibp->qp1 = qp; +else { + qp->next = dev->qp_table[n]; + dev->qp_table[n] = qp; + } +atomic_inc (&qp->refcount); + +spin_unlock_irqrestore (&dev->qpt_lock, flags); +} + +/* +* Remove the QP from the table so it can't be found asynchronously by +* the receive interrupt routine. +*/ +static void remove_qp (struct qib_ibdev *dev,struct qib_qp *qp) +{ +struct qib_ibport *ibp =to_iport (qp->ibqp.device, qp->port_num); +struct qib_qp *q, **qpp; +unsigned long flags; + + qpp = &dev->qp_table[qp->ibqp.qp_num % dev->qp_table_size]; + +spin_lock_irqsave (&dev->qpt_lock, flags); + +if (ibp->qp0 == qp) { + ibp->qp0 =NULL ; +atomic_dec (&qp->refcount); + }else if (ibp->qp1 == qp) { + ibp->qp1 =NULL ; +atomic_dec (&qp->refcount); + }else +for (; (q = *qpp) !=NULL ; qpp = &q->next) +if (q == qp) { + *qpp = qp->next; + qp->next =NULL ; +atomic_dec (&qp->refcount); +break ; + } + +spin_unlock_irqrestore (&dev->qpt_lock, flags); +} + +/** +* qib_free_all_qps - check for QPs still in use +* @qpt: the QP table to empty +* +* There should not be any QPs still in use. +* Free memory for table. +*/ +unsigned qib_free_all_qps (struct qib_devdata *dd) +{ +struct qib_ibdev *dev = &dd->verbs_dev; +unsigned long flags; +struct qib_qp *qp; +unsigned n, qp_inuse =0 ; + +for (n =0 ; n < dd->num_pports; n++) { +struct qib_ibport *ibp = &dd->pport[n].ibport_data; + +if (!qib_mcast_tree_empty (ibp)) + qp_inuse++; +if (ibp->qp0) + qp_inuse++; +if (ibp->qp1) + qp_inuse++; + } + +spin_lock_irqsave (&dev->qpt_lock, flags); +for (n =0 ; n < dev->qp_table_size; n++) { + qp = dev->qp_table[n]; + dev->qp_table[n] =NULL ; + +for (; qp; qp = qp->next) + qp_inuse++; + } +spin_unlock_irqrestore (&dev->qpt_lock, flags); + +return qp_inuse; +} + +/** +* qib_lookup_qpn - return the QP with the given QPN +* @qpt: the QP table +* @qpn: the QP number to look up +* +* The caller is responsible for decrementing the QP reference count +* when done. +*/ +struct qib_qp *qib_lookup_qpn (struct qib_ibport *ibp,u32 qpn) +{ +struct qib_ibdev *dev = &ppd_from_ibp (ibp)->dd->verbs_dev; +unsigned long flags; +struct qib_qp *qp; + +spin_lock_irqsave (&dev->qpt_lock, flags); + +if (qpn ==0 ) + qp = ibp->qp0; +else if (qpn ==1 ) + qp = ibp->qp1; +else +for (qp = dev->qp_table[qpn % dev->qp_table_size]; qp; + qp = qp->next) +if (qp->ibqp.qp_num == qpn) +break ; +if (qp) +atomic_inc (&qp->refcount); + +spin_unlock_irqrestore (&dev->qpt_lock, flags); +return qp; +} + +/** +* qib_reset_qp - initialize the QP state to the reset state +* @qp: the QP to reset +* @type: the QP type +*/ +static void qib_reset_qp (struct qib_qp *qp,enum ib_qp_type type) +{ + qp->remote_qpn =0 ; + qp->qkey =0 ; + qp->qp_access_flags =0 ; +atomic_set (&qp->s_dma_busy,0 ); + qp->s_flags &=QIB_S_SIGNAL_REQ_WR ; + qp->s_hdrwords =0 ; + qp->s_wqe =NULL ; + qp->s_draining =0 ; + qp->s_next_psn =0 ; + qp->s_last_psn =0 ; + qp->s_sending_psn =0 ; + qp->s_sending_hpsn =0 ; + qp->s_psn =0 ; + qp->r_psn =0 ; + qp->r_msn =0 ; +if (type ==IB_QPT_RC ) { + qp->s_state =IB_OPCODE_RC_SEND_LAST ; + qp->r_state =IB_OPCODE_RC_SEND_LAST ; + }else { + qp->s_state =IB_OPCODE_UC_SEND_LAST ; + qp->r_state =IB_OPCODE_UC_SEND_LAST ; + } + qp->s_ack_state =IB_OPCODE_RC_ACKNOWLEDGE ; + qp->r_nak_state =0 ; + qp->r_aflags =0 ; + qp->r_flags =0 ; + qp->s_head =0 ; + qp->s_tail =0 ; + qp->s_cur =0 ; + qp->s_acked =0 ; + qp->s_last =0 ; + qp->s_ssn =1 ; + qp->s_lsn =0 ; + qp->s_mig_state =IB_MIG_MIGRATED ; +memset (qp->s_ack_queue,0 ,sizeof (qp->s_ack_queue)); + qp->r_head_ack_queue =0 ; + qp->s_tail_ack_queue =0 ; + qp->s_num_rd_atomic =0 ; +if (qp->r_rq.wq) { + qp->r_rq.wq->head =0 ; + qp->r_rq.wq->tail =0 ; + } + qp->r_sge.num_sge =0 ; +} + +static void clear_mr_refs (struct qib_qp *qp,int clr_sends) +{ +unsigned n; + +if (test_and_clear_bit (QIB_R_REWIND_SGE , &qp->r_aflags)) +while (qp->s_rdma_read_sge.num_sge) { +atomic_dec (&qp->s_rdma_read_sge.sge.mr->refcount); +if (--qp->s_rdma_read_sge.num_sge) + qp->s_rdma_read_sge.sge = + *qp->s_rdma_read_sge.sg_list++; + } + +while (qp->r_sge.num_sge) { +atomic_dec (&qp->r_sge.sge.mr->refcount); +if (--qp->r_sge.num_sge) + qp->r_sge.sge = *qp->r_sge.sg_list++; + } + +if (clr_sends) { +while (qp->s_last != qp->s_head) { +struct qib_swqe *wqe =get_swqe_ptr (qp, qp->s_last); +unsigned i; + +for (i =0 ; i < wqe->wr.num_sge; i++) { +struct qib_sge *sge = &wqe->sg_list[i]; + +atomic_dec (&sge->mr->refcount); + } +if (qp->ibqp.qp_type ==IB_QPT_UD || + qp->ibqp.qp_type ==IB_QPT_SMI || + qp->ibqp.qp_type ==IB_QPT_GSI ) +atomic_dec (&to_iah (wqe->wr.wr.ud.ah)->refcount); +if (++qp->s_last >= qp->s_size) + qp->s_last =0 ; + } +if (qp->s_rdma_mr) { +atomic_dec (&qp->s_rdma_mr->refcount); + qp->s_rdma_mr =NULL ; + } + } + +if (qp->ibqp.qp_type !=IB_QPT_RC ) +return ; + +for (n =0 ; n <ARRAY_SIZE (qp->s_ack_queue); n++) { +struct qib_ack_entry *e = &qp->s_ack_queue[n]; + +if (e->opcode ==IB_OPCODE_RC_RDMA_READ_REQUEST && + e->rdma_sge.mr) { +atomic_dec (&e->rdma_sge.mr->refcount); + e->rdma_sge.mr =NULL ; + } + } +} + +/** +* qib_error_qp - put a QP into the error state +* @qp: the QP to put into the error state +* @err: the receive completion error to signal if a RWQE is active +* +* Flushes both send and receive work queues. +* Returns true if last WQE event should be generated. +* The QP s_lock should be held and interrupts disabled. +* If we are already in error state, just return. +*/ +int qib_error_qp (struct qib_qp *qp,enum ib_wc_status err) +{ +struct qib_ibdev *dev =to_idev (qp->ibqp.device); +struct ib_wc wc; +int ret =0 ; + +if (qp->state ==IB_QPS_ERR || qp->state ==IB_QPS_RESET ) + goto bail; + + qp->state =IB_QPS_ERR ; + +if (qp->s_flags & (QIB_S_TIMER |QIB_S_WAIT_RNR )) { + qp->s_flags &= ~(QIB_S_TIMER |QIB_S_WAIT_RNR ); +del_timer (&qp->s_timer); + } +spin_lock (&dev->pending_lock); +if (!list_empty (&qp->iowait) && !(qp->s_flags &QIB_S_BUSY )) { + qp->s_flags &= ~QIB_S_ANY_WAIT_IO ; +list_del_init (&qp->iowait); + } +spin_unlock (&dev->pending_lock); + +if (!(qp->s_flags &QIB_S_BUSY )) { + qp->s_hdrwords =0 ; +if (qp->s_rdma_mr) { +atomic_dec (&qp->s_rdma_mr->refcount); + qp->s_rdma_mr =NULL ; + } +if (qp->s_tx) { +qib_put_txreq (qp->s_tx); + qp->s_tx =NULL ; + } + } + +/* Schedule the sending tasklet to drain the send work queue. */ +if (qp->s_last != qp->s_head) +qib_schedule_send (qp); + +clear_mr_refs (qp,0 ); + +memset (&wc,0 ,sizeof (wc)); + wc.qp = &qp->ibqp; + wc.opcode =IB_WC_RECV ; + +if (test_and_clear_bit (QIB_R_WRID_VALID , &qp->r_aflags)) { + wc.wr_id = qp->r_wr_id; + wc.status = err; +qib_cq_enter (to_icq (qp->ibqp.recv_cq), &wc,1 ); + } + wc.status =IB_WC_WR_FLUSH_ERR ; + +if (qp->r_rq.wq) { +struct qib_rwq *wq; +u32 head; +u32 tail; + +spin_lock (&qp->r_rq.lock); + +/* sanity check pointers before trusting them */ + wq = qp->r_rq.wq; + head = wq->head; +if (head >= qp->r_rq.size) + head =0 ; + tail = wq->tail; +if (tail >= qp->r_rq.size) + tail =0 ; +while (tail != head) { + wc.wr_id =get_rwqe_ptr (&qp->r_rq, tail)->wr_id; +if (++tail >= qp->r_rq.size) + tail =0 ; +qib_cq_enter (to_icq (qp->ibqp.recv_cq), &wc,1 ); + } + wq->tail = tail; + +spin_unlock (&qp->r_rq.lock); + }else if (qp->ibqp.event_handler) + ret =1 ; + +bail: +return ret; +} + +/** +* qib_modify_qp - modify the attributes of a queue pair +* @ibqp: the queue pair who's attributes we're modifying +* @attr: the new attributes +* @attr_mask: the mask of attributes to modify +* @udata: user data for libibverbs.so +* +* Returns 0 on success, otherwise returns an errno. +*/ +int qib_modify_qp (struct ib_qp *ibqp,struct ib_qp_attr *attr, +int attr_mask,struct ib_udata *udata) +{ +struct qib_ibdev *dev =to_idev (ibqp->device); +struct qib_qp *qp =to_iqp (ibqp); +enum ib_qp_state cur_state, new_state; +struct ib_event ev; +int lastwqe =0 ; +int mig =0 ; +int ret; +u32 pmtu =0 ;/* for gcc warning only */ + +spin_lock_irq (&qp->r_lock); +spin_lock (&qp->s_lock); + + cur_state = attr_mask &IB_QP_CUR_STATE ? + attr->cur_qp_state : qp->state; + new_state = attr_mask &IB_QP_STATE ? attr->qp_state : cur_state; + +if (!ib_modify_qp_is_ok (cur_state, new_state, ibqp->qp_type, + attr_mask)) + goto inval; + +if (attr_mask &IB_QP_AV ) { +if (attr->ah_attr.dlid >=QIB_MULTICAST_LID_BASE ) + goto inval; +if (qib_check_ah (qp->ibqp.device, &attr->ah_attr)) + goto inval; + } + +if (attr_mask &IB_QP_ALT_PATH ) { +if (attr->alt_ah_attr.dlid >=QIB_MULTICAST_LID_BASE ) + goto inval; +if (qib_check_ah (qp->ibqp.device, &attr->alt_ah_attr)) + goto inval; +if (attr->alt_pkey_index >=qib_get_npkeys (dd_from_dev (dev))) + goto inval; + } + +if (attr_mask &IB_QP_PKEY_INDEX ) +if (attr->pkey_index >=qib_get_npkeys (dd_from_dev (dev))) + goto inval; + +if (attr_mask &IB_QP_MIN_RNR_TIMER ) +if (attr->min_rnr_timer >31 ) + goto inval; + +if (attr_mask &IB_QP_PORT ) +if (qp->ibqp.qp_type ==IB_QPT_SMI || + qp->ibqp.qp_type ==IB_QPT_GSI || + attr->port_num ==0 || + attr->port_num > ibqp->device->phys_port_cnt) + goto inval; + +if (attr_mask &IB_QP_DEST_QPN ) +if (attr->dest_qp_num >QIB_QPN_MASK ) + goto inval; + +if (attr_mask &IB_QP_RETRY_CNT ) +if (attr->retry_cnt >7 ) + goto inval; + +if (attr_mask &IB_QP_RNR_RETRY ) +if (attr->rnr_retry >7 ) + goto inval; + +/* +* Don't allow invalid path_mtu values. OK to set greater +* than the active mtu (or even the max_cap, if we have tuned +* that to a small mtu. We'll set qp->path_mtu +* to the lesser of requested attribute mtu and active, +* for packetizing messages. +* Note that the QP port has to be set in INIT and MTU in RTR. +*/ +if (attr_mask &IB_QP_PATH_MTU ) { +struct qib_devdata *dd =dd_from_dev (dev); +int mtu, pidx = qp->port_num -1 ; + + mtu =ib_mtu_enum_to_int (attr->path_mtu); +if (mtu ==-1 ) + goto inval; +if (mtu > dd->pport[pidx].ibmtu) { +switch (dd->pport[pidx].ibmtu) { +case 4096 : + pmtu =IB_MTU_4096 ; +break ; +case 2048 : + pmtu =IB_MTU_2048 ; +break ; +case 1024 : + pmtu =IB_MTU_1024 ; +break ; +case 512 : + pmtu =IB_MTU_512 ; +break ; +case 256 : + pmtu =IB_MTU_256 ; +break ; +default : + pmtu =IB_MTU_2048 ; + } + }else + pmtu = attr->path_mtu; + } + +if (attr_mask &IB_QP_PATH_MIG_STATE ) { +if (attr->path_mig_state ==IB_MIG_REARM ) { +if (qp->s_mig_state ==IB_MIG_ARMED ) + goto inval; +if (new_state !=IB_QPS_RTS ) + goto inval; + }else if (attr->path_mig_state ==IB_MIG_MIGRATED ) { +if (qp->s_mig_state ==IB_MIG_REARM ) + goto inval; +if (new_state !=IB_QPS_RTS && new_state !=IB_QPS_SQD ) + goto inval; +if (qp->s_mig_state ==IB_MIG_ARMED ) + mig =1 ; + }else + goto inval; + } + +if (attr_mask &IB_QP_MAX_DEST_RD_ATOMIC ) +if (attr->max_dest_rd_atomic >QIB_MAX_RDMA_ATOMIC ) + goto inval; + +switch (new_state) { +case IB_QPS_RESET : +if (qp->state !=IB_QPS_RESET ) { + qp->state =IB_QPS_RESET ; +spin_lock (&dev->pending_lock); +if (!list_empty (&qp->iowait)) +list_del_init (&qp->iowait); +spin_unlock (&dev->pending_lock); + qp->s_flags &= ~(QIB_S_TIMER |QIB_S_ANY_WAIT ); +spin_unlock (&qp->s_lock); +spin_unlock_irq (&qp->r_lock); +/* Stop the sending work queue and retry timer */ +cancel_work_sync (&qp->s_work); +del_timer_sync (&qp->s_timer); +wait_event (qp->wait_dma, !atomic_read (&qp->s_dma_busy)); +if (qp->s_tx) { +qib_put_txreq (qp->s_tx); + qp->s_tx =NULL ; + } +remove_qp (dev, qp); +wait_event (qp->wait, !atomic_read (&qp->refcount)); +spin_lock_irq (&qp->r_lock); +spin_lock (&qp->s_lock); +clear_mr_refs (qp,1 ); +qib_reset_qp (qp, ibqp->qp_type); + } +break ; + +case IB_QPS_RTR : +/* Allow event to retrigger if QP set to RTR more than once */ + qp->r_flags &= ~QIB_R_COMM_EST ; + qp->state = new_state; +break ; + +case IB_QPS_SQD : + qp->s_draining = qp->s_last != qp->s_cur; + qp->state = new_state; +break ; + +case IB_QPS_SQE : +if (qp->ibqp.qp_type ==IB_QPT_RC ) + goto inval; + qp->state = new_state; +break ; + +case IB_QPS_ERR : + lastwqe =qib_error_qp (qp,IB_WC_WR_FLUSH_ERR ); +break ; + +default : + qp->state = new_state; +break ; + } + +if (attr_mask &IB_QP_PKEY_INDEX ) + qp->s_pkey_index = attr->pkey_index; + +if (attr_mask &IB_QP_PORT ) + qp->port_num = attr->port_num; + +if (attr_mask &IB_QP_DEST_QPN ) + qp->remote_qpn = attr->dest_qp_num; + +if (attr_mask &IB_QP_SQ_PSN ) { + qp->s_next_psn = attr->sq_psn &QIB_PSN_MASK ; + qp->s_psn = qp->s_next_psn; + qp->s_sending_psn = qp->s_next_psn; + qp->s_last_psn = qp->s_next_psn -1 ; + qp->s_sending_hpsn = qp->s_last_psn; + } + +if (attr_mask &IB_QP_RQ_PSN ) + qp->r_psn = attr->rq_psn &QIB_PSN_MASK ; + +if (attr_mask &IB_QP_ACCESS_FLAGS ) + qp->qp_access_flags = attr->qp_access_flags; + +if (attr_mask &IB_QP_AV ) { + qp->remote_ah_attr = attr->ah_attr; + qp->s_srate = attr->ah_attr.static_rate; + } + +if (attr_mask &IB_QP_ALT_PATH ) { + qp->alt_ah_attr = attr->alt_ah_attr; + qp->s_alt_pkey_index = attr->alt_pkey_index; + } + +if (attr_mask &IB_QP_PATH_MIG_STATE ) { + qp->s_mig_state = attr->path_mig_state; +if (mig) { + qp->remote_ah_attr = qp->alt_ah_attr; + qp->port_num = qp->alt_ah_attr.port_num; + qp->s_pkey_index = qp->s_alt_pkey_index; + } + } + +if (attr_mask &IB_QP_PATH_MTU ) + qp->path_mtu = pmtu; + +if (attr_mask &IB_QP_RETRY_CNT ) { + qp->s_retry_cnt = attr->retry_cnt; + qp->s_retry = attr->retry_cnt; + } + +if (attr_mask &IB_QP_RNR_RETRY ) { + qp->s_rnr_retry_cnt = attr->rnr_retry; + qp->s_rnr_retry = attr->rnr_retry; + } + +if (attr_mask &IB_QP_MIN_RNR_TIMER ) + qp->r_min_rnr_timer = attr->min_rnr_timer; + +if (attr_mask &IB_QP_TIMEOUT ) + qp->timeout = attr->timeout; + +if (attr_mask &IB_QP_QKEY ) + qp->qkey = attr->qkey; + +if (attr_mask &IB_QP_MAX_DEST_RD_ATOMIC ) + qp->r_max_rd_atomic = attr->max_dest_rd_atomic; + +if (attr_mask &IB_QP_MAX_QP_RD_ATOMIC ) + qp->s_max_rd_atomic = attr->max_rd_atomic; + +spin_unlock (&qp->s_lock); +spin_unlock_irq (&qp->r_lock); + +if (cur_state ==IB_QPS_RESET && new_state ==IB_QPS_INIT ) +insert_qp (dev, qp); + +if (lastwqe) { + ev.device = qp->ibqp.device; + ev.element.qp = &qp->ibqp; + ev.event =IB_EVENT_QP_LAST_WQE_REACHED ; + qp->ibqp.event_handler (&ev, qp->ibqp.qp_context); + } +if (mig) { + ev.device = qp->ibqp.device; + ev.element.qp = &qp->ibqp; + ev.event =IB_EVENT_PATH_MIG ; + qp->ibqp.event_handler (&ev, qp->ibqp.qp_context); + } + ret =0 ; + goto bail; + +inval: +spin_unlock (&qp->s_lock); +spin_unlock_irq (&qp->r_lock); + ret = -EINVAL ; + +bail: +return ret; +} + +int qib_query_qp (struct ib_qp *ibqp,struct ib_qp_attr *attr, +int attr_mask,struct ib_qp_init_attr *init_attr) +{ +struct qib_qp *qp =to_iqp (ibqp); + + attr->qp_state = qp->state; + attr->cur_qp_state = attr->qp_state; + attr->path_mtu = qp->path_mtu; + attr->path_mig_state = qp->s_mig_state; + attr->qkey = qp->qkey; + attr->rq_psn = qp->r_psn &QIB_PSN_MASK ; + attr->sq_psn = qp->s_next_psn &QIB_PSN_MASK ; + attr->dest_qp_num = qp->remote_qpn; + attr->qp_access_flags = qp->qp_access_flags; + attr->cap.max_send_wr = qp->s_size -1 ; + attr->cap.max_recv_wr = qp->ibqp.srq ?0 : qp->r_rq.size -1 ; + attr->cap.max_send_sge = qp->s_max_sge; + attr->cap.max_recv_sge = qp->r_rq.max_sge; + attr->cap.max_inline_data =0 ; + attr->ah_attr = qp->remote_ah_attr; + attr->alt_ah_attr = qp->alt_ah_attr; + attr->pkey_index = qp->s_pkey_index; + attr->alt_pkey_index = qp->s_alt_pkey_index; + attr->en_sqd_async_notify =0 ; + attr->sq_draining = qp->s_draining; + attr->max_rd_atomic = qp->s_max_rd_atomic; + attr->max_dest_rd_atomic = qp->r_max_rd_atomic; + attr->min_rnr_timer = qp->r_min_rnr_timer; + attr->port_num = qp->port_num; + attr->timeout = qp->timeout; + attr->retry_cnt = qp->s_retry_cnt; + attr->rnr_retry = qp->s_rnr_retry_cnt; + attr->alt_port_num = qp->alt_ah_attr.port_num; + attr->alt_timeout = qp->alt_timeout; + + init_attr->event_handler = qp->ibqp.event_handler; + init_attr->qp_context = qp->ibqp.qp_context; + init_attr->send_cq = qp->ibqp.send_cq; + init_attr->recv_cq = qp->ibqp.recv_cq; + init_attr->srq = qp->ibqp.srq; + init_attr->cap = attr->cap; +if (qp->s_flags &QIB_S_SIGNAL_REQ_WR ) + init_attr->sq_sig_type =IB_SIGNAL_REQ_WR ; +else + init_attr->sq_sig_type =IB_SIGNAL_ALL_WR ; + init_attr->qp_type = qp->ibqp.qp_type; + init_attr->port_num = qp->port_num; +return 0 ; +} + +/** +* qib_compute_aeth - compute the AETH (syndrome + MSN) +* @qp: the queue pair to compute the AETH for +* +* Returns the AETH. +*/ +__be32 qib_compute_aeth (struct qib_qp *qp) +{ +u32 aeth = qp->r_msn &QIB_MSN_MASK ; + +if (qp->ibqp.srq) { +/* +* Shared receive queues don't generate credits. +* Set the credit field to the invalid value. +*/ + aeth |=QIB_AETH_CREDIT_INVAL <<QIB_AETH_CREDIT_SHIFT ; + }else { +u32 min, max, x; +u32 credits; +struct qib_rwq *wq = qp->r_rq.wq; +u32 head; +u32 tail; + +/* sanity check pointers before trusting them */ + head = wq->head; +if (head >= qp->r_rq.size) + head =0 ; + tail = wq->tail; +if (tail >= qp->r_rq.size) + tail =0 ; +/* +* Compute the number of credits available (RWQEs). +* XXX Not holding the r_rq.lock here so there is a small +* chance that the pair of reads are not atomic. +*/ + credits = head - tail; +if ((int )credits <0 ) + credits += qp->r_rq.size; +/* +* Binary search the credit table to find the code to +* use. +*/ + min =0 ; + max =31 ; +for (;;) { + x = (min + max) /2 ; +if (credit_table[x] == credits) +break ; +if (credit_table[x] > credits) + max = x; +else if (min == x) +break ; +else + min = x; + } + aeth |= x <<QIB_AETH_CREDIT_SHIFT ; + } +return cpu_to_be32 (aeth); +} + +/** +* qib_create_qp - create a queue pair for a device +* @ibpd: the protection domain who's device we create the queue pair for +* @init_attr: the attributes of the queue pair +* @udata: user data for libibverbs.so +* +* Returns the queue pair on success, otherwise returns an errno. +* +* Called by the ib_create_qp() core verbs function. +*/ +struct ib_qp *qib_create_qp (struct ib_pd *ibpd, +struct ib_qp_init_attr *init_attr, +struct ib_udata *udata) +{ +struct qib_qp *qp; +int err; +struct qib_swqe *swq =NULL ; +struct qib_ibdev *dev; +struct qib_devdata *dd; +size_t sz; +size_t sg_list_sz; +struct ib_qp *ret; + +if (init_attr->cap.max_send_sge > ib_qib_max_sges || + init_attr->cap.max_send_wr > ib_qib_max_qp_wrs) { + ret =ERR_PTR (-EINVAL ); + goto bail; + } + +/* Check receive queue parameters if no SRQ is specified. */ +if (!init_attr->srq) { +if (init_attr->cap.max_recv_sge > ib_qib_max_sges || + init_attr->cap.max_recv_wr > ib_qib_max_qp_wrs) { + ret =ERR_PTR (-EINVAL ); + goto bail; + } +if (init_attr->cap.max_send_sge + + init_attr->cap.max_send_wr + + init_attr->cap.max_recv_sge + + init_attr->cap.max_recv_wr ==0 ) { + ret =ERR_PTR (-EINVAL ); + goto bail; + } + } + +switch (init_attr->qp_type) { +case IB_QPT_SMI : +case IB_QPT_GSI : +if (init_attr->port_num ==0 || + init_attr->port_num > ibpd->device->phys_port_cnt) { + ret =ERR_PTR (-EINVAL ); + goto bail; + } +case IB_QPT_UC : +case IB_QPT_RC : +case IB_QPT_UD : + sz =sizeof (struct qib_sge ) * + init_attr->cap.max_send_sge + +sizeof (struct qib_swqe ); + swq =vmalloc ((init_attr->cap.max_send_wr +1 ) * sz); +if (swq ==NULL ) { + ret =ERR_PTR (-ENOMEM ); + goto bail; + } + sz =sizeof (*qp); + sg_list_sz =0 ; +if (init_attr->srq) { +struct qib_srq *srq =to_isrq (init_attr->srq); + +if (srq->rq.max_sge >1 ) + sg_list_sz =sizeof (*qp->r_sg_list) * + (srq->rq.max_sge -1 ); + }else if (init_attr->cap.max_recv_sge >1 ) + sg_list_sz =sizeof (*qp->r_sg_list) * + (init_attr->cap.max_recv_sge -1 ); + qp =kzalloc (sz + sg_list_sz,GFP_KERNEL ); +if (!qp) { + ret =ERR_PTR (-ENOMEM ); + goto bail_swq; + } +if (init_attr->srq) + sz =0 ; +else { + qp->r_rq.size = init_attr->cap.max_recv_wr +1 ; + qp->r_rq.max_sge = init_attr->cap.max_recv_sge; + sz = (sizeof (struct ib_sge ) * qp->r_rq.max_sge) + +sizeof (struct qib_rwqe ); + qp->r_rq.wq =vmalloc_user (sizeof (struct qib_rwq ) + + qp->r_rq.size * sz); +if (!qp->r_rq.wq) { + ret =ERR_PTR (-ENOMEM ); + goto bail_qp; + } + } + +/* +* ib_create_qp() will initialize qp->ibqp +* except for qp->ibqp.qp_num. +*/ +spin_lock_init (&qp->r_lock); +spin_lock_init (&qp->s_lock); +spin_lock_init (&qp->r_rq.lock); +atomic_set (&qp->refcount,0 ); +init_waitqueue_head (&qp->wait); +init_waitqueue_head (&qp->wait_dma); +init_timer (&qp->s_timer); + qp->s_timer.data = (unsigned long )qp; +INIT_WORK (&qp->s_work, qib_do_send); +INIT_LIST_HEAD (&qp->iowait); +INIT_LIST_HEAD (&qp->rspwait); + qp->state =IB_QPS_RESET ; + qp->s_wq = swq; + qp->s_size = init_attr->cap.max_send_wr +1 ; + qp->s_max_sge = init_attr->cap.max_send_sge; +if (init_attr->sq_sig_type ==IB_SIGNAL_REQ_WR ) + qp->s_flags =QIB_S_SIGNAL_REQ_WR ; + dev =to_idev (ibpd->device); + dd =dd_from_dev (dev); + err =alloc_qpn (dd, &dev->qpn_table, init_attr->qp_type, + init_attr->port_num); +if (err <0 ) { + ret =ERR_PTR (err); +vfree (qp->r_rq.wq); + goto bail_qp; + } + qp->ibqp.qp_num = err; + qp->port_num = init_attr->port_num; + qp->processor_id =smp_processor_id (); +qib_reset_qp (qp, init_attr->qp_type); +break ; + +default : +/* Don't support raw QPs */ + ret =ERR_PTR (-ENOSYS ); + goto bail; + } + + init_attr->cap.max_inline_data =0 ; + +/* +* Return the address of the RWQ as the offset to mmap. +* See qib_mmap() for details. +*/ +if (udata && udata->outlen >=sizeof (__u64)) { +if (!qp->r_rq.wq) { +__u64 offset =0 ; + + err =ib_copy_to_udata (udata, &offset, +sizeof (offset)); +if (err) { + ret =ERR_PTR (err); + goto bail_ip; + } + }else { +u32 s =sizeof (struct qib_rwq ) + qp->r_rq.size * sz; + + qp->ip =qib_create_mmap_info (dev, s, + ibpd->uobject->context, + qp->r_rq.wq); +if (!qp->ip) { + ret =ERR_PTR (-ENOMEM ); + goto bail_ip; + } + + err =ib_copy_to_udata (udata, &(qp->ip->offset), +sizeof (qp->ip->offset)); +if (err) { + ret =ERR_PTR (err); + goto bail_ip; + } + } + } + +spin_lock (&dev->n_qps_lock); +if (dev->n_qps_allocated == ib_qib_max_qps) { +spin_unlock (&dev->n_qps_lock); + ret =ERR_PTR (-ENOMEM ); + goto bail_ip; + } + + dev->n_qps_allocated++; +spin_unlock (&dev->n_qps_lock); + +if (qp->ip) { +spin_lock_irq (&dev->pending_lock); +list_add (&qp->ip->pending_mmaps, &dev->pending_mmaps); +spin_unlock_irq (&dev->pending_lock); + } + + ret = &qp->ibqp; + goto bail; + +bail_ip: +if (qp->ip) +kref_put (&qp->ip->ref, qib_release_mmap_info); +else +vfree (qp->r_rq.wq); +free_qpn (&dev->qpn_table, qp->ibqp.qp_num); +bail_qp: +kfree (qp); +bail_swq: +vfree (swq); +bail: +return ret; +} + +/** +* qib_destroy_qp - destroy a queue pair +* @ibqp: the queue pair to destroy +* +* Returns 0 on success. +* +* Note that this can be called while the QP is actively sending or +* receiving! +*/ +int qib_destroy_qp (struct ib_qp *ibqp) +{ +struct qib_qp *qp =to_iqp (ibqp); +struct qib_ibdev *dev =to_idev (ibqp->device); + +/* Make sure HW and driver activity is stopped. */ +spin_lock_irq (&qp->s_lock); +if (qp->state !=IB_QPS_RESET ) { + qp->state =IB_QPS_RESET ; +spin_lock (&dev->pending_lock); +if (!list_empty (&qp->iowait)) +list_del_init (&qp->iowait); +spin_unlock (&dev->pending_lock); + qp->s_flags &= ~(QIB_S_TIMER |QIB_S_ANY_WAIT ); +spin_unlock_irq (&qp->s_lock); +cancel_work_sync (&qp->s_work); +del_timer_sync (&qp->s_timer); +wait_event (qp->wait_dma, !atomic_read (&qp->s_dma_busy)); +if (qp->s_tx) { +qib_put_txreq (qp->s_tx); + qp->s_tx =NULL ; + } +remove_qp (dev, qp); +wait_event (qp->wait, !atomic_read (&qp->refcount)); +clear_mr_refs (qp,1 ); + }else +spin_unlock_irq (&qp->s_lock); + +/* all user's cleaned up, mark it available */ +free_qpn (&dev->qpn_table, qp->ibqp.qp_num); +spin_lock (&dev->n_qps_lock); + dev->n_qps_allocated--; +spin_unlock (&dev->n_qps_lock); + +if (qp->ip) +kref_put (&qp->ip->ref, qib_release_mmap_info); +else +vfree (qp->r_rq.wq); +vfree (qp->s_wq); +kfree (qp); +return 0 ; +} + +/** +* qib_init_qpn_table - initialize the QP number table for a device +* @qpt: the QPN table +*/ +void qib_init_qpn_table (struct qib_devdata *dd,struct qib_qpn_table *qpt) +{ +spin_lock_init (&qpt->lock); + qpt->last =1 ;/* start with QPN 2 */ + qpt->nmaps =1 ; + qpt->mask = dd->qpn_mask; +} + +/** +* qib_free_qpn_table - free the QP number table for a device +* @qpt: the QPN table +*/ +void qib_free_qpn_table (struct qib_qpn_table *qpt) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (qpt->map); i++) +if (qpt->map[i].page) +free_page ((unsigned long ) qpt->map[i].page); +} + +/** +* qib_get_credit - flush the send work queue of a QP +* @qp: the qp who's send work queue to flush +* @aeth: the Acknowledge Extended Transport Header +* +* The QP s_lock should be held. +*/ +void qib_get_credit (struct qib_qp *qp,u32 aeth) +{ +u32 credit = (aeth >>QIB_AETH_CREDIT_SHIFT ) &QIB_AETH_CREDIT_MASK ; + +/* +* If the credit is invalid, we can send +* as many packets as we like. Otherwise, we have to +* honor the credit field. +*/ +if (credit ==QIB_AETH_CREDIT_INVAL ) { +if (!(qp->s_flags &QIB_S_UNLIMITED_CREDIT )) { + qp->s_flags |=QIB_S_UNLIMITED_CREDIT ; +if (qp->s_flags &QIB_S_WAIT_SSN_CREDIT ) { + qp->s_flags &= ~QIB_S_WAIT_SSN_CREDIT ; +qib_schedule_send (qp); + } + } + }else if (!(qp->s_flags &QIB_S_UNLIMITED_CREDIT )) { +/* Compute new LSN (i.e., MSN + credit) */ + credit = (aeth + credit_table[credit]) &QIB_MSN_MASK ; +if (qib_cmp24 (credit, qp->s_lsn) >0 ) { + qp->s_lsn = credit; +if (qp->s_flags &QIB_S_WAIT_SSN_CREDIT ) { + qp->s_flags &= ~QIB_S_WAIT_SSN_CREDIT ; +qib_schedule_send (qp); + } + } + } +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 29/52 IB/qib: Add qib_qsfp.c
In reply to a message not in the archivecreates the qib_qsfp.c file.
---
drivers/infiniband/hw/qib/qib_qsfp.c | 564 ++++++++++++++++++++++++++++++++++ 1 files changed, 564 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_qsfp.c
drivers/infiniband/hw/qib/qib_qsfp.c new file +564 -0
@@ -0,0 +1,564 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/delay.h> +#include <linux/pci.h> +#include <linux/vmalloc.h> + +#include "qib.h" +#include "qib_qsfp.h" + +/* +* QSFP support for ib_qib driver, using "Two Wire Serial Interface" driver +* in qib_twsi.c +*/ +#define QSFP_MAX_RETRY 4 + +static int qsfp_read (struct qib_pportdata *ppd,int addr,void *bp,int len) +{ +struct qib_devdata *dd = ppd->dd; +u32 out, mask; +int ret, cnt, pass =0 ; +int stuck =0 ; +u8 *buff = bp; + + ret =mutex_lock_interruptible (&dd->eep_lock); +if (ret) + goto no_unlock; + +if (dd->twsi_eeprom_dev ==QIB_TWSI_NO_DEV ) { + ret = -ENXIO ; + goto bail; + } + +/* +* We presume, if we are called at all, that this board has +* QSFP. This is on the same i2c chain as the legacy parts, +* but only responds if the module is selected via GPIO pins. +* Further, there are very long setup and hold requirements +* on MODSEL. +*/ + mask =QSFP_GPIO_MOD_SEL_N |QSFP_GPIO_MOD_RST_N |QSFP_GPIO_LP_MODE ; + out =QSFP_GPIO_MOD_RST_N |QSFP_GPIO_LP_MODE ; +if (ppd->hw_pidx) { + mask <<=QSFP_GPIO_PORT2_SHIFT ; + out <<=QSFP_GPIO_PORT2_SHIFT ; + } + + dd->f_gpio_mod (dd, out, mask, mask); + +/* +* Module could take up to 2 Msec to respond to MOD_SEL, and there +* is no way to tell if it is ready, so we must wait. +*/ +msleep (2 ); + +/* Make sure TWSI bus is in sane state. */ + ret =qib_twsi_reset (dd); +if (ret) { +qib_dev_porterr (dd, ppd->port, +"QSFP interface Reset for read failed\n" ); + ret = -EIO ; + stuck =1 ; + goto deselect; + } + +/* All QSFP modules are at A0 */ + + cnt =0 ; +while (cnt < len) { +unsigned in_page; +int wlen = len - cnt; + in_page = addr %QSFP_PAGESIZE ; +if ((in_page + wlen) >QSFP_PAGESIZE ) + wlen =QSFP_PAGESIZE - in_page; + ret =qib_twsi_blk_rd (dd,QSFP_DEV , addr, buff + cnt, wlen); +/* Some QSFP's fail first try. Retry as experiment */ +if (ret && cnt ==0 && ++pass <QSFP_MAX_RETRY ) +continue ; +if (ret) { +/* qib_twsi_blk_rd() 1 for error, else 0 */ + ret = -EIO ; + goto deselect; + } + addr += wlen; + cnt += wlen; + } + ret = cnt; + +deselect: +/* +* Module could take up to 10 uSec after transfer before +* ready to respond to MOD_SEL negation, and there is no way +* to tell if it is ready, so we must wait. +*/ +udelay (10 ); +/* set QSFP MODSEL, RST. LP all high */ + dd->f_gpio_mod (dd, mask, mask, mask); + +/* +* Module could take up to 2 Msec to respond to MOD_SEL +* going away, and there is no way to tell if it is ready. +* so we must wait. +*/ +if (stuck) +qib_dev_err (dd,"QSFP interface bus stuck non-idle\n" ); + +if (pass >=QSFP_MAX_RETRY && ret) +qib_dev_porterr (dd, ppd->port,"QSFP failed even retrying\n" ); +else if (pass) +qib_dev_porterr (dd, ppd->port,"QSFP retries: %d\n" , pass); + +msleep (2 ); + +bail: +mutex_unlock (&dd->eep_lock); + +no_unlock: +return ret; +} + +/* +* qsfp_write +* We do not ordinarily write the QSFP, but this is needed to select +* the page on non-flat QSFPs, and possibly later unusual cases +*/ +static int qib_qsfp_write (struct qib_pportdata *ppd,int addr,void *bp, +int len) +{ +struct qib_devdata *dd = ppd->dd; +u32 out, mask; +int ret, cnt; +u8 *buff = bp; + + ret =mutex_lock_interruptible (&dd->eep_lock); +if (ret) + goto no_unlock; + +if (dd->twsi_eeprom_dev ==QIB_TWSI_NO_DEV ) { + ret = -ENXIO ; + goto bail; + } + +/* +* We presume, if we are called at all, that this board has +* QSFP. This is on the same i2c chain as the legacy parts, +* but only responds if the module is selected via GPIO pins. +* Further, there are very long setup and hold requirements +* on MODSEL. +*/ + mask =QSFP_GPIO_MOD_SEL_N |QSFP_GPIO_MOD_RST_N |QSFP_GPIO_LP_MODE ; + out =QSFP_GPIO_MOD_RST_N |QSFP_GPIO_LP_MODE ; +if (ppd->hw_pidx) { + mask <<=QSFP_GPIO_PORT2_SHIFT ; + out <<=QSFP_GPIO_PORT2_SHIFT ; + } + dd->f_gpio_mod (dd, out, mask, mask); + +/* +* Module could take up to 2 Msec to respond to MOD_SEL, +* and there is no way to tell if it is ready, so we must wait. +*/ +msleep (2 ); + +/* Make sure TWSI bus is in sane state. */ + ret =qib_twsi_reset (dd); +if (ret) { +qib_dev_porterr (dd, ppd->port, +"QSFP interface Reset for write failed\n" ); + ret = -EIO ; + goto deselect; + } + +/* All QSFP modules are at A0 */ + + cnt =0 ; +while (cnt < len) { +unsigned in_page; +int wlen = len - cnt; + in_page = addr %QSFP_PAGESIZE ; +if ((in_page + wlen) >QSFP_PAGESIZE ) + wlen =QSFP_PAGESIZE - in_page; + ret =qib_twsi_blk_wr (dd,QSFP_DEV , addr, buff + cnt, wlen); +if (ret) { +/* qib_twsi_blk_wr() 1 for error, else 0 */ + ret = -EIO ; + goto deselect; + } + addr += wlen; + cnt += wlen; + } + ret = cnt; + +deselect: +/* +* Module could take up to 10 uSec after transfer before +* ready to respond to MOD_SEL negation, and there is no way +* to tell if it is ready, so we must wait. +*/ +udelay (10 ); +/* set QSFP MODSEL, RST, LP high */ + dd->f_gpio_mod (dd, mask, mask, mask); +/* +* Module could take up to 2 Msec to respond to MOD_SEL +* going away, and there is no way to tell if it is ready. +* so we must wait. +*/ +msleep (2 ); + +bail: +mutex_unlock (&dd->eep_lock); + +no_unlock: +return ret; +} + +/* +* For validation, we want to check the checksums, even of the +* fields we do not otherwise use. This function reads the bytes from +* <first> to <next-1> and returns the 8lsbs of the sum, or <0 for errors +*/ +static int qsfp_cks (struct qib_pportdata *ppd,int first,int next) +{ +int ret; +u16 cks; +u8 bval; + + cks =0 ; +while (first < next) { + ret =qsfp_read (ppd, first, &bval,1 ); +if (ret <0 ) + goto bail; + cks += bval; + ++first; + } + ret = cks &0xFF ; +bail: +return ret; + +} + +int qib_refresh_qsfp_cache (struct qib_pportdata *ppd,struct qib_qsfp_cache *cp) +{ +int ret; +int idx; +u16 cks; +u32 mask; +u8 peek[4 ]; + +/* ensure sane contents on invalid reads, for cable swaps */ +memset (cp,0 ,sizeof (*cp)); + + mask =QSFP_GPIO_MOD_PRS_N ; +if (ppd->hw_pidx) + mask <<=QSFP_GPIO_PORT2_SHIFT ; + + ret = ppd->dd->f_gpio_mod (ppd->dd,0 ,0 ,0 ); +if (ret & mask) { + ret = -ENODEV ; + goto bail; + } + + ret =qsfp_read (ppd,0 , peek,3 ); +if (ret <0 ) + goto bail; +if ((peek[0 ] &0xFE ) !=0x0C ) +qib_dev_porterr (ppd->dd, ppd->port, +"QSFP byte0 is 0x%02X, S/B 0x0C/D\n" , peek[0 ]); + +if ((peek[2 ] &2 ) ==0 ) { +/* +* If cable is paged, rather than "flat memory", we need to +* set the page to zero, Even if it already appears to be zero. +*/ +u8 poke =0 ; + ret =qib_qsfp_write (ppd,127 , &poke,1 ); +udelay (50 ); +if (ret !=1 ) { +qib_dev_porterr (ppd->dd, ppd->port, +"Failed QSFP Page set\n" ); + goto bail; + } + } + + ret =qsfp_read (ppd,QSFP_MOD_ID_OFFS , &cp->id,1 ); +if (ret <0 ) + goto bail; +if ((cp->id &0xFE ) !=0x0C ) +qib_dev_porterr (ppd->dd, ppd->port, +"QSFP ID byte is 0x%02X, S/B 0x0C/D\n" , cp->id); + cks = cp->id; + + ret =qsfp_read (ppd,QSFP_MOD_PWR_OFFS , &cp->pwr,1 ); +if (ret <0 ) + goto bail; + cks += cp->pwr; + + ret =qsfp_cks (ppd,QSFP_MOD_PWR_OFFS +1 ,QSFP_MOD_LEN_OFFS ); +if (ret <0 ) + goto bail; + cks += ret; + + ret =qsfp_read (ppd,QSFP_MOD_LEN_OFFS , &cp->len,1 ); +if (ret <0 ) + goto bail; + cks += cp->len; + + ret =qsfp_read (ppd,QSFP_MOD_TECH_OFFS , &cp->tech,1 ); +if (ret <0 ) + goto bail; + cks += cp->tech; + + ret =qsfp_read (ppd,QSFP_VEND_OFFS , &cp->vendor,QSFP_VEND_LEN ); +if (ret <0 ) + goto bail; +for (idx =0 ; idx <QSFP_VEND_LEN ; ++idx) + cks += cp->vendor[idx]; + + ret =qsfp_read (ppd,QSFP_IBXCV_OFFS , &cp->xt_xcv,1 ); +if (ret <0 ) + goto bail; + cks += cp->xt_xcv; + + ret =qsfp_read (ppd,QSFP_VOUI_OFFS , &cp->oui,QSFP_VOUI_LEN ); +if (ret <0 ) + goto bail; +for (idx =0 ; idx <QSFP_VOUI_LEN ; ++idx) + cks += cp->oui[idx]; + + ret =qsfp_read (ppd,QSFP_PN_OFFS , &cp->partnum,QSFP_PN_LEN ); +if (ret <0 ) + goto bail; +for (idx =0 ; idx <QSFP_PN_LEN ; ++idx) + cks += cp->partnum[idx]; + + ret =qsfp_read (ppd,QSFP_REV_OFFS , &cp->rev,QSFP_REV_LEN ); +if (ret <0 ) + goto bail; +for (idx =0 ; idx <QSFP_REV_LEN ; ++idx) + cks += cp->rev[idx]; + + ret =qsfp_read (ppd,QSFP_ATTEN_OFFS , &cp->atten,QSFP_ATTEN_LEN ); +if (ret <0 ) + goto bail; +for (idx =0 ; idx <QSFP_ATTEN_LEN ; ++idx) + cks += cp->atten[idx]; + + ret =qsfp_cks (ppd,QSFP_ATTEN_OFFS +QSFP_ATTEN_LEN ,QSFP_CC_OFFS ); +if (ret <0 ) + goto bail; + cks += ret; + + cks &=0xFF ; + ret =qsfp_read (ppd,QSFP_CC_OFFS , &cp->cks1,1 ); +if (ret <0 ) + goto bail; +if (cks != cp->cks1) +qib_dev_porterr (ppd->dd, ppd->port, +"QSFP cks1 is %02X, computed %02X\n" , cp->cks1, + cks); + +/* Second checksum covers 192 to (serial, date, lot) */ + ret =qsfp_cks (ppd,QSFP_CC_OFFS +1 ,QSFP_SN_OFFS ); +if (ret <0 ) + goto bail; + cks = ret; + + ret =qsfp_read (ppd,QSFP_SN_OFFS , &cp->serial,QSFP_SN_LEN ); +if (ret <0 ) + goto bail; +for (idx =0 ; idx <QSFP_SN_LEN ; ++idx) + cks += cp->serial[idx]; + + ret =qsfp_read (ppd,QSFP_DATE_OFFS , &cp->date,QSFP_DATE_LEN ); +if (ret <0 ) + goto bail; +for (idx =0 ; idx <QSFP_DATE_LEN ; ++idx) + cks += cp->date[idx]; + + ret =qsfp_read (ppd,QSFP_LOT_OFFS , &cp->lot,QSFP_LOT_LEN ); +if (ret <0 ) + goto bail; +for (idx =0 ; idx <QSFP_LOT_LEN ; ++idx) + cks += cp->lot[idx]; + + ret =qsfp_cks (ppd,QSFP_LOT_OFFS +QSFP_LOT_LEN ,QSFP_CC_EXT_OFFS ); +if (ret <0 ) + goto bail; + cks += ret; + + ret =qsfp_read (ppd,QSFP_CC_EXT_OFFS , &cp->cks2,1 ); +if (ret <0 ) + goto bail; + cks &=0xFF ; +if (cks != cp->cks2) +qib_dev_porterr (ppd->dd, ppd->port, +"QSFP cks2 is %02X, computed %02X\n" , cp->cks2, + cks); +return 0 ; + +bail: + cp->id =0 ; +return ret; +} + +const char *const qib_qsfp_devtech[16 ] = { +"850nm VCSEL" ,"1310nm VCSEL" ,"1550nm VCSEL" ,"1310nm FP" , +"1310nm DFB" ,"1550nm DFB" ,"1310nm EML" ,"1550nm EML" , +"Cu Misc" ,"1490nm DFB" ,"Cu NoEq" ,"Cu Eq" , +"Undef" ,"Cu Active BothEq" ,"Cu FarEq" ,"Cu NearEq" +}; + +#define QSFP_DUMP_CHUNK 16/* Holds longest string */ +#define QSFP_DEFAULT_HDR_CNT 224 + +static const char *pwr_codes ="1.5W2.0W2.5W3.5W" ; + +/* +* Initialize structures that control access to QSFP. Called once per port +* on cards that support QSFP. +*/ +void qib_qsfp_init (struct qib_qsfp_data *qd, +void (*fevent)(struct work_struct *)) +{ +u32 mask, highs; +int pins; + +struct qib_devdata *dd = qd->ppd->dd; + +/* Initialize work struct for later QSFP events */ +INIT_WORK (&qd->work, fevent); + +/* +* Later, we may want more validation. For now, just set up pins and +* blip reset. If module is present, call qib_refresh_qsfp_cache(), +* to do further init. +*/ + mask =QSFP_GPIO_MOD_SEL_N |QSFP_GPIO_MOD_RST_N |QSFP_GPIO_LP_MODE ; + highs = mask -QSFP_GPIO_MOD_RST_N ; +if (qd->ppd->hw_pidx) { + mask <<=QSFP_GPIO_PORT2_SHIFT ; + highs <<=QSFP_GPIO_PORT2_SHIFT ; + } + dd->f_gpio_mod (dd, highs, mask, mask); +udelay (20 );/* Generous RST dwell */ + + dd->f_gpio_mod (dd, mask, mask, mask); +/* Spec says module can take up to two seconds! */ + mask =QSFP_GPIO_MOD_PRS_N ; +if (qd->ppd->hw_pidx) + mask <<=QSFP_GPIO_PORT2_SHIFT ; + +/* Do not try to wait here. Better to let event handle it */ + pins = dd->f_gpio_mod (dd,0 ,0 ,0 ); +if (pins & mask) + goto bail; +/* We see a module, but it may be unwise to look yet. Just schedule */ + qd->t_insert =get_jiffies_64 (); +schedule_work (&qd->work); +bail: +return ; +} + +void qib_qsfp_deinit (struct qib_qsfp_data *qd) +{ +/* +* There is nothing to do here for now. our +* work is scheduled with schedule_work(), and +* flush_scheduled_work() from remove_one will +* block until all work ssetup with schedule_work() +* completes. +*/ +} + +int qib_qsfp_dump (struct qib_pportdata *ppd,char *buf,int len) +{ +struct qib_qsfp_cache cd; +u8 bin_buff[QSFP_DUMP_CHUNK ]; +char lenstr[6 ]; +int sofar, ret; +int bidx =0 ; + + sofar =0 ; + ret =qib_refresh_qsfp_cache (ppd, &cd); +if (ret <0 ) + goto bail; + + lenstr[0 ] =' ' ; + lenstr[1 ] ='\0' ; +if (QSFP_IS_CU (cd.tech)) +sprintf (lenstr,"%dM " , cd.len); + + sofar +=scnprintf (buf + sofar, len - sofar,"PWR:%.3sW\n" , pwr_codes + + (QSFP_PWR (cd.pwr) *4 )); + + sofar +=scnprintf (buf + sofar, len - sofar,"TECH:%s%s\n" , lenstr, + qib_qsfp_devtech[cd.tech >>4 ]); + + sofar +=scnprintf (buf + sofar, len - sofar,"Vendor:%.*s\n" , +QSFP_VEND_LEN , cd.vendor); + + sofar +=scnprintf (buf + sofar, len - sofar,"OUI:%06X\n" , +QSFP_OUI (cd.oui)); + + sofar +=scnprintf (buf + sofar, len - sofar,"Part#:%.*s\n" , +QSFP_PN_LEN , cd.partnum); + sofar +=scnprintf (buf + sofar, len - sofar,"Rev:%.*s\n" , +QSFP_REV_LEN , cd.rev); +if (QSFP_IS_CU (cd.tech)) + sofar +=scnprintf (buf + sofar, len - sofar,"Atten:%d, %d\n" , +QSFP_ATTEN_SDR (cd.atten), +QSFP_ATTEN_DDR (cd.atten)); + sofar +=scnprintf (buf + sofar, len - sofar,"Serial:%.*s\n" , +QSFP_SN_LEN , cd.serial); + sofar +=scnprintf (buf + sofar, len - sofar,"Date:%.*s\n" , +QSFP_DATE_LEN , cd.date); + sofar +=scnprintf (buf + sofar, len - sofar,"Lot:%.*s\n" , +QSFP_LOT_LEN , cd.date); + +while (bidx <QSFP_DEFAULT_HDR_CNT ) { +int iidx; + ret =qsfp_read (ppd, bidx, bin_buff,QSFP_DUMP_CHUNK ); +if (ret <0 ) + goto bail; +for (iidx =0 ; iidx < ret; ++iidx) { + sofar +=scnprintf (buf + sofar, len-sofar," %02X" , + bin_buff[iidx]); + } + sofar +=scnprintf (buf + sofar, len - sofar,"\n" ); + bidx +=QSFP_DUMP_CHUNK ; + } + ret = sofar; +bail: +return ret; +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 30/52 IB/qib: Add qib_qsfp.h
In reply to a message not in the archivecreates the qib_qsfp.h file.
---
drivers/infiniband/hw/qib/qib_qsfp.h | 184 ++++++++++++++++++++++++++++++++++ 1 files changed, 184 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_qsfp.h
drivers/infiniband/hw/qib/qib_qsfp.h new file +184 -0
@@ -0,0 +1,184 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ +/* QSFP support common definitions, for ib_qib driver */ + +#define QSFP_DEV 0xA0 +#define QSFP_PWR_LAG_MSEC 2000 + +/* +* Below are masks for various QSFP signals, for Port 1. +* Port2 equivalents are shifted by QSFP_GPIO_PORT2_SHIFT. +* _N means asserted low +*/ +#define QSFP_GPIO_MOD_SEL_N (4) +#define QSFP_GPIO_MOD_PRS_N (8) +#define QSFP_GPIO_INT_N (0x10) +#define QSFP_GPIO_MOD_RST_N (0x20) +#define QSFP_GPIO_LP_MODE (0x40) +#define QSFP_GPIO_PORT2_SHIFT 5 + +#define QSFP_PAGESIZE 128 +/* Defined fields that QLogic requires of qualified cables */ +/* Byte 0 is Identifier, not checked */ +/* Byte 1 is reserved "status MSB" */ +/* Byte 2 is "status LSB" We only care that D2 "Flat Mem" is set. */ +/* +* Rest of first 128 not used, although 127 is reserved for page select +* if module is not "Flat memory". +*/ +/* Byte 128 is Identifier: must be 0x0c for QSFP, or 0x0d for QSFP+ */ +#define QSFP_MOD_ID_OFFS 128 +/* +* Byte 129 is "Extended Identifier". We only care about D7,D6: Power class +* 0:1.5W, 1:2.0W, 2:2.5W, 3:3.5W +*/ +#define QSFP_MOD_PWR_OFFS 129 +/* Byte 130 is Connector type. Not QLogic req'd */ +/* Bytes 131..138 are Transceiver types, bit maps for various tech, none IB */ +/* Byte 139 is encoding. code 0x01 is 8b10b. Not QLogic req'd */ +/* byte 140 is nominal bit-rate, in units of 100Mbits/sec Not QLogic req'd */ +/* Byte 141 is Extended Rate Select. Not QLogic req'd */ +/* Bytes 142..145 are lengths for various fiber types. Not QLogic req'd */ +/* Byte 146 is length for Copper. Units of 1 meter */ +#define QSFP_MOD_LEN_OFFS 146 +/* +* Byte 147 is Device technology. D0..3 not Qlogc req'd +* D4..7 select from 15 choices, translated by table: +*/ +#define QSFP_MOD_TECH_OFFS 147 +extern const char *const qib_qsfp_devtech[16 ]; +/* Active Equalization includes fiber, copper full EQ, and copper near Eq */ +#define QSFP_IS_ACTIVE (tech) ((0xA2FF >> ((tech) >> 4)) & 1) +/* Attenuation should be valid for copper other than full/near Eq */ +#define QSFP_HAS_ATTEN (tech) ((0x4D00 >> ((tech) >> 4)) & 1) +/* Length is only valid if technology is "copper" */ +#define QSFP_IS_CU (tech) ((0xED00 >> ((tech) >> 4)) & 1) +#define QSFP_TECH_1490 9 + +#define QSFP_OUI (oui) (((unsigned)oui[0] << 16) | ((unsigned)oui[1] << 8) | \ + oui[2]) +#define QSFP_OUI_AMPHENOL 0x415048 +#define QSFP_OUI_FINISAR 0x009065 +#define QSFP_OUI_GORE 0x002177 + +/* Bytes 148..163 are Vendor Name, Left-justified Blank-filled */ +#define QSFP_VEND_OFFS 148 +#define QSFP_VEND_LEN 16 +/* Byte 164 is IB Extended tranceiver codes Bits D0..3 are SDR,DDR,QDR,EDR */ +#define QSFP_IBXCV_OFFS 164 +/* Bytes 165..167 are Vendor OUI number */ +#define QSFP_VOUI_OFFS 165 +#define QSFP_VOUI_LEN 3 +/* Bytes 168..183 are Vendor Part Number, string */ +#define QSFP_PN_OFFS 168 +#define QSFP_PN_LEN 16 +/* Bytes 184,185 are Vendor Rev. Left Justified, Blank-filled */ +#define QSFP_REV_OFFS 184 +#define QSFP_REV_LEN 2 +/* +* Bytes 186,187 are Wavelength, if Optical. Not Qlogic req'd +* If copper, they are attenuation in dB: +* Byte 186 is at 2.5Gb/sec (SDR), Byte 187 at 5.0Gb/sec (DDR) +*/ +#define QSFP_ATTEN_OFFS 186 +#define QSFP_ATTEN_LEN 2 +/* Bytes 188,189 are Wavelength tolerance, not QLogic req'd */ +/* Byte 190 is Max Case Temp. Not QLogic req'd */ +/* Byte 191 is LSB of sum of bytes 128..190. Not QLogic req'd */ +#define QSFP_CC_OFFS 191 +/* Bytes 192..195 are Options implemented in qsfp. Not Qlogic req'd */ +/* Bytes 196..211 are Serial Number, String */ +#define QSFP_SN_OFFS 196 +#define QSFP_SN_LEN 16 +/* Bytes 212..219 are date-code YYMMDD (MM==1 for Jan) */ +#define QSFP_DATE_OFFS 212 +#define QSFP_DATE_LEN 6 +/* Bytes 218,219 are optional lot-code, string */ +#define QSFP_LOT_OFFS 218 +#define QSFP_LOT_LEN 2 +/* Bytes 220, 221 indicate monitoring options, Not QLogic req'd */ +/* Byte 223 is LSB of sum of bytes 192..222 */ +#define QSFP_CC_EXT_OFFS 223 + +/* +* struct qib_qsfp_data encapsulates state of QSFP device for one port. +* it will be part of port-chip-specific data if a board supports QSFP. +* +* Since multiple board-types use QSFP, and their pport_data structs +* differ (in the chip-specific section), we need a pointer to its head. +* +* Avoiding premature optimization, we will have one work_struct per port, +* and let the (increasingly inaccurately named) eep_lock arbitrate +* access to common resources. +* +*/ + +/* +* Hold the parts of the onboard EEPROM that we care about, so we aren't +* coonstantly bit-boffing +*/ +struct qib_qsfp_cache { +u8 id;/* must be 0x0C or 0x0D; 0 indicates invalid EEPROM read */ +u8 pwr;/* in D6,7 */ +u8 len;/* in meters, Cu only */ +u8 tech; +char vendor[QSFP_VEND_LEN ]; +u8 xt_xcv;/* Ext. tranceiver codes, 4 lsbs are IB speed supported */ +u8 oui[QSFP_VOUI_LEN ]; +u8 partnum[QSFP_PN_LEN ]; +u8 rev[QSFP_REV_LEN ]; +u8 atten[QSFP_ATTEN_LEN ]; +u8 cks1;/* Checksum of bytes 128..190 */ +u8 serial[QSFP_SN_LEN ]; +u8 date[QSFP_DATE_LEN ]; +u8 lot[QSFP_LOT_LEN ]; +u8 cks2;/* Checsum of bytes 192..222 */ +}; + +#define QSFP_PWR (pbyte) (((pbyte) >> 6) & 3) +#define QSFP_ATTEN_SDR (attenarray) (attenarray[0]) +#define QSFP_ATTEN_DDR (attenarray) (attenarray[1]) + +struct qib_qsfp_data { +/* Helps to find our way */ +struct qib_pportdata *ppd; +struct work_struct work; +struct qib_qsfp_cache cache; +u64 t_insert; +}; + +extern int qib_refresh_qsfp_cache (struct qib_pportdata *ppd, +struct qib_qsfp_cache *cp); +extern void qib_qsfp_init (struct qib_qsfp_data *qd, +void (*fevent)(struct work_struct *)); +extern void qib_qsfp_deinit (struct qib_qsfp_data *qd);
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 31/52 IB/qib: Add qib_rc.c
In reply to a message not in the archivecreates the qib_rc.c file.
---
drivers/infiniband/hw/qib/qib_rc.c | 2288 ++++++++++++++++++++++++++++++++++++ 1 files changed, 2288 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_rc.c
drivers/infiniband/hw/qib/qib_rc.c new file +2288 -0
@@ -0,0 +1,2288 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/io.h> + +#include "qib.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 qib_sge_state *ss,struct qib_swqe *wqe, +u32 psn,u32 pmtu) +{ +u32 len; + + len = ((psn - wqe->psn) &QIB_PSN_MASK ) * 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; +qib_skip_sge (ss, len,0 ); +return wqe->length - len; +} + +static void start_timer (struct qib_qp *qp) +{ + qp->s_flags |=QIB_S_TIMER ; + qp->s_timer.function = rc_timeout; +/* 4.096 usec. * (1 << qp->timeout) */ + qp->s_timer.expires = jiffies + +usecs_to_jiffies ((4096UL * (1UL << qp->timeout)) /1000UL ); +add_timer (&qp->s_timer); +} + +/** +* qib_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 qib_make_rc_ack (struct qib_ibdev *dev,struct qib_qp *qp, +struct qib_other_headers *ohdr,u32 pmtu) +{ +struct qib_ack_entry *e; +u32 hwords; +u32 len; +u32 bth0; +u32 bth2; + +/* Don't send an ACK if we aren't supposed to. */ +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK )) + goto bail; + +/* header size in 32-bit words LRH+BTH = (8+12)/4. */ + hwords =5 ; + +switch (qp->s_ack_state) { +case OP (RDMA_READ_RESPONSE_LAST ): +case OP (RDMA_READ_RESPONSE_ONLY ): + e = &qp->s_ack_queue[qp->s_tail_ack_queue]; +if (e->rdma_sge.mr) { +atomic_dec (&e->rdma_sge.mr->refcount); + e->rdma_sge.mr =NULL ; + } +/* FALLTHROUGH */ +case OP (ATOMIC_ACKNOWLEDGE ): +/* +* We can increment the tail pointer now that the last +* response has been sent instead of only being +* constructed. +*/ +if (++qp->s_tail_ack_queue >QIB_MAX_RDMA_ATOMIC ) + qp->s_tail_ack_queue =0 ; +/* FALLTHROUGH */ +case OP (SEND_ONLY ): +case OP (ACKNOWLEDGE ): +/* Check for no next entry in the queue. */ +if (qp->r_head_ack_queue == qp->s_tail_ack_queue) { +if (qp->s_flags &QIB_S_ACK_PENDING ) + goto normal; + goto bail; + } + + e = &qp->s_ack_queue[qp->s_tail_ack_queue]; +if (e->opcode ==OP (RDMA_READ_REQUEST )) { +/* +* If a RDMA read response is being resent and +* we haven't seen the duplicate request yet, +* then stop sending the remaining responses the +* responder has seen until the requester resends it. +*/ + len = e->rdma_sge.sge_length; +if (len && !e->rdma_sge.mr) { + qp->s_tail_ack_queue = qp->r_head_ack_queue; + goto bail; + } +/* Copy SGE state in case we need to resend */ + qp->s_rdma_mr = e->rdma_sge.mr; +if (qp->s_rdma_mr) +atomic_inc (&qp->s_rdma_mr->refcount); + qp->s_ack_rdma_sge.sge = e->rdma_sge; + qp->s_ack_rdma_sge.num_sge =1 ; + qp->s_cur_sge = &qp->s_ack_rdma_sge; +if (len > pmtu) { + len = pmtu; + qp->s_ack_state =OP (RDMA_READ_RESPONSE_FIRST ); + }else { + qp->s_ack_state =OP (RDMA_READ_RESPONSE_ONLY ); + e->sent =1 ; + } + ohdr->u.aeth =qib_compute_aeth (qp); + hwords++; + qp->s_ack_rdma_psn = e->psn; + bth2 = qp->s_ack_rdma_psn++ &QIB_PSN_MASK ; + }else { +/* COMPARE_SWAP or FETCH_ADD */ + qp->s_cur_sge =NULL ; + len =0 ; + qp->s_ack_state =OP (ATOMIC_ACKNOWLEDGE ); + ohdr->u.at.aeth =qib_compute_aeth (qp); + ohdr->u.at.atomic_ack_eth[0 ] = +cpu_to_be32 (e->atomic_data >>32 ); + ohdr->u.at.atomic_ack_eth[1 ] = +cpu_to_be32 (e->atomic_data); + hwords +=sizeof (ohdr->u.at) /sizeof (u32); + bth2 = e->psn &QIB_PSN_MASK ; + e->sent =1 ; + } + bth0 = qp->s_ack_state <<24 ; +break ; + +case OP (RDMA_READ_RESPONSE_FIRST ): + qp->s_ack_state =OP (RDMA_READ_RESPONSE_MIDDLE ); +/* FALLTHROUGH */ +case OP (RDMA_READ_RESPONSE_MIDDLE ): + qp->s_cur_sge = &qp->s_ack_rdma_sge; + qp->s_rdma_mr = qp->s_ack_rdma_sge.sge.mr; +if (qp->s_rdma_mr) +atomic_inc (&qp->s_rdma_mr->refcount); + len = qp->s_ack_rdma_sge.sge.sge_length; +if (len > pmtu) + len = pmtu; +else { + ohdr->u.aeth =qib_compute_aeth (qp); + hwords++; + qp->s_ack_state =OP (RDMA_READ_RESPONSE_LAST ); + e = &qp->s_ack_queue[qp->s_tail_ack_queue]; + e->sent =1 ; + } + bth0 = qp->s_ack_state <<24 ; + bth2 = qp->s_ack_rdma_psn++ &QIB_PSN_MASK ; +break ; + +default : +normal: +/* +* Send a regular ACK. +* Set the s_ack_state so we wait until after sending +* the ACK before setting s_ack_state to ACKNOWLEDGE +* (see above). +*/ + qp->s_ack_state =OP (SEND_ONLY ); + qp->s_flags &= ~QIB_S_ACK_PENDING ; + qp->s_cur_sge =NULL ; +if (qp->s_nak_state) + ohdr->u.aeth = +cpu_to_be32 ((qp->r_msn &QIB_MSN_MASK ) | + (qp->s_nak_state << +QIB_AETH_CREDIT_SHIFT )); +else + ohdr->u.aeth =qib_compute_aeth (qp); + hwords++; + len =0 ; + bth0 =OP (ACKNOWLEDGE ) <<24 ; + bth2 = qp->s_ack_psn &QIB_PSN_MASK ; + } + qp->s_rdma_ack_cnt++; + qp->s_hdrwords = hwords; + qp->s_cur_size = len; +qib_make_ruc_header (qp, ohdr, bth0, bth2); +return 1 ; + +bail: + qp->s_ack_state =OP (ACKNOWLEDGE ); + qp->s_flags &= ~(QIB_S_RESP_PENDING |QIB_S_ACK_PENDING ); +return 0 ; +} + +/** +* qib_make_rc_req - construct a request packet (SEND, RDMA r/w, ATOMIC) +* @qp: a pointer to the QP +* +* Return 1 if constructed; otherwise, return 0. +*/ +int qib_make_rc_req (struct qib_qp *qp) +{ +struct qib_ibdev *dev =to_idev (qp->ibqp.device); +struct qib_other_headers *ohdr; +struct qib_sge_state *ss; +struct qib_swqe *wqe; +u32 hwords; +u32 len; +u32 bth0; +u32 bth2; +u32 pmtu =ib_mtu_enum_to_int (qp->path_mtu); +char newreq; +unsigned long flags; +int ret =0 ; +int delta; + + ohdr = &qp->s_hdr.u.oth; +if (qp->remote_ah_attr.ah_flags &IB_AH_GRH ) + ohdr = &qp->s_hdr.u.l.oth; + +/* +* The lock is needed to synchronize between the sending tasklet, +* the receive interrupt handler, and timeout resends. +*/ +spin_lock_irqsave (&qp->s_lock, flags); + +/* Sending responses has higher priority over sending requests. */ +if ((qp->s_flags &QIB_S_RESP_PENDING ) && +qib_make_rc_ack (dev, qp, ohdr, pmtu)) + goto done; + +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_SEND_OK )) { +if (!(ib_qib_state_ops[qp->state] &QIB_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_dma_busy)) { + qp->s_flags |=QIB_S_WAIT_DMA ; + goto bail; + } + wqe =get_swqe_ptr (qp, qp->s_last); +while (qp->s_last != qp->s_acked) { +qib_send_complete (qp, wqe,IB_WC_SUCCESS ); +if (++qp->s_last >= qp->s_size) + qp->s_last =0 ; + wqe =get_swqe_ptr (qp, qp->s_last); + } +qib_send_complete (qp, wqe,IB_WC_WR_FLUSH_ERR ); + goto done; + } + +if (qp->s_flags & (QIB_S_WAIT_RNR |QIB_S_WAIT_ACK )) + goto bail; + +if (qib_cmp24 (qp->s_psn, qp->s_sending_hpsn) <=0 ) { +if (qib_cmp24 (qp->s_sending_psn, qp->s_sending_hpsn) <=0 ) { + qp->s_flags |=QIB_S_WAIT_PSN ; + goto bail; + } + qp->s_sending_psn = qp->s_psn; + qp->s_sending_hpsn = qp->s_psn -1 ; + } + +/* header size in 32-bit words LRH+BTH = (8+12)/4. */ + hwords =5 ; + bth0 =0 ; + +/* Send a request. */ + wqe =get_swqe_ptr (qp, qp->s_cur); +switch (qp->s_state) { +default : +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_NEXT_SEND_OK )) + goto bail; +/* +* Resend an old request or start a new one. +* +* We keep track of the current SWQE so that +* we don't reset the "furthest progress" state +* if we need to back up. +*/ + newreq =0 ; +if (qp->s_cur == qp->s_tail) { +/* Check if send work queue is empty. */ +if (qp->s_tail == qp->s_head) + goto bail; +/* +* If a fence is requested, wait for previous +* RDMA read and atomic operations to finish. +*/ +if ((wqe->wr.send_flags &IB_SEND_FENCE ) && + qp->s_num_rd_atomic) { + qp->s_flags |=QIB_S_WAIT_FENCE ; + goto bail; + } + wqe->psn = qp->s_next_psn; + newreq =1 ; + } +/* +* Note that we have to be careful not to modify the +* original work request since we may need to resend +* it. +*/ + len = wqe->length; + ss = &qp->s_sge; + bth2 = qp->s_psn &QIB_PSN_MASK ; +switch (wqe->wr.opcode) { +case IB_WR_SEND : +case IB_WR_SEND_WITH_IMM : +/* If no credit, return. */ +if (!(qp->s_flags &QIB_S_UNLIMITED_CREDIT ) && +qib_cmp24 (wqe->ssn, qp->s_lsn +1 ) >0 ) { + qp->s_flags |=QIB_S_WAIT_SSN_CREDIT ; + goto bail; + } + wqe->lpsn = wqe->psn; +if (len > pmtu) { + wqe->lpsn += (len -1 ) / pmtu; + qp->s_state =OP (SEND_FIRST ); + len = pmtu; +break ; + } +if (wqe->wr.opcode ==IB_WR_SEND ) + qp->s_state =OP (SEND_ONLY ); +else { + qp->s_state =OP (SEND_ONLY_WITH_IMMEDIATE ); +/* Immediate data comes after the BTH */ + ohdr->u.imm_data = wqe->wr.ex.imm_data; + hwords +=1 ; + } +if (wqe->wr.send_flags &IB_SEND_SOLICITED ) + bth0 |=IB_BTH_SOLICITED ; + bth2 |=IB_BTH_REQ_ACK ; +if (++qp->s_cur == qp->s_size) + qp->s_cur =0 ; +break ; + +case IB_WR_RDMA_WRITE : +if (newreq && !(qp->s_flags &QIB_S_UNLIMITED_CREDIT )) + qp->s_lsn++; +/* FALLTHROUGH */ +case IB_WR_RDMA_WRITE_WITH_IMM : +/* If no credit, return. */ +if (!(qp->s_flags &QIB_S_UNLIMITED_CREDIT ) && +qib_cmp24 (wqe->ssn, qp->s_lsn +1 ) >0 ) { + qp->s_flags |=QIB_S_WAIT_SSN_CREDIT ; + goto bail; + } + ohdr->u.rc.reth.vaddr = +cpu_to_be64 (wqe->wr.wr.rdma.remote_addr); + ohdr->u.rc.reth.rkey = +cpu_to_be32 (wqe->wr.wr.rdma.rkey); + ohdr->u.rc.reth.length =cpu_to_be32 (len); + hwords +=sizeof (struct ib_reth ) /sizeof (u32); + wqe->lpsn = wqe->psn; +if (len > pmtu) { + wqe->lpsn += (len -1 ) / pmtu; + qp->s_state =OP (RDMA_WRITE_FIRST ); + len = pmtu; +break ; + } +if (wqe->wr.opcode ==IB_WR_RDMA_WRITE ) + qp->s_state =OP (RDMA_WRITE_ONLY ); +else { + qp->s_state = +OP (RDMA_WRITE_ONLY_WITH_IMMEDIATE ); +/* Immediate data comes after RETH */ + ohdr->u.rc.imm_data = wqe->wr.ex.imm_data; + hwords +=1 ; +if (wqe->wr.send_flags &IB_SEND_SOLICITED ) + bth0 |=IB_BTH_SOLICITED ; + } + bth2 |=IB_BTH_REQ_ACK ; +if (++qp->s_cur == qp->s_size) + qp->s_cur =0 ; +break ; + +case IB_WR_RDMA_READ : +/* +* Don't allow more operations to be started +* than the QP limits allow. +*/ +if (newreq) { +if (qp->s_num_rd_atomic >= + qp->s_max_rd_atomic) { + qp->s_flags |=QIB_S_WAIT_RDMAR ; + goto bail; + } + qp->s_num_rd_atomic++; +if (!(qp->s_flags &QIB_S_UNLIMITED_CREDIT )) + qp->s_lsn++; +/* +* Adjust s_next_psn to count the +* expected number of responses. +*/ +if (len > pmtu) + qp->s_next_psn += (len -1 ) / pmtu; + wqe->lpsn = qp->s_next_psn++; + } + ohdr->u.rc.reth.vaddr = +cpu_to_be64 (wqe->wr.wr.rdma.remote_addr); + ohdr->u.rc.reth.rkey = +cpu_to_be32 (wqe->wr.wr.rdma.rkey); + ohdr->u.rc.reth.length =cpu_to_be32 (len); + qp->s_state =OP (RDMA_READ_REQUEST ); + hwords +=sizeof (ohdr->u.rc.reth) /sizeof (u32); + ss =NULL ; + len =0 ; + bth2 |=IB_BTH_REQ_ACK ; +if (++qp->s_cur == qp->s_size) + qp->s_cur =0 ; +break ; + +case IB_WR_ATOMIC_CMP_AND_SWP : +case IB_WR_ATOMIC_FETCH_AND_ADD : +/* +* Don't allow more operations to be started +* than the QP limits allow. +*/ +if (newreq) { +if (qp->s_num_rd_atomic >= + qp->s_max_rd_atomic) { + qp->s_flags |=QIB_S_WAIT_RDMAR ; + goto bail; + } + qp->s_num_rd_atomic++; +if (!(qp->s_flags &QIB_S_UNLIMITED_CREDIT )) + qp->s_lsn++; + wqe->lpsn = wqe->psn; + } +if (wqe->wr.opcode ==IB_WR_ATOMIC_CMP_AND_SWP ) { + qp->s_state =OP (COMPARE_SWAP ); + ohdr->u.atomic_eth.swap_data =cpu_to_be64 ( + wqe->wr.wr.atomic.swap); + ohdr->u.atomic_eth.compare_data =cpu_to_be64 ( + wqe->wr.wr.atomic.compare_add); + }else { + qp->s_state =OP (FETCH_ADD ); + ohdr->u.atomic_eth.swap_data =cpu_to_be64 ( + wqe->wr.wr.atomic.compare_add); + ohdr->u.atomic_eth.compare_data =0 ; + } + ohdr->u.atomic_eth.vaddr[0 ] =cpu_to_be32 ( + wqe->wr.wr.atomic.remote_addr >>32 ); + ohdr->u.atomic_eth.vaddr[1 ] =cpu_to_be32 ( + wqe->wr.wr.atomic.remote_addr); + ohdr->u.atomic_eth.rkey =cpu_to_be32 ( + wqe->wr.wr.atomic.rkey); + hwords +=sizeof (struct ib_atomic_eth ) /sizeof (u32); + ss =NULL ; + len =0 ; + bth2 |=IB_BTH_REQ_ACK ; +if (++qp->s_cur == qp->s_size) + qp->s_cur =0 ; +break ; + +default : + goto bail; + } + qp->s_sge.sge = wqe->sg_list[0 ]; + qp->s_sge.sg_list = wqe->sg_list +1 ; + qp->s_sge.num_sge = wqe->wr.num_sge; + qp->s_sge.total_len = wqe->length; + qp->s_len = wqe->length; +if (newreq) { + qp->s_tail++; +if (qp->s_tail >= qp->s_size) + qp->s_tail =0 ; + } +if (wqe->wr.opcode ==IB_WR_RDMA_READ ) + qp->s_psn = wqe->lpsn +1 ; +else { + qp->s_psn++; +if (qib_cmp24 (qp->s_psn, qp->s_next_psn) >0 ) + qp->s_next_psn = qp->s_psn; + } +break ; + +case OP (RDMA_READ_RESPONSE_FIRST ): +/* +* qp->s_state is normally set to the opcode of the +* last packet constructed for new requests and therefore +* is never set to RDMA read response. +* RDMA_READ_RESPONSE_FIRST is used by the ACK processing +* thread to indicate a SEND needs to be restarted from an +* earlier PSN without interferring with the sending thread. +* See qib_restart_rc(). +*/ + qp->s_len =restart_sge (&qp->s_sge, wqe, qp->s_psn, pmtu); +/* FALLTHROUGH */ +case OP (SEND_FIRST ): + qp->s_state =OP (SEND_MIDDLE ); +/* FALLTHROUGH */ +case OP (SEND_MIDDLE ): + bth2 = qp->s_psn++ &QIB_PSN_MASK ; +if (qib_cmp24 (qp->s_psn, qp->s_next_psn) >0 ) + qp->s_next_psn = qp->s_psn; + ss = &qp->s_sge; + len = qp->s_len; +if (len > pmtu) { + len = pmtu; +break ; + } +if (wqe->wr.opcode ==IB_WR_SEND ) + qp->s_state =OP (SEND_LAST ); +else { + qp->s_state =OP (SEND_LAST_WITH_IMMEDIATE ); +/* Immediate data comes after the BTH */ + ohdr->u.imm_data = wqe->wr.ex.imm_data; + hwords +=1 ; + } +if (wqe->wr.send_flags &IB_SEND_SOLICITED ) + bth0 |=IB_BTH_SOLICITED ; + bth2 |=IB_BTH_REQ_ACK ; + qp->s_cur++; +if (qp->s_cur >= qp->s_size) + qp->s_cur =0 ; +break ; + +case OP (RDMA_READ_RESPONSE_LAST ): +/* +* qp->s_state is normally set to the opcode of the +* last packet constructed for new requests and therefore +* is never set to RDMA read response. +* RDMA_READ_RESPONSE_LAST is used by the ACK processing +* thread to indicate a RDMA write needs to be restarted from +* an earlier PSN without interferring with the sending thread. +* See qib_restart_rc(). +*/ + qp->s_len =restart_sge (&qp->s_sge, wqe, qp->s_psn, pmtu); +/* FALLTHROUGH */ +case OP (RDMA_WRITE_FIRST ): + qp->s_state =OP (RDMA_WRITE_MIDDLE ); +/* FALLTHROUGH */ +case OP (RDMA_WRITE_MIDDLE ): + bth2 = qp->s_psn++ &QIB_PSN_MASK ; +if (qib_cmp24 (qp->s_psn, qp->s_next_psn) >0 ) + qp->s_next_psn = qp->s_psn; + ss = &qp->s_sge; + len = qp->s_len; +if (len > pmtu) { + len = pmtu; +break ; + } +if (wqe->wr.opcode ==IB_WR_RDMA_WRITE ) + qp->s_state =OP (RDMA_WRITE_LAST ); +else { + qp->s_state =OP (RDMA_WRITE_LAST_WITH_IMMEDIATE ); +/* Immediate data comes after the BTH */ + ohdr->u.imm_data = wqe->wr.ex.imm_data; + hwords +=1 ; +if (wqe->wr.send_flags &IB_SEND_SOLICITED ) + bth0 |=IB_BTH_SOLICITED ; + } + bth2 |=IB_BTH_REQ_ACK ; + qp->s_cur++; +if (qp->s_cur >= qp->s_size) + qp->s_cur =0 ; +break ; + +case OP (RDMA_READ_RESPONSE_MIDDLE ): +/* +* qp->s_state is normally set to the opcode of the +* last packet constructed for new requests and therefore +* is never set to RDMA read response. +* RDMA_READ_RESPONSE_MIDDLE is used by the ACK processing +* thread to indicate a RDMA read needs to be restarted from +* an earlier PSN without interferring with the sending thread. +* See qib_restart_rc(). +*/ + len = ((qp->s_psn - wqe->psn) &QIB_PSN_MASK ) * pmtu; + ohdr->u.rc.reth.vaddr = +cpu_to_be64 (wqe->wr.wr.rdma.remote_addr + len); + ohdr->u.rc.reth.rkey = +cpu_to_be32 (wqe->wr.wr.rdma.rkey); + ohdr->u.rc.reth.length =cpu_to_be32 (wqe->length - len); + qp->s_state =OP (RDMA_READ_REQUEST ); + hwords +=sizeof (ohdr->u.rc.reth) /sizeof (u32); + bth2 = (qp->s_psn &QIB_PSN_MASK ) |IB_BTH_REQ_ACK ; + qp->s_psn = wqe->lpsn +1 ; + ss =NULL ; + len =0 ; + qp->s_cur++; +if (qp->s_cur == qp->s_size) + qp->s_cur =0 ; +break ; + } + qp->s_sending_hpsn = bth2; + delta = (((int ) bth2 - (int ) wqe->psn) <<8 ) >>8 ; +if (delta && delta %QIB_PSN_CREDIT ==0 ) + bth2 |=IB_BTH_REQ_ACK ; +if (qp->s_flags &QIB_S_SEND_ONE ) { + qp->s_flags &= ~QIB_S_SEND_ONE ; + qp->s_flags |=QIB_S_WAIT_ACK ; + bth2 |=IB_BTH_REQ_ACK ; + } + qp->s_len -= len; + qp->s_hdrwords = hwords; + qp->s_cur_sge = ss; + qp->s_cur_size = len; +qib_make_ruc_header (qp, ohdr, bth0 | (qp->s_state <<24 ), bth2); +done: + ret =1 ; + goto unlock; + +bail: + qp->s_flags &= ~QIB_S_BUSY ; +unlock: +spin_unlock_irqrestore (&qp->s_lock, flags); +return ret; +} + +/** +* qib_send_rc_ack - Construct an ACK packet and send it +* @qp: a pointer to the QP +* +* This is called from qib_rc_rcv() and qib_kreceive(). +* Note that RDMA reads and atomics are handled in the +* send side QP state and tasklet. +*/ +void qib_send_rc_ack (struct qib_qp *qp) +{ +struct qib_devdata *dd =dd_from_ibdev (qp->ibqp.device); +struct qib_ibport *ibp =to_iport (qp->ibqp.device, qp->port_num); +struct qib_pportdata *ppd =ppd_from_ibp (ibp); +u64 pbc; +u16 lrh0; +u32 bth0; +u32 hwords; +u32 pbufn; +u32 __iomem *piobuf; +struct qib_ib_header hdr; +struct qib_other_headers *ohdr; +u32 control; +unsigned long flags; + +spin_lock_irqsave (&qp->s_lock, flags); + +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK )) + goto unlock; + +/* Don't send ACK or NAK if a RDMA read or atomic is pending. */ +if ((qp->s_flags &QIB_S_RESP_PENDING ) || qp->s_rdma_ack_cnt) + goto queue_ack; + +/* Construct the header with s_lock held so APM doesn't change it. */ + ohdr = &hdr.u.oth; + lrh0 =QIB_LRH_BTH ; +/* header size in 32-bit words LRH+BTH+AETH = (8+12+4)/4. */ + hwords =6 ; +if (unlikely (qp->remote_ah_attr.ah_flags &IB_AH_GRH )) { + hwords +=qib_make_grh (ibp, &hdr.u.l.grh, + &qp->remote_ah_attr.grh, hwords,0 ); + ohdr = &hdr.u.l.oth; + lrh0 =QIB_LRH_GRH ; + } +/* read pkey_index w/o lock (its atomic) */ + bth0 =qib_get_pkey (ibp, qp->s_pkey_index) | (OP (ACKNOWLEDGE ) <<24 ); +if (qp->s_mig_state ==IB_MIG_MIGRATED ) + bth0 |=IB_BTH_MIG_REQ ; +if (qp->r_nak_state) + ohdr->u.aeth =cpu_to_be32 ((qp->r_msn &QIB_MSN_MASK ) | + (qp->r_nak_state << +QIB_AETH_CREDIT_SHIFT )); +else + ohdr->u.aeth =qib_compute_aeth (qp); + lrh0 |= ibp->sl_to_vl[qp->remote_ah_attr.sl] <<12 | + qp->remote_ah_attr.sl <<4 ; + hdr.lrh[0 ] =cpu_to_be16 (lrh0); + hdr.lrh[1 ] =cpu_to_be16 (qp->remote_ah_attr.dlid); + hdr.lrh[2 ] =cpu_to_be16 (hwords +SIZE_OF_CRC ); + hdr.lrh[3 ] =cpu_to_be16 (ppd->lid | qp->remote_ah_attr.src_path_bits); + ohdr->bth[0 ] =cpu_to_be32 (bth0); + ohdr->bth[1 ] =cpu_to_be32 (qp->remote_qpn); + ohdr->bth[2 ] =cpu_to_be32 (qp->r_ack_psn &QIB_PSN_MASK ); + +spin_unlock_irqrestore (&qp->s_lock, flags); + +/* Don't try to send ACKs if the link isn't ACTIVE */ +if (!(ppd->lflags &QIBL_LINKACTIVE )) + goto done; + + control = dd->f_setpbc_control (ppd, hwords +SIZE_OF_CRC , + qp->s_srate, lrh0 >>12 ); +/* length is + 1 for the control dword */ + pbc = ((u64 ) control <<32 ) | (hwords +1 ); + + piobuf = dd->f_getsendbuf (ppd, pbc, &pbufn); +if (!piobuf) { +/* +* We are out of PIO buffers at the moment. +* Pass responsibility for sending the ACK to the +* send tasklet so that when a PIO buffer becomes +* available, the ACK is sent ahead of other outgoing +* packets. +*/ +spin_lock_irqsave (&qp->s_lock, flags); + goto queue_ack; + } + +/* +* Write the pbc. +* We have to flush after the PBC for correctness +* on some cpus or WC buffer can be written out of order. +*/ +writeq (pbc, piobuf); + +if (dd->flags &QIB_PIO_FLUSH_WC ) { +u32 *hdrp = (u32 *) &hdr; + +qib_flush_wc (); +qib_pio_copy (piobuf +2 , hdrp, hwords -1 ); +qib_flush_wc (); +__raw_writel (hdrp[hwords -1 ], piobuf + hwords +1 ); + }else +qib_pio_copy (piobuf +2 , (u32 *) &hdr, hwords); + +if (dd->flags &QIB_USE_SPCL_TRIG ) { +u32 spcl_off = (pbufn >= dd->piobcnt2k) ?2047 :1023 ; + +qib_flush_wc (); +__raw_writel (0xaebecede , piobuf + spcl_off); + } + +qib_flush_wc (); +qib_sendbuf_done (dd, pbufn); + + ibp->n_unicast_xmit++; + goto done; + +queue_ack: +if (ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK ) { + ibp->n_rc_qacks++; + qp->s_flags |=QIB_S_ACK_PENDING |QIB_S_RESP_PENDING ; + qp->s_nak_state = qp->r_nak_state; + qp->s_ack_psn = qp->r_ack_psn; + +/* Schedule the send tasklet. */ +qib_schedule_send (qp); + } +unlock: +spin_unlock_irqrestore (&qp->s_lock, flags); +done: +return ; +} + +/** +* reset_psn - reset the QP state to send starting from PSN +* @qp: the QP +* @psn: the packet sequence number to restart at +* +* This is called from qib_rc_rcv() to process an incoming RC ACK +* for the given QP. +* Called at interrupt level with the QP s_lock held. +*/ +static void reset_psn (struct qib_qp *qp,u32 psn) +{ +u32 n = qp->s_acked; +struct qib_swqe *wqe =get_swqe_ptr (qp, n); +u32 opcode; + + qp->s_cur = n; + +/* +* If we are starting the request from the beginning, +* let the normal send code handle initialization. +*/ +if (qib_cmp24 (psn, wqe->psn) <=0 ) { + qp->s_state =OP (SEND_LAST ); + goto done; + } + +/* Find the work request opcode corresponding to the given PSN. */ + opcode = wqe->wr.opcode; +for (;;) { +int diff; + +if (++n == qp->s_size) + n =0 ; +if (n == qp->s_tail) +break ; + wqe =get_swqe_ptr (qp, n); + diff =qib_cmp24 (psn, wqe->psn); +if (diff <0 ) +break ; + qp->s_cur = n; +/* +* If we are starting the request from the beginning, +* let the normal send code handle initialization. +*/ +if (diff ==0 ) { + qp->s_state =OP (SEND_LAST ); + goto done; + } + opcode = wqe->wr.opcode; + } + +/* +* Set the state to restart in the middle of a request. +* Don't change the s_sge, s_cur_sge, or s_cur_size. +* See qib_make_rc_req(). +*/ +switch (opcode) { +case IB_WR_SEND : +case IB_WR_SEND_WITH_IMM : + qp->s_state =OP (RDMA_READ_RESPONSE_FIRST ); +break ; + +case IB_WR_RDMA_WRITE : +case IB_WR_RDMA_WRITE_WITH_IMM : + qp->s_state =OP (RDMA_READ_RESPONSE_LAST ); +break ; + +case IB_WR_RDMA_READ : + qp->s_state =OP (RDMA_READ_RESPONSE_MIDDLE ); +break ; + +default : +/* +* This case shouldn't happen since its only +* one PSN per req. +*/ + qp->s_state =OP (SEND_LAST ); + } +done: + qp->s_psn = psn; +/* +* Set QIB_S_WAIT_PSN as qib_rc_complete() may start the timer +* asynchronously before the send tasklet can get scheduled. +* Doing it in qib_make_rc_req() is too late. +*/ +if ((qib_cmp24 (qp->s_psn, qp->s_sending_hpsn) <=0 ) && + (qib_cmp24 (qp->s_sending_psn, qp->s_sending_hpsn) <=0 )) + qp->s_flags |=QIB_S_WAIT_PSN ; +} + +/* +* Back up requester to resend the last un-ACKed request. +* The QP s_lock should be held and interrupts disabled. +*/ +static void qib_restart_rc (struct qib_qp *qp,u32 psn,int wait) +{ +struct qib_swqe *wqe =get_swqe_ptr (qp, qp->s_acked); +struct qib_ibport *ibp; + +if (qp->s_retry ==0 ) { +if (qp->s_mig_state ==IB_MIG_ARMED ) { +qib_migrate_qp (qp); + qp->s_retry = qp->s_retry_cnt; + }else if (qp->s_last == qp->s_acked) { +qib_send_complete (qp, wqe,IB_WC_RETRY_EXC_ERR ); +qib_error_qp (qp,IB_WC_WR_FLUSH_ERR ); +return ; + }else /* XXX need to handle delayed completion */ +return ; + }else + qp->s_retry--; + + ibp =to_iport (qp->ibqp.device, qp->port_num); +if (wqe->wr.opcode ==IB_WR_RDMA_READ ) + ibp->n_rc_resends++; +else + ibp->n_rc_resends += (qp->s_psn - psn) &QIB_PSN_MASK ; + + qp->s_flags &= ~(QIB_S_WAIT_FENCE |QIB_S_WAIT_RDMAR | +QIB_S_WAIT_SSN_CREDIT |QIB_S_WAIT_PSN | +QIB_S_WAIT_ACK ); +if (wait) + qp->s_flags |=QIB_S_SEND_ONE ; +reset_psn (qp, psn); +} + +/* +* This is called from s_timer for missing responses. +*/ +static void rc_timeout (unsigned long arg) +{ +struct qib_qp *qp = (struct qib_qp *)arg; +struct qib_ibport *ibp; +unsigned long flags; + +spin_lock_irqsave (&qp->s_lock, flags); +if (qp->s_flags &QIB_S_TIMER ) { + ibp =to_iport (qp->ibqp.device, qp->port_num); + ibp->n_rc_timeouts++; + qp->s_flags &= ~QIB_S_TIMER ; +del_timer (&qp->s_timer); +qib_restart_rc (qp, qp->s_last_psn +1 ,1 ); +qib_schedule_send (qp); + } +spin_unlock_irqrestore (&qp->s_lock, flags); +} + +/* +* This is called from s_timer for RNR timeouts. +*/ +void qib_rc_rnr_retry (unsigned long arg) +{ +struct qib_qp *qp = (struct qib_qp *)arg; +unsigned long flags; + +spin_lock_irqsave (&qp->s_lock, flags); +if (qp->s_flags &QIB_S_WAIT_RNR ) { + qp->s_flags &= ~QIB_S_WAIT_RNR ; +del_timer (&qp->s_timer); +qib_schedule_send (qp); + } +spin_unlock_irqrestore (&qp->s_lock, flags); +} + +/* +* Set qp->s_sending_psn to the next PSN after the given one. +* This would be psn+1 except when RDMA reads are present. +*/ +static void reset_sending_psn (struct qib_qp *qp,u32 psn) +{ +struct qib_swqe *wqe; +u32 n = qp->s_last; + +/* Find the work request corresponding to the given PSN. */ +for (;;) { + wqe =get_swqe_ptr (qp, n); +if (qib_cmp24 (psn, wqe->lpsn) <=0 ) { +if (wqe->wr.opcode ==IB_WR_RDMA_READ ) + qp->s_sending_psn = wqe->lpsn +1 ; +else + qp->s_sending_psn = psn +1 ; +break ; + } +if (++n == qp->s_size) + n =0 ; +if (n == qp->s_tail) +break ; + } +} + +/* +* This should be called with the QP s_lock held and interrupts disabled. +*/ +void qib_rc_send_complete (struct qib_qp *qp,struct qib_ib_header *hdr) +{ +struct qib_other_headers *ohdr; +struct qib_swqe *wqe; +struct ib_wc wc; +unsigned i; +u32 opcode; +u32 psn; + +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_OR_FLUSH_SEND )) +return ; + +/* Find out where the BTH is */ +if ((be16_to_cpu (hdr->lrh[0 ]) &3 ) ==QIB_LRH_BTH ) + ohdr = &hdr->u.oth; +else + ohdr = &hdr->u.l.oth; + + opcode =be32_to_cpu (ohdr->bth[0 ]) >>24 ; +if (opcode >=OP (RDMA_READ_RESPONSE_FIRST ) && + opcode <=OP (ATOMIC_ACKNOWLEDGE )) { +WARN_ON (!qp->s_rdma_ack_cnt); + qp->s_rdma_ack_cnt--; +return ; + } + + psn =be32_to_cpu (ohdr->bth[2 ]); +reset_sending_psn (qp, psn); + +/* +* Start timer after a packet requesting an ACK has been sent and +* there are still requests that haven't been acked. +*/ +if ((psn &IB_BTH_REQ_ACK ) && qp->s_acked != qp->s_tail && + !(qp->s_flags & (QIB_S_TIMER |QIB_S_WAIT_RNR |QIB_S_WAIT_PSN ))) +start_timer (qp); + +while (qp->s_last != qp->s_acked) { + wqe =get_swqe_ptr (qp, qp->s_last); +if (qib_cmp24 (wqe->lpsn, qp->s_sending_psn) >=0 && +qib_cmp24 (qp->s_sending_psn, qp->s_sending_hpsn) <=0 ) +break ; +for (i =0 ; i < wqe->wr.num_sge; i++) { +struct qib_sge *sge = &wqe->sg_list[i]; + +atomic_dec (&sge->mr->refcount); + } +/* Post a send completion queue entry if requested. */ +if (!(qp->s_flags &QIB_S_SIGNAL_REQ_WR ) || + (wqe->wr.send_flags &IB_SEND_SIGNALED )) { +memset (&wc,0 ,sizeof wc); + wc.wr_id = wqe->wr.wr_id; + wc.status =IB_WC_SUCCESS ; + wc.opcode = ib_qib_wc_opcode[wqe->wr.opcode]; + wc.byte_len = wqe->length; + wc.qp = &qp->ibqp; +qib_cq_enter (to_icq (qp->ibqp.send_cq), &wc,0 ); + } +if (++qp->s_last >= qp->s_size) + qp->s_last =0 ; + } +/* +* If we were waiting for sends to complete before resending, +* and they are now complete, restart sending. +*/ +if (qp->s_flags &QIB_S_WAIT_PSN && +qib_cmp24 (qp->s_sending_psn, qp->s_sending_hpsn) >0 ) { + qp->s_flags &= ~QIB_S_WAIT_PSN ; + qp->s_sending_psn = qp->s_psn; + qp->s_sending_hpsn = qp->s_psn -1 ; +qib_schedule_send (qp); + } +} + +static inline void update_last_psn (struct qib_qp *qp,u32 psn) +{ + qp->s_last_psn = psn; +} + +/* +* Generate a SWQE completion. +* This is similar to qib_send_complete but has to check to be sure +* that the SGEs are not being referenced if the SWQE is being resent. +*/ +static struct qib_swqe *do_rc_completion (struct qib_qp *qp, +struct qib_swqe *wqe, +struct qib_ibport *ibp) +{ +struct ib_wc wc; +unsigned i; + +/* +* Don't decrement refcount and don't generate a +* completion if the SWQE is being resent until the send +* is finished. +*/ +if (qib_cmp24 (wqe->lpsn, qp->s_sending_psn) <0 || +qib_cmp24 (qp->s_sending_psn, qp->s_sending_hpsn) >0 ) { +for (i =0 ; i < wqe->wr.num_sge; i++) { +struct qib_sge *sge = &wqe->sg_list[i]; + +atomic_dec (&sge->mr->refcount); + } +/* Post a send completion queue entry if requested. */ +if (!(qp->s_flags &QIB_S_SIGNAL_REQ_WR ) || + (wqe->wr.send_flags &IB_SEND_SIGNALED )) { +memset (&wc,0 ,sizeof wc); + wc.wr_id = wqe->wr.wr_id; + wc.status =IB_WC_SUCCESS ; + wc.opcode = ib_qib_wc_opcode[wqe->wr.opcode]; + wc.byte_len = wqe->length; + wc.qp = &qp->ibqp; +qib_cq_enter (to_icq (qp->ibqp.send_cq), &wc,0 ); + } +if (++qp->s_last >= qp->s_size) + qp->s_last =0 ; + }else + ibp->n_rc_delayed_comp++; + + qp->s_retry = qp->s_retry_cnt; +update_last_psn (qp, wqe->lpsn); + +/* +* If we are completing a request which is in the process of +* being resent, we can stop resending it since we know the +* responder has already seen it. +*/ +if (qp->s_acked == qp->s_cur) { +if (++qp->s_cur >= qp->s_size) + qp->s_cur =0 ; + qp->s_acked = qp->s_cur; + wqe =get_swqe_ptr (qp, qp->s_cur); +if (qp->s_acked != qp->s_tail) { + qp->s_state =OP (SEND_LAST ); + qp->s_psn = wqe->psn; + } + }else { +if (++qp->s_acked >= qp->s_size) + qp->s_acked =0 ; +if (qp->state ==IB_QPS_SQD && qp->s_acked == qp->s_cur) + qp->s_draining =0 ; + wqe =get_swqe_ptr (qp, qp->s_acked); + } +return wqe; +} + +/** +* do_rc_ack - process an incoming RC ACK +* @qp: the QP the ACK came in on +* @psn: the packet sequence number of the ACK +* @opcode: the opcode of the request that resulted in the ACK +* +* This is called from qib_rc_rcv_resp() to process an incoming RC ACK +* for the given QP. +* Called at interrupt level with the QP s_lock held. +* Returns 1 if OK, 0 if current operation should be aborted (NAK). +*/ +static int do_rc_ack (struct qib_qp *qp,u32 aeth,u32 psn,int opcode, +u64 val,struct qib_ctxtdata *rcd) +{ +struct qib_ibport *ibp; +enum ib_wc_status status; +struct qib_swqe *wqe; +int ret =0 ; +u32 ack_psn; +int diff; + +/* Remove QP from retry timer */ +if (qp->s_flags & (QIB_S_TIMER |QIB_S_WAIT_RNR )) { + qp->s_flags &= ~(QIB_S_TIMER |QIB_S_WAIT_RNR ); +del_timer (&qp->s_timer); + } + +/* +* Note that NAKs implicitly ACK outstanding SEND and RDMA write +* requests and implicitly NAK RDMA read and atomic requests issued +* before the NAK'ed request. The MSN won't include the NAK'ed +* request but will include an ACK'ed request(s). +*/ + ack_psn = psn; +if (aeth >>29 ) + ack_psn--; + wqe =get_swqe_ptr (qp, qp->s_acked); + ibp =to_iport (qp->ibqp.device, qp->port_num); + +/* +* The MSN might be for a later WQE than the PSN indicates so +* only complete WQEs that the PSN finishes. +*/ +while ((diff =qib_cmp24 (ack_psn, wqe->lpsn)) >=0 ) { +/* +* RDMA_READ_RESPONSE_ONLY is a special case since +* we want to generate completion events for everything +* before the RDMA read, copy the data, then generate +* the completion for the read. +*/ +if (wqe->wr.opcode ==IB_WR_RDMA_READ && + opcode ==OP (RDMA_READ_RESPONSE_ONLY ) && + diff ==0 ) { + ret =1 ; + goto bail; + } +/* +* If this request is a RDMA read or atomic, and the ACK is +* for a later operation, this ACK NAKs the RDMA read or +* atomic. In other words, only a RDMA_READ_LAST or ONLY +* can ACK a RDMA read and likewise for atomic ops. Note +* that the NAK case can only happen if relaxed ordering is +* used and requests are sent after an RDMA read or atomic +* is sent but before the response is received. +*/ +if ((wqe->wr.opcode ==IB_WR_RDMA_READ && + (opcode !=OP (RDMA_READ_RESPONSE_LAST ) || diff !=0 )) || + ((wqe->wr.opcode ==IB_WR_ATOMIC_CMP_AND_SWP || + wqe->wr.opcode ==IB_WR_ATOMIC_FETCH_AND_ADD ) && + (opcode !=OP (ATOMIC_ACKNOWLEDGE ) || diff !=0 ))) { +/* Retry this request. */ +if (!(qp->r_flags &QIB_R_RDMAR_SEQ )) { + qp->r_flags |=QIB_R_RDMAR_SEQ ; +qib_restart_rc (qp, qp->s_last_psn +1 ,0 ); +if (list_empty (&qp->rspwait)) { + qp->r_flags |=QIB_R_RSP_SEND ; +atomic_inc (&qp->refcount); +list_add_tail (&qp->rspwait, + &rcd->qp_wait_list); + } + } +/* +* No need to process the ACK/NAK since we are +* restarting an earlier request. +*/ + goto bail; + } +if (wqe->wr.opcode ==IB_WR_ATOMIC_CMP_AND_SWP || + wqe->wr.opcode ==IB_WR_ATOMIC_FETCH_AND_ADD ) { +u64 *vaddr = wqe->sg_list[0 ].vaddr; + *vaddr = val; + } +if (qp->s_num_rd_atomic && + (wqe->wr.opcode ==IB_WR_RDMA_READ || + wqe->wr.opcode ==IB_WR_ATOMIC_CMP_AND_SWP || + wqe->wr.opcode ==IB_WR_ATOMIC_FETCH_AND_ADD )) { + qp->s_num_rd_atomic--; +/* Restart sending task if fence is complete */ +if ((qp->s_flags &QIB_S_WAIT_FENCE ) && + !qp->s_num_rd_atomic) { + qp->s_flags &= ~(QIB_S_WAIT_FENCE | +QIB_S_WAIT_ACK ); +qib_schedule_send (qp); + }else if (qp->s_flags &QIB_S_WAIT_RDMAR ) { + qp->s_flags &= ~(QIB_S_WAIT_RDMAR | +QIB_S_WAIT_ACK ); +qib_schedule_send (qp); + } + } + wqe =do_rc_completion (qp, wqe, ibp); +if (qp->s_acked == qp->s_tail) +break ; + } + +switch (aeth >>29 ) { +case 0 :/* ACK */ + ibp->n_rc_acks++; +if (qp->s_acked != qp->s_tail) { +/* +* We are expecting more ACKs so +* reset the retransmit timer. +*/ +start_timer (qp); +/* +* We can stop resending the earlier packets and +* continue with the next packet the receiver wants. +*/ +if (qib_cmp24 (qp->s_psn, psn) <=0 ) +reset_psn (qp, psn +1 ); + }else if (qib_cmp24 (qp->s_psn, psn) <=0 ) { + qp->s_state =OP (SEND_LAST ); + qp->s_psn = psn +1 ; + } +if (qp->s_flags &QIB_S_WAIT_ACK ) { + qp->s_flags &= ~QIB_S_WAIT_ACK ; +qib_schedule_send (qp); + } +qib_get_credit (qp, aeth); + qp->s_rnr_retry = qp->s_rnr_retry_cnt; + qp->s_retry = qp->s_retry_cnt; +update_last_psn (qp, psn); + ret =1 ; + goto bail; + +case 1 :/* RNR NAK */ + ibp->n_rnr_naks++; +if (qp->s_acked == qp->s_tail) + goto bail; +if (qp->s_flags &QIB_S_WAIT_RNR ) + goto bail; +if (qp->s_rnr_retry ==0 ) { + status =IB_WC_RNR_RETRY_EXC_ERR ; + goto class_b; + } +if (qp->s_rnr_retry_cnt <7 ) + qp->s_rnr_retry--; + +/* The last valid PSN is the previous PSN. */ +update_last_psn (qp, psn -1 ); + + ibp->n_rc_resends += (qp->s_psn - psn) &QIB_PSN_MASK ; + +reset_psn (qp, psn); + + qp->s_flags &= ~(QIB_S_WAIT_SSN_CREDIT |QIB_S_WAIT_ACK ); + qp->s_flags |=QIB_S_WAIT_RNR ; + qp->s_timer.function = qib_rc_rnr_retry; + qp->s_timer.expires = jiffies +usecs_to_jiffies ( + ib_qib_rnr_table[(aeth >>QIB_AETH_CREDIT_SHIFT ) & +QIB_AETH_CREDIT_MASK ]); +add_timer (&qp->s_timer); + goto bail; + +case 3 :/* NAK */ +if (qp->s_acked == qp->s_tail) + goto bail; +/* The last valid PSN is the previous PSN. */ +update_last_psn (qp, psn -1 ); +switch ((aeth >>QIB_AETH_CREDIT_SHIFT ) & +QIB_AETH_CREDIT_MASK ) { +case 0 :/* PSN sequence error */ + ibp->n_seq_naks++; +/* +* Back up to the responder's expected PSN. +* Note that we might get a NAK in the middle of an +* RDMA READ response which terminates the RDMA +* READ. +*/ +qib_restart_rc (qp, psn,0 ); +qib_schedule_send (qp); +break ; + +case 1 :/* Invalid Request */ + status =IB_WC_REM_INV_REQ_ERR ; + ibp->n_other_naks++; + goto class_b; + +case 2 :/* Remote Access Error */ + status =IB_WC_REM_ACCESS_ERR ; + ibp->n_other_naks++; + goto class_b; + +case 3 :/* Remote Operation Error */ + status =IB_WC_REM_OP_ERR ; + ibp->n_other_naks++; +class_b: +if (qp->s_last == qp->s_acked) { +qib_send_complete (qp, wqe, status); +qib_error_qp (qp,IB_WC_WR_FLUSH_ERR ); + } +break ; + +default : +/* Ignore other reserved NAK error codes */ + goto reserved; + } + qp->s_retry = qp->s_retry_cnt; + qp->s_rnr_retry = qp->s_rnr_retry_cnt; + goto bail; + +default :/* 2: reserved */ +reserved: +/* Ignore reserved NAK codes. */ + goto bail; + } + +bail: +return ret; +} + +/* +* We have seen an out of sequence RDMA read middle or last packet. +* This ACKs SENDs and RDMA writes up to the first RDMA read or atomic SWQE. +*/ +static void rdma_seq_err (struct qib_qp *qp,struct qib_ibport *ibp,u32 psn, +struct qib_ctxtdata *rcd) +{ +struct qib_swqe *wqe; + +/* Remove QP from retry timer */ +if (qp->s_flags & (QIB_S_TIMER |QIB_S_WAIT_RNR )) { + qp->s_flags &= ~(QIB_S_TIMER |QIB_S_WAIT_RNR ); +del_timer (&qp->s_timer); + } + + wqe =get_swqe_ptr (qp, qp->s_acked); + +while (qib_cmp24 (psn, wqe->lpsn) >0 ) { +if (wqe->wr.opcode ==IB_WR_RDMA_READ || + wqe->wr.opcode ==IB_WR_ATOMIC_CMP_AND_SWP || + wqe->wr.opcode ==IB_WR_ATOMIC_FETCH_AND_ADD ) +break ; + wqe =do_rc_completion (qp, wqe, ibp); + } + + ibp->n_rdma_seq++; + qp->r_flags |=QIB_R_RDMAR_SEQ ; +qib_restart_rc (qp, qp->s_last_psn +1 ,0 ); +if (list_empty (&qp->rspwait)) { + qp->r_flags |=QIB_R_RSP_SEND ; +atomic_inc (&qp->refcount); +list_add_tail (&qp->rspwait, &rcd->qp_wait_list); + } +} + +/** +* qib_rc_rcv_resp - process an incoming RC response packet +* @ibp: the port this packet came in on +* @ohdr: the other headers for this packet +* @data: the packet data +* @tlen: the packet length +* @qp: the QP for this packet +* @opcode: the opcode for this packet +* @psn: the packet sequence number for this packet +* @hdrsize: the header length +* @pmtu: the path MTU +* +* This is called from qib_rc_rcv() to process an incoming RC response +* packet for the given QP. +* Called at interrupt level. +*/ +static void qib_rc_rcv_resp (struct qib_ibport *ibp, +struct qib_other_headers *ohdr, +void *data,u32 tlen, +struct qib_qp *qp, +u32 opcode, +u32 psn,u32 hdrsize,u32 pmtu, +struct qib_ctxtdata *rcd) +{ +struct qib_swqe *wqe; +enum ib_wc_status status; +unsigned long flags; +int diff; +u32 pad; +u32 aeth; +u64 val; + +spin_lock_irqsave (&qp->s_lock, flags); + +/* Double check we can process this now that we hold the s_lock. */ +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK )) + goto ack_done; + +/* Ignore invalid responses. */ +if (qib_cmp24 (psn, qp->s_next_psn) >=0 ) + goto ack_done; + +/* Ignore duplicate responses. */ + diff =qib_cmp24 (psn, qp->s_last_psn); +if (unlikely (diff <=0 )) { +/* Update credits for "ghost" ACKs */ +if (diff ==0 && opcode ==OP (ACKNOWLEDGE )) { + aeth =be32_to_cpu (ohdr->u.aeth); +if ((aeth >>29 ) ==0 ) +qib_get_credit (qp, aeth); + } + goto ack_done; + } + +/* +* Skip everything other than the PSN we expect, if we are waiting +* for a reply to a restarted RDMA read or atomic op. +*/ +if (qp->r_flags &QIB_R_RDMAR_SEQ ) { +if (qib_cmp24 (psn, qp->s_last_psn +1 ) !=0 ) + goto ack_done; + qp->r_flags &= ~QIB_R_RDMAR_SEQ ; + } + +if (unlikely (qp->s_acked == qp->s_tail)) + goto ack_done; + wqe =get_swqe_ptr (qp, qp->s_acked); + status =IB_WC_SUCCESS ; + +switch (opcode) { +case OP (ACKNOWLEDGE ): +case OP (ATOMIC_ACKNOWLEDGE ): +case OP (RDMA_READ_RESPONSE_FIRST ): + aeth =be32_to_cpu (ohdr->u.aeth); +if (opcode ==OP (ATOMIC_ACKNOWLEDGE )) { +__be32 *p = ohdr->u.at.atomic_ack_eth; + + val = ((u64 )be32_to_cpu (p[0 ]) <<32 ) | +be32_to_cpu (p[1 ]); + }else + val =0 ; +if (!do_rc_ack (qp, aeth, psn, opcode, val, rcd) || + opcode !=OP (RDMA_READ_RESPONSE_FIRST )) + goto ack_done; + hdrsize +=4 ; + wqe =get_swqe_ptr (qp, qp->s_acked); +if (unlikely (wqe->wr.opcode !=IB_WR_RDMA_READ )) + goto ack_op_err; +/* +* If this is a response to a resent RDMA read, we +* have to be careful to copy the data to the right +* location. +*/ + qp->s_rdma_read_len =restart_sge (&qp->s_rdma_read_sge, + wqe, psn, pmtu); + goto read_middle; + +case OP (RDMA_READ_RESPONSE_MIDDLE ): +/* no AETH, no ACK */ +if (unlikely (qib_cmp24 (psn, qp->s_last_psn +1 ))) + goto ack_seq_err; +if (unlikely (wqe->wr.opcode !=IB_WR_RDMA_READ )) + goto ack_op_err; +read_middle: +if (unlikely (tlen != (hdrsize + pmtu +4 ))) + goto ack_len_err; +if (unlikely (pmtu >= qp->s_rdma_read_len)) + goto ack_len_err; + +/* +* We got a response so update the timeout. +* 4.096 usec. * (1 << qp->timeout) +*/ + qp->s_flags |=QIB_S_TIMER ; +mod_timer (&qp->s_timer, jiffies + +usecs_to_jiffies ((4096UL * (1UL << qp->timeout)) / +1000UL )); +if (qp->s_flags &QIB_S_WAIT_ACK ) { + qp->s_flags &= ~QIB_S_WAIT_ACK ; +qib_schedule_send (qp); + } + +if (opcode ==OP (RDMA_READ_RESPONSE_MIDDLE )) + qp->s_retry = qp->s_retry_cnt; + +/* +* Update the RDMA receive state but do the copy w/o +* holding the locks and blocking interrupts. +*/ + qp->s_rdma_read_len -= pmtu; +update_last_psn (qp, psn); +spin_unlock_irqrestore (&qp->s_lock, flags); +qib_copy_sge (&qp->s_rdma_read_sge, data, pmtu,0 ); + goto bail; + +case OP (RDMA_READ_RESPONSE_ONLY ): + aeth =be32_to_cpu (ohdr->u.aeth); +if (!do_rc_ack (qp, aeth, psn, opcode,0 , rcd)) + goto ack_done; +/* Get the number of bytes the message was padded by. */ + pad = (be32_to_cpu (ohdr->bth[0 ]) >>20 ) &3 ; +/* +* Check that the data size is >= 0 && <= pmtu. +* Remember to account for the AETH header (4) and +* ICRC (4). +*/ +if (unlikely (tlen < (hdrsize + pad +8 ))) + goto ack_len_err; +/* +* If this is a response to a resent RDMA read, we +* have to be careful to copy the data to the right +* location. +*/ + wqe =get_swqe_ptr (qp, qp->s_acked); + qp->s_rdma_read_len =restart_sge (&qp->s_rdma_read_sge, + wqe, psn, pmtu); + goto read_last; + +case OP (RDMA_READ_RESPONSE_LAST ): +/* ACKs READ req. */ +if (unlikely (qib_cmp24 (psn, qp->s_last_psn +1 ))) + goto ack_seq_err; +if (unlikely (wqe->wr.opcode !=IB_WR_RDMA_READ )) + goto ack_op_err; +/* Get the number of bytes the message was padded by. */ + pad = (be32_to_cpu (ohdr->bth[0 ]) >>20 ) &3 ; +/* +* Check that the data size is >= 1 && <= pmtu. +* Remember to account for the AETH header (4) and +* ICRC (4). +*/ +if (unlikely (tlen <= (hdrsize + pad +8 ))) + goto ack_len_err; +read_last: + tlen -= hdrsize + pad +8 ; +if (unlikely (tlen != qp->s_rdma_read_len)) + goto ack_len_err; + aeth =be32_to_cpu (ohdr->u.aeth); +qib_copy_sge (&qp->s_rdma_read_sge, data, tlen,0 ); +WARN_ON (qp->s_rdma_read_sge.num_sge); + (void )do_rc_ack (qp, aeth, psn, +OP (RDMA_READ_RESPONSE_LAST ),0 , rcd); + goto ack_done; + } + +ack_op_err: + status =IB_WC_LOC_QP_OP_ERR ; + goto ack_err; + +ack_seq_err: +rdma_seq_err (qp, ibp, psn, rcd); + goto ack_done; + +ack_len_err: + status =IB_WC_LOC_LEN_ERR ; +ack_err: +if (qp->s_last == qp->s_acked) { +qib_send_complete (qp, wqe, status); +qib_error_qp (qp,IB_WC_WR_FLUSH_ERR ); + } +ack_done: +spin_unlock_irqrestore (&qp->s_lock, flags); +bail: +return ; +} + +/** +* qib_rc_rcv_error - process an incoming duplicate or error RC packet +* @ohdr: the other headers for this packet +* @data: the packet data +* @qp: the QP for this packet +* @opcode: the opcode for this packet +* @psn: the packet sequence number for this packet +* @diff: the difference between the PSN and the expected PSN +* +* This is called from qib_rc_rcv() to process an unexpected +* incoming RC packet for the given QP. +* Called at interrupt level. +* Return 1 if no more processing is needed; otherwise return 0 to +* schedule a response to be sent. +*/ +static int qib_rc_rcv_error (struct qib_other_headers *ohdr, +void *data, +struct qib_qp *qp, +u32 opcode, +u32 psn, +int diff, +struct qib_ctxtdata *rcd) +{ +struct qib_ibport *ibp =to_iport (qp->ibqp.device, qp->port_num); +struct qib_ack_entry *e; +unsigned long flags; +u8 i, prev; +int old_req; + +if (diff >0 ) { +/* +* Packet sequence error. +* A NAK will ACK earlier sends and RDMA writes. +* Don't queue the NAK if we already sent one. +*/ +if (!qp->r_nak_state) { + ibp->n_rc_seqnak++; + qp->r_nak_state =IB_NAK_PSN_ERROR ; +/* Use the expected PSN. */ + qp->r_ack_psn = qp->r_psn; +/* +* Wait to send the sequence NAK until all packets +* in the receive queue have been processed. +* Otherwise, we end up propagating congestion. +*/ +if (list_empty (&qp->rspwait)) { + qp->r_flags |=QIB_R_RSP_NAK ; +atomic_inc (&qp->refcount); +list_add_tail (&qp->rspwait, &rcd->qp_wait_list); + } + } + goto done; + } + +/* +* Handle a duplicate request. Don't re-execute SEND, RDMA +* write or atomic op. Don't NAK errors, just silently drop +* the duplicate request. Note that r_sge, r_len, and +* r_rcv_len may be in use so don't modify them. +* +* We are supposed to ACK the earliest duplicate PSN but we +* can coalesce an outstanding duplicate ACK. We have to +* send the earliest so that RDMA reads can be restarted at +* the requester's expected PSN. +* +* First, find where this duplicate PSN falls within the +* ACKs previously sent. +* old_req is true if there is an older response that is scheduled +* to be sent before sending this one. +*/ + e =NULL ; + old_req =1 ; + ibp->n_rc_dupreq++; + +spin_lock_irqsave (&qp->s_lock, flags); +/* Double check we can process this now that we hold the s_lock. */ +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK )) + goto unlock_done; + +for (i = qp->r_head_ack_queue; ; i = prev) { +if (i == qp->s_tail_ack_queue) + old_req =0 ; +if (i) + prev = i -1 ; +else + prev =QIB_MAX_RDMA_ATOMIC ; +if (prev == qp->r_head_ack_queue) { + e =NULL ; +break ; + } + e = &qp->s_ack_queue[prev]; +if (!e->opcode) { + e =NULL ; +break ; + } +if (qib_cmp24 (psn, e->psn) >=0 ) { +if (prev == qp->s_tail_ack_queue && +qib_cmp24 (psn, e->lpsn) <=0 ) + old_req =0 ; +break ; + } + } +switch (opcode) { +case OP (RDMA_READ_REQUEST ): { +struct ib_reth *reth; +u32 offset; +u32 len; + +/* +* If we didn't find the RDMA read request in the ack queue, +* we can ignore this request. +*/ +if (!e || e->opcode !=OP (RDMA_READ_REQUEST )) + goto unlock_done; +/* RETH comes after BTH */ + reth = &ohdr->u.rc.reth; +/* +* Address range must be a subset of the original +* request and start on pmtu boundaries. +* We reuse the old ack_queue slot since the requester +* should not back up and request an earlier PSN for the +* same request. +*/ + offset = ((psn - e->psn) &QIB_PSN_MASK ) * +ib_mtu_enum_to_int (qp->path_mtu); + len =be32_to_cpu (reth->length); +if (unlikely (offset + len != e->rdma_sge.sge_length)) + goto unlock_done; +if (e->rdma_sge.mr) { +atomic_dec (&e->rdma_sge.mr->refcount); + e->rdma_sge.mr =NULL ; + } +if (len !=0 ) { +u32 rkey =be32_to_cpu (reth->rkey); +u64 vaddr =be64_to_cpu (reth->vaddr); +int ok; + + ok =qib_rkey_ok (qp, &e->rdma_sge, len, vaddr, rkey, +IB_ACCESS_REMOTE_READ ); +if (unlikely (!ok)) + goto unlock_done; + }else { + e->rdma_sge.vaddr =NULL ; + e->rdma_sge.length =0 ; + e->rdma_sge.sge_length =0 ; + } + e->psn = psn; +if (old_req) + goto unlock_done; + qp->s_tail_ack_queue = prev; +break ; + } + +case OP (COMPARE_SWAP ): +case OP (FETCH_ADD ): { +/* +* If we didn't find the atomic request in the ack queue +* or the send tasklet is already backed up to send an +* earlier entry, we can ignore this request. +*/ +if (!e || e->opcode != (u8 ) opcode || old_req) + goto unlock_done; + qp->s_tail_ack_queue = prev; +break ; + } + +default : +/* +* Ignore this operation if it doesn't request an ACK +* or an earlier RDMA read or atomic is going to be resent. +*/ +if (!(psn &IB_BTH_REQ_ACK ) || old_req) + goto unlock_done; +/* +* Resend the most recent ACK if this request is +* after all the previous RDMA reads and atomics. +*/ +if (i == qp->r_head_ack_queue) { +spin_unlock_irqrestore (&qp->s_lock, flags); + qp->r_nak_state =0 ; + qp->r_ack_psn = qp->r_psn -1 ; + goto send_ack; + } +/* +* Try to send a simple ACK to work around a Mellanox bug +* which doesn't accept a RDMA read response or atomic +* response as an ACK for earlier SENDs or RDMA writes. +*/ +if (!(qp->s_flags &QIB_S_RESP_PENDING )) { +spin_unlock_irqrestore (&qp->s_lock, flags); + qp->r_nak_state =0 ; + qp->r_ack_psn = qp->s_ack_queue[i].psn -1 ; + goto send_ack; + } +/* +* Resend the RDMA read or atomic op which +* ACKs this duplicate request. +*/ + qp->s_tail_ack_queue = i; +break ; + } + qp->s_ack_state =OP (ACKNOWLEDGE ); + qp->s_flags |=QIB_S_RESP_PENDING ; + qp->r_nak_state =0 ; +qib_schedule_send (qp); + +unlock_done: +spin_unlock_irqrestore (&qp->s_lock, flags); +done: +return 1 ; + +send_ack: +return 0 ; +} + +void qib_rc_error (struct qib_qp *qp,enum ib_wc_status err) +{ +unsigned long flags; +int lastwqe; + +spin_lock_irqsave (&qp->s_lock, flags); + lastwqe =qib_error_qp (qp, err); +spin_unlock_irqrestore (&qp->s_lock, flags); + +if (lastwqe) { +struct ib_event ev; + + ev.device = qp->ibqp.device; + ev.element.qp = &qp->ibqp; + ev.event =IB_EVENT_QP_LAST_WQE_REACHED ; + qp->ibqp.event_handler (&ev, qp->ibqp.qp_context); + } +} + +static inline void qib_update_ack_queue (struct qib_qp *qp,unsigned n) +{ +unsigned next; + + next = n +1 ; +if (next >QIB_MAX_RDMA_ATOMIC ) + next =0 ; + qp->s_tail_ack_queue = next; + qp->s_ack_state =OP (ACKNOWLEDGE ); +} + +/** +* qib_rc_rcv - process an incoming RC packet +* @rcd: the context pointer +* @hdr: the header of this packet +* @has_grh: true if the header has a GRH +* @data: the packet data +* @tlen: the packet length +* @qp: the QP for this packet +* +* This is called from qib_qp_rcv() to process an incoming RC packet +* for the given QP. +* Called at interrupt level. +*/ +void qib_rc_rcv (struct qib_ctxtdata *rcd,struct qib_ib_header *hdr, +int has_grh,void *data,u32 tlen,struct qib_qp *qp) +{ +struct qib_ibport *ibp = &rcd->ppd->ibport_data; +struct qib_other_headers *ohdr; +u32 opcode; +u32 hdrsize; +u32 psn; +u32 pad; +struct ib_wc wc; +u32 pmtu =ib_mtu_enum_to_int (qp->path_mtu); +int diff; +struct ib_reth *reth; +unsigned long flags; +int ret; + +/* Check for GRH */ +if (!has_grh) { + ohdr = &hdr->u.oth; + hdrsize =8 +12 ;/* LRH + BTH */ + }else { + ohdr = &hdr->u.l.oth; + hdrsize =8 +40 +12 ;/* LRH + GRH + BTH */ + } + + opcode =be32_to_cpu (ohdr->bth[0 ]); +spin_lock_irqsave (&qp->s_lock, flags); +if (qib_ruc_check_hdr (ibp, hdr, has_grh, qp, opcode)) + goto sunlock; +spin_unlock_irqrestore (&qp->s_lock, flags); + + psn =be32_to_cpu (ohdr->bth[2 ]); + opcode >>=24 ; + +/* Prevent simultaneous processing after APM on different CPUs */ +spin_lock (&qp->r_lock); + +/* +* Process responses (ACKs) before anything else. Note that the +* packet sequence number will be for something in the send work +* queue rather than the expected receive packet sequence number. +* In other words, this QP is the requester. +*/ +if (opcode >=OP (RDMA_READ_RESPONSE_FIRST ) && + opcode <=OP (ATOMIC_ACKNOWLEDGE )) { +qib_rc_rcv_resp (ibp, ohdr, data, tlen, qp, opcode, psn, + hdrsize, pmtu, rcd); + goto runlock; + } + +/* Compute 24 bits worth of difference. */ + diff =qib_cmp24 (psn, qp->r_psn); +if (unlikely (diff)) { +if (qib_rc_rcv_error (ohdr, data, qp, opcode, psn, diff, rcd)) + goto runlock; + goto send_ack; + } + +/* Check for opcode sequence errors. */ +switch (qp->r_state) { +case OP (SEND_FIRST ): +case OP (SEND_MIDDLE ): +if (opcode ==OP (SEND_MIDDLE ) || + opcode ==OP (SEND_LAST ) || + opcode ==OP (SEND_LAST_WITH_IMMEDIATE )) +break ; + goto nack_inv; + +case OP (RDMA_WRITE_FIRST ): +case OP (RDMA_WRITE_MIDDLE ): +if (opcode ==OP (RDMA_WRITE_MIDDLE ) || + opcode ==OP (RDMA_WRITE_LAST ) || + opcode ==OP (RDMA_WRITE_LAST_WITH_IMMEDIATE )) +break ; + goto nack_inv; + +default : +if (opcode ==OP (SEND_MIDDLE ) || + opcode ==OP (SEND_LAST ) || + opcode ==OP (SEND_LAST_WITH_IMMEDIATE ) || + opcode ==OP (RDMA_WRITE_MIDDLE ) || + opcode ==OP (RDMA_WRITE_LAST ) || + opcode ==OP (RDMA_WRITE_LAST_WITH_IMMEDIATE )) + goto nack_inv; +/* +* Note that it is up to the requester to not send a new +* RDMA read or atomic operation before receiving an ACK +* for the previous operation. +*/ +break ; + } + +memset (&wc,0 ,sizeof wc); + +if (qp->state ==IB_QPS_RTR && !(qp->r_flags &QIB_R_COMM_EST )) { + qp->r_flags |=QIB_R_COMM_EST ; +if (qp->ibqp.event_handler) { +struct ib_event ev; + + ev.device = qp->ibqp.device; + ev.element.qp = &qp->ibqp; + ev.event =IB_EVENT_COMM_EST ; + qp->ibqp.event_handler (&ev, qp->ibqp.qp_context); + } + } + +/* OK, process the packet. */ +switch (opcode) { +case OP (SEND_FIRST ): + ret =qib_get_rwqe (qp,0 ); +if (ret <0 ) + goto nack_op_err; +if (!ret) + goto rnr_nak; + qp->r_rcv_len =0 ; +/* FALLTHROUGH */ +case OP (SEND_MIDDLE ): +case OP (RDMA_WRITE_MIDDLE ): +send_middle: +/* Check for invalid length PMTU or posted rwqe len. */ +if (unlikely (tlen != (hdrsize + pmtu +4 ))) + goto nack_inv; + qp->r_rcv_len += pmtu; +if (unlikely (qp->r_rcv_len > qp->r_len)) + goto nack_inv; +qib_copy_sge (&qp->r_sge, data, pmtu,1 ); +break ; + +case OP (RDMA_WRITE_LAST_WITH_IMMEDIATE ): +/* consume RWQE */ + ret =qib_get_rwqe (qp,1 ); +if (ret <0 ) + goto nack_op_err; +if (!ret) + goto rnr_nak; + goto send_last_imm; + +case OP (SEND_ONLY ): +case OP (SEND_ONLY_WITH_IMMEDIATE ): + ret =qib_get_rwqe (qp,0 ); +if (ret <0 ) + goto nack_op_err; +if (!ret) + goto rnr_nak; + qp->r_rcv_len =0 ; +if (opcode ==OP (SEND_ONLY )) + goto send_last; +/* FALLTHROUGH */ +case OP (SEND_LAST_WITH_IMMEDIATE ): +send_last_imm: + wc.ex.imm_data = ohdr->u.imm_data; + hdrsize +=4 ; + wc.wc_flags =IB_WC_WITH_IMM ; +/* FALLTHROUGH */ +case OP (SEND_LAST ): +case OP (RDMA_WRITE_LAST ): +send_last: +/* Get the number of bytes the message was padded by. */ + pad = (be32_to_cpu (ohdr->bth[0 ]) >>20 ) &3 ; +/* Check for invalid length. */ +/* XXX LAST len should be >= 1 */ +if (unlikely (tlen < (hdrsize + pad +4 ))) + goto nack_inv; +/* Don't count the CRC. */ + tlen -= (hdrsize + pad +4 ); + wc.byte_len = tlen + qp->r_rcv_len; +if (unlikely (wc.byte_len > qp->r_len)) + goto nack_inv; +qib_copy_sge (&qp->r_sge, data, tlen,1 ); +while (qp->r_sge.num_sge) { +atomic_dec (&qp->r_sge.sge.mr->refcount); +if (--qp->r_sge.num_sge) + qp->r_sge.sge = *qp->r_sge.sg_list++; + } + qp->r_msn++; +if (!test_and_clear_bit (QIB_R_WRID_VALID , &qp->r_aflags)) +break ; + wc.wr_id = qp->r_wr_id; + wc.status =IB_WC_SUCCESS ; +if (opcode ==OP (RDMA_WRITE_LAST_WITH_IMMEDIATE ) || + opcode ==OP (RDMA_WRITE_ONLY_WITH_IMMEDIATE )) + wc.opcode =IB_WC_RECV_RDMA_WITH_IMM ; +else + wc.opcode =IB_WC_RECV ; + wc.qp = &qp->ibqp; + wc.src_qp = qp->remote_qpn; + wc.slid = qp->remote_ah_attr.dlid; + wc.sl = qp->remote_ah_attr.sl; +/* Signal completion event if the solicited bit is set. */ +qib_cq_enter (to_icq (qp->ibqp.recv_cq), &wc, + (ohdr->bth[0 ] & +cpu_to_be32 (IB_BTH_SOLICITED )) !=0 ); +break ; + +case OP (RDMA_WRITE_FIRST ): +case OP (RDMA_WRITE_ONLY ): +case OP (RDMA_WRITE_ONLY_WITH_IMMEDIATE ): +if (unlikely (!(qp->qp_access_flags &IB_ACCESS_REMOTE_WRITE ))) + goto nack_inv; +/* consume RWQE */ + reth = &ohdr->u.rc.reth; + hdrsize +=sizeof (*reth); + qp->r_len =be32_to_cpu (reth->length); + qp->r_rcv_len =0 ; + qp->r_sge.sg_list =NULL ; +if (qp->r_len !=0 ) { +u32 rkey =be32_to_cpu (reth->rkey); +u64 vaddr =be64_to_cpu (reth->vaddr); +int ok; + +/* Check rkey & NAK */ + ok =qib_rkey_ok (qp, &qp->r_sge.sge, qp->r_len, vaddr, + rkey,IB_ACCESS_REMOTE_WRITE ); +if (unlikely (!ok)) + goto nack_acc; + qp->r_sge.num_sge =1 ; + }else { + qp->r_sge.num_sge =0 ; + qp->r_sge.sge.mr =NULL ; + qp->r_sge.sge.vaddr =NULL ; + qp->r_sge.sge.length =0 ; + qp->r_sge.sge.sge_length =0 ; + } +if (opcode ==OP (RDMA_WRITE_FIRST )) + goto send_middle; +else if (opcode ==OP (RDMA_WRITE_ONLY )) + goto send_last; + ret =qib_get_rwqe (qp,1 ); +if (ret <0 ) + goto nack_op_err; +if (!ret) + goto rnr_nak; + goto send_last_imm; + +case OP (RDMA_READ_REQUEST ): { +struct qib_ack_entry *e; +u32 len; +u8 next; + +if (unlikely (!(qp->qp_access_flags &IB_ACCESS_REMOTE_READ ))) + goto nack_inv; + next = qp->r_head_ack_queue +1 ; +/* s_ack_queue is size QIB_MAX_RDMA_ATOMIC+1 so use > not >= */ +if (next >QIB_MAX_RDMA_ATOMIC ) + next =0 ; +spin_lock_irqsave (&qp->s_lock, flags); +/* Double check we can process this while holding the s_lock. */ +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK )) + goto srunlock; +if (unlikely (next == qp->s_tail_ack_queue)) { +if (!qp->s_ack_queue[next].sent) + goto nack_inv_unlck; +qib_update_ack_queue (qp, next); + } + e = &qp->s_ack_queue[qp->r_head_ack_queue]; +if (e->opcode ==OP (RDMA_READ_REQUEST ) && e->rdma_sge.mr) { +atomic_dec (&e->rdma_sge.mr->refcount); + e->rdma_sge.mr =NULL ; + } + reth = &ohdr->u.rc.reth; + len =be32_to_cpu (reth->length); +if (len) { +u32 rkey =be32_to_cpu (reth->rkey); +u64 vaddr =be64_to_cpu (reth->vaddr); +int ok; + +/* Check rkey & NAK */ + ok =qib_rkey_ok (qp, &e->rdma_sge, len, vaddr, + rkey,IB_ACCESS_REMOTE_READ ); +if (unlikely (!ok)) + goto nack_acc_unlck; +/* +* Update the next expected PSN. We add 1 later +* below, so only add the remainder here. +*/ +if (len > pmtu) + qp->r_psn += (len -1 ) / pmtu; + }else { + e->rdma_sge.mr =NULL ; + e->rdma_sge.vaddr =NULL ; + e->rdma_sge.length =0 ; + e->rdma_sge.sge_length =0 ; + } + e->opcode = opcode; + e->sent =0 ; + e->psn = psn; + e->lpsn = qp->r_psn; +/* +* We need to increment the MSN here instead of when we +* finish sending the result since a duplicate request would +* increment it more than once. +*/ + qp->r_msn++; + qp->r_psn++; + qp->r_state = opcode; + qp->r_nak_state =0 ; + qp->r_head_ack_queue = next; + +/* Schedule the send tasklet. */ + qp->s_flags |=QIB_S_RESP_PENDING ; +qib_schedule_send (qp); + + goto srunlock; + } + +case OP (COMPARE_SWAP ): +case OP (FETCH_ADD ): { +struct ib_atomic_eth *ateth; +struct qib_ack_entry *e; +u64 vaddr; +atomic64_t *maddr; +u64 sdata; +u32 rkey; +u8 next; + +if (unlikely (!(qp->qp_access_flags &IB_ACCESS_REMOTE_ATOMIC ))) + goto nack_inv; + next = qp->r_head_ack_queue +1 ; +if (next >QIB_MAX_RDMA_ATOMIC ) + next =0 ; +spin_lock_irqsave (&qp->s_lock, flags); +/* Double check we can process this while holding the s_lock. */ +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK )) + goto srunlock; +if (unlikely (next == qp->s_tail_ack_queue)) { +if (!qp->s_ack_queue[next].sent) + goto nack_inv_unlck; +qib_update_ack_queue (qp, next); + } + e = &qp->s_ack_queue[qp->r_head_ack_queue]; +if (e->opcode ==OP (RDMA_READ_REQUEST ) && e->rdma_sge.mr) { +atomic_dec (&e->rdma_sge.mr->refcount); + e->rdma_sge.mr =NULL ; + } + ateth = &ohdr->u.atomic_eth; + vaddr = ((u64 )be32_to_cpu (ateth->vaddr[0 ]) <<32 ) | +be32_to_cpu (ateth->vaddr[1 ]); +if (unlikely (vaddr & (sizeof (u64) -1 ))) + goto nack_inv_unlck; + rkey =be32_to_cpu (ateth->rkey); +/* Check rkey & NAK */ +if (unlikely (!qib_rkey_ok (qp, &qp->r_sge.sge,sizeof (u64), + vaddr, rkey, +IB_ACCESS_REMOTE_ATOMIC ))) + goto nack_acc_unlck; +/* Perform atomic OP and save result. */ + maddr = (atomic64_t *) qp->r_sge.sge.vaddr; + sdata =be64_to_cpu (ateth->swap_data); + e->atomic_data = (opcode ==OP (FETCH_ADD )) ? + (u64 )atomic64_add_return (sdata, maddr) - sdata : + (u64 )cmpxchg ((u64 *) qp->r_sge.sge.vaddr, +be64_to_cpu (ateth->compare_data), + sdata); +atomic_dec (&qp->r_sge.sge.mr->refcount); + qp->r_sge.num_sge =0 ; + e->opcode = opcode; + e->sent =0 ; + e->psn = psn; + e->lpsn = psn; + qp->r_msn++; + qp->r_psn++; + qp->r_state = opcode; + qp->r_nak_state =0 ; + qp->r_head_ack_queue = next; + +/* Schedule the send tasklet. */ + qp->s_flags |=QIB_S_RESP_PENDING ; +qib_schedule_send (qp); + + goto srunlock; + } + +default : +/* NAK unknown opcodes. */ + goto nack_inv; + } + qp->r_psn++; + qp->r_state = opcode; + qp->r_ack_psn = psn; + qp->r_nak_state =0 ; +/* Send an ACK if requested or required. */ +if (psn & (1 <<31 )) + goto send_ack; + goto runlock; + +rnr_nak: + qp->r_nak_state =IB_RNR_NAK | qp->r_min_rnr_timer; + qp->r_ack_psn = qp->r_psn; +/* Queue RNR NAK for later */ +if (list_empty (&qp->rspwait)) { + qp->r_flags |=QIB_R_RSP_NAK ; +atomic_inc (&qp->refcount); +list_add_tail (&qp->rspwait, &rcd->qp_wait_list); + } + goto runlock; + +nack_op_err: +qib_rc_error (qp,IB_WC_LOC_QP_OP_ERR ); + qp->r_nak_state =IB_NAK_REMOTE_OPERATIONAL_ERROR ; + qp->r_ack_psn = qp->r_psn; +/* Queue NAK for later */ +if (list_empty (&qp->rspwait)) { + qp->r_flags |=QIB_R_RSP_NAK ; +atomic_inc (&qp->refcount); +list_add_tail (&qp->rspwait, &rcd->qp_wait_list); + } + goto runlock; + +nack_inv_unlck: +spin_unlock_irqrestore (&qp->s_lock, flags); +nack_inv: +qib_rc_error (qp,IB_WC_LOC_QP_OP_ERR ); + qp->r_nak_state =IB_NAK_INVALID_REQUEST ; + qp->r_ack_psn = qp->r_psn; +/* Queue NAK for later */ +if (list_empty (&qp->rspwait)) { + qp->r_flags |=QIB_R_RSP_NAK ; +atomic_inc (&qp->refcount); +list_add_tail (&qp->rspwait, &rcd->qp_wait_list); + } + goto runlock; + +nack_acc_unlck: +spin_unlock_irqrestore (&qp->s_lock, flags); +nack_acc: +qib_rc_error (qp,IB_WC_LOC_PROT_ERR ); + qp->r_nak_state =IB_NAK_REMOTE_ACCESS_ERROR ; + qp->r_ack_psn = qp->r_psn; +send_ack: +qib_send_rc_ack (qp); +runlock: +spin_unlock (&qp->r_lock); +return ; + +srunlock: +spin_unlock_irqrestore (&qp->s_lock, flags); +spin_unlock (&qp->r_lock); +return ; + +sunlock: +spin_unlock_irqrestore (&qp->s_lock, flags); +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 32/52 IB/qib: Add qib_ruc.c
In reply to a message not in the archivecreates the qib_ruc.c file.
---
drivers/infiniband/hw/qib/qib_ruc.c | 817 +++++++++++++++++++++++++++++++++++ 1 files changed, 817 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_ruc.c
drivers/infiniband/hw/qib/qib_ruc.c new file +817 -0
@@ -0,0 +1,817 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/spinlock.h> + +#include "qib.h" +#include "qib_mad.h" + +/* +* Convert the AETH RNR timeout code into the number of microseconds. +*/ +const u32 ib_qib_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 qib_init_sge (struct qib_qp *qp,struct qib_rwqe *wqe) +{ +int i, j, ret; +struct ib_wc wc; +struct qib_lkey_table *rkt; +struct qib_pd *pd; +struct qib_sge_state *ss; + + rkt = &to_idev (qp->ibqp.device)->lk_table; + pd =to_ipd (qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd); + ss = &qp->r_sge; + ss->sg_list = qp->r_sg_list; + qp->r_len =0 ; +for (i = j =0 ; i < wqe->num_sge; i++) { +if (wqe->sg_list[i].length ==0 ) +continue ; +/* Check LKEY */ +if (!qib_lkey_ok (rkt, pd, j ? &ss->sg_list[j -1 ] : &ss->sge, + &wqe->sg_list[i],IB_ACCESS_LOCAL_WRITE )) + goto bad_lkey; + qp->r_len += wqe->sg_list[i].length; + j++; + } + ss->num_sge = j; + ss->total_len = qp->r_len; + ret =1 ; + goto bail; + +bad_lkey: +while (j) { +struct qib_sge *sge = --j ? &ss->sg_list[j -1 ] : &ss->sge; + +atomic_dec (&sge->mr->refcount); + } + ss->num_sge =0 ; +memset (&wc,0 ,sizeof (wc)); + wc.wr_id = wqe->wr_id; + wc.status =IB_WC_LOC_PROT_ERR ; + wc.opcode =IB_WC_RECV ; + wc.qp = &qp->ibqp; +/* Signal solicited completion event. */ +qib_cq_enter (to_icq (qp->ibqp.recv_cq), &wc,1 ); + ret =0 ; +bail: +return ret; +} + +/** +* qib_get_rwqe - copy the next RWQE into the QP's RWQE +* @qp: the QP +* @wr_id_only: update qp->r_wr_id only, not qp->r_sge +* +* Return -1 if there is a local error, 0 if no RWQE is available, +* otherwise return 1. +* +* Can be called from interrupt level. +*/ +int qib_get_rwqe (struct qib_qp *qp,int wr_id_only) +{ +unsigned long flags; +struct qib_rq *rq; +struct qib_rwq *wq; +struct qib_srq *srq; +struct qib_rwqe *wqe; +void (*handler)(struct ib_event *,void *); +u32 tail; +int ret; + +if (qp->ibqp.srq) { + srq =to_isrq (qp->ibqp.srq); + handler = srq->ibsrq.event_handler; + rq = &srq->rq; + }else { + srq =NULL ; + handler =NULL ; + rq = &qp->r_rq; + } + +spin_lock_irqsave (&rq->lock, flags); +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK )) { + ret =0 ; + goto unlock; + } + + wq = rq->wq; + tail = wq->tail; +/* Validate tail before using it since it is user writable. */ +if (tail >= rq->size) + tail =0 ; +if (unlikely (tail == wq->head)) { + ret =0 ; + goto unlock; + } +/* Make sure entry is read after head index is read. */ +smp_rmb (); + wqe =get_rwqe_ptr (rq, tail); +/* +* Even though we update the tail index in memory, the verbs +* consumer is not supposed to post more entries until a +* completion is generated. +*/ +if (++tail >= rq->size) + tail =0 ; + wq->tail = tail; +if (!wr_id_only && !qib_init_sge (qp, wqe)) { + ret =-1 ; + goto unlock; + } + qp->r_wr_id = wqe->wr_id; + + ret =1 ; +set_bit (QIB_R_WRID_VALID , &qp->r_aflags); +if (handler) { +u32 n; + +/* +* Validate head pointer value and compute +* the number of remaining WQEs. +*/ + n = wq->head; +if (n >= rq->size) + n =0 ; +if (n < tail) + n += rq->size - tail; +else + n -= tail; +if (n < srq->limit) { +struct ib_event ev; + + srq->limit =0 ; +spin_unlock_irqrestore (&rq->lock, flags); + ev.device = qp->ibqp.device; + ev.element.srq = qp->ibqp.srq; + ev.event =IB_EVENT_SRQ_LIMIT_REACHED ; +handler (&ev, srq->ibsrq.srq_context); + goto bail; + } + } +unlock: +spin_unlock_irqrestore (&rq->lock, flags); +bail: +return ret; +} + +/* +* Switch to alternate path. +* The QP s_lock should be held and interrupts disabled. +*/ +void qib_migrate_qp (struct qib_qp *qp) +{ +struct ib_event ev; + + qp->s_mig_state =IB_MIG_MIGRATED ; + qp->remote_ah_attr = qp->alt_ah_attr; + qp->port_num = qp->alt_ah_attr.port_num; + qp->s_pkey_index = qp->s_alt_pkey_index; + + ev.device = qp->ibqp.device; + ev.element.qp = &qp->ibqp; + ev.event =IB_EVENT_PATH_MIG ; + qp->ibqp.event_handler (&ev, qp->ibqp.qp_context); +} + +static __be64 get_sguid (struct qib_ibport *ibp,unsigned index) +{ +if (!index) { +struct qib_pportdata *ppd =ppd_from_ibp (ibp); + +return ppd->guid; + }else +return ibp->guids[index -1 ]; +} + +static int gid_ok (union ib_gid *gid,__be64 gid_prefix,__be64 id) +{ +return (gid->global.interface_id == id && + (gid->global.subnet_prefix == gid_prefix || + gid->global.subnet_prefix ==IB_DEFAULT_GID_PREFIX )); +} + +/* +* +* This should be called with the QP s_lock held. +*/ +int qib_ruc_check_hdr (struct qib_ibport *ibp,struct qib_ib_header *hdr, +int has_grh,struct qib_qp *qp,u32 bth0) +{ +__be64 guid; + +if (qp->s_mig_state ==IB_MIG_ARMED && (bth0 &IB_BTH_MIG_REQ )) { +if (!has_grh) { +if (qp->alt_ah_attr.ah_flags &IB_AH_GRH ) + goto err; + }else { +if (!(qp->alt_ah_attr.ah_flags &IB_AH_GRH )) + goto err; + guid =get_sguid (ibp, qp->alt_ah_attr.grh.sgid_index); +if (!gid_ok (&hdr->u.l.grh.dgid, ibp->gid_prefix, guid)) + goto err; +if (!gid_ok (&hdr->u.l.grh.sgid, + qp->alt_ah_attr.grh.dgid.global.subnet_prefix, + qp->alt_ah_attr.grh.dgid.global.interface_id)) + goto err; + } +if (!qib_pkey_ok ((u16 )bth0, +qib_get_pkey (ibp, qp->s_alt_pkey_index))) { +qib_bad_pqkey (ibp,IB_NOTICE_TRAP_BAD_PKEY , + (u16 )bth0, + (be16_to_cpu (hdr->lrh[0 ]) >>4 ) &0xF , +0 , qp->ibqp.qp_num, + hdr->lrh[3 ], hdr->lrh[1 ]); + goto err; + } +/* Validate the SLID. See Ch. 9.6.1.5 and 17.2.8 */ +if (be16_to_cpu (hdr->lrh[3 ]) != qp->alt_ah_attr.dlid || +ppd_from_ibp (ibp)->port != qp->alt_ah_attr.port_num) + goto err; +qib_migrate_qp (qp); + }else { +if (!has_grh) { +if (qp->remote_ah_attr.ah_flags &IB_AH_GRH ) + goto err; + }else { +if (!(qp->remote_ah_attr.ah_flags &IB_AH_GRH )) + goto err; + guid =get_sguid (ibp, + qp->remote_ah_attr.grh.sgid_index); +if (!gid_ok (&hdr->u.l.grh.dgid, ibp->gid_prefix, guid)) + goto err; +if (!gid_ok (&hdr->u.l.grh.sgid, + qp->remote_ah_attr.grh.dgid.global.subnet_prefix, + qp->remote_ah_attr.grh.dgid.global.interface_id)) + goto err; + } +if (!qib_pkey_ok ((u16 )bth0, +qib_get_pkey (ibp, qp->s_pkey_index))) { +qib_bad_pqkey (ibp,IB_NOTICE_TRAP_BAD_PKEY , + (u16 )bth0, + (be16_to_cpu (hdr->lrh[0 ]) >>4 ) &0xF , +0 , qp->ibqp.qp_num, + hdr->lrh[3 ], hdr->lrh[1 ]); + goto err; + } +/* Validate the SLID. See Ch. 9.6.1.5 */ +if (be16_to_cpu (hdr->lrh[3 ]) != qp->remote_ah_attr.dlid || +ppd_from_ibp (ibp)->port != qp->port_num) + goto err; +if (qp->s_mig_state ==IB_MIG_REARM && + !(bth0 &IB_BTH_MIG_REQ )) + qp->s_mig_state =IB_MIG_ARMED ; + } + +return 0 ; + +err: +return 1 ; +} + +/** +* qib_ruc_loopback - handle UC and RC lookback requests +* @sqp: the sending QP +* +* This is called from qib_do_send() to +* forward a WQE addressed to the same HCA. +* Note that although we are single threaded due to the tasklet, we still +* have to protect against post_send(). We don't have to worry about +* receive interrupts since this is a connected protocol and all packets +* will pass through here. +*/ +static void qib_ruc_loopback (struct qib_qp *sqp) +{ +struct qib_ibport *ibp =to_iport (sqp->ibqp.device, sqp->port_num); +struct qib_qp *qp; +struct qib_swqe *wqe; +struct qib_sge *sge; +unsigned long flags; +struct ib_wc wc; +u64 sdata; +atomic64_t *maddr; +enum ib_wc_status send_status; +int release; +int ret; + +/* +* Note that we check the responder QP state after +* checking the requester's state. +*/ + qp =qib_lookup_qpn (ibp, sqp->remote_qpn); + +spin_lock_irqsave (&sqp->s_lock, flags); + +/* Return if we are already busy processing a work request. */ +if ((sqp->s_flags & (QIB_S_BUSY |QIB_S_ANY_WAIT )) || + !(ib_qib_state_ops[sqp->state] &QIB_PROCESS_OR_FLUSH_SEND )) + goto unlock; + + sqp->s_flags |=QIB_S_BUSY ; + +again: +if (sqp->s_last == sqp->s_head) + goto clr_busy; + wqe =get_swqe_ptr (sqp, sqp->s_last); + +/* Return if it is not OK to start a new work reqeust. */ +if (!(ib_qib_state_ops[sqp->state] &QIB_PROCESS_NEXT_SEND_OK )) { +if (!(ib_qib_state_ops[sqp->state] &QIB_FLUSH_SEND )) + goto clr_busy; +/* We are in the error state, flush the work request. */ + send_status =IB_WC_WR_FLUSH_ERR ; + goto flush_send; + } + +/* +* We can rely on the entry not changing without the s_lock +* being held until we update s_last. +* We increment s_cur to indicate s_last is in progress. +*/ +if (sqp->s_last == sqp->s_cur) { +if (++sqp->s_cur >= sqp->s_size) + sqp->s_cur =0 ; + } +spin_unlock_irqrestore (&sqp->s_lock, flags); + +if (!qp || !(ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK ) || + qp->ibqp.qp_type != sqp->ibqp.qp_type) { + ibp->n_pkt_drops++; +/* +* For RC, the requester would timeout and retry so +* shortcut the timeouts and just signal too many retries. +*/ +if (sqp->ibqp.qp_type ==IB_QPT_RC ) + send_status =IB_WC_RETRY_EXC_ERR ; +else + send_status =IB_WC_SUCCESS ; + goto serr; + } + +memset (&wc,0 ,sizeof wc); + send_status =IB_WC_SUCCESS ; + + release =1 ; + sqp->s_sge.sge = wqe->sg_list[0 ]; + sqp->s_sge.sg_list = wqe->sg_list +1 ; + sqp->s_sge.num_sge = wqe->wr.num_sge; + sqp->s_len = wqe->length; +switch (wqe->wr.opcode) { +case IB_WR_SEND_WITH_IMM : + wc.wc_flags =IB_WC_WITH_IMM ; + wc.ex.imm_data = wqe->wr.ex.imm_data; +/* FALLTHROUGH */ +case IB_WR_SEND : + ret =qib_get_rwqe (qp,0 ); +if (ret <0 ) + goto op_err; +if (!ret) + goto rnr_nak; +break ; + +case IB_WR_RDMA_WRITE_WITH_IMM : +if (unlikely (!(qp->qp_access_flags &IB_ACCESS_REMOTE_WRITE ))) + goto inv_err; + wc.wc_flags =IB_WC_WITH_IMM ; + wc.ex.imm_data = wqe->wr.ex.imm_data; + ret =qib_get_rwqe (qp,1 ); +if (ret <0 ) + goto op_err; +if (!ret) + goto rnr_nak; +/* FALLTHROUGH */ +case IB_WR_RDMA_WRITE : +if (unlikely (!(qp->qp_access_flags &IB_ACCESS_REMOTE_WRITE ))) + goto inv_err; +if (wqe->length ==0 ) +break ; +if (unlikely (!qib_rkey_ok (qp, &qp->r_sge.sge, wqe->length, + wqe->wr.wr.rdma.remote_addr, + wqe->wr.wr.rdma.rkey, +IB_ACCESS_REMOTE_WRITE ))) + goto acc_err; + qp->r_sge.sg_list =NULL ; + qp->r_sge.num_sge =1 ; + qp->r_sge.total_len = wqe->length; +break ; + +case IB_WR_RDMA_READ : +if (unlikely (!(qp->qp_access_flags &IB_ACCESS_REMOTE_READ ))) + goto inv_err; +if (unlikely (!qib_rkey_ok (qp, &sqp->s_sge.sge, wqe->length, + wqe->wr.wr.rdma.remote_addr, + wqe->wr.wr.rdma.rkey, +IB_ACCESS_REMOTE_READ ))) + goto acc_err; + release =0 ; + sqp->s_sge.sg_list =NULL ; + sqp->s_sge.num_sge =1 ; + qp->r_sge.sge = wqe->sg_list[0 ]; + qp->r_sge.sg_list = wqe->sg_list +1 ; + qp->r_sge.num_sge = wqe->wr.num_sge; + qp->r_sge.total_len = wqe->length; +break ; + +case IB_WR_ATOMIC_CMP_AND_SWP : +case IB_WR_ATOMIC_FETCH_AND_ADD : +if (unlikely (!(qp->qp_access_flags &IB_ACCESS_REMOTE_ATOMIC ))) + goto inv_err; +if (unlikely (!qib_rkey_ok (qp, &qp->r_sge.sge,sizeof (u64), + wqe->wr.wr.atomic.remote_addr, + wqe->wr.wr.atomic.rkey, +IB_ACCESS_REMOTE_ATOMIC ))) + goto acc_err; +/* Perform atomic OP and save result. */ + maddr = (atomic64_t *) qp->r_sge.sge.vaddr; + sdata = wqe->wr.wr.atomic.compare_add; + *(u64 *) sqp->s_sge.sge.vaddr = + (wqe->wr.opcode ==IB_WR_ATOMIC_FETCH_AND_ADD ) ? + (u64 )atomic64_add_return (sdata, maddr) - sdata : + (u64 )cmpxchg ((u64 *) qp->r_sge.sge.vaddr, + sdata, wqe->wr.wr.atomic.swap); +atomic_dec (&qp->r_sge.sge.mr->refcount); + qp->r_sge.num_sge =0 ; + goto send_comp; + +default : + send_status =IB_WC_LOC_QP_OP_ERR ; + goto serr; + } + + sge = &sqp->s_sge.sge; +while (sqp->s_len) { +u32 len = sqp->s_len; + +if (len > sge->length) + len = sge->length; +if (len > sge->sge_length) + len = sge->sge_length; +BUG_ON (len ==0 ); +qib_copy_sge (&qp->r_sge, sge->vaddr, len, release); + sge->vaddr += len; + sge->length -= len; + sge->sge_length -= len; +if (sge->sge_length ==0 ) { +if (!release) +atomic_dec (&sge->mr->refcount); +if (--sqp->s_sge.num_sge) + *sge = *sqp->s_sge.sg_list++; + }else if (sge->length ==0 && sge->mr->lkey) { +if (++sge->n >=QIB_SEGSZ ) { +if (++sge->m >= sge->mr->mapsz) +break ; + sge->n =0 ; + } + sge->vaddr = + sge->mr->map[sge->m]->segs[sge->n].vaddr; + sge->length = + sge->mr->map[sge->m]->segs[sge->n].length; + } + sqp->s_len -= len; + } +if (release) +while (qp->r_sge.num_sge) { +atomic_dec (&qp->r_sge.sge.mr->refcount); +if (--qp->r_sge.num_sge) + qp->r_sge.sge = *qp->r_sge.sg_list++; + } + +if (!test_and_clear_bit (QIB_R_WRID_VALID , &qp->r_aflags)) + goto send_comp; + +if (wqe->wr.opcode ==IB_WR_RDMA_WRITE_WITH_IMM ) + wc.opcode =IB_WC_RECV_RDMA_WITH_IMM ; +else + wc.opcode =IB_WC_RECV ; + wc.wr_id = qp->r_wr_id; + wc.status =IB_WC_SUCCESS ; + wc.byte_len = wqe->length; + wc.qp = &qp->ibqp; + wc.src_qp = qp->remote_qpn; + wc.slid = qp->remote_ah_attr.dlid; + wc.sl = qp->remote_ah_attr.sl; + wc.port_num =1 ; +/* Signal completion event if the solicited bit is set. */ +qib_cq_enter (to_icq (qp->ibqp.recv_cq), &wc, + wqe->wr.send_flags &IB_SEND_SOLICITED ); + +send_comp: +spin_lock_irqsave (&sqp->s_lock, flags); + ibp->n_loop_pkts++; +flush_send: + sqp->s_rnr_retry = sqp->s_rnr_retry_cnt; +qib_send_complete (sqp, wqe, send_status); + goto again; + +rnr_nak: +/* Handle RNR NAK */ +if (qp->ibqp.qp_type ==IB_QPT_UC ) + goto send_comp; + ibp->n_rnr_naks++; +/* +* Note: we don't need the s_lock held since the BUSY flag +* makes this single threaded. +*/ +if (sqp->s_rnr_retry ==0 ) { + send_status =IB_WC_RNR_RETRY_EXC_ERR ; + goto serr; + } +if (sqp->s_rnr_retry_cnt <7 ) + sqp->s_rnr_retry--; +spin_lock_irqsave (&sqp->s_lock, flags); +if (!(ib_qib_state_ops[sqp->state] &QIB_PROCESS_RECV_OK )) + goto clr_busy; + sqp->s_flags |=QIB_S_WAIT_RNR ; + sqp->s_timer.function = qib_rc_rnr_retry; + sqp->s_timer.expires = jiffies + +usecs_to_jiffies (ib_qib_rnr_table[qp->r_min_rnr_timer]); +add_timer (&sqp->s_timer); + goto clr_busy; + +op_err: + send_status =IB_WC_REM_OP_ERR ; + wc.status =IB_WC_LOC_QP_OP_ERR ; + goto err; + +inv_err: + send_status =IB_WC_REM_INV_REQ_ERR ; + wc.status =IB_WC_LOC_QP_OP_ERR ; + goto err; + +acc_err: + send_status =IB_WC_REM_ACCESS_ERR ; + wc.status =IB_WC_LOC_PROT_ERR ; +err: +/* responder goes to error state */ +qib_rc_error (qp, wc.status); + +serr: +spin_lock_irqsave (&sqp->s_lock, flags); +qib_send_complete (sqp, wqe, send_status); +if (sqp->ibqp.qp_type ==IB_QPT_RC ) { +int lastwqe =qib_error_qp (sqp,IB_WC_WR_FLUSH_ERR ); + + sqp->s_flags &= ~QIB_S_BUSY ; +spin_unlock_irqrestore (&sqp->s_lock, flags); +if (lastwqe) { +struct ib_event ev; + + ev.device = sqp->ibqp.device; + ev.element.qp = &sqp->ibqp; + ev.event =IB_EVENT_QP_LAST_WQE_REACHED ; + sqp->ibqp.event_handler (&ev, sqp->ibqp.qp_context); + } + goto done; + } +clr_busy: + sqp->s_flags &= ~QIB_S_BUSY ; +unlock: +spin_unlock_irqrestore (&sqp->s_lock, flags); +done: +if (qp &&atomic_dec_and_test (&qp->refcount)) +wake_up (&qp->wait); +} + +/** +* qib_make_grh - construct a GRH header +* @ibp: a pointer to the IB port +* @hdr: a pointer to the GRH header being constructed +* @grh: the global route address to send to +* @hwords: the number of 32 bit words of header being sent +* @nwords: the number of 32 bit words of data being sent +* +* Return the size of the header in 32 bit words. +*/ +u32 qib_make_grh (struct qib_ibport *ibp,struct ib_grh *hdr, +struct ib_global_route *grh,u32 hwords,u32 nwords) +{ + hdr->version_tclass_flow = +cpu_to_be32 ((IB_GRH_VERSION <<IB_GRH_VERSION_SHIFT ) | + (grh->traffic_class <<IB_GRH_TCLASS_SHIFT ) | + (grh->flow_label <<IB_GRH_FLOW_SHIFT )); + hdr->paylen =cpu_to_be16 ((hwords -2 + nwords +SIZE_OF_CRC ) <<2 ); +/* next_hdr is defined by C8-7 in ch. 8.4.1 */ + hdr->next_hdr =IB_GRH_NEXT_HDR ; + hdr->hop_limit = grh->hop_limit; +/* The SGID is 32-bit aligned. */ + hdr->sgid.global.subnet_prefix = ibp->gid_prefix; + hdr->sgid.global.interface_id = grh->sgid_index ? + ibp->guids[grh->sgid_index -1 ] :ppd_from_ibp (ibp)->guid; + hdr->dgid = grh->dgid; + +/* GRH header size in 32-bit words. */ +return sizeof (struct ib_grh ) /sizeof (u32); +} + +void qib_make_ruc_header (struct qib_qp *qp,struct qib_other_headers *ohdr, +u32 bth0,u32 bth2) +{ +struct qib_ibport *ibp =to_iport (qp->ibqp.device, qp->port_num); +u16 lrh0; +u32 nwords; +u32 extra_bytes; + +/* Construct the header. */ + extra_bytes = -qp->s_cur_size &3 ; + nwords = (qp->s_cur_size + extra_bytes) >>2 ; + lrh0 =QIB_LRH_BTH ; +if (unlikely (qp->remote_ah_attr.ah_flags &IB_AH_GRH )) { + qp->s_hdrwords +=qib_make_grh (ibp, &qp->s_hdr.u.l.grh, + &qp->remote_ah_attr.grh, + qp->s_hdrwords, nwords); + lrh0 =QIB_LRH_GRH ; + } + lrh0 |= ibp->sl_to_vl[qp->remote_ah_attr.sl] <<12 | + qp->remote_ah_attr.sl <<4 ; + qp->s_hdr.lrh[0 ] =cpu_to_be16 (lrh0); + qp->s_hdr.lrh[1 ] =cpu_to_be16 (qp->remote_ah_attr.dlid); + qp->s_hdr.lrh[2 ] =cpu_to_be16 (qp->s_hdrwords + nwords +SIZE_OF_CRC ); + qp->s_hdr.lrh[3 ] =cpu_to_be16 (ppd_from_ibp (ibp)->lid | + qp->remote_ah_attr.src_path_bits); + bth0 |=qib_get_pkey (ibp, qp->s_pkey_index); + bth0 |= extra_bytes <<20 ; +if (qp->s_mig_state ==IB_MIG_MIGRATED ) + bth0 |=IB_BTH_MIG_REQ ; + ohdr->bth[0 ] =cpu_to_be32 (bth0); + ohdr->bth[1 ] =cpu_to_be32 (qp->remote_qpn); + ohdr->bth[2 ] =cpu_to_be32 (bth2); +} + +/** +* qib_do_send - perform a send on a QP +* @work: contains a pointer to the QP +* +* Process entries in the send work queue until credit or queue is +* exhausted. Only allow one CPU to send a packet per QP (tasklet). +* Otherwise, two threads could send packets out of order. +*/ +void qib_do_send (struct work_struct *work) +{ + struct qib_qp *qp = container_of(work, struct qib_qp, s_work); +struct qib_ibport *ibp =to_iport (qp->ibqp.device, qp->port_num); +struct qib_pportdata *ppd =ppd_from_ibp (ibp); +int (*make_req)(struct qib_qp *qp); +unsigned long flags; + +if ((qp->ibqp.qp_type ==IB_QPT_RC || + qp->ibqp.qp_type ==IB_QPT_UC ) && + (qp->remote_ah_attr.dlid & ~((1 << ppd->lmc) -1 )) == ppd->lid) { +qib_ruc_loopback (qp); +return ; + } + +if (qp->ibqp.qp_type ==IB_QPT_RC ) + make_req = qib_make_rc_req; +else if (qp->ibqp.qp_type ==IB_QPT_UC ) + make_req = qib_make_uc_req; +else + make_req = qib_make_ud_req; + +spin_lock_irqsave (&qp->s_lock, flags); + +/* Return if we are already busy processing a work request. */ +if (!qib_send_ok (qp)) { +spin_unlock_irqrestore (&qp->s_lock, flags); +return ; + } + + qp->s_flags |=QIB_S_BUSY ; + +spin_unlock_irqrestore (&qp->s_lock, flags); + +do { +/* Check for a constructed packet to be sent. */ +if (qp->s_hdrwords !=0 ) { +/* +* If the packet cannot be sent now, return and +* the send tasklet will be woken up later. +*/ +if (qib_verbs_send (qp, &qp->s_hdr, qp->s_hdrwords, + qp->s_cur_sge, qp->s_cur_size)) +break ; +/* Record that s_hdr is empty. */ + qp->s_hdrwords =0 ; + } + }while (make_req (qp)); +} + +/* +* This should be called with s_lock held. +*/ +void qib_send_complete (struct qib_qp *qp,struct qib_swqe *wqe, +enum ib_wc_status status) +{ +u32 old_last, last; +unsigned i; + +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_OR_FLUSH_SEND )) +return ; + +for (i =0 ; i < wqe->wr.num_sge; i++) { +struct qib_sge *sge = &wqe->sg_list[i]; + +atomic_dec (&sge->mr->refcount); + } +if (qp->ibqp.qp_type ==IB_QPT_UD || + qp->ibqp.qp_type ==IB_QPT_SMI || + qp->ibqp.qp_type ==IB_QPT_GSI ) +atomic_dec (&to_iah (wqe->wr.wr.ud.ah)->refcount); + +/* See ch. 11.2.4.1 and 10.7.3.1 */ +if (!(qp->s_flags &QIB_S_SIGNAL_REQ_WR ) || + (wqe->wr.send_flags &IB_SEND_SIGNALED ) || + status !=IB_WC_SUCCESS ) { +struct ib_wc wc; + +memset (&wc,0 ,sizeof wc); + wc.wr_id = wqe->wr.wr_id; + wc.status = status; + wc.opcode = ib_qib_wc_opcode[wqe->wr.opcode]; + wc.qp = &qp->ibqp; +if (status ==IB_WC_SUCCESS ) + wc.byte_len = wqe->length; +qib_cq_enter (to_icq (qp->ibqp.send_cq), &wc, + status !=IB_WC_SUCCESS ); + } + + last = qp->s_last; + old_last = last; +if (++last >= qp->s_size) + last =0 ; + qp->s_last = last; +if (qp->s_acked == old_last) + qp->s_acked = last; +if (qp->s_cur == old_last) + qp->s_cur = last; +if (qp->s_tail == old_last) + qp->s_tail = last; +if (qp->state ==IB_QPS_SQD && last == qp->s_cur) + qp->s_draining =0 ; +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 33/52 IB/qib: Add qib_sd7220.c
In reply to a message not in the archivecreates the qib_sd7220.c file.
---
drivers/infiniband/hw/qib/qib_sd7220.c | 1415 ++++++++++++++++++++++++++++++++ 1 files changed, 1415 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_sd7220.c
drivers/infiniband/hw/qib/qib_sd7220.c new file +1415 -0
@@ -0,0 +1,1415 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ +/* +* This file contains all of the code that is specific to the SerDes +* on the QLogic_IB 7220 chip. +*/ + +#include <linux/pci.h> +#include <linux/delay.h> + +#include "qib.h" +#include "qib_7220.h" + +/* +* Same as in qib_iba7220.c, but just the registers needed here. +* Could move whole set to qib_7220.h, but decided better to keep +* local. +*/ +#define KREG_IDX (regname) (QIB_7220_##regname##_OFFS / sizeof(u64)) +#define kr_hwerrclear KREG_IDX(HwErrClear) +#define kr_hwerrmask KREG_IDX(HwErrMask) +#define kr_hwerrstatus KREG_IDX(HwErrStatus) +#define kr_ibcstatus KREG_IDX(IBCStatus) +#define kr_ibserdesctrl KREG_IDX(IBSerDesCtrl) +#define kr_scratch KREG_IDX(Scratch) +#define kr_xgxs_cfg KREG_IDX(XGXSCfg) +/* these are used only here, not in qib_iba7220.c */ +#define kr_ibsd_epb_access_ctrl KREG_IDX(ibsd_epb_access_ctrl) +#define kr_ibsd_epb_transaction_reg KREG_IDX(ibsd_epb_transaction_reg) +#define kr_pciesd_epb_transaction_reg KREG_IDX(pciesd_epb_transaction_reg) +#define kr_pciesd_epb_access_ctrl KREG_IDX(pciesd_epb_access_ctrl) +#define kr_serdes_ddsrxeq0 KREG_IDX(SerDes_DDSRXEQ0) + +/* +* The IBSerDesMappTable is a memory that holds values to be stored in +* various SerDes registers by IBC. +*/ +#define kr_serdes_maptable KREG_IDX(IBSerDesMappTable) + +/* +* Below used for sdnum parameter, selecting one of the two sections +* used for PCIe, or the single SerDes used for IB. +*/ +#define PCIE_SERDES0 0 +#define PCIE_SERDES1 1 + +/* +* The EPB requires addressing in a particular form. EPB_LOC() is intended +* to make #definitions a little more readable. +*/ +#define EPB_ADDR_SHF 8 +#define EPB_LOC (chn, elt, reg) \ + (((elt & 0xf) | ((chn & 7) << 4) | ((reg & 0x3f) << 9)) << \ + EPB_ADDR_SHF) +#define EPB_IB_QUAD0_CS_SHF (25) +#define EPB_IB_QUAD0_CS (1U << EPB_IB_QUAD0_CS_SHF) +#define EPB_IB_UC_CS_SHF (26) +#define EPB_PCIE_UC_CS_SHF (27) +#define EPB_GLOBAL_WR (1U << (EPB_ADDR_SHF + 8)) + +/* Forward declarations. */ +static int qib_sd7220_reg_mod (struct qib_devdata *dd,int sdnum,u32 loc, +u32 data,u32 mask); +static int ibsd_mod_allchnls (struct qib_devdata *dd,int loc,int val, +int mask); +static int qib_sd_trimdone_poll (struct qib_devdata *dd); +static void qib_sd_trimdone_monitor (struct qib_devdata *dd,const char *where); +static int qib_sd_setvals (struct qib_devdata *dd); +static int qib_sd_early (struct qib_devdata *dd); +static int qib_sd_dactrim (struct qib_devdata *dd); +static int qib_internal_presets (struct qib_devdata *dd); +/* Tweak the register (CMUCTRL5) that contains the TRIMSELF controls */ +static int qib_sd_trimself (struct qib_devdata *dd,int val); +static int epb_access (struct qib_devdata *dd,int sdnum,int claim); + +/* +* Below keeps track of whether the "once per power-on" initialization has +* been done, because uC code Version 1.32.17 or higher allows the uC to +* be reset at will, and Automatic Equalization may require it. So the +* state of the reset "pin", is no longer valid. Instead, we check for the +* actual uC code having been loaded. +*/ +static int qib_ibsd_ucode_loaded (struct qib_pportdata *ppd) +{ +struct qib_devdata *dd = ppd->dd; +if (!dd->cspec->serdes_first_init_done && (qib_sd7220_ib_vfy (dd) >0 )) + dd->cspec->serdes_first_init_done =1 ; +return dd->cspec->serdes_first_init_done; +} + +/* repeat #define for local use. "Real" #define is in qib_iba7220.c */ +#define QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR 0x0000004000000000ULL +#define IB_MPREG5 (EPB_LOC(6, 0, 0xE) | (1L << EPB_IB_UC_CS_SHF)) +#define IB_MPREG6 (EPB_LOC(6, 0, 0xF) | (1U << EPB_IB_UC_CS_SHF)) +#define UC_PAR_CLR_D 8 +#define UC_PAR_CLR_M 0xC +#define IB_CTRL2 (chn) (EPB_LOC(chn, 7, 3) | EPB_IB_QUAD0_CS) +#define START_EQ1 (chan) EPB_LOC(chan, 7, 0x27) + +void qib_sd7220_clr_ibpar (struct qib_devdata *dd) +{ +int ret; + +/* clear, then re-enable parity errs */ + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES ,IB_MPREG6 , +UC_PAR_CLR_D ,UC_PAR_CLR_M ); +if (ret <0 ) { +qib_dev_err (dd,"Failed clearing IBSerDes Parity err\n" ); + goto bail; + } + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES ,IB_MPREG6 ,0 , +UC_PAR_CLR_M ); + +qib_read_kreg32 (dd, kr_scratch); +udelay (4 ); +qib_write_kreg (dd, kr_hwerrclear, +QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR ); +qib_read_kreg32 (dd, kr_scratch); +bail: +return ; +} + +/* +* After a reset or other unusual event, the epb interface may need +* to be re-synchronized, between the host and the uC. +* returns <0 for failure to resync within IBSD_RESYNC_TRIES (not expected) +*/ +#define IBSD_RESYNC_TRIES 3 +#define IB_PGUDP (chn) (EPB_LOC((chn), 2, 1) | EPB_IB_QUAD0_CS) +#define IB_CMUDONE (chn) (EPB_LOC((chn), 7, 0xF) | EPB_IB_QUAD0_CS) + +static int qib_resync_ibepb (struct qib_devdata *dd) +{ +int ret, pat, tries, chn; +u32 loc; + + ret =-1 ; + chn =0 ; +for (tries =0 ; tries < (4 *IBSD_RESYNC_TRIES ); ++tries) { + loc =IB_PGUDP (chn); + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES , loc,0 ,0 ); +if (ret <0 ) { +qib_dev_err (dd,"Failed read in resync\n" ); +continue ; + } +if (ret !=0xF0 && ret !=0x55 && tries ==0 ) +qib_dev_err (dd,"unexpected pattern in resync\n" ); + pat = ret ^0xA5 ;/* alternate F0 and 55 */ + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES , loc, pat,0xFF ); +if (ret <0 ) { +qib_dev_err (dd,"Failed write in resync\n" ); +continue ; + } + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES , loc,0 ,0 ); +if (ret <0 ) { +qib_dev_err (dd,"Failed re-read in resync\n" ); +continue ; + } +if (ret != pat) { +qib_dev_err (dd,"Failed compare1 in resync\n" ); +continue ; + } + loc =IB_CMUDONE (chn); + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES , loc,0 ,0 ); +if (ret <0 ) { +qib_dev_err (dd,"Failed CMUDONE rd in resync\n" ); +continue ; + } +if ((ret &0x70 ) != ((chn <<4 ) |0x40 )) { +qib_dev_err (dd,"Bad CMUDONE value %02X, chn %d\n" , + ret, chn); +continue ; + } +if (++chn ==4 ) +break ;/* Success */ + } +return (ret >0 ) ?0 : ret; +} + +/* +* Localize the stuff that should be done to change IB uC reset +* returns <0 for errors. +*/ +static int qib_ibsd_reset (struct qib_devdata *dd,int assert_rst) +{ +u64 rst_val; +int ret =0 ; +unsigned long flags; + + rst_val =qib_read_kreg64 (dd, kr_ibserdesctrl); +if (assert_rst) { +/* +* Vendor recommends "interrupting" uC before reset, to +* minimize possible glitches. +*/ +spin_lock_irqsave (&dd->cspec->sdepb_lock, flags); +epb_access (dd,IB_7220_SERDES ,1 ); + rst_val |=1ULL ; +/* Squelch possible parity error from _asserting_ reset */ +qib_write_kreg (dd, kr_hwerrmask, + dd->cspec->hwerrmask & + ~QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR ); +qib_write_kreg (dd, kr_ibserdesctrl, rst_val); +/* flush write, delay to ensure it took effect */ +qib_read_kreg32 (dd, kr_scratch); +udelay (2 ); +/* once it's reset, can remove interrupt */ +epb_access (dd,IB_7220_SERDES ,-1 ); +spin_unlock_irqrestore (&dd->cspec->sdepb_lock, flags); + }else { +/* +* Before we de-assert reset, we need to deal with +* possible glitch on the Parity-error line. +* Suppress it around the reset, both in chip-level +* hwerrmask and in IB uC control reg. uC will allow +* it again during startup. +*/ +u64 val; + rst_val &= ~(1ULL ); +qib_write_kreg (dd, kr_hwerrmask, + dd->cspec->hwerrmask & + ~QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR ); + + ret =qib_resync_ibepb (dd); +if (ret <0 ) +qib_dev_err (dd,"unable to re-sync IB EPB\n" ); + +/* set uC control regs to suppress parity errs */ + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES ,IB_MPREG5 ,1 ,1 ); +if (ret <0 ) + goto bail; +/* IB uC code past Version 1.32.17 allow suppression of wdog */ + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES ,IB_MPREG6 ,0x80 , +0x80 ); +if (ret <0 ) { +qib_dev_err (dd,"Failed to set WDOG disable\n" ); + goto bail; + } +qib_write_kreg (dd, kr_ibserdesctrl, rst_val); +/* flush write, delay for startup */ +qib_read_kreg32 (dd, kr_scratch); +udelay (1 ); +/* clear, then re-enable parity errs */ +qib_sd7220_clr_ibpar (dd); + val =qib_read_kreg64 (dd, kr_hwerrstatus); +if (val &QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR ) { +qib_dev_err (dd,"IBUC Parity still set after RST\n" ); + dd->cspec->hwerrmask &= + ~QLOGIC_IB_HWE_IB_UC_MEMORYPARITYERR ; + } +qib_write_kreg (dd, kr_hwerrmask, + dd->cspec->hwerrmask); + } + +bail: +return ret; +} + +static void qib_sd_trimdone_monitor (struct qib_devdata *dd, +const char *where) +{ +int ret, chn, baduns; +u64 val; + +if (!where) + where ="?" ; + +/* give time for reset to settle out in EPB */ +udelay (2 ); + + ret =qib_resync_ibepb (dd); +if (ret <0 ) +qib_dev_err (dd,"not able to re-sync IB EPB (%s)\n" , where); + +/* Do "sacrificial read" to get EPB in sane state after reset */ + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES ,IB_CTRL2 (0 ),0 ,0 ); +if (ret <0 ) +qib_dev_err (dd,"Failed TRIMDONE 1st read, (%s)\n" , where); + +/* Check/show "summary" Trim-done bit in IBCStatus */ + val =qib_read_kreg64 (dd, kr_ibcstatus); +if (!(val & (1ULL <<11 ))) +qib_dev_err (dd,"IBCS TRIMDONE clear (%s)\n" , where); +/* +* Do "dummy read/mod/wr" to get EPB in sane state after reset +* The default value for MPREG6 is 0. +*/ +udelay (2 ); + + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES ,IB_MPREG6 ,0x80 ,0x80 ); +if (ret <0 ) +qib_dev_err (dd,"Failed Dummy RMW, (%s)\n" , where); +udelay (10 ); + + baduns =0 ; + +for (chn =3 ; chn >=0 ; --chn) { +/* Read CTRL reg for each channel to check TRIMDONE */ + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES , +IB_CTRL2 (chn),0 ,0 ); +if (ret <0 ) +qib_dev_err (dd,"Failed checking TRIMDONE, chn %d" +" (%s)\n" , chn, where); + +if (!(ret &0x10 )) { +int probe; + + baduns |= (1 << chn); +qib_dev_err (dd,"TRIMDONE cleared on chn %d (%02X)." +" (%s)\n" , chn, ret, where); + probe =qib_sd7220_reg_mod (dd,IB_7220_SERDES , +IB_PGUDP (0 ),0 ,0 ); +qib_dev_err (dd,"probe is %d (%02X)\n" , + probe, probe); + probe =qib_sd7220_reg_mod (dd,IB_7220_SERDES , +IB_CTRL2 (chn),0 ,0 ); +qib_dev_err (dd,"re-read: %d (%02X)\n" , + probe, probe); + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES , +IB_CTRL2 (chn),0x10 ,0x10 ); +if (ret <0 ) +qib_dev_err (dd, +"Err on TRIMDONE rewrite1\n" ); + } + } +for (chn =3 ; chn >=0 ; --chn) { +/* Read CTRL reg for each channel to check TRIMDONE */ +if (baduns & (1 << chn)) { +qib_dev_err (dd, +"Reseting TRIMDONE on chn %d (%s)\n" , + chn, where); + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES , +IB_CTRL2 (chn),0x10 ,0x10 ); +if (ret <0 ) +qib_dev_err (dd,"Failed re-setting " +"TRIMDONE, chn %d (%s)\n" , + chn, where); + } + } +} + +/* +* Below is portion of IBA7220-specific bringup_serdes() that actually +* deals with registers and memory within the SerDes itself. +* Post IB uC code version 1.32.17, was_reset being 1 is not really +* informative, so we double-check. +*/ +int qib_sd7220_init (struct qib_devdata *dd) +{ +int ret =1 ;/* default to failure */ +int first_reset, was_reset; + +/* SERDES MPU reset recorded in D0 */ + was_reset = (qib_read_kreg64 (dd, kr_ibserdesctrl) &1 ); +if (!was_reset) { +/* entered with reset not asserted, we need to do it */ +qib_ibsd_reset (dd,1 ); +qib_sd_trimdone_monitor (dd,"Driver-reload" ); + } +/* Substitute our deduced value for was_reset */ + ret =qib_ibsd_ucode_loaded (dd->pport); +if (ret <0 ) + goto bail; + + first_reset = !ret;/* First reset if IBSD uCode not yet loaded */ +/* +* Alter some regs per vendor latest doc, reset-defaults +* are not right for IB. +*/ + ret =qib_sd_early (dd); +if (ret <0 ) { +qib_dev_err (dd,"Failed to set IB SERDES early defaults\n" ); + goto bail; + } +/* +* Set DAC manual trim IB. +* We only do this once after chip has been reset (usually +* same as once per system boot). +*/ +if (first_reset) { + ret =qib_sd_dactrim (dd); +if (ret <0 ) { +qib_dev_err (dd,"Failed IB SERDES DAC trim\n" ); + goto bail; + } + } +/* +* Set various registers (DDS and RXEQ) that will be +* controlled by IBC (in 1.2 mode) to reasonable preset values +* Calling the "internal" version avoids the "check for needed" +* and "trimdone monitor" that might be counter-productive. +*/ + ret =qib_internal_presets (dd); +if (ret <0 ) { +qib_dev_err (dd,"Failed to set IB SERDES presets\n" ); + goto bail; + } + ret =qib_sd_trimself (dd,0x80 ); +if (ret <0 ) { +qib_dev_err (dd,"Failed to set IB SERDES TRIMSELF\n" ); + goto bail; + } + +/* Load image, then try to verify */ + ret =0 ;/* Assume success */ +if (first_reset) { +int vfy; +int trim_done; + + ret =qib_sd7220_ib_load (dd); +if (ret <0 ) { +qib_dev_err (dd,"Failed to load IB SERDES image\n" ); + goto bail; + }else { +/* Loaded image, try to verify */ + vfy =qib_sd7220_ib_vfy (dd); +if (vfy != ret) { +qib_dev_err (dd,"SERDES PRAM VFY failed\n" ); + goto bail; + }/* end if verified */ + }/* end if loaded */ + +/* +* Loaded and verified. Almost good... +* hold "success" in ret +*/ + ret =0 ; +/* +* Prev steps all worked, continue bringup +* De-assert RESET to uC, only in first reset, to allow +* trimming. +* +* Since our default setup sets START_EQ1 to +* PRESET, we need to clear that for this very first run. +*/ + ret =ibsd_mod_allchnls (dd,START_EQ1 (0 ),0 ,0x38 ); +if (ret <0 ) { +qib_dev_err (dd,"Failed clearing START_EQ1\n" ); + goto bail; + } + +qib_ibsd_reset (dd,0 ); +/* +* If this is not the first reset, trimdone should be set +* already. We may need to check about this. +*/ + trim_done =qib_sd_trimdone_poll (dd); +/* +* Whether or not trimdone succeeded, we need to put the +* uC back into reset to avoid a possible fight with the +* IBC state-machine. +*/ +qib_ibsd_reset (dd,1 ); + +if (!trim_done) { +qib_dev_err (dd,"No TRIMDONE seen\n" ); + goto bail; + } +/* +* DEBUG: check each time we reset if trimdone bits have +* gotten cleared, and re-set them. +*/ +qib_sd_trimdone_monitor (dd,"First-reset" ); +/* Remember so we do not re-do the load, dactrim, etc. */ + dd->cspec->serdes_first_init_done =1 ; + } +/* +* setup for channel training and load values for +* RxEq and DDS in tables used by IBC in IB1.2 mode +*/ + ret =0 ; +if (qib_sd_setvals (dd) >=0 ) + goto done; +bail: + ret =1 ; +done: +/* start relock timer regardless, but start at 1 second */ +set_7220_relock_poll (dd,-1 ); +return ret; +} + +#define EPB_ACC_REQ 1 +#define EPB_ACC_GNT 0x100 +#define EPB_DATA_MASK 0xFF +#define EPB_RD (1ULL << 24) +#define EPB_TRANS_RDY (1ULL << 31) +#define EPB_TRANS_ERR (1ULL << 30) +#define EPB_TRANS_TRIES 5 + +/* +* query, claim, release ownership of the EPB (External Parallel Bus) +* for a specified SERDES. +* the "claim" parameter is >0 to claim, <0 to release, 0 to query. +* Returns <0 for errors, >0 if we had ownership, else 0. +*/ +static int epb_access (struct qib_devdata *dd,int sdnum,int claim) +{ +u16 acc; +u64 accval; +int owned =0 ; +u64 oct_sel =0 ; + +switch (sdnum) { +case IB_7220_SERDES : +/* +* The IB SERDES "ownership" is fairly simple. A single each +* request/grant. +*/ + acc = kr_ibsd_epb_access_ctrl; +break ; + +case PCIE_SERDES0 : +case PCIE_SERDES1 : +/* PCIe SERDES has two "octants", need to select which */ + acc = kr_pciesd_epb_access_ctrl; + oct_sel = (2 << (sdnum -PCIE_SERDES0 )); +break ; + +default : +return 0 ; + } + +/* Make sure any outstanding transaction was seen */ +qib_read_kreg32 (dd, kr_scratch); +udelay (15 ); + + accval =qib_read_kreg32 (dd, acc); + + owned = !!(accval &EPB_ACC_GNT ); +if (claim <0 ) { +/* Need to release */ +u64 pollval; +/* +* The only writeable bits are the request and CS. +* Both should be clear +*/ +u64 newval =0 ; +qib_write_kreg (dd, acc, newval); +/* First read after write is not trustworthy */ + pollval =qib_read_kreg32 (dd, acc); +udelay (5 ); + pollval =qib_read_kreg32 (dd, acc); +if (pollval &EPB_ACC_GNT ) + owned =-1 ; + }else if (claim >0 ) { +/* Need to claim */ +u64 pollval; +u64 newval =EPB_ACC_REQ | oct_sel; +qib_write_kreg (dd, acc, newval); +/* First read after write is not trustworthy */ + pollval =qib_read_kreg32 (dd, acc); +udelay (5 ); + pollval =qib_read_kreg32 (dd, acc); +if (!(pollval &EPB_ACC_GNT )) + owned =-1 ; + } +return owned; +} + +/* +* Lemma to deal with race condition of write..read to epb regs +*/ +static int epb_trans (struct qib_devdata *dd,u16 reg,u64 i_val,u64 *o_vp) +{ +int tries; +u64 transval; + +qib_write_kreg (dd, reg, i_val); +/* Throw away first read, as RDY bit may be stale */ + transval =qib_read_kreg64 (dd, reg); + +for (tries =EPB_TRANS_TRIES ; tries; --tries) { + transval =qib_read_kreg32 (dd, reg); +if (transval &EPB_TRANS_RDY ) +break ; +udelay (5 ); + } +if (transval &EPB_TRANS_ERR ) +return -1 ; +if (tries >0 && o_vp) + *o_vp = transval; +return tries; +} + +/** +* qib_sd7220_reg_mod - modify SERDES register +* @dd: the qlogic_ib device +* @sdnum: which SERDES to access +* @loc: location - channel, element, register, as packed by EPB_LOC() macro. +* @wd: Write Data - value to set in register +* @mask: ones where data should be spliced into reg. +* +* Basic register read/modify/write, with un-needed acesses elided. That is, +* a mask of zero will prevent write, while a mask of 0xFF will prevent read. +* returns current (presumed, if a write was done) contents of selected +* register, or <0 if errors. +*/ +static int qib_sd7220_reg_mod (struct qib_devdata *dd,int sdnum,u32 loc, +u32 wd,u32 mask) +{ +u16 trans; +u64 transval; +int owned; +int tries, ret; +unsigned long flags; + +switch (sdnum) { +case IB_7220_SERDES : + trans = kr_ibsd_epb_transaction_reg; +break ; + +case PCIE_SERDES0 : +case PCIE_SERDES1 : + trans = kr_pciesd_epb_transaction_reg; +break ; + +default : +return -1 ; + } + +/* +* All access is locked in software (vs other host threads) and +* hardware (vs uC access). +*/ +spin_lock_irqsave (&dd->cspec->sdepb_lock, flags); + + owned =epb_access (dd, sdnum,1 ); +if (owned <0 ) { +spin_unlock_irqrestore (&dd->cspec->sdepb_lock, flags); +return -1 ; + } + ret =0 ; +for (tries =EPB_TRANS_TRIES ; tries; --tries) { + transval =qib_read_kreg32 (dd, trans); +if (transval &EPB_TRANS_RDY ) +break ; +udelay (5 ); + } + +if (tries >0 ) { + tries =1 ;/* to make read-skip work */ +if (mask !=0xFF ) { +/* +* Not a pure write, so need to read. +* loc encodes chip-select as well as address +*/ + transval = loc |EPB_RD ; + tries =epb_trans (dd, trans, transval, &transval); + } +if (tries >0 && mask !=0 ) { +/* +* Not a pure read, so need to write. +*/ + wd = (wd & mask) | (transval & ~mask); + transval = loc | (wd &EPB_DATA_MASK ); + tries =epb_trans (dd, trans, transval, &transval); + } + } +/* else, failed to see ready, what error-handling? */ + +/* +* Release bus. Failure is an error. +*/ +if (epb_access (dd, sdnum,-1 ) <0 ) + ret =-1 ; +else + ret = transval &EPB_DATA_MASK ; + +spin_unlock_irqrestore (&dd->cspec->sdepb_lock, flags); +if (tries <=0 ) + ret =-1 ; +return ret; +} + +#define EPB_ROM_R (2) +#define EPB_ROM_W (1) +/* +* Below, all uC-related, use appropriate UC_CS, depending +* on which SerDes is used. +*/ +#define EPB_UC_CTL EPB_LOC(6, 0, 0) +#define EPB_MADDRL EPB_LOC(6, 0, 2) +#define EPB_MADDRH EPB_LOC(6, 0, 3) +#define EPB_ROMDATA EPB_LOC(6, 0, 4) +#define EPB_RAMDATA EPB_LOC(6, 0, 5) + +/* Transfer date to/from uC Program RAM of IB or PCIe SerDes */ +static int qib_sd7220_ram_xfer (struct qib_devdata *dd,int sdnum,u32 loc, +u8 *buf,int cnt,int rd_notwr) +{ +u16 trans; +u64 transval; +u64 csbit; +int owned; +int tries; +int sofar; +int addr; +int ret; +unsigned long flags; +const char *op; + +/* Pick appropriate transaction reg and "Chip select" for this serdes */ +switch (sdnum) { +case IB_7220_SERDES : + csbit =1ULL <<EPB_IB_UC_CS_SHF ; + trans = kr_ibsd_epb_transaction_reg; +break ; + +case PCIE_SERDES0 : +case PCIE_SERDES1 : +/* PCIe SERDES has uC "chip select" in different bit, too */ + csbit =1ULL <<EPB_PCIE_UC_CS_SHF ; + trans = kr_pciesd_epb_transaction_reg; +break ; + +default : +return -1 ; + } + + op = rd_notwr ?"Rd" :"Wr" ; +spin_lock_irqsave (&dd->cspec->sdepb_lock, flags); + + owned =epb_access (dd, sdnum,1 ); +if (owned <0 ) { +spin_unlock_irqrestore (&dd->cspec->sdepb_lock, flags); +return -1 ; + } + +/* +* In future code, we may need to distinguish several address ranges, +* and select various memories based on this. For now, just trim +* "loc" (location including address and memory select) to +* "addr" (address within memory). we will only support PRAM +* The memory is 8KB. +*/ + addr = loc &0x1FFF ; +for (tries =EPB_TRANS_TRIES ; tries; --tries) { + transval =qib_read_kreg32 (dd, trans); +if (transval &EPB_TRANS_RDY ) +break ; +udelay (5 ); + } + + sofar =0 ; +if (tries >0 ) { +/* +* Every "memory" access is doubly-indirect. +* We set two bytes of address, then read/write +* one or mores bytes of data. +*/ + +/* First, we set control to "Read" or "Write" */ + transval = csbit |EPB_UC_CTL | + (rd_notwr ?EPB_ROM_R :EPB_ROM_W ); + tries =epb_trans (dd, trans, transval, &transval); +while (tries >0 && sofar < cnt) { +if (!sofar) { +/* Only set address at start of chunk */ +int addrbyte = (addr + sofar) >>8 ; + transval = csbit |EPB_MADDRH | addrbyte; + tries =epb_trans (dd, trans, transval, + &transval); +if (tries <=0 ) +break ; + addrbyte = (addr + sofar) &0xFF ; + transval = csbit |EPB_MADDRL | addrbyte; + tries =epb_trans (dd, trans, transval, + &transval); +if (tries <=0 ) +break ; + } + +if (rd_notwr) + transval = csbit |EPB_ROMDATA |EPB_RD ; +else + transval = csbit |EPB_ROMDATA | buf[sofar]; + tries =epb_trans (dd, trans, transval, &transval); +if (tries <=0 ) +break ; +if (rd_notwr) + buf[sofar] = transval &EPB_DATA_MASK ; + ++sofar; + } +/* Finally, clear control-bit for Read or Write */ + transval = csbit |EPB_UC_CTL ; + tries =epb_trans (dd, trans, transval, &transval); + } + + ret = sofar; +/* Release bus. Failure is an error */ +if (epb_access (dd, sdnum,-1 ) <0 ) + ret =-1 ; + +spin_unlock_irqrestore (&dd->cspec->sdepb_lock, flags); +if (tries <=0 ) + ret =-1 ; +return ret; +} + +#define PROG_CHUNK 64 + +int qib_sd7220_prog_ld (struct qib_devdata *dd,int sdnum, +u8 *img,int len,int offset) +{ +int cnt, sofar, req; + + sofar =0 ; +while (sofar < len) { + req = len - sofar; +if (req >PROG_CHUNK ) + req =PROG_CHUNK ; + cnt =qib_sd7220_ram_xfer (dd, sdnum, offset + sofar, + img + sofar, req,0 ); +if (cnt < req) { + sofar =-1 ; +break ; + } + sofar += req; + } +return sofar; +} + +#define VFY_CHUNK 64 +#define SD_PRAM_ERROR_LIMIT 42 + +int qib_sd7220_prog_vfy (struct qib_devdata *dd,int sdnum, +const u8 *img,int len,int offset) +{ +int cnt, sofar, req, idx, errors; +unsigned char readback[VFY_CHUNK ]; + + errors =0 ; + sofar =0 ; +while (sofar < len) { + req = len - sofar; +if (req >VFY_CHUNK ) + req =VFY_CHUNK ; + cnt =qib_sd7220_ram_xfer (dd, sdnum, sofar + offset, + readback, req,1 ); +if (cnt < req) { +/* failed in read itself */ + sofar =-1 ; +break ; + } +for (idx =0 ; idx < cnt; ++idx) { +if (readback[idx] != img[idx+sofar]) + ++errors; + } + sofar += cnt; + } +return errors ? -errors : sofar; +} + +/* +* IRQ not set up at this point in init, so we poll. +*/ +#define IB_SERDES_TRIM_DONE (1ULL << 11) +#define TRIM_TMO (30) + +static int qib_sd_trimdone_poll (struct qib_devdata *dd) +{ +int trim_tmo, ret; +uint64_t val; + +/* +* Default to failure, so IBC will not start +* without IB_SERDES_TRIM_DONE. +*/ + ret =0 ; +for (trim_tmo =0 ; trim_tmo <TRIM_TMO ; ++trim_tmo) { + val =qib_read_kreg64 (dd, kr_ibcstatus); +if (val &IB_SERDES_TRIM_DONE ) { + ret =1 ; +break ; + } +msleep (10 ); + } +if (trim_tmo >=TRIM_TMO ) { +qib_dev_err (dd,"No TRIMDONE in %d tries\n" , trim_tmo); + ret =0 ; + } +return ret; +} + +#define TX_FAST_ELT (9) + +/* +* Set the "negotiation" values for SERDES. These are used by the IB1.2 +* link negotiation. Macros below are attempt to keep the values a +* little more human-editable. +* First, values related to Drive De-emphasis Settings. +*/ + +#define NUM_DDS_REGS 6 +#define DDS_REG_MAP 0x76A910/* LSB-first list of regs (in elt 9) to mod */ + +#define DDS_VAL (amp_d, main_d, ipst_d, ipre_d, amp_s, main_s, ipst_s, ipre_s) \ + { { ((amp_d & 0x1F) << 1) | 1, ((amp_s & 0x1F) << 1) | 1, \ + (main_d << 3) | 4 | (ipre_d >> 2), \ + (main_s << 3) | 4 | (ipre_s >> 2), \ + ((ipst_d & 0xF) << 1) | ((ipre_d & 3) << 6) | 0x21, \ + ((ipst_s & 0xF) << 1) | ((ipre_s & 3) << 6) | 0x21 } } + +static struct dds_init { +uint8_t reg_vals[NUM_DDS_REGS ]; +} dds_init_vals[] = { +/* DDR(FDR) SDR(HDR) */ +/* Vendor recommends below for 3m cable */ +#define DDS_3M 0 +DDS_VAL (31 ,19 ,12 ,0 ,29 ,22 ,9 ,0 ), +DDS_VAL (31 ,12 ,15 ,4 ,31 ,15 ,15 ,1 ), +DDS_VAL (31 ,13 ,15 ,3 ,31 ,16 ,15 ,0 ), +DDS_VAL (31 ,14 ,15 ,2 ,31 ,17 ,14 ,0 ), +DDS_VAL (31 ,15 ,15 ,1 ,31 ,18 ,13 ,0 ), +DDS_VAL (31 ,16 ,15 ,0 ,31 ,19 ,12 ,0 ), +DDS_VAL (31 ,17 ,14 ,0 ,31 ,20 ,11 ,0 ), +DDS_VAL (31 ,18 ,13 ,0 ,30 ,21 ,10 ,0 ), +DDS_VAL (31 ,20 ,11 ,0 ,28 ,23 ,8 ,0 ), +DDS_VAL (31 ,21 ,10 ,0 ,27 ,24 ,7 ,0 ), +DDS_VAL (31 ,22 ,9 ,0 ,26 ,25 ,6 ,0 ), +DDS_VAL (30 ,23 ,8 ,0 ,25 ,26 ,5 ,0 ), +DDS_VAL (29 ,24 ,7 ,0 ,23 ,27 ,4 ,0 ), +/* Vendor recommends below for 1m cable */ +#define DDS_1M 13 +DDS_VAL (28 ,25 ,6 ,0 ,21 ,28 ,3 ,0 ), +DDS_VAL (27 ,26 ,5 ,0 ,19 ,29 ,2 ,0 ), +DDS_VAL (25 ,27 ,4 ,0 ,17 ,30 ,1 ,0 ) +}; + +/* +* Now the RXEQ section of the table. +*/ +/* Hardware packs an element number and register address thus: */ +#define RXEQ_INIT_RDESC (elt, addr) (((elt) & 0xF) | ((addr) << 4)) +#define RXEQ_VAL (elt, adr, val0, val1, val2, val3) \ + {RXEQ_INIT_RDESC((elt), (adr)), {(val0), (val1), (val2), (val3)} } + +#define RXEQ_VAL_ALL (elt, adr, val) \ + {RXEQ_INIT_RDESC((elt), (adr)), {(val), (val), (val), (val)} } + +#define RXEQ_SDR_DFELTH 0 +#define RXEQ_SDR_TLTH 0 +#define RXEQ_SDR_G1CNT_Z1CNT 0x11 +#define RXEQ_SDR_ZCNT 23 + +static struct rxeq_init { +u16 rdesc;/* in form used in SerDesDDSRXEQ */ +u8 rdata[4 ]; +} rxeq_init_vals[] = { +/* Set Rcv Eq. to Preset node */ +RXEQ_VAL_ALL (7 ,0x27 ,0x10 ), +/* Set DFELTHFDR/HDR thresholds */ +RXEQ_VAL (7 ,8 ,0 ,0 ,0 ,0 ),/* FDR, was 0, 1, 2, 3 */ +RXEQ_VAL (7 ,0x21 ,0 ,0 ,0 ,0 ),/* HDR */ +/* Set TLTHFDR/HDR theshold */ +RXEQ_VAL (7 ,9 ,2 ,2 ,2 ,2 ),/* FDR, was 0, 2, 4, 6 */ +RXEQ_VAL (7 ,0x23 ,2 ,2 ,2 ,2 ),/* HDR, was 0, 1, 2, 3 */ +/* Set Preamp setting 2 (ZFR/ZCNT) */ +RXEQ_VAL (7 ,0x1B ,12 ,12 ,12 ,12 ),/* FDR, was 12, 16, 20, 24 */ +RXEQ_VAL (7 ,0x1C ,12 ,12 ,12 ,12 ),/* HDR, was 12, 16, 20, 24 */ +/* Set Preamp DC gain and Setting 1 (GFR/GHR) */ +RXEQ_VAL (7 ,0x1E ,16 ,16 ,16 ,16 ),/* FDR, was 16, 17, 18, 20 */ +RXEQ_VAL (7 ,0x1F ,16 ,16 ,16 ,16 ),/* HDR, was 16, 17, 18, 20 */ +/* Toggle RELOCK (in VCDL_CTRL0) to lock to data */ +RXEQ_VAL_ALL (6 ,6 ,0x20 ),/* Set D5 High */ +RXEQ_VAL_ALL (6 ,6 ,0 ),/* Set D5 Low */ +}; + +/* There are 17 values from vendor, but IBC only accesses the first 16 */ +#define DDS_ROWS (16) +#define RXEQ_ROWS ARRAY_SIZE(rxeq_init_vals) + +static int qib_sd_setvals (struct qib_devdata *dd) +{ +int idx, midx; +int min_idx;/* Minimum index for this portion of table */ +uint32_t dds_reg_map; +u64 __iomem *taddr, *iaddr; +uint64_t data; +uint64_t sdctl; + + taddr = dd->kregbase + kr_serdes_maptable; + iaddr = dd->kregbase + kr_serdes_ddsrxeq0; + +/* +* Init the DDS section of the table. +* Each "row" of the table provokes NUM_DDS_REG writes, to the +* registers indicated in DDS_REG_MAP. +*/ + sdctl =qib_read_kreg64 (dd, kr_ibserdesctrl); + sdctl = (sdctl & ~(0x1f <<8 )) | (NUM_DDS_REGS <<8 ); + sdctl = (sdctl & ~(0x1f <<13 )) | (RXEQ_ROWS <<13 ); +qib_write_kreg (dd, kr_ibserdesctrl, sdctl); + +/* +* Iterate down table within loop for each register to store. +*/ + dds_reg_map =DDS_REG_MAP ; +for (idx =0 ; idx <NUM_DDS_REGS ; ++idx) { + data = ((dds_reg_map &0xF ) <<4 ) |TX_FAST_ELT ; +writeq (data, iaddr + idx); +mmiowb (); +qib_read_kreg32 (dd, kr_scratch); + dds_reg_map >>=4 ; +for (midx =0 ; midx <DDS_ROWS ; ++midx) { +u64 __iomem *daddr = taddr + ((midx <<4 ) + idx); + data = dds_init_vals[midx].reg_vals[idx]; +writeq (data, daddr); +mmiowb (); +qib_read_kreg32 (dd, kr_scratch); + }/* End inner for (vals for this reg, each row) */ + }/* end outer for (regs to be stored) */ + +/* +* Init the RXEQ section of the table. +* This runs in a different order, as the pattern of +* register references is more complex, but there are only +* four "data" values per register. +*/ + min_idx = idx;/* RXEQ indices pick up where DDS left off */ + taddr +=0x100 ;/* RXEQ data is in second half of table */ +/* Iterate through RXEQ register addresses */ +for (idx =0 ; idx <RXEQ_ROWS ; ++idx) { +int didx;/* "destination" */ +int vidx; + +/* didx is offset by min_idx to address RXEQ range of regs */ + didx = idx + min_idx; +/* Store the next RXEQ register address */ +writeq (rxeq_init_vals[idx].rdesc, iaddr + didx); +mmiowb (); +qib_read_kreg32 (dd, kr_scratch); +/* Iterate through RXEQ values */ +for (vidx =0 ; vidx <4 ; vidx++) { + data = rxeq_init_vals[idx].rdata[vidx]; +writeq (data, taddr + (vidx <<6 ) + idx); +mmiowb (); +qib_read_kreg32 (dd, kr_scratch); + } + }/* end outer for (Reg-writes for RXEQ) */ +return 0 ; +} + +#define CMUCTRL5 EPB_LOC(7, 0, 0x15) +#define RXHSCTRL0 (chan) EPB_LOC(chan, 6, 0) +#define VCDL_DAC2 (chan) EPB_LOC(chan, 6, 5) +#define VCDL_CTRL0 (chan) EPB_LOC(chan, 6, 6) +#define VCDL_CTRL2 (chan) EPB_LOC(chan, 6, 8) +#define START_EQ2 (chan) EPB_LOC(chan, 7, 0x28) + +/* +* Repeat a "store" across all channels of the IB SerDes. +* Although nominally it inherits the "read value" of the last +* channel it modified, the only really useful return is <0 for +* failure, >= 0 for success. The parameter 'loc' is assumed to +* be the location in some channel of the register to be modified +* The caller can specify use of the "gang write" option of EPB, +* in which case we use the specified channel data for any fields +* not explicitely written. +*/ +static int ibsd_mod_allchnls (struct qib_devdata *dd,int loc,int val, +int mask) +{ +int ret =-1 ; +int chnl; + +if (loc &EPB_GLOBAL_WR ) { +/* +* Our caller has assured us that we can set all four +* channels at once. Trust that. If mask is not 0xFF, +* we will read the _specified_ channel for our starting +* value. +*/ + loc |= (1U <<EPB_IB_QUAD0_CS_SHF ); + chnl = (loc >> (4 +EPB_ADDR_SHF )) &7 ; +if (mask !=0xFF ) { + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES , + loc & ~EPB_GLOBAL_WR ,0 ,0 ); +if (ret <0 ) { +int sloc = loc >>EPB_ADDR_SHF ; + +qib_dev_err (dd,"pre-read failed: elt %d," +" addr 0x%X, chnl %d\n" , + (sloc &0xF ), + (sloc >>9 ) &0x3f , chnl); +return ret; + } + val = (ret & ~mask) | (val & mask); + } + loc &= ~(7 << (4 +EPB_ADDR_SHF )); + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES , loc, val,0xFF ); +if (ret <0 ) { +int sloc = loc >>EPB_ADDR_SHF ; + +qib_dev_err (dd,"Global WR failed: elt %d," +" addr 0x%X, val %02X\n" , + (sloc &0xF ), (sloc >>9 ) &0x3f , val); + } +return ret; + } +/* Clear "channel" and set CS so we can simply iterate */ + loc &= ~(7 << (4 +EPB_ADDR_SHF )); + loc |= (1U <<EPB_IB_QUAD0_CS_SHF ); +for (chnl =0 ; chnl <4 ; ++chnl) { +int cloc = loc | (chnl << (4 +EPB_ADDR_SHF )); + + ret =qib_sd7220_reg_mod (dd,IB_7220_SERDES , cloc, val, mask); +if (ret <0 ) { +int sloc = loc >>EPB_ADDR_SHF ; + +qib_dev_err (dd,"Write failed: elt %d," +" addr 0x%X, chnl %d, val 0x%02X," +" mask 0x%02X\n" , + (sloc &0xF ), (sloc >>9 ) &0x3f , chnl, + val &0xFF , mask &0xFF ); +break ; + } + } +return ret; +} + +/* +* Set the Tx values normally modified by IBC in IB1.2 mode to default +* values, as gotten from first row of init table. +*/ +static int set_dds_vals (struct qib_devdata *dd,struct dds_init *ddi) +{ +int ret; +int idx, reg, data; +uint32_t regmap; + + regmap =DDS_REG_MAP ; +for (idx =0 ; idx <NUM_DDS_REGS ; ++idx) { + reg = (regmap &0xF ); + regmap >>=4 ; + data = ddi->reg_vals[idx]; +/* Vendor says RMW not needed for these regs, use 0xFF mask */ + ret =ibsd_mod_allchnls (dd,EPB_LOC (0 ,9 , reg), data,0xFF ); +if (ret <0 ) +break ; + } +return ret; +} + +/* +* Set the Rx values normally modified by IBC in IB1.2 mode to default +* values, as gotten from selected column of init table. +*/ +static int set_rxeq_vals (struct qib_devdata *dd,int vsel) +{ +int ret; +int ridx; +int cnt =ARRAY_SIZE (rxeq_init_vals); + +for (ridx =0 ; ridx < cnt; ++ridx) { +int elt, reg, val, loc; + + elt = rxeq_init_vals[ridx].rdesc &0xF ; + reg = rxeq_init_vals[ridx].rdesc >>4 ; + loc =EPB_LOC (0 , elt, reg); + val = rxeq_init_vals[ridx].rdata[vsel]; +/* mask of 0xFF, because hardware does full-byte store. */ + ret =ibsd_mod_allchnls (dd, loc, val,0xFF ); +if (ret <0 ) +break ; + } +return ret; +} + +/* +* Set the default values (row 0) for DDR Driver Demphasis. +* we do this initially and whenever we turn off IB-1.2 +* +* The "default" values for Rx equalization are also stored to +* SerDes registers. Formerly (and still default), we used set 2. +* For experimenting with cables and link-partners, we allow changing +* that via a module parameter. +*/ +static unsigned qib_rxeq_set =2 ; +module_param_named (rxeq_default_set, qib_rxeq_set, uint, +S_IWUSR |S_IRUGO ); +MODULE_PARM_DESC (rxeq_default_set, +"Which set [0..3] of Rx Equalization values is default" ); + +static int qib_internal_presets (struct qib_devdata *dd) +{ +int ret =0 ; + + ret =set_dds_vals (dd, dds_init_vals +DDS_3M ); + +if (ret <0 ) +qib_dev_err (dd,"Failed to set default DDS values\n" ); + ret =set_rxeq_vals (dd, qib_rxeq_set &3 ); +if (ret <0 ) +qib_dev_err (dd,"Failed to set default RXEQ values\n" ); +return ret; +} + +int qib_sd7220_presets (struct qib_devdata *dd) +{ +int ret =0 ; + +if (!dd->cspec->presets_needed) +return ret; + dd->cspec->presets_needed =0 ; +/* Assert uC reset, so we don't clash with it. */ +qib_ibsd_reset (dd,1 ); +udelay (2 ); +qib_sd_trimdone_monitor (dd,"link-down" ); + + ret =qib_internal_presets (dd); +return ret; +} + +static int qib_sd_trimself (struct qib_devdata *dd,int val) +{ +int loc =CMUCTRL5 | (1U <<EPB_IB_QUAD0_CS_SHF ); + +return qib_sd7220_reg_mod (dd,IB_7220_SERDES , loc, val,0xFF ); +} + +static int qib_sd_early (struct qib_devdata *dd) +{ +int ret; + + ret =ibsd_mod_allchnls (dd,RXHSCTRL0 (0 ) |EPB_GLOBAL_WR ,0xD4 ,0xFF ); +if (ret <0 ) + goto bail; + ret =ibsd_mod_allchnls (dd,START_EQ1 (0 ) |EPB_GLOBAL_WR ,0x10 ,0xFF ); +if (ret <0 ) + goto bail; + ret =ibsd_mod_allchnls (dd,START_EQ2 (0 ) |EPB_GLOBAL_WR ,0x30 ,0xFF ); +bail: +return ret; +} + +#define BACTRL (chnl) EPB_LOC(chnl, 6, 0x0E) +#define LDOUTCTRL1 (chnl) EPB_LOC(chnl, 7, 6) +#define RXHSSTATUS (chnl) EPB_LOC(chnl, 6, 0xF) + +static int qib_sd_dactrim (struct qib_devdata *dd) +{ +int ret; + + ret =ibsd_mod_allchnls (dd,VCDL_DAC2 (0 ) |EPB_GLOBAL_WR ,0x2D ,0xFF ); +if (ret <0 ) + goto bail; + +/* more fine-tuning of what will be default */ + ret =ibsd_mod_allchnls (dd,VCDL_CTRL2 (0 ),3 ,0xF ); +if (ret <0 ) + goto bail; + + ret =ibsd_mod_allchnls (dd,BACTRL (0 ) |EPB_GLOBAL_WR ,0x40 ,0xFF ); +if (ret <0 ) + goto bail; + + ret =ibsd_mod_allchnls (dd,LDOUTCTRL1 (0 ) |EPB_GLOBAL_WR ,0x04 ,0xFF ); +if (ret <0 ) + goto bail; + + ret =ibsd_mod_allchnls (dd,RXHSSTATUS (0 ) |EPB_GLOBAL_WR ,0x04 ,0xFF ); +if (ret <0 ) + goto bail; + +/* +* Delay for max possible number of steps, with slop. +* Each step is about 4usec. +*/ +udelay (415 ); + + ret =ibsd_mod_allchnls (dd,LDOUTCTRL1 (0 ) |EPB_GLOBAL_WR ,0x00 ,0xFF ); + +bail: +return ret; +} + +#define RELOCK_FIRST_MS 3 +#define RXLSPPM (chan) EPB_LOC(chan, 0, 2) +void toggle_7220_rclkrls (struct qib_devdata *dd) +{ +int loc =RXLSPPM (0 ) |EPB_GLOBAL_WR ; +int ret; + + ret =ibsd_mod_allchnls (dd, loc,0 ,0x80 ); +if (ret <0 ) +qib_dev_err (dd,"RCLKRLS failed to clear D7\n" ); +else { +udelay (1 ); +ibsd_mod_allchnls (dd, loc,0x80 ,0x80 ); + } +/* And again for good measure */ +udelay (1 ); + ret =ibsd_mod_allchnls (dd, loc,0 ,0x80 ); +if (ret <0 ) +qib_dev_err (dd,"RCLKRLS failed to clear D7\n" ); +else { +udelay (1 ); +ibsd_mod_allchnls (dd, loc,0x80 ,0x80 ); + } +/* Now reset xgxs and IBC to complete the recovery */ + dd->f_xgxs_reset (dd->pport); +} + +/* +* Shut down the timer that polls for relock occasions, if needed +* this is "hooked" from qib_7220_quiet_serdes(), which is called +* just before qib_shutdown_device() in qib_driver.c shuts down all +* the other timers +*/ +void shutdown_7220_relock_poll (struct qib_devdata *dd) +{ +struct qib_relock *irp = &dd->cspec->relock_st; + +if (atomic_read (&irp->relock_timer_active)) { +del_timer_sync (&irp->relock_timer); +atomic_set (&irp->relock_timer_active,0 ); + } +} + +static unsigned qib_relock_by_timer =1 ; +module_param_named (relock_by_timer, qib_relock_by_timer, uint, +S_IWUSR |S_IRUGO ); +MODULE_PARM_DESC (relock_by_timer,"Allow relock attempt if link not up" ); + +static void qib_run_relock (unsigned long opaque) +{ +struct qib_devdata *dd = (struct qib_devdata *)opaque; +struct qib_pportdata *ppd = dd->pport; +struct qib_relock *irp = &dd->cspec->relock_st; +int timeoff; + +/* +* Check link-training state for "stuck" state, when down. +* if found, try relock and schedule another try at +* exponentially growing delay, maxed at one second. +* if not stuck, our work is done. +*/ +if ((dd->flags &QIB_INITTED ) && !(ppd->lflags & + (QIBL_IB_AUTONEG_INPROG |QIBL_LINKINIT |QIBL_LINKARMED | +QIBL_LINKACTIVE ))) { +if (qib_relock_by_timer) { +if (!(ppd->lflags &QIBL_IB_LINK_DISABLED )) +toggle_7220_rclkrls (dd); + } +/* re-set timer for next check */ + timeoff = irp->relock_interval <<1 ; +if (timeoff >HZ ) + timeoff =HZ ; + irp->relock_interval = timeoff; + }else + timeoff =HZ ; +mod_timer (&irp->relock_timer, jiffies + timeoff); +} + +void set_7220_relock_poll (struct qib_devdata *dd,int ibup) +{ +struct qib_relock *irp = &dd->cspec->relock_st; + +if (ibup >0 ) { +/* We are now up, relax timer to 1 second interval */ +if (atomic_read (&irp->relock_timer_active)) +mod_timer (&irp->relock_timer, jiffies +HZ ); + }else { +/* Transition to down, (re-)set timer to short interval. */ +int timeout; + + timeout = (HZ * ((ibup ==-1 ) ?1000 :RELOCK_FIRST_MS )) /1000 ; +if (timeout ==0 ) + timeout =1 ; +/* If timer has not yet been started, do so. */ +if (atomic_inc_return (&irp->relock_timer_active) ==1 ) { +init_timer (&irp->relock_timer); + irp->relock_timer.function = qib_run_relock; + irp->relock_timer.data = (unsigned long ) dd; + irp->relock_interval = timeout; + irp->relock_timer.expires = jiffies + timeout; +add_timer (&irp->relock_timer); + }else { + irp->relock_interval = timeout; +mod_timer (&irp->relock_timer, jiffies + timeout); +atomic_dec (&irp->relock_timer_active); + } + } +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20100507000145.3441.59808.stgit-/[email protected]
Re: [PATCH v3 33/52] IB/qib: Add qib_sd7220.c
I don't think this is really a merge-blocker, but this code seems to have faith in the talismanic power of atomic_t to avoid races in nearby code. The following anti-pattern appears in a few other variants in the driver as well (just search for atomic_inc_return).
drivers/infiniband/hw/qib/qib_sd7220.c line 1413
Quoted 12 lines
drivers/infiniband/hw/qib/qib_sd7220.c new file +12
-0+if (atomic_inc_return (&irp->relock_timer_active) ==1 ) { +init_timer (&irp->relock_timer); + irp->relock_timer.function = qib_run_relock; + irp->relock_timer.data = (unsigned long ) dd; + irp->relock_interval = timeout; + irp->relock_timer.expires = jiffies + timeout; +add_timer (&irp->relock_timer); + }else { + irp->relock_interval = timeout; +mod_timer (&irp->relock_timer, jiffies + timeout); +atomic_dec (&irp->relock_timer_active); + }
Think about if two threads hit this code at the same time:
if (atomic_inc_return(&active) == 1) {
/* yep, first time through */
if (atomic_inc_return(&active) == 1) {
/* nope, go to else */
} else {
irp->relock_interval = timeout;
/* err, who set up this timer? */
mod_timer(&irp->relock_timer, jiffies + timeout);
atomic_dec(&irp->relock_timer_active);
}
/* a bit too late, the timer might already have run */
init_timer(&irp->relock_timer);
irp->relock_timer.function = qib_run_relock;
irp->relock_timer.data = (unsigned long) dd;
irp->relock_interval = timeout;
irp->relock_timer.expires = jiffies + timeout;
add_timer(&irp->relock_timer);Now, maybe this is safe because the code is actually never running concurrently, but using this atomic_t relock_timer_active makes it really hard to see that this code is safe. Why not just use a proper lock for this, since it doesn't look particularly performance critical (and an atomic_t is really the same cost as a spinlock anyway)?
As I said, not a merge-blocker but it would be nice to get this fixed someday before everyone loses interest in this driver.
- R.
Signature · 6 lines
Roland Dreier <[email protected]> || For corporate legal information go to: http://www.cisco.com/web/about/doing_business/legal/cri/index.html -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 34/52 IB/qib: Add qib_sd7220_img.c
In reply to a message not in the archivecreates the qib_sd7220_img.c file.
---
drivers/infiniband/hw/qib/qib_sd7220_img.c | 1081 ++++++++++++++++++++++++++++ 1 files changed, 1081 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_sd7220_img.c
drivers/infiniband/hw/qib/qib_sd7220_img.c new file +1081 -0
@@ -0,0 +1,1081 @@ +/* +* Copyright (c) 2007, 2008 QLogic Corporation. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +/* +* This file contains the memory image from the vendor, to be copied into +* the IB SERDES of the IBA7220 during initialization. +* The file also includes the two functions which use this image. +*/ +#include <linux/pci.h> +#include <linux/delay.h> +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}; + +int qib_sd7220_ib_load (struct qib_devdata *dd) +{ +return qib_sd7220_prog_ld (dd,IB_7220_SERDES , qib_sd7220_ib_img, +sizeof (qib_sd7220_ib_img),0 ); +} + +int qib_sd7220_ib_vfy (struct qib_devdata *dd) +{ +return qib_sd7220_prog_vfy (dd,IB_7220_SERDES , qib_sd7220_ib_img, +sizeof (qib_sd7220_ib_img),0 ); +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 35/52 IB/qib: Add qib_sdma.c
In reply to a message not in the archivecreates the qib_sdma.c file.
---
drivers/infiniband/hw/qib/qib_sdma.c | 973 ++++++++++++++++++++++++++++++++++ 1 files changed, 973 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_sdma.c
drivers/infiniband/hw/qib/qib_sdma.c new file +973 -0
@@ -0,0 +1,973 @@ +/* +* Copyright (c) 2007, 2008, 2009, 2010 QLogic Corporation. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/spinlock.h> +#include <linux/netdevice.h> + +#include "qib.h" +#include "qib_common.h" + +/* default pio off, sdma on */ +static ushort sdma_descq_cnt =256 ; +module_param_named (sdma_descq_cnt, sdma_descq_cnt, ushort,S_IRUGO ); +MODULE_PARM_DESC (sdma_descq_cnt,"Number of SDMA descq entries" ); + +/* +* Bits defined in the send DMA descriptor. +*/ +#define SDMA_DESC_LAST (1ULL << 11) +#define SDMA_DESC_FIRST (1ULL << 12) +#define SDMA_DESC_DMA_HEAD (1ULL << 13) +#define SDMA_DESC_USE_LARGE_BUF (1ULL << 14) +#define SDMA_DESC_INTR (1ULL << 15) +#define SDMA_DESC_COUNT_LSB 16 +#define SDMA_DESC_GEN_LSB 30 + +char *qib_sdma_state_names[] = { + [qib_sdma_state_s00_hw_down] ="s00_HwDown" , + [qib_sdma_state_s10_hw_start_up_wait] ="s10_HwStartUpWait" , + [qib_sdma_state_s20_idle] ="s20_Idle" , + [qib_sdma_state_s30_sw_clean_up_wait] ="s30_SwCleanUpWait" , + [qib_sdma_state_s40_hw_clean_up_wait] ="s40_HwCleanUpWait" , + [qib_sdma_state_s50_hw_halt_wait] ="s50_HwHaltWait" , + [qib_sdma_state_s99_running] ="s99_Running" , +}; + +char *qib_sdma_event_names[] = { + [qib_sdma_event_e00_go_hw_down] ="e00_GoHwDown" , + [qib_sdma_event_e10_go_hw_start] ="e10_GoHwStart" , + [qib_sdma_event_e20_hw_started] ="e20_HwStarted" , + [qib_sdma_event_e30_go_running] ="e30_GoRunning" , + [qib_sdma_event_e40_sw_cleaned] ="e40_SwCleaned" , + [qib_sdma_event_e50_hw_cleaned] ="e50_HwCleaned" , + [qib_sdma_event_e60_hw_halted] ="e60_HwHalted" , + [qib_sdma_event_e70_go_idle] ="e70_GoIdle" , + [qib_sdma_event_e7220_err_halted] ="e7220_ErrHalted" , + [qib_sdma_event_e7322_err_halted] ="e7322_ErrHalted" , + [qib_sdma_event_e90_timer_tick] ="e90_TimerTick" , +}; + +/* declare all statics here rather than keep sorting */ +static int alloc_sdma (struct qib_pportdata *); +static void sdma_complete (struct kref *); +static void sdma_finalput (struct qib_sdma_state *); +static void sdma_get (struct qib_sdma_state *); +static void sdma_put (struct qib_sdma_state *); +static void sdma_set_state (struct qib_pportdata *,enum qib_sdma_states ); +static void sdma_start_sw_clean_up (struct qib_pportdata *); +static void sdma_sw_clean_up_task (unsigned long ); +static void unmap_desc (struct qib_pportdata *,unsigned ); + +static void sdma_get (struct qib_sdma_state *ss) +{ +kref_get (&ss->kref); +} + +static void sdma_complete (struct kref *kref) +{ +struct qib_sdma_state *ss = + container_of(kref, struct qib_sdma_state, kref); + +complete (&ss->comp); +} + +static void sdma_put (struct qib_sdma_state *ss) +{ +kref_put (&ss->kref, sdma_complete); +} + +static void sdma_finalput (struct qib_sdma_state *ss) +{ +sdma_put (ss); +wait_for_completion (&ss->comp); +} + +/* +* Complete all the sdma requests on the active list, in the correct +* order, and with appropriate processing. Called when cleaning up +* after sdma shutdown, and when new sdma requests are submitted for +* a link that is down. This matches what is done for requests +* that complete normally, it's just the full list. +* +* Must be called with sdma_lock held +*/ +static void clear_sdma_activelist (struct qib_pportdata *ppd) +{ +struct qib_sdma_txreq *txp, *txp_next; + +list_for_each_entry_safe (txp, txp_next, &ppd->sdma_activelist, list) { +list_del_init (&txp->list); +if (txp->flags &QIB_SDMA_TXREQ_F_FREEDESC ) { +unsigned idx; + + idx = txp->start_idx; +while (idx != txp->next_descq_idx) { +unmap_desc (ppd, idx); +if (++idx == ppd->sdma_descq_cnt) + idx =0 ; + } + } +if (txp->callback) + (*txp->callback)(txp,QIB_SDMA_TXREQ_S_ABORTED ); + } +} + +static void sdma_sw_clean_up_task (unsigned long opaque) +{ +struct qib_pportdata *ppd = (struct qib_pportdata *) opaque; +unsigned long flags; + +spin_lock_irqsave (&ppd->sdma_lock, flags); + +/* +* At this point, the following should always be true: +* - We are halted, so no more descriptors are getting retired. +* - We are not running, so no one is submitting new work. +* - Only we can send the e40_sw_cleaned, so we can't start +* running again until we say so. So, the active list and +* descq are ours to play with. +*/ + +/* Process all retired requests. */ +qib_sdma_make_progress (ppd); + +clear_sdma_activelist (ppd); + +/* +* Resync count of added and removed. It is VERY important that +* sdma_descq_removed NEVER decrement - user_sdma depends on it. +*/ + ppd->sdma_descq_removed = ppd->sdma_descq_added; + +/* +* Reset our notion of head and tail. +* Note that the HW registers will be reset when switching states +* due to calling __qib_sdma_process_event() below. +*/ + ppd->sdma_descq_tail =0 ; + ppd->sdma_descq_head =0 ; + ppd->sdma_head_dma[0 ] =0 ; + ppd->sdma_generation =0 ; + +__qib_sdma_process_event (ppd, qib_sdma_event_e40_sw_cleaned); + +spin_unlock_irqrestore (&ppd->sdma_lock, flags); +} + +/* +* This is called when changing to state qib_sdma_state_s10_hw_start_up_wait +* as a result of send buffer errors or send DMA descriptor errors. +* We want to disarm the buffers in these cases. +*/ +static void sdma_hw_start_up (struct qib_pportdata *ppd) +{ +struct qib_sdma_state *ss = &ppd->sdma_state; +unsigned bufno; + +for (bufno = ss->first_sendbuf; bufno < ss->last_sendbuf; ++bufno) + ppd->dd->f_sendctrl (ppd,QIB_SENDCTRL_DISARM_BUF (bufno)); + + ppd->dd->f_sdma_hw_start_up (ppd); +} + +static void sdma_sw_tear_down (struct qib_pportdata *ppd) +{ +struct qib_sdma_state *ss = &ppd->sdma_state; + +/* Releasing this reference means the state machine has stopped. */ +sdma_put (ss); +} + +static void sdma_start_sw_clean_up (struct qib_pportdata *ppd) +{ +tasklet_hi_schedule (&ppd->sdma_sw_clean_up_task); +} + +static void sdma_set_state (struct qib_pportdata *ppd, +enum qib_sdma_states next_state) +{ +struct qib_sdma_state *ss = &ppd->sdma_state; +struct sdma_set_state_action *action = ss->set_state_action; +unsigned op =0 ; + +/* debugging bookkeeping */ + ss->previous_state = ss->current_state; + ss->previous_op = ss->current_op; + + ss->current_state = next_state; + +if (action[next_state].op_enable) + op |=QIB_SDMA_SENDCTRL_OP_ENABLE ; + +if (action[next_state].op_intenable) + op |=QIB_SDMA_SENDCTRL_OP_INTENABLE ; + +if (action[next_state].op_halt) + op |=QIB_SDMA_SENDCTRL_OP_HALT ; + +if (action[next_state].op_drain) + op |=QIB_SDMA_SENDCTRL_OP_DRAIN ; + +if (action[next_state].go_s99_running_tofalse) + ss->go_s99_running =0 ; + +if (action[next_state].go_s99_running_totrue) + ss->go_s99_running =1 ; + + ss->current_op = op; + + ppd->dd->f_sdma_sendctrl (ppd, ss->current_op); +} + +static void unmap_desc (struct qib_pportdata *ppd,unsigned head) +{ +__le64 *descqp = &ppd->sdma_descq[head].qw[0 ]; +u64 desc[2 ]; +dma_addr_t addr; +size_t len; + + desc[0 ] =le64_to_cpu (descqp[0 ]); + desc[1 ] =le64_to_cpu (descqp[1 ]); + + addr = (desc[1 ] <<32 ) | (desc[0 ] >>32 ); + len = (desc[0 ] >>14 ) & (0x7ffULL <<2 ); +dma_unmap_single (&ppd->dd->pcidev->dev, addr, len,DMA_TO_DEVICE ); +} + +static int alloc_sdma (struct qib_pportdata *ppd) +{ + ppd->sdma_descq_cnt = sdma_descq_cnt; +if (!ppd->sdma_descq_cnt) + ppd->sdma_descq_cnt =256 ; + +/* Allocate memory for SendDMA descriptor FIFO */ + ppd->sdma_descq =dma_alloc_coherent (&ppd->dd->pcidev->dev, + ppd->sdma_descq_cnt *sizeof (u64[2 ]), &ppd->sdma_descq_phys, +GFP_KERNEL ); + +if (!ppd->sdma_descq) { +qib_dev_err (ppd->dd,"failed to allocate SendDMA descriptor " +"FIFO memory\n" ); + goto bail; + } + +/* Allocate memory for DMA of head register to memory */ + ppd->sdma_head_dma =dma_alloc_coherent (&ppd->dd->pcidev->dev, +PAGE_SIZE , &ppd->sdma_head_phys,GFP_KERNEL ); +if (!ppd->sdma_head_dma) { +qib_dev_err (ppd->dd,"failed to allocate SendDMA " +"head memory\n" ); + goto cleanup_descq; + } + ppd->sdma_head_dma[0 ] =0 ; +return 0 ; + +cleanup_descq: +dma_free_coherent (&ppd->dd->pcidev->dev, + ppd->sdma_descq_cnt *sizeof (u64[2 ]), (void *)ppd->sdma_descq, + ppd->sdma_descq_phys); + ppd->sdma_descq =NULL ; + ppd->sdma_descq_phys =0 ; +bail: + ppd->sdma_descq_cnt =0 ; +return -ENOMEM ; +} + +static void free_sdma (struct qib_pportdata *ppd) +{ +struct qib_devdata *dd = ppd->dd; + +if (ppd->sdma_head_dma) { +dma_free_coherent (&dd->pcidev->dev,PAGE_SIZE , + (void *)ppd->sdma_head_dma, + ppd->sdma_head_phys); + ppd->sdma_head_dma =NULL ; + ppd->sdma_head_phys =0 ; + } + +if (ppd->sdma_descq) { +dma_free_coherent (&dd->pcidev->dev, + ppd->sdma_descq_cnt *sizeof (u64[2 ]), + ppd->sdma_descq, ppd->sdma_descq_phys); + ppd->sdma_descq =NULL ; + ppd->sdma_descq_phys =0 ; + } +} + +static inline void make_sdma_desc (struct qib_pportdata *ppd, +u64 *sdmadesc,u64 addr,u64 dwlen, +u64 dwoffset) +{ + +WARN_ON (addr &3 ); +/* SDmaPhyAddr[47:32] */ + sdmadesc[1 ] = addr >>32 ; +/* SDmaPhyAddr[31:0] */ + sdmadesc[0 ] = (addr &0xfffffffcULL ) <<32 ; +/* SDmaGeneration[1:0] */ + sdmadesc[0 ] |= (ppd->sdma_generation &3ULL ) << +SDMA_DESC_GEN_LSB ; +/* SDmaDwordCount[10:0] */ + sdmadesc[0 ] |= (dwlen &0x7ffULL ) <<SDMA_DESC_COUNT_LSB ; +/* SDmaBufOffset[12:2] */ + sdmadesc[0 ] |= dwoffset &0x7ffULL ; +} + +/* sdma_lock must be held */ +int qib_sdma_make_progress (struct qib_pportdata *ppd) +{ +struct list_head *lp =NULL ; +struct qib_sdma_txreq *txp =NULL ; +struct qib_devdata *dd = ppd->dd; +int progress =0 ; +u16 hwhead; +u16 idx =0 ; + + hwhead = dd->f_sdma_gethead (ppd); + +/* The reason for some of the complexity of this code is that +* not all descriptors have corresponding txps. So, we have to +* be able to skip over descs until we wander into the range of +* the next txp on the list. +*/ + +if (!list_empty (&ppd->sdma_activelist)) { + lp = ppd->sdma_activelist.next; + txp = list_entry(lp, struct qib_sdma_txreq, list); + idx = txp->start_idx; + } + +while (ppd->sdma_descq_head != hwhead) { +/* if desc is part of this txp, unmap if needed */ +if (txp && (txp->flags &QIB_SDMA_TXREQ_F_FREEDESC ) && + (idx == ppd->sdma_descq_head)) { +unmap_desc (ppd, ppd->sdma_descq_head); +if (++idx == ppd->sdma_descq_cnt) + idx =0 ; + } + +/* increment dequed desc count */ + ppd->sdma_descq_removed++; + +/* advance head, wrap if needed */ +if (++ppd->sdma_descq_head == ppd->sdma_descq_cnt) + ppd->sdma_descq_head =0 ; + +/* if now past this txp's descs, do the callback */ +if (txp && txp->next_descq_idx == ppd->sdma_descq_head) { +/* remove from active list */ +list_del_init (&txp->list); +if (txp->callback) + (*txp->callback)(txp,QIB_SDMA_TXREQ_S_OK ); +/* see if there is another txp */ +if (list_empty (&ppd->sdma_activelist)) + txp =NULL ; +else { + lp = ppd->sdma_activelist.next; + txp = list_entry(lp, struct qib_sdma_txreq, + list); + idx = txp->start_idx; + } + } + progress =1 ; + } +if (progress) +qib_verbs_sdma_desc_avail (ppd,qib_sdma_descq_freecnt (ppd)); +return progress; +} + +/* +* This is called from interrupt context. +*/ +void qib_sdma_intr (struct qib_pportdata *ppd) +{ +unsigned long flags; + +spin_lock_irqsave (&ppd->sdma_lock, flags); + +__qib_sdma_intr (ppd); + +spin_unlock_irqrestore (&ppd->sdma_lock, flags); +} + +void __qib_sdma_intr (struct qib_pportdata *ppd) +{ +if (__qib_sdma_running (ppd)) +qib_sdma_make_progress (ppd); +} + +int qib_setup_sdma (struct qib_pportdata *ppd) +{ +struct qib_devdata *dd = ppd->dd; +unsigned long flags; +int ret =0 ; + + ret =alloc_sdma (ppd); +if (ret) + goto bail; + +/* set consistent sdma state */ + ppd->dd->f_sdma_init_early (ppd); +spin_lock_irqsave (&ppd->sdma_lock, flags); +sdma_set_state (ppd, qib_sdma_state_s00_hw_down); +spin_unlock_irqrestore (&ppd->sdma_lock, flags); + +/* set up reference counting */ +kref_init (&ppd->sdma_state.kref); +init_completion (&ppd->sdma_state.comp); + + ppd->sdma_generation =0 ; + ppd->sdma_descq_head =0 ; + ppd->sdma_descq_removed =0 ; + ppd->sdma_descq_added =0 ; + +INIT_LIST_HEAD (&ppd->sdma_activelist); + +tasklet_init (&ppd->sdma_sw_clean_up_task, sdma_sw_clean_up_task, + (unsigned long )ppd); + + ret = dd->f_init_sdma_regs (ppd); +if (ret) + goto bail_alloc; + +qib_sdma_process_event (ppd, qib_sdma_event_e10_go_hw_start); + +return 0 ; + +bail_alloc: +qib_teardown_sdma (ppd); +bail: +return ret; +} + +void qib_teardown_sdma (struct qib_pportdata *ppd) +{ +qib_sdma_process_event (ppd, qib_sdma_event_e00_go_hw_down); + +/* +* This waits for the state machine to exit so it is not +* necessary to kill the sdma_sw_clean_up_task to make sure +* it is not running. +*/ +sdma_finalput (&ppd->sdma_state); + +free_sdma (ppd); +} + +int qib_sdma_running (struct qib_pportdata *ppd) +{ +unsigned long flags; +int ret; + +spin_lock_irqsave (&ppd->sdma_lock, flags); + ret =__qib_sdma_running (ppd); +spin_unlock_irqrestore (&ppd->sdma_lock, flags); + +return ret; +} + +/* +* Complete a request when sdma not running; likely only request +* but to simplify the code, always queue it, then process the full +* activelist. We process the entire list to ensure that this particular +* request does get it's callback, but in the correct order. +* Must be called with sdma_lock held +*/ +static void complete_sdma_err_req (struct qib_pportdata *ppd, +struct qib_verbs_txreq *tx) +{ +atomic_inc (&tx->qp->s_dma_busy); +/* no sdma descriptors, so no unmap_desc */ + tx->txreq.start_idx =0 ; + tx->txreq.next_descq_idx =0 ; +list_add_tail (&tx->txreq.list, &ppd->sdma_activelist); +clear_sdma_activelist (ppd); +} + +/* +* This function queues one IB packet onto the send DMA queue per call. +* The caller is responsible for checking: +* 1) The number of send DMA descriptor entries is less than the size of +* the descriptor queue. +* 2) The IB SGE addresses and lengths are 32-bit aligned +* (except possibly the last SGE's length) +* 3) The SGE addresses are suitable for passing to dma_map_single(). +*/ +int qib_sdma_verbs_send (struct qib_pportdata *ppd, +struct qib_sge_state *ss,u32 dwords, +struct qib_verbs_txreq *tx) +{ +unsigned long flags; +struct qib_sge *sge; +struct qib_qp *qp; +int ret =0 ; +u16 tail; +__le64 *descqp; +u64 sdmadesc[2 ]; +u32 dwoffset; +dma_addr_t addr; + +spin_lock_irqsave (&ppd->sdma_lock, flags); + +retry: +if (unlikely (!__qib_sdma_running (ppd))) { +complete_sdma_err_req (ppd, tx); + goto unlock; + } + +if (tx->txreq.sg_count >qib_sdma_descq_freecnt (ppd)) { +if (qib_sdma_make_progress (ppd)) + goto retry; +if (ppd->dd->flags &QIB_HAS_SDMA_TIMEOUT ) + ppd->dd->f_sdma_set_desc_cnt (ppd, + ppd->sdma_descq_cnt /2 ); + goto busy; + } + + dwoffset = tx->hdr_dwords; +make_sdma_desc (ppd, sdmadesc, (u64 ) tx->txreq.addr, dwoffset,0 ); + + sdmadesc[0 ] |=SDMA_DESC_FIRST ; +if (tx->txreq.flags &QIB_SDMA_TXREQ_F_USELARGEBUF ) + sdmadesc[0 ] |=SDMA_DESC_USE_LARGE_BUF ; + +/* write to the descq */ + tail = ppd->sdma_descq_tail; + descqp = &ppd->sdma_descq[tail].qw[0 ]; + *descqp++ =cpu_to_le64 (sdmadesc[0 ]); + *descqp++ =cpu_to_le64 (sdmadesc[1 ]); + +/* increment the tail */ +if (++tail == ppd->sdma_descq_cnt) { + tail =0 ; + descqp = &ppd->sdma_descq[0 ].qw[0 ]; + ++ppd->sdma_generation; + } + + tx->txreq.start_idx = tail; + + sge = &ss->sge; +while (dwords) { +u32 dw; +u32 len; + + len = dwords <<2 ; +if (len > sge->length) + len = sge->length; +if (len > sge->sge_length) + len = sge->sge_length; +BUG_ON (len ==0 ); + dw = (len +3 ) >>2 ; + addr =dma_map_single (&ppd->dd->pcidev->dev, sge->vaddr, + dw <<2 ,DMA_TO_DEVICE ); +if (dma_mapping_error (&ppd->dd->pcidev->dev, addr)) + goto unmap; + sdmadesc[0 ] =0 ; +make_sdma_desc (ppd, sdmadesc, (u64 ) addr, dw, dwoffset); +/* SDmaUseLargeBuf has to be set in every descriptor */ +if (tx->txreq.flags &QIB_SDMA_TXREQ_F_USELARGEBUF ) + sdmadesc[0 ] |=SDMA_DESC_USE_LARGE_BUF ; +/* write to the descq */ + *descqp++ =cpu_to_le64 (sdmadesc[0 ]); + *descqp++ =cpu_to_le64 (sdmadesc[1 ]); + +/* increment the tail */ +if (++tail == ppd->sdma_descq_cnt) { + tail =0 ; + descqp = &ppd->sdma_descq[0 ].qw[0 ]; + ++ppd->sdma_generation; + } + sge->vaddr += len; + sge->length -= len; + sge->sge_length -= len; +if (sge->sge_length ==0 ) { +if (--ss->num_sge) + *sge = *ss->sg_list++; + }else if (sge->length ==0 && sge->mr->lkey) { +if (++sge->n >=QIB_SEGSZ ) { +if (++sge->m >= sge->mr->mapsz) +break ; + sge->n =0 ; + } + sge->vaddr = + sge->mr->map[sge->m]->segs[sge->n].vaddr; + sge->length = + sge->mr->map[sge->m]->segs[sge->n].length; + } + + dwoffset += dw; + dwords -= dw; + } + +if (!tail) + descqp = &ppd->sdma_descq[ppd->sdma_descq_cnt].qw[0 ]; + descqp -=2 ; + descqp[0 ] |=cpu_to_le64 (SDMA_DESC_LAST ); +if (tx->txreq.flags &QIB_SDMA_TXREQ_F_HEADTOHOST ) + descqp[0 ] |=cpu_to_le64 (SDMA_DESC_DMA_HEAD ); +if (tx->txreq.flags &QIB_SDMA_TXREQ_F_INTREQ ) + descqp[0 ] |=cpu_to_le64 (SDMA_DESC_INTR ); + +atomic_inc (&tx->qp->s_dma_busy); + tx->txreq.next_descq_idx = tail; + ppd->dd->f_sdma_update_tail (ppd, tail); + ppd->sdma_descq_added += tx->txreq.sg_count; +list_add_tail (&tx->txreq.list, &ppd->sdma_activelist); + goto unlock; + +unmap: +for (;;) { +if (!tail) + tail = ppd->sdma_descq_cnt -1 ; +else + tail--; +if (tail == ppd->sdma_descq_tail) +break ; +unmap_desc (ppd, tail); + } + qp = tx->qp; +qib_put_txreq (tx); +spin_lock (&qp->s_lock); +if (qp->ibqp.qp_type ==IB_QPT_RC ) { +/* XXX what about error sending RDMA read responses? */ +if (ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK ) +qib_error_qp (qp,IB_WC_GENERAL_ERR ); + }else if (qp->s_wqe) +qib_send_complete (qp, qp->s_wqe,IB_WC_GENERAL_ERR ); +spin_unlock (&qp->s_lock); +/* return zero to process the next send work request */ + goto unlock; + +busy: + qp = tx->qp; +spin_lock (&qp->s_lock); +if (ib_qib_state_ops[qp->state] &QIB_PROCESS_RECV_OK ) { +struct qib_ibdev *dev; + +/* +* If we couldn't queue the DMA request, save the info +* and try again later rather than destroying the +* buffer and undoing the side effects of the copy. +*/ + tx->ss = ss; + tx->dwords = dwords; + qp->s_tx = tx; + dev = &ppd->dd->verbs_dev; +spin_lock (&dev->pending_lock); +if (list_empty (&qp->iowait)) { +struct qib_ibport *ibp; + + ibp = &ppd->ibport_data; + ibp->n_dmawait++; + qp->s_flags |=QIB_S_WAIT_DMA_DESC ; +list_add_tail (&qp->iowait, &dev->dmawait); + } +spin_unlock (&dev->pending_lock); + qp->s_flags &= ~QIB_S_BUSY ; +spin_unlock (&qp->s_lock); + ret = -EBUSY ; + }else { +spin_unlock (&qp->s_lock); +qib_put_txreq (tx); + } +unlock: +spin_unlock_irqrestore (&ppd->sdma_lock, flags); +return ret; +} + +void qib_sdma_process_event (struct qib_pportdata *ppd, +enum qib_sdma_events event) +{ +unsigned long flags; + +spin_lock_irqsave (&ppd->sdma_lock, flags); + +__qib_sdma_process_event (ppd, event); + +if (ppd->sdma_state.current_state == qib_sdma_state_s99_running) +qib_verbs_sdma_desc_avail (ppd,qib_sdma_descq_freecnt (ppd)); + +spin_unlock_irqrestore (&ppd->sdma_lock, flags); +} + +void __qib_sdma_process_event (struct qib_pportdata *ppd, +enum qib_sdma_events event) +{ +struct qib_sdma_state *ss = &ppd->sdma_state; + +switch (ss->current_state) { +case qib_sdma_state_s00_hw_down: +switch (event) { +case qib_sdma_event_e00_go_hw_down: +break ; +case qib_sdma_event_e30_go_running: +/* +* If down, but running requested (usually result +* of link up, then we need to start up. +* This can happen when hw down is requested while +* bringing the link up with traffic active on +* 7220, e.g. */ + ss->go_s99_running =1 ; +/* fall through and start dma engine */ +case qib_sdma_event_e10_go_hw_start: +/* This reference means the state machine is started */ +sdma_get (&ppd->sdma_state); +sdma_set_state (ppd, + qib_sdma_state_s10_hw_start_up_wait); +break ; +case qib_sdma_event_e20_hw_started: +break ; +case qib_sdma_event_e40_sw_cleaned: +sdma_sw_tear_down (ppd); +break ; +case qib_sdma_event_e50_hw_cleaned: +break ; +case qib_sdma_event_e60_hw_halted: +break ; +case qib_sdma_event_e70_go_idle: +break ; +case qib_sdma_event_e7220_err_halted: +break ; +case qib_sdma_event_e7322_err_halted: +break ; +case qib_sdma_event_e90_timer_tick: +break ; + } +break ; + +case qib_sdma_state_s10_hw_start_up_wait: +switch (event) { +case qib_sdma_event_e00_go_hw_down: +sdma_set_state (ppd, qib_sdma_state_s00_hw_down); +sdma_sw_tear_down (ppd); +break ; +case qib_sdma_event_e10_go_hw_start: +break ; +case qib_sdma_event_e20_hw_started: +sdma_set_state (ppd, ss->go_s99_running ? + qib_sdma_state_s99_running : + qib_sdma_state_s20_idle); +break ; +case qib_sdma_event_e30_go_running: + ss->go_s99_running =1 ; +break ; +case qib_sdma_event_e40_sw_cleaned: +break ; +case qib_sdma_event_e50_hw_cleaned: +break ; +case qib_sdma_event_e60_hw_halted: +break ; +case qib_sdma_event_e70_go_idle: + ss->go_s99_running =0 ; +break ; +case qib_sdma_event_e7220_err_halted: +break ; +case qib_sdma_event_e7322_err_halted: +break ; +case qib_sdma_event_e90_timer_tick: +break ; + } +break ; + +case qib_sdma_state_s20_idle: +switch (event) { +case qib_sdma_event_e00_go_hw_down: +sdma_set_state (ppd, qib_sdma_state_s00_hw_down); +sdma_sw_tear_down (ppd); +break ; +case qib_sdma_event_e10_go_hw_start: +break ; +case qib_sdma_event_e20_hw_started: +break ; +case qib_sdma_event_e30_go_running: +sdma_set_state (ppd, qib_sdma_state_s99_running); + ss->go_s99_running =1 ; +break ; +case qib_sdma_event_e40_sw_cleaned: +break ; +case qib_sdma_event_e50_hw_cleaned: +break ; +case qib_sdma_event_e60_hw_halted: +break ; +case qib_sdma_event_e70_go_idle: +break ; +case qib_sdma_event_e7220_err_halted: +break ; +case qib_sdma_event_e7322_err_halted: +break ; +case qib_sdma_event_e90_timer_tick: +break ; + } +break ; + +case qib_sdma_state_s30_sw_clean_up_wait: +switch (event) { +case qib_sdma_event_e00_go_hw_down: +sdma_set_state (ppd, qib_sdma_state_s00_hw_down); +break ; +case qib_sdma_event_e10_go_hw_start: +break ; +case qib_sdma_event_e20_hw_started: +break ; +case qib_sdma_event_e30_go_running: + ss->go_s99_running =1 ; +break ; +case qib_sdma_event_e40_sw_cleaned: +sdma_set_state (ppd, + qib_sdma_state_s10_hw_start_up_wait); +sdma_hw_start_up (ppd); +break ; +case qib_sdma_event_e50_hw_cleaned: +break ; +case qib_sdma_event_e60_hw_halted: +break ; +case qib_sdma_event_e70_go_idle: + ss->go_s99_running =0 ; +break ; +case qib_sdma_event_e7220_err_halted: +break ; +case qib_sdma_event_e7322_err_halted: +break ; +case qib_sdma_event_e90_timer_tick: +break ; + } +break ; + +case qib_sdma_state_s40_hw_clean_up_wait: +switch (event) { +case qib_sdma_event_e00_go_hw_down: +sdma_set_state (ppd, qib_sdma_state_s00_hw_down); +sdma_start_sw_clean_up (ppd); +break ; +case qib_sdma_event_e10_go_hw_start: +break ; +case qib_sdma_event_e20_hw_started: +break ; +case qib_sdma_event_e30_go_running: + ss->go_s99_running =1 ; +break ; +case qib_sdma_event_e40_sw_cleaned: +break ; +case qib_sdma_event_e50_hw_cleaned: +sdma_set_state (ppd, + qib_sdma_state_s30_sw_clean_up_wait); +sdma_start_sw_clean_up (ppd); +break ; +case qib_sdma_event_e60_hw_halted: +break ; +case qib_sdma_event_e70_go_idle: + ss->go_s99_running =0 ; +break ; +case qib_sdma_event_e7220_err_halted: +break ; +case qib_sdma_event_e7322_err_halted: +break ; +case qib_sdma_event_e90_timer_tick: +break ; + } +break ; + +case qib_sdma_state_s50_hw_halt_wait: +switch (event) { +case qib_sdma_event_e00_go_hw_down: +sdma_set_state (ppd, qib_sdma_state_s00_hw_down); +sdma_start_sw_clean_up (ppd); +break ; +case qib_sdma_event_e10_go_hw_start: +break ; +case qib_sdma_event_e20_hw_started: +break ; +case qib_sdma_event_e30_go_running: + ss->go_s99_running =1 ; +break ; +case qib_sdma_event_e40_sw_cleaned: +break ; +case qib_sdma_event_e50_hw_cleaned: +break ; +case qib_sdma_event_e60_hw_halted: +sdma_set_state (ppd, + qib_sdma_state_s40_hw_clean_up_wait); + ppd->dd->f_sdma_hw_clean_up (ppd); +break ; +case qib_sdma_event_e70_go_idle: + ss->go_s99_running =0 ; +break ; +case qib_sdma_event_e7220_err_halted: +break ; +case qib_sdma_event_e7322_err_halted: +break ; +case qib_sdma_event_e90_timer_tick: +break ; + } +break ; + +case qib_sdma_state_s99_running: +switch (event) { +case qib_sdma_event_e00_go_hw_down: +sdma_set_state (ppd, qib_sdma_state_s00_hw_down); +sdma_start_sw_clean_up (ppd); +break ; +case qib_sdma_event_e10_go_hw_start: +break ; +case qib_sdma_event_e20_hw_started: +break ; +case qib_sdma_event_e30_go_running: +break ; +case qib_sdma_event_e40_sw_cleaned: +break ; +case qib_sdma_event_e50_hw_cleaned: +break ; +case qib_sdma_event_e60_hw_halted: +sdma_set_state (ppd, + qib_sdma_state_s30_sw_clean_up_wait); +sdma_start_sw_clean_up (ppd); +break ; +case qib_sdma_event_e70_go_idle: +sdma_set_state (ppd, qib_sdma_state_s50_hw_halt_wait); + ss->go_s99_running =0 ; +break ; +case qib_sdma_event_e7220_err_halted: +sdma_set_state (ppd, + qib_sdma_state_s30_sw_clean_up_wait); +sdma_start_sw_clean_up (ppd); +break ; +case qib_sdma_event_e7322_err_halted: +sdma_set_state (ppd, qib_sdma_state_s50_hw_halt_wait); +break ; +case qib_sdma_event_e90_timer_tick: +break ; + } +break ; + } + + ss->last_event = event; +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 36/52 IB/qib: Add qib_srq.c
In reply to a message not in the archivecreates the qib_srq.c file.
---
drivers/infiniband/hw/qib/qib_srq.c | 374 +++++++++++++++++++++++++++++++++++ 1 files changed, 374 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_srq.c
drivers/infiniband/hw/qib/qib_srq.c new file +374 -0
@@ -0,0 +1,374 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/err.h> +#include <linux/vmalloc.h> + +#include "qib_verbs.h" + +/** +* qib_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 qib_post_srq_receive (struct ib_srq *ibsrq,struct ib_recv_wr *wr, +struct ib_recv_wr **bad_wr) +{ +struct qib_srq *srq =to_isrq (ibsrq); +struct qib_rwq *wq; +unsigned long flags; +int ret; + +for (; wr; wr = wr->next) { +struct qib_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 entry is written before the head index. */ +smp_wmb (); + wq->head = next; +spin_unlock_irqrestore (&srq->rq.lock, flags); + } + ret =0 ; + +bail: +return ret; +} + +/** +* qib_create_srq - create a shared receive queue +* @ibpd: the protection domain of the SRQ to create +* @srq_init_attr: the attributes of the SRQ +* @udata: data from libibverbs when creating a user SRQ +*/ +struct ib_srq *qib_create_srq (struct ib_pd *ibpd, +struct ib_srq_init_attr *srq_init_attr, +struct ib_udata *udata) +{ +struct qib_ibdev *dev =to_idev (ibpd->device); +struct qib_srq *srq; +u32 sz; +struct ib_srq *ret; + +if (srq_init_attr->attr.max_sge ==0 || + srq_init_attr->attr.max_sge > ib_qib_max_srq_sges || + srq_init_attr->attr.max_wr ==0 || + srq_init_attr->attr.max_wr > ib_qib_max_srq_wrs) { + ret =ERR_PTR (-EINVAL ); + goto done; + } + + srq =kmalloc (sizeof (*srq),GFP_KERNEL ); +if (!srq) { + ret =ERR_PTR (-ENOMEM ); + goto done; + } + +/* +* Need to use vmalloc() if we want to support large #s of entries. +*/ + srq->rq.size = srq_init_attr->attr.max_wr +1 ; + srq->rq.max_sge = srq_init_attr->attr.max_sge; + sz =sizeof (struct ib_sge ) * srq->rq.max_sge + +sizeof (struct qib_rwqe ); + srq->rq.wq =vmalloc_user (sizeof (struct qib_rwq ) + srq->rq.size * sz); +if (!srq->rq.wq) { + ret =ERR_PTR (-ENOMEM ); + goto bail_srq; + } + +/* +* Return the address of the RWQ as the offset to mmap. +* See qib_mmap() for details. +*/ +if (udata && udata->outlen >=sizeof (__u64)) { +int err; +u32 s =sizeof (struct qib_rwq ) + srq->rq.size * sz; + + srq->ip = +qib_create_mmap_info (dev, s, ibpd->uobject->context, + srq->rq.wq); +if (!srq->ip) { + ret =ERR_PTR (-ENOMEM ); + goto bail_wq; + } + + err =ib_copy_to_udata (udata, &srq->ip->offset, +sizeof (srq->ip->offset)); +if (err) { + ret =ERR_PTR (err); + goto bail_ip; + } + }else + srq->ip =NULL ; + +/* +* ib_create_srq() will initialize srq->ibsrq. +*/ +spin_lock_init (&srq->rq.lock); + srq->rq.wq->head =0 ; + srq->rq.wq->tail =0 ; + srq->limit = srq_init_attr->attr.srq_limit; + +spin_lock (&dev->n_srqs_lock); +if (dev->n_srqs_allocated == ib_qib_max_srqs) { +spin_unlock (&dev->n_srqs_lock); + ret =ERR_PTR (-ENOMEM ); + goto bail_ip; + } + + dev->n_srqs_allocated++; +spin_unlock (&dev->n_srqs_lock); + +if (srq->ip) { +spin_lock_irq (&dev->pending_lock); +list_add (&srq->ip->pending_mmaps, &dev->pending_mmaps); +spin_unlock_irq (&dev->pending_lock); + } + + ret = &srq->ibsrq; + goto done; + +bail_ip: +kfree (srq->ip); +bail_wq: +vfree (srq->rq.wq); +bail_srq: +kfree (srq); +done: +return ret; +} + +/** +* qib_modify_srq - modify a shared receive queue +* @ibsrq: the SRQ to modify +* @attr: the new attributes of the SRQ +* @attr_mask: indicates which attributes to modify +* @udata: user data for libibverbs.so +*/ +int qib_modify_srq (struct ib_srq *ibsrq,struct ib_srq_attr *attr, +enum ib_srq_attr_mask attr_mask, +struct ib_udata *udata) +{ +struct qib_srq *srq =to_isrq (ibsrq); +struct qib_rwq *wq; +int ret =0 ; + +if (attr_mask &IB_SRQ_MAX_WR ) { +struct qib_rwq *owq; +struct qib_rwqe *p; +u32 sz, size, n, head, tail; + +/* Check that the requested sizes are below the limits. */ +if ((attr->max_wr > ib_qib_max_srq_wrs) || + ((attr_mask &IB_SRQ_LIMIT ) ? + attr->srq_limit : srq->limit) > attr->max_wr) { + ret = -EINVAL ; + goto bail; + } + + sz =sizeof (struct qib_rwqe ) + + srq->rq.max_sge *sizeof (struct ib_sge ); + size = attr->max_wr +1 ; + wq =vmalloc_user (sizeof (struct qib_rwq ) + size * sz); +if (!wq) { + ret = -ENOMEM ; + goto bail; + } + +/* Check that we can write the offset to mmap. */ +if (udata && udata->inlen >=sizeof (__u64)) { +__u64 offset_addr; +__u64 offset =0 ; + + ret =ib_copy_from_udata (&offset_addr, udata, +sizeof (offset_addr)); +if (ret) + goto bail_free; + udata->outbuf = + (void __user *) (unsigned long ) offset_addr; + ret =ib_copy_to_udata (udata, &offset, +sizeof (offset)); +if (ret) + goto bail_free; + } + +spin_lock_irq (&srq->rq.lock); +/* +* validate head and tail pointer values and compute +* the number of remaining WQEs. +*/ + owq = srq->rq.wq; + head = owq->head; + tail = owq->tail; +if (head >= srq->rq.size || tail >= srq->rq.size) { + ret = -EINVAL ; + goto bail_unlock; + } + n = head; +if (n < tail) + n += srq->rq.size - tail; +else + n -= tail; +if (size <= n) { + ret = -EINVAL ; + goto bail_unlock; + } + n =0 ; + p = wq->wq; +while (tail != head) { +struct qib_rwqe *wqe; +int i; + + wqe =get_rwqe_ptr (&srq->rq, tail); + p->wr_id = wqe->wr_id; + p->num_sge = wqe->num_sge; +for (i =0 ; i < wqe->num_sge; i++) + p->sg_list[i] = wqe->sg_list[i]; + n++; + p = (struct qib_rwqe *)((char *) p + sz); +if (++tail >= srq->rq.size) + tail =0 ; + } + srq->rq.wq = wq; + srq->rq.size = size; + wq->head = n; + wq->tail =0 ; +if (attr_mask &IB_SRQ_LIMIT ) + srq->limit = attr->srq_limit; +spin_unlock_irq (&srq->rq.lock); + +vfree (owq); + +if (srq->ip) { +struct qib_mmap_info *ip = srq->ip; +struct qib_ibdev *dev =to_idev (srq->ibsrq.device); +u32 s =sizeof (struct qib_rwq ) + size * sz; + +qib_update_mmap_info (dev, ip, s, wq); + +/* +* Return the offset to mmap. +* See qib_mmap() for details. +*/ +if (udata && udata->inlen >=sizeof (__u64)) { + ret =ib_copy_to_udata (udata, &ip->offset, +sizeof (ip->offset)); +if (ret) + goto bail; + } + +/* +* Put user mapping info onto the pending list +* unless it already is on the list. +*/ +spin_lock_irq (&dev->pending_lock); +if (list_empty (&ip->pending_mmaps)) +list_add (&ip->pending_mmaps, + &dev->pending_mmaps); +spin_unlock_irq (&dev->pending_lock); + } + }else if (attr_mask &IB_SRQ_LIMIT ) { +spin_lock_irq (&srq->rq.lock); +if (attr->srq_limit >= srq->rq.size) + ret = -EINVAL ; +else + srq->limit = attr->srq_limit; +spin_unlock_irq (&srq->rq.lock); + } + goto bail; + +bail_unlock: +spin_unlock_irq (&srq->rq.lock); +bail_free: +vfree (wq); +bail: +return ret; +} + +int qib_query_srq (struct ib_srq *ibsrq,struct ib_srq_attr *attr) +{ +struct qib_srq *srq =to_isrq (ibsrq); + + attr->max_wr = srq->rq.size -1 ; + attr->max_sge = srq->rq.max_sge; + attr->srq_limit = srq->limit; +return 0 ; +} + +/** +* qib_destroy_srq - destroy a shared receive queue +* @ibsrq: the SRQ to destroy +*/ +int qib_destroy_srq (struct ib_srq *ibsrq) +{ +struct qib_srq *srq =to_isrq (ibsrq); +struct qib_ibdev *dev =to_idev (ibsrq->device); + +spin_lock (&dev->n_srqs_lock); + dev->n_srqs_allocated--; +spin_unlock (&dev->n_srqs_lock); +if (srq->ip) +kref_put (&srq->ip->ref, qib_release_mmap_info); +else +vfree (srq->rq.wq); +kfree (srq); + +return 0 ; +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 37/52 IB/qib: Add qib_sysfs.c
In reply to a message not in the archivecreates the qib_sysfs.c file.
---
drivers/infiniband/hw/qib/qib_sysfs.c | 691 +++++++++++++++++++++++++++++++++ 1 files changed, 691 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_sysfs.c
drivers/infiniband/hw/qib/qib_sysfs.c new file +691 -0
@@ -0,0 +1,691 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ +#include <linux/ctype.h> + +#include "qib.h" + +/** +* qib_parse_ushort - parse an unsigned short value in an arbitrary base +* @str: the string containing the number +* @valp: where to put the result +* +* Returns the number of bytes consumed, or negative value on error. +*/ +static int qib_parse_ushort (const char *str,unsigned short *valp) +{ +unsigned long val; +char *end; +int ret; + +if (!isdigit (str[0 ])) { + ret = -EINVAL ; + goto bail; + } + + val =simple_strtoul (str, &end,0 ); + +if (val >0xffff ) { + ret = -EINVAL ; + goto bail; + } + + *valp = val; + + ret = end +1 - str; +if (ret ==0 ) + ret = -EINVAL ; + +bail: +return ret; +} + +/* start of per-port functions */ +/* +* Get/Set heartbeat enable. OR of 1=enabled, 2=auto +*/ +static ssize_t show_hrtbt_enb (struct qib_pportdata *ppd,char *buf) +{ +struct qib_devdata *dd = ppd->dd; +int ret; + + ret = dd->f_get_ib_cfg (ppd,QIB_IB_CFG_HRTBT ); + ret =scnprintf (buf,PAGE_SIZE ,"%d\n" , ret); +return ret; +} + +static ssize_t store_hrtbt_enb (struct qib_pportdata *ppd,const char *buf, +size_t count) +{ +struct qib_devdata *dd = ppd->dd; +int ret; +u16 val; + + ret =qib_parse_ushort (buf, &val); + +/* +* 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. +*/ +if (ret >=0 ) + ret = dd->f_set_ib_cfg (ppd,QIB_IB_CFG_HRTBT , val); +if (ret <0 ) +qib_dev_err (dd,"attempt to set invalid Heartbeat enable\n" ); +return ret <0 ? ret : count; +} + +static ssize_t store_loopback (struct qib_pportdata *ppd,const char *buf, +size_t count) +{ +struct qib_devdata *dd = ppd->dd; +int ret = count, r; + + r = dd->f_set_ib_loopback (ppd, buf); +if (r <0 ) + ret = r; + +return ret; +} + +static ssize_t store_led_override (struct qib_pportdata *ppd,const char *buf, +size_t count) +{ +struct qib_devdata *dd = ppd->dd; +int ret; +u16 val; + + ret =qib_parse_ushort (buf, &val); +if (ret >0 ) +qib_set_led_override (ppd, val); +else +qib_dev_err (dd,"attempt to set invalid LED override\n" ); +return ret <0 ? ret : count; +} + +static ssize_t show_status (struct qib_pportdata *ppd,char *buf) +{ +ssize_t ret; + +if (!ppd->statusp) + ret = -EINVAL ; +else + ret =scnprintf (buf,PAGE_SIZE ,"0x%llx\n" , + (unsigned long long ) *(ppd->statusp)); +return ret; +} + +/* +* For userland compatibility, these offsets must remain fixed. +* They are strings for QIB_STATUS_* +*/ +static const char *qib_status_str[] = { +"Initted" , +"" , +"" , +"" , +"" , +"Present" , +"IB_link_up" , +"IB_configured" , +"" , +"Fatal_Hardware_Error" , +NULL , +}; + +static ssize_t show_status_str (struct qib_pportdata *ppd,char *buf) +{ +int i, any; +u64 s; +ssize_t ret; + +if (!ppd->statusp) { + ret = -EINVAL ; + goto bail; + } + + s = *(ppd->statusp); + *buf ='\0' ; +for (any = i =0 ; s && qib_status_str[i]; i++) { +if (s &1 ) { +/* if overflow */ +if (any &&strlcat (buf," " ,PAGE_SIZE ) >=PAGE_SIZE ) +break ; +if (strlcat (buf, qib_status_str[i],PAGE_SIZE ) >= +PAGE_SIZE ) +break ; + any =1 ; + } + s >>=1 ; + } +if (any) +strlcat (buf,"\n" ,PAGE_SIZE ); + + ret =strlen (buf); + +bail: +return ret; +} + +/* end of per-port functions */ + +/* +* Start of per-port file structures and support code +* Because we are fitting into other infrastructure, we have to supply the +* full set of kobject/sysfs_ops structures and routines. +*/ +#define QIB_PORT_ATTR (name, mode, show, store) \ + static struct qib_port_attr qib_port_attr_##name = \ + __ATTR(name, mode, show, store) + +struct qib_port_attr { +struct attribute attr; +ssize_t (*show)(struct qib_pportdata *,char *); +ssize_t (*store)(struct qib_pportdata *,const char *,size_t ); +}; + +QIB_PORT_ATTR (loopback,S_IWUSR ,NULL , store_loopback); +QIB_PORT_ATTR (led_override,S_IWUSR ,NULL , store_led_override); +QIB_PORT_ATTR (hrtbt_enable,S_IWUSR |S_IRUGO , show_hrtbt_enb, + store_hrtbt_enb); +QIB_PORT_ATTR (status,S_IRUGO , show_status,NULL ); +QIB_PORT_ATTR (status_str,S_IRUGO , show_status_str,NULL ); + +static struct attribute *port_default_attributes[] = { + &qib_port_attr_loopback.attr, + &qib_port_attr_led_override.attr, + &qib_port_attr_hrtbt_enable.attr, + &qib_port_attr_status.attr, + &qib_port_attr_status_str.attr, +NULL +}; + +static ssize_t qib_portattr_show (struct kobject *kobj, +struct attribute *attr,char *buf) +{ +struct qib_port_attr *pattr = + container_of(attr, struct qib_port_attr, attr); +struct qib_pportdata *ppd = + container_of(kobj, struct qib_pportdata, pport_kobj); + +return pattr->show (ppd, buf); +} + +static ssize_t qib_portattr_store (struct kobject *kobj, +struct attribute *attr,const char *buf,size_t len) +{ +struct qib_port_attr *pattr = + container_of(attr, struct qib_port_attr, attr); +struct qib_pportdata *ppd = + container_of(kobj, struct qib_pportdata, pport_kobj); + +return pattr->store (ppd, buf, len); +} + +static void qib_port_release (struct kobject *kobj) +{ +/* nothing to do since memory is freed by qib_free_devdata() */ +} + +static const struct sysfs_ops qib_port_ops = { + .show = qib_portattr_show, + .store = qib_portattr_store, +}; + +static struct kobj_type qib_port_ktype = { + .release = qib_port_release, + .sysfs_ops = &qib_port_ops, + .default_attrs = port_default_attributes +}; + +/* Start sl2vl */ + +#define QIB_SL2VL_ATTR (N ) \ + static struct qib_sl2vl_attr qib_sl2vl_attr_##N = { \ + .attr = { .name = __stringify(N), .mode = 0444 }, \ + .sl = N \ + } + +struct qib_sl2vl_attr { +struct attribute attr; +int sl; +}; + +QIB_SL2VL_ATTR (0 ); +QIB_SL2VL_ATTR (1 ); +QIB_SL2VL_ATTR (2 ); +QIB_SL2VL_ATTR (3 ); +QIB_SL2VL_ATTR (4 ); +QIB_SL2VL_ATTR (5 ); +QIB_SL2VL_ATTR (6 ); +QIB_SL2VL_ATTR (7 ); +QIB_SL2VL_ATTR (8 ); +QIB_SL2VL_ATTR (9 ); +QIB_SL2VL_ATTR (10 ); +QIB_SL2VL_ATTR (11 ); +QIB_SL2VL_ATTR (12 ); +QIB_SL2VL_ATTR (13 ); +QIB_SL2VL_ATTR (14 ); +QIB_SL2VL_ATTR (15 ); + +static struct attribute *sl2vl_default_attributes[] = { + &qib_sl2vl_attr_0.attr, + &qib_sl2vl_attr_1.attr, + &qib_sl2vl_attr_2.attr, + &qib_sl2vl_attr_3.attr, + &qib_sl2vl_attr_4.attr, + &qib_sl2vl_attr_5.attr, + &qib_sl2vl_attr_6.attr, + &qib_sl2vl_attr_7.attr, + &qib_sl2vl_attr_8.attr, + &qib_sl2vl_attr_9.attr, + &qib_sl2vl_attr_10.attr, + &qib_sl2vl_attr_11.attr, + &qib_sl2vl_attr_12.attr, + &qib_sl2vl_attr_13.attr, + &qib_sl2vl_attr_14.attr, + &qib_sl2vl_attr_15.attr, +NULL +}; + +static ssize_t sl2vl_attr_show (struct kobject *kobj,struct attribute *attr, +char *buf) +{ +struct qib_sl2vl_attr *sattr = + container_of(attr, struct qib_sl2vl_attr, attr); +struct qib_pportdata *ppd = + container_of(kobj, struct qib_pportdata, sl2vl_kobj); +struct qib_ibport *qibp = &ppd->ibport_data; + +return sprintf (buf,"%u\n" , qibp->sl_to_vl[sattr->sl]); +} + +static const struct sysfs_ops qib_sl2vl_ops = { + .show = sl2vl_attr_show, +}; + +static struct kobj_type qib_sl2vl_ktype = { + .release = qib_port_release, + .sysfs_ops = &qib_sl2vl_ops, + .default_attrs = sl2vl_default_attributes +}; + +/* End sl2vl */ + +/* Start diag_counters */ + +#define QIB_DIAGC_ATTR (N ) \ + static struct qib_diagc_attr qib_diagc_attr_##N = { \ + .attr = { .name = __stringify(N), .mode = 0444 }, \ + .counter = offsetof(struct qib_ibport, n_##N) \ + } + +struct qib_diagc_attr { +struct attribute attr; +size_t counter; +}; + +QIB_DIAGC_ATTR (rc_resends); +QIB_DIAGC_ATTR (rc_acks); +QIB_DIAGC_ATTR (rc_qacks); +QIB_DIAGC_ATTR (rc_delayed_comp); +QIB_DIAGC_ATTR (seq_naks); +QIB_DIAGC_ATTR (rdma_seq); +QIB_DIAGC_ATTR (rnr_naks); +QIB_DIAGC_ATTR (other_naks); +QIB_DIAGC_ATTR (rc_timeouts); +QIB_DIAGC_ATTR (loop_pkts); +QIB_DIAGC_ATTR (pkt_drops); +QIB_DIAGC_ATTR (dmawait); +QIB_DIAGC_ATTR (unaligned); +QIB_DIAGC_ATTR (rc_dupreq); +QIB_DIAGC_ATTR (rc_seqnak); + +static struct attribute *diagc_default_attributes[] = { + &qib_diagc_attr_rc_resends.attr, + &qib_diagc_attr_rc_acks.attr, + &qib_diagc_attr_rc_qacks.attr, + &qib_diagc_attr_rc_delayed_comp.attr, + &qib_diagc_attr_seq_naks.attr, + &qib_diagc_attr_rdma_seq.attr, + &qib_diagc_attr_rnr_naks.attr, + &qib_diagc_attr_other_naks.attr, + &qib_diagc_attr_rc_timeouts.attr, + &qib_diagc_attr_loop_pkts.attr, + &qib_diagc_attr_pkt_drops.attr, + &qib_diagc_attr_dmawait.attr, + &qib_diagc_attr_unaligned.attr, + &qib_diagc_attr_rc_dupreq.attr, + &qib_diagc_attr_rc_seqnak.attr, +NULL +}; + +static ssize_t diagc_attr_show (struct kobject *kobj,struct attribute *attr, +char *buf) +{ +struct qib_diagc_attr *dattr = + container_of(attr, struct qib_diagc_attr, attr); +struct qib_pportdata *ppd = + container_of(kobj, struct qib_pportdata, diagc_kobj); +struct qib_ibport *qibp = &ppd->ibport_data; + +return sprintf (buf,"%u\n" , *(u32 *)((char *)qibp + dattr->counter)); +} + +static const struct sysfs_ops qib_diagc_ops = { + .show = diagc_attr_show, +}; + +static struct kobj_type qib_diagc_ktype = { + .release = qib_port_release, + .sysfs_ops = &qib_diagc_ops, + .default_attrs = diagc_default_attributes +}; + +/* End diag_counters */ + +/* end of per-port file structures and support code */ + +/* +* Start of per-unit (or driver, in some cases, but replicated +* per unit) functions (these get a device *) +*/ +static ssize_t show_rev (struct device *device,struct device_attribute *attr, +char *buf) +{ +struct qib_ibdev *dev = + container_of(device, struct qib_ibdev, ibdev.dev); + +return sprintf (buf,"%x\n" ,dd_from_dev (dev)->minrev); +} + +static ssize_t show_hca (struct device *device,struct device_attribute *attr, +char *buf) +{ +struct qib_ibdev *dev = + container_of(device, struct qib_ibdev, ibdev.dev); +struct qib_devdata *dd =dd_from_dev (dev); +int ret; + +if (!dd->boardname) + ret = -EINVAL ; +else + ret =scnprintf (buf,PAGE_SIZE ,"%s\n" , dd->boardname); +return ret; +} + +static ssize_t show_version (struct device *device, +struct device_attribute *attr,char *buf) +{ +/* The string printed here is already newline-terminated. */ +return scnprintf (buf,PAGE_SIZE ,"%s" , (char *)ib_qib_version); +} + +static ssize_t show_boardversion (struct device *device, +struct device_attribute *attr,char *buf) +{ +struct qib_ibdev *dev = + container_of(device, struct qib_ibdev, ibdev.dev); +struct qib_devdata *dd =dd_from_dev (dev); + +/* The string printed here is already newline-terminated. */ +return scnprintf (buf,PAGE_SIZE ,"%s" , dd->boardversion); +} + + +static ssize_t show_localbus_info (struct device *device, +struct device_attribute *attr,char *buf) +{ +struct qib_ibdev *dev = + container_of(device, struct qib_ibdev, ibdev.dev); +struct qib_devdata *dd =dd_from_dev (dev); + +/* The string printed here is already newline-terminated. */ +return scnprintf (buf,PAGE_SIZE ,"%s" , dd->lbus_info); +} + + +static ssize_t show_nctxts (struct device *device, +struct device_attribute *attr,char *buf) +{ +struct qib_ibdev *dev = + container_of(device, struct qib_ibdev, ibdev.dev); +struct qib_devdata *dd =dd_from_dev (dev); + +/* Return the number of user ports (contexts) available. */ +return scnprintf (buf,PAGE_SIZE ,"%u\n" , dd->cfgctxts - + dd->first_user_ctxt); +} + +static ssize_t show_serial (struct device *device, +struct device_attribute *attr,char *buf) +{ +struct qib_ibdev *dev = + container_of(device, struct qib_ibdev, ibdev.dev); +struct qib_devdata *dd =dd_from_dev (dev); + + buf[sizeof dd->serial] ='\0' ; +memcpy (buf, dd->serial,sizeof dd->serial); +strcat (buf,"\n" ); +return strlen (buf); +} + +static ssize_t store_chip_reset (struct device *device, +struct device_attribute *attr,const char *buf, +size_t count) +{ +struct qib_ibdev *dev = + container_of(device, struct qib_ibdev, ibdev.dev); +struct qib_devdata *dd =dd_from_dev (dev); +int ret; + +if (count <5 ||memcmp (buf,"reset" ,5 ) || !dd->diag_client) { + ret = -EINVAL ; + goto bail; + } + + ret =qib_reset_device (dd->unit); +bail: +return ret <0 ? ret : count; +} + +static ssize_t show_logged_errs (struct device *device, +struct device_attribute *attr,char *buf) +{ +struct qib_ibdev *dev = + container_of(device, struct qib_ibdev, ibdev.dev); +struct qib_devdata *dd =dd_from_dev (dev); +int idx, count; + +/* force consistency with actual EEPROM */ +if (qib_update_eeprom_log (dd) !=0 ) +return -ENXIO ; + + count =0 ; +for (idx =0 ; idx <QIB_EEP_LOG_CNT ; ++idx) { + count +=scnprintf (buf + count,PAGE_SIZE - count,"%d%c" , + dd->eep_st_errs[idx], + idx == (QIB_EEP_LOG_CNT -1 ) ?'\n' :' ' ); + } + +return count; +} + +/* +* Dump tempsense regs. in decimal, to ease shell-scripts. +*/ +static ssize_t show_tempsense (struct device *device, +struct device_attribute *attr,char *buf) +{ +struct qib_ibdev *dev = + container_of(device, struct qib_ibdev, ibdev.dev); +struct qib_devdata *dd =dd_from_dev (dev); +int ret; +int idx; +u8 regvals[8 ]; + + ret = -ENXIO ; +for (idx =0 ; idx <8 ; ++idx) { +if (idx ==6 ) +continue ; + ret = dd->f_tempsense_rd (dd, idx); +if (ret <0 ) +break ; + regvals[idx] = ret; + } +if (idx ==8 ) + ret =scnprintf (buf,PAGE_SIZE ,"%d %d %02X %02X %d %d\n" , + *(signed char *)(regvals), + *(signed char *)(regvals +1 ), + regvals[2 ], regvals[3 ], + *(signed char *)(regvals +5 ), + *(signed char *)(regvals +7 )); +return ret; +} + +/* +* end of per-unit (or driver, in some cases, but replicated +* per unit) functions +*/ + +/* start of per-unit file structures and support code */ +static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); +static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); +static DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL); +static DEVICE_ATTR(version, S_IRUGO, show_version, NULL); +static DEVICE_ATTR(nctxts, S_IRUGO, show_nctxts, NULL); +static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); +static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL); +static DEVICE_ATTR(logged_errors, S_IRUGO, show_logged_errs, NULL); +static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL); +static DEVICE_ATTR(localbus_info, S_IRUGO, show_localbus_info, NULL); +static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset); + +static struct device_attribute *qib_attributes[] = { + &dev_attr_hw_rev, + &dev_attr_hca_type, + &dev_attr_board_id, + &dev_attr_version, + &dev_attr_nctxts, + &dev_attr_serial, + &dev_attr_boardversion, + &dev_attr_logged_errors, + &dev_attr_tempsense, + &dev_attr_localbus_info, + &dev_attr_chip_reset, +}; + +int qib_create_port_files (struct ib_device *ibdev,u8 port_num, +struct kobject *kobj) +{ +struct qib_pportdata *ppd; +struct qib_devdata *dd =dd_from_ibdev (ibdev); +int ret; + +if (!port_num || port_num > dd->num_pports) { +qib_dev_err (dd,"Skipping infiniband class with " +"invalid port %u\n" , port_num); + ret = -ENODEV ; + goto bail; + } + ppd = &dd->pport[port_num -1 ]; + + ret =kobject_init_and_add (&ppd->pport_kobj, &qib_port_ktype, kobj, +"linkcontrol" ); +if (ret) { +qib_dev_err (dd,"Skipping linkcontrol sysfs info, " +"(err %d) port %u\n" , ret, port_num); + goto bail; + } +kobject_uevent (&ppd->pport_kobj,KOBJ_ADD ); + + ret =kobject_init_and_add (&ppd->sl2vl_kobj, &qib_sl2vl_ktype, kobj, +"sl2vl" ); +if (ret) { +qib_dev_err (dd,"Skipping sl2vl sysfs info, " +"(err %d) port %u\n" , ret, port_num); + goto bail_sl; + } +kobject_uevent (&ppd->sl2vl_kobj,KOBJ_ADD ); + + ret =kobject_init_and_add (&ppd->diagc_kobj, &qib_diagc_ktype, kobj, +"diag_counters" ); +if (ret) { +qib_dev_err (dd,"Skipping diag_counters sysfs info, " +"(err %d) port %u\n" , ret, port_num); + goto bail_diagc; + } +kobject_uevent (&ppd->diagc_kobj,KOBJ_ADD ); + +return 0 ; + +bail_diagc: +kobject_put (&ppd->sl2vl_kobj); +bail_sl: +kobject_put (&ppd->pport_kobj); +bail: +return ret; +} + +/* +* Register and create our files in /sys/class/infiniband. +*/ +int qib_verbs_register_sysfs (struct qib_devdata *dd) +{ +struct ib_device *dev = &dd->verbs_dev.ibdev; +int i, ret; + +for (i =0 ; i <ARRAY_SIZE (qib_attributes); ++i) { + ret =device_create_file (&dev->dev, qib_attributes[i]); +if (ret) +return ret; + } + +return 0 ; +} + +/* +* Unregister and remove our files in /sys/class/infiniband. +*/ +void qib_verbs_unregister_sysfs (struct qib_devdata *dd) +{ +struct qib_pportdata *ppd; +int i; + +for (i =0 ; i < dd->num_pports; i++) { + ppd = &dd->pport[i]; +kobject_put (&ppd->pport_kobj); +kobject_put (&ppd->sl2vl_kobj); + } +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 38/52 IB/qib: Add qib_twsi.c
In reply to a message not in the archivecreates the qib_twsi.c file.
---
drivers/infiniband/hw/qib/qib_twsi.c | 498 ++++++++++++++++++++++++++++++++++ 1 files changed, 498 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_twsi.c
drivers/infiniband/hw/qib/qib_twsi.c new file +498 -0
@@ -0,0 +1,498 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/delay.h> +#include <linux/pci.h> +#include <linux/vmalloc.h> + +#include "qib.h" + +/* +* QLogic_IB "Two Wire Serial Interface" driver. +* 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 teh 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 qlogic_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 qib_devdata *dd) +{ +/* +* implicit read of EXTStatus is as good as explicit +* read of scratch, if all we want to do is flush +* writes. +*/ + dd->f_gpio_mod (dd,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 +*/ +#define SCL_WAIT_USEC 1000 + +/* BUF_WAIT is time bus must be free between STOP or ACK and to next START. +* Should be 20, but some chips need more. +*/ +#define TWSI_BUF_WAIT_USEC 60 + +static void scl_out (struct qib_devdata *dd,u8 bit) +{ +u32 mask; + +udelay (1 ); + + mask =1UL << dd->gpio_scl_num; + +/* SCL is meant to be bare-drain, so never set "OUT", just DIR */ + dd->f_gpio_mod (dd,0 , bit ?0 : mask, mask); + +/* +* Allow for slow slaves by simple +* delay for falling edge, sampling on rise. +*/ +if (!bit) +udelay (2 ); +else { +int rise_usec; +for (rise_usec =SCL_WAIT_USEC ; rise_usec >0 ; rise_usec -=2 ) { +if (mask & dd->f_gpio_mod (dd,0 ,0 ,0 )) +break ; +udelay (2 ); + } +if (rise_usec <=0 ) +qib_dev_err (dd,"SCL interface stuck low > %d uSec\n" , +SCL_WAIT_USEC ); + } +i2c_wait_for_writes (dd); +} + +static void sda_out (struct qib_devdata *dd,u8 bit) +{ +u32 mask; + + mask =1UL << dd->gpio_sda_num; + +/* SDA is meant to be bare-drain, so never set "OUT", just DIR */ + dd->f_gpio_mod (dd,0 , bit ?0 : mask, mask); + +i2c_wait_for_writes (dd); +udelay (2 ); +} + +static u8 sda_in (struct qib_devdata *dd,int wait) +{ +int bnum; +u32 read_val, mask; + + bnum = dd->gpio_sda_num; + mask = (1UL << bnum); +/* SDA is meant to be bare-drain, so never set "OUT", just DIR */ + dd->f_gpio_mod (dd,0 ,0 , mask); + read_val = dd->f_gpio_mod (dd,0 ,0 ,0 ); +if (wait) +i2c_wait_for_writes (dd); +return (read_val & mask) >> bnum; +} + +/** +* i2c_ackrcv - see if ack following write is true +* @dd: the qlogic_ib device +*/ +static int i2c_ackrcv (struct qib_devdata *dd) +{ +u8 ack_received; + +/* AT ENTRY SCL = LOW */ +/* change direction, ignore data */ + ack_received =sda_in (dd,1 ); +scl_out (dd,1 ); + ack_received =sda_in (dd,1 ) ==0 ; +scl_out (dd,0 ); +return ack_received; +} + +static void stop_cmd (struct qib_devdata *dd); + +/** +* rd_byte - read a byte, sending STOP on last, else ACK +* @dd: the qlogic_ib device +* +* Returns byte shifted out of device +*/ +static int rd_byte (struct qib_devdata *dd,int last) +{ +int bit_cntr, data; + + data =0 ; + +for (bit_cntr =7 ; bit_cntr >=0 ; --bit_cntr) { + data <<=1 ; +scl_out (dd,1 ); + data |=sda_in (dd,0 ); +scl_out (dd,0 ); + } +if (last) { +scl_out (dd,1 ); +stop_cmd (dd); + }else { +sda_out (dd,0 ); +scl_out (dd,1 ); +scl_out (dd,0 ); +sda_out (dd,1 ); + } +return data; +} + +/** +* wr_byte - write a byte, one bit at a time +* @dd: the qlogic_ib device +* @data: the byte to write +* +* Returns 0 if we got the following ack, otherwise 1 +*/ +static int wr_byte (struct qib_devdata *dd,u8 data) +{ +int bit_cntr; +u8 bit; + +for (bit_cntr =7 ; bit_cntr >=0 ; bit_cntr--) { + bit = (data >> bit_cntr) &1 ; +sda_out (dd, bit); +scl_out (dd,1 ); +scl_out (dd,0 ); + } +return (!i2c_ackrcv (dd)) ?1 :0 ; +} + +/* +* issue TWSI start sequence: +* (both clock/data high, clock high, data low while clock is high) +*/ +static void start_seq (struct qib_devdata *dd) +{ +sda_out (dd,1 ); +scl_out (dd,1 ); +sda_out (dd,0 ); +udelay (1 ); +scl_out (dd,0 ); +} + +/** +* stop_seq - transmit the stop sequence +* @dd: the qlogic_ib device +* +* (both clock/data low, clock high, data high while clock is high) +*/ +static void stop_seq (struct qib_devdata *dd) +{ +scl_out (dd,0 ); +sda_out (dd,0 ); +scl_out (dd,1 ); +sda_out (dd,1 ); +} + +/** +* stop_cmd - transmit the stop condition +* @dd: the qlogic_ib device +* +* (both clock/data low, clock high, data high while clock is high) +*/ +static void stop_cmd (struct qib_devdata *dd) +{ +stop_seq (dd); +udelay (TWSI_BUF_WAIT_USEC ); +} + +/** +* qib_twsi_reset - reset I2C communication +* @dd: the qlogic_ib device +*/ + +int qib_twsi_reset (struct qib_devdata *dd) +{ +int clock_cycles_left =9 ; +int was_high =0 ; +u32 pins, mask; + +/* Both SCL and SDA should be high. If not, there +* is something wrong. +*/ + mask = (1UL << dd->gpio_scl_num) | (1UL << dd->gpio_sda_num); + +/* +* Force pins to desired innocuous state. +* This is the default power-on state with out=0 and dir=0, +* So tri-stated and should be floating high (barring HW problems) +*/ + dd->f_gpio_mod (dd,0 ,0 , mask); + +/* +* Clock nine times to get all listeners into a sane state. +* If SDA does not go high at any point, we are wedged. +* One vendor recommends then issuing START followed by STOP. +* we cannot use our "normal" functions to do that, because +* if SCL drops between them, another vendor's part will +* wedge, dropping SDA and keeping it low forever, at the end of +* the next transaction (even if it was not the device addressed). +* So our START and STOP take place with SCL held high. +*/ +while (clock_cycles_left--) { +scl_out (dd,0 ); +scl_out (dd,1 ); +/* Note if SDA is high, but keep clocking to sync slave */ + was_high |=sda_in (dd,0 ); + } + +if (was_high) { +/* +* We saw a high, which we hope means the slave is sync'd. +* Issue START, STOP, pause for T_BUF. +*/ + + pins = dd->f_gpio_mod (dd,0 ,0 ,0 ); +if ((pins & mask) != mask) +qib_dev_err (dd,"GPIO pins not at rest: %d\n" , + pins & mask); +/* Drop SDA to issue START */ +udelay (1 );/* Guarantee .6 uSec setup */ +sda_out (dd,0 ); +udelay (1 );/* Guarantee .6 uSec hold */ +/* At this point, SCL is high, SDA low. Raise SDA for STOP */ +sda_out (dd,1 ); +udelay (TWSI_BUF_WAIT_USEC ); + } + +return !was_high; +} + +#define QIB_TWSI_START 0x100 +#define QIB_TWSI_STOP 0x200 + +/* Write byte to TWSI, optionally prefixed with START or suffixed with +* STOP. +* returns 0 if OK (ACK received), else != 0 +*/ +static int qib_twsi_wr (struct qib_devdata *dd,int data,int flags) +{ +int ret =1 ; +if (flags &QIB_TWSI_START ) +start_seq (dd); + + ret =wr_byte (dd, data);/* Leaves SCL low (from i2c_ackrcv()) */ + +if (flags &QIB_TWSI_STOP ) +stop_cmd (dd); +return ret; +} + +/* Added functionality for IBA7220-based cards */ +#define QIB_TEMP_DEV 0x98 + +/* +* qib_twsi_blk_rd +* Formerly called qib_eeprom_internal_read, and only used for eeprom, +* but now the general interface for data transfer from twsi devices. +* One vestige of its former role is that it recognizes a device +* QIB_TWSI_NO_DEV and does the correct operation for the legacy part, +* which responded to all TWSI device codes, interpreting them as +* address within device. On all other devices found on board handled by +* this driver, the device is followed by a one-byte "address" which selects +* the "register" or "offset" within the device from which data should +* be read. +*/ +int qib_twsi_blk_rd (struct qib_devdata *dd,int dev,int addr, +void *buffer,int len) +{ +int ret; +u8 *bp = buffer; + + ret =1 ; + +if (dev ==QIB_TWSI_NO_DEV ) { +/* legacy not-really-I2C */ + addr = (addr <<1 ) |READ_CMD ; + ret =qib_twsi_wr (dd, addr,QIB_TWSI_START ); + }else { +/* Actual I2C */ + ret =qib_twsi_wr (dd, dev |WRITE_CMD ,QIB_TWSI_START ); +if (ret) { +stop_cmd (dd); + ret =1 ; + goto bail; + } +/* +* SFF spec claims we do _not_ stop after the addr +* but simply issue a start with the "read" dev-addr. +* Since we are implicitely waiting for ACK here, +* we need t_buf (nominally 20uSec) before that start, +* and cannot rely on the delay built in to the STOP +*/ + ret =qib_twsi_wr (dd, addr,0 ); +udelay (TWSI_BUF_WAIT_USEC ); + +if (ret) { +qib_dev_err (dd, +"Failed to write interface read addr %02X\n" , + addr); + ret =1 ; + goto bail; + } + ret =qib_twsi_wr (dd, dev |READ_CMD ,QIB_TWSI_START ); + } +if (ret) { +stop_cmd (dd); + ret =1 ; + goto bail; + } + +/* +* block devices keeps clocking data out as long as we ack, +* automatically incrementing the address. Some have "pages" +* whose boundaries will not be crossed, but the handling +* of these is left to the caller, who is in a better +* position to know. +*/ +while (len-- >0 ) { +/* +* Get and store data, sending ACK if length remaining, +* else STOP +*/ + *bp++ =rd_byte (dd, !len); + } + + ret =0 ; + +bail: +return ret; +} + +/* +* qib_twsi_blk_wr +* Formerly called qib_eeprom_internal_write, and only used for eeprom, +* but now the general interface for data transfer to twsi devices. +* One vestige of its former role is that it recognizes a device +* QIB_TWSI_NO_DEV and does the correct operation for the legacy part, +* which responded to all TWSI device codes, interpreting them as +* address within device. On all other devices found on board handled by +* this driver, the device is followed by a one-byte "address" which selects +* the "register" or "offset" within the device to which data should +* be written. +*/ +int qib_twsi_blk_wr (struct qib_devdata *dd,int dev,int addr, +const void *buffer,int len) +{ +int sub_len; +const u8 *bp = buffer; +int max_wait_time, i; +int ret; + ret =1 ; + +while (len >0 ) { +if (dev ==QIB_TWSI_NO_DEV ) { +if (qib_twsi_wr (dd, (addr <<1 ) |WRITE_CMD , +QIB_TWSI_START )) { + goto failed_write; + } + }else { +/* Real I2C */ +if (qib_twsi_wr (dd, dev |WRITE_CMD ,QIB_TWSI_START )) + goto failed_write; + ret =qib_twsi_wr (dd, addr,0 ); +if (ret) { +qib_dev_err (dd,"Failed to write interface" +" write addr %02X\n" , addr); + goto failed_write; + } + } + + sub_len =min (len,4 ); + addr += sub_len; + len -= sub_len; + +for (i =0 ; i < sub_len; i++) +if (qib_twsi_wr (dd, *bp++,0 )) + goto failed_write; + +stop_cmd (dd); + +/* +* Wait for write complete by waiting for a successful +* read (the chip replies with a zero after the write +* cmd completes, and before it writes to the eeprom. +* The startcmd for the read will fail the ack until +* the writes have completed. We do this inline to avoid +* the debug prints that are in the real read routine +* if the startcmd fails. +* We also use the proper device address, so it doesn't matter +* whether we have real eeprom_dev. Legacy likes any address. +*/ + max_wait_time =100 ; +while (qib_twsi_wr (dd, dev |READ_CMD ,QIB_TWSI_START )) { +stop_cmd (dd); +if (!--max_wait_time) + goto failed_write; + } +/* now read (and ignore) the resulting byte */ +rd_byte (dd,1 ); + } + + ret =0 ; + goto bail; + +failed_write: +stop_cmd (dd); + ret =1 ; + +bail: +return ret; +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 39/52 IB/qib: Add qib_tx.c
In reply to a message not in the archivecreates the qib_tx.c file.
---
drivers/infiniband/hw/qib/qib_tx.c | 557 ++++++++++++++++++++++++++++++++++++ 1 files changed, 557 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_tx.c
drivers/infiniband/hw/qib/qib_tx.c new file +557 -0
@@ -0,0 +1,557 @@ +/* +* Copyright (c) 2008, 2009, 2010 QLogic Corporation. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/spinlock.h> +#include <linux/pci.h> +#include <linux/io.h> +#include <linux/delay.h> +#include <linux/netdevice.h> +#include <linux/vmalloc.h> + +#include "qib.h" + +static unsigned qib_hol_timeout_ms =3000 ; +module_param_named (hol_timeout_ms, qib_hol_timeout_ms, uint,S_IRUGO ); +MODULE_PARM_DESC (hol_timeout_ms, +"duration of user app suspension after link failure" ); + +unsigned qib_sdma_fetch_arb =1 ; +module_param_named (fetch_arb, qib_sdma_fetch_arb, uint,S_IRUGO ); +MODULE_PARM_DESC (fetch_arb,"IBA7220: change SDMA descriptor arbitration" ); + +/** +* qib_disarm_piobufs - cancel a range of PIO buffers +* @dd: the qlogic_ib device +* @first: the first PIO buffer to cancel +* @cnt: the number of PIO buffers to cancel +* +* Cancel a range of PIO buffers. Used at user process close, +* in case it died while writing to a PIO buffer. +*/ +void qib_disarm_piobufs (struct qib_devdata *dd,unsigned first,unsigned cnt) +{ +unsigned long flags; +unsigned i; +unsigned last; + + last = first + cnt; +spin_lock_irqsave (&dd->pioavail_lock, flags); +for (i = first; i < last; i++) { +__clear_bit (i, dd->pio_need_disarm); + dd->f_sendctrl (dd->pport,QIB_SENDCTRL_DISARM_BUF (i)); + } +spin_unlock_irqrestore (&dd->pioavail_lock, flags); +} + +/* +* This is called by a user process when it sees the DISARM_BUFS event +* bit is set. +*/ +int qib_disarm_piobufs_ifneeded (struct qib_ctxtdata *rcd) +{ +struct qib_devdata *dd = rcd->dd; +unsigned i; +unsigned last; +unsigned n =0 ; + + last = rcd->pio_base + rcd->piocnt; +/* +* Don't need uctxt_lock here, since user has called in to us. +* Clear at start in case more interrupts set bits while we +* are disarming +*/ +if (rcd->user_event_mask) { +/* +* subctxt_cnt is 0 if not shared, so do base +* separately, first, then remaining subctxt, if any +*/ +clear_bit (_QIB_EVENT_DISARM_BUFS_BIT, &rcd->user_event_mask[0 ]); +for (i =1 ; i < rcd->subctxt_cnt; i++) +clear_bit (_QIB_EVENT_DISARM_BUFS_BIT, + &rcd->user_event_mask[i]); + } +spin_lock_irq (&dd->pioavail_lock); +for (i = rcd->pio_base; i < last; i++) { +if (__test_and_clear_bit (i, dd->pio_need_disarm)) { + n++; + dd->f_sendctrl (rcd->ppd,QIB_SENDCTRL_DISARM_BUF (i)); + } + } +spin_unlock_irq (&dd->pioavail_lock); +return 0 ; +} + +static struct qib_pportdata *is_sdma_buf (struct qib_devdata *dd,unsigned i) +{ +struct qib_pportdata *ppd; +unsigned pidx; + +for (pidx =0 ; pidx < dd->num_pports; pidx++) { + ppd = dd->pport + pidx; +if (i >= ppd->sdma_state.first_sendbuf && + i < ppd->sdma_state.last_sendbuf) +return ppd; + } +return NULL ; +} + +/* +* Return true if send buffer is being used by a user context. +* Sets _QIB_EVENT_DISARM_BUFS_BIT in user_event_mask as a side effect +*/ +static int find_ctxt (struct qib_devdata *dd,unsigned bufn) +{ +struct qib_ctxtdata *rcd; +unsigned ctxt; +int ret =0 ; + +spin_lock (&dd->uctxt_lock); +for (ctxt = dd->first_user_ctxt; ctxt < dd->cfgctxts; ctxt++) { + rcd = dd->rcd[ctxt]; +if (!rcd || bufn < rcd->pio_base || + bufn >= rcd->pio_base + rcd->piocnt) +continue ; +if (rcd->user_event_mask) { +int i; +/* +* subctxt_cnt is 0 if not shared, so do base +* separately, first, then remaining subctxt, if any +*/ +set_bit (_QIB_EVENT_DISARM_BUFS_BIT, + &rcd->user_event_mask[0 ]); +for (i =1 ; i < rcd->subctxt_cnt; i++) +set_bit (_QIB_EVENT_DISARM_BUFS_BIT, + &rcd->user_event_mask[i]); + } + ret =1 ; +break ; + } +spin_unlock (&dd->uctxt_lock); + +return ret; +} + +/* +* Disarm a set of send buffers. If the buffer might be actively being +* written to, mark the buffer to be disarmed later when it is not being +* written to. +* +* This should only be called from the IRQ error handler. +*/ +void qib_disarm_piobufs_set (struct qib_devdata *dd,unsigned long *mask, +unsigned cnt) +{ +struct qib_pportdata *ppd, *pppd[dd->num_pports]; +unsigned i; +unsigned long flags; + +for (i =0 ; i < dd->num_pports; i++) + pppd[i] =NULL ; + +for (i =0 ; i < cnt; i++) { +int which; +if (!test_bit (i, mask)) +continue ; +/* +* If the buffer is owned by the DMA hardware, +* reset the DMA engine. +*/ + ppd =is_sdma_buf (dd, i); +if (ppd) { + pppd[ppd->port] = ppd; +continue ; + } +/* +* If the kernel is writing the buffer or the buffer is +* owned by a user process, we can't clear it yet. +*/ +spin_lock_irqsave (&dd->pioavail_lock, flags); +if (test_bit (i, dd->pio_writing) || + (!test_bit (i <<1 , dd->pioavailkernel) && +find_ctxt (dd, i))) { +__set_bit (i, dd->pio_need_disarm); + which =0 ; + }else { + which =1 ; + dd->f_sendctrl (dd->pport,QIB_SENDCTRL_DISARM_BUF (i)); + } +spin_unlock_irqrestore (&dd->pioavail_lock, flags); + } + +/* do cancel_sends once per port that had sdma piobufs in error */ +for (i =0 ; i < dd->num_pports; i++) +if (pppd[i]) +qib_cancel_sends (pppd[i]); +} + +/** +* update_send_bufs - update shadow copy of the PIO availability map +* @dd: the qlogic_ib device +* +* called whenever our local copy indicates we have run out of send buffers +*/ +static void update_send_bufs (struct qib_devdata *dd) +{ +unsigned long flags; +unsigned i; +const unsigned piobregs = dd->pioavregs; + +/* +* If the generation (check) bits have changed, then we update the +* busy bit for the corresponding PIO buffer. This algorithm will +* modify positions to the value they already have in some cases +* (i.e., no change), but it's faster than changing only the bits +* that have changed. +* +* We would like to do this atomicly, to avoid spinlocks in the +* critical send path, but that's not really possible, given the +* type of changes, and that this routine could be called on +* multiple cpu's simultaneously, so we lock in this routine only, +* to avoid conflicting updates; all we change is the shadow, and +* it's a single 64 bit memory location, so by definition the update +* is atomic in terms of what other cpu's can see in testing the +* bits. The spin_lock overhead isn't too bad, since it only +* happens when all buffers are in use, so only cpu overhead, not +* latency or bandwidth is affected. +*/ +if (!dd->pioavailregs_dma) +return ; +spin_lock_irqsave (&dd->pioavail_lock, flags); +for (i =0 ; i < piobregs; i++) { +u64 pchbusy, pchg, piov, pnew; + + piov =le64_to_cpu (dd->pioavailregs_dma[i]); + pchg = dd->pioavailkernel[i] & + ~(dd->pioavailshadow[i] ^ piov); + pchbusy = pchg <<QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT ; +if (pchg && (pchbusy & dd->pioavailshadow[i])) { + pnew = dd->pioavailshadow[i] & ~pchbusy; + pnew |= piov & pchbusy; + dd->pioavailshadow[i] = pnew; + } + } +spin_unlock_irqrestore (&dd->pioavail_lock, flags); +} + +/* +* Debugging code and stats updates if no pio buffers available. +*/ +static noinline void no_send_bufs(struct qib_devdata *dd) +{ + dd->upd_pio_shadow =1 ; + +/* not atomic, but if we lose a stat count in a while, that's OK */ + qib_stats.sps_nopiobufs++; +} + +/* +* Common code for normal driver send buffer allocation, and reserved +* allocation. +* +* Do appropriate marking as busy, etc. +* Returns buffer pointer if one is found, otherwise NULL. +*/ +u32 __iomem *qib_getsendbuf_range (struct qib_devdata *dd,u32 *pbufnum, +u32 first,u32 last) +{ +unsigned i, j, updated =0 ; +unsigned nbufs; +unsigned long flags; +unsigned long *shadow = dd->pioavailshadow; +u32 __iomem *buf; + +if (!(dd->flags &QIB_PRESENT )) +return NULL ; + + nbufs = last - first +1 ;/* number in range to check */ +if (dd->upd_pio_shadow) { +/* +* Minor optimization. If we had no buffers on last call, +* start out by doing the update; continue and do scan even +* if no buffers were updated, to be paranoid. +*/ +update_send_bufs (dd); + updated++; + } + i = first; +rescan: +/* +* While test_and_set_bit() is atomic, we do that and then the +* change_bit(), and the pair is not. See if this is the cause +* of the remaining armlaunch errors. +*/ +spin_lock_irqsave (&dd->pioavail_lock, flags); +for (j =0 ; j < nbufs; j++, i++) { +if (i > last) + i = first; +if (__test_and_set_bit ((2 * i) +1 , shadow)) +continue ; +/* flip generation bit */ +__change_bit (2 * i, shadow); +/* remember that the buffer can be written to now */ +__set_bit (i, dd->pio_writing); +break ; + } +spin_unlock_irqrestore (&dd->pioavail_lock, flags); + +if (j == nbufs) { +if (!updated) { +/* +* First time through; shadow exhausted, but may be +* buffers available, try an update and then rescan. +*/ +update_send_bufs (dd); + updated++; + i = first; + goto rescan; + } +no_send_bufs (dd); + buf =NULL ; + }else { +if (i < dd->piobcnt2k) + buf = (u32 __iomem *)(dd->pio2kbase + + i * dd->palign); +else + buf = (u32 __iomem *)(dd->pio4kbase + + (i - dd->piobcnt2k) * dd->align4k); +if (pbufnum) + *pbufnum = i; + dd->upd_pio_shadow =0 ; + } + +return buf; +} + +/* +* Record that the caller is finished writing to the buffer so we don't +* disarm it while it is being written and disarm it now if needed. +*/ +void qib_sendbuf_done (struct qib_devdata *dd,unsigned n) +{ +unsigned long flags; + +spin_lock_irqsave (&dd->pioavail_lock, flags); +__clear_bit (n, dd->pio_writing); +if (__test_and_clear_bit (n, dd->pio_need_disarm)) + dd->f_sendctrl (dd->pport,QIB_SENDCTRL_DISARM_BUF (n)); +spin_unlock_irqrestore (&dd->pioavail_lock, flags); +} + +/** +* qib_chg_pioavailkernel - change which send buffers are available for kernel +* @dd: the qlogic_ib device +* @start: the starting send buffer number +* @len: the number of send buffers +* @avail: true if the buffers are available for kernel use, false otherwise +*/ +void qib_chg_pioavailkernel (struct qib_devdata *dd,unsigned start, +unsigned len,u32 avail,struct qib_ctxtdata *rcd) +{ +unsigned long flags; +unsigned end; +unsigned ostart = start; + +/* There are two bits per send buffer (busy and generation) */ + start *=2 ; + end = start + len *2 ; + +spin_lock_irqsave (&dd->pioavail_lock, flags); +/* Set or clear the busy bit in the shadow. */ +while (start < end) { +if (avail) { +unsigned long dma; +int i; + +/* +* The BUSY bit will never be set, because we disarm +* the user buffers before we hand them back to the +* kernel. We do have to make sure the generation +* bit is set correctly in shadow, since it could +* have changed many times while allocated to user. +* We can't use the bitmap functions on the full +* dma array because it is always little-endian, so +* we have to flip to host-order first. +* BITS_PER_LONG is slightly wrong, since it's +* always 64 bits per register in chip... +* We only work on 64 bit kernels, so that's OK. +*/ + i = start /BITS_PER_LONG ; +__clear_bit (QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT + start, + dd->pioavailshadow); + dma = (unsigned long ) +le64_to_cpu (dd->pioavailregs_dma[i]); +if (test_bit ((QLOGIC_IB_SENDPIOAVAIL_CHECK_SHIFT + + start) %BITS_PER_LONG , &dma)) +__set_bit (QLOGIC_IB_SENDPIOAVAIL_CHECK_SHIFT + + start, dd->pioavailshadow); +else +__clear_bit (QLOGIC_IB_SENDPIOAVAIL_CHECK_SHIFT + + start, dd->pioavailshadow); +__set_bit (start, dd->pioavailkernel); + }else { +__set_bit (start +QLOGIC_IB_SENDPIOAVAIL_BUSY_SHIFT , + dd->pioavailshadow); +__clear_bit (start, dd->pioavailkernel); + } + start +=2 ; + } + +spin_unlock_irqrestore (&dd->pioavail_lock, flags); + + dd->f_txchk_change (dd, ostart, len, avail, rcd); +} + +/* +* Flush all sends that might be in the ready to send state, as well as any +* that are in the process of being sent. Used whenever we need to be +* sure the send side is idle. Cleans up all buffer state by canceling +* all pio buffers, and issuing an abort, which cleans up anything in the +* launch fifo. The cancel is superfluous on some chip versions, but +* it's safer to always do it. +* PIOAvail bits are updated by the chip as if a normal send had happened. +*/ +void qib_cancel_sends (struct qib_pportdata *ppd) +{ +struct qib_devdata *dd = ppd->dd; +struct qib_ctxtdata *rcd; +unsigned long flags; +unsigned ctxt; +unsigned i; +unsigned last; + +/* +* Tell PSM to disarm buffers again before trying to reuse them. +* We need to be sure the rcd doesn't change out from under us +* while we do so. We hold the two locks sequentially. We might +* needlessly set some need_disarm bits as a result, if the +* context is closed after we release the uctxt_lock, but that's +* fairly benign, and safer than nesting the locks. +*/ +for (ctxt = dd->first_user_ctxt; ctxt < dd->cfgctxts; ctxt++) { +spin_lock_irqsave (&dd->uctxt_lock, flags); + rcd = dd->rcd[ctxt]; +if (rcd && rcd->ppd == ppd) { + last = rcd->pio_base + rcd->piocnt; +if (rcd->user_event_mask) { +/* +* subctxt_cnt is 0 if not shared, so do base +* separately, first, then remaining subctxt, +* if any +*/ +set_bit (_QIB_EVENT_DISARM_BUFS_BIT, + &rcd->user_event_mask[0 ]); +for (i =1 ; i < rcd->subctxt_cnt; i++) +set_bit (_QIB_EVENT_DISARM_BUFS_BIT, + &rcd->user_event_mask[i]); + } + i = rcd->pio_base; +spin_unlock_irqrestore (&dd->uctxt_lock, flags); +spin_lock_irqsave (&dd->pioavail_lock, flags); +for (; i < last; i++) +__set_bit (i, dd->pio_need_disarm); +spin_unlock_irqrestore (&dd->pioavail_lock, flags); + }else +spin_unlock_irqrestore (&dd->uctxt_lock, flags); + } + +if (!(dd->flags &QIB_HAS_SEND_DMA )) + dd->f_sendctrl (ppd,QIB_SENDCTRL_DISARM_ALL | +QIB_SENDCTRL_FLUSH ); +} + +/* +* Force an update of in-memory copy of the pioavail registers, when +* needed for any of a variety of reasons. +* If already off, this routine is a nop, on the assumption that the +* caller (or set of callers) will "do the right thing". +* This is a per-device operation, so just the first port. +*/ +void qib_force_pio_avail_update (struct qib_devdata *dd) +{ + dd->f_sendctrl (dd->pport,QIB_SENDCTRL_AVAIL_BLIP ); +} + +void qib_hol_down (struct qib_pportdata *ppd) +{ +/* +* Cancel sends when the link goes DOWN so that we aren't doing it +* at INIT when we might be trying to send SMI packets. +*/ +if (!(ppd->lflags &QIBL_IB_AUTONEG_INPROG )) +qib_cancel_sends (ppd); +} + +/* +* Link is at INIT. +* We start the HoL timer so we can detect stuck packets blocking SMP replies. +* Timer may already be running, so use mod_timer, not add_timer. +*/ +void qib_hol_init (struct qib_pportdata *ppd) +{ +if (ppd->hol_state !=QIB_HOL_INIT ) { + ppd->hol_state =QIB_HOL_INIT ; +mod_timer (&ppd->hol_timer, + jiffies +msecs_to_jiffies (qib_hol_timeout_ms)); + } +} + +/* +* Link is up, continue any user processes, and ensure timer +* is a nop, if running. Let timer keep running, if set; it +* will nop when it sees the link is up. +*/ +void qib_hol_up (struct qib_pportdata *ppd) +{ + ppd->hol_state =QIB_HOL_UP ; +} + +/* +* This is only called via the timer. +*/ +void qib_hol_event (unsigned long opaque) +{ +struct qib_pportdata *ppd = (struct qib_pportdata *)opaque; + +/* If hardware error, etc, skip. */ +if (!(ppd->dd->flags &QIB_INITTED )) +return ; + +if (ppd->hol_state !=QIB_HOL_UP ) { +/* +* Try to flush sends in case a stuck packet is blocking +* SMP replies. +*/ +qib_hol_down (ppd); +mod_timer (&ppd->hol_timer, + jiffies +msecs_to_jiffies (qib_hol_timeout_ms)); + } +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 40/52 IB/qib: Add qib_uc.c
In reply to a message not in the archivecreates the qib_uc.c file.
---
drivers/infiniband/hw/qib/qib_uc.c | 555 ++++++++++++++++++++++++++++++++++++ 1 files changed, 555 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_uc.c
drivers/infiniband/hw/qib/qib_uc.c new file +555 -0
@@ -0,0 +1,555 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation. +* All rights reserved. +* Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include "qib.h" + +/* cut down ridiculously long IB macro names */ +#define OP (x) IB_OPCODE_UC_##x + +/** +* qib_make_uc_req - construct a request packet (SEND, RDMA write) +* @qp: a pointer to the QP +* +* Return 1 if constructed; otherwise, return 0. +*/ +int qib_make_uc_req (struct qib_qp *qp) +{ +struct qib_other_headers *ohdr; +struct qib_swqe *wqe; +unsigned long flags; +u32 hwords; +u32 bth0; +u32 len; +u32 pmtu =ib_mtu_enum_to_int (qp->path_mtu); +int ret =0 ; + +spin_lock_irqsave (&qp->s_lock, flags); + +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_SEND_OK )) { +if (!(ib_qib_state_ops[qp->state] &QIB_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_dma_busy)) { + qp->s_flags |=QIB_S_WAIT_DMA ; + goto bail; + } + wqe =get_swqe_ptr (qp, qp->s_last); +qib_send_complete (qp, wqe,IB_WC_WR_FLUSH_ERR ); + goto done; + } + + ohdr = &qp->s_hdr.u.oth; +if (qp->remote_ah_attr.ah_flags &IB_AH_GRH ) + ohdr = &qp->s_hdr.u.l.oth; + +/* header size in 32-bit words LRH+BTH = (8+12)/4. */ + hwords =5 ; + bth0 =0 ; + +/* Get the next send request. */ + wqe =get_swqe_ptr (qp, qp->s_cur); + qp->s_wqe =NULL ; +switch (qp->s_state) { +default : +if (!(ib_qib_state_ops[qp->state] & +QIB_PROCESS_NEXT_SEND_OK )) + goto bail; +/* Check if send work queue is empty. */ +if (qp->s_cur == qp->s_head) + goto bail; +/* +* Start a new request. +*/ + wqe->psn = qp->s_next_psn; + qp->s_psn = qp->s_next_psn; + qp->s_sge.sge = wqe->sg_list[0 ]; + qp->s_sge.sg_list = wqe->sg_list +1 ; + qp->s_sge.num_sge = wqe->wr.num_sge; + qp->s_sge.total_len = wqe->length; + len = wqe->length; + qp->s_len = len; +switch (wqe->wr.opcode) { +case IB_WR_SEND : +case IB_WR_SEND_WITH_IMM : +if (len > pmtu) { + qp->s_state =OP (SEND_FIRST ); + len = pmtu; +break ; + } +if (wqe->wr.opcode ==IB_WR_SEND ) + qp->s_state =OP (SEND_ONLY ); +else { + qp->s_state = +OP (SEND_ONLY_WITH_IMMEDIATE ); +/* Immediate data comes after the BTH */ + ohdr->u.imm_data = wqe->wr.ex.imm_data; + hwords +=1 ; + } +if (wqe->wr.send_flags &IB_SEND_SOLICITED ) + bth0 |=IB_BTH_SOLICITED ; + qp->s_wqe = wqe; +if (++qp->s_cur >= qp->s_size) + qp->s_cur =0 ; +break ; + +case IB_WR_RDMA_WRITE : +case IB_WR_RDMA_WRITE_WITH_IMM : + ohdr->u.rc.reth.vaddr = +cpu_to_be64 (wqe->wr.wr.rdma.remote_addr); + ohdr->u.rc.reth.rkey = +cpu_to_be32 (wqe->wr.wr.rdma.rkey); + ohdr->u.rc.reth.length =cpu_to_be32 (len); + hwords +=sizeof (struct ib_reth ) /4 ; +if (len > pmtu) { + qp->s_state =OP (RDMA_WRITE_FIRST ); + len = pmtu; +break ; + } +if (wqe->wr.opcode ==IB_WR_RDMA_WRITE ) + qp->s_state =OP (RDMA_WRITE_ONLY ); +else { + qp->s_state = +OP (RDMA_WRITE_ONLY_WITH_IMMEDIATE ); +/* Immediate data comes after the RETH */ + ohdr->u.rc.imm_data = wqe->wr.ex.imm_data; + hwords +=1 ; +if (wqe->wr.send_flags &IB_SEND_SOLICITED ) + bth0 |=IB_BTH_SOLICITED ; + } + qp->s_wqe = wqe; +if (++qp->s_cur >= qp->s_size) + qp->s_cur =0 ; +break ; + +default : + goto bail; + } +break ; + +case OP (SEND_FIRST ): + qp->s_state =OP (SEND_MIDDLE ); +/* FALLTHROUGH */ +case OP (SEND_MIDDLE ): + len = qp->s_len; +if (len > pmtu) { + len = pmtu; +break ; + } +if (wqe->wr.opcode ==IB_WR_SEND ) + qp->s_state =OP (SEND_LAST ); +else { + qp->s_state =OP (SEND_LAST_WITH_IMMEDIATE ); +/* Immediate data comes after the BTH */ + ohdr->u.imm_data = wqe->wr.ex.imm_data; + hwords +=1 ; + } +if (wqe->wr.send_flags &IB_SEND_SOLICITED ) + bth0 |=IB_BTH_SOLICITED ; + qp->s_wqe = wqe; +if (++qp->s_cur >= qp->s_size) + qp->s_cur =0 ; +break ; + +case OP (RDMA_WRITE_FIRST ): + qp->s_state =OP (RDMA_WRITE_MIDDLE ); +/* FALLTHROUGH */ +case OP (RDMA_WRITE_MIDDLE ): + len = qp->s_len; +if (len > pmtu) { + len = pmtu; +break ; + } +if (wqe->wr.opcode ==IB_WR_RDMA_WRITE ) + qp->s_state =OP (RDMA_WRITE_LAST ); +else { + qp->s_state = +OP (RDMA_WRITE_LAST_WITH_IMMEDIATE ); +/* Immediate data comes after the BTH */ + ohdr->u.imm_data = wqe->wr.ex.imm_data; + hwords +=1 ; +if (wqe->wr.send_flags &IB_SEND_SOLICITED ) + bth0 |=IB_BTH_SOLICITED ; + } + qp->s_wqe = wqe; +if (++qp->s_cur >= qp->s_size) + qp->s_cur =0 ; +break ; + } + qp->s_len -= len; + qp->s_hdrwords = hwords; + qp->s_cur_sge = &qp->s_sge; + qp->s_cur_size = len; +qib_make_ruc_header (qp, ohdr, bth0 | (qp->s_state <<24 ), + qp->s_next_psn++ &QIB_PSN_MASK ); +done: + ret =1 ; + goto unlock; + +bail: + qp->s_flags &= ~QIB_S_BUSY ; +unlock: +spin_unlock_irqrestore (&qp->s_lock, flags); +return ret; +} + +/** +* qib_uc_rcv - handle an incoming UC packet +* @ibp: the port the packet came in on +* @hdr: the header of the packet +* @has_grh: true if the packet has a GRH +* @data: the packet data +* @tlen: the length of the packet +* @qp: the QP for this packet. +* +* This is called from qib_qp_rcv() to process an incoming UC packet +* for the given QP. +* Called at interrupt level. +*/ +void qib_uc_rcv (struct qib_ibport *ibp,struct qib_ib_header *hdr, +int has_grh,void *data,u32 tlen,struct qib_qp *qp) +{ +struct qib_other_headers *ohdr; +unsigned long flags; +u32 opcode; +u32 hdrsize; +u32 psn; +u32 pad; +struct ib_wc wc; +u32 pmtu =ib_mtu_enum_to_int (qp->path_mtu); +struct ib_reth *reth; +int ret; + +/* Check for GRH */ +if (!has_grh) { + ohdr = &hdr->u.oth; + hdrsize =8 +12 ;/* LRH + BTH */ + }else { + ohdr = &hdr->u.l.oth; + hdrsize =8 +40 +12 ;/* LRH + GRH + BTH */ + } + + opcode =be32_to_cpu (ohdr->bth[0 ]); +spin_lock_irqsave (&qp->s_lock, flags); +if (qib_ruc_check_hdr (ibp, hdr, has_grh, qp, opcode)) + goto sunlock; +spin_unlock_irqrestore (&qp->s_lock, flags); + + psn =be32_to_cpu (ohdr->bth[2 ]); + opcode >>=24 ; +memset (&wc,0 ,sizeof wc); + +/* Prevent simultaneous processing after APM on different CPUs */ +spin_lock (&qp->r_lock); + +/* Compare the PSN verses the expected PSN. */ +if (unlikely (qib_cmp24 (psn, qp->r_psn) !=0 )) { +/* +* Handle a sequence error. +* Silently drop any current message. +*/ + qp->r_psn = psn; +inv: +if (qp->r_state ==OP (SEND_FIRST ) || + qp->r_state ==OP (SEND_MIDDLE )) { +set_bit (QIB_R_REWIND_SGE , &qp->r_aflags); + qp->r_sge.num_sge =0 ; + }else +while (qp->r_sge.num_sge) { +atomic_dec (&qp->r_sge.sge.mr->refcount); +if (--qp->r_sge.num_sge) + qp->r_sge.sge = *qp->r_sge.sg_list++; + } + qp->r_state =OP (SEND_LAST ); +switch (opcode) { +case OP (SEND_FIRST ): +case OP (SEND_ONLY ): +case OP (SEND_ONLY_WITH_IMMEDIATE ): + goto send_first; + +case OP (RDMA_WRITE_FIRST ): +case OP (RDMA_WRITE_ONLY ): +case OP (RDMA_WRITE_ONLY_WITH_IMMEDIATE ): + goto rdma_first; + +default : + goto drop; + } + } + +/* Check for opcode sequence errors. */ +switch (qp->r_state) { +case OP (SEND_FIRST ): +case OP (SEND_MIDDLE ): +if (opcode ==OP (SEND_MIDDLE ) || + opcode ==OP (SEND_LAST ) || + opcode ==OP (SEND_LAST_WITH_IMMEDIATE )) +break ; + goto inv; + +case OP (RDMA_WRITE_FIRST ): +case OP (RDMA_WRITE_MIDDLE ): +if (opcode ==OP (RDMA_WRITE_MIDDLE ) || + opcode ==OP (RDMA_WRITE_LAST ) || + opcode ==OP (RDMA_WRITE_LAST_WITH_IMMEDIATE )) +break ; + goto inv; + +default : +if (opcode ==OP (SEND_FIRST ) || + opcode ==OP (SEND_ONLY ) || + opcode ==OP (SEND_ONLY_WITH_IMMEDIATE ) || + opcode ==OP (RDMA_WRITE_FIRST ) || + opcode ==OP (RDMA_WRITE_ONLY ) || + opcode ==OP (RDMA_WRITE_ONLY_WITH_IMMEDIATE )) +break ; + goto inv; + } + +if (qp->state ==IB_QPS_RTR && !(qp->r_flags &QIB_R_COMM_EST )) { + qp->r_flags |=QIB_R_COMM_EST ; +if (qp->ibqp.event_handler) { +struct ib_event ev; + + ev.device = qp->ibqp.device; + ev.element.qp = &qp->ibqp; + ev.event =IB_EVENT_COMM_EST ; + qp->ibqp.event_handler (&ev, qp->ibqp.qp_context); + } + } + +/* OK, process the packet. */ +switch (opcode) { +case OP (SEND_FIRST ): +case OP (SEND_ONLY ): +case OP (SEND_ONLY_WITH_IMMEDIATE ): +send_first: +if (test_and_clear_bit (QIB_R_REWIND_SGE , &qp->r_aflags)) + qp->r_sge = qp->s_rdma_read_sge; +else { + ret =qib_get_rwqe (qp,0 ); +if (ret <0 ) + goto op_err; +if (!ret) + goto drop; +/* +* qp->s_rdma_read_sge will be the owner +* of the mr references. +*/ + qp->s_rdma_read_sge = qp->r_sge; + } + qp->r_rcv_len =0 ; +if (opcode ==OP (SEND_ONLY )) + goto send_last; +else if (opcode ==OP (SEND_ONLY_WITH_IMMEDIATE )) + goto send_last_imm; +/* FALLTHROUGH */ +case OP (SEND_MIDDLE ): +/* Check for invalid length PMTU or posted rwqe len. */ +if (unlikely (tlen != (hdrsize + pmtu +4 ))) + goto rewind; + qp->r_rcv_len += pmtu; +if (unlikely (qp->r_rcv_len > qp->r_len)) + goto rewind; +qib_copy_sge (&qp->r_sge, data, pmtu,0 ); +break ; + +case OP (SEND_LAST_WITH_IMMEDIATE ): +send_last_imm: + wc.ex.imm_data = ohdr->u.imm_data; + hdrsize +=4 ; + wc.wc_flags =IB_WC_WITH_IMM ; +/* FALLTHROUGH */ +case OP (SEND_LAST ): +send_last: +/* Get the number of bytes the message was padded by. */ + pad = (be32_to_cpu (ohdr->bth[0 ]) >>20 ) &3 ; +/* Check for invalid length. */ +/* XXX LAST len should be >= 1 */ +if (unlikely (tlen < (hdrsize + pad +4 ))) + goto rewind; +/* Don't count the CRC. */ + tlen -= (hdrsize + pad +4 ); + wc.byte_len = tlen + qp->r_rcv_len; +if (unlikely (wc.byte_len > qp->r_len)) + goto rewind; + wc.opcode =IB_WC_RECV ; +last_imm: +qib_copy_sge (&qp->r_sge, data, tlen,0 ); +while (qp->s_rdma_read_sge.num_sge) { +atomic_dec (&qp->s_rdma_read_sge.sge.mr->refcount); +if (--qp->s_rdma_read_sge.num_sge) + qp->s_rdma_read_sge.sge = + *qp->s_rdma_read_sge.sg_list++; + } + wc.wr_id = qp->r_wr_id; + wc.status =IB_WC_SUCCESS ; + wc.qp = &qp->ibqp; + wc.src_qp = qp->remote_qpn; + wc.slid = qp->remote_ah_attr.dlid; + wc.sl = qp->remote_ah_attr.sl; +/* Signal completion event if the solicited bit is set. */ +qib_cq_enter (to_icq (qp->ibqp.recv_cq), &wc, + (ohdr->bth[0 ] & +cpu_to_be32 (IB_BTH_SOLICITED )) !=0 ); +break ; + +case OP (RDMA_WRITE_FIRST ): +case OP (RDMA_WRITE_ONLY ): +case OP (RDMA_WRITE_ONLY_WITH_IMMEDIATE ):/* consume RWQE */ +rdma_first: +if (unlikely (!(qp->qp_access_flags & +IB_ACCESS_REMOTE_WRITE ))) { + goto drop; + } + reth = &ohdr->u.rc.reth; + hdrsize +=sizeof (*reth); + qp->r_len =be32_to_cpu (reth->length); + qp->r_rcv_len =0 ; + qp->r_sge.sg_list =NULL ; +if (qp->r_len !=0 ) { +u32 rkey =be32_to_cpu (reth->rkey); +u64 vaddr =be64_to_cpu (reth->vaddr); +int ok; + +/* Check rkey */ + ok =qib_rkey_ok (qp, &qp->r_sge.sge, qp->r_len, + vaddr, rkey,IB_ACCESS_REMOTE_WRITE ); +if (unlikely (!ok)) + goto drop; + qp->r_sge.num_sge =1 ; + }else { + qp->r_sge.num_sge =0 ; + qp->r_sge.sge.mr =NULL ; + qp->r_sge.sge.vaddr =NULL ; + qp->r_sge.sge.length =0 ; + qp->r_sge.sge.sge_length =0 ; + } +if (opcode ==OP (RDMA_WRITE_ONLY )) + goto rdma_last; +else if (opcode ==OP (RDMA_WRITE_ONLY_WITH_IMMEDIATE )) + goto rdma_last_imm; +/* FALLTHROUGH */ +case OP (RDMA_WRITE_MIDDLE ): +/* Check for invalid length PMTU or posted rwqe len. */ +if (unlikely (tlen != (hdrsize + pmtu +4 ))) + goto drop; + qp->r_rcv_len += pmtu; +if (unlikely (qp->r_rcv_len > qp->r_len)) + goto drop; +qib_copy_sge (&qp->r_sge, data, pmtu,1 ); +break ; + +case OP (RDMA_WRITE_LAST_WITH_IMMEDIATE ): +rdma_last_imm: + wc.ex.imm_data = ohdr->u.imm_data; + hdrsize +=4 ; + wc.wc_flags =IB_WC_WITH_IMM ; + +/* Get the number of bytes the message was padded by. */ + pad = (be32_to_cpu (ohdr->bth[0 ]) >>20 ) &3 ; +/* Check for invalid length. */ +/* XXX LAST len should be >= 1 */ +if (unlikely (tlen < (hdrsize + pad +4 ))) + goto drop; +/* Don't count the CRC. */ + tlen -= (hdrsize + pad +4 ); +if (unlikely (tlen + qp->r_rcv_len != qp->r_len)) + goto drop; +if (test_and_clear_bit (QIB_R_REWIND_SGE , &qp->r_aflags)) +while (qp->s_rdma_read_sge.num_sge) { +atomic_dec (&qp->s_rdma_read_sge.sge.mr-> + refcount); +if (--qp->s_rdma_read_sge.num_sge) + qp->s_rdma_read_sge.sge = + *qp->s_rdma_read_sge.sg_list++; + } +else { + ret =qib_get_rwqe (qp,1 ); +if (ret <0 ) + goto op_err; +if (!ret) + goto drop; + } + wc.byte_len = qp->r_len; + wc.opcode =IB_WC_RECV_RDMA_WITH_IMM ; + goto last_imm; + +case OP (RDMA_WRITE_LAST ): +rdma_last: +/* Get the number of bytes the message was padded by. */ + pad = (be32_to_cpu (ohdr->bth[0 ]) >>20 ) &3 ; +/* Check for invalid length. */ +/* XXX LAST len should be >= 1 */ +if (unlikely (tlen < (hdrsize + pad +4 ))) + goto drop; +/* Don't count the CRC. */ + tlen -= (hdrsize + pad +4 ); +if (unlikely (tlen + qp->r_rcv_len != qp->r_len)) + goto drop; +qib_copy_sge (&qp->r_sge, data, tlen,1 ); +while (qp->r_sge.num_sge) { +atomic_dec (&qp->r_sge.sge.mr->refcount); +if (--qp->r_sge.num_sge) + qp->r_sge.sge = *qp->r_sge.sg_list++; + } +break ; + +default : +/* Drop packet for unknown opcodes. */ + goto drop; + } + qp->r_psn++; + qp->r_state = opcode; +spin_unlock (&qp->r_lock); +return ; + +rewind: +set_bit (QIB_R_REWIND_SGE , &qp->r_aflags); + qp->r_sge.num_sge =0 ; +drop: + ibp->n_pkt_drops++; +spin_unlock (&qp->r_lock); +return ; + +op_err: +qib_rc_error (qp,IB_WC_LOC_QP_OP_ERR ); +spin_unlock (&qp->r_lock); +return ; + +sunlock: +spin_unlock_irqrestore (&qp->s_lock, flags); +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 41/52 IB/qib: Add qib_ud.c
In reply to a message not in the archivecreates the qib_ud.c file.
---
drivers/infiniband/hw/qib/qib_ud.c | 607 ++++++++++++++++++++++++++++++++++++ 1 files changed, 607 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_ud.c
drivers/infiniband/hw/qib/qib_ud.c new file +607 -0
@@ -0,0 +1,607 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <rdma/ib_smi.h> + +#include "qib.h" +#include "qib_mad.h" + +/** +* qib_ud_loopback - handle send on loopback QPs +* @sqp: the sending QP +* @swqe: the send work request +* +* This is called from qib_make_ud_req() to forward a WQE addressed +* to the same HCA. +* Note that the receive interrupt handler may be calling qib_ud_rcv() +* while this is being called. +*/ +static void qib_ud_loopback (struct qib_qp *sqp,struct qib_swqe *swqe) +{ +struct qib_ibport *ibp =to_iport (sqp->ibqp.device, sqp->port_num); +struct qib_pportdata *ppd; +struct qib_qp *qp; +struct ib_ah_attr *ah_attr; +unsigned long flags; +struct qib_sge_state ssge; +struct qib_sge *sge; +struct ib_wc wc; +u32 length; + + qp =qib_lookup_qpn (ibp, swqe->wr.wr.ud.remote_qpn); +if (!qp) { + ibp->n_pkt_drops++; +return ; + } +if (qp->ibqp.qp_type != sqp->ibqp.qp_type || + !(ib_qib_state_ops[qp->state] &QIB_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 pkey1; +u16 pkey2; +u16 lid; + + pkey1 =qib_get_pkey (ibp, sqp->s_pkey_index); + pkey2 =qib_get_pkey (ibp, qp->s_pkey_index); +if (unlikely (!qib_pkey_ok (pkey1, pkey2))) { + lid = ppd->lid | (ah_attr->src_path_bits & + ((1 << ppd->lmc) -1 )); +qib_bad_pqkey (ibp,IB_NOTICE_TRAP_BAD_PKEY , pkey1, + ah_attr->sl, + sqp->ibqp.qp_num, qp->ibqp.qp_num, +cpu_to_be16 (lid), +cpu_to_be16 (ah_attr->dlid)); + goto drop; + } + } + +/* +* Check that the qkey matches (except for QP0, see 9.6.1.4.1). +* Qkeys with the high order bit set mean use the +* qkey from the QP context instead of the WR (see 10.2.5). +*/ +if (qp->ibqp.qp_num) { +u32 qkey; + + qkey = (int )swqe->wr.wr.ud.remote_qkey <0 ? + sqp->qkey : swqe->wr.wr.ud.remote_qkey; +if (unlikely (qkey != qp->qkey)) { +u16 lid; + + lid = ppd->lid | (ah_attr->src_path_bits & + ((1 << ppd->lmc) -1 )); +qib_bad_pqkey (ibp,IB_NOTICE_TRAP_BAD_QKEY , qkey, + ah_attr->sl, + sqp->ibqp.qp_num, qp->ibqp.qp_num, +cpu_to_be16 (lid), +cpu_to_be16 (ah_attr->dlid)); + goto drop; + } + } + +/* +* A GRH is expected to preceed the data even if not +* present on the wire. +*/ + length = swqe->length; +memset (&wc,0 ,sizeof wc); + wc.byte_len = length +sizeof (struct ib_grh ); + +if (swqe->wr.opcode ==IB_WR_SEND_WITH_IMM ) { + wc.wc_flags =IB_WC_WITH_IMM ; + wc.ex.imm_data = swqe->wr.ex.imm_data; + } + +spin_lock_irqsave (&qp->r_lock, flags); + +/* +* Get the next work request entry to find where to put the data. +*/ +if (qp->r_flags &QIB_R_REUSE_SGE ) + qp->r_flags &= ~QIB_R_REUSE_SGE ; +else { +int ret; + + ret =qib_get_rwqe (qp,0 ); +if (ret <0 ) { +qib_rc_error (qp,IB_WC_LOC_QP_OP_ERR ); + goto bail_unlock; + } +if (!ret) { +if (qp->ibqp.qp_num ==0 ) + ibp->n_vl15_dropped++; + goto bail_unlock; + } + } +/* Silently drop packets which are too big. */ +if (unlikely (wc.byte_len > qp->r_len)) { + qp->r_flags |=QIB_R_REUSE_SGE ; + ibp->n_pkt_drops++; + goto bail_unlock; + } + +if (ah_attr->ah_flags &IB_AH_GRH ) { +qib_copy_sge (&qp->r_sge, &ah_attr->grh, +sizeof (struct ib_grh ),1 ); + wc.wc_flags |=IB_WC_GRH ; + }else +qib_skip_sge (&qp->r_sge,sizeof (struct ib_grh ),1 ); + ssge.sg_list = swqe->sg_list +1 ; + ssge.sge = *swqe->sg_list; + ssge.num_sge = swqe->wr.num_sge; + sge = &ssge.sge; +while (length) { +u32 len = sge->length; + +if (len > length) + len = length; +if (len > sge->sge_length) + len = sge->sge_length; +BUG_ON (len ==0 ); +qib_copy_sge (&qp->r_sge, sge->vaddr, len,1 ); + sge->vaddr += len; + sge->length -= len; + sge->sge_length -= len; +if (sge->sge_length ==0 ) { +if (--ssge.num_sge) + *sge = *ssge.sg_list++; + }else if (sge->length ==0 && sge->mr->lkey) { +if (++sge->n >=QIB_SEGSZ ) { +if (++sge->m >= sge->mr->mapsz) +break ; + sge->n =0 ; + } + sge->vaddr = + sge->mr->map[sge->m]->segs[sge->n].vaddr; + sge->length = + sge->mr->map[sge->m]->segs[sge->n].length; + } + length -= len; + } +while (qp->r_sge.num_sge) { +atomic_dec (&qp->r_sge.sge.mr->refcount); +if (--qp->r_sge.num_sge) + qp->r_sge.sge = *qp->r_sge.sg_list++; + } +if (!test_and_clear_bit (QIB_R_WRID_VALID , &qp->r_aflags)) + goto bail_unlock; + wc.wr_id = qp->r_wr_id; + wc.status =IB_WC_SUCCESS ; + wc.opcode =IB_WC_RECV ; + wc.qp = &qp->ibqp; + wc.src_qp = sqp->ibqp.qp_num; + wc.pkey_index = qp->ibqp.qp_type ==IB_QPT_GSI ? + swqe->wr.wr.ud.pkey_index :0 ; + wc.slid = ppd->lid | (ah_attr->src_path_bits & ((1 << ppd->lmc) -1 )); + wc.sl = ah_attr->sl; + wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) -1 ); + wc.port_num = qp->port_num; +/* Signal completion event if the solicited bit is set. */ +qib_cq_enter (to_icq (qp->ibqp.recv_cq), &wc, + swqe->wr.send_flags &IB_SEND_SOLICITED ); + ibp->n_loop_pkts++; +bail_unlock: +spin_unlock_irqrestore (&qp->r_lock, flags); +drop: +if (atomic_dec_and_test (&qp->refcount)) +wake_up (&qp->wait); +} + +/** +* qib_make_ud_req - construct a UD request packet +* @qp: the QP +* +* Return 1 if constructed; otherwise, return 0. +*/ +int qib_make_ud_req (struct qib_qp *qp) +{ +struct qib_other_headers *ohdr; +struct ib_ah_attr *ah_attr; +struct qib_pportdata *ppd; +struct qib_ibport *ibp; +struct qib_swqe *wqe; +unsigned long flags; +u32 nwords; +u32 extra_bytes; +u32 bth0; +u16 lrh0; +u16 lid; +int ret =0 ; +int next_cur; + +spin_lock_irqsave (&qp->s_lock, flags); + +if (!(ib_qib_state_ops[qp->state] &QIB_PROCESS_NEXT_SEND_OK )) { +if (!(ib_qib_state_ops[qp->state] &QIB_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_dma_busy)) { + qp->s_flags |=QIB_S_WAIT_DMA ; + goto bail; + } + wqe =get_swqe_ptr (qp, qp->s_last); +qib_send_complete (qp, wqe,IB_WC_WR_FLUSH_ERR ); + goto done; + } + +if (qp->s_cur == qp->s_head) + goto bail; + + wqe =get_swqe_ptr (qp, qp->s_cur); + next_cur = qp->s_cur +1 ; +if (next_cur >= qp->s_size) + next_cur =0 ; + +/* Construct the header. */ + ibp =to_iport (qp->ibqp.device, qp->port_num); + ppd =ppd_from_ibp (ibp); + ah_attr = &to_iah (wqe->wr.wr.ud.ah)->attr; +if (ah_attr->dlid >=QIB_MULTICAST_LID_BASE ) { +if (ah_attr->dlid !=QIB_PERMISSIVE_LID ) + ibp->n_multicast_xmit++; +else + ibp->n_unicast_xmit++; + }else { + ibp->n_unicast_xmit++; + lid = ah_attr->dlid & ~((1 << ppd->lmc) -1 ); +if (unlikely (lid == ppd->lid)) { +/* +* If DMAs are in progress, we can't generate +* a completion for the loopback packet since +* it would be out of order. +* XXX Instead of waiting, we could queue a +* zero length descriptor so we get a callback. +*/ +if (atomic_read (&qp->s_dma_busy)) { + qp->s_flags |=QIB_S_WAIT_DMA ; + goto bail; + } + qp->s_cur = next_cur; +spin_unlock_irqrestore (&qp->s_lock, flags); +qib_ud_loopback (qp, wqe); +spin_lock_irqsave (&qp->s_lock, flags); +qib_send_complete (qp, wqe,IB_WC_SUCCESS ); + goto done; + } + } + + qp->s_cur = next_cur; + extra_bytes = -wqe->length &3 ; + nwords = (wqe->length + extra_bytes) >>2 ; + +/* header size in 32-bit words LRH+BTH+DETH = (8+12+8)/4. */ + qp->s_hdrwords =7 ; + qp->s_cur_size = wqe->length; + qp->s_cur_sge = &qp->s_sge; + qp->s_srate = ah_attr->static_rate; + qp->s_wqe = wqe; + qp->s_sge.sge = wqe->sg_list[0 ]; + qp->s_sge.sg_list = wqe->sg_list +1 ; + qp->s_sge.num_sge = wqe->wr.num_sge; + qp->s_sge.total_len = wqe->length; + +if (ah_attr->ah_flags &IB_AH_GRH ) { +/* Header size in 32-bit words. */ + qp->s_hdrwords +=qib_make_grh (ibp, &qp->s_hdr.u.l.grh, + &ah_attr->grh, + qp->s_hdrwords, nwords); + lrh0 =QIB_LRH_GRH ; + ohdr = &qp->s_hdr.u.l.oth; +/* +* Don't worry about sending to locally attached multicast +* QPs. It is unspecified by the spec. what happens. +*/ + }else { +/* Header size in 32-bit words. */ + lrh0 =QIB_LRH_BTH ; + ohdr = &qp->s_hdr.u.oth; + } +if (wqe->wr.opcode ==IB_WR_SEND_WITH_IMM ) { + qp->s_hdrwords++; + ohdr->u.ud.imm_data = wqe->wr.ex.imm_data; + bth0 =IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE <<24 ; + }else + bth0 =IB_OPCODE_UD_SEND_ONLY <<24 ; + lrh0 |= ah_attr->sl <<4 ; +if (qp->ibqp.qp_type ==IB_QPT_SMI ) + lrh0 |=0xF000 ;/* Set VL (see ch. 13.5.3.1) */ +else + lrh0 |= ibp->sl_to_vl[ah_attr->sl] <<12 ; + qp->s_hdr.lrh[0 ] =cpu_to_be16 (lrh0); + qp->s_hdr.lrh[1 ] =cpu_to_be16 (ah_attr->dlid);/* DEST LID */ + qp->s_hdr.lrh[2 ] =cpu_to_be16 (qp->s_hdrwords + nwords +SIZE_OF_CRC ); + lid = ppd->lid; +if (lid) { + lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) -1 ); + qp->s_hdr.lrh[3 ] =cpu_to_be16 (lid); + }else + qp->s_hdr.lrh[3 ] =IB_LID_PERMISSIVE ; +if (wqe->wr.send_flags &IB_SEND_SOLICITED ) + bth0 |=IB_BTH_SOLICITED ; + bth0 |= extra_bytes <<20 ; + bth0 |= qp->ibqp.qp_type ==IB_QPT_SMI ?QIB_DEFAULT_P_KEY : +qib_get_pkey (ibp, qp->ibqp.qp_type ==IB_QPT_GSI ? + wqe->wr.wr.ud.pkey_index : qp->s_pkey_index); + ohdr->bth[0 ] =cpu_to_be32 (bth0); +/* +* Use the multicast QP if the destination LID is a multicast LID. +*/ + ohdr->bth[1 ] = ah_attr->dlid >=QIB_MULTICAST_LID_BASE && + ah_attr->dlid !=QIB_PERMISSIVE_LID ? +cpu_to_be32 (QIB_MULTICAST_QPN ) : +cpu_to_be32 (wqe->wr.wr.ud.remote_qpn); + ohdr->bth[2 ] =cpu_to_be32 (qp->s_next_psn++ &QIB_PSN_MASK ); +/* +* Qkeys with the high order bit set mean use the +* qkey from the QP context instead of the WR (see 10.2.5). +*/ + ohdr->u.ud.deth[0 ] =cpu_to_be32 ((int )wqe->wr.wr.ud.remote_qkey <0 ? + qp->qkey : wqe->wr.wr.ud.remote_qkey); + ohdr->u.ud.deth[1 ] =cpu_to_be32 (qp->ibqp.qp_num); + +done: + ret =1 ; + goto unlock; + +bail: + qp->s_flags &= ~QIB_S_BUSY ; +unlock: +spin_unlock_irqrestore (&qp->s_lock, flags); +return ret; +} + +static unsigned qib_lookup_pkey (struct qib_ibport *ibp,u16 pkey) +{ +struct qib_pportdata *ppd =ppd_from_ibp (ibp); +struct qib_devdata *dd = ppd->dd; +unsigned ctxt = ppd->hw_pidx; +unsigned i; + + pkey &=0x7fff ;/* remove limited/full membership bit */ + +for (i =0 ; i <ARRAY_SIZE (dd->rcd[ctxt]->pkeys); ++i) +if ((dd->rcd[ctxt]->pkeys[i] &0x7fff ) == pkey) +return i; + +/* +* Should not get here, this means hardware failed to validate pkeys. +* Punt and return index 0. +*/ +return 0 ; +} + +/** +* qib_ud_rcv - receive an incoming UD packet +* @ibp: the port the packet came in on +* @hdr: the packet header +* @has_grh: true if the packet has a GRH +* @data: the packet data +* @tlen: the packet length +* @qp: the QP the packet came on +* +* This is called from qib_qp_rcv() to process an incoming UD packet +* for the given QP. +* Called at interrupt level. +*/ +void qib_ud_rcv (struct qib_ibport *ibp,struct qib_ib_header *hdr, +int has_grh,void *data,u32 tlen,struct qib_qp *qp) +{ +struct qib_other_headers *ohdr; +int opcode; +u32 hdrsize; +u32 pad; +struct ib_wc wc; +u32 qkey; +u32 src_qp; +u16 dlid; + +/* Check for GRH */ +if (!has_grh) { + ohdr = &hdr->u.oth; + hdrsize =8 +12 +8 ;/* LRH + BTH + DETH */ + }else { + ohdr = &hdr->u.l.oth; + hdrsize =8 +40 +12 +8 ;/* LRH + GRH + BTH + DETH */ + } + qkey =be32_to_cpu (ohdr->u.ud.deth[0 ]); + src_qp =be32_to_cpu (ohdr->u.ud.deth[1 ]) &QIB_QPN_MASK ; + +/* Get the number of bytes the message was padded by. */ + pad = (be32_to_cpu (ohdr->bth[0 ]) >>20 ) &3 ; +if (unlikely (tlen < (hdrsize + pad +4 ))) { +/* Drop incomplete packets. */ + ibp->n_pkt_drops++; + goto bail; + } + tlen -= hdrsize + pad +4 ; + +/* +* Check that the permissive LID is only used on QP0 +* and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1). +*/ +if (qp->ibqp.qp_num) { +if (unlikely (hdr->lrh[1 ] ==IB_LID_PERMISSIVE || + hdr->lrh[3 ] ==IB_LID_PERMISSIVE )) { + ibp->n_pkt_drops++; + goto bail; + } +if (qp->ibqp.qp_num >1 ) { +u16 pkey1, pkey2; + + pkey1 =be32_to_cpu (ohdr->bth[0 ]); + pkey2 =qib_get_pkey (ibp, qp->s_pkey_index); +if (unlikely (!qib_pkey_ok (pkey1, pkey2))) { +qib_bad_pqkey (ibp,IB_NOTICE_TRAP_BAD_PKEY , + pkey1, + (be16_to_cpu (hdr->lrh[0 ]) >>4 ) & +0xF , + src_qp, qp->ibqp.qp_num, + hdr->lrh[3 ], hdr->lrh[1 ]); + goto bail; + } + } +if (unlikely (qkey != qp->qkey)) { +qib_bad_pqkey (ibp,IB_NOTICE_TRAP_BAD_QKEY , qkey, + (be16_to_cpu (hdr->lrh[0 ]) >>4 ) &0xF , + src_qp, qp->ibqp.qp_num, + hdr->lrh[3 ], hdr->lrh[1 ]); + goto bail; + } +/* Drop invalid MAD packets (see 13.5.3.1). */ +if (unlikely (qp->ibqp.qp_num ==1 && + (tlen !=256 || + (be16_to_cpu (hdr->lrh[0 ]) >>12 ) ==15 ))) { + ibp->n_pkt_drops++; + goto bail; + } + }else { +struct ib_smp *smp; + +/* Drop invalid MAD packets (see 13.5.3.1). */ +if (tlen !=256 || (be16_to_cpu (hdr->lrh[0 ]) >>12 ) !=15 ) { + ibp->n_pkt_drops++; + goto bail; + } + smp = (struct ib_smp *) data; +if ((hdr->lrh[1 ] ==IB_LID_PERMISSIVE || + hdr->lrh[3 ] ==IB_LID_PERMISSIVE ) && + smp->mgmt_class !=IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE ) { + ibp->n_pkt_drops++; + goto bail; + } + } + +/* +* The opcode is in the low byte when its in network order +* (top byte when in host order). +*/ + opcode =be32_to_cpu (ohdr->bth[0 ]) >>24 ; +if (qp->ibqp.qp_num >1 && + opcode ==IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE ) { + wc.ex.imm_data = ohdr->u.ud.imm_data; + wc.wc_flags =IB_WC_WITH_IMM ; + hdrsize +=sizeof (u32); + }else if (opcode ==IB_OPCODE_UD_SEND_ONLY ) { + wc.ex.imm_data =0 ; + wc.wc_flags =0 ; + }else { + ibp->n_pkt_drops++; + goto bail; + } + +/* +* A GRH is expected to preceed the data even if not +* present on the wire. +*/ + wc.byte_len = tlen +sizeof (struct ib_grh ); + +/* +* We need to serialize getting a receive work queue entry and +* generating a completion for it against QPs sending to this QP +* locally. +*/ +spin_lock (&qp->r_lock); + +/* +* Get the next work request entry to find where to put the data. +*/ +if (qp->r_flags &QIB_R_REUSE_SGE ) + qp->r_flags &= ~QIB_R_REUSE_SGE ; +else { +int ret; + + ret =qib_get_rwqe (qp,0 ); +if (ret <0 ) { +qib_rc_error (qp,IB_WC_LOC_QP_OP_ERR ); + goto bail_unlock; + } +if (!ret) { +if (qp->ibqp.qp_num ==0 ) + ibp->n_vl15_dropped++; + goto bail_unlock; + } + } +/* Silently drop packets which are too big. */ +if (unlikely (wc.byte_len > qp->r_len)) { + qp->r_flags |=QIB_R_REUSE_SGE ; + ibp->n_pkt_drops++; + goto bail_unlock; + } +if (has_grh) { +qib_copy_sge (&qp->r_sge, &hdr->u.l.grh, +sizeof (struct ib_grh ),1 ); + wc.wc_flags |=IB_WC_GRH ; + }else +qib_skip_sge (&qp->r_sge,sizeof (struct ib_grh ),1 ); +qib_copy_sge (&qp->r_sge, data, wc.byte_len -sizeof (struct ib_grh ),1 ); +while (qp->r_sge.num_sge) { +atomic_dec (&qp->r_sge.sge.mr->refcount); +if (--qp->r_sge.num_sge) + qp->r_sge.sge = *qp->r_sge.sg_list++; + } +if (!test_and_clear_bit (QIB_R_WRID_VALID , &qp->r_aflags)) + goto bail_unlock; + wc.wr_id = qp->r_wr_id; + wc.status =IB_WC_SUCCESS ; + wc.opcode =IB_WC_RECV ; + wc.vendor_err =0 ; + wc.qp = &qp->ibqp; + wc.src_qp = src_qp; + wc.pkey_index = qp->ibqp.qp_type ==IB_QPT_GSI ? +qib_lookup_pkey (ibp,be32_to_cpu (ohdr->bth[0 ])) :0 ; + wc.slid =be16_to_cpu (hdr->lrh[3 ]); + wc.sl = (be16_to_cpu (hdr->lrh[0 ]) >>4 ) &0xF ; + dlid =be16_to_cpu (hdr->lrh[1 ]); +/* +* Save the LMC lower bits if the destination LID is a unicast LID. +*/ + wc.dlid_path_bits = dlid >=QIB_MULTICAST_LID_BASE ?0 : + dlid & ((1 <<ppd_from_ibp (ibp)->lmc) -1 ); + wc.port_num = qp->port_num; +/* Signal completion event if the solicited bit is set. */ +qib_cq_enter (to_icq (qp->ibqp.recv_cq), &wc, + (ohdr->bth[0 ] & +cpu_to_be32 (IB_BTH_SOLICITED )) !=0 ); +bail_unlock: +spin_unlock (&qp->r_lock); +bail:; +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 42/52 IB/qib: Add qib_user_pages.c
In reply to a message not in the archivecreates the qib_user_pages.c file.
---
drivers/infiniband/hw/qib/qib_user_pages.c | 157 ++++++++++++++++++++++++++++ 1 files changed, 157 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_user_pages.c
drivers/infiniband/hw/qib/qib_user_pages.c new file +157 -0
@@ -0,0 +1,157 @@ +/* +* Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ + +#include <linux/mm.h> +#include <linux/device.h> + +#include "qib.h" + +static void __qib_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 __get_user_pages (unsigned long start_page,size_t num_pages, +struct page **p,struct vm_area_struct **vma) +{ +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, vma); +if (ret <0 ) + goto bail_release; + } + + current->mm->locked_vm += num_pages; + + ret =0 ; + goto bail; + +bail_release: +__qib_release_user_pages (p, got,0 ); +bail: +return ret; +} + +/** +* qib_map_page - a safety wrapper around pci_map_page() +* +* A dma_addr of all 0's is interpreted by the chip as "disabled". +* Unfortunately, it can also be a valid dma_addr returned on some +* architectures. +* +* The powerpc iommu assigns dma_addrs in ascending order, so we don't +* have to bother with retries or mapping a dummy page to insure we +* don't just get the same mapping again. +* +* I'm sure we won't be so lucky with other iommu's, so FIXME. +*/ +dma_addr_t qib_map_page (struct pci_dev *hwdev,struct page *page, +unsigned long offset,size_t size,int direction) +{ +dma_addr_t phys; + + phys =pci_map_page (hwdev, page, offset, size, direction); + +if (phys ==0 ) { +pci_unmap_page (hwdev, phys, size, direction); + phys =pci_map_page (hwdev, page, offset, size, direction); +/* +* FIXME: If we get 0 again, we should keep this page, +* map another, then free the 0 page. +*/ + } + +return phys; +} + +/** +* qib_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 qib_get_user_pages (unsigned long start_page,size_t num_pages, +struct page **p) +{ +int ret; + +down_write (¤t->mm->mmap_sem); + + ret =__get_user_pages (start_page, num_pages, p,NULL ); + +up_write (¤t->mm->mmap_sem); + +return ret; +} + +void qib_release_user_pages (struct page **p,size_t num_pages) +{ +if (current->mm)/* during close after signal, mm can be NULL */ +down_write (¤t->mm->mmap_sem); + +__qib_release_user_pages (p, num_pages,1 ); + +if (current->mm) { + current->mm->locked_vm -= num_pages; +up_write (¤t->mm->mmap_sem); + } +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 43/52 IB/qib: Add qib_user_sdma.c
In reply to a message not in the archivecreates the qib_user_sdma.c file.
---
drivers/infiniband/hw/qib/qib_user_sdma.c | 897 +++++++++++++++++++++++++++++ 1 files changed, 897 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_user_sdma.c
drivers/infiniband/hw/qib/qib_user_sdma.c new file +897 -0
@@ -0,0 +1,897 @@ +/* +* Copyright (c) 2007, 2008, 2009 QLogic Corporation. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ +#include <linux/mm.h> +#include <linux/types.h> +#include <linux/device.h> +#include <linux/dmapool.h> +#include <linux/slab.h> +#include <linux/list.h> +#include <linux/highmem.h> +#include <linux/io.h> +#include <linux/uio.h> +#include <linux/rbtree.h> +#include <linux/spinlock.h> +#include <linux/delay.h> + +#include "qib.h" +#include "qib_user_sdma.h" + +/* minimum size of header */ +#define QIB_USER_SDMA_MIN_HEADER_LENGTH 64 +/* expected size of headers (for dma_pool) */ +#define QIB_USER_SDMA_EXP_HEADER_LENGTH 64 +/* attempt to drain the queue for 5secs */ +#define QIB_USER_SDMA_DRAIN_TIMEOUT 500 + +struct qib_user_sdma_pkt { +u8 naddr;/* dimension of addr (1..3) ... */ +u32 counter;/* sdma pkts queued counter for this entry */ +u64 added;/* global descq number of entries */ + +struct { +u32 offset;/* offset for kvaddr, addr */ +u32 length;/* length in page */ +u8 put_page;/* should we put_page? */ +u8 dma_mapped;/* is page dma_mapped? */ +struct page *page;/* may be NULL (coherent mem) */ +void *kvaddr;/* FIXME: only for pio hack */ +dma_addr_t addr; + } addr[4 ];/* max pages, any more and we coalesce */ +struct list_head list;/* list element */ +}; + +struct qib_user_sdma_queue { +/* +* pkts sent to dma engine are queued on this +* list head. the type of the elements of this +* list are struct qib_user_sdma_pkt... +*/ +struct list_head sent; + +/* headers with expected length are allocated from here... */ +char header_cache_name[64 ]; +struct dma_pool *header_cache; + +/* packets are allocated from the slab cache... */ +char pkt_slab_name[64 ]; +struct kmem_cache *pkt_slab; + +/* as packets go on the queued queue, they are counted... */ +u32 counter; +u32 sent_counter; + +/* dma page table */ +struct rb_root dma_pages_root; + +/* protect everything above... */ +struct mutex lock; +}; + +struct qib_user_sdma_queue * +qib_user_sdma_queue_create (struct device *dev,int unit,int ctxt,int sctxt) +{ +struct qib_user_sdma_queue *pq = +kmalloc (sizeof (struct qib_user_sdma_queue ),GFP_KERNEL ); + +if (!pq) + goto done; + + pq->counter =0 ; + pq->sent_counter =0 ; +INIT_LIST_HEAD (&pq->sent); + +mutex_init (&pq->lock); + +snprintf (pq->pkt_slab_name,sizeof (pq->pkt_slab_name), +"qib-user-sdma-pkts-%u-%02u.%02u" , unit, ctxt, sctxt); + pq->pkt_slab =kmem_cache_create (pq->pkt_slab_name, +sizeof (struct qib_user_sdma_pkt ), +0 ,0 ,NULL ); + +if (!pq->pkt_slab) + goto err_kfree; + +snprintf (pq->header_cache_name,sizeof (pq->header_cache_name), +"qib-user-sdma-headers-%u-%02u.%02u" , unit, ctxt, sctxt); + pq->header_cache =dma_pool_create (pq->header_cache_name, + dev, +QIB_USER_SDMA_EXP_HEADER_LENGTH , +4 ,0 ); +if (!pq->header_cache) + goto err_slab; + + pq->dma_pages_root =RB_ROOT ; + + goto done; + +err_slab: +kmem_cache_destroy (pq->pkt_slab); +err_kfree: +kfree (pq); + pq =NULL ; + +done: +return pq; +} + +static void qib_user_sdma_init_frag (struct qib_user_sdma_pkt *pkt, +int i,size_t offset,size_t len, +int put_page,int dma_mapped, +struct page *page, +void *kvaddr,dma_addr_t dma_addr) +{ + pkt->addr[i].offset = offset; + pkt->addr[i].length = len; + pkt->addr[i].put_page = put_page; + pkt->addr[i].dma_mapped = dma_mapped; + pkt->addr[i].page = page; + pkt->addr[i].kvaddr = kvaddr; + pkt->addr[i].addr = dma_addr; +} + +static void qib_user_sdma_init_header (struct qib_user_sdma_pkt *pkt, +u32 counter,size_t offset, +size_t len,int dma_mapped, +struct page *page, +void *kvaddr,dma_addr_t dma_addr) +{ + pkt->naddr =1 ; + pkt->counter = counter; +qib_user_sdma_init_frag (pkt,0 , offset, len,0 , dma_mapped, page, + kvaddr, dma_addr); +} + +/* we've too many pages in the iovec, coalesce to a single page */ +static int qib_user_sdma_coalesce (const struct qib_devdata *dd, +struct qib_user_sdma_pkt *pkt, +const struct iovec *iov, +unsigned long niov) +{ +int ret =0 ; +struct page *page =alloc_page (GFP_KERNEL ); +void *mpage_save; +char *mpage; +int i; +int len =0 ; +dma_addr_t dma_addr; + +if (!page) { + ret = -ENOMEM ; + goto done; + } + + mpage =kmap (page); + mpage_save = mpage; +for (i =0 ; i < niov; i++) { +int cfur; + + cfur =copy_from_user (mpage, + iov[i].iov_base, iov[i].iov_len); +if (cfur) { + ret = -EFAULT ; + goto free_unmap; + } + + mpage += iov[i].iov_len; + len += iov[i].iov_len; + } + + dma_addr =dma_map_page (&dd->pcidev->dev, page,0 , len, +DMA_TO_DEVICE ); +if (dma_mapping_error (&dd->pcidev->dev, dma_addr)) { + ret = -ENOMEM ; + goto free_unmap; + } + +qib_user_sdma_init_frag (pkt,1 ,0 , len,0 ,1 , page, mpage_save, + dma_addr); + pkt->naddr =2 ; + + goto done; + +free_unmap: +kunmap (page); +__free_page (page); +done: +return ret; +} + +/* +* How many pages in this iovec element? +*/ +static int qib_user_sdma_num_pages (const struct iovec *iov) +{ +const unsigned long addr = (unsigned long ) iov->iov_base; +const unsigned long len = iov->iov_len; +const unsigned long spage = addr &PAGE_MASK ; +const unsigned long epage = (addr + len -1 ) &PAGE_MASK ; + +return 1 + ((epage - spage) >>PAGE_SHIFT ); +} + +/* +* Truncate length to page boundry. +*/ +static int qib_user_sdma_page_length (unsigned long addr,unsigned long len) +{ +const unsigned long offset = addr & ~PAGE_MASK ; + +return ((offset + len) >PAGE_SIZE ) ? (PAGE_SIZE - offset) : len; +} + +static void qib_user_sdma_free_pkt_frag (struct device *dev, +struct qib_user_sdma_queue *pq, +struct qib_user_sdma_pkt *pkt, +int frag) +{ +const int i = frag; + +if (pkt->addr[i].page) { +if (pkt->addr[i].dma_mapped) +dma_unmap_page (dev, + pkt->addr[i].addr, + pkt->addr[i].length, +DMA_TO_DEVICE ); + +if (pkt->addr[i].kvaddr) +kunmap (pkt->addr[i].page); + +if (pkt->addr[i].put_page) +put_page (pkt->addr[i].page); +else +__free_page (pkt->addr[i].page); + }else if (pkt->addr[i].kvaddr) +/* free coherent mem from cache... */ +dma_pool_free (pq->header_cache, + pkt->addr[i].kvaddr, pkt->addr[i].addr); +} + +/* return number of pages pinned... */ +static int qib_user_sdma_pin_pages (const struct qib_devdata *dd, +struct qib_user_sdma_pkt *pkt, +unsigned long addr,int tlen,int npages) +{ +struct page *pages[2 ]; +int j; +int ret; + + ret =get_user_pages (current, current->mm, addr, + npages,0 ,1 , pages,NULL ); + +if (ret != npages) { +int i; + +for (i =0 ; i < ret; i++) +put_page (pages[i]); + + ret = -ENOMEM ; + goto done; + } + +for (j =0 ; j < npages; j++) { +/* map the pages... */ +const int flen =qib_user_sdma_page_length (addr, tlen); +dma_addr_t dma_addr = +dma_map_page (&dd->pcidev->dev, + pages[j],0 , flen,DMA_TO_DEVICE ); +unsigned long fofs = addr & ~PAGE_MASK ; + +if (dma_mapping_error (&dd->pcidev->dev, dma_addr)) { + ret = -ENOMEM ; + goto done; + } + +qib_user_sdma_init_frag (pkt, pkt->naddr, fofs, flen,1 ,1 , + pages[j],kmap (pages[j]), dma_addr); + + pkt->naddr++; + addr += flen; + tlen -= flen; + } + +done: +return ret; +} + +static int qib_user_sdma_pin_pkt (const struct qib_devdata *dd, +struct qib_user_sdma_queue *pq, +struct qib_user_sdma_pkt *pkt, +const struct iovec *iov, +unsigned long niov) +{ +int ret =0 ; +unsigned long idx; + +for (idx =0 ; idx < niov; idx++) { +const int npages =qib_user_sdma_num_pages (iov + idx); +const unsigned long addr = (unsigned long ) iov[idx].iov_base; + + ret =qib_user_sdma_pin_pages (dd, pkt, addr, + iov[idx].iov_len, npages); +if (ret <0 ) + goto free_pkt; + } + + goto done; + +free_pkt: +for (idx =0 ; idx < pkt->naddr; idx++) +qib_user_sdma_free_pkt_frag (&dd->pcidev->dev, pq, pkt, idx); + +done: +return ret; +} + +static int qib_user_sdma_init_payload (const struct qib_devdata *dd, +struct qib_user_sdma_queue *pq, +struct qib_user_sdma_pkt *pkt, +const struct iovec *iov, +unsigned long niov,int npages) +{ +int ret =0 ; + +if (npages >=ARRAY_SIZE (pkt->addr)) + ret =qib_user_sdma_coalesce (dd, pkt, iov, niov); +else + ret =qib_user_sdma_pin_pkt (dd, pq, pkt, iov, niov); + +return ret; +} + +/* free a packet list -- return counter value of last packet */ +static void qib_user_sdma_free_pkt_list (struct device *dev, +struct qib_user_sdma_queue *pq, +struct list_head *list) +{ +struct qib_user_sdma_pkt *pkt, *pkt_next; + +list_for_each_entry_safe (pkt, pkt_next, list, list) { +int i; + +for (i =0 ; i < pkt->naddr; i++) +qib_user_sdma_free_pkt_frag (dev, pq, pkt, i); + +kmem_cache_free (pq->pkt_slab, pkt); + } +} + +/* +* copy headers, coalesce etc -- pq->lock must be held +* +* we queue all the packets to list, returning the +* number of bytes total. list must be empty initially, +* as, if there is an error we clean it... +*/ +static int qib_user_sdma_queue_pkts (const struct qib_devdata *dd, +struct qib_user_sdma_queue *pq, +struct list_head *list, +const struct iovec *iov, +unsigned long niov, +int maxpkts) +{ +unsigned long idx =0 ; +int ret =0 ; +int npkts =0 ; +struct page *page =NULL ; +__le32 *pbc; +dma_addr_t dma_addr; +struct qib_user_sdma_pkt *pkt =NULL ; +size_t len; +size_t nw; +u32 counter = pq->counter; +int dma_mapped =0 ; + +while (idx < niov && npkts < maxpkts) { +const unsigned long addr = (unsigned long ) iov[idx].iov_base; +const unsigned long idx_save = idx; +unsigned pktnw; +unsigned pktnwc; +int nfrags =0 ; +int npages =0 ; +int cfur; + + dma_mapped =0 ; + len = iov[idx].iov_len; + nw = len >>2 ; + page =NULL ; + + pkt =kmem_cache_alloc (pq->pkt_slab,GFP_KERNEL ); +if (!pkt) { + ret = -ENOMEM ; + goto free_list; + } + +if (len <QIB_USER_SDMA_MIN_HEADER_LENGTH || + len >PAGE_SIZE || len &3 || addr &3 ) { + ret = -EINVAL ; + goto free_pkt; + } + +if (len ==QIB_USER_SDMA_EXP_HEADER_LENGTH ) + pbc =dma_pool_alloc (pq->header_cache,GFP_KERNEL , + &dma_addr); +else + pbc =NULL ; + +if (!pbc) { + page =alloc_page (GFP_KERNEL ); +if (!page) { + ret = -ENOMEM ; + goto free_pkt; + } + pbc =kmap (page); + } + + cfur =copy_from_user (pbc, iov[idx].iov_base, len); +if (cfur) { + ret = -EFAULT ; + goto free_pbc; + } + +/* +* This assignment is a bit strange. it's because the +* the pbc counts the number of 32 bit words in the full +* packet _except_ the first word of the pbc itself... +*/ + pktnwc = nw -1 ; + +/* +* pktnw computation yields the number of 32 bit words +* that the caller has indicated in the PBC. note that +* this is one less than the total number of words that +* goes to the send DMA engine as the first 32 bit word +* of the PBC itself is not counted. Armed with this count, +* we can verify that the packet is consistent with the +* iovec lengths. +*/ + pktnw =le32_to_cpu (*pbc) &QIB_PBC_LENGTH_MASK ; +if (pktnw < pktnwc || pktnw > pktnwc + (PAGE_SIZE >>2 )) { + ret = -EINVAL ; + goto free_pbc; + } + + idx++; +while (pktnwc < pktnw && idx < niov) { +const size_t slen = iov[idx].iov_len; +const unsigned long faddr = + (unsigned long ) iov[idx].iov_base; + +if (slen &3 || faddr &3 || !slen || + slen >PAGE_SIZE ) { + ret = -EINVAL ; + goto free_pbc; + } + + npages++; +if ((faddr &PAGE_MASK ) != + ((faddr + slen -1 ) &PAGE_MASK )) + npages++; + + pktnwc += slen >>2 ; + idx++; + nfrags++; + } + +if (pktnwc != pktnw) { + ret = -EINVAL ; + goto free_pbc; + } + +if (page) { + dma_addr =dma_map_page (&dd->pcidev->dev, + page,0 , len,DMA_TO_DEVICE ); +if (dma_mapping_error (&dd->pcidev->dev, dma_addr)) { + ret = -ENOMEM ; + goto free_pbc; + } + + dma_mapped =1 ; + } + +qib_user_sdma_init_header (pkt, counter,0 , len, dma_mapped, + page, pbc, dma_addr); + +if (nfrags) { + ret =qib_user_sdma_init_payload (dd, pq, pkt, + iov + idx_save +1 , + nfrags, npages); +if (ret <0 ) + goto free_pbc_dma; + } + + counter++; + npkts++; + +list_add_tail (&pkt->list, list); + } + + ret = idx; + goto done; + +free_pbc_dma: +if (dma_mapped) +dma_unmap_page (&dd->pcidev->dev, dma_addr, len,DMA_TO_DEVICE ); +free_pbc: +if (page) { +kunmap (page); +__free_page (page); + }else +dma_pool_free (pq->header_cache, pbc, dma_addr); +free_pkt: +kmem_cache_free (pq->pkt_slab, pkt); +free_list: +qib_user_sdma_free_pkt_list (&dd->pcidev->dev, pq, list); +done: +return ret; +} + +static void qib_user_sdma_set_complete_counter (struct qib_user_sdma_queue *pq, +u32 c) +{ + pq->sent_counter = c; +} + +/* try to clean out queue -- needs pq->lock */ +static int qib_user_sdma_queue_clean (struct qib_pportdata *ppd, +struct qib_user_sdma_queue *pq) +{ +struct qib_devdata *dd = ppd->dd; +struct list_head free_list; +struct qib_user_sdma_pkt *pkt; +struct qib_user_sdma_pkt *pkt_prev; +int ret =0 ; + +INIT_LIST_HEAD (&free_list); + +list_for_each_entry_safe (pkt, pkt_prev, &pq->sent, list) { +s64 descd = ppd->sdma_descq_removed - pkt->added; + +if (descd <0 ) +break ; + +list_move_tail (&pkt->list, &free_list); + +/* one more packet cleaned */ + ret++; + } + +if (!list_empty (&free_list)) { +u32 counter; + + pkt =list_entry (free_list.prev, + struct qib_user_sdma_pkt, list); + counter = pkt->counter; + +qib_user_sdma_free_pkt_list (&dd->pcidev->dev, pq, &free_list); +qib_user_sdma_set_complete_counter (pq, counter); + } + +return ret; +} + +void qib_user_sdma_queue_destroy (struct qib_user_sdma_queue *pq) +{ +if (!pq) +return ; + +kmem_cache_destroy (pq->pkt_slab); +dma_pool_destroy (pq->header_cache); +kfree (pq); +} + +/* clean descriptor queue, returns > 0 if some elements cleaned */ +static int qib_user_sdma_hwqueue_clean (struct qib_pportdata *ppd) +{ +int ret; +unsigned long flags; + +spin_lock_irqsave (&ppd->sdma_lock, flags); + ret =qib_sdma_make_progress (ppd); +spin_unlock_irqrestore (&ppd->sdma_lock, flags); + +return ret; +} + +/* we're in close, drain packets so that we can cleanup successfully... */ +void qib_user_sdma_queue_drain (struct qib_pportdata *ppd, +struct qib_user_sdma_queue *pq) +{ +struct qib_devdata *dd = ppd->dd; +int i; + +if (!pq) +return ; + +for (i =0 ; i <QIB_USER_SDMA_DRAIN_TIMEOUT ; i++) { +mutex_lock (&pq->lock); +if (list_empty (&pq->sent)) { +mutex_unlock (&pq->lock); +break ; + } +qib_user_sdma_hwqueue_clean (ppd); +qib_user_sdma_queue_clean (ppd, pq); +mutex_unlock (&pq->lock); +msleep (10 ); + } + +if (!list_empty (&pq->sent)) { +struct list_head free_list; + +qib_dev_err (dd,"user sdma lists not empty: forcing!\n" ); +INIT_LIST_HEAD (&free_list); +mutex_lock (&pq->lock); +list_splice_init (&pq->sent, &free_list); +qib_user_sdma_free_pkt_list (&dd->pcidev->dev, pq, &free_list); +mutex_unlock (&pq->lock); + } +} + +static inline __le64 qib_sdma_make_desc0 (struct qib_pportdata *ppd, +u64 addr,u64 dwlen,u64 dwoffset) +{ +u8 tmpgen; + + tmpgen = ppd->sdma_generation; + +return cpu_to_le64 (/* SDmaPhyAddr[31:0] */ + ((addr &0xfffffffcULL ) <<32 ) | +/* SDmaGeneration[1:0] */ + ((tmpgen &3ULL ) <<30 ) | +/* SDmaDwordCount[10:0] */ + ((dwlen &0x7ffULL ) <<16 ) | +/* SDmaBufOffset[12:2] */ + (dwoffset &0x7ffULL )); +} + +static inline __le64 qib_sdma_make_first_desc0 (__le64 descq) +{ +return descq |cpu_to_le64 (1ULL <<12 ); +} + +static inline __le64 qib_sdma_make_last_desc0 (__le64 descq) +{ +/* last */ /* dma head */ +return descq |cpu_to_le64 (1ULL <<11 |1ULL <<13 ); +} + +static inline __le64 qib_sdma_make_desc1 (u64 addr) +{ +/* SDmaPhyAddr[47:32] */ +return cpu_to_le64 (addr >>32 ); +} + +static void qib_user_sdma_send_frag (struct qib_pportdata *ppd, +struct qib_user_sdma_pkt *pkt,int idx, +unsigned ofs,u16 tail) +{ +const u64 addr = (u64 ) pkt->addr[idx].addr + + (u64 ) pkt->addr[idx].offset; +const u64 dwlen = (u64 ) pkt->addr[idx].length /4 ; +__le64 *descqp; +__le64 descq0; + + descqp = &ppd->sdma_descq[tail].qw[0 ]; + + descq0 =qib_sdma_make_desc0 (ppd, addr, dwlen, ofs); +if (idx ==0 ) + descq0 =qib_sdma_make_first_desc0 (descq0); +if (idx == pkt->naddr -1 ) + descq0 =qib_sdma_make_last_desc0 (descq0); + + descqp[0 ] = descq0; + descqp[1 ] =qib_sdma_make_desc1 (addr); +} + +/* pq->lock must be held, get packets on the wire... */ +static int qib_user_sdma_push_pkts (struct qib_pportdata *ppd, +struct qib_user_sdma_queue *pq, +struct list_head *pktlist) +{ +struct qib_devdata *dd = ppd->dd; +int ret =0 ; +unsigned long flags; +u16 tail; +u8 generation; +u64 descq_added; + +if (list_empty (pktlist)) +return 0 ; + +if (unlikely (!(ppd->lflags &QIBL_LINKACTIVE ))) +return -ECOMM ; + +spin_lock_irqsave (&ppd->sdma_lock, flags); + +/* keep a copy for restoring purposes in case of problems */ + generation = ppd->sdma_generation; + descq_added = ppd->sdma_descq_added; + +if (unlikely (!__qib_sdma_running (ppd))) { + ret = -ECOMM ; + goto unlock; + } + + tail = ppd->sdma_descq_tail; +while (!list_empty (pktlist)) { +struct qib_user_sdma_pkt *pkt = + list_entry(pktlist->next, struct qib_user_sdma_pkt, + list); +int i; +unsigned ofs =0 ; +u16 dtail = tail; + +if (pkt->naddr >qib_sdma_descq_freecnt (ppd)) + goto unlock_check_tail; + +for (i =0 ; i < pkt->naddr; i++) { +qib_user_sdma_send_frag (ppd, pkt, i, ofs, tail); + ofs += pkt->addr[i].length >>2 ; + +if (++tail == ppd->sdma_descq_cnt) { + tail =0 ; + ++ppd->sdma_generation; + } + } + +if ((ofs <<2 ) > ppd->ibmaxlen) { + ret = -EMSGSIZE ; + goto unlock; + } + +/* +* If the packet is >= 2KB mtu equivalent, we have to use +* the large buffers, and have to mark each descriptor as +* part of a large buffer packet. +*/ +if (ofs > dd->piosize2kmax_dwords) { +for (i =0 ; i < pkt->naddr; i++) { + ppd->sdma_descq[dtail].qw[0 ] |= +cpu_to_le64 (1ULL <<14 ); +if (++dtail == ppd->sdma_descq_cnt) + dtail =0 ; + } + } + + ppd->sdma_descq_added += pkt->naddr; + pkt->added = ppd->sdma_descq_added; +list_move_tail (&pkt->list, &pq->sent); + ret++; + } + +unlock_check_tail: +/* advance the tail on the chip if necessary */ +if (ppd->sdma_descq_tail != tail) + dd->f_sdma_update_tail (ppd, tail); + +unlock: +if (unlikely (ret <0 )) { + ppd->sdma_generation = generation; + ppd->sdma_descq_added = descq_added; + } +spin_unlock_irqrestore (&ppd->sdma_lock, flags); + +return ret; +} + +int qib_user_sdma_writev (struct qib_ctxtdata *rcd, +struct qib_user_sdma_queue *pq, +const struct iovec *iov, +unsigned long dim) +{ +struct qib_devdata *dd = rcd->dd; +struct qib_pportdata *ppd = rcd->ppd; +int ret =0 ; +struct list_head list; +int npkts =0 ; + +INIT_LIST_HEAD (&list); + +mutex_lock (&pq->lock); + +/* why not -ECOMM like qib_user_sdma_push_pkts() below? */ +if (!qib_sdma_running (ppd)) + goto done_unlock; + +if (ppd->sdma_descq_added != ppd->sdma_descq_removed) { +qib_user_sdma_hwqueue_clean (ppd); +qib_user_sdma_queue_clean (ppd, pq); + } + +while (dim) { +const int mxp =8 ; + +down_write (¤t->mm->mmap_sem); + ret =qib_user_sdma_queue_pkts (dd, pq, &list, iov, dim, mxp); +up_write (¤t->mm->mmap_sem); + +if (ret <=0 ) + goto done_unlock; +else { + dim -= ret; + iov += ret; + } + +/* force packets onto the sdma hw queue... */ +if (!list_empty (&list)) { +/* +* Lazily clean hw queue. the 4 is a guess of about +* how many sdma descriptors a packet will take (it +* doesn't have to be perfect). +*/ +if (qib_sdma_descq_freecnt (ppd) < ret *4 ) { +qib_user_sdma_hwqueue_clean (ppd); +qib_user_sdma_queue_clean (ppd, pq); + } + + ret =qib_user_sdma_push_pkts (ppd, pq, &list); +if (ret <0 ) + goto done_unlock; +else { + npkts += ret; + pq->counter += ret; + +if (!list_empty (&list)) + goto done_unlock; + } + } + } + +done_unlock: +if (!list_empty (&list)) +qib_user_sdma_free_pkt_list (&dd->pcidev->dev, pq, &list); +mutex_unlock (&pq->lock); + +return (ret <0 ) ? ret : npkts; +} + +int qib_user_sdma_make_progress (struct qib_pportdata *ppd, +struct qib_user_sdma_queue *pq) +{ +int ret =0 ; + +mutex_lock (&pq->lock); +qib_user_sdma_hwqueue_clean (ppd); + ret =qib_user_sdma_queue_clean (ppd, pq); +mutex_unlock (&pq->lock); + +return ret; +} + +u32 qib_user_sdma_complete_counter (const struct qib_user_sdma_queue *pq) +{ +return pq ? pq->sent_counter :0 ; +} + +u32 qib_user_sdma_inflight_counter (struct qib_user_sdma_queue *pq) +{ +return pq ? pq->counter :0 ; +}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 44/52 IB/qib: Add qib_user_sdma.h
In reply to a message not in the archivecreates the qib_user_sdma.h file.
---
drivers/infiniband/hw/qib/qib_user_sdma.h | 52 +++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/qib/qib_user_sdma.h
drivers/infiniband/hw/qib/qib_user_sdma.h new file +52 -0
@@ -0,0 +1,52 @@ +/* +* Copyright (c) 2007, 2008 QLogic Corporation. All rights reserved. +* +* This software is available to you under a choice of one of two +* licenses. You may choose to be licensed under the terms of the GNU +* General Public License (GPL) Version 2, available from the file +* COPYING in the main directory of this source tree, or the +* OpenIB.org BSD license below: +* +* 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. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +*/ +#include <linux/device.h> + +struct qib_user_sdma_queue ; + +struct qib_user_sdma_queue * +qib_user_sdma_queue_create (struct device *dev,int unit,int port,int sport); +void qib_user_sdma_queue_destroy (struct qib_user_sdma_queue *pq); + +int qib_user_sdma_writev (struct qib_ctxtdata *pd, +struct qib_user_sdma_queue *pq, +const struct iovec *iov, +unsigned long dim); + +int qib_user_sdma_make_progress (struct qib_pportdata *ppd, +struct qib_user_sdma_queue *pq); + +void qib_user_sdma_queue_drain (struct qib_pportdata *ppd, +struct qib_user_sdma_queue *pq); + +u32 qib_user_sdma_complete_counter (const struct qib_user_sdma_queue *pq); +u32 qib_user_sdma_inflight_counter (struct qib_user_sdma_queue *pq);
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html