ipmi_si_intf.c 92 KB

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