pciehp_hpc.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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 inline int pcie_wait_cmd(struct controller *ctrl)
  218. {
  219. int retval = 0;
  220. unsigned int msecs = pciehp_poll_mode ? 2500 : 1000;
  221. unsigned long timeout = msecs_to_jiffies(msecs);
  222. int rc;
  223. rc = wait_event_interruptible_timeout(ctrl->queue,
  224. !ctrl->cmd_busy, timeout);
  225. if (!rc)
  226. dbg("Command not completed in 1000 msec\n");
  227. else if (rc < 0) {
  228. retval = -EINTR;
  229. info("Command was interrupted by a signal\n");
  230. }
  231. return retval;
  232. }
  233. /**
  234. * pcie_write_cmd - Issue controller command
  235. * @ctrl: controller to which the command is issued
  236. * @cmd: command value written to slot control register
  237. * @mask: bitmask of slot control register to be modified
  238. */
  239. static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask)
  240. {
  241. int retval = 0;
  242. u16 slot_status;
  243. u16 slot_ctrl;
  244. mutex_lock(&ctrl->ctrl_lock);
  245. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  246. if (retval) {
  247. err("%s: Cannot read SLOTSTATUS register\n", __func__);
  248. goto out;
  249. }
  250. if (slot_status & CMD_COMPLETED) {
  251. if (!ctrl->no_cmd_complete) {
  252. /*
  253. * After 1 sec and CMD_COMPLETED still not set, just
  254. * proceed forward to issue the next command according
  255. * to spec. Just print out the error message.
  256. */
  257. dbg("%s: CMD_COMPLETED not clear after 1 sec.\n",
  258. __func__);
  259. } else if (!NO_CMD_CMPL(ctrl)) {
  260. /*
  261. * This controller semms to notify of command completed
  262. * event even though it supports none of power
  263. * controller, attention led, power led and EMI.
  264. */
  265. dbg("%s: Unexpected CMD_COMPLETED. Need to wait for "
  266. "command completed event.\n", __func__);
  267. ctrl->no_cmd_complete = 0;
  268. } else {
  269. dbg("%s: Unexpected CMD_COMPLETED. Maybe the "
  270. "controller is broken.\n", __func__);
  271. }
  272. }
  273. retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
  274. if (retval) {
  275. err("%s: Cannot read SLOTCTRL register\n", __func__);
  276. goto out;
  277. }
  278. slot_ctrl &= ~mask;
  279. slot_ctrl |= (cmd & mask);
  280. /* Don't enable command completed if caller is changing it. */
  281. if (!(mask & CMD_CMPL_INTR_ENABLE))
  282. slot_ctrl |= CMD_CMPL_INTR_ENABLE;
  283. ctrl->cmd_busy = 1;
  284. smp_mb();
  285. retval = pciehp_writew(ctrl, SLOTCTRL, slot_ctrl);
  286. if (retval)
  287. err("%s: Cannot write to SLOTCTRL register\n", __func__);
  288. /*
  289. * Wait for command completion.
  290. */
  291. if (!retval && !ctrl->no_cmd_complete)
  292. retval = pcie_wait_cmd(ctrl);
  293. out:
  294. mutex_unlock(&ctrl->ctrl_lock);
  295. return retval;
  296. }
  297. static int hpc_check_lnk_status(struct controller *ctrl)
  298. {
  299. u16 lnk_status;
  300. int retval = 0;
  301. retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
  302. if (retval) {
  303. err("%s: Cannot read LNKSTATUS register\n", __func__);
  304. return retval;
  305. }
  306. dbg("%s: lnk_status = %x\n", __func__, lnk_status);
  307. if ( (lnk_status & LNK_TRN) || (lnk_status & LNK_TRN_ERR) ||
  308. !(lnk_status & NEG_LINK_WD)) {
  309. err("%s : Link Training Error occurs \n", __func__);
  310. retval = -1;
  311. return retval;
  312. }
  313. return retval;
  314. }
  315. static int hpc_get_attention_status(struct slot *slot, u8 *status)
  316. {
  317. struct controller *ctrl = slot->ctrl;
  318. u16 slot_ctrl;
  319. u8 atten_led_state;
  320. int retval = 0;
  321. retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
  322. if (retval) {
  323. err("%s: Cannot read SLOTCTRL register\n", __func__);
  324. return retval;
  325. }
  326. dbg("%s: SLOTCTRL %x, value read %x\n",
  327. __func__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
  328. atten_led_state = (slot_ctrl & ATTN_LED_CTRL) >> 6;
  329. switch (atten_led_state) {
  330. case 0:
  331. *status = 0xFF; /* Reserved */
  332. break;
  333. case 1:
  334. *status = 1; /* On */
  335. break;
  336. case 2:
  337. *status = 2; /* Blink */
  338. break;
  339. case 3:
  340. *status = 0; /* Off */
  341. break;
  342. default:
  343. *status = 0xFF;
  344. break;
  345. }
  346. return 0;
  347. }
  348. static int hpc_get_power_status(struct slot *slot, u8 *status)
  349. {
  350. struct controller *ctrl = slot->ctrl;
  351. u16 slot_ctrl;
  352. u8 pwr_state;
  353. int retval = 0;
  354. retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl);
  355. if (retval) {
  356. err("%s: Cannot read SLOTCTRL register\n", __func__);
  357. return retval;
  358. }
  359. dbg("%s: SLOTCTRL %x value read %x\n",
  360. __func__, ctrl->cap_base + SLOTCTRL, slot_ctrl);
  361. pwr_state = (slot_ctrl & PWR_CTRL) >> 10;
  362. switch (pwr_state) {
  363. case 0:
  364. *status = 1;
  365. break;
  366. case 1:
  367. *status = 0;
  368. break;
  369. default:
  370. *status = 0xFF;
  371. break;
  372. }
  373. return retval;
  374. }
  375. static int hpc_get_latch_status(struct slot *slot, u8 *status)
  376. {
  377. struct controller *ctrl = slot->ctrl;
  378. u16 slot_status;
  379. int retval = 0;
  380. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  381. if (retval) {
  382. err("%s: Cannot read SLOTSTATUS register\n", __func__);
  383. return retval;
  384. }
  385. *status = (((slot_status & MRL_STATE) >> 5) == 0) ? 0 : 1;
  386. return 0;
  387. }
  388. static int hpc_get_adapter_status(struct slot *slot, u8 *status)
  389. {
  390. struct controller *ctrl = slot->ctrl;
  391. u16 slot_status;
  392. u8 card_state;
  393. int retval = 0;
  394. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  395. if (retval) {
  396. err("%s: Cannot read SLOTSTATUS register\n", __func__);
  397. return retval;
  398. }
  399. card_state = (u8)((slot_status & PRSN_STATE) >> 6);
  400. *status = (card_state == 1) ? 1 : 0;
  401. return 0;
  402. }
  403. static int hpc_query_power_fault(struct slot *slot)
  404. {
  405. struct controller *ctrl = slot->ctrl;
  406. u16 slot_status;
  407. u8 pwr_fault;
  408. int retval = 0;
  409. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  410. if (retval) {
  411. err("%s: Cannot check for power fault\n", __func__);
  412. return retval;
  413. }
  414. pwr_fault = (u8)((slot_status & PWR_FAULT_DETECTED) >> 1);
  415. return pwr_fault;
  416. }
  417. static int hpc_get_emi_status(struct slot *slot, u8 *status)
  418. {
  419. struct controller *ctrl = slot->ctrl;
  420. u16 slot_status;
  421. int retval = 0;
  422. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  423. if (retval) {
  424. err("%s : Cannot check EMI status\n", __func__);
  425. return retval;
  426. }
  427. *status = (slot_status & EMI_STATE) >> EMI_STATUS_BIT;
  428. return retval;
  429. }
  430. static int hpc_toggle_emi(struct slot *slot)
  431. {
  432. u16 slot_cmd;
  433. u16 cmd_mask;
  434. int rc;
  435. slot_cmd = EMI_CTRL;
  436. cmd_mask = EMI_CTRL;
  437. rc = pcie_write_cmd(slot->ctrl, slot_cmd, cmd_mask);
  438. slot->last_emi_toggle = get_seconds();
  439. return rc;
  440. }
  441. static int hpc_set_attention_status(struct slot *slot, u8 value)
  442. {
  443. struct controller *ctrl = slot->ctrl;
  444. u16 slot_cmd;
  445. u16 cmd_mask;
  446. int rc;
  447. cmd_mask = ATTN_LED_CTRL;
  448. switch (value) {
  449. case 0 : /* turn off */
  450. slot_cmd = 0x00C0;
  451. break;
  452. case 1: /* turn on */
  453. slot_cmd = 0x0040;
  454. break;
  455. case 2: /* turn blink */
  456. slot_cmd = 0x0080;
  457. break;
  458. default:
  459. return -1;
  460. }
  461. rc = pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  462. dbg("%s: SLOTCTRL %x write cmd %x\n",
  463. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  464. return rc;
  465. }
  466. static void hpc_set_green_led_on(struct slot *slot)
  467. {
  468. struct controller *ctrl = slot->ctrl;
  469. u16 slot_cmd;
  470. u16 cmd_mask;
  471. slot_cmd = 0x0100;
  472. cmd_mask = PWR_LED_CTRL;
  473. pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  474. dbg("%s: SLOTCTRL %x write cmd %x\n",
  475. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  476. }
  477. static void hpc_set_green_led_off(struct slot *slot)
  478. {
  479. struct controller *ctrl = slot->ctrl;
  480. u16 slot_cmd;
  481. u16 cmd_mask;
  482. slot_cmd = 0x0300;
  483. cmd_mask = PWR_LED_CTRL;
  484. pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  485. dbg("%s: SLOTCTRL %x write cmd %x\n",
  486. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  487. }
  488. static void hpc_set_green_led_blink(struct slot *slot)
  489. {
  490. struct controller *ctrl = slot->ctrl;
  491. u16 slot_cmd;
  492. u16 cmd_mask;
  493. slot_cmd = 0x0200;
  494. cmd_mask = PWR_LED_CTRL;
  495. pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  496. dbg("%s: SLOTCTRL %x write cmd %x\n",
  497. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  498. }
  499. static void hpc_release_ctlr(struct controller *ctrl)
  500. {
  501. /* Mask Hot-plug Interrupt Enable */
  502. if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE))
  503. err("%s: Cannot mask hotplut interrupt enable\n", __func__);
  504. /* Free interrupt handler or interrupt polling timer */
  505. pciehp_free_irq(ctrl);
  506. /*
  507. * If this is the last controller to be released, destroy the
  508. * pciehp work queue
  509. */
  510. if (atomic_dec_and_test(&pciehp_num_controllers))
  511. destroy_workqueue(pciehp_wq);
  512. }
  513. static int hpc_power_on_slot(struct slot * slot)
  514. {
  515. struct controller *ctrl = slot->ctrl;
  516. u16 slot_cmd;
  517. u16 cmd_mask;
  518. u16 slot_status;
  519. int retval = 0;
  520. dbg("%s: slot->hp_slot %x\n", __func__, slot->hp_slot);
  521. /* Clear sticky power-fault bit from previous power failures */
  522. retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status);
  523. if (retval) {
  524. err("%s: Cannot read SLOTSTATUS register\n", __func__);
  525. return retval;
  526. }
  527. slot_status &= PWR_FAULT_DETECTED;
  528. if (slot_status) {
  529. retval = pciehp_writew(ctrl, SLOTSTATUS, slot_status);
  530. if (retval) {
  531. err("%s: Cannot write to SLOTSTATUS register\n",
  532. __func__);
  533. return retval;
  534. }
  535. }
  536. slot_cmd = POWER_ON;
  537. cmd_mask = PWR_CTRL;
  538. /* Enable detection that we turned off at slot power-off time */
  539. if (!pciehp_poll_mode) {
  540. slot_cmd |= (PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE |
  541. PRSN_DETECT_ENABLE);
  542. cmd_mask |= (PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE |
  543. PRSN_DETECT_ENABLE);
  544. }
  545. retval = pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  546. if (retval) {
  547. err("%s: Write %x command failed!\n", __func__, slot_cmd);
  548. return -1;
  549. }
  550. dbg("%s: SLOTCTRL %x write cmd %x\n",
  551. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  552. return retval;
  553. }
  554. static inline int pcie_mask_bad_dllp(struct controller *ctrl)
  555. {
  556. struct pci_dev *dev = ctrl->pci_dev;
  557. int pos;
  558. u32 reg;
  559. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
  560. if (!pos)
  561. return 0;
  562. pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, &reg);
  563. if (reg & PCI_ERR_COR_BAD_DLLP)
  564. return 0;
  565. reg |= PCI_ERR_COR_BAD_DLLP;
  566. pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, reg);
  567. return 1;
  568. }
  569. static inline void pcie_unmask_bad_dllp(struct controller *ctrl)
  570. {
  571. struct pci_dev *dev = ctrl->pci_dev;
  572. u32 reg;
  573. int pos;
  574. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
  575. if (!pos)
  576. return;
  577. pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, &reg);
  578. if (!(reg & PCI_ERR_COR_BAD_DLLP))
  579. return;
  580. reg &= ~PCI_ERR_COR_BAD_DLLP;
  581. pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, reg);
  582. }
  583. static int hpc_power_off_slot(struct slot * slot)
  584. {
  585. struct controller *ctrl = slot->ctrl;
  586. u16 slot_cmd;
  587. u16 cmd_mask;
  588. int retval = 0;
  589. int changed;
  590. dbg("%s: slot->hp_slot %x\n", __func__, slot->hp_slot);
  591. /*
  592. * Set Bad DLLP Mask bit in Correctable Error Mask
  593. * Register. This is the workaround against Bad DLLP error
  594. * that sometimes happens during turning power off the slot
  595. * which conforms to PCI Express 1.0a spec.
  596. */
  597. changed = pcie_mask_bad_dllp(ctrl);
  598. slot_cmd = POWER_OFF;
  599. cmd_mask = PWR_CTRL;
  600. /*
  601. * If we get MRL or presence detect interrupts now, the isr
  602. * will notice the sticky power-fault bit too and issue power
  603. * indicator change commands. This will lead to an endless loop
  604. * of command completions, since the power-fault bit remains on
  605. * till the slot is powered on again.
  606. */
  607. if (!pciehp_poll_mode) {
  608. slot_cmd &= ~(PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE |
  609. PRSN_DETECT_ENABLE);
  610. cmd_mask |= (PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE |
  611. PRSN_DETECT_ENABLE);
  612. }
  613. retval = pcie_write_cmd(ctrl, slot_cmd, cmd_mask);
  614. if (retval) {
  615. err("%s: Write command failed!\n", __func__);
  616. retval = -1;
  617. goto out;
  618. }
  619. dbg("%s: SLOTCTRL %x write cmd %x\n",
  620. __func__, ctrl->cap_base + SLOTCTRL, slot_cmd);
  621. /*
  622. * After turning power off, we must wait for at least 1 second
  623. * before taking any action that relies on power having been
  624. * removed from the slot/adapter.
  625. */
  626. msleep(1000);
  627. out:
  628. if (changed)
  629. pcie_unmask_bad_dllp(ctrl);
  630. return retval;
  631. }
  632. static irqreturn_t pcie_isr(int irq, void *dev_id)
  633. {
  634. struct controller *ctrl = (struct controller *)dev_id;
  635. u16 detected, intr_loc;
  636. struct slot *p_slot;
  637. /*
  638. * In order to guarantee that all interrupt events are
  639. * serviced, we need to re-inspect Slot Status register after
  640. * clearing what is presumed to be the last pending interrupt.
  641. */
  642. intr_loc = 0;
  643. do {
  644. if (pciehp_readw(ctrl, SLOTSTATUS, &detected)) {
  645. err("%s: Cannot read SLOTSTATUS\n", __func__);
  646. return IRQ_NONE;
  647. }
  648. detected &= (ATTN_BUTTN_PRESSED | PWR_FAULT_DETECTED |
  649. MRL_SENS_CHANGED | PRSN_DETECT_CHANGED |
  650. CMD_COMPLETED);
  651. intr_loc |= detected;
  652. if (!intr_loc)
  653. return IRQ_NONE;
  654. if (pciehp_writew(ctrl, SLOTSTATUS, detected)) {
  655. err("%s: Cannot write to SLOTSTATUS\n", __func__);
  656. return IRQ_NONE;
  657. }
  658. } while (detected);
  659. dbg("%s: intr_loc %x\n", __FUNCTION__, intr_loc);
  660. /* Check Command Complete Interrupt Pending */
  661. if (intr_loc & CMD_COMPLETED) {
  662. ctrl->cmd_busy = 0;
  663. smp_mb();
  664. wake_up_interruptible(&ctrl->queue);
  665. }
  666. if (!(intr_loc & ~CMD_COMPLETED))
  667. return IRQ_HANDLED;
  668. /*
  669. * Return without handling events if this handler routine is
  670. * called before controller initialization is done. This may
  671. * happen if hotplug event or another interrupt that shares
  672. * the IRQ with pciehp arrives before slot initialization is
  673. * done after interrupt handler is registered.
  674. *
  675. * FIXME - Need more structural fixes. We need to be ready to
  676. * handle the event before installing interrupt handler.
  677. */
  678. p_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset);
  679. if (!p_slot || !p_slot->hpc_ops)
  680. return IRQ_HANDLED;
  681. /* Check MRL Sensor Changed */
  682. if (intr_loc & MRL_SENS_CHANGED)
  683. pciehp_handle_switch_change(p_slot);
  684. /* Check Attention Button Pressed */
  685. if (intr_loc & ATTN_BUTTN_PRESSED)
  686. pciehp_handle_attention_button(p_slot);
  687. /* Check Presence Detect Changed */
  688. if (intr_loc & PRSN_DETECT_CHANGED)
  689. pciehp_handle_presence_change(p_slot);
  690. /* Check Power Fault Detected */
  691. if (intr_loc & PWR_FAULT_DETECTED)
  692. pciehp_handle_power_fault(p_slot);
  693. return IRQ_HANDLED;
  694. }
  695. static int hpc_get_max_lnk_speed(struct slot *slot, enum pci_bus_speed *value)
  696. {
  697. struct controller *ctrl = slot->ctrl;
  698. enum pcie_link_speed lnk_speed;
  699. u32 lnk_cap;
  700. int retval = 0;
  701. retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap);
  702. if (retval) {
  703. err("%s: Cannot read LNKCAP register\n", __func__);
  704. return retval;
  705. }
  706. switch (lnk_cap & 0x000F) {
  707. case 1:
  708. lnk_speed = PCIE_2PT5GB;
  709. break;
  710. default:
  711. lnk_speed = PCIE_LNK_SPEED_UNKNOWN;
  712. break;
  713. }
  714. *value = lnk_speed;
  715. dbg("Max link speed = %d\n", lnk_speed);
  716. return retval;
  717. }
  718. static int hpc_get_max_lnk_width(struct slot *slot,
  719. enum pcie_link_width *value)
  720. {
  721. struct controller *ctrl = slot->ctrl;
  722. enum pcie_link_width lnk_wdth;
  723. u32 lnk_cap;
  724. int retval = 0;
  725. retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap);
  726. if (retval) {
  727. err("%s: Cannot read LNKCAP register\n", __func__);
  728. return retval;
  729. }
  730. switch ((lnk_cap & 0x03F0) >> 4){
  731. case 0:
  732. lnk_wdth = PCIE_LNK_WIDTH_RESRV;
  733. break;
  734. case 1:
  735. lnk_wdth = PCIE_LNK_X1;
  736. break;
  737. case 2:
  738. lnk_wdth = PCIE_LNK_X2;
  739. break;
  740. case 4:
  741. lnk_wdth = PCIE_LNK_X4;
  742. break;
  743. case 8:
  744. lnk_wdth = PCIE_LNK_X8;
  745. break;
  746. case 12:
  747. lnk_wdth = PCIE_LNK_X12;
  748. break;
  749. case 16:
  750. lnk_wdth = PCIE_LNK_X16;
  751. break;
  752. case 32:
  753. lnk_wdth = PCIE_LNK_X32;
  754. break;
  755. default:
  756. lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
  757. break;
  758. }
  759. *value = lnk_wdth;
  760. dbg("Max link width = %d\n", lnk_wdth);
  761. return retval;
  762. }
  763. static int hpc_get_cur_lnk_speed(struct slot *slot, enum pci_bus_speed *value)
  764. {
  765. struct controller *ctrl = slot->ctrl;
  766. enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN;
  767. int retval = 0;
  768. u16 lnk_status;
  769. retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
  770. if (retval) {
  771. err("%s: Cannot read LNKSTATUS register\n", __func__);
  772. return retval;
  773. }
  774. switch (lnk_status & 0x0F) {
  775. case 1:
  776. lnk_speed = PCIE_2PT5GB;
  777. break;
  778. default:
  779. lnk_speed = PCIE_LNK_SPEED_UNKNOWN;
  780. break;
  781. }
  782. *value = lnk_speed;
  783. dbg("Current link speed = %d\n", lnk_speed);
  784. return retval;
  785. }
  786. static int hpc_get_cur_lnk_width(struct slot *slot,
  787. enum pcie_link_width *value)
  788. {
  789. struct controller *ctrl = slot->ctrl;
  790. enum pcie_link_width lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
  791. int retval = 0;
  792. u16 lnk_status;
  793. retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status);
  794. if (retval) {
  795. err("%s: Cannot read LNKSTATUS register\n", __func__);
  796. return retval;
  797. }
  798. switch ((lnk_status & 0x03F0) >> 4){
  799. case 0:
  800. lnk_wdth = PCIE_LNK_WIDTH_RESRV;
  801. break;
  802. case 1:
  803. lnk_wdth = PCIE_LNK_X1;
  804. break;
  805. case 2:
  806. lnk_wdth = PCIE_LNK_X2;
  807. break;
  808. case 4:
  809. lnk_wdth = PCIE_LNK_X4;
  810. break;
  811. case 8:
  812. lnk_wdth = PCIE_LNK_X8;
  813. break;
  814. case 12:
  815. lnk_wdth = PCIE_LNK_X12;
  816. break;
  817. case 16:
  818. lnk_wdth = PCIE_LNK_X16;
  819. break;
  820. case 32:
  821. lnk_wdth = PCIE_LNK_X32;
  822. break;
  823. default:
  824. lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN;
  825. break;
  826. }
  827. *value = lnk_wdth;
  828. dbg("Current link width = %d\n", lnk_wdth);
  829. return retval;
  830. }
  831. static struct hpc_ops pciehp_hpc_ops = {
  832. .power_on_slot = hpc_power_on_slot,
  833. .power_off_slot = hpc_power_off_slot,
  834. .set_attention_status = hpc_set_attention_status,
  835. .get_power_status = hpc_get_power_status,
  836. .get_attention_status = hpc_get_attention_status,
  837. .get_latch_status = hpc_get_latch_status,
  838. .get_adapter_status = hpc_get_adapter_status,
  839. .get_emi_status = hpc_get_emi_status,
  840. .toggle_emi = hpc_toggle_emi,
  841. .get_max_bus_speed = hpc_get_max_lnk_speed,
  842. .get_cur_bus_speed = hpc_get_cur_lnk_speed,
  843. .get_max_lnk_width = hpc_get_max_lnk_width,
  844. .get_cur_lnk_width = hpc_get_cur_lnk_width,
  845. .query_power_fault = hpc_query_power_fault,
  846. .green_led_on = hpc_set_green_led_on,
  847. .green_led_off = hpc_set_green_led_off,
  848. .green_led_blink = hpc_set_green_led_blink,
  849. .release_ctlr = hpc_release_ctlr,
  850. .check_lnk_status = hpc_check_lnk_status,
  851. };
  852. #ifdef CONFIG_ACPI
  853. static int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev)
  854. {
  855. acpi_status status;
  856. acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
  857. struct pci_dev *pdev = dev;
  858. struct pci_bus *parent;
  859. struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
  860. /*
  861. * Per PCI firmware specification, we should run the ACPI _OSC
  862. * method to get control of hotplug hardware before using it.
  863. * If an _OSC is missing, we look for an OSHP to do the same thing.
  864. * To handle different BIOS behavior, we look for _OSC and OSHP
  865. * within the scope of the hotplug controller and its parents, upto
  866. * the host bridge under which this controller exists.
  867. */
  868. while (!handle) {
  869. /*
  870. * This hotplug controller was not listed in the ACPI name
  871. * space at all. Try to get acpi handle of parent pci bus.
  872. */
  873. if (!pdev || !pdev->bus->parent)
  874. break;
  875. parent = pdev->bus->parent;
  876. dbg("Could not find %s in acpi namespace, trying parent\n",
  877. pci_name(pdev));
  878. if (!parent->self)
  879. /* Parent must be a host bridge */
  880. handle = acpi_get_pci_rootbridge_handle(
  881. pci_domain_nr(parent),
  882. parent->number);
  883. else
  884. handle = DEVICE_ACPI_HANDLE(
  885. &(parent->self->dev));
  886. pdev = parent->self;
  887. }
  888. while (handle) {
  889. acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
  890. dbg("Trying to get hotplug control for %s \n",
  891. (char *)string.pointer);
  892. status = pci_osc_control_set(handle,
  893. OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL |
  894. OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
  895. if (status == AE_NOT_FOUND)
  896. status = acpi_run_oshp(handle);
  897. if (ACPI_SUCCESS(status)) {
  898. dbg("Gained control for hotplug HW for pci %s (%s)\n",
  899. pci_name(dev), (char *)string.pointer);
  900. kfree(string.pointer);
  901. return 0;
  902. }
  903. if (acpi_root_bridge(handle))
  904. break;
  905. chandle = handle;
  906. status = acpi_get_parent(chandle, &handle);
  907. if (ACPI_FAILURE(status))
  908. break;
  909. }
  910. dbg("Cannot get control of hotplug hardware for pci %s\n",
  911. pci_name(dev));
  912. kfree(string.pointer);
  913. return -1;
  914. }
  915. #endif
  916. static int pcie_init_hardware_part1(struct controller *ctrl,
  917. struct pcie_device *dev)
  918. {
  919. /* Clear all remaining event bits in Slot Status register */
  920. if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f)) {
  921. err("%s: Cannot write to SLOTSTATUS register\n", __func__);
  922. return -1;
  923. }
  924. /* Mask Hot-plug Interrupt Enable */
  925. if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE)) {
  926. err("%s: Cannot mask hotplug interrupt enable\n", __func__);
  927. return -1;
  928. }
  929. return 0;
  930. }
  931. int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev)
  932. {
  933. u16 cmd, mask;
  934. cmd = PRSN_DETECT_ENABLE;
  935. if (ATTN_BUTTN(ctrl))
  936. cmd |= ATTN_BUTTN_ENABLE;
  937. if (POWER_CTRL(ctrl))
  938. cmd |= PWR_FAULT_DETECT_ENABLE;
  939. if (MRL_SENS(ctrl))
  940. cmd |= MRL_DETECT_ENABLE;
  941. if (!pciehp_poll_mode)
  942. cmd |= HP_INTR_ENABLE;
  943. mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE |
  944. PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE | HP_INTR_ENABLE;
  945. if (pcie_write_cmd(ctrl, cmd, mask)) {
  946. err("%s: Cannot enable software notification\n", __func__);
  947. goto abort;
  948. }
  949. if (pciehp_force)
  950. dbg("Bypassing BIOS check for pciehp use on %s\n",
  951. pci_name(ctrl->pci_dev));
  952. else if (pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev))
  953. goto abort_disable_intr;
  954. return 0;
  955. /* We end up here for the many possible ways to fail this API. */
  956. abort_disable_intr:
  957. if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE))
  958. err("%s : disabling interrupts failed\n", __func__);
  959. abort:
  960. return -1;
  961. }
  962. static inline void dbg_ctrl(struct controller *ctrl)
  963. {
  964. int i;
  965. u16 reg16;
  966. struct pci_dev *pdev = ctrl->pci_dev;
  967. if (!pciehp_debug)
  968. return;
  969. dbg("Hotplug Controller:\n");
  970. dbg(" Seg/Bus/Dev/Func/IRQ : %s IRQ %d\n", pci_name(pdev), pdev->irq);
  971. dbg(" Vendor ID : 0x%04x\n", pdev->vendor);
  972. dbg(" Device ID : 0x%04x\n", pdev->device);
  973. dbg(" Subsystem ID : 0x%04x\n", pdev->subsystem_device);
  974. dbg(" Subsystem Vendor ID : 0x%04x\n", pdev->subsystem_vendor);
  975. dbg(" PCIe Cap offset : 0x%02x\n", ctrl->cap_base);
  976. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  977. if (!pci_resource_len(pdev, i))
  978. continue;
  979. dbg(" PCI resource [%d] : 0x%llx@0x%llx\n", i,
  980. (unsigned long long)pci_resource_len(pdev, i),
  981. (unsigned long long)pci_resource_start(pdev, i));
  982. }
  983. dbg("Slot Capabilities : 0x%08x\n", ctrl->slot_cap);
  984. dbg(" Physical Slot Number : %d\n", ctrl->first_slot);
  985. dbg(" Attention Button : %3s\n", ATTN_BUTTN(ctrl) ? "yes" : "no");
  986. dbg(" Power Controller : %3s\n", POWER_CTRL(ctrl) ? "yes" : "no");
  987. dbg(" MRL Sensor : %3s\n", MRL_SENS(ctrl) ? "yes" : "no");
  988. dbg(" Attention Indicator : %3s\n", ATTN_LED(ctrl) ? "yes" : "no");
  989. dbg(" Power Indicator : %3s\n", PWR_LED(ctrl) ? "yes" : "no");
  990. dbg(" Hot-Plug Surprise : %3s\n", HP_SUPR_RM(ctrl) ? "yes" : "no");
  991. dbg(" EMI Present : %3s\n", EMI(ctrl) ? "yes" : "no");
  992. dbg(" Comamnd Completed : %3s\n", NO_CMD_CMPL(ctrl)? "no" : "yes");
  993. pciehp_readw(ctrl, SLOTSTATUS, &reg16);
  994. dbg("Slot Status : 0x%04x\n", reg16);
  995. pciehp_readw(ctrl, SLOTSTATUS, &reg16);
  996. dbg("Slot Control : 0x%04x\n", reg16);
  997. }
  998. int pcie_init(struct controller *ctrl, struct pcie_device *dev)
  999. {
  1000. u32 slot_cap;
  1001. struct pci_dev *pdev = dev->port;
  1002. ctrl->pci_dev = pdev;
  1003. ctrl->cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP);
  1004. if (!ctrl->cap_base) {
  1005. err("%s: Cannot find PCI Express capability\n", __func__);
  1006. goto abort;
  1007. }
  1008. if (pciehp_readl(ctrl, SLOTCAP, &slot_cap)) {
  1009. err("%s: Cannot read SLOTCAP register\n", __func__);
  1010. goto abort;
  1011. }
  1012. ctrl->slot_cap = slot_cap;
  1013. ctrl->first_slot = slot_cap >> 19;
  1014. ctrl->slot_device_offset = 0;
  1015. ctrl->num_slots = 1;
  1016. ctrl->hpc_ops = &pciehp_hpc_ops;
  1017. mutex_init(&ctrl->crit_sect);
  1018. mutex_init(&ctrl->ctrl_lock);
  1019. init_waitqueue_head(&ctrl->queue);
  1020. dbg_ctrl(ctrl);
  1021. /*
  1022. * Controller doesn't notify of command completion if the "No
  1023. * Command Completed Support" bit is set in Slot Capability
  1024. * register or the controller supports none of power
  1025. * controller, attention led, power led and EMI.
  1026. */
  1027. if (NO_CMD_CMPL(ctrl) ||
  1028. !(POWER_CTRL(ctrl) | ATTN_LED(ctrl) | PWR_LED(ctrl) | EMI(ctrl)))
  1029. ctrl->no_cmd_complete = 1;
  1030. info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n",
  1031. pdev->vendor, pdev->device,
  1032. pdev->subsystem_vendor, pdev->subsystem_device);
  1033. if (pcie_init_hardware_part1(ctrl, dev))
  1034. goto abort;
  1035. if (pciehp_request_irq(ctrl))
  1036. goto abort;
  1037. /*
  1038. * If this is the first controller to be initialized,
  1039. * initialize the pciehp work queue
  1040. */
  1041. if (atomic_add_return(1, &pciehp_num_controllers) == 1) {
  1042. pciehp_wq = create_singlethread_workqueue("pciehpd");
  1043. if (!pciehp_wq) {
  1044. goto abort_free_irq;
  1045. }
  1046. }
  1047. if (pcie_init_hardware_part2(ctrl, dev))
  1048. goto abort_free_irq;
  1049. return 0;
  1050. abort_free_irq:
  1051. pciehp_free_irq(ctrl);
  1052. abort:
  1053. return -1;
  1054. }