sbp.c (110129) | sbp.c (110145) |
---|---|
1/* 2 * Copyright (c) 1998,1999,2000,2001 Katsushi Kobayashi and Hidetosh Shimokawa 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 --- 16 unchanged lines hidden (view full) --- 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 * | 1/* 2 * Copyright (c) 1998,1999,2000,2001 Katsushi Kobayashi and Hidetosh Shimokawa 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 --- 16 unchanged lines hidden (view full) --- 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 * |
33 * $FreeBSD: head/sys/dev/firewire/sbp.c 110129 2003-01-31 03:09:13Z simokawa $ | 33 * $FreeBSD: head/sys/dev/firewire/sbp.c 110145 2003-01-31 14:11:22Z simokawa $ |
34 * 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/module.h> 40#include <sys/bus.h> 41#include <sys/mbuf.h> --- 212 unchanged lines hidden (view full) --- 254static void sbp_execute_ocb __P((void *, bus_dma_segment_t *, int, int)); 255static void sbp_free_ocb __P((struct sbp_softc *, struct sbp_ocb *)); 256static void sbp_abort_ocb __P((struct sbp_ocb *, int)); 257static void sbp_abort_all_ocbs __P((struct sbp_dev *, int)); 258static struct fw_xfer * sbp_write_cmd __P((struct sbp_dev *, int, int)); 259static struct sbp_ocb * sbp_get_ocb __P((struct sbp_softc *)); 260static struct sbp_ocb * sbp_enqueue_ocb __P((struct sbp_dev *, struct sbp_ocb *)); 261static struct sbp_ocb * sbp_dequeue_ocb __P((struct sbp_dev *, u_int32_t)); | 34 * 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/module.h> 40#include <sys/bus.h> 41#include <sys/mbuf.h> --- 212 unchanged lines hidden (view full) --- 254static void sbp_execute_ocb __P((void *, bus_dma_segment_t *, int, int)); 255static void sbp_free_ocb __P((struct sbp_softc *, struct sbp_ocb *)); 256static void sbp_abort_ocb __P((struct sbp_ocb *, int)); 257static void sbp_abort_all_ocbs __P((struct sbp_dev *, int)); 258static struct fw_xfer * sbp_write_cmd __P((struct sbp_dev *, int, int)); 259static struct sbp_ocb * sbp_get_ocb __P((struct sbp_softc *)); 260static struct sbp_ocb * sbp_enqueue_ocb __P((struct sbp_dev *, struct sbp_ocb *)); 261static struct sbp_ocb * sbp_dequeue_ocb __P((struct sbp_dev *, u_int32_t)); |
262static void sbp_detach_target __P((struct sbp_target *)); | 262static void sbp_cam_detach_target __P((struct sbp_target *)); |
263static void sbp_timeout __P((void *arg)); 264static void sbp_mgm_orb __P((struct sbp_dev *, int)); 265 266MALLOC_DEFINE(M_SBP, "sbp", "SBP-II/FireWire"); 267 268/* cam related functions */ 269static void sbp_action(struct cam_sim *sim, union ccb *ccb); 270static void sbp_poll(struct cam_sim *sim); --- 349 unchanged lines hidden (view full) --- 620 target = &sbp->targets[i]; 621 for( fwdev = TAILQ_FIRST(&sbp->fd.fc->devices); 622 fwdev != NULL; fwdev = TAILQ_NEXT(fwdev, link)){ 623 if(target->fwdev == NULL) break; 624 if(target->fwdev == fwdev) break; 625 } 626 if(fwdev == NULL){ 627 /* device has removed in lower driver */ | 263static void sbp_timeout __P((void *arg)); 264static void sbp_mgm_orb __P((struct sbp_dev *, int)); 265 266MALLOC_DEFINE(M_SBP, "sbp", "SBP-II/FireWire"); 267 268/* cam related functions */ 269static void sbp_action(struct cam_sim *sim, union ccb *ccb); 270static void sbp_poll(struct cam_sim *sim); --- 349 unchanged lines hidden (view full) --- 620 target = &sbp->targets[i]; 621 for( fwdev = TAILQ_FIRST(&sbp->fd.fc->devices); 622 fwdev != NULL; fwdev = TAILQ_NEXT(fwdev, link)){ 623 if(target->fwdev == NULL) break; 624 if(target->fwdev == fwdev) break; 625 } 626 if(fwdev == NULL){ 627 /* device has removed in lower driver */ |
628 sbp_detach_target(target); | 628 sbp_cam_detach_target(target); 629 if (target->luns != NULL) 630 free(target->luns, M_SBP); 631 target->num_lun = 0;; 632 target->luns = NULL; 633 target->fwdev = NULL; |
629 } 630 } 631 /* traverse device list */ 632 for( fwdev = TAILQ_FIRST(&sbp->fd.fc->devices); 633 fwdev != NULL; fwdev = TAILQ_NEXT(fwdev, link)){ 634SBP_DEBUG(0) 635 printf("sbp_post_explore: EUI:%08x%08x ", 636 fwdev->eui.hi, fwdev->eui.lo); --- 972 unchanged lines hidden (view full) --- 1609 s = splfw(); 1610 sbp_post_explore((void *)sbp); 1611 splx(s); 1612 1613 return (0); 1614} 1615 1616static int | 634 } 635 } 636 /* traverse device list */ 637 for( fwdev = TAILQ_FIRST(&sbp->fd.fc->devices); 638 fwdev != NULL; fwdev = TAILQ_NEXT(fwdev, link)){ 639SBP_DEBUG(0) 640 printf("sbp_post_explore: EUI:%08x%08x ", 641 fwdev->eui.hi, fwdev->eui.lo); --- 972 unchanged lines hidden (view full) --- 1614 s = splfw(); 1615 sbp_post_explore((void *)sbp); 1616 splx(s); 1617 1618 return (0); 1619} 1620 1621static int |
1622sbp_logout_all(struct sbp_softc *sbp) 1623{ 1624 struct sbp_target *target; 1625 struct sbp_dev *sdev; 1626 int i, j; 1627 1628SBP_DEBUG(0) 1629 printf("sbp_logout_all\n"); 1630END_DEBUG 1631 for (i = 0 ; i < SBP_NUM_TARGETS ; i ++) { 1632 target = &sbp->targets[i]; 1633 if (target->luns == NULL) 1634 continue; 1635 for (j = 0; j < target->num_lun; j++) { 1636 sdev = &target->luns[j]; 1637 if (sdev->status == SBP_DEV_ATTACHED) { 1638 sbp_show_sdev_info(sdev, 2); 1639 printf("logout\n"); 1640 sbp_mgm_orb(sdev, ORB_FUN_LGO); 1641 } 1642 } 1643 } 1644 return 0; 1645} 1646 1647static int 1648sbp_shutdown(device_t dev) 1649{ 1650 struct sbp_softc *sbp = ((struct sbp_softc *)device_get_softc(dev)); 1651 1652 sbp_logout_all(sbp); 1653 return (0); 1654} 1655 1656static int |
|
1617sbp_detach(device_t dev) 1618{ 1619 struct sbp_softc *sbp = ((struct sbp_softc *)device_get_softc(dev)); 1620 struct firewire_comm *fc = sbp->fd.fc; 1621 int i; 1622 1623SBP_DEBUG(0) 1624 printf("sbp_detach\n"); 1625END_DEBUG | 1657sbp_detach(device_t dev) 1658{ 1659 struct sbp_softc *sbp = ((struct sbp_softc *)device_get_softc(dev)); 1660 struct firewire_comm *fc = sbp->fd.fc; 1661 int i; 1662 1663SBP_DEBUG(0) 1664 printf("sbp_detach\n"); 1665END_DEBUG |
1626 | 1666#if 0 |
1627 /* bus reset for logout */ 1628 sbp->fd.post_explore = NULL; 1629 fc->ibr(fc); | 1667 /* bus reset for logout */ 1668 sbp->fd.post_explore = NULL; 1669 fc->ibr(fc); |
1670#endif |
|
1630 | 1671 |
1631 contigfree(sbp->ocb, sizeof (struct sbp_ocb) * SBP_NUM_OCB, M_SBP); 1632 fw_bindremove(fc, &sbp->fwb); | |
1633 for (i = 0; i < SBP_NUM_TARGETS; i ++) | 1672 for (i = 0; i < SBP_NUM_TARGETS; i ++) |
1634 sbp_detach_target(&sbp->targets[i]); | 1673 sbp_cam_detach_target(&sbp->targets[i]); |
1635 xpt_bus_deregister(cam_sim_path(sbp->sim)); | 1674 xpt_bus_deregister(cam_sim_path(sbp->sim)); |
1675 1676 sbp_logout_all(sbp); 1677 /* XXX wait for logout completion */ 1678 tsleep(&i, FWPRI, "sbpdtc", hz/2); 1679 1680 fw_bindremove(fc, &sbp->fwb); 1681 contigfree(sbp->ocb, sizeof (struct sbp_ocb) * SBP_NUM_OCB, M_SBP); |
|
1636 bus_dma_tag_destroy(sbp->dmat); | 1682 bus_dma_tag_destroy(sbp->dmat); |
1683 1684 for (i = 0; i < SBP_NUM_TARGETS; i ++) 1685 if (sbp->targets[i].luns != NULL) 1686 free(sbp->targets[i].luns, M_SBP); 1687 |
|
1637 return (0); 1638} 1639 1640static void | 1688 return (0); 1689} 1690 1691static void |
1641sbp_detach_target(struct sbp_target *target) | 1692sbp_cam_detach_target(struct sbp_target *target) |
1642{ 1643 int i; 1644 struct sbp_dev *sdev; 1645 1646 if (target->luns != NULL) { 1647SBP_DEBUG(0) 1648 printf("sbp_detach_target %d\n", target->target_id); 1649END_DEBUG 1650 for (i=0; i < target->num_lun; i++) { 1651 sdev = &target->luns[i]; 1652 if (sdev->status == SBP_DEV_RESET || 1653 sdev->status == SBP_DEV_DEAD) 1654 continue; 1655 if (sdev->path) 1656 xpt_async(AC_LOST_DEVICE, sdev->path, NULL); 1657 xpt_free_path(sdev->path); 1658 sdev->path = NULL; 1659 sbp_abort_all_ocbs(sdev, CAM_DEV_NOT_THERE); 1660 } | 1693{ 1694 int i; 1695 struct sbp_dev *sdev; 1696 1697 if (target->luns != NULL) { 1698SBP_DEBUG(0) 1699 printf("sbp_detach_target %d\n", target->target_id); 1700END_DEBUG 1701 for (i=0; i < target->num_lun; i++) { 1702 sdev = &target->luns[i]; 1703 if (sdev->status == SBP_DEV_RESET || 1704 sdev->status == SBP_DEV_DEAD) 1705 continue; 1706 if (sdev->path) 1707 xpt_async(AC_LOST_DEVICE, sdev->path, NULL); 1708 xpt_free_path(sdev->path); 1709 sdev->path = NULL; 1710 sbp_abort_all_ocbs(sdev, CAM_DEV_NOT_THERE); 1711 } |
1661 free(target->luns, M_SBP); 1662 target->luns = NULL; | |
1663 } | 1712 } |
1664 target->fwdev = NULL; | |
1665} 1666 1667static void 1668sbp_timeout(void *arg) 1669{ 1670 struct sbp_ocb *ocb = (struct sbp_ocb *)arg; 1671 struct sbp_dev *sdev = ocb->sdev; 1672 int s; --- 548 unchanged lines hidden (view full) --- 2221static devclass_t sbp_devclass; 2222 2223static device_method_t sbp_methods[] = { 2224 /* device interface */ 2225 DEVMETHOD(device_identify, sbp_identify), 2226 DEVMETHOD(device_probe, sbp_probe), 2227 DEVMETHOD(device_attach, sbp_attach), 2228 DEVMETHOD(device_detach, sbp_detach), | 1713} 1714 1715static void 1716sbp_timeout(void *arg) 1717{ 1718 struct sbp_ocb *ocb = (struct sbp_ocb *)arg; 1719 struct sbp_dev *sdev = ocb->sdev; 1720 int s; --- 548 unchanged lines hidden (view full) --- 2269static devclass_t sbp_devclass; 2270 2271static device_method_t sbp_methods[] = { 2272 /* device interface */ 2273 DEVMETHOD(device_identify, sbp_identify), 2274 DEVMETHOD(device_probe, sbp_probe), 2275 DEVMETHOD(device_attach, sbp_attach), 2276 DEVMETHOD(device_detach, sbp_detach), |
2277 DEVMETHOD(device_shutdown, sbp_shutdown), |
|
2229 2230 { 0, 0 } 2231}; 2232 2233static driver_t sbp_driver = { 2234 "sbp", 2235 sbp_methods, 2236 sizeof(struct sbp_softc), 2237}; 2238DRIVER_MODULE(sbp, firewire, sbp_driver, sbp_devclass, 0, 0); 2239MODULE_VERSION(sbp, 1); 2240MODULE_DEPEND(sbp, firewire, 1, 1, 1); 2241MODULE_DEPEND(sbp, cam, 1, 1, 1); | 2278 2279 { 0, 0 } 2280}; 2281 2282static driver_t sbp_driver = { 2283 "sbp", 2284 sbp_methods, 2285 sizeof(struct sbp_softc), 2286}; 2287DRIVER_MODULE(sbp, firewire, sbp_driver, sbp_devclass, 0, 0); 2288MODULE_VERSION(sbp, 1); 2289MODULE_DEPEND(sbp, firewire, 1, 1, 1); 2290MODULE_DEPEND(sbp, cam, 1, 1, 1); |