shpchp_hpc.c 42 KB

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