shpchp_hpc.c 36 KB

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