svn commit: r210581 - projects/ofed/head/sys/ofed/include/linux
Jeff Roberson
jeff at FreeBSD.org
Thu Jul 29 02:08:22 UTC 2010
Author: jeff
Date: Thu Jul 29 02:08:21 2010
New Revision: 210581
URL: http://svn.freebsd.org/changeset/base/210581
Log:
- Make a minorly incompatible version of request_irq() that passes the
device as the last parameter so it is easy to port linux code. The
alternative would be to search all devices for the one which may have
been assigned that irq to maintain a diffless compat layer.
- Update the generic dma and pci dma with routines used by mthca.
- Add various pci register defines and convenience functions.
- Correct scatterlist usage.
Sponsored by: Isilon Systems, iX Systems, and Panasas.
Modified:
projects/ofed/head/sys/ofed/include/linux/dma-mapping.h
projects/ofed/head/sys/ofed/include/linux/hardirq.h
projects/ofed/head/sys/ofed/include/linux/interrupt.h
projects/ofed/head/sys/ofed/include/linux/pci.h
projects/ofed/head/sys/ofed/include/linux/scatterlist.h
Modified: projects/ofed/head/sys/ofed/include/linux/dma-mapping.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/dma-mapping.h Thu Jul 29 02:05:06 2010 (r210580)
+++ projects/ofed/head/sys/ofed/include/linux/dma-mapping.h Thu Jul 29 02:08:21 2010 (r210581)
@@ -33,6 +33,7 @@
#include <linux/err.h>
#include <linux/dma-attrs.h>
#include <linux/scatterlist.h>
+#include <linux/mm.h>
#include <linux/page.h>
#include <sys/systm.h>
@@ -123,14 +124,15 @@ dma_alloc_coherent(struct device *dev, s
gfp_t flag)
{
vm_paddr_t high;
+ size_t align;
void *mem;
if (dev->dma_mask)
high = *dev->dma_mask;
else
high = BUS_SPACE_MAXADDR_32BIT;
-
- mem = contigmalloc(size, M_LINUX_DMA, flag, 0, high, 1, 0);
+ align = PAGE_SIZE << get_order(size);
+ mem = contigmalloc(size, M_LINUX_DMA, flag, 0, high, align, 0);
if (mem)
*dma_handle = vtophys(mem);
else
@@ -236,6 +238,13 @@ dma_mapping_error(struct device *dev, dm
#define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL)
#define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL)
+#define DEFINE_DMA_UNMAP_ADDR(name) dma_addr_t name
+#define DEFINE_DMA_UNMAP_LEN(name) __u32 name
+#define dma_unmap_addr(p, name) ((p)->name)
+#define dma_unmap_addr_set(p, name, v) (((p)->name) = (v))
+#define dma_unmap_len(p, name) ((p)->name)
+#define dma_unmap_len_set(p, name, v) (((p)->name) = (v))
+
extern int uma_align_cache;
#define dma_get_cache_alignment() uma_align_cache
Modified: projects/ofed/head/sys/ofed/include/linux/hardirq.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/hardirq.h Thu Jul 29 02:05:06 2010 (r210580)
+++ projects/ofed/head/sys/ofed/include/linux/hardirq.h Thu Jul 29 02:08:21 2010 (r210581)
@@ -28,6 +28,6 @@
#ifndef _LINUX_HARDIRQ_H_
#define _LINUX_HARDIRQ_H_
-#define synchronize_irq(irq) panic("Unimplemented");
+#define synchronize_irq(irq) printf("synchronize_irq: Unimplemented\n")
#endif /* _LINUX_HARDIRQ_H_ */
Modified: projects/ofed/head/sys/ofed/include/linux/interrupt.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/interrupt.h Thu Jul 29 02:05:06 2010 (r210580)
+++ projects/ofed/head/sys/ofed/include/linux/interrupt.h Thu Jul 29 02:08:21 2010 (r210581)
@@ -46,28 +46,28 @@ _irq_handler(void *device)
struct device *dev;
dev = device;
- dev->irqhandler(0, dev);
+ dev->irqhandler(0, dev->irqarg);
}
static inline int
request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
- const char *name, void *device)
+ const char *name, void *arg, struct device *dev)
{
struct resource *res;
- struct device *dev;
int error;
int rid;
- dev = device;
rid = 0;
- res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, flags | RF_ACTIVE);
+ res = bus_alloc_resource_any(dev->bsddev, SYS_RES_IRQ, &rid,
+ flags | RF_ACTIVE);
if (res == NULL)
return (-ENXIO);
- error = bus_setup_intr(dev, res, INTR_TYPE_NET | INTR_MPSAFE, NULL,
- _irq_handler, dev, &dev->irqtag);
+ error = bus_setup_intr(dev->bsddev, res, INTR_TYPE_NET | INTR_MPSAFE,
+ NULL, _irq_handler, dev, &dev->irqtag);
if (error)
return (-error);
dev->irqhandler = handler;
+ dev->irqarg = arg;
return 0;
}
Modified: projects/ofed/head/sys/ofed/include/linux/pci.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/pci.h Thu Jul 29 02:05:06 2010 (r210580)
+++ projects/ofed/head/sys/ofed/include/linux/pci.h Thu Jul 29 02:08:21 2010 (r210581)
@@ -61,13 +61,28 @@ struct pci_device_id {
#define MODULE_DEVICE_TABLE(bus, table)
#define PCI_ANY_ID (-1)
-#define PCI_VENDOR_ID_MELLANOX 0x15b3
+#define PCI_VENDOR_ID_MELLANOX 0x15b3
+#define PCI_VENDOR_ID_TOPSPIN 0x1867
+#define PCI_DEVICE_ID_MELLANOX_TAVOR 0x5a44
+#define PCI_DEVICE_ID_MELLANOX_TAVOR_BRIDGE 0x5a46
+#define PCI_DEVICE_ID_MELLANOX_ARBEL_COMPAT 0x6278
+#define PCI_DEVICE_ID_MELLANOX_ARBEL 0x6282
+#define PCI_DEVICE_ID_MELLANOX_SINAI_OLD 0x5e8c
+#define PCI_DEVICE_ID_MELLANOX_SINAI 0x6274
+
#define PCI_VDEVICE(vendor, device) \
PCI_VENDOR_ID_##vendor, (device), PCI_ANY_ID, PCI_ANY_ID, 0, 0
+#define PCI_DEVICE(vendor, device) \
+ (vendor), (device), PCI_ANY_ID, PCI_ANY_ID, 0, 0
#define to_pci_dev(n) container_of(n, struct pci_dev, dev)
+#define PCI_VENDOR_ID PCIR_DEVVENDOR
+#define PCI_COMMAND PCIR_COMMAND
+#define PCI_EXP_DEVCTL PCIR_EXPRESS_DEVICE_CTL
+#define PCI_EXP_LNKCTL PCIR_EXPRESS_LINK_CTL
+
#define IORESOURCE_MEM SYS_RES_MEMORY
#define IORESOURCE_IO SYS_RES_IOPORT
#define IORESOURCE_IRQ SYS_RES_IRQ
@@ -112,6 +127,7 @@ _pci_get_bar(struct pci_dev *pdev, int b
{
struct resource_list_entry *rle;
+ bar = PCIR_BAR(bar);
if ((rle = _pci_get_rle(pdev, SYS_RES_MEMORY, bar)) == NULL)
rle = _pci_get_rle(pdev, SYS_RES_IOPORT, bar);
return (rle);
@@ -200,6 +216,8 @@ pci_request_region(struct pci_dev *pdev,
int type;
type = pci_resource_flags(pdev, bar);
+ if (type == 0)
+ return (-ENODEV);
rid = PCIR_BAR(bar);
if (bus_alloc_resource_any(pdev->dev.bsddev, type, &rid,
RF_ACTIVE) == NULL)
@@ -218,12 +236,98 @@ pci_release_region(struct pci_dev *pdev,
}
static inline void
+pci_release_regions(struct pci_dev *pdev)
+{
+ int i;
+
+ for (i = 0; i <= PCIR_MAX_BAR_0; i++)
+ pci_release_region(pdev, i);
+}
+
+static inline int
+pci_request_regions(struct pci_dev *pdev, const char *res_name)
+{
+ int error;
+ int i;
+
+ for (i = 0; i <= PCIR_MAX_BAR_0; i++) {
+ error = pci_request_region(pdev, i, res_name);
+ if (error && error != -ENODEV) {
+ pci_release_regions(pdev);
+ return (error);
+ }
+ }
+ return (0);
+}
+
+static inline void
pci_disable_msix(struct pci_dev *pdev)
{
pci_release_msi(pdev->dev.bsddev);
}
+#define PCI_CAP_ID_EXP PCIY_EXPRESS
+#define PCI_CAP_ID_PCIX PCIY_PCIX
+
+static inline int
+pci_find_capability(struct pci_dev *pdev, int capid)
+{
+ int reg;
+
+ if (pci_find_extcap(pdev->dev.bsddev, capid, ®))
+ return (0);
+ return (reg);
+}
+
+static inline int
+pci_read_config_byte(struct pci_dev *pdev, int where, u8 *val)
+{
+
+ *val = (u8)pci_read_config(pdev->dev.bsddev, where, 1);
+ return (0);
+}
+
+static inline int
+pci_read_config_word(struct pci_dev *pdev, int where, u16 *val)
+{
+
+ *val = (u16)pci_read_config(pdev->dev.bsddev, where, 2);
+ return (0);
+}
+
+static inline int
+pci_read_config_dword(struct pci_dev *pdev, int where, u32 *val)
+{
+
+ *val = (u32)pci_read_config(pdev->dev.bsddev, where, 4);
+ return (0);
+}
+
+static inline int
+pci_write_config_byte(struct pci_dev *pdev, int where, u8 val)
+{
+
+ pci_write_config(pdev->dev.bsddev, where, val, 1);
+ return (0);
+}
+
+static inline int
+pci_write_config_word(struct pci_dev *pdev, int where, u16 val)
+{
+
+ pci_write_config(pdev->dev.bsddev, where, val, 2);
+ return (0);
+}
+
+static inline int
+pci_write_config_dword(struct pci_dev *pdev, int where, u32 val)
+{
+
+ pci_write_config(pdev->dev.bsddev, where, val, 4);
+ return (0);
+}
+
static struct pci_driver *
linux_pci_find(device_t dev, struct pci_device_id **idp)
{
@@ -278,7 +382,9 @@ linux_pci_attach(device_t dev)
rle = _pci_get_rle(pdev, SYS_RES_IRQ, 0);
if (rle)
pdev->irq = rle->start;
+ mtx_unlock(&Giant);
error = pdrv->probe(pdev, id);
+ mtx_lock(&Giant);
if (error)
return (-error);
return (0);
@@ -329,6 +435,11 @@ pci_unregister_driver(struct pci_driver
devclass_delete_driver(bus, &pdrv->driver);
}
+/* XXX This should not be necessary. */
+#define pcix_set_mmrbc(d, v) 0
+#define pcix_get_max_mmrbc(d) 0
+#define pcie_set_readrq(d, v) 0
+
#define PCI_DMA_BIDIRECTIONAL 0
#define PCI_DMA_TODEVICE 1
#define PCI_DMA_FROMDEVICE 2
@@ -349,8 +460,23 @@ pci_unregister_driver(struct pci_driver
#define pci_unmap_sg(hwdev, sg, nents, direction) \
dma_unmap_sg((hwdev) == NULL ? NULL : &(hwdev)->dev, \
sg, nents, (enum dma_data_direction)direction)
+#define pci_map_page(hwdev, page, offset, size, direction) \
+ dma_map_page((hwdev) == NULL ? NULL : &(hwdev)->dev, page, \
+ offset, size, (enum dma_data_direction)direction)
+#define pci_unmap_page(hwdev, dma_address, size, direction) \
+ dma_unmap_page((hwdev) == NULL ? NULL : &(hwdev)->dev, \
+ dma_address, size, (enum dma_data_direction)direction)
#define pci_set_dma_mask(pdev, mask) dma_set_mask(&(pdev)->dev, (mask))
+#define pci_dma_mapping_error(pdev, dma_addr) \
+ dma_mapping_error(&(pdev)->dev, dma_addr)
#define pci_set_consistent_dma_mask(pdev, mask) \
dma_set_coherent_mask(&(pdev)->dev, (mask))
+#define DECLARE_PCI_UNMAP_ADDR(x) DEFINE_DMA_UNMAP_ADDR(x);
+#define DECLARE_PCI_UNMAP_LEN(x) DEFINE_DMA_UNMAP_LEN(x);
+#define pci_unmap_addr dma_unmap_addr
+#define pci_unmap_addr_set dma_unmap_addr_set
+#define pci_unmap_len dma_unmap_len
+#define pci_unmap_len_set dma_unmap_len_set
+
#endif /* _LINUX_PCI_H_ */
Modified: projects/ofed/head/sys/ofed/include/linux/scatterlist.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/scatterlist.h Thu Jul 29 02:05:06 2010 (r210580)
+++ projects/ofed/head/sys/ofed/include/linux/scatterlist.h Thu Jul 29 02:08:21 2010 (r210581)
@@ -56,7 +56,6 @@ sg_set_page(struct scatterlist *sg, stru
{
sg_page(sg) = page;
sg_dma_len(sg) = len;
- sg_dma_address(sg) = 0;
sg->offset = offset;
}
@@ -71,7 +70,7 @@ static inline void
sg_init_table(struct scatterlist *sg, unsigned int nents)
{
bzero(sg, sizeof(*sg) * nents);
- sg[nents].flags = SG_END;
+ sg[nents - 1].flags = SG_END;
}
static inline struct scatterlist *
More information about the svn-src-projects
mailing list