Print this page
5218 posix definition of NULL
correct unistd.h and iso/stddef_iso.h
update gate source affected
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/cfgadm_plugins/pci/common/cfga.c
+++ new/usr/src/lib/cfgadm_plugins/pci/common/cfga.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #pragma ident "%Z%%M% %I% %E% SMI"
28 28
29 29 /*
30 30 * Plugin Library for PCI Hot-Plug Controller
31 31 */
32 32
33 33 #include <stddef.h>
34 34 #include <locale.h>
35 35 #include <ctype.h>
36 36 #include <stdio.h>
37 37 #include <stdlib.h>
38 38 #include <string.h>
39 39 #include <fcntl.h>
40 40 #include <unistd.h>
41 41 #include <errno.h>
42 42 #include <locale.h>
43 43 #include <langinfo.h>
44 44 #include <time.h>
45 45 #include <sys/param.h>
46 46 #include <stdarg.h>
47 47 #include <libdevinfo.h>
48 48 #include <libdevice.h>
49 49
50 50 #define CFGA_PLUGIN_LIB
51 51
52 52 #include <config_admin.h>
53 53
54 54 #include <sys/types.h>
55 55 #include <sys/stat.h>
56 56 #include <sys/ioctl.h>
57 57 #include <sys/dditypes.h>
58 58 #include <sys/devctl.h>
59 59 #include <sys/modctl.h>
60 60 #include <sys/hotplug/hpctrl.h>
61 61 #include <sys/pci.h>
62 62 #include <libintl.h>
63 63
64 64 #include <dirent.h>
65 65 #include <limits.h>
66 66 #include <sys/mkdev.h>
67 67 #include <librcm.h>
68 68 #include "../../../../common/pci/pci_strings.h"
69 69
70 70 extern const struct pci_class_strings_s class_pci[];
71 71 extern int class_pci_items;
72 72
73 73 /*
74 74 * Set the version number
75 75 */
76 76 int cfga_version = CFGA_HSL_V2;
77 77
78 78 #ifdef DEBUG
79 79 #define PCIHP_DBG 1
80 80 #endif
81 81
82 82 #if !defined(TEXT_DOMAIN)
83 83 #define TEXT_DOMAIN "SYS_TEST"
84 84 #endif
85 85
86 86 /*
87 87 * DEBUGING LEVEL
88 88 *
89 89 * External routines: 1 - 2
90 90 * Internal routines: 3 - 4
91 91 */
92 92 #ifdef PCIHP_DBG
93 93 int pcihp_debug = 1;
94 94 #define DBG(level, args) \
95 95 { if (pcihp_debug >= (level)) printf args; }
96 96 #define DBG_F(level, args) \
97 97 { if (pcihp_debug >= (level)) fprintf args; }
98 98 #else
99 99 #define DBG(level, args) /* nothing */
100 100 #define DBG_F(level, args) /* nothing */
101 101 #endif
102 102
103 103 #define CMD_ACQUIRE 0
104 104 #define CMD_GETSTAT 1
105 105 #define CMD_LIST 2
106 106 #define CMD_SLOT_CONNECT 3
107 107 #define CMD_SLOT_DISCONNECT 4
108 108 #define CMD_SLOT_CONFIGURE 5
109 109 #define CMD_SLOT_UNCONFIGURE 6
110 110 #define CMD_SLOT_INSERT 7
111 111 #define CMD_SLOT_REMOVE 8
112 112 #define CMD_OPEN 9
113 113 #define CMD_FSTAT 10
114 114 #define ERR_CMD_INVAL 11
115 115 #define ERR_AP_INVAL 12
116 116 #define ERR_AP_ERR 13
117 117 #define ERR_OPT_INVAL 14
118 118
119 119 static char *
120 120 cfga_errstrs[] = {
121 121 /* n */ "acquire ",
122 122 /* n */ "get-status ",
123 123 /* n */ "list ",
124 124 /* n */ "connect ",
125 125 /* n */ "disconnect ",
126 126 /* n */ "configure ",
127 127 /* n */ "unconfigure ",
128 128 /* n */ "insert ",
129 129 /* n */ "remove ",
130 130 /* n */ "open ",
131 131 /* n */ "fstat ",
132 132 /* y */ "invalid command ",
133 133 /* y */ "invalid attachment point ",
134 134 /* y */ "invalid transition ",
135 135 /* y */ "invalid option ",
136 136 NULL
137 137 };
138 138
139 139 #define HELP_HEADER 1
140 140 #define HELP_CONFIG 2
141 141 #define HELP_ENABLE_SLOT 3
142 142 #define HELP_DISABLE_SLOT 4
143 143 #define HELP_ENABLE_AUTOCONF 5
144 144 #define HELP_DISABLE_AUTOCONF 6
145 145 #define HELP_LED_CNTRL 7
146 146 #define HELP_UNKNOWN 8
147 147 #define SUCCESS 9
148 148 #define FAILED 10
149 149 #define UNKNOWN 11
150 150
151 151 #define MAXLINE 256
152 152
153 153 /* for type string assembly in get_type() */
154 154 #define TPCT(s) (void) strlcat(buf, (s), CFGA_TYPE_LEN)
155 155
156 156 extern int errno;
157 157
158 158 static void cfga_err(char **errstring, ...);
159 159 static cfga_err_t fix_ap_name(char *ap_log_id, const char *ap_id,
160 160 char *slot_name, char **errstring);
161 161 static void build_control_data(struct hpc_control_data *iocdata, uint_t cmd,
162 162 void *retdata);
163 163 static cfga_err_t check_options(const char *options);
164 164 static void cfga_msg(struct cfga_msg *msgp, const char *str);
165 165 static char *findlink(char *ap_phys_id);
166 166
167 167 static char *
168 168 cfga_strs[] = {
169 169 NULL,
170 170 "\nPCI hotplug specific commands:",
171 171 "\t-c [connect|disconnect|configure|unconfigure|insert|remove] "
172 172 "ap_id [ap_id...]",
173 173 "\t-x enable_slot ap_id [ap_id...]",
174 174 "\t-x disable_slot ap_id [ap_id...]",
175 175 "\t-x enable_autoconfig ap_id [ap_id...]",
176 176 "\t-x disable_autoconfig ap_id [ap_id...]",
177 177 "\t-x led[=[fault|power|active|attn],mode=[on|off|blink]] ap_id [ap_id...]",
178 178 "\tunknown command or option: ",
179 179 "success ",
180 180 "failed ",
181 181 "unknown",
182 182 NULL
183 183 };
184 184
185 185 #define MAX_FORMAT 80
186 186
187 187 #define ENABLE_SLOT 0
188 188 #define DISABLE_SLOT 1
189 189 #define ENABLE_AUTOCNF 2
190 190 #define DISABLE_AUTOCNF 3
191 191 #define LED 4
192 192 #define MODE 5
193 193
194 194 /*
195 195 * Board Type
196 196 */
197 197 static char *
198 198 board_strs[] = {
199 199 /* n */ "???", /* HPC_BOARD_UNKNOWN */
200 200 /* n */ "hp", /* HPC_BOARD_PCI_HOTPLUG */
201 201 /* n */ "nhs", /* HPC_BOARD_CPCI_NON_HS */
202 202 /* n */ "bhs", /* HPC_BOARD_CPCI_BASIC_HS */
203 203 /* n */ "fhs", /* HPC_BOARD_CPCI_FULL_HS */
204 204 /* n */ "hs", /* HPC_BOARD_CPCI_HS */
205 205 /* n */ NULL
206 206 };
207 207
208 208 /*
209 209 * HW functions
210 210 */
211 211 static char *
212 212 func_strs[] = {
213 213 /* n */ "enable_slot",
214 214 /* n */ "disable_slot",
215 215 /* n */ "enable_autoconfig",
216 216 /* n */ "disable_autoconfig",
217 217 /* n */ "led",
218 218 /* n */ "mode",
219 219 /* n */ NULL
220 220 };
221 221
222 222 /*
223 223 * LED strings
224 224 */
225 225 static char *
226 226 led_strs[] = {
227 227 /* n */ "fault", /* HPC_FAULT_LED */
228 228 /* n */ "power", /* HPC_POWER_LED */
229 229 /* n */ "attn", /* HPC_ATTN_LED */
230 230 /* n */ "active", /* HPC_ACTIVE_LED */
231 231 /* n */ NULL
232 232 };
233 233
234 234 #define FAULT 0
235 235 #define POWER 1
236 236 #define ATTN 2
237 237 #define ACTIVE 3
238 238
239 239 static char *
240 240 mode_strs[] = {
241 241 /* n */ "off", /* HPC_LED_OFF */
242 242 /* n */ "on", /* HPC_LED_ON */
243 243 /* n */ "blink", /* HPC_LED_BLINK */
244 244 /* n */ NULL
245 245 };
246 246
247 247 #define OFF 0
248 248 #define ON 1
249 249 #define BLINK 2
250 250
251 251 #define cfga_errstrs(i) cfga_errstrs[(i)]
252 252
253 253 #define cfga_eid(a, b) (((a) << 8) + (b))
254 254 #define MAXDEVS 32
255 255
256 256 typedef enum {
257 257 SOLARIS_SLT_NAME,
258 258 PROM_SLT_NAME
259 259 } slt_name_src_t;
260 260
261 261 struct searcharg {
262 262 char *devpath;
263 263 char slotnames[MAXDEVS][MAXNAMELEN];
264 264 int minor;
265 265 di_prom_handle_t promp;
266 266 slt_name_src_t slt_name_src;
267 267 };
268 268
269 269 static void *private_check;
270 270
271 271 static int
272 272 get_occupants(const char *ap_id, hpc_occupant_info_t *occupant)
273 273 {
274 274 int rv;
275 275 int fd;
276 276 di_node_t ap_node;
277 277 char *prop_data;
278 278 char *tmp;
279 279 char *ptr;
280 280 struct stat statbuf;
281 281 dev_t devt;
282 282
283 283 if ((fd = open(ap_id, O_RDWR)) == -1) {
284 284 DBG(2, ("open = ap_id%s, fd%d\n", ap_id, fd));
285 285 DBG_F(2, (stderr, "open on %s failed\n", ap_id));
286 286 return (CFGA_ERROR);
287 287 }
288 288
289 289 if (fstat(fd, &statbuf) == -1) {
290 290 DBG(1, ("stat failed: %i\n", errno));
291 291 (void) close(fd);
292 292 return (CFGA_ERROR);
293 293 }
294 294 (void) close(fd);
295 295
296 296 devt = statbuf.st_rdev;
297 297
298 298 tmp = (char *)(ap_id + sizeof ("/devices") - 1);
299 299 if ((ptr = strrchr(tmp, ':')) != NULL)
300 300 *ptr = '\0';
301 301
302 302 ap_node = di_init(tmp, DINFOPROP | DINFOMINOR);
303 303 if (ap_node == DI_NODE_NIL) {
304 304 DBG(1, ("dead %i\n", errno));
305 305 return (CFGA_ERROR);
306 306 }
307 307
308 308 #ifdef PCIHP_DBG
309 309 ptr = di_devfs_path(ap_node);
310 310 DBG(1, ("get_occupants: %s\n", ptr));
311 311 di_devfs_path_free(ptr);
312 312 #endif
313 313
314 314 if ((rv = di_prop_lookup_strings(devt, ap_node, "pci-occupant",
315 315 &prop_data)) == -1) {
316 316 DBG(1, ("get_occupants: prop_lookup failed: %i\n", errno));
317 317 di_fini(ap_node);
318 318 return (CFGA_ERROR);
319 319 }
320 320
321 321 if (prop_data && (strcmp(prop_data, "") == 0)) {
322 322 di_fini(ap_node);
323 323 occupant->i = 0;
324 324 occupant->id[0] = NULL;
325 325 return (CFGA_OK);
326 326 }
327 327
328 328 DBG(1, ("get_occupants: %i devices found\n", rv));
329 329 for (occupant->i = 0; occupant->i < rv; occupant->i++) {
330 330 if (occupant->i >= (HPC_MAX_OCCUPANTS - 1)) {
331 331 occupant->i--;
332 332 break;
333 333 }
334 334 occupant->id[occupant->i] = (char *)malloc(
335 335 strlen(prop_data) + sizeof ("/devices"));
336 336 (void) snprintf(occupant->id[occupant->i], strlen(prop_data) +
337 337 sizeof ("/devices"), "/devices%s", prop_data);
338 338 DBG(1, ("%s\n", occupant->id[occupant->i]));
339 339 prop_data += strlen(prop_data) + 1;
340 340 }
341 341 di_fini(ap_node);
342 342
343 343 occupant->id[occupant->i] = NULL;
344 344
345 345 return (CFGA_OK);
346 346 }
347 347
348 348 /*
349 349 * let rcm know that the device has indeed been removed and clean
350 350 * up rcm data
351 351 */
352 352 static void
353 353 confirm_rcm(hpc_occupant_info_t *occupant, rcm_handle_t *rhandle)
354 354 {
355 355 DBG(1, ("confirm_rcm\n"));
356 356
357 357 if (occupant->i == 0) /* nothing was found to ask rcm about */
358 358 return;
359 359
360 360 (void) rcm_notify_remove_list(rhandle, occupant->id, 0, NULL);
361 361 (void) rcm_free_handle(rhandle);
362 362
363 363 for (; occupant->i >= 0; occupant->i--)
364 364 free(occupant->id[occupant->i]);
365 365 }
366 366
367 367 static void
368 368 fail_rcm(hpc_occupant_info_t *occupant, rcm_handle_t *rhandle)
369 369 {
370 370 DBG(1, ("fail_rcm\n"));
371 371
372 372 if (occupant->i == 0) /* nothing was found to ask rcm about */
373 373 return;
374 374
375 375 (void) rcm_notify_online_list(rhandle, occupant->id, 0, NULL);
376 376 (void) rcm_free_handle(rhandle);
377 377
378 378 for (; occupant->i >= 0; occupant->i--)
379 379 free(occupant->id[occupant->i]);
380 380 }
381 381
382 382 /*
383 383 * copied from scsi_rcm_info_table
384 384 *
385 385 * Takes an opaque rcm_info_t pointer and a character pointer, and appends
386 386 * the rcm_info_t data in the form of a table to the given character pointer.
387 387 */
388 388 static void
389 389 pci_rcm_info_table(rcm_info_t *rinfo, char **table)
390 390 {
391 391 int i;
392 392 size_t w;
393 393 size_t width = 0;
394 394 size_t w_rsrc = 0;
395 395 size_t w_info = 0;
396 396 size_t table_size = 0;
397 397 uint_t tuples = 0;
398 398 rcm_info_tuple_t *tuple = NULL;
399 399 char *rsrc;
400 400 char *info;
401 401 char *newtable;
402 402 static char format[MAX_FORMAT];
403 403 const char *infostr;
404 404
405 405 /* Protect against invalid arguments */
406 406 if (rinfo == NULL || table == NULL)
407 407 return;
408 408
409 409 /* Set localized table header strings */
410 410 rsrc = dgettext(TEXT_DOMAIN, "Resource");
411 411 info = dgettext(TEXT_DOMAIN, "Information");
412 412
413 413 /* A first pass, to size up the RCM information */
414 414 while (tuple = rcm_info_next(rinfo, tuple)) {
415 415 if ((infostr = rcm_info_info(tuple)) != NULL) {
416 416 tuples++;
417 417 if ((w = strlen(rcm_info_rsrc(tuple))) > w_rsrc)
418 418 w_rsrc = w;
419 419 if ((w = strlen(infostr)) > w_info)
420 420 w_info = w;
421 421 }
422 422 }
423 423
424 424 /* If nothing was sized up above, stop early */
425 425 if (tuples == 0)
426 426 return;
427 427
428 428 /* Adjust column widths for column headings */
429 429 if ((w = strlen(rsrc)) > w_rsrc)
430 430 w_rsrc = w;
431 431 else if ((w_rsrc - w) % 2)
432 432 w_rsrc++;
433 433 if ((w = strlen(info)) > w_info)
434 434 w_info = w;
435 435 else if ((w_info - w) % 2)
436 436 w_info++;
437 437
438 438 /*
439 439 * Compute the total line width of each line,
440 440 * accounting for intercolumn spacing.
441 441 */
442 442 width = w_info + w_rsrc + 4;
443 443
444 444 /* Allocate space for the table */
445 445 table_size = (2 + tuples) * (width + 1) + 2;
446 446 if (*table == NULL) {
447 447 /* zero fill for the strcat() call below */
448 448 *table = calloc(table_size, sizeof (char));
449 449 if (*table == NULL)
450 450 return;
451 451 } else {
452 452 newtable = realloc(*table, strlen(*table) + table_size);
453 453 if (newtable == NULL)
454 454 return;
455 455 else
456 456 *table = newtable;
457 457 }
458 458
459 459 /* Place a table header into the string */
460 460
461 461 /* The resource header */
462 462 (void) strcat(*table, "\n");
463 463 w = strlen(rsrc);
464 464 for (i = 0; i < ((w_rsrc - w) / 2); i++)
465 465 (void) strcat(*table, " ");
466 466 (void) strcat(*table, rsrc);
467 467 for (i = 0; i < ((w_rsrc - w) / 2); i++)
468 468 (void) strcat(*table, " ");
469 469
470 470 /* The information header */
471 471 (void) strcat(*table, " ");
472 472 w = strlen(info);
473 473 for (i = 0; i < ((w_info - w) / 2); i++)
474 474 (void) strcat(*table, " ");
475 475 (void) strcat(*table, info);
476 476 for (i = 0; i < ((w_info - w) / 2); i++)
477 477 (void) strcat(*table, " ");
478 478 /* Underline the headers */
479 479 (void) strcat(*table, "\n");
480 480 for (i = 0; i < w_rsrc; i++)
481 481 (void) strcat(*table, "-");
482 482 (void) strcat(*table, " ");
483 483 for (i = 0; i < w_info; i++)
484 484 (void) strcat(*table, "-");
485 485
486 486 /* Construct the format string */
487 487 (void) snprintf(format, MAX_FORMAT, "%%-%ds %%-%ds",
488 488 (int)w_rsrc, (int)w_info);
489 489
490 490 /* Add the tuples to the table string */
491 491 tuple = NULL;
492 492 while ((tuple = rcm_info_next(rinfo, tuple)) != NULL) {
493 493 if ((infostr = rcm_info_info(tuple)) != NULL) {
494 494 (void) strcat(*table, "\n");
495 495 (void) sprintf(&((*table)[strlen(*table)]),
496 496 format, rcm_info_rsrc(tuple),
497 497 infostr);
498 498 }
499 499 }
500 500 }
501 501
502 502 /*
503 503 * Figure out what device is about to be unconfigured or disconnected
504 504 * and make sure rcm is ok with it.
505 505 * hangs on to a list of handles so they can then be confirmed or denied
506 506 * if either getting the occupant list or talking to rcm fails
507 507 * return CFGA_ERROR so that things can go on without rcm
508 508 */
509 509 static int
510 510 check_rcm(const char *ap_id, hpc_occupant_info_t *occupant,
511 511 rcm_handle_t **rhandlep, char **errstring, cfga_flags_t flags)
512 512 {
513 513 int rv;
514 514 rcm_info_t *rinfo;
515 515 rcm_handle_t *rhandle;
516 516 uint_t rcmflags;
517 517
518 518 if (get_occupants(ap_id, occupant) != 0) {
519 519 DBG(1, ("check_rcm: failed to get occupants\n"));
520 520 return (CFGA_ERROR);
521 521 }
522 522
523 523 if (occupant->i == 0) {
524 524 DBG(1, ("check_rcm: no drivers attaching to occupants\n"));
525 525 return (CFGA_OK);
526 526 }
527 527
528 528 if (rcm_alloc_handle(NULL, 0, NULL, &rhandle)
529 529 != RCM_SUCCESS) {
530 530 DBG(1, ("check_rcm: blocked by rcm failure\n"));
531 531 return (CFGA_ERROR);
532 532 }
533 533
534 534 rcmflags = (flags & CFGA_FLAG_FORCE) ? RCM_FORCE : 0;
535 535 rv = rcm_request_offline_list(rhandle, occupant->id, rcmflags, &rinfo);
536 536
537 537 if (rv == RCM_FAILURE) {
538 538 DBG(1, ("check_rcm: blocked by rcm failure 2\n"));
539 539 pci_rcm_info_table(rinfo, errstring);
540 540 rcm_free_info(rinfo);
541 541 fail_rcm(occupant, rhandle);
542 542 return (CFGA_BUSY);
543 543 }
544 544 if (rv == RCM_CONFLICT) {
545 545 DBG(1, ("check_rcm: blocked by %i\n",
546 546 rcm_info_pid(rinfo)));
547 547 pci_rcm_info_table(rinfo, errstring);
548 548 rcm_free_info(rinfo);
549 549 (void) rcm_free_handle(rhandle);
550 550 for (; occupant->i >= 0; occupant->i--)
551 551 free(occupant->id[occupant->i]);
552 552 return (CFGA_BUSY);
553 553 }
554 554
555 555 rcm_free_info(rinfo);
556 556 *rhandlep = rhandle;
557 557
558 558 /* else */
559 559 return (CFGA_OK);
560 560 }
561 561
562 562
563 563 /*
564 564 * Transitional Diagram:
565 565 *
566 566 * empty unconfigure
567 567 * (remove) ^| (physically insert card)
568 568 * |V
569 569 * disconnect configure
570 570 * "-c DISCONNECT" ^| "-c CONNECT"
571 571 * |V "-c CONFIGURE"
572 572 * connect unconfigure -> connect configure
573 573 * <-
574 574 * "-c UNCONFIGURE"
575 575 *
576 576 */
577 577 /*ARGSUSED*/
578 578 cfga_err_t
579 579 cfga_change_state(cfga_cmd_t state_change_cmd, const char *ap_id,
580 580 const char *options, struct cfga_confirm *confp,
581 581 struct cfga_msg *msgp, char **errstring, cfga_flags_t flags)
582 582 {
583 583 int rv;
584 584 devctl_hdl_t dcp;
585 585 devctl_ap_state_t state;
586 586 ap_rstate_t rs;
587 587 ap_ostate_t os;
588 588 hpc_occupant_info_t occupants;
589 589 rcm_handle_t *rhandle;
590 590
591 591 if ((rv = check_options(options)) != CFGA_OK) {
592 592 return (rv);
593 593 }
594 594
595 595 if (errstring != NULL)
596 596 *errstring = NULL;
597 597
598 598 rv = CFGA_OK;
599 599 DBG(1, ("cfga_change_state:(%s)\n", ap_id));
600 600
601 601 if ((dcp = devctl_ap_acquire((char *)ap_id, 0)) == NULL) {
602 602 if (rv == EBUSY) {
603 603 cfga_err(errstring, CMD_ACQUIRE, ap_id, 0);
604 604 DBG(1, ("cfga_change_state: device is busy\n"));
605 605 rv = CFGA_BUSY;
606 606 } else
607 607 rv = CFGA_ERROR;
608 608 return (rv);
609 609 }
610 610
611 611 if (devctl_ap_getstate(dcp, NULL, &state) == -1) {
612 612 DBG(2, ("cfga_change_state: devctl ap getstate failed\n"));
613 613 cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
614 614 devctl_release((devctl_hdl_t)dcp);
615 615 if (rv == EBUSY)
616 616 rv = CFGA_BUSY;
617 617 else
618 618 rv = CFGA_ERROR;
619 619 return (rv);
620 620 }
621 621
622 622 rs = state.ap_rstate;
623 623 os = state.ap_ostate;
624 624
625 625 DBG(1, ("cfga_change_state: rs is %d\n", state.ap_rstate));
626 626 DBG(1, ("cfga_change_state: os is %d\n", state.ap_ostate));
627 627 switch (state_change_cmd) {
628 628 case CFGA_CMD_CONNECT:
629 629 if ((rs == AP_RSTATE_EMPTY) ||
630 630 (rs == AP_RSTATE_CONNECTED) ||
631 631 (os == AP_OSTATE_CONFIGURED)) {
632 632 cfga_err(errstring, ERR_AP_ERR, 0);
633 633 rv = CFGA_INVAL;
634 634 } else {
635 635 /* Lets connect the slot */
636 636 if (devctl_ap_connect(dcp, NULL) == -1) {
637 637 rv = CFGA_ERROR;
638 638 cfga_err(errstring,
639 639 CMD_SLOT_CONNECT, 0);
640 640 }
641 641 }
642 642
643 643 break;
644 644
645 645 case CFGA_CMD_DISCONNECT:
646 646 DBG(1, ("disconnect\n"));
647 647
648 648 if (os == AP_OSTATE_CONFIGURED) {
649 649 if ((rv = check_rcm(ap_id, &occupants, &rhandle,
650 650 errstring, flags)) == CFGA_BUSY) {
651 651 break;
652 652 } else if (rv == CFGA_OK) {
653 653 if (devctl_ap_unconfigure(dcp, NULL) == -1) {
654 654 if (errno == EBUSY)
655 655 rv = CFGA_BUSY;
656 656 else
657 657 rv = CFGA_ERROR;
658 658 cfga_err(errstring,
659 659 CMD_SLOT_DISCONNECT, 0);
660 660 fail_rcm(&occupants, rhandle);
661 661 break;
662 662 } else {
663 663 confirm_rcm(&occupants, rhandle);
664 664 }
665 665 } else { /* rv == CFGA_ERROR */
666 666 if (devctl_ap_unconfigure(dcp, NULL) == -1) {
667 667 if (errno == EBUSY)
668 668 rv = CFGA_BUSY;
669 669 else
670 670 rv = CFGA_ERROR;
671 671 break;
672 672 } else {
673 673 rv = CFGA_OK;
674 674 }
675 675 }
676 676 }
677 677
678 678 if (rs == AP_RSTATE_CONNECTED) {
679 679 if (devctl_ap_disconnect(dcp, NULL) == -1) {
680 680 rv = CFGA_ERROR;
681 681 cfga_err(errstring, CMD_SLOT_DISCONNECT, 0);
682 682 break;
683 683 }
684 684 } else {
685 685 cfga_err(errstring, ERR_AP_ERR, 0);
686 686 rv = CFGA_INVAL;
687 687 }
688 688
689 689 break;
690 690
691 691 case CFGA_CMD_CONFIGURE:
692 692 if (rs == AP_RSTATE_DISCONNECTED) {
693 693 if (devctl_ap_connect(dcp, NULL) == -1) {
694 694 rv = CFGA_ERROR;
695 695 cfga_err(errstring, CMD_SLOT_CONNECT, 0);
696 696 break;
697 697 }
698 698 }
699 699
700 700 /*
701 701 * for multi-func device we allow multiple
702 702 * configure on the same slot because one
703 703 * func can be configured and other one won't
704 704 */
705 705 if (devctl_ap_configure(dcp, NULL) == -1) {
706 706 rv = CFGA_ERROR;
707 707 cfga_err(errstring, CMD_SLOT_CONFIGURE, 0);
708 708 if ((rs == AP_RSTATE_DISCONNECTED) &&
709 709 (devctl_ap_disconnect(dcp, NULL)
710 710 == -1)) {
711 711 rv = CFGA_ERROR;
712 712 cfga_err(errstring,
713 713 CMD_SLOT_CONFIGURE, 0);
714 714 }
715 715 break;
716 716 }
717 717
718 718 break;
719 719
720 720 case CFGA_CMD_UNCONFIGURE:
721 721 DBG(1, ("unconfigure\n"));
722 722
723 723 if (os == AP_OSTATE_CONFIGURED) {
724 724 if ((rv = check_rcm(ap_id, &occupants, &rhandle,
725 725 errstring, flags)) == CFGA_BUSY) {
726 726 break;
727 727 } else if (rv == CFGA_OK) {
728 728 if (devctl_ap_unconfigure(dcp, NULL) == -1) {
729 729 if (errno == EBUSY)
730 730 rv = CFGA_BUSY;
731 731 else {
732 732 if (errno == ENOTSUP)
733 733 rv = CFGA_OPNOTSUPP;
734 734 else
735 735 rv = CFGA_ERROR;
736 736 }
737 737 cfga_err(errstring,
738 738 CMD_SLOT_UNCONFIGURE, 0);
739 739 fail_rcm(&occupants, rhandle);
740 740 } else {
741 741 confirm_rcm(&occupants, rhandle);
742 742 }
743 743 } else { /* rv == CFGA_ERROR */
744 744 if (devctl_ap_unconfigure(dcp, NULL) == -1) {
745 745 if (errno == EBUSY)
746 746 rv = CFGA_BUSY;
747 747 else {
748 748 if (errno == ENOTSUP)
749 749 rv = CFGA_OPNOTSUPP;
750 750 else
751 751 rv = CFGA_ERROR;
752 752 }
753 753 cfga_err(errstring,
754 754 CMD_SLOT_UNCONFIGURE, 0);
755 755 } else {
756 756 rv = CFGA_OK;
757 757 }
758 758 }
759 759 } else {
760 760 cfga_err(errstring, ERR_AP_ERR, 0);
761 761 rv = CFGA_INVAL;
762 762 }
763 763
764 764 DBG(1, ("uncofigure rv:(%i)\n", rv));
765 765 break;
766 766
767 767 case CFGA_CMD_LOAD:
768 768 if ((os == AP_OSTATE_UNCONFIGURED) &&
769 769 (rs == AP_RSTATE_DISCONNECTED)) {
770 770 if (devctl_ap_insert(dcp, NULL) == -1) {
771 771 rv = CFGA_ERROR;
772 772 cfga_err(errstring, CMD_SLOT_INSERT, 0);
773 773 }
774 774 } else {
775 775 cfga_err(errstring, ERR_AP_ERR, 0);
776 776 rv = CFGA_INVAL;
777 777 }
778 778
779 779 break;
780 780
781 781 case CFGA_CMD_UNLOAD:
782 782 if ((os == AP_OSTATE_UNCONFIGURED) &&
783 783 (rs == AP_RSTATE_DISCONNECTED)) {
784 784 if (devctl_ap_remove(dcp, NULL) == -1) {
785 785 rv = CFGA_ERROR;
786 786 cfga_err(errstring, CMD_SLOT_REMOVE, 0);
787 787 }
788 788 } else {
789 789 cfga_err(errstring, ERR_AP_ERR, 0);
790 790 rv = CFGA_INVAL;
791 791 }
792 792
793 793 break;
794 794
795 795 default:
796 796 rv = CFGA_OPNOTSUPP;
797 797 break;
798 798 }
799 799
800 800 devctl_release((devctl_hdl_t)dcp);
801 801 return (rv);
802 802 }
803 803
804 804 /*
805 805 * Building iocdatat to pass it to nexus
806 806 *
807 807 * iocdata->cmd == HPC_CTRL_ENABLE_SLOT/HPC_CTRL_DISABLE_SLOT
808 808 * HPC_CTRL_ENABLE_AUTOCFG/HPC_CTRL_DISABLE_AUTOCFG
809 809 * HPC_CTRL_GET_LED_STATE/HPC_CTRL_SET_LED_STATE
810 810 * HPC_CTRL_GET_SLOT_STATE/HPC_CTRL_GET_SLOT_INFO
811 811 * HPC_CTRL_DEV_CONFIGURE/HPC_CTRL_DEV_UNCONFIGURE
812 812 * HPC_CTRL_GET_BOARD_TYPE
813 813 *
814 814 */
815 815 static void
816 816 build_control_data(struct hpc_control_data *iocdata, uint_t cmd,
817 817 void *retdata)
818 818 {
819 819 iocdata->cmd = cmd;
820 820 iocdata->data = retdata;
821 821 }
822 822
823 823 /*
824 824 * building logical name from ap_id
825 825 */
826 826 /*ARGSUSED2*/
827 827 static void
828 828 get_logical_name(const char *ap_id, char *buf, dev_t rdev)
829 829 {
830 830 char *bufptr, *bufptr2, *pci, *apid;
831 831
832 832 DBG(1, ("get_logical_name: %s\n", ap_id));
833 833
834 834 if ((apid = malloc(MAXPATHLEN)) == NULL) {
835 835 DBG(1, ("malloc failed\n"));
836 836 return;
837 837 }
838 838
839 839 (void) memset(apid, 0, MAXPATHLEN);
840 840 (void) strncpy(apid, ap_id, strlen(ap_id));
841 841
842 842 /* needs to look for last /, not first */
843 843 bufptr = strrchr(apid, '/');
844 844
845 845 bufptr2 = strrchr(apid, ':');
846 846 pci = ++bufptr;
847 847 bufptr = strchr(pci, ',');
848 848 if (bufptr != NULL) {
849 849 *bufptr = '\0';
850 850 }
851 851
852 852 bufptr = strchr(pci, '@');
853 853 if (bufptr != NULL) {
854 854 *bufptr = '\0';
855 855 bufptr++;
856 856 }
857 857
858 858 DBG(1, ("%s\n%s\n%s\n", pci, bufptr, bufptr2));
859 859
860 860 (void) strcat(buf, pci);
861 861 (void) strcat(buf, bufptr);
862 862 (void) strcat(buf, bufptr2);
863 863 free(apid);
864 864 }
865 865
866 866 static cfga_err_t
867 867 prt_led_mode(const char *ap_id, int repeat, char **errstring,
868 868 struct cfga_msg *msgp)
869 869 {
870 870 hpc_led_info_t power_led_info = {HPC_POWER_LED, 0};
871 871 hpc_led_info_t fault_led_info = {HPC_FAULT_LED, 0};
872 872 hpc_led_info_t attn_led_info = {HPC_ATTN_LED, 0};
873 873 hpc_led_info_t active_led_info = {HPC_ACTIVE_LED, 0};
874 874 struct hpc_control_data iocdata;
875 875 struct stat statbuf;
876 876 char *buff;
877 877 int fd;
878 878 hpc_slot_info_t slot_info;
879 879 char *cp, line[MAXLINE];
880 880 int len = MAXLINE;
881 881
882 882 DBG(1, ("prt_led_mod function\n"));
883 883 if (!repeat)
884 884 cfga_msg(msgp, "Ap_Id\t\t\tLed");
885 885
886 886 if ((fd = open(ap_id, O_RDWR)) == -1) {
887 887 DBG(2, ("open = ap_id%s, fd%d\n", ap_id, fd));
888 888 DBG_F(2, (stderr, "open on %s failed\n", ap_id));
889 889 cfga_err(errstring, CMD_OPEN, ap_id, 0);
890 890 return (CFGA_ERROR);
891 891 }
892 892
893 893 if (fstat(fd, &statbuf) == -1) {
894 894 DBG(2, ("fstat = ap_id%s, fd%d\n", ap_id, fd));
895 895 DBG_F(2, (stderr, "fstat on %s failed\n", ap_id));
896 896 cfga_err(errstring, CMD_FSTAT, ap_id, 0);
897 897 return (CFGA_ERROR);
898 898 }
899 899
900 900 if ((buff = malloc(MAXPATHLEN)) == NULL) {
901 901 cfga_err(errstring, "malloc ", 0);
902 902 return (CFGA_ERROR);
903 903 }
904 904
905 905 (void) memset(buff, 0, MAXPATHLEN);
906 906
907 907 DBG(1, ("ioctl boardtype\n"));
908 908
909 909 build_control_data(&iocdata, HPC_CTRL_GET_SLOT_INFO,
910 910 (void *)&slot_info);
911 911
912 912 if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
913 913 get_logical_name(ap_id, slot_info.pci_slot_name, 0);
914 914 DBG(1, ("ioctl failed slotinfo: %s\n",
915 915 slot_info.pci_slot_name));
916 916 } else {
917 917
918 918 /*
919 919 * the driver will report back things like hpc0_slot0
920 920 * this needs to be changed to things like pci1:hpc0_slot0
921 921 */
922 922 if (fix_ap_name(buff, ap_id, slot_info.pci_slot_name,
923 923 errstring) != CFGA_OK) {
924 924 free(buff);
925 925 (void) close(fd);
926 926 return (CFGA_ERROR);
927 927 }
928 928 DBG(1, ("ioctl slotinfo: %s\n", buff));
929 929 }
930 930
931 931 cp = line;
932 932 (void) snprintf(cp, len, "%s\t\t", buff);
933 933 len -= strlen(cp);
934 934 cp += strlen(cp);
935 935
936 936 free(buff);
937 937
938 938 build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &power_led_info);
939 939 if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
940 940 (void) snprintf(cp, len, "%s=%s,",
941 941 led_strs[power_led_info.led], cfga_strs[UNKNOWN]);
942 942 len -= strlen(cp);
943 943 cp += strlen(cp);
944 944 } else {
945 945 (void) snprintf(cp, len, "%s=%s,", led_strs[power_led_info.led],
946 946 mode_strs[power_led_info.state]);
947 947 len -= strlen(cp);
948 948 cp += strlen(cp);
949 949 }
950 950
951 951 DBG(1, ("%s:%d\n", led_strs[power_led_info.led], power_led_info.state));
952 952
953 953 build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &fault_led_info);
954 954 if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
955 955 (void) snprintf(cp, len, "%s=%s,",
956 956 led_strs[fault_led_info.led], cfga_strs[UNKNOWN]);
957 957 len -= strlen(cp);
958 958 cp += strlen(cp);
959 959 } else {
960 960 (void) snprintf(cp, len, "%s=%s,",
961 961 led_strs[fault_led_info.led],
962 962 mode_strs[fault_led_info.state]);
963 963 len -= strlen(cp);
964 964 cp += strlen(cp);
965 965 }
966 966 DBG(1, ("%s:%d\n", led_strs[fault_led_info.led], fault_led_info.state));
967 967
968 968 build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &attn_led_info);
969 969 if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
970 970 (void) snprintf(cp, len, "%s=%s,",
971 971 led_strs[attn_led_info.led], cfga_strs[UNKNOWN]);
972 972 len -= strlen(cp);
973 973 cp += strlen(cp);
974 974 } else {
975 975 (void) snprintf(cp, len, "%s=%s,",
976 976 led_strs[attn_led_info.led],
977 977 mode_strs[attn_led_info.state]);
978 978 len -= strlen(cp);
979 979 cp += strlen(cp);
980 980 }
981 981 DBG(1, ("%s:%d\n", led_strs[attn_led_info.led], attn_led_info.state));
982 982
983 983 build_control_data(&iocdata, HPC_CTRL_GET_LED_STATE, &active_led_info);
984 984 if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
985 985 (void) snprintf(cp, len, "%s=%s", led_strs[active_led_info.led],
986 986 cfga_strs[UNKNOWN]);
987 987 } else {
988 988 (void) snprintf(cp, len, "%s=%s",
989 989 led_strs[active_led_info.led],
990 990 mode_strs[active_led_info.state]);
991 991 }
992 992 cfga_msg(msgp, line); /* print the message */
993 993 DBG(1, ("%s:%d\n", led_strs[active_led_info.led],
994 994 active_led_info.state));
995 995
996 996 (void) close(fd);
997 997
998 998 return (CFGA_OK);
999 999 }
1000 1000
1001 1001 /*ARGSUSED*/
1002 1002 cfga_err_t
1003 1003 cfga_private_func(const char *function, const char *ap_id,
1004 1004 const char *options, struct cfga_confirm *confp,
1005 1005 struct cfga_msg *msgp, char **errstring, cfga_flags_t flags)
1006 1006 {
1007 1007 char *str;
1008 1008 int len, fd, i = 0, repeat = 0;
1009 1009 char buf[MAXNAMELEN];
1010 1010 char ptr;
1011 1011 hpc_led_info_t led_info;
1012 1012 struct hpc_control_data iocdata;
1013 1013 cfga_err_t rv;
1014 1014
1015 1015 DBG(1, ("cfgadm_private_func: ap_id:%s\n", ap_id));
1016 1016 DBG(2, (" options: %s\n", (options == NULL)?"null":options));
1017 1017 DBG(2, (" confp: %x\n", confp));
1018 1018 DBG(2, (" cfga_msg: %x\n", cfga_msg));
1019 1019 DBG(2, (" flag: %d\n", flags));
1020 1020
1021 1021 if ((rv = check_options(options)) != CFGA_OK) {
1022 1022 return (rv);
1023 1023 }
1024 1024
1025 1025 if (private_check == confp)
1026 1026 repeat = 1;
1027 1027 else
1028 1028 private_check = (void*)confp;
1029 1029
1030 1030 /* XXX change const 6 to func_str[i] != NULL */
1031 1031 for (i = 0, str = func_strs[i], len = strlen(str); i < 6; i++) {
1032 1032 str = func_strs[i];
1033 1033 len = strlen(str);
1034 1034 if (strncmp(function, str, len) == 0)
1035 1035 break;
1036 1036 }
1037 1037
1038 1038 switch (i) {
1039 1039 case ENABLE_SLOT:
1040 1040 build_control_data(&iocdata,
1041 1041 HPC_CTRL_ENABLE_SLOT, 0);
1042 1042 break;
1043 1043 case DISABLE_SLOT:
1044 1044 build_control_data(&iocdata,
1045 1045 HPC_CTRL_DISABLE_SLOT, 0);
1046 1046 break;
1047 1047 case ENABLE_AUTOCNF:
1048 1048 build_control_data(&iocdata,
1049 1049 HPC_CTRL_ENABLE_AUTOCFG, 0);
1050 1050 break;
1051 1051 case DISABLE_AUTOCNF:
1052 1052 build_control_data(&iocdata,
1053 1053 HPC_CTRL_DISABLE_AUTOCFG, 0);
1054 1054 break;
1055 1055 case LED:
1056 1056 /* set mode */
1057 1057 ptr = function[len++];
1058 1058 if (ptr == '=') {
1059 1059 str = (char *)function;
1060 1060 for (str = (str+len++), i = 0; *str != ',';
1061 1061 i++, str++) {
1062 1062 if (i == (MAXNAMELEN - 1))
1063 1063 break;
1064 1064
1065 1065 buf[i] = *str;
1066 1066 DBG_F(2, (stdout, "%c\n", buf[i]));
1067 1067 }
1068 1068 buf[i] = '\0'; str++;
1069 1069 DBG(2, ("buf = %s\n", buf));
1070 1070
1071 1071 /* ACTIVE=3,ATTN=2,POWER=1,FAULT=0 */
1072 1072 if (strcmp(buf, led_strs[POWER]) == 0)
1073 1073 led_info.led = HPC_POWER_LED;
1074 1074 else if (strcmp(buf, led_strs[FAULT]) == 0)
1075 1075 led_info.led = HPC_FAULT_LED;
↓ open down ↓ |
1075 lines elided |
↑ open up ↑ |
1076 1076 else if (strcmp(buf, led_strs[ATTN]) == 0)
1077 1077 led_info.led = HPC_ATTN_LED;
1078 1078 else if (strcmp(buf, led_strs[ACTIVE]) == 0)
1079 1079 led_info.led = HPC_ACTIVE_LED;
1080 1080 else return (CFGA_INVAL);
1081 1081
1082 1082 len = strlen(func_strs[MODE]);
1083 1083 if ((strncmp(str, func_strs[MODE], len) == 0) &&
1084 1084 (*(str+(len)) == '=')) {
1085 1085 for (str = (str+(++len)), i = 0;
1086 - *str != NULL; i++, str++) {
1086 + *str != '\0'; i++, str++) {
1087 1087 buf[i] = *str;
1088 1088
1089 1089 }
1090 1090 }
1091 1091 buf[i] = '\0';
1092 1092 DBG(2, ("buf_mode= %s\n", buf));
1093 1093
1094 1094 /* ON = 1, OFF = 0 */
1095 1095 if (strcmp(buf, mode_strs[ON]) == 0)
1096 1096 led_info.state = HPC_LED_ON;
1097 1097 else if (strcmp(buf, mode_strs[OFF]) == 0)
1098 1098 led_info.state = HPC_LED_OFF;
1099 1099 else if (strcmp(buf, mode_strs[BLINK]) == 0)
1100 1100 led_info.state = HPC_LED_BLINK;
1101 1101 else return (CFGA_INVAL);
1102 1102
1103 1103 /* sendin */
1104 1104 build_control_data(&iocdata,
1105 1105 HPC_CTRL_SET_LED_STATE,
1106 1106 (void *)&led_info);
1107 1107 break;
1108 1108 } else if (ptr == '\0') {
1109 1109 /* print mode */
1110 1110 DBG(1, ("Print mode\n"));
1111 1111 return (prt_led_mode(ap_id, repeat, errstring,
1112 1112 msgp));
1113 1113 }
1114 1114 default:
1115 1115 DBG(1, ("default\n"));
1116 1116 errno = EINVAL;
1117 1117 return (CFGA_INVAL);
1118 1118 }
1119 1119
1120 1120 if ((fd = open(ap_id, O_RDWR)) == -1) {
1121 1121 DBG(1, ("open failed\n"));
1122 1122 return (CFGA_ERROR);
1123 1123 }
1124 1124
1125 1125 DBG(1, ("open = ap_id=%s, fd=%d\n", ap_id, fd));
1126 1126
1127 1127 if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
1128 1128 DBG(1, ("ioctl failed\n"));
1129 1129 (void) close(fd);
1130 1130 return (CFGA_ERROR);
1131 1131 }
1132 1132
1133 1133 (void) close(fd);
1134 1134
1135 1135 return (CFGA_OK);
1136 1136 }
1137 1137
1138 1138 /*ARGSUSED*/
1139 1139 cfga_err_t cfga_test(const char *ap_id, const char *options,
1140 1140 struct cfga_msg *msgp, char **errstring, cfga_flags_t flags)
1141 1141 {
1142 1142 cfga_err_t rv;
1143 1143 if (errstring != NULL)
1144 1144 *errstring = NULL;
1145 1145
1146 1146 if ((rv = check_options(options)) != CFGA_OK) {
1147 1147 return (rv);
1148 1148 }
1149 1149
1150 1150 DBG(1, ("cfga_test:(%s)\n", ap_id));
1151 1151 /* will need to implement pci CTRL command */
1152 1152 return (CFGA_NOTSUPP);
1153 1153 }
1154 1154
1155 1155 static int
1156 1156 fixup_slotname(int rval, int *intp, struct searcharg *slotarg)
1157 1157 {
1158 1158
1159 1159 /*
1160 1160 * The slot-names property describes the external labeling of add-in slots.
1161 1161 * This property is an encoded array, an integer followed by a list of
1162 1162 * strings. The return value from di_prop_lookup_ints for slot-names is -1.
1163 1163 * The expected return value should be the number of elements.
1164 1164 * Di_prop_decode_common does not decode encoded data from software,
1165 1165 * such as the solaris device tree, unlike from the prom.
1166 1166 * Di_prop_decode_common takes the size of the encoded data and mods
1167 1167 * it with the size of int. The size of the encoded data for slot-names is 9
1168 1168 * and the size of int is 4, yielding a non zero result. A value of -1 is used
1169 1169 * to indicate that the number of elements can not be determined.
1170 1170 * Di_prop_decode_common can be modified to decode encoded data from the solaris
1171 1171 * device tree.
1172 1172 */
1173 1173
1174 1174 if ((slotarg->slt_name_src == PROM_SLT_NAME) && (rval == -1)) {
1175 1175 return (DI_WALK_TERMINATE);
1176 1176 } else {
1177 1177 int i;
1178 1178 char *tmptr = (char *)(intp+1);
1179 1179 DBG(1, ("slot-bitmask: %x \n", *intp));
1180 1180
1181 1181 rval = (rval -1) * 4;
1182 1182
1183 1183 for (i = 0; i <= slotarg->minor; i++) {
1184 1184 DBG(2, ("curr slot-name: %s \n", tmptr));
1185 1185
1186 1186 if (i >= MAXDEVS)
1187 1187 return (DI_WALK_TERMINATE);
1188 1188
1189 1189 if ((*intp >> i) & 1) {
1190 1190 /* assign tmptr */
1191 1191 DBG(2, ("slot-name: %s \n", tmptr));
1192 1192 if (i == slotarg->minor)
1193 1193 (void) strcpy(slotarg->slotnames[i],
1194 1194 tmptr);
1195 1195 /* wind tmptr to next \0 */
1196 1196 while (*tmptr != '\0') {
1197 1197 tmptr++;
1198 1198 }
1199 1199 tmptr++;
1200 1200 } else {
1201 1201 /* point at unknown string */
1202 1202 if (i == slotarg->minor)
1203 1203 (void) strcpy(slotarg->slotnames[i],
1204 1204 "unknown");
1205 1205 }
1206 1206 }
1207 1207 }
1208 1208 return (DI_WALK_TERMINATE);
1209 1209 }
1210 1210
1211 1211 static int
1212 1212 find_slotname(di_node_t din, di_minor_t dim, void *arg)
1213 1213 {
1214 1214 struct searcharg *slotarg = (struct searcharg *)arg;
1215 1215 di_prom_handle_t ph = (di_prom_handle_t)slotarg->promp;
1216 1216 di_prom_prop_t prom_prop;
1217 1217 di_prop_t solaris_prop;
1218 1218 int *intp, rval;
1219 1219 char *devname;
1220 1220 char fulldevname[MAXNAMELEN];
1221 1221
1222 1222 slotarg->minor = dim->dev_minor % 256;
1223 1223
1224 1224 DBG(2, ("minor number:(%i)\n", slotarg->minor));
1225 1225 DBG(2, ("hot plug slots found so far:(%i)\n", 0));
1226 1226
1227 1227 if ((devname = di_devfs_path(din)) != NULL) {
1228 1228 (void) snprintf(fulldevname, MAXNAMELEN,
1229 1229 "/devices%s:%s", devname, di_minor_name(dim));
1230 1230 di_devfs_path_free(devname);
1231 1231 }
1232 1232
1233 1233 if (strcmp(fulldevname, slotarg->devpath) == 0) {
1234 1234
1235 1235 /*
1236 1236 * Check the Solaris device tree first
1237 1237 * in the case of a DR operation
1238 1238 */
1239 1239 solaris_prop = di_prop_hw_next(din, DI_PROP_NIL);
1240 1240 while (solaris_prop != DI_PROP_NIL) {
1241 1241 if (strcmp("slot-names", di_prop_name(solaris_prop))
1242 1242 == 0) {
1243 1243 rval = di_prop_lookup_ints(DDI_DEV_T_ANY,
1244 1244 din, di_prop_name(solaris_prop), &intp);
1245 1245 slotarg->slt_name_src = SOLARIS_SLT_NAME;
1246 1246
1247 1247 return (fixup_slotname(rval, intp, slotarg));
1248 1248 }
1249 1249 solaris_prop = di_prop_hw_next(din, solaris_prop);
1250 1250 }
1251 1251
1252 1252 /*
1253 1253 * Check the prom device tree which is populated at boot.
1254 1254 * If this fails, give up and set the slot name to null.
1255 1255 */
1256 1256 prom_prop = di_prom_prop_next(ph, din, DI_PROM_PROP_NIL);
1257 1257 while (prom_prop != DI_PROM_PROP_NIL) {
1258 1258 if (strcmp("slot-names", di_prom_prop_name(prom_prop))
1259 1259 == 0) {
1260 1260 rval = di_prom_prop_lookup_ints(ph,
1261 1261 din, di_prom_prop_name(prom_prop), &intp);
1262 1262 slotarg->slt_name_src = PROM_SLT_NAME;
1263 1263
1264 1264 return (fixup_slotname(rval, intp, slotarg));
1265 1265 }
1266 1266 prom_prop = di_prom_prop_next(ph, din, prom_prop);
1267 1267 }
1268 1268 *slotarg->slotnames[slotarg->minor] = '\0';
1269 1269 return (DI_WALK_TERMINATE);
1270 1270 } else
1271 1271 return (DI_WALK_CONTINUE);
1272 1272 }
1273 1273
↓ open down ↓ |
177 lines elided |
↑ open up ↑ |
1274 1274 static int
1275 1275 find_physical_slot_names(const char *devcomp, struct searcharg *slotarg)
1276 1276 {
1277 1277 di_node_t root_node;
1278 1278
1279 1279 DBG(1, ("find_physical_slot_names\n"));
1280 1280
1281 1281 if ((root_node = di_init("/", DINFOCPYALL|DINFOPATH))
1282 1282 == DI_NODE_NIL) {
1283 1283 DBG(1, ("di_init() failed\n"));
1284 - return (NULL);
1284 + return (0);
1285 1285 }
1286 1286
1287 1287 slotarg->devpath = (char *)devcomp;
1288 1288
1289 1289 if ((slotarg->promp = di_prom_init()) == DI_PROM_HANDLE_NIL) {
1290 1290 DBG(1, ("di_prom_init() failed\n"));
1291 1291 di_fini(root_node);
1292 - return (NULL);
1292 + return (0);
1293 1293 }
1294 1294
1295 1295 (void) di_walk_minor(root_node, "ddi_ctl:attachment_point:pci",
1296 1296 0, (void *)slotarg, find_slotname);
1297 1297
1298 1298 di_prom_fini(slotarg->promp);
1299 1299 di_fini(root_node);
1300 1300 if (slotarg->slotnames[0] != NULL)
1301 1301 return (0);
1302 1302 else
1303 1303 return (-1);
1304 1304 }
1305 1305
1306 1306 static void
1307 1307 get_type(hpc_board_type_t boardtype, hpc_card_info_t cardinfo, char *buf)
1308 1308 {
1309 1309 int i;
1310 1310
1311 1311 DBG(1, ("class: %i\n", cardinfo.base_class));
1312 1312 DBG(1, ("subclass: %i\n", cardinfo.sub_class));
1313 1313
1314 1314 if (cardinfo.base_class == PCI_CLASS_NONE) {
1315 1315 TPCT("unknown");
1316 1316 return;
1317 1317 }
1318 1318
1319 1319 for (i = 0; i < class_pci_items; i++) {
1320 1320 if ((cardinfo.base_class == class_pci[i].base_class) &&
1321 1321 (cardinfo.sub_class == class_pci[i].sub_class) &&
1322 1322 (cardinfo.prog_class == class_pci[i].prog_class)) {
1323 1323 TPCT(class_pci[i].short_desc);
1324 1324 break;
1325 1325 }
1326 1326 }
1327 1327
1328 1328 if (i == class_pci_items)
1329 1329 TPCT("unknown");
1330 1330
1331 1331 TPCT("/");
1332 1332 switch (boardtype) {
1333 1333 case HPC_BOARD_PCI_HOTPLUG:
1334 1334 case HPC_BOARD_CPCI_NON_HS:
1335 1335 case HPC_BOARD_CPCI_BASIC_HS:
1336 1336 case HPC_BOARD_CPCI_FULL_HS:
1337 1337 case HPC_BOARD_CPCI_HS:
1338 1338 TPCT(board_strs[boardtype]);
1339 1339 break;
1340 1340 case HPC_BOARD_UNKNOWN:
1341 1341 default:
1342 1342 TPCT(board_strs[HPC_BOARD_UNKNOWN]);
1343 1343 }
1344 1344 }
1345 1345
1346 1346 /*
1347 1347 * call-back function for di_devlink_walk
1348 1348 * if the link lives in /dev/cfg copy its name
1349 1349 */
1350 1350 static int
1351 1351 found_devlink(di_devlink_t link, void *ap_log_id)
1352 1352 {
1353 1353 if (strncmp("/dev/cfg/", di_devlink_path(link), 9) == 0) {
1354 1354 /* copy everything but /dev/cfg/ */
1355 1355 (void) strcpy((char *)ap_log_id, di_devlink_path(link) + 9);
1356 1356 DBG(1, ("found_devlink: %s\n", (char *)ap_log_id));
1357 1357 return (DI_WALK_TERMINATE);
1358 1358 }
1359 1359 return (DI_WALK_CONTINUE);
1360 1360 }
1361 1361
1362 1362 /*
1363 1363 * Walk throught the cached /dev link tree looking for links to the ap
1364 1364 * if none are found return an error
1365 1365 */
1366 1366 static cfga_err_t
1367 1367 check_devlinks(char *ap_log_id, const char *ap_id)
1368 1368 {
1369 1369 di_devlink_handle_t hdl;
1370 1370
1371 1371 DBG(1, ("check_devlinks: %s\n", ap_id));
1372 1372
1373 1373 hdl = di_devlink_init(NULL, 0);
1374 1374
1375 1375 if (strncmp("/devices/", ap_id, 9) == 0) {
1376 1376 /* ap_id is a valid minor_path with /devices prepended */
1377 1377 (void) di_devlink_walk(hdl, NULL, ap_id + 8, DI_PRIMARY_LINK,
1378 1378 (void *)ap_log_id, found_devlink);
1379 1379 } else {
1380 1380 DBG(1, ("check_devlinks: invalid ap_id: %s\n", ap_id));
1381 1381 return (CFGA_ERROR);
1382 1382 }
1383 1383
1384 1384 (void) di_devlink_fini(&hdl);
1385 1385
1386 1386 if (ap_log_id[0] != '\0')
1387 1387 return (CFGA_OK);
1388 1388 else
1389 1389 return (CFGA_ERROR);
1390 1390 }
1391 1391
1392 1392 /*
1393 1393 * most of this is needed to compensate for
1394 1394 * differences between various platforms
1395 1395 */
1396 1396 static cfga_err_t
1397 1397 fix_ap_name(char *ap_log_id, const char *ap_id, char *slot_name,
1398 1398 char **errstring)
1399 1399 {
1400 1400 char *buf;
1401 1401 char *tmp;
1402 1402 char *ptr;
1403 1403
1404 1404 di_node_t ap_node;
1405 1405
1406 1406 ap_log_id[0] = '\0';
1407 1407
1408 1408 if (check_devlinks(ap_log_id, ap_id) == CFGA_OK)
1409 1409 return (CFGA_OK);
1410 1410
1411 1411 DBG(1, ("fix_ap_name: %s\n", ap_id));
1412 1412
1413 1413 if ((buf = malloc(strlen(ap_id) + 1)) == NULL) {
1414 1414 DBG(1, ("malloc failed\n"));
1415 1415 return (CFGA_ERROR);
1416 1416 }
1417 1417 (void) strcpy(buf, ap_id);
1418 1418 tmp = buf + sizeof ("/devices") - 1;
1419 1419
1420 1420 ptr = strchr(tmp, ':');
1421 1421 ptr[0] = '\0';
1422 1422
1423 1423 DBG(1, ("fix_ap_name: %s\n", tmp));
1424 1424
1425 1425 ap_node = di_init(tmp, DINFOMINOR);
1426 1426 if (ap_node == DI_NODE_NIL) {
1427 1427 cfga_err(errstring, "di_init ", 0);
1428 1428 DBG(1, ("fix_ap_name: failed to snapshot node\n"));
1429 1429 return (CFGA_ERROR);
1430 1430 }
1431 1431
1432 1432 (void) snprintf(ap_log_id, strlen(ap_id) + 1, "%s%i:%s",
1433 1433 di_driver_name(ap_node), di_instance(ap_node), slot_name);
1434 1434
1435 1435 DBG(1, ("fix_ap_name: %s\n", ap_log_id));
1436 1436
1437 1437 di_fini(ap_node);
1438 1438
1439 1439 free(buf);
1440 1440 return (CFGA_OK);
1441 1441 }
1442 1442
1443 1443
1444 1444 static int
1445 1445 findlink_cb(di_devlink_t devlink, void *arg)
1446 1446 {
1447 1447 (*(char **)arg) = strdup(di_devlink_path(devlink));
1448 1448
1449 1449 return (DI_WALK_TERMINATE);
1450 1450 }
1451 1451
1452 1452 /*
1453 1453 * returns an allocated string containing the full path to the devlink for
1454 1454 * <ap_phys_id> in the devlink database; we expect only one devlink per
1455 1455 * <ap_phys_id> so we return the first encountered
1456 1456 */
1457 1457 static char *
1458 1458 findlink(char *ap_phys_id)
1459 1459 {
1460 1460 di_devlink_handle_t hdl;
1461 1461 char *path = NULL;
1462 1462
1463 1463 hdl = di_devlink_init(NULL, 0);
1464 1464
1465 1465 if (strncmp("/devices/", ap_phys_id, 9) == 0)
1466 1466 ap_phys_id += 8;
1467 1467
1468 1468 (void) di_devlink_walk(hdl, "^cfg/.+$", ap_phys_id, DI_PRIMARY_LINK,
1469 1469 (void *)&path, findlink_cb);
1470 1470
1471 1471 (void) di_devlink_fini(&hdl);
1472 1472 return (path);
1473 1473 }
1474 1474
1475 1475
1476 1476 /*
1477 1477 * returns CFGA_OK if it can succesfully retrieve the devlink info associated
1478 1478 * with devlink for <ap_phys_id> which will be returned through <ap_info>
1479 1479 */
1480 1480 cfga_err_t
1481 1481 get_dli(char *dlpath, char *ap_info, int ap_info_sz)
1482 1482 {
1483 1483 int fd;
1484 1484
1485 1485 fd = di_dli_openr(dlpath);
1486 1486 if (fd < 0)
1487 1487 return (CFGA_ERROR);
1488 1488
1489 1489 (void) read(fd, ap_info, ap_info_sz);
1490 1490 ap_info[ap_info_sz - 1] = '\0';
1491 1491
1492 1492 di_dli_close(fd);
1493 1493 return (CFGA_OK);
1494 1494 }
1495 1495
1496 1496
1497 1497 /*ARGSUSED*/
1498 1498 cfga_err_t
1499 1499 cfga_list_ext(const char *ap_id, cfga_list_data_t **cs,
1500 1500 int *nlist, const char *options, const char *listopts, char **errstring,
1501 1501 cfga_flags_t flags)
1502 1502 {
1503 1503 devctl_hdl_t dcp;
1504 1504 struct hpc_control_data iocdata;
1505 1505 devctl_ap_state_t state;
1506 1506 hpc_board_type_t boardtype;
1507 1507 hpc_card_info_t cardinfo;
1508 1508 hpc_slot_info_t slot_info;
1509 1509 struct searcharg slotname_arg;
1510 1510 int fd;
1511 1511 int rv = CFGA_OK;
1512 1512 char *dlpath = NULL;
1513 1513
1514 1514 if ((rv = check_options(options)) != CFGA_OK) {
1515 1515 return (rv);
1516 1516 }
1517 1517
1518 1518 if (errstring != NULL)
1519 1519 *errstring = NULL;
1520 1520
1521 1521 (void) memset(&slot_info, 0, sizeof (hpc_slot_info_t));
1522 1522
1523 1523 DBG(1, ("cfga_list_ext:(%s)\n", ap_id));
1524 1524
1525 1525 if (cs == NULL || nlist == NULL) {
1526 1526 rv = CFGA_ERROR;
1527 1527 return (rv);
1528 1528 }
1529 1529
1530 1530 *nlist = 1;
1531 1531
1532 1532 if ((*cs = malloc(sizeof (cfga_list_data_t))) == NULL) {
1533 1533 cfga_err(errstring, "malloc ", 0);
1534 1534 DBG(1, ("malloc failed\n"));
1535 1535 rv = CFGA_ERROR;
1536 1536 return (rv);
1537 1537 }
1538 1538 (void) memset(*cs, 0, sizeof (cfga_list_data_t));
1539 1539
1540 1540 if ((dcp = devctl_ap_acquire((char *)ap_id, 0)) == NULL) {
1541 1541 cfga_err(errstring, CMD_GETSTAT, 0);
1542 1542 DBG(2, ("cfga_list_ext::(devctl_ap_acquire())\n"));
1543 1543 rv = CFGA_ERROR;
1544 1544 return (rv);
1545 1545 }
1546 1546
1547 1547 if (devctl_ap_getstate(dcp, NULL, &state) == -1) {
1548 1548 cfga_err(errstring, ERR_AP_ERR, ap_id, 0);
1549 1549 devctl_release((devctl_hdl_t)dcp);
1550 1550 DBG(2, ("cfga_list_ext::(devctl_ap_getstate())\n"));
1551 1551 rv = CFGA_ERROR;
1552 1552 return (rv);
1553 1553 }
1554 1554
1555 1555 switch (state.ap_rstate) {
1556 1556 case AP_RSTATE_EMPTY:
1557 1557 (*cs)->ap_r_state = CFGA_STAT_EMPTY;
1558 1558 DBG(2, ("ap_rstate = CFGA_STAT_EMPTY\n"));
1559 1559 break;
1560 1560 case AP_RSTATE_DISCONNECTED:
1561 1561 (*cs)->ap_r_state = CFGA_STAT_DISCONNECTED;
1562 1562 DBG(2, ("ap_rstate = CFGA_STAT_DISCONNECTED\n"));
1563 1563 break;
1564 1564 case AP_RSTATE_CONNECTED:
1565 1565 (*cs)->ap_r_state = CFGA_STAT_CONNECTED;
1566 1566 DBG(2, ("ap_rstate = CFGA_STAT_CONNECTED\n"));
1567 1567 break;
1568 1568 default:
1569 1569 cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
1570 1570 rv = CFGA_ERROR;
1571 1571 devctl_release((devctl_hdl_t)dcp);
1572 1572 return (rv);
1573 1573 }
1574 1574
1575 1575 switch (state.ap_ostate) {
1576 1576 case AP_OSTATE_CONFIGURED:
1577 1577 (*cs)->ap_o_state = CFGA_STAT_CONFIGURED;
1578 1578 DBG(2, ("ap_ostate = CFGA_STAT_CONFIGURED\n"));
1579 1579 break;
1580 1580 case AP_OSTATE_UNCONFIGURED:
1581 1581 (*cs)->ap_o_state = CFGA_STAT_UNCONFIGURED;
1582 1582 DBG(2, ("ap_ostate = CFGA_STAT_UNCONFIGURED\n"));
1583 1583 break;
1584 1584 default:
1585 1585 cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
1586 1586 rv = CFGA_ERROR;
1587 1587 devctl_release((devctl_hdl_t)dcp);
1588 1588 return (rv);
1589 1589 }
1590 1590
1591 1591 switch (state.ap_condition) {
1592 1592 case AP_COND_OK:
1593 1593 (*cs)->ap_cond = CFGA_COND_OK;
1594 1594 DBG(2, ("ap_cond = CFGA_COND_OK\n"));
1595 1595 break;
1596 1596 case AP_COND_FAILING:
1597 1597 (*cs)->ap_cond = CFGA_COND_FAILING;
1598 1598 DBG(2, ("ap_cond = CFGA_COND_FAILING\n"));
1599 1599 break;
1600 1600 case AP_COND_FAILED:
1601 1601 (*cs)->ap_cond = CFGA_COND_FAILED;
1602 1602 DBG(2, ("ap_cond = CFGA_COND_FAILED\n"));
1603 1603 break;
1604 1604 case AP_COND_UNUSABLE:
1605 1605 (*cs)->ap_cond = CFGA_COND_UNUSABLE;
1606 1606 DBG(2, ("ap_cond = CFGA_COND_UNUSABLE\n"));
1607 1607 break;
1608 1608 case AP_COND_UNKNOWN:
1609 1609 (*cs)->ap_cond = CFGA_COND_UNKNOWN;
1610 1610 DBG(2, ("ap_cond = CFGA_COND_UNKNOW\n"));
1611 1611 break;
1612 1612 default:
1613 1613 cfga_err(errstring, CMD_GETSTAT, ap_id, 0);
1614 1614 rv = CFGA_ERROR;
1615 1615 devctl_release((devctl_hdl_t)dcp);
1616 1616 return (rv);
1617 1617 }
1618 1618 (*cs)->ap_busy = (int)state.ap_in_transition;
1619 1619
1620 1620 devctl_release((devctl_hdl_t)dcp);
1621 1621
1622 1622 if ((fd = open(ap_id, O_RDWR)) == -1) {
1623 1623 cfga_err(errstring, ERR_AP_ERR, ap_id, 0);
1624 1624 (*cs)->ap_status_time = 0;
1625 1625 boardtype = HPC_BOARD_UNKNOWN;
1626 1626 cardinfo.base_class = PCI_CLASS_NONE;
1627 1627 get_logical_name(ap_id, slot_info.pci_slot_name, 0);
1628 1628 DBG(2, ("open on %s failed\n", ap_id));
1629 1629 goto cont;
1630 1630 }
1631 1631 DBG(1, ("open = ap_id=%s, fd=%d\n", ap_id, fd));
1632 1632
1633 1633 (*cs)->ap_status_time = state.ap_last_change;
1634 1634
1635 1635 /* need board type and a way to get to hpc_slot_info */
1636 1636 build_control_data(&iocdata, HPC_CTRL_GET_BOARD_TYPE,
1637 1637 (void *)&boardtype);
1638 1638
1639 1639 if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
1640 1640 boardtype = HPC_BOARD_UNKNOWN;
1641 1641 }
1642 1642 DBG(1, ("ioctl boardtype\n"));
1643 1643
1644 1644 build_control_data(&iocdata, HPC_CTRL_GET_SLOT_INFO,
1645 1645 (void *)&slot_info);
1646 1646
1647 1647 if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
1648 1648 get_logical_name(ap_id, slot_info.pci_slot_name, 0);
1649 1649 DBG(1, ("ioctl failed slotinfo: %s\n",
1650 1650 slot_info.pci_slot_name));
1651 1651 } else {
1652 1652
1653 1653 /*
1654 1654 * the driver will report back things like hpc0_slot0
1655 1655 * this needs to be changed to things like pci1:hpc0_slot0
1656 1656 */
1657 1657 rv = fix_ap_name((*cs)->ap_log_id,
1658 1658 ap_id, slot_info.pci_slot_name, errstring);
1659 1659 DBG(1, ("ioctl slotinfo: %s\n", (*cs)->ap_log_id));
1660 1660 }
1661 1661
1662 1662 build_control_data(&iocdata, HPC_CTRL_GET_CARD_INFO,
1663 1663 (void *)&cardinfo);
1664 1664
1665 1665 if (ioctl(fd, DEVCTL_AP_CONTROL, &iocdata) == -1) {
1666 1666 DBG(1, ("ioctl failed\n"));
1667 1667 cardinfo.base_class = PCI_CLASS_NONE;
1668 1668 }
1669 1669
1670 1670 DBG(1, ("ioctl cardinfo: %d\n", cardinfo.base_class));
1671 1671 DBG(1, ("ioctl subclass: %d\n", cardinfo.sub_class));
1672 1672 DBG(1, ("ioctl headertype: %d\n", cardinfo.header_type));
1673 1673
1674 1674 (void) close(fd);
1675 1675
1676 1676 cont:
1677 1677 (void) strcpy((*cs)->ap_phys_id, ap_id); /* physical path of AP */
1678 1678
1679 1679 dlpath = findlink((*cs)->ap_phys_id);
1680 1680 if (dlpath != NULL) {
1681 1681 if (get_dli(dlpath, (*cs)->ap_info,
1682 1682 sizeof ((*cs)->ap_info)) != CFGA_OK)
1683 1683 (*cs)->ap_info[0] = '\0';
1684 1684 free(dlpath);
1685 1685 }
1686 1686
1687 1687 if ((*cs)->ap_log_id[0] == '\0')
1688 1688 (void) strcpy((*cs)->ap_log_id, slot_info.pci_slot_name);
1689 1689
1690 1690 if ((*cs)->ap_info[0] == '\0') {
1691 1691 /* slot_names of bus node */
1692 1692 if (find_physical_slot_names(ap_id, &slotname_arg) != -1)
1693 1693 (void) strcpy((*cs)->ap_info,
1694 1694 slotname_arg.slotnames[slotname_arg.minor]);
1695 1695 }
1696 1696
1697 1697 /* class_code/subclass/boardtype */
1698 1698 get_type(boardtype, cardinfo, (*cs)->ap_type);
1699 1699
1700 1700 DBG(1, ("cfga_list_ext return success\n"));
1701 1701 rv = CFGA_OK;
1702 1702
1703 1703 return (rv);
1704 1704 }
1705 1705
1706 1706 /*
1707 1707 * This routine prints a single line of help message
1708 1708 */
1709 1709 static void
1710 1710 cfga_msg(struct cfga_msg *msgp, const char *str)
1711 1711 {
1712 1712 DBG(2, ("<%s>", str));
1713 1713
1714 1714 if (msgp == NULL || msgp->message_routine == NULL)
1715 1715 return;
1716 1716
1717 1717 (*msgp->message_routine)(msgp->appdata_ptr, str);
1718 1718 (*msgp->message_routine)(msgp->appdata_ptr, "\n");
1719 1719 }
1720 1720
1721 1721 static cfga_err_t
1722 1722 check_options(const char *options)
1723 1723 {
1724 1724 struct cfga_msg *msgp = NULL;
1725 1725
1726 1726 if (options) {
1727 1727 cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_UNKNOWN]));
1728 1728 cfga_msg(msgp, options);
1729 1729 return (CFGA_INVAL);
1730 1730 }
1731 1731 return (CFGA_OK);
1732 1732 }
1733 1733
1734 1734 /*ARGSUSED*/
1735 1735 cfga_err_t
1736 1736 cfga_help(struct cfga_msg *msgp, const char *options, cfga_flags_t flags)
1737 1737 {
1738 1738 if (options) {
1739 1739 cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_UNKNOWN]));
1740 1740 cfga_msg(msgp, options);
1741 1741 }
1742 1742 DBG(1, ("cfga_help\n"));
1743 1743
1744 1744 cfga_msg(msgp, dgettext(TEXT_DOMAIN, cfga_strs[HELP_HEADER]));
1745 1745 cfga_msg(msgp, cfga_strs[HELP_CONFIG]);
1746 1746 cfga_msg(msgp, cfga_strs[HELP_ENABLE_SLOT]);
1747 1747 cfga_msg(msgp, cfga_strs[HELP_DISABLE_SLOT]);
1748 1748 cfga_msg(msgp, cfga_strs[HELP_ENABLE_AUTOCONF]);
1749 1749 cfga_msg(msgp, cfga_strs[HELP_DISABLE_AUTOCONF]);
1750 1750 cfga_msg(msgp, cfga_strs[HELP_LED_CNTRL]);
1751 1751 return (CFGA_OK);
1752 1752 }
1753 1753
1754 1754 /*
1755 1755 * cfga_err() accepts a variable number of message IDs and constructs
1756 1756 * a corresponding error string which is returned via the errstring argument.
1757 1757 * cfga_err() calls gettext() to internationalize proper messages.
1758 1758 */
1759 1759 static void
1760 1760 cfga_err(char **errstring, ...)
1761 1761 {
1762 1762 int a;
1763 1763 int i;
1764 1764 int n;
1765 1765 int len;
1766 1766 int flen;
1767 1767 char *p;
1768 1768 char *q;
1769 1769 char *s[32];
1770 1770 char *failed;
1771 1771 va_list ap;
1772 1772
1773 1773 /*
1774 1774 * If errstring is null it means user in not interested in getting
1775 1775 * error status. So we don't do all the work
1776 1776 */
1777 1777 if (errstring == NULL) {
1778 1778 return;
1779 1779 }
1780 1780 va_start(ap, errstring);
1781 1781
1782 1782 failed = dgettext(TEXT_DOMAIN, cfga_strs[FAILED]);
1783 1783 flen = strlen(failed);
1784 1784
1785 1785 for (n = len = 0; (a = va_arg(ap, int)) != 0; n++) {
1786 1786 switch (a) {
1787 1787 case CMD_GETSTAT:
1788 1788 case CMD_LIST:
1789 1789 case CMD_SLOT_CONNECT:
1790 1790 case CMD_SLOT_DISCONNECT:
1791 1791 case CMD_SLOT_CONFIGURE:
1792 1792 case CMD_SLOT_UNCONFIGURE:
1793 1793 p = cfga_errstrs(a);
1794 1794 len += (strlen(p) + flen);
1795 1795 s[n] = p;
1796 1796 s[++n] = cfga_strs[FAILED];
1797 1797
1798 1798 DBG(2, ("<%s>", p));
1799 1799 DBG(2, (cfga_strs[FAILED]));
1800 1800 break;
1801 1801
1802 1802 case ERR_CMD_INVAL:
1803 1803 case ERR_AP_INVAL:
1804 1804 case ERR_OPT_INVAL:
1805 1805 case ERR_AP_ERR:
1806 1806 switch (a) {
1807 1807 case ERR_CMD_INVAL:
1808 1808 p = dgettext(TEXT_DOMAIN,
1809 1809 cfga_errstrs[ERR_CMD_INVAL]);
1810 1810 break;
1811 1811 case ERR_AP_INVAL:
1812 1812 p = dgettext(TEXT_DOMAIN,
1813 1813 cfga_errstrs[ERR_AP_INVAL]);
1814 1814 break;
1815 1815 case ERR_OPT_INVAL:
1816 1816 p = dgettext(TEXT_DOMAIN,
1817 1817 cfga_errstrs[ERR_OPT_INVAL]);
1818 1818 break;
1819 1819 case ERR_AP_ERR:
1820 1820 p = dgettext(TEXT_DOMAIN,
1821 1821 cfga_errstrs[ERR_AP_ERR]);
1822 1822 break;
1823 1823 }
1824 1824
1825 1825 if ((q = va_arg(ap, char *)) != NULL) {
1826 1826 len += (strlen(p) + strlen(q));
1827 1827 s[n] = p;
1828 1828 s[++n] = q;
1829 1829 DBG(2, ("<%s>", p));
1830 1830 DBG(2, ("<%s>", q));
1831 1831 break;
1832 1832 } else {
1833 1833 len += strlen(p);
1834 1834 s[n] = p;
1835 1835
1836 1836 }
1837 1837 DBG(2, ("<%s>", p));
1838 1838 break;
1839 1839
1840 1840 default:
1841 1841 n--;
1842 1842 break;
1843 1843 }
1844 1844 }
1845 1845
1846 1846 DBG(2, ("\n"));
1847 1847 va_end(ap);
1848 1848
1849 1849 if ((p = calloc(len + 1, 1)) == NULL)
1850 1850 return;
1851 1851
1852 1852 for (i = 0; i < n; i++) {
1853 1853 (void) strlcat(p, s[i], len + 1);
1854 1854 DBG(2, ("i:%d, %s\n", i, s[i]));
1855 1855 }
1856 1856
1857 1857 *errstring = p;
1858 1858 #ifdef DEBUG
1859 1859 printf("%s\n", *errstring);
1860 1860 free(*errstring);
1861 1861 #endif
1862 1862 }
1863 1863
1864 1864 /*
1865 1865 * cfga_ap_id_cmp -- use default_ap_id_cmp() in libcfgadm
1866 1866 */
↓ open down ↓ |
564 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX