Deleted Added
full compact
sbp.c (271795) sbp.c (272214)
1/*-
2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
1/*-
2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 * $FreeBSD: head/sys/dev/firewire/sbp.c 271795 2014-09-18 17:28:21Z will $
35 *
33 *
34 * $FreeBSD: head/sys/dev/firewire/sbp.c 272214 2014-09-27 16:50:21Z kan $
35 *
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/module.h>
41#include <sys/bus.h>
42#include <sys/kernel.h>
43#include <sys/sysctl.h>

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

70 */
71#define SBP_NUM_LUNS 64
72#define SBP_MAXPHYS MIN(MAXPHYS, (512*1024) /* 512KB */)
73#define SBP_DMA_SIZE PAGE_SIZE
74#define SBP_LOGIN_SIZE sizeof(struct sbp_login_res)
75#define SBP_QUEUE_LEN ((SBP_DMA_SIZE - SBP_LOGIN_SIZE) / sizeof(struct sbp_ocb))
76#define SBP_NUM_OCB (SBP_QUEUE_LEN * SBP_NUM_TARGETS)
77
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/module.h>
41#include <sys/bus.h>
42#include <sys/kernel.h>
43#include <sys/sysctl.h>

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

70 */
71#define SBP_NUM_LUNS 64
72#define SBP_MAXPHYS MIN(MAXPHYS, (512*1024) /* 512KB */)
73#define SBP_DMA_SIZE PAGE_SIZE
74#define SBP_LOGIN_SIZE sizeof(struct sbp_login_res)
75#define SBP_QUEUE_LEN ((SBP_DMA_SIZE - SBP_LOGIN_SIZE) / sizeof(struct sbp_ocb))
76#define SBP_NUM_OCB (SBP_QUEUE_LEN * SBP_NUM_TARGETS)
77
78/*
78/*
79 * STATUS FIFO addressing
80 * bit
79 * STATUS FIFO addressing
80 * bit
81 * -----------------------
81 *-----------------------
82 * 0- 1( 2): 0 (alignment)
83 * 2- 7( 6): target
84 * 8-15( 8): lun
85 * 16-31( 8): reserved
82 * 0- 1( 2): 0 (alignment)
83 * 2- 7( 6): target
84 * 8-15( 8): lun
85 * 16-31( 8): reserved
86 * 32-47(16): SBP_BIND_HI
87 * 48-64(16): bus_id, node_id
86 * 32-47(16): SBP_BIND_HI
87 * 48-64(16): bus_id, node_id
88 */
89#define SBP_BIND_HI 0x1
90#define SBP_DEV2ADDR(t, l) \
91 (((u_int64_t)SBP_BIND_HI << 32) \
92 | (((l) & 0xff) << 8) \
93 | (((t) & 0x3f) << 2))
94#define SBP_ADDR2TRG(a) (((a) >> 2) & 0x3f)
95#define SBP_ADDR2LUN(a) (((a) >> 8) & 0xff)

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

149 bus_dmamap_t dmamap;
150 struct callout timer;
151};
152
153#define OCB_ACT_MGM 0
154#define OCB_ACT_CMD 1
155#define OCB_MATCH(o,s) ((o)->bus_addr == ntohl((s)->orb_lo))
156
88 */
89#define SBP_BIND_HI 0x1
90#define SBP_DEV2ADDR(t, l) \
91 (((u_int64_t)SBP_BIND_HI << 32) \
92 | (((l) & 0xff) << 8) \
93 | (((t) & 0x3f) << 2))
94#define SBP_ADDR2TRG(a) (((a) >> 2) & 0x3f)
95#define SBP_ADDR2LUN(a) (((a) >> 8) & 0xff)

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

149 bus_dmamap_t dmamap;
150 struct callout timer;
151};
152
153#define OCB_ACT_MGM 0
154#define OCB_ACT_CMD 1
155#define OCB_MATCH(o,s) ((o)->bus_addr == ntohl((s)->orb_lo))
156
157struct sbp_dev{
157struct sbp_dev {
158#define SBP_DEV_RESET 0 /* accept login */
159#define SBP_DEV_LOGIN 1 /* to login */
160#if 0
161#define SBP_DEV_RECONN 2 /* to reconnect */
162#endif
163#define SBP_DEV_TOATTACH 3 /* to attach */
164#define SBP_DEV_PROBE 4 /* scan lun */
165#define SBP_DEV_ATTACHED 5 /* in operation */

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

227static void sbp_post_explore (void *);
228static void sbp_recv (struct fw_xfer *);
229static void sbp_mgm_callback (struct fw_xfer *);
230#if 0
231static void sbp_cmd_callback (struct fw_xfer *);
232#endif
233static void sbp_orb_pointer (struct sbp_dev *, struct sbp_ocb *);
234static void sbp_doorbell(struct sbp_dev *);
158#define SBP_DEV_RESET 0 /* accept login */
159#define SBP_DEV_LOGIN 1 /* to login */
160#if 0
161#define SBP_DEV_RECONN 2 /* to reconnect */
162#endif
163#define SBP_DEV_TOATTACH 3 /* to attach */
164#define SBP_DEV_PROBE 4 /* scan lun */
165#define SBP_DEV_ATTACHED 5 /* in operation */

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

227static void sbp_post_explore (void *);
228static void sbp_recv (struct fw_xfer *);
229static void sbp_mgm_callback (struct fw_xfer *);
230#if 0
231static void sbp_cmd_callback (struct fw_xfer *);
232#endif
233static void sbp_orb_pointer (struct sbp_dev *, struct sbp_ocb *);
234static void sbp_doorbell(struct sbp_dev *);
235static void sbp_execute_ocb (void *, bus_dma_segment_t *, int, int);
235static void sbp_execute_ocb (void *, bus_dma_segment_t *, int, int);
236static void sbp_free_ocb (struct sbp_dev *, struct sbp_ocb *);
237static void sbp_abort_ocb (struct sbp_ocb *, int);
238static void sbp_abort_all_ocbs (struct sbp_dev *, int);
239static struct fw_xfer * sbp_write_cmd (struct sbp_dev *, int, int);
240static struct sbp_ocb * sbp_get_ocb (struct sbp_dev *);
241static struct sbp_ocb * sbp_enqueue_ocb (struct sbp_dev *, struct sbp_ocb *);
242static struct sbp_ocb * sbp_dequeue_ocb (struct sbp_dev *, struct sbp_status *);
243static void sbp_cam_detach_sdev(struct sbp_dev *);

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

383 int bus, i, target=-1;
384 char w[SBP_NUM_TARGETS];
385
386 bzero(w, sizeof(w));
387 bus = device_get_unit(sbp->fd.dev);
388
389 /* XXX wired-down configuration should be gotten from
390 tunable or device hint */
236static void sbp_free_ocb (struct sbp_dev *, struct sbp_ocb *);
237static void sbp_abort_ocb (struct sbp_ocb *, int);
238static void sbp_abort_all_ocbs (struct sbp_dev *, int);
239static struct fw_xfer * sbp_write_cmd (struct sbp_dev *, int, int);
240static struct sbp_ocb * sbp_get_ocb (struct sbp_dev *);
241static struct sbp_ocb * sbp_enqueue_ocb (struct sbp_dev *, struct sbp_ocb *);
242static struct sbp_ocb * sbp_dequeue_ocb (struct sbp_dev *, struct sbp_status *);
243static void sbp_cam_detach_sdev(struct sbp_dev *);

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

383 int bus, i, target=-1;
384 char w[SBP_NUM_TARGETS];
385
386 bzero(w, sizeof(w));
387 bus = device_get_unit(sbp->fd.dev);
388
389 /* XXX wired-down configuration should be gotten from
390 tunable or device hint */
391 for (i = 0; wired[i].bus >= 0; i ++) {
391 for (i = 0; wired[i].bus >= 0; i++) {
392 if (wired[i].bus == bus) {
393 w[wired[i].target] = 1;
394 if (wired[i].eui.hi == fwdev->eui.hi &&
395 wired[i].eui.lo == fwdev->eui.lo)
396 target = wired[i].target;
397 }
398 }
399 if (target >= 0) {
392 if (wired[i].bus == bus) {
393 w[wired[i].target] = 1;
394 if (wired[i].eui.hi == fwdev->eui.hi &&
395 wired[i].eui.lo == fwdev->eui.lo)
396 target = wired[i].target;
397 }
398 }
399 if (target >= 0) {
400 if(target < SBP_NUM_TARGETS &&
400 if (target < SBP_NUM_TARGETS &&
401 sbp->targets[target].fwdev == NULL)
401 sbp->targets[target].fwdev == NULL)
402 return(target);
402 return (target);
403 device_printf(sbp->fd.dev,
403 device_printf(sbp->fd.dev,
404 "target %d is not free for %08x:%08x\n",
404 "target %d is not free for %08x:%08x\n",
405 target, fwdev->eui.hi, fwdev->eui.lo);
406 target = -1;
407 }
408 /* non-wired target */
405 target, fwdev->eui.hi, fwdev->eui.lo);
406 target = -1;
407 }
408 /* non-wired target */
409 for (i = 0; i < SBP_NUM_TARGETS; i ++)
409 for (i = 0; i < SBP_NUM_TARGETS; i++)
410 if (sbp->targets[i].fwdev == NULL && w[i] == 0) {
411 target = i;
412 break;
413 }
414
415 return target;
416}
417

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

440 if (maxlun < lun)
441 maxlun = lun;
442 crom_next(&cc);
443 }
444 if (maxlun < 0)
445 device_printf(target->sbp->fd.dev, "%d no LUN found\n",
446 target->target_id);
447
410 if (sbp->targets[i].fwdev == NULL && w[i] == 0) {
411 target = i;
412 break;
413 }
414
415 return target;
416}
417

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

