shpchp_hpc.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565
  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 inline int shpc_wait_cmd(struct controller *ctrl)
  228. {
  229. int retval = 0;
  230. unsigned int timeout_msec = shpchp_poll_mode ? 2000 : 1000;
  231. unsigned long timeout = msecs_to_jiffies(timeout_msec);
  232. int rc = wait_event_interruptible_timeout(ctrl->queue,
  233. !ctrl->cmd_busy, timeout);
  234. if (!rc) {
  235. retval = -EIO;
  236. err("Command not completed in %d msec\n", timeout_msec);
  237. } else if (rc < 0) {
  238. retval = -EINTR;
  239. info("Command was interrupted by a signal\n");
  240. }
  241. ctrl->cmd_busy = 0;
  242. return retval;
  243. }
  244. static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
  245. {
  246. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  247. u16 cmd_status;
  248. int retval = 0;
  249. u16 temp_word;
  250. int i;
  251. DBG_ENTER_ROUTINE
  252. if (!php_ctlr) {
  253. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  254. return -1;
  255. }
  256. for (i = 0; i < 10; i++) {
  257. cmd_status = readw(php_ctlr->creg + CMD_STATUS);
  258. if (!(cmd_status & 0x1))
  259. break;
  260. /* Check every 0.1 sec for a total of 1 sec*/
  261. msleep(100);
  262. }
  263. cmd_status = readw(php_ctlr->creg + CMD_STATUS);
  264. if (cmd_status & 0x1) {
  265. /* After 1 sec and and the controller is still busy */
  266. err("%s : Controller is still busy after 1 sec.\n", __FUNCTION__);
  267. return -1;
  268. }
  269. ++t_slot;
  270. temp_word = (t_slot << 8) | (cmd & 0xFF);
  271. dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd);
  272. /* To make sure the Controller Busy bit is 0 before we send out the
  273. * command.
  274. */
  275. slot->ctrl->cmd_busy = 1;
  276. writew(temp_word, php_ctlr->creg + CMD);
  277. /*
  278. * Wait for command completion.
  279. */
  280. retval = shpc_wait_cmd(slot->ctrl);
  281. DBG_LEAVE_ROUTINE
  282. return retval;
  283. }
  284. static int hpc_check_cmd_status(struct controller *ctrl)
  285. {
  286. struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
  287. u16 cmd_status;
  288. int retval = 0;
  289. DBG_ENTER_ROUTINE
  290. if (!ctrl->hpc_ctlr_handle) {
  291. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  292. return -1;
  293. }
  294. cmd_status = readw(php_ctlr->creg + CMD_STATUS) & 0x000F;
  295. switch (cmd_status >> 1) {
  296. case 0:
  297. retval = 0;
  298. break;
  299. case 1:
  300. retval = SWITCH_OPEN;
  301. err("%s: Switch opened!\n", __FUNCTION__);
  302. break;
  303. case 2:
  304. retval = INVALID_CMD;
  305. err("%s: Invalid HPC command!\n", __FUNCTION__);
  306. break;
  307. case 4:
  308. retval = INVALID_SPEED_MODE;
  309. err("%s: Invalid bus speed/mode!\n", __FUNCTION__);
  310. break;
  311. default:
  312. retval = cmd_status;
  313. }
  314. DBG_LEAVE_ROUTINE
  315. return retval;
  316. }
  317. static int hpc_get_attention_status(struct slot *slot, u8 *status)
  318. {
  319. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  320. u32 slot_reg;
  321. u16 slot_status;
  322. u8 atten_led_state;
  323. DBG_ENTER_ROUTINE
  324. if (!slot->ctrl->hpc_ctlr_handle) {
  325. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  326. return -1;
  327. }
  328. slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
  329. slot_status = (u16) slot_reg;
  330. atten_led_state = (slot_status & 0x0030) >> 4;
  331. switch (atten_led_state) {
  332. case 0:
  333. *status = 0xFF; /* Reserved */
  334. break;
  335. case 1:
  336. *status = 1; /* On */
  337. break;
  338. case 2:
  339. *status = 2; /* Blink */
  340. break;
  341. case 3:
  342. *status = 0; /* Off */
  343. break;
  344. default:
  345. *status = 0xFF;
  346. break;
  347. }
  348. DBG_LEAVE_ROUTINE
  349. return 0;
  350. }
  351. static int hpc_get_power_status(struct slot * slot, u8 *status)
  352. {
  353. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  354. u32 slot_reg;
  355. u16 slot_status;
  356. u8 slot_state;
  357. int retval = 0;
  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 = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
  364. slot_status = (u16) slot_reg;
  365. slot_state = (slot_status & 0x0003);
  366. switch (slot_state) {
  367. case 0:
  368. *status = 0xFF;
  369. break;
  370. case 1:
  371. *status = 2; /* Powered only */
  372. break;
  373. case 2:
  374. *status = 1; /* Enabled */
  375. break;
  376. case 3:
  377. *status = 0; /* Disabled */
  378. break;
  379. default:
  380. *status = 0xFF;
  381. break;
  382. }
  383. DBG_LEAVE_ROUTINE
  384. return retval;
  385. }
  386. static int hpc_get_latch_status(struct slot *slot, u8 *status)
  387. {
  388. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  389. u32 slot_reg;
  390. u16 slot_status;
  391. DBG_ENTER_ROUTINE
  392. if (!slot->ctrl->hpc_ctlr_handle) {
  393. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  394. return -1;
  395. }
  396. slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
  397. slot_status = (u16)slot_reg;
  398. *status = ((slot_status & 0x0100) == 0) ? 0 : 1; /* 0 -> close; 1 -> open */
  399. DBG_LEAVE_ROUTINE
  400. return 0;
  401. }
  402. static int hpc_get_adapter_status(struct slot *slot, u8 *status)
  403. {
  404. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  405. u32 slot_reg;
  406. u16 slot_status;
  407. u8 card_state;
  408. DBG_ENTER_ROUTINE
  409. if (!slot->ctrl->hpc_ctlr_handle) {
  410. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  411. return -1;
  412. }
  413. slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
  414. slot_status = (u16)slot_reg;
  415. card_state = (u8)((slot_status & 0x0C00) >> 10);
  416. *status = (card_state != 0x3) ? 1 : 0;
  417. DBG_LEAVE_ROUTINE
  418. return 0;
  419. }
  420. static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
  421. {
  422. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  423. DBG_ENTER_ROUTINE
  424. if (!slot->ctrl->hpc_ctlr_handle) {
  425. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  426. return -1;
  427. }
  428. *prog_int = readb(php_ctlr->creg + PROG_INTERFACE);
  429. DBG_LEAVE_ROUTINE
  430. return 0;
  431. }
  432. static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
  433. {
  434. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  435. u32 slot_reg;
  436. u16 slot_status, sec_bus_status;
  437. u8 m66_cap, pcix_cap, pi;
  438. int retval = 0;
  439. DBG_ENTER_ROUTINE
  440. if (!slot->ctrl->hpc_ctlr_handle) {
  441. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  442. return -1;
  443. }
  444. if (slot->hp_slot >= php_ctlr->num_slots) {
  445. err("%s: Invalid HPC slot number!\n", __FUNCTION__);
  446. return -1;
  447. }
  448. pi = readb(php_ctlr->creg + PROG_INTERFACE);
  449. slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
  450. dbg("%s: pi = %d, slot_reg = %x\n", __FUNCTION__, pi, slot_reg);
  451. slot_status = (u16) slot_reg;
  452. dbg("%s: slot_status = %x\n", __FUNCTION__, slot_status);
  453. sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
  454. pcix_cap = (u8) ((slot_status & 0x3000) >> 12);
  455. dbg("%s: pcix_cap = %x\n", __FUNCTION__, pcix_cap);
  456. m66_cap = (u8) ((slot_status & 0x0200) >> 9);
  457. dbg("%s: m66_cap = %x\n", __FUNCTION__, m66_cap);
  458. if (pi == 2) {
  459. switch (pcix_cap) {
  460. case 0:
  461. *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
  462. break;
  463. case 1:
  464. *value = PCI_SPEED_66MHz_PCIX;
  465. break;
  466. case 3:
  467. *value = PCI_SPEED_133MHz_PCIX;
  468. break;
  469. case 4:
  470. *value = PCI_SPEED_133MHz_PCIX_266;
  471. break;
  472. case 5:
  473. *value = PCI_SPEED_133MHz_PCIX_533;
  474. break;
  475. case 2: /* Reserved */
  476. default:
  477. *value = PCI_SPEED_UNKNOWN;
  478. retval = -ENODEV;
  479. break;
  480. }
  481. } else {
  482. switch (pcix_cap) {
  483. case 0:
  484. *value = m66_cap ? PCI_SPEED_66MHz : PCI_SPEED_33MHz;
  485. break;
  486. case 1:
  487. *value = PCI_SPEED_66MHz_PCIX;
  488. break;
  489. case 3:
  490. *value = PCI_SPEED_133MHz_PCIX;
  491. break;
  492. case 2: /* Reserved */
  493. default:
  494. *value = PCI_SPEED_UNKNOWN;
  495. retval = -ENODEV;
  496. break;
  497. }
  498. }
  499. dbg("Adapter speed = %d\n", *value);
  500. DBG_LEAVE_ROUTINE
  501. return retval;
  502. }
  503. static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
  504. {
  505. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  506. u16 sec_bus_status;
  507. u8 pi;
  508. int retval = 0;
  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. pi = readb(php_ctlr->creg + PROG_INTERFACE);
  515. sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
  516. if (pi == 2) {
  517. *mode = (sec_bus_status & 0x0100) >> 8;
  518. } else {
  519. retval = -1;
  520. }
  521. dbg("Mode 1 ECC cap = %d\n", *mode);
  522. DBG_LEAVE_ROUTINE
  523. return retval;
  524. }
  525. static int hpc_query_power_fault(struct slot * slot)
  526. {
  527. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  528. u32 slot_reg;
  529. u16 slot_status;
  530. u8 pwr_fault_state, status;
  531. DBG_ENTER_ROUTINE
  532. if (!slot->ctrl->hpc_ctlr_handle) {
  533. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  534. return -1;
  535. }
  536. slot_reg = readl(php_ctlr->creg + SLOT1 + 4*(slot->hp_slot));
  537. slot_status = (u16) slot_reg;
  538. pwr_fault_state = (slot_status & 0x0040) >> 7;
  539. status = (pwr_fault_state == 1) ? 0 : 1;
  540. DBG_LEAVE_ROUTINE
  541. /* Note: Logic 0 => fault */
  542. return status;
  543. }
  544. static int hpc_set_attention_status(struct slot *slot, u8 value)
  545. {
  546. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  547. u8 slot_cmd = 0;
  548. int rc = 0;
  549. if (!slot->ctrl->hpc_ctlr_handle) {
  550. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  551. return -1;
  552. }
  553. if (slot->hp_slot >= php_ctlr->num_slots) {
  554. err("%s: Invalid HPC slot number!\n", __FUNCTION__);
  555. return -1;
  556. }
  557. switch (value) {
  558. case 0 :
  559. slot_cmd = 0x30; /* OFF */
  560. break;
  561. case 1:
  562. slot_cmd = 0x10; /* ON */
  563. break;
  564. case 2:
  565. slot_cmd = 0x20; /* BLINK */
  566. break;
  567. default:
  568. return -1;
  569. }
  570. shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
  571. return rc;
  572. }
  573. static void hpc_set_green_led_on(struct slot *slot)
  574. {
  575. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  576. u8 slot_cmd;
  577. if (!slot->ctrl->hpc_ctlr_handle) {
  578. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  579. return ;
  580. }
  581. if (slot->hp_slot >= php_ctlr->num_slots) {
  582. err("%s: Invalid HPC slot number!\n", __FUNCTION__);
  583. return ;
  584. }
  585. slot_cmd = 0x04;
  586. shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
  587. return;
  588. }
  589. static void hpc_set_green_led_off(struct slot *slot)
  590. {
  591. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  592. u8 slot_cmd;
  593. if (!slot->ctrl->hpc_ctlr_handle) {
  594. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  595. return ;
  596. }
  597. if (slot->hp_slot >= php_ctlr->num_slots) {
  598. err("%s: Invalid HPC slot number!\n", __FUNCTION__);
  599. return ;
  600. }
  601. slot_cmd = 0x0C;
  602. shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
  603. return;
  604. }
  605. static void hpc_set_green_led_blink(struct slot *slot)
  606. {
  607. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  608. u8 slot_cmd;
  609. if (!slot->ctrl->hpc_ctlr_handle) {
  610. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  611. return ;
  612. }
  613. if (slot->hp_slot >= php_ctlr->num_slots) {
  614. err("%s: Invalid HPC slot number!\n", __FUNCTION__);
  615. return ;
  616. }
  617. slot_cmd = 0x08;
  618. shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
  619. return;
  620. }
  621. int shpc_get_ctlr_slot_config(struct controller *ctrl,
  622. int *num_ctlr_slots, /* number of slots in this HPC */
  623. int *first_device_num, /* PCI dev num of the first slot in this SHPC */
  624. int *physical_slot_num, /* phy slot num of the first slot in this SHPC */
  625. int *updown, /* physical_slot_num increament: 1 or -1 */
  626. int *flags)
  627. {
  628. struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
  629. DBG_ENTER_ROUTINE
  630. if (!ctrl->hpc_ctlr_handle) {
  631. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  632. return -1;
  633. }
  634. *first_device_num = php_ctlr->slot_device_offset; /* Obtained in shpc_init() */
  635. *num_ctlr_slots = php_ctlr->num_slots; /* Obtained in shpc_init() */
  636. *physical_slot_num = (readl(php_ctlr->creg + SLOT_CONFIG) & PSN) >> 16;
  637. dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num);
  638. *updown = ((readl(php_ctlr->creg + SLOT_CONFIG) & UPDOWN ) >> 29) ? 1 : -1;
  639. DBG_LEAVE_ROUTINE
  640. return 0;
  641. }
  642. static void hpc_release_ctlr(struct controller *ctrl)
  643. {
  644. struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
  645. struct php_ctlr_state_s *p, *p_prev;
  646. DBG_ENTER_ROUTINE
  647. if (!ctrl->hpc_ctlr_handle) {
  648. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  649. return ;
  650. }
  651. if (shpchp_poll_mode) {
  652. del_timer(&php_ctlr->int_poll_timer);
  653. } else {
  654. if (php_ctlr->irq) {
  655. free_irq(php_ctlr->irq, ctrl);
  656. php_ctlr->irq = 0;
  657. pci_disable_msi(php_ctlr->pci_dev);
  658. }
  659. }
  660. if (php_ctlr->pci_dev) {
  661. iounmap(php_ctlr->creg);
  662. release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
  663. php_ctlr->pci_dev = NULL;
  664. }
  665. spin_lock(&list_lock);
  666. p = php_ctlr_list_head;
  667. p_prev = NULL;
  668. while (p) {
  669. if (p == php_ctlr) {
  670. if (p_prev)
  671. p_prev->pnext = p->pnext;
  672. else
  673. php_ctlr_list_head = p->pnext;
  674. break;
  675. } else {
  676. p_prev = p;
  677. p = p->pnext;
  678. }
  679. }
  680. spin_unlock(&list_lock);
  681. kfree(php_ctlr);
  682. DBG_LEAVE_ROUTINE
  683. }
  684. static int hpc_power_on_slot(struct slot * slot)
  685. {
  686. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  687. u8 slot_cmd;
  688. int retval = 0;
  689. DBG_ENTER_ROUTINE
  690. if (!slot->ctrl->hpc_ctlr_handle) {
  691. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  692. return -1;
  693. }
  694. if (slot->hp_slot >= php_ctlr->num_slots) {
  695. err("%s: Invalid HPC slot number!\n", __FUNCTION__);
  696. return -1;
  697. }
  698. slot_cmd = 0x01;
  699. retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
  700. if (retval) {
  701. err("%s: Write command failed!\n", __FUNCTION__);
  702. return -1;
  703. }
  704. DBG_LEAVE_ROUTINE
  705. return retval;
  706. }
  707. static int hpc_slot_enable(struct slot * slot)
  708. {
  709. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  710. u8 slot_cmd;
  711. int retval = 0;
  712. DBG_ENTER_ROUTINE
  713. if (!slot->ctrl->hpc_ctlr_handle) {
  714. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  715. return -1;
  716. }
  717. if (slot->hp_slot >= php_ctlr->num_slots) {
  718. err("%s: Invalid HPC slot number!\n", __FUNCTION__);
  719. return -1;
  720. }
  721. /* 3A => Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */
  722. slot_cmd = 0x3A;
  723. retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
  724. if (retval) {
  725. err("%s: Write command failed!\n", __FUNCTION__);
  726. return -1;
  727. }
  728. DBG_LEAVE_ROUTINE
  729. return retval;
  730. }
  731. static int hpc_slot_disable(struct slot * slot)
  732. {
  733. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  734. u8 slot_cmd;
  735. int retval = 0;
  736. DBG_ENTER_ROUTINE
  737. if (!slot->ctrl->hpc_ctlr_handle) {
  738. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  739. return -1;
  740. }
  741. if (slot->hp_slot >= php_ctlr->num_slots) {
  742. err("%s: Invalid HPC slot number!\n", __FUNCTION__);
  743. return -1;
  744. }
  745. /* 1F => Slot - Disable, Power Indicator - Off, Attention Indicator - On */
  746. slot_cmd = 0x1F;
  747. retval = shpc_write_cmd(slot, slot->hp_slot, slot_cmd);
  748. if (retval) {
  749. err("%s: Write command failed!\n", __FUNCTION__);
  750. return -1;
  751. }
  752. DBG_LEAVE_ROUTINE
  753. return retval;
  754. }
  755. static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
  756. {
  757. u8 slot_cmd;
  758. u8 pi;
  759. int retval = 0;
  760. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  761. DBG_ENTER_ROUTINE
  762. if (!slot->ctrl->hpc_ctlr_handle) {
  763. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  764. return -1;
  765. }
  766. pi = readb(php_ctlr->creg + PROG_INTERFACE);
  767. if (pi == 1) {
  768. switch (value) {
  769. case 0:
  770. slot_cmd = SETA_PCI_33MHZ;
  771. break;
  772. case 1:
  773. slot_cmd = SETA_PCI_66MHZ;
  774. break;
  775. case 2:
  776. slot_cmd = SETA_PCIX_66MHZ;
  777. break;
  778. case 3:
  779. slot_cmd = SETA_PCIX_100MHZ;
  780. break;
  781. case 4:
  782. slot_cmd = SETA_PCIX_133MHZ;
  783. break;
  784. default:
  785. slot_cmd = PCI_SPEED_UNKNOWN;
  786. retval = -ENODEV;
  787. return retval;
  788. }
  789. } else {
  790. switch (value) {
  791. case 0:
  792. slot_cmd = SETB_PCI_33MHZ;
  793. break;
  794. case 1:
  795. slot_cmd = SETB_PCI_66MHZ;
  796. break;
  797. case 2:
  798. slot_cmd = SETB_PCIX_66MHZ_PM;
  799. break;
  800. case 3:
  801. slot_cmd = SETB_PCIX_100MHZ_PM;
  802. break;
  803. case 4:
  804. slot_cmd = SETB_PCIX_133MHZ_PM;
  805. break;
  806. case 5:
  807. slot_cmd = SETB_PCIX_66MHZ_EM;
  808. break;
  809. case 6:
  810. slot_cmd = SETB_PCIX_100MHZ_EM;
  811. break;
  812. case 7:
  813. slot_cmd = SETB_PCIX_133MHZ_EM;
  814. break;
  815. case 8:
  816. slot_cmd = SETB_PCIX_66MHZ_266;
  817. break;
  818. case 0x9:
  819. slot_cmd = SETB_PCIX_100MHZ_266;
  820. break;
  821. case 0xa:
  822. slot_cmd = SETB_PCIX_133MHZ_266;
  823. break;
  824. case 0xb:
  825. slot_cmd = SETB_PCIX_66MHZ_533;
  826. break;
  827. case 0xc:
  828. slot_cmd = SETB_PCIX_100MHZ_533;
  829. break;
  830. case 0xd:
  831. slot_cmd = SETB_PCIX_133MHZ_533;
  832. break;
  833. default:
  834. slot_cmd = PCI_SPEED_UNKNOWN;
  835. retval = -ENODEV;
  836. return retval;
  837. }
  838. }
  839. retval = shpc_write_cmd(slot, 0, slot_cmd);
  840. if (retval) {
  841. err("%s: Write command failed!\n", __FUNCTION__);
  842. return -1;
  843. }
  844. DBG_LEAVE_ROUTINE
  845. return retval;
  846. }
  847. static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
  848. {
  849. struct controller *ctrl = NULL;
  850. struct php_ctlr_state_s *php_ctlr;
  851. u8 schedule_flag = 0;
  852. u8 temp_byte;
  853. u32 temp_dword, intr_loc, intr_loc2;
  854. int hp_slot;
  855. if (!dev_id)
  856. return IRQ_NONE;
  857. if (!shpchp_poll_mode) {
  858. ctrl = (struct controller *)dev_id;
  859. php_ctlr = ctrl->hpc_ctlr_handle;
  860. } else {
  861. php_ctlr = (struct php_ctlr_state_s *) dev_id;
  862. ctrl = (struct controller *)php_ctlr->callback_instance_id;
  863. }
  864. if (!ctrl)
  865. return IRQ_NONE;
  866. if (!php_ctlr || !php_ctlr->creg)
  867. return IRQ_NONE;
  868. /* Check to see if it was our interrupt */
  869. intr_loc = readl(php_ctlr->creg + INTR_LOC);
  870. if (!intr_loc)
  871. return IRQ_NONE;
  872. dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc);
  873. if(!shpchp_poll_mode) {
  874. /* Mask Global Interrupt Mask - see implementation note on p. 139 */
  875. /* of SHPC spec rev 1.0*/
  876. temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
  877. temp_dword |= 0x00000001;
  878. writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
  879. intr_loc2 = readl(php_ctlr->creg + INTR_LOC);
  880. dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
  881. }
  882. if (intr_loc & 0x0001) {
  883. /*
  884. * Command Complete Interrupt Pending
  885. * RO only - clear by writing 1 to the Command Completion
  886. * Detect bit in Controller SERR-INT register
  887. */
  888. temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
  889. temp_dword &= 0xfffdffff;
  890. writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
  891. ctrl->cmd_busy = 0;
  892. wake_up_interruptible(&ctrl->queue);
  893. }
  894. if ((intr_loc = (intr_loc >> 1)) == 0) {
  895. /* Unmask Global Interrupt Mask */
  896. temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
  897. temp_dword &= 0xfffffffe;
  898. writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
  899. return IRQ_NONE;
  900. }
  901. for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
  902. /* To find out which slot has interrupt pending */
  903. if ((intr_loc >> hp_slot) & 0x01) {
  904. temp_dword = readl(php_ctlr->creg + SLOT1 + (4*hp_slot));
  905. dbg("%s: Slot %x with intr, slot register = %x\n",
  906. __FUNCTION__, hp_slot, temp_dword);
  907. temp_byte = (temp_dword >> 16) & 0xFF;
  908. if ((php_ctlr->switch_change_callback) && (temp_byte & 0x08))
  909. schedule_flag += php_ctlr->switch_change_callback(
  910. hp_slot, php_ctlr->callback_instance_id);
  911. if ((php_ctlr->attention_button_callback) && (temp_byte & 0x04))
  912. schedule_flag += php_ctlr->attention_button_callback(
  913. hp_slot, php_ctlr->callback_instance_id);
  914. if ((php_ctlr->presence_change_callback) && (temp_byte & 0x01))
  915. schedule_flag += php_ctlr->presence_change_callback(
  916. hp_slot , php_ctlr->callback_instance_id);
  917. if ((php_ctlr->power_fault_callback) && (temp_byte & 0x12))
  918. schedule_flag += php_ctlr->power_fault_callback(
  919. hp_slot, php_ctlr->callback_instance_id);
  920. /* Clear all slot events */
  921. temp_dword = 0xe01f3fff;
  922. writel(temp_dword, php_ctlr->creg + SLOT1 + (4*hp_slot));
  923. intr_loc2 = readl(php_ctlr->creg + INTR_LOC);
  924. dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2);
  925. }
  926. }
  927. if (!shpchp_poll_mode) {
  928. /* Unmask Global Interrupt Mask */
  929. temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
  930. temp_dword &= 0xfffffffe;
  931. writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
  932. }
  933. return IRQ_HANDLED;
  934. }
  935. static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
  936. {
  937. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  938. enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
  939. int retval = 0;
  940. u8 pi;
  941. u32 slot_avail1, slot_avail2;
  942. DBG_ENTER_ROUTINE
  943. if (!slot->ctrl->hpc_ctlr_handle) {
  944. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  945. return -1;
  946. }
  947. if (slot->hp_slot >= php_ctlr->num_slots) {
  948. err("%s: Invalid HPC slot number!\n", __FUNCTION__);
  949. return -1;
  950. }
  951. pi = readb(php_ctlr->creg + PROG_INTERFACE);
  952. slot_avail1 = readl(php_ctlr->creg + SLOT_AVAIL1);
  953. slot_avail2 = readl(php_ctlr->creg + SLOT_AVAIL2);
  954. if (pi == 2) {
  955. if (slot_avail2 & SLOT_133MHZ_PCIX_533)
  956. bus_speed = PCIX_133MHZ_533;
  957. else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
  958. bus_speed = PCIX_100MHZ_533;
  959. else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
  960. bus_speed = PCIX_66MHZ_533;
  961. else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
  962. bus_speed = PCIX_133MHZ_266;
  963. else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
  964. bus_speed = PCIX_100MHZ_266;
  965. else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
  966. bus_speed = PCIX_66MHZ_266;
  967. else if (slot_avail1 & SLOT_133MHZ_PCIX)
  968. bus_speed = PCIX_133MHZ;
  969. else if (slot_avail1 & SLOT_100MHZ_PCIX)
  970. bus_speed = PCIX_100MHZ;
  971. else if (slot_avail1 & SLOT_66MHZ_PCIX)
  972. bus_speed = PCIX_66MHZ;
  973. else if (slot_avail2 & SLOT_66MHZ)
  974. bus_speed = PCI_66MHZ;
  975. else if (slot_avail1 & SLOT_33MHZ)
  976. bus_speed = PCI_33MHZ;
  977. else bus_speed = PCI_SPEED_UNKNOWN;
  978. } else {
  979. if (slot_avail1 & SLOT_133MHZ_PCIX)
  980. bus_speed = PCIX_133MHZ;
  981. else if (slot_avail1 & SLOT_100MHZ_PCIX)
  982. bus_speed = PCIX_100MHZ;
  983. else if (slot_avail1 & SLOT_66MHZ_PCIX)
  984. bus_speed = PCIX_66MHZ;
  985. else if (slot_avail2 & SLOT_66MHZ)
  986. bus_speed = PCI_66MHZ;
  987. else if (slot_avail1 & SLOT_33MHZ)
  988. bus_speed = PCI_33MHZ;
  989. else bus_speed = PCI_SPEED_UNKNOWN;
  990. }
  991. *value = bus_speed;
  992. dbg("Max bus speed = %d\n", bus_speed);
  993. DBG_LEAVE_ROUTINE
  994. return retval;
  995. }
  996. static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
  997. {
  998. struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
  999. enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
  1000. u16 sec_bus_status;
  1001. int retval = 0;
  1002. u8 pi;
  1003. DBG_ENTER_ROUTINE
  1004. if (!slot->ctrl->hpc_ctlr_handle) {
  1005. err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
  1006. return -1;
  1007. }
  1008. if (slot->hp_slot >= php_ctlr->num_slots) {
  1009. err("%s: Invalid HPC slot number!\n", __FUNCTION__);
  1010. return -1;
  1011. }
  1012. pi = readb(php_ctlr->creg + PROG_INTERFACE);
  1013. sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
  1014. if (pi == 2) {
  1015. switch (sec_bus_status & 0x000f) {
  1016. case 0:
  1017. bus_speed = PCI_SPEED_33MHz;
  1018. break;
  1019. case 1:
  1020. bus_speed = PCI_SPEED_66MHz;
  1021. break;
  1022. case 2:
  1023. bus_speed = PCI_SPEED_66MHz_PCIX;
  1024. break;
  1025. case 3:
  1026. bus_speed = PCI_SPEED_100MHz_PCIX;
  1027. break;
  1028. case 4:
  1029. bus_speed = PCI_SPEED_133MHz_PCIX;
  1030. break;
  1031. case 5:
  1032. bus_speed = PCI_SPEED_66MHz_PCIX_ECC;
  1033. break;
  1034. case 6:
  1035. bus_speed = PCI_SPEED_100MHz_PCIX_ECC;
  1036. break;
  1037. case 7:
  1038. bus_speed = PCI_SPEED_133MHz_PCIX_ECC;
  1039. break;
  1040. case 8:
  1041. bus_speed = PCI_SPEED_66MHz_PCIX_266;
  1042. break;
  1043. case 9:
  1044. bus_speed = PCI_SPEED_100MHz_PCIX_266;
  1045. break;
  1046. case 0xa:
  1047. bus_speed = PCI_SPEED_133MHz_PCIX_266;
  1048. break;
  1049. case 0xb:
  1050. bus_speed = PCI_SPEED_66MHz_PCIX_533;
  1051. break;
  1052. case 0xc:
  1053. bus_speed = PCI_SPEED_100MHz_PCIX_533;
  1054. break;
  1055. case 0xd:
  1056. bus_speed = PCI_SPEED_133MHz_PCIX_533;
  1057. break;
  1058. case 0xe:
  1059. case 0xf:
  1060. default:
  1061. bus_speed = PCI_SPEED_UNKNOWN;
  1062. break;
  1063. }
  1064. } else {
  1065. /* In the case where pi is undefined, default it to 1 */
  1066. switch (sec_bus_status & 0x0007) {
  1067. case 0:
  1068. bus_speed = PCI_SPEED_33MHz;
  1069. break;
  1070. case 1:
  1071. bus_speed = PCI_SPEED_66MHz;
  1072. break;
  1073. case 2:
  1074. bus_speed = PCI_SPEED_66MHz_PCIX;
  1075. break;
  1076. case 3:
  1077. bus_speed = PCI_SPEED_100MHz_PCIX;
  1078. break;
  1079. case 4:
  1080. bus_speed = PCI_SPEED_133MHz_PCIX;
  1081. break;
  1082. case 5:
  1083. bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
  1084. break;
  1085. case 6:
  1086. bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
  1087. break;
  1088. case 7:
  1089. bus_speed = PCI_SPEED_UNKNOWN; /* Reserved */
  1090. break;
  1091. default:
  1092. bus_speed = PCI_SPEED_UNKNOWN;
  1093. break;
  1094. }
  1095. }
  1096. *value = bus_speed;
  1097. dbg("Current bus speed = %d\n", bus_speed);
  1098. DBG_LEAVE_ROUTINE
  1099. return retval;
  1100. }
  1101. static struct hpc_ops shpchp_hpc_ops = {
  1102. .power_on_slot = hpc_power_on_slot,
  1103. .slot_enable = hpc_slot_enable,
  1104. .slot_disable = hpc_slot_disable,
  1105. .set_bus_speed_mode = hpc_set_bus_speed_mode,
  1106. .set_attention_status = hpc_set_attention_status,
  1107. .get_power_status = hpc_get_power_status,
  1108. .get_attention_status = hpc_get_attention_status,
  1109. .get_latch_status = hpc_get_latch_status,
  1110. .get_adapter_status = hpc_get_adapter_status,
  1111. .get_max_bus_speed = hpc_get_max_bus_speed,
  1112. .get_cur_bus_speed = hpc_get_cur_bus_speed,
  1113. .get_adapter_speed = hpc_get_adapter_speed,
  1114. .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
  1115. .get_prog_int = hpc_get_prog_int,
  1116. .query_power_fault = hpc_query_power_fault,
  1117. .green_led_on = hpc_set_green_led_on,
  1118. .green_led_off = hpc_set_green_led_off,
  1119. .green_led_blink = hpc_set_green_led_blink,
  1120. .release_ctlr = hpc_release_ctlr,
  1121. .check_cmd_status = hpc_check_cmd_status,
  1122. };
  1123. inline static int shpc_indirect_creg_read(struct controller *ctrl, int index,
  1124. u32 *value)
  1125. {
  1126. int rc;
  1127. u32 cap_offset = ctrl->cap_offset;
  1128. struct pci_dev *pdev = ctrl->pci_dev;
  1129. rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
  1130. if (rc)
  1131. return rc;
  1132. return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
  1133. }
  1134. int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
  1135. {
  1136. struct php_ctlr_state_s *php_ctlr, *p;
  1137. void *instance_id = ctrl;
  1138. int rc, num_slots = 0;
  1139. u8 hp_slot;
  1140. static int first = 1;
  1141. u32 shpc_base_offset;
  1142. u32 tempdword, slot_reg;
  1143. u8 i;
  1144. DBG_ENTER_ROUTINE
  1145. ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
  1146. spin_lock_init(&list_lock);
  1147. php_ctlr = (struct php_ctlr_state_s *) kmalloc(sizeof(struct php_ctlr_state_s), GFP_KERNEL);
  1148. if (!php_ctlr) { /* allocate controller state data */
  1149. err("%s: HPC controller memory allocation error!\n", __FUNCTION__);
  1150. goto abort;
  1151. }
  1152. memset(php_ctlr, 0, sizeof(struct php_ctlr_state_s));
  1153. php_ctlr->pci_dev = pdev; /* save pci_dev in context */
  1154. if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
  1155. PCI_DEVICE_ID_AMD_GOLAM_7450)) {
  1156. /* amd shpc driver doesn't use Base Offset; assume 0 */
  1157. ctrl->mmio_base = pci_resource_start(pdev, 0);
  1158. ctrl->mmio_size = pci_resource_len(pdev, 0);
  1159. } else {
  1160. ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
  1161. if (!ctrl->cap_offset) {
  1162. err("%s : cap_offset == 0\n", __FUNCTION__);
  1163. goto abort_free_ctlr;
  1164. }
  1165. dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
  1166. rc = shpc_indirect_creg_read(ctrl, 0, &shpc_base_offset);
  1167. if (rc) {
  1168. err("%s: cannot read base_offset\n", __FUNCTION__);
  1169. goto abort_free_ctlr;
  1170. }
  1171. rc = shpc_indirect_creg_read(ctrl, 3, &tempdword);
  1172. if (rc) {
  1173. err("%s: cannot read slot config\n", __FUNCTION__);
  1174. goto abort_free_ctlr;
  1175. }
  1176. num_slots = tempdword & SLOT_NUM;
  1177. dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
  1178. for (i = 0; i < 9 + num_slots; i++) {
  1179. rc = shpc_indirect_creg_read(ctrl, i, &tempdword);
  1180. if (rc) {
  1181. err("%s: cannot read creg (index = %d)\n",
  1182. __FUNCTION__, i);
  1183. goto abort_free_ctlr;
  1184. }
  1185. dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
  1186. tempdword);
  1187. }
  1188. ctrl->mmio_base =
  1189. pci_resource_start(pdev, 0) + shpc_base_offset;
  1190. ctrl->mmio_size = 0x24 + 0x4 * num_slots;
  1191. }
  1192. if (first) {
  1193. spin_lock_init(&hpc_event_lock);
  1194. first = 0;
  1195. }
  1196. info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor,
  1197. pdev->subsystem_device);
  1198. if (pci_enable_device(pdev))
  1199. goto abort_free_ctlr;
  1200. if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
  1201. err("%s: cannot reserve MMIO region\n", __FUNCTION__);
  1202. goto abort_free_ctlr;
  1203. }
  1204. php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
  1205. if (!php_ctlr->creg) {
  1206. err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
  1207. ctrl->mmio_size, ctrl->mmio_base);
  1208. release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
  1209. goto abort_free_ctlr;
  1210. }
  1211. dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
  1212. init_MUTEX(&ctrl->crit_sect);
  1213. /* Setup wait queue */
  1214. init_waitqueue_head(&ctrl->queue);
  1215. /* Find the IRQ */
  1216. php_ctlr->irq = pdev->irq;
  1217. php_ctlr->attention_button_callback = shpchp_handle_attention_button,
  1218. php_ctlr->switch_change_callback = shpchp_handle_switch_change;
  1219. php_ctlr->presence_change_callback = shpchp_handle_presence_change;
  1220. php_ctlr->power_fault_callback = shpchp_handle_power_fault;
  1221. php_ctlr->callback_instance_id = instance_id;
  1222. /* Return PCI Controller Info */
  1223. php_ctlr->slot_device_offset = (readl(php_ctlr->creg + SLOT_CONFIG) & FIRST_DEV_NUM ) >> 8;
  1224. php_ctlr->num_slots = readl(php_ctlr->creg + SLOT_CONFIG) & SLOT_NUM;
  1225. dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset);
  1226. dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots);
  1227. /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
  1228. tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
  1229. dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
  1230. tempdword = 0x0003000f;
  1231. writel(tempdword, php_ctlr->creg + SERR_INTR_ENABLE);
  1232. tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
  1233. dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
  1234. /* Mask the MRL sensor SERR Mask of individual slot in
  1235. * Slot SERR-INT Mask & clear all the existing event if any
  1236. */
  1237. for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
  1238. slot_reg = readl(php_ctlr->creg + SLOT1 + 4*hp_slot );
  1239. dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
  1240. hp_slot, slot_reg);
  1241. tempdword = 0xffff3fff;
  1242. writel(tempdword, php_ctlr->creg + SLOT1 + (4*hp_slot));
  1243. }
  1244. if (shpchp_poll_mode) {/* Install interrupt polling code */
  1245. /* Install and start the interrupt polling timer */
  1246. init_timer(&php_ctlr->int_poll_timer);
  1247. start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */
  1248. } else {
  1249. /* Installs the interrupt handler */
  1250. rc = pci_enable_msi(pdev);
  1251. if (rc) {
  1252. info("Can't get msi for the hotplug controller\n");
  1253. info("Use INTx for the hotplug controller\n");
  1254. } else
  1255. php_ctlr->irq = pdev->irq;
  1256. rc = request_irq(php_ctlr->irq, shpc_isr, SA_SHIRQ, MY_NAME, (void *) ctrl);
  1257. dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc);
  1258. if (rc) {
  1259. err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);
  1260. goto abort_free_ctlr;
  1261. }
  1262. }
  1263. dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
  1264. pdev->bus->number, PCI_SLOT(pdev->devfn),
  1265. PCI_FUNC(pdev->devfn), pdev->irq);
  1266. get_hp_hw_control_from_firmware(pdev);
  1267. /* Add this HPC instance into the HPC list */
  1268. spin_lock(&list_lock);
  1269. if (php_ctlr_list_head == 0) {
  1270. php_ctlr_list_head = php_ctlr;
  1271. p = php_ctlr_list_head;
  1272. p->pnext = NULL;
  1273. } else {
  1274. p = php_ctlr_list_head;
  1275. while (p->pnext)
  1276. p = p->pnext;
  1277. p->pnext = php_ctlr;
  1278. }
  1279. spin_unlock(&list_lock);
  1280. ctlr_seq_num++;
  1281. ctrl->hpc_ctlr_handle = php_ctlr;
  1282. ctrl->hpc_ops = &shpchp_hpc_ops;
  1283. for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {
  1284. slot_reg = readl(php_ctlr->creg + SLOT1 + 4*hp_slot );
  1285. dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
  1286. hp_slot, slot_reg);
  1287. tempdword = 0xe01f3fff;
  1288. writel(tempdword, php_ctlr->creg + SLOT1 + (4*hp_slot));
  1289. }
  1290. if (!shpchp_poll_mode) {
  1291. /* Unmask all general input interrupts and SERR */
  1292. tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
  1293. tempdword = 0x0000000a;
  1294. writel(tempdword, php_ctlr->creg + SERR_INTR_ENABLE);
  1295. tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
  1296. dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
  1297. }
  1298. DBG_LEAVE_ROUTINE
  1299. return 0;
  1300. /* We end up here for the many possible ways to fail this API. */
  1301. abort_free_ctlr:
  1302. kfree(php_ctlr);
  1303. abort:
  1304. DBG_LEAVE_ROUTINE
  1305. return -1;
  1306. }