shpchp_hpc.c 39 KB

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