fwcontrol.c (109787) | fwcontrol.c (109814) |
---|---|
1/* 2 * Copyright (C) 2002 3 * Hidetoshi Shimokawa. 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 --- 17 unchanged lines hidden (view full) --- 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * | 1/* 2 * Copyright (C) 2002 3 * Hidetoshi Shimokawa. 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 --- 17 unchanged lines hidden (view full) --- 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * |
34 * $FreeBSD: head/usr.sbin/fwcontrol/fwcontrol.c 109787 2003-01-24 03:40:36Z simokawa $ | 34 * $FreeBSD: head/usr.sbin/fwcontrol/fwcontrol.c 109814 2003-01-25 14:47:33Z simokawa $ |
35 */ 36 37#include <sys/param.h> 38#include <sys/malloc.h> 39#include <sys/socket.h> 40#include <sys/ioctl.h> 41#include <sys/errno.h> 42#include <dev/firewire/firewire.h> --- 24 unchanged lines hidden (view full) --- 67 fprintf(stderr, "\t-d: hex dump of configuration ROM\n"); 68 fprintf(stderr, 69 "\t-l: load and parse hex dump file of configuration ROM\n"); 70 fprintf(stderr, "\t-R: Receive DV stream\n"); 71 fprintf(stderr, "\t-S: Send DV stream\n"); 72 exit(0); 73} 74 | 35 */ 36 37#include <sys/param.h> 38#include <sys/malloc.h> 39#include <sys/socket.h> 40#include <sys/ioctl.h> 41#include <sys/errno.h> 42#include <dev/firewire/firewire.h> --- 24 unchanged lines hidden (view full) --- 67 fprintf(stderr, "\t-d: hex dump of configuration ROM\n"); 68 fprintf(stderr, 69 "\t-l: load and parse hex dump file of configuration ROM\n"); 70 fprintf(stderr, "\t-R: Receive DV stream\n"); 71 fprintf(stderr, "\t-S: Send DV stream\n"); 72 exit(0); 73} 74 |
75static void 76get_num_of_dev(int fd, struct fw_devlstreq *data) | 75static struct fw_devlstreq * 76get_dev(int fd) |
77{ | 77{ |
78 data->n = 64; | 78 struct fw_devlstreq *data; 79 80 data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); 81 if (data == NULL) 82 err(1, "malloc"); |
79 if( ioctl(fd, FW_GDEVLST, data) < 0) { 80 err(1, "ioctl"); 81 } | 83 if( ioctl(fd, FW_GDEVLST, data) < 0) { 84 err(1, "ioctl"); 85 } |
86 return data; |
|
82} 83 84static void 85list_dev(int fd) 86{ | 87} 88 89static void 90list_dev(int fd) 91{ |
87 struct fw_devlstreq data; | 92 struct fw_devlstreq *data; 93 struct fw_devinfo *devinfo; |
88 int i; 89 | 94 int i; 95 |
90 get_num_of_dev(fd, &data); 91 printf("%d devices\n", data.n); 92 for (i = 0; i < data.n; i++) { | 96 data = get_dev(fd); 97 printf("%d devices (info_len=%d)\n", data->n, data->info_len); 98 for (i = 0; i < data->info_len; i++) { 99 devinfo = &data->dev[i]; |
93 printf("%d node %d eui:%08x%08x status:%d\n", 94 i, | 100 printf("%d node %d eui:%08x%08x status:%d\n", 101 i, |
95 data.dst[i], 96 data.eui[i].hi, 97 data.eui[i].lo, 98 data.status[i] | 102 devinfo->dst, 103 devinfo->eui.hi, 104 devinfo->eui.lo, 105 devinfo->status |
99 ); 100 } | 106 ); 107 } |
108 free((void *)data); |
|
101} 102 103static u_int32_t 104read_write_quad(int fd, struct fw_eui64 eui, u_int32_t addr_lo, int read, u_int32_t data) 105{ 106 struct fw_asyreq *asyreq; 107 u_int32_t *qld, res; 108 --- 51 unchanged lines hidden (view full) --- 160 if (ioctl(fd, FW_ASYREQ, asyreq) < 0) { 161 err(1, "ioctl"); 162 } 163} 164 165static void 166set_pri_req(int fd, int pri_req) 167{ | 109} 110 111static u_int32_t 112read_write_quad(int fd, struct fw_eui64 eui, u_int32_t addr_lo, int read, u_int32_t data) 113{ 114 struct fw_asyreq *asyreq; 115 u_int32_t *qld, res; 116 --- 51 unchanged lines hidden (view full) --- 168 if (ioctl(fd, FW_ASYREQ, asyreq) < 0) { 169 err(1, "ioctl"); 170 } 171} 172 173static void 174set_pri_req(int fd, int pri_req) 175{ |
168 struct fw_devlstreq data; | 176 struct fw_devlstreq *data; 177 struct fw_devinfo *devinfo; |
169 u_int32_t max, reg, old; 170 int i; 171 | 178 u_int32_t max, reg, old; 179 int i; 180 |
172 get_num_of_dev(fd, &data); | 181 data = get_dev(fd); |
173#define BUGET_REG 0xf0000218 | 182#define BUGET_REG 0xf0000218 |
174 for (i = 0; i < data.n; i++) { 175 if (!data.status[i]) | 183 for (i = 0; i < data->info_len; i++) { 184 devinfo = &data->dev[i]; 185 if (!devinfo->status) |
176 continue; | 186 continue; |
177 reg = read_write_quad(fd, data.eui[i], BUGET_REG, 1, 0); | 187 reg = read_write_quad(fd, devinfo->eui, BUGET_REG, 1, 0); |
178 printf("%d %08x:%08x, %08x", | 188 printf("%d %08x:%08x, %08x", |
179 data.dst[i], data.eui[i].hi, data.eui[i].lo, reg); | 189 devinfo->dst, devinfo->eui.hi, devinfo->eui.lo, reg); |
180 if (reg > 0 && pri_req >= 0) { 181 old = (reg & 0x3f); 182 max = (reg & 0x3f00) >> 8; 183 if (pri_req > max) 184 pri_req = max; 185 printf(" 0x%x -> 0x%x\n", old, pri_req); | 190 if (reg > 0 && pri_req >= 0) { 191 old = (reg & 0x3f); 192 max = (reg & 0x3f00) >> 8; 193 if (pri_req > max) 194 pri_req = max; 195 printf(" 0x%x -> 0x%x\n", old, pri_req); |
186 read_write_quad(fd, data.eui[i], BUGET_REG, 0, pri_req); | 196 read_write_quad(fd, devinfo->eui, BUGET_REG, 0, pri_req); |
187 } else { 188 printf("\n"); 189 } 190 } | 197 } else { 198 printf("\n"); 199 } 200 } |
201 free((void *)data); |
|
191} 192 193static void 194parse_bus_info_block(u_int32_t *p, int info_len) 195{ 196 int i; 197 198 for (i = 0; i < info_len; i++) { 199 printf("bus_info%d: 0x%08x\n", i, *p++); 200 } 201} 202 203static int 204get_crom(int fd, int node, void *crom_buf, int len) 205{ 206 struct fw_crom_buf buf; | 202} 203 204static void 205parse_bus_info_block(u_int32_t *p, int info_len) 206{ 207 int i; 208 209 for (i = 0; i < info_len; i++) { 210 printf("bus_info%d: 0x%08x\n", i, *p++); 211 } 212} 213 214static int 215get_crom(int fd, int node, void *crom_buf, int len) 216{ 217 struct fw_crom_buf buf; |
207 int i, error; 208 struct fw_devlstreq data; | 218 int i, n, error; 219 struct fw_devlstreq *data; |
209 | 220 |
210 get_num_of_dev(fd, &data); | 221 data = get_dev(fd); |
211 | 222 |
212 for (i = 0; i < data.n; i++) { 213 if (data.dst[i] == node && data.eui[i].lo != 0) | 223 for (i = 0; i < data->info_len; i++) { 224 if (data->dev[i].dst == node && data->dev[i].eui.lo != 0) |
214 break; 215 } | 225 break; 226 } |
216 if (i != data.n) { 217 buf.eui = data.eui[i]; 218 } else { 219 err(1, "no such node: %d\n", node); 220 } | 227 if (i == data->info_len) 228 errx(1, "no such node %d.", node); 229 else if (i == 0) 230 errx(1, "node %d is myself.", node); 231 else 232 buf.eui = data->dev[i].eui; 233 free((void *)data); |
221 222 buf.len = len; 223 buf.ptr = crom_buf; 224 if ((error = ioctl(fd, FW_GCROM, &buf)) < 0) { 225 err(1, "ioctl"); 226 } | 234 235 buf.len = len; 236 buf.ptr = crom_buf; 237 if ((error = ioctl(fd, FW_GCROM, &buf)) < 0) { 238 err(1, "ioctl"); 239 } |
240 |
|
227 return error; 228} 229 230static void 231show_crom(u_int32_t *crom_buf) 232{ 233 int i; 234 struct crom_context cc; --- 173 unchanged lines hidden --- | 241 return error; 242} 243 244static void 245show_crom(u_int32_t *crom_buf) 246{ 247 int i; 248 struct crom_context cc; --- 173 unchanged lines hidden --- |