shpchp_hpc.c 36 KB

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