pciehp.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * PCI Express Hot Plug Controller Driver
  4. *
  5. * Copyright (C) 1995,2001 Compaq Computer Corporation
  6. * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
  7. * Copyright (C) 2001 IBM Corp.
  8. * Copyright (C) 2003-2004 Intel Corporation
  9. *
  10. * All rights reserved.
  11. *
  12. * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
  13. *
  14. */
  15. #ifndef _PCIEHP_H
  16. #define _PCIEHP_H
  17. #include <linux/types.h>
  18. #include <linux/pci.h>
  19. #include <linux/pci_hotplug.h>
  20. #include <linux/delay.h>
  21. #include <linux/sched/signal.h> /* signal_pending() */
  22. #include <linux/mutex.h>
  23. #include <linux/workqueue.h>
  24. #include "../pcie/portdrv.h"
  25. #define MY_NAME "pciehp"
  26. extern bool pciehp_poll_mode;
  27. extern int pciehp_poll_time;
  28. extern bool pciehp_debug;
  29. #define dbg(format, arg...) \
  30. do { \
  31. if (pciehp_debug) \
  32. printk(KERN_DEBUG "%s: " format, MY_NAME, ## arg); \
  33. } while (0)
  34. #define err(format, arg...) \
  35. printk(KERN_ERR "%s: " format, MY_NAME, ## arg)
  36. #define info(format, arg...) \
  37. printk(KERN_INFO "%s: " format, MY_NAME, ## arg)
  38. #define warn(format, arg...) \
  39. printk(KERN_WARNING "%s: " format, MY_NAME, ## arg)
  40. #define ctrl_dbg(ctrl, format, arg...) \
  41. do { \
  42. if (pciehp_debug) \
  43. dev_printk(KERN_DEBUG, &ctrl->pcie->device, \
  44. format, ## arg); \
  45. } while (0)
  46. #define ctrl_err(ctrl, format, arg...) \
  47. dev_err(&ctrl->pcie->device, format, ## arg)
  48. #define ctrl_info(ctrl, format, arg...) \
  49. dev_info(&ctrl->pcie->device, format, ## arg)
  50. #define ctrl_warn(ctrl, format, arg...) \
  51. dev_warn(&ctrl->pcie->device, format, ## arg)
  52. #define SLOT_NAME_SIZE 10
  53. struct slot {
  54. u8 state;
  55. struct controller *ctrl;
  56. struct hotplug_slot *hotplug_slot;
  57. struct delayed_work work; /* work for button event */
  58. struct mutex lock;
  59. struct mutex hotplug_lock;
  60. struct workqueue_struct *wq;
  61. };
  62. struct event_info {
  63. u32 event_type;
  64. struct slot *p_slot;
  65. struct work_struct work;
  66. };
  67. struct controller {
  68. struct mutex ctrl_lock; /* controller lock */
  69. struct pcie_device *pcie; /* PCI Express port service */
  70. struct slot *slot;
  71. wait_queue_head_t queue; /* sleep & wake process */
  72. u32 slot_cap;
  73. u16 slot_ctrl;
  74. struct timer_list poll_timer;
  75. unsigned long cmd_started; /* jiffies */
  76. unsigned int cmd_busy:1;
  77. unsigned int link_active_reporting:1;
  78. unsigned int notification_enabled:1;
  79. unsigned int power_fault_detected;
  80. };
  81. #define INT_PRESENCE_ON 1
  82. #define INT_PRESENCE_OFF 2
  83. #define INT_POWER_FAULT 3
  84. #define INT_BUTTON_PRESS 4
  85. #define INT_LINK_UP 5
  86. #define INT_LINK_DOWN 6
  87. #define STATIC_STATE 0
  88. #define BLINKINGON_STATE 1
  89. #define BLINKINGOFF_STATE 2
  90. #define POWERON_STATE 3
  91. #define POWEROFF_STATE 4
  92. #define ATTN_BUTTN(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_ABP)
  93. #define POWER_CTRL(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_PCP)
  94. #define MRL_SENS(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_MRLSP)
  95. #define ATTN_LED(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_AIP)
  96. #define PWR_LED(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_PIP)
  97. #define HP_SUPR_RM(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_HPS)
  98. #define EMI(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_EIP)
  99. #define NO_CMD_CMPL(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_NCCS)
  100. #define PSN(ctrl) (((ctrl)->slot_cap & PCI_EXP_SLTCAP_PSN) >> 19)
  101. int pciehp_sysfs_enable_slot(struct slot *slot);
  102. int pciehp_sysfs_disable_slot(struct slot *slot);
  103. void pciehp_queue_interrupt_event(struct slot *slot, u32 event_type);
  104. int pciehp_configure_device(struct slot *p_slot);
  105. int pciehp_unconfigure_device(struct slot *p_slot);
  106. void pciehp_queue_pushbutton_work(struct work_struct *work);
  107. struct controller *pcie_init(struct pcie_device *dev);
  108. int pcie_init_notification(struct controller *ctrl);
  109. int pciehp_enable_slot(struct slot *p_slot);
  110. int pciehp_disable_slot(struct slot *p_slot);
  111. void pcie_enable_notification(struct controller *ctrl);
  112. int pciehp_power_on_slot(struct slot *slot);
  113. void pciehp_power_off_slot(struct slot *slot);
  114. void pciehp_get_power_status(struct slot *slot, u8 *status);
  115. void pciehp_get_attention_status(struct slot *slot, u8 *status);
  116. void pciehp_set_attention_status(struct slot *slot, u8 status);
  117. void pciehp_get_latch_status(struct slot *slot, u8 *status);
  118. void pciehp_get_adapter_status(struct slot *slot, u8 *status);
  119. int pciehp_query_power_fault(struct slot *slot);
  120. void pciehp_green_led_on(struct slot *slot);
  121. void pciehp_green_led_off(struct slot *slot);
  122. void pciehp_green_led_blink(struct slot *slot);
  123. int pciehp_check_link_status(struct controller *ctrl);
  124. bool pciehp_check_link_active(struct controller *ctrl);
  125. void pciehp_release_ctrl(struct controller *ctrl);
  126. int pciehp_reset_slot(struct slot *slot, int probe);
  127. int pciehp_set_raw_indicator_status(struct hotplug_slot *h_slot, u8 status);
  128. int pciehp_get_raw_indicator_status(struct hotplug_slot *h_slot, u8 *status);
  129. static inline const char *slot_name(struct slot *slot)
  130. {
  131. return hotplug_slot_name(slot->hotplug_slot);
  132. }
  133. #endif /* _PCIEHP_H */