2018-01-26 23:22:04 +03:00
// SPDX-License-Identifier: GPL-2.0+
2005-04-17 02:20:36 +04:00
/*
* IBM Hot Plug Controller Driver
*
* Written By : Chuck Cole , Jyoti Shah , Tong Yu , Irene Zubarev , IBM Corporation
*
* Copyright ( C ) 2001 , 2003 Greg Kroah - Hartman ( greg @ kroah . com )
* Copyright ( C ) 2001 - 2003 IBM Corp .
*
* All rights reserved .
*
* Send feedback to < gregkh @ us . ibm . com >
*
*/
# include <linux/init.h>
# include <linux/module.h>
# include <linux/slab.h>
# include <linux/pci.h>
# include <linux/interrupt.h>
# include <linux/delay.h>
# include <linux/wait.h>
# include "../pci.h"
2008-12-27 16:02:28 +03:00
# include <asm/pci_x86.h> /* for struct irq_routing_table */
2014-10-27 11:12:04 +03:00
# include <asm/io_apic.h>
2005-04-17 02:20:36 +04:00
# include "ibmphp.h"
2015-12-28 00:21:11 +03:00
# define attn_on(sl) ibmphp_hpc_writeslot(sl, HPC_SLOT_ATTNON)
# define attn_off(sl) ibmphp_hpc_writeslot(sl, HPC_SLOT_ATTNOFF)
# define attn_LED_blink(sl) ibmphp_hpc_writeslot(sl, HPC_SLOT_BLINKLED)
# define get_ctrl_revision(sl, rev) ibmphp_hpc_readslot(sl, READ_REVLEVEL, rev)
# define get_hpc_options(sl, opt) ibmphp_hpc_readslot(sl, READ_HPCOPTIONS, opt)
2005-04-17 02:20:36 +04:00
# define DRIVER_VERSION "0.6"
# define DRIVER_DESC "IBM Hot Plug PCI Controller Driver"
int ibmphp_debug ;
2012-01-13 03:02:20 +04:00
static bool debug ;
2005-04-17 02:20:36 +04:00
module_param ( debug , bool , S_IRUGO | S_IWUSR ) ;
2015-12-28 00:21:11 +03:00
MODULE_PARM_DESC ( debug , " Debugging mode enabled or not " ) ;
MODULE_LICENSE ( " GPL " ) ;
MODULE_DESCRIPTION ( DRIVER_DESC ) ;
2005-04-17 02:20:36 +04:00
struct pci_bus * ibmphp_pci_bus ;
static int max_slots ;
2013-11-14 22:28:18 +04:00
static int irqs [ 16 ] ; /* PIC mode IRQs we're using so far (in case MPS
2005-04-17 02:20:36 +04:00
* tables don ' t provide default info for empty slots */
static int init_flag ;
2013-11-14 22:28:18 +04:00
static inline int get_cur_bus_info ( struct slot * * sl )
2005-04-17 02:20:36 +04:00
{
int rc = 1 ;
2014-04-19 04:13:49 +04:00
struct slot * slot_cur = * sl ;
2005-04-17 02:20:36 +04:00
debug ( " options = %x \n " , slot_cur - > ctrl - > options ) ;
2013-11-14 22:28:18 +04:00
debug ( " revision = %x \n " , slot_cur - > ctrl - > revision ) ;
2005-04-17 02:20:36 +04:00
2013-11-14 22:28:18 +04:00
if ( READ_BUS_STATUS ( slot_cur - > ctrl ) )
2005-04-17 02:20:36 +04:00
rc = ibmphp_hpc_readslot ( slot_cur , READ_BUSSTATUS , NULL ) ;
2013-11-14 22:28:18 +04:00
if ( rc )
2005-04-17 02:20:36 +04:00
return rc ;
2013-11-14 22:28:18 +04:00
2005-04-17 02:20:36 +04:00
slot_cur - > bus_on - > current_speed = CURRENT_BUS_SPEED ( slot_cur - > busstatus ) ;
if ( READ_BUS_MODE ( slot_cur - > ctrl ) )
slot_cur - > bus_on - > current_bus_mode =
CURRENT_BUS_MODE ( slot_cur - > busstatus ) ;
else
slot_cur - > bus_on - > current_bus_mode = 0xFF ;
debug ( " busstatus = %x, bus_speed = %x, bus_mode = %x \n " ,
slot_cur - > busstatus ,
slot_cur - > bus_on - > current_speed ,
slot_cur - > bus_on - > current_bus_mode ) ;
2013-11-14 22:28:18 +04:00
2005-04-17 02:20:36 +04:00
* sl = slot_cur ;
return 0 ;
}
static inline int slot_update ( struct slot * * sl )
{
int rc ;
2013-11-14 22:28:18 +04:00
rc = ibmphp_hpc_readslot ( * sl , READ_ALLSTAT , NULL ) ;
if ( rc )
2005-04-17 02:20:36 +04:00
return rc ;
if ( ! init_flag )
rc = get_cur_bus_info ( sl ) ;
return rc ;
}
2015-12-28 00:21:11 +03:00
static int __init get_max_slots ( void )
2005-04-17 02:20:36 +04:00
{
2014-04-19 04:13:49 +04:00
struct slot * slot_cur ;
2005-04-17 02:20:36 +04:00
u8 slot_count = 0 ;
2015-12-12 16:36:57 +03:00
list_for_each_entry ( slot_cur , & ibmphp_slot_head , ibm_slot_list ) {
2005-04-17 02:20:36 +04:00
/* sometimes the hot-pluggable slots start with 4 (not always from 1) */
slot_count = max ( slot_count , slot_cur - > number ) ;
}
return slot_count ;
}
/* This routine will put the correct slot->device information per slot. It's
* called from initialization of the slot structures . It will also assign
* interrupt numbers per each slot .
* Parameters : struct slot
* Returns 0 or errors
*/
int ibmphp_init_devno ( struct slot * * cur_slot )
{
struct irq_routing_table * rtable ;
int len ;
int loop ;
int i ;
rtable = pcibios_get_irq_routing_table ( ) ;
if ( ! rtable ) {
err ( " no BIOS routing table... \n " ) ;
return - ENOMEM ;
}
len = ( rtable - > size - sizeof ( struct irq_routing_table ) ) /
sizeof ( struct irq_info ) ;
2008-03-22 02:07:13 +03:00
if ( ! len ) {
kfree ( rtable ) ;
2005-04-17 02:20:36 +04:00
return - 1 ;
2008-03-22 02:07:13 +03:00
}
2005-04-17 02:20:36 +04:00
for ( loop = 0 ; loop < len ; loop + + ) {
2009-05-06 21:08:22 +04:00
if ( ( * cur_slot ) - > number = = rtable - > slots [ loop ] . slot & &
( * cur_slot ) - > bus = = rtable - > slots [ loop ] . bus ) {
2005-04-17 02:20:36 +04:00
( * cur_slot ) - > device = PCI_SLOT ( rtable - > slots [ loop ] . devfn ) ;
for ( i = 0 ; i < 4 ; i + + )
( * cur_slot ) - > irq [ i ] = IO_APIC_get_PCI_irq_vector ( ( int ) ( * cur_slot ) - > bus ,
2014-10-27 11:11:54 +03:00
( int ) ( * cur_slot ) - > device , i ) ;
2009-05-06 21:08:22 +04:00
debug ( " (*cur_slot)->irq[0] = %x \n " ,
( * cur_slot ) - > irq [ 0 ] ) ;
debug ( " (*cur_slot)->irq[1] = %x \n " ,
( * cur_slot ) - > irq [ 1 ] ) ;
debug ( " (*cur_slot)->irq[2] = %x \n " ,
( * cur_slot ) - > irq [ 2 ] ) ;
debug ( " (*cur_slot)->irq[3] = %x \n " ,
( * cur_slot ) - > irq [ 3 ] ) ;
2013-11-14 22:28:18 +04:00
debug ( " rtable->exclusive_irqs = %x \n " ,
2005-04-17 02:20:36 +04:00
rtable - > exclusive_irqs ) ;
2009-05-06 21:08:22 +04:00
debug ( " rtable->slots[loop].irq[0].bitmap = %x \n " ,
2005-04-17 02:20:36 +04:00
rtable - > slots [ loop ] . irq [ 0 ] . bitmap ) ;
2009-05-06 21:08:22 +04:00
debug ( " rtable->slots[loop].irq[1].bitmap = %x \n " ,
2005-04-17 02:20:36 +04:00
rtable - > slots [ loop ] . irq [ 1 ] . bitmap ) ;
2009-05-06 21:08:22 +04:00
debug ( " rtable->slots[loop].irq[2].bitmap = %x \n " ,
2005-04-17 02:20:36 +04:00
rtable - > slots [ loop ] . irq [ 2 ] . bitmap ) ;
2009-05-06 21:08:22 +04:00
debug ( " rtable->slots[loop].irq[3].bitmap = %x \n " ,
2005-04-17 02:20:36 +04:00
rtable - > slots [ loop ] . irq [ 3 ] . bitmap ) ;
2009-05-06 21:08:22 +04:00
debug ( " rtable->slots[loop].irq[0].link = %x \n " ,
2005-04-17 02:20:36 +04:00
rtable - > slots [ loop ] . irq [ 0 ] . link ) ;
2009-05-06 21:08:22 +04:00
debug ( " rtable->slots[loop].irq[1].link = %x \n " ,
2005-04-17 02:20:36 +04:00
rtable - > slots [ loop ] . irq [ 1 ] . link ) ;
2009-05-06 21:08:22 +04:00
debug ( " rtable->slots[loop].irq[2].link = %x \n " ,
2005-04-17 02:20:36 +04:00
rtable - > slots [ loop ] . irq [ 2 ] . link ) ;
2009-05-06 21:08:22 +04:00
debug ( " rtable->slots[loop].irq[3].link = %x \n " ,
2005-04-17 02:20:36 +04:00
rtable - > slots [ loop ] . irq [ 3 ] . link ) ;
2009-05-06 21:08:22 +04:00
debug ( " end of init_devno \n " ) ;
kfree ( rtable ) ;
return 0 ;
2005-04-17 02:20:36 +04:00
}
}
2008-03-22 02:07:13 +03:00
kfree ( rtable ) ;
2005-04-17 02:20:36 +04:00
return - 1 ;
}
static inline int power_on ( struct slot * slot_cur )
{
u8 cmd = HPC_SLOT_ON ;
int retval ;
retval = ibmphp_hpc_writeslot ( slot_cur , cmd ) ;
if ( retval ) {
err ( " power on failed \n " ) ;
return retval ;
}
if ( CTLR_RESULT ( slot_cur - > ctrl - > status ) ) {
err ( " command not completed successfully in power_on \n " ) ;
return - EIO ;
}
msleep ( 3000 ) ; /* For ServeRAID cards, and some 66 PCI */
return 0 ;
}
static inline int power_off ( struct slot * slot_cur )
{
u8 cmd = HPC_SLOT_OFF ;
int retval ;
retval = ibmphp_hpc_writeslot ( slot_cur , cmd ) ;
if ( retval ) {
err ( " power off failed \n " ) ;
return retval ;
}
if ( CTLR_RESULT ( slot_cur - > ctrl - > status ) ) {
err ( " command not completed successfully in power_off \n " ) ;
retval = - EIO ;
}
return retval ;
}
static int set_attention_status ( struct hotplug_slot * hotplug_slot , u8 value )
{
int rc = 0 ;
struct slot * pslot ;
2006-01-08 22:11:59 +03:00
u8 cmd = 0x00 ; /* avoid compiler warning */
2005-04-17 02:20:36 +04:00
debug ( " set_attention_status - Entry hotplug_slot[%lx] value[%x] \n " ,
( ulong ) hotplug_slot , value ) ;
ibmphp_lock_operations ( ) ;
2006-01-08 22:11:59 +03:00
2005-04-17 02:20:36 +04:00
if ( hotplug_slot ) {
switch ( value ) {
case HPC_SLOT_ATTN_OFF :
cmd = HPC_SLOT_ATTNOFF ;
break ;
case HPC_SLOT_ATTN_ON :
cmd = HPC_SLOT_ATTNON ;
break ;
case HPC_SLOT_ATTN_BLINK :
cmd = HPC_SLOT_BLINKLED ;
break ;
default :
rc = - ENODEV ;
err ( " set_attention_status - Error : invalid input [%x] \n " ,
value ) ;
break ;
}
if ( rc = = 0 ) {
2018-09-08 10:59:01 +03:00
pslot = to_slot ( hotplug_slot ) ;
rc = ibmphp_hpc_writeslot ( pslot , cmd ) ;
2005-04-17 02:20:36 +04:00
}
2013-11-14 22:28:18 +04:00
} else
2005-04-17 02:20:36 +04:00
rc = - ENODEV ;
ibmphp_unlock_operations ( ) ;
debug ( " set_attention_status - Exit rc[%d] \n " , rc ) ;
return rc ;
}
2014-04-19 04:13:49 +04:00
static int get_attention_status ( struct hotplug_slot * hotplug_slot , u8 * value )
2005-04-17 02:20:36 +04:00
{
int rc = - ENODEV ;
struct slot * pslot ;
struct slot myslot ;
debug ( " get_attention_status - Entry hotplug_slot[%lx] pvalue[%lx] \n " ,
( ulong ) hotplug_slot , ( ulong ) value ) ;
2013-11-14 22:28:18 +04:00
2005-04-17 02:20:36 +04:00
ibmphp_lock_operations ( ) ;
2006-06-01 13:41:44 +04:00
if ( hotplug_slot ) {
2018-09-08 10:59:01 +03:00
pslot = to_slot ( hotplug_slot ) ;
memcpy ( & myslot , pslot , sizeof ( struct slot ) ) ;
rc = ibmphp_hpc_readslot ( pslot , READ_SLOTSTATUS ,
& myslot . status ) ;
if ( ! rc )
rc = ibmphp_hpc_readslot ( pslot , READ_EXTSLOTSTATUS ,
& myslot . ext_status ) ;
if ( ! rc )
* value = SLOT_ATTN ( myslot . status , myslot . ext_status ) ;
2005-04-17 02:20:36 +04:00
}
ibmphp_unlock_operations ( ) ;
debug ( " get_attention_status - Exit rc[%d] value[%x] \n " , rc , * value ) ;
return rc ;
}
2014-04-19 04:13:49 +04:00
static int get_latch_status ( struct hotplug_slot * hotplug_slot , u8 * value )
2005-04-17 02:20:36 +04:00
{
int rc = - ENODEV ;
struct slot * pslot ;
struct slot myslot ;
debug ( " get_latch_status - Entry hotplug_slot[%lx] pvalue[%lx] \n " ,
( ulong ) hotplug_slot , ( ulong ) value ) ;
ibmphp_lock_operations ( ) ;
2006-06-01 13:41:44 +04:00
if ( hotplug_slot ) {
2018-09-08 10:59:01 +03:00
pslot = to_slot ( hotplug_slot ) ;
memcpy ( & myslot , pslot , sizeof ( struct slot ) ) ;
rc = ibmphp_hpc_readslot ( pslot , READ_SLOTSTATUS ,
& myslot . status ) ;
if ( ! rc )
* value = SLOT_LATCH ( myslot . status ) ;
2005-04-17 02:20:36 +04:00
}
ibmphp_unlock_operations ( ) ;
debug ( " get_latch_status - Exit rc[%d] rc[%x] value[%x] \n " ,
rc , rc , * value ) ;
return rc ;
}
2014-04-19 04:13:49 +04:00
static int get_power_status ( struct hotplug_slot * hotplug_slot , u8 * value )
2005-04-17 02:20:36 +04:00
{
int rc = - ENODEV ;
struct slot * pslot ;
struct slot myslot ;
debug ( " get_power_status - Entry hotplug_slot[%lx] pvalue[%lx] \n " ,
( ulong ) hotplug_slot , ( ulong ) value ) ;
ibmphp_lock_operations ( ) ;
2006-06-01 13:41:44 +04:00
if ( hotplug_slot ) {
2018-09-08 10:59:01 +03:00
pslot = to_slot ( hotplug_slot ) ;
memcpy ( & myslot , pslot , sizeof ( struct slot ) ) ;
rc = ibmphp_hpc_readslot ( pslot , READ_SLOTSTATUS ,
& myslot . status ) ;
if ( ! rc )
* value = SLOT_PWRGD ( myslot . status ) ;
2005-04-17 02:20:36 +04:00
}
ibmphp_unlock_operations ( ) ;
debug ( " get_power_status - Exit rc[%d] rc[%x] value[%x] \n " ,
rc , rc , * value ) ;
return rc ;
}
2014-04-19 04:13:49 +04:00
static int get_adapter_present ( struct hotplug_slot * hotplug_slot , u8 * value )
2005-04-17 02:20:36 +04:00
{
int rc = - ENODEV ;
struct slot * pslot ;
u8 present ;
struct slot myslot ;
debug ( " get_adapter_status - Entry hotplug_slot[%lx] pvalue[%lx] \n " ,
( ulong ) hotplug_slot , ( ulong ) value ) ;
ibmphp_lock_operations ( ) ;
2006-06-01 13:41:44 +04:00
if ( hotplug_slot ) {
2018-09-08 10:59:01 +03:00
pslot = to_slot ( hotplug_slot ) ;
memcpy ( & myslot , pslot , sizeof ( struct slot ) ) ;
rc = ibmphp_hpc_readslot ( pslot , READ_SLOTSTATUS ,
& myslot . status ) ;
if ( ! rc ) {
present = SLOT_PRESENT ( myslot . status ) ;
if ( present = = HPC_SLOT_EMPTY )
* value = 0 ;
else
* value = 1 ;
2005-04-17 02:20:36 +04:00
}
}
ibmphp_unlock_operations ( ) ;
debug ( " get_adapter_present - Exit rc[%d] value[%x] \n " , rc , * value ) ;
return rc ;
}
2009-12-13 16:11:32 +03:00
static int get_max_bus_speed ( struct slot * slot )
2005-04-17 02:20:36 +04:00
{
2018-04-19 13:05:49 +03:00
int rc = 0 ;
2005-04-17 02:20:36 +04:00
u8 mode = 0 ;
2009-12-13 16:11:32 +03:00
enum pci_bus_speed speed ;
2018-09-08 10:59:01 +03:00
struct pci_bus * bus = slot - > hotplug_slot . pci_slot - > bus ;
2005-04-17 02:20:36 +04:00
2009-12-13 16:11:32 +03:00
debug ( " %s - Entry slot[%p] \n " , __func__ , slot ) ;
2005-04-17 02:20:36 +04:00
ibmphp_lock_operations ( ) ;
2009-12-13 16:11:32 +03:00
mode = slot - > supported_bus_mode ;
2013-11-14 22:28:18 +04:00
speed = slot - > supported_speed ;
2005-04-17 02:20:36 +04:00
ibmphp_unlock_operations ( ) ;
2009-12-13 16:11:32 +03:00
switch ( speed ) {
case BUS_SPEED_33 :
break ;
case BUS_SPEED_66 :
2013-11-14 22:28:18 +04:00
if ( mode = = BUS_MODE_PCIX )
2009-12-13 16:11:32 +03:00
speed + = 0x01 ;
break ;
case BUS_SPEED_100 :
case BUS_SPEED_133 :
speed + = 0x01 ;
break ;
default :
/* Note (will need to change): there would be soon 256, 512 also */
rc = - ENODEV ;
2005-04-17 02:20:36 +04:00
}
2009-12-13 16:11:32 +03:00
if ( ! rc )
bus - > max_bus_speed = speed ;
debug ( " %s - Exit rc[%d] speed[%x] \n " , __func__ , rc , speed ) ;
2005-04-17 02:20:36 +04:00
return rc ;
}
/****************************************************************************
* This routine will initialize the ops data structure used in the validate
* function . It will also power off empty slots that are powered on since BIOS
* leaves those on , albeit disconnected
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int __init init_ops ( void )
{
struct slot * slot_cur ;
int retval ;
int rc ;
2015-12-12 16:36:57 +03:00
list_for_each_entry ( slot_cur , & ibmphp_slot_head , ibm_slot_list ) {
2005-04-17 02:20:36 +04:00
debug ( " BEFORE GETTING SLOT STATUS, slot # %x \n " ,
slot_cur - > number ) ;
2013-11-14 22:28:18 +04:00
if ( slot_cur - > ctrl - > revision = = 0xFF )
2005-04-17 02:20:36 +04:00
if ( get_ctrl_revision ( slot_cur ,
& slot_cur - > ctrl - > revision ) )
return - 1 ;
2013-11-14 22:28:18 +04:00
if ( slot_cur - > bus_on - > current_speed = = 0xFF )
if ( get_cur_bus_info ( & slot_cur ) )
2005-04-17 02:20:36 +04:00
return - 1 ;
2009-12-13 16:11:32 +03:00
get_max_bus_speed ( slot_cur ) ;
2005-04-17 02:20:36 +04:00
if ( slot_cur - > ctrl - > options = = 0xFF )
if ( get_hpc_options ( slot_cur , & slot_cur - > ctrl - > options ) )
return - 1 ;
retval = slot_update ( & slot_cur ) ;
if ( retval )
return retval ;
debug ( " status = %x \n " , slot_cur - > status ) ;
debug ( " ext_status = %x \n " , slot_cur - > ext_status ) ;
debug ( " SLOT_POWER = %x \n " , SLOT_POWER ( slot_cur - > status ) ) ;
debug ( " SLOT_PRESENT = %x \n " , SLOT_PRESENT ( slot_cur - > status ) ) ;
debug ( " SLOT_LATCH = %x \n " , SLOT_LATCH ( slot_cur - > status ) ) ;
2013-11-14 22:28:18 +04:00
if ( ( SLOT_PWRGD ( slot_cur - > status ) ) & &
! ( SLOT_PRESENT ( slot_cur - > status ) ) & &
2005-04-17 02:20:36 +04:00
! ( SLOT_LATCH ( slot_cur - > status ) ) ) {
debug ( " BEFORE POWER OFF COMMAND \n " ) ;
rc = power_off ( slot_cur ) ;
if ( rc )
return rc ;
/* retval = slot_update(&slot_cur);
* if ( retval )
* return retval ;
* ibmphp_update_slot_info ( slot_cur ) ;
*/
}
}
init_flag = 0 ;
return 0 ;
}
/* This operation will check whether the slot is within the bounds and
* the operation is valid to perform on that slot
* Parameters : slot , operation
* Returns : 0 or error codes
*/
static int validate ( struct slot * slot_cur , int opn )
{
int number ;
int retval ;
if ( ! slot_cur )
return - ENODEV ;
number = slot_cur - > number ;
if ( ( number > max_slots ) | | ( number < 0 ) )
return - EBADSLT ;
debug ( " slot_number in validate is %d \n " , slot_cur - > number ) ;
retval = slot_update ( & slot_cur ) ;
if ( retval )
return retval ;
switch ( opn ) {
case ENABLE :
2013-11-14 22:28:18 +04:00
if ( ! ( SLOT_PWRGD ( slot_cur - > status ) ) & &
( SLOT_PRESENT ( slot_cur - > status ) ) & &
2005-04-17 02:20:36 +04:00
! ( SLOT_LATCH ( slot_cur - > status ) ) )
return 0 ;
break ;
case DISABLE :
2013-11-14 22:28:18 +04:00
if ( ( SLOT_PWRGD ( slot_cur - > status ) ) & &
2005-04-17 02:20:36 +04:00
( SLOT_PRESENT ( slot_cur - > status ) ) & &
! ( SLOT_LATCH ( slot_cur - > status ) ) )
return 0 ;
break ;
default :
break ;
}
err ( " validate failed.... \n " ) ;
return - EINVAL ;
}
/****************************************************************************
* This routine is for updating the data structures in the hotplug core
* Parameters : struct slot
* Returns : 0 or error
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int ibmphp_update_slot_info ( struct slot * slot_cur )
{
2018-09-08 10:59:01 +03:00
struct pci_bus * bus = slot_cur - > hotplug_slot . pci_slot - > bus ;
2005-04-17 02:20:36 +04:00
u8 bus_speed ;
u8 mode ;
bus_speed = slot_cur - > bus_on - > current_speed ;
mode = slot_cur - > bus_on - > current_bus_mode ;
switch ( bus_speed ) {
case BUS_SPEED_33 :
break ;
case BUS_SPEED_66 :
2013-11-14 22:28:18 +04:00
if ( mode = = BUS_MODE_PCIX )
2005-04-17 02:20:36 +04:00
bus_speed + = 0x01 ;
else if ( mode = = BUS_MODE_PCI )
;
else
bus_speed = PCI_SPEED_UNKNOWN ;
break ;
case BUS_SPEED_100 :
case BUS_SPEED_133 :
bus_speed + = 0x01 ;
break ;
default :
bus_speed = PCI_SPEED_UNKNOWN ;
}
2009-12-13 16:11:32 +03:00
bus - > cur_bus_speed = bus_speed ;
2013-11-14 22:28:18 +04:00
// To do: bus_names
PCI: hotplug: Drop hotplug_slot_info
Ever since the PCI hotplug core was introduced in 2002, drivers had to
allocate and register a struct hotplug_slot_info for every slot:
https://git.kernel.org/tglx/history/c/a8a2069f432c
Apparently the idea was that drivers furnish the hotplug core with an
up-to-date card presence status, power status, latch status and
attention indicator status as well as notify the hotplug core of changes
thereof. However only 4 out of 12 hotplug drivers bother to notify the
hotplug core with pci_hp_change_slot_info() and the hotplug core never
made any use of the information: There is just a single macro in
pci_hotplug_core.c, GET_STATUS(), which uses the hotplug_slot_info if
the driver lacks the corresponding callback in hotplug_slot_ops. The
macro is called when the user reads the attribute via sysfs.
Now, if the callback isn't defined, the attribute isn't exposed in sysfs
in the first place (see e.g. has_power_file()). There are only two
situations when the hotplug_slot_info would actually be accessed:
* If the driver defines ->enable_slot or ->disable_slot but not
->get_power_status.
* If the driver defines ->set_attention_status but not
->get_attention_status.
There is no driver doing the former and just a single driver doing the
latter, namely pnv_php.c. Amend it with a ->get_attention_status
callback. With that, the hotplug_slot_info becomes completely unused by
the PCI hotplug core. But a few drivers use it internally as a cache:
cpcihp uses it to cache the latch_status and adapter_status.
cpqhp uses it to cache the adapter_status.
pnv_php and rpaphp use it to cache the attention_status.
shpchp uses it to cache all four values.
Amend these drivers to cache the information in their private slot
struct. shpchp's slot struct already contains members to cache the
power_status and adapter_status, so additional members are only needed
for the other two values. In the case of cpqphp, the cached value is
only accessed in a single place, so instead of caching it, read the
current value from the hardware.
Caution: acpiphp, cpci, cpqhp, shpchp, asus-wmi and eeepc-laptop
populate the hotplug_slot_info with initial values on probe. That code
is herewith removed. There is a theoretical chance that the code has
side effects without which the driver fails to function, e.g. if the
ACPI method to read the adapter status needs to be executed at least
once on probe. That seems unlikely to me, still maintainers should
review the changes carefully for this possibility.
Rafael adds: "I'm not aware of any case in which it will break anything,
[...] but if that happens, it may be necessary to add the execution of
the control methods in question directly to the initialization part."
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com> # drivers/pci/hotplug/rpa*
Acked-by: Sebastian Ott <sebott@linux.ibm.com> # drivers/pci/hotplug/s390*
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86
Cc: Len Brown <lenb@kernel.org>
Cc: Scott Murray <scott@spiteful.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Oliver OHalloran <oliveroh@au1.ibm.com>
Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Cc: Corentin Chary <corentin.chary@gmail.com>
Cc: Darren Hart <dvhart@infradead.org>
2018-09-08 10:59:01 +03:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
/******************************************************************************
* This function will return the pci_func , given bus and devfunc , or NULL . It
* is called from visit routines
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static struct pci_func * ibm_slot_find ( u8 busno , u8 device , u8 function )
{
struct pci_func * func_cur ;
struct slot * slot_cur ;
2015-12-12 16:36:57 +03:00
list_for_each_entry ( slot_cur , & ibmphp_slot_head , ibm_slot_list ) {
2005-04-17 02:20:36 +04:00
if ( slot_cur - > func ) {
func_cur = slot_cur - > func ;
while ( func_cur ) {
if ( ( func_cur - > busno = = busno ) & &
( func_cur - > device = = device ) & &
( func_cur - > function = = function ) )
return func_cur ;
func_cur = func_cur - > next ;
}
}
}
return NULL ;
}
/*************************************************************
* This routine frees up memory used by struct slot , including
* the pointers to pci_func , bus , hotplug_slot , controller ,
* and deregistering from the hotplug core
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void free_slots ( void )
{
2015-12-12 16:36:57 +03:00
struct slot * slot_cur , * next ;
2005-04-17 02:20:36 +04:00
2008-03-04 06:09:46 +03:00
debug ( " %s -- enter \n " , __func__ ) ;
2005-04-17 02:20:36 +04:00
2015-12-12 16:36:57 +03:00
list_for_each_entry_safe ( slot_cur , next , & ibmphp_slot_head ,
ibm_slot_list ) {
2018-09-08 10:59:01 +03:00
pci_hp_del ( & slot_cur - > hotplug_slot ) ;
PCI: hotplug: Demidlayer registration with the core
When a hotplug driver calls pci_hp_register(), all steps necessary for
registration are carried out in one go, including creation of a kobject
and addition to sysfs. That's a problem for pciehp once it's converted
to enable/disable the slot exclusively from the IRQ thread: The thread
needs to be spawned after creation of the kobject (because it uses the
kobject's name), but before addition to sysfs (because it will handle
enable/disable requests submitted via sysfs).
pci_hp_deregister() does offer a ->release callback that's invoked
after deletion from sysfs and before destruction of the kobject. But
because pci_hp_register() doesn't offer a counterpart, hotplug drivers'
->probe and ->remove code becomes asymmetric, which is error prone
as recently discovered use-after-free bugs in pciehp's ->remove hook
have shown.
In a sense, this appears to be a case of the midlayer antipattern:
"The core thesis of the "midlayer mistake" is that midlayers are
bad and should not exist. That common functionality which it is
so tempting to put in a midlayer should instead be provided as
library routines which can [be] used, augmented, or ignored by
each bottom level driver independently. Thus every subsystem
that supports multiple implementations (or drivers) should
provide a very thin top layer which calls directly into the
bottom layer drivers, and a rich library of support code that
eases the implementation of those drivers. This library is
available to, but not forced upon, those drivers."
-- Neil Brown (2009), https://lwn.net/Articles/336262/
The presence of midlayer traits in the PCI hotplug core might be ascribed
to its age: When it was introduced in February 2002, the blessings of a
library approach might not have been well known:
https://git.kernel.org/tglx/history/c/a8a2069f432c
For comparison, the driver core does offer split functions for creating
a kobject (device_initialize()) and addition to sysfs (device_add()) as
an alternative to carrying out everything at once (device_register()).
This was introduced in October 2002:
https://git.kernel.org/tglx/history/c/8b290eb19962
The odd ->release callback in the PCI hotplug core was added in 2003:
https://git.kernel.org/tglx/history/c/69f8d663b595
Clearly, a library approach would not force every hotplug driver to
implement a ->release callback, but rather allow the driver to remove
the sysfs files, release its data structures and finally destroy the
kobject. Alternatively, a driver may choose to remove everything with
pci_hp_deregister(), then release its data structures.
To this end, offer drivers pci_hp_initialize() and pci_hp_add() as a
split-up version of pci_hp_register(). Likewise, offer pci_hp_del()
and pci_hp_destroy() as a split-up version of pci_hp_deregister().
Eliminate the ->release callback and move its code into each driver's
teardown routine.
Declare pci_hp_deregister() void, in keeping with the usual kernel
pattern that enablement can fail, but disablement cannot. It only
returned an error if the caller passed in a NULL pointer or a slot which
has never or is no longer registered or is sharing its name with another
slot. Those would be bugs, so WARN about them. Few hotplug drivers
actually checked the return value and those that did only printed a
useless error message to dmesg. Remove that.
For most drivers the conversion was straightforward since it doesn't
matter whether the code in the ->release callback is executed before or
after destruction of the kobject. But in the case of ibmphp, it was
unclear to me whether setting slot_cur->ctrl and slot_cur->bus_on to
NULL needs to happen before the kobject is destroyed, so I erred on
the side of caution and ensured that the order stays the same. Another
nontrivial case is pnv_php, I've found the list and kref logic difficult
to understand, however my impression was that it is safe to delete the
list element and drop the references until after the kobject is
destroyed.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Len Brown <lenb@kernel.org>
Cc: Scott Murray <scott@spiteful.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>
Cc: Sebastian Ott <sebott@linux.vnet.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Cc: Corentin Chary <corentin.chary@gmail.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
2018-07-20 01:27:43 +03:00
slot_cur - > ctrl = NULL ;
slot_cur - > bus_on = NULL ;
/*
* We don ' t want to actually remove the resources ,
* since ibmphp_free_resources ( ) will do just that .
*/
ibmphp_unconfigure_card ( & slot_cur , - 1 ) ;
2018-09-08 10:59:01 +03:00
pci_hp_destroy ( & slot_cur - > hotplug_slot ) ;
PCI: hotplug: Demidlayer registration with the core
When a hotplug driver calls pci_hp_register(), all steps necessary for
registration are carried out in one go, including creation of a kobject
and addition to sysfs. That's a problem for pciehp once it's converted
to enable/disable the slot exclusively from the IRQ thread: The thread
needs to be spawned after creation of the kobject (because it uses the
kobject's name), but before addition to sysfs (because it will handle
enable/disable requests submitted via sysfs).
pci_hp_deregister() does offer a ->release callback that's invoked
after deletion from sysfs and before destruction of the kobject. But
because pci_hp_register() doesn't offer a counterpart, hotplug drivers'
->probe and ->remove code becomes asymmetric, which is error prone
as recently discovered use-after-free bugs in pciehp's ->remove hook
have shown.
In a sense, this appears to be a case of the midlayer antipattern:
"The core thesis of the "midlayer mistake" is that midlayers are
bad and should not exist. That common functionality which it is
so tempting to put in a midlayer should instead be provided as
library routines which can [be] used, augmented, or ignored by
each bottom level driver independently. Thus every subsystem
that supports multiple implementations (or drivers) should
provide a very thin top layer which calls directly into the
bottom layer drivers, and a rich library of support code that
eases the implementation of those drivers. This library is
available to, but not forced upon, those drivers."
-- Neil Brown (2009), https://lwn.net/Articles/336262/
The presence of midlayer traits in the PCI hotplug core might be ascribed
to its age: When it was introduced in February 2002, the blessings of a
library approach might not have been well known:
https://git.kernel.org/tglx/history/c/a8a2069f432c
For comparison, the driver core does offer split functions for creating
a kobject (device_initialize()) and addition to sysfs (device_add()) as
an alternative to carrying out everything at once (device_register()).
This was introduced in October 2002:
https://git.kernel.org/tglx/history/c/8b290eb19962
The odd ->release callback in the PCI hotplug core was added in 2003:
https://git.kernel.org/tglx/history/c/69f8d663b595
Clearly, a library approach would not force every hotplug driver to
implement a ->release callback, but rather allow the driver to remove
the sysfs files, release its data structures and finally destroy the
kobject. Alternatively, a driver may choose to remove everything with
pci_hp_deregister(), then release its data structures.
To this end, offer drivers pci_hp_initialize() and pci_hp_add() as a
split-up version of pci_hp_register(). Likewise, offer pci_hp_del()
and pci_hp_destroy() as a split-up version of pci_hp_deregister().
Eliminate the ->release callback and move its code into each driver's
teardown routine.
Declare pci_hp_deregister() void, in keeping with the usual kernel
pattern that enablement can fail, but disablement cannot. It only
returned an error if the caller passed in a NULL pointer or a slot which
has never or is no longer registered or is sharing its name with another
slot. Those would be bugs, so WARN about them. Few hotplug drivers
actually checked the return value and those that did only printed a
useless error message to dmesg. Remove that.
For most drivers the conversion was straightforward since it doesn't
matter whether the code in the ->release callback is executed before or
after destruction of the kobject. But in the case of ibmphp, it was
unclear to me whether setting slot_cur->ctrl and slot_cur->bus_on to
NULL needs to happen before the kobject is destroyed, so I erred on
the side of caution and ensured that the order stays the same. Another
nontrivial case is pnv_php, I've found the list and kref logic difficult
to understand, however my impression was that it is safe to delete the
list element and drop the references until after the kobject is
destroyed.
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Len Brown <lenb@kernel.org>
Cc: Scott Murray <scott@spiteful.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>
Cc: Sebastian Ott <sebott@linux.vnet.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Cc: Corentin Chary <corentin.chary@gmail.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Andy Shevchenko <andy@infradead.org>
2018-07-20 01:27:43 +03:00
kfree ( slot_cur ) ;
2005-04-17 02:20:36 +04:00
}
2008-03-04 06:09:46 +03:00
debug ( " %s -- exit \n " , __func__ ) ;
2005-04-17 02:20:36 +04:00
}
static void ibm_unconfigure_device ( struct pci_func * func )
{
struct pci_dev * temp ;
u8 j ;
2008-03-04 06:09:46 +03:00
debug ( " inside %s \n " , __func__ ) ;
2005-04-17 02:20:36 +04:00
debug ( " func->device = %x, func->function = %x \n " ,
func - > device , func - > function ) ;
debug ( " func->device << 3 | 0x0 = %x \n " , func - > device < < 3 | 0x0 ) ;
2014-01-14 23:03:14 +04:00
pci_lock_rescan_remove ( ) ;
2005-04-17 02:20:36 +04:00
for ( j = 0 ; j < 0x08 ; j + + ) {
2017-12-19 08:37:52 +03:00
temp = pci_get_domain_bus_and_slot ( 0 , func - > busno ,
( func - > device < < 3 ) | j ) ;
2007-10-13 03:20:29 +04:00
if ( temp ) {
2012-02-26 01:54:20 +04:00
pci_stop_and_remove_bus_device ( temp ) ;
2007-10-13 03:20:29 +04:00
pci_dev_put ( temp ) ;
}
2005-04-17 02:20:36 +04:00
}
2014-01-14 23:03:14 +04:00
2007-10-13 03:20:29 +04:00
pci_dev_put ( func - > dev ) ;
2014-01-14 23:03:14 +04:00
pci_unlock_rescan_remove ( ) ;
2005-04-17 02:20:36 +04:00
}
/*
2013-11-14 22:28:18 +04:00
* The following function is to fix kernel bug regarding
* getting bus entries , here we manually add those primary
2005-04-17 02:20:36 +04:00
* bus entries to kernel bus structure whenever apply
*/
static u8 bus_structure_fixup ( u8 busno )
{
2015-03-09 05:33:58 +03:00
struct pci_bus * bus , * b ;
2005-04-17 02:20:36 +04:00
struct pci_dev * dev ;
u16 l ;
if ( pci_find_bus ( 0 , busno ) | | ! ( ibmphp_find_same_bus_num ( busno ) ) )
return 1 ;
bus = kmalloc ( sizeof ( * bus ) , GFP_KERNEL ) ;
PCI: Remove unnecessary messages for memory allocation failures
Per ebfdc40969f2 ("checkpatch: attempt to find unnecessary 'out of memory'
messages"), when a memory allocation fails, the memory subsystem emits
generic "out of memory" messages (see slab_out_of_memory() for some of this
logging). Therefore, additional error messages in the caller don't add
much value.
Remove messages that merely report "out of memory".
This preserves some messages that report additional information, e.g.,
allocation failures that mean we drop hotplug events.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
[bhelgaas: changelog, squash patches, make similar changes to acpiphp,
cpqphp, ibmphp, keep warning when dropping hotplug event]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2017-12-29 14:15:16 +03:00
if ( ! bus )
2005-04-17 02:20:36 +04:00
return 1 ;
PCI: Remove unnecessary messages for memory allocation failures
Per ebfdc40969f2 ("checkpatch: attempt to find unnecessary 'out of memory'
messages"), when a memory allocation fails, the memory subsystem emits
generic "out of memory" messages (see slab_out_of_memory() for some of this
logging). Therefore, additional error messages in the caller don't add
much value.
Remove messages that merely report "out of memory".
This preserves some messages that report additional information, e.g.,
allocation failures that mean we drop hotplug events.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
[bhelgaas: changelog, squash patches, make similar changes to acpiphp,
cpqphp, ibmphp, keep warning when dropping hotplug event]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2017-12-29 14:15:16 +03:00
2005-04-17 02:20:36 +04:00
dev = kmalloc ( sizeof ( * dev ) , GFP_KERNEL ) ;
if ( ! dev ) {
kfree ( bus ) ;
return 1 ;
}
bus - > number = busno ;
bus - > ops = ibmphp_pci_bus - > ops ;
dev - > bus = bus ;
for ( dev - > devfn = 0 ; dev - > devfn < 256 ; dev - > devfn + = 8 ) {
if ( ! pci_read_config_word ( dev , PCI_VENDOR_ID , & l ) & &
( l ! = 0x0000 ) & & ( l ! = 0xffff ) ) {
2012-07-23 17:39:51 +04:00
debug ( " %s - Inside bus_structure_fixup() \n " ,
2008-03-04 06:09:46 +03:00
__func__ ) ;
2015-03-09 05:33:58 +03:00
b = pci_scan_bus ( busno , ibmphp_pci_bus - > ops , NULL ) ;
if ( ! b )
continue ;
pci_bus_add_devices ( b ) ;
2005-04-17 02:20:36 +04:00
break ;
}
}
kfree ( dev ) ;
kfree ( bus ) ;
return 0 ;
}
static int ibm_configure_device ( struct pci_func * func )
{
struct pci_bus * child ;
int num ;
int flag = 0 ; /* this is to make sure we don't double scan the bus,
for bridged devices primarily */
2014-01-14 23:03:14 +04:00
pci_lock_rescan_remove ( ) ;
2005-04-17 02:20:36 +04:00
if ( ! ( bus_structure_fixup ( func - > busno ) ) )
flag = 1 ;
if ( func - > dev = = NULL )
2017-12-19 08:37:52 +03:00
func - > dev = pci_get_domain_bus_and_slot ( 0 , func - > busno ,
2005-04-17 02:20:36 +04:00
PCI_DEVFN ( func - > device , func - > function ) ) ;
if ( func - > dev = = NULL ) {
struct pci_bus * bus = pci_find_bus ( 0 , func - > busno ) ;
if ( ! bus )
2014-01-14 23:03:14 +04:00
goto out ;
2005-04-17 02:20:36 +04:00
num = pci_scan_slot ( bus ,
PCI_DEVFN ( func - > device , func - > function ) ) ;
if ( num )
pci_bus_add_devices ( bus ) ;
2017-12-19 08:37:52 +03:00
func - > dev = pci_get_domain_bus_and_slot ( 0 , func - > busno ,
2005-04-17 02:20:36 +04:00
PCI_DEVFN ( func - > device , func - > function ) ) ;
if ( func - > dev = = NULL ) {
err ( " ERROR... : pci_dev still NULL \n " ) ;
2014-01-14 23:03:14 +04:00
goto out ;
2005-04-17 02:20:36 +04:00
}
}
if ( ! ( flag ) & & ( func - > dev - > hdr_type = = PCI_HEADER_TYPE_BRIDGE ) ) {
2012-05-18 05:58:41 +04:00
pci_hp_add_bridge ( func - > dev ) ;
child = func - > dev - > subordinate ;
if ( child )
pci_bus_add_devices ( child ) ;
2005-04-17 02:20:36 +04:00
}
2014-01-14 23:03:14 +04:00
out :
pci_unlock_rescan_remove ( ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
/*******************************************************
2013-11-14 22:28:18 +04:00
* Returns whether the bus is empty or not
2005-04-17 02:20:36 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2014-04-19 04:13:49 +04:00
static int is_bus_empty ( struct slot * slot_cur )
2005-04-17 02:20:36 +04:00
{
int rc ;
2014-04-19 04:13:49 +04:00
struct slot * tmp_slot ;
2005-04-17 02:20:36 +04:00
u8 i = slot_cur - > bus_on - > slot_min ;
while ( i < = slot_cur - > bus_on - > slot_max ) {
if ( i = = slot_cur - > number ) {
i + + ;
continue ;
}
tmp_slot = ibmphp_get_slot_from_physical_num ( i ) ;
if ( ! tmp_slot )
return 0 ;
rc = slot_update ( & tmp_slot ) ;
if ( rc )
return 0 ;
if ( SLOT_PRESENT ( tmp_slot - > status ) & &
SLOT_PWRGD ( tmp_slot - > status ) )
return 0 ;
i + + ;
}
return 1 ;
}
/***********************************************************
2013-11-14 22:28:18 +04:00
* If the HPC permits and the bus currently empty , tries to set the
2005-04-17 02:20:36 +04:00
* bus speed and mode at the maximum card and bus capability
* Parameters : slot
* Returns : bus is set ( 0 ) or error code
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2014-04-19 04:13:49 +04:00
static int set_bus ( struct slot * slot_cur )
2005-04-17 02:20:36 +04:00
{
int rc ;
u8 speed ;
u8 cmd = 0x0 ;
int retval ;
2017-08-04 02:20:17 +03:00
static const struct pci_device_id ciobx [ ] = {
2005-04-17 02:20:36 +04:00
{ PCI_DEVICE ( PCI_VENDOR_ID_SERVERWORKS , 0x0101 ) } ,
2015-12-28 00:21:11 +03:00
{ } ,
2013-11-14 22:28:18 +04:00
} ;
2005-04-17 02:20:36 +04:00
2008-03-04 06:09:46 +03:00
debug ( " %s - entry slot # %d \n " , __func__ , slot_cur - > number ) ;
2005-04-17 02:20:36 +04:00
if ( SET_BUS_STATUS ( slot_cur - > ctrl ) & & is_bus_empty ( slot_cur ) ) {
rc = slot_update ( & slot_cur ) ;
if ( rc )
return rc ;
speed = SLOT_SPEED ( slot_cur - > ext_status ) ;
debug ( " ext_status = %x, speed = %x \n " , slot_cur - > ext_status , speed ) ;
switch ( speed ) {
case HPC_SLOT_SPEED_33 :
cmd = HPC_BUS_33CONVMODE ;
break ;
case HPC_SLOT_SPEED_66 :
if ( SLOT_PCIX ( slot_cur - > ext_status ) ) {
if ( ( slot_cur - > supported_speed > = BUS_SPEED_66 ) & &
( slot_cur - > supported_bus_mode = = BUS_MODE_PCIX ) )
cmd = HPC_BUS_66PCIXMODE ;
else if ( ! SLOT_BUS_MODE ( slot_cur - > ext_status ) )
/* if max slot/bus capability is 66 pci
and there ' s no bus mode mismatch , then
2013-11-14 22:28:18 +04:00
the adapter supports 66 pci */
2005-04-17 02:20:36 +04:00
cmd = HPC_BUS_66CONVMODE ;
else
cmd = HPC_BUS_33CONVMODE ;
} else {
if ( slot_cur - > supported_speed > = BUS_SPEED_66 )
cmd = HPC_BUS_66CONVMODE ;
else
cmd = HPC_BUS_33CONVMODE ;
}
break ;
case HPC_SLOT_SPEED_133 :
switch ( slot_cur - > supported_speed ) {
case BUS_SPEED_33 :
cmd = HPC_BUS_33CONVMODE ;
break ;
case BUS_SPEED_66 :
if ( slot_cur - > supported_bus_mode = = BUS_MODE_PCIX )
cmd = HPC_BUS_66PCIXMODE ;
else
cmd = HPC_BUS_66CONVMODE ;
break ;
case BUS_SPEED_100 :
cmd = HPC_BUS_100PCIXMODE ;
break ;
case BUS_SPEED_133 :
/* This is to take care of the bug in CIOBX chip */
if ( pci_dev_present ( ciobx ) )
ibmphp_hpc_writeslot ( slot_cur ,
HPC_BUS_100PCIXMODE ) ;
cmd = HPC_BUS_133PCIXMODE ;
break ;
default :
err ( " Wrong bus speed \n " ) ;
return - ENODEV ;
}
break ;
default :
err ( " wrong slot speed \n " ) ;
return - ENODEV ;
}
debug ( " setting bus speed for slot %d, cmd %x \n " ,
slot_cur - > number , cmd ) ;
retval = ibmphp_hpc_writeslot ( slot_cur , cmd ) ;
if ( retval ) {
err ( " setting bus speed failed \n " ) ;
return retval ;
}
if ( CTLR_RESULT ( slot_cur - > ctrl - > status ) ) {
err ( " command not completed successfully in set_bus \n " ) ;
return - EIO ;
}
}
2013-11-14 22:28:18 +04:00
/* This is for x440, once Brandon fixes the firmware,
2005-04-17 02:20:36 +04:00
will not need this delay */
msleep ( 1000 ) ;
2008-03-04 06:09:46 +03:00
debug ( " %s -Exit \n " , __func__ ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
/* This routine checks the bus limitations that the slot is on from the BIOS.
2013-11-14 22:28:18 +04:00
* This is used in deciding whether or not to power up the slot .
2005-04-17 02:20:36 +04:00
* ( electrical / spec limitations . For example , > 1 133 MHz or > 2 66 PCI cards on
2013-11-14 22:28:18 +04:00
* same bus )
2005-04-17 02:20:36 +04:00
* Parameters : slot
* Returns : 0 = no limitations , - EINVAL = exceeded limitations on the bus
*/
static int check_limitations ( struct slot * slot_cur )
{
u8 i ;
2014-04-19 04:13:49 +04:00
struct slot * tmp_slot ;
2005-04-17 02:20:36 +04:00
u8 count = 0 ;
u8 limitation = 0 ;
for ( i = slot_cur - > bus_on - > slot_min ; i < = slot_cur - > bus_on - > slot_max ; i + + ) {
tmp_slot = ibmphp_get_slot_from_physical_num ( i ) ;
if ( ! tmp_slot )
return - ENODEV ;
if ( ( SLOT_PWRGD ( tmp_slot - > status ) ) & &
! ( SLOT_CONNECT ( tmp_slot - > status ) ) )
count + + ;
}
get_cur_bus_info ( & slot_cur ) ;
switch ( slot_cur - > bus_on - > current_speed ) {
case BUS_SPEED_33 :
limitation = slot_cur - > bus_on - > slots_at_33_conv ;
break ;
case BUS_SPEED_66 :
if ( slot_cur - > bus_on - > current_bus_mode = = BUS_MODE_PCIX )
limitation = slot_cur - > bus_on - > slots_at_66_pcix ;
else
limitation = slot_cur - > bus_on - > slots_at_66_conv ;
break ;
case BUS_SPEED_100 :
limitation = slot_cur - > bus_on - > slots_at_100_pcix ;
break ;
case BUS_SPEED_133 :
limitation = slot_cur - > bus_on - > slots_at_133_pcix ;
break ;
}
if ( ( count + 1 ) > limitation )
return - EINVAL ;
return 0 ;
}
static inline void print_card_capability ( struct slot * slot_cur )
{
info ( " capability of the card is " ) ;
2013-11-14 22:28:18 +04:00
if ( ( slot_cur - > ext_status & CARD_INFO ) = = PCIX133 )
2005-04-17 02:20:36 +04:00
info ( " 133 MHz PCI-X \n " ) ;
else if ( ( slot_cur - > ext_status & CARD_INFO ) = = PCIX66 )
info ( " 66 MHz PCI-X \n " ) ;
else if ( ( slot_cur - > ext_status & CARD_INFO ) = = PCI66 )
info ( " 66 MHz PCI \n " ) ;
else
info ( " 33 MHz PCI \n " ) ;
}
/* This routine will power on the slot, configure the device(s) and find the
* drivers for them .
* Parameters : hotplug_slot
* Returns : 0 or failure codes
*/
static int enable_slot ( struct hotplug_slot * hs )
{
int rc , i , rcpr ;
struct slot * slot_cur ;
u8 function ;
struct pci_func * tmp_func ;
ibmphp_lock_operations ( ) ;
debug ( " ENABLING SLOT........ \n " ) ;
2018-09-08 10:59:01 +03:00
slot_cur = to_slot ( hs ) ;
2005-04-17 02:20:36 +04:00
2014-09-07 22:03:32 +04:00
rc = validate ( slot_cur , ENABLE ) ;
if ( rc ) {
2005-04-17 02:20:36 +04:00
err ( " validate function failed \n " ) ;
goto error_nopower ;
}
attn_LED_blink ( slot_cur ) ;
2013-11-14 22:28:18 +04:00
2005-04-17 02:20:36 +04:00
rc = set_bus ( slot_cur ) ;
if ( rc ) {
err ( " was not able to set the bus \n " ) ;
goto error_nopower ;
}
/*-----------------debugging------------------------------*/
get_cur_bus_info ( & slot_cur ) ;
debug ( " the current bus speed right after set_bus = %x \n " ,
slot_cur - > bus_on - > current_speed ) ;
/*----------------------------------------------------------*/
rc = check_limitations ( slot_cur ) ;
if ( rc ) {
err ( " Adding this card exceeds the limitations of this bus. \n " ) ;
2014-04-19 04:13:50 +04:00
err ( " (i.e., >1 133MHz cards running on same bus, or >2 66 PCI cards running on same bus. \n " ) ;
2005-04-17 02:20:36 +04:00
err ( " Try hot-adding into another bus \n " ) ;
rc = - EINVAL ;
goto error_nopower ;
}
rc = power_on ( slot_cur ) ;
if ( rc ) {
err ( " something wrong when powering up... please see below for details \n " ) ;
/* need to turn off before on, otherwise, blinking overwrites */
attn_off ( slot_cur ) ;
attn_on ( slot_cur ) ;
if ( slot_update ( & slot_cur ) ) {
attn_off ( slot_cur ) ;
attn_on ( slot_cur ) ;
rc = - ENODEV ;
goto exit ;
}
/* Check to see the error of why it failed */
if ( ( SLOT_POWER ( slot_cur - > status ) ) & &
! ( SLOT_PWRGD ( slot_cur - > status ) ) )
err ( " power fault occurred trying to power up \n " ) ;
else if ( SLOT_BUS_SPEED ( slot_cur - > status ) ) {
2014-04-19 04:13:50 +04:00
err ( " bus speed mismatch occurred. please check current bus speed and card capability \n " ) ;
2005-04-17 02:20:36 +04:00
print_card_capability ( slot_cur ) ;
} else if ( SLOT_BUS_MODE ( slot_cur - > ext_status ) ) {
2014-04-19 04:13:50 +04:00
err ( " bus mode mismatch occurred. please check current bus mode and card capability \n " ) ;
2005-04-17 02:20:36 +04:00
print_card_capability ( slot_cur ) ;
}
ibmphp_update_slot_info ( slot_cur ) ;
goto exit ;
}
debug ( " after power_on \n " ) ;
/*-----------------------debugging---------------------------*/
get_cur_bus_info ( & slot_cur ) ;
debug ( " the current bus speed right after power_on = %x \n " ,
slot_cur - > bus_on - > current_speed ) ;
/*----------------------------------------------------------*/
rc = slot_update ( & slot_cur ) ;
if ( rc )
goto error_power ;
2013-11-14 22:28:18 +04:00
2005-04-17 02:20:36 +04:00
rc = - EINVAL ;
if ( SLOT_POWER ( slot_cur - > status ) & & ! ( SLOT_PWRGD ( slot_cur - > status ) ) ) {
err ( " power fault occurred trying to power up... \n " ) ;
goto error_power ;
}
if ( SLOT_POWER ( slot_cur - > status ) & & ( SLOT_BUS_SPEED ( slot_cur - > status ) ) ) {
2014-04-19 04:13:50 +04:00
err ( " bus speed mismatch occurred. please check current bus speed and card capability \n " ) ;
2005-04-17 02:20:36 +04:00
print_card_capability ( slot_cur ) ;
goto error_power ;
2013-11-14 22:28:18 +04:00
}
2005-04-17 02:20:36 +04:00
/* Don't think this case will happen after above checks...
* but just in case , for paranoia sake */
if ( ! ( SLOT_POWER ( slot_cur - > status ) ) ) {
err ( " power on failed... \n " ) ;
goto error_power ;
}
2006-02-28 17:34:49 +03:00
slot_cur - > func = kzalloc ( sizeof ( struct pci_func ) , GFP_KERNEL ) ;
2005-04-17 02:20:36 +04:00
if ( ! slot_cur - > func ) {
PCI: hotplug: Drop hotplug_slot_info
Ever since the PCI hotplug core was introduced in 2002, drivers had to
allocate and register a struct hotplug_slot_info for every slot:
https://git.kernel.org/tglx/history/c/a8a2069f432c
Apparently the idea was that drivers furnish the hotplug core with an
up-to-date card presence status, power status, latch status and
attention indicator status as well as notify the hotplug core of changes
thereof. However only 4 out of 12 hotplug drivers bother to notify the
hotplug core with pci_hp_change_slot_info() and the hotplug core never
made any use of the information: There is just a single macro in
pci_hotplug_core.c, GET_STATUS(), which uses the hotplug_slot_info if
the driver lacks the corresponding callback in hotplug_slot_ops. The
macro is called when the user reads the attribute via sysfs.
Now, if the callback isn't defined, the attribute isn't exposed in sysfs
in the first place (see e.g. has_power_file()). There are only two
situations when the hotplug_slot_info would actually be accessed:
* If the driver defines ->enable_slot or ->disable_slot but not
->get_power_status.
* If the driver defines ->set_attention_status but not
->get_attention_status.
There is no driver doing the former and just a single driver doing the
latter, namely pnv_php.c. Amend it with a ->get_attention_status
callback. With that, the hotplug_slot_info becomes completely unused by
the PCI hotplug core. But a few drivers use it internally as a cache:
cpcihp uses it to cache the latch_status and adapter_status.
cpqhp uses it to cache the adapter_status.
pnv_php and rpaphp use it to cache the attention_status.
shpchp uses it to cache all four values.
Amend these drivers to cache the information in their private slot
struct. shpchp's slot struct already contains members to cache the
power_status and adapter_status, so additional members are only needed
for the other two values. In the case of cpqphp, the cached value is
only accessed in a single place, so instead of caching it, read the
current value from the hardware.
Caution: acpiphp, cpci, cpqhp, shpchp, asus-wmi and eeepc-laptop
populate the hotplug_slot_info with initial values on probe. That code
is herewith removed. There is a theoretical chance that the code has
side effects without which the driver fails to function, e.g. if the
ACPI method to read the adapter status needs to be executed at least
once on probe. That seems unlikely to me, still maintainers should
review the changes carefully for this possibility.
Rafael adds: "I'm not aware of any case in which it will break anything,
[...] but if that happens, it may be necessary to add the execution of
the control methods in question directly to the initialization part."
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com> # drivers/pci/hotplug/rpa*
Acked-by: Sebastian Ott <sebott@linux.ibm.com> # drivers/pci/hotplug/s390*
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> # drivers/platform/x86
Cc: Len Brown <lenb@kernel.org>
Cc: Scott Murray <scott@spiteful.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Oliver OHalloran <oliveroh@au1.ibm.com>
Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Cc: Corentin Chary <corentin.chary@gmail.com>
Cc: Darren Hart <dvhart@infradead.org>
2018-09-08 10:59:01 +03:00
/* do update_slot_info here? */
2005-04-17 02:20:36 +04:00
rc = - ENOMEM ;
goto error_power ;
}
slot_cur - > func - > busno = slot_cur - > bus ;
slot_cur - > func - > device = slot_cur - > device ;
for ( i = 0 ; i < 4 ; i + + )
slot_cur - > func - > irq [ i ] = slot_cur - > irq [ i ] ;
debug ( " b4 configure_card, slot_cur->bus = %x, slot_cur->device = %x \n " ,
slot_cur - > bus , slot_cur - > device ) ;
if ( ibmphp_configure_card ( slot_cur - > func , slot_cur - > number ) ) {
err ( " configure_card was unsuccessful... \n " ) ;
/* true because don't need to actually deallocate resources,
* just remove references */
ibmphp_unconfigure_card ( & slot_cur , 1 ) ;
debug ( " after unconfigure_card \n " ) ;
slot_cur - > func = NULL ;
rc = - ENOMEM ;
goto error_power ;
}
function = 0x00 ;
do {
tmp_func = ibm_slot_find ( slot_cur - > bus , slot_cur - > func - > device ,
function + + ) ;
if ( tmp_func & & ! ( tmp_func - > dev ) )
ibm_configure_device ( tmp_func ) ;
} while ( tmp_func ) ;
attn_off ( slot_cur ) ;
if ( slot_update ( & slot_cur ) ) {
rc = - EFAULT ;
goto exit ;
}
ibmphp_print_test ( ) ;
rc = ibmphp_update_slot_info ( slot_cur ) ;
exit :
2013-11-14 22:28:18 +04:00
ibmphp_unlock_operations ( ) ;
2005-04-17 02:20:36 +04:00
return rc ;
error_nopower :
attn_off ( slot_cur ) ; /* need to turn off if was blinking b4 */
attn_on ( slot_cur ) ;
error_cont :
rcpr = slot_update ( & slot_cur ) ;
if ( rcpr ) {
rc = rcpr ;
goto exit ;
}
ibmphp_update_slot_info ( slot_cur ) ;
goto exit ;
error_power :
attn_off ( slot_cur ) ; /* need to turn off if was blinking b4 */
attn_on ( slot_cur ) ;
rcpr = power_off ( slot_cur ) ;
if ( rcpr ) {
rc = rcpr ;
goto exit ;
}
goto error_cont ;
}
/**************************************************************
* HOT REMOVING ADAPTER CARD *
* INPUT : POINTER TO THE HOTPLUG SLOT STRUCTURE *
* OUTPUT : SUCCESS 0 ; FAILURE : UNCONFIGURE , VALIDATE *
2015-12-28 00:21:11 +03:00
* DISABLE POWER , *
2005-04-17 02:20:36 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int ibmphp_disable_slot ( struct hotplug_slot * hotplug_slot )
{
2018-09-08 10:59:01 +03:00
struct slot * slot = to_slot ( hotplug_slot ) ;
2005-04-17 02:20:36 +04:00
int rc ;
2013-11-14 22:28:18 +04:00
2005-04-17 02:20:36 +04:00
ibmphp_lock_operations ( ) ;
rc = ibmphp_do_disable_slot ( slot ) ;
ibmphp_unlock_operations ( ) ;
return rc ;
}
int ibmphp_do_disable_slot ( struct slot * slot_cur )
{
int rc ;
u8 flag ;
2013-11-14 22:28:18 +04:00
debug ( " DISABLING SLOT... \n " ) ;
2014-09-07 22:02:47 +04:00
if ( ( slot_cur = = NULL ) | | ( slot_cur - > ctrl = = NULL ) )
2005-04-17 02:20:36 +04:00
return - ENODEV ;
2013-11-14 22:28:18 +04:00
2005-04-17 02:20:36 +04:00
flag = slot_cur - > flag ;
2006-03-15 03:24:47 +03:00
slot_cur - > flag = 1 ;
2005-04-17 02:20:36 +04:00
2006-03-15 03:24:47 +03:00
if ( flag = = 1 ) {
2005-04-17 02:20:36 +04:00
rc = validate ( slot_cur , DISABLE ) ;
/* checking if powered off already & valid slot # */
if ( rc )
goto error ;
}
attn_LED_blink ( slot_cur ) ;
if ( slot_cur - > func = = NULL ) {
2013-11-14 22:28:18 +04:00
/* We need this for functions that were there on bootup */
2006-02-28 17:34:49 +03:00
slot_cur - > func = kzalloc ( sizeof ( struct pci_func ) , GFP_KERNEL ) ;
2005-04-17 02:20:36 +04:00
if ( ! slot_cur - > func ) {
rc = - ENOMEM ;
goto error ;
}
slot_cur - > func - > busno = slot_cur - > bus ;
slot_cur - > func - > device = slot_cur - > device ;
}
ibm_unconfigure_device ( slot_cur - > func ) ;
2013-11-14 22:28:18 +04:00
/*
* If we got here from latch suddenly opening on operating card or
* a power fault , there ' s no power to the card , so cannot
* read from it to determine what resources it occupied . This operation
* is forbidden anyhow . The best we can do is remove it from kernel
* lists at least */
2005-04-17 02:20:36 +04:00
if ( ! flag ) {
attn_off ( slot_cur ) ;
return 0 ;
}
rc = ibmphp_unconfigure_card ( & slot_cur , 0 ) ;
slot_cur - > func = NULL ;
debug ( " in disable_slot. after unconfigure_card \n " ) ;
if ( rc ) {
err ( " could not unconfigure card. \n " ) ;
goto error ;
}
rc = ibmphp_hpc_writeslot ( slot_cur , HPC_SLOT_OFF ) ;
if ( rc )
goto error ;
attn_off ( slot_cur ) ;
rc = slot_update ( & slot_cur ) ;
if ( rc )
goto exit ;
rc = ibmphp_update_slot_info ( slot_cur ) ;
ibmphp_print_test ( ) ;
exit :
return rc ;
error :
/* Need to turn off if was blinking b4 */
attn_off ( slot_cur ) ;
attn_on ( slot_cur ) ;
if ( slot_update ( & slot_cur ) ) {
rc = - EFAULT ;
goto exit ;
}
2013-11-14 22:28:18 +04:00
if ( flag )
2005-04-17 02:20:36 +04:00
ibmphp_update_slot_info ( slot_cur ) ;
goto exit ;
}
2018-09-08 10:59:01 +03:00
const struct hotplug_slot_ops ibmphp_hotplug_slot_ops = {
2005-04-17 02:20:36 +04:00
. set_attention_status = set_attention_status ,
. enable_slot = enable_slot ,
. disable_slot = ibmphp_disable_slot ,
. hardware_test = NULL ,
. get_power_status = get_power_status ,
. get_attention_status = get_attention_status ,
. get_latch_status = get_latch_status ,
. get_adapter_status = get_adapter_present ,
} ;
static void ibmphp_unload ( void )
{
free_slots ( ) ;
debug ( " after slots \n " ) ;
ibmphp_free_resources ( ) ;
debug ( " after resources \n " ) ;
ibmphp_free_bus_info_queue ( ) ;
debug ( " after bus info \n " ) ;
ibmphp_free_ebda_hpc_queue ( ) ;
debug ( " after ebda hpc \n " ) ;
ibmphp_free_ebda_pci_rsrc_queue ( ) ;
debug ( " after ebda pci rsrc \n " ) ;
kfree ( ibmphp_pci_bus ) ;
}
static int __init ibmphp_init ( void )
{
struct pci_bus * bus ;
int i = 0 ;
int rc = 0 ;
init_flag = 1 ;
info ( DRIVER_DESC " version: " DRIVER_VERSION " \n " ) ;
ibmphp_pci_bus = kmalloc ( sizeof ( * ibmphp_pci_bus ) , GFP_KERNEL ) ;
if ( ! ibmphp_pci_bus ) {
rc = - ENOMEM ;
goto exit ;
}
bus = pci_find_bus ( 0 , 0 ) ;
if ( ! bus ) {
err ( " Can't find the root pci bus, can not continue \n " ) ;
rc = - ENODEV ;
goto error ;
}
memcpy ( ibmphp_pci_bus , bus , sizeof ( * ibmphp_pci_bus ) ) ;
ibmphp_debug = debug ;
for ( i = 0 ; i < 16 ; i + + )
irqs [ i ] = 0 ;
2014-09-07 22:03:32 +04:00
rc = ibmphp_access_ebda ( ) ;
if ( rc )
2005-04-17 02:20:36 +04:00
goto error ;
debug ( " after ibmphp_access_ebda() \n " ) ;
2014-09-07 22:03:32 +04:00
rc = ibmphp_rsrc_init ( ) ;
if ( rc )
2005-04-17 02:20:36 +04:00
goto error ;
debug ( " AFTER Resource & EBDA INITIALIZATIONS \n " ) ;
max_slots = get_max_slots ( ) ;
2013-11-14 22:28:18 +04:00
2014-09-07 22:03:32 +04:00
rc = ibmphp_register_pci ( ) ;
if ( rc )
2005-04-17 02:20:36 +04:00
goto error ;
if ( init_ops ( ) ) {
rc = - ENODEV ;
goto error ;
}
ibmphp_print_test ( ) ;
2014-09-07 22:03:32 +04:00
rc = ibmphp_hpc_start_poll_thread ( ) ;
if ( rc )
2005-04-17 02:20:36 +04:00
goto error ;
exit :
return rc ;
error :
ibmphp_unload ( ) ;
goto exit ;
}
static void __exit ibmphp_exit ( void )
{
ibmphp_hpc_stop_poll_thread ( ) ;
debug ( " after polling \n " ) ;
ibmphp_unload ( ) ;
debug ( " done \n " ) ;
}
module_init ( ibmphp_init ) ;
2009-04-16 01:24:08 +04:00
module_exit ( ibmphp_exit ) ;