440 if (maxlun < lun)
441 maxlun = lun;
442 crom_next(&cc);
443 }
444 if (maxlun < 0)
445 device_printf(target->sbp->fd.dev, "%d no LUN found\n",
446 target->target_id);
447
448 maxlun ++;
448 maxlun++;
449 if (maxlun >= SBP_NUM_LUNS)
450 maxlun = SBP_NUM_LUNS;
451
452 /* Invalidiate stale devices */
449 if (maxlun >= SBP_NUM_LUNS)
450 maxlun = SBP_NUM_LUNS;
451
452 /* Invalidiate stale devices */
453 for (lun = 0; lun < target->num_lun; lun ++) {
453 for (lun = 0; lun < target->num_lun; lun++) {
454 sdev = target->luns[lun];
455 if (sdev == NULL)
456 continue;
457 sdev->flags &= ~VALID_LUN;
458 if (lun >= maxlun) {
459 /* lost device */
460 sbp_cam_detach_sdev(sdev);
461 sbp_free_sdev(sdev);
462 target->luns[lun] = NULL;
463 }
464 }
465
466 /* Reallocate */
467 if (maxlun != target->num_lun) {
468 newluns = (struct sbp_dev **) realloc(target->luns,
469 sizeof(struct sbp_dev *) * maxlun,
470 M_SBP, M_NOWAIT | M_ZERO);
454 sdev = target->luns[lun];
455 if (sdev == NULL)
456 continue;
457 sdev->flags &= ~VALID_LUN;
458 if (lun >= maxlun) {
459 /* lost device */
460 sbp_cam_detach_sdev(sdev);
461 sbp_free_sdev(sdev);
462 target->luns[lun] = NULL;
463 }
464 }
465
466 /* Reallocate */
467 if (maxlun != target->num_lun) {
468 newluns = (struct sbp_dev **) realloc(target->luns,
469 sizeof(struct sbp_dev *) * maxlun,
470 M_SBP, M_NOWAIT | M_ZERO);
471
471
472 if (newluns == NULL) {
473 printf("%s: realloc failed\n", __func__);
474 newluns = target->luns;
475 maxlun = target->num_lun;
476 }
477
478 /*
479 * We must zero the extended region for the case

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

522 sdev->lun_id);
523 }
524 sdev->flags |= VALID_LUN;
525 sdev->type = (reg->val & 0xff0000) >> 16;
526
527 if (new == 0)
528 goto next;
529
472 if (newluns == NULL) {
473 printf("%s: realloc failed\n", __func__);
474 newluns = target->luns;
475 maxlun = target->num_lun;
476 }
477
478 /*
479 * We must zero the extended region for the case

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

522 sdev->lun_id);
523 }
524 sdev->flags |= VALID_LUN;
525 sdev->type = (reg->val & 0xff0000) >> 16;
526
527 if (new == 0)
528 goto next;
529
530 fwdma_malloc(sbp->fd.fc,
530 fwdma_malloc(sbp->fd.fc,
531 /* alignment */ sizeof(uint32_t),
532 SBP_DMA_SIZE, &sdev->dma, BUS_DMA_NOWAIT |
533 BUS_DMA_COHERENT);
534 if (sdev->dma.v_addr == NULL) {
535 printf("%s: dma space allocation failed\n",
536 __func__);
537 free(sdev, M_SBP);
538 target->luns[lun] = NULL;
539 goto next;
540 }
541 sdev->login = (struct sbp_login_res *) sdev->dma.v_addr;
542 sdev->ocb = (struct sbp_ocb *)
543 ((char *)sdev->dma.v_addr + SBP_LOGIN_SIZE);
544 bzero((char *)sdev->ocb,
531 /* alignment */ sizeof(uint32_t),
532 SBP_DMA_SIZE, &sdev->dma, BUS_DMA_NOWAIT |
533 BUS_DMA_COHERENT);
534 if (sdev->dma.v_addr == NULL) {
535 printf("%s: dma space allocation failed\n",
536 __func__);
537 free(sdev, M_SBP);
538 target->luns[lun] = NULL;
539 goto next;
540 }
541 sdev->login = (struct sbp_login_res *) sdev->dma.v_addr;
542 sdev->ocb = (struct sbp_ocb *)
543 ((char *)sdev->dma.v_addr + SBP_LOGIN_SIZE);
544 bzero((char *)sdev->ocb,
545 sizeof (struct sbp_ocb) * SBP_QUEUE_LEN);
545 sizeof(struct sbp_ocb) * SBP_QUEUE_LEN);
546
547 STAILQ_INIT(&sdev->free_ocbs);
548 for (i = 0; i < SBP_QUEUE_LEN; i++) {
549 struct sbp_ocb *ocb;
550 ocb = &sdev->ocb[i];
551 ocb->bus_addr = sdev->dma.bus_addr
552 + SBP_LOGIN_SIZE
553 + sizeof(struct sbp_ocb) * i

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

559 }
560 callout_init_mtx(&ocb->timer, &sbp->mtx, 0);
561 sbp_free_ocb(sdev, ocb);
562 }
563next:
564 crom_next(&cc);
565 }
566
546
547 STAILQ_INIT(&sdev->free_ocbs);
548 for (i = 0; i < SBP_QUEUE_LEN; i++) {
549 struct sbp_ocb *ocb;
550 ocb = &sdev->ocb[i];
551 ocb->bus_addr = sdev->dma.bus_addr
552 + SBP_LOGIN_SIZE
553 + sizeof(struct sbp_ocb) * i

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

559 }
560 callout_init_mtx(&ocb->timer, &sbp->mtx, 0);
561 sbp_free_ocb(sdev, ocb);
562 }
563next:
564 crom_next(&cc);
565 }
566
567 for (lun = 0; lun < target->num_lun; lun ++) {
567 for (lun = 0; lun < target->num_lun; lun++) {
568 sdev = target->luns[lun];
569 if (sdev != NULL && (sdev->flags & VALID_LUN) == 0) {
570 sbp_cam_detach_sdev(sdev);
571 sbp_free_sdev(sdev);
572 target->luns[lun] = NULL;
573 }
574 }
575}

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

