shpchp_hpc.c 36 KB

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