204 }
205 }
206 }
207 break;
208 }
209 if (rlabel != NULL) {
210 topo_mod_dprintf(mod, "%s: match found, label=%s\n",
211 __func__, rlabel);
212 }
213 return (rlabel);
214 }
215
216 /*
217 * Do an overall slot label lookup for the device node.
218 */
219 char *
220 pci_slot_label_lookup(topo_mod_t *mod, tnode_t *node, did_t *dp, did_t *pdp)
221 {
222 tnode_t *anode, *apnode;
223 did_t *adp, *apdp;
224 char *plat, *pp, *l, *ancestor_l = NULL, *new_l = NULL;
225 int err, b, d, f, done = 0;
226 size_t len;
227
228 did_BDF(dp, &b, &d, &f);
229
230 topo_mod_dprintf(mod, "%s: entry: node=%p, node_name=%s, "
231 "node_inst=%d, dp=%p, dp_bdf=%d/%d/%d, pdp=%p\n",
232 __func__, node, topo_node_name(node), topo_node_instance(node),
233 dp, b, d, f, pdp);
234
235 /*
236 * If this device has a physical slot number then check if
237 * an ancestor also has a slot label.
238 *
239 * If an ancestor has a slot label, then this node's label
240 * is generated by concatenating a default label onto the
241 * ancestor's label.
242 *
243 * We grab pairs of ancestors (parent and child) as we go up
244 * the tree because the parent is checked for the presence
335 }
336 if (ancestor_l == NULL) {
337 topo_mod_dprintf(mod, "%s: node=%p: no ancestor "
338 "slot found\n", __func__, node);
339 }
340 }
341
342 /*
343 * If we found an ancestor with a slot label, and this node has
344 * a physical slot number label then concatenate the two to form
345 * this node's label. Otherwise, do a full slot label lookup.
346 */
347 if (ancestor_l && l) {
348 topo_mod_dprintf(mod, "%s: node=%p: concatenating "
349 "ancestor_l=%s and l=%s\n",
350 __func__, node, ancestor_l, l);
351 len = strlen(ancestor_l) + strlen(l) + 2;
352 new_l = alloca(len);
353 (void) snprintf(new_l, len, "%s/%s", ancestor_l, l);
354 l = new_l;
355 } else {
356 /*
357 * Get platform name used for lookups.
358 */
359 if (topo_prop_get_string(node, FM_FMRI_AUTHORITY,
360 FM_FMRI_AUTH_PRODUCT, &plat, &err) < 0) {
361 (void) topo_mod_seterrno(mod, err);
362 return (NULL);
363 }
364 /*
365 * Trim SUNW, from the platform name
366 */
367 pp = strchr(plat, ',');
368 if (pp == NULL)
369 pp = plat;
370 else
371 ++pp;
372 /*
373 * Get device number used for lookup.
374 */
375 did_BDF(dp, NULL, &d, NULL);
376
377 /*
378 * The slot label is determined in the following order:
379 * - Platform specific lookup based on physical slot #.
380 * - Platform specific lookup based on default label string.
381 * - Platform specific lookup based on device number.
382 * - Default label.
383 * The default label is based on the slot names property
384 * if it exists, else it is a generic name derived from
385 * the slot #.
386 */
387 if ((l = (char *)pci_label_physlot_lookup(mod, pp, pdp))
388 == NULL) {
389 if ((l = (char *)did_physlot_name(pdp, d)) != NULL) {
390 l = (char *)
391 pci_label_slotname_lookup(mod, pp, l, dp);
392 }
393 if (l == NULL) {
394 l = (char *)
395 pci_label_missing_lookup(mod, pp, dp);
396 }
397 }
398 topo_mod_strfree(mod, plat);
399 }
400
401 /*
402 * If we calculated a slot label, then save it in the
403 * node's data structure so we can free it later.
404 */
405 if (l) {
406 if (did_slot_label_get(dp) != NULL)
407 topo_mod_strfree(mod, did_slot_label_get(dp));
408 l = topo_mod_strdup(mod, l);
409 did_slot_label_set(dp, l);
410 }
411
412 topo_mod_dprintf(mod, "%s: exit: node=%p: label=%s\n",
413 __func__, node, (l ? l : "NULL"));
414
415 return (l);
416 }
417
418 int
419 pci_label_cmn(topo_mod_t *mod, tnode_t *node, nvlist_t *in, nvlist_t **out)
420 {
|
204 }
205 }
206 }
207 break;
208 }
209 if (rlabel != NULL) {
210 topo_mod_dprintf(mod, "%s: match found, label=%s\n",
211 __func__, rlabel);
212 }
213 return (rlabel);
214 }
215
216 /*
217 * Do an overall slot label lookup for the device node.
218 */
219 char *
220 pci_slot_label_lookup(topo_mod_t *mod, tnode_t *node, did_t *dp, did_t *pdp)
221 {
222 tnode_t *anode, *apnode;
223 did_t *adp, *apdp;
224 char *plat, *pp, *l = NULL, *ancestor_l = NULL, *new_l = NULL;
225 int err, b, d, f, done = 0;
226 size_t len;
227
228 did_BDF(dp, &b, &d, &f);
229
230 topo_mod_dprintf(mod, "%s: entry: node=%p, node_name=%s, "
231 "node_inst=%d, dp=%p, dp_bdf=%d/%d/%d, pdp=%p\n",
232 __func__, node, topo_node_name(node), topo_node_instance(node),
233 dp, b, d, f, pdp);
234
235 /*
236 * If this device has a physical slot number then check if
237 * an ancestor also has a slot label.
238 *
239 * If an ancestor has a slot label, then this node's label
240 * is generated by concatenating a default label onto the
241 * ancestor's label.
242 *
243 * We grab pairs of ancestors (parent and child) as we go up
244 * the tree because the parent is checked for the presence
335 }
336 if (ancestor_l == NULL) {
337 topo_mod_dprintf(mod, "%s: node=%p: no ancestor "
338 "slot found\n", __func__, node);
339 }
340 }
341
342 /*
343 * If we found an ancestor with a slot label, and this node has
344 * a physical slot number label then concatenate the two to form
345 * this node's label. Otherwise, do a full slot label lookup.
346 */
347 if (ancestor_l && l) {
348 topo_mod_dprintf(mod, "%s: node=%p: concatenating "
349 "ancestor_l=%s and l=%s\n",
350 __func__, node, ancestor_l, l);
351 len = strlen(ancestor_l) + strlen(l) + 2;
352 new_l = alloca(len);
353 (void) snprintf(new_l, len, "%s/%s", ancestor_l, l);
354 l = new_l;
355 } else if (topo_prop_get_string(node, FM_FMRI_AUTHORITY,
356 FM_FMRI_AUTH_PRODUCT, &plat, &err) == 0) {
357 /*
358 * Trim SUNW, from the platform name
359 */
360 pp = strchr(plat, ',');
361 if (pp == NULL)
362 pp = plat;
363 else
364 ++pp;
365 /*
366 * Get device number used for lookup.
367 */
368 did_BDF(dp, NULL, &d, NULL);
369
370 /*
371 * The slot label is determined in the following order:
372 * - Platform specific lookup based on physical slot #.
373 * - Platform specific lookup based on default label string.
374 * - Platform specific lookup based on device number.
375 * - Default label.
376 * The default label is based on the slot names property
377 * if it exists, else it is a generic name derived from
378 * the slot #.
379 */
380 if ((l = (char *)pci_label_physlot_lookup(mod, pp, pdp))
381 == NULL) {
382 if ((l = (char *)did_physlot_name(pdp, d)) != NULL) {
383 l = (char *)
384 pci_label_slotname_lookup(mod, pp, l, dp);
385 }
386 if (l == NULL) {
387 l = (char *)
388 pci_label_missing_lookup(mod, pp, dp);
389 }
390 }
391 topo_mod_strfree(mod, plat);
392 } else {
393 (void) topo_mod_seterrno(mod, err);
394 l = NULL;
395 }
396
397 topo_mod_strfree(mod, ancestor_l);
398
399 /*
400 * If we calculated a slot label, then save it in the
401 * node's data structure so we can free it later.
402 */
403 if (l) {
404 if (did_slot_label_get(dp) != NULL)
405 topo_mod_strfree(mod, did_slot_label_get(dp));
406 l = topo_mod_strdup(mod, l);
407 did_slot_label_set(dp, l);
408 }
409
410 topo_mod_dprintf(mod, "%s: exit: node=%p: label=%s\n",
411 __func__, node, (l ? l : "NULL"));
412
413 return (l);
414 }
415
416 int
417 pci_label_cmn(topo_mod_t *mod, tnode_t *node, nvlist_t *in, nvlist_t **out)
418 {
|