708 /* XXX untimeout mgm_ocb and dequeue */
709 for (i=0; i < target->num_lun; i++) {
710 sdev = target->luns[i];
711 if (sdev == NULL)
712 continue;
713 if (alive && (sdev->status != SBP_DEV_DEAD)) {
714 if (sdev->path != NULL) {
715 xpt_freeze_devq(sdev->path, 1);
568 sdev = target->luns[lun];
569 if (sdev != NULL && (sdev->flags & VALID_LUN) == 0) {
570 sbp_cam_detach_sdev(sdev);
571 sbp_free_sdev(sdev);
572 target->luns[lun] = NULL;
573 }
574 }
575}

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

708 /* XXX untimeout mgm_ocb and dequeue */
709 for (i=0; i < target->num_lun; i++) {
710 sdev = target->luns[i];
711 if (sdev == NULL)
712 continue;
713 if (alive && (sdev->status != SBP_DEV_DEAD)) {
714 if (sdev->path != NULL) {
715 xpt_freeze_devq(sdev->path, 1);
716 sdev->freeze ++;
716 sdev->freeze++;
717 }
718 sbp_probe_lun(sdev);
719 sbp_show_sdev_info(sdev);
720
721 sbp_abort_all_ocbs(sdev, CAM_SCSI_BUS_RESET);
722 switch (sdev->status) {
723 case SBP_DEV_RESET:
724 /* new or revived target */

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

738 case SBP_DEV_ATTACHED:
739SBP_DEBUG(0)
740 /* the device has gone */
741 device_printf(sbp->fd.dev, "%s: lost target\n",
742 __func__);
743END_DEBUG
744 if (sdev->path) {
745 xpt_freeze_devq(sdev->path, 1);
717 }
718 sbp_probe_lun(sdev);
719 sbp_show_sdev_info(sdev);
720
721 sbp_abort_all_ocbs(sdev, CAM_SCSI_BUS_RESET);
722 switch (sdev->status) {
723 case SBP_DEV_RESET:
724 /* new or revived target */

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

738 case SBP_DEV_ATTACHED:
739SBP_DEBUG(0)
740 /* the device has gone */
741 device_printf(sbp->fd.dev, "%s: lost target\n",
742 __func__);
743END_DEBUG
744 if (sdev->path) {
745 xpt_freeze_devq(sdev->path, 1);
746 sdev->freeze ++;
746 sdev->freeze++;
747 }
748 sdev->status = SBP_DEV_RETRY;
749 sbp_cam_detach_sdev(sdev);
750 sbp_free_sdev(sdev);
751 target->luns[i] = NULL;
752 break;
753 case SBP_DEV_PROBE:
754 case SBP_DEV_TOATTACH:

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

792SBP_DEBUG(0)
793 printf("sbp_post_explore (sbp_cold=%d)\n", sbp_cold);
794END_DEBUG
795 /* We need physical access */
796 if (!firewire_phydma_enable)
797 return;
798
799 if (sbp_cold > 0)
747 }
748 sdev->status = SBP_DEV_RETRY;
749 sbp_cam_detach_sdev(sdev);
750 sbp_free_sdev(sdev);
751 target->luns[i] = NULL;
752 break;
753 case SBP_DEV_PROBE:
754 case SBP_DEV_TOATTACH:

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

792SBP_DEBUG(0)
793 printf("sbp_post_explore (sbp_cold=%d)\n", sbp_cold);
794END_DEBUG
795 /* We need physical access */
796 if (!firewire_phydma_enable)
797 return;
798
799 if (sbp_cold > 0)
800 sbp_cold --;
800 sbp_cold--;
801
802 SBP_LOCK(sbp);
803#if 0
804 /*
805 * XXX don't let CAM the bus rest.
806 * CAM tries to do something with freezed (DEV_RETRY) devices.
807 */
808 xpt_async(AC_BUS_RESET, sbp->path, /*arg*/ NULL);
809#endif
810
811 /* Garbage Collection */
801
802 SBP_LOCK(sbp);
803#if 0
804 /*
805 * XXX don't let CAM the bus rest.
806 * CAM tries to do something with freezed (DEV_RETRY) devices.
807 */
808 xpt_async(AC_BUS_RESET, sbp->path, /*arg*/ NULL);
809#endif
810
811 /* Garbage Collection */
812 for(i = 0 ; i < SBP_NUM_TARGETS ; i ++){
812 for (i = 0; i < SBP_NUM_TARGETS; i++) {
813 target = &sbp->targets[i];
814 STAILQ_FOREACH(fwdev, &sbp->fd.fc->devices, link)
815 if (target->fwdev == NULL || target->fwdev == fwdev)
816 break;
817 if (fwdev == NULL) {
818 /* device has removed in lower driver */
819 sbp_cam_detach_target(target);
820 sbp_free_target(target);
821 }
822 }
823 /* traverse device list */
824 STAILQ_FOREACH(fwdev, &sbp->fd.fc->devices, link) {
825SBP_DEBUG(0)
826 device_printf(sbp->fd.dev,"%s:: EUI:%08x%08x %s attached, state=%d\n",
827 __func__, fwdev->eui.hi, fwdev->eui.lo,
828 (fwdev->status != FWDEVATTACHED) ? "not" : "",
829 fwdev->status);
830END_DEBUG
831 alive = SBP_FWDEV_ALIVE(fwdev);
813 target = &sbp->targets[i];
814 STAILQ_FOREACH(fwdev, &sbp->fd.fc->devices, link)
815 if (target->fwdev == NULL || target->fwdev == fwdev)
816 break;
817 if (fwdev == NULL) {
818 /* device has removed in lower driver */
819 sbp_cam_detach_target(target);
820 sbp_free_target(target);
821 }
822 }
823 /* traverse device list */
824 STAILQ_FOREACH(fwdev, &sbp->fd.fc->devices, link) {
825SBP_DEBUG(0)
826 device_printf(sbp->fd.dev,"%s:: EUI:%08x%08x %s attached, state=%d\n",
827 __func__, fwdev->eui.hi, fwdev->eui.lo,
828 (fwdev->status != FWDEVATTACHED) ? "not" : "",
829 fwdev->status);
830END_DEBUG
831 alive = SBP_FWDEV_ALIVE(fwdev);
832 for(i = 0 ; i < SBP_NUM_TARGETS ; i ++){
832 for (i = 0; i < SBP_NUM_TARGETS; i++) {
833 target = &sbp->targets[i];
833 target = &sbp->targets[i];
834 if(target->fwdev == fwdev ) {
834 if (target->fwdev == fwdev) {
835 /* known target */
836 break;
837 }
838 }
835 /* known target */
836 break;
837 }
838 }
839 if(i == SBP_NUM_TARGETS){
839 if (i == SBP_NUM_TARGETS) {
840 if (alive) {
841 /* new target */
842 target = sbp_alloc_target(sbp, fwdev);
843 if (target == NULL)
844 continue;
845 } else {
846 continue;
847 }

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

852 }
853 xpt_release_simq(sbp->sim, /*run queue*/TRUE);
854 sbp->sim->flags &= ~SIMQ_FREEZED;
855 SBP_UNLOCK(sbp);
856}
857
858#if NEED_RESPONSE
859static void
840 if (alive) {
841 /* new target */
842 target = sbp_alloc_target(sbp, fwdev);
843 if (target == NULL)
844 continue;
845 } else {
846 continue;
847 }

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

852 }
853 xpt_release_simq(sbp->sim, /*run queue*/TRUE);
854 sbp->sim->flags &= ~SIMQ_FREEZED;
855 SBP_UNLOCK(sbp);
856}
857
858#if NEED_RESPONSE
859static void
860sbp_loginres_callback(struct fw_xfer *xfer){
860sbp_loginres_callback(struct fw_xfer *xfer)
861{
861 struct sbp_dev *sdev;
862 sdev = (struct sbp_dev *)xfer->sc;
863SBP_DEBUG(1)
864 device_printf(sdev->target->sbp->fd.dev,"%s\n", __func__);
865END_DEBUG
866 /* recycle */
867 SBP_LOCK(sdev->target->sbp);
868 STAILQ_INSERT_TAIL(&sdev->target->sbp->fwb.xferlist, xfer, link);

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

945sbp_next_dev(struct sbp_target *target, int lun)
946{
947 struct sbp_dev **sdevp;
948 int i;
949
950 for (i = lun, sdevp = &target->luns[lun]; i < target->num_lun;
951 i++, sdevp++)
952 if (*sdevp != NULL && (*sdevp)->status == SBP_DEV_PROBE)
862 struct sbp_dev *sdev;
863 sdev = (struct sbp_dev *)xfer->sc;
864SBP_DEBUG(1)
865 device_printf(sdev->target->sbp->fd.dev,"%s\n", __func__);
866END_DEBUG
867 /* recycle */
868 SBP_LOCK(sdev->target->sbp);
869 STAILQ_INSERT_TAIL(&sdev->target->sbp->fwb.xferlist, xfer, link);

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

946sbp_next_dev(struct sbp_target *target, int lun)
947{
948 struct sbp_dev **sdevp;
949 int i;
950
951 for (i = lun, sdevp = &target->luns[lun]; i < target->num_lun;
952 i++, sdevp++)
953 if (*sdevp != NULL && (*sdevp)->status == SBP_DEV_PROBE)
953 return(*sdevp);
954 return(NULL);
954 return (*sdevp);
955 return (NULL);
955}
956
957#define SCAN_PRI 1
958static void
959sbp_cam_scan_lun(struct cam_periph *periph, union ccb *ccb)
960{
961 struct sbp_target *target;
962 struct sbp_dev *sdev;

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

1142 "%s:%s\n", __func__, sdev->bustgtlun);
1143END_DEBUG
1144 xfer = sbp_write_cmd(sdev, FWTCODE_WREQQ, 0);
1145
1146 xfer->hand = sbp_busy_timeout_callback;
1147 fp = &xfer->send.hdr;
1148 fp->mode.wreqq.dest_hi = 0xffff;
1149 fp->mode.wreqq.dest_lo = 0xf0000000 | BUSY_TIMEOUT;
956}
957
958#define SCAN_PRI 1
959static void
960sbp_cam_scan_lun(struct cam_periph *periph, union ccb *ccb)
961{
962 struct sbp_target *target;
963 struct sbp_dev *sdev;

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

1143 "%s:%s\n", __func__, sdev->bustgtlun);
1144END_DEBUG
1145 xfer = sbp_write_cmd(sdev, FWTCODE_WREQQ, 0);
1146
1147 xfer->hand = sbp_busy_timeout_callback;
1148 fp = &xfer->send.hdr;
1149 fp->mode.wreqq.dest_hi = 0xffff;
1150 fp->mode.wreqq.dest_lo = 0xf0000000 | BUSY_TIMEOUT;
1150 fp->mode.wreqq.data = htonl((1 << (13+12)) | 0xf);
1151 fp->mode.wreqq.data = htonl((1 << (13 + 12)) | 0xf);
1151 fw_asyreq(xfer->fc, -1, xfer);
1152}
1153
1154static void
1155sbp_orb_pointer_callback(struct fw_xfer *xfer)
1156{
1157 struct sbp_dev *sdev;
1158 sdev = (struct sbp_dev *)xfer->sc;

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

1208 xfer = sbp_write_cmd(sdev, FWTCODE_WREQB, 0x08);
1209 if (xfer == NULL)
1210 return;
1211 xfer->hand = sbp_orb_pointer_callback;
1212
1213 fp = &xfer->send.hdr;
1214 fp->mode.wreqb.len = 8;
1215 fp->mode.wreqb.extcode = 0;
1152 fw_asyreq(xfer->fc, -1, xfer);
1153}
1154
1155static void
1156sbp_orb_pointer_callback(struct fw_xfer *xfer)
1157{
1158 struct sbp_dev *sdev;
1159 sdev = (struct sbp_dev *)xfer->sc;

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

1209 xfer = sbp_write_cmd(sdev, FWTCODE_WREQB, 0x08);
1210 if (xfer == NULL)
1211 return;
1212 xfer->hand = sbp_orb_pointer_callback;
1213
1214 fp = &xfer->send.hdr;
1215 fp->mode.wreqb.len = 8;
1216 fp->mode.wreqb.extcode = 0;
1216 xfer->send.payload[0] =
1217 htonl(((sdev->target->sbp->fd.fc->nodeid | FWLOCALBUS )<< 16));
1217 xfer->send.payload[0] =
1218 htonl(((sdev->target->sbp->fd.fc->nodeid | FWLOCALBUS) << 16));
1218 xfer->send.payload[1] = htonl((uint32_t)ocb->bus_addr);
1219
1220 if (fw_asyreq(xfer->fc, -1, xfer) != 0) {
1221 sbp_xfer_free(xfer);
1222 ocb->ccb->ccb_h.status = CAM_REQ_INVALID;
1223 xpt_done(ocb->ccb);
1224 }
1225}

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

1283
1284 SBP_LOCK_ASSERT(sdev->target->sbp);
1285
1286 target = sdev->target;
1287 xfer = STAILQ_FIRST(&target->xferlist);
1288 if (xfer == NULL) {
1289 if (target->n_xfer > 5 /* XXX */) {
1290 printf("sbp: no more xfer for this target\n");
1219 xfer->send.payload[1] = htonl((uint32_t)ocb->bus_addr);
1220
1221 if (fw_asyreq(xfer->fc, -1, xfer) != 0) {
1222 sbp_xfer_free(xfer);
1223 ocb->ccb->ccb_h.status = CAM_REQ_INVALID;
1224 xpt_done(ocb->ccb);
1225 }
1226}

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

1284
1285 SBP_LOCK_ASSERT(sdev->target->sbp);
1286
1287 target = sdev->target;
1288 xfer = STAILQ_FIRST(&target->xferlist);
1289 if (xfer == NULL) {
1290 if (target->n_xfer > 5 /* XXX */) {
1291 printf("sbp: no more xfer for this target\n");
1291 return(NULL);
1292 return (NULL);
1292 }
1293 xfer = fw_xfer_alloc_buf(M_SBP, 8, 0);
1293 }
1294 xfer = fw_xfer_alloc_buf(M_SBP, 8, 0);
1294 if(xfer == NULL){
1295 if (xfer == NULL) {
1295 printf("sbp: fw_xfer_alloc_buf failed\n");
1296 return NULL;
1297 }
1296 printf("sbp: fw_xfer_alloc_buf failed\n");
1297 return NULL;
1298 }
1298 target->n_xfer ++;
1299 target->n_xfer++;
1299 if (debug)
1300 printf("sbp: alloc %d xfer\n", target->n_xfer);
1301 new = 1;
1302 } else {
1303 STAILQ_REMOVE_HEAD(&target->xferlist, link);
1304 }
1305
1306 if (new) {

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

1357 bzero((void *)ocb->orb, sizeof(ocb->orb));
1358 ocb->orb[6] = htonl((nid << 16) | SBP_BIND_HI);
1359 ocb->orb[7] = htonl(SBP_DEV2ADDR(target->target_id, sdev->lun_id));
1360
1361SBP_DEBUG(0)
1362 device_printf(sdev->target->sbp->fd.dev,
1363 "%s:%s %s\n",
1364 __func__,sdev->bustgtlun,
1300 if (debug)
1301 printf("sbp: alloc %d xfer\n", target->n_xfer);
1302 new = 1;
1303 } else {
1304 STAILQ_REMOVE_HEAD(&target->xferlist, link);
1305 }
1306
1307 if (new) {

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

1358 bzero((void *)ocb->orb, sizeof(ocb->orb));
1359 ocb->orb[6] = htonl((nid << 16) | SBP_BIND_HI);
1360 ocb->orb[7] = htonl(SBP_DEV2ADDR(target->target_id, sdev->lun_id));
1361
1362SBP_DEBUG(0)
1363 device_printf(sdev->target->sbp->fd.dev,
1364 "%s:%s %s\n",
1365 __func__,sdev->bustgtlun,
1365 orb_fun_name[(func>>16)&0xf]);
1366 orb_fun_name[(func >> 16) & 0xf]);
1366END_DEBUG
1367 switch (func) {
1368 case ORB_FUN_LGI:
1369 ocb->orb[0] = ocb->orb[1] = 0; /* password */
1370 ocb->orb[2] = htonl(nid << 16);
1371 ocb->orb[3] = htonl(sdev->dma.bus_addr);
1372 ocb->orb[4] = htonl(ORB_NOTIFY | sdev->lun_id);
1373 if (ex_login)

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

1394 return;
1395 }
1396start:
1397 target->mgm_ocb_cur = ocb;
1398
1399 callout_reset(&target->mgm_ocb_timeout, 5*hz,
1400 sbp_mgm_timeout, (caddr_t)ocb);
1401 xfer = sbp_write_cmd(sdev, FWTCODE_WREQB, 0);
1367END_DEBUG
1368 switch (func) {
1369 case ORB_FUN_LGI:
1370 ocb->orb[0] = ocb->orb[1] = 0; /* password */
1371 ocb->orb[2] = htonl(nid << 16);
1372 ocb->orb[3] = htonl(sdev->dma.bus_addr);
1373 ocb->orb[4] = htonl(ORB_NOTIFY | sdev->lun_id);
1374 if (ex_login)

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

1395 return;
1396 }
1397start:
1398 target->mgm_ocb_cur = ocb;
1399
1400 callout_reset(&target->mgm_ocb_timeout, 5*hz,
1401 sbp_mgm_timeout, (caddr_t)ocb);
1402 xfer = sbp_write_cmd(sdev, FWTCODE_WREQB, 0);
1402 if(xfer == NULL){
1403 if (xfer == NULL) {
1403 return;
1404 }
1405 xfer->hand = sbp_mgm_callback;
1406
1407 fp = &xfer->send.hdr;
1408 fp->mode.wreqb.dest_hi = sdev->target->mgm_hi;
1409 fp->mode.wreqb.dest_lo = sdev->target->mgm_lo;
1410 fp->mode.wreqb.len = 8;

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

1465 sbp_cmd_status->s_qlfr,
1466 sbp_status->len);
1467END_DEBUG
1468
1469 switch (sbp_cmd_status->status) {
1470 case SCSI_STATUS_CHECK_COND:
1471 case SCSI_STATUS_BUSY:
1472 case SCSI_STATUS_CMD_TERMINATED:
1404 return;
1405 }
1406 xfer->hand = sbp_mgm_callback;
1407
1408 fp = &xfer->send.hdr;
1409 fp->mode.wreqb.dest_hi = sdev->target->mgm_hi;
1410 fp->mode.wreqb.dest_lo = sdev->target->mgm_lo;
1411 fp->mode.wreqb.len = 8;

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

1466 sbp_cmd_status->s_qlfr,
1467 sbp_status->len);
1468END_DEBUG
1469
1470 switch (sbp_cmd_status->status) {
1471 case SCSI_STATUS_CHECK_COND:
1472 case SCSI_STATUS_BUSY:
1473 case SCSI_STATUS_CMD_TERMINATED:
1473 if(sbp_cmd_status->sfmt == SBP_SFMT_CURR){
1474 if (sbp_cmd_status->sfmt == SBP_SFMT_CURR) {
1474 sense->error_code = SSD_CURRENT_ERROR;
1475 sense->error_code = SSD_CURRENT_ERROR;
1475 }else{
1476 } else {
1476 sense->error_code = SSD_DEFERRED_ERROR;
1477 }
1477 sense->error_code = SSD_DEFERRED_ERROR;
1478 }
1478 if(sbp_cmd_status->valid)
1479 if (sbp_cmd_status->valid)
1479 sense->error_code |= SSD_ERRCODE_VALID;
1480 sense->flags = sbp_cmd_status->s_key;
1480 sense->error_code |= SSD_ERRCODE_VALID;
1481 sense->flags = sbp_cmd_status->s_key;
1481 if(sbp_cmd_status->mark)
1482 if (sbp_cmd_status->mark)
1482 sense->flags |= SSD_FILEMARK;
1483 sense->flags |= SSD_FILEMARK;
1483 if(sbp_cmd_status->eom)
1484 if (sbp_cmd_status->eom)
1484 sense->flags |= SSD_EOM;
1485 sense->flags |= SSD_EOM;
1485 if(sbp_cmd_status->ill_len)
1486 if (sbp_cmd_status->ill_len)
1486 sense->flags |= SSD_ILI;
1487
1488 bcopy(&sbp_cmd_status->info, &sense->info[0], 4);
1489
1490 if (sbp_status->len <= 1)
1487 sense->flags |= SSD_ILI;
1488
1489 bcopy(&sbp_cmd_status->info, &sense->info[0], 4);
1490
1491 if (sbp_status->len <= 1)
1491 /* XXX not scsi status. shouldn't be happened */
1492 /* XXX not scsi status. shouldn't be happened */
1492 sense->extra_len = 0;
1493 else if (sbp_status->len <= 4)
1494 /* add_sense_code(_qual), info, cmd_spec_info */
1495 sense->extra_len = 6;
1496 else
1497 /* fru, sense_key_spec */
1498 sense->extra_len = 10;
1499

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

1508
1509 ocb->ccb->csio.scsi_status = sbp_cmd_status->status;
1510 ocb->ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR
1511 | CAM_AUTOSNS_VALID;
1512/*
1513{
1514 uint8_t j, *tmp;
1515 tmp = sense;
1493 sense->extra_len = 0;
1494 else if (sbp_status->len <= 4)
1495 /* add_sense_code(_qual), info, cmd_spec_info */
1496 sense->extra_len = 6;
1497 else
1498 /* fru, sense_key_spec */
1499 sense->extra_len = 10;
1500

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

1509
1510 ocb->ccb->csio.scsi_status = sbp_cmd_status->status;
1511 ocb->ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR
1512 | CAM_AUTOSNS_VALID;
1513/*
1514{
1515 uint8_t j, *tmp;
1516 tmp = sense;
1516 for( j = 0 ; j < 32 ; j+=8){
1517 printf("sense %02x%02x %02x%02x %02x%02x %02x%02x\n",
1518 tmp[j], tmp[j+1], tmp[j+2], tmp[j+3],
1519 tmp[j+4], tmp[j+5], tmp[j+6], tmp[j+7]);
1517 for (j = 0; j < 32; j += 8) {
1518 printf("sense %02x%02x %02x%02x %02x%02x %02x%02x\n",
1519 tmp[j], tmp[j + 1], tmp[j + 2], tmp[j + 3],
1520 tmp[j + 4], tmp[j + 5], tmp[j + 6], tmp[j + 7]);
1520 }
1521
1522}
1523*/
1524 break;
1525 default:
1526 device_printf(ocb->sdev->target->sbp->fd.dev,
1527 "%s:%s unknown scsi status 0x%x\n",

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

1545SBP_DEBUG(1)
1546 device_printf(sdev->target->sbp->fd.dev,
1547 "%s:%s\n", __func__, sdev->bustgtlun);
1548END_DEBUG
1549 inq = (struct scsi_inquiry_data *) ccb->csio.data_ptr;
1550 switch (SID_TYPE(inq)) {
1551 case T_DIRECT:
1552#if 0
1521 }
1522
1523}
1524*/
1525 break;
1526 default:
1527 device_printf(ocb->sdev->target->sbp->fd.dev,
1528 "%s:%s unknown scsi status 0x%x\n",

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

1546SBP_DEBUG(1)
1547 device_printf(sdev->target->sbp->fd.dev,
1548 "%s:%s\n", __func__, sdev->bustgtlun);
1549END_DEBUG
1550 inq = (struct scsi_inquiry_data *) ccb->csio.data_ptr;
1551 switch (SID_TYPE(inq)) {
1552 case T_DIRECT:
1553#if 0
1553 /*
1554 /*
1554 * XXX Convert Direct Access device to RBC.
1555 * I've never seen FireWire DA devices which support READ_6.
1556 */
1557 if (SID_TYPE(inq) == T_DIRECT)
1558 inq->device |= T_RBC; /* T_DIRECT == 0 */
1559#endif
1560 /* fall through */
1561 case T_RBC:
1562 /*
1563 * Override vendor/product/revision information.
1564 * Some devices sometimes return strange strings.
1565 */
1566#if 1
1567 bcopy(sdev->vendor, inq->vendor, sizeof(inq->vendor));
1568 bcopy(sdev->product, inq->product, sizeof(inq->product));
1555 * XXX Convert Direct Access device to RBC.
1556 * I've never seen FireWire DA devices which support READ_6.
1557 */
1558 if (SID_TYPE(inq) == T_DIRECT)
1559 inq->device |= T_RBC; /* T_DIRECT == 0 */
1560#endif
1561 /* fall through */
1562 case T_RBC:
1563 /*
1564 * Override vendor/product/revision information.
1565 * Some devices sometimes return strange strings.
1566 */
1567#if 1
1568 bcopy(sdev->vendor, inq->vendor, sizeof(inq->vendor));
1569 bcopy(sdev->product, inq->product, sizeof(inq->product));
1569 bcopy(sdev->revision+2, inq->revision, sizeof(inq->revision));
1570 bcopy(sdev->revision + 2, inq->revision, sizeof(inq->revision));
1570#endif
1571 break;
1572 }
1573 /*
1574 * Force to enable/disable tagged queuing.
1575 * XXX CAM also checks SCP_QUEUE_DQUE flag in the control mode page.
1576 */
1577 if (sbp_tags > 0)

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

1601 ld = xfer->recv.buf;
1602printf("sbp %x %d %d %08x %08x %08x %08x\n",
1603 xfer->resp, xfer->recv.len, xfer->recv.off, ntohl(ld[0]), ntohl(ld[1]), ntohl(ld[2]), ntohl(ld[3]));
1604printf("sbp %08x %08x %08x %08x\n", ntohl(ld[4]), ntohl(ld[5]), ntohl(ld[6]), ntohl(ld[7]));
1605printf("sbp %08x %08x %08x %08x\n", ntohl(ld[8]), ntohl(ld[9]), ntohl(ld[10]), ntohl(ld[11]));
1606*/
1607 sbp = (struct sbp_softc *)xfer->sc;
1608 SBP_LOCK_ASSERT(sbp);
1571#endif
1572 break;
1573 }
1574 /*
1575 * Force to enable/disable tagged queuing.
1576 * XXX CAM also checks SCP_QUEUE_DQUE flag in the control mode page.
1577 */
1578 if (sbp_tags > 0)

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

1602 ld = xfer->recv.buf;
1603printf("sbp %x %d %d %08x %08x %08x %08x\n",
1604 xfer->resp, xfer->recv.len, xfer->recv.off, ntohl(ld[0]), ntohl(ld[1]), ntohl(ld[2]), ntohl(ld[3]));
1605printf("sbp %08x %08x %08x %08x\n", ntohl(ld[4]), ntohl(ld[5]), ntohl(ld[6]), ntohl(ld[7]));
1606printf("sbp %08x %08x %08x %08x\n", ntohl(ld[8]), ntohl(ld[9]), ntohl(ld[10]), ntohl(ld[11]));
1607*/
1608 sbp = (struct sbp_softc *)xfer->sc;
1609 SBP_LOCK_ASSERT(sbp);
1609 if (xfer->resp != 0){
1610 if (xfer->resp != 0) {
1610 printf("sbp_recv: xfer->resp = %d\n", xfer->resp);
1611 goto done0;
1612 }
1611 printf("sbp_recv: xfer->resp = %d\n", xfer->resp);
1612 goto done0;
1613 }
1613 if (xfer->recv.payload == NULL){
1614 if (xfer->recv.payload == NULL) {
1614 printf("sbp_recv: xfer->recv.payload == NULL\n");
1615 goto done0;
1616 }
1617 rfp = &xfer->recv.hdr;
1615 printf("sbp_recv: xfer->recv.payload == NULL\n");
1616 goto done0;
1617 }
1618 rfp = &xfer->recv.hdr;
1618 if(rfp->mode.wreqb.tcode != FWTCODE_WREQB){
1619 if (rfp->mode.wreqb.tcode != FWTCODE_WREQB) {
1619 printf("sbp_recv: tcode = %d\n", rfp->mode.wreqb.tcode);
1620 goto done0;
1621 }
1622 sbp_status = (struct sbp_status *)xfer->recv.payload;
1623 addr = rfp->mode.wreqb.dest_lo;
1624SBP_DEBUG(2)
1625 printf("received address 0x%x\n", addr);
1626END_DEBUG

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

1672 __func__, sdev->bustgtlun);
1673 }
1674
1675 status_valid0 = (sbp_status->src < 2
1676 && sbp_status->resp == ORB_RES_CMPL
1677 && sbp_status->dead == 0);
1678 status_valid = (status_valid0 && sbp_status->status == 0);
1679
1620 printf("sbp_recv: tcode = %d\n", rfp->mode.wreqb.tcode);
1621 goto done0;
1622 }
1623 sbp_status = (struct sbp_status *)xfer->recv.payload;
1624 addr = rfp->mode.wreqb.dest_lo;
1625SBP_DEBUG(2)
1626 printf("received address 0x%x\n", addr);
1627END_DEBUG

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

1673 __func__, sdev->bustgtlun);
1674 }
1675
1676 status_valid0 = (sbp_status->src < 2
1677 && sbp_status->resp == ORB_RES_CMPL
1678 && sbp_status->dead == 0);
1679 status_valid = (status_valid0 && sbp_status->status == 0);
1680
1680 if (!status_valid0 || debug > 2){
1681 if (!status_valid0 || debug > 2) {
1681 int status;
1682SBP_DEBUG(0)
1683 device_printf(sdev->target->sbp->fd.dev,
1684 "%s:%s ORB status src:%x resp:%x dead:%x"
1685 " len:%x stat:%x orb:%x%08x\n",
1686 __func__, sdev->bustgtlun,
1687 sbp_status->src, sbp_status->resp, sbp_status->dead,
1688 sbp_status->len, sbp_status->status,
1689 ntohs(sbp_status->orb_hi), ntohl(sbp_status->orb_lo));
1690END_DEBUG
1691 device_printf(sdev->target->sbp->fd.dev,
1692 "%s\n", sdev->bustgtlun);
1693 status = sbp_status->status;
1682 int status;
1683SBP_DEBUG(0)
1684 device_printf(sdev->target->sbp->fd.dev,
1685 "%s:%s ORB status src:%x resp:%x dead:%x"
1686 " len:%x stat:%x orb:%x%08x\n",
1687 __func__, sdev->bustgtlun,
1688 sbp_status->src, sbp_status->resp, sbp_status->dead,
1689 sbp_status->len, sbp_status->status,
1690 ntohs(sbp_status->orb_hi), ntohl(sbp_status->orb_lo));
1691END_DEBUG
1692 device_printf(sdev->target->sbp->fd.dev,
1693 "%s\n", sdev->bustgtlun);
1694 status = sbp_status->status;
1694 switch(sbp_status->resp) {
1695 switch (sbp_status->resp) {
1695 case 0:
1696 if (status > MAX_ORB_STATUS0)
1697 printf("%s\n", orb_status0[MAX_ORB_STATUS0]);
1698 else
1699 printf("%s\n", orb_status0[status]);
1700 break;
1701 case 1:
1702 printf("Obj: %s, Error: %s\n",
1696 case 0:
1697 if (status > MAX_ORB_STATUS0)
1698 printf("%s\n", orb_status0[MAX_ORB_STATUS0]);
1699 else
1700 printf("%s\n", orb_status0[status]);
1701 break;
1702 case 1:
1703 printf("Obj: %s, Error: %s\n",
1703 orb_status1_object[(status>>6) & 3],
1704 orb_status1_object[(status >> 6) & 3],
1704 orb_status1_serial_bus_error[status & 0xf]);
1705 break;
1706 case 2:
1707 printf("Illegal request\n");
1708 break;
1709 case 3:
1710 printf("Vendor dependent\n");
1711 break;
1712 default:
1713 printf("unknown respose code %d\n", sbp_status->resp);
1714 }
1715 }
1716
1717 /* we have to reset the fetch agent if it's dead */
1718 if (sbp_status->dead) {
1719 if (sdev->path) {
1720 xpt_freeze_devq(sdev->path, 1);
1705 orb_status1_serial_bus_error[status & 0xf]);
1706 break;
1707 case 2:
1708 printf("Illegal request\n");
1709 break;
1710 case 3:
1711 printf("Vendor dependent\n");
1712 break;
1713 default:
1714 printf("unknown respose code %d\n", sbp_status->resp);
1715 }
1716 }
1717
1718 /* we have to reset the fetch agent if it's dead */
1719 if (sbp_status->dead) {
1720 if (sdev->path) {
1721 xpt_freeze_devq(sdev->path, 1);
1721 sdev->freeze ++;
1722 sdev->freeze++;
1722 }
1723 reset_agent = 1;
1724 }
1725
1726 if (ocb == NULL)
1727 goto done;
1728
1723 }
1724 reset_agent = 1;
1725 }
1726
1727 if (ocb == NULL)
1728 goto done;
1729
1729 switch(ntohl(ocb->orb[4]) & ORB_FMT_MSK){
1730 switch (ntohl(ocb->orb[4]) & ORB_FMT_MSK) {
1730 case ORB_FMT_NOP:
1731 break;
1732 case ORB_FMT_VED:
1733 break;
1734 case ORB_FMT_STD:
1731 case ORB_FMT_NOP:
1732 break;
1733 case ORB_FMT_VED:
1734 break;
1735 case ORB_FMT_STD:
1735 switch(ocb->flags) {
1736 switch (ocb->flags) {
1736 case OCB_ACT_MGM:
1737 orb_fun = ntohl(ocb->orb[4]) & ORB_FUN_MSK;
1738 reset_agent = 0;
1737 case OCB_ACT_MGM:
1738 orb_fun = ntohl(ocb->orb[4]) & ORB_FUN_MSK;
1739 reset_agent = 0;
1739 switch(orb_fun) {
1740 switch (orb_fun) {
1740 case ORB_FUN_LGI:
1741 fwdma_sync(&sdev->dma, BUS_DMASYNC_POSTREAD);
1742 login_res = sdev->login;
1743 login_res->len = ntohs(login_res->len);
1744 login_res->id = ntohs(login_res->id);
1745 login_res->cmd_hi = ntohs(login_res->cmd_hi);
1746 login_res->cmd_lo = ntohl(login_res->cmd_lo);
1747 if (status_valid) {

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

1802 "%s:%s unknown function %d\n",
1803 __func__, sdev->bustgtlun, orb_fun);
1804 break;
1805 }
1806 sbp_mgm_orb(sdev, ORB_FUN_RUNQUEUE, NULL);
1807 break;
1808 case OCB_ACT_CMD:
1809 sdev->timeout = 0;
1741 case ORB_FUN_LGI:
1742 fwdma_sync(&sdev->dma, BUS_DMASYNC_POSTREAD);
1743 login_res = sdev->login;
1744 login_res->len = ntohs(login_res->len);
1745 login_res->id = ntohs(login_res->id);
1746 login_res->cmd_hi = ntohs(login_res->cmd_hi);
1747 login_res->cmd_lo = ntohl(login_res->cmd_lo);
1748 if (status_valid) {

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

1803 "%s:%s unknown function %d\n",
1804 __func__, sdev->bustgtlun, orb_fun);
1805 break;
1806 }
1807 sbp_mgm_orb(sdev, ORB_FUN_RUNQUEUE, NULL);
1808 break;
1809 case OCB_ACT_CMD:
1810 sdev->timeout = 0;
1810 if(ocb->ccb != NULL){
1811 if (ocb->ccb != NULL) {
1811 union ccb *ccb;
1812
1813 ccb = ocb->ccb;
1812 union ccb *ccb;
1813
1814 ccb = ocb->ccb;
1814 if(sbp_status->len > 1){
1815 if (sbp_status->len > 1) {
1815 sbp_scsi_status(sbp_status, ocb);
1816 sbp_scsi_status(sbp_status, ocb);
1816 }else{
1817 if(sbp_status->resp != ORB_RES_CMPL){
1817 } else {
1818 if (sbp_status->resp != ORB_RES_CMPL) {
1818 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1819 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1819 }else{
1820 } else {
1820 ccb->ccb_h.status = CAM_REQ_CMP;
1821 }
1822 }
1823 /* fix up inq data */
1824 if (ccb->csio.cdb_io.cdb_bytes[0] == INQUIRY)
1825 sbp_fix_inq_data(ocb);
1826 xpt_done(ccb);
1827 }

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

1838 sbp_agent_reset(sdev);
1839
1840done0:
1841 xfer->recv.pay_len = SBP_RECV_LEN;
1842/* The received packet is usually small enough to be stored within
1843 * the buffer. In that case, the controller return ack_complete and
1844 * no respose is necessary.
1845 *
1821 ccb->ccb_h.status = CAM_REQ_CMP;
1822 }
1823 }
1824 /* fix up inq data */
1825 if (ccb->csio.cdb_io.cdb_bytes[0] == INQUIRY)
1826 sbp_fix_inq_data(ocb);
1827 xpt_done(ccb);
1828 }

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

1839 sbp_agent_reset(sdev);
1840
1841done0:
1842 xfer->recv.pay_len = SBP_RECV_LEN;
1843/* The received packet is usually small enough to be stored within
1844 * the buffer. In that case, the controller return ack_complete and
1845 * no respose is necessary.
1846 *
1846 * XXX fwohci.c and firewire.c should inform event_code such as
1847 * XXX fwohci.c and firewire.c should inform event_code such as
1847 * ack_complete or ack_pending to upper driver.
1848 */
1849#if NEED_RESPONSE
1850 xfer->send.off = 0;
1851 sfp = (struct fw_pkt *)xfer->send.buf;
1852 sfp->mode.wres.dst = rfp->mode.wreqb.src;
1853 xfer->dst = sfp->mode.wres.dst;
1854 xfer->spd = min(sdev->target->fwdev->speed, max_speed);

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

1895 if (!firewire_phydma_enable)
1896 device_printf(dev, "Warning, hw.firewire.phydma_enable must be 1 "
1897 "for SBP over FireWire.\n");
1898SBP_DEBUG(0)
1899 printf("sbp_attach (cold=%d)\n", cold);
1900END_DEBUG
1901
1902 if (cold)
1848 * ack_complete or ack_pending to upper driver.
1849 */
1850#if NEED_RESPONSE
1851 xfer->send.off = 0;
1852 sfp = (struct fw_pkt *)xfer->send.buf;
1853 sfp->mode.wres.dst = rfp->mode.wreqb.src;
1854 xfer->dst = sfp->mode.wres.dst;
1855 xfer->spd = min(sdev->target->fwdev->speed, max_speed);

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

1896 if (!firewire_phydma_enable)
1897 device_printf(dev, "Warning, hw.firewire.phydma_enable must be 1 "
1898 "for SBP over FireWire.\n");
1899SBP_DEBUG(0)
1900 printf("sbp_attach (cold=%d)\n", cold);
1901END_DEBUG
1902
1903 if (cold)
1903 sbp_cold ++;
1904 sbp_cold++;
1904 sbp = device_get_softc(dev);
1905 sbp->fd.dev = dev;
1906 sbp->fd.fc = fc = device_get_ivars(dev);
1907 mtx_init(&sbp->mtx, "sbp", NULL, MTX_DEF);
1908
1909 if (max_speed < 0)
1910 max_speed = fc->speed;
1911

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

1927 "- error %d\n", error);
1928 return (ENOMEM);
1929 }
1930
1931 devq = cam_simq_alloc(/*maxopenings*/SBP_NUM_OCB);
1932 if (devq == NULL)
1933 return (ENXIO);
1934
1905 sbp = device_get_softc(dev);
1906 sbp->fd.dev = dev;
1907 sbp->fd.fc = fc = device_get_ivars(dev);
1908 mtx_init(&sbp->mtx, "sbp", NULL, MTX_DEF);
1909
1910 if (max_speed < 0)
1911 max_speed = fc->speed;
1912

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

1928 "- error %d\n", error);
1929 return (ENOMEM);
1930 }
1931
1932 devq = cam_simq_alloc(/*maxopenings*/SBP_NUM_OCB);
1933 if (devq == NULL)
1934 return (ENXIO);
1935
1935 for( i = 0 ; i < SBP_NUM_TARGETS ; i++){
1936 for (i = 0; i < SBP_NUM_TARGETS; i++) {
1936 sbp->targets[i].fwdev = NULL;
1937 sbp->targets[i].luns = NULL;
1938 sbp->targets[i].sbp = sbp;
1939 }
1940
1941 sbp->sim = cam_sim_alloc(sbp_action, sbp_poll, "sbp", sbp,
1942 device_get_unit(dev),
1943 &sbp->mtx,

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

1996 struct sbp_target *target;
1997 struct sbp_dev *sdev;
1998 int i, j;
1999
2000SBP_DEBUG(0)
2001 printf("sbp_logout_all\n");
2002END_DEBUG
2003 SBP_LOCK_ASSERT(sbp);
1937 sbp->targets[i].fwdev = NULL;
1938 sbp->targets[i].luns = NULL;
1939 sbp->targets[i].sbp = sbp;
1940 }
1941
1942 sbp->sim = cam_sim_alloc(sbp_action, sbp_poll, "sbp", sbp,
1943 device_get_unit(dev),
1944 &sbp->mtx,

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

1997 struct sbp_target *target;
1998 struct sbp_dev *sdev;
1999 int i, j;
2000
2001SBP_DEBUG(0)
2002 printf("sbp_logout_all\n");
2003END_DEBUG
2004 SBP_LOCK_ASSERT(sbp);
2004 for (i = 0 ; i < SBP_NUM_TARGETS ; i ++) {
2005 for (i = 0; i < SBP_NUM_TARGETS; i++) {
2005 target = &sbp->targets[i];
2006 if (target->luns == NULL)
2007 continue;
2008 for (j = 0; j < target->num_lun; j++) {
2009 sdev = target->luns[j];
2010 if (sdev == NULL)
2011 continue;
2012 callout_stop(&sdev->login_callout);

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

2085 struct firewire_comm *fc = sbp->fd.fc;
2086 int i;
2087
2088SBP_DEBUG(0)
2089 printf("sbp_detach\n");
2090END_DEBUG
2091
2092 SBP_LOCK(sbp);
2006 target = &sbp->targets[i];
2007 if (target->luns == NULL)
2008 continue;
2009 for (j = 0; j < target->num_lun; j++) {
2010 sdev = target->luns[j];
2011 if (sdev == NULL)
2012 continue;
2013 callout_stop(&sdev->login_callout);

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

2086 struct firewire_comm *fc = sbp->fd.fc;
2087 int i;
2088
2089SBP_DEBUG(0)
2090 printf("sbp_detach\n");
2091END_DEBUG
2092
2093 SBP_LOCK(sbp);
2093 for (i = 0; i < SBP_NUM_TARGETS; i ++)
2094 for (i = 0; i < SBP_NUM_TARGETS; i++)
2094 sbp_cam_detach_target(&sbp->targets[i]);
2095
2096 xpt_async(AC_LOST_DEVICE, sbp->path, NULL);
2097 xpt_free_path(sbp->path);
2098 xpt_bus_deregister(cam_sim_path(sbp->sim));
2099 cam_sim_free(sbp->sim, /*free_devq*/ TRUE);
2100
2101 sbp_logout_all(sbp);
2102 SBP_UNLOCK(sbp);
2103
2104 /* XXX wait for logout completion */
2105 pause("sbpdtc", hz/2);
2106
2107 SBP_LOCK(sbp);
2095 sbp_cam_detach_target(&sbp->targets[i]);
2096
2097 xpt_async(AC_LOST_DEVICE, sbp->path, NULL);
2098 xpt_free_path(sbp->path);
2099 xpt_bus_deregister(cam_sim_path(sbp->sim));
2100 cam_sim_free(sbp->sim, /*free_devq*/ TRUE);
2101
2102 sbp_logout_all(sbp);
2103 SBP_UNLOCK(sbp);
2104
2105 /* XXX wait for logout completion */
2106 pause("sbpdtc", hz/2);
2107
2108 SBP_LOCK(sbp);
2108 for (i = 0 ; i < SBP_NUM_TARGETS ; i ++)
2109 for (i = 0; i < SBP_NUM_TARGETS; i++)
2109 sbp_free_target(&sbp->targets[i]);
2110 SBP_UNLOCK(sbp);
2111
2112 fw_bindremove(fc, &sbp->fwb);
2113 fw_xferlist_remove(&sbp->fwb.xferlist);
2114
2115 bus_dma_tag_destroy(sbp->dmat);
2116 mtx_destroy(&sbp->mtx);

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

2167 tsdev = target->luns[i];
2168 if (tsdev == NULL)
2169 continue;
2170 if (tsdev->status == SBP_DEV_DEAD)
2171 continue;
2172 if (tsdev->status == SBP_DEV_RESET)
2173 continue;
2174 xpt_freeze_devq(tsdev->path, 1);
2110 sbp_free_target(&sbp->targets[i]);
2111 SBP_UNLOCK(sbp);
2112
2113 fw_bindremove(fc, &sbp->fwb);
2114 fw_xferlist_remove(&sbp->fwb.xferlist);
2115
2116 bus_dma_tag_destroy(sbp->dmat);
2117 mtx_destroy(&sbp->mtx);

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

2168 tsdev = target->luns[i];
2169 if (tsdev == NULL)
2170 continue;
2171 if (tsdev->status == SBP_DEV_DEAD)
2172 continue;
2173 if (tsdev->status == SBP_DEV_RESET)
2174 continue;
2175 xpt_freeze_devq(tsdev->path, 1);
2175 tsdev->freeze ++;
2176 tsdev->freeze++;
2176 sbp_abort_all_ocbs(tsdev, CAM_CMD_TIMEOUT);
2177 if (method == 2)
2178 tsdev->status = SBP_DEV_LOGIN;
2179 }
2177 sbp_abort_all_ocbs(tsdev, CAM_CMD_TIMEOUT);
2178 if (method == 2)
2179 tsdev->status = SBP_DEV_LOGIN;
2180 }
2180 switch(method) {
2181 switch (method) {
2181 case 1:
2182 printf("target reset\n");
2183 sbp_mgm_orb(sdev, ORB_FUN_RST, NULL);
2184 break;
2185 case 2:
2186 printf("reset start\n");
2187 sbp_reset_start(sdev);
2188 break;
2189 }
2182 case 1:
2183 printf("target reset\n");
2184 sbp_mgm_orb(sdev, ORB_FUN_RST, NULL);
2185 break;
2186 case 2:
2187 printf("reset start\n");
2188 sbp_reset_start(sdev);
2189 break;
2190 }
2190
2191
2191}
2192
2193static void
2194sbp_mgm_timeout(void *arg)
2195{
2196 struct sbp_ocb *ocb = (struct sbp_ocb *)arg;
2197 struct sbp_dev *sdev = ocb->sdev;
2198 struct sbp_target *target = sdev->target;

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

2220 struct sbp_ocb *ocb = (struct sbp_ocb *)arg;
2221 struct sbp_dev *sdev = ocb->sdev;
2222
2223 device_printf(sdev->target->sbp->fd.dev,
2224 "%s:%s request timeout(cmd orb:0x%08x) ... ",
2225 __func__, sdev->bustgtlun, (uint32_t)ocb->bus_addr);
2226
2227 SBP_LOCK_ASSERT(sdev->target->sbp);
2192}
2193
2194static void
2195sbp_mgm_timeout(void *arg)
2196{
2197 struct sbp_ocb *ocb = (struct sbp_ocb *)arg;
2198 struct sbp_dev *sdev = ocb->sdev;
2199 struct sbp_target *target = sdev->target;

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

2221 struct sbp_ocb *ocb = (struct sbp_ocb *)arg;
2222 struct sbp_dev *sdev = ocb->sdev;
2223
2224 device_printf(sdev->target->sbp->fd.dev,
2225 "%s:%s request timeout(cmd orb:0x%08x) ... ",
2226 __func__, sdev->bustgtlun, (uint32_t)ocb->bus_addr);
2227
2228 SBP_LOCK_ASSERT(sdev->target->sbp);
2228 sdev->timeout ++;
2229 switch(sdev->timeout) {
2229 sdev->timeout++;
2230 switch (sdev->timeout) {
2230 case 1:
2231 printf("agent reset\n");
2232 xpt_freeze_devq(sdev->path, 1);
2231 case 1:
2232 printf("agent reset\n");
2233 xpt_freeze_devq(sdev->path, 1);
2233 sdev->freeze ++;
2234 sdev->freeze++;
2234 sbp_abort_all_ocbs(sdev, CAM_CMD_TIMEOUT);
2235 sbp_agent_reset(sdev);
2236 break;
2237 case 2:
2238 case 3:
2239 sbp_target_reset(sdev, sdev->timeout - 1);
2240 break;
2241#if 0

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

2304 }
2305 break;
2306 case XPT_PATH_INQ:
2307 case XPT_NOOP:
2308 /* The opcodes sometimes aimed at a target (sc is valid),
2309 * sometimes aimed at the SIM (sc is invalid and target is
2310 * CAM_TARGET_WILDCARD)
2311 */
2235 sbp_abort_all_ocbs(sdev, CAM_CMD_TIMEOUT);
2236 sbp_agent_reset(sdev);
2237 break;
2238 case 2:
2239 case 3:
2240 sbp_target_reset(sdev, sdev->timeout - 1);
2241 break;
2242#if 0

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

2305 }
2306 break;
2307 case XPT_PATH_INQ:
2308 case XPT_NOOP:
2309 /* The opcodes sometimes aimed at a target (sc is valid),
2310 * sometimes aimed at the SIM (sc is invalid and target is
2311 * CAM_TARGET_WILDCARD)
2312 */
2312 if (sbp == NULL &&
2313 if (sbp == NULL &&
2313 ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) {
2314SBP_DEBUG(0)
2315 printf("%s:%d:%jx func_code 0x%04x: "
2316 "Invalid target (no wildcard)\n",
2317 device_get_nameunit(sbp->fd.dev),
2318 ccb->ccb_h.target_id,
2319 (uintmax_t)ccb->ccb_h.target_lun,
2320 ccb->ccb_h.func_code);

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

2356 csio->cdb_io.cdb_bytes[6],
2357 csio->cdb_io.cdb_bytes[7],
2358 csio->cdb_io.cdb_bytes[8],
2359 csio->cdb_io.cdb_bytes[9],
2360 ccb->ccb_h.flags & CAM_DIR_MASK,
2361 csio->cdb_len, csio->dxfer_len,
2362 csio->sense_len);
2363END_DEBUG
2314 ccb->ccb_h.target_id != CAM_TARGET_WILDCARD) {
2315SBP_DEBUG(0)
2316 printf("%s:%d:%jx func_code 0x%04x: "
2317 "Invalid target (no wildcard)\n",
2318 device_get_nameunit(sbp->fd.dev),
2319 ccb->ccb_h.target_id,
2320 (uintmax_t)ccb->ccb_h.target_lun,
2321 ccb->ccb_h.func_code);

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

2357 csio->cdb_io.cdb_bytes[6],
2358 csio->cdb_io.cdb_bytes[7],
2359 csio->cdb_io.cdb_bytes[8],
2360 csio->cdb_io.cdb_bytes[9],
2361 ccb->ccb_h.flags & CAM_DIR_MASK,
2362 csio->cdb_len, csio->dxfer_len,
2363 csio->sense_len);
2364END_DEBUG
2364 if(sdev == NULL){
2365 if (sdev == NULL) {
2365 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
2366 xpt_done(ccb);
2367 return;
2368 }
2369#if 0
2370 /* if we are in probe stage, pass only probe commands */
2371 if (sdev->status == SBP_DEV_PROBE) {
2372 char *name;

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

2378 return;
2379 }
2380 }
2381#endif
2382 if ((ocb = sbp_get_ocb(sdev)) == NULL) {
2383 ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
2384 if (sdev->freeze == 0) {
2385 xpt_freeze_devq(sdev->path, 1);
2366 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
2367 xpt_done(ccb);
2368 return;
2369 }
2370#if 0
2371 /* if we are in probe stage, pass only probe commands */
2372 if (sdev->status == SBP_DEV_PROBE) {
2373 char *name;

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

2379 return;
2380 }
2381 }
2382#endif
2383 if ((ocb = sbp_get_ocb(sdev)) == NULL) {
2384 ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
2385 if (sdev->freeze == 0) {
2386 xpt_freeze_devq(sdev->path, 1);
2386 sdev->freeze ++;
2387 sdev->freeze++;
2387 }
2388 xpt_done(ccb);
2389 return;
2390 }
2391
2392 ocb->flags = OCB_ACT_CMD;
2393 ocb->sdev = sdev;
2394 ocb->ccb = ccb;
2395 ccb->ccb_h.ccb_sdev_ptr = sdev;
2396 ocb->orb[0] = htonl(1U << 31);
2397 ocb->orb[1] = 0;
2388 }
2389 xpt_done(ccb);
2390 return;
2391 }
2392
2393 ocb->flags = OCB_ACT_CMD;
2394 ocb->sdev = sdev;
2395 ocb->ccb = ccb;
2396 ccb->ccb_h.ccb_sdev_ptr = sdev;
2397 ocb->orb[0] = htonl(1U << 31);
2398 ocb->orb[1] = 0;
2398 ocb->orb[2] = htonl(((sbp->fd.fc->nodeid | FWLOCALBUS )<< 16) );
2399 ocb->orb[2] = htonl(((sbp->fd.fc->nodeid | FWLOCALBUS) << 16));
2399 ocb->orb[3] = htonl(ocb->bus_addr + IND_PTR_OFFSET);
2400 speed = min(target->fwdev->speed, max_speed);
2401 ocb->orb[4] = htonl(ORB_NOTIFY | ORB_CMD_SPD(speed)
2402 | ORB_CMD_MAXP(speed + 7));
2400 ocb->orb[3] = htonl(ocb->bus_addr + IND_PTR_OFFSET);
2401 speed = min(target->fwdev->speed, max_speed);
2402 ocb->orb[4] = htonl(ORB_NOTIFY | ORB_CMD_SPD(speed)
2403 | ORB_CMD_MAXP(speed + 7));
2403 if((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN){
2404 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) {
2404 ocb->orb[4] |= htonl(ORB_CMD_IN);
2405 }
2406
2407 if (csio->ccb_h.flags & CAM_CDB_POINTER)
2408 cdb = (void *)csio->cdb_io.cdb_ptr;
2409 else
2410 cdb = (void *)&csio->cdb_io.cdb_bytes;
2411 bcopy(cdb, (void *)&ocb->orb[5], csio->cdb_len);

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

2462
2463 ccb->ccb_h.status = CAM_REQ_INVALID;
2464 xpt_done(ccb);
2465 break;
2466 }
2467 case XPT_PATH_INQ: /* Path routing inquiry */
2468 {
2469 struct ccb_pathinq *cpi = &ccb->cpi;
2405 ocb->orb[4] |= htonl(ORB_CMD_IN);
2406 }
2407
2408 if (csio->ccb_h.flags & CAM_CDB_POINTER)
2409 cdb = (void *)csio->cdb_io.cdb_ptr;
2410 else
2411 cdb = (void *)&csio->cdb_io.cdb_bytes;
2412 bcopy(cdb, (void *)&ocb->orb[5], csio->cdb_len);

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

2463
2464 ccb->ccb_h.status = CAM_REQ_INVALID;
2465 xpt_done(ccb);
2466 break;
2467 }
2468 case XPT_PATH_INQ: /* Path routing inquiry */
2469 {
2470 struct ccb_pathinq *cpi = &ccb->cpi;
2470
2471
2471SBP_DEBUG(1)
2472 printf("%s:%d:%jx XPT_PATH_INQ:.\n",
2473 device_get_nameunit(sbp->fd.dev),
2474 ccb->ccb_h.target_id, (uintmax_t)ccb->ccb_h.target_lun);
2475END_DEBUG
2476 cpi->version_num = 1; /* XXX??? */
2477 cpi->hba_inquiry = PI_TAG_ABLE;
2478 cpi->target_sprt = 0;

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

2531 ccb->ccb_h.status = CAM_REQ_INVALID;
2532 xpt_done(ccb);
2533 break;
2534 }
2535 return;
2536}
2537
2538static void
2472SBP_DEBUG(1)
2473 printf("%s:%d:%jx XPT_PATH_INQ:.\n",
2474 device_get_nameunit(sbp->fd.dev),
2475 ccb->ccb_h.target_id, (uintmax_t)ccb->ccb_h.target_lun);
2476END_DEBUG
2477 cpi->version_num = 1; /* XXX??? */
2478 cpi->hba_inquiry = PI_TAG_ABLE;
2479 cpi->target_sprt = 0;

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

2532 ccb->ccb_h.status = CAM_REQ_INVALID;
2533 xpt_done(ccb);
2534 break;
2535 }
2536 return;
2537}
2538
2539static void
2539sbp_execute_ocb(void *arg, bus_dma_segment_t *segments, int seg, int error)
2540sbp_execute_ocb(void *arg, bus_dma_segment_t *segments, int seg, int error)
2540{
2541 int i;
2542 struct sbp_ocb *ocb;
2543 struct sbp_ocb *prev;
2544 bus_dma_segment_t *s;
2545
2546 if (error)
2547 printf("sbp_execute_ocb: error=%d\n", error);

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

2558
2559 if (seg == 1) {
2560 /* direct pointer */
2561 s = &segments[0];
2562 if (s->ds_len > SBP_SEG_MAX)
2563 panic("ds_len > SBP_SEG_MAX, fix busdma code");
2564 ocb->orb[3] = htonl(s->ds_addr);
2565 ocb->orb[4] |= htonl(s->ds_len);
2541{
2542 int i;
2543 struct sbp_ocb *ocb;
2544 struct sbp_ocb *prev;
2545 bus_dma_segment_t *s;
2546
2547 if (error)
2548 printf("sbp_execute_ocb: error=%d\n", error);

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

2559
2560 if (seg == 1) {
2561 /* direct pointer */
2562 s = &segments[0];
2563 if (s->ds_len > SBP_SEG_MAX)
2564 panic("ds_len > SBP_SEG_MAX, fix busdma code");
2565 ocb->orb[3] = htonl(s->ds_addr);
2566 ocb->orb[4] |= htonl(s->ds_len);
2566 } else if(seg > 1) {
2567 } else if (seg > 1) {
2567 /* page table */
2568 for (i = 0; i < seg; i++) {
2569 s = &segments[i];
2570SBP_DEBUG(0)
2571 /* XXX LSI Logic "< 16 byte" bug might be hit */
2572 if (s->ds_len < 16)
2573 printf("sbp_execute_ocb: warning, "
2574 "segment length(%zd) is less than 16."
2568 /* page table */
2569 for (i = 0; i < seg; i++) {
2570 s = &segments[i];
2571SBP_DEBUG(0)
2572 /* XXX LSI Logic "< 16 byte" bug might be hit */
2573 if (s->ds_len < 16)
2574 printf("sbp_execute_ocb: warning, "
2575 "segment length(%zd) is less than 16."
2575 "(seg=%d/%d)\n", (size_t)s->ds_len, i+1, seg);
2576 "(seg=%d/%d)\n", (size_t)s->ds_len, i + 1, seg);
2576END_DEBUG
2577 if (s->ds_len > SBP_SEG_MAX)
2578 panic("ds_len > SBP_SEG_MAX, fix busdma code");
2579 ocb->ind_ptr[i].hi = htonl(s->ds_len << 16);
2580 ocb->ind_ptr[i].lo = htonl(s->ds_addr);
2581 }
2582 ocb->orb[4] |= htonl(ORB_CMD_PTBL | seg);
2583 }
2577END_DEBUG
2578 if (s->ds_len > SBP_SEG_MAX)
2579 panic("ds_len > SBP_SEG_MAX, fix busdma code");
2580 ocb->ind_ptr[i].hi = htonl(s->ds_len << 16);
2581 ocb->ind_ptr[i].lo = htonl(s->ds_addr);
2582 }
2583 ocb->orb[4] |= htonl(ORB_CMD_PTBL | seg);
2584 }
2584
2585
2585 if (seg > 0)
2586 bus_dmamap_sync(ocb->sdev->target->sbp->dmat, ocb->dmamap,
2587 (ntohl(ocb->orb[4]) & ORB_CMD_IN) ?
2588 BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
2589 prev = sbp_enqueue_ocb(ocb->sdev, ocb);
2590 fwdma_sync(&ocb->sdev->dma, BUS_DMASYNC_PREWRITE);
2591 if (use_doorbell) {
2592 if (prev == NULL) {
2593 if (ocb->sdev->last_ocb != NULL)
2594 sbp_doorbell(ocb->sdev);
2595 else
2586 if (seg > 0)
2587 bus_dmamap_sync(ocb->sdev->target->sbp->dmat, ocb->dmamap,
2588 (ntohl(ocb->orb[4]) & ORB_CMD_IN) ?
2589 BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
2590 prev = sbp_enqueue_ocb(ocb->sdev, ocb);
2591 fwdma_sync(&ocb->sdev->dma, BUS_DMASYNC_PREWRITE);
2592 if (use_doorbell) {
2593 if (prev == NULL) {
2594 if (ocb->sdev->last_ocb != NULL)
2595 sbp_doorbell(ocb->sdev);
2596 else
2596 sbp_orb_pointer(ocb->sdev, ocb);
2597 sbp_orb_pointer(ocb->sdev, ocb);
2597 }
2598 } else {
2599 if (prev == NULL || (ocb->sdev->flags & ORB_LINK_DEAD) != 0) {
2600 ocb->sdev->flags &= ~ORB_LINK_DEAD;
2598 }
2599 } else {
2600 if (prev == NULL || (ocb->sdev->flags & ORB_LINK_DEAD) != 0) {
2601 ocb->sdev->flags &= ~ORB_LINK_DEAD;
2601 sbp_orb_pointer(ocb->sdev, ocb);
2602 sbp_orb_pointer(ocb->sdev, ocb);
2602 }
2603 }
2604}
2605
2606static void
2607sbp_poll(struct cam_sim *sim)
2603 }
2604 }
2605}
2606
2607static void
2608sbp_poll(struct cam_sim *sim)
2608{
2609{
2609 struct sbp_softc *sbp;
2610 struct firewire_comm *fc;
2611
2612 sbp = (struct sbp_softc *)sim->softc;
2613 fc = sbp->fd.fc;
2614
2615 fc->poll(fc, 0, -1);
2616

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

2643 BUS_DMASYNC_POSTREAD :
2644 BUS_DMASYNC_POSTWRITE);
2645 bus_dmamap_unload(sdev->target->sbp->dmat,
2646 ocb->dmamap);
2647 }
2648 if (!use_doorbell) {
2649 if (sbp_status->src == SRC_NO_NEXT) {
2650 if (next != NULL)
2610 struct sbp_softc *sbp;
2611 struct firewire_comm *fc;
2612
2613 sbp = (struct sbp_softc *)sim->softc;
2614 fc = sbp->fd.fc;
2615
2616 fc->poll(fc, 0, -1);
2617

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

2644 BUS_DMASYNC_POSTREAD :
2645 BUS_DMASYNC_POSTWRITE);
2646 bus_dmamap_unload(sdev->target->sbp->dmat,
2647 ocb->dmamap);
2648 }
2649 if (!use_doorbell) {
2650 if (sbp_status->src == SRC_NO_NEXT) {
2651 if (next != NULL)
2651 sbp_orb_pointer(sdev, next);
2652 sbp_orb_pointer(sdev, next);
2652 else if (order > 0) {
2653 /*
2654 * Unordered execution
2655 * We need to send pointer for
2656 * next ORB
2657 */
2658 sdev->flags |= ORB_LINK_DEAD;
2659 }
2660 }
2661 } else {
2662 /*
2663 * XXX this is not correct for unordered
2653 else if (order > 0) {
2654 /*
2655 * Unordered execution
2656 * We need to send pointer for
2657 * next ORB
2658 */
2659 sdev->flags |= ORB_LINK_DEAD;
2660 }
2661 }
2662 } else {
2663 /*
2664 * XXX this is not correct for unordered
2664 * execution.
2665 * execution.
2665 */
2666 if (sdev->last_ocb != NULL) {
2667 sbp_free_ocb(sdev, sdev->last_ocb);
2668 }
2669 sdev->last_ocb = ocb;
2670 if (next != NULL &&
2671 sbp_status->src == SRC_NO_NEXT)
2672 sbp_doorbell(sdev);
2673 }
2674 break;
2675 } else
2666 */
2667 if (sdev->last_ocb != NULL) {
2668 sbp_free_ocb(sdev, sdev->last_ocb);
2669 }
2670 sdev->last_ocb = ocb;
2671 if (next != NULL &&
2672 sbp_status->src == SRC_NO_NEXT)
2673 sbp_doorbell(sdev);
2674 }
2675 break;
2676 } else
2676 order ++;
2677 order++;
2677 }
2678SBP_DEBUG(0)
2679 if (ocb && order > 0) {
2680 device_printf(sdev->target->sbp->fd.dev,
2681 "%s:%s unordered execution order:%d\n",
2682 __func__, sdev->bustgtlun, order);
2683 }
2684END_DEBUG

--- 146 unchanged lines hidden ---
2678 }
2679SBP_DEBUG(0)
2680 if (ocb && order > 0) {
2681 device_printf(sdev->target->sbp->fd.dev,
2682 "%s:%s unordered execution order:%d\n",
2683 __func__, sdev->bustgtlun, order);
2684 }
2685END_DEBUG

--- 146 unchanged lines hidden ---