Deleted Added
full compact
isp_pci.c (316408) isp_pci.c (317360)
1/*-
2 * Copyright (c) 1997-2008 by Matthew Jacob
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26/*
27 * PCI specific probe and attach routines for Qlogic ISP SCSI adapters.
28 * FreeBSD Version.
29 */
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1997-2008 by Matthew Jacob
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26/*
27 * PCI specific probe and attach routines for Qlogic ISP SCSI adapters.
28 * FreeBSD Version.
29 */
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: stable/11/sys/dev/isp/isp_pci.c 316408 2017-04-02 10:58:55Z mav $");
31__FBSDID("$FreeBSD: stable/11/sys/dev/isp/isp_pci.c 317360 2017-04-24 10:21:13Z mav $");
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/module.h>
37#include <sys/linker.h>
38#include <sys/firmware.h>
39#include <sys/bus.h>

--- 637 unchanged lines hidden (view full) ---

677 int i;
678 uint32_t data, cmd, linesz, did;
679 size_t psize, xsize;
680 char fwname[32];
681
682 pcs->pci_dev = dev;
683 isp->isp_dev = dev;
684 isp->isp_nchan = 1;
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/module.h>
37#include <sys/linker.h>
38#include <sys/firmware.h>
39#include <sys/bus.h>

--- 637 unchanged lines hidden (view full) ---

677 int i;
678 uint32_t data, cmd, linesz, did;
679 size_t psize, xsize;
680 char fwname[32];
681
682 pcs->pci_dev = dev;
683 isp->isp_dev = dev;
684 isp->isp_nchan = 1;
685 if (sizeof (bus_addr_t) > 4)
686 isp->isp_osinfo.sixtyfourbit = 1;
687 mtx_init(&isp->isp_lock, "isp", NULL, MTX_DEF);
688
689 /*
690 * Get Generic Options
691 */
692 isp_nvports = 0;
693 isp_get_generic_options(dev, isp);
694

--- 827 unchanged lines hidden (view full) ---

1522 slim = (bus_size_t) (1ULL << 32);
1523 else
1524 slim = (bus_size_t) (1UL << 31);
1525 llim = BUS_SPACE_MAXADDR;
1526 } else {
1527 slim = (1UL << 24);
1528 llim = BUS_SPACE_MAXADDR_32BIT;
1529 }
685 mtx_init(&isp->isp_lock, "isp", NULL, MTX_DEF);
686
687 /*
688 * Get Generic Options
689 */
690 isp_nvports = 0;
691 isp_get_generic_options(dev, isp);
692

--- 827 unchanged lines hidden (view full) ---

