shpchp_hpc.c 39 KB

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