17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5f94c6026Sjj156685 * Common Development and Distribution License (the "License"). 6f94c6026Sjj156685 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*26947304SEvan Yan * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * ********************************************************************** 287c478bd9Sstevel@tonic-gate * Extension module for PCI nexus drivers to support PCI Hot Plug feature. 297c478bd9Sstevel@tonic-gate * 307c478bd9Sstevel@tonic-gate * DESCRIPTION: 317c478bd9Sstevel@tonic-gate * This module basically implements "devctl" and Attachment Point device 327c478bd9Sstevel@tonic-gate * nodes for hot plug operations. The cb_ops functions needed for access 337c478bd9Sstevel@tonic-gate * to these device nodes are also implemented. For hotplug operations 347c478bd9Sstevel@tonic-gate * on Attachment Points it interacts with the hotplug services (HPS) 357c478bd9Sstevel@tonic-gate * framework. A pci nexus driver would simply call pcihp_init() in its 367c478bd9Sstevel@tonic-gate * attach() function and pcihp_uninit() call in its detach() function. 377c478bd9Sstevel@tonic-gate * ********************************************************************** 387c478bd9Sstevel@tonic-gate */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #include <sys/conf.h> 417c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 427c478bd9Sstevel@tonic-gate #include <sys/debug.h> 437c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 447c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 457c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 467c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 477c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 487c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 497c478bd9Sstevel@tonic-gate #include <sys/ndi_impldefs.h> 507c478bd9Sstevel@tonic-gate #include <sys/ddipropdefs.h> 517c478bd9Sstevel@tonic-gate #include <sys/open.h> 527c478bd9Sstevel@tonic-gate #include <sys/file.h> 537c478bd9Sstevel@tonic-gate #include <sys/stat.h> 547c478bd9Sstevel@tonic-gate #include <sys/pci.h> 557c478bd9Sstevel@tonic-gate #include <sys/pci_impl.h> 567c478bd9Sstevel@tonic-gate #include <sys/devctl.h> 577c478bd9Sstevel@tonic-gate #include <sys/hotplug/hpcsvc.h> 587c478bd9Sstevel@tonic-gate #include <sys/hotplug/pci/pcicfg.h> 597c478bd9Sstevel@tonic-gate #include <sys/hotplug/pci/pcihp.h> 607c478bd9Sstevel@tonic-gate #include <sys/sysevent.h> 617c478bd9Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h> 627c478bd9Sstevel@tonic-gate #include <sys/sysevent/dr.h> 637c478bd9Sstevel@tonic-gate #include <sys/fs/dv_node.h> 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* 667c478bd9Sstevel@tonic-gate * NOTE: 677c478bd9Sstevel@tonic-gate * This module depends on PCI Configurator module (misc/pcicfg), 687c478bd9Sstevel@tonic-gate * Hot Plug Services framework module (misc/hpcsvc) and Bus Resource 697c478bd9Sstevel@tonic-gate * Allocator module (misc/busra). 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * ************************************************************************ 747c478bd9Sstevel@tonic-gate * *** Implementation specific data structures/definitions. *** 757c478bd9Sstevel@tonic-gate * ************************************************************************ 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate /* soft state */ 797c478bd9Sstevel@tonic-gate typedef enum { PCIHP_SOFT_STATE_CLOSED, PCIHP_SOFT_STATE_OPEN, 807c478bd9Sstevel@tonic-gate PCIHP_SOFT_STATE_OPEN_EXCL } pcihp_soft_state_t; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #define PCI_MAX_DEVS 32 /* max. number of devices on a pci bus */ 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* the following correspond to sysevent defined subclasses */ 857c478bd9Sstevel@tonic-gate #define PCIHP_DR_AP_STATE_CHANGE 0 867c478bd9Sstevel@tonic-gate #define PCIHP_DR_REQ 1 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* pcihp_get_soft_state() command argument */ 897c478bd9Sstevel@tonic-gate #define PCIHP_DR_NOOP 0 907c478bd9Sstevel@tonic-gate #define PCIHP_DR_BUS_CONFIGURE 1 917c478bd9Sstevel@tonic-gate #define PCIHP_DR_BUS_UNCONFIGURE 2 927c478bd9Sstevel@tonic-gate #define PCIHP_DR_SLOT_ENTER 4 937c478bd9Sstevel@tonic-gate #define PCIHP_DR_SLOT_EXIT 8 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* hot plug bus state */ 967c478bd9Sstevel@tonic-gate enum { PCIHP_BUS_INITIALIZING, PCIHP_BUS_UNCONFIGURED, 977c478bd9Sstevel@tonic-gate PCIHP_BUS_CONFIGURED }; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * Soft state structure associated with each hot plug pci bus instance. 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate typedef struct pcihp { 1037c478bd9Sstevel@tonic-gate struct pcihp *nextp; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* devinfo pointer to the pci bus node */ 1067c478bd9Sstevel@tonic-gate dev_info_t *dip; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate /* soft state flags: PCIHP_SOFT_STATE_* */ 1097c478bd9Sstevel@tonic-gate pcihp_soft_state_t soft_state; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* global mutex to serialize exclusive access to the bus */ 1127c478bd9Sstevel@tonic-gate kmutex_t mutex; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* slot information structure */ 1157c478bd9Sstevel@tonic-gate struct pcihp_slotinfo { 1167c478bd9Sstevel@tonic-gate hpc_slot_t slot_hdl; /* HPS slot handle */ 1177c478bd9Sstevel@tonic-gate ap_rstate_t rstate; /* state of Receptacle */ 1187c478bd9Sstevel@tonic-gate ap_ostate_t ostate; /* state of the Occupant */ 1197c478bd9Sstevel@tonic-gate ap_condition_t condition; /* condition of the occupant */ 1207c478bd9Sstevel@tonic-gate time32_t last_change; /* XXX needed? */ 1217c478bd9Sstevel@tonic-gate uint32_t event_mask; /* last event mask registered */ 1227c478bd9Sstevel@tonic-gate char *name; /* slot logical name */ 1237c478bd9Sstevel@tonic-gate uint_t slot_flags; 1247c478bd9Sstevel@tonic-gate uint16_t slot_type; /* slot type: pci or cpci */ 1257c478bd9Sstevel@tonic-gate uint16_t slot_capabilities; /* 64bit, etc. */ 1267c478bd9Sstevel@tonic-gate int hs_csr_location; /* Location of HS_CSR */ 1277c478bd9Sstevel@tonic-gate kmutex_t slot_mutex; /* mutex to serialize hotplug */ 1287c478bd9Sstevel@tonic-gate /* operations on the slot */ 1297c478bd9Sstevel@tonic-gate } slotinfo[PCI_MAX_DEVS]; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* misc. bus attributes */ 1327c478bd9Sstevel@tonic-gate uint_t bus_flags; 1337c478bd9Sstevel@tonic-gate uint_t bus_state; 1347c478bd9Sstevel@tonic-gate uint_t slots_active; 1357c478bd9Sstevel@tonic-gate } pcihp_t; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* 1387c478bd9Sstevel@tonic-gate * Bit definitions for slot_flags field: 1397c478bd9Sstevel@tonic-gate * 1407c478bd9Sstevel@tonic-gate * PCIHP_SLOT_AUTO_CFG_EN This flags is set if nexus can do auto 1417c478bd9Sstevel@tonic-gate * configuration of hot plugged card on this slot 1427c478bd9Sstevel@tonic-gate * if the hardware reports the hot plug events. 1437c478bd9Sstevel@tonic-gate * 1447c478bd9Sstevel@tonic-gate * PCIHP_SLOT_DISABLED Slot is disabled for hotplug operations. 1457c478bd9Sstevel@tonic-gate * 1467c478bd9Sstevel@tonic-gate * PCIHP_SLOT_NOT_HEALTHY HEALTHY# signal is not OK on this slot. 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate #define PCIHP_SLOT_AUTO_CFG_EN 0x1 1497c478bd9Sstevel@tonic-gate #define PCIHP_SLOT_DISABLED 0x2 1507c478bd9Sstevel@tonic-gate #define PCIHP_SLOT_NOT_HEALTHY 0x4 1517c478bd9Sstevel@tonic-gate #define PCIHP_SLOT_DEV_NON_HOTPLUG 0x8 1527c478bd9Sstevel@tonic-gate #define PCIHP_SLOT_ENUM_INS_PENDING 0x10 1537c478bd9Sstevel@tonic-gate #define PCIHP_SLOT_ENUM_EXT_PENDING 0x20 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* 1567c478bd9Sstevel@tonic-gate * Bit definitions for bus_flags field: 1577c478bd9Sstevel@tonic-gate * 1587c478bd9Sstevel@tonic-gate * PCIHP_BUS_66MHZ Bus is running at 66Mhz. 1597c478bd9Sstevel@tonic-gate */ 1607c478bd9Sstevel@tonic-gate #define PCIHP_BUS_66MHZ 0x1 1617c478bd9Sstevel@tonic-gate #define PCIHP_BUS_ENUM_RADIAL 0x2 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate #define PCIHP_DEVICES_STR "/devices" 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * control structure for tree walk during configure/unconfigure operation. 1677c478bd9Sstevel@tonic-gate */ 1687c478bd9Sstevel@tonic-gate struct pcihp_config_ctrl { 1697c478bd9Sstevel@tonic-gate int pci_dev; /* PCI device number for the slot */ 1707c478bd9Sstevel@tonic-gate uint_t flags; /* control flags (see below) */ 1717c478bd9Sstevel@tonic-gate int op; /* operation: PCIHP_ONLINE or PCIHP_OFFLINE */ 1727c478bd9Sstevel@tonic-gate int rv; /* return error code */ 1737c478bd9Sstevel@tonic-gate dev_info_t *dip; /* dip at which the (first) error occurred */ 1747c478bd9Sstevel@tonic-gate hpc_occupant_info_t *occupant; 1757c478bd9Sstevel@tonic-gate }; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate /* 1787c478bd9Sstevel@tonic-gate * control flags for configure/unconfigure operations on the tree. 1797c478bd9Sstevel@tonic-gate * 1807c478bd9Sstevel@tonic-gate * PCIHP_CFG_CONTINUE continue the operation ignoring errors 1817c478bd9Sstevel@tonic-gate */ 1827c478bd9Sstevel@tonic-gate #define PCIHP_CFG_CONTINUE 0x1 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate #define PCIHP_ONLINE 1 1857c478bd9Sstevel@tonic-gate #define PCIHP_OFFLINE 0 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate /* Leaf ops (hotplug controls for target devices) */ 1897c478bd9Sstevel@tonic-gate static int pcihp_open(dev_t *, int, int, cred_t *); 1907c478bd9Sstevel@tonic-gate static int pcihp_close(dev_t, int, int, cred_t *); 1917c478bd9Sstevel@tonic-gate static int pcihp_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate #ifdef DEBUG 1947c478bd9Sstevel@tonic-gate static int pcihp_debug = 0; 1957c478bd9Sstevel@tonic-gate #define PCIHP_DEBUG(args) if (pcihp_debug >= 1) cmn_err args 1967c478bd9Sstevel@tonic-gate #define PCIHP_DEBUG2(args) if (pcihp_debug >= 2) cmn_err args 1977c478bd9Sstevel@tonic-gate #else 1987c478bd9Sstevel@tonic-gate #define PCIHP_DEBUG(args) 1997c478bd9Sstevel@tonic-gate #define PCIHP_DEBUG2(args) 2007c478bd9Sstevel@tonic-gate #endif 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate /* 2037c478bd9Sstevel@tonic-gate * We process ENUM# event one device at a time ie. as soon as we detect 2047c478bd9Sstevel@tonic-gate * that a device has the right ENUM# conditions, we return. If the following 2057c478bd9Sstevel@tonic-gate * variable is set to non-zero, we scan all the devices on the bus 2067c478bd9Sstevel@tonic-gate * for ENUM# conditions. 2077c478bd9Sstevel@tonic-gate */ 2087c478bd9Sstevel@tonic-gate static int pcihp_enum_scan_all = 0; 2097c478bd9Sstevel@tonic-gate /* 2107c478bd9Sstevel@tonic-gate * If HSC driver cannot determine the board type (for example: it may not 2117c478bd9Sstevel@tonic-gate * be possible to differentiate between a Basic Hotswap, Non Hotswap or 2127c478bd9Sstevel@tonic-gate * Non-friendly Full hotswap board), the default board type is assigned 2137c478bd9Sstevel@tonic-gate * to be as defined by the following variable. 2147c478bd9Sstevel@tonic-gate */ 2157c478bd9Sstevel@tonic-gate static int pcihp_cpci_board_type = HPC_BOARD_CPCI_NON_HS; 2167c478bd9Sstevel@tonic-gate static int pcihp_cpci_led_blink = 30; 2177c478bd9Sstevel@tonic-gate /* 2187c478bd9Sstevel@tonic-gate * It was noted that the blue LED when written on/off would cause INS/EXT 2197c478bd9Sstevel@tonic-gate * bit to be set causing an extra interrupt. Although the cPCI specifications 2207c478bd9Sstevel@tonic-gate * does not imply this, this behavior is seen with some FHS silicons. 2217c478bd9Sstevel@tonic-gate * Also, handling the INS/EXT bit would control the LED being On/Off. 2227c478bd9Sstevel@tonic-gate * Until the behavior is confirmed, this flag could be used to enable or 2237c478bd9Sstevel@tonic-gate * disable handling the LED. 2247c478bd9Sstevel@tonic-gate * 0 means the silicons handles the LED behavior via the INS/EXT bit. 2257c478bd9Sstevel@tonic-gate * 1 means the software must explicitly do the LED behavior. 2267c478bd9Sstevel@tonic-gate */ 2277c478bd9Sstevel@tonic-gate static int pcihp_cpci_blue_led = 1; 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate /* static functions */ 2307c478bd9Sstevel@tonic-gate static pcihp_t *pcihp_create_soft_state(dev_info_t *dip); 2317c478bd9Sstevel@tonic-gate static void pcihp_destroy_soft_state(dev_info_t *dip); 2327c478bd9Sstevel@tonic-gate static pcihp_t *pcihp_get_soft_state(dev_info_t *dip, int cmd, int *rv); 2337c478bd9Sstevel@tonic-gate static int pcihp_configure_ap(pcihp_t *pcihp_p, int pci_dev); 2347c478bd9Sstevel@tonic-gate static int pcihp_unconfigure_ap(pcihp_t *pcihp_p, int pci_dev); 2357c478bd9Sstevel@tonic-gate static int pcihp_new_slot_state(dev_info_t *, hpc_slot_t, 2367c478bd9Sstevel@tonic-gate hpc_slot_info_t *, int); 2377c478bd9Sstevel@tonic-gate static int pcihp_configure(dev_info_t *, void *); 23832d69156Sscarter static bool_t pcihp_check_status(dev_info_t *); 2397c478bd9Sstevel@tonic-gate static int pcihp_event_handler(caddr_t, uint_t); 2407c478bd9Sstevel@tonic-gate static dev_info_t *pcihp_devi_find(dev_info_t *dip, uint_t dev, uint_t func); 2417c478bd9Sstevel@tonic-gate static int pcihp_match_dev(dev_info_t *dip, void *hdl); 2427c478bd9Sstevel@tonic-gate static int pcihp_get_hs_csr(struct pcihp_slotinfo *, ddi_acc_handle_t, 2437c478bd9Sstevel@tonic-gate uint8_t *); 2447c478bd9Sstevel@tonic-gate static void pcihp_set_hs_csr(struct pcihp_slotinfo *, ddi_acc_handle_t, 2457c478bd9Sstevel@tonic-gate uint8_t *); 2467c478bd9Sstevel@tonic-gate static int pcihp_get_hs_csr_location(ddi_acc_handle_t); 2477c478bd9Sstevel@tonic-gate static int pcihp_handle_enum(pcihp_t *, int, int, int); 2487c478bd9Sstevel@tonic-gate static void pcihp_hs_csr_op(pcihp_t *, int, int); 2497c478bd9Sstevel@tonic-gate static int pcihp_enum_slot(pcihp_t *, struct pcihp_slotinfo *, int, int, int); 2507c478bd9Sstevel@tonic-gate static int pcihp_handle_enum_extraction(pcihp_t *, int, int, int); 2517c478bd9Sstevel@tonic-gate static int pcihp_handle_enum_insertion(pcihp_t *, int, int, int); 2527c478bd9Sstevel@tonic-gate static int pcihp_add_dummy_reg_property(dev_info_t *, uint_t, uint_t, uint_t); 2537c478bd9Sstevel@tonic-gate static int pcihp_config_setup(dev_info_t **, ddi_acc_handle_t *, 2547c478bd9Sstevel@tonic-gate dev_info_t **, int, pcihp_t *); 2557c478bd9Sstevel@tonic-gate static void pcihp_config_teardown(ddi_acc_handle_t *, 2567c478bd9Sstevel@tonic-gate dev_info_t **, int, pcihp_t *); 2577c478bd9Sstevel@tonic-gate static int pcihp_get_board_type(struct pcihp_slotinfo *); 2587c478bd9Sstevel@tonic-gate /* sysevent function */ 2597c478bd9Sstevel@tonic-gate static void pcihp_gen_sysevent(char *, int, int, dev_info_t *, int); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate static int pcihp_list_occupants(dev_info_t *, void *); 2627c478bd9Sstevel@tonic-gate static int pcihp_indirect_map(dev_info_t *dip); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate #if 0 2657c478bd9Sstevel@tonic-gate static void pcihp_probe_slot_state(dev_info_t *, int, hpc_slot_state_t *); 2667c478bd9Sstevel@tonic-gate #endif 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate int pcihp_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, 2697c478bd9Sstevel@tonic-gate int flags, char *name, caddr_t valuep, int *lengthp); 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate struct cb_ops pcihp_cb_ops = { 2727c478bd9Sstevel@tonic-gate pcihp_open, /* open */ 2737c478bd9Sstevel@tonic-gate pcihp_close, /* close */ 2747c478bd9Sstevel@tonic-gate nodev, /* strategy */ 2757c478bd9Sstevel@tonic-gate nodev, /* print */ 2767c478bd9Sstevel@tonic-gate nodev, /* dump */ 2777c478bd9Sstevel@tonic-gate nodev, /* read */ 2787c478bd9Sstevel@tonic-gate nodev, /* write */ 2797c478bd9Sstevel@tonic-gate pcihp_ioctl, /* ioctl */ 2807c478bd9Sstevel@tonic-gate nodev, /* devmap */ 2817c478bd9Sstevel@tonic-gate nodev, /* mmap */ 2827c478bd9Sstevel@tonic-gate nodev, /* segmap */ 2837c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 2847c478bd9Sstevel@tonic-gate pcihp_prop_op, /* cb_prop_op */ 2857c478bd9Sstevel@tonic-gate NULL, /* streamtab */ 2867c478bd9Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */ 2877c478bd9Sstevel@tonic-gate CB_REV, /* rev */ 2887c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 2897c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 2907c478bd9Sstevel@tonic-gate }; 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate /* 2937c478bd9Sstevel@tonic-gate * local data 2947c478bd9Sstevel@tonic-gate */ 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate int pcihp_autocfg_enabled = 1; /* auto config is enabled by default */ 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate static kmutex_t pcihp_mutex; /* mutex to protect the following data */ 2997c478bd9Sstevel@tonic-gate static pcihp_t *pcihp_head = NULL; 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate static kmutex_t pcihp_open_mutex; /* mutex to protect open/close/uninit */ 3027c478bd9Sstevel@tonic-gate static int pci_devlink_flags = 0; 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate /* 3057c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 3067c478bd9Sstevel@tonic-gate */ 3077c478bd9Sstevel@tonic-gate extern struct mod_ops mod_miscops; 3087c478bd9Sstevel@tonic-gate static struct modlmisc modlmisc = { 3097c478bd9Sstevel@tonic-gate &mod_miscops, 31099e6869fSjmcp "PCI nexus hotplug support", 3117c478bd9Sstevel@tonic-gate }; 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 3147c478bd9Sstevel@tonic-gate MODREV_1, 3157c478bd9Sstevel@tonic-gate &modlmisc, 3167c478bd9Sstevel@tonic-gate NULL 3177c478bd9Sstevel@tonic-gate }; 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate int 3207c478bd9Sstevel@tonic-gate _init(void) 3217c478bd9Sstevel@tonic-gate { 3227c478bd9Sstevel@tonic-gate int error; 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate mutex_init(&pcihp_mutex, NULL, MUTEX_DRIVER, NULL); 3257c478bd9Sstevel@tonic-gate mutex_init(&pcihp_open_mutex, NULL, MUTEX_DRIVER, NULL); 3267c478bd9Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) { 3277c478bd9Sstevel@tonic-gate mutex_destroy(&pcihp_open_mutex); 3287c478bd9Sstevel@tonic-gate mutex_destroy(&pcihp_mutex); 3297c478bd9Sstevel@tonic-gate } 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate return (error); 3327c478bd9Sstevel@tonic-gate } 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate int 3357c478bd9Sstevel@tonic-gate _fini(void) 3367c478bd9Sstevel@tonic-gate { 3377c478bd9Sstevel@tonic-gate return (EBUSY); 3387c478bd9Sstevel@tonic-gate } 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate int 3417c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 3427c478bd9Sstevel@tonic-gate { 3437c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate static pcihp_t * 3477c478bd9Sstevel@tonic-gate pcihp_create_soft_state( 3487c478bd9Sstevel@tonic-gate dev_info_t *dip) 3497c478bd9Sstevel@tonic-gate { 3507c478bd9Sstevel@tonic-gate pcihp_t *pcihp_p; 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate pcihp_p = kmem_zalloc(sizeof (struct pcihp), KM_SLEEP); 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate pcihp_p->dip = dip; 3557c478bd9Sstevel@tonic-gate mutex_init(&pcihp_p->mutex, NULL, MUTEX_DRIVER, NULL); 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate mutex_enter(&pcihp_mutex); 3587c478bd9Sstevel@tonic-gate pcihp_p->nextp = pcihp_head; 3597c478bd9Sstevel@tonic-gate pcihp_head = pcihp_p; 3607c478bd9Sstevel@tonic-gate pcihp_p->bus_state = PCIHP_BUS_INITIALIZING; 3617c478bd9Sstevel@tonic-gate pcihp_p->slots_active = 0; 3627c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_mutex); 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate return (pcihp_p); 3657c478bd9Sstevel@tonic-gate } 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate static void 3687c478bd9Sstevel@tonic-gate pcihp_destroy_soft_state( 3697c478bd9Sstevel@tonic-gate dev_info_t *dip) 3707c478bd9Sstevel@tonic-gate { 3717c478bd9Sstevel@tonic-gate pcihp_t *p; 3727c478bd9Sstevel@tonic-gate pcihp_t **pp; 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate mutex_enter(&pcihp_mutex); 3757c478bd9Sstevel@tonic-gate pp = &pcihp_head; 3767c478bd9Sstevel@tonic-gate while ((p = *pp) != NULL) { 3777c478bd9Sstevel@tonic-gate if (p->dip == dip) { 3787c478bd9Sstevel@tonic-gate *pp = p->nextp; 3797c478bd9Sstevel@tonic-gate kmem_free(p, sizeof (struct pcihp)); 3807c478bd9Sstevel@tonic-gate break; 3817c478bd9Sstevel@tonic-gate } 3827c478bd9Sstevel@tonic-gate pp = &(p->nextp); 3837c478bd9Sstevel@tonic-gate } 3847c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_mutex); 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate /* 3887c478bd9Sstevel@tonic-gate * This function should be imported by client nexus drivers as their 3897c478bd9Sstevel@tonic-gate * devo_getinfo() entry point. 3907c478bd9Sstevel@tonic-gate */ 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate /* ARGSUSED */ 3937c478bd9Sstevel@tonic-gate int 3947c478bd9Sstevel@tonic-gate pcihp_info( 3957c478bd9Sstevel@tonic-gate dev_info_t *dip, 3967c478bd9Sstevel@tonic-gate ddi_info_cmd_t cmd, 3977c478bd9Sstevel@tonic-gate void *arg, 3987c478bd9Sstevel@tonic-gate void **result) 3997c478bd9Sstevel@tonic-gate { 4007c478bd9Sstevel@tonic-gate pcihp_t *pcihp_p; 4017c478bd9Sstevel@tonic-gate major_t major; 4027c478bd9Sstevel@tonic-gate minor_t minor; 4037c478bd9Sstevel@tonic-gate int instance; 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate major = getmajor((dev_t)arg); 4067c478bd9Sstevel@tonic-gate minor = getminor((dev_t)arg); 4077c478bd9Sstevel@tonic-gate instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor); 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate switch (cmd) { 4107c478bd9Sstevel@tonic-gate default: 4117c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 4147c478bd9Sstevel@tonic-gate *result = (void *)(intptr_t)instance; 4157c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 4187c478bd9Sstevel@tonic-gate mutex_enter(&pcihp_mutex); 4197c478bd9Sstevel@tonic-gate pcihp_p = pcihp_head; 4207c478bd9Sstevel@tonic-gate while (pcihp_p != NULL) { 4215c066ec2SJerry Gilliam if (ddi_driver_major(pcihp_p->dip) == 4227c478bd9Sstevel@tonic-gate major && ddi_get_instance(pcihp_p->dip) == 4237c478bd9Sstevel@tonic-gate instance) { 4247c478bd9Sstevel@tonic-gate *result = (void *)pcihp_p->dip; 4257c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_mutex); 4267c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4277c478bd9Sstevel@tonic-gate } 4287c478bd9Sstevel@tonic-gate pcihp_p = pcihp_p->nextp; 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_mutex); 4317c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate } 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate /* 4367c478bd9Sstevel@tonic-gate * This function retrieves the hot plug soft state and performs the 4377c478bd9Sstevel@tonic-gate * following primitive commands while the soft state is locked: 4387c478bd9Sstevel@tonic-gate * mark the bus unconfigured, increment slot activity, decrement 4397c478bd9Sstevel@tonic-gate * slot activity and noop. 4407c478bd9Sstevel@tonic-gate */ 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4437c478bd9Sstevel@tonic-gate static pcihp_t * 4447c478bd9Sstevel@tonic-gate pcihp_get_soft_state( 4457c478bd9Sstevel@tonic-gate dev_info_t *dip, int cmd, int *rv) 4467c478bd9Sstevel@tonic-gate { 4477c478bd9Sstevel@tonic-gate pcihp_t *pcihp_p; 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate *rv = PCIHP_SUCCESS; 4507c478bd9Sstevel@tonic-gate mutex_enter(&pcihp_mutex); 4517c478bd9Sstevel@tonic-gate pcihp_p = pcihp_head; 4527c478bd9Sstevel@tonic-gate while (pcihp_p != NULL) { 4537c478bd9Sstevel@tonic-gate if (pcihp_p->dip == dip) { 4547c478bd9Sstevel@tonic-gate switch (cmd) { 4557c478bd9Sstevel@tonic-gate case PCIHP_DR_BUS_UNCONFIGURE: 4567c478bd9Sstevel@tonic-gate if (pcihp_p->slots_active == 0) 4577c478bd9Sstevel@tonic-gate pcihp_p->bus_state = 4587c478bd9Sstevel@tonic-gate PCIHP_BUS_UNCONFIGURED; 4597c478bd9Sstevel@tonic-gate else 4607c478bd9Sstevel@tonic-gate *rv = PCIHP_FAILURE; 4617c478bd9Sstevel@tonic-gate break; 4627c478bd9Sstevel@tonic-gate case PCIHP_DR_SLOT_ENTER: 4637c478bd9Sstevel@tonic-gate if (pcihp_p->bus_state == 4647c478bd9Sstevel@tonic-gate PCIHP_BUS_UNCONFIGURED) 4657c478bd9Sstevel@tonic-gate *rv = PCIHP_FAILURE; 4667c478bd9Sstevel@tonic-gate else 4677c478bd9Sstevel@tonic-gate pcihp_p->slots_active++; 4687c478bd9Sstevel@tonic-gate break; 4697c478bd9Sstevel@tonic-gate case PCIHP_DR_SLOT_EXIT: 4707c478bd9Sstevel@tonic-gate ASSERT(pcihp_p->slots_active > 0); 4717c478bd9Sstevel@tonic-gate if (pcihp_p->slots_active == 0) 4727c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, 4737c478bd9Sstevel@tonic-gate "pcihp (%s%d): mismatched slot" 4747c478bd9Sstevel@tonic-gate " activity", 4757c478bd9Sstevel@tonic-gate ddi_driver_name(dip), 4767c478bd9Sstevel@tonic-gate ddi_get_instance(dip)); 4777c478bd9Sstevel@tonic-gate else 4787c478bd9Sstevel@tonic-gate pcihp_p->slots_active--; 4797c478bd9Sstevel@tonic-gate break; 4807c478bd9Sstevel@tonic-gate case PCIHP_DR_NOOP: 4817c478bd9Sstevel@tonic-gate break; 4827c478bd9Sstevel@tonic-gate default: 4837c478bd9Sstevel@tonic-gate *rv = PCIHP_FAILURE; 4847c478bd9Sstevel@tonic-gate break; 4857c478bd9Sstevel@tonic-gate } 4867c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_mutex); 4877c478bd9Sstevel@tonic-gate return (pcihp_p); 4887c478bd9Sstevel@tonic-gate } 4897c478bd9Sstevel@tonic-gate pcihp_p = pcihp_p->nextp; 4907c478bd9Sstevel@tonic-gate } 4917c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_mutex); 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate return (NULL); 4947c478bd9Sstevel@tonic-gate } 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate /* ARGSUSED3 */ 4977c478bd9Sstevel@tonic-gate static int 4987c478bd9Sstevel@tonic-gate pcihp_open(dev_t *devp, int flags, int otyp, cred_t *credp) 4997c478bd9Sstevel@tonic-gate { 5007c478bd9Sstevel@tonic-gate dev_info_t *self; 5017c478bd9Sstevel@tonic-gate pcihp_t *pcihp_p; 5027c478bd9Sstevel@tonic-gate minor_t minor; 5037c478bd9Sstevel@tonic-gate int pci_dev; 5047c478bd9Sstevel@tonic-gate int rv; 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate /* 5077c478bd9Sstevel@tonic-gate * Make sure the open is for the right file type. 5087c478bd9Sstevel@tonic-gate */ 5097c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 5107c478bd9Sstevel@tonic-gate return (EINVAL); 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate mutex_enter(&pcihp_open_mutex); 5137c478bd9Sstevel@tonic-gate /* 5147c478bd9Sstevel@tonic-gate * Get the soft state structure. 5157c478bd9Sstevel@tonic-gate */ 5167c478bd9Sstevel@tonic-gate if (pcihp_info(NULL, DDI_INFO_DEVT2DEVINFO, (void *)*devp, 5177c478bd9Sstevel@tonic-gate (void **)&self) != DDI_SUCCESS) { 5187c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 5197c478bd9Sstevel@tonic-gate return (ENXIO); 5207c478bd9Sstevel@tonic-gate } 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate pcihp_p = pcihp_get_soft_state(self, PCIHP_DR_NOOP, &rv); 5237c478bd9Sstevel@tonic-gate ASSERT(pcihp_p != NULL); 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate mutex_enter(&pcihp_p->mutex); 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* 5287c478bd9Sstevel@tonic-gate * If the pci_dev is valid then the minor device is an 5297c478bd9Sstevel@tonic-gate * AP. Otherwise it is ":devctl" minor device. 5307c478bd9Sstevel@tonic-gate */ 5317c478bd9Sstevel@tonic-gate minor = getminor(*devp); 5327c478bd9Sstevel@tonic-gate pci_dev = PCIHP_AP_MINOR_NUM_TO_PCI_DEVNUM(minor); 5337c478bd9Sstevel@tonic-gate if (pci_dev < PCI_MAX_DEVS) { 5347c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 5377c478bd9Sstevel@tonic-gate if (slotinfop->slot_hdl == NULL) { 5387c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_p->mutex); 5397c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 5407c478bd9Sstevel@tonic-gate return (ENXIO); 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate } 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate /* 5457c478bd9Sstevel@tonic-gate * Handle the open by tracking the device state. 5467c478bd9Sstevel@tonic-gate * 5477c478bd9Sstevel@tonic-gate * Note: Needs review w.r.t exclusive access to AP or the bus. 5487c478bd9Sstevel@tonic-gate * Currently in the pci plug-in we don't use EXCL open at all 5497c478bd9Sstevel@tonic-gate * so the code below implements EXCL access on the bus. 5507c478bd9Sstevel@tonic-gate */ 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate /* enforce exclusive access to the bus */ 5537c478bd9Sstevel@tonic-gate if ((pcihp_p->soft_state == PCIHP_SOFT_STATE_OPEN_EXCL) || 5547c478bd9Sstevel@tonic-gate ((flags & FEXCL) && 5557c478bd9Sstevel@tonic-gate (pcihp_p->soft_state != PCIHP_SOFT_STATE_CLOSED))) { 5567c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_p->mutex); 5577c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 5587c478bd9Sstevel@tonic-gate return (EBUSY); 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate if (flags & FEXCL) 5627c478bd9Sstevel@tonic-gate pcihp_p->soft_state = PCIHP_SOFT_STATE_OPEN_EXCL; 5637c478bd9Sstevel@tonic-gate else 5647c478bd9Sstevel@tonic-gate pcihp_p->soft_state = PCIHP_SOFT_STATE_OPEN; 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_p->mutex); 5677c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate return (0); 5707c478bd9Sstevel@tonic-gate } 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5737c478bd9Sstevel@tonic-gate static int 5747c478bd9Sstevel@tonic-gate pcihp_close(dev_t dev, int flags, int otyp, cred_t *credp) 5757c478bd9Sstevel@tonic-gate { 5767c478bd9Sstevel@tonic-gate dev_info_t *self; 5777c478bd9Sstevel@tonic-gate pcihp_t *pcihp_p; 5787c478bd9Sstevel@tonic-gate int rv; 5797c478bd9Sstevel@tonic-gate 5807c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 5817c478bd9Sstevel@tonic-gate return (EINVAL); 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate mutex_enter(&pcihp_open_mutex); 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate if (pcihp_info(NULL, DDI_INFO_DEVT2DEVINFO, (void *)dev, 5867c478bd9Sstevel@tonic-gate (void **)&self) != DDI_SUCCESS) { 5877c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 5887c478bd9Sstevel@tonic-gate return (ENXIO); 5897c478bd9Sstevel@tonic-gate } 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate pcihp_p = pcihp_get_soft_state(self, PCIHP_DR_NOOP, &rv); 5927c478bd9Sstevel@tonic-gate ASSERT(pcihp_p != NULL); 5937c478bd9Sstevel@tonic-gate 5947c478bd9Sstevel@tonic-gate mutex_enter(&pcihp_p->mutex); 5957c478bd9Sstevel@tonic-gate pcihp_p->soft_state = PCIHP_SOFT_STATE_CLOSED; 5967c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_p->mutex); 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate return (0); 6017c478bd9Sstevel@tonic-gate } 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate static int 6047c478bd9Sstevel@tonic-gate pcihp_list_occupants(dev_info_t *dip, void *hdl) 6057c478bd9Sstevel@tonic-gate { 6067c478bd9Sstevel@tonic-gate int pci_dev; 6077c478bd9Sstevel@tonic-gate struct pcihp_config_ctrl *ctrl = (struct pcihp_config_ctrl *)hdl; 6087c478bd9Sstevel@tonic-gate pci_regspec_t *pci_rp; 6097c478bd9Sstevel@tonic-gate int length; 6107c478bd9Sstevel@tonic-gate major_t major; 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate /* 6137c478bd9Sstevel@tonic-gate * Get the PCI device number information from the devinfo 6147c478bd9Sstevel@tonic-gate * node. Since the node may not have the address field 6157c478bd9Sstevel@tonic-gate * setup (this is done in the DDI_INITCHILD of the parent) 6167c478bd9Sstevel@tonic-gate * we look up the 'reg' property to decode that information. 6177c478bd9Sstevel@tonic-gate */ 6187c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 6197c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "reg", (int **)&pci_rp, 6207c478bd9Sstevel@tonic-gate (uint_t *)&length) != DDI_PROP_SUCCESS) { 6217c478bd9Sstevel@tonic-gate ctrl->rv = DDI_FAILURE; 6227c478bd9Sstevel@tonic-gate ctrl->dip = dip; 6237c478bd9Sstevel@tonic-gate return (DDI_WALK_TERMINATE); 6247c478bd9Sstevel@tonic-gate } 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate /* get the pci device id information */ 6277c478bd9Sstevel@tonic-gate pci_dev = PCI_REG_DEV_G(pci_rp->pci_phys_hi); 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate /* 6307c478bd9Sstevel@tonic-gate * free the memory allocated by ddi_prop_lookup_int_array 6317c478bd9Sstevel@tonic-gate */ 6327c478bd9Sstevel@tonic-gate ddi_prop_free(pci_rp); 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate /* 6357c478bd9Sstevel@tonic-gate * Match the node for the device number of the slot. 6367c478bd9Sstevel@tonic-gate */ 6377c478bd9Sstevel@tonic-gate if (pci_dev == ctrl->pci_dev) { /* node is a match */ 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate major = ddi_driver_major(dip); 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate /* 6427c478bd9Sstevel@tonic-gate * If the node is not yet attached, then don't list it 6437c478bd9Sstevel@tonic-gate * as an occupant. This is valid, since nothing can be 6447c478bd9Sstevel@tonic-gate * consuming it until it is attached, and cfgadm will 6457c478bd9Sstevel@tonic-gate * ask for the property explicitly which will cause it 6467c478bd9Sstevel@tonic-gate * to be re-freshed right before checking with rcm. 6477c478bd9Sstevel@tonic-gate */ 648737d277aScth if ((major == -1) || !i_ddi_devi_attached(dip)) 6497c478bd9Sstevel@tonic-gate return (DDI_WALK_PRUNECHILD); 6507c478bd9Sstevel@tonic-gate 65110302a14Scth /* 65210302a14Scth * If we have used all our occupants then print mesage 65310302a14Scth * and terminate walk. 65410302a14Scth */ 65510302a14Scth if (ctrl->occupant->i >= HPC_MAX_OCCUPANTS) { 65610302a14Scth cmn_err(CE_WARN, 65710302a14Scth "pcihp (%s%d): unable to list all occupants", 65810302a14Scth ddi_driver_name(ddi_get_parent(dip)), 65910302a14Scth ddi_get_instance(ddi_get_parent(dip))); 66010302a14Scth return (DDI_WALK_TERMINATE); 66110302a14Scth } 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate /* 6647c478bd9Sstevel@tonic-gate * No need to hold the dip as ddi_walk_devs 6657c478bd9Sstevel@tonic-gate * has already arranged that for us. 6667c478bd9Sstevel@tonic-gate */ 66710302a14Scth ctrl->occupant->id[ctrl->occupant->i] = 66810302a14Scth kmem_alloc(sizeof (char[MAXPATHLEN]), KM_SLEEP); 6697c478bd9Sstevel@tonic-gate (void) ddi_pathname(dip, 6707c478bd9Sstevel@tonic-gate (char *)ctrl->occupant->id[ctrl->occupant->i]); 6717c478bd9Sstevel@tonic-gate ctrl->occupant->i++; 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate /* 6757c478bd9Sstevel@tonic-gate * continue the walk to the next sibling to look for a match 6767c478bd9Sstevel@tonic-gate * or to find other nodes if this card is a multi-function card. 6777c478bd9Sstevel@tonic-gate */ 6787c478bd9Sstevel@tonic-gate return (DDI_WALK_PRUNECHILD); 6797c478bd9Sstevel@tonic-gate } 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate static void 6827c478bd9Sstevel@tonic-gate pcihp_create_occupant_props_nolock(dev_info_t *self, dev_t dev, int pci_dev) 6837c478bd9Sstevel@tonic-gate { 6847c478bd9Sstevel@tonic-gate struct pcihp_config_ctrl ctrl; 6857c478bd9Sstevel@tonic-gate hpc_occupant_info_t *occupant; 6867c478bd9Sstevel@tonic-gate int i; 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate occupant = kmem_alloc(sizeof (hpc_occupant_info_t), KM_SLEEP); 6897c478bd9Sstevel@tonic-gate occupant->i = 0; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate ctrl.flags = 0; 6927c478bd9Sstevel@tonic-gate ctrl.dip = NULL; 6937c478bd9Sstevel@tonic-gate ctrl.rv = NDI_SUCCESS; 6947c478bd9Sstevel@tonic-gate ctrl.pci_dev = pci_dev; 6957c478bd9Sstevel@tonic-gate ctrl.op = 55; /* should define DRYRUN */ 6967c478bd9Sstevel@tonic-gate ctrl.occupant = occupant; 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_get_child(self), pcihp_list_occupants, 6997c478bd9Sstevel@tonic-gate (void *)&ctrl); 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate if (occupant->i == 0) { 7027c478bd9Sstevel@tonic-gate /* no occupants right now, need to create stub property */ 7037c478bd9Sstevel@tonic-gate char *c[] = { "" }; 7047c478bd9Sstevel@tonic-gate (void) ddi_prop_update_string_array(dev, self, "pci-occupant", 7057c478bd9Sstevel@tonic-gate c, 1); 7067c478bd9Sstevel@tonic-gate } else { 7077c478bd9Sstevel@tonic-gate (void) ddi_prop_update_string_array(dev, self, "pci-occupant", 7087c478bd9Sstevel@tonic-gate occupant->id, occupant->i); 7097c478bd9Sstevel@tonic-gate } 7107c478bd9Sstevel@tonic-gate for (i = 0; i < occupant->i; i++) { 7117c478bd9Sstevel@tonic-gate kmem_free(occupant->id[i], sizeof (char[MAXPATHLEN])); 7127c478bd9Sstevel@tonic-gate } 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate kmem_free(occupant, sizeof (hpc_occupant_info_t)); 7157c478bd9Sstevel@tonic-gate } 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate static void 7187c478bd9Sstevel@tonic-gate pcihp_create_occupant_props(dev_info_t *self, dev_t dev, int pci_dev) 7197c478bd9Sstevel@tonic-gate { 7207c478bd9Sstevel@tonic-gate int circular; 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate ndi_devi_enter(self, &circular); 7237c478bd9Sstevel@tonic-gate pcihp_create_occupant_props_nolock(self, dev, pci_dev); 7247c478bd9Sstevel@tonic-gate ndi_devi_exit(self, circular); 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate 7277c478bd9Sstevel@tonic-gate static void 7287c478bd9Sstevel@tonic-gate pcihp_delete_occupant_props(dev_info_t *dip, dev_t dev) 7297c478bd9Sstevel@tonic-gate { 7307c478bd9Sstevel@tonic-gate if (ddi_prop_remove(dev, dip, "pci-occupant") 7317c478bd9Sstevel@tonic-gate != DDI_PROP_SUCCESS) 7327c478bd9Sstevel@tonic-gate return; /* add error handling */ 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate } 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate /* 7377c478bd9Sstevel@tonic-gate * pcihp_ioctl: devctl hotplug controls 7387c478bd9Sstevel@tonic-gate */ 7397c478bd9Sstevel@tonic-gate /* ARGSUSED */ 7407c478bd9Sstevel@tonic-gate static int 7417c478bd9Sstevel@tonic-gate pcihp_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, 7427c478bd9Sstevel@tonic-gate int *rvalp) 7437c478bd9Sstevel@tonic-gate { 7447c478bd9Sstevel@tonic-gate pcihp_t *pcihp_p; 7457c478bd9Sstevel@tonic-gate dev_info_t *self; 7467c478bd9Sstevel@tonic-gate struct devctl_iocdata *dcp; 7477c478bd9Sstevel@tonic-gate uint_t bus_state; 7487c478bd9Sstevel@tonic-gate int rv = 0; 7497c478bd9Sstevel@tonic-gate int pci_dev; 7507c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 7517c478bd9Sstevel@tonic-gate hpc_slot_state_t rstate; 7527c478bd9Sstevel@tonic-gate devctl_ap_state_t ap_state; 7537c478bd9Sstevel@tonic-gate struct hpc_control_data hpc_ctrldata; 7547c478bd9Sstevel@tonic-gate struct hpc_led_info led_info; 7557c478bd9Sstevel@tonic-gate time_t time; 7567c478bd9Sstevel@tonic-gate int state_locking; 7577c478bd9Sstevel@tonic-gate int state_unlocking; 7587c478bd9Sstevel@tonic-gate int rval; 7597c478bd9Sstevel@tonic-gate char *pathname = NULL; 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate /* 7627c478bd9Sstevel@tonic-gate * read devctl ioctl data before soft state retrieval 7637c478bd9Sstevel@tonic-gate */ 7647c478bd9Sstevel@tonic-gate if ((cmd != DEVCTL_AP_CONTROL) && 7657c478bd9Sstevel@tonic-gate ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS) 7667c478bd9Sstevel@tonic-gate return (EFAULT); 7677c478bd9Sstevel@tonic-gate 7687c478bd9Sstevel@tonic-gate if (pcihp_info(NULL, DDI_INFO_DEVT2DEVINFO, (void *)dev, 7697c478bd9Sstevel@tonic-gate (void **)&self) != DDI_SUCCESS) { 7707c478bd9Sstevel@tonic-gate if (cmd != DEVCTL_AP_CONTROL) 7717c478bd9Sstevel@tonic-gate ndi_dc_freehdl(dcp); 7727c478bd9Sstevel@tonic-gate return (ENXIO); 7737c478bd9Sstevel@tonic-gate } 7747c478bd9Sstevel@tonic-gate 7757c478bd9Sstevel@tonic-gate switch (cmd) { 7767c478bd9Sstevel@tonic-gate case DEVCTL_AP_INSERT: 7777c478bd9Sstevel@tonic-gate case DEVCTL_AP_REMOVE: 7787c478bd9Sstevel@tonic-gate case DEVCTL_AP_CONNECT: 7797c478bd9Sstevel@tonic-gate case DEVCTL_AP_DISCONNECT: 7807c478bd9Sstevel@tonic-gate case DEVCTL_AP_CONFIGURE: 7817c478bd9Sstevel@tonic-gate case DEVCTL_AP_UNCONFIGURE: 7827c478bd9Sstevel@tonic-gate case DEVCTL_AP_GETSTATE: 7837c478bd9Sstevel@tonic-gate case DEVCTL_AP_CONTROL: 7847c478bd9Sstevel@tonic-gate state_locking = PCIHP_DR_SLOT_ENTER; 7857c478bd9Sstevel@tonic-gate state_unlocking = PCIHP_DR_SLOT_EXIT; 7867c478bd9Sstevel@tonic-gate break; 7877c478bd9Sstevel@tonic-gate default: 7887c478bd9Sstevel@tonic-gate state_locking = PCIHP_DR_NOOP; 7897c478bd9Sstevel@tonic-gate state_unlocking = PCIHP_DR_NOOP; 7907c478bd9Sstevel@tonic-gate break; 7917c478bd9Sstevel@tonic-gate } 7927c478bd9Sstevel@tonic-gate 7937c478bd9Sstevel@tonic-gate pcihp_p = pcihp_get_soft_state(self, state_locking, &rval); 7947c478bd9Sstevel@tonic-gate ASSERT(pcihp_p != NULL); 7957c478bd9Sstevel@tonic-gate 7967c478bd9Sstevel@tonic-gate if (rval == PCIHP_FAILURE) { 7977c478bd9Sstevel@tonic-gate (void) ddi_pathname(pcihp_p->dip, pathname); 7987c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_WARN, "Hot Plug bus %s instance is unconfigured" 7997c478bd9Sstevel@tonic-gate " while slot activity is requested\n", pathname)); 8007c478bd9Sstevel@tonic-gate if (cmd != DEVCTL_AP_CONTROL) 8017c478bd9Sstevel@tonic-gate ndi_dc_freehdl(dcp); 8027c478bd9Sstevel@tonic-gate return (EBUSY); 8037c478bd9Sstevel@tonic-gate } 8047c478bd9Sstevel@tonic-gate 8057c478bd9Sstevel@tonic-gate /* 8067c478bd9Sstevel@tonic-gate * For attachment points the lower 8 bits of the minor number is the 8077c478bd9Sstevel@tonic-gate * PCI device number. 8087c478bd9Sstevel@tonic-gate */ 8097c478bd9Sstevel@tonic-gate pci_dev = PCIHP_AP_MINOR_NUM_TO_PCI_DEVNUM(getminor(dev)); 8107c478bd9Sstevel@tonic-gate 8117c478bd9Sstevel@tonic-gate /* 8127c478bd9Sstevel@tonic-gate * We can use the generic implementation for these ioctls 8137c478bd9Sstevel@tonic-gate */ 8147c478bd9Sstevel@tonic-gate switch (cmd) { 8157c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_GETSTATE: 8167c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_ONLINE: 8177c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_OFFLINE: 8187c478bd9Sstevel@tonic-gate case DEVCTL_BUS_GETSTATE: 8197c478bd9Sstevel@tonic-gate rv = ndi_devctl_ioctl(self, cmd, arg, mode, 0); 8207c478bd9Sstevel@tonic-gate ndi_dc_freehdl(dcp); 8217c478bd9Sstevel@tonic-gate return (rv); 8227c478bd9Sstevel@tonic-gate default: 8237c478bd9Sstevel@tonic-gate break; 8247c478bd9Sstevel@tonic-gate } 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate switch (cmd) { 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_RESET: 8297c478bd9Sstevel@tonic-gate rv = ENOTSUP; 8307c478bd9Sstevel@tonic-gate break; 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate case DEVCTL_BUS_QUIESCE: 8337c478bd9Sstevel@tonic-gate if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS) 8347c478bd9Sstevel@tonic-gate if (bus_state == BUS_QUIESCED) 8357c478bd9Sstevel@tonic-gate break; 8367c478bd9Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_QUIESCED); 8377c478bd9Sstevel@tonic-gate break; 8387c478bd9Sstevel@tonic-gate 8397c478bd9Sstevel@tonic-gate case DEVCTL_BUS_UNQUIESCE: 8407c478bd9Sstevel@tonic-gate if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS) 8417c478bd9Sstevel@tonic-gate if (bus_state == BUS_ACTIVE) 8427c478bd9Sstevel@tonic-gate break; 8437c478bd9Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_ACTIVE); 8447c478bd9Sstevel@tonic-gate break; 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate case DEVCTL_BUS_RESET: 8477c478bd9Sstevel@tonic-gate rv = ENOTSUP; 8487c478bd9Sstevel@tonic-gate break; 8497c478bd9Sstevel@tonic-gate 8507c478bd9Sstevel@tonic-gate case DEVCTL_BUS_RESETALL: 8517c478bd9Sstevel@tonic-gate rv = ENOTSUP; 8527c478bd9Sstevel@tonic-gate break; 8537c478bd9Sstevel@tonic-gate 8547c478bd9Sstevel@tonic-gate case DEVCTL_AP_CONNECT: 8557c478bd9Sstevel@tonic-gate case DEVCTL_AP_DISCONNECT: 8567c478bd9Sstevel@tonic-gate /* 8577c478bd9Sstevel@tonic-gate * CONNECT(DISCONNECT) the hot plug slot to(from) the bus. 8587c478bd9Sstevel@tonic-gate * 8597c478bd9Sstevel@tonic-gate * For cPCI slots this operation is a nop so the HPC 8607c478bd9Sstevel@tonic-gate * driver may return success if it is a valid operation. 8617c478bd9Sstevel@tonic-gate */ 8627c478bd9Sstevel@tonic-gate case DEVCTL_AP_INSERT: 8637c478bd9Sstevel@tonic-gate case DEVCTL_AP_REMOVE: 8647c478bd9Sstevel@tonic-gate /* 8657c478bd9Sstevel@tonic-gate * Prepare the slot for INSERT/REMOVE operation. 8667c478bd9Sstevel@tonic-gate */ 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate /* 8697c478bd9Sstevel@tonic-gate * check for valid request: 8707c478bd9Sstevel@tonic-gate * 1. It is a hotplug slot. 8717c478bd9Sstevel@tonic-gate * 2. The slot has no occupant that is in 8727c478bd9Sstevel@tonic-gate * the 'configured' state. 8737c478bd9Sstevel@tonic-gate */ 8747c478bd9Sstevel@tonic-gate if (pci_dev >= PCI_MAX_DEVS) { 8757c478bd9Sstevel@tonic-gate rv = ENXIO; 8767c478bd9Sstevel@tonic-gate break; 8777c478bd9Sstevel@tonic-gate } 8787c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 8797c478bd9Sstevel@tonic-gate 8807c478bd9Sstevel@tonic-gate mutex_enter(&slotinfop->slot_mutex); 8817c478bd9Sstevel@tonic-gate 8827c478bd9Sstevel@tonic-gate if ((slotinfop->slot_hdl == NULL) || 8837c478bd9Sstevel@tonic-gate (slotinfop->slot_flags & PCIHP_SLOT_DISABLED)) { 8847c478bd9Sstevel@tonic-gate rv = ENXIO; 8857c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 8867c478bd9Sstevel@tonic-gate break; 8877c478bd9Sstevel@tonic-gate } 8887c478bd9Sstevel@tonic-gate 8897c478bd9Sstevel@tonic-gate /* the slot occupant must be in the UNCONFIGURED state */ 8907c478bd9Sstevel@tonic-gate if (slotinfop->ostate != AP_OSTATE_UNCONFIGURED) { 8917c478bd9Sstevel@tonic-gate rv = EINVAL; 8927c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 8937c478bd9Sstevel@tonic-gate break; 8947c478bd9Sstevel@tonic-gate } 8957c478bd9Sstevel@tonic-gate /* 8967c478bd9Sstevel@tonic-gate * Call the HPC driver to perform the operation on the slot. 8977c478bd9Sstevel@tonic-gate */ 8987c478bd9Sstevel@tonic-gate 8997c478bd9Sstevel@tonic-gate switch (cmd) { 9007c478bd9Sstevel@tonic-gate case DEVCTL_AP_INSERT: 9017c478bd9Sstevel@tonic-gate rv = hpc_nexus_insert(slotinfop->slot_hdl, NULL, 0); 9027c478bd9Sstevel@tonic-gate break; 9037c478bd9Sstevel@tonic-gate case DEVCTL_AP_REMOVE: 9047c478bd9Sstevel@tonic-gate rv = hpc_nexus_remove(slotinfop->slot_hdl, NULL, 0); 9057c478bd9Sstevel@tonic-gate break; 9067c478bd9Sstevel@tonic-gate case DEVCTL_AP_CONNECT: 9077c478bd9Sstevel@tonic-gate rv = hpc_nexus_connect(slotinfop->slot_hdl, NULL, 0); 9087c478bd9Sstevel@tonic-gate if (rv == HPC_SUCCESS) { 9097c478bd9Sstevel@tonic-gate slotinfop->rstate = AP_RSTATE_CONNECTED; 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate if (drv_getparm(TIME, (void *)&time) != 9127c478bd9Sstevel@tonic-gate DDI_SUCCESS) 9137c478bd9Sstevel@tonic-gate slotinfop->last_change = (time_t)-1; 9147c478bd9Sstevel@tonic-gate else 9157c478bd9Sstevel@tonic-gate slotinfop->last_change = (time32_t)time; 9167c478bd9Sstevel@tonic-gate 9177c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 9187c478bd9Sstevel@tonic-gate pcihp_gen_sysevent(slotinfop->name, 9197c478bd9Sstevel@tonic-gate PCIHP_DR_AP_STATE_CHANGE, 9207c478bd9Sstevel@tonic-gate SE_NO_HINT, pcihp_p->dip, 9217c478bd9Sstevel@tonic-gate KM_SLEEP); 9227c478bd9Sstevel@tonic-gate } 9237c478bd9Sstevel@tonic-gate break; 9247c478bd9Sstevel@tonic-gate case DEVCTL_AP_DISCONNECT: 9257c478bd9Sstevel@tonic-gate rv = hpc_nexus_disconnect(slotinfop->slot_hdl, NULL, 0); 9267c478bd9Sstevel@tonic-gate if (rv == HPC_SUCCESS) { 9277c478bd9Sstevel@tonic-gate slotinfop->rstate = AP_RSTATE_DISCONNECTED; 9287c478bd9Sstevel@tonic-gate 9297c478bd9Sstevel@tonic-gate if (drv_getparm(TIME, (void *)&time) != 9307c478bd9Sstevel@tonic-gate DDI_SUCCESS) 9317c478bd9Sstevel@tonic-gate slotinfop->last_change = (time_t)-1; 9327c478bd9Sstevel@tonic-gate else 9337c478bd9Sstevel@tonic-gate slotinfop->last_change = (time32_t)time; 9347c478bd9Sstevel@tonic-gate 9357c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 9367c478bd9Sstevel@tonic-gate pcihp_gen_sysevent(slotinfop->name, 9377c478bd9Sstevel@tonic-gate PCIHP_DR_AP_STATE_CHANGE, 9387c478bd9Sstevel@tonic-gate SE_NO_HINT, pcihp_p->dip, 9397c478bd9Sstevel@tonic-gate KM_SLEEP); 9407c478bd9Sstevel@tonic-gate } 9417c478bd9Sstevel@tonic-gate break; 9427c478bd9Sstevel@tonic-gate } 9437c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 9447c478bd9Sstevel@tonic-gate 9457c478bd9Sstevel@tonic-gate switch (rv) { 9467c478bd9Sstevel@tonic-gate case HPC_ERR_INVALID: 9477c478bd9Sstevel@tonic-gate rv = ENXIO; 9487c478bd9Sstevel@tonic-gate break; 9497c478bd9Sstevel@tonic-gate case HPC_ERR_NOTSUPPORTED: 9507c478bd9Sstevel@tonic-gate rv = ENOTSUP; 9517c478bd9Sstevel@tonic-gate break; 9527c478bd9Sstevel@tonic-gate case HPC_ERR_FAILED: 9537c478bd9Sstevel@tonic-gate rv = EIO; 9547c478bd9Sstevel@tonic-gate break; 9557c478bd9Sstevel@tonic-gate } 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate break; 9587c478bd9Sstevel@tonic-gate 9597c478bd9Sstevel@tonic-gate case DEVCTL_AP_CONFIGURE: 9607c478bd9Sstevel@tonic-gate /* 9617c478bd9Sstevel@tonic-gate * ************************************** 9627c478bd9Sstevel@tonic-gate * CONFIGURE the occupant in the slot. 9637c478bd9Sstevel@tonic-gate * ************************************** 9647c478bd9Sstevel@tonic-gate */ 96570025d76Sjohnny slotinfop = &pcihp_p->slotinfo[pci_dev]; 96670025d76Sjohnny 96770025d76Sjohnny mutex_enter(&slotinfop->slot_mutex); 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate rv = pcihp_configure_ap(pcihp_p, pci_dev); 9707c478bd9Sstevel@tonic-gate if (rv == HPC_SUCCESS) { 9717c478bd9Sstevel@tonic-gate pcihp_gen_sysevent(slotinfop->name, 9727c478bd9Sstevel@tonic-gate PCIHP_DR_AP_STATE_CHANGE, 9737c478bd9Sstevel@tonic-gate SE_NO_HINT, pcihp_p->dip, KM_SLEEP); 9747c478bd9Sstevel@tonic-gate pcihp_create_occupant_props(self, dev, pci_dev); 9757c478bd9Sstevel@tonic-gate } 97670025d76Sjohnny mutex_exit(&slotinfop->slot_mutex); 9777c478bd9Sstevel@tonic-gate 9787c478bd9Sstevel@tonic-gate break; 9797c478bd9Sstevel@tonic-gate 9807c478bd9Sstevel@tonic-gate case DEVCTL_AP_UNCONFIGURE: 9817c478bd9Sstevel@tonic-gate /* 9827c478bd9Sstevel@tonic-gate * ************************************** 9837c478bd9Sstevel@tonic-gate * UNCONFIGURE the occupant in the slot. 9847c478bd9Sstevel@tonic-gate * ************************************** 9857c478bd9Sstevel@tonic-gate */ 98670025d76Sjohnny slotinfop = &pcihp_p->slotinfo[pci_dev]; 98770025d76Sjohnny 98870025d76Sjohnny mutex_enter(&slotinfop->slot_mutex); 9897c478bd9Sstevel@tonic-gate 9907c478bd9Sstevel@tonic-gate rv = pcihp_unconfigure_ap(pcihp_p, pci_dev); 9917c478bd9Sstevel@tonic-gate 9927c478bd9Sstevel@tonic-gate if (rv == HPC_SUCCESS) { 9937c478bd9Sstevel@tonic-gate pcihp_gen_sysevent(slotinfop->name, 9947c478bd9Sstevel@tonic-gate PCIHP_DR_AP_STATE_CHANGE, 9957c478bd9Sstevel@tonic-gate SE_NO_HINT, pcihp_p->dip, KM_SLEEP); 9967c478bd9Sstevel@tonic-gate pcihp_delete_occupant_props(pcihp_p->dip, dev); 9977c478bd9Sstevel@tonic-gate } 99870025d76Sjohnny mutex_exit(&slotinfop->slot_mutex); 9997c478bd9Sstevel@tonic-gate 10007c478bd9Sstevel@tonic-gate break; 10017c478bd9Sstevel@tonic-gate 10027c478bd9Sstevel@tonic-gate case DEVCTL_AP_GETSTATE: 10037c478bd9Sstevel@tonic-gate { 10047c478bd9Sstevel@tonic-gate int mutex_held; 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate /* 10077c478bd9Sstevel@tonic-gate * return the state of Attachment Point. 10087c478bd9Sstevel@tonic-gate * 10097c478bd9Sstevel@tonic-gate * If the occupant is in UNCONFIGURED state then 10107c478bd9Sstevel@tonic-gate * we should get the receptacle state from the 10117c478bd9Sstevel@tonic-gate * HPC driver because the receptacle state 10127c478bd9Sstevel@tonic-gate * maintained in the nexus may not be accurate. 10137c478bd9Sstevel@tonic-gate */ 10147c478bd9Sstevel@tonic-gate 10157c478bd9Sstevel@tonic-gate /* 10167c478bd9Sstevel@tonic-gate * check for valid request: 10177c478bd9Sstevel@tonic-gate * 1. It is a hotplug slot. 10187c478bd9Sstevel@tonic-gate */ 10197c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 10207c478bd9Sstevel@tonic-gate 10217c478bd9Sstevel@tonic-gate /* try to acquire the slot mutex */ 10227c478bd9Sstevel@tonic-gate mutex_held = mutex_tryenter(&slotinfop->slot_mutex); 10237c478bd9Sstevel@tonic-gate 10247c478bd9Sstevel@tonic-gate if (pci_dev >= PCI_MAX_DEVS || slotinfop->slot_hdl == NULL) { 10257c478bd9Sstevel@tonic-gate rv = ENXIO; 10267c478bd9Sstevel@tonic-gate if (mutex_held) { 10277c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 10287c478bd9Sstevel@tonic-gate } 10297c478bd9Sstevel@tonic-gate break; 10307c478bd9Sstevel@tonic-gate } 10317c478bd9Sstevel@tonic-gate 10327c478bd9Sstevel@tonic-gate if (slotinfop->ostate == AP_OSTATE_UNCONFIGURED) { 10337c478bd9Sstevel@tonic-gate if (hpc_nexus_control(slotinfop->slot_hdl, 10347c478bd9Sstevel@tonic-gate HPC_CTRL_GET_SLOT_STATE, (caddr_t)&rstate) != 0) { 10357c478bd9Sstevel@tonic-gate rv = EIO; 10367c478bd9Sstevel@tonic-gate if (mutex_held) 10377c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 10387c478bd9Sstevel@tonic-gate break; 10397c478bd9Sstevel@tonic-gate } 10407c478bd9Sstevel@tonic-gate slotinfop->rstate = (ap_rstate_t)rstate; 10417c478bd9Sstevel@tonic-gate } 10427c478bd9Sstevel@tonic-gate 10437c478bd9Sstevel@tonic-gate ap_state.ap_rstate = slotinfop->rstate; 10447c478bd9Sstevel@tonic-gate ap_state.ap_ostate = slotinfop->ostate; 10457c478bd9Sstevel@tonic-gate ap_state.ap_condition = slotinfop->condition; 10467c478bd9Sstevel@tonic-gate ap_state.ap_last_change = slotinfop->last_change; 10477c478bd9Sstevel@tonic-gate ap_state.ap_error_code = 0; /* XXX */ 10487c478bd9Sstevel@tonic-gate if (mutex_held) 10497c478bd9Sstevel@tonic-gate ap_state.ap_in_transition = 0; /* AP is not busy */ 10507c478bd9Sstevel@tonic-gate else 10517c478bd9Sstevel@tonic-gate ap_state.ap_in_transition = 1; /* AP is busy */ 10527c478bd9Sstevel@tonic-gate 10537c478bd9Sstevel@tonic-gate if (mutex_held) 10547c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 10557c478bd9Sstevel@tonic-gate 10567c478bd9Sstevel@tonic-gate /* copy the return-AP-state information to the user space */ 10577c478bd9Sstevel@tonic-gate if (ndi_dc_return_ap_state(&ap_state, dcp) != NDI_SUCCESS) 10587c478bd9Sstevel@tonic-gate rv = EFAULT; 10597c478bd9Sstevel@tonic-gate 10607c478bd9Sstevel@tonic-gate break; 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate } 10637c478bd9Sstevel@tonic-gate case DEVCTL_AP_CONTROL: 10647c478bd9Sstevel@tonic-gate /* 10657c478bd9Sstevel@tonic-gate * HPC control functions: 10667c478bd9Sstevel@tonic-gate * HPC_CTRL_ENABLE_SLOT/HPC_CTRL_DISABLE_SLOT 10677c478bd9Sstevel@tonic-gate * Changes the state of the slot and preserves 10687c478bd9Sstevel@tonic-gate * the state across the reboot. 10697c478bd9Sstevel@tonic-gate * HPC_CTRL_ENABLE_AUTOCFG/HPC_CTRL_DISABLE_AUTOCFG 10707c478bd9Sstevel@tonic-gate * Enables or disables the auto configuration 10717c478bd9Sstevel@tonic-gate * of hot plugged occupant if the hardware 10727c478bd9Sstevel@tonic-gate * supports notification of the hot plug 10737c478bd9Sstevel@tonic-gate * events. 10747c478bd9Sstevel@tonic-gate * HPC_CTRL_GET_LED_STATE/HPC_CTRL_SET_LED_STATE 10757c478bd9Sstevel@tonic-gate * Controls the state of an LED. 10767c478bd9Sstevel@tonic-gate * HPC_CTRL_GET_SLOT_INFO 10777c478bd9Sstevel@tonic-gate * Get slot information data structure 10787c478bd9Sstevel@tonic-gate * (hpc_slot_info_t). 10797c478bd9Sstevel@tonic-gate * HPC_CTRL_GET_BOARD_TYPE 10807c478bd9Sstevel@tonic-gate * Get board type information (hpc_board_type_t). 10817c478bd9Sstevel@tonic-gate * HPC_CTRL_GET_CARD_INFO 10827c478bd9Sstevel@tonic-gate * Get card information (hpc_card_info_t). 10837c478bd9Sstevel@tonic-gate * 10847c478bd9Sstevel@tonic-gate * These control functions are used by the cfgadm plug-in 10857c478bd9Sstevel@tonic-gate * to implement "-x" and "-v" options. 10867c478bd9Sstevel@tonic-gate */ 10877c478bd9Sstevel@tonic-gate 10887c478bd9Sstevel@tonic-gate /* copy user ioctl data first */ 108999e6869fSjmcp switch (ddi_model_convert_from(mode & FMODELS)) { 109099e6869fSjmcp case DDI_MODEL_ILP32: { 10917c478bd9Sstevel@tonic-gate struct hpc_control32_data hpc_ctrldata32; 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate if (copyin((void *)arg, (void *)&hpc_ctrldata32, 10947c478bd9Sstevel@tonic-gate sizeof (struct hpc_control32_data)) != 0) { 10957c478bd9Sstevel@tonic-gate rv = EFAULT; 10967c478bd9Sstevel@tonic-gate break; 10977c478bd9Sstevel@tonic-gate } 10987c478bd9Sstevel@tonic-gate hpc_ctrldata.cmd = hpc_ctrldata32.cmd; 10997c478bd9Sstevel@tonic-gate hpc_ctrldata.data = 11007c478bd9Sstevel@tonic-gate (void *)(intptr_t)hpc_ctrldata32.data; 110199e6869fSjmcp break; 11027c478bd9Sstevel@tonic-gate } 110399e6869fSjmcp case DDI_MODEL_NONE: 11047c478bd9Sstevel@tonic-gate if (copyin((void *)arg, (void *)&hpc_ctrldata, 11057c478bd9Sstevel@tonic-gate sizeof (struct hpc_control_data)) != 0) { 11067c478bd9Sstevel@tonic-gate rv = EFAULT; 110799e6869fSjmcp } 110899e6869fSjmcp break; 110999e6869fSjmcp default: 111099e6869fSjmcp rv = EFAULT; 11117c478bd9Sstevel@tonic-gate break; 11127c478bd9Sstevel@tonic-gate } 111399e6869fSjmcp if (rv == EFAULT) 111499e6869fSjmcp break; 11157c478bd9Sstevel@tonic-gate /* 11167c478bd9Sstevel@tonic-gate * check for valid request: 11177c478bd9Sstevel@tonic-gate * 1. It is a hotplug slot. 11187c478bd9Sstevel@tonic-gate */ 11197c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate mutex_enter(&slotinfop->slot_mutex); 11227c478bd9Sstevel@tonic-gate 11237c478bd9Sstevel@tonic-gate if (pci_dev >= PCI_MAX_DEVS || slotinfop->slot_hdl == NULL) { 11247c478bd9Sstevel@tonic-gate rv = ENXIO; 11257c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 11267c478bd9Sstevel@tonic-gate break; 11277c478bd9Sstevel@tonic-gate } 11287c478bd9Sstevel@tonic-gate 11297c478bd9Sstevel@tonic-gate switch (hpc_ctrldata.cmd) { 11307c478bd9Sstevel@tonic-gate 11317c478bd9Sstevel@tonic-gate case HPC_CTRL_GET_LED_STATE: 11327c478bd9Sstevel@tonic-gate /* copy the led info from the user space */ 11337c478bd9Sstevel@tonic-gate if (copyin(hpc_ctrldata.data, (void *)&led_info, 11347c478bd9Sstevel@tonic-gate sizeof (hpc_led_info_t)) != 0) { 11357c478bd9Sstevel@tonic-gate rv = EFAULT; 11367c478bd9Sstevel@tonic-gate break; 11377c478bd9Sstevel@tonic-gate } 11387c478bd9Sstevel@tonic-gate 11397c478bd9Sstevel@tonic-gate /* get the state of LED information */ 11407c478bd9Sstevel@tonic-gate if (hpc_nexus_control(slotinfop->slot_hdl, 114132d69156Sscarter HPC_CTRL_GET_LED_STATE, (caddr_t)&led_info) != 0) { 11427c478bd9Sstevel@tonic-gate 11437c478bd9Sstevel@tonic-gate if (rv != ENOTSUP) 11447c478bd9Sstevel@tonic-gate rv = EIO; 11457c478bd9Sstevel@tonic-gate 11467c478bd9Sstevel@tonic-gate break; 11477c478bd9Sstevel@tonic-gate } 11487c478bd9Sstevel@tonic-gate 11497c478bd9Sstevel@tonic-gate /* copy the led info to the user space */ 115032d69156Sscarter if (copyout((void *)&led_info, hpc_ctrldata.data, 11517c478bd9Sstevel@tonic-gate sizeof (hpc_led_info_t)) != 0) { 11527c478bd9Sstevel@tonic-gate rv = EFAULT; 11537c478bd9Sstevel@tonic-gate break; 11547c478bd9Sstevel@tonic-gate } 11557c478bd9Sstevel@tonic-gate 11567c478bd9Sstevel@tonic-gate break; 11577c478bd9Sstevel@tonic-gate 11587c478bd9Sstevel@tonic-gate case HPC_CTRL_SET_LED_STATE: 11597c478bd9Sstevel@tonic-gate /* copy the led info from the user space */ 11607c478bd9Sstevel@tonic-gate if (copyin(hpc_ctrldata.data, (void *)&led_info, 11617c478bd9Sstevel@tonic-gate sizeof (hpc_led_info_t)) != 0) { 11627c478bd9Sstevel@tonic-gate rv = EFAULT; 11637c478bd9Sstevel@tonic-gate break; 11647c478bd9Sstevel@tonic-gate } 11657c478bd9Sstevel@tonic-gate 11667c478bd9Sstevel@tonic-gate /* set the state of an LED */ 11677c478bd9Sstevel@tonic-gate rv = hpc_nexus_control(slotinfop->slot_hdl, 11687c478bd9Sstevel@tonic-gate HPC_CTRL_SET_LED_STATE, (caddr_t)&led_info); 11697c478bd9Sstevel@tonic-gate 11707c478bd9Sstevel@tonic-gate /* 11717c478bd9Sstevel@tonic-gate * If the Hotswap Controller does not support 11727c478bd9Sstevel@tonic-gate * LED management (as you would find typically 11737c478bd9Sstevel@tonic-gate * in the cPCI industry), then we handle the 11747c478bd9Sstevel@tonic-gate * blue LED on/off/blink operations, just in 11757c478bd9Sstevel@tonic-gate * case it helps slot identification. 11767c478bd9Sstevel@tonic-gate */ 11777c478bd9Sstevel@tonic-gate if ((rv == HPC_ERR_NOTSUPPORTED) && 11787c478bd9Sstevel@tonic-gate (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI)) { 11797c478bd9Sstevel@tonic-gate if (led_info.led != HPC_ATTN_LED) 11807c478bd9Sstevel@tonic-gate break; 11817c478bd9Sstevel@tonic-gate 11827c478bd9Sstevel@tonic-gate switch (led_info.state) { 11837c478bd9Sstevel@tonic-gate case HPC_LED_OFF: 11847c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, 11857c478bd9Sstevel@tonic-gate pci_dev, 11867c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_OFF); 11877c478bd9Sstevel@tonic-gate rv = 0; 11887c478bd9Sstevel@tonic-gate break; 11897c478bd9Sstevel@tonic-gate case HPC_LED_ON: 11907c478bd9Sstevel@tonic-gate /* 11917c478bd9Sstevel@tonic-gate * Please note that leaving 11927c478bd9Sstevel@tonic-gate * LED ON could be dangerous 11937c478bd9Sstevel@tonic-gate * as it means it is Ok to 11947c478bd9Sstevel@tonic-gate * remove the board, which 11957c478bd9Sstevel@tonic-gate * is not what we want to 11967c478bd9Sstevel@tonic-gate * convey. So it is upto the 11977c478bd9Sstevel@tonic-gate * user to take care of this 11987c478bd9Sstevel@tonic-gate * situation and usage. 11997c478bd9Sstevel@tonic-gate * 12007c478bd9Sstevel@tonic-gate * Normally, a Blink command 12017c478bd9Sstevel@tonic-gate * is more appropriate for 12027c478bd9Sstevel@tonic-gate * identifying a board. 12037c478bd9Sstevel@tonic-gate */ 12047c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, 12057c478bd9Sstevel@tonic-gate pci_dev, 12067c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_ON); 12077c478bd9Sstevel@tonic-gate rv = 0; 12087c478bd9Sstevel@tonic-gate break; 12097c478bd9Sstevel@tonic-gate case HPC_LED_BLINK: 12107c478bd9Sstevel@tonic-gate { 12117c478bd9Sstevel@tonic-gate int bl; 12127c478bd9Sstevel@tonic-gate 12137c478bd9Sstevel@tonic-gate for (bl = 0; bl < 2; bl++) { 12147c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, 12157c478bd9Sstevel@tonic-gate pci_dev, 12167c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_ON); 12177c478bd9Sstevel@tonic-gate delay(pcihp_cpci_led_blink); 12187c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, 12197c478bd9Sstevel@tonic-gate pci_dev, 12207c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_OFF); 12217c478bd9Sstevel@tonic-gate delay(pcihp_cpci_led_blink); 12227c478bd9Sstevel@tonic-gate } 12237c478bd9Sstevel@tonic-gate rv = 0; 12247c478bd9Sstevel@tonic-gate break; 12257c478bd9Sstevel@tonic-gate } 12267c478bd9Sstevel@tonic-gate default: 12277c478bd9Sstevel@tonic-gate break; 12287c478bd9Sstevel@tonic-gate } 12297c478bd9Sstevel@tonic-gate } 12307c478bd9Sstevel@tonic-gate 12317c478bd9Sstevel@tonic-gate if (rv == HPC_ERR_FAILED) 12327c478bd9Sstevel@tonic-gate rv = EIO; 12337c478bd9Sstevel@tonic-gate break; 12347c478bd9Sstevel@tonic-gate 12357c478bd9Sstevel@tonic-gate case HPC_CTRL_ENABLE_SLOT: 12367c478bd9Sstevel@tonic-gate 12377c478bd9Sstevel@tonic-gate /* 12387c478bd9Sstevel@tonic-gate * If slot already enabled, do not send a duplicate 12397c478bd9Sstevel@tonic-gate * control message to the HPC driver. 12407c478bd9Sstevel@tonic-gate */ 12417c478bd9Sstevel@tonic-gate if ((slotinfop->slot_flags & PCIHP_SLOT_DISABLED) == 0) 12427c478bd9Sstevel@tonic-gate break; 12437c478bd9Sstevel@tonic-gate 12447c478bd9Sstevel@tonic-gate /* tell the HPC driver also */ 12457c478bd9Sstevel@tonic-gate if (hpc_nexus_control(slotinfop->slot_hdl, 124632d69156Sscarter HPC_CTRL_ENABLE_SLOT, NULL) != HPC_SUCCESS) { 12477c478bd9Sstevel@tonic-gate rv = EIO; 12487c478bd9Sstevel@tonic-gate break; 12497c478bd9Sstevel@tonic-gate } 12507c478bd9Sstevel@tonic-gate 12517c478bd9Sstevel@tonic-gate /* 12527c478bd9Sstevel@tonic-gate * Enable the slot for hotplug operations. 12537c478bd9Sstevel@tonic-gate */ 12547c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= ~PCIHP_SLOT_DISABLED; 12557c478bd9Sstevel@tonic-gate 12567c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_UNKNOWN; 12577c478bd9Sstevel@tonic-gate 12587c478bd9Sstevel@tonic-gate /* XXX need to preserve this state across reboot? */ 12597c478bd9Sstevel@tonic-gate 12607c478bd9Sstevel@tonic-gate break; 12617c478bd9Sstevel@tonic-gate 12627c478bd9Sstevel@tonic-gate case HPC_CTRL_DISABLE_SLOT: 12637c478bd9Sstevel@tonic-gate 12647c478bd9Sstevel@tonic-gate /* Do not disable if occupant configured */ 12657c478bd9Sstevel@tonic-gate if (slotinfop->ostate == AP_OSTATE_CONFIGURED) { 12667c478bd9Sstevel@tonic-gate rv = EAGAIN; 12677c478bd9Sstevel@tonic-gate break; 12687c478bd9Sstevel@tonic-gate } 12697c478bd9Sstevel@tonic-gate 12707c478bd9Sstevel@tonic-gate /* tell the HPC driver also */ 12717c478bd9Sstevel@tonic-gate if (hpc_nexus_control(slotinfop->slot_hdl, 127232d69156Sscarter HPC_CTRL_DISABLE_SLOT, NULL) != HPC_SUCCESS) { 12737c478bd9Sstevel@tonic-gate rv = EIO; 12747c478bd9Sstevel@tonic-gate break; 12757c478bd9Sstevel@tonic-gate } 12767c478bd9Sstevel@tonic-gate 12777c478bd9Sstevel@tonic-gate /* 12787c478bd9Sstevel@tonic-gate * Disable the slot for hotplug operations. 12797c478bd9Sstevel@tonic-gate */ 12807c478bd9Sstevel@tonic-gate slotinfop->slot_flags |= PCIHP_SLOT_DISABLED; 12817c478bd9Sstevel@tonic-gate 12827c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_UNUSABLE; 12837c478bd9Sstevel@tonic-gate 12847c478bd9Sstevel@tonic-gate /* XXX need to preserve this state across reboot? */ 12857c478bd9Sstevel@tonic-gate 12867c478bd9Sstevel@tonic-gate break; 12877c478bd9Sstevel@tonic-gate 12887c478bd9Sstevel@tonic-gate case HPC_CTRL_ENABLE_AUTOCFG: 12897c478bd9Sstevel@tonic-gate /* 12907c478bd9Sstevel@tonic-gate * Enable auto configuration on this slot. 12917c478bd9Sstevel@tonic-gate */ 12927c478bd9Sstevel@tonic-gate slotinfop->slot_flags |= PCIHP_SLOT_AUTO_CFG_EN; 12937c478bd9Sstevel@tonic-gate 12947c478bd9Sstevel@tonic-gate /* tell the HPC driver also */ 12957c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 12967c478bd9Sstevel@tonic-gate HPC_CTRL_ENABLE_AUTOCFG, NULL); 12977c478bd9Sstevel@tonic-gate 12987c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) 12997c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 13007c478bd9Sstevel@tonic-gate HPC_EVENT_ENABLE_ENUM); 13017c478bd9Sstevel@tonic-gate break; 13027c478bd9Sstevel@tonic-gate 13037c478bd9Sstevel@tonic-gate case HPC_CTRL_DISABLE_AUTOCFG: 13047c478bd9Sstevel@tonic-gate /* 13057c478bd9Sstevel@tonic-gate * Disable auto configuration on this slot. 13067c478bd9Sstevel@tonic-gate */ 13077c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= ~PCIHP_SLOT_AUTO_CFG_EN; 13087c478bd9Sstevel@tonic-gate 13097c478bd9Sstevel@tonic-gate /* tell the HPC driver also */ 13107c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 13117c478bd9Sstevel@tonic-gate HPC_CTRL_DISABLE_AUTOCFG, NULL); 13127c478bd9Sstevel@tonic-gate 13137c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) 13147c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 13157c478bd9Sstevel@tonic-gate HPC_EVENT_DISABLE_ENUM); 13167c478bd9Sstevel@tonic-gate break; 13177c478bd9Sstevel@tonic-gate 13187c478bd9Sstevel@tonic-gate case HPC_CTRL_GET_BOARD_TYPE: 13197c478bd9Sstevel@tonic-gate { 13207c478bd9Sstevel@tonic-gate hpc_board_type_t board_type; 13217c478bd9Sstevel@tonic-gate 13227c478bd9Sstevel@tonic-gate /* 13237c478bd9Sstevel@tonic-gate * Get board type data structure, hpc_board_type_t. 13247c478bd9Sstevel@tonic-gate */ 13257c478bd9Sstevel@tonic-gate board_type = pcihp_get_board_type(slotinfop); 13267c478bd9Sstevel@tonic-gate if (board_type == -1) { 13277c478bd9Sstevel@tonic-gate rv = ENXIO; 13287c478bd9Sstevel@tonic-gate break; 13297c478bd9Sstevel@tonic-gate } 13307c478bd9Sstevel@tonic-gate 13317c478bd9Sstevel@tonic-gate /* copy the board type info to the user space */ 13327c478bd9Sstevel@tonic-gate if (copyout((void *)&board_type, hpc_ctrldata.data, 13337c478bd9Sstevel@tonic-gate sizeof (hpc_board_type_t)) != 0) { 13347c478bd9Sstevel@tonic-gate rv = ENXIO; 13357c478bd9Sstevel@tonic-gate break; 13367c478bd9Sstevel@tonic-gate } 13377c478bd9Sstevel@tonic-gate 13387c478bd9Sstevel@tonic-gate break; 13397c478bd9Sstevel@tonic-gate } 13407c478bd9Sstevel@tonic-gate 13417c478bd9Sstevel@tonic-gate case HPC_CTRL_GET_SLOT_INFO: 13427c478bd9Sstevel@tonic-gate { 13437c478bd9Sstevel@tonic-gate hpc_slot_info_t slot_info; 13447c478bd9Sstevel@tonic-gate 13457c478bd9Sstevel@tonic-gate /* 13467c478bd9Sstevel@tonic-gate * Get slot information structure, hpc_slot_info_t. 13477c478bd9Sstevel@tonic-gate */ 13487c478bd9Sstevel@tonic-gate slot_info.version = HPC_SLOT_INFO_VERSION; 13497c478bd9Sstevel@tonic-gate slot_info.slot_type = slotinfop->slot_type; 13507c478bd9Sstevel@tonic-gate slot_info.pci_slot_capabilities = 13517c478bd9Sstevel@tonic-gate slotinfop->slot_capabilities; 13527c478bd9Sstevel@tonic-gate slot_info.pci_dev_num = (uint16_t)pci_dev; 13537c478bd9Sstevel@tonic-gate (void) strcpy(slot_info.pci_slot_name, slotinfop->name); 13547c478bd9Sstevel@tonic-gate 13557c478bd9Sstevel@tonic-gate /* copy the slot info structure to the user space */ 13567c478bd9Sstevel@tonic-gate if (copyout((void *)&slot_info, hpc_ctrldata.data, 13577c478bd9Sstevel@tonic-gate sizeof (hpc_slot_info_t)) != 0) { 13587c478bd9Sstevel@tonic-gate rv = EFAULT; 13597c478bd9Sstevel@tonic-gate break; 13607c478bd9Sstevel@tonic-gate } 13617c478bd9Sstevel@tonic-gate 13627c478bd9Sstevel@tonic-gate break; 13637c478bd9Sstevel@tonic-gate } 13647c478bd9Sstevel@tonic-gate 13657c478bd9Sstevel@tonic-gate case HPC_CTRL_GET_CARD_INFO: 13667c478bd9Sstevel@tonic-gate { 13677c478bd9Sstevel@tonic-gate hpc_card_info_t card_info; 13687c478bd9Sstevel@tonic-gate ddi_acc_handle_t handle; 13697c478bd9Sstevel@tonic-gate dev_info_t *cdip; 13707c478bd9Sstevel@tonic-gate 13717c478bd9Sstevel@tonic-gate /* 13727c478bd9Sstevel@tonic-gate * Get card information structure, hpc_card_info_t. 13737c478bd9Sstevel@tonic-gate */ 13747c478bd9Sstevel@tonic-gate 13757c478bd9Sstevel@tonic-gate /* verify that the card is configured */ 13767c478bd9Sstevel@tonic-gate if ((slotinfop->ostate != AP_OSTATE_CONFIGURED) || 137732d69156Sscarter ((cdip = pcihp_devi_find(self, 137832d69156Sscarter pci_dev, 0)) == NULL)) { 137932d69156Sscarter /* 138032d69156Sscarter * either the card is not present or 138132d69156Sscarter * it is not configured. 138232d69156Sscarter */ 13837c478bd9Sstevel@tonic-gate rv = ENXIO; 13847c478bd9Sstevel@tonic-gate break; 13857c478bd9Sstevel@tonic-gate } 13867c478bd9Sstevel@tonic-gate 13877c478bd9Sstevel@tonic-gate /* 13887c478bd9Sstevel@tonic-gate * If declared failed, don't allow Config operations. 13897c478bd9Sstevel@tonic-gate * Otherwise, if good or failing, it is assumed Ok 13907c478bd9Sstevel@tonic-gate * to get config data. 13917c478bd9Sstevel@tonic-gate */ 13927c478bd9Sstevel@tonic-gate if (slotinfop->condition == AP_COND_FAILED) { 13937c478bd9Sstevel@tonic-gate rv = EIO; 13947c478bd9Sstevel@tonic-gate break; 13957c478bd9Sstevel@tonic-gate } 13967c478bd9Sstevel@tonic-gate 13977c478bd9Sstevel@tonic-gate /* get the information from the PCI config header */ 13987c478bd9Sstevel@tonic-gate /* for the function 0. */ 13997c478bd9Sstevel@tonic-gate if (pci_config_setup(cdip, &handle) != DDI_SUCCESS) { 14007c478bd9Sstevel@tonic-gate rv = EIO; 14017c478bd9Sstevel@tonic-gate break; 14027c478bd9Sstevel@tonic-gate } 14037c478bd9Sstevel@tonic-gate card_info.prog_class = pci_config_get8(handle, 14047c478bd9Sstevel@tonic-gate PCI_CONF_PROGCLASS); 14057c478bd9Sstevel@tonic-gate card_info.base_class = pci_config_get8(handle, 14067c478bd9Sstevel@tonic-gate PCI_CONF_BASCLASS); 14077c478bd9Sstevel@tonic-gate card_info.sub_class = pci_config_get8(handle, 14087c478bd9Sstevel@tonic-gate PCI_CONF_SUBCLASS); 14097c478bd9Sstevel@tonic-gate card_info.header_type = pci_config_get8(handle, 14107c478bd9Sstevel@tonic-gate PCI_CONF_HEADER); 14117c478bd9Sstevel@tonic-gate pci_config_teardown(&handle); 14127c478bd9Sstevel@tonic-gate 14137c478bd9Sstevel@tonic-gate /* copy the card info structure to the user space */ 14147c478bd9Sstevel@tonic-gate if (copyout((void *)&card_info, hpc_ctrldata.data, 14157c478bd9Sstevel@tonic-gate sizeof (hpc_card_info_t)) != 0) { 14167c478bd9Sstevel@tonic-gate rv = EFAULT; 14177c478bd9Sstevel@tonic-gate break; 14187c478bd9Sstevel@tonic-gate } 14197c478bd9Sstevel@tonic-gate 14207c478bd9Sstevel@tonic-gate break; 14217c478bd9Sstevel@tonic-gate } 14227c478bd9Sstevel@tonic-gate 14237c478bd9Sstevel@tonic-gate default: 14247c478bd9Sstevel@tonic-gate rv = EINVAL; 14257c478bd9Sstevel@tonic-gate break; 14267c478bd9Sstevel@tonic-gate } 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 14297c478bd9Sstevel@tonic-gate 14307c478bd9Sstevel@tonic-gate break; 14317c478bd9Sstevel@tonic-gate 14327c478bd9Sstevel@tonic-gate default: 14337c478bd9Sstevel@tonic-gate rv = ENOTTY; 14347c478bd9Sstevel@tonic-gate } 14357c478bd9Sstevel@tonic-gate 14367c478bd9Sstevel@tonic-gate if (cmd != DEVCTL_AP_CONTROL) 14377c478bd9Sstevel@tonic-gate ndi_dc_freehdl(dcp); 14387c478bd9Sstevel@tonic-gate 14397c478bd9Sstevel@tonic-gate (void) pcihp_get_soft_state(self, state_unlocking, &rval); 14407c478bd9Sstevel@tonic-gate 14417c478bd9Sstevel@tonic-gate return (rv); 14427c478bd9Sstevel@tonic-gate } 14437c478bd9Sstevel@tonic-gate 14447c478bd9Sstevel@tonic-gate /* 14457c478bd9Sstevel@tonic-gate * ************************************** 14467c478bd9Sstevel@tonic-gate * CONFIGURE the occupant in the slot. 14477c478bd9Sstevel@tonic-gate * ************************************** 14487c478bd9Sstevel@tonic-gate */ 14497c478bd9Sstevel@tonic-gate static int 14507c478bd9Sstevel@tonic-gate pcihp_configure_ap(pcihp_t *pcihp_p, int pci_dev) 14517c478bd9Sstevel@tonic-gate { 14527c478bd9Sstevel@tonic-gate dev_info_t *self = pcihp_p->dip; 14537c478bd9Sstevel@tonic-gate int rv = HPC_SUCCESS; 14547c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 14557c478bd9Sstevel@tonic-gate hpc_slot_state_t rstate; 14567c478bd9Sstevel@tonic-gate struct pcihp_config_ctrl ctrl; 14577c478bd9Sstevel@tonic-gate int circular_count; 14587c478bd9Sstevel@tonic-gate time_t time; 14597c478bd9Sstevel@tonic-gate 14607c478bd9Sstevel@tonic-gate /* 14617c478bd9Sstevel@tonic-gate * check for valid request: 14627c478bd9Sstevel@tonic-gate * 1. It is a hotplug slot. 14637c478bd9Sstevel@tonic-gate * 2. The receptacle is in the CONNECTED state. 14647c478bd9Sstevel@tonic-gate */ 14657c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 14667c478bd9Sstevel@tonic-gate 146770025d76Sjohnny 14687c478bd9Sstevel@tonic-gate 14697c478bd9Sstevel@tonic-gate if ((pci_dev >= PCI_MAX_DEVS) || (slotinfop->slot_hdl == NULL) || 14707c478bd9Sstevel@tonic-gate (slotinfop->slot_flags & PCIHP_SLOT_DISABLED)) { 147170025d76Sjohnny 14727c478bd9Sstevel@tonic-gate return (ENXIO); 14737c478bd9Sstevel@tonic-gate } 14747c478bd9Sstevel@tonic-gate 14757c478bd9Sstevel@tonic-gate /* 14767c478bd9Sstevel@tonic-gate * If the occupant is already in (partially?) configured 14777c478bd9Sstevel@tonic-gate * state then call the ndi_devi_online() on the device 14787c478bd9Sstevel@tonic-gate * subtree(s) for this attachment point. 14797c478bd9Sstevel@tonic-gate */ 14807c478bd9Sstevel@tonic-gate 14817c478bd9Sstevel@tonic-gate if (slotinfop->ostate == AP_OSTATE_CONFIGURED) { 14827c478bd9Sstevel@tonic-gate ctrl.flags = PCIHP_CFG_CONTINUE; 14837c478bd9Sstevel@tonic-gate ctrl.rv = NDI_SUCCESS; 14847c478bd9Sstevel@tonic-gate ctrl.dip = NULL; 14857c478bd9Sstevel@tonic-gate ctrl.pci_dev = pci_dev; 14867c478bd9Sstevel@tonic-gate ctrl.op = PCIHP_ONLINE; 14877c478bd9Sstevel@tonic-gate 14887c478bd9Sstevel@tonic-gate ndi_devi_enter(self, &circular_count); 14897c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_get_child(self), pcihp_configure, 14907c478bd9Sstevel@tonic-gate (void *)&ctrl); 14917c478bd9Sstevel@tonic-gate ndi_devi_exit(self, circular_count); 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate if (ctrl.rv != NDI_SUCCESS) { 14947c478bd9Sstevel@tonic-gate /* 14957c478bd9Sstevel@tonic-gate * one or more of the devices are not 14967c478bd9Sstevel@tonic-gate * onlined. How is this to be reported? 14977c478bd9Sstevel@tonic-gate */ 14987c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 14997c478bd9Sstevel@tonic-gate "pcihp (%s%d): failed to attach one or" 15007c478bd9Sstevel@tonic-gate " more drivers for the card in the slot %s", 15017c478bd9Sstevel@tonic-gate ddi_driver_name(self), ddi_get_instance(self), 15027c478bd9Sstevel@tonic-gate slotinfop->name); 15037c478bd9Sstevel@tonic-gate /* rv = EFAULT; */ 15047c478bd9Sstevel@tonic-gate } 15057c478bd9Sstevel@tonic-gate /* tell HPC driver that the occupant is configured */ 15067c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 15077c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIGURED, NULL); 15087c478bd9Sstevel@tonic-gate 15097c478bd9Sstevel@tonic-gate if (drv_getparm(TIME, (void *)&time) != DDI_SUCCESS) 15107c478bd9Sstevel@tonic-gate slotinfop->last_change = (time_t)-1; 15117c478bd9Sstevel@tonic-gate else 15127c478bd9Sstevel@tonic-gate slotinfop->last_change = (time32_t)time; 15137c478bd9Sstevel@tonic-gate 151470025d76Sjohnny 15157c478bd9Sstevel@tonic-gate return (rv); 15167c478bd9Sstevel@tonic-gate } 15177c478bd9Sstevel@tonic-gate 15187c478bd9Sstevel@tonic-gate /* 15197c478bd9Sstevel@tonic-gate * Occupant is in the UNCONFIGURED state. 15207c478bd9Sstevel@tonic-gate */ 15217c478bd9Sstevel@tonic-gate 15227c478bd9Sstevel@tonic-gate /* Check if the receptacle is in the CONNECTED state. */ 15237c478bd9Sstevel@tonic-gate if (hpc_nexus_control(slotinfop->slot_hdl, 15247c478bd9Sstevel@tonic-gate HPC_CTRL_GET_SLOT_STATE, (caddr_t)&rstate) != 0) { 152570025d76Sjohnny 15267c478bd9Sstevel@tonic-gate return (ENXIO); 15277c478bd9Sstevel@tonic-gate } 15287c478bd9Sstevel@tonic-gate 15297c478bd9Sstevel@tonic-gate if (rstate == HPC_SLOT_EMPTY) { 15307c478bd9Sstevel@tonic-gate /* error. slot is empty */ 153170025d76Sjohnny 15327c478bd9Sstevel@tonic-gate return (ENXIO); 15337c478bd9Sstevel@tonic-gate } 15347c478bd9Sstevel@tonic-gate 15357c478bd9Sstevel@tonic-gate if (rstate != HPC_SLOT_CONNECTED) { 15367c478bd9Sstevel@tonic-gate /* error. either the slot is empty or connect failed */ 153770025d76Sjohnny 15387c478bd9Sstevel@tonic-gate return (ENXIO); 15397c478bd9Sstevel@tonic-gate } 15407c478bd9Sstevel@tonic-gate 15417c478bd9Sstevel@tonic-gate slotinfop->rstate = AP_RSTATE_CONNECTED; /* record rstate */ 15427c478bd9Sstevel@tonic-gate 15437c478bd9Sstevel@tonic-gate /* Turn INS and LED off, and start configuration. */ 15447c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 154532d69156Sscarter pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_SLOT_CONFIGURE); 15467c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 15477c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 15487c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_OFF); 15497c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= ~PCIHP_SLOT_ENUM_INS_PENDING; 15507c478bd9Sstevel@tonic-gate } 15517c478bd9Sstevel@tonic-gate 15527c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 15537c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIG_START, NULL); 15547c478bd9Sstevel@tonic-gate 15557c478bd9Sstevel@tonic-gate /* 15567c478bd9Sstevel@tonic-gate * Call the configurator to configure the card. 15577c478bd9Sstevel@tonic-gate */ 1558*26947304SEvan Yan if (pcicfg_configure(self, pci_dev, PCICFG_ALL_FUNC, 0) 1559*26947304SEvan Yan != PCICFG_SUCCESS) { 15607c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 15617c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 15627c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 15637c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_ON); 15647c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 15657c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_UNCONFIGURE); 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate /* tell HPC driver occupant configure Error */ 15687c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 15697c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIG_FAILURE, NULL); 157070025d76Sjohnny 15717c478bd9Sstevel@tonic-gate return (EIO); 15727c478bd9Sstevel@tonic-gate } 15737c478bd9Sstevel@tonic-gate 15747c478bd9Sstevel@tonic-gate /* record the occupant state as CONFIGURED */ 15757c478bd9Sstevel@tonic-gate slotinfop->ostate = AP_OSTATE_CONFIGURED; 15767c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_OK; 15777c478bd9Sstevel@tonic-gate 15787c478bd9Sstevel@tonic-gate /* now, online all the devices in the AP */ 15797c478bd9Sstevel@tonic-gate ctrl.flags = PCIHP_CFG_CONTINUE; 15807c478bd9Sstevel@tonic-gate ctrl.rv = NDI_SUCCESS; 15817c478bd9Sstevel@tonic-gate ctrl.dip = NULL; 15827c478bd9Sstevel@tonic-gate ctrl.pci_dev = pci_dev; 15837c478bd9Sstevel@tonic-gate ctrl.op = PCIHP_ONLINE; 15847c478bd9Sstevel@tonic-gate 15857c478bd9Sstevel@tonic-gate ndi_devi_enter(self, &circular_count); 158632d69156Sscarter ddi_walk_devs(ddi_get_child(self), pcihp_configure, (void *)&ctrl); 15877c478bd9Sstevel@tonic-gate ndi_devi_exit(self, circular_count); 15887c478bd9Sstevel@tonic-gate 15897c478bd9Sstevel@tonic-gate if (ctrl.rv != NDI_SUCCESS) { 15907c478bd9Sstevel@tonic-gate /* 15917c478bd9Sstevel@tonic-gate * one or more of the devices are not 15927c478bd9Sstevel@tonic-gate * ONLINE'd. How is this to be 15937c478bd9Sstevel@tonic-gate * reported? 15947c478bd9Sstevel@tonic-gate */ 15957c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 15967c478bd9Sstevel@tonic-gate "pcihp (%s%d): failed to attach one or" 159732d69156Sscarter " more drivers for the card in the slot %s", 15987c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 15997c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 16007c478bd9Sstevel@tonic-gate slotinfop->name); 16017c478bd9Sstevel@tonic-gate /* rv = EFAULT; */ 16027c478bd9Sstevel@tonic-gate } 16037c478bd9Sstevel@tonic-gate /* store HS_CSR location. No events, jut a read operation. */ 16047c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) 16057c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, -1); 16067c478bd9Sstevel@tonic-gate 16077c478bd9Sstevel@tonic-gate /* tell HPC driver that the occupant is configured */ 16087c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 16097c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIGURED, NULL); 16107c478bd9Sstevel@tonic-gate 161170025d76Sjohnny 16127c478bd9Sstevel@tonic-gate return (rv); 16137c478bd9Sstevel@tonic-gate } 16147c478bd9Sstevel@tonic-gate 16157c478bd9Sstevel@tonic-gate /* 16167c478bd9Sstevel@tonic-gate * ************************************** 16177c478bd9Sstevel@tonic-gate * UNCONFIGURE the occupant in the slot. 16187c478bd9Sstevel@tonic-gate * ************************************** 16197c478bd9Sstevel@tonic-gate */ 16207c478bd9Sstevel@tonic-gate static int 16217c478bd9Sstevel@tonic-gate pcihp_unconfigure_ap(pcihp_t *pcihp_p, int pci_dev) 16227c478bd9Sstevel@tonic-gate { 16237c478bd9Sstevel@tonic-gate dev_info_t *self = pcihp_p->dip; 16247c478bd9Sstevel@tonic-gate int rv = HPC_SUCCESS; 16257c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 16267c478bd9Sstevel@tonic-gate struct pcihp_config_ctrl ctrl; 16277c478bd9Sstevel@tonic-gate int circular_count; 16287c478bd9Sstevel@tonic-gate time_t time; 16297c478bd9Sstevel@tonic-gate 16307c478bd9Sstevel@tonic-gate /* 16317c478bd9Sstevel@tonic-gate * check for valid request: 16327c478bd9Sstevel@tonic-gate * 1. It is a hotplug slot. 16337c478bd9Sstevel@tonic-gate * 2. The occupant is in the CONFIGURED state. 16347c478bd9Sstevel@tonic-gate */ 16357c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 16367c478bd9Sstevel@tonic-gate 163770025d76Sjohnny 16387c478bd9Sstevel@tonic-gate 16397c478bd9Sstevel@tonic-gate if ((pci_dev >= PCI_MAX_DEVS) || (slotinfop->slot_hdl == NULL) || 16407c478bd9Sstevel@tonic-gate (slotinfop->slot_flags & PCIHP_SLOT_DISABLED)) { 164170025d76Sjohnny 16427c478bd9Sstevel@tonic-gate return (ENXIO); 16437c478bd9Sstevel@tonic-gate } 16447c478bd9Sstevel@tonic-gate /* 16457c478bd9Sstevel@tonic-gate * The following may not need to be there, as we should 16467c478bd9Sstevel@tonic-gate * support unconfiguring of boards and free resources 16477c478bd9Sstevel@tonic-gate * even when the board is not hotswappable. But this is 16487c478bd9Sstevel@tonic-gate * the only way, we may be able to tell the system 16497c478bd9Sstevel@tonic-gate * administrator that it is not a hotswap board since 16507c478bd9Sstevel@tonic-gate * disconnect operation is never called. 16517c478bd9Sstevel@tonic-gate * This way we help the system administrator from not 16527c478bd9Sstevel@tonic-gate * accidentally removing a non hotswap board and 16537c478bd9Sstevel@tonic-gate * possibly destroying it. May be this behavior can 16547c478bd9Sstevel@tonic-gate * be a default, and can be enabled or disabled via 16557c478bd9Sstevel@tonic-gate * a global flag. 16567c478bd9Sstevel@tonic-gate */ 16577c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 165832d69156Sscarter if (slotinfop->slot_flags & PCIHP_SLOT_DEV_NON_HOTPLUG) { 16597c478bd9Sstevel@tonic-gate /* Operation unsupported if no HS board/slot */ 16607c478bd9Sstevel@tonic-gate return (ENOTSUP); 16617c478bd9Sstevel@tonic-gate } 16627c478bd9Sstevel@tonic-gate } 16637c478bd9Sstevel@tonic-gate 16647c478bd9Sstevel@tonic-gate /* 16657c478bd9Sstevel@tonic-gate * If the occupant is in the CONFIGURED state then 16667c478bd9Sstevel@tonic-gate * call the configurator to unconfigure the slot. 16677c478bd9Sstevel@tonic-gate */ 16687c478bd9Sstevel@tonic-gate if (slotinfop->ostate == AP_OSTATE_CONFIGURED) { 16697c478bd9Sstevel@tonic-gate 16707c478bd9Sstevel@tonic-gate /* 16717c478bd9Sstevel@tonic-gate * since potential state change is imminent mask 16727c478bd9Sstevel@tonic-gate * enum events to prevent the slot from being re-configured 16737c478bd9Sstevel@tonic-gate */ 16747c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_DISABLE_ENUM); 16757c478bd9Sstevel@tonic-gate 16767c478bd9Sstevel@tonic-gate /* 16777c478bd9Sstevel@tonic-gate * Detach all the drivers for the devices in the 16787c478bd9Sstevel@tonic-gate * slot. Call pcihp_configure() to do this. 16797c478bd9Sstevel@tonic-gate */ 16807c478bd9Sstevel@tonic-gate ctrl.flags = 0; 16817c478bd9Sstevel@tonic-gate ctrl.rv = NDI_SUCCESS; 16827c478bd9Sstevel@tonic-gate ctrl.dip = NULL; 16837c478bd9Sstevel@tonic-gate ctrl.pci_dev = pci_dev; 16847c478bd9Sstevel@tonic-gate ctrl.op = PCIHP_OFFLINE; 16857c478bd9Sstevel@tonic-gate 16867c478bd9Sstevel@tonic-gate (void) devfs_clean(self, NULL, DV_CLEAN_FORCE); 16877c478bd9Sstevel@tonic-gate ndi_devi_enter(self, &circular_count); 16887c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_get_child(self), pcihp_configure, 16897c478bd9Sstevel@tonic-gate (void *)&ctrl); 16907c478bd9Sstevel@tonic-gate ndi_devi_exit(self, circular_count); 16917c478bd9Sstevel@tonic-gate 16927c478bd9Sstevel@tonic-gate if (ctrl.rv != NDI_SUCCESS) { 16937c478bd9Sstevel@tonic-gate /* 16947c478bd9Sstevel@tonic-gate * Failed to detach one or more drivers 16957c478bd9Sstevel@tonic-gate * Restore the state of drivers which 16967c478bd9Sstevel@tonic-gate * are offlined during this operation. 16977c478bd9Sstevel@tonic-gate */ 16987c478bd9Sstevel@tonic-gate ctrl.flags = 0; 16997c478bd9Sstevel@tonic-gate ctrl.rv = NDI_SUCCESS; 17007c478bd9Sstevel@tonic-gate ctrl.dip = NULL; 17017c478bd9Sstevel@tonic-gate ctrl.pci_dev = pci_dev; 17027c478bd9Sstevel@tonic-gate ctrl.op = PCIHP_ONLINE; 17037c478bd9Sstevel@tonic-gate 17047c478bd9Sstevel@tonic-gate ndi_devi_enter(self, &circular_count); 17057c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_get_child(self), 17067c478bd9Sstevel@tonic-gate pcihp_configure, (void *)&ctrl); 17077c478bd9Sstevel@tonic-gate ndi_devi_exit(self, circular_count); 17087c478bd9Sstevel@tonic-gate 17097c478bd9Sstevel@tonic-gate /* tell HPC driver that the occupant is Busy */ 17107c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 17117c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_UNCONFIG_FAILURE, NULL); 17127c478bd9Sstevel@tonic-gate 17137c478bd9Sstevel@tonic-gate rv = EBUSY; 17147c478bd9Sstevel@tonic-gate } else { 17157c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 17167c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_UNCONFIG_START, NULL); 17177c478bd9Sstevel@tonic-gate 1718*26947304SEvan Yan if (pcicfg_unconfigure(self, pci_dev, 1719*26947304SEvan Yan PCICFG_ALL_FUNC, 0) == PCICFG_SUCCESS) { 17207c478bd9Sstevel@tonic-gate /* 17217c478bd9Sstevel@tonic-gate * Now that resources are freed, 17227c478bd9Sstevel@tonic-gate * clear EXT and Turn LED ON. 17237c478bd9Sstevel@tonic-gate */ 17247c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 17257c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 17267c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_UNCONFIGURE); 17277c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 172832d69156Sscarter pcihp_hs_csr_op(pcihp_p, 172932d69156Sscarter pci_dev, 17307c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_ON); 17317c478bd9Sstevel@tonic-gate slotinfop->hs_csr_location = 0; 17327c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= 17337c478bd9Sstevel@tonic-gate ~(PCIHP_SLOT_DEV_NON_HOTPLUG| 17347c478bd9Sstevel@tonic-gate PCIHP_SLOT_ENUM_EXT_PENDING); 17357c478bd9Sstevel@tonic-gate } 173632d69156Sscarter slotinfop->ostate = AP_OSTATE_UNCONFIGURED; 17377c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_UNKNOWN; 17387c478bd9Sstevel@tonic-gate /* 17397c478bd9Sstevel@tonic-gate * send the notification of state change 17407c478bd9Sstevel@tonic-gate * to the HPC driver. 17417c478bd9Sstevel@tonic-gate */ 174232d69156Sscarter (void) hpc_nexus_control(slotinfop->slot_hdl, 17437c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_UNCONFIGURED, 17447c478bd9Sstevel@tonic-gate NULL); 17457c478bd9Sstevel@tonic-gate } else { 17467c478bd9Sstevel@tonic-gate /* tell HPC driver occupant unconfigure Error */ 17477c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 17487c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_UNCONFIG_FAILURE, NULL); 17497c478bd9Sstevel@tonic-gate 17507c478bd9Sstevel@tonic-gate rv = EIO; 17517c478bd9Sstevel@tonic-gate } 17527c478bd9Sstevel@tonic-gate } 17537c478bd9Sstevel@tonic-gate } 17547c478bd9Sstevel@tonic-gate 17557c478bd9Sstevel@tonic-gate if (drv_getparm(TIME, (void *)&time) != DDI_SUCCESS) 17567c478bd9Sstevel@tonic-gate slotinfop->last_change = (time_t)-1; 17577c478bd9Sstevel@tonic-gate else 17587c478bd9Sstevel@tonic-gate slotinfop->last_change = (time32_t)time; 17597c478bd9Sstevel@tonic-gate 176070025d76Sjohnny 17617c478bd9Sstevel@tonic-gate 17627c478bd9Sstevel@tonic-gate /* unmask enum events again */ 17637c478bd9Sstevel@tonic-gate if ((slotinfop->slot_flags & PCIHP_SLOT_AUTO_CFG_EN) == 0) { 17647c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_ENABLE_ENUM); 17657c478bd9Sstevel@tonic-gate } 17667c478bd9Sstevel@tonic-gate 17677c478bd9Sstevel@tonic-gate return (rv); 17687c478bd9Sstevel@tonic-gate } 17697c478bd9Sstevel@tonic-gate 17707c478bd9Sstevel@tonic-gate /* 17717c478bd9Sstevel@tonic-gate * Accessor function to return pointer to the pci hotplug 17727c478bd9Sstevel@tonic-gate * cb_ops structure. 17737c478bd9Sstevel@tonic-gate */ 17747c478bd9Sstevel@tonic-gate struct cb_ops * 17757c478bd9Sstevel@tonic-gate pcihp_get_cb_ops() 17767c478bd9Sstevel@tonic-gate { 17777c478bd9Sstevel@tonic-gate return (&pcihp_cb_ops); 17787c478bd9Sstevel@tonic-gate } 17797c478bd9Sstevel@tonic-gate 17807c478bd9Sstevel@tonic-gate /* 17817c478bd9Sstevel@tonic-gate * Setup function to initialize hot plug feature. Returns DDI_SUCCESS 17827c478bd9Sstevel@tonic-gate * for successful initialization, otherwise it returns DDI_FAILURE. 17837c478bd9Sstevel@tonic-gate * 17847c478bd9Sstevel@tonic-gate * It is assumed that this this function is called from the attach() 17857c478bd9Sstevel@tonic-gate * entry point of the PCI nexus driver. 17867c478bd9Sstevel@tonic-gate */ 17877c478bd9Sstevel@tonic-gate 17887c478bd9Sstevel@tonic-gate int 17897c478bd9Sstevel@tonic-gate pcihp_init(dev_info_t *dip) 17907c478bd9Sstevel@tonic-gate { 17917c478bd9Sstevel@tonic-gate pcihp_t *pcihp_p; 17927c478bd9Sstevel@tonic-gate int i; 17937c478bd9Sstevel@tonic-gate caddr_t enum_data; 17947c478bd9Sstevel@tonic-gate int enum_size; 17957c478bd9Sstevel@tonic-gate int rv; 17967c478bd9Sstevel@tonic-gate 17977c478bd9Sstevel@tonic-gate mutex_enter(&pcihp_open_mutex); 17987c478bd9Sstevel@tonic-gate 17997c478bd9Sstevel@tonic-gate /* 18007c478bd9Sstevel@tonic-gate * Make sure that it is not already initialized. 18017c478bd9Sstevel@tonic-gate */ 18027c478bd9Sstevel@tonic-gate if (pcihp_get_soft_state(dip, PCIHP_DR_NOOP, &rv) != NULL) { 18037c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: pcihp instance already initialized!", 18047c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 18057c478bd9Sstevel@tonic-gate goto cleanup; 18067c478bd9Sstevel@tonic-gate } 18077c478bd9Sstevel@tonic-gate 18087c478bd9Sstevel@tonic-gate /* 18097c478bd9Sstevel@tonic-gate * Initialize soft state structure for the bus instance. 18107c478bd9Sstevel@tonic-gate */ 18117c478bd9Sstevel@tonic-gate if ((pcihp_p = pcihp_create_soft_state(dip)) == NULL) { 18127c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: can't allocate pcihp structure", 18137c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 18147c478bd9Sstevel@tonic-gate goto cleanup; 18157c478bd9Sstevel@tonic-gate } 18167c478bd9Sstevel@tonic-gate 18177c478bd9Sstevel@tonic-gate pcihp_p->soft_state = PCIHP_SOFT_STATE_CLOSED; 18187c478bd9Sstevel@tonic-gate /* XXX if bus is running at 66Mhz then set PCI_BUS_66MHZ bit */ 18197c478bd9Sstevel@tonic-gate pcihp_p->bus_flags = 0; /* XXX FIX IT */ 18207c478bd9Sstevel@tonic-gate 18217c478bd9Sstevel@tonic-gate /* 18227c478bd9Sstevel@tonic-gate * If a platform wishes to implement Radial ENUM# routing 18237c478bd9Sstevel@tonic-gate * a property "enum-impl" must be presented to us with a 18247c478bd9Sstevel@tonic-gate * string value "radial". 18257c478bd9Sstevel@tonic-gate * This helps us not go for polling operation (default) 18267c478bd9Sstevel@tonic-gate * during a ENUM# event. 18277c478bd9Sstevel@tonic-gate */ 18287c478bd9Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, dip, 0, "enum-impl", 18297c478bd9Sstevel@tonic-gate (caddr_t)&enum_data, &enum_size) == DDI_PROP_SUCCESS) { 18307c478bd9Sstevel@tonic-gate if (strcmp(enum_data, "radial") == 0) { 18317c478bd9Sstevel@tonic-gate pcihp_p->bus_flags |= PCIHP_BUS_ENUM_RADIAL; 18327c478bd9Sstevel@tonic-gate } 18337c478bd9Sstevel@tonic-gate kmem_free(enum_data, enum_size); 18347c478bd9Sstevel@tonic-gate } 18357c478bd9Sstevel@tonic-gate 18367c478bd9Sstevel@tonic-gate for (i = 0; i < PCI_MAX_DEVS; i++) { 18377c478bd9Sstevel@tonic-gate /* initialize slot mutex */ 18387c478bd9Sstevel@tonic-gate mutex_init(&pcihp_p->slotinfo[i].slot_mutex, NULL, 18397c478bd9Sstevel@tonic-gate MUTEX_DRIVER, NULL); 18407c478bd9Sstevel@tonic-gate } 18417c478bd9Sstevel@tonic-gate 18427c478bd9Sstevel@tonic-gate /* 18437c478bd9Sstevel@tonic-gate * register the bus instance with the HPS framework. 18447c478bd9Sstevel@tonic-gate */ 18457c478bd9Sstevel@tonic-gate if (hpc_nexus_register_bus(dip, pcihp_new_slot_state, 0) != 0) { 18467c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: failed to register the bus with HPS", 18477c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 18487c478bd9Sstevel@tonic-gate goto cleanup1; 18497c478bd9Sstevel@tonic-gate } 18507c478bd9Sstevel@tonic-gate 18517c478bd9Sstevel@tonic-gate /* 18527c478bd9Sstevel@tonic-gate * Create the "devctl" minor for hot plug support. The minor 18537c478bd9Sstevel@tonic-gate * number for "devctl" node is in the same format as the AP 18547c478bd9Sstevel@tonic-gate * minor nodes. 18557c478bd9Sstevel@tonic-gate */ 18567c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, "devctl", S_IFCHR, 18577c478bd9Sstevel@tonic-gate PCIHP_AP_MINOR_NUM(ddi_get_instance(dip), PCIHP_DEVCTL_MINOR), 18587c478bd9Sstevel@tonic-gate DDI_NT_NEXUS, 0) != DDI_SUCCESS) 18597c478bd9Sstevel@tonic-gate goto cleanup2; 18607c478bd9Sstevel@tonic-gate 18617c478bd9Sstevel@tonic-gate /* 18627c478bd9Sstevel@tonic-gate * Setup resource maps for this bus node. (Note: This can 18637c478bd9Sstevel@tonic-gate * be done from the attach(9E) of the nexus itself.) 18647c478bd9Sstevel@tonic-gate */ 18657c478bd9Sstevel@tonic-gate (void) pci_resource_setup(dip); 18667c478bd9Sstevel@tonic-gate 18677c478bd9Sstevel@tonic-gate pcihp_p->bus_state = PCIHP_BUS_CONFIGURED; 18687c478bd9Sstevel@tonic-gate 18697c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 18707c478bd9Sstevel@tonic-gate 18717c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 18727c478bd9Sstevel@tonic-gate 18737c478bd9Sstevel@tonic-gate cleanup2: 18747c478bd9Sstevel@tonic-gate (void) hpc_nexus_unregister_bus(dip); 18757c478bd9Sstevel@tonic-gate cleanup1: 18767c478bd9Sstevel@tonic-gate for (i = 0; i < PCI_MAX_DEVS; i++) 18777c478bd9Sstevel@tonic-gate mutex_destroy(&pcihp_p->slotinfo[i].slot_mutex); 18787c478bd9Sstevel@tonic-gate pcihp_destroy_soft_state(dip); 18797c478bd9Sstevel@tonic-gate cleanup: 18807c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 18817c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 18827c478bd9Sstevel@tonic-gate } 18837c478bd9Sstevel@tonic-gate 18847c478bd9Sstevel@tonic-gate /* 18857c478bd9Sstevel@tonic-gate * pcihp_uninit() 18867c478bd9Sstevel@tonic-gate * 18877c478bd9Sstevel@tonic-gate * The bus instance is going away, cleanup any data associated with 18887c478bd9Sstevel@tonic-gate * the management of hot plug slots. It is assumed that this function 18897c478bd9Sstevel@tonic-gate * is called from detach() routine of the PCI nexus driver. Also, 18907c478bd9Sstevel@tonic-gate * it is assumed that no devices on the bus are in the configured state. 18917c478bd9Sstevel@tonic-gate */ 18927c478bd9Sstevel@tonic-gate int 18937c478bd9Sstevel@tonic-gate pcihp_uninit(dev_info_t *dip) 18947c478bd9Sstevel@tonic-gate { 18957c478bd9Sstevel@tonic-gate pcihp_t *pcihp_p; 18967c478bd9Sstevel@tonic-gate int i, j; 18977c478bd9Sstevel@tonic-gate int rv; 18987c478bd9Sstevel@tonic-gate 18997c478bd9Sstevel@tonic-gate mutex_enter(&pcihp_open_mutex); 19007c478bd9Sstevel@tonic-gate /* get a pointer to the soft state structure */ 19017c478bd9Sstevel@tonic-gate pcihp_p = pcihp_get_soft_state(dip, PCIHP_DR_BUS_UNCONFIGURE, &rv); 19027c478bd9Sstevel@tonic-gate ASSERT(pcihp_p != NULL); 19037c478bd9Sstevel@tonic-gate 19047c478bd9Sstevel@tonic-gate /* slot mutexes should prevent any configure/unconfigure access */ 19057c478bd9Sstevel@tonic-gate for (i = 0; i < PCI_MAX_DEVS; i++) { 19067c478bd9Sstevel@tonic-gate if (!mutex_tryenter(&pcihp_p->slotinfo[i].slot_mutex)) { 19077c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) { 19087c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_p->slotinfo[j].slot_mutex); 19097c478bd9Sstevel@tonic-gate } 19107c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 19117c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 19127c478bd9Sstevel@tonic-gate } 19137c478bd9Sstevel@tonic-gate } 19147c478bd9Sstevel@tonic-gate 19157c478bd9Sstevel@tonic-gate if ((pcihp_p->soft_state != PCIHP_SOFT_STATE_CLOSED) || 19167c478bd9Sstevel@tonic-gate (rv == PCIHP_FAILURE)) { 19177c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: pcihp instance is busy", 19187c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 19197c478bd9Sstevel@tonic-gate for (i = 0; i < PCI_MAX_DEVS; i++) { 19207c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_p->slotinfo[i].slot_mutex); 19217c478bd9Sstevel@tonic-gate } 19227c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 19237c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 19247c478bd9Sstevel@tonic-gate } 19257c478bd9Sstevel@tonic-gate 19267c478bd9Sstevel@tonic-gate /* 19277c478bd9Sstevel@tonic-gate * Unregister the bus with the HPS. 19287c478bd9Sstevel@tonic-gate * 19297c478bd9Sstevel@tonic-gate * (Note: It is assumed that the HPS framework uninstalls 19307c478bd9Sstevel@tonic-gate * event handlers for all the hot plug slots on this bus.) 19317c478bd9Sstevel@tonic-gate */ 19327c478bd9Sstevel@tonic-gate (void) hpc_nexus_unregister_bus(dip); 19337c478bd9Sstevel@tonic-gate 19347c478bd9Sstevel@tonic-gate /* Free up any kmem_alloc'd memory for slot info table. */ 19357c478bd9Sstevel@tonic-gate for (i = 0; i < PCI_MAX_DEVS; i++) { 19367c478bd9Sstevel@tonic-gate /* free up slot name strings */ 19377c478bd9Sstevel@tonic-gate if (pcihp_p->slotinfo[i].name != NULL) 19387c478bd9Sstevel@tonic-gate kmem_free(pcihp_p->slotinfo[i].name, 19397c478bd9Sstevel@tonic-gate strlen(pcihp_p->slotinfo[i].name) + 1); 19407c478bd9Sstevel@tonic-gate } 19417c478bd9Sstevel@tonic-gate 19427c478bd9Sstevel@tonic-gate /* destroy slot mutexes */ 19437c478bd9Sstevel@tonic-gate for (i = 0; i < PCI_MAX_DEVS; i++) 19447c478bd9Sstevel@tonic-gate mutex_destroy(&pcihp_p->slotinfo[i].slot_mutex); 19457c478bd9Sstevel@tonic-gate 19467c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 19477c478bd9Sstevel@tonic-gate 19487c478bd9Sstevel@tonic-gate /* free up the soft state structure */ 19497c478bd9Sstevel@tonic-gate pcihp_destroy_soft_state(dip); 19507c478bd9Sstevel@tonic-gate 19517c478bd9Sstevel@tonic-gate /* 19527c478bd9Sstevel@tonic-gate * Destroy resource maps for this bus node. (Note: This can 19537c478bd9Sstevel@tonic-gate * be done from the detach(9E) of the nexus itself.) 19547c478bd9Sstevel@tonic-gate */ 19557c478bd9Sstevel@tonic-gate (void) pci_resource_destroy(dip); 19567c478bd9Sstevel@tonic-gate 19577c478bd9Sstevel@tonic-gate mutex_exit(&pcihp_open_mutex); 19587c478bd9Sstevel@tonic-gate 19597c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 19607c478bd9Sstevel@tonic-gate } 19617c478bd9Sstevel@tonic-gate 19627c478bd9Sstevel@tonic-gate /* 19637c478bd9Sstevel@tonic-gate * pcihp_new_slot_state() 19647c478bd9Sstevel@tonic-gate * 19657c478bd9Sstevel@tonic-gate * This function is called by the HPS when it finds a hot plug 19667c478bd9Sstevel@tonic-gate * slot is added or being removed from the hot plug framework. 19677c478bd9Sstevel@tonic-gate * It returns 0 for success and HPC_ERR_FAILED for errors. 19687c478bd9Sstevel@tonic-gate */ 19697c478bd9Sstevel@tonic-gate static int 19707c478bd9Sstevel@tonic-gate pcihp_new_slot_state(dev_info_t *dip, hpc_slot_t hdl, 19717c478bd9Sstevel@tonic-gate hpc_slot_info_t *slot_info, int slot_state) 19727c478bd9Sstevel@tonic-gate { 19737c478bd9Sstevel@tonic-gate pcihp_t *pcihp_p; 19747c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 19757c478bd9Sstevel@tonic-gate int pci_dev; 19767c478bd9Sstevel@tonic-gate minor_t ap_minor; 19777c478bd9Sstevel@tonic-gate major_t ap_major; 19787c478bd9Sstevel@tonic-gate int rv = 0; 19797c478bd9Sstevel@tonic-gate time_t time; 19807c478bd9Sstevel@tonic-gate int auto_enable = 1; 19817c478bd9Sstevel@tonic-gate int rval; 19827c478bd9Sstevel@tonic-gate 19837c478bd9Sstevel@tonic-gate /* get a pointer to the soft state structure */ 19847c478bd9Sstevel@tonic-gate pcihp_p = pcihp_get_soft_state(dip, PCIHP_DR_SLOT_ENTER, &rval); 19857c478bd9Sstevel@tonic-gate ASSERT(pcihp_p != NULL); 19867c478bd9Sstevel@tonic-gate 19877c478bd9Sstevel@tonic-gate if (rval == PCIHP_FAILURE) { 19887c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_WARN, "pcihp instance is unconfigured" 19897c478bd9Sstevel@tonic-gate " while slot activity is requested\n")); 19907c478bd9Sstevel@tonic-gate return (HPC_ERR_FAILED); 19917c478bd9Sstevel@tonic-gate } 19927c478bd9Sstevel@tonic-gate 19937c478bd9Sstevel@tonic-gate pci_dev = slot_info->pci_dev_num; 19947c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 19957c478bd9Sstevel@tonic-gate 19967c478bd9Sstevel@tonic-gate mutex_enter(&slotinfop->slot_mutex); 19977c478bd9Sstevel@tonic-gate 19987c478bd9Sstevel@tonic-gate switch (slot_state) { 19997c478bd9Sstevel@tonic-gate 20007c478bd9Sstevel@tonic-gate case HPC_SLOT_ONLINE: 20017c478bd9Sstevel@tonic-gate 20027c478bd9Sstevel@tonic-gate /* 20037c478bd9Sstevel@tonic-gate * Make sure the slot is not already ONLINE (paranoia?). 20047c478bd9Sstevel@tonic-gate * (Note: Should this be simply an ASSERTION?) 20057c478bd9Sstevel@tonic-gate */ 20067c478bd9Sstevel@tonic-gate if (slotinfop->slot_hdl != NULL) { 20077c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_WARN, 20087c478bd9Sstevel@tonic-gate "pcihp (%s%d): pci slot (dev %x) already ONLINE!!", 200932d69156Sscarter ddi_driver_name(dip), ddi_get_instance(dip), 201032d69156Sscarter pci_dev)); 20117c478bd9Sstevel@tonic-gate rv = HPC_ERR_FAILED; 20127c478bd9Sstevel@tonic-gate break; 20137c478bd9Sstevel@tonic-gate } 20147c478bd9Sstevel@tonic-gate 20157c478bd9Sstevel@tonic-gate /* 20167c478bd9Sstevel@tonic-gate * Add the hot plug slot to the bus. 20177c478bd9Sstevel@tonic-gate */ 20187c478bd9Sstevel@tonic-gate 20197c478bd9Sstevel@tonic-gate /* create the AP minor node */ 20207c478bd9Sstevel@tonic-gate ap_minor = PCIHP_AP_MINOR_NUM(ddi_get_instance(dip), pci_dev); 20217c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, slot_info->pci_slot_name, 20227c478bd9Sstevel@tonic-gate S_IFCHR, ap_minor, 20237c478bd9Sstevel@tonic-gate DDI_NT_PCI_ATTACHMENT_POINT, 0) == DDI_FAILURE) { 20247c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 20257c478bd9Sstevel@tonic-gate "pcihp (%s%d): ddi_create_minor_node failed" 20267c478bd9Sstevel@tonic-gate " for pci dev %x", ddi_driver_name(dip), 20277c478bd9Sstevel@tonic-gate ddi_get_instance(dip), pci_dev); 20287c478bd9Sstevel@tonic-gate rv = HPC_ERR_FAILED; 20297c478bd9Sstevel@tonic-gate break; 20307c478bd9Sstevel@tonic-gate } 20317c478bd9Sstevel@tonic-gate 20327c478bd9Sstevel@tonic-gate /* save the slot handle */ 20337c478bd9Sstevel@tonic-gate slotinfop->slot_hdl = hdl; 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate /* setup event handler for all hardware events on the slot */ 20365c066ec2SJerry Gilliam ap_major = ddi_driver_major(dip); 20377c478bd9Sstevel@tonic-gate if (hpc_install_event_handler(hdl, -1, pcihp_event_handler, 20387c478bd9Sstevel@tonic-gate (caddr_t)makedevice(ap_major, ap_minor)) != 0) { 20397c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 20407c478bd9Sstevel@tonic-gate "pcihp (%s%d): install event handler failed" 20417c478bd9Sstevel@tonic-gate " for pci dev %x", ddi_driver_name(dip), 20427c478bd9Sstevel@tonic-gate ddi_get_instance(dip), pci_dev); 20437c478bd9Sstevel@tonic-gate rv = HPC_ERR_FAILED; 20447c478bd9Sstevel@tonic-gate break; 20457c478bd9Sstevel@tonic-gate } 20467c478bd9Sstevel@tonic-gate slotinfop->event_mask = (uint32_t)0xFFFFFFFF; 20477c478bd9Sstevel@tonic-gate 20487c478bd9Sstevel@tonic-gate pcihp_create_occupant_props(dip, makedevice(ap_major, 20497c478bd9Sstevel@tonic-gate ap_minor), pci_dev); 20507c478bd9Sstevel@tonic-gate 20517c478bd9Sstevel@tonic-gate /* set default auto configuration enabled flag for this slot */ 20527c478bd9Sstevel@tonic-gate slotinfop->slot_flags = pcihp_autocfg_enabled; 20537c478bd9Sstevel@tonic-gate 20547c478bd9Sstevel@tonic-gate /* copy the slot information */ 20557c478bd9Sstevel@tonic-gate slotinfop->name = 20567c478bd9Sstevel@tonic-gate kmem_alloc(strlen(slot_info->pci_slot_name) + 1, KM_SLEEP); 20577c478bd9Sstevel@tonic-gate (void) strcpy(slotinfop->name, slot_info->pci_slot_name); 20587c478bd9Sstevel@tonic-gate slotinfop->slot_type = slot_info->slot_type; 20597c478bd9Sstevel@tonic-gate slotinfop->hs_csr_location = 0; 20607c478bd9Sstevel@tonic-gate slotinfop->slot_capabilities = slot_info->pci_slot_capabilities; 20617c478bd9Sstevel@tonic-gate if (slot_info->slot_flags & HPC_SLOT_NO_AUTO_ENABLE) 20627c478bd9Sstevel@tonic-gate auto_enable = 0; 20637c478bd9Sstevel@tonic-gate 20647c478bd9Sstevel@tonic-gate if (slot_info->slot_flags & HPC_SLOT_CREATE_DEVLINK) { 20657c478bd9Sstevel@tonic-gate pci_devlink_flags |= (1 << pci_dev); 20667c478bd9Sstevel@tonic-gate (void) ddi_prop_update_int(DDI_DEV_T_NONE, 206732d69156Sscarter dip, "ap-names", pci_devlink_flags); 20687c478bd9Sstevel@tonic-gate } 20697c478bd9Sstevel@tonic-gate 20707c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, 20717c478bd9Sstevel@tonic-gate "pcihp (%s%d): pci slot (dev %x) ONLINE\n", 20727c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), pci_dev)); 20737c478bd9Sstevel@tonic-gate 20747c478bd9Sstevel@tonic-gate /* 20757c478bd9Sstevel@tonic-gate * The slot may have an occupant that was configured 20767c478bd9Sstevel@tonic-gate * at boot time. If we find a devinfo node in the tree 20777c478bd9Sstevel@tonic-gate * for this slot (i.e pci device number) then we 20787c478bd9Sstevel@tonic-gate * record the occupant state as CONFIGURED. 20797c478bd9Sstevel@tonic-gate */ 20807c478bd9Sstevel@tonic-gate if (pcihp_devi_find(dip, pci_dev, 0) != NULL) { 20817c478bd9Sstevel@tonic-gate /* we have a configured occupant */ 20827c478bd9Sstevel@tonic-gate slotinfop->ostate = AP_OSTATE_CONFIGURED; 20837c478bd9Sstevel@tonic-gate slotinfop->rstate = AP_RSTATE_CONNECTED; 20847c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_OK; 20857c478bd9Sstevel@tonic-gate 20867c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 20877c478bd9Sstevel@tonic-gate /* this will set slot flags too. */ 20887c478bd9Sstevel@tonic-gate (void) pcihp_get_board_type(slotinfop); 20897c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 20907c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_CONFIGURE); 20917c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 20927c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 20937c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_OFF); 20947c478bd9Sstevel@tonic-gate /* ENUM# enabled by default for cPCI devices */ 20957c478bd9Sstevel@tonic-gate slotinfop->slot_flags |= PCIHP_SLOT_AUTO_CFG_EN; 20967c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= 20977c478bd9Sstevel@tonic-gate ~PCIHP_SLOT_ENUM_INS_PENDING; 20987c478bd9Sstevel@tonic-gate } 20997c478bd9Sstevel@tonic-gate 21007c478bd9Sstevel@tonic-gate /* tell HPC driver that the occupant is configured */ 21017c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 21027c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIGURED, NULL); 2103daeea309Sarutz 2104daeea309Sarutz /* 2105daeea309Sarutz * Tell sysevent listeners that slot has 2106daeea309Sarutz * changed state. At minimum, this is useful 2107daeea309Sarutz * when a PCI-E Chassis (containing Occupants) is 2108daeea309Sarutz * hotplugged. In this case, the following will 2109daeea309Sarutz * announce that the Occupant in the Receptacle 2110daeea309Sarutz * in the Chassis had a state-change. 2111daeea309Sarutz */ 2112daeea309Sarutz pcihp_gen_sysevent(slotinfop->name, 2113daeea309Sarutz PCIHP_DR_AP_STATE_CHANGE, SE_NO_HINT, 2114daeea309Sarutz pcihp_p->dip, KM_SLEEP); 21157c478bd9Sstevel@tonic-gate } else { 21167c478bd9Sstevel@tonic-gate struct pcihp_config_ctrl ctrl; 21177c478bd9Sstevel@tonic-gate int circular_count; 21187c478bd9Sstevel@tonic-gate 21197c478bd9Sstevel@tonic-gate slotinfop->ostate = AP_OSTATE_UNCONFIGURED; 21207c478bd9Sstevel@tonic-gate slotinfop->rstate = AP_RSTATE_EMPTY; 21217c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_UNKNOWN; 21227c478bd9Sstevel@tonic-gate 21237c478bd9Sstevel@tonic-gate if (!auto_enable) { /* no further action */ 21247c478bd9Sstevel@tonic-gate break; 21257c478bd9Sstevel@tonic-gate } 21267c478bd9Sstevel@tonic-gate 21277c478bd9Sstevel@tonic-gate /* 21287c478bd9Sstevel@tonic-gate * We enable power to the slot and try to 21297c478bd9Sstevel@tonic-gate * configure if there is any card present. 21307c478bd9Sstevel@tonic-gate * 21317c478bd9Sstevel@tonic-gate * Note: This case is possible if the BIOS or 21327c478bd9Sstevel@tonic-gate * firmware doesn't enable the slots during 21337c478bd9Sstevel@tonic-gate * soft reboot. 21347c478bd9Sstevel@tonic-gate */ 21357c478bd9Sstevel@tonic-gate if (hpc_nexus_connect(slotinfop->slot_hdl, 21367c478bd9Sstevel@tonic-gate NULL, 0) != HPC_SUCCESS) 21377c478bd9Sstevel@tonic-gate break; 21387c478bd9Sstevel@tonic-gate 21397c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 21407c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 21417c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_CONFIGURE); 21427c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 21437c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 21447c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_OFF); 21457c478bd9Sstevel@tonic-gate slotinfop->slot_flags |= PCIHP_SLOT_AUTO_CFG_EN; 21467c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= 21477c478bd9Sstevel@tonic-gate ~PCIHP_SLOT_ENUM_INS_PENDING; 21487c478bd9Sstevel@tonic-gate } 21497c478bd9Sstevel@tonic-gate 21507c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 21517c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIG_START, NULL); 21527c478bd9Sstevel@tonic-gate 21537c478bd9Sstevel@tonic-gate /* 21547c478bd9Sstevel@tonic-gate * Call the configurator to configure the card. 21557c478bd9Sstevel@tonic-gate */ 2156*26947304SEvan Yan if (pcicfg_configure(dip, pci_dev, PCICFG_ALL_FUNC, 0) 2157*26947304SEvan Yan != PCICFG_SUCCESS) { 21587c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 21597c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 21607c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, 21617c478bd9Sstevel@tonic-gate pci_dev, 21627c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_ON); 21637c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 21647c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_UNCONFIGURE); 21657c478bd9Sstevel@tonic-gate } 21667c478bd9Sstevel@tonic-gate 21677c478bd9Sstevel@tonic-gate /* tell HPC driver occupant configure Error */ 21687c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 21697c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIG_FAILURE, NULL); 21707c478bd9Sstevel@tonic-gate 21717c478bd9Sstevel@tonic-gate /* 21727c478bd9Sstevel@tonic-gate * call HPC driver to turn off the power for 21737c478bd9Sstevel@tonic-gate * the slot. 21747c478bd9Sstevel@tonic-gate */ 21757c478bd9Sstevel@tonic-gate (void) hpc_nexus_disconnect(slotinfop->slot_hdl, 21767c478bd9Sstevel@tonic-gate NULL, 0); 21777c478bd9Sstevel@tonic-gate } else { 21787c478bd9Sstevel@tonic-gate /* record the occupant state as CONFIGURED */ 21797c478bd9Sstevel@tonic-gate slotinfop->ostate = AP_OSTATE_CONFIGURED; 21807c478bd9Sstevel@tonic-gate slotinfop->rstate = AP_RSTATE_CONNECTED; 21817c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_OK; 21827c478bd9Sstevel@tonic-gate 21837c478bd9Sstevel@tonic-gate /* now, online all the devices in the AP */ 21847c478bd9Sstevel@tonic-gate ctrl.flags = PCIHP_CFG_CONTINUE; 21857c478bd9Sstevel@tonic-gate ctrl.rv = NDI_SUCCESS; 21867c478bd9Sstevel@tonic-gate ctrl.dip = NULL; 21877c478bd9Sstevel@tonic-gate ctrl.pci_dev = pci_dev; 21887c478bd9Sstevel@tonic-gate ctrl.op = PCIHP_ONLINE; 21897c478bd9Sstevel@tonic-gate /* 21907c478bd9Sstevel@tonic-gate * the following sets slot_flags and 21917c478bd9Sstevel@tonic-gate * hs_csr_location too. 21927c478bd9Sstevel@tonic-gate */ 21937c478bd9Sstevel@tonic-gate (void) pcihp_get_board_type(slotinfop); 21947c478bd9Sstevel@tonic-gate 21957c478bd9Sstevel@tonic-gate ndi_devi_enter(dip, &circular_count); 219632d69156Sscarter ddi_walk_devs(ddi_get_child(dip), 219732d69156Sscarter pcihp_configure, (void *)&ctrl); 21987c478bd9Sstevel@tonic-gate ndi_devi_exit(dip, circular_count); 21997c478bd9Sstevel@tonic-gate 22007c478bd9Sstevel@tonic-gate if (ctrl.rv != NDI_SUCCESS) { 22017c478bd9Sstevel@tonic-gate /* 22027c478bd9Sstevel@tonic-gate * one or more of the devices are not 22037c478bd9Sstevel@tonic-gate * ONLINE'd. How is this to be 22047c478bd9Sstevel@tonic-gate * reported? 22057c478bd9Sstevel@tonic-gate */ 2206daeea309Sarutz cmn_err(CE_WARN, 2207daeea309Sarutz "pcihp (%s%d): failed to attach" 2208daeea309Sarutz " one or more drivers for the" 2209daeea309Sarutz " card in the slot %s", 22107c478bd9Sstevel@tonic-gate ddi_driver_name(dip), 22117c478bd9Sstevel@tonic-gate ddi_get_instance(dip), 22127c478bd9Sstevel@tonic-gate slotinfop->name); 22137c478bd9Sstevel@tonic-gate } 22147c478bd9Sstevel@tonic-gate 2215daeea309Sarutz /* tell HPC driver the Occupant is Configured */ 22167c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 22177c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIGURED, NULL); 2218daeea309Sarutz 2219daeea309Sarutz /* 2220daeea309Sarutz * Tell sysevent listeners that slot has 2221daeea309Sarutz * changed state. At minimum, this is useful 2222daeea309Sarutz * when a PCI-E Chassis (containing Occupants) 2223daeea309Sarutz * is hotplugged. In this case, the following 2224daeea309Sarutz * will announce that the Occupant in the 2225daeea309Sarutz * Receptacle in the Chassis had a state-change. 2226daeea309Sarutz */ 2227daeea309Sarutz pcihp_gen_sysevent(slotinfop->name, 2228daeea309Sarutz PCIHP_DR_AP_STATE_CHANGE, SE_NO_HINT, 2229daeea309Sarutz pcihp_p->dip, KM_SLEEP); 22307c478bd9Sstevel@tonic-gate } 22317c478bd9Sstevel@tonic-gate } 22327c478bd9Sstevel@tonic-gate 22337c478bd9Sstevel@tonic-gate break; 22347c478bd9Sstevel@tonic-gate 22357c478bd9Sstevel@tonic-gate case HPC_SLOT_OFFLINE: 22367c478bd9Sstevel@tonic-gate /* 22377c478bd9Sstevel@tonic-gate * A hot plug slot is being removed from the bus. 22387c478bd9Sstevel@tonic-gate * Make sure there is no occupant configured on the 22397c478bd9Sstevel@tonic-gate * slot before removing the AP minor node. 22407c478bd9Sstevel@tonic-gate */ 22417c478bd9Sstevel@tonic-gate if (slotinfop->ostate != AP_OSTATE_UNCONFIGURED) { 224232d69156Sscarter cmn_err(CE_WARN, "pcihp (%s%d): Card is still in " 224332d69156Sscarter "configured state for pci dev %x", 224432d69156Sscarter ddi_driver_name(dip), ddi_get_instance(dip), 224532d69156Sscarter pci_dev); 22467c478bd9Sstevel@tonic-gate rv = HPC_ERR_FAILED; 22477c478bd9Sstevel@tonic-gate break; 22487c478bd9Sstevel@tonic-gate } 22497c478bd9Sstevel@tonic-gate 22507c478bd9Sstevel@tonic-gate /* 22517c478bd9Sstevel@tonic-gate * If the AP device is in open state then return 22527c478bd9Sstevel@tonic-gate * error. 22537c478bd9Sstevel@tonic-gate */ 22547c478bd9Sstevel@tonic-gate if (pcihp_p->soft_state != PCIHP_SOFT_STATE_CLOSED) { 22557c478bd9Sstevel@tonic-gate rv = HPC_ERR_FAILED; 22567c478bd9Sstevel@tonic-gate break; 22577c478bd9Sstevel@tonic-gate } 22587c478bd9Sstevel@tonic-gate if (slot_info->slot_flags & HPC_SLOT_CREATE_DEVLINK) { 22597c478bd9Sstevel@tonic-gate pci_devlink_flags &= ~(1 << pci_dev); 226032d69156Sscarter (void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, 226132d69156Sscarter "ap-names", pci_devlink_flags); 22627c478bd9Sstevel@tonic-gate } 22637c478bd9Sstevel@tonic-gate 22647c478bd9Sstevel@tonic-gate /* remove the minor node */ 22657c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, slotinfop->name); 22667c478bd9Sstevel@tonic-gate 22677c478bd9Sstevel@tonic-gate /* free up the memory for the name string */ 22687c478bd9Sstevel@tonic-gate kmem_free(slotinfop->name, strlen(slotinfop->name) + 1); 22697c478bd9Sstevel@tonic-gate 22707c478bd9Sstevel@tonic-gate /* update the slot info data */ 22717c478bd9Sstevel@tonic-gate slotinfop->name = NULL; 22727c478bd9Sstevel@tonic-gate slotinfop->slot_hdl = NULL; 22737c478bd9Sstevel@tonic-gate 22747c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, 22757c478bd9Sstevel@tonic-gate "pcihp (%s%d): pci slot (dev %x) OFFLINE\n", 22767c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 22777c478bd9Sstevel@tonic-gate slot_info->pci_dev_num)); 22787c478bd9Sstevel@tonic-gate 22797c478bd9Sstevel@tonic-gate break; 22807c478bd9Sstevel@tonic-gate default: 22817c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 22827c478bd9Sstevel@tonic-gate "pcihp_new_slot_state: unknown slot_state %d", slot_state); 22837c478bd9Sstevel@tonic-gate rv = HPC_ERR_FAILED; 22847c478bd9Sstevel@tonic-gate } 22857c478bd9Sstevel@tonic-gate 22867c478bd9Sstevel@tonic-gate if (rv == 0) { 22877c478bd9Sstevel@tonic-gate if (drv_getparm(TIME, (void *)&time) != DDI_SUCCESS) 22887c478bd9Sstevel@tonic-gate slotinfop->last_change = (time_t)-1; 22897c478bd9Sstevel@tonic-gate else 22907c478bd9Sstevel@tonic-gate slotinfop->last_change = (time32_t)time; 22917c478bd9Sstevel@tonic-gate } 22927c478bd9Sstevel@tonic-gate 22937c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 22947c478bd9Sstevel@tonic-gate 22957c478bd9Sstevel@tonic-gate (void) pcihp_get_soft_state(dip, PCIHP_DR_SLOT_EXIT, &rval); 22967c478bd9Sstevel@tonic-gate 22977c478bd9Sstevel@tonic-gate return (rv); 22987c478bd9Sstevel@tonic-gate } 22997c478bd9Sstevel@tonic-gate 23007c478bd9Sstevel@tonic-gate /* 23017c478bd9Sstevel@tonic-gate * Event handler. It is assumed that this function is called from 23027c478bd9Sstevel@tonic-gate * a kernel context only. 23037c478bd9Sstevel@tonic-gate * 23047c478bd9Sstevel@tonic-gate * Parameters: 23057c478bd9Sstevel@tonic-gate * slot_arg AP minor number. 23067c478bd9Sstevel@tonic-gate * event_mask Event that occurred. 23077c478bd9Sstevel@tonic-gate */ 23087c478bd9Sstevel@tonic-gate 23097c478bd9Sstevel@tonic-gate static int 23107c478bd9Sstevel@tonic-gate pcihp_event_handler(caddr_t slot_arg, uint_t event_mask) 23117c478bd9Sstevel@tonic-gate { 23127c478bd9Sstevel@tonic-gate dev_t ap_dev = (dev_t)slot_arg; 23137c478bd9Sstevel@tonic-gate dev_info_t *self; 23147c478bd9Sstevel@tonic-gate pcihp_t *pcihp_p; 23157c478bd9Sstevel@tonic-gate int pci_dev; 23167c478bd9Sstevel@tonic-gate int rv = HPC_EVENT_CLAIMED; 23177c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 23187c478bd9Sstevel@tonic-gate struct pcihp_config_ctrl ctrl; 23197c478bd9Sstevel@tonic-gate int circular_count; 23207c478bd9Sstevel@tonic-gate int rval; 232170025d76Sjohnny int hint; 232270025d76Sjohnny hpc_slot_state_t rstate; 23234eacc763Sjj156685 struct hpc_led_info led_info; 23247c478bd9Sstevel@tonic-gate 23257c478bd9Sstevel@tonic-gate /* 23267c478bd9Sstevel@tonic-gate * Get the soft state structure. 23277c478bd9Sstevel@tonic-gate */ 23287c478bd9Sstevel@tonic-gate if (pcihp_info(NULL, DDI_INFO_DEVT2DEVINFO, (void *)ap_dev, 23297c478bd9Sstevel@tonic-gate (void **)&self) != DDI_SUCCESS) 23307c478bd9Sstevel@tonic-gate return (ENXIO); 23317c478bd9Sstevel@tonic-gate 23327c478bd9Sstevel@tonic-gate pcihp_p = pcihp_get_soft_state(self, PCIHP_DR_SLOT_ENTER, &rval); 23337c478bd9Sstevel@tonic-gate ASSERT(pcihp_p != NULL); 23347c478bd9Sstevel@tonic-gate 23357c478bd9Sstevel@tonic-gate if (rval == PCIHP_FAILURE) { 23367c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_WARN, "pcihp instance is unconfigured" 23377c478bd9Sstevel@tonic-gate " while slot activity is requested\n")); 23387c478bd9Sstevel@tonic-gate return (-1); 23397c478bd9Sstevel@tonic-gate } 23407c478bd9Sstevel@tonic-gate 23417c478bd9Sstevel@tonic-gate /* get the PCI device number for the slot */ 23427c478bd9Sstevel@tonic-gate pci_dev = PCIHP_AP_MINOR_NUM_TO_PCI_DEVNUM(getminor(ap_dev)); 23437c478bd9Sstevel@tonic-gate 23447c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 23457c478bd9Sstevel@tonic-gate 23467c478bd9Sstevel@tonic-gate /* 23477c478bd9Sstevel@tonic-gate * All the events that may be handled in interrupt context should be 23487c478bd9Sstevel@tonic-gate * free of any mutex usage. 23497c478bd9Sstevel@tonic-gate */ 23507c478bd9Sstevel@tonic-gate switch (event_mask) { 23517c478bd9Sstevel@tonic-gate 23527c478bd9Sstevel@tonic-gate case HPC_EVENT_CLEAR_ENUM: 23537c478bd9Sstevel@tonic-gate /* 23547c478bd9Sstevel@tonic-gate * Check and clear ENUM# interrupt status. This may be 23557c478bd9Sstevel@tonic-gate * called by the Hotswap controller driver when it is 23567c478bd9Sstevel@tonic-gate * operating in a full hotswap system where the 23577c478bd9Sstevel@tonic-gate * platform may not have control on globally disabling ENUM#. 23587c478bd9Sstevel@tonic-gate * In such cases, the intent is to clear interrupt and 23597c478bd9Sstevel@tonic-gate * process the interrupt in non-interrupt context. 23607c478bd9Sstevel@tonic-gate * This is the first part of the ENUM# event processing. 23617c478bd9Sstevel@tonic-gate */ 23627c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): ENUM# is generated" 23637c478bd9Sstevel@tonic-gate " on the bus (for slot %s ?)", 23647c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 23657c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), slotinfop->name)); 23667c478bd9Sstevel@tonic-gate 23677c478bd9Sstevel@tonic-gate /* this is the only event coming through in interrupt context */ 23687c478bd9Sstevel@tonic-gate rv = pcihp_handle_enum(pcihp_p, pci_dev, PCIHP_CLEAR_ENUM, 23697c478bd9Sstevel@tonic-gate KM_NOSLEEP); 23707c478bd9Sstevel@tonic-gate 23717c478bd9Sstevel@tonic-gate (void) pcihp_get_soft_state(self, PCIHP_DR_SLOT_EXIT, &rval); 23727c478bd9Sstevel@tonic-gate 23737c478bd9Sstevel@tonic-gate return (rv); 23747c478bd9Sstevel@tonic-gate default: 23757c478bd9Sstevel@tonic-gate break; 23767c478bd9Sstevel@tonic-gate } 23777c478bd9Sstevel@tonic-gate 23787c478bd9Sstevel@tonic-gate mutex_enter(&slotinfop->slot_mutex); 23797c478bd9Sstevel@tonic-gate 238070025d76Sjohnny if (hpc_nexus_control(slotinfop->slot_hdl, 238170025d76Sjohnny HPC_CTRL_GET_SLOT_STATE, (caddr_t)&rstate) != 0) 238270025d76Sjohnny rv = HPC_ERR_FAILED; 238370025d76Sjohnny 238470025d76Sjohnny slotinfop->rstate = (ap_rstate_t)rstate; 238570025d76Sjohnny 23867c478bd9Sstevel@tonic-gate switch (event_mask) { 23877c478bd9Sstevel@tonic-gate 23887c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_INSERTION: 23897c478bd9Sstevel@tonic-gate /* 23907c478bd9Sstevel@tonic-gate * A card is inserted in the slot. Just report this 23917c478bd9Sstevel@tonic-gate * event and return. 23927c478bd9Sstevel@tonic-gate */ 23937c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "pcihp (%s%d): card is inserted" 23947c478bd9Sstevel@tonic-gate " in the slot %s (pci dev %x)", 23957c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 23967c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 23977c478bd9Sstevel@tonic-gate slotinfop->name, pci_dev); 23987c478bd9Sstevel@tonic-gate 23997c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 24007c478bd9Sstevel@tonic-gate 24017c478bd9Sstevel@tonic-gate break; 24027c478bd9Sstevel@tonic-gate 24037c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_CONFIGURE: 24047c478bd9Sstevel@tonic-gate /* 24057c478bd9Sstevel@tonic-gate * Configure the occupant that is just inserted in the slot. 24067c478bd9Sstevel@tonic-gate * The receptacle may or may not be in the connected state. If 24077c478bd9Sstevel@tonic-gate * the receptacle is not connected and the auto configuration 24087c478bd9Sstevel@tonic-gate * is enabled on this slot then connect the slot. If auto 24097c478bd9Sstevel@tonic-gate * configuration is enabled then configure the card. 24107c478bd9Sstevel@tonic-gate */ 24117c478bd9Sstevel@tonic-gate if ((slotinfop->slot_flags & PCIHP_SLOT_AUTO_CFG_EN) == 0) { 24127c478bd9Sstevel@tonic-gate /* 24137c478bd9Sstevel@tonic-gate * auto configuration is disabled. Tell someone 24147c478bd9Sstevel@tonic-gate * like RCM about this hotplug event? 24157c478bd9Sstevel@tonic-gate */ 24167c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "pcihp (%s%d): SLOT_CONFIGURE event" 24177c478bd9Sstevel@tonic-gate " occurred for pci dev %x (slot %s)," 24187c478bd9Sstevel@tonic-gate " Slot disabled for auto-configuration.", 24197c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 24207c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), pci_dev, 24217c478bd9Sstevel@tonic-gate slotinfop->name); 24227c478bd9Sstevel@tonic-gate 24237c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 24247c478bd9Sstevel@tonic-gate 24257c478bd9Sstevel@tonic-gate break; 24267c478bd9Sstevel@tonic-gate } 24277c478bd9Sstevel@tonic-gate 24287c478bd9Sstevel@tonic-gate if (slotinfop->ostate == AP_OSTATE_CONFIGURED) { 24297c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pcihp (%s%d): SLOT_CONFIGURE event" 24307c478bd9Sstevel@tonic-gate " re-occurred for pci dev %x (slot %s),", 24317c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 24327c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), pci_dev, 24337c478bd9Sstevel@tonic-gate slotinfop->name); 24347c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 24357c478bd9Sstevel@tonic-gate 24367c478bd9Sstevel@tonic-gate (void) pcihp_get_soft_state(self, PCIHP_DR_SLOT_EXIT, 24377c478bd9Sstevel@tonic-gate &rval); 24387c478bd9Sstevel@tonic-gate 24397c478bd9Sstevel@tonic-gate return (EAGAIN); 24407c478bd9Sstevel@tonic-gate } 24417c478bd9Sstevel@tonic-gate 24427c478bd9Sstevel@tonic-gate /* 24437c478bd9Sstevel@tonic-gate * Auto configuration is enabled. First, make sure the 24447c478bd9Sstevel@tonic-gate * receptacle is in the CONNECTED state. 24457c478bd9Sstevel@tonic-gate */ 24467c478bd9Sstevel@tonic-gate if ((rv = hpc_nexus_connect(slotinfop->slot_hdl, 24477c478bd9Sstevel@tonic-gate NULL, 0)) == HPC_SUCCESS) { 244832d69156Sscarter /* record rstate */ 244932d69156Sscarter slotinfop->rstate = AP_RSTATE_CONNECTED; 24507c478bd9Sstevel@tonic-gate } 24517c478bd9Sstevel@tonic-gate 24527c478bd9Sstevel@tonic-gate /* Clear INS and Turn LED Off and start configuring. */ 24537c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 24547c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 24557c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_CONFIGURE); 24567c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 24577c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 24587c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_OFF); 24597c478bd9Sstevel@tonic-gate } 24607c478bd9Sstevel@tonic-gate 24617c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 24627c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIG_START, NULL); 24637c478bd9Sstevel@tonic-gate 24647c478bd9Sstevel@tonic-gate /* 24657c478bd9Sstevel@tonic-gate * Call the configurator to configure the card. 24667c478bd9Sstevel@tonic-gate */ 2467*26947304SEvan Yan if (pcicfg_configure(pcihp_p->dip, pci_dev, PCICFG_ALL_FUNC, 0) 2468*26947304SEvan Yan != PCICFG_SUCCESS) { 24697c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 24707c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 24717c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 24727c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_ON); 24737c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 24747c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_UNCONFIGURE); 24757c478bd9Sstevel@tonic-gate } 24767c478bd9Sstevel@tonic-gate /* failed to configure the card */ 24777c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pcihp (%s%d): failed to configure" 24787c478bd9Sstevel@tonic-gate " the card in the slot %s", 24797c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 24807c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 24817c478bd9Sstevel@tonic-gate slotinfop->name); 24827c478bd9Sstevel@tonic-gate /* failed to configure; disconnect the slot */ 24837c478bd9Sstevel@tonic-gate if (hpc_nexus_disconnect(slotinfop->slot_hdl, 24847c478bd9Sstevel@tonic-gate NULL, 0) == HPC_SUCCESS) { 24857c478bd9Sstevel@tonic-gate slotinfop->rstate = AP_RSTATE_DISCONNECTED; 24867c478bd9Sstevel@tonic-gate } 24877c478bd9Sstevel@tonic-gate 24887c478bd9Sstevel@tonic-gate /* tell HPC driver occupant configure Error */ 24897c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 24907c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIG_FAILURE, NULL); 24917c478bd9Sstevel@tonic-gate } else { 24927c478bd9Sstevel@tonic-gate /* record the occupant state as CONFIGURED */ 24937c478bd9Sstevel@tonic-gate slotinfop->ostate = AP_OSTATE_CONFIGURED; 24947c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_OK; 24957c478bd9Sstevel@tonic-gate 24967c478bd9Sstevel@tonic-gate /* now, online all the devices in the AP */ 24977c478bd9Sstevel@tonic-gate ctrl.flags = PCIHP_CFG_CONTINUE; 24987c478bd9Sstevel@tonic-gate ctrl.rv = NDI_SUCCESS; 24997c478bd9Sstevel@tonic-gate ctrl.dip = NULL; 25007c478bd9Sstevel@tonic-gate ctrl.pci_dev = pci_dev; 25017c478bd9Sstevel@tonic-gate ctrl.op = PCIHP_ONLINE; 25027c478bd9Sstevel@tonic-gate (void) pcihp_get_board_type(slotinfop); 25037c478bd9Sstevel@tonic-gate 25047c478bd9Sstevel@tonic-gate ndi_devi_enter(pcihp_p->dip, &circular_count); 25057c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_get_child(pcihp_p->dip), 25067c478bd9Sstevel@tonic-gate pcihp_configure, (void *)&ctrl); 25077c478bd9Sstevel@tonic-gate ndi_devi_exit(pcihp_p->dip, circular_count); 25087c478bd9Sstevel@tonic-gate 25097c478bd9Sstevel@tonic-gate if (ctrl.rv != NDI_SUCCESS) { 25107c478bd9Sstevel@tonic-gate /* 25117c478bd9Sstevel@tonic-gate * one or more of the devices are not 25127c478bd9Sstevel@tonic-gate * ONLINE'd. How is this to be 25137c478bd9Sstevel@tonic-gate * reported? 25147c478bd9Sstevel@tonic-gate */ 25157c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 25167c478bd9Sstevel@tonic-gate "pcihp (%s%d): failed to attach one or" 25177c478bd9Sstevel@tonic-gate " more drivers for the card in" 25187c478bd9Sstevel@tonic-gate " the slot %s", 25197c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 25207c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 25217c478bd9Sstevel@tonic-gate slotinfop->name); 25227c478bd9Sstevel@tonic-gate } 25237c478bd9Sstevel@tonic-gate 25247c478bd9Sstevel@tonic-gate /* tell HPC driver that the occupant is configured */ 25257c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 25267c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_CONFIGURED, NULL); 25277c478bd9Sstevel@tonic-gate 25287c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "pcihp (%s%d): card is CONFIGURED" 25297c478bd9Sstevel@tonic-gate " in the slot %s (pci dev %x)", 25307c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 25317c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 25327c478bd9Sstevel@tonic-gate slotinfop->name, pci_dev); 25337c478bd9Sstevel@tonic-gate } 25347c478bd9Sstevel@tonic-gate 25357c478bd9Sstevel@tonic-gate break; 25367c478bd9Sstevel@tonic-gate 25377c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_UNCONFIGURE: 25387c478bd9Sstevel@tonic-gate /* 25397c478bd9Sstevel@tonic-gate * Unconfigure the occupant in this slot. 25407c478bd9Sstevel@tonic-gate */ 25417c478bd9Sstevel@tonic-gate if ((slotinfop->slot_flags & PCIHP_SLOT_AUTO_CFG_EN) == 0) { 25427c478bd9Sstevel@tonic-gate /* 25437c478bd9Sstevel@tonic-gate * auto configuration is disabled. Tell someone 25447c478bd9Sstevel@tonic-gate * like RCM about this hotplug event? 25457c478bd9Sstevel@tonic-gate */ 25467c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "pcihp (%s%d): SLOT_UNCONFIGURE event" 25477c478bd9Sstevel@tonic-gate " for pci dev %x (slot %s) ignored," 25487c478bd9Sstevel@tonic-gate " Slot disabled for auto-configuration.", 25497c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 25507c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), pci_dev, 25517c478bd9Sstevel@tonic-gate slotinfop->name); 25527c478bd9Sstevel@tonic-gate 25537c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 25547c478bd9Sstevel@tonic-gate 25557c478bd9Sstevel@tonic-gate break; 25567c478bd9Sstevel@tonic-gate } 25577c478bd9Sstevel@tonic-gate 25587c478bd9Sstevel@tonic-gate if (slotinfop->ostate == AP_OSTATE_UNCONFIGURED) { 25597c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pcihp (%s%d): SLOT_UNCONFIGURE " 25607c478bd9Sstevel@tonic-gate "event re-occurred for pci dev %x (slot %s),", 25617c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 25627c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), pci_dev, 25637c478bd9Sstevel@tonic-gate slotinfop->name); 25647c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 25657c478bd9Sstevel@tonic-gate 25667c478bd9Sstevel@tonic-gate (void) pcihp_get_soft_state(self, PCIHP_DR_SLOT_EXIT, 25677c478bd9Sstevel@tonic-gate &rval); 25687c478bd9Sstevel@tonic-gate 25697c478bd9Sstevel@tonic-gate return (EAGAIN); 25707c478bd9Sstevel@tonic-gate } 25717c478bd9Sstevel@tonic-gate /* 25727c478bd9Sstevel@tonic-gate * If the occupant is in the CONFIGURED state then 25737c478bd9Sstevel@tonic-gate * call the configurator to unconfigure the slot. 25747c478bd9Sstevel@tonic-gate */ 25757c478bd9Sstevel@tonic-gate if (slotinfop->ostate == AP_OSTATE_CONFIGURED) { 25767c478bd9Sstevel@tonic-gate /* 25777c478bd9Sstevel@tonic-gate * Detach all the drivers for the devices in the 25787c478bd9Sstevel@tonic-gate * slot. Call pcihp_configure() to offline the 25797c478bd9Sstevel@tonic-gate * devices. 25807c478bd9Sstevel@tonic-gate */ 25817c478bd9Sstevel@tonic-gate ctrl.flags = 0; 25827c478bd9Sstevel@tonic-gate ctrl.rv = NDI_SUCCESS; 25837c478bd9Sstevel@tonic-gate ctrl.dip = NULL; 25847c478bd9Sstevel@tonic-gate ctrl.pci_dev = pci_dev; 25857c478bd9Sstevel@tonic-gate ctrl.op = PCIHP_OFFLINE; 25867c478bd9Sstevel@tonic-gate 25877c478bd9Sstevel@tonic-gate (void) devfs_clean(pcihp_p->dip, NULL, DV_CLEAN_FORCE); 25887c478bd9Sstevel@tonic-gate ndi_devi_enter(pcihp_p->dip, &circular_count); 25897c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_get_child(pcihp_p->dip), 25907c478bd9Sstevel@tonic-gate pcihp_configure, (void *)&ctrl); 25917c478bd9Sstevel@tonic-gate ndi_devi_exit(pcihp_p->dip, circular_count); 25927c478bd9Sstevel@tonic-gate 25937c478bd9Sstevel@tonic-gate if (ctrl.rv != NDI_SUCCESS) { 25947c478bd9Sstevel@tonic-gate /* 25957c478bd9Sstevel@tonic-gate * Failed to detach one or more drivers. 25967c478bd9Sstevel@tonic-gate * Restore the status for the drivers 25977c478bd9Sstevel@tonic-gate * which are offlined during this step. 25987c478bd9Sstevel@tonic-gate */ 25997c478bd9Sstevel@tonic-gate ctrl.flags = PCIHP_CFG_CONTINUE; 26007c478bd9Sstevel@tonic-gate ctrl.rv = NDI_SUCCESS; 26017c478bd9Sstevel@tonic-gate ctrl.dip = NULL; 26027c478bd9Sstevel@tonic-gate ctrl.pci_dev = pci_dev; 26037c478bd9Sstevel@tonic-gate ctrl.op = PCIHP_ONLINE; 26047c478bd9Sstevel@tonic-gate 26057c478bd9Sstevel@tonic-gate ndi_devi_enter(pcihp_p->dip, &circular_count); 26067c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_get_child(pcihp_p->dip), 26077c478bd9Sstevel@tonic-gate pcihp_configure, (void *)&ctrl); 26087c478bd9Sstevel@tonic-gate ndi_devi_exit(pcihp_p->dip, circular_count); 26097c478bd9Sstevel@tonic-gate rv = HPC_ERR_FAILED; 26107c478bd9Sstevel@tonic-gate } else { 26117c478bd9Sstevel@tonic-gate (void) hpc_nexus_control(slotinfop->slot_hdl, 26127c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_UNCONFIG_START, NULL); 26137c478bd9Sstevel@tonic-gate 2614*26947304SEvan Yan if (pcicfg_unconfigure(pcihp_p->dip, pci_dev, 2615*26947304SEvan Yan PCICFG_ALL_FUNC, 0) == PCICFG_SUCCESS) { 26167c478bd9Sstevel@tonic-gate 26177c478bd9Sstevel@tonic-gate /* Resources freed. Turn LED on. Clear EXT. */ 26187c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 26197c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 26207c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, 26217c478bd9Sstevel@tonic-gate pci_dev, 26227c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_ON); 26237c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 26247c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_UNCONFIGURE); 26257c478bd9Sstevel@tonic-gate slotinfop->hs_csr_location = 0; 26267c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= 26277c478bd9Sstevel@tonic-gate ~PCIHP_SLOT_DEV_NON_HOTPLUG; 26287c478bd9Sstevel@tonic-gate } 26297c478bd9Sstevel@tonic-gate slotinfop->ostate = 26307c478bd9Sstevel@tonic-gate AP_OSTATE_UNCONFIGURED; 26317c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_UNKNOWN; 26327c478bd9Sstevel@tonic-gate /* 26337c478bd9Sstevel@tonic-gate * send the notification of state change 26347c478bd9Sstevel@tonic-gate * to the HPC driver. 26357c478bd9Sstevel@tonic-gate */ 26367c478bd9Sstevel@tonic-gate (void) hpc_nexus_control( 26377c478bd9Sstevel@tonic-gate slotinfop->slot_hdl, 263832d69156Sscarter HPC_CTRL_DEV_UNCONFIGURED, NULL); 26397c478bd9Sstevel@tonic-gate /* disconnect the slot */ 26407c478bd9Sstevel@tonic-gate if (hpc_nexus_disconnect( 26417c478bd9Sstevel@tonic-gate slotinfop->slot_hdl, 26427c478bd9Sstevel@tonic-gate NULL, 0) == HPC_SUCCESS) { 26437c478bd9Sstevel@tonic-gate slotinfop->rstate = 26447c478bd9Sstevel@tonic-gate AP_RSTATE_DISCONNECTED; 26457c478bd9Sstevel@tonic-gate } 26467c478bd9Sstevel@tonic-gate 26477c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, 26487c478bd9Sstevel@tonic-gate "pcihp (%s%d): card is UNCONFIGURED" 26497c478bd9Sstevel@tonic-gate " in the slot %s (pci dev %x)", 26507c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 26517c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 26527c478bd9Sstevel@tonic-gate slotinfop->name, pci_dev); 26537c478bd9Sstevel@tonic-gate } else { 26547c478bd9Sstevel@tonic-gate /* tell HPC driver occupant is Busy */ 26557c478bd9Sstevel@tonic-gate (void) hpc_nexus_control( 26567c478bd9Sstevel@tonic-gate slotinfop->slot_hdl, 26577c478bd9Sstevel@tonic-gate HPC_CTRL_DEV_UNCONFIG_FAILURE, 26587c478bd9Sstevel@tonic-gate NULL); 26597c478bd9Sstevel@tonic-gate 26607c478bd9Sstevel@tonic-gate rv = HPC_ERR_FAILED; 26617c478bd9Sstevel@tonic-gate } 26627c478bd9Sstevel@tonic-gate } 26637c478bd9Sstevel@tonic-gate } 26647c478bd9Sstevel@tonic-gate 26657c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 26667c478bd9Sstevel@tonic-gate 26677c478bd9Sstevel@tonic-gate break; 26687c478bd9Sstevel@tonic-gate 26697c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_REMOVAL: 26707c478bd9Sstevel@tonic-gate /* 26717c478bd9Sstevel@tonic-gate * Card is removed from the slot. The card must have been 26727c478bd9Sstevel@tonic-gate * unconfigured before this event. 26737c478bd9Sstevel@tonic-gate */ 26747c478bd9Sstevel@tonic-gate if (slotinfop->ostate != AP_OSTATE_UNCONFIGURED) { 267570025d76Sjohnny slotinfop->condition = AP_COND_FAILED; 267670025d76Sjohnny cmn_err(CE_WARN, "pcihp (%s%d): card is removed" 267770025d76Sjohnny " from the slot %s", 26787c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 26797c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 26807c478bd9Sstevel@tonic-gate slotinfop->name); 2681f94c6026Sjj156685 } else { 2682f94c6026Sjj156685 slotinfop->condition = AP_COND_UNKNOWN; 26837c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "pcihp (%s%d): card is removed" 26847c478bd9Sstevel@tonic-gate " from the slot %s", 26857c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 26867c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 26877c478bd9Sstevel@tonic-gate slotinfop->name); 2688f94c6026Sjj156685 } 26897c478bd9Sstevel@tonic-gate 269070025d76Sjohnny slotinfop->rstate = AP_RSTATE_EMPTY; 269170025d76Sjohnny 26927c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 26937c478bd9Sstevel@tonic-gate 26947c478bd9Sstevel@tonic-gate break; 26957c478bd9Sstevel@tonic-gate 26967c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_POWER_ON: 26977c478bd9Sstevel@tonic-gate /* 26987c478bd9Sstevel@tonic-gate * Slot is connected to the bus. i.e the card is powered 26997c478bd9Sstevel@tonic-gate * on. Are there any error conditions to be checked? 27007c478bd9Sstevel@tonic-gate */ 27017c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): card is powered" 27027c478bd9Sstevel@tonic-gate " on in the slot %s", 27037c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 27047c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 27057c478bd9Sstevel@tonic-gate slotinfop->name)); 27067c478bd9Sstevel@tonic-gate 27077c478bd9Sstevel@tonic-gate slotinfop->rstate = AP_RSTATE_CONNECTED; /* record rstate */ 27087c478bd9Sstevel@tonic-gate 27097c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 27107c478bd9Sstevel@tonic-gate 27117c478bd9Sstevel@tonic-gate break; 27127c478bd9Sstevel@tonic-gate 27137c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_POWER_OFF: 27147c478bd9Sstevel@tonic-gate /* 27157c478bd9Sstevel@tonic-gate * Slot is disconnected from the bus. i.e the card is powered 27167c478bd9Sstevel@tonic-gate * off. Are there any error conditions to be checked? 27177c478bd9Sstevel@tonic-gate */ 27187c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): card is powered" 27197c478bd9Sstevel@tonic-gate " off in the slot %s", 27207c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 27217c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 27227c478bd9Sstevel@tonic-gate slotinfop->name)); 27237c478bd9Sstevel@tonic-gate 27247c478bd9Sstevel@tonic-gate slotinfop->rstate = AP_RSTATE_DISCONNECTED; /* record rstate */ 27257c478bd9Sstevel@tonic-gate 27267c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 27277c478bd9Sstevel@tonic-gate 27287c478bd9Sstevel@tonic-gate break; 27297c478bd9Sstevel@tonic-gate 27307c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_LATCH_SHUT: 27317c478bd9Sstevel@tonic-gate /* 27327c478bd9Sstevel@tonic-gate * Latch on the slot is closed. 27337c478bd9Sstevel@tonic-gate */ 273432d69156Sscarter cmn_err(CE_NOTE, "pcihp (%s%d): latch is shut for the slot %s", 27357c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 27367c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 27377c478bd9Sstevel@tonic-gate slotinfop->name); 27387c478bd9Sstevel@tonic-gate 27397c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 27407c478bd9Sstevel@tonic-gate 27417c478bd9Sstevel@tonic-gate break; 27427c478bd9Sstevel@tonic-gate 27437c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_LATCH_OPEN: 27447c478bd9Sstevel@tonic-gate /* 27457c478bd9Sstevel@tonic-gate * Latch on the slot is open. 27467c478bd9Sstevel@tonic-gate */ 274732d69156Sscarter cmn_err(CE_NOTE, "pcihp (%s%d): latch is open for the slot %s", 27487c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 27497c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 27507c478bd9Sstevel@tonic-gate slotinfop->name); 27517c478bd9Sstevel@tonic-gate 27527c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 27537c478bd9Sstevel@tonic-gate 27547c478bd9Sstevel@tonic-gate break; 27557c478bd9Sstevel@tonic-gate 27567c478bd9Sstevel@tonic-gate case HPC_EVENT_PROCESS_ENUM: 27577c478bd9Sstevel@tonic-gate /* 27587c478bd9Sstevel@tonic-gate * HSC knows the device number of the slot where the 27597c478bd9Sstevel@tonic-gate * ENUM# was triggered. 27607c478bd9Sstevel@tonic-gate * Now finish the necessary actions to be taken on that 27617c478bd9Sstevel@tonic-gate * slot. Please note that the interrupt is already cleared. 27627c478bd9Sstevel@tonic-gate * This is the second(last) part of the ENUM# event processing. 27637c478bd9Sstevel@tonic-gate */ 27647c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): processing ENUM#" 27657c478bd9Sstevel@tonic-gate " for slot %s", 27667c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 27677c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 27687c478bd9Sstevel@tonic-gate slotinfop->name)); 27697c478bd9Sstevel@tonic-gate 27707c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 27717c478bd9Sstevel@tonic-gate rv = pcihp_enum_slot(pcihp_p, slotinfop, pci_dev, 27727c478bd9Sstevel@tonic-gate PCIHP_HANDLE_ENUM, KM_SLEEP); 27737c478bd9Sstevel@tonic-gate mutex_enter(&slotinfop->slot_mutex); 27747c478bd9Sstevel@tonic-gate 27757c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 27767c478bd9Sstevel@tonic-gate 27777c478bd9Sstevel@tonic-gate break; 27787c478bd9Sstevel@tonic-gate 27797c478bd9Sstevel@tonic-gate case HPC_EVENT_BUS_ENUM: 27807c478bd9Sstevel@tonic-gate /* 27817c478bd9Sstevel@tonic-gate * Same as HPC_EVENT_SLOT_ENUM as defined the PSARC doc. 27827c478bd9Sstevel@tonic-gate * This term is used for better clarity of its usage. 27837c478bd9Sstevel@tonic-gate * 27847c478bd9Sstevel@tonic-gate * ENUM signal occurred on the bus. It may be from this 27857c478bd9Sstevel@tonic-gate * slot or any other hotplug slot on the bus. 27867c478bd9Sstevel@tonic-gate * 27877c478bd9Sstevel@tonic-gate * It is NOT recommended that the hotswap controller uses 27887c478bd9Sstevel@tonic-gate * event without queuing as NDI and other DDI calls may not 27897c478bd9Sstevel@tonic-gate * necessarily be invokable in interrupt context. 27907c478bd9Sstevel@tonic-gate * Hence the hotswap controller driver should use the 27917c478bd9Sstevel@tonic-gate * CLEAR_ENUM event which returns the slot device number 27927c478bd9Sstevel@tonic-gate * and then call HPC_EVENT_PROCESS_ENUM event with queuing. 27937c478bd9Sstevel@tonic-gate * 27947c478bd9Sstevel@tonic-gate * This can be used when the hotswap controller is 27957c478bd9Sstevel@tonic-gate * implementing a polled event mechanism to do the 27967c478bd9Sstevel@tonic-gate * necessary actions in a single call. 27977c478bd9Sstevel@tonic-gate */ 27987c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): ENUM# is generated" 27997c478bd9Sstevel@tonic-gate " on the bus (for slot %s ?)", 28007c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 28017c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 28027c478bd9Sstevel@tonic-gate slotinfop->name)); 28037c478bd9Sstevel@tonic-gate 28047c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 28057c478bd9Sstevel@tonic-gate rv = pcihp_handle_enum(pcihp_p, pci_dev, PCIHP_HANDLE_ENUM, 28067c478bd9Sstevel@tonic-gate KM_SLEEP); 28077c478bd9Sstevel@tonic-gate mutex_enter(&slotinfop->slot_mutex); 28087c478bd9Sstevel@tonic-gate 28097c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 28107c478bd9Sstevel@tonic-gate 28117c478bd9Sstevel@tonic-gate break; 28127c478bd9Sstevel@tonic-gate 28137c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_BLUE_LED_ON: 28147c478bd9Sstevel@tonic-gate 28157c478bd9Sstevel@tonic-gate /* 28167c478bd9Sstevel@tonic-gate * Request to turn Hot Swap Blue LED on. 28177c478bd9Sstevel@tonic-gate */ 28187c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): Request To Turn On Blue " 28197c478bd9Sstevel@tonic-gate "LED on the bus (for slot %s ?)", 28207c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 28217c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 28227c478bd9Sstevel@tonic-gate slotinfop->name)); 28237c478bd9Sstevel@tonic-gate 28247c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_SLOT_BLUE_LED_ON); 28257c478bd9Sstevel@tonic-gate break; 28267c478bd9Sstevel@tonic-gate 28277c478bd9Sstevel@tonic-gate case HPC_EVENT_DISABLE_ENUM: 28287c478bd9Sstevel@tonic-gate /* 28297c478bd9Sstevel@tonic-gate * Disable ENUM# which disables auto configuration on this slot 28307c478bd9Sstevel@tonic-gate */ 28317c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 28327c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 28337c478bd9Sstevel@tonic-gate HPC_EVENT_DISABLE_ENUM); 28347c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= ~PCIHP_SLOT_AUTO_CFG_EN; 28357c478bd9Sstevel@tonic-gate } 28367c478bd9Sstevel@tonic-gate break; 28377c478bd9Sstevel@tonic-gate 28387c478bd9Sstevel@tonic-gate case HPC_EVENT_ENABLE_ENUM: 28397c478bd9Sstevel@tonic-gate /* 28407c478bd9Sstevel@tonic-gate * Enable ENUM# which enables auto configuration on this slot. 28417c478bd9Sstevel@tonic-gate */ 28427c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 28437c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 28447c478bd9Sstevel@tonic-gate HPC_EVENT_ENABLE_ENUM); 28457c478bd9Sstevel@tonic-gate slotinfop->slot_flags |= PCIHP_SLOT_AUTO_CFG_EN; 28467c478bd9Sstevel@tonic-gate } 28477c478bd9Sstevel@tonic-gate break; 28487c478bd9Sstevel@tonic-gate 28497c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_BLUE_LED_OFF: 28507c478bd9Sstevel@tonic-gate 28517c478bd9Sstevel@tonic-gate /* 28527c478bd9Sstevel@tonic-gate * Request to turn Hot Swap Blue LED off. 28537c478bd9Sstevel@tonic-gate */ 28547c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): Request To Turn Off Blue " 28557c478bd9Sstevel@tonic-gate "LED on the bus (for slot %s ?)", 28567c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 28577c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 28587c478bd9Sstevel@tonic-gate slotinfop->name)); 28597c478bd9Sstevel@tonic-gate 28607c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_SLOT_BLUE_LED_OFF); 28617c478bd9Sstevel@tonic-gate 28627c478bd9Sstevel@tonic-gate break; 28637c478bd9Sstevel@tonic-gate 28647c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_NOT_HEALTHY: 28657c478bd9Sstevel@tonic-gate /* 28667c478bd9Sstevel@tonic-gate * HEALTHY# signal on this slot is not OK. 28677c478bd9Sstevel@tonic-gate */ 28687c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): HEALTHY# signal is not OK" 28697c478bd9Sstevel@tonic-gate " for this slot %s", 28707c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 28717c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 28727c478bd9Sstevel@tonic-gate slotinfop->name)); 28737c478bd9Sstevel@tonic-gate 28747c478bd9Sstevel@tonic-gate /* record the state in slot_flags field */ 28757c478bd9Sstevel@tonic-gate slotinfop->slot_flags |= PCIHP_SLOT_NOT_HEALTHY; 28767c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_FAILED; 28777c478bd9Sstevel@tonic-gate 28787c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 28797c478bd9Sstevel@tonic-gate 28807c478bd9Sstevel@tonic-gate break; 28817c478bd9Sstevel@tonic-gate 28827c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_HEALTHY_OK: 28837c478bd9Sstevel@tonic-gate /* 28847c478bd9Sstevel@tonic-gate * HEALTHY# signal on this slot is OK now. 28857c478bd9Sstevel@tonic-gate */ 28867c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): HEALTHY# signal is OK now" 28877c478bd9Sstevel@tonic-gate " for this slot %s", 28887c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 28897c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 28907c478bd9Sstevel@tonic-gate slotinfop->name)); 28917c478bd9Sstevel@tonic-gate 28927c478bd9Sstevel@tonic-gate /* update the state in slot_flags field */ 28937c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= ~PCIHP_SLOT_NOT_HEALTHY; 28947c478bd9Sstevel@tonic-gate slotinfop->condition = AP_COND_OK; 28957c478bd9Sstevel@tonic-gate 28967c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 28977c478bd9Sstevel@tonic-gate 28987c478bd9Sstevel@tonic-gate break; 28997c478bd9Sstevel@tonic-gate 290070025d76Sjohnny case HPC_EVENT_SLOT_ATTN: 290170025d76Sjohnny /* 290270025d76Sjohnny * Attention button is pressed. 290370025d76Sjohnny */ 290470025d76Sjohnny if (((slotinfop->slot_flags & PCIHP_SLOT_AUTO_CFG_EN) == 0) || 290570025d76Sjohnny (slotinfop->slot_flags & PCIHP_SLOT_DISABLED)) { 290670025d76Sjohnny /* 290770025d76Sjohnny * either auto-conifiguration or the slot is disabled, 290870025d76Sjohnny * ignore this event. 290970025d76Sjohnny */ 291070025d76Sjohnny break; 291170025d76Sjohnny } 291270025d76Sjohnny 291370025d76Sjohnny if (slotinfop->ostate == AP_OSTATE_UNCONFIGURED) 291470025d76Sjohnny hint = SE_INCOMING_RES; 291570025d76Sjohnny else 291670025d76Sjohnny hint = SE_OUTGOING_RES; 291770025d76Sjohnny 291870025d76Sjohnny if (ddi_getprop(DDI_DEV_T_ANY, pcihp_p->dip, DDI_PROP_DONTPASS, 291970025d76Sjohnny "inkernel-autoconfig", 0) == 0) { 292070025d76Sjohnny pcihp_gen_sysevent(slotinfop->name, PCIHP_DR_REQ, hint, 292170025d76Sjohnny pcihp_p->dip, KM_SLEEP); 292270025d76Sjohnny break; 292370025d76Sjohnny } 292470025d76Sjohnny 292570025d76Sjohnny if ((slotinfop->ostate == AP_OSTATE_UNCONFIGURED) && 292670025d76Sjohnny (slotinfop->rstate != AP_RSTATE_EMPTY) && 292770025d76Sjohnny (slotinfop->condition != AP_COND_FAILED)) { 292870025d76Sjohnny if (slotinfop->rstate == AP_RSTATE_DISCONNECTED) { 292970025d76Sjohnny rv = hpc_nexus_connect(slotinfop->slot_hdl, 293070025d76Sjohnny NULL, 0); 293170025d76Sjohnny if (rv == HPC_SUCCESS) 293270025d76Sjohnny slotinfop->rstate = AP_RSTATE_CONNECTED; 293370025d76Sjohnny else 293470025d76Sjohnny break; 293570025d76Sjohnny } 293670025d76Sjohnny 293770025d76Sjohnny rv = pcihp_configure_ap(pcihp_p, pci_dev); 293870025d76Sjohnny 293970025d76Sjohnny } else if ((slotinfop->ostate == AP_OSTATE_CONFIGURED) && 294070025d76Sjohnny (slotinfop->rstate == AP_RSTATE_CONNECTED) && 294170025d76Sjohnny (slotinfop->condition != AP_COND_FAILED)) { 294270025d76Sjohnny rv = pcihp_unconfigure_ap(pcihp_p, pci_dev); 294370025d76Sjohnny 294470025d76Sjohnny if (rv != HPC_SUCCESS) 294570025d76Sjohnny break; 294670025d76Sjohnny 294770025d76Sjohnny rv = hpc_nexus_disconnect(slotinfop->slot_hdl, 294870025d76Sjohnny NULL, 0); 294970025d76Sjohnny if (rv == HPC_SUCCESS) 295070025d76Sjohnny slotinfop->rstate = AP_RSTATE_DISCONNECTED; 295170025d76Sjohnny } 295270025d76Sjohnny 295370025d76Sjohnny break; 295470025d76Sjohnny 295570025d76Sjohnny case HPC_EVENT_SLOT_POWER_FAULT: 295670025d76Sjohnny /* 295770025d76Sjohnny * Power fault is detected. 295870025d76Sjohnny */ 295970025d76Sjohnny cmn_err(CE_NOTE, "pcihp (%s%d): power-fault" 296070025d76Sjohnny " for this slot %s", 296170025d76Sjohnny ddi_driver_name(pcihp_p->dip), 296270025d76Sjohnny ddi_get_instance(pcihp_p->dip), 296370025d76Sjohnny slotinfop->name); 296470025d76Sjohnny 29654eacc763Sjj156685 /* turn on ATTN led */ 29664eacc763Sjj156685 led_info.led = HPC_ATTN_LED; 29674eacc763Sjj156685 led_info.state = HPC_LED_ON; 29684eacc763Sjj156685 rv = hpc_nexus_control(slotinfop->slot_hdl, 29694eacc763Sjj156685 HPC_CTRL_SET_LED_STATE, (caddr_t)&led_info); 29704eacc763Sjj156685 2971f94c6026Sjj156685 if (slotinfop->rstate == AP_RSTATE_CONNECTED) 2972f94c6026Sjj156685 (void) hpc_nexus_disconnect(slotinfop->slot_hdl, 2973f94c6026Sjj156685 NULL, 0); 2974f94c6026Sjj156685 297570025d76Sjohnny slotinfop->condition = AP_COND_FAILED; 297670025d76Sjohnny 297770025d76Sjohnny pcihp_gen_sysevent(slotinfop->name, PCIHP_DR_AP_STATE_CHANGE, 297870025d76Sjohnny SE_NO_HINT, pcihp_p->dip, KM_SLEEP); 297970025d76Sjohnny 298070025d76Sjohnny break; 298170025d76Sjohnny 29827c478bd9Sstevel@tonic-gate default: 29837c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "pcihp (%s%d): unknown event %x" 29847c478bd9Sstevel@tonic-gate " for this slot %s", 29857c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 29867c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), event_mask, 29877c478bd9Sstevel@tonic-gate slotinfop->name); 29887c478bd9Sstevel@tonic-gate 29897c478bd9Sstevel@tonic-gate /* +++ HOOK for RCM to report this hotplug event? +++ */ 29907c478bd9Sstevel@tonic-gate 29917c478bd9Sstevel@tonic-gate break; 29927c478bd9Sstevel@tonic-gate } 29937c478bd9Sstevel@tonic-gate 29947c478bd9Sstevel@tonic-gate mutex_exit(&slotinfop->slot_mutex); 29957c478bd9Sstevel@tonic-gate 29967c478bd9Sstevel@tonic-gate (void) pcihp_get_soft_state(self, PCIHP_DR_SLOT_EXIT, &rval); 29977c478bd9Sstevel@tonic-gate 29987c478bd9Sstevel@tonic-gate return (rv); 29997c478bd9Sstevel@tonic-gate } 30007c478bd9Sstevel@tonic-gate 30017c478bd9Sstevel@tonic-gate /* 30027c478bd9Sstevel@tonic-gate * This function is called to online or offline the devices for an 30037c478bd9Sstevel@tonic-gate * attachment point. If the PCI device number of the node matches 30047c478bd9Sstevel@tonic-gate * with the device number of the specified hot plug slot then 30057c478bd9Sstevel@tonic-gate * the operation is performed. 30067c478bd9Sstevel@tonic-gate */ 30077c478bd9Sstevel@tonic-gate static int 30087c478bd9Sstevel@tonic-gate pcihp_configure(dev_info_t *dip, void *hdl) 30097c478bd9Sstevel@tonic-gate { 30107c478bd9Sstevel@tonic-gate int pci_dev; 30117c478bd9Sstevel@tonic-gate struct pcihp_config_ctrl *ctrl = (struct pcihp_config_ctrl *)hdl; 30127c478bd9Sstevel@tonic-gate int rv; 30137c478bd9Sstevel@tonic-gate pci_regspec_t *pci_rp; 30147c478bd9Sstevel@tonic-gate int length; 30157c478bd9Sstevel@tonic-gate 30167c478bd9Sstevel@tonic-gate /* 30177c478bd9Sstevel@tonic-gate * Get the PCI device number information from the devinfo 30187c478bd9Sstevel@tonic-gate * node. Since the node may not have the address field 30197c478bd9Sstevel@tonic-gate * setup (this is done in the DDI_INITCHILD of the parent) 30207c478bd9Sstevel@tonic-gate * we look up the 'reg' property to decode that information. 30217c478bd9Sstevel@tonic-gate */ 302232d69156Sscarter if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 302332d69156Sscarter "reg", (int **)&pci_rp, (uint_t *)&length) != DDI_PROP_SUCCESS) { 30247c478bd9Sstevel@tonic-gate ctrl->rv = DDI_FAILURE; 30257c478bd9Sstevel@tonic-gate ctrl->dip = dip; 30267c478bd9Sstevel@tonic-gate return (DDI_WALK_TERMINATE); 30277c478bd9Sstevel@tonic-gate } 30287c478bd9Sstevel@tonic-gate 30297c478bd9Sstevel@tonic-gate /* get the pci device id information */ 30307c478bd9Sstevel@tonic-gate pci_dev = PCI_REG_DEV_G(pci_rp->pci_phys_hi); 30317c478bd9Sstevel@tonic-gate 30327c478bd9Sstevel@tonic-gate /* 30337c478bd9Sstevel@tonic-gate * free the memory allocated by ddi_prop_lookup_int_array 30347c478bd9Sstevel@tonic-gate */ 30357c478bd9Sstevel@tonic-gate ddi_prop_free(pci_rp); 30367c478bd9Sstevel@tonic-gate 30377c478bd9Sstevel@tonic-gate /* 30387c478bd9Sstevel@tonic-gate * Match the node for the device number of the slot. 30397c478bd9Sstevel@tonic-gate */ 30407c478bd9Sstevel@tonic-gate if (pci_dev == ctrl->pci_dev) { /* node is a match */ 30417c478bd9Sstevel@tonic-gate if (ctrl->op == PCIHP_ONLINE) { 30427c478bd9Sstevel@tonic-gate /* it is CONFIGURE operation */ 304332d69156Sscarter 304432d69156Sscarter /* skip this device if it is disabled or faulty */ 304532d69156Sscarter if (pcihp_check_status(dip) == B_FALSE) { 304632d69156Sscarter return (DDI_WALK_PRUNECHILD); 304732d69156Sscarter } 304832d69156Sscarter 30497c478bd9Sstevel@tonic-gate rv = ndi_devi_online(dip, NDI_ONLINE_ATTACH|NDI_CONFIG); 30507c478bd9Sstevel@tonic-gate } else { 30517c478bd9Sstevel@tonic-gate /* 30527c478bd9Sstevel@tonic-gate * it is UNCONFIGURE operation. 30537c478bd9Sstevel@tonic-gate */ 30547c478bd9Sstevel@tonic-gate rv = ndi_devi_offline(dip, NDI_UNCONFIG); 30557c478bd9Sstevel@tonic-gate } 30567c478bd9Sstevel@tonic-gate if (rv != NDI_SUCCESS) { 30577c478bd9Sstevel@tonic-gate /* failed to attach/detach the driver(s) */ 30587c478bd9Sstevel@tonic-gate ctrl->rv = rv; 30597c478bd9Sstevel@tonic-gate ctrl->dip = dip; 30607c478bd9Sstevel@tonic-gate /* terminate the search if specified */ 30617c478bd9Sstevel@tonic-gate if (!(ctrl->flags & PCIHP_CFG_CONTINUE)) 30627c478bd9Sstevel@tonic-gate return (DDI_WALK_TERMINATE); 30637c478bd9Sstevel@tonic-gate } 30647c478bd9Sstevel@tonic-gate } 30657c478bd9Sstevel@tonic-gate 30667c478bd9Sstevel@tonic-gate /* 30677c478bd9Sstevel@tonic-gate * continue the walk to the next sibling to look for a match 30687c478bd9Sstevel@tonic-gate * or to find other nodes if this card is a multi-function card. 30697c478bd9Sstevel@tonic-gate */ 30707c478bd9Sstevel@tonic-gate return (DDI_WALK_PRUNECHILD); 30717c478bd9Sstevel@tonic-gate } 30727c478bd9Sstevel@tonic-gate 307332d69156Sscarter /* 307432d69156Sscarter * Check the device for a 'status' property. A conforming device 307532d69156Sscarter * should have a status of "okay", "disabled", "fail", or "fail-xxx". 307632d69156Sscarter * 307732d69156Sscarter * Return FALSE for a conforming device that is disabled or faulted. 307832d69156Sscarter * Return TRUE in every other case. 307932d69156Sscarter */ 308032d69156Sscarter static bool_t 308132d69156Sscarter pcihp_check_status(dev_info_t *dip) 308232d69156Sscarter { 308332d69156Sscarter char *status_prop; 308432d69156Sscarter bool_t rv = B_TRUE; 308532d69156Sscarter 308632d69156Sscarter /* try to get the 'status' property */ 308732d69156Sscarter if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 308832d69156Sscarter "status", &status_prop) == DDI_PROP_SUCCESS) { 308932d69156Sscarter 309032d69156Sscarter /* 309132d69156Sscarter * test if the status is "disabled", "fail", or 309232d69156Sscarter * "fail-xxx". 309332d69156Sscarter */ 309432d69156Sscarter if (strcmp(status_prop, "disabled") == 0) { 309532d69156Sscarter rv = B_FALSE; 309632d69156Sscarter PCIHP_DEBUG((CE_NOTE, 309732d69156Sscarter "pcihp (%s%d): device is in disabled state", 309832d69156Sscarter ddi_driver_name(dip), ddi_get_instance(dip))); 309932d69156Sscarter } else if (strncmp(status_prop, "fail", 4) == 0) { 310032d69156Sscarter rv = B_FALSE; 310132d69156Sscarter cmn_err(CE_WARN, 310232d69156Sscarter "pcihp (%s%d): device is in fault state (%s)", 310332d69156Sscarter ddi_driver_name(dip), ddi_get_instance(dip), 310432d69156Sscarter status_prop); 310532d69156Sscarter } 310632d69156Sscarter 310732d69156Sscarter ddi_prop_free(status_prop); 310832d69156Sscarter } 310932d69156Sscarter 311032d69156Sscarter return (rv); 311132d69156Sscarter } 311232d69156Sscarter 31137c478bd9Sstevel@tonic-gate /* control structure used to find a device in the devinfo tree */ 31147c478bd9Sstevel@tonic-gate struct pcihp_find_ctrl { 31157c478bd9Sstevel@tonic-gate uint_t device; 31167c478bd9Sstevel@tonic-gate uint_t function; 31177c478bd9Sstevel@tonic-gate dev_info_t *dip; 31187c478bd9Sstevel@tonic-gate }; 31197c478bd9Sstevel@tonic-gate 31207c478bd9Sstevel@tonic-gate static dev_info_t * 31217c478bd9Sstevel@tonic-gate pcihp_devi_find(dev_info_t *dip, uint_t device, uint_t function) 31227c478bd9Sstevel@tonic-gate { 31237c478bd9Sstevel@tonic-gate struct pcihp_find_ctrl ctrl; 31247c478bd9Sstevel@tonic-gate int circular_count; 31257c478bd9Sstevel@tonic-gate 31267c478bd9Sstevel@tonic-gate ctrl.device = device; 31277c478bd9Sstevel@tonic-gate ctrl.function = function; 31287c478bd9Sstevel@tonic-gate ctrl.dip = NULL; 31297c478bd9Sstevel@tonic-gate 31307c478bd9Sstevel@tonic-gate ndi_devi_enter(dip, &circular_count); 31317c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_get_child(dip), pcihp_match_dev, (void *)&ctrl); 31327c478bd9Sstevel@tonic-gate ndi_devi_exit(dip, circular_count); 31337c478bd9Sstevel@tonic-gate 31347c478bd9Sstevel@tonic-gate return (ctrl.dip); 31357c478bd9Sstevel@tonic-gate } 31367c478bd9Sstevel@tonic-gate 31377c478bd9Sstevel@tonic-gate static int 31387c478bd9Sstevel@tonic-gate pcihp_match_dev(dev_info_t *dip, void *hdl) 31397c478bd9Sstevel@tonic-gate { 31407c478bd9Sstevel@tonic-gate struct pcihp_find_ctrl *ctrl = (struct pcihp_find_ctrl *)hdl; 31417c478bd9Sstevel@tonic-gate pci_regspec_t *pci_rp; 31427c478bd9Sstevel@tonic-gate int length; 31437c478bd9Sstevel@tonic-gate int pci_dev; 31447c478bd9Sstevel@tonic-gate int pci_func; 31457c478bd9Sstevel@tonic-gate 314632d69156Sscarter if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 314732d69156Sscarter "reg", (int **)&pci_rp, (uint_t *)&length) != DDI_PROP_SUCCESS) { 31487c478bd9Sstevel@tonic-gate ctrl->dip = NULL; 31497c478bd9Sstevel@tonic-gate return (DDI_WALK_TERMINATE); 31507c478bd9Sstevel@tonic-gate } 31517c478bd9Sstevel@tonic-gate 31527c478bd9Sstevel@tonic-gate /* get the PCI device address info */ 31537c478bd9Sstevel@tonic-gate pci_dev = PCI_REG_DEV_G(pci_rp->pci_phys_hi); 31547c478bd9Sstevel@tonic-gate pci_func = PCI_REG_FUNC_G(pci_rp->pci_phys_hi); 31557c478bd9Sstevel@tonic-gate 31567c478bd9Sstevel@tonic-gate /* 31577c478bd9Sstevel@tonic-gate * free the memory allocated by ddi_prop_lookup_int_array 31587c478bd9Sstevel@tonic-gate */ 31597c478bd9Sstevel@tonic-gate ddi_prop_free(pci_rp); 31607c478bd9Sstevel@tonic-gate 31617c478bd9Sstevel@tonic-gate 31627c478bd9Sstevel@tonic-gate if ((pci_dev == ctrl->device) && (pci_func == ctrl->function)) { 31637c478bd9Sstevel@tonic-gate /* found the match for the specified device address */ 31647c478bd9Sstevel@tonic-gate ctrl->dip = dip; 31657c478bd9Sstevel@tonic-gate return (DDI_WALK_TERMINATE); 31667c478bd9Sstevel@tonic-gate } 31677c478bd9Sstevel@tonic-gate 31687c478bd9Sstevel@tonic-gate /* 31697c478bd9Sstevel@tonic-gate * continue the walk to the next sibling to look for a match. 31707c478bd9Sstevel@tonic-gate */ 31717c478bd9Sstevel@tonic-gate return (DDI_WALK_PRUNECHILD); 31727c478bd9Sstevel@tonic-gate } 31737c478bd9Sstevel@tonic-gate 31747c478bd9Sstevel@tonic-gate #if 0 31757c478bd9Sstevel@tonic-gate /* 31767c478bd9Sstevel@tonic-gate * Probe the configuration space of the slot to determine the receptacle 31777c478bd9Sstevel@tonic-gate * state. There may not be any devinfo tree created for this slot. 31787c478bd9Sstevel@tonic-gate */ 31797c478bd9Sstevel@tonic-gate static void 31807c478bd9Sstevel@tonic-gate pcihp_probe_slot_state(dev_info_t *dip, int dev, hpc_slot_state_t *rstatep) 31817c478bd9Sstevel@tonic-gate { 31827c478bd9Sstevel@tonic-gate /* XXX FIX IT */ 31837c478bd9Sstevel@tonic-gate } 31847c478bd9Sstevel@tonic-gate #endif 31857c478bd9Sstevel@tonic-gate 31867c478bd9Sstevel@tonic-gate /* 31877c478bd9Sstevel@tonic-gate * This routine is called when a ENUM# assertion is detected for a bus. 31887c478bd9Sstevel@tonic-gate * Since ENUM# may be bussed, the slot that asserted ENUM# may not be known. 31897c478bd9Sstevel@tonic-gate * The HPC Driver passes the handle of a slot that is its best guess. 31907c478bd9Sstevel@tonic-gate * If the best guess slot is the one that asserted ENUM#, the proper handling 31917c478bd9Sstevel@tonic-gate * will be done. If its not, all possible slots will be locked at until 31927c478bd9Sstevel@tonic-gate * one that is asserting ENUM is found. 31937c478bd9Sstevel@tonic-gate * Also, indicate to the HSC to turn on ENUM# after it is serviced, 31947c478bd9Sstevel@tonic-gate * incase if it was disabled by the HSC due to the nature of asynchronous 31957c478bd9Sstevel@tonic-gate * delivery of interrupt by the framework. 31967c478bd9Sstevel@tonic-gate * 31977c478bd9Sstevel@tonic-gate * opcode has the following meanings. 31987c478bd9Sstevel@tonic-gate * PCIHP_CLEAR_ENUM = just clear interrupt and return the PCI device no. if 31997c478bd9Sstevel@tonic-gate * success, else return -1. 32007c478bd9Sstevel@tonic-gate * PCIHP_HANDLE_ENUM = clear interrupt and handle interrupt also. 32017c478bd9Sstevel@tonic-gate * 32027c478bd9Sstevel@tonic-gate */ 32037c478bd9Sstevel@tonic-gate static int 32047c478bd9Sstevel@tonic-gate pcihp_handle_enum(pcihp_t *pcihp_p, int favorite_pci_dev, int opcode, 32057c478bd9Sstevel@tonic-gate int kmflag) 32067c478bd9Sstevel@tonic-gate { 32077c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 32087c478bd9Sstevel@tonic-gate int pci_dev, rc, event_serviced = 0; 32097c478bd9Sstevel@tonic-gate 32107c478bd9Sstevel@tonic-gate /* 32117c478bd9Sstevel@tonic-gate * Handle ENUM# condition for the "favorite" slot first. 32127c478bd9Sstevel@tonic-gate */ 32137c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[favorite_pci_dev]; 32147c478bd9Sstevel@tonic-gate if (slotinfop) { 32157c478bd9Sstevel@tonic-gate /* 32167c478bd9Sstevel@tonic-gate * First try the "favorite" pci device. This is the device 32177c478bd9Sstevel@tonic-gate * associated with the handle passed by the HPC Driver. 32187c478bd9Sstevel@tonic-gate */ 32197c478bd9Sstevel@tonic-gate rc = pcihp_enum_slot(pcihp_p, slotinfop, favorite_pci_dev, 32207c478bd9Sstevel@tonic-gate opcode, kmflag); 32217c478bd9Sstevel@tonic-gate if (rc != HPC_EVENT_UNCLAIMED) { /* indicates success */ 32227c478bd9Sstevel@tonic-gate event_serviced = 1; 32237c478bd9Sstevel@tonic-gate /* This MUST be a non-DEBUG feature. */ 32247c478bd9Sstevel@tonic-gate if (! pcihp_enum_scan_all) { 32257c478bd9Sstevel@tonic-gate return (rc); 32267c478bd9Sstevel@tonic-gate } 32277c478bd9Sstevel@tonic-gate } 32287c478bd9Sstevel@tonic-gate } 32297c478bd9Sstevel@tonic-gate 32307c478bd9Sstevel@tonic-gate /* 32317c478bd9Sstevel@tonic-gate * If ENUM# is implemented as a radial signal, then there is no 32327c478bd9Sstevel@tonic-gate * need to further poll the slots. 32337c478bd9Sstevel@tonic-gate */ 32347c478bd9Sstevel@tonic-gate if (pcihp_p->bus_flags & PCIHP_BUS_ENUM_RADIAL) 32357c478bd9Sstevel@tonic-gate goto enum_service_check; 32367c478bd9Sstevel@tonic-gate 32377c478bd9Sstevel@tonic-gate /* 32387c478bd9Sstevel@tonic-gate * If the "favorite" pci device didn't assert ENUM#, then 32397c478bd9Sstevel@tonic-gate * try the rest. Once we find and handle a device that asserted 32407c478bd9Sstevel@tonic-gate * ENUM#, then we will terminate the walk by returning unless 32417c478bd9Sstevel@tonic-gate * scan-all flag is set. 32427c478bd9Sstevel@tonic-gate */ 32437c478bd9Sstevel@tonic-gate for (pci_dev = 0; pci_dev < PCI_MAX_DEVS; pci_dev++) { 32447c478bd9Sstevel@tonic-gate if (pci_dev != favorite_pci_dev) { 32457c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 32467c478bd9Sstevel@tonic-gate if (slotinfop == NULL) { 32477c478bd9Sstevel@tonic-gate continue; 32487c478bd9Sstevel@tonic-gate } 32497c478bd9Sstevel@tonic-gate /* Only CPCI devices support ENUM# generation. */ 32507c478bd9Sstevel@tonic-gate if (!(slotinfop->slot_type & HPC_SLOT_TYPE_CPCI)) 32517c478bd9Sstevel@tonic-gate continue; 32527c478bd9Sstevel@tonic-gate rc = pcihp_enum_slot(pcihp_p, slotinfop, pci_dev, 32537c478bd9Sstevel@tonic-gate opcode, kmflag); 32547c478bd9Sstevel@tonic-gate if (rc != HPC_EVENT_UNCLAIMED) { 32557c478bd9Sstevel@tonic-gate event_serviced = 1; 32567c478bd9Sstevel@tonic-gate /* This MUST be a non-DEBUG feature. */ 32577c478bd9Sstevel@tonic-gate if (! pcihp_enum_scan_all) 32587c478bd9Sstevel@tonic-gate break; 32597c478bd9Sstevel@tonic-gate } 32607c478bd9Sstevel@tonic-gate } 32617c478bd9Sstevel@tonic-gate } 32627c478bd9Sstevel@tonic-gate 32637c478bd9Sstevel@tonic-gate enum_service_check: 32647c478bd9Sstevel@tonic-gate if (event_serviced) { 32657c478bd9Sstevel@tonic-gate return (rc); 32667c478bd9Sstevel@tonic-gate } 32677c478bd9Sstevel@tonic-gate 32687c478bd9Sstevel@tonic-gate /* No ENUM# event found, Return */ 32697c478bd9Sstevel@tonic-gate return (HPC_EVENT_UNCLAIMED); 32707c478bd9Sstevel@tonic-gate } 32717c478bd9Sstevel@tonic-gate 32727c478bd9Sstevel@tonic-gate /* 32737c478bd9Sstevel@tonic-gate * This routine attempts to handle a possible ENUM# assertion case for a 32747c478bd9Sstevel@tonic-gate * specified slot. This only works for adapters that implement Hot Swap 32757c478bd9Sstevel@tonic-gate * Friendly Silicon. If the slot's HS_CSR is read and it specifies ENUM# 32767c478bd9Sstevel@tonic-gate * has been asserted, either the insertion or removal handlers will be 32777c478bd9Sstevel@tonic-gate * called. 32787c478bd9Sstevel@tonic-gate */ 32797c478bd9Sstevel@tonic-gate static int 32807c478bd9Sstevel@tonic-gate pcihp_enum_slot(pcihp_t *pcihp_p, struct pcihp_slotinfo *slotinfop, int pci_dev, 32817c478bd9Sstevel@tonic-gate int opcode, int kmflag) 32827c478bd9Sstevel@tonic-gate { 32837c478bd9Sstevel@tonic-gate ddi_acc_handle_t handle; 32847c478bd9Sstevel@tonic-gate dev_info_t *dip, *new_child = NULL; 32857c478bd9Sstevel@tonic-gate int result, rv = -1; 32867c478bd9Sstevel@tonic-gate uint8_t hs_csr; 32877c478bd9Sstevel@tonic-gate 32887c478bd9Sstevel@tonic-gate if (pcihp_config_setup(&dip, &handle, &new_child, pci_dev, 32897c478bd9Sstevel@tonic-gate pcihp_p) != DDI_SUCCESS) { 32907c478bd9Sstevel@tonic-gate return (HPC_EVENT_UNCLAIMED); 32917c478bd9Sstevel@tonic-gate } 32927c478bd9Sstevel@tonic-gate 32937c478bd9Sstevel@tonic-gate /* 32947c478bd9Sstevel@tonic-gate * Read the device's HS_CSR. 32957c478bd9Sstevel@tonic-gate */ 32967c478bd9Sstevel@tonic-gate result = pcihp_get_hs_csr(slotinfop, handle, (uint8_t *)&hs_csr); 32977c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): hs_csr = %x, flags = %x", 32987c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), ddi_get_instance(pcihp_p->dip), 32997c478bd9Sstevel@tonic-gate hs_csr, slotinfop->slot_flags)); 33007c478bd9Sstevel@tonic-gate /* 33017c478bd9Sstevel@tonic-gate * we teardown our device map here, because in case of an 33027c478bd9Sstevel@tonic-gate * extraction event, our nodes would be freed and a teardown 33037c478bd9Sstevel@tonic-gate * will cause problems. 33047c478bd9Sstevel@tonic-gate */ 33057c478bd9Sstevel@tonic-gate pcihp_config_teardown(&handle, &new_child, pci_dev, pcihp_p); 33067c478bd9Sstevel@tonic-gate 33077c478bd9Sstevel@tonic-gate if (result == PCIHP_SUCCESS) { 33087c478bd9Sstevel@tonic-gate 33097c478bd9Sstevel@tonic-gate /* If ENUM# is masked, then it is not us. Some other device */ 33107c478bd9Sstevel@tonic-gate if ((hs_csr & HS_CSR_EIM) && (opcode == PCIHP_CLEAR_ENUM)) 33117c478bd9Sstevel@tonic-gate return (HPC_EVENT_UNCLAIMED); 33127c478bd9Sstevel@tonic-gate /* 33137c478bd9Sstevel@tonic-gate * This device supports Full Hot Swap and implements 33147c478bd9Sstevel@tonic-gate * the Hot Swap Control and Status Register. 33157c478bd9Sstevel@tonic-gate */ 33167c478bd9Sstevel@tonic-gate if ((hs_csr & HS_CSR_INS) || 33177c478bd9Sstevel@tonic-gate (slotinfop->slot_flags & PCIHP_SLOT_ENUM_INS_PENDING)) { 33187c478bd9Sstevel@tonic-gate /* handle insertion ENUM */ 33197c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): " 33207c478bd9Sstevel@tonic-gate "Handle Insertion ENUM (INS) " 33217c478bd9Sstevel@tonic-gate "on the bus (for slot %s ?)", 33227c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 33237c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 33247c478bd9Sstevel@tonic-gate slotinfop->name)); 33257c478bd9Sstevel@tonic-gate 33267c478bd9Sstevel@tonic-gate /* 33277c478bd9Sstevel@tonic-gate * generate sysevent 33287c478bd9Sstevel@tonic-gate */ 33297c478bd9Sstevel@tonic-gate 33307c478bd9Sstevel@tonic-gate if (opcode == PCIHP_CLEAR_ENUM) 33317c478bd9Sstevel@tonic-gate pcihp_gen_sysevent(slotinfop->name, 33327c478bd9Sstevel@tonic-gate PCIHP_DR_REQ, 33337c478bd9Sstevel@tonic-gate SE_INCOMING_RES, pcihp_p->dip, 33347c478bd9Sstevel@tonic-gate kmflag); 33357c478bd9Sstevel@tonic-gate 33367c478bd9Sstevel@tonic-gate rv = pcihp_handle_enum_insertion(pcihp_p, pci_dev, 33377c478bd9Sstevel@tonic-gate opcode, kmflag); 33387c478bd9Sstevel@tonic-gate 333932d69156Sscarter } else if ((hs_csr & HS_CSR_EXT) || 334032d69156Sscarter (slotinfop->slot_flags & PCIHP_SLOT_ENUM_EXT_PENDING)) { 33417c478bd9Sstevel@tonic-gate /* handle extraction ENUM */ 33427c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "pcihp (%s%d): " 33437c478bd9Sstevel@tonic-gate "Handle Extraction ENUM (EXT) " 33447c478bd9Sstevel@tonic-gate "on the bus (for slot %s ?)", 33457c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 33467c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), 33477c478bd9Sstevel@tonic-gate slotinfop->name)); 33487c478bd9Sstevel@tonic-gate 33497c478bd9Sstevel@tonic-gate /* 33507c478bd9Sstevel@tonic-gate * generate sysevent 33517c478bd9Sstevel@tonic-gate */ 33527c478bd9Sstevel@tonic-gate 33537c478bd9Sstevel@tonic-gate if (opcode == PCIHP_CLEAR_ENUM) 33547c478bd9Sstevel@tonic-gate pcihp_gen_sysevent(slotinfop->name, 33557c478bd9Sstevel@tonic-gate PCIHP_DR_REQ, 33567c478bd9Sstevel@tonic-gate SE_OUTGOING_RES, 33577c478bd9Sstevel@tonic-gate pcihp_p->dip, 33587c478bd9Sstevel@tonic-gate kmflag); 33597c478bd9Sstevel@tonic-gate 33607c478bd9Sstevel@tonic-gate rv = pcihp_handle_enum_extraction(pcihp_p, pci_dev, 33617c478bd9Sstevel@tonic-gate opcode, kmflag); 33627c478bd9Sstevel@tonic-gate } 33637c478bd9Sstevel@tonic-gate if (opcode == PCIHP_CLEAR_ENUM) { 33647c478bd9Sstevel@tonic-gate if (rv == PCIHP_SUCCESS) 33657c478bd9Sstevel@tonic-gate rv = pci_dev; 33667c478bd9Sstevel@tonic-gate else 33677c478bd9Sstevel@tonic-gate rv = HPC_EVENT_UNCLAIMED; 33687c478bd9Sstevel@tonic-gate } 33697c478bd9Sstevel@tonic-gate } 33707c478bd9Sstevel@tonic-gate 33717c478bd9Sstevel@tonic-gate return (rv); 33727c478bd9Sstevel@tonic-gate } 33737c478bd9Sstevel@tonic-gate 33747c478bd9Sstevel@tonic-gate /* 33757c478bd9Sstevel@tonic-gate * This routine is called when a ENUM# caused by lifting the lever 33767c478bd9Sstevel@tonic-gate * is detected. If the occupant is configured, it will be unconfigured. 33777c478bd9Sstevel@tonic-gate * If the occupant is already unconfigured or is successfully unconfigured, 33787c478bd9Sstevel@tonic-gate * the blue LED on the adapter is illuminated which means its OK to remove. 33797c478bd9Sstevel@tonic-gate * Please note that the lock must be released before invoking the 33807c478bd9Sstevel@tonic-gate * generic AP unconfigure function. 33817c478bd9Sstevel@tonic-gate */ 33827c478bd9Sstevel@tonic-gate static int 33837c478bd9Sstevel@tonic-gate pcihp_handle_enum_extraction(pcihp_t *pcihp_p, int pci_dev, int opcode, 33847c478bd9Sstevel@tonic-gate int kmflag) 33857c478bd9Sstevel@tonic-gate { 33867c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 33877c478bd9Sstevel@tonic-gate int rv = PCIHP_FAILURE; 33887c478bd9Sstevel@tonic-gate 33897c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 33907c478bd9Sstevel@tonic-gate 33917c478bd9Sstevel@tonic-gate /* 33927c478bd9Sstevel@tonic-gate * It was observed that, clearing the EXT bit turned the LED ON. 33937c478bd9Sstevel@tonic-gate * This is a BIG problem in case if the unconfigure operation 33947c478bd9Sstevel@tonic-gate * failed because the board was busy. 33957c478bd9Sstevel@tonic-gate * In order to avoid this confusing situation (LED ON but the board 33967c478bd9Sstevel@tonic-gate * is not unconfigured), we instead decided not to clear EXT but 33977c478bd9Sstevel@tonic-gate * disable further ENUM# from this slot. Disabling ENUM# clears 33987c478bd9Sstevel@tonic-gate * the interrupt. 33997c478bd9Sstevel@tonic-gate * Finally before returning we clear the interrupt and enable 34007c478bd9Sstevel@tonic-gate * ENUM# back again from this slot. 34017c478bd9Sstevel@tonic-gate */ 34027c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_DISABLE_ENUM); 34037c478bd9Sstevel@tonic-gate if (opcode == PCIHP_CLEAR_ENUM) { 34047c478bd9Sstevel@tonic-gate slotinfop->slot_flags |= PCIHP_SLOT_ENUM_EXT_PENDING; 34057c478bd9Sstevel@tonic-gate return (PCIHP_SUCCESS); 34067c478bd9Sstevel@tonic-gate } 34077c478bd9Sstevel@tonic-gate 340870025d76Sjohnny mutex_enter(&slotinfop->slot_mutex); 34097c478bd9Sstevel@tonic-gate rv = pcihp_unconfigure_ap(pcihp_p, pci_dev); 341070025d76Sjohnny mutex_exit(&slotinfop->slot_mutex); 34117c478bd9Sstevel@tonic-gate if (rv != HPC_SUCCESS && rv != EBUSY) { 34127c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "%s%d: PCI device %x Failed on Unconfigure", 34137c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 34147c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), pci_dev); 34157c478bd9Sstevel@tonic-gate } 34167c478bd9Sstevel@tonic-gate if (rv == EBUSY) 34177c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "%s%d: PCI device %x Busy", 34187c478bd9Sstevel@tonic-gate ddi_driver_name(pcihp_p->dip), 34197c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), pci_dev); 34207c478bd9Sstevel@tonic-gate if (rv) { 34217c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 34227c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 34237c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_OFF); 34247c478bd9Sstevel@tonic-gate } 34257c478bd9Sstevel@tonic-gate /* 34267c478bd9Sstevel@tonic-gate * we must clear interrupt in case the unconfigure didn't do it 34277c478bd9Sstevel@tonic-gate * due to a duplicate interrupt. Extraction is success. 34287c478bd9Sstevel@tonic-gate */ 34297c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_SLOT_UNCONFIGURE); 34307c478bd9Sstevel@tonic-gate 34317c478bd9Sstevel@tonic-gate if (!rv) { 34327c478bd9Sstevel@tonic-gate /* 34337c478bd9Sstevel@tonic-gate * Sys Event Notification. 34347c478bd9Sstevel@tonic-gate */ 34357c478bd9Sstevel@tonic-gate pcihp_gen_sysevent(slotinfop->name, PCIHP_DR_AP_STATE_CHANGE, 34367c478bd9Sstevel@tonic-gate SE_HINT_REMOVE, pcihp_p->dip, kmflag); 34377c478bd9Sstevel@tonic-gate } 34387c478bd9Sstevel@tonic-gate 34397c478bd9Sstevel@tonic-gate /* 34407c478bd9Sstevel@tonic-gate * Enable interrupts back from this board. 34417c478bd9Sstevel@tonic-gate * This could potentially be problematic in case if the user is 34427c478bd9Sstevel@tonic-gate * quick enough to extract the board. 34437c478bd9Sstevel@tonic-gate * But we must do it just in case if the switch is closed again. 34447c478bd9Sstevel@tonic-gate */ 34457c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_ENABLE_ENUM); 34467c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= ~PCIHP_SLOT_ENUM_EXT_PENDING; 34477c478bd9Sstevel@tonic-gate return (rv); 34487c478bd9Sstevel@tonic-gate } 34497c478bd9Sstevel@tonic-gate 34507c478bd9Sstevel@tonic-gate /* 34517c478bd9Sstevel@tonic-gate * This routine is called when a ENUM# caused by when an adapter insertion 34527c478bd9Sstevel@tonic-gate * is detected. If the occupant is successfully configured (i.e. PCI resources 34537c478bd9Sstevel@tonic-gate * successfully assigned, the blue LED is left off, otherwise if configuration 34547c478bd9Sstevel@tonic-gate * is not successful, the blue LED is illuminated. 34557c478bd9Sstevel@tonic-gate * Please note that the lock must be released before invoking the 34567c478bd9Sstevel@tonic-gate * generic AP configure function. 34577c478bd9Sstevel@tonic-gate */ 34587c478bd9Sstevel@tonic-gate static int 34597c478bd9Sstevel@tonic-gate pcihp_handle_enum_insertion(pcihp_t *pcihp_p, int pci_dev, int opcode, 34607c478bd9Sstevel@tonic-gate int kmflag) 34617c478bd9Sstevel@tonic-gate { 34627c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 34637c478bd9Sstevel@tonic-gate int rv = PCIHP_FAILURE; 34647c478bd9Sstevel@tonic-gate minor_t ap_minor; 34657c478bd9Sstevel@tonic-gate major_t ap_major; 34667c478bd9Sstevel@tonic-gate 34677c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 34687c478bd9Sstevel@tonic-gate slotinfop->hs_csr_location = 0; 34697c478bd9Sstevel@tonic-gate /* we clear the interrupt here. This is a must here. */ 34707c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_SLOT_CONFIGURE); 34717c478bd9Sstevel@tonic-gate /* 34727c478bd9Sstevel@tonic-gate * disable further interrupt from this board till it is 34737c478bd9Sstevel@tonic-gate * configured. 34747c478bd9Sstevel@tonic-gate */ 34757c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_DISABLE_ENUM); 34767c478bd9Sstevel@tonic-gate if (opcode == PCIHP_CLEAR_ENUM) { 34777c478bd9Sstevel@tonic-gate slotinfop->slot_flags |= PCIHP_SLOT_ENUM_INS_PENDING; 34787c478bd9Sstevel@tonic-gate return (PCIHP_SUCCESS); 34797c478bd9Sstevel@tonic-gate } 34807c478bd9Sstevel@tonic-gate 34817c478bd9Sstevel@tonic-gate if ((slotinfop->slot_flags & PCIHP_SLOT_AUTO_CFG_EN) == 34827c478bd9Sstevel@tonic-gate PCIHP_SLOT_AUTO_CFG_EN) { 348370025d76Sjohnny mutex_enter(&slotinfop->slot_mutex); 34847c478bd9Sstevel@tonic-gate rv = pcihp_configure_ap(pcihp_p, pci_dev); 348570025d76Sjohnny mutex_exit(&slotinfop->slot_mutex); 34867c478bd9Sstevel@tonic-gate if (rv != HPC_SUCCESS) { /* configure failed */ 34877c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "%s%d: PCI device %x Failed on" 34887c478bd9Sstevel@tonic-gate " Configure", ddi_driver_name(pcihp_p->dip), 34897c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), pci_dev); 34907c478bd9Sstevel@tonic-gate if (pcihp_cpci_blue_led) 34917c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, 34927c478bd9Sstevel@tonic-gate HPC_EVENT_SLOT_BLUE_LED_ON); 34937c478bd9Sstevel@tonic-gate } 34947c478bd9Sstevel@tonic-gate 34957c478bd9Sstevel@tonic-gate /* pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_CLEAR_ENUM); */ 34967c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_ENABLE_ENUM); 34977c478bd9Sstevel@tonic-gate 34987c478bd9Sstevel@tonic-gate if (!rv) { 34997c478bd9Sstevel@tonic-gate ap_major = ddi_driver_major(pcihp_p->dip); 35007c478bd9Sstevel@tonic-gate ap_minor = PCIHP_AP_MINOR_NUM( 35017c478bd9Sstevel@tonic-gate ddi_get_instance(pcihp_p->dip), pci_dev); 35027c478bd9Sstevel@tonic-gate pcihp_create_occupant_props(pcihp_p->dip, 35037c478bd9Sstevel@tonic-gate makedevice(ap_major, ap_minor), pci_dev); 35047c478bd9Sstevel@tonic-gate 35057c478bd9Sstevel@tonic-gate /* 35067c478bd9Sstevel@tonic-gate * Sys Event Notification. 35077c478bd9Sstevel@tonic-gate */ 35087c478bd9Sstevel@tonic-gate pcihp_gen_sysevent(slotinfop->name, 35097c478bd9Sstevel@tonic-gate PCIHP_DR_AP_STATE_CHANGE, 35107c478bd9Sstevel@tonic-gate SE_HINT_INSERT, pcihp_p->dip, kmflag); 35117c478bd9Sstevel@tonic-gate } 35127c478bd9Sstevel@tonic-gate 35137c478bd9Sstevel@tonic-gate } else 35147c478bd9Sstevel@tonic-gate rv = PCIHP_SUCCESS; 35157c478bd9Sstevel@tonic-gate slotinfop->slot_flags &= ~PCIHP_SLOT_ENUM_INS_PENDING; 35167c478bd9Sstevel@tonic-gate return (rv); 35177c478bd9Sstevel@tonic-gate } 35187c478bd9Sstevel@tonic-gate 35197c478bd9Sstevel@tonic-gate /* 35207c478bd9Sstevel@tonic-gate * Read the Hot Swap Control and Status Register (HS_CSR) and 35217c478bd9Sstevel@tonic-gate * place the result in the location pointed to be hs_csr. 35227c478bd9Sstevel@tonic-gate */ 35237c478bd9Sstevel@tonic-gate static int 35247c478bd9Sstevel@tonic-gate pcihp_get_hs_csr(struct pcihp_slotinfo *slotinfop, 35257c478bd9Sstevel@tonic-gate ddi_acc_handle_t config_handle, uint8_t *hs_csr) 35267c478bd9Sstevel@tonic-gate { 35277c478bd9Sstevel@tonic-gate if (slotinfop->hs_csr_location == -1) 35287c478bd9Sstevel@tonic-gate return (PCIHP_FAILURE); 35297c478bd9Sstevel@tonic-gate 35307c478bd9Sstevel@tonic-gate if (slotinfop->hs_csr_location == 0) { 35317c478bd9Sstevel@tonic-gate slotinfop->hs_csr_location = 35327c478bd9Sstevel@tonic-gate pcihp_get_hs_csr_location(config_handle); 35337c478bd9Sstevel@tonic-gate 35347c478bd9Sstevel@tonic-gate if (slotinfop->hs_csr_location == -1) 35357c478bd9Sstevel@tonic-gate return (PCIHP_FAILURE); 35367c478bd9Sstevel@tonic-gate } 35377c478bd9Sstevel@tonic-gate *hs_csr = pci_config_get8(config_handle, slotinfop->hs_csr_location); 35387c478bd9Sstevel@tonic-gate return (PCIHP_SUCCESS); 35397c478bd9Sstevel@tonic-gate } 35407c478bd9Sstevel@tonic-gate 35417c478bd9Sstevel@tonic-gate /* 35427c478bd9Sstevel@tonic-gate * Write the Hot Swap Control and Status Register (HS_CSR) with 35437c478bd9Sstevel@tonic-gate * the value being pointed at by hs_csr. 35447c478bd9Sstevel@tonic-gate */ 35457c478bd9Sstevel@tonic-gate static void 35467c478bd9Sstevel@tonic-gate pcihp_set_hs_csr(struct pcihp_slotinfo *slotinfop, 35477c478bd9Sstevel@tonic-gate ddi_acc_handle_t config_handle, uint8_t *hs_csr) 35487c478bd9Sstevel@tonic-gate { 35497c478bd9Sstevel@tonic-gate if (slotinfop->hs_csr_location == -1) 35507c478bd9Sstevel@tonic-gate return; 35517c478bd9Sstevel@tonic-gate if (slotinfop->hs_csr_location == 0) { 35527c478bd9Sstevel@tonic-gate slotinfop->hs_csr_location = 35537c478bd9Sstevel@tonic-gate pcihp_get_hs_csr_location(config_handle); 35547c478bd9Sstevel@tonic-gate if (slotinfop->hs_csr_location == -1) 35557c478bd9Sstevel@tonic-gate return; 35567c478bd9Sstevel@tonic-gate } 35577c478bd9Sstevel@tonic-gate pci_config_put8(config_handle, slotinfop->hs_csr_location, *hs_csr); 35587c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "hs_csr wrote %x, read %x", *hs_csr, 35597c478bd9Sstevel@tonic-gate pci_config_get8(config_handle, slotinfop->hs_csr_location))); 35607c478bd9Sstevel@tonic-gate } 35617c478bd9Sstevel@tonic-gate 35627c478bd9Sstevel@tonic-gate static int 35637c478bd9Sstevel@tonic-gate pcihp_get_hs_csr_location(ddi_acc_handle_t config_handle) 35647c478bd9Sstevel@tonic-gate { 35657c478bd9Sstevel@tonic-gate uint8_t cap_id; 35667c478bd9Sstevel@tonic-gate uint_t cap_id_loc; 35677c478bd9Sstevel@tonic-gate uint16_t status; 35687c478bd9Sstevel@tonic-gate int location = -1; 35697c478bd9Sstevel@tonic-gate #define PCI_STAT_ECP_SUPP 0x10 35707c478bd9Sstevel@tonic-gate 35717c478bd9Sstevel@tonic-gate /* 35727c478bd9Sstevel@tonic-gate * Need to check the Status register for ECP support first. 35737c478bd9Sstevel@tonic-gate * Also please note that for type 1 devices, the 35747c478bd9Sstevel@tonic-gate * offset could change. Should support type 1 next. 35757c478bd9Sstevel@tonic-gate */ 35767c478bd9Sstevel@tonic-gate status = pci_config_get16(config_handle, PCI_CONF_STAT); 35777c478bd9Sstevel@tonic-gate if (!(status & PCI_STAT_ECP_SUPP)) { 35787c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "No Ext Capabilities for device\n")); 35797c478bd9Sstevel@tonic-gate return (-1); 35807c478bd9Sstevel@tonic-gate } 35817c478bd9Sstevel@tonic-gate cap_id_loc = pci_config_get8(config_handle, PCI_CONF_EXTCAP); 35827c478bd9Sstevel@tonic-gate 35837c478bd9Sstevel@tonic-gate /* 35847c478bd9Sstevel@tonic-gate * Walk the list of capabilities, but don't walk past the end 35857c478bd9Sstevel@tonic-gate * of the Configuration Space Header. 35867c478bd9Sstevel@tonic-gate */ 35877c478bd9Sstevel@tonic-gate while ((cap_id_loc) && (cap_id_loc < PCI_CONF_HDR_SIZE)) { 35887c478bd9Sstevel@tonic-gate 35897c478bd9Sstevel@tonic-gate cap_id = pci_config_get8(config_handle, cap_id_loc); 35907c478bd9Sstevel@tonic-gate 35917c478bd9Sstevel@tonic-gate if (cap_id == CPCI_HOTSWAP_CAPID) { 35927c478bd9Sstevel@tonic-gate location = cap_id_loc + PCI_ECP_HS_CSR; 35937c478bd9Sstevel@tonic-gate break; 35947c478bd9Sstevel@tonic-gate } 35957c478bd9Sstevel@tonic-gate cap_id_loc = pci_config_get8(config_handle, 35967c478bd9Sstevel@tonic-gate cap_id_loc + 1); 35977c478bd9Sstevel@tonic-gate } 35987c478bd9Sstevel@tonic-gate return (location); 35997c478bd9Sstevel@tonic-gate } 36007c478bd9Sstevel@tonic-gate 36017c478bd9Sstevel@tonic-gate static int 36027c478bd9Sstevel@tonic-gate pcihp_add_dummy_reg_property(dev_info_t *dip, 36037c478bd9Sstevel@tonic-gate uint_t bus, uint_t device, uint_t func) 36047c478bd9Sstevel@tonic-gate { 36057c478bd9Sstevel@tonic-gate pci_regspec_t dummy_reg; 36067c478bd9Sstevel@tonic-gate 36077c478bd9Sstevel@tonic-gate bzero(&dummy_reg, sizeof (dummy_reg)); 36087c478bd9Sstevel@tonic-gate 36097c478bd9Sstevel@tonic-gate dummy_reg.pci_phys_hi = PCIHP_MAKE_REG_HIGH(bus, device, func, 0); 36107c478bd9Sstevel@tonic-gate 36117c478bd9Sstevel@tonic-gate return (ndi_prop_update_int_array(DDI_DEV_T_NONE, dip, 36127c478bd9Sstevel@tonic-gate "reg", (int *)&dummy_reg, sizeof (pci_regspec_t)/sizeof (int))); 36137c478bd9Sstevel@tonic-gate } 36147c478bd9Sstevel@tonic-gate 36157c478bd9Sstevel@tonic-gate static void 36167c478bd9Sstevel@tonic-gate pcihp_hs_csr_op(pcihp_t *pcihp_p, int pci_dev, int event) 36177c478bd9Sstevel@tonic-gate { 36187c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 36197c478bd9Sstevel@tonic-gate ddi_acc_handle_t config_handle; 36207c478bd9Sstevel@tonic-gate dev_info_t *dip, *new_child = NULL; 36217c478bd9Sstevel@tonic-gate uint8_t hs_csr; 36227c478bd9Sstevel@tonic-gate int result; 36237c478bd9Sstevel@tonic-gate 36247c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 36257c478bd9Sstevel@tonic-gate 36267c478bd9Sstevel@tonic-gate if (pcihp_config_setup(&dip, &config_handle, &new_child, pci_dev, 36277c478bd9Sstevel@tonic-gate pcihp_p) != DDI_SUCCESS) { 36287c478bd9Sstevel@tonic-gate return; 36297c478bd9Sstevel@tonic-gate } 36307c478bd9Sstevel@tonic-gate 36317c478bd9Sstevel@tonic-gate result = pcihp_get_hs_csr(slotinfop, config_handle, (uint8_t *)&hs_csr); 36327c478bd9Sstevel@tonic-gate if ((result != PCIHP_SUCCESS) || (event == -1)) { 36337c478bd9Sstevel@tonic-gate pcihp_config_teardown(&config_handle, &new_child, pci_dev, 36347c478bd9Sstevel@tonic-gate pcihp_p); 36357c478bd9Sstevel@tonic-gate return; 36367c478bd9Sstevel@tonic-gate } 36377c478bd9Sstevel@tonic-gate 36387c478bd9Sstevel@tonic-gate hs_csr &= 0xf; 36397c478bd9Sstevel@tonic-gate switch (event) { 36407c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_BLUE_LED_ON: 36417c478bd9Sstevel@tonic-gate hs_csr |= HS_CSR_LOO; 36427c478bd9Sstevel@tonic-gate break; 36437c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_BLUE_LED_OFF: 36447c478bd9Sstevel@tonic-gate hs_csr &= ~HS_CSR_LOO; 36457c478bd9Sstevel@tonic-gate break; 36467c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_CONFIGURE: 36477c478bd9Sstevel@tonic-gate hs_csr |= HS_CSR_INS; /* clear INS */ 36487c478bd9Sstevel@tonic-gate break; 36497c478bd9Sstevel@tonic-gate case HPC_EVENT_CLEAR_ENUM: 36507c478bd9Sstevel@tonic-gate hs_csr |= (HS_CSR_INS | HS_CSR_EXT); 36517c478bd9Sstevel@tonic-gate break; 36527c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_UNCONFIGURE: 36537c478bd9Sstevel@tonic-gate hs_csr |= HS_CSR_EXT; /* clear EXT */ 36547c478bd9Sstevel@tonic-gate break; 36557c478bd9Sstevel@tonic-gate case HPC_EVENT_ENABLE_ENUM: 36567c478bd9Sstevel@tonic-gate hs_csr &= ~HS_CSR_EIM; 36577c478bd9Sstevel@tonic-gate break; 36587c478bd9Sstevel@tonic-gate case HPC_EVENT_DISABLE_ENUM: 36597c478bd9Sstevel@tonic-gate hs_csr |= HS_CSR_EIM; 36607c478bd9Sstevel@tonic-gate break; 36617c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_NOT_HEALTHY: 36627c478bd9Sstevel@tonic-gate case HPC_EVENT_SLOT_HEALTHY_OK: 36637c478bd9Sstevel@tonic-gate default: 36647c478bd9Sstevel@tonic-gate break; 36657c478bd9Sstevel@tonic-gate } 36667c478bd9Sstevel@tonic-gate pcihp_set_hs_csr(slotinfop, config_handle, (uint8_t *)&hs_csr); 36677c478bd9Sstevel@tonic-gate pcihp_config_teardown(&config_handle, &new_child, pci_dev, pcihp_p); 36687c478bd9Sstevel@tonic-gate } 36697c478bd9Sstevel@tonic-gate 36707c478bd9Sstevel@tonic-gate static int 36717c478bd9Sstevel@tonic-gate pcihp_config_setup(dev_info_t **dip, ddi_acc_handle_t *handle, 36727c478bd9Sstevel@tonic-gate dev_info_t **new_child, int pci_dev, pcihp_t *pcihp_p) 36737c478bd9Sstevel@tonic-gate { 36747c478bd9Sstevel@tonic-gate dev_info_t *pdip = pcihp_p->dip; 36757c478bd9Sstevel@tonic-gate int bus, len, rc = DDI_SUCCESS; 36767c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop; 36777c478bd9Sstevel@tonic-gate hpc_slot_state_t rstate; 36787c478bd9Sstevel@tonic-gate ddi_acc_hdl_t *hp; 367900d0963fSdilpreet pci_bus_range_t pci_bus_range; 36807c478bd9Sstevel@tonic-gate 36817c478bd9Sstevel@tonic-gate slotinfop = &pcihp_p->slotinfo[pci_dev]; 36827c478bd9Sstevel@tonic-gate 36837c478bd9Sstevel@tonic-gate /* 36847c478bd9Sstevel@tonic-gate * If declared failed, don't allow Config operations. 36857c478bd9Sstevel@tonic-gate * Otherwise, if good or failing, it is assumed Ok 36867c478bd9Sstevel@tonic-gate * to get config data. 36877c478bd9Sstevel@tonic-gate */ 36887c478bd9Sstevel@tonic-gate if (slotinfop->condition == AP_COND_FAILED) { 36897c478bd9Sstevel@tonic-gate return (PCIHP_FAILURE); 36907c478bd9Sstevel@tonic-gate } 36917c478bd9Sstevel@tonic-gate /* 36927c478bd9Sstevel@tonic-gate * check to see if there is a hardware present first. 36937c478bd9Sstevel@tonic-gate * If no hardware present, no need to probe this slot. 36947c478bd9Sstevel@tonic-gate * We can do this first probably as a first step towards 36957c478bd9Sstevel@tonic-gate * safeguarding from accidental removal (we don't support it!). 36967c478bd9Sstevel@tonic-gate */ 369732d69156Sscarter if (hpc_nexus_control(slotinfop->slot_hdl, HPC_CTRL_GET_SLOT_STATE, 369832d69156Sscarter (caddr_t)&rstate) != 0) { 36997c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 37007c478bd9Sstevel@tonic-gate } 37017c478bd9Sstevel@tonic-gate 37027c478bd9Sstevel@tonic-gate if (rstate != HPC_SLOT_CONNECTED) { 37037c478bd9Sstevel@tonic-gate /* error. slot must be connected */ 37047c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 37057c478bd9Sstevel@tonic-gate } 37067c478bd9Sstevel@tonic-gate *new_child = NULL; 37077c478bd9Sstevel@tonic-gate 37087c478bd9Sstevel@tonic-gate /* 37097c478bd9Sstevel@tonic-gate * If there is no dip then we need to see if an 37107c478bd9Sstevel@tonic-gate * adapter has just been hot plugged. 37117c478bd9Sstevel@tonic-gate */ 371200d0963fSdilpreet len = sizeof (pci_bus_range_t); 3713a3282898Scth if (ddi_getlongprop_buf(DDI_DEV_T_ANY, pdip, 37147c478bd9Sstevel@tonic-gate 0, "bus-range", 37157c478bd9Sstevel@tonic-gate (caddr_t)&pci_bus_range, &len) != DDI_SUCCESS) { 37167c478bd9Sstevel@tonic-gate 37177c478bd9Sstevel@tonic-gate return (PCIHP_FAILURE); 37187c478bd9Sstevel@tonic-gate } 37197c478bd9Sstevel@tonic-gate 37207c478bd9Sstevel@tonic-gate /* primary bus number of this bus node */ 37217c478bd9Sstevel@tonic-gate bus = pci_bus_range.lo; 37227c478bd9Sstevel@tonic-gate 37237c478bd9Sstevel@tonic-gate if (ndi_devi_alloc(pdip, DEVI_PSEUDO_NEXNAME, 3724fa9e4066Sahrens (pnode_t)DEVI_SID_NODEID, dip) != NDI_SUCCESS) { 37257c478bd9Sstevel@tonic-gate 37267c478bd9Sstevel@tonic-gate PCIHP_DEBUG((CE_NOTE, "Failed to alloc probe node\n")); 37277c478bd9Sstevel@tonic-gate return (PCIHP_FAILURE); 37287c478bd9Sstevel@tonic-gate } 37297c478bd9Sstevel@tonic-gate 37307c478bd9Sstevel@tonic-gate if (pcihp_add_dummy_reg_property(*dip, bus, 37317c478bd9Sstevel@tonic-gate pci_dev, 0) != DDI_SUCCESS) { 37327c478bd9Sstevel@tonic-gate 37337c478bd9Sstevel@tonic-gate (void) ndi_devi_free(*dip); 37347c478bd9Sstevel@tonic-gate return (PCIHP_FAILURE); 37357c478bd9Sstevel@tonic-gate } 37367c478bd9Sstevel@tonic-gate 37377c478bd9Sstevel@tonic-gate /* 37387c478bd9Sstevel@tonic-gate * Probe for a device. Possibly a non (c)PCI board could be sitting 37397c478bd9Sstevel@tonic-gate * here which would never respond to PCI config cycles - in which 37407c478bd9Sstevel@tonic-gate * case we return. Eventually a configure operation would fail. 37417c478bd9Sstevel@tonic-gate */ 37427c478bd9Sstevel@tonic-gate if (pci_config_setup(*dip, handle) != DDI_SUCCESS) { 37437c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Cannot set config space map for" 37447c478bd9Sstevel@tonic-gate " pci device number %d", pci_dev); 37457c478bd9Sstevel@tonic-gate (void) ndi_devi_free(*dip); 37467c478bd9Sstevel@tonic-gate return (PCIHP_FAILURE); 37477c478bd9Sstevel@tonic-gate } 37487c478bd9Sstevel@tonic-gate 37497c478bd9Sstevel@tonic-gate /* 37507c478bd9Sstevel@tonic-gate * See if there is any PCI HW at this location 37517c478bd9Sstevel@tonic-gate * by reading the Vendor ID. If it returns with 0xffff 37527c478bd9Sstevel@tonic-gate * then there is no hardware at this location. 37537c478bd9Sstevel@tonic-gate */ 375470025d76Sjohnny if (pcihp_indirect_map(*dip) == DDI_SUCCESS) { 37557c478bd9Sstevel@tonic-gate if (pci_config_get16(*handle, 0) == 0xffff) { 37567c478bd9Sstevel@tonic-gate pci_config_teardown(handle); 37577c478bd9Sstevel@tonic-gate (void) ndi_devi_free(*dip); 37587c478bd9Sstevel@tonic-gate return (PCIHP_FAILURE); 37597c478bd9Sstevel@tonic-gate } 37607c478bd9Sstevel@tonic-gate } else { 37617c478bd9Sstevel@tonic-gate /* Check if mapping is OK */ 37627c478bd9Sstevel@tonic-gate hp = impl_acc_hdl_get(*handle); 37637c478bd9Sstevel@tonic-gate 37647c478bd9Sstevel@tonic-gate if (ddi_peek16(*dip, (int16_t *)(hp->ah_addr), 37657c478bd9Sstevel@tonic-gate (int16_t *)0) != DDI_SUCCESS) { 37667c478bd9Sstevel@tonic-gate #ifdef DEBUG 37677c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Cannot Map PCI config space for " 37687c478bd9Sstevel@tonic-gate "device number %d", pci_dev); 37697c478bd9Sstevel@tonic-gate #endif 37707c478bd9Sstevel@tonic-gate pci_config_teardown(handle); 37717c478bd9Sstevel@tonic-gate (void) ndi_devi_free(*dip); 37727c478bd9Sstevel@tonic-gate return (PCIHP_FAILURE); 37737c478bd9Sstevel@tonic-gate } 37747c478bd9Sstevel@tonic-gate } 37757c478bd9Sstevel@tonic-gate 37767c478bd9Sstevel@tonic-gate *new_child = *dip; 37777c478bd9Sstevel@tonic-gate return (rc); 37787c478bd9Sstevel@tonic-gate 37797c478bd9Sstevel@tonic-gate } 37807c478bd9Sstevel@tonic-gate 37817c478bd9Sstevel@tonic-gate static void 37827c478bd9Sstevel@tonic-gate pcihp_config_teardown(ddi_acc_handle_t *handle, 37837c478bd9Sstevel@tonic-gate dev_info_t **new_child, int pci_dev, pcihp_t *pcihp_p) 37847c478bd9Sstevel@tonic-gate { 37857c478bd9Sstevel@tonic-gate struct pcihp_slotinfo *slotinfop = &pcihp_p->slotinfo[pci_dev]; 37867c478bd9Sstevel@tonic-gate 37877c478bd9Sstevel@tonic-gate pci_config_teardown(handle); 37887c478bd9Sstevel@tonic-gate if (*new_child) { 37897c478bd9Sstevel@tonic-gate (void) ndi_devi_free(*new_child); 37907c478bd9Sstevel@tonic-gate /* 37917c478bd9Sstevel@tonic-gate * If occupant not configured, reset HS_CSR location 37927c478bd9Sstevel@tonic-gate * so that we reprobe. This covers cases where 37937c478bd9Sstevel@tonic-gate * the receptacle had a status change without a 37947c478bd9Sstevel@tonic-gate * notification to the framework. 37957c478bd9Sstevel@tonic-gate */ 37967c478bd9Sstevel@tonic-gate if (slotinfop->ostate != AP_OSTATE_CONFIGURED) 37977c478bd9Sstevel@tonic-gate slotinfop->hs_csr_location = 0; 37987c478bd9Sstevel@tonic-gate } 37997c478bd9Sstevel@tonic-gate } 38007c478bd9Sstevel@tonic-gate 38017c478bd9Sstevel@tonic-gate static int 38027c478bd9Sstevel@tonic-gate pcihp_get_board_type(struct pcihp_slotinfo *slotinfop) 38037c478bd9Sstevel@tonic-gate { 38047c478bd9Sstevel@tonic-gate hpc_board_type_t board_type; 38057c478bd9Sstevel@tonic-gate 38067c478bd9Sstevel@tonic-gate /* 38077c478bd9Sstevel@tonic-gate * Get board type data structure, hpc_board_type_t. 38087c478bd9Sstevel@tonic-gate */ 38097c478bd9Sstevel@tonic-gate if (hpc_nexus_control(slotinfop->slot_hdl, HPC_CTRL_GET_BOARD_TYPE, 38107c478bd9Sstevel@tonic-gate (caddr_t)&board_type) != 0) { 38117c478bd9Sstevel@tonic-gate 38127c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Cannot Get Board Type.."); 38137c478bd9Sstevel@tonic-gate return (-1); 38147c478bd9Sstevel@tonic-gate } 38157c478bd9Sstevel@tonic-gate 38167c478bd9Sstevel@tonic-gate /* 38177c478bd9Sstevel@tonic-gate * We expect the Hotswap Controller to tell us if the board is 38187c478bd9Sstevel@tonic-gate * a hotswap board or not, as it probably cannot differentiate 38197c478bd9Sstevel@tonic-gate * between a basic hotswap board, a non hotswap board and a 38207c478bd9Sstevel@tonic-gate * hotswap nonfriendly board. 38217c478bd9Sstevel@tonic-gate * So here is the logic to differentiate between the various 38227c478bd9Sstevel@tonic-gate * types of cPCI boards. 38237c478bd9Sstevel@tonic-gate * In case if the HSC returns board type as unknown, we assign 38247c478bd9Sstevel@tonic-gate * the default board type as defined by a configurable variable 38257c478bd9Sstevel@tonic-gate * for a BHS, nonfriendly FHS and non HS board. 38267c478bd9Sstevel@tonic-gate */ 38277c478bd9Sstevel@tonic-gate if (slotinfop->slot_type & HPC_SLOT_TYPE_CPCI) { 38287c478bd9Sstevel@tonic-gate if (slotinfop->hs_csr_location > 0) 38297c478bd9Sstevel@tonic-gate board_type = HPC_BOARD_CPCI_FULL_HS; 38307c478bd9Sstevel@tonic-gate else { 38317c478bd9Sstevel@tonic-gate if (board_type == HPC_BOARD_CPCI_HS) { 383232d69156Sscarter if (slotinfop->hs_csr_location == -1) 383332d69156Sscarter board_type = HPC_BOARD_CPCI_BASIC_HS; 38347c478bd9Sstevel@tonic-gate } 38357c478bd9Sstevel@tonic-gate if (board_type == HPC_BOARD_UNKNOWN) { 383632d69156Sscarter if (slotinfop->hs_csr_location == -1) { 383732d69156Sscarter board_type = pcihp_cpci_board_type; 383832d69156Sscarter } else if (slotinfop->hs_csr_location != 0) { 383932d69156Sscarter board_type = HPC_BOARD_CPCI_FULL_HS; 38407c478bd9Sstevel@tonic-gate } 38417c478bd9Sstevel@tonic-gate } 38427c478bd9Sstevel@tonic-gate } 38437c478bd9Sstevel@tonic-gate /* 38447c478bd9Sstevel@tonic-gate * If board type is a non hotswap board, then we must 38457c478bd9Sstevel@tonic-gate * deny a unconfigure operation. So set this flag. 38467c478bd9Sstevel@tonic-gate * Strictly speaking, there is no reason not to disallow 38477c478bd9Sstevel@tonic-gate * a unconfigure operation on nonhotswap boards. But this 38487c478bd9Sstevel@tonic-gate * is the only way we can prevent a user from accidentally 38497c478bd9Sstevel@tonic-gate * removing the board and damaging it. 38507c478bd9Sstevel@tonic-gate */ 38517c478bd9Sstevel@tonic-gate if (board_type == HPC_BOARD_CPCI_NON_HS) 385232d69156Sscarter slotinfop->slot_flags |= PCIHP_SLOT_DEV_NON_HOTPLUG; 38537c478bd9Sstevel@tonic-gate else 385432d69156Sscarter slotinfop->slot_flags &= ~PCIHP_SLOT_DEV_NON_HOTPLUG; 38557c478bd9Sstevel@tonic-gate } 38567c478bd9Sstevel@tonic-gate return (board_type); 38577c478bd9Sstevel@tonic-gate } 38587c478bd9Sstevel@tonic-gate 38597c478bd9Sstevel@tonic-gate 38607c478bd9Sstevel@tonic-gate /* 38617c478bd9Sstevel@tonic-gate * Generate the System Event with a possible hint. 38627c478bd9Sstevel@tonic-gate */ 38637c478bd9Sstevel@tonic-gate static void 38647c478bd9Sstevel@tonic-gate pcihp_gen_sysevent(char *slot_name, int event_sub_class, int hint, 38657c478bd9Sstevel@tonic-gate dev_info_t *self, int kmflag) 38667c478bd9Sstevel@tonic-gate { 38677c478bd9Sstevel@tonic-gate 38687c478bd9Sstevel@tonic-gate int err; 38697c478bd9Sstevel@tonic-gate char *ev_subclass = NULL; 38707c478bd9Sstevel@tonic-gate sysevent_id_t eid; 38717c478bd9Sstevel@tonic-gate nvlist_t *ev_attr_list = NULL; 38727c478bd9Sstevel@tonic-gate char attach_pnt[MAXPATHLEN]; 38737c478bd9Sstevel@tonic-gate 38747c478bd9Sstevel@tonic-gate /* 38757c478bd9Sstevel@tonic-gate * Minor device name (AP) will be bus path 38767c478bd9Sstevel@tonic-gate * concatenated with slot name 38777c478bd9Sstevel@tonic-gate */ 38787c478bd9Sstevel@tonic-gate 38797c478bd9Sstevel@tonic-gate (void) strcpy(attach_pnt, PCIHP_DEVICES_STR); 38807c478bd9Sstevel@tonic-gate (void) ddi_pathname(self, attach_pnt + strlen(PCIHP_DEVICES_STR)); 38817c478bd9Sstevel@tonic-gate (void) strcat(attach_pnt, ":"); 38827c478bd9Sstevel@tonic-gate (void) strcat(attach_pnt, slot_name); 38837c478bd9Sstevel@tonic-gate err = nvlist_alloc(&ev_attr_list, NV_UNIQUE_NAME_TYPE, kmflag); 38847c478bd9Sstevel@tonic-gate if (err != 0) { 38857c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 38867c478bd9Sstevel@tonic-gate "%s%d: Failed to allocate memory " 38877c478bd9Sstevel@tonic-gate "for event attributes%s", ddi_driver_name(self), 38887c478bd9Sstevel@tonic-gate ddi_get_instance(self), ESC_DR_AP_STATE_CHANGE); 38897c478bd9Sstevel@tonic-gate return; 38907c478bd9Sstevel@tonic-gate } 38917c478bd9Sstevel@tonic-gate 38927c478bd9Sstevel@tonic-gate switch (event_sub_class) { 38937c478bd9Sstevel@tonic-gate 38947c478bd9Sstevel@tonic-gate /* event sub class: ESC_DR_AP_STATE_CHANGE */ 38957c478bd9Sstevel@tonic-gate case PCIHP_DR_AP_STATE_CHANGE: 38967c478bd9Sstevel@tonic-gate 38977c478bd9Sstevel@tonic-gate ev_subclass = ESC_DR_AP_STATE_CHANGE; 38987c478bd9Sstevel@tonic-gate 38997c478bd9Sstevel@tonic-gate switch (hint) { 39007c478bd9Sstevel@tonic-gate 39017c478bd9Sstevel@tonic-gate case SE_NO_HINT: /* fall through */ 39027c478bd9Sstevel@tonic-gate case SE_HINT_INSERT: /* fall through */ 39037c478bd9Sstevel@tonic-gate case SE_HINT_REMOVE: 39047c478bd9Sstevel@tonic-gate 39057c478bd9Sstevel@tonic-gate 39067c478bd9Sstevel@tonic-gate err = nvlist_add_string(ev_attr_list, DR_HINT, 39077c478bd9Sstevel@tonic-gate SE_HINT2STR(hint)); 39087c478bd9Sstevel@tonic-gate 39097c478bd9Sstevel@tonic-gate if (err != 0) { 39107c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: Failed to add attr [%s]" 39117c478bd9Sstevel@tonic-gate " for %s event", ddi_driver_name(self), 39127c478bd9Sstevel@tonic-gate ddi_get_instance(self), 39137c478bd9Sstevel@tonic-gate DR_HINT, ESC_DR_AP_STATE_CHANGE); 39147c478bd9Sstevel@tonic-gate nvlist_free(ev_attr_list); 39157c478bd9Sstevel@tonic-gate return; 39167c478bd9Sstevel@tonic-gate } 39177c478bd9Sstevel@tonic-gate break; 39187c478bd9Sstevel@tonic-gate 39197c478bd9Sstevel@tonic-gate default: 39207c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: Unknown hint on sysevent", 39217c478bd9Sstevel@tonic-gate ddi_driver_name(self), ddi_get_instance(self)); 39227c478bd9Sstevel@tonic-gate nvlist_free(ev_attr_list); 39237c478bd9Sstevel@tonic-gate return; 39247c478bd9Sstevel@tonic-gate } 39257c478bd9Sstevel@tonic-gate 39267c478bd9Sstevel@tonic-gate break; 39277c478bd9Sstevel@tonic-gate 39287c478bd9Sstevel@tonic-gate /* event sub class: ESC_DR_REQ */ 39297c478bd9Sstevel@tonic-gate case PCIHP_DR_REQ: 39307c478bd9Sstevel@tonic-gate 39317c478bd9Sstevel@tonic-gate ev_subclass = ESC_DR_REQ; 39327c478bd9Sstevel@tonic-gate 39337c478bd9Sstevel@tonic-gate switch (hint) { 39347c478bd9Sstevel@tonic-gate 39357c478bd9Sstevel@tonic-gate case SE_INVESTIGATE_RES: /* fall through */ 39367c478bd9Sstevel@tonic-gate case SE_INCOMING_RES: /* fall through */ 39377c478bd9Sstevel@tonic-gate case SE_OUTGOING_RES: /* fall through */ 39387c478bd9Sstevel@tonic-gate 39397c478bd9Sstevel@tonic-gate err = nvlist_add_string(ev_attr_list, DR_REQ_TYPE, 39407c478bd9Sstevel@tonic-gate SE_REQ2STR(hint)); 39417c478bd9Sstevel@tonic-gate 39427c478bd9Sstevel@tonic-gate if (err != 0) { 39437c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 39447c478bd9Sstevel@tonic-gate "%s%d: Failed to add attr [%s] " 39457c478bd9Sstevel@tonic-gate "for %s event", ddi_driver_name(self), 39467c478bd9Sstevel@tonic-gate ddi_get_instance(self), 39477c478bd9Sstevel@tonic-gate DR_REQ_TYPE, ESC_DR_REQ); 39487c478bd9Sstevel@tonic-gate nvlist_free(ev_attr_list); 39497c478bd9Sstevel@tonic-gate return; 39507c478bd9Sstevel@tonic-gate } 39517c478bd9Sstevel@tonic-gate break; 39527c478bd9Sstevel@tonic-gate 39537c478bd9Sstevel@tonic-gate default: 395432d69156Sscarter cmn_err(CE_WARN, "%s%d: Unknown hint on sysevent", 39557c478bd9Sstevel@tonic-gate ddi_driver_name(self), ddi_get_instance(self)); 39567c478bd9Sstevel@tonic-gate nvlist_free(ev_attr_list); 39577c478bd9Sstevel@tonic-gate return; 39587c478bd9Sstevel@tonic-gate } 39597c478bd9Sstevel@tonic-gate 39607c478bd9Sstevel@tonic-gate break; 39617c478bd9Sstevel@tonic-gate 39627c478bd9Sstevel@tonic-gate default: 396332d69156Sscarter cmn_err(CE_WARN, "%s%d: Unknown Event subclass", 396432d69156Sscarter ddi_driver_name(self), ddi_get_instance(self)); 39657c478bd9Sstevel@tonic-gate nvlist_free(ev_attr_list); 39667c478bd9Sstevel@tonic-gate return; 39677c478bd9Sstevel@tonic-gate } 39687c478bd9Sstevel@tonic-gate 39697c478bd9Sstevel@tonic-gate /* 39707c478bd9Sstevel@tonic-gate * Add attachment point as attribute (common attribute) 39717c478bd9Sstevel@tonic-gate */ 39727c478bd9Sstevel@tonic-gate 39737c478bd9Sstevel@tonic-gate err = nvlist_add_string(ev_attr_list, DR_AP_ID, attach_pnt); 39747c478bd9Sstevel@tonic-gate 39757c478bd9Sstevel@tonic-gate if (err != 0) { 397632d69156Sscarter cmn_err(CE_WARN, "%s%d: Failed to add attr [%s] for %s event", 39777c478bd9Sstevel@tonic-gate ddi_driver_name(self), ddi_get_instance(self), 39787c478bd9Sstevel@tonic-gate DR_AP_ID, EC_DR); 39797c478bd9Sstevel@tonic-gate nvlist_free(ev_attr_list); 39807c478bd9Sstevel@tonic-gate return; 39817c478bd9Sstevel@tonic-gate } 39827c478bd9Sstevel@tonic-gate 39837c478bd9Sstevel@tonic-gate 39847c478bd9Sstevel@tonic-gate /* 39857c478bd9Sstevel@tonic-gate * Log this event with sysevent framework. 39867c478bd9Sstevel@tonic-gate */ 39877c478bd9Sstevel@tonic-gate 39887c478bd9Sstevel@tonic-gate err = ddi_log_sysevent(self, DDI_VENDOR_SUNW, EC_DR, 39897c478bd9Sstevel@tonic-gate ev_subclass, ev_attr_list, &eid, 39907c478bd9Sstevel@tonic-gate ((kmflag == KM_SLEEP) ? DDI_SLEEP : DDI_NOSLEEP)); 39917c478bd9Sstevel@tonic-gate if (err != 0) { 39927c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: Failed to log %s event", 39937c478bd9Sstevel@tonic-gate ddi_driver_name(self), ddi_get_instance(self), EC_DR); 39947c478bd9Sstevel@tonic-gate } 39957c478bd9Sstevel@tonic-gate 39967c478bd9Sstevel@tonic-gate nvlist_free(ev_attr_list); 39977c478bd9Sstevel@tonic-gate } 39987c478bd9Sstevel@tonic-gate 39997c478bd9Sstevel@tonic-gate int 40007c478bd9Sstevel@tonic-gate pcihp_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, 40017c478bd9Sstevel@tonic-gate int flags, char *name, caddr_t valuep, int *lengthp) 40027c478bd9Sstevel@tonic-gate { 40037c478bd9Sstevel@tonic-gate int pci_dev; 40047c478bd9Sstevel@tonic-gate 40057c478bd9Sstevel@tonic-gate if (dev == DDI_DEV_T_ANY) 40067c478bd9Sstevel@tonic-gate goto skip; 40077c478bd9Sstevel@tonic-gate 40087c478bd9Sstevel@tonic-gate if (strcmp(name, "pci-occupant") == 0) { 40097c478bd9Sstevel@tonic-gate pci_dev = PCIHP_AP_MINOR_NUM_TO_PCI_DEVNUM(getminor(dev)); 4010656d7645SChris Horne pcihp_create_occupant_props(dip, dev, pci_dev); 40117c478bd9Sstevel@tonic-gate } 40127c478bd9Sstevel@tonic-gate /* other cases... */ 40137c478bd9Sstevel@tonic-gate skip: 40147c478bd9Sstevel@tonic-gate return (ddi_prop_op(dev, dip, prop_op, flags, name, valuep, lengthp)); 40157c478bd9Sstevel@tonic-gate } 40167c478bd9Sstevel@tonic-gate 40177c478bd9Sstevel@tonic-gate /* 40187c478bd9Sstevel@tonic-gate * this function is called only for SPARC platforms, where we may have 40197c478bd9Sstevel@tonic-gate * a mix n' match of direct vs indirectly mapped configuration space. 40207c478bd9Sstevel@tonic-gate * On x86, this function should always return success since the configuration 40217c478bd9Sstevel@tonic-gate * space is always indirect mapped. 40227c478bd9Sstevel@tonic-gate */ 40237c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 40247c478bd9Sstevel@tonic-gate static int 40257c478bd9Sstevel@tonic-gate pcihp_indirect_map(dev_info_t *dip) 40267c478bd9Sstevel@tonic-gate { 40277c478bd9Sstevel@tonic-gate #if defined(__sparc) 40287c478bd9Sstevel@tonic-gate int rc = DDI_FAILURE; 40297c478bd9Sstevel@tonic-gate 40307c478bd9Sstevel@tonic-gate if (ddi_prop_get_int(DDI_DEV_T_ANY, ddi_get_parent(dip), 0, 403170025d76Sjohnny PCI_DEV_CONF_MAP_PROP, DDI_FAILURE) != DDI_FAILURE) 40327c478bd9Sstevel@tonic-gate rc = DDI_SUCCESS; 40337c478bd9Sstevel@tonic-gate else 40347c478bd9Sstevel@tonic-gate if (ddi_prop_get_int(DDI_DEV_T_ANY, ddi_get_parent(dip), 403532d69156Sscarter 0, PCI_BUS_CONF_MAP_PROP, DDI_FAILURE) != DDI_FAILURE) 40367c478bd9Sstevel@tonic-gate rc = DDI_SUCCESS; 40377c478bd9Sstevel@tonic-gate return (rc); 40387c478bd9Sstevel@tonic-gate #else 40397c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 40407c478bd9Sstevel@tonic-gate #endif 40417c478bd9Sstevel@tonic-gate } 4042