1520 slim = (bus_size_t) (1ULL << 32);
1521 else
1522 slim = (bus_size_t) (1UL << 31);
1523 llim = BUS_SPACE_MAXADDR;
1524 } else {
1525 slim = (1UL << 24);
1526 llim = BUS_SPACE_MAXADDR_32BIT;
1527 }
1530 if (isp->isp_osinfo.sixtyfourbit)
1528 if (sizeof (bus_size_t) > 4)
1531 nsegs = ISP_NSEG64_MAX;
1532 else
1533 nsegs = ISP_NSEG_MAX;
1534
1535 if (bus_dma_tag_create(bus_get_dma_tag(ISP_PCD(isp)), 1,
1536 slim, llim, hlim, NULL, NULL, BUS_SPACE_MAXSIZE, nsegs, slim, 0,
1537 busdma_lock_mutex, &isp->isp_lock, &isp->isp_osinfo.dmat)) {
1538 ISP_LOCK(isp);

--- 295 unchanged lines hidden (view full) ---

1834 ispsoftc_t *isp;
1835 void *cmd_token;
1836 void *rq; /* original request */
1837 int error;
1838} mush_t;
1839
1840#define MUSHERR_NOQENTRIES -2
1841
1529 nsegs = ISP_NSEG64_MAX;
1530 else
1531 nsegs = ISP_NSEG_MAX;
1532
1533 if (bus_dma_tag_create(bus_get_dma_tag(ISP_PCD(isp)), 1,
1534 slim, llim, hlim, NULL, NULL, BUS_SPACE_MAXSIZE, nsegs, slim, 0,
1535 busdma_lock_mutex, &isp->isp_lock, &isp->isp_osinfo.dmat)) {
1536 ISP_LOCK(isp);

--- 295 unchanged lines hidden (view full) ---

1832 ispsoftc_t *isp;
1833 void *cmd_token;
1834 void *rq; /* original request */
1835 int error;
1836} mush_t;
1837
1838#define MUSHERR_NOQENTRIES -2
1839
1842#ifdef ISP_TARGET_MODE
1843static void
1840static void
1844tdma2(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1841dma2(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1845{
1842{
1846 mush_t *mp;
1847 ispsoftc_t *isp;
1848 struct ccb_scsiio *csio;
1843 mush_t *mp = (mush_t *) arg;
1844 ispsoftc_t *isp= mp->isp;
1845 struct ccb_scsiio *csio = mp->cmd_token;
1849 isp_ddir_t ddir;
1846 isp_ddir_t ddir;
1850 ispreq_t *rq;
1847 int sdir;
1851
1848
1852 mp = (mush_t *) arg;
1853 if (error) {
1854 mp->error = error;
1855 return;
1856 }
1849 if (error) {
1850 mp->error = error;
1851 return;
1852 }
1857 csio = mp->cmd_token;
1858 isp = mp->isp;
1859 rq = mp->rq;
1860 if (nseg) {
1861 if (isp->isp_osinfo.sixtyfourbit) {
1862 if (nseg >= ISP_NSEG64_MAX) {
1863 isp_prt(isp, ISP_LOGERR, "number of segments (%d) exceed maximum we can support (%d)", nseg, ISP_NSEG64_MAX);
1864 mp->error = EFAULT;
1865 return;
1866 }
1867 if (rq->req_header.rqs_entry_type == RQSTYPE_CTIO2) {
1868 rq->req_header.rqs_entry_type = RQSTYPE_CTIO3;
1869 }
1870 } else {
1871 if (nseg >= ISP_NSEG_MAX) {
1872 isp_prt(isp, ISP_LOGERR, "number of segments (%d) exceed maximum we can support (%d)", nseg, ISP_NSEG_MAX);
1873 mp->error = EFAULT;
1874 return;
1875 }
1876 }
1853 if (nseg == 0) {
1854 ddir = ISP_NOXFR;
1855 } else {
1877 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1856 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1878 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREWRITE);
1879 ddir = ISP_TO_DEVICE;
1880 } else if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
1881 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREREAD);
1882 ddir = ISP_FROM_DEVICE;
1883 } else {
1857 ddir = ISP_FROM_DEVICE;
1858 } else {
1884 dm_segs = NULL;
1885 nseg = 0;
1886 ddir = ISP_NOXFR;
1859 ddir = ISP_TO_DEVICE;
1887 }
1860 }
1888 } else {
1889 dm_segs = NULL;
1890 nseg = 0;
1891 ddir = ISP_NOXFR;
1892 }
1893
1894 error = isp_send_tgt_cmd(isp, rq, dm_segs, nseg, XS_XFRLEN(csio), ddir, &csio->sense_data, csio->sense_len);
1895 switch (error) {
1896 case CMD_EAGAIN:
1897 mp->error = MUSHERR_NOQENTRIES;
1898 case CMD_QUEUED:
1899 break;
1900 default:
1901 mp->error = EIO;
1902 }
1903}
1904#endif
1905
1906static void
1907dma2(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
1908{
1909 mush_t *mp;
1910 ispsoftc_t *isp;
1911 struct ccb_scsiio *csio;
1912 isp_ddir_t ddir;
1913 ispreq_t *rq;
1914
1915 mp = (mush_t *) arg;
1916 if (error) {
1917 mp->error = error;
1918 return;
1919 }
1920 csio = mp->cmd_token;
1921 isp = mp->isp;
1922 rq = mp->rq;
1923 if (nseg) {
1924 if (isp->isp_osinfo.sixtyfourbit) {
1925 if (nseg >= ISP_NSEG64_MAX) {
1926 isp_prt(isp, ISP_LOGERR, "number of segments (%d) exceed maximum we can support (%d)", nseg, ISP_NSEG64_MAX);
1927 mp->error = EFAULT;
1928 return;
1929 }
1930 if (rq->req_header.rqs_entry_type == RQSTYPE_T2RQS) {
1931 rq->req_header.rqs_entry_type = RQSTYPE_T3RQS;
1932 } else if (rq->req_header.rqs_entry_type == RQSTYPE_REQUEST) {
1933 rq->req_header.rqs_entry_type = RQSTYPE_A64;
1934 }
1861 if ((csio->ccb_h.func_code == XPT_CONT_TARGET_IO) ^
1862 ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)) {
1863 sdir = BUS_DMASYNC_PREREAD;
1935 } else {
1864 } else {
1936 if (nseg >= ISP_NSEG_MAX) {
1937 isp_prt(isp, ISP_LOGERR, "number of segments (%d) exceed maximum we can support (%d)", nseg, ISP_NSEG_MAX);
1938 mp->error = EFAULT;
1939 return;
1940 }
1865 sdir = BUS_DMASYNC_PREWRITE;
1941 }
1866 }
1942 if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
1943 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREREAD);
1944 ddir = ISP_FROM_DEVICE;
1945 } else if ((csio->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
1946 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap, BUS_DMASYNC_PREWRITE);
1947 ddir = ISP_TO_DEVICE;
1948 } else {
1949 ddir = ISP_NOXFR;
1950 }
1951 } else {
1952 dm_segs = NULL;
1953 nseg = 0;
1954 ddir = ISP_NOXFR;
1867 bus_dmamap_sync(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap,
1868 sdir);
1955 }
1956
1869 }
1870
1957 error = isp_send_cmd(isp, rq, dm_segs, nseg, XS_XFRLEN(csio), ddir, (ispds64_t *)csio->req_map);
1871 error = isp_send_cmd(isp, mp->rq, dm_segs, nseg, XS_XFRLEN(csio),
1872 ddir, (ispds64_t *)csio->req_map);
1958 switch (error) {
1959 case CMD_EAGAIN:
1960 mp->error = MUSHERR_NOQENTRIES;
1961 break;
1962 case CMD_QUEUED:
1963 break;
1964 default:
1965 mp->error = EIO;
1966 break;
1967 }
1968}
1969
1970static int
1971isp_pci_dmasetup(ispsoftc_t *isp, struct ccb_scsiio *csio, void *ff)
1972{
1973 mush_t mush, *mp;
1873 switch (error) {
1874 case CMD_EAGAIN:
1875 mp->error = MUSHERR_NOQENTRIES;
1876 break;
1877 case CMD_QUEUED:
1878 break;
1879 default:
1880 mp->error = EIO;
1881 break;
1882 }
1883}
1884
1885static int
1886isp_pci_dmasetup(ispsoftc_t *isp, struct ccb_scsiio *csio, void *ff)
1887{
1888 mush_t mush, *mp;
1974 void (*eptr)(void *, bus_dma_segment_t *, int, int);
1975 int error;
1976
1977 mp = &mush;
1978 mp->isp = isp;
1979 mp->cmd_token = csio;
1980 mp->rq = ff;
1981 mp->error = 0;
1982
1889 int error;
1890
1891 mp = &mush;
1892 mp->isp = isp;
1893 mp->cmd_token = csio;
1894 mp->rq = ff;
1895 mp->error = 0;
1896
1983#ifdef ISP_TARGET_MODE
1984 if (csio->ccb_h.func_code == XPT_CONT_TARGET_IO)
1985 eptr = tdma2;
1986 else
1987#endif
1988 eptr = dma2;
1989
1990 error = bus_dmamap_load_ccb(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap,
1897 error = bus_dmamap_load_ccb(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap,
1991 (union ccb *)csio, eptr, mp, 0);
1898 (union ccb *)csio, dma2, mp, 0);
1992 if (error == EINPROGRESS) {
1993 bus_dmamap_unload(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap);
1994 mp->error = EINVAL;
1995 isp_prt(isp, ISP_LOGERR, "deferred dma allocation not supported");
1996 } else if (error && mp->error == 0) {
1997#ifdef DIAGNOSTIC
1998 isp_prt(isp, ISP_LOGERR, "error %d in dma mapping code", error);
1999#endif

--- 114 unchanged lines hidden ---
1899 if (error == EINPROGRESS) {
1900 bus_dmamap_unload(isp->isp_osinfo.dmat, PISP_PCMD(csio)->dmap);
1901 mp->error = EINVAL;
1902 isp_prt(isp, ISP_LOGERR, "deferred dma allocation not supported");
1903 } else if (error && mp->error == 0) {
1904#ifdef DIAGNOSTIC
1905 isp_prt(isp, ISP_LOGERR, "error %d in dma mapping code", error);
1906#endif

--- 114 unchanged lines hidden ---