shpchp_hpc.c 39 KB

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