shpchp_hpc.c 38 KB

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