shpchp_hpc.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. /*
  2. * Standard 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/pci.h>
  33. #include <linux/interrupt.h>
  34. #include "shpchp.h"
  35. #ifdef DEBUG
  36. #define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */
  37. #define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */
  38. #define DBG_K_INFO ((unsigned int)0x00000004) /* Info messages */
  39. #define DBG_K_ERROR ((unsigned int)0x00000008) /* Error messages */
  40. #define DBG_K_TRACE (DBG_K_TRACE_ENTRY|DBG_K_TRACE_EXIT)
  41. #define DBG_K_STANDARD (DBG_K_INFO|DBG_K_ERROR|DBG_K_TRACE)
  42. /* Redefine this flagword to set debug level */
  43. #define DEBUG_LEVEL DBG_K_STANDARD
  44. #define DEFINE_DBG_BUFFER char __dbg_str_buf[256];
  45. #define DBG_PRINT( dbg_flags, args... ) \
  46. do { \
  47. if ( DEBUG_LEVEL & ( dbg_flags ) ) \
  48. { \
  49. int len; \
  50. len = sprintf( __dbg_str_buf, "%s:%d: %s: ", \
  51. __FILE__, __LINE__, __FUNCTION__ ); \
  52. sprintf( __dbg_str_buf + len, args ); \
  53. printk( KERN_NOTICE "%s\n", __dbg_str_buf ); \
  54. } \
  55. } while (0)
  56. #define DBG_ENTER_ROUTINE DBG_PRINT (DBG_K_TRACE_ENTRY, "%s", "[Entry]");
  57. #define DBG_LEAVE_ROUTINE DBG_PRINT (DBG_K_TRACE_EXIT, "%s", "[Exit]");
  58. #else
  59. #define DEFINE_DBG_BUFFER
  60. #define DBG_ENTER_ROUTINE
  61. #define DBG_LEAVE_ROUTINE
  62. #endif /* DEBUG */
  63. /* Slot Available Register I field definition */
  64. #define SLOT_33MHZ 0x0000001f
  65. #define SLOT_66MHZ_PCIX 0x00001f00
  66. #define SLOT_100MHZ_PCIX 0x001f0000
  67. #define SLOT_133MHZ_PCIX 0x1f000000
  68. /* Slot Available Register II field definition */
  69. #define SLOT_66MHZ 0x0000001f
  70. #define SLOT_66MHZ_PCIX_266 0x00000f00
  71. #define SLOT_100MHZ_PCIX_266 0x0000f000
  72. #define SLOT_133MHZ_PCIX_266 0x000f0000
  73. #define SLOT_66MHZ_PCIX_533 0x00f00000
  74. #define SLOT_100MHZ_PCIX_533 0x0f000000
  75. #define SLOT_133MHZ_PCIX_533 0xf0000000
  76. /* Slot Configuration */
  77. #define SLOT_NUM 0x0000001F
  78. #define FIRST_DEV_NUM 0x00001F00
  79. #define PSN 0x07FF0000
  80. #define UPDOWN 0x20000000
  81. #define MRLSENSOR 0x40000000
  82. #define ATTN_BUTTON 0x80000000
  83. /*
  84. * Interrupt Locator Register definitions
  85. */
  86. #define CMD_INTR_PENDING (1 << 0)
  87. #define SLOT_INTR_PENDING(i) (1 << (i + 1))
  88. /*
  89. * Controller SERR-INT Register
  90. */
  91. #define GLOBAL_INTR_MASK (1 << 0)
  92. #define GLOBAL_SERR_MASK (1 << 1)
  93. #define COMMAND_INTR_MASK (1 << 2)
  94. #define ARBITER_SERR_MASK (1 << 3)
  95. #define COMMAND_DETECTED (1 << 16)
  96. #define ARBITER_DETECTED (1 << 17)
  97. #define SERR_INTR_RSVDZ_MASK 0xfffc0000
  98. /*
  99. * Logical Slot Register definitions
  100. */
  101. #define SLOT_REG(i) (SLOT1 + (4 * i))
  102. #define SLOT_STATE_SHIFT (0)
  103. #define SLOT_STATE_MASK (3 << 0)
  104. #define SLOT_STATE_PWRONLY (1)
  105. #define SLOT_STATE_ENABLED (2)
  106. #define SLOT_STATE_DISABLED (3)
  107. #define PWR_LED_STATE_SHIFT (2)
  108. #define PWR_LED_STATE_MASK (3 << 2)
  109. #define ATN_LED_STATE_SHIFT (4)
  110. #define ATN_LED_STATE_MASK (3 << 4)
  111. #define ATN_LED_STATE_ON (1)
  112. #define ATN_LED_STATE_BLINK (2)
  113. #define ATN_LED_STATE_OFF (3)
  114. #define POWER_FAULT (1 << 6)
  115. #define ATN_BUTTON (1 << 7)
  116. #define MRL_SENSOR (1 << 8)
  117. #define MHZ66_CAP (1 << 9)
  118. #define PRSNT_SHIFT (10)
  119. #define PRSNT_MASK (3 << 10)
  120. #define PCIX_CAP_SHIFT (12)
  121. #define PCIX_CAP_MASK_PI1 (3 << 12)
  122. #define PCIX_CAP_MASK_PI2 (7 << 12)
  123. #define PRSNT_CHANGE_DETECTED (1 << 16)
  124. #define ISO_PFAULT_DETECTED (1 << 17)
  125. #define BUTTON_PRESS_DETECTED (1 << 18)
  126. #define MRL_CHANGE_DETECTED (1 << 19)
  127. #define CON_PFAULT_DETECTED (1 << 20)
  128. #define PRSNT_CHANGE_INTR_MASK (1 << 24)
  129. #define ISO_PFAULT_INTR_MASK (1 << 25)
  130. #define BUTTON_PRESS_INTR_MASK (1 << 26)
  131. #define MRL_CHANGE_INTR_MASK (1 << 27)
  132. #define CON_PFAULT_INTR_MASK (1 << 28)
  133. #define MRL_CHANGE_SERR_MASK (1 << 29)
  134. #define CON_PFAULT_SERR_MASK (1 << 30)
  135. #define SLOT_REG_RSVDZ_MASK (1 << 15) | (7 << 21)
  136. /*
  137. * SHPC Command Code definitnions
  138. *
  139. * Slot Operation 00h - 3Fh
  140. * Set Bus Segment Speed/Mode A 40h - 47h
  141. * Power-Only All Slots 48h
  142. * Enable All Slots 49h
  143. * Set Bus Segment Speed/Mode B (PI=2) 50h - 5Fh
  144. * Reserved Command Codes 60h - BFh
  145. * Vendor Specific Commands C0h - FFh
  146. */
  147. #define SET_SLOT_PWR 0x01 /* Slot Operation */
  148. #define SET_SLOT_ENABLE 0x02
  149. #define SET_SLOT_DISABLE 0x03
  150. #define SET_PWR_ON 0x04
  151. #define SET_PWR_BLINK 0x08
  152. #define SET_PWR_OFF 0x0c
  153. #define SET_ATTN_ON 0x10
  154. #define SET_ATTN_BLINK 0x20
  155. #define SET_ATTN_OFF 0x30
  156. #define SETA_PCI_33MHZ 0x40 /* Set Bus Segment Speed/Mode A */
  157. #define SETA_PCI_66MHZ 0x41
  158. #define SETA_PCIX_66MHZ 0x42
  159. #define SETA_PCIX_100MHZ 0x43
  160. #define SETA_PCIX_133MHZ 0x44
  161. #define SETA_RESERVED1 0x45
  162. #define SETA_RESERVED2 0x46
  163. #define SETA_RESERVED3 0x47
  164. #define SET_PWR_ONLY_ALL 0x48 /* Power-Only All Slots */
  165. #define SET_ENABLE_ALL 0x49 /* Enable All Slots */
  166. #define SETB_PCI_33MHZ 0x50 /* Set Bus Segment Speed/Mode B */
  167. #define SETB_PCI_66MHZ 0x51
  168. #define SETB_PCIX_66MHZ_PM 0x52
  169. #define SETB_PCIX_100MHZ_PM 0x53
  170. #define SETB_PCIX_133MHZ_PM 0x54
  171. #define SETB_PCIX_66MHZ_EM 0x55
  172. #define SETB_PCIX_100MHZ_EM 0x56
  173. #define SETB_PCIX_133MHZ_EM 0x57
  174. #define SETB_PCIX_66MHZ_266 0x58
  175. #define SETB_PCIX_100MHZ_266 0x59
  176. #define SETB_PCIX_133MHZ_266 0x5a
  177. #define SETB_PCIX_66MHZ_533 0x5b
  178. #define SETB_PCIX_100MHZ_533 0x5c
  179. #define SETB_PCIX_133MHZ_533 0x5d
  180. #define SETB_RESERVED1 0x5e
  181. #define SETB_RESERVED2 0x5f
  182. /*
  183. * SHPC controller command error code
  184. */
  185. #define SWITCH_OPEN 0x1
  186. #define INVALID_CMD 0x2
  187. #define INVALID_SPEED_MODE 0x4
  188. /*
  189. * For accessing SHPC Working Register Set via PCI Configuration Space
  190. */
  191. #define DWORD_SELECT 0x2
  192. #define DWORD_DATA 0x4
  193. /* Field Offset in Logical Slot Register - byte boundary */
  194. #define SLOT_EVENT_LATCH 0x2
  195. #define SLOT_SERR_INT_MASK 0x3
  196. DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
  197. static atomic_t shpchp_num_controllers = ATOMIC_INIT(0);
  198. static irqreturn_t shpc_isr(int irq, void *dev_id);
  199. static void start_int_poll_timer(struct controller *ctrl, int sec);
  200. static int hpc_check_cmd_status(struct controller *ctrl);
  201. static inline u8 shpc_readb(struct controller *ctrl, int reg)
  202. {
  203. return readb(ctrl->creg + reg);
  204. }
  205. static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val)
  206. {
  207. writeb(val, ctrl->creg + reg);
  208. }
  209. static inline u16 shpc_readw(struct controller *ctrl, int reg)
  210. {
  211. return readw(ctrl->creg + reg);
  212. }
  213. static inline void shpc_writew(struct controller *ctrl, int reg, u16 val)
  214. {
  215. writew(val, ctrl->creg + reg);
  216. }
  217. static inline u32 shpc_readl(struct controller *ctrl, int reg)
  218. {
  219. return readl(ctrl->creg + reg);
  220. }
  221. static inline void shpc_writel(struct controller *ctrl, int reg, u32 val)
  222. {
  223. writel(val, ctrl->creg + reg);
  224. }
  225. static inline int shpc_indirect_read(struct controller *ctrl, int index,
  226. u32 *value)
  227. {
  228. int rc;
  229. u32 cap_offset = ctrl->cap_offset;
  230. struct pci_dev *pdev = ctrl->pci_dev;
  231. rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
  232. if (rc)
  233. return rc;
  234. return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
  235. }
  236. /*
  237. * This is the interrupt polling timeout function.
  238. */
  239. static void int_poll_timeout(unsigned long data)
  240. {
  241. struct controller *ctrl = (struct controller *)data;
  242. DBG_ENTER_ROUTINE
  243. /* Poll for interrupt events. regs == NULL => polling */
  244. shpc_isr(0, ctrl);
  245. init_timer(&ctrl->poll_timer);
  246. if (!shpchp_poll_time)
  247. shpchp_poll_time = 2; /* default polling interval is 2 sec */
  248. start_int_poll_timer(ctrl, shpchp_poll_time);
  249. DBG_LEAVE_ROUTINE
  250. }
  251. /*
  252. * This function starts the interrupt polling timer.
  253. */
  254. static void start_int_poll_timer(struct controller *ctrl, int sec)
  255. {
  256. /* Clamp to sane value */
  257. if ((sec <= 0) || (sec > 60))
  258. sec = 2;
  259. ctrl->poll_timer.function = &int_poll_timeout;
  260. ctrl->poll_timer.data = (unsigned long)ctrl;
  261. ctrl->poll_timer.expires = jiffies + sec * HZ;
  262. add_timer(&ctrl->poll_timer);
  263. }
  264. static inline int is_ctrl_busy(struct controller *ctrl)
  265. {
  266. u16 cmd_status = shpc_readw(ctrl, CMD_STATUS);
  267. return cmd_status & 0x1;
  268. }
  269. /*
  270. * Returns 1 if SHPC finishes executing a command within 1 sec,
  271. * otherwise returns 0.
  272. */
  273. static inline int shpc_poll_ctrl_busy(struct controller *ctrl)
  274. {
  275. int i;
  276. if (!is_ctrl_busy(ctrl))
  277. return 1;
  278. /* Check every 0.1 sec for a total of 1 sec */
  279. for (i = 0; i < 10; i++) {
  280. msleep(100);
  281. if (!is_ctrl_busy(ctrl))
  282. return 1;
  283. }
  284. return 0;
  285. }
  286. static inline int shpc_wait_cmd(struct controller *ctrl)
  287. {
  288. int retval = 0;
  289. unsigned long timeout = msecs_to_jiffies(1000);
  290. int rc;
  291. if (shpchp_poll_mode)
  292. rc = shpc_poll_ctrl_busy(ctrl);
  293. else
  294. rc = wait_event_interruptible_timeout(ctrl->queue,
  295. !is_ctrl_busy(ctrl), timeout);
  296. if (!rc && is_ctrl_busy(ctrl)) {
  297. retval = -EIO;
  298. err("Command not completed in 1000 msec\n");
  299. } else if (rc < 0) {
  300. retval = -EINTR;
  301. info("Command was interrupted by a signal\n");
  302. }
  303. return retval;
  304. }
  305. static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
  306. {
  307. struct controller *ctrl = slot->ctrl;
  308. u16 cmd_status;
  309. int retval = 0;
  310. u16 temp_word;
  311. DBG_ENTER_ROUTINE
  312. mutex_lock(&slot->ctrl->cmd_lock);
  313. if (!shpc_poll_ctrl_busy(ctrl)) {
  314. /* After 1 sec and and the controller is still busy */
  315. err("%s : Controller is still busy after 1 sec.\n",
  316. __FUNCTION__);
  317. retval = -EBUSY;
  318. goto out;
  319. }
  320. ++t_slot;
  321. temp_word = (t_slot << 8) | (cmd & 0xFF);
  322. dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd);
  323. /* To make sure the Controller Busy bit is 0 before we send out the
  324. * command.
  325. */
  326. shpc_writew(ctrl, CMD, temp_word);
  327. /*
  328. * Wait for command completion.
  329. */
  330. retval = shpc_wait_cmd(slot->ctrl);
  331. if (retval)
  332. goto out;
  333. cmd_status = hpc_check_cmd_status(slot->ctrl);
  334. if (cmd_status) {
  335. err("%s: Failed to issued command 0x%x (error code = %d)\n",
  336. __FUNCTION__, cmd, cmd_status);
  337. retval = -EIO;
  338. }
  339. out:
  340. mutex_unlock(&slot->ctrl->cmd_lock);
  341. DBG_LEAVE_ROUTINE
  342. return retval;
  343. }
  344. static int hpc_check_cmd_status(struct controller *ctrl)
  345. {
  346. u16 cmd_status;
  347. int retval = 0;
  348. DBG_ENTER_ROUTINE
  349. cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F;
  350. switch (cmd_status >> 1) {
  351. case 0:
  352. retval = 0;
  353. break;
  354. case 1:
  355. retval = SWITCH_OPEN;
  356. err("%s: Switch opened!\n", __FUNCTION__);
  357. break;
  358. case 2:
  359. retval = INVALID_CMD;
  360. err("%s: Invalid HPC command!\n", __FUNCTION__);
  361. break;
  362. case 4:
  363. retval = INVALID_SPEED_MODE;
  364. err("%s: Invalid bus speed/mode!\n", __FUNCTION__);
  365. break;
  366. default:
  367. retval = cmd_status;
  368. }
  369. DBG_LEAVE_ROUTINE
  370. return retval;
  371. }
  372. static int hpc_get_attention_status(struct slot *slot, u8 *status)
  373. {
  374. struct controller *ctrl = slot->ctrl;
  375. u32 slot_reg;
  376. u8 state;
  377. DBG_ENTER_ROUTINE
  378. slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  379. state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT;
  380. switch (state) {
  381. case ATN_LED_STATE_ON:
  382. *status = 1; /* On */
  383. break;
  384. case ATN_LED_STATE_BLINK:
  385. *status = 2; /* Blink */
  386. break;
  387. case ATN_LED_STATE_OFF:
  388. *status = 0; /* Off */
  389. break;
  390. default:
  391. *status = 0xFF; /* Reserved */
  392. break;
  393. }
  394. DBG_LEAVE_ROUTINE
  395. return 0;
  396. }
  397. static int hpc_get_power_status(struct slot * slot, u8 *status)
  398. {
  399. struct controller *ctrl = slot->ctrl;
  400. u32 slot_reg;
  401. u8 state;
  402. DBG_ENTER_ROUTINE
  403. slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  404. state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT;
  405. switch (state) {
  406. case SLOT_STATE_PWRONLY:
  407. *status = 2; /* Powered only */
  408. break;
  409. case SLOT_STATE_ENABLED:
  410. *status = 1; /* Enabled */
  411. break;
  412. case SLOT_STATE_DISABLED:
  413. *status = 0; /* Disabled */
  414. break;
  415. default:
  416. *status = 0xFF; /* Reserved */
  417. break;
  418. }
  419. DBG_LEAVE_ROUTINE
  420. return 0;
  421. }
  422. static int hpc_get_latch_status(struct slot *slot, u8 *status)
  423. {
  424. struct controller *ctrl = slot->ctrl;
  425. u32 slot_reg;
  426. DBG_ENTER_ROUTINE
  427. slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  428. *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */
  429. DBG_LEAVE_ROUTINE
  430. return 0;
  431. }
  432. static int hpc_get_adapter_status(struct slot *slot, u8 *status)
  433. {
  434. struct controller *ctrl = slot->ctrl;
  435. u32 slot_reg;
  436. u8 state;
  437. DBG_ENTER_ROUTINE
  438. slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  439. state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT;
  440. *status = (state != 0x3) ? 1 : 0;
  441. DBG_LEAVE_ROUTINE
  442. return 0;
  443. }
  444. static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
  445. {
  446. struct controller *ctrl = slot->ctrl;
  447. DBG_ENTER_ROUTINE
  448. *prog_int = shpc_readb(ctrl, PROG_INTERFACE);
  449. DBG_LEAVE_ROUTINE
  450. return 0;
  451. }
  452. static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
  453. {
  454. int retval = 0;
  455. struct controller *ctrl = slot->ctrl;
  456. u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  457. u8 m66_cap = !!(slot_reg & MHZ66_CAP);
  458. u8 pi, pcix_cap;
  459. DBG_ENTER_ROUTINE
  460. if ((retval = hpc_get_prog_int(slot, &pi)))
  461. return retval;
  462. switch (pi) {
  463. case 1:
  464. pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT;
  465. break;
  466. case 2:
  467. pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT;
  468. break;
  469. default:
  470. return -ENODEV;
  471. }
  472. dbg("%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n",
  473. __FUNCTION__, slot_reg, pcix_cap, m66_cap);
  474. switch (pcix_cap) {
  475. case 0x0:
  476. *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
  477. break;
  478. case 0x1:
  479. *value = PCI_SPEED_66MHz_PCIX;
  480. break;
  481. case 0x3:
  482. *value = PCI_SPEED_133MHz_PCIX;
  483. break;
  484. case 0x4:
  485. *value = PCI_SPEED_133MHz_PCIX_266;
  486. break;
  487. case 0x5:
  488. *value = PCI_SPEED_133MHz_PCIX_533;
  489. break;
  490. case 0x2:
  491. default:
  492. *value = PCI_SPEED_UNKNOWN;
  493. retval = -ENODEV;
  494. break;
  495. }
  496. dbg("Adapter speed = %d\n", *value);
  497. DBG_LEAVE_ROUTINE
  498. return retval;
  499. }
  500. static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
  501. {
  502. struct controller *ctrl = slot->ctrl;
  503. u16 sec_bus_status;
  504. u8 pi;
  505. int retval = 0;
  506. DBG_ENTER_ROUTINE
  507. pi = shpc_readb(ctrl, PROG_INTERFACE);
  508. sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG);
  509. if (pi == 2) {
  510. *mode = (sec_bus_status & 0x0100) >> 8;
  511. } else {
  512. retval = -1;
  513. }
  514. dbg("Mode 1 ECC cap = %d\n", *mode);
  515. DBG_LEAVE_ROUTINE
  516. return retval;
  517. }
  518. static int hpc_query_power_fault(struct slot * slot)
  519. {
  520. struct controller *ctrl = slot->ctrl;
  521. u32 slot_reg;
  522. DBG_ENTER_ROUTINE
  523. slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  524. DBG_LEAVE_ROUTINE
  525. /* Note: Logic 0 => fault */
  526. return !(slot_reg & POWER_FAULT);
  527. }
  528. static int hpc_set_attention_status(struct slot *slot, u8 value)
  529. {
  530. u8 slot_cmd = 0;
  531. switch (value) {
  532. case 0 :
  533. slot_cmd = SET_ATTN_OFF; /* OFF */
  534. break;
  535. case 1:
  536. slot_cmd = SET_ATTN_ON; /* ON */
  537. break;
  538. case 2:
  539. slot_cmd = SET_ATTN_BLINK; /* BLINK */
  540. break;
  541. default:
  542. return -1;
  543. }
  544. return shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
  545. }
  546. static void hpc_set_green_led_on(struct slot *slot)
  547. {
  548. shpc_write_cmd(slot, slot->hp_slot, SET_PWR_ON);
  549. }
  550. static void hpc_set_green_led_off(struct slot *slot)
  551. {
  552. shpc_write_cmd(slot, slot->hp_slot, SET_PWR_OFF);
  553. }
  554. static void hpc_set_green_led_blink(struct slot *slot)
  555. {
  556. shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK);
  557. }
  558. static void hpc_release_ctlr(struct controller *ctrl)
  559. {
  560. int i;
  561. u32 slot_reg, serr_int;
  562. DBG_ENTER_ROUTINE
  563. /*
  564. * Mask event interrupts and SERRs of all slots
  565. */
  566. for (i = 0; i < ctrl->num_slots; i++) {
  567. slot_reg = shpc_readl(ctrl, SLOT_REG(i));
  568. slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
  569. BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
  570. CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
  571. CON_PFAULT_SERR_MASK);
  572. slot_reg &= ~SLOT_REG_RSVDZ_MASK;
  573. shpc_writel(ctrl, SLOT_REG(i), slot_reg);
  574. }
  575. cleanup_slots(ctrl);
  576. /*
  577. * Mask SERR and System Interrut generation
  578. */
  579. serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
  580. serr_int |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
  581. COMMAND_INTR_MASK | ARBITER_SERR_MASK);
  582. serr_int &= ~SERR_INTR_RSVDZ_MASK;
  583. shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
  584. if (shpchp_poll_mode)
  585. del_timer(&ctrl->poll_timer);
  586. else {
  587. free_irq(ctrl->pci_dev->irq, ctrl);
  588. pci_disable_msi(ctrl->pci_dev);
  589. }
  590. iounmap(ctrl->creg);
  591. release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
  592. /*
  593. * If this is the last controller to be released, destroy the
  594. * shpchpd work queue
  595. */
  596. if (atomic_dec_and_test(&shpchp_num_controllers))
  597. destroy_workqueue(shpchp_wq);
  598. DBG_LEAVE_ROUTINE
  599. }
  600. static int hpc_power_on_slot(struct slot * slot)
  601. {
  602. int retval;
  603. DBG_ENTER_ROUTINE
  604. retval = shpc_write_cmd(slot, slot->hp_slot, SET_SLOT_PWR);
  605. if (retval) {
  606. err("%s: Write command failed!\n", __FUNCTION__);
  607. return retval;
  608. }
  609. DBG_LEAVE_ROUTINE
  610. return 0;
  611. }
  612. static int hpc_slot_enable(struct slot * slot)
  613. {
  614. int retval;
  615. DBG_ENTER_ROUTINE
  616. /* Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
  617. retval = shpc_write_cmd(slot, slot->hp_slot,
  618. SET_SLOT_ENABLE | SET_PWR_BLINK | SET_ATTN_OFF);
  619. if (retval) {
  620. err("%s: Write command failed!\n", __FUNCTION__);
  621. return retval;
  622. }
  623. DBG_LEAVE_ROUTINE
  624. return 0;
  625. }
  626. static int hpc_slot_disable(struct slot * slot)
  627. {
  628. int retval;
  629. DBG_ENTER_ROUTINE
  630. /* Slot - Disable, Power Indicator - Off, Attention Indicator - On */
  631. retval = shpc_write_cmd(slot, slot->hp_slot,
  632. SET_SLOT_DISABLE | SET_PWR_OFF | SET_ATTN_ON);
  633. if (retval) {
  634. err("%s: Write command failed!\n", __FUNCTION__);
  635. return retval;
  636. }
  637. DBG_LEAVE_ROUTINE
  638. return 0;
  639. }
  640. static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
  641. {
  642. int retval;
  643. struct controller *ctrl = slot->ctrl;
  644. u8 pi, cmd;
  645. DBG_ENTER_ROUTINE
  646. pi = shpc_readb(ctrl, PROG_INTERFACE);
  647. if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX))
  648. return -EINVAL;
  649. switch (value) {
  650. case PCI_SPEED_33MHz:
  651. cmd = SETA_PCI_33MHZ;
  652. break;
  653. case PCI_SPEED_66MHz:
  654. cmd = SETA_PCI_66MHZ;
  655. break;
  656. case PCI_SPEED_66MHz_PCIX:
  657. cmd = SETA_PCIX_66MHZ;
  658. break;
  659. case PCI_SPEED_100MHz_PCIX:
  660. cmd = SETA_PCIX_100MHZ;
  661. break;
  662. case PCI_SPEED_133MHz_PCIX:
  663. cmd = SETA_PCIX_133MHZ;
  664. break;
  665. case PCI_SPEED_66MHz_PCIX_ECC:
  666. cmd = SETB_PCIX_66MHZ_EM;
  667. break;
  668. case PCI_SPEED_100MHz_PCIX_ECC:
  669. cmd = SETB_PCIX_100MHZ_EM;
  670. break;
  671. case PCI_SPEED_133MHz_PCIX_ECC:
  672. cmd = SETB_PCIX_133MHZ_EM;
  673. break;
  674. case PCI_SPEED_66MHz_PCIX_266:
  675. cmd = SETB_PCIX_66MHZ_266;
  676. break;
  677. case PCI_SPEED_100MHz_PCIX_266:
  678. cmd = SETB_PCIX_100MHZ_266;
  679. break;
  680. case PCI_SPEED_133MHz_PCIX_266:
  681. cmd = SETB_PCIX_133MHZ_266;
  682. break;
  683. case PCI_SPEED_66MHz_PCIX_533:
  684. cmd = SETB_PCIX_66MHZ_533;
  685. break;
  686. case PCI_SPEED_100MHz_PCIX_533:
  687. cmd = SETB_PCIX_100MHZ_533;
  688. break;
  689. case PCI_SPEED_133MHz_PCIX_533:
  690. cmd = SETB_PCIX_133MHZ_533;
  691. break;
  692. default:
  693. return -EINVAL;
  694. }
  695. retval = shpc_write_cmd(slot, 0, cmd);
  696. if (retval)
  697. err("%s: Write command failed!\n", __FUNCTION__);
  698. DBG_LEAVE_ROUTINE
  699. return retval;
  700. }
  701. static irqreturn_t shpc_isr(int irq, void *dev_id)
  702. {
  703. struct controller *ctrl = (struct controller *)dev_id;
  704. u32 serr_int, slot_reg, intr_loc, intr_loc2;
  705. int hp_slot;
  706. /* Check to see if it was our interrupt */
  707. intr_loc = shpc_readl(ctrl, INTR_LOC);
  708. if (!intr_loc)
  709. return IRQ_NONE;
  710. dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc);
  711. if(!shpchp_poll_mode) {
  712. /*
  713. * Mask Global Interrupt Mask - see implementation
  714. * note on p. 139 of SHPC spec rev 1.0
  715. */
  716. serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
  717. serr_int |= GLOBAL_INTR_MASK;
  718. serr_int &= ~SERR_INTR_RSVDZ_MASK;
  719. shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
  720. intr_loc2 = shpc_readl(ctrl, INTR_LOC);
  721. dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
  722. }
  723. if (intr_loc & CMD_INTR_PENDING) {
  724. /*
  725. * Command Complete Interrupt Pending
  726. * RO only - clear by writing 1 to the Command Completion
  727. * Detect bit in Controller SERR-INT register
  728. */
  729. serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
  730. serr_int &= ~SERR_INTR_RSVDZ_MASK;
  731. shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
  732. wake_up_interruptible(&ctrl->queue);
  733. }
  734. if (!(intr_loc & ~CMD_INTR_PENDING))
  735. goto out;
  736. for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
  737. /* To find out which slot has interrupt pending */
  738. if (!(intr_loc & SLOT_INTR_PENDING(hp_slot)))
  739. continue;
  740. slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
  741. dbg("%s: Slot %x with intr, slot register = %x\n",
  742. __FUNCTION__, hp_slot, slot_reg);
  743. if (slot_reg & MRL_CHANGE_DETECTED)
  744. shpchp_handle_switch_change(hp_slot, ctrl);
  745. if (slot_reg & BUTTON_PRESS_DETECTED)
  746. shpchp_handle_attention_button(hp_slot, ctrl);
  747. if (slot_reg & PRSNT_CHANGE_DETECTED)
  748. shpchp_handle_presence_change(hp_slot, ctrl);
  749. if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED))
  750. shpchp_handle_power_fault(hp_slot, ctrl);
  751. /* Clear all slot events */
  752. slot_reg &= ~SLOT_REG_RSVDZ_MASK;
  753. shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
  754. }
  755. out:
  756. if (!shpchp_poll_mode) {
  757. /* Unmask Global Interrupt Mask */
  758. serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
  759. serr_int &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK);
  760. shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
  761. }
  762. return IRQ_HANDLED;
  763. }
  764. static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
  765. {
  766. int retval = 0;
  767. struct controller *ctrl = slot->ctrl;
  768. enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
  769. u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
  770. u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1);
  771. u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2);
  772. DBG_ENTER_ROUTINE
  773. if (pi == 2) {
  774. if (slot_avail2 & SLOT_133MHZ_PCIX_533)
  775. bus_speed = PCI_SPEED_133MHz_PCIX_533;
  776. else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
  777. bus_speed = PCI_SPEED_100MHz_PCIX_533;
  778. else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
  779. bus_speed = PCI_SPEED_66MHz_PCIX_533;
  780. else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
  781. bus_speed = PCI_SPEED_133MHz_PCIX_266;
  782. else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
  783. bus_speed = PCI_SPEED_100MHz_PCIX_266;
  784. else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
  785. bus_speed = PCI_SPEED_66MHz_PCIX_266;
  786. }
  787. if (bus_speed == PCI_SPEED_UNKNOWN) {
  788. if (slot_avail1 & SLOT_133MHZ_PCIX)
  789. bus_speed = PCI_SPEED_133MHz_PCIX;
  790. else if (slot_avail1 & SLOT_100MHZ_PCIX)
  791. bus_speed = PCI_SPEED_100MHz_PCIX;
  792. else if (slot_avail1 & SLOT_66MHZ_PCIX)
  793. bus_speed = PCI_SPEED_66MHz_PCIX;
  794. else if (slot_avail2 & SLOT_66MHZ)
  795. bus_speed = PCI_SPEED_66MHz;
  796. else if (slot_avail1 & SLOT_33MHZ)
  797. bus_speed = PCI_SPEED_33MHz;
  798. else
  799. retval = -ENODEV;
  800. }
  801. *value = bus_speed;
  802. dbg("Max bus speed = %d\n", bus_speed);
  803. DBG_LEAVE_ROUTINE
  804. return retval;
  805. }
  806. static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
  807. {
  808. int retval = 0;
  809. struct controller *ctrl = slot->ctrl;
  810. enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
  811. u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG);
  812. u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
  813. u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
  814. DBG_ENTER_ROUTINE
  815. if ((pi == 1) && (speed_mode > 4)) {
  816. *value = PCI_SPEED_UNKNOWN;
  817. return -ENODEV;
  818. }
  819. switch (speed_mode) {
  820. case 0x0:
  821. *value = PCI_SPEED_33MHz;
  822. break;
  823. case 0x1:
  824. *value = PCI_SPEED_66MHz;
  825. break;
  826. case 0x2:
  827. *value = PCI_SPEED_66MHz_PCIX;
  828. break;
  829. case 0x3:
  830. *value = PCI_SPEED_100MHz_PCIX;
  831. break;
  832. case 0x4:
  833. *value = PCI_SPEED_133MHz_PCIX;
  834. break;
  835. case 0x5:
  836. *value = PCI_SPEED_66MHz_PCIX_ECC;
  837. break;
  838. case 0x6:
  839. *value = PCI_SPEED_100MHz_PCIX_ECC;
  840. break;
  841. case 0x7:
  842. *value = PCI_SPEED_133MHz_PCIX_ECC;
  843. break;
  844. case 0x8:
  845. *value = PCI_SPEED_66MHz_PCIX_266;
  846. break;
  847. case 0x9:
  848. *value = PCI_SPEED_100MHz_PCIX_266;
  849. break;
  850. case 0xa:
  851. *value = PCI_SPEED_133MHz_PCIX_266;
  852. break;
  853. case 0xb:
  854. *value = PCI_SPEED_66MHz_PCIX_533;
  855. break;
  856. case 0xc:
  857. *value = PCI_SPEED_100MHz_PCIX_533;
  858. break;
  859. case 0xd:
  860. *value = PCI_SPEED_133MHz_PCIX_533;
  861. break;
  862. default:
  863. *value = PCI_SPEED_UNKNOWN;
  864. retval = -ENODEV;
  865. break;
  866. }
  867. dbg("Current bus speed = %d\n", bus_speed);
  868. DBG_LEAVE_ROUTINE
  869. return retval;
  870. }
  871. static struct hpc_ops shpchp_hpc_ops = {
  872. .power_on_slot = hpc_power_on_slot,
  873. .slot_enable = hpc_slot_enable,
  874. .slot_disable = hpc_slot_disable,
  875. .set_bus_speed_mode = hpc_set_bus_speed_mode,
  876. .set_attention_status = hpc_set_attention_status,
  877. .get_power_status = hpc_get_power_status,
  878. .get_attention_status = hpc_get_attention_status,
  879. .get_latch_status = hpc_get_latch_status,
  880. .get_adapter_status = hpc_get_adapter_status,
  881. .get_max_bus_speed = hpc_get_max_bus_speed,
  882. .get_cur_bus_speed = hpc_get_cur_bus_speed,
  883. .get_adapter_speed = hpc_get_adapter_speed,
  884. .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
  885. .get_prog_int = hpc_get_prog_int,
  886. .query_power_fault = hpc_query_power_fault,
  887. .green_led_on = hpc_set_green_led_on,
  888. .green_led_off = hpc_set_green_led_off,
  889. .green_led_blink = hpc_set_green_led_blink,
  890. .release_ctlr = hpc_release_ctlr,
  891. };
  892. int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
  893. {
  894. int rc = -1, num_slots = 0;
  895. u8 hp_slot;
  896. u32 shpc_base_offset;
  897. u32 tempdword, slot_reg, slot_config;
  898. u8 i;
  899. DBG_ENTER_ROUTINE
  900. ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
  901. if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
  902. PCI_DEVICE_ID_AMD_GOLAM_7450)) {
  903. /* amd shpc driver doesn't use Base Offset; assume 0 */
  904. ctrl->mmio_base = pci_resource_start(pdev, 0);
  905. ctrl->mmio_size = pci_resource_len(pdev, 0);
  906. } else {
  907. ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
  908. if (!ctrl->cap_offset) {
  909. err("%s : cap_offset == 0\n", __FUNCTION__);
  910. goto abort;
  911. }
  912. dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
  913. rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
  914. if (rc) {
  915. err("%s: cannot read base_offset\n", __FUNCTION__);
  916. goto abort;
  917. }
  918. rc = shpc_indirect_read(ctrl, 3, &tempdword);
  919. if (rc) {
  920. err("%s: cannot read slot config\n", __FUNCTION__);
  921. goto abort;
  922. }
  923. num_slots = tempdword & SLOT_NUM;
  924. dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
  925. for (i = 0; i < 9 + num_slots; i++) {
  926. rc = shpc_indirect_read(ctrl, i, &tempdword);
  927. if (rc) {
  928. err("%s: cannot read creg (index = %d)\n",
  929. __FUNCTION__, i);
  930. goto abort;
  931. }
  932. dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
  933. tempdword);
  934. }
  935. ctrl->mmio_base =
  936. pci_resource_start(pdev, 0) + shpc_base_offset;
  937. ctrl->mmio_size = 0x24 + 0x4 * num_slots;
  938. }
  939. info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
  940. pdev->subsystem_device);
  941. rc = pci_enable_device(pdev);
  942. if (rc) {
  943. err("%s: pci_enable_device failed\n", __FUNCTION__);
  944. goto abort;
  945. }
  946. if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
  947. err("%s: cannot reserve MMIO region\n", __FUNCTION__);
  948. rc = -1;
  949. goto abort;
  950. }
  951. ctrl->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
  952. if (!ctrl->creg) {
  953. err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
  954. ctrl->mmio_size, ctrl->mmio_base);
  955. release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
  956. rc = -1;
  957. goto abort;
  958. }
  959. dbg("%s: ctrl->creg %p\n", __FUNCTION__, ctrl->creg);
  960. mutex_init(&ctrl->crit_sect);
  961. mutex_init(&ctrl->cmd_lock);
  962. /* Setup wait queue */
  963. init_waitqueue_head(&ctrl->queue);
  964. ctrl->hpc_ops = &shpchp_hpc_ops;
  965. /* Return PCI Controller Info */
  966. slot_config = shpc_readl(ctrl, SLOT_CONFIG);
  967. ctrl->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8;
  968. ctrl->num_slots = slot_config & SLOT_NUM;
  969. ctrl->first_slot = (slot_config & PSN) >> 16;
  970. ctrl->slot_num_inc = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
  971. /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
  972. tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
  973. dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
  974. tempdword |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
  975. COMMAND_INTR_MASK | ARBITER_SERR_MASK);
  976. tempdword &= ~SERR_INTR_RSVDZ_MASK;
  977. shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
  978. tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
  979. dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
  980. /* Mask the MRL sensor SERR Mask of individual slot in
  981. * Slot SERR-INT Mask & clear all the existing event if any
  982. */
  983. for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
  984. slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
  985. dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
  986. hp_slot, slot_reg);
  987. slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
  988. BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
  989. CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
  990. CON_PFAULT_SERR_MASK);
  991. slot_reg &= ~SLOT_REG_RSVDZ_MASK;
  992. shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
  993. }
  994. if (shpchp_poll_mode) {
  995. /* Install interrupt polling timer. Start with 10 sec delay */
  996. init_timer(&ctrl->poll_timer);
  997. start_int_poll_timer(ctrl, 10);
  998. } else {
  999. /* Installs the interrupt handler */
  1000. rc = pci_enable_msi(pdev);
  1001. if (rc) {
  1002. info("Can't get msi for the hotplug controller\n");
  1003. info("Use INTx for the hotplug controller\n");
  1004. }
  1005. rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED,
  1006. MY_NAME, (void *)ctrl);
  1007. dbg("%s: request_irq %d for hpc%d (returns %d)\n",
  1008. __FUNCTION__, ctrl->pci_dev->irq,
  1009. atomic_read(&shpchp_num_controllers), rc);
  1010. if (rc) {
  1011. err("Can't get irq %d for the hotplug controller\n",
  1012. ctrl->pci_dev->irq);
  1013. goto abort_iounmap;
  1014. }
  1015. }
  1016. dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
  1017. pdev->bus->number, PCI_SLOT(pdev->devfn),
  1018. PCI_FUNC(pdev->devfn), pdev->irq);
  1019. get_hp_hw_control_from_firmware(pdev);
  1020. /*
  1021. * If this is the first controller to be initialized,
  1022. * initialize the shpchpd work queue
  1023. */
  1024. if (atomic_add_return(1, &shpchp_num_controllers) == 1) {
  1025. shpchp_wq = create_singlethread_workqueue("shpchpd");
  1026. if (!shpchp_wq) {
  1027. rc = -ENOMEM;
  1028. goto abort_iounmap;
  1029. }
  1030. }
  1031. /*
  1032. * Unmask all event interrupts of all slots
  1033. */
  1034. for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
  1035. slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
  1036. dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
  1037. hp_slot, slot_reg);
  1038. slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
  1039. BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
  1040. CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK);
  1041. shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
  1042. }
  1043. if (!shpchp_poll_mode) {
  1044. /* Unmask all general input interrupts and SERR */
  1045. tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
  1046. tempdword &= ~(GLOBAL_INTR_MASK | COMMAND_INTR_MASK |
  1047. SERR_INTR_RSVDZ_MASK);
  1048. shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
  1049. tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
  1050. dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
  1051. }
  1052. DBG_LEAVE_ROUTINE
  1053. return 0;
  1054. /* We end up here for the many possible ways to fail this API. */
  1055. abort_iounmap:
  1056. iounmap(ctrl->creg);
  1057. abort:
  1058. DBG_LEAVE_ROUTINE
  1059. return rc;
  1060. }