pciehp_hpc.c 31 KB

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