shpchp_hpc.c 38 KB

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