shpchp_hpc.c 38 KB

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