shpchp_hpc.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  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 struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */
  198. static int ctlr_seq_num = 0; /* Controller sequenc # */
  199. static spinlock_t list_lock;
  200. static atomic_t shpchp_num_controllers = ATOMIC_INIT(0);
  201. static irqreturn_t shpc_isr(int irq, void *dev_id);
  202. static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec);
  203. static int hpc_check_cmd_status(struct controller *ctrl);
  204. static inline u8 shpc_readb(struct controller *ctrl, int reg)
  205. {
  206. return readb(ctrl->hpc_ctlr_handle->creg + reg);
  207. }
  208. static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val)
  209. {
  210. writeb(val, ctrl->hpc_ctlr_handle->creg + reg);
  211. }
  212. static inline u16 shpc_readw(struct controller *ctrl, int reg)
  213. {
  214. return readw(ctrl->hpc_ctlr_handle->creg + reg);
  215. }
  216. static inline void shpc_writew(struct controller *ctrl, int reg, u16 val)
  217. {
  218. writew(val, ctrl->hpc_ctlr_handle->creg + reg);
  219. }
  220. static inline u32 shpc_readl(struct controller *ctrl, int reg)
  221. {
  222. return readl(ctrl->hpc_ctlr_handle->creg + reg);
  223. }
  224. static inline void shpc_writel(struct controller *ctrl, int reg, u32 val)
  225. {
  226. writel(val, ctrl->hpc_ctlr_handle->creg + reg);
  227. }
  228. static inline int shpc_indirect_read(struct controller *ctrl, int index,
  229. u32 *value)
  230. {
  231. int rc;
  232. u32 cap_offset = ctrl->cap_offset;
  233. struct pci_dev *pdev = ctrl->pci_dev;
  234. rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
  235. if (rc)
  236. return rc;
  237. return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
  238. }
  239. /*
  240. * This is the interrupt polling timeout function.
  241. */
  242. static void int_poll_timeout(unsigned long lphp_ctlr)
  243. {
  244. struct php_ctlr_state_s *php_ctlr =
  245. (struct php_ctlr_state_s *)lphp_ctlr;
  246. DBG_ENTER_ROUTINE
  247. /* Poll for interrupt events. regs == NULL => polling */
  248. shpc_isr(0, php_ctlr->callback_instance_id);
  249. init_timer(&php_ctlr->int_poll_timer);
  250. if (!shpchp_poll_time)
  251. shpchp_poll_time = 2; /* default polling interval is 2 sec */
  252. start_int_poll_timer(php_ctlr, shpchp_poll_time);
  253. DBG_LEAVE_ROUTINE
  254. }
  255. /*
  256. * This function starts the interrupt polling timer.
  257. */
  258. static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec)
  259. {
  260. /* Clamp to sane value */
  261. if ((sec <= 0) || (sec > 60))
  262. sec = 2;
  263. php_ctlr->int_poll_timer.function = &int_poll_timeout;
  264. php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr;
  265. php_ctlr->int_poll_timer.expires = jiffies + sec * HZ;
  266. add_timer(&php_ctlr->int_poll_timer);
  267. }
  268. /*
  269. * Returns 1 if SHPC finishes executing a command within 1 sec,
  270. * otherwise returns 0.
  271. */
  272. static inline int shpc_poll_ctrl_busy(struct controller *ctrl)
  273. {
  274. int i;
  275. u16 cmd_status = shpc_readw(ctrl, CMD_STATUS);
  276. if (!(cmd_status & 0x1))
  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. cmd_status = shpc_readw(ctrl, CMD_STATUS);
  282. if (!(cmd_status & 0x1))
  283. return 1;
  284. }
  285. return 0;
  286. }
  287. static inline int shpc_wait_cmd(struct controller *ctrl)
  288. {
  289. int retval = 0;
  290. unsigned long timeout = msecs_to_jiffies(1000);
  291. int rc;
  292. if (shpchp_poll_mode)
  293. rc = shpc_poll_ctrl_busy(ctrl);
  294. else
  295. rc = wait_event_interruptible_timeout(ctrl->queue,
  296. !ctrl->cmd_busy, timeout);
  297. if (!rc) {
  298. retval = -EIO;
  299. err("Command not completed in 1000 msec\n");
  300. } else if (rc < 0) {
  301. retval = -EINTR;
  302. info("Command was interrupted by a signal\n");
  303. }
  304. ctrl->cmd_busy = 0;
  305. return retval;
  306. }
  307. static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
  308. {
  309. struct controller *ctrl = slot->ctrl;
  310. u16 cmd_status;
  311. int retval = 0;
  312. u16 temp_word;
  313. DBG_ENTER_ROUTINE
  314. mutex_lock(&slot->ctrl->cmd_lock);
  315. if (!shpc_poll_ctrl_busy(ctrl)) {
  316. /* After 1 sec and and the controller is still busy */
  317. err("%s : Controller is still busy after 1 sec.\n",
  318. __FUNCTION__);
  319. retval = -EBUSY;
  320. goto out;
  321. }
  322. ++t_slot;
  323. temp_word = (t_slot << 8) | (cmd & 0xFF);
  324. dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd);
  325. /* To make sure the Controller Busy bit is 0 before we send out the
  326. * command.
  327. */
  328. slot->ctrl->cmd_busy = 1;
  329. shpc_writew(ctrl, CMD, temp_word);
  330. /*
  331. * Wait for command completion.
  332. */
  333. retval = shpc_wait_cmd(slot->ctrl);
  334. if (retval)
  335. goto out;
  336. cmd_status = hpc_check_cmd_status(slot->ctrl);
  337. if (cmd_status) {
  338. err("%s: Failed to issued command 0x%x (error code = %d)\n",
  339. __FUNCTION__, cmd, cmd_status);
  340. retval = -EIO;
  341. }
  342. out:
  343. mutex_unlock(&slot->ctrl->cmd_lock);
  344. DBG_LEAVE_ROUTINE
  345. return retval;
  346. }
  347. static int hpc_check_cmd_status(struct controller *ctrl)
  348. {
  349. u16 cmd_status;
  350. int retval = 0;
  351. DBG_ENTER_ROUTINE
  352. cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F;
  353. switch (cmd_status >> 1) {
  354. case 0:
  355. retval = 0;
  356. break;
  357. case 1:
  358. retval = SWITCH_OPEN;
  359. err("%s: Switch opened!\n", __FUNCTION__);
  360. break;
  361. case 2:
  362. retval = INVALID_CMD;
  363. err("%s: Invalid HPC command!\n", __FUNCTION__);
  364. break;
  365. case 4:
  366. retval = INVALID_SPEED_MODE;
  367. err("%s: Invalid bus speed/mode!\n", __FUNCTION__);
  368. break;
  369. default:
  370. retval = cmd_status;
  371. }
  372. DBG_LEAVE_ROUTINE
  373. return retval;
  374. }
  375. static int hpc_get_attention_status(struct slot *slot, u8 *status)
  376. {
  377. struct controller *ctrl = slot->ctrl;
  378. u32 slot_reg;
  379. u8 state;
  380. DBG_ENTER_ROUTINE
  381. slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  382. state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT;
  383. switch (state) {
  384. case ATN_LED_STATE_ON:
  385. *status = 1; /* On */
  386. break;
  387. case ATN_LED_STATE_BLINK:
  388. *status = 2; /* Blink */
  389. break;
  390. case ATN_LED_STATE_OFF:
  391. *status = 0; /* Off */
  392. break;
  393. default:
  394. *status = 0xFF; /* Reserved */
  395. break;
  396. }
  397. DBG_LEAVE_ROUTINE
  398. return 0;
  399. }
  400. static int hpc_get_power_status(struct slot * slot, u8 *status)
  401. {
  402. struct controller *ctrl = slot->ctrl;
  403. u32 slot_reg;
  404. u8 state;
  405. DBG_ENTER_ROUTINE
  406. slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  407. state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT;
  408. switch (state) {
  409. case SLOT_STATE_PWRONLY:
  410. *status = 2; /* Powered only */
  411. break;
  412. case SLOT_STATE_ENABLED:
  413. *status = 1; /* Enabled */
  414. break;
  415. case SLOT_STATE_DISABLED:
  416. *status = 0; /* Disabled */
  417. break;
  418. default:
  419. *status = 0xFF; /* Reserved */
  420. break;
  421. }
  422. DBG_LEAVE_ROUTINE
  423. return 0;
  424. }
  425. static int hpc_get_latch_status(struct slot *slot, u8 *status)
  426. {
  427. struct controller *ctrl = slot->ctrl;
  428. u32 slot_reg;
  429. DBG_ENTER_ROUTINE
  430. slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  431. *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */
  432. DBG_LEAVE_ROUTINE
  433. return 0;
  434. }
  435. static int hpc_get_adapter_status(struct slot *slot, u8 *status)
  436. {
  437. struct controller *ctrl = slot->ctrl;
  438. u32 slot_reg;
  439. u8 state;
  440. DBG_ENTER_ROUTINE
  441. slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  442. state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT;
  443. *status = (state != 0x3) ? 1 : 0;
  444. DBG_LEAVE_ROUTINE
  445. return 0;
  446. }
  447. static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
  448. {
  449. struct controller *ctrl = slot->ctrl;
  450. DBG_ENTER_ROUTINE
  451. *prog_int = shpc_readb(ctrl, PROG_INTERFACE);
  452. DBG_LEAVE_ROUTINE
  453. return 0;
  454. }
  455. static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
  456. {
  457. int retval = 0;
  458. struct controller *ctrl = slot->ctrl;
  459. u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  460. u8 m66_cap = !!(slot_reg & MHZ66_CAP);
  461. u8 pi, pcix_cap;
  462. DBG_ENTER_ROUTINE
  463. if ((retval = hpc_get_prog_int(slot, &pi)))
  464. return retval;
  465. switch (pi) {
  466. case 1:
  467. pcix_cap = (slot_reg & PCIX_CAP_MASK_PI1) >> PCIX_CAP_SHIFT;
  468. break;
  469. case 2:
  470. pcix_cap = (slot_reg & PCIX_CAP_MASK_PI2) >> PCIX_CAP_SHIFT;
  471. break;
  472. default:
  473. return -ENODEV;
  474. }
  475. dbg("%s: slot_reg = %x, pcix_cap = %x, m66_cap = %x\n",
  476. __FUNCTION__, slot_reg, pcix_cap, m66_cap);
  477. switch (pcix_cap) {
  478. case 0x0:
  479. *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
  480. break;
  481. case 0x1:
  482. *value = PCI_SPEED_66MHz_PCIX;
  483. break;
  484. case 0x3:
  485. *value = PCI_SPEED_133MHz_PCIX;
  486. break;
  487. case 0x4:
  488. *value = PCI_SPEED_133MHz_PCIX_266;
  489. break;
  490. case 0x5:
  491. *value = PCI_SPEED_133MHz_PCIX_533;
  492. break;
  493. case 0x2:
  494. default:
  495. *value = PCI_SPEED_UNKNOWN;
  496. retval = -ENODEV;
  497. break;
  498. }
  499. dbg("Adapter speed = %d\n", *value);
  500. DBG_LEAVE_ROUTINE
  501. return retval;
  502. }
  503. static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
  504. {
  505. struct controller *ctrl = slot->ctrl;
  506. u16 sec_bus_status;
  507. u8 pi;
  508. int retval = 0;
  509. DBG_ENTER_ROUTINE
  510. pi = shpc_readb(ctrl, PROG_INTERFACE);
  511. sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG);
  512. if (pi == 2) {
  513. *mode = (sec_bus_status & 0x0100) >> 8;
  514. } else {
  515. retval = -1;
  516. }
  517. dbg("Mode 1 ECC cap = %d\n", *mode);
  518. DBG_LEAVE_ROUTINE
  519. return retval;
  520. }
  521. static int hpc_query_power_fault(struct slot * slot)
  522. {
  523. struct controller *ctrl = slot->ctrl;
  524. u32 slot_reg;
  525. DBG_ENTER_ROUTINE
  526. slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot));
  527. DBG_LEAVE_ROUTINE
  528. /* Note: Logic 0 => fault */
  529. return !(slot_reg & POWER_FAULT);
  530. }
  531. static int hpc_set_attention_status(struct slot *slot, u8 value)
  532. {
  533. u8 slot_cmd = 0;
  534. switch (value) {
  535. case 0 :
  536. slot_cmd = SET_ATTN_OFF; /* OFF */
  537. break;
  538. case 1:
  539. slot_cmd = SET_ATTN_ON; /* ON */
  540. break;
  541. case 2:
  542. slot_cmd = SET_ATTN_BLINK; /* BLINK */
  543. break;
  544. default:
  545. return -1;
  546. }
  547. return shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
  548. }
  549. static void hpc_set_green_led_on(struct slot *slot)
  550. {
  551. shpc_write_cmd(slot, slot->hp_slot, SET_PWR_ON);
  552. }
  553. static void hpc_set_green_led_off(struct slot *slot)
  554. {
  555. shpc_write_cmd(slot, slot->hp_slot, SET_PWR_OFF);
  556. }
  557. static void hpc_set_green_led_blink(struct slot *slot)
  558. {
  559. shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK);
  560. }
  561. int shpc_get_ctlr_slot_config(struct controller *ctrl,
  562. int *num_ctlr_slots, /* number of slots in this HPC */
  563. int *first_device_num, /* PCI dev num of the first slot in this SHPC */
  564. int *physical_slot_num, /* phy slot num of the first slot in this SHPC */
  565. int *updown, /* physical_slot_num increament: 1 or -1 */
  566. int *flags)
  567. {
  568. u32 slot_config;
  569. DBG_ENTER_ROUTINE
  570. slot_config = shpc_readl(ctrl, SLOT_CONFIG);
  571. *first_device_num = (slot_config & FIRST_DEV_NUM) >> 8;
  572. *num_ctlr_slots = slot_config & SLOT_NUM;
  573. *physical_slot_num = (slot_config & PSN) >> 16;
  574. *updown = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
  575. dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num);
  576. DBG_LEAVE_ROUTINE
  577. return 0;
  578. }
  579. static void hpc_release_ctlr(struct controller *ctrl)
  580. {
  581. struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
  582. struct php_ctlr_state_s *p, *p_prev;
  583. int i;
  584. u32 slot_reg, serr_int;
  585. DBG_ENTER_ROUTINE
  586. /*
  587. * Mask event interrupts and SERRs of all slots
  588. */
  589. for (i = 0; i < ctrl->num_slots; i++) {
  590. slot_reg = shpc_readl(ctrl, SLOT_REG(i));
  591. slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
  592. BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
  593. CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
  594. CON_PFAULT_SERR_MASK);
  595. slot_reg &= ~SLOT_REG_RSVDZ_MASK;
  596. shpc_writel(ctrl, SLOT_REG(i), slot_reg);
  597. }
  598. cleanup_slots(ctrl);
  599. /*
  600. * Mask SERR and System Interrut generation
  601. */
  602. serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
  603. serr_int |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
  604. COMMAND_INTR_MASK | ARBITER_SERR_MASK);
  605. serr_int &= ~SERR_INTR_RSVDZ_MASK;
  606. shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
  607. if (shpchp_poll_mode) {
  608. del_timer(&php_ctlr->int_poll_timer);
  609. } else {
  610. if (php_ctlr->irq) {
  611. free_irq(php_ctlr->irq, ctrl);
  612. php_ctlr->irq = 0;
  613. pci_disable_msi(php_ctlr->pci_dev);
  614. }
  615. }
  616. if (php_ctlr->pci_dev) {
  617. iounmap(php_ctlr->creg);
  618. release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
  619. php_ctlr->pci_dev = NULL;
  620. }
  621. spin_lock(&list_lock);
  622. p = php_ctlr_list_head;
  623. p_prev = NULL;
  624. while (p) {
  625. if (p == php_ctlr) {
  626. if (p_prev)
  627. p_prev->pnext = p->pnext;
  628. else
  629. php_ctlr_list_head = p->pnext;
  630. break;
  631. } else {
  632. p_prev = p;
  633. p = p->pnext;
  634. }
  635. }
  636. spin_unlock(&list_lock);
  637. kfree(php_ctlr);
  638. /*
  639. * If this is the last controller to be released, destroy the
  640. * shpchpd work queue
  641. */
  642. if (atomic_dec_and_test(&shpchp_num_controllers))
  643. destroy_workqueue(shpchp_wq);
  644. DBG_LEAVE_ROUTINE
  645. }
  646. static int hpc_power_on_slot(struct slot * slot)
  647. {
  648. int retval;
  649. DBG_ENTER_ROUTINE
  650. retval = shpc_write_cmd(slot, slot->hp_slot, SET_SLOT_PWR);
  651. if (retval) {
  652. err("%s: Write command failed!\n", __FUNCTION__);
  653. return retval;
  654. }
  655. DBG_LEAVE_ROUTINE
  656. return 0;
  657. }
  658. static int hpc_slot_enable(struct slot * slot)
  659. {
  660. int retval;
  661. DBG_ENTER_ROUTINE
  662. /* Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
  663. retval = shpc_write_cmd(slot, slot->hp_slot,
  664. SET_SLOT_ENABLE | SET_PWR_BLINK | SET_ATTN_OFF);
  665. if (retval) {
  666. err("%s: Write command failed!\n", __FUNCTION__);
  667. return retval;
  668. }
  669. DBG_LEAVE_ROUTINE
  670. return 0;
  671. }
  672. static int hpc_slot_disable(struct slot * slot)
  673. {
  674. int retval;
  675. DBG_ENTER_ROUTINE
  676. /* Slot - Disable, Power Indicator - Off, Attention Indicator - On */
  677. retval = shpc_write_cmd(slot, slot->hp_slot,
  678. SET_SLOT_DISABLE | SET_PWR_OFF | SET_ATTN_ON);
  679. if (retval) {
  680. err("%s: Write command failed!\n", __FUNCTION__);
  681. return retval;
  682. }
  683. DBG_LEAVE_ROUTINE
  684. return 0;
  685. }
  686. static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
  687. {
  688. int retval;
  689. struct controller *ctrl = slot->ctrl;
  690. u8 pi, cmd;
  691. DBG_ENTER_ROUTINE
  692. pi = shpc_readb(ctrl, PROG_INTERFACE);
  693. if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX))
  694. return -EINVAL;
  695. switch (value) {
  696. case PCI_SPEED_33MHz:
  697. cmd = SETA_PCI_33MHZ;
  698. break;
  699. case PCI_SPEED_66MHz:
  700. cmd = SETA_PCI_66MHZ;
  701. break;
  702. case PCI_SPEED_66MHz_PCIX:
  703. cmd = SETA_PCIX_66MHZ;
  704. break;
  705. case PCI_SPEED_100MHz_PCIX:
  706. cmd = SETA_PCIX_100MHZ;
  707. break;
  708. case PCI_SPEED_133MHz_PCIX:
  709. cmd = SETA_PCIX_133MHZ;
  710. break;
  711. case PCI_SPEED_66MHz_PCIX_ECC:
  712. cmd = SETB_PCIX_66MHZ_EM;
  713. break;
  714. case PCI_SPEED_100MHz_PCIX_ECC:
  715. cmd = SETB_PCIX_100MHZ_EM;
  716. break;
  717. case PCI_SPEED_133MHz_PCIX_ECC:
  718. cmd = SETB_PCIX_133MHZ_EM;
  719. break;
  720. case PCI_SPEED_66MHz_PCIX_266:
  721. cmd = SETB_PCIX_66MHZ_266;
  722. break;
  723. case PCI_SPEED_100MHz_PCIX_266:
  724. cmd = SETB_PCIX_100MHZ_266;
  725. break;
  726. case PCI_SPEED_133MHz_PCIX_266:
  727. cmd = SETB_PCIX_133MHZ_266;
  728. break;
  729. case PCI_SPEED_66MHz_PCIX_533:
  730. cmd = SETB_PCIX_66MHZ_533;
  731. break;
  732. case PCI_SPEED_100MHz_PCIX_533:
  733. cmd = SETB_PCIX_100MHZ_533;
  734. break;
  735. case PCI_SPEED_133MHz_PCIX_533:
  736. cmd = SETB_PCIX_133MHZ_533;
  737. break;
  738. default:
  739. return -EINVAL;
  740. }
  741. retval = shpc_write_cmd(slot, 0, cmd);
  742. if (retval)
  743. err("%s: Write command failed!\n", __FUNCTION__);
  744. DBG_LEAVE_ROUTINE
  745. return retval;
  746. }
  747. static irqreturn_t shpc_isr(int irq, void *dev_id)
  748. {
  749. struct controller *ctrl = (struct controller *)dev_id;
  750. struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
  751. u32 serr_int, slot_reg, intr_loc, intr_loc2;
  752. int hp_slot;
  753. /* Check to see if it was our interrupt */
  754. intr_loc = shpc_readl(ctrl, INTR_LOC);
  755. if (!intr_loc)
  756. return IRQ_NONE;
  757. dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc);
  758. if(!shpchp_poll_mode) {
  759. /*
  760. * Mask Global Interrupt Mask - see implementation
  761. * note on p. 139 of SHPC spec rev 1.0
  762. */
  763. serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
  764. serr_int |= GLOBAL_INTR_MASK;
  765. serr_int &= ~SERR_INTR_RSVDZ_MASK;
  766. shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
  767. intr_loc2 = shpc_readl(ctrl, INTR_LOC);
  768. dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
  769. }
  770. if (intr_loc & CMD_INTR_PENDING) {
  771. /*
  772. * Command Complete Interrupt Pending
  773. * RO only - clear by writing 1 to the Command Completion
  774. * Detect bit in Controller SERR-INT register
  775. */
  776. serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
  777. serr_int &= ~SERR_INTR_RSVDZ_MASK;
  778. shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
  779. ctrl->cmd_busy = 0;
  780. wake_up_interruptible(&ctrl->queue);
  781. }
  782. if (!(intr_loc & ~CMD_INTR_PENDING))
  783. goto out;
  784. for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
  785. /* To find out which slot has interrupt pending */
  786. if (!(intr_loc & SLOT_INTR_PENDING(hp_slot)))
  787. continue;
  788. slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
  789. dbg("%s: Slot %x with intr, slot register = %x\n",
  790. __FUNCTION__, hp_slot, slot_reg);
  791. if (slot_reg & MRL_CHANGE_DETECTED)
  792. php_ctlr->switch_change_callback(
  793. hp_slot, php_ctlr->callback_instance_id);
  794. if (slot_reg & BUTTON_PRESS_DETECTED)
  795. php_ctlr->attention_button_callback(
  796. hp_slot, php_ctlr->callback_instance_id);
  797. if (slot_reg & PRSNT_CHANGE_DETECTED)
  798. php_ctlr->presence_change_callback(
  799. hp_slot , php_ctlr->callback_instance_id);
  800. if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED))
  801. php_ctlr->power_fault_callback(
  802. hp_slot, php_ctlr->callback_instance_id);
  803. /* Clear all slot events */
  804. slot_reg &= ~SLOT_REG_RSVDZ_MASK;
  805. shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
  806. }
  807. out:
  808. if (!shpchp_poll_mode) {
  809. /* Unmask Global Interrupt Mask */
  810. serr_int = shpc_readl(ctrl, SERR_INTR_ENABLE);
  811. serr_int &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK);
  812. shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
  813. }
  814. return IRQ_HANDLED;
  815. }
  816. static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
  817. {
  818. int retval = 0;
  819. struct controller *ctrl = slot->ctrl;
  820. enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
  821. u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
  822. u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1);
  823. u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2);
  824. DBG_ENTER_ROUTINE
  825. if (pi == 2) {
  826. if (slot_avail2 & SLOT_133MHZ_PCIX_533)
  827. bus_speed = PCI_SPEED_133MHz_PCIX_533;
  828. else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
  829. bus_speed = PCI_SPEED_100MHz_PCIX_533;
  830. else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
  831. bus_speed = PCI_SPEED_66MHz_PCIX_533;
  832. else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
  833. bus_speed = PCI_SPEED_133MHz_PCIX_266;
  834. else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
  835. bus_speed = PCI_SPEED_100MHz_PCIX_266;
  836. else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
  837. bus_speed = PCI_SPEED_66MHz_PCIX_266;
  838. }
  839. if (bus_speed == PCI_SPEED_UNKNOWN) {
  840. if (slot_avail1 & SLOT_133MHZ_PCIX)
  841. bus_speed = PCI_SPEED_133MHz_PCIX;
  842. else if (slot_avail1 & SLOT_100MHZ_PCIX)
  843. bus_speed = PCI_SPEED_100MHz_PCIX;
  844. else if (slot_avail1 & SLOT_66MHZ_PCIX)
  845. bus_speed = PCI_SPEED_66MHz_PCIX;
  846. else if (slot_avail2 & SLOT_66MHZ)
  847. bus_speed = PCI_SPEED_66MHz;
  848. else if (slot_avail1 & SLOT_33MHZ)
  849. bus_speed = PCI_SPEED_33MHz;
  850. else
  851. retval = -ENODEV;
  852. }
  853. *value = bus_speed;
  854. dbg("Max bus speed = %d\n", bus_speed);
  855. DBG_LEAVE_ROUTINE
  856. return retval;
  857. }
  858. static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
  859. {
  860. int retval = 0;
  861. struct controller *ctrl = slot->ctrl;
  862. enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
  863. u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG);
  864. u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
  865. u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
  866. DBG_ENTER_ROUTINE
  867. if ((pi == 1) && (speed_mode > 4)) {
  868. *value = PCI_SPEED_UNKNOWN;
  869. return -ENODEV;
  870. }
  871. switch (speed_mode) {
  872. case 0x0:
  873. *value = PCI_SPEED_33MHz;
  874. break;
  875. case 0x1:
  876. *value = PCI_SPEED_66MHz;
  877. break;
  878. case 0x2:
  879. *value = PCI_SPEED_66MHz_PCIX;
  880. break;
  881. case 0x3:
  882. *value = PCI_SPEED_100MHz_PCIX;
  883. break;
  884. case 0x4:
  885. *value = PCI_SPEED_133MHz_PCIX;
  886. break;
  887. case 0x5:
  888. *value = PCI_SPEED_66MHz_PCIX_ECC;
  889. break;
  890. case 0x6:
  891. *value = PCI_SPEED_100MHz_PCIX_ECC;
  892. break;
  893. case 0x7:
  894. *value = PCI_SPEED_133MHz_PCIX_ECC;
  895. break;
  896. case 0x8:
  897. *value = PCI_SPEED_66MHz_PCIX_266;
  898. break;
  899. case 0x9:
  900. *value = PCI_SPEED_100MHz_PCIX_266;
  901. break;
  902. case 0xa:
  903. *value = PCI_SPEED_133MHz_PCIX_266;
  904. break;
  905. case 0xb:
  906. *value = PCI_SPEED_66MHz_PCIX_533;
  907. break;
  908. case 0xc:
  909. *value = PCI_SPEED_100MHz_PCIX_533;
  910. break;
  911. case 0xd:
  912. *value = PCI_SPEED_133MHz_PCIX_533;
  913. break;
  914. default:
  915. *value = PCI_SPEED_UNKNOWN;
  916. retval = -ENODEV;
  917. break;
  918. }
  919. dbg("Current bus speed = %d\n", bus_speed);
  920. DBG_LEAVE_ROUTINE
  921. return retval;
  922. }
  923. static struct hpc_ops shpchp_hpc_ops = {
  924. .power_on_slot = hpc_power_on_slot,
  925. .slot_enable = hpc_slot_enable,
  926. .slot_disable = hpc_slot_disable,
  927. .set_bus_speed_mode = hpc_set_bus_speed_mode,
  928. .set_attention_status = hpc_set_attention_status,
  929. .get_power_status = hpc_get_power_status,
  930. .get_attention_status = hpc_get_attention_status,
  931. .get_latch_status = hpc_get_latch_status,
  932. .get_adapter_status = hpc_get_adapter_status,
  933. .get_max_bus_speed = hpc_get_max_bus_speed,
  934. .get_cur_bus_speed = hpc_get_cur_bus_speed,
  935. .get_adapter_speed = hpc_get_adapter_speed,
  936. .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
  937. .get_prog_int = hpc_get_prog_int,
  938. .query_power_fault = hpc_query_power_fault,
  939. .green_led_on = hpc_set_green_led_on,
  940. .green_led_off = hpc_set_green_led_off,
  941. .green_led_blink = hpc_set_green_led_blink,
  942. .release_ctlr = hpc_release_ctlr,
  943. };
  944. int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
  945. {
  946. struct php_ctlr_state_s *php_ctlr, *p;
  947. void *instance_id = ctrl;
  948. int rc, num_slots = 0;
  949. u8 hp_slot;
  950. u32 shpc_base_offset;
  951. u32 tempdword, slot_reg, slot_config;
  952. u8 i;
  953. DBG_ENTER_ROUTINE
  954. ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
  955. spin_lock_init(&list_lock);
  956. php_ctlr = kzalloc(sizeof(*php_ctlr), GFP_KERNEL);
  957. if (!php_ctlr) { /* allocate controller state data */
  958. err("%s: HPC controller memory allocation error!\n", __FUNCTION__);
  959. goto abort;
  960. }
  961. php_ctlr->pci_dev = pdev; /* save pci_dev in context */
  962. if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
  963. PCI_DEVICE_ID_AMD_GOLAM_7450)) {
  964. /* amd shpc driver doesn't use Base Offset; assume 0 */
  965. ctrl->mmio_base = pci_resource_start(pdev, 0);
  966. ctrl->mmio_size = pci_resource_len(pdev, 0);
  967. } else {
  968. ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
  969. if (!ctrl->cap_offset) {
  970. err("%s : cap_offset == 0\n", __FUNCTION__);
  971. goto abort_free_ctlr;
  972. }
  973. dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
  974. rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
  975. if (rc) {
  976. err("%s: cannot read base_offset\n", __FUNCTION__);
  977. goto abort_free_ctlr;
  978. }
  979. rc = shpc_indirect_read(ctrl, 3, &tempdword);
  980. if (rc) {
  981. err("%s: cannot read slot config\n", __FUNCTION__);
  982. goto abort_free_ctlr;
  983. }
  984. num_slots = tempdword & SLOT_NUM;
  985. dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
  986. for (i = 0; i < 9 + num_slots; i++) {
  987. rc = shpc_indirect_read(ctrl, i, &tempdword);
  988. if (rc) {
  989. err("%s: cannot read creg (index = %d)\n",
  990. __FUNCTION__, i);
  991. goto abort_free_ctlr;
  992. }
  993. dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
  994. tempdword);
  995. }
  996. ctrl->mmio_base =
  997. pci_resource_start(pdev, 0) + shpc_base_offset;
  998. ctrl->mmio_size = 0x24 + 0x4 * num_slots;
  999. }
  1000. info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
  1001. pdev->subsystem_device);
  1002. if (pci_enable_device(pdev))
  1003. goto abort_free_ctlr;
  1004. if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
  1005. err("%s: cannot reserve MMIO region\n", __FUNCTION__);
  1006. goto abort_free_ctlr;
  1007. }
  1008. php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
  1009. if (!php_ctlr->creg) {
  1010. err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
  1011. ctrl->mmio_size, ctrl->mmio_base);
  1012. release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
  1013. goto abort_free_ctlr;
  1014. }
  1015. dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
  1016. mutex_init(&ctrl->crit_sect);
  1017. mutex_init(&ctrl->cmd_lock);
  1018. /* Setup wait queue */
  1019. init_waitqueue_head(&ctrl->queue);
  1020. /* Find the IRQ */
  1021. php_ctlr->irq = pdev->irq;
  1022. php_ctlr->attention_button_callback = shpchp_handle_attention_button,
  1023. php_ctlr->switch_change_callback = shpchp_handle_switch_change;
  1024. php_ctlr->presence_change_callback = shpchp_handle_presence_change;
  1025. php_ctlr->power_fault_callback = shpchp_handle_power_fault;
  1026. php_ctlr->callback_instance_id = instance_id;
  1027. ctrl->hpc_ctlr_handle = php_ctlr;
  1028. ctrl->hpc_ops = &shpchp_hpc_ops;
  1029. /* Return PCI Controller Info */
  1030. slot_config = shpc_readl(ctrl, SLOT_CONFIG);
  1031. php_ctlr->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8;
  1032. php_ctlr->num_slots = slot_config & SLOT_NUM;
  1033. dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset);
  1034. dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots);
  1035. /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
  1036. tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
  1037. dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
  1038. tempdword |= (GLOBAL_INTR_MASK | GLOBAL_SERR_MASK |
  1039. COMMAND_INTR_MASK | ARBITER_SERR_MASK);
  1040. tempdword &= ~SERR_INTR_RSVDZ_MASK;
  1041. shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
  1042. tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
  1043. dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
  1044. /* Mask the MRL sensor SERR Mask of individual slot in
  1045. * Slot SERR-INT Mask & clear all the existing event if any
  1046. */
  1047. for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
  1048. slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
  1049. dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
  1050. hp_slot, slot_reg);
  1051. slot_reg |= (PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
  1052. BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
  1053. CON_PFAULT_INTR_MASK | MRL_CHANGE_SERR_MASK |
  1054. CON_PFAULT_SERR_MASK);
  1055. slot_reg &= ~SLOT_REG_RSVDZ_MASK;
  1056. shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
  1057. }
  1058. if (shpchp_poll_mode) {/* Install interrupt polling code */
  1059. /* Install and start the interrupt polling timer */
  1060. init_timer(&php_ctlr->int_poll_timer);
  1061. start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */
  1062. } else {
  1063. /* Installs the interrupt handler */
  1064. rc = pci_enable_msi(pdev);
  1065. if (rc) {
  1066. info("Can't get msi for the hotplug controller\n");
  1067. info("Use INTx for the hotplug controller\n");
  1068. } else
  1069. php_ctlr->irq = pdev->irq;
  1070. rc = request_irq(php_ctlr->irq, shpc_isr, IRQF_SHARED, MY_NAME, (void *) ctrl);
  1071. dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc);
  1072. if (rc) {
  1073. err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);
  1074. goto abort_free_ctlr;
  1075. }
  1076. }
  1077. dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
  1078. pdev->bus->number, PCI_SLOT(pdev->devfn),
  1079. PCI_FUNC(pdev->devfn), pdev->irq);
  1080. get_hp_hw_control_from_firmware(pdev);
  1081. /* Add this HPC instance into the HPC list */
  1082. spin_lock(&list_lock);
  1083. if (php_ctlr_list_head == 0) {
  1084. php_ctlr_list_head = php_ctlr;
  1085. p = php_ctlr_list_head;
  1086. p->pnext = NULL;
  1087. } else {
  1088. p = php_ctlr_list_head;
  1089. while (p->pnext)
  1090. p = p->pnext;
  1091. p->pnext = php_ctlr;
  1092. }
  1093. spin_unlock(&list_lock);
  1094. ctlr_seq_num++;
  1095. /*
  1096. * If this is the first controller to be initialized,
  1097. * initialize the shpchpd work queue
  1098. */
  1099. if (atomic_add_return(1, &shpchp_num_controllers) == 1) {
  1100. shpchp_wq = create_singlethread_workqueue("shpchpd");
  1101. if (!shpchp_wq)
  1102. return -ENOMEM;
  1103. }
  1104. /*
  1105. * Unmask all event interrupts of all slots
  1106. */
  1107. for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
  1108. slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
  1109. dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
  1110. hp_slot, slot_reg);
  1111. slot_reg &= ~(PRSNT_CHANGE_INTR_MASK | ISO_PFAULT_INTR_MASK |
  1112. BUTTON_PRESS_INTR_MASK | MRL_CHANGE_INTR_MASK |
  1113. CON_PFAULT_INTR_MASK | SLOT_REG_RSVDZ_MASK);
  1114. shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
  1115. }
  1116. if (!shpchp_poll_mode) {
  1117. /* Unmask all general input interrupts and SERR */
  1118. tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
  1119. tempdword &= ~(GLOBAL_INTR_MASK | COMMAND_INTR_MASK |
  1120. SERR_INTR_RSVDZ_MASK);
  1121. shpc_writel(ctrl, SERR_INTR_ENABLE, tempdword);
  1122. tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
  1123. dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
  1124. }
  1125. DBG_LEAVE_ROUTINE
  1126. return 0;
  1127. /* We end up here for the many possible ways to fail this API. */
  1128. abort_free_ctlr:
  1129. kfree(php_ctlr);
  1130. abort:
  1131. DBG_LEAVE_ROUTINE
  1132. return -1;
  1133. }