shpchp_hpc.c 39 KB

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