ipmi_si_intf.c 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715
  1. /*
  2. * ipmi_si.c
  3. *
  4. * The interface to the IPMI driver for the system interfaces (KCS, SMIC,
  5. * BT).
  6. *
  7. * Author: MontaVista Software, Inc.
  8. * Corey Minyard <minyard@mvista.com>
  9. * source@mvista.com
  10. *
  11. * Copyright 2002 MontaVista Software Inc.
  12. * Copyright 2006 IBM Corp., Christian Krafft <krafft@de.ibm.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License as published by the
  16. * Free Software Foundation; either version 2 of the License, or (at your
  17. * option) any later version.
  18. *
  19. *
  20. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  27. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  28. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  29. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * You should have received a copy of the GNU General Public License along
  32. * with this program; if not, write to the Free Software Foundation, Inc.,
  33. * 675 Mass Ave, Cambridge, MA 02139, USA.
  34. */
  35. /*
  36. * This file holds the "policy" for the interface to the SMI state
  37. * machine. It does the configuration, handles timers and interrupts,
  38. * and drives the real SMI state machine.
  39. */
  40. #include <linux/module.h>
  41. #include <linux/moduleparam.h>
  42. #include <linux/sched.h>
  43. #include <linux/seq_file.h>
  44. #include <linux/timer.h>
  45. #include <linux/errno.h>
  46. #include <linux/spinlock.h>
  47. #include <linux/slab.h>
  48. #include <linux/delay.h>
  49. #include <linux/list.h>
  50. #include <linux/pci.h>
  51. #include <linux/ioport.h>
  52. #include <linux/notifier.h>
  53. #include <linux/mutex.h>
  54. #include <linux/kthread.h>
  55. #include <asm/irq.h>
  56. #include <linux/interrupt.h>
  57. #include <linux/rcupdate.h>
  58. #include <linux/ipmi.h>
  59. #include <linux/ipmi_smi.h>
  60. #include <asm/io.h>
  61. #include "ipmi_si_sm.h"
  62. #include <linux/dmi.h>
  63. #include <linux/string.h>
  64. #include <linux/ctype.h>
  65. #include <linux/pnp.h>
  66. #include <linux/of_device.h>
  67. #include <linux/of_platform.h>
  68. #include <linux/of_address.h>
  69. #include <linux/of_irq.h>
  70. #ifdef CONFIG_PARISC
  71. #include <asm/hardware.h> /* for register_parisc_driver() stuff */
  72. #include <asm/parisc-device.h>
  73. #endif
  74. #define PFX "ipmi_si: "
  75. /* Measure times between events in the driver. */
  76. #undef DEBUG_TIMING
  77. /* Call every 10 ms. */
  78. #define SI_TIMEOUT_TIME_USEC 10000
  79. #define SI_USEC_PER_JIFFY (1000000/HZ)
  80. #define SI_TIMEOUT_JIFFIES (SI_TIMEOUT_TIME_USEC/SI_USEC_PER_JIFFY)
  81. #define SI_SHORT_TIMEOUT_USEC 250 /* .25ms when the SM request a
  82. short timeout */
  83. enum si_intf_state {
  84. SI_NORMAL,
  85. SI_GETTING_FLAGS,
  86. SI_GETTING_EVENTS,
  87. SI_CLEARING_FLAGS,
  88. SI_CLEARING_FLAGS_THEN_SET_IRQ,
  89. SI_GETTING_MESSAGES,
  90. SI_ENABLE_INTERRUPTS1,
  91. SI_ENABLE_INTERRUPTS2,
  92. SI_DISABLE_INTERRUPTS1,
  93. SI_DISABLE_INTERRUPTS2
  94. /* FIXME - add watchdog stuff. */
  95. };
  96. /* Some BT-specific defines we need here. */
  97. #define IPMI_BT_INTMASK_REG 2
  98. #define IPMI_BT_INTMASK_CLEAR_IRQ_BIT 2
  99. #define IPMI_BT_INTMASK_ENABLE_IRQ_BIT 1
  100. enum si_type {
  101. SI_KCS, SI_SMIC, SI_BT
  102. };
  103. static char *si_to_str[] = { "kcs", "smic", "bt" };
  104. static char *ipmi_addr_src_to_str[] = { NULL, "hotmod", "hardcoded", "SPMI",
  105. "ACPI", "SMBIOS", "PCI",
  106. "device-tree", "default" };
  107. #define DEVICE_NAME "ipmi_si"
  108. static struct platform_driver ipmi_driver;
  109. /*
  110. * Indexes into stats[] in smi_info below.
  111. */
  112. enum si_stat_indexes {
  113. /*
  114. * Number of times the driver requested a timer while an operation
  115. * was in progress.
  116. */
  117. SI_STAT_short_timeouts = 0,
  118. /*
  119. * Number of times the driver requested a timer while nothing was in
  120. * progress.
  121. */
  122. SI_STAT_long_timeouts,
  123. /* Number of times the interface was idle while being polled. */
  124. SI_STAT_idles,
  125. /* Number of interrupts the driver handled. */
  126. SI_STAT_interrupts,
  127. /* Number of time the driver got an ATTN from the hardware. */
  128. SI_STAT_attentions,
  129. /* Number of times the driver requested flags from the hardware. */
  130. SI_STAT_flag_fetches,
  131. /* Number of times the hardware didn't follow the state machine. */
  132. SI_STAT_hosed_count,
  133. /* Number of completed messages. */
  134. SI_STAT_complete_transactions,
  135. /* Number of IPMI events received from the hardware. */
  136. SI_STAT_events,
  137. /* Number of watchdog pretimeouts. */
  138. SI_STAT_watchdog_pretimeouts,
  139. /* Number of asynchronous messages received. */
  140. SI_STAT_incoming_messages,
  141. /* This *must* remain last, add new values above this. */
  142. SI_NUM_STATS
  143. };
  144. struct smi_info {
  145. int intf_num;
  146. ipmi_smi_t intf;
  147. struct si_sm_data *si_sm;
  148. struct si_sm_handlers *handlers;
  149. enum si_type si_type;
  150. spinlock_t si_lock;
  151. struct list_head xmit_msgs;
  152. struct list_head hp_xmit_msgs;
  153. struct ipmi_smi_msg *curr_msg;
  154. enum si_intf_state si_state;
  155. /*
  156. * Used to handle the various types of I/O that can occur with
  157. * IPMI
  158. */
  159. struct si_sm_io io;
  160. int (*io_setup)(struct smi_info *info);
  161. void (*io_cleanup)(struct smi_info *info);
  162. int (*irq_setup)(struct smi_info *info);
  163. void (*irq_cleanup)(struct smi_info *info);
  164. unsigned int io_size;
  165. enum ipmi_addr_src addr_source; /* ACPI, PCI, SMBIOS, hardcode, etc. */
  166. void (*addr_source_cleanup)(struct smi_info *info);
  167. void *addr_source_data;
  168. /*
  169. * Per-OEM handler, called from handle_flags(). Returns 1
  170. * when handle_flags() needs to be re-run or 0 indicating it
  171. * set si_state itself.
  172. */
  173. int (*oem_data_avail_handler)(struct smi_info *smi_info);
  174. /*
  175. * Flags from the last GET_MSG_FLAGS command, used when an ATTN
  176. * is set to hold the flags until we are done handling everything
  177. * from the flags.
  178. */
  179. #define RECEIVE_MSG_AVAIL 0x01
  180. #define EVENT_MSG_BUFFER_FULL 0x02
  181. #define WDT_PRE_TIMEOUT_INT 0x08
  182. #define OEM0_DATA_AVAIL 0x20
  183. #define OEM1_DATA_AVAIL 0x40
  184. #define OEM2_DATA_AVAIL 0x80
  185. #define OEM_DATA_AVAIL (OEM0_DATA_AVAIL | \
  186. OEM1_DATA_AVAIL | \
  187. OEM2_DATA_AVAIL)
  188. unsigned char msg_flags;
  189. /* Does the BMC have an event buffer? */
  190. char has_event_buffer;
  191. /*
  192. * If set to true, this will request events the next time the
  193. * state machine is idle.
  194. */
  195. atomic_t req_events;
  196. /*
  197. * If true, run the state machine to completion on every send
  198. * call. Generally used after a panic to make sure stuff goes
  199. * out.
  200. */
  201. int run_to_completion;
  202. /* The I/O port of an SI interface. */
  203. int port;
  204. /*
  205. * The space between start addresses of the two ports. For
  206. * instance, if the first port is 0xca2 and the spacing is 4, then
  207. * the second port is 0xca6.
  208. */
  209. unsigned int spacing;
  210. /* zero if no irq; */
  211. int irq;
  212. /* The timer for this si. */
  213. struct timer_list si_timer;
  214. /* The time (in jiffies) the last timeout occurred at. */
  215. unsigned long last_timeout_jiffies;
  216. /* Used to gracefully stop the timer without race conditions. */
  217. atomic_t stop_operation;
  218. /*
  219. * The driver will disable interrupts when it gets into a
  220. * situation where it cannot handle messages due to lack of
  221. * memory. Once that situation clears up, it will re-enable
  222. * interrupts.
  223. */
  224. int interrupt_disabled;
  225. /* From the get device id response... */
  226. struct ipmi_device_id device_id;
  227. /* Driver model stuff. */
  228. struct device *dev;
  229. struct platform_device *pdev;
  230. /*
  231. * True if we allocated the device, false if it came from
  232. * someplace else (like PCI).
  233. */
  234. int dev_registered;
  235. /* Slave address, could be reported from DMI. */
  236. unsigned char slave_addr;
  237. /* Counters and things for the proc filesystem. */
  238. atomic_t stats[SI_NUM_STATS];
  239. struct task_struct *thread;
  240. struct list_head link;
  241. union ipmi_smi_info_union addr_info;
  242. };
  243. #define smi_inc_stat(smi, stat) \
  244. atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
  245. #define smi_get_stat(smi, stat) \
  246. ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
  247. #define SI_MAX_PARMS 4
  248. static int force_kipmid[SI_MAX_PARMS];
  249. static int num_force_kipmid;
  250. #ifdef CONFIG_PCI
  251. static int pci_registered;
  252. #endif
  253. #ifdef CONFIG_ACPI
  254. static int pnp_registered;
  255. #endif
  256. #ifdef CONFIG_PARISC
  257. static int parisc_registered;
  258. #endif
  259. static unsigned int kipmid_max_busy_us[SI_MAX_PARMS];
  260. static int num_max_busy_us;
  261. static int unload_when_empty = 1;
  262. static int add_smi(struct smi_info *smi);
  263. static int try_smi_init(struct smi_info *smi);
  264. static void cleanup_one_si(struct smi_info *to_clean);
  265. static void cleanup_ipmi_si(void);
  266. static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list);
  267. static int register_xaction_notifier(struct notifier_block *nb)
  268. {
  269. return atomic_notifier_chain_register(&xaction_notifier_list, nb);
  270. }
  271. static void deliver_recv_msg(struct smi_info *smi_info,
  272. struct ipmi_smi_msg *msg)
  273. {
  274. /* Deliver the message to the upper layer. */
  275. ipmi_smi_msg_received(smi_info->intf, msg);
  276. }
  277. static void return_hosed_msg(struct smi_info *smi_info, int cCode)
  278. {
  279. struct ipmi_smi_msg *msg = smi_info->curr_msg;
  280. if (cCode < 0 || cCode > IPMI_ERR_UNSPECIFIED)
  281. cCode = IPMI_ERR_UNSPECIFIED;
  282. /* else use it as is */
  283. /* Make it a response */
  284. msg->rsp[0] = msg->data[0] | 4;
  285. msg->rsp[1] = msg->data[1];
  286. msg->rsp[2] = cCode;
  287. msg->rsp_size = 3;
  288. smi_info->curr_msg = NULL;
  289. deliver_recv_msg(smi_info, msg);
  290. }
  291. static enum si_sm_result start_next_msg(struct smi_info *smi_info)
  292. {
  293. int rv;
  294. struct list_head *entry = NULL;
  295. #ifdef DEBUG_TIMING
  296. struct timeval t;
  297. #endif
  298. /* Pick the high priority queue first. */
  299. if (!list_empty(&(smi_info->hp_xmit_msgs))) {
  300. entry = smi_info->hp_xmit_msgs.next;
  301. } else if (!list_empty(&(smi_info->xmit_msgs))) {
  302. entry = smi_info->xmit_msgs.next;
  303. }
  304. if (!entry) {
  305. smi_info->curr_msg = NULL;
  306. rv = SI_SM_IDLE;
  307. } else {
  308. int err;
  309. list_del(entry);
  310. smi_info->curr_msg = list_entry(entry,
  311. struct ipmi_smi_msg,
  312. link);
  313. #ifdef DEBUG_TIMING
  314. do_gettimeofday(&t);
  315. printk(KERN_DEBUG "**Start2: %d.%9.9d\n", t.tv_sec, t.tv_usec);
  316. #endif
  317. err = atomic_notifier_call_chain(&xaction_notifier_list,
  318. 0, smi_info);
  319. if (err & NOTIFY_STOP_MASK) {
  320. rv = SI_SM_CALL_WITHOUT_DELAY;
  321. goto out;
  322. }
  323. err = smi_info->handlers->start_transaction(
  324. smi_info->si_sm,
  325. smi_info->curr_msg->data,
  326. smi_info->curr_msg->data_size);
  327. if (err)
  328. return_hosed_msg(smi_info, err);
  329. rv = SI_SM_CALL_WITHOUT_DELAY;
  330. }
  331. out:
  332. return rv;
  333. }
  334. static void start_enable_irq(struct smi_info *smi_info)
  335. {
  336. unsigned char msg[2];
  337. /*
  338. * If we are enabling interrupts, we have to tell the
  339. * BMC to use them.
  340. */
  341. msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
  342. msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD;
  343. smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2);
  344. smi_info->si_state = SI_ENABLE_INTERRUPTS1;
  345. }
  346. static void start_disable_irq(struct smi_info *smi_info)
  347. {
  348. unsigned char msg[2];
  349. msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
  350. msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD;
  351. smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2);
  352. smi_info->si_state = SI_DISABLE_INTERRUPTS1;
  353. }
  354. static void start_clear_flags(struct smi_info *smi_info)
  355. {
  356. unsigned char msg[3];
  357. /* Make sure the watchdog pre-timeout flag is not set at startup. */
  358. msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
  359. msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD;
  360. msg[2] = WDT_PRE_TIMEOUT_INT;
  361. smi_info->handlers->start_transaction(smi_info->si_sm, msg, 3);
  362. smi_info->si_state = SI_CLEARING_FLAGS;
  363. }
  364. /*
  365. * When we have a situtaion where we run out of memory and cannot
  366. * allocate messages, we just leave them in the BMC and run the system
  367. * polled until we can allocate some memory. Once we have some
  368. * memory, we will re-enable the interrupt.
  369. */
  370. static inline void disable_si_irq(struct smi_info *smi_info)
  371. {
  372. if ((smi_info->irq) && (!smi_info->interrupt_disabled)) {
  373. start_disable_irq(smi_info);
  374. smi_info->interrupt_disabled = 1;
  375. if (!atomic_read(&smi_info->stop_operation))
  376. mod_timer(&smi_info->si_timer,
  377. jiffies + SI_TIMEOUT_JIFFIES);
  378. }
  379. }
  380. static inline void enable_si_irq(struct smi_info *smi_info)
  381. {
  382. if ((smi_info->irq) && (smi_info->interrupt_disabled)) {
  383. start_enable_irq(smi_info);
  384. smi_info->interrupt_disabled = 0;
  385. }
  386. }
  387. static void handle_flags(struct smi_info *smi_info)
  388. {
  389. retry:
  390. if (smi_info->msg_flags & WDT_PRE_TIMEOUT_INT) {
  391. /* Watchdog pre-timeout */
  392. smi_inc_stat(smi_info, watchdog_pretimeouts);
  393. start_clear_flags(smi_info);
  394. smi_info->msg_flags &= ~WDT_PRE_TIMEOUT_INT;
  395. ipmi_smi_watchdog_pretimeout(smi_info->intf);
  396. } else if (smi_info->msg_flags & RECEIVE_MSG_AVAIL) {
  397. /* Messages available. */
  398. smi_info->curr_msg = ipmi_alloc_smi_msg();
  399. if (!smi_info->curr_msg) {
  400. disable_si_irq(smi_info);
  401. smi_info->si_state = SI_NORMAL;
  402. return;
  403. }
  404. enable_si_irq(smi_info);
  405. smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
  406. smi_info->curr_msg->data[1] = IPMI_GET_MSG_CMD;
  407. smi_info->curr_msg->data_size = 2;
  408. smi_info->handlers->start_transaction(
  409. smi_info->si_sm,
  410. smi_info->curr_msg->data,
  411. smi_info->curr_msg->data_size);
  412. smi_info->si_state = SI_GETTING_MESSAGES;
  413. } else if (smi_info->msg_flags & EVENT_MSG_BUFFER_FULL) {
  414. /* Events available. */
  415. smi_info->curr_msg = ipmi_alloc_smi_msg();
  416. if (!smi_info->curr_msg) {
  417. disable_si_irq(smi_info);
  418. smi_info->si_state = SI_NORMAL;
  419. return;
  420. }
  421. enable_si_irq(smi_info);
  422. smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
  423. smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD;
  424. smi_info->curr_msg->data_size = 2;
  425. smi_info->handlers->start_transaction(
  426. smi_info->si_sm,
  427. smi_info->curr_msg->data,
  428. smi_info->curr_msg->data_size);
  429. smi_info->si_state = SI_GETTING_EVENTS;
  430. } else if (smi_info->msg_flags & OEM_DATA_AVAIL &&
  431. smi_info->oem_data_avail_handler) {
  432. if (smi_info->oem_data_avail_handler(smi_info))
  433. goto retry;
  434. } else
  435. smi_info->si_state = SI_NORMAL;
  436. }
  437. static void handle_transaction_done(struct smi_info *smi_info)
  438. {
  439. struct ipmi_smi_msg *msg;
  440. #ifdef DEBUG_TIMING
  441. struct timeval t;
  442. do_gettimeofday(&t);
  443. printk(KERN_DEBUG "**Done: %d.%9.9d\n", t.tv_sec, t.tv_usec);
  444. #endif
  445. switch (smi_info->si_state) {
  446. case SI_NORMAL:
  447. if (!smi_info->curr_msg)
  448. break;
  449. smi_info->curr_msg->rsp_size
  450. = smi_info->handlers->get_result(
  451. smi_info->si_sm,
  452. smi_info->curr_msg->rsp,
  453. IPMI_MAX_MSG_LENGTH);
  454. /*
  455. * Do this here becase deliver_recv_msg() releases the
  456. * lock, and a new message can be put in during the
  457. * time the lock is released.
  458. */
  459. msg = smi_info->curr_msg;
  460. smi_info->curr_msg = NULL;
  461. deliver_recv_msg(smi_info, msg);
  462. break;
  463. case SI_GETTING_FLAGS:
  464. {
  465. unsigned char msg[4];
  466. unsigned int len;
  467. /* We got the flags from the SMI, now handle them. */
  468. len = smi_info->handlers->get_result(smi_info->si_sm, msg, 4);
  469. if (msg[2] != 0) {
  470. /* Error fetching flags, just give up for now. */
  471. smi_info->si_state = SI_NORMAL;
  472. } else if (len < 4) {
  473. /*
  474. * Hmm, no flags. That's technically illegal, but
  475. * don't use uninitialized data.
  476. */
  477. smi_info->si_state = SI_NORMAL;
  478. } else {
  479. smi_info->msg_flags = msg[3];
  480. handle_flags(smi_info);
  481. }
  482. break;
  483. }
  484. case SI_CLEARING_FLAGS:
  485. case SI_CLEARING_FLAGS_THEN_SET_IRQ:
  486. {
  487. unsigned char msg[3];
  488. /* We cleared the flags. */
  489. smi_info->handlers->get_result(smi_info->si_sm, msg, 3);
  490. if (msg[2] != 0) {
  491. /* Error clearing flags */
  492. dev_warn(smi_info->dev,
  493. "Error clearing flags: %2.2x\n", msg[2]);
  494. }
  495. if (smi_info->si_state == SI_CLEARING_FLAGS_THEN_SET_IRQ)
  496. start_enable_irq(smi_info);
  497. else
  498. smi_info->si_state = SI_NORMAL;
  499. break;
  500. }
  501. case SI_GETTING_EVENTS:
  502. {
  503. smi_info->curr_msg->rsp_size
  504. = smi_info->handlers->get_result(
  505. smi_info->si_sm,
  506. smi_info->curr_msg->rsp,
  507. IPMI_MAX_MSG_LENGTH);
  508. /*
  509. * Do this here becase deliver_recv_msg() releases the
  510. * lock, and a new message can be put in during the
  511. * time the lock is released.
  512. */
  513. msg = smi_info->curr_msg;
  514. smi_info->curr_msg = NULL;
  515. if (msg->rsp[2] != 0) {
  516. /* Error getting event, probably done. */
  517. msg->done(msg);
  518. /* Take off the event flag. */
  519. smi_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL;
  520. handle_flags(smi_info);
  521. } else {
  522. smi_inc_stat(smi_info, events);
  523. /*
  524. * Do this before we deliver the message
  525. * because delivering the message releases the
  526. * lock and something else can mess with the
  527. * state.
  528. */
  529. handle_flags(smi_info);
  530. deliver_recv_msg(smi_info, msg);
  531. }
  532. break;
  533. }
  534. case SI_GETTING_MESSAGES:
  535. {
  536. smi_info->curr_msg->rsp_size
  537. = smi_info->handlers->get_result(
  538. smi_info->si_sm,
  539. smi_info->curr_msg->rsp,
  540. IPMI_MAX_MSG_LENGTH);
  541. /*
  542. * Do this here becase deliver_recv_msg() releases the
  543. * lock, and a new message can be put in during the
  544. * time the lock is released.
  545. */
  546. msg = smi_info->curr_msg;
  547. smi_info->curr_msg = NULL;
  548. if (msg->rsp[2] != 0) {
  549. /* Error getting event, probably done. */
  550. msg->done(msg);
  551. /* Take off the msg flag. */
  552. smi_info->msg_flags &= ~RECEIVE_MSG_AVAIL;
  553. handle_flags(smi_info);
  554. } else {
  555. smi_inc_stat(smi_info, incoming_messages);
  556. /*
  557. * Do this before we deliver the message
  558. * because delivering the message releases the
  559. * lock and something else can mess with the
  560. * state.
  561. */
  562. handle_flags(smi_info);
  563. deliver_recv_msg(smi_info, msg);
  564. }
  565. break;
  566. }
  567. case SI_ENABLE_INTERRUPTS1:
  568. {
  569. unsigned char msg[4];
  570. /* We got the flags from the SMI, now handle them. */
  571. smi_info->handlers->get_result(smi_info->si_sm, msg, 4);
  572. if (msg[2] != 0) {
  573. dev_warn(smi_info->dev,
  574. "Couldn't get irq info: %x.\n", msg[2]);
  575. dev_warn(smi_info->dev,
  576. "Maybe ok, but ipmi might run very slowly.\n");
  577. smi_info->si_state = SI_NORMAL;
  578. } else {
  579. msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
  580. msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
  581. msg[2] = (msg[3] |
  582. IPMI_BMC_RCV_MSG_INTR |
  583. IPMI_BMC_EVT_MSG_INTR);
  584. smi_info->handlers->start_transaction(
  585. smi_info->si_sm, msg, 3);
  586. smi_info->si_state = SI_ENABLE_INTERRUPTS2;
  587. }
  588. break;
  589. }
  590. case SI_ENABLE_INTERRUPTS2:
  591. {
  592. unsigned char msg[4];
  593. /* We got the flags from the SMI, now handle them. */
  594. smi_info->handlers->get_result(smi_info->si_sm, msg, 4);
  595. if (msg[2] != 0) {
  596. dev_warn(smi_info->dev,
  597. "Couldn't set irq info: %x.\n", msg[2]);
  598. dev_warn(smi_info->dev,
  599. "Maybe ok, but ipmi might run very slowly.\n");
  600. } else
  601. smi_info->interrupt_disabled = 0;
  602. smi_info->si_state = SI_NORMAL;
  603. break;
  604. }
  605. case SI_DISABLE_INTERRUPTS1:
  606. {
  607. unsigned char msg[4];
  608. /* We got the flags from the SMI, now handle them. */
  609. smi_info->handlers->get_result(smi_info->si_sm, msg, 4);
  610. if (msg[2] != 0) {
  611. dev_warn(smi_info->dev, "Could not disable interrupts"
  612. ", failed get.\n");
  613. smi_info->si_state = SI_NORMAL;
  614. } else {
  615. msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
  616. msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
  617. msg[2] = (msg[3] &
  618. ~(IPMI_BMC_RCV_MSG_INTR |
  619. IPMI_BMC_EVT_MSG_INTR));
  620. smi_info->handlers->start_transaction(
  621. smi_info->si_sm, msg, 3);
  622. smi_info->si_state = SI_DISABLE_INTERRUPTS2;
  623. }
  624. break;
  625. }
  626. case SI_DISABLE_INTERRUPTS2:
  627. {
  628. unsigned char msg[4];
  629. /* We got the flags from the SMI, now handle them. */
  630. smi_info->handlers->get_result(smi_info->si_sm, msg, 4);
  631. if (msg[2] != 0) {
  632. dev_warn(smi_info->dev, "Could not disable interrupts"
  633. ", failed set.\n");
  634. }
  635. smi_info->si_state = SI_NORMAL;
  636. break;
  637. }
  638. }
  639. }
  640. /*
  641. * Called on timeouts and events. Timeouts should pass the elapsed
  642. * time, interrupts should pass in zero. Must be called with
  643. * si_lock held and interrupts disabled.
  644. */
  645. static enum si_sm_result smi_event_handler(struct smi_info *smi_info,
  646. int time)
  647. {
  648. enum si_sm_result si_sm_result;
  649. restart:
  650. /*
  651. * There used to be a loop here that waited a little while
  652. * (around 25us) before giving up. That turned out to be
  653. * pointless, the minimum delays I was seeing were in the 300us
  654. * range, which is far too long to wait in an interrupt. So
  655. * we just run until the state machine tells us something
  656. * happened or it needs a delay.
  657. */
  658. si_sm_result = smi_info->handlers->event(smi_info->si_sm, time);
  659. time = 0;
  660. while (si_sm_result == SI_SM_CALL_WITHOUT_DELAY)
  661. si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0);
  662. if (si_sm_result == SI_SM_TRANSACTION_COMPLETE) {
  663. smi_inc_stat(smi_info, complete_transactions);
  664. handle_transaction_done(smi_info);
  665. si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0);
  666. } else if (si_sm_result == SI_SM_HOSED) {
  667. smi_inc_stat(smi_info, hosed_count);
  668. /*
  669. * Do the before return_hosed_msg, because that
  670. * releases the lock.
  671. */
  672. smi_info->si_state = SI_NORMAL;
  673. if (smi_info->curr_msg != NULL) {
  674. /*
  675. * If we were handling a user message, format
  676. * a response to send to the upper layer to
  677. * tell it about the error.
  678. */
  679. return_hosed_msg(smi_info, IPMI_ERR_UNSPECIFIED);
  680. }
  681. si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0);
  682. }
  683. /*
  684. * We prefer handling attn over new messages. But don't do
  685. * this if there is not yet an upper layer to handle anything.
  686. */
  687. if (likely(smi_info->intf) && si_sm_result == SI_SM_ATTN) {
  688. unsigned char msg[2];
  689. smi_inc_stat(smi_info, attentions);
  690. /*
  691. * Got a attn, send down a get message flags to see
  692. * what's causing it. It would be better to handle
  693. * this in the upper layer, but due to the way
  694. * interrupts work with the SMI, that's not really
  695. * possible.
  696. */
  697. msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
  698. msg[1] = IPMI_GET_MSG_FLAGS_CMD;
  699. smi_info->handlers->start_transaction(
  700. smi_info->si_sm, msg, 2);
  701. smi_info->si_state = SI_GETTING_FLAGS;
  702. goto restart;
  703. }
  704. /* If we are currently idle, try to start the next message. */
  705. if (si_sm_result == SI_SM_IDLE) {
  706. smi_inc_stat(smi_info, idles);
  707. si_sm_result = start_next_msg(smi_info);
  708. if (si_sm_result != SI_SM_IDLE)
  709. goto restart;
  710. }
  711. if ((si_sm_result == SI_SM_IDLE)
  712. && (atomic_read(&smi_info->req_events))) {
  713. /*
  714. * We are idle and the upper layer requested that I fetch
  715. * events, so do so.
  716. */
  717. atomic_set(&smi_info->req_events, 0);
  718. smi_info->curr_msg = ipmi_alloc_smi_msg();
  719. if (!smi_info->curr_msg)
  720. goto out;
  721. smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2);
  722. smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD;
  723. smi_info->curr_msg->data_size = 2;
  724. smi_info->handlers->start_transaction(
  725. smi_info->si_sm,
  726. smi_info->curr_msg->data,
  727. smi_info->curr_msg->data_size);
  728. smi_info->si_state = SI_GETTING_EVENTS;
  729. goto restart;
  730. }
  731. out:
  732. return si_sm_result;
  733. }
  734. static void sender(void *send_info,
  735. struct ipmi_smi_msg *msg,
  736. int priority)
  737. {
  738. struct smi_info *smi_info = send_info;
  739. enum si_sm_result result;
  740. unsigned long flags;
  741. #ifdef DEBUG_TIMING
  742. struct timeval t;
  743. #endif
  744. if (atomic_read(&smi_info->stop_operation)) {
  745. msg->rsp[0] = msg->data[0] | 4;
  746. msg->rsp[1] = msg->data[1];
  747. msg->rsp[2] = IPMI_ERR_UNSPECIFIED;
  748. msg->rsp_size = 3;
  749. deliver_recv_msg(smi_info, msg);
  750. return;
  751. }
  752. #ifdef DEBUG_TIMING
  753. do_gettimeofday(&t);
  754. printk("**Enqueue: %d.%9.9d\n", t.tv_sec, t.tv_usec);
  755. #endif
  756. if (smi_info->run_to_completion) {
  757. /*
  758. * If we are running to completion, then throw it in
  759. * the list and run transactions until everything is
  760. * clear. Priority doesn't matter here.
  761. */
  762. /*
  763. * Run to completion means we are single-threaded, no
  764. * need for locks.
  765. */
  766. list_add_tail(&(msg->link), &(smi_info->xmit_msgs));
  767. result = smi_event_handler(smi_info, 0);
  768. while (result != SI_SM_IDLE) {
  769. udelay(SI_SHORT_TIMEOUT_USEC);
  770. result = smi_event_handler(smi_info,
  771. SI_SHORT_TIMEOUT_USEC);
  772. }
  773. return;
  774. }
  775. spin_lock_irqsave(&smi_info->si_lock, flags);
  776. if (priority > 0)
  777. list_add_tail(&msg->link, &smi_info->hp_xmit_msgs);
  778. else
  779. list_add_tail(&msg->link, &smi_info->xmit_msgs);
  780. if (smi_info->si_state == SI_NORMAL && smi_info->curr_msg == NULL) {
  781. /*
  782. * last_timeout_jiffies is updated here to avoid
  783. * smi_timeout() handler passing very large time_diff
  784. * value to smi_event_handler() that causes
  785. * the send command to abort.
  786. */
  787. smi_info->last_timeout_jiffies = jiffies;
  788. mod_timer(&smi_info->si_timer, jiffies + SI_TIMEOUT_JIFFIES);
  789. if (smi_info->thread)
  790. wake_up_process(smi_info->thread);
  791. start_next_msg(smi_info);
  792. smi_event_handler(smi_info, 0);
  793. }
  794. spin_unlock_irqrestore(&smi_info->si_lock, flags);
  795. }
  796. static void set_run_to_completion(void *send_info, int i_run_to_completion)
  797. {
  798. struct smi_info *smi_info = send_info;
  799. enum si_sm_result result;
  800. smi_info->run_to_completion = i_run_to_completion;
  801. if (i_run_to_completion) {
  802. result = smi_event_handler(smi_info, 0);
  803. while (result != SI_SM_IDLE) {
  804. udelay(SI_SHORT_TIMEOUT_USEC);
  805. result = smi_event_handler(smi_info,
  806. SI_SHORT_TIMEOUT_USEC);
  807. }
  808. }
  809. }
  810. /*
  811. * Use -1 in the nsec value of the busy waiting timespec to tell that
  812. * we are spinning in kipmid looking for something and not delaying
  813. * between checks
  814. */
  815. static inline void ipmi_si_set_not_busy(struct timespec *ts)
  816. {
  817. ts->tv_nsec = -1;
  818. }
  819. static inline int ipmi_si_is_busy(struct timespec *ts)
  820. {
  821. return ts->tv_nsec != -1;
  822. }
  823. static int ipmi_thread_busy_wait(enum si_sm_result smi_result,
  824. const struct smi_info *smi_info,
  825. struct timespec *busy_until)
  826. {
  827. unsigned int max_busy_us = 0;
  828. if (smi_info->intf_num < num_max_busy_us)
  829. max_busy_us = kipmid_max_busy_us[smi_info->intf_num];
  830. if (max_busy_us == 0 || smi_result != SI_SM_CALL_WITH_DELAY)
  831. ipmi_si_set_not_busy(busy_until);
  832. else if (!ipmi_si_is_busy(busy_until)) {
  833. getnstimeofday(busy_until);
  834. timespec_add_ns(busy_until, max_busy_us*NSEC_PER_USEC);
  835. } else {
  836. struct timespec now;
  837. getnstimeofday(&now);
  838. if (unlikely(timespec_compare(&now, busy_until) > 0)) {
  839. ipmi_si_set_not_busy(busy_until);
  840. return 0;
  841. }
  842. }
  843. return 1;
  844. }
  845. /*
  846. * A busy-waiting loop for speeding up IPMI operation.
  847. *
  848. * Lousy hardware makes this hard. This is only enabled for systems
  849. * that are not BT and do not have interrupts. It starts spinning
  850. * when an operation is complete or until max_busy tells it to stop
  851. * (if that is enabled). See the paragraph on kimid_max_busy_us in
  852. * Documentation/IPMI.txt for details.
  853. */
  854. static int ipmi_thread(void *data)
  855. {
  856. struct smi_info *smi_info = data;
  857. unsigned long flags;
  858. enum si_sm_result smi_result;
  859. struct timespec busy_until;
  860. ipmi_si_set_not_busy(&busy_until);
  861. set_user_nice(current, 19);
  862. while (!kthread_should_stop()) {
  863. int busy_wait;
  864. spin_lock_irqsave(&(smi_info->si_lock), flags);
  865. smi_result = smi_event_handler(smi_info, 0);
  866. spin_unlock_irqrestore(&(smi_info->si_lock), flags);
  867. busy_wait = ipmi_thread_busy_wait(smi_result, smi_info,
  868. &busy_until);
  869. if (smi_result == SI_SM_CALL_WITHOUT_DELAY)
  870. ; /* do nothing */
  871. else if (smi_result == SI_SM_CALL_WITH_DELAY && busy_wait)
  872. schedule();
  873. else if (smi_result == SI_SM_IDLE)
  874. schedule_timeout_interruptible(100);
  875. else
  876. schedule_timeout_interruptible(1);
  877. }
  878. return 0;
  879. }
  880. static void poll(void *send_info)
  881. {
  882. struct smi_info *smi_info = send_info;
  883. unsigned long flags = 0;
  884. int run_to_completion = smi_info->run_to_completion;
  885. /*
  886. * Make sure there is some delay in the poll loop so we can
  887. * drive time forward and timeout things.
  888. */
  889. udelay(10);
  890. if (!run_to_completion)
  891. spin_lock_irqsave(&smi_info->si_lock, flags);
  892. smi_event_handler(smi_info, 10);
  893. if (!run_to_completion)
  894. spin_unlock_irqrestore(&smi_info->si_lock, flags);
  895. }
  896. static void request_events(void *send_info)
  897. {
  898. struct smi_info *smi_info = send_info;
  899. if (atomic_read(&smi_info->stop_operation) ||
  900. !smi_info->has_event_buffer)
  901. return;
  902. atomic_set(&smi_info->req_events, 1);
  903. }
  904. static int initialized;
  905. static void smi_timeout(unsigned long data)
  906. {
  907. struct smi_info *smi_info = (struct smi_info *) data;
  908. enum si_sm_result smi_result;
  909. unsigned long flags;
  910. unsigned long jiffies_now;
  911. long time_diff;
  912. long timeout;
  913. #ifdef DEBUG_TIMING
  914. struct timeval t;
  915. #endif
  916. spin_lock_irqsave(&(smi_info->si_lock), flags);
  917. #ifdef DEBUG_TIMING
  918. do_gettimeofday(&t);
  919. printk(KERN_DEBUG "**Timer: %d.%9.9d\n", t.tv_sec, t.tv_usec);
  920. #endif
  921. jiffies_now = jiffies;
  922. time_diff = (((long)jiffies_now - (long)smi_info->last_timeout_jiffies)
  923. * SI_USEC_PER_JIFFY);
  924. smi_result = smi_event_handler(smi_info, time_diff);
  925. spin_unlock_irqrestore(&(smi_info->si_lock), flags);
  926. smi_info->last_timeout_jiffies = jiffies_now;
  927. if ((smi_info->irq) && (!smi_info->interrupt_disabled)) {
  928. /* Running with interrupts, only do long timeouts. */
  929. timeout = jiffies + SI_TIMEOUT_JIFFIES;
  930. smi_inc_stat(smi_info, long_timeouts);
  931. goto do_mod_timer;
  932. }
  933. /*
  934. * If the state machine asks for a short delay, then shorten
  935. * the timer timeout.
  936. */
  937. if (smi_result == SI_SM_CALL_WITH_DELAY) {
  938. smi_inc_stat(smi_info, short_timeouts);
  939. timeout = jiffies + 1;
  940. } else {
  941. smi_inc_stat(smi_info, long_timeouts);
  942. timeout = jiffies + SI_TIMEOUT_JIFFIES;
  943. }
  944. do_mod_timer:
  945. if (smi_result != SI_SM_IDLE)
  946. mod_timer(&(smi_info->si_timer), timeout);
  947. }
  948. static irqreturn_t si_irq_handler(int irq, void *data)
  949. {
  950. struct smi_info *smi_info = data;
  951. unsigned long flags;
  952. #ifdef DEBUG_TIMING
  953. struct timeval t;
  954. #endif
  955. spin_lock_irqsave(&(smi_info->si_lock), flags);
  956. smi_inc_stat(smi_info, interrupts);
  957. #ifdef DEBUG_TIMING
  958. do_gettimeofday(&t);
  959. printk(KERN_DEBUG "**Interrupt: %d.%9.9d\n", t.tv_sec, t.tv_usec);
  960. #endif
  961. smi_event_handler(smi_info, 0);
  962. spin_unlock_irqrestore(&(smi_info->si_lock), flags);
  963. return IRQ_HANDLED;
  964. }
  965. static irqreturn_t si_bt_irq_handler(int irq, void *data)
  966. {
  967. struct smi_info *smi_info = data;
  968. /* We need to clear the IRQ flag for the BT interface. */
  969. smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG,
  970. IPMI_BT_INTMASK_CLEAR_IRQ_BIT
  971. | IPMI_BT_INTMASK_ENABLE_IRQ_BIT);
  972. return si_irq_handler(irq, data);
  973. }
  974. static int smi_start_processing(void *send_info,
  975. ipmi_smi_t intf)
  976. {
  977. struct smi_info *new_smi = send_info;
  978. int enable = 0;
  979. new_smi->intf = intf;
  980. /* Try to claim any interrupts. */
  981. if (new_smi->irq_setup)
  982. new_smi->irq_setup(new_smi);
  983. /* Set up the timer that drives the interface. */
  984. setup_timer(&new_smi->si_timer, smi_timeout, (long)new_smi);
  985. new_smi->last_timeout_jiffies = jiffies;
  986. mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES);
  987. /*
  988. * Check if the user forcefully enabled the daemon.
  989. */
  990. if (new_smi->intf_num < num_force_kipmid)
  991. enable = force_kipmid[new_smi->intf_num];
  992. /*
  993. * The BT interface is efficient enough to not need a thread,
  994. * and there is no need for a thread if we have interrupts.
  995. */
  996. else if ((new_smi->si_type != SI_BT) && (!new_smi->irq))
  997. enable = 1;
  998. if (enable) {
  999. new_smi->thread = kthread_run(ipmi_thread, new_smi,
  1000. "kipmi%d", new_smi->intf_num);
  1001. if (IS_ERR(new_smi->thread)) {
  1002. dev_notice(new_smi->dev, "Could not start"
  1003. " kernel thread due to error %ld, only using"
  1004. " timers to drive the interface\n",
  1005. PTR_ERR(new_smi->thread));
  1006. new_smi->thread = NULL;
  1007. }
  1008. }
  1009. return 0;
  1010. }
  1011. static int get_smi_info(void *send_info, struct ipmi_smi_info *data)
  1012. {
  1013. struct smi_info *smi = send_info;
  1014. data->addr_src = smi->addr_source;
  1015. data->dev = smi->dev;
  1016. data->addr_info = smi->addr_info;
  1017. get_device(smi->dev);
  1018. return 0;
  1019. }
  1020. static void set_maintenance_mode(void *send_info, int enable)
  1021. {
  1022. struct smi_info *smi_info = send_info;
  1023. if (!enable)
  1024. atomic_set(&smi_info->req_events, 0);
  1025. }
  1026. static struct ipmi_smi_handlers handlers = {
  1027. .owner = THIS_MODULE,
  1028. .start_processing = smi_start_processing,
  1029. .get_smi_info = get_smi_info,
  1030. .sender = sender,
  1031. .request_events = request_events,
  1032. .set_maintenance_mode = set_maintenance_mode,
  1033. .set_run_to_completion = set_run_to_completion,
  1034. .poll = poll,
  1035. };
  1036. /*
  1037. * There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
  1038. * a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS.
  1039. */
  1040. static LIST_HEAD(smi_infos);
  1041. static DEFINE_MUTEX(smi_infos_lock);
  1042. static int smi_num; /* Used to sequence the SMIs */
  1043. #define DEFAULT_REGSPACING 1
  1044. #define DEFAULT_REGSIZE 1
  1045. #ifdef CONFIG_ACPI
  1046. static bool si_tryacpi = 1;
  1047. #endif
  1048. #ifdef CONFIG_DMI
  1049. static bool si_trydmi = 1;
  1050. #endif
  1051. static bool si_tryplatform = 1;
  1052. #ifdef CONFIG_PCI
  1053. static bool si_trypci = 1;
  1054. #endif
  1055. static bool si_trydefaults = 1;
  1056. static char *si_type[SI_MAX_PARMS];
  1057. #define MAX_SI_TYPE_STR 30
  1058. static char si_type_str[MAX_SI_TYPE_STR];
  1059. static unsigned long addrs[SI_MAX_PARMS];
  1060. static unsigned int num_addrs;
  1061. static unsigned int ports[SI_MAX_PARMS];
  1062. static unsigned int num_ports;
  1063. static int irqs[SI_MAX_PARMS];
  1064. static unsigned int num_irqs;
  1065. static int regspacings[SI_MAX_PARMS];
  1066. static unsigned int num_regspacings;
  1067. static int regsizes[SI_MAX_PARMS];
  1068. static unsigned int num_regsizes;
  1069. static int regshifts[SI_MAX_PARMS];
  1070. static unsigned int num_regshifts;
  1071. static int slave_addrs[SI_MAX_PARMS]; /* Leaving 0 chooses the default value */
  1072. static unsigned int num_slave_addrs;
  1073. #define IPMI_IO_ADDR_SPACE 0
  1074. #define IPMI_MEM_ADDR_SPACE 1
  1075. static char *addr_space_to_str[] = { "i/o", "mem" };
  1076. static int hotmod_handler(const char *val, struct kernel_param *kp);
  1077. module_param_call(hotmod, hotmod_handler, NULL, NULL, 0200);
  1078. MODULE_PARM_DESC(hotmod, "Add and remove interfaces. See"
  1079. " Documentation/IPMI.txt in the kernel sources for the"
  1080. " gory details.");
  1081. #ifdef CONFIG_ACPI
  1082. module_param_named(tryacpi, si_tryacpi, bool, 0);
  1083. MODULE_PARM_DESC(tryacpi, "Setting this to zero will disable the"
  1084. " default scan of the interfaces identified via ACPI");
  1085. #endif
  1086. #ifdef CONFIG_DMI
  1087. module_param_named(trydmi, si_trydmi, bool, 0);
  1088. MODULE_PARM_DESC(trydmi, "Setting this to zero will disable the"
  1089. " default scan of the interfaces identified via DMI");
  1090. #endif
  1091. module_param_named(tryplatform, si_tryplatform, bool, 0);
  1092. MODULE_PARM_DESC(tryacpi, "Setting this to zero will disable the"
  1093. " default scan of the interfaces identified via platform"
  1094. " interfaces like openfirmware");
  1095. #ifdef CONFIG_PCI
  1096. module_param_named(trypci, si_trypci, bool, 0);
  1097. MODULE_PARM_DESC(tryacpi, "Setting this to zero will disable the"
  1098. " default scan of the interfaces identified via pci");
  1099. #endif
  1100. module_param_named(trydefaults, si_trydefaults, bool, 0);
  1101. MODULE_PARM_DESC(trydefaults, "Setting this to 'false' will disable the"
  1102. " default scan of the KCS and SMIC interface at the standard"
  1103. " address");
  1104. module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0);
  1105. MODULE_PARM_DESC(type, "Defines the type of each interface, each"
  1106. " interface separated by commas. The types are 'kcs',"
  1107. " 'smic', and 'bt'. For example si_type=kcs,bt will set"
  1108. " the first interface to kcs and the second to bt");
  1109. module_param_array(addrs, ulong, &num_addrs, 0);
  1110. MODULE_PARM_DESC(addrs, "Sets the memory address of each interface, the"
  1111. " addresses separated by commas. Only use if an interface"
  1112. " is in memory. Otherwise, set it to zero or leave"
  1113. " it blank.");
  1114. module_param_array(ports, uint, &num_ports, 0);
  1115. MODULE_PARM_DESC(ports, "Sets the port address of each interface, the"
  1116. " addresses separated by commas. Only use if an interface"
  1117. " is a port. Otherwise, set it to zero or leave"
  1118. " it blank.");
  1119. module_param_array(irqs, int, &num_irqs, 0);
  1120. MODULE_PARM_DESC(irqs, "Sets the interrupt of each interface, the"
  1121. " addresses separated by commas. Only use if an interface"
  1122. " has an interrupt. Otherwise, set it to zero or leave"
  1123. " it blank.");
  1124. module_param_array(regspacings, int, &num_regspacings, 0);
  1125. MODULE_PARM_DESC(regspacings, "The number of bytes between the start address"
  1126. " and each successive register used by the interface. For"
  1127. " instance, if the start address is 0xca2 and the spacing"
  1128. " is 2, then the second address is at 0xca4. Defaults"
  1129. " to 1.");
  1130. module_param_array(regsizes, int, &num_regsizes, 0);
  1131. MODULE_PARM_DESC(regsizes, "The size of the specific IPMI register in bytes."
  1132. " This should generally be 1, 2, 4, or 8 for an 8-bit,"
  1133. " 16-bit, 32-bit, or 64-bit register. Use this if you"
  1134. " the 8-bit IPMI register has to be read from a larger"
  1135. " register.");
  1136. module_param_array(regshifts, int, &num_regshifts, 0);
  1137. MODULE_PARM_DESC(regshifts, "The amount to shift the data read from the."
  1138. " IPMI register, in bits. For instance, if the data"
  1139. " is read from a 32-bit word and the IPMI data is in"
  1140. " bit 8-15, then the shift would be 8");
  1141. module_param_array(slave_addrs, int, &num_slave_addrs, 0);
  1142. MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for"
  1143. " the controller. Normally this is 0x20, but can be"
  1144. " overridden by this parm. This is an array indexed"
  1145. " by interface number.");
  1146. module_param_array(force_kipmid, int, &num_force_kipmid, 0);
  1147. MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or"
  1148. " disabled(0). Normally the IPMI driver auto-detects"
  1149. " this, but the value may be overridden by this parm.");
  1150. module_param(unload_when_empty, int, 0);
  1151. MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are"
  1152. " specified or found, default is 1. Setting to 0"
  1153. " is useful for hot add of devices using hotmod.");
  1154. module_param_array(kipmid_max_busy_us, uint, &num_max_busy_us, 0644);
  1155. MODULE_PARM_DESC(kipmid_max_busy_us,
  1156. "Max time (in microseconds) to busy-wait for IPMI data before"
  1157. " sleeping. 0 (default) means to wait forever. Set to 100-500"
  1158. " if kipmid is using up a lot of CPU time.");
  1159. static void std_irq_cleanup(struct smi_info *info)
  1160. {
  1161. if (info->si_type == SI_BT)
  1162. /* Disable the interrupt in the BT interface. */
  1163. info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 0);
  1164. free_irq(info->irq, info);
  1165. }
  1166. static int std_irq_setup(struct smi_info *info)
  1167. {
  1168. int rv;
  1169. if (!info->irq)
  1170. return 0;
  1171. if (info->si_type == SI_BT) {
  1172. rv = request_irq(info->irq,
  1173. si_bt_irq_handler,
  1174. IRQF_SHARED,
  1175. DEVICE_NAME,
  1176. info);
  1177. if (!rv)
  1178. /* Enable the interrupt in the BT interface. */
  1179. info->io.outputb(&info->io, IPMI_BT_INTMASK_REG,
  1180. IPMI_BT_INTMASK_ENABLE_IRQ_BIT);
  1181. } else
  1182. rv = request_irq(info->irq,
  1183. si_irq_handler,
  1184. IRQF_SHARED,
  1185. DEVICE_NAME,
  1186. info);
  1187. if (rv) {
  1188. dev_warn(info->dev, "%s unable to claim interrupt %d,"
  1189. " running polled\n",
  1190. DEVICE_NAME, info->irq);
  1191. info->irq = 0;
  1192. } else {
  1193. info->irq_cleanup = std_irq_cleanup;
  1194. dev_info(info->dev, "Using irq %d\n", info->irq);
  1195. }
  1196. return rv;
  1197. }
  1198. static unsigned char port_inb(struct si_sm_io *io, unsigned int offset)
  1199. {
  1200. unsigned int addr = io->addr_data;
  1201. return inb(addr + (offset * io->regspacing));
  1202. }
  1203. static void port_outb(struct si_sm_io *io, unsigned int offset,
  1204. unsigned char b)
  1205. {
  1206. unsigned int addr = io->addr_data;
  1207. outb(b, addr + (offset * io->regspacing));
  1208. }
  1209. static unsigned char port_inw(struct si_sm_io *io, unsigned int offset)
  1210. {
  1211. unsigned int addr = io->addr_data;
  1212. return (inw(addr + (offset * io->regspacing)) >> io->regshift) & 0xff;
  1213. }
  1214. static void port_outw(struct si_sm_io *io, unsigned int offset,
  1215. unsigned char b)
  1216. {
  1217. unsigned int addr = io->addr_data;
  1218. outw(b << io->regshift, addr + (offset * io->regspacing));
  1219. }
  1220. static unsigned char port_inl(struct si_sm_io *io, unsigned int offset)
  1221. {
  1222. unsigned int addr = io->addr_data;
  1223. return (inl(addr + (offset * io->regspacing)) >> io->regshift) & 0xff;
  1224. }
  1225. static void port_outl(struct si_sm_io *io, unsigned int offset,
  1226. unsigned char b)
  1227. {
  1228. unsigned int addr = io->addr_data;
  1229. outl(b << io->regshift, addr+(offset * io->regspacing));
  1230. }
  1231. static void port_cleanup(struct smi_info *info)
  1232. {
  1233. unsigned int addr = info->io.addr_data;
  1234. int idx;
  1235. if (addr) {
  1236. for (idx = 0; idx < info->io_size; idx++)
  1237. release_region(addr + idx * info->io.regspacing,
  1238. info->io.regsize);
  1239. }
  1240. }
  1241. static int port_setup(struct smi_info *info)
  1242. {
  1243. unsigned int addr = info->io.addr_data;
  1244. int idx;
  1245. if (!addr)
  1246. return -ENODEV;
  1247. info->io_cleanup = port_cleanup;
  1248. /*
  1249. * Figure out the actual inb/inw/inl/etc routine to use based
  1250. * upon the register size.
  1251. */
  1252. switch (info->io.regsize) {
  1253. case 1:
  1254. info->io.inputb = port_inb;
  1255. info->io.outputb = port_outb;
  1256. break;
  1257. case 2:
  1258. info->io.inputb = port_inw;
  1259. info->io.outputb = port_outw;
  1260. break;
  1261. case 4:
  1262. info->io.inputb = port_inl;
  1263. info->io.outputb = port_outl;
  1264. break;
  1265. default:
  1266. dev_warn(info->dev, "Invalid register size: %d\n",
  1267. info->io.regsize);
  1268. return -EINVAL;
  1269. }
  1270. /*
  1271. * Some BIOSes reserve disjoint I/O regions in their ACPI
  1272. * tables. This causes problems when trying to register the
  1273. * entire I/O region. Therefore we must register each I/O
  1274. * port separately.
  1275. */
  1276. for (idx = 0; idx < info->io_size; idx++) {
  1277. if (request_region(addr + idx * info->io.regspacing,
  1278. info->io.regsize, DEVICE_NAME) == NULL) {
  1279. /* Undo allocations */
  1280. while (idx--) {
  1281. release_region(addr + idx * info->io.regspacing,
  1282. info->io.regsize);
  1283. }
  1284. return -EIO;
  1285. }
  1286. }
  1287. return 0;
  1288. }
  1289. static unsigned char intf_mem_inb(struct si_sm_io *io, unsigned int offset)
  1290. {
  1291. return readb((io->addr)+(offset * io->regspacing));
  1292. }
  1293. static void intf_mem_outb(struct si_sm_io *io, unsigned int offset,
  1294. unsigned char b)
  1295. {
  1296. writeb(b, (io->addr)+(offset * io->regspacing));
  1297. }
  1298. static unsigned char intf_mem_inw(struct si_sm_io *io, unsigned int offset)
  1299. {
  1300. return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift)
  1301. & 0xff;
  1302. }
  1303. static void intf_mem_outw(struct si_sm_io *io, unsigned int offset,
  1304. unsigned char b)
  1305. {
  1306. writeb(b << io->regshift, (io->addr)+(offset * io->regspacing));
  1307. }
  1308. static unsigned char intf_mem_inl(struct si_sm_io *io, unsigned int offset)
  1309. {
  1310. return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift)
  1311. & 0xff;
  1312. }
  1313. static void intf_mem_outl(struct si_sm_io *io, unsigned int offset,
  1314. unsigned char b)
  1315. {
  1316. writel(b << io->regshift, (io->addr)+(offset * io->regspacing));
  1317. }
  1318. #ifdef readq
  1319. static unsigned char mem_inq(struct si_sm_io *io, unsigned int offset)
  1320. {
  1321. return (readq((io->addr)+(offset * io->regspacing)) >> io->regshift)
  1322. & 0xff;
  1323. }
  1324. static void mem_outq(struct si_sm_io *io, unsigned int offset,
  1325. unsigned char b)
  1326. {
  1327. writeq(b << io->regshift, (io->addr)+(offset * io->regspacing));
  1328. }
  1329. #endif
  1330. static void mem_cleanup(struct smi_info *info)
  1331. {
  1332. unsigned long addr = info->io.addr_data;
  1333. int mapsize;
  1334. if (info->io.addr) {
  1335. iounmap(info->io.addr);
  1336. mapsize = ((info->io_size * info->io.regspacing)
  1337. - (info->io.regspacing - info->io.regsize));
  1338. release_mem_region(addr, mapsize);
  1339. }
  1340. }
  1341. static int mem_setup(struct smi_info *info)
  1342. {
  1343. unsigned long addr = info->io.addr_data;
  1344. int mapsize;
  1345. if (!addr)
  1346. return -ENODEV;
  1347. info->io_cleanup = mem_cleanup;
  1348. /*
  1349. * Figure out the actual readb/readw/readl/etc routine to use based
  1350. * upon the register size.
  1351. */
  1352. switch (info->io.regsize) {
  1353. case 1:
  1354. info->io.inputb = intf_mem_inb;
  1355. info->io.outputb = intf_mem_outb;
  1356. break;
  1357. case 2:
  1358. info->io.inputb = intf_mem_inw;
  1359. info->io.outputb = intf_mem_outw;
  1360. break;
  1361. case 4:
  1362. info->io.inputb = intf_mem_inl;
  1363. info->io.outputb = intf_mem_outl;
  1364. break;
  1365. #ifdef readq
  1366. case 8:
  1367. info->io.inputb = mem_inq;
  1368. info->io.outputb = mem_outq;
  1369. break;
  1370. #endif
  1371. default:
  1372. dev_warn(info->dev, "Invalid register size: %d\n",
  1373. info->io.regsize);
  1374. return -EINVAL;
  1375. }
  1376. /*
  1377. * Calculate the total amount of memory to claim. This is an
  1378. * unusual looking calculation, but it avoids claiming any
  1379. * more memory than it has to. It will claim everything
  1380. * between the first address to the end of the last full
  1381. * register.
  1382. */
  1383. mapsize = ((info->io_size * info->io.regspacing)
  1384. - (info->io.regspacing - info->io.regsize));
  1385. if (request_mem_region(addr, mapsize, DEVICE_NAME) == NULL)
  1386. return -EIO;
  1387. info->io.addr = ioremap(addr, mapsize);
  1388. if (info->io.addr == NULL) {
  1389. release_mem_region(addr, mapsize);
  1390. return -EIO;
  1391. }
  1392. return 0;
  1393. }
  1394. /*
  1395. * Parms come in as <op1>[:op2[:op3...]]. ops are:
  1396. * add|remove,kcs|bt|smic,mem|i/o,<address>[,<opt1>[,<opt2>[,...]]]
  1397. * Options are:
  1398. * rsp=<regspacing>
  1399. * rsi=<regsize>
  1400. * rsh=<regshift>
  1401. * irq=<irq>
  1402. * ipmb=<ipmb addr>
  1403. */
  1404. enum hotmod_op { HM_ADD, HM_REMOVE };
  1405. struct hotmod_vals {
  1406. char *name;
  1407. int val;
  1408. };
  1409. static struct hotmod_vals hotmod_ops[] = {
  1410. { "add", HM_ADD },
  1411. { "remove", HM_REMOVE },
  1412. { NULL }
  1413. };
  1414. static struct hotmod_vals hotmod_si[] = {
  1415. { "kcs", SI_KCS },
  1416. { "smic", SI_SMIC },
  1417. { "bt", SI_BT },
  1418. { NULL }
  1419. };
  1420. static struct hotmod_vals hotmod_as[] = {
  1421. { "mem", IPMI_MEM_ADDR_SPACE },
  1422. { "i/o", IPMI_IO_ADDR_SPACE },
  1423. { NULL }
  1424. };
  1425. static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr)
  1426. {
  1427. char *s;
  1428. int i;
  1429. s = strchr(*curr, ',');
  1430. if (!s) {
  1431. printk(KERN_WARNING PFX "No hotmod %s given.\n", name);
  1432. return -EINVAL;
  1433. }
  1434. *s = '\0';
  1435. s++;
  1436. for (i = 0; hotmod_ops[i].name; i++) {
  1437. if (strcmp(*curr, v[i].name) == 0) {
  1438. *val = v[i].val;
  1439. *curr = s;
  1440. return 0;
  1441. }
  1442. }
  1443. printk(KERN_WARNING PFX "Invalid hotmod %s '%s'\n", name, *curr);
  1444. return -EINVAL;
  1445. }
  1446. static int check_hotmod_int_op(const char *curr, const char *option,
  1447. const char *name, int *val)
  1448. {
  1449. char *n;
  1450. if (strcmp(curr, name) == 0) {
  1451. if (!option) {
  1452. printk(KERN_WARNING PFX
  1453. "No option given for '%s'\n",
  1454. curr);
  1455. return -EINVAL;
  1456. }
  1457. *val = simple_strtoul(option, &n, 0);
  1458. if ((*n != '\0') || (*option == '\0')) {
  1459. printk(KERN_WARNING PFX
  1460. "Bad option given for '%s'\n",
  1461. curr);
  1462. return -EINVAL;
  1463. }
  1464. return 1;
  1465. }
  1466. return 0;
  1467. }
  1468. static struct smi_info *smi_info_alloc(void)
  1469. {
  1470. struct smi_info *info = kzalloc(sizeof(*info), GFP_KERNEL);
  1471. if (info)
  1472. spin_lock_init(&info->si_lock);
  1473. return info;
  1474. }
  1475. static int hotmod_handler(const char *val, struct kernel_param *kp)
  1476. {
  1477. char *str = kstrdup(val, GFP_KERNEL);
  1478. int rv;
  1479. char *next, *curr, *s, *n, *o;
  1480. enum hotmod_op op;
  1481. enum si_type si_type;
  1482. int addr_space;
  1483. unsigned long addr;
  1484. int regspacing;
  1485. int regsize;
  1486. int regshift;
  1487. int irq;
  1488. int ipmb;
  1489. int ival;
  1490. int len;
  1491. struct smi_info *info;
  1492. if (!str)
  1493. return -ENOMEM;
  1494. /* Kill any trailing spaces, as we can get a "\n" from echo. */
  1495. len = strlen(str);
  1496. ival = len - 1;
  1497. while ((ival >= 0) && isspace(str[ival])) {
  1498. str[ival] = '\0';
  1499. ival--;
  1500. }
  1501. for (curr = str; curr; curr = next) {
  1502. regspacing = 1;
  1503. regsize = 1;
  1504. regshift = 0;
  1505. irq = 0;
  1506. ipmb = 0; /* Choose the default if not specified */
  1507. next = strchr(curr, ':');
  1508. if (next) {
  1509. *next = '\0';
  1510. next++;
  1511. }
  1512. rv = parse_str(hotmod_ops, &ival, "operation", &curr);
  1513. if (rv)
  1514. break;
  1515. op = ival;
  1516. rv = parse_str(hotmod_si, &ival, "interface type", &curr);
  1517. if (rv)
  1518. break;
  1519. si_type = ival;
  1520. rv = parse_str(hotmod_as, &addr_space, "address space", &curr);
  1521. if (rv)
  1522. break;
  1523. s = strchr(curr, ',');
  1524. if (s) {
  1525. *s = '\0';
  1526. s++;
  1527. }
  1528. addr = simple_strtoul(curr, &n, 0);
  1529. if ((*n != '\0') || (*curr == '\0')) {
  1530. printk(KERN_WARNING PFX "Invalid hotmod address"
  1531. " '%s'\n", curr);
  1532. break;
  1533. }
  1534. while (s) {
  1535. curr = s;
  1536. s = strchr(curr, ',');
  1537. if (s) {
  1538. *s = '\0';
  1539. s++;
  1540. }
  1541. o = strchr(curr, '=');
  1542. if (o) {
  1543. *o = '\0';
  1544. o++;
  1545. }
  1546. rv = check_hotmod_int_op(curr, o, "rsp", &regspacing);
  1547. if (rv < 0)
  1548. goto out;
  1549. else if (rv)
  1550. continue;
  1551. rv = check_hotmod_int_op(curr, o, "rsi", &regsize);
  1552. if (rv < 0)
  1553. goto out;
  1554. else if (rv)
  1555. continue;
  1556. rv = check_hotmod_int_op(curr, o, "rsh", &regshift);
  1557. if (rv < 0)
  1558. goto out;
  1559. else if (rv)
  1560. continue;
  1561. rv = check_hotmod_int_op(curr, o, "irq", &irq);
  1562. if (rv < 0)
  1563. goto out;
  1564. else if (rv)
  1565. continue;
  1566. rv = check_hotmod_int_op(curr, o, "ipmb", &ipmb);
  1567. if (rv < 0)
  1568. goto out;
  1569. else if (rv)
  1570. continue;
  1571. rv = -EINVAL;
  1572. printk(KERN_WARNING PFX
  1573. "Invalid hotmod option '%s'\n",
  1574. curr);
  1575. goto out;
  1576. }
  1577. if (op == HM_ADD) {
  1578. info = smi_info_alloc();
  1579. if (!info) {
  1580. rv = -ENOMEM;
  1581. goto out;
  1582. }
  1583. info->addr_source = SI_HOTMOD;
  1584. info->si_type = si_type;
  1585. info->io.addr_data = addr;
  1586. info->io.addr_type = addr_space;
  1587. if (addr_space == IPMI_MEM_ADDR_SPACE)
  1588. info->io_setup = mem_setup;
  1589. else
  1590. info->io_setup = port_setup;
  1591. info->io.addr = NULL;
  1592. info->io.regspacing = regspacing;
  1593. if (!info->io.regspacing)
  1594. info->io.regspacing = DEFAULT_REGSPACING;
  1595. info->io.regsize = regsize;
  1596. if (!info->io.regsize)
  1597. info->io.regsize = DEFAULT_REGSPACING;
  1598. info->io.regshift = regshift;
  1599. info->irq = irq;
  1600. if (info->irq)
  1601. info->irq_setup = std_irq_setup;
  1602. info->slave_addr = ipmb;
  1603. rv = add_smi(info);
  1604. if (rv) {
  1605. kfree(info);
  1606. goto out;
  1607. }
  1608. rv = try_smi_init(info);
  1609. if (rv) {
  1610. cleanup_one_si(info);
  1611. goto out;
  1612. }
  1613. } else {
  1614. /* remove */
  1615. struct smi_info *e, *tmp_e;
  1616. mutex_lock(&smi_infos_lock);
  1617. list_for_each_entry_safe(e, tmp_e, &smi_infos, link) {
  1618. if (e->io.addr_type != addr_space)
  1619. continue;
  1620. if (e->si_type != si_type)
  1621. continue;
  1622. if (e->io.addr_data == addr)
  1623. cleanup_one_si(e);
  1624. }
  1625. mutex_unlock(&smi_infos_lock);
  1626. }
  1627. }
  1628. rv = len;
  1629. out:
  1630. kfree(str);
  1631. return rv;
  1632. }
  1633. static int hardcode_find_bmc(void)
  1634. {
  1635. int ret = -ENODEV;
  1636. int i;
  1637. struct smi_info *info;
  1638. for (i = 0; i < SI_MAX_PARMS; i++) {
  1639. if (!ports[i] && !addrs[i])
  1640. continue;
  1641. info = smi_info_alloc();
  1642. if (!info)
  1643. return -ENOMEM;
  1644. info->addr_source = SI_HARDCODED;
  1645. printk(KERN_INFO PFX "probing via hardcoded address\n");
  1646. if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) {
  1647. info->si_type = SI_KCS;
  1648. } else if (strcmp(si_type[i], "smic") == 0) {
  1649. info->si_type = SI_SMIC;
  1650. } else if (strcmp(si_type[i], "bt") == 0) {
  1651. info->si_type = SI_BT;
  1652. } else {
  1653. printk(KERN_WARNING PFX "Interface type specified "
  1654. "for interface %d, was invalid: %s\n",
  1655. i, si_type[i]);
  1656. kfree(info);
  1657. continue;
  1658. }
  1659. if (ports[i]) {
  1660. /* An I/O port */
  1661. info->io_setup = port_setup;
  1662. info->io.addr_data = ports[i];
  1663. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  1664. } else if (addrs[i]) {
  1665. /* A memory port */
  1666. info->io_setup = mem_setup;
  1667. info->io.addr_data = addrs[i];
  1668. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  1669. } else {
  1670. printk(KERN_WARNING PFX "Interface type specified "
  1671. "for interface %d, but port and address were "
  1672. "not set or set to zero.\n", i);
  1673. kfree(info);
  1674. continue;
  1675. }
  1676. info->io.addr = NULL;
  1677. info->io.regspacing = regspacings[i];
  1678. if (!info->io.regspacing)
  1679. info->io.regspacing = DEFAULT_REGSPACING;
  1680. info->io.regsize = regsizes[i];
  1681. if (!info->io.regsize)
  1682. info->io.regsize = DEFAULT_REGSPACING;
  1683. info->io.regshift = regshifts[i];
  1684. info->irq = irqs[i];
  1685. if (info->irq)
  1686. info->irq_setup = std_irq_setup;
  1687. info->slave_addr = slave_addrs[i];
  1688. if (!add_smi(info)) {
  1689. if (try_smi_init(info))
  1690. cleanup_one_si(info);
  1691. ret = 0;
  1692. } else {
  1693. kfree(info);
  1694. }
  1695. }
  1696. return ret;
  1697. }
  1698. #ifdef CONFIG_ACPI
  1699. #include <linux/acpi.h>
  1700. /*
  1701. * Once we get an ACPI failure, we don't try any more, because we go
  1702. * through the tables sequentially. Once we don't find a table, there
  1703. * are no more.
  1704. */
  1705. static int acpi_failure;
  1706. /* For GPE-type interrupts. */
  1707. static u32 ipmi_acpi_gpe(acpi_handle gpe_device,
  1708. u32 gpe_number, void *context)
  1709. {
  1710. struct smi_info *smi_info = context;
  1711. unsigned long flags;
  1712. #ifdef DEBUG_TIMING
  1713. struct timeval t;
  1714. #endif
  1715. spin_lock_irqsave(&(smi_info->si_lock), flags);
  1716. smi_inc_stat(smi_info, interrupts);
  1717. #ifdef DEBUG_TIMING
  1718. do_gettimeofday(&t);
  1719. printk("**ACPI_GPE: %d.%9.9d\n", t.tv_sec, t.tv_usec);
  1720. #endif
  1721. smi_event_handler(smi_info, 0);
  1722. spin_unlock_irqrestore(&(smi_info->si_lock), flags);
  1723. return ACPI_INTERRUPT_HANDLED;
  1724. }
  1725. static void acpi_gpe_irq_cleanup(struct smi_info *info)
  1726. {
  1727. if (!info->irq)
  1728. return;
  1729. acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe);
  1730. }
  1731. static int acpi_gpe_irq_setup(struct smi_info *info)
  1732. {
  1733. acpi_status status;
  1734. if (!info->irq)
  1735. return 0;
  1736. /* FIXME - is level triggered right? */
  1737. status = acpi_install_gpe_handler(NULL,
  1738. info->irq,
  1739. ACPI_GPE_LEVEL_TRIGGERED,
  1740. &ipmi_acpi_gpe,
  1741. info);
  1742. if (status != AE_OK) {
  1743. dev_warn(info->dev, "%s unable to claim ACPI GPE %d,"
  1744. " running polled\n", DEVICE_NAME, info->irq);
  1745. info->irq = 0;
  1746. return -EINVAL;
  1747. } else {
  1748. info->irq_cleanup = acpi_gpe_irq_cleanup;
  1749. dev_info(info->dev, "Using ACPI GPE %d\n", info->irq);
  1750. return 0;
  1751. }
  1752. }
  1753. /*
  1754. * Defined at
  1755. * http://h21007.www2.hp.com/portal/download/files/unprot/hpspmi.pdf
  1756. */
  1757. struct SPMITable {
  1758. s8 Signature[4];
  1759. u32 Length;
  1760. u8 Revision;
  1761. u8 Checksum;
  1762. s8 OEMID[6];
  1763. s8 OEMTableID[8];
  1764. s8 OEMRevision[4];
  1765. s8 CreatorID[4];
  1766. s8 CreatorRevision[4];
  1767. u8 InterfaceType;
  1768. u8 IPMIlegacy;
  1769. s16 SpecificationRevision;
  1770. /*
  1771. * Bit 0 - SCI interrupt supported
  1772. * Bit 1 - I/O APIC/SAPIC
  1773. */
  1774. u8 InterruptType;
  1775. /*
  1776. * If bit 0 of InterruptType is set, then this is the SCI
  1777. * interrupt in the GPEx_STS register.
  1778. */
  1779. u8 GPE;
  1780. s16 Reserved;
  1781. /*
  1782. * If bit 1 of InterruptType is set, then this is the I/O
  1783. * APIC/SAPIC interrupt.
  1784. */
  1785. u32 GlobalSystemInterrupt;
  1786. /* The actual register address. */
  1787. struct acpi_generic_address addr;
  1788. u8 UID[4];
  1789. s8 spmi_id[1]; /* A '\0' terminated array starts here. */
  1790. };
  1791. static int try_init_spmi(struct SPMITable *spmi)
  1792. {
  1793. struct smi_info *info;
  1794. int rv;
  1795. if (spmi->IPMIlegacy != 1) {
  1796. printk(KERN_INFO PFX "Bad SPMI legacy %d\n", spmi->IPMIlegacy);
  1797. return -ENODEV;
  1798. }
  1799. info = smi_info_alloc();
  1800. if (!info) {
  1801. printk(KERN_ERR PFX "Could not allocate SI data (3)\n");
  1802. return -ENOMEM;
  1803. }
  1804. info->addr_source = SI_SPMI;
  1805. printk(KERN_INFO PFX "probing via SPMI\n");
  1806. /* Figure out the interface type. */
  1807. switch (spmi->InterfaceType) {
  1808. case 1: /* KCS */
  1809. info->si_type = SI_KCS;
  1810. break;
  1811. case 2: /* SMIC */
  1812. info->si_type = SI_SMIC;
  1813. break;
  1814. case 3: /* BT */
  1815. info->si_type = SI_BT;
  1816. break;
  1817. default:
  1818. printk(KERN_INFO PFX "Unknown ACPI/SPMI SI type %d\n",
  1819. spmi->InterfaceType);
  1820. kfree(info);
  1821. return -EIO;
  1822. }
  1823. if (spmi->InterruptType & 1) {
  1824. /* We've got a GPE interrupt. */
  1825. info->irq = spmi->GPE;
  1826. info->irq_setup = acpi_gpe_irq_setup;
  1827. } else if (spmi->InterruptType & 2) {
  1828. /* We've got an APIC/SAPIC interrupt. */
  1829. info->irq = spmi->GlobalSystemInterrupt;
  1830. info->irq_setup = std_irq_setup;
  1831. } else {
  1832. /* Use the default interrupt setting. */
  1833. info->irq = 0;
  1834. info->irq_setup = NULL;
  1835. }
  1836. if (spmi->addr.bit_width) {
  1837. /* A (hopefully) properly formed register bit width. */
  1838. info->io.regspacing = spmi->addr.bit_width / 8;
  1839. } else {
  1840. info->io.regspacing = DEFAULT_REGSPACING;
  1841. }
  1842. info->io.regsize = info->io.regspacing;
  1843. info->io.regshift = spmi->addr.bit_offset;
  1844. if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
  1845. info->io_setup = mem_setup;
  1846. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  1847. } else if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
  1848. info->io_setup = port_setup;
  1849. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  1850. } else {
  1851. kfree(info);
  1852. printk(KERN_WARNING PFX "Unknown ACPI I/O Address type\n");
  1853. return -EIO;
  1854. }
  1855. info->io.addr_data = spmi->addr.address;
  1856. pr_info("ipmi_si: SPMI: %s %#lx regsize %d spacing %d irq %d\n",
  1857. (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
  1858. info->io.addr_data, info->io.regsize, info->io.regspacing,
  1859. info->irq);
  1860. rv = add_smi(info);
  1861. if (rv)
  1862. kfree(info);
  1863. return rv;
  1864. }
  1865. static void spmi_find_bmc(void)
  1866. {
  1867. acpi_status status;
  1868. struct SPMITable *spmi;
  1869. int i;
  1870. if (acpi_disabled)
  1871. return;
  1872. if (acpi_failure)
  1873. return;
  1874. for (i = 0; ; i++) {
  1875. status = acpi_get_table(ACPI_SIG_SPMI, i+1,
  1876. (struct acpi_table_header **)&spmi);
  1877. if (status != AE_OK)
  1878. return;
  1879. try_init_spmi(spmi);
  1880. }
  1881. }
  1882. static int ipmi_pnp_probe(struct pnp_dev *dev,
  1883. const struct pnp_device_id *dev_id)
  1884. {
  1885. struct acpi_device *acpi_dev;
  1886. struct smi_info *info;
  1887. struct resource *res, *res_second;
  1888. acpi_handle handle;
  1889. acpi_status status;
  1890. unsigned long long tmp;
  1891. int rv;
  1892. acpi_dev = pnp_acpi_device(dev);
  1893. if (!acpi_dev)
  1894. return -ENODEV;
  1895. info = smi_info_alloc();
  1896. if (!info)
  1897. return -ENOMEM;
  1898. info->addr_source = SI_ACPI;
  1899. printk(KERN_INFO PFX "probing via ACPI\n");
  1900. handle = acpi_dev->handle;
  1901. info->addr_info.acpi_info.acpi_handle = handle;
  1902. /* _IFT tells us the interface type: KCS, BT, etc */
  1903. status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp);
  1904. if (ACPI_FAILURE(status))
  1905. goto err_free;
  1906. switch (tmp) {
  1907. case 1:
  1908. info->si_type = SI_KCS;
  1909. break;
  1910. case 2:
  1911. info->si_type = SI_SMIC;
  1912. break;
  1913. case 3:
  1914. info->si_type = SI_BT;
  1915. break;
  1916. default:
  1917. dev_info(&dev->dev, "unknown IPMI type %lld\n", tmp);
  1918. goto err_free;
  1919. }
  1920. res = pnp_get_resource(dev, IORESOURCE_IO, 0);
  1921. if (res) {
  1922. info->io_setup = port_setup;
  1923. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  1924. } else {
  1925. res = pnp_get_resource(dev, IORESOURCE_MEM, 0);
  1926. if (res) {
  1927. info->io_setup = mem_setup;
  1928. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  1929. }
  1930. }
  1931. if (!res) {
  1932. dev_err(&dev->dev, "no I/O or memory address\n");
  1933. goto err_free;
  1934. }
  1935. info->io.addr_data = res->start;
  1936. info->io.regspacing = DEFAULT_REGSPACING;
  1937. res_second = pnp_get_resource(dev,
  1938. (info->io.addr_type == IPMI_IO_ADDR_SPACE) ?
  1939. IORESOURCE_IO : IORESOURCE_MEM,
  1940. 1);
  1941. if (res_second) {
  1942. if (res_second->start > info->io.addr_data)
  1943. info->io.regspacing = res_second->start - info->io.addr_data;
  1944. }
  1945. info->io.regsize = DEFAULT_REGSPACING;
  1946. info->io.regshift = 0;
  1947. /* If _GPE exists, use it; otherwise use standard interrupts */
  1948. status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp);
  1949. if (ACPI_SUCCESS(status)) {
  1950. info->irq = tmp;
  1951. info->irq_setup = acpi_gpe_irq_setup;
  1952. } else if (pnp_irq_valid(dev, 0)) {
  1953. info->irq = pnp_irq(dev, 0);
  1954. info->irq_setup = std_irq_setup;
  1955. }
  1956. info->dev = &dev->dev;
  1957. pnp_set_drvdata(dev, info);
  1958. dev_info(info->dev, "%pR regsize %d spacing %d irq %d\n",
  1959. res, info->io.regsize, info->io.regspacing,
  1960. info->irq);
  1961. rv = add_smi(info);
  1962. if (rv)
  1963. kfree(info);
  1964. return rv;
  1965. err_free:
  1966. kfree(info);
  1967. return -EINVAL;
  1968. }
  1969. static void ipmi_pnp_remove(struct pnp_dev *dev)
  1970. {
  1971. struct smi_info *info = pnp_get_drvdata(dev);
  1972. cleanup_one_si(info);
  1973. }
  1974. static const struct pnp_device_id pnp_dev_table[] = {
  1975. {"IPI0001", 0},
  1976. {"", 0},
  1977. };
  1978. static struct pnp_driver ipmi_pnp_driver = {
  1979. .name = DEVICE_NAME,
  1980. .probe = ipmi_pnp_probe,
  1981. .remove = ipmi_pnp_remove,
  1982. .id_table = pnp_dev_table,
  1983. };
  1984. MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
  1985. #endif
  1986. #ifdef CONFIG_DMI
  1987. struct dmi_ipmi_data {
  1988. u8 type;
  1989. u8 addr_space;
  1990. unsigned long base_addr;
  1991. u8 irq;
  1992. u8 offset;
  1993. u8 slave_addr;
  1994. };
  1995. static int decode_dmi(const struct dmi_header *dm,
  1996. struct dmi_ipmi_data *dmi)
  1997. {
  1998. const u8 *data = (const u8 *)dm;
  1999. unsigned long base_addr;
  2000. u8 reg_spacing;
  2001. u8 len = dm->length;
  2002. dmi->type = data[4];
  2003. memcpy(&base_addr, data+8, sizeof(unsigned long));
  2004. if (len >= 0x11) {
  2005. if (base_addr & 1) {
  2006. /* I/O */
  2007. base_addr &= 0xFFFE;
  2008. dmi->addr_space = IPMI_IO_ADDR_SPACE;
  2009. } else
  2010. /* Memory */
  2011. dmi->addr_space = IPMI_MEM_ADDR_SPACE;
  2012. /* If bit 4 of byte 0x10 is set, then the lsb for the address
  2013. is odd. */
  2014. dmi->base_addr = base_addr | ((data[0x10] & 0x10) >> 4);
  2015. dmi->irq = data[0x11];
  2016. /* The top two bits of byte 0x10 hold the register spacing. */
  2017. reg_spacing = (data[0x10] & 0xC0) >> 6;
  2018. switch (reg_spacing) {
  2019. case 0x00: /* Byte boundaries */
  2020. dmi->offset = 1;
  2021. break;
  2022. case 0x01: /* 32-bit boundaries */
  2023. dmi->offset = 4;
  2024. break;
  2025. case 0x02: /* 16-byte boundaries */
  2026. dmi->offset = 16;
  2027. break;
  2028. default:
  2029. /* Some other interface, just ignore it. */
  2030. return -EIO;
  2031. }
  2032. } else {
  2033. /* Old DMI spec. */
  2034. /*
  2035. * Note that technically, the lower bit of the base
  2036. * address should be 1 if the address is I/O and 0 if
  2037. * the address is in memory. So many systems get that
  2038. * wrong (and all that I have seen are I/O) so we just
  2039. * ignore that bit and assume I/O. Systems that use
  2040. * memory should use the newer spec, anyway.
  2041. */
  2042. dmi->base_addr = base_addr & 0xfffe;
  2043. dmi->addr_space = IPMI_IO_ADDR_SPACE;
  2044. dmi->offset = 1;
  2045. }
  2046. dmi->slave_addr = data[6];
  2047. return 0;
  2048. }
  2049. static void try_init_dmi(struct dmi_ipmi_data *ipmi_data)
  2050. {
  2051. struct smi_info *info;
  2052. info = smi_info_alloc();
  2053. if (!info) {
  2054. printk(KERN_ERR PFX "Could not allocate SI data\n");
  2055. return;
  2056. }
  2057. info->addr_source = SI_SMBIOS;
  2058. printk(KERN_INFO PFX "probing via SMBIOS\n");
  2059. switch (ipmi_data->type) {
  2060. case 0x01: /* KCS */
  2061. info->si_type = SI_KCS;
  2062. break;
  2063. case 0x02: /* SMIC */
  2064. info->si_type = SI_SMIC;
  2065. break;
  2066. case 0x03: /* BT */
  2067. info->si_type = SI_BT;
  2068. break;
  2069. default:
  2070. kfree(info);
  2071. return;
  2072. }
  2073. switch (ipmi_data->addr_space) {
  2074. case IPMI_MEM_ADDR_SPACE:
  2075. info->io_setup = mem_setup;
  2076. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  2077. break;
  2078. case IPMI_IO_ADDR_SPACE:
  2079. info->io_setup = port_setup;
  2080. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  2081. break;
  2082. default:
  2083. kfree(info);
  2084. printk(KERN_WARNING PFX "Unknown SMBIOS I/O Address type: %d\n",
  2085. ipmi_data->addr_space);
  2086. return;
  2087. }
  2088. info->io.addr_data = ipmi_data->base_addr;
  2089. info->io.regspacing = ipmi_data->offset;
  2090. if (!info->io.regspacing)
  2091. info->io.regspacing = DEFAULT_REGSPACING;
  2092. info->io.regsize = DEFAULT_REGSPACING;
  2093. info->io.regshift = 0;
  2094. info->slave_addr = ipmi_data->slave_addr;
  2095. info->irq = ipmi_data->irq;
  2096. if (info->irq)
  2097. info->irq_setup = std_irq_setup;
  2098. pr_info("ipmi_si: SMBIOS: %s %#lx regsize %d spacing %d irq %d\n",
  2099. (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem",
  2100. info->io.addr_data, info->io.regsize, info->io.regspacing,
  2101. info->irq);
  2102. if (add_smi(info))
  2103. kfree(info);
  2104. }
  2105. static void dmi_find_bmc(void)
  2106. {
  2107. const struct dmi_device *dev = NULL;
  2108. struct dmi_ipmi_data data;
  2109. int rv;
  2110. while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) {
  2111. memset(&data, 0, sizeof(data));
  2112. rv = decode_dmi((const struct dmi_header *) dev->device_data,
  2113. &data);
  2114. if (!rv)
  2115. try_init_dmi(&data);
  2116. }
  2117. }
  2118. #endif /* CONFIG_DMI */
  2119. #ifdef CONFIG_PCI
  2120. #define PCI_ERMC_CLASSCODE 0x0C0700
  2121. #define PCI_ERMC_CLASSCODE_MASK 0xffffff00
  2122. #define PCI_ERMC_CLASSCODE_TYPE_MASK 0xff
  2123. #define PCI_ERMC_CLASSCODE_TYPE_SMIC 0x00
  2124. #define PCI_ERMC_CLASSCODE_TYPE_KCS 0x01
  2125. #define PCI_ERMC_CLASSCODE_TYPE_BT 0x02
  2126. #define PCI_HP_VENDOR_ID 0x103C
  2127. #define PCI_MMC_DEVICE_ID 0x121A
  2128. #define PCI_MMC_ADDR_CW 0x10
  2129. static void ipmi_pci_cleanup(struct smi_info *info)
  2130. {
  2131. struct pci_dev *pdev = info->addr_source_data;
  2132. pci_disable_device(pdev);
  2133. }
  2134. static int ipmi_pci_probe_regspacing(struct smi_info *info)
  2135. {
  2136. if (info->si_type == SI_KCS) {
  2137. unsigned char status;
  2138. int regspacing;
  2139. info->io.regsize = DEFAULT_REGSIZE;
  2140. info->io.regshift = 0;
  2141. info->io_size = 2;
  2142. info->handlers = &kcs_smi_handlers;
  2143. /* detect 1, 4, 16byte spacing */
  2144. for (regspacing = DEFAULT_REGSPACING; regspacing <= 16;) {
  2145. info->io.regspacing = regspacing;
  2146. if (info->io_setup(info)) {
  2147. dev_err(info->dev,
  2148. "Could not setup I/O space\n");
  2149. return DEFAULT_REGSPACING;
  2150. }
  2151. /* write invalid cmd */
  2152. info->io.outputb(&info->io, 1, 0x10);
  2153. /* read status back */
  2154. status = info->io.inputb(&info->io, 1);
  2155. info->io_cleanup(info);
  2156. if (status)
  2157. return regspacing;
  2158. regspacing *= 4;
  2159. }
  2160. }
  2161. return DEFAULT_REGSPACING;
  2162. }
  2163. static int ipmi_pci_probe(struct pci_dev *pdev,
  2164. const struct pci_device_id *ent)
  2165. {
  2166. int rv;
  2167. int class_type = pdev->class & PCI_ERMC_CLASSCODE_TYPE_MASK;
  2168. struct smi_info *info;
  2169. info = smi_info_alloc();
  2170. if (!info)
  2171. return -ENOMEM;
  2172. info->addr_source = SI_PCI;
  2173. dev_info(&pdev->dev, "probing via PCI");
  2174. switch (class_type) {
  2175. case PCI_ERMC_CLASSCODE_TYPE_SMIC:
  2176. info->si_type = SI_SMIC;
  2177. break;
  2178. case PCI_ERMC_CLASSCODE_TYPE_KCS:
  2179. info->si_type = SI_KCS;
  2180. break;
  2181. case PCI_ERMC_CLASSCODE_TYPE_BT:
  2182. info->si_type = SI_BT;
  2183. break;
  2184. default:
  2185. kfree(info);
  2186. dev_info(&pdev->dev, "Unknown IPMI type: %d\n", class_type);
  2187. return -ENOMEM;
  2188. }
  2189. rv = pci_enable_device(pdev);
  2190. if (rv) {
  2191. dev_err(&pdev->dev, "couldn't enable PCI device\n");
  2192. kfree(info);
  2193. return rv;
  2194. }
  2195. info->addr_source_cleanup = ipmi_pci_cleanup;
  2196. info->addr_source_data = pdev;
  2197. if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) {
  2198. info->io_setup = port_setup;
  2199. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  2200. } else {
  2201. info->io_setup = mem_setup;
  2202. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  2203. }
  2204. info->io.addr_data = pci_resource_start(pdev, 0);
  2205. info->io.regspacing = ipmi_pci_probe_regspacing(info);
  2206. info->io.regsize = DEFAULT_REGSIZE;
  2207. info->io.regshift = 0;
  2208. info->irq = pdev->irq;
  2209. if (info->irq)
  2210. info->irq_setup = std_irq_setup;
  2211. info->dev = &pdev->dev;
  2212. pci_set_drvdata(pdev, info);
  2213. dev_info(&pdev->dev, "%pR regsize %d spacing %d irq %d\n",
  2214. &pdev->resource[0], info->io.regsize, info->io.regspacing,
  2215. info->irq);
  2216. rv = add_smi(info);
  2217. if (rv) {
  2218. kfree(info);
  2219. pci_disable_device(pdev);
  2220. }
  2221. return rv;
  2222. }
  2223. static void ipmi_pci_remove(struct pci_dev *pdev)
  2224. {
  2225. struct smi_info *info = pci_get_drvdata(pdev);
  2226. cleanup_one_si(info);
  2227. pci_disable_device(pdev);
  2228. }
  2229. static struct pci_device_id ipmi_pci_devices[] = {
  2230. { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) },
  2231. { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE_MASK) },
  2232. { 0, }
  2233. };
  2234. MODULE_DEVICE_TABLE(pci, ipmi_pci_devices);
  2235. static struct pci_driver ipmi_pci_driver = {
  2236. .name = DEVICE_NAME,
  2237. .id_table = ipmi_pci_devices,
  2238. .probe = ipmi_pci_probe,
  2239. .remove = ipmi_pci_remove,
  2240. };
  2241. #endif /* CONFIG_PCI */
  2242. static struct of_device_id ipmi_match[];
  2243. static int ipmi_probe(struct platform_device *dev)
  2244. {
  2245. #ifdef CONFIG_OF
  2246. const struct of_device_id *match;
  2247. struct smi_info *info;
  2248. struct resource resource;
  2249. const __be32 *regsize, *regspacing, *regshift;
  2250. struct device_node *np = dev->dev.of_node;
  2251. int ret;
  2252. int proplen;
  2253. dev_info(&dev->dev, "probing via device tree\n");
  2254. match = of_match_device(ipmi_match, &dev->dev);
  2255. if (!match)
  2256. return -EINVAL;
  2257. ret = of_address_to_resource(np, 0, &resource);
  2258. if (ret) {
  2259. dev_warn(&dev->dev, PFX "invalid address from OF\n");
  2260. return ret;
  2261. }
  2262. regsize = of_get_property(np, "reg-size", &proplen);
  2263. if (regsize && proplen != 4) {
  2264. dev_warn(&dev->dev, PFX "invalid regsize from OF\n");
  2265. return -EINVAL;
  2266. }
  2267. regspacing = of_get_property(np, "reg-spacing", &proplen);
  2268. if (regspacing && proplen != 4) {
  2269. dev_warn(&dev->dev, PFX "invalid regspacing from OF\n");
  2270. return -EINVAL;
  2271. }
  2272. regshift = of_get_property(np, "reg-shift", &proplen);
  2273. if (regshift && proplen != 4) {
  2274. dev_warn(&dev->dev, PFX "invalid regshift from OF\n");
  2275. return -EINVAL;
  2276. }
  2277. info = smi_info_alloc();
  2278. if (!info) {
  2279. dev_err(&dev->dev,
  2280. "could not allocate memory for OF probe\n");
  2281. return -ENOMEM;
  2282. }
  2283. info->si_type = (enum si_type) match->data;
  2284. info->addr_source = SI_DEVICETREE;
  2285. info->irq_setup = std_irq_setup;
  2286. if (resource.flags & IORESOURCE_IO) {
  2287. info->io_setup = port_setup;
  2288. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  2289. } else {
  2290. info->io_setup = mem_setup;
  2291. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  2292. }
  2293. info->io.addr_data = resource.start;
  2294. info->io.regsize = regsize ? be32_to_cpup(regsize) : DEFAULT_REGSIZE;
  2295. info->io.regspacing = regspacing ? be32_to_cpup(regspacing) : DEFAULT_REGSPACING;
  2296. info->io.regshift = regshift ? be32_to_cpup(regshift) : 0;
  2297. info->irq = irq_of_parse_and_map(dev->dev.of_node, 0);
  2298. info->dev = &dev->dev;
  2299. dev_dbg(&dev->dev, "addr 0x%lx regsize %d spacing %d irq %d\n",
  2300. info->io.addr_data, info->io.regsize, info->io.regspacing,
  2301. info->irq);
  2302. dev_set_drvdata(&dev->dev, info);
  2303. ret = add_smi(info);
  2304. if (ret) {
  2305. kfree(info);
  2306. return ret;
  2307. }
  2308. #endif
  2309. return 0;
  2310. }
  2311. static int ipmi_remove(struct platform_device *dev)
  2312. {
  2313. #ifdef CONFIG_OF
  2314. cleanup_one_si(dev_get_drvdata(&dev->dev));
  2315. #endif
  2316. return 0;
  2317. }
  2318. static struct of_device_id ipmi_match[] =
  2319. {
  2320. { .type = "ipmi", .compatible = "ipmi-kcs",
  2321. .data = (void *)(unsigned long) SI_KCS },
  2322. { .type = "ipmi", .compatible = "ipmi-smic",
  2323. .data = (void *)(unsigned long) SI_SMIC },
  2324. { .type = "ipmi", .compatible = "ipmi-bt",
  2325. .data = (void *)(unsigned long) SI_BT },
  2326. {},
  2327. };
  2328. static struct platform_driver ipmi_driver = {
  2329. .driver = {
  2330. .name = DEVICE_NAME,
  2331. .owner = THIS_MODULE,
  2332. .of_match_table = ipmi_match,
  2333. },
  2334. .probe = ipmi_probe,
  2335. .remove = ipmi_remove,
  2336. };
  2337. #ifdef CONFIG_PARISC
  2338. static int ipmi_parisc_probe(struct parisc_device *dev)
  2339. {
  2340. struct smi_info *info;
  2341. int rv;
  2342. info = smi_info_alloc();
  2343. if (!info) {
  2344. dev_err(&dev->dev,
  2345. "could not allocate memory for PARISC probe\n");
  2346. return -ENOMEM;
  2347. }
  2348. info->si_type = SI_KCS;
  2349. info->addr_source = SI_DEVICETREE;
  2350. info->io_setup = mem_setup;
  2351. info->io.addr_type = IPMI_MEM_ADDR_SPACE;
  2352. info->io.addr_data = dev->hpa.start;
  2353. info->io.regsize = 1;
  2354. info->io.regspacing = 1;
  2355. info->io.regshift = 0;
  2356. info->irq = 0; /* no interrupt */
  2357. info->irq_setup = NULL;
  2358. info->dev = &dev->dev;
  2359. dev_dbg(&dev->dev, "addr 0x%lx\n", info->io.addr_data);
  2360. dev_set_drvdata(&dev->dev, info);
  2361. rv = add_smi(info);
  2362. if (rv) {
  2363. kfree(info);
  2364. return rv;
  2365. }
  2366. return 0;
  2367. }
  2368. static int ipmi_parisc_remove(struct parisc_device *dev)
  2369. {
  2370. cleanup_one_si(dev_get_drvdata(&dev->dev));
  2371. return 0;
  2372. }
  2373. static struct parisc_device_id ipmi_parisc_tbl[] = {
  2374. { HPHW_MC, HVERSION_REV_ANY_ID, 0x004, 0xC0 },
  2375. { 0, }
  2376. };
  2377. static struct parisc_driver ipmi_parisc_driver = {
  2378. .name = "ipmi",
  2379. .id_table = ipmi_parisc_tbl,
  2380. .probe = ipmi_parisc_probe,
  2381. .remove = ipmi_parisc_remove,
  2382. };
  2383. #endif /* CONFIG_PARISC */
  2384. static int wait_for_msg_done(struct smi_info *smi_info)
  2385. {
  2386. enum si_sm_result smi_result;
  2387. smi_result = smi_info->handlers->event(smi_info->si_sm, 0);
  2388. for (;;) {
  2389. if (smi_result == SI_SM_CALL_WITH_DELAY ||
  2390. smi_result == SI_SM_CALL_WITH_TICK_DELAY) {
  2391. schedule_timeout_uninterruptible(1);
  2392. smi_result = smi_info->handlers->event(
  2393. smi_info->si_sm, jiffies_to_usecs(1));
  2394. } else if (smi_result == SI_SM_CALL_WITHOUT_DELAY) {
  2395. smi_result = smi_info->handlers->event(
  2396. smi_info->si_sm, 0);
  2397. } else
  2398. break;
  2399. }
  2400. if (smi_result == SI_SM_HOSED)
  2401. /*
  2402. * We couldn't get the state machine to run, so whatever's at
  2403. * the port is probably not an IPMI SMI interface.
  2404. */
  2405. return -ENODEV;
  2406. return 0;
  2407. }
  2408. static int try_get_dev_id(struct smi_info *smi_info)
  2409. {
  2410. unsigned char msg[2];
  2411. unsigned char *resp;
  2412. unsigned long resp_len;
  2413. int rv = 0;
  2414. resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
  2415. if (!resp)
  2416. return -ENOMEM;
  2417. /*
  2418. * Do a Get Device ID command, since it comes back with some
  2419. * useful info.
  2420. */
  2421. msg[0] = IPMI_NETFN_APP_REQUEST << 2;
  2422. msg[1] = IPMI_GET_DEVICE_ID_CMD;
  2423. smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2);
  2424. rv = wait_for_msg_done(smi_info);
  2425. if (rv)
  2426. goto out;
  2427. resp_len = smi_info->handlers->get_result(smi_info->si_sm,
  2428. resp, IPMI_MAX_MSG_LENGTH);
  2429. /* Check and record info from the get device id, in case we need it. */
  2430. rv = ipmi_demangle_device_id(resp, resp_len, &smi_info->device_id);
  2431. out:
  2432. kfree(resp);
  2433. return rv;
  2434. }
  2435. static int try_enable_event_buffer(struct smi_info *smi_info)
  2436. {
  2437. unsigned char msg[3];
  2438. unsigned char *resp;
  2439. unsigned long resp_len;
  2440. int rv = 0;
  2441. resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
  2442. if (!resp)
  2443. return -ENOMEM;
  2444. msg[0] = IPMI_NETFN_APP_REQUEST << 2;
  2445. msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD;
  2446. smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2);
  2447. rv = wait_for_msg_done(smi_info);
  2448. if (rv) {
  2449. printk(KERN_WARNING PFX "Error getting response from get"
  2450. " global enables command, the event buffer is not"
  2451. " enabled.\n");
  2452. goto out;
  2453. }
  2454. resp_len = smi_info->handlers->get_result(smi_info->si_sm,
  2455. resp, IPMI_MAX_MSG_LENGTH);
  2456. if (resp_len < 4 ||
  2457. resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 ||
  2458. resp[1] != IPMI_GET_BMC_GLOBAL_ENABLES_CMD ||
  2459. resp[2] != 0) {
  2460. printk(KERN_WARNING PFX "Invalid return from get global"
  2461. " enables command, cannot enable the event buffer.\n");
  2462. rv = -EINVAL;
  2463. goto out;
  2464. }
  2465. if (resp[3] & IPMI_BMC_EVT_MSG_BUFF)
  2466. /* buffer is already enabled, nothing to do. */
  2467. goto out;
  2468. msg[0] = IPMI_NETFN_APP_REQUEST << 2;
  2469. msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
  2470. msg[2] = resp[3] | IPMI_BMC_EVT_MSG_BUFF;
  2471. smi_info->handlers->start_transaction(smi_info->si_sm, msg, 3);
  2472. rv = wait_for_msg_done(smi_info);
  2473. if (rv) {
  2474. printk(KERN_WARNING PFX "Error getting response from set"
  2475. " global, enables command, the event buffer is not"
  2476. " enabled.\n");
  2477. goto out;
  2478. }
  2479. resp_len = smi_info->handlers->get_result(smi_info->si_sm,
  2480. resp, IPMI_MAX_MSG_LENGTH);
  2481. if (resp_len < 3 ||
  2482. resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 ||
  2483. resp[1] != IPMI_SET_BMC_GLOBAL_ENABLES_CMD) {
  2484. printk(KERN_WARNING PFX "Invalid return from get global,"
  2485. "enables command, not enable the event buffer.\n");
  2486. rv = -EINVAL;
  2487. goto out;
  2488. }
  2489. if (resp[2] != 0)
  2490. /*
  2491. * An error when setting the event buffer bit means
  2492. * that the event buffer is not supported.
  2493. */
  2494. rv = -ENOENT;
  2495. out:
  2496. kfree(resp);
  2497. return rv;
  2498. }
  2499. static int smi_type_proc_show(struct seq_file *m, void *v)
  2500. {
  2501. struct smi_info *smi = m->private;
  2502. return seq_printf(m, "%s\n", si_to_str[smi->si_type]);
  2503. }
  2504. static int smi_type_proc_open(struct inode *inode, struct file *file)
  2505. {
  2506. return single_open(file, smi_type_proc_show, PDE_DATA(inode));
  2507. }
  2508. static const struct file_operations smi_type_proc_ops = {
  2509. .open = smi_type_proc_open,
  2510. .read = seq_read,
  2511. .llseek = seq_lseek,
  2512. .release = single_release,
  2513. };
  2514. static int smi_si_stats_proc_show(struct seq_file *m, void *v)
  2515. {
  2516. struct smi_info *smi = m->private;
  2517. seq_printf(m, "interrupts_enabled: %d\n",
  2518. smi->irq && !smi->interrupt_disabled);
  2519. seq_printf(m, "short_timeouts: %u\n",
  2520. smi_get_stat(smi, short_timeouts));
  2521. seq_printf(m, "long_timeouts: %u\n",
  2522. smi_get_stat(smi, long_timeouts));
  2523. seq_printf(m, "idles: %u\n",
  2524. smi_get_stat(smi, idles));
  2525. seq_printf(m, "interrupts: %u\n",
  2526. smi_get_stat(smi, interrupts));
  2527. seq_printf(m, "attentions: %u\n",
  2528. smi_get_stat(smi, attentions));
  2529. seq_printf(m, "flag_fetches: %u\n",
  2530. smi_get_stat(smi, flag_fetches));
  2531. seq_printf(m, "hosed_count: %u\n",
  2532. smi_get_stat(smi, hosed_count));
  2533. seq_printf(m, "complete_transactions: %u\n",
  2534. smi_get_stat(smi, complete_transactions));
  2535. seq_printf(m, "events: %u\n",
  2536. smi_get_stat(smi, events));
  2537. seq_printf(m, "watchdog_pretimeouts: %u\n",
  2538. smi_get_stat(smi, watchdog_pretimeouts));
  2539. seq_printf(m, "incoming_messages: %u\n",
  2540. smi_get_stat(smi, incoming_messages));
  2541. return 0;
  2542. }
  2543. static int smi_si_stats_proc_open(struct inode *inode, struct file *file)
  2544. {
  2545. return single_open(file, smi_si_stats_proc_show, PDE_DATA(inode));
  2546. }
  2547. static const struct file_operations smi_si_stats_proc_ops = {
  2548. .open = smi_si_stats_proc_open,
  2549. .read = seq_read,
  2550. .llseek = seq_lseek,
  2551. .release = single_release,
  2552. };
  2553. static int smi_params_proc_show(struct seq_file *m, void *v)
  2554. {
  2555. struct smi_info *smi = m->private;
  2556. return seq_printf(m,
  2557. "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n",
  2558. si_to_str[smi->si_type],
  2559. addr_space_to_str[smi->io.addr_type],
  2560. smi->io.addr_data,
  2561. smi->io.regspacing,
  2562. smi->io.regsize,
  2563. smi->io.regshift,
  2564. smi->irq,
  2565. smi->slave_addr);
  2566. }
  2567. static int smi_params_proc_open(struct inode *inode, struct file *file)
  2568. {
  2569. return single_open(file, smi_params_proc_show, PDE_DATA(inode));
  2570. }
  2571. static const struct file_operations smi_params_proc_ops = {
  2572. .open = smi_params_proc_open,
  2573. .read = seq_read,
  2574. .llseek = seq_lseek,
  2575. .release = single_release,
  2576. };
  2577. /*
  2578. * oem_data_avail_to_receive_msg_avail
  2579. * @info - smi_info structure with msg_flags set
  2580. *
  2581. * Converts flags from OEM_DATA_AVAIL to RECEIVE_MSG_AVAIL
  2582. * Returns 1 indicating need to re-run handle_flags().
  2583. */
  2584. static int oem_data_avail_to_receive_msg_avail(struct smi_info *smi_info)
  2585. {
  2586. smi_info->msg_flags = ((smi_info->msg_flags & ~OEM_DATA_AVAIL) |
  2587. RECEIVE_MSG_AVAIL);
  2588. return 1;
  2589. }
  2590. /*
  2591. * setup_dell_poweredge_oem_data_handler
  2592. * @info - smi_info.device_id must be populated
  2593. *
  2594. * Systems that match, but have firmware version < 1.40 may assert
  2595. * OEM0_DATA_AVAIL on their own, without being told via Set Flags that
  2596. * it's safe to do so. Such systems will de-assert OEM1_DATA_AVAIL
  2597. * upon receipt of IPMI_GET_MSG_CMD, so we should treat these flags
  2598. * as RECEIVE_MSG_AVAIL instead.
  2599. *
  2600. * As Dell has no plans to release IPMI 1.5 firmware that *ever*
  2601. * assert the OEM[012] bits, and if it did, the driver would have to
  2602. * change to handle that properly, we don't actually check for the
  2603. * firmware version.
  2604. * Device ID = 0x20 BMC on PowerEdge 8G servers
  2605. * Device Revision = 0x80
  2606. * Firmware Revision1 = 0x01 BMC version 1.40
  2607. * Firmware Revision2 = 0x40 BCD encoded
  2608. * IPMI Version = 0x51 IPMI 1.5
  2609. * Manufacturer ID = A2 02 00 Dell IANA
  2610. *
  2611. * Additionally, PowerEdge systems with IPMI < 1.5 may also assert
  2612. * OEM0_DATA_AVAIL and needs to be treated as RECEIVE_MSG_AVAIL.
  2613. *
  2614. */
  2615. #define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20
  2616. #define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80
  2617. #define DELL_POWEREDGE_8G_BMC_IPMI_VERSION 0x51
  2618. #define DELL_IANA_MFR_ID 0x0002a2
  2619. static void setup_dell_poweredge_oem_data_handler(struct smi_info *smi_info)
  2620. {
  2621. struct ipmi_device_id *id = &smi_info->device_id;
  2622. if (id->manufacturer_id == DELL_IANA_MFR_ID) {
  2623. if (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID &&
  2624. id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV &&
  2625. id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION) {
  2626. smi_info->oem_data_avail_handler =
  2627. oem_data_avail_to_receive_msg_avail;
  2628. } else if (ipmi_version_major(id) < 1 ||
  2629. (ipmi_version_major(id) == 1 &&
  2630. ipmi_version_minor(id) < 5)) {
  2631. smi_info->oem_data_avail_handler =
  2632. oem_data_avail_to_receive_msg_avail;
  2633. }
  2634. }
  2635. }
  2636. #define CANNOT_RETURN_REQUESTED_LENGTH 0xCA
  2637. static void return_hosed_msg_badsize(struct smi_info *smi_info)
  2638. {
  2639. struct ipmi_smi_msg *msg = smi_info->curr_msg;
  2640. /* Make it a response */
  2641. msg->rsp[0] = msg->data[0] | 4;
  2642. msg->rsp[1] = msg->data[1];
  2643. msg->rsp[2] = CANNOT_RETURN_REQUESTED_LENGTH;
  2644. msg->rsp_size = 3;
  2645. smi_info->curr_msg = NULL;
  2646. deliver_recv_msg(smi_info, msg);
  2647. }
  2648. /*
  2649. * dell_poweredge_bt_xaction_handler
  2650. * @info - smi_info.device_id must be populated
  2651. *
  2652. * Dell PowerEdge servers with the BT interface (x6xx and 1750) will
  2653. * not respond to a Get SDR command if the length of the data
  2654. * requested is exactly 0x3A, which leads to command timeouts and no
  2655. * data returned. This intercepts such commands, and causes userspace
  2656. * callers to try again with a different-sized buffer, which succeeds.
  2657. */
  2658. #define STORAGE_NETFN 0x0A
  2659. #define STORAGE_CMD_GET_SDR 0x23
  2660. static int dell_poweredge_bt_xaction_handler(struct notifier_block *self,
  2661. unsigned long unused,
  2662. void *in)
  2663. {
  2664. struct smi_info *smi_info = in;
  2665. unsigned char *data = smi_info->curr_msg->data;
  2666. unsigned int size = smi_info->curr_msg->data_size;
  2667. if (size >= 8 &&
  2668. (data[0]>>2) == STORAGE_NETFN &&
  2669. data[1] == STORAGE_CMD_GET_SDR &&
  2670. data[7] == 0x3A) {
  2671. return_hosed_msg_badsize(smi_info);
  2672. return NOTIFY_STOP;
  2673. }
  2674. return NOTIFY_DONE;
  2675. }
  2676. static struct notifier_block dell_poweredge_bt_xaction_notifier = {
  2677. .notifier_call = dell_poweredge_bt_xaction_handler,
  2678. };
  2679. /*
  2680. * setup_dell_poweredge_bt_xaction_handler
  2681. * @info - smi_info.device_id must be filled in already
  2682. *
  2683. * Fills in smi_info.device_id.start_transaction_pre_hook
  2684. * when we know what function to use there.
  2685. */
  2686. static void
  2687. setup_dell_poweredge_bt_xaction_handler(struct smi_info *smi_info)
  2688. {
  2689. struct ipmi_device_id *id = &smi_info->device_id;
  2690. if (id->manufacturer_id == DELL_IANA_MFR_ID &&
  2691. smi_info->si_type == SI_BT)
  2692. register_xaction_notifier(&dell_poweredge_bt_xaction_notifier);
  2693. }
  2694. /*
  2695. * setup_oem_data_handler
  2696. * @info - smi_info.device_id must be filled in already
  2697. *
  2698. * Fills in smi_info.device_id.oem_data_available_handler
  2699. * when we know what function to use there.
  2700. */
  2701. static void setup_oem_data_handler(struct smi_info *smi_info)
  2702. {
  2703. setup_dell_poweredge_oem_data_handler(smi_info);
  2704. }
  2705. static void setup_xaction_handlers(struct smi_info *smi_info)
  2706. {
  2707. setup_dell_poweredge_bt_xaction_handler(smi_info);
  2708. }
  2709. static inline void wait_for_timer_and_thread(struct smi_info *smi_info)
  2710. {
  2711. if (smi_info->intf) {
  2712. /*
  2713. * The timer and thread are only running if the
  2714. * interface has been started up and registered.
  2715. */
  2716. if (smi_info->thread != NULL)
  2717. kthread_stop(smi_info->thread);
  2718. del_timer_sync(&smi_info->si_timer);
  2719. }
  2720. }
  2721. static struct ipmi_default_vals
  2722. {
  2723. int type;
  2724. int port;
  2725. } ipmi_defaults[] =
  2726. {
  2727. { .type = SI_KCS, .port = 0xca2 },
  2728. { .type = SI_SMIC, .port = 0xca9 },
  2729. { .type = SI_BT, .port = 0xe4 },
  2730. { .port = 0 }
  2731. };
  2732. static void default_find_bmc(void)
  2733. {
  2734. struct smi_info *info;
  2735. int i;
  2736. for (i = 0; ; i++) {
  2737. if (!ipmi_defaults[i].port)
  2738. break;
  2739. #ifdef CONFIG_PPC
  2740. if (check_legacy_ioport(ipmi_defaults[i].port))
  2741. continue;
  2742. #endif
  2743. info = smi_info_alloc();
  2744. if (!info)
  2745. return;
  2746. info->addr_source = SI_DEFAULT;
  2747. info->si_type = ipmi_defaults[i].type;
  2748. info->io_setup = port_setup;
  2749. info->io.addr_data = ipmi_defaults[i].port;
  2750. info->io.addr_type = IPMI_IO_ADDR_SPACE;
  2751. info->io.addr = NULL;
  2752. info->io.regspacing = DEFAULT_REGSPACING;
  2753. info->io.regsize = DEFAULT_REGSPACING;
  2754. info->io.regshift = 0;
  2755. if (add_smi(info) == 0) {
  2756. if ((try_smi_init(info)) == 0) {
  2757. /* Found one... */
  2758. printk(KERN_INFO PFX "Found default %s"
  2759. " state machine at %s address 0x%lx\n",
  2760. si_to_str[info->si_type],
  2761. addr_space_to_str[info->io.addr_type],
  2762. info->io.addr_data);
  2763. } else
  2764. cleanup_one_si(info);
  2765. } else {
  2766. kfree(info);
  2767. }
  2768. }
  2769. }
  2770. static int is_new_interface(struct smi_info *info)
  2771. {
  2772. struct smi_info *e;
  2773. list_for_each_entry(e, &smi_infos, link) {
  2774. if (e->io.addr_type != info->io.addr_type)
  2775. continue;
  2776. if (e->io.addr_data == info->io.addr_data)
  2777. return 0;
  2778. }
  2779. return 1;
  2780. }
  2781. static int add_smi(struct smi_info *new_smi)
  2782. {
  2783. int rv = 0;
  2784. printk(KERN_INFO PFX "Adding %s-specified %s state machine",
  2785. ipmi_addr_src_to_str[new_smi->addr_source],
  2786. si_to_str[new_smi->si_type]);
  2787. mutex_lock(&smi_infos_lock);
  2788. if (!is_new_interface(new_smi)) {
  2789. printk(KERN_CONT " duplicate interface\n");
  2790. rv = -EBUSY;
  2791. goto out_err;
  2792. }
  2793. printk(KERN_CONT "\n");
  2794. /* So we know not to free it unless we have allocated one. */
  2795. new_smi->intf = NULL;
  2796. new_smi->si_sm = NULL;
  2797. new_smi->handlers = NULL;
  2798. list_add_tail(&new_smi->link, &smi_infos);
  2799. out_err:
  2800. mutex_unlock(&smi_infos_lock);
  2801. return rv;
  2802. }
  2803. static int try_smi_init(struct smi_info *new_smi)
  2804. {
  2805. int rv = 0;
  2806. int i;
  2807. printk(KERN_INFO PFX "Trying %s-specified %s state"
  2808. " machine at %s address 0x%lx, slave address 0x%x,"
  2809. " irq %d\n",
  2810. ipmi_addr_src_to_str[new_smi->addr_source],
  2811. si_to_str[new_smi->si_type],
  2812. addr_space_to_str[new_smi->io.addr_type],
  2813. new_smi->io.addr_data,
  2814. new_smi->slave_addr, new_smi->irq);
  2815. switch (new_smi->si_type) {
  2816. case SI_KCS:
  2817. new_smi->handlers = &kcs_smi_handlers;
  2818. break;
  2819. case SI_SMIC:
  2820. new_smi->handlers = &smic_smi_handlers;
  2821. break;
  2822. case SI_BT:
  2823. new_smi->handlers = &bt_smi_handlers;
  2824. break;
  2825. default:
  2826. /* No support for anything else yet. */
  2827. rv = -EIO;
  2828. goto out_err;
  2829. }
  2830. /* Allocate the state machine's data and initialize it. */
  2831. new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL);
  2832. if (!new_smi->si_sm) {
  2833. printk(KERN_ERR PFX
  2834. "Could not allocate state machine memory\n");
  2835. rv = -ENOMEM;
  2836. goto out_err;
  2837. }
  2838. new_smi->io_size = new_smi->handlers->init_data(new_smi->si_sm,
  2839. &new_smi->io);
  2840. /* Now that we know the I/O size, we can set up the I/O. */
  2841. rv = new_smi->io_setup(new_smi);
  2842. if (rv) {
  2843. printk(KERN_ERR PFX "Could not set up I/O space\n");
  2844. goto out_err;
  2845. }
  2846. /* Do low-level detection first. */
  2847. if (new_smi->handlers->detect(new_smi->si_sm)) {
  2848. if (new_smi->addr_source)
  2849. printk(KERN_INFO PFX "Interface detection failed\n");
  2850. rv = -ENODEV;
  2851. goto out_err;
  2852. }
  2853. /*
  2854. * Attempt a get device id command. If it fails, we probably
  2855. * don't have a BMC here.
  2856. */
  2857. rv = try_get_dev_id(new_smi);
  2858. if (rv) {
  2859. if (new_smi->addr_source)
  2860. printk(KERN_INFO PFX "There appears to be no BMC"
  2861. " at this location\n");
  2862. goto out_err;
  2863. }
  2864. setup_oem_data_handler(new_smi);
  2865. setup_xaction_handlers(new_smi);
  2866. INIT_LIST_HEAD(&(new_smi->xmit_msgs));
  2867. INIT_LIST_HEAD(&(new_smi->hp_xmit_msgs));
  2868. new_smi->curr_msg = NULL;
  2869. atomic_set(&new_smi->req_events, 0);
  2870. new_smi->run_to_completion = 0;
  2871. for (i = 0; i < SI_NUM_STATS; i++)
  2872. atomic_set(&new_smi->stats[i], 0);
  2873. new_smi->interrupt_disabled = 1;
  2874. atomic_set(&new_smi->stop_operation, 0);
  2875. new_smi->intf_num = smi_num;
  2876. smi_num++;
  2877. rv = try_enable_event_buffer(new_smi);
  2878. if (rv == 0)
  2879. new_smi->has_event_buffer = 1;
  2880. /*
  2881. * Start clearing the flags before we enable interrupts or the
  2882. * timer to avoid racing with the timer.
  2883. */
  2884. start_clear_flags(new_smi);
  2885. /* IRQ is defined to be set when non-zero. */
  2886. if (new_smi->irq)
  2887. new_smi->si_state = SI_CLEARING_FLAGS_THEN_SET_IRQ;
  2888. if (!new_smi->dev) {
  2889. /*
  2890. * If we don't already have a device from something
  2891. * else (like PCI), then register a new one.
  2892. */
  2893. new_smi->pdev = platform_device_alloc("ipmi_si",
  2894. new_smi->intf_num);
  2895. if (!new_smi->pdev) {
  2896. printk(KERN_ERR PFX
  2897. "Unable to allocate platform device\n");
  2898. goto out_err;
  2899. }
  2900. new_smi->dev = &new_smi->pdev->dev;
  2901. new_smi->dev->driver = &ipmi_driver.driver;
  2902. rv = platform_device_add(new_smi->pdev);
  2903. if (rv) {
  2904. printk(KERN_ERR PFX
  2905. "Unable to register system interface device:"
  2906. " %d\n",
  2907. rv);
  2908. goto out_err;
  2909. }
  2910. new_smi->dev_registered = 1;
  2911. }
  2912. rv = ipmi_register_smi(&handlers,
  2913. new_smi,
  2914. &new_smi->device_id,
  2915. new_smi->dev,
  2916. "bmc",
  2917. new_smi->slave_addr);
  2918. if (rv) {
  2919. dev_err(new_smi->dev, "Unable to register device: error %d\n",
  2920. rv);
  2921. goto out_err_stop_timer;
  2922. }
  2923. rv = ipmi_smi_add_proc_entry(new_smi->intf, "type",
  2924. &smi_type_proc_ops,
  2925. new_smi);
  2926. if (rv) {
  2927. dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv);
  2928. goto out_err_stop_timer;
  2929. }
  2930. rv = ipmi_smi_add_proc_entry(new_smi->intf, "si_stats",
  2931. &smi_si_stats_proc_ops,
  2932. new_smi);
  2933. if (rv) {
  2934. dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv);
  2935. goto out_err_stop_timer;
  2936. }
  2937. rv = ipmi_smi_add_proc_entry(new_smi->intf, "params",
  2938. &smi_params_proc_ops,
  2939. new_smi);
  2940. if (rv) {
  2941. dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv);
  2942. goto out_err_stop_timer;
  2943. }
  2944. dev_info(new_smi->dev, "IPMI %s interface initialized\n",
  2945. si_to_str[new_smi->si_type]);
  2946. return 0;
  2947. out_err_stop_timer:
  2948. atomic_inc(&new_smi->stop_operation);
  2949. wait_for_timer_and_thread(new_smi);
  2950. out_err:
  2951. new_smi->interrupt_disabled = 1;
  2952. if (new_smi->intf) {
  2953. ipmi_unregister_smi(new_smi->intf);
  2954. new_smi->intf = NULL;
  2955. }
  2956. if (new_smi->irq_cleanup) {
  2957. new_smi->irq_cleanup(new_smi);
  2958. new_smi->irq_cleanup = NULL;
  2959. }
  2960. /*
  2961. * Wait until we know that we are out of any interrupt
  2962. * handlers might have been running before we freed the
  2963. * interrupt.
  2964. */
  2965. synchronize_sched();
  2966. if (new_smi->si_sm) {
  2967. if (new_smi->handlers)
  2968. new_smi->handlers->cleanup(new_smi->si_sm);
  2969. kfree(new_smi->si_sm);
  2970. new_smi->si_sm = NULL;
  2971. }
  2972. if (new_smi->addr_source_cleanup) {
  2973. new_smi->addr_source_cleanup(new_smi);
  2974. new_smi->addr_source_cleanup = NULL;
  2975. }
  2976. if (new_smi->io_cleanup) {
  2977. new_smi->io_cleanup(new_smi);
  2978. new_smi->io_cleanup = NULL;
  2979. }
  2980. if (new_smi->dev_registered) {
  2981. platform_device_unregister(new_smi->pdev);
  2982. new_smi->dev_registered = 0;
  2983. }
  2984. return rv;
  2985. }
  2986. static int init_ipmi_si(void)
  2987. {
  2988. int i;
  2989. char *str;
  2990. int rv;
  2991. struct smi_info *e;
  2992. enum ipmi_addr_src type = SI_INVALID;
  2993. if (initialized)
  2994. return 0;
  2995. initialized = 1;
  2996. if (si_tryplatform) {
  2997. rv = platform_driver_register(&ipmi_driver);
  2998. if (rv) {
  2999. printk(KERN_ERR PFX "Unable to register "
  3000. "driver: %d\n", rv);
  3001. return rv;
  3002. }
  3003. }
  3004. /* Parse out the si_type string into its components. */
  3005. str = si_type_str;
  3006. if (*str != '\0') {
  3007. for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) {
  3008. si_type[i] = str;
  3009. str = strchr(str, ',');
  3010. if (str) {
  3011. *str = '\0';
  3012. str++;
  3013. } else {
  3014. break;
  3015. }
  3016. }
  3017. }
  3018. printk(KERN_INFO "IPMI System Interface driver.\n");
  3019. /* If the user gave us a device, they presumably want us to use it */
  3020. if (!hardcode_find_bmc())
  3021. return 0;
  3022. #ifdef CONFIG_PCI
  3023. if (si_trypci) {
  3024. rv = pci_register_driver(&ipmi_pci_driver);
  3025. if (rv)
  3026. printk(KERN_ERR PFX "Unable to register "
  3027. "PCI driver: %d\n", rv);
  3028. else
  3029. pci_registered = 1;
  3030. }
  3031. #endif
  3032. #ifdef CONFIG_ACPI
  3033. if (si_tryacpi) {
  3034. pnp_register_driver(&ipmi_pnp_driver);
  3035. pnp_registered = 1;
  3036. }
  3037. #endif
  3038. #ifdef CONFIG_DMI
  3039. if (si_trydmi)
  3040. dmi_find_bmc();
  3041. #endif
  3042. #ifdef CONFIG_ACPI
  3043. if (si_tryacpi)
  3044. spmi_find_bmc();
  3045. #endif
  3046. #ifdef CONFIG_PARISC
  3047. register_parisc_driver(&ipmi_parisc_driver);
  3048. parisc_registered = 1;
  3049. /* poking PC IO addresses will crash machine, don't do it */
  3050. si_trydefaults = 0;
  3051. #endif
  3052. /* We prefer devices with interrupts, but in the case of a machine
  3053. with multiple BMCs we assume that there will be several instances
  3054. of a given type so if we succeed in registering a type then also
  3055. try to register everything else of the same type */
  3056. mutex_lock(&smi_infos_lock);
  3057. list_for_each_entry(e, &smi_infos, link) {
  3058. /* Try to register a device if it has an IRQ and we either
  3059. haven't successfully registered a device yet or this
  3060. device has the same type as one we successfully registered */
  3061. if (e->irq && (!type || e->addr_source == type)) {
  3062. if (!try_smi_init(e)) {
  3063. type = e->addr_source;
  3064. }
  3065. }
  3066. }
  3067. /* type will only have been set if we successfully registered an si */
  3068. if (type) {
  3069. mutex_unlock(&smi_infos_lock);
  3070. return 0;
  3071. }
  3072. /* Fall back to the preferred device */
  3073. list_for_each_entry(e, &smi_infos, link) {
  3074. if (!e->irq && (!type || e->addr_source == type)) {
  3075. if (!try_smi_init(e)) {
  3076. type = e->addr_source;
  3077. }
  3078. }
  3079. }
  3080. mutex_unlock(&smi_infos_lock);
  3081. if (type)
  3082. return 0;
  3083. if (si_trydefaults) {
  3084. mutex_lock(&smi_infos_lock);
  3085. if (list_empty(&smi_infos)) {
  3086. /* No BMC was found, try defaults. */
  3087. mutex_unlock(&smi_infos_lock);
  3088. default_find_bmc();
  3089. } else
  3090. mutex_unlock(&smi_infos_lock);
  3091. }
  3092. mutex_lock(&smi_infos_lock);
  3093. if (unload_when_empty && list_empty(&smi_infos)) {
  3094. mutex_unlock(&smi_infos_lock);
  3095. cleanup_ipmi_si();
  3096. printk(KERN_WARNING PFX
  3097. "Unable to find any System Interface(s)\n");
  3098. return -ENODEV;
  3099. } else {
  3100. mutex_unlock(&smi_infos_lock);
  3101. return 0;
  3102. }
  3103. }
  3104. module_init(init_ipmi_si);
  3105. static void cleanup_one_si(struct smi_info *to_clean)
  3106. {
  3107. int rv = 0;
  3108. unsigned long flags;
  3109. if (!to_clean)
  3110. return;
  3111. list_del(&to_clean->link);
  3112. /* Tell the driver that we are shutting down. */
  3113. atomic_inc(&to_clean->stop_operation);
  3114. /*
  3115. * Make sure the timer and thread are stopped and will not run
  3116. * again.
  3117. */
  3118. wait_for_timer_and_thread(to_clean);
  3119. /*
  3120. * Timeouts are stopped, now make sure the interrupts are off
  3121. * for the device. A little tricky with locks to make sure
  3122. * there are no races.
  3123. */
  3124. spin_lock_irqsave(&to_clean->si_lock, flags);
  3125. while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
  3126. spin_unlock_irqrestore(&to_clean->si_lock, flags);
  3127. poll(to_clean);
  3128. schedule_timeout_uninterruptible(1);
  3129. spin_lock_irqsave(&to_clean->si_lock, flags);
  3130. }
  3131. disable_si_irq(to_clean);
  3132. spin_unlock_irqrestore(&to_clean->si_lock, flags);
  3133. while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
  3134. poll(to_clean);
  3135. schedule_timeout_uninterruptible(1);
  3136. }
  3137. /* Clean up interrupts and make sure that everything is done. */
  3138. if (to_clean->irq_cleanup)
  3139. to_clean->irq_cleanup(to_clean);
  3140. while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
  3141. poll(to_clean);
  3142. schedule_timeout_uninterruptible(1);
  3143. }
  3144. if (to_clean->intf)
  3145. rv = ipmi_unregister_smi(to_clean->intf);
  3146. if (rv) {
  3147. printk(KERN_ERR PFX "Unable to unregister device: errno=%d\n",
  3148. rv);
  3149. }
  3150. if (to_clean->handlers)
  3151. to_clean->handlers->cleanup(to_clean->si_sm);
  3152. kfree(to_clean->si_sm);
  3153. if (to_clean->addr_source_cleanup)
  3154. to_clean->addr_source_cleanup(to_clean);
  3155. if (to_clean->io_cleanup)
  3156. to_clean->io_cleanup(to_clean);
  3157. if (to_clean->dev_registered)
  3158. platform_device_unregister(to_clean->pdev);
  3159. kfree(to_clean);
  3160. }
  3161. static void cleanup_ipmi_si(void)
  3162. {
  3163. struct smi_info *e, *tmp_e;
  3164. if (!initialized)
  3165. return;
  3166. #ifdef CONFIG_PCI
  3167. if (pci_registered)
  3168. pci_unregister_driver(&ipmi_pci_driver);
  3169. #endif
  3170. #ifdef CONFIG_ACPI
  3171. if (pnp_registered)
  3172. pnp_unregister_driver(&ipmi_pnp_driver);
  3173. #endif
  3174. #ifdef CONFIG_PARISC
  3175. if (parisc_registered)
  3176. unregister_parisc_driver(&ipmi_parisc_driver);
  3177. #endif
  3178. platform_driver_unregister(&ipmi_driver);
  3179. mutex_lock(&smi_infos_lock);
  3180. list_for_each_entry_safe(e, tmp_e, &smi_infos, link)
  3181. cleanup_one_si(e);
  3182. mutex_unlock(&smi_infos_lock);
  3183. }
  3184. module_exit(cleanup_ipmi_si);
  3185. MODULE_LICENSE("GPL");
  3186. MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
  3187. MODULE_DESCRIPTION("Interface to the IPMI driver for the KCS, SMIC, and BT"
  3188. " system interfaces.");