sbp.c (110798) | sbp.c (110839) |
---|---|
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 110798 2003-02-13 13:35:57Z simokawa $ | 33 * $FreeBSD: head/sys/dev/firewire/sbp.c 110839 2003-02-14 03:09:59Z 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> --- 427 unchanged lines hidden (view full) --- 469 /* XXX num_lun may be changed. realloc luns? */ 470 crom_init_context(&cc, target->fwdev->csrrom); 471 /* XXX shoud parse appropriate unit directories only */ 472 maxlun = -1; 473 while (cc.depth >= 0) { 474 reg = crom_search_key(&cc, CROM_LUN); 475 if (reg == NULL) 476 break; | 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> --- 427 unchanged lines hidden (view full) --- 469 /* XXX num_lun may be changed. realloc luns? */ 470 crom_init_context(&cc, target->fwdev->csrrom); 471 /* XXX shoud parse appropriate unit directories only */ 472 maxlun = -1; 473 while (cc.depth >= 0) { 474 reg = crom_search_key(&cc, CROM_LUN); 475 if (reg == NULL) 476 break; |
477 lun = reg->val & 0xff; | 477 lun = reg->val & 0xffff; |
478SBP_DEBUG(0) 479 printf("target %d lun %d found\n", target->target_id, lun); 480END_DEBUG 481 if (maxlun < lun) 482 maxlun = lun; 483 crom_next(&cc); 484 } | 478SBP_DEBUG(0) 479 printf("target %d lun %d found\n", target->target_id, lun); 480END_DEBUG 481 if (maxlun < lun) 482 maxlun = lun; 483 crom_next(&cc); 484 } |
485 target->num_lun = maxlun + 1; 486 if (maxlun < 0) { | 485 if (maxlun < 0) |
487 printf("no lun found!\n"); | 486 printf("no lun found!\n"); |
488 } | 487 if (maxlun >= SBP_NUM_LUNS) 488 maxlun = SBP_NUM_LUNS; 489 target->num_lun = maxlun + 1; |
489 target->luns = (struct sbp_dev *) malloc( 490 sizeof(struct sbp_dev) * target->num_lun, 491 M_SBP, M_NOWAIT | M_ZERO); 492 for (i = 0; i < target->num_lun; i++) { 493 sdev = &target->luns[i]; 494 sdev->lun_id = i; 495 sdev->target = target; 496 STAILQ_INIT(&sdev->ocbs); 497 sdev->status = SBP_DEV_DEAD; 498 } 499 crom_init_context(&cc, target->fwdev->csrrom); 500 while (cc.depth >= 0) { 501 reg = crom_search_key(&cc, CROM_LUN); 502 if (reg == NULL) 503 break; | 490 target->luns = (struct sbp_dev *) malloc( 491 sizeof(struct sbp_dev) * target->num_lun, 492 M_SBP, M_NOWAIT | M_ZERO); 493 for (i = 0; i < target->num_lun; i++) { 494 sdev = &target->luns[i]; 495 sdev->lun_id = i; 496 sdev->target = target; 497 STAILQ_INIT(&sdev->ocbs); 498 sdev->status = SBP_DEV_DEAD; 499 } 500 crom_init_context(&cc, target->fwdev->csrrom); 501 while (cc.depth >= 0) { 502 reg = crom_search_key(&cc, CROM_LUN); 503 if (reg == NULL) 504 break; |
504 lun = reg->val & 0xff; | 505 lun = reg->val & 0xffff; 506 if (lun >= SBP_NUM_LUNS) { 507 printf("too large lun %d\n", lun); 508 continue; 509 } |
505 target->luns[lun].status = SBP_DEV_RESET; | 510 target->luns[lun].status = SBP_DEV_RESET; |
506 target->luns[lun].type = (reg->val & 0x0f00) >> 16; | 511 target->luns[lun].type = (reg->val & 0xf0000) >> 16; |
507 crom_next(&cc); | 512 crom_next(&cc); |
508 } 509 return target; 510} | 513 } 514 return target; 515 } |
511 512static void 513sbp_get_text_leaf(struct fw_device *fwdev, int key, char *buf, int len) 514{ 515 static char *nullstr = "(null)"; 516 int i, clen, found=0; 517 struct csrhdr *chdr; 518 struct csrreg *creg; 519 u_int32_t *src, *dst; 520 521 chdr = (struct csrhdr *)&fwdev->csrrom[0]; | 516 517static void 518sbp_get_text_leaf(struct fw_device *fwdev, int key, char *buf, int len) 519{ 520 static char *nullstr = "(null)"; 521 int i, clen, found=0; 522 struct csrhdr *chdr; 523 struct csrreg *creg; 524 u_int32_t *src, *dst; 525 526 chdr = (struct csrhdr *)&fwdev->csrrom[0]; |
522 creg = (struct csrreg *)chdr; 523 creg += chdr->info_len; 524 for( i = chdr->info_len + 4; i <= fwdev->rommax - 4; i+=4){ | 527 /* skip crom header, bus info and root directory */ 528 creg = (struct csrreg *)chdr + chdr->info_len + 2; 529 /* search unitl the one before the last. */ 530 for (i = chdr->info_len + 2; i < fwdev->rommax / 4; i++) { |
525 if((creg++)->key == key){ 526 found = 1; 527 break; 528 } 529 } 530 if (!found || creg->key != CROM_TEXTLEAF) { 531 strncpy(buf, nullstr, len); 532 return; --- 1877 unchanged lines hidden --- | 531 if((creg++)->key == key){ 532 found = 1; 533 break; 534 } 535 } 536 if (!found || creg->key != CROM_TEXTLEAF) { 537 strncpy(buf, nullstr, len); 538 return; --- 1877 unchanged lines hidden --- |