1 /************************************************************************/
2 /* File iSeries_pci_reset.c created by Allan Trautman on Mar 21 2001.   */
3 /************************************************************************/
4 /* This code supports the pci interface on the IBM iSeries systems.     */
5 /* Copyright (C) 20yy  <Allan H Trautman> <IBM Corp>                    */
6 /*                                                                      */
7 /* This program is free software; you can redistribute it and/or modify */
8 /* it under the terms of the GNU General Public License as published by */
9 /* the Free Software Foundation; either version 2 of the License, or    */
10 /* (at your option) any later version.                                  */
11 /*                                                                      */
12 /* This program is distributed in the hope that it will be useful,      */
13 /* but WITHOUT ANY WARRANTY; without even the implied warranty of       */
14 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        */
15 /* GNU General Public License for more details.                         */
16 /*                                                                      */
17 /* You should have received a copy of the GNU General Public License    */
18 /* along with this program; if not, write to the:                       */
19 /* Free Software Foundation, Inc.,                                      */
20 /* 59 Temple Place, Suite 330,                                          */
21 /* Boston, MA  02111-1307  USA                                          */
22 /************************************************************************/
23 /* Change Activity:                                                     */
24 /*   Created, March 20, 2001                                            */
25 /*   April 30, 2001, Added return codes on functions.                   */
26 /*   September 10, 2001, Ported to ppc64.                               */
27 /* End Change Activity                                                  */
28 /************************************************************************/
29 #include <linux/kernel.h>
30 #include <linux/init.h>
31 #include <linux/pci.h>
32 #include <linux/irq.h>
33 
34 #include <asm/io.h>
35 #include <asm/init.h>
36 #include <asm/iSeries/HvCallPci.h>
37 #include <asm/iSeries/HvTypes.h>
38 #include <asm/iSeries/mf.h>
39 #include <asm/flight_recorder.h>
40 #include <asm/pci.h>
41 
42 #include <asm/iSeries/iSeries_pci.h>
43 #include "pci.h"
44 
45 /************************************************************************/
46 /* Interface to toggle the reset line                                   */
47 /* Time is in .1 seconds, need for seconds.                             */
48 /************************************************************************/
iSeries_Device_ToggleReset(struct pci_dev * PciDev,int AssertTime,int DelayTime)49 int  iSeries_Device_ToggleReset(struct pci_dev* PciDev, int AssertTime, int DelayTime)
50 {
51 	unsigned long AssertDelay, WaitDelay;
52 	struct iSeries_Device_Node* DeviceNode = (struct iSeries_Device_Node*)PciDev->sysdata;
53  	if (DeviceNode == NULL) {
54 		printk("PCI: Pci Reset Failed, Device Node not found for pci_dev %p\n",PciDev);
55 		return -1;
56 	}
57 	/********************************************************************
58 	 * Set defaults, Assert is .5 second, Wait is 3 seconds.
59 	 ********************************************************************/
60 	if (AssertTime == 0) AssertDelay = ( 5 * HZ)/10;
61 	else                 AssertDelay = (AssertTime*HZ)/10;
62 	if (WaitDelay == 0)  WaitDelay   = (30 * HZ)/10;
63 	else                 WaitDelay   = (DelayTime* HZ)/10;
64 
65 	/********************************************************************
66 	 * Assert reset
67 	 ********************************************************************/
68 	DeviceNode->ReturnCode = HvCallPci_setSlotReset(ISERIES_BUS(DeviceNode),0x00,DeviceNode->AgentId,1);
69 	if (DeviceNode->ReturnCode == 0) {
70 		set_current_state(TASK_UNINTERRUPTIBLE);
71 		schedule_timeout(AssertDelay);       /* Sleep for the time     */
72 		DeviceNode->ReturnCode = HvCallPci_setSlotReset(ISERIES_BUS(DeviceNode),0x00,DeviceNode->AgentId, 0);
73 
74 		/***************************************************************
75    		 * Wait for device to reset
76 		 ***************************************************************/
77 		set_current_state(TASK_UNINTERRUPTIBLE);
78 		schedule_timeout(WaitDelay);
79 	}
80 	if (DeviceNode->ReturnCode == 0) {
81 		PCIFR("Slot 0x%04X.%02X Reset\n",ISERIES_BUS(DeviceNode),DeviceNode->AgentId );
82 	}
83 	else {
84 		printk("PCI: Slot 0x%04X.%02X Reset Failed, RCode: %04X\n",ISERIES_BUS(DeviceNode),DeviceNode->AgentId,DeviceNode->ReturnCode);
85 		PCIFR(      "Slot 0x%04X.%02X Reset Failed, RCode: %04X\n",ISERIES_BUS(DeviceNode),DeviceNode->AgentId,DeviceNode->ReturnCode);
86 	}
87 	return DeviceNode->ReturnCode;
88 }
89