diff options
Diffstat (limited to 'drivers/pci/hotplug/pciehp_hpc.c')
-rw-r--r-- | drivers/pci/hotplug/pciehp_hpc.c | 827 |
1 files changed, 319 insertions, 508 deletions
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 25d3aadfddbf..fbc64aa2dd68 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/timer.h> | 35 | #include <linux/timer.h> |
36 | #include <linux/pci.h> | 36 | #include <linux/pci.h> |
37 | #include <linux/interrupt.h> | 37 | #include <linux/interrupt.h> |
38 | #include <linux/time.h> | ||
38 | 39 | ||
39 | #include "../pci.h" | 40 | #include "../pci.h" |
40 | #include "pciehp.h" | 41 | #include "pciehp.h" |
@@ -105,34 +106,30 @@ enum ctrl_offsets { | |||
105 | ROOTCTRL = offsetof(struct ctrl_reg, root_ctrl), | 106 | ROOTCTRL = offsetof(struct ctrl_reg, root_ctrl), |
106 | ROOTSTATUS = offsetof(struct ctrl_reg, root_status), | 107 | ROOTSTATUS = offsetof(struct ctrl_reg, root_status), |
107 | }; | 108 | }; |
108 | static int pcie_cap_base = 0; /* Base of the PCI Express capability item structure */ | 109 | |
109 | 110 | static inline int pciehp_readw(struct controller *ctrl, int reg, u16 *value) | |
110 | #define PCIE_CAP_ID(cb) ( cb + PCIECAPID ) | 111 | { |
111 | #define NXT_CAP_PTR(cb) ( cb + NXTCAPPTR ) | 112 | struct pci_dev *dev = ctrl->pci_dev; |
112 | #define CAP_REG(cb) ( cb + CAPREG ) | 113 | return pci_read_config_word(dev, ctrl->cap_base + reg, value); |
113 | #define DEV_CAP(cb) ( cb + DEVCAP ) | 114 | } |
114 | #define DEV_CTRL(cb) ( cb + DEVCTRL ) | 115 | |
115 | #define DEV_STATUS(cb) ( cb + DEVSTATUS ) | 116 | static inline int pciehp_readl(struct controller *ctrl, int reg, u32 *value) |
116 | #define LNK_CAP(cb) ( cb + LNKCAP ) | 117 | { |
117 | #define LNK_CTRL(cb) ( cb + LNKCTRL ) | 118 | struct pci_dev *dev = ctrl->pci_dev; |
118 | #define LNK_STATUS(cb) ( cb + LNKSTATUS ) | 119 | return pci_read_config_dword(dev, ctrl->cap_base + reg, value); |
119 | #define SLOT_CAP(cb) ( cb + SLOTCAP ) | 120 | } |
120 | #define SLOT_CTRL(cb) ( cb + SLOTCTRL ) | 121 | |
121 | #define SLOT_STATUS(cb) ( cb + SLOTSTATUS ) | 122 | static inline int pciehp_writew(struct controller *ctrl, int reg, u16 value) |
122 | #define ROOT_CTRL(cb) ( cb + ROOTCTRL ) | 123 | { |
123 | #define ROOT_STATUS(cb) ( cb + ROOTSTATUS ) | 124 | struct pci_dev *dev = ctrl->pci_dev; |
124 | 125 | return pci_write_config_word(dev, ctrl->cap_base + reg, value); | |
125 | #define hp_register_read_word(pdev, reg , value) \ | 126 | } |
126 | pci_read_config_word(pdev, reg, &value) | 127 | |
127 | 128 | static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value) | |
128 | #define hp_register_read_dword(pdev, reg , value) \ | 129 | { |
129 | pci_read_config_dword(pdev, reg, &value) | 130 | struct pci_dev *dev = ctrl->pci_dev; |
130 | 131 | return pci_write_config_dword(dev, ctrl->cap_base + reg, value); | |
131 | #define hp_register_write_word(pdev, reg , value) \ | 132 | } |
132 | pci_write_config_word(pdev, reg, value) | ||
133 | |||
134 | #define hp_register_dwrite_word(pdev, reg , value) \ | ||
135 | pci_write_config_dword(pdev, reg, value) | ||
136 | 133 | ||
137 | /* Field definitions in PCI Express Capabilities Register */ | 134 | /* Field definitions in PCI Express Capabilities Register */ |
138 | #define CAP_VER 0x000F | 135 | #define CAP_VER 0x000F |
@@ -196,6 +193,7 @@ static int pcie_cap_base = 0; /* Base of the PCI Express capability item struct | |||
196 | #define ATTN_LED_CTRL 0x00C0 | 193 | #define ATTN_LED_CTRL 0x00C0 |
197 | #define PWR_LED_CTRL 0x0300 | 194 | #define PWR_LED_CTRL 0x0300 |
198 | #define PWR_CTRL 0x0400 | 195 | #define PWR_CTRL 0x0400 |
196 | #define EMI_CTRL 0x0800 | ||
199 | 197 | ||
200 | /* Attention indicator and Power indicator states */ | 198 | /* Attention indicator and Power indicator states */ |
201 | #define LED_ON 0x01 | 199 | #define LED_ON 0x01 |
@@ -206,6 +204,10 @@ static int pcie_cap_base = 0; /* Base of the PCI Express capability item struct | |||
206 | #define POWER_ON 0 | 204 | #define POWER_ON 0 |
207 | #define POWER_OFF 0x0400 | 205 | #define POWER_OFF 0x0400 |
208 | 206 | ||
207 | /* EMI Status defines */ | ||
208 | #define EMI_DISENGAGED 0 | ||
209 | #define EMI_ENGAGED 1 | ||
210 | |||
209 | /* Field definitions in Slot Status Register */ | 211 | /* Field definitions in Slot Status Register */ |
210 | #define ATTN_BUTTN_PRESSED 0x0001 | 212 | #define ATTN_BUTTN_PRESSED 0x0001 |
211 | #define PWR_FAULT_DETECTED 0x0002 | 213 | #define PWR_FAULT_DETECTED 0x0002 |
@@ -214,114 +216,117 @@ static int pcie_cap_base = 0; /* Base of the PCI Express capability item struct | |||
214 | #define CMD_COMPLETED 0x0010 | 216 | #define CMD_COMPLETED 0x0010 |
215 | #define MRL_STATE 0x0020 | 217 | #define MRL_STATE 0x0020 |
216 | #define PRSN_STATE 0x0040 | 218 | #define PRSN_STATE 0x0040 |
219 | #define EMI_STATE 0x0080 | ||
220 | #define EMI_STATUS_BIT 7 | ||
217 | 221 | ||
218 | static spinlock_t hpc_event_lock; | 222 | static spinlock_t hpc_event_lock; |
219 | 223 | ||
220 | DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */ | 224 | DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */ |
221 | static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */ | ||
222 | static int ctlr_seq_num = 0; /* Controller sequence # */ | 225 | static int ctlr_seq_num = 0; /* Controller sequence # */ |
223 | static spinlock_t list_lock; | ||
224 | |||
225 | static irqreturn_t pcie_isr(int IRQ, void *dev_id); | ||
226 | 226 | ||
227 | static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds); | 227 | static irqreturn_t pcie_isr(int irq, void *dev_id); |
228 | static void start_int_poll_timer(struct controller *ctrl, int sec); | ||
228 | 229 | ||
229 | /* This is the interrupt polling timeout function. */ | 230 | /* This is the interrupt polling timeout function. */ |
230 | static void int_poll_timeout(unsigned long lphp_ctlr) | 231 | static void int_poll_timeout(unsigned long data) |
231 | { | 232 | { |
232 | struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *)lphp_ctlr; | 233 | struct controller *ctrl = (struct controller *)data; |
233 | 234 | ||
234 | DBG_ENTER_ROUTINE | 235 | DBG_ENTER_ROUTINE |
235 | 236 | ||
236 | if ( !php_ctlr ) { | ||
237 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
238 | return; | ||
239 | } | ||
240 | |||
241 | /* Poll for interrupt events. regs == NULL => polling */ | 237 | /* Poll for interrupt events. regs == NULL => polling */ |
242 | pcie_isr( 0, (void *)php_ctlr ); | 238 | pcie_isr(0, ctrl); |
243 | |||
244 | init_timer(&php_ctlr->int_poll_timer); | ||
245 | 239 | ||
240 | init_timer(&ctrl->poll_timer); | ||
246 | if (!pciehp_poll_time) | 241 | if (!pciehp_poll_time) |
247 | pciehp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/ | 242 | pciehp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/ |
248 | 243 | ||
249 | start_int_poll_timer(php_ctlr, pciehp_poll_time); | 244 | start_int_poll_timer(ctrl, pciehp_poll_time); |
250 | |||
251 | return; | ||
252 | } | 245 | } |
253 | 246 | ||
254 | /* This function starts the interrupt polling timer. */ | 247 | /* This function starts the interrupt polling timer. */ |
255 | static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds) | 248 | static void start_int_poll_timer(struct controller *ctrl, int sec) |
256 | { | 249 | { |
257 | if (!php_ctlr) { | 250 | /* Clamp to sane value */ |
258 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | 251 | if ((sec <= 0) || (sec > 60)) |
259 | return; | 252 | sec = 2; |
260 | } | 253 | |
254 | ctrl->poll_timer.function = &int_poll_timeout; | ||
255 | ctrl->poll_timer.data = (unsigned long)ctrl; | ||
256 | ctrl->poll_timer.expires = jiffies + sec * HZ; | ||
257 | add_timer(&ctrl->poll_timer); | ||
258 | } | ||
261 | 259 | ||
262 | if ( ( seconds <= 0 ) || ( seconds > 60 ) ) | 260 | static inline int pcie_wait_cmd(struct controller *ctrl) |
263 | seconds = 2; /* Clamp to sane value */ | 261 | { |
262 | int retval = 0; | ||
263 | unsigned int msecs = pciehp_poll_mode ? 2500 : 1000; | ||
264 | unsigned long timeout = msecs_to_jiffies(msecs); | ||
265 | int rc; | ||
264 | 266 | ||
265 | php_ctlr->int_poll_timer.function = &int_poll_timeout; | 267 | rc = wait_event_interruptible_timeout(ctrl->queue, |
266 | php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr; /* Instance data */ | 268 | !ctrl->cmd_busy, timeout); |
267 | php_ctlr->int_poll_timer.expires = jiffies + seconds * HZ; | 269 | if (!rc) |
268 | add_timer(&php_ctlr->int_poll_timer); | 270 | dbg("Command not completed in 1000 msec\n"); |
271 | else if (rc < 0) { | ||
272 | retval = -EINTR; | ||
273 | info("Command was interrupted by a signal\n"); | ||
274 | } | ||
269 | 275 | ||
270 | return; | 276 | return retval; |
271 | } | 277 | } |
272 | 278 | ||
273 | static int pcie_write_cmd(struct slot *slot, u16 cmd) | 279 | static int pcie_write_cmd(struct slot *slot, u16 cmd) |
274 | { | 280 | { |
275 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 281 | struct controller *ctrl = slot->ctrl; |
276 | int retval = 0; | 282 | int retval = 0; |
277 | u16 slot_status; | 283 | u16 slot_status; |
278 | 284 | ||
279 | DBG_ENTER_ROUTINE | 285 | DBG_ENTER_ROUTINE |
280 | |||
281 | if (!php_ctlr) { | ||
282 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
283 | return -1; | ||
284 | } | ||
285 | 286 | ||
286 | retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(slot->ctrl->cap_base), slot_status); | 287 | mutex_lock(&ctrl->ctrl_lock); |
288 | |||
289 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); | ||
287 | if (retval) { | 290 | if (retval) { |
288 | err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); | 291 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
289 | return retval; | 292 | goto out; |
290 | } | 293 | } |
291 | 294 | ||
292 | if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) { | 295 | if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) { |
293 | /* After 1 sec and CMD_COMPLETED still not set, just proceed forward to issue | 296 | /* After 1 sec and CMD_COMPLETED still not set, just |
294 | the next command according to spec. Just print out the error message */ | 297 | proceed forward to issue the next command according |
295 | dbg("%s : CMD_COMPLETED not clear after 1 sec.\n", __FUNCTION__); | 298 | to spec. Just print out the error message */ |
299 | dbg("%s: CMD_COMPLETED not clear after 1 sec.\n", | ||
300 | __FUNCTION__); | ||
296 | } | 301 | } |
297 | 302 | ||
298 | retval = hp_register_write_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), cmd | CMD_CMPL_INTR_ENABLE); | 303 | ctrl->cmd_busy = 1; |
304 | retval = pciehp_writew(ctrl, SLOTCTRL, (cmd | CMD_CMPL_INTR_ENABLE)); | ||
299 | if (retval) { | 305 | if (retval) { |
300 | err("%s : hp_register_write_word SLOT_CTRL failed\n", __FUNCTION__); | 306 | err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); |
301 | return retval; | 307 | goto out; |
302 | } | 308 | } |
303 | 309 | ||
310 | /* | ||
311 | * Wait for command completion. | ||
312 | */ | ||
313 | retval = pcie_wait_cmd(ctrl); | ||
314 | out: | ||
315 | mutex_unlock(&ctrl->ctrl_lock); | ||
304 | DBG_LEAVE_ROUTINE | 316 | DBG_LEAVE_ROUTINE |
305 | return retval; | 317 | return retval; |
306 | } | 318 | } |
307 | 319 | ||
308 | static int hpc_check_lnk_status(struct controller *ctrl) | 320 | static int hpc_check_lnk_status(struct controller *ctrl) |
309 | { | 321 | { |
310 | struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; | ||
311 | u16 lnk_status; | 322 | u16 lnk_status; |
312 | int retval = 0; | 323 | int retval = 0; |
313 | 324 | ||
314 | DBG_ENTER_ROUTINE | 325 | DBG_ENTER_ROUTINE |
315 | 326 | ||
316 | if (!php_ctlr) { | 327 | retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); |
317 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
318 | return -1; | ||
319 | } | ||
320 | |||
321 | retval = hp_register_read_word(php_ctlr->pci_dev, LNK_STATUS(ctrl->cap_base), lnk_status); | ||
322 | |||
323 | if (retval) { | 328 | if (retval) { |
324 | err("%s : hp_register_read_word LNK_STATUS failed\n", __FUNCTION__); | 329 | err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); |
325 | return retval; | 330 | return retval; |
326 | } | 331 | } |
327 | 332 | ||
@@ -340,26 +345,21 @@ static int hpc_check_lnk_status(struct controller *ctrl) | |||
340 | 345 | ||
341 | static int hpc_get_attention_status(struct slot *slot, u8 *status) | 346 | static int hpc_get_attention_status(struct slot *slot, u8 *status) |
342 | { | 347 | { |
343 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 348 | struct controller *ctrl = slot->ctrl; |
344 | u16 slot_ctrl; | 349 | u16 slot_ctrl; |
345 | u8 atten_led_state; | 350 | u8 atten_led_state; |
346 | int retval = 0; | 351 | int retval = 0; |
347 | 352 | ||
348 | DBG_ENTER_ROUTINE | 353 | DBG_ENTER_ROUTINE |
349 | 354 | ||
350 | if (!php_ctlr) { | 355 | retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
351 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
352 | return -1; | ||
353 | } | ||
354 | |||
355 | retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); | ||
356 | |||
357 | if (retval) { | 356 | if (retval) { |
358 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 357 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
359 | return retval; | 358 | return retval; |
360 | } | 359 | } |
361 | 360 | ||
362 | dbg("%s: SLOT_CTRL %x, value read %x\n", __FUNCTION__,SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); | 361 | dbg("%s: SLOTCTRL %x, value read %x\n", |
362 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl); | ||
363 | 363 | ||
364 | atten_led_state = (slot_ctrl & ATTN_LED_CTRL) >> 6; | 364 | atten_led_state = (slot_ctrl & ATTN_LED_CTRL) >> 6; |
365 | 365 | ||
@@ -385,27 +385,22 @@ static int hpc_get_attention_status(struct slot *slot, u8 *status) | |||
385 | return 0; | 385 | return 0; |
386 | } | 386 | } |
387 | 387 | ||
388 | static int hpc_get_power_status(struct slot * slot, u8 *status) | 388 | static int hpc_get_power_status(struct slot *slot, u8 *status) |
389 | { | 389 | { |
390 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 390 | struct controller *ctrl = slot->ctrl; |
391 | u16 slot_ctrl; | 391 | u16 slot_ctrl; |
392 | u8 pwr_state; | 392 | u8 pwr_state; |
393 | int retval = 0; | 393 | int retval = 0; |
394 | 394 | ||
395 | DBG_ENTER_ROUTINE | 395 | DBG_ENTER_ROUTINE |
396 | 396 | ||
397 | if (!php_ctlr) { | 397 | retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
398 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
399 | return -1; | ||
400 | } | ||
401 | |||
402 | retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); | ||
403 | |||
404 | if (retval) { | 398 | if (retval) { |
405 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 399 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
406 | return retval; | 400 | return retval; |
407 | } | 401 | } |
408 | dbg("%s: SLOT_CTRL %x value read %x\n", __FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); | 402 | dbg("%s: SLOTCTRL %x value read %x\n", |
403 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl); | ||
409 | 404 | ||
410 | pwr_state = (slot_ctrl & PWR_CTRL) >> 10; | 405 | pwr_state = (slot_ctrl & PWR_CTRL) >> 10; |
411 | 406 | ||
@@ -428,21 +423,15 @@ static int hpc_get_power_status(struct slot * slot, u8 *status) | |||
428 | 423 | ||
429 | static int hpc_get_latch_status(struct slot *slot, u8 *status) | 424 | static int hpc_get_latch_status(struct slot *slot, u8 *status) |
430 | { | 425 | { |
431 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 426 | struct controller *ctrl = slot->ctrl; |
432 | u16 slot_status; | 427 | u16 slot_status; |
433 | int retval = 0; | 428 | int retval = 0; |
434 | 429 | ||
435 | DBG_ENTER_ROUTINE | 430 | DBG_ENTER_ROUTINE |
436 | 431 | ||
437 | if (!php_ctlr) { | 432 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
438 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
439 | return -1; | ||
440 | } | ||
441 | |||
442 | retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(slot->ctrl->cap_base), slot_status); | ||
443 | |||
444 | if (retval) { | 433 | if (retval) { |
445 | err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); | 434 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
446 | return retval; | 435 | return retval; |
447 | } | 436 | } |
448 | 437 | ||
@@ -454,22 +443,16 @@ static int hpc_get_latch_status(struct slot *slot, u8 *status) | |||
454 | 443 | ||
455 | static int hpc_get_adapter_status(struct slot *slot, u8 *status) | 444 | static int hpc_get_adapter_status(struct slot *slot, u8 *status) |
456 | { | 445 | { |
457 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 446 | struct controller *ctrl = slot->ctrl; |
458 | u16 slot_status; | 447 | u16 slot_status; |
459 | u8 card_state; | 448 | u8 card_state; |
460 | int retval = 0; | 449 | int retval = 0; |
461 | 450 | ||
462 | DBG_ENTER_ROUTINE | 451 | DBG_ENTER_ROUTINE |
463 | 452 | ||
464 | if (!php_ctlr) { | 453 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
465 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
466 | return -1; | ||
467 | } | ||
468 | |||
469 | retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(slot->ctrl->cap_base), slot_status); | ||
470 | |||
471 | if (retval) { | 454 | if (retval) { |
472 | err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); | 455 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
473 | return retval; | 456 | return retval; |
474 | } | 457 | } |
475 | card_state = (u8)((slot_status & PRSN_STATE) >> 6); | 458 | card_state = (u8)((slot_status & PRSN_STATE) >> 6); |
@@ -479,24 +462,18 @@ static int hpc_get_adapter_status(struct slot *slot, u8 *status) | |||
479 | return 0; | 462 | return 0; |
480 | } | 463 | } |
481 | 464 | ||
482 | static int hpc_query_power_fault(struct slot * slot) | 465 | static int hpc_query_power_fault(struct slot *slot) |
483 | { | 466 | { |
484 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 467 | struct controller *ctrl = slot->ctrl; |
485 | u16 slot_status; | 468 | u16 slot_status; |
486 | u8 pwr_fault; | 469 | u8 pwr_fault; |
487 | int retval = 0; | 470 | int retval = 0; |
488 | 471 | ||
489 | DBG_ENTER_ROUTINE | 472 | DBG_ENTER_ROUTINE |
490 | 473 | ||
491 | if (!php_ctlr) { | 474 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
492 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
493 | return -1; | ||
494 | } | ||
495 | |||
496 | retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(slot->ctrl->cap_base), slot_status); | ||
497 | |||
498 | if (retval) { | 475 | if (retval) { |
499 | err("%s : Cannot check for power fault\n", __FUNCTION__); | 476 | err("%s: Cannot check for power fault\n", __FUNCTION__); |
500 | return retval; | 477 | return retval; |
501 | } | 478 | } |
502 | pwr_fault = (u8)((slot_status & PWR_FAULT_DETECTED) >> 1); | 479 | pwr_fault = (u8)((slot_status & PWR_FAULT_DETECTED) >> 1); |
@@ -505,28 +482,63 @@ static int hpc_query_power_fault(struct slot * slot) | |||
505 | return pwr_fault; | 482 | return pwr_fault; |
506 | } | 483 | } |
507 | 484 | ||
508 | static int hpc_set_attention_status(struct slot *slot, u8 value) | 485 | static int hpc_get_emi_status(struct slot *slot, u8 *status) |
509 | { | 486 | { |
510 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 487 | struct controller *ctrl = slot->ctrl; |
488 | u16 slot_status; | ||
489 | int retval = 0; | ||
490 | |||
491 | DBG_ENTER_ROUTINE | ||
492 | |||
493 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); | ||
494 | if (retval) { | ||
495 | err("%s : Cannot check EMI status\n", __FUNCTION__); | ||
496 | return retval; | ||
497 | } | ||
498 | *status = (slot_status & EMI_STATE) >> EMI_STATUS_BIT; | ||
499 | |||
500 | DBG_LEAVE_ROUTINE | ||
501 | return retval; | ||
502 | } | ||
503 | |||
504 | static int hpc_toggle_emi(struct slot *slot) | ||
505 | { | ||
506 | struct controller *ctrl = slot->ctrl; | ||
511 | u16 slot_cmd = 0; | 507 | u16 slot_cmd = 0; |
512 | u16 slot_ctrl; | 508 | u16 slot_ctrl; |
513 | int rc = 0; | 509 | int rc = 0; |
514 | 510 | ||
515 | DBG_ENTER_ROUTINE | 511 | DBG_ENTER_ROUTINE |
516 | 512 | ||
517 | if (!php_ctlr) { | 513 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
518 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | 514 | if (rc) { |
519 | return -1; | 515 | err("%s : hp_register_read_word SLOT_CTRL failed\n", |
516 | __FUNCTION__); | ||
517 | return rc; | ||
520 | } | 518 | } |
521 | 519 | ||
522 | if (slot->hp_slot >= php_ctlr->num_slots) { | 520 | slot_cmd = (slot_ctrl | EMI_CTRL); |
523 | err("%s: Invalid HPC slot number!\n", __FUNCTION__); | 521 | if (!pciehp_poll_mode) |
524 | return -1; | 522 | slot_cmd = slot_cmd | HP_INTR_ENABLE; |
525 | } | ||
526 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); | ||
527 | 523 | ||
524 | pcie_write_cmd(slot, slot_cmd); | ||
525 | slot->last_emi_toggle = get_seconds(); | ||
526 | DBG_LEAVE_ROUTINE | ||
527 | return rc; | ||
528 | } | ||
529 | |||
530 | static int hpc_set_attention_status(struct slot *slot, u8 value) | ||
531 | { | ||
532 | struct controller *ctrl = slot->ctrl; | ||
533 | u16 slot_cmd = 0; | ||
534 | u16 slot_ctrl; | ||
535 | int rc = 0; | ||
536 | |||
537 | DBG_ENTER_ROUTINE | ||
538 | |||
539 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); | ||
528 | if (rc) { | 540 | if (rc) { |
529 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 541 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
530 | return rc; | 542 | return rc; |
531 | } | 543 | } |
532 | 544 | ||
@@ -547,7 +559,8 @@ static int hpc_set_attention_status(struct slot *slot, u8 value) | |||
547 | slot_cmd = slot_cmd | HP_INTR_ENABLE; | 559 | slot_cmd = slot_cmd | HP_INTR_ENABLE; |
548 | 560 | ||
549 | pcie_write_cmd(slot, slot_cmd); | 561 | pcie_write_cmd(slot, slot_cmd); |
550 | dbg("%s: SLOT_CTRL %x write cmd %x\n", __FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); | 562 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
563 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); | ||
551 | 564 | ||
552 | DBG_LEAVE_ROUTINE | 565 | DBG_LEAVE_ROUTINE |
553 | return rc; | 566 | return rc; |
@@ -556,27 +569,16 @@ static int hpc_set_attention_status(struct slot *slot, u8 value) | |||
556 | 569 | ||
557 | static void hpc_set_green_led_on(struct slot *slot) | 570 | static void hpc_set_green_led_on(struct slot *slot) |
558 | { | 571 | { |
559 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 572 | struct controller *ctrl = slot->ctrl; |
560 | u16 slot_cmd; | 573 | u16 slot_cmd; |
561 | u16 slot_ctrl; | 574 | u16 slot_ctrl; |
562 | int rc = 0; | 575 | int rc = 0; |
563 | 576 | ||
564 | DBG_ENTER_ROUTINE | 577 | DBG_ENTER_ROUTINE |
565 | 578 | ||
566 | if (!php_ctlr) { | 579 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
567 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
568 | return ; | ||
569 | } | ||
570 | |||
571 | if (slot->hp_slot >= php_ctlr->num_slots) { | ||
572 | err("%s: Invalid HPC slot number!\n", __FUNCTION__); | ||
573 | return ; | ||
574 | } | ||
575 | |||
576 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); | ||
577 | |||
578 | if (rc) { | 580 | if (rc) { |
579 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 581 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
580 | return; | 582 | return; |
581 | } | 583 | } |
582 | slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0100; | 584 | slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0100; |
@@ -585,34 +587,24 @@ static void hpc_set_green_led_on(struct slot *slot) | |||
585 | 587 | ||
586 | pcie_write_cmd(slot, slot_cmd); | 588 | pcie_write_cmd(slot, slot_cmd); |
587 | 589 | ||
588 | dbg("%s: SLOT_CTRL %x write cmd %x\n",__FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); | 590 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
591 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); | ||
589 | DBG_LEAVE_ROUTINE | 592 | DBG_LEAVE_ROUTINE |
590 | return; | 593 | return; |
591 | } | 594 | } |
592 | 595 | ||
593 | static void hpc_set_green_led_off(struct slot *slot) | 596 | static void hpc_set_green_led_off(struct slot *slot) |
594 | { | 597 | { |
595 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 598 | struct controller *ctrl = slot->ctrl; |
596 | u16 slot_cmd; | 599 | u16 slot_cmd; |
597 | u16 slot_ctrl; | 600 | u16 slot_ctrl; |
598 | int rc = 0; | 601 | int rc = 0; |
599 | 602 | ||
600 | DBG_ENTER_ROUTINE | 603 | DBG_ENTER_ROUTINE |
601 | 604 | ||
602 | if (!php_ctlr) { | 605 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
603 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
604 | return ; | ||
605 | } | ||
606 | |||
607 | if (slot->hp_slot >= php_ctlr->num_slots) { | ||
608 | err("%s: Invalid HPC slot number!\n", __FUNCTION__); | ||
609 | return ; | ||
610 | } | ||
611 | |||
612 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); | ||
613 | |||
614 | if (rc) { | 606 | if (rc) { |
615 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 607 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
616 | return; | 608 | return; |
617 | } | 609 | } |
618 | 610 | ||
@@ -621,7 +613,8 @@ static void hpc_set_green_led_off(struct slot *slot) | |||
621 | if (!pciehp_poll_mode) | 613 | if (!pciehp_poll_mode) |
622 | slot_cmd = slot_cmd | HP_INTR_ENABLE; | 614 | slot_cmd = slot_cmd | HP_INTR_ENABLE; |
623 | pcie_write_cmd(slot, slot_cmd); | 615 | pcie_write_cmd(slot, slot_cmd); |
624 | dbg("%s: SLOT_CTRL %x write cmd %x\n", __FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); | 616 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
617 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); | ||
625 | 618 | ||
626 | DBG_LEAVE_ROUTINE | 619 | DBG_LEAVE_ROUTINE |
627 | return; | 620 | return; |
@@ -629,27 +622,16 @@ static void hpc_set_green_led_off(struct slot *slot) | |||
629 | 622 | ||
630 | static void hpc_set_green_led_blink(struct slot *slot) | 623 | static void hpc_set_green_led_blink(struct slot *slot) |
631 | { | 624 | { |
632 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 625 | struct controller *ctrl = slot->ctrl; |
633 | u16 slot_cmd; | 626 | u16 slot_cmd; |
634 | u16 slot_ctrl; | 627 | u16 slot_ctrl; |
635 | int rc = 0; | 628 | int rc = 0; |
636 | 629 | ||
637 | DBG_ENTER_ROUTINE | 630 | DBG_ENTER_ROUTINE |
638 | 631 | ||
639 | if (!php_ctlr) { | 632 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
640 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
641 | return ; | ||
642 | } | ||
643 | |||
644 | if (slot->hp_slot >= php_ctlr->num_slots) { | ||
645 | err("%s: Invalid HPC slot number!\n", __FUNCTION__); | ||
646 | return ; | ||
647 | } | ||
648 | |||
649 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); | ||
650 | |||
651 | if (rc) { | 633 | if (rc) { |
652 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 634 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
653 | return; | 635 | return; |
654 | } | 636 | } |
655 | 637 | ||
@@ -659,126 +641,54 @@ static void hpc_set_green_led_blink(struct slot *slot) | |||
659 | slot_cmd = slot_cmd | HP_INTR_ENABLE; | 641 | slot_cmd = slot_cmd | HP_INTR_ENABLE; |
660 | pcie_write_cmd(slot, slot_cmd); | 642 | pcie_write_cmd(slot, slot_cmd); |
661 | 643 | ||
662 | dbg("%s: SLOT_CTRL %x write cmd %x\n",__FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); | 644 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
645 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); | ||
663 | DBG_LEAVE_ROUTINE | 646 | DBG_LEAVE_ROUTINE |
664 | return; | 647 | return; |
665 | } | 648 | } |
666 | 649 | ||
667 | int pcie_get_ctlr_slot_config(struct controller *ctrl, | ||
668 | int *num_ctlr_slots, /* number of slots in this HPC; only 1 in PCIE */ | ||
669 | int *first_device_num, /* PCI dev num of the first slot in this PCIE */ | ||
670 | int *physical_slot_num, /* phy slot num of the first slot in this PCIE */ | ||
671 | u8 *ctrlcap) | ||
672 | { | ||
673 | struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; | ||
674 | u32 slot_cap; | ||
675 | int rc = 0; | ||
676 | |||
677 | DBG_ENTER_ROUTINE | ||
678 | |||
679 | if (!php_ctlr) { | ||
680 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
681 | return -1; | ||
682 | } | ||
683 | |||
684 | *first_device_num = 0; | ||
685 | *num_ctlr_slots = 1; | ||
686 | |||
687 | rc = hp_register_read_dword(php_ctlr->pci_dev, SLOT_CAP(ctrl->cap_base), slot_cap); | ||
688 | |||
689 | if (rc) { | ||
690 | err("%s : hp_register_read_dword SLOT_CAP failed\n", __FUNCTION__); | ||
691 | return -1; | ||
692 | } | ||
693 | |||
694 | *physical_slot_num = slot_cap >> 19; | ||
695 | dbg("%s: PSN %d \n", __FUNCTION__, *physical_slot_num); | ||
696 | |||
697 | *ctrlcap = slot_cap & 0x0000007f; | ||
698 | |||
699 | DBG_LEAVE_ROUTINE | ||
700 | return 0; | ||
701 | } | ||
702 | |||
703 | static void hpc_release_ctlr(struct controller *ctrl) | 650 | static void hpc_release_ctlr(struct controller *ctrl) |
704 | { | 651 | { |
705 | struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; | ||
706 | struct php_ctlr_state_s *p, *p_prev; | ||
707 | |||
708 | DBG_ENTER_ROUTINE | 652 | DBG_ENTER_ROUTINE |
709 | 653 | ||
710 | if (!php_ctlr) { | 654 | if (pciehp_poll_mode) |
711 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | 655 | del_timer(&ctrl->poll_timer); |
712 | return ; | 656 | else |
713 | } | 657 | free_irq(ctrl->pci_dev->irq, ctrl); |
714 | |||
715 | if (pciehp_poll_mode) { | ||
716 | del_timer(&php_ctlr->int_poll_timer); | ||
717 | } else { | ||
718 | if (php_ctlr->irq) { | ||
719 | free_irq(php_ctlr->irq, ctrl); | ||
720 | php_ctlr->irq = 0; | ||
721 | } | ||
722 | } | ||
723 | if (php_ctlr->pci_dev) | ||
724 | php_ctlr->pci_dev = NULL; | ||
725 | |||
726 | spin_lock(&list_lock); | ||
727 | p = php_ctlr_list_head; | ||
728 | p_prev = NULL; | ||
729 | while (p) { | ||
730 | if (p == php_ctlr) { | ||
731 | if (p_prev) | ||
732 | p_prev->pnext = p->pnext; | ||
733 | else | ||
734 | php_ctlr_list_head = p->pnext; | ||
735 | break; | ||
736 | } else { | ||
737 | p_prev = p; | ||
738 | p = p->pnext; | ||
739 | } | ||
740 | } | ||
741 | spin_unlock(&list_lock); | ||
742 | |||
743 | kfree(php_ctlr); | ||
744 | 658 | ||
745 | DBG_LEAVE_ROUTINE | 659 | DBG_LEAVE_ROUTINE |
746 | |||
747 | } | 660 | } |
748 | 661 | ||
749 | static int hpc_power_on_slot(struct slot * slot) | 662 | static int hpc_power_on_slot(struct slot * slot) |
750 | { | 663 | { |
751 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 664 | struct controller *ctrl = slot->ctrl; |
752 | u16 slot_cmd; | 665 | u16 slot_cmd; |
753 | u16 slot_ctrl, slot_status; | 666 | u16 slot_ctrl, slot_status; |
754 | |||
755 | int retval = 0; | 667 | int retval = 0; |
756 | 668 | ||
757 | DBG_ENTER_ROUTINE | 669 | DBG_ENTER_ROUTINE |
758 | 670 | ||
759 | if (!php_ctlr) { | ||
760 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
761 | return -1; | ||
762 | } | ||
763 | |||
764 | dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot); | 671 | dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot); |
765 | if (slot->hp_slot >= php_ctlr->num_slots) { | ||
766 | err("%s: Invalid HPC slot number!\n", __FUNCTION__); | ||
767 | return -1; | ||
768 | } | ||
769 | 672 | ||
770 | /* Clear sticky power-fault bit from previous power failures */ | 673 | /* Clear sticky power-fault bit from previous power failures */ |
771 | hp_register_read_word(php_ctlr->pci_dev, | 674 | retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
772 | SLOT_STATUS(slot->ctrl->cap_base), slot_status); | 675 | if (retval) { |
676 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); | ||
677 | return retval; | ||
678 | } | ||
773 | slot_status &= PWR_FAULT_DETECTED; | 679 | slot_status &= PWR_FAULT_DETECTED; |
774 | if (slot_status) | 680 | if (slot_status) { |
775 | hp_register_write_word(php_ctlr->pci_dev, | 681 | retval = pciehp_writew(ctrl, SLOTSTATUS, slot_status); |
776 | SLOT_STATUS(slot->ctrl->cap_base), slot_status); | 682 | if (retval) { |
777 | 683 | err("%s: Cannot write to SLOTSTATUS register\n", | |
778 | retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); | 684 | __FUNCTION__); |
685 | return retval; | ||
686 | } | ||
687 | } | ||
779 | 688 | ||
689 | retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); | ||
780 | if (retval) { | 690 | if (retval) { |
781 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 691 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
782 | return retval; | 692 | return retval; |
783 | } | 693 | } |
784 | 694 | ||
@@ -798,7 +708,8 @@ static int hpc_power_on_slot(struct slot * slot) | |||
798 | err("%s: Write %x command failed!\n", __FUNCTION__, slot_cmd); | 708 | err("%s: Write %x command failed!\n", __FUNCTION__, slot_cmd); |
799 | return -1; | 709 | return -1; |
800 | } | 710 | } |
801 | dbg("%s: SLOT_CTRL %x write cmd %x\n",__FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); | 711 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
712 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); | ||
802 | 713 | ||
803 | DBG_LEAVE_ROUTINE | 714 | DBG_LEAVE_ROUTINE |
804 | 715 | ||
@@ -807,29 +718,18 @@ static int hpc_power_on_slot(struct slot * slot) | |||
807 | 718 | ||
808 | static int hpc_power_off_slot(struct slot * slot) | 719 | static int hpc_power_off_slot(struct slot * slot) |
809 | { | 720 | { |
810 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 721 | struct controller *ctrl = slot->ctrl; |
811 | u16 slot_cmd; | 722 | u16 slot_cmd; |
812 | u16 slot_ctrl; | 723 | u16 slot_ctrl; |
813 | |||
814 | int retval = 0; | 724 | int retval = 0; |
815 | 725 | ||
816 | DBG_ENTER_ROUTINE | 726 | DBG_ENTER_ROUTINE |
817 | 727 | ||
818 | if (!php_ctlr) { | ||
819 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
820 | return -1; | ||
821 | } | ||
822 | |||
823 | dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot); | 728 | dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot); |
824 | slot->hp_slot = 0; | ||
825 | if (slot->hp_slot >= php_ctlr->num_slots) { | ||
826 | err("%s: Invalid HPC slot number!\n", __FUNCTION__); | ||
827 | return -1; | ||
828 | } | ||
829 | retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); | ||
830 | 729 | ||
730 | retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); | ||
831 | if (retval) { | 731 | if (retval) { |
832 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 732 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
833 | return retval; | 733 | return retval; |
834 | } | 734 | } |
835 | 735 | ||
@@ -854,47 +754,25 @@ static int hpc_power_off_slot(struct slot * slot) | |||
854 | err("%s: Write command failed!\n", __FUNCTION__); | 754 | err("%s: Write command failed!\n", __FUNCTION__); |
855 | return -1; | 755 | return -1; |
856 | } | 756 | } |
857 | dbg("%s: SLOT_CTRL %x write cmd %x\n",__FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); | 757 | dbg("%s: SLOTCTRL %x write cmd %x\n", |
758 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); | ||
858 | 759 | ||
859 | DBG_LEAVE_ROUTINE | 760 | DBG_LEAVE_ROUTINE |
860 | 761 | ||
861 | return retval; | 762 | return retval; |
862 | } | 763 | } |
863 | 764 | ||
864 | static irqreturn_t pcie_isr(int IRQ, void *dev_id) | 765 | static irqreturn_t pcie_isr(int irq, void *dev_id) |
865 | { | 766 | { |
866 | struct controller *ctrl = NULL; | 767 | struct controller *ctrl = (struct controller *)dev_id; |
867 | struct php_ctlr_state_s *php_ctlr; | ||
868 | u8 schedule_flag = 0; | ||
869 | u16 slot_status, intr_detect, intr_loc; | 768 | u16 slot_status, intr_detect, intr_loc; |
870 | u16 temp_word; | 769 | u16 temp_word; |
871 | int hp_slot = 0; /* only 1 slot per PCI Express port */ | 770 | int hp_slot = 0; /* only 1 slot per PCI Express port */ |
872 | int rc = 0; | 771 | int rc = 0; |
873 | 772 | ||
874 | if (!dev_id) | 773 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
875 | return IRQ_NONE; | ||
876 | |||
877 | if (!pciehp_poll_mode) { | ||
878 | ctrl = dev_id; | ||
879 | php_ctlr = ctrl->hpc_ctlr_handle; | ||
880 | } else { | ||
881 | php_ctlr = dev_id; | ||
882 | ctrl = (struct controller *)php_ctlr->callback_instance_id; | ||
883 | } | ||
884 | |||
885 | if (!ctrl) { | ||
886 | dbg("%s: dev_id %p ctlr == NULL\n", __FUNCTION__, (void*) dev_id); | ||
887 | return IRQ_NONE; | ||
888 | } | ||
889 | |||
890 | if (!php_ctlr) { | ||
891 | dbg("%s: php_ctlr == NULL\n", __FUNCTION__); | ||
892 | return IRQ_NONE; | ||
893 | } | ||
894 | |||
895 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); | ||
896 | if (rc) { | 774 | if (rc) { |
897 | err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); | 775 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
898 | return IRQ_NONE; | 776 | return IRQ_NONE; |
899 | } | 777 | } |
900 | 778 | ||
@@ -910,33 +788,38 @@ static irqreturn_t pcie_isr(int IRQ, void *dev_id) | |||
910 | dbg("%s: intr_loc %x\n", __FUNCTION__, intr_loc); | 788 | dbg("%s: intr_loc %x\n", __FUNCTION__, intr_loc); |
911 | /* Mask Hot-plug Interrupt Enable */ | 789 | /* Mask Hot-plug Interrupt Enable */ |
912 | if (!pciehp_poll_mode) { | 790 | if (!pciehp_poll_mode) { |
913 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(ctrl->cap_base), temp_word); | 791 | rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); |
914 | if (rc) { | 792 | if (rc) { |
915 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 793 | err("%s: Cannot read SLOT_CTRL register\n", |
794 | __FUNCTION__); | ||
916 | return IRQ_NONE; | 795 | return IRQ_NONE; |
917 | } | 796 | } |
918 | 797 | ||
919 | dbg("%s: hp_register_read_word SLOT_CTRL with value %x\n", __FUNCTION__, temp_word); | 798 | dbg("%s: pciehp_readw(SLOTCTRL) with value %x\n", |
799 | __FUNCTION__, temp_word); | ||
920 | temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00; | 800 | temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00; |
921 | 801 | rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); | |
922 | rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_CTRL(ctrl->cap_base), temp_word); | ||
923 | if (rc) { | 802 | if (rc) { |
924 | err("%s : hp_register_write_word SLOT_CTRL failed\n", __FUNCTION__); | 803 | err("%s: Cannot write to SLOTCTRL register\n", |
804 | __FUNCTION__); | ||
925 | return IRQ_NONE; | 805 | return IRQ_NONE; |
926 | } | 806 | } |
927 | 807 | ||
928 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); | 808 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
929 | if (rc) { | 809 | if (rc) { |
930 | err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); | 810 | err("%s: Cannot read SLOT_STATUS register\n", |
811 | __FUNCTION__); | ||
931 | return IRQ_NONE; | 812 | return IRQ_NONE; |
932 | } | 813 | } |
933 | dbg("%s: hp_register_read_word SLOT_STATUS with value %x\n", __FUNCTION__, slot_status); | 814 | dbg("%s: pciehp_readw(SLOTSTATUS) with value %x\n", |
815 | __FUNCTION__, slot_status); | ||
934 | 816 | ||
935 | /* Clear command complete interrupt caused by this write */ | 817 | /* Clear command complete interrupt caused by this write */ |
936 | temp_word = 0x1f; | 818 | temp_word = 0x1f; |
937 | rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), temp_word); | 819 | rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); |
938 | if (rc) { | 820 | if (rc) { |
939 | err("%s : hp_register_write_word SLOT_STATUS failed\n", __FUNCTION__); | 821 | err("%s: Cannot write to SLOTSTATUS register\n", |
822 | __FUNCTION__); | ||
940 | return IRQ_NONE; | 823 | return IRQ_NONE; |
941 | } | 824 | } |
942 | } | 825 | } |
@@ -945,60 +828,65 @@ static irqreturn_t pcie_isr(int IRQ, void *dev_id) | |||
945 | /* | 828 | /* |
946 | * Command Complete Interrupt Pending | 829 | * Command Complete Interrupt Pending |
947 | */ | 830 | */ |
831 | ctrl->cmd_busy = 0; | ||
948 | wake_up_interruptible(&ctrl->queue); | 832 | wake_up_interruptible(&ctrl->queue); |
949 | } | 833 | } |
950 | 834 | ||
951 | if ((php_ctlr->switch_change_callback) && (intr_loc & MRL_SENS_CHANGED)) | 835 | if (intr_loc & MRL_SENS_CHANGED) |
952 | schedule_flag += php_ctlr->switch_change_callback( | 836 | pciehp_handle_switch_change(hp_slot, ctrl); |
953 | hp_slot, php_ctlr->callback_instance_id); | 837 | |
954 | if ((php_ctlr->attention_button_callback) && (intr_loc & ATTN_BUTTN_PRESSED)) | 838 | if (intr_loc & ATTN_BUTTN_PRESSED) |
955 | schedule_flag += php_ctlr->attention_button_callback( | 839 | pciehp_handle_attention_button(hp_slot, ctrl); |
956 | hp_slot, php_ctlr->callback_instance_id); | 840 | |
957 | if ((php_ctlr->presence_change_callback) && (intr_loc & PRSN_DETECT_CHANGED)) | 841 | if (intr_loc & PRSN_DETECT_CHANGED) |
958 | schedule_flag += php_ctlr->presence_change_callback( | 842 | pciehp_handle_presence_change(hp_slot, ctrl); |
959 | hp_slot , php_ctlr->callback_instance_id); | 843 | |
960 | if ((php_ctlr->power_fault_callback) && (intr_loc & PWR_FAULT_DETECTED)) | 844 | if (intr_loc & PWR_FAULT_DETECTED) |
961 | schedule_flag += php_ctlr->power_fault_callback( | 845 | pciehp_handle_power_fault(hp_slot, ctrl); |
962 | hp_slot, php_ctlr->callback_instance_id); | ||
963 | 846 | ||
964 | /* Clear all events after serving them */ | 847 | /* Clear all events after serving them */ |
965 | temp_word = 0x1F; | 848 | temp_word = 0x1F; |
966 | rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), temp_word); | 849 | rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); |
967 | if (rc) { | 850 | if (rc) { |
968 | err("%s : hp_register_write_word SLOT_STATUS failed\n", __FUNCTION__); | 851 | err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); |
969 | return IRQ_NONE; | 852 | return IRQ_NONE; |
970 | } | 853 | } |
971 | /* Unmask Hot-plug Interrupt Enable */ | 854 | /* Unmask Hot-plug Interrupt Enable */ |
972 | if (!pciehp_poll_mode) { | 855 | if (!pciehp_poll_mode) { |
973 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(ctrl->cap_base), temp_word); | 856 | rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); |
974 | if (rc) { | 857 | if (rc) { |
975 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 858 | err("%s: Cannot read SLOTCTRL register\n", |
859 | __FUNCTION__); | ||
976 | return IRQ_NONE; | 860 | return IRQ_NONE; |
977 | } | 861 | } |
978 | 862 | ||
979 | dbg("%s: Unmask Hot-plug Interrupt Enable\n", __FUNCTION__); | 863 | dbg("%s: Unmask Hot-plug Interrupt Enable\n", __FUNCTION__); |
980 | temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE; | 864 | temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE; |
981 | 865 | ||
982 | rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_CTRL(ctrl->cap_base), temp_word); | 866 | rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); |
983 | if (rc) { | 867 | if (rc) { |
984 | err("%s : hp_register_write_word SLOT_CTRL failed\n", __FUNCTION__); | 868 | err("%s: Cannot write to SLOTCTRL register\n", |
869 | __FUNCTION__); | ||
985 | return IRQ_NONE; | 870 | return IRQ_NONE; |
986 | } | 871 | } |
987 | 872 | ||
988 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); | 873 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
989 | if (rc) { | 874 | if (rc) { |
990 | err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); | 875 | err("%s: Cannot read SLOT_STATUS register\n", |
876 | __FUNCTION__); | ||
991 | return IRQ_NONE; | 877 | return IRQ_NONE; |
992 | } | 878 | } |
993 | 879 | ||
994 | /* Clear command complete interrupt caused by this write */ | 880 | /* Clear command complete interrupt caused by this write */ |
995 | temp_word = 0x1F; | 881 | temp_word = 0x1F; |
996 | rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), temp_word); | 882 | rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); |
997 | if (rc) { | 883 | if (rc) { |
998 | err("%s : hp_register_write_word SLOT_STATUS failed\n", __FUNCTION__); | 884 | err("%s: Cannot write to SLOTSTATUS failed\n", |
885 | __FUNCTION__); | ||
999 | return IRQ_NONE; | 886 | return IRQ_NONE; |
1000 | } | 887 | } |
1001 | dbg("%s: hp_register_write_word SLOT_STATUS with value %x\n", __FUNCTION__, temp_word); | 888 | dbg("%s: pciehp_writew(SLOTSTATUS) with value %x\n", |
889 | __FUNCTION__, temp_word); | ||
1002 | } | 890 | } |
1003 | 891 | ||
1004 | return IRQ_HANDLED; | 892 | return IRQ_HANDLED; |
@@ -1006,27 +894,16 @@ static irqreturn_t pcie_isr(int IRQ, void *dev_id) | |||
1006 | 894 | ||
1007 | static int hpc_get_max_lnk_speed (struct slot *slot, enum pci_bus_speed *value) | 895 | static int hpc_get_max_lnk_speed (struct slot *slot, enum pci_bus_speed *value) |
1008 | { | 896 | { |
1009 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 897 | struct controller *ctrl = slot->ctrl; |
1010 | enum pcie_link_speed lnk_speed; | 898 | enum pcie_link_speed lnk_speed; |
1011 | u32 lnk_cap; | 899 | u32 lnk_cap; |
1012 | int retval = 0; | 900 | int retval = 0; |
1013 | 901 | ||
1014 | DBG_ENTER_ROUTINE | 902 | DBG_ENTER_ROUTINE |
1015 | 903 | ||
1016 | if (!php_ctlr) { | 904 | retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap); |
1017 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
1018 | return -1; | ||
1019 | } | ||
1020 | |||
1021 | if (slot->hp_slot >= php_ctlr->num_slots) { | ||
1022 | err("%s: Invalid HPC slot number!\n", __FUNCTION__); | ||
1023 | return -1; | ||
1024 | } | ||
1025 | |||
1026 | retval = hp_register_read_dword(php_ctlr->pci_dev, LNK_CAP(slot->ctrl->cap_base), lnk_cap); | ||
1027 | |||
1028 | if (retval) { | 905 | if (retval) { |
1029 | err("%s : hp_register_read_dword LNK_CAP failed\n", __FUNCTION__); | 906 | err("%s: Cannot read LNKCAP register\n", __FUNCTION__); |
1030 | return retval; | 907 | return retval; |
1031 | } | 908 | } |
1032 | 909 | ||
@@ -1047,27 +924,16 @@ static int hpc_get_max_lnk_speed (struct slot *slot, enum pci_bus_speed *value) | |||
1047 | 924 | ||
1048 | static int hpc_get_max_lnk_width (struct slot *slot, enum pcie_link_width *value) | 925 | static int hpc_get_max_lnk_width (struct slot *slot, enum pcie_link_width *value) |
1049 | { | 926 | { |
1050 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 927 | struct controller *ctrl = slot->ctrl; |
1051 | enum pcie_link_width lnk_wdth; | 928 | enum pcie_link_width lnk_wdth; |
1052 | u32 lnk_cap; | 929 | u32 lnk_cap; |
1053 | int retval = 0; | 930 | int retval = 0; |
1054 | 931 | ||
1055 | DBG_ENTER_ROUTINE | 932 | DBG_ENTER_ROUTINE |
1056 | 933 | ||
1057 | if (!php_ctlr) { | 934 | retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap); |
1058 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
1059 | return -1; | ||
1060 | } | ||
1061 | |||
1062 | if (slot->hp_slot >= php_ctlr->num_slots) { | ||
1063 | err("%s: Invalid HPC slot number!\n", __FUNCTION__); | ||
1064 | return -1; | ||
1065 | } | ||
1066 | |||
1067 | retval = hp_register_read_dword(php_ctlr->pci_dev, LNK_CAP(slot->ctrl->cap_base), lnk_cap); | ||
1068 | |||
1069 | if (retval) { | 935 | if (retval) { |
1070 | err("%s : hp_register_read_dword LNK_CAP failed\n", __FUNCTION__); | 936 | err("%s: Cannot read LNKCAP register\n", __FUNCTION__); |
1071 | return retval; | 937 | return retval; |
1072 | } | 938 | } |
1073 | 939 | ||
@@ -1109,27 +975,16 @@ static int hpc_get_max_lnk_width (struct slot *slot, enum pcie_link_width *value | |||
1109 | 975 | ||
1110 | static int hpc_get_cur_lnk_speed (struct slot *slot, enum pci_bus_speed *value) | 976 | static int hpc_get_cur_lnk_speed (struct slot *slot, enum pci_bus_speed *value) |
1111 | { | 977 | { |
1112 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 978 | struct controller *ctrl = slot->ctrl; |
1113 | enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN; | 979 | enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN; |
1114 | int retval = 0; | 980 | int retval = 0; |
1115 | u16 lnk_status; | 981 | u16 lnk_status; |
1116 | 982 | ||
1117 | DBG_ENTER_ROUTINE | 983 | DBG_ENTER_ROUTINE |
1118 | 984 | ||
1119 | if (!php_ctlr) { | 985 | retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); |
1120 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
1121 | return -1; | ||
1122 | } | ||
1123 | |||
1124 | if (slot->hp_slot >= php_ctlr->num_slots) { | ||
1125 | err("%s: Invalid HPC slot number!\n", __FUNCTION__); | ||
1126 | return -1; | ||
1127 | } | ||
1128 | |||
1129 | retval = hp_register_read_word(php_ctlr->pci_dev, LNK_STATUS(slot->ctrl->cap_base), lnk_status); | ||
1130 | |||
1131 | if (retval) { | 986 | if (retval) { |
1132 | err("%s : hp_register_read_word LNK_STATUS failed\n", __FUNCTION__); | 987 | err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); |
1133 | return retval; | 988 | return retval; |
1134 | } | 989 | } |
1135 | 990 | ||
@@ -1150,27 +1005,16 @@ static int hpc_get_cur_lnk_speed (struct slot *slot, enum pci_bus_speed *value) | |||
1150 | 1005 | ||
1151 | static int hpc_get_cur_lnk_width (struct slot *slot, enum pcie_link_width *value) | 1006 | static int hpc_get_cur_lnk_width (struct slot *slot, enum pcie_link_width *value) |
1152 | { | 1007 | { |
1153 | struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; | 1008 | struct controller *ctrl = slot->ctrl; |
1154 | enum pcie_link_width lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN; | 1009 | enum pcie_link_width lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN; |
1155 | int retval = 0; | 1010 | int retval = 0; |
1156 | u16 lnk_status; | 1011 | u16 lnk_status; |
1157 | 1012 | ||
1158 | DBG_ENTER_ROUTINE | 1013 | DBG_ENTER_ROUTINE |
1159 | 1014 | ||
1160 | if (!php_ctlr) { | 1015 | retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); |
1161 | err("%s: Invalid HPC controller handle!\n", __FUNCTION__); | ||
1162 | return -1; | ||
1163 | } | ||
1164 | |||
1165 | if (slot->hp_slot >= php_ctlr->num_slots) { | ||
1166 | err("%s: Invalid HPC slot number!\n", __FUNCTION__); | ||
1167 | return -1; | ||
1168 | } | ||
1169 | |||
1170 | retval = hp_register_read_word(php_ctlr->pci_dev, LNK_STATUS(slot->ctrl->cap_base), lnk_status); | ||
1171 | |||
1172 | if (retval) { | 1016 | if (retval) { |
1173 | err("%s : hp_register_read_word LNK_STATUS failed\n", __FUNCTION__); | 1017 | err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); |
1174 | return retval; | 1018 | return retval; |
1175 | } | 1019 | } |
1176 | 1020 | ||
@@ -1218,6 +1062,8 @@ static struct hpc_ops pciehp_hpc_ops = { | |||
1218 | .get_attention_status = hpc_get_attention_status, | 1062 | .get_attention_status = hpc_get_attention_status, |
1219 | .get_latch_status = hpc_get_latch_status, | 1063 | .get_latch_status = hpc_get_latch_status, |
1220 | .get_adapter_status = hpc_get_adapter_status, | 1064 | .get_adapter_status = hpc_get_adapter_status, |
1065 | .get_emi_status = hpc_get_emi_status, | ||
1066 | .toggle_emi = hpc_toggle_emi, | ||
1221 | 1067 | ||
1222 | .get_max_bus_speed = hpc_get_max_lnk_speed, | 1068 | .get_max_bus_speed = hpc_get_max_lnk_speed, |
1223 | .get_cur_bus_speed = hpc_get_cur_lnk_speed, | 1069 | .get_cur_bus_speed = hpc_get_cur_lnk_speed, |
@@ -1305,38 +1151,24 @@ int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev) | |||
1305 | 1151 | ||
1306 | int pcie_init(struct controller * ctrl, struct pcie_device *dev) | 1152 | int pcie_init(struct controller * ctrl, struct pcie_device *dev) |
1307 | { | 1153 | { |
1308 | struct php_ctlr_state_s *php_ctlr, *p; | ||
1309 | void *instance_id = ctrl; | ||
1310 | int rc; | 1154 | int rc; |
1311 | static int first = 1; | 1155 | static int first = 1; |
1312 | u16 temp_word; | 1156 | u16 temp_word; |
1313 | u16 cap_reg; | 1157 | u16 cap_reg; |
1314 | u16 intr_enable = 0; | 1158 | u16 intr_enable = 0; |
1315 | u32 slot_cap; | 1159 | u32 slot_cap; |
1316 | int cap_base, saved_cap_base; | 1160 | int cap_base; |
1317 | u16 slot_status, slot_ctrl; | 1161 | u16 slot_status, slot_ctrl; |
1318 | struct pci_dev *pdev; | 1162 | struct pci_dev *pdev; |
1319 | 1163 | ||
1320 | DBG_ENTER_ROUTINE | 1164 | DBG_ENTER_ROUTINE |
1321 | 1165 | ||
1322 | spin_lock_init(&list_lock); | ||
1323 | php_ctlr = kmalloc(sizeof(struct php_ctlr_state_s), GFP_KERNEL); | ||
1324 | |||
1325 | if (!php_ctlr) { /* allocate controller state data */ | ||
1326 | err("%s: HPC controller memory allocation error!\n", __FUNCTION__); | ||
1327 | goto abort; | ||
1328 | } | ||
1329 | |||
1330 | memset(php_ctlr, 0, sizeof(struct php_ctlr_state_s)); | ||
1331 | |||
1332 | pdev = dev->port; | 1166 | pdev = dev->port; |
1333 | php_ctlr->pci_dev = pdev; /* save pci_dev in context */ | 1167 | ctrl->pci_dev = pdev; /* save pci_dev in context */ |
1334 | 1168 | ||
1335 | dbg("%s: hotplug controller vendor id 0x%x device id 0x%x\n", | 1169 | dbg("%s: hotplug controller vendor id 0x%x device id 0x%x\n", |
1336 | __FUNCTION__, pdev->vendor, pdev->device); | 1170 | __FUNCTION__, pdev->vendor, pdev->device); |
1337 | 1171 | ||
1338 | saved_cap_base = pcie_cap_base; | ||
1339 | |||
1340 | if ((cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP)) == 0) { | 1172 | if ((cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP)) == 0) { |
1341 | dbg("%s: Can't find PCI_CAP_ID_EXP (0x10)\n", __FUNCTION__); | 1173 | dbg("%s: Can't find PCI_CAP_ID_EXP (0x10)\n", __FUNCTION__); |
1342 | goto abort_free_ctlr; | 1174 | goto abort_free_ctlr; |
@@ -1344,14 +1176,15 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev) | |||
1344 | 1176 | ||
1345 | ctrl->cap_base = cap_base; | 1177 | ctrl->cap_base = cap_base; |
1346 | 1178 | ||
1347 | dbg("%s: pcie_cap_base %x\n", __FUNCTION__, pcie_cap_base); | 1179 | dbg("%s: pcie_cap_base %x\n", __FUNCTION__, cap_base); |
1348 | 1180 | ||
1349 | rc = hp_register_read_word(pdev, CAP_REG(ctrl->cap_base), cap_reg); | 1181 | rc = pciehp_readw(ctrl, CAPREG, &cap_reg); |
1350 | if (rc) { | 1182 | if (rc) { |
1351 | err("%s : hp_register_read_word CAP_REG failed\n", __FUNCTION__); | 1183 | err("%s: Cannot read CAPREG register\n", __FUNCTION__); |
1352 | goto abort_free_ctlr; | 1184 | goto abort_free_ctlr; |
1353 | } | 1185 | } |
1354 | dbg("%s: CAP_REG offset %x cap_reg %x\n", __FUNCTION__, CAP_REG(ctrl->cap_base), cap_reg); | 1186 | dbg("%s: CAPREG offset %x cap_reg %x\n", |
1187 | __FUNCTION__, ctrl->cap_base + CAPREG, cap_reg); | ||
1355 | 1188 | ||
1356 | if (((cap_reg & SLOT_IMPL) == 0) || (((cap_reg & DEV_PORT_TYPE) != 0x0040) | 1189 | if (((cap_reg & SLOT_IMPL) == 0) || (((cap_reg & DEV_PORT_TYPE) != 0x0040) |
1357 | && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) { | 1190 | && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) { |
@@ -1359,31 +1192,34 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev) | |||
1359 | goto abort_free_ctlr; | 1192 | goto abort_free_ctlr; |
1360 | } | 1193 | } |
1361 | 1194 | ||
1362 | rc = hp_register_read_dword(php_ctlr->pci_dev, SLOT_CAP(ctrl->cap_base), slot_cap); | 1195 | rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap); |
1363 | if (rc) { | 1196 | if (rc) { |
1364 | err("%s : hp_register_read_word CAP_REG failed\n", __FUNCTION__); | 1197 | err("%s: Cannot read SLOTCAP register\n", __FUNCTION__); |
1365 | goto abort_free_ctlr; | 1198 | goto abort_free_ctlr; |
1366 | } | 1199 | } |
1367 | dbg("%s: SLOT_CAP offset %x slot_cap %x\n", __FUNCTION__, SLOT_CAP(ctrl->cap_base), slot_cap); | 1200 | dbg("%s: SLOTCAP offset %x slot_cap %x\n", |
1201 | __FUNCTION__, ctrl->cap_base + SLOTCAP, slot_cap); | ||
1368 | 1202 | ||
1369 | if (!(slot_cap & HP_CAP)) { | 1203 | if (!(slot_cap & HP_CAP)) { |
1370 | dbg("%s : This slot is not hot-plug capable\n", __FUNCTION__); | 1204 | dbg("%s : This slot is not hot-plug capable\n", __FUNCTION__); |
1371 | goto abort_free_ctlr; | 1205 | goto abort_free_ctlr; |
1372 | } | 1206 | } |
1373 | /* For debugging purpose */ | 1207 | /* For debugging purpose */ |
1374 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); | 1208 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
1375 | if (rc) { | 1209 | if (rc) { |
1376 | err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); | 1210 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
1377 | goto abort_free_ctlr; | 1211 | goto abort_free_ctlr; |
1378 | } | 1212 | } |
1379 | dbg("%s: SLOT_STATUS offset %x slot_status %x\n", __FUNCTION__, SLOT_STATUS(ctrl->cap_base), slot_status); | 1213 | dbg("%s: SLOTSTATUS offset %x slot_status %x\n", |
1214 | __FUNCTION__, ctrl->cap_base + SLOTSTATUS, slot_status); | ||
1380 | 1215 | ||
1381 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(ctrl->cap_base), slot_ctrl); | 1216 | rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); |
1382 | if (rc) { | 1217 | if (rc) { |
1383 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 1218 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
1384 | goto abort_free_ctlr; | 1219 | goto abort_free_ctlr; |
1385 | } | 1220 | } |
1386 | dbg("%s: SLOT_CTRL offset %x slot_ctrl %x\n", __FUNCTION__, SLOT_CTRL(ctrl->cap_base), slot_ctrl); | 1221 | dbg("%s: SLOTCTRL offset %x slot_ctrl %x\n", |
1222 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl); | ||
1387 | 1223 | ||
1388 | if (first) { | 1224 | if (first) { |
1389 | spin_lock_init(&hpc_event_lock); | 1225 | spin_lock_init(&hpc_event_lock); |
@@ -1405,69 +1241,64 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev) | |||
1405 | /* setup wait queue */ | 1241 | /* setup wait queue */ |
1406 | init_waitqueue_head(&ctrl->queue); | 1242 | init_waitqueue_head(&ctrl->queue); |
1407 | 1243 | ||
1408 | /* find the IRQ */ | ||
1409 | php_ctlr->irq = dev->irq; | ||
1410 | |||
1411 | /* Save interrupt callback info */ | ||
1412 | php_ctlr->attention_button_callback = pciehp_handle_attention_button; | ||
1413 | php_ctlr->switch_change_callback = pciehp_handle_switch_change; | ||
1414 | php_ctlr->presence_change_callback = pciehp_handle_presence_change; | ||
1415 | php_ctlr->power_fault_callback = pciehp_handle_power_fault; | ||
1416 | php_ctlr->callback_instance_id = instance_id; | ||
1417 | |||
1418 | /* return PCI Controller Info */ | 1244 | /* return PCI Controller Info */ |
1419 | php_ctlr->slot_device_offset = 0; | 1245 | ctrl->slot_device_offset = 0; |
1420 | php_ctlr->num_slots = 1; | 1246 | ctrl->num_slots = 1; |
1247 | ctrl->first_slot = slot_cap >> 19; | ||
1248 | ctrl->ctrlcap = slot_cap & 0x0000007f; | ||
1421 | 1249 | ||
1422 | /* Mask Hot-plug Interrupt Enable */ | 1250 | /* Mask Hot-plug Interrupt Enable */ |
1423 | rc = hp_register_read_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); | 1251 | rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); |
1424 | if (rc) { | 1252 | if (rc) { |
1425 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 1253 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
1426 | goto abort_free_ctlr; | 1254 | goto abort_free_ctlr; |
1427 | } | 1255 | } |
1428 | 1256 | ||
1429 | dbg("%s: SLOT_CTRL %x value read %x\n", __FUNCTION__, SLOT_CTRL(ctrl->cap_base), temp_word); | 1257 | dbg("%s: SLOTCTRL %x value read %x\n", |
1258 | __FUNCTION__, ctrl->cap_base + SLOTCTRL, temp_word); | ||
1430 | temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00; | 1259 | temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00; |
1431 | 1260 | ||
1432 | rc = hp_register_write_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); | 1261 | rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); |
1433 | if (rc) { | 1262 | if (rc) { |
1434 | err("%s : hp_register_write_word SLOT_CTRL failed\n", __FUNCTION__); | 1263 | err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); |
1435 | goto abort_free_ctlr; | 1264 | goto abort_free_ctlr; |
1436 | } | 1265 | } |
1437 | 1266 | ||
1438 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); | 1267 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
1439 | if (rc) { | 1268 | if (rc) { |
1440 | err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); | 1269 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
1441 | goto abort_free_ctlr; | 1270 | goto abort_free_ctlr; |
1442 | } | 1271 | } |
1443 | 1272 | ||
1444 | temp_word = 0x1F; /* Clear all events */ | 1273 | temp_word = 0x1F; /* Clear all events */ |
1445 | rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), temp_word); | 1274 | rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); |
1446 | if (rc) { | 1275 | if (rc) { |
1447 | err("%s : hp_register_write_word SLOT_STATUS failed\n", __FUNCTION__); | 1276 | err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); |
1448 | goto abort_free_ctlr; | 1277 | goto abort_free_ctlr; |
1449 | } | 1278 | } |
1450 | 1279 | ||
1451 | if (pciehp_poll_mode) {/* Install interrupt polling code */ | 1280 | if (pciehp_poll_mode) { |
1452 | /* Install and start the interrupt polling timer */ | 1281 | /* Install interrupt polling timer. Start with 10 sec delay */ |
1453 | init_timer(&php_ctlr->int_poll_timer); | 1282 | init_timer(&ctrl->poll_timer); |
1454 | start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */ | 1283 | start_int_poll_timer(ctrl, 10); |
1455 | } else { | 1284 | } else { |
1456 | /* Installs the interrupt handler */ | 1285 | /* Installs the interrupt handler */ |
1457 | rc = request_irq(php_ctlr->irq, pcie_isr, IRQF_SHARED, MY_NAME, (void *) ctrl); | 1286 | rc = request_irq(ctrl->pci_dev->irq, pcie_isr, IRQF_SHARED, |
1458 | dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc); | 1287 | MY_NAME, (void *)ctrl); |
1288 | dbg("%s: request_irq %d for hpc%d (returns %d)\n", | ||
1289 | __FUNCTION__, ctrl->pci_dev->irq, ctlr_seq_num, rc); | ||
1459 | if (rc) { | 1290 | if (rc) { |
1460 | err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq); | 1291 | err("Can't get irq %d for the hotplug controller\n", |
1292 | ctrl->pci_dev->irq); | ||
1461 | goto abort_free_ctlr; | 1293 | goto abort_free_ctlr; |
1462 | } | 1294 | } |
1463 | } | 1295 | } |
1464 | |||
1465 | dbg("pciehp ctrl b:d:f:irq=0x%x:%x:%x:%x\n", pdev->bus->number, | 1296 | dbg("pciehp ctrl b:d:f:irq=0x%x:%x:%x:%x\n", pdev->bus->number, |
1466 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), dev->irq); | 1297 | PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), dev->irq); |
1467 | 1298 | ||
1468 | rc = hp_register_read_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); | 1299 | rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); |
1469 | if (rc) { | 1300 | if (rc) { |
1470 | err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); | 1301 | err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); |
1471 | goto abort_free_irq; | 1302 | goto abort_free_irq; |
1472 | } | 1303 | } |
1473 | 1304 | ||
@@ -1491,21 +1322,21 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev) | |||
1491 | } | 1322 | } |
1492 | 1323 | ||
1493 | /* Unmask Hot-plug Interrupt Enable for the interrupt notification mechanism case */ | 1324 | /* Unmask Hot-plug Interrupt Enable for the interrupt notification mechanism case */ |
1494 | rc = hp_register_write_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); | 1325 | rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); |
1495 | if (rc) { | 1326 | if (rc) { |
1496 | err("%s : hp_register_write_word SLOT_CTRL failed\n", __FUNCTION__); | 1327 | err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); |
1497 | goto abort_free_irq; | 1328 | goto abort_free_irq; |
1498 | } | 1329 | } |
1499 | rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); | 1330 | rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); |
1500 | if (rc) { | 1331 | if (rc) { |
1501 | err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); | 1332 | err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); |
1502 | goto abort_disable_intr; | 1333 | goto abort_disable_intr; |
1503 | } | 1334 | } |
1504 | 1335 | ||
1505 | temp_word = 0x1F; /* Clear all events */ | 1336 | temp_word = 0x1F; /* Clear all events */ |
1506 | rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), temp_word); | 1337 | rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); |
1507 | if (rc) { | 1338 | if (rc) { |
1508 | err("%s : hp_register_write_word SLOT_STATUS failed\n", __FUNCTION__); | 1339 | err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); |
1509 | goto abort_disable_intr; | 1340 | goto abort_disable_intr; |
1510 | } | 1341 | } |
1511 | 1342 | ||
@@ -1518,24 +1349,7 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev) | |||
1518 | goto abort_disable_intr; | 1349 | goto abort_disable_intr; |
1519 | } | 1350 | } |
1520 | 1351 | ||
1521 | /* Add this HPC instance into the HPC list */ | ||
1522 | spin_lock(&list_lock); | ||
1523 | if (php_ctlr_list_head == 0) { | ||
1524 | php_ctlr_list_head = php_ctlr; | ||
1525 | p = php_ctlr_list_head; | ||
1526 | p->pnext = NULL; | ||
1527 | } else { | ||
1528 | p = php_ctlr_list_head; | ||
1529 | |||
1530 | while (p->pnext) | ||
1531 | p = p->pnext; | ||
1532 | |||
1533 | p->pnext = php_ctlr; | ||
1534 | } | ||
1535 | spin_unlock(&list_lock); | ||
1536 | |||
1537 | ctlr_seq_num++; | 1352 | ctlr_seq_num++; |
1538 | ctrl->hpc_ctlr_handle = php_ctlr; | ||
1539 | ctrl->hpc_ops = &pciehp_hpc_ops; | 1353 | ctrl->hpc_ops = &pciehp_hpc_ops; |
1540 | 1354 | ||
1541 | DBG_LEAVE_ROUTINE | 1355 | DBG_LEAVE_ROUTINE |
@@ -1543,24 +1357,21 @@ int pcie_init(struct controller * ctrl, struct pcie_device *dev) | |||
1543 | 1357 | ||
1544 | /* We end up here for the many possible ways to fail this API. */ | 1358 | /* We end up here for the many possible ways to fail this API. */ |
1545 | abort_disable_intr: | 1359 | abort_disable_intr: |
1546 | rc = hp_register_read_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); | 1360 | rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); |
1547 | if (!rc) { | 1361 | if (!rc) { |
1548 | temp_word &= ~(intr_enable | HP_INTR_ENABLE); | 1362 | temp_word &= ~(intr_enable | HP_INTR_ENABLE); |
1549 | rc = hp_register_write_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); | 1363 | rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); |
1550 | } | 1364 | } |
1551 | if (rc) | 1365 | if (rc) |
1552 | err("%s : disabling interrupts failed\n", __FUNCTION__); | 1366 | err("%s : disabling interrupts failed\n", __FUNCTION__); |
1553 | 1367 | ||
1554 | abort_free_irq: | 1368 | abort_free_irq: |
1555 | if (pciehp_poll_mode) | 1369 | if (pciehp_poll_mode) |
1556 | del_timer_sync(&php_ctlr->int_poll_timer); | 1370 | del_timer_sync(&ctrl->poll_timer); |
1557 | else | 1371 | else |
1558 | free_irq(php_ctlr->irq, ctrl); | 1372 | free_irq(ctrl->pci_dev->irq, ctrl); |
1559 | 1373 | ||
1560 | abort_free_ctlr: | 1374 | abort_free_ctlr: |
1561 | pcie_cap_base = saved_cap_base; | ||
1562 | kfree(php_ctlr); | ||
1563 | abort: | ||
1564 | DBG_LEAVE_ROUTINE | 1375 | DBG_LEAVE_ROUTINE |
1565 | return -1; | 1376 | return -1; |
1566 | } | 1377 | } |