pciehp_hpc.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. /*
  2. * PCI Express PCI Hot Plug Driver
  3. *
  4. * Copyright (C) 1995,2001 Compaq Computer Corporation
  5. * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
  6. * Copyright (C) 2001 IBM Corp.
  7. * Copyright (C) 2003-2004 Intel Corporation
  8. *
  9. * All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or (at
  14. * your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  19. * NON INFRINGEMENT. See the GNU General Public License for more
  20. * details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. *
  26. * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com>
  27. *
  28. */
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/types.h>
  32. #include <linux/signal.h>
  33. #include <linux/jiffies.h>
  34. #include <linux/timer.h>
  35. #include <linux/pci.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/time.h>
  38. #include "../pci.h"
  39. #include "pciehp.h"
  40. static atomic_t pciehp_num_controllers = ATOMIC_INIT(0);
  41. struct ctrl_reg {
  42. u8 cap_id;
  43. u8 nxt_ptr;
  44. u16 cap_reg;
  45. u32 dev_cap;
  46. u16 dev_ctrl;
  47. u16 dev_status;
  48. u32 lnk_cap;
  49. u16 lnk_ctrl;
  50. u16 lnk_status;
  51. u32 slot_cap;
  52. u16 slot_ctrl;
  53. u16 slot_status;
  54. u16 root_ctrl;
  55. u16 rsvp;
  56. u32 root_status;
  57. } __attribute__ ((packed));
  58. /* offsets to the controller registers based on the above structure layout */
  59. enum ctrl_offsets {
  60. PCIECAPID = offsetof(struct ctrl_reg, cap_id),
  61. NXTCAPPTR = offsetof(struct ctrl_reg, nxt_ptr),
  62. CAPREG = offsetof(struct ctrl_reg, cap_reg),
  63. DEVCAP = offsetof(struct ctrl_reg, dev_cap),
  64. DEVCTRL = offsetof(struct ctrl_reg, dev_ctrl),
  65. DEVSTATUS = offsetof(struct ctrl_reg, dev_status),
  66. LNKCAP = offsetof(struct ctrl_reg, lnk_cap),
  67. LNKCTRL = offsetof(struct ctrl_reg, lnk_ctrl),
  68. LNKSTATUS = offsetof(struct ctrl_reg, lnk_status),
  69. SLOTCAP = offsetof(struct ctrl_reg, slot_cap),
  70. SLOTCTRL = offsetof(struct ctrl_reg, slot_ctrl),
  71. SLOTSTATUS = offsetof(struct ctrl_reg, slot_status),
  72. ROOTCTRL = offsetof(struct ctrl_reg, root_ctrl),
  73. ROOTSTATUS = offsetof(struct ctrl_reg, root_status),
  74. };
  75. static inline int pciehp_readw(struct controller *ctrl, int reg, u16 *value)
  76. {
  77. struct pci_dev *dev = ctrl->pci_dev;
  78. return pci_read_config_word(dev, ctrl->cap_base + reg, value);
  79. }
  80. static inline int pciehp_readl(struct controller *ctrl, int reg, u32 *value)
  81. {
  82. struct pci_dev *dev = ctrl->pci_dev;
  83. return pci_read_config_dword(dev, ctrl->cap_base + reg, value);
  84. }
  85. static inline int pciehp_writew(struct controller *ctrl, int reg, u16 value)
  86. {
  87. struct pci_dev *dev = ctrl->pci_dev;
  88. return pci_write_config_word(dev, ctrl->cap_base + reg, value);
  89. }
  90. static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value)
  91. {
  92. struct pci_dev *dev = ctrl->pci_dev;
  93. return pci_write_config_dword(dev, ctrl->cap_base + reg, value);
  94. }
  95. /* Field definitions in PCI Express Capabilities Register */
  96. #define CAP_VER 0x000F
  97. #define DEV_PORT_TYPE 0x00F0
  98. #define SLOT_IMPL 0x0100
  99. #define MSG_NUM 0x3E00
  100. /* Device or Port Type */
  101. #define NAT_ENDPT 0x00
  102. #define LEG_ENDPT 0x01
  103. #define ROOT_PORT 0x04
  104. #define UP_STREAM 0x05
  105. #define DN_STREAM 0x06
  106. #define PCIE_PCI_BRDG 0x07
  107. #define PCI_PCIE_BRDG 0x10
  108. /* Field definitions in Device Capabilities Register */
  109. #define DATTN_BUTTN_PRSN 0x1000
  110. #define DATTN_LED_PRSN 0x2000
  111. #define DPWR_LED_PRSN 0x4000
  112. /* Field definitions in Link Capabilities Register */
  113. #define MAX_LNK_SPEED 0x000F
  114. #define MAX_LNK_WIDTH 0x03F0
  115. /* Link Width Encoding */
  116. #define LNK_X1 0x01
  117. #define LNK_X2 0x02
  118. #define LNK_X4 0x04
  119. #define LNK_X8 0x08
  120. #define LNK_X12 0x0C
  121. #define LNK_X16 0x10
  122. #define LNK_X32 0x20
  123. /*Field definitions of Link Status Register */
  124. #define LNK_SPEED 0x000F
  125. #define NEG_LINK_WD 0x03F0
  126. #define LNK_TRN_ERR 0x0400
  127. #define LNK_TRN 0x0800
  128. #define SLOT_CLK_CONF 0x1000
  129. /* Field definitions in Slot Capabilities Register */
  130. #define ATTN_BUTTN_PRSN 0x00000001
  131. #define PWR_CTRL_PRSN 0x00000002
  132. #define MRL_SENS_PRSN 0x00000004
  133. #define ATTN_LED_PRSN 0x00000008
  134. #define PWR_LED_PRSN 0x00000010
  135. #define HP_SUPR_RM_SUP 0x00000020
  136. #define HP_CAP 0x00000040
  137. #define SLOT_PWR_VALUE 0x000003F8
  138. #define SLOT_PWR_LIMIT 0x00000C00
  139. #define PSN 0xFFF80000 /* PSN: Physical Slot Number */
  140. /* Field definitions in Slot Control Register */
  141. #define ATTN_BUTTN_ENABLE 0x0001
  142. #define PWR_FAULT_DETECT_ENABLE 0x0002
  143. #define MRL_DETECT_ENABLE 0x0004
  144. #define PRSN_DETECT_ENABLE 0x0008
  145. #define CMD_CMPL_INTR_ENABLE 0x0010
  146. #define HP_INTR_ENABLE 0x0020
  147. #define ATTN_LED_CTRL 0x00C0
  148. #define PWR_LED_CTRL 0x0300
  149. #define PWR_CTRL 0x0400
  150. #define EMI_CTRL 0x0800
  151. /* Attention indicator and Power indicator states */
  152. #define LED_ON 0x01
  153. #define LED_BLINK 0x10
  154. #define LED_OFF 0x11
  155. /* Power Control Command */
  156. #define POWER_ON 0
  157. #define POWER_OFF 0x0400
  158. /* EMI Status defines */
  159. #define EMI_DISENGAGED 0
  160. #define EMI_ENGAGED 1
  161. /* Field definitions in Slot Status Register */
  162. #define ATTN_BUTTN_PRESSED 0x0001
  163. #define PWR_FAULT_DETECTED 0x0002
  164. #define MRL_SENS_CHANGED 0x0004
  165. #define PRSN_DETECT_CHANGED 0x0008
  166. #define CMD_COMPLETED 0x0010
  167. #define MRL_STATE 0x0020
  168. #define PRSN_STATE 0x0040
  169. #define EMI_STATE 0x0080
  170. #define EMI_STATUS_BIT 7
  171. static irqreturn_t pcie_isr(int irq, void *dev_id);
  172. static void start_int_poll_timer(struct controller *ctrl, int sec);
  173. /* This is the interrupt polling timeout function. */
  174. static void int_poll_timeout(unsigned long data)
  175. {
  176. struct controller *ctrl = (struct controller *)data;
  177. /* Poll for interrupt events. regs == NULL => polling */
  178. pcie_isr(0, ctrl);
  179. init_timer(&ctrl->poll_timer);
  180. if (!pciehp_poll_time)
  181. pciehp_poll_time = 2; /* default polling interval is 2 sec */
  182. start_int_poll_timer(ctrl, pciehp_poll_time);
  183. }
  184. /* This function starts the interrupt polling timer. */
  185. static void start_int_poll_timer(struct controller *ctrl, int sec)
  186. {
  187. /* Clamp to sane value */
  188. if ((sec <= 0) || (sec > 60))
  189. sec = 2;
  190. ctrl->poll_timer.function = &int_poll_timeout;
  191. ctrl->poll_timer.data = (unsigned long)ctrl;
  192. ctrl->poll_timer.expires = jiffies + sec * HZ;
  193. add_timer(&ctrl->poll_timer);
  194. }
  195. static inline int pciehp_request_irq(struct controller *ctrl)
  196. {
  197. int retval, irq = ctrl->pci_dev->irq;
  198. /* Install interrupt polling timer. Start with 10 sec delay */
  199. if (pciehp_poll_mode) {
  200. init_timer(&ctrl->poll_timer);
  201. start_int_poll_timer(ctrl, 10);
  202. return 0;
  203. }
  204. /* Installs the interrupt handler */
  205. retval = request_irq(irq, pcie_isr, IRQF_SHARED, MY_NAME, ctrl);
  206. if (retval)
  207. err("Cannot get irq %d for the hotplug controller\n", irq);
  208. return retval;
  209. }
  210. static inline void pciehp_free_irq(struct controller *ctrl)
  211. {
  212. if (pciehp_poll_mode)
  213. del_timer_sync(&ctrl->poll_timer);
  214. else
  215. free_irq(ctrl->pci_dev->irq, ctrl);
  216. }
  217. static int pcie_poll_cmd(struct controller *ctrl)
  218. {
  219. u16 slot_status;
  220. int timeout = 1000;
  221. if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) {
  222. if (slot_status & CMD_COMPLETED) {
  223. pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED);
  224. return 1;
  225. }
  226. }
  227. while (timeout > 1000) {
  228. msleep(10);
  229. timeout -= 10;
  230. if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) {
  231. if (slot_status & CMD_COMPLETED) {
  232. pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED);
  233. return 1;
  234. }
  235. }
  236. }
  237. return 0; /* timeout */
  238. }
  239. static void pcie_wait_cmd(struct controller *ctrl, int poll)
  240. {
  241. unsigned int msecs = pciehp_poll_mode ? 2500 : 1000;
  242. unsigned long timeout = msecs_to_jiffies(msecs);
  243. int rc;
  244. if (poll)
  245. rc = pcie_poll_cmd(ctrl);
  246. else
  247. rc = wait_event_timeout(ctrl->queue, !ctrl->cmd_busy, timeout);
  248. if (!rc)
  249. dbg("Command not completed in 1000 msec\n");
  250. }
  251. /**
  252. * pcie_write_cmd - Issue controller command
  253. * @ctrl: controller to which the command is issued
  254. * @cmd: command value written to slot control register
  255. * @mask: bitmask of slot control register to be modified
  256. */
  257. static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
  258. {
  259. int retval = 0;
  260. u16 slot_status;
  261. u16 slot_ctrl;
  262. mutex_lock(&ctrl->ctrl_lock);
  263. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  264. if (retval) {
  265. err("%s: Cannot read SLOTSTATUS register\n", __func__);
  266. goto out;
  267. }
  268. if (slot_status & CMD_COMPLETED) {
  269. if (!ctrl->no_cmd_complete) {
  270. /*
  271. * After 1 sec and CMD_COMPLETED still not set, just
  272. * proceed forward to issue the next command according
  273. * to spec. Just print out the error message.
  274. */
  275. dbg("%s: CMD_COMPLETED not clear after 1 sec.\n",
  276. __func__);
  277. } else if (!NO_CMD_CMPL(ctrl)) {
  278. /*
  279. * This controller semms to notify of command completed
  280. * event even though it supports none of power
  281. * controller, attention led, power led and EMI.
  282. */
  283. dbg("%s: Unexpected CMD_COMPLETED. Need to wait for "
  284. "command completed event.\n", __func__);
  285. ctrl->no_cmd_complete = 0;
  286. } else {
  287. dbg("%s: Unexpected CMD_COMPLETED. Maybe the "
  288. "controller is broken.\n", __func__);
  289. }
  290. }
  291. retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
  292. if (retval) {
  293. err("%s: Cannot read SLOTCTRL register\n", __func__);
  294. goto out;
  295. }
  296. slot_ctrl &= ~mask;
  297. slot_ctrl |= (cmd & mask);
  298. /* Don't enable command completed if caller is changing it. */
  299. if (!(mask & CMD_CMPL_INTR_ENABLE))
  300. slot_ctrl |= CMD_CMPL_INTR_ENABLE;
  301. ctrl->cmd_busy = 1;
  302. smp_mb();
  303. retval = pciehp_writew(ctrl, SLOTCTRL, slot_ctrl);
  304. if (retval)
  305. err("%s: Cannot write to SLOTCTRL register\n", __func__);
  306. /*
  307. * Wait for command completion.
  308. */
  309. if (!retval && !ctrl->no_cmd_complete) {
  310. int poll = 0;
  311. /*
  312. * if hotplug interrupt is not enabled or command
  313. * completed interrupt is not enabled, we need to poll
  314. * command completed event.
  315. */
  316. if (!(slot_ctrl & HP_INTR_ENABLE) ||
  317. !(slot_ctrl & CMD_CMPL_INTR_ENABLE))
  318. poll = 1;
  319. pcie_wait_cmd(ctrl, poll);
  320. }
  321. out:
  322. mutex_unlock(&ctrl->ctrl_lock);
  323. return retval;
  324. }
  325. static int hpc_check_lnk_status(struct controller *ctrl)
  326. {
  327. u16 lnk_status;
  328. int retval = 0;
  329. retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
  330. if (retval) {
  331. err("%s: Cannot read LNKSTATUS register\n", __func__);
  332. return retval;
  333. }
  334. dbg("%s: lnk_status = %x\n", __func__, lnk_status);
  335. if ( (lnk_status & LNK_TRN) || (lnk_status & LNK_TRN_ERR) ||
  336. !(lnk_status & NEG_LINK_WD)) {
  337. err("%s : Link Training Error occurs \n", __func__);
  338. retval = -1;
  339. return retval;
  340. }
  341. return retval;
  342. }
  343. static int hpc_get_attention_status(struct slot *slot, u8 *status)
  344. {
  345. struct controller *ctrl = slot->ctrl;
  346. u16 slot_ctrl;
  347. u8 atten_led_state;
  348. int retval = 0;
  349. retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
  350. if (retval) {
  351. err("%s: Cannot read SLOTCTRL register\n", __func__);
  352. return retval;
  353. }
  354. dbg("%s: SLOTCTRL %x, value read %x\n",
  355. __func__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
  356. atten_led_state = (slot_ctrl & ATTN_LED_CTRL) >> 6;
  357. switch (atten_led_state) {
  358. case 0:
  359. *status = 0xFF; /* Reserved */
  360. break;
  361. case 1:
  362. *status = 1; /* On */
  363. break;
  364. case 2:
  365. *status = 2; /* Blink */
  366. break;
  367. case 3:
  368. *status = 0; /* Off */
  369. break;
  370. default:
  371. *status = 0xFF;
  372. break;
  373. }
  374. return 0;
  375. }
  376. static int hpc_get_power_status(struct slot *slot, u8 *status)
  377. {
  378. struct controller *ctrl = slot->ctrl;
  379. u16 slot_ctrl;
  380. u8 pwr_state;
  381. int retval = 0;
  382. retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
  383. if (retval) {
  384. err("%s: Cannot read SLOTCTRL register\n", __func__);
  385. return retval;
  386. }
  387. dbg("%s: SLOTCTRL %x value read %x\n",
  388. __func__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
  389. pwr_state = (slot_ctrl & PWR_CTRL) >> 10;
  390. switch (pwr_state) {
  391. case 0:
  392. *status = 1;
  393. break;
  394. case 1:
  395. *status = 0;
  396. break;
  397. default:
  398. *status = 0xFF;
  399. break;
  400. }
  401. return retval;
  402. }
  403. static int hpc_get_latch_status(struct slot *slot, u8 *status)
  404. {
  405. struct controller *ctrl = slot->ctrl;
  406. u16 slot_status;
  407. int retval = 0;
  408. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  409. if (retval) {
  410. err("%s: Cannot read SLOTSTATUS register\n", __func__);
  411. return retval;
  412. }
  413. *status = (((slot_status & MRL_STATE) >> 5) == 0) ? 0 : 1;
  414. return 0;
  415. }
  416. static int hpc_get_adapter_status(struct slot *slot, u8 *status)
  417. {
  418. struct controller *ctrl = slot->ctrl;
  419. u16 slot_status;
  420. u8 card_state;
  421. int retval = 0;
  422. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  423. if (retval) {
  424. err("%s: Cannot read SLOTSTATUS register\n", __func__);
  425. return retval;
  426. }
  427. card_state = (u8)((slot_status & PRSN_STATE) >> 6);
  428. *status = (card_state == 1) ? 1 : 0;
  429. return 0;
  430. }
  431. static int hpc_query_power_fault(struct slot *slot)
  432. {
  433. struct controller *ctrl = slot->ctrl;
  434. u16 slot_status;
  435. u8 pwr_fault;
  436. int retval = 0;
  437. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  438. if (retval) {
  439. err("%s: Cannot check for power fault\n", __func__);
  440. return retval;
  441. }
  442. pwr_fault = (u8)((slot_status & PWR_FAULT_DETECTED) >> 1);
  443. return pwr_fault;
  444. }
  445. static int hpc_get_emi_status(struct slot *slot, u8 *status)
  446. {
  447. struct controller *ctrl = slot->ctrl;
  448. u16 slot_status;
  449. int retval = 0;
  450. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  451. if (retval) {
  452. err("%s : Cannot check EMI status\n", __func__);
  453. return retval;
  454. }
  455. *status = (slot_status & EMI_STATE) >> EMI_STATUS_BIT;
  456. return retval;
  457. }
  458. static int hpc_toggle_emi(struct slot *slot)
  459. {
  460. u16 slot_cmd;
  461. u16 cmd_mask;
  462. int rc;
  463. slot_cmd = EMI_CTRL;
  464. cmd_mask = EMI_CTRL;
  465. rc = pcie_write_cmd(slot->ctrl, slot_cmd, cmd_mask);
  466. slot->last_emi_toggle = get_seconds();
  467. return rc;
  468. }
  469. static int hpc_set_attention_status(struct slot *slot, u8 value)
  470. {
  471. struct controller *ctrl = slot->ctrl;
  472. u16 slot_cmd;
  473. u16 cmd_mask;
  474. int rc;
  475. cmd_mask = ATTN_LED_CTRL;
  476. switch (value) {
  477. case 0 : /* turn off */
  478. slot_cmd = 0x00C0;
  479. break;
  480. case 1: /* turn on */
  481. slot_cmd = 0x0040;
  482. break;
  483. case 2: /* turn blink */
  484. slot_cmd = 0x0080;
  485. break;
  486. default:
  487. return -1;
  488. }
  489. rc = pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  490. dbg("%s: SLOTCTRL %x write cmd %x\n",
  491. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  492. return rc;
  493. }
  494. static void hpc_set_green_led_on(struct slot *slot)
  495. {
  496. struct controller *ctrl = slot->ctrl;
  497. u16 slot_cmd;
  498. u16 cmd_mask;
  499. slot_cmd = 0x0100;
  500. cmd_mask = PWR_LED_CTRL;
  501. pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  502. dbg("%s: SLOTCTRL %x write cmd %x\n",
  503. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  504. }
  505. static void hpc_set_green_led_off(struct slot *slot)
  506. {
  507. struct controller *ctrl = slot->ctrl;
  508. u16 slot_cmd;
  509. u16 cmd_mask;
  510. slot_cmd = 0x0300;
  511. cmd_mask = PWR_LED_CTRL;
  512. pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  513. dbg("%s: SLOTCTRL %x write cmd %x\n",
  514. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  515. }
  516. static void hpc_set_green_led_blink(struct slot *slot)
  517. {
  518. struct controller *ctrl = slot->ctrl;
  519. u16 slot_cmd;
  520. u16 cmd_mask;
  521. slot_cmd = 0x0200;
  522. cmd_mask = PWR_LED_CTRL;
  523. pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  524. dbg("%s: SLOTCTRL %x write cmd %x\n",
  525. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  526. }
  527. static int hpc_power_on_slot(struct slot * slot)
  528. {
  529. struct controller *ctrl = slot->ctrl;
  530. u16 slot_cmd;
  531. u16 cmd_mask;
  532. u16 slot_status;
  533. int retval = 0;
  534. dbg("%s: slot->hp_slot %x\n", __func__, slot->hp_slot);
  535. /* Clear sticky power-fault bit from previous power failures */
  536. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  537. if (retval) {
  538. err("%s: Cannot read SLOTSTATUS register\n", __func__);
  539. return retval;
  540. }
  541. slot_status &= PWR_FAULT_DETECTED;
  542. if (slot_status) {
  543. retval = pciehp_writew(ctrl, SLOTSTATUS, slot_status);
  544. if (retval) {
  545. err("%s: Cannot write to SLOTSTATUS register\n",
  546. __func__);
  547. return retval;
  548. }
  549. }
  550. slot_cmd = POWER_ON;
  551. cmd_mask = PWR_CTRL;
  552. /* Enable detection that we turned off at slot power-off time */
  553. if (!pciehp_poll_mode) {
  554. slot_cmd |= (PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE |
  555. PRSN_DETECT_ENABLE);
  556. cmd_mask |= (PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE |
  557. PRSN_DETECT_ENABLE);
  558. }
  559. retval = pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  560. if (retval) {
  561. err("%s: Write %x command failed!\n", __func__, slot_cmd);
  562. return -1;
  563. }
  564. dbg("%s: SLOTCTRL %x write cmd %x\n",
  565. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  566. return retval;
  567. }
  568. static inline int pcie_mask_bad_dllp(struct controller *ctrl)
  569. {
  570. struct pci_dev *dev = ctrl->pci_dev;
  571. int pos;
  572. u32 reg;
  573. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
  574. if (!pos)
  575. return 0;
  576. pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, &reg);
  577. if (reg & PCI_ERR_COR_BAD_DLLP)
  578. return 0;
  579. reg |= PCI_ERR_COR_BAD_DLLP;
  580. pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, reg);
  581. return 1;
  582. }
  583. static inline void pcie_unmask_bad_dllp(struct controller *ctrl)
  584. {
  585. struct pci_dev *dev = ctrl->pci_dev;
  586. u32 reg;
  587. int pos;
  588. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
  589. if (!pos)
  590. return;
  591. pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, &reg);
  592. if (!(reg & PCI_ERR_COR_BAD_DLLP))
  593. return;
  594. reg &= ~PCI_ERR_COR_BAD_DLLP;
  595. pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, reg);
  596. }
  597. static int hpc_power_off_slot(struct slot * slot)
  598. {
  599. struct controller *ctrl = slot->ctrl;
  600. u16 slot_cmd;
  601. u16 cmd_mask;
  602. int retval = 0;
  603. int changed;
  604. dbg("%s: slot->hp_slot %x\n", __func__, slot->hp_slot);
  605. /*
  606. * Set Bad DLLP Mask bit in Correctable Error Mask
  607. * Register. This is the workaround against Bad DLLP error
  608. * that sometimes happens during turning power off the slot
  609. * which conforms to PCI Express 1.0a spec.
  610. */
  611. changed = pcie_mask_bad_dllp(ctrl);
  612. slot_cmd = POWER_OFF;
  613. cmd_mask = PWR_CTRL;
  614. /*
  615. * If we get MRL or presence detect interrupts now, the isr
  616. * will notice the sticky power-fault bit too and issue power
  617. * indicator change commands. This will lead to an endless loop
  618. * of command completions, since the power-fault bit remains on
  619. * till the slot is powered on again.
  620. */
  621. if (!pciehp_poll_mode) {
  622. slot_cmd &= ~(PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE |
  623. PRSN_DETECT_ENABLE);
  624. cmd_mask |= (PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE |
  625. PRSN_DETECT_ENABLE);
  626. }
  627. retval = pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  628. if (retval) {
  629. err("%s: Write command failed!\n", __func__);
  630. retval = -1;
  631. goto out;
  632. }
  633. dbg("%s: SLOTCTRL %x write cmd %x\n",
  634. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  635. out:
  636. if (changed)
  637. pcie_unmask_bad_dllp(ctrl);
  638. return retval;
  639. }
  640. static irqreturn_t pcie_isr(int irq, void *dev_id)
  641. {
  642. struct controller *ctrl = (struct controller *)dev_id;
  643. u16 detected, intr_loc;
  644. struct slot *p_slot;
  645. /*
  646. * In order to guarantee that all interrupt events are
  647. * serviced, we need to re-inspect Slot Status register after
  648. * clearing what is presumed to be the last pending interrupt.
  649. */
  650. intr_loc = 0;
  651. do {
  652. if (pciehp_readw(ctrl, SLOTSTATUS, &detected)) {
  653. err("%s: Cannot read SLOTSTATUS\n", __func__);
  654. return IRQ_NONE;
  655. }
  656. detected &= (ATTN_BUTTN_PRESSED | PWR_FAULT_DETECTED |
  657. MRL_SENS_CHANGED | PRSN_DETECT_CHANGED |
  658. CMD_COMPLETED);
  659. intr_loc |= detected;
  660. if (!intr_loc)
  661. return IRQ_NONE;
  662. if (detected && pciehp_writew(ctrl, SLOTSTATUS, detected)) {
  663. err("%s: Cannot write to SLOTSTATUS\n", __func__);
  664. return IRQ_NONE;
  665. }
  666. } while (detected);
  667. dbg("%s: intr_loc %x\n", __FUNCTION__, intr_loc);
  668. /* Check Command Complete Interrupt Pending */
  669. if (intr_loc & CMD_COMPLETED) {
  670. ctrl->cmd_busy = 0;
  671. smp_mb();
  672. wake_up(&ctrl->queue);
  673. }
  674. if (!(intr_loc & ~CMD_COMPLETED))
  675. return IRQ_HANDLED;
  676. p_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset);
  677. /* Check MRL Sensor Changed */
  678. if (intr_loc & MRL_SENS_CHANGED)
  679. pciehp_handle_switch_change(p_slot);
  680. /* Check Attention Button Pressed */
  681. if (intr_loc & ATTN_BUTTN_PRESSED)
  682. pciehp_handle_attention_button(p_slot);
  683. /* Check Presence Detect Changed */
  684. if (intr_loc & PRSN_DETECT_CHANGED)
  685. pciehp_handle_presence_change(p_slot);
  686. /* Check Power Fault Detected */
  687. if (intr_loc & PWR_FAULT_DETECTED)
  688. pciehp_handle_power_fault(p_slot);
  689. return IRQ_HANDLED;
  690. }
  691. static int hpc_get_max_lnk_speed(struct slot *slot, enum pci_bus_speed *value)
  692. {
  693. struct controller *ctrl = slot->ctrl;
  694. enum pcie_link_speed lnk_speed;
  695. u32 lnk_cap;
  696. int retval = 0;
  697. retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap);
  698. if (retval) {
  699. err("%s: Cannot read LNKCAP register\n", __func__);
  700. return retval;
  701. }
  702. switch (lnk_cap & 0x000F) {
  703. case 1:
  704. lnk_speed = PCIE_2PT5GB;
  705. break;
  706. default:
  707. lnk_speed = PCIE_LNK_SPEED_UNKNOWN;
  708. break;
  709. }
  710. *value = lnk_speed;
  711. dbg("Max link speed = %d\n", lnk_speed);
  712. return retval;
  713. }
  714. static int hpc_get_max_lnk_width(struct slot *slot,
  715. enum pcie_link_width *value)
  716. {
  717. struct controller *ctrl = slot->ctrl;
  718. enum pcie_link_width lnk_wdth;
  719. u32 lnk_cap;
  720. int retval = 0;
  721. retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap);
  722. if (retval) {
  723. err("%s: Cannot read LNKCAP register\n", __func__);
  724. return retval;
  725. }
  726. switch ((lnk_cap & 0x03F0) >> 4){
  727. case 0:
  728. lnk_wdth = PCIE_LNK_WIDTH_RESRV;
  729. break;
  730. case 1:
  731. lnk_wdth = PCIE_LNK_X1;
  732. break;
  733. case 2:
  734. lnk_wdth = PCIE_LNK_X2;
  735. break;
  736. case 4:
  737. lnk_wdth = PCIE_LNK_X4;
  738. break;
  739. case 8:
  740. lnk_wdth = PCIE_LNK_X8;
  741. break;
  742. case 12:
  743. lnk_wdth = PCIE_LNK_X12;
  744. break;
  745. case 16:
  746. lnk_wdth = PCIE_LNK_X16;
  747. break;
  748. case 32:
  749. lnk_wdth = PCIE_LNK_X32;
  750. break;
  751. default:
  752. lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
  753. break;
  754. }
  755. *value = lnk_wdth;
  756. dbg("Max link width = %d\n", lnk_wdth);
  757. return retval;
  758. }
  759. static int hpc_get_cur_lnk_speed(struct slot *slot, enum pci_bus_speed *value)
  760. {
  761. struct controller *ctrl = slot->ctrl;
  762. enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN;
  763. int retval = 0;
  764. u16 lnk_status;
  765. retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
  766. if (retval) {
  767. err("%s: Cannot read LNKSTATUS register\n", __func__);
  768. return retval;
  769. }
  770. switch (lnk_status & 0x0F) {
  771. case 1:
  772. lnk_speed = PCIE_2PT5GB;
  773. break;
  774. default:
  775. lnk_speed = PCIE_LNK_SPEED_UNKNOWN;
  776. break;
  777. }
  778. *value = lnk_speed;
  779. dbg("Current link speed = %d\n", lnk_speed);
  780. return retval;
  781. }
  782. static int hpc_get_cur_lnk_width(struct slot *slot,
  783. enum pcie_link_width *value)
  784. {
  785. struct controller *ctrl = slot->ctrl;
  786. enum pcie_link_width lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
  787. int retval = 0;
  788. u16 lnk_status;
  789. retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
  790. if (retval) {
  791. err("%s: Cannot read LNKSTATUS register\n", __func__);
  792. return retval;
  793. }
  794. switch ((lnk_status & 0x03F0) >> 4){
  795. case 0:
  796. lnk_wdth = PCIE_LNK_WIDTH_RESRV;
  797. break;
  798. case 1:
  799. lnk_wdth = PCIE_LNK_X1;
  800. break;
  801. case 2:
  802. lnk_wdth = PCIE_LNK_X2;
  803. break;
  804. case 4:
  805. lnk_wdth = PCIE_LNK_X4;
  806. break;
  807. case 8:
  808. lnk_wdth = PCIE_LNK_X8;
  809. break;
  810. case 12:
  811. lnk_wdth = PCIE_LNK_X12;
  812. break;
  813. case 16:
  814. lnk_wdth = PCIE_LNK_X16;
  815. break;
  816. case 32:
  817. lnk_wdth = PCIE_LNK_X32;
  818. break;
  819. default:
  820. lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
  821. break;
  822. }
  823. *value = lnk_wdth;
  824. dbg("Current link width = %d\n", lnk_wdth);
  825. return retval;
  826. }
  827. static void pcie_release_ctrl(struct controller *ctrl);
  828. static struct hpc_ops pciehp_hpc_ops = {
  829. .power_on_slot = hpc_power_on_slot,
  830. .power_off_slot = hpc_power_off_slot,
  831. .set_attention_status = hpc_set_attention_status,
  832. .get_power_status = hpc_get_power_status,
  833. .get_attention_status = hpc_get_attention_status,
  834. .get_latch_status = hpc_get_latch_status,
  835. .get_adapter_status = hpc_get_adapter_status,
  836. .get_emi_status = hpc_get_emi_status,
  837. .toggle_emi = hpc_toggle_emi,
  838. .get_max_bus_speed = hpc_get_max_lnk_speed,
  839. .get_cur_bus_speed = hpc_get_cur_lnk_speed,
  840. .get_max_lnk_width = hpc_get_max_lnk_width,
  841. .get_cur_lnk_width = hpc_get_cur_lnk_width,
  842. .query_power_fault = hpc_query_power_fault,
  843. .green_led_on = hpc_set_green_led_on,
  844. .green_led_off = hpc_set_green_led_off,
  845. .green_led_blink = hpc_set_green_led_blink,
  846. .release_ctlr = pcie_release_ctrl,
  847. .check_lnk_status = hpc_check_lnk_status,
  848. };
  849. int pcie_enable_notification(struct controller *ctrl)
  850. {
  851. u16 cmd, mask;
  852. cmd = PRSN_DETECT_ENABLE;
  853. if (ATTN_BUTTN(ctrl))
  854. cmd |= ATTN_BUTTN_ENABLE;
  855. if (POWER_CTRL(ctrl))
  856. cmd |= PWR_FAULT_DETECT_ENABLE;
  857. if (MRL_SENS(ctrl))
  858. cmd |= MRL_DETECT_ENABLE;
  859. if (!pciehp_poll_mode)
  860. cmd |= HP_INTR_ENABLE;
  861. mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE |
  862. PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE | HP_INTR_ENABLE;
  863. if (pcie_write_cmd(ctrl, cmd, mask)) {
  864. err("%s: Cannot enable software notification\n", __func__);
  865. return -1;
  866. }
  867. return 0;
  868. }
  869. static void pcie_disable_notification(struct controller *ctrl)
  870. {
  871. u16 mask;
  872. mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | MRL_DETECT_ENABLE |
  873. PWR_FAULT_DETECT_ENABLE | HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE;
  874. if (pcie_write_cmd(ctrl, 0, mask))
  875. warn("%s: Cannot disable software notification\n", __func__);
  876. }
  877. static int pcie_init_notification(struct controller *ctrl)
  878. {
  879. if (pciehp_request_irq(ctrl))
  880. return -1;
  881. if (pcie_enable_notification(ctrl)) {
  882. pciehp_free_irq(ctrl);
  883. return -1;
  884. }
  885. return 0;
  886. }
  887. static void pcie_shutdown_notification(struct controller *ctrl)
  888. {
  889. pcie_disable_notification(ctrl);
  890. pciehp_free_irq(ctrl);
  891. }
  892. static void make_slot_name(struct slot *slot)
  893. {
  894. if (pciehp_slot_with_bus)
  895. snprintf(slot->name, SLOT_NAME_SIZE, "%04d_%04d",
  896. slot->bus, slot->number);
  897. else
  898. snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number);
  899. }
  900. static int pcie_init_slot(struct controller *ctrl)
  901. {
  902. struct slot *slot;
  903. slot = kzalloc(sizeof(*slot), GFP_KERNEL);
  904. if (!slot)
  905. return -ENOMEM;
  906. slot->hp_slot = 0;
  907. slot->ctrl = ctrl;
  908. slot->bus = ctrl->pci_dev->subordinate->number;
  909. slot->device = ctrl->slot_device_offset + slot->hp_slot;
  910. slot->hpc_ops = ctrl->hpc_ops;
  911. slot->number = ctrl->first_slot;
  912. make_slot_name(slot);
  913. mutex_init(&slot->lock);
  914. INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work);
  915. list_add(&slot->slot_list, &ctrl->slot_list);
  916. return 0;
  917. }
  918. static void pcie_cleanup_slot(struct controller *ctrl)
  919. {
  920. struct slot *slot;
  921. slot = list_first_entry(&ctrl->slot_list, struct slot, slot_list);
  922. list_del(&slot->slot_list);
  923. cancel_delayed_work(&slot->work);
  924. flush_scheduled_work();
  925. flush_workqueue(pciehp_wq);
  926. kfree(slot);
  927. }
  928. static inline void dbg_ctrl(struct controller *ctrl)
  929. {
  930. int i;
  931. u16 reg16;
  932. struct pci_dev *pdev = ctrl->pci_dev;
  933. if (!pciehp_debug)
  934. return;
  935. dbg("Hotplug Controller:\n");
  936. dbg(" Seg/Bus/Dev/Func/IRQ : %s IRQ %d\n", pci_name(pdev), pdev->irq);
  937. dbg(" Vendor ID : 0x%04x\n", pdev->vendor);
  938. dbg(" Device ID : 0x%04x\n", pdev->device);
  939. dbg(" Subsystem ID : 0x%04x\n", pdev->subsystem_device);
  940. dbg(" Subsystem Vendor ID : 0x%04x\n", pdev->subsystem_vendor);
  941. dbg(" PCIe Cap offset : 0x%02x\n", ctrl->cap_base);
  942. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  943. if (!pci_resource_len(pdev, i))
  944. continue;
  945. dbg(" PCI resource [%d] : 0x%llx@0x%llx\n", i,
  946. (unsigned long long)pci_resource_len(pdev, i),
  947. (unsigned long long)pci_resource_start(pdev, i));
  948. }
  949. dbg("Slot Capabilities : 0x%08x\n", ctrl->slot_cap);
  950. dbg(" Physical Slot Number : %d\n", ctrl->first_slot);
  951. dbg(" Attention Button : %3s\n", ATTN_BUTTN(ctrl) ? "yes" : "no");
  952. dbg(" Power Controller : %3s\n", POWER_CTRL(ctrl) ? "yes" : "no");
  953. dbg(" MRL Sensor : %3s\n", MRL_SENS(ctrl) ? "yes" : "no");
  954. dbg(" Attention Indicator : %3s\n", ATTN_LED(ctrl) ? "yes" : "no");
  955. dbg(" Power Indicator : %3s\n", PWR_LED(ctrl) ? "yes" : "no");
  956. dbg(" Hot-Plug Surprise : %3s\n", HP_SUPR_RM(ctrl) ? "yes" : "no");
  957. dbg(" EMI Present : %3s\n", EMI(ctrl) ? "yes" : "no");
  958. dbg(" Comamnd Completed : %3s\n", NO_CMD_CMPL(ctrl)? "no" : "yes");
  959. pciehp_readw(ctrl, SLOTSTATUS, &reg16);
  960. dbg("Slot Status : 0x%04x\n", reg16);
  961. pciehp_readw(ctrl, SLOTCTRL, &reg16);
  962. dbg("Slot Control : 0x%04x\n", reg16);
  963. }
  964. struct controller *pcie_init(struct pcie_device *dev)
  965. {
  966. struct controller *ctrl;
  967. u32 slot_cap;
  968. struct pci_dev *pdev = dev->port;
  969. ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
  970. if (!ctrl) {
  971. err("%s : out of memory\n", __func__);
  972. goto abort;
  973. }
  974. INIT_LIST_HEAD(&ctrl->slot_list);
  975. ctrl->pci_dev = pdev;
  976. ctrl->cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP);
  977. if (!ctrl->cap_base) {
  978. err("%s: Cannot find PCI Express capability\n", __func__);
  979. goto abort;
  980. }
  981. if (pciehp_readl(ctrl, SLOTCAP, &slot_cap)) {
  982. err("%s: Cannot read SLOTCAP register\n", __func__);
  983. goto abort;
  984. }
  985. ctrl->slot_cap = slot_cap;
  986. ctrl->first_slot = slot_cap >> 19;
  987. ctrl->slot_device_offset = 0;
  988. ctrl->num_slots = 1;
  989. ctrl->hpc_ops = &pciehp_hpc_ops;
  990. mutex_init(&ctrl->crit_sect);
  991. mutex_init(&ctrl->ctrl_lock);
  992. init_waitqueue_head(&ctrl->queue);
  993. dbg_ctrl(ctrl);
  994. /*
  995. * Controller doesn't notify of command completion if the "No
  996. * Command Completed Support" bit is set in Slot Capability
  997. * register or the controller supports none of power
  998. * controller, attention led, power led and EMI.
  999. */
  1000. if (NO_CMD_CMPL(ctrl) ||
  1001. !(POWER_CTRL(ctrl) | ATTN_LED(ctrl) | PWR_LED(ctrl) | EMI(ctrl)))
  1002. ctrl->no_cmd_complete = 1;
  1003. /* Clear all remaining event bits in Slot Status register */
  1004. if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f))
  1005. goto abort_ctrl;
  1006. /* Disable sotfware notification */
  1007. pcie_disable_notification(ctrl);
  1008. /*
  1009. * If this is the first controller to be initialized,
  1010. * initialize the pciehp work queue
  1011. */
  1012. if (atomic_add_return(1, &pciehp_num_controllers) == 1) {
  1013. pciehp_wq = create_singlethread_workqueue("pciehpd");
  1014. if (!pciehp_wq)
  1015. goto abort_ctrl;
  1016. }
  1017. info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n",
  1018. pdev->vendor, pdev->device,
  1019. pdev->subsystem_vendor, pdev->subsystem_device);
  1020. if (pcie_init_slot(ctrl))
  1021. goto abort_ctrl;
  1022. if (pcie_init_notification(ctrl))
  1023. goto abort_slot;
  1024. return ctrl;
  1025. abort_slot:
  1026. pcie_cleanup_slot(ctrl);
  1027. abort_ctrl:
  1028. kfree(ctrl);
  1029. abort:
  1030. return NULL;
  1031. }
  1032. void pcie_release_ctrl(struct controller *ctrl)
  1033. {
  1034. pcie_shutdown_notification(ctrl);
  1035. pcie_cleanup_slot(ctrl);
  1036. /*
  1037. * If this is the last controller to be released, destroy the
  1038. * pciehp work queue
  1039. */
  1040. if (atomic_dec_and_test(&pciehp_num_controllers))
  1041. destroy_workqueue(pciehp_wq);
  1042. kfree(ctrl);
  1043. }