Bjorn Helgaas | 736759e | 2018-01-26 14:22:04 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * IBM Hot Plug Controller Driver |
| 4 | * |
| 5 | * Written By: Jyoti Shah, IBM Corporation |
| 6 | * |
| 7 | * Copyright (C) 2001-2003 IBM Corp. |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Send feedback to <gregkh@us.ibm.com> |
| 12 | * <jshah@us.ibm.com> |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/wait.h> |
| 17 | #include <linux/time.h> |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 18 | #include <linux/completion.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/delay.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 23 | #include <linux/mutex.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 24 | #include <linux/sched.h> |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 25 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "ibmphp.h" |
| 27 | |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 28 | static int to_debug = 0; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 29 | #define debug_polling(fmt, arg...) do { if (to_debug) debug(fmt, arg); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | //---------------------------------------------------------------------------- |
| 32 | // timeout values |
| 33 | //---------------------------------------------------------------------------- |
| 34 | #define CMD_COMPLETE_TOUT_SEC 60 // give HPC 60 sec to finish cmd |
| 35 | #define HPC_CTLR_WORKING_TOUT 60 // give HPC 60 sec to finish cmd |
| 36 | #define HPC_GETACCESS_TIMEOUT 60 // seconds |
| 37 | #define POLL_INTERVAL_SEC 2 // poll HPC every 2 seconds |
| 38 | #define POLL_LATCH_CNT 5 // poll latch 5 times, then poll slots |
| 39 | |
| 40 | //---------------------------------------------------------------------------- |
| 41 | // Winnipeg Architected Register Offsets |
| 42 | //---------------------------------------------------------------------------- |
| 43 | #define WPG_I2CMBUFL_OFFSET 0x08 // I2C Message Buffer Low |
| 44 | #define WPG_I2CMOSUP_OFFSET 0x10 // I2C Master Operation Setup Reg |
| 45 | #define WPG_I2CMCNTL_OFFSET 0x20 // I2C Master Control Register |
| 46 | #define WPG_I2CPARM_OFFSET 0x40 // I2C Parameter Register |
| 47 | #define WPG_I2CSTAT_OFFSET 0x70 // I2C Status Register |
| 48 | |
| 49 | //---------------------------------------------------------------------------- |
| 50 | // Winnipeg Store Type commands (Add this commands to the register offset) |
| 51 | //---------------------------------------------------------------------------- |
| 52 | #define WPG_I2C_AND 0x1000 // I2C AND operation |
| 53 | #define WPG_I2C_OR 0x2000 // I2C OR operation |
| 54 | |
| 55 | //---------------------------------------------------------------------------- |
Steven Cole | eaae4b3 | 2005-05-03 18:38:30 -0600 | [diff] [blame] | 56 | // Command set for I2C Master Operation Setup Register |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | //---------------------------------------------------------------------------- |
| 58 | #define WPG_READATADDR_MASK 0x00010000 // read,bytes,I2C shifted,index |
| 59 | #define WPG_WRITEATADDR_MASK 0x40010000 // write,bytes,I2C shifted,index |
| 60 | #define WPG_READDIRECT_MASK 0x10010000 |
| 61 | #define WPG_WRITEDIRECT_MASK 0x60010000 |
| 62 | |
| 63 | |
| 64 | //---------------------------------------------------------------------------- |
| 65 | // bit masks for I2C Master Control Register |
| 66 | //---------------------------------------------------------------------------- |
| 67 | #define WPG_I2CMCNTL_STARTOP_MASK 0x00000002 // Start the Operation |
| 68 | |
| 69 | //---------------------------------------------------------------------------- |
| 70 | // |
| 71 | //---------------------------------------------------------------------------- |
| 72 | #define WPG_I2C_IOREMAP_SIZE 0x2044 // size of linear address interval |
| 73 | |
| 74 | //---------------------------------------------------------------------------- |
| 75 | // command index |
| 76 | //---------------------------------------------------------------------------- |
| 77 | #define WPG_1ST_SLOT_INDEX 0x01 // index - 1st slot for ctlr |
| 78 | #define WPG_CTLR_INDEX 0x0F // index - ctlr |
| 79 | #define WPG_1ST_EXTSLOT_INDEX 0x10 // index - 1st ext slot for ctlr |
| 80 | #define WPG_1ST_BUS_INDEX 0x1F // index - 1st bus for ctlr |
| 81 | |
| 82 | //---------------------------------------------------------------------------- |
| 83 | // macro utilities |
| 84 | //---------------------------------------------------------------------------- |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 85 | // if bits 20,22,25,26,27,29,30 are OFF return 1 |
| 86 | #define HPC_I2CSTATUS_CHECK(s) ((u8)((s & 0x00000A76) ? 0 : 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | //---------------------------------------------------------------------------- |
| 89 | // global variables |
| 90 | //---------------------------------------------------------------------------- |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 91 | static DEFINE_MUTEX(sem_hpcaccess); // lock access to HPC |
| 92 | static DEFINE_MUTEX(operations_mutex); // lock all operations and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | // access to data structures |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 94 | static DECLARE_COMPLETION(exit_complete); // make sure polling thread goes away |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 95 | static struct task_struct *ibmphp_poll_thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | //---------------------------------------------------------------------------- |
| 97 | // local function prototypes |
| 98 | //---------------------------------------------------------------------------- |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 99 | static u8 i2c_ctrl_read(struct controller *, void __iomem *, u8); |
| 100 | static u8 i2c_ctrl_write(struct controller *, void __iomem *, u8, u8); |
| 101 | static u8 hpc_writecmdtoindex(u8, u8); |
| 102 | static u8 hpc_readcmdtoindex(u8, u8); |
| 103 | static void get_hpc_access(void); |
| 104 | static void free_hpc_access(void); |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 105 | static int poll_hpc(void *data); |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 106 | static int process_changeinstatus(struct slot *, struct slot *); |
| 107 | static int process_changeinlatch(u8, u8, struct controller *); |
| 108 | static int hpc_wait_ctlr_notworking(int, struct controller *, void __iomem *, u8 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | //---------------------------------------------------------------------------- |
| 110 | |
| 111 | |
| 112 | /*---------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | * Name: i2c_ctrl_read |
| 114 | * |
| 115 | * Action: read from HPC over I2C |
| 116 | * |
| 117 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 118 | static u8 i2c_ctrl_read(struct controller *ctlr_ptr, void __iomem *WPGBbar, u8 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
| 120 | u8 status; |
| 121 | int i; |
| 122 | void __iomem *wpg_addr; // base addr + offset |
| 123 | unsigned long wpg_data; // data to/from WPG LOHI format |
| 124 | unsigned long ultemp; |
| 125 | unsigned long data; // actual data HILO format |
| 126 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 127 | debug_polling("%s - Entry WPGBbar[%p] index[%x] \n", __func__, WPGBbar, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | //-------------------------------------------------------------------- |
| 130 | // READ - step 1 |
| 131 | // read at address, byte length, I2C address (shifted), index |
| 132 | // or read direct, byte length, index |
| 133 | if (ctlr_ptr->ctlr_type == 0x02) { |
| 134 | data = WPG_READATADDR_MASK; |
| 135 | // fill in I2C address |
| 136 | ultemp = (unsigned long)ctlr_ptr->u.wpeg_ctlr.i2c_addr; |
| 137 | ultemp = ultemp >> 1; |
| 138 | data |= (ultemp << 8); |
| 139 | |
| 140 | // fill in index |
| 141 | data |= (unsigned long)index; |
| 142 | } else if (ctlr_ptr->ctlr_type == 0x04) { |
| 143 | data = WPG_READDIRECT_MASK; |
| 144 | |
| 145 | // fill in index |
| 146 | ultemp = (unsigned long)index; |
| 147 | ultemp = ultemp << 8; |
| 148 | data |= ultemp; |
| 149 | } else { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 150 | err("this controller type is not supported \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | return HPC_ERROR; |
| 152 | } |
| 153 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 154 | wpg_data = swab32(data); // swap data before writing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | wpg_addr = WPGBbar + WPG_I2CMOSUP_OFFSET; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 156 | writel(wpg_data, wpg_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | //-------------------------------------------------------------------- |
| 159 | // READ - step 2 : clear the message buffer |
| 160 | data = 0x00000000; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 161 | wpg_data = swab32(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | wpg_addr = WPGBbar + WPG_I2CMBUFL_OFFSET; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 163 | writel(wpg_data, wpg_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | //-------------------------------------------------------------------- |
| 166 | // READ - step 3 : issue start operation, I2C master control bit 30:ON |
| 167 | // 2020 : [20] OR operation at [20] offset 0x20 |
| 168 | data = WPG_I2CMCNTL_STARTOP_MASK; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 169 | wpg_data = swab32(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | wpg_addr = WPGBbar + WPG_I2CMCNTL_OFFSET + WPG_I2C_OR; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 171 | writel(wpg_data, wpg_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | //-------------------------------------------------------------------- |
| 174 | // READ - step 4 : wait until start operation bit clears |
| 175 | i = CMD_COMPLETE_TOUT_SEC; |
| 176 | while (i) { |
| 177 | msleep(10); |
| 178 | wpg_addr = WPGBbar + WPG_I2CMCNTL_OFFSET; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 179 | wpg_data = readl(wpg_addr); |
| 180 | data = swab32(wpg_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (!(data & WPG_I2CMCNTL_STARTOP_MASK)) |
| 182 | break; |
| 183 | i--; |
| 184 | } |
| 185 | if (i == 0) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 186 | debug("%s - Error : WPG timeout\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | return HPC_ERROR; |
| 188 | } |
| 189 | //-------------------------------------------------------------------- |
| 190 | // READ - step 5 : read I2C status register |
| 191 | i = CMD_COMPLETE_TOUT_SEC; |
| 192 | while (i) { |
| 193 | msleep(10); |
| 194 | wpg_addr = WPGBbar + WPG_I2CSTAT_OFFSET; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 195 | wpg_data = readl(wpg_addr); |
| 196 | data = swab32(wpg_data); |
| 197 | if (HPC_I2CSTATUS_CHECK(data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | break; |
| 199 | i--; |
| 200 | } |
| 201 | if (i == 0) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 202 | debug("ctrl_read - Exit Error:I2C timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | return HPC_ERROR; |
| 204 | } |
| 205 | |
| 206 | //-------------------------------------------------------------------- |
| 207 | // READ - step 6 : get DATA |
| 208 | wpg_addr = WPGBbar + WPG_I2CMBUFL_OFFSET; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 209 | wpg_data = readl(wpg_addr); |
| 210 | data = swab32(wpg_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | status = (u8) data; |
| 213 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 214 | debug_polling("%s - Exit index[%x] status[%x]\n", __func__, index, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | return (status); |
| 217 | } |
| 218 | |
| 219 | /*---------------------------------------------------------------------- |
| 220 | * Name: i2c_ctrl_write |
| 221 | * |
| 222 | * Action: write to HPC over I2C |
| 223 | * |
| 224 | * Return 0 or error codes |
| 225 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 226 | static u8 i2c_ctrl_write(struct controller *ctlr_ptr, void __iomem *WPGBbar, u8 index, u8 cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | u8 rc; |
| 229 | void __iomem *wpg_addr; // base addr + offset |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 230 | unsigned long wpg_data; // data to/from WPG LOHI format |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | unsigned long ultemp; |
| 232 | unsigned long data; // actual data HILO format |
| 233 | int i; |
| 234 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 235 | debug_polling("%s - Entry WPGBbar[%p] index[%x] cmd[%x]\n", __func__, WPGBbar, index, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | rc = 0; |
| 238 | //-------------------------------------------------------------------- |
| 239 | // WRITE - step 1 |
| 240 | // write at address, byte length, I2C address (shifted), index |
| 241 | // or write direct, byte length, index |
| 242 | data = 0x00000000; |
| 243 | |
| 244 | if (ctlr_ptr->ctlr_type == 0x02) { |
| 245 | data = WPG_WRITEATADDR_MASK; |
| 246 | // fill in I2C address |
| 247 | ultemp = (unsigned long)ctlr_ptr->u.wpeg_ctlr.i2c_addr; |
| 248 | ultemp = ultemp >> 1; |
| 249 | data |= (ultemp << 8); |
| 250 | |
| 251 | // fill in index |
| 252 | data |= (unsigned long)index; |
| 253 | } else if (ctlr_ptr->ctlr_type == 0x04) { |
| 254 | data = WPG_WRITEDIRECT_MASK; |
| 255 | |
| 256 | // fill in index |
| 257 | ultemp = (unsigned long)index; |
| 258 | ultemp = ultemp << 8; |
| 259 | data |= ultemp; |
| 260 | } else { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 261 | err("this controller type is not supported \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return HPC_ERROR; |
| 263 | } |
| 264 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 265 | wpg_data = swab32(data); // swap data before writing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | wpg_addr = WPGBbar + WPG_I2CMOSUP_OFFSET; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 267 | writel(wpg_data, wpg_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | //-------------------------------------------------------------------- |
| 270 | // WRITE - step 2 : clear the message buffer |
| 271 | data = 0x00000000 | (unsigned long)cmd; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 272 | wpg_data = swab32(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | wpg_addr = WPGBbar + WPG_I2CMBUFL_OFFSET; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 274 | writel(wpg_data, wpg_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
| 276 | //-------------------------------------------------------------------- |
| 277 | // WRITE - step 3 : issue start operation,I2C master control bit 30:ON |
| 278 | // 2020 : [20] OR operation at [20] offset 0x20 |
| 279 | data = WPG_I2CMCNTL_STARTOP_MASK; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 280 | wpg_data = swab32(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | wpg_addr = WPGBbar + WPG_I2CMCNTL_OFFSET + WPG_I2C_OR; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 282 | writel(wpg_data, wpg_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | //-------------------------------------------------------------------- |
| 285 | // WRITE - step 4 : wait until start operation bit clears |
| 286 | i = CMD_COMPLETE_TOUT_SEC; |
| 287 | while (i) { |
| 288 | msleep(10); |
| 289 | wpg_addr = WPGBbar + WPG_I2CMCNTL_OFFSET; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 290 | wpg_data = readl(wpg_addr); |
| 291 | data = swab32(wpg_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | if (!(data & WPG_I2CMCNTL_STARTOP_MASK)) |
| 293 | break; |
| 294 | i--; |
| 295 | } |
| 296 | if (i == 0) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 297 | debug("%s - Exit Error:WPG timeout\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | rc = HPC_ERROR; |
| 299 | } |
| 300 | |
| 301 | //-------------------------------------------------------------------- |
| 302 | // WRITE - step 5 : read I2C status register |
| 303 | i = CMD_COMPLETE_TOUT_SEC; |
| 304 | while (i) { |
| 305 | msleep(10); |
| 306 | wpg_addr = WPGBbar + WPG_I2CSTAT_OFFSET; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 307 | wpg_data = readl(wpg_addr); |
| 308 | data = swab32(wpg_data); |
| 309 | if (HPC_I2CSTATUS_CHECK(data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | break; |
| 311 | i--; |
| 312 | } |
| 313 | if (i == 0) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 314 | debug("ctrl_read - Error : I2C timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | rc = HPC_ERROR; |
| 316 | } |
| 317 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 318 | debug_polling("%s Exit rc[%x]\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | return (rc); |
| 320 | } |
| 321 | |
| 322 | //------------------------------------------------------------ |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 323 | // Read from ISA type HPC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | //------------------------------------------------------------ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 325 | static u8 isa_ctrl_read(struct controller *ctlr_ptr, u8 offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
| 327 | u16 start_address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | u8 data; |
| 329 | |
| 330 | start_address = ctlr_ptr->u.isa_ctlr.io_start; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 331 | data = inb(start_address + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | return data; |
| 333 | } |
| 334 | |
| 335 | //-------------------------------------------------------------- |
| 336 | // Write to ISA type HPC |
| 337 | //-------------------------------------------------------------- |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 338 | static void isa_ctrl_write(struct controller *ctlr_ptr, u8 offset, u8 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
| 340 | u16 start_address; |
| 341 | u16 port_address; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | start_address = ctlr_ptr->u.isa_ctlr.io_start; |
| 344 | port_address = start_address + (u16) offset; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 345 | outb(data, port_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 348 | static u8 pci_ctrl_read(struct controller *ctrl, u8 offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
| 350 | u8 data = 0x00; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 351 | debug("inside pci_ctrl_read\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | if (ctrl->ctrl_dev) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 353 | pci_read_config_byte(ctrl->ctrl_dev, HPC_PCI_OFFSET + offset, &data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | return data; |
| 355 | } |
| 356 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 357 | static u8 pci_ctrl_write(struct controller *ctrl, u8 offset, u8 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
| 359 | u8 rc = -ENODEV; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 360 | debug("inside pci_ctrl_write\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | if (ctrl->ctrl_dev) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 362 | pci_write_config_byte(ctrl->ctrl_dev, HPC_PCI_OFFSET + offset, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | rc = 0; |
| 364 | } |
| 365 | return rc; |
| 366 | } |
| 367 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 368 | static u8 ctrl_read(struct controller *ctlr, void __iomem *base, u8 offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { |
| 370 | u8 rc; |
| 371 | switch (ctlr->ctlr_type) { |
| 372 | case 0: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 373 | rc = isa_ctrl_read(ctlr, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | break; |
| 375 | case 1: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 376 | rc = pci_ctrl_read(ctlr, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | break; |
| 378 | case 2: |
| 379 | case 4: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 380 | rc = i2c_ctrl_read(ctlr, base, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | break; |
| 382 | default: |
| 383 | return -ENODEV; |
| 384 | } |
| 385 | return rc; |
| 386 | } |
| 387 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 388 | static u8 ctrl_write(struct controller *ctlr, void __iomem *base, u8 offset, u8 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | { |
| 390 | u8 rc = 0; |
| 391 | switch (ctlr->ctlr_type) { |
| 392 | case 0: |
| 393 | isa_ctrl_write(ctlr, offset, data); |
| 394 | break; |
| 395 | case 1: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 396 | rc = pci_ctrl_write(ctlr, offset, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | break; |
| 398 | case 2: |
| 399 | case 4: |
| 400 | rc = i2c_ctrl_write(ctlr, base, offset, data); |
| 401 | break; |
| 402 | default: |
| 403 | return -ENODEV; |
| 404 | } |
| 405 | return rc; |
| 406 | } |
| 407 | /*---------------------------------------------------------------------- |
| 408 | * Name: hpc_writecmdtoindex() |
| 409 | * |
| 410 | * Action: convert a write command to proper index within a controller |
| 411 | * |
| 412 | * Return index, HPC_ERROR |
| 413 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 414 | static u8 hpc_writecmdtoindex(u8 cmd, u8 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
| 416 | u8 rc; |
| 417 | |
| 418 | switch (cmd) { |
| 419 | case HPC_CTLR_ENABLEIRQ: // 0x00.N.15 |
| 420 | case HPC_CTLR_CLEARIRQ: // 0x06.N.15 |
| 421 | case HPC_CTLR_RESET: // 0x07.N.15 |
| 422 | case HPC_CTLR_IRQSTEER: // 0x08.N.15 |
| 423 | case HPC_CTLR_DISABLEIRQ: // 0x01.N.15 |
| 424 | case HPC_ALLSLOT_ON: // 0x11.N.15 |
| 425 | case HPC_ALLSLOT_OFF: // 0x12.N.15 |
| 426 | rc = 0x0F; |
| 427 | break; |
| 428 | |
| 429 | case HPC_SLOT_OFF: // 0x02.Y.0-14 |
| 430 | case HPC_SLOT_ON: // 0x03.Y.0-14 |
| 431 | case HPC_SLOT_ATTNOFF: // 0x04.N.0-14 |
| 432 | case HPC_SLOT_ATTNON: // 0x05.N.0-14 |
| 433 | case HPC_SLOT_BLINKLED: // 0x13.N.0-14 |
| 434 | rc = index; |
| 435 | break; |
| 436 | |
| 437 | case HPC_BUS_33CONVMODE: |
| 438 | case HPC_BUS_66CONVMODE: |
| 439 | case HPC_BUS_66PCIXMODE: |
| 440 | case HPC_BUS_100PCIXMODE: |
| 441 | case HPC_BUS_133PCIXMODE: |
| 442 | rc = index + WPG_1ST_BUS_INDEX - 1; |
| 443 | break; |
| 444 | |
| 445 | default: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 446 | err("hpc_writecmdtoindex - Error invalid cmd[%x]\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | rc = HPC_ERROR; |
| 448 | } |
| 449 | |
| 450 | return rc; |
| 451 | } |
| 452 | |
| 453 | /*---------------------------------------------------------------------- |
| 454 | * Name: hpc_readcmdtoindex() |
| 455 | * |
| 456 | * Action: convert a read command to proper index within a controller |
| 457 | * |
| 458 | * Return index, HPC_ERROR |
| 459 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 460 | static u8 hpc_readcmdtoindex(u8 cmd, u8 index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
| 462 | u8 rc; |
| 463 | |
| 464 | switch (cmd) { |
| 465 | case READ_CTLRSTATUS: |
| 466 | rc = 0x0F; |
| 467 | break; |
| 468 | case READ_SLOTSTATUS: |
| 469 | case READ_ALLSTAT: |
| 470 | rc = index; |
| 471 | break; |
| 472 | case READ_EXTSLOTSTATUS: |
| 473 | rc = index + WPG_1ST_EXTSLOT_INDEX; |
| 474 | break; |
| 475 | case READ_BUSSTATUS: |
| 476 | rc = index + WPG_1ST_BUS_INDEX - 1; |
| 477 | break; |
| 478 | case READ_SLOTLATCHLOWREG: |
| 479 | rc = 0x28; |
| 480 | break; |
| 481 | case READ_REVLEVEL: |
| 482 | rc = 0x25; |
| 483 | break; |
| 484 | case READ_HPCOPTIONS: |
| 485 | rc = 0x27; |
| 486 | break; |
| 487 | default: |
| 488 | rc = HPC_ERROR; |
| 489 | } |
| 490 | return rc; |
| 491 | } |
| 492 | |
| 493 | /*---------------------------------------------------------------------- |
| 494 | * Name: HPCreadslot() |
| 495 | * |
| 496 | * Action: issue a READ command to HPC |
| 497 | * |
Matt LaPlante | 0779bf2d | 2006-11-30 05:24:39 +0100 | [diff] [blame] | 498 | * Input: pslot - cannot be NULL for READ_ALLSTAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | * pstatus - can be NULL for READ_ALLSTAT |
| 500 | * |
| 501 | * Return 0 or error codes |
| 502 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 503 | int ibmphp_hpc_readslot(struct slot *pslot, u8 cmd, u8 *pstatus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
| 505 | void __iomem *wpg_bbar = NULL; |
| 506 | struct controller *ctlr_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | u8 index, status; |
| 508 | int rc = 0; |
| 509 | int busindex; |
| 510 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 511 | debug_polling("%s - Entry pslot[%p] cmd[%x] pstatus[%p]\n", __func__, pslot, cmd, pstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | if ((pslot == NULL) |
| 514 | || ((pstatus == NULL) && (cmd != READ_ALLSTAT) && (cmd != READ_BUSSTATUS))) { |
| 515 | rc = -EINVAL; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 516 | err("%s - Error invalid pointer, rc[%d]\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | return rc; |
| 518 | } |
| 519 | |
| 520 | if (cmd == READ_BUSSTATUS) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 521 | busindex = ibmphp_get_bus_index(pslot->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | if (busindex < 0) { |
| 523 | rc = -EINVAL; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 524 | err("%s - Exit Error:invalid bus, rc[%d]\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | return rc; |
| 526 | } else |
| 527 | index = (u8) busindex; |
| 528 | } else |
| 529 | index = pslot->ctlr_index; |
| 530 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 531 | index = hpc_readcmdtoindex(cmd, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 533 | if (index == HPC_ERROR) { |
| 534 | rc = -EINVAL; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 535 | err("%s - Exit Error:invalid index, rc[%d]\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | return rc; |
| 537 | } |
| 538 | |
| 539 | ctlr_ptr = pslot->ctrl; |
| 540 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 541 | get_hpc_access(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | //-------------------------------------------------------------------- |
| 544 | // map physical address to logical address |
| 545 | //-------------------------------------------------------------------- |
| 546 | if ((ctlr_ptr->ctlr_type == 2) || (ctlr_ptr->ctlr_type == 4)) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 547 | wpg_bbar = ioremap(ctlr_ptr->u.wpeg_ctlr.wpegbbar, WPG_I2C_IOREMAP_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
| 549 | //-------------------------------------------------------------------- |
| 550 | // check controller status before reading |
| 551 | //-------------------------------------------------------------------- |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 552 | rc = hpc_wait_ctlr_notworking(HPC_CTLR_WORKING_TOUT, ctlr_ptr, wpg_bbar, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | if (!rc) { |
| 554 | switch (cmd) { |
| 555 | case READ_ALLSTAT: |
| 556 | // update the slot structure |
| 557 | pslot->ctrl->status = status; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 558 | pslot->status = ctrl_read(ctlr_ptr, wpg_bbar, index); |
| 559 | rc = hpc_wait_ctlr_notworking(HPC_CTLR_WORKING_TOUT, ctlr_ptr, wpg_bbar, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | &status); |
| 561 | if (!rc) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 562 | pslot->ext_status = ctrl_read(ctlr_ptr, wpg_bbar, index + WPG_1ST_EXTSLOT_INDEX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | break; |
| 565 | |
| 566 | case READ_SLOTSTATUS: |
| 567 | // DO NOT update the slot structure |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 568 | *pstatus = ctrl_read(ctlr_ptr, wpg_bbar, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | break; |
| 570 | |
| 571 | case READ_EXTSLOTSTATUS: |
| 572 | // DO NOT update the slot structure |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 573 | *pstatus = ctrl_read(ctlr_ptr, wpg_bbar, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | break; |
| 575 | |
| 576 | case READ_CTLRSTATUS: |
| 577 | // DO NOT update the slot structure |
| 578 | *pstatus = status; |
| 579 | break; |
| 580 | |
| 581 | case READ_BUSSTATUS: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 582 | pslot->busstatus = ctrl_read(ctlr_ptr, wpg_bbar, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | break; |
| 584 | case READ_REVLEVEL: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 585 | *pstatus = ctrl_read(ctlr_ptr, wpg_bbar, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | break; |
| 587 | case READ_HPCOPTIONS: |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 588 | *pstatus = ctrl_read(ctlr_ptr, wpg_bbar, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | break; |
| 590 | case READ_SLOTLATCHLOWREG: |
| 591 | // DO NOT update the slot structure |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 592 | *pstatus = ctrl_read(ctlr_ptr, wpg_bbar, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | break; |
| 594 | |
| 595 | // Not used |
| 596 | case READ_ALLSLOT: |
Geliang Tang | 2ac83cc | 2015-12-12 21:36:57 +0800 | [diff] [blame] | 597 | list_for_each_entry(pslot, &ibmphp_slot_head, |
| 598 | ibm_slot_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | index = pslot->ctlr_index; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 600 | rc = hpc_wait_ctlr_notworking(HPC_CTLR_WORKING_TOUT, ctlr_ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | wpg_bbar, &status); |
| 602 | if (!rc) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 603 | pslot->status = ctrl_read(ctlr_ptr, wpg_bbar, index); |
| 604 | rc = hpc_wait_ctlr_notworking(HPC_CTLR_WORKING_TOUT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | ctlr_ptr, wpg_bbar, &status); |
| 606 | if (!rc) |
| 607 | pslot->ext_status = |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 608 | ctrl_read(ctlr_ptr, wpg_bbar, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | index + WPG_1ST_EXTSLOT_INDEX); |
| 610 | } else { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 611 | err("%s - Error ctrl_read failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | rc = -EINVAL; |
| 613 | break; |
| 614 | } |
| 615 | } |
| 616 | break; |
| 617 | default: |
| 618 | rc = -EINVAL; |
| 619 | break; |
| 620 | } |
| 621 | } |
| 622 | //-------------------------------------------------------------------- |
| 623 | // cleanup |
| 624 | //-------------------------------------------------------------------- |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | // remove physical to logical address mapping |
| 627 | if ((ctlr_ptr->ctlr_type == 2) || (ctlr_ptr->ctlr_type == 4)) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 628 | iounmap(wpg_bbar); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 629 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 630 | free_hpc_access(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 632 | debug_polling("%s - Exit rc[%d]\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | return rc; |
| 634 | } |
| 635 | |
| 636 | /*---------------------------------------------------------------------- |
| 637 | * Name: ibmphp_hpc_writeslot() |
| 638 | * |
| 639 | * Action: issue a WRITE command to HPC |
| 640 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 641 | int ibmphp_hpc_writeslot(struct slot *pslot, u8 cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | { |
| 643 | void __iomem *wpg_bbar = NULL; |
| 644 | struct controller *ctlr_ptr; |
| 645 | u8 index, status; |
| 646 | int busindex; |
| 647 | u8 done; |
| 648 | int rc = 0; |
| 649 | int timeout; |
| 650 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 651 | debug_polling("%s - Entry pslot[%p] cmd[%x]\n", __func__, pslot, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | if (pslot == NULL) { |
| 653 | rc = -EINVAL; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 654 | err("%s - Error Exit rc[%d]\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | return rc; |
| 656 | } |
| 657 | |
| 658 | if ((cmd == HPC_BUS_33CONVMODE) || (cmd == HPC_BUS_66CONVMODE) || |
| 659 | (cmd == HPC_BUS_66PCIXMODE) || (cmd == HPC_BUS_100PCIXMODE) || |
| 660 | (cmd == HPC_BUS_133PCIXMODE)) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 661 | busindex = ibmphp_get_bus_index(pslot->bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | if (busindex < 0) { |
| 663 | rc = -EINVAL; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 664 | err("%s - Exit Error:invalid bus, rc[%d]\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | return rc; |
| 666 | } else |
| 667 | index = (u8) busindex; |
| 668 | } else |
| 669 | index = pslot->ctlr_index; |
| 670 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 671 | index = hpc_writecmdtoindex(cmd, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
| 673 | if (index == HPC_ERROR) { |
| 674 | rc = -EINVAL; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 675 | err("%s - Error Exit rc[%d]\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | return rc; |
| 677 | } |
| 678 | |
| 679 | ctlr_ptr = pslot->ctrl; |
| 680 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 681 | get_hpc_access(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
| 683 | //-------------------------------------------------------------------- |
| 684 | // map physical address to logical address |
| 685 | //-------------------------------------------------------------------- |
| 686 | if ((ctlr_ptr->ctlr_type == 2) || (ctlr_ptr->ctlr_type == 4)) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 687 | wpg_bbar = ioremap(ctlr_ptr->u.wpeg_ctlr.wpegbbar, WPG_I2C_IOREMAP_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 689 | debug("%s - ctlr id[%x] physical[%lx] logical[%lx] i2c[%x]\n", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | ctlr_ptr->ctlr_id, (ulong) (ctlr_ptr->u.wpeg_ctlr.wpegbbar), (ulong) wpg_bbar, |
| 691 | ctlr_ptr->u.wpeg_ctlr.i2c_addr); |
| 692 | } |
| 693 | //-------------------------------------------------------------------- |
| 694 | // check controller status before writing |
| 695 | //-------------------------------------------------------------------- |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 696 | rc = hpc_wait_ctlr_notworking(HPC_CTLR_WORKING_TOUT, ctlr_ptr, wpg_bbar, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | if (!rc) { |
| 698 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 699 | ctrl_write(ctlr_ptr, wpg_bbar, index, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
| 701 | //-------------------------------------------------------------------- |
| 702 | // check controller is still not working on the command |
| 703 | //-------------------------------------------------------------------- |
| 704 | timeout = CMD_COMPLETE_TOUT_SEC; |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 705 | done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | while (!done) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 707 | rc = hpc_wait_ctlr_notworking(HPC_CTLR_WORKING_TOUT, ctlr_ptr, wpg_bbar, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | &status); |
| 709 | if (!rc) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 710 | if (NEEDTOCHECK_CMDSTATUS(cmd)) { |
| 711 | if (CTLR_FINISHED(status) == HPC_CTLR_FINISHED_YES) |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 712 | done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } else |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 714 | done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | } |
| 716 | if (!done) { |
| 717 | msleep(1000); |
| 718 | if (timeout < 1) { |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 719 | done = 1; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 720 | err("%s - Error command complete timeout\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | rc = -EFAULT; |
| 722 | } else |
| 723 | timeout--; |
| 724 | } |
| 725 | } |
| 726 | ctlr_ptr->status = status; |
| 727 | } |
| 728 | // cleanup |
| 729 | |
| 730 | // remove physical to logical address mapping |
| 731 | if ((ctlr_ptr->ctlr_type == 2) || (ctlr_ptr->ctlr_type == 4)) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 732 | iounmap(wpg_bbar); |
| 733 | free_hpc_access(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 735 | debug_polling("%s - Exit rc[%d]\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | return rc; |
| 737 | } |
| 738 | |
| 739 | /*---------------------------------------------------------------------- |
| 740 | * Name: get_hpc_access() |
| 741 | * |
| 742 | * Action: make sure only one process can access HPC at one time |
| 743 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 744 | static void get_hpc_access(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | { |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 746 | mutex_lock(&sem_hpcaccess); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /*---------------------------------------------------------------------- |
| 750 | * Name: free_hpc_access() |
| 751 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 752 | void free_hpc_access(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | { |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 754 | mutex_unlock(&sem_hpcaccess); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | /*---------------------------------------------------------------------- |
| 758 | * Name: ibmphp_lock_operations() |
| 759 | * |
| 760 | * Action: make sure only one process can change the data structure |
| 761 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 762 | void ibmphp_lock_operations(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | { |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 764 | mutex_lock(&operations_mutex); |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 765 | to_debug = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /*---------------------------------------------------------------------- |
| 769 | * Name: ibmphp_unlock_operations() |
| 770 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 771 | void ibmphp_unlock_operations(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 773 | debug("%s - Entry\n", __func__); |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 774 | mutex_unlock(&operations_mutex); |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 775 | to_debug = 0; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 776 | debug("%s - Exit\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | /*---------------------------------------------------------------------- |
| 780 | * Name: poll_hpc() |
| 781 | *---------------------------------------------------------------------*/ |
| 782 | #define POLL_LATCH_REGISTER 0 |
| 783 | #define POLL_SLOTS 1 |
| 784 | #define POLL_SLEEP 2 |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 785 | static int poll_hpc(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | { |
| 787 | struct slot myslot; |
| 788 | struct slot *pslot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | int rc; |
| 790 | int poll_state = POLL_LATCH_REGISTER; |
| 791 | u8 oldlatchlow = 0x00; |
| 792 | u8 curlatchlow = 0x00; |
| 793 | int poll_count = 0; |
| 794 | u8 ctrl_count = 0x00; |
| 795 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 796 | debug("%s - Entry\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 798 | while (!kthread_should_stop()) { |
Steven Cole | eaae4b3 | 2005-05-03 18:38:30 -0600 | [diff] [blame] | 799 | /* try to get the lock to do some kind of hardware access */ |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 800 | mutex_lock(&operations_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
| 802 | switch (poll_state) { |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 803 | case POLL_LATCH_REGISTER: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | oldlatchlow = curlatchlow; |
| 805 | ctrl_count = 0x00; |
Geliang Tang | 2ac83cc | 2015-12-12 21:36:57 +0800 | [diff] [blame] | 806 | list_for_each_entry(pslot, &ibmphp_slot_head, |
| 807 | ibm_slot_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | if (ctrl_count >= ibmphp_get_total_controllers()) |
| 809 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | if (pslot->ctrl->ctlr_relative_id == ctrl_count) { |
| 811 | ctrl_count++; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 812 | if (READ_SLOT_LATCH(pslot->ctrl)) { |
| 813 | rc = ibmphp_hpc_readslot(pslot, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | READ_SLOTLATCHLOWREG, |
| 815 | &curlatchlow); |
| 816 | if (oldlatchlow != curlatchlow) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 817 | process_changeinlatch(oldlatchlow, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | curlatchlow, |
| 819 | pslot->ctrl); |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | ++poll_count; |
| 824 | poll_state = POLL_SLEEP; |
| 825 | break; |
| 826 | case POLL_SLOTS: |
Geliang Tang | 2ac83cc | 2015-12-12 21:36:57 +0800 | [diff] [blame] | 827 | list_for_each_entry(pslot, &ibmphp_slot_head, |
| 828 | ibm_slot_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | // make a copy of the old status |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 830 | memcpy((void *) &myslot, (void *) pslot, |
| 831 | sizeof(struct slot)); |
| 832 | rc = ibmphp_hpc_readslot(pslot, READ_ALLSTAT, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | if ((myslot.status != pslot->status) |
| 834 | || (myslot.ext_status != pslot->ext_status)) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 835 | process_changeinstatus(pslot, &myslot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | } |
| 837 | ctrl_count = 0x00; |
Geliang Tang | 2ac83cc | 2015-12-12 21:36:57 +0800 | [diff] [blame] | 838 | list_for_each_entry(pslot, &ibmphp_slot_head, |
| 839 | ibm_slot_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | if (ctrl_count >= ibmphp_get_total_controllers()) |
| 841 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | if (pslot->ctrl->ctlr_relative_id == ctrl_count) { |
| 843 | ctrl_count++; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 844 | if (READ_SLOT_LATCH(pslot->ctrl)) |
| 845 | rc = ibmphp_hpc_readslot(pslot, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | READ_SLOTLATCHLOWREG, |
| 847 | &curlatchlow); |
| 848 | } |
| 849 | } |
| 850 | ++poll_count; |
| 851 | poll_state = POLL_SLEEP; |
| 852 | break; |
| 853 | case POLL_SLEEP: |
| 854 | /* don't sleep with a lock on the hardware */ |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 855 | mutex_unlock(&operations_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | msleep(POLL_INTERVAL_SEC * 1000); |
| 857 | |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 858 | if (kthread_should_stop()) |
Jesse Barnes | 5c788a6 | 2009-12-04 15:18:01 -0800 | [diff] [blame] | 859 | goto out_sleep; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 860 | |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 861 | mutex_lock(&operations_mutex); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | if (poll_count >= POLL_LATCH_CNT) { |
| 864 | poll_count = 0; |
| 865 | poll_state = POLL_SLOTS; |
| 866 | } else |
| 867 | poll_state = POLL_LATCH_REGISTER; |
| 868 | break; |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 869 | } |
Steven Cole | eaae4b3 | 2005-05-03 18:38:30 -0600 | [diff] [blame] | 870 | /* give up the hardware semaphore */ |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 871 | mutex_unlock(&operations_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | /* sleep for a short time just for good measure */ |
Jesse Barnes | 5c788a6 | 2009-12-04 15:18:01 -0800 | [diff] [blame] | 873 | out_sleep: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | msleep(100); |
| 875 | } |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 876 | complete(&exit_complete); |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 877 | debug("%s - Exit\n", __func__); |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 878 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | |
| 882 | /*---------------------------------------------------------------------- |
| 883 | * Name: process_changeinstatus |
| 884 | * |
| 885 | * Action: compare old and new slot status, process the change in status |
| 886 | * |
| 887 | * Input: pointer to slot struct, old slot struct |
| 888 | * |
| 889 | * Return 0 or error codes |
| 890 | * Value: |
| 891 | * |
| 892 | * Side |
| 893 | * Effects: None. |
| 894 | * |
| 895 | * Notes: |
| 896 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 897 | static int process_changeinstatus(struct slot *pslot, struct slot *poldslot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | { |
| 899 | u8 status; |
| 900 | int rc = 0; |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 901 | u8 disable = 0; |
| 902 | u8 update = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 904 | debug("process_changeinstatus - Entry pslot[%p], poldslot[%p]\n", pslot, poldslot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
| 906 | // bit 0 - HPC_SLOT_POWER |
| 907 | if ((pslot->status & 0x01) != (poldslot->status & 0x01)) |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 908 | update = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
| 910 | // bit 1 - HPC_SLOT_CONNECT |
| 911 | // ignore |
| 912 | |
| 913 | // bit 2 - HPC_SLOT_ATTN |
| 914 | if ((pslot->status & 0x04) != (poldslot->status & 0x04)) |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 915 | update = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
| 917 | // bit 3 - HPC_SLOT_PRSNT2 |
| 918 | // bit 4 - HPC_SLOT_PRSNT1 |
| 919 | if (((pslot->status & 0x08) != (poldslot->status & 0x08)) |
| 920 | || ((pslot->status & 0x10) != (poldslot->status & 0x10))) |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 921 | update = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
| 923 | // bit 5 - HPC_SLOT_PWRGD |
| 924 | if ((pslot->status & 0x20) != (poldslot->status & 0x20)) |
| 925 | // OFF -> ON: ignore, ON -> OFF: disable slot |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 926 | if ((poldslot->status & 0x20) && (SLOT_CONNECT(poldslot->status) == HPC_SLOT_CONNECTED) && (SLOT_PRESENT(poldslot->status))) |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 927 | disable = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
| 929 | // bit 6 - HPC_SLOT_BUS_SPEED |
| 930 | // ignore |
| 931 | |
| 932 | // bit 7 - HPC_SLOT_LATCH |
| 933 | if ((pslot->status & 0x80) != (poldslot->status & 0x80)) { |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 934 | update = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | // OPEN -> CLOSE |
| 936 | if (pslot->status & 0x80) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 937 | if (SLOT_PWRGD(pslot->status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | // power goes on and off after closing latch |
| 939 | // check again to make sure power is still ON |
| 940 | msleep(1000); |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 941 | rc = ibmphp_hpc_readslot(pslot, READ_SLOTSTATUS, &status); |
| 942 | if (SLOT_PWRGD(status)) |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 943 | update = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | else // overwrite power in pslot to OFF |
| 945 | pslot->status &= ~HPC_SLOT_POWER; |
| 946 | } |
| 947 | } |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 948 | // CLOSE -> OPEN |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 949 | else if ((SLOT_PWRGD(poldslot->status) == HPC_SLOT_PWRGD_GOOD) |
| 950 | && (SLOT_CONNECT(poldslot->status) == HPC_SLOT_CONNECTED) && (SLOT_PRESENT(poldslot->status))) { |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 951 | disable = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | } |
| 953 | // else - ignore |
| 954 | } |
| 955 | // bit 4 - HPC_SLOT_BLINK_ATTN |
| 956 | if ((pslot->ext_status & 0x08) != (poldslot->ext_status & 0x08)) |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 957 | update = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
| 959 | if (disable) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 960 | debug("process_changeinstatus - disable slot\n"); |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 961 | pslot->flag = 0; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 962 | rc = ibmphp_do_disable_slot(pslot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Quentin Lambert | 656f978 | 2014-09-07 20:02:47 +0200 | [diff] [blame] | 965 | if (update || disable) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 966 | ibmphp_update_slot_info(pslot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 968 | debug("%s - Exit rc[%d] disable[%x] update[%x]\n", __func__, rc, disable, update); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | |
| 970 | return rc; |
| 971 | } |
| 972 | |
| 973 | /*---------------------------------------------------------------------- |
| 974 | * Name: process_changeinlatch |
| 975 | * |
| 976 | * Action: compare old and new latch reg status, process the change |
| 977 | * |
| 978 | * Input: old and current latch register status |
| 979 | * |
| 980 | * Return 0 or error codes |
| 981 | * Value: |
| 982 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 983 | static int process_changeinlatch(u8 old, u8 new, struct controller *ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | { |
| 985 | struct slot myslot, *pslot; |
| 986 | u8 i; |
| 987 | u8 mask; |
| 988 | int rc = 0; |
| 989 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 990 | debug("%s - Entry old[%x], new[%x]\n", __func__, old, new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | // bit 0 reserved, 0 is LSB, check bit 1-6 for 6 slots |
| 992 | |
| 993 | for (i = ctrl->starting_slot_num; i <= ctrl->ending_slot_num; i++) { |
| 994 | mask = 0x01 << i; |
| 995 | if ((mask & old) != (mask & new)) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 996 | pslot = ibmphp_get_slot_from_physical_num(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | if (pslot) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 998 | memcpy((void *) &myslot, (void *) pslot, sizeof(struct slot)); |
| 999 | rc = ibmphp_hpc_readslot(pslot, READ_ALLSTAT, NULL); |
| 1000 | debug("%s - call process_changeinstatus for slot[%d]\n", __func__, i); |
| 1001 | process_changeinstatus(pslot, &myslot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | } else { |
| 1003 | rc = -EINVAL; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1004 | err("%s - Error bad pointer for slot[%d]\n", __func__, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1008 | debug("%s - Exit rc[%d]\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | return rc; |
| 1010 | } |
| 1011 | |
| 1012 | /*---------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | * Name: ibmphp_hpc_start_poll_thread |
| 1014 | * |
| 1015 | * Action: start polling thread |
| 1016 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1017 | int __init ibmphp_hpc_start_poll_thread(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1019 | debug("%s - Entry\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 1021 | ibmphp_poll_thread = kthread_run(poll_hpc, NULL, "hpc_poll"); |
| 1022 | if (IS_ERR(ibmphp_poll_thread)) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1023 | err("%s - Error, thread not started\n", __func__); |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 1024 | return PTR_ERR(ibmphp_poll_thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | } |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 1026 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | /*---------------------------------------------------------------------- |
| 1030 | * Name: ibmphp_hpc_stop_poll_thread |
| 1031 | * |
| 1032 | * Action: stop polling thread and cleanup |
| 1033 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1034 | void __exit ibmphp_hpc_stop_poll_thread(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1036 | debug("%s - Entry\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
Kristen Carlson Accardi | 2d100fe | 2007-08-14 16:07:00 -0700 | [diff] [blame] | 1038 | kthread_stop(ibmphp_poll_thread); |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1039 | debug("before locking operations\n"); |
| 1040 | ibmphp_lock_operations(); |
| 1041 | debug("after locking operations\n"); |
Bjorn Helgaas | f762598 | 2013-11-14 11:28:18 -0700 | [diff] [blame] | 1042 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | // wait for poll thread to exit |
Arnd Bergmann | 2a727f6 | 2018-12-10 22:49:10 +0100 | [diff] [blame] | 1044 | debug("before exit_complete down\n"); |
| 1045 | wait_for_completion(&exit_complete); |
| 1046 | debug("after exit_completion down\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
| 1048 | // cleanup |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1049 | debug("before free_hpc_access\n"); |
| 1050 | free_hpc_access(); |
| 1051 | debug("after free_hpc_access\n"); |
| 1052 | ibmphp_unlock_operations(); |
| 1053 | debug("after unlock operations\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1055 | debug("%s - Exit\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | /*---------------------------------------------------------------------- |
| 1059 | * Name: hpc_wait_ctlr_notworking |
| 1060 | * |
| 1061 | * Action: wait until the controller is in a not working state |
| 1062 | * |
| 1063 | * Return 0, HPC_ERROR |
| 1064 | * Value: |
| 1065 | *---------------------------------------------------------------------*/ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1066 | static int hpc_wait_ctlr_notworking(int timeout, struct controller *ctlr_ptr, void __iomem *wpg_bbar, |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 1067 | u8 *pstatus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | { |
| 1069 | int rc = 0; |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 1070 | u8 done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1072 | debug_polling("hpc_wait_ctlr_notworking - Entry timeout[%d]\n", timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | |
| 1074 | while (!done) { |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1075 | *pstatus = ctrl_read(ctlr_ptr, wpg_bbar, WPG_CTLR_INDEX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | if (*pstatus == HPC_ERROR) { |
| 1077 | rc = HPC_ERROR; |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 1078 | done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1080 | if (CTLR_WORKING(*pstatus) == HPC_CTLR_WORKING_NO) |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 1081 | done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | if (!done) { |
| 1083 | msleep(1000); |
| 1084 | if (timeout < 1) { |
Kristen Accardi | dc6712d | 2006-03-14 16:24:47 -0800 | [diff] [blame] | 1085 | done = 1; |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1086 | err("HPCreadslot - Error ctlr timeout\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | rc = HPC_ERROR; |
| 1088 | } else |
| 1089 | timeout--; |
| 1090 | } |
| 1091 | } |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 1092 | debug_polling("hpc_wait_ctlr_notworking - Exit rc[%x] status[%x]\n", rc, *pstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | return rc; |
| 1094 | } |