pcihp.c revision 656d76456fa4392118fe5f8dcb500fd7c1637d84
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* **********************************************************************
* Extension module for PCI nexus drivers to support PCI Hot Plug feature.
*
* DESCRIPTION:
* This module basically implements "devctl" and Attachment Point device
* nodes for hot plug operations. The cb_ops functions needed for access
* to these device nodes are also implemented. For hotplug operations
* on Attachment Points it interacts with the hotplug services (HPS)
* framework. A pci nexus driver would simply call pcihp_init() in its
* attach() function and pcihp_uninit() call in its detach() function.
* **********************************************************************
*/
#include <sys/autoconf.h>
#include <sys/ddi_impldefs.h>
#include <sys/ndi_impldefs.h>
#include <sys/ddipropdefs.h>
#include <sys/pci_impl.h>
#include <sys/sysevent.h>
/*
* NOTE:
*/
/*
* ************************************************************************
* *** Implementation specific data structures/definitions. ***
* ************************************************************************
*/
/* soft state */
typedef enum { PCIHP_SOFT_STATE_CLOSED, PCIHP_SOFT_STATE_OPEN,
/* the following correspond to sysevent defined subclasses */
#define PCIHP_DR_AP_STATE_CHANGE 0
#define PCIHP_DR_REQ 1
/* pcihp_get_soft_state() command argument */
#define PCIHP_DR_NOOP 0
#define PCIHP_DR_BUS_CONFIGURE 1
#define PCIHP_DR_BUS_UNCONFIGURE 2
#define PCIHP_DR_SLOT_ENTER 4
#define PCIHP_DR_SLOT_EXIT 8
/* hot plug bus state */
/*
* Soft state structure associated with each hot plug pci bus instance.
*/
typedef struct pcihp {
/* devinfo pointer to the pci bus node */
/* soft state flags: PCIHP_SOFT_STATE_* */
/* global mutex to serialize exclusive access to the bus */
/* slot information structure */
struct pcihp_slotinfo {
char *name; /* slot logical name */
int hs_csr_location; /* Location of HS_CSR */
/* operations on the slot */
} slotinfo[PCI_MAX_DEVS];
/* misc. bus attributes */
} pcihp_t;
/*
* Bit definitions for slot_flags field:
*
* PCIHP_SLOT_AUTO_CFG_EN This flags is set if nexus can do auto
* configuration of hot plugged card on this slot
* if the hardware reports the hot plug events.
*
* PCIHP_SLOT_DISABLED Slot is disabled for hotplug operations.
*
* PCIHP_SLOT_NOT_HEALTHY HEALTHY# signal is not OK on this slot.
*/
#define PCIHP_SLOT_AUTO_CFG_EN 0x1
#define PCIHP_SLOT_DISABLED 0x2
#define PCIHP_SLOT_NOT_HEALTHY 0x4
#define PCIHP_SLOT_DEV_NON_HOTPLUG 0x8
#define PCIHP_SLOT_ENUM_INS_PENDING 0x10
#define PCIHP_SLOT_ENUM_EXT_PENDING 0x20
/*
* Bit definitions for bus_flags field:
*
* PCIHP_BUS_66MHZ Bus is running at 66Mhz.
*/
#define PCIHP_BUS_66MHZ 0x1
#define PCIHP_BUS_ENUM_RADIAL 0x2
#define PCIHP_DEVICES_STR "/devices"
/*
* control structure for tree walk during configure/unconfigure operation.
*/
struct pcihp_config_ctrl {
int pci_dev; /* PCI device number for the slot */
int op; /* operation: PCIHP_ONLINE or PCIHP_OFFLINE */
int rv; /* return error code */
};
/*
* control flags for configure/unconfigure operations on the tree.
*
* PCIHP_CFG_CONTINUE continue the operation ignoring errors
*/
#define PCIHP_CFG_CONTINUE 0x1
#define PCIHP_ONLINE 1
#define PCIHP_OFFLINE 0
/* Leaf ops (hotplug controls for target devices) */
#ifdef DEBUG
static int pcihp_debug = 0;
#else
#define PCIHP_DEBUG(args)
#define PCIHP_DEBUG2(args)
#endif
/*
* We process ENUM# event one device at a time ie. as soon as we detect
* that a device has the right ENUM# conditions, we return. If the following
* variable is set to non-zero, we scan all the devices on the bus
* for ENUM# conditions.
*/
static int pcihp_enum_scan_all = 0;
/*
* If HSC driver cannot determine the board type (for example: it may not
* be possible to differentiate between a Basic Hotswap, Non Hotswap or
* Non-friendly Full hotswap board), the default board type is assigned
* to be as defined by the following variable.
*/
static int pcihp_cpci_board_type = HPC_BOARD_CPCI_NON_HS;
static int pcihp_cpci_led_blink = 30;
/*
* bit to be set causing an extra interrupt. Although the cPCI specifications
* does not imply this, this behavior is seen with some FHS silicons.
* Until the behavior is confirmed, this flag could be used to enable or
* disable handling the LED.
* 1 means the software must explicitly do the LED behavior.
*/
static int pcihp_cpci_blue_led = 1;
/* static functions */
hpc_slot_info_t *, int);
static int pcihp_configure(dev_info_t *, void *);
uint8_t *);
uint8_t *);
static int pcihp_get_hs_csr_location(ddi_acc_handle_t);
static int pcihp_handle_enum(pcihp_t *, int, int, int);
static void pcihp_hs_csr_op(pcihp_t *, int, int);
static int pcihp_handle_enum_extraction(pcihp_t *, int, int, int);
static int pcihp_handle_enum_insertion(pcihp_t *, int, int, int);
dev_info_t **, int, pcihp_t *);
static void pcihp_config_teardown(ddi_acc_handle_t *,
dev_info_t **, int, pcihp_t *);
static int pcihp_get_board_type(struct pcihp_slotinfo *);
/* sysevent function */
static void pcihp_gen_sysevent(char *, int, int, dev_info_t *, int);
static int pcihp_list_occupants(dev_info_t *, void *);
#if 0
#endif
struct cb_ops pcihp_cb_ops = {
pcihp_open, /* open */
pcihp_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
pcihp_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
pcihp_prop_op, /* cb_prop_op */
NULL, /* streamtab */
CB_REV, /* rev */
nodev, /* int (*cb_aread)() */
nodev /* int (*cb_awrite)() */
};
/*
* local data
*/
static int pci_devlink_flags = 0;
/*
* Module linkage information for the kernel.
*/
extern struct mod_ops mod_miscops;
"PCI nexus hotplug support",
};
static struct modlinkage modlinkage = {
&modlmisc,
};
int
_init(void)
{
int error;
}
return (error);
}
int
_fini(void)
{
return (EBUSY);
}
int
{
}
static pcihp_t *
{
pcihp_p->slots_active = 0;
return (pcihp_p);
}
static void
{
pcihp_t *p;
pp = &pcihp_head;
break;
}
}
}
/*
* This function should be imported by client nexus drivers as their
* devo_getinfo() entry point.
*/
/* ARGSUSED */
int
void *arg,
void **result)
{
int instance;
switch (cmd) {
default:
return (DDI_FAILURE);
case DDI_INFO_DEVT2INSTANCE:
return (DDI_SUCCESS);
case DDI_INFO_DEVT2DEVINFO:
instance) {
return (DDI_SUCCESS);
}
}
return (DDI_FAILURE);
}
}
/*
* This function retrieves the hot plug soft state and performs the
* following primitive commands while the soft state is locked:
* mark the bus unconfigured, increment slot activity, decrement
* slot activity and noop.
*/
/* ARGSUSED */
static pcihp_t *
{
*rv = PCIHP_SUCCESS;
switch (cmd) {
case PCIHP_DR_BUS_UNCONFIGURE:
if (pcihp_p->slots_active == 0)
else
*rv = PCIHP_FAILURE;
break;
case PCIHP_DR_SLOT_ENTER:
*rv = PCIHP_FAILURE;
else
pcihp_p->slots_active++;
break;
case PCIHP_DR_SLOT_EXIT:
if (pcihp_p->slots_active == 0)
"pcihp (%s%d): mismatched slot"
" activity",
else
pcihp_p->slots_active--;
break;
case PCIHP_DR_NOOP:
break;
default:
*rv = PCIHP_FAILURE;
break;
}
return (pcihp_p);
}
}
return (NULL);
}
/* ARGSUSED3 */
static int
{
int pci_dev;
int rv;
/*
* Make sure the open is for the right file type.
*/
return (EINVAL);
/*
* Get the soft state structure.
*/
(void **)&self) != DDI_SUCCESS) {
return (ENXIO);
}
/*
* If the pci_dev is valid then the minor device is an
* AP. Otherwise it is ":devctl" minor device.
*/
if (pci_dev < PCI_MAX_DEVS) {
struct pcihp_slotinfo *slotinfop;
return (ENXIO);
}
}
/*
* Handle the open by tracking the device state.
*
* Note: Needs review w.r.t exclusive access to AP or the bus.
* Currently in the pci plug-in we don't use EXCL open at all
* so the code below implements EXCL access on the bus.
*/
/* enforce exclusive access to the bus */
return (EBUSY);
}
else
return (0);
}
/* ARGSUSED */
static int
{
int rv;
return (EINVAL);
(void **)&self) != DDI_SUCCESS) {
return (ENXIO);
}
return (0);
}
static int
{
int pci_dev;
int length;
/*
* Get the PCI device number information from the devinfo
* node. Since the node may not have the address field
* setup (this is done in the DDI_INITCHILD of the parent)
* we look up the 'reg' property to decode that information.
*/
return (DDI_WALK_TERMINATE);
}
/* get the pci device id information */
/*
* free the memory allocated by ddi_prop_lookup_int_array
*/
/*
* Match the node for the device number of the slot.
*/
/*
* If the node is not yet attached, then don't list it
* as an occupant. This is valid, since nothing can be
* consuming it until it is attached, and cfgadm will
* ask for the property explicitly which will cause it
* to be re-freshed right before checking with rcm.
*/
return (DDI_WALK_PRUNECHILD);
/*
* If we have used all our occupants then print mesage
* and terminate walk.
*/
"pcihp (%s%d): unable to list all occupants",
return (DDI_WALK_TERMINATE);
}
/*
* No need to hold the dip as ddi_walk_devs
* has already arranged that for us.
*/
(void) ddi_pathname(dip,
}
/*
* continue the walk to the next sibling to look for a match
* or to find other nodes if this card is a multi-function card.
*/
return (DDI_WALK_PRUNECHILD);
}
static void
{
struct pcihp_config_ctrl ctrl;
int i;
occupant->i = 0;
(void *)&ctrl);
if (occupant->i == 0) {
/* no occupants right now, need to create stub property */
char *c[] = { "" };
c, 1);
} else {
}
for (i = 0; i < occupant->i; i++) {
}
}
static void
{
int circular;
}
static void
{
!= DDI_PROP_SUCCESS)
return; /* add error handling */
}
/*
* pcihp_ioctl: devctl hotplug controls
*/
/* ARGSUSED */
static int
int *rvalp)
{
struct devctl_iocdata *dcp;
int rv = 0;
int pci_dev;
struct pcihp_slotinfo *slotinfop;
struct hpc_control_data hpc_ctrldata;
struct hpc_led_info led_info;
int state_locking;
int state_unlocking;
int rval;
/*
* read devctl ioctl data before soft state retrieval
*/
if ((cmd != DEVCTL_AP_CONTROL) &&
return (EFAULT);
(void **)&self) != DDI_SUCCESS) {
if (cmd != DEVCTL_AP_CONTROL)
return (ENXIO);
}
switch (cmd) {
case DEVCTL_AP_INSERT:
case DEVCTL_AP_REMOVE:
case DEVCTL_AP_CONNECT:
case DEVCTL_AP_DISCONNECT:
case DEVCTL_AP_CONFIGURE:
case DEVCTL_AP_UNCONFIGURE:
case DEVCTL_AP_GETSTATE:
case DEVCTL_AP_CONTROL:
break;
default:
break;
}
if (rval == PCIHP_FAILURE) {
" while slot activity is requested\n", pathname));
if (cmd != DEVCTL_AP_CONTROL)
return (EBUSY);
}
/*
* For attachment points the lower 8 bits of the minor number is the
* PCI device number.
*/
/*
* We can use the generic implementation for these ioctls
*/
switch (cmd) {
case DEVCTL_DEVICE_GETSTATE:
case DEVCTL_DEVICE_ONLINE:
case DEVCTL_DEVICE_OFFLINE:
case DEVCTL_BUS_GETSTATE:
return (rv);
default:
break;
}
switch (cmd) {
case DEVCTL_DEVICE_RESET:
break;
case DEVCTL_BUS_QUIESCE:
if (bus_state == BUS_QUIESCED)
break;
break;
case DEVCTL_BUS_UNQUIESCE:
if (bus_state == BUS_ACTIVE)
break;
break;
case DEVCTL_BUS_RESET:
break;
case DEVCTL_BUS_RESETALL:
break;
case DEVCTL_AP_CONNECT:
case DEVCTL_AP_DISCONNECT:
/*
* CONNECT(DISCONNECT) the hot plug slot to(from) the bus.
*
* For cPCI slots this operation is a nop so the HPC
* driver may return success if it is a valid operation.
*/
case DEVCTL_AP_INSERT:
case DEVCTL_AP_REMOVE:
/*
*/
/*
* check for valid request:
* 1. It is a hotplug slot.
* 2. The slot has no occupant that is in
* the 'configured' state.
*/
if (pci_dev >= PCI_MAX_DEVS) {
break;
}
break;
}
/* the slot occupant must be in the UNCONFIGURED state */
break;
}
/*
* Call the HPC driver to perform the operation on the slot.
*/
switch (cmd) {
case DEVCTL_AP_INSERT:
break;
case DEVCTL_AP_REMOVE:
break;
case DEVCTL_AP_CONNECT:
if (rv == HPC_SUCCESS) {
else
KM_SLEEP);
}
break;
case DEVCTL_AP_DISCONNECT:
if (rv == HPC_SUCCESS) {
else
KM_SLEEP);
}
break;
}
switch (rv) {
case HPC_ERR_INVALID:
break;
case HPC_ERR_NOTSUPPORTED:
break;
case HPC_ERR_FAILED:
break;
}
break;
case DEVCTL_AP_CONFIGURE:
/*
* **************************************
* CONFIGURE the occupant in the slot.
* **************************************
*/
if (rv == HPC_SUCCESS) {
}
break;
case DEVCTL_AP_UNCONFIGURE:
/*
* **************************************
* UNCONFIGURE the occupant in the slot.
* **************************************
*/
if (rv == HPC_SUCCESS) {
}
break;
case DEVCTL_AP_GETSTATE:
{
int mutex_held;
/*
* return the state of Attachment Point.
*
* If the occupant is in UNCONFIGURED state then
* we should get the receptacle state from the
* HPC driver because the receptacle state
* maintained in the nexus may not be accurate.
*/
/*
* check for valid request:
* 1. It is a hotplug slot.
*/
/* try to acquire the slot mutex */
if (mutex_held) {
}
break;
}
if (mutex_held)
break;
}
}
if (mutex_held)
else
if (mutex_held)
/* copy the return-AP-state information to the user space */
break;
}
case DEVCTL_AP_CONTROL:
/*
* HPC control functions:
* Changes the state of the slot and preserves
* the state across the reboot.
* Enables or disables the auto configuration
* of hot plugged occupant if the hardware
* supports notification of the hot plug
* events.
* Controls the state of an LED.
* HPC_CTRL_GET_SLOT_INFO
* Get slot information data structure
* (hpc_slot_info_t).
* HPC_CTRL_GET_BOARD_TYPE
* Get board type information (hpc_board_type_t).
* HPC_CTRL_GET_CARD_INFO
* Get card information (hpc_card_info_t).
*
* These control functions are used by the cfgadm plug-in
* to implement "-x" and "-v" options.
*/
/* copy user ioctl data first */
case DDI_MODEL_ILP32: {
struct hpc_control32_data hpc_ctrldata32;
sizeof (struct hpc_control32_data)) != 0) {
break;
}
break;
}
case DDI_MODEL_NONE:
sizeof (struct hpc_control_data)) != 0) {
}
break;
default:
break;
}
break;
/*
* check for valid request:
* 1. It is a hotplug slot.
*/
break;
}
switch (hpc_ctrldata.cmd) {
case HPC_CTRL_GET_LED_STATE:
/* copy the led info from the user space */
sizeof (hpc_led_info_t)) != 0) {
break;
}
/* get the state of LED information */
break;
}
/* copy the led info to the user space */
sizeof (hpc_led_info_t)) != 0) {
break;
}
break;
case HPC_CTRL_SET_LED_STATE:
/* copy the led info from the user space */
sizeof (hpc_led_info_t)) != 0) {
break;
}
/* set the state of an LED */
/*
* If the Hotswap Controller does not support
* LED management (as you would find typically
* in the cPCI industry), then we handle the
* case it helps slot identification.
*/
if ((rv == HPC_ERR_NOTSUPPORTED) &&
break;
case HPC_LED_OFF:
rv = 0;
break;
case HPC_LED_ON:
/*
* Please note that leaving
* LED ON could be dangerous
* as it means it is Ok to
* remove the board, which
* is not what we want to
* convey. So it is upto the
* user to take care of this
* situation and usage.
*
* Normally, a Blink command
* is more appropriate for
* identifying a board.
*/
rv = 0;
break;
case HPC_LED_BLINK:
{
int bl;
}
rv = 0;
break;
}
default:
break;
}
}
if (rv == HPC_ERR_FAILED)
break;
case HPC_CTRL_ENABLE_SLOT:
/*
* If slot already enabled, do not send a duplicate
* control message to the HPC driver.
*/
break;
/* tell the HPC driver also */
break;
}
/*
* Enable the slot for hotplug operations.
*/
/* XXX need to preserve this state across reboot? */
break;
case HPC_CTRL_DISABLE_SLOT:
/* Do not disable if occupant configured */
break;
}
/* tell the HPC driver also */
break;
}
/*
* Disable the slot for hotplug operations.
*/
/* XXX need to preserve this state across reboot? */
break;
case HPC_CTRL_ENABLE_AUTOCFG:
/*
* Enable auto configuration on this slot.
*/
/* tell the HPC driver also */
break;
case HPC_CTRL_DISABLE_AUTOCFG:
/*
* Disable auto configuration on this slot.
*/
/* tell the HPC driver also */
break;
case HPC_CTRL_GET_BOARD_TYPE:
{
/*
* Get board type data structure, hpc_board_type_t.
*/
if (board_type == -1) {
break;
}
/* copy the board type info to the user space */
sizeof (hpc_board_type_t)) != 0) {
break;
}
break;
}
case HPC_CTRL_GET_SLOT_INFO:
{
/*
* Get slot information structure, hpc_slot_info_t.
*/
/* copy the slot info structure to the user space */
sizeof (hpc_slot_info_t)) != 0) {
break;
}
break;
}
case HPC_CTRL_GET_CARD_INFO:
{
/*
* Get card information structure, hpc_card_info_t.
*/
/* verify that the card is configured */
/*
* either the card is not present or
* it is not configured.
*/
break;
}
/*
* If declared failed, don't allow Config operations.
* Otherwise, if good or failing, it is assumed Ok
* to get config data.
*/
break;
}
/* get the information from the PCI config header */
/* for the function 0. */
break;
}
/* copy the card info structure to the user space */
sizeof (hpc_card_info_t)) != 0) {
break;
}
break;
}
default:
break;
}
break;
default:
}
if (cmd != DEVCTL_AP_CONTROL)
return (rv);
}
/*
* **************************************
* CONFIGURE the occupant in the slot.
* **************************************
*/
static int
{
int rv = HPC_SUCCESS;
struct pcihp_slotinfo *slotinfop;
struct pcihp_config_ctrl ctrl;
int circular_count;
/*
* check for valid request:
* 1. It is a hotplug slot.
* 2. The receptacle is in the CONNECTED state.
*/
return (ENXIO);
}
/*
* If the occupant is already in (partially?) configured
* state then call the ndi_devi_online() on the device
* subtree(s) for this attachment point.
*/
(void *)&ctrl);
/*
* one or more of the devices are not
* onlined. How is this to be reported?
*/
"pcihp (%s%d): failed to attach one or"
" more drivers for the card in the slot %s",
/* rv = EFAULT; */
}
/* tell HPC driver that the occupant is configured */
else
return (rv);
}
/*
* Occupant is in the UNCONFIGURED state.
*/
/* Check if the receptacle is in the CONNECTED state. */
return (ENXIO);
}
if (rstate == HPC_SLOT_EMPTY) {
/* error. slot is empty */
return (ENXIO);
}
if (rstate != HPC_SLOT_CONNECTED) {
/* error. either the slot is empty or connect failed */
return (ENXIO);
}
/* Turn INS and LED off, and start configuration. */
if (pcihp_cpci_blue_led)
}
/*
* Call the configurator to configure the card.
*/
if (pcihp_cpci_blue_led)
}
/* tell HPC driver occupant configure Error */
return (EIO);
}
/* record the occupant state as CONFIGURED */
/* now, online all the devices in the AP */
/*
* one or more of the devices are not
* ONLINE'd. How is this to be
* reported?
*/
"pcihp (%s%d): failed to attach one or"
" more drivers for the card in the slot %s",
/* rv = EFAULT; */
}
/* store HS_CSR location. No events, jut a read operation. */
/* tell HPC driver that the occupant is configured */
return (rv);
}
/*
* **************************************
* UNCONFIGURE the occupant in the slot.
* **************************************
*/
static int
{
int rv = HPC_SUCCESS;
struct pcihp_slotinfo *slotinfop;
struct pcihp_config_ctrl ctrl;
int circular_count;
/*
* check for valid request:
* 1. It is a hotplug slot.
* 2. The occupant is in the CONFIGURED state.
*/
return (ENXIO);
}
/*
* The following may not need to be there, as we should
* support unconfiguring of boards and free resources
* even when the board is not hotswappable. But this is
* the only way, we may be able to tell the system
* administrator that it is not a hotswap board since
* disconnect operation is never called.
* This way we help the system administrator from not
* accidentally removing a non hotswap board and
* possibly destroying it. May be this behavior can
* be a default, and can be enabled or disabled via
* a global flag.
*/
return (ENOTSUP);
}
}
/*
* If the occupant is in the CONFIGURED state then
* call the configurator to unconfigure the slot.
*/
/*
* since potential state change is imminent mask
* enum events to prevent the slot from being re-configured
*/
/*
* Detach all the drivers for the devices in the
* slot. Call pcihp_configure() to do this.
*/
(void *)&ctrl);
/*
* Failed to detach one or more drivers
* Restore the state of drivers which
* are offlined during this operation.
*/
pcihp_configure, (void *)&ctrl);
/* tell HPC driver that the occupant is Busy */
} else {
if (pcicfg_unconfigure(self,
pci_dev) == PCICFG_SUCCESS) {
/*
* Now that resources are freed,
* clear EXT and Turn LED ON.
*/
if (pcihp_cpci_blue_led)
slotinfop->hs_csr_location = 0;
slotinfop->slot_flags &=
}
/*
* send the notification of state change
* to the HPC driver.
*/
NULL);
} else {
/* tell HPC driver occupant unconfigure Error */
}
}
}
else
/* unmask enum events again */
}
return (rv);
}
/*
* Accessor function to return pointer to the pci hotplug
* cb_ops structure.
*/
struct cb_ops *
{
return (&pcihp_cb_ops);
}
/*
* Setup function to initialize hot plug feature. Returns DDI_SUCCESS
* for successful initialization, otherwise it returns DDI_FAILURE.
*
* It is assumed that this this function is called from the attach()
* entry point of the PCI nexus driver.
*/
int
{
int i;
int enum_size;
int rv;
/*
* Make sure that it is not already initialized.
*/
goto cleanup;
}
/*
* Initialize soft state structure for the bus instance.
*/
goto cleanup;
}
/* XXX if bus is running at 66Mhz then set PCI_BUS_66MHZ bit */
/*
* If a platform wishes to implement Radial ENUM# routing
* a property "enum-impl" must be presented to us with a
* string value "radial".
* This helps us not go for polling operation (default)
* during a ENUM# event.
*/
}
}
for (i = 0; i < PCI_MAX_DEVS; i++) {
/* initialize slot mutex */
MUTEX_DRIVER, NULL);
}
/*
* register the bus instance with the HPS framework.
*/
goto cleanup1;
}
/*
* Create the "devctl" minor for hot plug support. The minor
* number for "devctl" node is in the same format as the AP
* minor nodes.
*/
DDI_NT_NEXUS, 0) != DDI_SUCCESS)
goto cleanup2;
/*
* Setup resource maps for this bus node. (Note: This can
* be done from the attach(9E) of the nexus itself.)
*/
(void) pci_resource_setup(dip);
return (DDI_SUCCESS);
(void) hpc_nexus_unregister_bus(dip);
for (i = 0; i < PCI_MAX_DEVS; i++)
return (DDI_FAILURE);
}
/*
* pcihp_uninit()
*
* The bus instance is going away, cleanup any data associated with
* the management of hot plug slots. It is assumed that this function
* is called from detach() routine of the PCI nexus driver. Also,
* it is assumed that no devices on the bus are in the configured state.
*/
int
{
int i, j;
int rv;
/* get a pointer to the soft state structure */
/* slot mutexes should prevent any configure/unconfigure access */
for (i = 0; i < PCI_MAX_DEVS; i++) {
for (j = 0; j < i; j++) {
}
return (DDI_FAILURE);
}
}
(rv == PCIHP_FAILURE)) {
for (i = 0; i < PCI_MAX_DEVS; i++) {
}
return (DDI_FAILURE);
}
/*
* Unregister the bus with the HPS.
*
* (Note: It is assumed that the HPS framework uninstalls
* event handlers for all the hot plug slots on this bus.)
*/
(void) hpc_nexus_unregister_bus(dip);
/* Free up any kmem_alloc'd memory for slot info table. */
for (i = 0; i < PCI_MAX_DEVS; i++) {
/* free up slot name strings */
}
/* destroy slot mutexes */
for (i = 0; i < PCI_MAX_DEVS; i++)
/* free up the soft state structure */
/*
* Destroy resource maps for this bus node. (Note: This can
* be done from the detach(9E) of the nexus itself.)
*/
(void) pci_resource_destroy(dip);
return (DDI_SUCCESS);
}
/*
* pcihp_new_slot_state()
*
* This function is called by the HPS when it finds a hot plug
* slot is added or being removed from the hot plug framework.
* It returns 0 for success and HPC_ERR_FAILED for errors.
*/
static int
{
struct pcihp_slotinfo *slotinfop;
int pci_dev;
int rv = 0;
int auto_enable = 1;
int rval;
/* get a pointer to the soft state structure */
if (rval == PCIHP_FAILURE) {
" while slot activity is requested\n"));
return (HPC_ERR_FAILED);
}
switch (slot_state) {
case HPC_SLOT_ONLINE:
/*
* Make sure the slot is not already ONLINE (paranoia?).
* (Note: Should this be simply an ASSERTION?)
*/
"pcihp (%s%d): pci slot (dev %x) already ONLINE!!",
pci_dev));
rv = HPC_ERR_FAILED;
break;
}
/*
* Add the hot plug slot to the bus.
*/
/* create the AP minor node */
DDI_NT_PCI_ATTACHMENT_POINT, 0) == DDI_FAILURE) {
"pcihp (%s%d): ddi_create_minor_node failed"
rv = HPC_ERR_FAILED;
break;
}
/* save the slot handle */
/* setup event handler for all hardware events on the slot */
"pcihp (%s%d): install event handler failed"
rv = HPC_ERR_FAILED;
break;
}
/* set default auto configuration enabled flag for this slot */
/* copy the slot information */
slotinfop->hs_csr_location = 0;
auto_enable = 0;
(void) ddi_prop_update_int(DDI_DEV_T_NONE,
}
"pcihp (%s%d): pci slot (dev %x) ONLINE\n",
/*
* The slot may have an occupant that was configured
* at boot time. If we find a devinfo node in the tree
* for this slot (i.e pci device number) then we
* record the occupant state as CONFIGURED.
*/
/* we have a configured occupant */
/* this will set slot flags too. */
(void) pcihp_get_board_type(slotinfop);
if (pcihp_cpci_blue_led)
/* ENUM# enabled by default for cPCI devices */
slotinfop->slot_flags &=
}
/* tell HPC driver that the occupant is configured */
/*
* Tell sysevent listeners that slot has
* changed state. At minimum, this is useful
* when a PCI-E Chassis (containing Occupants) is
* hotplugged. In this case, the following will
* announce that the Occupant in the Receptacle
* in the Chassis had a state-change.
*/
} else {
struct pcihp_config_ctrl ctrl;
int circular_count;
if (!auto_enable) { /* no further action */
break;
}
/*
* We enable power to the slot and try to
* configure if there is any card present.
*
* Note: This case is possible if the BIOS or
* firmware doesn't enable the slots during
* soft reboot.
*/
NULL, 0) != HPC_SUCCESS)
break;
if (pcihp_cpci_blue_led)
slotinfop->slot_flags &=
}
/*
* Call the configurator to configure the card.
*/
if (pcihp_cpci_blue_led)
}
/* tell HPC driver occupant configure Error */
/*
* call HPC driver to turn off the power for
* the slot.
*/
NULL, 0);
} else {
/* record the occupant state as CONFIGURED */
/* now, online all the devices in the AP */
/*
* the following sets slot_flags and
* hs_csr_location too.
*/
(void) pcihp_get_board_type(slotinfop);
pcihp_configure, (void *)&ctrl);
/*
* one or more of the devices are not
* ONLINE'd. How is this to be
* reported?
*/
"pcihp (%s%d): failed to attach"
" one or more drivers for the"
" card in the slot %s",
}
/* tell HPC driver the Occupant is Configured */
/*
* Tell sysevent listeners that slot has
* changed state. At minimum, this is useful
* when a PCI-E Chassis (containing Occupants)
* is hotplugged. In this case, the following
* will announce that the Occupant in the
* Receptacle in the Chassis had a state-change.
*/
}
}
break;
case HPC_SLOT_OFFLINE:
/*
* A hot plug slot is being removed from the bus.
* Make sure there is no occupant configured on the
* slot before removing the AP minor node.
*/
"configured state for pci dev %x",
pci_dev);
rv = HPC_ERR_FAILED;
break;
}
/*
* If the AP device is in open state then return
* error.
*/
rv = HPC_ERR_FAILED;
break;
}
"ap-names", pci_devlink_flags);
}
/* remove the minor node */
/* free up the memory for the name string */
/* update the slot info data */
"pcihp (%s%d): pci slot (dev %x) OFFLINE\n",
slot_info->pci_dev_num));
break;
default:
"pcihp_new_slot_state: unknown slot_state %d", slot_state);
rv = HPC_ERR_FAILED;
}
if (rv == 0) {
else
}
return (rv);
}
/*
* Event handler. It is assumed that this function is called from
* a kernel context only.
*
* Parameters:
* slot_arg AP minor number.
* event_mask Event that occurred.
*/
static int
{
int pci_dev;
int rv = HPC_EVENT_CLAIMED;
struct pcihp_slotinfo *slotinfop;
struct pcihp_config_ctrl ctrl;
int circular_count;
int rval;
int hint;
struct hpc_led_info led_info;
/*
* Get the soft state structure.
*/
(void **)&self) != DDI_SUCCESS)
return (ENXIO);
if (rval == PCIHP_FAILURE) {
" while slot activity is requested\n"));
return (-1);
}
/* get the PCI device number for the slot */
/*
* All the events that may be handled in interrupt context should be
* free of any mutex usage.
*/
switch (event_mask) {
case HPC_EVENT_CLEAR_ENUM:
/*
* Check and clear ENUM# interrupt status. This may be
* called by the Hotswap controller driver when it is
* operating in a full hotswap system where the
* platform may not have control on globally disabling ENUM#.
* In such cases, the intent is to clear interrupt and
* process the interrupt in non-interrupt context.
* This is the first part of the ENUM# event processing.
*/
" on the bus (for slot %s ?)",
/* this is the only event coming through in interrupt context */
return (rv);
default:
break;
}
rv = HPC_ERR_FAILED;
switch (event_mask) {
case HPC_EVENT_SLOT_INSERTION:
/*
* A card is inserted in the slot. Just report this
* event and return.
*/
" in the slot %s (pci dev %x)",
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
case HPC_EVENT_SLOT_CONFIGURE:
/*
* Configure the occupant that is just inserted in the slot.
* The receptacle may or may not be in the connected state. If
* the receptacle is not connected and the auto configuration
* is enabled on this slot then connect the slot. If auto
* configuration is enabled then configure the card.
*/
/*
* auto configuration is disabled. Tell someone
* like RCM about this hotplug event?
*/
" occurred for pci dev %x (slot %s),"
" Slot disabled for auto-configuration.",
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
}
" re-occurred for pci dev %x (slot %s),",
&rval);
return (EAGAIN);
}
/*
* Auto configuration is enabled. First, make sure the
* receptacle is in the CONNECTED state.
*/
NULL, 0)) == HPC_SUCCESS) {
/* record rstate */
}
/* Clear INS and Turn LED Off and start configuring. */
if (pcihp_cpci_blue_led)
}
/*
* Call the configurator to configure the card.
*/
if (pcihp_cpci_blue_led)
}
/* failed to configure the card */
" the card in the slot %s",
/* failed to configure; disconnect the slot */
NULL, 0) == HPC_SUCCESS) {
}
/* tell HPC driver occupant configure Error */
} else {
/* record the occupant state as CONFIGURED */
/* now, online all the devices in the AP */
(void) pcihp_get_board_type(slotinfop);
pcihp_configure, (void *)&ctrl);
/*
* one or more of the devices are not
* ONLINE'd. How is this to be
* reported?
*/
"pcihp (%s%d): failed to attach one or"
" more drivers for the card in"
" the slot %s",
}
/* tell HPC driver that the occupant is configured */
" in the slot %s (pci dev %x)",
}
break;
/*
* Unconfigure the occupant in this slot.
*/
/*
* auto configuration is disabled. Tell someone
* like RCM about this hotplug event?
*/
" for pci dev %x (slot %s) ignored,"
" Slot disabled for auto-configuration.",
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
}
"event re-occurred for pci dev %x (slot %s),",
&rval);
return (EAGAIN);
}
/*
* If the occupant is in the CONFIGURED state then
* call the configurator to unconfigure the slot.
*/
/*
* Detach all the drivers for the devices in the
* slot. Call pcihp_configure() to offline the
* devices.
*/
pcihp_configure, (void *)&ctrl);
/*
* Failed to detach one or more drivers.
* Restore the status for the drivers
* which are offlined during this step.
*/
pcihp_configure, (void *)&ctrl);
rv = HPC_ERR_FAILED;
} else {
pci_dev) == PCICFG_SUCCESS) {
/* Resources freed. Turn LED on. Clear EXT. */
if (pcihp_cpci_blue_led)
slotinfop->hs_csr_location = 0;
slotinfop->slot_flags &=
}
/*
* send the notification of state change
* to the HPC driver.
*/
(void) hpc_nexus_control(
/* disconnect the slot */
if (hpc_nexus_disconnect(
NULL, 0) == HPC_SUCCESS) {
}
"pcihp (%s%d): card is UNCONFIGURED"
" in the slot %s (pci dev %x)",
} else {
/* tell HPC driver occupant is Busy */
(void) hpc_nexus_control(
NULL);
rv = HPC_ERR_FAILED;
}
}
}
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
case HPC_EVENT_SLOT_REMOVAL:
/*
* Card is removed from the slot. The card must have been
* unconfigured before this event.
*/
" from the slot %s",
} else {
" from the slot %s",
}
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
case HPC_EVENT_SLOT_POWER_ON:
/*
* Slot is connected to the bus. i.e the card is powered
* on. Are there any error conditions to be checked?
*/
" on in the slot %s",
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
case HPC_EVENT_SLOT_POWER_OFF:
/*
* Slot is disconnected from the bus. i.e the card is powered
* off. Are there any error conditions to be checked?
*/
" off in the slot %s",
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
/*
* Latch on the slot is closed.
*/
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
/*
* Latch on the slot is open.
*/
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
case HPC_EVENT_PROCESS_ENUM:
/*
* HSC knows the device number of the slot where the
* ENUM# was triggered.
* Now finish the necessary actions to be taken on that
* slot. Please note that the interrupt is already cleared.
* This is the second(last) part of the ENUM# event processing.
*/
" for slot %s",
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
case HPC_EVENT_BUS_ENUM:
/*
* Same as HPC_EVENT_SLOT_ENUM as defined the PSARC doc.
* This term is used for better clarity of its usage.
*
* ENUM signal occurred on the bus. It may be from this
* slot or any other hotplug slot on the bus.
*
* It is NOT recommended that the hotswap controller uses
* event without queuing as NDI and other DDI calls may not
* necessarily be invokable in interrupt context.
* Hence the hotswap controller driver should use the
* CLEAR_ENUM event which returns the slot device number
* and then call HPC_EVENT_PROCESS_ENUM event with queuing.
*
* This can be used when the hotswap controller is
* implementing a polled event mechanism to do the
* necessary actions in a single call.
*/
" on the bus (for slot %s ?)",
KM_SLEEP);
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
/*
* Request to turn Hot Swap Blue LED on.
*/
"LED on the bus (for slot %s ?)",
break;
case HPC_EVENT_DISABLE_ENUM:
/*
* Disable ENUM# which disables auto configuration on this slot
*/
}
break;
case HPC_EVENT_ENABLE_ENUM:
/*
* Enable ENUM# which enables auto configuration on this slot.
*/
}
break;
/*
* Request to turn Hot Swap Blue LED off.
*/
"LED on the bus (for slot %s ?)",
break;
/*
* HEALTHY# signal on this slot is not OK.
*/
" for this slot %s",
/* record the state in slot_flags field */
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
/*
* HEALTHY# signal on this slot is OK now.
*/
" for this slot %s",
/* update the state in slot_flags field */
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
case HPC_EVENT_SLOT_ATTN:
/*
* Attention button is pressed.
*/
/*
* either auto-conifiguration or the slot is disabled,
* ignore this event.
*/
break;
}
else
"inkernel-autoconfig", 0) == 0) {
break;
}
NULL, 0);
if (rv == HPC_SUCCESS)
else
break;
}
if (rv != HPC_SUCCESS)
break;
NULL, 0);
if (rv == HPC_SUCCESS)
}
break;
/*
* Power fault is detected.
*/
" for this slot %s",
/* turn on ATTN led */
NULL, 0);
break;
default:
" for this slot %s",
/* +++ HOOK for RCM to report this hotplug event? +++ */
break;
}
return (rv);
}
/*
* This function is called to online or offline the devices for an
* attachment point. If the PCI device number of the node matches
* with the device number of the specified hot plug slot then
* the operation is performed.
*/
static int
{
int pci_dev;
int rv;
int length;
/*
* Get the PCI device number information from the devinfo
* node. Since the node may not have the address field
* setup (this is done in the DDI_INITCHILD of the parent)
* we look up the 'reg' property to decode that information.
*/
return (DDI_WALK_TERMINATE);
}
/* get the pci device id information */
/*
* free the memory allocated by ddi_prop_lookup_int_array
*/
/*
* Match the node for the device number of the slot.
*/
/* it is CONFIGURE operation */
/* skip this device if it is disabled or faulty */
return (DDI_WALK_PRUNECHILD);
}
} else {
/*
* it is UNCONFIGURE operation.
*/
}
if (rv != NDI_SUCCESS) {
/* terminate the search if specified */
return (DDI_WALK_TERMINATE);
}
}
/*
* continue the walk to the next sibling to look for a match
* or to find other nodes if this card is a multi-function card.
*/
return (DDI_WALK_PRUNECHILD);
}
/*
* Check the device for a 'status' property. A conforming device
* should have a status of "okay", "disabled", "fail", or "fail-xxx".
*
* Return FALSE for a conforming device that is disabled or faulted.
* Return TRUE in every other case.
*/
static bool_t
{
char *status_prop;
/* try to get the 'status' property */
/*
* test if the status is "disabled", "fail", or
* "fail-xxx".
*/
"pcihp (%s%d): device is in disabled state",
"pcihp (%s%d): device is in fault state (%s)",
}
}
return (rv);
}
/* control structure used to find a device in the devinfo tree */
struct pcihp_find_ctrl {
};
static dev_info_t *
{
struct pcihp_find_ctrl ctrl;
int circular_count;
}
static int
{
int length;
int pci_dev;
int pci_func;
return (DDI_WALK_TERMINATE);
}
/* get the PCI device address info */
/*
* free the memory allocated by ddi_prop_lookup_int_array
*/
/* found the match for the specified device address */
return (DDI_WALK_TERMINATE);
}
/*
* continue the walk to the next sibling to look for a match.
*/
return (DDI_WALK_PRUNECHILD);
}
#if 0
/*
* Probe the configuration space of the slot to determine the receptacle
* state. There may not be any devinfo tree created for this slot.
*/
static void
{
/* XXX FIX IT */
}
#endif
/*
* This routine is called when a ENUM# assertion is detected for a bus.
* Since ENUM# may be bussed, the slot that asserted ENUM# may not be known.
* The HPC Driver passes the handle of a slot that is its best guess.
* If the best guess slot is the one that asserted ENUM#, the proper handling
* will be done. If its not, all possible slots will be locked at until
* one that is asserting ENUM is found.
* Also, indicate to the HSC to turn on ENUM# after it is serviced,
* incase if it was disabled by the HSC due to the nature of asynchronous
* delivery of interrupt by the framework.
*
* opcode has the following meanings.
* PCIHP_CLEAR_ENUM = just clear interrupt and return the PCI device no. if
* success, else return -1.
* PCIHP_HANDLE_ENUM = clear interrupt and handle interrupt also.
*
*/
static int
int kmflag)
{
struct pcihp_slotinfo *slotinfop;
/*
* Handle ENUM# condition for the "favorite" slot first.
*/
if (slotinfop) {
/*
* First try the "favorite" pci device. This is the device
* associated with the handle passed by the HPC Driver.
*/
event_serviced = 1;
/* This MUST be a non-DEBUG feature. */
if (! pcihp_enum_scan_all) {
return (rc);
}
}
}
/*
* If ENUM# is implemented as a radial signal, then there is no
* need to further poll the slots.
*/
goto enum_service_check;
/*
* If the "favorite" pci device didn't assert ENUM#, then
* try the rest. Once we find and handle a device that asserted
* ENUM#, then we will terminate the walk by returning unless
* scan-all flag is set.
*/
if (pci_dev != favorite_pci_dev) {
continue;
}
/* Only CPCI devices support ENUM# generation. */
continue;
if (rc != HPC_EVENT_UNCLAIMED) {
event_serviced = 1;
/* This MUST be a non-DEBUG feature. */
if (! pcihp_enum_scan_all)
break;
}
}
}
if (event_serviced) {
return (rc);
}
/* No ENUM# event found, Return */
return (HPC_EVENT_UNCLAIMED);
}
/*
* This routine attempts to handle a possible ENUM# assertion case for a
* specified slot. This only works for adapters that implement Hot Swap
* Friendly Silicon. If the slot's HS_CSR is read and it specifies ENUM#
* has been asserted, either the insertion or removal handlers will be
* called.
*/
static int
{
pcihp_p) != DDI_SUCCESS) {
return (HPC_EVENT_UNCLAIMED);
}
/*
* Read the device's HS_CSR.
*/
/*
* we teardown our device map here, because in case of an
* extraction event, our nodes would be freed and a teardown
* will cause problems.
*/
if (result == PCIHP_SUCCESS) {
/* If ENUM# is masked, then it is not us. Some other device */
return (HPC_EVENT_UNCLAIMED);
/*
* This device supports Full Hot Swap and implements
* the Hot Swap Control and Status Register.
*/
if ((hs_csr & HS_CSR_INS) ||
/* handle insertion ENUM */
"Handle Insertion ENUM (INS) "
"on the bus (for slot %s ?)",
/*
* generate sysevent
*/
if (opcode == PCIHP_CLEAR_ENUM)
kmflag);
} else if ((hs_csr & HS_CSR_EXT) ||
/* handle extraction ENUM */
"Handle Extraction ENUM (EXT) "
"on the bus (for slot %s ?)",
/*
* generate sysevent
*/
if (opcode == PCIHP_CLEAR_ENUM)
kmflag);
}
if (opcode == PCIHP_CLEAR_ENUM) {
if (rv == PCIHP_SUCCESS)
else
}
}
return (rv);
}
/*
* This routine is called when a ENUM# caused by lifting the lever
* is detected. If the occupant is configured, it will be unconfigured.
* If the occupant is already unconfigured or is successfully unconfigured,
* the blue LED on the adapter is illuminated which means its OK to remove.
* Please note that the lock must be released before invoking the
* generic AP unconfigure function.
*/
static int
int kmflag)
{
struct pcihp_slotinfo *slotinfop;
int rv = PCIHP_FAILURE;
/*
* It was observed that, clearing the EXT bit turned the LED ON.
* This is a BIG problem in case if the unconfigure operation
* failed because the board was busy.
* In order to avoid this confusing situation (LED ON but the board
* is not unconfigured), we instead decided not to clear EXT but
* disable further ENUM# from this slot. Disabling ENUM# clears
* the interrupt.
* Finally before returning we clear the interrupt and enable
* ENUM# back again from this slot.
*/
if (opcode == PCIHP_CLEAR_ENUM) {
return (PCIHP_SUCCESS);
}
}
if (rv) {
if (pcihp_cpci_blue_led)
}
/*
* we must clear interrupt in case the unconfigure didn't do it
* due to a duplicate interrupt. Extraction is success.
*/
if (!rv) {
/*
* Sys Event Notification.
*/
}
/*
* Enable interrupts back from this board.
* This could potentially be problematic in case if the user is
* quick enough to extract the board.
* But we must do it just in case if the switch is closed again.
*/
return (rv);
}
/*
* This routine is called when a ENUM# caused by when an adapter insertion
* is detected. If the occupant is successfully configured (i.e. PCI resources
* successfully assigned, the blue LED is left off, otherwise if configuration
* is not successful, the blue LED is illuminated.
* Please note that the lock must be released before invoking the
* generic AP configure function.
*/
static int
int kmflag)
{
struct pcihp_slotinfo *slotinfop;
int rv = PCIHP_FAILURE;
slotinfop->hs_csr_location = 0;
/* we clear the interrupt here. This is a must here. */
/*
* disable further interrupt from this board till it is
* configured.
*/
if (opcode == PCIHP_CLEAR_ENUM) {
return (PCIHP_SUCCESS);
}
if (pcihp_cpci_blue_led)
}
/* pcihp_hs_csr_op(pcihp_p, pci_dev, HPC_EVENT_CLEAR_ENUM); */
if (!rv) {
/*
* Sys Event Notification.
*/
}
} else
rv = PCIHP_SUCCESS;
return (rv);
}
/*
* Read the Hot Swap Control and Status Register (HS_CSR) and
* place the result in the location pointed to be hs_csr.
*/
static int
{
return (PCIHP_FAILURE);
if (slotinfop->hs_csr_location == 0) {
return (PCIHP_FAILURE);
}
return (PCIHP_SUCCESS);
}
/*
* Write the Hot Swap Control and Status Register (HS_CSR) with
* the value being pointed at by hs_csr.
*/
static void
{
return;
if (slotinfop->hs_csr_location == 0) {
return;
}
}
static int
{
int location = -1;
#define PCI_STAT_ECP_SUPP 0x10
/*
* Need to check the Status register for ECP support first.
* Also please note that for type 1 devices, the
* offset could change. Should support type 1 next.
*/
if (!(status & PCI_STAT_ECP_SUPP)) {
return (-1);
}
/*
* Walk the list of capabilities, but don't walk past the end
* of the Configuration Space Header.
*/
if (cap_id == CPCI_HOTSWAP_CAPID) {
break;
}
cap_id_loc + 1);
}
return (location);
}
static int
{
}
static void
{
struct pcihp_slotinfo *slotinfop;
int result;
pcihp_p) != DDI_SUCCESS) {
return;
}
pcihp_p);
return;
}
hs_csr &= 0xf;
switch (event) {
hs_csr |= HS_CSR_LOO;
break;
hs_csr &= ~HS_CSR_LOO;
break;
case HPC_EVENT_SLOT_CONFIGURE:
break;
case HPC_EVENT_CLEAR_ENUM:
break;
break;
case HPC_EVENT_ENABLE_ENUM:
hs_csr &= ~HS_CSR_EIM;
break;
case HPC_EVENT_DISABLE_ENUM:
hs_csr |= HS_CSR_EIM;
break;
default:
break;
}
}
static int
{
struct pcihp_slotinfo *slotinfop;
/*
* If declared failed, don't allow Config operations.
* Otherwise, if good or failing, it is assumed Ok
* to get config data.
*/
return (PCIHP_FAILURE);
}
/*
* check to see if there is a hardware present first.
* If no hardware present, no need to probe this slot.
* We can do this first probably as a first step towards
* safeguarding from accidental removal (we don't support it!).
*/
return (DDI_FAILURE);
}
if (rstate != HPC_SLOT_CONNECTED) {
/* error. slot must be connected */
return (DDI_FAILURE);
}
/*
* If there is no dip then we need to see if an
* adapter has just been hot plugged.
*/
len = sizeof (pci_bus_range_t);
0, "bus-range",
return (PCIHP_FAILURE);
}
/* primary bus number of this bus node */
return (PCIHP_FAILURE);
}
pci_dev, 0) != DDI_SUCCESS) {
(void) ndi_devi_free(*dip);
return (PCIHP_FAILURE);
}
/*
* Probe for a device. Possibly a non (c)PCI board could be sitting
* here which would never respond to PCI config cycles - in which
* case we return. Eventually a configure operation would fail.
*/
" pci device number %d", pci_dev);
(void) ndi_devi_free(*dip);
return (PCIHP_FAILURE);
}
/*
* See if there is any PCI HW at this location
* by reading the Vendor ID. If it returns with 0xffff
* then there is no hardware at this location.
*/
(void) ndi_devi_free(*dip);
return (PCIHP_FAILURE);
}
} else {
/* Check if mapping is OK */
(int16_t *)0) != DDI_SUCCESS) {
#ifdef DEBUG
"device number %d", pci_dev);
#endif
(void) ndi_devi_free(*dip);
return (PCIHP_FAILURE);
}
}
return (rc);
}
static void
{
if (*new_child) {
(void) ndi_devi_free(*new_child);
/*
* If occupant not configured, reset HS_CSR location
* so that we reprobe. This covers cases where
* the receptacle had a status change without a
* notification to the framework.
*/
slotinfop->hs_csr_location = 0;
}
}
static int
{
/*
* Get board type data structure, hpc_board_type_t.
*/
(caddr_t)&board_type) != 0) {
return (-1);
}
/*
* We expect the Hotswap Controller to tell us if the board is
* a hotswap board or not, as it probably cannot differentiate
* between a basic hotswap board, a non hotswap board and a
* hotswap nonfriendly board.
* So here is the logic to differentiate between the various
* types of cPCI boards.
* In case if the HSC returns board type as unknown, we assign
* the default board type as defined by a configurable variable
* for a BHS, nonfriendly FHS and non HS board.
*/
if (slotinfop->hs_csr_location > 0)
else {
if (board_type == HPC_BOARD_CPCI_HS) {
}
if (board_type == HPC_BOARD_UNKNOWN) {
} else if (slotinfop->hs_csr_location != 0) {
}
}
}
/*
* If board type is a non hotswap board, then we must
* deny a unconfigure operation. So set this flag.
* Strictly speaking, there is no reason not to disallow
* a unconfigure operation on nonhotswap boards. But this
* is the only way we can prevent a user from accidentally
* removing the board and damaging it.
*/
if (board_type == HPC_BOARD_CPCI_NON_HS)
else
}
return (board_type);
}
/*
* Generate the System Event with a possible hint.
*/
static void
{
int err;
char *ev_subclass = NULL;
char attach_pnt[MAXPATHLEN];
/*
* Minor device name (AP) will be bus path
* concatenated with slot name
*/
if (err != 0) {
"%s%d: Failed to allocate memory "
return;
}
switch (event_sub_class) {
/* event sub class: ESC_DR_AP_STATE_CHANGE */
case PCIHP_DR_AP_STATE_CHANGE:
switch (hint) {
case SE_NO_HINT: /* fall through */
case SE_HINT_INSERT: /* fall through */
case SE_HINT_REMOVE:
SE_HINT2STR(hint));
if (err != 0) {
return;
}
break;
default:
return;
}
break;
/* event sub class: ESC_DR_REQ */
case PCIHP_DR_REQ:
switch (hint) {
case SE_INVESTIGATE_RES: /* fall through */
case SE_INCOMING_RES: /* fall through */
case SE_OUTGOING_RES: /* fall through */
SE_REQ2STR(hint));
if (err != 0) {
"%s%d: Failed to add attr [%s] "
return;
}
break;
default:
return;
}
break;
default:
return;
}
/*
* Add attachment point as attribute (common attribute)
*/
if (err != 0) {
return;
}
/*
* Log this event with sysevent framework.
*/
if (err != 0) {
}
}
int
{
int pci_dev;
if (dev == DDI_DEV_T_ANY)
goto skip;
}
/* other cases... */
skip:
}
/*
* this function is called only for SPARC platforms, where we may have
* a mix n' match of direct vs indirectly mapped configuration space.
* On x86, this function should always return success since the configuration
* space is always indirect mapped.
*/
/*ARGSUSED*/
static int
{
#if defined(__sparc)
int rc = DDI_FAILURE;
rc = DDI_SUCCESS;
else
rc = DDI_SUCCESS;
return (rc);
#else
return (DDI_SUCCESS);
#endif
}