Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/hotplug/pcihp/pcihp.c
+++ new/usr/src/uts/common/io/hotplug/pcihp/pcihp.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 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /*
27 27 * **********************************************************************
28 28 * Extension module for PCI nexus drivers to support PCI Hot Plug feature.
29 29 *
30 30 * DESCRIPTION:
31 31 * This module basically implements "devctl" and Attachment Point device
32 32 * nodes for hot plug operations. The cb_ops functions needed for access
33 33 * to these device nodes are also implemented. For hotplug operations
34 34 * on Attachment Points it interacts with the hotplug services (HPS)
35 35 * framework. A pci nexus driver would simply call pcihp_init() in its
36 36 * attach() function and pcihp_uninit() call in its detach() function.
37 37 * **********************************************************************
38 38 */
39 39
40 40 #include <sys/conf.h>
41 41 #include <sys/kmem.h>
42 42 #include <sys/debug.h>
43 43 #include <sys/modctl.h>
44 44 #include <sys/autoconf.h>
45 45 #include <sys/ddi.h>
46 46 #include <sys/sunddi.h>
47 47 #include <sys/sunndi.h>
48 48 #include <sys/ddi_impldefs.h>
49 49 #include <sys/ndi_impldefs.h>
50 50 #include <sys/ddipropdefs.h>
51 51 #include <sys/open.h>
52 52 #include <sys/file.h>
53 53 #include <sys/stat.h>
54 54 #include <sys/pci.h>
55 55 #include <sys/pci_impl.h>
56 56 #include <sys/devctl.h>
57 57 #include <sys/hotplug/hpcsvc.h>
58 58 #include <sys/hotplug/pci/pcicfg.h>
59 59 #include <sys/hotplug/pci/pcihp.h>
60 60 #include <sys/sysevent.h>
61 61 #include <sys/sysevent/eventdefs.h>
62 62 #include <sys/sysevent/dr.h>
63 63 #include <sys/fs/dv_node.h>
64 64
65 65 /*
66 66 * NOTE:
67 67 * This module depends on PCI Configurator module (misc/pcicfg),
68 68 * Hot Plug Services framework module (misc/hpcsvc) and Bus Resource
69 69 * Allocator module (misc/busra).
70 70 */
71 71
72 72 /*
73 73 * ************************************************************************
74 74 * *** Implementation specific data structures/definitions. ***
75 75 * ************************************************************************
76 76 */
77 77
78 78 /* soft state */
79 79 typedef enum { PCIHP_SOFT_STATE_CLOSED, PCIHP_SOFT_STATE_OPEN,
80 80 PCIHP_SOFT_STATE_OPEN_EXCL } pcihp_soft_state_t;
81 81
82 82 #define PCI_MAX_DEVS 32 /* max. number of devices on a pci bus */
83 83
84 84 /* the following correspond to sysevent defined subclasses */
85 85 #define PCIHP_DR_AP_STATE_CHANGE 0
86 86 #define PCIHP_DR_REQ 1
87 87
88 88 /* pcihp_get_soft_state() command argument */
89 89 #define PCIHP_DR_NOOP 0
90 90 #define PCIHP_DR_BUS_CONFIGURE 1
91 91 #define PCIHP_DR_BUS_UNCONFIGURE 2
92 92 #define PCIHP_DR_SLOT_ENTER 4
93 93 #define PCIHP_DR_SLOT_EXIT 8
94 94
95 95 /* hot plug bus state */
96 96 enum { PCIHP_BUS_INITIALIZING, PCIHP_BUS_UNCONFIGURED,
97 97 PCIHP_BUS_CONFIGURED };
98 98
99 99 /*
100 100 * Soft state structure associated with each hot plug pci bus instance.
101 101 */
102 102 typedef struct pcihp {
103 103 struct pcihp *nextp;
104 104
105 105 /* devinfo pointer to the pci bus node */
106 106 dev_info_t *dip;
107 107
108 108 /* soft state flags: PCIHP_SOFT_STATE_* */
109 109 pcihp_soft_state_t soft_state;
110 110
111 111 /* global mutex to serialize exclusive access to the bus */
112 112 kmutex_t mutex;
113 113
114 114 /* slot information structure */
115 115 struct pcihp_slotinfo {
116 116 hpc_slot_t slot_hdl; /* HPS slot handle */
117 117 ap_rstate_t rstate; /* state of Receptacle */
118 118 ap_ostate_t ostate; /* state of the Occupant */
119 119 ap_condition_t condition; /* condition of the occupant */
120 120 time32_t last_change; /* XXX needed? */
121 121 uint32_t event_mask; /* last event mask registered */
122 122 char *name; /* slot logical name */
123 123 uint_t slot_flags;
124 124 uint16_t slot_type; /* slot type: pci or cpci */
125 125 uint16_t slot_capabilities; /* 64bit, etc. */
126 126 int hs_csr_location; /* Location of HS_CSR */
127 127 kmutex_t slot_mutex; /* mutex to serialize hotplug */
128 128 /* operations on the slot */
129 129 } slotinfo[PCI_MAX_DEVS];
130 130
131 131 /* misc. bus attributes */
132 132 uint_t bus_flags;
133 133 uint_t bus_state;
134 134 uint_t slots_active;
135 135 } pcihp_t;
136 136
137 137 /*
138 138 * Bit definitions for slot_flags field:
139 139 *
140 140 * PCIHP_SLOT_AUTO_CFG_EN This flags is set if nexus can do auto
141 141 * configuration of hot plugged card on this slot
142 142 * if the hardware reports the hot plug events.
143 143 *
144 144 * PCIHP_SLOT_DISABLED Slot is disabled for hotplug operations.
145 145 *
146 146 * PCIHP_SLOT_NOT_HEALTHY HEALTHY# signal is not OK on this slot.
147 147 */
148 148 #define PCIHP_SLOT_AUTO_CFG_EN 0x1
149 149 #define PCIHP_SLOT_DISABLED 0x2
150 150 #define PCIHP_SLOT_NOT_HEALTHY 0x4
151 151 #define PCIHP_SLOT_DEV_NON_HOTPLUG 0x8
152 152 #define PCIHP_SLOT_ENUM_INS_PENDING 0x10
153 153 #define PCIHP_SLOT_ENUM_EXT_PENDING 0x20
154 154
155 155 /*
156 156 * Bit definitions for bus_flags field:
157 157 *
158 158 * PCIHP_BUS_66MHZ Bus is running at 66Mhz.
159 159 */
160 160 #define PCIHP_BUS_66MHZ 0x1
161 161 #define PCIHP_BUS_ENUM_RADIAL 0x2
162 162
163 163 #define PCIHP_DEVICES_STR "/devices"
164 164
165 165 /*
166 166 * control structure for tree walk during configure/unconfigure operation.
167 167 */
168 168 struct pcihp_config_ctrl {
169 169 int pci_dev; /* PCI device number for the slot */
170 170 uint_t flags; /* control flags (see below) */
171 171 int op; /* operation: PCIHP_ONLINE or PCIHP_OFFLINE */
172 172 int rv; /* return error code */
173 173 dev_info_t *dip; /* dip at which the (first) error occurred */
174 174 hpc_occupant_info_t *occupant;
175 175 };
176 176
177 177 /*
178 178 * control flags for configure/unconfigure operations on the tree.
179 179 *
180 180 * PCIHP_CFG_CONTINUE continue the operation ignoring errors
181 181 */
182 182 #define PCIHP_CFG_CONTINUE 0x1
183 183
184 184 #define PCIHP_ONLINE 1
185 185 #define PCIHP_OFFLINE 0
186 186
187 187
188 188 /* Leaf ops (hotplug controls for target devices) */
189 189 static int pcihp_open(dev_t *, int, int, cred_t *);
190 190 static int pcihp_close(dev_t, int, int, cred_t *);
191 191 static int pcihp_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
192 192
193 193 #ifdef DEBUG
194 194 static int pcihp_debug = 0;
195 195 #define PCIHP_DEBUG(args) if (pcihp_debug >= 1) cmn_err args
196 196 #define PCIHP_DEBUG2(args) if (pcihp_debug >= 2) cmn_err args
197 197 #else
198 198 #define PCIHP_DEBUG(args)
199 199 #define PCIHP_DEBUG2(args)
200 200 #endif
201 201
202 202 /*
203 203 * We process ENUM# event one device at a time ie. as soon as we detect
204 204 * that a device has the right ENUM# conditions, we return. If the following
205 205 * variable is set to non-zero, we scan all the devices on the bus
206 206 * for ENUM# conditions.
207 207 */
208 208 static int pcihp_enum_scan_all = 0;
209 209 /*
210 210 * If HSC driver cannot determine the board type (for example: it may not
211 211 * be possible to differentiate between a Basic Hotswap, Non Hotswap or
212 212 * Non-friendly Full hotswap board), the default board type is assigned
213 213 * to be as defined by the following variable.
214 214 */
215 215 static int pcihp_cpci_board_type = HPC_BOARD_CPCI_NON_HS;
216 216 static int pcihp_cpci_led_blink = 30;
217 217 /*
218 218 * It was noted that the blue LED when written on/off would cause INS/EXT
219 219 * bit to be set causing an extra interrupt. Although the cPCI specifications
220 220 * does not imply this, this behavior is seen with some FHS silicons.
221 221 * Also, handling the INS/EXT bit would control the LED being On/Off.
222 222 * Until the behavior is confirmed, this flag could be used to enable or
223 223 * disable handling the LED.
224 224 * 0 means the silicons handles the LED behavior via the INS/EXT bit.
225 225 * 1 means the software must explicitly do the LED behavior.
226 226 */
227 227 static int pcihp_cpci_blue_led = 1;
228 228
229 229 /* static functions */
230 230 static pcihp_t *pcihp_create_soft_state(dev_info_t *dip);
231 231 static void pcihp_destroy_soft_state(dev_info_t *dip);
232 232 static pcihp_t *pcihp_get_soft_state(dev_info_t *dip, int cmd, int *rv);
233 233 static int pcihp_configure_ap(pcihp_t *pcihp_p, int pci_dev);
234 234 static int pcihp_unconfigure_ap(pcihp_t *pcihp_p, int pci_dev);
235 235 static int pcihp_new_slot_state(dev_info_t *, hpc_slot_t,
236 236 hpc_slot_info_t *, int);
237 237 static int pcihp_configure(dev_info_t *, void *);
238 238 static bool_t pcihp_check_status(dev_info_t *);
239 239 static int pcihp_event_handler(caddr_t, uint_t);
240 240 static dev_info_t *pcihp_devi_find(dev_info_t *dip, uint_t dev, uint_t func);
241 241 static int pcihp_match_dev(dev_info_t *dip, void *hdl);
242 242 static int pcihp_get_hs_csr(struct pcihp_slotinfo *, ddi_acc_handle_t,
243 243 uint8_t *);
244 244 static void pcihp_set_hs_csr(struct pcihp_slotinfo *, ddi_acc_handle_t,
245 245 uint8_t *);
246 246 static int pcihp_get_hs_csr_location(ddi_acc_handle_t);
247 247 static int pcihp_handle_enum(pcihp_t *, int, int, int);
248 248 static void pcihp_hs_csr_op(pcihp_t *, int, int);
249 249 static int pcihp_enum_slot(pcihp_t *, struct pcihp_slotinfo *, int, int, int);
250 250 static int pcihp_handle_enum_extraction(pcihp_t *, int, int, int);
251 251 static int pcihp_handle_enum_insertion(pcihp_t *, int, int, int);
252 252 static int pcihp_add_dummy_reg_property(dev_info_t *, uint_t, uint_t, uint_t);
253 253 static int pcihp_config_setup(dev_info_t **, ddi_acc_handle_t *,
254 254 dev_info_t **, int, pcihp_t *);
255 255 static void pcihp_config_teardown(ddi_acc_handle_t *,
256 256 dev_info_t **, int, pcihp_t *);
257 257 static int pcihp_get_board_type(struct pcihp_slotinfo *);
258 258 /* sysevent function */
259 259 static void pcihp_gen_sysevent(char *, int, int, dev_info_t *, int);
260 260
261 261 static int pcihp_list_occupants(dev_info_t *, void *);
262 262 static int pcihp_indirect_map(dev_info_t *dip);
263 263
264 264 #if 0
265 265 static void pcihp_probe_slot_state(dev_info_t *, int, hpc_slot_state_t *);
266 266 #endif
267 267
268 268 int pcihp_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
269 269 int flags, char *name, caddr_t valuep, int *lengthp);
270 270
271 271 struct cb_ops pcihp_cb_ops = {
272 272 pcihp_open, /* open */
273 273 pcihp_close, /* close */
274 274 nodev, /* strategy */
275 275 nodev, /* print */
276 276 nodev, /* dump */
277 277 nodev, /* read */
278 278 nodev, /* write */
279 279 pcihp_ioctl, /* ioctl */
280 280 nodev, /* devmap */
281 281 nodev, /* mmap */
282 282 nodev, /* segmap */
283 283 nochpoll, /* poll */
284 284 pcihp_prop_op, /* cb_prop_op */
285 285 NULL, /* streamtab */
286 286 D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */
287 287 CB_REV, /* rev */
288 288 nodev, /* int (*cb_aread)() */
289 289 nodev /* int (*cb_awrite)() */
290 290 };
291 291
292 292 /*
293 293 * local data
294 294 */
295 295
296 296 int pcihp_autocfg_enabled = 1; /* auto config is enabled by default */
297 297
298 298 static kmutex_t pcihp_mutex; /* mutex to protect the following data */
299 299 static pcihp_t *pcihp_head = NULL;
300 300
301 301 static kmutex_t pcihp_open_mutex; /* mutex to protect open/close/uninit */
302 302 static int pci_devlink_flags = 0;
303 303
304 304 /*
↓ open down ↓ |
304 lines elided |
↑ open up ↑ |
305 305 * Module linkage information for the kernel.
306 306 */
307 307 extern struct mod_ops mod_miscops;
308 308 static struct modlmisc modlmisc = {
309 309 &mod_miscops,
310 310 "PCI nexus hotplug support",
311 311 };
312 312
313 313 static struct modlinkage modlinkage = {
314 314 MODREV_1,
315 - &modlmisc,
316 - NULL
315 + { &modlmisc, NULL }
317 316 };
318 317
319 318 int
320 319 _init(void)
321 320 {
322 321 int error;
323 322
324 323 mutex_init(&pcihp_mutex, NULL, MUTEX_DRIVER, NULL);
325 324 mutex_init(&pcihp_open_mutex, NULL, MUTEX_DRIVER, NULL);
326 325 if ((error = mod_install(&modlinkage)) != 0) {
327 326 mutex_destroy(&pcihp_open_mutex);
328 327 mutex_destroy(&pcihp_mutex);
329 328 }
330 329
331 330 return (error);
332 331 }
333 332
334 333 int
335 334 _fini(void)
336 335 {
337 336 return (EBUSY);
338 337 }
339 338
340 339 int
341 340 _info(struct modinfo *modinfop)
342 341 {
343 342 return (mod_info(&modlinkage, modinfop));
344 343 }
345 344
346 345 static pcihp_t *
347 346 pcihp_create_soft_state(
348 347 dev_info_t *dip)
349 348 {
350 349 pcihp_t *pcihp_p;
351 350
352 351 pcihp_p = kmem_zalloc(sizeof (struct pcihp), KM_SLEEP);
353 352
354 353 pcihp_p->dip = dip;
355 354 mutex_init(&pcihp_p->mutex, NULL, MUTEX_DRIVER, NULL);
356 355
357 356 mutex_enter(&pcihp_mutex);
358 357 pcihp_p->nextp = pcihp_head;
359 358 pcihp_head = pcihp_p;
360 359 pcihp_p->bus_state = PCIHP_BUS_INITIALIZING;
361 360 pcihp_p->slots_active = 0;
362 361 mutex_exit(&pcihp_mutex);
363 362
364 363 return (pcihp_p);
365 364 }
366 365
367 366 static void
368 367 pcihp_destroy_soft_state(
369 368 dev_info_t *dip)
370 369 {
371 370 pcihp_t *p;
372 371 pcihp_t **pp;
373 372
374 373 mutex_enter(&pcihp_mutex);
375 374 pp = &pcihp_head;
376 375 while ((p = *pp) != NULL) {
377 376 if (p->dip == dip) {
378 377 *pp = p->nextp;
379 378 kmem_free(p, sizeof (struct pcihp));
380 379 break;
381 380 }
382 381 pp = &(p->nextp);
383 382 }
384 383 mutex_exit(&pcihp_mutex);
385 384 }
386 385
387 386 /*
388 387 * This function should be imported by client nexus drivers as their
389 388 * devo_getinfo() entry point.
390 389 */
391 390
392 391 /* ARGSUSED */
393 392 int
394 393 pcihp_info(
395 394 dev_info_t *dip,
396 395 ddi_info_cmd_t cmd,
397 396 void *arg,
398 397 void **result)
399 398 {
400 399 pcihp_t *pcihp_p;
401 400 major_t major;
402 401 minor_t minor;
403 402 int instance;
404 403
405 404 major = getmajor((dev_t)arg);
406 405 minor = getminor((dev_t)arg);
407 406 instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
408 407
409 408 switch (cmd) {
410 409 default:
411 410 return (DDI_FAILURE);
412 411
413 412 case DDI_INFO_DEVT2INSTANCE:
414 413 *result = (void *)(intptr_t)instance;
415 414 return (DDI_SUCCESS);
416 415
417 416 case DDI_INFO_DEVT2DEVINFO:
418 417 mutex_enter(&pcihp_mutex);
419 418 pcihp_p = pcihp_head;
420 419 while (pcihp_p != NULL) {
421 420 if (ddi_driver_major(pcihp_p->dip) ==
422 421 major && ddi_get_instance(pcihp_p->dip) ==
423 422 instance) {
424 423 *result = (void *)pcihp_p->dip;
425 424 mutex_exit(&pcihp_mutex);
426 425 return (DDI_SUCCESS);
427 426 }
428 427 pcihp_p = pcihp_p->nextp;
429 428 }
430 429 mutex_exit(&pcihp_mutex);
431 430 return (DDI_FAILURE);
432 431 }
433 432 }
434 433
435 434 /*
436 435 * This function retrieves the hot plug soft state and performs the
437 436 * following primitive commands while the soft state is locked:
438 437 * mark the bus unconfigured, increment slot activity, decrement
439 438 * slot activity and noop.
440 439 */
441 440
442 441 /* ARGSUSED */
443 442 static pcihp_t *
444 443 pcihp_get_soft_state(
445 444 dev_info_t *dip, int cmd, int *rv)
446 445 {
447 446 pcihp_t *pcihp_p;
448 447
449 448 *rv = PCIHP_SUCCESS;
450 449 mutex_enter(&pcihp_mutex);
451 450 pcihp_p = pcihp_head;
452 451 while (pcihp_p != NULL) {
453 452 if (pcihp_p->dip == dip) {
454 453 switch (cmd) {
455 454 case PCIHP_DR_BUS_UNCONFIGURE:
456 455 if (pcihp_p->slots_active == 0)
457 456 pcihp_p->bus_state =
458 457 PCIHP_BUS_UNCONFIGURED;
459 458 else
460 459 *rv = PCIHP_FAILURE;
461 460 break;
462 461 case PCIHP_DR_SLOT_ENTER:
463 462 if (pcihp_p->bus_state ==
464 463 PCIHP_BUS_UNCONFIGURED)
465 464 *rv = PCIHP_FAILURE;
466 465 else
467 466 pcihp_p->slots_active++;
468 467 break;
469 468 case PCIHP_DR_SLOT_EXIT:
470 469 ASSERT(pcihp_p->slots_active > 0);
471 470 if (pcihp_p->slots_active == 0)
472 471 cmn_err(CE_PANIC,
473 472 "pcihp (%s%d): mismatched slot"
474 473 " activity",
475 474 ddi_driver_name(dip),
476 475 ddi_get_instance(dip));
477 476 else
478 477 pcihp_p->slots_active--;
479 478 break;
480 479 case PCIHP_DR_NOOP:
481 480 break;
482 481 default:
483 482 *rv = PCIHP_FAILURE;
484 483 break;
485 484 }
486 485 mutex_exit(&pcihp_mutex);
487 486 return (pcihp_p);
488 487 }
489 488 pcihp_p = pcihp_p->nextp;
490 489 }
491 490 mutex_exit(&pcihp_mutex);
492 491
493 492 return (NULL);
494 493 }
495 494
496 495 /* ARGSUSED3 */
497 496 static int
498 497 pcihp_open(dev_t *devp, int flags, int otyp, cred_t *credp)
499 498 {
500 499 dev_info_t *self;
501 500 pcihp_t *pcihp_p;
502 501 minor_t minor;
503 502 int pci_dev;
504 503 int rv;
505 504
506 505 /*
507 506 * Make sure the open is for the right file type.
508 507 */
509 508 if (otyp != OTYP_CHR)
510 509 return (EINVAL);
511 510
512 511 mutex_enter(&pcihp_open_mutex);
513 512 /*
514 513 * Get the soft state structure.
515 514 */
516 515 if (pcihp_info(NULL, DDI_INFO_DEVT2DEVINFO, (void *)*devp,
517 516 (void **)&self) != DDI_SUCCESS) {
518 517 mutex_exit(&pcihp_open_mutex);
519 518 return (ENXIO);
520 519 }
521 520
522 521 pcihp_p = pcihp_get_soft_state(self, PCIHP_DR_NOOP, &rv);
523 522 ASSERT(pcihp_p != NULL);
524 523
525 524 mutex_enter(&pcihp_p->mutex);
526 525
527 526 /*
528 527 * If the pci_dev is valid then the minor device is an
529 528 * AP. Otherwise it is ":devctl" minor device.
530 529 */
531 530 minor = getminor(*devp);
532 531 pci_dev = PCIHP_AP_MINOR_NUM_TO_PCI_DEVNUM(minor);
533 532 if (pci_dev < PCI_MAX_DEVS) {
534 533 struct pcihp_slotinfo *slotinfop;
535 534
536 535 slotinfop = &pcihp_p->slotinfo[pci_dev];
537 536 if (slotinfop->slot_hdl == NULL) {
538 537 mutex_exit(&pcihp_p->mutex);
539 538 mutex_exit(&pcihp_open_mutex);
540 539 return (ENXIO);
541 540 }
542 541 }
543 542
544 543 /*
545 544 * Handle the open by tracking the device state.
546 545 *
547 546 * Note: Needs review w.r.t exclusive access to AP or the bus.
548 547 * Currently in the pci plug-in we don't use EXCL open at all
549 548 * so the code below implements EXCL access on the bus.
550 549 */
551 550
552 551 /* enforce exclusive access to the bus */
553 552 if ((pcihp_p->soft_state == PCIHP_SOFT_STATE_OPEN_EXCL) ||
554 553 ((flags & FEXCL) &&
555 554 (pcihp_p->soft_state != PCIHP_SOFT_STATE_CLOSED))) {
556 555 mutex_exit(&pcihp_p->mutex);
557 556 mutex_exit(&pcihp_open_mutex);
558 557 return (EBUSY);
559 558 }
560 559
561 560 if (flags & FEXCL)
562 561 pcihp_p->soft_state = PCIHP_SOFT_STATE_OPEN_EXCL;
563 562 else
564 563 pcihp_p->soft_state = PCIHP_SOFT_STATE_OPEN;
565 564
566 565 mutex_exit(&pcihp_p->mutex);
567 566 mutex_exit(&pcihp_open_mutex);
568 567
569 568 return (0);
570 569 }
571 570
572 571 /* ARGSUSED */
573 572 static int
574 573 pcihp_close(dev_t dev, int flags, int otyp, cred_t *credp)
575 574 {
576 575 dev_info_t *self;
577 576 pcihp_t *pcihp_p;
578 577 int rv;
579 578
580 579 if (otyp != OTYP_CHR)
581 580 return (EINVAL);
582 581
583 582 mutex_enter(&pcihp_open_mutex);
584 583
585 584 if (pcihp_info(NULL, DDI_INFO_DEVT2DEVINFO, (void *)dev,
586 585 (void **)&self) != DDI_SUCCESS) {
587 586 mutex_exit(&pcihp_open_mutex);
588 587 return (ENXIO);
589 588 }
590 589
591 590 pcihp_p = pcihp_get_soft_state(self, PCIHP_DR_NOOP, &rv);
592 591 ASSERT(pcihp_p != NULL);
593 592
594 593 mutex_enter(&pcihp_p->mutex);
595 594 pcihp_p->soft_state = PCIHP_SOFT_STATE_CLOSED;
596 595 mutex_exit(&pcihp_p->mutex);
597 596
598 597 mutex_exit(&pcihp_open_mutex);
599 598
600 599 return (0);
601 600 }
602 601
603 602 static int
604 603 pcihp_list_occupants(dev_info_t *dip, void *hdl)
605 604 {
606 605 int pci_dev;
607 606 struct pcihp_config_ctrl *ctrl = (struct pcihp_config_ctrl *)hdl;
608 607 pci_regspec_t *pci_rp;
609 608 int length;
610 609 major_t major;
611 610
612 611 /*
613 612 * Get the PCI device number information from the devinfo
614 613 * node. Since the node may not have the address field
615 614 * setup (this is done in the DDI_INITCHILD of the parent)
616 615 * we look up the 'reg' property to decode that information.
617 616 */
618 617 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
619 618 DDI_PROP_DONTPASS, "reg", (int **)&pci_rp,
620 619 (uint_t *)&length) != DDI_PROP_SUCCESS) {
621 620 ctrl->rv = DDI_FAILURE;
622 621 ctrl->dip = dip;
623 622 return (DDI_WALK_TERMINATE);
624 623 }
625 624
626 625 /* get the pci device id information */
627 626 pci_dev = PCI_REG_DEV_G(pci_rp->pci_phys_hi);
628 627
629 628 /*
630 629 * free the memory allocated by ddi_prop_lookup_int_array
631 630 */
632 631 ddi_prop_free(pci_rp);
633 632
634 633 /*
635 634 * Match the node for the device number of the slot.
636 635 */
637 636 if (pci_dev == ctrl->pci_dev) { /* node is a match */
638 637
639 638 major = ddi_driver_major(dip);
640 639
641 640 /*
642 641 * If the node is not yet attached, then don't list it
643 642 * as an occupant. This is valid, since nothing can be
644 643 * consuming it until it is attached, and cfgadm will
645 644 * ask for the property explicitly which will cause it
646 645 * to be re-freshed right before checking with rcm.
647 646 */
648 647 if ((major == -1) || !i_ddi_devi_attached(dip))
649 648 return (DDI_WALK_PRUNECHILD);
650 649
651 650 /*
652 651 * If we have used all our occupants then print mesage
653 652 * and terminate walk.
654 653 */
655 654 if (ctrl->occupant->i >= HPC_MAX_OCCUPANTS) {
656 655 cmn_err(CE_WARN,
657 656 "pcihp (%s%d): unable to list all occupants",
658 657 ddi_driver_name(ddi_get_parent(dip)),
659 658 ddi_get_instance(ddi_get_parent(dip)));
660 659 return (DDI_WALK_TERMINATE);
661 660 }
662 661
663 662 /*
664 663 * No need to hold the dip as ddi_walk_devs
665 664 * has already arranged that for us.
666 665 */
667 666 ctrl->occupant->id[ctrl->occupant->i] =
668 667 kmem_alloc(sizeof (char[MAXPATHLEN]), KM_SLEEP);
669 668 (void) ddi_pathname(dip,
670 669 (char *)ctrl->occupant->id[ctrl->occupant->i]);
671 670 ctrl->occupant->i++;
672 671 }
673 672
674 673 /*
675 674 * continue the walk to the next sibling to look for a match
676 675 * or to find other nodes if this card is a multi-function card.
677 676 */
678 677 return (DDI_WALK_PRUNECHILD);
679 678 }
680 679
681 680 static void
682 681 pcihp_create_occupant_props_nolock(dev_info_t *self, dev_t dev, int pci_dev)
683 682 {
684 683 struct pcihp_config_ctrl ctrl;
685 684 hpc_occupant_info_t *occupant;
686 685 int i;
687 686
688 687 occupant = kmem_alloc(sizeof (hpc_occupant_info_t), KM_SLEEP);
689 688 occupant->i = 0;
690 689
691 690 ctrl.flags = 0;
692 691 ctrl.dip = NULL;
693 692 ctrl.rv = NDI_SUCCESS;
694 693 ctrl.pci_dev = pci_dev;
695 694 ctrl.op = 55; /* should define DRYRUN */
696 695 ctrl.occupant = occupant;
697 696
698 697 ddi_walk_devs(ddi_get_child(self), pcihp_list_occupants,
699 698 (void *)&ctrl);
700 699
701 700 if (occupant->i == 0) {
702 701 /* no occupants right now, need to create stub property */
703 702 char *c[] = { "" };
704 703 (void) ddi_prop_update_string_array(dev, self, "pci-occupant",
705 704 c, 1);
706 705 } else {
707 706 (void) ddi_prop_update_string_array(dev, self, "pci-occupant",
708 707 occupant->id, occupant->i);
709 708 }
710 709 for (i = 0; i < occupant->i; i++) {
711 710 kmem_free(occupant->id[i], sizeof (char[MAXPATHLEN]));
712 711 }
713 712
714 713 kmem_free(occupant, sizeof (hpc_occupant_info_t));
715 714 }
716 715
717 716 static void
718 717 pcihp_create_occupant_props(dev_info_t *self, dev_t dev, int pci_dev)
719 718 {
720 719 int circular;
721 720
722 721 ndi_devi_enter(self, &circular);
723 722 pcihp_create_occupant_props_nolock(self, dev, pci_dev);
724 723 ndi_devi_exit(self, circular);
725 724 }
726 725
727 726 static void
728 727 pcihp_delete_occupant_props(dev_info_t *dip, dev_t dev)
729 728 {
730 729 if (ddi_prop_remove(dev, dip, "pci-occupant")
731 730 != DDI_PROP_SUCCESS)
732 731 return; /* add error handling */
733 732
734 733 }
735 734
736 735 /*
737 736 * pcihp_ioctl: devctl hotplug controls
738 737 */
739 738 /* ARGSUSED */
740 739 static int
741 740 pcihp_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
742 741 int *rvalp)
743 742 {
744 743 pcihp_t *pcihp_p;
745 744 dev_info_t *self;
746 745 struct devctl_iocdata *dcp;
747 746 uint_t bus_state;
748 747 int rv = 0;
749 748 int pci_dev;
750 749 struct pcihp_slotinfo *slotinfop;
751 750 hpc_slot_state_t rstate;
752 751 devctl_ap_state_t ap_state;
753 752 struct hpc_control_data hpc_ctrldata;
754 753 struct hpc_led_info led_info;
755 754 time_t time;
756 755 int state_locking;
757 756 int state_unlocking;
758 757 int rval;
759 758 char *pathname = NULL;
760 759
761 760 /*
762 761 * read devctl ioctl data before soft state retrieval
763 762 */
764 763 if ((cmd != DEVCTL_AP_CONTROL) &&
765 764 ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS)
766 765 return (EFAULT);
767 766
768 767 if (pcihp_info(NULL, DDI_INFO_DEVT2DEVINFO, (void *)dev,
769 768 (void **)&self) != DDI_SUCCESS) {
770 769 if (cmd != DEVCTL_AP_CONTROL)
771 770 ndi_dc_freehdl(dcp);
772 771 return (ENXIO);
773 772 }
774 773
775 774 switch (cmd) {
776 775 case DEVCTL_AP_INSERT:
777 776 case DEVCTL_AP_REMOVE:
778 777 case DEVCTL_AP_CONNECT:
779 778 case DEVCTL_AP_DISCONNECT:
780 779 case DEVCTL_AP_CONFIGURE:
781 780 case DEVCTL_AP_UNCONFIGURE:
782 781 case DEVCTL_AP_GETSTATE:
783 782 case DEVCTL_AP_CONTROL:
784 783 state_locking = PCIHP_DR_SLOT_ENTER;
785 784 state_unlocking = PCIHP_DR_SLOT_EXIT;
786 785 break;
787 786 default:
788 787 state_locking = PCIHP_DR_NOOP;
789 788 state_unlocking = PCIHP_DR_NOOP;
790 789 break;
791 790 }
792 791
793 792 pcihp_p = pcihp_get_soft_state(self, state_locking, &rval);
794 793 ASSERT(pcihp_p != NULL);
795 794
796 795 if (rval == PCIHP_FAILURE) {
797 796 (void) ddi_pathname(pcihp_p->dip, pathname);
798 797 PCIHP_DEBUG((CE_WARN, "Hot Plug bus %s instance is unconfigured"
799 798 " while slot activity is requested\n", pathname));
800 799 if (cmd != DEVCTL_AP_CONTROL)
801 800 ndi_dc_freehdl(dcp);
802 801 return (EBUSY);
803 802 }
804 803
805 804 /*
806 805 * For attachment points the lower 8 bits of the minor number is the
807 806 * PCI device number.
808 807 */
809 808 pci_dev = PCIHP_AP_MINOR_NUM_TO_PCI_DEVNUM(getminor(dev));
810 809
811 810 /*
812 811 * We can use the generic implementation for these ioctls
813 812 */
814 813 switch (cmd) {
815 814 case DEVCTL_DEVICE_GETSTATE:
816 815 case DEVCTL_DEVICE_ONLINE:
817 816 case DEVCTL_DEVICE_OFFLINE:
818 817 case DEVCTL_BUS_GETSTATE:
819 818 rv = ndi_devctl_ioctl(self, cmd, arg, mode, 0);
820 819 ndi_dc_freehdl(dcp);
821 820 return (rv);
822 821 default:
823 822 break;
824 823 }
825 824
826 825 switch (cmd) {
827 826
828 827 case DEVCTL_DEVICE_RESET:
829 828 rv = ENOTSUP;
830 829 break;
831 830
832 831 case DEVCTL_BUS_QUIESCE:
833 832 if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS)
834 833 if (bus_state == BUS_QUIESCED)
835 834 break;
836 835 (void) ndi_set_bus_state(self, BUS_QUIESCED);
837 836 break;
838 837
839 838 case DEVCTL_BUS_UNQUIESCE:
840 839 if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS)
841 840 if (bus_state == BUS_ACTIVE)
842 841 break;
843 842 (void) ndi_set_bus_state(self, BUS_ACTIVE);
844 843 break;
845 844
846 845 case DEVCTL_BUS_RESET:
847 846 rv = ENOTSUP;
848 847 break;
849 848
850 849 case DEVCTL_BUS_RESETALL:
851 850 rv = ENOTSUP;
852 851 break;
853 852
854 853 case DEVCTL_AP_CONNECT:
855 854 case DEVCTL_AP_DISCONNECT:
856 855 /*
857 856 * CONNECT(DISCONNECT) the hot plug slot to(from) the bus.
858 857 *
859 858 * For cPCI slots this operation is a nop so the HPC
860 859 * driver may return success if it is a valid operation.
861 860 */
862 861 case DEVCTL_AP_INSERT:
863 862 case DEVCTL_AP_REMOVE:
864 863 /*
865 864 * Prepare the slot for INSERT/REMOVE operation.
866 865 */
867 866
868 867 /*
869 868 * check for valid request:
870 869 * 1. It is a hotplug slot.
871 870 * 2. The slot has no occupant that is in
872 871 * the 'configured' state.
873 872 */
874 873 if (pci_dev >= PCI_MAX_DEVS) {
875 874 rv = ENXIO;
876 875 break;
877 876 }
878 877 slotinfop = &pcihp_p->slotinfo[pci_dev];
879 878
880 879 mutex_enter(&slotinfop->slot_mutex);
881 880
882 881 if ((slotinfop->slot_hdl == NULL) ||
883 882 (slotinfop->slot_flags & PCIHP_SLOT_DISABLED)) {
884 883 rv = ENXIO;
885 884 mutex_exit(&slotinfop->slot_mutex);
886 885 break;
887 886 }
888 887
889 888 /* the slot occupant must be in the UNCONFIGURED state */
890 889 if (slotinfop->ostate != AP_OSTATE_UNCONFIGURED) {
891 890 rv = EINVAL;
892 891 mutex_exit(&slotinfop->slot_mutex);
893 892 break;
894 893 }
895 894 /*
896 895 * Call the HPC driver to perform the operation on the slot.
897 896 */
898 897
899 898 switch (cmd) {
900 899 case DEVCTL_AP_INSERT:
901 900 rv = hpc_nexus_insert(slotinfop->slot_hdl, NULL, 0);
902 901 break;
903 902 case DEVCTL_AP_REMOVE:
904 903 rv = hpc_nexus_remove(slotinfop->slot_hdl, NULL, 0);
905 904 break;
906 905 case DEVCTL_AP_CONNECT:
907 906 rv = hpc_nexus_connect(slotinfop->slot_hdl, NULL, 0);
908 907 if (rv == HPC_SUCCESS) {
909 908 slotinfop->rstate = AP_RSTATE_CONNECTED;
910 909
911 910 if (drv_getparm(TIME, (void *)&time) !=
912 911 DDI_SUCCESS)
913 912 slotinfop->last_change = (time_t)-1;
914 913 else
915 914 slotinfop->last_change = (time32_t)time;
916 915
917 916 slotinfop = &pcihp_p->slotinfo[pci_dev];
918 917 pcihp_gen_sysevent(slotinfop->name,
919 918 PCIHP_DR_AP_STATE_CHANGE,
920 919 SE_NO_HINT, pcihp_p->dip,
921 920 KM_SLEEP);
922 921 }
923 922 break;
924 923 case DEVCTL_AP_DISCONNECT:
925 924 rv = hpc_nexus_disconnect(slotinfop->slot_hdl, NULL, 0);
926 925 if (rv == HPC_SUCCESS) {
927 926 slotinfop->rstate = AP_RSTATE_DISCONNECTED;
928 927
929 928 if (drv_getparm(TIME, (void *)&time) !=
930 929 DDI_SUCCESS)
931 930 slotinfop->last_change = (time_t)-1;
932 931 else
933 932 slotinfop->last_change = (time32_t)time;
934 933
935 934 slotinfop = &pcihp_p->slotinfo[pci_dev];
936 935 pcihp_gen_sysevent(slotinfop->name,
937 936 PCIHP_DR_AP_STATE_CHANGE,
938 937 SE_NO_HINT, pcihp_p->dip,
939 938 KM_SLEEP);
940 939 }
941 940 break;
942 941 }
943 942 mutex_exit(&slotinfop->slot_mutex);
944 943
945 944 switch (rv) {
946 945 case HPC_ERR_INVALID:
947 946 rv = ENXIO;
948 947 break;
949 948 case HPC_ERR_NOTSUPPORTED:
950 949 rv = ENOTSUP;
951 950 break;
952 951 case HPC_ERR_FAILED:
953 952 rv = EIO;
954 953 break;
955 954 }
956 955
957 956 break;
958 957
959 958 case DEVCTL_AP_CONFIGURE:
960 959 /*
961 960 * **************************************
962 961 * CONFIGURE the occupant in the slot.
963 962 * **************************************
964 963 */
965 964 slotinfop = &pcihp_p->slotinfo[pci_dev];
966 965
967 966 mutex_enter(&slotinfop->slot_mutex);
968 967
969 968 rv = pcihp_configure_ap(pcihp_p, pci_dev);
970 969 if (rv == HPC_SUCCESS) {
971 970 pcihp_gen_sysevent(slotinfop->name,
972 971 PCIHP_DR_AP_STATE_CHANGE,
973 972 SE_NO_HINT, pcihp_p->dip, KM_SLEEP);
974 973 pcihp_create_occupant_props(self, dev, pci_dev);
975 974 }
976 975 mutex_exit(&slotinfop->slot_mutex);
977 976
978 977 break;
979 978
980 979 case DEVCTL_AP_UNCONFIGURE:
981 980 /*
982 981 * **************************************
983 982 * UNCONFIGURE the occupant in the slot.
984 983 * **************************************
985 984 */
986 985 slotinfop = &pcihp_p->slotinfo[pci_dev];
987 986
988 987 mutex_enter(&slotinfop->slot_mutex);
989 988
990 989 rv = pcihp_unconfigure_ap(pcihp_p, pci_dev);
991 990
992 991 if (rv == HPC_SUCCESS) {
993 992 pcihp_gen_sysevent(slotinfop->name,
994 993 PCIHP_DR_AP_STATE_CHANGE,
995 994 SE_NO_HINT, pcihp_p->dip, KM_SLEEP);
996 995 pcihp_delete_occupant_props(pcihp_p->dip, dev);
997 996 }
998 997 mutex_exit(&slotinfop->slot_mutex);
999 998
1000 999 break;
1001 1000
1002 1001 case DEVCTL_AP_GETSTATE:
1003 1002 {
1004 1003 int mutex_held;
1005 1004
1006 1005 /*
1007 1006 * return the state of Attachment Point.
1008 1007 *
1009 1008 * If the occupant is in UNCONFIGURED state then
1010 1009 * we should get the receptacle state from the
1011 1010 * HPC driver because the receptacle state
1012 1011 * maintained in the nexus may not be accurate.
1013 1012 */
1014 1013
1015 1014 /*
1016 1015 * check for valid request:
1017 1016 * 1. It is a hotplug slot.
1018 1017 */
1019 1018 slotinfop = &pcihp_p->slotinfo[pci_dev];
1020 1019
1021 1020 /* try to acquire the slot mutex */
1022 1021 mutex_held = mutex_tryenter(&slotinfop->slot_mutex);
1023 1022
1024 1023 if (pci_dev >= PCI_MAX_DEVS || slotinfop->slot_hdl == NULL) {
1025 1024 rv = ENXIO;
1026 1025 if (mutex_held) {
1027 1026 mutex_exit(&slotinfop->slot_mutex);
1028 1027 }
1029 1028 break;
1030 1029 }
1031 1030
1032 1031 if (slotinfop->ostate == AP_OSTATE_UNCONFIGURED) {
1033 1032 if (hpc_nexus_control(slotinfop->slot_hdl,
1034 1033 HPC_CTRL_GET_SLOT_STATE, (caddr_t)&rstate) != 0) {
1035 1034 rv = EIO;
1036 1035 if (mutex_held)
1037 1036 mutex_exit(&slotinfop->slot_mutex);
1038 1037 break;
1039 1038 }
1040 1039 slotinfop->rstate = (ap_rstate_t)rstate;
1041 1040 }
1042 1041
1043 1042 ap_state.ap_rstate = slotinfop->rstate;
1044 1043 ap_state.ap_ostate = slotinfop->ostate;
1045 1044 ap_state.ap_condition = slotinfop->condition;
1046 1045 ap_state.ap_last_change = slotinfop->last_change;
1047 1046 ap_state.ap_error_code = 0; /* XXX */
1048 1047 if (mutex_held)
1049 1048 ap_state.ap_in_transition = 0; /* AP is not busy */
1050 1049 else
1051 1050 ap_state.ap_in_transition = 1; /* AP is busy */
1052 1051
1053 1052 if (mutex_held)
1054 1053 mutex_exit(&slotinfop->slot_mutex);
1055 1054
1056 1055 /* copy the return-AP-state information to the user space */
1057 1056 if (ndi_dc_return_ap_state(&ap_state, dcp) != NDI_SUCCESS)
1058 1057 rv = EFAULT;
1059 1058
1060 1059 break;
1061 1060
1062 1061 }
1063 1062 case DEVCTL_AP_CONTROL:
1064 1063 /*
1065 1064 * HPC control functions:
1066 1065 * HPC_CTRL_ENABLE_SLOT/HPC_CTRL_DISABLE_SLOT
1067 1066 * Changes the state of the slot and preserves
1068 1067 * the state across the reboot.
1069 1068 * HPC_CTRL_ENABLE_AUTOCFG/HPC_CTRL_DISABLE_AUTOCFG
1070 1069 * Enables or disables the auto configuration
1071 1070 * of hot plugged occupant if the hardware
1072 1071 * supports notification of the hot plug
1073 1072 * events.
1074 1073 * HPC_CTRL_GET_LED_STATE/HPC_CTRL_SET_LED_STATE
1075 1074 * Controls the state of an LED.
1076 1075 * HPC_CTRL_GET_SLOT_INFO
1077 1076 * Get slot information data structure
1078 1077 * (hpc_slot_info_t).
1079 1078 * HPC_CTRL_GET_BOARD_TYPE
1080 1079 * Get board type information (hpc_board_type_t).
1081 1080 * HPC_CTRL_GET_CARD_INFO
1082 1081 * Get card information (hpc_card_info_t).
1083 1082 *
1084 1083 * These control functions are used by the cfgadm plug-in
1085 1084 * to implement "-x" and "-v" options.
1086 1085 */
1087 1086
1088 1087 /* copy user ioctl data first */
1089 1088 switch (ddi_model_convert_from(mode & FMODELS)) {
1090 1089 case DDI_MODEL_ILP32: {
1091 1090 struct hpc_control32_data hpc_ctrldata32;
1092 1091
1093 1092 if (copyin((void *)arg, (void *)&hpc_ctrldata32,
1094 1093 sizeof (struct hpc_control32_data)) != 0) {
1095 1094 rv = EFAULT;
1096 1095 break;
1097 1096 }
1098 1097 hpc_ctrldata.cmd = hpc_ctrldata32.cmd;
1099 1098 hpc_ctrldata.data =
1100 1099 (void *)(intptr_t)hpc_ctrldata32.data;
1101 1100 break;
1102 1101 }
1103 1102 case DDI_MODEL_NONE:
1104 1103 if (copyin((void *)arg, (void *)&hpc_ctrldata,
1105 1104 sizeof (struct hpc_control_data)) != 0) {
1106 1105 rv = EFAULT;
1107 1106 }
1108 1107 break;
1109 1108 default:
1110 1109 rv = EFAULT;
1111 1110 break;
1112 1111 }
1113 1112 if (rv == EFAULT)
1114 1113 break;
1115 1114 /*
1116 1115 * check for valid request:
1117 1116 * 1. It is a hotplug slot.
1118 1117 */
1119 1118 slotinfop = &pcihp_p->slotinfo[pci_dev];
1120 1119
1121 1120 mutex_enter(&slotinfop->slot_mutex);
1122 1121
1123 1122 if (pci_dev >= PCI_MAX_DEVS || slotinfop->slot_hdl == NULL) {
1124 1123 rv = ENXIO;
1125 1124 mutex_exit(&slotinfop->slot_mutex);
1126 1125 break;
1127 1126 }
1128 1127
1129 1128 switch (hpc_ctrldata.cmd) {
1130 1129
1131 1130 case HPC_CTRL_GET_LED_STATE:
1132 1131 /* copy the led info from the user space */
1133 1132 if (copyin(hpc_ctrldata.data, (void *)&led_info,
1134 1133 sizeof (hpc_led_info_t)) != 0) {
1135 1134 rv = EFAULT;
1136 1135 break;
1137 1136 }
1138 1137
1139 1138 /* get the state of LED information */
1140 1139 if (hpc_nexus_control(slotinfop->slot_hdl,
1141 1140 HPC_CTRL_GET_LED_STATE, (caddr_t)&led_info) != 0) {
1142 1141
1143 1142 if (rv != ENOTSUP)
1144 1143 rv = EIO;
1145 1144
1146 1145 break;
1147 1146 }
1148 1147
1149 1148 /* copy the led info to the user space */
1150 1149 if (copyout((void *)&led_info, hpc_ctrldata.data,
1151 1150 sizeof (hpc_led_info_t)) != 0) {
1152 1151 rv = EFAULT;
1153 1152 break;
1154 1153 }
1155 1154
1156 1155 break;
1157 1156
1158 1157 case HPC_CTRL_SET_LED_STATE:
1159 1158 /* copy the led info from the user space */
1160 1159 if (copyin(hpc_ctrldata.data, (void *)&led_info,
1161 1160 sizeof (hpc_led_info_t)) != 0) {
1162 1161 rv = EFAULT;
1163 1162 break;
1164 1163 }
1165 1164
1166 1165 /* set the state of an LED */
1167 1166 rv = hpc_nexus_control(slotinfop->slot_hdl,
1168 1167 HPC_CTRL_SET_LED_STATE, (caddr_t)&led_info);
1169 1168
1170 1169 /*
1171 1170 * If the Hotswap Controller does not support
1172 1171 * LED management (as you would find typically
1173 1172 * in the cPCI industry), then we handle the
1174 1173 * blue LED on/off/blink operations, just in
1175 1174 * case it helps slot identification.
1176 1175 */
1177 1176 if ((rv == HPC_ERR_NOTSUPPORTED) &&
1178 1177 (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI)) {
1179 1178 if (led_info.led != HPC_ATTN_LED)
1180 1179 break;
1181 1180
1182 1181 switch (led_info.state) {
1183 1182 case HPC_LED_OFF:
1184 1183 pcihp_hs_csr_op(pcihp_p,
1185 1184 pci_dev,
1186 1185 HPC_EVENT_SLOT_BLUE_LED_OFF);
1187 1186 rv = 0;
1188 1187 break;
1189 1188 case HPC_LED_ON:
1190 1189 /*
1191 1190 * Please note that leaving
1192 1191 * LED ON could be dangerous
1193 1192 * as it means it is Ok to
1194 1193 * remove the board, which
1195 1194 * is not what we want to
1196 1195 * convey. So it is upto the
1197 1196 * user to take care of this
1198 1197 * situation and usage.
1199 1198 *
1200 1199 * Normally, a Blink command
1201 1200 * is more appropriate for
1202 1201 * identifying a board.
1203 1202 */
1204 1203 pcihp_hs_csr_op(pcihp_p,
1205 1204 pci_dev,
1206 1205 HPC_EVENT_SLOT_BLUE_LED_ON);
1207 1206 rv = 0;
1208 1207 break;
1209 1208 case HPC_LED_BLINK:
1210 1209 {
1211 1210 int bl;
1212 1211
1213 1212 for (bl = 0; bl < 2; bl++) {
1214 1213 pcihp_hs_csr_op(pcihp_p,
1215 1214 pci_dev,
1216 1215 HPC_EVENT_SLOT_BLUE_LED_ON);
1217 1216 delay(pcihp_cpci_led_blink);
1218 1217 pcihp_hs_csr_op(pcihp_p,
1219 1218 pci_dev,
1220 1219 HPC_EVENT_SLOT_BLUE_LED_OFF);
1221 1220 delay(pcihp_cpci_led_blink);
1222 1221 }
1223 1222 rv = 0;
1224 1223 break;
1225 1224 }
1226 1225 default:
1227 1226 break;
1228 1227 }
1229 1228 }
1230 1229
1231 1230 if (rv == HPC_ERR_FAILED)
1232 1231 rv = EIO;
1233 1232 break;
1234 1233
1235 1234 case HPC_CTRL_ENABLE_SLOT:
1236 1235
1237 1236 /*
1238 1237 * If slot already enabled, do not send a duplicate
1239 1238 * control message to the HPC driver.
1240 1239 */
1241 1240 if ((slotinfop->slot_flags & PCIHP_SLOT_DISABLED) == 0)
1242 1241 break;
1243 1242
1244 1243 /* tell the HPC driver also */
1245 1244 if (hpc_nexus_control(slotinfop->slot_hdl,
1246 1245 HPC_CTRL_ENABLE_SLOT, NULL) != HPC_SUCCESS) {
1247 1246 rv = EIO;
1248 1247 break;
1249 1248 }
1250 1249
1251 1250 /*
1252 1251 * Enable the slot for hotplug operations.
1253 1252 */
1254 1253 slotinfop->slot_flags &= ~PCIHP_SLOT_DISABLED;
1255 1254
1256 1255 slotinfop->condition = AP_COND_UNKNOWN;
1257 1256
1258 1257 /* XXX need to preserve this state across reboot? */
1259 1258
1260 1259 break;
1261 1260
1262 1261 case HPC_CTRL_DISABLE_SLOT:
1263 1262
1264 1263 /* Do not disable if occupant configured */
1265 1264 if (slotinfop->ostate == AP_OSTATE_CONFIGURED) {
1266 1265 rv = EAGAIN;
1267 1266 break;
1268 1267 }
1269 1268
1270 1269 /* tell the HPC driver also */
1271 1270 if (hpc_nexus_control(slotinfop->slot_hdl,
1272 1271 HPC_CTRL_DISABLE_SLOT, NULL) != HPC_SUCCESS) {
1273 1272 rv = EIO;
1274 1273 break;
1275 1274 }
1276 1275
1277 1276 /*
1278 1277 * Disable the slot for hotplug operations.
1279 1278 */
1280 1279 slotinfop->slot_flags |= PCIHP_SLOT_DISABLED;
1281 1280
1282 1281 slotinfop->condition = AP_COND_UNUSABLE;
1283 1282
1284 1283 /* XXX need to preserve this state across reboot? */
1285 1284
1286 1285 break;
1287 1286
1288 1287 case HPC_CTRL_ENABLE_AUTOCFG:
1289 1288 /*
1290 1289 * Enable auto configuration on this slot.
1291 1290 */
1292 1291 slotinfop->slot_flags |= PCIHP_SLOT_AUTO_CFG_EN;
1293 1292
1294 1293 /* tell the HPC driver also */
1295 1294 (void) hpc_nexus_control(slotinfop->slot_hdl,
1296 1295 HPC_CTRL_ENABLE_AUTOCFG, NULL);
1297 1296
1298 1297 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI)
1299 1298 pcihp_hs_csr_op(pcihp_p, pci_dev,
1300 1299 HPC_EVENT_ENABLE_ENUM);
1301 1300 break;
1302 1301
1303 1302 case HPC_CTRL_DISABLE_AUTOCFG:
1304 1303 /*
1305 1304 * Disable auto configuration on this slot.
1306 1305 */
1307 1306 slotinfop->slot_flags &= ~PCIHP_SLOT_AUTO_CFG_EN;
1308 1307
1309 1308 /* tell the HPC driver also */
1310 1309 (void) hpc_nexus_control(slotinfop->slot_hdl,
1311 1310 HPC_CTRL_DISABLE_AUTOCFG, NULL);
1312 1311
1313 1312 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI)
1314 1313 pcihp_hs_csr_op(pcihp_p, pci_dev,
1315 1314 HPC_EVENT_DISABLE_ENUM);
1316 1315 break;
1317 1316
1318 1317 case HPC_CTRL_GET_BOARD_TYPE:
1319 1318 {
1320 1319 hpc_board_type_t board_type;
1321 1320
1322 1321 /*
1323 1322 * Get board type data structure, hpc_board_type_t.
1324 1323 */
1325 1324 board_type = pcihp_get_board_type(slotinfop);
1326 1325 if (board_type == -1) {
1327 1326 rv = ENXIO;
1328 1327 break;
1329 1328 }
1330 1329
1331 1330 /* copy the board type info to the user space */
1332 1331 if (copyout((void *)&board_type, hpc_ctrldata.data,
1333 1332 sizeof (hpc_board_type_t)) != 0) {
1334 1333 rv = ENXIO;
1335 1334 break;
1336 1335 }
1337 1336
1338 1337 break;
1339 1338 }
1340 1339
1341 1340 case HPC_CTRL_GET_SLOT_INFO:
1342 1341 {
1343 1342 hpc_slot_info_t slot_info;
1344 1343
1345 1344 /*
1346 1345 * Get slot information structure, hpc_slot_info_t.
1347 1346 */
1348 1347 slot_info.version = HPC_SLOT_INFO_VERSION;
1349 1348 slot_info.slot_type = slotinfop->slot_type;
1350 1349 slot_info.pci_slot_capabilities =
1351 1350 slotinfop->slot_capabilities;
1352 1351 slot_info.pci_dev_num = (uint16_t)pci_dev;
1353 1352 (void) strcpy(slot_info.pci_slot_name, slotinfop->name);
1354 1353
1355 1354 /* copy the slot info structure to the user space */
1356 1355 if (copyout((void *)&slot_info, hpc_ctrldata.data,
1357 1356 sizeof (hpc_slot_info_t)) != 0) {
1358 1357 rv = EFAULT;
1359 1358 break;
1360 1359 }
1361 1360
1362 1361 break;
1363 1362 }
1364 1363
1365 1364 case HPC_CTRL_GET_CARD_INFO:
1366 1365 {
1367 1366 hpc_card_info_t card_info;
1368 1367 ddi_acc_handle_t handle;
1369 1368 dev_info_t *cdip;
1370 1369
1371 1370 /*
1372 1371 * Get card information structure, hpc_card_info_t.
1373 1372 */
1374 1373
1375 1374 /* verify that the card is configured */
1376 1375 if ((slotinfop->ostate != AP_OSTATE_CONFIGURED) ||
1377 1376 ((cdip = pcihp_devi_find(self,
1378 1377 pci_dev, 0)) == NULL)) {
1379 1378 /*
1380 1379 * either the card is not present or
1381 1380 * it is not configured.
1382 1381 */
1383 1382 rv = ENXIO;
1384 1383 break;
1385 1384 }
1386 1385
1387 1386 /*
1388 1387 * If declared failed, don't allow Config operations.
1389 1388 * Otherwise, if good or failing, it is assumed Ok
1390 1389 * to get config data.
1391 1390 */
1392 1391 if (slotinfop->condition == AP_COND_FAILED) {
1393 1392 rv = EIO;
1394 1393 break;
1395 1394 }
1396 1395
1397 1396 /* get the information from the PCI config header */
1398 1397 /* for the function 0. */
1399 1398 if (pci_config_setup(cdip, &handle) != DDI_SUCCESS) {
1400 1399 rv = EIO;
1401 1400 break;
1402 1401 }
1403 1402 card_info.prog_class = pci_config_get8(handle,
1404 1403 PCI_CONF_PROGCLASS);
1405 1404 card_info.base_class = pci_config_get8(handle,
1406 1405 PCI_CONF_BASCLASS);
1407 1406 card_info.sub_class = pci_config_get8(handle,
1408 1407 PCI_CONF_SUBCLASS);
1409 1408 card_info.header_type = pci_config_get8(handle,
1410 1409 PCI_CONF_HEADER);
1411 1410 pci_config_teardown(&handle);
1412 1411
1413 1412 /* copy the card info structure to the user space */
1414 1413 if (copyout((void *)&card_info, hpc_ctrldata.data,
1415 1414 sizeof (hpc_card_info_t)) != 0) {
1416 1415 rv = EFAULT;
1417 1416 break;
1418 1417 }
1419 1418
1420 1419 break;
1421 1420 }
1422 1421
1423 1422 default:
1424 1423 rv = EINVAL;
1425 1424 break;
1426 1425 }
1427 1426
1428 1427 mutex_exit(&slotinfop->slot_mutex);
1429 1428
1430 1429 break;
1431 1430
1432 1431 default:
1433 1432 rv = ENOTTY;
1434 1433 }
1435 1434
1436 1435 if (cmd != DEVCTL_AP_CONTROL)
1437 1436 ndi_dc_freehdl(dcp);
1438 1437
1439 1438 (void) pcihp_get_soft_state(self, state_unlocking, &rval);
1440 1439
1441 1440 return (rv);
1442 1441 }
1443 1442
1444 1443 /*
1445 1444 * **************************************
1446 1445 * CONFIGURE the occupant in the slot.
1447 1446 * **************************************
1448 1447 */
1449 1448 static int
1450 1449 pcihp_configure_ap(pcihp_t *pcihp_p, int pci_dev)
1451 1450 {
1452 1451 dev_info_t *self = pcihp_p->dip;
1453 1452 int rv = HPC_SUCCESS;
1454 1453 struct pcihp_slotinfo *slotinfop;
1455 1454 hpc_slot_state_t rstate;
1456 1455 struct pcihp_config_ctrl ctrl;
1457 1456 int circular_count;
1458 1457 time_t time;
1459 1458
1460 1459 /*
1461 1460 * check for valid request:
1462 1461 * 1. It is a hotplug slot.
1463 1462 * 2. The receptacle is in the CONNECTED state.
1464 1463 */
1465 1464 slotinfop = &pcihp_p->slotinfo[pci_dev];
1466 1465
1467 1466
1468 1467
1469 1468 if ((pci_dev >= PCI_MAX_DEVS) || (slotinfop->slot_hdl == NULL) ||
1470 1469 (slotinfop->slot_flags & PCIHP_SLOT_DISABLED)) {
1471 1470
1472 1471 return (ENXIO);
1473 1472 }
1474 1473
1475 1474 /*
1476 1475 * If the occupant is already in (partially?) configured
1477 1476 * state then call the ndi_devi_online() on the device
1478 1477 * subtree(s) for this attachment point.
1479 1478 */
1480 1479
1481 1480 if (slotinfop->ostate == AP_OSTATE_CONFIGURED) {
1482 1481 ctrl.flags = PCIHP_CFG_CONTINUE;
1483 1482 ctrl.rv = NDI_SUCCESS;
1484 1483 ctrl.dip = NULL;
1485 1484 ctrl.pci_dev = pci_dev;
1486 1485 ctrl.op = PCIHP_ONLINE;
1487 1486
1488 1487 ndi_devi_enter(self, &circular_count);
1489 1488 ddi_walk_devs(ddi_get_child(self), pcihp_configure,
1490 1489 (void *)&ctrl);
1491 1490 ndi_devi_exit(self, circular_count);
1492 1491
1493 1492 if (ctrl.rv != NDI_SUCCESS) {
1494 1493 /*
1495 1494 * one or more of the devices are not
1496 1495 * onlined. How is this to be reported?
1497 1496 */
1498 1497 cmn_err(CE_WARN,
1499 1498 "pcihp (%s%d): failed to attach one or"
1500 1499 " more drivers for the card in the slot %s",
1501 1500 ddi_driver_name(self), ddi_get_instance(self),
1502 1501 slotinfop->name);
1503 1502 /* rv = EFAULT; */
1504 1503 }
1505 1504 /* tell HPC driver that the occupant is configured */
1506 1505 (void) hpc_nexus_control(slotinfop->slot_hdl,
1507 1506 HPC_CTRL_DEV_CONFIGURED, NULL);
1508 1507
1509 1508 if (drv_getparm(TIME, (void *)&time) != DDI_SUCCESS)
1510 1509 slotinfop->last_change = (time_t)-1;
1511 1510 else
1512 1511 slotinfop->last_change = (time32_t)time;
1513 1512
1514 1513
1515 1514 return (rv);
1516 1515 }
1517 1516
1518 1517 /*
1519 1518 * Occupant is in the UNCONFIGURED state.
1520 1519 */
1521 1520
1522 1521 /* Check if the receptacle is in the CONNECTED state. */
1523 1522 if (hpc_nexus_control(slotinfop->slot_hdl,
1524 1523 HPC_CTRL_GET_SLOT_STATE, (caddr_t)&rstate) != 0) {
1525 1524
1526 1525 return (ENXIO);
1527 1526 }
1528 1527
1529 1528 if (rstate == HPC_SLOT_EMPTY) {
1530 1529 /* error. slot is empty */
1531 1530
1532 1531 return (ENXIO);
1533 1532 }
1534 1533
1535 1534 if (rstate != HPC_SLOT_CONNECTED) {
1536 1535 /* error. either the slot is empty or connect failed */
1537 1536
1538 1537 return (ENXIO);
1539 1538 }
1540 1539
1541 1540 slotinfop->rstate = AP_RSTATE_CONNECTED; /* record rstate */
1542 1541
1543 1542 /* Turn INS and LED off, and start configuration. */
1544 1543 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
1545 1544 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_SLOT_CONFIGURE);
1546 1545 if (pcihp_cpci_blue_led)
1547 1546 pcihp_hs_csr_op(pcihp_p, pci_dev,
1548 1547 HPC_EVENT_SLOT_BLUE_LED_OFF);
1549 1548 slotinfop->slot_flags &= ~PCIHP_SLOT_ENUM_INS_PENDING;
1550 1549 }
1551 1550
1552 1551 (void) hpc_nexus_control(slotinfop->slot_hdl,
1553 1552 HPC_CTRL_DEV_CONFIG_START, NULL);
1554 1553
1555 1554 /*
1556 1555 * Call the configurator to configure the card.
1557 1556 */
1558 1557 if (pcicfg_configure(self, pci_dev, PCICFG_ALL_FUNC, 0)
1559 1558 != PCICFG_SUCCESS) {
1560 1559 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
1561 1560 if (pcihp_cpci_blue_led)
1562 1561 pcihp_hs_csr_op(pcihp_p, pci_dev,
1563 1562 HPC_EVENT_SLOT_BLUE_LED_ON);
1564 1563 pcihp_hs_csr_op(pcihp_p, pci_dev,
1565 1564 HPC_EVENT_SLOT_UNCONFIGURE);
1566 1565 }
1567 1566 /* tell HPC driver occupant configure Error */
1568 1567 (void) hpc_nexus_control(slotinfop->slot_hdl,
1569 1568 HPC_CTRL_DEV_CONFIG_FAILURE, NULL);
1570 1569
1571 1570 return (EIO);
1572 1571 }
1573 1572
1574 1573 /* record the occupant state as CONFIGURED */
1575 1574 slotinfop->ostate = AP_OSTATE_CONFIGURED;
1576 1575 slotinfop->condition = AP_COND_OK;
1577 1576
1578 1577 /* now, online all the devices in the AP */
1579 1578 ctrl.flags = PCIHP_CFG_CONTINUE;
1580 1579 ctrl.rv = NDI_SUCCESS;
1581 1580 ctrl.dip = NULL;
1582 1581 ctrl.pci_dev = pci_dev;
1583 1582 ctrl.op = PCIHP_ONLINE;
1584 1583
1585 1584 ndi_devi_enter(self, &circular_count);
1586 1585 ddi_walk_devs(ddi_get_child(self), pcihp_configure, (void *)&ctrl);
1587 1586 ndi_devi_exit(self, circular_count);
1588 1587
1589 1588 if (ctrl.rv != NDI_SUCCESS) {
1590 1589 /*
1591 1590 * one or more of the devices are not
1592 1591 * ONLINE'd. How is this to be
1593 1592 * reported?
1594 1593 */
1595 1594 cmn_err(CE_WARN,
1596 1595 "pcihp (%s%d): failed to attach one or"
1597 1596 " more drivers for the card in the slot %s",
1598 1597 ddi_driver_name(pcihp_p->dip),
1599 1598 ddi_get_instance(pcihp_p->dip),
1600 1599 slotinfop->name);
1601 1600 /* rv = EFAULT; */
1602 1601 }
1603 1602 /* store HS_CSR location. No events, jut a read operation. */
1604 1603 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI)
1605 1604 pcihp_hs_csr_op(pcihp_p, pci_dev, -1);
1606 1605
1607 1606 /* tell HPC driver that the occupant is configured */
1608 1607 (void) hpc_nexus_control(slotinfop->slot_hdl,
1609 1608 HPC_CTRL_DEV_CONFIGURED, NULL);
1610 1609
1611 1610
1612 1611 return (rv);
1613 1612 }
1614 1613
1615 1614 /*
1616 1615 * **************************************
1617 1616 * UNCONFIGURE the occupant in the slot.
1618 1617 * **************************************
1619 1618 */
1620 1619 static int
1621 1620 pcihp_unconfigure_ap(pcihp_t *pcihp_p, int pci_dev)
1622 1621 {
1623 1622 dev_info_t *self = pcihp_p->dip;
1624 1623 int rv = HPC_SUCCESS;
1625 1624 struct pcihp_slotinfo *slotinfop;
1626 1625 struct pcihp_config_ctrl ctrl;
1627 1626 int circular_count;
1628 1627 time_t time;
1629 1628
1630 1629 /*
1631 1630 * check for valid request:
1632 1631 * 1. It is a hotplug slot.
1633 1632 * 2. The occupant is in the CONFIGURED state.
1634 1633 */
1635 1634 slotinfop = &pcihp_p->slotinfo[pci_dev];
1636 1635
1637 1636
1638 1637
1639 1638 if ((pci_dev >= PCI_MAX_DEVS) || (slotinfop->slot_hdl == NULL) ||
1640 1639 (slotinfop->slot_flags & PCIHP_SLOT_DISABLED)) {
1641 1640
1642 1641 return (ENXIO);
1643 1642 }
1644 1643 /*
1645 1644 * The following may not need to be there, as we should
1646 1645 * support unconfiguring of boards and free resources
1647 1646 * even when the board is not hotswappable. But this is
1648 1647 * the only way, we may be able to tell the system
1649 1648 * administrator that it is not a hotswap board since
1650 1649 * disconnect operation is never called.
1651 1650 * This way we help the system administrator from not
1652 1651 * accidentally removing a non hotswap board and
1653 1652 * possibly destroying it. May be this behavior can
1654 1653 * be a default, and can be enabled or disabled via
1655 1654 * a global flag.
1656 1655 */
1657 1656 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
1658 1657 if (slotinfop->slot_flags & PCIHP_SLOT_DEV_NON_HOTPLUG) {
1659 1658 /* Operation unsupported if no HS board/slot */
1660 1659 return (ENOTSUP);
1661 1660 }
1662 1661 }
1663 1662
1664 1663 /*
1665 1664 * If the occupant is in the CONFIGURED state then
1666 1665 * call the configurator to unconfigure the slot.
1667 1666 */
1668 1667 if (slotinfop->ostate == AP_OSTATE_CONFIGURED) {
1669 1668
1670 1669 /*
1671 1670 * since potential state change is imminent mask
1672 1671 * enum events to prevent the slot from being re-configured
1673 1672 */
1674 1673 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_DISABLE_ENUM);
1675 1674
1676 1675 /*
1677 1676 * Detach all the drivers for the devices in the
1678 1677 * slot. Call pcihp_configure() to do this.
1679 1678 */
1680 1679 ctrl.flags = 0;
1681 1680 ctrl.rv = NDI_SUCCESS;
1682 1681 ctrl.dip = NULL;
1683 1682 ctrl.pci_dev = pci_dev;
1684 1683 ctrl.op = PCIHP_OFFLINE;
1685 1684
1686 1685 (void) devfs_clean(self, NULL, DV_CLEAN_FORCE);
1687 1686 ndi_devi_enter(self, &circular_count);
1688 1687 ddi_walk_devs(ddi_get_child(self), pcihp_configure,
1689 1688 (void *)&ctrl);
1690 1689 ndi_devi_exit(self, circular_count);
1691 1690
1692 1691 if (ctrl.rv != NDI_SUCCESS) {
1693 1692 /*
1694 1693 * Failed to detach one or more drivers
1695 1694 * Restore the state of drivers which
1696 1695 * are offlined during this operation.
1697 1696 */
1698 1697 ctrl.flags = 0;
1699 1698 ctrl.rv = NDI_SUCCESS;
1700 1699 ctrl.dip = NULL;
1701 1700 ctrl.pci_dev = pci_dev;
1702 1701 ctrl.op = PCIHP_ONLINE;
1703 1702
1704 1703 ndi_devi_enter(self, &circular_count);
1705 1704 ddi_walk_devs(ddi_get_child(self),
1706 1705 pcihp_configure, (void *)&ctrl);
1707 1706 ndi_devi_exit(self, circular_count);
1708 1707
1709 1708 /* tell HPC driver that the occupant is Busy */
1710 1709 (void) hpc_nexus_control(slotinfop->slot_hdl,
1711 1710 HPC_CTRL_DEV_UNCONFIG_FAILURE, NULL);
1712 1711
1713 1712 rv = EBUSY;
1714 1713 } else {
1715 1714 (void) hpc_nexus_control(slotinfop->slot_hdl,
1716 1715 HPC_CTRL_DEV_UNCONFIG_START, NULL);
1717 1716
1718 1717 if (pcicfg_unconfigure(self, pci_dev,
1719 1718 PCICFG_ALL_FUNC, 0) == PCICFG_SUCCESS) {
1720 1719 /*
1721 1720 * Now that resources are freed,
1722 1721 * clear EXT and Turn LED ON.
1723 1722 */
1724 1723 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
1725 1724 pcihp_hs_csr_op(pcihp_p, pci_dev,
1726 1725 HPC_EVENT_SLOT_UNCONFIGURE);
1727 1726 if (pcihp_cpci_blue_led)
1728 1727 pcihp_hs_csr_op(pcihp_p,
1729 1728 pci_dev,
1730 1729 HPC_EVENT_SLOT_BLUE_LED_ON);
1731 1730 slotinfop->hs_csr_location = 0;
1732 1731 slotinfop->slot_flags &=
1733 1732 ~(PCIHP_SLOT_DEV_NON_HOTPLUG|
1734 1733 PCIHP_SLOT_ENUM_EXT_PENDING);
1735 1734 }
1736 1735 slotinfop->ostate = AP_OSTATE_UNCONFIGURED;
1737 1736 slotinfop->condition = AP_COND_UNKNOWN;
1738 1737 /*
1739 1738 * send the notification of state change
1740 1739 * to the HPC driver.
1741 1740 */
1742 1741 (void) hpc_nexus_control(slotinfop->slot_hdl,
1743 1742 HPC_CTRL_DEV_UNCONFIGURED,
1744 1743 NULL);
1745 1744 } else {
1746 1745 /* tell HPC driver occupant unconfigure Error */
1747 1746 (void) hpc_nexus_control(slotinfop->slot_hdl,
1748 1747 HPC_CTRL_DEV_UNCONFIG_FAILURE, NULL);
1749 1748
1750 1749 rv = EIO;
1751 1750 }
1752 1751 }
1753 1752 }
1754 1753
1755 1754 if (drv_getparm(TIME, (void *)&time) != DDI_SUCCESS)
1756 1755 slotinfop->last_change = (time_t)-1;
1757 1756 else
1758 1757 slotinfop->last_change = (time32_t)time;
1759 1758
1760 1759
1761 1760
1762 1761 /* unmask enum events again */
1763 1762 if ((slotinfop->slot_flags & PCIHP_SLOT_AUTO_CFG_EN) == 0) {
1764 1763 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_ENABLE_ENUM);
1765 1764 }
1766 1765
1767 1766 return (rv);
1768 1767 }
1769 1768
1770 1769 /*
1771 1770 * Accessor function to return pointer to the pci hotplug
1772 1771 * cb_ops structure.
1773 1772 */
1774 1773 struct cb_ops *
1775 1774 pcihp_get_cb_ops()
1776 1775 {
1777 1776 return (&pcihp_cb_ops);
1778 1777 }
1779 1778
1780 1779 /*
1781 1780 * Setup function to initialize hot plug feature. Returns DDI_SUCCESS
1782 1781 * for successful initialization, otherwise it returns DDI_FAILURE.
1783 1782 *
1784 1783 * It is assumed that this this function is called from the attach()
1785 1784 * entry point of the PCI nexus driver.
1786 1785 */
1787 1786
1788 1787 int
1789 1788 pcihp_init(dev_info_t *dip)
1790 1789 {
1791 1790 pcihp_t *pcihp_p;
1792 1791 int i;
1793 1792 caddr_t enum_data;
1794 1793 int enum_size;
1795 1794 int rv;
1796 1795
1797 1796 mutex_enter(&pcihp_open_mutex);
1798 1797
1799 1798 /*
1800 1799 * Make sure that it is not already initialized.
1801 1800 */
1802 1801 if (pcihp_get_soft_state(dip, PCIHP_DR_NOOP, &rv) != NULL) {
1803 1802 cmn_err(CE_WARN, "%s%d: pcihp instance already initialized!",
1804 1803 ddi_driver_name(dip), ddi_get_instance(dip));
1805 1804 goto cleanup;
1806 1805 }
1807 1806
1808 1807 /*
1809 1808 * Initialize soft state structure for the bus instance.
1810 1809 */
1811 1810 if ((pcihp_p = pcihp_create_soft_state(dip)) == NULL) {
1812 1811 cmn_err(CE_WARN, "%s%d: can't allocate pcihp structure",
1813 1812 ddi_driver_name(dip), ddi_get_instance(dip));
1814 1813 goto cleanup;
1815 1814 }
1816 1815
1817 1816 pcihp_p->soft_state = PCIHP_SOFT_STATE_CLOSED;
1818 1817 /* XXX if bus is running at 66Mhz then set PCI_BUS_66MHZ bit */
1819 1818 pcihp_p->bus_flags = 0; /* XXX FIX IT */
1820 1819
1821 1820 /*
1822 1821 * If a platform wishes to implement Radial ENUM# routing
1823 1822 * a property "enum-impl" must be presented to us with a
1824 1823 * string value "radial".
1825 1824 * This helps us not go for polling operation (default)
1826 1825 * during a ENUM# event.
1827 1826 */
1828 1827 if (ddi_getlongprop(DDI_DEV_T_ANY, dip, 0, "enum-impl",
1829 1828 (caddr_t)&enum_data, &enum_size) == DDI_PROP_SUCCESS) {
1830 1829 if (strcmp(enum_data, "radial") == 0) {
1831 1830 pcihp_p->bus_flags |= PCIHP_BUS_ENUM_RADIAL;
1832 1831 }
1833 1832 kmem_free(enum_data, enum_size);
1834 1833 }
1835 1834
1836 1835 for (i = 0; i < PCI_MAX_DEVS; i++) {
1837 1836 /* initialize slot mutex */
1838 1837 mutex_init(&pcihp_p->slotinfo[i].slot_mutex, NULL,
1839 1838 MUTEX_DRIVER, NULL);
1840 1839 }
1841 1840
1842 1841 /*
1843 1842 * register the bus instance with the HPS framework.
1844 1843 */
1845 1844 if (hpc_nexus_register_bus(dip, pcihp_new_slot_state, 0) != 0) {
1846 1845 cmn_err(CE_WARN, "%s%d: failed to register the bus with HPS",
1847 1846 ddi_driver_name(dip), ddi_get_instance(dip));
1848 1847 goto cleanup1;
1849 1848 }
1850 1849
1851 1850 /*
1852 1851 * Create the "devctl" minor for hot plug support. The minor
1853 1852 * number for "devctl" node is in the same format as the AP
1854 1853 * minor nodes.
1855 1854 */
1856 1855 if (ddi_create_minor_node(dip, "devctl", S_IFCHR,
1857 1856 PCIHP_AP_MINOR_NUM(ddi_get_instance(dip), PCIHP_DEVCTL_MINOR),
1858 1857 DDI_NT_NEXUS, 0) != DDI_SUCCESS)
1859 1858 goto cleanup2;
1860 1859
1861 1860 /*
1862 1861 * Setup resource maps for this bus node. (Note: This can
1863 1862 * be done from the attach(9E) of the nexus itself.)
1864 1863 */
1865 1864 (void) pci_resource_setup(dip);
1866 1865
1867 1866 pcihp_p->bus_state = PCIHP_BUS_CONFIGURED;
1868 1867
1869 1868 mutex_exit(&pcihp_open_mutex);
1870 1869
1871 1870 return (DDI_SUCCESS);
1872 1871
1873 1872 cleanup2:
1874 1873 (void) hpc_nexus_unregister_bus(dip);
1875 1874 cleanup1:
1876 1875 for (i = 0; i < PCI_MAX_DEVS; i++)
1877 1876 mutex_destroy(&pcihp_p->slotinfo[i].slot_mutex);
1878 1877 pcihp_destroy_soft_state(dip);
1879 1878 cleanup:
1880 1879 mutex_exit(&pcihp_open_mutex);
1881 1880 return (DDI_FAILURE);
1882 1881 }
1883 1882
1884 1883 /*
1885 1884 * pcihp_uninit()
1886 1885 *
1887 1886 * The bus instance is going away, cleanup any data associated with
1888 1887 * the management of hot plug slots. It is assumed that this function
1889 1888 * is called from detach() routine of the PCI nexus driver. Also,
1890 1889 * it is assumed that no devices on the bus are in the configured state.
1891 1890 */
1892 1891 int
1893 1892 pcihp_uninit(dev_info_t *dip)
1894 1893 {
1895 1894 pcihp_t *pcihp_p;
1896 1895 int i, j;
1897 1896 int rv;
1898 1897
1899 1898 mutex_enter(&pcihp_open_mutex);
1900 1899 /* get a pointer to the soft state structure */
1901 1900 pcihp_p = pcihp_get_soft_state(dip, PCIHP_DR_BUS_UNCONFIGURE, &rv);
1902 1901 ASSERT(pcihp_p != NULL);
1903 1902
1904 1903 /* slot mutexes should prevent any configure/unconfigure access */
1905 1904 for (i = 0; i < PCI_MAX_DEVS; i++) {
1906 1905 if (!mutex_tryenter(&pcihp_p->slotinfo[i].slot_mutex)) {
1907 1906 for (j = 0; j < i; j++) {
1908 1907 mutex_exit(&pcihp_p->slotinfo[j].slot_mutex);
1909 1908 }
1910 1909 mutex_exit(&pcihp_open_mutex);
1911 1910 return (DDI_FAILURE);
1912 1911 }
1913 1912 }
1914 1913
1915 1914 if ((pcihp_p->soft_state != PCIHP_SOFT_STATE_CLOSED) ||
1916 1915 (rv == PCIHP_FAILURE)) {
1917 1916 cmn_err(CE_WARN, "%s%d: pcihp instance is busy",
1918 1917 ddi_driver_name(dip), ddi_get_instance(dip));
1919 1918 for (i = 0; i < PCI_MAX_DEVS; i++) {
1920 1919 mutex_exit(&pcihp_p->slotinfo[i].slot_mutex);
1921 1920 }
1922 1921 mutex_exit(&pcihp_open_mutex);
1923 1922 return (DDI_FAILURE);
1924 1923 }
1925 1924
1926 1925 /*
1927 1926 * Unregister the bus with the HPS.
1928 1927 *
1929 1928 * (Note: It is assumed that the HPS framework uninstalls
1930 1929 * event handlers for all the hot plug slots on this bus.)
1931 1930 */
1932 1931 (void) hpc_nexus_unregister_bus(dip);
1933 1932
1934 1933 /* Free up any kmem_alloc'd memory for slot info table. */
1935 1934 for (i = 0; i < PCI_MAX_DEVS; i++) {
1936 1935 /* free up slot name strings */
1937 1936 if (pcihp_p->slotinfo[i].name != NULL)
1938 1937 kmem_free(pcihp_p->slotinfo[i].name,
1939 1938 strlen(pcihp_p->slotinfo[i].name) + 1);
1940 1939 }
1941 1940
1942 1941 /* destroy slot mutexes */
1943 1942 for (i = 0; i < PCI_MAX_DEVS; i++)
1944 1943 mutex_destroy(&pcihp_p->slotinfo[i].slot_mutex);
1945 1944
1946 1945 ddi_remove_minor_node(dip, NULL);
1947 1946
1948 1947 /* free up the soft state structure */
1949 1948 pcihp_destroy_soft_state(dip);
1950 1949
1951 1950 /*
1952 1951 * Destroy resource maps for this bus node. (Note: This can
1953 1952 * be done from the detach(9E) of the nexus itself.)
1954 1953 */
1955 1954 (void) pci_resource_destroy(dip);
1956 1955
1957 1956 mutex_exit(&pcihp_open_mutex);
1958 1957
1959 1958 return (DDI_SUCCESS);
1960 1959 }
1961 1960
1962 1961 /*
1963 1962 * pcihp_new_slot_state()
1964 1963 *
1965 1964 * This function is called by the HPS when it finds a hot plug
1966 1965 * slot is added or being removed from the hot plug framework.
1967 1966 * It returns 0 for success and HPC_ERR_FAILED for errors.
1968 1967 */
1969 1968 static int
1970 1969 pcihp_new_slot_state(dev_info_t *dip, hpc_slot_t hdl,
1971 1970 hpc_slot_info_t *slot_info, int slot_state)
1972 1971 {
1973 1972 pcihp_t *pcihp_p;
1974 1973 struct pcihp_slotinfo *slotinfop;
1975 1974 int pci_dev;
1976 1975 minor_t ap_minor;
1977 1976 major_t ap_major;
1978 1977 int rv = 0;
1979 1978 time_t time;
1980 1979 int auto_enable = 1;
1981 1980 int rval;
1982 1981
1983 1982 /* get a pointer to the soft state structure */
1984 1983 pcihp_p = pcihp_get_soft_state(dip, PCIHP_DR_SLOT_ENTER, &rval);
1985 1984 ASSERT(pcihp_p != NULL);
1986 1985
1987 1986 if (rval == PCIHP_FAILURE) {
1988 1987 PCIHP_DEBUG((CE_WARN, "pcihp instance is unconfigured"
1989 1988 " while slot activity is requested\n"));
1990 1989 return (HPC_ERR_FAILED);
1991 1990 }
1992 1991
1993 1992 pci_dev = slot_info->pci_dev_num;
1994 1993 slotinfop = &pcihp_p->slotinfo[pci_dev];
1995 1994
1996 1995 mutex_enter(&slotinfop->slot_mutex);
1997 1996
1998 1997 switch (slot_state) {
1999 1998
2000 1999 case HPC_SLOT_ONLINE:
2001 2000
2002 2001 /*
2003 2002 * Make sure the slot is not already ONLINE (paranoia?).
2004 2003 * (Note: Should this be simply an ASSERTION?)
2005 2004 */
2006 2005 if (slotinfop->slot_hdl != NULL) {
2007 2006 PCIHP_DEBUG((CE_WARN,
2008 2007 "pcihp (%s%d): pci slot (dev %x) already ONLINE!!",
2009 2008 ddi_driver_name(dip), ddi_get_instance(dip),
2010 2009 pci_dev));
2011 2010 rv = HPC_ERR_FAILED;
2012 2011 break;
2013 2012 }
2014 2013
2015 2014 /*
2016 2015 * Add the hot plug slot to the bus.
2017 2016 */
2018 2017
2019 2018 /* create the AP minor node */
2020 2019 ap_minor = PCIHP_AP_MINOR_NUM(ddi_get_instance(dip), pci_dev);
2021 2020 if (ddi_create_minor_node(dip, slot_info->pci_slot_name,
2022 2021 S_IFCHR, ap_minor,
2023 2022 DDI_NT_PCI_ATTACHMENT_POINT, 0) == DDI_FAILURE) {
2024 2023 cmn_err(CE_WARN,
2025 2024 "pcihp (%s%d): ddi_create_minor_node failed"
2026 2025 " for pci dev %x", ddi_driver_name(dip),
2027 2026 ddi_get_instance(dip), pci_dev);
2028 2027 rv = HPC_ERR_FAILED;
2029 2028 break;
2030 2029 }
2031 2030
2032 2031 /* save the slot handle */
2033 2032 slotinfop->slot_hdl = hdl;
2034 2033
2035 2034 /* setup event handler for all hardware events on the slot */
2036 2035 ap_major = ddi_driver_major(dip);
2037 2036 if (hpc_install_event_handler(hdl, -1, pcihp_event_handler,
2038 2037 (caddr_t)makedevice(ap_major, ap_minor)) != 0) {
2039 2038 cmn_err(CE_WARN,
2040 2039 "pcihp (%s%d): install event handler failed"
2041 2040 " for pci dev %x", ddi_driver_name(dip),
2042 2041 ddi_get_instance(dip), pci_dev);
2043 2042 rv = HPC_ERR_FAILED;
2044 2043 break;
2045 2044 }
2046 2045 slotinfop->event_mask = (uint32_t)0xFFFFFFFF;
2047 2046
2048 2047 pcihp_create_occupant_props(dip, makedevice(ap_major,
2049 2048 ap_minor), pci_dev);
2050 2049
2051 2050 /* set default auto configuration enabled flag for this slot */
2052 2051 slotinfop->slot_flags = pcihp_autocfg_enabled;
2053 2052
2054 2053 /* copy the slot information */
2055 2054 slotinfop->name =
2056 2055 kmem_alloc(strlen(slot_info->pci_slot_name) + 1, KM_SLEEP);
2057 2056 (void) strcpy(slotinfop->name, slot_info->pci_slot_name);
2058 2057 slotinfop->slot_type = slot_info->slot_type;
2059 2058 slotinfop->hs_csr_location = 0;
2060 2059 slotinfop->slot_capabilities = slot_info->pci_slot_capabilities;
2061 2060 if (slot_info->slot_flags & HPC_SLOT_NO_AUTO_ENABLE)
2062 2061 auto_enable = 0;
2063 2062
2064 2063 if (slot_info->slot_flags & HPC_SLOT_CREATE_DEVLINK) {
2065 2064 pci_devlink_flags |= (1 << pci_dev);
2066 2065 (void) ddi_prop_update_int(DDI_DEV_T_NONE,
2067 2066 dip, "ap-names", pci_devlink_flags);
2068 2067 }
2069 2068
2070 2069 PCIHP_DEBUG((CE_NOTE,
2071 2070 "pcihp (%s%d): pci slot (dev %x) ONLINE\n",
2072 2071 ddi_driver_name(dip), ddi_get_instance(dip), pci_dev));
2073 2072
2074 2073 /*
2075 2074 * The slot may have an occupant that was configured
2076 2075 * at boot time. If we find a devinfo node in the tree
2077 2076 * for this slot (i.e pci device number) then we
2078 2077 * record the occupant state as CONFIGURED.
2079 2078 */
2080 2079 if (pcihp_devi_find(dip, pci_dev, 0) != NULL) {
2081 2080 /* we have a configured occupant */
2082 2081 slotinfop->ostate = AP_OSTATE_CONFIGURED;
2083 2082 slotinfop->rstate = AP_RSTATE_CONNECTED;
2084 2083 slotinfop->condition = AP_COND_OK;
2085 2084
2086 2085 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
2087 2086 /* this will set slot flags too. */
2088 2087 (void) pcihp_get_board_type(slotinfop);
2089 2088 pcihp_hs_csr_op(pcihp_p, pci_dev,
2090 2089 HPC_EVENT_SLOT_CONFIGURE);
2091 2090 if (pcihp_cpci_blue_led)
2092 2091 pcihp_hs_csr_op(pcihp_p, pci_dev,
2093 2092 HPC_EVENT_SLOT_BLUE_LED_OFF);
2094 2093 /* ENUM# enabled by default for cPCI devices */
2095 2094 slotinfop->slot_flags |= PCIHP_SLOT_AUTO_CFG_EN;
2096 2095 slotinfop->slot_flags &=
2097 2096 ~PCIHP_SLOT_ENUM_INS_PENDING;
2098 2097 }
2099 2098
2100 2099 /* tell HPC driver that the occupant is configured */
2101 2100 (void) hpc_nexus_control(slotinfop->slot_hdl,
2102 2101 HPC_CTRL_DEV_CONFIGURED, NULL);
2103 2102
2104 2103 /*
2105 2104 * Tell sysevent listeners that slot has
2106 2105 * changed state. At minimum, this is useful
2107 2106 * when a PCI-E Chassis (containing Occupants) is
2108 2107 * hotplugged. In this case, the following will
2109 2108 * announce that the Occupant in the Receptacle
2110 2109 * in the Chassis had a state-change.
2111 2110 */
2112 2111 pcihp_gen_sysevent(slotinfop->name,
2113 2112 PCIHP_DR_AP_STATE_CHANGE, SE_NO_HINT,
2114 2113 pcihp_p->dip, KM_SLEEP);
2115 2114 } else {
2116 2115 struct pcihp_config_ctrl ctrl;
2117 2116 int circular_count;
2118 2117
2119 2118 slotinfop->ostate = AP_OSTATE_UNCONFIGURED;
2120 2119 slotinfop->rstate = AP_RSTATE_EMPTY;
2121 2120 slotinfop->condition = AP_COND_UNKNOWN;
2122 2121
2123 2122 if (!auto_enable) { /* no further action */
2124 2123 break;
2125 2124 }
2126 2125
2127 2126 /*
2128 2127 * We enable power to the slot and try to
2129 2128 * configure if there is any card present.
2130 2129 *
2131 2130 * Note: This case is possible if the BIOS or
2132 2131 * firmware doesn't enable the slots during
2133 2132 * soft reboot.
2134 2133 */
2135 2134 if (hpc_nexus_connect(slotinfop->slot_hdl,
2136 2135 NULL, 0) != HPC_SUCCESS)
2137 2136 break;
2138 2137
2139 2138 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
2140 2139 pcihp_hs_csr_op(pcihp_p, pci_dev,
2141 2140 HPC_EVENT_SLOT_CONFIGURE);
2142 2141 if (pcihp_cpci_blue_led)
2143 2142 pcihp_hs_csr_op(pcihp_p, pci_dev,
2144 2143 HPC_EVENT_SLOT_BLUE_LED_OFF);
2145 2144 slotinfop->slot_flags |= PCIHP_SLOT_AUTO_CFG_EN;
2146 2145 slotinfop->slot_flags &=
2147 2146 ~PCIHP_SLOT_ENUM_INS_PENDING;
2148 2147 }
2149 2148
2150 2149 (void) hpc_nexus_control(slotinfop->slot_hdl,
2151 2150 HPC_CTRL_DEV_CONFIG_START, NULL);
2152 2151
2153 2152 /*
2154 2153 * Call the configurator to configure the card.
2155 2154 */
2156 2155 if (pcicfg_configure(dip, pci_dev, PCICFG_ALL_FUNC, 0)
2157 2156 != PCICFG_SUCCESS) {
2158 2157 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
2159 2158 if (pcihp_cpci_blue_led)
2160 2159 pcihp_hs_csr_op(pcihp_p,
2161 2160 pci_dev,
2162 2161 HPC_EVENT_SLOT_BLUE_LED_ON);
2163 2162 pcihp_hs_csr_op(pcihp_p, pci_dev,
2164 2163 HPC_EVENT_SLOT_UNCONFIGURE);
2165 2164 }
2166 2165
2167 2166 /* tell HPC driver occupant configure Error */
2168 2167 (void) hpc_nexus_control(slotinfop->slot_hdl,
2169 2168 HPC_CTRL_DEV_CONFIG_FAILURE, NULL);
2170 2169
2171 2170 /*
2172 2171 * call HPC driver to turn off the power for
2173 2172 * the slot.
2174 2173 */
2175 2174 (void) hpc_nexus_disconnect(slotinfop->slot_hdl,
2176 2175 NULL, 0);
2177 2176 } else {
2178 2177 /* record the occupant state as CONFIGURED */
2179 2178 slotinfop->ostate = AP_OSTATE_CONFIGURED;
2180 2179 slotinfop->rstate = AP_RSTATE_CONNECTED;
2181 2180 slotinfop->condition = AP_COND_OK;
2182 2181
2183 2182 /* now, online all the devices in the AP */
2184 2183 ctrl.flags = PCIHP_CFG_CONTINUE;
2185 2184 ctrl.rv = NDI_SUCCESS;
2186 2185 ctrl.dip = NULL;
2187 2186 ctrl.pci_dev = pci_dev;
2188 2187 ctrl.op = PCIHP_ONLINE;
2189 2188 /*
2190 2189 * the following sets slot_flags and
2191 2190 * hs_csr_location too.
2192 2191 */
2193 2192 (void) pcihp_get_board_type(slotinfop);
2194 2193
2195 2194 ndi_devi_enter(dip, &circular_count);
2196 2195 ddi_walk_devs(ddi_get_child(dip),
2197 2196 pcihp_configure, (void *)&ctrl);
2198 2197 ndi_devi_exit(dip, circular_count);
2199 2198
2200 2199 if (ctrl.rv != NDI_SUCCESS) {
2201 2200 /*
2202 2201 * one or more of the devices are not
2203 2202 * ONLINE'd. How is this to be
2204 2203 * reported?
2205 2204 */
2206 2205 cmn_err(CE_WARN,
2207 2206 "pcihp (%s%d): failed to attach"
2208 2207 " one or more drivers for the"
2209 2208 " card in the slot %s",
2210 2209 ddi_driver_name(dip),
2211 2210 ddi_get_instance(dip),
2212 2211 slotinfop->name);
2213 2212 }
2214 2213
2215 2214 /* tell HPC driver the Occupant is Configured */
2216 2215 (void) hpc_nexus_control(slotinfop->slot_hdl,
2217 2216 HPC_CTRL_DEV_CONFIGURED, NULL);
2218 2217
2219 2218 /*
2220 2219 * Tell sysevent listeners that slot has
2221 2220 * changed state. At minimum, this is useful
2222 2221 * when a PCI-E Chassis (containing Occupants)
2223 2222 * is hotplugged. In this case, the following
2224 2223 * will announce that the Occupant in the
2225 2224 * Receptacle in the Chassis had a state-change.
2226 2225 */
2227 2226 pcihp_gen_sysevent(slotinfop->name,
2228 2227 PCIHP_DR_AP_STATE_CHANGE, SE_NO_HINT,
2229 2228 pcihp_p->dip, KM_SLEEP);
2230 2229 }
2231 2230 }
2232 2231
2233 2232 break;
2234 2233
2235 2234 case HPC_SLOT_OFFLINE:
2236 2235 /*
2237 2236 * A hot plug slot is being removed from the bus.
2238 2237 * Make sure there is no occupant configured on the
2239 2238 * slot before removing the AP minor node.
2240 2239 */
2241 2240 if (slotinfop->ostate != AP_OSTATE_UNCONFIGURED) {
2242 2241 cmn_err(CE_WARN, "pcihp (%s%d): Card is still in "
2243 2242 "configured state for pci dev %x",
2244 2243 ddi_driver_name(dip), ddi_get_instance(dip),
2245 2244 pci_dev);
2246 2245 rv = HPC_ERR_FAILED;
2247 2246 break;
2248 2247 }
2249 2248
2250 2249 /*
2251 2250 * If the AP device is in open state then return
2252 2251 * error.
2253 2252 */
2254 2253 if (pcihp_p->soft_state != PCIHP_SOFT_STATE_CLOSED) {
2255 2254 rv = HPC_ERR_FAILED;
2256 2255 break;
2257 2256 }
2258 2257 if (slot_info->slot_flags & HPC_SLOT_CREATE_DEVLINK) {
2259 2258 pci_devlink_flags &= ~(1 << pci_dev);
2260 2259 (void) ddi_prop_update_int(DDI_DEV_T_NONE, dip,
2261 2260 "ap-names", pci_devlink_flags);
2262 2261 }
2263 2262
2264 2263 /* remove the minor node */
2265 2264 ddi_remove_minor_node(dip, slotinfop->name);
2266 2265
2267 2266 /* free up the memory for the name string */
2268 2267 kmem_free(slotinfop->name, strlen(slotinfop->name) + 1);
2269 2268
2270 2269 /* update the slot info data */
2271 2270 slotinfop->name = NULL;
2272 2271 slotinfop->slot_hdl = NULL;
2273 2272
2274 2273 PCIHP_DEBUG((CE_NOTE,
2275 2274 "pcihp (%s%d): pci slot (dev %x) OFFLINE\n",
2276 2275 ddi_driver_name(dip), ddi_get_instance(dip),
2277 2276 slot_info->pci_dev_num));
2278 2277
2279 2278 break;
2280 2279 default:
2281 2280 cmn_err(CE_WARN,
2282 2281 "pcihp_new_slot_state: unknown slot_state %d", slot_state);
2283 2282 rv = HPC_ERR_FAILED;
2284 2283 }
2285 2284
2286 2285 if (rv == 0) {
2287 2286 if (drv_getparm(TIME, (void *)&time) != DDI_SUCCESS)
2288 2287 slotinfop->last_change = (time_t)-1;
2289 2288 else
2290 2289 slotinfop->last_change = (time32_t)time;
2291 2290 }
2292 2291
2293 2292 mutex_exit(&slotinfop->slot_mutex);
2294 2293
2295 2294 (void) pcihp_get_soft_state(dip, PCIHP_DR_SLOT_EXIT, &rval);
2296 2295
2297 2296 return (rv);
2298 2297 }
2299 2298
2300 2299 /*
2301 2300 * Event handler. It is assumed that this function is called from
2302 2301 * a kernel context only.
2303 2302 *
2304 2303 * Parameters:
2305 2304 * slot_arg AP minor number.
2306 2305 * event_mask Event that occurred.
2307 2306 */
2308 2307
2309 2308 static int
2310 2309 pcihp_event_handler(caddr_t slot_arg, uint_t event_mask)
2311 2310 {
2312 2311 dev_t ap_dev = (dev_t)slot_arg;
2313 2312 dev_info_t *self;
2314 2313 pcihp_t *pcihp_p;
2315 2314 int pci_dev;
2316 2315 int rv = HPC_EVENT_CLAIMED;
2317 2316 struct pcihp_slotinfo *slotinfop;
2318 2317 struct pcihp_config_ctrl ctrl;
2319 2318 int circular_count;
2320 2319 int rval;
2321 2320 int hint;
2322 2321 hpc_slot_state_t rstate;
2323 2322 struct hpc_led_info led_info;
2324 2323
2325 2324 /*
2326 2325 * Get the soft state structure.
2327 2326 */
2328 2327 if (pcihp_info(NULL, DDI_INFO_DEVT2DEVINFO, (void *)ap_dev,
2329 2328 (void **)&self) != DDI_SUCCESS)
2330 2329 return (ENXIO);
2331 2330
2332 2331 pcihp_p = pcihp_get_soft_state(self, PCIHP_DR_SLOT_ENTER, &rval);
2333 2332 ASSERT(pcihp_p != NULL);
2334 2333
2335 2334 if (rval == PCIHP_FAILURE) {
2336 2335 PCIHP_DEBUG((CE_WARN, "pcihp instance is unconfigured"
2337 2336 " while slot activity is requested\n"));
2338 2337 return (-1);
2339 2338 }
2340 2339
2341 2340 /* get the PCI device number for the slot */
2342 2341 pci_dev = PCIHP_AP_MINOR_NUM_TO_PCI_DEVNUM(getminor(ap_dev));
2343 2342
2344 2343 slotinfop = &pcihp_p->slotinfo[pci_dev];
2345 2344
2346 2345 /*
2347 2346 * All the events that may be handled in interrupt context should be
2348 2347 * free of any mutex usage.
2349 2348 */
2350 2349 switch (event_mask) {
2351 2350
2352 2351 case HPC_EVENT_CLEAR_ENUM:
2353 2352 /*
2354 2353 * Check and clear ENUM# interrupt status. This may be
2355 2354 * called by the Hotswap controller driver when it is
2356 2355 * operating in a full hotswap system where the
2357 2356 * platform may not have control on globally disabling ENUM#.
2358 2357 * In such cases, the intent is to clear interrupt and
2359 2358 * process the interrupt in non-interrupt context.
2360 2359 * This is the first part of the ENUM# event processing.
2361 2360 */
2362 2361 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): ENUM# is generated"
2363 2362 " on the bus (for slot %s ?)",
2364 2363 ddi_driver_name(pcihp_p->dip),
2365 2364 ddi_get_instance(pcihp_p->dip), slotinfop->name));
2366 2365
2367 2366 /* this is the only event coming through in interrupt context */
2368 2367 rv = pcihp_handle_enum(pcihp_p, pci_dev, PCIHP_CLEAR_ENUM,
2369 2368 KM_NOSLEEP);
2370 2369
2371 2370 (void) pcihp_get_soft_state(self, PCIHP_DR_SLOT_EXIT, &rval);
2372 2371
2373 2372 return (rv);
2374 2373 default:
2375 2374 break;
2376 2375 }
2377 2376
2378 2377 mutex_enter(&slotinfop->slot_mutex);
2379 2378
2380 2379 if (hpc_nexus_control(slotinfop->slot_hdl,
2381 2380 HPC_CTRL_GET_SLOT_STATE, (caddr_t)&rstate) != 0)
2382 2381 rv = HPC_ERR_FAILED;
2383 2382
2384 2383 slotinfop->rstate = (ap_rstate_t)rstate;
2385 2384
2386 2385 switch (event_mask) {
2387 2386
2388 2387 case HPC_EVENT_SLOT_INSERTION:
2389 2388 /*
2390 2389 * A card is inserted in the slot. Just report this
2391 2390 * event and return.
2392 2391 */
2393 2392 cmn_err(CE_NOTE, "pcihp (%s%d): card is inserted"
2394 2393 " in the slot %s (pci dev %x)",
2395 2394 ddi_driver_name(pcihp_p->dip),
2396 2395 ddi_get_instance(pcihp_p->dip),
2397 2396 slotinfop->name, pci_dev);
2398 2397
2399 2398 /* +++ HOOK for RCM to report this hotplug event? +++ */
2400 2399
2401 2400 break;
2402 2401
2403 2402 case HPC_EVENT_SLOT_CONFIGURE:
2404 2403 /*
2405 2404 * Configure the occupant that is just inserted in the slot.
2406 2405 * The receptacle may or may not be in the connected state. If
2407 2406 * the receptacle is not connected and the auto configuration
2408 2407 * is enabled on this slot then connect the slot. If auto
2409 2408 * configuration is enabled then configure the card.
2410 2409 */
2411 2410 if ((slotinfop->slot_flags & PCIHP_SLOT_AUTO_CFG_EN) == 0) {
2412 2411 /*
2413 2412 * auto configuration is disabled. Tell someone
2414 2413 * like RCM about this hotplug event?
2415 2414 */
2416 2415 cmn_err(CE_NOTE, "pcihp (%s%d): SLOT_CONFIGURE event"
2417 2416 " occurred for pci dev %x (slot %s),"
2418 2417 " Slot disabled for auto-configuration.",
2419 2418 ddi_driver_name(pcihp_p->dip),
2420 2419 ddi_get_instance(pcihp_p->dip), pci_dev,
2421 2420 slotinfop->name);
2422 2421
2423 2422 /* +++ HOOK for RCM to report this hotplug event? +++ */
2424 2423
2425 2424 break;
2426 2425 }
2427 2426
2428 2427 if (slotinfop->ostate == AP_OSTATE_CONFIGURED) {
2429 2428 cmn_err(CE_WARN, "pcihp (%s%d): SLOT_CONFIGURE event"
2430 2429 " re-occurred for pci dev %x (slot %s),",
2431 2430 ddi_driver_name(pcihp_p->dip),
2432 2431 ddi_get_instance(pcihp_p->dip), pci_dev,
2433 2432 slotinfop->name);
2434 2433 mutex_exit(&slotinfop->slot_mutex);
2435 2434
2436 2435 (void) pcihp_get_soft_state(self, PCIHP_DR_SLOT_EXIT,
2437 2436 &rval);
2438 2437
2439 2438 return (EAGAIN);
2440 2439 }
2441 2440
2442 2441 /*
2443 2442 * Auto configuration is enabled. First, make sure the
2444 2443 * receptacle is in the CONNECTED state.
2445 2444 */
2446 2445 if ((rv = hpc_nexus_connect(slotinfop->slot_hdl,
2447 2446 NULL, 0)) == HPC_SUCCESS) {
2448 2447 /* record rstate */
2449 2448 slotinfop->rstate = AP_RSTATE_CONNECTED;
2450 2449 }
2451 2450
2452 2451 /* Clear INS and Turn LED Off and start configuring. */
2453 2452 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
2454 2453 pcihp_hs_csr_op(pcihp_p, pci_dev,
2455 2454 HPC_EVENT_SLOT_CONFIGURE);
2456 2455 if (pcihp_cpci_blue_led)
2457 2456 pcihp_hs_csr_op(pcihp_p, pci_dev,
2458 2457 HPC_EVENT_SLOT_BLUE_LED_OFF);
2459 2458 }
2460 2459
2461 2460 (void) hpc_nexus_control(slotinfop->slot_hdl,
2462 2461 HPC_CTRL_DEV_CONFIG_START, NULL);
2463 2462
2464 2463 /*
2465 2464 * Call the configurator to configure the card.
2466 2465 */
2467 2466 if (pcicfg_configure(pcihp_p->dip, pci_dev, PCICFG_ALL_FUNC, 0)
2468 2467 != PCICFG_SUCCESS) {
2469 2468 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
2470 2469 if (pcihp_cpci_blue_led)
2471 2470 pcihp_hs_csr_op(pcihp_p, pci_dev,
2472 2471 HPC_EVENT_SLOT_BLUE_LED_ON);
2473 2472 pcihp_hs_csr_op(pcihp_p, pci_dev,
2474 2473 HPC_EVENT_SLOT_UNCONFIGURE);
2475 2474 }
2476 2475 /* failed to configure the card */
2477 2476 cmn_err(CE_WARN, "pcihp (%s%d): failed to configure"
2478 2477 " the card in the slot %s",
2479 2478 ddi_driver_name(pcihp_p->dip),
2480 2479 ddi_get_instance(pcihp_p->dip),
2481 2480 slotinfop->name);
2482 2481 /* failed to configure; disconnect the slot */
2483 2482 if (hpc_nexus_disconnect(slotinfop->slot_hdl,
2484 2483 NULL, 0) == HPC_SUCCESS) {
2485 2484 slotinfop->rstate = AP_RSTATE_DISCONNECTED;
2486 2485 }
2487 2486
2488 2487 /* tell HPC driver occupant configure Error */
2489 2488 (void) hpc_nexus_control(slotinfop->slot_hdl,
2490 2489 HPC_CTRL_DEV_CONFIG_FAILURE, NULL);
2491 2490 } else {
2492 2491 /* record the occupant state as CONFIGURED */
2493 2492 slotinfop->ostate = AP_OSTATE_CONFIGURED;
2494 2493 slotinfop->condition = AP_COND_OK;
2495 2494
2496 2495 /* now, online all the devices in the AP */
2497 2496 ctrl.flags = PCIHP_CFG_CONTINUE;
2498 2497 ctrl.rv = NDI_SUCCESS;
2499 2498 ctrl.dip = NULL;
2500 2499 ctrl.pci_dev = pci_dev;
2501 2500 ctrl.op = PCIHP_ONLINE;
2502 2501 (void) pcihp_get_board_type(slotinfop);
2503 2502
2504 2503 ndi_devi_enter(pcihp_p->dip, &circular_count);
2505 2504 ddi_walk_devs(ddi_get_child(pcihp_p->dip),
2506 2505 pcihp_configure, (void *)&ctrl);
2507 2506 ndi_devi_exit(pcihp_p->dip, circular_count);
2508 2507
2509 2508 if (ctrl.rv != NDI_SUCCESS) {
2510 2509 /*
2511 2510 * one or more of the devices are not
2512 2511 * ONLINE'd. How is this to be
2513 2512 * reported?
2514 2513 */
2515 2514 cmn_err(CE_WARN,
2516 2515 "pcihp (%s%d): failed to attach one or"
2517 2516 " more drivers for the card in"
2518 2517 " the slot %s",
2519 2518 ddi_driver_name(pcihp_p->dip),
2520 2519 ddi_get_instance(pcihp_p->dip),
2521 2520 slotinfop->name);
2522 2521 }
2523 2522
2524 2523 /* tell HPC driver that the occupant is configured */
2525 2524 (void) hpc_nexus_control(slotinfop->slot_hdl,
2526 2525 HPC_CTRL_DEV_CONFIGURED, NULL);
2527 2526
2528 2527 cmn_err(CE_NOTE, "pcihp (%s%d): card is CONFIGURED"
2529 2528 " in the slot %s (pci dev %x)",
2530 2529 ddi_driver_name(pcihp_p->dip),
2531 2530 ddi_get_instance(pcihp_p->dip),
2532 2531 slotinfop->name, pci_dev);
2533 2532 }
2534 2533
2535 2534 break;
2536 2535
2537 2536 case HPC_EVENT_SLOT_UNCONFIGURE:
2538 2537 /*
2539 2538 * Unconfigure the occupant in this slot.
2540 2539 */
2541 2540 if ((slotinfop->slot_flags & PCIHP_SLOT_AUTO_CFG_EN) == 0) {
2542 2541 /*
2543 2542 * auto configuration is disabled. Tell someone
2544 2543 * like RCM about this hotplug event?
2545 2544 */
2546 2545 cmn_err(CE_NOTE, "pcihp (%s%d): SLOT_UNCONFIGURE event"
2547 2546 " for pci dev %x (slot %s) ignored,"
2548 2547 " Slot disabled for auto-configuration.",
2549 2548 ddi_driver_name(pcihp_p->dip),
2550 2549 ddi_get_instance(pcihp_p->dip), pci_dev,
2551 2550 slotinfop->name);
2552 2551
2553 2552 /* +++ HOOK for RCM to report this hotplug event? +++ */
2554 2553
2555 2554 break;
2556 2555 }
2557 2556
2558 2557 if (slotinfop->ostate == AP_OSTATE_UNCONFIGURED) {
2559 2558 cmn_err(CE_WARN, "pcihp (%s%d): SLOT_UNCONFIGURE "
2560 2559 "event re-occurred for pci dev %x (slot %s),",
2561 2560 ddi_driver_name(pcihp_p->dip),
2562 2561 ddi_get_instance(pcihp_p->dip), pci_dev,
2563 2562 slotinfop->name);
2564 2563 mutex_exit(&slotinfop->slot_mutex);
2565 2564
2566 2565 (void) pcihp_get_soft_state(self, PCIHP_DR_SLOT_EXIT,
2567 2566 &rval);
2568 2567
2569 2568 return (EAGAIN);
2570 2569 }
2571 2570 /*
2572 2571 * If the occupant is in the CONFIGURED state then
2573 2572 * call the configurator to unconfigure the slot.
2574 2573 */
2575 2574 if (slotinfop->ostate == AP_OSTATE_CONFIGURED) {
2576 2575 /*
2577 2576 * Detach all the drivers for the devices in the
2578 2577 * slot. Call pcihp_configure() to offline the
2579 2578 * devices.
2580 2579 */
2581 2580 ctrl.flags = 0;
2582 2581 ctrl.rv = NDI_SUCCESS;
2583 2582 ctrl.dip = NULL;
2584 2583 ctrl.pci_dev = pci_dev;
2585 2584 ctrl.op = PCIHP_OFFLINE;
2586 2585
2587 2586 (void) devfs_clean(pcihp_p->dip, NULL, DV_CLEAN_FORCE);
2588 2587 ndi_devi_enter(pcihp_p->dip, &circular_count);
2589 2588 ddi_walk_devs(ddi_get_child(pcihp_p->dip),
2590 2589 pcihp_configure, (void *)&ctrl);
2591 2590 ndi_devi_exit(pcihp_p->dip, circular_count);
2592 2591
2593 2592 if (ctrl.rv != NDI_SUCCESS) {
2594 2593 /*
2595 2594 * Failed to detach one or more drivers.
2596 2595 * Restore the status for the drivers
2597 2596 * which are offlined during this step.
2598 2597 */
2599 2598 ctrl.flags = PCIHP_CFG_CONTINUE;
2600 2599 ctrl.rv = NDI_SUCCESS;
2601 2600 ctrl.dip = NULL;
2602 2601 ctrl.pci_dev = pci_dev;
2603 2602 ctrl.op = PCIHP_ONLINE;
2604 2603
2605 2604 ndi_devi_enter(pcihp_p->dip, &circular_count);
2606 2605 ddi_walk_devs(ddi_get_child(pcihp_p->dip),
2607 2606 pcihp_configure, (void *)&ctrl);
2608 2607 ndi_devi_exit(pcihp_p->dip, circular_count);
2609 2608 rv = HPC_ERR_FAILED;
2610 2609 } else {
2611 2610 (void) hpc_nexus_control(slotinfop->slot_hdl,
2612 2611 HPC_CTRL_DEV_UNCONFIG_START, NULL);
2613 2612
2614 2613 if (pcicfg_unconfigure(pcihp_p->dip, pci_dev,
2615 2614 PCICFG_ALL_FUNC, 0) == PCICFG_SUCCESS) {
2616 2615
2617 2616 /* Resources freed. Turn LED on. Clear EXT. */
2618 2617 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
2619 2618 if (pcihp_cpci_blue_led)
2620 2619 pcihp_hs_csr_op(pcihp_p,
2621 2620 pci_dev,
2622 2621 HPC_EVENT_SLOT_BLUE_LED_ON);
2623 2622 pcihp_hs_csr_op(pcihp_p, pci_dev,
2624 2623 HPC_EVENT_SLOT_UNCONFIGURE);
2625 2624 slotinfop->hs_csr_location = 0;
2626 2625 slotinfop->slot_flags &=
2627 2626 ~PCIHP_SLOT_DEV_NON_HOTPLUG;
2628 2627 }
2629 2628 slotinfop->ostate =
2630 2629 AP_OSTATE_UNCONFIGURED;
2631 2630 slotinfop->condition = AP_COND_UNKNOWN;
2632 2631 /*
2633 2632 * send the notification of state change
2634 2633 * to the HPC driver.
2635 2634 */
2636 2635 (void) hpc_nexus_control(
2637 2636 slotinfop->slot_hdl,
2638 2637 HPC_CTRL_DEV_UNCONFIGURED, NULL);
2639 2638 /* disconnect the slot */
2640 2639 if (hpc_nexus_disconnect(
2641 2640 slotinfop->slot_hdl,
2642 2641 NULL, 0) == HPC_SUCCESS) {
2643 2642 slotinfop->rstate =
2644 2643 AP_RSTATE_DISCONNECTED;
2645 2644 }
2646 2645
2647 2646 cmn_err(CE_NOTE,
2648 2647 "pcihp (%s%d): card is UNCONFIGURED"
2649 2648 " in the slot %s (pci dev %x)",
2650 2649 ddi_driver_name(pcihp_p->dip),
2651 2650 ddi_get_instance(pcihp_p->dip),
2652 2651 slotinfop->name, pci_dev);
2653 2652 } else {
2654 2653 /* tell HPC driver occupant is Busy */
2655 2654 (void) hpc_nexus_control(
2656 2655 slotinfop->slot_hdl,
2657 2656 HPC_CTRL_DEV_UNCONFIG_FAILURE,
2658 2657 NULL);
2659 2658
2660 2659 rv = HPC_ERR_FAILED;
2661 2660 }
2662 2661 }
2663 2662 }
2664 2663
2665 2664 /* +++ HOOK for RCM to report this hotplug event? +++ */
2666 2665
2667 2666 break;
2668 2667
2669 2668 case HPC_EVENT_SLOT_REMOVAL:
2670 2669 /*
2671 2670 * Card is removed from the slot. The card must have been
2672 2671 * unconfigured before this event.
2673 2672 */
2674 2673 if (slotinfop->ostate != AP_OSTATE_UNCONFIGURED) {
2675 2674 slotinfop->condition = AP_COND_FAILED;
2676 2675 cmn_err(CE_WARN, "pcihp (%s%d): card is removed"
2677 2676 " from the slot %s",
2678 2677 ddi_driver_name(pcihp_p->dip),
2679 2678 ddi_get_instance(pcihp_p->dip),
2680 2679 slotinfop->name);
2681 2680 } else {
2682 2681 slotinfop->condition = AP_COND_UNKNOWN;
2683 2682 cmn_err(CE_NOTE, "pcihp (%s%d): card is removed"
2684 2683 " from the slot %s",
2685 2684 ddi_driver_name(pcihp_p->dip),
2686 2685 ddi_get_instance(pcihp_p->dip),
2687 2686 slotinfop->name);
2688 2687 }
2689 2688
2690 2689 slotinfop->rstate = AP_RSTATE_EMPTY;
2691 2690
2692 2691 /* +++ HOOK for RCM to report this hotplug event? +++ */
2693 2692
2694 2693 break;
2695 2694
2696 2695 case HPC_EVENT_SLOT_POWER_ON:
2697 2696 /*
2698 2697 * Slot is connected to the bus. i.e the card is powered
2699 2698 * on. Are there any error conditions to be checked?
2700 2699 */
2701 2700 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): card is powered"
2702 2701 " on in the slot %s",
2703 2702 ddi_driver_name(pcihp_p->dip),
2704 2703 ddi_get_instance(pcihp_p->dip),
2705 2704 slotinfop->name));
2706 2705
2707 2706 slotinfop->rstate = AP_RSTATE_CONNECTED; /* record rstate */
2708 2707
2709 2708 /* +++ HOOK for RCM to report this hotplug event? +++ */
2710 2709
2711 2710 break;
2712 2711
2713 2712 case HPC_EVENT_SLOT_POWER_OFF:
2714 2713 /*
2715 2714 * Slot is disconnected from the bus. i.e the card is powered
2716 2715 * off. Are there any error conditions to be checked?
2717 2716 */
2718 2717 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): card is powered"
2719 2718 " off in the slot %s",
2720 2719 ddi_driver_name(pcihp_p->dip),
2721 2720 ddi_get_instance(pcihp_p->dip),
2722 2721 slotinfop->name));
2723 2722
2724 2723 slotinfop->rstate = AP_RSTATE_DISCONNECTED; /* record rstate */
2725 2724
2726 2725 /* +++ HOOK for RCM to report this hotplug event? +++ */
2727 2726
2728 2727 break;
2729 2728
2730 2729 case HPC_EVENT_SLOT_LATCH_SHUT:
2731 2730 /*
2732 2731 * Latch on the slot is closed.
2733 2732 */
2734 2733 cmn_err(CE_NOTE, "pcihp (%s%d): latch is shut for the slot %s",
2735 2734 ddi_driver_name(pcihp_p->dip),
2736 2735 ddi_get_instance(pcihp_p->dip),
2737 2736 slotinfop->name);
2738 2737
2739 2738 /* +++ HOOK for RCM to report this hotplug event? +++ */
2740 2739
2741 2740 break;
2742 2741
2743 2742 case HPC_EVENT_SLOT_LATCH_OPEN:
2744 2743 /*
2745 2744 * Latch on the slot is open.
2746 2745 */
2747 2746 cmn_err(CE_NOTE, "pcihp (%s%d): latch is open for the slot %s",
2748 2747 ddi_driver_name(pcihp_p->dip),
2749 2748 ddi_get_instance(pcihp_p->dip),
2750 2749 slotinfop->name);
2751 2750
2752 2751 /* +++ HOOK for RCM to report this hotplug event? +++ */
2753 2752
2754 2753 break;
2755 2754
2756 2755 case HPC_EVENT_PROCESS_ENUM:
2757 2756 /*
2758 2757 * HSC knows the device number of the slot where the
2759 2758 * ENUM# was triggered.
2760 2759 * Now finish the necessary actions to be taken on that
2761 2760 * slot. Please note that the interrupt is already cleared.
2762 2761 * This is the second(last) part of the ENUM# event processing.
2763 2762 */
2764 2763 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): processing ENUM#"
2765 2764 " for slot %s",
2766 2765 ddi_driver_name(pcihp_p->dip),
2767 2766 ddi_get_instance(pcihp_p->dip),
2768 2767 slotinfop->name));
2769 2768
2770 2769 mutex_exit(&slotinfop->slot_mutex);
2771 2770 rv = pcihp_enum_slot(pcihp_p, slotinfop, pci_dev,
2772 2771 PCIHP_HANDLE_ENUM, KM_SLEEP);
2773 2772 mutex_enter(&slotinfop->slot_mutex);
2774 2773
2775 2774 /* +++ HOOK for RCM to report this hotplug event? +++ */
2776 2775
2777 2776 break;
2778 2777
2779 2778 case HPC_EVENT_BUS_ENUM:
2780 2779 /*
2781 2780 * Same as HPC_EVENT_SLOT_ENUM as defined the PSARC doc.
2782 2781 * This term is used for better clarity of its usage.
2783 2782 *
2784 2783 * ENUM signal occurred on the bus. It may be from this
2785 2784 * slot or any other hotplug slot on the bus.
2786 2785 *
2787 2786 * It is NOT recommended that the hotswap controller uses
2788 2787 * event without queuing as NDI and other DDI calls may not
2789 2788 * necessarily be invokable in interrupt context.
2790 2789 * Hence the hotswap controller driver should use the
2791 2790 * CLEAR_ENUM event which returns the slot device number
2792 2791 * and then call HPC_EVENT_PROCESS_ENUM event with queuing.
2793 2792 *
2794 2793 * This can be used when the hotswap controller is
2795 2794 * implementing a polled event mechanism to do the
2796 2795 * necessary actions in a single call.
2797 2796 */
2798 2797 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): ENUM# is generated"
2799 2798 " on the bus (for slot %s ?)",
2800 2799 ddi_driver_name(pcihp_p->dip),
2801 2800 ddi_get_instance(pcihp_p->dip),
2802 2801 slotinfop->name));
2803 2802
2804 2803 mutex_exit(&slotinfop->slot_mutex);
2805 2804 rv = pcihp_handle_enum(pcihp_p, pci_dev, PCIHP_HANDLE_ENUM,
2806 2805 KM_SLEEP);
2807 2806 mutex_enter(&slotinfop->slot_mutex);
2808 2807
2809 2808 /* +++ HOOK for RCM to report this hotplug event? +++ */
2810 2809
2811 2810 break;
2812 2811
2813 2812 case HPC_EVENT_SLOT_BLUE_LED_ON:
2814 2813
2815 2814 /*
2816 2815 * Request to turn Hot Swap Blue LED on.
2817 2816 */
2818 2817 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): Request To Turn On Blue "
2819 2818 "LED on the bus (for slot %s ?)",
2820 2819 ddi_driver_name(pcihp_p->dip),
2821 2820 ddi_get_instance(pcihp_p->dip),
2822 2821 slotinfop->name));
2823 2822
2824 2823 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_SLOT_BLUE_LED_ON);
2825 2824 break;
2826 2825
2827 2826 case HPC_EVENT_DISABLE_ENUM:
2828 2827 /*
2829 2828 * Disable ENUM# which disables auto configuration on this slot
2830 2829 */
2831 2830 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
2832 2831 pcihp_hs_csr_op(pcihp_p, pci_dev,
2833 2832 HPC_EVENT_DISABLE_ENUM);
2834 2833 slotinfop->slot_flags &= ~PCIHP_SLOT_AUTO_CFG_EN;
2835 2834 }
2836 2835 break;
2837 2836
2838 2837 case HPC_EVENT_ENABLE_ENUM:
2839 2838 /*
2840 2839 * Enable ENUM# which enables auto configuration on this slot.
2841 2840 */
2842 2841 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
2843 2842 pcihp_hs_csr_op(pcihp_p, pci_dev,
2844 2843 HPC_EVENT_ENABLE_ENUM);
2845 2844 slotinfop->slot_flags |= PCIHP_SLOT_AUTO_CFG_EN;
2846 2845 }
2847 2846 break;
2848 2847
2849 2848 case HPC_EVENT_SLOT_BLUE_LED_OFF:
2850 2849
2851 2850 /*
2852 2851 * Request to turn Hot Swap Blue LED off.
2853 2852 */
2854 2853 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): Request To Turn Off Blue "
2855 2854 "LED on the bus (for slot %s ?)",
2856 2855 ddi_driver_name(pcihp_p->dip),
2857 2856 ddi_get_instance(pcihp_p->dip),
2858 2857 slotinfop->name));
2859 2858
2860 2859 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_SLOT_BLUE_LED_OFF);
2861 2860
2862 2861 break;
2863 2862
2864 2863 case HPC_EVENT_SLOT_NOT_HEALTHY:
2865 2864 /*
2866 2865 * HEALTHY# signal on this slot is not OK.
2867 2866 */
2868 2867 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): HEALTHY# signal is not OK"
2869 2868 " for this slot %s",
2870 2869 ddi_driver_name(pcihp_p->dip),
2871 2870 ddi_get_instance(pcihp_p->dip),
2872 2871 slotinfop->name));
2873 2872
2874 2873 /* record the state in slot_flags field */
2875 2874 slotinfop->slot_flags |= PCIHP_SLOT_NOT_HEALTHY;
2876 2875 slotinfop->condition = AP_COND_FAILED;
2877 2876
2878 2877 /* +++ HOOK for RCM to report this hotplug event? +++ */
2879 2878
2880 2879 break;
2881 2880
2882 2881 case HPC_EVENT_SLOT_HEALTHY_OK:
2883 2882 /*
2884 2883 * HEALTHY# signal on this slot is OK now.
2885 2884 */
2886 2885 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): HEALTHY# signal is OK now"
2887 2886 " for this slot %s",
2888 2887 ddi_driver_name(pcihp_p->dip),
2889 2888 ddi_get_instance(pcihp_p->dip),
2890 2889 slotinfop->name));
2891 2890
2892 2891 /* update the state in slot_flags field */
2893 2892 slotinfop->slot_flags &= ~PCIHP_SLOT_NOT_HEALTHY;
2894 2893 slotinfop->condition = AP_COND_OK;
2895 2894
2896 2895 /* +++ HOOK for RCM to report this hotplug event? +++ */
2897 2896
2898 2897 break;
2899 2898
2900 2899 case HPC_EVENT_SLOT_ATTN:
2901 2900 /*
2902 2901 * Attention button is pressed.
2903 2902 */
2904 2903 if (((slotinfop->slot_flags & PCIHP_SLOT_AUTO_CFG_EN) == 0) ||
2905 2904 (slotinfop->slot_flags & PCIHP_SLOT_DISABLED)) {
2906 2905 /*
2907 2906 * either auto-conifiguration or the slot is disabled,
2908 2907 * ignore this event.
2909 2908 */
2910 2909 break;
2911 2910 }
2912 2911
2913 2912 if (slotinfop->ostate == AP_OSTATE_UNCONFIGURED)
2914 2913 hint = SE_INCOMING_RES;
2915 2914 else
2916 2915 hint = SE_OUTGOING_RES;
2917 2916
2918 2917 if (ddi_getprop(DDI_DEV_T_ANY, pcihp_p->dip, DDI_PROP_DONTPASS,
2919 2918 "inkernel-autoconfig", 0) == 0) {
2920 2919 pcihp_gen_sysevent(slotinfop->name, PCIHP_DR_REQ, hint,
2921 2920 pcihp_p->dip, KM_SLEEP);
2922 2921 break;
2923 2922 }
2924 2923
2925 2924 if ((slotinfop->ostate == AP_OSTATE_UNCONFIGURED) &&
2926 2925 (slotinfop->rstate != AP_RSTATE_EMPTY) &&
2927 2926 (slotinfop->condition != AP_COND_FAILED)) {
2928 2927 if (slotinfop->rstate == AP_RSTATE_DISCONNECTED) {
2929 2928 rv = hpc_nexus_connect(slotinfop->slot_hdl,
2930 2929 NULL, 0);
2931 2930 if (rv == HPC_SUCCESS)
2932 2931 slotinfop->rstate = AP_RSTATE_CONNECTED;
2933 2932 else
2934 2933 break;
2935 2934 }
2936 2935
2937 2936 rv = pcihp_configure_ap(pcihp_p, pci_dev);
2938 2937
2939 2938 } else if ((slotinfop->ostate == AP_OSTATE_CONFIGURED) &&
2940 2939 (slotinfop->rstate == AP_RSTATE_CONNECTED) &&
2941 2940 (slotinfop->condition != AP_COND_FAILED)) {
2942 2941 rv = pcihp_unconfigure_ap(pcihp_p, pci_dev);
2943 2942
2944 2943 if (rv != HPC_SUCCESS)
2945 2944 break;
2946 2945
2947 2946 rv = hpc_nexus_disconnect(slotinfop->slot_hdl,
2948 2947 NULL, 0);
2949 2948 if (rv == HPC_SUCCESS)
2950 2949 slotinfop->rstate = AP_RSTATE_DISCONNECTED;
2951 2950 }
2952 2951
2953 2952 break;
2954 2953
2955 2954 case HPC_EVENT_SLOT_POWER_FAULT:
2956 2955 /*
2957 2956 * Power fault is detected.
2958 2957 */
2959 2958 cmn_err(CE_NOTE, "pcihp (%s%d): power-fault"
2960 2959 " for this slot %s",
2961 2960 ddi_driver_name(pcihp_p->dip),
2962 2961 ddi_get_instance(pcihp_p->dip),
2963 2962 slotinfop->name);
2964 2963
2965 2964 /* turn on ATTN led */
2966 2965 led_info.led = HPC_ATTN_LED;
2967 2966 led_info.state = HPC_LED_ON;
2968 2967 rv = hpc_nexus_control(slotinfop->slot_hdl,
2969 2968 HPC_CTRL_SET_LED_STATE, (caddr_t)&led_info);
2970 2969
2971 2970 if (slotinfop->rstate == AP_RSTATE_CONNECTED)
2972 2971 (void) hpc_nexus_disconnect(slotinfop->slot_hdl,
2973 2972 NULL, 0);
2974 2973
2975 2974 slotinfop->condition = AP_COND_FAILED;
2976 2975
2977 2976 pcihp_gen_sysevent(slotinfop->name, PCIHP_DR_AP_STATE_CHANGE,
2978 2977 SE_NO_HINT, pcihp_p->dip, KM_SLEEP);
2979 2978
2980 2979 break;
2981 2980
2982 2981 default:
2983 2982 cmn_err(CE_NOTE, "pcihp (%s%d): unknown event %x"
2984 2983 " for this slot %s",
2985 2984 ddi_driver_name(pcihp_p->dip),
2986 2985 ddi_get_instance(pcihp_p->dip), event_mask,
2987 2986 slotinfop->name);
2988 2987
2989 2988 /* +++ HOOK for RCM to report this hotplug event? +++ */
2990 2989
2991 2990 break;
2992 2991 }
2993 2992
2994 2993 mutex_exit(&slotinfop->slot_mutex);
2995 2994
2996 2995 (void) pcihp_get_soft_state(self, PCIHP_DR_SLOT_EXIT, &rval);
2997 2996
2998 2997 return (rv);
2999 2998 }
3000 2999
3001 3000 /*
3002 3001 * This function is called to online or offline the devices for an
3003 3002 * attachment point. If the PCI device number of the node matches
3004 3003 * with the device number of the specified hot plug slot then
3005 3004 * the operation is performed.
3006 3005 */
3007 3006 static int
3008 3007 pcihp_configure(dev_info_t *dip, void *hdl)
3009 3008 {
3010 3009 int pci_dev;
3011 3010 struct pcihp_config_ctrl *ctrl = (struct pcihp_config_ctrl *)hdl;
3012 3011 int rv;
3013 3012 pci_regspec_t *pci_rp;
3014 3013 int length;
3015 3014
3016 3015 /*
3017 3016 * Get the PCI device number information from the devinfo
3018 3017 * node. Since the node may not have the address field
3019 3018 * setup (this is done in the DDI_INITCHILD of the parent)
3020 3019 * we look up the 'reg' property to decode that information.
3021 3020 */
3022 3021 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
3023 3022 "reg", (int **)&pci_rp, (uint_t *)&length) != DDI_PROP_SUCCESS) {
3024 3023 ctrl->rv = DDI_FAILURE;
3025 3024 ctrl->dip = dip;
3026 3025 return (DDI_WALK_TERMINATE);
3027 3026 }
3028 3027
3029 3028 /* get the pci device id information */
3030 3029 pci_dev = PCI_REG_DEV_G(pci_rp->pci_phys_hi);
3031 3030
3032 3031 /*
3033 3032 * free the memory allocated by ddi_prop_lookup_int_array
3034 3033 */
3035 3034 ddi_prop_free(pci_rp);
3036 3035
3037 3036 /*
3038 3037 * Match the node for the device number of the slot.
3039 3038 */
3040 3039 if (pci_dev == ctrl->pci_dev) { /* node is a match */
3041 3040 if (ctrl->op == PCIHP_ONLINE) {
3042 3041 /* it is CONFIGURE operation */
3043 3042
3044 3043 /* skip this device if it is disabled or faulty */
3045 3044 if (pcihp_check_status(dip) == B_FALSE) {
3046 3045 return (DDI_WALK_PRUNECHILD);
3047 3046 }
3048 3047
3049 3048 rv = ndi_devi_online(dip, NDI_ONLINE_ATTACH|NDI_CONFIG);
3050 3049 } else {
3051 3050 /*
3052 3051 * it is UNCONFIGURE operation.
3053 3052 */
3054 3053 rv = ndi_devi_offline(dip, NDI_UNCONFIG);
3055 3054 }
3056 3055 if (rv != NDI_SUCCESS) {
3057 3056 /* failed to attach/detach the driver(s) */
3058 3057 ctrl->rv = rv;
3059 3058 ctrl->dip = dip;
3060 3059 /* terminate the search if specified */
3061 3060 if (!(ctrl->flags & PCIHP_CFG_CONTINUE))
3062 3061 return (DDI_WALK_TERMINATE);
3063 3062 }
3064 3063 }
3065 3064
3066 3065 /*
3067 3066 * continue the walk to the next sibling to look for a match
3068 3067 * or to find other nodes if this card is a multi-function card.
3069 3068 */
3070 3069 return (DDI_WALK_PRUNECHILD);
3071 3070 }
3072 3071
3073 3072 /*
3074 3073 * Check the device for a 'status' property. A conforming device
3075 3074 * should have a status of "okay", "disabled", "fail", or "fail-xxx".
3076 3075 *
3077 3076 * Return FALSE for a conforming device that is disabled or faulted.
3078 3077 * Return TRUE in every other case.
3079 3078 */
3080 3079 static bool_t
3081 3080 pcihp_check_status(dev_info_t *dip)
3082 3081 {
3083 3082 char *status_prop;
3084 3083 bool_t rv = B_TRUE;
3085 3084
3086 3085 /* try to get the 'status' property */
3087 3086 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
3088 3087 "status", &status_prop) == DDI_PROP_SUCCESS) {
3089 3088
3090 3089 /*
3091 3090 * test if the status is "disabled", "fail", or
3092 3091 * "fail-xxx".
3093 3092 */
3094 3093 if (strcmp(status_prop, "disabled") == 0) {
3095 3094 rv = B_FALSE;
3096 3095 PCIHP_DEBUG((CE_NOTE,
3097 3096 "pcihp (%s%d): device is in disabled state",
3098 3097 ddi_driver_name(dip), ddi_get_instance(dip)));
3099 3098 } else if (strncmp(status_prop, "fail", 4) == 0) {
3100 3099 rv = B_FALSE;
3101 3100 cmn_err(CE_WARN,
3102 3101 "pcihp (%s%d): device is in fault state (%s)",
3103 3102 ddi_driver_name(dip), ddi_get_instance(dip),
3104 3103 status_prop);
3105 3104 }
3106 3105
3107 3106 ddi_prop_free(status_prop);
3108 3107 }
3109 3108
3110 3109 return (rv);
3111 3110 }
3112 3111
3113 3112 /* control structure used to find a device in the devinfo tree */
3114 3113 struct pcihp_find_ctrl {
3115 3114 uint_t device;
3116 3115 uint_t function;
3117 3116 dev_info_t *dip;
3118 3117 };
3119 3118
3120 3119 static dev_info_t *
3121 3120 pcihp_devi_find(dev_info_t *dip, uint_t device, uint_t function)
3122 3121 {
3123 3122 struct pcihp_find_ctrl ctrl;
3124 3123 int circular_count;
3125 3124
3126 3125 ctrl.device = device;
3127 3126 ctrl.function = function;
3128 3127 ctrl.dip = NULL;
3129 3128
3130 3129 ndi_devi_enter(dip, &circular_count);
3131 3130 ddi_walk_devs(ddi_get_child(dip), pcihp_match_dev, (void *)&ctrl);
3132 3131 ndi_devi_exit(dip, circular_count);
3133 3132
3134 3133 return (ctrl.dip);
3135 3134 }
3136 3135
3137 3136 static int
3138 3137 pcihp_match_dev(dev_info_t *dip, void *hdl)
3139 3138 {
3140 3139 struct pcihp_find_ctrl *ctrl = (struct pcihp_find_ctrl *)hdl;
3141 3140 pci_regspec_t *pci_rp;
3142 3141 int length;
3143 3142 int pci_dev;
3144 3143 int pci_func;
3145 3144
3146 3145 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
3147 3146 "reg", (int **)&pci_rp, (uint_t *)&length) != DDI_PROP_SUCCESS) {
3148 3147 ctrl->dip = NULL;
3149 3148 return (DDI_WALK_TERMINATE);
3150 3149 }
3151 3150
3152 3151 /* get the PCI device address info */
3153 3152 pci_dev = PCI_REG_DEV_G(pci_rp->pci_phys_hi);
3154 3153 pci_func = PCI_REG_FUNC_G(pci_rp->pci_phys_hi);
3155 3154
3156 3155 /*
3157 3156 * free the memory allocated by ddi_prop_lookup_int_array
3158 3157 */
3159 3158 ddi_prop_free(pci_rp);
3160 3159
3161 3160
3162 3161 if ((pci_dev == ctrl->device) && (pci_func == ctrl->function)) {
3163 3162 /* found the match for the specified device address */
3164 3163 ctrl->dip = dip;
3165 3164 return (DDI_WALK_TERMINATE);
3166 3165 }
3167 3166
3168 3167 /*
3169 3168 * continue the walk to the next sibling to look for a match.
3170 3169 */
3171 3170 return (DDI_WALK_PRUNECHILD);
3172 3171 }
3173 3172
3174 3173 #if 0
3175 3174 /*
3176 3175 * Probe the configuration space of the slot to determine the receptacle
3177 3176 * state. There may not be any devinfo tree created for this slot.
3178 3177 */
3179 3178 static void
3180 3179 pcihp_probe_slot_state(dev_info_t *dip, int dev, hpc_slot_state_t *rstatep)
3181 3180 {
3182 3181 /* XXX FIX IT */
3183 3182 }
3184 3183 #endif
3185 3184
3186 3185 /*
3187 3186 * This routine is called when a ENUM# assertion is detected for a bus.
3188 3187 * Since ENUM# may be bussed, the slot that asserted ENUM# may not be known.
3189 3188 * The HPC Driver passes the handle of a slot that is its best guess.
3190 3189 * If the best guess slot is the one that asserted ENUM#, the proper handling
3191 3190 * will be done. If its not, all possible slots will be locked at until
3192 3191 * one that is asserting ENUM is found.
3193 3192 * Also, indicate to the HSC to turn on ENUM# after it is serviced,
3194 3193 * incase if it was disabled by the HSC due to the nature of asynchronous
3195 3194 * delivery of interrupt by the framework.
3196 3195 *
3197 3196 * opcode has the following meanings.
3198 3197 * PCIHP_CLEAR_ENUM = just clear interrupt and return the PCI device no. if
3199 3198 * success, else return -1.
3200 3199 * PCIHP_HANDLE_ENUM = clear interrupt and handle interrupt also.
3201 3200 *
3202 3201 */
3203 3202 static int
3204 3203 pcihp_handle_enum(pcihp_t *pcihp_p, int favorite_pci_dev, int opcode,
3205 3204 int kmflag)
3206 3205 {
3207 3206 struct pcihp_slotinfo *slotinfop;
3208 3207 int pci_dev, rc, event_serviced = 0;
3209 3208
3210 3209 /*
3211 3210 * Handle ENUM# condition for the "favorite" slot first.
3212 3211 */
3213 3212 slotinfop = &pcihp_p->slotinfo[favorite_pci_dev];
3214 3213 if (slotinfop) {
3215 3214 /*
3216 3215 * First try the "favorite" pci device. This is the device
3217 3216 * associated with the handle passed by the HPC Driver.
3218 3217 */
3219 3218 rc = pcihp_enum_slot(pcihp_p, slotinfop, favorite_pci_dev,
3220 3219 opcode, kmflag);
3221 3220 if (rc != HPC_EVENT_UNCLAIMED) { /* indicates success */
3222 3221 event_serviced = 1;
3223 3222 /* This MUST be a non-DEBUG feature. */
3224 3223 if (! pcihp_enum_scan_all) {
3225 3224 return (rc);
3226 3225 }
3227 3226 }
3228 3227 }
3229 3228
3230 3229 /*
3231 3230 * If ENUM# is implemented as a radial signal, then there is no
3232 3231 * need to further poll the slots.
3233 3232 */
3234 3233 if (pcihp_p->bus_flags & PCIHP_BUS_ENUM_RADIAL)
3235 3234 goto enum_service_check;
3236 3235
3237 3236 /*
3238 3237 * If the "favorite" pci device didn't assert ENUM#, then
3239 3238 * try the rest. Once we find and handle a device that asserted
3240 3239 * ENUM#, then we will terminate the walk by returning unless
3241 3240 * scan-all flag is set.
3242 3241 */
3243 3242 for (pci_dev = 0; pci_dev < PCI_MAX_DEVS; pci_dev++) {
3244 3243 if (pci_dev != favorite_pci_dev) {
3245 3244 slotinfop = &pcihp_p->slotinfo[pci_dev];
3246 3245 if (slotinfop == NULL) {
3247 3246 continue;
3248 3247 }
3249 3248 /* Only CPCI devices support ENUM# generation. */
3250 3249 if (!(slotinfop->slot_type & HPC_SLOT_TYPE_CPCI))
3251 3250 continue;
3252 3251 rc = pcihp_enum_slot(pcihp_p, slotinfop, pci_dev,
3253 3252 opcode, kmflag);
3254 3253 if (rc != HPC_EVENT_UNCLAIMED) {
3255 3254 event_serviced = 1;
3256 3255 /* This MUST be a non-DEBUG feature. */
3257 3256 if (! pcihp_enum_scan_all)
3258 3257 break;
3259 3258 }
3260 3259 }
3261 3260 }
3262 3261
3263 3262 enum_service_check:
3264 3263 if (event_serviced) {
3265 3264 return (rc);
3266 3265 }
3267 3266
3268 3267 /* No ENUM# event found, Return */
3269 3268 return (HPC_EVENT_UNCLAIMED);
3270 3269 }
3271 3270
3272 3271 /*
3273 3272 * This routine attempts to handle a possible ENUM# assertion case for a
3274 3273 * specified slot. This only works for adapters that implement Hot Swap
3275 3274 * Friendly Silicon. If the slot's HS_CSR is read and it specifies ENUM#
3276 3275 * has been asserted, either the insertion or removal handlers will be
3277 3276 * called.
3278 3277 */
3279 3278 static int
3280 3279 pcihp_enum_slot(pcihp_t *pcihp_p, struct pcihp_slotinfo *slotinfop, int pci_dev,
3281 3280 int opcode, int kmflag)
3282 3281 {
3283 3282 ddi_acc_handle_t handle;
3284 3283 dev_info_t *dip, *new_child = NULL;
3285 3284 int result, rv = -1;
3286 3285 uint8_t hs_csr;
3287 3286
3288 3287 if (pcihp_config_setup(&dip, &handle, &new_child, pci_dev,
3289 3288 pcihp_p) != DDI_SUCCESS) {
3290 3289 return (HPC_EVENT_UNCLAIMED);
3291 3290 }
3292 3291
3293 3292 /*
3294 3293 * Read the device's HS_CSR.
3295 3294 */
3296 3295 result = pcihp_get_hs_csr(slotinfop, handle, (uint8_t *)&hs_csr);
3297 3296 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): hs_csr = %x, flags = %x",
3298 3297 ddi_driver_name(pcihp_p->dip), ddi_get_instance(pcihp_p->dip),
3299 3298 hs_csr, slotinfop->slot_flags));
3300 3299 /*
3301 3300 * we teardown our device map here, because in case of an
3302 3301 * extraction event, our nodes would be freed and a teardown
3303 3302 * will cause problems.
3304 3303 */
3305 3304 pcihp_config_teardown(&handle, &new_child, pci_dev, pcihp_p);
3306 3305
3307 3306 if (result == PCIHP_SUCCESS) {
3308 3307
3309 3308 /* If ENUM# is masked, then it is not us. Some other device */
3310 3309 if ((hs_csr & HS_CSR_EIM) && (opcode == PCIHP_CLEAR_ENUM))
3311 3310 return (HPC_EVENT_UNCLAIMED);
3312 3311 /*
3313 3312 * This device supports Full Hot Swap and implements
3314 3313 * the Hot Swap Control and Status Register.
3315 3314 */
3316 3315 if ((hs_csr & HS_CSR_INS) ||
3317 3316 (slotinfop->slot_flags & PCIHP_SLOT_ENUM_INS_PENDING)) {
3318 3317 /* handle insertion ENUM */
3319 3318 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): "
3320 3319 "Handle Insertion ENUM (INS) "
3321 3320 "on the bus (for slot %s ?)",
3322 3321 ddi_driver_name(pcihp_p->dip),
3323 3322 ddi_get_instance(pcihp_p->dip),
3324 3323 slotinfop->name));
3325 3324
3326 3325 /*
3327 3326 * generate sysevent
3328 3327 */
3329 3328
3330 3329 if (opcode == PCIHP_CLEAR_ENUM)
3331 3330 pcihp_gen_sysevent(slotinfop->name,
3332 3331 PCIHP_DR_REQ,
3333 3332 SE_INCOMING_RES, pcihp_p->dip,
3334 3333 kmflag);
3335 3334
3336 3335 rv = pcihp_handle_enum_insertion(pcihp_p, pci_dev,
3337 3336 opcode, kmflag);
3338 3337
3339 3338 } else if ((hs_csr & HS_CSR_EXT) ||
3340 3339 (slotinfop->slot_flags & PCIHP_SLOT_ENUM_EXT_PENDING)) {
3341 3340 /* handle extraction ENUM */
3342 3341 PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): "
3343 3342 "Handle Extraction ENUM (EXT) "
3344 3343 "on the bus (for slot %s ?)",
3345 3344 ddi_driver_name(pcihp_p->dip),
3346 3345 ddi_get_instance(pcihp_p->dip),
3347 3346 slotinfop->name));
3348 3347
3349 3348 /*
3350 3349 * generate sysevent
3351 3350 */
3352 3351
3353 3352 if (opcode == PCIHP_CLEAR_ENUM)
3354 3353 pcihp_gen_sysevent(slotinfop->name,
3355 3354 PCIHP_DR_REQ,
3356 3355 SE_OUTGOING_RES,
3357 3356 pcihp_p->dip,
3358 3357 kmflag);
3359 3358
3360 3359 rv = pcihp_handle_enum_extraction(pcihp_p, pci_dev,
3361 3360 opcode, kmflag);
3362 3361 }
3363 3362 if (opcode == PCIHP_CLEAR_ENUM) {
3364 3363 if (rv == PCIHP_SUCCESS)
3365 3364 rv = pci_dev;
3366 3365 else
3367 3366 rv = HPC_EVENT_UNCLAIMED;
3368 3367 }
3369 3368 }
3370 3369
3371 3370 return (rv);
3372 3371 }
3373 3372
3374 3373 /*
3375 3374 * This routine is called when a ENUM# caused by lifting the lever
3376 3375 * is detected. If the occupant is configured, it will be unconfigured.
3377 3376 * If the occupant is already unconfigured or is successfully unconfigured,
3378 3377 * the blue LED on the adapter is illuminated which means its OK to remove.
3379 3378 * Please note that the lock must be released before invoking the
3380 3379 * generic AP unconfigure function.
3381 3380 */
3382 3381 static int
3383 3382 pcihp_handle_enum_extraction(pcihp_t *pcihp_p, int pci_dev, int opcode,
3384 3383 int kmflag)
3385 3384 {
3386 3385 struct pcihp_slotinfo *slotinfop;
3387 3386 int rv = PCIHP_FAILURE;
3388 3387
3389 3388 slotinfop = &pcihp_p->slotinfo[pci_dev];
3390 3389
3391 3390 /*
3392 3391 * It was observed that, clearing the EXT bit turned the LED ON.
3393 3392 * This is a BIG problem in case if the unconfigure operation
3394 3393 * failed because the board was busy.
3395 3394 * In order to avoid this confusing situation (LED ON but the board
3396 3395 * is not unconfigured), we instead decided not to clear EXT but
3397 3396 * disable further ENUM# from this slot. Disabling ENUM# clears
3398 3397 * the interrupt.
3399 3398 * Finally before returning we clear the interrupt and enable
3400 3399 * ENUM# back again from this slot.
3401 3400 */
3402 3401 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_DISABLE_ENUM);
3403 3402 if (opcode == PCIHP_CLEAR_ENUM) {
3404 3403 slotinfop->slot_flags |= PCIHP_SLOT_ENUM_EXT_PENDING;
3405 3404 return (PCIHP_SUCCESS);
3406 3405 }
3407 3406
3408 3407 mutex_enter(&slotinfop->slot_mutex);
3409 3408 rv = pcihp_unconfigure_ap(pcihp_p, pci_dev);
3410 3409 mutex_exit(&slotinfop->slot_mutex);
3411 3410 if (rv != HPC_SUCCESS && rv != EBUSY) {
3412 3411 cmn_err(CE_NOTE, "%s%d: PCI device %x Failed on Unconfigure",
3413 3412 ddi_driver_name(pcihp_p->dip),
3414 3413 ddi_get_instance(pcihp_p->dip), pci_dev);
3415 3414 }
3416 3415 if (rv == EBUSY)
3417 3416 cmn_err(CE_NOTE, "%s%d: PCI device %x Busy",
3418 3417 ddi_driver_name(pcihp_p->dip),
3419 3418 ddi_get_instance(pcihp_p->dip), pci_dev);
3420 3419 if (rv) {
3421 3420 if (pcihp_cpci_blue_led)
3422 3421 pcihp_hs_csr_op(pcihp_p, pci_dev,
3423 3422 HPC_EVENT_SLOT_BLUE_LED_OFF);
3424 3423 }
3425 3424 /*
3426 3425 * we must clear interrupt in case the unconfigure didn't do it
3427 3426 * due to a duplicate interrupt. Extraction is success.
3428 3427 */
3429 3428 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_SLOT_UNCONFIGURE);
3430 3429
3431 3430 if (!rv) {
3432 3431 /*
3433 3432 * Sys Event Notification.
3434 3433 */
3435 3434 pcihp_gen_sysevent(slotinfop->name, PCIHP_DR_AP_STATE_CHANGE,
3436 3435 SE_HINT_REMOVE, pcihp_p->dip, kmflag);
3437 3436 }
3438 3437
3439 3438 /*
3440 3439 * Enable interrupts back from this board.
3441 3440 * This could potentially be problematic in case if the user is
3442 3441 * quick enough to extract the board.
3443 3442 * But we must do it just in case if the switch is closed again.
3444 3443 */
3445 3444 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_ENABLE_ENUM);
3446 3445 slotinfop->slot_flags &= ~PCIHP_SLOT_ENUM_EXT_PENDING;
3447 3446 return (rv);
3448 3447 }
3449 3448
3450 3449 /*
3451 3450 * This routine is called when a ENUM# caused by when an adapter insertion
3452 3451 * is detected. If the occupant is successfully configured (i.e. PCI resources
3453 3452 * successfully assigned, the blue LED is left off, otherwise if configuration
3454 3453 * is not successful, the blue LED is illuminated.
3455 3454 * Please note that the lock must be released before invoking the
3456 3455 * generic AP configure function.
3457 3456 */
3458 3457 static int
3459 3458 pcihp_handle_enum_insertion(pcihp_t *pcihp_p, int pci_dev, int opcode,
3460 3459 int kmflag)
3461 3460 {
3462 3461 struct pcihp_slotinfo *slotinfop;
3463 3462 int rv = PCIHP_FAILURE;
3464 3463 minor_t ap_minor;
3465 3464 major_t ap_major;
3466 3465
3467 3466 slotinfop = &pcihp_p->slotinfo[pci_dev];
3468 3467 slotinfop->hs_csr_location = 0;
3469 3468 /* we clear the interrupt here. This is a must here. */
3470 3469 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_SLOT_CONFIGURE);
3471 3470 /*
3472 3471 * disable further interrupt from this board till it is
3473 3472 * configured.
3474 3473 */
3475 3474 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_DISABLE_ENUM);
3476 3475 if (opcode == PCIHP_CLEAR_ENUM) {
3477 3476 slotinfop->slot_flags |= PCIHP_SLOT_ENUM_INS_PENDING;
3478 3477 return (PCIHP_SUCCESS);
3479 3478 }
3480 3479
3481 3480 if ((slotinfop->slot_flags & PCIHP_SLOT_AUTO_CFG_EN) ==
3482 3481 PCIHP_SLOT_AUTO_CFG_EN) {
3483 3482 mutex_enter(&slotinfop->slot_mutex);
3484 3483 rv = pcihp_configure_ap(pcihp_p, pci_dev);
3485 3484 mutex_exit(&slotinfop->slot_mutex);
3486 3485 if (rv != HPC_SUCCESS) { /* configure failed */
3487 3486 cmn_err(CE_NOTE, "%s%d: PCI device %x Failed on"
3488 3487 " Configure", ddi_driver_name(pcihp_p->dip),
3489 3488 ddi_get_instance(pcihp_p->dip), pci_dev);
3490 3489 if (pcihp_cpci_blue_led)
3491 3490 pcihp_hs_csr_op(pcihp_p, pci_dev,
3492 3491 HPC_EVENT_SLOT_BLUE_LED_ON);
3493 3492 }
3494 3493
3495 3494 /* pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_CLEAR_ENUM); */
3496 3495 pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_ENABLE_ENUM);
3497 3496
3498 3497 if (!rv) {
3499 3498 ap_major = ddi_driver_major(pcihp_p->dip);
3500 3499 ap_minor = PCIHP_AP_MINOR_NUM(
3501 3500 ddi_get_instance(pcihp_p->dip), pci_dev);
3502 3501 pcihp_create_occupant_props(pcihp_p->dip,
3503 3502 makedevice(ap_major, ap_minor), pci_dev);
3504 3503
3505 3504 /*
3506 3505 * Sys Event Notification.
3507 3506 */
3508 3507 pcihp_gen_sysevent(slotinfop->name,
3509 3508 PCIHP_DR_AP_STATE_CHANGE,
3510 3509 SE_HINT_INSERT, pcihp_p->dip, kmflag);
3511 3510 }
3512 3511
3513 3512 } else
3514 3513 rv = PCIHP_SUCCESS;
3515 3514 slotinfop->slot_flags &= ~PCIHP_SLOT_ENUM_INS_PENDING;
3516 3515 return (rv);
3517 3516 }
3518 3517
3519 3518 /*
3520 3519 * Read the Hot Swap Control and Status Register (HS_CSR) and
3521 3520 * place the result in the location pointed to be hs_csr.
3522 3521 */
3523 3522 static int
3524 3523 pcihp_get_hs_csr(struct pcihp_slotinfo *slotinfop,
3525 3524 ddi_acc_handle_t config_handle, uint8_t *hs_csr)
3526 3525 {
3527 3526 if (slotinfop->hs_csr_location == -1)
3528 3527 return (PCIHP_FAILURE);
3529 3528
3530 3529 if (slotinfop->hs_csr_location == 0) {
3531 3530 slotinfop->hs_csr_location =
3532 3531 pcihp_get_hs_csr_location(config_handle);
3533 3532
3534 3533 if (slotinfop->hs_csr_location == -1)
3535 3534 return (PCIHP_FAILURE);
3536 3535 }
3537 3536 *hs_csr = pci_config_get8(config_handle, slotinfop->hs_csr_location);
3538 3537 return (PCIHP_SUCCESS);
3539 3538 }
3540 3539
3541 3540 /*
3542 3541 * Write the Hot Swap Control and Status Register (HS_CSR) with
3543 3542 * the value being pointed at by hs_csr.
3544 3543 */
3545 3544 static void
3546 3545 pcihp_set_hs_csr(struct pcihp_slotinfo *slotinfop,
3547 3546 ddi_acc_handle_t config_handle, uint8_t *hs_csr)
3548 3547 {
3549 3548 if (slotinfop->hs_csr_location == -1)
3550 3549 return;
3551 3550 if (slotinfop->hs_csr_location == 0) {
3552 3551 slotinfop->hs_csr_location =
3553 3552 pcihp_get_hs_csr_location(config_handle);
3554 3553 if (slotinfop->hs_csr_location == -1)
3555 3554 return;
3556 3555 }
3557 3556 pci_config_put8(config_handle, slotinfop->hs_csr_location, *hs_csr);
3558 3557 PCIHP_DEBUG((CE_NOTE, "hs_csr wrote %x, read %x", *hs_csr,
3559 3558 pci_config_get8(config_handle, slotinfop->hs_csr_location)));
3560 3559 }
3561 3560
3562 3561 static int
3563 3562 pcihp_get_hs_csr_location(ddi_acc_handle_t config_handle)
3564 3563 {
3565 3564 uint8_t cap_id;
3566 3565 uint_t cap_id_loc;
3567 3566 uint16_t status;
3568 3567 int location = -1;
3569 3568 #define PCI_STAT_ECP_SUPP 0x10
3570 3569
3571 3570 /*
3572 3571 * Need to check the Status register for ECP support first.
3573 3572 * Also please note that for type 1 devices, the
3574 3573 * offset could change. Should support type 1 next.
3575 3574 */
3576 3575 status = pci_config_get16(config_handle, PCI_CONF_STAT);
3577 3576 if (!(status & PCI_STAT_ECP_SUPP)) {
3578 3577 PCIHP_DEBUG((CE_NOTE, "No Ext Capabilities for device\n"));
3579 3578 return (-1);
3580 3579 }
3581 3580 cap_id_loc = pci_config_get8(config_handle, PCI_CONF_EXTCAP);
3582 3581
3583 3582 /*
3584 3583 * Walk the list of capabilities, but don't walk past the end
3585 3584 * of the Configuration Space Header.
3586 3585 */
3587 3586 while ((cap_id_loc) && (cap_id_loc < PCI_CONF_HDR_SIZE)) {
3588 3587
3589 3588 cap_id = pci_config_get8(config_handle, cap_id_loc);
3590 3589
3591 3590 if (cap_id == CPCI_HOTSWAP_CAPID) {
3592 3591 location = cap_id_loc + PCI_ECP_HS_CSR;
3593 3592 break;
3594 3593 }
3595 3594 cap_id_loc = pci_config_get8(config_handle,
3596 3595 cap_id_loc + 1);
3597 3596 }
3598 3597 return (location);
3599 3598 }
3600 3599
3601 3600 static int
3602 3601 pcihp_add_dummy_reg_property(dev_info_t *dip,
3603 3602 uint_t bus, uint_t device, uint_t func)
3604 3603 {
3605 3604 pci_regspec_t dummy_reg;
3606 3605
3607 3606 bzero(&dummy_reg, sizeof (dummy_reg));
3608 3607
3609 3608 dummy_reg.pci_phys_hi = PCIHP_MAKE_REG_HIGH(bus, device, func, 0);
3610 3609
3611 3610 return (ndi_prop_update_int_array(DDI_DEV_T_NONE, dip,
3612 3611 "reg", (int *)&dummy_reg, sizeof (pci_regspec_t)/sizeof (int)));
3613 3612 }
3614 3613
3615 3614 static void
3616 3615 pcihp_hs_csr_op(pcihp_t *pcihp_p, int pci_dev, int event)
3617 3616 {
3618 3617 struct pcihp_slotinfo *slotinfop;
3619 3618 ddi_acc_handle_t config_handle;
3620 3619 dev_info_t *dip, *new_child = NULL;
3621 3620 uint8_t hs_csr;
3622 3621 int result;
3623 3622
3624 3623 slotinfop = &pcihp_p->slotinfo[pci_dev];
3625 3624
3626 3625 if (pcihp_config_setup(&dip, &config_handle, &new_child, pci_dev,
3627 3626 pcihp_p) != DDI_SUCCESS) {
3628 3627 return;
3629 3628 }
3630 3629
3631 3630 result = pcihp_get_hs_csr(slotinfop, config_handle, (uint8_t *)&hs_csr);
3632 3631 if ((result != PCIHP_SUCCESS) || (event == -1)) {
3633 3632 pcihp_config_teardown(&config_handle, &new_child, pci_dev,
3634 3633 pcihp_p);
3635 3634 return;
3636 3635 }
3637 3636
3638 3637 hs_csr &= 0xf;
3639 3638 switch (event) {
3640 3639 case HPC_EVENT_SLOT_BLUE_LED_ON:
3641 3640 hs_csr |= HS_CSR_LOO;
3642 3641 break;
3643 3642 case HPC_EVENT_SLOT_BLUE_LED_OFF:
3644 3643 hs_csr &= ~HS_CSR_LOO;
3645 3644 break;
3646 3645 case HPC_EVENT_SLOT_CONFIGURE:
3647 3646 hs_csr |= HS_CSR_INS; /* clear INS */
3648 3647 break;
3649 3648 case HPC_EVENT_CLEAR_ENUM:
3650 3649 hs_csr |= (HS_CSR_INS | HS_CSR_EXT);
3651 3650 break;
3652 3651 case HPC_EVENT_SLOT_UNCONFIGURE:
3653 3652 hs_csr |= HS_CSR_EXT; /* clear EXT */
3654 3653 break;
3655 3654 case HPC_EVENT_ENABLE_ENUM:
3656 3655 hs_csr &= ~HS_CSR_EIM;
3657 3656 break;
3658 3657 case HPC_EVENT_DISABLE_ENUM:
3659 3658 hs_csr |= HS_CSR_EIM;
3660 3659 break;
3661 3660 case HPC_EVENT_SLOT_NOT_HEALTHY:
3662 3661 case HPC_EVENT_SLOT_HEALTHY_OK:
3663 3662 default:
3664 3663 break;
3665 3664 }
3666 3665 pcihp_set_hs_csr(slotinfop, config_handle, (uint8_t *)&hs_csr);
3667 3666 pcihp_config_teardown(&config_handle, &new_child, pci_dev, pcihp_p);
3668 3667 }
3669 3668
3670 3669 static int
3671 3670 pcihp_config_setup(dev_info_t **dip, ddi_acc_handle_t *handle,
3672 3671 dev_info_t **new_child, int pci_dev, pcihp_t *pcihp_p)
3673 3672 {
3674 3673 dev_info_t *pdip = pcihp_p->dip;
3675 3674 int bus, len, rc = DDI_SUCCESS;
3676 3675 struct pcihp_slotinfo *slotinfop;
3677 3676 hpc_slot_state_t rstate;
3678 3677 ddi_acc_hdl_t *hp;
3679 3678 pci_bus_range_t pci_bus_range;
3680 3679
3681 3680 slotinfop = &pcihp_p->slotinfo[pci_dev];
3682 3681
3683 3682 /*
3684 3683 * If declared failed, don't allow Config operations.
3685 3684 * Otherwise, if good or failing, it is assumed Ok
3686 3685 * to get config data.
3687 3686 */
3688 3687 if (slotinfop->condition == AP_COND_FAILED) {
3689 3688 return (PCIHP_FAILURE);
3690 3689 }
3691 3690 /*
3692 3691 * check to see if there is a hardware present first.
3693 3692 * If no hardware present, no need to probe this slot.
3694 3693 * We can do this first probably as a first step towards
3695 3694 * safeguarding from accidental removal (we don't support it!).
3696 3695 */
3697 3696 if (hpc_nexus_control(slotinfop->slot_hdl, HPC_CTRL_GET_SLOT_STATE,
3698 3697 (caddr_t)&rstate) != 0) {
3699 3698 return (DDI_FAILURE);
3700 3699 }
3701 3700
3702 3701 if (rstate != HPC_SLOT_CONNECTED) {
3703 3702 /* error. slot must be connected */
3704 3703 return (DDI_FAILURE);
3705 3704 }
3706 3705 *new_child = NULL;
3707 3706
3708 3707 /*
3709 3708 * If there is no dip then we need to see if an
3710 3709 * adapter has just been hot plugged.
3711 3710 */
3712 3711 len = sizeof (pci_bus_range_t);
3713 3712 if (ddi_getlongprop_buf(DDI_DEV_T_ANY, pdip,
3714 3713 0, "bus-range",
3715 3714 (caddr_t)&pci_bus_range, &len) != DDI_SUCCESS) {
3716 3715
3717 3716 return (PCIHP_FAILURE);
3718 3717 }
3719 3718
3720 3719 /* primary bus number of this bus node */
3721 3720 bus = pci_bus_range.lo;
3722 3721
3723 3722 if (ndi_devi_alloc(pdip, DEVI_PSEUDO_NEXNAME,
3724 3723 (pnode_t)DEVI_SID_NODEID, dip) != NDI_SUCCESS) {
3725 3724
3726 3725 PCIHP_DEBUG((CE_NOTE, "Failed to alloc probe node\n"));
3727 3726 return (PCIHP_FAILURE);
3728 3727 }
3729 3728
3730 3729 if (pcihp_add_dummy_reg_property(*dip, bus,
3731 3730 pci_dev, 0) != DDI_SUCCESS) {
3732 3731
3733 3732 (void) ndi_devi_free(*dip);
3734 3733 return (PCIHP_FAILURE);
3735 3734 }
3736 3735
3737 3736 /*
3738 3737 * Probe for a device. Possibly a non (c)PCI board could be sitting
3739 3738 * here which would never respond to PCI config cycles - in which
3740 3739 * case we return. Eventually a configure operation would fail.
3741 3740 */
3742 3741 if (pci_config_setup(*dip, handle) != DDI_SUCCESS) {
3743 3742 cmn_err(CE_WARN, "Cannot set config space map for"
3744 3743 " pci device number %d", pci_dev);
3745 3744 (void) ndi_devi_free(*dip);
3746 3745 return (PCIHP_FAILURE);
3747 3746 }
3748 3747
3749 3748 /*
3750 3749 * See if there is any PCI HW at this location
3751 3750 * by reading the Vendor ID. If it returns with 0xffff
3752 3751 * then there is no hardware at this location.
3753 3752 */
3754 3753 if (pcihp_indirect_map(*dip) == DDI_SUCCESS) {
3755 3754 if (pci_config_get16(*handle, 0) == 0xffff) {
3756 3755 pci_config_teardown(handle);
3757 3756 (void) ndi_devi_free(*dip);
3758 3757 return (PCIHP_FAILURE);
3759 3758 }
3760 3759 } else {
3761 3760 /* Check if mapping is OK */
3762 3761 hp = impl_acc_hdl_get(*handle);
3763 3762
3764 3763 if (ddi_peek16(*dip, (int16_t *)(hp->ah_addr),
3765 3764 (int16_t *)0) != DDI_SUCCESS) {
3766 3765 #ifdef DEBUG
3767 3766 cmn_err(CE_WARN, "Cannot Map PCI config space for "
3768 3767 "device number %d", pci_dev);
3769 3768 #endif
3770 3769 pci_config_teardown(handle);
3771 3770 (void) ndi_devi_free(*dip);
3772 3771 return (PCIHP_FAILURE);
3773 3772 }
3774 3773 }
3775 3774
3776 3775 *new_child = *dip;
3777 3776 return (rc);
3778 3777
3779 3778 }
3780 3779
3781 3780 static void
3782 3781 pcihp_config_teardown(ddi_acc_handle_t *handle,
3783 3782 dev_info_t **new_child, int pci_dev, pcihp_t *pcihp_p)
3784 3783 {
3785 3784 struct pcihp_slotinfo *slotinfop = &pcihp_p->slotinfo[pci_dev];
3786 3785
3787 3786 pci_config_teardown(handle);
3788 3787 if (*new_child) {
3789 3788 (void) ndi_devi_free(*new_child);
3790 3789 /*
3791 3790 * If occupant not configured, reset HS_CSR location
3792 3791 * so that we reprobe. This covers cases where
3793 3792 * the receptacle had a status change without a
3794 3793 * notification to the framework.
3795 3794 */
3796 3795 if (slotinfop->ostate != AP_OSTATE_CONFIGURED)
3797 3796 slotinfop->hs_csr_location = 0;
3798 3797 }
3799 3798 }
3800 3799
3801 3800 static int
3802 3801 pcihp_get_board_type(struct pcihp_slotinfo *slotinfop)
3803 3802 {
3804 3803 hpc_board_type_t board_type;
3805 3804
3806 3805 /*
3807 3806 * Get board type data structure, hpc_board_type_t.
3808 3807 */
3809 3808 if (hpc_nexus_control(slotinfop->slot_hdl, HPC_CTRL_GET_BOARD_TYPE,
3810 3809 (caddr_t)&board_type) != 0) {
3811 3810
3812 3811 cmn_err(CE_WARN, "Cannot Get Board Type..");
3813 3812 return (-1);
3814 3813 }
3815 3814
3816 3815 /*
3817 3816 * We expect the Hotswap Controller to tell us if the board is
3818 3817 * a hotswap board or not, as it probably cannot differentiate
3819 3818 * between a basic hotswap board, a non hotswap board and a
3820 3819 * hotswap nonfriendly board.
3821 3820 * So here is the logic to differentiate between the various
3822 3821 * types of cPCI boards.
3823 3822 * In case if the HSC returns board type as unknown, we assign
3824 3823 * the default board type as defined by a configurable variable
3825 3824 * for a BHS, nonfriendly FHS and non HS board.
3826 3825 */
3827 3826 if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) {
3828 3827 if (slotinfop->hs_csr_location > 0)
3829 3828 board_type = HPC_BOARD_CPCI_FULL_HS;
3830 3829 else {
3831 3830 if (board_type == HPC_BOARD_CPCI_HS) {
3832 3831 if (slotinfop->hs_csr_location == -1)
3833 3832 board_type = HPC_BOARD_CPCI_BASIC_HS;
3834 3833 }
3835 3834 if (board_type == HPC_BOARD_UNKNOWN) {
3836 3835 if (slotinfop->hs_csr_location == -1) {
3837 3836 board_type = pcihp_cpci_board_type;
3838 3837 } else if (slotinfop->hs_csr_location != 0) {
3839 3838 board_type = HPC_BOARD_CPCI_FULL_HS;
3840 3839 }
3841 3840 }
3842 3841 }
3843 3842 /*
3844 3843 * If board type is a non hotswap board, then we must
3845 3844 * deny a unconfigure operation. So set this flag.
3846 3845 * Strictly speaking, there is no reason not to disallow
3847 3846 * a unconfigure operation on nonhotswap boards. But this
3848 3847 * is the only way we can prevent a user from accidentally
3849 3848 * removing the board and damaging it.
3850 3849 */
3851 3850 if (board_type == HPC_BOARD_CPCI_NON_HS)
3852 3851 slotinfop->slot_flags |= PCIHP_SLOT_DEV_NON_HOTPLUG;
3853 3852 else
3854 3853 slotinfop->slot_flags &= ~PCIHP_SLOT_DEV_NON_HOTPLUG;
3855 3854 }
3856 3855 return (board_type);
3857 3856 }
3858 3857
3859 3858
3860 3859 /*
3861 3860 * Generate the System Event with a possible hint.
3862 3861 */
3863 3862 static void
3864 3863 pcihp_gen_sysevent(char *slot_name, int event_sub_class, int hint,
3865 3864 dev_info_t *self, int kmflag)
3866 3865 {
3867 3866
3868 3867 int err;
3869 3868 char *ev_subclass = NULL;
3870 3869 sysevent_id_t eid;
3871 3870 nvlist_t *ev_attr_list = NULL;
3872 3871 char attach_pnt[MAXPATHLEN];
3873 3872
3874 3873 /*
3875 3874 * Minor device name (AP) will be bus path
3876 3875 * concatenated with slot name
3877 3876 */
3878 3877
3879 3878 (void) strcpy(attach_pnt, PCIHP_DEVICES_STR);
3880 3879 (void) ddi_pathname(self, attach_pnt + strlen(PCIHP_DEVICES_STR));
3881 3880 (void) strcat(attach_pnt, ":");
3882 3881 (void) strcat(attach_pnt, slot_name);
3883 3882 err = nvlist_alloc(&ev_attr_list, NV_UNIQUE_NAME_TYPE, kmflag);
3884 3883 if (err != 0) {
3885 3884 cmn_err(CE_WARN,
3886 3885 "%s%d: Failed to allocate memory "
3887 3886 "for event attributes%s", ddi_driver_name(self),
3888 3887 ddi_get_instance(self), ESC_DR_AP_STATE_CHANGE);
3889 3888 return;
3890 3889 }
3891 3890
3892 3891 switch (event_sub_class) {
3893 3892
3894 3893 /* event sub class: ESC_DR_AP_STATE_CHANGE */
3895 3894 case PCIHP_DR_AP_STATE_CHANGE:
3896 3895
3897 3896 ev_subclass = ESC_DR_AP_STATE_CHANGE;
3898 3897
3899 3898 switch (hint) {
3900 3899
3901 3900 case SE_NO_HINT: /* fall through */
3902 3901 case SE_HINT_INSERT: /* fall through */
3903 3902 case SE_HINT_REMOVE:
3904 3903
3905 3904
3906 3905 err = nvlist_add_string(ev_attr_list, DR_HINT,
3907 3906 SE_HINT2STR(hint));
3908 3907
3909 3908 if (err != 0) {
3910 3909 cmn_err(CE_WARN, "%s%d: Failed to add attr [%s]"
3911 3910 " for %s event", ddi_driver_name(self),
3912 3911 ddi_get_instance(self),
3913 3912 DR_HINT, ESC_DR_AP_STATE_CHANGE);
3914 3913 nvlist_free(ev_attr_list);
3915 3914 return;
3916 3915 }
3917 3916 break;
3918 3917
3919 3918 default:
3920 3919 cmn_err(CE_WARN, "%s%d: Unknown hint on sysevent",
3921 3920 ddi_driver_name(self), ddi_get_instance(self));
3922 3921 nvlist_free(ev_attr_list);
3923 3922 return;
3924 3923 }
3925 3924
3926 3925 break;
3927 3926
3928 3927 /* event sub class: ESC_DR_REQ */
3929 3928 case PCIHP_DR_REQ:
3930 3929
3931 3930 ev_subclass = ESC_DR_REQ;
3932 3931
3933 3932 switch (hint) {
3934 3933
3935 3934 case SE_INVESTIGATE_RES: /* fall through */
3936 3935 case SE_INCOMING_RES: /* fall through */
3937 3936 case SE_OUTGOING_RES: /* fall through */
3938 3937
3939 3938 err = nvlist_add_string(ev_attr_list, DR_REQ_TYPE,
3940 3939 SE_REQ2STR(hint));
3941 3940
3942 3941 if (err != 0) {
3943 3942 cmn_err(CE_WARN,
3944 3943 "%s%d: Failed to add attr [%s] "
3945 3944 "for %s event", ddi_driver_name(self),
3946 3945 ddi_get_instance(self),
3947 3946 DR_REQ_TYPE, ESC_DR_REQ);
3948 3947 nvlist_free(ev_attr_list);
3949 3948 return;
3950 3949 }
3951 3950 break;
3952 3951
3953 3952 default:
3954 3953 cmn_err(CE_WARN, "%s%d: Unknown hint on sysevent",
3955 3954 ddi_driver_name(self), ddi_get_instance(self));
3956 3955 nvlist_free(ev_attr_list);
3957 3956 return;
3958 3957 }
3959 3958
3960 3959 break;
3961 3960
3962 3961 default:
3963 3962 cmn_err(CE_WARN, "%s%d: Unknown Event subclass",
3964 3963 ddi_driver_name(self), ddi_get_instance(self));
3965 3964 nvlist_free(ev_attr_list);
3966 3965 return;
3967 3966 }
3968 3967
3969 3968 /*
3970 3969 * Add attachment point as attribute (common attribute)
3971 3970 */
3972 3971
3973 3972 err = nvlist_add_string(ev_attr_list, DR_AP_ID, attach_pnt);
3974 3973
3975 3974 if (err != 0) {
3976 3975 cmn_err(CE_WARN, "%s%d: Failed to add attr [%s] for %s event",
3977 3976 ddi_driver_name(self), ddi_get_instance(self),
3978 3977 DR_AP_ID, EC_DR);
3979 3978 nvlist_free(ev_attr_list);
3980 3979 return;
3981 3980 }
3982 3981
3983 3982
3984 3983 /*
3985 3984 * Log this event with sysevent framework.
3986 3985 */
3987 3986
3988 3987 err = ddi_log_sysevent(self, DDI_VENDOR_SUNW, EC_DR,
3989 3988 ev_subclass, ev_attr_list, &eid,
3990 3989 ((kmflag == KM_SLEEP) ? DDI_SLEEP : DDI_NOSLEEP));
3991 3990 if (err != 0) {
3992 3991 cmn_err(CE_WARN, "%s%d: Failed to log %s event",
3993 3992 ddi_driver_name(self), ddi_get_instance(self), EC_DR);
3994 3993 }
3995 3994
3996 3995 nvlist_free(ev_attr_list);
3997 3996 }
3998 3997
3999 3998 int
4000 3999 pcihp_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
4001 4000 int flags, char *name, caddr_t valuep, int *lengthp)
4002 4001 {
4003 4002 int pci_dev;
4004 4003
4005 4004 if (dev == DDI_DEV_T_ANY)
4006 4005 goto skip;
4007 4006
4008 4007 if (strcmp(name, "pci-occupant") == 0) {
4009 4008 pci_dev = PCIHP_AP_MINOR_NUM_TO_PCI_DEVNUM(getminor(dev));
4010 4009 pcihp_create_occupant_props(dip, dev, pci_dev);
4011 4010 }
4012 4011 /* other cases... */
4013 4012 skip:
4014 4013 return (ddi_prop_op(dev, dip, prop_op, flags, name, valuep, lengthp));
4015 4014 }
4016 4015
4017 4016 /*
4018 4017 * this function is called only for SPARC platforms, where we may have
4019 4018 * a mix n' match of direct vs indirectly mapped configuration space.
4020 4019 * On x86, this function should always return success since the configuration
4021 4020 * space is always indirect mapped.
4022 4021 */
4023 4022 /*ARGSUSED*/
4024 4023 static int
4025 4024 pcihp_indirect_map(dev_info_t *dip)
4026 4025 {
4027 4026 #if defined(__sparc)
4028 4027 int rc = DDI_FAILURE;
4029 4028
4030 4029 if (ddi_prop_get_int(DDI_DEV_T_ANY, ddi_get_parent(dip), 0,
4031 4030 PCI_DEV_CONF_MAP_PROP, DDI_FAILURE) != DDI_FAILURE)
4032 4031 rc = DDI_SUCCESS;
4033 4032 else
4034 4033 if (ddi_prop_get_int(DDI_DEV_T_ANY, ddi_get_parent(dip),
4035 4034 0, PCI_BUS_CONF_MAP_PROP, DDI_FAILURE) != DDI_FAILURE)
4036 4035 rc = DDI_SUCCESS;
4037 4036 return (rc);
4038 4037 #else
4039 4038 return (DDI_SUCCESS);
4040 4039 #endif
4041 4040 }
↓ open down ↓ |
3715 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX